1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
|
/* SPDX-License-Identifier: GPL-2.0-only */
/* Copyright (C) 2024 Intel Corporation */
#ifndef _IDPF_PTP_H
#define _IDPF_PTP_H
#include <linux/ptp_clock_kernel.h>
/**
* struct idpf_ptp_cmd - PTP command masks
* @exec_cmd_mask: mask to trigger command execution
* @shtime_enable_mask: mask to enable shadow time
*/
struct idpf_ptp_cmd {
u32 exec_cmd_mask;
u32 shtime_enable_mask;
};
/* struct idpf_ptp_dev_clk_regs - PTP device registers
* @dev_clk_ns_l: low part of the device clock register
* @dev_clk_ns_h: high part of the device clock register
* @phy_clk_ns_l: low part of the PHY clock register
* @phy_clk_ns_h: high part of the PHY clock register
* @incval_l: low part of the increment value register
* @incval_h: high part of the increment value register
* @shadj_l: low part of the shadow adjust register
* @shadj_h: high part of the shadow adjust register
* @phy_incval_l: low part of the PHY increment value register
* @phy_incval_h: high part of the PHY increment value register
* @phy_shadj_l: low part of the PHY shadow adjust register
* @phy_shadj_h: high part of the PHY shadow adjust register
* @cmd: PTP command register
* @phy_cmd: PHY command register
* @cmd_sync: PTP command synchronization register
*/
struct idpf_ptp_dev_clk_regs {
/* Main clock */
void __iomem *dev_clk_ns_l;
void __iomem *dev_clk_ns_h;
/* PHY timer */
void __iomem *phy_clk_ns_l;
void __iomem *phy_clk_ns_h;
/* Main timer adjustments */
void __iomem *incval_l;
void __iomem *incval_h;
void __iomem *shadj_l;
void __iomem *shadj_h;
/* PHY timer adjustments */
void __iomem *phy_incval_l;
void __iomem *phy_incval_h;
void __iomem *phy_shadj_l;
void __iomem *phy_shadj_h;
/* Command */
void __iomem *cmd;
void __iomem *phy_cmd;
void __iomem *cmd_sync;
};
/**
* enum idpf_ptp_access - the type of access to PTP operations
* @IDPF_PTP_NONE: no access
* @IDPF_PTP_DIRECT: direct access through BAR registers
* @IDPF_PTP_MAILBOX: access through mailbox messages
*/
enum idpf_ptp_access {
IDPF_PTP_NONE = 0,
IDPF_PTP_DIRECT,
IDPF_PTP_MAILBOX,
};
/**
* struct idpf_ptp_secondary_mbx - PTP secondary mailbox
* @peer_mbx_q_id: PTP mailbox queue ID
* @peer_id: Peer ID for PTP Device Control daemon
* @valid: indicates whether secondary mailblox is supported by the Control
* Plane
*/
struct idpf_ptp_secondary_mbx {
u16 peer_mbx_q_id;
u16 peer_id;
bool valid:1;
};
/**
* enum idpf_ptp_tx_tstamp_state - Tx timestamp states
* @IDPF_PTP_FREE: Tx timestamp index free to use
* @IDPF_PTP_REQUEST: Tx timestamp index set to the Tx descriptor
* @IDPF_PTP_READ_VALUE: Tx timestamp value ready to be read
*/
enum idpf_ptp_tx_tstamp_state {
IDPF_PTP_FREE,
IDPF_PTP_REQUEST,
IDPF_PTP_READ_VALUE,
};
/**
* struct idpf_ptp_tx_tstamp_status - Parameters to track Tx timestamp
* @skb: the pointer to the SKB that received the completion tag
* @state: the state of the Tx timestamp
*/
struct idpf_ptp_tx_tstamp_status {
struct sk_buff *skb;
enum idpf_ptp_tx_tstamp_state state;
};
/**
* struct idpf_ptp_tx_tstamp - Parameters for Tx timestamping
* @list_member: the list member structure
* @tx_latch_reg_offset_l: Tx tstamp latch low register offset
* @tx_latch_reg_offset_h: Tx tstamp latch high register offset
* @skb: the pointer to the SKB for this timestamp request
* @tstamp: the Tx tstamp value
* @idx: the index of the Tx tstamp
*/
struct idpf_ptp_tx_tstamp {
struct list_head list_member;
u32 tx_latch_reg_offset_l;
u32 tx_latch_reg_offset_h;
struct sk_buff *skb;
u64 tstamp;
u32 idx;
};
/**
* struct idpf_ptp_vport_tx_tstamp_caps - Tx timestamp capabilities
* @vport_id: the vport id
* @num_entries: the number of negotiated Tx timestamp entries
* @tstamp_ns_lo_bit: first bit for nanosecond part of the timestamp
* @latches_lock: the lock to the lists of free/used timestamp indexes
* @status_lock: the lock to the status tracker
* @access: indicates an access to Tx timestamp
* @latches_free: the list of the free Tx timestamps latches
* @latches_in_use: the list of the used Tx timestamps latches
* @tx_tstamp_status: Tx tstamp status tracker
*/
struct idpf_ptp_vport_tx_tstamp_caps {
u32 vport_id;
u16 num_entries;
u16 tstamp_ns_lo_bit;
spinlock_t latches_lock;
spinlock_t status_lock;
bool access:1;
struct list_head latches_free;
struct list_head latches_in_use;
struct idpf_ptp_tx_tstamp_status tx_tstamp_status[];
};
/**
* struct idpf_ptp - PTP parameters
* @info: structure defining PTP hardware capabilities
* @clock: pointer to registered PTP clock device
* @adapter: back pointer to the adapter
* @base_incval: base increment value of the PTP clock
* @max_adj: maximum adjustment of the PTP clock
* @cmd: HW specific command masks
* @cached_phc_time: a cached copy of the PHC time for timestamp extension
* @cached_phc_jiffies: jiffies when cached_phc_time was last updated
* @dev_clk_regs: the set of registers to access the device clock
* @caps: PTP capabilities negotiated with the Control Plane
* @get_dev_clk_time_access: access type for getting the device clock time
* @set_dev_clk_time_access: access type for setting the device clock time
* @adj_dev_clk_time_access: access type for the adjusting the device clock
* @tx_tstamp_access: access type for the Tx timestamp value read
* @rsv: reserved bits
* @secondary_mbx: parameters for using dedicated PTP mailbox
* @read_dev_clk_lock: spinlock protecting access to the device clock read
* operation executed by the HW latch
*/
struct idpf_ptp {
struct ptp_clock_info info;
struct ptp_clock *clock;
struct idpf_adapter *adapter;
u64 base_incval;
u64 max_adj;
struct idpf_ptp_cmd cmd;
u64 cached_phc_time;
unsigned long cached_phc_jiffies;
struct idpf_ptp_dev_clk_regs dev_clk_regs;
u32 caps;
enum idpf_ptp_access get_dev_clk_time_access:2;
enum idpf_ptp_access set_dev_clk_time_access:2;
enum idpf_ptp_access adj_dev_clk_time_access:2;
enum idpf_ptp_access tx_tstamp_access:2;
u8 rsv;
struct idpf_ptp_secondary_mbx secondary_mbx;
spinlock_t read_dev_clk_lock;
};
/**
* idpf_ptp_info_to_adapter - get driver adapter struct from ptp_clock_info
* @info: pointer to ptp_clock_info struct
*
* Return: pointer to the corresponding adapter struct
*/
static inline struct idpf_adapter *
idpf_ptp_info_to_adapter(const struct ptp_clock_info *info)
{
const struct idpf_ptp *ptp = container_of_const(info, struct idpf_ptp,
info);
return ptp->adapter;
}
/**
* struct idpf_ptp_dev_timers - System time and device time values
* @sys_time_ns: system time value expressed in nanoseconds
* @dev_clk_time_ns: device clock time value expressed in nanoseconds
*/
struct idpf_ptp_dev_timers {
u64 sys_time_ns;
u64 dev_clk_time_ns;
};
/**
* idpf_ptp_is_vport_tx_tstamp_ena - Verify the Tx timestamping enablement for
* a given vport.
* @vport: Virtual port structure
*
* Tx timestamp capabilities are negotiated with the Control Plane only if the
* device clock value can be read, Tx timestamp access type is different than
* NONE, and the PTP clock for the adapter is created. When all those conditions
* are satisfied, Tx timestamp feature is enabled and tx_tstamp_caps is
* allocated and fulfilled.
*
* Return: true if the Tx timestamping is enabled, false otherwise.
*/
static inline bool idpf_ptp_is_vport_tx_tstamp_ena(struct idpf_vport *vport)
{
if (!vport->tx_tstamp_caps)
return false;
else
return true;
}
/**
* idpf_ptp_is_vport_rx_tstamp_ena - Verify the Rx timestamping enablement for
* a given vport.
* @vport: Virtual port structure
*
* Rx timestamp feature is enabled if the PTP clock for the adapter is created
* and it is possible to read the value of the device clock. The second
* assumption comes from the need to extend the Rx timestamp value to 64 bit
* based on the current device clock time.
*
* Return: true if the Rx timestamping is enabled, false otherwise.
*/
static inline bool idpf_ptp_is_vport_rx_tstamp_ena(struct idpf_vport *vport)
{
if (!vport->adapter->ptp ||
vport->adapter->ptp->get_dev_clk_time_access == IDPF_PTP_NONE)
return false;
else
return true;
}
#if IS_ENABLED(CONFIG_PTP_1588_CLOCK)
int idpf_ptp_init(struct idpf_adapter *adapter);
void idpf_ptp_release(struct idpf_adapter *adapter);
int idpf_ptp_get_caps(struct idpf_adapter *adapter);
void idpf_ptp_get_features_access(const struct idpf_adapter *adapter);
bool idpf_ptp_get_txq_tstamp_capability(struct idpf_tx_queue *txq);
int idpf_ptp_get_dev_clk_time(struct idpf_adapter *adapter,
struct idpf_ptp_dev_timers *dev_clk_time);
int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter, u64 time);
int idpf_ptp_adj_dev_clk_fine(struct idpf_adapter *adapter, u64 incval);
int idpf_ptp_adj_dev_clk_time(struct idpf_adapter *adapter, s64 delta);
int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport);
int idpf_ptp_get_tx_tstamp(struct idpf_vport *vport);
int idpf_ptp_set_timestamp_mode(struct idpf_vport *vport,
struct kernel_hwtstamp_config *config);
u64 idpf_ptp_extend_ts(struct idpf_vport *vport, u64 in_tstamp);
u64 idpf_ptp_tstamp_extend_32b_to_64b(u64 cached_phc_time, u32 in_timestamp);
int idpf_ptp_request_ts(struct idpf_tx_queue *tx_q, struct sk_buff *skb,
u32 *idx);
void idpf_tstamp_task(struct work_struct *work);
#else /* CONFIG_PTP_1588_CLOCK */
static inline int idpf_ptp_init(struct idpf_adapter *adapter)
{
return 0;
}
static inline void idpf_ptp_release(struct idpf_adapter *adapter) { }
static inline int idpf_ptp_get_caps(struct idpf_adapter *adapter)
{
return -EOPNOTSUPP;
}
static inline void
idpf_ptp_get_features_access(const struct idpf_adapter *adapter) { }
static inline bool
idpf_ptp_get_txq_tstamp_capability(struct idpf_tx_queue *txq)
{
return false;
}
static inline int
idpf_ptp_get_dev_clk_time(struct idpf_adapter *adapter,
struct idpf_ptp_dev_timers *dev_clk_time)
{
return -EOPNOTSUPP;
}
static inline int idpf_ptp_set_dev_clk_time(struct idpf_adapter *adapter,
u64 time)
{
return -EOPNOTSUPP;
}
static inline int idpf_ptp_adj_dev_clk_fine(struct idpf_adapter *adapter,
u64 incval)
{
return -EOPNOTSUPP;
}
static inline int idpf_ptp_adj_dev_clk_time(struct idpf_adapter *adapter,
s64 delta)
{
return -EOPNOTSUPP;
}
static inline int idpf_ptp_get_vport_tstamps_caps(struct idpf_vport *vport)
{
return -EOPNOTSUPP;
}
static inline int idpf_ptp_get_tx_tstamp(struct idpf_vport *vport)
{
return -EOPNOTSUPP;
}
static inline int
idpf_ptp_set_timestamp_mode(struct idpf_vport *vport,
struct kernel_hwtstamp_config *config)
{
return -EOPNOTSUPP;
}
static inline u64 idpf_ptp_extend_ts(struct idpf_vport *vport, u32 in_tstamp)
{
return 0;
}
static inline u64 idpf_ptp_tstamp_extend_32b_to_64b(u64 cached_phc_time,
u32 in_timestamp)
{
return 0;
}
static inline int idpf_ptp_request_ts(struct idpf_tx_queue *tx_q,
struct sk_buff *skb, u32 *idx)
{
return -EOPNOTSUPP;
}
static inline void idpf_tstamp_task(struct work_struct *work) { }
#endif /* CONFIG_PTP_1588_CLOCK */
#endif /* _IDPF_PTP_H */
|