1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Support for generic time stamping devices on MII buses.
4 * Copyright (C) 2018 Richard Cochran <richardcochran@gmail.com>
6 #ifndef _LINUX_MII_TIMESTAMPER_H
7 #define _LINUX_MII_TIMESTAMPER_H
9 #include <linux/device.h>
10 #include <linux/ethtool.h>
11 #include <linux/skbuff.h>
16 * struct mii_timestamper - Callback interface to MII time stamping devices.
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.
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'.
29 * @hwtstamp: Handles SIOCSHWTSTAMP ioctl for hardware time stamping.
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.
35 * @ts_info: Handles ethtool queries for hardware time stamping.
36 * @device: Remembers the device to which the instance belongs.
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().
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.
46 struct mii_timestamper {
47 bool (*rxtstamp)(struct mii_timestamper *mii_ts,
48 struct sk_buff *skb, int type);
50 void (*txtstamp)(struct mii_timestamper *mii_ts,
51 struct sk_buff *skb, int type);
53 int (*hwtstamp)(struct mii_timestamper *mii_ts,
56 void (*link_state)(struct mii_timestamper *mii_ts,
57 struct phy_device *phydev);
59 int (*ts_info)(struct mii_timestamper *mii_ts,
60 struct ethtool_ts_info *ts_info);
62 struct device *device;
66 * struct mii_timestamping_ctrl - MII time stamping controller interface.
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.
74 * @release_channel: Releases an instance obtained via .probe_channel.
76 struct mii_timestamping_ctrl {
77 struct mii_timestamper *(*probe_channel)(struct device *device,
79 void (*release_channel)(struct device *device,
80 struct mii_timestamper *mii_ts);
83 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
85 int register_mii_tstamp_controller(struct device *device,
86 struct mii_timestamping_ctrl *ctrl);
88 void unregister_mii_tstamp_controller(struct device *device);
90 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
93 void unregister_mii_timestamper(struct mii_timestamper *mii_ts);
98 int register_mii_tstamp_controller(struct device *device,
99 struct mii_timestamping_ctrl *ctrl)
104 static inline void unregister_mii_tstamp_controller(struct device *device)
109 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
115 static inline void unregister_mii_timestamper(struct mii_timestamper *mii_ts)