1992aa864SShalom Toledo /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2992aa864SShalom Toledo /* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
3992aa864SShalom Toledo
4992aa864SShalom Toledo #ifndef _MLXSW_SPECTRUM_PTP_H
5992aa864SShalom Toledo #define _MLXSW_SPECTRUM_PTP_H
6992aa864SShalom Toledo
7992aa864SShalom Toledo #include <linux/device.h>
8810256ceSPetr Machata #include <linux/rhashtable.h>
9992aa864SShalom Toledo
10810256ceSPetr Machata struct mlxsw_sp;
11810256ceSPetr Machata struct mlxsw_sp_port;
12992aa864SShalom Toledo struct mlxsw_sp_ptp_clock;
13992aa864SShalom Toledo
14992aa864SShalom Toledo #if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
15992aa864SShalom Toledo
16992aa864SShalom Toledo struct mlxsw_sp_ptp_clock *
17992aa864SShalom Toledo mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
18992aa864SShalom Toledo
19992aa864SShalom Toledo void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
20992aa864SShalom Toledo
21810256ceSPetr Machata struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
22810256ceSPetr Machata
23810256ceSPetr Machata void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
24810256ceSPetr Machata
25aed4b572SPetr Machata void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
26c934757dSAmit Cohen u16 local_port);
27aed4b572SPetr Machata
280714256cSPetr Machata void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
29c934757dSAmit Cohen struct sk_buff *skb, u16 local_port);
300714256cSPetr Machata
31d92e4e6eSPetr Machata void mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
32c934757dSAmit Cohen u16 local_port, u8 message_type,
33d92e4e6eSPetr Machata u8 domain_number, u16 sequence_id,
34d92e4e6eSPetr Machata u64 timestamp);
35d92e4e6eSPetr Machata
3687486427SPetr Machata int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
3787486427SPetr Machata struct hwtstamp_config *config);
3887486427SPetr Machata
3987486427SPetr Machata int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
4087486427SPetr Machata struct hwtstamp_config *config);
4187486427SPetr Machata
425fc17338SShalom Toledo void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
435fc17338SShalom Toledo
4487ee07f8SPetr Machata int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
45*2111375bSKory Maincent struct kernel_ethtool_ts_info *info);
4687ee07f8SPetr Machata
47dc4f3eb0SPetr Machata int mlxsw_sp1_get_stats_count(void);
48dc4f3eb0SPetr Machata void mlxsw_sp1_get_stats_strings(u8 **p);
49dc4f3eb0SPetr Machata void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
50dc4f3eb0SPetr Machata u64 *data, int data_index);
51dc4f3eb0SPetr Machata
5224157bc6SDanielle Ratson int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
5324157bc6SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
5424157bc6SDanielle Ratson struct sk_buff *skb,
5524157bc6SDanielle Ratson const struct mlxsw_tx_info *tx_info);
5624157bc6SDanielle Ratson
57a5bf8e5eSDanielle Ratson struct mlxsw_sp_ptp_clock *
58a5bf8e5eSDanielle Ratson mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
59a5bf8e5eSDanielle Ratson
60a5bf8e5eSDanielle Ratson void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
61a5bf8e5eSDanielle Ratson
62d25ff63aSDanielle Ratson struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
63d25ff63aSDanielle Ratson
64d25ff63aSDanielle Ratson void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
6524157bc6SDanielle Ratson
66382ad0d9SDanielle Ratson void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
67382ad0d9SDanielle Ratson u16 local_port);
68382ad0d9SDanielle Ratson
69382ad0d9SDanielle Ratson void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
70382ad0d9SDanielle Ratson struct sk_buff *skb, u16 local_port);
71382ad0d9SDanielle Ratson
7208ef8bc8SDanielle Ratson int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
7308ef8bc8SDanielle Ratson struct hwtstamp_config *config);
7408ef8bc8SDanielle Ratson
7508ef8bc8SDanielle Ratson int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
7608ef8bc8SDanielle Ratson struct hwtstamp_config *config);
7708ef8bc8SDanielle Ratson
78eba28aafSDanielle Ratson int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
79*2111375bSKory Maincent struct kernel_ethtool_ts_info *info);
80eba28aafSDanielle Ratson
8124157bc6SDanielle Ratson int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
8224157bc6SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
8324157bc6SDanielle Ratson struct sk_buff *skb,
8424157bc6SDanielle Ratson const struct mlxsw_tx_info *tx_info);
8524157bc6SDanielle Ratson
86992aa864SShalom Toledo #else
87992aa864SShalom Toledo
88992aa864SShalom Toledo static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp1_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)89992aa864SShalom Toledo mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
90992aa864SShalom Toledo {
91992aa864SShalom Toledo return NULL;
92992aa864SShalom Toledo }
93992aa864SShalom Toledo
mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)94992aa864SShalom Toledo static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
95992aa864SShalom Toledo {
96992aa864SShalom Toledo }
97992aa864SShalom Toledo
98810256ceSPetr Machata static inline struct mlxsw_sp_ptp_state *
mlxsw_sp1_ptp_init(struct mlxsw_sp * mlxsw_sp)99810256ceSPetr Machata mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
100810256ceSPetr Machata {
101810256ceSPetr Machata return NULL;
102810256ceSPetr Machata }
103810256ceSPetr Machata
mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)104810256ceSPetr Machata static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
105810256ceSPetr Machata {
106810256ceSPetr Machata }
107810256ceSPetr Machata
mlxsw_sp1_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)108aed4b572SPetr Machata static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
109c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
110aed4b572SPetr Machata {
111aed4b572SPetr Machata mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
112aed4b572SPetr Machata }
113aed4b572SPetr Machata
mlxsw_sp1_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)1140714256cSPetr Machata static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
115c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
1160714256cSPetr Machata {
1170714256cSPetr Machata dev_kfree_skb_any(skb);
1180714256cSPetr Machata }
1190714256cSPetr Machata
120d92e4e6eSPetr Machata static inline void
mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp * mlxsw_sp,bool ingress,u16 local_port,u8 message_type,u8 domain_number,u16 sequence_id,u64 timestamp)121d92e4e6eSPetr Machata mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
122c934757dSAmit Cohen u16 local_port, u8 message_type,
123d92e4e6eSPetr Machata u8 domain_number,
124d92e4e6eSPetr Machata u16 sequence_id, u64 timestamp)
125d92e4e6eSPetr Machata {
126d92e4e6eSPetr Machata }
127d92e4e6eSPetr Machata
12887486427SPetr Machata static inline int
mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)12987486427SPetr Machata mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
13087486427SPetr Machata struct hwtstamp_config *config)
13187486427SPetr Machata {
13287486427SPetr Machata return -EOPNOTSUPP;
13387486427SPetr Machata }
13487486427SPetr Machata
13587486427SPetr Machata static inline int
mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)13687486427SPetr Machata mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
13787486427SPetr Machata struct hwtstamp_config *config)
13887486427SPetr Machata {
13987486427SPetr Machata return -EOPNOTSUPP;
14087486427SPetr Machata }
14187486427SPetr Machata
mlxsw_sp1_ptp_shaper_work(struct work_struct * work)1425fc17338SShalom Toledo static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
1435fc17338SShalom Toledo {
1445fc17338SShalom Toledo }
1455fc17338SShalom Toledo
mlxsw_sp1_get_stats_count(void)146dc4f3eb0SPetr Machata static inline int mlxsw_sp1_get_stats_count(void)
147dc4f3eb0SPetr Machata {
148dc4f3eb0SPetr Machata return 0;
149dc4f3eb0SPetr Machata }
150dc4f3eb0SPetr Machata
mlxsw_sp1_get_stats_strings(u8 ** p)151dc4f3eb0SPetr Machata static inline void mlxsw_sp1_get_stats_strings(u8 **p)
152dc4f3eb0SPetr Machata {
153dc4f3eb0SPetr Machata }
154dc4f3eb0SPetr Machata
mlxsw_sp1_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)155dc4f3eb0SPetr Machata static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
156dc4f3eb0SPetr Machata u64 *data, int data_index)
157dc4f3eb0SPetr Machata {
158dc4f3eb0SPetr Machata }
159d25ff63aSDanielle Ratson
16012e09138SAmit Cohen static inline int
mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core * mlxsw_core,struct mlxsw_sp_port * mlxsw_sp_port,struct sk_buff * skb,const struct mlxsw_tx_info * tx_info)16112e09138SAmit Cohen mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
16224157bc6SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
16324157bc6SDanielle Ratson struct sk_buff *skb,
16424157bc6SDanielle Ratson const struct mlxsw_tx_info *tx_info)
16524157bc6SDanielle Ratson {
16624157bc6SDanielle Ratson return -EOPNOTSUPP;
16724157bc6SDanielle Ratson }
16824157bc6SDanielle Ratson
169a5bf8e5eSDanielle Ratson static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp2_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)170a5bf8e5eSDanielle Ratson mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
171a5bf8e5eSDanielle Ratson {
172a5bf8e5eSDanielle Ratson return NULL;
173a5bf8e5eSDanielle Ratson }
174a5bf8e5eSDanielle Ratson
mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)175a5bf8e5eSDanielle Ratson static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
176a5bf8e5eSDanielle Ratson {
177a5bf8e5eSDanielle Ratson }
178a5bf8e5eSDanielle Ratson
179d25ff63aSDanielle Ratson static inline struct mlxsw_sp_ptp_state *
mlxsw_sp2_ptp_init(struct mlxsw_sp * mlxsw_sp)180d25ff63aSDanielle Ratson mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
181d25ff63aSDanielle Ratson {
182d25ff63aSDanielle Ratson return NULL;
183d25ff63aSDanielle Ratson }
184d25ff63aSDanielle Ratson
mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)185d25ff63aSDanielle Ratson static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
186d25ff63aSDanielle Ratson {
187d25ff63aSDanielle Ratson }
18824157bc6SDanielle Ratson
mlxsw_sp2_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)189aed4b572SPetr Machata static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
190c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
191aed4b572SPetr Machata {
192aed4b572SPetr Machata mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
193aed4b572SPetr Machata }
194aed4b572SPetr Machata
mlxsw_sp2_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)1950714256cSPetr Machata static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
196c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
1970714256cSPetr Machata {
1980714256cSPetr Machata dev_kfree_skb_any(skb);
1990714256cSPetr Machata }
2000714256cSPetr Machata
20187486427SPetr Machata static inline int
mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)20287486427SPetr Machata mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
20387486427SPetr Machata struct hwtstamp_config *config)
20487486427SPetr Machata {
20587486427SPetr Machata return -EOPNOTSUPP;
20687486427SPetr Machata }
20787486427SPetr Machata
20887486427SPetr Machata static inline int
mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)20987486427SPetr Machata mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
21087486427SPetr Machata struct hwtstamp_config *config)
21187486427SPetr Machata {
21287486427SPetr Machata return -EOPNOTSUPP;
21387486427SPetr Machata }
21487486427SPetr Machata
21512e09138SAmit Cohen static inline int
mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core * mlxsw_core,struct mlxsw_sp_port * mlxsw_sp_port,struct sk_buff * skb,const struct mlxsw_tx_info * tx_info)21612e09138SAmit Cohen mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
21708ef8bc8SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
21808ef8bc8SDanielle Ratson struct sk_buff *skb,
21908ef8bc8SDanielle Ratson const struct mlxsw_tx_info *tx_info)
22008ef8bc8SDanielle Ratson {
22108ef8bc8SDanielle Ratson return -EOPNOTSUPP;
22208ef8bc8SDanielle Ratson }
22308ef8bc8SDanielle Ratson #endif
22408ef8bc8SDanielle Ratson
mlxsw_sp2_ptp_shaper_work(struct work_struct * work)2255fc17338SShalom Toledo static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
2265fc17338SShalom Toledo {
2275fc17338SShalom Toledo }
2285fc17338SShalom Toledo
mlxsw_sp2_get_stats_count(void)229dc4f3eb0SPetr Machata static inline int mlxsw_sp2_get_stats_count(void)
230dc4f3eb0SPetr Machata {
231dc4f3eb0SPetr Machata return 0;
232dc4f3eb0SPetr Machata }
233dc4f3eb0SPetr Machata
mlxsw_sp2_get_stats_strings(u8 ** p)234dc4f3eb0SPetr Machata static inline void mlxsw_sp2_get_stats_strings(u8 **p)
235dc4f3eb0SPetr Machata {
236dc4f3eb0SPetr Machata }
237dc4f3eb0SPetr Machata
mlxsw_sp2_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)238dc4f3eb0SPetr Machata static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
239dc4f3eb0SPetr Machata u64 *data, int data_index)
240dc4f3eb0SPetr Machata {
241dc4f3eb0SPetr Machata }
242dc4f3eb0SPetr Machata
243992aa864SShalom Toledo #endif
244