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