9636d8414311d593a6cb5d315cb529f2ced8f0db
[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_MAX_TIM_RINGS              (256)
21 #define OTX2_TIM_MAX_BUCKETS            (0xFFFFF)
22 #define OTX2_TIM_RING_DEF_CHUNK_SZ      (4096)
23 #define OTX2_TIM_CHUNK_ALIGNMENT        (16)
24 #define OTX2_TIM_NB_CHUNK_SLOTS(sz)     (((sz) / OTX2_TIM_CHUNK_ALIGNMENT) - 1)
25 #define OTX2_TIM_MIN_CHUNK_SLOTS        (0x1)
26 #define OTX2_TIM_MAX_CHUNK_SLOTS        (0x1FFE)
27 #define OTX2_TIM_MIN_TMO_TKS            (256)
28
29 enum otx2_tim_clk_src {
30         OTX2_TIM_CLK_SRC_10NS = RTE_EVENT_TIMER_ADAPTER_CPU_CLK,
31         OTX2_TIM_CLK_SRC_GPIO = RTE_EVENT_TIMER_ADAPTER_EXT_CLK0,
32         OTX2_TIM_CLK_SRC_GTI  = RTE_EVENT_TIMER_ADAPTER_EXT_CLK1,
33         OTX2_TIM_CLK_SRC_PTP  = RTE_EVENT_TIMER_ADAPTER_EXT_CLK2,
34 };
35
36 struct otx2_tim_bkt {
37         uint64_t first_chunk;
38         union {
39                 uint64_t w1;
40                 struct {
41                         uint32_t nb_entry;
42                         uint8_t sbt:1;
43                         uint8_t hbt:1;
44                         uint8_t bsk:1;
45                         uint8_t rsvd:5;
46                         uint8_t lock;
47                         int16_t chunk_remainder;
48                 };
49         };
50         uint64_t current_chunk;
51         uint64_t pad;
52 } __rte_packed __rte_aligned(32);
53
54 struct otx2_tim_evdev {
55         struct rte_pci_device *pci_dev;
56         struct rte_eventdev *event_dev;
57         struct otx2_mbox *mbox;
58         uint16_t nb_rings;
59         uint32_t chunk_sz;
60         uintptr_t bar2;
61         /* Dev args */
62         uint8_t disable_npa;
63         uint16_t chunk_slots;
64 };
65
66 struct otx2_tim_ring {
67         uintptr_t base;
68         uint16_t nb_chunk_slots;
69         uint32_t nb_bkts;
70         struct otx2_tim_bkt *bkt;
71         struct rte_mempool *chunk_pool;
72         uint64_t tck_int;
73         uint8_t prod_type_sp;
74         uint8_t disable_npa;
75         uint8_t optimized;
76         uint8_t ena_dfb;
77         uint16_t ring_id;
78         uint32_t aura;
79         uint64_t tck_nsec;
80         uint64_t max_tout;
81         uint64_t nb_chunks;
82         uint64_t chunk_sz;
83         uint64_t tenns_clk_freq;
84         enum otx2_tim_clk_src clk_src;
85 } __rte_cache_aligned;
86
87 static inline struct otx2_tim_evdev *
88 tim_priv_get(void)
89 {
90         const struct rte_memzone *mz;
91
92         mz = rte_memzone_lookup(RTE_STR(OTX2_TIM_EVDEV_NAME));
93         if (mz == NULL)
94                 return NULL;
95
96         return mz->addr;
97 }
98
99 int otx2_tim_caps_get(const struct rte_eventdev *dev, uint64_t flags,
100                       uint32_t *caps,
101                       const struct rte_event_timer_adapter_ops **ops);
102
103 void otx2_tim_init(struct rte_pci_device *pci_dev, struct otx2_dev *cmn_dev);
104 void otx2_tim_fini(void);
105
106 #endif /* __OTX2_TIM_EVDEV_H__ */