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

Generated by: LCOV version 1.14