2 * SPDX-License-Identifier: BSD-3-Clause
3 * Copyright(c) 2017 Cavium, Inc
6 #include "timvf_evdev.h"
10 RTE_INIT(otx_timvf_init_log);
12 otx_timvf_init_log(void)
14 otx_logtype_timvf = rte_log_register("pmd.event.octeontx.timer");
15 if (otx_logtype_timvf >= 0)
16 rte_log_set_level(otx_logtype_timvf, RTE_LOG_NOTICE);
20 timvf_ring_info_get(const struct rte_event_timer_adapter *adptr,
21 struct rte_event_timer_adapter_info *adptr_info)
23 struct timvf_ring *timr = adptr->data->adapter_priv;
24 adptr_info->max_tmo_ns = timr->max_tout;
25 adptr_info->min_resolution_ns = timr->tck_nsec;
26 rte_memcpy(&adptr_info->conf, &adptr->data->conf,
27 sizeof(struct rte_event_timer_adapter_conf));
31 timvf_ring_create(struct rte_event_timer_adapter *adptr)
36 struct rte_event_timer_adapter_conf *rcfg = &adptr->data->conf;
37 struct timvf_ring *timr;
38 struct timvf_info tinfo;
39 const char *mempool_ops;
41 if (timvf_info(&tinfo) < 0)
44 if (adptr->data->id >= tinfo.total_timvfs)
47 timr = rte_zmalloc("octeontx_timvf_priv",
48 sizeof(struct timvf_ring), 0);
52 adptr->data->adapter_priv = timr;
53 /* Check config parameters. */
54 if ((rcfg->clk_src != RTE_EVENT_TIMER_ADAPTER_CPU_CLK) &&
55 (!rcfg->timer_tick_ns ||
56 rcfg->timer_tick_ns < TIM_MIN_INTERVAL)) {
57 timvf_log_err("Too low timer ticks");
61 timr->clk_src = (int) rcfg->clk_src;
62 timr->tim_ring_id = adptr->data->id;
63 timr->tck_nsec = rcfg->timer_tick_ns;
64 timr->max_tout = rcfg->max_tmo_ns;
65 timr->nb_bkts = (timr->max_tout / timr->tck_nsec);
66 timr->vbar0 = timvf_bar(timr->tim_ring_id, 0);
67 timr->bkt_pos = (uint8_t *)timr->vbar0 + TIM_VRING_REL;
68 nb_timers = rcfg->nb_timers;
69 timr->get_target_bkt = bkt_mod;
71 timr->nb_chunks = nb_timers / nb_chunk_slots;
73 timr->bkt = rte_zmalloc("octeontx_timvf_bucket",
74 (timr->nb_bkts) * sizeof(struct tim_mem_bucket),
76 if (timr->bkt == NULL)
79 snprintf(pool_name, 30, "timvf_chunk_pool%d", timr->tim_ring_id);
80 timr->chunk_pool = (void *)rte_mempool_create_empty(pool_name,
81 timr->nb_chunks, TIM_CHUNK_SIZE, 0, 0, rte_socket_id(),
84 if (!timr->chunk_pool) {
86 timvf_log_err("Unable to create chunkpool.");
90 mempool_ops = rte_mbuf_best_mempool_ops();
91 ret = rte_mempool_set_ops_byname(timr->chunk_pool,
95 timvf_log_err("Unable to set chunkpool ops.");
99 ret = rte_mempool_populate_default(timr->chunk_pool);
101 timvf_log_err("Unable to set populate chunkpool.");
104 timvf_write64(0, (uint8_t *)timr->vbar0 + TIM_VRING_BASE);
105 timvf_write64(0, (uint8_t *)timr->vbar0 + TIM_VF_NRSPERR_INT);
106 timvf_write64(0, (uint8_t *)timr->vbar0 + TIM_VF_NRSPERR_INT_W1S);
107 timvf_write64(0x7, (uint8_t *)timr->vbar0 + TIM_VF_NRSPERR_ENA_W1C);
108 timvf_write64(0x7, (uint8_t *)timr->vbar0 + TIM_VF_NRSPERR_ENA_W1S);
120 timvf_ring_free(struct rte_event_timer_adapter *adptr)
122 struct timvf_ring *timr = adptr->data->adapter_priv;
123 rte_mempool_free(timr->chunk_pool);
125 rte_free(adptr->data->adapter_priv);
129 static struct rte_event_timer_adapter_ops timvf_ops = {
130 .init = timvf_ring_create,
131 .uninit = timvf_ring_free,
132 .get_info = timvf_ring_info_get,
136 timvf_timer_adapter_caps_get(const struct rte_eventdev *dev, uint64_t flags,
137 uint32_t *caps, const struct rte_event_timer_adapter_ops **ops,
138 uint8_t enable_stats)
142 RTE_SET_USED(enable_stats);
143 *caps = RTE_EVENT_TIMER_ADAPTER_CAP_INTERNAL_PORT;