1
2
3
4#ifndef _SJA1105_PTP_H
5#define _SJA1105_PTP_H
6
7#include <linux/timer.h>
8
9#if IS_ENABLED(CONFIG_NET_DSA_SJA1105_PTP)
10
11
12
13
14#define SJA1105_TICK_NS 8
15
16static inline s64 ns_to_sja1105_ticks(s64 ns)
17{
18 return ns / SJA1105_TICK_NS;
19}
20
21static inline s64 sja1105_ticks_to_ns(s64 ticks)
22{
23 return ticks * SJA1105_TICK_NS;
24}
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39static inline s64 future_base_time(s64 base_time, s64 cycle_time, s64 now)
40{
41 s64 a, b, n;
42
43 if (base_time >= now)
44 return base_time;
45
46 a = now - base_time;
47 b = cycle_time;
48 n = div_s64(a + b - 1, b);
49
50 return base_time + n * cycle_time;
51}
52
53
54
55
56static inline s64 ns_to_sja1105_delta(s64 ns)
57{
58 return div_s64(ns, 200);
59}
60
61static inline s64 sja1105_delta_to_ns(s64 delta)
62{
63 return delta * 200;
64}
65
66struct sja1105_ptp_cmd {
67 u64 startptpcp;
68 u64 stopptpcp;
69 u64 ptpstrtsch;
70 u64 ptpstopsch;
71 u64 resptp;
72 u64 corrclk4ts;
73 u64 ptpclkadd;
74};
75
76struct sja1105_ptp_data {
77 struct timer_list extts_timer;
78
79 struct sk_buff_head skb_rxtstamp_queue;
80
81
82
83 struct sk_buff_head skb_txtstamp_queue;
84 struct ptp_clock_info caps;
85 struct ptp_clock *clock;
86 struct sja1105_ptp_cmd cmd;
87
88 struct mutex lock;
89 bool extts_enabled;
90 u64 ptpsyncts;
91};
92
93int sja1105_ptp_clock_register(struct dsa_switch *ds);
94
95void sja1105_ptp_clock_unregister(struct dsa_switch *ds);
96
97void sja1105et_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd,
98 enum packing_op op);
99
100void sja1105pqrs_ptp_cmd_packing(u8 *buf, struct sja1105_ptp_cmd *cmd,
101 enum packing_op op);
102
103int sja1105_get_ts_info(struct dsa_switch *ds, int port,
104 struct ethtool_ts_info *ts);
105
106void sja1105_ptp_txtstamp_skb(struct dsa_switch *ds, int slot,
107 struct sk_buff *clone);
108
109bool sja1105_port_rxtstamp(struct dsa_switch *ds, int port,
110 struct sk_buff *skb, unsigned int type);
111
112void sja1105_port_txtstamp(struct dsa_switch *ds, int port,
113 struct sk_buff *skb);
114
115int sja1105_hwtstamp_get(struct dsa_switch *ds, int port, struct ifreq *ifr);
116
117int sja1105_hwtstamp_set(struct dsa_switch *ds, int port, struct ifreq *ifr);
118
119int __sja1105_ptp_gettimex(struct dsa_switch *ds, u64 *ns,
120 struct ptp_system_timestamp *sts);
121
122int __sja1105_ptp_settime(struct dsa_switch *ds, u64 ns,
123 struct ptp_system_timestamp *ptp_sts);
124
125int __sja1105_ptp_adjtime(struct dsa_switch *ds, s64 delta);
126
127int sja1105_ptp_commit(struct dsa_switch *ds, struct sja1105_ptp_cmd *cmd,
128 sja1105_spi_rw_mode_t rw);
129
130bool sja1105_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
131bool sja1110_rxtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
132void sja1110_txtstamp(struct dsa_switch *ds, int port, struct sk_buff *skb);
133
134#else
135
136struct sja1105_ptp_cmd;
137
138
139
140
141
142struct sja1105_ptp_data {
143 struct mutex lock;
144};
145
146static inline int sja1105_ptp_clock_register(struct dsa_switch *ds)
147{
148 return 0;
149}
150
151static inline void sja1105_ptp_clock_unregister(struct dsa_switch *ds) { }
152
153static inline void sja1105_ptp_txtstamp_skb(struct dsa_switch *ds, int slot,
154 struct sk_buff *clone)
155{
156}
157
158static inline int __sja1105_ptp_gettimex(struct dsa_switch *ds, u64 *ns,
159 struct ptp_system_timestamp *sts)
160{
161 return 0;
162}
163
164static inline int __sja1105_ptp_settime(struct dsa_switch *ds, u64 ns,
165 struct ptp_system_timestamp *ptp_sts)
166{
167 return 0;
168}
169
170static inline int __sja1105_ptp_adjtime(struct dsa_switch *ds, s64 delta)
171{
172 return 0;
173}
174
175static inline int sja1105_ptp_commit(struct dsa_switch *ds,
176 struct sja1105_ptp_cmd *cmd,
177 sja1105_spi_rw_mode_t rw)
178{
179 return 0;
180}
181
182#define sja1105et_ptp_cmd_packing NULL
183
184#define sja1105pqrs_ptp_cmd_packing NULL
185
186#define sja1105_get_ts_info NULL
187
188#define sja1105_port_rxtstamp NULL
189
190#define sja1105_port_txtstamp NULL
191
192#define sja1105_hwtstamp_get NULL
193
194#define sja1105_hwtstamp_set NULL
195
196#define sja1105_rxtstamp NULL
197#define sja1110_rxtstamp NULL
198#define sja1110_txtstamp NULL
199
200#endif
201
202#endif
203