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 
mlxsw_sp_ptp_get_ts_info_noptp(struct ethtool_ts_info * info)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 			   u8 local_port);
35 
36 void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
37 			       struct sk_buff *skb, u8 local_port);
38 
39 void 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 
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 #else
61 
62 static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp1_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)63 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
64 {
65 	return NULL;
66 }
67 
mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)68 static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
69 {
70 }
71 
72 static inline struct mlxsw_sp_ptp_state *
mlxsw_sp1_ptp_init(struct mlxsw_sp * mlxsw_sp)73 mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
74 {
75 	return NULL;
76 }
77 
mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)78 static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
79 {
80 }
81 
mlxsw_sp1_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u8 local_port)82 static 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 
mlxsw_sp1_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u8 local_port)88 static 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 
94 static inline void
mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp * mlxsw_sp,bool ingress,u8 local_port,u8 message_type,u8 domain_number,u16 sequence_id,u64 timestamp)95 mlxsw_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 
102 static inline int
mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)103 mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
104 			   struct hwtstamp_config *config)
105 {
106 	return -EOPNOTSUPP;
107 }
108 
109 static inline int
mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)110 mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
111 			   struct hwtstamp_config *config)
112 {
113 	return -EOPNOTSUPP;
114 }
115 
mlxsw_sp1_ptp_shaper_work(struct work_struct * work)116 static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
117 {
118 }
119 
mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp * mlxsw_sp,struct ethtool_ts_info * info)120 static 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 
mlxsw_sp1_get_stats_count(void)126 static inline int mlxsw_sp1_get_stats_count(void)
127 {
128 	return 0;
129 }
130 
mlxsw_sp1_get_stats_strings(u8 ** p)131 static inline void mlxsw_sp1_get_stats_strings(u8 **p)
132 {
133 }
134 
mlxsw_sp1_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)135 static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
136 				       u64 *data, int data_index)
137 {
138 }
139 #endif
140 
141 static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp2_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)142 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
143 {
144 	return NULL;
145 }
146 
mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)147 static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
148 {
149 }
150 
151 static inline struct mlxsw_sp_ptp_state *
mlxsw_sp2_ptp_init(struct mlxsw_sp * mlxsw_sp)152 mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
153 {
154 	return NULL;
155 }
156 
mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)157 static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
158 {
159 }
160 
mlxsw_sp2_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u8 local_port)161 static 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 
mlxsw_sp2_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u8 local_port)167 static 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 
173 static inline int
mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)174 mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
175 			   struct hwtstamp_config *config)
176 {
177 	return -EOPNOTSUPP;
178 }
179 
180 static inline int
mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct hwtstamp_config * config)181 mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
182 			   struct hwtstamp_config *config)
183 {
184 	return -EOPNOTSUPP;
185 }
186 
mlxsw_sp2_ptp_shaper_work(struct work_struct * work)187 static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
188 {
189 }
190 
mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp * mlxsw_sp,struct ethtool_ts_info * info)191 static 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 
mlxsw_sp2_get_stats_count(void)197 static inline int mlxsw_sp2_get_stats_count(void)
198 {
199 	return 0;
200 }
201 
mlxsw_sp2_get_stats_strings(u8 ** p)202 static inline void mlxsw_sp2_get_stats_strings(u8 **p)
203 {
204 }
205 
mlxsw_sp2_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)206 static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
207 				       u64 *data, int data_index)
208 {
209 }
210 
211 #endif
212