1 /* SPDX-License-Identifier: GPL-2.0 */
2 
3 #ifndef _LINUX_NET_TIMESTAMPING_H_
4 #define _LINUX_NET_TIMESTAMPING_H_
5 
6 #include <uapi/linux/net_tstamp.h>
7 
8 #define SOF_TIMESTAMPING_SOFTWARE_MASK	(SOF_TIMESTAMPING_RX_SOFTWARE | \
9 					 SOF_TIMESTAMPING_TX_SOFTWARE | \
10 					 SOF_TIMESTAMPING_SOFTWARE)
11 
12 #define SOF_TIMESTAMPING_HARDWARE_MASK	(SOF_TIMESTAMPING_RX_HARDWARE | \
13 					 SOF_TIMESTAMPING_TX_HARDWARE | \
14 					 SOF_TIMESTAMPING_RAW_HARDWARE)
15 
16 enum hwtstamp_source {
17 	HWTSTAMP_SOURCE_UNSPEC,
18 	HWTSTAMP_SOURCE_NETDEV,
19 	HWTSTAMP_SOURCE_PHYLIB,
20 };
21 
22 /**
23  * struct hwtstamp_provider_desc - hwtstamp provider description
24  *
25  * @index: index of the hwtstamp provider.
26  * @qualifier: hwtstamp provider qualifier.
27  */
28 struct hwtstamp_provider_desc {
29 	int index;
30 	enum hwtstamp_provider_qualifier qualifier;
31 };
32 
33 /**
34  * struct hwtstamp_provider - hwtstamp provider object
35  *
36  * @rcu_head: RCU callback used to free the struct.
37  * @source: source of the hwtstamp provider.
38  * @phydev: pointer of the phydev source in case a PTP coming from phylib
39  * @desc: hwtstamp provider description.
40  */
41 
42 struct hwtstamp_provider {
43 	struct rcu_head rcu_head;
44 	enum hwtstamp_source source;
45 	struct phy_device *phydev;
46 	struct hwtstamp_provider_desc desc;
47 };
48 
49 /**
50  * struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config
51  *
52  * @flags: see struct hwtstamp_config
53  * @tx_type: see struct hwtstamp_config
54  * @rx_filter: see struct hwtstamp_config
55  * @ifr: pointer to ifreq structure from the original ioctl request, to pass to
56  *	a legacy implementation of a lower driver
57  * @copied_to_user: request was passed to a legacy implementation which already
58  *	copied the ioctl request back to user space
59  * @source: indication whether timestamps should come from the netdev or from
60  *	an attached phylib PHY
61  * @qualifier: qualifier of the hwtstamp provider
62  *
63  * Prefer using this structure for in-kernel processing of hardware
64  * timestamping configuration, over the inextensible struct hwtstamp_config
65  * exposed to the %SIOCGHWTSTAMP and %SIOCSHWTSTAMP ioctl UAPI.
66  */
67 struct kernel_hwtstamp_config {
68 	int flags;
69 	int tx_type;
70 	int rx_filter;
71 	struct ifreq *ifr;
72 	bool copied_to_user;
73 	enum hwtstamp_source source;
74 	enum hwtstamp_provider_qualifier qualifier;
75 };
76 
hwtstamp_config_to_kernel(struct kernel_hwtstamp_config * kernel_cfg,const struct hwtstamp_config * cfg)77 static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg,
78 					     const struct hwtstamp_config *cfg)
79 {
80 	kernel_cfg->flags = cfg->flags;
81 	kernel_cfg->tx_type = cfg->tx_type;
82 	kernel_cfg->rx_filter = cfg->rx_filter;
83 }
84 
hwtstamp_config_from_kernel(struct hwtstamp_config * cfg,const struct kernel_hwtstamp_config * kernel_cfg)85 static inline void hwtstamp_config_from_kernel(struct hwtstamp_config *cfg,
86 					       const struct kernel_hwtstamp_config *kernel_cfg)
87 {
88 	cfg->flags = kernel_cfg->flags;
89 	cfg->tx_type = kernel_cfg->tx_type;
90 	cfg->rx_filter = kernel_cfg->rx_filter;
91 }
92 
kernel_hwtstamp_config_changed(const struct kernel_hwtstamp_config * a,const struct kernel_hwtstamp_config * b)93 static inline bool kernel_hwtstamp_config_changed(const struct kernel_hwtstamp_config *a,
94 						  const struct kernel_hwtstamp_config *b)
95 {
96 	return a->flags != b->flags ||
97 	       a->tx_type != b->tx_type ||
98 	       a->rx_filter != b->rx_filter;
99 }
100 
101 #endif /* _LINUX_NET_TIMESTAMPING_H_ */
102