1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #ifndef __OTX2_TIM_EVDEV_H__
6 #define __OTX2_TIM_EVDEV_H__
8 #include <rte_event_timer_adapter.h>
9 #include <rte_event_timer_adapter_pmd.h>
10 #include <rte_reciprocal.h>
14 #define OTX2_TIM_EVDEV_NAME otx2_tim_eventdev
16 #define otx2_tim_func_trace otx2_tim_dbg
18 #define TIM_LF_RING_AURA (0x0)
19 #define TIM_LF_RING_BASE (0x130)
20 #define TIM_LF_NRSPERR_INT (0x200)
21 #define TIM_LF_NRSPERR_INT_W1S (0x208)
22 #define TIM_LF_NRSPERR_INT_ENA_W1S (0x210)
23 #define TIM_LF_NRSPERR_INT_ENA_W1C (0x218)
24 #define TIM_LF_RAS_INT (0x300)
25 #define TIM_LF_RAS_INT_W1S (0x308)
26 #define TIM_LF_RAS_INT_ENA_W1S (0x310)
27 #define TIM_LF_RAS_INT_ENA_W1C (0x318)
29 #define TIM_BUCKET_W1_S_CHUNK_REMAINDER (48)
30 #define TIM_BUCKET_W1_M_CHUNK_REMAINDER ((1ULL << (64 - \
31 TIM_BUCKET_W1_S_CHUNK_REMAINDER)) - 1)
32 #define TIM_BUCKET_W1_S_LOCK (40)
33 #define TIM_BUCKET_W1_M_LOCK ((1ULL << \
34 (TIM_BUCKET_W1_S_CHUNK_REMAINDER - \
35 TIM_BUCKET_W1_S_LOCK)) - 1)
36 #define TIM_BUCKET_W1_S_RSVD (35)
37 #define TIM_BUCKET_W1_S_BSK (34)
38 #define TIM_BUCKET_W1_M_BSK ((1ULL << \
39 (TIM_BUCKET_W1_S_RSVD - \
40 TIM_BUCKET_W1_S_BSK)) - 1)
41 #define TIM_BUCKET_W1_S_HBT (33)
42 #define TIM_BUCKET_W1_M_HBT ((1ULL << \
43 (TIM_BUCKET_W1_S_BSK - \
44 TIM_BUCKET_W1_S_HBT)) - 1)
45 #define TIM_BUCKET_W1_S_SBT (32)
46 #define TIM_BUCKET_W1_M_SBT ((1ULL << \
47 (TIM_BUCKET_W1_S_HBT - \
48 TIM_BUCKET_W1_S_SBT)) - 1)
49 #define TIM_BUCKET_W1_S_NUM_ENTRIES (0)
50 #define TIM_BUCKET_W1_M_NUM_ENTRIES ((1ULL << \
51 (TIM_BUCKET_W1_S_SBT - \
52 TIM_BUCKET_W1_S_NUM_ENTRIES)) - 1)
54 #define TIM_BUCKET_SEMA (TIM_BUCKET_CHUNK_REMAIN)
56 #define TIM_BUCKET_CHUNK_REMAIN \
57 (TIM_BUCKET_W1_M_CHUNK_REMAINDER << TIM_BUCKET_W1_S_CHUNK_REMAINDER)
59 #define TIM_BUCKET_LOCK \
60 (TIM_BUCKET_W1_M_LOCK << TIM_BUCKET_W1_S_LOCK)
62 #define TIM_BUCKET_SEMA_WLOCK \
63 (TIM_BUCKET_CHUNK_REMAIN | (1ull << TIM_BUCKET_W1_S_LOCK))
65 #define OTX2_MAX_TIM_RINGS (256)
66 #define OTX2_TIM_MAX_BUCKETS (0xFFFFF)
67 #define OTX2_TIM_RING_DEF_CHUNK_SZ (4096)
68 #define OTX2_TIM_CHUNK_ALIGNMENT (16)
69 #define OTX2_TIM_MAX_BURST (RTE_CACHE_LINE_SIZE / \
70 OTX2_TIM_CHUNK_ALIGNMENT)
71 #define OTX2_TIM_NB_CHUNK_SLOTS(sz) (((sz) / OTX2_TIM_CHUNK_ALIGNMENT) - 1)
72 #define OTX2_TIM_MIN_CHUNK_SLOTS (0x1)
73 #define OTX2_TIM_MAX_CHUNK_SLOTS (0x1FFE)
74 #define OTX2_TIM_MIN_TMO_TKS (256)
76 #define OTX2_TIM_SP 0x1
77 #define OTX2_TIM_MP 0x2
78 #define OTX2_TIM_BKT_AND 0x4
79 #define OTX2_TIM_BKT_MOD 0x8
80 #define OTX2_TIM_ENA_FB 0x10
81 #define OTX2_TIM_ENA_DFB 0x20
82 #define OTX2_TIM_ENA_STATS 0x40
84 enum otx2_tim_clk_src {
85 OTX2_TIM_CLK_SRC_10NS = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
86 OTX2_TIM_CLK_SRC_GPIO = RTE_EVENT_TIMER_ADAPTER_EXT_CLK0,
87 OTX2_TIM_CLK_SRC_GTI = RTE_EVENT_TIMER_ADAPTER_EXT_CLK1,
88 OTX2_TIM_CLK_SRC_PTP = RTE_EVENT_TIMER_ADAPTER_EXT_CLK2,
102 int16_t chunk_remainder;
105 uint64_t current_chunk;
107 } __rte_packed __rte_aligned(32);
109 struct otx2_tim_ent {
114 struct otx2_tim_ctl {
116 uint16_t chunk_slots;
117 uint16_t disable_npa;
118 uint16_t enable_stats;
121 struct otx2_tim_evdev {
122 struct rte_pci_device *pci_dev;
123 struct rte_eventdev *event_dev;
124 struct otx2_mbox *mbox;
130 uint16_t chunk_slots;
131 uint16_t min_ring_cnt;
132 uint8_t enable_stats;
133 uint16_t ring_ctl_cnt;
134 struct otx2_tim_ctl *ring_ctl_data;
137 uint16_t tim_msixoff[OTX2_MAX_TIM_RINGS];
140 struct otx2_tim_ring {
142 struct rte_reciprocal_u64 fast_div;
143 uint16_t nb_chunk_slots;
145 uint64_t ring_start_cyc;
146 struct otx2_tim_bkt *bkt;
147 struct rte_mempool *chunk_pool;
149 rte_atomic64_t arm_cnt;
150 uint8_t prod_type_sp;
151 uint8_t enable_stats;
161 uint64_t tenns_clk_freq;
162 enum otx2_tim_clk_src clk_src;
163 } __rte_cache_aligned;
165 static inline struct otx2_tim_evdev *
168 const struct rte_memzone *mz;
170 mz = rte_memzone_lookup(RTE_STR(OTX2_TIM_EVDEV_NAME));
177 #define TIM_ARM_FASTPATH_MODES \
178 FP(mod_sp, 0, 0, 0, 0, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
179 FP(mod_mp, 0, 0, 0, 1, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
180 FP(mod_fb_sp, 0, 0, 1, 0, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
181 FP(mod_fb_mp, 0, 0, 1, 1, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_FB | OTX2_TIM_MP) \
182 FP(and_sp, 0, 1, 0, 0, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
183 FP(and_mp, 0, 1, 0, 1, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
184 FP(and_fb_sp, 0, 1, 1, 0, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
185 FP(and_fb_mp, 0, 1, 1, 1, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_FB | OTX2_TIM_MP) \
186 FP(stats_mod_sp, 1, 0, 0, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
187 OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
188 FP(stats_mod_mp, 1, 0, 0, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
189 OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
190 FP(stats_mod_fb_sp, 1, 0, 1, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
191 OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
192 FP(stats_mod_fb_mp, 1, 0, 1, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
193 OTX2_TIM_ENA_FB | OTX2_TIM_MP) \
194 FP(stats_and_sp, 1, 1, 0, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
195 OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
196 FP(stats_and_mp, 1, 1, 0, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
197 OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
198 FP(stats_and_fb_sp, 1, 1, 1, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
199 OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
200 FP(stats_and_fb_mp, 1, 1, 1, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
201 OTX2_TIM_ENA_FB | OTX2_TIM_MP)
203 #define TIM_ARM_TMO_FASTPATH_MODES \
204 FP(mod, 0, 0, 0, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_DFB) \
205 FP(mod_fb, 0, 0, 1, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_FB) \
206 FP(and, 0, 1, 0, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_DFB) \
207 FP(and_fb, 0, 1, 1, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_FB) \
208 FP(stats_mod, 1, 0, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
210 FP(stats_mod_fb, 1, 0, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
212 FP(stats_and, 1, 1, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
214 FP(stats_and_fb, 1, 1, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
217 #define FP(_name, _f4, _f3, _f2, _f1, flags) \
219 otx2_tim_arm_burst_ ## _name(const struct rte_event_timer_adapter *adptr, \
220 struct rte_event_timer **tim, \
221 const uint16_t nb_timers);
222 TIM_ARM_FASTPATH_MODES
225 #define FP(_name, _f3, _f2, _f1, flags) \
227 otx2_tim_arm_tmo_tick_burst_ ## _name( \
228 const struct rte_event_timer_adapter *adptr, \
229 struct rte_event_timer **tim, \
230 const uint64_t timeout_tick, const uint16_t nb_timers);
231 TIM_ARM_TMO_FASTPATH_MODES
234 uint16_t otx2_tim_timer_cancel_burst(
235 const struct rte_event_timer_adapter *adptr,
236 struct rte_event_timer **tim, const uint16_t nb_timers);
238 int otx2_tim_caps_get(const struct rte_eventdev *dev, uint64_t flags,
240 const struct rte_event_timer_adapter_ops **ops);
242 void otx2_tim_init(struct rte_pci_device *pci_dev, struct otx2_dev *cmn_dev);
243 void otx2_tim_fini(void);
246 int tim_register_irq(uint16_t ring_id);
247 void tim_unregister_irq(uint16_t ring_id);
249 #endif /* __OTX2_TIM_EVDEV_H__ */