Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2022 Intel Corporation
3 : : */
4 : :
5 : : #include <unistd.h>
6 : :
7 : : #include <rte_common.h>
8 : : #include <rte_log.h>
9 : : #include <rte_dev.h>
10 : : #include <rte_malloc.h>
11 : : #include <rte_mempool.h>
12 : : #include <rte_byteorder.h>
13 : : #include <rte_errno.h>
14 : : #include <rte_branch_prediction.h>
15 : : #include <rte_hexdump.h>
16 : : #include <rte_pci.h>
17 : : #include <rte_bus_pci.h>
18 : : #include <rte_cycles.h>
19 : :
20 : : #include <rte_bbdev.h>
21 : : #include <rte_bbdev_pmd.h>
22 : : #include "vrb_pmd.h"
23 : :
24 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
25 : : RTE_LOG_REGISTER_SUFFIX(vrb_logtype, vrb, DEBUG);
26 : : #else
27 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(vrb_logtype, vrb, NOTICE);
28 : : #endif
29 : : #define RTE_LOGTYPE_VRB vrb_logtype
30 : :
31 : : /* Calculate the offset of the enqueue register. */
32 : : static inline uint32_t
33 : 0 : vrb1_queue_offset(bool pf_device, uint8_t vf_id, uint8_t qgrp_id, uint16_t aq_id)
34 : : {
35 [ # # ]: 0 : if (pf_device)
36 : 0 : return ((vf_id << 12) + (qgrp_id << 7) + (aq_id << 3) + VRB1_PfQmgrIngressAq);
37 : : else
38 : 0 : return ((qgrp_id << 7) + (aq_id << 3) + VRB1_VfQmgrIngressAq);
39 : : }
40 : :
41 : : static inline uint32_t
42 : 0 : vrb2_queue_offset(bool pf_device, uint8_t vf_id, uint8_t qgrp_id, uint16_t aq_id)
43 : : {
44 [ # # ]: 0 : if (pf_device)
45 : 0 : return ((vf_id << 14) + (qgrp_id << 9) + (aq_id << 3) + VRB2_PfQmgrIngressAq);
46 : : else
47 : 0 : return ((qgrp_id << 9) + (aq_id << 3) + VRB2_VfQmgrIngressAq);
48 : : }
49 : :
50 : : enum {UL_4G = 0, UL_5G, DL_4G, DL_5G, FFT, MLD, NUM_ACC};
51 : :
52 : : /* Return the accelerator enum for a Queue Group Index. */
53 : : static inline int
54 : 0 : accFromQgid(int qg_idx, const struct rte_acc_conf *acc_conf)
55 : : {
56 : : int accQg[VRB_MAX_QGRPS];
57 : : int NumQGroupsPerFn[NUM_ACC];
58 : : int acc, qgIdx, qgIndex = 0;
59 [ # # ]: 0 : for (qgIdx = 0; qgIdx < VRB_MAX_QGRPS; qgIdx++)
60 : 0 : accQg[qgIdx] = 0;
61 : 0 : NumQGroupsPerFn[UL_4G] = acc_conf->q_ul_4g.num_qgroups;
62 : 0 : NumQGroupsPerFn[UL_5G] = acc_conf->q_ul_5g.num_qgroups;
63 : 0 : NumQGroupsPerFn[DL_4G] = acc_conf->q_dl_4g.num_qgroups;
64 : 0 : NumQGroupsPerFn[DL_5G] = acc_conf->q_dl_5g.num_qgroups;
65 : 0 : NumQGroupsPerFn[FFT] = acc_conf->q_fft.num_qgroups;
66 : 0 : NumQGroupsPerFn[MLD] = acc_conf->q_mld.num_qgroups;
67 [ # # ]: 0 : for (acc = UL_4G; acc < NUM_ACC; acc++)
68 [ # # ]: 0 : for (qgIdx = 0; qgIdx < NumQGroupsPerFn[acc]; qgIdx++)
69 : 0 : accQg[qgIndex++] = acc;
70 : 0 : acc = accQg[qg_idx];
71 : 0 : return acc;
72 : : }
73 : :
74 : : /* Return the queue topology for a Queue Group Index. */
75 : : static inline void
76 : 0 : qtopFromAcc(struct rte_acc_queue_topology **qtop, int acc_enum, struct rte_acc_conf *acc_conf)
77 : : {
78 : : struct rte_acc_queue_topology *p_qtop;
79 : : p_qtop = NULL;
80 : :
81 [ # # # # : 0 : switch (acc_enum) {
# # # ]
82 : 0 : case UL_4G:
83 : 0 : p_qtop = &(acc_conf->q_ul_4g);
84 : 0 : break;
85 : 0 : case UL_5G:
86 : 0 : p_qtop = &(acc_conf->q_ul_5g);
87 : 0 : break;
88 : 0 : case DL_4G:
89 : 0 : p_qtop = &(acc_conf->q_dl_4g);
90 : 0 : break;
91 : 0 : case DL_5G:
92 : 0 : p_qtop = &(acc_conf->q_dl_5g);
93 : 0 : break;
94 : 0 : case FFT:
95 : 0 : p_qtop = &(acc_conf->q_fft);
96 : 0 : break;
97 : 0 : case MLD:
98 : 0 : p_qtop = &(acc_conf->q_mld);
99 : 0 : break;
100 : 0 : default:
101 : : /* NOTREACHED. */
102 : 0 : rte_bbdev_log(ERR, "Unexpected error evaluating %s using %d", __func__, acc_enum);
103 : 0 : break;
104 : : }
105 : 0 : *qtop = p_qtop;
106 : 0 : }
107 : :
108 : : /* Return the AQ depth for a Queue Group Index. */
109 : : static inline int
110 : 0 : aqDepth(int qg_idx, struct rte_acc_conf *acc_conf)
111 : : {
112 : 0 : struct rte_acc_queue_topology *q_top = NULL;
113 : :
114 : 0 : int acc_enum = accFromQgid(qg_idx, acc_conf);
115 : 0 : qtopFromAcc(&q_top, acc_enum, acc_conf);
116 : :
117 [ # # ]: 0 : if (unlikely(q_top == NULL))
118 : : return 1;
119 : :
120 : 0 : return RTE_MAX(1, q_top->aq_depth_log2);
121 : : }
122 : :
123 : : /* Return the AQ depth for a Queue Group Index. */
124 : : static inline int
125 : 0 : aqNum(int qg_idx, struct rte_acc_conf *acc_conf)
126 : : {
127 : 0 : struct rte_acc_queue_topology *q_top = NULL;
128 : :
129 : 0 : int acc_enum = accFromQgid(qg_idx, acc_conf);
130 : 0 : qtopFromAcc(&q_top, acc_enum, acc_conf);
131 : :
132 [ # # ]: 0 : if (unlikely(q_top == NULL))
133 : : return 0;
134 : :
135 : 0 : return q_top->num_aqs_per_groups;
136 : : }
137 : :
138 : : static void
139 : : initQTop(struct rte_acc_conf *acc_conf)
140 : : {
141 : 0 : acc_conf->q_ul_4g.num_aqs_per_groups = 0;
142 : 0 : acc_conf->q_ul_4g.num_qgroups = 0;
143 : 0 : acc_conf->q_ul_4g.first_qgroup_index = -1;
144 : 0 : acc_conf->q_ul_5g.num_aqs_per_groups = 0;
145 : 0 : acc_conf->q_ul_5g.num_qgroups = 0;
146 : 0 : acc_conf->q_ul_5g.first_qgroup_index = -1;
147 : 0 : acc_conf->q_dl_4g.num_aqs_per_groups = 0;
148 : 0 : acc_conf->q_dl_4g.num_qgroups = 0;
149 : 0 : acc_conf->q_dl_4g.first_qgroup_index = -1;
150 : 0 : acc_conf->q_dl_5g.num_aqs_per_groups = 0;
151 : 0 : acc_conf->q_dl_5g.num_qgroups = 0;
152 : 0 : acc_conf->q_dl_5g.first_qgroup_index = -1;
153 : 0 : acc_conf->q_fft.num_aqs_per_groups = 0;
154 : 0 : acc_conf->q_fft.num_qgroups = 0;
155 : 0 : acc_conf->q_fft.first_qgroup_index = -1;
156 : 0 : acc_conf->q_mld.num_aqs_per_groups = 0;
157 : 0 : acc_conf->q_mld.num_qgroups = 0;
158 : 0 : acc_conf->q_mld.first_qgroup_index = -1;
159 : : }
160 : :
161 : : static inline void
162 : 0 : updateQtop(uint8_t acc, uint8_t qg, struct rte_acc_conf *acc_conf, struct acc_device *d) {
163 : : uint32_t reg;
164 : 0 : struct rte_acc_queue_topology *q_top = NULL;
165 : : uint16_t aq;
166 : :
167 : 0 : qtopFromAcc(&q_top, acc, acc_conf);
168 [ # # ]: 0 : if (unlikely(q_top == NULL))
169 : 0 : return;
170 : 0 : q_top->num_qgroups++;
171 [ # # ]: 0 : if (q_top->first_qgroup_index == -1) {
172 : 0 : q_top->first_qgroup_index = qg;
173 : : /* Can be optimized to assume all are enabled by default. */
174 : 0 : reg = acc_reg_read(d, d->queue_offset(d->pf_device, 0, qg, d->num_aqs - 1));
175 [ # # ]: 0 : if (reg & ACC_QUEUE_ENABLE) {
176 : 0 : q_top->num_aqs_per_groups = d->num_aqs;
177 : 0 : return;
178 : : }
179 : 0 : q_top->num_aqs_per_groups = 0;
180 [ # # ]: 0 : for (aq = 0; aq < d->num_aqs; aq++) {
181 : 0 : reg = acc_reg_read(d, d->queue_offset(d->pf_device, 0, qg, aq));
182 [ # # ]: 0 : if (reg & ACC_QUEUE_ENABLE)
183 : 0 : q_top->num_aqs_per_groups++;
184 : : }
185 : : }
186 : : }
187 : :
188 : : /* Check device Qmgr is enabled for protection */
189 : : static inline bool
190 : 0 : vrb_check_device_enable(struct rte_bbdev *dev)
191 : : {
192 : : uint32_t reg_aq, qg;
193 : 0 : struct acc_device *d = dev->data->dev_private;
194 : :
195 [ # # ]: 0 : for (qg = 0; qg < d->num_qgroups; qg++) {
196 : 0 : reg_aq = acc_reg_read(d, d->queue_offset(d->pf_device, 0, qg, 0));
197 [ # # ]: 0 : if (reg_aq & ACC_QUEUE_ENABLE)
198 : : return true;
199 : : }
200 : : return false;
201 : : }
202 : :
203 : : static inline void
204 : : vrb_vf2pf(struct acc_device *d, unsigned int payload)
205 : : {
206 : 0 : acc_reg_write(d, d->reg_addr->vf2pf_doorbell, payload);
207 : : }
208 : :
209 : : /* Request device FFT windowing information. */
210 : : static inline void
211 : 0 : vrb_device_fft_win(struct rte_bbdev *dev)
212 : : {
213 : 0 : struct acc_device *d = dev->data->dev_private;
214 : : uint32_t reg, time_out = 0, win;
215 : :
216 [ # # ]: 0 : if (d->pf_device)
217 : : return;
218 : :
219 : : /* Check from the device the first time. */
220 [ # # ]: 0 : if (d->fft_window_width[0] == 0) {
221 [ # # ]: 0 : for (win = 0; win < ACC_MAX_FFT_WIN; win++) {
222 : 0 : vrb_vf2pf(d, ACC_VF2PF_FFT_WIN_REQUEST | win);
223 : 0 : reg = acc_reg_read(d, d->reg_addr->pf2vf_doorbell);
224 [ # # ]: 0 : while ((time_out < ACC_STATUS_TO) && (reg == RTE_BBDEV_DEV_NOSTATUS)) {
225 : 0 : usleep(ACC_STATUS_WAIT); /*< Wait or VF->PF->VF Comms. */
226 : 0 : reg = acc_reg_read(d, d->reg_addr->pf2vf_doorbell);
227 : 0 : time_out++;
228 : : }
229 : 0 : d->fft_window_width[win] = reg;
230 : : }
231 : : }
232 : : }
233 : :
234 : : /* Fetch configuration enabled for the PF/VF using MMIO Read (slow). */
235 : : static inline void
236 : 0 : fetch_acc_config(struct rte_bbdev *dev)
237 : : {
238 : 0 : struct acc_device *d = dev->data->dev_private;
239 : 0 : struct rte_acc_conf *acc_conf = &d->acc_conf;
240 : : uint8_t acc, qg;
241 : : uint32_t reg_aq, reg_len0, reg_len1, reg_len2, reg_len3, reg0, reg1, reg2, reg3;
242 : : uint32_t reg_mode, idx;
243 : 0 : struct rte_acc_queue_topology *q_top = NULL;
244 : 0 : int qman_func_id[VRB_NUM_ACCS] = {ACC_ACCMAP_0, ACC_ACCMAP_1,
245 : : ACC_ACCMAP_2, ACC_ACCMAP_3, ACC_ACCMAP_4, ACC_ACCMAP_5};
246 : :
247 : : /* No need to retrieve the configuration is already done. */
248 [ # # ]: 0 : if (d->configured)
249 : 0 : return;
250 : :
251 [ # # ]: 0 : if (!vrb_check_device_enable(dev)) {
252 : 0 : rte_bbdev_log(NOTICE, "%s has no queue enabled and can't be used.",
253 : : dev->data->name);
254 : 0 : return;
255 : : }
256 : :
257 : 0 : vrb_device_fft_win(dev);
258 : :
259 : 0 : d->ddr_size = 0;
260 : :
261 : : /* Single VF Bundle by VF. */
262 : 0 : acc_conf->num_vf_bundles = 1;
263 : : initQTop(acc_conf);
264 : :
265 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
266 : 0 : reg0 = acc_reg_read(d, d->reg_addr->qman_group_func);
267 : 0 : reg1 = acc_reg_read(d, d->reg_addr->qman_group_func + 4);
268 [ # # ]: 0 : for (qg = 0; qg < d->num_qgroups; qg++) {
269 : 0 : reg_aq = acc_reg_read(d, d->queue_offset(d->pf_device, 0, qg, 0));
270 [ # # ]: 0 : if (reg_aq & ACC_QUEUE_ENABLE) {
271 [ # # ]: 0 : if (qg < ACC_NUM_QGRPS_PER_WORD)
272 : 0 : idx = (reg0 >> (qg * 4)) & 0x7;
273 : : else
274 : 0 : idx = (reg1 >> ((qg - ACC_NUM_QGRPS_PER_WORD) * 4)) & 0x7;
275 [ # # ]: 0 : if (idx < VRB1_NUM_ACCS) {
276 : 0 : acc = qman_func_id[idx];
277 : 0 : updateQtop(acc, qg, acc_conf, d);
278 : : }
279 : : }
280 : : }
281 : :
282 : : /* Check the depth of the AQs. */
283 : 0 : reg_len0 = acc_reg_read(d, d->reg_addr->depth_log0_offset);
284 : 0 : reg_len1 = acc_reg_read(d, d->reg_addr->depth_log1_offset);
285 [ # # ]: 0 : for (acc = 0; acc < VRB1_NUM_ACCS; acc++) {
286 : 0 : qtopFromAcc(&q_top, acc, acc_conf);
287 [ # # ]: 0 : if (q_top->first_qgroup_index < ACC_NUM_QGRPS_PER_WORD)
288 : 0 : q_top->aq_depth_log2 =
289 : 0 : (reg_len0 >> (q_top->first_qgroup_index * 4)) & 0xF;
290 : : else
291 : 0 : q_top->aq_depth_log2 = (reg_len1 >> ((q_top->first_qgroup_index -
292 : 0 : ACC_NUM_QGRPS_PER_WORD) * 4)) & 0xF;
293 : : }
294 [ # # ]: 0 : } else if (d->device_variant == VRB2_VARIANT) {
295 : 0 : reg0 = acc_reg_read(d, d->reg_addr->qman_group_func);
296 : 0 : reg1 = acc_reg_read(d, d->reg_addr->qman_group_func + 4);
297 : 0 : reg2 = acc_reg_read(d, d->reg_addr->qman_group_func + 8);
298 : 0 : reg3 = acc_reg_read(d, d->reg_addr->qman_group_func + 12);
299 : : /* printf("Debug Function %08x %08x %08x %08x\n", reg0, reg1, reg2, reg3);*/
300 [ # # ]: 0 : for (qg = 0; qg < VRB2_NUM_QGRPS; qg++) {
301 [ # # ]: 0 : reg_aq = acc_reg_read(d, vrb2_queue_offset(d->pf_device, 0, qg, 0));
302 [ # # ]: 0 : if (reg_aq & ACC_QUEUE_ENABLE) {
303 : : /* printf("Qg enabled %d %x\n", qg, reg_aq);*/
304 [ # # ]: 0 : if (qg / ACC_NUM_QGRPS_PER_WORD == 0)
305 : 0 : idx = (reg0 >> ((qg % ACC_NUM_QGRPS_PER_WORD) * 4)) & 0x7;
306 [ # # ]: 0 : else if (qg / ACC_NUM_QGRPS_PER_WORD == 1)
307 : 0 : idx = (reg1 >> ((qg % ACC_NUM_QGRPS_PER_WORD) * 4)) & 0x7;
308 [ # # ]: 0 : else if (qg / ACC_NUM_QGRPS_PER_WORD == 2)
309 : 0 : idx = (reg2 >> ((qg % ACC_NUM_QGRPS_PER_WORD) * 4)) & 0x7;
310 : : else
311 : 0 : idx = (reg3 >> ((qg % ACC_NUM_QGRPS_PER_WORD) * 4)) & 0x7;
312 [ # # ]: 0 : if (idx < VRB2_NUM_ACCS) {
313 : 0 : acc = qman_func_id[idx];
314 : 0 : updateQtop(acc, qg, acc_conf, d);
315 : : }
316 : : }
317 : : }
318 : :
319 : : /* Check the depth of the AQs. */
320 : 0 : reg_len0 = acc_reg_read(d, d->reg_addr->depth_log0_offset);
321 : 0 : reg_len1 = acc_reg_read(d, d->reg_addr->depth_log0_offset + 4);
322 : 0 : reg_len2 = acc_reg_read(d, d->reg_addr->depth_log0_offset + 8);
323 : 0 : reg_len3 = acc_reg_read(d, d->reg_addr->depth_log0_offset + 12);
324 : :
325 [ # # ]: 0 : for (acc = 0; acc < VRB2_NUM_ACCS; acc++) {
326 : 0 : qtopFromAcc(&q_top, acc, acc_conf);
327 [ # # ]: 0 : if (q_top->first_qgroup_index / ACC_NUM_QGRPS_PER_WORD == 0)
328 : 0 : q_top->aq_depth_log2 = (reg_len0 >> ((q_top->first_qgroup_index %
329 : 0 : ACC_NUM_QGRPS_PER_WORD) * 4)) & 0xF;
330 [ # # ]: 0 : else if (q_top->first_qgroup_index / ACC_NUM_QGRPS_PER_WORD == 1)
331 : 0 : q_top->aq_depth_log2 = (reg_len1 >> ((q_top->first_qgroup_index %
332 : 0 : ACC_NUM_QGRPS_PER_WORD) * 4)) & 0xF;
333 [ # # ]: 0 : else if (q_top->first_qgroup_index / ACC_NUM_QGRPS_PER_WORD == 2)
334 : 0 : q_top->aq_depth_log2 = (reg_len2 >> ((q_top->first_qgroup_index %
335 : 0 : ACC_NUM_QGRPS_PER_WORD) * 4)) & 0xF;
336 : : else
337 : 0 : q_top->aq_depth_log2 = (reg_len3 >> ((q_top->first_qgroup_index %
338 : 0 : ACC_NUM_QGRPS_PER_WORD) * 4)) & 0xF;
339 : : }
340 : : }
341 : :
342 : : /* Read PF mode. */
343 [ # # ]: 0 : if (d->pf_device) {
344 : 0 : reg_mode = acc_reg_read(d, d->reg_addr->pf_mode);
345 : 0 : acc_conf->pf_mode_en = (reg_mode == ACC_PF_VAL) ? 1 : 0;
346 : : } else {
347 : 0 : reg_mode = acc_reg_read(d, d->reg_addr->hi_mode);
348 : 0 : acc_conf->pf_mode_en = reg_mode & 1;
349 : : }
350 : :
351 : : rte_bbdev_log_debug(
352 : : "%s Config LLR SIGN IN/OUT %s %s QG %u %u %u %u %u %u AQ %u %u %u %u %u %u Len %u %u %u %u %u %u",
353 : : (d->pf_device) ? "PF" : "VF",
354 : : (acc_conf->input_pos_llr_1_bit) ? "POS" : "NEG",
355 : : (acc_conf->output_pos_llr_1_bit) ? "POS" : "NEG",
356 : : acc_conf->q_ul_4g.num_qgroups,
357 : : acc_conf->q_dl_4g.num_qgroups,
358 : : acc_conf->q_ul_5g.num_qgroups,
359 : : acc_conf->q_dl_5g.num_qgroups,
360 : : acc_conf->q_fft.num_qgroups,
361 : : acc_conf->q_mld.num_qgroups,
362 : : acc_conf->q_ul_4g.num_aqs_per_groups,
363 : : acc_conf->q_dl_4g.num_aqs_per_groups,
364 : : acc_conf->q_ul_5g.num_aqs_per_groups,
365 : : acc_conf->q_dl_5g.num_aqs_per_groups,
366 : : acc_conf->q_fft.num_aqs_per_groups,
367 : : acc_conf->q_mld.num_aqs_per_groups,
368 : : acc_conf->q_ul_4g.aq_depth_log2,
369 : : acc_conf->q_dl_4g.aq_depth_log2,
370 : : acc_conf->q_ul_5g.aq_depth_log2,
371 : : acc_conf->q_dl_5g.aq_depth_log2,
372 : : acc_conf->q_fft.aq_depth_log2,
373 : : acc_conf->q_mld.aq_depth_log2);
374 : : }
375 : :
376 : : /* Request device status information. */
377 : : static inline uint32_t
378 : 0 : vrb_device_status(struct rte_bbdev *dev)
379 : : {
380 : 0 : struct acc_device *d = dev->data->dev_private;
381 : : uint32_t reg, time_out = 0;
382 : :
383 [ # # ]: 0 : if (d->pf_device)
384 : : return RTE_BBDEV_DEV_NOT_SUPPORTED;
385 : :
386 : : vrb_vf2pf(d, ACC_VF2PF_STATUS_REQUEST);
387 : 0 : reg = acc_reg_read(d, d->reg_addr->pf2vf_doorbell);
388 [ # # ]: 0 : while ((time_out < ACC_STATUS_TO) && (reg == RTE_BBDEV_DEV_NOSTATUS)) {
389 : 0 : usleep(ACC_STATUS_WAIT); /*< Wait or VF->PF->VF Comms */
390 : 0 : reg = acc_reg_read(d, d->reg_addr->pf2vf_doorbell);
391 : 0 : time_out++;
392 : : }
393 : :
394 : : return reg;
395 : : }
396 : :
397 : : /* Checks PF Info Ring to find the interrupt cause and handles it accordingly. */
398 : : static inline void
399 : 0 : vrb_check_ir(struct acc_device *acc_dev)
400 : : {
401 : : volatile union acc_info_ring_data *ring_data;
402 : 0 : uint16_t info_ring_head = acc_dev->info_ring_head, int_nb;
403 [ # # ]: 0 : if (unlikely(acc_dev->info_ring == NULL))
404 : : return;
405 : :
406 : 0 : ring_data = acc_dev->info_ring + (acc_dev->info_ring_head & ACC_INFO_RING_MASK);
407 : :
408 [ # # ]: 0 : while (ring_data->valid) {
409 [ # # ]: 0 : int_nb = int_from_ring(*ring_data, acc_dev->device_variant);
410 [ # # ]: 0 : if ((int_nb < ACC_PF_INT_DMA_DL_DESC_IRQ) || (
411 : : int_nb > ACC_PF_INT_DMA_MLD_DESC_IRQ)) {
412 : 0 : rte_bbdev_log(WARNING, "InfoRing: ITR:%d Info:0x%x",
413 : : int_nb, ring_data->detailed_info);
414 : : /* Initialize Info Ring entry and move forward. */
415 : 0 : ring_data->valid = 0;
416 : : }
417 : 0 : info_ring_head++;
418 : 0 : ring_data = acc_dev->info_ring + (info_ring_head & ACC_INFO_RING_MASK);
419 : : }
420 : : }
421 : :
422 : : /* Interrupt handler triggered by dev for handling specific interrupt. */
423 : : static void
424 : 0 : vrb_dev_interrupt_handler(void *cb_arg)
425 : : {
426 : : struct rte_bbdev *dev = cb_arg;
427 : 0 : struct acc_device *acc_dev = dev->data->dev_private;
428 : : volatile union acc_info_ring_data *ring_data;
429 : : struct acc_deq_intr_details deq_intr_det;
430 : : uint16_t vf_id, aq_id, qg_id, int_nb;
431 : :
432 : 0 : ring_data = acc_dev->info_ring + (acc_dev->info_ring_head & ACC_INFO_RING_MASK);
433 : :
434 [ # # ]: 0 : while (ring_data->valid) {
435 [ # # # # ]: 0 : vf_id = vf_from_ring(*ring_data, acc_dev->device_variant);
436 [ # # ]: 0 : aq_id = aq_from_ring(*ring_data, acc_dev->device_variant);
437 [ # # ]: 0 : qg_id = qg_from_ring(*ring_data, acc_dev->device_variant);
438 : 0 : int_nb = int_from_ring(*ring_data, acc_dev->device_variant);
439 [ # # ]: 0 : if (acc_dev->pf_device) {
440 : : rte_bbdev_log_debug(
441 : : "PF Interrupt received, Info Ring data: 0x%x -> %d",
442 : : ring_data->val, int_nb);
443 : :
444 [ # # ]: 0 : switch (int_nb) {
445 : 0 : case ACC_PF_INT_DMA_DL_DESC_IRQ:
446 : : case ACC_PF_INT_DMA_UL_DESC_IRQ:
447 : : case ACC_PF_INT_DMA_FFT_DESC_IRQ:
448 : : case ACC_PF_INT_DMA_UL5G_DESC_IRQ:
449 : : case ACC_PF_INT_DMA_DL5G_DESC_IRQ:
450 : : case ACC_PF_INT_DMA_MLD_DESC_IRQ:
451 : 0 : deq_intr_det.queue_id = get_queue_id_from_ring_info(
452 : : dev->data, *ring_data);
453 [ # # ]: 0 : if (deq_intr_det.queue_id == UINT16_MAX) {
454 : 0 : rte_bbdev_log(ERR,
455 : : "Couldn't find queue: aq_id: %u, qg_id: %u, vf_id: %u",
456 : : aq_id, qg_id, vf_id);
457 : 0 : return;
458 : : }
459 : 0 : rte_bbdev_pmd_callback_process(dev,
460 : : RTE_BBDEV_EVENT_DEQUEUE, &deq_intr_det);
461 : 0 : break;
462 : 0 : default:
463 : 0 : rte_bbdev_pmd_callback_process(dev, RTE_BBDEV_EVENT_ERROR, NULL);
464 : 0 : break;
465 : : }
466 : : } else {
467 : : rte_bbdev_log_debug(
468 : : "VRB VF Interrupt received, Info Ring data: 0x%x",
469 : : ring_data->val);
470 [ # # ]: 0 : switch (int_nb) {
471 [ # # ]: 0 : case ACC_VF_INT_DMA_DL_DESC_IRQ:
472 : : case ACC_VF_INT_DMA_UL_DESC_IRQ:
473 : : case ACC_VF_INT_DMA_FFT_DESC_IRQ:
474 : : case ACC_VF_INT_DMA_UL5G_DESC_IRQ:
475 : : case ACC_VF_INT_DMA_DL5G_DESC_IRQ:
476 : : case ACC_VF_INT_DMA_MLD_DESC_IRQ:
477 : : /* VFs are not aware of their vf_id - it's set to 0. */
478 : : set_vf_in_ring(ring_data, acc_dev->device_variant, 0);
479 : 0 : deq_intr_det.queue_id = get_queue_id_from_ring_info(
480 : : dev->data, *ring_data);
481 [ # # ]: 0 : if (deq_intr_det.queue_id == UINT16_MAX) {
482 : 0 : rte_bbdev_log(ERR,
483 : : "Couldn't find queue: aq_id: %u, qg_id: %u",
484 : : aq_id, qg_id);
485 : 0 : return;
486 : : }
487 : 0 : rte_bbdev_pmd_callback_process(dev,
488 : : RTE_BBDEV_EVENT_DEQUEUE, &deq_intr_det);
489 : 0 : break;
490 : 0 : default:
491 : 0 : rte_bbdev_pmd_callback_process(dev, RTE_BBDEV_EVENT_ERROR, NULL);
492 : 0 : break;
493 : : }
494 : : }
495 : :
496 : : /* Initialize Info Ring entry and move forward. */
497 : 0 : ring_data->val = 0;
498 : 0 : ++acc_dev->info_ring_head;
499 : 0 : ring_data = acc_dev->info_ring + (acc_dev->info_ring_head & ACC_INFO_RING_MASK);
500 : : }
501 : : }
502 : :
503 : : /* Allocate and setup inforing. */
504 : : static int
505 : 0 : allocate_info_ring(struct rte_bbdev *dev)
506 : : {
507 : 0 : struct acc_device *d = dev->data->dev_private;
508 : : rte_iova_t info_ring_iova;
509 : : uint32_t phys_low, phys_high;
510 : :
511 [ # # ]: 0 : if (d->info_ring != NULL)
512 : : return 0; /* Already configured. */
513 : :
514 : : /* Allocate InfoRing */
515 : 0 : d->info_ring = rte_zmalloc_socket("Info Ring", ACC_INFO_RING_NUM_ENTRIES *
516 : : sizeof(*d->info_ring), RTE_CACHE_LINE_SIZE, dev->data->socket_id);
517 [ # # ]: 0 : if (d->info_ring == NULL) {
518 : 0 : rte_bbdev_log(ERR,
519 : : "Failed to allocate Info Ring for %s:%u",
520 : : dev->device->driver->name,
521 : : dev->data->dev_id);
522 : 0 : return -ENOMEM;
523 : : }
524 : 0 : info_ring_iova = rte_malloc_virt2iova(d->info_ring);
525 : :
526 : : /* Setup Info Ring. */
527 : 0 : phys_high = (uint32_t)(info_ring_iova >> 32);
528 : 0 : phys_low = (uint32_t)(info_ring_iova);
529 : 0 : acc_reg_write(d, d->reg_addr->info_ring_hi, phys_high);
530 : 0 : acc_reg_write(d, d->reg_addr->info_ring_lo, phys_low);
531 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT)
532 : 0 : acc_reg_write(d, d->reg_addr->info_ring_en, VRB1_REG_IRQ_EN_ALL);
533 : : else
534 : 0 : acc_reg_write(d, d->reg_addr->info_ring_en, VRB2_REG_IRQ_EN_ALL);
535 : 0 : d->info_ring_head = (acc_reg_read(d, d->reg_addr->info_ring_ptr) &
536 : 0 : 0xFFF) / sizeof(union acc_info_ring_data);
537 : 0 : return 0;
538 : : }
539 : :
540 : :
541 : : /* Allocate 64MB memory used for all software rings. */
542 : : static int
543 : 0 : vrb_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id)
544 : : {
545 : : uint32_t phys_low, phys_high, value;
546 : 0 : struct acc_device *d = dev->data->dev_private;
547 : : uint16_t queues_per_op, i;
548 : : int ret, max_queues = 0;
549 : :
550 [ # # # # ]: 0 : if (d->pf_device && !d->acc_conf.pf_mode_en) {
551 : 0 : rte_bbdev_log(NOTICE,
552 : : "%s has PF mode disabled. This PF can't be used.",
553 : : dev->data->name);
554 : 0 : return -ENODEV;
555 : : }
556 [ # # # # ]: 0 : if (!d->pf_device && d->acc_conf.pf_mode_en) {
557 : 0 : rte_bbdev_log(NOTICE,
558 : : "%s has PF mode enabled. This VF can't be used.",
559 : : dev->data->name);
560 : 0 : return -ENODEV;
561 : : }
562 : :
563 [ # # ]: 0 : if (!vrb_check_device_enable(dev)) {
564 : 0 : rte_bbdev_log(NOTICE, "%s has no queue enabled and can't be used.",
565 : : dev->data->name);
566 : 0 : return -ENODEV;
567 : : }
568 : :
569 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
570 : 0 : alloc_sw_rings_min_mem(dev, d, num_queues, socket_id);
571 : :
572 : : /* If minimal memory space approach failed, then allocate
573 : : * the 2 * 64MB block for the sw rings.
574 : : */
575 [ # # ]: 0 : if (d->sw_rings == NULL)
576 : 0 : alloc_2x64mb_sw_rings_mem(dev, d, socket_id);
577 : :
578 [ # # ]: 0 : if (d->sw_rings == NULL) {
579 : 0 : rte_bbdev_log(NOTICE, "Failure allocating sw_rings memory");
580 : 0 : return -ENOMEM;
581 : : }
582 [ # # ]: 0 : } else if (d->device_variant == VRB2_VARIANT) {
583 : 0 : queues_per_op = RTE_MIN(VRB2_MAX_Q_PER_OP, num_queues);
584 [ # # ]: 0 : for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) {
585 : 0 : alloc_sw_rings_min_mem(dev, d, queues_per_op, socket_id);
586 [ # # ]: 0 : if (d->sw_rings == NULL) {
587 : 0 : rte_bbdev_log(NOTICE, "Failure allocating sw_rings memory %d", i);
588 : 0 : return -ENOMEM;
589 : : }
590 : : /* Moves the pointer to the relevant array. */
591 : 0 : d->sw_rings_array[i] = d->sw_rings;
592 : 0 : d->sw_rings_iova_array[i] = d->sw_rings_iova;
593 : 0 : d->sw_rings = NULL;
594 : 0 : d->sw_rings_base = NULL;
595 : 0 : d->sw_rings_iova = 0;
596 : 0 : d->queue_index[i] = 0;
597 : : }
598 : : }
599 : :
600 : : /* Read the populated cfg from device registers. */
601 : 0 : fetch_acc_config(dev);
602 : :
603 : : /* Start Pmon */
604 [ # # ]: 0 : for (value = 0; value <= 2; value++) {
605 : 0 : acc_reg_write(d, d->reg_addr->pmon_ctrl_a, value);
606 : 0 : acc_reg_write(d, d->reg_addr->pmon_ctrl_b, value);
607 : 0 : acc_reg_write(d, d->reg_addr->pmon_ctrl_c, value);
608 : : }
609 : :
610 : : /* Release AXI from PF. */
611 [ # # ]: 0 : if (d->pf_device)
612 : : acc_reg_write(d, VRB1_PfDmaAxiControl, 1);
613 : :
614 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
615 : : /* Configure device with the base address for DMA descriptor rings.
616 : : * Same descriptor rings used for UL and DL DMA Engines.
617 : : * Note : Assuming only VF0 bundle is used for PF mode.
618 : : */
619 : 0 : phys_high = (uint32_t)(d->sw_rings_iova >> 32);
620 : 0 : phys_low = (uint32_t)(d->sw_rings_iova & ~(ACC_SIZE_64MBYTE-1));
621 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul5g_hi, phys_high);
622 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul5g_lo, phys_low);
623 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl5g_hi, phys_high);
624 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl5g_lo, phys_low);
625 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul4g_hi, phys_high);
626 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul4g_lo, phys_low);
627 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl4g_hi, phys_high);
628 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl4g_lo, phys_low);
629 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_fft_hi, phys_high);
630 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_fft_lo, phys_low);
631 [ # # ]: 0 : } else if (d->device_variant == VRB2_VARIANT) {
632 : : /* Configure device with the base address for DMA descriptor rings.
633 : : * Different ring buffer used for each operation type.
634 : : * Note : Assuming only VF0 bundle is used for PF mode.
635 : : */
636 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul5g_hi,
637 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_LDPC_DEC] >> 32));
638 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul5g_lo,
639 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_LDPC_DEC]
640 : : & ~(ACC_SIZE_64MBYTE - 1)));
641 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl5g_hi,
642 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_LDPC_ENC] >> 32));
643 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl5g_lo,
644 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_LDPC_ENC]
645 : : & ~(ACC_SIZE_64MBYTE - 1)));
646 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul4g_hi,
647 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_TURBO_DEC] >> 32));
648 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_ul4g_lo,
649 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_TURBO_DEC]
650 : : & ~(ACC_SIZE_64MBYTE - 1)));
651 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl4g_hi,
652 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_TURBO_ENC] >> 32));
653 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_dl4g_lo,
654 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_TURBO_ENC]
655 : : & ~(ACC_SIZE_64MBYTE - 1)));
656 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_fft_hi,
657 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_FFT] >> 32));
658 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_fft_lo,
659 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_FFT]
660 : : & ~(ACC_SIZE_64MBYTE - 1)));
661 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_mld_hi,
662 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_MLDTS] >> 32));
663 : 0 : acc_reg_write(d, d->reg_addr->dma_ring_mld_lo,
664 : 0 : (uint32_t)(d->sw_rings_iova_array[RTE_BBDEV_OP_MLDTS]
665 : : & ~(ACC_SIZE_64MBYTE - 1)));
666 : : }
667 : :
668 : : /*
669 : : * Configure Ring Size to the max queue ring size
670 : : * (used for wrapping purpose).
671 : : */
672 [ # # ]: 0 : value = log2_basic(d->sw_ring_size / ACC_RING_SIZE_GRANULARITY);
673 : 0 : acc_reg_write(d, d->reg_addr->ring_size, value);
674 : :
675 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT)
676 : : max_queues = VRB1_NUM_QGRPS * VRB1_NUM_AQS;
677 [ # # ]: 0 : else if (d->device_variant == VRB2_VARIANT)
678 : : max_queues = VRB2_NUM_QGRPS * VRB2_NUM_AQS;
679 : :
680 : : /* Configure tail pointer for use when SDONE enabled. */
681 [ # # ]: 0 : if (d->tail_ptrs == NULL)
682 : 0 : d->tail_ptrs = rte_zmalloc_socket(dev->device->driver->name,
683 : : max_queues * sizeof(uint32_t),
684 : : RTE_CACHE_LINE_SIZE, socket_id);
685 [ # # ]: 0 : if (d->tail_ptrs == NULL) {
686 : 0 : rte_bbdev_log(ERR, "Failed to allocate tail ptr for %s:%u",
687 : : dev->device->driver->name,
688 : : dev->data->dev_id);
689 : : ret = -ENOMEM;
690 : 0 : goto free_sw_rings;
691 : : }
692 : 0 : d->tail_ptr_iova = rte_malloc_virt2iova(d->tail_ptrs);
693 : :
694 : 0 : phys_high = (uint32_t)(d->tail_ptr_iova >> 32);
695 : 0 : phys_low = (uint32_t)(d->tail_ptr_iova);
696 : : {
697 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_ul5g_hi, phys_high);
698 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_ul5g_lo, phys_low);
699 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_dl5g_hi, phys_high);
700 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_dl5g_lo, phys_low);
701 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_ul4g_hi, phys_high);
702 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_ul4g_lo, phys_low);
703 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_dl4g_hi, phys_high);
704 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_dl4g_lo, phys_low);
705 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_fft_hi, phys_high);
706 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_fft_lo, phys_low);
707 [ # # ]: 0 : if (d->device_variant == VRB2_VARIANT) {
708 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_mld_hi, phys_high);
709 : 0 : acc_reg_write(d, d->reg_addr->tail_ptrs_mld_lo, phys_low);
710 : : }
711 : : }
712 : :
713 : 0 : ret = allocate_info_ring(dev);
714 [ # # ]: 0 : if (ret < 0) {
715 : 0 : rte_bbdev_log(ERR, "Failed to allocate info_ring for %s:%u",
716 : : dev->device->driver->name,
717 : : dev->data->dev_id);
718 : : /* Continue */
719 : : }
720 : :
721 [ # # ]: 0 : if (d->harq_layout == NULL)
722 : 0 : d->harq_layout = rte_zmalloc_socket("HARQ Layout",
723 : : ACC_HARQ_LAYOUT * sizeof(*d->harq_layout),
724 : 0 : RTE_CACHE_LINE_SIZE, dev->data->socket_id);
725 [ # # ]: 0 : if (d->harq_layout == NULL) {
726 : 0 : rte_bbdev_log(ERR, "Failed to allocate harq_layout for %s:%u",
727 : : dev->device->driver->name,
728 : : dev->data->dev_id);
729 : : ret = -ENOMEM;
730 : 0 : goto free_tail_ptrs;
731 : : }
732 : :
733 : : /* Mark as configured properly */
734 : 0 : d->configured = true;
735 : : vrb_vf2pf(d, ACC_VF2PF_USING_VF);
736 : :
737 : : rte_bbdev_log_debug(
738 : : "Device (%s) configured sw_rings = %p, sw_rings_iova = %#"
739 : : PRIx64, dev->data->name, d->sw_rings, d->sw_rings_iova);
740 : 0 : return 0;
741 : :
742 : : free_tail_ptrs:
743 : 0 : rte_free(d->tail_ptrs);
744 : 0 : d->tail_ptrs = NULL;
745 : 0 : free_sw_rings:
746 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
747 : 0 : rte_free(d->sw_rings_base);
748 : 0 : d->sw_rings_base = NULL;
749 : 0 : d->sw_rings = NULL;
750 [ # # ]: 0 : } else if (d->device_variant == VRB2_VARIANT) {
751 [ # # ]: 0 : for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) {
752 : 0 : rte_free(d->sw_rings_array[i]);
753 : 0 : d->sw_rings_array[i] = 0;
754 : : }
755 : : }
756 : :
757 : : return ret;
758 : : }
759 : :
760 : : static int
761 : 0 : vrb_intr_enable(struct rte_bbdev *dev)
762 : : {
763 : : int ret;
764 : 0 : struct acc_device *d = dev->data->dev_private;
765 : :
766 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
767 : : /* On VRB1: cannot enable MSI/IR to avoid potential back-pressure corner case. */
768 : 0 : rte_bbdev_log(ERR, "VRB1 (%s) doesn't support any MSI/MSI-X interrupt",
769 : : dev->data->name);
770 : 0 : return -ENOTSUP;
771 : : }
772 : :
773 : : /*
774 : : * MSI/MSI-X are supported.
775 : : * Option controlled by vfio-intr through EAL parameter.
776 : : */
777 [ # # ]: 0 : if (rte_intr_type_get(dev->intr_handle) == RTE_INTR_HANDLE_VFIO_MSI) {
778 : :
779 : 0 : ret = allocate_info_ring(dev);
780 [ # # ]: 0 : if (ret < 0) {
781 : 0 : rte_bbdev_log(ERR,
782 : : "Couldn't allocate info ring for device: %s",
783 : : dev->data->name);
784 : 0 : return ret;
785 : : }
786 : 0 : ret = rte_intr_enable(dev->intr_handle);
787 [ # # ]: 0 : if (ret < 0) {
788 : 0 : rte_bbdev_log(ERR,
789 : : "Couldn't enable interrupts for device: %s",
790 : : dev->data->name);
791 : 0 : rte_free(d->info_ring);
792 : 0 : d->info_ring = NULL;
793 : 0 : return ret;
794 : : }
795 : 0 : ret = rte_intr_callback_register(dev->intr_handle,
796 : : vrb_dev_interrupt_handler, dev);
797 [ # # ]: 0 : if (ret < 0) {
798 : 0 : rte_bbdev_log(ERR,
799 : : "Couldn't register interrupt callback for device: %s",
800 : : dev->data->name);
801 : 0 : rte_free(d->info_ring);
802 : 0 : d->info_ring = NULL;
803 : 0 : return ret;
804 : : }
805 : :
806 : : return 0;
807 [ # # ]: 0 : } else if (rte_intr_type_get(dev->intr_handle) == RTE_INTR_HANDLE_VFIO_MSIX) {
808 : : int i, max_queues;
809 : 0 : struct acc_device *acc_dev = dev->data->dev_private;
810 : :
811 : 0 : ret = allocate_info_ring(dev);
812 [ # # ]: 0 : if (ret < 0) {
813 : 0 : rte_bbdev_log(ERR,
814 : : "Couldn't allocate info ring for device: %s",
815 : : dev->data->name);
816 : 0 : return ret;
817 : : }
818 : :
819 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
820 [ # # ]: 0 : if (acc_dev->pf_device)
821 : : max_queues = VRB1_MAX_PF_MSIX;
822 : : else
823 : : max_queues = VRB1_MAX_VF_MSIX;
824 : : } else {
825 [ # # ]: 0 : if (acc_dev->pf_device)
826 : : max_queues = VRB2_MAX_PF_MSIX;
827 : : else
828 : : max_queues = VRB2_MAX_VF_MSIX;
829 : : }
830 : :
831 [ # # ]: 0 : if (rte_intr_efd_enable(dev->intr_handle, max_queues)) {
832 : 0 : rte_bbdev_log(ERR, "Failed to create fds for %u queues",
833 : : dev->data->num_queues);
834 : 0 : return -1;
835 : : }
836 : :
837 [ # # ]: 0 : for (i = 0; i < max_queues; ++i) {
838 [ # # ]: 0 : if (rte_intr_efds_index_set(dev->intr_handle, i,
839 : 0 : rte_intr_fd_get(dev->intr_handle)))
840 : 0 : return -rte_errno;
841 : : }
842 : :
843 [ # # ]: 0 : if (rte_intr_vec_list_alloc(dev->intr_handle, "intr_vec",
844 : 0 : dev->data->num_queues)) {
845 : 0 : rte_bbdev_log(ERR, "Failed to allocate %u vectors",
846 : : dev->data->num_queues);
847 : 0 : return -ENOMEM;
848 : : }
849 : :
850 : 0 : ret = rte_intr_enable(dev->intr_handle);
851 : :
852 [ # # ]: 0 : if (ret < 0) {
853 : 0 : rte_bbdev_log(ERR,
854 : : "Couldn't enable interrupts for device: %s",
855 : : dev->data->name);
856 : 0 : rte_free(d->info_ring);
857 : 0 : d->info_ring = NULL;
858 : 0 : return ret;
859 : : }
860 : 0 : ret = rte_intr_callback_register(dev->intr_handle,
861 : : vrb_dev_interrupt_handler, dev);
862 [ # # ]: 0 : if (ret < 0) {
863 : 0 : rte_bbdev_log(ERR,
864 : : "Couldn't register interrupt callback for device: %s",
865 : : dev->data->name);
866 : 0 : rte_free(d->info_ring);
867 : 0 : d->info_ring = NULL;
868 : 0 : return ret;
869 : : }
870 : :
871 : : return 0;
872 : : }
873 : :
874 : 0 : rte_bbdev_log(ERR, "Device (%s) supports only VFIO MSI/MSI-X interrupts",
875 : : dev->data->name);
876 : 0 : return -ENOTSUP;
877 : : }
878 : :
879 : : /* Free memory used for software rings. */
880 : : static int
881 : 0 : vrb_dev_close(struct rte_bbdev *dev)
882 : : {
883 : : int i;
884 : 0 : struct acc_device *d = dev->data->dev_private;
885 : :
886 : 0 : vrb_check_ir(d);
887 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
888 : 0 : rte_free(d->tail_ptrs);
889 : 0 : rte_free(d->info_ring);
890 : 0 : rte_free(d->sw_rings_base);
891 : 0 : rte_free(d->harq_layout);
892 : 0 : d->tail_ptrs = NULL;
893 : 0 : d->info_ring = NULL;
894 : 0 : d->sw_rings_base = NULL;
895 : 0 : d->sw_rings = NULL;
896 : 0 : d->harq_layout = NULL;
897 [ # # ]: 0 : } else if (d->device_variant == VRB2_VARIANT) {
898 : 0 : rte_free(d->tail_ptrs);
899 : 0 : rte_free(d->info_ring);
900 : 0 : rte_free(d->harq_layout);
901 : 0 : d->tail_ptrs = NULL;
902 : 0 : d->info_ring = NULL;
903 : 0 : d->harq_layout = NULL;
904 [ # # ]: 0 : for (i = 0; i <= RTE_BBDEV_OP_MLDTS; i++) {
905 : 0 : rte_free(d->sw_rings_array[i]);
906 : 0 : d->sw_rings_array[i] = NULL;
907 : : }
908 : : }
909 : : /* Ensure all in flight HW transactions are completed. */
910 : 0 : usleep(ACC_LONG_WAIT);
911 : 0 : return 0;
912 : : }
913 : :
914 : : /**
915 : : * Report a queue index which is free.
916 : : * Return 0 to 16k for a valid queue_idx or -1 when no queue is available.
917 : : * Note : Only supporting VF0 Bundle for PF mode.
918 : : */
919 : : static int
920 : 0 : vrb_find_free_queue_idx(struct rte_bbdev *dev,
921 : : const struct rte_bbdev_queue_conf *conf)
922 : : {
923 : 0 : struct acc_device *d = dev->data->dev_private;
924 : 0 : int op_2_acc[7] = {0, UL_4G, DL_4G, UL_5G, DL_5G, FFT, MLD};
925 : 0 : int acc = op_2_acc[conf->op_type];
926 : 0 : struct rte_acc_queue_topology *qtop = NULL;
927 : : uint16_t group_idx;
928 : : uint64_t aq_idx;
929 : :
930 : 0 : qtopFromAcc(&qtop, acc, &(d->acc_conf));
931 [ # # ]: 0 : if (qtop == NULL)
932 : : return -1;
933 : : /* Identify matching QGroup Index which are sorted in priority order. */
934 : 0 : group_idx = qtop->first_qgroup_index + conf->priority;
935 [ # # ]: 0 : if (group_idx >= d->num_qgroups ||
936 [ # # ]: 0 : conf->priority >= qtop->num_qgroups) {
937 : 0 : rte_bbdev_log(INFO, "Invalid Priority on %s, priority %u",
938 : : dev->data->name, conf->priority);
939 : 0 : return -1;
940 : : }
941 : : /* Find a free AQ_idx. */
942 [ # # ]: 0 : for (aq_idx = 0; aq_idx < qtop->num_aqs_per_groups; aq_idx++) {
943 [ # # ]: 0 : if (((d->q_assigned_bit_map[group_idx] >> aq_idx) & 0x1) == 0) {
944 : : /* Mark the Queue as assigned. */
945 : 0 : d->q_assigned_bit_map[group_idx] |= (1ULL << aq_idx);
946 : : /* Report the AQ Index. */
947 [ # # ]: 0 : return queue_index(group_idx, aq_idx, d->device_variant);
948 : : }
949 : : }
950 : 0 : rte_bbdev_log(INFO, "Failed to find free queue on %s, priority %u",
951 : : dev->data->name, conf->priority);
952 : 0 : return -1;
953 : : }
954 : :
955 : : /* Setup device queue. */
956 : : static int
957 : 0 : vrb_queue_setup(struct rte_bbdev *dev, uint16_t queue_id,
958 : : const struct rte_bbdev_queue_conf *conf)
959 : : {
960 : 0 : struct acc_device *d = dev->data->dev_private;
961 : : struct acc_queue *q;
962 : : int32_t q_idx;
963 : : int ret;
964 : : union acc_dma_desc *desc = NULL;
965 : : unsigned int desc_idx, b_idx;
966 : : int fcw_len;
967 : :
968 [ # # ]: 0 : if (d == NULL) {
969 : 0 : rte_bbdev_log(ERR, "Undefined device");
970 : 0 : return -ENODEV;
971 : : }
972 : : /* Allocate the queue data structure. */
973 : 0 : q = rte_zmalloc_socket(dev->device->driver->name, sizeof(*q),
974 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
975 [ # # ]: 0 : if (q == NULL) {
976 : 0 : rte_bbdev_log(ERR, "Failed to allocate queue memory");
977 : 0 : return -ENOMEM;
978 : : }
979 : :
980 : 0 : q->d = d;
981 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT) {
982 : 0 : q->ring_addr = RTE_PTR_ADD(d->sw_rings, (d->sw_ring_size * queue_id));
983 : 0 : q->ring_addr_iova = d->sw_rings_iova + (d->sw_ring_size * queue_id);
984 [ # # ]: 0 : } else if (d->device_variant == VRB2_VARIANT) {
985 : 0 : q->ring_addr = RTE_PTR_ADD(d->sw_rings_array[conf->op_type],
986 : : (d->sw_ring_size * d->queue_index[conf->op_type]));
987 : 0 : q->ring_addr_iova = d->sw_rings_iova_array[conf->op_type] +
988 : : (d->sw_ring_size * d->queue_index[conf->op_type]);
989 : 0 : d->queue_index[conf->op_type]++;
990 : : }
991 : :
992 : : /* Prepare the Ring with default descriptor format. */
993 [ # # # # : 0 : switch (conf->op_type) {
# ]
994 : : case RTE_BBDEV_OP_LDPC_ENC:
995 : : fcw_len = ACC_FCW_LE_BLEN;
996 : : break;
997 : 0 : case RTE_BBDEV_OP_LDPC_DEC:
998 : : fcw_len = ACC_FCW_LD_BLEN;
999 : 0 : break;
1000 : 0 : case RTE_BBDEV_OP_TURBO_DEC:
1001 : : fcw_len = ACC_FCW_TD_BLEN;
1002 : 0 : break;
1003 : : case RTE_BBDEV_OP_TURBO_ENC:
1004 : : fcw_len = ACC_FCW_TE_BLEN;
1005 : : break;
1006 : 0 : case RTE_BBDEV_OP_FFT:
1007 : : fcw_len = ACC_FCW_FFT_BLEN;
1008 [ # # ]: 0 : if (q->d->device_variant == VRB2_VARIANT)
1009 : : fcw_len = ACC_FCW_FFT_BLEN_VRB2;
1010 : : break;
1011 : : case RTE_BBDEV_OP_MLDTS:
1012 : : fcw_len = ACC_FCW_MLDTS_BLEN;
1013 : : break;
1014 : 0 : default:
1015 : : /* NOT REACHED. */
1016 : : fcw_len = 0;
1017 : 0 : rte_bbdev_log(ERR, "Unexpected error in %s using type %d", __func__, conf->op_type);
1018 : 0 : break;
1019 : : }
1020 : :
1021 [ # # ]: 0 : for (desc_idx = 0; desc_idx < d->sw_ring_max_depth; desc_idx++) {
1022 : 0 : desc = q->ring_addr + desc_idx;
1023 : 0 : desc->req.word0 = ACC_DMA_DESC_TYPE;
1024 : 0 : desc->req.word1 = 0; /**< Timestamp. */
1025 : 0 : desc->req.word2 = 0;
1026 : 0 : desc->req.word3 = 0;
1027 : 0 : uint64_t fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
1028 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
1029 : 0 : desc->req.data_ptrs[0].blen = fcw_len;
1030 : 0 : desc->req.data_ptrs[0].blkid = ACC_DMA_BLKID_FCW;
1031 : 0 : desc->req.data_ptrs[0].last = 0;
1032 : 0 : desc->req.data_ptrs[0].dma_ext = 0;
1033 [ # # ]: 0 : for (b_idx = 1; b_idx < ACC_DMA_MAX_NUM_POINTERS - 1; b_idx++) {
1034 : 0 : desc->req.data_ptrs[b_idx].blkid = ACC_DMA_BLKID_IN;
1035 : 0 : desc->req.data_ptrs[b_idx].last = 1;
1036 : 0 : desc->req.data_ptrs[b_idx].dma_ext = 0;
1037 : 0 : b_idx++;
1038 : 0 : desc->req.data_ptrs[b_idx].blkid =
1039 : : ACC_DMA_BLKID_OUT_ENC;
1040 : 0 : desc->req.data_ptrs[b_idx].last = 1;
1041 : 0 : desc->req.data_ptrs[b_idx].dma_ext = 0;
1042 : : }
1043 : : /* Preset some fields of LDPC FCW. */
1044 : 0 : desc->req.fcw_ld.FCWversion = ACC_FCW_VER;
1045 : 0 : desc->req.fcw_ld.gain_i = 1;
1046 : 0 : desc->req.fcw_ld.gain_h = 1;
1047 : : }
1048 : :
1049 : 0 : q->lb_in = rte_zmalloc_socket(dev->device->driver->name,
1050 : : RTE_CACHE_LINE_SIZE,
1051 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
1052 [ # # ]: 0 : if (q->lb_in == NULL) {
1053 : 0 : rte_bbdev_log(ERR, "Failed to allocate lb_in memory");
1054 : : ret = -ENOMEM;
1055 : 0 : goto free_q;
1056 : : }
1057 : 0 : q->lb_in_addr_iova = rte_malloc_virt2iova(q->lb_in);
1058 : 0 : q->lb_out = rte_zmalloc_socket(dev->device->driver->name,
1059 : : RTE_CACHE_LINE_SIZE,
1060 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
1061 [ # # ]: 0 : if (q->lb_out == NULL) {
1062 : 0 : rte_bbdev_log(ERR, "Failed to allocate lb_out memory");
1063 : : ret = -ENOMEM;
1064 : 0 : goto free_lb_in;
1065 : : }
1066 : 0 : q->lb_out_addr_iova = rte_malloc_virt2iova(q->lb_out);
1067 : 0 : q->companion_ring_addr = rte_zmalloc_socket(dev->device->driver->name,
1068 : 0 : d->sw_ring_max_depth * sizeof(*q->companion_ring_addr),
1069 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
1070 [ # # ]: 0 : if (q->companion_ring_addr == NULL) {
1071 : 0 : rte_bbdev_log(ERR, "Failed to allocate companion_ring memory");
1072 : : ret = -ENOMEM;
1073 : 0 : goto free_lb_out;
1074 : : }
1075 : :
1076 : : /*
1077 : : * Software queue ring wraps synchronously with the HW when it reaches
1078 : : * the boundary of the maximum allocated queue size, no matter what the
1079 : : * sw queue size is. This wrapping is guarded by setting the wrap_mask
1080 : : * to represent the maximum queue size as allocated at the time when
1081 : : * the device has been setup (in configure()).
1082 : : *
1083 : : * The queue depth is set to the queue size value (conf->queue_size).
1084 : : * This limits the occupancy of the queue at any point of time, so that
1085 : : * the queue does not get swamped with enqueue requests.
1086 : : */
1087 : 0 : q->sw_ring_depth = conf->queue_size;
1088 : 0 : q->sw_ring_wrap_mask = d->sw_ring_max_depth - 1;
1089 : :
1090 : 0 : q->op_type = conf->op_type;
1091 : :
1092 : 0 : q_idx = vrb_find_free_queue_idx(dev, conf);
1093 [ # # ]: 0 : if (q_idx == -1) {
1094 : : ret = -EINVAL;
1095 : 0 : goto free_companion_ring_addr;
1096 : : }
1097 : :
1098 : 0 : q->fcw_ring = rte_zmalloc_socket(dev->device->driver->name,
1099 : 0 : ACC_MAX_FCW_SIZE * d->sw_ring_max_depth,
1100 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
1101 [ # # ]: 0 : if (q->fcw_ring == NULL) {
1102 : 0 : rte_bbdev_log(ERR, "Failed to allocate fcw_ring memory");
1103 : : ret = -ENOMEM;
1104 : 0 : goto free_companion_ring_addr;
1105 : : }
1106 : 0 : q->fcw_ring_addr_iova = rte_malloc_virt2iova(q->fcw_ring);
1107 : :
1108 : : /* For FFT we need to store the FCW separately */
1109 [ # # ]: 0 : if (conf->op_type == RTE_BBDEV_OP_FFT) {
1110 [ # # ]: 0 : for (desc_idx = 0; desc_idx < d->sw_ring_max_depth; desc_idx++) {
1111 : 0 : desc = q->ring_addr + desc_idx;
1112 : 0 : desc->req.data_ptrs[0].address = q->fcw_ring_addr_iova +
1113 : 0 : desc_idx * ACC_MAX_FCW_SIZE;
1114 : : }
1115 : : }
1116 : :
1117 [ # # # # ]: 0 : q->qgrp_id = qg_from_q(q_idx, d->device_variant);
1118 [ # # ]: 0 : q->vf_id = vf_from_q(q_idx, d->device_variant);
1119 : 0 : q->aq_id = aq_from_q(q_idx, d->device_variant);
1120 : :
1121 : 0 : q->aq_depth = 0;
1122 [ # # ]: 0 : if (conf->op_type == RTE_BBDEV_OP_TURBO_DEC)
1123 : 0 : q->aq_depth = (1 << d->acc_conf.q_ul_4g.aq_depth_log2);
1124 : : else if (conf->op_type == RTE_BBDEV_OP_TURBO_ENC)
1125 : 0 : q->aq_depth = (1 << d->acc_conf.q_dl_4g.aq_depth_log2);
1126 : : else if (conf->op_type == RTE_BBDEV_OP_LDPC_DEC)
1127 : 0 : q->aq_depth = (1 << d->acc_conf.q_ul_5g.aq_depth_log2);
1128 : : else if (conf->op_type == RTE_BBDEV_OP_LDPC_ENC)
1129 : 0 : q->aq_depth = (1 << d->acc_conf.q_dl_5g.aq_depth_log2);
1130 : : else if (conf->op_type == RTE_BBDEV_OP_FFT)
1131 : 0 : q->aq_depth = (1 << d->acc_conf.q_fft.aq_depth_log2);
1132 : : else if (conf->op_type == RTE_BBDEV_OP_MLDTS)
1133 : 0 : q->aq_depth = (1 << d->acc_conf.q_mld.aq_depth_log2);
1134 : :
1135 : 0 : q->mmio_reg_enqueue = RTE_PTR_ADD(d->mmio_base,
1136 : : d->queue_offset(d->pf_device, q->vf_id, q->qgrp_id, q->aq_id));
1137 : :
1138 : : rte_bbdev_log_debug(
1139 : : "Setup dev%u q%u: qgrp_id=%u, vf_id=%u, aq_id=%u, aq_depth=%u, mmio_reg_enqueue=%p base %p",
1140 : : dev->data->dev_id, queue_id, q->qgrp_id, q->vf_id,
1141 : : q->aq_id, q->aq_depth, q->mmio_reg_enqueue,
1142 : : d->mmio_base);
1143 : :
1144 : 0 : dev->data->queues[queue_id].queue_private = q;
1145 : 0 : return 0;
1146 : :
1147 : 0 : free_companion_ring_addr:
1148 : 0 : rte_free(q->companion_ring_addr);
1149 : 0 : q->companion_ring_addr = NULL;
1150 : 0 : free_lb_out:
1151 : 0 : rte_free(q->lb_out);
1152 : 0 : q->lb_out = NULL;
1153 : 0 : free_lb_in:
1154 : 0 : rte_free(q->lb_in);
1155 : 0 : q->lb_in = NULL;
1156 : 0 : free_q:
1157 : 0 : rte_free(q);
1158 : : q = NULL;
1159 [ # # ]: 0 : if (d->device_variant == VRB2_VARIANT)
1160 : 0 : d->queue_index[conf->op_type]--;
1161 : :
1162 : : return ret;
1163 : : }
1164 : :
1165 : : /* Stop queue and clear counters. */
1166 : : static int
1167 : 0 : vrb_queue_stop(struct rte_bbdev *dev, uint16_t queue_id)
1168 : : {
1169 : : struct acc_queue *q;
1170 : :
1171 : 0 : q = dev->data->queues[queue_id].queue_private;
1172 : 0 : rte_bbdev_log(INFO, "Queue Stop %d H/T/D %d %d %x OpType %d",
1173 : : queue_id, q->sw_ring_head, q->sw_ring_tail,
1174 : : q->sw_ring_depth, q->op_type);
1175 : : /* ignore all operations in flight and clear counters */
1176 : 0 : q->sw_ring_tail = q->sw_ring_head;
1177 : 0 : q->aq_enqueued = 0;
1178 : 0 : q->aq_dequeued = 0;
1179 : 0 : dev->data->queues[queue_id].queue_stats.enqueued_count = 0;
1180 : 0 : dev->data->queues[queue_id].queue_stats.dequeued_count = 0;
1181 : 0 : dev->data->queues[queue_id].queue_stats.enqueue_err_count = 0;
1182 : 0 : dev->data->queues[queue_id].queue_stats.dequeue_err_count = 0;
1183 : 0 : dev->data->queues[queue_id].queue_stats.enqueue_warn_count = 0;
1184 : 0 : dev->data->queues[queue_id].queue_stats.dequeue_warn_count = 0;
1185 : 0 : dev->data->queues[queue_id].queue_stats.enqueue_depth_avail = 0;
1186 : 0 : return 0;
1187 : : }
1188 : :
1189 : : /* Release queue. */
1190 : : static int
1191 : 0 : vrb_queue_release(struct rte_bbdev *dev, uint16_t q_id)
1192 : : {
1193 : 0 : struct acc_device *d = dev->data->dev_private;
1194 : 0 : struct acc_queue *q = dev->data->queues[q_id].queue_private;
1195 : :
1196 [ # # ]: 0 : if (q != NULL) {
1197 : : /* Mark the Queue as un-assigned. */
1198 : 0 : d->q_assigned_bit_map[q->qgrp_id] &= (~0ULL - (1 << (uint64_t) q->aq_id));
1199 : 0 : rte_free(q->fcw_ring);
1200 : 0 : rte_free(q->companion_ring_addr);
1201 : 0 : rte_free(q->lb_in);
1202 : 0 : rte_free(q->lb_out);
1203 : 0 : rte_free(q);
1204 : 0 : dev->data->queues[q_id].queue_private = NULL;
1205 : : }
1206 : :
1207 : 0 : return 0;
1208 : : }
1209 : :
1210 : : /* Get device info. */
1211 : : static void
1212 : 0 : vrb_dev_info_get(struct rte_bbdev *dev, struct rte_bbdev_driver_info *dev_info)
1213 : : {
1214 : 0 : struct acc_device *d = dev->data->dev_private;
1215 : : int i;
1216 : : static const struct rte_bbdev_op_cap vrb1_bbdev_capabilities[] = {
1217 : : {
1218 : : .type = RTE_BBDEV_OP_TURBO_DEC,
1219 : : .cap.turbo_dec = {
1220 : : .capability_flags =
1221 : : RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE |
1222 : : RTE_BBDEV_TURBO_CRC_TYPE_24B |
1223 : : RTE_BBDEV_TURBO_DEC_CRC_24B_DROP |
1224 : : RTE_BBDEV_TURBO_HALF_ITERATION_EVEN |
1225 : : RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH |
1226 : : RTE_BBDEV_TURBO_EARLY_TERMINATION |
1227 : : RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN |
1228 : : RTE_BBDEV_TURBO_MAP_DEC |
1229 : : RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP |
1230 : : RTE_BBDEV_TURBO_DEC_SCATTER_GATHER,
1231 : : .max_llr_modulus = INT8_MAX,
1232 : : .num_buffers_src =
1233 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1234 : : .num_buffers_hard_out =
1235 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1236 : : .num_buffers_soft_out =
1237 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1238 : : }
1239 : : },
1240 : : {
1241 : : .type = RTE_BBDEV_OP_TURBO_ENC,
1242 : : .cap.turbo_enc = {
1243 : : .capability_flags =
1244 : : RTE_BBDEV_TURBO_CRC_24B_ATTACH |
1245 : : RTE_BBDEV_TURBO_RV_INDEX_BYPASS |
1246 : : RTE_BBDEV_TURBO_RATE_MATCH |
1247 : : RTE_BBDEV_TURBO_ENC_SCATTER_GATHER,
1248 : : .num_buffers_src =
1249 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1250 : : .num_buffers_dst =
1251 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1252 : : }
1253 : : },
1254 : : {
1255 : : .type = RTE_BBDEV_OP_LDPC_ENC,
1256 : : .cap.ldpc_enc = {
1257 : : .capability_flags =
1258 : : RTE_BBDEV_LDPC_RATE_MATCH |
1259 : : RTE_BBDEV_LDPC_CRC_24B_ATTACH |
1260 : : RTE_BBDEV_LDPC_INTERLEAVER_BYPASS,
1261 : : .num_buffers_src =
1262 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1263 : : .num_buffers_dst =
1264 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1265 : : }
1266 : : },
1267 : : {
1268 : : .type = RTE_BBDEV_OP_LDPC_DEC,
1269 : : .cap.ldpc_dec = {
1270 : : .capability_flags =
1271 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
1272 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
1273 : : RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK |
1274 : : RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK |
1275 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
1276 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
1277 : : RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE |
1278 : : RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS |
1279 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER |
1280 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION |
1281 : : RTE_BBDEV_LDPC_LLR_COMPRESSION,
1282 : : .llr_size = 8,
1283 : : .llr_decimals = 1,
1284 : : .num_buffers_src =
1285 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1286 : : .num_buffers_hard_out =
1287 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1288 : : .num_buffers_soft_out = 0,
1289 : : }
1290 : : },
1291 : : {
1292 : : .type = RTE_BBDEV_OP_FFT,
1293 : : .cap.fft = {
1294 : : .capability_flags =
1295 : : RTE_BBDEV_FFT_WINDOWING |
1296 : : RTE_BBDEV_FFT_CS_ADJUSTMENT |
1297 : : RTE_BBDEV_FFT_DFT_BYPASS |
1298 : : RTE_BBDEV_FFT_IDFT_BYPASS |
1299 : : RTE_BBDEV_FFT_WINDOWING_BYPASS,
1300 : : .num_buffers_src = 1,
1301 : : .num_buffers_dst = 1,
1302 : : .fft_windows_num = ACC_MAX_FFT_WIN,
1303 : : }
1304 : : },
1305 : : RTE_BBDEV_END_OF_CAPABILITIES_LIST()
1306 : : };
1307 : :
1308 : : static const struct rte_bbdev_op_cap vrb2_bbdev_capabilities[] = {
1309 : : {
1310 : : .type = RTE_BBDEV_OP_TURBO_DEC,
1311 : : .cap.turbo_dec = {
1312 : : .capability_flags =
1313 : : RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE |
1314 : : RTE_BBDEV_TURBO_CRC_TYPE_24B |
1315 : : RTE_BBDEV_TURBO_DEC_CRC_24B_DROP |
1316 : : RTE_BBDEV_TURBO_EQUALIZER |
1317 : : RTE_BBDEV_TURBO_SOFT_OUT_SATURATE |
1318 : : RTE_BBDEV_TURBO_HALF_ITERATION_EVEN |
1319 : : RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH |
1320 : : RTE_BBDEV_TURBO_SOFT_OUTPUT |
1321 : : RTE_BBDEV_TURBO_EARLY_TERMINATION |
1322 : : RTE_BBDEV_TURBO_DEC_INTERRUPTS |
1323 : : RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN |
1324 : : RTE_BBDEV_TURBO_NEG_LLR_1_BIT_SOFT_OUT |
1325 : : RTE_BBDEV_TURBO_MAP_DEC |
1326 : : RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP |
1327 : : RTE_BBDEV_TURBO_DEC_SCATTER_GATHER,
1328 : : .max_llr_modulus = INT8_MAX,
1329 : : .num_buffers_src =
1330 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1331 : : .num_buffers_hard_out =
1332 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1333 : : .num_buffers_soft_out =
1334 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1335 : : }
1336 : : },
1337 : : {
1338 : : .type = RTE_BBDEV_OP_TURBO_ENC,
1339 : : .cap.turbo_enc = {
1340 : : .capability_flags =
1341 : : RTE_BBDEV_TURBO_CRC_24B_ATTACH |
1342 : : RTE_BBDEV_TURBO_RV_INDEX_BYPASS |
1343 : : RTE_BBDEV_TURBO_RATE_MATCH |
1344 : : RTE_BBDEV_TURBO_ENC_INTERRUPTS |
1345 : : RTE_BBDEV_TURBO_ENC_SCATTER_GATHER,
1346 : : .num_buffers_src =
1347 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1348 : : .num_buffers_dst =
1349 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
1350 : : }
1351 : : },
1352 : : {
1353 : : .type = RTE_BBDEV_OP_LDPC_ENC,
1354 : : .cap.ldpc_enc = {
1355 : : .capability_flags =
1356 : : RTE_BBDEV_LDPC_RATE_MATCH |
1357 : : RTE_BBDEV_LDPC_CRC_24B_ATTACH |
1358 : : RTE_BBDEV_LDPC_INTERLEAVER_BYPASS |
1359 : : RTE_BBDEV_LDPC_ENC_INTERRUPTS |
1360 : : RTE_BBDEV_LDPC_ENC_SCATTER_GATHER |
1361 : : RTE_BBDEV_LDPC_ENC_CONCATENATION,
1362 : : .num_buffers_src =
1363 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1364 : : .num_buffers_dst =
1365 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1366 : : }
1367 : : },
1368 : : {
1369 : : .type = RTE_BBDEV_OP_LDPC_DEC,
1370 : : .cap.ldpc_dec = {
1371 : : .capability_flags =
1372 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
1373 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
1374 : : RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK |
1375 : : RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK |
1376 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
1377 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
1378 : : RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE |
1379 : : RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS |
1380 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER |
1381 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION |
1382 : : RTE_BBDEV_LDPC_HARQ_4BIT_COMPRESSION |
1383 : : RTE_BBDEV_LDPC_LLR_COMPRESSION |
1384 : : RTE_BBDEV_LDPC_SOFT_OUT_ENABLE |
1385 : : RTE_BBDEV_LDPC_SOFT_OUT_DEINTERLEAVER_BYPASS |
1386 : : RTE_BBDEV_LDPC_DEC_INTERRUPTS,
1387 : : .llr_size = 8,
1388 : : .llr_decimals = 1,
1389 : : .num_buffers_src =
1390 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1391 : : .num_buffers_hard_out =
1392 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
1393 : : .num_buffers_soft_out = 0,
1394 : : }
1395 : : },
1396 : : {
1397 : : .type = RTE_BBDEV_OP_FFT,
1398 : : .cap.fft = {
1399 : : .capability_flags =
1400 : : RTE_BBDEV_FFT_WINDOWING |
1401 : : RTE_BBDEV_FFT_CS_ADJUSTMENT |
1402 : : RTE_BBDEV_FFT_DFT_BYPASS |
1403 : : RTE_BBDEV_FFT_IDFT_BYPASS |
1404 : : RTE_BBDEV_FFT_FP16_INPUT |
1405 : : RTE_BBDEV_FFT_FP16_OUTPUT |
1406 : : RTE_BBDEV_FFT_POWER_MEAS |
1407 : : RTE_BBDEV_FFT_WINDOWING_BYPASS |
1408 : : RTE_BBDEV_FFT_TIMING_OFFSET_PER_CS |
1409 : : RTE_BBDEV_FFT_TIMING_ERROR |
1410 : : RTE_BBDEV_FFT_DEWINDOWING |
1411 : : RTE_BBDEV_FFT_FREQ_RESAMPLING,
1412 : : .num_buffers_src = 1,
1413 : : .num_buffers_dst = 1,
1414 : : .fft_windows_num = ACC_MAX_FFT_WIN,
1415 : : }
1416 : : },
1417 : : {
1418 : : .type = RTE_BBDEV_OP_MLDTS,
1419 : : .cap.mld = {
1420 : : .capability_flags =
1421 : : RTE_BBDEV_MLDTS_REP,
1422 : : .num_buffers_src =
1423 : : 1,
1424 : : .num_buffers_dst =
1425 : : 1,
1426 : : }
1427 : : },
1428 : : RTE_BBDEV_END_OF_CAPABILITIES_LIST()
1429 : : };
1430 : :
1431 : : static struct rte_bbdev_queue_conf default_queue_conf;
1432 : 0 : default_queue_conf.socket = dev->data->socket_id;
1433 : 0 : default_queue_conf.queue_size = ACC_MAX_QUEUE_DEPTH;
1434 : :
1435 : 0 : dev_info->driver_name = dev->device->driver->name;
1436 : :
1437 : : /* Read and save the populated config from registers. */
1438 : 0 : fetch_acc_config(dev);
1439 : : /* Check the status of device. */
1440 : 0 : dev_info->device_status = vrb_device_status(dev);
1441 : 0 : dev_info->fft_window_width = d->fft_window_width;
1442 : :
1443 : : /* Exposed number of queues. */
1444 : 0 : dev_info->num_queues[RTE_BBDEV_OP_NONE] = 0;
1445 : 0 : dev_info->num_queues[RTE_BBDEV_OP_TURBO_DEC] = d->acc_conf.q_ul_4g.num_aqs_per_groups *
1446 : 0 : d->acc_conf.q_ul_4g.num_qgroups;
1447 : 0 : dev_info->num_queues[RTE_BBDEV_OP_TURBO_ENC] = d->acc_conf.q_dl_4g.num_aqs_per_groups *
1448 : 0 : d->acc_conf.q_dl_4g.num_qgroups;
1449 : 0 : dev_info->num_queues[RTE_BBDEV_OP_LDPC_DEC] = d->acc_conf.q_ul_5g.num_aqs_per_groups *
1450 : 0 : d->acc_conf.q_ul_5g.num_qgroups;
1451 : 0 : dev_info->num_queues[RTE_BBDEV_OP_LDPC_ENC] = d->acc_conf.q_dl_5g.num_aqs_per_groups *
1452 : 0 : d->acc_conf.q_dl_5g.num_qgroups;
1453 : 0 : dev_info->num_queues[RTE_BBDEV_OP_FFT] = d->acc_conf.q_fft.num_aqs_per_groups *
1454 : 0 : d->acc_conf.q_fft.num_qgroups;
1455 : 0 : dev_info->num_queues[RTE_BBDEV_OP_MLDTS] = d->acc_conf.q_mld.num_aqs_per_groups *
1456 : 0 : d->acc_conf.q_mld.num_qgroups;
1457 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_TURBO_DEC] = d->acc_conf.q_ul_4g.num_qgroups;
1458 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_TURBO_ENC] = d->acc_conf.q_dl_4g.num_qgroups;
1459 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_LDPC_DEC] = d->acc_conf.q_ul_5g.num_qgroups;
1460 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_LDPC_ENC] = d->acc_conf.q_dl_5g.num_qgroups;
1461 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_FFT] = d->acc_conf.q_fft.num_qgroups;
1462 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_MLDTS] = d->acc_conf.q_mld.num_qgroups;
1463 : 0 : dev_info->max_num_queues = 0;
1464 [ # # ]: 0 : for (i = RTE_BBDEV_OP_NONE; i <= RTE_BBDEV_OP_MLDTS; i++) {
1465 [ # # ]: 0 : if (unlikely(dev_info->num_queues[i] > VRB2_MAX_Q_PER_OP)) {
1466 : 0 : rte_bbdev_log(ERR, "Unexpected number of queues %d exposed for op %d",
1467 : : dev_info->num_queues[i], i);
1468 : 0 : dev_info->num_queues[i] = VRB2_MAX_Q_PER_OP;
1469 : : }
1470 : 0 : dev_info->max_num_queues += dev_info->num_queues[i];
1471 : : }
1472 : 0 : dev_info->queue_size_lim = ACC_MAX_QUEUE_DEPTH;
1473 : 0 : dev_info->hardware_accelerated = true;
1474 : 0 : dev_info->max_dl_queue_priority =
1475 : 0 : d->acc_conf.q_dl_4g.num_qgroups - 1;
1476 : 0 : dev_info->max_ul_queue_priority =
1477 : 0 : d->acc_conf.q_ul_4g.num_qgroups - 1;
1478 : 0 : dev_info->default_queue_conf = default_queue_conf;
1479 : 0 : dev_info->cpu_flag_reqs = NULL;
1480 : 0 : dev_info->min_alignment = 1;
1481 [ # # ]: 0 : if (d->device_variant == VRB1_VARIANT)
1482 : 0 : dev_info->capabilities = vrb1_bbdev_capabilities;
1483 : : else
1484 : 0 : dev_info->capabilities = vrb2_bbdev_capabilities;
1485 : 0 : dev_info->harq_buffer_size = 0;
1486 : :
1487 : 0 : vrb_check_ir(d);
1488 : 0 : }
1489 : :
1490 : : static int
1491 : 0 : vrb_queue_intr_enable(struct rte_bbdev *dev, uint16_t queue_id)
1492 : : {
1493 : 0 : struct acc_queue *q = dev->data->queues[queue_id].queue_private;
1494 : :
1495 [ # # # # ]: 0 : if (rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_VFIO_MSI &&
1496 : 0 : rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_VFIO_MSIX)
1497 : : return -ENOTSUP;
1498 : :
1499 : 0 : q->irq_enable = 1;
1500 : 0 : return 0;
1501 : : }
1502 : :
1503 : : static int
1504 : 0 : vrb_queue_intr_disable(struct rte_bbdev *dev, uint16_t queue_id)
1505 : : {
1506 : 0 : struct acc_queue *q = dev->data->queues[queue_id].queue_private;
1507 : :
1508 [ # # # # ]: 0 : if (rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_VFIO_MSI &&
1509 : 0 : rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_VFIO_MSIX)
1510 : : return -ENOTSUP;
1511 : :
1512 : 0 : q->irq_enable = 0;
1513 : 0 : return 0;
1514 : : }
1515 : :
1516 : : static int
1517 : 0 : vrb_queue_ops_dump(struct rte_bbdev *dev, uint16_t queue_id, FILE *f)
1518 : : {
1519 : 0 : struct acc_queue *q = dev->data->queues[queue_id].queue_private;
1520 : : struct rte_bbdev_dec_op *op;
1521 : : uint16_t i, int_nb;
1522 : : volatile union acc_info_ring_data *ring_data;
1523 : 0 : uint16_t info_ring_head = q->d->info_ring_head;
1524 : : static char str[1024];
1525 : :
1526 [ # # ]: 0 : if (f == NULL) {
1527 : 0 : rte_bbdev_log(ERR, "Invalid File input");
1528 : 0 : return -EINVAL;
1529 : : }
1530 : :
1531 : : /** Print generic information on queue status. */
1532 : 0 : fprintf(f, "Dump of operations %s on Queue %d by %s\n",
1533 : 0 : rte_bbdev_op_type_str(q->op_type), queue_id, dev->device->driver->name);
1534 : 0 : fprintf(f, " AQ Enqueued %d Dequeued %d Depth %d - Available Enq %d Deq %d\n",
1535 : 0 : q->aq_enqueued, q->aq_dequeued, q->aq_depth,
1536 : : acc_ring_avail_enq(q), acc_ring_avail_deq(q));
1537 : :
1538 : : /** Print information captured in the info ring. */
1539 [ # # ]: 0 : if (q->d->info_ring != NULL) {
1540 : 0 : fprintf(f, "Info Ring Buffer - Head %d\n", q->d->info_ring_head);
1541 : 0 : ring_data = q->d->info_ring + (q->d->info_ring_head & ACC_INFO_RING_MASK);
1542 [ # # ]: 0 : while (ring_data->valid) {
1543 [ # # ]: 0 : int_nb = int_from_ring(*ring_data, q->d->device_variant);
1544 [ # # ]: 0 : if ((int_nb < ACC_PF_INT_DMA_DL_DESC_IRQ) || (
1545 : : int_nb > ACC_PF_INT_DMA_MLD_DESC_IRQ)) {
1546 : 0 : fprintf(f, " InfoRing: ITR:%d Info:0x%x",
1547 : 0 : int_nb, ring_data->detailed_info);
1548 : : /* Initialize Info Ring entry and move forward. */
1549 : 0 : ring_data->valid = 0;
1550 : : }
1551 : 0 : info_ring_head++;
1552 : 0 : ring_data = q->d->info_ring + (info_ring_head & ACC_INFO_RING_MASK);
1553 : : }
1554 : : }
1555 : :
1556 : 0 : fprintf(f, "Ring Content - Head %d Tail %d Depth %d\n",
1557 : : q->sw_ring_head, q->sw_ring_tail, q->sw_ring_depth);
1558 : : /** Print information about each operation in the software ring. */
1559 [ # # ]: 0 : for (i = 0; i < q->sw_ring_depth; ++i) {
1560 : 0 : op = (q->ring_addr + i)->req.op_addr;
1561 [ # # ]: 0 : if (op != NULL)
1562 : 0 : fprintf(f, " %d\tn %d %s", i, (q->ring_addr + i)->req.numCBs,
1563 : : rte_bbdev_ops_param_string(op, q->op_type,
1564 : : str, sizeof(str)));
1565 : : }
1566 : :
1567 : : fprintf(f, "== End of File ==\n");
1568 : :
1569 : 0 : return 0;
1570 : : }
1571 : :
1572 : : static const struct rte_bbdev_ops vrb_bbdev_ops = {
1573 : : .setup_queues = vrb_setup_queues,
1574 : : .intr_enable = vrb_intr_enable,
1575 : : .close = vrb_dev_close,
1576 : : .info_get = vrb_dev_info_get,
1577 : : .queue_setup = vrb_queue_setup,
1578 : : .queue_release = vrb_queue_release,
1579 : : .queue_stop = vrb_queue_stop,
1580 : : .queue_intr_enable = vrb_queue_intr_enable,
1581 : : .queue_intr_disable = vrb_queue_intr_disable,
1582 : : .queue_ops_dump = vrb_queue_ops_dump
1583 : : };
1584 : :
1585 : : /* PCI PF address map. */
1586 : : static struct rte_pci_id pci_id_vrb_pf_map[] = {
1587 : : {
1588 : : RTE_PCI_DEVICE(RTE_VRB1_VENDOR_ID, RTE_VRB1_PF_DEVICE_ID)
1589 : : },
1590 : : {
1591 : : RTE_PCI_DEVICE(RTE_VRB2_VENDOR_ID, RTE_VRB2_PF_DEVICE_ID)
1592 : : },
1593 : : {.device_id = 0},
1594 : : };
1595 : :
1596 : : /* PCI VF address map. */
1597 : : static struct rte_pci_id pci_id_vrb_vf_map[] = {
1598 : : {
1599 : : RTE_PCI_DEVICE(RTE_VRB1_VENDOR_ID, RTE_VRB1_VF_DEVICE_ID)
1600 : : },
1601 : : {
1602 : : RTE_PCI_DEVICE(RTE_VRB2_VENDOR_ID, RTE_VRB2_VF_DEVICE_ID)
1603 : : },
1604 : : {.device_id = 0},
1605 : : };
1606 : :
1607 : : /* Fill in a frame control word for turbo decoding. */
1608 : : static inline void
1609 : 0 : vrb_fcw_td_fill(const struct rte_bbdev_dec_op *op, struct acc_fcw_td *fcw)
1610 : : {
1611 : 0 : fcw->fcw_ver = 1;
1612 : 0 : fcw->num_maps = ACC_FCW_TD_AUTOMAP;
1613 [ # # ]: 0 : fcw->bypass_sb_deint = !check_bit(op->turbo_dec.op_flags,
1614 : : RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE);
1615 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1616 : 0 : fcw->c = op->turbo_dec.tb_params.c;
1617 : 0 : fcw->k_pos = op->turbo_dec.tb_params.k_pos;
1618 : : } else {
1619 : 0 : fcw->c = 1;
1620 : 0 : fcw->k_pos = op->turbo_dec.cb_params.k;
1621 : : }
1622 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT)) {
1623 : 0 : fcw->soft_output_en = 1;
1624 [ # # ]: 0 : fcw->sw_soft_out_dis = 0;
1625 : 0 : fcw->sw_et_cont = check_bit(op->turbo_dec.op_flags,
1626 : : RTE_BBDEV_TURBO_CONTINUE_CRC_MATCH);
1627 : 0 : fcw->sw_soft_out_saturation = check_bit(op->turbo_dec.op_flags,
1628 : : RTE_BBDEV_TURBO_SOFT_OUT_SATURATE);
1629 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
1630 : : RTE_BBDEV_TURBO_EQUALIZER)) {
1631 : 0 : fcw->bypass_teq = 0;
1632 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1633 : 0 : fcw->cab = op->turbo_dec.tb_params.cab;
1634 : 0 : fcw->ea = op->turbo_dec.tb_params.ea;
1635 : 0 : fcw->eb = op->turbo_dec.tb_params.eb;
1636 : : } else {
1637 : 0 : fcw->ea = op->turbo_dec.cb_params.e;
1638 : 0 : fcw->eb = op->turbo_dec.cb_params.e;
1639 : : }
1640 : :
1641 [ # # ]: 0 : if (op->turbo_dec.rv_index == 0)
1642 : 0 : fcw->k0_start_col = ACC_FCW_TD_RVIDX_0;
1643 [ # # ]: 0 : else if (op->turbo_dec.rv_index == 1)
1644 : 0 : fcw->k0_start_col = ACC_FCW_TD_RVIDX_1;
1645 [ # # ]: 0 : else if (op->turbo_dec.rv_index == 2)
1646 : 0 : fcw->k0_start_col = ACC_FCW_TD_RVIDX_2;
1647 : : else
1648 : 0 : fcw->k0_start_col = ACC_FCW_TD_RVIDX_3;
1649 : : } else {
1650 : 0 : fcw->bypass_teq = 1;
1651 : 0 : fcw->eb = 64; /* avoid undefined value */
1652 : : }
1653 : : } else {
1654 : 0 : fcw->soft_output_en = 0;
1655 : 0 : fcw->sw_soft_out_dis = 1;
1656 : 0 : fcw->bypass_teq = 0;
1657 : : }
1658 : :
1659 : 0 : fcw->code_block_mode = 1;
1660 : 0 : fcw->turbo_crc_type = check_bit(op->turbo_dec.op_flags,
1661 : : RTE_BBDEV_TURBO_CRC_TYPE_24B);
1662 : :
1663 : 0 : fcw->ext_td_cold_reg_en = 1;
1664 : 0 : fcw->raw_decoder_input_on = 0;
1665 : 0 : fcw->max_iter = RTE_MAX((uint8_t) op->turbo_dec.iter_max, 2);
1666 : 0 : fcw->min_iter = 2;
1667 : 0 : fcw->half_iter_on = check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_HALF_ITERATION_EVEN);
1668 : :
1669 : 0 : fcw->early_stop_en = check_bit(op->turbo_dec.op_flags,
1670 : 0 : RTE_BBDEV_TURBO_EARLY_TERMINATION) & !fcw->soft_output_en;
1671 : 0 : fcw->ext_scale = 0xF;
1672 : 0 : }
1673 : :
1674 : : /* Fill in a frame control word for LDPC decoding. */
1675 : : static inline void
1676 : 0 : vrb_fcw_ld_fill(struct rte_bbdev_dec_op *op, struct acc_fcw_ld *fcw,
1677 : : union acc_harq_layout_data *harq_layout, uint16_t device_variant)
1678 : : {
1679 : : uint16_t harq_out_length, harq_in_length, ncb_p, k0_p, parity_offset;
1680 : : uint32_t harq_index;
1681 : : uint32_t l;
1682 : :
1683 : 0 : fcw->qm = op->ldpc_dec.q_m;
1684 : 0 : fcw->nfiller = op->ldpc_dec.n_filler;
1685 : 0 : fcw->BG = (op->ldpc_dec.basegraph - 1);
1686 : 0 : fcw->Zc = op->ldpc_dec.z_c;
1687 : 0 : fcw->ncb = op->ldpc_dec.n_cb;
1688 : 0 : fcw->k0 = get_k0(fcw->ncb, fcw->Zc, op->ldpc_dec.basegraph,
1689 : 0 : op->ldpc_dec.rv_index, op->ldpc_dec.k0);
1690 [ # # ]: 0 : if (op->ldpc_dec.code_block_mode == RTE_BBDEV_CODE_BLOCK)
1691 : 0 : fcw->rm_e = op->ldpc_dec.cb_params.e;
1692 : : else
1693 : 0 : fcw->rm_e = (op->ldpc_dec.tb_params.r <
1694 : 0 : op->ldpc_dec.tb_params.cab) ?
1695 [ # # ]: 0 : op->ldpc_dec.tb_params.ea :
1696 : 0 : op->ldpc_dec.tb_params.eb;
1697 : :
1698 [ # # # # ]: 0 : if (unlikely(check_bit(op->ldpc_dec.op_flags,
1699 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE) &&
1700 : : (op->ldpc_dec.harq_combined_input.length == 0))) {
1701 : 0 : rte_bbdev_log(WARNING, "Null HARQ input size provided");
1702 : : /* Disable HARQ input in that case to carry forward. */
1703 : 0 : op->ldpc_dec.op_flags ^= RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE;
1704 : : }
1705 [ # # ]: 0 : if (unlikely(fcw->rm_e == 0)) {
1706 : 0 : rte_bbdev_log(WARNING, "Null E input provided");
1707 : 0 : fcw->rm_e = 2;
1708 : : }
1709 : :
1710 [ # # ]: 0 : fcw->hcin_en = check_bit(op->ldpc_dec.op_flags,
1711 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE);
1712 : 0 : fcw->hcout_en = check_bit(op->ldpc_dec.op_flags,
1713 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE);
1714 : 0 : fcw->crc_select = check_bit(op->ldpc_dec.op_flags,
1715 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK);
1716 : 0 : fcw->bypass_dec = 0;
1717 : 0 : fcw->bypass_intlv = check_bit(op->ldpc_dec.op_flags,
1718 : : RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS);
1719 [ # # ]: 0 : if (op->ldpc_dec.q_m == 1) {
1720 : 0 : fcw->bypass_intlv = 1;
1721 : 0 : fcw->qm = 2;
1722 : : }
1723 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION)) {
1724 : 0 : fcw->hcin_decomp_mode = 1;
1725 : 0 : fcw->hcout_comp_mode = 1;
1726 [ # # ]: 0 : } else if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HARQ_4BIT_COMPRESSION)) {
1727 : 0 : fcw->hcin_decomp_mode = 4;
1728 : 0 : fcw->hcout_comp_mode = 4;
1729 : : } else {
1730 : 0 : fcw->hcin_decomp_mode = 0;
1731 : 0 : fcw->hcout_comp_mode = 0;
1732 : : }
1733 : :
1734 : 0 : fcw->llr_pack_mode = check_bit(op->ldpc_dec.op_flags,
1735 : : RTE_BBDEV_LDPC_LLR_COMPRESSION);
1736 [ # # ]: 0 : harq_index = hq_index(op->ldpc_dec.harq_combined_output.offset);
1737 [ # # ]: 0 : if (fcw->hcin_en > 0) {
1738 : 0 : harq_in_length = op->ldpc_dec.harq_combined_input.length;
1739 [ # # ]: 0 : if (fcw->hcin_decomp_mode == 1)
1740 : 0 : harq_in_length = harq_in_length * 8 / 6;
1741 [ # # ]: 0 : else if (fcw->hcin_decomp_mode == 4)
1742 : 0 : harq_in_length = harq_in_length * 2;
1743 : 0 : harq_in_length = RTE_MIN(harq_in_length, op->ldpc_dec.n_cb
1744 : : - op->ldpc_dec.n_filler);
1745 : 0 : harq_in_length = RTE_ALIGN_CEIL(harq_in_length, 64);
1746 : 0 : fcw->hcin_size0 = harq_in_length;
1747 : 0 : fcw->hcin_offset = 0;
1748 : 0 : fcw->hcin_size1 = 0;
1749 : : } else {
1750 : 0 : fcw->hcin_size0 = 0;
1751 : 0 : fcw->hcin_offset = 0;
1752 : 0 : fcw->hcin_size1 = 0;
1753 : : }
1754 : :
1755 [ # # ]: 0 : fcw->itmax = op->ldpc_dec.iter_max;
1756 : 0 : fcw->itstop = check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE);
1757 : 0 : fcw->cnu_algo = ACC_ALGO_MSA;
1758 : 0 : fcw->synd_precoder = fcw->itstop;
1759 : :
1760 [ # # ]: 0 : if (device_variant != VRB1_VARIANT) {
1761 : 0 : fcw->so_it = op->ldpc_dec.iter_max;
1762 : 0 : fcw->so_en = check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_SOFT_OUT_ENABLE);
1763 : 0 : fcw->so_bypass_intlv = check_bit(op->ldpc_dec.op_flags,
1764 : : RTE_BBDEV_LDPC_SOFT_OUT_DEINTERLEAVER_BYPASS);
1765 : 0 : fcw->so_bypass_rm = 0;
1766 : 0 : fcw->minsum_offset = 0;
1767 : 0 : fcw->dec_llrclip = 0;
1768 : : }
1769 : :
1770 : : /*
1771 : : * These are all implicitly set:
1772 : : * fcw->synd_post = 0;
1773 : : * fcw->dec_convllr = 0;
1774 : : * fcw->hcout_convllr = 0;
1775 : : * fcw->hcout_size1 = 0;
1776 : : * fcw->so_it = 0;
1777 : : * fcw->hcout_offset = 0;
1778 : : * fcw->negstop_th = 0;
1779 : : * fcw->negstop_it = 0;
1780 : : * fcw->negstop_en = 0;
1781 : : * fcw->gain_i = 1;
1782 : : * fcw->gain_h = 1;
1783 : : */
1784 [ # # ]: 0 : if (fcw->hcout_en > 0) {
1785 : 0 : parity_offset = (op->ldpc_dec.basegraph == 1 ? 20 : 8)
1786 [ # # ]: 0 : * op->ldpc_dec.z_c - op->ldpc_dec.n_filler;
1787 [ # # ]: 0 : k0_p = (fcw->k0 > parity_offset) ? fcw->k0 - op->ldpc_dec.n_filler : fcw->k0;
1788 : 0 : ncb_p = fcw->ncb - op->ldpc_dec.n_filler;
1789 : 0 : l = k0_p + fcw->rm_e;
1790 : 0 : harq_out_length = (uint16_t) fcw->hcin_size0;
1791 : 0 : harq_out_length = RTE_MIN(RTE_MAX(harq_out_length, l), ncb_p);
1792 : 0 : harq_out_length = RTE_ALIGN_CEIL(harq_out_length, 64);
1793 : 0 : fcw->hcout_size0 = harq_out_length;
1794 : 0 : fcw->hcout_size1 = 0;
1795 : 0 : fcw->hcout_offset = 0;
1796 : 0 : harq_layout[harq_index].offset = fcw->hcout_offset;
1797 : 0 : harq_layout[harq_index].size0 = fcw->hcout_size0;
1798 : : } else {
1799 : 0 : fcw->hcout_size0 = 0;
1800 : 0 : fcw->hcout_size1 = 0;
1801 : 0 : fcw->hcout_offset = 0;
1802 : : }
1803 : :
1804 : : /* Force saturation to 6 bits LLR. */
1805 : 0 : fcw->saturate_input = 1;
1806 : :
1807 [ # # ]: 0 : fcw->tb_crc_select = 0;
1808 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK))
1809 : 0 : fcw->tb_crc_select = 2;
1810 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK))
1811 : 0 : fcw->tb_crc_select = 1;
1812 : 0 : }
1813 : :
1814 : : static inline int
1815 : 0 : vrb_dma_desc_td_fill(struct rte_bbdev_dec_op *op,
1816 : : struct acc_dma_req_desc *desc, struct rte_mbuf **input,
1817 : : struct rte_mbuf *h_output, struct rte_mbuf *s_output,
1818 : : uint32_t *in_offset, uint32_t *h_out_offset,
1819 : : uint32_t *s_out_offset, uint32_t *h_out_length,
1820 : : uint32_t *s_out_length, uint32_t *mbuf_total_left,
1821 : : uint32_t *seg_total_left, uint8_t r, struct acc_queue *q)
1822 : : {
1823 : : int next_triplet = 1; /* FCW already done. */
1824 : : uint16_t k;
1825 : : uint16_t crc24_overlap = 0;
1826 : : uint32_t e, kw;
1827 : :
1828 : 0 : desc->word0 = ACC_DMA_DESC_TYPE;
1829 : 0 : desc->word1 = 0; /**< Timestamp could be disabled. */
1830 : 0 : desc->word2 = 0;
1831 : 0 : desc->word3 = 0;
1832 : 0 : desc->numCBs = 1;
1833 : :
1834 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1835 : 0 : k = op->turbo_dec.tb_params.k_pos;
1836 : 0 : e = (r < op->turbo_dec.tb_params.cab)
1837 : : ? op->turbo_dec.tb_params.ea
1838 [ # # ]: 0 : : op->turbo_dec.tb_params.eb;
1839 : : } else {
1840 : 0 : k = op->turbo_dec.cb_params.k;
1841 : 0 : e = op->turbo_dec.cb_params.e;
1842 : : }
1843 : :
1844 [ # # ]: 0 : if ((op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1845 [ # # ]: 0 : && !check_bit(op->turbo_dec.op_flags,
1846 : : RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP))
1847 : : crc24_overlap = 24;
1848 [ # # ]: 0 : if ((op->turbo_dec.code_block_mode == RTE_BBDEV_CODE_BLOCK)
1849 [ # # ]: 0 : && check_bit(op->turbo_dec.op_flags,
1850 : : RTE_BBDEV_TURBO_DEC_CRC_24B_DROP))
1851 : : crc24_overlap = 24;
1852 : :
1853 : : /* Calculates circular buffer size.
1854 : : * According to 3gpp 36.212 section 5.1.4.2
1855 : : * Kw = 3 * Kpi,
1856 : : * where:
1857 : : * Kpi = nCol * nRow
1858 : : * where nCol is 32 and nRow can be calculated from:
1859 : : * D =< nCol * nRow
1860 : : * where D is the size of each output from turbo encoder block (k + 4).
1861 : : */
1862 : 0 : kw = RTE_ALIGN_CEIL(k + 4, 32) * 3;
1863 : :
1864 [ # # # # ]: 0 : if (unlikely((*mbuf_total_left == 0) || (*mbuf_total_left < kw))) {
1865 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_MBUF,
1866 : : "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u\n",
1867 : : *mbuf_total_left, kw);
1868 : 0 : return -1;
1869 : : }
1870 : :
1871 : 0 : next_triplet = acc_dma_fill_blk_type_in(desc, input, in_offset, kw,
1872 : : seg_total_left, next_triplet,
1873 : 0 : check_bit(op->turbo_dec.op_flags,
1874 : : RTE_BBDEV_TURBO_DEC_SCATTER_GATHER));
1875 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1876 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_MBUF,
1877 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p\n",
1878 : : op);
1879 : 0 : return -1;
1880 : : }
1881 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1882 : 0 : desc->m2dlen = next_triplet;
1883 : 0 : *mbuf_total_left -= kw;
1884 : 0 : *h_out_length = ((k - crc24_overlap) >> 3);
1885 [ # # ]: 0 : next_triplet = acc_dma_fill_blk_type(
1886 : : desc, h_output, *h_out_offset,
1887 : : *h_out_length, next_triplet, ACC_DMA_BLKID_OUT_HARD);
1888 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1889 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_MBUF,
1890 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p\n",
1891 : : op);
1892 : 0 : return -1;
1893 : : }
1894 : :
1895 : 0 : op->turbo_dec.hard_output.length += *h_out_length;
1896 : 0 : *h_out_offset += *h_out_length;
1897 : :
1898 : : /* Soft output. */
1899 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT)) {
1900 [ # # ]: 0 : if (op->turbo_dec.soft_output.data == 0) {
1901 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_SOFT,
1902 : : "Soft output is not defined\n");
1903 : 0 : return -1;
1904 : : }
1905 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
1906 : : RTE_BBDEV_TURBO_EQUALIZER))
1907 : 0 : *s_out_length = e;
1908 : : else
1909 : 0 : *s_out_length = (k * 3) + 12;
1910 : :
1911 [ # # ]: 0 : next_triplet = acc_dma_fill_blk_type(desc, s_output,
1912 : : *s_out_offset, *s_out_length, next_triplet,
1913 : : ACC_DMA_BLKID_OUT_SOFT);
1914 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1915 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_MBUF,
1916 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p\n",
1917 : : op);
1918 : 0 : return -1;
1919 : : }
1920 : :
1921 : 0 : op->turbo_dec.soft_output.length += *s_out_length;
1922 : 0 : *s_out_offset += *s_out_length;
1923 : : }
1924 : :
1925 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1926 : 0 : desc->d2mlen = next_triplet - desc->m2dlen;
1927 : :
1928 : 0 : desc->op_addr = op;
1929 : :
1930 : 0 : return 0;
1931 : : }
1932 : :
1933 : : static inline int
1934 : 0 : vrb_dma_desc_ld_fill(struct rte_bbdev_dec_op *op,
1935 : : struct acc_dma_req_desc *desc,
1936 : : struct rte_mbuf **input, struct rte_mbuf *h_output,
1937 : : uint32_t *in_offset, uint32_t *h_out_offset,
1938 : : uint32_t *h_out_length, uint32_t *mbuf_total_left,
1939 : : uint32_t *seg_total_left, struct acc_fcw_ld *fcw, uint16_t device_variant,
1940 : : struct acc_queue *q)
1941 : : {
1942 : : struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1943 : : int next_triplet = 1; /* FCW already done. */
1944 : : uint32_t input_length;
1945 : : uint16_t output_length, crc24_overlap = 0;
1946 : : uint16_t sys_cols, K, h_p_size, h_np_size;
1947 : :
1948 [ # # ]: 0 : if (device_variant == VRB1_VARIANT) {
1949 [ # # # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HARQ_4BIT_COMPRESSION) ||
1950 : : check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_SOFT_OUT_ENABLE)) {
1951 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_CAP,
1952 : : "VRB1 does not support the requested capabilities %x\n",
1953 : : op->ldpc_dec.op_flags);
1954 : 0 : return -1;
1955 : : }
1956 : : }
1957 : :
1958 : : acc_header_init(desc);
1959 : :
1960 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
1961 : : crc24_overlap = 24;
1962 : :
1963 : : /* Compute some LDPC BG lengths. */
1964 [ # # ]: 0 : input_length = fcw->rm_e;
1965 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_LLR_COMPRESSION))
1966 : 0 : input_length = (input_length * 3 + 3) / 4;
1967 [ # # ]: 0 : sys_cols = (dec->basegraph == 1) ? 22 : 10;
1968 : 0 : K = sys_cols * dec->z_c;
1969 : 0 : output_length = K - dec->n_filler - crc24_overlap;
1970 : :
1971 [ # # # # ]: 0 : if (unlikely((*mbuf_total_left == 0) || (*mbuf_total_left < input_length))) {
1972 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_MBUF,
1973 : : "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u\n",
1974 : : *mbuf_total_left, input_length);
1975 : 0 : return -1;
1976 : : }
1977 : :
1978 : 0 : next_triplet = acc_dma_fill_blk_type_in(desc, input,
1979 : : in_offset, input_length,
1980 : : seg_total_left, next_triplet,
1981 : : check_bit(op->ldpc_dec.op_flags,
1982 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER));
1983 : :
1984 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1985 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_MBUF,
1986 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p\n",
1987 : : op);
1988 : 0 : return -1;
1989 : : }
1990 : :
1991 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1992 [ # # ]: 0 : if (op->ldpc_dec.harq_combined_input.data == 0) {
1993 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_HARQ,
1994 : : "HARQ input is not defined\n");
1995 : 0 : return -1;
1996 : : }
1997 : 0 : h_p_size = fcw->hcin_size0 + fcw->hcin_size1;
1998 [ # # ]: 0 : if (fcw->hcin_decomp_mode == 1)
1999 : 0 : h_p_size = (h_p_size * 3 + 3) / 4;
2000 [ # # ]: 0 : else if (fcw->hcin_decomp_mode == 4)
2001 : 0 : h_p_size = h_p_size / 2;
2002 : : if (op->ldpc_dec.harq_combined_input.data == 0) {
2003 : : acc_error_log(q, (void *)op, ACC_ERR_REJ_HARQ,
2004 : : "HARQ input is not defined\n");
2005 : : return -1;
2006 : : }
2007 : 0 : acc_dma_fill_blk_type(
2008 : : desc,
2009 : : op->ldpc_dec.harq_combined_input.data,
2010 : : op->ldpc_dec.harq_combined_input.offset,
2011 : : h_p_size,
2012 : : next_triplet,
2013 : : ACC_DMA_BLKID_IN_HARQ);
2014 : : next_triplet++;
2015 : : }
2016 : :
2017 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
2018 : 0 : desc->m2dlen = next_triplet;
2019 : 0 : *mbuf_total_left -= input_length;
2020 : :
2021 [ # # ]: 0 : next_triplet = acc_dma_fill_blk_type(desc, h_output,
2022 : : *h_out_offset, output_length >> 3, next_triplet,
2023 : : ACC_DMA_BLKID_OUT_HARD);
2024 : :
2025 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_SOFT_OUT_ENABLE)) {
2026 [ # # ]: 0 : if (op->ldpc_dec.soft_output.data == 0) {
2027 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_SOFT,
2028 : : "Soft output is not defined\n");
2029 : 0 : return -1;
2030 : : }
2031 : 0 : dec->soft_output.length = fcw->rm_e;
2032 : 0 : acc_dma_fill_blk_type(desc, dec->soft_output.data, dec->soft_output.offset,
2033 : : fcw->rm_e, next_triplet, ACC_DMA_BLKID_OUT_SOFT);
2034 : : next_triplet++;
2035 : : }
2036 : :
2037 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
2038 [ # # ]: 0 : if (op->ldpc_dec.harq_combined_output.data == 0) {
2039 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_HARQ,
2040 : : "HARQ output is not defined\n");
2041 : 0 : return -1;
2042 : : }
2043 : :
2044 : : /* Pruned size of the HARQ. */
2045 : 0 : h_p_size = fcw->hcout_size0 + fcw->hcout_size1;
2046 : : /* Non-Pruned size of the HARQ. */
2047 [ # # ]: 0 : h_np_size = fcw->hcout_offset > 0 ?
2048 : : fcw->hcout_offset + fcw->hcout_size1 :
2049 : : h_p_size;
2050 [ # # ]: 0 : if (fcw->hcin_decomp_mode == 1) {
2051 : 0 : h_np_size = (h_np_size * 3 + 3) / 4;
2052 : 0 : h_p_size = (h_p_size * 3 + 3) / 4;
2053 [ # # ]: 0 : } else if (fcw->hcin_decomp_mode == 4) {
2054 : 0 : h_np_size = h_np_size / 2;
2055 : 0 : h_p_size = h_p_size / 2;
2056 : : }
2057 : 0 : dec->harq_combined_output.length = h_np_size;
2058 : 0 : acc_dma_fill_blk_type(
2059 : : desc,
2060 : : dec->harq_combined_output.data,
2061 : : dec->harq_combined_output.offset,
2062 : : h_p_size,
2063 : : next_triplet,
2064 : : ACC_DMA_BLKID_OUT_HARQ);
2065 : :
2066 : : next_triplet++;
2067 : : }
2068 : :
2069 : 0 : *h_out_length = output_length >> 3;
2070 : 0 : dec->hard_output.length += *h_out_length;
2071 : 0 : *h_out_offset += *h_out_length;
2072 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
2073 : 0 : desc->d2mlen = next_triplet - desc->m2dlen;
2074 : :
2075 : 0 : desc->op_addr = op;
2076 : :
2077 : 0 : return 0;
2078 : : }
2079 : :
2080 : : static inline void
2081 [ # # ]: 0 : vrb_dma_desc_ld_update(struct rte_bbdev_dec_op *op,
2082 : : struct acc_dma_req_desc *desc,
2083 : : struct rte_mbuf *input, struct rte_mbuf *h_output,
2084 : : uint32_t *in_offset, uint32_t *h_out_offset,
2085 : : uint32_t *h_out_length,
2086 : : union acc_harq_layout_data *harq_layout)
2087 : : {
2088 : : int next_triplet = 1; /* FCW already done. */
2089 : 0 : desc->data_ptrs[next_triplet].address = rte_pktmbuf_iova_offset(input, *in_offset);
2090 : : next_triplet++;
2091 : :
2092 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
2093 : 0 : struct rte_bbdev_op_data hi = op->ldpc_dec.harq_combined_input;
2094 : 0 : desc->data_ptrs[next_triplet].address =
2095 : 0 : rte_pktmbuf_iova_offset(hi.data, hi.offset);
2096 : : next_triplet++;
2097 : : }
2098 : :
2099 : 0 : desc->data_ptrs[next_triplet].address =
2100 : 0 : rte_pktmbuf_iova_offset(h_output, *h_out_offset);
2101 : 0 : *h_out_length = desc->data_ptrs[next_triplet].blen;
2102 : 0 : next_triplet++;
2103 : :
2104 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
2105 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
2106 : : /* Adjust based on previous operation. */
2107 : 0 : struct rte_bbdev_dec_op *prev_op = desc->op_addr;
2108 : 0 : op->ldpc_dec.harq_combined_output.length =
2109 : 0 : prev_op->ldpc_dec.harq_combined_output.length;
2110 : 0 : uint32_t harq_idx = hq_index(op->ldpc_dec.harq_combined_output.offset);
2111 : 0 : uint32_t prev_harq_idx = hq_index(prev_op->ldpc_dec.harq_combined_output.offset);
2112 : 0 : harq_layout[harq_idx].val = harq_layout[prev_harq_idx].val;
2113 : 0 : struct rte_bbdev_op_data ho = op->ldpc_dec.harq_combined_output;
2114 : 0 : desc->data_ptrs[next_triplet].address =
2115 : 0 : rte_pktmbuf_iova_offset(ho.data, ho.offset);
2116 : : next_triplet++;
2117 : : }
2118 : :
2119 : 0 : op->ldpc_dec.hard_output.length += *h_out_length;
2120 : 0 : desc->op_addr = op;
2121 : 0 : }
2122 : :
2123 : : /* Enqueue one encode operations for device in CB mode. */
2124 : : static inline int
2125 : 0 : enqueue_enc_one_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2126 : : uint16_t total_enqueued_cbs)
2127 : : {
2128 : : union acc_dma_desc *desc = NULL;
2129 : : int ret;
2130 : : uint32_t in_offset, out_offset, out_length, mbuf_total_left, seg_total_left;
2131 : : struct rte_mbuf *input, *output_head, *output;
2132 : :
2133 : : desc = acc_desc(q, total_enqueued_cbs);
2134 : 0 : acc_fcw_te_fill(op, &desc->req.fcw_te);
2135 : :
2136 : 0 : input = op->turbo_enc.input.data;
2137 : 0 : output_head = output = op->turbo_enc.output.data;
2138 : 0 : in_offset = op->turbo_enc.input.offset;
2139 : 0 : out_offset = op->turbo_enc.output.offset;
2140 : 0 : out_length = 0;
2141 : 0 : mbuf_total_left = op->turbo_enc.input.length;
2142 : 0 : seg_total_left = rte_pktmbuf_data_len(op->turbo_enc.input.data) - in_offset;
2143 : :
2144 : 0 : ret = acc_dma_desc_te_fill(op, &desc->req, &input, output,
2145 : : &in_offset, &out_offset, &out_length, &mbuf_total_left,
2146 : : &seg_total_left, 0);
2147 : :
2148 [ # # ]: 0 : if (unlikely(ret < 0))
2149 : : return ret;
2150 : :
2151 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2152 : :
2153 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2154 : : rte_memdump(stderr, "FCW", &desc->req.fcw_te,
2155 : : sizeof(desc->req.fcw_te) - 8);
2156 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2157 : : #endif
2158 : : /* One CB (one op) was successfully prepared to enqueue */
2159 : : return 1;
2160 : : }
2161 : :
2162 : : /* Enqueue one encode operations for device in CB mode
2163 : : * multiplexed on the same descriptor.
2164 : : */
2165 : : static inline int
2166 : 0 : enqueue_ldpc_enc_n_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op **ops,
2167 : : uint16_t total_enqueued_descs, int16_t num)
2168 : : {
2169 : : union acc_dma_desc *desc = NULL;
2170 : : uint32_t out_length;
2171 : : struct rte_mbuf *output_head, *output;
2172 : : int i, next_triplet;
2173 : : uint16_t in_length_in_bytes;
2174 : 0 : struct rte_bbdev_op_ldpc_enc *enc = &ops[0]->ldpc_enc;
2175 : : struct acc_ptrs *context_ptrs;
2176 : :
2177 : : desc = acc_desc(q, total_enqueued_descs);
2178 : 0 : acc_fcw_le_fill(ops[0], &desc->req.fcw_le, num, 0);
2179 : :
2180 : : /** This could be done at polling. */
2181 : : acc_header_init(&desc->req);
2182 : 0 : desc->req.numCBs = num;
2183 : 0 : desc->req.dltb = 0;
2184 : :
2185 : 0 : in_length_in_bytes = ops[0]->ldpc_enc.input.data->data_len;
2186 : 0 : out_length = (enc->cb_params.e + 7) >> 3;
2187 : 0 : desc->req.m2dlen = 1 + num;
2188 : 0 : desc->req.d2mlen = num;
2189 : : next_triplet = 1;
2190 : :
2191 [ # # ]: 0 : for (i = 0; i < num; i++) {
2192 : 0 : desc->req.data_ptrs[next_triplet].address =
2193 [ # # ]: 0 : rte_pktmbuf_iova_offset(ops[i]->ldpc_enc.input.data, 0);
2194 : 0 : desc->req.data_ptrs[next_triplet].blen = in_length_in_bytes;
2195 : 0 : next_triplet++;
2196 : 0 : desc->req.data_ptrs[next_triplet].address = rte_pktmbuf_iova_offset(
2197 : : ops[i]->ldpc_enc.output.data, 0);
2198 : 0 : desc->req.data_ptrs[next_triplet].blen = out_length;
2199 : 0 : next_triplet++;
2200 : 0 : ops[i]->ldpc_enc.output.length = out_length;
2201 : 0 : output_head = output = ops[i]->ldpc_enc.output.data;
2202 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2203 : 0 : output->data_len = out_length;
2204 : : }
2205 : :
2206 : 0 : desc->req.op_addr = ops[0];
2207 : : /* Keep track of pointers even when multiplexed in single descriptor. */
2208 : 0 : context_ptrs = q->companion_ring_addr + acc_desc_idx(q, total_enqueued_descs);
2209 [ # # ]: 0 : for (i = 0; i < num; i++)
2210 : 0 : context_ptrs->ptr[i].op_addr = ops[i];
2211 : :
2212 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2213 : : rte_memdump(stderr, "FCW", &desc->req.fcw_le,
2214 : : sizeof(desc->req.fcw_le) - 8);
2215 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2216 : : #endif
2217 : :
2218 : : /* Number of compatible CBs/ops successfully prepared to enqueue. */
2219 : 0 : return num;
2220 : : }
2221 : :
2222 : : /* Enqueue one encode operations for VRB1 device for a partial TB
2223 : : * all codes blocks have same configuration multiplexed on the same descriptor.
2224 : : */
2225 : : static inline void
2226 : 0 : vrb1_enqueue_ldpc_enc_part_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2227 : : uint16_t total_enqueued_descs, int16_t num_cbs, uint32_t e,
2228 : : uint16_t in_len_B, uint32_t out_len_B, uint32_t *in_offset,
2229 : : uint32_t *out_offset)
2230 : : {
2231 : :
2232 : : union acc_dma_desc *desc = NULL;
2233 : : struct rte_mbuf *output_head, *output;
2234 : : int i, next_triplet;
2235 : : struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
2236 : :
2237 : : desc = acc_desc(q, total_enqueued_descs);
2238 : 0 : acc_fcw_le_fill(op, &desc->req.fcw_le, num_cbs, e);
2239 : :
2240 : : /** This could be done at polling. */
2241 : : acc_header_init(&desc->req);
2242 : 0 : desc->req.numCBs = num_cbs;
2243 : :
2244 : 0 : desc->req.m2dlen = 1 + num_cbs;
2245 : 0 : desc->req.d2mlen = num_cbs;
2246 : : next_triplet = 1;
2247 : :
2248 [ # # ]: 0 : for (i = 0; i < num_cbs; i++) {
2249 [ # # ]: 0 : desc->req.data_ptrs[next_triplet].address = rte_pktmbuf_iova_offset(
2250 : : enc->input.data, *in_offset);
2251 : 0 : *in_offset += in_len_B;
2252 : 0 : desc->req.data_ptrs[next_triplet].blen = in_len_B;
2253 : 0 : next_triplet++;
2254 : 0 : desc->req.data_ptrs[next_triplet].address = rte_pktmbuf_iova_offset(
2255 : : enc->output.data, *out_offset);
2256 : 0 : *out_offset += out_len_B;
2257 : 0 : desc->req.data_ptrs[next_triplet].blen = out_len_B;
2258 : 0 : next_triplet++;
2259 : 0 : enc->output.length += out_len_B;
2260 : : output_head = output = enc->output.data;
2261 [ # # ]: 0 : mbuf_append(output_head, output, out_len_B);
2262 : : }
2263 : :
2264 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2265 : : rte_memdump(stderr, "FCW", &desc->req.fcw_le,
2266 : : sizeof(desc->req.fcw_le) - 8);
2267 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2268 : : #endif
2269 : :
2270 : 0 : }
2271 : :
2272 : : /* Enqueue one encode operations for device in TB mode. */
2273 : : static inline int
2274 : 0 : enqueue_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2275 : : uint16_t total_enqueued_cbs, uint8_t cbs_in_tb)
2276 : : {
2277 : : union acc_dma_desc *desc = NULL;
2278 : : int ret;
2279 : : uint8_t r, c;
2280 : : uint32_t in_offset, out_offset, out_length, mbuf_total_left,
2281 : : seg_total_left;
2282 : : struct rte_mbuf *input, *output_head, *output;
2283 : : uint16_t desc_idx, current_enqueued_cbs = 0;
2284 : : uint64_t fcw_offset;
2285 : :
2286 : : desc_idx = acc_desc_idx(q, total_enqueued_cbs);
2287 : 0 : desc = q->ring_addr + desc_idx;
2288 : 0 : fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
2289 : 0 : acc_fcw_te_fill(op, &desc->req.fcw_te);
2290 : :
2291 : 0 : input = op->turbo_enc.input.data;
2292 : 0 : output_head = output = op->turbo_enc.output.data;
2293 : 0 : in_offset = op->turbo_enc.input.offset;
2294 : 0 : out_offset = op->turbo_enc.output.offset;
2295 : 0 : out_length = 0;
2296 : 0 : mbuf_total_left = op->turbo_enc.input.length;
2297 : :
2298 : 0 : c = op->turbo_enc.tb_params.c;
2299 : 0 : r = op->turbo_enc.tb_params.r;
2300 : :
2301 [ # # ]: 0 : while (mbuf_total_left > 0 && r < c) {
2302 [ # # ]: 0 : if (unlikely((input == NULL) || (output == NULL)))
2303 : : return -1;
2304 : :
2305 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2306 : : /* Set up DMA descriptor */
2307 : : desc = acc_desc(q, total_enqueued_cbs);
2308 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
2309 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_TE_BLEN;
2310 : :
2311 : 0 : ret = acc_dma_desc_te_fill(op, &desc->req, &input, output,
2312 : : &in_offset, &out_offset, &out_length,
2313 : : &mbuf_total_left, &seg_total_left, r);
2314 [ # # ]: 0 : if (unlikely(ret < 0))
2315 : 0 : return ret;
2316 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2317 : :
2318 : : /* Set total number of CBs in TB */
2319 : 0 : desc->req.cbs_in_tb = cbs_in_tb;
2320 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2321 : : rte_memdump(stderr, "FCW", &desc->req.fcw_te,
2322 : : sizeof(desc->req.fcw_te) - 8);
2323 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2324 : : #endif
2325 : :
2326 [ # # ]: 0 : if (seg_total_left == 0) {
2327 : : /* Go to the next mbuf */
2328 : 0 : input = input->next;
2329 : 0 : in_offset = 0;
2330 : 0 : output = output->next;
2331 : 0 : out_offset = 0;
2332 : : }
2333 : :
2334 : 0 : total_enqueued_cbs++;
2335 : 0 : current_enqueued_cbs++;
2336 : 0 : r++;
2337 : : }
2338 : :
2339 : : /* In case the number of CB doesn't match, the configuration was invalid. */
2340 [ # # ]: 0 : if (unlikely(current_enqueued_cbs != cbs_in_tb))
2341 : : return -1;
2342 : :
2343 : : /* Set SDone on last CB descriptor for TB mode. */
2344 : 0 : desc->req.sdone_enable = 1;
2345 : :
2346 : 0 : return current_enqueued_cbs;
2347 : : }
2348 : :
2349 : : /* Enqueue one encode operations for device in TB mode.
2350 : : * returns the number of descs used.
2351 : : */
2352 : : static inline int
2353 : 0 : vrb1_enqueue_ldpc_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2354 : : uint16_t enq_descs, uint8_t cbs_in_tb)
2355 : : {
2356 : : uint8_t num_a, num_b;
2357 : : uint16_t input_len_B, return_descs;
2358 : 0 : uint8_t r = op->ldpc_enc.tb_params.r;
2359 : 0 : uint8_t cab = op->ldpc_enc.tb_params.cab;
2360 : : union acc_dma_desc *desc;
2361 : : uint16_t init_enq_descs = enq_descs;
2362 : 0 : uint32_t in_offset = 0, out_offset = 0;
2363 : :
2364 [ # # ]: 0 : input_len_B = ((op->ldpc_enc.basegraph == 1 ? 22 : 10) * op->ldpc_enc.z_c
2365 : 0 : - op->ldpc_enc.n_filler) >> 3;
2366 : :
2367 [ # # ]: 0 : if (check_bit(op->ldpc_enc.op_flags, RTE_BBDEV_LDPC_CRC_24B_ATTACH))
2368 : 0 : input_len_B -= 3;
2369 : :
2370 [ # # ]: 0 : if (r < cab) {
2371 : 0 : num_a = cab - r;
2372 : 0 : num_b = cbs_in_tb - cab;
2373 : : } else {
2374 : : num_a = 0;
2375 : 0 : num_b = cbs_in_tb - r;
2376 : : }
2377 : :
2378 [ # # ]: 0 : while (num_a > 0) {
2379 : 0 : uint32_t e = op->ldpc_enc.tb_params.ea;
2380 : 0 : uint32_t out_len_B = (e + 7) >> 3;
2381 : 0 : uint8_t enq = RTE_MIN(num_a, ACC_MUX_5GDL_DESC);
2382 : 0 : num_a -= enq;
2383 : 0 : vrb1_enqueue_ldpc_enc_part_tb(q, op, enq_descs, enq, e, input_len_B,
2384 : : out_len_B, &in_offset, &out_offset);
2385 : 0 : enq_descs++;
2386 : : }
2387 [ # # ]: 0 : while (num_b > 0) {
2388 : 0 : uint32_t e = op->ldpc_enc.tb_params.eb;
2389 : 0 : uint32_t out_len_B = (e + 7) >> 3;
2390 : 0 : uint8_t enq = RTE_MIN(num_b, ACC_MUX_5GDL_DESC);
2391 : 0 : num_b -= enq;
2392 : 0 : vrb1_enqueue_ldpc_enc_part_tb(q, op, enq_descs, enq, e, input_len_B,
2393 : : out_len_B, &in_offset, &out_offset);
2394 : 0 : enq_descs++;
2395 : : }
2396 : :
2397 : 0 : return_descs = enq_descs - init_enq_descs;
2398 : : /* Keep total number of CBs in first TB. */
2399 : : desc = acc_desc(q, init_enq_descs);
2400 : 0 : desc->req.cbs_in_tb = return_descs; /** Actual number of descriptors. */
2401 : 0 : desc->req.op_addr = op;
2402 : :
2403 : : /* Set SDone on last CB descriptor for TB mode. */
2404 : 0 : desc = acc_desc(q, enq_descs - 1);
2405 : 0 : desc->req.sdone_enable = 1;
2406 : 0 : desc->req.op_addr = op;
2407 : 0 : return return_descs;
2408 : : }
2409 : :
2410 : : /* Fill in a frame control word for LDPC encoding. */
2411 : : static inline void
2412 : 0 : vrb2_fcw_letb_fill(const struct rte_bbdev_enc_op *op, struct acc_fcw_le *fcw)
2413 : : {
2414 : 0 : fcw->qm = op->ldpc_enc.q_m;
2415 : 0 : fcw->nfiller = op->ldpc_enc.n_filler;
2416 : 0 : fcw->BG = (op->ldpc_enc.basegraph - 1);
2417 : 0 : fcw->Zc = op->ldpc_enc.z_c;
2418 : 0 : fcw->ncb = op->ldpc_enc.n_cb;
2419 : 0 : fcw->k0 = get_k0(fcw->ncb, fcw->Zc, op->ldpc_enc.basegraph,
2420 : 0 : op->ldpc_enc.rv_index, 0);
2421 : 0 : fcw->rm_e = op->ldpc_enc.tb_params.ea;
2422 : 0 : fcw->rm_e_b = op->ldpc_enc.tb_params.eb;
2423 [ # # ]: 0 : fcw->crc_select = check_bit(op->ldpc_enc.op_flags,
2424 : : RTE_BBDEV_LDPC_CRC_24B_ATTACH);
2425 : 0 : fcw->bypass_intlv = 0;
2426 [ # # ]: 0 : if (op->ldpc_enc.tb_params.c > 1) {
2427 : 0 : fcw->mcb_count = 0;
2428 : 0 : fcw->C = op->ldpc_enc.tb_params.c;
2429 : 0 : fcw->Cab = op->ldpc_enc.tb_params.cab;
2430 : : } else {
2431 : 0 : fcw->mcb_count = 1;
2432 : 0 : fcw->C = 0;
2433 : : }
2434 : 0 : }
2435 : :
2436 : : /* Enqueue one encode operations for device in TB mode.
2437 : : * returns the number of descs used.
2438 : : */
2439 : : static inline int
2440 : 0 : vrb2_enqueue_ldpc_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2441 : : uint16_t enq_descs)
2442 : : {
2443 : : union acc_dma_desc *desc = NULL;
2444 : : uint32_t in_offset, out_offset, out_length, seg_total_left;
2445 : : struct rte_mbuf *input, *output_head, *output;
2446 : : struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
2447 : : int next_triplet = 1; /* FCW already done. */
2448 : : uint32_t in_length_in_bytes;
2449 : : uint16_t K, in_length_in_bits;
2450 : :
2451 : : desc = acc_desc(q, enq_descs);
2452 : 0 : vrb2_fcw_letb_fill(op, &desc->req.fcw_le);
2453 : :
2454 : 0 : input = enc->input.data;
2455 : 0 : output_head = output = enc->output.data;
2456 : 0 : in_offset = enc->input.offset;
2457 : 0 : out_offset = enc->output.offset;
2458 : 0 : seg_total_left = rte_pktmbuf_data_len(enc->input.data) - in_offset;
2459 : :
2460 [ # # ]: 0 : acc_header_init(&desc->req);
2461 [ # # ]: 0 : K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
2462 : 0 : in_length_in_bits = K - enc->n_filler;
2463 [ # # ]: 0 : if ((enc->op_flags & RTE_BBDEV_LDPC_CRC_24A_ATTACH) ||
2464 : : (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH))
2465 : 0 : in_length_in_bits -= 24;
2466 : 0 : in_length_in_bytes = (in_length_in_bits >> 3) * enc->tb_params.c;
2467 : :
2468 : 0 : next_triplet = acc_dma_fill_blk_type_in(&desc->req, &input, &in_offset,
2469 : : in_length_in_bytes, &seg_total_left, next_triplet,
2470 : : check_bit(enc->op_flags, RTE_BBDEV_LDPC_ENC_SCATTER_GATHER));
2471 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
2472 : 0 : rte_bbdev_log(ERR,
2473 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p",
2474 : : op);
2475 : 0 : return -1;
2476 : : }
2477 : 0 : desc->req.data_ptrs[next_triplet - 1].last = 1;
2478 : 0 : desc->req.m2dlen = next_triplet;
2479 : :
2480 : : /* Set output length */
2481 : : /* Integer round up division by 8 */
2482 : 0 : out_length = (enc->tb_params.ea * enc->tb_params.cab +
2483 [ # # ]: 0 : enc->tb_params.eb * (enc->tb_params.c - enc->tb_params.cab) + 7) >> 3;
2484 : :
2485 : : next_triplet = acc_dma_fill_blk_type(&desc->req, output, out_offset,
2486 : : out_length, next_triplet, ACC_DMA_BLKID_OUT_ENC);
2487 : 0 : enc->output.length = out_length;
2488 : : out_offset += out_length;
2489 : 0 : desc->req.data_ptrs[next_triplet - 1].last = 1;
2490 : 0 : desc->req.data_ptrs[next_triplet - 1].dma_ext = 0;
2491 : 0 : desc->req.d2mlen = next_triplet - desc->req.m2dlen;
2492 : 0 : desc->req.numCBs = enc->tb_params.c;
2493 [ # # ]: 0 : if (desc->req.numCBs > 1)
2494 : 0 : desc->req.dltb = 1;
2495 : 0 : desc->req.op_addr = op;
2496 : :
2497 [ # # ]: 0 : if (out_length < ACC_MAX_E_MBUF)
2498 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2499 : :
2500 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2501 : : rte_memdump(stderr, "FCW", &desc->req.fcw_le, sizeof(desc->req.fcw_le));
2502 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2503 : : #endif
2504 : : /* One CB (one op) was successfully prepared to enqueue */
2505 : : return 1;
2506 : : }
2507 : :
2508 : : /** Enqueue one decode operations for device in CB mode. */
2509 : : static inline int
2510 : 0 : enqueue_dec_one_op_cb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2511 : : uint16_t total_enqueued_cbs)
2512 : : {
2513 : : union acc_dma_desc *desc = NULL;
2514 : : int ret;
2515 : : uint32_t in_offset, h_out_offset, s_out_offset, s_out_length,
2516 : : h_out_length, mbuf_total_left, seg_total_left;
2517 : : struct rte_mbuf *input, *h_output_head, *h_output,
2518 : : *s_output_head, *s_output;
2519 : :
2520 [ # # # # ]: 0 : if ((q->d->device_variant == VRB1_VARIANT) &&
2521 [ # # ]: 0 : (check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT))) {
2522 : : /* SO not supported for VRB1. */
2523 : : return -EPERM;
2524 : : }
2525 : :
2526 : : desc = acc_desc(q, total_enqueued_cbs);
2527 : 0 : vrb_fcw_td_fill(op, &desc->req.fcw_td);
2528 : :
2529 : 0 : input = op->turbo_dec.input.data;
2530 : 0 : h_output_head = h_output = op->turbo_dec.hard_output.data;
2531 : 0 : s_output_head = s_output = op->turbo_dec.soft_output.data;
2532 : 0 : in_offset = op->turbo_dec.input.offset;
2533 : 0 : h_out_offset = op->turbo_dec.hard_output.offset;
2534 : 0 : s_out_offset = op->turbo_dec.soft_output.offset;
2535 : 0 : h_out_length = s_out_length = 0;
2536 : 0 : mbuf_total_left = op->turbo_dec.input.length;
2537 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2538 : :
2539 : : /* Set up DMA descriptor */
2540 : : desc = acc_desc(q, total_enqueued_cbs);
2541 : :
2542 : 0 : ret = vrb_dma_desc_td_fill(op, &desc->req, &input, h_output,
2543 : : s_output, &in_offset, &h_out_offset, &s_out_offset,
2544 : : &h_out_length, &s_out_length, &mbuf_total_left,
2545 : : &seg_total_left, 0, q);
2546 : :
2547 [ # # ]: 0 : if (unlikely(ret < 0))
2548 : : return ret;
2549 : :
2550 : : /* Hard output */
2551 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
2552 : :
2553 : : /* Soft output */
2554 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT))
2555 [ # # ]: 0 : mbuf_append(s_output_head, s_output, s_out_length);
2556 : :
2557 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2558 : : rte_memdump(stderr, "FCW", &desc->req.fcw_td,
2559 : : sizeof(desc->req.fcw_td));
2560 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2561 : : #endif
2562 : :
2563 : : /* One CB (one op) was successfully prepared to enqueue */
2564 : : return 1;
2565 : : }
2566 : :
2567 : : /** Enqueue one decode operations for device in CB mode. */
2568 : : static inline int
2569 : 0 : vrb_enqueue_ldpc_dec_one_op_cb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2570 : : uint16_t total_enqueued_cbs, bool same_op)
2571 : : {
2572 : : int ret, hq_len;
2573 : : union acc_dma_desc *desc;
2574 : : struct rte_mbuf *input, *h_output_head, *h_output;
2575 : 0 : uint32_t in_offset, h_out_offset, mbuf_total_left, h_out_length = 0;
2576 : : union acc_harq_layout_data *harq_layout;
2577 : :
2578 [ # # ]: 0 : if (op->ldpc_dec.cb_params.e == 0)
2579 : : return -EINVAL;
2580 : :
2581 : : desc = acc_desc(q, total_enqueued_cbs);
2582 : :
2583 : 0 : input = op->ldpc_dec.input.data;
2584 : 0 : h_output_head = h_output = op->ldpc_dec.hard_output.data;
2585 : 0 : in_offset = op->ldpc_dec.input.offset;
2586 : 0 : h_out_offset = op->ldpc_dec.hard_output.offset;
2587 : 0 : mbuf_total_left = op->ldpc_dec.input.length;
2588 : 0 : harq_layout = q->d->harq_layout;
2589 : :
2590 [ # # ]: 0 : if (same_op) {
2591 : : union acc_dma_desc *prev_desc;
2592 [ # # ]: 0 : prev_desc = acc_desc(q, total_enqueued_cbs - 1);
2593 : : uint8_t *prev_ptr = (uint8_t *) prev_desc;
2594 : : uint8_t *new_ptr = (uint8_t *) desc;
2595 : : /* Copy first 4 words and BDESCs. */
2596 : : rte_memcpy(new_ptr, prev_ptr, ACC_5GUL_SIZE_0);
2597 : 0 : rte_memcpy(new_ptr + ACC_5GUL_OFFSET_0,
2598 [ # # ]: 0 : prev_ptr + ACC_5GUL_OFFSET_0,
2599 : : ACC_5GUL_SIZE_1);
2600 : 0 : desc->req.op_addr = prev_desc->req.op_addr;
2601 : : /* Copy FCW. */
2602 : 0 : rte_memcpy(new_ptr + ACC_DESC_FCW_OFFSET,
2603 [ # # ]: 0 : prev_ptr + ACC_DESC_FCW_OFFSET,
2604 : : ACC_FCW_LD_BLEN);
2605 : 0 : vrb_dma_desc_ld_update(op, &desc->req, input, h_output,
2606 : : &in_offset, &h_out_offset,
2607 : : &h_out_length, harq_layout);
2608 : : } else {
2609 : : struct acc_fcw_ld *fcw;
2610 : : uint32_t seg_total_left;
2611 : 0 : fcw = &desc->req.fcw_ld;
2612 : 0 : vrb_fcw_ld_fill(op, fcw, harq_layout, q->d->device_variant);
2613 : :
2614 : : /* Special handling when using mbuf or not. */
2615 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
2616 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER))
2617 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2618 : : else
2619 : 0 : seg_total_left = fcw->rm_e;
2620 : 0 : ret = vrb_dma_desc_ld_fill(op, &desc->req, &input, h_output,
2621 : : &in_offset, &h_out_offset,
2622 : : &h_out_length, &mbuf_total_left,
2623 : 0 : &seg_total_left, fcw, q->d->device_variant, q);
2624 [ # # ]: 0 : if (unlikely(ret < 0))
2625 : 0 : return ret;
2626 : : }
2627 : :
2628 : : /* Hard output. */
2629 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
2630 [ # # ]: 0 : if (op->ldpc_dec.harq_combined_output.length > 0) {
2631 : : /* Push the HARQ output into host memory overwriting existing data. */
2632 : : struct rte_mbuf *hq_output_head, *hq_output;
2633 : 0 : op->ldpc_dec.harq_combined_output.data->data_len = 0;
2634 : : hq_output_head = op->ldpc_dec.harq_combined_output.data;
2635 : : hq_output = op->ldpc_dec.harq_combined_output.data;
2636 : 0 : hq_len = op->ldpc_dec.harq_combined_output.length;
2637 [ # # # # ]: 0 : if (unlikely(!mbuf_append(hq_output_head, hq_output, hq_len))) {
2638 : 0 : acc_error_log(q, (void *)op, ACC_ERR_REJ_HARQ_OUT,
2639 : : "HARQ output mbuf cannot be appended Buffer %d Current data %d New data %d\n",
2640 : 0 : hq_output->buf_len, hq_output->data_len, hq_len);
2641 : :
2642 : 0 : return -1;
2643 : : }
2644 : : }
2645 : :
2646 [ # # ]: 0 : if (op->ldpc_dec.soft_output.length > 0)
2647 [ # # ]: 0 : mbuf_append(op->ldpc_dec.soft_output.data, op->ldpc_dec.soft_output.data,
2648 : : op->ldpc_dec.soft_output.length);
2649 : :
2650 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2651 : : rte_memdump(stderr, "FCW", &desc->req.fcw_ld,
2652 : : sizeof(desc->req.fcw_ld) - 8);
2653 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2654 : : #endif
2655 : :
2656 : : /* One CB (one op) was successfully prepared to enqueue. */
2657 : : return 1;
2658 : : }
2659 : :
2660 : :
2661 : : /* Enqueue one decode operations for device in TB mode. */
2662 : : static inline int
2663 : 0 : vrb_enqueue_ldpc_dec_one_op_tb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2664 : : uint16_t total_enqueued_cbs, uint8_t cbs_in_tb)
2665 : : {
2666 : : union acc_dma_desc *desc = NULL;
2667 : : union acc_dma_desc *desc_first = NULL;
2668 : : int ret;
2669 : : uint8_t r, c;
2670 : : uint32_t in_offset, h_out_offset, h_out_length, mbuf_total_left, seg_total_left;
2671 : : struct rte_mbuf *input, *h_output_head, *h_output;
2672 : : uint16_t current_enqueued_cbs = 0;
2673 : : uint16_t desc_idx, sys_cols, trail_len = 0;
2674 : : uint64_t fcw_offset;
2675 : : union acc_harq_layout_data *harq_layout;
2676 : :
2677 : : desc_idx = acc_desc_idx(q, total_enqueued_cbs);
2678 : 0 : desc = q->ring_addr + desc_idx;
2679 : : desc_first = desc;
2680 : : fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
2681 : 0 : harq_layout = q->d->harq_layout;
2682 : 0 : vrb_fcw_ld_fill(op, &desc->req.fcw_ld, harq_layout, q->d->device_variant);
2683 : :
2684 : 0 : input = op->ldpc_dec.input.data;
2685 : 0 : h_output_head = h_output = op->ldpc_dec.hard_output.data;
2686 : 0 : in_offset = op->ldpc_dec.input.offset;
2687 : 0 : h_out_offset = op->ldpc_dec.hard_output.offset;
2688 : 0 : h_out_length = 0;
2689 : 0 : mbuf_total_left = op->ldpc_dec.input.length;
2690 : 0 : c = op->ldpc_dec.tb_params.c;
2691 : 0 : r = op->ldpc_dec.tb_params.r;
2692 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK)) {
2693 [ # # ]: 0 : sys_cols = (op->ldpc_dec.basegraph == 1) ? 22 : 10;
2694 : 0 : trail_len = sys_cols * op->ldpc_dec.z_c -
2695 : 0 : op->ldpc_dec.n_filler - 24;
2696 : : }
2697 : :
2698 [ # # ]: 0 : while (mbuf_total_left > 0 && r < c) {
2699 [ # # ]: 0 : if (unlikely((input == NULL) || (h_output == NULL)))
2700 : : return -1;
2701 : :
2702 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_DEC_SCATTER_GATHER))
2703 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2704 : : else
2705 : 0 : seg_total_left = op->ldpc_dec.input.length;
2706 : : /* Set up DMA descriptor. */
2707 : : desc_idx = acc_desc_idx(q, total_enqueued_cbs);
2708 : 0 : desc = q->ring_addr + desc_idx;
2709 : 0 : fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
2710 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
2711 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_LD_BLEN;
2712 [ # # ]: 0 : rte_memcpy(&desc->req.fcw_ld, &desc_first->req.fcw_ld, ACC_FCW_LD_BLEN);
2713 : 0 : desc->req.fcw_ld.tb_trailer_size = (c - r - 1) * trail_len;
2714 : 0 : ret = vrb_dma_desc_ld_fill(op, &desc->req, &input,
2715 : : h_output, &in_offset, &h_out_offset,
2716 : : &h_out_length,
2717 : : &mbuf_total_left, &seg_total_left,
2718 : 0 : &desc->req.fcw_ld, q->d->device_variant, q);
2719 : :
2720 [ # # ]: 0 : if (unlikely(ret < 0))
2721 : 0 : return ret;
2722 : :
2723 : : /* Hard output. */
2724 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
2725 : :
2726 : : /* Set total number of CBs in TB. */
2727 : 0 : desc->req.cbs_in_tb = cbs_in_tb;
2728 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2729 : : rte_memdump(stderr, "FCW", &desc->req.fcw_td,
2730 : : sizeof(desc->req.fcw_td) - 8);
2731 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2732 : : #endif
2733 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_DEC_SCATTER_GATHER)
2734 [ # # ]: 0 : && (seg_total_left == 0)) {
2735 : : /* Go to the next mbuf. */
2736 : 0 : input = input->next;
2737 : 0 : in_offset = 0;
2738 : 0 : h_output = h_output->next;
2739 : 0 : h_out_offset = 0;
2740 : : }
2741 : 0 : total_enqueued_cbs++;
2742 : 0 : current_enqueued_cbs++;
2743 : 0 : r++;
2744 : : }
2745 : :
2746 : : /* In case the number of CB doesn't match, the configuration was invalid. */
2747 [ # # ]: 0 : if (unlikely(current_enqueued_cbs != cbs_in_tb))
2748 : : return -1;
2749 : :
2750 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2751 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
2752 : : return -EINVAL;
2753 : : #endif
2754 : : /* Set SDone on last CB descriptor for TB mode. */
2755 : 0 : desc->req.sdone_enable = 1;
2756 : :
2757 : 0 : return current_enqueued_cbs;
2758 : : }
2759 : :
2760 : : /* Enqueue one decode operations for device in TB mode. */
2761 : : static inline int
2762 : 0 : enqueue_dec_one_op_tb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2763 : : uint16_t total_enqueued_cbs, uint8_t cbs_in_tb)
2764 : : {
2765 : : union acc_dma_desc *desc = NULL;
2766 : : int ret;
2767 : : uint8_t r, c;
2768 : : uint32_t in_offset, h_out_offset, s_out_offset, s_out_length,
2769 : : h_out_length, mbuf_total_left, seg_total_left;
2770 : : struct rte_mbuf *input, *h_output_head, *h_output,
2771 : : *s_output_head, *s_output;
2772 : : uint16_t desc_idx, current_enqueued_cbs = 0;
2773 : : uint64_t fcw_offset;
2774 : :
2775 : : desc_idx = acc_desc_idx(q, total_enqueued_cbs);
2776 : 0 : desc = q->ring_addr + desc_idx;
2777 : 0 : fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
2778 : 0 : vrb_fcw_td_fill(op, &desc->req.fcw_td);
2779 : :
2780 : 0 : input = op->turbo_dec.input.data;
2781 : 0 : h_output_head = h_output = op->turbo_dec.hard_output.data;
2782 : 0 : s_output_head = s_output = op->turbo_dec.soft_output.data;
2783 : 0 : in_offset = op->turbo_dec.input.offset;
2784 : 0 : h_out_offset = op->turbo_dec.hard_output.offset;
2785 : 0 : s_out_offset = op->turbo_dec.soft_output.offset;
2786 : 0 : h_out_length = s_out_length = 0;
2787 : 0 : mbuf_total_left = op->turbo_dec.input.length;
2788 : 0 : c = op->turbo_dec.tb_params.c;
2789 : 0 : r = op->turbo_dec.tb_params.r;
2790 : :
2791 [ # # ]: 0 : while (mbuf_total_left > 0 && r < c) {
2792 [ # # ]: 0 : if (unlikely((input == NULL) || (h_output == NULL)))
2793 : : return -1;
2794 : :
2795 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2796 : :
2797 : : /* Set up DMA descriptor */
2798 : : desc = acc_desc(q, total_enqueued_cbs);
2799 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
2800 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_TD_BLEN;
2801 : 0 : ret = vrb_dma_desc_td_fill(op, &desc->req, &input,
2802 : : h_output, s_output, &in_offset, &h_out_offset,
2803 : : &s_out_offset, &h_out_length, &s_out_length,
2804 : : &mbuf_total_left, &seg_total_left, r, q);
2805 : :
2806 [ # # ]: 0 : if (unlikely(ret < 0))
2807 : 0 : return ret;
2808 : :
2809 : : /* Hard output */
2810 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
2811 : :
2812 : : /* Soft output */
2813 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
2814 : : RTE_BBDEV_TURBO_SOFT_OUTPUT))
2815 [ # # ]: 0 : mbuf_append(s_output_head, s_output, s_out_length);
2816 : :
2817 : : /* Set total number of CBs in TB */
2818 : 0 : desc->req.cbs_in_tb = cbs_in_tb;
2819 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2820 : : rte_memdump(stderr, "FCW", &desc->req.fcw_td,
2821 : : sizeof(desc->req.fcw_td) - 8);
2822 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2823 : : #endif
2824 : :
2825 [ # # ]: 0 : if (seg_total_left == 0) {
2826 : : /* Go to the next mbuf */
2827 : 0 : input = input->next;
2828 : 0 : in_offset = 0;
2829 : 0 : h_output = h_output->next;
2830 : 0 : h_out_offset = 0;
2831 : :
2832 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
2833 : : RTE_BBDEV_TURBO_SOFT_OUTPUT)) {
2834 : 0 : s_output = s_output->next;
2835 : 0 : s_out_offset = 0;
2836 : : }
2837 : : }
2838 : :
2839 : 0 : total_enqueued_cbs++;
2840 : 0 : current_enqueued_cbs++;
2841 : 0 : r++;
2842 : : }
2843 : :
2844 : : /* In case the number of CB doesn't match, the configuration was invalid. */
2845 [ # # ]: 0 : if (unlikely(current_enqueued_cbs != cbs_in_tb))
2846 : : return -1;
2847 : :
2848 : : /* Set SDone on last CB descriptor for TB mode */
2849 : 0 : desc->req.sdone_enable = 1;
2850 : :
2851 : 0 : return current_enqueued_cbs;
2852 : : }
2853 : :
2854 : : /* Enqueue encode operations for device in CB mode. */
2855 : : static uint16_t
2856 : 0 : vrb_enqueue_enc_cb(struct rte_bbdev_queue_data *q_data,
2857 : : struct rte_bbdev_enc_op **ops, uint16_t num)
2858 : : {
2859 : 0 : struct acc_queue *q = q_data->queue_private;
2860 : 0 : int32_t avail = acc_ring_avail_enq(q);
2861 : : uint16_t i;
2862 : : int ret;
2863 : :
2864 [ # # ]: 0 : for (i = 0; i < num; ++i) {
2865 : : /* Check if there are available space for further processing */
2866 [ # # ]: 0 : if (unlikely(avail - 1 < 0)) {
2867 : : acc_enqueue_ring_full(q_data);
2868 : : break;
2869 : : }
2870 : 0 : avail -= 1;
2871 : :
2872 : 0 : ret = enqueue_enc_one_op_cb(q, ops[i], i);
2873 [ # # ]: 0 : if (ret < 0) {
2874 : : acc_enqueue_invalid(q_data);
2875 : : break;
2876 : : }
2877 : : }
2878 : :
2879 [ # # ]: 0 : if (unlikely(i == 0))
2880 : : return 0; /* Nothing to enqueue */
2881 : :
2882 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
2883 : :
2884 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
2885 : 0 : return i;
2886 : : }
2887 : :
2888 : : /** Enqueue encode operations for device in CB mode. */
2889 : : static inline uint16_t
2890 : 0 : vrb_enqueue_ldpc_enc_cb(struct rte_bbdev_queue_data *q_data,
2891 : : struct rte_bbdev_enc_op **ops, uint16_t num)
2892 : : {
2893 : 0 : struct acc_queue *q = q_data->queue_private;
2894 : 0 : int32_t avail = acc_ring_avail_enq(q);
2895 : : uint16_t i = 0;
2896 : : int ret, desc_idx = 0;
2897 : 0 : int16_t enq, left = num;
2898 : :
2899 [ # # ]: 0 : while (left > 0) {
2900 [ # # ]: 0 : if (unlikely(avail < 1)) {
2901 : : acc_enqueue_ring_full(q_data);
2902 : : break;
2903 : : }
2904 : 0 : avail--;
2905 : 0 : enq = RTE_MIN(left, ACC_MUX_5GDL_DESC);
2906 : 0 : enq = check_mux(&ops[i], enq);
2907 : 0 : ret = enqueue_ldpc_enc_n_op_cb(q, &ops[i], desc_idx, enq);
2908 [ # # ]: 0 : if (ret < 0) {
2909 : : acc_enqueue_invalid(q_data);
2910 : : break;
2911 : : }
2912 : 0 : i += enq;
2913 : 0 : desc_idx++;
2914 : 0 : left = num - i;
2915 : : }
2916 : :
2917 [ # # ]: 0 : if (unlikely(i == 0))
2918 : : return 0; /* Nothing to enqueue. */
2919 : :
2920 : 0 : acc_dma_enqueue(q, desc_idx, &q_data->queue_stats);
2921 : :
2922 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
2923 : :
2924 : 0 : return i;
2925 : : }
2926 : :
2927 : : /* Enqueue encode operations for device in TB mode. */
2928 : : static uint16_t
2929 : 0 : vrb_enqueue_enc_tb(struct rte_bbdev_queue_data *q_data,
2930 : : struct rte_bbdev_enc_op **ops, uint16_t num)
2931 : : {
2932 : 0 : struct acc_queue *q = q_data->queue_private;
2933 : 0 : int32_t avail = acc_ring_avail_enq(q);
2934 : : uint16_t i, enqueued_cbs = 0;
2935 : : uint8_t cbs_in_tb;
2936 : : int ret;
2937 : :
2938 [ # # ]: 0 : for (i = 0; i < num; ++i) {
2939 : 0 : cbs_in_tb = get_num_cbs_in_tb_enc(&ops[i]->turbo_enc);
2940 : : /* Check if there are available space for further processing */
2941 [ # # # # ]: 0 : if (unlikely((avail - cbs_in_tb < 0) || (cbs_in_tb == 0))) {
2942 : : acc_enqueue_ring_full(q_data);
2943 : : break;
2944 : : }
2945 : : avail -= cbs_in_tb;
2946 : :
2947 : 0 : ret = enqueue_enc_one_op_tb(q, ops[i], enqueued_cbs, cbs_in_tb);
2948 [ # # ]: 0 : if (ret <= 0) {
2949 : : acc_enqueue_invalid(q_data);
2950 : : break;
2951 : : }
2952 : 0 : enqueued_cbs += ret;
2953 : : }
2954 [ # # ]: 0 : if (unlikely(enqueued_cbs == 0))
2955 : : return 0; /* Nothing to enqueue */
2956 : :
2957 : 0 : acc_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
2958 : :
2959 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
2960 : :
2961 : 0 : return i;
2962 : : }
2963 : :
2964 : : /* Enqueue LDPC encode operations for device in TB mode. */
2965 : : static uint16_t
2966 : 0 : vrb_enqueue_ldpc_enc_tb(struct rte_bbdev_queue_data *q_data,
2967 : : struct rte_bbdev_enc_op **ops, uint16_t num)
2968 : : {
2969 : 0 : struct acc_queue *q = q_data->queue_private;
2970 : 0 : int32_t avail = acc_ring_avail_enq(q);
2971 : : uint16_t i, enqueued_descs = 0;
2972 : : uint8_t cbs_in_tb;
2973 : : int descs_used;
2974 : :
2975 [ # # ]: 0 : for (i = 0; i < num; ++i) {
2976 [ # # ]: 0 : if (q->d->device_variant == VRB1_VARIANT) {
2977 : 0 : cbs_in_tb = get_num_cbs_in_tb_ldpc_enc(&ops[i]->ldpc_enc);
2978 : : /* Check if there are available space for further processing. */
2979 [ # # # # ]: 0 : if (unlikely((avail - cbs_in_tb < 0) || (cbs_in_tb == 0))) {
2980 : : acc_enqueue_ring_full(q_data);
2981 : : break;
2982 : : }
2983 : 0 : descs_used = vrb1_enqueue_ldpc_enc_one_op_tb(q, ops[i],
2984 : : enqueued_descs, cbs_in_tb);
2985 : : } else {
2986 [ # # ]: 0 : if (unlikely(avail < 1)) {
2987 : : acc_enqueue_ring_full(q_data);
2988 : : break;
2989 : : }
2990 : 0 : descs_used = vrb2_enqueue_ldpc_enc_one_op_tb(q, ops[i], enqueued_descs);
2991 : : }
2992 [ # # ]: 0 : if (descs_used < 0) {
2993 : : acc_enqueue_invalid(q_data);
2994 : : break;
2995 : : }
2996 : 0 : enqueued_descs += descs_used;
2997 : 0 : avail -= descs_used;
2998 : : }
2999 [ # # ]: 0 : if (unlikely(enqueued_descs == 0))
3000 : : return 0; /* Nothing to enqueue. */
3001 : :
3002 : 0 : acc_dma_enqueue(q, enqueued_descs, &q_data->queue_stats);
3003 : :
3004 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3005 : :
3006 : 0 : return i;
3007 : : }
3008 : :
3009 : : /* Enqueue encode operations for device. */
3010 : : static uint16_t
3011 : 0 : vrb_enqueue_enc(struct rte_bbdev_queue_data *q_data,
3012 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3013 : : {
3014 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3015 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3016 : : return 0;
3017 [ # # ]: 0 : if (ops[0]->turbo_enc.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3018 : 0 : return vrb_enqueue_enc_tb(q_data, ops, num);
3019 : : else
3020 : 0 : return vrb_enqueue_enc_cb(q_data, ops, num);
3021 : : }
3022 : :
3023 : : /* Enqueue encode operations for device. */
3024 : : static uint16_t
3025 : 0 : vrb_enqueue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
3026 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3027 : : {
3028 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3029 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3030 : : return 0;
3031 [ # # ]: 0 : if (ops[0]->ldpc_enc.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3032 : 0 : return vrb_enqueue_ldpc_enc_tb(q_data, ops, num);
3033 : : else
3034 : 0 : return vrb_enqueue_ldpc_enc_cb(q_data, ops, num);
3035 : : }
3036 : :
3037 : :
3038 : : /* Enqueue decode operations for device in CB mode. */
3039 : : static uint16_t
3040 : 0 : vrb_enqueue_dec_cb(struct rte_bbdev_queue_data *q_data,
3041 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3042 : : {
3043 : 0 : struct acc_queue *q = q_data->queue_private;
3044 : 0 : int32_t avail = acc_ring_avail_enq(q);
3045 : : uint16_t i;
3046 : : int ret;
3047 : :
3048 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3049 : : /* Check if there are available space for further processing. */
3050 [ # # ]: 0 : if (unlikely(avail - 1 < 0))
3051 : : break;
3052 : 0 : avail -= 1;
3053 : :
3054 : 0 : ret = enqueue_dec_one_op_cb(q, ops[i], i);
3055 [ # # ]: 0 : if (ret < 0)
3056 : : break;
3057 : : }
3058 : :
3059 [ # # ]: 0 : if (unlikely(i == 0))
3060 : : return 0; /* Nothing to enqueue. */
3061 : :
3062 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
3063 : :
3064 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3065 : :
3066 : 0 : return i;
3067 : : }
3068 : :
3069 : : /* Enqueue decode operations for device in TB mode. */
3070 : : static uint16_t
3071 : 0 : vrb_enqueue_ldpc_dec_tb(struct rte_bbdev_queue_data *q_data,
3072 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3073 : : {
3074 : 0 : struct acc_queue *q = q_data->queue_private;
3075 : 0 : int32_t avail = acc_ring_avail_enq(q);
3076 : : uint16_t i, enqueued_cbs = 0;
3077 : : uint8_t cbs_in_tb;
3078 : : int ret;
3079 : :
3080 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3081 : 0 : cbs_in_tb = get_num_cbs_in_tb_ldpc_dec(&ops[i]->ldpc_dec);
3082 : : /* Check if there are available space for further processing. */
3083 [ # # # # ]: 0 : if (unlikely((avail - cbs_in_tb < 0) ||
3084 : : (cbs_in_tb == 0)))
3085 : : break;
3086 : : avail -= cbs_in_tb;
3087 : :
3088 : 0 : ret = vrb_enqueue_ldpc_dec_one_op_tb(q, ops[i],
3089 : : enqueued_cbs, cbs_in_tb);
3090 [ # # ]: 0 : if (ret <= 0)
3091 : : break;
3092 : 0 : enqueued_cbs += ret;
3093 : : }
3094 : :
3095 : 0 : acc_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
3096 : :
3097 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3098 : 0 : return i;
3099 : : }
3100 : :
3101 : : /* Enqueue decode operations for device in CB mode. */
3102 : : static uint16_t
3103 : 0 : vrb_enqueue_ldpc_dec_cb(struct rte_bbdev_queue_data *q_data,
3104 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3105 : : {
3106 : 0 : struct acc_queue *q = q_data->queue_private;
3107 : 0 : int32_t avail = acc_ring_avail_enq(q);
3108 : : uint16_t i;
3109 : : int ret;
3110 : : bool same_op = false;
3111 : :
3112 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3113 : : /* Check if there are available space for further processing. */
3114 [ # # ]: 0 : if (unlikely(avail < 1)) {
3115 : : acc_enqueue_ring_full(q_data);
3116 : : break;
3117 : : }
3118 : 0 : avail -= 1;
3119 : 0 : rte_bbdev_log(INFO, "Op %d %d %d %d %d %d %d %d %d %d %d %d",
3120 : : i, ops[i]->ldpc_dec.op_flags, ops[i]->ldpc_dec.rv_index,
3121 : : ops[i]->ldpc_dec.iter_max, ops[i]->ldpc_dec.iter_count,
3122 : : ops[i]->ldpc_dec.basegraph, ops[i]->ldpc_dec.z_c,
3123 : : ops[i]->ldpc_dec.n_cb, ops[i]->ldpc_dec.q_m,
3124 : : ops[i]->ldpc_dec.n_filler, ops[i]->ldpc_dec.cb_params.e,
3125 : : same_op);
3126 : 0 : ret = vrb_enqueue_ldpc_dec_one_op_cb(q, ops[i], i, same_op);
3127 [ # # ]: 0 : if (ret < 0) {
3128 : : acc_enqueue_invalid(q_data);
3129 : : break;
3130 : : }
3131 : : }
3132 : :
3133 [ # # ]: 0 : if (unlikely(i == 0))
3134 : : return 0; /* Nothing to enqueue. */
3135 : :
3136 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
3137 : :
3138 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3139 : 0 : return i;
3140 : : }
3141 : :
3142 : :
3143 : : /* Enqueue decode operations for device in TB mode. */
3144 : : static uint16_t
3145 : 0 : vrb_enqueue_dec_tb(struct rte_bbdev_queue_data *q_data,
3146 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3147 : : {
3148 : 0 : struct acc_queue *q = q_data->queue_private;
3149 : 0 : int32_t avail = acc_ring_avail_enq(q);
3150 : : uint16_t i, enqueued_cbs = 0;
3151 : : uint8_t cbs_in_tb;
3152 : : int ret;
3153 : :
3154 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3155 : 0 : cbs_in_tb = get_num_cbs_in_tb_dec(&ops[i]->turbo_dec);
3156 : : /* Check if there are available space for further processing */
3157 [ # # # # ]: 0 : if (unlikely((avail - cbs_in_tb < 0) || (cbs_in_tb == 0))) {
3158 : : acc_enqueue_ring_full(q_data);
3159 : : break;
3160 : : }
3161 : : avail -= cbs_in_tb;
3162 : :
3163 : 0 : ret = enqueue_dec_one_op_tb(q, ops[i], enqueued_cbs, cbs_in_tb);
3164 [ # # ]: 0 : if (ret <= 0) {
3165 : : acc_enqueue_invalid(q_data);
3166 : : break;
3167 : : }
3168 : 0 : enqueued_cbs += ret;
3169 : : }
3170 : :
3171 : 0 : acc_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
3172 : :
3173 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3174 : :
3175 : 0 : return i;
3176 : : }
3177 : :
3178 : : /* Enqueue decode operations for device. */
3179 : : static uint16_t
3180 : 0 : vrb_enqueue_dec(struct rte_bbdev_queue_data *q_data,
3181 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3182 : : {
3183 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3184 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3185 : : return 0;
3186 [ # # ]: 0 : if (ops[0]->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3187 : 0 : return vrb_enqueue_dec_tb(q_data, ops, num);
3188 : : else
3189 : 0 : return vrb_enqueue_dec_cb(q_data, ops, num);
3190 : : }
3191 : :
3192 : : /* Enqueue decode operations for device. */
3193 : : static uint16_t
3194 : 0 : vrb_enqueue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
3195 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3196 : : {
3197 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3198 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3199 : : return 0;
3200 [ # # ]: 0 : if (ops[0]->ldpc_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3201 : 0 : return vrb_enqueue_ldpc_dec_tb(q_data, ops, num);
3202 : : else
3203 : 0 : return vrb_enqueue_ldpc_dec_cb(q_data, ops, num);
3204 : : }
3205 : :
3206 : : /* Update the operation status when dequeuing for any operation type. */
3207 : : static inline void
3208 : : vrb_update_dequeued_operation(union acc_dma_desc *desc, union acc_dma_rsp_desc rsp, int *op_status,
3209 : : uint32_t *aq_dequeued, bool clear_rsp, bool clear_opstatus)
3210 : : {
3211 : : rte_bbdev_log_debug("Resp. desc %p: %x", desc, rsp.val);
3212 : :
3213 : : /* Set status based on DMA response. */
3214 : : if (clear_opstatus)
3215 : : *op_status = 0;
3216 : 0 : *op_status |= ((rsp.input_err) ? (1 << RTE_BBDEV_DATA_ERROR) : 0);
3217 : 0 : *op_status |= ((rsp.dma_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3218 : 0 : *op_status |= ((rsp.fcw_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3219 : 0 : *op_status |= ((rsp.engine_hung) ? (1 << RTE_BBDEV_ENGINE_ERROR) : 0);
3220 : :
3221 : 0 : if (desc->req.last_desc_in_batch) {
3222 : 0 : (*aq_dequeued)++;
3223 : 0 : desc->req.last_desc_in_batch = 0;
3224 : : }
3225 : :
3226 : : if (clear_rsp) {
3227 : : /* Clear response explicitly. */
3228 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3229 : 0 : desc->rsp.add_info_0 = 0; /* Reserved bits. */
3230 : 0 : desc->rsp.add_info_1 = 0; /* Reserved bits. */
3231 : : }
3232 : : }
3233 : :
3234 : : /* Dequeue one encode operations from device in CB mode. */
3235 : : static inline int
3236 : 0 : vrb_dequeue_enc_one_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op **ref_op,
3237 : : uint16_t *dequeued_ops, uint32_t *aq_dequeued, uint16_t *dequeued_descs,
3238 : : uint16_t max_requested_ops)
3239 : : {
3240 : : union acc_dma_desc *desc, atom_desc;
3241 : : union acc_dma_rsp_desc rsp;
3242 : : struct rte_bbdev_enc_op *op;
3243 : : int i;
3244 : : struct acc_ptrs *context_ptrs;
3245 : : uint16_t desc_idx;
3246 : :
3247 [ # # ]: 0 : desc_idx = acc_desc_idx_tail(q, *dequeued_descs);
3248 : 0 : desc = q->ring_addr + desc_idx;
3249 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3250 : : rte_memory_order_relaxed);
3251 : :
3252 [ # # ]: 0 : if (*dequeued_ops + desc->req.numCBs > max_requested_ops)
3253 : : return -1;
3254 : :
3255 : : /* Check fdone bit. */
3256 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3257 : : return -1;
3258 : :
3259 : : rsp.val = atom_desc.rsp.val;
3260 : :
3261 : : /* Dequeue. */
3262 [ # # ]: 0 : op = desc->req.op_addr;
3263 : :
3264 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, true, true);
3265 : :
3266 : 0 : ref_op[0] = op;
3267 : 0 : context_ptrs = q->companion_ring_addr + desc_idx;
3268 [ # # ]: 0 : for (i = 1 ; i < desc->req.numCBs; i++)
3269 : 0 : ref_op[i] = context_ptrs->ptr[i].op_addr;
3270 : :
3271 : : /* One op was successfully dequeued. */
3272 : 0 : (*dequeued_descs)++;
3273 : 0 : *dequeued_ops += desc->req.numCBs;
3274 : 0 : return desc->req.numCBs;
3275 : : }
3276 : :
3277 : : /* Dequeue one LDPC encode operations from VRB2 device in TB mode. */
3278 : : static inline int
3279 : 0 : vrb2_dequeue_ldpc_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op **ref_op,
3280 : : uint16_t *dequeued_ops, uint32_t *aq_dequeued,
3281 : : uint16_t *dequeued_descs)
3282 : : {
3283 : : union acc_dma_desc *desc, atom_desc;
3284 : : union acc_dma_rsp_desc rsp;
3285 : : struct rte_bbdev_enc_op *op;
3286 : :
3287 [ # # ]: 0 : desc = acc_desc_tail(q, *dequeued_descs);
3288 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3289 : : rte_memory_order_relaxed);
3290 : :
3291 : : /* Check fdone bit. */
3292 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3293 : : return -1;
3294 : :
3295 : : rsp.val = atom_desc.rsp.val;
3296 : :
3297 : : /* Dequeue. */
3298 [ # # ]: 0 : op = desc->req.op_addr;
3299 : :
3300 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, true, true);
3301 : :
3302 : : /* One op was successfully dequeued */
3303 : 0 : ref_op[0] = op;
3304 : 0 : (*dequeued_descs)++;
3305 : 0 : (*dequeued_ops)++;
3306 : 0 : return 1;
3307 : : }
3308 : :
3309 : : /* Dequeue one encode operations from device in TB mode.
3310 : : * That operation may cover multiple descriptors.
3311 : : */
3312 : : static inline int
3313 : 0 : vrb_dequeue_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op **ref_op,
3314 : : uint16_t *dequeued_ops, uint32_t *aq_dequeued,
3315 : : uint16_t *dequeued_descs, uint16_t max_requested_ops)
3316 : : {
3317 : : union acc_dma_desc *desc, *last_desc, atom_desc;
3318 : : union acc_dma_rsp_desc rsp;
3319 : : struct rte_bbdev_enc_op *op;
3320 : : uint8_t i = 0;
3321 : : uint16_t current_dequeued_descs = 0, descs_in_tb;
3322 : :
3323 [ # # ]: 0 : desc = acc_desc_tail(q, *dequeued_descs);
3324 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3325 : : rte_memory_order_relaxed);
3326 : :
3327 [ # # ]: 0 : if (*dequeued_ops + 1 > max_requested_ops)
3328 : : return -1;
3329 : :
3330 : : /* Check fdone bit. */
3331 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3332 : : return -1;
3333 : :
3334 : : /* Get number of CBs in dequeued TB. */
3335 : 0 : descs_in_tb = desc->req.cbs_in_tb;
3336 : : /* Get last CB */
3337 [ # # ]: 0 : last_desc = acc_desc_tail(q, *dequeued_descs + descs_in_tb - 1);
3338 : : /* Check if last CB in TB is ready to dequeue (and thus
3339 : : * the whole TB) - checking sdone bit. If not return.
3340 : : */
3341 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)last_desc,
3342 : : rte_memory_order_relaxed);
3343 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_SDONE))
3344 : : return -1;
3345 : :
3346 : : /* Dequeue. */
3347 : 0 : op = desc->req.op_addr;
3348 : :
3349 : : /* Clearing status, it will be set based on response. */
3350 : 0 : op->status = 0;
3351 : :
3352 [ # # ]: 0 : while (i < descs_in_tb) {
3353 [ # # ]: 0 : desc = acc_desc_tail(q, *dequeued_descs);
3354 [ # # ]: 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3355 : : rte_memory_order_relaxed);
3356 : : rsp.val = atom_desc.rsp.val;
3357 : :
3358 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, true, false);
3359 : :
3360 : 0 : (*dequeued_descs)++;
3361 : 0 : current_dequeued_descs++;
3362 : 0 : i++;
3363 : : }
3364 : :
3365 : 0 : *ref_op = op;
3366 : 0 : (*dequeued_ops)++;
3367 : 0 : return current_dequeued_descs;
3368 : : }
3369 : :
3370 : : /* Dequeue one decode operation from device in CB mode. */
3371 : : static inline int
3372 [ # # ]: 0 : vrb_dequeue_dec_one_op_cb(struct rte_bbdev_queue_data *q_data,
3373 : : struct acc_queue *q, struct rte_bbdev_dec_op **ref_op,
3374 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3375 : : {
3376 : : union acc_dma_desc *desc, atom_desc;
3377 : : union acc_dma_rsp_desc rsp;
3378 : : struct rte_bbdev_dec_op *op;
3379 : :
3380 : : desc = acc_desc_tail(q, dequeued_cbs);
3381 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3382 : : rte_memory_order_relaxed);
3383 : :
3384 : : /* Check fdone bit. */
3385 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3386 : : return -1;
3387 : :
3388 : 0 : rsp.val = atom_desc.rsp.val;
3389 : :
3390 : : /* Dequeue. */
3391 [ # # ]: 0 : op = desc->req.op_addr;
3392 : :
3393 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, false, true);
3394 : :
3395 [ # # ]: 0 : if (op->status != 0) {
3396 : : /* These errors are not expected. */
3397 : 0 : q_data->queue_stats.dequeue_err_count++;
3398 : 0 : vrb_check_ir(q->d);
3399 : : }
3400 : :
3401 : : /* CRC invalid if error exists. */
3402 [ # # ]: 0 : if (!op->status)
3403 : 0 : op->status |= rsp.crc_status << RTE_BBDEV_CRC_ERROR;
3404 : 0 : op->turbo_dec.iter_count = (uint8_t) rsp.iter_cnt;
3405 : :
3406 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3407 : 0 : desc->rsp.add_info_0 = 0;
3408 : 0 : desc->rsp.add_info_1 = 0;
3409 : 0 : *ref_op = op;
3410 : :
3411 : : /* One CB (op) was successfully dequeued. */
3412 : 0 : return 1;
3413 : : }
3414 : :
3415 : : /* Dequeue one decode operations from device in CB mode. */
3416 : : static inline int
3417 [ # # ]: 0 : vrb_dequeue_ldpc_dec_one_op_cb(struct rte_bbdev_queue_data *q_data,
3418 : : struct acc_queue *q, struct rte_bbdev_dec_op **ref_op,
3419 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3420 : : {
3421 : : union acc_dma_desc *desc, atom_desc;
3422 : : union acc_dma_rsp_desc rsp;
3423 : : struct rte_bbdev_dec_op *op;
3424 : :
3425 : : desc = acc_desc_tail(q, dequeued_cbs);
3426 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3427 : : rte_memory_order_relaxed);
3428 : :
3429 : : /* Check fdone bit. */
3430 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3431 : : return -1;
3432 : :
3433 : 0 : rsp.val = atom_desc.rsp.val;
3434 : : rte_bbdev_log_debug("Resp. desc %p: %x %x %x", desc, rsp.val, desc->rsp.add_info_0,
3435 : : desc->rsp.add_info_1);
3436 : :
3437 : : /* Dequeue. */
3438 [ # # ]: 0 : op = desc->req.op_addr;
3439 : :
3440 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, false, true);
3441 : :
3442 : : /* Additional op status update for LDPC Decoder. */
3443 [ # # ]: 0 : if (op->status != 0)
3444 : 0 : q_data->queue_stats.dequeue_err_count++;
3445 : :
3446 : 0 : op->status |= rsp.crc_status << RTE_BBDEV_CRC_ERROR;
3447 [ # # # # ]: 0 : if (op->ldpc_dec.hard_output.length > 0 && !rsp.synd_ok)
3448 : 0 : op->status |= 1 << RTE_BBDEV_SYNDROME_ERROR;
3449 : :
3450 [ # # # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK) ||
3451 : : check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_16_CHECK)) {
3452 [ # # ]: 0 : if (desc->rsp.add_info_1 != 0)
3453 : 0 : op->status |= 1 << RTE_BBDEV_CRC_ERROR;
3454 : : }
3455 : :
3456 : 0 : op->ldpc_dec.iter_count = (uint8_t) rsp.iter_cnt;
3457 : :
3458 [ # # ]: 0 : if (op->status & (1 << RTE_BBDEV_DRV_ERROR))
3459 : 0 : vrb_check_ir(q->d);
3460 : :
3461 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3462 : 0 : desc->rsp.add_info_0 = 0;
3463 : 0 : desc->rsp.add_info_1 = 0;
3464 : :
3465 : 0 : *ref_op = op;
3466 : :
3467 : : /* One CB (op) was successfully dequeued. */
3468 : 0 : return 1;
3469 : : }
3470 : :
3471 : : /* Dequeue one decode operations from device in TB mode for 4G or 5G. */
3472 : : static inline int
3473 [ # # ]: 0 : vrb_dequeue_dec_one_op_tb(struct acc_queue *q, struct rte_bbdev_dec_op **ref_op,
3474 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3475 : : {
3476 : : union acc_dma_desc *desc, *last_desc, atom_desc;
3477 : : union acc_dma_rsp_desc rsp;
3478 : : struct rte_bbdev_dec_op *op;
3479 : : uint8_t cbs_in_tb = 1, cb_idx = 0;
3480 : : uint32_t tb_crc_check = 0;
3481 : :
3482 : : desc = acc_desc_tail(q, dequeued_cbs);
3483 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3484 : : rte_memory_order_relaxed);
3485 : :
3486 : : /* Check fdone bit. */
3487 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3488 : : return -1;
3489 : :
3490 : : /* Dequeue. */
3491 : 0 : op = desc->req.op_addr;
3492 : :
3493 : : /* Get number of CBs in dequeued TB. */
3494 : 0 : cbs_in_tb = desc->req.cbs_in_tb;
3495 : : /* Get last CB. */
3496 [ # # ]: 0 : last_desc = acc_desc_tail(q, dequeued_cbs + cbs_in_tb - 1);
3497 : : /* Check if last CB in TB is ready to dequeue (and thus the whole TB) - checking sdone bit.
3498 : : * If not return.
3499 : : */
3500 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)last_desc,
3501 : : rte_memory_order_relaxed);
3502 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_SDONE))
3503 : : return -1;
3504 : :
3505 : : /* Clearing status, it will be set based on response. */
3506 : 0 : op->status = 0;
3507 : :
3508 : : /* Read remaining CBs if exists. */
3509 [ # # ]: 0 : while (cb_idx < cbs_in_tb) {
3510 : : desc = acc_desc_tail(q, dequeued_cbs);
3511 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3512 : : rte_memory_order_relaxed);
3513 [ # # ]: 0 : rsp.val = atom_desc.rsp.val;
3514 : : rte_bbdev_log_debug("Resp. desc %p: %x %x %x", desc,
3515 : : rsp.val, desc->rsp.add_info_0,
3516 : : desc->rsp.add_info_1);
3517 : :
3518 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, false, false);
3519 : :
3520 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK))
3521 : 0 : tb_crc_check ^= desc->rsp.add_info_1;
3522 : :
3523 : : /* CRC invalid if error exists. */
3524 [ # # ]: 0 : if (!op->status)
3525 : 0 : op->status |= rsp.crc_status << RTE_BBDEV_CRC_ERROR;
3526 [ # # ]: 0 : if (q->op_type == RTE_BBDEV_OP_LDPC_DEC)
3527 : 0 : op->ldpc_dec.iter_count = RTE_MAX((uint8_t) rsp.iter_cnt,
3528 : : op->ldpc_dec.iter_count);
3529 : : else
3530 : 0 : op->turbo_dec.iter_count = RTE_MAX((uint8_t) rsp.iter_cnt,
3531 : : op->turbo_dec.iter_count);
3532 : :
3533 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3534 : 0 : desc->rsp.add_info_0 = 0;
3535 : 0 : desc->rsp.add_info_1 = 0;
3536 : 0 : dequeued_cbs++;
3537 : 0 : cb_idx++;
3538 : : }
3539 : :
3540 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24A_CHECK)) {
3541 : : rte_bbdev_log_debug("TB-CRC Check %x", tb_crc_check);
3542 [ # # ]: 0 : if (tb_crc_check > 0)
3543 : 0 : op->status |= 1 << RTE_BBDEV_CRC_ERROR;
3544 : : }
3545 : :
3546 : 0 : *ref_op = op;
3547 : :
3548 : 0 : return cb_idx;
3549 : : }
3550 : :
3551 : : /* Dequeue encode operations from device. */
3552 : : static uint16_t
3553 : 0 : vrb_dequeue_enc(struct rte_bbdev_queue_data *q_data,
3554 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3555 : : {
3556 [ # # ]: 0 : struct acc_queue *q = q_data->queue_private;
3557 : : uint32_t avail = acc_ring_avail_deq(q);
3558 : 0 : uint32_t aq_dequeued = 0;
3559 : 0 : uint16_t i, dequeued_ops = 0, dequeued_descs = 0;
3560 : : int ret, cbm;
3561 : : struct rte_bbdev_enc_op *op;
3562 [ # # ]: 0 : if (avail == 0)
3563 : : return 0;
3564 : : op = acc_op_tail(q, 0);
3565 : 0 : cbm = op->turbo_enc.code_block_mode;
3566 : :
3567 [ # # ]: 0 : for (i = 0; i < avail; i++) {
3568 [ # # ]: 0 : if (cbm == RTE_BBDEV_TRANSPORT_BLOCK)
3569 : 0 : ret = vrb_dequeue_enc_one_op_tb(q, &ops[dequeued_ops],
3570 : : &dequeued_ops, &aq_dequeued,
3571 : : &dequeued_descs, num);
3572 : : else
3573 : 0 : ret = vrb_dequeue_enc_one_op_cb(q, &ops[dequeued_ops],
3574 : : &dequeued_ops, &aq_dequeued,
3575 : : &dequeued_descs, num);
3576 [ # # ]: 0 : if (ret < 0)
3577 : : break;
3578 : : }
3579 : :
3580 : 0 : q->aq_dequeued += aq_dequeued;
3581 : 0 : q->sw_ring_tail += dequeued_descs;
3582 : :
3583 : 0 : acc_update_qstat_dequeue(q_data, dequeued_ops);
3584 : :
3585 : 0 : return dequeued_ops;
3586 : : }
3587 : :
3588 : : /* Dequeue LDPC encode operations from device. */
3589 : : static uint16_t
3590 : 0 : vrb_dequeue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
3591 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3592 : : {
3593 [ # # ]: 0 : struct acc_queue *q = q_data->queue_private;
3594 : : uint32_t avail = acc_ring_avail_deq(q);
3595 : 0 : uint32_t aq_dequeued = 0;
3596 : 0 : uint16_t i, dequeued_ops = 0, dequeued_descs = 0;
3597 : : int ret, cbm;
3598 : : struct rte_bbdev_enc_op *op;
3599 [ # # ]: 0 : if (avail == 0)
3600 : : return 0;
3601 : : op = acc_op_tail(q, 0);
3602 : 0 : cbm = op->ldpc_enc.code_block_mode;
3603 : :
3604 [ # # ]: 0 : for (i = 0; i < avail; i++) {
3605 [ # # ]: 0 : if (cbm == RTE_BBDEV_TRANSPORT_BLOCK)
3606 [ # # ]: 0 : if (q->d->device_variant == VRB1_VARIANT)
3607 : 0 : ret = vrb_dequeue_enc_one_op_tb(q, &ops[dequeued_ops],
3608 : : &dequeued_ops, &aq_dequeued,
3609 : : &dequeued_descs, num);
3610 : : else
3611 : 0 : ret = vrb2_dequeue_ldpc_enc_one_op_tb(q, &ops[dequeued_ops],
3612 : : &dequeued_ops, &aq_dequeued,
3613 : : &dequeued_descs);
3614 : : else
3615 : 0 : ret = vrb_dequeue_enc_one_op_cb(q, &ops[dequeued_ops],
3616 : : &dequeued_ops, &aq_dequeued,
3617 : : &dequeued_descs, num);
3618 [ # # ]: 0 : if (ret < 0)
3619 : : break;
3620 : : }
3621 : :
3622 : 0 : q->aq_dequeued += aq_dequeued;
3623 : 0 : q->sw_ring_tail += dequeued_descs;
3624 : :
3625 : 0 : acc_update_qstat_dequeue(q_data, dequeued_ops);
3626 : :
3627 : 0 : return dequeued_ops;
3628 : : }
3629 : :
3630 : : /* Dequeue decode operations from device. */
3631 : : static uint16_t
3632 : 0 : vrb_dequeue_dec(struct rte_bbdev_queue_data *q_data,
3633 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3634 : : {
3635 : 0 : struct acc_queue *q = q_data->queue_private;
3636 : : uint16_t dequeue_num;
3637 : : uint32_t avail = acc_ring_avail_deq(q);
3638 : 0 : uint32_t aq_dequeued = 0;
3639 : : uint16_t i;
3640 : : uint16_t dequeued_cbs = 0;
3641 : : struct rte_bbdev_dec_op *op;
3642 : : int ret;
3643 : :
3644 : 0 : dequeue_num = (avail < num) ? avail : num;
3645 : :
3646 [ # # ]: 0 : for (i = 0; i < dequeue_num; ++i) {
3647 [ # # ]: 0 : op = acc_op_tail(q, dequeued_cbs);
3648 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3649 : 0 : ret = vrb_dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
3650 : : &aq_dequeued);
3651 : : else
3652 : 0 : ret = vrb_dequeue_dec_one_op_cb(q_data, q, &ops[i],
3653 : : dequeued_cbs, &aq_dequeued);
3654 : :
3655 [ # # ]: 0 : if (ret <= 0)
3656 : : break;
3657 : 0 : dequeued_cbs += ret;
3658 : : }
3659 : :
3660 : 0 : q->aq_dequeued += aq_dequeued;
3661 : 0 : q->sw_ring_tail += dequeued_cbs;
3662 : :
3663 : : acc_update_qstat_dequeue(q_data, i);
3664 : :
3665 : 0 : return i;
3666 : : }
3667 : :
3668 : : /* Dequeue decode operations from device. */
3669 : : static uint16_t
3670 : 0 : vrb_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
3671 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3672 : : {
3673 : 0 : struct acc_queue *q = q_data->queue_private;
3674 : : uint16_t dequeue_num;
3675 : : uint32_t avail = acc_ring_avail_deq(q);
3676 : 0 : uint32_t aq_dequeued = 0;
3677 : : uint16_t i;
3678 : : uint16_t dequeued_cbs = 0;
3679 : : struct rte_bbdev_dec_op *op;
3680 : : int ret;
3681 : :
3682 : 0 : dequeue_num = RTE_MIN(avail, num);
3683 : :
3684 [ # # ]: 0 : for (i = 0; i < dequeue_num; ++i) {
3685 [ # # ]: 0 : op = acc_op_tail(q, dequeued_cbs);
3686 [ # # ]: 0 : if (op->ldpc_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3687 : 0 : ret = vrb_dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
3688 : : &aq_dequeued);
3689 : : else
3690 : 0 : ret = vrb_dequeue_ldpc_dec_one_op_cb(
3691 : 0 : q_data, q, &ops[i], dequeued_cbs,
3692 : : &aq_dequeued);
3693 : :
3694 [ # # ]: 0 : if (ret <= 0)
3695 : : break;
3696 : 0 : dequeued_cbs += ret;
3697 : : }
3698 : :
3699 : 0 : q->aq_dequeued += aq_dequeued;
3700 : 0 : q->sw_ring_tail += dequeued_cbs;
3701 : :
3702 : : acc_update_qstat_dequeue(q_data, i);
3703 : :
3704 : 0 : return i;
3705 : : }
3706 : :
3707 : : /* Fill in a frame control word for FFT processing. */
3708 : : static inline void
3709 : 0 : vrb1_fcw_fft_fill(struct rte_bbdev_fft_op *op, struct acc_fcw_fft *fcw)
3710 : : {
3711 : 0 : fcw->in_frame_size = op->fft.input_sequence_size;
3712 : 0 : fcw->leading_pad_size = op->fft.input_leading_padding;
3713 : 0 : fcw->out_frame_size = op->fft.output_sequence_size;
3714 : 0 : fcw->leading_depad_size = op->fft.output_leading_depadding;
3715 : 0 : fcw->cs_window_sel = op->fft.window_index[0] +
3716 : 0 : (op->fft.window_index[1] << 8) +
3717 : 0 : (op->fft.window_index[2] << 16) +
3718 : 0 : (op->fft.window_index[3] << 24);
3719 : 0 : fcw->cs_window_sel2 = op->fft.window_index[4] +
3720 : 0 : (op->fft.window_index[5] << 8);
3721 : 0 : fcw->cs_enable_bmap = op->fft.cs_bitmap;
3722 : 0 : fcw->num_antennas = op->fft.num_antennas_log2;
3723 : 0 : fcw->idft_size = op->fft.idft_log2;
3724 : 0 : fcw->dft_size = op->fft.dft_log2;
3725 : 0 : fcw->cs_offset = op->fft.cs_time_adjustment;
3726 : 0 : fcw->idft_shift = op->fft.idft_shift;
3727 : 0 : fcw->dft_shift = op->fft.dft_shift;
3728 : 0 : fcw->cs_multiplier = op->fft.ncs_reciprocal;
3729 [ # # ]: 0 : if (check_bit(op->fft.op_flags, RTE_BBDEV_FFT_IDFT_BYPASS)) {
3730 [ # # ]: 0 : if (check_bit(op->fft.op_flags, RTE_BBDEV_FFT_WINDOWING_BYPASS))
3731 : 0 : fcw->bypass = 2;
3732 : : else
3733 : 0 : fcw->bypass = 1;
3734 [ # # ]: 0 : } else if (check_bit(op->fft.op_flags, RTE_BBDEV_FFT_DFT_BYPASS))
3735 : 0 : fcw->bypass = 3;
3736 : : else
3737 : 0 : fcw->bypass = 0;
3738 : 0 : }
3739 : :
3740 : : /* Fill in a frame control word for FFT processing. */
3741 : : static inline void
3742 : 0 : vrb2_fcw_fft_fill(struct rte_bbdev_fft_op *op, struct acc_fcw_fft_3 *fcw)
3743 : : {
3744 : : uint8_t cs;
3745 : :
3746 : 0 : fcw->in_frame_size = op->fft.input_sequence_size;
3747 : 0 : fcw->leading_pad_size = op->fft.input_leading_padding;
3748 : 0 : fcw->out_frame_size = op->fft.output_sequence_size;
3749 : 0 : fcw->leading_depad_size = op->fft.output_leading_depadding;
3750 : 0 : fcw->cs_window_sel = op->fft.window_index[0] +
3751 : 0 : (op->fft.window_index[1] << 8) +
3752 : 0 : (op->fft.window_index[2] << 16) +
3753 : 0 : (op->fft.window_index[3] << 24);
3754 : 0 : fcw->cs_window_sel2 = op->fft.window_index[4] +
3755 : 0 : (op->fft.window_index[5] << 8);
3756 : 0 : fcw->cs_enable_bmap = op->fft.cs_bitmap;
3757 : 0 : fcw->num_antennas = op->fft.num_antennas_log2;
3758 : 0 : fcw->idft_size = op->fft.idft_log2;
3759 : 0 : fcw->dft_size = op->fft.dft_log2;
3760 : 0 : fcw->cs_offset = op->fft.cs_time_adjustment;
3761 : 0 : fcw->idft_shift = op->fft.idft_shift;
3762 : 0 : fcw->dft_shift = op->fft.dft_shift;
3763 : 0 : fcw->cs_multiplier = op->fft.ncs_reciprocal;
3764 : 0 : fcw->power_shift = op->fft.power_shift;
3765 : 0 : fcw->exp_adj = op->fft.fp16_exp_adjust;
3766 [ # # ]: 0 : fcw->fp16_in = check_bit(op->fft.op_flags, RTE_BBDEV_FFT_FP16_INPUT);
3767 : 0 : fcw->fp16_out = check_bit(op->fft.op_flags, RTE_BBDEV_FFT_FP16_OUTPUT);
3768 : 0 : fcw->power_en = check_bit(op->fft.op_flags, RTE_BBDEV_FFT_POWER_MEAS);
3769 [ # # ]: 0 : if (check_bit(op->fft.op_flags,
3770 : : RTE_BBDEV_FFT_IDFT_BYPASS)) {
3771 [ # # ]: 0 : if (check_bit(op->fft.op_flags,
3772 : : RTE_BBDEV_FFT_WINDOWING_BYPASS))
3773 : 0 : fcw->bypass = 2;
3774 : : else
3775 : 0 : fcw->bypass = 1;
3776 [ # # ]: 0 : } else if (check_bit(op->fft.op_flags,
3777 : : RTE_BBDEV_FFT_DFT_BYPASS))
3778 : 0 : fcw->bypass = 3;
3779 : : else
3780 : 0 : fcw->bypass = 0;
3781 : :
3782 : 0 : fcw->enable_dewin = check_bit(op->fft.op_flags, RTE_BBDEV_FFT_DEWINDOWING);
3783 : 0 : fcw->freq_resample_mode = op->fft.freq_resample_mode;
3784 [ # # ]: 0 : fcw->depad_output_size = fcw->freq_resample_mode == 0 ?
3785 : : op->fft.output_sequence_size : op->fft.output_depadded_size;
3786 [ # # ]: 0 : for (cs = 0; cs < RTE_BBDEV_MAX_CS; cs++) {
3787 : 0 : fcw->cs_theta_0[cs] = op->fft.cs_theta_0[cs];
3788 : 0 : fcw->cs_theta_d[cs] = op->fft.cs_theta_d[cs];
3789 : 0 : fcw->cs_time_offset[cs] = op->fft.time_offset[cs];
3790 : : }
3791 : 0 : }
3792 : :
3793 : : static inline int
3794 : 0 : vrb_dma_desc_fft_fill(struct rte_bbdev_fft_op *op,
3795 : : struct acc_dma_req_desc *desc,
3796 : : struct rte_mbuf *input, struct rte_mbuf *output, struct rte_mbuf *win_input,
3797 : : struct rte_mbuf *pwr, uint32_t *in_offset, uint32_t *out_offset,
3798 : : uint32_t *win_offset, uint32_t *pwr_offset, uint16_t device_variant)
3799 : : {
3800 [ # # ]: 0 : bool pwr_en = check_bit(op->fft.op_flags, RTE_BBDEV_FFT_POWER_MEAS);
3801 : : bool win_en = check_bit(op->fft.op_flags, RTE_BBDEV_FFT_DEWINDOWING);
3802 : : int num_cs = 0, i, bd_idx = 1;
3803 : :
3804 [ # # ]: 0 : if (device_variant == VRB1_VARIANT) {
3805 : : /* Force unsupported descriptor format out. */
3806 : : pwr_en = 0;
3807 : : win_en = 0;
3808 : : }
3809 : :
3810 : : /* FCW already done */
3811 : : acc_header_init(desc);
3812 : :
3813 [ # # ]: 0 : if (win_en && win_input) {
3814 : 0 : desc->data_ptrs[bd_idx].address = rte_pktmbuf_iova_offset(win_input, *win_offset);
3815 : 0 : desc->data_ptrs[bd_idx].blen = op->fft.output_depadded_size * 2;
3816 : 0 : desc->data_ptrs[bd_idx].blkid = ACC_DMA_BLKID_DEWIN_IN;
3817 : 0 : desc->data_ptrs[bd_idx].last = 0;
3818 : 0 : desc->data_ptrs[bd_idx].dma_ext = 0;
3819 : : bd_idx++;
3820 : : }
3821 : :
3822 : 0 : desc->data_ptrs[bd_idx].address = rte_pktmbuf_iova_offset(input, *in_offset);
3823 : 0 : desc->data_ptrs[bd_idx].blen = op->fft.input_sequence_size * ACC_IQ_SIZE;
3824 : 0 : desc->data_ptrs[bd_idx].blkid = ACC_DMA_BLKID_IN;
3825 : 0 : desc->data_ptrs[bd_idx].last = 1;
3826 : 0 : desc->data_ptrs[bd_idx].dma_ext = 0;
3827 : 0 : bd_idx++;
3828 : :
3829 : 0 : desc->data_ptrs[bd_idx].address = rte_pktmbuf_iova_offset(output, *out_offset);
3830 : 0 : desc->data_ptrs[bd_idx].blen = op->fft.output_sequence_size * ACC_IQ_SIZE;
3831 : 0 : desc->data_ptrs[bd_idx].blkid = ACC_DMA_BLKID_OUT_HARD;
3832 : 0 : desc->data_ptrs[bd_idx].last = pwr_en ? 0 : 1;
3833 : 0 : desc->data_ptrs[bd_idx].dma_ext = 0;
3834 [ # # ]: 0 : desc->m2dlen = win_en ? 3 : 2;
3835 [ # # ]: 0 : desc->d2mlen = pwr_en ? 2 : 1;
3836 : 0 : desc->ib_ant_offset = op->fft.input_sequence_size;
3837 : 0 : desc->num_ant = op->fft.num_antennas_log2 - 3;
3838 : :
3839 [ # # ]: 0 : for (i = 0; i < RTE_BBDEV_MAX_CS; i++)
3840 [ # # ]: 0 : if (check_bit(op->fft.cs_bitmap, 1 << i))
3841 : 0 : num_cs++;
3842 : 0 : desc->num_cs = num_cs;
3843 : :
3844 [ # # ]: 0 : if (pwr_en && pwr) {
3845 : 0 : bd_idx++;
3846 : 0 : desc->data_ptrs[bd_idx].address = rte_pktmbuf_iova_offset(pwr, *pwr_offset);
3847 : 0 : desc->data_ptrs[bd_idx].blen = num_cs * (1 << op->fft.num_antennas_log2) * 4;
3848 : 0 : desc->data_ptrs[bd_idx].blkid = ACC_DMA_BLKID_OUT_SOFT;
3849 : 0 : desc->data_ptrs[bd_idx].last = 1;
3850 : 0 : desc->data_ptrs[bd_idx].dma_ext = 0;
3851 : : }
3852 : 0 : desc->ob_cyc_offset = op->fft.output_sequence_size;
3853 : 0 : desc->ob_ant_offset = op->fft.output_sequence_size * num_cs;
3854 : 0 : desc->op_addr = op;
3855 : 0 : return 0;
3856 : : }
3857 : :
3858 : : /** Enqueue one FFT operation for device. */
3859 : : static inline int
3860 [ # # ]: 0 : vrb_enqueue_fft_one_op(struct acc_queue *q, struct rte_bbdev_fft_op *op,
3861 : : uint16_t total_enqueued_cbs)
3862 : : {
3863 : : union acc_dma_desc *desc;
3864 : : struct rte_mbuf *input, *output, *pwr, *win;
3865 : : uint32_t in_offset, out_offset, pwr_offset, win_offset;
3866 : : struct acc_fcw_fft *fcw;
3867 : :
3868 : : desc = acc_desc(q, total_enqueued_cbs);
3869 : 0 : input = op->fft.base_input.data;
3870 : 0 : output = op->fft.base_output.data;
3871 : 0 : pwr = op->fft.power_meas_output.data;
3872 : 0 : win = op->fft.dewindowing_input.data;
3873 : 0 : in_offset = op->fft.base_input.offset;
3874 : 0 : out_offset = op->fft.base_output.offset;
3875 : 0 : pwr_offset = op->fft.power_meas_output.offset;
3876 : 0 : win_offset = op->fft.dewindowing_input.offset;
3877 : :
3878 : 0 : fcw = (struct acc_fcw_fft *) (q->fcw_ring +
3879 : 0 : ((q->sw_ring_head + total_enqueued_cbs) & q->sw_ring_wrap_mask)
3880 : 0 : * ACC_MAX_FCW_SIZE);
3881 : :
3882 [ # # ]: 0 : if (q->d->device_variant == VRB1_VARIANT)
3883 : 0 : vrb1_fcw_fft_fill(op, fcw);
3884 : : else
3885 : 0 : vrb2_fcw_fft_fill(op, (struct acc_fcw_fft_3 *) fcw);
3886 : 0 : vrb_dma_desc_fft_fill(op, &desc->req, input, output, win, pwr,
3887 : : &in_offset, &out_offset, &win_offset, &pwr_offset, q->d->device_variant);
3888 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3889 : : rte_memdump(stderr, "FCW", fcw, 128);
3890 : : rte_memdump(stderr, "Req Desc.", desc, 128);
3891 : : #endif
3892 : 0 : return 1;
3893 : : }
3894 : :
3895 : : /* Enqueue decode operations for device. */
3896 : : static uint16_t
3897 : 0 : vrb_enqueue_fft(struct rte_bbdev_queue_data *q_data,
3898 : : struct rte_bbdev_fft_op **ops, uint16_t num)
3899 : : {
3900 : : struct acc_queue *q;
3901 : : int32_t aq_avail, avail;
3902 : : uint16_t i;
3903 : : int ret;
3904 : :
3905 : 0 : aq_avail = acc_aq_avail(q_data, num);
3906 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3907 : : return 0;
3908 : 0 : q = q_data->queue_private;
3909 : 0 : avail = acc_ring_avail_enq(q);
3910 : :
3911 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3912 : : /* Check if there are available space for further processing. */
3913 [ # # ]: 0 : if (unlikely(avail < 1))
3914 : : break;
3915 : 0 : avail -= 1;
3916 : 0 : ret = vrb_enqueue_fft_one_op(q, ops[i], i);
3917 [ # # ]: 0 : if (ret < 0)
3918 : : break;
3919 : : }
3920 : :
3921 [ # # ]: 0 : if (unlikely(i == 0))
3922 : : return 0; /* Nothing to enqueue. */
3923 : :
3924 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
3925 : :
3926 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3927 : 0 : return i;
3928 : : }
3929 : :
3930 : :
3931 : : /* Dequeue one FFT operations from device. */
3932 : : static inline int
3933 [ # # ]: 0 : vrb_dequeue_fft_one_op(struct rte_bbdev_queue_data *q_data,
3934 : : struct acc_queue *q, struct rte_bbdev_fft_op **ref_op,
3935 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3936 : : {
3937 : : union acc_dma_desc *desc, atom_desc;
3938 : : union acc_dma_rsp_desc rsp;
3939 : : struct rte_bbdev_fft_op *op;
3940 : :
3941 : : desc = acc_desc_tail(q, dequeued_cbs);
3942 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3943 : : rte_memory_order_relaxed);
3944 : :
3945 : : /* Check fdone bit */
3946 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3947 : : return -1;
3948 : :
3949 : : rsp.val = atom_desc.rsp.val;
3950 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3951 : : rte_memdump(stderr, "Resp", &desc->rsp.val,
3952 : : sizeof(desc->rsp.val));
3953 : : #endif
3954 : : /* Dequeue. */
3955 [ # # ]: 0 : op = desc->req.op_addr;
3956 : :
3957 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, true, true);
3958 : :
3959 [ # # ]: 0 : if (op->status != 0)
3960 : 0 : q_data->queue_stats.dequeue_err_count++;
3961 : :
3962 [ # # ]: 0 : if (op->status & (1 << RTE_BBDEV_DRV_ERROR))
3963 : 0 : vrb_check_ir(q->d);
3964 : :
3965 : 0 : *ref_op = op;
3966 : : /* One CB (op) was successfully dequeued. */
3967 : 0 : return 1;
3968 : : }
3969 : :
3970 : :
3971 : : /* Dequeue FFT operations from device. */
3972 : : static uint16_t
3973 : 0 : vrb_dequeue_fft(struct rte_bbdev_queue_data *q_data,
3974 : : struct rte_bbdev_fft_op **ops, uint16_t num)
3975 : : {
3976 : 0 : struct acc_queue *q = q_data->queue_private;
3977 : : uint16_t dequeue_num, i, dequeued_cbs = 0;
3978 : : uint32_t avail = acc_ring_avail_deq(q);
3979 : 0 : uint32_t aq_dequeued = 0;
3980 : : int ret;
3981 : :
3982 : 0 : dequeue_num = RTE_MIN(avail, num);
3983 : :
3984 [ # # ]: 0 : for (i = 0; i < dequeue_num; ++i) {
3985 : 0 : ret = vrb_dequeue_fft_one_op(q_data, q, &ops[i], dequeued_cbs, &aq_dequeued);
3986 [ # # ]: 0 : if (ret <= 0)
3987 : : break;
3988 : 0 : dequeued_cbs += ret;
3989 : : }
3990 : :
3991 : 0 : q->aq_dequeued += aq_dequeued;
3992 : 0 : q->sw_ring_tail += dequeued_cbs;
3993 : : acc_update_qstat_dequeue(q_data, i);
3994 : 0 : return i;
3995 : : }
3996 : :
3997 : : /* Fill in a frame control word for MLD-TS processing. */
3998 : : static inline void
3999 : 0 : vrb2_fcw_mldts_fill(struct rte_bbdev_mldts_op *op, struct acc_fcw_mldts *fcw)
4000 : : {
4001 : 0 : fcw->nrb = op->mldts.num_rbs;
4002 : 0 : fcw->NLayers = op->mldts.num_layers - 1;
4003 : 0 : fcw->Qmod0 = (op->mldts.q_m[0] >> 1) - 1;
4004 : 0 : fcw->Qmod1 = (op->mldts.q_m[1] >> 1) - 1;
4005 : 0 : fcw->Qmod2 = (op->mldts.q_m[2] >> 1) - 1;
4006 : 0 : fcw->Qmod3 = (op->mldts.q_m[3] >> 1) - 1;
4007 : : /* Mark some layers as disabled */
4008 [ # # ]: 0 : if (op->mldts.num_layers == 2) {
4009 : 0 : fcw->Qmod2 = 3;
4010 : 0 : fcw->Qmod3 = 3;
4011 : : }
4012 [ # # ]: 0 : if (op->mldts.num_layers == 3)
4013 : 0 : fcw->Qmod3 = 3;
4014 : 0 : fcw->Rrep = op->mldts.r_rep;
4015 : 0 : fcw->Crep = op->mldts.c_rep;
4016 : 0 : }
4017 : :
4018 : : /* Fill in descriptor for one MLD-TS processing operation. */
4019 : : static inline int
4020 : 0 : vrb2_dma_desc_mldts_fill(struct rte_bbdev_mldts_op *op,
4021 : : struct acc_dma_req_desc *desc,
4022 : : struct rte_mbuf *input_q, struct rte_mbuf *input_r,
4023 : : struct rte_mbuf *output,
4024 : : uint32_t *in_offset, uint32_t *out_offset)
4025 : : {
4026 : 0 : uint16_t qsize_per_re[VRB2_MLD_LAY_SIZE] = {8, 12, 16}; /* Layer 2 to 4. */
4027 : 0 : uint16_t rsize_per_re[VRB2_MLD_LAY_SIZE] = {14, 26, 42};
4028 : 0 : uint16_t sc_factor_per_rrep[VRB2_MLD_RREP_SIZE] = {12, 6, 4, 3, 0, 2};
4029 : : uint16_t i, outsize_per_re = 0;
4030 : : uint32_t sc_num, r_num, q_size, r_size, out_size;
4031 : :
4032 : : /* Prevent out of range access. */
4033 [ # # ]: 0 : if (op->mldts.r_rep > 5)
4034 : 0 : op->mldts.r_rep = 5;
4035 [ # # ]: 0 : if (op->mldts.num_layers < 2)
4036 : 0 : op->mldts.num_layers = 2;
4037 [ # # ]: 0 : if (op->mldts.num_layers > 4)
4038 : 0 : op->mldts.num_layers = 4;
4039 [ # # ]: 0 : for (i = 0; i < op->mldts.num_layers; i++)
4040 : 0 : outsize_per_re += op->mldts.q_m[i];
4041 : 0 : sc_num = op->mldts.num_rbs * RTE_BBDEV_SCPERRB * (op->mldts.c_rep + 1);
4042 : 0 : r_num = op->mldts.num_rbs * sc_factor_per_rrep[op->mldts.r_rep];
4043 : 0 : q_size = qsize_per_re[op->mldts.num_layers - 2] * sc_num;
4044 : 0 : r_size = rsize_per_re[op->mldts.num_layers - 2] * r_num;
4045 : 0 : out_size = sc_num * outsize_per_re;
4046 : :
4047 : : /* FCW already done. */
4048 : : acc_header_init(desc);
4049 : 0 : desc->data_ptrs[1].address = rte_pktmbuf_iova_offset(input_q, *in_offset);
4050 : 0 : desc->data_ptrs[1].blen = q_size;
4051 : 0 : desc->data_ptrs[1].blkid = ACC_DMA_BLKID_IN;
4052 : 0 : desc->data_ptrs[1].last = 0;
4053 : 0 : desc->data_ptrs[1].dma_ext = 0;
4054 : 0 : desc->data_ptrs[2].address = rte_pktmbuf_iova_offset(input_r, *in_offset);
4055 : 0 : desc->data_ptrs[2].blen = r_size;
4056 : 0 : desc->data_ptrs[2].blkid = ACC_DMA_BLKID_IN_MLD_R;
4057 : 0 : desc->data_ptrs[2].last = 1;
4058 : 0 : desc->data_ptrs[2].dma_ext = 0;
4059 : 0 : desc->data_ptrs[3].address = rte_pktmbuf_iova_offset(output, *out_offset);
4060 : 0 : desc->data_ptrs[3].blen = out_size;
4061 : 0 : desc->data_ptrs[3].blkid = ACC_DMA_BLKID_OUT_HARD;
4062 : 0 : desc->data_ptrs[3].last = 1;
4063 : 0 : desc->data_ptrs[3].dma_ext = 0;
4064 : 0 : desc->m2dlen = 3;
4065 : 0 : desc->d2mlen = 1;
4066 : 0 : desc->op_addr = op;
4067 : 0 : desc->cbs_in_tb = 1;
4068 : :
4069 : 0 : return 0;
4070 : : }
4071 : :
4072 : : /* Check whether the MLD operation can be processed as a single operation. */
4073 : : static inline bool
4074 : 0 : vrb2_check_mld_r_constraint(struct rte_bbdev_mldts_op *op) {
4075 : : uint8_t layer_idx, rrep_idx;
4076 : 0 : uint16_t max_rb[VRB2_MLD_LAY_SIZE][VRB2_MLD_RREP_SIZE] = {
4077 : : {188, 275, 275, 275, 0, 275},
4078 : : {101, 202, 275, 275, 0, 275},
4079 : : {62, 124, 186, 248, 0, 275} };
4080 : :
4081 [ # # ]: 0 : if (op->mldts.c_rep == 0)
4082 : : return true;
4083 : :
4084 : 0 : layer_idx = RTE_MIN(op->mldts.num_layers - VRB2_MLD_MIN_LAYER,
4085 : : VRB2_MLD_MAX_LAYER - VRB2_MLD_MIN_LAYER);
4086 : 0 : rrep_idx = RTE_MIN(op->mldts.r_rep, VRB2_MLD_MAX_RREP);
4087 : : rte_bbdev_log_debug("RB %d index %d %d max %d", op->mldts.num_rbs, layer_idx, rrep_idx,
4088 : : max_rb[layer_idx][rrep_idx]);
4089 : :
4090 : 0 : return (op->mldts.num_rbs <= max_rb[layer_idx][rrep_idx]);
4091 : : }
4092 : :
4093 : : /** Enqueue MLDTS operation split across symbols. */
4094 : : static inline int
4095 : 0 : enqueue_mldts_split_op(struct acc_queue *q, struct rte_bbdev_mldts_op *op,
4096 : : uint16_t total_enqueued_descs)
4097 : : {
4098 : 0 : uint16_t qsize_per_re[VRB2_MLD_LAY_SIZE] = {8, 12, 16}; /* Layer 2 to 4. */
4099 : 0 : uint16_t rsize_per_re[VRB2_MLD_LAY_SIZE] = {14, 26, 42};
4100 : 0 : uint16_t sc_factor_per_rrep[VRB2_MLD_RREP_SIZE] = {12, 6, 4, 3, 0, 2};
4101 : : uint32_t i, outsize_per_re = 0, sc_num, r_num, q_size, r_size, out_size, num_syms;
4102 : : union acc_dma_desc *desc, *first_desc;
4103 : : uint16_t desc_idx, symb;
4104 : : struct rte_mbuf *input_q, *input_r, *output;
4105 : : uint32_t in_offset, out_offset;
4106 : : struct acc_fcw_mldts *fcw;
4107 : :
4108 : : desc_idx = acc_desc_idx(q, total_enqueued_descs);
4109 : 0 : first_desc = q->ring_addr + desc_idx;
4110 : 0 : input_q = op->mldts.qhy_input.data;
4111 : 0 : input_r = op->mldts.r_input.data;
4112 : 0 : output = op->mldts.output.data;
4113 : 0 : in_offset = op->mldts.qhy_input.offset;
4114 : 0 : out_offset = op->mldts.output.offset;
4115 : 0 : num_syms = op->mldts.c_rep + 1;
4116 : 0 : fcw = &first_desc->req.fcw_mldts;
4117 : 0 : vrb2_fcw_mldts_fill(op, fcw);
4118 : 0 : fcw->Crep = 0; /* C rep forced to zero. */
4119 : :
4120 : : /* Prevent out of range access. */
4121 [ # # ]: 0 : if (op->mldts.r_rep > 5)
4122 : 0 : op->mldts.r_rep = 5;
4123 [ # # ]: 0 : if (op->mldts.num_layers < 2)
4124 : 0 : op->mldts.num_layers = 2;
4125 [ # # ]: 0 : if (op->mldts.num_layers > 4)
4126 : 0 : op->mldts.num_layers = 4;
4127 : :
4128 [ # # ]: 0 : for (i = 0; i < op->mldts.num_layers; i++)
4129 : 0 : outsize_per_re += op->mldts.q_m[i];
4130 : 0 : sc_num = op->mldts.num_rbs * RTE_BBDEV_SCPERRB; /* C rep forced to zero. */
4131 : 0 : r_num = op->mldts.num_rbs * sc_factor_per_rrep[op->mldts.r_rep];
4132 : 0 : q_size = qsize_per_re[op->mldts.num_layers - 2] * sc_num;
4133 : 0 : r_size = rsize_per_re[op->mldts.num_layers - 2] * r_num;
4134 : 0 : out_size = sc_num * outsize_per_re;
4135 : :
4136 [ # # ]: 0 : for (symb = 0; symb < num_syms; symb++) {
4137 : 0 : desc_idx = ((q->sw_ring_head + total_enqueued_descs + symb) & q->sw_ring_wrap_mask);
4138 [ # # ]: 0 : desc = q->ring_addr + desc_idx;
4139 : : acc_header_init(&desc->req);
4140 [ # # ]: 0 : if (symb == 0)
4141 : 0 : desc->req.cbs_in_tb = num_syms;
4142 : : else
4143 [ # # ]: 0 : rte_memcpy(&desc->req.fcw_mldts, fcw, ACC_FCW_MLDTS_BLEN);
4144 : 0 : desc->req.data_ptrs[1].address = rte_pktmbuf_iova_offset(input_q, in_offset);
4145 : 0 : desc->req.data_ptrs[1].blen = q_size;
4146 : 0 : in_offset += q_size;
4147 : 0 : desc->req.data_ptrs[1].blkid = ACC_DMA_BLKID_IN;
4148 : 0 : desc->req.data_ptrs[1].last = 0;
4149 : 0 : desc->req.data_ptrs[1].dma_ext = 0;
4150 : 0 : desc->req.data_ptrs[2].address = rte_pktmbuf_iova_offset(input_r, 0);
4151 : 0 : desc->req.data_ptrs[2].blen = r_size;
4152 : 0 : desc->req.data_ptrs[2].blkid = ACC_DMA_BLKID_IN_MLD_R;
4153 : 0 : desc->req.data_ptrs[2].last = 1;
4154 : 0 : desc->req.data_ptrs[2].dma_ext = 0;
4155 : 0 : desc->req.data_ptrs[3].address = rte_pktmbuf_iova_offset(output, out_offset);
4156 : 0 : desc->req.data_ptrs[3].blen = out_size;
4157 : 0 : out_offset += out_size;
4158 : 0 : desc->req.data_ptrs[3].blkid = ACC_DMA_BLKID_OUT_HARD;
4159 : 0 : desc->req.data_ptrs[3].last = 1;
4160 : 0 : desc->req.data_ptrs[3].dma_ext = 0;
4161 : 0 : desc->req.m2dlen = VRB2_MLD_M2DLEN;
4162 : 0 : desc->req.d2mlen = 1;
4163 : 0 : desc->req.op_addr = op;
4164 : :
4165 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
4166 : : rte_memdump(stderr, "FCW", &desc->req.fcw_mldts, sizeof(desc->req.fcw_mldts));
4167 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
4168 : : #endif
4169 : : }
4170 : 0 : desc->req.sdone_enable = 0;
4171 : :
4172 : 0 : return num_syms;
4173 : : }
4174 : :
4175 : : /** Enqueue one MLDTS operation. */
4176 : : static inline int
4177 : 0 : enqueue_mldts_one_op(struct acc_queue *q, struct rte_bbdev_mldts_op *op,
4178 : : uint16_t total_enqueued_descs)
4179 : : {
4180 : : union acc_dma_desc *desc;
4181 : : struct rte_mbuf *input_q, *input_r, *output;
4182 : : uint32_t in_offset, out_offset;
4183 : : struct acc_fcw_mldts *fcw;
4184 : :
4185 : : desc = acc_desc(q, total_enqueued_descs);
4186 : 0 : input_q = op->mldts.qhy_input.data;
4187 : 0 : input_r = op->mldts.r_input.data;
4188 : 0 : output = op->mldts.output.data;
4189 : 0 : in_offset = op->mldts.qhy_input.offset;
4190 : 0 : out_offset = op->mldts.output.offset;
4191 : 0 : fcw = &desc->req.fcw_mldts;
4192 : 0 : vrb2_fcw_mldts_fill(op, fcw);
4193 : 0 : vrb2_dma_desc_mldts_fill(op, &desc->req, input_q, input_r, output,
4194 : : &in_offset, &out_offset);
4195 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
4196 : : rte_memdump(stderr, "FCW", &desc->req.fcw_mldts, sizeof(desc->req.fcw_mldts));
4197 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
4198 : : #endif
4199 : 0 : return 1;
4200 : : }
4201 : :
4202 : : /* Enqueue MLDTS operations. */
4203 : : static uint16_t
4204 : 0 : vrb2_enqueue_mldts(struct rte_bbdev_queue_data *q_data,
4205 : : struct rte_bbdev_mldts_op **ops, uint16_t num)
4206 : : {
4207 : : int32_t aq_avail, avail;
4208 : 0 : struct acc_queue *q = q_data->queue_private;
4209 : : uint16_t i, enqueued_descs = 0, descs_in_op;
4210 : : int ret;
4211 : : bool as_one_op;
4212 : :
4213 : 0 : aq_avail = acc_aq_avail(q_data, num);
4214 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
4215 : : return 0;
4216 : 0 : avail = acc_ring_avail_enq(q);
4217 : :
4218 [ # # ]: 0 : for (i = 0; i < num; ++i) {
4219 : 0 : as_one_op = vrb2_check_mld_r_constraint(ops[i]);
4220 [ # # ]: 0 : descs_in_op = as_one_op ? 1 : ops[i]->mldts.c_rep + 1;
4221 : :
4222 : : /* Check if there are available space for further processing. */
4223 [ # # ]: 0 : if (unlikely(avail < descs_in_op)) {
4224 : : acc_enqueue_ring_full(q_data);
4225 : : break;
4226 : : }
4227 : 0 : avail -= descs_in_op;
4228 : :
4229 [ # # ]: 0 : if (as_one_op)
4230 : 0 : ret = enqueue_mldts_one_op(q, ops[i], enqueued_descs);
4231 : : else
4232 : 0 : ret = enqueue_mldts_split_op(q, ops[i], enqueued_descs);
4233 : :
4234 [ # # ]: 0 : if (ret < 0) {
4235 : : acc_enqueue_invalid(q_data);
4236 : : break;
4237 : : }
4238 : :
4239 : 0 : enqueued_descs += ret;
4240 : : }
4241 : :
4242 [ # # ]: 0 : if (unlikely(i == 0))
4243 : : return 0; /* Nothing to enqueue. */
4244 : :
4245 : 0 : acc_dma_enqueue(q, enqueued_descs, &q_data->queue_stats);
4246 : :
4247 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
4248 : 0 : return i;
4249 : : }
4250 : :
4251 : : /*
4252 : : * Dequeue one MLDTS operation.
4253 : : * This may have been split over multiple descriptors.
4254 : : */
4255 : : static inline int
4256 [ # # ]: 0 : dequeue_mldts_one_op(struct rte_bbdev_queue_data *q_data,
4257 : : struct acc_queue *q, struct rte_bbdev_mldts_op **ref_op,
4258 : : uint16_t dequeued_ops, uint32_t *aq_dequeued)
4259 : : {
4260 : : union acc_dma_desc *desc, atom_desc, *last_desc;
4261 : : union acc_dma_rsp_desc rsp;
4262 : : struct rte_bbdev_mldts_op *op;
4263 : : uint8_t descs_in_op, i;
4264 : :
4265 : : desc = acc_desc_tail(q, dequeued_ops);
4266 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
4267 : : rte_memory_order_relaxed);
4268 : :
4269 : : /* Check fdone bit. */
4270 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
4271 : : return -1;
4272 : :
4273 : 0 : descs_in_op = desc->req.cbs_in_tb;
4274 [ # # ]: 0 : if (descs_in_op > 1) {
4275 : : /* Get last CB. */
4276 [ # # ]: 0 : last_desc = acc_desc_tail(q, dequeued_ops + descs_in_op - 1);
4277 : : /* Check if last op is ready to dequeue by checking fdone bit. If not exit. */
4278 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)last_desc,
4279 : : rte_memory_order_relaxed);
4280 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
4281 : : return -1;
4282 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
4283 : : rte_memdump(stderr, "Last Resp", &last_desc->rsp.val, sizeof(desc->rsp.val));
4284 : : #endif
4285 : : /* Check each operation iteratively using fdone. */
4286 [ # # ]: 0 : for (i = 1; i < descs_in_op - 1; i++) {
4287 : 0 : last_desc = q->ring_addr + ((q->sw_ring_tail + dequeued_ops + i)
4288 : 0 : & q->sw_ring_wrap_mask);
4289 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit(
4290 : : (uint64_t __rte_atomic *)last_desc,
4291 : : rte_memory_order_relaxed);
4292 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
4293 : : return -1;
4294 : : }
4295 : : }
4296 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
4297 : : rte_memdump(stderr, "Resp", &desc->rsp.val, sizeof(desc->rsp.val));
4298 : : #endif
4299 : : /* Dequeue. */
4300 : 0 : op = desc->req.op_addr;
4301 : :
4302 : : /* Clearing status, it will be set based on response. */
4303 : 0 : op->status = 0;
4304 : :
4305 [ # # ]: 0 : for (i = 0; i < descs_in_op; i++) {
4306 : 0 : desc = q->ring_addr + ((q->sw_ring_tail + dequeued_ops + i) & q->sw_ring_wrap_mask);
4307 [ # # ]: 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
4308 : : rte_memory_order_relaxed);
4309 : : rsp.val = atom_desc.rsp.val;
4310 : :
4311 : : vrb_update_dequeued_operation(desc, rsp, &op->status, aq_dequeued, true, false);
4312 : : }
4313 : :
4314 [ # # ]: 0 : if (op->status != 0)
4315 : 0 : q_data->queue_stats.dequeue_err_count++;
4316 [ # # ]: 0 : if (op->status & (1 << RTE_BBDEV_DRV_ERROR))
4317 : 0 : vrb_check_ir(q->d);
4318 : :
4319 : 0 : *ref_op = op;
4320 : :
4321 : 0 : return descs_in_op;
4322 : : }
4323 : :
4324 : : /* Dequeue MLDTS operations from VRB2 device. */
4325 : : static uint16_t
4326 : 0 : vrb2_dequeue_mldts(struct rte_bbdev_queue_data *q_data,
4327 : : struct rte_bbdev_mldts_op **ops, uint16_t num)
4328 : : {
4329 : 0 : struct acc_queue *q = q_data->queue_private;
4330 : : uint16_t dequeue_num, i, dequeued_cbs = 0;
4331 : : uint32_t avail = acc_ring_avail_deq(q);
4332 : 0 : uint32_t aq_dequeued = 0;
4333 : : int ret;
4334 : :
4335 : 0 : dequeue_num = RTE_MIN(avail, num);
4336 : :
4337 [ # # ]: 0 : for (i = 0; i < dequeue_num; ++i) {
4338 : 0 : ret = dequeue_mldts_one_op(q_data, q, &ops[i], dequeued_cbs, &aq_dequeued);
4339 [ # # ]: 0 : if (ret <= 0)
4340 : : break;
4341 : 0 : dequeued_cbs += ret;
4342 : : }
4343 : :
4344 : 0 : q->aq_dequeued += aq_dequeued;
4345 : 0 : q->sw_ring_tail += dequeued_cbs;
4346 : :
4347 : : acc_update_qstat_dequeue(q_data, i);
4348 : :
4349 : 0 : return i;
4350 : : }
4351 : :
4352 : : /* Initialization Function */
4353 : : static void
4354 : 0 : vrb_bbdev_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
4355 : : {
4356 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
4357 : 0 : struct acc_device *d = dev->data->dev_private;
4358 : :
4359 : 0 : dev->dev_ops = &vrb_bbdev_ops;
4360 : 0 : dev->enqueue_enc_ops = vrb_enqueue_enc;
4361 : 0 : dev->enqueue_dec_ops = vrb_enqueue_dec;
4362 : 0 : dev->dequeue_enc_ops = vrb_dequeue_enc;
4363 : 0 : dev->dequeue_dec_ops = vrb_dequeue_dec;
4364 : 0 : dev->enqueue_ldpc_enc_ops = vrb_enqueue_ldpc_enc;
4365 : 0 : dev->enqueue_ldpc_dec_ops = vrb_enqueue_ldpc_dec;
4366 : 0 : dev->dequeue_ldpc_enc_ops = vrb_dequeue_ldpc_enc;
4367 : 0 : dev->dequeue_ldpc_dec_ops = vrb_dequeue_ldpc_dec;
4368 : 0 : dev->enqueue_fft_ops = vrb_enqueue_fft;
4369 : 0 : dev->dequeue_fft_ops = vrb_dequeue_fft;
4370 : 0 : dev->enqueue_mldts_ops = vrb2_enqueue_mldts;
4371 : 0 : dev->dequeue_mldts_ops = vrb2_dequeue_mldts;
4372 : :
4373 : 0 : d->pf_device = !strcmp(drv->driver.name, RTE_STR(VRB_PF_DRIVER_NAME));
4374 : 0 : d->mmio_base = pci_dev->mem_resource[0].addr;
4375 : :
4376 : : /* Device variant specific handling. */
4377 [ # # ]: 0 : if ((pci_dev->id.device_id == RTE_VRB1_PF_DEVICE_ID) ||
4378 : : (pci_dev->id.device_id == RTE_VRB1_VF_DEVICE_ID)) {
4379 : 0 : d->device_variant = VRB1_VARIANT;
4380 : 0 : d->queue_offset = vrb1_queue_offset;
4381 : 0 : d->num_qgroups = VRB1_NUM_QGRPS;
4382 : 0 : d->num_aqs = VRB1_NUM_AQS;
4383 [ # # ]: 0 : if (d->pf_device)
4384 : 0 : d->reg_addr = &vrb1_pf_reg_addr;
4385 : : else
4386 : 0 : d->reg_addr = &vrb1_vf_reg_addr;
4387 [ # # ]: 0 : } else if ((pci_dev->id.device_id == RTE_VRB2_PF_DEVICE_ID) ||
4388 : : (pci_dev->id.device_id == RTE_VRB2_VF_DEVICE_ID)) {
4389 : 0 : d->device_variant = VRB2_VARIANT;
4390 : 0 : d->queue_offset = vrb2_queue_offset;
4391 : 0 : d->num_qgroups = VRB2_NUM_QGRPS;
4392 : 0 : d->num_aqs = VRB2_NUM_AQS;
4393 [ # # ]: 0 : if (d->pf_device)
4394 : 0 : d->reg_addr = &vrb2_pf_reg_addr;
4395 : : else
4396 : 0 : d->reg_addr = &vrb2_vf_reg_addr;
4397 : : }
4398 : :
4399 : : rte_bbdev_log_debug("Init device %s [%s] @ vaddr %p paddr %#"PRIx64"",
4400 : : drv->driver.name, dev->data->name,
4401 : : (void *)pci_dev->mem_resource[0].addr,
4402 : : pci_dev->mem_resource[0].phys_addr);
4403 : 0 : }
4404 : :
4405 : 0 : static int vrb_pci_probe(struct rte_pci_driver *pci_drv,
4406 : : struct rte_pci_device *pci_dev)
4407 : : {
4408 : : struct rte_bbdev *bbdev = NULL;
4409 : : char dev_name[RTE_BBDEV_NAME_MAX_LEN];
4410 : :
4411 [ # # ]: 0 : if (pci_dev == NULL) {
4412 : 0 : rte_bbdev_log(ERR, "NULL PCI device");
4413 : 0 : return -EINVAL;
4414 : : }
4415 : :
4416 : 0 : rte_pci_device_name(&pci_dev->addr, dev_name, sizeof(dev_name));
4417 : :
4418 : : /* Allocate memory to be used privately by drivers. */
4419 : 0 : bbdev = rte_bbdev_allocate(pci_dev->device.name);
4420 [ # # ]: 0 : if (bbdev == NULL)
4421 : : return -ENODEV;
4422 : :
4423 : : /* allocate device private memory. */
4424 : 0 : bbdev->data->dev_private = rte_zmalloc_socket(dev_name,
4425 : : sizeof(struct acc_device), RTE_CACHE_LINE_SIZE,
4426 : : pci_dev->device.numa_node);
4427 : :
4428 [ # # ]: 0 : if (bbdev->data->dev_private == NULL) {
4429 : 0 : rte_bbdev_log(CRIT,
4430 : : "Allocate of %zu bytes for device \"%s\" failed",
4431 : : sizeof(struct acc_device), dev_name);
4432 : 0 : rte_bbdev_release(bbdev);
4433 : 0 : return -ENOMEM;
4434 : : }
4435 : :
4436 : : /* Fill HW specific part of device structure. */
4437 : 0 : bbdev->device = &pci_dev->device;
4438 : 0 : bbdev->intr_handle = pci_dev->intr_handle;
4439 : 0 : bbdev->data->socket_id = pci_dev->device.numa_node;
4440 : :
4441 : : /* Invoke device initialization function. */
4442 : 0 : vrb_bbdev_init(bbdev, pci_drv);
4443 : :
4444 : : rte_bbdev_log_debug("Initialised bbdev %s (id = %u)",
4445 : : dev_name, bbdev->data->dev_id);
4446 : 0 : return 0;
4447 : : }
4448 : :
4449 : : static struct rte_pci_driver vrb_pci_pf_driver = {
4450 : : .probe = vrb_pci_probe,
4451 : : .remove = acc_pci_remove,
4452 : : .id_table = pci_id_vrb_pf_map,
4453 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING
4454 : : };
4455 : :
4456 : : static struct rte_pci_driver vrb_pci_vf_driver = {
4457 : : .probe = vrb_pci_probe,
4458 : : .remove = acc_pci_remove,
4459 : : .id_table = pci_id_vrb_vf_map,
4460 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING
4461 : : };
4462 : :
4463 : 252 : RTE_PMD_REGISTER_PCI(VRB_PF_DRIVER_NAME, vrb_pci_pf_driver);
4464 : : RTE_PMD_REGISTER_PCI_TABLE(VRB_PF_DRIVER_NAME, pci_id_vrb_pf_map);
4465 : 252 : RTE_PMD_REGISTER_PCI(VRB_VF_DRIVER_NAME, vrb_pci_vf_driver);
4466 : : RTE_PMD_REGISTER_PCI_TABLE(VRB_VF_DRIVER_NAME, pci_id_vrb_vf_map);
4467 : :
4468 : : /* Initial configuration of a VRB1 device prior to running configure(). */
4469 : : int
4470 : 0 : vrb1_configure(const char *dev_name, struct rte_acc_conf *conf)
4471 : : {
4472 : 0 : rte_bbdev_log(INFO, "vrb1_configure");
4473 : : uint32_t value, address, status;
4474 : : int qg_idx, template_idx, vf_idx, acc, i, rlim, alen, timestamp, totalQgs, numEngines;
4475 : : int numQgs, numQqsAcc;
4476 : 0 : struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
4477 : :
4478 : : /* Compile time checks. */
4479 : : RTE_BUILD_BUG_ON(sizeof(struct acc_dma_req_desc) != 256);
4480 : : RTE_BUILD_BUG_ON(sizeof(union acc_dma_desc) != 256);
4481 : : RTE_BUILD_BUG_ON(sizeof(struct acc_fcw_td) != 24);
4482 : : RTE_BUILD_BUG_ON(sizeof(struct acc_fcw_te) != 32);
4483 : :
4484 [ # # ]: 0 : if (bbdev == NULL) {
4485 : 0 : rte_bbdev_log(ERR,
4486 : : "Invalid dev_name (%s), or device is not yet initialised",
4487 : : dev_name);
4488 : 0 : return -ENODEV;
4489 : : }
4490 : 0 : struct acc_device *d = bbdev->data->dev_private;
4491 : :
4492 : : /* Store configuration. */
4493 [ # # ]: 0 : rte_memcpy(&d->acc_conf, conf, sizeof(d->acc_conf));
4494 : :
4495 : : /* Check we are already out of PG. */
4496 : : status = acc_reg_read(d, VRB1_PfHiSectionPowerGatingAck);
4497 [ # # ]: 0 : if (status > 0) {
4498 [ # # ]: 0 : if (status != VRB1_PG_MASK_0) {
4499 : 0 : rte_bbdev_log(ERR, "Unexpected status %x %x",
4500 : : status, VRB1_PG_MASK_0);
4501 : 0 : return -ENODEV;
4502 : : }
4503 : : /* Clock gate sections that will be un-PG. */
4504 : : acc_reg_write(d, VRB1_PfHiClkGateHystReg, VRB1_CLK_DIS);
4505 : : /* Un-PG required sections. */
4506 : : acc_reg_write(d, VRB1_PfHiSectionPowerGatingReq,
4507 : : VRB1_PG_MASK_1);
4508 : : status = acc_reg_read(d, VRB1_PfHiSectionPowerGatingAck);
4509 [ # # ]: 0 : if (status != VRB1_PG_MASK_1) {
4510 : 0 : rte_bbdev_log(ERR, "Unexpected status %x %x",
4511 : : status, VRB1_PG_MASK_1);
4512 : 0 : return -ENODEV;
4513 : : }
4514 : : acc_reg_write(d, VRB1_PfHiSectionPowerGatingReq,
4515 : : VRB1_PG_MASK_2);
4516 : : status = acc_reg_read(d, VRB1_PfHiSectionPowerGatingAck);
4517 [ # # ]: 0 : if (status != VRB1_PG_MASK_2) {
4518 : 0 : rte_bbdev_log(ERR, "Unexpected status %x %x",
4519 : : status, VRB1_PG_MASK_2);
4520 : 0 : return -ENODEV;
4521 : : }
4522 : : acc_reg_write(d, VRB1_PfHiSectionPowerGatingReq,
4523 : : VRB1_PG_MASK_3);
4524 : : status = acc_reg_read(d, VRB1_PfHiSectionPowerGatingAck);
4525 [ # # ]: 0 : if (status != VRB1_PG_MASK_3) {
4526 : 0 : rte_bbdev_log(ERR, "Unexpected status %x %x",
4527 : : status, VRB1_PG_MASK_3);
4528 : 0 : return -ENODEV;
4529 : : }
4530 : : /* Enable clocks for all sections. */
4531 : : acc_reg_write(d, VRB1_PfHiClkGateHystReg, VRB1_CLK_EN);
4532 : : }
4533 : :
4534 : : /* Explicitly releasing AXI as this may be stopped after PF FLR/BME. */
4535 : : address = VRB1_PfDmaAxiControl;
4536 : : value = 1;
4537 : : acc_reg_write(d, address, value);
4538 : :
4539 : : /* Set the fabric mode. */
4540 : : address = VRB1_PfFabricM2iBufferReg;
4541 : : value = VRB1_FABRIC_MODE;
4542 : : acc_reg_write(d, address, value);
4543 : :
4544 : : /* Set default descriptor signature. */
4545 : : address = VRB1_PfDmaDescriptorSignatuture;
4546 : : value = 0;
4547 : : acc_reg_write(d, address, value);
4548 : :
4549 : : /* Enable the Error Detection in DMA. */
4550 : : value = VRB1_CFG_DMA_ERROR;
4551 : : address = VRB1_PfDmaErrorDetectionEn;
4552 : : acc_reg_write(d, address, value);
4553 : :
4554 : : /* AXI Cache configuration. */
4555 : : value = VRB1_CFG_AXI_CACHE;
4556 : : address = VRB1_PfDmaAxcacheReg;
4557 : : acc_reg_write(d, address, value);
4558 : :
4559 : : /* AXI Response configuration. */
4560 : : acc_reg_write(d, VRB1_PfDmaCfgRrespBresp, 0x0);
4561 : :
4562 : : /* Default DMA Configuration (Qmgr Enabled). */
4563 : : address = VRB1_PfDmaConfig0Reg;
4564 : : value = 0;
4565 : : acc_reg_write(d, address, value);
4566 : : address = VRB1_PfDmaQmanen;
4567 : : value = 0;
4568 : : acc_reg_write(d, address, value);
4569 : :
4570 : : /* Default RLIM/ALEN configuration. */
4571 : : rlim = 0;
4572 : : alen = 1;
4573 : : timestamp = 0;
4574 : : address = VRB1_PfDmaConfig1Reg;
4575 : : value = (1 << 31) + (rlim << 8) + (timestamp << 6) + alen;
4576 : : acc_reg_write(d, address, value);
4577 : :
4578 : : /* Default FFT configuration. */
4579 : : address = VRB1_PfFftConfig0;
4580 : : value = VRB1_FFT_CFG_0;
4581 : : acc_reg_write(d, address, value);
4582 : :
4583 : : /* Configure DMA Qmanager addresses. */
4584 : : address = VRB1_PfDmaQmgrAddrReg;
4585 : : value = VRB1_PfQmgrEgressQueuesTemplate;
4586 : : acc_reg_write(d, address, value);
4587 : :
4588 : : /* ===== Qmgr Configuration ===== */
4589 : : /* Configuration of the AQueue Depth QMGR_GRP_0_DEPTH_LOG2 for UL. */
4590 : 0 : totalQgs = conf->q_ul_4g.num_qgroups +
4591 : 0 : conf->q_ul_5g.num_qgroups +
4592 : 0 : conf->q_dl_4g.num_qgroups +
4593 : 0 : conf->q_dl_5g.num_qgroups +
4594 : 0 : conf->q_fft.num_qgroups;
4595 [ # # ]: 0 : for (qg_idx = 0; qg_idx < VRB1_NUM_QGRPS; qg_idx++) {
4596 : 0 : address = VRB1_PfQmgrDepthLog2Grp + ACC_BYTES_IN_WORD * qg_idx;
4597 : 0 : value = aqDepth(qg_idx, conf);
4598 : : acc_reg_write(d, address, value);
4599 : 0 : address = VRB1_PfQmgrTholdGrp + ACC_BYTES_IN_WORD * qg_idx;
4600 : 0 : value = (1 << 16) + (1 << (aqDepth(qg_idx, conf) - 1));
4601 : : acc_reg_write(d, address, value);
4602 : : }
4603 : :
4604 : : /* Template Priority in incremental order. */
4605 [ # # ]: 0 : for (template_idx = 0; template_idx < ACC_NUM_TMPL;
4606 : 0 : template_idx++) {
4607 : 0 : address = VRB1_PfQmgrGrpTmplateReg0Indx + ACC_BYTES_IN_WORD * template_idx;
4608 : : value = ACC_TMPL_PRI_0;
4609 : : acc_reg_write(d, address, value);
4610 : 0 : address = VRB1_PfQmgrGrpTmplateReg1Indx + ACC_BYTES_IN_WORD * template_idx;
4611 : : value = ACC_TMPL_PRI_1;
4612 : : acc_reg_write(d, address, value);
4613 : 0 : address = VRB1_PfQmgrGrpTmplateReg2indx + ACC_BYTES_IN_WORD * template_idx;
4614 : : value = ACC_TMPL_PRI_2;
4615 : : acc_reg_write(d, address, value);
4616 : 0 : address = VRB1_PfQmgrGrpTmplateReg3Indx + ACC_BYTES_IN_WORD * template_idx;
4617 : : value = ACC_TMPL_PRI_3;
4618 : : acc_reg_write(d, address, value);
4619 : : }
4620 : :
4621 : : address = VRB1_PfQmgrGrpPriority;
4622 : : value = VRB1_CFG_QMGR_HI_P;
4623 : : acc_reg_write(d, address, value);
4624 : :
4625 : : /* Template Configuration. */
4626 [ # # ]: 0 : for (template_idx = 0; template_idx < ACC_NUM_TMPL;
4627 : 0 : template_idx++) {
4628 : : value = 0;
4629 : : address = VRB1_PfQmgrGrpTmplateReg4Indx
4630 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4631 : : acc_reg_write(d, address, value);
4632 : : }
4633 : : /* 4GUL */
4634 : 0 : numQgs = conf->q_ul_4g.num_qgroups;
4635 : : numQqsAcc = 0;
4636 : : value = 0;
4637 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4638 : 0 : value |= (1 << qg_idx);
4639 : : for (template_idx = VRB1_SIG_UL_4G;
4640 [ # # ]: 0 : template_idx <= VRB1_SIG_UL_4G_LAST;
4641 : 0 : template_idx++) {
4642 : : address = VRB1_PfQmgrGrpTmplateReg4Indx
4643 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4644 : : acc_reg_write(d, address, value);
4645 : : }
4646 : : /* 5GUL */
4647 : : numQqsAcc += numQgs;
4648 : 0 : numQgs = conf->q_ul_5g.num_qgroups;
4649 : : value = 0;
4650 : : numEngines = 0;
4651 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4652 : 0 : value |= (1 << qg_idx);
4653 : : for (template_idx = VRB1_SIG_UL_5G;
4654 [ # # ]: 0 : template_idx <= VRB1_SIG_UL_5G_LAST;
4655 : 0 : template_idx++) {
4656 : : /* Check engine power-on status */
4657 [ # # ]: 0 : address = VRB1_PfFecUl5gIbDebugReg + ACC_ENGINE_OFFSET * template_idx;
4658 : 0 : status = (acc_reg_read(d, address) >> 4) & 0x7;
4659 : : address = VRB1_PfQmgrGrpTmplateReg4Indx
4660 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4661 [ # # ]: 0 : if (status == 1) {
4662 : : acc_reg_write(d, address, value);
4663 : 0 : numEngines++;
4664 : : } else
4665 : : acc_reg_write(d, address, 0);
4666 : : }
4667 : 0 : rte_bbdev_log(INFO, "Number of 5GUL engines %d", numEngines);
4668 : : /* 4GDL */
4669 : : numQqsAcc += numQgs;
4670 : 0 : numQgs = conf->q_dl_4g.num_qgroups;
4671 : : value = 0;
4672 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4673 : 0 : value |= (1 << qg_idx);
4674 : : for (template_idx = VRB1_SIG_DL_4G;
4675 [ # # ]: 0 : template_idx <= VRB1_SIG_DL_4G_LAST;
4676 : 0 : template_idx++) {
4677 : : address = VRB1_PfQmgrGrpTmplateReg4Indx
4678 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4679 : : acc_reg_write(d, address, value);
4680 : : }
4681 : : /* 5GDL */
4682 : : numQqsAcc += numQgs;
4683 : 0 : numQgs = conf->q_dl_5g.num_qgroups;
4684 : : value = 0;
4685 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4686 : 0 : value |= (1 << qg_idx);
4687 : : for (template_idx = VRB1_SIG_DL_5G;
4688 [ # # ]: 0 : template_idx <= VRB1_SIG_DL_5G_LAST;
4689 : 0 : template_idx++) {
4690 : : address = VRB1_PfQmgrGrpTmplateReg4Indx
4691 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4692 : : acc_reg_write(d, address, value);
4693 : : }
4694 : : /* FFT */
4695 : : numQqsAcc += numQgs;
4696 : 0 : numQgs = conf->q_fft.num_qgroups;
4697 : : value = 0;
4698 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4699 : 0 : value |= (1 << qg_idx);
4700 : : for (template_idx = VRB1_SIG_FFT;
4701 [ # # ]: 0 : template_idx <= VRB1_SIG_FFT_LAST;
4702 : : template_idx++) {
4703 : : address = VRB1_PfQmgrGrpTmplateReg4Indx
4704 : : + ACC_BYTES_IN_WORD * template_idx;
4705 : : acc_reg_write(d, address, value);
4706 : : }
4707 : :
4708 : : /* Queue Group Function mapping. */
4709 : 0 : int qman_func_id[8] = {0, 2, 1, 3, 4, 0, 0, 0};
4710 : : value = 0;
4711 [ # # ]: 0 : for (qg_idx = 0; qg_idx < ACC_NUM_QGRPS_PER_WORD; qg_idx++) {
4712 : 0 : acc = accFromQgid(qg_idx, conf);
4713 : 0 : value |= qman_func_id[acc] << (qg_idx * 4);
4714 : : }
4715 : : acc_reg_write(d, VRB1_PfQmgrGrpFunction0, value);
4716 : : value = 0;
4717 [ # # ]: 0 : for (qg_idx = 0; qg_idx < ACC_NUM_QGRPS_PER_WORD; qg_idx++) {
4718 : 0 : acc = accFromQgid(qg_idx + ACC_NUM_QGRPS_PER_WORD, conf);
4719 : 0 : value |= qman_func_id[acc] << (qg_idx * 4);
4720 : : }
4721 : : acc_reg_write(d, VRB1_PfQmgrGrpFunction1, value);
4722 : :
4723 : : /* Configuration of the Arbitration QGroup depth to 1. */
4724 [ # # ]: 0 : for (qg_idx = 0; qg_idx < VRB1_NUM_QGRPS; qg_idx++) {
4725 : 0 : address = VRB1_PfQmgrArbQDepthGrp +
4726 : : ACC_BYTES_IN_WORD * qg_idx;
4727 : : value = 0;
4728 : : acc_reg_write(d, address, value);
4729 : : }
4730 : :
4731 : : /* This pointer to ARAM (256kB) is shifted by 2 (4B per register). */
4732 : : uint32_t aram_address = 0;
4733 [ # # ]: 0 : for (qg_idx = 0; qg_idx < totalQgs; qg_idx++) {
4734 [ # # ]: 0 : for (vf_idx = 0; vf_idx < conf->num_vf_bundles; vf_idx++) {
4735 : 0 : address = VRB1_PfQmgrVfBaseAddr + vf_idx
4736 : 0 : * ACC_BYTES_IN_WORD + qg_idx
4737 : : * ACC_BYTES_IN_WORD * 64;
4738 : : value = aram_address;
4739 : : acc_reg_write(d, address, value);
4740 : : /* Offset ARAM Address for next memory bank - increment of 4B. */
4741 : 0 : aram_address += aqNum(qg_idx, conf) *
4742 : 0 : (1 << aqDepth(qg_idx, conf));
4743 : : }
4744 : : }
4745 : :
4746 [ # # ]: 0 : if (aram_address > VRB1_WORDS_IN_ARAM_SIZE) {
4747 : 0 : rte_bbdev_log(ERR, "ARAM Configuration not fitting %d %d",
4748 : : aram_address, VRB1_WORDS_IN_ARAM_SIZE);
4749 : 0 : return -EINVAL;
4750 : : }
4751 : :
4752 : : /* Performance tuning. */
4753 : : acc_reg_write(d, VRB1_PfFabricI2Mdma_weight, 0x0FFF);
4754 : : acc_reg_write(d, VRB1_PfDma4gdlIbThld, 0x1f10);
4755 : :
4756 : : /* ==== HI Configuration ==== */
4757 : :
4758 : : /* No Info Ring/MSI by default. */
4759 : : address = VRB1_PfHiInfoRingIntWrEnRegPf;
4760 : : value = 0;
4761 : : acc_reg_write(d, address, value);
4762 : : address = VRB1_PfHiCfgMsiIntWrEnRegPf;
4763 : : value = 0xFFFFFFFF;
4764 : : acc_reg_write(d, address, value);
4765 : : /* Prevent Block on Transmit Error. */
4766 : : address = VRB1_PfHiBlockTransmitOnErrorEn;
4767 : : value = 0;
4768 : : acc_reg_write(d, address, value);
4769 : : /* Prevents to drop MSI. */
4770 : : address = VRB1_PfHiMsiDropEnableReg;
4771 : : value = 0;
4772 : : acc_reg_write(d, address, value);
4773 : : /* Set the PF Mode register. */
4774 : : address = VRB1_PfHiPfMode;
4775 [ # # ]: 0 : value = (conf->pf_mode_en) ? ACC_PF_VAL : 0;
4776 : : acc_reg_write(d, address, value);
4777 : :
4778 : : /* QoS overflow init. */
4779 : : value = 1;
4780 : : address = VRB1_PfQosmonAEvalOverflow0;
4781 : : acc_reg_write(d, address, value);
4782 : : address = VRB1_PfQosmonBEvalOverflow0;
4783 : : acc_reg_write(d, address, value);
4784 : :
4785 : : /* Configure the FFT RAM LUT. */
4786 : 0 : uint32_t fft_lut[VRB1_FFT_RAM_SIZE] = {
4787 : : 0x1FFFF, 0x1FFFF, 0x1FFFE, 0x1FFFA, 0x1FFF6, 0x1FFF1, 0x1FFEA, 0x1FFE2,
4788 : : 0x1FFD9, 0x1FFCE, 0x1FFC2, 0x1FFB5, 0x1FFA7, 0x1FF98, 0x1FF87, 0x1FF75,
4789 : : 0x1FF62, 0x1FF4E, 0x1FF38, 0x1FF21, 0x1FF09, 0x1FEF0, 0x1FED6, 0x1FEBA,
4790 : : 0x1FE9D, 0x1FE7F, 0x1FE5F, 0x1FE3F, 0x1FE1D, 0x1FDFA, 0x1FDD5, 0x1FDB0,
4791 : : 0x1FD89, 0x1FD61, 0x1FD38, 0x1FD0D, 0x1FCE1, 0x1FCB4, 0x1FC86, 0x1FC57,
4792 : : 0x1FC26, 0x1FBF4, 0x1FBC1, 0x1FB8D, 0x1FB58, 0x1FB21, 0x1FAE9, 0x1FAB0,
4793 : : 0x1FA75, 0x1FA3A, 0x1F9FD, 0x1F9BF, 0x1F980, 0x1F93F, 0x1F8FD, 0x1F8BA,
4794 : : 0x1F876, 0x1F831, 0x1F7EA, 0x1F7A3, 0x1F75A, 0x1F70F, 0x1F6C4, 0x1F677,
4795 : : 0x1F629, 0x1F5DA, 0x1F58A, 0x1F539, 0x1F4E6, 0x1F492, 0x1F43D, 0x1F3E7,
4796 : : 0x1F38F, 0x1F337, 0x1F2DD, 0x1F281, 0x1F225, 0x1F1C8, 0x1F169, 0x1F109,
4797 : : 0x1F0A8, 0x1F046, 0x1EFE2, 0x1EF7D, 0x1EF18, 0x1EEB0, 0x1EE48, 0x1EDDF,
4798 : : 0x1ED74, 0x1ED08, 0x1EC9B, 0x1EC2D, 0x1EBBE, 0x1EB4D, 0x1EADB, 0x1EA68,
4799 : : 0x1E9F4, 0x1E97F, 0x1E908, 0x1E891, 0x1E818, 0x1E79E, 0x1E722, 0x1E6A6,
4800 : : 0x1E629, 0x1E5AA, 0x1E52A, 0x1E4A9, 0x1E427, 0x1E3A3, 0x1E31F, 0x1E299,
4801 : : 0x1E212, 0x1E18A, 0x1E101, 0x1E076, 0x1DFEB, 0x1DF5E, 0x1DED0, 0x1DE41,
4802 : : 0x1DDB1, 0x1DD20, 0x1DC8D, 0x1DBFA, 0x1DB65, 0x1DACF, 0x1DA38, 0x1D9A0,
4803 : : 0x1D907, 0x1D86C, 0x1D7D1, 0x1D734, 0x1D696, 0x1D5F7, 0x1D557, 0x1D4B6,
4804 : : 0x1D413, 0x1D370, 0x1D2CB, 0x1D225, 0x1D17E, 0x1D0D6, 0x1D02D, 0x1CF83,
4805 : : 0x1CED8, 0x1CE2B, 0x1CD7E, 0x1CCCF, 0x1CC1F, 0x1CB6E, 0x1CABC, 0x1CA09,
4806 : : 0x1C955, 0x1C89F, 0x1C7E9, 0x1C731, 0x1C679, 0x1C5BF, 0x1C504, 0x1C448,
4807 : : 0x1C38B, 0x1C2CD, 0x1C20E, 0x1C14E, 0x1C08C, 0x1BFCA, 0x1BF06, 0x1BE42,
4808 : : 0x1BD7C, 0x1BCB5, 0x1BBED, 0x1BB25, 0x1BA5B, 0x1B990, 0x1B8C4, 0x1B7F6,
4809 : : 0x1B728, 0x1B659, 0x1B589, 0x1B4B7, 0x1B3E5, 0x1B311, 0x1B23D, 0x1B167,
4810 : : 0x1B091, 0x1AFB9, 0x1AEE0, 0x1AE07, 0x1AD2C, 0x1AC50, 0x1AB73, 0x1AA95,
4811 : : 0x1A9B6, 0x1A8D6, 0x1A7F6, 0x1A714, 0x1A631, 0x1A54D, 0x1A468, 0x1A382,
4812 : : 0x1A29A, 0x1A1B2, 0x1A0C9, 0x19FDF, 0x19EF4, 0x19E08, 0x19D1B, 0x19C2D,
4813 : : 0x19B3E, 0x19A4E, 0x1995D, 0x1986B, 0x19778, 0x19684, 0x1958F, 0x19499,
4814 : : 0x193A2, 0x192AA, 0x191B1, 0x190B8, 0x18FBD, 0x18EC1, 0x18DC4, 0x18CC7,
4815 : : 0x18BC8, 0x18AC8, 0x189C8, 0x188C6, 0x187C4, 0x186C1, 0x185BC, 0x184B7,
4816 : : 0x183B1, 0x182AA, 0x181A2, 0x18099, 0x17F8F, 0x17E84, 0x17D78, 0x17C6C,
4817 : : 0x17B5E, 0x17A4F, 0x17940, 0x17830, 0x1771E, 0x1760C, 0x174F9, 0x173E5,
4818 : : 0x172D1, 0x171BB, 0x170A4, 0x16F8D, 0x16E74, 0x16D5B, 0x16C41, 0x16B26,
4819 : : 0x16A0A, 0x168ED, 0x167CF, 0x166B1, 0x16592, 0x16471, 0x16350, 0x1622E,
4820 : : 0x1610B, 0x15FE8, 0x15EC3, 0x15D9E, 0x15C78, 0x15B51, 0x15A29, 0x15900,
4821 : : 0x157D7, 0x156AC, 0x15581, 0x15455, 0x15328, 0x151FB, 0x150CC, 0x14F9D,
4822 : : 0x14E6D, 0x14D3C, 0x14C0A, 0x14AD8, 0x149A4, 0x14870, 0x1473B, 0x14606,
4823 : : 0x144CF, 0x14398, 0x14260, 0x14127, 0x13FEE, 0x13EB3, 0x13D78, 0x13C3C,
4824 : : 0x13B00, 0x139C2, 0x13884, 0x13745, 0x13606, 0x134C5, 0x13384, 0x13242,
4825 : : 0x130FF, 0x12FBC, 0x12E78, 0x12D33, 0x12BEE, 0x12AA7, 0x12960, 0x12819,
4826 : : 0x126D0, 0x12587, 0x1243D, 0x122F3, 0x121A8, 0x1205C, 0x11F0F, 0x11DC2,
4827 : : 0x11C74, 0x11B25, 0x119D6, 0x11886, 0x11735, 0x115E3, 0x11491, 0x1133F,
4828 : : 0x111EB, 0x11097, 0x10F42, 0x10DED, 0x10C97, 0x10B40, 0x109E9, 0x10891,
4829 : : 0x10738, 0x105DF, 0x10485, 0x1032B, 0x101D0, 0x10074, 0x0FF18, 0x0FDBB,
4830 : : 0x0FC5D, 0x0FAFF, 0x0F9A0, 0x0F841, 0x0F6E1, 0x0F580, 0x0F41F, 0x0F2BD,
4831 : : 0x0F15B, 0x0EFF8, 0x0EE94, 0x0ED30, 0x0EBCC, 0x0EA67, 0x0E901, 0x0E79A,
4832 : : 0x0E633, 0x0E4CC, 0x0E364, 0x0E1FB, 0x0E092, 0x0DF29, 0x0DDBE, 0x0DC54,
4833 : : 0x0DAE9, 0x0D97D, 0x0D810, 0x0D6A4, 0x0D536, 0x0D3C8, 0x0D25A, 0x0D0EB,
4834 : : 0x0CF7C, 0x0CE0C, 0x0CC9C, 0x0CB2B, 0x0C9B9, 0x0C847, 0x0C6D5, 0x0C562,
4835 : : 0x0C3EF, 0x0C27B, 0x0C107, 0x0BF92, 0x0BE1D, 0x0BCA8, 0x0BB32, 0x0B9BB,
4836 : : 0x0B844, 0x0B6CD, 0x0B555, 0x0B3DD, 0x0B264, 0x0B0EB, 0x0AF71, 0x0ADF7,
4837 : : 0x0AC7D, 0x0AB02, 0x0A987, 0x0A80B, 0x0A68F, 0x0A513, 0x0A396, 0x0A219,
4838 : : 0x0A09B, 0x09F1D, 0x09D9E, 0x09C20, 0x09AA1, 0x09921, 0x097A1, 0x09621,
4839 : : 0x094A0, 0x0931F, 0x0919E, 0x0901C, 0x08E9A, 0x08D18, 0x08B95, 0x08A12,
4840 : : 0x0888F, 0x0870B, 0x08587, 0x08402, 0x0827E, 0x080F9, 0x07F73, 0x07DEE,
4841 : : 0x07C68, 0x07AE2, 0x0795B, 0x077D4, 0x0764D, 0x074C6, 0x0733E, 0x071B6,
4842 : : 0x0702E, 0x06EA6, 0x06D1D, 0x06B94, 0x06A0B, 0x06881, 0x066F7, 0x0656D,
4843 : : 0x063E3, 0x06258, 0x060CE, 0x05F43, 0x05DB7, 0x05C2C, 0x05AA0, 0x05914,
4844 : : 0x05788, 0x055FC, 0x0546F, 0x052E3, 0x05156, 0x04FC9, 0x04E3B, 0x04CAE,
4845 : : 0x04B20, 0x04992, 0x04804, 0x04676, 0x044E8, 0x04359, 0x041CB, 0x0403C,
4846 : : 0x03EAD, 0x03D1D, 0x03B8E, 0x039FF, 0x0386F, 0x036DF, 0x0354F, 0x033BF,
4847 : : 0x0322F, 0x0309F, 0x02F0F, 0x02D7E, 0x02BEE, 0x02A5D, 0x028CC, 0x0273B,
4848 : : 0x025AA, 0x02419, 0x02288, 0x020F7, 0x01F65, 0x01DD4, 0x01C43, 0x01AB1,
4849 : : 0x0191F, 0x0178E, 0x015FC, 0x0146A, 0x012D8, 0x01147, 0x00FB5, 0x00E23,
4850 : : 0x00C91, 0x00AFF, 0x0096D, 0x007DB, 0x00648, 0x004B6, 0x00324, 0x00192};
4851 : :
4852 : : acc_reg_write(d, VRB1_PfFftRamPageAccess, VRB1_FFT_RAM_EN + 64);
4853 [ # # ]: 0 : for (i = 0; i < VRB1_FFT_RAM_SIZE; i++)
4854 : 0 : acc_reg_write(d, VRB1_PfFftRamOff + i * 4, fft_lut[i]);
4855 : : acc_reg_write(d, VRB1_PfFftRamPageAccess, VRB1_FFT_RAM_DIS);
4856 : :
4857 : : /* Enabling AQueues through the Queue hierarchy. */
4858 [ # # ]: 0 : for (vf_idx = 0; vf_idx < VRB1_NUM_VFS; vf_idx++) {
4859 [ # # ]: 0 : for (qg_idx = 0; qg_idx < VRB1_NUM_QGRPS; qg_idx++) {
4860 : : value = 0;
4861 [ # # # # ]: 0 : if (vf_idx < conf->num_vf_bundles && qg_idx < totalQgs)
4862 : 0 : value = (1 << aqNum(qg_idx, conf)) - 1;
4863 : 0 : address = VRB1_PfQmgrAqEnableVf + vf_idx * ACC_BYTES_IN_WORD;
4864 : 0 : value += (qg_idx << 16);
4865 : : acc_reg_write(d, address, value);
4866 : : }
4867 : : }
4868 : :
4869 : : rte_bbdev_log_debug("PF Tip configuration complete for %s", dev_name);
4870 : : return 0;
4871 : : }
4872 : :
4873 : : /* Initial configuration of a VRB2 device prior to running configure(). */
4874 : : int
4875 : 0 : vrb2_configure(const char *dev_name, struct rte_acc_conf *conf)
4876 : : {
4877 : 0 : rte_bbdev_log(INFO, "vrb2_configure");
4878 : : uint32_t value, address, status;
4879 : : int qg_idx, template_idx, vf_idx, acc, i, aq_reg, static_allocation, numEngines;
4880 : : int numQgs, numQqsAcc, totalQgs;
4881 : 0 : int qman_func_id[8] = {0, 2, 1, 3, 4, 5, 0, 0};
4882 : 0 : struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
4883 : : int rlim, alen, timestamp;
4884 : :
4885 : : /* Compile time checks. */
4886 : : RTE_BUILD_BUG_ON(sizeof(struct acc_dma_req_desc) != 256);
4887 : : RTE_BUILD_BUG_ON(sizeof(union acc_dma_desc) != 256);
4888 : : RTE_BUILD_BUG_ON(sizeof(struct acc_fcw_td) != 24);
4889 : : RTE_BUILD_BUG_ON(sizeof(struct acc_fcw_te) != 32);
4890 : :
4891 [ # # ]: 0 : if (bbdev == NULL) {
4892 : 0 : rte_bbdev_log(ERR,
4893 : : "Invalid dev_name (%s), or device is not yet initialised",
4894 : : dev_name);
4895 : 0 : return -ENODEV;
4896 : : }
4897 : 0 : struct acc_device *d = bbdev->data->dev_private;
4898 : :
4899 : : /* Store configuration. */
4900 [ # # ]: 0 : rte_memcpy(&d->acc_conf, conf, sizeof(d->acc_conf));
4901 : :
4902 : : /* Explicitly releasing AXI as this may be stopped after PF FLR/BME. */
4903 : : address = VRB2_PfDmaAxiControl;
4904 : : value = 1;
4905 : : acc_reg_write(d, address, value);
4906 : :
4907 : : /* Set the fabric mode. */
4908 : : address = VRB2_PfFabricM2iBufferReg;
4909 : : value = VRB2_FABRIC_MODE;
4910 : : acc_reg_write(d, address, value);
4911 : :
4912 : : /* Set default descriptor signature. */
4913 : : address = VRB2_PfDmaDescriptorSignature;
4914 : : value = 0;
4915 : : acc_reg_write(d, address, value);
4916 : :
4917 : : /* Enable the Error Detection in DMA. */
4918 : : value = VRB2_CFG_DMA_ERROR;
4919 : : address = VRB2_PfDmaErrorDetectionEn;
4920 : : acc_reg_write(d, address, value);
4921 : :
4922 : : /* AXI Cache configuration. */
4923 : : value = VRB2_CFG_AXI_CACHE;
4924 : : address = VRB2_PfDmaAxcacheReg;
4925 : : acc_reg_write(d, address, value);
4926 : :
4927 : : /* AXI Response configuration. */
4928 : : acc_reg_write(d, VRB2_PfDmaCfgRrespBresp, 0x0);
4929 : :
4930 : : /* Default DMA Configuration (Qmgr Enabled) */
4931 : : acc_reg_write(d, VRB2_PfDmaConfig0Reg, 0);
4932 : : acc_reg_write(d, VRB2_PfDmaQmanenSelect, 0xFFFFFFFF);
4933 : : acc_reg_write(d, VRB2_PfDmaQmanen, 0);
4934 : :
4935 : : /* Default RLIM/ALEN configuration. */
4936 : : rlim = 0;
4937 : : alen = 3;
4938 : : timestamp = 0;
4939 : : address = VRB2_PfDmaConfig1Reg;
4940 : : value = (1 << 31) + (rlim << 8) + (timestamp << 6) + alen;
4941 : : acc_reg_write(d, address, value);
4942 : :
4943 : : /* Default FFT configuration. */
4944 [ # # ]: 0 : for (template_idx = 0; template_idx < VRB2_FFT_NUM; template_idx++) {
4945 : 0 : acc_reg_write(d, VRB2_PfFftConfig0 + template_idx * 0x1000, VRB2_FFT_CFG_0);
4946 : 0 : acc_reg_write(d, VRB2_PfFftParityMask8 + template_idx * 0x1000, VRB2_FFT_ECC);
4947 : : }
4948 : :
4949 : : /* Configure DMA Qmanager addresses. */
4950 : : address = VRB2_PfDmaQmgrAddrReg;
4951 : : value = VRB2_PfQmgrEgressQueuesTemplate;
4952 : : acc_reg_write(d, address, value);
4953 : :
4954 : : /* ===== Qmgr Configuration ===== */
4955 : : /* Configuration of the AQueue Depth QMGR_GRP_0_DEPTH_LOG2 for UL. */
4956 : 0 : totalQgs = conf->q_ul_4g.num_qgroups + conf->q_ul_5g.num_qgroups +
4957 : 0 : conf->q_dl_4g.num_qgroups + conf->q_dl_5g.num_qgroups +
4958 : 0 : conf->q_fft.num_qgroups + conf->q_mld.num_qgroups;
4959 [ # # ]: 0 : for (qg_idx = 0; qg_idx < VRB2_NUM_QGRPS; qg_idx++) {
4960 : 0 : address = VRB2_PfQmgrDepthLog2Grp + ACC_BYTES_IN_WORD * qg_idx;
4961 : 0 : value = aqDepth(qg_idx, conf);
4962 : : acc_reg_write(d, address, value);
4963 : 0 : address = VRB2_PfQmgrTholdGrp + ACC_BYTES_IN_WORD * qg_idx;
4964 : 0 : value = (1 << 16) + (1 << (aqDepth(qg_idx, conf) - 1));
4965 : : acc_reg_write(d, address, value);
4966 : : }
4967 : :
4968 : : /* Template Priority in incremental order. */
4969 [ # # ]: 0 : for (template_idx = 0; template_idx < ACC_NUM_TMPL; template_idx++) {
4970 : 0 : address = VRB2_PfQmgrGrpTmplateReg0Indx + ACC_BYTES_IN_WORD * template_idx;
4971 : : value = ACC_TMPL_PRI_0;
4972 : : acc_reg_write(d, address, value);
4973 : 0 : address = VRB2_PfQmgrGrpTmplateReg1Indx + ACC_BYTES_IN_WORD * template_idx;
4974 : : value = ACC_TMPL_PRI_1;
4975 : : acc_reg_write(d, address, value);
4976 : 0 : address = VRB2_PfQmgrGrpTmplateReg2Indx + ACC_BYTES_IN_WORD * template_idx;
4977 : : value = ACC_TMPL_PRI_2;
4978 : : acc_reg_write(d, address, value);
4979 : 0 : address = VRB2_PfQmgrGrpTmplateReg3Indx + ACC_BYTES_IN_WORD * template_idx;
4980 : : value = ACC_TMPL_PRI_3;
4981 : : acc_reg_write(d, address, value);
4982 : 0 : address = VRB2_PfQmgrGrpTmplateReg4Indx + ACC_BYTES_IN_WORD * template_idx;
4983 : : value = ACC_TMPL_PRI_4;
4984 : : acc_reg_write(d, address, value);
4985 : 0 : address = VRB2_PfQmgrGrpTmplateReg5Indx + ACC_BYTES_IN_WORD * template_idx;
4986 : : value = ACC_TMPL_PRI_5;
4987 : : acc_reg_write(d, address, value);
4988 : 0 : address = VRB2_PfQmgrGrpTmplateReg6Indx + ACC_BYTES_IN_WORD * template_idx;
4989 : : value = ACC_TMPL_PRI_6;
4990 : : acc_reg_write(d, address, value);
4991 : 0 : address = VRB2_PfQmgrGrpTmplateReg7Indx + ACC_BYTES_IN_WORD * template_idx;
4992 : : value = ACC_TMPL_PRI_7;
4993 : : acc_reg_write(d, address, value);
4994 : : }
4995 : :
4996 : : address = VRB2_PfQmgrGrpPriority;
4997 : : value = VRB2_CFG_QMGR_HI_P;
4998 : : acc_reg_write(d, address, value);
4999 : :
5000 : : /* Template Configuration. */
5001 [ # # ]: 0 : for (template_idx = 0; template_idx < ACC_NUM_TMPL; template_idx++) {
5002 : : value = 0;
5003 : 0 : address = VRB2_PfQmgrGrpTmplateEnRegIndx + ACC_BYTES_IN_WORD * template_idx;
5004 : : acc_reg_write(d, address, value);
5005 : : }
5006 : : /* 4GUL */
5007 : 0 : numQgs = conf->q_ul_4g.num_qgroups;
5008 : : numQqsAcc = 0;
5009 : : value = 0;
5010 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
5011 : 0 : value |= (1 << qg_idx);
5012 [ # # ]: 0 : for (template_idx = VRB2_SIG_UL_4G; template_idx <= VRB2_SIG_UL_4G_LAST;
5013 : 0 : template_idx++) {
5014 : 0 : address = VRB2_PfQmgrGrpTmplateEnRegIndx + ACC_BYTES_IN_WORD * template_idx;
5015 : : acc_reg_write(d, address, value);
5016 : : }
5017 : : /* 5GUL */
5018 : : numQqsAcc += numQgs;
5019 : 0 : numQgs = conf->q_ul_5g.num_qgroups;
5020 : : value = 0;
5021 : : numEngines = 0;
5022 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
5023 : 0 : value |= (1 << qg_idx);
5024 [ # # ]: 0 : for (template_idx = VRB2_SIG_UL_5G; template_idx <= VRB2_SIG_UL_5G_LAST;
5025 : 0 : template_idx++) {
5026 : : /* Check engine power-on status. */
5027 [ # # ]: 0 : address = VRB2_PfFecUl5gIbDebug0Reg + ACC_ENGINE_OFFSET * template_idx;
5028 : 0 : status = (acc_reg_read(d, address) >> 4) & 0x7;
5029 : 0 : address = VRB2_PfQmgrGrpTmplateEnRegIndx + ACC_BYTES_IN_WORD * template_idx;
5030 [ # # ]: 0 : if (status == 1) {
5031 : : acc_reg_write(d, address, value);
5032 : 0 : numEngines++;
5033 : : } else
5034 : : acc_reg_write(d, address, 0);
5035 : : }
5036 : 0 : rte_bbdev_log(INFO, "Number of 5GUL engines %d", numEngines);
5037 : : /* 4GDL */
5038 : : numQqsAcc += numQgs;
5039 : 0 : numQgs = conf->q_dl_4g.num_qgroups;
5040 : : value = 0;
5041 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
5042 : 0 : value |= (1 << qg_idx);
5043 [ # # ]: 0 : for (template_idx = VRB2_SIG_DL_4G; template_idx <= VRB2_SIG_DL_4G_LAST;
5044 : 0 : template_idx++) {
5045 : 0 : address = VRB2_PfQmgrGrpTmplateEnRegIndx + ACC_BYTES_IN_WORD * template_idx;
5046 : : acc_reg_write(d, address, value);
5047 : : }
5048 : : /* 5GDL */
5049 : : numQqsAcc += numQgs;
5050 : 0 : numQgs = conf->q_dl_5g.num_qgroups;
5051 : : value = 0;
5052 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
5053 : 0 : value |= (1 << qg_idx);
5054 [ # # ]: 0 : for (template_idx = VRB2_SIG_DL_5G; template_idx <= VRB2_SIG_DL_5G_LAST;
5055 : 0 : template_idx++) {
5056 : 0 : address = VRB2_PfQmgrGrpTmplateEnRegIndx + ACC_BYTES_IN_WORD * template_idx;
5057 : : acc_reg_write(d, address, value);
5058 : : }
5059 : : /* FFT */
5060 : : numQqsAcc += numQgs;
5061 : 0 : numQgs = conf->q_fft.num_qgroups;
5062 : : value = 0;
5063 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
5064 : 0 : value |= (1 << qg_idx);
5065 [ # # ]: 0 : for (template_idx = VRB2_SIG_FFT; template_idx <= VRB2_SIG_FFT_LAST;
5066 : 0 : template_idx++) {
5067 : 0 : address = VRB2_PfQmgrGrpTmplateEnRegIndx + ACC_BYTES_IN_WORD * template_idx;
5068 : : acc_reg_write(d, address, value);
5069 : : }
5070 : : /* MLD */
5071 : : numQqsAcc += numQgs;
5072 : 0 : numQgs = conf->q_mld.num_qgroups;
5073 : : value = 0;
5074 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
5075 : 0 : value |= (1 << qg_idx);
5076 [ # # ]: 0 : for (template_idx = VRB2_SIG_MLD; template_idx <= VRB2_SIG_MLD_LAST;
5077 : 0 : template_idx++) {
5078 : : address = VRB2_PfQmgrGrpTmplateEnRegIndx
5079 : 0 : + ACC_BYTES_IN_WORD * template_idx;
5080 : : acc_reg_write(d, address, value);
5081 : : }
5082 : :
5083 : : /* Queue Group Function mapping. */
5084 [ # # ]: 0 : for (i = 0; i < 4; i++) {
5085 : : value = 0;
5086 [ # # ]: 0 : for (qg_idx = 0; qg_idx < ACC_NUM_QGRPS_PER_WORD; qg_idx++) {
5087 : 0 : acc = accFromQgid(qg_idx + i * ACC_NUM_QGRPS_PER_WORD, conf);
5088 : 0 : value |= qman_func_id[acc] << (qg_idx * 4);
5089 : : }
5090 : 0 : acc_reg_write(d, VRB2_PfQmgrGrpFunction0 + i * ACC_BYTES_IN_WORD, value);
5091 : : }
5092 : :
5093 : : /* Configuration of the Arbitration QGroup depth to 1. */
5094 [ # # ]: 0 : for (qg_idx = 0; qg_idx < VRB2_NUM_QGRPS; qg_idx++) {
5095 : 0 : address = VRB2_PfQmgrArbQDepthGrp + ACC_BYTES_IN_WORD * qg_idx;
5096 : : value = 0;
5097 : : acc_reg_write(d, address, value);
5098 : : }
5099 : :
5100 : : static_allocation = 1;
5101 : : if (static_allocation == 1) {
5102 : : /* This pointer to ARAM (512kB) is shifted by 2 (4B per register). */
5103 : : uint32_t aram_address = 0;
5104 [ # # ]: 0 : for (qg_idx = 0; qg_idx < totalQgs; qg_idx++) {
5105 [ # # ]: 0 : for (vf_idx = 0; vf_idx < conf->num_vf_bundles; vf_idx++) {
5106 : 0 : address = VRB2_PfQmgrVfBaseAddr + vf_idx
5107 : 0 : * ACC_BYTES_IN_WORD + qg_idx
5108 : : * ACC_BYTES_IN_WORD * 64;
5109 : : value = aram_address;
5110 : : acc_reg_fast_write(d, address, value);
5111 : : /* Offset ARAM Address for next memory bank - increment of 4B. */
5112 : 0 : aram_address += aqNum(qg_idx, conf) *
5113 : 0 : (1 << aqDepth(qg_idx, conf));
5114 : : }
5115 : : }
5116 [ # # ]: 0 : if (aram_address > VRB2_WORDS_IN_ARAM_SIZE) {
5117 : 0 : rte_bbdev_log(ERR, "ARAM Configuration not fitting %d %d",
5118 : : aram_address, VRB2_WORDS_IN_ARAM_SIZE);
5119 : 0 : return -EINVAL;
5120 : : }
5121 : : } else {
5122 : : /* Dynamic Qmgr allocation. */
5123 : : acc_reg_write(d, VRB2_PfQmgrAramAllocEn, 1);
5124 : : acc_reg_write(d, VRB2_PfQmgrAramAllocSetupN0, 0x1000);
5125 : : acc_reg_write(d, VRB2_PfQmgrAramAllocSetupN1, 0);
5126 : : acc_reg_write(d, VRB2_PfQmgrAramAllocSetupN2, 0);
5127 : : acc_reg_write(d, VRB2_PfQmgrAramAllocSetupN3, 0);
5128 : : acc_reg_write(d, VRB2_PfQmgrSoftReset, 1);
5129 : : acc_reg_write(d, VRB2_PfQmgrSoftReset, 0);
5130 : : }
5131 : :
5132 : : /* ==== HI Configuration ==== */
5133 : :
5134 : : /* No Info Ring/MSI by default. */
5135 : : address = VRB2_PfHiInfoRingIntWrEnRegPf;
5136 : : value = 0;
5137 : : acc_reg_write(d, address, value);
5138 : : address = VRB2_PfHiCfgMsiIntWrEnRegPf;
5139 : : value = 0xFFFFFFFF;
5140 : : acc_reg_write(d, address, value);
5141 : : /* Prevent Block on Transmit Error. */
5142 : : address = VRB2_PfHiBlockTransmitOnErrorEn;
5143 : : value = 0;
5144 : : acc_reg_write(d, address, value);
5145 : : /* Prevents to drop MSI */
5146 : : address = VRB2_PfHiMsiDropEnableReg;
5147 : : value = 0;
5148 : : acc_reg_write(d, address, value);
5149 : : /* Set the PF Mode register */
5150 : : address = VRB2_PfHiPfMode;
5151 [ # # ]: 0 : value = ((conf->pf_mode_en) ? ACC_PF_VAL : 0) | 0x1F07F0;
5152 : : acc_reg_write(d, address, value);
5153 : : /* Explicitly releasing AXI after PF Mode. */
5154 : : acc_reg_write(d, VRB2_PfDmaAxiControl, 1);
5155 : :
5156 : : /* QoS overflow init. */
5157 : : value = 1;
5158 : : address = VRB2_PfQosmonAEvalOverflow0;
5159 : : acc_reg_write(d, address, value);
5160 : : address = VRB2_PfQosmonBEvalOverflow0;
5161 : : acc_reg_write(d, address, value);
5162 : :
5163 : : /* Enabling AQueues through the Queue hierarchy. */
5164 : : unsigned int en_bitmask[VRB2_AQ_REG_NUM];
5165 [ # # ]: 0 : for (vf_idx = 0; vf_idx < VRB2_NUM_VFS; vf_idx++) {
5166 [ # # ]: 0 : for (qg_idx = 0; qg_idx < VRB2_NUM_QGRPS; qg_idx++) {
5167 [ # # ]: 0 : for (aq_reg = 0; aq_reg < VRB2_AQ_REG_NUM; aq_reg++)
5168 : 0 : en_bitmask[aq_reg] = 0;
5169 [ # # # # ]: 0 : if (vf_idx < conf->num_vf_bundles && qg_idx < totalQgs) {
5170 [ # # ]: 0 : for (aq_reg = 0; aq_reg < VRB2_AQ_REG_NUM; aq_reg++) {
5171 [ # # ]: 0 : if (aqNum(qg_idx, conf) >= 16 * (aq_reg + 1))
5172 : 0 : en_bitmask[aq_reg] = 0xFFFF;
5173 [ # # ]: 0 : else if (aqNum(qg_idx, conf) <= 16 * aq_reg)
5174 : 0 : en_bitmask[aq_reg] = 0x0;
5175 : : else
5176 : 0 : en_bitmask[aq_reg] = (1 << (aqNum(qg_idx,
5177 : 0 : conf) - aq_reg * 16)) - 1;
5178 : : }
5179 : : }
5180 [ # # ]: 0 : for (aq_reg = 0; aq_reg < VRB2_AQ_REG_NUM; aq_reg++) {
5181 : 0 : address = VRB2_PfQmgrAqEnableVf + vf_idx * 16 + aq_reg * 4;
5182 : 0 : value = (qg_idx << 16) + en_bitmask[aq_reg];
5183 : : acc_reg_fast_write(d, address, value);
5184 : : }
5185 : : }
5186 : : }
5187 : :
5188 : 0 : rte_bbdev_log(INFO,
5189 : : "VRB2 basic config complete for %s - pf_bb_config should ideally be used instead",
5190 : : dev_name);
5191 : 0 : return 0;
5192 : : }
|