Blame view

net/core/timestamping.c 1.45 KB
74ba9207e   Thomas Gleixner   treewide: Replace...
1
  // SPDX-License-Identifier: GPL-2.0-or-later
c1f19b51d   Richard Cochran   net: support time...
2
3
4
5
  /*
   * PTP 1588 clock support - support for timestamping in PHY devices
   *
   * Copyright (C) 2010 OMICRON electronics GmbH
c1f19b51d   Richard Cochran   net: support time...
6
7
8
9
10
   */
  #include <linux/errqueue.h>
  #include <linux/phy.h>
  #include <linux/ptp_classify.h>
  #include <linux/skbuff.h>
bc3b2d7fb   Paul Gortmaker   net: Add export.h...
11
  #include <linux/export.h>
c1f19b51d   Richard Cochran   net: support time...
12

62ab08121   Eric Dumazet   filter: constify ...
13
  static unsigned int classify(const struct sk_buff *skb)
c1f19b51d   Richard Cochran   net: support time...
14
  {
e62d2df08   Daniel Borkmann   net: ptp: use sk_...
15
  	if (likely(skb->dev && skb->dev->phydev &&
4715f65ff   Richard Cochran   net: Introduce a ...
16
  		   skb->dev->phydev->mii_ts))
164d8c666   Daniel Borkmann   net: ptp: do not ...
17
  		return ptp_classify_raw(skb);
c1f19b51d   Richard Cochran   net: support time...
18
19
20
21
22
23
  	else
  		return PTP_CLASS_NONE;
  }
  
  void skb_clone_tx_timestamp(struct sk_buff *skb)
  {
4715f65ff   Richard Cochran   net: Introduce a ...
24
  	struct mii_timestamper *mii_ts;
c1f19b51d   Richard Cochran   net: support time...
25
  	struct sk_buff *clone;
c1f19b51d   Richard Cochran   net: support time...
26
  	unsigned int type;
62bccb8cd   Alexander Duyck   net-timestamp: Ma...
27
  	if (!skb->sk)
c1f19b51d   Richard Cochran   net: support time...
28
29
30
  		return;
  
  	type = classify(skb);
b9c701edc   Stefan Sørensen   net: Simplify ptp...
31
32
  	if (type == PTP_CLASS_NONE)
  		return;
4715f65ff   Richard Cochran   net: Introduce a ...
33
34
  	mii_ts = skb->dev->phydev->mii_ts;
  	if (likely(mii_ts->txtstamp)) {
62bccb8cd   Alexander Duyck   net-timestamp: Ma...
35
36
  		clone = skb_clone_sk(skb);
  		if (!clone)
b9c701edc   Stefan Sørensen   net: Simplify ptp...
37
  			return;
4715f65ff   Richard Cochran   net: Introduce a ...
38
  		mii_ts->txtstamp(mii_ts, clone, type);
c1f19b51d   Richard Cochran   net: support time...
39
40
  	}
  }
1c17216ee   Richard Cochran   net: export time ...
41
  EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp);
c1f19b51d   Richard Cochran   net: support time...
42

c1f19b51d   Richard Cochran   net: support time...
43
44
  bool skb_defer_rx_timestamp(struct sk_buff *skb)
  {
4715f65ff   Richard Cochran   net: Introduce a ...
45
  	struct mii_timestamper *mii_ts;
c1f19b51d   Richard Cochran   net: support time...
46
  	unsigned int type;
4715f65ff   Richard Cochran   net: Introduce a ...
47
  	if (!skb->dev || !skb->dev->phydev || !skb->dev->phydev->mii_ts)
1007f59dc   Alexander Duyck   net: skb_defer_rx...
48
  		return false;
a19faf025   Eric Dumazet   net: fix skb_defe...
49
50
  	if (skb_headroom(skb) < ETH_HLEN)
  		return false;
1007f59dc   Alexander Duyck   net: skb_defer_rx...
51

a19faf025   Eric Dumazet   net: fix skb_defe...
52
  	__skb_push(skb, ETH_HLEN);
c1f19b51d   Richard Cochran   net: support time...
53

1007f59dc   Alexander Duyck   net: skb_defer_rx...
54
  	type = ptp_classify_raw(skb);
c1f19b51d   Richard Cochran   net: support time...
55

a19faf025   Eric Dumazet   net: fix skb_defe...
56
  	__skb_pull(skb, ETH_HLEN);
c1f19b51d   Richard Cochran   net: support time...
57

b9c701edc   Stefan Sørensen   net: Simplify ptp...
58
59
  	if (type == PTP_CLASS_NONE)
  		return false;
4715f65ff   Richard Cochran   net: Introduce a ...
60
61
62
  	mii_ts = skb->dev->phydev->mii_ts;
  	if (likely(mii_ts->rxtstamp))
  		return mii_ts->rxtstamp(mii_ts, skb, type);
c1f19b51d   Richard Cochran   net: support time...
63
64
65
  
  	return false;
  }
238442f6b   Richard Cochran   net: export the r...
66
  EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);