xref: /linux/drivers/net/ethernet/mellanox/mlxsw/spectrum_ptp.h (revision ab93e0dd72c37d378dd936f031ffb83ff2bd87ce)
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 kernel_hwtstamp_config *config);
38 
39 int mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
40 			       struct kernel_hwtstamp_config *config,
41 			       struct netlink_ext_ack *extack);
42 
43 void mlxsw_sp1_ptp_shaper_work(struct work_struct *work);
44 
45 int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
46 			      struct kernel_ethtool_ts_info *info);
47 
48 int mlxsw_sp1_get_stats_count(void);
49 void mlxsw_sp1_get_stats_strings(u8 **p);
50 void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
51 			 u64 *data, int data_index);
52 
53 struct mlxsw_sp_ptp_clock *
54 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev);
55 
56 void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock);
57 
58 struct mlxsw_sp_ptp_state *mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp);
59 
60 void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state);
61 
62 void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, struct sk_buff *skb,
63 			   u16 local_port);
64 
65 void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
66 			       struct sk_buff *skb, u16 local_port);
67 
68 int mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
69 			       struct kernel_hwtstamp_config *config);
70 
71 int mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
72 			       struct kernel_hwtstamp_config *config,
73 			       struct netlink_ext_ack *extack);
74 
75 int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp,
76 			      struct kernel_ethtool_ts_info *info);
77 
78 #else
79 
80 static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp1_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)81 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
82 {
83 	return NULL;
84 }
85 
mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)86 static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
87 {
88 }
89 
90 static inline struct mlxsw_sp_ptp_state *
mlxsw_sp1_ptp_init(struct mlxsw_sp * mlxsw_sp)91 mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp)
92 {
93 	return NULL;
94 }
95 
mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)96 static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
97 {
98 }
99 
mlxsw_sp1_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)100 static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp,
101 					 struct sk_buff *skb, u16 local_port)
102 {
103 	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
104 }
105 
mlxsw_sp1_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)106 static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
107 					     struct sk_buff *skb, u16 local_port)
108 {
109 	dev_kfree_skb_any(skb);
110 }
111 
112 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)113 mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress,
114 			    u16 local_port, u8 message_type,
115 			    u8 domain_number,
116 			    u16 sequence_id, u64 timestamp)
117 {
118 }
119 
120 static inline int
mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct kernel_hwtstamp_config * config)121 mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
122 			   struct kernel_hwtstamp_config *config)
123 {
124 	return -EOPNOTSUPP;
125 }
126 
127 static inline int
mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct kernel_hwtstamp_config * config,struct netlink_ext_ack * extack)128 mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
129 			   struct kernel_hwtstamp_config *config,
130 			   struct netlink_ext_ack *extack)
131 {
132 	return -EOPNOTSUPP;
133 }
134 
mlxsw_sp1_ptp_shaper_work(struct work_struct * work)135 static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work)
136 {
137 }
138 
mlxsw_sp1_get_stats_count(void)139 static inline int mlxsw_sp1_get_stats_count(void)
140 {
141 	return 0;
142 }
143 
mlxsw_sp1_get_stats_strings(u8 ** p)144 static inline void mlxsw_sp1_get_stats_strings(u8 **p)
145 {
146 }
147 
mlxsw_sp1_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)148 static inline void mlxsw_sp1_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
149 				       u64 *data, int data_index)
150 {
151 }
152 
153 static inline struct mlxsw_sp_ptp_clock *
mlxsw_sp2_ptp_clock_init(struct mlxsw_sp * mlxsw_sp,struct device * dev)154 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev)
155 {
156 	return NULL;
157 }
158 
mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock * clock)159 static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock)
160 {
161 }
162 
163 static inline struct mlxsw_sp_ptp_state *
mlxsw_sp2_ptp_init(struct mlxsw_sp * mlxsw_sp)164 mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp)
165 {
166 	return NULL;
167 }
168 
mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state * ptp_state)169 static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state)
170 {
171 }
172 
mlxsw_sp2_ptp_receive(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)173 static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp,
174 					 struct sk_buff *skb, u16 local_port)
175 {
176 	mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp);
177 }
178 
mlxsw_sp2_ptp_transmitted(struct mlxsw_sp * mlxsw_sp,struct sk_buff * skb,u16 local_port)179 static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp,
180 					     struct sk_buff *skb, u16 local_port)
181 {
182 	dev_kfree_skb_any(skb);
183 }
184 
185 static inline int
mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port * mlxsw_sp_port,struct kernel_hwtstamp_config * config)186 mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port,
187 			   struct kernel_hwtstamp_config *config)
188 {
189 	return -EOPNOTSUPP;
190 }
191 
192 static inline int
mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port * mlxsw_sp_port,struct kernel_hwtstamp_config * config,struct netlink_ext_ack * extack)193 mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port,
194 			   struct kernel_hwtstamp_config *config,
195 			   struct netlink_ext_ack *extack)
196 {
197 	return -EOPNOTSUPP;
198 }
199 #endif
200 
mlxsw_sp2_ptp_shaper_work(struct work_struct * work)201 static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work)
202 {
203 }
204 
mlxsw_sp2_get_stats_count(void)205 static inline int mlxsw_sp2_get_stats_count(void)
206 {
207 	return 0;
208 }
209 
mlxsw_sp2_get_stats_strings(u8 ** p)210 static inline void mlxsw_sp2_get_stats_strings(u8 **p)
211 {
212 }
213 
mlxsw_sp2_get_stats(struct mlxsw_sp_port * mlxsw_sp_port,u64 * data,int data_index)214 static inline void mlxsw_sp2_get_stats(struct mlxsw_sp_port *mlxsw_sp_port,
215 				       u64 *data, int data_index)
216 {
217 }
218 
219 #endif
220