1
2
3
4#ifndef _ICE_PTP_H_
5#define _ICE_PTP_H_
6
7#include <linux/ptp_clock_kernel.h>
8#include <linux/kthread.h>
9
10#include "ice_ptp_hw.h"
11
12enum ice_ptp_pin {
13 GPIO_20 = 0,
14 GPIO_21,
15 GPIO_22,
16 GPIO_23,
17 NUM_ICE_PTP_PIN
18};
19
20struct ice_perout_channel {
21 bool ena;
22 u32 gpio_pin;
23 u64 period;
24 u64 start_time;
25};
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55struct ice_tx_tstamp {
56 struct sk_buff *skb;
57 unsigned long start;
58};
59
60
61
62
63
64
65
66
67
68
69
70
71struct ice_ptp_tx {
72 struct kthread_work work;
73 spinlock_t lock;
74 struct ice_tx_tstamp *tstamps;
75 unsigned long *in_use;
76 u8 quad;
77 u8 quad_offset;
78 u8 len;
79 u8 init;
80};
81
82
83#define INDEX_PER_QUAD 64
84#define INDEX_PER_PORT (INDEX_PER_QUAD / ICE_PORTS_PER_QUAD)
85
86
87
88
89
90
91
92
93
94
95
96struct ice_ptp_port {
97 struct ice_ptp_tx tx;
98};
99
100#define GLTSYN_TGT_H_IDX_MAX 4
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116struct ice_ptp {
117 struct ice_ptp_port port;
118 struct kthread_delayed_work work;
119 struct kthread_work extts_work;
120 u64 cached_phc_time;
121 u8 ext_ts_chan;
122 u8 ext_ts_irq;
123 struct kthread_worker *kworker;
124 struct ice_perout_channel perout_channels[GLTSYN_TGT_H_IDX_MAX];
125 struct ptp_clock_info info;
126 struct ptp_clock *clock;
127 struct hwtstamp_config tstamp_config;
128};
129
130#define __ptp_port_to_ptp(p) \
131 container_of((p), struct ice_ptp, port)
132#define ptp_port_to_pf(p) \
133 container_of(__ptp_port_to_ptp((p)), struct ice_pf, ptp)
134
135#define __ptp_info_to_ptp(i) \
136 container_of((i), struct ice_ptp, info)
137#define ptp_info_to_pf(i) \
138 container_of(__ptp_info_to_ptp((i)), struct ice_pf, ptp)
139
140#define PTP_SHARED_CLK_IDX_VALID BIT(31)
141#define ICE_PTP_TS_VALID BIT(0)
142
143
144#define GLTSYN_AUX_OUT(_chan, _idx) (GLTSYN_AUX_OUT_0(_idx) + ((_chan) * 8))
145#define GLTSYN_AUX_IN(_chan, _idx) (GLTSYN_AUX_IN_0(_idx) + ((_chan) * 8))
146#define GLTSYN_CLKO(_chan, _idx) (GLTSYN_CLKO_0(_idx) + ((_chan) * 8))
147#define GLTSYN_TGT_L(_chan, _idx) (GLTSYN_TGT_L_0(_idx) + ((_chan) * 16))
148#define GLTSYN_TGT_H(_chan, _idx) (GLTSYN_TGT_H_0(_idx) + ((_chan) * 16))
149#define GLTSYN_EVNT_L(_chan, _idx) (GLTSYN_EVNT_L_0(_idx) + ((_chan) * 16))
150#define GLTSYN_EVNT_H(_chan, _idx) (GLTSYN_EVNT_H_0(_idx) + ((_chan) * 16))
151#define GLTSYN_EVNT_H_IDX_MAX 3
152
153
154#define PPS_CLK_GEN_CHAN 3
155#define PPS_CLK_SRC_CHAN 2
156#define PPS_PIN_INDEX 5
157#define TIME_SYNC_PIN_INDEX 4
158#define E810_N_EXT_TS 3
159#define E810_N_PER_OUT 4
160
161#if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
162struct ice_pf;
163int ice_ptp_set_ts_config(struct ice_pf *pf, struct ifreq *ifr);
164int ice_ptp_get_ts_config(struct ice_pf *pf, struct ifreq *ifr);
165int ice_get_ptp_clock_index(struct ice_pf *pf);
166
167s8 ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb);
168void ice_ptp_process_ts(struct ice_pf *pf);
169
170void
171ice_ptp_rx_hwtstamp(struct ice_ring *rx_ring,
172 union ice_32b_rx_flex_desc *rx_desc, struct sk_buff *skb);
173void ice_ptp_init(struct ice_pf *pf);
174void ice_ptp_release(struct ice_pf *pf);
175#else
176static inline int ice_ptp_set_ts_config(struct ice_pf *pf, struct ifreq *ifr)
177{
178 return -EOPNOTSUPP;
179}
180
181static inline int ice_ptp_get_ts_config(struct ice_pf *pf, struct ifreq *ifr)
182{
183 return -EOPNOTSUPP;
184}
185
186static inline int ice_get_ptp_clock_index(struct ice_pf *pf)
187{
188 return -1;
189}
190
191static inline s8
192ice_ptp_request_ts(struct ice_ptp_tx *tx, struct sk_buff *skb)
193{
194 return -1;
195}
196
197static inline void ice_ptp_process_ts(struct ice_pf *pf) { }
198static inline void
199ice_ptp_rx_hwtstamp(struct ice_ring *rx_ring,
200 union ice_32b_rx_flex_desc *rx_desc, struct sk_buff *skb) { }
201static inline void ice_ptp_init(struct ice_pf *pf) { }
202static inline void ice_ptp_release(struct ice_pf *pf) { }
203#endif
204#endif
205