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