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)
28 #define TIM_LF_RING_REL (0x400)
30 #define TIM_BUCKET_W1_S_CHUNK_REMAINDER (48)
31 #define TIM_BUCKET_W1_M_CHUNK_REMAINDER ((1ULL << (64 - \
32 TIM_BUCKET_W1_S_CHUNK_REMAINDER)) - 1)
33 #define TIM_BUCKET_W1_S_LOCK (40)
34 #define TIM_BUCKET_W1_M_LOCK ((1ULL << \
35 (TIM_BUCKET_W1_S_CHUNK_REMAINDER - \
36 TIM_BUCKET_W1_S_LOCK)) - 1)
37 #define TIM_BUCKET_W1_S_RSVD (35)
38 #define TIM_BUCKET_W1_S_BSK (34)
39 #define TIM_BUCKET_W1_M_BSK ((1ULL << \
40 (TIM_BUCKET_W1_S_RSVD - \
41 TIM_BUCKET_W1_S_BSK)) - 1)
42 #define TIM_BUCKET_W1_S_HBT (33)
43 #define TIM_BUCKET_W1_M_HBT ((1ULL << \
44 (TIM_BUCKET_W1_S_BSK - \
45 TIM_BUCKET_W1_S_HBT)) - 1)
46 #define TIM_BUCKET_W1_S_SBT (32)
47 #define TIM_BUCKET_W1_M_SBT ((1ULL << \
48 (TIM_BUCKET_W1_S_HBT - \
49 TIM_BUCKET_W1_S_SBT)) - 1)
50 #define TIM_BUCKET_W1_S_NUM_ENTRIES (0)
51 #define TIM_BUCKET_W1_M_NUM_ENTRIES ((1ULL << \
52 (TIM_BUCKET_W1_S_SBT - \
53 TIM_BUCKET_W1_S_NUM_ENTRIES)) - 1)
55 #define TIM_BUCKET_SEMA (TIM_BUCKET_CHUNK_REMAIN)
57 #define TIM_BUCKET_CHUNK_REMAIN \
58 (TIM_BUCKET_W1_M_CHUNK_REMAINDER << TIM_BUCKET_W1_S_CHUNK_REMAINDER)
60 #define TIM_BUCKET_LOCK \
61 (TIM_BUCKET_W1_M_LOCK << TIM_BUCKET_W1_S_LOCK)
63 #define TIM_BUCKET_SEMA_WLOCK \
64 (TIM_BUCKET_CHUNK_REMAIN | (1ull << TIM_BUCKET_W1_S_LOCK))
66 #define OTX2_MAX_TIM_RINGS (256)
67 #define OTX2_TIM_MAX_BUCKETS (0xFFFFF)
68 #define OTX2_TIM_RING_DEF_CHUNK_SZ (4096)
69 #define OTX2_TIM_CHUNK_ALIGNMENT (16)
70 #define OTX2_TIM_MAX_BURST (RTE_CACHE_LINE_SIZE / \
71 OTX2_TIM_CHUNK_ALIGNMENT)
72 #define OTX2_TIM_NB_CHUNK_SLOTS(sz) (((sz) / OTX2_TIM_CHUNK_ALIGNMENT) - 1)
73 #define OTX2_TIM_MIN_CHUNK_SLOTS (0x1)
74 #define OTX2_TIM_MAX_CHUNK_SLOTS (0x1FFE)
75 #define OTX2_TIM_MIN_TMO_TKS (256)
77 #define OTX2_TIM_SP 0x1
78 #define OTX2_TIM_MP 0x2
79 #define OTX2_TIM_BKT_AND 0x4
80 #define OTX2_TIM_BKT_MOD 0x8
81 #define OTX2_TIM_ENA_FB 0x10
82 #define OTX2_TIM_ENA_DFB 0x20
83 #define OTX2_TIM_ENA_STATS 0x40
85 enum otx2_tim_clk_src {
86 OTX2_TIM_CLK_SRC_10NS = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
87 OTX2_TIM_CLK_SRC_GPIO = RTE_EVENT_TIMER_ADAPTER_EXT_CLK0,
88 OTX2_TIM_CLK_SRC_GTI = RTE_EVENT_TIMER_ADAPTER_EXT_CLK1,
89 OTX2_TIM_CLK_SRC_PTP = RTE_EVENT_TIMER_ADAPTER_EXT_CLK2,
103 int16_t chunk_remainder;
106 uint64_t current_chunk;
108 } __rte_packed __rte_aligned(32);
110 struct otx2_tim_ent {
115 struct otx2_tim_ctl {
117 uint16_t chunk_slots;
118 uint16_t disable_npa;
119 uint16_t enable_stats;
122 struct otx2_tim_evdev {
123 struct rte_pci_device *pci_dev;
124 struct rte_eventdev *event_dev;
125 struct otx2_mbox *mbox;
131 uint16_t chunk_slots;
132 uint16_t min_ring_cnt;
133 uint8_t enable_stats;
134 uint16_t ring_ctl_cnt;
135 struct otx2_tim_ctl *ring_ctl_data;
138 uint16_t tim_msixoff[OTX2_MAX_TIM_RINGS];
141 struct otx2_tim_ring {
143 uint16_t nb_chunk_slots;
145 uint64_t last_updt_cyc;
146 uint64_t ring_start_cyc;
149 struct otx2_tim_bkt *bkt;
150 struct rte_mempool *chunk_pool;
151 struct rte_reciprocal_u64 fast_div;
153 uint8_t prod_type_sp;
154 uint8_t enable_stats;
165 uint64_t tenns_clk_freq;
166 enum otx2_tim_clk_src clk_src;
167 } __rte_cache_aligned;
169 static inline struct otx2_tim_evdev *
172 const struct rte_memzone *mz;
174 mz = rte_memzone_lookup(RTE_STR(OTX2_TIM_EVDEV_NAME));
181 #define TIM_ARM_FASTPATH_MODES \
182 FP(mod_sp, 0, 0, 0, 0, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
183 FP(mod_mp, 0, 0, 0, 1, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
184 FP(mod_fb_sp, 0, 0, 1, 0, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
185 FP(mod_fb_mp, 0, 0, 1, 1, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_FB | OTX2_TIM_MP) \
186 FP(and_sp, 0, 1, 0, 0, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
187 FP(and_mp, 0, 1, 0, 1, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
188 FP(and_fb_sp, 0, 1, 1, 0, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
189 FP(and_fb_mp, 0, 1, 1, 1, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_FB | OTX2_TIM_MP) \
190 FP(stats_mod_sp, 1, 0, 0, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
191 OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
192 FP(stats_mod_mp, 1, 0, 0, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
193 OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
194 FP(stats_mod_fb_sp, 1, 0, 1, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
195 OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
196 FP(stats_mod_fb_mp, 1, 0, 1, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
197 OTX2_TIM_ENA_FB | OTX2_TIM_MP) \
198 FP(stats_and_sp, 1, 1, 0, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
199 OTX2_TIM_ENA_DFB | OTX2_TIM_SP) \
200 FP(stats_and_mp, 1, 1, 0, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
201 OTX2_TIM_ENA_DFB | OTX2_TIM_MP) \
202 FP(stats_and_fb_sp, 1, 1, 1, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
203 OTX2_TIM_ENA_FB | OTX2_TIM_SP) \
204 FP(stats_and_fb_mp, 1, 1, 1, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
205 OTX2_TIM_ENA_FB | OTX2_TIM_MP)
207 #define TIM_ARM_TMO_FASTPATH_MODES \
208 FP(mod, 0, 0, 0, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_DFB) \
209 FP(mod_fb, 0, 0, 1, OTX2_TIM_BKT_MOD | OTX2_TIM_ENA_FB) \
210 FP(and, 0, 1, 0, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_DFB) \
211 FP(and_fb, 0, 1, 1, OTX2_TIM_BKT_AND | OTX2_TIM_ENA_FB) \
212 FP(stats_mod, 1, 0, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
214 FP(stats_mod_fb, 1, 0, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_MOD | \
216 FP(stats_and, 1, 1, 0, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
218 FP(stats_and_fb, 1, 1, 1, OTX2_TIM_ENA_STATS | OTX2_TIM_BKT_AND | \
221 #define FP(_name, _f4, _f3, _f2, _f1, flags) \
223 otx2_tim_arm_burst_ ## _name(const struct rte_event_timer_adapter *adptr, \
224 struct rte_event_timer **tim, \
225 const uint16_t nb_timers);
226 TIM_ARM_FASTPATH_MODES
229 #define FP(_name, _f3, _f2, _f1, flags) \
231 otx2_tim_arm_tmo_tick_burst_ ## _name( \
232 const struct rte_event_timer_adapter *adptr, \
233 struct rte_event_timer **tim, \
234 const uint64_t timeout_tick, const uint16_t nb_timers);
235 TIM_ARM_TMO_FASTPATH_MODES
238 uint16_t otx2_tim_timer_cancel_burst(
239 const struct rte_event_timer_adapter *adptr,
240 struct rte_event_timer **tim, const uint16_t nb_timers);
242 int otx2_tim_caps_get(const struct rte_eventdev *dev, uint64_t flags,
244 const struct rte_event_timer_adapter_ops **ops);
246 void otx2_tim_init(struct rte_pci_device *pci_dev, struct otx2_dev *cmn_dev);
247 void otx2_tim_fini(void);
250 int tim_register_irq(uint16_t ring_id);
251 void tim_unregister_irq(uint16_t ring_id);
253 #endif /* __OTX2_TIM_EVDEV_H__ */