1/* SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 */
2/* Copyright (c) 2019 Mellanox Technologies. All rights reserved */
3
4#ifndef _MLXSW_SPECTRUM_PTP_H
5#define _MLXSW_SPECTRUM_PTP_H
6
7#include <linux/device.h>
8#include <linux/rhashtable.h>
9
10struct mlxsw_sp;
11struct mlxsw_sp_port;
12struct mlxsw_sp_ptp_clock;
13
14enum {
15	MLXSW_SP_PTP_MESSAGE_TYPE_SYNC,
16	MLXSW_SP_PTP_MESSAGE_TYPE_DELAY_REQ,
17	MLXSW_SP_PTP_MESSAGE_TYPE_PDELAY_REQ,
18	MLXSW_SP_PTP_MESSAGE_TYPE_PDELAY_RESP,
19};
20
21static inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
22{
23	info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
24				SOF_TIMESTAMPING_SOFTWARE;
25	info->phc_index = -1;
26	return 0;
27}
28
29#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
30
31struct mlxsw_sp_ptp_clock *
32mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
33
34void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
35
36struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
37
38void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
39
40void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
41			   u8 local_port);
42
43void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
44			       struct sk_buff *skb, u8 local_port);
45
46void mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
47				 u8 local_port, u8 message_type,
48				 u8 domain_number, u16 sequence_id,
49				 u64 timestamp);
50
51int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
52			       struct hwtstamp_config *config);
53
54int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
55			       struct hwtstamp_config *config);
56
57void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
58
59int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
60			      struct ethtool_ts_info *info);
61
62int mlxsw_sp1_get_stats_count(void);
63void mlxsw_sp1_get_stats_strings(u8 **p);
64void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
65			 u64 *data, int data_index);
66
67#else
68
69static inline struct mlxsw_sp_ptp_clock *
70mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
71{
72	return NULL;
73}
74
75static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
76{
77}
78
79static inline struct mlxsw_sp_ptp_state *
80mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
81{
82	return NULL;
83}
84
85static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
86{
87}
88
89static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
90					 struct sk_buff *skb, u8 local_port)
91{
92	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
93}
94
95static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
96					     struct sk_buff *skb, u8 local_port)
97{
98	dev_kfree_skb_any(skb);
99}
100
101static inline void
102mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
103			    u8 local_port, u8 message_type,
104			    u8 domain_number,
105			    u16 sequence_id, u64 timestamp)
106{
107}
108
109static inline int
110mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
111			   struct hwtstamp_config *config)
112{
113	return -EOPNOTSUPP;
114}
115
116static inline int
117mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
118			   struct hwtstamp_config *config)
119{
120	return -EOPNOTSUPP;
121}
122
123static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
124{
125}
126
127static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
128					    struct ethtool_ts_info *info)
129{
130	return mlxsw_sp_ptp_get_ts_info_noptp(info);
131}
132
133static inline int mlxsw_sp1_get_stats_count(void)
134{
135	return 0;
136}
137
138static inline void mlxsw_sp1_get_stats_strings(u8 **p)
139{
140}
141
142static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
143				       u64 *data, int data_index)
144{
145}
146#endif
147
148static inline struct mlxsw_sp_ptp_clock *
149mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
150{
151	return NULL;
152}
153
154static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
155{
156}
157
158static inline struct mlxsw_sp_ptp_state *
159mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
160{
161	return NULL;
162}
163
164static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
165{
166}
167
168static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
169					 struct sk_buff *skb, u8 local_port)
170{
171	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
172}
173
174static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
175					     struct sk_buff *skb, u8 local_port)
176{
177	dev_kfree_skb_any(skb);
178}
179
180static inline int
181mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
182			   struct hwtstamp_config *config)
183{
184	return -EOPNOTSUPP;
185}
186
187static inline int
188mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
189			   struct hwtstamp_config *config)
190{
191	return -EOPNOTSUPP;
192}
193
194static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
195{
196}
197
198static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
199					    struct ethtool_ts_info *info)
200{
201	return mlxsw_sp_ptp_get_ts_info_noptp(info);
202}
203
204static inline int mlxsw_sp2_get_stats_count(void)
205{
206	return 0;
207}
208
209static inline void mlxsw_sp2_get_stats_strings(u8 **p)
210{
211}
212
213static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
214				       u64 *data, int data_index)
215{
216}
217
218#endif
219