aaa4d93f5c4f2d1a2df9680000419886b7c72539
[dpdk.git] / drivers / event / octeontx2 / otx2_tim_evdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(C) 2019 Marvell International Ltd.
3  */
4
5 #ifndef __OTX2_TIM_EVDEV_H__
6 #define __OTX2_TIM_EVDEV_H__
7
8 #include <rte_event_timer_adapter.h>
9 #include <rte_event_timer_adapter_pmd.h>
10
11 #include "otx2_dev.h"
12
13 #define OTX2_TIM_EVDEV_NAME otx2_tim_eventdev
14
15 #define otx2_tim_func_trace otx2_tim_dbg
16
17 #define TIM_LF_RING_AURA                (0x0)
18 #define TIM_LF_RING_BASE                (0x130)
19
20 #define OTX2_TIM_RING_DEF_CHUNK_SZ      (4096)
21 #define OTX2_TIM_CHUNK_ALIGNMENT        (16)
22 #define OTX2_TIM_NB_CHUNK_SLOTS(sz)     (((sz) / OTX2_TIM_CHUNK_ALIGNMENT) - 1)
23 #define OTX2_TIM_MIN_TMO_TKS            (256)
24
25 enum otx2_tim_clk_src {
26         OTX2_TIM_CLK_SRC_10NS = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
27         OTX2_TIM_CLK_SRC_GPIO = RTE_EVENT_TIMER_ADAPTER_EXT_CLK0,
28         OTX2_TIM_CLK_SRC_GTI  = RTE_EVENT_TIMER_ADAPTER_EXT_CLK1,
29         OTX2_TIM_CLK_SRC_PTP  = RTE_EVENT_TIMER_ADAPTER_EXT_CLK2,
30 };
31
32 struct otx2_tim_bkt {
33         uint64_t first_chunk;
34         union {
35                 uint64_t w1;
36                 struct {
37                         uint32_t nb_entry;
38                         uint8_t sbt:1;
39                         uint8_t hbt:1;
40                         uint8_t bsk:1;
41                         uint8_t rsvd:5;
42                         uint8_t lock;
43                         int16_t chunk_remainder;
44                 };
45         };
46         uint64_t current_chunk;
47         uint64_t pad;
48 } __rte_packed __rte_aligned(32);
49
50 struct otx2_tim_evdev {
51         struct rte_pci_device *pci_dev;
52         struct rte_eventdev *event_dev;
53         struct otx2_mbox *mbox;
54         uint16_t nb_rings;
55         uintptr_t bar2;
56 };
57
58 struct otx2_tim_ring {
59         uintptr_t base;
60         uint16_t nb_chunk_slots;
61         uint32_t nb_bkts;
62         struct otx2_tim_bkt *bkt;
63         struct rte_mempool *chunk_pool;
64         uint64_t tck_int;
65         uint8_t prod_type_sp;
66         uint8_t ena_dfb;
67         uint16_t ring_id;
68         uint32_t aura;
69         uint64_t tck_nsec;
70         uint64_t max_tout;
71         uint64_t nb_chunks;
72         uint64_t chunk_sz;
73         uint64_t tenns_clk_freq;
74         enum otx2_tim_clk_src clk_src;
75 } __rte_cache_aligned;
76
77 static inline struct otx2_tim_evdev *
78 tim_priv_get(void)
79 {
80         const struct rte_memzone *mz;
81
82         mz = rte_memzone_lookup(RTE_STR(OTX2_TIM_EVDEV_NAME));
83         if (mz == NULL)
84                 return NULL;
85
86         return mz->addr;
87 }
88
89 int otx2_tim_caps_get(const struct rte_eventdev *dev, uint64_t flags,
90                       uint32_t *caps,
91                       const struct rte_event_timer_adapter_ops **ops);
92
93 void otx2_tim_init(struct rte_pci_device *pci_dev, struct otx2_dev *cmn_dev);
94 void otx2_tim_fini(void);
95
96 #endif /* __OTX2_TIM_EVDEV_H__ */