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