LCOV - code coverage report
Current view: top level - drivers/event/cnxk - cnxk_tim_evdev.c (source / functions) Hit Total Coverage
Test: Code coverage Lines: 0 316 0.0 %
Date: 2025-02-01 18:54:23 Functions: 0 19 0.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 0 136 0.0 %

           Branch data     Line data    Source code
       1                 :            : /* SPDX-License-Identifier: BSD-3-Clause
       2                 :            :  * Copyright(C) 2021 Marvell.
       3                 :            :  */
       4                 :            : 
       5                 :            : #include <math.h>
       6                 :            : 
       7                 :            : #include "roc_api.h"
       8                 :            : 
       9                 :            : #include "cnxk_eventdev.h"
      10                 :            : #include "cnxk_tim_evdev.h"
      11                 :            : 
      12                 :            : static struct event_timer_adapter_ops cnxk_tim_ops;
      13                 :            : static cnxk_sso_set_priv_mem_t sso_set_priv_mem_fn;
      14                 :            : 
      15                 :            : static int
      16                 :          0 : cnxk_tim_chnk_pool_create(struct cnxk_tim_ring *tim_ring,
      17                 :            :                           struct rte_event_timer_adapter_conf *rcfg)
      18                 :            : {
      19                 :            :         unsigned int mp_flags = 0;
      20                 :            :         unsigned int cache_sz;
      21                 :            :         char pool_name[25];
      22                 :            :         int rc;
      23                 :            : 
      24                 :            :         /* Create chunk pool. */
      25         [ #  # ]:          0 :         if (rcfg->flags & RTE_EVENT_TIMER_ADAPTER_F_SP_PUT) {
      26                 :            :                 mp_flags = RTE_MEMPOOL_F_SP_PUT | RTE_MEMPOOL_F_SC_GET;
      27                 :          0 :                 plt_tim_dbg("Using single producer mode");
      28                 :          0 :                 tim_ring->prod_type_sp = true;
      29                 :            :         }
      30                 :            : 
      31                 :          0 :         snprintf(pool_name, sizeof(pool_name), "cnxk_tim_chunk_pool%d",
      32                 :          0 :                  tim_ring->ring_id);
      33                 :            : 
      34                 :            :         cache_sz = CNXK_TIM_MAX_POOL_CACHE_SZ;
      35                 :          0 :         tim_ring->nb_chunks += (cache_sz * rte_lcore_count());
      36         [ #  # ]:          0 :         if (!tim_ring->disable_npa) {
      37                 :          0 :                 tim_ring->chunk_pool = rte_mempool_create_empty(
      38                 :          0 :                         pool_name, tim_ring->nb_chunks, tim_ring->chunk_sz,
      39                 :          0 :                         cache_sz, 0, rte_socket_id(), mp_flags);
      40                 :            : 
      41         [ #  # ]:          0 :                 if (tim_ring->chunk_pool == NULL) {
      42                 :          0 :                         plt_err("Unable to create chunkpool.");
      43                 :          0 :                         return -ENOMEM;
      44                 :            :                 }
      45                 :            : 
      46                 :          0 :                 rc = rte_mempool_set_ops_byname(tim_ring->chunk_pool,
      47                 :            :                                                 rte_mbuf_platform_mempool_ops(),
      48                 :            :                                                 NULL);
      49         [ #  # ]:          0 :                 if (rc < 0) {
      50                 :          0 :                         plt_err("Unable to set chunkpool ops");
      51                 :          0 :                         goto free;
      52                 :            :                 }
      53                 :            : 
      54                 :          0 :                 rc = rte_mempool_populate_default(tim_ring->chunk_pool);
      55         [ #  # ]:          0 :                 if (rc < 0) {
      56                 :          0 :                         plt_err("Unable to set populate chunkpool.");
      57                 :          0 :                         goto free;
      58                 :            :                 }
      59                 :          0 :                 tim_ring->aura = roc_npa_aura_handle_to_aura(
      60                 :          0 :                         tim_ring->chunk_pool->pool_id);
      61                 :          0 :                 tim_ring->ena_dfb = tim_ring->ena_periodic ? 1 : 0;
      62                 :            :         } else {
      63                 :          0 :                 tim_ring->chunk_pool = rte_mempool_create(
      64                 :          0 :                         pool_name, tim_ring->nb_chunks, tim_ring->chunk_sz,
      65                 :          0 :                         cache_sz, 0, NULL, NULL, NULL, NULL, rte_socket_id(),
      66                 :            :                         mp_flags);
      67         [ #  # ]:          0 :                 if (tim_ring->chunk_pool == NULL) {
      68                 :          0 :                         plt_err("Unable to create chunkpool.");
      69                 :          0 :                         return -ENOMEM;
      70                 :            :                 }
      71                 :          0 :                 tim_ring->ena_dfb = 1;
      72                 :            :         }
      73                 :            : 
      74                 :            :         return 0;
      75                 :            : 
      76                 :          0 : free:
      77                 :          0 :         rte_mempool_free(tim_ring->chunk_pool);
      78                 :          0 :         return rc;
      79                 :            : }
      80                 :            : 
      81                 :            : static int
      82                 :          0 : cnxk_tim_enable_hwwqe(struct cnxk_tim_evdev *dev, struct cnxk_tim_ring *tim_ring)
      83                 :            : {
      84                 :            :         struct roc_tim_hwwqe_cfg hwwqe_cfg;
      85                 :            : 
      86                 :            :         memset(&hwwqe_cfg, 0, sizeof(hwwqe_cfg));
      87                 :          0 :         hwwqe_cfg.hwwqe_ena = 1;
      88                 :            :         hwwqe_cfg.grp_ena = 0;
      89                 :            :         hwwqe_cfg.flw_ctrl_ena = 0;
      90                 :          0 :         hwwqe_cfg.result_offset = CNXK_TIM_HWWQE_RES_OFFSET_B;
      91                 :            : 
      92                 :          0 :         tim_ring->lmt_base = dev->tim.roc_sso->lmt_base;
      93                 :          0 :         return roc_tim_lf_config_hwwqe(&dev->tim, tim_ring->ring_id, &hwwqe_cfg);
      94                 :            : }
      95                 :            : 
      96                 :            : static void
      97                 :          0 : cnxk_tim_set_fp_ops(struct cnxk_tim_ring *tim_ring)
      98                 :            : {
      99                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     100                 :          0 :         uint8_t prod_flag = !tim_ring->prod_type_sp;
     101                 :            : 
     102                 :            :         /* [STATS] [DFB/FB] [SP][MP]*/
     103                 :          0 :         const rte_event_timer_arm_burst_t arm_burst[2][2][2] = {
     104                 :            : #define FP(_name, _f3, _f2, _f1, flags)                                        \
     105                 :            :         [_f3][_f2][_f1] = cnxk_tim_arm_burst_##_name,
     106                 :            :                 TIM_ARM_FASTPATH_MODES
     107                 :            : #undef FP
     108                 :            :         };
     109                 :            : 
     110                 :          0 :         const rte_event_timer_arm_tmo_tick_burst_t arm_tmo_burst[2][2] = {
     111                 :            : #define FP(_name, _f2, _f1, flags)                                             \
     112                 :            :         [_f2][_f1] = cnxk_tim_arm_tmo_tick_burst_##_name,
     113                 :            :                 TIM_ARM_TMO_FASTPATH_MODES
     114                 :            : #undef FP
     115                 :            :         };
     116                 :            : 
     117         [ #  # ]:          0 :         if (dev == NULL)
     118                 :          0 :                 return;
     119                 :            : 
     120         [ #  # ]:          0 :         if (dev->tim.feat.hwwqe) {
     121                 :          0 :                 cnxk_tim_ops.arm_burst = cnxk_tim_arm_burst_hwwqe;
     122                 :          0 :                 cnxk_tim_ops.arm_tmo_tick_burst = cnxk_tim_arm_tmo_burst_hwwqe;
     123                 :          0 :                 cnxk_tim_ops.cancel_burst = cnxk_tim_timer_cancel_burst_hwwqe;
     124                 :          0 :                 return;
     125                 :            :         }
     126                 :            : 
     127                 :          0 :         cnxk_tim_ops.arm_burst =
     128                 :          0 :                 arm_burst[tim_ring->enable_stats][tim_ring->ena_dfb][prod_flag];
     129                 :          0 :         cnxk_tim_ops.arm_tmo_tick_burst =
     130                 :          0 :                 arm_tmo_burst[tim_ring->enable_stats][tim_ring->ena_dfb];
     131                 :          0 :         cnxk_tim_ops.cancel_burst = cnxk_tim_timer_cancel_burst;
     132                 :            : }
     133                 :            : 
     134                 :            : static void
     135                 :          0 : cnxk_tim_ring_info_get(const struct rte_event_timer_adapter *adptr,
     136                 :            :                        struct rte_event_timer_adapter_info *adptr_info)
     137                 :            : {
     138                 :          0 :         struct cnxk_tim_ring *tim_ring = adptr->data->adapter_priv;
     139                 :            : 
     140                 :          0 :         adptr_info->max_tmo_ns = tim_ring->max_tout;
     141                 :          0 :         adptr_info->min_resolution_ns = tim_ring->ena_periodic ?
     142         [ #  # ]:          0 :                                                 tim_ring->max_tout :
     143                 :            :                                                 tim_ring->tck_nsec;
     144         [ #  # ]:          0 :         rte_memcpy(&adptr_info->conf, &adptr->data->conf,
     145                 :            :                    sizeof(struct rte_event_timer_adapter_conf));
     146                 :          0 : }
     147                 :            : 
     148                 :            : static int
     149                 :          0 : cnxk_tim_ring_create(struct rte_event_timer_adapter *adptr)
     150                 :            : {
     151                 :          0 :         struct rte_event_timer_adapter_conf *rcfg = &adptr->data->conf;
     152                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     153                 :            :         uint64_t min_intvl_ns, min_intvl_cyc;
     154                 :            :         struct cnxk_tim_ring *tim_ring;
     155                 :            :         enum roc_tim_clk_src clk_src;
     156                 :            :         uint64_t clk_freq = 0;
     157                 :            :         int i, rc;
     158                 :            : 
     159         [ #  # ]:          0 :         if (dev == NULL)
     160                 :            :                 return -ENODEV;
     161                 :            : 
     162         [ #  # ]:          0 :         if (adptr->data->id >= dev->nb_rings)
     163                 :            :                 return -ENODEV;
     164                 :            : 
     165                 :          0 :         tim_ring = rte_zmalloc("cnxk_tim_prv", sizeof(struct cnxk_tim_ring), 0);
     166         [ #  # ]:          0 :         if (tim_ring == NULL)
     167                 :            :                 return -ENOMEM;
     168                 :            : 
     169                 :          0 :         rc = roc_tim_lf_alloc(&dev->tim, adptr->data->id, NULL);
     170         [ #  # ]:          0 :         if (rc < 0) {
     171                 :          0 :                 plt_err("Failed to create timer ring");
     172                 :          0 :                 goto tim_ring_free;
     173                 :            :         }
     174                 :            : 
     175         [ #  # ]:          0 :         clk_src = cnxk_tim_convert_clk_src(rcfg->clk_src);
     176         [ #  # ]:          0 :         if (clk_src == ROC_TIM_CLK_SRC_INVALID) {
     177                 :          0 :                 plt_err("Invalid clock source");
     178                 :          0 :                 goto tim_hw_free;
     179                 :            :         }
     180                 :            : 
     181                 :            :         rc = cnxk_tim_get_clk_freq(dev, clk_src, &clk_freq);
     182                 :            :         if (rc < 0) {
     183                 :          0 :                 plt_err("Failed to get clock frequency");
     184                 :          0 :                 goto tim_hw_free;
     185                 :            :         }
     186                 :            : 
     187                 :          0 :         rc = roc_tim_lf_interval(&dev->tim, clk_src, clk_freq, &min_intvl_ns,
     188                 :            :                                  &min_intvl_cyc);
     189         [ #  # ]:          0 :         if (rc < 0) {
     190                 :          0 :                 plt_err("Failed to get min interval details");
     191                 :          0 :                 goto tim_hw_free;
     192                 :            :         }
     193                 :            : 
     194         [ #  # ]:          0 :         if (rcfg->flags & RTE_EVENT_TIMER_ADAPTER_F_PERIODIC) {
     195                 :            :                 /* Use 2 buckets to avoid contention */
     196                 :          0 :                 rcfg->timer_tick_ns /= 2;
     197                 :          0 :                 tim_ring->ena_periodic = 1;
     198                 :            :         }
     199                 :            : 
     200         [ #  # ]:          0 :         if (rcfg->timer_tick_ns < min_intvl_ns) {
     201         [ #  # ]:          0 :                 if (rcfg->flags & RTE_EVENT_TIMER_ADAPTER_F_ADJUST_RES) {
     202                 :          0 :                         rcfg->timer_tick_ns = min_intvl_ns;
     203                 :            :                 } else {
     204                 :            :                         rc = -ERANGE;
     205                 :          0 :                         goto tim_hw_free;
     206                 :            :                 }
     207                 :            :         }
     208                 :            : 
     209         [ #  # ]:          0 :         if (tim_ring->ena_periodic)
     210                 :          0 :                 rcfg->max_tmo_ns = rcfg->timer_tick_ns * 2;
     211                 :            : 
     212         [ #  # ]:          0 :         if (rcfg->timer_tick_ns > rcfg->max_tmo_ns) {
     213                 :          0 :                 plt_err("Max timeout to too high");
     214                 :            :                 rc = -ERANGE;
     215                 :          0 :                 goto tim_hw_free;
     216                 :            :         }
     217                 :            : 
     218                 :          0 :         tim_ring->tck_int = round((double)rcfg->timer_tick_ns /
     219                 :            :                                   cnxk_tim_ns_per_tck(clk_freq));
     220                 :          0 :         tim_ring->tck_nsec =
     221                 :          0 :                 ceil(tim_ring->tck_int * cnxk_tim_ns_per_tck(clk_freq));
     222                 :            : 
     223                 :          0 :         tim_ring->ring_id = adptr->data->id;
     224                 :          0 :         tim_ring->clk_src = clk_src;
     225                 :          0 :         tim_ring->max_tout = rcfg->max_tmo_ns;
     226                 :          0 :         tim_ring->nb_bkts = (tim_ring->max_tout / tim_ring->tck_nsec);
     227                 :          0 :         tim_ring->nb_timers = rcfg->nb_timers;
     228                 :          0 :         tim_ring->chunk_sz = dev->chunk_sz;
     229                 :          0 :         tim_ring->disable_npa = dev->disable_npa;
     230                 :          0 :         tim_ring->enable_stats = dev->enable_stats;
     231                 :          0 :         tim_ring->base = roc_tim_lf_base_get(&dev->tim, tim_ring->ring_id);
     232         [ #  # ]:          0 :         tim_ring->tbase = cnxk_tim_get_tick_base(clk_src, tim_ring->base);
     233                 :            : 
     234   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() && (tim_ring->clk_src == ROC_TIM_CLK_SRC_GTI))
     235                 :          0 :                 tim_ring->tick_fn = cnxk_tim_cntvct;
     236                 :            :         else
     237                 :          0 :                 tim_ring->tick_fn = cnxk_tim_tick_read;
     238                 :            : 
     239         [ #  # ]:          0 :         for (i = 0; i < dev->ring_ctl_cnt; i++) {
     240                 :          0 :                 struct cnxk_tim_ctl *ring_ctl = &dev->ring_ctl_data[i];
     241                 :            : 
     242         [ #  # ]:          0 :                 if (ring_ctl->ring == tim_ring->ring_id) {
     243                 :          0 :                         tim_ring->chunk_sz =
     244                 :          0 :                                 ring_ctl->chunk_slots ?
     245                 :          0 :                                         ((uint32_t)(ring_ctl->chunk_slots + 1) *
     246         [ #  # ]:          0 :                                          CNXK_TIM_CHUNK_ALIGNMENT) :
     247                 :            :                                               tim_ring->chunk_sz;
     248                 :          0 :                         tim_ring->enable_stats = ring_ctl->enable_stats;
     249                 :          0 :                         tim_ring->disable_npa = ring_ctl->disable_npa;
     250                 :            :                 }
     251                 :            :         }
     252                 :            : 
     253   [ #  #  #  # ]:          0 :         if (!dev->tim.feat.hwwqe && tim_ring->disable_npa) {
     254                 :            :                 tim_ring->nb_chunks =
     255                 :          0 :                         tim_ring->nb_timers /
     256                 :          0 :                         CNXK_TIM_NB_CHUNK_SLOTS(tim_ring->chunk_sz);
     257                 :          0 :                 tim_ring->nb_chunks = tim_ring->nb_chunks * tim_ring->nb_bkts;
     258                 :            :         } else {
     259                 :          0 :                 tim_ring->disable_npa = 0;
     260                 :          0 :                 tim_ring->nb_chunks = tim_ring->nb_timers;
     261                 :            :         }
     262                 :            : 
     263                 :          0 :         tim_ring->nb_chunk_slots = CNXK_TIM_NB_CHUNK_SLOTS(tim_ring->chunk_sz);
     264                 :            :         /* Create buckets. */
     265                 :          0 :         tim_ring->bkt =
     266                 :          0 :                 rte_zmalloc("cnxk_tim_bucket",
     267                 :          0 :                             (tim_ring->nb_bkts) * sizeof(struct cnxk_tim_bkt),
     268                 :            :                             RTE_CACHE_LINE_SIZE);
     269         [ #  # ]:          0 :         if (tim_ring->bkt == NULL)
     270                 :          0 :                 goto tim_hw_free;
     271                 :            : 
     272                 :          0 :         rc = cnxk_tim_chnk_pool_create(tim_ring, rcfg);
     273         [ #  # ]:          0 :         if (rc < 0)
     274                 :          0 :                 goto tim_bkt_free;
     275                 :            : 
     276                 :          0 :         rc = roc_tim_lf_config(&dev->tim, tim_ring->ring_id, clk_src,
     277                 :          0 :                                tim_ring->ena_periodic, tim_ring->ena_dfb,
     278                 :          0 :                                tim_ring->nb_bkts, tim_ring->chunk_sz,
     279                 :            :                                tim_ring->tck_int, tim_ring->tck_nsec, clk_freq);
     280         [ #  # ]:          0 :         if (rc < 0) {
     281                 :          0 :                 plt_err("Failed to configure timer ring");
     282                 :          0 :                 goto tim_chnk_free;
     283                 :            :         }
     284                 :            : 
     285         [ #  # ]:          0 :         if (dev->tim.feat.hwwqe) {
     286                 :          0 :                 rc = cnxk_tim_enable_hwwqe(dev, tim_ring);
     287         [ #  # ]:          0 :                 if (rc < 0) {
     288                 :          0 :                         plt_err("Failed to enable hwwqe");
     289                 :          0 :                         goto tim_chnk_free;
     290                 :            :                 }
     291                 :            :         }
     292                 :            : 
     293                 :          0 :         plt_write64((uint64_t)tim_ring->bkt, tim_ring->base + TIM_LF_RING_BASE);
     294                 :          0 :         plt_write64(tim_ring->aura, tim_ring->base + TIM_LF_RING_AURA);
     295                 :            : 
     296                 :            :         /* Set fastpath ops. */
     297                 :          0 :         cnxk_tim_set_fp_ops(tim_ring);
     298                 :            : 
     299                 :            :         /* Update SSO xae count. */
     300                 :          0 :         cnxk_sso_updt_xae_cnt(cnxk_sso_pmd_priv(dev->event_dev), tim_ring,
     301                 :            :                               RTE_EVENT_TYPE_TIMER);
     302                 :          0 :         cnxk_sso_xae_reconfigure(dev->event_dev);
     303                 :          0 :         sso_set_priv_mem_fn(dev->event_dev, NULL);
     304                 :            : 
     305                 :          0 :         plt_tim_dbg(
     306                 :            :                 "Total memory used %" PRIu64 "MB",
     307                 :            :                 (uint64_t)(((tim_ring->nb_chunks * tim_ring->chunk_sz) +
     308                 :            :                             (tim_ring->nb_bkts * sizeof(struct cnxk_tim_bkt))) /
     309                 :            :                            BIT_ULL(20)));
     310                 :            : 
     311                 :          0 :         adptr->data->adapter_priv = tim_ring;
     312                 :          0 :         return rc;
     313                 :            : 
     314                 :          0 : tim_chnk_free:
     315                 :          0 :         rte_mempool_free(tim_ring->chunk_pool);
     316                 :          0 : tim_bkt_free:
     317                 :          0 :         rte_free(tim_ring->bkt);
     318                 :          0 : tim_hw_free:
     319                 :          0 :         roc_tim_lf_free(&dev->tim, tim_ring->ring_id);
     320                 :          0 : tim_ring_free:
     321                 :          0 :         rte_free(tim_ring);
     322                 :          0 :         return rc;
     323                 :            : }
     324                 :            : 
     325                 :            : static int
     326                 :          0 : cnxk_tim_ring_free(struct rte_event_timer_adapter *adptr)
     327                 :            : {
     328                 :          0 :         struct cnxk_tim_ring *tim_ring = adptr->data->adapter_priv;
     329                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     330                 :            : 
     331         [ #  # ]:          0 :         if (dev == NULL)
     332                 :            :                 return -ENODEV;
     333                 :            : 
     334                 :          0 :         roc_tim_lf_free(&dev->tim, tim_ring->ring_id);
     335                 :          0 :         rte_free(tim_ring->bkt);
     336                 :          0 :         rte_mempool_free(tim_ring->chunk_pool);
     337                 :          0 :         rte_free(tim_ring);
     338                 :            : 
     339                 :          0 :         return 0;
     340                 :            : }
     341                 :            : 
     342                 :            : static int
     343                 :          0 : cnxk_tim_ring_start(const struct rte_event_timer_adapter *adptr)
     344                 :            : {
     345                 :          0 :         struct cnxk_tim_ring *tim_ring = adptr->data->adapter_priv;
     346                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     347                 :            :         int rc;
     348                 :            : 
     349         [ #  # ]:          0 :         if (dev == NULL)
     350                 :            :                 return -ENODEV;
     351                 :            : 
     352                 :          0 :         rc = roc_tim_lf_enable(&dev->tim, tim_ring->ring_id,
     353                 :            :                                &tim_ring->ring_start_cyc, NULL);
     354         [ #  # ]:          0 :         if (rc < 0)
     355                 :            :                 return rc;
     356                 :            : 
     357                 :          0 :         tim_ring->fast_div = rte_reciprocal_value_u64(tim_ring->tck_int);
     358                 :          0 :         tim_ring->fast_bkt = rte_reciprocal_value_u64(tim_ring->nb_bkts);
     359                 :            : 
     360   [ #  #  #  # ]:          0 :         if (roc_model_is_cn9k() && (tim_ring->clk_src == ROC_TIM_CLK_SRC_GTI)) {
     361                 :            :                 uint64_t start_diff;
     362                 :            : 
     363                 :          0 :                 start_diff = cnxk_tim_cntvct(tim_ring->tbase) -
     364                 :            :                              cnxk_tim_tick_read(tim_ring->tbase);
     365                 :          0 :                 tim_ring->ring_start_cyc += start_diff;
     366                 :            :         }
     367                 :            :         return rc;
     368                 :            : }
     369                 :            : 
     370                 :            : static int
     371                 :          0 : cnxk_tim_ring_stop(const struct rte_event_timer_adapter *adptr)
     372                 :            : {
     373                 :          0 :         struct cnxk_tim_ring *tim_ring = adptr->data->adapter_priv;
     374                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     375                 :            :         int rc;
     376                 :            : 
     377         [ #  # ]:          0 :         if (dev == NULL)
     378                 :            :                 return -ENODEV;
     379                 :            : 
     380                 :          0 :         rc = roc_tim_lf_disable(&dev->tim, tim_ring->ring_id);
     381         [ #  # ]:          0 :         if (rc < 0)
     382                 :          0 :                 plt_err("Failed to disable timer ring");
     383                 :            : 
     384                 :            :         return rc;
     385                 :            : }
     386                 :            : 
     387                 :            : static int
     388                 :          0 : cnxk_tim_stats_get(const struct rte_event_timer_adapter *adapter,
     389                 :            :                    struct rte_event_timer_adapter_stats *stats)
     390                 :            : {
     391                 :          0 :         struct cnxk_tim_ring *tim_ring = adapter->data->adapter_priv;
     392                 :          0 :         uint64_t bkt_cyc =
     393                 :          0 :                 tim_ring->tick_fn(tim_ring->tbase) - tim_ring->ring_start_cyc;
     394                 :            : 
     395                 :          0 :         stats->evtim_exp_count =
     396                 :          0 :                 rte_atomic_load_explicit(&tim_ring->arm_cnt, rte_memory_order_relaxed);
     397                 :          0 :         stats->ev_enq_count = stats->evtim_exp_count;
     398                 :          0 :         stats->adapter_tick_count =
     399                 :            :                 rte_reciprocal_divide_u64(bkt_cyc, &tim_ring->fast_div);
     400                 :          0 :         return 0;
     401                 :            : }
     402                 :            : 
     403                 :            : static int
     404                 :          0 : cnxk_tim_stats_reset(const struct rte_event_timer_adapter *adapter)
     405                 :            : {
     406                 :          0 :         struct cnxk_tim_ring *tim_ring = adapter->data->adapter_priv;
     407                 :            : 
     408                 :          0 :         rte_atomic_store_explicit(&tim_ring->arm_cnt, 0, rte_memory_order_relaxed);
     409                 :          0 :         return 0;
     410                 :            : }
     411                 :            : 
     412                 :            : int
     413                 :          0 : cnxk_tim_caps_get(const struct rte_eventdev *evdev, uint64_t flags,
     414                 :            :                   uint32_t *caps, const struct event_timer_adapter_ops **ops,
     415                 :            :                   cnxk_sso_set_priv_mem_t priv_mem_fn)
     416                 :            : {
     417                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     418                 :            :         struct cnxk_tim_ring *tim_ring;
     419                 :            : 
     420                 :            :         RTE_SET_USED(flags);
     421                 :            : 
     422         [ #  # ]:          0 :         if (dev == NULL)
     423                 :            :                 return -ENODEV;
     424                 :            : 
     425                 :          0 :         cnxk_tim_ops.init = cnxk_tim_ring_create;
     426                 :          0 :         cnxk_tim_ops.uninit = cnxk_tim_ring_free;
     427                 :          0 :         cnxk_tim_ops.start = cnxk_tim_ring_start;
     428                 :          0 :         cnxk_tim_ops.stop = cnxk_tim_ring_stop;
     429                 :          0 :         cnxk_tim_ops.get_info = cnxk_tim_ring_info_get;
     430                 :          0 :         cnxk_tim_ops.remaining_ticks_get = cnxk_tim_remaining_ticks_get;
     431                 :          0 :         sso_set_priv_mem_fn = priv_mem_fn;
     432                 :            : 
     433         [ #  # ]:          0 :         if (dev->enable_stats) {
     434                 :          0 :                 cnxk_tim_ops.stats_get = cnxk_tim_stats_get;
     435                 :          0 :                 cnxk_tim_ops.stats_reset = cnxk_tim_stats_reset;
     436                 :            :         }
     437                 :            : 
     438                 :            :         /* Store evdev pointer for later use. */
     439                 :          0 :         dev->event_dev = (struct rte_eventdev *)(uintptr_t)evdev;
     440                 :          0 :         *caps = RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT |
     441                 :            :                 RTE_EVENT_TIMER_ADAPTER_CAP_PERIODIC;
     442                 :            : 
     443                 :          0 :         tim_ring = ((struct rte_event_timer_adapter_data
     444                 :            :                              *)((char *)caps - offsetof(struct rte_event_timer_adapter_data, caps)))
     445                 :            :                            ->adapter_priv;
     446   [ #  #  #  # ]:          0 :         if (tim_ring != NULL && rte_eal_process_type() == RTE_PROC_SECONDARY)
     447                 :          0 :                 cnxk_tim_set_fp_ops(tim_ring);
     448                 :          0 :         *ops = &cnxk_tim_ops;
     449                 :            : 
     450                 :          0 :         return 0;
     451                 :            : }
     452                 :            : 
     453                 :            : static void
     454                 :          0 : cnxk_tim_parse_ring_param(char *value, void *opaque)
     455                 :            : {
     456                 :            :         struct cnxk_tim_evdev *dev = opaque;
     457                 :          0 :         struct cnxk_tim_ctl ring_ctl = {0};
     458                 :          0 :         char *tok = strtok(value, "-");
     459                 :            :         struct cnxk_tim_ctl *old_ptr;
     460                 :            :         uint16_t *val;
     461                 :            : 
     462                 :            :         val = (uint16_t *)&ring_ctl;
     463                 :            : 
     464         [ #  # ]:          0 :         if (!strlen(value))
     465                 :          0 :                 return;
     466                 :            : 
     467         [ #  # ]:          0 :         while (tok != NULL) {
     468                 :          0 :                 *val = atoi(tok);
     469                 :          0 :                 tok = strtok(NULL, "-");
     470                 :          0 :                 val++;
     471                 :            :         }
     472                 :            : 
     473         [ #  # ]:          0 :         if (val != (&ring_ctl.enable_stats + 1)) {
     474                 :          0 :                 plt_err("Invalid ring param expected [ring-chunk_sz-disable_npa-enable_stats]");
     475                 :          0 :                 return;
     476                 :            :         }
     477                 :            : 
     478                 :          0 :         dev->ring_ctl_cnt++;
     479                 :          0 :         old_ptr = dev->ring_ctl_data;
     480                 :          0 :         dev->ring_ctl_data =
     481                 :          0 :                 rte_realloc(dev->ring_ctl_data,
     482                 :          0 :                             sizeof(struct cnxk_tim_ctl) * dev->ring_ctl_cnt, 0);
     483         [ #  # ]:          0 :         if (dev->ring_ctl_data == NULL) {
     484                 :          0 :                 dev->ring_ctl_data = old_ptr;
     485                 :          0 :                 dev->ring_ctl_cnt--;
     486                 :          0 :                 return;
     487                 :            :         }
     488                 :            : 
     489                 :          0 :         dev->ring_ctl_data[dev->ring_ctl_cnt - 1] = ring_ctl;
     490                 :            : }
     491                 :            : 
     492                 :            : static void
     493                 :          0 : cnxk_tim_parse_ring_ctl_list(const char *value, void *opaque)
     494                 :            : {
     495                 :          0 :         char *s = strdup(value);
     496                 :            :         char *start = NULL;
     497                 :            :         char *end = NULL;
     498                 :            :         char *f = s;
     499                 :            : 
     500   [ #  #  #  # ]:          0 :         if (s == NULL || !strlen(s))
     501                 :          0 :                 goto free;
     502                 :            : 
     503         [ #  # ]:          0 :         while (*s) {
     504         [ #  # ]:          0 :                 if (*s == '[')
     505                 :            :                         start = s;
     506         [ #  # ]:          0 :                 else if (*s == ']')
     507                 :            :                         end = s;
     508                 :            :                 else
     509                 :          0 :                         continue;
     510                 :            : 
     511         [ #  # ]:          0 :                 if (start && start < end) {
     512                 :          0 :                         *end = 0;
     513                 :          0 :                         cnxk_tim_parse_ring_param(start + 1, opaque);
     514                 :            :                         start = end;
     515                 :            :                         s = end;
     516                 :            :                 }
     517                 :          0 :                 s++;
     518                 :            :         }
     519                 :            : 
     520                 :          0 : free:
     521                 :          0 :         free(f);
     522                 :          0 : }
     523                 :            : 
     524                 :            : static int
     525                 :          0 : cnxk_tim_parse_kvargs_dict(const char *key, const char *value, void *opaque)
     526                 :            : {
     527                 :            :         RTE_SET_USED(key);
     528                 :            : 
     529                 :            :         /* Dict format [ring-chunk_sz-disable_npa-enable_stats] use '-' as ','
     530                 :            :          * isn't allowed. 0 represents default.
     531                 :            :          */
     532                 :          0 :         cnxk_tim_parse_ring_ctl_list(value, opaque);
     533                 :            : 
     534                 :          0 :         return 0;
     535                 :            : }
     536                 :            : 
     537                 :            : static void
     538                 :          0 : cnxk_tim_parse_clk_list(const char *value, void *opaque)
     539                 :            : {
     540                 :          0 :         enum roc_tim_clk_src src[] = {ROC_TIM_CLK_SRC_GPIO, ROC_TIM_CLK_SRC_PTP,
     541                 :            :                                       ROC_TIM_CLK_SRC_SYNCE,
     542                 :            :                                       ROC_TIM_CLK_SRC_INVALID};
     543                 :            :         struct cnxk_tim_evdev *dev = opaque;
     544                 :          0 :         char *str = strdup(value);
     545                 :            :         char *tok;
     546                 :            :         int i = 0;
     547                 :            : 
     548   [ #  #  #  # ]:          0 :         if (str == NULL || !strlen(str))
     549                 :          0 :                 goto free;
     550                 :            : 
     551                 :          0 :         tok = strtok(str, "-");
     552   [ #  #  #  # ]:          0 :         while (tok != NULL && src[i] != ROC_TIM_CLK_SRC_INVALID) {
     553                 :          0 :                 dev->ext_clk_freq[src[i]] = strtoull(tok, NULL, 10);
     554                 :          0 :                 tok = strtok(NULL, "-");
     555                 :          0 :                 i++;
     556                 :            :         }
     557                 :            : 
     558                 :          0 : free:
     559                 :          0 :         free(str);
     560                 :          0 : }
     561                 :            : 
     562                 :            : static int
     563                 :          0 : cnxk_tim_parse_kvargs_dsv(const char *key, const char *value, void *opaque)
     564                 :            : {
     565                 :            :         RTE_SET_USED(key);
     566                 :            : 
     567                 :            :         /* DSV format GPIO-PTP-SYNCE-BTS use '-' as ','
     568                 :            :          * isn't allowed. 0 represents default.
     569                 :            :          */
     570                 :          0 :         cnxk_tim_parse_clk_list(value, opaque);
     571                 :            : 
     572                 :          0 :         return 0;
     573                 :            : }
     574                 :            : 
     575                 :            : static void
     576                 :          0 : cnxk_tim_parse_devargs(struct rte_devargs *devargs, struct cnxk_tim_evdev *dev)
     577                 :            : {
     578                 :            :         struct rte_kvargs *kvlist;
     579                 :            : 
     580         [ #  # ]:          0 :         if (devargs == NULL)
     581                 :            :                 return;
     582                 :            : 
     583                 :          0 :         kvlist = rte_kvargs_parse(devargs->args, NULL);
     584         [ #  # ]:          0 :         if (kvlist == NULL)
     585                 :            :                 return;
     586                 :            : 
     587                 :          0 :         rte_kvargs_process(kvlist, CNXK_TIM_DISABLE_NPA, &parse_kvargs_flag,
     588                 :          0 :                            &dev->disable_npa);
     589                 :          0 :         rte_kvargs_process(kvlist, CNXK_TIM_CHNK_SLOTS, &parse_kvargs_value,
     590                 :          0 :                            &dev->chunk_slots);
     591                 :          0 :         rte_kvargs_process(kvlist, CNXK_TIM_STATS_ENA, &parse_kvargs_flag,
     592                 :          0 :                            &dev->enable_stats);
     593                 :          0 :         rte_kvargs_process(kvlist, CNXK_TIM_RINGS_LMT, &parse_kvargs_value,
     594                 :          0 :                            &dev->min_ring_cnt);
     595                 :          0 :         rte_kvargs_process(kvlist, CNXK_TIM_RING_CTL,
     596                 :            :                            &cnxk_tim_parse_kvargs_dict, &dev);
     597                 :          0 :         rte_kvargs_process(kvlist, CNXK_TIM_EXT_CLK, &cnxk_tim_parse_kvargs_dsv,
     598                 :            :                            dev);
     599                 :            : 
     600                 :          0 :         rte_kvargs_free(kvlist);
     601                 :            : }
     602                 :            : 
     603                 :            : void
     604                 :          0 : cnxk_tim_init(struct roc_sso *sso)
     605                 :            : {
     606                 :            :         const struct rte_memzone *mz;
     607                 :            :         struct cnxk_tim_evdev *dev;
     608                 :            :         int rc;
     609                 :            : 
     610         [ #  # ]:          0 :         if (rte_eal_process_type() != RTE_PROC_PRIMARY)
     611                 :            :                 return;
     612                 :            : 
     613                 :          0 :         mz = rte_memzone_reserve(RTE_STR(CNXK_TIM_EVDEV_NAME),
     614                 :            :                                  sizeof(struct cnxk_tim_evdev), 0, 0);
     615         [ #  # ]:          0 :         if (mz == NULL) {
     616                 :          0 :                 plt_tim_dbg("Unable to allocate memory for TIM Event device");
     617                 :          0 :                 return;
     618                 :            :         }
     619                 :          0 :         dev = mz->addr;
     620                 :            : 
     621                 :          0 :         cnxk_tim_parse_devargs(sso->pci_dev->device.devargs, dev);
     622                 :            : 
     623                 :          0 :         dev->tim.roc_sso = sso;
     624                 :          0 :         dev->tim.nb_lfs = dev->min_ring_cnt;
     625                 :          0 :         rc = roc_tim_init(&dev->tim);
     626         [ #  # ]:          0 :         if (rc < 0) {
     627                 :          0 :                 plt_err("Failed to initialize roc tim resources");
     628                 :          0 :                 rte_memzone_free(mz);
     629                 :          0 :                 return;
     630                 :            :         }
     631                 :          0 :         dev->nb_rings = rc;
     632                 :            : 
     633         [ #  # ]:          0 :         if (dev->chunk_slots && dev->chunk_slots <= CNXK_TIM_MAX_CHUNK_SLOTS &&
     634                 :            :             dev->chunk_slots >= CNXK_TIM_MIN_CHUNK_SLOTS) {
     635                 :          0 :                 dev->chunk_sz =
     636                 :          0 :                         (dev->chunk_slots + 1) * CNXK_TIM_CHUNK_ALIGNMENT;
     637                 :            :         } else {
     638                 :          0 :                 dev->chunk_sz = CNXK_TIM_RING_DEF_CHUNK_SZ;
     639                 :            :         }
     640                 :            : }
     641                 :            : 
     642                 :            : void
     643                 :          0 : cnxk_tim_fini(void)
     644                 :            : {
     645                 :            :         struct cnxk_tim_evdev *dev = cnxk_tim_priv_get();
     646                 :            : 
     647   [ #  #  #  # ]:          0 :         if (dev == NULL || rte_eal_process_type() != RTE_PROC_PRIMARY)
     648                 :          0 :                 return;
     649                 :            : 
     650                 :          0 :         roc_tim_fini(&dev->tim);
     651                 :          0 :         rte_memzone_free(rte_memzone_lookup(RTE_STR(CNXK_TIM_EVDEV_NAME)));
     652                 :            : }

Generated by: LCOV version 1.14