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 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 #else 63 64 static inline struct mlxsw_sp_ptp_clock * 65 mlxsw_sp1_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev) 66 { 67 return NULL; 68 } 69 70 static inline void mlxsw_sp1_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock) 71 { 72 } 73 74 static inline struct mlxsw_sp_ptp_state * 75 mlxsw_sp1_ptp_init(struct mlxsw_sp *mlxsw_sp) 76 { 77 return NULL; 78 } 79 80 static inline void mlxsw_sp1_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state) 81 { 82 } 83 84 static inline void mlxsw_sp1_ptp_receive(struct mlxsw_sp *mlxsw_sp, 85 struct sk_buff *skb, u8 local_port) 86 { 87 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp); 88 } 89 90 static inline void mlxsw_sp1_ptp_transmitted(struct mlxsw_sp *mlxsw_sp, 91 struct sk_buff *skb, u8 local_port) 92 { 93 dev_kfree_skb_any(skb); 94 } 95 96 static inline void 97 mlxsw_sp1_ptp_got_timestamp(struct mlxsw_sp *mlxsw_sp, bool ingress, 98 u8 local_port, u8 message_type, 99 u8 domain_number, 100 u16 sequence_id, u64 timestamp) 101 { 102 } 103 104 static inline int 105 mlxsw_sp1_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port, 106 struct hwtstamp_config *config) 107 { 108 return -EOPNOTSUPP; 109 } 110 111 static inline int 112 mlxsw_sp1_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port, 113 struct hwtstamp_config *config) 114 { 115 return -EOPNOTSUPP; 116 } 117 118 static inline void mlxsw_sp1_ptp_shaper_work(struct work_struct *work) 119 { 120 } 121 122 static inline int mlxsw_sp1_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp, 123 struct ethtool_ts_info *info) 124 { 125 return mlxsw_sp_ptp_get_ts_info_noptp(info); 126 } 127 128 #endif 129 130 static inline struct mlxsw_sp_ptp_clock * 131 mlxsw_sp2_ptp_clock_init(struct mlxsw_sp *mlxsw_sp, struct device *dev) 132 { 133 return NULL; 134 } 135 136 static inline void mlxsw_sp2_ptp_clock_fini(struct mlxsw_sp_ptp_clock *clock) 137 { 138 } 139 140 static inline struct mlxsw_sp_ptp_state * 141 mlxsw_sp2_ptp_init(struct mlxsw_sp *mlxsw_sp) 142 { 143 return NULL; 144 } 145 146 static inline void mlxsw_sp2_ptp_fini(struct mlxsw_sp_ptp_state *ptp_state) 147 { 148 } 149 150 static inline void mlxsw_sp2_ptp_receive(struct mlxsw_sp *mlxsw_sp, 151 struct sk_buff *skb, u8 local_port) 152 { 153 mlxsw_sp_rx_listener_no_mark_func(skb, local_port, mlxsw_sp); 154 } 155 156 static inline void mlxsw_sp2_ptp_transmitted(struct mlxsw_sp *mlxsw_sp, 157 struct sk_buff *skb, u8 local_port) 158 { 159 dev_kfree_skb_any(skb); 160 } 161 162 static inline int 163 mlxsw_sp2_ptp_hwtstamp_get(struct mlxsw_sp_port *mlxsw_sp_port, 164 struct hwtstamp_config *config) 165 { 166 return -EOPNOTSUPP; 167 } 168 169 static inline int 170 mlxsw_sp2_ptp_hwtstamp_set(struct mlxsw_sp_port *mlxsw_sp_port, 171 struct hwtstamp_config *config) 172 { 173 return -EOPNOTSUPP; 174 } 175 176 static inline void mlxsw_sp2_ptp_shaper_work(struct work_struct *work) 177 { 178 } 179 180 static inline int mlxsw_sp2_ptp_get_ts_info(struct mlxsw_sp *mlxsw_sp, 181 struct ethtool_ts_info *info) 182 { 183 return mlxsw_sp_ptp_get_ts_info_noptp(info); 184 } 185 186 #endif 187