1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* Copyright (c) 2019, Vladimir Oltean <olteanv@gmail.com> 3 */ 4 #ifndef _SJA1105_PTP_H 5 #define _SJA1105_PTP_H 6 7 #if IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP) 8 9 /* Timestamps are in units of 8 ns clock ticks (equivalent to 10 * a fixed 125 MHz clock). 11 */ 12 #define SJA1105_TICK_NS 8 13 14 static inline s64 ns_to_sja1105_ticks(s64 ns) 15 { 16 return ns / SJA1105_TICK_NS; 17 } 18 19 static inline s64 sja1105_ticks_to_ns(s64 ticks) 20 { 21 return ticks * SJA1105_TICK_NS; 22 } 23 24 struct sja1105_ptp_cmd { 25 u64 ptpstrtsch; /* start schedule */ 26 u64 ptpstopsch; /* stop schedule */ 27 u64 resptp; /* reset */ 28 u64 corrclk4ts; /* use the corrected clock for timestamps */ 29 u64 ptpclkadd; /* enum sja1105_ptp_clk_mode */ 30 }; 31 32 struct sja1105_ptp_data { 33 struct sk_buff_head skb_rxtstamp_queue; 34 struct ptp_clock_info caps; 35 struct ptp_clock *clock; 36 struct sja1105_ptp_cmd cmd; 37 /* Serializes all operations on the PTP hardware clock */ 38 struct mutex lock; 39 }; 40 41 int sja1105_ptp_clock_register(struct dsa_switch *ds); 42 43 void sja1105_ptp_clock_unregister(struct dsa_switch *ds); 44 45 void sja1105et_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd, 46 enum packing_op op); 47 48 void sja1105pqrs_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd, 49 enum packing_op op); 50 51 int sja1105_get_ts_info(struct dsa_switch *ds, int port, 52 struct ethtool_ts_info *ts); 53 54 void sja1105_ptp_txtstamp_skb(struct dsa_switch *ds, int slot, 55 struct sk_buff *clone); 56 57 bool sja1105_port_rxtstamp(struct dsa_switch *ds, int port, 58 struct sk_buff *skb, unsigned int type); 59 60 bool sja1105_port_txtstamp(struct dsa_switch *ds, int port, 61 struct sk_buff *skb, unsigned int type); 62 63 int sja1105_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr); 64 65 int sja1105_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr); 66 67 int __sja1105_ptp_gettimex(struct dsa_switch *ds, u64 *ns, 68 struct ptp_system_timestamp *sts); 69 70 int __sja1105_ptp_settime(struct dsa_switch *ds, u64 ns, 71 struct ptp_system_timestamp *ptp_sts); 72 73 int __sja1105_ptp_adjtime(struct dsa_switch *ds, s64 delta); 74 75 int sja1105_ptp_commit(struct dsa_switch *ds, struct sja1105_ptp_cmd *cmd, 76 sja1105_spi_rw_mode_t rw); 77 78 #else 79 80 struct sja1105_ptp_cmd; 81 82 /* Structures cannot be empty in C. Bah! 83 * Keep the mutex as the only element, which is a bit more difficult to 84 * refactor out of sja1105_main.c anyway. 85 */ 86 struct sja1105_ptp_data { 87 struct mutex lock; 88 }; 89 90 static inline int sja1105_ptp_clock_register(struct dsa_switch *ds) 91 { 92 return 0; 93 } 94 95 static inline void sja1105_ptp_clock_unregister(struct dsa_switch *ds) { } 96 97 static inline void sja1105_ptp_txtstamp_skb(struct dsa_switch *ds, int slot, 98 struct sk_buff *clone) 99 { 100 } 101 102 static inline int __sja1105_ptp_gettimex(struct dsa_switch *ds, u64 *ns, 103 struct ptp_system_timestamp *sts) 104 { 105 return 0; 106 } 107 108 static inline int __sja1105_ptp_settime(struct dsa_switch *ds, u64 ns, 109 struct ptp_system_timestamp *ptp_sts) 110 { 111 return 0; 112 } 113 114 static inline int __sja1105_ptp_adjtime(struct dsa_switch *ds, s64 delta) 115 { 116 return 0; 117 } 118 119 static inline int sja1105_ptp_commit(struct dsa_switch *ds, 120 struct sja1105_ptp_cmd *cmd, 121 sja1105_spi_rw_mode_t rw) 122 { 123 return 0; 124 } 125 126 #define sja1105et_ptp_cmd_packing NULL 127 128 #define sja1105pqrs_ptp_cmd_packing NULL 129 130 #define sja1105_get_ts_info NULL 131 132 #define sja1105_port_rxtstamp NULL 133 134 #define sja1105_port_txtstamp NULL 135 136 #define sja1105_hwtstamp_get NULL 137 138 #define sja1105_hwtstamp_set NULL 139 140 #endif /* IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP) */ 141 142 #endif /* _SJA1105_PTP_H */ 143