mii_timestamper.h 3.6 KB

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