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
mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info * info)1487ee07f8SPetr Machata static inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
1587ee07f8SPetr Machata {
1687ee07f8SPetr Machata info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
1787ee07f8SPetr Machata SOF_TIMESTAMPING_SOFTWARE;
1887ee07f8SPetr Machata info->phc_index = -1;
1987ee07f8SPetr Machata return 0;
2087ee07f8SPetr Machata }
2187ee07f8SPetr Machata
22992aa864SShalom Toledo #if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
23992aa864SShalom Toledo
24992aa864SShalom Toledo struct mlxsw_sp_ptp_clock *
25992aa864SShalom Toledo mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
26992aa864SShalom Toledo
27992aa864SShalom Toledo void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
28992aa864SShalom Toledo
29810256ceSPetr Machata struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
30810256ceSPetr Machata
31810256ceSPetr Machata void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
32810256ceSPetr Machata
33aed4b572SPetr Machata void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
34c934757dSAmit Cohen u16 local_port);
35aed4b572SPetr Machata
360714256cSPetr Machata void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
37c934757dSAmit Cohen struct sk_buff *skb, u16 local_port);
380714256cSPetr Machata
39d92e4e6eSPetr Machata void mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
40c934757dSAmit Cohen u16 local_port, u8 message_type,
41d92e4e6eSPetr Machata u8 domain_number, u16 sequence_id,
42d92e4e6eSPetr Machata u64 timestamp);
43d92e4e6eSPetr Machata
4487486427SPetr Machata int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
4587486427SPetr Machata struct hwtstamp_config *config);
4687486427SPetr Machata
4787486427SPetr Machata int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
4887486427SPetr Machata struct hwtstamp_config *config);
4987486427SPetr Machata
505fc17338SShalom Toledo void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
515fc17338SShalom Toledo
5287ee07f8SPetr Machata int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
5387ee07f8SPetr Machata struct ethtool_ts_info *info);
5487ee07f8SPetr Machata
55dc4f3eb0SPetr Machata int mlxsw_sp1_get_stats_count(void);
56dc4f3eb0SPetr Machata void mlxsw_sp1_get_stats_strings(u8 **p);
57dc4f3eb0SPetr Machata void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
58dc4f3eb0SPetr Machata u64 *data, int data_index);
59dc4f3eb0SPetr Machata
6024157bc6SDanielle Ratson int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
6124157bc6SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
6224157bc6SDanielle Ratson struct sk_buff *skb,
6324157bc6SDanielle Ratson const struct mlxsw_tx_info *tx_info);
6424157bc6SDanielle Ratson
65a5bf8e5eSDanielle Ratson struct mlxsw_sp_ptp_clock *
66a5bf8e5eSDanielle Ratson mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
67a5bf8e5eSDanielle Ratson
68a5bf8e5eSDanielle Ratson void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
69a5bf8e5eSDanielle Ratson
70d25ff63aSDanielle Ratson struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
71d25ff63aSDanielle Ratson
72d25ff63aSDanielle Ratson void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
7324157bc6SDanielle Ratson
74382ad0d9SDanielle Ratson void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
75382ad0d9SDanielle Ratson u16 local_port);
76382ad0d9SDanielle Ratson
77382ad0d9SDanielle Ratson void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
78382ad0d9SDanielle Ratson struct sk_buff *skb, u16 local_port);
79382ad0d9SDanielle Ratson
8008ef8bc8SDanielle Ratson int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
8108ef8bc8SDanielle Ratson struct hwtstamp_config *config);
8208ef8bc8SDanielle Ratson
8308ef8bc8SDanielle Ratson int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
8408ef8bc8SDanielle Ratson struct hwtstamp_config *config);
8508ef8bc8SDanielle Ratson
86eba28aafSDanielle Ratson int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
87eba28aafSDanielle Ratson struct ethtool_ts_info *info);
88eba28aafSDanielle Ratson
8924157bc6SDanielle Ratson int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
9024157bc6SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
9124157bc6SDanielle Ratson struct sk_buff *skb,
9224157bc6SDanielle Ratson const struct mlxsw_tx_info *tx_info);
9324157bc6SDanielle Ratson
94992aa864SShalom Toledo #else
95992aa864SShalom Toledo
96992aa864SShalom Toledo static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp1_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)97992aa864SShalom Toledo mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
98992aa864SShalom Toledo {
99992aa864SShalom Toledo return NULL;
100992aa864SShalom Toledo }
101992aa864SShalom Toledo
mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)102992aa864SShalom Toledo static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
103992aa864SShalom Toledo {
104992aa864SShalom Toledo }
105992aa864SShalom Toledo
106810256ceSPetr Machata static inline struct mlxsw_sp_ptp_state *
mlxsw_sp1_ptp_init(struct mlxsw_sp * mlxsw_sp)107810256ceSPetr Machata mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
108810256ceSPetr Machata {
109810256ceSPetr Machata return NULL;
110810256ceSPetr Machata }
111810256ceSPetr Machata
mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)112810256ceSPetr Machata static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
113810256ceSPetr Machata {
114810256ceSPetr Machata }
115810256ceSPetr Machata
mlxsw_sp1_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)116aed4b572SPetr Machata static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
117c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
118aed4b572SPetr Machata {
119aed4b572SPetr Machata mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
120aed4b572SPetr Machata }
121aed4b572SPetr Machata
mlxsw_sp1_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)1220714256cSPetr Machata static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
123c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
1240714256cSPetr Machata {
1250714256cSPetr Machata dev_kfree_skb_any(skb);
1260714256cSPetr Machata }
1270714256cSPetr Machata
128d92e4e6eSPetr 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)129d92e4e6eSPetr Machata mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
130c934757dSAmit Cohen u16 local_port, u8 message_type,
131d92e4e6eSPetr Machata u8 domain_number,
132d92e4e6eSPetr Machata u16 sequence_id, u64 timestamp)
133d92e4e6eSPetr Machata {
134d92e4e6eSPetr Machata }
135d92e4e6eSPetr Machata
13687486427SPetr Machata static inline int
mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)13787486427SPetr Machata mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
13887486427SPetr Machata struct hwtstamp_config *config)
13987486427SPetr Machata {
14087486427SPetr Machata return -EOPNOTSUPP;
14187486427SPetr Machata }
14287486427SPetr Machata
14387486427SPetr Machata static inline int
mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)14487486427SPetr Machata mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
14587486427SPetr Machata struct hwtstamp_config *config)
14687486427SPetr Machata {
14787486427SPetr Machata return -EOPNOTSUPP;
14887486427SPetr Machata }
14987486427SPetr Machata
mlxsw_sp1_ptp_shaper_work(struct work_struct * work)1505fc17338SShalom Toledo static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
1515fc17338SShalom Toledo {
1525fc17338SShalom Toledo }
1535fc17338SShalom Toledo
mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp * mlxsw_sp,struct ethtool_ts_info * info)15487ee07f8SPetr Machata static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
15587ee07f8SPetr Machata struct ethtool_ts_info *info)
15687ee07f8SPetr Machata {
15787ee07f8SPetr Machata return mlxsw_sp_ptp_get_ts_info_noptp(info);
15887ee07f8SPetr Machata }
15987ee07f8SPetr Machata
mlxsw_sp1_get_stats_count(void)160dc4f3eb0SPetr Machata static inline int mlxsw_sp1_get_stats_count(void)
161dc4f3eb0SPetr Machata {
162dc4f3eb0SPetr Machata return 0;
163dc4f3eb0SPetr Machata }
164dc4f3eb0SPetr Machata
mlxsw_sp1_get_stats_strings(u8 ** p)165dc4f3eb0SPetr Machata static inline void mlxsw_sp1_get_stats_strings(u8 **p)
166dc4f3eb0SPetr Machata {
167dc4f3eb0SPetr Machata }
168dc4f3eb0SPetr Machata
mlxsw_sp1_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)169dc4f3eb0SPetr Machata static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
170dc4f3eb0SPetr Machata u64 *data, int data_index)
171dc4f3eb0SPetr Machata {
172dc4f3eb0SPetr Machata }
173d25ff63aSDanielle Ratson
174*12e09138SAmit 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)175*12e09138SAmit Cohen mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
17624157bc6SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
17724157bc6SDanielle Ratson struct sk_buff *skb,
17824157bc6SDanielle Ratson const struct mlxsw_tx_info *tx_info)
17924157bc6SDanielle Ratson {
18024157bc6SDanielle Ratson return -EOPNOTSUPP;
18124157bc6SDanielle Ratson }
18224157bc6SDanielle Ratson
183a5bf8e5eSDanielle Ratson static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp2_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)184a5bf8e5eSDanielle Ratson mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
185a5bf8e5eSDanielle Ratson {
186a5bf8e5eSDanielle Ratson return NULL;
187a5bf8e5eSDanielle Ratson }
188a5bf8e5eSDanielle Ratson
mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)189a5bf8e5eSDanielle Ratson static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
190a5bf8e5eSDanielle Ratson {
191a5bf8e5eSDanielle Ratson }
192a5bf8e5eSDanielle Ratson
193d25ff63aSDanielle Ratson static inline struct mlxsw_sp_ptp_state *
mlxsw_sp2_ptp_init(struct mlxsw_sp * mlxsw_sp)194d25ff63aSDanielle Ratson mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
195d25ff63aSDanielle Ratson {
196d25ff63aSDanielle Ratson return NULL;
197d25ff63aSDanielle Ratson }
198d25ff63aSDanielle Ratson
mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)199d25ff63aSDanielle Ratson static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
200d25ff63aSDanielle Ratson {
201d25ff63aSDanielle Ratson }
20224157bc6SDanielle Ratson
mlxsw_sp2_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)203aed4b572SPetr Machata static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
204c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
205aed4b572SPetr Machata {
206aed4b572SPetr Machata mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
207aed4b572SPetr Machata }
208aed4b572SPetr Machata
mlxsw_sp2_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)2090714256cSPetr Machata static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
210c934757dSAmit Cohen struct sk_buff *skb, u16 local_port)
2110714256cSPetr Machata {
2120714256cSPetr Machata dev_kfree_skb_any(skb);
2130714256cSPetr Machata }
2140714256cSPetr Machata
21587486427SPetr Machata static inline int
mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)21687486427SPetr Machata mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
21787486427SPetr Machata struct hwtstamp_config *config)
21887486427SPetr Machata {
21987486427SPetr Machata return -EOPNOTSUPP;
22087486427SPetr Machata }
22187486427SPetr Machata
22287486427SPetr Machata static inline int
mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)22387486427SPetr Machata mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
22487486427SPetr Machata struct hwtstamp_config *config)
22587486427SPetr Machata {
22687486427SPetr Machata return -EOPNOTSUPP;
22787486427SPetr Machata }
22887486427SPetr Machata
mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp * mlxsw_sp,struct ethtool_ts_info * info)229eba28aafSDanielle Ratson static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
230eba28aafSDanielle Ratson struct ethtool_ts_info *info)
231eba28aafSDanielle Ratson {
232eba28aafSDanielle Ratson return mlxsw_sp_ptp_get_ts_info_noptp(info);
233eba28aafSDanielle Ratson }
234eba28aafSDanielle Ratson
235*12e09138SAmit 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)236*12e09138SAmit Cohen mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
23708ef8bc8SDanielle Ratson struct mlxsw_sp_port *mlxsw_sp_port,
23808ef8bc8SDanielle Ratson struct sk_buff *skb,
23908ef8bc8SDanielle Ratson const struct mlxsw_tx_info *tx_info)
24008ef8bc8SDanielle Ratson {
24108ef8bc8SDanielle Ratson return -EOPNOTSUPP;
24208ef8bc8SDanielle Ratson }
24308ef8bc8SDanielle Ratson #endif
24408ef8bc8SDanielle Ratson
mlxsw_sp2_ptp_shaper_work(struct work_struct * work)2455fc17338SShalom Toledo static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
2465fc17338SShalom Toledo {
2475fc17338SShalom Toledo }
2485fc17338SShalom Toledo
mlxsw_sp2_get_stats_count(void)249dc4f3eb0SPetr Machata static inline int mlxsw_sp2_get_stats_count(void)
250dc4f3eb0SPetr Machata {
251dc4f3eb0SPetr Machata return 0;
252dc4f3eb0SPetr Machata }
253dc4f3eb0SPetr Machata
mlxsw_sp2_get_stats_strings(u8 ** p)254dc4f3eb0SPetr Machata static inline void mlxsw_sp2_get_stats_strings(u8 **p)
255dc4f3eb0SPetr Machata {
256dc4f3eb0SPetr Machata }
257dc4f3eb0SPetr Machata
mlxsw_sp2_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)258dc4f3eb0SPetr Machata static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
259dc4f3eb0SPetr Machata u64 *data, int data_index)
260dc4f3eb0SPetr Machata {
261dc4f3eb0SPetr Machata }
262dc4f3eb0SPetr Machata
263992aa864SShalom Toledo #endif
264