event/cnxk: add option to disable NPA
[dpdk.git] / drivers / event / cnxk / cnxk_tim_evdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2021 Marvell.
3  */
4
5 #ifndef __CNXK_TIM_EVDEV_H__
6 #define __CNXK_TIM_EVDEV_H__
7
8 #include <stddef.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include <eventdev_pmd_pci.h>
14 #include <rte_event_timer_adapter.h>
15 #include <rte_malloc.h>
16 #include <rte_memzone.h>
17
18 #include "roc_api.h"
19
20 #define NSECPERSEC               1E9
21 #define USECPERSEC               1E6
22 #define TICK2NSEC(__tck, __freq) (((__tck)*NSECPERSEC) / (__freq))
23
24 #define CNXK_TIM_EVDEV_NAME         cnxk_tim_eventdev
25 #define CNXK_TIM_MAX_BUCKETS        (0xFFFFF)
26 #define CNXK_TIM_RING_DEF_CHUNK_SZ  (4096)
27 #define CNXK_TIM_CHUNK_ALIGNMENT    (16)
28 #define CNXK_TIM_MAX_BURST          \
29                         (RTE_CACHE_LINE_SIZE / CNXK_TIM_CHUNK_ALIGNMENT)
30 #define CNXK_TIM_NB_CHUNK_SLOTS(sz) (((sz) / CNXK_TIM_CHUNK_ALIGNMENT) - 1)
31 #define CNXK_TIM_MIN_CHUNK_SLOTS    (0x1)
32 #define CNXK_TIM_MAX_CHUNK_SLOTS    (0x1FFE)
33
34 #define CN9K_TIM_MIN_TMO_TKS (256)
35
36 #define CNXK_TIM_DISABLE_NPA "tim_disable_npa"
37
38 struct cnxk_tim_evdev {
39         struct roc_tim tim;
40         struct rte_eventdev *event_dev;
41         uint16_t nb_rings;
42         uint32_t chunk_sz;
43         /* Dev args */
44         uint8_t disable_npa;
45 };
46
47 enum cnxk_tim_clk_src {
48         CNXK_TIM_CLK_SRC_10NS = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
49         CNXK_TIM_CLK_SRC_GPIO = RTE_EVENT_TIMER_ADAPTER_EXT_CLK0,
50         CNXK_TIM_CLK_SRC_GTI = RTE_EVENT_TIMER_ADAPTER_EXT_CLK1,
51         CNXK_TIM_CLK_SRC_PTP = RTE_EVENT_TIMER_ADAPTER_EXT_CLK2,
52 };
53
54 struct cnxk_tim_bkt {
55         uint64_t first_chunk;
56         union {
57                 uint64_t w1;
58                 struct {
59                         uint32_t nb_entry;
60                         uint8_t sbt : 1;
61                         uint8_t hbt : 1;
62                         uint8_t bsk : 1;
63                         uint8_t rsvd : 5;
64                         uint8_t lock;
65                         int16_t chunk_remainder;
66                 };
67         };
68         uint64_t current_chunk;
69         uint64_t pad;
70 };
71
72 struct cnxk_tim_ring {
73         uintptr_t base;
74         uint16_t nb_chunk_slots;
75         uint32_t nb_bkts;
76         uint64_t tck_int;
77         uint64_t tot_int;
78         struct cnxk_tim_bkt *bkt;
79         struct rte_mempool *chunk_pool;
80         uint64_t arm_cnt;
81         uint8_t prod_type_sp;
82         uint8_t disable_npa;
83         uint8_t ena_dfb;
84         uint16_t ring_id;
85         uint32_t aura;
86         uint64_t nb_timers;
87         uint64_t tck_nsec;
88         uint64_t max_tout;
89         uint64_t nb_chunks;
90         uint64_t chunk_sz;
91         enum cnxk_tim_clk_src clk_src;
92 } __rte_cache_aligned;
93
94 struct cnxk_tim_ent {
95         uint64_t w0;
96         uint64_t wqe;
97 };
98
99 static inline struct cnxk_tim_evdev *
100 cnxk_tim_priv_get(void)
101 {
102         const struct rte_memzone *mz;
103
104         mz = rte_memzone_lookup(RTE_STR(CNXK_TIM_EVDEV_NAME));
105         if (mz == NULL)
106                 return NULL;
107
108         return mz->addr;
109 }
110
111 static inline uint64_t
112 cnxk_tim_min_tmo_ticks(uint64_t freq)
113 {
114         if (roc_model_runtime_is_cn9k())
115                 return CN9K_TIM_MIN_TMO_TKS;
116         else /* CN10K min tick is of 1us */
117                 return freq / USECPERSEC;
118 }
119
120 static inline uint64_t
121 cnxk_tim_min_resolution_ns(uint64_t freq)
122 {
123         return NSECPERSEC / freq;
124 }
125
126 static inline enum roc_tim_clk_src
127 cnxk_tim_convert_clk_src(enum cnxk_tim_clk_src clk_src)
128 {
129         switch (clk_src) {
130         case RTE_EVENT_TIMER_ADAPTER_CPU_CLK:
131                 return roc_model_runtime_is_cn9k() ? ROC_TIM_CLK_SRC_10NS :
132                                                            ROC_TIM_CLK_SRC_GTI;
133         default:
134                 return ROC_TIM_CLK_SRC_INVALID;
135         }
136 }
137
138 #ifdef RTE_ARCH_ARM64
139 static inline uint64_t
140 cnxk_tim_cntvct(void)
141 {
142         uint64_t tsc;
143
144         asm volatile("mrs %0, cntvct_el0" : "=r"(tsc));
145         return tsc;
146 }
147
148 static inline uint64_t
149 cnxk_tim_cntfrq(void)
150 {
151         uint64_t freq;
152
153         asm volatile("mrs %0, cntfrq_el0" : "=r"(freq));
154         return freq;
155 }
156 #else
157 static inline uint64_t
158 cnxk_tim_cntvct(void)
159 {
160         return 0;
161 }
162
163 static inline uint64_t
164 cnxk_tim_cntfrq(void)
165 {
166         return 0;
167 }
168 #endif
169
170 int cnxk_tim_caps_get(const struct rte_eventdev *dev, uint64_t flags,
171                       uint32_t *caps,
172                       const struct rte_event_timer_adapter_ops **ops);
173
174 void cnxk_tim_init(struct roc_sso *sso);
175 void cnxk_tim_fini(void);
176
177 #endif /* __CNXK_TIM_EVDEV_H__ */