LCOV - code coverage report
Current view: top level - drivers/event/cnxk - cnxk_eventdev_adptr.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 344 0.0 %
Date: 2024-01-22 16:26:08 Functions: 0 23 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 172 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include "cnxk_cryptodev_ops.h"
       6                 :            : #include "cnxk_ethdev.h"
       7                 :            : #include "cnxk_eventdev.h"
       8                 :            : 
       9                 :            : void
      10                 :          0 : cnxk_sso_updt_xae_cnt(struct cnxk_sso_evdev *dev, void *data,
      11                 :            :                       uint32_t event_type)
      12                 :            : {
      13                 :            :         int i;
      14                 :            : 
      15   [ #  #  #  # ]:          0 :         switch (event_type) {
      16                 :            :         case RTE_EVENT_TYPE_ETHDEV: {
      17                 :            :                 struct cnxk_eth_rxq_sp *rxq = data;
      18                 :            :                 uint64_t *old_ptr;
      19                 :            : 
      20         [ #  # ]:          0 :                 for (i = 0; i < dev->rx_adptr_pool_cnt; i++) {
      21         [ #  # ]:          0 :                         if ((uint64_t)rxq->qconf.mp == dev->rx_adptr_pools[i])
      22                 :            :                                 return;
      23                 :            :                 }
      24                 :            : 
      25                 :          0 :                 dev->rx_adptr_pool_cnt++;
      26                 :          0 :                 old_ptr = dev->rx_adptr_pools;
      27                 :          0 :                 dev->rx_adptr_pools = rte_realloc(
      28                 :            :                         dev->rx_adptr_pools,
      29                 :          0 :                         sizeof(uint64_t) * dev->rx_adptr_pool_cnt, 0);
      30         [ #  # ]:          0 :                 if (dev->rx_adptr_pools == NULL) {
      31                 :          0 :                         dev->adptr_xae_cnt += rxq->qconf.mp->size;
      32                 :          0 :                         dev->rx_adptr_pools = old_ptr;
      33                 :          0 :                         dev->rx_adptr_pool_cnt--;
      34                 :          0 :                         return;
      35                 :            :                 }
      36                 :          0 :                 dev->rx_adptr_pools[dev->rx_adptr_pool_cnt - 1] =
      37                 :          0 :                         (uint64_t)rxq->qconf.mp;
      38                 :            : 
      39                 :          0 :                 dev->adptr_xae_cnt += rxq->qconf.mp->size;
      40                 :          0 :                 break;
      41                 :            :         }
      42                 :            :         case RTE_EVENT_TYPE_ETHDEV_VECTOR: {
      43                 :            :                 struct rte_mempool *mp = data;
      44                 :            :                 uint64_t *old_ptr;
      45                 :            : 
      46         [ #  # ]:          0 :                 for (i = 0; i < dev->vec_pool_cnt; i++) {
      47         [ #  # ]:          0 :                         if ((uint64_t)mp == dev->vec_pools[i])
      48                 :            :                                 return;
      49                 :            :                 }
      50                 :            : 
      51                 :          0 :                 dev->vec_pool_cnt++;
      52                 :          0 :                 old_ptr = dev->vec_pools;
      53                 :          0 :                 dev->vec_pools =
      54                 :          0 :                         rte_realloc(dev->vec_pools,
      55                 :          0 :                                     sizeof(uint64_t) * dev->vec_pool_cnt, 0);
      56         [ #  # ]:          0 :                 if (dev->vec_pools == NULL) {
      57                 :          0 :                         dev->adptr_xae_cnt += mp->size;
      58                 :          0 :                         dev->vec_pools = old_ptr;
      59                 :          0 :                         dev->vec_pool_cnt--;
      60                 :          0 :                         return;
      61                 :            :                 }
      62                 :          0 :                 dev->vec_pools[dev->vec_pool_cnt - 1] = (uint64_t)mp;
      63                 :            : 
      64                 :          0 :                 dev->adptr_xae_cnt += mp->size;
      65                 :          0 :                 break;
      66                 :            :         }
      67                 :            :         case RTE_EVENT_TYPE_TIMER: {
      68                 :            :                 struct cnxk_tim_ring *timr = data;
      69                 :            :                 uint16_t *old_ring_ptr;
      70                 :            :                 uint64_t *old_sz_ptr;
      71                 :            : 
      72         [ #  # ]:          0 :                 for (i = 0; i < dev->tim_adptr_ring_cnt; i++) {
      73         [ #  # ]:          0 :                         if (timr->ring_id != dev->timer_adptr_rings[i])
      74                 :            :                                 continue;
      75         [ #  # ]:          0 :                         if (timr->nb_timers == dev->timer_adptr_sz[i])
      76                 :            :                                 return;
      77                 :          0 :                         dev->adptr_xae_cnt -= dev->timer_adptr_sz[i];
      78                 :          0 :                         dev->adptr_xae_cnt += timr->nb_timers;
      79                 :          0 :                         dev->timer_adptr_sz[i] = timr->nb_timers;
      80                 :            : 
      81                 :          0 :                         return;
      82                 :            :                 }
      83                 :            : 
      84                 :          0 :                 dev->tim_adptr_ring_cnt++;
      85                 :          0 :                 old_ring_ptr = dev->timer_adptr_rings;
      86                 :          0 :                 old_sz_ptr = dev->timer_adptr_sz;
      87                 :            : 
      88                 :          0 :                 dev->timer_adptr_rings = rte_realloc(
      89                 :            :                         dev->timer_adptr_rings,
      90                 :          0 :                         sizeof(uint16_t) * dev->tim_adptr_ring_cnt, 0);
      91         [ #  # ]:          0 :                 if (dev->timer_adptr_rings == NULL) {
      92                 :          0 :                         dev->adptr_xae_cnt += timr->nb_timers;
      93                 :          0 :                         dev->timer_adptr_rings = old_ring_ptr;
      94                 :          0 :                         dev->tim_adptr_ring_cnt--;
      95                 :          0 :                         return;
      96                 :            :                 }
      97                 :            : 
      98                 :          0 :                 dev->timer_adptr_sz = rte_realloc(
      99                 :          0 :                         dev->timer_adptr_sz,
     100                 :          0 :                         sizeof(uint64_t) * dev->tim_adptr_ring_cnt, 0);
     101                 :            : 
     102         [ #  # ]:          0 :                 if (dev->timer_adptr_sz == NULL) {
     103                 :          0 :                         dev->adptr_xae_cnt += timr->nb_timers;
     104                 :          0 :                         dev->timer_adptr_sz = old_sz_ptr;
     105                 :          0 :                         dev->tim_adptr_ring_cnt--;
     106                 :          0 :                         return;
     107                 :            :                 }
     108                 :            : 
     109                 :          0 :                 dev->timer_adptr_rings[dev->tim_adptr_ring_cnt - 1] =
     110                 :          0 :                         timr->ring_id;
     111                 :          0 :                 dev->timer_adptr_sz[dev->tim_adptr_ring_cnt - 1] =
     112                 :          0 :                         timr->nb_timers;
     113                 :            : 
     114                 :          0 :                 dev->adptr_xae_cnt += timr->nb_timers;
     115                 :          0 :                 break;
     116                 :            :         }
     117                 :            :         default:
     118                 :            :                 break;
     119                 :            :         }
     120                 :            : }
     121                 :            : 
     122                 :            : static int
     123                 :          0 : cnxk_sso_rxq_enable(struct cnxk_eth_dev *cnxk_eth_dev, uint16_t rq_id,
     124                 :            :                     uint16_t port_id, const struct rte_event *ev,
     125                 :            :                     uint8_t custom_flowid)
     126                 :            : {
     127                 :          0 :         struct roc_nix *nix = &cnxk_eth_dev->nix;
     128                 :            :         struct roc_nix_rq *rq;
     129                 :            :         uint16_t wqe_skip;
     130                 :            :         int rc;
     131                 :            : 
     132                 :          0 :         rq = &cnxk_eth_dev->rqs[rq_id];
     133                 :          0 :         rq->sso_ena = 1;
     134                 :          0 :         rq->tt = ev->sched_type;
     135                 :          0 :         rq->hwgrp = ev->queue_id;
     136                 :          0 :         rq->flow_tag_width = 20;
     137                 :            :         wqe_skip = RTE_ALIGN_CEIL(sizeof(struct rte_mbuf), ROC_CACHE_LINE_SZ);
     138                 :            :         wqe_skip = wqe_skip / ROC_CACHE_LINE_SZ;
     139                 :          0 :         rq->wqe_skip = wqe_skip;
     140                 :          0 :         rq->tag_mask = (port_id & 0xF) << 20;
     141                 :          0 :         rq->tag_mask |= (((port_id >> 4) & 0xF) | (RTE_EVENT_TYPE_ETHDEV << 4))
     142                 :          0 :                         << 24;
     143                 :            : 
     144         [ #  # ]:          0 :         if (custom_flowid) {
     145                 :          0 :                 rq->flow_tag_width = 0;
     146                 :          0 :                 rq->tag_mask |= ev->flow_id;
     147                 :            :         }
     148                 :            : 
     149                 :          0 :         rc = roc_nix_rq_modify(&cnxk_eth_dev->nix, rq, 0);
     150         [ #  # ]:          0 :         if (rc)
     151                 :            :                 return rc;
     152                 :            : 
     153   [ #  #  #  # ]:          0 :         if (rq_id == 0 && roc_nix_inl_inb_is_enabled(nix)) {
     154                 :            :                 uint32_t sec_tag_const;
     155                 :            : 
     156                 :            :                 /* IPSec tag const is 8-bit left shifted value of tag_mask
     157                 :            :                  * as it applies to bit 32:8 of tag only.
     158                 :            :                  */
     159                 :          0 :                 sec_tag_const = rq->tag_mask >> 8;
     160                 :          0 :                 rc = roc_nix_inl_inb_tag_update(nix, sec_tag_const,
     161                 :          0 :                                                 ev->sched_type);
     162         [ #  # ]:          0 :                 if (rc)
     163                 :          0 :                         plt_err("Failed to set tag conf for ipsec, rc=%d", rc);
     164                 :            :         }
     165                 :            : 
     166                 :            :         return rc;
     167                 :            : }
     168                 :            : 
     169                 :            : static int
     170                 :            : cnxk_sso_rxq_disable(struct cnxk_eth_dev *cnxk_eth_dev, uint16_t rq_id)
     171                 :            : {
     172                 :            :         struct roc_nix_rq *rq;
     173                 :            : 
     174                 :          0 :         rq = &cnxk_eth_dev->rqs[rq_id];
     175                 :          0 :         rq->sso_ena = 0;
     176                 :          0 :         rq->flow_tag_width = 32;
     177                 :          0 :         rq->tag_mask = 0;
     178                 :            : 
     179                 :          0 :         return roc_nix_rq_modify(&cnxk_eth_dev->nix, rq, 0);
     180                 :            : }
     181                 :            : 
     182                 :            : static int
     183                 :          0 : cnxk_sso_rx_adapter_vwqe_enable(struct cnxk_eth_dev *cnxk_eth_dev,
     184                 :            :                                 uint16_t port_id, uint16_t rq_id, uint16_t sz,
     185                 :            :                                 uint64_t tmo_ns, struct rte_mempool *vmp)
     186                 :            : {
     187                 :            :         struct roc_nix_rq *rq;
     188                 :            : 
     189                 :          0 :         rq = &cnxk_eth_dev->rqs[rq_id];
     190                 :            : 
     191         [ #  # ]:          0 :         if (!rq->sso_ena)
     192                 :            :                 return -EINVAL;
     193         [ #  # ]:          0 :         if (rq->flow_tag_width == 0)
     194                 :            :                 return -EINVAL;
     195                 :            : 
     196                 :          0 :         rq->vwqe_ena = 1;
     197                 :          0 :         rq->vwqe_first_skip = 0;
     198                 :          0 :         rq->vwqe_aura_handle = vmp->pool_id;
     199         [ #  # ]:          0 :         rq->vwqe_max_sz_exp = rte_log2_u32(sz);
     200                 :          0 :         rq->vwqe_wait_tmo =
     201                 :          0 :                 tmo_ns /
     202                 :          0 :                 ((roc_nix_get_vwqe_interval(&cnxk_eth_dev->nix) + 1) * 100);
     203                 :          0 :         rq->tag_mask = (port_id & 0xF) << 20;
     204                 :          0 :         rq->tag_mask |=
     205                 :            :                 (((port_id >> 4) & 0xF) | (RTE_EVENT_TYPE_ETHDEV_VECTOR << 4))
     206                 :          0 :                 << 24;
     207                 :            : 
     208                 :          0 :         return roc_nix_rq_modify(&cnxk_eth_dev->nix, rq, 0);
     209                 :            : }
     210                 :            : 
     211                 :            : static void
     212                 :            : cnxk_sso_tstamp_cfg(uint16_t port_id, struct cnxk_eth_dev *cnxk_eth_dev,
     213                 :            :                     struct cnxk_sso_evdev *dev)
     214                 :            : {
     215                 :          0 :         if (cnxk_eth_dev->rx_offloads & RTE_ETH_RX_OFFLOAD_TIMESTAMP)
     216                 :          0 :                 dev->tstamp[port_id] = &cnxk_eth_dev->tstamp;
     217                 :            : }
     218                 :            : 
     219                 :            : int
     220                 :          0 : cnxk_sso_rx_adapter_queue_add(
     221                 :            :         const struct rte_eventdev *event_dev, const struct rte_eth_dev *eth_dev,
     222                 :            :         int32_t rx_queue_id,
     223                 :            :         const struct rte_event_eth_rx_adapter_queue_conf *queue_conf)
     224                 :            : {
     225         [ #  # ]:          0 :         struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
     226                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     227                 :          0 :         uint16_t port = eth_dev->data->port_id;
     228                 :            :         struct cnxk_eth_rxq_sp *rxq_sp;
     229                 :            :         int i, rc = 0;
     230                 :            : 
     231         [ #  # ]:          0 :         if (rx_queue_id < 0) {
     232         [ #  # ]:          0 :                 for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
     233                 :          0 :                         rc |= cnxk_sso_rx_adapter_queue_add(event_dev, eth_dev,
     234                 :            :                                                             i, queue_conf);
     235                 :            :         } else {
     236                 :          0 :                 rxq_sp = cnxk_eth_rxq_to_sp(
     237                 :          0 :                         eth_dev->data->rx_queues[rx_queue_id]);
     238                 :          0 :                 cnxk_sso_updt_xae_cnt(dev, rxq_sp, RTE_EVENT_TYPE_ETHDEV);
     239                 :          0 :                 rc = cnxk_sso_xae_reconfigure(
     240                 :            :                         (struct rte_eventdev *)(uintptr_t)event_dev);
     241                 :          0 :                 rc |= cnxk_sso_rxq_enable(
     242                 :            :                         cnxk_eth_dev, (uint16_t)rx_queue_id, port,
     243                 :            :                         &queue_conf->ev,
     244                 :          0 :                         !!(queue_conf->rx_queue_flags &
     245                 :            :                            RTE_EVENT_ETH_RX_ADAPTER_QUEUE_FLOW_ID_VALID));
     246         [ #  # ]:          0 :                 if (queue_conf->rx_queue_flags &
     247                 :            :                     RTE_EVENT_ETH_RX_ADAPTER_QUEUE_EVENT_VECTOR) {
     248                 :          0 :                         cnxk_sso_updt_xae_cnt(dev, queue_conf->vector_mp,
     249                 :            :                                               RTE_EVENT_TYPE_ETHDEV_VECTOR);
     250                 :          0 :                         rc |= cnxk_sso_xae_reconfigure(
     251                 :            :                                 (struct rte_eventdev *)(uintptr_t)event_dev);
     252                 :          0 :                         rc |= cnxk_sso_rx_adapter_vwqe_enable(
     253                 :            :                                 cnxk_eth_dev, port, rx_queue_id,
     254                 :          0 :                                 queue_conf->vector_sz,
     255                 :          0 :                                 queue_conf->vector_timeout_ns,
     256                 :          0 :                                 queue_conf->vector_mp);
     257                 :            : 
     258         [ #  # ]:          0 :                         if (cnxk_eth_dev->vec_drop_re_dis)
     259                 :          0 :                                 rc |= roc_nix_rx_drop_re_set(&cnxk_eth_dev->nix,
     260                 :            :                                                              false);
     261                 :            :                 }
     262                 :            : 
     263                 :            :                 /* Propagate force bp devarg */
     264                 :          0 :                 cnxk_eth_dev->nix.force_rx_aura_bp = dev->force_ena_bp;
     265         [ #  # ]:          0 :                 cnxk_sso_tstamp_cfg(eth_dev->data->port_id, cnxk_eth_dev, dev);
     266                 :          0 :                 cnxk_eth_dev->nb_rxq_sso++;
     267                 :            :         }
     268                 :            : 
     269         [ #  # ]:          0 :         if (rc < 0) {
     270                 :          0 :                 plt_err("Failed to configure Rx adapter port=%d, q=%d", port,
     271                 :            :                         queue_conf->ev.queue_id);
     272                 :          0 :                 return rc;
     273                 :            :         }
     274                 :            : 
     275                 :          0 :         dev->rx_offloads |= cnxk_eth_dev->rx_offload_flags;
     276                 :          0 :         return 0;
     277                 :            : }
     278                 :            : 
     279                 :            : int
     280                 :          0 : cnxk_sso_rx_adapter_queue_del(const struct rte_eventdev *event_dev,
     281                 :            :                               const struct rte_eth_dev *eth_dev,
     282                 :            :                               int32_t rx_queue_id)
     283                 :            : {
     284                 :          0 :         struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
     285                 :            :         int i, rc = 0;
     286                 :            : 
     287                 :            :         RTE_SET_USED(event_dev);
     288         [ #  # ]:          0 :         if (rx_queue_id < 0) {
     289         [ #  # ]:          0 :                 for (i = 0; i < eth_dev->data->nb_rx_queues; i++)
     290                 :          0 :                         cnxk_sso_rx_adapter_queue_del(event_dev, eth_dev, i);
     291                 :            :         } else {
     292                 :          0 :                 rc = cnxk_sso_rxq_disable(cnxk_eth_dev, (uint16_t)rx_queue_id);
     293                 :          0 :                 cnxk_eth_dev->nb_rxq_sso--;
     294                 :            : 
     295                 :            :                 /* Enable drop_re if it was disabled earlier */
     296   [ #  #  #  # ]:          0 :                 if (cnxk_eth_dev->vec_drop_re_dis && !cnxk_eth_dev->nb_rxq_sso)
     297                 :          0 :                         rc |= roc_nix_rx_drop_re_set(&cnxk_eth_dev->nix, true);
     298                 :            :         }
     299                 :            : 
     300         [ #  # ]:          0 :         if (rc < 0)
     301                 :          0 :                 plt_err("Failed to clear Rx adapter config port=%d, q=%d",
     302                 :            :                         eth_dev->data->port_id, rx_queue_id);
     303                 :          0 :         return rc;
     304                 :            : }
     305                 :            : 
     306                 :            : int
     307                 :          0 : cnxk_sso_rx_adapter_start(const struct rte_eventdev *event_dev,
     308                 :            :                           const struct rte_eth_dev *eth_dev)
     309                 :            : {
     310                 :          0 :         struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
     311                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     312                 :          0 :         dev->rx_offloads |= cnxk_eth_dev->rx_offload_flags;
     313                 :          0 :         return 0;
     314                 :            : }
     315                 :            : 
     316                 :            : int
     317                 :          0 : cnxk_sso_rx_adapter_stop(const struct rte_eventdev *event_dev,
     318                 :            :                          const struct rte_eth_dev *eth_dev)
     319                 :            : {
     320                 :            :         RTE_SET_USED(eth_dev);
     321                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     322                 :          0 :         dev->rx_offloads = 0;
     323                 :          0 :         return 0;
     324                 :            : }
     325                 :            : 
     326                 :            : static int
     327                 :          0 : cnxk_sso_sqb_aura_limit_edit(struct roc_nix_sq *sq, uint16_t nb_sqb_bufs)
     328                 :            : {
     329                 :            :         int rc;
     330                 :            : 
     331         [ #  # ]:          0 :         if (sq->aura_sqb_bufs != nb_sqb_bufs) {
     332                 :          0 :                 rc = roc_npa_aura_limit_modify(
     333                 :            :                         sq->aura_handle,
     334                 :          0 :                         RTE_MIN(nb_sqb_bufs, sq->aura_sqb_bufs));
     335         [ #  # ]:          0 :                 if (rc < 0)
     336                 :            :                         return rc;
     337                 :            : 
     338                 :          0 :                 sq->nb_sqb_bufs = RTE_MIN(nb_sqb_bufs, sq->aura_sqb_bufs) -
     339                 :          0 :                                   sq->roc_nix->sqb_slack;
     340                 :            :         }
     341                 :            :         return 0;
     342                 :            : }
     343                 :            : 
     344                 :            : static void
     345                 :          0 : cnxk_sso_tx_queue_data_init(struct cnxk_sso_evdev *dev, uint64_t *txq_data,
     346                 :            :                             uint16_t eth_port_id, uint16_t tx_queue_id)
     347                 :            : {
     348                 :            :         uint64_t offset = 0;
     349                 :            :         int i;
     350                 :            : 
     351                 :          0 :         dev->max_queue_id[0] = RTE_MAX(dev->max_queue_id[0], eth_port_id);
     352         [ #  # ]:          0 :         for (i = 1; i < eth_port_id; i++) {
     353                 :          0 :                 offset += (dev->max_queue_id[i - 1] + 1);
     354                 :          0 :                 txq_data[i] |= offset << 48;
     355                 :            :         }
     356                 :          0 :         dev->max_port_id = RTE_MAX(dev->max_port_id, eth_port_id);
     357                 :          0 :         dev->max_queue_id[eth_port_id] =
     358                 :          0 :                 RTE_MAX(dev->max_queue_id[eth_port_id], tx_queue_id);
     359                 :          0 : }
     360                 :            : 
     361                 :            : static void
     362                 :          0 : cnxk_sso_tx_queue_data_cpy(struct cnxk_sso_evdev *dev, uint64_t *txq_data,
     363                 :            :                            uint64_t *otxq_data, uint16_t eth_port_id)
     364                 :            : {
     365                 :            :         uint64_t offset = 0;
     366                 :            :         int i, j;
     367                 :            : 
     368         [ #  # ]:          0 :         for (i = 1; i < eth_port_id; i++) {
     369                 :          0 :                 offset += (dev->max_queue_id[i - 1] + 1);
     370                 :          0 :                 txq_data[i] |= offset << 48;
     371                 :          0 :                 for (j = 0;
     372   [ #  #  #  # ]:          0 :                      (i < dev->max_port_id) && (j < dev->max_queue_id[i] + 1);
     373                 :          0 :                      j++)
     374                 :          0 :                         txq_data[offset + j] =
     375                 :          0 :                                 otxq_data[(otxq_data[i] >> 48) + j];
     376                 :            :         }
     377                 :          0 : }
     378                 :            : 
     379                 :            : static void
     380                 :          0 : cnxk_sso_tx_queue_data_cpy_max(struct cnxk_sso_evdev *dev, uint64_t *txq_data,
     381                 :            :                                uint64_t *otxq_data, uint16_t eth_port_id,
     382                 :            :                                uint16_t max_port_id, uint16_t max_queue_id)
     383                 :            : {
     384                 :            :         uint64_t offset = 0;
     385                 :            :         int i, j;
     386                 :            : 
     387         [ #  # ]:          0 :         for (i = 1; i < max_port_id + 1; i++) {
     388                 :          0 :                 offset += (dev->max_queue_id[i - 1] + 1);
     389                 :          0 :                 txq_data[i] |= offset << 48;
     390         [ #  # ]:          0 :                 for (j = 0; j < dev->max_queue_id[i] + 1; j++) {
     391   [ #  #  #  # ]:          0 :                         if (i == eth_port_id && j > max_queue_id)
     392                 :          0 :                                 continue;
     393                 :          0 :                         txq_data[offset + j] =
     394                 :          0 :                                 otxq_data[(otxq_data[i] >> 48) + j];
     395                 :            :                 }
     396                 :            :         }
     397                 :          0 : }
     398                 :            : 
     399                 :            : static void
     400                 :          0 : cnxk_sso_tx_queue_data_rewrite(struct cnxk_sso_evdev *dev, uint64_t *txq_data,
     401                 :            :                                uint16_t eth_port_id, uint16_t tx_queue_id,
     402                 :            :                                uint64_t *otxq_data, uint16_t max_port_id,
     403                 :            :                                uint16_t max_queue_id)
     404                 :            : {
     405                 :            :         int i;
     406                 :            : 
     407         [ #  # ]:          0 :         for (i = 0; i < dev->max_queue_id[0] + 1; i++)
     408                 :          0 :                 txq_data[i] |= (otxq_data[i] & ~((BIT_ULL(16) - 1) << 48));
     409                 :            : 
     410         [ #  # ]:          0 :         if (eth_port_id > max_port_id) {
     411                 :          0 :                 dev->max_queue_id[0] =
     412                 :          0 :                         RTE_MAX(dev->max_queue_id[0], eth_port_id);
     413                 :          0 :                 dev->max_port_id = RTE_MAX(dev->max_port_id, eth_port_id);
     414                 :            : 
     415                 :          0 :                 cnxk_sso_tx_queue_data_cpy(dev, txq_data, otxq_data,
     416                 :            :                                            eth_port_id);
     417                 :          0 :                 dev->max_queue_id[eth_port_id] =
     418                 :          0 :                         RTE_MAX(dev->max_queue_id[eth_port_id], tx_queue_id);
     419         [ #  # ]:          0 :         } else if (tx_queue_id > max_queue_id) {
     420                 :          0 :                 dev->max_queue_id[eth_port_id] =
     421                 :          0 :                         RTE_MAX(dev->max_queue_id[eth_port_id], tx_queue_id);
     422                 :          0 :                 dev->max_port_id = RTE_MAX(max_port_id, eth_port_id);
     423                 :          0 :                 cnxk_sso_tx_queue_data_cpy_max(dev, txq_data, otxq_data,
     424                 :            :                                                eth_port_id, max_port_id,
     425                 :            :                                                max_queue_id);
     426                 :            :         }
     427                 :          0 : }
     428                 :            : 
     429                 :            : static void
     430                 :          0 : cnxk_sso_tx_queue_data_sz(struct cnxk_sso_evdev *dev, uint16_t eth_port_id,
     431                 :            :                           uint16_t tx_queue_id, uint16_t max_port_id,
     432                 :            :                           uint16_t max_queue_id, uint64_t *r, size_t *sz)
     433                 :            : {
     434                 :            :         uint64_t row = 0;
     435                 :            :         size_t size = 0;
     436                 :            :         int i;
     437                 :            : 
     438         [ #  # ]:          0 :         if (dev->tx_adptr_data == NULL) {
     439                 :          0 :                 size = (eth_port_id + 1);
     440                 :          0 :                 size += (eth_port_id + tx_queue_id);
     441                 :          0 :                 row = 2 * eth_port_id;
     442                 :          0 :                 *r = row;
     443                 :          0 :                 *sz = size;
     444                 :          0 :                 return;
     445                 :            :         }
     446                 :            : 
     447         [ #  # ]:          0 :         if (eth_port_id > max_port_id) {
     448                 :          0 :                 size = (RTE_MAX(eth_port_id, dev->max_queue_id[0]) + 1);
     449         [ #  # ]:          0 :                 for (i = 1; i < eth_port_id; i++)
     450                 :          0 :                         size += (dev->max_queue_id[i] + 1);
     451                 :            :                 row = size;
     452                 :          0 :                 size += (tx_queue_id + 1);
     453         [ #  # ]:          0 :         } else if (tx_queue_id > max_queue_id) {
     454                 :            :                 size = !eth_port_id ?
     455         [ #  # ]:          0 :                                tx_queue_id + 1 :
     456                 :          0 :                                      RTE_MAX(max_port_id, dev->max_queue_id[0]) + 1;
     457         [ #  # ]:          0 :                 for (i = 1; i < max_port_id + 1; i++) {
     458         [ #  # ]:          0 :                         if (i == eth_port_id) {
     459                 :            :                                 row = size;
     460                 :          0 :                                 size += tx_queue_id + 1;
     461                 :            :                         } else {
     462                 :          0 :                                 size += dev->max_queue_id[i] + 1;
     463                 :            :                         }
     464                 :            :                 }
     465                 :            :         }
     466                 :          0 :         *r = row;
     467                 :          0 :         *sz = size;
     468                 :            : }
     469                 :            : 
     470                 :            : static int
     471         [ #  # ]:          0 : cnxk_sso_updt_tx_queue_data(const struct rte_eventdev *event_dev,
     472                 :            :                             uint16_t eth_port_id, uint16_t tx_queue_id,
     473                 :            :                             void *txq)
     474                 :            : {
     475                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     476                 :          0 :         uint16_t max_queue_id = dev->max_queue_id[eth_port_id];
     477                 :          0 :         uint16_t max_port_id = dev->max_port_id;
     478                 :            :         uint64_t *txq_data = NULL;
     479                 :          0 :         uint64_t row = 0;
     480                 :          0 :         size_t size = 0;
     481                 :            : 
     482         [ #  # ]:          0 :         if (((uint64_t)txq) & 0xFFFF000000000000)
     483                 :            :                 return -EINVAL;
     484                 :            : 
     485                 :          0 :         cnxk_sso_tx_queue_data_sz(dev, eth_port_id, tx_queue_id, max_port_id,
     486                 :            :                                   max_queue_id, &row, &size);
     487                 :            : 
     488                 :          0 :         size *= sizeof(uint64_t);
     489                 :            : 
     490         [ #  # ]:          0 :         if (size) {
     491                 :          0 :                 uint64_t *otxq_data = dev->tx_adptr_data;
     492                 :            : 
     493                 :          0 :                 txq_data = malloc(size);
     494         [ #  # ]:          0 :                 if (txq_data == NULL)
     495                 :            :                         return -ENOMEM;
     496                 :            :                 memset(txq_data, 0, size);
     497                 :          0 :                 txq_data[eth_port_id] = ((uint64_t)row) << 48;
     498                 :          0 :                 txq_data[row + tx_queue_id] = (uint64_t)txq;
     499                 :            : 
     500         [ #  # ]:          0 :                 if (otxq_data != NULL)
     501                 :          0 :                         cnxk_sso_tx_queue_data_rewrite(
     502                 :            :                                 dev, txq_data, eth_port_id, tx_queue_id,
     503                 :            :                                 otxq_data, max_port_id, max_queue_id);
     504                 :            :                 else
     505                 :          0 :                         cnxk_sso_tx_queue_data_init(dev, txq_data, eth_port_id,
     506                 :            :                                                     tx_queue_id);
     507                 :          0 :                 dev->tx_adptr_data_sz = size;
     508                 :          0 :                 free(otxq_data);
     509                 :          0 :                 dev->tx_adptr_data = txq_data;
     510                 :            :         } else {
     511                 :          0 :                 txq_data = dev->tx_adptr_data;
     512                 :          0 :                 row = txq_data[eth_port_id] >> 48;
     513                 :          0 :                 txq_data[row + tx_queue_id] &= ~(BIT_ULL(48) - 1);
     514                 :          0 :                 txq_data[row + tx_queue_id] |= (uint64_t)txq;
     515                 :            :         }
     516                 :            : 
     517                 :            :         return 0;
     518                 :            : }
     519                 :            : 
     520                 :            : int
     521                 :          0 : cnxk_sso_tx_adapter_queue_add(const struct rte_eventdev *event_dev,
     522                 :            :                               const struct rte_eth_dev *eth_dev,
     523                 :            :                               int32_t tx_queue_id)
     524                 :            : {
     525                 :          0 :         struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
     526                 :            :         struct roc_nix_sq *sq;
     527                 :            :         int i, ret = 0;
     528                 :            :         void *txq;
     529                 :            : 
     530         [ #  # ]:          0 :         if (tx_queue_id < 0) {
     531         [ #  # ]:          0 :                 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
     532                 :          0 :                         ret |= cnxk_sso_tx_adapter_queue_add(event_dev, eth_dev,
     533                 :            :                                                              i);
     534                 :            :         } else {
     535                 :          0 :                 txq = eth_dev->data->tx_queues[tx_queue_id];
     536                 :          0 :                 sq = &cnxk_eth_dev->sqs[tx_queue_id];
     537                 :          0 :                 cnxk_sso_sqb_aura_limit_edit(sq, sq->aura_sqb_bufs);
     538                 :          0 :                 ret = cnxk_sso_updt_tx_queue_data(
     539                 :          0 :                         event_dev, eth_dev->data->port_id, tx_queue_id, txq);
     540         [ #  # ]:          0 :                 if (ret < 0)
     541                 :            :                         return ret;
     542                 :            :         }
     543                 :            : 
     544         [ #  # ]:          0 :         if (ret < 0) {
     545                 :          0 :                 plt_err("Failed to configure Tx adapter port=%d, q=%d",
     546                 :            :                         eth_dev->data->port_id, tx_queue_id);
     547                 :          0 :                 return ret;
     548                 :            :         }
     549                 :            : 
     550                 :            :         return 0;
     551                 :            : }
     552                 :            : 
     553                 :            : int
     554                 :          0 : cnxk_sso_tx_adapter_queue_del(const struct rte_eventdev *event_dev,
     555                 :            :                               const struct rte_eth_dev *eth_dev,
     556                 :            :                               int32_t tx_queue_id)
     557                 :            : {
     558                 :          0 :         struct cnxk_eth_dev *cnxk_eth_dev = eth_dev->data->dev_private;
     559                 :            :         struct roc_nix_sq *sq;
     560                 :            :         int i, ret = 0;
     561                 :            : 
     562                 :            :         RTE_SET_USED(event_dev);
     563         [ #  # ]:          0 :         if (tx_queue_id < 0) {
     564         [ #  # ]:          0 :                 for (i = 0; i < eth_dev->data->nb_tx_queues; i++)
     565                 :          0 :                         ret |= cnxk_sso_tx_adapter_queue_del(event_dev, eth_dev,
     566                 :            :                                                              i);
     567                 :            :         } else {
     568                 :          0 :                 sq = &cnxk_eth_dev->sqs[tx_queue_id];
     569                 :          0 :                 cnxk_sso_sqb_aura_limit_edit(sq, sq->aura_sqb_bufs);
     570                 :          0 :                 ret = cnxk_sso_updt_tx_queue_data(
     571                 :          0 :                         event_dev, eth_dev->data->port_id, tx_queue_id, NULL);
     572         [ #  # ]:          0 :                 if (ret < 0)
     573                 :            :                         return ret;
     574                 :            :         }
     575                 :            : 
     576         [ #  # ]:          0 :         if (ret < 0) {
     577                 :          0 :                 plt_err("Failed to clear Tx adapter config port=%d, q=%d",
     578                 :            :                         eth_dev->data->port_id, tx_queue_id);
     579                 :          0 :                 return ret;
     580                 :            :         }
     581                 :            : 
     582                 :            :         return 0;
     583                 :            : }
     584                 :            : 
     585                 :            : int
     586                 :          0 : cnxk_sso_tx_adapter_start(uint8_t id, const struct rte_eventdev *event_dev)
     587                 :            : {
     588                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     589                 :            : 
     590                 :          0 :         dev->tx_adptr_active_mask |= (1 << id);
     591                 :            : 
     592                 :          0 :         return 0;
     593                 :            : }
     594                 :            : 
     595                 :            : int
     596                 :          0 : cnxk_sso_tx_adapter_stop(uint8_t id, const struct rte_eventdev *event_dev)
     597                 :            : {
     598                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     599                 :            : 
     600                 :          0 :         dev->tx_adptr_active_mask &= ~(1 << id);
     601                 :            : 
     602                 :          0 :         return 0;
     603                 :            : }
     604                 :            : 
     605                 :            : int
     606         [ #  # ]:          0 : cnxk_sso_tx_adapter_free(uint8_t id __rte_unused,
     607                 :            :                          const struct rte_eventdev *event_dev)
     608                 :            : {
     609                 :            :         struct cnxk_sso_evdev *dev = cnxk_sso_pmd_priv(event_dev);
     610                 :            : 
     611   [ #  #  #  # ]:          0 :         if (dev->tx_adptr_data_sz && dev->tx_adptr_active_mask == 0) {
     612                 :          0 :                 dev->tx_adptr_data_sz = 0;
     613                 :          0 :                 free(dev->tx_adptr_data);
     614                 :          0 :                 dev->tx_adptr_data = NULL;
     615                 :            :         }
     616                 :            : 
     617                 :          0 :         return 0;
     618                 :            : }
     619                 :            : 
     620                 :            : static int
     621         [ #  # ]:          0 : crypto_adapter_qp_setup(const struct rte_cryptodev *cdev, struct cnxk_cpt_qp *qp,
     622                 :            :                         const struct rte_event_crypto_adapter_queue_conf *conf)
     623                 :            : {
     624                 :            :         char name[RTE_MEMPOOL_NAMESIZE];
     625                 :            :         uint32_t cache_size, nb_req;
     626                 :            :         unsigned int req_size;
     627                 :            :         uint32_t nb_desc_min;
     628                 :            : 
     629                 :            :         /*
     630                 :            :          * Update CPT FC threshold. Decrement by hardware burst size to allow
     631                 :            :          * simultaneous enqueue from all available cores.
     632                 :            :          */
     633         [ #  # ]:          0 :         if (roc_model_is_cn10k())
     634                 :          0 :                 nb_desc_min = rte_lcore_count() * 32;
     635                 :            :         else
     636                 :          0 :                 nb_desc_min = rte_lcore_count() * 2;
     637                 :            : 
     638         [ #  # ]:          0 :         if (qp->lmtline.fc_thresh < nb_desc_min) {
     639                 :          0 :                 plt_err("CPT queue depth not sufficient to allow enqueueing from %d cores",
     640                 :            :                         rte_lcore_count());
     641                 :          0 :                 return -ENOSPC;
     642                 :            :         }
     643                 :            : 
     644                 :          0 :         qp->lmtline.fc_thresh -= nb_desc_min;
     645                 :            : 
     646         [ #  # ]:          0 :         snprintf(name, RTE_MEMPOOL_NAMESIZE, "cnxk_ca_req_%u:%u", cdev->data->dev_id, qp->lf.lf_id);
     647                 :            :         req_size = sizeof(struct cpt_inflight_req);
     648         [ #  # ]:          0 :         cache_size = RTE_MIN(RTE_MEMPOOL_CACHE_MAX_SIZE, qp->lf.nb_desc / 1.5);
     649                 :          0 :         nb_req = RTE_MAX(qp->lf.nb_desc, cache_size * rte_lcore_count());
     650                 :          0 :         qp->ca.req_mp = rte_mempool_create(name, nb_req, req_size, cache_size, 0, NULL, NULL, NULL,
     651                 :          0 :                                            NULL, rte_socket_id(), 0);
     652         [ #  # ]:          0 :         if (qp->ca.req_mp == NULL)
     653                 :            :                 return -ENOMEM;
     654                 :            : 
     655         [ #  # ]:          0 :         if (conf != NULL) {
     656                 :          0 :                 qp->ca.vector_sz = conf->vector_sz;
     657                 :          0 :                 qp->ca.vector_mp = conf->vector_mp;
     658                 :            :         }
     659                 :          0 :         qp->ca.enabled = true;
     660                 :            : 
     661                 :          0 :         return 0;
     662                 :            : }
     663                 :            : 
     664                 :            : int
     665         [ #  # ]:          0 : cnxk_crypto_adapter_qp_add(const struct rte_eventdev *event_dev, const struct rte_cryptodev *cdev,
     666                 :            :                            int32_t queue_pair_id,
     667                 :            :                            const struct rte_event_crypto_adapter_queue_conf *conf)
     668                 :            : {
     669                 :            :         struct cnxk_sso_evdev *sso_evdev = cnxk_sso_pmd_priv(event_dev);
     670                 :            :         uint32_t adptr_xae_cnt = 0;
     671                 :            :         struct cnxk_cpt_qp *qp;
     672                 :            :         int ret;
     673                 :            : 
     674         [ #  # ]:          0 :         if (queue_pair_id == -1) {
     675                 :            :                 uint16_t qp_id;
     676                 :            : 
     677         [ #  # ]:          0 :                 for (qp_id = 0; qp_id < cdev->data->nb_queue_pairs; qp_id++) {
     678                 :          0 :                         qp = cdev->data->queue_pairs[qp_id];
     679                 :          0 :                         ret = crypto_adapter_qp_setup(cdev, qp, conf);
     680         [ #  # ]:          0 :                         if (ret) {
     681                 :          0 :                                 cnxk_crypto_adapter_qp_del(cdev, -1);
     682                 :          0 :                                 return ret;
     683                 :            :                         }
     684                 :          0 :                         adptr_xae_cnt += qp->ca.req_mp->size;
     685                 :            :                 }
     686                 :            :         } else {
     687                 :          0 :                 qp = cdev->data->queue_pairs[queue_pair_id];
     688                 :          0 :                 ret = crypto_adapter_qp_setup(cdev, qp, conf);
     689         [ #  # ]:          0 :                 if (ret)
     690                 :            :                         return ret;
     691                 :          0 :                 adptr_xae_cnt = qp->ca.req_mp->size;
     692                 :            :         }
     693                 :            : 
     694                 :            :         /* Update crypto adapter XAE count */
     695                 :          0 :         sso_evdev->adptr_xae_cnt += adptr_xae_cnt;
     696                 :          0 :         cnxk_sso_xae_reconfigure((struct rte_eventdev *)(uintptr_t)event_dev);
     697                 :            : 
     698                 :          0 :         return 0;
     699                 :            : }
     700                 :            : 
     701                 :            : static int
     702                 :          0 : crypto_adapter_qp_free(struct cnxk_cpt_qp *qp)
     703                 :            : {
     704                 :            :         int ret;
     705                 :            : 
     706                 :          0 :         rte_mempool_free(qp->ca.req_mp);
     707                 :          0 :         qp->ca.enabled = false;
     708                 :            : 
     709                 :          0 :         ret = roc_cpt_lmtline_init(qp->lf.roc_cpt, &qp->lmtline, qp->lf.lf_id);
     710         [ #  # ]:          0 :         if (ret < 0) {
     711                 :          0 :                 plt_err("Could not reset lmtline for queue pair %d", qp->lf.lf_id);
     712                 :          0 :                 return ret;
     713                 :            :         }
     714                 :            : 
     715                 :            :         return 0;
     716                 :            : }
     717                 :            : 
     718                 :            : int
     719                 :          0 : cnxk_crypto_adapter_qp_del(const struct rte_cryptodev *cdev,
     720                 :            :                            int32_t queue_pair_id)
     721                 :            : {
     722                 :            :         struct cnxk_cpt_qp *qp;
     723                 :            : 
     724         [ #  # ]:          0 :         if (queue_pair_id == -1) {
     725                 :            :                 uint16_t qp_id;
     726                 :            : 
     727         [ #  # ]:          0 :                 for (qp_id = 0; qp_id < cdev->data->nb_queue_pairs; qp_id++) {
     728                 :          0 :                         qp = cdev->data->queue_pairs[qp_id];
     729         [ #  # ]:          0 :                         if (qp->ca.enabled)
     730                 :          0 :                                 crypto_adapter_qp_free(qp);
     731                 :            :                 }
     732                 :            :         } else {
     733                 :          0 :                 qp = cdev->data->queue_pairs[queue_pair_id];
     734         [ #  # ]:          0 :                 if (qp->ca.enabled)
     735                 :          0 :                         crypto_adapter_qp_free(qp);
     736                 :            :         }
     737                 :            : 
     738                 :          0 :         return 0;
     739                 :            : }

Generated by: LCOV version 1.14