clk: baikal-t1: Convert to platform device driver
[platform/kernel/linux-starfive.git] / drivers / net / ethernet / mellanox / mlxsw / spectrum_ptp.h
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 static 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
24 struct mlxsw_sp_ptp_clock *
25 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
26
27 void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
28
29 struct mlxsw_sp_ptp_state *mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp);
30
31 void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
32
33 void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
34                            u16 local_port);
35
36 void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
37                                struct sk_buff *skb, u16 local_port);
38
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,
42                                  u64 timestamp);
43
44 int mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
45                                struct hwtstamp_config *config);
46
47 int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
48                                struct hwtstamp_config *config);
49
50 void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
51
52 int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
53                               struct ethtool_ts_info *info);
54
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);
59
60 int 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
65 struct mlxsw_sp_ptp_clock *
66 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
67
68 void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
69
70 struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
71
72 void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
73
74 void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
75                            u16 local_port);
76
77 void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
78                                struct sk_buff *skb, u16 local_port);
79
80 int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
81                                struct hwtstamp_config *config);
82
83 int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
84                                struct hwtstamp_config *config);
85
86 int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
87                               struct ethtool_ts_info *info);
88
89 int 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
96 static inline struct mlxsw_sp_ptp_clock *
97 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
98 {
99         return NULL;
100 }
101
102 static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
103 {
104 }
105
106 static inline struct mlxsw_sp_ptp_state *
107 mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
108 {
109         return NULL;
110 }
111
112 static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
113 {
114 }
115
116 static 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
122 static 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
128 static inline void
129 mlxsw_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
136 static inline int
137 mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
138                            struct hwtstamp_config *config)
139 {
140         return -EOPNOTSUPP;
141 }
142
143 static inline int
144 mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
145                            struct hwtstamp_config *config)
146 {
147         return -EOPNOTSUPP;
148 }
149
150 static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
151 {
152 }
153
154 static 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
160 static inline int mlxsw_sp1_get_stats_count(void)
161 {
162         return 0;
163 }
164
165 static inline void mlxsw_sp1_get_stats_strings(u8 **p)
166 {
167 }
168
169 static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
170                                        u64 *data, int data_index)
171 {
172 }
173
174 int mlxsw_sp_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
175                                  struct mlxsw_sp_port *mlxsw_sp_port,
176                                  struct sk_buff *skb,
177                                  const struct mlxsw_tx_info *tx_info)
178 {
179         return -EOPNOTSUPP;
180 }
181
182 static inline struct mlxsw_sp_ptp_clock *
183 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
184 {
185         return NULL;
186 }
187
188 static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
189 {
190 }
191
192 static inline struct mlxsw_sp_ptp_state *
193 mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
194 {
195         return NULL;
196 }
197
198 static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
199 {
200 }
201
202 static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
203                                          struct sk_buff *skb, u16 local_port)
204 {
205         mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
206 }
207
208 static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
209                                              struct sk_buff *skb, u16 local_port)
210 {
211         dev_kfree_skb_any(skb);
212 }
213
214 static inline int
215 mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
216                            struct hwtstamp_config *config)
217 {
218         return -EOPNOTSUPP;
219 }
220
221 static inline int
222 mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
223                            struct hwtstamp_config *config)
224 {
225         return -EOPNOTSUPP;
226 }
227
228 static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
229                                             struct ethtool_ts_info *info)
230 {
231         return mlxsw_sp_ptp_get_ts_info_noptp(info);
232 }
233
234 int mlxsw_sp2_ptp_txhdr_construct(struct mlxsw_core *mlxsw_core,
235                                   struct mlxsw_sp_port *mlxsw_sp_port,
236                                   struct sk_buff *skb,
237                                   const struct mlxsw_tx_info *tx_info)
238 {
239         return -EOPNOTSUPP;
240 }
241 #endif
242
243 static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
244 {
245 }
246
247 static inline int mlxsw_sp2_get_stats_count(void)
248 {
249         return 0;
250 }
251
252 static inline void mlxsw_sp2_get_stats_strings(u8 **p)
253 {
254 }
255
256 static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
257                                        u64 *data, int data_index)
258 {
259 }
260
261 #endif