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