Merge tag 'trace-v5.15-3' of git://git.kernel.org/pub/scm/linux/kernel/git/rostedt...
[linux-2.6-microblaze.git] / include / linux / mii_timestamper.h
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
13 struct phy_device;
14
15 /**
16  * struct mii_timestamper - Callback interface to MII time stamping devices.
17  *
18  * @rxtstamp:   Requests a Rx timestamp for 'skb'.  If the skb is accepted,
19  *              the MII time stamping device promises to deliver it using
20  *              netif_rx() as soon as a timestamp becomes available. One of
21  *              the PTP_CLASS_ values is passed in 'type'.  The function
22  *              must return true if the skb is accepted for delivery.
23  *
24  * @txtstamp:   Requests a Tx timestamp for 'skb'.  The MII time stamping
25  *              device promises to deliver it using skb_complete_tx_timestamp()
26  *              as soon as a timestamp becomes available. One of the PTP_CLASS_
27  *              values is passed in 'type'.
28  *
29  * @hwtstamp:   Handles SIOCSHWTSTAMP ioctl for hardware time stamping.
30  *
31  * @link_state: Allows the device to respond to changes in the link
32  *              state.  The caller invokes this function while holding
33  *              the phy_device mutex.
34  *
35  * @ts_info:    Handles ethtool queries for hardware time stamping.
36  * @device:     Remembers the device to which the instance belongs.
37  *
38  * Drivers for PHY time stamping devices should embed their
39  * mii_timestamper within a private structure, obtaining a reference
40  * to it using container_of().
41  *
42  * Drivers for non-PHY time stamping devices should return a pointer
43  * to a mii_timestamper from the probe_channel() callback of their
44  * mii_timestamping_ctrl interface.
45  */
46 struct mii_timestamper {
47         bool (*rxtstamp)(struct mii_timestamper *mii_ts,
48                          struct sk_buff *skb, int type);
49
50         void (*txtstamp)(struct mii_timestamper *mii_ts,
51                          struct sk_buff *skb, int type);
52
53         int  (*hwtstamp)(struct mii_timestamper *mii_ts,
54                          struct ifreq *ifreq);
55
56         void (*link_state)(struct mii_timestamper *mii_ts,
57                            struct phy_device *phydev);
58
59         int  (*ts_info)(struct mii_timestamper *mii_ts,
60                         struct ethtool_ts_info *ts_info);
61
62         struct device *device;
63 };
64
65 /**
66  * struct mii_timestamping_ctrl - MII time stamping controller interface.
67  *
68  * @probe_channel:      Callback into the controller driver announcing the
69  *                      presence of the 'port' channel.  The 'device' field
70  *                      had been passed to register_mii_tstamp_controller().
71  *                      The driver must return either a pointer to a valid
72  *                      MII timestamper instance or PTR_ERR.
73  *
74  * @release_channel:    Releases an instance obtained via .probe_channel.
75  */
76 struct mii_timestamping_ctrl {
77         struct mii_timestamper *(*probe_channel)(struct device *device,
78                                                  unsigned int port);
79         void (*release_channel)(struct device *device,
80                                 struct mii_timestamper *mii_ts);
81 };
82
83 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
84
85 int register_mii_tstamp_controller(struct device *device,
86                                    struct mii_timestamping_ctrl *ctrl);
87
88 void unregister_mii_tstamp_controller(struct device *device);
89
90 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
91                                                  unsigned int port);
92
93 void unregister_mii_timestamper(struct mii_timestamper *mii_ts);
94
95 #else
96
97 static inline
98 int register_mii_tstamp_controller(struct device *device,
99                                    struct mii_timestamping_ctrl *ctrl)
100 {
101         return -EOPNOTSUPP;
102 }
103
104 static inline void unregister_mii_tstamp_controller(struct device *device)
105 {
106 }
107
108 static inline
109 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
110                                                  unsigned int port)
111 {
112         return NULL;
113 }
114
115 static inline void unregister_mii_timestamper(struct mii_timestamper *mii_ts)
116 {
117 }
118
119 #endif
120
121 #endif