]>
Commit | Line | Data |
---|---|---|
74ba9207 | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
c1f19b51 RC |
2 | /* |
3 | * PTP 1588 clock support - support for timestamping in PHY devices | |
4 | * | |
5 | * Copyright (C) 2010 OMICRON electronics GmbH | |
c1f19b51 RC |
6 | */ |
7 | #include <linux/errqueue.h> | |
8 | #include <linux/phy.h> | |
9 | #include <linux/ptp_classify.h> | |
10 | #include <linux/skbuff.h> | |
bc3b2d7f | 11 | #include <linux/export.h> |
c1f19b51 | 12 | |
62ab0812 | 13 | static unsigned int classify(const struct sk_buff *skb) |
c1f19b51 | 14 | { |
e62d2df0 | 15 | if (likely(skb->dev && skb->dev->phydev && |
4715f65f | 16 | skb->dev->phydev->mii_ts)) |
164d8c66 | 17 | return ptp_classify_raw(skb); |
c1f19b51 RC |
18 | else |
19 | return PTP_CLASS_NONE; | |
20 | } | |
21 | ||
22 | void skb_clone_tx_timestamp(struct sk_buff *skb) | |
23 | { | |
4715f65f | 24 | struct mii_timestamper *mii_ts; |
c1f19b51 | 25 | struct sk_buff *clone; |
c1f19b51 RC |
26 | unsigned int type; |
27 | ||
62bccb8c | 28 | if (!skb->sk) |
c1f19b51 RC |
29 | return; |
30 | ||
31 | type = classify(skb); | |
b9c701ed SS |
32 | if (type == PTP_CLASS_NONE) |
33 | return; | |
34 | ||
4715f65f RC |
35 | mii_ts = skb->dev->phydev->mii_ts; |
36 | if (likely(mii_ts->txtstamp)) { | |
62bccb8c AD |
37 | clone = skb_clone_sk(skb); |
38 | if (!clone) | |
b9c701ed | 39 | return; |
4715f65f | 40 | mii_ts->txtstamp(mii_ts, clone, type); |
c1f19b51 RC |
41 | } |
42 | } | |
1c17216e | 43 | EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp); |
c1f19b51 | 44 | |
c1f19b51 RC |
45 | bool skb_defer_rx_timestamp(struct sk_buff *skb) |
46 | { | |
4715f65f | 47 | struct mii_timestamper *mii_ts; |
c1f19b51 RC |
48 | unsigned int type; |
49 | ||
4715f65f | 50 | if (!skb->dev || !skb->dev->phydev || !skb->dev->phydev->mii_ts) |
1007f59d AD |
51 | return false; |
52 | ||
a19faf02 ED |
53 | if (skb_headroom(skb) < ETH_HLEN) |
54 | return false; | |
1007f59d | 55 | |
a19faf02 | 56 | __skb_push(skb, ETH_HLEN); |
c1f19b51 | 57 | |
1007f59d | 58 | type = ptp_classify_raw(skb); |
c1f19b51 | 59 | |
a19faf02 | 60 | __skb_pull(skb, ETH_HLEN); |
c1f19b51 | 61 | |
b9c701ed SS |
62 | if (type == PTP_CLASS_NONE) |
63 | return false; | |
64 | ||
4715f65f RC |
65 | mii_ts = skb->dev->phydev->mii_ts; |
66 | if (likely(mii_ts->rxtstamp)) | |
67 | return mii_ts->rxtstamp(mii_ts, skb, type); | |
c1f19b51 RC |
68 | |
69 | return false; | |
70 | } | |
238442f6 | 71 | EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp); |