1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2020 Intel Corporation
7 #include <rte_common.h>
10 #include <rte_malloc.h>
11 #include <rte_mempool.h>
12 #include <rte_errno.h>
14 #include <rte_bus_pci.h>
15 #include <rte_byteorder.h>
16 #ifdef RTE_BBDEV_OFFLOAD_COST
17 #include <rte_cycles.h>
20 #include <rte_bbdev.h>
21 #include <rte_bbdev_pmd.h>
23 #include "fpga_5gnr_fec.h"
24 #include "rte_pmd_fpga_5gnr_fec.h"
26 #ifdef RTE_LIBRTE_BBDEV_DEBUG
27 RTE_LOG_REGISTER_DEFAULT(fpga_5gnr_fec_logtype, DEBUG);
29 RTE_LOG_REGISTER_DEFAULT(fpga_5gnr_fec_logtype, NOTICE);
32 #ifdef RTE_LIBRTE_BBDEV_DEBUG
34 /* Read Ring Control Register of FPGA 5GNR FEC device */
36 print_ring_reg_debug_info(void *mmio_base, uint32_t offset)
39 "FPGA MMIO base address @ %p | Ring Control Register @ offset = 0x%08"
40 PRIx32, mmio_base, offset);
42 "RING_BASE_ADDR = 0x%016"PRIx64,
43 fpga_reg_read_64(mmio_base, offset));
45 "RING_HEAD_ADDR = 0x%016"PRIx64,
46 fpga_reg_read_64(mmio_base, offset +
47 FPGA_5GNR_FEC_RING_HEAD_ADDR));
49 "RING_SIZE = 0x%04"PRIx16,
50 fpga_reg_read_16(mmio_base, offset +
51 FPGA_5GNR_FEC_RING_SIZE));
53 "RING_MISC = 0x%02"PRIx8,
54 fpga_reg_read_8(mmio_base, offset +
55 FPGA_5GNR_FEC_RING_MISC));
57 "RING_ENABLE = 0x%02"PRIx8,
58 fpga_reg_read_8(mmio_base, offset +
59 FPGA_5GNR_FEC_RING_ENABLE));
61 "RING_FLUSH_QUEUE_EN = 0x%02"PRIx8,
62 fpga_reg_read_8(mmio_base, offset +
63 FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN));
65 "RING_SHADOW_TAIL = 0x%04"PRIx16,
66 fpga_reg_read_16(mmio_base, offset +
67 FPGA_5GNR_FEC_RING_SHADOW_TAIL));
69 "RING_HEAD_POINT = 0x%04"PRIx16,
70 fpga_reg_read_16(mmio_base, offset +
71 FPGA_5GNR_FEC_RING_HEAD_POINT));
74 /* Read Static Register of FPGA 5GNR FEC device */
76 print_static_reg_debug_info(void *mmio_base)
78 uint16_t config = fpga_reg_read_16(mmio_base,
79 FPGA_5GNR_FEC_CONFIGURATION);
80 uint8_t qmap_done = fpga_reg_read_8(mmio_base,
81 FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE);
82 uint16_t lb_factor = fpga_reg_read_16(mmio_base,
83 FPGA_5GNR_FEC_LOAD_BALANCE_FACTOR);
84 uint16_t ring_desc_len = fpga_reg_read_16(mmio_base,
85 FPGA_5GNR_FEC_RING_DESC_LEN);
87 rte_bbdev_log_debug("UL.DL Weights = %u.%u",
88 ((uint8_t)config), ((uint8_t)(config >> 8)));
89 rte_bbdev_log_debug("UL.DL Load Balance = %u.%u",
90 ((uint8_t)lb_factor), ((uint8_t)(lb_factor >> 8)));
91 rte_bbdev_log_debug("Queue-PF/VF Mapping Table = %s",
92 (qmap_done > 0) ? "READY" : "NOT-READY");
93 rte_bbdev_log_debug("Ring Descriptor Size = %u bytes",
94 ring_desc_len*FPGA_RING_DESC_LEN_UNIT_BYTES);
97 /* Print decode DMA Descriptor of FPGA 5GNR Decoder device */
99 print_dma_dec_desc_debug_info(union fpga_dma_desc *desc)
101 rte_bbdev_log_debug("DMA response desc %p\n"
102 "\t-- done(%"PRIu32") | iter(%"PRIu32") | et_pass(%"PRIu32")"
103 " | crcb_pass (%"PRIu32") | error(%"PRIu32")\n"
104 "\t-- qm_idx(%"PRIu32") | max_iter(%"PRIu32") | "
105 "bg_idx (%"PRIu32") | harqin_en(%"PRIu32") | zc(%"PRIu32")\n"
106 "\t-- hbstroe_offset(%"PRIu32") | num_null (%"PRIu32") "
107 "| irq_en(%"PRIu32")\n"
108 "\t-- ncb(%"PRIu32") | desc_idx (%"PRIu32") | "
109 "drop_crc24b(%"PRIu32") | RV (%"PRIu32")\n"
110 "\t-- crc24b_ind(%"PRIu32") | et_dis (%"PRIu32")\n"
111 "\t-- harq_input_length(%"PRIu32") | rm_e(%"PRIu32")\n"
112 "\t-- cbs_in_op(%"PRIu32") | in_add (0x%08"PRIx32"%08"PRIx32")"
113 "| out_add (0x%08"PRIx32"%08"PRIx32")",
115 (uint32_t)desc->dec_req.done,
116 (uint32_t)desc->dec_req.iter,
117 (uint32_t)desc->dec_req.et_pass,
118 (uint32_t)desc->dec_req.crcb_pass,
119 (uint32_t)desc->dec_req.error,
120 (uint32_t)desc->dec_req.qm_idx,
121 (uint32_t)desc->dec_req.max_iter,
122 (uint32_t)desc->dec_req.bg_idx,
123 (uint32_t)desc->dec_req.harqin_en,
124 (uint32_t)desc->dec_req.zc,
125 (uint32_t)desc->dec_req.hbstroe_offset,
126 (uint32_t)desc->dec_req.num_null,
127 (uint32_t)desc->dec_req.irq_en,
128 (uint32_t)desc->dec_req.ncb,
129 (uint32_t)desc->dec_req.desc_idx,
130 (uint32_t)desc->dec_req.drop_crc24b,
131 (uint32_t)desc->dec_req.rv,
132 (uint32_t)desc->dec_req.crc24b_ind,
133 (uint32_t)desc->dec_req.et_dis,
134 (uint32_t)desc->dec_req.harq_input_length,
135 (uint32_t)desc->dec_req.rm_e,
136 (uint32_t)desc->dec_req.cbs_in_op,
137 (uint32_t)desc->dec_req.in_addr_hi,
138 (uint32_t)desc->dec_req.in_addr_lw,
139 (uint32_t)desc->dec_req.out_addr_hi,
140 (uint32_t)desc->dec_req.out_addr_lw);
141 uint32_t *word = (uint32_t *) desc;
142 rte_bbdev_log_debug("%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n"
143 "%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n",
144 word[0], word[1], word[2], word[3],
145 word[4], word[5], word[6], word[7]);
148 /* Print decode DMA Descriptor of FPGA 5GNR encoder device */
150 print_dma_enc_desc_debug_info(union fpga_dma_desc *desc)
152 rte_bbdev_log_debug("DMA response desc %p\n"
153 "%"PRIu32" %"PRIu32"\n"
154 "K' %"PRIu32" E %"PRIu32" desc %"PRIu32" Z %"PRIu32"\n"
155 "BG %"PRIu32" Qm %"PRIu32" CRC %"PRIu32" IRQ %"PRIu32"\n"
156 "k0 %"PRIu32" Ncb %"PRIu32" F %"PRIu32"\n",
158 (uint32_t)desc->enc_req.done,
159 (uint32_t)desc->enc_req.error,
161 (uint32_t)desc->enc_req.k_,
162 (uint32_t)desc->enc_req.rm_e,
163 (uint32_t)desc->enc_req.desc_idx,
164 (uint32_t)desc->enc_req.zc,
166 (uint32_t)desc->enc_req.bg_idx,
167 (uint32_t)desc->enc_req.qm_idx,
168 (uint32_t)desc->enc_req.crc_en,
169 (uint32_t)desc->enc_req.irq_en,
171 (uint32_t)desc->enc_req.k0,
172 (uint32_t)desc->enc_req.ncb,
173 (uint32_t)desc->enc_req.num_null);
174 uint32_t *word = (uint32_t *) desc;
175 rte_bbdev_log_debug("%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n"
176 "%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n",
177 word[0], word[1], word[2], word[3],
178 word[4], word[5], word[6], word[7]);
184 fpga_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id)
186 /* Number of queues bound to a PF/VF */
187 uint32_t hw_q_num = 0;
188 uint32_t ring_size, payload, address, q_id, offset;
189 rte_iova_t phys_addr;
190 struct fpga_ring_ctrl_reg ring_reg;
191 struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
193 address = FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE;
194 if (!(fpga_reg_read_32(fpga_dev->mmio_base, address) & 0x1)) {
196 "Queue-PF/VF mapping is not set! Was PF configured for device (%s) ?",
201 /* Clear queue registers structure */
202 memset(&ring_reg, 0, sizeof(struct fpga_ring_ctrl_reg));
205 * If a queue is valid and mapped to a calling PF/VF the read value is
206 * replaced with a queue ID and if it's not then
207 * FPGA_INVALID_HW_QUEUE_ID is returned.
209 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
210 uint32_t hw_q_id = fpga_reg_read_32(fpga_dev->mmio_base,
211 FPGA_5GNR_FEC_QUEUE_MAP + (q_id << 2));
213 rte_bbdev_log_debug("%s: queue ID: %u, registry queue ID: %u",
214 dev->device->name, q_id, hw_q_id);
216 if (hw_q_id != FPGA_INVALID_HW_QUEUE_ID) {
217 fpga_dev->q_bound_bit_map |= (1ULL << q_id);
218 /* Clear queue register of found queue */
219 offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
220 (sizeof(struct fpga_ring_ctrl_reg) * q_id);
221 fpga_ring_reg_write(fpga_dev->mmio_base,
228 "No HW queues assigned to this device. Probably this is a VF configured for PF mode. Check device configuration!");
232 if (num_queues > hw_q_num) {
234 "Not enough queues for device %s! Requested: %u, available: %u",
235 dev->device->name, num_queues, hw_q_num);
239 ring_size = FPGA_RING_MAX_SIZE * sizeof(struct fpga_dma_dec_desc);
241 /* Enforce 32 byte alignment */
242 RTE_BUILD_BUG_ON((RTE_CACHE_LINE_SIZE % 32) != 0);
244 /* Allocate memory for SW descriptor rings */
245 fpga_dev->sw_rings = rte_zmalloc_socket(dev->device->driver->name,
246 num_queues * ring_size, RTE_CACHE_LINE_SIZE,
248 if (fpga_dev->sw_rings == NULL) {
250 "Failed to allocate memory for %s:%u sw_rings",
251 dev->device->driver->name, dev->data->dev_id);
255 fpga_dev->sw_rings_phys = rte_malloc_virt2iova(fpga_dev->sw_rings);
256 fpga_dev->sw_ring_size = ring_size;
257 fpga_dev->sw_ring_max_depth = FPGA_RING_MAX_SIZE;
259 /* Allocate memory for ring flush status */
260 fpga_dev->flush_queue_status = rte_zmalloc_socket(NULL,
261 sizeof(uint64_t), RTE_CACHE_LINE_SIZE, socket_id);
262 if (fpga_dev->flush_queue_status == NULL) {
264 "Failed to allocate memory for %s:%u flush_queue_status",
265 dev->device->driver->name, dev->data->dev_id);
269 /* Set the flush status address registers */
270 phys_addr = rte_malloc_virt2iova(fpga_dev->flush_queue_status);
272 address = FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_LW;
273 payload = (uint32_t)(phys_addr);
274 fpga_reg_write_32(fpga_dev->mmio_base, address, payload);
276 address = FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_HI;
277 payload = (uint32_t)(phys_addr >> 32);
278 fpga_reg_write_32(fpga_dev->mmio_base, address, payload);
284 fpga_dev_close(struct rte_bbdev *dev)
286 struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
288 rte_free(fpga_dev->sw_rings);
289 rte_free(fpga_dev->flush_queue_status);
295 fpga_dev_info_get(struct rte_bbdev *dev,
296 struct rte_bbdev_driver_info *dev_info)
298 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
301 static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
303 .type = RTE_BBDEV_OP_LDPC_ENC,
306 RTE_BBDEV_LDPC_RATE_MATCH |
307 RTE_BBDEV_LDPC_ENC_INTERRUPTS |
308 RTE_BBDEV_LDPC_CRC_24B_ATTACH,
310 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
312 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
316 .type = RTE_BBDEV_OP_LDPC_DEC,
319 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
320 RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
321 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
322 RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
323 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE |
324 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE |
325 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE |
326 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK |
327 RTE_BBDEV_LDPC_DEC_INTERRUPTS |
328 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_FILLERS,
332 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
333 .num_buffers_hard_out =
334 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
335 .num_buffers_soft_out = 0,
338 RTE_BBDEV_END_OF_CAPABILITIES_LIST()
341 /* Check the HARQ DDR size available */
342 uint8_t timeout_counter = 0;
343 uint32_t harq_buf_ready = fpga_reg_read_32(d->mmio_base,
344 FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS);
345 while (harq_buf_ready != 1) {
346 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
348 harq_buf_ready = fpga_reg_read_32(d->mmio_base,
349 FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS);
350 if (timeout_counter > FPGA_HARQ_RDY_TIMEOUT) {
351 rte_bbdev_log(ERR, "HARQ Buffer not ready %d",
356 uint32_t harq_buf_size = fpga_reg_read_32(d->mmio_base,
357 FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
359 static struct rte_bbdev_queue_conf default_queue_conf;
360 default_queue_conf.socket = dev->data->socket_id;
361 default_queue_conf.queue_size = FPGA_RING_MAX_SIZE;
363 dev_info->driver_name = dev->device->driver->name;
364 dev_info->queue_size_lim = FPGA_RING_MAX_SIZE;
365 dev_info->hardware_accelerated = true;
366 dev_info->min_alignment = 64;
367 dev_info->harq_buffer_size = (harq_buf_size >> 10) + 1;
368 dev_info->default_queue_conf = default_queue_conf;
369 dev_info->capabilities = bbdev_capabilities;
370 dev_info->cpu_flag_reqs = NULL;
371 dev_info->data_endianness = RTE_LITTLE_ENDIAN;
373 /* Calculates number of queues assigned to device */
374 dev_info->max_num_queues = 0;
375 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
376 uint32_t hw_q_id = fpga_reg_read_32(d->mmio_base,
377 FPGA_5GNR_FEC_QUEUE_MAP + (q_id << 2));
378 if (hw_q_id != FPGA_INVALID_HW_QUEUE_ID)
379 dev_info->max_num_queues++;
384 * Find index of queue bound to current PF/VF which is unassigned. Return -1
385 * when there is no available queue
388 fpga_find_free_queue_idx(struct rte_bbdev *dev,
389 const struct rte_bbdev_queue_conf *conf)
391 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
394 uint8_t range = FPGA_TOTAL_NUM_QUEUES >> 1;
396 if (conf->op_type == RTE_BBDEV_OP_LDPC_ENC) {
397 i = FPGA_NUM_DL_QUEUES;
398 range = FPGA_TOTAL_NUM_QUEUES;
401 for (; i < range; ++i) {
403 /* Check if index of queue is bound to current PF/VF */
404 if (d->q_bound_bit_map & q_idx)
405 /* Check if found queue was not already assigned */
406 if (!(d->q_assigned_bit_map & q_idx)) {
407 d->q_assigned_bit_map |= q_idx;
412 rte_bbdev_log(INFO, "Failed to find free queue on %s", dev->data->name);
418 fpga_queue_setup(struct rte_bbdev *dev, uint16_t queue_id,
419 const struct rte_bbdev_queue_conf *conf)
421 uint32_t address, ring_offset;
422 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
423 struct fpga_queue *q;
426 /* Check if there is a free queue to assign */
427 q_idx = fpga_find_free_queue_idx(dev, conf);
431 /* Allocate the queue data structure. */
432 q = rte_zmalloc_socket(dev->device->driver->name, sizeof(*q),
433 RTE_CACHE_LINE_SIZE, conf->socket);
435 /* Mark queue as un-assigned */
436 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
437 rte_bbdev_log(ERR, "Failed to allocate queue memory");
444 /* Set ring_base_addr */
445 q->ring_addr = RTE_PTR_ADD(d->sw_rings, (d->sw_ring_size * queue_id));
446 q->ring_ctrl_reg.ring_base_addr = d->sw_rings_phys +
447 (d->sw_ring_size * queue_id);
449 /* Allocate memory for Completion Head variable*/
450 q->ring_head_addr = rte_zmalloc_socket(dev->device->driver->name,
451 sizeof(uint64_t), RTE_CACHE_LINE_SIZE, conf->socket);
452 if (q->ring_head_addr == NULL) {
453 /* Mark queue as un-assigned */
454 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
457 "Failed to allocate memory for %s:%u completion_head",
458 dev->device->driver->name, dev->data->dev_id);
461 /* Set ring_head_addr */
462 q->ring_ctrl_reg.ring_head_addr =
463 rte_malloc_virt2iova(q->ring_head_addr);
465 /* Clear shadow_completion_head */
466 q->shadow_completion_head = 0;
469 if (conf->queue_size > FPGA_RING_MAX_SIZE) {
470 /* Mark queue as un-assigned */
471 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
472 rte_free(q->ring_head_addr);
475 "Size of queue is too big %d (MAX: %d ) for %s:%u",
476 conf->queue_size, FPGA_RING_MAX_SIZE,
477 dev->device->driver->name, dev->data->dev_id);
480 q->ring_ctrl_reg.ring_size = conf->queue_size;
482 /* Set Miscellaneous FPGA register*/
483 /* Max iteration number for TTI mitigation - todo */
484 q->ring_ctrl_reg.max_ul_dec = 0;
485 /* Enable max iteration number for TTI - todo */
486 q->ring_ctrl_reg.max_ul_dec_en = 0;
488 /* Enable the ring */
489 q->ring_ctrl_reg.enable = 1;
491 /* Set FPGA head_point and tail registers */
492 q->ring_ctrl_reg.head_point = q->tail = 0;
494 /* Set FPGA shadow_tail register */
495 q->ring_ctrl_reg.shadow_tail = q->tail;
497 /* Calculates the ring offset for found queue */
498 ring_offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
499 (sizeof(struct fpga_ring_ctrl_reg) * q_idx);
501 /* Set FPGA Ring Control Registers */
502 fpga_ring_reg_write(d->mmio_base, ring_offset, q->ring_ctrl_reg);
504 /* Store MMIO register of shadow_tail */
505 address = ring_offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL;
506 q->shadow_tail_addr = RTE_PTR_ADD(d->mmio_base, address);
508 q->head_free_desc = q->tail;
511 q->sw_ring_wrap_mask = conf->queue_size - 1;
513 rte_bbdev_log_debug("Setup dev%u q%u: queue_idx=%u",
514 dev->data->dev_id, queue_id, q->q_idx);
516 dev->data->queues[queue_id].queue_private = q;
518 rte_bbdev_log_debug("BBDEV queue[%d] set up for FPGA queue[%d]",
521 #ifdef RTE_LIBRTE_BBDEV_DEBUG
522 /* Read FPGA Ring Control Registers after configuration*/
523 print_ring_reg_debug_info(d->mmio_base, ring_offset);
529 fpga_queue_release(struct rte_bbdev *dev, uint16_t queue_id)
531 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
532 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
533 struct fpga_ring_ctrl_reg ring_reg;
536 rte_bbdev_log_debug("FPGA Queue[%d] released", queue_id);
539 memset(&ring_reg, 0, sizeof(struct fpga_ring_ctrl_reg));
540 offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
541 (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
543 fpga_reg_write_8(d->mmio_base,
544 offset + FPGA_5GNR_FEC_RING_ENABLE, 0x00);
545 /* Clear queue registers */
546 fpga_ring_reg_write(d->mmio_base, offset, ring_reg);
548 /* Mark the Queue as un-assigned */
549 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q->q_idx));
550 rte_free(q->ring_head_addr);
552 dev->data->queues[queue_id].queue_private = NULL;
558 /* Function starts a device queue. */
560 fpga_queue_start(struct rte_bbdev *dev, uint16_t queue_id)
562 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
563 #ifdef RTE_LIBRTE_BBDEV_DEBUG
565 rte_bbdev_log(ERR, "Invalid device pointer");
569 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
570 uint32_t offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
571 (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
572 uint8_t enable = 0x01;
573 uint16_t zero = 0x0000;
575 /* Clear queue head and tail variables */
576 q->tail = q->head_free_desc = 0;
578 /* Clear FPGA head_point and tail registers */
579 fpga_reg_write_16(d->mmio_base, offset + FPGA_5GNR_FEC_RING_HEAD_POINT,
581 fpga_reg_write_16(d->mmio_base, offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL,
585 fpga_reg_write_8(d->mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE,
588 rte_bbdev_log_debug("FPGA Queue[%d] started", queue_id);
592 /* Function stops a device queue. */
594 fpga_queue_stop(struct rte_bbdev *dev, uint16_t queue_id)
596 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
597 #ifdef RTE_LIBRTE_BBDEV_DEBUG
599 rte_bbdev_log(ERR, "Invalid device pointer");
603 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
604 uint32_t offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
605 (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
606 uint8_t payload = 0x01;
608 uint8_t timeout = FPGA_QUEUE_FLUSH_TIMEOUT_US /
609 FPGA_TIMEOUT_CHECK_INTERVAL;
611 /* Set flush_queue_en bit to trigger queue flushing */
612 fpga_reg_write_8(d->mmio_base,
613 offset + FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN, payload);
615 /** Check if queue flush is completed.
616 * FPGA will update the completion flag after queue flushing is
617 * completed. If completion flag is not updated within 1ms it is
618 * considered as a failure.
620 while (!(*((volatile uint8_t *)d->flush_queue_status + q->q_idx)
622 if (counter > timeout) {
623 rte_bbdev_log(ERR, "FPGA Queue Flush failed for queue %d",
627 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
633 fpga_reg_write_8(d->mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE,
636 rte_bbdev_log_debug("FPGA Queue[%d] stopped", queue_id);
640 static inline uint16_t
641 get_queue_id(struct rte_bbdev_data *data, uint8_t q_idx)
645 for (queue_id = 0; queue_id < data->num_queues; ++queue_id) {
646 struct fpga_queue *q = data->queues[queue_id].queue_private;
647 if (q != NULL && q->q_idx == q_idx)
654 /* Interrupt handler triggered by FPGA dev for handling specific interrupt */
656 fpga_dev_interrupt_handler(void *cb_arg)
658 struct rte_bbdev *dev = cb_arg;
659 struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
660 struct fpga_queue *q;
666 /* Scan queue assigned to this device */
667 for (i = 0; i < FPGA_TOTAL_NUM_QUEUES; ++i) {
669 if (fpga_dev->q_bound_bit_map & q_idx) {
670 queue_id = get_queue_id(dev->data, i);
671 if (queue_id == (uint16_t) -1)
674 /* Check if completion head was changed */
675 q = dev->data->queues[queue_id].queue_private;
676 ring_head = *q->ring_head_addr;
677 if (q->shadow_completion_head != ring_head &&
678 q->irq_enable == 1) {
679 q->shadow_completion_head = ring_head;
680 rte_bbdev_pmd_callback_process(
682 RTE_BBDEV_EVENT_DEQUEUE,
690 fpga_queue_intr_enable(struct rte_bbdev *dev, uint16_t queue_id)
692 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
694 if (!rte_intr_cap_multiple(dev->intr_handle))
703 fpga_queue_intr_disable(struct rte_bbdev *dev, uint16_t queue_id)
705 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
712 fpga_intr_enable(struct rte_bbdev *dev)
717 if (!rte_intr_cap_multiple(dev->intr_handle)) {
718 rte_bbdev_log(ERR, "Multiple intr vector is not supported by FPGA (%s)",
723 /* Create event file descriptors for each of 64 queue. Event fds will be
724 * mapped to FPGA IRQs in rte_intr_enable(). This is a 1:1 mapping where
725 * the IRQ number is a direct translation to the queue number.
727 * 63 (FPGA_NUM_INTR_VEC) event fds are created as rte_intr_enable()
728 * mapped the first IRQ to already created interrupt event file
729 * descriptor (intr_handle->fd).
731 if (rte_intr_efd_enable(dev->intr_handle, FPGA_NUM_INTR_VEC)) {
732 rte_bbdev_log(ERR, "Failed to create fds for %u queues",
733 dev->data->num_queues);
737 /* TODO Each event file descriptor is overwritten by interrupt event
738 * file descriptor. That descriptor is added to epoll observed list.
739 * It ensures that callback function assigned to that descriptor will
740 * invoked when any FPGA queue issues interrupt.
742 for (i = 0; i < FPGA_NUM_INTR_VEC; ++i) {
743 if (rte_intr_efds_index_set(dev->intr_handle, i,
744 rte_intr_fd_get(dev->intr_handle)))
748 if (rte_intr_vec_list_alloc(dev->intr_handle, "intr_vec",
749 dev->data->num_queues)) {
750 rte_bbdev_log(ERR, "Failed to allocate %u vectors",
751 dev->data->num_queues);
755 ret = rte_intr_enable(dev->intr_handle);
758 "Couldn't enable interrupts for device: %s",
763 ret = rte_intr_callback_register(dev->intr_handle,
764 fpga_dev_interrupt_handler, dev);
767 "Couldn't register interrupt callback for device: %s",
775 static const struct rte_bbdev_ops fpga_ops = {
776 .setup_queues = fpga_setup_queues,
777 .intr_enable = fpga_intr_enable,
778 .close = fpga_dev_close,
779 .info_get = fpga_dev_info_get,
780 .queue_setup = fpga_queue_setup,
781 .queue_stop = fpga_queue_stop,
782 .queue_start = fpga_queue_start,
783 .queue_release = fpga_queue_release,
784 .queue_intr_enable = fpga_queue_intr_enable,
785 .queue_intr_disable = fpga_queue_intr_disable
789 fpga_dma_enqueue(struct fpga_queue *q, uint16_t num_desc,
790 struct rte_bbdev_stats *queue_stats)
792 #ifdef RTE_BBDEV_OFFLOAD_COST
793 uint64_t start_time = 0;
794 queue_stats->acc_offload_cycles = 0;
796 RTE_SET_USED(queue_stats);
799 /* Update tail and shadow_tail register */
800 q->tail = (q->tail + num_desc) & q->sw_ring_wrap_mask;
804 #ifdef RTE_BBDEV_OFFLOAD_COST
805 /* Start time measurement for enqueue function offload. */
806 start_time = rte_rdtsc_precise();
808 mmio_write_16(q->shadow_tail_addr, q->tail);
810 #ifdef RTE_BBDEV_OFFLOAD_COST
812 queue_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
816 /* Read flag value 0/1/ from bitmap */
818 check_bit(uint32_t bitmap, uint32_t bitmask)
820 return bitmap & bitmask;
823 /* Print an error if a descriptor error has occurred.
824 * Return 0 on success, 1 on failure
827 check_desc_error(uint32_t error_code) {
828 switch (error_code) {
829 case DESC_ERR_NO_ERR:
831 case DESC_ERR_K_P_OUT_OF_RANGE:
832 rte_bbdev_log(ERR, "Encode block size K' is out of range");
834 case DESC_ERR_Z_C_NOT_LEGAL:
835 rte_bbdev_log(ERR, "Zc is illegal");
837 case DESC_ERR_DESC_OFFSET_ERR:
839 "Queue offset does not meet the expectation in the FPGA"
842 case DESC_ERR_DESC_READ_FAIL:
843 rte_bbdev_log(ERR, "Unsuccessful completion for descriptor read");
845 case DESC_ERR_DESC_READ_TIMEOUT:
846 rte_bbdev_log(ERR, "Descriptor read time-out");
848 case DESC_ERR_DESC_READ_TLP_POISONED:
849 rte_bbdev_log(ERR, "Descriptor read TLP poisoned");
851 case DESC_ERR_HARQ_INPUT_LEN:
852 rte_bbdev_log(ERR, "HARQ input length is invalid");
854 case DESC_ERR_CB_READ_FAIL:
855 rte_bbdev_log(ERR, "Unsuccessful completion for code block");
857 case DESC_ERR_CB_READ_TIMEOUT:
858 rte_bbdev_log(ERR, "Code block read time-out");
860 case DESC_ERR_CB_READ_TLP_POISONED:
861 rte_bbdev_log(ERR, "Code block read TLP poisoned");
863 case DESC_ERR_HBSTORE_ERR:
864 rte_bbdev_log(ERR, "Hbstroe exceeds HARQ buffer size.");
867 rte_bbdev_log(ERR, "Descriptor error unknown error code %u",
874 /* Compute value of k0.
875 * Based on 3GPP 38.212 Table 5.4.2.1-2
876 * Starting position of different redundancy versions, k0
878 static inline uint16_t
879 get_k0(uint16_t n_cb, uint16_t z_c, uint8_t bg, uint8_t rv_index)
883 uint16_t n = (bg == 1 ? N_ZC_1 : N_ZC_2) * z_c;
886 return (bg == 1 ? K0_1_1 : K0_1_2) * z_c;
887 else if (rv_index == 2)
888 return (bg == 1 ? K0_2_1 : K0_2_2) * z_c;
890 return (bg == 1 ? K0_3_1 : K0_3_2) * z_c;
892 /* LBRM case - includes a division by N */
894 return (((bg == 1 ? K0_1_1 : K0_1_2) * n_cb)
896 else if (rv_index == 2)
897 return (((bg == 1 ? K0_2_1 : K0_2_2) * n_cb)
900 return (((bg == 1 ? K0_3_1 : K0_3_2) * n_cb)
905 * Set DMA descriptor for encode operation (1 Code Block)
908 * Pointer to a single encode operation.
910 * Pointer to DMA descriptor.
912 * Pointer to pointer to input data which will be decoded.
914 * E value (length of output in bits).
916 * Ncb value (size of the soft buffer).
918 * Length of output buffer
920 * Input offset in rte_mbuf structure. It is used for calculating the point
921 * where data is starting.
923 * Output offset in rte_mbuf structure. It is used for calculating the point
924 * where hard output data will be stored.
926 * Number of CBs contained in one operation.
929 fpga_dma_desc_te_fill(struct rte_bbdev_enc_op *op,
930 struct fpga_dma_enc_desc *desc, struct rte_mbuf *input,
931 struct rte_mbuf *output, uint16_t k_, uint16_t e,
932 uint32_t in_offset, uint32_t out_offset, uint16_t desc_offset,
940 desc->desc_idx = desc_offset;
941 desc->zc = op->ldpc_enc.z_c;
942 desc->bg_idx = op->ldpc_enc.basegraph - 1;
943 desc->qm_idx = op->ldpc_enc.q_m / 2;
944 desc->crc_en = check_bit(op->ldpc_enc.op_flags,
945 RTE_BBDEV_LDPC_CRC_24B_ATTACH);
947 desc->k0 = get_k0(op->ldpc_enc.n_cb, op->ldpc_enc.z_c,
948 op->ldpc_enc.basegraph, op->ldpc_enc.rv_index);
949 desc->ncb = op->ldpc_enc.n_cb;
950 desc->num_null = op->ldpc_enc.n_filler;
951 /* Set inbound data buffer address */
952 desc->in_addr_hi = (uint32_t)(
953 rte_pktmbuf_iova_offset(input, in_offset) >> 32);
954 desc->in_addr_lw = (uint32_t)(
955 rte_pktmbuf_iova_offset(input, in_offset));
957 desc->out_addr_hi = (uint32_t)(
958 rte_pktmbuf_iova_offset(output, out_offset) >> 32);
959 desc->out_addr_lw = (uint32_t)(
960 rte_pktmbuf_iova_offset(output, out_offset));
961 /* Save software context needed for dequeue */
963 /* Set total number of CBs in an op */
964 desc->cbs_in_op = cbs_in_op;
969 * Set DMA descriptor for decode operation (1 Code Block)
972 * Pointer to a single encode operation.
974 * Pointer to DMA descriptor.
976 * Pointer to pointer to input data which will be decoded.
978 * Input offset in rte_mbuf structure. It is used for calculating the point
979 * where data is starting.
981 * Output offset in rte_mbuf structure. It is used for calculating the point
982 * where hard output data will be stored.
984 * Number of CBs contained in one operation.
987 fpga_dma_desc_ld_fill(struct rte_bbdev_dec_op *op,
988 struct fpga_dma_dec_desc *desc,
989 struct rte_mbuf *input, struct rte_mbuf *output,
990 uint16_t harq_in_length,
991 uint32_t in_offset, uint32_t out_offset,
992 uint32_t harq_offset,
993 uint16_t desc_offset,
999 /* Set inbound data buffer address */
1000 desc->in_addr_hi = (uint32_t)(
1001 rte_pktmbuf_iova_offset(input, in_offset) >> 32);
1002 desc->in_addr_lw = (uint32_t)(
1003 rte_pktmbuf_iova_offset(input, in_offset));
1004 desc->rm_e = op->ldpc_dec.cb_params.e;
1005 desc->harq_input_length = harq_in_length;
1006 desc->et_dis = !check_bit(op->ldpc_dec.op_flags,
1007 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE);
1008 desc->rv = op->ldpc_dec.rv_index;
1009 desc->crc24b_ind = check_bit(op->ldpc_dec.op_flags,
1010 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK);
1011 desc->drop_crc24b = check_bit(op->ldpc_dec.op_flags,
1012 RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP);
1013 desc->desc_idx = desc_offset;
1014 desc->ncb = op->ldpc_dec.n_cb;
1015 desc->num_null = op->ldpc_dec.n_filler;
1016 desc->hbstroe_offset = harq_offset >> 10;
1017 desc->zc = op->ldpc_dec.z_c;
1018 desc->harqin_en = check_bit(op->ldpc_dec.op_flags,
1019 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE);
1020 desc->bg_idx = op->ldpc_dec.basegraph - 1;
1021 desc->max_iter = op->ldpc_dec.iter_max;
1022 desc->qm_idx = op->ldpc_dec.q_m / 2;
1023 desc->out_addr_hi = (uint32_t)(
1024 rte_pktmbuf_iova_offset(output, out_offset) >> 32);
1025 desc->out_addr_lw = (uint32_t)(
1026 rte_pktmbuf_iova_offset(output, out_offset));
1027 /* Save software context needed for dequeue */
1029 /* Set total number of CBs in an op */
1030 desc->cbs_in_op = cbs_in_op;
1035 /* Validates LDPC encoder parameters */
1037 validate_ldpc_enc_op(struct rte_bbdev_enc_op *op)
1039 struct rte_bbdev_op_ldpc_enc *ldpc_enc = &op->ldpc_enc;
1041 if (op->mempool == NULL) {
1042 rte_bbdev_log(ERR, "Invalid mempool pointer");
1045 if (ldpc_enc->input.data == NULL) {
1046 rte_bbdev_log(ERR, "Invalid input pointer");
1049 if (ldpc_enc->output.data == NULL) {
1050 rte_bbdev_log(ERR, "Invalid output pointer");
1053 if (ldpc_enc->input.length == 0) {
1054 rte_bbdev_log(ERR, "CB size (%u) is null",
1055 ldpc_enc->input.length);
1058 if ((ldpc_enc->basegraph > 2) || (ldpc_enc->basegraph == 0)) {
1060 "BG (%u) is out of range 1 <= value <= 2",
1061 ldpc_enc->basegraph);
1064 if (ldpc_enc->rv_index > 3) {
1066 "rv_index (%u) is out of range 0 <= value <= 3",
1067 ldpc_enc->rv_index);
1070 if (ldpc_enc->code_block_mode > RTE_BBDEV_CODE_BLOCK) {
1072 "code_block_mode (%u) is out of range 0 <= value <= 1",
1073 ldpc_enc->code_block_mode);
1077 if (ldpc_enc->input.length >
1078 RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) {
1079 rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
1080 ldpc_enc->input.length,
1081 RTE_BBDEV_LDPC_MAX_CB_SIZE);
1084 int z_c = ldpc_enc->z_c;
1085 /* Check Zc is valid value */
1086 if ((z_c > 384) || (z_c < 4)) {
1087 rte_bbdev_log(ERR, "Zc (%u) is out of range", z_c);
1091 if ((z_c % 32) != 0) {
1092 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1095 } else if (z_c > 128) {
1096 if ((z_c % 16) != 0) {
1097 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1100 } else if (z_c > 64) {
1101 if ((z_c % 8) != 0) {
1102 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1105 } else if (z_c > 32) {
1106 if ((z_c % 4) != 0) {
1107 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1110 } else if (z_c > 16) {
1111 if ((z_c % 2) != 0) {
1112 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1117 int n_filler = ldpc_enc->n_filler;
1118 int K = (ldpc_enc->basegraph == 1 ? 22 : 10) * ldpc_enc->z_c;
1119 int Kp = K - n_filler;
1120 int q_m = ldpc_enc->q_m;
1121 int n_cb = ldpc_enc->n_cb;
1122 int N = (ldpc_enc->basegraph == 1 ? N_ZC_1 : N_ZC_2) * z_c;
1123 int k0 = get_k0(n_cb, z_c, ldpc_enc->basegraph,
1124 ldpc_enc->rv_index);
1126 int32_t L, Lcb, cw, cw_rm;
1127 int32_t e = ldpc_enc->cb_params.e;
1128 if (check_bit(op->ldpc_enc.op_flags,
1129 RTE_BBDEV_LDPC_CRC_24B_ATTACH))
1132 if (K < (int) (ldpc_enc->input.length * 8 + n_filler) + crc24) {
1133 rte_bbdev_log(ERR, "K and F not matching input size %u %u %u",
1134 K, n_filler, ldpc_enc->input.length);
1137 if (ldpc_enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1138 rte_bbdev_log(ERR, "TB mode not supported");
1143 /* K' range check */
1145 rte_bbdev_log(ERR, "K' not byte aligned %u", Kp);
1148 if ((crc24 > 0) && (Kp < 292)) {
1149 rte_bbdev_log(ERR, "Invalid CRC24 for small block %u", Kp);
1153 rte_bbdev_log(ERR, "K' too small %u", Kp);
1156 if (n_filler >= (K - 2 * z_c)) {
1157 rte_bbdev_log(ERR, "K - F invalid %u %u", K, n_filler);
1160 /* Ncb range check */
1161 if ((n_cb > N) || (n_cb < 32) || (n_cb <= (Kp - crc24))) {
1162 rte_bbdev_log(ERR, "Ncb (%u) is out of range K %d N %d", n_cb, K, N);
1165 /* Qm range check */
1166 if (!check_bit(op->ldpc_enc.op_flags, RTE_BBDEV_LDPC_INTERLEAVER_BYPASS) &&
1167 ((q_m == 0) || ((q_m > 2) && ((q_m % 2) == 1)) || (q_m > 8))) {
1168 rte_bbdev_log(ERR, "Qm (%u) is out of range", q_m);
1171 /* K0 range check */
1172 if (((k0 % z_c) > 0) || (k0 >= n_cb) || ((k0 >= (Kp - 2 * z_c))
1173 && (k0 < (K - 2 * z_c)))) {
1174 rte_bbdev_log(ERR, "K0 (%u) is out of range", k0);
1178 if (e <= RTE_MAX(32, z_c)) {
1179 rte_bbdev_log(ERR, "E is too small %"PRIu32"", e);
1183 rte_bbdev_log(ERR, "E is too large for N3000 %"PRIu32" > 64k", e);
1188 rte_bbdev_log(ERR, "E %"PRIu32" not multiple of qm %d", e, q_m);
1192 /* Code word in RM range check */
1193 if (k0 > (Kp - 2 * z_c))
1196 L = k0 + e + n_filler;
1197 Lcb = RTE_MIN(L, n_cb);
1198 if (ldpc_enc->basegraph == 1) {
1199 if (Lcb <= 25 * z_c)
1201 else if (Lcb <= 27 * z_c)
1203 else if (Lcb <= 30 * z_c)
1205 else if (Lcb <= 33 * z_c)
1207 else if (Lcb <= 44 * z_c)
1209 else if (Lcb <= 55 * z_c)
1214 if (Lcb <= 15 * z_c)
1216 else if (Lcb <= 20 * z_c)
1218 else if (Lcb <= 25 * z_c)
1220 else if (Lcb <= 30 * z_c)
1225 if (n_cb < Kp - 2 * z_c)
1227 else if ((Kp - 2 * z_c <= n_cb) && (n_cb < K - 2 * z_c))
1228 cw_rm = Kp - 2 * z_c;
1229 else if ((K - 2 * z_c <= n_cb) && (n_cb < cw))
1230 cw_rm = n_cb - n_filler;
1232 cw_rm = cw - n_filler;
1235 "Invalid Ratematching");
1241 /* Validates LDPC decoder parameters */
1243 validate_ldpc_dec_op(struct rte_bbdev_dec_op *op)
1245 struct rte_bbdev_op_ldpc_dec *ldpc_dec = &op->ldpc_dec;
1246 if (check_bit(ldpc_dec->op_flags,
1247 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK))
1249 if (ldpc_dec->input.data == NULL) {
1250 rte_bbdev_log(ERR, "Invalid input pointer");
1253 if (ldpc_dec->hard_output.data == NULL) {
1254 rte_bbdev_log(ERR, "Invalid output pointer");
1257 if (ldpc_dec->input.length == 0) {
1258 rte_bbdev_log(ERR, "input is null");
1261 if ((ldpc_dec->basegraph > 2) || (ldpc_dec->basegraph == 0)) {
1263 "BG (%u) is out of range 1 <= value <= 2",
1264 ldpc_dec->basegraph);
1267 if (ldpc_dec->iter_max == 0) {
1269 "iter_max (%u) is equal to 0",
1270 ldpc_dec->iter_max);
1273 if (ldpc_dec->rv_index > 3) {
1275 "rv_index (%u) is out of range 0 <= value <= 3",
1276 ldpc_dec->rv_index);
1279 if (ldpc_dec->code_block_mode > RTE_BBDEV_CODE_BLOCK) {
1281 "code_block_mode (%u) is out of range 0 <= value <= 1",
1282 ldpc_dec->code_block_mode);
1285 if (check_bit(op->ldpc_dec.op_flags,
1286 RTE_BBDEV_LDPC_DECODE_BYPASS)) {
1287 rte_bbdev_log(ERR, "Avoid LDPC Decode bypass");
1290 int z_c = ldpc_dec->z_c;
1291 /* Check Zc is valid value */
1292 if ((z_c > 384) || (z_c < 4)) {
1294 "Zc (%u) is out of range",
1299 if ((z_c % 32) != 0) {
1300 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1303 } else if (z_c > 128) {
1304 if ((z_c % 16) != 0) {
1305 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1308 } else if (z_c > 64) {
1309 if ((z_c % 8) != 0) {
1310 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1313 } else if (z_c > 32) {
1314 if ((z_c % 4) != 0) {
1315 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1318 } else if (z_c > 16) {
1319 if ((z_c % 2) != 0) {
1320 rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
1325 int n_filler = ldpc_dec->n_filler;
1326 int K = (ldpc_dec->basegraph == 1 ? 22 : 10) * ldpc_dec->z_c;
1327 int Kp = K - n_filler;
1328 int q_m = ldpc_dec->q_m;
1329 int n_cb = ldpc_dec->n_cb;
1330 int N = (ldpc_dec->basegraph == 1 ? N_ZC_1 : N_ZC_2) * z_c;
1331 int k0 = get_k0(n_cb, z_c, ldpc_dec->basegraph,
1332 ldpc_dec->rv_index);
1334 int32_t L, Lcb, cw, cw_rm;
1335 int32_t e = ldpc_dec->cb_params.e;
1336 if (check_bit(op->ldpc_dec.op_flags,
1337 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK))
1340 if (ldpc_dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1342 "TB mode not supported");
1345 /* Enforce HARQ input length */
1346 ldpc_dec->harq_combined_input.length = RTE_MIN((uint32_t) n_cb,
1347 ldpc_dec->harq_combined_input.length);
1348 if ((ldpc_dec->harq_combined_input.length == 0) &&
1349 check_bit(ldpc_dec->op_flags,
1350 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1352 "HARQ input length (%u) should not be null",
1353 ldpc_dec->harq_combined_input.length);
1356 if ((ldpc_dec->harq_combined_input.length > 0) &&
1357 !check_bit(ldpc_dec->op_flags,
1358 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1359 ldpc_dec->harq_combined_input.length = 0;
1362 /* K' range check */
1365 "K' not byte aligned %u",
1369 if ((crc24 > 0) && (Kp < 292)) {
1371 "Invalid CRC24 for small block %u",
1381 if (n_filler >= (K - 2 * z_c)) {
1383 "K - F invalid %u %u",
1387 /* Ncb range check */
1390 "Ncb (%u) is out of range K %d N %d",
1394 /* Qm range check */
1395 if (!check_bit(op->ldpc_dec.op_flags,
1396 RTE_BBDEV_LDPC_INTERLEAVER_BYPASS) &&
1397 ((q_m == 0) || ((q_m > 2) && ((q_m % 2) == 1))
1400 "Qm (%u) is out of range",
1404 /* K0 range check */
1405 if (((k0 % z_c) > 0) || (k0 >= n_cb) || ((k0 >= (Kp - 2 * z_c))
1406 && (k0 < (K - 2 * z_c)))) {
1408 "K0 (%u) is out of range",
1413 if (e <= RTE_MAX(32, z_c)) {
1426 "E not multiple of qm %d", q_m);
1430 /* Code word in RM range check */
1431 if (k0 > (Kp - 2 * z_c))
1434 L = k0 + e + n_filler;
1435 Lcb = RTE_MIN(n_cb, RTE_MAX(L,
1436 (int32_t) ldpc_dec->harq_combined_input.length));
1437 if (ldpc_dec->basegraph == 1) {
1438 if (Lcb <= 25 * z_c)
1440 else if (Lcb <= 27 * z_c)
1442 else if (Lcb <= 30 * z_c)
1444 else if (Lcb <= 33 * z_c)
1446 else if (Lcb <= 44 * z_c)
1448 else if (Lcb <= 55 * z_c)
1453 if (Lcb <= 15 * z_c)
1455 else if (Lcb <= 20 * z_c)
1457 else if (Lcb <= 25 * z_c)
1459 else if (Lcb <= 30 * z_c)
1464 cw_rm = cw - n_filler;
1467 "Invalid Ratematching");
1473 static inline char *
1474 mbuf_append(struct rte_mbuf *m_head, struct rte_mbuf *m, uint16_t len)
1476 if (unlikely(len > rte_pktmbuf_tailroom(m)))
1479 char *tail = (char *)m->buf_addr + m->data_off + m->data_len;
1480 m->data_len = (uint16_t)(m->data_len + len);
1481 m_head->pkt_len = (m_head->pkt_len + len);
1486 fpga_mutex_acquisition(struct fpga_queue *q)
1488 uint32_t mutex_ctrl, mutex_read, cnt = 0;
1489 /* Assign a unique id for the duration of the DDR access */
1490 q->ddr_mutex_uuid = rand();
1491 /* Request and wait for acquisition of the mutex */
1492 mutex_ctrl = (q->ddr_mutex_uuid << 16) + 1;
1495 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
1496 rte_bbdev_log_debug("Acquiring Mutex for %x\n",
1498 fpga_reg_write_32(q->d->mmio_base,
1499 FPGA_5GNR_FEC_MUTEX,
1501 mutex_read = fpga_reg_read_32(q->d->mmio_base,
1502 FPGA_5GNR_FEC_MUTEX);
1503 rte_bbdev_log_debug("Mutex %x cnt %d owner %x\n",
1504 mutex_read, cnt, q->ddr_mutex_uuid);
1506 } while ((mutex_read >> 16) != q->ddr_mutex_uuid);
1510 fpga_mutex_free(struct fpga_queue *q)
1512 uint32_t mutex_ctrl = q->ddr_mutex_uuid << 16;
1513 fpga_reg_write_32(q->d->mmio_base,
1514 FPGA_5GNR_FEC_MUTEX,
1519 fpga_harq_write_loopback(struct fpga_queue *q,
1520 struct rte_mbuf *harq_input, uint16_t harq_in_length,
1521 uint32_t harq_in_offset, uint32_t harq_out_offset)
1523 fpga_mutex_acquisition(q);
1524 uint32_t out_offset = harq_out_offset;
1525 uint32_t in_offset = harq_in_offset;
1526 uint32_t left_length = harq_in_length;
1527 uint32_t reg_32, increment = 0;
1528 uint64_t *input = NULL;
1529 uint32_t last_transaction = left_length
1530 % FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1533 if (last_transaction > 0)
1534 left_length -= last_transaction;
1537 * Get HARQ buffer size for each VF/PF: When 0x00, there is no
1538 * available DDR space for the corresponding VF/PF.
1540 reg_32 = fpga_reg_read_32(q->d->mmio_base,
1541 FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
1542 if (reg_32 < harq_in_length) {
1543 left_length = reg_32;
1544 rte_bbdev_log(ERR, "HARQ in length > HARQ buffer size\n");
1547 input = (uint64_t *)rte_pktmbuf_mtod_offset(harq_input,
1548 uint8_t *, in_offset);
1550 while (left_length > 0) {
1551 if (fpga_reg_read_8(q->d->mmio_base,
1552 FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS) == 1) {
1553 fpga_reg_write_32(q->d->mmio_base,
1554 FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS,
1556 fpga_reg_write_64(q->d->mmio_base,
1557 FPGA_5GNR_FEC_DDR4_WR_DATA_REGS,
1559 left_length -= FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1560 out_offset += FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1562 fpga_reg_write_8(q->d->mmio_base,
1563 FPGA_5GNR_FEC_DDR4_WR_DONE_REGS, 1);
1566 while (last_transaction > 0) {
1567 if (fpga_reg_read_8(q->d->mmio_base,
1568 FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS) == 1) {
1569 fpga_reg_write_32(q->d->mmio_base,
1570 FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS,
1572 last_word = input[increment];
1573 last_word &= (uint64_t)(1 << (last_transaction * 4))
1575 fpga_reg_write_64(q->d->mmio_base,
1576 FPGA_5GNR_FEC_DDR4_WR_DATA_REGS,
1578 fpga_reg_write_8(q->d->mmio_base,
1579 FPGA_5GNR_FEC_DDR4_WR_DONE_REGS, 1);
1580 last_transaction = 0;
1588 fpga_harq_read_loopback(struct fpga_queue *q,
1589 struct rte_mbuf *harq_output, uint16_t harq_in_length,
1590 uint32_t harq_in_offset, uint32_t harq_out_offset)
1592 fpga_mutex_acquisition(q);
1593 uint32_t left_length, in_offset = harq_in_offset;
1595 uint32_t increment = 0;
1596 uint64_t *input = NULL;
1597 uint32_t last_transaction = harq_in_length
1598 % FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1600 if (last_transaction > 0)
1601 harq_in_length += (8 - last_transaction);
1603 reg = fpga_reg_read_32(q->d->mmio_base,
1604 FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
1605 if (reg < harq_in_length) {
1606 harq_in_length = reg;
1607 rte_bbdev_log(ERR, "HARQ in length > HARQ buffer size\n");
1610 if (!mbuf_append(harq_output, harq_output, harq_in_length)) {
1611 rte_bbdev_log(ERR, "HARQ output buffer warning %d %d\n",
1612 harq_output->buf_len -
1613 rte_pktmbuf_headroom(harq_output),
1615 harq_in_length = harq_output->buf_len -
1616 rte_pktmbuf_headroom(harq_output);
1617 if (!mbuf_append(harq_output, harq_output, harq_in_length)) {
1618 rte_bbdev_log(ERR, "HARQ output buffer issue %d %d\n",
1619 harq_output->buf_len, harq_in_length);
1623 left_length = harq_in_length;
1625 input = (uint64_t *)rte_pktmbuf_mtod_offset(harq_output,
1626 uint8_t *, harq_out_offset);
1628 while (left_length > 0) {
1629 fpga_reg_write_32(q->d->mmio_base,
1630 FPGA_5GNR_FEC_DDR4_RD_ADDR_REGS, in_offset);
1631 fpga_reg_write_8(q->d->mmio_base,
1632 FPGA_5GNR_FEC_DDR4_RD_DONE_REGS, 1);
1633 reg = fpga_reg_read_8(q->d->mmio_base,
1634 FPGA_5GNR_FEC_DDR4_RD_RDY_REGS);
1636 reg = fpga_reg_read_8(q->d->mmio_base,
1637 FPGA_5GNR_FEC_DDR4_RD_RDY_REGS);
1638 if (reg == FPGA_DDR_OVERFLOW) {
1640 "Read address is overflow!\n");
1644 input[increment] = fpga_reg_read_64(q->d->mmio_base,
1645 FPGA_5GNR_FEC_DDR4_RD_DATA_REGS);
1646 left_length -= FPGA_5GNR_FEC_DDR_RD_DATA_LEN_IN_BYTES;
1647 in_offset += FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1649 fpga_reg_write_8(q->d->mmio_base,
1650 FPGA_5GNR_FEC_DDR4_RD_DONE_REGS, 0);
1657 enqueue_ldpc_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op *op,
1658 uint16_t desc_offset)
1660 union fpga_dma_desc *desc;
1662 uint8_t c, crc24_bits = 0;
1663 struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
1664 uint16_t in_offset = enc->input.offset;
1665 uint16_t out_offset = enc->output.offset;
1666 struct rte_mbuf *m_in = enc->input.data;
1667 struct rte_mbuf *m_out = enc->output.data;
1668 struct rte_mbuf *m_out_head = enc->output.data;
1669 uint32_t in_length, out_length, e;
1670 uint16_t total_left = enc->input.length;
1671 uint16_t ring_offset;
1675 if (validate_ldpc_enc_op(op) == -1) {
1676 rte_bbdev_log(ERR, "LDPC encoder validation rejected");
1680 /* Clear op status */
1683 if (m_in == NULL || m_out == NULL) {
1684 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1685 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1689 if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH)
1692 if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
1693 /* For Transport Block mode */
1695 c = enc->tb_params.c;
1696 e = enc->tb_params.ea;
1697 } else { /* For Code Block mode */
1699 e = enc->cb_params.e;
1702 /* Update total_left */
1703 K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
1704 k_ = K - enc->n_filler;
1705 in_length = (k_ - crc24_bits) >> 3;
1706 out_length = (e + 7) >> 3;
1708 total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1710 /* Update offsets */
1711 if (total_left != in_length) {
1712 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1714 "Mismatch between mbuf length and included CBs sizes %d",
1718 mbuf_append(m_out_head, m_out, out_length);
1720 /* Offset into the ring */
1721 ring_offset = ((q->tail + desc_offset) & q->sw_ring_wrap_mask);
1722 /* Setup DMA Descriptor */
1723 desc = q->ring_addr + ring_offset;
1725 ret = fpga_dma_desc_te_fill(op, &desc->enc_req, m_in, m_out,
1726 k_, e, in_offset, out_offset, ring_offset, c);
1727 if (unlikely(ret < 0))
1730 /* Update lengths */
1731 total_left -= in_length;
1732 op->ldpc_enc.output.length += out_length;
1734 if (total_left > 0) {
1736 "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1737 total_left, in_length);
1741 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1742 print_dma_enc_desc_debug_info(desc);
1748 enqueue_ldpc_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op *op,
1749 uint16_t desc_offset)
1751 union fpga_dma_desc *desc;
1753 uint16_t ring_offset;
1755 uint16_t e, in_length, out_length, k0, l, seg_total_left, sys_cols;
1756 uint16_t K, parity_offset, harq_in_length = 0, harq_out_length = 0;
1757 uint16_t crc24_overlap = 0;
1758 struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1759 struct rte_mbuf *m_in = dec->input.data;
1760 struct rte_mbuf *m_out = dec->hard_output.data;
1761 struct rte_mbuf *m_out_head = dec->hard_output.data;
1762 uint16_t in_offset = dec->input.offset;
1763 uint16_t out_offset = dec->hard_output.offset;
1764 uint32_t harq_offset = 0;
1766 if (validate_ldpc_dec_op(op) == -1) {
1767 rte_bbdev_log(ERR, "LDPC decoder validation rejected");
1771 /* Clear op status */
1774 /* Setup DMA Descriptor */
1775 ring_offset = ((q->tail + desc_offset) & q->sw_ring_wrap_mask);
1776 desc = q->ring_addr + ring_offset;
1778 if (check_bit(dec->op_flags,
1779 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK)) {
1780 struct rte_mbuf *harq_in = dec->harq_combined_input.data;
1781 struct rte_mbuf *harq_out = dec->harq_combined_output.data;
1782 harq_in_length = dec->harq_combined_input.length;
1783 uint32_t harq_in_offset = dec->harq_combined_input.offset;
1784 uint32_t harq_out_offset = dec->harq_combined_output.offset;
1786 if (check_bit(dec->op_flags,
1787 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE
1789 ret = fpga_harq_write_loopback(q, harq_in,
1790 harq_in_length, harq_in_offset,
1792 } else if (check_bit(dec->op_flags,
1793 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE
1795 ret = fpga_harq_read_loopback(q, harq_out,
1796 harq_in_length, harq_in_offset,
1798 dec->harq_combined_output.length = harq_in_length;
1800 rte_bbdev_log(ERR, "OP flag Err!");
1803 /* Set descriptor for dequeue */
1804 desc->dec_req.done = 1;
1805 desc->dec_req.error = 0;
1806 desc->dec_req.op_addr = op;
1807 desc->dec_req.cbs_in_op = 1;
1808 /* Mark this dummy descriptor to be dropped by HW */
1809 desc->dec_req.desc_idx = (ring_offset + 1)
1810 & q->sw_ring_wrap_mask;
1811 return ret; /* Error or number of CB */
1814 if (m_in == NULL || m_out == NULL) {
1815 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1816 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1821 e = dec->cb_params.e;
1823 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
1826 sys_cols = (dec->basegraph == 1) ? 22 : 10;
1827 K = sys_cols * dec->z_c;
1828 parity_offset = K - 2 * dec->z_c;
1830 out_length = ((K - crc24_overlap - dec->n_filler) >> 3);
1832 seg_total_left = dec->input.length;
1834 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1835 harq_in_length = RTE_MIN(dec->harq_combined_input.length,
1836 (uint32_t)dec->n_cb);
1839 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
1840 k0 = get_k0(dec->n_cb, dec->z_c,
1841 dec->basegraph, dec->rv_index);
1842 if (k0 > parity_offset)
1845 l = k0 + e + dec->n_filler;
1846 harq_out_length = RTE_MIN(RTE_MAX(harq_in_length, l),
1848 dec->harq_combined_output.length = harq_out_length;
1851 mbuf_append(m_out_head, m_out, out_length);
1852 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE))
1853 harq_offset = dec->harq_combined_input.offset;
1854 else if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE))
1855 harq_offset = dec->harq_combined_output.offset;
1857 if ((harq_offset & 0x3FF) > 0) {
1858 rte_bbdev_log(ERR, "Invalid HARQ offset %d", harq_offset);
1859 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1863 ret = fpga_dma_desc_ld_fill(op, &desc->dec_req, m_in, m_out,
1864 harq_in_length, in_offset, out_offset, harq_offset,
1866 if (unlikely(ret < 0))
1868 /* Update lengths */
1869 seg_total_left -= in_length;
1870 op->ldpc_dec.hard_output.length += out_length;
1871 if (seg_total_left > 0) {
1873 "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1874 seg_total_left, in_length);
1878 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1879 print_dma_dec_desc_debug_info(desc);
1886 fpga_enqueue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
1887 struct rte_bbdev_enc_op **ops, uint16_t num)
1889 uint16_t i, total_enqueued_cbs = 0;
1892 struct fpga_queue *q = q_data->queue_private;
1893 union fpga_dma_desc *desc;
1895 /* Check if queue is not full */
1896 if (unlikely(((q->tail + 1) & q->sw_ring_wrap_mask) ==
1900 /* Calculates available space */
1901 avail = (q->head_free_desc > q->tail) ?
1902 q->head_free_desc - q->tail - 1 :
1903 q->ring_ctrl_reg.ring_size + q->head_free_desc - q->tail - 1;
1905 for (i = 0; i < num; ++i) {
1907 /* Check if there is available space for further
1910 if (unlikely(avail - 1 < 0))
1913 enqueued_cbs = enqueue_ldpc_enc_one_op_cb(q, ops[i],
1914 total_enqueued_cbs);
1916 if (enqueued_cbs < 0)
1919 total_enqueued_cbs += enqueued_cbs;
1921 rte_bbdev_log_debug("enqueuing enc ops [%d/%d] | head %d | tail %d",
1922 total_enqueued_cbs, num,
1923 q->head_free_desc, q->tail);
1926 /* Set interrupt bit for last CB in enqueued ops. FPGA issues interrupt
1927 * only when all previous CBs were already processed.
1929 desc = q->ring_addr + ((q->tail + total_enqueued_cbs - 1)
1930 & q->sw_ring_wrap_mask);
1931 desc->enc_req.irq_en = q->irq_enable;
1933 fpga_dma_enqueue(q, total_enqueued_cbs, &q_data->queue_stats);
1936 q_data->queue_stats.enqueued_count += i;
1937 q_data->queue_stats.enqueue_err_count += num - i;
1943 fpga_enqueue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
1944 struct rte_bbdev_dec_op **ops, uint16_t num)
1946 uint16_t i, total_enqueued_cbs = 0;
1949 struct fpga_queue *q = q_data->queue_private;
1950 union fpga_dma_desc *desc;
1952 /* Check if queue is not full */
1953 if (unlikely(((q->tail + 1) & q->sw_ring_wrap_mask) ==
1957 /* Calculates available space */
1958 avail = (q->head_free_desc > q->tail) ?
1959 q->head_free_desc - q->tail - 1 :
1960 q->ring_ctrl_reg.ring_size + q->head_free_desc - q->tail - 1;
1962 for (i = 0; i < num; ++i) {
1964 /* Check if there is available space for further
1967 if (unlikely(avail - 1 < 0))
1970 enqueued_cbs = enqueue_ldpc_dec_one_op_cb(q, ops[i],
1971 total_enqueued_cbs);
1973 if (enqueued_cbs < 0)
1976 total_enqueued_cbs += enqueued_cbs;
1978 rte_bbdev_log_debug("enqueuing dec ops [%d/%d] | head %d | tail %d",
1979 total_enqueued_cbs, num,
1980 q->head_free_desc, q->tail);
1984 q_data->queue_stats.enqueued_count += i;
1985 q_data->queue_stats.enqueue_err_count += num - i;
1987 /* Set interrupt bit for last CB in enqueued ops. FPGA issues interrupt
1988 * only when all previous CBs were already processed.
1990 desc = q->ring_addr + ((q->tail + total_enqueued_cbs - 1)
1991 & q->sw_ring_wrap_mask);
1992 desc->enc_req.irq_en = q->irq_enable;
1993 fpga_dma_enqueue(q, total_enqueued_cbs, &q_data->queue_stats);
1999 dequeue_ldpc_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
2000 uint16_t desc_offset)
2002 union fpga_dma_desc *desc;
2004 /* Set current desc */
2005 desc = q->ring_addr + ((q->head_free_desc + desc_offset)
2006 & q->sw_ring_wrap_mask);
2009 if (desc->enc_req.done == 0)
2012 /* make sure the response is read atomically */
2015 rte_bbdev_log_debug("DMA response desc %p", desc);
2017 #ifdef RTE_LIBRTE_BBDEV_DEBUG
2018 print_dma_enc_desc_debug_info(desc);
2021 *op = desc->enc_req.op_addr;
2022 /* Check the descriptor error field, return 1 on error */
2023 desc_error = check_desc_error(desc->enc_req.error);
2024 (*op)->status = desc_error << RTE_BBDEV_DATA_ERROR;
2031 dequeue_ldpc_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
2032 uint16_t desc_offset)
2034 union fpga_dma_desc *desc;
2036 /* Set descriptor */
2037 desc = q->ring_addr + ((q->head_free_desc + desc_offset)
2038 & q->sw_ring_wrap_mask);
2040 /* Verify done bit is set */
2041 if (desc->dec_req.done == 0)
2044 /* make sure the response is read atomically */
2047 #ifdef RTE_LIBRTE_BBDEV_DEBUG
2048 print_dma_dec_desc_debug_info(desc);
2051 *op = desc->dec_req.op_addr;
2053 if (check_bit((*op)->ldpc_dec.op_flags,
2054 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK)) {
2059 /* FPGA reports iterations based on round-up minus 1 */
2060 (*op)->ldpc_dec.iter_count = desc->dec_req.iter + 1;
2061 /* CRC Check criteria */
2062 if (desc->dec_req.crc24b_ind && !(desc->dec_req.crcb_pass))
2063 (*op)->status = 1 << RTE_BBDEV_CRC_ERROR;
2064 /* et_pass = 0 when decoder fails */
2065 (*op)->status |= !(desc->dec_req.et_pass) << RTE_BBDEV_SYNDROME_ERROR;
2066 /* Check the descriptor error field, return 1 on error */
2067 desc_error = check_desc_error(desc->dec_req.error);
2068 (*op)->status |= desc_error << RTE_BBDEV_DATA_ERROR;
2073 fpga_dequeue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
2074 struct rte_bbdev_enc_op **ops, uint16_t num)
2076 struct fpga_queue *q = q_data->queue_private;
2077 uint32_t avail = (q->tail - q->head_free_desc) & q->sw_ring_wrap_mask;
2079 uint16_t dequeued_cbs = 0;
2082 for (i = 0; (i < num) && (dequeued_cbs < avail); ++i) {
2083 ret = dequeue_ldpc_enc_one_op_cb(q, &ops[i], dequeued_cbs);
2088 dequeued_cbs += ret;
2090 rte_bbdev_log_debug("dequeuing enc ops [%d/%d] | head %d | tail %d",
2091 dequeued_cbs, num, q->head_free_desc, q->tail);
2095 q->head_free_desc = (q->head_free_desc + dequeued_cbs) &
2096 q->sw_ring_wrap_mask;
2099 q_data->queue_stats.dequeued_count += i;
2105 fpga_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
2106 struct rte_bbdev_dec_op **ops, uint16_t num)
2108 struct fpga_queue *q = q_data->queue_private;
2109 uint32_t avail = (q->tail - q->head_free_desc) & q->sw_ring_wrap_mask;
2111 uint16_t dequeued_cbs = 0;
2114 for (i = 0; (i < num) && (dequeued_cbs < avail); ++i) {
2115 ret = dequeue_ldpc_dec_one_op_cb(q, &ops[i], dequeued_cbs);
2120 dequeued_cbs += ret;
2122 rte_bbdev_log_debug("dequeuing dec ops [%d/%d] | head %d | tail %d",
2123 dequeued_cbs, num, q->head_free_desc, q->tail);
2127 q->head_free_desc = (q->head_free_desc + dequeued_cbs) &
2128 q->sw_ring_wrap_mask;
2131 q_data->queue_stats.dequeued_count += i;
2137 /* Initialization Function */
2139 fpga_5gnr_fec_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
2141 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
2143 dev->dev_ops = &fpga_ops;
2144 dev->enqueue_ldpc_enc_ops = fpga_enqueue_ldpc_enc;
2145 dev->enqueue_ldpc_dec_ops = fpga_enqueue_ldpc_dec;
2146 dev->dequeue_ldpc_enc_ops = fpga_dequeue_ldpc_enc;
2147 dev->dequeue_ldpc_dec_ops = fpga_dequeue_ldpc_dec;
2149 ((struct fpga_5gnr_fec_device *) dev->data->dev_private)->pf_device =
2150 !strcmp(drv->driver.name,
2151 RTE_STR(FPGA_5GNR_FEC_PF_DRIVER_NAME));
2152 ((struct fpga_5gnr_fec_device *) dev->data->dev_private)->mmio_base =
2153 pci_dev->mem_resource[0].addr;
2155 rte_bbdev_log_debug(
2156 "Init device %s [%s] @ virtaddr %p phyaddr %#"PRIx64,
2157 drv->driver.name, dev->data->name,
2158 (void *)pci_dev->mem_resource[0].addr,
2159 pci_dev->mem_resource[0].phys_addr);
2163 fpga_5gnr_fec_probe(struct rte_pci_driver *pci_drv,
2164 struct rte_pci_device *pci_dev)
2166 struct rte_bbdev *bbdev = NULL;
2167 char dev_name[RTE_BBDEV_NAME_MAX_LEN];
2169 if (pci_dev == NULL) {
2170 rte_bbdev_log(ERR, "NULL PCI device");
2174 rte_pci_device_name(&pci_dev->addr, dev_name, sizeof(dev_name));
2176 /* Allocate memory to be used privately by drivers */
2177 bbdev = rte_bbdev_allocate(pci_dev->device.name);
2181 /* allocate device private memory */
2182 bbdev->data->dev_private = rte_zmalloc_socket(dev_name,
2183 sizeof(struct fpga_5gnr_fec_device),
2184 RTE_CACHE_LINE_SIZE,
2185 pci_dev->device.numa_node);
2187 if (bbdev->data->dev_private == NULL) {
2189 "Allocate of %zu bytes for device \"%s\" failed",
2190 sizeof(struct fpga_5gnr_fec_device), dev_name);
2191 rte_bbdev_release(bbdev);
2195 /* Fill HW specific part of device structure */
2196 bbdev->device = &pci_dev->device;
2197 bbdev->intr_handle = pci_dev->intr_handle;
2198 bbdev->data->socket_id = pci_dev->device.numa_node;
2200 /* Invoke FEC FPGA device initialization function */
2201 fpga_5gnr_fec_init(bbdev, pci_drv);
2203 rte_bbdev_log_debug("bbdev id = %u [%s]",
2204 bbdev->data->dev_id, dev_name);
2206 struct fpga_5gnr_fec_device *d = bbdev->data->dev_private;
2207 uint32_t version_id = fpga_reg_read_32(d->mmio_base,
2208 FPGA_5GNR_FEC_VERSION_ID);
2209 rte_bbdev_log(INFO, "FEC FPGA RTL v%u.%u",
2210 ((uint16_t)(version_id >> 16)), ((uint16_t)version_id));
2212 #ifdef RTE_LIBRTE_BBDEV_DEBUG
2213 if (!strcmp(pci_drv->driver.name,
2214 RTE_STR(FPGA_5GNR_FEC_PF_DRIVER_NAME)))
2215 print_static_reg_debug_info(d->mmio_base);
2221 fpga_5gnr_fec_remove(struct rte_pci_device *pci_dev)
2223 struct rte_bbdev *bbdev;
2227 if (pci_dev == NULL)
2231 bbdev = rte_bbdev_get_named_dev(pci_dev->device.name);
2232 if (bbdev == NULL) {
2234 "Couldn't find HW dev \"%s\" to uninitialise it",
2235 pci_dev->device.name);
2238 dev_id = bbdev->data->dev_id;
2240 /* free device private memory before close */
2241 rte_free(bbdev->data->dev_private);
2244 ret = rte_bbdev_close(dev_id);
2247 "Device %i failed to close during uninit: %i",
2250 /* release bbdev from library */
2251 ret = rte_bbdev_release(bbdev);
2253 rte_bbdev_log(ERR, "Device %i failed to uninit: %i", dev_id,
2256 rte_bbdev_log_debug("Destroyed bbdev = %u", dev_id);
2262 set_default_fpga_conf(struct rte_fpga_5gnr_fec_conf *def_conf)
2264 /* clear default configuration before initialization */
2265 memset(def_conf, 0, sizeof(struct rte_fpga_5gnr_fec_conf));
2266 /* Set pf mode to true */
2267 def_conf->pf_mode_en = true;
2269 /* Set ratio between UL and DL to 1:1 (unit of weight is 3 CBs) */
2270 def_conf->ul_bandwidth = 3;
2271 def_conf->dl_bandwidth = 3;
2273 /* Set Load Balance Factor to 64 */
2274 def_conf->dl_load_balance = 64;
2275 def_conf->ul_load_balance = 64;
2278 /* Initial configuration of FPGA 5GNR FEC device */
2280 rte_fpga_5gnr_fec_configure(const char *dev_name,
2281 const struct rte_fpga_5gnr_fec_conf *conf)
2283 uint32_t payload_32, address;
2284 uint16_t payload_16;
2286 uint16_t q_id, vf_id, total_q_id, total_ul_q_id, total_dl_q_id;
2287 struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
2288 struct rte_fpga_5gnr_fec_conf def_conf;
2290 if (bbdev == NULL) {
2292 "Invalid dev_name (%s), or device is not yet initialised",
2297 struct fpga_5gnr_fec_device *d = bbdev->data->dev_private;
2301 "FPGA Configuration was not provided. Default configuration will be loaded.");
2302 set_default_fpga_conf(&def_conf);
2307 * Configure UL:DL ratio.
2311 payload_16 = (conf->dl_bandwidth << 8) | conf->ul_bandwidth;
2312 address = FPGA_5GNR_FEC_CONFIGURATION;
2313 fpga_reg_write_16(d->mmio_base, address, payload_16);
2315 /* Clear all queues registers */
2316 payload_32 = FPGA_INVALID_HW_QUEUE_ID;
2317 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
2318 address = (q_id << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
2319 fpga_reg_write_32(d->mmio_base, address, payload_32);
2323 * If PF mode is enabled allocate all queues for PF only.
2325 * For VF mode each VF can have different number of UL and DL queues.
2326 * Total number of queues to configure cannot exceed FPGA
2327 * capabilities - 64 queues - 32 queues for UL and 32 queues for DL.
2328 * Queues mapping is done according to configuration:
2334 * | conf->vf_dl_queues_number[0] - 1 | 0 |
2335 * | conf->vf_dl_queues_number[0] | 1 |
2337 * | conf->vf_dl_queues_number[1] - 1 | 1 |
2339 * | conf->vf_dl_queues_number[7] - 1 | 7 |
2345 * | conf->vf_ul_queues_number[0] - 1 | 0 |
2346 * | conf->vf_ul_queues_number[0] | 1 |
2348 * | conf->vf_ul_queues_number[1] - 1 | 1 |
2350 * | conf->vf_ul_queues_number[7] - 1 | 7 |
2352 * Example of configuration:
2353 * conf->vf_ul_queues_number[0] = 4; -> 4 UL queues for VF0
2354 * conf->vf_dl_queues_number[0] = 4; -> 4 DL queues for VF0
2355 * conf->vf_ul_queues_number[1] = 2; -> 2 UL queues for VF1
2356 * conf->vf_dl_queues_number[1] = 2; -> 2 DL queues for VF1
2376 if (conf->pf_mode_en) {
2378 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
2379 address = (q_id << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
2380 fpga_reg_write_32(d->mmio_base, address, payload_32);
2383 /* Calculate total number of UL and DL queues to configure */
2384 total_ul_q_id = total_dl_q_id = 0;
2385 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
2386 total_ul_q_id += conf->vf_ul_queues_number[vf_id];
2387 total_dl_q_id += conf->vf_dl_queues_number[vf_id];
2389 total_q_id = total_dl_q_id + total_ul_q_id;
2391 * Check if total number of queues to configure does not exceed
2392 * FPGA capabilities (64 queues - 32 UL and 32 DL queues)
2394 if ((total_ul_q_id > FPGA_NUM_UL_QUEUES) ||
2395 (total_dl_q_id > FPGA_NUM_DL_QUEUES) ||
2396 (total_q_id > FPGA_TOTAL_NUM_QUEUES)) {
2398 "FPGA Configuration failed. Too many queues to configure: UL_Q %u, DL_Q %u, FPGA_Q %u",
2399 total_ul_q_id, total_dl_q_id,
2400 FPGA_TOTAL_NUM_QUEUES);
2404 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
2405 for (q_id = 0; q_id < conf->vf_ul_queues_number[vf_id];
2406 ++q_id, ++total_ul_q_id) {
2407 address = (total_ul_q_id << 2) +
2408 FPGA_5GNR_FEC_QUEUE_MAP;
2409 payload_32 = ((0x80 + vf_id) << 16) | 0x1;
2410 fpga_reg_write_32(d->mmio_base, address,
2415 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
2416 for (q_id = 0; q_id < conf->vf_dl_queues_number[vf_id];
2417 ++q_id, ++total_dl_q_id) {
2418 address = ((total_dl_q_id + FPGA_NUM_UL_QUEUES)
2419 << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
2420 payload_32 = ((0x80 + vf_id) << 16) | 0x1;
2421 fpga_reg_write_32(d->mmio_base, address,
2427 /* Setting Load Balance Factor */
2428 payload_16 = (conf->dl_load_balance << 8) | (conf->ul_load_balance);
2429 address = FPGA_5GNR_FEC_LOAD_BALANCE_FACTOR;
2430 fpga_reg_write_16(d->mmio_base, address, payload_16);
2432 /* Setting length of ring descriptor entry */
2433 payload_16 = FPGA_RING_DESC_ENTRY_LENGTH;
2434 address = FPGA_5GNR_FEC_RING_DESC_LEN;
2435 fpga_reg_write_16(d->mmio_base, address, payload_16);
2437 /* Queue PF/VF mapping table is ready */
2439 address = FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE;
2440 fpga_reg_write_8(d->mmio_base, address, payload_8);
2442 rte_bbdev_log_debug("PF FPGA 5GNR FEC configuration complete for %s",
2445 #ifdef RTE_LIBRTE_BBDEV_DEBUG
2446 print_static_reg_debug_info(d->mmio_base);
2451 /* FPGA 5GNR FEC PCI PF address map */
2452 static struct rte_pci_id pci_id_fpga_5gnr_fec_pf_map[] = {
2454 RTE_PCI_DEVICE(FPGA_5GNR_FEC_VENDOR_ID,
2455 FPGA_5GNR_FEC_PF_DEVICE_ID)
2460 static struct rte_pci_driver fpga_5gnr_fec_pci_pf_driver = {
2461 .probe = fpga_5gnr_fec_probe,
2462 .remove = fpga_5gnr_fec_remove,
2463 .id_table = pci_id_fpga_5gnr_fec_pf_map,
2464 .drv_flags = RTE_PCI_DRV_NEED_MAPPING
2467 /* FPGA 5GNR FEC PCI VF address map */
2468 static struct rte_pci_id pci_id_fpga_5gnr_fec_vf_map[] = {
2470 RTE_PCI_DEVICE(FPGA_5GNR_FEC_VENDOR_ID,
2471 FPGA_5GNR_FEC_VF_DEVICE_ID)
2476 static struct rte_pci_driver fpga_5gnr_fec_pci_vf_driver = {
2477 .probe = fpga_5gnr_fec_probe,
2478 .remove = fpga_5gnr_fec_remove,
2479 .id_table = pci_id_fpga_5gnr_fec_vf_map,
2480 .drv_flags = RTE_PCI_DRV_NEED_MAPPING
2484 RTE_PMD_REGISTER_PCI(FPGA_5GNR_FEC_PF_DRIVER_NAME, fpga_5gnr_fec_pci_pf_driver);
2485 RTE_PMD_REGISTER_PCI_TABLE(FPGA_5GNR_FEC_PF_DRIVER_NAME,
2486 pci_id_fpga_5gnr_fec_pf_map);
2487 RTE_PMD_REGISTER_PCI(FPGA_5GNR_FEC_VF_DRIVER_NAME, fpga_5gnr_fec_pci_vf_driver);
2488 RTE_PMD_REGISTER_PCI_TABLE(FPGA_5GNR_FEC_VF_DRIVER_NAME,
2489 pci_id_fpga_5gnr_fec_vf_map);