Loading...
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
14static inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
15{
16 info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
17 SOF_TIMESTAMPING_SOFTWARE;
18 info->phc_index = -1;
19 return 0;
20}
21
22#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
23
24struct mlxsw_sp_ptp_clock *
25mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
26
27void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
28
29struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
30
31void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
32
33void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
34 u16 local_port);
35
36void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
37 struct sk_buff *skb, u16 local_port);
38
39void 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,
42 u64 timestamp);
43
44int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
45 struct hwtstamp_config *config);
46
47int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
48 struct hwtstamp_config *config);
49
50void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
51
52int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
53 struct ethtool_ts_info *info);
54
55int mlxsw_sp1_get_stats_count(void);
56void mlxsw_sp1_get_stats_strings(u8 **p);
57void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
58 u64 *data, int data_index);
59
60int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
61 struct mlxsw_sp_port *mlxsw_sp_port,
62 struct sk_buff *skb,
63 const struct mlxsw_tx_info *tx_info);
64
65struct mlxsw_sp_ptp_clock *
66mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
67
68void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
69
70struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
71
72void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
73
74void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
75 u16 local_port);
76
77void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
78 struct sk_buff *skb, u16 local_port);
79
80int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
81 struct hwtstamp_config *config);
82
83int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
84 struct hwtstamp_config *config);
85
86int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
87 struct ethtool_ts_info *info);
88
89int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
90 struct mlxsw_sp_port *mlxsw_sp_port,
91 struct sk_buff *skb,
92 const struct mlxsw_tx_info *tx_info);
93
94#else
95
96static inline struct mlxsw_sp_ptp_clock *
97mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
98{
99 return NULL;
100}
101
102static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
103{
104}
105
106static inline struct mlxsw_sp_ptp_state *
107mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
108{
109 return NULL;
110}
111
112static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
113{
114}
115
116static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
117 struct sk_buff *skb, u16 local_port)
118{
119 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
120}
121
122static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
123 struct sk_buff *skb, u16 local_port)
124{
125 dev_kfree_skb_any(skb);
126}
127
128static inline void
129mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
130 u16 local_port, u8 message_type,
131 u8 domain_number,
132 u16 sequence_id, u64 timestamp)
133{
134}
135
136static inline int
137mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
138 struct hwtstamp_config *config)
139{
140 return -EOPNOTSUPP;
141}
142
143static inline int
144mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
145 struct hwtstamp_config *config)
146{
147 return -EOPNOTSUPP;
148}
149
150static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
151{
152}
153
154static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
155 struct ethtool_ts_info *info)
156{
157 return mlxsw_sp_ptp_get_ts_info_noptp(info);
158}
159
160static inline int mlxsw_sp1_get_stats_count(void)
161{
162 return 0;
163}
164
165static inline void mlxsw_sp1_get_stats_strings(u8 **p)
166{
167}
168
169static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
170 u64 *data, int data_index)
171{
172}
173
174static inline int
175mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
176 struct mlxsw_sp_port *mlxsw_sp_port,
177 struct sk_buff *skb,
178 const struct mlxsw_tx_info *tx_info)
179{
180 return -EOPNOTSUPP;
181}
182
183static inline struct mlxsw_sp_ptp_clock *
184mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
185{
186 return NULL;
187}
188
189static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
190{
191}
192
193static inline struct mlxsw_sp_ptp_state *
194mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
195{
196 return NULL;
197}
198
199static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
200{
201}
202
203static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
204 struct sk_buff *skb, u16 local_port)
205{
206 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
207}
208
209static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
210 struct sk_buff *skb, u16 local_port)
211{
212 dev_kfree_skb_any(skb);
213}
214
215static inline int
216mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
217 struct hwtstamp_config *config)
218{
219 return -EOPNOTSUPP;
220}
221
222static inline int
223mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
224 struct hwtstamp_config *config)
225{
226 return -EOPNOTSUPP;
227}
228
229static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
230 struct ethtool_ts_info *info)
231{
232 return mlxsw_sp_ptp_get_ts_info_noptp(info);
233}
234
235static inline int
236mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
237 struct mlxsw_sp_port *mlxsw_sp_port,
238 struct sk_buff *skb,
239 const struct mlxsw_tx_info *tx_info)
240{
241 return -EOPNOTSUPP;
242}
243#endif
244
245static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
246{
247}
248
249static inline int mlxsw_sp2_get_stats_count(void)
250{
251 return 0;
252}
253
254static inline void mlxsw_sp2_get_stats_strings(u8 **p)
255{
256}
257
258static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
259 u64 *data, int data_index)
260{
261}
262
263#endif
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
14static inline int mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info *info)
15{
16 info->so_timestamping = SOF_TIMESTAMPING_RX_SOFTWARE |
17 SOF_TIMESTAMPING_SOFTWARE;
18 info->phc_index = -1;
19 return 0;
20}
21
22#if IS_REACHABLE(CONFIG_PTP_1588_CLOCK)
23
24struct mlxsw_sp_ptp_clock *
25mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
26
27void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
28
29struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
30
31void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
32
33void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
34 u8 local_port);
35
36void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
37 struct sk_buff *skb, u8 local_port);
38
39void mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
40 u8 local_port, u8 message_type,
41 u8 domain_number, u16 sequence_id,
42 u64 timestamp);
43
44int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
45 struct hwtstamp_config *config);
46
47int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
48 struct hwtstamp_config *config);
49
50void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
51
52int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
53 struct ethtool_ts_info *info);
54
55int mlxsw_sp1_get_stats_count(void);
56void mlxsw_sp1_get_stats_strings(u8 **p);
57void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
58 u64 *data, int data_index);
59
60#else
61
62static inline struct mlxsw_sp_ptp_clock *
63mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
64{
65 return NULL;
66}
67
68static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
69{
70}
71
72static inline struct mlxsw_sp_ptp_state *
73mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
74{
75 return NULL;
76}
77
78static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
79{
80}
81
82static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
83 struct sk_buff *skb, u8 local_port)
84{
85 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
86}
87
88static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
89 struct sk_buff *skb, u8 local_port)
90{
91 dev_kfree_skb_any(skb);
92}
93
94static inline void
95mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
96 u8 local_port, u8 message_type,
97 u8 domain_number,
98 u16 sequence_id, u64 timestamp)
99{
100}
101
102static inline int
103mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
104 struct hwtstamp_config *config)
105{
106 return -EOPNOTSUPP;
107}
108
109static inline int
110mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
111 struct hwtstamp_config *config)
112{
113 return -EOPNOTSUPP;
114}
115
116static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
117{
118}
119
120static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
121 struct ethtool_ts_info *info)
122{
123 return mlxsw_sp_ptp_get_ts_info_noptp(info);
124}
125
126static inline int mlxsw_sp1_get_stats_count(void)
127{
128 return 0;
129}
130
131static inline void mlxsw_sp1_get_stats_strings(u8 **p)
132{
133}
134
135static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
136 u64 *data, int data_index)
137{
138}
139#endif
140
141static inline struct mlxsw_sp_ptp_clock *
142mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
143{
144 return NULL;
145}
146
147static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
148{
149}
150
151static inline struct mlxsw_sp_ptp_state *
152mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
153{
154 return NULL;
155}
156
157static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
158{
159}
160
161static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
162 struct sk_buff *skb, u8 local_port)
163{
164 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
165}
166
167static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
168 struct sk_buff *skb, u8 local_port)
169{
170 dev_kfree_skb_any(skb);
171}
172
173static inline int
174mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
175 struct hwtstamp_config *config)
176{
177 return -EOPNOTSUPP;
178}
179
180static inline int
181mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
182 struct hwtstamp_config *config)
183{
184 return -EOPNOTSUPP;
185}
186
187static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
188{
189}
190
191static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
192 struct ethtool_ts_info *info)
193{
194 return mlxsw_sp_ptp_get_ts_info_noptp(info);
195}
196
197static inline int mlxsw_sp2_get_stats_count(void)
198{
199 return 0;
200}
201
202static inline void mlxsw_sp2_get_stats_strings(u8 **p)
203{
204}
205
206static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
207 u64 *data, int data_index)
208{
209}
210
211#endif