LCOV - code coverage report
Current view: top level - drivers/baseband/acc - rte_acc100_pmd.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 3 2164 0.1 %
Date: 2024-01-22 15:55:54 Functions: 3 74 4.1 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 1 1193 0.1 %

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

Generated by: LCOV version 1.14