Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2020 Intel Corporation
3 : : */
4 : :
5 : : #include <unistd.h>
6 : :
7 : : #include <rte_common.h>
8 : : #include <rte_log.h>
9 : : #include <dev_driver.h>
10 : : #include <rte_malloc.h>
11 : : #include <rte_byteorder.h>
12 : : #include <rte_errno.h>
13 : : #include <rte_branch_prediction.h>
14 : : #include <rte_hexdump.h>
15 : : #include <rte_pci.h>
16 : : #include <bus_pci_driver.h>
17 : : #include <rte_cycles.h>
18 : :
19 : : #include <rte_bbdev.h>
20 : : #include <rte_bbdev_pmd.h>
21 : : #include "acc100_pmd.h"
22 : : #include "vrb_cfg.h"
23 : :
24 : : #ifdef RTE_BBDEV_SDK_AVX512
25 : : #include <phy_rate_dematching_5gnr.h>
26 : : #endif
27 : :
28 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
29 : : RTE_LOG_REGISTER_SUFFIX(acc100_logtype, acc100, DEBUG);
30 : : #else
31 [ - + ]: 252 : RTE_LOG_REGISTER_SUFFIX(acc100_logtype, acc100, NOTICE);
32 : : #endif
33 : : #define RTE_LOGTYPE_ACC100 acc100_logtype
34 : :
35 : : /* Calculate the offset of the enqueue register */
36 : : static inline uint32_t
37 : : queue_offset(bool pf_device, uint8_t vf_id, uint8_t qgrp_id, uint16_t aq_id)
38 : : {
39 : 0 : if (pf_device)
40 : 0 : return ((vf_id << 12) + (qgrp_id << 7) + (aq_id << 3) +
41 : : HWPfQmgrIngressAq);
42 : : else
43 : 0 : return ((qgrp_id << 7) + (aq_id << 3) +
44 : : HWVfQmgrIngressAq);
45 : : }
46 : :
47 : : enum {UL_4G = 0, UL_5G, DL_4G, DL_5G, NUM_ACC};
48 : :
49 : : /* Return the accelerator enum for a Queue Group Index */
50 : : static inline int
51 : 0 : accFromQgid(int qg_idx, const struct rte_acc_conf *acc_conf)
52 : : {
53 : : int accQg[ACC100_NUM_QGRPS];
54 : : int NumQGroupsPerFn[NUM_ACC];
55 : : int acc, qgIdx, qgIndex = 0;
56 [ # # ]: 0 : for (qgIdx = 0; qgIdx < ACC100_NUM_QGRPS; qgIdx++)
57 : 0 : accQg[qgIdx] = 0;
58 : 0 : NumQGroupsPerFn[UL_4G] = acc_conf->q_ul_4g.num_qgroups;
59 : 0 : NumQGroupsPerFn[UL_5G] = acc_conf->q_ul_5g.num_qgroups;
60 : 0 : NumQGroupsPerFn[DL_4G] = acc_conf->q_dl_4g.num_qgroups;
61 : 0 : NumQGroupsPerFn[DL_5G] = acc_conf->q_dl_5g.num_qgroups;
62 [ # # ]: 0 : for (acc = UL_4G; acc < NUM_ACC; acc++)
63 [ # # ]: 0 : for (qgIdx = 0; qgIdx < NumQGroupsPerFn[acc]; qgIdx++)
64 : 0 : accQg[qgIndex++] = acc;
65 : 0 : acc = accQg[qg_idx];
66 : 0 : return acc;
67 : : }
68 : :
69 : : /* Return the queue topology for a Queue Group Index */
70 : : static inline void
71 : 0 : qtopFromAcc(struct rte_acc_queue_topology **qtop, int acc_enum,
72 : : struct rte_acc_conf *acc_conf)
73 : : {
74 : : struct rte_acc_queue_topology *p_qtop;
75 : : p_qtop = NULL;
76 [ # # # # : 0 : switch (acc_enum) {
# ]
77 : 0 : case UL_4G:
78 : 0 : p_qtop = &(acc_conf->q_ul_4g);
79 : 0 : break;
80 : 0 : case UL_5G:
81 : 0 : p_qtop = &(acc_conf->q_ul_5g);
82 : 0 : break;
83 : 0 : case DL_4G:
84 : 0 : p_qtop = &(acc_conf->q_dl_4g);
85 : 0 : break;
86 : 0 : case DL_5G:
87 : 0 : p_qtop = &(acc_conf->q_dl_5g);
88 : 0 : break;
89 : 0 : default:
90 : : /* NOTREACHED */
91 : 0 : rte_bbdev_log(ERR, "Unexpected error evaluating qtopFromAcc");
92 : 0 : break;
93 : : }
94 : 0 : *qtop = p_qtop;
95 : 0 : }
96 : :
97 : : /* Return the AQ depth for a Queue Group Index */
98 : : static inline int
99 : 0 : aqDepth(int qg_idx, struct rte_acc_conf *acc_conf)
100 : : {
101 : 0 : struct rte_acc_queue_topology *q_top = NULL;
102 : 0 : int acc_enum = accFromQgid(qg_idx, acc_conf);
103 : 0 : qtopFromAcc(&q_top, acc_enum, acc_conf);
104 [ # # ]: 0 : if (unlikely(q_top == NULL))
105 : : return 1;
106 : 0 : return RTE_MAX(1, q_top->aq_depth_log2);
107 : : }
108 : :
109 : : /* Return the AQ depth for a Queue Group Index */
110 : : static inline int
111 : 0 : aqNum(int qg_idx, struct rte_acc_conf *acc_conf)
112 : : {
113 : 0 : struct rte_acc_queue_topology *q_top = NULL;
114 : 0 : int acc_enum = accFromQgid(qg_idx, acc_conf);
115 : 0 : qtopFromAcc(&q_top, acc_enum, acc_conf);
116 [ # # ]: 0 : if (unlikely(q_top == NULL))
117 : : return 0;
118 : 0 : return q_top->num_aqs_per_groups;
119 : : }
120 : :
121 : : static void
122 : : initQTop(struct rte_acc_conf *acc_conf)
123 : : {
124 : 0 : acc_conf->q_ul_4g.num_aqs_per_groups = 0;
125 : 0 : acc_conf->q_ul_4g.num_qgroups = 0;
126 : 0 : acc_conf->q_ul_4g.first_qgroup_index = -1;
127 : 0 : acc_conf->q_ul_5g.num_aqs_per_groups = 0;
128 : 0 : acc_conf->q_ul_5g.num_qgroups = 0;
129 : 0 : acc_conf->q_ul_5g.first_qgroup_index = -1;
130 : 0 : acc_conf->q_dl_4g.num_aqs_per_groups = 0;
131 : 0 : acc_conf->q_dl_4g.num_qgroups = 0;
132 : 0 : acc_conf->q_dl_4g.first_qgroup_index = -1;
133 : 0 : acc_conf->q_dl_5g.num_aqs_per_groups = 0;
134 : 0 : acc_conf->q_dl_5g.num_qgroups = 0;
135 : 0 : acc_conf->q_dl_5g.first_qgroup_index = -1;
136 : : }
137 : :
138 : : static inline void
139 : 0 : updateQtop(uint8_t acc, uint8_t qg, struct rte_acc_conf *acc_conf,
140 : : struct acc_device *d) {
141 : : uint32_t reg;
142 : 0 : struct rte_acc_queue_topology *q_top = NULL;
143 : 0 : qtopFromAcc(&q_top, acc, acc_conf);
144 [ # # ]: 0 : if (unlikely(q_top == NULL))
145 : 0 : return;
146 : : uint16_t aq;
147 : 0 : q_top->num_qgroups++;
148 [ # # ]: 0 : if (q_top->first_qgroup_index == -1) {
149 : 0 : q_top->first_qgroup_index = qg;
150 : : /* Can be optimized to assume all are enabled by default */
151 [ # # ]: 0 : reg = acc_reg_read(d, queue_offset(d->pf_device,
152 : : 0, qg, ACC100_NUM_AQS - 1));
153 [ # # ]: 0 : if (reg & ACC_QUEUE_ENABLE) {
154 : 0 : q_top->num_aqs_per_groups = ACC100_NUM_AQS;
155 : 0 : return;
156 : : }
157 : 0 : q_top->num_aqs_per_groups = 0;
158 [ # # ]: 0 : for (aq = 0; aq < ACC100_NUM_AQS; aq++) {
159 [ # # ]: 0 : reg = acc_reg_read(d, queue_offset(d->pf_device,
160 : : 0, qg, aq));
161 [ # # ]: 0 : if (reg & ACC_QUEUE_ENABLE)
162 : 0 : q_top->num_aqs_per_groups++;
163 : : }
164 : : }
165 : : }
166 : :
167 : : /* Fetch configuration enabled for the PF/VF using MMIO Read (slow) */
168 : : static inline void
169 : 0 : fetch_acc100_config(struct rte_bbdev *dev)
170 : : {
171 : 0 : struct acc_device *d = dev->data->dev_private;
172 : 0 : struct rte_acc_conf *acc_conf = &d->acc_conf;
173 : : const struct acc100_registry_addr *reg_addr;
174 : : uint8_t acc, qg;
175 : : uint32_t reg, reg_aq, reg_len0, reg_len1;
176 : : uint32_t reg_mode;
177 : :
178 : : /* No need to retrieve the configuration is already done */
179 [ # # ]: 0 : if (d->configured)
180 : 0 : return;
181 : :
182 : : /* Choose correct registry addresses for the device type */
183 [ # # ]: 0 : if (d->pf_device)
184 : : reg_addr = &pf_reg_addr;
185 : : else
186 : : reg_addr = &vf_reg_addr;
187 : :
188 : 0 : d->ddr_size = (1 + acc_reg_read(d, reg_addr->ddr_range)) << 10;
189 : :
190 : : /* Single VF Bundle by VF */
191 : 0 : acc_conf->num_vf_bundles = 1;
192 : : initQTop(acc_conf);
193 : :
194 : 0 : struct rte_acc_queue_topology *q_top = NULL;
195 : 0 : int qman_func_id[ACC100_NUM_ACCS] = {ACC_ACCMAP_0, ACC_ACCMAP_1,
196 : : ACC_ACCMAP_2, ACC_ACCMAP_3, ACC_ACCMAP_4};
197 : 0 : reg = acc_reg_read(d, reg_addr->qman_group_func);
198 [ # # ]: 0 : for (qg = 0; qg < ACC_NUM_QGRPS_PER_WORD; qg++) {
199 : 0 : reg_aq = acc_reg_read(d,
200 [ # # ]: 0 : queue_offset(d->pf_device, 0, qg, 0));
201 [ # # ]: 0 : if (reg_aq & ACC_QUEUE_ENABLE) {
202 : 0 : uint32_t idx = (reg >> (qg * 4)) & 0x7;
203 [ # # ]: 0 : if (idx < ACC100_NUM_ACCS) {
204 : 0 : acc = qman_func_id[idx];
205 : 0 : updateQtop(acc, qg, acc_conf, d);
206 : : }
207 : : }
208 : : }
209 : :
210 : : /* Check the depth of the AQs*/
211 : 0 : reg_len0 = acc_reg_read(d, reg_addr->depth_log0_offset);
212 : 0 : reg_len1 = acc_reg_read(d, reg_addr->depth_log1_offset);
213 [ # # ]: 0 : for (acc = 0; acc < NUM_ACC; acc++) {
214 : 0 : qtopFromAcc(&q_top, acc, acc_conf);
215 [ # # ]: 0 : if (q_top->first_qgroup_index < ACC_NUM_QGRPS_PER_WORD)
216 : 0 : q_top->aq_depth_log2 = (reg_len0 >>
217 : 0 : (q_top->first_qgroup_index * 4))
218 : 0 : & 0xF;
219 : : else
220 : 0 : q_top->aq_depth_log2 = (reg_len1 >>
221 : 0 : ((q_top->first_qgroup_index -
222 : 0 : ACC_NUM_QGRPS_PER_WORD) * 4))
223 : 0 : & 0xF;
224 : : }
225 : :
226 : : /* Read PF mode */
227 [ # # ]: 0 : if (d->pf_device) {
228 : : reg_mode = acc_reg_read(d, HWPfHiPfMode);
229 : 0 : acc_conf->pf_mode_en = (reg_mode == ACC_PF_VAL) ? 1 : 0;
230 : : }
231 : :
232 : : rte_bbdev_log_debug(
233 : : "%s Config LLR SIGN IN/OUT %s %s QG %u %u %u %u AQ %u %u %u %u Len %u %u %u %u",
234 : : (d->pf_device) ? "PF" : "VF",
235 : : (acc_conf->input_pos_llr_1_bit) ? "POS" : "NEG",
236 : : (acc_conf->output_pos_llr_1_bit) ? "POS" : "NEG",
237 : : acc_conf->q_ul_4g.num_qgroups,
238 : : acc_conf->q_dl_4g.num_qgroups,
239 : : acc_conf->q_ul_5g.num_qgroups,
240 : : acc_conf->q_dl_5g.num_qgroups,
241 : : acc_conf->q_ul_4g.num_aqs_per_groups,
242 : : acc_conf->q_dl_4g.num_aqs_per_groups,
243 : : acc_conf->q_ul_5g.num_aqs_per_groups,
244 : : acc_conf->q_dl_5g.num_aqs_per_groups,
245 : : acc_conf->q_ul_4g.aq_depth_log2,
246 : : acc_conf->q_dl_4g.aq_depth_log2,
247 : : acc_conf->q_ul_5g.aq_depth_log2,
248 : : acc_conf->q_dl_5g.aq_depth_log2);
249 : : }
250 : :
251 : : /* Checks PF Info Ring to find the interrupt cause and handles it accordingly */
252 : : static inline void
253 : 0 : acc100_check_ir(struct acc_device *acc100_dev)
254 : : {
255 : : volatile union acc_info_ring_data *ring_data;
256 : 0 : uint16_t info_ring_head = acc100_dev->info_ring_head;
257 [ # # ]: 0 : if (acc100_dev->info_ring == NULL)
258 : : return;
259 : :
260 : 0 : ring_data = acc100_dev->info_ring + (acc100_dev->info_ring_head &
261 : : ACC_INFO_RING_MASK);
262 : :
263 [ # # ]: 0 : while (ring_data->valid) {
264 [ # # ]: 0 : if ((ring_data->int_nb < ACC100_PF_INT_DMA_DL_DESC_IRQ) || (
265 [ # # ]: 0 : ring_data->int_nb >
266 : : ACC100_PF_INT_DMA_DL5G_DESC_IRQ)) {
267 : 0 : rte_bbdev_log(WARNING, "InfoRing: ITR:%d Info:0x%x",
268 : : ring_data->int_nb, ring_data->detailed_info);
269 : : /* Initialize Info Ring entry and move forward */
270 : 0 : ring_data->val = 0;
271 : : }
272 : 0 : info_ring_head++;
273 : 0 : ring_data = acc100_dev->info_ring +
274 : 0 : (info_ring_head & ACC_INFO_RING_MASK);
275 : : }
276 : : }
277 : :
278 : : /* Checks PF Info Ring to find the interrupt cause and handles it accordingly */
279 : : static inline void
280 : 0 : acc100_pf_interrupt_handler(struct rte_bbdev *dev)
281 : : {
282 : 0 : struct acc_device *acc100_dev = dev->data->dev_private;
283 : : volatile union acc_info_ring_data *ring_data;
284 : : struct acc_deq_intr_details deq_intr_det;
285 : :
286 : 0 : ring_data = acc100_dev->info_ring + (acc100_dev->info_ring_head &
287 : : ACC_INFO_RING_MASK);
288 : :
289 [ # # ]: 0 : while (ring_data->valid) {
290 : :
291 : : rte_bbdev_log_debug(
292 : : "ACC100 PF Interrupt received, Info Ring data: 0x%x",
293 : : ring_data->val);
294 : :
295 [ # # ]: 0 : switch (ring_data->int_nb) {
296 : 0 : case ACC100_PF_INT_DMA_DL_DESC_IRQ:
297 : : case ACC100_PF_INT_DMA_UL_DESC_IRQ:
298 : : case ACC100_PF_INT_DMA_UL5G_DESC_IRQ:
299 : : case ACC100_PF_INT_DMA_DL5G_DESC_IRQ:
300 : 0 : deq_intr_det.queue_id = get_queue_id_from_ring_info(
301 : : dev->data, *ring_data);
302 [ # # ]: 0 : if (deq_intr_det.queue_id == UINT16_MAX) {
303 : 0 : rte_bbdev_log(ERR,
304 : : "Couldn't find queue: aq_id: %u, qg_id: %u, vf_id: %u",
305 : : ring_data->aq_id,
306 : : ring_data->qg_id,
307 : : ring_data->vf_id);
308 : 0 : return;
309 : : }
310 : 0 : rte_bbdev_pmd_callback_process(dev,
311 : : RTE_BBDEV_EVENT_DEQUEUE, &deq_intr_det);
312 : 0 : break;
313 : 0 : default:
314 : 0 : rte_bbdev_pmd_callback_process(dev,
315 : : RTE_BBDEV_EVENT_ERROR, NULL);
316 : 0 : break;
317 : : }
318 : :
319 : : /* Initialize Info Ring entry and move forward */
320 : 0 : ring_data->val = 0;
321 : 0 : ++acc100_dev->info_ring_head;
322 : 0 : ring_data = acc100_dev->info_ring +
323 : 0 : (acc100_dev->info_ring_head &
324 : : ACC_INFO_RING_MASK);
325 : : }
326 : : }
327 : :
328 : : /* Checks VF Info Ring to find the interrupt cause and handles it accordingly */
329 : : static inline void
330 : 0 : acc100_vf_interrupt_handler(struct rte_bbdev *dev)
331 : : {
332 : 0 : struct acc_device *acc100_dev = dev->data->dev_private;
333 : : volatile union acc_info_ring_data *ring_data;
334 : : struct acc_deq_intr_details deq_intr_det;
335 : :
336 : 0 : ring_data = acc100_dev->info_ring + (acc100_dev->info_ring_head &
337 : : ACC_INFO_RING_MASK);
338 : :
339 [ # # ]: 0 : while (ring_data->valid) {
340 : :
341 : : rte_bbdev_log_debug(
342 : : "ACC100 VF Interrupt received, Info Ring data: 0x%x",
343 : : ring_data->val);
344 : :
345 [ # # ]: 0 : switch (ring_data->int_nb) {
346 : 0 : case ACC100_VF_INT_DMA_DL_DESC_IRQ:
347 : : case ACC100_VF_INT_DMA_UL_DESC_IRQ:
348 : : case ACC100_VF_INT_DMA_UL5G_DESC_IRQ:
349 : : case ACC100_VF_INT_DMA_DL5G_DESC_IRQ:
350 : : /* VFs are not aware of their vf_id - it's set to 0 in
351 : : * queue structures.
352 : : */
353 : 0 : ring_data->vf_id = 0;
354 : 0 : deq_intr_det.queue_id = get_queue_id_from_ring_info(
355 : : dev->data, *ring_data);
356 [ # # ]: 0 : if (deq_intr_det.queue_id == UINT16_MAX) {
357 : 0 : rte_bbdev_log(ERR,
358 : : "Couldn't find queue: aq_id: %u, qg_id: %u",
359 : : ring_data->aq_id,
360 : : ring_data->qg_id);
361 : 0 : return;
362 : : }
363 : 0 : rte_bbdev_pmd_callback_process(dev,
364 : : RTE_BBDEV_EVENT_DEQUEUE, &deq_intr_det);
365 : 0 : break;
366 : 0 : default:
367 : 0 : rte_bbdev_pmd_callback_process(dev,
368 : : RTE_BBDEV_EVENT_ERROR, NULL);
369 : 0 : break;
370 : : }
371 : :
372 : : /* Initialize Info Ring entry and move forward */
373 : 0 : ring_data->valid = 0;
374 : 0 : ++acc100_dev->info_ring_head;
375 : 0 : ring_data = acc100_dev->info_ring + (acc100_dev->info_ring_head
376 : 0 : & ACC_INFO_RING_MASK);
377 : : }
378 : : }
379 : :
380 : : /* Interrupt handler triggered by ACC100 dev for handling specific interrupt */
381 : : static void
382 : 0 : acc100_dev_interrupt_handler(void *cb_arg)
383 : : {
384 : : struct rte_bbdev *dev = cb_arg;
385 : 0 : struct acc_device *acc100_dev = dev->data->dev_private;
386 : :
387 : : /* Read info ring */
388 [ # # ]: 0 : if (acc100_dev->pf_device)
389 : 0 : acc100_pf_interrupt_handler(dev);
390 : : else
391 : 0 : acc100_vf_interrupt_handler(dev);
392 : 0 : }
393 : :
394 : : /* Allocate and setup inforing */
395 : : static int
396 : 0 : allocate_info_ring(struct rte_bbdev *dev)
397 : : {
398 : 0 : struct acc_device *d = dev->data->dev_private;
399 : : const struct acc100_registry_addr *reg_addr;
400 : : rte_iova_t info_ring_iova;
401 : : uint32_t phys_low, phys_high;
402 : :
403 [ # # ]: 0 : if (d->info_ring != NULL)
404 : : return 0; /* Already configured */
405 : :
406 : : /* Choose correct registry addresses for the device type */
407 [ # # ]: 0 : if (d->pf_device)
408 : : reg_addr = &pf_reg_addr;
409 : : else
410 : : reg_addr = &vf_reg_addr;
411 : : /* Allocate InfoRing */
412 : 0 : d->info_ring = rte_zmalloc_socket("Info Ring",
413 : : ACC_INFO_RING_NUM_ENTRIES *
414 : : sizeof(*d->info_ring), RTE_CACHE_LINE_SIZE,
415 : : dev->data->socket_id);
416 [ # # ]: 0 : if (d->info_ring == NULL) {
417 : 0 : rte_bbdev_log(ERR,
418 : : "Failed to allocate Info Ring for %s:%u",
419 : : dev->device->driver->name,
420 : : dev->data->dev_id);
421 : 0 : return -ENOMEM;
422 : : }
423 : 0 : info_ring_iova = rte_malloc_virt2iova(d->info_ring);
424 : :
425 : : /* Setup Info Ring */
426 : 0 : phys_high = (uint32_t)(info_ring_iova >> 32);
427 : 0 : phys_low = (uint32_t)(info_ring_iova);
428 : 0 : acc_reg_write(d, reg_addr->info_ring_hi, phys_high);
429 : 0 : acc_reg_write(d, reg_addr->info_ring_lo, phys_low);
430 : 0 : acc_reg_write(d, reg_addr->info_ring_en, ACC100_REG_IRQ_EN_ALL);
431 : 0 : d->info_ring_head = (acc_reg_read(d, reg_addr->info_ring_ptr) &
432 : 0 : 0xFFF) / sizeof(union acc_info_ring_data);
433 : 0 : return 0;
434 : : }
435 : :
436 : :
437 : : /* Allocate 64MB memory used for all software rings */
438 : : static int
439 : 0 : acc100_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id)
440 : : {
441 : : uint32_t phys_low, phys_high, value;
442 : 0 : struct acc_device *d = dev->data->dev_private;
443 : : const struct acc100_registry_addr *reg_addr;
444 : : int ret;
445 : :
446 [ # # # # ]: 0 : if (d->pf_device && !d->acc_conf.pf_mode_en) {
447 : 0 : rte_bbdev_log(NOTICE,
448 : : "%s has PF mode disabled. This PF can't be used.",
449 : : dev->data->name);
450 : 0 : return -ENODEV;
451 : : }
452 : :
453 : 0 : alloc_sw_rings_min_mem(dev, d, num_queues, socket_id);
454 : :
455 : : /* If minimal memory space approach failed, then allocate
456 : : * the 2 * 64MB block for the sw rings
457 : : */
458 [ # # ]: 0 : if (d->sw_rings == NULL)
459 : 0 : alloc_2x64mb_sw_rings_mem(dev, d, socket_id);
460 : :
461 [ # # ]: 0 : if (d->sw_rings == NULL) {
462 : 0 : rte_bbdev_log(NOTICE,
463 : : "Failure allocating sw_rings memory");
464 : 0 : return -ENODEV;
465 : : }
466 : :
467 : : /* Configure ACC100 with the base address for DMA descriptor rings
468 : : * Same descriptor rings used for UL and DL DMA Engines
469 : : * Note : Assuming only VF0 bundle is used for PF mode
470 : : */
471 : 0 : phys_high = (uint32_t)(d->sw_rings_iova >> 32);
472 : 0 : phys_low = (uint32_t)(d->sw_rings_iova & ~(ACC_SIZE_64MBYTE-1));
473 : :
474 : : /* Choose correct registry addresses for the device type */
475 [ # # ]: 0 : if (d->pf_device)
476 : : reg_addr = &pf_reg_addr;
477 : : else
478 : : reg_addr = &vf_reg_addr;
479 : :
480 : : /* Read the populated cfg from ACC100 registers */
481 : 0 : fetch_acc100_config(dev);
482 : :
483 [ # # ]: 0 : for (value = 0; value <= 2; value++) {
484 : 0 : acc_reg_write(d, reg_addr->pmon_ctrl_a, value);
485 : 0 : acc_reg_write(d, reg_addr->pmon_ctrl_b, value);
486 : : }
487 : :
488 : : /* Release AXI from PF */
489 [ # # ]: 0 : if (d->pf_device)
490 : : acc_reg_write(d, HWPfDmaAxiControl, 1);
491 : :
492 : 0 : acc_reg_write(d, reg_addr->dma_ring_ul5g_hi, phys_high);
493 : 0 : acc_reg_write(d, reg_addr->dma_ring_ul5g_lo, phys_low);
494 : 0 : acc_reg_write(d, reg_addr->dma_ring_dl5g_hi, phys_high);
495 : 0 : acc_reg_write(d, reg_addr->dma_ring_dl5g_lo, phys_low);
496 : 0 : acc_reg_write(d, reg_addr->dma_ring_ul4g_hi, phys_high);
497 : 0 : acc_reg_write(d, reg_addr->dma_ring_ul4g_lo, phys_low);
498 : 0 : acc_reg_write(d, reg_addr->dma_ring_dl4g_hi, phys_high);
499 : 0 : acc_reg_write(d, reg_addr->dma_ring_dl4g_lo, phys_low);
500 : :
501 : : /*
502 : : * Configure Ring Size to the max queue ring size
503 : : * (used for wrapping purpose)
504 : : */
505 [ # # ]: 0 : value = log2_basic(d->sw_ring_size / 64);
506 : 0 : acc_reg_write(d, reg_addr->ring_size, value);
507 : :
508 : : /* Configure tail pointer for use when SDONE enabled */
509 [ # # ]: 0 : if (d->tail_ptrs == NULL)
510 : 0 : d->tail_ptrs = rte_zmalloc_socket(
511 : 0 : dev->device->driver->name,
512 : : ACC100_NUM_QGRPS * ACC100_NUM_AQS * sizeof(uint32_t),
513 : : RTE_CACHE_LINE_SIZE, socket_id);
514 [ # # ]: 0 : if (d->tail_ptrs == NULL) {
515 : 0 : rte_bbdev_log(ERR, "Failed to allocate tail ptr for %s:%u",
516 : : dev->device->driver->name,
517 : : dev->data->dev_id);
518 : : ret = -ENOMEM;
519 : 0 : goto free_sw_rings;
520 : : }
521 : 0 : d->tail_ptr_iova = rte_malloc_virt2iova(d->tail_ptrs);
522 : :
523 : 0 : phys_high = (uint32_t)(d->tail_ptr_iova >> 32);
524 : 0 : phys_low = (uint32_t)(d->tail_ptr_iova);
525 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_ul5g_hi, phys_high);
526 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_ul5g_lo, phys_low);
527 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_dl5g_hi, phys_high);
528 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_dl5g_lo, phys_low);
529 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_ul4g_hi, phys_high);
530 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_ul4g_lo, phys_low);
531 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_dl4g_hi, phys_high);
532 : 0 : acc_reg_write(d, reg_addr->tail_ptrs_dl4g_lo, phys_low);
533 : :
534 : 0 : ret = allocate_info_ring(dev);
535 [ # # ]: 0 : if (ret < 0) {
536 : 0 : rte_bbdev_log(ERR, "Failed to allocate info_ring for %s:%u",
537 : : dev->device->driver->name,
538 : : dev->data->dev_id);
539 : : /* Continue */
540 : : }
541 : :
542 [ # # ]: 0 : if (d->harq_layout == NULL)
543 : 0 : d->harq_layout = rte_zmalloc_socket("HARQ Layout",
544 : : ACC_HARQ_LAYOUT * sizeof(*d->harq_layout),
545 : 0 : RTE_CACHE_LINE_SIZE, dev->data->socket_id);
546 [ # # ]: 0 : if (d->harq_layout == NULL) {
547 : 0 : rte_bbdev_log(ERR, "Failed to allocate harq_layout for %s:%u",
548 : : dev->device->driver->name,
549 : : dev->data->dev_id);
550 : : ret = -ENOMEM;
551 : 0 : goto free_tail_ptrs;
552 : : }
553 : :
554 : : /* Mark as configured properly */
555 : 0 : d->configured = true;
556 : :
557 : : rte_bbdev_log_debug(
558 : : "ACC100 (%s) configured sw_rings = %p, sw_rings_iova = %#"
559 : : PRIx64, dev->data->name, d->sw_rings, d->sw_rings_iova);
560 : 0 : return 0;
561 : :
562 : : free_tail_ptrs:
563 : 0 : rte_free(d->tail_ptrs);
564 : 0 : d->tail_ptrs = NULL;
565 : 0 : free_sw_rings:
566 : 0 : rte_free(d->sw_rings_base);
567 : 0 : d->sw_rings_base = NULL;
568 : 0 : d->sw_rings = NULL;
569 : :
570 : 0 : return ret;
571 : : }
572 : :
573 : : static int
574 : 0 : acc100_intr_enable(struct rte_bbdev *dev)
575 : : {
576 : : int ret;
577 : 0 : struct acc_device *d = dev->data->dev_private;
578 : :
579 : : /* Only MSI are currently supported */
580 [ # # # # ]: 0 : if (rte_intr_type_get(dev->intr_handle) == RTE_INTR_HANDLE_VFIO_MSI ||
581 : 0 : rte_intr_type_get(dev->intr_handle) == RTE_INTR_HANDLE_UIO) {
582 : :
583 : 0 : ret = allocate_info_ring(dev);
584 [ # # ]: 0 : if (ret < 0) {
585 : 0 : rte_bbdev_log(ERR,
586 : : "Couldn't allocate info ring for device: %s",
587 : : dev->data->name);
588 : 0 : return ret;
589 : : }
590 : :
591 : 0 : ret = rte_intr_enable(dev->intr_handle);
592 [ # # ]: 0 : if (ret < 0) {
593 : 0 : rte_bbdev_log(ERR,
594 : : "Couldn't enable interrupts for device: %s",
595 : : dev->data->name);
596 : 0 : rte_free(d->info_ring);
597 : 0 : d->info_ring = NULL;
598 : 0 : return ret;
599 : : }
600 : 0 : ret = rte_intr_callback_register(dev->intr_handle,
601 : : acc100_dev_interrupt_handler, dev);
602 [ # # ]: 0 : if (ret < 0) {
603 : 0 : rte_bbdev_log(ERR,
604 : : "Couldn't register interrupt callback for device: %s",
605 : : dev->data->name);
606 : 0 : rte_free(d->info_ring);
607 : 0 : d->info_ring = NULL;
608 : 0 : return ret;
609 : : }
610 : :
611 : : return 0;
612 : : }
613 : :
614 : 0 : rte_bbdev_log(ERR, "ACC100 (%s) supports only VFIO MSI interrupts",
615 : : dev->data->name);
616 : 0 : return -ENOTSUP;
617 : : }
618 : :
619 : : /* Free memory used for software rings */
620 : : static int
621 : 0 : acc100_dev_close(struct rte_bbdev *dev)
622 : : {
623 : 0 : struct acc_device *d = dev->data->dev_private;
624 : 0 : acc100_check_ir(d);
625 : 0 : rte_free(d->tail_ptrs);
626 : 0 : rte_free(d->info_ring);
627 : 0 : rte_free(d->sw_rings_base);
628 : 0 : rte_free(d->harq_layout);
629 : 0 : d->tail_ptrs = NULL;
630 : 0 : d->info_ring = NULL;
631 : 0 : d->sw_rings_base = NULL;
632 : 0 : d->sw_rings = NULL;
633 : 0 : d->harq_layout = NULL;
634 : : /* Ensure all in flight HW transactions are completed */
635 : 0 : usleep(ACC_LONG_WAIT);
636 : 0 : return 0;
637 : : }
638 : :
639 : : /**
640 : : * Report a ACC100 queue index which is free
641 : : * Return 0 to 16k for a valid queue_idx or -1 when no queue is available
642 : : * Note : Only supporting VF0 Bundle for PF mode
643 : : */
644 : : static int
645 : 0 : acc100_find_free_queue_idx(struct rte_bbdev *dev,
646 : : const struct rte_bbdev_queue_conf *conf)
647 : : {
648 : 0 : struct acc_device *d = dev->data->dev_private;
649 : 0 : int op_2_acc[5] = {0, UL_4G, DL_4G, UL_5G, DL_5G};
650 : 0 : int acc = op_2_acc[conf->op_type];
651 : 0 : struct rte_acc_queue_topology *qtop = NULL;
652 : :
653 : 0 : qtopFromAcc(&qtop, acc, &(d->acc_conf));
654 [ # # ]: 0 : if (qtop == NULL)
655 : : return -1;
656 : : /* Identify matching QGroup Index which are sorted in priority order */
657 : 0 : uint16_t group_idx = qtop->first_qgroup_index;
658 : 0 : group_idx += conf->priority;
659 [ # # ]: 0 : if (group_idx >= ACC100_NUM_QGRPS ||
660 [ # # ]: 0 : conf->priority >= qtop->num_qgroups) {
661 : 0 : rte_bbdev_log(INFO, "Invalid Priority on %s, priority %u",
662 : : dev->data->name, conf->priority);
663 : 0 : return -1;
664 : : }
665 : : /* Find a free AQ_idx */
666 : : uint64_t aq_idx;
667 [ # # ]: 0 : for (aq_idx = 0; aq_idx < qtop->num_aqs_per_groups; aq_idx++) {
668 [ # # ]: 0 : if (((d->q_assigned_bit_map[group_idx] >> aq_idx) & 0x1) == 0) {
669 : : /* Mark the Queue as assigned */
670 : 0 : d->q_assigned_bit_map[group_idx] |= (1ULL << aq_idx);
671 : : /* Report the AQ Index */
672 : 0 : return (group_idx << ACC100_GRP_ID_SHIFT) + aq_idx;
673 : : }
674 : : }
675 : 0 : rte_bbdev_log(INFO, "Failed to find free queue on %s, priority %u",
676 : : dev->data->name, conf->priority);
677 : 0 : return -1;
678 : : }
679 : :
680 : : /* Setup ACC100 queue */
681 : : static int
682 : 0 : acc100_queue_setup(struct rte_bbdev *dev, uint16_t queue_id,
683 : : const struct rte_bbdev_queue_conf *conf)
684 : : {
685 : 0 : struct acc_device *d = dev->data->dev_private;
686 : : struct acc_queue *q;
687 : : int16_t q_idx;
688 : : int ret;
689 : :
690 [ # # ]: 0 : if (d == NULL) {
691 : 0 : rte_bbdev_log(ERR, "Undefined device");
692 : 0 : return -ENODEV;
693 : : }
694 : : /* Allocate the queue data structure. */
695 : 0 : q = rte_zmalloc_socket(dev->device->driver->name, sizeof(*q),
696 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
697 [ # # ]: 0 : if (q == NULL) {
698 : 0 : rte_bbdev_log(ERR, "Failed to allocate queue memory");
699 : 0 : return -ENOMEM;
700 : : }
701 : :
702 : 0 : q->d = d;
703 : 0 : q->ring_addr = RTE_PTR_ADD(d->sw_rings, (d->sw_ring_size * queue_id));
704 : 0 : q->ring_addr_iova = d->sw_rings_iova + (d->sw_ring_size * queue_id);
705 : :
706 : : /* Prepare the Ring with default descriptor format */
707 : : union acc_dma_desc *desc = NULL;
708 : : unsigned int desc_idx, b_idx;
709 : 0 : int fcw_len = (conf->op_type == RTE_BBDEV_OP_LDPC_ENC ?
710 [ # # ]: 0 : ACC_FCW_LE_BLEN : (conf->op_type == RTE_BBDEV_OP_TURBO_DEC ?
711 [ # # ]: 0 : ACC_FCW_TD_BLEN : ACC_FCW_LD_BLEN));
712 : :
713 [ # # ]: 0 : for (desc_idx = 0; desc_idx < d->sw_ring_max_depth; desc_idx++) {
714 : 0 : desc = q->ring_addr + desc_idx;
715 : 0 : desc->req.word0 = ACC_DMA_DESC_TYPE;
716 : 0 : desc->req.word1 = 0; /**< Timestamp */
717 : 0 : desc->req.word2 = 0;
718 : 0 : desc->req.word3 = 0;
719 : 0 : uint64_t fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
720 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
721 : 0 : desc->req.data_ptrs[0].blen = fcw_len;
722 : 0 : desc->req.data_ptrs[0].blkid = ACC_DMA_BLKID_FCW;
723 : 0 : desc->req.data_ptrs[0].last = 0;
724 : 0 : desc->req.data_ptrs[0].dma_ext = 0;
725 [ # # ]: 0 : for (b_idx = 1; b_idx < ACC_DMA_MAX_NUM_POINTERS - 1;
726 : 0 : b_idx++) {
727 : 0 : desc->req.data_ptrs[b_idx].blkid = ACC_DMA_BLKID_IN;
728 : 0 : desc->req.data_ptrs[b_idx].last = 1;
729 : 0 : desc->req.data_ptrs[b_idx].dma_ext = 0;
730 : 0 : b_idx++;
731 : 0 : desc->req.data_ptrs[b_idx].blkid =
732 : : ACC_DMA_BLKID_OUT_ENC;
733 : 0 : desc->req.data_ptrs[b_idx].last = 1;
734 : 0 : desc->req.data_ptrs[b_idx].dma_ext = 0;
735 : : }
736 : : /* Preset some fields of LDPC FCW */
737 : 0 : desc->req.fcw_ld.FCWversion = ACC_FCW_VER;
738 : 0 : desc->req.fcw_ld.gain_i = 1;
739 : 0 : desc->req.fcw_ld.gain_h = 1;
740 : : }
741 : :
742 : 0 : q->lb_in = rte_zmalloc_socket(dev->device->driver->name,
743 : : RTE_CACHE_LINE_SIZE,
744 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
745 [ # # ]: 0 : if (q->lb_in == NULL) {
746 : 0 : rte_bbdev_log(ERR, "Failed to allocate lb_in memory");
747 : : ret = -ENOMEM;
748 : 0 : goto free_q;
749 : : }
750 : 0 : q->lb_in_addr_iova = rte_malloc_virt2iova(q->lb_in);
751 : 0 : q->lb_out = rte_zmalloc_socket(dev->device->driver->name,
752 : : RTE_CACHE_LINE_SIZE,
753 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
754 [ # # ]: 0 : if (q->lb_out == NULL) {
755 : 0 : rte_bbdev_log(ERR, "Failed to allocate lb_out memory");
756 : : ret = -ENOMEM;
757 : 0 : goto free_lb_in;
758 : : }
759 : 0 : q->lb_out_addr_iova = rte_malloc_virt2iova(q->lb_out);
760 : 0 : q->companion_ring_addr = rte_zmalloc_socket(dev->device->driver->name,
761 : 0 : d->sw_ring_max_depth * sizeof(*q->companion_ring_addr),
762 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
763 [ # # ]: 0 : if (q->companion_ring_addr == NULL) {
764 : 0 : rte_bbdev_log(ERR, "Failed to allocate companion_ring memory");
765 : : ret = -ENOMEM;
766 : 0 : goto free_lb_out;
767 : : }
768 : 0 : q->derm_buffer = rte_zmalloc_socket(dev->device->driver->name,
769 : : RTE_BBDEV_TURBO_MAX_CB_SIZE * 10,
770 : 0 : RTE_CACHE_LINE_SIZE, conf->socket);
771 [ # # ]: 0 : if (q->derm_buffer == NULL) {
772 : 0 : rte_bbdev_log(ERR, "Failed to allocate derm_buffer memory");
773 : : ret = -ENOMEM;
774 : 0 : goto free_companion_ring_addr;
775 : : }
776 : :
777 : : /*
778 : : * Software queue ring wraps synchronously with the HW when it reaches
779 : : * the boundary of the maximum allocated queue size, no matter what the
780 : : * sw queue size is. This wrapping is guarded by setting the wrap_mask
781 : : * to represent the maximum queue size as allocated at the time when
782 : : * the device has been setup (in configure()).
783 : : *
784 : : * The queue depth is set to the queue size value (conf->queue_size).
785 : : * This limits the occupancy of the queue at any point of time, so that
786 : : * the queue does not get swamped with enqueue requests.
787 : : */
788 : 0 : q->sw_ring_depth = conf->queue_size;
789 : 0 : q->sw_ring_wrap_mask = d->sw_ring_max_depth - 1;
790 : :
791 : 0 : q->op_type = conf->op_type;
792 : :
793 : 0 : q_idx = acc100_find_free_queue_idx(dev, conf);
794 [ # # ]: 0 : if (q_idx == -1) {
795 : : ret = -EINVAL;
796 : 0 : goto free_derm_buffer;
797 : : }
798 : :
799 : 0 : q->qgrp_id = (q_idx >> ACC100_GRP_ID_SHIFT) & 0xF;
800 : 0 : q->vf_id = (q_idx >> ACC100_VF_ID_SHIFT) & 0x3F;
801 : 0 : q->aq_id = q_idx & 0xF;
802 : 0 : q->aq_depth = 0;
803 [ # # ]: 0 : if (conf->op_type == RTE_BBDEV_OP_TURBO_DEC)
804 : 0 : q->aq_depth = (1 << d->acc_conf.q_ul_4g.aq_depth_log2);
805 [ # # ]: 0 : else if (conf->op_type == RTE_BBDEV_OP_TURBO_ENC)
806 : 0 : q->aq_depth = (1 << d->acc_conf.q_dl_4g.aq_depth_log2);
807 [ # # ]: 0 : else if (conf->op_type == RTE_BBDEV_OP_LDPC_DEC)
808 : 0 : q->aq_depth = (1 << d->acc_conf.q_ul_5g.aq_depth_log2);
809 [ # # ]: 0 : else if (conf->op_type == RTE_BBDEV_OP_LDPC_ENC)
810 : 0 : q->aq_depth = (1 << d->acc_conf.q_dl_5g.aq_depth_log2);
811 : :
812 [ # # ]: 0 : q->mmio_reg_enqueue = RTE_PTR_ADD(d->mmio_base,
813 : : queue_offset(d->pf_device,
814 : : q->vf_id, q->qgrp_id, q->aq_id));
815 : :
816 : : rte_bbdev_log_debug(
817 : : "Setup dev%u q%u: qgrp_id=%u, vf_id=%u, aq_id=%u, aq_depth=%u, mmio_reg_enqueue=%p",
818 : : dev->data->dev_id, queue_id, q->qgrp_id, q->vf_id,
819 : : q->aq_id, q->aq_depth, q->mmio_reg_enqueue);
820 : :
821 : 0 : dev->data->queues[queue_id].queue_private = q;
822 : 0 : return 0;
823 : :
824 : : free_derm_buffer:
825 : 0 : rte_free(q->derm_buffer);
826 : 0 : q->derm_buffer = NULL;
827 : 0 : free_companion_ring_addr:
828 : 0 : rte_free(q->companion_ring_addr);
829 : 0 : q->companion_ring_addr = NULL;
830 : 0 : free_lb_out:
831 : 0 : rte_free(q->lb_out);
832 : 0 : q->lb_out = NULL;
833 : 0 : free_lb_in:
834 : 0 : rte_free(q->lb_in);
835 : 0 : q->lb_in = NULL;
836 : 0 : free_q:
837 : 0 : rte_free(q);
838 : : q = NULL;
839 : :
840 : 0 : return ret;
841 : : }
842 : :
843 : : static int
844 : 0 : acc100_queue_stop(struct rte_bbdev *dev, uint16_t queue_id)
845 : : {
846 : : struct acc_queue *q;
847 : :
848 : 0 : q = dev->data->queues[queue_id].queue_private;
849 : 0 : rte_bbdev_log(INFO, "Queue Stop %d H/T/D %d %d %x OpType %d",
850 : : queue_id, q->sw_ring_head, q->sw_ring_tail,
851 : : q->sw_ring_depth, q->op_type);
852 : : /* ignore all operations in flight and clear counters */
853 : 0 : q->sw_ring_tail = q->sw_ring_head;
854 : 0 : q->aq_enqueued = 0;
855 : 0 : q->aq_dequeued = 0;
856 : 0 : dev->data->queues[queue_id].queue_stats.enqueued_count = 0;
857 : 0 : dev->data->queues[queue_id].queue_stats.dequeued_count = 0;
858 : 0 : dev->data->queues[queue_id].queue_stats.enqueue_err_count = 0;
859 : 0 : dev->data->queues[queue_id].queue_stats.dequeue_err_count = 0;
860 : 0 : dev->data->queues[queue_id].queue_stats.enqueue_warn_count = 0;
861 : 0 : dev->data->queues[queue_id].queue_stats.dequeue_warn_count = 0;
862 : 0 : dev->data->queues[queue_id].queue_stats.enqueue_depth_avail = 0;
863 : :
864 : 0 : return 0;
865 : : }
866 : :
867 : : /* Release ACC100 queue */
868 : : static int
869 : 0 : acc100_queue_release(struct rte_bbdev *dev, uint16_t q_id)
870 : : {
871 : 0 : struct acc_device *d = dev->data->dev_private;
872 : 0 : struct acc_queue *q = dev->data->queues[q_id].queue_private;
873 : :
874 [ # # ]: 0 : if (q != NULL) {
875 : : /* Mark the Queue as un-assigned */
876 : 0 : d->q_assigned_bit_map[q->qgrp_id] &= (~0ULL - (1 << (uint64_t) q->aq_id));
877 : 0 : rte_free(q->derm_buffer);
878 : 0 : rte_free(q->companion_ring_addr);
879 : 0 : rte_free(q->lb_in);
880 : 0 : rte_free(q->lb_out);
881 : 0 : rte_free(q);
882 : 0 : dev->data->queues[q_id].queue_private = NULL;
883 : : }
884 : :
885 : 0 : return 0;
886 : : }
887 : :
888 : : /* Get ACC100 device info */
889 : : static void
890 : 0 : acc100_dev_info_get(struct rte_bbdev *dev,
891 : : struct rte_bbdev_driver_info *dev_info)
892 : : {
893 : 0 : struct acc_device *d = dev->data->dev_private;
894 : : int i;
895 : : static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
896 : : {
897 : : .type = RTE_BBDEV_OP_TURBO_DEC,
898 : : .cap.turbo_dec = {
899 : : .capability_flags =
900 : : RTE_BBDEV_TURBO_SUBBLOCK_DEINTERLEAVE |
901 : : RTE_BBDEV_TURBO_CRC_TYPE_24B |
902 : : RTE_BBDEV_TURBO_HALF_ITERATION_EVEN |
903 : : RTE_BBDEV_TURBO_EARLY_TERMINATION |
904 : : RTE_BBDEV_TURBO_DEC_INTERRUPTS |
905 : : RTE_BBDEV_TURBO_NEG_LLR_1_BIT_IN |
906 : : RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP |
907 : : RTE_BBDEV_TURBO_DEC_CRC_24B_DROP |
908 : : RTE_BBDEV_TURBO_DEC_SCATTER_GATHER,
909 : : .max_llr_modulus = INT8_MAX,
910 : : .num_buffers_src =
911 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
912 : : .num_buffers_hard_out =
913 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
914 : : .num_buffers_soft_out =
915 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
916 : : }
917 : : },
918 : : {
919 : : .type = RTE_BBDEV_OP_TURBO_ENC,
920 : : .cap.turbo_enc = {
921 : : .capability_flags =
922 : : RTE_BBDEV_TURBO_CRC_24B_ATTACH |
923 : : RTE_BBDEV_TURBO_RV_INDEX_BYPASS |
924 : : RTE_BBDEV_TURBO_RATE_MATCH |
925 : : RTE_BBDEV_TURBO_ENC_INTERRUPTS |
926 : : RTE_BBDEV_TURBO_ENC_SCATTER_GATHER,
927 : : .num_buffers_src =
928 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
929 : : .num_buffers_dst =
930 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS,
931 : : }
932 : : },
933 : : {
934 : : .type = RTE_BBDEV_OP_LDPC_ENC,
935 : : .cap.ldpc_enc = {
936 : : .capability_flags =
937 : : RTE_BBDEV_LDPC_RATE_MATCH |
938 : : RTE_BBDEV_LDPC_CRC_24B_ATTACH |
939 : : RTE_BBDEV_LDPC_INTERLEAVER_BYPASS |
940 : : RTE_BBDEV_LDPC_ENC_INTERRUPTS,
941 : : .num_buffers_src =
942 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
943 : : .num_buffers_dst =
944 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
945 : : }
946 : : },
947 : : {
948 : : .type = RTE_BBDEV_OP_LDPC_DEC,
949 : : .cap.ldpc_dec = {
950 : : .capability_flags =
951 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
952 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
953 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
954 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
955 : : #ifdef ACC100_EXT_MEM
956 : : RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK |
957 : : RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE |
958 : : RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE |
959 : : #endif
960 : : RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE |
961 : : RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS |
962 : : RTE_BBDEV_LDPC_DECODE_BYPASS |
963 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER |
964 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION |
965 : : RTE_BBDEV_LDPC_LLR_COMPRESSION |
966 : : RTE_BBDEV_LDPC_DEC_INTERRUPTS,
967 : : .llr_size = 8,
968 : : .llr_decimals = 1,
969 : : .num_buffers_src =
970 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
971 : : .num_buffers_hard_out =
972 : : RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
973 : : .num_buffers_soft_out = 0,
974 : : }
975 : : },
976 : : RTE_BBDEV_END_OF_CAPABILITIES_LIST()
977 : : };
978 : :
979 : : static struct rte_bbdev_queue_conf default_queue_conf;
980 : 0 : default_queue_conf.socket = dev->data->socket_id;
981 : 0 : default_queue_conf.queue_size = ACC_MAX_QUEUE_DEPTH;
982 : :
983 : 0 : dev_info->driver_name = dev->device->driver->name;
984 : :
985 : : /* Read and save the populated config from ACC100 registers */
986 : 0 : fetch_acc100_config(dev);
987 : : /* Check the status of device */
988 : 0 : dev_info->device_status = RTE_BBDEV_DEV_NOT_SUPPORTED;
989 : :
990 : : /* Expose number of queues */
991 : 0 : dev_info->num_queues[RTE_BBDEV_OP_NONE] = 0;
992 : 0 : dev_info->num_queues[RTE_BBDEV_OP_TURBO_DEC] = d->acc_conf.q_ul_4g.num_aqs_per_groups *
993 : 0 : d->acc_conf.q_ul_4g.num_qgroups;
994 : 0 : dev_info->num_queues[RTE_BBDEV_OP_TURBO_ENC] = d->acc_conf.q_dl_4g.num_aqs_per_groups *
995 : 0 : d->acc_conf.q_dl_4g.num_qgroups;
996 : 0 : dev_info->num_queues[RTE_BBDEV_OP_LDPC_DEC] = d->acc_conf.q_ul_5g.num_aqs_per_groups *
997 : 0 : d->acc_conf.q_ul_5g.num_qgroups;
998 : 0 : dev_info->num_queues[RTE_BBDEV_OP_LDPC_ENC] = d->acc_conf.q_dl_5g.num_aqs_per_groups *
999 : 0 : d->acc_conf.q_dl_5g.num_qgroups;
1000 : 0 : dev_info->num_queues[RTE_BBDEV_OP_FFT] = 0;
1001 : 0 : dev_info->num_queues[RTE_BBDEV_OP_MLDTS] = 0;
1002 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_TURBO_DEC] = d->acc_conf.q_ul_4g.num_qgroups;
1003 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_TURBO_ENC] = d->acc_conf.q_dl_4g.num_qgroups;
1004 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_LDPC_DEC] = d->acc_conf.q_ul_5g.num_qgroups;
1005 : 0 : dev_info->queue_priority[RTE_BBDEV_OP_LDPC_ENC] = d->acc_conf.q_dl_5g.num_qgroups;
1006 : 0 : dev_info->max_num_queues = 0;
1007 [ # # ]: 0 : for (i = RTE_BBDEV_OP_NONE; i <= RTE_BBDEV_OP_LDPC_ENC; i++)
1008 : 0 : dev_info->max_num_queues += dev_info->num_queues[i];
1009 : 0 : dev_info->queue_size_lim = ACC_MAX_QUEUE_DEPTH;
1010 : 0 : dev_info->hardware_accelerated = true;
1011 : 0 : dev_info->max_dl_queue_priority =
1012 : 0 : d->acc_conf.q_dl_4g.num_qgroups - 1;
1013 : 0 : dev_info->max_ul_queue_priority =
1014 : 0 : d->acc_conf.q_ul_4g.num_qgroups - 1;
1015 : 0 : dev_info->default_queue_conf = default_queue_conf;
1016 : 0 : dev_info->cpu_flag_reqs = NULL;
1017 : 0 : dev_info->min_alignment = 1;
1018 : 0 : dev_info->capabilities = bbdev_capabilities;
1019 : : #ifdef ACC100_EXT_MEM
1020 : 0 : dev_info->harq_buffer_size = d->ddr_size;
1021 : : #else
1022 : : dev_info->harq_buffer_size = 0;
1023 : : #endif
1024 : 0 : dev_info->data_endianness = RTE_LITTLE_ENDIAN;
1025 : 0 : acc100_check_ir(d);
1026 : 0 : }
1027 : :
1028 : : static int
1029 : 0 : acc100_queue_intr_enable(struct rte_bbdev *dev, uint16_t queue_id)
1030 : : {
1031 : 0 : struct acc_queue *q = dev->data->queues[queue_id].queue_private;
1032 : :
1033 [ # # # # ]: 0 : if (rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_VFIO_MSI &&
1034 : 0 : rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_UIO)
1035 : : return -ENOTSUP;
1036 : :
1037 : 0 : q->irq_enable = 1;
1038 : 0 : return 0;
1039 : : }
1040 : :
1041 : : static int
1042 : 0 : acc100_queue_intr_disable(struct rte_bbdev *dev, uint16_t queue_id)
1043 : : {
1044 : 0 : struct acc_queue *q = dev->data->queues[queue_id].queue_private;
1045 : :
1046 [ # # # # ]: 0 : if (rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_VFIO_MSI &&
1047 : 0 : rte_intr_type_get(dev->intr_handle) != RTE_INTR_HANDLE_UIO)
1048 : : return -ENOTSUP;
1049 : :
1050 : 0 : q->irq_enable = 0;
1051 : 0 : return 0;
1052 : : }
1053 : :
1054 : : static const struct rte_bbdev_ops acc100_bbdev_ops = {
1055 : : .setup_queues = acc100_setup_queues,
1056 : : .intr_enable = acc100_intr_enable,
1057 : : .close = acc100_dev_close,
1058 : : .info_get = acc100_dev_info_get,
1059 : : .queue_setup = acc100_queue_setup,
1060 : : .queue_release = acc100_queue_release,
1061 : : .queue_stop = acc100_queue_stop,
1062 : : .queue_intr_enable = acc100_queue_intr_enable,
1063 : : .queue_intr_disable = acc100_queue_intr_disable
1064 : : };
1065 : :
1066 : : /* ACC100 PCI PF address map */
1067 : : static struct rte_pci_id pci_id_acc100_pf_map[] = {
1068 : : {
1069 : : RTE_PCI_DEVICE(ACC100_VENDOR_ID, ACC100_PF_DEVICE_ID),
1070 : : },
1071 : : {.device_id = 0},
1072 : : };
1073 : :
1074 : : /* ACC100 PCI VF address map */
1075 : : static struct rte_pci_id pci_id_acc100_vf_map[] = {
1076 : : {
1077 : : RTE_PCI_DEVICE(ACC100_VENDOR_ID, ACC100_VF_DEVICE_ID),
1078 : : },
1079 : : {.device_id = 0},
1080 : : };
1081 : :
1082 : :
1083 : : /* Fill in a frame control word for turbo decoding. */
1084 : : static inline void
1085 : : acc100_fcw_td_fill(const struct rte_bbdev_dec_op *op, struct acc_fcw_td *fcw)
1086 : : {
1087 : : /* Note : Early termination is always enabled for 4GUL */
1088 : 0 : fcw->fcw_ver = 1;
1089 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1090 : 0 : fcw->k_pos = op->turbo_dec.tb_params.k_pos;
1091 : : else
1092 : 0 : fcw->k_pos = op->turbo_dec.cb_params.k;
1093 : 0 : fcw->turbo_crc_type = check_bit(op->turbo_dec.op_flags,
1094 : : RTE_BBDEV_TURBO_CRC_TYPE_24B);
1095 : 0 : fcw->bypass_sb_deint = 0;
1096 : 0 : fcw->raw_decoder_input_on = 0;
1097 : 0 : fcw->max_iter = op->turbo_dec.iter_max;
1098 : 0 : fcw->half_iter_on = !check_bit(op->turbo_dec.op_flags,
1099 : : RTE_BBDEV_TURBO_HALF_ITERATION_EVEN);
1100 : : }
1101 : :
1102 : : static inline bool
1103 : : is_acc100(struct acc_queue *q)
1104 : : {
1105 : 0 : return (q->d->device_variant == ACC100_VARIANT);
1106 : : }
1107 : :
1108 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
1109 : : static inline bool
1110 : : validate_op_required(struct acc_queue *q)
1111 : : {
1112 : : return is_acc100(q);
1113 : : }
1114 : : #endif
1115 : :
1116 : : /* Fill in a frame control word for LDPC decoding. */
1117 : : static inline void
1118 : 0 : acc100_fcw_ld_fill(struct rte_bbdev_dec_op *op, struct acc_fcw_ld *fcw,
1119 : : union acc_harq_layout_data *harq_layout)
1120 : : {
1121 : : uint16_t harq_out_length, harq_in_length, ncb_p, k0_p, parity_offset;
1122 : : uint32_t harq_index;
1123 : : uint32_t l;
1124 : :
1125 : 0 : fcw->qm = op->ldpc_dec.q_m;
1126 : 0 : fcw->nfiller = op->ldpc_dec.n_filler;
1127 : 0 : fcw->BG = (op->ldpc_dec.basegraph - 1);
1128 : 0 : fcw->Zc = op->ldpc_dec.z_c;
1129 : 0 : fcw->ncb = op->ldpc_dec.n_cb;
1130 : 0 : fcw->k0 = get_k0(fcw->ncb, fcw->Zc, op->ldpc_dec.basegraph,
1131 : 0 : op->ldpc_dec.rv_index, op->ldpc_dec.k0);
1132 [ # # ]: 0 : if (op->ldpc_dec.code_block_mode == RTE_BBDEV_CODE_BLOCK)
1133 : 0 : fcw->rm_e = op->ldpc_dec.cb_params.e;
1134 : : else
1135 : 0 : fcw->rm_e = (op->ldpc_dec.tb_params.r <
1136 : 0 : op->ldpc_dec.tb_params.cab) ?
1137 [ # # ]: 0 : op->ldpc_dec.tb_params.ea :
1138 : 0 : op->ldpc_dec.tb_params.eb;
1139 : :
1140 [ # # # # ]: 0 : if (unlikely(check_bit(op->ldpc_dec.op_flags,
1141 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE) &&
1142 : : (op->ldpc_dec.harq_combined_input.length == 0))) {
1143 : 0 : rte_bbdev_log(WARNING, "Null HARQ input size provided");
1144 : : /* Disable HARQ input in that case to carry forward. */
1145 : 0 : op->ldpc_dec.op_flags ^= RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE;
1146 : : }
1147 : :
1148 [ # # ]: 0 : fcw->hcin_en = check_bit(op->ldpc_dec.op_flags,
1149 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE);
1150 : 0 : fcw->hcout_en = check_bit(op->ldpc_dec.op_flags,
1151 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE);
1152 : 0 : fcw->crc_select = check_bit(op->ldpc_dec.op_flags,
1153 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK);
1154 : 0 : fcw->bypass_dec = check_bit(op->ldpc_dec.op_flags,
1155 : : RTE_BBDEV_LDPC_DECODE_BYPASS);
1156 : 0 : fcw->bypass_intlv = check_bit(op->ldpc_dec.op_flags,
1157 : : RTE_BBDEV_LDPC_DEINTERLEAVER_BYPASS);
1158 [ # # ]: 0 : if (op->ldpc_dec.q_m == 1) {
1159 : 0 : fcw->bypass_intlv = 1;
1160 : 0 : fcw->qm = 2;
1161 : : }
1162 : 0 : fcw->hcin_decomp_mode = check_bit(op->ldpc_dec.op_flags,
1163 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION);
1164 : 0 : fcw->hcout_comp_mode = check_bit(op->ldpc_dec.op_flags,
1165 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION);
1166 : 0 : fcw->llr_pack_mode = check_bit(op->ldpc_dec.op_flags,
1167 : : RTE_BBDEV_LDPC_LLR_COMPRESSION);
1168 [ # # ]: 0 : harq_index = hq_index(op->ldpc_dec.harq_combined_output.offset);
1169 [ # # ]: 0 : if (fcw->hcin_en > 0) {
1170 : 0 : harq_in_length = op->ldpc_dec.harq_combined_input.length;
1171 [ # # ]: 0 : if (fcw->hcin_decomp_mode > 0)
1172 : 0 : harq_in_length = harq_in_length * 8 / 6;
1173 : :
1174 : 0 : harq_in_length = RTE_MIN(harq_in_length, op->ldpc_dec.n_cb
1175 : : - op->ldpc_dec.n_filler);
1176 : :
1177 : : /* Alignment on next 64B - Already enforced from HC output */
1178 : 0 : harq_in_length = RTE_ALIGN_CEIL(harq_in_length, ACC_HARQ_ALIGN_64B);
1179 : :
1180 : : /* Stronger alignment requirement when in decompression mode */
1181 [ # # ]: 0 : if (fcw->hcin_decomp_mode > 0)
1182 : 0 : harq_in_length = RTE_ALIGN_FLOOR(harq_in_length, ACC100_HARQ_ALIGN_COMP);
1183 : :
1184 : 0 : fcw->hcin_size0 = harq_in_length;
1185 : 0 : fcw->hcin_offset = 0;
1186 : 0 : fcw->hcin_size1 = 0;
1187 : : } else {
1188 : 0 : fcw->hcin_size0 = 0;
1189 : 0 : fcw->hcin_offset = 0;
1190 : 0 : fcw->hcin_size1 = 0;
1191 : : }
1192 : :
1193 [ # # ]: 0 : fcw->itmax = op->ldpc_dec.iter_max;
1194 : 0 : fcw->itstop = check_bit(op->ldpc_dec.op_flags,
1195 : : RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE);
1196 : 0 : fcw->synd_precoder = fcw->itstop;
1197 : : /*
1198 : : * These are all implicitly set
1199 : : * fcw->synd_post = 0;
1200 : : * fcw->so_en = 0;
1201 : : * fcw->so_bypass_rm = 0;
1202 : : * fcw->so_bypass_intlv = 0;
1203 : : * fcw->dec_convllr = 0;
1204 : : * fcw->hcout_convllr = 0;
1205 : : * fcw->hcout_size1 = 0;
1206 : : * fcw->so_it = 0;
1207 : : * fcw->hcout_offset = 0;
1208 : : * fcw->negstop_th = 0;
1209 : : * fcw->negstop_it = 0;
1210 : : * fcw->negstop_en = 0;
1211 : : * fcw->gain_i = 1;
1212 : : * fcw->gain_h = 1;
1213 : : */
1214 [ # # ]: 0 : if (fcw->hcout_en > 0) {
1215 : 0 : parity_offset = (op->ldpc_dec.basegraph == 1 ? 20 : 8)
1216 [ # # ]: 0 : * op->ldpc_dec.z_c - op->ldpc_dec.n_filler;
1217 [ # # ]: 0 : k0_p = (fcw->k0 > parity_offset) ? fcw->k0 - op->ldpc_dec.n_filler : fcw->k0;
1218 : 0 : ncb_p = fcw->ncb - op->ldpc_dec.n_filler;
1219 : 0 : l = RTE_MIN(k0_p + fcw->rm_e, INT16_MAX);
1220 : 0 : harq_out_length = (uint16_t) fcw->hcin_size0;
1221 : 0 : harq_out_length = RTE_MAX(harq_out_length, l);
1222 : :
1223 : : /* Stronger alignment when in compression mode */
1224 [ # # ]: 0 : if (fcw->hcout_comp_mode > 0)
1225 : 0 : harq_out_length = RTE_ALIGN_CEIL(harq_out_length, ACC100_HARQ_ALIGN_COMP);
1226 : :
1227 : : /* Cannot exceed the pruned Ncb circular buffer */
1228 : 0 : harq_out_length = RTE_MIN(harq_out_length, ncb_p);
1229 : :
1230 : : /* Alignment on next 64B */
1231 : 0 : harq_out_length = RTE_ALIGN_CEIL(harq_out_length, ACC_HARQ_ALIGN_64B);
1232 : :
1233 : : /* Stronger alignment when in compression mode enforced again */
1234 [ # # ]: 0 : if (fcw->hcout_comp_mode > 0)
1235 : 0 : harq_out_length = RTE_ALIGN_FLOOR(harq_out_length, ACC100_HARQ_ALIGN_COMP);
1236 : :
1237 : 0 : fcw->hcout_size0 = harq_out_length;
1238 : 0 : fcw->hcout_size1 = 0;
1239 : 0 : fcw->hcout_offset = 0;
1240 : :
1241 [ # # ]: 0 : if (fcw->hcout_size0 == 0) {
1242 : 0 : rte_bbdev_log(ERR, " Disabling HARQ output as size is zero");
1243 : 0 : op->ldpc_dec.op_flags ^= RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE;
1244 : 0 : fcw->hcout_en = 0;
1245 : : }
1246 : :
1247 : 0 : harq_layout[harq_index].offset = fcw->hcout_offset;
1248 : 0 : harq_layout[harq_index].size0 = fcw->hcout_size0;
1249 : : } else {
1250 : 0 : fcw->hcout_size0 = 0;
1251 : 0 : fcw->hcout_size1 = 0;
1252 : 0 : fcw->hcout_offset = 0;
1253 : : }
1254 : 0 : }
1255 : :
1256 : : /* May need to pad LDPC Encoder input to avoid small beat for ACC100. */
1257 : : static inline uint16_t
1258 : : pad_le_in(uint16_t blen, struct acc_queue *q)
1259 : : {
1260 : : uint16_t last_beat;
1261 : :
1262 [ # # ]: 0 : if (!is_acc100(q))
1263 : : return blen;
1264 : :
1265 : 0 : last_beat = blen % 64;
1266 [ # # # # ]: 0 : if ((last_beat > 0) && (last_beat <= 8))
1267 : 0 : blen += 8;
1268 : :
1269 : : return blen;
1270 : : }
1271 : :
1272 : : static inline int
1273 [ # # ]: 0 : acc100_dma_desc_le_fill(struct rte_bbdev_enc_op *op,
1274 : : struct acc_dma_req_desc *desc, struct rte_mbuf **input,
1275 : : struct rte_mbuf *output, uint32_t *in_offset,
1276 : : uint32_t *out_offset, uint32_t *out_length,
1277 : : uint32_t *mbuf_total_left, uint32_t *seg_total_left, struct acc_queue *q)
1278 : : {
1279 : : int next_triplet = 1; /* FCW already done */
1280 : : uint16_t K, in_length_in_bits, in_length_in_bytes;
1281 : : struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
1282 : :
1283 : : acc_header_init(desc);
1284 : :
1285 [ # # ]: 0 : K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
1286 : 0 : in_length_in_bits = K - enc->n_filler;
1287 [ # # ]: 0 : if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH)
1288 : 0 : in_length_in_bits -= 24;
1289 : 0 : in_length_in_bytes = in_length_in_bits >> 3;
1290 : :
1291 [ # # # # ]: 0 : if (unlikely((*mbuf_total_left == 0) ||
1292 : : (*mbuf_total_left < in_length_in_bytes))) {
1293 : 0 : rte_bbdev_log(ERR,
1294 : : "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1295 : : *mbuf_total_left, in_length_in_bytes);
1296 : 0 : return -1;
1297 : : }
1298 : :
1299 : 0 : next_triplet = acc_dma_fill_blk_type_in(desc, input, in_offset,
1300 : : pad_le_in(in_length_in_bytes, q), seg_total_left, next_triplet, false);
1301 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1302 : 0 : rte_bbdev_log(ERR,
1303 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p",
1304 : : op);
1305 : 0 : return -1;
1306 : : }
1307 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1308 : 0 : desc->m2dlen = next_triplet;
1309 : 0 : *mbuf_total_left -= in_length_in_bytes;
1310 : :
1311 : : /* Set output length */
1312 : : /* Integer round up division by 8 */
1313 : 0 : *out_length = (enc->cb_params.e + 7) >> 3;
1314 : :
1315 : 0 : next_triplet = acc_dma_fill_blk_type(desc, output, *out_offset,
1316 : : *out_length, next_triplet, ACC_DMA_BLKID_OUT_ENC);
1317 : 0 : op->ldpc_enc.output.length += *out_length;
1318 : 0 : *out_offset += *out_length;
1319 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1320 : 0 : desc->data_ptrs[next_triplet - 1].dma_ext = 0;
1321 : 0 : desc->d2mlen = next_triplet - desc->m2dlen;
1322 : :
1323 : 0 : desc->op_addr = op;
1324 : :
1325 : 0 : return 0;
1326 : : }
1327 : :
1328 : : static inline int
1329 : 0 : acc100_dma_desc_td_fill(struct rte_bbdev_dec_op *op,
1330 : : struct acc_dma_req_desc *desc, struct rte_mbuf **input,
1331 : : struct rte_mbuf *h_output, struct rte_mbuf *s_output,
1332 : : uint32_t *in_offset, uint32_t *h_out_offset,
1333 : : uint32_t *s_out_offset, uint32_t *h_out_length,
1334 : : uint32_t *s_out_length, uint32_t *mbuf_total_left,
1335 : : uint32_t *seg_total_left, uint8_t r)
1336 : : {
1337 : : int next_triplet = 1; /* FCW already done */
1338 : : uint16_t k;
1339 : : uint16_t crc24_overlap = 0;
1340 : : uint32_t e, kw;
1341 : :
1342 : 0 : desc->word0 = ACC_DMA_DESC_TYPE;
1343 : 0 : desc->word1 = 0; /**< Timestamp could be disabled */
1344 : 0 : desc->word2 = 0;
1345 : 0 : desc->word3 = 0;
1346 : 0 : desc->numCBs = 1;
1347 : :
1348 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1349 [ # # ]: 0 : k = (r < op->turbo_dec.tb_params.c_neg)
1350 : : ? op->turbo_dec.tb_params.k_neg
1351 : : : op->turbo_dec.tb_params.k_pos;
1352 : 0 : e = (r < op->turbo_dec.tb_params.cab)
1353 : : ? op->turbo_dec.tb_params.ea
1354 [ # # ]: 0 : : op->turbo_dec.tb_params.eb;
1355 : : } else {
1356 : 0 : k = op->turbo_dec.cb_params.k;
1357 : 0 : e = op->turbo_dec.cb_params.e;
1358 : : }
1359 : :
1360 [ # # ]: 0 : if ((op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
1361 [ # # ]: 0 : && !check_bit(op->turbo_dec.op_flags,
1362 : : RTE_BBDEV_TURBO_DEC_TB_CRC_24B_KEEP))
1363 : : crc24_overlap = 24;
1364 [ # # ]: 0 : if ((op->turbo_dec.code_block_mode == RTE_BBDEV_CODE_BLOCK)
1365 [ # # ]: 0 : && check_bit(op->turbo_dec.op_flags,
1366 : : RTE_BBDEV_TURBO_DEC_CRC_24B_DROP))
1367 : : crc24_overlap = 24;
1368 : :
1369 : : /* Calculates circular buffer size.
1370 : : * According to 3gpp 36.212 section 5.1.4.2
1371 : : * Kw = 3 * Kpi,
1372 : : * where:
1373 : : * Kpi = nCol * nRow
1374 : : * where nCol is 32 and nRow can be calculated from:
1375 : : * D =< nCol * nRow
1376 : : * where D is the size of each output from turbo encoder block (k + 4).
1377 : : */
1378 : 0 : kw = RTE_ALIGN_CEIL(k + 4, 32) * 3;
1379 : :
1380 [ # # # # ]: 0 : if (unlikely((*mbuf_total_left == 0) || (*mbuf_total_left < kw))) {
1381 : 0 : rte_bbdev_log(ERR,
1382 : : "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1383 : : *mbuf_total_left, kw);
1384 : 0 : return -1;
1385 : : }
1386 : :
1387 : 0 : next_triplet = acc_dma_fill_blk_type_in(desc, input, in_offset, kw,
1388 : : seg_total_left, next_triplet,
1389 : 0 : check_bit(op->turbo_dec.op_flags,
1390 : : RTE_BBDEV_TURBO_DEC_SCATTER_GATHER));
1391 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1392 : 0 : rte_bbdev_log(ERR,
1393 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p",
1394 : : op);
1395 : 0 : return -1;
1396 : : }
1397 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1398 : 0 : desc->m2dlen = next_triplet;
1399 : 0 : *mbuf_total_left -= kw;
1400 : :
1401 : 0 : next_triplet = acc_dma_fill_blk_type(
1402 : : desc, h_output, *h_out_offset,
1403 [ # # ]: 0 : (k - crc24_overlap) >> 3, next_triplet,
1404 : : ACC_DMA_BLKID_OUT_HARD);
1405 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1406 : 0 : rte_bbdev_log(ERR,
1407 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p",
1408 : : op);
1409 : 0 : return -1;
1410 : : }
1411 : :
1412 : 0 : *h_out_length = ((k - crc24_overlap) >> 3);
1413 : 0 : op->turbo_dec.hard_output.length += *h_out_length;
1414 : 0 : *h_out_offset += *h_out_length;
1415 : :
1416 : : /* Soft output */
1417 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT)) {
1418 [ # # ]: 0 : if (op->turbo_dec.soft_output.data == 0) {
1419 : 0 : rte_bbdev_log(ERR, "Soft output is not defined");
1420 : 0 : return -1;
1421 : : }
1422 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
1423 : : RTE_BBDEV_TURBO_EQUALIZER))
1424 : 0 : *s_out_length = e;
1425 : : else
1426 : 0 : *s_out_length = (k * 3) + 12;
1427 : :
1428 [ # # ]: 0 : next_triplet = acc_dma_fill_blk_type(desc, s_output,
1429 : : *s_out_offset, *s_out_length, next_triplet,
1430 : : ACC_DMA_BLKID_OUT_SOFT);
1431 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1432 : 0 : rte_bbdev_log(ERR,
1433 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p",
1434 : : op);
1435 : 0 : return -1;
1436 : : }
1437 : :
1438 : 0 : op->turbo_dec.soft_output.length += *s_out_length;
1439 : 0 : *s_out_offset += *s_out_length;
1440 : : }
1441 : :
1442 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1443 : 0 : desc->d2mlen = next_triplet - desc->m2dlen;
1444 : :
1445 : 0 : desc->op_addr = op;
1446 : :
1447 : 0 : return 0;
1448 : : }
1449 : :
1450 : : static inline int
1451 : 0 : acc100_dma_desc_ld_fill(struct rte_bbdev_dec_op *op,
1452 : : struct acc_dma_req_desc *desc,
1453 : : struct rte_mbuf **input, struct rte_mbuf *h_output,
1454 : : uint32_t *in_offset, uint32_t *h_out_offset,
1455 : : uint32_t *h_out_length, uint32_t *mbuf_total_left,
1456 : : uint32_t *seg_total_left,
1457 : : struct acc_fcw_ld *fcw)
1458 : : {
1459 : : struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1460 : : int next_triplet = 1; /* FCW already done */
1461 : : uint32_t input_length;
1462 : : uint16_t output_length, crc24_overlap = 0;
1463 : : uint16_t sys_cols, K, h_p_size, h_np_size;
1464 [ # # ]: 0 : bool h_comp = check_bit(dec->op_flags,
1465 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION);
1466 : :
1467 : : acc_header_init(desc);
1468 : :
1469 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
1470 : : RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
1471 : : crc24_overlap = 24;
1472 : :
1473 : : /* Compute some LDPC BG lengths */
1474 [ # # ]: 0 : input_length = fcw->rm_e;
1475 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
1476 : : RTE_BBDEV_LDPC_LLR_COMPRESSION))
1477 : 0 : input_length = (input_length * 3 + 3) / 4;
1478 [ # # ]: 0 : sys_cols = (dec->basegraph == 1) ? 22 : 10;
1479 : 0 : K = sys_cols * dec->z_c;
1480 : 0 : output_length = K - dec->n_filler - crc24_overlap;
1481 : :
1482 [ # # # # ]: 0 : if (unlikely((*mbuf_total_left == 0) ||
1483 : : (*mbuf_total_left < input_length))) {
1484 : 0 : rte_bbdev_log(ERR,
1485 : : "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1486 : : *mbuf_total_left, input_length);
1487 : 0 : return -1;
1488 : : }
1489 : :
1490 : 0 : next_triplet = acc_dma_fill_blk_type_in(desc, input,
1491 : : in_offset, input_length,
1492 : : seg_total_left, next_triplet,
1493 : : check_bit(op->ldpc_dec.op_flags,
1494 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER));
1495 : :
1496 [ # # ]: 0 : if (unlikely(next_triplet < 0)) {
1497 : 0 : rte_bbdev_log(ERR,
1498 : : "Mismatch between data to process and mbuf data length in bbdev_op: %p",
1499 : : op);
1500 : 0 : return -1;
1501 : : }
1502 : :
1503 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
1504 : : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1505 : 0 : h_p_size = fcw->hcin_size0 + fcw->hcin_size1;
1506 [ # # ]: 0 : if (h_comp)
1507 : 0 : h_p_size = (h_p_size * 3 + 3) / 4;
1508 : 0 : desc->data_ptrs[next_triplet].address =
1509 : 0 : dec->harq_combined_input.offset;
1510 : 0 : desc->data_ptrs[next_triplet].blen = h_p_size;
1511 : 0 : desc->data_ptrs[next_triplet].blkid = ACC_DMA_BLKID_IN_HARQ;
1512 : 0 : desc->data_ptrs[next_triplet].dma_ext = 1;
1513 : : #ifndef ACC100_EXT_MEM
1514 : : acc_dma_fill_blk_type(
1515 : : desc,
1516 : : op->ldpc_dec.harq_combined_input.data,
1517 : : op->ldpc_dec.harq_combined_input.offset,
1518 : : h_p_size,
1519 : : next_triplet,
1520 : : ACC_DMA_BLKID_IN_HARQ);
1521 : : #endif
1522 : 0 : next_triplet++;
1523 : : }
1524 : :
1525 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1526 : 0 : desc->m2dlen = next_triplet;
1527 : 0 : *mbuf_total_left -= input_length;
1528 : :
1529 [ # # ]: 0 : next_triplet = acc_dma_fill_blk_type(desc, h_output,
1530 : : *h_out_offset, output_length >> 3, next_triplet,
1531 : : ACC_DMA_BLKID_OUT_HARD);
1532 : :
1533 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
1534 : : RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
1535 : : /* Pruned size of the HARQ */
1536 : 0 : h_p_size = fcw->hcout_size0 + fcw->hcout_size1;
1537 : : /* Non-Pruned size of the HARQ */
1538 [ # # ]: 0 : h_np_size = fcw->hcout_offset > 0 ?
1539 : : fcw->hcout_offset + fcw->hcout_size1 :
1540 : : h_p_size;
1541 [ # # ]: 0 : if (h_comp) {
1542 : 0 : h_np_size = (h_np_size * 3 + 3) / 4;
1543 : 0 : h_p_size = (h_p_size * 3 + 3) / 4;
1544 : : }
1545 : 0 : dec->harq_combined_output.length = h_np_size;
1546 : 0 : desc->data_ptrs[next_triplet].address =
1547 : 0 : dec->harq_combined_output.offset;
1548 : 0 : desc->data_ptrs[next_triplet].blen = h_p_size;
1549 : 0 : desc->data_ptrs[next_triplet].blkid = ACC_DMA_BLKID_OUT_HARQ;
1550 : 0 : desc->data_ptrs[next_triplet].dma_ext = 1;
1551 : : #ifndef ACC100_EXT_MEM
1552 : : acc_dma_fill_blk_type(
1553 : : desc,
1554 : : dec->harq_combined_output.data,
1555 : : dec->harq_combined_output.offset,
1556 : : h_p_size,
1557 : : next_triplet,
1558 : : ACC_DMA_BLKID_OUT_HARQ);
1559 : : #endif
1560 : 0 : next_triplet++;
1561 : : }
1562 : :
1563 : 0 : *h_out_length = output_length >> 3;
1564 : 0 : dec->hard_output.length += *h_out_length;
1565 : 0 : *h_out_offset += *h_out_length;
1566 : 0 : desc->data_ptrs[next_triplet - 1].last = 1;
1567 : 0 : desc->d2mlen = next_triplet - desc->m2dlen;
1568 : :
1569 : 0 : desc->op_addr = op;
1570 : :
1571 : 0 : return 0;
1572 : : }
1573 : :
1574 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
1575 : : /* Validates turbo encoder parameters */
1576 : : static inline int
1577 : 0 : validate_enc_op(struct rte_bbdev_enc_op *op, struct acc_queue *q)
1578 : : {
1579 : : struct rte_bbdev_op_turbo_enc *turbo_enc = &op->turbo_enc;
1580 : : struct rte_bbdev_op_enc_turbo_cb_params *cb = NULL;
1581 : : struct rte_bbdev_op_enc_turbo_tb_params *tb = NULL;
1582 : : uint16_t kw, kw_neg, kw_pos;
1583 : :
1584 [ # # ]: 0 : if (!validate_op_required(q))
1585 : : return 0;
1586 : :
1587 [ # # ]: 0 : if (turbo_enc->input.data == NULL) {
1588 : 0 : rte_bbdev_log(ERR, "Invalid input pointer");
1589 : 0 : return -1;
1590 : : }
1591 [ # # ]: 0 : if (turbo_enc->output.data == NULL) {
1592 : 0 : rte_bbdev_log(ERR, "Invalid output pointer");
1593 : 0 : return -1;
1594 : : }
1595 [ # # ]: 0 : if (turbo_enc->rv_index > 3) {
1596 : 0 : rte_bbdev_log(ERR,
1597 : : "rv_index (%u) is out of range 0 <= value <= 3",
1598 : : turbo_enc->rv_index);
1599 : 0 : return -1;
1600 : : }
1601 [ # # ]: 0 : if (turbo_enc->code_block_mode != RTE_BBDEV_TRANSPORT_BLOCK &&
1602 : : turbo_enc->code_block_mode != RTE_BBDEV_CODE_BLOCK) {
1603 : 0 : rte_bbdev_log(ERR,
1604 : : "code_block_mode (%u) is out of range 0 <= value <= 1",
1605 : : turbo_enc->code_block_mode);
1606 : 0 : return -1;
1607 : : }
1608 : :
1609 [ # # ]: 0 : if (unlikely(turbo_enc->input.length == 0)) {
1610 : 0 : rte_bbdev_log(ERR, "input length null");
1611 : 0 : return -1;
1612 : : }
1613 : :
1614 [ # # ]: 0 : if (turbo_enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1615 : : tb = &turbo_enc->tb_params;
1616 : 0 : if ((tb->k_neg < RTE_BBDEV_TURBO_MIN_CB_SIZE
1617 [ # # ]: 0 : || tb->k_neg > RTE_BBDEV_TURBO_MAX_CB_SIZE)
1618 [ # # ]: 0 : && tb->c_neg > 0) {
1619 : 0 : rte_bbdev_log(ERR,
1620 : : "k_neg (%u) is out of range %u <= value <= %u",
1621 : : tb->k_neg, RTE_BBDEV_TURBO_MIN_CB_SIZE,
1622 : : RTE_BBDEV_TURBO_MAX_CB_SIZE);
1623 : 0 : return -1;
1624 : : }
1625 : 0 : if (tb->k_pos < RTE_BBDEV_TURBO_MIN_CB_SIZE
1626 [ # # ]: 0 : || tb->k_pos > RTE_BBDEV_TURBO_MAX_CB_SIZE) {
1627 : 0 : rte_bbdev_log(ERR,
1628 : : "k_pos (%u) is out of range %u <= value <= %u",
1629 : : tb->k_pos, RTE_BBDEV_TURBO_MIN_CB_SIZE,
1630 : : RTE_BBDEV_TURBO_MAX_CB_SIZE);
1631 : 0 : return -1;
1632 : : }
1633 [ # # ]: 0 : if (unlikely(tb->c_neg > 0)) {
1634 : 0 : rte_bbdev_log(ERR,
1635 : : "c_neg (%u) expected to be null",
1636 : : tb->c_neg);
1637 : 0 : return -1;
1638 : : }
1639 [ # # ]: 0 : if (tb->c < 1 || tb->c > RTE_BBDEV_TURBO_MAX_CODE_BLOCKS) {
1640 : 0 : rte_bbdev_log(ERR,
1641 : : "c (%u) is out of range 1 <= value <= %u",
1642 : : tb->c, RTE_BBDEV_TURBO_MAX_CODE_BLOCKS);
1643 : 0 : return -1;
1644 : : }
1645 [ # # ]: 0 : if (tb->cab > tb->c) {
1646 : 0 : rte_bbdev_log(ERR,
1647 : : "cab (%u) is greater than c (%u)",
1648 : : tb->cab, tb->c);
1649 : 0 : return -1;
1650 : : }
1651 [ # # # # ]: 0 : if ((tb->ea < RTE_BBDEV_TURBO_MIN_CB_SIZE || (tb->ea % 2))
1652 [ # # ]: 0 : && tb->r < tb->cab) {
1653 : 0 : rte_bbdev_log(ERR,
1654 : : "ea (%u) is less than %u or it is not even",
1655 : : tb->ea, RTE_BBDEV_TURBO_MIN_CB_SIZE);
1656 : 0 : return -1;
1657 : : }
1658 [ # # # # ]: 0 : if ((tb->eb < RTE_BBDEV_TURBO_MIN_CB_SIZE || (tb->eb % 2))
1659 [ # # ]: 0 : && tb->c > tb->cab) {
1660 : 0 : rte_bbdev_log(ERR,
1661 : : "eb (%u) is less than %u or it is not even",
1662 : : tb->eb, RTE_BBDEV_TURBO_MIN_CB_SIZE);
1663 : 0 : return -1;
1664 : : }
1665 : :
1666 : 0 : kw_neg = 3 * RTE_ALIGN_CEIL(tb->k_neg + 4,
1667 : : RTE_BBDEV_TURBO_C_SUBBLOCK);
1668 [ # # # # ]: 0 : if (tb->ncb_neg < tb->k_neg || tb->ncb_neg > kw_neg) {
1669 : 0 : rte_bbdev_log(ERR,
1670 : : "ncb_neg (%u) is out of range (%u) k_neg <= value <= (%u) kw_neg",
1671 : : tb->ncb_neg, tb->k_neg, kw_neg);
1672 : 0 : return -1;
1673 : : }
1674 : :
1675 : 0 : kw_pos = 3 * RTE_ALIGN_CEIL(tb->k_pos + 4,
1676 : : RTE_BBDEV_TURBO_C_SUBBLOCK);
1677 [ # # # # ]: 0 : if (tb->ncb_pos < tb->k_pos || tb->ncb_pos > kw_pos) {
1678 : 0 : rte_bbdev_log(ERR,
1679 : : "ncb_pos (%u) is out of range (%u) k_pos <= value <= (%u) kw_pos",
1680 : : tb->ncb_pos, tb->k_pos, kw_pos);
1681 : 0 : return -1;
1682 : : }
1683 [ # # ]: 0 : if (tb->r > (tb->c - 1)) {
1684 : 0 : rte_bbdev_log(ERR,
1685 : : "r (%u) is greater than c - 1 (%u)",
1686 : : tb->r, tb->c - 1);
1687 : 0 : return -1;
1688 : : }
1689 : : } else {
1690 : : cb = &turbo_enc->cb_params;
1691 : 0 : if (cb->k < RTE_BBDEV_TURBO_MIN_CB_SIZE
1692 [ # # ]: 0 : || cb->k > RTE_BBDEV_TURBO_MAX_CB_SIZE) {
1693 : 0 : rte_bbdev_log(ERR,
1694 : : "k (%u) is out of range %u <= value <= %u",
1695 : : cb->k, RTE_BBDEV_TURBO_MIN_CB_SIZE,
1696 : : RTE_BBDEV_TURBO_MAX_CB_SIZE);
1697 : 0 : return -1;
1698 : : }
1699 : :
1700 [ # # # # ]: 0 : if (cb->e < RTE_BBDEV_TURBO_MIN_CB_SIZE || (cb->e % 2)) {
1701 : 0 : rte_bbdev_log(ERR,
1702 : : "e (%u) is less than %u or it is not even",
1703 : : cb->e, RTE_BBDEV_TURBO_MIN_CB_SIZE);
1704 : 0 : return -1;
1705 : : }
1706 : :
1707 : 0 : kw = RTE_ALIGN_CEIL(cb->k + 4, RTE_BBDEV_TURBO_C_SUBBLOCK) * 3;
1708 [ # # # # ]: 0 : if (cb->ncb < cb->k || cb->ncb > kw) {
1709 : 0 : rte_bbdev_log(ERR,
1710 : : "ncb (%u) is out of range (%u) k <= value <= (%u) kw",
1711 : : cb->ncb, cb->k, kw);
1712 : 0 : return -1;
1713 : : }
1714 : : }
1715 : :
1716 : : return 0;
1717 : : }
1718 : : /* Validates LDPC encoder parameters */
1719 : : static inline int
1720 : 0 : validate_ldpc_enc_op(struct rte_bbdev_enc_op *op, struct acc_queue *q)
1721 : : {
1722 : : struct rte_bbdev_op_ldpc_enc *ldpc_enc = &op->ldpc_enc;
1723 : : int K, N, q_m, crc24;
1724 : :
1725 [ # # ]: 0 : if (!validate_op_required(q))
1726 : : return 0;
1727 : :
1728 [ # # ]: 0 : if (ldpc_enc->input.data == NULL) {
1729 : 0 : rte_bbdev_log(ERR, "Invalid input pointer");
1730 : 0 : return -1;
1731 : : }
1732 [ # # ]: 0 : if (ldpc_enc->output.data == NULL) {
1733 : 0 : rte_bbdev_log(ERR, "Invalid output pointer");
1734 : 0 : return -1;
1735 : : }
1736 [ # # ]: 0 : if (ldpc_enc->input.length == 0) {
1737 : 0 : rte_bbdev_log(ERR, "CB size (%u) is null", ldpc_enc->input.length);
1738 : 0 : return -1;
1739 : : }
1740 [ # # ]: 0 : if ((ldpc_enc->basegraph > 2) || (ldpc_enc->basegraph == 0)) {
1741 : 0 : rte_bbdev_log(ERR, "BG (%u) is out of range 1 <= value <= 2", ldpc_enc->basegraph);
1742 : 0 : return -1;
1743 : : }
1744 [ # # ]: 0 : if (ldpc_enc->rv_index > 3) {
1745 : 0 : rte_bbdev_log(ERR,
1746 : : "rv_index (%u) is out of range 0 <= value <= 3",
1747 : : ldpc_enc->rv_index);
1748 : 0 : return -1;
1749 : : }
1750 [ # # ]: 0 : if (ldpc_enc->code_block_mode > RTE_BBDEV_CODE_BLOCK) {
1751 : 0 : rte_bbdev_log(ERR,
1752 : : "code_block_mode (%u) is out of range 0 <= value <= 1",
1753 : : ldpc_enc->code_block_mode);
1754 : 0 : return -1;
1755 : : }
1756 [ # # ]: 0 : if (ldpc_enc->z_c > ACC_MAX_ZC) {
1757 : 0 : rte_bbdev_log(ERR, "Zc (%u) is out of range", ldpc_enc->z_c);
1758 : 0 : return -1;
1759 : : }
1760 : :
1761 [ # # ]: 0 : K = (ldpc_enc->basegraph == 1 ? 22 : 10) * ldpc_enc->z_c;
1762 [ # # ]: 0 : N = (ldpc_enc->basegraph == 1 ? ACC_N_ZC_1 : ACC_N_ZC_2) * ldpc_enc->z_c;
1763 : 0 : q_m = ldpc_enc->q_m;
1764 : : crc24 = 0;
1765 : :
1766 [ # # ]: 0 : if (check_bit(op->ldpc_enc.op_flags,
1767 [ # # ]: 0 : RTE_BBDEV_LDPC_CRC_24A_ATTACH) ||
1768 : : check_bit(op->ldpc_enc.op_flags,
1769 : : RTE_BBDEV_LDPC_CRC_24B_ATTACH))
1770 : : crc24 = 24;
1771 [ # # ]: 0 : if ((K - ldpc_enc->n_filler) % 8 > 0) {
1772 : 0 : rte_bbdev_log(ERR, "K - F not byte aligned %u", K - ldpc_enc->n_filler);
1773 : 0 : return -1;
1774 : : }
1775 [ # # ]: 0 : if (ldpc_enc->n_filler > (K - 2 * ldpc_enc->z_c)) {
1776 : 0 : rte_bbdev_log(ERR, "K - F invalid %u %u", K, ldpc_enc->n_filler);
1777 : 0 : return -1;
1778 : : }
1779 [ # # # # ]: 0 : if ((ldpc_enc->n_cb > N) || (ldpc_enc->n_cb <= K)) {
1780 : 0 : rte_bbdev_log(ERR, "Ncb (%u) is out of range K %d N %d", ldpc_enc->n_cb, K, N);
1781 : 0 : return -1;
1782 : : }
1783 [ # # ]: 0 : if (!check_bit(op->ldpc_enc.op_flags,
1784 [ # # ]: 0 : RTE_BBDEV_LDPC_INTERLEAVER_BYPASS) &&
1785 [ # # # # ]: 0 : ((q_m == 0) || ((q_m > 2) && ((q_m % 2) == 1))
1786 [ # # ]: 0 : || (q_m > 8))) {
1787 : 0 : rte_bbdev_log(ERR, "Qm (%u) is out of range", ldpc_enc->q_m);
1788 : 0 : return -1;
1789 : : }
1790 [ # # ]: 0 : if (ldpc_enc->code_block_mode == RTE_BBDEV_CODE_BLOCK) {
1791 [ # # ]: 0 : if (ldpc_enc->cb_params.e == 0) {
1792 : 0 : rte_bbdev_log(ERR, "E is null");
1793 : 0 : return -1;
1794 : : }
1795 [ # # ]: 0 : if (q_m > 0) {
1796 [ # # ]: 0 : if (ldpc_enc->cb_params.e % q_m > 0) {
1797 : 0 : rte_bbdev_log(ERR, "E not multiple of qm %d", q_m);
1798 : 0 : return -1;
1799 : : }
1800 : : }
1801 [ # # # # ]: 0 : if ((ldpc_enc->z_c <= 11) && (ldpc_enc->cb_params.e > 3456)) {
1802 : 0 : rte_bbdev_log(ERR, "E too large for small block");
1803 : 0 : return -1;
1804 : : }
1805 [ # # ]: 0 : if (ldpc_enc->input.length >
1806 : : RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) {
1807 : 0 : rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
1808 : : ldpc_enc->input.length,
1809 : : RTE_BBDEV_LDPC_MAX_CB_SIZE);
1810 : 0 : return -1;
1811 : : }
1812 [ # # ]: 0 : if (K < (int) (ldpc_enc->input.length * 8 + ldpc_enc->n_filler) + crc24) {
1813 : 0 : rte_bbdev_log(ERR,
1814 : : "K and F not matching input size %u %u %u",
1815 : : K, ldpc_enc->n_filler,
1816 : : ldpc_enc->input.length);
1817 : 0 : return -1;
1818 : : }
1819 : : } else {
1820 [ # # ]: 0 : if ((ldpc_enc->tb_params.c == 0) ||
1821 [ # # ]: 0 : (ldpc_enc->tb_params.ea == 0) ||
1822 [ # # ]: 0 : (ldpc_enc->tb_params.eb == 0)) {
1823 : 0 : rte_bbdev_log(ERR, "TB parameter is null");
1824 : 0 : return -1;
1825 : : }
1826 [ # # ]: 0 : if (q_m > 0) {
1827 [ # # ]: 0 : if ((ldpc_enc->tb_params.ea % q_m > 0) ||
1828 [ # # ]: 0 : (ldpc_enc->tb_params.eb % q_m > 0)) {
1829 : 0 : rte_bbdev_log(ERR, "E not multiple of qm %d", q_m);
1830 : 0 : return -1;
1831 : : }
1832 : : }
1833 [ # # # # ]: 0 : if ((ldpc_enc->z_c <= 11) && (RTE_MAX(ldpc_enc->tb_params.ea,
1834 : : ldpc_enc->tb_params.eb) > 3456)) {
1835 : 0 : rte_bbdev_log(ERR, "E too large for small block");
1836 : 0 : return -1;
1837 : : }
1838 : : }
1839 : : return 0;
1840 : : }
1841 : :
1842 : : /* Validates LDPC decoder parameters */
1843 : : static inline int
1844 : 0 : validate_ldpc_dec_op(struct rte_bbdev_dec_op *op, struct acc_queue *q)
1845 : : {
1846 : : struct rte_bbdev_op_ldpc_dec *ldpc_dec = &op->ldpc_dec;
1847 : : int K, N, q_m;
1848 : : uint32_t min_harq_input;
1849 : :
1850 [ # # ]: 0 : if (!validate_op_required(q))
1851 : : return 0;
1852 : :
1853 [ # # ]: 0 : if (ldpc_dec->input.data == NULL) {
1854 : 0 : rte_bbdev_log(ERR, "Invalid input pointer");
1855 : 0 : return -1;
1856 : : }
1857 [ # # ]: 0 : if (ldpc_dec->hard_output.data == NULL) {
1858 : 0 : rte_bbdev_log(ERR, "Invalid output pointer");
1859 : 0 : return -1;
1860 : : }
1861 [ # # ]: 0 : if (ldpc_dec->input.length == 0) {
1862 : 0 : rte_bbdev_log(ERR, "input is null");
1863 : 0 : return -1;
1864 : : }
1865 [ # # ]: 0 : if ((ldpc_dec->basegraph > 2) || (ldpc_dec->basegraph == 0)) {
1866 : 0 : rte_bbdev_log(ERR, "BG (%u) is out of range 1 <= value <= 2", ldpc_dec->basegraph);
1867 : 0 : return -1;
1868 : : }
1869 [ # # ]: 0 : if (ldpc_dec->iter_max == 0) {
1870 : 0 : rte_bbdev_log(ERR, "iter_max (%u) is equal to 0", ldpc_dec->iter_max);
1871 : 0 : return -1;
1872 : : }
1873 [ # # ]: 0 : if (ldpc_dec->rv_index > 3) {
1874 : 0 : rte_bbdev_log(ERR,
1875 : : "rv_index (%u) is out of range 0 <= value <= 3",
1876 : : ldpc_dec->rv_index);
1877 : 0 : return -1;
1878 : : }
1879 [ # # ]: 0 : if (ldpc_dec->code_block_mode > RTE_BBDEV_CODE_BLOCK) {
1880 : 0 : rte_bbdev_log(ERR,
1881 : : "code_block_mode (%u) is out of range 0 <= value <= 1",
1882 : : ldpc_dec->code_block_mode);
1883 : 0 : return -1;
1884 : : }
1885 : : /* Check Zc is valid value. */
1886 [ # # ]: 0 : if ((ldpc_dec->z_c > ACC_MAX_ZC) || (ldpc_dec->z_c < 2)) {
1887 : 0 : rte_bbdev_log(ERR, "Zc (%u) is out of range", ldpc_dec->z_c);
1888 : 0 : return -1;
1889 : : }
1890 [ # # ]: 0 : if (ldpc_dec->z_c > 256) {
1891 [ # # ]: 0 : if ((ldpc_dec->z_c % 32) != 0) {
1892 : 0 : rte_bbdev_log(ERR, "Invalid Zc %d", ldpc_dec->z_c);
1893 : 0 : return -1;
1894 : : }
1895 [ # # ]: 0 : } else if (ldpc_dec->z_c > 128) {
1896 [ # # ]: 0 : if ((ldpc_dec->z_c % 16) != 0) {
1897 : 0 : rte_bbdev_log(ERR, "Invalid Zc %d", ldpc_dec->z_c);
1898 : 0 : return -1;
1899 : : }
1900 [ # # ]: 0 : } else if (ldpc_dec->z_c > 64) {
1901 [ # # ]: 0 : if ((ldpc_dec->z_c % 8) != 0) {
1902 : 0 : rte_bbdev_log(ERR, "Invalid Zc %d", ldpc_dec->z_c);
1903 : 0 : return -1;
1904 : : }
1905 [ # # ]: 0 : } else if (ldpc_dec->z_c > 32) {
1906 [ # # ]: 0 : if ((ldpc_dec->z_c % 4) != 0) {
1907 : 0 : rte_bbdev_log(ERR, "Invalid Zc %d", ldpc_dec->z_c);
1908 : 0 : return -1;
1909 : : }
1910 [ # # ]: 0 : } else if (ldpc_dec->z_c > 16) {
1911 [ # # ]: 0 : if ((ldpc_dec->z_c % 2) != 0) {
1912 : 0 : rte_bbdev_log(ERR, "Invalid Zc %d", ldpc_dec->z_c);
1913 : 0 : return -1;
1914 : : }
1915 : : }
1916 : :
1917 [ # # ]: 0 : K = (ldpc_dec->basegraph == 1 ? 22 : 10) * ldpc_dec->z_c;
1918 [ # # ]: 0 : N = (ldpc_dec->basegraph == 1 ? ACC_N_ZC_1 : ACC_N_ZC_2) * ldpc_dec->z_c;
1919 : 0 : q_m = ldpc_dec->q_m;
1920 : :
1921 [ # # ]: 0 : if (ldpc_dec->n_filler >= K - 2 * ldpc_dec->z_c) {
1922 : 0 : rte_bbdev_log(ERR, "K and F are not compatible %u %u", K, ldpc_dec->n_filler);
1923 : 0 : return -1;
1924 : : }
1925 [ # # # # ]: 0 : if ((ldpc_dec->n_cb > N) || (ldpc_dec->n_cb <= K)) {
1926 : 0 : rte_bbdev_log(ERR, "Ncb (%u) is out of range K %d N %d", ldpc_dec->n_cb, K, N);
1927 : 0 : return -1;
1928 : : }
1929 [ # # # # : 0 : if (((q_m == 0) || ((q_m > 2) && ((q_m % 2) == 1))
# # ]
1930 [ # # ]: 0 : || (q_m > 8))) {
1931 : 0 : rte_bbdev_log(ERR, "Qm (%u) is out of range", ldpc_dec->q_m);
1932 : 0 : return -1;
1933 : : }
1934 [ # # ]: 0 : if (ldpc_dec->code_block_mode == RTE_BBDEV_CODE_BLOCK) {
1935 [ # # ]: 0 : if (ldpc_dec->cb_params.e == 0) {
1936 : 0 : rte_bbdev_log(ERR, "E is null");
1937 : 0 : return -1;
1938 : : }
1939 [ # # ]: 0 : if (ldpc_dec->cb_params.e % q_m > 0) {
1940 : 0 : rte_bbdev_log(ERR, "E not multiple of qm %d", q_m);
1941 : 0 : return -1;
1942 : : }
1943 [ # # ]: 0 : if (ldpc_dec->cb_params.e > 512 * ldpc_dec->z_c) {
1944 : 0 : rte_bbdev_log(ERR, "E too high");
1945 : 0 : return -1;
1946 : : }
1947 : : } else {
1948 [ # # ]: 0 : if ((ldpc_dec->tb_params.c == 0) ||
1949 [ # # ]: 0 : (ldpc_dec->tb_params.ea == 0) ||
1950 [ # # ]: 0 : (ldpc_dec->tb_params.eb == 0)) {
1951 : 0 : rte_bbdev_log(ERR, "TB parameter is null");
1952 : 0 : return -1;
1953 : : }
1954 [ # # ]: 0 : if ((ldpc_dec->tb_params.ea % q_m > 0) ||
1955 [ # # ]: 0 : (ldpc_dec->tb_params.eb % q_m > 0)) {
1956 : 0 : rte_bbdev_log(ERR, "E not multiple of qm %d", q_m);
1957 : 0 : return -1;
1958 : : }
1959 [ # # # # ]: 0 : if ((ldpc_dec->tb_params.ea > 512 * ldpc_dec->z_c) ||
1960 : : (ldpc_dec->tb_params.eb > 512 * ldpc_dec->z_c)) {
1961 : 0 : rte_bbdev_log(ERR, "E too high");
1962 : 0 : return -1;
1963 : : }
1964 : : }
1965 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_DECODE_BYPASS)) {
1966 : 0 : rte_bbdev_log(ERR, "Avoid LDPC Decode bypass");
1967 : 0 : return -1;
1968 : : }
1969 : :
1970 : : /* Avoid HARQ compression for small block size */
1971 [ # # # # ]: 0 : if ((check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION)) && (K < 2048))
1972 : 0 : op->ldpc_dec.op_flags ^= RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION;
1973 : :
1974 [ # # ]: 0 : min_harq_input = check_bit(op->ldpc_dec.op_flags,
1975 [ # # ]: 0 : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION) ? 256 : 64;
1976 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
1977 : 0 : RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE) &&
1978 [ # # ]: 0 : ldpc_dec->harq_combined_input.length <
1979 : : min_harq_input) {
1980 : 0 : rte_bbdev_log(ERR, "HARQ input size is too small %d < %d",
1981 : : ldpc_dec->harq_combined_input.length,
1982 : : min_harq_input);
1983 : 0 : return -1;
1984 : : }
1985 : :
1986 : : /* Enforce in-range HARQ input size */
1987 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1988 : 0 : uint32_t max_harq_input = RTE_ALIGN_CEIL(ldpc_dec->n_cb - ldpc_dec->n_filler, 64);
1989 : :
1990 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION))
1991 : 0 : max_harq_input = max_harq_input * 3 / 4;
1992 : :
1993 [ # # ]: 0 : if (ldpc_dec->harq_combined_input.length > max_harq_input) {
1994 : 0 : rte_bbdev_log(ERR,
1995 : : "HARQ input size out of range %d > %d, Ncb %d F %d K %d N %d",
1996 : : ldpc_dec->harq_combined_input.length,
1997 : : max_harq_input, ldpc_dec->n_cb,
1998 : : ldpc_dec->n_filler, K, N);
1999 : : /* Fallback to flush HARQ combine */
2000 : 0 : ldpc_dec->harq_combined_input.length = 0;
2001 : :
2002 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE))
2003 : 0 : op->ldpc_dec.op_flags ^= RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE;
2004 : : }
2005 : : }
2006 : :
2007 : : #ifdef ACC100_EXT_MEM
2008 : : /* Enforce in-range HARQ offset */
2009 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
2010 [ # # ]: 0 : if ((op->ldpc_dec.harq_combined_input.offset >> 10) >= q->d->ddr_size) {
2011 : 0 : rte_bbdev_log(ERR,
2012 : : "HARQin offset out of range %d > %d",
2013 : : op->ldpc_dec.harq_combined_input.offset,
2014 : : q->d->ddr_size);
2015 : 0 : return -1;
2016 : : }
2017 [ # # ]: 0 : if ((op->ldpc_dec.harq_combined_input.offset & 0x3FF) > 0) {
2018 : 0 : rte_bbdev_log(ERR,
2019 : : "HARQin offset not aligned on 1kB %d",
2020 : : op->ldpc_dec.harq_combined_input.offset);
2021 : 0 : return -1;
2022 : : }
2023 : : }
2024 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
2025 [ # # ]: 0 : if ((op->ldpc_dec.harq_combined_output.offset >> 10) >= q->d->ddr_size) {
2026 : 0 : rte_bbdev_log(ERR,
2027 : : "HARQout offset out of range %d > %d",
2028 : : op->ldpc_dec.harq_combined_output.offset,
2029 : : q->d->ddr_size);
2030 : 0 : return -1;
2031 : : }
2032 [ # # ]: 0 : if ((op->ldpc_dec.harq_combined_output.offset & 0x3FF) > 0) {
2033 : 0 : rte_bbdev_log(ERR,
2034 : : "HARQout offset not aligned on 1kB %d",
2035 : : op->ldpc_dec.harq_combined_output.offset);
2036 : 0 : return -1;
2037 : : }
2038 : : }
2039 : : #endif
2040 : :
2041 : : return 0;
2042 : : }
2043 : : #endif
2044 : :
2045 : : /* Enqueue one encode operations for ACC100 device in CB mode */
2046 : : static inline int
2047 : 0 : enqueue_enc_one_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2048 : : uint16_t total_enqueued_cbs)
2049 : : {
2050 : : union acc_dma_desc *desc = NULL;
2051 : : int ret;
2052 : : uint32_t in_offset, out_offset, out_length, mbuf_total_left,
2053 : : seg_total_left;
2054 : : struct rte_mbuf *input, *output_head, *output;
2055 : :
2056 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2057 : : /* Validate op structure */
2058 [ # # ]: 0 : if (validate_enc_op(op, q) == -1) {
2059 : 0 : rte_bbdev_log(ERR, "Turbo encoder validation rejected");
2060 : 0 : return -EINVAL;
2061 : : }
2062 : : #endif
2063 : :
2064 : : desc = acc_desc(q, total_enqueued_cbs);
2065 : 0 : acc_fcw_te_fill(op, &desc->req.fcw_te);
2066 : :
2067 : 0 : input = op->turbo_enc.input.data;
2068 : 0 : output_head = output = op->turbo_enc.output.data;
2069 : 0 : in_offset = op->turbo_enc.input.offset;
2070 : 0 : out_offset = op->turbo_enc.output.offset;
2071 : 0 : out_length = 0;
2072 : 0 : mbuf_total_left = op->turbo_enc.input.length;
2073 : 0 : seg_total_left = rte_pktmbuf_data_len(op->turbo_enc.input.data)
2074 : 0 : - in_offset;
2075 : :
2076 : 0 : ret = acc_dma_desc_te_fill(op, &desc->req, &input, output,
2077 : : &in_offset, &out_offset, &out_length, &mbuf_total_left,
2078 : : &seg_total_left, 0);
2079 : :
2080 [ # # ]: 0 : if (unlikely(ret < 0))
2081 : : return ret;
2082 : :
2083 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2084 : :
2085 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2086 : : rte_memdump(stderr, "FCW", &desc->req.fcw_te,
2087 : : sizeof(desc->req.fcw_te) - 8);
2088 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2089 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
2090 : : return -EINVAL;
2091 : : #endif
2092 : : /* One CB (one op) was successfully prepared to enqueue */
2093 : : return 1;
2094 : : }
2095 : :
2096 : : /* Enqueue one encode operations for ACC100 device in CB mode */
2097 : : static inline int
2098 : 0 : enqueue_ldpc_enc_n_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op **ops,
2099 : : uint16_t total_enqueued_descs, int16_t num)
2100 : : {
2101 : : union acc_dma_desc *desc = NULL;
2102 : : uint32_t out_length;
2103 : : struct rte_mbuf *output_head, *output;
2104 : : int i, next_triplet;
2105 : : uint16_t in_length_in_bytes;
2106 : 0 : struct rte_bbdev_op_ldpc_enc *enc = &ops[0]->ldpc_enc;
2107 : :
2108 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2109 : : /* Validate op structure */
2110 [ # # ]: 0 : if (validate_ldpc_enc_op(ops[0], q) == -1) {
2111 : 0 : rte_bbdev_log(ERR, "LDPC encoder validation rejected");
2112 : 0 : return -EINVAL;
2113 : : }
2114 : : #endif
2115 : :
2116 : : desc = acc_desc(q, total_enqueued_descs);
2117 : 0 : acc_fcw_le_fill(ops[0], &desc->req.fcw_le, num, 0);
2118 : :
2119 : : /** This could be done at polling */
2120 : : acc_header_init(&desc->req);
2121 : 0 : desc->req.numCBs = num;
2122 : :
2123 [ # # ]: 0 : in_length_in_bytes = pad_le_in(ops[0]->ldpc_enc.input.data->data_len, q);
2124 : 0 : out_length = (enc->cb_params.e + 7) >> 3;
2125 : 0 : desc->req.m2dlen = 1 + num;
2126 : 0 : desc->req.d2mlen = num;
2127 : : next_triplet = 1;
2128 : :
2129 [ # # ]: 0 : for (i = 0; i < num; i++) {
2130 : 0 : desc->req.data_ptrs[next_triplet].address =
2131 [ # # ]: 0 : rte_pktmbuf_iova_offset(ops[i]->ldpc_enc.input.data, 0);
2132 : 0 : desc->req.data_ptrs[next_triplet].blen = in_length_in_bytes;
2133 : 0 : next_triplet++;
2134 : 0 : desc->req.data_ptrs[next_triplet].address =
2135 : 0 : rte_pktmbuf_iova_offset(
2136 : : ops[i]->ldpc_enc.output.data, 0);
2137 : 0 : desc->req.data_ptrs[next_triplet].blen = out_length;
2138 : 0 : next_triplet++;
2139 : 0 : ops[i]->ldpc_enc.output.length = out_length;
2140 : 0 : output_head = output = ops[i]->ldpc_enc.output.data;
2141 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2142 : 0 : output->data_len = out_length;
2143 : : }
2144 : :
2145 : 0 : desc->req.op_addr = ops[0];
2146 : : /* Keep track of pointers even when multiplexed in single descriptor */
2147 : 0 : struct acc_ptrs *context_ptrs = q->companion_ring_addr
2148 : 0 : + acc_desc_idx(q, total_enqueued_descs);
2149 [ # # ]: 0 : for (i = 0; i < num; i++)
2150 : 0 : context_ptrs->ptr[i].op_addr = ops[i];
2151 : :
2152 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2153 : : rte_memdump(stderr, "FCW", &desc->req.fcw_le,
2154 : : sizeof(desc->req.fcw_le) - 8);
2155 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2156 : : #endif
2157 : :
2158 : : /* One CB (one op) was successfully prepared to enqueue */
2159 : : return num;
2160 : : }
2161 : :
2162 : : /* Enqueue one encode operations for ACC100 device for a partial TB
2163 : : * all codes blocks have same configuration multiplexed on the same descriptor.
2164 : : */
2165 : : static inline void
2166 : 0 : enqueue_ldpc_enc_part_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2167 : : uint16_t total_enqueued_descs, int16_t num_cbs, uint32_t e,
2168 : : uint16_t in_len_bytes, uint32_t out_len_bytes, uint32_t *in_offset,
2169 : : uint32_t *out_offset)
2170 : : {
2171 : : union acc_dma_desc *desc = NULL;
2172 : : struct rte_mbuf *output_head, *output;
2173 : : int i, next_triplet;
2174 : : struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
2175 : :
2176 : : desc = acc_desc(q, total_enqueued_descs);
2177 : 0 : acc_fcw_le_fill(op, &desc->req.fcw_le, num_cbs, e);
2178 : :
2179 : : /* This could be done at polling. */
2180 : : acc_header_init(&desc->req);
2181 : 0 : desc->req.numCBs = num_cbs;
2182 : :
2183 : 0 : desc->req.m2dlen = 1 + num_cbs;
2184 : 0 : desc->req.d2mlen = num_cbs;
2185 : : next_triplet = 1;
2186 : :
2187 [ # # ]: 0 : for (i = 0; i < num_cbs; i++) {
2188 : 0 : desc->req.data_ptrs[next_triplet].address =
2189 [ # # ]: 0 : rte_pktmbuf_iova_offset(enc->input.data, *in_offset);
2190 : 0 : *in_offset += in_len_bytes;
2191 : 0 : desc->req.data_ptrs[next_triplet].blen = in_len_bytes;
2192 : 0 : next_triplet++;
2193 : 0 : desc->req.data_ptrs[next_triplet].address =
2194 : 0 : rte_pktmbuf_iova_offset(enc->output.data, *out_offset);
2195 : 0 : *out_offset += out_len_bytes;
2196 : 0 : desc->req.data_ptrs[next_triplet].blen = out_len_bytes;
2197 : 0 : next_triplet++;
2198 : 0 : enc->output.length += out_len_bytes;
2199 : : output_head = output = enc->output.data;
2200 [ # # ]: 0 : mbuf_append(output_head, output, out_len_bytes);
2201 : : }
2202 : :
2203 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2204 : : rte_memdump(stderr, "FCW", &desc->req.fcw_le,
2205 : : sizeof(desc->req.fcw_le) - 8);
2206 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2207 : : #endif
2208 : :
2209 : 0 : }
2210 : :
2211 : : /* Enqueue one encode operations for ACC100 device in CB mode */
2212 : : static inline int
2213 : 0 : enqueue_ldpc_enc_one_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2214 : : uint16_t total_enqueued_cbs)
2215 : : {
2216 : : union acc_dma_desc *desc = NULL;
2217 : : int ret;
2218 : : uint32_t in_offset, out_offset, out_length, mbuf_total_left,
2219 : : seg_total_left;
2220 : : struct rte_mbuf *input, *output_head, *output;
2221 : :
2222 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2223 : : /* Validate op structure */
2224 [ # # ]: 0 : if (validate_ldpc_enc_op(op, q) == -1) {
2225 : 0 : rte_bbdev_log(ERR, "LDPC encoder validation rejected");
2226 : 0 : return -EINVAL;
2227 : : }
2228 : : #endif
2229 : :
2230 : : desc = acc_desc(q, total_enqueued_cbs);
2231 : 0 : acc_fcw_le_fill(op, &desc->req.fcw_le, 1, 0);
2232 : :
2233 : 0 : input = op->ldpc_enc.input.data;
2234 : 0 : output_head = output = op->ldpc_enc.output.data;
2235 : 0 : in_offset = op->ldpc_enc.input.offset;
2236 : 0 : out_offset = op->ldpc_enc.output.offset;
2237 : 0 : out_length = 0;
2238 : 0 : mbuf_total_left = op->ldpc_enc.input.length;
2239 : 0 : seg_total_left = rte_pktmbuf_data_len(op->ldpc_enc.input.data)
2240 : 0 : - in_offset;
2241 : :
2242 : 0 : ret = acc100_dma_desc_le_fill(op, &desc->req, &input, output,
2243 : : &in_offset, &out_offset, &out_length, &mbuf_total_left,
2244 : : &seg_total_left, q);
2245 : :
2246 [ # # ]: 0 : if (unlikely(ret < 0))
2247 : : return ret;
2248 : :
2249 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2250 : :
2251 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2252 : : rte_memdump(stderr, "FCW", &desc->req.fcw_le,
2253 : : sizeof(desc->req.fcw_le) - 8);
2254 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2255 : :
2256 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
2257 : : return -EINVAL;
2258 : : #endif
2259 : : /* One CB (one op) was successfully prepared to enqueue */
2260 : : return 1;
2261 : : }
2262 : :
2263 : :
2264 : : /* Enqueue one encode operations for ACC100 device in TB mode. */
2265 : : static inline int
2266 : 0 : enqueue_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2267 : : uint16_t total_enqueued_cbs, uint8_t cbs_in_tb)
2268 : : {
2269 : : union acc_dma_desc *desc = NULL;
2270 : : int ret;
2271 : : uint8_t r, c;
2272 : : uint32_t in_offset, out_offset, out_length, mbuf_total_left,
2273 : : seg_total_left;
2274 : : struct rte_mbuf *input, *output_head, *output;
2275 : : uint16_t desc_idx, current_enqueued_cbs = 0;
2276 : : uint64_t fcw_offset;
2277 : :
2278 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2279 : : /* Validate op structure */
2280 [ # # ]: 0 : if (validate_enc_op(op, q) == -1) {
2281 : 0 : rte_bbdev_log(ERR, "Turbo encoder validation rejected");
2282 : 0 : return -EINVAL;
2283 : : }
2284 : : #endif
2285 : :
2286 : : desc_idx = acc_desc_idx(q, total_enqueued_cbs);
2287 : 0 : desc = q->ring_addr + desc_idx;
2288 : 0 : fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
2289 : 0 : acc_fcw_te_fill(op, &desc->req.fcw_te);
2290 : :
2291 : 0 : input = op->turbo_enc.input.data;
2292 : 0 : output_head = output = op->turbo_enc.output.data;
2293 : 0 : in_offset = op->turbo_enc.input.offset;
2294 : 0 : out_offset = op->turbo_enc.output.offset;
2295 : 0 : out_length = 0;
2296 : 0 : mbuf_total_left = op->turbo_enc.input.length;
2297 : :
2298 : 0 : c = op->turbo_enc.tb_params.c;
2299 : 0 : r = op->turbo_enc.tb_params.r;
2300 : :
2301 [ # # ]: 0 : while (mbuf_total_left > 0 && r < c) {
2302 [ # # ]: 0 : if (unlikely(input == NULL)) {
2303 : 0 : rte_bbdev_log(ERR, "Not enough input segment");
2304 : 0 : return -EINVAL;
2305 : : }
2306 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2307 : : /* Set up DMA descriptor */
2308 : : desc = acc_desc(q, total_enqueued_cbs);
2309 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
2310 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_TE_BLEN;
2311 : :
2312 : 0 : ret = acc_dma_desc_te_fill(op, &desc->req, &input, output,
2313 : : &in_offset, &out_offset, &out_length,
2314 : : &mbuf_total_left, &seg_total_left, r);
2315 [ # # ]: 0 : if (unlikely(ret < 0))
2316 : 0 : return ret;
2317 [ # # ]: 0 : mbuf_append(output_head, output, out_length);
2318 : :
2319 : : /* Set total number of CBs in TB */
2320 : 0 : desc->req.cbs_in_tb = cbs_in_tb;
2321 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2322 : : rte_memdump(stderr, "FCW", &desc->req.fcw_te,
2323 : : sizeof(desc->req.fcw_te) - 8);
2324 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2325 : : #endif
2326 : :
2327 [ # # ]: 0 : if (seg_total_left == 0) {
2328 : : /* Go to the next mbuf */
2329 : 0 : input = input->next;
2330 : 0 : in_offset = 0;
2331 : 0 : output = output->next;
2332 : 0 : out_offset = 0;
2333 : : }
2334 : :
2335 : 0 : total_enqueued_cbs++;
2336 : 0 : current_enqueued_cbs++;
2337 : 0 : r++;
2338 : : }
2339 : :
2340 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2341 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
2342 : : return -EINVAL;
2343 : : #endif
2344 : :
2345 : : /* Set SDone on last CB descriptor for TB mode. */
2346 : 0 : desc->req.sdone_enable = 1;
2347 : :
2348 : 0 : return current_enqueued_cbs;
2349 : : }
2350 : :
2351 : : /* Enqueue one encode operations for ACC100 device in TB mode.
2352 : : * returns the number of descs used.
2353 : : */
2354 : : static inline int
2355 : 0 : enqueue_ldpc_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op *op,
2356 : : uint16_t enq_descs, uint8_t cbs_in_tb)
2357 : : {
2358 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2359 [ # # ]: 0 : if (validate_ldpc_enc_op(op, q) == -1) {
2360 : 0 : rte_bbdev_log(ERR, "LDPC encoder validation rejected");
2361 : 0 : return -EINVAL;
2362 : : }
2363 : : #endif
2364 : : uint8_t num_a, num_b;
2365 : 0 : uint8_t r = op->ldpc_enc.tb_params.r;
2366 : 0 : uint8_t cab = op->ldpc_enc.tb_params.cab;
2367 : : union acc_dma_desc *desc;
2368 : : uint16_t init_enq_descs = enq_descs;
2369 [ # # ]: 0 : uint16_t input_len_B = ((op->ldpc_enc.basegraph == 1 ? 22 : 10) *
2370 : 0 : op->ldpc_enc.z_c - op->ldpc_enc.n_filler) >> 3;
2371 : 0 : uint32_t in_offset = 0, out_offset = 0;
2372 : : uint16_t return_descs;
2373 : :
2374 [ # # ]: 0 : if (check_bit(op->ldpc_enc.op_flags, RTE_BBDEV_LDPC_CRC_24B_ATTACH))
2375 : 0 : input_len_B -= 3;
2376 : :
2377 [ # # ]: 0 : if (r < cab) {
2378 : 0 : num_a = cab - r;
2379 : 0 : num_b = cbs_in_tb - cab;
2380 : : } else {
2381 : : num_a = 0;
2382 : 0 : num_b = cbs_in_tb - r;
2383 : : }
2384 : :
2385 [ # # ]: 0 : while (num_a > 0) {
2386 : 0 : uint32_t e = op->ldpc_enc.tb_params.ea;
2387 : 0 : uint32_t out_len_bytes = (e + 7) >> 3;
2388 : 0 : uint8_t enq = RTE_MIN(num_a, ACC_MUX_5GDL_DESC);
2389 : 0 : num_a -= enq;
2390 : 0 : enqueue_ldpc_enc_part_tb(q, op, enq_descs, enq, e, input_len_B,
2391 : : out_len_bytes, &in_offset, &out_offset);
2392 : 0 : enq_descs++;
2393 : : }
2394 [ # # ]: 0 : while (num_b > 0) {
2395 : 0 : uint32_t e = op->ldpc_enc.tb_params.eb;
2396 : 0 : uint32_t out_len_bytes = (e + 7) >> 3;
2397 : 0 : uint8_t enq = RTE_MIN(num_b, ACC_MUX_5GDL_DESC);
2398 : 0 : num_b -= enq;
2399 : 0 : enqueue_ldpc_enc_part_tb(q, op, enq_descs, enq, e, input_len_B,
2400 : : out_len_bytes, &in_offset, &out_offset);
2401 : 0 : enq_descs++;
2402 : : }
2403 : :
2404 : 0 : return_descs = enq_descs - init_enq_descs;
2405 : : /* Keep total number of CBs in first TB. */
2406 : : desc = acc_desc(q, init_enq_descs);
2407 : 0 : desc->req.cbs_in_tb = return_descs; /** Actual number of descriptors. */
2408 : 0 : desc->req.op_addr = op;
2409 : :
2410 : : /* Set SDone on last CB descriptor for TB mode. */
2411 : 0 : desc = acc_desc(q, enq_descs - 1);
2412 : 0 : desc->req.sdone_enable = 1;
2413 : 0 : desc->req.op_addr = op;
2414 : :
2415 : 0 : return return_descs;
2416 : : }
2417 : :
2418 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2419 : : /* Validates turbo decoder parameters */
2420 : : static inline int
2421 : 0 : validate_dec_op(struct rte_bbdev_dec_op *op, struct acc_queue *q)
2422 : : {
2423 : : struct rte_bbdev_op_turbo_dec *turbo_dec = &op->turbo_dec;
2424 : : struct rte_bbdev_op_dec_turbo_cb_params *cb = NULL;
2425 : : struct rte_bbdev_op_dec_turbo_tb_params *tb = NULL;
2426 : :
2427 [ # # ]: 0 : if (!validate_op_required(q))
2428 : : return 0;
2429 : :
2430 [ # # ]: 0 : if (turbo_dec->input.data == NULL) {
2431 : 0 : rte_bbdev_log(ERR, "Invalid input pointer");
2432 : 0 : return -1;
2433 : : }
2434 [ # # ]: 0 : if (turbo_dec->hard_output.data == NULL) {
2435 : 0 : rte_bbdev_log(ERR, "Invalid hard_output pointer");
2436 : 0 : return -1;
2437 : : }
2438 [ # # ]: 0 : if (check_bit(turbo_dec->op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT) &&
2439 [ # # ]: 0 : turbo_dec->soft_output.data == NULL) {
2440 : 0 : rte_bbdev_log(ERR, "Invalid soft_output pointer");
2441 : 0 : return -1;
2442 : : }
2443 [ # # ]: 0 : if (turbo_dec->rv_index > 3) {
2444 : 0 : rte_bbdev_log(ERR,
2445 : : "rv_index (%u) is out of range 0 <= value <= 3",
2446 : : turbo_dec->rv_index);
2447 : 0 : return -1;
2448 : : }
2449 [ # # ]: 0 : if (turbo_dec->iter_min < 1) {
2450 : 0 : rte_bbdev_log(ERR,
2451 : : "iter_min (%u) is less than 1",
2452 : : turbo_dec->iter_min);
2453 : 0 : return -1;
2454 : : }
2455 [ # # ]: 0 : if (turbo_dec->iter_max <= 2) {
2456 : 0 : rte_bbdev_log(ERR,
2457 : : "iter_max (%u) is less than or equal to 2",
2458 : : turbo_dec->iter_max);
2459 : 0 : return -1;
2460 : : }
2461 [ # # ]: 0 : if (turbo_dec->iter_min > turbo_dec->iter_max) {
2462 : 0 : rte_bbdev_log(ERR,
2463 : : "iter_min (%u) is greater than iter_max (%u)",
2464 : : turbo_dec->iter_min, turbo_dec->iter_max);
2465 : 0 : return -1;
2466 : : }
2467 [ # # ]: 0 : if (turbo_dec->code_block_mode != RTE_BBDEV_TRANSPORT_BLOCK &&
2468 : : turbo_dec->code_block_mode != RTE_BBDEV_CODE_BLOCK) {
2469 : 0 : rte_bbdev_log(ERR,
2470 : : "code_block_mode (%u) is out of range 0 <= value <= 1",
2471 : : turbo_dec->code_block_mode);
2472 : 0 : return -1;
2473 : : }
2474 : :
2475 [ # # ]: 0 : if (unlikely(turbo_dec->input.length == 0)) {
2476 : 0 : rte_bbdev_log(ERR, "input length null");
2477 : 0 : return -1;
2478 : : }
2479 : :
2480 [ # # ]: 0 : if (turbo_dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
2481 : : tb = &turbo_dec->tb_params;
2482 : 0 : if ((tb->k_neg < RTE_BBDEV_TURBO_MIN_CB_SIZE
2483 [ # # ]: 0 : || tb->k_neg > RTE_BBDEV_TURBO_MAX_CB_SIZE)
2484 [ # # ]: 0 : && tb->c_neg > 0) {
2485 : 0 : rte_bbdev_log(ERR,
2486 : : "k_neg (%u) is out of range %u <= value <= %u",
2487 : : tb->k_neg, RTE_BBDEV_TURBO_MIN_CB_SIZE,
2488 : : RTE_BBDEV_TURBO_MAX_CB_SIZE);
2489 : 0 : return -1;
2490 : : }
2491 : 0 : if ((tb->k_pos < RTE_BBDEV_TURBO_MIN_CB_SIZE
2492 [ # # ]: 0 : || tb->k_pos > RTE_BBDEV_TURBO_MAX_CB_SIZE)
2493 [ # # ]: 0 : && tb->c > tb->c_neg) {
2494 : 0 : rte_bbdev_log(ERR,
2495 : : "k_pos (%u) is out of range %u <= value <= %u",
2496 : : tb->k_pos, RTE_BBDEV_TURBO_MIN_CB_SIZE,
2497 : : RTE_BBDEV_TURBO_MAX_CB_SIZE);
2498 : 0 : return -1;
2499 : : }
2500 [ # # ]: 0 : if (unlikely(tb->c_neg > (RTE_BBDEV_TURBO_MAX_CODE_BLOCKS - 1))) {
2501 : 0 : rte_bbdev_log(ERR,
2502 : : "c_neg (%u) is out of range 0 <= value <= %u",
2503 : : tb->c_neg,
2504 : : RTE_BBDEV_TURBO_MAX_CODE_BLOCKS - 1);
2505 : 0 : return -1;
2506 : : }
2507 [ # # ]: 0 : if (tb->c < 1 || tb->c > RTE_BBDEV_TURBO_MAX_CODE_BLOCKS) {
2508 : 0 : rte_bbdev_log(ERR,
2509 : : "c (%u) is out of range 1 <= value <= %u",
2510 : : tb->c, RTE_BBDEV_TURBO_MAX_CODE_BLOCKS);
2511 : 0 : return -1;
2512 : : }
2513 [ # # ]: 0 : if (tb->cab > tb->c) {
2514 : 0 : rte_bbdev_log(ERR,
2515 : : "cab (%u) is greater than c (%u)",
2516 : : tb->cab, tb->c);
2517 : 0 : return -1;
2518 : : }
2519 [ # # ]: 0 : if (check_bit(turbo_dec->op_flags, RTE_BBDEV_TURBO_EQUALIZER) &&
2520 [ # # ]: 0 : (tb->ea < RTE_BBDEV_TURBO_MIN_CB_SIZE
2521 [ # # ]: 0 : || (tb->ea % 2))
2522 [ # # ]: 0 : && tb->cab > 0) {
2523 : 0 : rte_bbdev_log(ERR,
2524 : : "ea (%u) is less than %u or it is not even",
2525 : : tb->ea, RTE_BBDEV_TURBO_MIN_CB_SIZE);
2526 : 0 : return -1;
2527 : : }
2528 [ # # ]: 0 : if (check_bit(turbo_dec->op_flags, RTE_BBDEV_TURBO_EQUALIZER) &&
2529 [ # # ]: 0 : (tb->eb < RTE_BBDEV_TURBO_MIN_CB_SIZE
2530 [ # # ]: 0 : || (tb->eb % 2))
2531 [ # # ]: 0 : && tb->c > tb->cab) {
2532 : 0 : rte_bbdev_log(ERR,
2533 : : "eb (%u) is less than %u or it is not even",
2534 : : tb->eb, RTE_BBDEV_TURBO_MIN_CB_SIZE);
2535 : : }
2536 : : } else {
2537 : : cb = &turbo_dec->cb_params;
2538 : 0 : if (cb->k < RTE_BBDEV_TURBO_MIN_CB_SIZE
2539 [ # # ]: 0 : || cb->k > RTE_BBDEV_TURBO_MAX_CB_SIZE) {
2540 : 0 : rte_bbdev_log(ERR,
2541 : : "k (%u) is out of range %u <= value <= %u",
2542 : : cb->k, RTE_BBDEV_TURBO_MIN_CB_SIZE,
2543 : : RTE_BBDEV_TURBO_MAX_CB_SIZE);
2544 : 0 : return -1;
2545 : : }
2546 [ # # ]: 0 : if (check_bit(turbo_dec->op_flags, RTE_BBDEV_TURBO_EQUALIZER) &&
2547 [ # # ]: 0 : (cb->e < RTE_BBDEV_TURBO_MIN_CB_SIZE ||
2548 [ # # ]: 0 : (cb->e % 2))) {
2549 : 0 : rte_bbdev_log(ERR,
2550 : : "e (%u) is less than %u or it is not even",
2551 : : cb->e, RTE_BBDEV_TURBO_MIN_CB_SIZE);
2552 : 0 : return -1;
2553 : : }
2554 : : }
2555 : :
2556 : : return 0;
2557 : : }
2558 : : #endif
2559 : :
2560 : : /** Enqueue one decode operations for ACC100 device in CB mode */
2561 : : static inline int
2562 : 0 : enqueue_dec_one_op_cb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2563 : : uint16_t total_enqueued_cbs)
2564 : : {
2565 : : union acc_dma_desc *desc = NULL;
2566 : : int ret;
2567 : : uint32_t in_offset, h_out_offset, s_out_offset, s_out_length,
2568 : : h_out_length, mbuf_total_left, seg_total_left;
2569 : : struct rte_mbuf *input, *h_output_head, *h_output,
2570 : : *s_output_head, *s_output;
2571 : :
2572 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2573 : : /* Validate op structure */
2574 [ # # ]: 0 : if (validate_dec_op(op, q) == -1) {
2575 : 0 : rte_bbdev_log(ERR, "Turbo decoder validation rejected");
2576 : 0 : return -EINVAL;
2577 : : }
2578 : : #endif
2579 : :
2580 : : desc = acc_desc(q, total_enqueued_cbs);
2581 : : acc100_fcw_td_fill(op, &desc->req.fcw_td);
2582 : :
2583 : 0 : input = op->turbo_dec.input.data;
2584 : 0 : h_output_head = h_output = op->turbo_dec.hard_output.data;
2585 : 0 : s_output_head = s_output = op->turbo_dec.soft_output.data;
2586 : 0 : in_offset = op->turbo_dec.input.offset;
2587 : 0 : h_out_offset = op->turbo_dec.hard_output.offset;
2588 : 0 : s_out_offset = op->turbo_dec.soft_output.offset;
2589 : 0 : h_out_length = s_out_length = 0;
2590 : 0 : mbuf_total_left = op->turbo_dec.input.length;
2591 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2592 : :
2593 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2594 : : if (unlikely(input == NULL)) {
2595 : : rte_bbdev_log(ERR, "Invalid mbuf pointer");
2596 : : return -EFAULT;
2597 : : }
2598 : : #endif
2599 : :
2600 : : /* Set up DMA descriptor */
2601 : : desc = acc_desc(q, total_enqueued_cbs);
2602 : :
2603 : 0 : ret = acc100_dma_desc_td_fill(op, &desc->req, &input, h_output,
2604 : : s_output, &in_offset, &h_out_offset, &s_out_offset,
2605 : : &h_out_length, &s_out_length, &mbuf_total_left,
2606 : : &seg_total_left, 0);
2607 : :
2608 [ # # ]: 0 : if (unlikely(ret < 0))
2609 : : return ret;
2610 : :
2611 : : /* Hard output */
2612 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
2613 : :
2614 : : /* Soft output */
2615 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags, RTE_BBDEV_TURBO_SOFT_OUTPUT))
2616 [ # # ]: 0 : mbuf_append(s_output_head, s_output, s_out_length);
2617 : :
2618 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2619 : : rte_memdump(stderr, "FCW", &desc->req.fcw_td,
2620 : : sizeof(desc->req.fcw_td) - 8);
2621 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2622 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
2623 : : return -EINVAL;
2624 : : #endif
2625 : :
2626 : : /* One CB (one op) was successfully prepared to enqueue */
2627 : : return 1;
2628 : : }
2629 : :
2630 : : static inline int
2631 : 0 : harq_loopback(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2632 : : uint16_t total_enqueued_cbs) {
2633 : : struct acc_fcw_ld *fcw;
2634 : : union acc_dma_desc *desc;
2635 : : int next_triplet = 1;
2636 : : struct rte_mbuf *hq_output_head, *hq_output;
2637 : : uint16_t harq_dma_length_in, harq_dma_length_out;
2638 : 0 : uint16_t harq_in_length = op->ldpc_dec.harq_combined_input.length;
2639 : : bool ddr_mem_in;
2640 : : union acc_harq_layout_data *harq_layout;
2641 : : uint32_t harq_index;
2642 : :
2643 [ # # ]: 0 : if (harq_in_length == 0) {
2644 : 0 : rte_bbdev_log(ERR, "Loopback of invalid null size");
2645 : 0 : return -EINVAL;
2646 : : }
2647 : :
2648 [ # # ]: 0 : int h_comp = check_bit(op->ldpc_dec.op_flags,
2649 : : RTE_BBDEV_LDPC_HARQ_6BIT_COMPRESSION
2650 : : ) ? 1 : 0;
2651 [ # # ]: 0 : if (h_comp == 1) {
2652 : 0 : harq_in_length = harq_in_length * 8 / 6;
2653 : 0 : harq_in_length = RTE_ALIGN(harq_in_length, 64);
2654 : 0 : harq_dma_length_in = harq_in_length * 6 / 8;
2655 : : } else {
2656 : 0 : harq_in_length = RTE_ALIGN(harq_in_length, 64);
2657 : : harq_dma_length_in = harq_in_length;
2658 : : }
2659 : : harq_dma_length_out = harq_dma_length_in;
2660 : :
2661 : : ddr_mem_in = check_bit(op->ldpc_dec.op_flags,
2662 : : RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE);
2663 : 0 : harq_layout = q->d->harq_layout;
2664 [ # # ]: 0 : harq_index = hq_index(ddr_mem_in ?
2665 : : op->ldpc_dec.harq_combined_input.offset :
2666 : : op->ldpc_dec.harq_combined_output.offset);
2667 : :
2668 : : desc = acc_desc(q, total_enqueued_cbs);
2669 [ # # ]: 0 : fcw = &desc->req.fcw_ld;
2670 : : /* Set the FCW from loopback into DDR */
2671 : : memset(fcw, 0, sizeof(struct acc_fcw_ld));
2672 : 0 : fcw->FCWversion = ACC_FCW_VER;
2673 : 0 : fcw->qm = 2;
2674 : 0 : fcw->Zc = ACC_MAX_ZC;
2675 [ # # ]: 0 : if (harq_in_length < 16 * ACC_N_ZC_1)
2676 : 0 : fcw->Zc = 16;
2677 : 0 : fcw->ncb = fcw->Zc * ACC_N_ZC_1;
2678 : 0 : fcw->rm_e = 2;
2679 : 0 : fcw->hcin_en = 1;
2680 : 0 : fcw->hcout_en = 1;
2681 : :
2682 : 0 : rte_bbdev_log(DEBUG, "Loopback IN %d Index %d offset %d length %d %d",
2683 : : ddr_mem_in, harq_index,
2684 : : harq_layout[harq_index].offset, harq_in_length,
2685 : : harq_dma_length_in);
2686 : :
2687 [ # # # # ]: 0 : if (ddr_mem_in && (harq_layout[harq_index].offset > 0)) {
2688 : 0 : fcw->hcin_size0 = harq_layout[harq_index].size0;
2689 : 0 : fcw->hcin_offset = harq_layout[harq_index].offset;
2690 : 0 : fcw->hcin_size1 = harq_in_length - fcw->hcin_offset;
2691 : 0 : harq_dma_length_in = (fcw->hcin_size0 + fcw->hcin_size1);
2692 [ # # ]: 0 : if (h_comp == 1)
2693 : 0 : harq_dma_length_in = harq_dma_length_in * 6 / 8;
2694 : : } else {
2695 : 0 : fcw->hcin_size0 = harq_in_length;
2696 : : }
2697 : 0 : harq_layout[harq_index].val = 0;
2698 : 0 : rte_bbdev_log(DEBUG, "Loopback FCW Config %d %d %d",
2699 : : fcw->hcin_size0, fcw->hcin_offset, fcw->hcin_size1);
2700 : 0 : fcw->hcout_size0 = harq_in_length;
2701 : 0 : fcw->hcin_decomp_mode = h_comp;
2702 : 0 : fcw->hcout_comp_mode = h_comp;
2703 : 0 : fcw->gain_i = 1;
2704 [ # # ]: 0 : fcw->gain_h = 1;
2705 : :
2706 : : /* Set the prefix of descriptor. This could be done at polling */
2707 : : acc_header_init(&desc->req);
2708 : :
2709 : : /* Null LLR input for Decoder */
2710 : 0 : desc->req.data_ptrs[next_triplet].address =
2711 : 0 : q->lb_in_addr_iova;
2712 : 0 : desc->req.data_ptrs[next_triplet].blen = 2;
2713 : 0 : desc->req.data_ptrs[next_triplet].blkid = ACC_DMA_BLKID_IN;
2714 : 0 : desc->req.data_ptrs[next_triplet].last = 0;
2715 : 0 : desc->req.data_ptrs[next_triplet].dma_ext = 0;
2716 : : next_triplet++;
2717 : :
2718 : : /* HARQ Combine input from either Memory interface */
2719 [ # # ]: 0 : if (!ddr_mem_in) {
2720 : 0 : next_triplet = acc_dma_fill_blk_type(&desc->req,
2721 : : op->ldpc_dec.harq_combined_input.data,
2722 : : op->ldpc_dec.harq_combined_input.offset,
2723 : : harq_dma_length_in,
2724 : : next_triplet,
2725 : : ACC_DMA_BLKID_IN_HARQ);
2726 : : } else {
2727 : 0 : desc->req.data_ptrs[next_triplet].address =
2728 : 0 : op->ldpc_dec.harq_combined_input.offset;
2729 : 0 : desc->req.data_ptrs[next_triplet].blen =
2730 : : harq_dma_length_in;
2731 : 0 : desc->req.data_ptrs[next_triplet].blkid =
2732 : : ACC_DMA_BLKID_IN_HARQ;
2733 : 0 : desc->req.data_ptrs[next_triplet].dma_ext = 1;
2734 : : next_triplet++;
2735 : : }
2736 : 0 : desc->req.data_ptrs[next_triplet - 1].last = 1;
2737 : 0 : desc->req.m2dlen = next_triplet;
2738 : :
2739 : : /* Dropped decoder hard output */
2740 : 0 : desc->req.data_ptrs[next_triplet].address =
2741 : 0 : q->lb_out_addr_iova;
2742 : 0 : desc->req.data_ptrs[next_triplet].blen = ACC_BYTES_IN_WORD;
2743 : 0 : desc->req.data_ptrs[next_triplet].blkid = ACC_DMA_BLKID_OUT_HARD;
2744 : 0 : desc->req.data_ptrs[next_triplet].last = 0;
2745 : 0 : desc->req.data_ptrs[next_triplet].dma_ext = 0;
2746 : : next_triplet++;
2747 : :
2748 : : /* HARQ Combine output to either Memory interface */
2749 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
2750 : : RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE
2751 : : )) {
2752 : 0 : desc->req.data_ptrs[next_triplet].address =
2753 : 0 : op->ldpc_dec.harq_combined_output.offset;
2754 : 0 : desc->req.data_ptrs[next_triplet].blen =
2755 : : harq_dma_length_out;
2756 : 0 : desc->req.data_ptrs[next_triplet].blkid =
2757 : : ACC_DMA_BLKID_OUT_HARQ;
2758 : 0 : desc->req.data_ptrs[next_triplet].dma_ext = 1;
2759 : : next_triplet++;
2760 : : } else {
2761 : 0 : hq_output_head = op->ldpc_dec.harq_combined_output.data;
2762 : : hq_output = op->ldpc_dec.harq_combined_output.data;
2763 [ # # ]: 0 : next_triplet = acc_dma_fill_blk_type(
2764 : : &desc->req,
2765 : : op->ldpc_dec.harq_combined_output.data,
2766 : : op->ldpc_dec.harq_combined_output.offset,
2767 : : harq_dma_length_out,
2768 : : next_triplet,
2769 : : ACC_DMA_BLKID_OUT_HARQ);
2770 : : /* HARQ output */
2771 : : mbuf_append(hq_output_head, hq_output, harq_dma_length_out);
2772 : 0 : op->ldpc_dec.harq_combined_output.length =
2773 : : harq_dma_length_out;
2774 : : }
2775 : 0 : desc->req.data_ptrs[next_triplet - 1].last = 1;
2776 : 0 : desc->req.d2mlen = next_triplet - desc->req.m2dlen;
2777 : 0 : desc->req.op_addr = op;
2778 : :
2779 : : /* One CB (one op) was successfully prepared to enqueue */
2780 : 0 : return 1;
2781 : : }
2782 : :
2783 : : /* Assess whether a work around is recommended for the deRM corner cases */
2784 : : static inline bool
2785 : 0 : derm_workaround_recommended(struct rte_bbdev_op_ldpc_dec *ldpc_dec, struct acc_queue *q)
2786 : : {
2787 [ # # ]: 0 : if (!is_acc100(q))
2788 : : return false;
2789 : 0 : int32_t e = ldpc_dec->cb_params.e;
2790 : 0 : int q_m = ldpc_dec->q_m;
2791 : 0 : int z_c = ldpc_dec->z_c;
2792 [ # # ]: 0 : int K = (ldpc_dec->basegraph == 1 ? ACC_K_ZC_1 : ACC_K_ZC_2) * z_c;
2793 : : bool recommended = false;
2794 : :
2795 [ # # ]: 0 : if (ldpc_dec->basegraph == 1) {
2796 [ # # # # ]: 0 : if ((q_m == 4) && (z_c >= 320) && (e * ACC_LIM_31 > K * 64))
2797 : : recommended = true;
2798 [ # # ]: 0 : else if ((e * ACC_LIM_21 > K * 64))
2799 : : recommended = true;
2800 : : } else {
2801 [ # # ]: 0 : if (q_m <= 2) {
2802 [ # # # # ]: 0 : if ((z_c >= 208) && (e * ACC_LIM_09 > K * 64))
2803 : : recommended = true;
2804 [ # # # # ]: 0 : else if ((z_c < 208) && (e * ACC_LIM_03 > K * 64))
2805 : : recommended = true;
2806 [ # # ]: 0 : } else if (e * ACC_LIM_14 > K * 64)
2807 : : recommended = true;
2808 : : }
2809 : :
2810 : : return recommended;
2811 : : }
2812 : :
2813 : : /** Enqueue one decode operations for ACC100 device in CB mode */
2814 : : static inline int
2815 : 0 : enqueue_ldpc_dec_one_op_cb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2816 : : uint16_t total_enqueued_cbs, struct rte_bbdev_queue_data *q_data)
2817 : : {
2818 : : int ret;
2819 [ # # ]: 0 : if (unlikely(check_bit(op->ldpc_dec.op_flags,
2820 : : RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK))) {
2821 : 0 : ret = harq_loopback(q, op, total_enqueued_cbs);
2822 : 0 : return ret;
2823 : : }
2824 : :
2825 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2826 : : /* Validate op structure */
2827 [ # # ]: 0 : if (validate_ldpc_dec_op(op, q) == -1) {
2828 : 0 : rte_bbdev_log(ERR, "LDPC decoder validation rejected");
2829 : 0 : return -EINVAL;
2830 : : }
2831 : : #endif
2832 : : union acc_dma_desc *desc;
2833 : : desc = acc_desc(q, total_enqueued_cbs);
2834 : : struct rte_mbuf *input, *h_output_head, *h_output;
2835 : 0 : uint32_t in_offset, h_out_offset, mbuf_total_left, h_out_length = 0;
2836 : 0 : input = op->ldpc_dec.input.data;
2837 : 0 : h_output_head = h_output = op->ldpc_dec.hard_output.data;
2838 : 0 : in_offset = op->ldpc_dec.input.offset;
2839 : 0 : h_out_offset = op->ldpc_dec.hard_output.offset;
2840 : 0 : mbuf_total_left = op->ldpc_dec.input.length;
2841 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2842 : : if (unlikely(input == NULL)) {
2843 : : rte_bbdev_log(ERR, "Invalid mbuf pointer");
2844 : : return -EFAULT;
2845 : : }
2846 : : #endif
2847 : 0 : union acc_harq_layout_data *harq_layout = q->d->harq_layout;
2848 : :
2849 : : struct acc_fcw_ld *fcw;
2850 : : uint32_t seg_total_left;
2851 : :
2852 [ # # ]: 0 : if (derm_workaround_recommended(&op->ldpc_dec, q)) {
2853 : : #ifdef RTE_BBDEV_SDK_AVX512
2854 : : struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
2855 : : struct bblib_rate_dematching_5gnr_request derm_req;
2856 : : struct bblib_rate_dematching_5gnr_response derm_resp;
2857 : : uint8_t *in;
2858 : :
2859 : : /* Checking input size is matching with E */
2860 : : if (dec->input.data->data_len < (dec->cb_params.e % 65536)) {
2861 : : rte_bbdev_log(ERR, "deRM: Input size mismatch");
2862 : : return -EFAULT;
2863 : : }
2864 : : /* Run first deRM processing in SW */
2865 : : in = rte_pktmbuf_mtod_offset(dec->input.data, uint8_t *, in_offset);
2866 : : derm_req.p_in = (int8_t *) in;
2867 : : derm_req.p_harq = (int8_t *) q->derm_buffer;
2868 : : derm_req.base_graph = dec->basegraph;
2869 : : derm_req.zc = dec->z_c;
2870 : : derm_req.ncb = dec->n_cb;
2871 : : derm_req.e = dec->cb_params.e;
2872 : : if (derm_req.e > ACC_MAX_E) {
2873 : : rte_bbdev_log(WARNING,
2874 : : "deRM: E %d > %d max",
2875 : : derm_req.e, ACC_MAX_E);
2876 : : derm_req.e = ACC_MAX_E;
2877 : : }
2878 : : derm_req.k0 = 0; /* Actual output from SDK */
2879 : : derm_req.isretx = false;
2880 : : derm_req.rvid = dec->rv_index;
2881 : : derm_req.modulation_order = dec->q_m;
2882 : : derm_req.start_null_index =
2883 : : (dec->basegraph == 1 ? 22 : 10)
2884 : : * dec->z_c - 2 * dec->z_c
2885 : : - dec->n_filler;
2886 : : derm_req.num_of_null = dec->n_filler;
2887 : : bblib_rate_dematching_5gnr(&derm_req, &derm_resp);
2888 : : /* Force back the HW DeRM */
2889 : : dec->q_m = 1;
2890 : : dec->cb_params.e = dec->n_cb - dec->n_filler;
2891 : : dec->rv_index = 0;
2892 : : rte_memcpy(in, q->derm_buffer, dec->cb_params.e);
2893 : : /* Capture counter when pre-processing is used */
2894 : : q_data->queue_stats.enqueue_warn_count++;
2895 : : #else
2896 : : RTE_SET_USED(q_data);
2897 : 0 : rte_bbdev_log(INFO, "Corner case may require deRM pre-processing in SDK");
2898 : : #endif
2899 : : }
2900 : :
2901 : 0 : fcw = &desc->req.fcw_ld;
2902 : 0 : q->d->fcw_ld_fill(op, fcw, harq_layout);
2903 : :
2904 : : /* Special handling when using mbuf or not */
2905 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_DEC_SCATTER_GATHER))
2906 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2907 : : else
2908 : 0 : seg_total_left = fcw->rm_e;
2909 : :
2910 : 0 : ret = acc100_dma_desc_ld_fill(op, &desc->req, &input, h_output,
2911 : : &in_offset, &h_out_offset,
2912 : : &h_out_length, &mbuf_total_left,
2913 : : &seg_total_left, fcw);
2914 [ # # ]: 0 : if (unlikely(ret < 0))
2915 : : return ret;
2916 : :
2917 : : /* Hard output */
2918 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
2919 : : #ifndef ACC100_EXT_MEM
2920 : : if (op->ldpc_dec.harq_combined_output.length > 0) {
2921 : : /* Push the HARQ output into host memory */
2922 : : struct rte_mbuf *hq_output_head, *hq_output;
2923 : : hq_output_head = op->ldpc_dec.harq_combined_output.data;
2924 : : hq_output = op->ldpc_dec.harq_combined_output.data;
2925 : : mbuf_append(hq_output_head, hq_output,
2926 : : op->ldpc_dec.harq_combined_output.length);
2927 : : }
2928 : : #endif
2929 : :
2930 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
2931 : : rte_memdump(stderr, "FCW", &desc->req.fcw_ld,
2932 : : sizeof(desc->req.fcw_ld));
2933 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
2934 : : #endif
2935 : :
2936 : : /* One CB (one op) was successfully prepared to enqueue */
2937 : : return 1;
2938 : : }
2939 : :
2940 : :
2941 : : /* Enqueue one decode operations for ACC100 device in TB mode */
2942 : : static inline int
2943 : 0 : enqueue_ldpc_dec_one_op_tb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
2944 : : uint16_t total_enqueued_cbs, uint8_t cbs_in_tb)
2945 : : {
2946 : : union acc_dma_desc *desc = NULL;
2947 : : union acc_dma_desc *desc_first = NULL;
2948 : : int ret;
2949 : : uint8_t r, c;
2950 : : uint32_t in_offset, h_out_offset,
2951 : : h_out_length, mbuf_total_left, seg_total_left;
2952 : : struct rte_mbuf *input, *h_output_head, *h_output;
2953 : : uint16_t desc_idx, current_enqueued_cbs = 0;
2954 : : uint64_t fcw_offset;
2955 : : union acc_harq_layout_data *harq_layout;
2956 : :
2957 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
2958 : : /* Validate op structure */
2959 [ # # ]: 0 : if (validate_ldpc_dec_op(op, q) == -1) {
2960 : 0 : rte_bbdev_log(ERR, "LDPC decoder validation rejected");
2961 : 0 : return -EINVAL;
2962 : : }
2963 : : #endif
2964 : :
2965 : : desc_idx = acc_desc_idx(q, total_enqueued_cbs);
2966 : 0 : desc = q->ring_addr + desc_idx;
2967 : : desc_first = desc;
2968 : 0 : fcw_offset = (desc_idx << 8) + ACC_DESC_FCW_OFFSET;
2969 : 0 : harq_layout = q->d->harq_layout;
2970 : 0 : q->d->fcw_ld_fill(op, &desc->req.fcw_ld, harq_layout);
2971 : :
2972 : 0 : input = op->ldpc_dec.input.data;
2973 : 0 : h_output_head = h_output = op->ldpc_dec.hard_output.data;
2974 : 0 : in_offset = op->ldpc_dec.input.offset;
2975 : 0 : h_out_offset = op->ldpc_dec.hard_output.offset;
2976 : 0 : h_out_length = 0;
2977 : 0 : mbuf_total_left = op->ldpc_dec.input.length;
2978 : 0 : c = op->ldpc_dec.tb_params.c;
2979 : 0 : r = op->ldpc_dec.tb_params.r;
2980 : :
2981 [ # # ]: 0 : while (mbuf_total_left > 0 && r < c) {
2982 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags, RTE_BBDEV_LDPC_DEC_SCATTER_GATHER))
2983 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
2984 : : else
2985 : 0 : seg_total_left = op->ldpc_dec.input.length;
2986 : : /* Set up DMA descriptor */
2987 : : desc = acc_desc(q, total_enqueued_cbs);
2988 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
2989 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_LD_BLEN;
2990 [ # # ]: 0 : rte_memcpy(&desc->req.fcw_ld, &desc_first->req.fcw_ld, ACC_FCW_LD_BLEN);
2991 : 0 : ret = acc100_dma_desc_ld_fill(op, &desc->req, &input,
2992 : : h_output, &in_offset, &h_out_offset,
2993 : : &h_out_length,
2994 : : &mbuf_total_left, &seg_total_left,
2995 : : &desc->req.fcw_ld);
2996 : :
2997 [ # # ]: 0 : if (unlikely(ret < 0))
2998 : 0 : return ret;
2999 : :
3000 : : /* Hard output */
3001 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
3002 : :
3003 : : /* Set total number of CBs in TB */
3004 : 0 : desc->req.cbs_in_tb = cbs_in_tb;
3005 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3006 : : rte_memdump(stderr, "FCW", &desc->req.fcw_td,
3007 : : sizeof(desc->req.fcw_td) - 8);
3008 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
3009 : : #endif
3010 : :
3011 [ # # ]: 0 : if (check_bit(op->ldpc_dec.op_flags,
3012 : : RTE_BBDEV_LDPC_DEC_SCATTER_GATHER)
3013 [ # # ]: 0 : && (seg_total_left == 0)) {
3014 : : /* Go to the next mbuf */
3015 : 0 : input = input->next;
3016 : 0 : in_offset = 0;
3017 : 0 : h_output = h_output->next;
3018 : 0 : h_out_offset = 0;
3019 : : }
3020 : 0 : total_enqueued_cbs++;
3021 : 0 : current_enqueued_cbs++;
3022 : 0 : r++;
3023 : : }
3024 : :
3025 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3026 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
3027 : : return -EINVAL;
3028 : : #endif
3029 : : /* Set SDone on last CB descriptor for TB mode */
3030 : 0 : desc->req.sdone_enable = 1;
3031 : :
3032 : 0 : return current_enqueued_cbs;
3033 : : }
3034 : :
3035 : : /* Enqueue one decode operations for ACC100 device in TB mode */
3036 : : static inline int
3037 : 0 : enqueue_dec_one_op_tb(struct acc_queue *q, struct rte_bbdev_dec_op *op,
3038 : : uint16_t total_enqueued_cbs, uint8_t cbs_in_tb)
3039 : : {
3040 : : union acc_dma_desc *desc = NULL;
3041 : : int ret;
3042 : : uint8_t r, c;
3043 : : uint32_t in_offset, h_out_offset, s_out_offset, s_out_length,
3044 : : h_out_length, mbuf_total_left, seg_total_left;
3045 : : struct rte_mbuf *input, *h_output_head, *h_output,
3046 : : *s_output_head, *s_output;
3047 : : uint16_t current_enqueued_cbs = 0;
3048 : : uint64_t fcw_offset;
3049 : :
3050 : : #ifndef RTE_LIBRTE_BBDEV_SKIP_VALIDATE
3051 : : /* Validate op structure */
3052 [ # # ]: 0 : if (cbs_in_tb == 0) {
3053 : 0 : rte_bbdev_log(ERR, "Turbo decoder invalid number of CBs");
3054 : 0 : return -EINVAL;
3055 : : }
3056 [ # # ]: 0 : if (validate_dec_op(op, q) == -1) {
3057 : 0 : rte_bbdev_log(ERR, "Turbo decoder validation rejected");
3058 : 0 : return -EINVAL;
3059 : : }
3060 : : #endif
3061 : :
3062 : : desc = acc_desc(q, total_enqueued_cbs);
3063 [ # # ]: 0 : fcw_offset = (acc_desc_idx(q, total_enqueued_cbs) << 8) + ACC_DESC_FCW_OFFSET;
3064 : : acc100_fcw_td_fill(op, &desc->req.fcw_td);
3065 : :
3066 : 0 : input = op->turbo_dec.input.data;
3067 : 0 : h_output_head = h_output = op->turbo_dec.hard_output.data;
3068 : 0 : s_output_head = s_output = op->turbo_dec.soft_output.data;
3069 : 0 : in_offset = op->turbo_dec.input.offset;
3070 : 0 : h_out_offset = op->turbo_dec.hard_output.offset;
3071 : 0 : s_out_offset = op->turbo_dec.soft_output.offset;
3072 : 0 : h_out_length = s_out_length = 0;
3073 : 0 : mbuf_total_left = op->turbo_dec.input.length;
3074 : 0 : c = op->turbo_dec.tb_params.c;
3075 : 0 : r = op->turbo_dec.tb_params.r;
3076 : :
3077 [ # # ]: 0 : while (mbuf_total_left > 0 && r < c) {
3078 : :
3079 : 0 : seg_total_left = rte_pktmbuf_data_len(input) - in_offset;
3080 : :
3081 : : /* Set up DMA descriptor */
3082 : : desc = acc_desc(q, total_enqueued_cbs);
3083 : 0 : desc->req.data_ptrs[0].address = q->ring_addr_iova + fcw_offset;
3084 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_TD_BLEN;
3085 : 0 : ret = acc100_dma_desc_td_fill(op, &desc->req, &input,
3086 : : h_output, s_output, &in_offset, &h_out_offset,
3087 : : &s_out_offset, &h_out_length, &s_out_length,
3088 : : &mbuf_total_left, &seg_total_left, r);
3089 : :
3090 [ # # ]: 0 : if (unlikely(ret < 0))
3091 : 0 : return ret;
3092 : :
3093 : : /* Hard output */
3094 [ # # ]: 0 : mbuf_append(h_output_head, h_output, h_out_length);
3095 : :
3096 : : /* Soft output */
3097 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
3098 : : RTE_BBDEV_TURBO_SOFT_OUTPUT))
3099 [ # # ]: 0 : mbuf_append(s_output_head, s_output, s_out_length);
3100 : :
3101 : : /* Set total number of CBs in TB */
3102 : 0 : desc->req.cbs_in_tb = cbs_in_tb;
3103 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3104 : : rte_memdump(stderr, "FCW", &desc->req.fcw_td,
3105 : : sizeof(desc->req.fcw_td) - 8);
3106 : : rte_memdump(stderr, "Req Desc.", desc, sizeof(*desc));
3107 : : #endif
3108 : :
3109 [ # # ]: 0 : if (seg_total_left == 0) {
3110 : : /* Go to the next mbuf */
3111 : 0 : input = input->next;
3112 : 0 : in_offset = 0;
3113 : 0 : h_output = h_output->next;
3114 : 0 : h_out_offset = 0;
3115 : :
3116 [ # # ]: 0 : if (check_bit(op->turbo_dec.op_flags,
3117 : : RTE_BBDEV_TURBO_SOFT_OUTPUT)) {
3118 : 0 : s_output = s_output->next;
3119 : 0 : s_out_offset = 0;
3120 : : }
3121 : : }
3122 : :
3123 : 0 : total_enqueued_cbs++;
3124 : 0 : current_enqueued_cbs++;
3125 : 0 : r++;
3126 : : }
3127 : :
3128 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3129 : : if (check_mbuf_total_left(mbuf_total_left) != 0)
3130 : : return -EINVAL;
3131 : : #endif
3132 : : /* Set SDone on last CB descriptor for TB mode */
3133 : 0 : desc->req.sdone_enable = 1;
3134 : :
3135 : 0 : return current_enqueued_cbs;
3136 : : }
3137 : :
3138 : : /* Enqueue encode operations for ACC100 device in CB mode. */
3139 : : static uint16_t
3140 : 0 : acc100_enqueue_enc_cb(struct rte_bbdev_queue_data *q_data,
3141 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3142 : : {
3143 : 0 : struct acc_queue *q = q_data->queue_private;
3144 : 0 : int32_t avail = acc_ring_avail_enq(q);
3145 : : uint16_t i;
3146 : : int ret;
3147 : :
3148 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3149 : : /* Check if there are available space for further processing */
3150 [ # # ]: 0 : if (unlikely(avail - 1 < 0)) {
3151 : : acc_enqueue_ring_full(q_data);
3152 : : break;
3153 : : }
3154 : 0 : avail -= 1;
3155 : :
3156 : 0 : ret = enqueue_enc_one_op_cb(q, ops[i], i);
3157 [ # # ]: 0 : if (ret < 0) {
3158 : : acc_enqueue_invalid(q_data);
3159 : : break;
3160 : : }
3161 : : }
3162 : :
3163 [ # # ]: 0 : if (unlikely(i == 0))
3164 : : return 0; /* Nothing to enqueue */
3165 : :
3166 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
3167 : :
3168 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3169 : 0 : return i;
3170 : : }
3171 : :
3172 : : /** Enqueue encode operations for ACC100 device in CB mode. */
3173 : : static inline uint16_t
3174 : 0 : acc100_enqueue_ldpc_enc_cb(struct rte_bbdev_queue_data *q_data,
3175 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3176 : : {
3177 : 0 : struct acc_queue *q = q_data->queue_private;
3178 : 0 : int32_t avail = acc_ring_avail_enq(q);
3179 : : uint16_t i = 0;
3180 : : int ret, desc_idx = 0;
3181 : 0 : int16_t enq, left = num;
3182 : :
3183 [ # # ]: 0 : while (left > 0) {
3184 [ # # ]: 0 : if (unlikely(avail < 1)) {
3185 : : acc_enqueue_ring_full(q_data);
3186 : : break;
3187 : : }
3188 : 0 : avail--;
3189 : 0 : enq = RTE_MIN(left, ACC_MUX_5GDL_DESC);
3190 : 0 : enq = check_mux(&ops[i], enq);
3191 [ # # ]: 0 : if (enq > 1) {
3192 : 0 : ret = enqueue_ldpc_enc_n_op_cb(q, &ops[i], desc_idx, enq);
3193 [ # # ]: 0 : if (ret < 0) {
3194 : : acc_enqueue_invalid(q_data);
3195 : : break;
3196 : : }
3197 : 0 : i += enq;
3198 : : } else {
3199 : 0 : ret = enqueue_ldpc_enc_one_op_cb(q, ops[i], desc_idx);
3200 [ # # ]: 0 : if (ret < 0) {
3201 : : acc_enqueue_invalid(q_data);
3202 : : break;
3203 : : }
3204 : 0 : i++;
3205 : : }
3206 : 0 : desc_idx++;
3207 : 0 : left = num - i;
3208 : : }
3209 : :
3210 [ # # ]: 0 : if (unlikely(i == 0))
3211 : : return 0; /* Nothing to enqueue */
3212 : :
3213 : 0 : acc_dma_enqueue(q, desc_idx, &q_data->queue_stats);
3214 : :
3215 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3216 : :
3217 : 0 : return i;
3218 : : }
3219 : :
3220 : : /* Enqueue encode operations for ACC100 device in TB mode. */
3221 : : static uint16_t
3222 : 0 : acc100_enqueue_enc_tb(struct rte_bbdev_queue_data *q_data,
3223 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3224 : : {
3225 : 0 : struct acc_queue *q = q_data->queue_private;
3226 : 0 : int32_t avail = acc_ring_avail_enq(q);
3227 : : uint16_t i, enqueued_cbs = 0;
3228 : : uint8_t cbs_in_tb;
3229 : : int ret;
3230 : :
3231 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3232 : 0 : cbs_in_tb = get_num_cbs_in_tb_enc(&ops[i]->turbo_enc);
3233 : : /* Check if there are available space for further processing */
3234 [ # # ]: 0 : if (unlikely(avail - cbs_in_tb < 0)) {
3235 : : acc_enqueue_ring_full(q_data);
3236 : : break;
3237 : : }
3238 : : avail -= cbs_in_tb;
3239 : :
3240 : 0 : ret = enqueue_enc_one_op_tb(q, ops[i], enqueued_cbs, cbs_in_tb);
3241 [ # # ]: 0 : if (ret < 0) {
3242 : : acc_enqueue_invalid(q_data);
3243 : : break;
3244 : : }
3245 : 0 : enqueued_cbs += ret;
3246 : : }
3247 [ # # ]: 0 : if (unlikely(enqueued_cbs == 0))
3248 : : return 0; /* Nothing to enqueue */
3249 : :
3250 : 0 : acc_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
3251 : :
3252 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3253 : :
3254 : 0 : return i;
3255 : : }
3256 : :
3257 : : /* Enqueue LDPC encode operations for ACC100 device in TB mode. */
3258 : : static uint16_t
3259 : 0 : acc100_enqueue_ldpc_enc_tb(struct rte_bbdev_queue_data *q_data,
3260 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3261 : : {
3262 : 0 : struct acc_queue *q = q_data->queue_private;
3263 : 0 : int32_t avail = acc_ring_avail_enq(q);
3264 : : uint16_t i, enqueued_descs = 0;
3265 : : uint8_t cbs_in_tb;
3266 : : int descs_used;
3267 : :
3268 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3269 : 0 : cbs_in_tb = get_num_cbs_in_tb_ldpc_enc(&ops[i]->ldpc_enc);
3270 : : /* Check if there are available space for further processing. */
3271 [ # # ]: 0 : if (unlikely(avail - cbs_in_tb < 0)) {
3272 : : acc_enqueue_ring_full(q_data);
3273 : : break;
3274 : : }
3275 : 0 : descs_used = enqueue_ldpc_enc_one_op_tb(q, ops[i], enqueued_descs, cbs_in_tb);
3276 [ # # ]: 0 : if (descs_used < 0) {
3277 : : acc_enqueue_invalid(q_data);
3278 : : break;
3279 : : }
3280 : 0 : enqueued_descs += descs_used;
3281 : 0 : avail -= descs_used;
3282 : : }
3283 [ # # ]: 0 : if (unlikely(enqueued_descs == 0))
3284 : : return 0; /* Nothing to enqueue. */
3285 : :
3286 : 0 : acc_dma_enqueue(q, enqueued_descs, &q_data->queue_stats);
3287 : :
3288 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3289 : :
3290 : 0 : return i;
3291 : : }
3292 : :
3293 : : /* Enqueue encode operations for ACC100 device. */
3294 : : static uint16_t
3295 : 0 : acc100_enqueue_enc(struct rte_bbdev_queue_data *q_data,
3296 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3297 : : {
3298 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3299 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3300 : : return 0;
3301 [ # # ]: 0 : if (ops[0]->turbo_enc.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3302 : 0 : return acc100_enqueue_enc_tb(q_data, ops, num);
3303 : : else
3304 : 0 : return acc100_enqueue_enc_cb(q_data, ops, num);
3305 : : }
3306 : :
3307 : : /* Enqueue encode operations for ACC100 device. */
3308 : : static uint16_t
3309 : 0 : acc100_enqueue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
3310 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3311 : : {
3312 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3313 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3314 : : return 0;
3315 [ # # ]: 0 : if (ops[0]->ldpc_enc.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3316 : 0 : return acc100_enqueue_ldpc_enc_tb(q_data, ops, num);
3317 : : else
3318 : 0 : return acc100_enqueue_ldpc_enc_cb(q_data, ops, num);
3319 : : }
3320 : :
3321 : :
3322 : : /* Enqueue decode operations for ACC100 device in CB mode */
3323 : : static uint16_t
3324 : 0 : acc100_enqueue_dec_cb(struct rte_bbdev_queue_data *q_data,
3325 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3326 : : {
3327 : 0 : struct acc_queue *q = q_data->queue_private;
3328 : 0 : int32_t avail = acc_ring_avail_enq(q);
3329 : : uint16_t i;
3330 : : int ret;
3331 : :
3332 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3333 : : /* Check if there are available space for further processing */
3334 [ # # ]: 0 : if (unlikely(avail - 1 < 0)) {
3335 : : acc_enqueue_ring_full(q_data);
3336 : : break;
3337 : : }
3338 : 0 : avail -= 1;
3339 : :
3340 : 0 : ret = enqueue_dec_one_op_cb(q, ops[i], i);
3341 [ # # ]: 0 : if (ret < 0) {
3342 : : acc_enqueue_invalid(q_data);
3343 : : break;
3344 : : }
3345 : : }
3346 : :
3347 [ # # ]: 0 : if (unlikely(i == 0))
3348 : : return 0; /* Nothing to enqueue */
3349 : :
3350 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
3351 : :
3352 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3353 : :
3354 : 0 : return i;
3355 : : }
3356 : :
3357 : : /* Enqueue decode operations for ACC100 device in TB mode */
3358 : : static uint16_t
3359 : 0 : acc100_enqueue_ldpc_dec_tb(struct rte_bbdev_queue_data *q_data,
3360 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3361 : : {
3362 : 0 : struct acc_queue *q = q_data->queue_private;
3363 : 0 : int32_t avail = acc_ring_avail_enq(q);
3364 : : uint16_t i, enqueued_cbs = 0;
3365 : : uint8_t cbs_in_tb;
3366 : : int ret;
3367 : :
3368 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3369 : 0 : cbs_in_tb = get_num_cbs_in_tb_ldpc_dec(&ops[i]->ldpc_dec);
3370 : : /* Check if there are available space for further processing */
3371 [ # # ]: 0 : if (unlikely(avail - cbs_in_tb < 0))
3372 : : break;
3373 : : avail -= cbs_in_tb;
3374 : :
3375 : 0 : ret = enqueue_ldpc_dec_one_op_tb(q, ops[i],
3376 : : enqueued_cbs, cbs_in_tb);
3377 [ # # ]: 0 : if (ret < 0) {
3378 : : acc_enqueue_invalid(q_data);
3379 : : break;
3380 : : }
3381 : 0 : enqueued_cbs += ret;
3382 : : }
3383 [ # # ]: 0 : if (unlikely(enqueued_cbs == 0))
3384 : : return 0; /* Nothing to enqueue */
3385 : :
3386 : 0 : acc_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
3387 : :
3388 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3389 : 0 : return i;
3390 : : }
3391 : :
3392 : : /* Enqueue decode operations for ACC100 device in CB mode */
3393 : : static uint16_t
3394 : 0 : acc100_enqueue_ldpc_dec_cb(struct rte_bbdev_queue_data *q_data,
3395 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3396 : : {
3397 : 0 : struct acc_queue *q = q_data->queue_private;
3398 : 0 : int32_t avail = acc_ring_avail_enq(q);
3399 : : uint16_t i;
3400 : : int ret;
3401 : :
3402 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3403 : : /* Check if there are available space for further processing */
3404 [ # # ]: 0 : if (unlikely(avail < 1)) {
3405 : : acc_enqueue_ring_full(q_data);
3406 : : break;
3407 : : }
3408 : 0 : avail -= 1;
3409 : :
3410 : 0 : rte_bbdev_log(INFO, "Op %d %d %d %d %d %d %d %d %d %d %d",
3411 : : i, ops[i]->ldpc_dec.op_flags, ops[i]->ldpc_dec.rv_index,
3412 : : ops[i]->ldpc_dec.iter_max, ops[i]->ldpc_dec.iter_count,
3413 : : ops[i]->ldpc_dec.basegraph, ops[i]->ldpc_dec.z_c,
3414 : : ops[i]->ldpc_dec.n_cb, ops[i]->ldpc_dec.q_m,
3415 : : ops[i]->ldpc_dec.n_filler, ops[i]->ldpc_dec.cb_params.e);
3416 : 0 : ret = enqueue_ldpc_dec_one_op_cb(q, ops[i], i, q_data);
3417 [ # # ]: 0 : if (ret < 0) {
3418 : : acc_enqueue_invalid(q_data);
3419 : : break;
3420 : : }
3421 : : }
3422 : :
3423 [ # # ]: 0 : if (unlikely(i == 0))
3424 : : return 0; /* Nothing to enqueue */
3425 : :
3426 : 0 : acc_dma_enqueue(q, i, &q_data->queue_stats);
3427 : :
3428 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3429 : 0 : return i;
3430 : : }
3431 : :
3432 : :
3433 : : /* Enqueue decode operations for ACC100 device in TB mode */
3434 : : static uint16_t
3435 : 0 : acc100_enqueue_dec_tb(struct rte_bbdev_queue_data *q_data,
3436 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3437 : : {
3438 : 0 : struct acc_queue *q = q_data->queue_private;
3439 : 0 : int32_t avail = acc_ring_avail_enq(q);
3440 : : uint16_t i, enqueued_cbs = 0;
3441 : : uint8_t cbs_in_tb;
3442 : : int ret;
3443 : :
3444 [ # # ]: 0 : for (i = 0; i < num; ++i) {
3445 : 0 : cbs_in_tb = get_num_cbs_in_tb_dec(&ops[i]->turbo_dec);
3446 : : /* Check if there are available space for further processing */
3447 [ # # ]: 0 : if (unlikely(avail - cbs_in_tb < 0)) {
3448 : : acc_enqueue_ring_full(q_data);
3449 : : break;
3450 : : }
3451 : : avail -= cbs_in_tb;
3452 : :
3453 : 0 : ret = enqueue_dec_one_op_tb(q, ops[i], enqueued_cbs, cbs_in_tb);
3454 [ # # ]: 0 : if (ret < 0) {
3455 : : acc_enqueue_invalid(q_data);
3456 : : break;
3457 : : }
3458 : 0 : enqueued_cbs += ret;
3459 : : }
3460 : :
3461 : 0 : acc_dma_enqueue(q, enqueued_cbs, &q_data->queue_stats);
3462 : :
3463 : 0 : acc_update_qstat_enqueue(q_data, i, num - i);
3464 : :
3465 : 0 : return i;
3466 : : }
3467 : :
3468 : : /* Enqueue decode operations for ACC100 device. */
3469 : : static uint16_t
3470 : 0 : acc100_enqueue_dec(struct rte_bbdev_queue_data *q_data,
3471 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3472 : : {
3473 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3474 : :
3475 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3476 : : return 0;
3477 : :
3478 [ # # ]: 0 : if (ops[0]->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3479 : 0 : return acc100_enqueue_dec_tb(q_data, ops, num);
3480 : : else
3481 : 0 : return acc100_enqueue_dec_cb(q_data, ops, num);
3482 : : }
3483 : :
3484 : : /* Enqueue decode operations for ACC100 device. */
3485 : : static uint16_t
3486 : 0 : acc100_enqueue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
3487 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3488 : : {
3489 : 0 : int32_t aq_avail = acc_aq_avail(q_data, num);
3490 : :
3491 [ # # ]: 0 : if (unlikely((aq_avail <= 0) || (num == 0)))
3492 : : return 0;
3493 : :
3494 [ # # ]: 0 : if (ops[0]->ldpc_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3495 : 0 : return acc100_enqueue_ldpc_dec_tb(q_data, ops, num);
3496 : : else
3497 : 0 : return acc100_enqueue_ldpc_dec_cb(q_data, ops, num);
3498 : : }
3499 : :
3500 : : /* Dequeue one encode operations from ACC100 device in CB mode */
3501 : : static inline int
3502 : 0 : dequeue_enc_one_op_cb(struct acc_queue *q, struct rte_bbdev_enc_op **ref_op,
3503 : : uint16_t *dequeued_ops, uint32_t *aq_dequeued,
3504 : : uint16_t *dequeued_descs)
3505 : : {
3506 : : union acc_dma_desc *desc, atom_desc;
3507 : : union acc_dma_rsp_desc rsp;
3508 : : struct rte_bbdev_enc_op *op;
3509 : : int i;
3510 : : uint16_t desc_idx;
3511 : :
3512 [ # # ]: 0 : desc_idx = acc_desc_idx_tail(q, *dequeued_descs);
3513 : 0 : desc = q->ring_addr + desc_idx;
3514 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3515 : : rte_memory_order_relaxed);
3516 : :
3517 : : /* Check fdone bit */
3518 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3519 : : return -1;
3520 : :
3521 : : rsp.val = atom_desc.rsp.val;
3522 : : rte_bbdev_log_debug("Resp. desc %p: %x num %d", desc, rsp.val, desc->req.numCBs);
3523 : :
3524 : : /* Dequeue */
3525 : 0 : op = desc->req.op_addr;
3526 : :
3527 : : /* Clearing status, it will be set based on response */
3528 : : op->status = 0;
3529 : 0 : op->status |= ((rsp.dma_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3530 : 0 : op->status |= ((rsp.fcw_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3531 : :
3532 [ # # ]: 0 : if (desc->req.last_desc_in_batch) {
3533 : 0 : (*aq_dequeued)++;
3534 : 0 : desc->req.last_desc_in_batch = 0;
3535 : : }
3536 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3537 : 0 : desc->rsp.add_info_0 = 0; /*Reserved bits */
3538 : 0 : desc->rsp.add_info_1 = 0; /*Reserved bits */
3539 : :
3540 : 0 : ref_op[0] = op;
3541 : 0 : struct acc_ptrs *context_ptrs = q->companion_ring_addr + desc_idx;
3542 [ # # ]: 0 : for (i = 1 ; i < desc->req.numCBs; i++)
3543 : 0 : ref_op[i] = context_ptrs->ptr[i].op_addr;
3544 : :
3545 : : /* One CB (op) was successfully dequeued */
3546 : : /* One op was successfully dequeued */
3547 : 0 : (*dequeued_descs)++;
3548 : 0 : *dequeued_ops += desc->req.numCBs;
3549 : :
3550 : : /* One CB (op) was successfully dequeued */
3551 : 0 : return desc->req.numCBs;
3552 : : }
3553 : :
3554 : : /* Dequeue one LDPC encode operations from ACC100 device in TB mode
3555 : : * That operation may cover multiple descriptors
3556 : : */
3557 : : static inline int
3558 : 0 : dequeue_enc_one_op_tb(struct acc_queue *q, struct rte_bbdev_enc_op **ref_op,
3559 : : uint16_t *dequeued_ops, uint32_t *aq_dequeued,
3560 : : uint16_t *dequeued_descs)
3561 : : {
3562 : : union acc_dma_desc *desc, *last_desc, atom_desc;
3563 : : union acc_dma_rsp_desc rsp;
3564 : : struct rte_bbdev_enc_op *op;
3565 : : uint8_t i = 0;
3566 : : uint16_t current_dequeued_descs = 0, descs_in_tb;
3567 : :
3568 [ # # ]: 0 : desc = acc_desc_tail(q, *dequeued_descs);
3569 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3570 : : rte_memory_order_relaxed);
3571 : :
3572 : : /* Check fdone bit */
3573 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3574 : : return -1;
3575 : :
3576 : : /* Get number of CBs in dequeued TB */
3577 : 0 : descs_in_tb = desc->req.cbs_in_tb;
3578 : : /* Get last CB */
3579 [ # # ]: 0 : last_desc = acc_desc_tail(q, *dequeued_descs + descs_in_tb - 1);
3580 : : /* Check if last CB in TB is ready to dequeue (and thus
3581 : : * the whole TB) - checking sdone bit. If not return.
3582 : : */
3583 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)last_desc,
3584 : : rte_memory_order_relaxed);
3585 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_SDONE))
3586 : : return -1;
3587 : :
3588 : : /* Dequeue */
3589 : 0 : op = desc->req.op_addr;
3590 : :
3591 : : /* Clearing status, it will be set based on response */
3592 : 0 : op->status = 0;
3593 : :
3594 [ # # ]: 0 : while (i < descs_in_tb) {
3595 [ # # ]: 0 : desc = acc_desc_tail(q, *dequeued_descs);
3596 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3597 : : rte_memory_order_relaxed);
3598 : : rsp.val = atom_desc.rsp.val;
3599 : : rte_bbdev_log_debug("Resp. desc %p: %x descs %d cbs %d",
3600 : : desc, rsp.val, descs_in_tb, desc->req.numCBs);
3601 : :
3602 : 0 : op->status |= ((rsp.dma_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3603 : 0 : op->status |= ((rsp.fcw_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3604 : :
3605 [ # # ]: 0 : if (desc->req.last_desc_in_batch) {
3606 : 0 : (*aq_dequeued)++;
3607 : 0 : desc->req.last_desc_in_batch = 0;
3608 : : }
3609 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3610 : 0 : desc->rsp.add_info_0 = 0;
3611 : 0 : desc->rsp.add_info_1 = 0;
3612 : 0 : (*dequeued_descs)++;
3613 : 0 : current_dequeued_descs++;
3614 : 0 : i++;
3615 : : }
3616 : :
3617 : 0 : *ref_op = op;
3618 : :
3619 : 0 : (*dequeued_ops)++;
3620 : 0 : return current_dequeued_descs;
3621 : : }
3622 : :
3623 : : /* Dequeue one decode operation from ACC100 device in CB mode */
3624 : : static inline int
3625 [ # # ]: 0 : dequeue_dec_one_op_cb(struct rte_bbdev_queue_data *q_data,
3626 : : struct acc_queue *q, struct rte_bbdev_dec_op **ref_op,
3627 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3628 : : {
3629 : : union acc_dma_desc *desc, atom_desc;
3630 : : union acc_dma_rsp_desc rsp;
3631 : : struct rte_bbdev_dec_op *op;
3632 : :
3633 : : desc = acc_desc_tail(q, dequeued_cbs);
3634 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3635 : : rte_memory_order_relaxed);
3636 : :
3637 : : /* Check fdone bit */
3638 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3639 : : return -1;
3640 : :
3641 : 0 : rsp.val = atom_desc.rsp.val;
3642 : : rte_bbdev_log_debug("Resp. desc %p: %x", desc, rsp.val);
3643 : :
3644 : : /* Dequeue */
3645 : 0 : op = desc->req.op_addr;
3646 : :
3647 : : /* Clearing status, it will be set based on response */
3648 : : op->status = 0;
3649 : : op->status |= ((rsp.input_err)
3650 : 0 : ? (1 << RTE_BBDEV_DATA_ERROR) : 0);
3651 : 0 : op->status |= ((rsp.dma_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3652 : 0 : op->status |= ((rsp.fcw_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3653 [ # # ]: 0 : if (op->status != 0) {
3654 : 0 : q_data->queue_stats.dequeue_err_count++;
3655 : 0 : acc100_check_ir(q->d);
3656 : : }
3657 : :
3658 : : /* CRC invalid if error exists */
3659 [ # # ]: 0 : if (!op->status)
3660 : 0 : op->status |= rsp.crc_status << RTE_BBDEV_CRC_ERROR;
3661 : 0 : op->turbo_dec.iter_count = (uint8_t) rsp.iter_cnt / 2;
3662 : : /* Check if this is the last desc in batch (Atomic Queue) */
3663 [ # # ]: 0 : if (desc->req.last_desc_in_batch) {
3664 : 0 : (*aq_dequeued)++;
3665 : 0 : desc->req.last_desc_in_batch = 0;
3666 : : }
3667 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3668 : 0 : desc->rsp.add_info_0 = 0;
3669 : 0 : desc->rsp.add_info_1 = 0;
3670 : 0 : *ref_op = op;
3671 : :
3672 : : /* One CB (op) was successfully dequeued */
3673 : 0 : return 1;
3674 : : }
3675 : :
3676 : : /* Dequeue one decode operations from ACC100 device in CB mode */
3677 : : static inline int
3678 [ # # ]: 0 : dequeue_ldpc_dec_one_op_cb(struct rte_bbdev_queue_data *q_data,
3679 : : struct acc_queue *q, struct rte_bbdev_dec_op **ref_op,
3680 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3681 : : {
3682 : : union acc_dma_desc *desc, atom_desc;
3683 : : union acc_dma_rsp_desc rsp;
3684 : : struct rte_bbdev_dec_op *op;
3685 : :
3686 : : desc = acc_desc_tail(q, dequeued_cbs);
3687 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3688 : : rte_memory_order_relaxed);
3689 : :
3690 : : /* Check fdone bit */
3691 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3692 : : return -1;
3693 : :
3694 : 0 : rsp.val = atom_desc.rsp.val;
3695 : : rte_bbdev_log_debug("Resp. desc %p: %x", desc, rsp.val);
3696 : :
3697 : : /* Dequeue */
3698 : 0 : op = desc->req.op_addr;
3699 : :
3700 : : /* Clearing status, it will be set based on response */
3701 : : op->status = 0;
3702 : 0 : op->status |= rsp.input_err << RTE_BBDEV_DATA_ERROR;
3703 : 0 : op->status |= rsp.dma_err << RTE_BBDEV_DRV_ERROR;
3704 : 0 : op->status |= rsp.fcw_err << RTE_BBDEV_DRV_ERROR;
3705 [ # # ]: 0 : if (op->status != 0)
3706 : 0 : q_data->queue_stats.dequeue_err_count++;
3707 : :
3708 : 0 : op->status |= rsp.crc_status << RTE_BBDEV_CRC_ERROR;
3709 [ # # # # ]: 0 : if (op->ldpc_dec.hard_output.length > 0 && !rsp.synd_ok)
3710 : 0 : op->status |= 1 << RTE_BBDEV_SYNDROME_ERROR;
3711 : 0 : op->ldpc_dec.iter_count = (uint8_t) rsp.iter_cnt;
3712 : :
3713 [ # # ]: 0 : if (op->status & (1 << RTE_BBDEV_DRV_ERROR))
3714 : 0 : acc100_check_ir(q->d);
3715 : :
3716 : : /* Check if this is the last desc in batch (Atomic Queue) */
3717 [ # # ]: 0 : if (desc->req.last_desc_in_batch) {
3718 : 0 : (*aq_dequeued)++;
3719 : 0 : desc->req.last_desc_in_batch = 0;
3720 : : }
3721 : :
3722 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3723 : 0 : desc->rsp.add_info_0 = 0;
3724 : 0 : desc->rsp.add_info_1 = 0;
3725 : :
3726 : 0 : *ref_op = op;
3727 : :
3728 : : /* One CB (op) was successfully dequeued */
3729 : 0 : return 1;
3730 : : }
3731 : :
3732 : : /* Dequeue one decode operations from ACC100 device in TB mode. */
3733 : : static inline int
3734 [ # # ]: 0 : dequeue_dec_one_op_tb(struct acc_queue *q, struct rte_bbdev_dec_op **ref_op,
3735 : : uint16_t dequeued_cbs, uint32_t *aq_dequeued)
3736 : : {
3737 : : union acc_dma_desc *desc, *last_desc, atom_desc;
3738 : : union acc_dma_rsp_desc rsp;
3739 : : struct rte_bbdev_dec_op *op;
3740 : : uint8_t cbs_in_tb = 1, cb_idx = 0;
3741 : :
3742 : : desc = acc_desc_tail(q, dequeued_cbs);
3743 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3744 : : rte_memory_order_relaxed);
3745 : :
3746 : : /* Check fdone bit */
3747 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_FDONE))
3748 : : return -1;
3749 : :
3750 : : /* Dequeue */
3751 : 0 : op = desc->req.op_addr;
3752 : :
3753 : : /* Get number of CBs in dequeued TB */
3754 : 0 : cbs_in_tb = desc->req.cbs_in_tb;
3755 : : /* Get last CB */
3756 [ # # ]: 0 : last_desc = acc_desc_tail(q, dequeued_cbs + cbs_in_tb - 1);
3757 : : /* Check if last CB in TB is ready to dequeue (and thus
3758 : : * the whole TB) - checking sdone bit. If not return.
3759 : : */
3760 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)last_desc,
3761 : : rte_memory_order_relaxed);
3762 [ # # ]: 0 : if (!(atom_desc.rsp.val & ACC_SDONE))
3763 : : return -1;
3764 : :
3765 : : /* Clearing status, it will be set based on response */
3766 : 0 : op->status = 0;
3767 : :
3768 : : /* Read remaining CBs if exists */
3769 [ # # ]: 0 : while (cb_idx < cbs_in_tb) {
3770 : : desc = acc_desc_tail(q, dequeued_cbs);
3771 : 0 : atom_desc.atom_hdr = rte_atomic_load_explicit((uint64_t __rte_atomic *)desc,
3772 : : rte_memory_order_relaxed);
3773 : 0 : rsp.val = atom_desc.rsp.val;
3774 : : rte_bbdev_log_debug("Resp. desc %p: %x r %d c %d",
3775 : : desc, rsp.val, cb_idx, cbs_in_tb);
3776 : :
3777 : 0 : op->status |= ((rsp.input_err) ? (1 << RTE_BBDEV_DATA_ERROR) : 0);
3778 : 0 : op->status |= ((rsp.dma_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3779 : 0 : op->status |= ((rsp.fcw_err) ? (1 << RTE_BBDEV_DRV_ERROR) : 0);
3780 : :
3781 : : /* CRC invalid if error exists */
3782 [ # # ]: 0 : if (!op->status)
3783 : 0 : op->status |= rsp.crc_status << RTE_BBDEV_CRC_ERROR;
3784 [ # # ]: 0 : if (q->op_type == RTE_BBDEV_OP_LDPC_DEC)
3785 : 0 : op->ldpc_dec.iter_count = RTE_MAX((uint8_t) rsp.iter_cnt,
3786 : : op->ldpc_dec.iter_count);
3787 : : else
3788 : 0 : op->turbo_dec.iter_count = RTE_MAX((uint8_t) rsp.iter_cnt,
3789 : : op->turbo_dec.iter_count);
3790 : :
3791 : : /* Check if this is the last desc in batch (Atomic Queue) */
3792 [ # # ]: 0 : if (desc->req.last_desc_in_batch) {
3793 : 0 : (*aq_dequeued)++;
3794 : 0 : desc->req.last_desc_in_batch = 0;
3795 : : }
3796 : 0 : desc->rsp.val = ACC_DMA_DESC_TYPE;
3797 : 0 : desc->rsp.add_info_0 = 0;
3798 : 0 : desc->rsp.add_info_1 = 0;
3799 : 0 : dequeued_cbs++;
3800 : 0 : cb_idx++;
3801 : : }
3802 : :
3803 : 0 : *ref_op = op;
3804 : :
3805 : 0 : return cb_idx;
3806 : : }
3807 : :
3808 : : /* Dequeue encode operations from ACC100 device. */
3809 : : static uint16_t
3810 : 0 : acc100_dequeue_enc(struct rte_bbdev_queue_data *q_data,
3811 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3812 : : {
3813 [ # # ]: 0 : struct acc_queue *q = q_data->queue_private;
3814 : : uint32_t avail = acc_ring_avail_deq(q);
3815 : 0 : uint32_t aq_dequeued = 0;
3816 : 0 : uint16_t i, dequeued_ops = 0, dequeued_descs = 0;
3817 : : int ret, cbm;
3818 : : struct rte_bbdev_enc_op *op;
3819 : :
3820 [ # # ]: 0 : if (avail == 0)
3821 : : return 0;
3822 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3823 : : if (unlikely(ops == NULL || q == NULL)) {
3824 : : rte_bbdev_log_debug("Unexpected undefined pointer");
3825 : : return 0;
3826 : : }
3827 : : #endif
3828 : : op = acc_op_tail(q, 0);
3829 [ # # ]: 0 : if (unlikely(ops == NULL || op == NULL))
3830 : : return 0;
3831 : 0 : cbm = op->turbo_enc.code_block_mode;
3832 : :
3833 [ # # ]: 0 : for (i = 0; i < num; i++) {
3834 [ # # ]: 0 : if (cbm == RTE_BBDEV_TRANSPORT_BLOCK)
3835 : 0 : ret = dequeue_enc_one_op_tb(q, &ops[dequeued_ops],
3836 : : &dequeued_ops, &aq_dequeued,
3837 : : &dequeued_descs);
3838 : : else
3839 : 0 : ret = dequeue_enc_one_op_cb(q, &ops[dequeued_ops],
3840 : : &dequeued_ops, &aq_dequeued,
3841 : : &dequeued_descs);
3842 : :
3843 [ # # ]: 0 : if (ret < 0)
3844 : : break;
3845 : :
3846 [ # # ]: 0 : if (dequeued_ops >= num)
3847 : : break;
3848 : : }
3849 : :
3850 : 0 : q->aq_dequeued += aq_dequeued;
3851 : 0 : q->sw_ring_tail += dequeued_descs;
3852 : :
3853 : 0 : acc_update_qstat_dequeue(q_data, dequeued_ops);
3854 : :
3855 : 0 : return dequeued_ops;
3856 : : }
3857 : :
3858 : : /* Dequeue LDPC encode operations from ACC100 device. */
3859 : : static uint16_t
3860 : 0 : acc100_dequeue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
3861 : : struct rte_bbdev_enc_op **ops, uint16_t num)
3862 : : {
3863 [ # # ]: 0 : struct acc_queue *q = q_data->queue_private;
3864 : : uint32_t avail = acc_ring_avail_deq(q);
3865 : 0 : uint32_t aq_dequeued = 0;
3866 : 0 : uint16_t i, dequeued_ops = 0, dequeued_descs = 0;
3867 : : int ret, cbm;
3868 : : struct rte_bbdev_enc_op *op;
3869 : :
3870 [ # # ]: 0 : if (avail == 0)
3871 : : return 0;
3872 : :
3873 : : op = acc_op_tail(q, 0);
3874 [ # # ]: 0 : if (unlikely(ops == NULL || op == NULL))
3875 : : return 0;
3876 : 0 : cbm = op->ldpc_enc.code_block_mode;
3877 [ # # ]: 0 : for (i = 0; i < avail; i++) {
3878 [ # # ]: 0 : if (cbm == RTE_BBDEV_TRANSPORT_BLOCK)
3879 : 0 : ret = dequeue_enc_one_op_tb(q, &ops[dequeued_ops],
3880 : : &dequeued_ops, &aq_dequeued,
3881 : : &dequeued_descs);
3882 : : else
3883 : 0 : ret = dequeue_enc_one_op_cb(q, &ops[dequeued_ops],
3884 : : &dequeued_ops, &aq_dequeued,
3885 : : &dequeued_descs);
3886 [ # # ]: 0 : if (ret < 0)
3887 : : break;
3888 [ # # ]: 0 : if (dequeued_ops >= num)
3889 : : break;
3890 : : }
3891 : :
3892 : 0 : q->aq_dequeued += aq_dequeued;
3893 : 0 : q->sw_ring_tail += dequeued_descs;
3894 : :
3895 : 0 : acc_update_qstat_dequeue(q_data, dequeued_ops);
3896 : :
3897 : 0 : return dequeued_ops;
3898 : : }
3899 : :
3900 : : /* Dequeue decode operations from ACC100 device. */
3901 : : static uint16_t
3902 : 0 : acc100_dequeue_dec(struct rte_bbdev_queue_data *q_data,
3903 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3904 : : {
3905 : 0 : struct acc_queue *q = q_data->queue_private;
3906 : : uint16_t dequeue_num;
3907 : : uint32_t avail = acc_ring_avail_deq(q);
3908 : 0 : uint32_t aq_dequeued = 0;
3909 : : uint16_t i;
3910 : : uint16_t dequeued_cbs = 0;
3911 : : struct rte_bbdev_dec_op *op;
3912 : : int ret;
3913 : :
3914 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3915 : : if (unlikely(ops == 0 && q == NULL))
3916 : : return 0;
3917 : : #endif
3918 : :
3919 : 0 : dequeue_num = (avail < num) ? avail : num;
3920 : :
3921 [ # # ]: 0 : for (i = 0; i < dequeue_num; ++i) {
3922 [ # # ]: 0 : op = acc_op_tail(q, dequeued_cbs);
3923 [ # # ]: 0 : if (unlikely(op == NULL))
3924 : : break;
3925 [ # # ]: 0 : if (op->turbo_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3926 : 0 : ret = dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
3927 : : &aq_dequeued);
3928 : : else
3929 : 0 : ret = dequeue_dec_one_op_cb(q_data, q, &ops[i],
3930 : : dequeued_cbs, &aq_dequeued);
3931 : :
3932 [ # # ]: 0 : if (ret < 0)
3933 : : break;
3934 : 0 : dequeued_cbs += ret;
3935 : : }
3936 : :
3937 : 0 : q->aq_dequeued += aq_dequeued;
3938 : 0 : q->sw_ring_tail += dequeued_cbs;
3939 : :
3940 : : acc_update_qstat_dequeue(q_data, i);
3941 : :
3942 : 0 : return i;
3943 : : }
3944 : :
3945 : : /* Dequeue decode operations from ACC100 device. */
3946 : : static uint16_t
3947 : 0 : acc100_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
3948 : : struct rte_bbdev_dec_op **ops, uint16_t num)
3949 : : {
3950 : 0 : struct acc_queue *q = q_data->queue_private;
3951 : : uint16_t dequeue_num;
3952 : : uint32_t avail = acc_ring_avail_deq(q);
3953 : 0 : uint32_t aq_dequeued = 0;
3954 : : uint16_t i;
3955 : : uint16_t dequeued_cbs = 0;
3956 : : struct rte_bbdev_dec_op *op;
3957 : : int ret;
3958 : :
3959 : : #ifdef RTE_LIBRTE_BBDEV_DEBUG
3960 : : if (unlikely(ops == 0 && q == NULL))
3961 : : return 0;
3962 : : #endif
3963 : :
3964 : 0 : dequeue_num = RTE_MIN(avail, num);
3965 : :
3966 [ # # ]: 0 : for (i = 0; i < dequeue_num; ++i) {
3967 [ # # ]: 0 : op = acc_op_tail(q, dequeued_cbs);
3968 [ # # ]: 0 : if (unlikely(op == NULL))
3969 : : break;
3970 [ # # ]: 0 : if (op->ldpc_dec.code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK)
3971 : 0 : ret = dequeue_dec_one_op_tb(q, &ops[i], dequeued_cbs,
3972 : : &aq_dequeued);
3973 : : else
3974 : 0 : ret = dequeue_ldpc_dec_one_op_cb(
3975 : 0 : q_data, q, &ops[i], dequeued_cbs,
3976 : : &aq_dequeued);
3977 : :
3978 [ # # ]: 0 : if (ret < 0)
3979 : : break;
3980 : 0 : dequeued_cbs += ret;
3981 : : }
3982 : :
3983 : 0 : q->aq_dequeued += aq_dequeued;
3984 : 0 : q->sw_ring_tail += dequeued_cbs;
3985 : :
3986 : : acc_update_qstat_dequeue(q_data, i);
3987 : :
3988 : 0 : return i;
3989 : : }
3990 : :
3991 : : /* Initialization Function */
3992 : : static void
3993 : 0 : acc100_bbdev_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
3994 : : {
3995 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
3996 : :
3997 : 0 : dev->dev_ops = &acc100_bbdev_ops;
3998 : 0 : dev->enqueue_enc_ops = acc100_enqueue_enc;
3999 : 0 : dev->enqueue_dec_ops = acc100_enqueue_dec;
4000 : 0 : dev->dequeue_enc_ops = acc100_dequeue_enc;
4001 : 0 : dev->dequeue_dec_ops = acc100_dequeue_dec;
4002 : 0 : dev->enqueue_ldpc_enc_ops = acc100_enqueue_ldpc_enc;
4003 : 0 : dev->enqueue_ldpc_dec_ops = acc100_enqueue_ldpc_dec;
4004 : 0 : dev->dequeue_ldpc_enc_ops = acc100_dequeue_ldpc_enc;
4005 : 0 : dev->dequeue_ldpc_dec_ops = acc100_dequeue_ldpc_dec;
4006 : :
4007 : : /* Device variant specific handling */
4008 [ # # ]: 0 : if ((pci_dev->id.device_id == ACC100_PF_DEVICE_ID) ||
4009 : : (pci_dev->id.device_id == ACC100_VF_DEVICE_ID)) {
4010 : 0 : ((struct acc_device *) dev->data->dev_private)->device_variant = ACC100_VARIANT;
4011 : 0 : ((struct acc_device *) dev->data->dev_private)->fcw_ld_fill = acc100_fcw_ld_fill;
4012 : : }
4013 : :
4014 : 0 : ((struct acc_device *) dev->data->dev_private)->pf_device =
4015 : 0 : !strcmp(drv->driver.name, RTE_STR(ACC100PF_DRIVER_NAME));
4016 : :
4017 : 0 : ((struct acc_device *) dev->data->dev_private)->mmio_base =
4018 : 0 : pci_dev->mem_resource[0].addr;
4019 : :
4020 : : rte_bbdev_log_debug("Init device %s [%s] @ vaddr %p paddr %#"PRIx64"",
4021 : : drv->driver.name, dev->data->name,
4022 : : (void *)pci_dev->mem_resource[0].addr,
4023 : : pci_dev->mem_resource[0].phys_addr);
4024 : 0 : }
4025 : :
4026 : 0 : static int acc100_pci_probe(struct rte_pci_driver *pci_drv,
4027 : : struct rte_pci_device *pci_dev)
4028 : : {
4029 : : struct rte_bbdev *bbdev = NULL;
4030 : : char dev_name[RTE_BBDEV_NAME_MAX_LEN];
4031 : :
4032 [ # # ]: 0 : if (pci_dev == NULL) {
4033 : 0 : rte_bbdev_log(ERR, "NULL PCI device");
4034 : 0 : return -EINVAL;
4035 : : }
4036 : :
4037 : 0 : rte_pci_device_name(&pci_dev->addr, dev_name, sizeof(dev_name));
4038 : :
4039 : : /* Allocate memory to be used privately by drivers */
4040 : 0 : bbdev = rte_bbdev_allocate(pci_dev->device.name);
4041 [ # # ]: 0 : if (bbdev == NULL)
4042 : : return -ENODEV;
4043 : :
4044 : : /* allocate device private memory */
4045 : 0 : bbdev->data->dev_private = rte_zmalloc_socket(dev_name,
4046 : : sizeof(struct acc_device), RTE_CACHE_LINE_SIZE,
4047 : : pci_dev->device.numa_node);
4048 : :
4049 [ # # ]: 0 : if (bbdev->data->dev_private == NULL) {
4050 : 0 : rte_bbdev_log(CRIT,
4051 : : "Allocate of %zu bytes for device \"%s\" failed",
4052 : : sizeof(struct acc_device), dev_name);
4053 : 0 : rte_bbdev_release(bbdev);
4054 : 0 : return -ENOMEM;
4055 : : }
4056 : :
4057 : : /* Fill HW specific part of device structure */
4058 : 0 : bbdev->device = &pci_dev->device;
4059 : 0 : bbdev->intr_handle = pci_dev->intr_handle;
4060 : 0 : bbdev->data->socket_id = pci_dev->device.numa_node;
4061 : :
4062 : : /* Invoke ACC100 device initialization function */
4063 : 0 : acc100_bbdev_init(bbdev, pci_drv);
4064 : :
4065 : : rte_bbdev_log_debug("Initialised bbdev %s (id = %u)",
4066 : : dev_name, bbdev->data->dev_id);
4067 : 0 : return 0;
4068 : : }
4069 : :
4070 : : static struct rte_pci_driver acc100_pci_pf_driver = {
4071 : : .probe = acc100_pci_probe,
4072 : : .remove = acc_pci_remove,
4073 : : .id_table = pci_id_acc100_pf_map,
4074 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING
4075 : : };
4076 : :
4077 : : static struct rte_pci_driver acc100_pci_vf_driver = {
4078 : : .probe = acc100_pci_probe,
4079 : : .remove = acc_pci_remove,
4080 : : .id_table = pci_id_acc100_vf_map,
4081 : : .drv_flags = RTE_PCI_DRV_NEED_MAPPING
4082 : : };
4083 : :
4084 : 252 : RTE_PMD_REGISTER_PCI(ACC100PF_DRIVER_NAME, acc100_pci_pf_driver);
4085 : : RTE_PMD_REGISTER_PCI_TABLE(ACC100PF_DRIVER_NAME, pci_id_acc100_pf_map);
4086 : 252 : RTE_PMD_REGISTER_PCI(ACC100VF_DRIVER_NAME, acc100_pci_vf_driver);
4087 : : RTE_PMD_REGISTER_PCI_TABLE(ACC100VF_DRIVER_NAME, pci_id_acc100_vf_map);
4088 : :
4089 : : /*
4090 : : * Workaround implementation to fix the power on status of some 5GUL engines
4091 : : * This requires DMA permission if ported outside DPDK
4092 : : * It consists in resolving the state of these engines by running a
4093 : : * dummy operation and resetting the engines to ensure state are reliably
4094 : : * defined.
4095 : : */
4096 : : static void
4097 : 0 : poweron_cleanup(struct rte_bbdev *bbdev, struct acc_device *d,
4098 : : struct rte_acc_conf *conf)
4099 : : {
4100 : : int i, template_idx, qg_idx;
4101 : : uint32_t address, status, value;
4102 : 0 : rte_bbdev_log(WARNING, "Need to clear power-on 5GUL status in internal memory");
4103 : : /* Reset LDPC Cores */
4104 [ # # ]: 0 : for (i = 0; i < ACC100_ENGINES_MAX; i++)
4105 : 0 : acc_reg_write(d, HWPfFecUl5gCntrlReg +
4106 : : ACC_ENGINE_OFFSET * i, ACC100_RESET_HI);
4107 : 0 : usleep(ACC_LONG_WAIT);
4108 [ # # ]: 0 : for (i = 0; i < ACC100_ENGINES_MAX; i++)
4109 : 0 : acc_reg_write(d, HWPfFecUl5gCntrlReg +
4110 : : ACC_ENGINE_OFFSET * i, ACC100_RESET_LO);
4111 : 0 : usleep(ACC_LONG_WAIT);
4112 : : /* Prepare dummy workload */
4113 : 0 : alloc_2x64mb_sw_rings_mem(bbdev, d, 0);
4114 : : /* Set base addresses */
4115 : 0 : uint32_t phys_high = (uint32_t)(d->sw_rings_iova >> 32);
4116 : 0 : uint32_t phys_low = (uint32_t)(d->sw_rings_iova &
4117 : : ~(ACC_SIZE_64MBYTE-1));
4118 : : acc_reg_write(d, HWPfDmaFec5GulDescBaseHiRegVf, phys_high);
4119 : : acc_reg_write(d, HWPfDmaFec5GulDescBaseLoRegVf, phys_low);
4120 : :
4121 : : /* Descriptor for a dummy 5GUL code block processing*/
4122 : : union acc_dma_desc *desc = NULL;
4123 : 0 : desc = d->sw_rings;
4124 : 0 : desc->req.data_ptrs[0].address = d->sw_rings_iova +
4125 : : ACC_DESC_FCW_OFFSET;
4126 : 0 : desc->req.data_ptrs[0].blen = ACC_FCW_LD_BLEN;
4127 : 0 : desc->req.data_ptrs[0].blkid = ACC_DMA_BLKID_FCW;
4128 : 0 : desc->req.data_ptrs[0].last = 0;
4129 : 0 : desc->req.data_ptrs[0].dma_ext = 0;
4130 : 0 : desc->req.data_ptrs[1].address = d->sw_rings_iova + 512;
4131 : 0 : desc->req.data_ptrs[1].blkid = ACC_DMA_BLKID_IN;
4132 : 0 : desc->req.data_ptrs[1].last = 1;
4133 : 0 : desc->req.data_ptrs[1].dma_ext = 0;
4134 : 0 : desc->req.data_ptrs[1].blen = 44;
4135 : 0 : desc->req.data_ptrs[2].address = d->sw_rings_iova + 1024;
4136 : 0 : desc->req.data_ptrs[2].blkid = ACC_DMA_BLKID_OUT_ENC;
4137 : 0 : desc->req.data_ptrs[2].last = 1;
4138 : 0 : desc->req.data_ptrs[2].dma_ext = 0;
4139 : 0 : desc->req.data_ptrs[2].blen = 5;
4140 : : /* Dummy FCW */
4141 : 0 : desc->req.fcw_ld.FCWversion = ACC_FCW_VER;
4142 : 0 : desc->req.fcw_ld.qm = 1;
4143 : 0 : desc->req.fcw_ld.nfiller = 30;
4144 : 0 : desc->req.fcw_ld.BG = 2 - 1;
4145 : 0 : desc->req.fcw_ld.Zc = 7;
4146 : 0 : desc->req.fcw_ld.ncb = 350;
4147 : 0 : desc->req.fcw_ld.rm_e = 4;
4148 : 0 : desc->req.fcw_ld.itmax = 10;
4149 : 0 : desc->req.fcw_ld.gain_i = 1;
4150 : 0 : desc->req.fcw_ld.gain_h = 1;
4151 : :
4152 : 0 : int engines_to_restart[ACC100_SIG_UL_5G_LAST + 1] = {0};
4153 : : int num_failed_engine = 0;
4154 : : /* Detect engines in undefined state */
4155 : 0 : for (template_idx = ACC100_SIG_UL_5G;
4156 [ # # ]: 0 : template_idx <= ACC100_SIG_UL_5G_LAST;
4157 : 0 : template_idx++) {
4158 : : /* Check engine power-on status */
4159 : 0 : address = HwPfFecUl5gIbDebugReg +
4160 [ # # ]: 0 : ACC_ENGINE_OFFSET * template_idx;
4161 : 0 : status = (acc_reg_read(d, address) >> 4) & 0xF;
4162 [ # # ]: 0 : if (status == 0) {
4163 : 0 : engines_to_restart[num_failed_engine] = template_idx;
4164 : 0 : num_failed_engine++;
4165 : : }
4166 : : }
4167 : :
4168 : 0 : int numQqsAcc = conf->q_ul_5g.num_qgroups;
4169 : : int numQgs = conf->q_ul_5g.num_qgroups;
4170 : : value = 0;
4171 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4172 : 0 : value |= (1 << qg_idx);
4173 : : /* Force each engine which is in unspecified state */
4174 [ # # ]: 0 : for (i = 0; i < num_failed_engine; i++) {
4175 : 0 : int failed_engine = engines_to_restart[i];
4176 : 0 : rte_bbdev_log(WARNING, "Force engine %d", failed_engine);
4177 : 0 : for (template_idx = ACC100_SIG_UL_5G;
4178 [ # # ]: 0 : template_idx <= ACC100_SIG_UL_5G_LAST;
4179 : 0 : template_idx++) {
4180 : : address = HWPfQmgrGrpTmplateReg4Indx
4181 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4182 [ # # ]: 0 : if (template_idx == failed_engine)
4183 : : acc_reg_write(d, address, value);
4184 : : else
4185 : : acc_reg_write(d, address, 0);
4186 : : }
4187 : : /* Reset descriptor header */
4188 : 0 : desc->req.word0 = ACC_DMA_DESC_TYPE;
4189 : 0 : desc->req.word1 = 0;
4190 : 0 : desc->req.word2 = 0;
4191 : 0 : desc->req.word3 = 0;
4192 : 0 : desc->req.numCBs = 1;
4193 : 0 : desc->req.m2dlen = 2;
4194 : 0 : desc->req.d2mlen = 1;
4195 : : /* Enqueue the code block for processing */
4196 : : union acc_enqueue_reg_fmt enq_req;
4197 : : enq_req.val = 0;
4198 : : enq_req.addr_offset = ACC_DESC_OFFSET;
4199 : : enq_req.num_elem = 1;
4200 : : enq_req.req_elem_addr = 0;
4201 : : rte_wmb();
4202 : : acc_reg_write(d, HWPfQmgrIngressAq + 0x100, enq_req.val);
4203 : 0 : usleep(ACC_LONG_WAIT * 100);
4204 [ # # ]: 0 : if (desc->req.word0 != 2)
4205 : 0 : rte_bbdev_log(WARNING, "DMA Response %#"PRIx32"", desc->req.word0);
4206 : : }
4207 : :
4208 : : /* Reset LDPC Cores */
4209 [ # # ]: 0 : for (i = 0; i < ACC100_ENGINES_MAX; i++)
4210 : 0 : acc_reg_write(d, HWPfFecUl5gCntrlReg +
4211 : : ACC_ENGINE_OFFSET * i,
4212 : : ACC100_RESET_HI);
4213 : 0 : usleep(ACC_LONG_WAIT);
4214 [ # # ]: 0 : for (i = 0; i < ACC100_ENGINES_MAX; i++)
4215 : 0 : acc_reg_write(d, HWPfFecUl5gCntrlReg +
4216 : : ACC_ENGINE_OFFSET * i,
4217 : : ACC100_RESET_LO);
4218 : 0 : usleep(ACC_LONG_WAIT);
4219 : : acc_reg_write(d, HWPfHi5GHardResetReg, ACC100_RESET_HARD);
4220 : 0 : usleep(ACC_LONG_WAIT);
4221 : : int numEngines = 0;
4222 : : /* Check engine power-on status again */
4223 : 0 : for (template_idx = ACC100_SIG_UL_5G;
4224 [ # # ]: 0 : template_idx <= ACC100_SIG_UL_5G_LAST;
4225 : 0 : template_idx++) {
4226 : 0 : address = HwPfFecUl5gIbDebugReg +
4227 [ # # ]: 0 : ACC_ENGINE_OFFSET * template_idx;
4228 : 0 : status = (acc_reg_read(d, address) >> 4) & 0xF;
4229 : : address = HWPfQmgrGrpTmplateReg4Indx
4230 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4231 [ # # ]: 0 : if (status == 1) {
4232 : : acc_reg_write(d, address, value);
4233 : 0 : numEngines++;
4234 : : } else
4235 : : acc_reg_write(d, address, 0);
4236 : : }
4237 : 0 : rte_bbdev_log(INFO, "Number of 5GUL engines %d", numEngines);
4238 : :
4239 : 0 : rte_free(d->sw_rings_base);
4240 : 0 : d->sw_rings_base = NULL;
4241 : 0 : usleep(ACC_LONG_WAIT);
4242 : 0 : }
4243 : :
4244 : : /* Initial configuration of a ACC100 device prior to running configure() */
4245 : : static int
4246 : 0 : acc100_configure(const char *dev_name, struct rte_acc_conf *conf)
4247 : : {
4248 : 0 : rte_bbdev_log(INFO, "rte_acc100_configure");
4249 : : uint32_t value, address, status;
4250 : : int qg_idx, template_idx, vf_idx, acc, i, j;
4251 : 0 : struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
4252 : :
4253 : : /* Compile time checks */
4254 : : RTE_BUILD_BUG_ON(sizeof(struct acc_dma_req_desc) != 256);
4255 : : RTE_BUILD_BUG_ON(sizeof(union acc_dma_desc) != 256);
4256 : : RTE_BUILD_BUG_ON(sizeof(struct acc_fcw_td) != 24);
4257 : : RTE_BUILD_BUG_ON(sizeof(struct acc_fcw_te) != 32);
4258 : :
4259 [ # # ]: 0 : if (bbdev == NULL) {
4260 : 0 : rte_bbdev_log(ERR,
4261 : : "Invalid dev_name (%s), or device is not yet initialised",
4262 : : dev_name);
4263 : 0 : return -ENODEV;
4264 : : }
4265 : 0 : struct acc_device *d = bbdev->data->dev_private;
4266 : :
4267 : : /* Store configuration */
4268 [ # # ]: 0 : rte_memcpy(&d->acc_conf, conf, sizeof(d->acc_conf));
4269 : :
4270 : : value = acc_reg_read(d, HwPfPcieGpexBridgeControl);
4271 : : bool firstCfg = (value != ACC100_CFG_PCI_BRIDGE);
4272 : :
4273 : : /* PCIe Bridge configuration */
4274 : : acc_reg_write(d, HwPfPcieGpexBridgeControl, ACC100_CFG_PCI_BRIDGE);
4275 [ # # ]: 0 : for (i = 1; i < ACC100_GPEX_AXIMAP_NUM; i++)
4276 : : acc_reg_write(d,
4277 : : HwPfPcieGpexAxiAddrMappingWindowPexBaseHigh
4278 : 0 : + i * 16, 0);
4279 : :
4280 : : /* Prevent blocking AXI read on BRESP for AXI Write */
4281 : : address = HwPfPcieGpexAxiPioControl;
4282 : : value = ACC100_CFG_PCI_AXI;
4283 : : acc_reg_write(d, address, value);
4284 : :
4285 : : /* 5GDL PLL phase shift */
4286 : : acc_reg_write(d, HWPfChaDl5gPllPhshft0, 0x1);
4287 : :
4288 : : /* Explicitly releasing AXI as this may be stopped after PF FLR/BME */
4289 : : address = HWPfDmaAxiControl;
4290 : : value = 1;
4291 : : acc_reg_write(d, address, value);
4292 : :
4293 : : /* Enable granular dynamic clock gating */
4294 : : address = HWPfHiClkGateHystReg;
4295 : : value = ACC100_CLOCK_GATING_EN;
4296 : : acc_reg_write(d, address, value);
4297 : :
4298 : : /* Set default descriptor signature */
4299 : : address = HWPfDmaDescriptorSignatuture;
4300 : : value = 0;
4301 : : acc_reg_write(d, address, value);
4302 : :
4303 : : /* Enable the Error Detection in DMA */
4304 : : value = ACC100_CFG_DMA_ERROR;
4305 : : address = HWPfDmaErrorDetectionEn;
4306 : : acc_reg_write(d, address, value);
4307 : :
4308 : : /* AXI Cache configuration */
4309 : : value = ACC100_CFG_AXI_CACHE;
4310 : : address = HWPfDmaAxcacheReg;
4311 : : acc_reg_write(d, address, value);
4312 : :
4313 : : /* Adjust PCIe Lane adaptation */
4314 [ # # ]: 0 : for (i = 0; i < ACC100_QUAD_NUMS; i++)
4315 [ # # ]: 0 : for (j = 0; j < ACC100_LANES_PER_QUAD; j++)
4316 : 0 : acc_reg_write(d, HwPfPcieLnAdaptctrl + i * ACC100_PCIE_QUAD_OFFSET
4317 : 0 : + j * ACC100_PCIE_LANE_OFFSET, ACC100_ADAPT);
4318 : :
4319 : : /* Enable PCIe live adaptation */
4320 [ # # ]: 0 : for (i = 0; i < ACC100_QUAD_NUMS; i++)
4321 : 0 : acc_reg_write(d, HwPfPciePcsEqControl +
4322 : 0 : i * ACC100_PCIE_QUAD_OFFSET, ACC100_PCS_EQ);
4323 : :
4324 : : /* Default DMA Configuration (Qmgr Enabled) */
4325 : : address = HWPfDmaConfig0Reg;
4326 : : value = 0;
4327 : : acc_reg_write(d, address, value);
4328 : : address = HWPfDmaQmanen;
4329 : : value = 0;
4330 : : acc_reg_write(d, address, value);
4331 : :
4332 : : /* Default RLIM/ALEN configuration */
4333 : : address = HWPfDmaConfig1Reg;
4334 : : value = (1 << 31) + (23 << 8) + (1 << 6) + 7;
4335 : : acc_reg_write(d, address, value);
4336 : :
4337 : : /* Configure DMA Qmanager addresses */
4338 : : address = HWPfDmaQmgrAddrReg;
4339 : : value = HWPfQmgrEgressQueuesTemplate;
4340 : : acc_reg_write(d, address, value);
4341 : :
4342 : : /* Default Fabric Mode */
4343 : : address = HWPfFabricMode;
4344 : : value = ACC100_FABRIC_MODE;
4345 : : acc_reg_write(d, address, value);
4346 : :
4347 : : /* ===== Qmgr Configuration ===== */
4348 : : /* Configuration of the AQueue Depth QMGR_GRP_0_DEPTH_LOG2 for UL */
4349 : 0 : int totalQgs = conf->q_ul_4g.num_qgroups +
4350 : 0 : conf->q_ul_5g.num_qgroups +
4351 : 0 : conf->q_dl_4g.num_qgroups +
4352 : 0 : conf->q_dl_5g.num_qgroups;
4353 [ # # ]: 0 : for (qg_idx = 0; qg_idx < totalQgs; qg_idx++) {
4354 : 0 : address = HWPfQmgrDepthLog2Grp +
4355 : : ACC_BYTES_IN_WORD * qg_idx;
4356 : 0 : value = aqDepth(qg_idx, conf);
4357 : : acc_reg_write(d, address, value);
4358 : 0 : address = HWPfQmgrTholdGrp +
4359 : : ACC_BYTES_IN_WORD * qg_idx;
4360 : 0 : value = (1 << 16) + (1 << (aqDepth(qg_idx, conf) - 1));
4361 : : acc_reg_write(d, address, value);
4362 : : }
4363 : :
4364 : : /* Template Priority in incremental order */
4365 [ # # ]: 0 : for (template_idx = 0; template_idx < ACC_NUM_TMPL; template_idx++) {
4366 : 0 : address = HWPfQmgrGrpTmplateReg0Indx + ACC_BYTES_IN_WORD * template_idx;
4367 : : value = ACC_TMPL_PRI_0;
4368 : : acc_reg_write(d, address, value);
4369 : 0 : address = HWPfQmgrGrpTmplateReg1Indx + ACC_BYTES_IN_WORD * template_idx;
4370 : : value = ACC_TMPL_PRI_1;
4371 : : acc_reg_write(d, address, value);
4372 : 0 : address = HWPfQmgrGrpTmplateReg2indx + ACC_BYTES_IN_WORD * template_idx;
4373 : : value = ACC_TMPL_PRI_2;
4374 : : acc_reg_write(d, address, value);
4375 : 0 : address = HWPfQmgrGrpTmplateReg3Indx + ACC_BYTES_IN_WORD * template_idx;
4376 : : value = ACC_TMPL_PRI_3;
4377 : : acc_reg_write(d, address, value);
4378 : : }
4379 : :
4380 : : address = HWPfQmgrGrpPriority;
4381 : : value = ACC100_CFG_QMGR_HI_P;
4382 : : acc_reg_write(d, address, value);
4383 : :
4384 : : /* Template Configuration */
4385 [ # # ]: 0 : for (template_idx = 0; template_idx < ACC_NUM_TMPL;
4386 : 0 : template_idx++) {
4387 : : value = 0;
4388 : : address = HWPfQmgrGrpTmplateReg4Indx
4389 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4390 : : acc_reg_write(d, address, value);
4391 : : }
4392 : : /* 4GUL */
4393 : 0 : int numQgs = conf->q_ul_4g.num_qgroups;
4394 : : int numQqsAcc = 0;
4395 : : value = 0;
4396 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4397 : 0 : value |= (1 << qg_idx);
4398 : : for (template_idx = ACC100_SIG_UL_4G;
4399 [ # # ]: 0 : template_idx <= ACC100_SIG_UL_4G_LAST;
4400 : 0 : template_idx++) {
4401 : : address = HWPfQmgrGrpTmplateReg4Indx
4402 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4403 : : acc_reg_write(d, address, value);
4404 : : }
4405 : : /* 5GUL */
4406 : : numQqsAcc += numQgs;
4407 : 0 : numQgs = conf->q_ul_5g.num_qgroups;
4408 : : value = 0;
4409 : : int numEngines = 0;
4410 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4411 : 0 : value |= (1 << qg_idx);
4412 : : for (template_idx = ACC100_SIG_UL_5G;
4413 [ # # ]: 0 : template_idx <= ACC100_SIG_UL_5G_LAST;
4414 : 0 : template_idx++) {
4415 : : /* Check engine power-on status */
4416 : 0 : address = HwPfFecUl5gIbDebugReg +
4417 [ # # ]: 0 : ACC_ENGINE_OFFSET * template_idx;
4418 : 0 : status = (acc_reg_read(d, address) >> 4) & 0xF;
4419 : : address = HWPfQmgrGrpTmplateReg4Indx
4420 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4421 [ # # ]: 0 : if (status == 1) {
4422 : : acc_reg_write(d, address, value);
4423 : 0 : numEngines++;
4424 : : } else
4425 : : acc_reg_write(d, address, 0);
4426 : : }
4427 : 0 : rte_bbdev_log(INFO, "Number of 5GUL engines %d", numEngines);
4428 : : /* 4GDL */
4429 : : numQqsAcc += numQgs;
4430 : 0 : numQgs = conf->q_dl_4g.num_qgroups;
4431 : : value = 0;
4432 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4433 : 0 : value |= (1 << qg_idx);
4434 : : for (template_idx = ACC100_SIG_DL_4G;
4435 [ # # ]: 0 : template_idx <= ACC100_SIG_DL_4G_LAST;
4436 : 0 : template_idx++) {
4437 : : address = HWPfQmgrGrpTmplateReg4Indx
4438 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4439 : : acc_reg_write(d, address, value);
4440 : : }
4441 : : /* 5GDL */
4442 : : numQqsAcc += numQgs;
4443 : 0 : numQgs = conf->q_dl_5g.num_qgroups;
4444 : : value = 0;
4445 [ # # ]: 0 : for (qg_idx = numQqsAcc; qg_idx < (numQgs + numQqsAcc); qg_idx++)
4446 : 0 : value |= (1 << qg_idx);
4447 : : for (template_idx = ACC100_SIG_DL_5G;
4448 [ # # ]: 0 : template_idx <= ACC100_SIG_DL_5G_LAST;
4449 : 0 : template_idx++) {
4450 : : address = HWPfQmgrGrpTmplateReg4Indx
4451 : 0 : + ACC_BYTES_IN_WORD * template_idx;
4452 : : acc_reg_write(d, address, value);
4453 : : }
4454 : :
4455 : : /* Queue Group Function mapping */
4456 : 0 : int qman_func_id[8] = {0, 2, 1, 3, 4, 0, 0, 0};
4457 : : address = HWPfQmgrGrpFunction0;
4458 : : value = 0;
4459 [ # # ]: 0 : for (qg_idx = 0; qg_idx < 8; qg_idx++) {
4460 : 0 : acc = accFromQgid(qg_idx, conf);
4461 : 0 : value |= qman_func_id[acc]<<(qg_idx * 4);
4462 : : }
4463 : : acc_reg_write(d, address, value);
4464 : :
4465 : : /* Configuration of the Arbitration QGroup depth to 1 */
4466 [ # # ]: 0 : for (qg_idx = 0; qg_idx < totalQgs; qg_idx++) {
4467 : 0 : address = HWPfQmgrArbQDepthGrp +
4468 : : ACC_BYTES_IN_WORD * qg_idx;
4469 : : value = 0;
4470 : : acc_reg_write(d, address, value);
4471 : : }
4472 : :
4473 : : /* Enabling AQueues through the Queue hierarchy*/
4474 [ # # ]: 0 : for (vf_idx = 0; vf_idx < ACC100_NUM_VFS; vf_idx++) {
4475 [ # # ]: 0 : for (qg_idx = 0; qg_idx < ACC100_NUM_QGRPS; qg_idx++) {
4476 : : value = 0;
4477 [ # # # # ]: 0 : if (vf_idx < conf->num_vf_bundles &&
4478 : : qg_idx < totalQgs)
4479 : 0 : value = (1 << aqNum(qg_idx, conf)) - 1;
4480 : : address = HWPfQmgrAqEnableVf
4481 : 0 : + vf_idx * ACC_BYTES_IN_WORD;
4482 : 0 : value += (qg_idx << 16);
4483 : : acc_reg_write(d, address, value);
4484 : : }
4485 : : }
4486 : :
4487 : : /* This pointer to ARAM (128kB) is shifted by 2 (4B per register) */
4488 : : uint32_t aram_address = 0;
4489 [ # # ]: 0 : for (qg_idx = 0; qg_idx < totalQgs; qg_idx++) {
4490 [ # # ]: 0 : for (vf_idx = 0; vf_idx < conf->num_vf_bundles; vf_idx++) {
4491 : 0 : address = HWPfQmgrVfBaseAddr + vf_idx
4492 : 0 : * ACC_BYTES_IN_WORD + qg_idx
4493 : : * ACC_BYTES_IN_WORD * 64;
4494 : : value = aram_address;
4495 : : acc_reg_write(d, address, value);
4496 : : /* Offset ARAM Address for next memory bank
4497 : : * - increment of 4B
4498 : : */
4499 : 0 : aram_address += aqNum(qg_idx, conf) *
4500 : 0 : (1 << aqDepth(qg_idx, conf));
4501 : : }
4502 : : }
4503 : :
4504 [ # # ]: 0 : if (aram_address > ACC100_WORDS_IN_ARAM_SIZE) {
4505 : 0 : rte_bbdev_log(ERR, "ARAM Configuration not fitting %d %d",
4506 : : aram_address, ACC100_WORDS_IN_ARAM_SIZE);
4507 : 0 : return -EINVAL;
4508 : : }
4509 : :
4510 : : /* ==== HI Configuration ==== */
4511 : :
4512 : : /* No Info Ring/MSI by default */
4513 : : acc_reg_write(d, HWPfHiInfoRingIntWrEnRegPf, 0);
4514 : : acc_reg_write(d, HWPfHiInfoRingVf2pfLoWrEnReg, 0);
4515 : : acc_reg_write(d, HWPfHiCfgMsiIntWrEnRegPf, 0xFFFFFFFF);
4516 : : acc_reg_write(d, HWPfHiCfgMsiVf2pfLoWrEnReg, 0xFFFFFFFF);
4517 : : /* Prevent Block on Transmit Error */
4518 : : address = HWPfHiBlockTransmitOnErrorEn;
4519 : : value = 0;
4520 : : acc_reg_write(d, address, value);
4521 : : /* Prevents to drop MSI */
4522 : : address = HWPfHiMsiDropEnableReg;
4523 : : value = 0;
4524 : : acc_reg_write(d, address, value);
4525 : : /* Set the PF Mode register */
4526 : : address = HWPfHiPfMode;
4527 [ # # ]: 0 : value = (conf->pf_mode_en) ? ACC_PF_VAL : 0;
4528 : : acc_reg_write(d, address, value);
4529 : :
4530 : : /* QoS overflow init */
4531 : : value = 1;
4532 : : address = HWPfQosmonAEvalOverflow0;
4533 : : acc_reg_write(d, address, value);
4534 : : address = HWPfQosmonBEvalOverflow0;
4535 : : acc_reg_write(d, address, value);
4536 : :
4537 : : /* HARQ DDR Configuration */
4538 : : unsigned int ddrSizeInMb = ACC100_HARQ_DDR;
4539 [ # # ]: 0 : for (vf_idx = 0; vf_idx < conf->num_vf_bundles; vf_idx++) {
4540 : 0 : address = HWPfDmaVfDdrBaseRw + vf_idx
4541 : : * 0x10;
4542 : 0 : value = ((vf_idx * (ddrSizeInMb / 64)) << 16) +
4543 : : (ddrSizeInMb - 1);
4544 : : acc_reg_write(d, address, value);
4545 : : }
4546 : 0 : usleep(ACC_LONG_WAIT);
4547 : :
4548 : : /* Workaround in case some 5GUL engines are in an unexpected state */
4549 [ # # ]: 0 : if (numEngines < (ACC100_SIG_UL_5G_LAST + 1))
4550 : 0 : poweron_cleanup(bbdev, d, conf);
4551 : :
4552 : : uint32_t version = 0;
4553 [ # # ]: 0 : for (i = 0; i < 4; i++)
4554 : 0 : version += acc_reg_read(d,
4555 : 0 : HWPfDdrPhyIdtmFwVersion + 4 * i) << (8 * i);
4556 [ # # ]: 0 : if (version != ACC100_PRQ_DDR_VER) {
4557 : 0 : rte_bbdev_log(ERR, "* Note: Not on DDR PRQ version %8x != %08x",
4558 : : version, ACC100_PRQ_DDR_VER);
4559 [ # # ]: 0 : } else if (firstCfg) {
4560 : : /* ---- DDR configuration at boot up --- */
4561 : : /* Read Clear Ddr training status */
4562 : : acc_reg_read(d, HWPfChaDdrStDoneStatus);
4563 : : /* Reset PHY/IDTM/UMMC */
4564 : : acc_reg_write(d, HWPfChaDdrWbRstCfg, 3);
4565 : : acc_reg_write(d, HWPfChaDdrApbRstCfg, 2);
4566 : : acc_reg_write(d, HWPfChaDdrPhyRstCfg, 2);
4567 : : acc_reg_write(d, HWPfChaDdrCpuRstCfg, 3);
4568 : : acc_reg_write(d, HWPfChaDdrSifRstCfg, 2);
4569 : 0 : usleep(ACC_MS_IN_US);
4570 : : /* Reset WB and APB resets */
4571 : : acc_reg_write(d, HWPfChaDdrWbRstCfg, 2);
4572 : : acc_reg_write(d, HWPfChaDdrApbRstCfg, 3);
4573 : : /* Configure PHY-IDTM */
4574 : : acc_reg_write(d, HWPfDdrPhyIdletimeout, 0x3e8);
4575 : : /* IDTM timing registers */
4576 : : acc_reg_write(d, HWPfDdrPhyRdLatency, 0x13);
4577 : : acc_reg_write(d, HWPfDdrPhyRdLatencyDbi, 0x15);
4578 : : acc_reg_write(d, HWPfDdrPhyWrLatency, 0x10011);
4579 : : /* Configure SDRAM MRS registers */
4580 : : acc_reg_write(d, HWPfDdrPhyMr01Dimm, 0x3030b70);
4581 : : acc_reg_write(d, HWPfDdrPhyMr01DimmDbi, 0x3030b50);
4582 : : acc_reg_write(d, HWPfDdrPhyMr23Dimm, 0x30);
4583 : : acc_reg_write(d, HWPfDdrPhyMr67Dimm, 0xc00);
4584 : : acc_reg_write(d, HWPfDdrPhyMr45Dimm, 0x4000000);
4585 : : /* Configure active lanes */
4586 : : acc_reg_write(d, HWPfDdrPhyDqsCountMax, 0x9);
4587 : : acc_reg_write(d, HWPfDdrPhyDqsCountNum, 0x9);
4588 : : /* Configure WR/RD leveling timing registers */
4589 : : acc_reg_write(d, HWPfDdrPhyWrlvlWwRdlvlRr, 0x101212);
4590 : : /* Configure what trainings to execute */
4591 : : acc_reg_write(d, HWPfDdrPhyTrngType, 0x2d3c);
4592 : : /* Releasing PHY reset */
4593 : : acc_reg_write(d, HWPfChaDdrPhyRstCfg, 3);
4594 : : /* Configure Memory Controller registers */
4595 : : acc_reg_write(d, HWPfDdrMemInitPhyTrng0, 0x3);
4596 : : acc_reg_write(d, HWPfDdrBcDram, 0x3c232003);
4597 : : acc_reg_write(d, HWPfDdrBcAddrMap, 0x31);
4598 : : /* Configure UMMC BC timing registers */
4599 : : acc_reg_write(d, HWPfDdrBcRef, 0xa22);
4600 : : acc_reg_write(d, HWPfDdrBcTim0, 0x4050501);
4601 : : acc_reg_write(d, HWPfDdrBcTim1, 0xf0b0476);
4602 : : acc_reg_write(d, HWPfDdrBcTim2, 0x103);
4603 : : acc_reg_write(d, HWPfDdrBcTim3, 0x144050a1);
4604 : : acc_reg_write(d, HWPfDdrBcTim4, 0x23300);
4605 : : acc_reg_write(d, HWPfDdrBcTim5, 0x4230276);
4606 : : acc_reg_write(d, HWPfDdrBcTim6, 0x857914);
4607 : : acc_reg_write(d, HWPfDdrBcTim7, 0x79100232);
4608 : : acc_reg_write(d, HWPfDdrBcTim8, 0x100007ce);
4609 : : acc_reg_write(d, HWPfDdrBcTim9, 0x50020);
4610 : : acc_reg_write(d, HWPfDdrBcTim10, 0x40ee);
4611 : : /* Configure UMMC DFI timing registers */
4612 : : acc_reg_write(d, HWPfDdrDfiInit, 0x5000);
4613 : : acc_reg_write(d, HWPfDdrDfiTim0, 0x15030006);
4614 : : acc_reg_write(d, HWPfDdrDfiTim1, 0x11305);
4615 : : acc_reg_write(d, HWPfDdrDfiPhyUpdEn, 0x1);
4616 : : acc_reg_write(d, HWPfDdrUmmcIntEn, 0x1f);
4617 : : /* Release IDTM CPU out of reset */
4618 : : acc_reg_write(d, HWPfChaDdrCpuRstCfg, 0x2);
4619 : : /* Wait PHY-IDTM to finish static training */
4620 [ # # ]: 0 : for (i = 0; i < ACC100_DDR_TRAINING_MAX; i++) {
4621 : 0 : usleep(ACC_MS_IN_US);
4622 : : value = acc_reg_read(d,
4623 : : HWPfChaDdrStDoneStatus);
4624 [ # # ]: 0 : if (value & 1)
4625 : : break;
4626 : : }
4627 : 0 : rte_bbdev_log(INFO, "DDR Training completed in %d ms", i);
4628 : : /* Enable Memory Controller */
4629 : : acc_reg_write(d, HWPfDdrUmmcCtrl, 0x401);
4630 : : /* Release AXI interface reset */
4631 : : acc_reg_write(d, HWPfChaDdrSifRstCfg, 3);
4632 : : }
4633 : :
4634 : : rte_bbdev_log_debug("PF Tip configuration complete for %s", dev_name);
4635 : : return 0;
4636 : : }
4637 : :
4638 : : int
4639 : 0 : rte_acc_configure(const char *dev_name, struct rte_acc_conf *conf)
4640 : : {
4641 : 0 : struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
4642 [ # # ]: 0 : if (bbdev == NULL) {
4643 : 0 : rte_bbdev_log(ERR, "Invalid dev_name (%s), or device is not yet initialised",
4644 : : dev_name);
4645 : 0 : return -ENODEV;
4646 : : }
4647 : 0 : struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(bbdev->device);
4648 : 0 : rte_bbdev_log(INFO, "Configure dev id %x", pci_dev->id.device_id);
4649 [ # # ]: 0 : if (pci_dev->id.device_id == ACC100_PF_DEVICE_ID)
4650 : 0 : return acc100_configure(dev_name, conf);
4651 [ # # ]: 0 : else if (pci_dev->id.device_id == VRB1_PF_DEVICE_ID)
4652 : 0 : return vrb1_configure(dev_name, conf);
4653 [ # # ]: 0 : else if (pci_dev->id.device_id == VRB2_PF_DEVICE_ID)
4654 : 0 : return vrb2_configure(dev_name, conf);
4655 : :
4656 : : return -ENXIO;
4657 : : }
|