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