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 enum hwtstamp_source {
9 	HWTSTAMP_SOURCE_NETDEV,
10 	HWTSTAMP_SOURCE_PHYLIB,
11 };
12 
13 /**
14  * struct kernel_hwtstamp_config - Kernel copy of struct hwtstamp_config
15  *
16  * @flags: see struct hwtstamp_config
17  * @tx_type: see struct hwtstamp_config
18  * @rx_filter: see struct hwtstamp_config
19  * @ifr: pointer to ifreq structure from the original ioctl request, to pass to
20  *	a legacy implementation of a lower driver
21  * @copied_to_user: request was passed to a legacy implementation which already
22  *	copied the ioctl request back to user space
23  * @source: indication whether timestamps should come from the netdev or from
24  *	an attached phylib PHY
25  *
26  * Prefer using this structure for in-kernel processing of hardware
27  * timestamping configuration, over the inextensible struct hwtstamp_config
28  * exposed to the %SIOCGHWTSTAMP and %SIOCSHWTSTAMP ioctl UAPI.
29  */
30 struct kernel_hwtstamp_config {
31 	int flags;
32 	int tx_type;
33 	int rx_filter;
34 	struct ifreq *ifr;
35 	bool copied_to_user;
36 	enum hwtstamp_source source;
37 };
38 
hwtstamp_config_to_kernel(struct kernel_hwtstamp_config * kernel_cfg,const struct hwtstamp_config * cfg)39 static inline void hwtstamp_config_to_kernel(struct kernel_hwtstamp_config *kernel_cfg,
40 					     const struct hwtstamp_config *cfg)
41 {
42 	kernel_cfg->flags = cfg->flags;
43 	kernel_cfg->tx_type = cfg->tx_type;
44 	kernel_cfg->rx_filter = cfg->rx_filter;
45 }
46 
hwtstamp_config_from_kernel(struct hwtstamp_config * cfg,const struct kernel_hwtstamp_config * kernel_cfg)47 static inline void hwtstamp_config_from_kernel(struct hwtstamp_config *cfg,
48 					       const struct kernel_hwtstamp_config *kernel_cfg)
49 {
50 	cfg->flags = kernel_cfg->flags;
51 	cfg->tx_type = kernel_cfg->tx_type;
52 	cfg->rx_filter = kernel_cfg->rx_filter;
53 }
54 
kernel_hwtstamp_config_changed(const struct kernel_hwtstamp_config * a,const struct kernel_hwtstamp_config * b)55 static inline bool kernel_hwtstamp_config_changed(const struct kernel_hwtstamp_config *a,
56 						  const struct kernel_hwtstamp_config *b)
57 {
58 	return a->flags != b->flags ||
59 	       a->tx_type != b->tx_type ||
60 	       a->rx_filter != b->rx_filter;
61 }
62 
63 #endif /* _LINUX_NET_TIMESTAMPING_H_ */
64