LCOV - code coverage report
Current view: top level - drivers/baseband/fpga_5gnr_fec - rte_fpga_5gnr_fec.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 3 920 0.3 %
Date: 2024-01-22 15:35:40 Functions: 3 36 8.3 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 543 0.2 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(c) 2020 Intel Corporation
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <unistd.h>
       6                 :            : 
       7                 :            : #include <rte_common.h>
       8                 :            : #include <rte_log.h>
       9                 :            : #include <dev_driver.h>
      10                 :            : #include <rte_malloc.h>
      11                 :            : #include <rte_mempool.h>
      12                 :            : #include <rte_errno.h>
      13                 :            : #include <rte_pci.h>
      14                 :            : #include <bus_pci_driver.h>
      15                 :            : #include <rte_byteorder.h>
      16                 :            : #include <rte_cycles.h>
      17                 :            : 
      18                 :            : #include <rte_bbdev.h>
      19                 :            : #include <rte_bbdev_pmd.h>
      20                 :            : 
      21                 :            : #include "fpga_5gnr_fec.h"
      22                 :            : #include "rte_pmd_fpga_5gnr_fec.h"
      23                 :            : 
      24                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
      25                 :            : RTE_LOG_REGISTER_DEFAULT(fpga_5gnr_fec_logtype, DEBUG);
      26                 :            : #else
      27         [ -  + ]:        235 : RTE_LOG_REGISTER_DEFAULT(fpga_5gnr_fec_logtype, NOTICE);
      28                 :            : #endif
      29                 :            : 
      30                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
      31                 :            : 
      32                 :            : /* Read Ring Control Register of FPGA 5GNR FEC device */
      33                 :            : static inline void
      34                 :            : print_ring_reg_debug_info(void *mmio_base, uint32_t offset)
      35                 :            : {
      36                 :            :         rte_bbdev_log_debug(
      37                 :            :                 "FPGA MMIO base address @ %p | Ring Control Register @ offset = 0x%08"
      38                 :            :                 PRIx32, mmio_base, offset);
      39                 :            :         rte_bbdev_log_debug(
      40                 :            :                 "RING_BASE_ADDR = 0x%016"PRIx64,
      41                 :            :                 fpga_reg_read_64(mmio_base, offset));
      42                 :            :         rte_bbdev_log_debug(
      43                 :            :                 "RING_HEAD_ADDR = 0x%016"PRIx64,
      44                 :            :                 fpga_reg_read_64(mmio_base, offset +
      45                 :            :                                 FPGA_5GNR_FEC_RING_HEAD_ADDR));
      46                 :            :         rte_bbdev_log_debug(
      47                 :            :                 "RING_SIZE = 0x%04"PRIx16,
      48                 :            :                 fpga_reg_read_16(mmio_base, offset +
      49                 :            :                                 FPGA_5GNR_FEC_RING_SIZE));
      50                 :            :         rte_bbdev_log_debug(
      51                 :            :                 "RING_MISC = 0x%02"PRIx8,
      52                 :            :                 fpga_reg_read_8(mmio_base, offset +
      53                 :            :                                 FPGA_5GNR_FEC_RING_MISC));
      54                 :            :         rte_bbdev_log_debug(
      55                 :            :                 "RING_ENABLE = 0x%02"PRIx8,
      56                 :            :                 fpga_reg_read_8(mmio_base, offset +
      57                 :            :                                 FPGA_5GNR_FEC_RING_ENABLE));
      58                 :            :         rte_bbdev_log_debug(
      59                 :            :                 "RING_FLUSH_QUEUE_EN = 0x%02"PRIx8,
      60                 :            :                 fpga_reg_read_8(mmio_base, offset +
      61                 :            :                                 FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN));
      62                 :            :         rte_bbdev_log_debug(
      63                 :            :                 "RING_SHADOW_TAIL = 0x%04"PRIx16,
      64                 :            :                 fpga_reg_read_16(mmio_base, offset +
      65                 :            :                                 FPGA_5GNR_FEC_RING_SHADOW_TAIL));
      66                 :            :         rte_bbdev_log_debug(
      67                 :            :                 "RING_HEAD_POINT = 0x%04"PRIx16,
      68                 :            :                 fpga_reg_read_16(mmio_base, offset +
      69                 :            :                                 FPGA_5GNR_FEC_RING_HEAD_POINT));
      70                 :            : }
      71                 :            : 
      72                 :            : /* Read Static Register of FPGA 5GNR FEC device */
      73                 :            : static inline void
      74                 :            : print_static_reg_debug_info(void *mmio_base)
      75                 :            : {
      76                 :            :         uint16_t config = fpga_reg_read_16(mmio_base,
      77                 :            :                         FPGA_5GNR_FEC_CONFIGURATION);
      78                 :            :         uint8_t qmap_done = fpga_reg_read_8(mmio_base,
      79                 :            :                         FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE);
      80                 :            :         uint16_t lb_factor = fpga_reg_read_16(mmio_base,
      81                 :            :                         FPGA_5GNR_FEC_LOAD_BALANCE_FACTOR);
      82                 :            :         uint16_t ring_desc_len = fpga_reg_read_16(mmio_base,
      83                 :            :                         FPGA_5GNR_FEC_RING_DESC_LEN);
      84                 :            : 
      85                 :            :         rte_bbdev_log_debug("UL.DL Weights = %u.%u",
      86                 :            :                         ((uint8_t)config), ((uint8_t)(config >> 8)));
      87                 :            :         rte_bbdev_log_debug("UL.DL Load Balance = %u.%u",
      88                 :            :                         ((uint8_t)lb_factor), ((uint8_t)(lb_factor >> 8)));
      89                 :            :         rte_bbdev_log_debug("Queue-PF/VF Mapping Table = %s",
      90                 :            :                         (qmap_done > 0) ? "READY" : "NOT-READY");
      91                 :            :         rte_bbdev_log_debug("Ring Descriptor Size = %u bytes",
      92                 :            :                         ring_desc_len*FPGA_RING_DESC_LEN_UNIT_BYTES);
      93                 :            : }
      94                 :            : 
      95                 :            : /* Print decode DMA Descriptor of FPGA 5GNR Decoder device */
      96                 :            : static void
      97                 :            : print_dma_dec_desc_debug_info(union fpga_dma_desc *desc)
      98                 :            : {
      99                 :            :         rte_bbdev_log_debug("DMA response desc %p\n"
     100                 :            :                 "\t-- done(%"PRIu32") | iter(%"PRIu32") | et_pass(%"PRIu32")"
     101                 :            :                 " | crcb_pass (%"PRIu32") | error(%"PRIu32")\n"
     102                 :            :                 "\t-- qm_idx(%"PRIu32") | max_iter(%"PRIu32") | "
     103                 :            :                 "bg_idx (%"PRIu32") | harqin_en(%"PRIu32") | zc(%"PRIu32")\n"
     104                 :            :                 "\t-- hbstroe_offset(%"PRIu32") | num_null (%"PRIu32") "
     105                 :            :                 "| irq_en(%"PRIu32")\n"
     106                 :            :                 "\t-- ncb(%"PRIu32") | desc_idx (%"PRIu32") | "
     107                 :            :                 "drop_crc24b(%"PRIu32") | RV (%"PRIu32")\n"
     108                 :            :                 "\t-- crc24b_ind(%"PRIu32") | et_dis (%"PRIu32")\n"
     109                 :            :                 "\t-- harq_input_length(%"PRIu32") | rm_e(%"PRIu32")\n"
     110                 :            :                 "\t-- cbs_in_op(%"PRIu32") | in_add (0x%08"PRIx32"%08"PRIx32")"
     111                 :            :                 "| out_add (0x%08"PRIx32"%08"PRIx32")",
     112                 :            :                 desc,
     113                 :            :                 (uint32_t)desc->dec_req.done,
     114                 :            :                 (uint32_t)desc->dec_req.iter,
     115                 :            :                 (uint32_t)desc->dec_req.et_pass,
     116                 :            :                 (uint32_t)desc->dec_req.crcb_pass,
     117                 :            :                 (uint32_t)desc->dec_req.error,
     118                 :            :                 (uint32_t)desc->dec_req.qm_idx,
     119                 :            :                 (uint32_t)desc->dec_req.max_iter,
     120                 :            :                 (uint32_t)desc->dec_req.bg_idx,
     121                 :            :                 (uint32_t)desc->dec_req.harqin_en,
     122                 :            :                 (uint32_t)desc->dec_req.zc,
     123                 :            :                 (uint32_t)desc->dec_req.hbstroe_offset,
     124                 :            :                 (uint32_t)desc->dec_req.num_null,
     125                 :            :                 (uint32_t)desc->dec_req.irq_en,
     126                 :            :                 (uint32_t)desc->dec_req.ncb,
     127                 :            :                 (uint32_t)desc->dec_req.desc_idx,
     128                 :            :                 (uint32_t)desc->dec_req.drop_crc24b,
     129                 :            :                 (uint32_t)desc->dec_req.rv,
     130                 :            :                 (uint32_t)desc->dec_req.crc24b_ind,
     131                 :            :                 (uint32_t)desc->dec_req.et_dis,
     132                 :            :                 (uint32_t)desc->dec_req.harq_input_length,
     133                 :            :                 (uint32_t)desc->dec_req.rm_e,
     134                 :            :                 (uint32_t)desc->dec_req.cbs_in_op,
     135                 :            :                 (uint32_t)desc->dec_req.in_addr_hi,
     136                 :            :                 (uint32_t)desc->dec_req.in_addr_lw,
     137                 :            :                 (uint32_t)desc->dec_req.out_addr_hi,
     138                 :            :                 (uint32_t)desc->dec_req.out_addr_lw);
     139                 :            :         uint32_t *word = (uint32_t *) desc;
     140                 :            :         rte_bbdev_log_debug("%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n"
     141                 :            :                         "%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n",
     142                 :            :                         word[0], word[1], word[2], word[3],
     143                 :            :                         word[4], word[5], word[6], word[7]);
     144                 :            : }
     145                 :            : 
     146                 :            : /* Print decode DMA Descriptor of FPGA 5GNR encoder device */
     147                 :            : static void
     148                 :            : print_dma_enc_desc_debug_info(union fpga_dma_desc *desc)
     149                 :            : {
     150                 :            :         rte_bbdev_log_debug("DMA response desc %p\n"
     151                 :            :                         "%"PRIu32" %"PRIu32"\n"
     152                 :            :                         "K' %"PRIu32" E %"PRIu32" desc %"PRIu32" Z %"PRIu32"\n"
     153                 :            :                         "BG %"PRIu32" Qm %"PRIu32" CRC %"PRIu32" IRQ %"PRIu32"\n"
     154                 :            :                         "k0 %"PRIu32" Ncb %"PRIu32" F %"PRIu32"\n",
     155                 :            :                         desc,
     156                 :            :                         (uint32_t)desc->enc_req.done,
     157                 :            :                         (uint32_t)desc->enc_req.error,
     158                 :            : 
     159                 :            :                         (uint32_t)desc->enc_req.k_,
     160                 :            :                         (uint32_t)desc->enc_req.rm_e,
     161                 :            :                         (uint32_t)desc->enc_req.desc_idx,
     162                 :            :                         (uint32_t)desc->enc_req.zc,
     163                 :            : 
     164                 :            :                         (uint32_t)desc->enc_req.bg_idx,
     165                 :            :                         (uint32_t)desc->enc_req.qm_idx,
     166                 :            :                         (uint32_t)desc->enc_req.crc_en,
     167                 :            :                         (uint32_t)desc->enc_req.irq_en,
     168                 :            : 
     169                 :            :                         (uint32_t)desc->enc_req.k0,
     170                 :            :                         (uint32_t)desc->enc_req.ncb,
     171                 :            :                         (uint32_t)desc->enc_req.num_null);
     172                 :            :         uint32_t *word = (uint32_t *) desc;
     173                 :            :         rte_bbdev_log_debug("%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n"
     174                 :            :                         "%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n%08"PRIx32"\n",
     175                 :            :                         word[0], word[1], word[2], word[3],
     176                 :            :                         word[4], word[5], word[6], word[7]);
     177                 :            : }
     178                 :            : 
     179                 :            : #endif
     180                 :            : 
     181                 :            : static int
     182                 :          0 : fpga_setup_queues(struct rte_bbdev *dev, uint16_t num_queues, int socket_id)
     183                 :            : {
     184                 :            :         /* Number of queues bound to a PF/VF */
     185                 :            :         uint32_t hw_q_num = 0;
     186                 :            :         uint32_t ring_size, payload, address, q_id, offset;
     187                 :            :         rte_iova_t phys_addr;
     188                 :            :         struct fpga_ring_ctrl_reg ring_reg;
     189                 :          0 :         struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
     190                 :            : 
     191                 :            :         address = FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE;
     192         [ #  # ]:          0 :         if (!(fpga_reg_read_32(fpga_dev->mmio_base, address) & 0x1)) {
     193                 :          0 :                 rte_bbdev_log(ERR,
     194                 :            :                                 "Queue-PF/VF mapping is not set! Was PF configured for device (%s) ?",
     195                 :            :                                 dev->data->name);
     196                 :          0 :                 return -EPERM;
     197                 :            :         }
     198                 :            : 
     199                 :            :         /* Clear queue registers structure */
     200                 :            :         memset(&ring_reg, 0, sizeof(struct fpga_ring_ctrl_reg));
     201                 :            : 
     202                 :            :         /* Scan queue map.
     203                 :            :          * If a queue is valid and mapped to a calling PF/VF the read value is
     204                 :            :          * replaced with a queue ID and if it's not then
     205                 :            :          * FPGA_INVALID_HW_QUEUE_ID is returned.
     206                 :            :          */
     207         [ #  # ]:          0 :         for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
     208                 :          0 :                 uint32_t hw_q_id = fpga_reg_read_32(fpga_dev->mmio_base,
     209         [ #  # ]:          0 :                                 FPGA_5GNR_FEC_QUEUE_MAP + (q_id << 2));
     210                 :            : 
     211                 :            :                 rte_bbdev_log_debug("%s: queue ID: %u, registry queue ID: %u",
     212                 :            :                                 dev->device->name, q_id, hw_q_id);
     213                 :            : 
     214         [ #  # ]:          0 :                 if (hw_q_id != FPGA_INVALID_HW_QUEUE_ID) {
     215                 :          0 :                         fpga_dev->q_bound_bit_map |= (1ULL << q_id);
     216                 :            :                         /* Clear queue register of found queue */
     217                 :          0 :                         offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
     218                 :            :                                 (sizeof(struct fpga_ring_ctrl_reg) * q_id);
     219                 :          0 :                         fpga_ring_reg_write(fpga_dev->mmio_base,
     220                 :            :                                         offset, ring_reg);
     221                 :          0 :                         ++hw_q_num;
     222                 :            :                 }
     223                 :            :         }
     224         [ #  # ]:          0 :         if (hw_q_num == 0) {
     225                 :          0 :                 rte_bbdev_log(ERR,
     226                 :            :                         "No HW queues assigned to this device. Probably this is a VF configured for PF mode. Check device configuration!");
     227                 :          0 :                 return -ENODEV;
     228                 :            :         }
     229                 :            : 
     230         [ #  # ]:          0 :         if (num_queues > hw_q_num) {
     231                 :          0 :                 rte_bbdev_log(ERR,
     232                 :            :                         "Not enough queues for device %s! Requested: %u, available: %u",
     233                 :            :                         dev->device->name, num_queues, hw_q_num);
     234                 :          0 :                 return -EINVAL;
     235                 :            :         }
     236                 :            : 
     237                 :            :         ring_size = FPGA_RING_MAX_SIZE * sizeof(struct fpga_dma_dec_desc);
     238                 :            : 
     239                 :            :         /* Enforce 32 byte alignment */
     240                 :            :         RTE_BUILD_BUG_ON((RTE_CACHE_LINE_SIZE % 32) != 0);
     241                 :            : 
     242                 :            :         /* Allocate memory for SW descriptor rings */
     243                 :          0 :         fpga_dev->sw_rings = rte_zmalloc_socket(dev->device->driver->name,
     244                 :          0 :                         num_queues * ring_size, RTE_CACHE_LINE_SIZE,
     245                 :            :                         socket_id);
     246         [ #  # ]:          0 :         if (fpga_dev->sw_rings == NULL) {
     247                 :          0 :                 rte_bbdev_log(ERR,
     248                 :            :                                 "Failed to allocate memory for %s:%u sw_rings",
     249                 :            :                                 dev->device->driver->name, dev->data->dev_id);
     250                 :          0 :                 return -ENOMEM;
     251                 :            :         }
     252                 :            : 
     253                 :          0 :         fpga_dev->sw_rings_phys = rte_malloc_virt2iova(fpga_dev->sw_rings);
     254                 :          0 :         fpga_dev->sw_ring_size = ring_size;
     255                 :          0 :         fpga_dev->sw_ring_max_depth = FPGA_RING_MAX_SIZE;
     256                 :            : 
     257                 :            :         /* Allocate memory for ring flush status */
     258                 :          0 :         fpga_dev->flush_queue_status = rte_zmalloc_socket(NULL,
     259                 :            :                         sizeof(uint64_t), RTE_CACHE_LINE_SIZE, socket_id);
     260         [ #  # ]:          0 :         if (fpga_dev->flush_queue_status == NULL) {
     261                 :          0 :                 rte_bbdev_log(ERR,
     262                 :            :                                 "Failed to allocate memory for %s:%u flush_queue_status",
     263                 :            :                                 dev->device->driver->name, dev->data->dev_id);
     264                 :          0 :                 return -ENOMEM;
     265                 :            :         }
     266                 :            : 
     267                 :            :         /* Set the flush status address registers */
     268                 :          0 :         phys_addr = rte_malloc_virt2iova(fpga_dev->flush_queue_status);
     269                 :            : 
     270                 :            :         address = FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_LW;
     271                 :          0 :         payload = (uint32_t)(phys_addr);
     272                 :          0 :         fpga_reg_write_32(fpga_dev->mmio_base, address, payload);
     273                 :            : 
     274                 :            :         address = FPGA_5GNR_FEC_VFQ_FLUSH_STATUS_HI;
     275                 :          0 :         payload = (uint32_t)(phys_addr >> 32);
     276                 :            :         fpga_reg_write_32(fpga_dev->mmio_base, address, payload);
     277                 :            : 
     278                 :          0 :         return 0;
     279                 :            : }
     280                 :            : 
     281                 :            : static int
     282                 :          0 : fpga_dev_close(struct rte_bbdev *dev)
     283                 :            : {
     284                 :          0 :         struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
     285                 :            : 
     286                 :          0 :         rte_free(fpga_dev->sw_rings);
     287                 :          0 :         rte_free(fpga_dev->flush_queue_status);
     288                 :            : 
     289                 :          0 :         return 0;
     290                 :            : }
     291                 :            : 
     292                 :            : static void
     293                 :          0 : fpga_dev_info_get(struct rte_bbdev *dev,
     294                 :            :                 struct rte_bbdev_driver_info *dev_info)
     295                 :            : {
     296                 :          0 :         struct fpga_5gnr_fec_device *d = dev->data->dev_private;
     297                 :            :         uint32_t q_id = 0;
     298                 :            : 
     299                 :            :         static const struct rte_bbdev_op_cap bbdev_capabilities[] = {
     300                 :            :                 {
     301                 :            :                         .type   = RTE_BBDEV_OP_LDPC_ENC,
     302                 :            :                         .cap.ldpc_enc = {
     303                 :            :                                 .capability_flags =
     304                 :            :                                                 RTE_BBDEV_LDPC_RATE_MATCH |
     305                 :            :                                                 RTE_BBDEV_LDPC_ENC_INTERRUPTS |
     306                 :            :                                                 RTE_BBDEV_LDPC_CRC_24B_ATTACH,
     307                 :            :                                 .num_buffers_src =
     308                 :            :                                                 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
     309                 :            :                                 .num_buffers_dst =
     310                 :            :                                                 RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
     311                 :            :                         }
     312                 :            :                 },
     313                 :            :                 {
     314                 :            :                 .type   = RTE_BBDEV_OP_LDPC_DEC,
     315                 :            :                 .cap.ldpc_dec = {
     316                 :            :                         .capability_flags =
     317                 :            :                                 RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK |
     318                 :            :                                 RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP |
     319                 :            :                                 RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE |
     320                 :            :                                 RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE |
     321                 :            :                                 RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE |
     322                 :            :                                 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE |
     323                 :            :                                 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE |
     324                 :            :                                 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK |
     325                 :            :                                 RTE_BBDEV_LDPC_DEC_INTERRUPTS |
     326                 :            :                                 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_FILLERS,
     327                 :            :                         .llr_size = 6,
     328                 :            :                         .llr_decimals = 2,
     329                 :            :                         .num_buffers_src =
     330                 :            :                                         RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
     331                 :            :                         .num_buffers_hard_out =
     332                 :            :                                         RTE_BBDEV_LDPC_MAX_CODE_BLOCKS,
     333                 :            :                         .num_buffers_soft_out = 0,
     334                 :            :                 }
     335                 :            :                 },
     336                 :            :                 RTE_BBDEV_END_OF_CAPABILITIES_LIST()
     337                 :            :         };
     338                 :            : 
     339                 :            :         /* Check the HARQ DDR size available */
     340                 :            :         uint8_t timeout_counter = 0;
     341                 :          0 :         uint32_t harq_buf_ready = fpga_reg_read_32(d->mmio_base,
     342                 :            :                         FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS);
     343         [ #  # ]:          0 :         while (harq_buf_ready != 1) {
     344                 :          0 :                 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
     345                 :          0 :                 timeout_counter++;
     346         [ #  # ]:          0 :                 harq_buf_ready = fpga_reg_read_32(d->mmio_base,
     347                 :            :                                 FPGA_5GNR_FEC_HARQ_BUF_SIZE_RDY_REGS);
     348         [ #  # ]:          0 :                 if (timeout_counter > FPGA_HARQ_RDY_TIMEOUT) {
     349                 :          0 :                         rte_bbdev_log(ERR, "HARQ Buffer not ready %d",
     350                 :            :                                         harq_buf_ready);
     351                 :            :                         harq_buf_ready = 1;
     352                 :            :                 }
     353                 :            :         }
     354                 :          0 :         uint32_t harq_buf_size = fpga_reg_read_32(d->mmio_base,
     355                 :            :                         FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
     356                 :            : 
     357                 :            :         static struct rte_bbdev_queue_conf default_queue_conf;
     358                 :          0 :         default_queue_conf.socket = dev->data->socket_id;
     359                 :          0 :         default_queue_conf.queue_size = FPGA_RING_MAX_SIZE;
     360                 :            : 
     361                 :          0 :         dev_info->driver_name = dev->device->driver->name;
     362                 :          0 :         dev_info->queue_size_lim = FPGA_RING_MAX_SIZE;
     363                 :          0 :         dev_info->hardware_accelerated = true;
     364                 :          0 :         dev_info->min_alignment = 64;
     365                 :          0 :         dev_info->harq_buffer_size = (harq_buf_size >> 10) + 1;
     366                 :          0 :         dev_info->default_queue_conf = default_queue_conf;
     367                 :          0 :         dev_info->capabilities = bbdev_capabilities;
     368                 :          0 :         dev_info->cpu_flag_reqs = NULL;
     369                 :          0 :         dev_info->data_endianness = RTE_LITTLE_ENDIAN;
     370                 :          0 :         dev_info->device_status = RTE_BBDEV_DEV_NOT_SUPPORTED;
     371                 :            : 
     372                 :            :         /* Calculates number of queues assigned to device */
     373                 :          0 :         dev_info->max_num_queues = 0;
     374         [ #  # ]:          0 :         for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
     375                 :          0 :                 uint32_t hw_q_id = fpga_reg_read_32(d->mmio_base,
     376         [ #  # ]:          0 :                                 FPGA_5GNR_FEC_QUEUE_MAP + (q_id << 2));
     377         [ #  # ]:          0 :                 if (hw_q_id != FPGA_INVALID_HW_QUEUE_ID)
     378                 :          0 :                         dev_info->max_num_queues++;
     379                 :            :         }
     380                 :            :         /* Expose number of queue per operation type */
     381                 :          0 :         dev_info->num_queues[RTE_BBDEV_OP_NONE] = 0;
     382                 :          0 :         dev_info->num_queues[RTE_BBDEV_OP_TURBO_DEC] = 0;
     383                 :          0 :         dev_info->num_queues[RTE_BBDEV_OP_TURBO_ENC] = 0;
     384                 :          0 :         dev_info->num_queues[RTE_BBDEV_OP_LDPC_DEC] = dev_info->max_num_queues / 2;
     385                 :          0 :         dev_info->num_queues[RTE_BBDEV_OP_LDPC_ENC] = dev_info->max_num_queues / 2;
     386                 :          0 :         dev_info->queue_priority[RTE_BBDEV_OP_LDPC_DEC] = 1;
     387                 :          0 :         dev_info->queue_priority[RTE_BBDEV_OP_LDPC_ENC] = 1;
     388                 :          0 : }
     389                 :            : 
     390                 :            : /**
     391                 :            :  * Find index of queue bound to current PF/VF which is unassigned. Return -1
     392                 :            :  * when there is no available queue
     393                 :            :  */
     394                 :            : static inline int
     395                 :          0 : fpga_find_free_queue_idx(struct rte_bbdev *dev,
     396                 :            :                 const struct rte_bbdev_queue_conf *conf)
     397                 :            : {
     398                 :          0 :         struct fpga_5gnr_fec_device *d = dev->data->dev_private;
     399                 :            :         uint64_t q_idx;
     400                 :            :         uint8_t i = 0;
     401                 :            :         uint8_t range = FPGA_TOTAL_NUM_QUEUES >> 1;
     402                 :            : 
     403         [ #  # ]:          0 :         if (conf->op_type == RTE_BBDEV_OP_LDPC_ENC) {
     404                 :            :                 i = FPGA_NUM_DL_QUEUES;
     405                 :            :                 range = FPGA_TOTAL_NUM_QUEUES;
     406                 :            :         }
     407                 :            : 
     408         [ #  # ]:          0 :         for (; i < range; ++i) {
     409                 :          0 :                 q_idx = 1ULL << i;
     410                 :            :                 /* Check if index of queue is bound to current PF/VF */
     411         [ #  # ]:          0 :                 if (d->q_bound_bit_map & q_idx)
     412                 :            :                         /* Check if found queue was not already assigned */
     413         [ #  # ]:          0 :                         if (!(d->q_assigned_bit_map & q_idx)) {
     414                 :          0 :                                 d->q_assigned_bit_map |= q_idx;
     415                 :          0 :                                 return i;
     416                 :            :                         }
     417                 :            :         }
     418                 :            : 
     419                 :          0 :         rte_bbdev_log(INFO, "Failed to find free queue on %s", dev->data->name);
     420                 :            : 
     421                 :          0 :         return -1;
     422                 :            : }
     423                 :            : 
     424                 :            : static int
     425                 :          0 : fpga_queue_setup(struct rte_bbdev *dev, uint16_t queue_id,
     426                 :            :                 const struct rte_bbdev_queue_conf *conf)
     427                 :            : {
     428                 :            :         uint32_t address, ring_offset;
     429                 :          0 :         struct fpga_5gnr_fec_device *d = dev->data->dev_private;
     430                 :            :         struct fpga_queue *q;
     431                 :            :         int8_t q_idx;
     432                 :            : 
     433                 :            :         /* Check if there is a free queue to assign */
     434                 :          0 :         q_idx = fpga_find_free_queue_idx(dev, conf);
     435         [ #  # ]:          0 :         if (q_idx == -1)
     436                 :            :                 return -1;
     437                 :            : 
     438                 :            :         /* Allocate the queue data structure. */
     439                 :          0 :         q = rte_zmalloc_socket(dev->device->driver->name, sizeof(*q),
     440                 :          0 :                         RTE_CACHE_LINE_SIZE, conf->socket);
     441         [ #  # ]:          0 :         if (q == NULL) {
     442                 :            :                 /* Mark queue as un-assigned */
     443                 :          0 :                 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
     444                 :          0 :                 rte_bbdev_log(ERR, "Failed to allocate queue memory");
     445                 :          0 :                 return -ENOMEM;
     446                 :            :         }
     447                 :            : 
     448                 :          0 :         q->d = d;
     449                 :          0 :         q->q_idx = q_idx;
     450                 :            : 
     451                 :            :         /* Set ring_base_addr */
     452                 :          0 :         q->ring_addr = RTE_PTR_ADD(d->sw_rings, (d->sw_ring_size * queue_id));
     453                 :          0 :         q->ring_ctrl_reg.ring_base_addr = d->sw_rings_phys +
     454                 :            :                         (d->sw_ring_size * queue_id);
     455                 :            : 
     456                 :            :         /* Allocate memory for Completion Head variable*/
     457                 :          0 :         q->ring_head_addr = rte_zmalloc_socket(dev->device->driver->name,
     458                 :          0 :                         sizeof(uint64_t), RTE_CACHE_LINE_SIZE, conf->socket);
     459         [ #  # ]:          0 :         if (q->ring_head_addr == NULL) {
     460                 :            :                 /* Mark queue as un-assigned */
     461                 :          0 :                 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
     462                 :          0 :                 rte_free(q);
     463                 :          0 :                 rte_bbdev_log(ERR,
     464                 :            :                                 "Failed to allocate memory for %s:%u completion_head",
     465                 :            :                                 dev->device->driver->name, dev->data->dev_id);
     466                 :          0 :                 return -ENOMEM;
     467                 :            :         }
     468                 :            :         /* Set ring_head_addr */
     469                 :          0 :         q->ring_ctrl_reg.ring_head_addr =
     470                 :          0 :                         rte_malloc_virt2iova(q->ring_head_addr);
     471                 :            : 
     472                 :            :         /* Clear shadow_completion_head */
     473                 :          0 :         q->shadow_completion_head = 0;
     474                 :            : 
     475                 :            :         /* Set ring_size */
     476         [ #  # ]:          0 :         if (conf->queue_size > FPGA_RING_MAX_SIZE) {
     477                 :            :                 /* Mark queue as un-assigned */
     478                 :          0 :                 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q_idx));
     479                 :          0 :                 rte_free(q->ring_head_addr);
     480                 :          0 :                 rte_free(q);
     481                 :          0 :                 rte_bbdev_log(ERR,
     482                 :            :                                 "Size of queue is too big %d (MAX: %d ) for %s:%u",
     483                 :            :                                 conf->queue_size, FPGA_RING_MAX_SIZE,
     484                 :            :                                 dev->device->driver->name, dev->data->dev_id);
     485                 :          0 :                 return -EINVAL;
     486                 :            :         }
     487                 :          0 :         q->ring_ctrl_reg.ring_size = conf->queue_size;
     488                 :            : 
     489                 :            :         /* Set Miscellaneous FPGA register*/
     490                 :            :         /* Max iteration number for TTI mitigation - todo */
     491                 :          0 :         q->ring_ctrl_reg.max_ul_dec = 0;
     492                 :            :         /* Enable max iteration number for TTI - todo */
     493                 :            :         q->ring_ctrl_reg.max_ul_dec_en = 0;
     494                 :            : 
     495                 :            :         /* Enable the ring */
     496                 :          0 :         q->ring_ctrl_reg.enable = 1;
     497                 :            : 
     498                 :            :         /* Set FPGA head_point and tail registers */
     499                 :          0 :         q->ring_ctrl_reg.head_point = q->tail = 0;
     500                 :            : 
     501                 :            :         /* Set FPGA shadow_tail register */
     502                 :          0 :         q->ring_ctrl_reg.shadow_tail = q->tail;
     503                 :            : 
     504                 :            :         /* Calculates the ring offset for found queue */
     505                 :          0 :         ring_offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
     506                 :            :                         (sizeof(struct fpga_ring_ctrl_reg) * q_idx);
     507                 :            : 
     508                 :            :         /* Set FPGA Ring Control Registers */
     509                 :          0 :         fpga_ring_reg_write(d->mmio_base, ring_offset, q->ring_ctrl_reg);
     510                 :            : 
     511                 :            :         /* Store MMIO register of shadow_tail */
     512                 :          0 :         address = ring_offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL;
     513                 :          0 :         q->shadow_tail_addr = RTE_PTR_ADD(d->mmio_base, address);
     514                 :            : 
     515                 :          0 :         q->head_free_desc = q->tail;
     516                 :            : 
     517                 :            :         /* Set wrap mask */
     518                 :          0 :         q->sw_ring_wrap_mask = conf->queue_size - 1;
     519                 :            : 
     520                 :            :         rte_bbdev_log_debug("Setup dev%u q%u: queue_idx=%u",
     521                 :            :                         dev->data->dev_id, queue_id, q->q_idx);
     522                 :            : 
     523                 :          0 :         dev->data->queues[queue_id].queue_private = q;
     524                 :            : 
     525                 :            :         rte_bbdev_log_debug("BBDEV queue[%d] set up for FPGA queue[%d]",
     526                 :            :                         queue_id, q_idx);
     527                 :            : 
     528                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
     529                 :            :         /* Read FPGA Ring Control Registers after configuration*/
     530                 :            :         print_ring_reg_debug_info(d->mmio_base, ring_offset);
     531                 :            : #endif
     532                 :          0 :         return 0;
     533                 :            : }
     534                 :            : 
     535                 :            : static int
     536                 :          0 : fpga_queue_release(struct rte_bbdev *dev, uint16_t queue_id)
     537                 :            : {
     538                 :          0 :         struct fpga_5gnr_fec_device *d = dev->data->dev_private;
     539                 :          0 :         struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
     540                 :            :         struct fpga_ring_ctrl_reg ring_reg;
     541                 :            :         uint32_t offset;
     542                 :            : 
     543                 :            :         rte_bbdev_log_debug("FPGA Queue[%d] released", queue_id);
     544                 :            : 
     545         [ #  # ]:          0 :         if (q != NULL) {
     546                 :            :                 memset(&ring_reg, 0, sizeof(struct fpga_ring_ctrl_reg));
     547                 :          0 :                 offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
     548                 :          0 :                         (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
     549                 :            :                 /* Disable queue */
     550                 :          0 :                 fpga_reg_write_8(d->mmio_base,
     551                 :            :                                 offset + FPGA_5GNR_FEC_RING_ENABLE, 0x00);
     552                 :            :                 /* Clear queue registers */
     553                 :          0 :                 fpga_ring_reg_write(d->mmio_base, offset, ring_reg);
     554                 :            : 
     555                 :            :                 /* Mark the Queue as un-assigned */
     556                 :          0 :                 d->q_assigned_bit_map &= (0xFFFFFFFF - (1ULL << q->q_idx));
     557                 :          0 :                 rte_free(q->ring_head_addr);
     558                 :          0 :                 rte_free(q);
     559                 :          0 :                 dev->data->queues[queue_id].queue_private = NULL;
     560                 :            :         }
     561                 :            : 
     562                 :          0 :         return 0;
     563                 :            : }
     564                 :            : 
     565                 :            : /* Function starts a device queue. */
     566                 :            : static int
     567                 :          0 : fpga_queue_start(struct rte_bbdev *dev, uint16_t queue_id)
     568                 :            : {
     569                 :          0 :         struct fpga_5gnr_fec_device *d = dev->data->dev_private;
     570                 :          0 :         struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
     571                 :          0 :         uint32_t offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
     572                 :          0 :                         (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
     573                 :            :         uint8_t enable = 0x01;
     574                 :            :         uint16_t zero = 0x0000;
     575                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
     576                 :            :         if (d == NULL) {
     577                 :            :                 rte_bbdev_log(ERR, "Invalid device pointer");
     578                 :            :                 return -1;
     579                 :            :         }
     580                 :            : #endif
     581                 :            :         if (dev->data->queues[queue_id].queue_private == NULL) {
     582                 :            :                 rte_bbdev_log(ERR, "Cannot start invalid queue %d", queue_id);
     583                 :            :                 return -1;
     584                 :            :         }
     585                 :            : 
     586                 :            :         /* Clear queue head and tail variables */
     587                 :          0 :         q->tail = q->head_free_desc = 0;
     588                 :            : 
     589                 :            :         /* Clear FPGA head_point and tail registers */
     590                 :          0 :         fpga_reg_write_16(d->mmio_base, offset + FPGA_5GNR_FEC_RING_HEAD_POINT,
     591                 :            :                         zero);
     592                 :          0 :         fpga_reg_write_16(d->mmio_base, offset + FPGA_5GNR_FEC_RING_SHADOW_TAIL,
     593                 :            :                         zero);
     594                 :            : 
     595                 :            :         /* Enable queue */
     596                 :          0 :         fpga_reg_write_8(d->mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE,
     597                 :            :                         enable);
     598                 :            : 
     599                 :            :         rte_bbdev_log_debug("FPGA Queue[%d] started", queue_id);
     600                 :            :         return 0;
     601                 :            : }
     602                 :            : 
     603                 :            : /* Function stops a device queue. */
     604                 :            : static int
     605                 :          0 : fpga_queue_stop(struct rte_bbdev *dev, uint16_t queue_id)
     606                 :            : {
     607                 :          0 :         struct fpga_5gnr_fec_device *d = dev->data->dev_private;
     608                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
     609                 :            :         if (d == NULL) {
     610                 :            :                 rte_bbdev_log(ERR, "Invalid device pointer");
     611                 :            :                 return -1;
     612                 :            :         }
     613                 :            : #endif
     614                 :          0 :         struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
     615                 :          0 :         uint32_t offset = FPGA_5GNR_FEC_RING_CTRL_REGS +
     616                 :          0 :                         (sizeof(struct fpga_ring_ctrl_reg) * q->q_idx);
     617                 :            :         uint8_t payload = 0x01;
     618                 :            :         uint8_t counter = 0;
     619                 :            :         uint8_t timeout = FPGA_QUEUE_FLUSH_TIMEOUT_US /
     620                 :            :                         FPGA_TIMEOUT_CHECK_INTERVAL;
     621                 :            : 
     622                 :            :         /* Set flush_queue_en bit to trigger queue flushing */
     623                 :          0 :         fpga_reg_write_8(d->mmio_base,
     624                 :            :                         offset + FPGA_5GNR_FEC_RING_FLUSH_QUEUE_EN, payload);
     625                 :            : 
     626                 :            :         /** Check if queue flush is completed.
     627                 :            :          * FPGA will update the completion flag after queue flushing is
     628                 :            :          * completed. If completion flag is not updated within 1ms it is
     629                 :            :          * considered as a failure.
     630                 :            :          */
     631         [ #  # ]:          0 :         while (!(*((volatile uint8_t *)d->flush_queue_status + q->q_idx)
     632                 :            :                         & payload)) {
     633         [ #  # ]:          0 :                 if (counter > timeout) {
     634                 :          0 :                         rte_bbdev_log(ERR, "FPGA Queue Flush failed for queue %d",
     635                 :            :                                         queue_id);
     636                 :          0 :                         return -1;
     637                 :            :                 }
     638                 :          0 :                 usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
     639                 :          0 :                 counter++;
     640                 :            :         }
     641                 :            : 
     642                 :            :         /* Disable queue */
     643                 :            :         payload = 0x00;
     644                 :          0 :         fpga_reg_write_8(d->mmio_base, offset + FPGA_5GNR_FEC_RING_ENABLE,
     645                 :            :                         payload);
     646                 :            : 
     647                 :            :         rte_bbdev_log_debug("FPGA Queue[%d] stopped", queue_id);
     648                 :          0 :         return 0;
     649                 :            : }
     650                 :            : 
     651                 :            : static inline uint16_t
     652                 :            : get_queue_id(struct rte_bbdev_data *data, uint8_t q_idx)
     653                 :            : {
     654                 :            :         uint16_t queue_id;
     655                 :            : 
     656         [ #  # ]:          0 :         for (queue_id = 0; queue_id < data->num_queues; ++queue_id) {
     657                 :          0 :                 struct fpga_queue *q = data->queues[queue_id].queue_private;
     658   [ #  #  #  # ]:          0 :                 if (q != NULL && q->q_idx == q_idx)
     659                 :            :                         return queue_id;
     660                 :            :         }
     661                 :            : 
     662                 :            :         return -1;
     663                 :            : }
     664                 :            : 
     665                 :            : /* Interrupt handler triggered by FPGA dev for handling specific interrupt */
     666                 :            : static void
     667                 :          0 : fpga_dev_interrupt_handler(void *cb_arg)
     668                 :            : {
     669                 :            :         struct rte_bbdev *dev = cb_arg;
     670                 :          0 :         struct fpga_5gnr_fec_device *fpga_dev = dev->data->dev_private;
     671                 :            :         struct fpga_queue *q;
     672                 :            :         uint64_t ring_head;
     673                 :            :         uint64_t q_idx;
     674                 :            :         uint16_t queue_id;
     675                 :            :         uint8_t i;
     676                 :            : 
     677                 :            :         /* Scan queue assigned to this device */
     678         [ #  # ]:          0 :         for (i = 0; i < FPGA_TOTAL_NUM_QUEUES; ++i) {
     679                 :          0 :                 q_idx = 1ULL << i;
     680         [ #  # ]:          0 :                 if (fpga_dev->q_bound_bit_map & q_idx) {
     681                 :          0 :                         queue_id = get_queue_id(dev->data, i);
     682         [ #  # ]:          0 :                         if (queue_id == (uint16_t) -1)
     683                 :          0 :                                 continue;
     684                 :            : 
     685                 :            :                         /* Check if completion head was changed */
     686                 :          0 :                         q = dev->data->queues[queue_id].queue_private;
     687                 :          0 :                         ring_head = *q->ring_head_addr;
     688         [ #  # ]:          0 :                         if (q->shadow_completion_head != ring_head &&
     689         [ #  # ]:          0 :                                 q->irq_enable == 1) {
     690                 :          0 :                                 q->shadow_completion_head = ring_head;
     691                 :          0 :                                 rte_bbdev_pmd_callback_process(
     692                 :            :                                                 dev,
     693                 :            :                                                 RTE_BBDEV_EVENT_DEQUEUE,
     694                 :            :                                                 &queue_id);
     695                 :            :                         }
     696                 :            :                 }
     697                 :            :         }
     698                 :          0 : }
     699                 :            : 
     700                 :            : static int
     701                 :          0 : fpga_queue_intr_enable(struct rte_bbdev *dev, uint16_t queue_id)
     702                 :            : {
     703                 :          0 :         struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
     704                 :            : 
     705         [ #  # ]:          0 :         if (!rte_intr_cap_multiple(dev->intr_handle))
     706                 :            :                 return -ENOTSUP;
     707                 :            : 
     708                 :          0 :         q->irq_enable = 1;
     709                 :            : 
     710                 :          0 :         return 0;
     711                 :            : }
     712                 :            : 
     713                 :            : static int
     714                 :          0 : fpga_queue_intr_disable(struct rte_bbdev *dev, uint16_t queue_id)
     715                 :            : {
     716                 :          0 :         struct fpga_queue *q = dev->data->queues[queue_id].queue_private;
     717                 :          0 :         q->irq_enable = 0;
     718                 :            : 
     719                 :          0 :         return 0;
     720                 :            : }
     721                 :            : 
     722                 :            : static int
     723                 :          0 : fpga_intr_enable(struct rte_bbdev *dev)
     724                 :            : {
     725                 :            :         int ret;
     726                 :            :         uint8_t i;
     727                 :            : 
     728         [ #  # ]:          0 :         if (!rte_intr_cap_multiple(dev->intr_handle)) {
     729                 :          0 :                 rte_bbdev_log(ERR, "Multiple intr vector is not supported by FPGA (%s)",
     730                 :            :                                 dev->data->name);
     731                 :          0 :                 return -ENOTSUP;
     732                 :            :         }
     733                 :            : 
     734                 :            :         /* Create event file descriptors for each of 64 queue. Event fds will be
     735                 :            :          * mapped to FPGA IRQs in rte_intr_enable(). This is a 1:1 mapping where
     736                 :            :          * the IRQ number is a direct translation to the queue number.
     737                 :            :          *
     738                 :            :          * 63 (FPGA_NUM_INTR_VEC) event fds are created as rte_intr_enable()
     739                 :            :          * mapped the first IRQ to already created interrupt event file
     740                 :            :          * descriptor (intr_handle->fd).
     741                 :            :          */
     742         [ #  # ]:          0 :         if (rte_intr_efd_enable(dev->intr_handle, FPGA_NUM_INTR_VEC)) {
     743                 :          0 :                 rte_bbdev_log(ERR, "Failed to create fds for %u queues",
     744                 :            :                                 dev->data->num_queues);
     745                 :          0 :                 return -1;
     746                 :            :         }
     747                 :            : 
     748                 :            :         /* TODO Each event file descriptor is overwritten by interrupt event
     749                 :            :          * file descriptor. That descriptor is added to epoll observed list.
     750                 :            :          * It ensures that callback function assigned to that descriptor will
     751                 :            :          * invoked when any FPGA queue issues interrupt.
     752                 :            :          */
     753         [ #  # ]:          0 :         for (i = 0; i < FPGA_NUM_INTR_VEC; ++i) {
     754         [ #  # ]:          0 :                 if (rte_intr_efds_index_set(dev->intr_handle, i,
     755                 :          0 :                                 rte_intr_fd_get(dev->intr_handle)))
     756                 :          0 :                         return -rte_errno;
     757                 :            :         }
     758                 :            : 
     759         [ #  # ]:          0 :         if (rte_intr_vec_list_alloc(dev->intr_handle, "intr_vec",
     760                 :          0 :                         dev->data->num_queues)) {
     761                 :          0 :                 rte_bbdev_log(ERR, "Failed to allocate %u vectors",
     762                 :            :                                 dev->data->num_queues);
     763                 :          0 :                 return -ENOMEM;
     764                 :            :         }
     765                 :            : 
     766                 :          0 :         ret = rte_intr_enable(dev->intr_handle);
     767         [ #  # ]:          0 :         if (ret < 0) {
     768                 :          0 :                 rte_bbdev_log(ERR,
     769                 :            :                                 "Couldn't enable interrupts for device: %s",
     770                 :            :                                 dev->data->name);
     771                 :          0 :                 return ret;
     772                 :            :         }
     773                 :            : 
     774                 :          0 :         ret = rte_intr_callback_register(dev->intr_handle,
     775                 :            :                         fpga_dev_interrupt_handler, dev);
     776         [ #  # ]:          0 :         if (ret < 0) {
     777                 :          0 :                 rte_bbdev_log(ERR,
     778                 :            :                                 "Couldn't register interrupt callback for device: %s",
     779                 :            :                                 dev->data->name);
     780                 :          0 :                 return ret;
     781                 :            :         }
     782                 :            : 
     783                 :            :         return 0;
     784                 :            : }
     785                 :            : 
     786                 :            : static const struct rte_bbdev_ops fpga_ops = {
     787                 :            :         .setup_queues = fpga_setup_queues,
     788                 :            :         .intr_enable = fpga_intr_enable,
     789                 :            :         .close = fpga_dev_close,
     790                 :            :         .info_get = fpga_dev_info_get,
     791                 :            :         .queue_setup = fpga_queue_setup,
     792                 :            :         .queue_stop = fpga_queue_stop,
     793                 :            :         .queue_start = fpga_queue_start,
     794                 :            :         .queue_release = fpga_queue_release,
     795                 :            :         .queue_intr_enable = fpga_queue_intr_enable,
     796                 :            :         .queue_intr_disable = fpga_queue_intr_disable
     797                 :            : };
     798                 :            : 
     799                 :            : static inline void
     800                 :            : fpga_dma_enqueue(struct fpga_queue *q, uint16_t num_desc,
     801                 :            :                 struct rte_bbdev_stats *queue_stats)
     802                 :            : {
     803                 :            :         uint64_t start_time = 0;
     804                 :          0 :         queue_stats->acc_offload_cycles = 0;
     805                 :            : 
     806                 :            :         /* Update tail and shadow_tail register */
     807                 :          0 :         q->tail = (q->tail + num_desc) & q->sw_ring_wrap_mask;
     808                 :            : 
     809                 :            :         rte_wmb();
     810                 :            : 
     811                 :            :         /* Start time measurement for enqueue function offload. */
     812                 :            :         start_time = rte_rdtsc_precise();
     813                 :          0 :         mmio_write_16(q->shadow_tail_addr, q->tail);
     814                 :            : 
     815                 :            :         rte_wmb();
     816                 :          0 :         queue_stats->acc_offload_cycles += rte_rdtsc_precise() - start_time;
     817                 :            : }
     818                 :            : 
     819                 :            : /* Read flag value 0/1/ from bitmap */
     820                 :            : static inline bool
     821                 :            : check_bit(uint32_t bitmap, uint32_t bitmask)
     822                 :            : {
     823                 :          0 :         return bitmap & bitmask;
     824                 :            : }
     825                 :            : 
     826                 :            : /* Print an error if a descriptor error has occurred.
     827                 :            :  *  Return 0 on success, 1 on failure
     828                 :            :  */
     829                 :            : static inline int
     830                 :          0 : check_desc_error(uint32_t error_code) {
     831   [ #  #  #  #  :          0 :         switch (error_code) {
          #  #  #  #  #  
             #  #  #  # ]
     832                 :            :         case DESC_ERR_NO_ERR:
     833                 :            :                 return 0;
     834                 :          0 :         case DESC_ERR_K_P_OUT_OF_RANGE:
     835                 :          0 :                 rte_bbdev_log(ERR, "Encode block size K' is out of range");
     836                 :          0 :                 break;
     837                 :          0 :         case DESC_ERR_Z_C_NOT_LEGAL:
     838                 :          0 :                 rte_bbdev_log(ERR, "Zc is illegal");
     839                 :          0 :                 break;
     840                 :          0 :         case DESC_ERR_DESC_OFFSET_ERR:
     841                 :          0 :                 rte_bbdev_log(ERR,
     842                 :            :                                 "Queue offset does not meet the expectation in the FPGA"
     843                 :            :                                 );
     844                 :          0 :                 break;
     845                 :          0 :         case DESC_ERR_DESC_READ_FAIL:
     846                 :          0 :                 rte_bbdev_log(ERR, "Unsuccessful completion for descriptor read");
     847                 :          0 :                 break;
     848                 :          0 :         case DESC_ERR_DESC_READ_TIMEOUT:
     849                 :          0 :                 rte_bbdev_log(ERR, "Descriptor read time-out");
     850                 :          0 :                 break;
     851                 :          0 :         case DESC_ERR_DESC_READ_TLP_POISONED:
     852                 :          0 :                 rte_bbdev_log(ERR, "Descriptor read TLP poisoned");
     853                 :          0 :                 break;
     854                 :          0 :         case DESC_ERR_HARQ_INPUT_LEN:
     855                 :          0 :                 rte_bbdev_log(ERR, "HARQ input length is invalid");
     856                 :          0 :                 break;
     857                 :          0 :         case DESC_ERR_CB_READ_FAIL:
     858                 :          0 :                 rte_bbdev_log(ERR, "Unsuccessful completion for code block");
     859                 :          0 :                 break;
     860                 :          0 :         case DESC_ERR_CB_READ_TIMEOUT:
     861                 :          0 :                 rte_bbdev_log(ERR, "Code block read time-out");
     862                 :          0 :                 break;
     863                 :          0 :         case DESC_ERR_CB_READ_TLP_POISONED:
     864                 :          0 :                 rte_bbdev_log(ERR, "Code block read TLP poisoned");
     865                 :          0 :                 break;
     866                 :          0 :         case DESC_ERR_HBSTORE_ERR:
     867                 :          0 :                 rte_bbdev_log(ERR, "Hbstroe exceeds HARQ buffer size.");
     868                 :          0 :                 break;
     869                 :          0 :         default:
     870                 :          0 :                 rte_bbdev_log(ERR, "Descriptor error unknown error code %u",
     871                 :            :                                 error_code);
     872                 :          0 :                 break;
     873                 :            :         }
     874                 :            :         return 1;
     875                 :            : }
     876                 :            : 
     877                 :            : /* Compute value of k0.
     878                 :            :  * Based on 3GPP 38.212 Table 5.4.2.1-2
     879                 :            :  * Starting position of different redundancy versions, k0
     880                 :            :  */
     881                 :            : static inline uint16_t
     882                 :          0 : get_k0(uint16_t n_cb, uint16_t z_c, uint8_t bg, uint8_t rv_index)
     883                 :            : {
     884         [ #  # ]:          0 :         uint16_t n = (bg == 1 ? N_ZC_1 : N_ZC_2) * z_c;
     885         [ #  # ]:          0 :         if (rv_index == 0)
     886                 :            :                 return 0;
     887         [ #  # ]:          0 :         if (z_c == 0)
     888                 :            :                 return 0;
     889         [ #  # ]:          0 :         if (n_cb == n) {
     890         [ #  # ]:          0 :                 if (rv_index == 1)
     891         [ #  # ]:          0 :                         return (bg == 1 ? K0_1_1 : K0_1_2) * z_c;
     892         [ #  # ]:          0 :                 else if (rv_index == 2)
     893         [ #  # ]:          0 :                         return (bg == 1 ? K0_2_1 : K0_2_2) * z_c;
     894                 :            :                 else
     895         [ #  # ]:          0 :                         return (bg == 1 ? K0_3_1 : K0_3_2) * z_c;
     896                 :            :         }
     897                 :            :         /* LBRM case - includes a division by N */
     898         [ #  # ]:          0 :         if (rv_index == 1)
     899         [ #  # ]:          0 :                 return (((bg == 1 ? K0_1_1 : K0_1_2) * n_cb)
     900                 :          0 :                                 / n) * z_c;
     901         [ #  # ]:          0 :         else if (rv_index == 2)
     902         [ #  # ]:          0 :                 return (((bg == 1 ? K0_2_1 : K0_2_2) * n_cb)
     903                 :          0 :                                 / n) * z_c;
     904                 :            :         else
     905         [ #  # ]:          0 :                 return (((bg == 1 ? K0_3_1 : K0_3_2) * n_cb)
     906                 :          0 :                                 / n) * z_c;
     907                 :            : }
     908                 :            : 
     909                 :            : /**
     910                 :            :  * Set DMA descriptor for encode operation (1 Code Block)
     911                 :            :  *
     912                 :            :  * @param op
     913                 :            :  *   Pointer to a single encode operation.
     914                 :            :  * @param desc
     915                 :            :  *   Pointer to DMA descriptor.
     916                 :            :  * @param input
     917                 :            :  *   Pointer to pointer to input data which will be decoded.
     918                 :            :  * @param e
     919                 :            :  *   E value (length of output in bits).
     920                 :            :  * @param ncb
     921                 :            :  *   Ncb value (size of the soft buffer).
     922                 :            :  * @param out_length
     923                 :            :  *   Length of output buffer
     924                 :            :  * @param in_offset
     925                 :            :  *   Input offset in rte_mbuf structure. It is used for calculating the point
     926                 :            :  *   where data is starting.
     927                 :            :  * @param out_offset
     928                 :            :  *   Output offset in rte_mbuf structure. It is used for calculating the point
     929                 :            :  *   where hard output data will be stored.
     930                 :            :  * @param cbs_in_op
     931                 :            :  *   Number of CBs contained in one operation.
     932                 :            :  */
     933                 :            : static inline int
     934                 :          0 : fpga_dma_desc_te_fill(struct rte_bbdev_enc_op *op,
     935                 :            :                 struct fpga_dma_enc_desc *desc, struct rte_mbuf *input,
     936                 :            :                 struct rte_mbuf *output, uint16_t k_,  uint16_t e,
     937                 :            :                 uint32_t in_offset, uint32_t out_offset, uint16_t desc_offset,
     938                 :            :                 uint8_t cbs_in_op)
     939                 :            : {
     940                 :            :         /* reset */
     941                 :          0 :         desc->done = 0;
     942                 :          0 :         desc->error = 0;
     943                 :          0 :         desc->k_ = k_;
     944                 :          0 :         desc->rm_e = e;
     945                 :          0 :         desc->desc_idx = desc_offset;
     946                 :          0 :         desc->zc = op->ldpc_enc.z_c;
     947                 :          0 :         desc->bg_idx = op->ldpc_enc.basegraph - 1;
     948                 :          0 :         desc->qm_idx = op->ldpc_enc.q_m / 2;
     949                 :          0 :         desc->crc_en = check_bit(op->ldpc_enc.op_flags,
     950                 :            :                         RTE_BBDEV_LDPC_CRC_24B_ATTACH);
     951                 :          0 :         desc->irq_en = 0;
     952                 :          0 :         desc->k0 = get_k0(op->ldpc_enc.n_cb, op->ldpc_enc.z_c,
     953                 :          0 :                         op->ldpc_enc.basegraph, op->ldpc_enc.rv_index);
     954                 :          0 :         desc->ncb = op->ldpc_enc.n_cb;
     955                 :          0 :         desc->num_null = op->ldpc_enc.n_filler;
     956                 :            :         /* Set inbound data buffer address */
     957                 :          0 :         desc->in_addr_hi = (uint32_t)(
     958                 :          0 :                         rte_pktmbuf_iova_offset(input, in_offset) >> 32);
     959                 :          0 :         desc->in_addr_lw = (uint32_t)(
     960                 :          0 :                         rte_pktmbuf_iova_offset(input, in_offset));
     961                 :            : 
     962                 :          0 :         desc->out_addr_hi = (uint32_t)(
     963                 :          0 :                         rte_pktmbuf_iova_offset(output, out_offset) >> 32);
     964                 :          0 :         desc->out_addr_lw = (uint32_t)(
     965                 :          0 :                         rte_pktmbuf_iova_offset(output, out_offset));
     966                 :            :         /* Save software context needed for dequeue */
     967                 :          0 :         desc->op_addr = op;
     968                 :            :         /* Set total number of CBs in an op */
     969                 :          0 :         desc->cbs_in_op = cbs_in_op;
     970                 :          0 :         return 0;
     971                 :            : }
     972                 :            : 
     973                 :            : /**
     974                 :            :  * Set DMA descriptor for decode operation (1 Code Block)
     975                 :            :  *
     976                 :            :  * @param op
     977                 :            :  *   Pointer to a single encode operation.
     978                 :            :  * @param desc
     979                 :            :  *   Pointer to DMA descriptor.
     980                 :            :  * @param input
     981                 :            :  *   Pointer to pointer to input data which will be decoded.
     982                 :            :  * @param in_offset
     983                 :            :  *   Input offset in rte_mbuf structure. It is used for calculating the point
     984                 :            :  *   where data is starting.
     985                 :            :  * @param out_offset
     986                 :            :  *   Output offset in rte_mbuf structure. It is used for calculating the point
     987                 :            :  *   where hard output data will be stored.
     988                 :            :  * @param cbs_in_op
     989                 :            :  *   Number of CBs contained in one operation.
     990                 :            :  */
     991                 :            : static inline int
     992                 :          0 : fpga_dma_desc_ld_fill(struct rte_bbdev_dec_op *op,
     993                 :            :                 struct fpga_dma_dec_desc *desc,
     994                 :            :                 struct rte_mbuf *input, struct rte_mbuf *output,
     995                 :            :                 uint16_t harq_in_length,
     996                 :            :                 uint32_t in_offset, uint32_t out_offset,
     997                 :            :                 uint32_t harq_offset,
     998                 :            :                 uint16_t desc_offset,
     999                 :            :                 uint8_t cbs_in_op)
    1000                 :            : {
    1001                 :            :         /* reset */
    1002                 :          0 :         desc->done = 0;
    1003                 :          0 :         desc->error = 0;
    1004                 :            :         /* Set inbound data buffer address */
    1005                 :          0 :         desc->in_addr_hi = (uint32_t)(
    1006                 :          0 :                         rte_pktmbuf_iova_offset(input, in_offset) >> 32);
    1007                 :          0 :         desc->in_addr_lw = (uint32_t)(
    1008                 :          0 :                         rte_pktmbuf_iova_offset(input, in_offset));
    1009                 :          0 :         desc->rm_e = op->ldpc_dec.cb_params.e;
    1010                 :          0 :         desc->harq_input_length = harq_in_length;
    1011                 :          0 :         desc->et_dis = !check_bit(op->ldpc_dec.op_flags,
    1012                 :            :                         RTE_BBDEV_LDPC_ITERATION_STOP_ENABLE);
    1013                 :          0 :         desc->rv = op->ldpc_dec.rv_index;
    1014                 :          0 :         desc->crc24b_ind = check_bit(op->ldpc_dec.op_flags,
    1015                 :            :                         RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK);
    1016                 :          0 :         desc->drop_crc24b = check_bit(op->ldpc_dec.op_flags,
    1017                 :            :                         RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP);
    1018                 :          0 :         desc->desc_idx = desc_offset;
    1019                 :          0 :         desc->ncb = op->ldpc_dec.n_cb;
    1020                 :          0 :         desc->num_null = op->ldpc_dec.n_filler;
    1021                 :          0 :         desc->hbstroe_offset = harq_offset >> 10;
    1022                 :          0 :         desc->zc = op->ldpc_dec.z_c;
    1023                 :          0 :         desc->harqin_en = check_bit(op->ldpc_dec.op_flags,
    1024                 :            :                         RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE);
    1025                 :          0 :         desc->bg_idx = op->ldpc_dec.basegraph - 1;
    1026                 :          0 :         desc->max_iter = op->ldpc_dec.iter_max;
    1027                 :          0 :         desc->qm_idx = op->ldpc_dec.q_m / 2;
    1028                 :          0 :         desc->out_addr_hi = (uint32_t)(
    1029                 :          0 :                         rte_pktmbuf_iova_offset(output, out_offset) >> 32);
    1030                 :          0 :         desc->out_addr_lw = (uint32_t)(
    1031                 :          0 :                         rte_pktmbuf_iova_offset(output, out_offset));
    1032                 :            :         /* Save software context needed for dequeue */
    1033                 :          0 :         desc->op_addr = op;
    1034                 :            :         /* Set total number of CBs in an op */
    1035                 :          0 :         desc->cbs_in_op = cbs_in_op;
    1036                 :            : 
    1037                 :          0 :         return 0;
    1038                 :            : }
    1039                 :            : 
    1040                 :            : /* Validates LDPC encoder parameters */
    1041                 :            : static inline int
    1042                 :          0 : validate_ldpc_enc_op(struct rte_bbdev_enc_op *op)
    1043                 :            : {
    1044                 :            :         struct rte_bbdev_op_ldpc_enc *ldpc_enc = &op->ldpc_enc;
    1045                 :            : 
    1046         [ #  # ]:          0 :         if (op->mempool == NULL) {
    1047                 :          0 :                 rte_bbdev_log(ERR, "Invalid mempool pointer");
    1048                 :          0 :                 return -1;
    1049                 :            :         }
    1050         [ #  # ]:          0 :         if (ldpc_enc->input.data == NULL) {
    1051                 :          0 :                 rte_bbdev_log(ERR, "Invalid input pointer");
    1052                 :          0 :                 return -1;
    1053                 :            :         }
    1054         [ #  # ]:          0 :         if (ldpc_enc->output.data == NULL) {
    1055                 :          0 :                 rte_bbdev_log(ERR, "Invalid output pointer");
    1056                 :          0 :                 return -1;
    1057                 :            :         }
    1058         [ #  # ]:          0 :         if (ldpc_enc->input.length == 0) {
    1059                 :          0 :                 rte_bbdev_log(ERR, "CB size (%u) is null",
    1060                 :            :                                 ldpc_enc->input.length);
    1061                 :          0 :                 return -1;
    1062                 :            :         }
    1063         [ #  # ]:          0 :         if ((ldpc_enc->basegraph > 2) || (ldpc_enc->basegraph == 0)) {
    1064                 :          0 :                 rte_bbdev_log(ERR,
    1065                 :            :                                 "BG (%u) is out of range 1 <= value <= 2",
    1066                 :            :                                 ldpc_enc->basegraph);
    1067                 :          0 :                 return -1;
    1068                 :            :         }
    1069         [ #  # ]:          0 :         if (ldpc_enc->rv_index > 3) {
    1070                 :          0 :                 rte_bbdev_log(ERR,
    1071                 :            :                                 "rv_index (%u) is out of range 0 <= value <= 3",
    1072                 :            :                                 ldpc_enc->rv_index);
    1073                 :          0 :                 return -1;
    1074                 :            :         }
    1075         [ #  # ]:          0 :         if (ldpc_enc->code_block_mode > RTE_BBDEV_CODE_BLOCK) {
    1076                 :          0 :                 rte_bbdev_log(ERR,
    1077                 :            :                                 "code_block_mode (%u) is out of range 0 <= value <= 1",
    1078                 :            :                                 ldpc_enc->code_block_mode);
    1079                 :          0 :                 return -1;
    1080                 :            :         }
    1081                 :            : 
    1082         [ #  # ]:          0 :         if (ldpc_enc->input.length >
    1083                 :            :                 RTE_BBDEV_LDPC_MAX_CB_SIZE >> 3) {
    1084                 :          0 :                 rte_bbdev_log(ERR, "CB size (%u) is too big, max: %d",
    1085                 :            :                                 ldpc_enc->input.length,
    1086                 :            :                                 RTE_BBDEV_LDPC_MAX_CB_SIZE);
    1087                 :          0 :                 return -1;
    1088                 :            :         }
    1089                 :          0 :         int z_c = ldpc_enc->z_c;
    1090                 :            :         /* Check Zc is valid value */
    1091         [ #  # ]:          0 :         if ((z_c > 384) || (z_c < 4)) {
    1092                 :          0 :                 rte_bbdev_log(ERR, "Zc (%u) is out of range", z_c);
    1093                 :          0 :                 return -1;
    1094                 :            :         }
    1095         [ #  # ]:          0 :         if (z_c > 256) {
    1096         [ #  # ]:          0 :                 if ((z_c % 32) != 0) {
    1097                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1098                 :          0 :                         return -1;
    1099                 :            :                 }
    1100         [ #  # ]:          0 :         } else if (z_c > 128) {
    1101         [ #  # ]:          0 :                 if ((z_c % 16) != 0) {
    1102                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1103                 :          0 :                         return -1;
    1104                 :            :                 }
    1105         [ #  # ]:          0 :         } else if (z_c > 64) {
    1106         [ #  # ]:          0 :                 if ((z_c % 8) != 0) {
    1107                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1108                 :          0 :                         return -1;
    1109                 :            :                 }
    1110         [ #  # ]:          0 :         } else if (z_c > 32) {
    1111         [ #  # ]:          0 :                 if ((z_c % 4) != 0) {
    1112                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1113                 :          0 :                         return -1;
    1114                 :            :                 }
    1115         [ #  # ]:          0 :         } else if (z_c > 16) {
    1116         [ #  # ]:          0 :                 if ((z_c % 2) != 0) {
    1117                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1118                 :          0 :                         return -1;
    1119                 :            :                 }
    1120                 :            :         }
    1121                 :            : 
    1122                 :          0 :         int n_filler = ldpc_enc->n_filler;
    1123         [ #  # ]:          0 :         int K = (ldpc_enc->basegraph == 1 ? 22 : 10) * ldpc_enc->z_c;
    1124                 :          0 :         int Kp = K - n_filler;
    1125                 :          0 :         int q_m = ldpc_enc->q_m;
    1126                 :          0 :         int n_cb = ldpc_enc->n_cb;
    1127         [ #  # ]:          0 :         int N = (ldpc_enc->basegraph == 1 ? N_ZC_1 : N_ZC_2) * z_c;
    1128                 :          0 :         int k0 = get_k0(n_cb, z_c, ldpc_enc->basegraph,
    1129                 :            :                         ldpc_enc->rv_index);
    1130                 :            :         int crc24 = 0;
    1131                 :            :         int32_t L, Lcb, cw, cw_rm;
    1132                 :          0 :         int32_t e = ldpc_enc->cb_params.e;
    1133         [ #  # ]:          0 :         if (check_bit(op->ldpc_enc.op_flags,
    1134                 :            :                         RTE_BBDEV_LDPC_CRC_24B_ATTACH))
    1135                 :            :                 crc24 = 24;
    1136                 :            : 
    1137         [ #  # ]:          0 :         if (K < (int) (ldpc_enc->input.length * 8 + n_filler) + crc24) {
    1138                 :          0 :                 rte_bbdev_log(ERR, "K and F not matching input size %u %u %u",
    1139                 :            :                                 K, n_filler, ldpc_enc->input.length);
    1140                 :          0 :                 return -1;
    1141                 :            :         }
    1142         [ #  # ]:          0 :         if (ldpc_enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
    1143                 :          0 :                 rte_bbdev_log(ERR, "TB mode not supported");
    1144                 :          0 :                 return -1;
    1145                 :            : 
    1146                 :            :         }
    1147                 :            : 
    1148                 :            :         /* K' range check */
    1149         [ #  # ]:          0 :         if (Kp % 8 > 0) {
    1150                 :          0 :                 rte_bbdev_log(ERR, "K' not byte aligned %u", Kp);
    1151                 :          0 :                 return -1;
    1152                 :            :         }
    1153         [ #  # ]:          0 :         if ((crc24 > 0) && (Kp < 292)) {
    1154                 :          0 :                 rte_bbdev_log(ERR, "Invalid CRC24 for small block %u", Kp);
    1155                 :          0 :                 return -1;
    1156                 :            :         }
    1157         [ #  # ]:          0 :         if (Kp < 24) {
    1158                 :          0 :                 rte_bbdev_log(ERR, "K' too small %u", Kp);
    1159                 :          0 :                 return -1;
    1160                 :            :         }
    1161         [ #  # ]:          0 :         if (n_filler >= (K - 2 * z_c)) {
    1162                 :          0 :                 rte_bbdev_log(ERR, "K - F invalid %u %u", K, n_filler);
    1163                 :          0 :                 return -1;
    1164                 :            :         }
    1165                 :            :         /* Ncb range check */
    1166   [ #  #  #  # ]:          0 :         if ((n_cb > N) || (n_cb < 32) || (n_cb <= (Kp - crc24))) {
    1167                 :          0 :                 rte_bbdev_log(ERR, "Ncb (%u) is out of range K  %d N %d", n_cb, K, N);
    1168                 :          0 :                 return -1;
    1169                 :            :         }
    1170                 :            :         /* Qm range check */
    1171   [ #  #  #  # ]:          0 :         if (!check_bit(op->ldpc_enc.op_flags, RTE_BBDEV_LDPC_INTERLEAVER_BYPASS) &&
    1172   [ #  #  #  #  :          0 :                         ((q_m == 0) || ((q_m > 2) && ((q_m % 2) == 1)) || (q_m > 8))) {
                   #  # ]
    1173                 :          0 :                 rte_bbdev_log(ERR, "Qm (%u) is out of range", q_m);
    1174                 :          0 :                 return -1;
    1175                 :            :         }
    1176                 :            :         /* K0 range check */
    1177   [ #  #  #  #  :          0 :         if (((k0 % z_c) > 0) || (k0 >= n_cb) || ((k0 >= (Kp - 2 * z_c))
                   #  # ]
    1178         [ #  # ]:          0 :                         && (k0 < (K - 2 * z_c)))) {
    1179                 :          0 :                 rte_bbdev_log(ERR, "K0 (%u) is out of range", k0);
    1180                 :          0 :                 return -1;
    1181                 :            :         }
    1182                 :            :         /* E range check */
    1183         [ #  # ]:          0 :         if (e <= RTE_MAX(32, z_c)) {
    1184                 :          0 :                 rte_bbdev_log(ERR, "E is too small %"PRIu32"", e);
    1185                 :          0 :                 return -1;
    1186                 :            :         }
    1187         [ #  # ]:          0 :         if ((e > 0xFFFF)) {
    1188                 :          0 :                 rte_bbdev_log(ERR, "E is too large for N3000 %"PRIu32" > 64k", e);
    1189                 :          0 :                 return -1;
    1190                 :            :         }
    1191         [ #  # ]:          0 :         if (q_m > 0) {
    1192         [ #  # ]:          0 :                 if (e % q_m > 0) {
    1193                 :          0 :                         rte_bbdev_log(ERR, "E %"PRIu32" not multiple of qm %d", e, q_m);
    1194                 :          0 :                         return -1;
    1195                 :            :                 }
    1196                 :            :         }
    1197                 :            :         /* Code word in RM range check */
    1198         [ #  # ]:          0 :         if (k0 > (Kp - 2 * z_c))
    1199                 :          0 :                 L = k0 + e;
    1200                 :            :         else
    1201                 :          0 :                 L = k0 + e + n_filler;
    1202                 :          0 :         Lcb = RTE_MIN(L, n_cb);
    1203         [ #  # ]:          0 :         if (ldpc_enc->basegraph == 1) {
    1204         [ #  # ]:          0 :                 if (Lcb <= 25 * z_c)
    1205                 :            :                         cw = 25 * z_c;
    1206         [ #  # ]:          0 :                 else if (Lcb <= 27 * z_c)
    1207                 :            :                         cw = 27 * z_c;
    1208         [ #  # ]:          0 :                 else if (Lcb <= 30 * z_c)
    1209                 :            :                         cw = 30 * z_c;
    1210         [ #  # ]:          0 :                 else if (Lcb <= 33 * z_c)
    1211                 :            :                         cw = 33 * z_c;
    1212         [ #  # ]:          0 :                 else if (Lcb <= 44 * z_c)
    1213                 :            :                         cw = 44 * z_c;
    1214         [ #  # ]:          0 :                 else if (Lcb <= 55 * z_c)
    1215                 :            :                         cw = 55 * z_c;
    1216                 :            :                 else
    1217                 :          0 :                         cw = 66 * z_c;
    1218                 :            :         } else {
    1219         [ #  # ]:          0 :                 if (Lcb <= 15 * z_c)
    1220                 :            :                         cw = 15 * z_c;
    1221         [ #  # ]:          0 :                 else if (Lcb <= 20 * z_c)
    1222                 :            :                         cw = 20 * z_c;
    1223         [ #  # ]:          0 :                 else if (Lcb <= 25 * z_c)
    1224                 :            :                         cw = 25 * z_c;
    1225         [ #  # ]:          0 :                 else if (Lcb <= 30 * z_c)
    1226                 :            :                         cw = 30 * z_c;
    1227                 :            :                 else
    1228                 :          0 :                         cw = 50 * z_c;
    1229                 :            :         }
    1230         [ #  # ]:          0 :         if (n_cb < Kp - 2 * z_c)
    1231                 :            :                 cw_rm = n_cb;
    1232         [ #  # ]:          0 :         else if ((Kp - 2 * z_c <= n_cb) && (n_cb < K - 2 * z_c))
    1233                 :            :                 cw_rm = Kp - 2 * z_c;
    1234   [ #  #  #  # ]:          0 :         else if ((K - 2 * z_c <= n_cb) && (n_cb < cw))
    1235                 :          0 :                 cw_rm = n_cb - n_filler;
    1236                 :            :         else
    1237                 :          0 :                 cw_rm = cw - n_filler;
    1238         [ #  # ]:          0 :         if (cw_rm <= 32) {
    1239                 :          0 :                 rte_bbdev_log(ERR,
    1240                 :            :                                 "Invalid Ratematching");
    1241                 :          0 :                 return -1;
    1242                 :            :         }
    1243                 :            :         return 0;
    1244                 :            : }
    1245                 :            : 
    1246                 :            : /* Validates LDPC decoder parameters */
    1247                 :            : static inline int
    1248                 :          0 : validate_ldpc_dec_op(struct rte_bbdev_dec_op *op)
    1249                 :            : {
    1250                 :            :         struct rte_bbdev_op_ldpc_dec *ldpc_dec = &op->ldpc_dec;
    1251         [ #  # ]:          0 :         if (check_bit(ldpc_dec->op_flags,
    1252                 :            :                         RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK))
    1253                 :            :                 return 0;
    1254         [ #  # ]:          0 :         if (ldpc_dec->input.data == NULL) {
    1255                 :          0 :                 rte_bbdev_log(ERR, "Invalid input pointer");
    1256                 :          0 :                 return -1;
    1257                 :            :         }
    1258         [ #  # ]:          0 :         if (ldpc_dec->hard_output.data == NULL) {
    1259                 :          0 :                 rte_bbdev_log(ERR, "Invalid output pointer");
    1260                 :          0 :                 return -1;
    1261                 :            :         }
    1262         [ #  # ]:          0 :         if (ldpc_dec->input.length == 0) {
    1263                 :          0 :                 rte_bbdev_log(ERR, "input is null");
    1264                 :          0 :                 return -1;
    1265                 :            :         }
    1266         [ #  # ]:          0 :         if ((ldpc_dec->basegraph > 2) || (ldpc_dec->basegraph == 0)) {
    1267                 :          0 :                 rte_bbdev_log(ERR,
    1268                 :            :                                 "BG (%u) is out of range 1 <= value <= 2",
    1269                 :            :                                 ldpc_dec->basegraph);
    1270                 :          0 :                 return -1;
    1271                 :            :         }
    1272         [ #  # ]:          0 :         if (ldpc_dec->iter_max == 0) {
    1273                 :          0 :                 rte_bbdev_log(ERR,
    1274                 :            :                                 "iter_max (%u) is equal to 0",
    1275                 :            :                                 ldpc_dec->iter_max);
    1276                 :          0 :                 return -1;
    1277                 :            :         }
    1278         [ #  # ]:          0 :         if (ldpc_dec->rv_index > 3) {
    1279                 :          0 :                 rte_bbdev_log(ERR,
    1280                 :            :                                 "rv_index (%u) is out of range 0 <= value <= 3",
    1281                 :            :                                 ldpc_dec->rv_index);
    1282                 :          0 :                 return -1;
    1283                 :            :         }
    1284         [ #  # ]:          0 :         if (ldpc_dec->code_block_mode > RTE_BBDEV_CODE_BLOCK) {
    1285                 :          0 :                 rte_bbdev_log(ERR,
    1286                 :            :                                 "code_block_mode (%u) is out of range 0 <= value <= 1",
    1287                 :            :                                 ldpc_dec->code_block_mode);
    1288                 :          0 :                 return -1;
    1289                 :            :         }
    1290         [ #  # ]:          0 :         if (check_bit(op->ldpc_dec.op_flags,
    1291                 :            :                         RTE_BBDEV_LDPC_DECODE_BYPASS)) {
    1292                 :          0 :                 rte_bbdev_log(ERR, "Avoid LDPC Decode bypass");
    1293                 :          0 :                 return -1;
    1294                 :            :         }
    1295                 :          0 :         int z_c = ldpc_dec->z_c;
    1296                 :            :         /* Check Zc is valid value */
    1297         [ #  # ]:          0 :         if ((z_c > 384) || (z_c < 4)) {
    1298                 :          0 :                 rte_bbdev_log(ERR,
    1299                 :            :                                 "Zc (%u) is out of range",
    1300                 :            :                                 z_c);
    1301                 :          0 :                 return -1;
    1302                 :            :         }
    1303         [ #  # ]:          0 :         if (z_c > 256) {
    1304         [ #  # ]:          0 :                 if ((z_c % 32) != 0) {
    1305                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1306                 :          0 :                         return -1;
    1307                 :            :                 }
    1308         [ #  # ]:          0 :         } else if (z_c > 128) {
    1309         [ #  # ]:          0 :                 if ((z_c % 16) != 0) {
    1310                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1311                 :          0 :                         return -1;
    1312                 :            :                 }
    1313         [ #  # ]:          0 :         } else if (z_c > 64) {
    1314         [ #  # ]:          0 :                 if ((z_c % 8) != 0) {
    1315                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1316                 :          0 :                         return -1;
    1317                 :            :                 }
    1318         [ #  # ]:          0 :         } else if (z_c > 32) {
    1319         [ #  # ]:          0 :                 if ((z_c % 4) != 0) {
    1320                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1321                 :          0 :                         return -1;
    1322                 :            :                 }
    1323         [ #  # ]:          0 :         } else if (z_c > 16) {
    1324         [ #  # ]:          0 :                 if ((z_c % 2) != 0) {
    1325                 :          0 :                         rte_bbdev_log(ERR, "Invalid Zc %d", z_c);
    1326                 :          0 :                         return -1;
    1327                 :            :                 }
    1328                 :            :         }
    1329                 :            : 
    1330                 :          0 :         int n_filler = ldpc_dec->n_filler;
    1331         [ #  # ]:          0 :         int K = (ldpc_dec->basegraph == 1 ? 22 : 10) * ldpc_dec->z_c;
    1332                 :          0 :         int Kp = K - n_filler;
    1333                 :          0 :         int q_m = ldpc_dec->q_m;
    1334                 :          0 :         int n_cb = ldpc_dec->n_cb;
    1335         [ #  # ]:          0 :         int N = (ldpc_dec->basegraph == 1 ? N_ZC_1 : N_ZC_2) * z_c;
    1336                 :          0 :         int k0 = get_k0(n_cb, z_c, ldpc_dec->basegraph,
    1337                 :            :                         ldpc_dec->rv_index);
    1338                 :            :         int crc24 = 0;
    1339                 :            :         int32_t L, Lcb, cw, cw_rm;
    1340                 :          0 :         int32_t e = ldpc_dec->cb_params.e;
    1341         [ #  # ]:          0 :         if (check_bit(op->ldpc_dec.op_flags,
    1342                 :            :                         RTE_BBDEV_LDPC_CRC_TYPE_24B_CHECK))
    1343                 :            :                 crc24 = 24;
    1344                 :            : 
    1345         [ #  # ]:          0 :         if (ldpc_dec->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
    1346                 :          0 :                 rte_bbdev_log(ERR,
    1347                 :            :                                 "TB mode not supported");
    1348                 :          0 :                 return -1;
    1349                 :            :         }
    1350                 :            :         /* Enforce HARQ input length */
    1351                 :          0 :         ldpc_dec->harq_combined_input.length = RTE_MIN((uint32_t) n_cb,
    1352                 :            :                         ldpc_dec->harq_combined_input.length);
    1353   [ #  #  #  # ]:          0 :         if ((ldpc_dec->harq_combined_input.length == 0) &&
    1354                 :            :                         check_bit(ldpc_dec->op_flags,
    1355                 :            :                         RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
    1356                 :          0 :                 rte_bbdev_log(ERR,
    1357                 :            :                                 "HARQ input length (%u) should not be null",
    1358                 :            :                                 ldpc_dec->harq_combined_input.length);
    1359                 :          0 :                 return -1;
    1360                 :            :         }
    1361   [ #  #  #  # ]:          0 :         if ((ldpc_dec->harq_combined_input.length > 0) &&
    1362                 :            :                         !check_bit(ldpc_dec->op_flags,
    1363                 :            :                         RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
    1364                 :          0 :                 ldpc_dec->harq_combined_input.length = 0;
    1365                 :            :         }
    1366                 :            : 
    1367                 :            :         /* K' range check */
    1368         [ #  # ]:          0 :         if (Kp % 8 > 0) {
    1369                 :          0 :                 rte_bbdev_log(ERR,
    1370                 :            :                                 "K' not byte aligned %u",
    1371                 :            :                                 Kp);
    1372                 :          0 :                 return -1;
    1373                 :            :         }
    1374         [ #  # ]:          0 :         if ((crc24 > 0) && (Kp < 292)) {
    1375                 :          0 :                 rte_bbdev_log(ERR,
    1376                 :            :                                 "Invalid CRC24 for small block %u",
    1377                 :            :                                 Kp);
    1378                 :          0 :                 return -1;
    1379                 :            :         }
    1380         [ #  # ]:          0 :         if (Kp < 24) {
    1381                 :          0 :                 rte_bbdev_log(ERR,
    1382                 :            :                                 "K' too small %u",
    1383                 :            :                                 Kp);
    1384                 :          0 :                 return -1;
    1385                 :            :         }
    1386         [ #  # ]:          0 :         if (n_filler >= (K - 2 * z_c)) {
    1387                 :          0 :                 rte_bbdev_log(ERR,
    1388                 :            :                                 "K - F invalid %u %u",
    1389                 :            :                                 K, n_filler);
    1390                 :          0 :                 return -1;
    1391                 :            :         }
    1392                 :            :         /* Ncb range check */
    1393         [ #  # ]:          0 :         if (n_cb != N) {
    1394                 :          0 :                 rte_bbdev_log(ERR,
    1395                 :            :                                 "Ncb (%u) is out of range K  %d N %d",
    1396                 :            :                                 n_cb, K, N);
    1397                 :          0 :                 return -1;
    1398                 :            :         }
    1399                 :            :         /* Qm range check */
    1400         [ #  # ]:          0 :         if (!check_bit(op->ldpc_dec.op_flags,
    1401         [ #  # ]:          0 :                         RTE_BBDEV_LDPC_INTERLEAVER_BYPASS) &&
    1402   [ #  #  #  # ]:          0 :                         ((q_m == 0) || ((q_m > 2) && ((q_m % 2) == 1))
    1403         [ #  # ]:          0 :                         || (q_m > 8))) {
    1404                 :          0 :                 rte_bbdev_log(ERR,
    1405                 :            :                                 "Qm (%u) is out of range",
    1406                 :            :                                 q_m);
    1407                 :          0 :                 return -1;
    1408                 :            :         }
    1409                 :            :         /* K0 range check */
    1410   [ #  #  #  #  :          0 :         if (((k0 % z_c) > 0) || (k0 >= n_cb) || ((k0 >= (Kp - 2 * z_c))
                   #  # ]
    1411         [ #  # ]:          0 :                         && (k0 < (K - 2 * z_c)))) {
    1412                 :          0 :                 rte_bbdev_log(ERR,
    1413                 :            :                                 "K0 (%u) is out of range",
    1414                 :            :                                 k0);
    1415                 :          0 :                 return -1;
    1416                 :            :         }
    1417                 :            :         /* E range check */
    1418         [ #  # ]:          0 :         if (e <= RTE_MAX(32, z_c)) {
    1419                 :          0 :                 rte_bbdev_log(ERR,
    1420                 :            :                                 "E is too small");
    1421                 :          0 :                 return -1;
    1422                 :            :         }
    1423         [ #  # ]:          0 :         if ((e > 0xFFFF)) {
    1424                 :          0 :                 rte_bbdev_log(ERR,
    1425                 :            :                                 "E is too large");
    1426                 :          0 :                 return -1;
    1427                 :            :         }
    1428         [ #  # ]:          0 :         if (q_m > 0) {
    1429         [ #  # ]:          0 :                 if (e % q_m > 0) {
    1430                 :          0 :                         rte_bbdev_log(ERR,
    1431                 :            :                                         "E not multiple of qm %d", q_m);
    1432                 :          0 :                         return -1;
    1433                 :            :                 }
    1434                 :            :         }
    1435                 :            :         /* Code word in RM range check */
    1436         [ #  # ]:          0 :         if (k0 > (Kp - 2 * z_c))
    1437                 :          0 :                 L = k0 + e;
    1438                 :            :         else
    1439                 :          0 :                 L = k0 + e + n_filler;
    1440                 :          0 :         Lcb = RTE_MIN(n_cb, RTE_MAX(L,
    1441                 :            :                         (int32_t) ldpc_dec->harq_combined_input.length));
    1442         [ #  # ]:          0 :         if (ldpc_dec->basegraph == 1) {
    1443         [ #  # ]:          0 :                 if (Lcb <= 25 * z_c)
    1444                 :            :                         cw = 25 * z_c;
    1445         [ #  # ]:          0 :                 else if (Lcb <= 27 * z_c)
    1446                 :            :                         cw = 27 * z_c;
    1447         [ #  # ]:          0 :                 else if (Lcb <= 30 * z_c)
    1448                 :            :                         cw = 30 * z_c;
    1449         [ #  # ]:          0 :                 else if (Lcb <= 33 * z_c)
    1450                 :            :                         cw = 33 * z_c;
    1451         [ #  # ]:          0 :                 else if (Lcb <= 44 * z_c)
    1452                 :            :                         cw = 44 * z_c;
    1453         [ #  # ]:          0 :                 else if (Lcb <= 55 * z_c)
    1454                 :            :                         cw = 55 * z_c;
    1455                 :            :                 else
    1456                 :          0 :                         cw = 66 * z_c;
    1457                 :            :         } else {
    1458         [ #  # ]:          0 :                 if (Lcb <= 15 * z_c)
    1459                 :            :                         cw = 15 * z_c;
    1460         [ #  # ]:          0 :                 else if (Lcb <= 20 * z_c)
    1461                 :            :                         cw = 20 * z_c;
    1462         [ #  # ]:          0 :                 else if (Lcb <= 25 * z_c)
    1463                 :            :                         cw = 25 * z_c;
    1464         [ #  # ]:          0 :                 else if (Lcb <= 30 * z_c)
    1465                 :            :                         cw = 30 * z_c;
    1466                 :            :                 else
    1467                 :          0 :                         cw = 50 * z_c;
    1468                 :            :         }
    1469                 :          0 :         cw_rm = cw - n_filler;
    1470         [ #  # ]:          0 :         if (cw_rm <= 32) {
    1471                 :          0 :                 rte_bbdev_log(ERR,
    1472                 :            :                                 "Invalid Ratematching");
    1473                 :          0 :                 return -1;
    1474                 :            :         }
    1475                 :            :         return 0;
    1476                 :            : }
    1477                 :            : 
    1478                 :            : static inline char *
    1479                 :            : mbuf_append(struct rte_mbuf *m_head, struct rte_mbuf *m, uint16_t len)
    1480                 :            : {
    1481   [ #  #  #  #  :          0 :         if (unlikely(len > rte_pktmbuf_tailroom(m)))
             #  #  #  # ]
    1482                 :            :                 return NULL;
    1483                 :            : 
    1484                 :          0 :         char *tail = (char *)m->buf_addr + m->data_off + m->data_len;
    1485                 :          0 :         m->data_len = (uint16_t)(m->data_len + len);
    1486                 :          0 :         m_head->pkt_len  = (m_head->pkt_len + len);
    1487                 :          0 :         return tail;
    1488                 :            : }
    1489                 :            : 
    1490                 :            : static inline void
    1491                 :          0 : fpga_mutex_acquisition(struct fpga_queue *q)
    1492                 :            : {
    1493                 :            :         uint32_t mutex_ctrl, mutex_read, cnt = 0;
    1494                 :            :         /* Assign a unique id for the duration of the DDR access */
    1495                 :          0 :         q->ddr_mutex_uuid = rand();
    1496                 :            :         /* Request and wait for acquisition of the mutex */
    1497                 :          0 :         mutex_ctrl = (q->ddr_mutex_uuid << 16) + 1;
    1498                 :            :         do {
    1499         [ #  # ]:          0 :                 if (cnt > 0)
    1500                 :          0 :                         usleep(FPGA_TIMEOUT_CHECK_INTERVAL);
    1501                 :            :                 rte_bbdev_log_debug("Acquiring Mutex for %x\n",
    1502                 :            :                                 q->ddr_mutex_uuid);
    1503         [ #  # ]:          0 :                 fpga_reg_write_32(q->d->mmio_base,
    1504                 :            :                                 FPGA_5GNR_FEC_MUTEX,
    1505                 :            :                                 mutex_ctrl);
    1506                 :            :                 mutex_read = fpga_reg_read_32(q->d->mmio_base,
    1507                 :            :                                 FPGA_5GNR_FEC_MUTEX);
    1508                 :            :                 rte_bbdev_log_debug("Mutex %x cnt %d owner %x\n",
    1509                 :            :                                 mutex_read, cnt, q->ddr_mutex_uuid);
    1510                 :          0 :                 cnt++;
    1511         [ #  # ]:          0 :         } while ((mutex_read >> 16) != q->ddr_mutex_uuid);
    1512                 :          0 : }
    1513                 :            : 
    1514                 :            : static inline void
    1515                 :            : fpga_mutex_free(struct fpga_queue *q)
    1516                 :            : {
    1517                 :          0 :         uint32_t mutex_ctrl = q->ddr_mutex_uuid << 16;
    1518                 :          0 :         fpga_reg_write_32(q->d->mmio_base,
    1519                 :            :                         FPGA_5GNR_FEC_MUTEX,
    1520                 :            :                         mutex_ctrl);
    1521                 :            : }
    1522                 :            : 
    1523                 :            : static inline int
    1524                 :          0 : fpga_harq_write_loopback(struct fpga_queue *q,
    1525                 :            :                 struct rte_mbuf *harq_input, uint16_t harq_in_length,
    1526                 :            :                 uint32_t harq_in_offset, uint32_t harq_out_offset)
    1527                 :            : {
    1528                 :          0 :         fpga_mutex_acquisition(q);
    1529                 :            :         uint32_t out_offset = harq_out_offset;
    1530                 :            :         uint32_t in_offset = harq_in_offset;
    1531                 :          0 :         uint32_t left_length = harq_in_length;
    1532                 :            :         uint32_t reg_32, increment = 0;
    1533                 :            :         uint64_t *input = NULL;
    1534                 :          0 :         uint32_t last_transaction = left_length
    1535                 :            :                         % FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
    1536                 :            :         uint64_t last_word;
    1537                 :            : 
    1538         [ #  # ]:          0 :         if (last_transaction > 0)
    1539                 :          0 :                 left_length -= last_transaction;
    1540                 :            : 
    1541                 :            :         /*
    1542                 :            :          * Get HARQ buffer size for each VF/PF: When 0x00, there is no
    1543                 :            :          * available DDR space for the corresponding VF/PF.
    1544                 :            :          */
    1545         [ #  # ]:          0 :         reg_32 = fpga_reg_read_32(q->d->mmio_base,
    1546                 :            :                         FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
    1547         [ #  # ]:          0 :         if (reg_32 < harq_in_length) {
    1548                 :            :                 left_length = reg_32;
    1549                 :          0 :                 rte_bbdev_log(ERR, "HARQ in length > HARQ buffer size\n");
    1550                 :            :         }
    1551                 :            : 
    1552                 :          0 :         input = (uint64_t *)rte_pktmbuf_mtod_offset(harq_input,
    1553                 :            :                         uint8_t *, in_offset);
    1554                 :            : 
    1555         [ #  # ]:          0 :         while (left_length > 0) {
    1556         [ #  # ]:          0 :                 if (fpga_reg_read_8(q->d->mmio_base,
    1557                 :            :                                 FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS) ==  1) {
    1558                 :            :                         fpga_reg_write_32(q->d->mmio_base,
    1559                 :            :                                         FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS,
    1560                 :            :                                         out_offset);
    1561                 :          0 :                         fpga_reg_write_64(q->d->mmio_base,
    1562                 :            :                                         FPGA_5GNR_FEC_DDR4_WR_DATA_REGS,
    1563                 :          0 :                                         input[increment]);
    1564                 :          0 :                         left_length -= FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
    1565                 :          0 :                         out_offset += FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
    1566                 :          0 :                         increment++;
    1567                 :            :                         fpga_reg_write_8(q->d->mmio_base,
    1568                 :            :                                         FPGA_5GNR_FEC_DDR4_WR_DONE_REGS, 1);
    1569                 :            :                 }
    1570                 :            :         }
    1571         [ #  # ]:          0 :         while (last_transaction > 0) {
    1572         [ #  # ]:          0 :                 if (fpga_reg_read_8(q->d->mmio_base,
    1573                 :            :                                 FPGA_5GNR_FEC_DDR4_ADDR_RDY_REGS) ==  1) {
    1574                 :            :                         fpga_reg_write_32(q->d->mmio_base,
    1575                 :            :                                         FPGA_5GNR_FEC_DDR4_WR_ADDR_REGS,
    1576                 :            :                                         out_offset);
    1577                 :          0 :                         last_word = input[increment];
    1578                 :          0 :                         last_word &= (uint64_t)(1 << (last_transaction * 4))
    1579                 :          0 :                                         - 1;
    1580                 :            :                         fpga_reg_write_64(q->d->mmio_base,
    1581                 :            :                                         FPGA_5GNR_FEC_DDR4_WR_DATA_REGS,
    1582                 :            :                                         last_word);
    1583                 :            :                         fpga_reg_write_8(q->d->mmio_base,
    1584                 :            :                                         FPGA_5GNR_FEC_DDR4_WR_DONE_REGS, 1);
    1585                 :            :                         last_transaction = 0;
    1586                 :            :                 }
    1587                 :            :         }
    1588                 :            :         fpga_mutex_free(q);
    1589                 :          0 :         return 1;
    1590                 :            : }
    1591                 :            : 
    1592                 :            : static inline int
    1593                 :          0 : fpga_harq_read_loopback(struct fpga_queue *q,
    1594                 :            :                 struct rte_mbuf *harq_output, uint16_t harq_in_length,
    1595                 :            :                 uint32_t harq_in_offset, uint32_t harq_out_offset)
    1596                 :            : {
    1597                 :          0 :         fpga_mutex_acquisition(q);
    1598                 :            :         uint32_t left_length, in_offset = harq_in_offset;
    1599                 :            :         uint64_t reg;
    1600                 :            :         uint32_t increment = 0;
    1601                 :            :         uint64_t *input = NULL;
    1602                 :          0 :         uint32_t last_transaction = harq_in_length
    1603                 :            :                         % FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
    1604                 :            : 
    1605         [ #  # ]:          0 :         if (last_transaction > 0)
    1606                 :          0 :                 harq_in_length += (8 - last_transaction);
    1607                 :            : 
    1608         [ #  # ]:          0 :         reg = fpga_reg_read_32(q->d->mmio_base,
    1609                 :            :                         FPGA_5GNR_FEC_HARQ_BUF_SIZE_REGS);
    1610         [ #  # ]:          0 :         if (reg < harq_in_length) {
    1611                 :          0 :                 harq_in_length = reg;
    1612                 :          0 :                 rte_bbdev_log(ERR, "HARQ in length > HARQ buffer size\n");
    1613                 :            :         }
    1614                 :            : 
    1615   [ #  #  #  # ]:          0 :         if (!mbuf_append(harq_output, harq_output, harq_in_length)) {
    1616                 :          0 :                 rte_bbdev_log(ERR, "HARQ output buffer warning %d %d\n",
    1617                 :            :                                 harq_output->buf_len -
    1618                 :            :                                 rte_pktmbuf_headroom(harq_output),
    1619                 :            :                                 harq_in_length);
    1620         [ #  # ]:          0 :                 harq_in_length = harq_output->buf_len -
    1621                 :            :                                 rte_pktmbuf_headroom(harq_output);
    1622   [ #  #  #  # ]:          0 :                 if (!mbuf_append(harq_output, harq_output, harq_in_length)) {
    1623                 :          0 :                         rte_bbdev_log(ERR, "HARQ output buffer issue %d %d\n",
    1624                 :            :                                         harq_output->buf_len, harq_in_length);
    1625                 :          0 :                         return -1;
    1626                 :            :                 }
    1627                 :            :         }
    1628                 :          0 :         left_length = harq_in_length;
    1629                 :            : 
    1630                 :          0 :         input = (uint64_t *)rte_pktmbuf_mtod_offset(harq_output,
    1631                 :            :                         uint8_t *, harq_out_offset);
    1632                 :            : 
    1633         [ #  # ]:          0 :         while (left_length > 0) {
    1634                 :          0 :                 fpga_reg_write_32(q->d->mmio_base,
    1635                 :            :                         FPGA_5GNR_FEC_DDR4_RD_ADDR_REGS, in_offset);
    1636                 :            :                 fpga_reg_write_8(q->d->mmio_base,
    1637                 :            :                                 FPGA_5GNR_FEC_DDR4_RD_DONE_REGS, 1);
    1638                 :          0 :                 reg = fpga_reg_read_8(q->d->mmio_base,
    1639                 :            :                         FPGA_5GNR_FEC_DDR4_RD_RDY_REGS);
    1640         [ #  # ]:          0 :                 while (reg != 1) {
    1641                 :          0 :                         reg = fpga_reg_read_8(q->d->mmio_base,
    1642                 :            :                                 FPGA_5GNR_FEC_DDR4_RD_RDY_REGS);
    1643         [ #  # ]:          0 :                         if (reg == FPGA_DDR_OVERFLOW) {
    1644                 :          0 :                                 rte_bbdev_log(ERR,
    1645                 :            :                                                 "Read address is overflow!\n");
    1646                 :          0 :                                 return -1;
    1647                 :            :                         }
    1648                 :            :                 }
    1649                 :          0 :                 input[increment] = fpga_reg_read_64(q->d->mmio_base,
    1650                 :            :                         FPGA_5GNR_FEC_DDR4_RD_DATA_REGS);
    1651                 :          0 :                 left_length -= FPGA_5GNR_FEC_DDR_RD_DATA_LEN_IN_BYTES;
    1652                 :          0 :                 in_offset += FPGA_5GNR_FEC_DDR_WR_DATA_LEN_IN_BYTES;
    1653                 :          0 :                 increment++;
    1654                 :            :                 fpga_reg_write_8(q->d->mmio_base,
    1655                 :            :                                 FPGA_5GNR_FEC_DDR4_RD_DONE_REGS, 0);
    1656                 :            :         }
    1657                 :            :         fpga_mutex_free(q);
    1658                 :          0 :         return 1;
    1659                 :            : }
    1660                 :            : 
    1661                 :            : static inline int
    1662                 :          0 : enqueue_ldpc_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op *op,
    1663                 :            :                 uint16_t desc_offset)
    1664                 :            : {
    1665                 :            :         union fpga_dma_desc *desc;
    1666                 :            :         int ret;
    1667                 :            :         uint8_t c, crc24_bits = 0;
    1668                 :            :         struct rte_bbdev_op_ldpc_enc *enc = &op->ldpc_enc;
    1669                 :          0 :         uint16_t in_offset = enc->input.offset;
    1670                 :          0 :         uint16_t out_offset = enc->output.offset;
    1671                 :          0 :         struct rte_mbuf *m_in = enc->input.data;
    1672                 :          0 :         struct rte_mbuf *m_out = enc->output.data;
    1673                 :            :         struct rte_mbuf *m_out_head = enc->output.data;
    1674                 :            :         uint32_t in_length, out_length, e;
    1675                 :            :         uint16_t total_left = enc->input.length;
    1676                 :            :         uint16_t ring_offset;
    1677                 :            :         uint16_t K, k_;
    1678                 :            : 
    1679                 :            : 
    1680         [ #  # ]:          0 :         if (validate_ldpc_enc_op(op) == -1) {
    1681                 :          0 :                 rte_bbdev_log(ERR, "LDPC encoder validation rejected");
    1682                 :          0 :                 return -EINVAL;
    1683                 :            :         }
    1684                 :            : 
    1685                 :            :         /* Clear op status */
    1686                 :          0 :         op->status = 0;
    1687                 :            : 
    1688         [ #  # ]:          0 :         if (m_in == NULL || m_out == NULL) {
    1689                 :          0 :                 rte_bbdev_log(ERR, "Invalid mbuf pointer");
    1690                 :          0 :                 op->status = 1 << RTE_BBDEV_DATA_ERROR;
    1691                 :          0 :                 return -EINVAL;
    1692                 :            :         }
    1693                 :            : 
    1694         [ #  # ]:          0 :         if (enc->op_flags & RTE_BBDEV_LDPC_CRC_24B_ATTACH)
    1695                 :            :                 crc24_bits = 24;
    1696                 :            : 
    1697         [ #  # ]:          0 :         if (enc->code_block_mode == RTE_BBDEV_TRANSPORT_BLOCK) {
    1698                 :            :                 /* For Transport Block mode */
    1699                 :            :                 /* FIXME */
    1700                 :          0 :                 c = enc->tb_params.c;
    1701                 :          0 :                 e = enc->tb_params.ea;
    1702                 :            :         } else { /* For Code Block mode */
    1703                 :            :                 c = 1;
    1704                 :          0 :                 e = enc->cb_params.e;
    1705                 :            :         }
    1706                 :            : 
    1707                 :            :         /* Update total_left */
    1708         [ #  # ]:          0 :         K = (enc->basegraph == 1 ? 22 : 10) * enc->z_c;
    1709                 :          0 :         k_ = K - enc->n_filler;
    1710                 :          0 :         in_length = (k_ - crc24_bits) >> 3;
    1711                 :          0 :         out_length = (e + 7) >> 3;
    1712                 :            : 
    1713                 :          0 :         total_left = rte_pktmbuf_data_len(m_in) - in_offset;
    1714                 :            : 
    1715                 :            :         /* Update offsets */
    1716         [ #  # ]:          0 :         if (total_left != in_length) {
    1717                 :          0 :                 op->status |= 1 << RTE_BBDEV_DATA_ERROR;
    1718                 :          0 :                 rte_bbdev_log(ERR,
    1719                 :            :                                 "Mismatch between mbuf length and included CBs sizes %d",
    1720                 :            :                                 total_left);
    1721                 :            :         }
    1722                 :            : 
    1723         [ #  # ]:          0 :         mbuf_append(m_out_head, m_out, out_length);
    1724                 :            : 
    1725                 :            :         /* Offset into the ring */
    1726                 :          0 :         ring_offset = ((q->tail + desc_offset) & q->sw_ring_wrap_mask);
    1727                 :            :         /* Setup DMA Descriptor */
    1728                 :          0 :         desc = q->ring_addr + ring_offset;
    1729                 :            : 
    1730                 :          0 :         ret = fpga_dma_desc_te_fill(op, &desc->enc_req, m_in, m_out,
    1731                 :            :                         k_, e, in_offset, out_offset, ring_offset, c);
    1732         [ #  # ]:          0 :         if (unlikely(ret < 0))
    1733                 :            :                 return ret;
    1734                 :            : 
    1735                 :            :         /* Update lengths */
    1736                 :          0 :         total_left -= in_length;
    1737                 :          0 :         op->ldpc_enc.output.length += out_length;
    1738                 :            : 
    1739         [ #  # ]:          0 :         if (total_left > 0) {
    1740                 :          0 :                 rte_bbdev_log(ERR,
    1741                 :            :                         "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
    1742                 :            :                                 total_left, in_length);
    1743                 :          0 :                 return -1;
    1744                 :            :         }
    1745                 :            : 
    1746                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
    1747                 :            :         print_dma_enc_desc_debug_info(desc);
    1748                 :            : #endif
    1749                 :            :         return 1;
    1750                 :            : }
    1751                 :            : 
    1752                 :            : static inline int
    1753                 :          0 : enqueue_ldpc_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op *op,
    1754                 :            :                 uint16_t desc_offset)
    1755                 :            : {
    1756                 :            :         union fpga_dma_desc *desc;
    1757                 :            :         int ret;
    1758                 :            :         uint16_t ring_offset;
    1759                 :            :         uint8_t c;
    1760                 :            :         uint16_t e, in_length, out_length, k0, l, seg_total_left, sys_cols;
    1761                 :            :         uint16_t K, parity_offset, harq_in_length = 0, harq_out_length = 0;
    1762                 :            :         uint16_t crc24_overlap = 0;
    1763                 :            :         struct rte_bbdev_op_ldpc_dec *dec = &op->ldpc_dec;
    1764                 :          0 :         struct rte_mbuf *m_in = dec->input.data;
    1765                 :          0 :         struct rte_mbuf *m_out = dec->hard_output.data;
    1766                 :            :         struct rte_mbuf *m_out_head = dec->hard_output.data;
    1767                 :          0 :         uint16_t in_offset = dec->input.offset;
    1768                 :          0 :         uint16_t out_offset = dec->hard_output.offset;
    1769                 :            :         uint32_t harq_offset = 0;
    1770                 :            : 
    1771         [ #  # ]:          0 :         if (validate_ldpc_dec_op(op) == -1) {
    1772                 :          0 :                 rte_bbdev_log(ERR, "LDPC decoder validation rejected");
    1773                 :          0 :                 return -EINVAL;
    1774                 :            :         }
    1775                 :            : 
    1776                 :            :         /* Clear op status */
    1777                 :          0 :         op->status = 0;
    1778                 :            : 
    1779                 :            :         /* Setup DMA Descriptor */
    1780                 :          0 :         ring_offset = ((q->tail + desc_offset) & q->sw_ring_wrap_mask);
    1781                 :          0 :         desc = q->ring_addr + ring_offset;
    1782                 :            : 
    1783         [ #  # ]:          0 :         if (check_bit(dec->op_flags,
    1784                 :            :                         RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK)) {
    1785                 :          0 :                 struct rte_mbuf *harq_in = dec->harq_combined_input.data;
    1786                 :          0 :                 struct rte_mbuf *harq_out = dec->harq_combined_output.data;
    1787                 :          0 :                 harq_in_length = dec->harq_combined_input.length;
    1788                 :          0 :                 uint32_t harq_in_offset = dec->harq_combined_input.offset;
    1789                 :          0 :                 uint32_t harq_out_offset = dec->harq_combined_output.offset;
    1790                 :            : 
    1791         [ #  # ]:          0 :                 if (check_bit(dec->op_flags,
    1792                 :            :                                 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_OUT_ENABLE
    1793                 :            :                                 )) {
    1794                 :          0 :                         ret = fpga_harq_write_loopback(q, harq_in,
    1795                 :            :                                         harq_in_length, harq_in_offset,
    1796                 :            :                                         harq_out_offset);
    1797         [ #  # ]:          0 :                 } else if (check_bit(dec->op_flags,
    1798                 :            :                                 RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_IN_ENABLE
    1799                 :            :                                 )) {
    1800                 :          0 :                         ret = fpga_harq_read_loopback(q, harq_out,
    1801                 :            :                                 harq_in_length, harq_in_offset,
    1802                 :            :                                 harq_out_offset);
    1803                 :          0 :                         dec->harq_combined_output.length = harq_in_length;
    1804                 :            :                 } else {
    1805                 :          0 :                         rte_bbdev_log(ERR, "OP flag Err!");
    1806                 :            :                         ret = -1;
    1807                 :            :                 }
    1808                 :            :                 /* Set descriptor for dequeue */
    1809                 :          0 :                 desc->dec_req.done = 1;
    1810                 :          0 :                 desc->dec_req.error = 0;
    1811                 :          0 :                 desc->dec_req.op_addr = op;
    1812                 :          0 :                 desc->dec_req.cbs_in_op = 1;
    1813                 :            :                 /* Mark this dummy descriptor to be dropped by HW */
    1814                 :          0 :                 desc->dec_req.desc_idx = (ring_offset + 1)
    1815                 :          0 :                                 & q->sw_ring_wrap_mask;
    1816                 :          0 :                 return ret; /* Error or number of CB */
    1817                 :            :         }
    1818                 :            : 
    1819         [ #  # ]:          0 :         if (m_in == NULL || m_out == NULL) {
    1820                 :          0 :                 rte_bbdev_log(ERR, "Invalid mbuf pointer");
    1821                 :          0 :                 op->status = 1 << RTE_BBDEV_DATA_ERROR;
    1822                 :          0 :                 return -1;
    1823                 :            :         }
    1824                 :            : 
    1825                 :            :         c = 1;
    1826                 :          0 :         e = dec->cb_params.e;
    1827                 :            : 
    1828         [ #  # ]:          0 :         if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_CRC_TYPE_24B_DROP))
    1829                 :            :                 crc24_overlap = 24;
    1830                 :            : 
    1831         [ #  # ]:          0 :         sys_cols = (dec->basegraph == 1) ? 22 : 10;
    1832                 :          0 :         K = sys_cols * dec->z_c;
    1833                 :          0 :         parity_offset = K - 2 * dec->z_c;
    1834                 :            : 
    1835                 :          0 :         out_length = ((K - crc24_overlap - dec->n_filler) >> 3);
    1836                 :            :         in_length = e;
    1837                 :          0 :         seg_total_left = dec->input.length;
    1838                 :            : 
    1839         [ #  # ]:          0 :         if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE)) {
    1840                 :          0 :                 harq_in_length = RTE_MIN(dec->harq_combined_input.length,
    1841                 :            :                                 (uint32_t)dec->n_cb);
    1842                 :            :         }
    1843                 :            : 
    1844         [ #  # ]:          0 :         if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE)) {
    1845                 :          0 :                 k0 = get_k0(dec->n_cb, dec->z_c,
    1846                 :          0 :                                 dec->basegraph, dec->rv_index);
    1847         [ #  # ]:          0 :                 if (k0 > parity_offset)
    1848                 :          0 :                         l = k0 + e;
    1849                 :            :                 else
    1850                 :          0 :                         l = k0 + e + dec->n_filler;
    1851                 :          0 :                 harq_out_length = RTE_MIN(RTE_MAX(harq_in_length, l),
    1852                 :            :                                 dec->n_cb);
    1853                 :          0 :                 dec->harq_combined_output.length = harq_out_length;
    1854                 :            :         }
    1855                 :            : 
    1856                 :            :         mbuf_append(m_out_head, m_out, out_length);
    1857         [ #  # ]:          0 :         if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_IN_ENABLE))
    1858                 :          0 :                 harq_offset = dec->harq_combined_input.offset;
    1859         [ #  # ]:          0 :         else if (check_bit(dec->op_flags, RTE_BBDEV_LDPC_HQ_COMBINE_OUT_ENABLE))
    1860                 :          0 :                 harq_offset = dec->harq_combined_output.offset;
    1861                 :            : 
    1862         [ #  # ]:          0 :         if ((harq_offset & 0x3FF) > 0) {
    1863                 :          0 :                 rte_bbdev_log(ERR, "Invalid HARQ offset %d", harq_offset);
    1864                 :          0 :                 op->status = 1 << RTE_BBDEV_DATA_ERROR;
    1865                 :          0 :                 return -1;
    1866                 :            :         }
    1867                 :            : 
    1868                 :          0 :         ret = fpga_dma_desc_ld_fill(op, &desc->dec_req, m_in, m_out,
    1869                 :            :                 harq_in_length, in_offset, out_offset, harq_offset,
    1870                 :            :                 ring_offset, c);
    1871         [ #  # ]:          0 :         if (unlikely(ret < 0))
    1872                 :            :                 return ret;
    1873                 :            :         /* Update lengths */
    1874                 :          0 :         seg_total_left -= in_length;
    1875                 :          0 :         op->ldpc_dec.hard_output.length += out_length;
    1876         [ #  # ]:          0 :         if (seg_total_left > 0) {
    1877                 :          0 :                 rte_bbdev_log(ERR,
    1878                 :            :                                 "Mismatch between mbuf length and included CB sizes: mbuf len %u, cb len %u",
    1879                 :            :                                 seg_total_left, in_length);
    1880                 :          0 :                 return -1;
    1881                 :            :         }
    1882                 :            : 
    1883                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
    1884                 :            :         print_dma_dec_desc_debug_info(desc);
    1885                 :            : #endif
    1886                 :            : 
    1887                 :            :         return 1;
    1888                 :            : }
    1889                 :            : 
    1890                 :            : static uint16_t
    1891                 :          0 : fpga_enqueue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
    1892                 :            :                 struct rte_bbdev_enc_op **ops, uint16_t num)
    1893                 :            : {
    1894                 :            :         uint16_t i, total_enqueued_cbs = 0;
    1895                 :            :         int32_t avail;
    1896                 :            :         int enqueued_cbs;
    1897                 :          0 :         struct fpga_queue *q = q_data->queue_private;
    1898                 :            :         union fpga_dma_desc *desc;
    1899                 :            : 
    1900                 :            :         /* Check if queue is not full */
    1901         [ #  # ]:          0 :         if (unlikely(((q->tail + 1) & q->sw_ring_wrap_mask) ==
    1902                 :            :                         q->head_free_desc))
    1903                 :            :                 return 0;
    1904                 :            : 
    1905                 :            :         /* Calculates available space */
    1906                 :            :         avail = (q->head_free_desc > q->tail) ?
    1907         [ #  # ]:          0 :                 q->head_free_desc - q->tail - 1 :
    1908                 :          0 :                 q->ring_ctrl_reg.ring_size + q->head_free_desc - q->tail - 1;
    1909                 :            : 
    1910         [ #  # ]:          0 :         for (i = 0; i < num; ++i) {
    1911                 :            : 
    1912                 :            :                 /* Check if there is available space for further
    1913                 :            :                  * processing
    1914                 :            :                  */
    1915         [ #  # ]:          0 :                 if (unlikely(avail - 1 < 0))
    1916                 :            :                         break;
    1917                 :          0 :                 avail -= 1;
    1918                 :          0 :                 enqueued_cbs = enqueue_ldpc_enc_one_op_cb(q, ops[i],
    1919                 :            :                                 total_enqueued_cbs);
    1920                 :            : 
    1921         [ #  # ]:          0 :                 if (enqueued_cbs < 0)
    1922                 :            :                         break;
    1923                 :            : 
    1924                 :          0 :                 total_enqueued_cbs += enqueued_cbs;
    1925                 :            : 
    1926                 :            :                 rte_bbdev_log_debug("enqueuing enc ops [%d/%d] | head %d | tail %d",
    1927                 :            :                                 total_enqueued_cbs, num,
    1928                 :            :                                 q->head_free_desc, q->tail);
    1929                 :            :         }
    1930                 :            : 
    1931                 :            :         /* Set interrupt bit for last CB in enqueued ops. FPGA issues interrupt
    1932                 :            :          * only when all previous CBs were already processed.
    1933                 :            :          */
    1934                 :          0 :         desc = q->ring_addr + ((q->tail + total_enqueued_cbs - 1)
    1935                 :          0 :                         & q->sw_ring_wrap_mask);
    1936                 :          0 :         desc->enc_req.irq_en = q->irq_enable;
    1937                 :            : 
    1938                 :            :         fpga_dma_enqueue(q, total_enqueued_cbs, &q_data->queue_stats);
    1939                 :            : 
    1940                 :            :         /* Update stats */
    1941                 :          0 :         q_data->queue_stats.enqueued_count += i;
    1942                 :          0 :         q_data->queue_stats.enqueue_err_count += num - i;
    1943                 :            : 
    1944                 :          0 :         return i;
    1945                 :            : }
    1946                 :            : 
    1947                 :            : static uint16_t
    1948                 :          0 : fpga_enqueue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
    1949                 :            :                 struct rte_bbdev_dec_op **ops, uint16_t num)
    1950                 :            : {
    1951                 :            :         uint16_t i, total_enqueued_cbs = 0;
    1952                 :            :         int32_t avail;
    1953                 :            :         int enqueued_cbs;
    1954                 :          0 :         struct fpga_queue *q = q_data->queue_private;
    1955                 :            :         union fpga_dma_desc *desc;
    1956                 :            : 
    1957                 :            :         /* Check if queue is not full */
    1958         [ #  # ]:          0 :         if (unlikely(((q->tail + 1) & q->sw_ring_wrap_mask) ==
    1959                 :            :                         q->head_free_desc))
    1960                 :            :                 return 0;
    1961                 :            : 
    1962                 :            :         /* Calculates available space */
    1963                 :            :         avail = (q->head_free_desc > q->tail) ?
    1964         [ #  # ]:          0 :                 q->head_free_desc - q->tail - 1 :
    1965                 :          0 :                 q->ring_ctrl_reg.ring_size + q->head_free_desc - q->tail - 1;
    1966                 :            : 
    1967         [ #  # ]:          0 :         for (i = 0; i < num; ++i) {
    1968                 :            : 
    1969                 :            :                 /* Check if there is available space for further
    1970                 :            :                  * processing
    1971                 :            :                  */
    1972         [ #  # ]:          0 :                 if (unlikely(avail - 1 < 0))
    1973                 :            :                         break;
    1974                 :          0 :                 avail -= 1;
    1975                 :          0 :                 enqueued_cbs = enqueue_ldpc_dec_one_op_cb(q, ops[i],
    1976                 :            :                                 total_enqueued_cbs);
    1977                 :            : 
    1978         [ #  # ]:          0 :                 if (enqueued_cbs < 0)
    1979                 :            :                         break;
    1980                 :            : 
    1981                 :          0 :                 total_enqueued_cbs += enqueued_cbs;
    1982                 :            : 
    1983                 :            :                 rte_bbdev_log_debug("enqueuing dec ops [%d/%d] | head %d | tail %d",
    1984                 :            :                                 total_enqueued_cbs, num,
    1985                 :            :                                 q->head_free_desc, q->tail);
    1986                 :            :         }
    1987                 :            : 
    1988                 :            :         /* Update stats */
    1989                 :          0 :         q_data->queue_stats.enqueued_count += i;
    1990                 :          0 :         q_data->queue_stats.enqueue_err_count += num - i;
    1991                 :            : 
    1992                 :            :         /* Set interrupt bit for last CB in enqueued ops. FPGA issues interrupt
    1993                 :            :          * only when all previous CBs were already processed.
    1994                 :            :          */
    1995                 :          0 :         desc = q->ring_addr + ((q->tail + total_enqueued_cbs - 1)
    1996                 :          0 :                         & q->sw_ring_wrap_mask);
    1997                 :          0 :         desc->enc_req.irq_en = q->irq_enable;
    1998                 :            :         fpga_dma_enqueue(q, total_enqueued_cbs, &q_data->queue_stats);
    1999                 :          0 :         return i;
    2000                 :            : }
    2001                 :            : 
    2002                 :            : 
    2003                 :            : static inline int
    2004                 :          0 : dequeue_ldpc_enc_one_op_cb(struct fpga_queue *q, struct rte_bbdev_enc_op **op,
    2005                 :            :                 uint16_t desc_offset)
    2006                 :            : {
    2007                 :            :         union fpga_dma_desc *desc;
    2008                 :            :         int desc_error;
    2009                 :            :         /* Set current desc */
    2010                 :          0 :         desc = q->ring_addr + ((q->head_free_desc + desc_offset)
    2011                 :          0 :                         & q->sw_ring_wrap_mask);
    2012                 :            : 
    2013                 :            :         /*check if done */
    2014         [ #  # ]:          0 :         if (desc->enc_req.done == 0)
    2015                 :            :                 return -1;
    2016                 :            : 
    2017                 :            :         /* make sure the response is read atomically */
    2018                 :          0 :         rte_smp_rmb();
    2019                 :            : 
    2020                 :            :         rte_bbdev_log_debug("DMA response desc %p", desc);
    2021                 :            : 
    2022                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
    2023                 :            :         print_dma_enc_desc_debug_info(desc);
    2024                 :            : #endif
    2025                 :            : 
    2026                 :          0 :         *op = desc->enc_req.op_addr;
    2027                 :            :         /* Check the descriptor error field, return 1 on error */
    2028                 :          0 :         desc_error = check_desc_error(desc->enc_req.error);
    2029                 :          0 :         (*op)->status = desc_error << RTE_BBDEV_DATA_ERROR;
    2030                 :            : 
    2031                 :          0 :         return 1;
    2032                 :            : }
    2033                 :            : 
    2034                 :            : 
    2035                 :            : static inline int
    2036                 :          0 : dequeue_ldpc_dec_one_op_cb(struct fpga_queue *q, struct rte_bbdev_dec_op **op,
    2037                 :            :                 uint16_t desc_offset)
    2038                 :            : {
    2039                 :            :         union fpga_dma_desc *desc;
    2040                 :            :         int desc_error;
    2041                 :            :         /* Set descriptor */
    2042                 :          0 :         desc = q->ring_addr + ((q->head_free_desc + desc_offset)
    2043                 :          0 :                         & q->sw_ring_wrap_mask);
    2044                 :            : 
    2045                 :            :         /* Verify done bit is set */
    2046         [ #  # ]:          0 :         if (desc->dec_req.done == 0)
    2047                 :            :                 return -1;
    2048                 :            : 
    2049                 :            :         /* make sure the response is read atomically */
    2050                 :          0 :         rte_smp_rmb();
    2051                 :            : 
    2052                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
    2053                 :            :         print_dma_dec_desc_debug_info(desc);
    2054                 :            : #endif
    2055                 :            : 
    2056                 :          0 :         *op = desc->dec_req.op_addr;
    2057                 :            : 
    2058         [ #  # ]:          0 :         if (check_bit((*op)->ldpc_dec.op_flags,
    2059                 :            :                         RTE_BBDEV_LDPC_INTERNAL_HARQ_MEMORY_LOOPBACK)) {
    2060                 :          0 :                 (*op)->status = 0;
    2061                 :          0 :                 return 1;
    2062                 :            :         }
    2063                 :            : 
    2064                 :            :         /* FPGA reports iterations based on round-up minus 1 */
    2065                 :          0 :         (*op)->ldpc_dec.iter_count = desc->dec_req.iter + 1;
    2066                 :            :         /* CRC Check criteria */
    2067   [ #  #  #  # ]:          0 :         if (desc->dec_req.crc24b_ind && !(desc->dec_req.crcb_pass))
    2068                 :          0 :                 (*op)->status = 1 << RTE_BBDEV_CRC_ERROR;
    2069                 :            :         /* et_pass = 0 when decoder fails */
    2070         [ #  # ]:          0 :         (*op)->status |= !(desc->dec_req.et_pass) << RTE_BBDEV_SYNDROME_ERROR;
    2071                 :            :         /* Check the descriptor error field, return 1 on error */
    2072                 :          0 :         desc_error = check_desc_error(desc->dec_req.error);
    2073                 :          0 :         (*op)->status |= desc_error << RTE_BBDEV_DATA_ERROR;
    2074                 :          0 :         return 1;
    2075                 :            : }
    2076                 :            : 
    2077                 :            : static uint16_t
    2078                 :          0 : fpga_dequeue_ldpc_enc(struct rte_bbdev_queue_data *q_data,
    2079                 :            :                 struct rte_bbdev_enc_op **ops, uint16_t num)
    2080                 :            : {
    2081                 :          0 :         struct fpga_queue *q = q_data->queue_private;
    2082                 :          0 :         uint32_t avail = (q->tail - q->head_free_desc) & q->sw_ring_wrap_mask;
    2083                 :            :         uint16_t i;
    2084                 :            :         uint16_t dequeued_cbs = 0;
    2085                 :            :         int ret;
    2086                 :            : 
    2087   [ #  #  #  # ]:          0 :         for (i = 0; (i < num) && (dequeued_cbs < avail); ++i) {
    2088                 :          0 :                 ret = dequeue_ldpc_enc_one_op_cb(q, &ops[i], dequeued_cbs);
    2089                 :            : 
    2090         [ #  # ]:          0 :                 if (ret < 0)
    2091                 :            :                         break;
    2092                 :            : 
    2093                 :          0 :                 dequeued_cbs += ret;
    2094                 :            : 
    2095                 :            :                 rte_bbdev_log_debug("dequeuing enc ops [%d/%d] | head %d | tail %d",
    2096                 :            :                                 dequeued_cbs, num, q->head_free_desc, q->tail);
    2097                 :            :         }
    2098                 :            : 
    2099                 :            :         /* Update head */
    2100                 :          0 :         q->head_free_desc = (q->head_free_desc + dequeued_cbs) &
    2101                 :          0 :                         q->sw_ring_wrap_mask;
    2102                 :            : 
    2103                 :            :         /* Update stats */
    2104                 :          0 :         q_data->queue_stats.dequeued_count += i;
    2105                 :            : 
    2106                 :          0 :         return i;
    2107                 :            : }
    2108                 :            : 
    2109                 :            : static uint16_t
    2110                 :          0 : fpga_dequeue_ldpc_dec(struct rte_bbdev_queue_data *q_data,
    2111                 :            :                 struct rte_bbdev_dec_op **ops, uint16_t num)
    2112                 :            : {
    2113                 :          0 :         struct fpga_queue *q = q_data->queue_private;
    2114                 :          0 :         uint32_t avail = (q->tail - q->head_free_desc) & q->sw_ring_wrap_mask;
    2115                 :            :         uint16_t i;
    2116                 :            :         uint16_t dequeued_cbs = 0;
    2117                 :            :         int ret;
    2118                 :            : 
    2119   [ #  #  #  # ]:          0 :         for (i = 0; (i < num) && (dequeued_cbs < avail); ++i) {
    2120                 :          0 :                 ret = dequeue_ldpc_dec_one_op_cb(q, &ops[i], dequeued_cbs);
    2121                 :            : 
    2122         [ #  # ]:          0 :                 if (ret < 0)
    2123                 :            :                         break;
    2124                 :            : 
    2125                 :          0 :                 dequeued_cbs += ret;
    2126                 :            : 
    2127                 :            :                 rte_bbdev_log_debug("dequeuing dec ops [%d/%d] | head %d | tail %d",
    2128                 :            :                                 dequeued_cbs, num, q->head_free_desc, q->tail);
    2129                 :            :         }
    2130                 :            : 
    2131                 :            :         /* Update head */
    2132                 :          0 :         q->head_free_desc = (q->head_free_desc + dequeued_cbs) &
    2133                 :          0 :                         q->sw_ring_wrap_mask;
    2134                 :            : 
    2135                 :            :         /* Update stats */
    2136                 :          0 :         q_data->queue_stats.dequeued_count += i;
    2137                 :            : 
    2138                 :          0 :         return i;
    2139                 :            : }
    2140                 :            : 
    2141                 :            : 
    2142                 :            : /* Initialization Function */
    2143                 :            : static void
    2144                 :          0 : fpga_5gnr_fec_init(struct rte_bbdev *dev, struct rte_pci_driver *drv)
    2145                 :            : {
    2146                 :          0 :         struct rte_pci_device *pci_dev = RTE_DEV_TO_PCI(dev->device);
    2147                 :            : 
    2148                 :          0 :         dev->dev_ops = &fpga_ops;
    2149                 :          0 :         dev->enqueue_ldpc_enc_ops = fpga_enqueue_ldpc_enc;
    2150                 :          0 :         dev->enqueue_ldpc_dec_ops = fpga_enqueue_ldpc_dec;
    2151                 :          0 :         dev->dequeue_ldpc_enc_ops = fpga_dequeue_ldpc_enc;
    2152                 :          0 :         dev->dequeue_ldpc_dec_ops = fpga_dequeue_ldpc_dec;
    2153                 :            : 
    2154                 :          0 :         ((struct fpga_5gnr_fec_device *) dev->data->dev_private)->pf_device =
    2155                 :          0 :                         !strcmp(drv->driver.name,
    2156                 :            :                                         RTE_STR(FPGA_5GNR_FEC_PF_DRIVER_NAME));
    2157                 :          0 :         ((struct fpga_5gnr_fec_device *) dev->data->dev_private)->mmio_base =
    2158                 :          0 :                         pci_dev->mem_resource[0].addr;
    2159                 :            : 
    2160                 :            :         rte_bbdev_log_debug(
    2161                 :            :                         "Init device %s [%s] @ virtaddr %p phyaddr %#"PRIx64,
    2162                 :            :                         drv->driver.name, dev->data->name,
    2163                 :            :                         (void *)pci_dev->mem_resource[0].addr,
    2164                 :            :                         pci_dev->mem_resource[0].phys_addr);
    2165                 :          0 : }
    2166                 :            : 
    2167                 :            : static int
    2168                 :          0 : fpga_5gnr_fec_probe(struct rte_pci_driver *pci_drv,
    2169                 :            :         struct rte_pci_device *pci_dev)
    2170                 :            : {
    2171                 :            :         struct rte_bbdev *bbdev = NULL;
    2172                 :            :         char dev_name[RTE_BBDEV_NAME_MAX_LEN];
    2173                 :            : 
    2174         [ #  # ]:          0 :         if (pci_dev == NULL) {
    2175                 :          0 :                 rte_bbdev_log(ERR, "NULL PCI device");
    2176                 :          0 :                 return -EINVAL;
    2177                 :            :         }
    2178                 :            : 
    2179                 :          0 :         rte_pci_device_name(&pci_dev->addr, dev_name, sizeof(dev_name));
    2180                 :            : 
    2181                 :            :         /* Allocate memory to be used privately by drivers */
    2182                 :          0 :         bbdev = rte_bbdev_allocate(pci_dev->device.name);
    2183         [ #  # ]:          0 :         if (bbdev == NULL)
    2184                 :            :                 return -ENODEV;
    2185                 :            : 
    2186                 :            :         /* allocate device private memory */
    2187                 :          0 :         bbdev->data->dev_private = rte_zmalloc_socket(dev_name,
    2188                 :            :                         sizeof(struct fpga_5gnr_fec_device),
    2189                 :            :                         RTE_CACHE_LINE_SIZE,
    2190                 :            :                         pci_dev->device.numa_node);
    2191                 :            : 
    2192         [ #  # ]:          0 :         if (bbdev->data->dev_private == NULL) {
    2193                 :          0 :                 rte_bbdev_log(CRIT,
    2194                 :            :                                 "Allocate of %zu bytes for device \"%s\" failed",
    2195                 :            :                                 sizeof(struct fpga_5gnr_fec_device), dev_name);
    2196                 :          0 :                                 rte_bbdev_release(bbdev);
    2197                 :          0 :                         return -ENOMEM;
    2198                 :            :         }
    2199                 :            : 
    2200                 :            :         /* Fill HW specific part of device structure */
    2201                 :          0 :         bbdev->device = &pci_dev->device;
    2202                 :          0 :         bbdev->intr_handle = pci_dev->intr_handle;
    2203                 :          0 :         bbdev->data->socket_id = pci_dev->device.numa_node;
    2204                 :            : 
    2205                 :            :         /* Invoke FEC FPGA device initialization function */
    2206                 :          0 :         fpga_5gnr_fec_init(bbdev, pci_drv);
    2207                 :            : 
    2208                 :            :         rte_bbdev_log_debug("bbdev id = %u [%s]",
    2209                 :            :                         bbdev->data->dev_id, dev_name);
    2210                 :            : 
    2211                 :            :         struct fpga_5gnr_fec_device *d = bbdev->data->dev_private;
    2212                 :          0 :         uint32_t version_id = fpga_reg_read_32(d->mmio_base,
    2213                 :            :                         FPGA_5GNR_FEC_VERSION_ID);
    2214                 :          0 :         rte_bbdev_log(INFO, "FEC FPGA RTL v%u.%u",
    2215                 :            :                 ((uint16_t)(version_id >> 16)), ((uint16_t)version_id));
    2216                 :            : 
    2217                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
    2218                 :            :         if (!strcmp(pci_drv->driver.name,
    2219                 :            :                         RTE_STR(FPGA_5GNR_FEC_PF_DRIVER_NAME)))
    2220                 :            :                 print_static_reg_debug_info(d->mmio_base);
    2221                 :            : #endif
    2222                 :          0 :         return 0;
    2223                 :            : }
    2224                 :            : 
    2225                 :            : static int
    2226                 :          0 : fpga_5gnr_fec_remove(struct rte_pci_device *pci_dev)
    2227                 :            : {
    2228                 :            :         struct rte_bbdev *bbdev;
    2229                 :            :         int ret;
    2230                 :            :         uint8_t dev_id;
    2231                 :            : 
    2232         [ #  # ]:          0 :         if (pci_dev == NULL)
    2233                 :            :                 return -EINVAL;
    2234                 :            : 
    2235                 :            :         /* Find device */
    2236                 :          0 :         bbdev = rte_bbdev_get_named_dev(pci_dev->device.name);
    2237         [ #  # ]:          0 :         if (bbdev == NULL) {
    2238                 :          0 :                 rte_bbdev_log(CRIT,
    2239                 :            :                                 "Couldn't find HW dev \"%s\" to uninitialise it",
    2240                 :            :                                 pci_dev->device.name);
    2241                 :          0 :                 return -ENODEV;
    2242                 :            :         }
    2243                 :          0 :         dev_id = bbdev->data->dev_id;
    2244                 :            : 
    2245                 :            :         /* free device private memory before close */
    2246                 :          0 :         rte_free(bbdev->data->dev_private);
    2247                 :            : 
    2248                 :            :         /* Close device */
    2249                 :          0 :         ret = rte_bbdev_close(dev_id);
    2250         [ #  # ]:          0 :         if (ret < 0)
    2251                 :          0 :                 rte_bbdev_log(ERR,
    2252                 :            :                                 "Device %i failed to close during uninit: %i",
    2253                 :            :                                 dev_id, ret);
    2254                 :            : 
    2255                 :            :         /* release bbdev from library */
    2256                 :          0 :         ret = rte_bbdev_release(bbdev);
    2257         [ #  # ]:          0 :         if (ret)
    2258                 :          0 :                 rte_bbdev_log(ERR, "Device %i failed to uninit: %i", dev_id,
    2259                 :            :                                 ret);
    2260                 :            : 
    2261                 :            :         rte_bbdev_log_debug("Destroyed bbdev = %u", dev_id);
    2262                 :            : 
    2263                 :            :         return 0;
    2264                 :            : }
    2265                 :            : 
    2266                 :            : static inline void
    2267                 :            : set_default_fpga_conf(struct rte_fpga_5gnr_fec_conf *def_conf)
    2268                 :            : {
    2269                 :            :         /* clear default configuration before initialization */
    2270                 :            :         memset(def_conf, 0, sizeof(struct rte_fpga_5gnr_fec_conf));
    2271                 :            :         /* Set pf mode to true */
    2272                 :          0 :         def_conf->pf_mode_en = true;
    2273                 :            : 
    2274                 :            :         /* Set ratio between UL and DL to 1:1 (unit of weight is 3 CBs) */
    2275                 :          0 :         def_conf->ul_bandwidth = 3;
    2276                 :          0 :         def_conf->dl_bandwidth = 3;
    2277                 :            : 
    2278                 :            :         /* Set Load Balance Factor to 64 */
    2279                 :          0 :         def_conf->dl_load_balance = 64;
    2280                 :          0 :         def_conf->ul_load_balance = 64;
    2281                 :            : }
    2282                 :            : 
    2283                 :            : /* Initial configuration of FPGA 5GNR FEC device */
    2284                 :            : int
    2285                 :          0 : rte_fpga_5gnr_fec_configure(const char *dev_name,
    2286                 :            :                 const struct rte_fpga_5gnr_fec_conf *conf)
    2287                 :            : {
    2288                 :            :         uint32_t payload_32, address;
    2289                 :            :         uint16_t payload_16;
    2290                 :            :         uint8_t payload_8;
    2291                 :            :         uint16_t q_id, vf_id, total_q_id, total_ul_q_id, total_dl_q_id;
    2292                 :          0 :         struct rte_bbdev *bbdev = rte_bbdev_get_named_dev(dev_name);
    2293                 :            :         struct rte_fpga_5gnr_fec_conf def_conf;
    2294                 :            : 
    2295         [ #  # ]:          0 :         if (bbdev == NULL) {
    2296                 :          0 :                 rte_bbdev_log(ERR,
    2297                 :            :                                 "Invalid dev_name (%s), or device is not yet initialised",
    2298                 :            :                                 dev_name);
    2299                 :          0 :                 return -ENODEV;
    2300                 :            :         }
    2301                 :            : 
    2302                 :          0 :         struct fpga_5gnr_fec_device *d = bbdev->data->dev_private;
    2303                 :            : 
    2304         [ #  # ]:          0 :         if (conf == NULL) {
    2305                 :          0 :                 rte_bbdev_log(ERR,
    2306                 :            :                                 "FPGA Configuration was not provided. Default configuration will be loaded.");
    2307                 :            :                 set_default_fpga_conf(&def_conf);
    2308                 :            :                 conf = &def_conf;
    2309                 :            :         }
    2310                 :            : 
    2311                 :            :         /*
    2312                 :            :          * Configure UL:DL ratio.
    2313                 :            :          * [7:0]: UL weight
    2314                 :            :          * [15:8]: DL weight
    2315                 :            :          */
    2316                 :          0 :         payload_16 = (conf->dl_bandwidth << 8) | conf->ul_bandwidth;
    2317                 :            :         address = FPGA_5GNR_FEC_CONFIGURATION;
    2318                 :          0 :         fpga_reg_write_16(d->mmio_base, address, payload_16);
    2319                 :            : 
    2320                 :            :         /* Clear all queues registers */
    2321                 :            :         payload_32 = FPGA_INVALID_HW_QUEUE_ID;
    2322         [ #  # ]:          0 :         for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
    2323                 :          0 :                 address = (q_id << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
    2324                 :            :                 fpga_reg_write_32(d->mmio_base, address, payload_32);
    2325                 :            :         }
    2326                 :            : 
    2327                 :            :         /*
    2328                 :            :          * If PF mode is enabled allocate all queues for PF only.
    2329                 :            :          *
    2330                 :            :          * For VF mode each VF can have different number of UL and DL queues.
    2331                 :            :          * Total number of queues to configure cannot exceed FPGA
    2332                 :            :          * capabilities - 64 queues - 32 queues for UL and 32 queues for DL.
    2333                 :            :          * Queues mapping is done according to configuration:
    2334                 :            :          *
    2335                 :            :          * UL queues:
    2336                 :            :          * |                Q_ID              | VF_ID |
    2337                 :            :          * |                 0                |   0   |
    2338                 :            :          * |                ...               |   0   |
    2339                 :            :          * | conf->vf_dl_queues_number[0] - 1 |   0   |
    2340                 :            :          * | conf->vf_dl_queues_number[0]     |   1   |
    2341                 :            :          * |                ...               |   1   |
    2342                 :            :          * | conf->vf_dl_queues_number[1] - 1 |   1   |
    2343                 :            :          * |                ...               |  ...  |
    2344                 :            :          * | conf->vf_dl_queues_number[7] - 1 |   7   |
    2345                 :            :          *
    2346                 :            :          * DL queues:
    2347                 :            :          * |                Q_ID              | VF_ID |
    2348                 :            :          * |                 32               |   0   |
    2349                 :            :          * |                ...               |   0   |
    2350                 :            :          * | conf->vf_ul_queues_number[0] - 1 |   0   |
    2351                 :            :          * | conf->vf_ul_queues_number[0]     |   1   |
    2352                 :            :          * |                ...               |   1   |
    2353                 :            :          * | conf->vf_ul_queues_number[1] - 1 |   1   |
    2354                 :            :          * |                ...               |  ...  |
    2355                 :            :          * | conf->vf_ul_queues_number[7] - 1 |   7   |
    2356                 :            :          *
    2357                 :            :          * Example of configuration:
    2358                 :            :          * conf->vf_ul_queues_number[0] = 4;  -> 4 UL queues for VF0
    2359                 :            :          * conf->vf_dl_queues_number[0] = 4;  -> 4 DL queues for VF0
    2360                 :            :          * conf->vf_ul_queues_number[1] = 2;  -> 2 UL queues for VF1
    2361                 :            :          * conf->vf_dl_queues_number[1] = 2;  -> 2 DL queues for VF1
    2362                 :            :          *
    2363                 :            :          * UL:
    2364                 :            :          * | Q_ID | VF_ID |
    2365                 :            :          * |   0  |   0   |
    2366                 :            :          * |   1  |   0   |
    2367                 :            :          * |   2  |   0   |
    2368                 :            :          * |   3  |   0   |
    2369                 :            :          * |   4  |   1   |
    2370                 :            :          * |   5  |   1   |
    2371                 :            :          *
    2372                 :            :          * DL:
    2373                 :            :          * | Q_ID | VF_ID |
    2374                 :            :          * |  32  |   0   |
    2375                 :            :          * |  33  |   0   |
    2376                 :            :          * |  34  |   0   |
    2377                 :            :          * |  35  |   0   |
    2378                 :            :          * |  36  |   1   |
    2379                 :            :          * |  37  |   1   |
    2380                 :            :          */
    2381         [ #  # ]:          0 :         if (conf->pf_mode_en) {
    2382                 :            :                 payload_32 = 0x1;
    2383         [ #  # ]:          0 :                 for (q_id = 0; q_id < FPGA_TOTAL_NUM_QUEUES; ++q_id) {
    2384                 :          0 :                         address = (q_id << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
    2385                 :            :                         fpga_reg_write_32(d->mmio_base, address, payload_32);
    2386                 :            :                 }
    2387                 :            :         } else {
    2388                 :            :                 /* Calculate total number of UL and DL queues to configure */
    2389                 :            :                 total_ul_q_id = total_dl_q_id = 0;
    2390         [ #  # ]:          0 :                 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
    2391                 :          0 :                         total_ul_q_id += conf->vf_ul_queues_number[vf_id];
    2392                 :          0 :                         total_dl_q_id += conf->vf_dl_queues_number[vf_id];
    2393                 :            :                 }
    2394                 :          0 :                 total_q_id = total_dl_q_id + total_ul_q_id;
    2395                 :            :                 /*
    2396                 :            :                  * Check if total number of queues to configure does not exceed
    2397                 :            :                  * FPGA capabilities (64 queues - 32 UL and 32 DL queues)
    2398                 :            :                  */
    2399                 :          0 :                 if ((total_ul_q_id > FPGA_NUM_UL_QUEUES) ||
    2400   [ #  #  #  # ]:          0 :                         (total_dl_q_id > FPGA_NUM_DL_QUEUES) ||
    2401                 :            :                         (total_q_id > FPGA_TOTAL_NUM_QUEUES)) {
    2402                 :          0 :                         rte_bbdev_log(ERR,
    2403                 :            :                                         "FPGA Configuration failed. Too many queues to configure: UL_Q %u, DL_Q %u, FPGA_Q %u",
    2404                 :            :                                         total_ul_q_id, total_dl_q_id,
    2405                 :            :                                         FPGA_TOTAL_NUM_QUEUES);
    2406                 :          0 :                         return -EINVAL;
    2407                 :            :                 }
    2408                 :            :                 total_ul_q_id = 0;
    2409         [ #  # ]:          0 :                 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
    2410         [ #  # ]:          0 :                         for (q_id = 0; q_id < conf->vf_ul_queues_number[vf_id];
    2411                 :          0 :                                         ++q_id, ++total_ul_q_id) {
    2412                 :          0 :                                 address = (total_ul_q_id << 2) +
    2413                 :            :                                                 FPGA_5GNR_FEC_QUEUE_MAP;
    2414                 :          0 :                                 payload_32 = ((0x80 + vf_id) << 16) | 0x1;
    2415                 :            :                                 fpga_reg_write_32(d->mmio_base, address,
    2416                 :            :                                                 payload_32);
    2417                 :            :                         }
    2418                 :            :                 }
    2419                 :            :                 total_dl_q_id = 0;
    2420         [ #  # ]:          0 :                 for (vf_id = 0; vf_id < FPGA_5GNR_FEC_NUM_VFS; ++vf_id) {
    2421         [ #  # ]:          0 :                         for (q_id = 0; q_id < conf->vf_dl_queues_number[vf_id];
    2422                 :          0 :                                         ++q_id, ++total_dl_q_id) {
    2423                 :          0 :                                 address = ((total_dl_q_id + FPGA_NUM_UL_QUEUES)
    2424                 :          0 :                                                 << 2) + FPGA_5GNR_FEC_QUEUE_MAP;
    2425                 :          0 :                                 payload_32 = ((0x80 + vf_id) << 16) | 0x1;
    2426                 :            :                                 fpga_reg_write_32(d->mmio_base, address,
    2427                 :            :                                                 payload_32);
    2428                 :            :                         }
    2429                 :            :                 }
    2430                 :            :         }
    2431                 :            : 
    2432                 :            :         /* Setting Load Balance Factor */
    2433                 :          0 :         payload_16 = (conf->dl_load_balance << 8) | (conf->ul_load_balance);
    2434                 :            :         address = FPGA_5GNR_FEC_LOAD_BALANCE_FACTOR;
    2435                 :            :         fpga_reg_write_16(d->mmio_base, address, payload_16);
    2436                 :            : 
    2437                 :            :         /* Setting length of ring descriptor entry */
    2438                 :            :         payload_16 = FPGA_RING_DESC_ENTRY_LENGTH;
    2439                 :            :         address = FPGA_5GNR_FEC_RING_DESC_LEN;
    2440                 :            :         fpga_reg_write_16(d->mmio_base, address, payload_16);
    2441                 :            : 
    2442                 :            :         /* Queue PF/VF mapping table is ready */
    2443                 :            :         payload_8 = 0x1;
    2444                 :            :         address = FPGA_5GNR_FEC_QUEUE_PF_VF_MAP_DONE;
    2445                 :            :         fpga_reg_write_8(d->mmio_base, address, payload_8);
    2446                 :            : 
    2447                 :            :         rte_bbdev_log_debug("PF FPGA 5GNR FEC configuration complete for %s",
    2448                 :            :                         dev_name);
    2449                 :            : 
    2450                 :            : #ifdef RTE_LIBRTE_BBDEV_DEBUG
    2451                 :            :         print_static_reg_debug_info(d->mmio_base);
    2452                 :            : #endif
    2453                 :          0 :         return 0;
    2454                 :            : }
    2455                 :            : 
    2456                 :            : /* FPGA 5GNR FEC PCI PF address map */
    2457                 :            : static struct rte_pci_id pci_id_fpga_5gnr_fec_pf_map[] = {
    2458                 :            :         {
    2459                 :            :                 RTE_PCI_DEVICE(FPGA_5GNR_FEC_VENDOR_ID,
    2460                 :            :                                 FPGA_5GNR_FEC_PF_DEVICE_ID)
    2461                 :            :         },
    2462                 :            :         {.device_id = 0},
    2463                 :            : };
    2464                 :            : 
    2465                 :            : static struct rte_pci_driver fpga_5gnr_fec_pci_pf_driver = {
    2466                 :            :         .probe = fpga_5gnr_fec_probe,
    2467                 :            :         .remove = fpga_5gnr_fec_remove,
    2468                 :            :         .id_table = pci_id_fpga_5gnr_fec_pf_map,
    2469                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING
    2470                 :            : };
    2471                 :            : 
    2472                 :            : /* FPGA 5GNR FEC PCI VF address map */
    2473                 :            : static struct rte_pci_id pci_id_fpga_5gnr_fec_vf_map[] = {
    2474                 :            :         {
    2475                 :            :                 RTE_PCI_DEVICE(FPGA_5GNR_FEC_VENDOR_ID,
    2476                 :            :                                 FPGA_5GNR_FEC_VF_DEVICE_ID)
    2477                 :            :         },
    2478                 :            :         {.device_id = 0},
    2479                 :            : };
    2480                 :            : 
    2481                 :            : static struct rte_pci_driver fpga_5gnr_fec_pci_vf_driver = {
    2482                 :            :         .probe = fpga_5gnr_fec_probe,
    2483                 :            :         .remove = fpga_5gnr_fec_remove,
    2484                 :            :         .id_table = pci_id_fpga_5gnr_fec_vf_map,
    2485                 :            :         .drv_flags = RTE_PCI_DRV_NEED_MAPPING
    2486                 :            : };
    2487                 :            : 
    2488                 :            : 
    2489                 :        235 : RTE_PMD_REGISTER_PCI(FPGA_5GNR_FEC_PF_DRIVER_NAME, fpga_5gnr_fec_pci_pf_driver);
    2490                 :            : RTE_PMD_REGISTER_PCI_TABLE(FPGA_5GNR_FEC_PF_DRIVER_NAME,
    2491                 :            :                 pci_id_fpga_5gnr_fec_pf_map);
    2492                 :        235 : RTE_PMD_REGISTER_PCI(FPGA_5GNR_FEC_VF_DRIVER_NAME, fpga_5gnr_fec_pci_vf_driver);
    2493                 :            : RTE_PMD_REGISTER_PCI_TABLE(FPGA_5GNR_FEC_VF_DRIVER_NAME,
    2494                 :            :                 pci_id_fpga_5gnr_fec_vf_map);

Generated by: LCOV version 1.14