]> git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blame - net/core/timestamping.c
UBUNTU: Start new release
[mirror_ubuntu-zesty-kernel.git] / net / core / timestamping.c
CommitLineData
c1f19b51
RC
1/*
2 * PTP 1588 clock support - support for timestamping in PHY devices
3 *
4 * Copyright (C) 2010 OMICRON electronics GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 */
20#include <linux/errqueue.h>
21#include <linux/phy.h>
22#include <linux/ptp_classify.h>
23#include <linux/skbuff.h>
bc3b2d7f 24#include <linux/export.h>
c1f19b51 25
62ab0812 26static unsigned int classify(const struct sk_buff *skb)
c1f19b51 27{
e62d2df0 28 if (likely(skb->dev && skb->dev->phydev &&
c1f19b51 29 skb->dev->phydev->drv))
164d8c66 30 return ptp_classify_raw(skb);
c1f19b51
RC
31 else
32 return PTP_CLASS_NONE;
33}
34
35void skb_clone_tx_timestamp(struct sk_buff *skb)
36{
37 struct phy_device *phydev;
38 struct sk_buff *clone;
c1f19b51
RC
39 unsigned int type;
40
62bccb8c 41 if (!skb->sk)
c1f19b51
RC
42 return;
43
44 type = classify(skb);
b9c701ed
SS
45 if (type == PTP_CLASS_NONE)
46 return;
47
48 phydev = skb->dev->phydev;
49 if (likely(phydev->drv->txtstamp)) {
62bccb8c
AD
50 clone = skb_clone_sk(skb);
51 if (!clone)
b9c701ed 52 return;
b9c701ed 53 phydev->drv->txtstamp(phydev, clone, type);
c1f19b51
RC
54 }
55}
1c17216e 56EXPORT_SYMBOL_GPL(skb_clone_tx_timestamp);
c1f19b51 57
c1f19b51
RC
58bool skb_defer_rx_timestamp(struct sk_buff *skb)
59{
60 struct phy_device *phydev;
61 unsigned int type;
62
1007f59d
AD
63 if (!skb->dev || !skb->dev->phydev || !skb->dev->phydev->drv)
64 return false;
65
a19faf02
ED
66 if (skb_headroom(skb) < ETH_HLEN)
67 return false;
1007f59d 68
a19faf02 69 __skb_push(skb, ETH_HLEN);
c1f19b51 70
1007f59d 71 type = ptp_classify_raw(skb);
c1f19b51 72
a19faf02 73 __skb_pull(skb, ETH_HLEN);
c1f19b51 74
b9c701ed
SS
75 if (type == PTP_CLASS_NONE)
76 return false;
77
78 phydev = skb->dev->phydev;
79 if (likely(phydev->drv->rxtstamp))
80 return phydev->drv->rxtstamp(phydev, skb, type);
c1f19b51
RC
81
82 return false;
83}
238442f6 84EXPORT_SYMBOL_GPL(skb_defer_rx_timestamp);