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