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(fpga_5gnr_fec_logtype, pmd.bb.fpga_5gnr_fec, DEBUG);
29 RTE_LOG_REGISTER(fpga_5gnr_fec_logtype, pmd.bb.fpga_5gnr_fec, 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);
86 uint16_t flr_time_out = fpga_reg_read_16(mmio_base,
87 FPGA_5GNR_FEC_FLR_TIME_OUT);
89 rte_bbdev_log_debug("UL.DL Weights = %u.%u",
90 ((uint8_t)config), ((uint8_t)(config >> 8)));
91 rte_bbdev_log_debug("UL.DL Load Balance = %u.%u",
92 ((uint8_t)lb_factor), ((uint8_t)(lb_factor >> 8)));
93 rte_bbdev_log_debug("Queue-PF/VF Mapping Table = %s",
94 (qmap_done > 0) ? "READY" : "NOT-READY");
95 rte_bbdev_log_debug("Ring Descriptor Size = %u bytes",
96 ring_desc_len*FPGA_RING_DESC_LEN_UNIT_BYTES);
97 rte_bbdev_log_debug("FLR Timeout = %f usec",
98 (float)flr_time_out*FPGA_FLR_TIMEOUT_UNIT);
101 /* Print decode DMA Descriptor of FPGA 5GNR Decoder device */
103 print_dma_dec_desc_debug_info(union fpga_dma_desc *desc)
105 rte_bbdev_log_debug("DMA response desc %p\n"
106 "\t-- done(%"PRIu32") | iter(%"PRIu32") | et_pass(%"PRIu32")"
107 " | crcb_pass (%"PRIu32") | error(%"PRIu32")\n"
108 "\t-- qm_idx(%"PRIu32") | max_iter(%"PRIu32") | "
109 "bg_idx (%"PRIu32") | harqin_en(%"PRIu32") | zc(%"PRIu32")\n"
110 "\t-- hbstroe_offset(%"PRIu32") | num_null (%"PRIu32") "
111 "| irq_en(%"PRIu32")\n"
112 "\t-- ncb(%"PRIu32") | desc_idx (%"PRIu32") | "
113 "drop_crc24b(%"PRIu32") | RV (%"PRIu32")\n"
114 "\t-- crc24b_ind(%"PRIu32") | et_dis (%"PRIu32")\n"
115 "\t-- harq_input_length(%"PRIu32") | rm_e(%"PRIu32")\n"
116 "\t-- cbs_in_op(%"PRIu32") | in_add (0x%08"PRIx32"%08"PRIx32")"
117 "| out_add (0x%08"PRIx32"%08"PRIx32")",
119 (uint32_t)desc->dec_req.done,
120 (uint32_t)desc->dec_req.iter,
121 (uint32_t)desc->dec_req.et_pass,
122 (uint32_t)desc->dec_req.crcb_pass,
123 (uint32_t)desc->dec_req.error,
124 (uint32_t)desc->dec_req.qm_idx,
125 (uint32_t)desc->dec_req.max_iter,
126 (uint32_t)desc->dec_req.bg_idx,
127 (uint32_t)desc->dec_req.harqin_en,
128 (uint32_t)desc->dec_req.zc,
129 (uint32_t)desc->dec_req.hbstroe_offset,
130 (uint32_t)desc->dec_req.num_null,
131 (uint32_t)desc->dec_req.irq_en,
132 (uint32_t)desc->dec_req.ncb,
133 (uint32_t)desc->dec_req.desc_idx,
134 (uint32_t)desc->dec_req.drop_crc24b,
135 (uint32_t)desc->dec_req.rv,
136 (uint32_t)desc->dec_req.crc24b_ind,
137 (uint32_t)desc->dec_req.et_dis,
138 (uint32_t)desc->dec_req.harq_input_length,
139 (uint32_t)desc->dec_req.rm_e,
140 (uint32_t)desc->dec_req.cbs_in_op,
141 (uint32_t)desc->dec_req.in_addr_hi,
142 (uint32_t)desc->dec_req.in_addr_lw,
143 (uint32_t)desc->dec_req.out_addr_hi,
144 (uint32_t)desc->dec_req.out_addr_lw);
145 uint32_t *word = (uint32_t *) desc;
146 rte_bbdev_log_debug("%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n"
147 "%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n",
148 word[0], word[1], word[2], word[3],
149 word[4], word[5], word[6], word[7]);
152 /* Print decode DMA Descriptor of FPGA 5GNR encoder device */
154 print_dma_enc_desc_debug_info(union fpga_dma_desc *desc)
156 rte_bbdev_log_debug("DMA response desc %p\n"
157 "%"PRIu32" %"PRIu32"\n"
158 "K' %"PRIu32" E %"PRIu32" desc %"PRIu32" Z %"PRIu32"\n"
159 "BG %"PRIu32" Qm %"PRIu32" CRC %"PRIu32" IRQ %"PRIu32"\n"
160 "k0 %"PRIu32" Ncb %"PRIu32" F %"PRIu32"\n",
162 (uint32_t)desc->enc_req.done,
163 (uint32_t)desc->enc_req.error,
165 (uint32_t)desc->enc_req.k_,
166 (uint32_t)desc->enc_req.rm_e,
167 (uint32_t)desc->enc_req.desc_idx,
168 (uint32_t)desc->enc_req.zc,
170 (uint32_t)desc->enc_req.bg_idx,
171 (uint32_t)desc->enc_req.qm_idx,
172 (uint32_t)desc->enc_req.crc_en,
173 (uint32_t)desc->enc_req.irq_en,
175 (uint32_t)desc->enc_req.k0,
176 (uint32_t)desc->enc_req.ncb,
177 (uint32_t)desc->enc_req.num_null);
178 uint32_t *word = (uint32_t *) desc;
179 rte_bbdev_log_debug("%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n"
180 "%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n",
181 word[0], word[1], word[2], word[3],
182 word[4], word[5], word[6], word[7]);
188 fpga_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id)
190 /* Number of queues bound to a PF/VF */
191 uint32_t hw_q_num = 0;
192 uint32_t ring_size, payload, address, q_id, offset;
193 rte_iova_t phys_addr;
194 struct fpga_ring_ctrl_reg ring_reg;
195 struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
197 address = FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE;
198 if (!(fpga_reg_read_32(fpga_dev->mmio_base, address) & 0x1)) {
200 "Queue-PF/VF mapping is not set! Was PF configured for device (%s) ?",
205 /* Clear queue registers structure */
206 memset(&ring_reg, 0, sizeof(struct fpga_ring_ctrl_reg));
209 * If a queue is valid and mapped to a calling PF/VF the read value is
210 * replaced with a queue ID and if it's not then
211 * FPGA_INVALID_HW_QUEUE_ID is returned.
213 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
214 uint32_t hw_q_id = fpga_reg_read_32(fpga_dev->mmio_base,
215 FPGA_5GNR_FEC_QUEUE_MAP + (q_id << 2));
217 rte_bbdev_log_debug("%s: queue ID: %u, registry queue ID: %u",
218 dev->device->name, q_id, hw_q_id);
220 if (hw_q_id != FPGA_INVALID_HW_QUEUE_ID) {
221 fpga_dev->q_bound_bit_map |= (1ULL << q_id);
222 /* Clear queue register of found queue */
223 offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
224 (sizeof(struct fpga_ring_ctrl_reg) * q_id);
225 fpga_ring_reg_write(fpga_dev->mmio_base,
232 "No HW queues assigned to this device. Probably this is a VF configured for PF mode. Check device configuration!");
236 if (num_queues > hw_q_num) {
238 "Not enough queues for device %s! Requested: %u, available: %u",
239 dev->device->name, num_queues, hw_q_num);
243 ring_size = FPGA_RING_MAX_SIZE * sizeof(struct fpga_dma_dec_desc);
245 /* Enforce 32 byte alignment */
246 RTE_BUILD_BUG_ON((RTE_CACHE_LINE_SIZE % 32) != 0);
248 /* Allocate memory for SW descriptor rings */
249 fpga_dev->sw_rings = rte_zmalloc_socket(dev->device->driver->name,
250 num_queues * ring_size, RTE_CACHE_LINE_SIZE,
252 if (fpga_dev->sw_rings == NULL) {
254 "Failed to allocate memory for %s:%u sw_rings",
255 dev->device->driver->name, dev->data->dev_id);
259 fpga_dev->sw_rings_phys = rte_malloc_virt2iova(fpga_dev->sw_rings);
260 fpga_dev->sw_ring_size = ring_size;
261 fpga_dev->sw_ring_max_depth = FPGA_RING_MAX_SIZE;
263 /* Allocate memory for ring flush status */
264 fpga_dev->flush_queue_status = rte_zmalloc_socket(NULL,
265 sizeof(uint64_t), RTE_CACHE_LINE_SIZE, socket_id);
266 if (fpga_dev->flush_queue_status == NULL) {
268 "Failed to allocate memory for %s:%u flush_queue_status",
269 dev->device->driver->name, dev->data->dev_id);
273 /* Set the flush status address registers */
274 phys_addr = rte_malloc_virt2iova(fpga_dev->flush_queue_status);
276 address = FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_LW;
277 payload = (uint32_t)(phys_addr);
278 fpga_reg_write_32(fpga_dev->mmio_base, address, payload);
280 address = FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_HI;
281 payload = (uint32_t)(phys_addr >> 32);
282 fpga_reg_write_32(fpga_dev->mmio_base, address, payload);
288 fpga_dev_close(struct rte_bbdev *dev)
290 struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
292 rte_free(fpga_dev->sw_rings);
293 rte_free(fpga_dev->flush_queue_status);
299 fpga_dev_info_get(struct rte_bbdev *dev,
300 struct rte_bbdev_driver_info *dev_info)
302 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
305 static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
307 .type = RTE_BBDEV_OP_LDPC_ENC,
310 RTE_BBDEV_LDPC_RATE_MATCH |
311 RTE_BBDEV_LDPC_ENC_INTERRUPTS |
312 RTE_BBDEV_LDPC_CRC_24B_ATTACH,
314 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
316 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
320 .type = RTE_BBDEV_OP_LDPC_DEC,
323 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
324 RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
325 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
326 RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
327 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE |
328 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE |
329 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE |
330 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK |
331 RTE_BBDEV_LDPC_DEC_INTERRUPTS |
332 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_FILLERS,
336 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
337 .num_buffers_hard_out =
338 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
339 .num_buffers_soft_out = 0,
342 RTE_BBDEV_END_OF_CAPABILITIES_LIST()
345 /* Check the HARQ DDR size available */
346 uint8_t timeout_counter = 0;
347 uint32_t harq_buf_ready = fpga_reg_read_32(d->mmio_base,
348 FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS);
349 while (harq_buf_ready != 1) {
350 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
352 harq_buf_ready = fpga_reg_read_32(d->mmio_base,
353 FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS);
354 if (timeout_counter > FPGA_HARQ_RDY_TIMEOUT) {
355 rte_bbdev_log(ERR, "HARQ Buffer not ready %d",
360 uint32_t harq_buf_size = fpga_reg_read_32(d->mmio_base,
361 FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
363 static struct rte_bbdev_queue_conf default_queue_conf;
364 default_queue_conf.socket = dev->data->socket_id;
365 default_queue_conf.queue_size = FPGA_RING_MAX_SIZE;
367 dev_info->driver_name = dev->device->driver->name;
368 dev_info->queue_size_lim = FPGA_RING_MAX_SIZE;
369 dev_info->hardware_accelerated = true;
370 dev_info->min_alignment = 64;
371 dev_info->harq_buffer_size = (harq_buf_size >> 10) + 1;
372 dev_info->default_queue_conf = default_queue_conf;
373 dev_info->capabilities = bbdev_capabilities;
374 dev_info->cpu_flag_reqs = NULL;
376 /* Calculates number of queues assigned to device */
377 dev_info->max_num_queues = 0;
378 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
379 uint32_t hw_q_id = fpga_reg_read_32(d->mmio_base,
380 FPGA_5GNR_FEC_QUEUE_MAP + (q_id << 2));
381 if (hw_q_id != FPGA_INVALID_HW_QUEUE_ID)
382 dev_info->max_num_queues++;
387 * Find index of queue bound to current PF/VF which is unassigned. Return -1
388 * when there is no available queue
391 fpga_find_free_queue_idx(struct rte_bbdev *dev,
392 const struct rte_bbdev_queue_conf *conf)
394 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
397 uint8_t range = FPGA_TOTAL_NUM_QUEUES >> 1;
399 if (conf->op_type == RTE_BBDEV_OP_LDPC_ENC) {
400 i = FPGA_NUM_DL_QUEUES;
401 range = FPGA_TOTAL_NUM_QUEUES;
404 for (; i < range; ++i) {
406 /* Check if index of queue is bound to current PF/VF */
407 if (d->q_bound_bit_map & q_idx)
408 /* Check if found queue was not already assigned */
409 if (!(d->q_assigned_bit_map & q_idx)) {
410 d->q_assigned_bit_map |= q_idx;
415 rte_bbdev_log(INFO, "Failed to find free queue on %s", dev->data->name);
421 fpga_queue_setup(struct rte_bbdev *dev, uint16_t queue_id,
422 const struct rte_bbdev_queue_conf *conf)
424 uint32_t address, ring_offset;
425 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
426 struct fpga_queue *q;
429 /* Check if there is a free queue to assign */
430 q_idx = fpga_find_free_queue_idx(dev, conf);
434 /* Allocate the queue data structure. */
435 q = rte_zmalloc_socket(dev->device->driver->name, sizeof(*q),
436 RTE_CACHE_LINE_SIZE, conf->socket);
438 /* Mark queue as un-assigned */
439 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
440 rte_bbdev_log(ERR, "Failed to allocate queue memory");
447 /* Set ring_base_addr */
448 q->ring_addr = RTE_PTR_ADD(d->sw_rings, (d->sw_ring_size * queue_id));
449 q->ring_ctrl_reg.ring_base_addr = d->sw_rings_phys +
450 (d->sw_ring_size * queue_id);
452 /* Allocate memory for Completion Head variable*/
453 q->ring_head_addr = rte_zmalloc_socket(dev->device->driver->name,
454 sizeof(uint64_t), RTE_CACHE_LINE_SIZE, conf->socket);
455 if (q->ring_head_addr == NULL) {
456 /* Mark queue as un-assigned */
457 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
460 "Failed to allocate memory for %s:%u completion_head",
461 dev->device->driver->name, dev->data->dev_id);
464 /* Set ring_head_addr */
465 q->ring_ctrl_reg.ring_head_addr =
466 rte_malloc_virt2iova(q->ring_head_addr);
468 /* Clear shadow_completion_head */
469 q->shadow_completion_head = 0;
472 if (conf->queue_size > FPGA_RING_MAX_SIZE) {
473 /* Mark queue as un-assigned */
474 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
475 rte_free(q->ring_head_addr);
478 "Size of queue is too big %d (MAX: %d ) for %s:%u",
479 conf->queue_size, FPGA_RING_MAX_SIZE,
480 dev->device->driver->name, dev->data->dev_id);
483 q->ring_ctrl_reg.ring_size = conf->queue_size;
485 /* Set Miscellaneous FPGA register*/
486 /* Max iteration number for TTI mitigation - todo */
487 q->ring_ctrl_reg.max_ul_dec = 0;
488 /* Enable max iteration number for TTI - todo */
489 q->ring_ctrl_reg.max_ul_dec_en = 0;
491 /* Enable the ring */
492 q->ring_ctrl_reg.enable = 1;
494 /* Set FPGA head_point and tail registers */
495 q->ring_ctrl_reg.head_point = q->tail = 0;
497 /* Set FPGA shadow_tail register */
498 q->ring_ctrl_reg.shadow_tail = q->tail;
500 /* Calculates the ring offset for found queue */
501 ring_offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
502 (sizeof(struct fpga_ring_ctrl_reg) * q_idx);
504 /* Set FPGA Ring Control Registers */
505 fpga_ring_reg_write(d->mmio_base, ring_offset, q->ring_ctrl_reg);
507 /* Store MMIO register of shadow_tail */
508 address = ring_offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL;
509 q->shadow_tail_addr = RTE_PTR_ADD(d->mmio_base, address);
511 q->head_free_desc = q->tail;
514 q->sw_ring_wrap_mask = conf->queue_size - 1;
516 rte_bbdev_log_debug("Setup dev%u q%u: queue_idx=%u",
517 dev->data->dev_id, queue_id, q->q_idx);
519 dev->data->queues[queue_id].queue_private = q;
521 rte_bbdev_log_debug("BBDEV queue[%d] set up for FPGA queue[%d]",
524 #ifdef RTE_LIBRTE_BBDEV_DEBUG
525 /* Read FPGA Ring Control Registers after configuration*/
526 print_ring_reg_debug_info(d->mmio_base, ring_offset);
532 fpga_queue_release(struct rte_bbdev *dev, uint16_t queue_id)
534 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
535 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
536 struct fpga_ring_ctrl_reg ring_reg;
539 rte_bbdev_log_debug("FPGA Queue[%d] released", queue_id);
542 memset(&ring_reg, 0, sizeof(struct fpga_ring_ctrl_reg));
543 offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
544 (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
546 fpga_reg_write_8(d->mmio_base,
547 offset + FPGA_5GNR_FEC_RING_ENABLE, 0x00);
548 /* Clear queue registers */
549 fpga_ring_reg_write(d->mmio_base, offset, ring_reg);
551 /* Mark the Queue as un-assigned */
552 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q->q_idx));
553 rte_free(q->ring_head_addr);
555 dev->data->queues[queue_id].queue_private = NULL;
561 /* Function starts a device queue. */
563 fpga_queue_start(struct rte_bbdev *dev, uint16_t queue_id)
565 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
566 #ifdef RTE_LIBRTE_BBDEV_DEBUG
568 rte_bbdev_log(ERR, "Invalid device pointer");
572 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
573 uint32_t offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
574 (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
575 uint8_t enable = 0x01;
576 uint16_t zero = 0x0000;
578 /* Clear queue head and tail variables */
579 q->tail = q->head_free_desc = 0;
581 /* Clear FPGA head_point and tail registers */
582 fpga_reg_write_16(d->mmio_base, offset + FPGA_5GNR_FEC_RING_HEAD_POINT,
584 fpga_reg_write_16(d->mmio_base, offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL,
588 fpga_reg_write_8(d->mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE,
591 rte_bbdev_log_debug("FPGA Queue[%d] started", queue_id);
595 /* Function stops a device queue. */
597 fpga_queue_stop(struct rte_bbdev *dev, uint16_t queue_id)
599 struct fpga_5gnr_fec_device *d = dev->data->dev_private;
600 #ifdef RTE_LIBRTE_BBDEV_DEBUG
602 rte_bbdev_log(ERR, "Invalid device pointer");
606 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
607 uint32_t offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
608 (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
609 uint8_t payload = 0x01;
611 uint8_t timeout = FPGA_QUEUE_FLUSH_TIMEOUT_US /
612 FPGA_TIMEOUT_CHECK_INTERVAL;
614 /* Set flush_queue_en bit to trigger queue flushing */
615 fpga_reg_write_8(d->mmio_base,
616 offset + FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN, payload);
618 /** Check if queue flush is completed.
619 * FPGA will update the completion flag after queue flushing is
620 * completed. If completion flag is not updated within 1ms it is
621 * considered as a failure.
623 while (!(*((volatile uint8_t *)d->flush_queue_status + q->q_idx)
625 if (counter > timeout) {
626 rte_bbdev_log(ERR, "FPGA Queue Flush failed for queue %d",
630 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
636 fpga_reg_write_8(d->mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE,
639 rte_bbdev_log_debug("FPGA Queue[%d] stopped", queue_id);
643 static inline uint16_t
644 get_queue_id(struct rte_bbdev_data *data, uint8_t q_idx)
648 for (queue_id = 0; queue_id < data->num_queues; ++queue_id) {
649 struct fpga_queue *q = data->queues[queue_id].queue_private;
650 if (q != NULL && q->q_idx == q_idx)
657 /* Interrupt handler triggered by FPGA dev for handling specific interrupt */
659 fpga_dev_interrupt_handler(void *cb_arg)
661 struct rte_bbdev *dev = cb_arg;
662 struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
663 struct fpga_queue *q;
669 /* Scan queue assigned to this device */
670 for (i = 0; i < FPGA_TOTAL_NUM_QUEUES; ++i) {
672 if (fpga_dev->q_bound_bit_map & q_idx) {
673 queue_id = get_queue_id(dev->data, i);
674 if (queue_id == (uint16_t) -1)
677 /* Check if completion head was changed */
678 q = dev->data->queues[queue_id].queue_private;
679 ring_head = *q->ring_head_addr;
680 if (q->shadow_completion_head != ring_head &&
681 q->irq_enable == 1) {
682 q->shadow_completion_head = ring_head;
683 rte_bbdev_pmd_callback_process(
685 RTE_BBDEV_EVENT_DEQUEUE,
693 fpga_queue_intr_enable(struct rte_bbdev *dev, uint16_t queue_id)
695 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
697 if (!rte_intr_cap_multiple(dev->intr_handle))
706 fpga_queue_intr_disable(struct rte_bbdev *dev, uint16_t queue_id)
708 struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
715 fpga_intr_enable(struct rte_bbdev *dev)
720 if (!rte_intr_cap_multiple(dev->intr_handle)) {
721 rte_bbdev_log(ERR, "Multiple intr vector is not supported by FPGA (%s)",
726 /* Create event file descriptors for each of 64 queue. Event fds will be
727 * mapped to FPGA IRQs in rte_intr_enable(). This is a 1:1 mapping where
728 * the IRQ number is a direct translation to the queue number.
730 * 63 (FPGA_NUM_INTR_VEC) event fds are created as rte_intr_enable()
731 * mapped the first IRQ to already created interrupt event file
732 * descriptor (intr_handle->fd).
734 if (rte_intr_efd_enable(dev->intr_handle, FPGA_NUM_INTR_VEC)) {
735 rte_bbdev_log(ERR, "Failed to create fds for %u queues",
736 dev->data->num_queues);
740 /* TODO Each event file descriptor is overwritten by interrupt event
741 * file descriptor. That descriptor is added to epoll observed list.
742 * It ensures that callback function assigned to that descriptor will
743 * invoked when any FPGA queue issues interrupt.
745 for (i = 0; i < FPGA_NUM_INTR_VEC; ++i)
746 dev->intr_handle->efds[i] = dev->intr_handle->fd;
748 if (!dev->intr_handle->intr_vec) {
749 dev->intr_handle->intr_vec = rte_zmalloc("intr_vec",
750 dev->data->num_queues * sizeof(int), 0);
751 if (!dev->intr_handle->intr_vec) {
752 rte_bbdev_log(ERR, "Failed to allocate %u vectors",
753 dev->data->num_queues);
758 ret = rte_intr_enable(dev->intr_handle);
761 "Couldn't enable interrupts for device: %s",
766 ret = rte_intr_callback_register(dev->intr_handle,
767 fpga_dev_interrupt_handler, dev);
770 "Couldn't register interrupt callback for device: %s",
778 static const struct rte_bbdev_ops fpga_ops = {
779 .setup_queues = fpga_setup_queues,
780 .intr_enable = fpga_intr_enable,
781 .close = fpga_dev_close,
782 .info_get = fpga_dev_info_get,
783 .queue_setup = fpga_queue_setup,
784 .queue_stop = fpga_queue_stop,
785 .queue_start = fpga_queue_start,
786 .queue_release = fpga_queue_release,
787 .queue_intr_enable = fpga_queue_intr_enable,
788 .queue_intr_disable = fpga_queue_intr_disable
792 fpga_dma_enqueue(struct fpga_queue *q, uint16_t num_desc,
793 struct rte_bbdev_stats *queue_stats)
795 #ifdef RTE_BBDEV_OFFLOAD_COST
796 uint64_t start_time = 0;
797 queue_stats->acc_offload_cycles = 0;
799 RTE_SET_USED(queue_stats);
802 /* Update tail and shadow_tail register */
803 q->tail = (q->tail + num_desc) & q->sw_ring_wrap_mask;
807 #ifdef RTE_BBDEV_OFFLOAD_COST
808 /* Start time measurement for enqueue function offload. */
809 start_time = rte_rdtsc_precise();
811 mmio_write_16(q->shadow_tail_addr, q->tail);
813 #ifdef RTE_BBDEV_OFFLOAD_COST
815 queue_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
819 /* Read flag value 0/1/ from bitmap */
821 check_bit(uint32_t bitmap, uint32_t bitmask)
823 return bitmap & bitmask;
826 /* Print an error if a descriptor error has occurred.
827 * Return 0 on success, 1 on failure
830 check_desc_error(uint32_t error_code) {
831 switch (error_code) {
832 case DESC_ERR_NO_ERR:
834 case DESC_ERR_K_P_OUT_OF_RANGE:
835 rte_bbdev_log(ERR, "Encode block size K' is out of range");
837 case DESC_ERR_Z_C_NOT_LEGAL:
838 rte_bbdev_log(ERR, "Zc is illegal");
840 case DESC_ERR_DESC_OFFSET_ERR:
842 "Queue offset does not meet the expectation in the FPGA"
845 case DESC_ERR_DESC_READ_FAIL:
846 rte_bbdev_log(ERR, "Unsuccessful completion for descriptor read");
848 case DESC_ERR_DESC_READ_TIMEOUT:
849 rte_bbdev_log(ERR, "Descriptor read time-out");
851 case DESC_ERR_DESC_READ_TLP_POISONED:
852 rte_bbdev_log(ERR, "Descriptor read TLP poisoned");
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_mtophys_offset(input, in_offset) >> 32);
954 desc->in_addr_lw = (uint32_t)(
955 rte_pktmbuf_mtophys_offset(input, in_offset));
957 desc->out_addr_hi = (uint32_t)(
958 rte_pktmbuf_mtophys_offset(output, out_offset) >> 32);
959 desc->out_addr_lw = (uint32_t)(
960 rte_pktmbuf_mtophys_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_mtophys_offset(input, in_offset) >> 32);
1002 desc->in_addr_lw = (uint32_t)(
1003 rte_pktmbuf_mtophys_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_mtophys_offset(output, out_offset) >> 32);
1025 desc->out_addr_lw = (uint32_t)(
1026 rte_pktmbuf_mtophys_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 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1036 /* Validates LDPC encoder parameters */
1038 validate_enc_op(struct rte_bbdev_enc_op *op __rte_unused)
1040 struct rte_bbdev_op_ldpc_enc *ldpc_enc = &op->ldpc_enc;
1041 struct rte_bbdev_op_enc_ldpc_cb_params *cb = NULL;
1042 struct rte_bbdev_op_enc_ldpc_tb_params *tb = NULL;
1045 if (ldpc_enc->input.length >
1046 RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) {
1047 rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
1048 ldpc_enc->input.length,
1049 RTE_BBDEV_LDPC_MAX_CB_SIZE);
1053 if (op->mempool == NULL) {
1054 rte_bbdev_log(ERR, "Invalid mempool pointer");
1057 if (ldpc_enc->input.data == NULL) {
1058 rte_bbdev_log(ERR, "Invalid input pointer");
1061 if (ldpc_enc->output.data == NULL) {
1062 rte_bbdev_log(ERR, "Invalid output pointer");
1065 if ((ldpc_enc->basegraph > 2) || (ldpc_enc->basegraph == 0)) {
1067 "basegraph (%u) is out of range 1 <= value <= 2",
1068 ldpc_enc->basegraph);
1071 if (ldpc_enc->code_block_mode > 1) {
1073 "code_block_mode (%u) is out of range 0:Tb 1:CB",
1074 ldpc_enc->code_block_mode);
1078 if (ldpc_enc->code_block_mode == 0) {
1079 tb = &ldpc_enc->tb_params;
1082 "c (%u) is out of range 1 <= value <= %u",
1083 tb->c, RTE_BBDEV_LDPC_MAX_CODE_BLOCKS);
1086 if (tb->cab > tb->c) {
1088 "cab (%u) is greater than c (%u)",
1092 if ((tb->ea < RTE_BBDEV_LDPC_MIN_CB_SIZE)
1093 && tb->r < tb->cab) {
1095 "ea (%u) is less than %u or it is not even",
1096 tb->ea, RTE_BBDEV_LDPC_MIN_CB_SIZE);
1099 if ((tb->eb < RTE_BBDEV_LDPC_MIN_CB_SIZE)
1100 && tb->c > tb->cab) {
1102 "eb (%u) is less than %u",
1103 tb->eb, RTE_BBDEV_LDPC_MIN_CB_SIZE);
1106 if (tb->r > (tb->c - 1)) {
1108 "r (%u) is greater than c - 1 (%u)",
1113 cb = &ldpc_enc->cb_params;
1114 if (cb->e < RTE_BBDEV_LDPC_MIN_CB_SIZE) {
1116 "e (%u) is less than %u or it is not even",
1117 cb->e, RTE_BBDEV_LDPC_MIN_CB_SIZE);
1125 static inline char *
1126 mbuf_append(struct rte_mbuf *m_head, struct rte_mbuf *m, uint16_t len)
1128 if (unlikely(len > rte_pktmbuf_tailroom(m)))
1131 char *tail = (char *)m->buf_addr + m->data_off + m->data_len;
1132 m->data_len = (uint16_t)(m->data_len + len);
1133 m_head->pkt_len = (m_head->pkt_len + len);
1137 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1138 /* Validates LDPC decoder parameters */
1140 validate_dec_op(struct rte_bbdev_dec_op *op __rte_unused)
1142 struct rte_bbdev_op_ldpc_dec *ldpc_dec = &op->ldpc_dec;
1143 struct rte_bbdev_op_dec_ldpc_cb_params *cb = NULL;
1144 struct rte_bbdev_op_dec_ldpc_tb_params *tb = NULL;
1146 if (op->mempool == NULL) {
1147 rte_bbdev_log(ERR, "Invalid mempool pointer");
1150 if (ldpc_dec->rv_index > 3) {
1152 "rv_index (%u) is out of range 0 <= value <= 3",
1153 ldpc_dec->rv_index);
1157 if (ldpc_dec->iter_max == 0) {
1159 "iter_max (%u) is equal to 0",
1160 ldpc_dec->iter_max);
1164 if (ldpc_dec->code_block_mode > 1) {
1166 "code_block_mode (%u) is out of range 0 <= value <= 1",
1167 ldpc_dec->code_block_mode);
1171 if (ldpc_dec->code_block_mode == 0) {
1172 tb = &ldpc_dec->tb_params;
1175 "c (%u) is out of range 1 <= value <= %u",
1176 tb->c, RTE_BBDEV_LDPC_MAX_CODE_BLOCKS);
1179 if (tb->cab > tb->c) {
1181 "cab (%u) is greater than c (%u)",
1186 cb = &ldpc_dec->cb_params;
1187 if (cb->e < RTE_BBDEV_LDPC_MIN_CB_SIZE) {
1189 "e (%u) is out of range %u <= value <= %u",
1190 cb->e, RTE_BBDEV_LDPC_MIN_CB_SIZE,
1191 RTE_BBDEV_LDPC_MAX_CB_SIZE);
1201 fpga_harq_write_loopback(struct fpga_5gnr_fec_device *fpga_dev,
1202 struct rte_mbuf *harq_input, uint16_t harq_in_length,
1203 uint32_t harq_in_offset, uint32_t harq_out_offset)
1205 uint32_t out_offset = harq_out_offset;
1206 uint32_t in_offset = harq_in_offset;
1207 uint32_t left_length = harq_in_length;
1208 uint32_t reg_32, increment = 0;
1209 uint64_t *input = NULL;
1210 uint32_t last_transaction = left_length
1211 % FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1214 if (last_transaction > 0)
1215 left_length -= last_transaction;
1218 * Get HARQ buffer size for each VF/PF: When 0x00, there is no
1219 * available DDR space for the corresponding VF/PF.
1221 reg_32 = fpga_reg_read_32(fpga_dev->mmio_base,
1222 FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
1223 if (reg_32 < harq_in_length) {
1224 left_length = reg_32;
1225 rte_bbdev_log(ERR, "HARQ in length > HARQ buffer size\n");
1228 input = (uint64_t *)rte_pktmbuf_mtod_offset(harq_input,
1229 uint8_t *, in_offset);
1231 while (left_length > 0) {
1232 if (fpga_reg_read_8(fpga_dev->mmio_base,
1233 FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS) == 1) {
1234 fpga_reg_write_32(fpga_dev->mmio_base,
1235 FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS,
1237 fpga_reg_write_64(fpga_dev->mmio_base,
1238 FPGA_5GNR_FEC_DDR4_WR_DATA_REGS,
1240 left_length -= FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1241 out_offset += FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1243 fpga_reg_write_8(fpga_dev->mmio_base,
1244 FPGA_5GNR_FEC_DDR4_WR_DONE_REGS, 1);
1247 while (last_transaction > 0) {
1248 if (fpga_reg_read_8(fpga_dev->mmio_base,
1249 FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS) == 1) {
1250 fpga_reg_write_32(fpga_dev->mmio_base,
1251 FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS,
1253 last_word = input[increment];
1254 last_word &= (uint64_t)(1 << (last_transaction * 4))
1256 fpga_reg_write_64(fpga_dev->mmio_base,
1257 FPGA_5GNR_FEC_DDR4_WR_DATA_REGS,
1259 fpga_reg_write_8(fpga_dev->mmio_base,
1260 FPGA_5GNR_FEC_DDR4_WR_DONE_REGS, 1);
1261 last_transaction = 0;
1268 fpga_harq_read_loopback(struct fpga_5gnr_fec_device *fpga_dev,
1269 struct rte_mbuf *harq_output, uint16_t harq_in_length,
1270 uint32_t harq_in_offset, uint32_t harq_out_offset)
1272 uint32_t left_length, in_offset = harq_in_offset;
1274 uint32_t increment = 0;
1275 uint64_t *input = NULL;
1276 uint32_t last_transaction = harq_in_length
1277 % FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1279 if (last_transaction > 0)
1280 harq_in_length += (8 - last_transaction);
1282 reg = fpga_reg_read_32(fpga_dev->mmio_base,
1283 FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
1284 if (reg < harq_in_length) {
1285 harq_in_length = reg;
1286 rte_bbdev_log(ERR, "HARQ in length > HARQ buffer size\n");
1289 if (!mbuf_append(harq_output, harq_output, harq_in_length)) {
1290 rte_bbdev_log(ERR, "HARQ output buffer warning %d %d\n",
1291 harq_output->buf_len -
1292 rte_pktmbuf_headroom(harq_output),
1294 harq_in_length = harq_output->buf_len -
1295 rte_pktmbuf_headroom(harq_output);
1296 if (!mbuf_append(harq_output, harq_output, harq_in_length)) {
1297 rte_bbdev_log(ERR, "HARQ output buffer issue %d %d\n",
1298 harq_output->buf_len, harq_in_length);
1302 left_length = harq_in_length;
1304 input = (uint64_t *)rte_pktmbuf_mtod_offset(harq_output,
1305 uint8_t *, harq_out_offset);
1307 while (left_length > 0) {
1308 fpga_reg_write_32(fpga_dev->mmio_base,
1309 FPGA_5GNR_FEC_DDR4_RD_ADDR_REGS, in_offset);
1310 fpga_reg_write_8(fpga_dev->mmio_base,
1311 FPGA_5GNR_FEC_DDR4_RD_DONE_REGS, 1);
1312 reg = fpga_reg_read_8(fpga_dev->mmio_base,
1313 FPGA_5GNR_FEC_DDR4_RD_RDY_REGS);
1315 reg = fpga_reg_read_8(fpga_dev->mmio_base,
1316 FPGA_5GNR_FEC_DDR4_RD_RDY_REGS);
1317 if (reg == FPGA_DDR_OVERFLOW) {
1319 "Read address is overflow!\n");
1323 input[increment] = fpga_reg_read_64(fpga_dev->mmio_base,
1324 FPGA_5GNR_FEC_DDR4_RD_DATA_REGS);
1325 left_length -= FPGA_5GNR_FEC_DDR_RD_DATA_LEN_IN_BYTES;
1326 in_offset += FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
1328 fpga_reg_write_8(fpga_dev->mmio_base,
1329 FPGA_5GNR_FEC_DDR4_RD_DONE_REGS, 0);
1335 enqueue_ldpc_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op *op,
1336 uint16_t desc_offset)
1338 union fpga_dma_desc *desc;
1340 uint8_t c, crc24_bits = 0;
1341 struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
1342 uint16_t in_offset = enc->input.offset;
1343 uint16_t out_offset = enc->output.offset;
1344 struct rte_mbuf *m_in = enc->input.data;
1345 struct rte_mbuf *m_out = enc->output.data;
1346 struct rte_mbuf *m_out_head = enc->output.data;
1347 uint32_t in_length, out_length, e;
1348 uint16_t total_left = enc->input.length;
1349 uint16_t ring_offset;
1352 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1353 /* Validate op structure */
1355 if (validate_enc_op(op) == -1) {
1356 rte_bbdev_log(ERR, "LDPC encoder validation failed");
1361 /* Clear op status */
1364 if (m_in == NULL || m_out == NULL) {
1365 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1366 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1370 if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH)
1373 if (enc->code_block_mode == 0) {
1374 /* For Transport Block mode */
1376 c = enc->tb_params.c;
1377 e = enc->tb_params.ea;
1378 } else { /* For Code Block mode */
1380 e = enc->cb_params.e;
1383 /* Update total_left */
1384 K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
1385 k_ = K - enc->n_filler;
1386 in_length = (k_ - crc24_bits) >> 3;
1387 out_length = (e + 7) >> 3;
1389 total_left = rte_pktmbuf_data_len(m_in) - in_offset;
1391 /* Update offsets */
1392 if (total_left != in_length) {
1393 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
1395 "Mismatch between mbuf length and included CBs sizes %d",
1399 mbuf_append(m_out_head, m_out, out_length);
1401 /* Offset into the ring */
1402 ring_offset = ((q->tail + desc_offset) & q->sw_ring_wrap_mask);
1403 /* Setup DMA Descriptor */
1404 desc = q->ring_addr + ring_offset;
1406 ret = fpga_dma_desc_te_fill(op, &desc->enc_req, m_in, m_out,
1407 k_, e, in_offset, out_offset, ring_offset, c);
1408 if (unlikely(ret < 0))
1411 /* Update lengths */
1412 total_left -= in_length;
1413 op->ldpc_enc.output.length += out_length;
1415 if (total_left > 0) {
1417 "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1418 total_left, in_length);
1422 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1423 print_dma_enc_desc_debug_info(desc);
1429 enqueue_ldpc_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op *op,
1430 uint16_t desc_offset)
1432 union fpga_dma_desc *desc;
1434 uint16_t ring_offset;
1436 uint16_t e, in_length, out_length, k0, l, seg_total_left, sys_cols;
1437 uint16_t K, parity_offset, harq_in_length = 0, harq_out_length = 0;
1438 uint16_t crc24_overlap = 0;
1439 struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
1440 struct rte_mbuf *m_in = dec->input.data;
1441 struct rte_mbuf *m_out = dec->hard_output.data;
1442 struct rte_mbuf *m_out_head = dec->hard_output.data;
1443 uint16_t in_offset = dec->input.offset;
1444 uint16_t out_offset = dec->hard_output.offset;
1445 uint32_t harq_offset = 0;
1447 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1448 /* Validate op structure */
1449 if (validate_dec_op(op) == -1) {
1450 rte_bbdev_log(ERR, "LDPC decoder validation failed");
1455 /* Clear op status */
1458 /* Setup DMA Descriptor */
1459 ring_offset = ((q->tail + desc_offset) & q->sw_ring_wrap_mask);
1460 desc = q->ring_addr + ring_offset;
1462 if (check_bit(dec->op_flags,
1463 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK)) {
1464 struct rte_mbuf *harq_in = dec->harq_combined_input.data;
1465 struct rte_mbuf *harq_out = dec->harq_combined_output.data;
1466 harq_in_length = dec->harq_combined_input.length;
1467 uint32_t harq_in_offset = dec->harq_combined_input.offset;
1468 uint32_t harq_out_offset = dec->harq_combined_output.offset;
1470 if (check_bit(dec->op_flags,
1471 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE
1473 ret = fpga_harq_write_loopback(q->d, harq_in,
1474 harq_in_length, harq_in_offset,
1476 } else if (check_bit(dec->op_flags,
1477 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE
1479 ret = fpga_harq_read_loopback(q->d, harq_out,
1480 harq_in_length, harq_in_offset,
1482 dec->harq_combined_output.length = harq_in_length;
1484 rte_bbdev_log(ERR, "OP flag Err!");
1487 /* Set descriptor for dequeue */
1488 desc->dec_req.done = 1;
1489 desc->dec_req.error = 0;
1490 desc->dec_req.op_addr = op;
1491 desc->dec_req.cbs_in_op = 1;
1492 /* Mark this dummy descriptor to be dropped by HW */
1493 desc->dec_req.desc_idx = (ring_offset + 1)
1494 & q->sw_ring_wrap_mask;
1495 return ret; /* Error or number of CB */
1498 if (m_in == NULL || m_out == NULL) {
1499 rte_bbdev_log(ERR, "Invalid mbuf pointer");
1500 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1505 e = dec->cb_params.e;
1507 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
1510 sys_cols = (dec->basegraph == 1) ? 22 : 10;
1511 K = sys_cols * dec->z_c;
1512 parity_offset = K - 2 * dec->z_c;
1514 out_length = ((K - crc24_overlap - dec->n_filler) >> 3);
1516 seg_total_left = dec->input.length;
1518 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
1519 harq_in_length = RTE_MIN(dec->harq_combined_input.length,
1520 (uint32_t)dec->n_cb);
1523 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
1524 k0 = get_k0(dec->n_cb, dec->z_c,
1525 dec->basegraph, dec->rv_index);
1526 if (k0 > parity_offset)
1529 l = k0 + e + dec->n_filler;
1530 harq_out_length = RTE_MIN(RTE_MAX(harq_in_length, l),
1531 dec->n_cb - dec->n_filler);
1532 dec->harq_combined_output.length = harq_out_length;
1535 mbuf_append(m_out_head, m_out, out_length);
1536 if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE))
1537 harq_offset = dec->harq_combined_input.offset;
1538 else if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE))
1539 harq_offset = dec->harq_combined_output.offset;
1541 if ((harq_offset & 0x3FF) > 0) {
1542 rte_bbdev_log(ERR, "Invalid HARQ offset %d", harq_offset);
1543 op->status = 1 << RTE_BBDEV_DATA_ERROR;
1547 ret = fpga_dma_desc_ld_fill(op, &desc->dec_req, m_in, m_out,
1548 harq_in_length, in_offset, out_offset, harq_offset,
1550 if (unlikely(ret < 0))
1552 /* Update lengths */
1553 seg_total_left -= in_length;
1554 op->ldpc_dec.hard_output.length += out_length;
1555 if (seg_total_left > 0) {
1557 "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
1558 seg_total_left, in_length);
1562 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1563 print_dma_dec_desc_debug_info(desc);
1570 fpga_enqueue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
1571 struct rte_bbdev_enc_op **ops, uint16_t num)
1573 uint16_t i, total_enqueued_cbs = 0;
1576 struct fpga_queue *q = q_data->queue_private;
1577 union fpga_dma_desc *desc;
1579 /* Check if queue is not full */
1580 if (unlikely(((q->tail + 1) & q->sw_ring_wrap_mask) ==
1584 /* Calculates available space */
1585 avail = (q->head_free_desc > q->tail) ?
1586 q->head_free_desc - q->tail - 1 :
1587 q->ring_ctrl_reg.ring_size + q->head_free_desc - q->tail - 1;
1589 for (i = 0; i < num; ++i) {
1591 /* Check if there is available space for further
1594 if (unlikely(avail - 1 < 0))
1597 enqueued_cbs = enqueue_ldpc_enc_one_op_cb(q, ops[i],
1598 total_enqueued_cbs);
1600 if (enqueued_cbs < 0)
1603 total_enqueued_cbs += enqueued_cbs;
1605 rte_bbdev_log_debug("enqueuing enc ops [%d/%d] | head %d | tail %d",
1606 total_enqueued_cbs, num,
1607 q->head_free_desc, q->tail);
1610 /* Set interrupt bit for last CB in enqueued ops. FPGA issues interrupt
1611 * only when all previous CBs were already processed.
1613 desc = q->ring_addr + ((q->tail + total_enqueued_cbs - 1)
1614 & q->sw_ring_wrap_mask);
1615 desc->enc_req.irq_en = q->irq_enable;
1617 fpga_dma_enqueue(q, total_enqueued_cbs, &q_data->queue_stats);
1620 q_data->queue_stats.enqueued_count += i;
1621 q_data->queue_stats.enqueue_err_count += num - i;
1627 fpga_enqueue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
1628 struct rte_bbdev_dec_op **ops, uint16_t num)
1630 uint16_t i, total_enqueued_cbs = 0;
1633 struct fpga_queue *q = q_data->queue_private;
1634 union fpga_dma_desc *desc;
1636 /* Check if queue is not full */
1637 if (unlikely(((q->tail + 1) & q->sw_ring_wrap_mask) ==
1641 /* Calculates available space */
1642 avail = (q->head_free_desc > q->tail) ?
1643 q->head_free_desc - q->tail - 1 :
1644 q->ring_ctrl_reg.ring_size + q->head_free_desc - q->tail - 1;
1646 for (i = 0; i < num; ++i) {
1648 /* Check if there is available space for further
1651 if (unlikely(avail - 1 < 0))
1654 enqueued_cbs = enqueue_ldpc_dec_one_op_cb(q, ops[i],
1655 total_enqueued_cbs);
1657 if (enqueued_cbs < 0)
1660 total_enqueued_cbs += enqueued_cbs;
1662 rte_bbdev_log_debug("enqueuing dec ops [%d/%d] | head %d | tail %d",
1663 total_enqueued_cbs, num,
1664 q->head_free_desc, q->tail);
1668 q_data->queue_stats.enqueued_count += i;
1669 q_data->queue_stats.enqueue_err_count += num - i;
1671 /* Set interrupt bit for last CB in enqueued ops. FPGA issues interrupt
1672 * only when all previous CBs were already processed.
1674 desc = q->ring_addr + ((q->tail + total_enqueued_cbs - 1)
1675 & q->sw_ring_wrap_mask);
1676 desc->enc_req.irq_en = q->irq_enable;
1677 fpga_dma_enqueue(q, total_enqueued_cbs, &q_data->queue_stats);
1683 dequeue_ldpc_enc_one_op_cb(struct fpga_queue *q,
1684 struct rte_bbdev_enc_op **op,
1685 uint16_t desc_offset)
1687 union fpga_dma_desc *desc;
1689 /* Set current desc */
1690 desc = q->ring_addr + ((q->head_free_desc + desc_offset)
1691 & q->sw_ring_wrap_mask);
1694 if (desc->enc_req.done == 0)
1697 /* make sure the response is read atomically */
1700 rte_bbdev_log_debug("DMA response desc %p", desc);
1702 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1703 print_dma_enc_desc_debug_info(desc);
1706 *op = desc->enc_req.op_addr;
1707 /* Check the descriptor error field, return 1 on error */
1708 desc_error = check_desc_error(desc->enc_req.error);
1709 (*op)->status = desc_error << RTE_BBDEV_DATA_ERROR;
1716 dequeue_ldpc_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
1717 uint16_t desc_offset)
1719 union fpga_dma_desc *desc;
1721 /* Set descriptor */
1722 desc = q->ring_addr + ((q->head_free_desc + desc_offset)
1723 & q->sw_ring_wrap_mask);
1725 /* Verify done bit is set */
1726 if (desc->dec_req.done == 0)
1729 /* make sure the response is read atomically */
1732 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1733 print_dma_dec_desc_debug_info(desc);
1736 *op = desc->dec_req.op_addr;
1738 if (check_bit((*op)->ldpc_dec.op_flags,
1739 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK)) {
1744 /* FPGA reports iterations based on round-up minus 1 */
1745 (*op)->ldpc_dec.iter_count = desc->dec_req.iter + 1;
1746 /* CRC Check criteria */
1747 if (desc->dec_req.crc24b_ind && !(desc->dec_req.crcb_pass))
1748 (*op)->status = 1 << RTE_BBDEV_CRC_ERROR;
1749 /* et_pass = 0 when decoder fails */
1750 (*op)->status |= !(desc->dec_req.et_pass) << RTE_BBDEV_SYNDROME_ERROR;
1751 /* Check the descriptor error field, return 1 on error */
1752 desc_error = check_desc_error(desc->dec_req.error);
1753 (*op)->status |= desc_error << RTE_BBDEV_DATA_ERROR;
1758 fpga_dequeue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
1759 struct rte_bbdev_enc_op **ops, uint16_t num)
1761 struct fpga_queue *q = q_data->queue_private;
1762 uint32_t avail = (q->tail - q->head_free_desc) & q->sw_ring_wrap_mask;
1764 uint16_t dequeued_cbs = 0;
1767 for (i = 0; (i < num) && (dequeued_cbs < avail); ++i) {
1768 ret = dequeue_ldpc_enc_one_op_cb(q, &ops[i], dequeued_cbs);
1773 dequeued_cbs += ret;
1775 rte_bbdev_log_debug("dequeuing enc ops [%d/%d] | head %d | tail %d",
1776 dequeued_cbs, num, q->head_free_desc, q->tail);
1780 q->head_free_desc = (q->head_free_desc + dequeued_cbs) &
1781 q->sw_ring_wrap_mask;
1784 q_data->queue_stats.dequeued_count += i;
1790 fpga_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
1791 struct rte_bbdev_dec_op **ops, uint16_t num)
1793 struct fpga_queue *q = q_data->queue_private;
1794 uint32_t avail = (q->tail - q->head_free_desc) & q->sw_ring_wrap_mask;
1796 uint16_t dequeued_cbs = 0;
1799 for (i = 0; (i < num) && (dequeued_cbs < avail); ++i) {
1800 ret = dequeue_ldpc_dec_one_op_cb(q, &ops[i], dequeued_cbs);
1805 dequeued_cbs += ret;
1807 rte_bbdev_log_debug("dequeuing dec ops [%d/%d] | head %d | tail %d",
1808 dequeued_cbs, num, q->head_free_desc, q->tail);
1812 q->head_free_desc = (q->head_free_desc + dequeued_cbs) &
1813 q->sw_ring_wrap_mask;
1816 q_data->queue_stats.dequeued_count += i;
1822 /* Initialization Function */
1824 fpga_5gnr_fec_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
1826 struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
1828 dev->dev_ops = &fpga_ops;
1829 dev->enqueue_ldpc_enc_ops = fpga_enqueue_ldpc_enc;
1830 dev->enqueue_ldpc_dec_ops = fpga_enqueue_ldpc_dec;
1831 dev->dequeue_ldpc_enc_ops = fpga_dequeue_ldpc_enc;
1832 dev->dequeue_ldpc_dec_ops = fpga_dequeue_ldpc_dec;
1834 ((struct fpga_5gnr_fec_device *) dev->data->dev_private)->pf_device =
1835 !strcmp(drv->driver.name,
1836 RTE_STR(FPGA_5GNR_FEC_PF_DRIVER_NAME));
1837 ((struct fpga_5gnr_fec_device *) dev->data->dev_private)->mmio_base =
1838 pci_dev->mem_resource[0].addr;
1840 rte_bbdev_log_debug(
1841 "Init device %s [%s] @ virtaddr %p phyaddr %#"PRIx64,
1842 dev->device->driver->name, dev->data->name,
1843 (void *)pci_dev->mem_resource[0].addr,
1844 pci_dev->mem_resource[0].phys_addr);
1848 fpga_5gnr_fec_probe(struct rte_pci_driver *pci_drv,
1849 struct rte_pci_device *pci_dev)
1851 struct rte_bbdev *bbdev = NULL;
1852 char dev_name[RTE_BBDEV_NAME_MAX_LEN];
1854 if (pci_dev == NULL) {
1855 rte_bbdev_log(ERR, "NULL PCI device");
1859 rte_pci_device_name(&pci_dev->addr, dev_name, sizeof(dev_name));
1861 /* Allocate memory to be used privately by drivers */
1862 bbdev = rte_bbdev_allocate(pci_dev->device.name);
1866 /* allocate device private memory */
1867 bbdev->data->dev_private = rte_zmalloc_socket(dev_name,
1868 sizeof(struct fpga_5gnr_fec_device),
1869 RTE_CACHE_LINE_SIZE,
1870 pci_dev->device.numa_node);
1872 if (bbdev->data->dev_private == NULL) {
1874 "Allocate of %zu bytes for device \"%s\" failed",
1875 sizeof(struct fpga_5gnr_fec_device), dev_name);
1876 rte_bbdev_release(bbdev);
1880 /* Fill HW specific part of device structure */
1881 bbdev->device = &pci_dev->device;
1882 bbdev->intr_handle = &pci_dev->intr_handle;
1883 bbdev->data->socket_id = pci_dev->device.numa_node;
1885 /* Invoke FEC FPGA device initialization function */
1886 fpga_5gnr_fec_init(bbdev, pci_drv);
1888 rte_bbdev_log_debug("bbdev id = %u [%s]",
1889 bbdev->data->dev_id, dev_name);
1891 struct fpga_5gnr_fec_device *d = bbdev->data->dev_private;
1892 uint32_t version_id = fpga_reg_read_32(d->mmio_base,
1893 FPGA_5GNR_FEC_VERSION_ID);
1894 rte_bbdev_log(INFO, "FEC FPGA RTL v%u.%u",
1895 ((uint16_t)(version_id >> 16)), ((uint16_t)version_id));
1897 #ifdef RTE_LIBRTE_BBDEV_DEBUG
1898 if (!strcmp(bbdev->device->driver->name,
1899 RTE_STR(FPGA_5GNR_FEC_PF_DRIVER_NAME)))
1900 print_static_reg_debug_info(d->mmio_base);
1906 fpga_5gnr_fec_remove(struct rte_pci_device *pci_dev)
1908 struct rte_bbdev *bbdev;
1912 if (pci_dev == NULL)
1916 bbdev = rte_bbdev_get_named_dev(pci_dev->device.name);
1917 if (bbdev == NULL) {
1919 "Couldn't find HW dev \"%s\" to uninitialise it",
1920 pci_dev->device.name);
1923 dev_id = bbdev->data->dev_id;
1925 /* free device private memory before close */
1926 rte_free(bbdev->data->dev_private);
1929 ret = rte_bbdev_close(dev_id);
1932 "Device %i failed to close during uninit: %i",
1935 /* release bbdev from library */
1936 ret = rte_bbdev_release(bbdev);
1938 rte_bbdev_log(ERR, "Device %i failed to uninit: %i", dev_id,
1941 rte_bbdev_log_debug("Destroyed bbdev = %u", dev_id);
1947 set_default_fpga_conf(struct fpga_5gnr_fec_conf *def_conf)
1949 /* clear default configuration before initialization */
1950 memset(def_conf, 0, sizeof(struct fpga_5gnr_fec_conf));
1951 /* Set pf mode to true */
1952 def_conf->pf_mode_en = true;
1954 /* Set ratio between UL and DL to 1:1 (unit of weight is 3 CBs) */
1955 def_conf->ul_bandwidth = 3;
1956 def_conf->dl_bandwidth = 3;
1958 /* Set Load Balance Factor to 64 */
1959 def_conf->dl_load_balance = 64;
1960 def_conf->ul_load_balance = 64;
1963 /* Initial configuration of FPGA 5GNR FEC device */
1965 fpga_5gnr_fec_configure(const char *dev_name,
1966 const struct fpga_5gnr_fec_conf *conf)
1968 uint32_t payload_32, address;
1969 uint16_t payload_16;
1971 uint16_t q_id, vf_id, total_q_id, total_ul_q_id, total_dl_q_id;
1972 struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
1973 struct fpga_5gnr_fec_conf def_conf;
1975 if (bbdev == NULL) {
1977 "Invalid dev_name (%s), or device is not yet initialised",
1982 struct fpga_5gnr_fec_device *d = bbdev->data->dev_private;
1986 "FPGA Configuration was not provided. Default configuration will be loaded.");
1987 set_default_fpga_conf(&def_conf);
1992 * Configure UL:DL ratio.
1996 payload_16 = (conf->dl_bandwidth << 8) | conf->ul_bandwidth;
1997 address = FPGA_5GNR_FEC_CONFIGURATION;
1998 fpga_reg_write_16(d->mmio_base, address, payload_16);
2000 /* Clear all queues registers */
2001 payload_32 = FPGA_INVALID_HW_QUEUE_ID;
2002 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
2003 address = (q_id << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
2004 fpga_reg_write_32(d->mmio_base, address, payload_32);
2008 * If PF mode is enabled allocate all queues for PF only.
2010 * For VF mode each VF can have different number of UL and DL queues.
2011 * Total number of queues to configure cannot exceed FPGA
2012 * capabilities - 64 queues - 32 queues for UL and 32 queues for DL.
2013 * Queues mapping is done according to configuration:
2019 * | conf->vf_dl_queues_number[0] - 1 | 0 |
2020 * | conf->vf_dl_queues_number[0] | 1 |
2022 * | conf->vf_dl_queues_number[1] - 1 | 1 |
2024 * | conf->vf_dl_queues_number[7] - 1 | 7 |
2030 * | conf->vf_ul_queues_number[0] - 1 | 0 |
2031 * | conf->vf_ul_queues_number[0] | 1 |
2033 * | conf->vf_ul_queues_number[1] - 1 | 1 |
2035 * | conf->vf_ul_queues_number[7] - 1 | 7 |
2037 * Example of configuration:
2038 * conf->vf_ul_queues_number[0] = 4; -> 4 UL queues for VF0
2039 * conf->vf_dl_queues_number[0] = 4; -> 4 DL queues for VF0
2040 * conf->vf_ul_queues_number[1] = 2; -> 2 UL queues for VF1
2041 * conf->vf_dl_queues_number[1] = 2; -> 2 DL queues for VF1
2061 if (conf->pf_mode_en) {
2063 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
2064 address = (q_id << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
2065 fpga_reg_write_32(d->mmio_base, address, payload_32);
2068 /* Calculate total number of UL and DL queues to configure */
2069 total_ul_q_id = total_dl_q_id = 0;
2070 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
2071 total_ul_q_id += conf->vf_ul_queues_number[vf_id];
2072 total_dl_q_id += conf->vf_dl_queues_number[vf_id];
2074 total_q_id = total_dl_q_id + total_ul_q_id;
2076 * Check if total number of queues to configure does not exceed
2077 * FPGA capabilities (64 queues - 32 UL and 32 DL queues)
2079 if ((total_ul_q_id > FPGA_NUM_UL_QUEUES) ||
2080 (total_dl_q_id > FPGA_NUM_DL_QUEUES) ||
2081 (total_q_id > FPGA_TOTAL_NUM_QUEUES)) {
2083 "FPGA Configuration failed. Too many queues to configure: UL_Q %u, DL_Q %u, FPGA_Q %u",
2084 total_ul_q_id, total_dl_q_id,
2085 FPGA_TOTAL_NUM_QUEUES);
2089 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
2090 for (q_id = 0; q_id < conf->vf_ul_queues_number[vf_id];
2091 ++q_id, ++total_ul_q_id) {
2092 address = (total_ul_q_id << 2) +
2093 FPGA_5GNR_FEC_QUEUE_MAP;
2094 payload_32 = ((0x80 + vf_id) << 16) | 0x1;
2095 fpga_reg_write_32(d->mmio_base, address,
2100 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
2101 for (q_id = 0; q_id < conf->vf_dl_queues_number[vf_id];
2102 ++q_id, ++total_dl_q_id) {
2103 address = ((total_dl_q_id + FPGA_NUM_UL_QUEUES)
2104 << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
2105 payload_32 = ((0x80 + vf_id) << 16) | 0x1;
2106 fpga_reg_write_32(d->mmio_base, address,
2112 /* Setting Load Balance Factor */
2113 payload_16 = (conf->dl_load_balance << 8) | (conf->ul_load_balance);
2114 address = FPGA_5GNR_FEC_LOAD_BALANCE_FACTOR;
2115 fpga_reg_write_16(d->mmio_base, address, payload_16);
2117 /* Setting length of ring descriptor entry */
2118 payload_16 = FPGA_RING_DESC_ENTRY_LENGTH;
2119 address = FPGA_5GNR_FEC_RING_DESC_LEN;
2120 fpga_reg_write_16(d->mmio_base, address, payload_16);
2122 /* Setting FLR timeout value */
2123 payload_16 = conf->flr_time_out;
2124 address = FPGA_5GNR_FEC_FLR_TIME_OUT;
2125 fpga_reg_write_16(d->mmio_base, address, payload_16);
2127 /* Queue PF/VF mapping table is ready */
2129 address = FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE;
2130 fpga_reg_write_8(d->mmio_base, address, payload_8);
2132 rte_bbdev_log_debug("PF FPGA 5GNR FEC configuration complete for %s",
2135 #ifdef RTE_LIBRTE_BBDEV_DEBUG
2136 print_static_reg_debug_info(d->mmio_base);
2141 /* FPGA 5GNR FEC PCI PF address map */
2142 static struct rte_pci_id pci_id_fpga_5gnr_fec_pf_map[] = {
2144 RTE_PCI_DEVICE(FPGA_5GNR_FEC_VENDOR_ID,
2145 FPGA_5GNR_FEC_PF_DEVICE_ID)
2150 static struct rte_pci_driver fpga_5gnr_fec_pci_pf_driver = {
2151 .probe = fpga_5gnr_fec_probe,
2152 .remove = fpga_5gnr_fec_remove,
2153 .id_table = pci_id_fpga_5gnr_fec_pf_map,
2154 .drv_flags = RTE_PCI_DRV_NEED_MAPPING
2157 /* FPGA 5GNR FEC PCI VF address map */
2158 static struct rte_pci_id pci_id_fpga_5gnr_fec_vf_map[] = {
2160 RTE_PCI_DEVICE(FPGA_5GNR_FEC_VENDOR_ID,
2161 FPGA_5GNR_FEC_VF_DEVICE_ID)
2166 static struct rte_pci_driver fpga_5gnr_fec_pci_vf_driver = {
2167 .probe = fpga_5gnr_fec_probe,
2168 .remove = fpga_5gnr_fec_remove,
2169 .id_table = pci_id_fpga_5gnr_fec_vf_map,
2170 .drv_flags = RTE_PCI_DRV_NEED_MAPPING
2174 RTE_PMD_REGISTER_PCI(FPGA_5GNR_FEC_PF_DRIVER_NAME, fpga_5gnr_fec_pci_pf_driver);
2175 RTE_PMD_REGISTER_PCI_TABLE(FPGA_5GNR_FEC_PF_DRIVER_NAME,
2176 pci_id_fpga_5gnr_fec_pf_map);
2177 RTE_PMD_REGISTER_PCI(FPGA_5GNR_FEC_VF_DRIVER_NAME, fpga_5gnr_fec_pci_vf_driver);
2178 RTE_PMD_REGISTER_PCI_TABLE(FPGA_5GNR_FEC_VF_DRIVER_NAME,
2179 pci_id_fpga_5gnr_fec_vf_map);