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>
12 #include <linux/net_tstamp.h>
17 * struct mii_timestamper - Callback interface to MII time stamping devices.
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.
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'.
30 * @hwtstamp: Handles SIOCSHWTSTAMP ioctl for hardware time stamping.
32 * @link_state: Allows the device to respond to changes in the link
33 * state. The caller invokes this function while holding
34 * the phy_device mutex.
36 * @ts_info: Handles ethtool queries for hardware time stamping.
37 * @device: Remembers the device to which the instance belongs.
39 * Drivers for PHY time stamping devices should embed their
40 * mii_timestamper within a private structure, obtaining a reference
41 * to it using container_of().
43 * Drivers for non-PHY time stamping devices should return a pointer
44 * to a mii_timestamper from the probe_channel() callback of their
45 * mii_timestamping_ctrl interface.
47 struct mii_timestamper
{
48 bool (*rxtstamp
)(struct mii_timestamper
*mii_ts
,
49 struct sk_buff
*skb
, int type
);
51 void (*txtstamp
)(struct mii_timestamper
*mii_ts
,
52 struct sk_buff
*skb
, int type
);
54 int (*hwtstamp
)(struct mii_timestamper
*mii_ts
,
55 struct kernel_hwtstamp_config
*kernel_config
,
56 struct netlink_ext_ack
*extack
);
58 void (*link_state
)(struct mii_timestamper
*mii_ts
,
59 struct phy_device
*phydev
);
61 int (*ts_info
)(struct mii_timestamper
*mii_ts
,
62 struct kernel_ethtool_ts_info
*ts_info
);
64 struct device
*device
;
68 * struct mii_timestamping_ctrl - MII time stamping controller interface.
70 * @probe_channel: Callback into the controller driver announcing the
71 * presence of the 'port' channel. The 'device' field
72 * had been passed to register_mii_tstamp_controller().
73 * The driver must return either a pointer to a valid
74 * MII timestamper instance or PTR_ERR.
76 * @release_channel: Releases an instance obtained via .probe_channel.
78 struct mii_timestamping_ctrl
{
79 struct mii_timestamper
*(*probe_channel
)(struct device
*device
,
81 void (*release_channel
)(struct device
*device
,
82 struct mii_timestamper
*mii_ts
);
85 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
87 int register_mii_tstamp_controller(struct device
*device
,
88 struct mii_timestamping_ctrl
*ctrl
);
90 void unregister_mii_tstamp_controller(struct device
*device
);
92 struct mii_timestamper
*register_mii_timestamper(struct device_node
*node
,
95 void unregister_mii_timestamper(struct mii_timestamper
*mii_ts
);
100 int register_mii_tstamp_controller(struct device
*device
,
101 struct mii_timestamping_ctrl
*ctrl
)
106 static inline void unregister_mii_tstamp_controller(struct device
*device
)
111 struct mii_timestamper
*register_mii_timestamper(struct device_node
*node
,
117 static inline void unregister_mii_timestamper(struct mii_timestamper
*mii_ts
)