xref: /linux/include/linux/mii_timestamper.h (revision 8f7aa3d3c7323f4ca2768a9e74ebbe359c4f8f88) !
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Support for generic time stamping devices on MII buses.
4  * Copyright (C) 2018 Richard Cochran <richardcochran@gmail.com>
5  */
6 #ifndef _LINUX_MII_TIMESTAMPER_H
7 #define _LINUX_MII_TIMESTAMPER_H
8 
9 #include <linux/device.h>
10 #include <linux/ethtool.h>
11 #include <linux/skbuff.h>
12 #include <linux/net_tstamp.h>
13 
14 struct phy_device;
15 
16 /**
17  * struct mii_timestamper - Callback interface to MII time stamping devices.
18  *
19  * @rxtstamp:	Requests a Rx timestamp for 'skb'.  If the skb is accepted,
20  *		the MII time stamping device promises to deliver it using
21  *		netif_rx() as soon as a timestamp becomes available. One of
22  *		the PTP_CLASS_ values is passed in 'type'.  The function
23  *		must return true if the skb is accepted for delivery.
24  *
25  * @txtstamp:	Requests a Tx timestamp for 'skb'.  The MII time stamping
26  *		device promises to deliver it using skb_complete_tx_timestamp()
27  *		as soon as a timestamp becomes available. One of the PTP_CLASS_
28  *		values is passed in 'type'.
29  *
30  * @hwtstamp_set: Handles SIOCSHWTSTAMP ioctl for hardware time stamping.
31  *
32  * @hwtstamp_get: Handles SIOCGHWTSTAMP ioctl for hardware time stamping.
33  *
34  * @link_state: Allows the device to respond to changes in the link
35  *		state.  The caller invokes this function while holding
36  *		the phy_device mutex.
37  *
38  * @ts_info:	Handles ethtool queries for hardware time stamping.
39  * @device:	Remembers the device to which the instance belongs.
40  *
41  * Drivers for PHY time stamping devices should embed their
42  * mii_timestamper within a private structure, obtaining a reference
43  * to it using container_of().
44  *
45  * Drivers for non-PHY time stamping devices should return a pointer
46  * to a mii_timestamper from the probe_channel() callback of their
47  * mii_timestamping_ctrl interface.
48  */
49 struct mii_timestamper {
50 	bool (*rxtstamp)(struct mii_timestamper *mii_ts,
51 			 struct sk_buff *skb, int type);
52 
53 	void (*txtstamp)(struct mii_timestamper *mii_ts,
54 			 struct sk_buff *skb, int type);
55 
56 	int  (*hwtstamp_set)(struct mii_timestamper *mii_ts,
57 			     struct kernel_hwtstamp_config *kernel_config,
58 			     struct netlink_ext_ack *extack);
59 
60 	int  (*hwtstamp_get)(struct mii_timestamper *mii_ts,
61 			     struct kernel_hwtstamp_config *kernel_config);
62 
63 	void (*link_state)(struct mii_timestamper *mii_ts,
64 			   struct phy_device *phydev);
65 
66 	int  (*ts_info)(struct mii_timestamper *mii_ts,
67 			struct kernel_ethtool_ts_info *ts_info);
68 
69 	struct device *device;
70 };
71 
72 /**
73  * struct mii_timestamping_ctrl - MII time stamping controller interface.
74  *
75  * @probe_channel:	Callback into the controller driver announcing the
76  *			presence of the 'port' channel.  The 'device' field
77  *			had been passed to register_mii_tstamp_controller().
78  *			The driver must return either a pointer to a valid
79  *			MII timestamper instance or PTR_ERR.
80  *
81  * @release_channel:	Releases an instance obtained via .probe_channel.
82  */
83 struct mii_timestamping_ctrl {
84 	struct mii_timestamper *(*probe_channel)(struct device *device,
85 						 unsigned int port);
86 	void (*release_channel)(struct device *device,
87 				struct mii_timestamper *mii_ts);
88 };
89 
90 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
91 
92 int register_mii_tstamp_controller(struct device *device,
93 				   struct mii_timestamping_ctrl *ctrl);
94 
95 void unregister_mii_tstamp_controller(struct device *device);
96 
97 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
98 						 unsigned int port);
99 
100 void unregister_mii_timestamper(struct mii_timestamper *mii_ts);
101 
102 #else
103 
104 static inline
register_mii_tstamp_controller(struct device * device,struct mii_timestamping_ctrl * ctrl)105 int register_mii_tstamp_controller(struct device *device,
106 				   struct mii_timestamping_ctrl *ctrl)
107 {
108 	return -EOPNOTSUPP;
109 }
110 
unregister_mii_tstamp_controller(struct device * device)111 static inline void unregister_mii_tstamp_controller(struct device *device)
112 {
113 }
114 
115 static inline
register_mii_timestamper(struct device_node * node,unsigned int port)116 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
117 						 unsigned int port)
118 {
119 	return NULL;
120 }
121 
unregister_mii_timestamper(struct mii_timestamper * mii_ts)122 static inline void unregister_mii_timestamper(struct mii_timestamper *mii_ts)
123 {
124 }
125 
126 #endif
127 
128 #endif
129