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