1 /* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2 /* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
4 #ifndef _MLXSW_SPECTRUM_PTP_H
5 #define _MLXSW_SPECTRUM_PTP_H
7 #include <linux/device.h>
8 #include <linux/rhashtable.h>
12 struct mlxsw_sp_ptp_clock;
14 static inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
16 info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
17 SOF_TIMESTAMPING_SOFTWARE;
22 #if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
24 struct mlxsw_sp_ptp_clock *
25 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
27 void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
29 struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
31 void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
33 void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
36 void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
37 struct sk_buff *skb, u16 local_port);
39 void mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
40 u16 local_port, u8 message_type,
41 u8 domain_number, u16 sequence_id,
44 int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
45 struct hwtstamp_config *config);
47 int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
48 struct hwtstamp_config *config);
50 void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
52 int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
53 struct ethtool_ts_info *info);
55 int mlxsw_sp1_get_stats_count(void);
56 void mlxsw_sp1_get_stats_strings(u8 **p);
57 void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
58 u64 *data, int data_index);
60 int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
61 struct mlxsw_sp_port *mlxsw_sp_port,
63 const struct mlxsw_tx_info *tx_info);
65 struct mlxsw_sp_ptp_clock *
66 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
68 void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
70 struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
72 void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
74 void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
77 void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
78 struct sk_buff *skb, u16 local_port);
80 int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
81 struct hwtstamp_config *config);
83 int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
84 struct hwtstamp_config *config);
86 int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
87 struct ethtool_ts_info *info);
89 int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
90 struct mlxsw_sp_port *mlxsw_sp_port,
92 const struct mlxsw_tx_info *tx_info);
96 static inline struct mlxsw_sp_ptp_clock *
97 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
102 static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
106 static inline struct mlxsw_sp_ptp_state *
107 mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
112 static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
116 static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
117 struct sk_buff *skb, u16 local_port)
119 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
122 static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
123 struct sk_buff *skb, u16 local_port)
125 dev_kfree_skb_any(skb);
129 mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
130 u16 local_port, u8 message_type,
132 u16 sequence_id, u64 timestamp)
137 mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
138 struct hwtstamp_config *config)
144 mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
145 struct hwtstamp_config *config)
150 static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
154 static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
155 struct ethtool_ts_info *info)
157 return mlxsw_sp_ptp_get_ts_info_noptp(info);
160 static inline int mlxsw_sp1_get_stats_count(void)
165 static inline void mlxsw_sp1_get_stats_strings(u8 **p)
169 static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
170 u64 *data, int data_index)
175 mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
176 struct mlxsw_sp_port *mlxsw_sp_port,
178 const struct mlxsw_tx_info *tx_info)
183 static inline struct mlxsw_sp_ptp_clock *
184 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
189 static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
193 static inline struct mlxsw_sp_ptp_state *
194 mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
199 static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
203 static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
204 struct sk_buff *skb, u16 local_port)
206 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
209 static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
210 struct sk_buff *skb, u16 local_port)
212 dev_kfree_skb_any(skb);
216 mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
217 struct hwtstamp_config *config)
223 mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
224 struct hwtstamp_config *config)
229 static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
230 struct ethtool_ts_info *info)
232 return mlxsw_sp_ptp_get_ts_info_noptp(info);
236 mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
237 struct mlxsw_sp_port *mlxsw_sp_port,
239 const struct mlxsw_tx_info *tx_info)
245 static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
249 static inline int mlxsw_sp2_get_stats_count(void)
254 static inline void mlxsw_sp2_get_stats_strings(u8 **p)
258 static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
259 u64 *data, int data_index)