Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Support for generic time stamping devices on MII buses.
0004  * Copyright (C) 2018 Richard Cochran <richardcochran@gmail.com>
0005  */
0006 #ifndef _LINUX_MII_TIMESTAMPER_H
0007 #define _LINUX_MII_TIMESTAMPER_H
0008 
0009 #include <linux/device.h>
0010 #include <linux/ethtool.h>
0011 #include <linux/skbuff.h>
0012 
0013 struct phy_device;
0014 
0015 /**
0016  * struct mii_timestamper - Callback interface to MII time stamping devices.
0017  *
0018  * @rxtstamp:   Requests a Rx timestamp for 'skb'.  If the skb is accepted,
0019  *      the MII time stamping device promises to deliver it using
0020  *      netif_rx() as soon as a timestamp becomes available. One of
0021  *      the PTP_CLASS_ values is passed in 'type'.  The function
0022  *      must return true if the skb is accepted for delivery.
0023  *
0024  * @txtstamp:   Requests a Tx timestamp for 'skb'.  The MII time stamping
0025  *      device promises to deliver it using skb_complete_tx_timestamp()
0026  *      as soon as a timestamp becomes available. One of the PTP_CLASS_
0027  *      values is passed in 'type'.
0028  *
0029  * @hwtstamp:   Handles SIOCSHWTSTAMP ioctl for hardware time stamping.
0030  *
0031  * @link_state: Allows the device to respond to changes in the link
0032  *      state.  The caller invokes this function while holding
0033  *      the phy_device mutex.
0034  *
0035  * @ts_info:    Handles ethtool queries for hardware time stamping.
0036  * @device: Remembers the device to which the instance belongs.
0037  *
0038  * Drivers for PHY time stamping devices should embed their
0039  * mii_timestamper within a private structure, obtaining a reference
0040  * to it using container_of().
0041  *
0042  * Drivers for non-PHY time stamping devices should return a pointer
0043  * to a mii_timestamper from the probe_channel() callback of their
0044  * mii_timestamping_ctrl interface.
0045  */
0046 struct mii_timestamper {
0047     bool (*rxtstamp)(struct mii_timestamper *mii_ts,
0048              struct sk_buff *skb, int type);
0049 
0050     void (*txtstamp)(struct mii_timestamper *mii_ts,
0051              struct sk_buff *skb, int type);
0052 
0053     int  (*hwtstamp)(struct mii_timestamper *mii_ts,
0054              struct ifreq *ifreq);
0055 
0056     void (*link_state)(struct mii_timestamper *mii_ts,
0057                struct phy_device *phydev);
0058 
0059     int  (*ts_info)(struct mii_timestamper *mii_ts,
0060             struct ethtool_ts_info *ts_info);
0061 
0062     struct device *device;
0063 };
0064 
0065 /**
0066  * struct mii_timestamping_ctrl - MII time stamping controller interface.
0067  *
0068  * @probe_channel:  Callback into the controller driver announcing the
0069  *          presence of the 'port' channel.  The 'device' field
0070  *          had been passed to register_mii_tstamp_controller().
0071  *          The driver must return either a pointer to a valid
0072  *          MII timestamper instance or PTR_ERR.
0073  *
0074  * @release_channel:    Releases an instance obtained via .probe_channel.
0075  */
0076 struct mii_timestamping_ctrl {
0077     struct mii_timestamper *(*probe_channel)(struct device *device,
0078                          unsigned int port);
0079     void (*release_channel)(struct device *device,
0080                 struct mii_timestamper *mii_ts);
0081 };
0082 
0083 #ifdef CONFIG_NETWORK_PHY_TIMESTAMPING
0084 
0085 int register_mii_tstamp_controller(struct device *device,
0086                    struct mii_timestamping_ctrl *ctrl);
0087 
0088 void unregister_mii_tstamp_controller(struct device *device);
0089 
0090 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
0091                          unsigned int port);
0092 
0093 void unregister_mii_timestamper(struct mii_timestamper *mii_ts);
0094 
0095 #else
0096 
0097 static inline
0098 int register_mii_tstamp_controller(struct device *device,
0099                    struct mii_timestamping_ctrl *ctrl)
0100 {
0101     return -EOPNOTSUPP;
0102 }
0103 
0104 static inline void unregister_mii_tstamp_controller(struct device *device)
0105 {
0106 }
0107 
0108 static inline
0109 struct mii_timestamper *register_mii_timestamper(struct device_node *node,
0110                          unsigned int port)
0111 {
0112     return NULL;
0113 }
0114 
0115 static inline void unregister_mii_timestamper(struct mii_timestamper *mii_ts)
0116 {
0117 }
0118 
0119 #endif
0120 
0121 #endif