Extend Time Stamping
Subsystems (8)
Richard Cochran
maintainerv3 cover Extend Time Stamping
This patch set extends the packet time stamping capabilites of the network stack in two ways.
1. The first patch presents a work-around for the TX software time stamping fallback problem cited in cd4d8fdad1f1. The idea is to add one inline function into each MAC driver. This function will act as hooks for current (and possible future) time stamping needs, once they are placed correctly within each MAC driver.
2. The other patches prepare the way for PHY drivers to offer time stamping.
I am preparing a new round of patches for PTP support, but it will require the changes in this patch set in order to function. Thus I would like to have this patch set reviewed (and hopefully merged) in order to go forward.
Thanks,
Richard
* Patch ChangeLog
** v3
After having received plenty of criticism on the idea of reading from the MDIO bus during the critical paths, this version presents a new approach. Now, when the CONFIG option for PHY time stamping is enabled, likely packets for time stamping are identified by the stack and presented to the PHY driver. The driver may accept the packet and defer its deliverly until the time stamp becomes available at a later time. This approach brings four main advantages.
1. Now only one MAC driver hook is necessary.
2. It leaves the option of how to get the time stamps open, allowing, for example, a driver to get them either via MDIO or PHY status frames.
3. If reading the MDIO bus is required to get the time stamp, this can be done during as a work queue task.
4. It moves the identification of PTP packets into the stack, so that each new PHY driver that comes only will not have to duplicate this logic again.
** v2
Removed the CONFIG option for the driver hooks.
Richard Cochran (4):
net: add driver hook for tx time stamping.
net: preserve ifreq parameter when calling generic phy_mii_ioctl().
net: added a BPF to help drivers detect PTP packets.
net: support time stamping in phy devices.
drivers/net/arm/ixp4xx_eth.c | 3 +- drivers/net/au1000_eth.c | 2 +- drivers/net/bcm63xx_enet.c | 2 +- drivers/net/cpmac.c | 5 +- drivers/net/dnet.c | 2 +- drivers/net/ethoc.c | 2 +- drivers/net/fec.c | 2 +- drivers/net/fec_mpc52xx.c | 2 +- drivers/net/fs_enet/fs_enet-main.c | 3 +- drivers/net/gianfar.c | 2 +- drivers/net/macb.c | 2 +- drivers/net/mv643xx_eth.c | 2 +- drivers/net/octeon/octeon_mgmt.c | 2 +- drivers/net/phy/phy.c | 8 ++- drivers/net/phy/phy_device.c | 2 + drivers/net/sb1250-mac.c | 2 +- drivers/net/sh_eth.c | 2 +- drivers/net/smsc911x.c | 2 +- drivers/net/smsc9420.c | 2 +- drivers/net/stmmac/stmmac_main.c | 22 ++---- drivers/net/tc35815.c | 2 +- drivers/net/tg3.c | 2 +- drivers/net/ucc_geth.c | 2 +- drivers/staging/octeon/ethernet-mdio.c | 2 +- include/linux/netdevice.h | 4 + include/linux/phy.h | 24 ++++++- include/linux/ptp_classify.h | 126 ++++++++++++++++++++++++++++++++ include/linux/skbuff.h | 52 +++++++++++++ net/Kconfig | 10 +++ net/core/Makefile | 2 +- net/core/dev.c | 3 + net/core/timestamping.c | 126 ++++++++++++++++++++++++++++++++ net/dsa/slave.c | 3 +- net/socket.c | 4 + 34 files changed, 389 insertions(+), 44 deletions(-) create mode 100644 include/linux/ptp_classify.h create mode 100644 net/core/timestamping.c
Richard Cochran
maintainerPATCH v3 1/4 net: add driver hook for tx time stamping.
This patch adds a hook for transmit time stamps. The transmit hook allows a software fallback for transmit time stamps, for MACs lacking time stamping hardware. Using the hook will still require adding an inline function call to each MAC driver.
--- include/linux/skbuff.h | 21 +++++++++++++++++++++ 1 files changed, 21 insertions(+), 0 deletions(-)
include/linux/skbuff.h +21 -0
@@ -1947,6 +1947,27 @@ static inline ktime_t net_invalid_timestamp(void)extern void skb_tstamp_tx (struct sk_buff *orig_skb,struct skb_shared_hwtstamps *hwtstamps); +static inline void sw_tx_timestamp (struct sk_buff *skb) +{ +union skb_shared_tx *shtx =skb_tx (skb); +if (shtx->software && !shtx->in_progress) +skb_tstamp_tx (skb,NULL ); +} + +/** +* skb_tx_timestamp() - Driver hook for transmit timestamping +* +* Ethernet MAC Drivers should call this function in their hard_xmit() +* function as soon as possible after giving the sk_buff to the MAC +* hardware, but before freeing the sk_buff. +* +* @skb: A socket buffer. +*/ +static inline void skb_tx_timestamp (struct sk_buff *skb) +{ +sw_tx_timestamp (skb); +} +extern __sum16 __skb_checksum_complete_head (struct sk_buff *skb,int len);extern __sum16 __skb_checksum_complete (struct sk_buff *skb);
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v3 2/4 net: preserve ifreq parameter when calling generic phy_mii_ioctl().
In reply to Richard CochranThe phy_mii_ioctl() function unnecessarily throws away the original ifreq. We need access to the ifreq in order to support PHYs that can perform hardware time stamping.
Two maverick drivers filter the ioctl commands passed to phy_mii_ioctl(). This is unnecessary since phylib will check the command in any case.
--- drivers/net/arm/ixp4xx_eth.c | 3 ++- drivers/net/au1000_eth.c | 2 +- drivers/net/bcm63xx_enet.c | 2 +- drivers/net/cpmac.c | 5 +---- drivers/net/dnet.c | 2 +- drivers/net/ethoc.c | 2 +- drivers/net/fec.c | 2 +- drivers/net/fec_mpc52xx.c | 2 +- drivers/net/fs_enet/fs_enet-main.c | 3 +-- drivers/net/gianfar.c | 2 +- drivers/net/macb.c | 2 +- drivers/net/mv643xx_eth.c | 2 +- drivers/net/octeon/octeon_mgmt.c | 2 +- drivers/net/phy/phy.c | 3 ++- drivers/net/sb1250-mac.c | 2 +- drivers/net/sh_eth.c | 2 +- drivers/net/smsc911x.c | 2 +- drivers/net/smsc9420.c | 2 +- drivers/net/stmmac/stmmac_main.c | 22 ++++++++-------------- drivers/net/tc35815.c | 2 +- drivers/net/tg3.c | 2 +- drivers/net/ucc_geth.c | 2 +- drivers/staging/octeon/ethernet-mdio.c | 2 +- include/linux/phy.h | 2 +- net/dsa/slave.c | 3 +-- 25 files changed, 34 insertions(+), 43 deletions(-)
drivers/net/arm/ixp4xx_eth.c +2 -1
@@ -782,7 +782,8 @@ static int eth_ioctl(struct net_device *dev, struct ifreq *req, int cmd)if (!netif_running (dev))return -EINVAL ; -return phy_mii_ioctl (port->phydev,if_mii (req), cmd); + +return phy_mii_ioctl (port->phydev, req, cmd); }/* ethtool support */
drivers/net/au1000_eth.c +1 -1
@@ -978,7 +978,7 @@ static int au1000_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!aup->phy_dev)return -EINVAL ;/* PHY not controllable */ -return phy_mii_ioctl (aup->phy_dev,if_mii (rq), cmd); +return phy_mii_ioctl (aup->phy_dev, rq, cmd); }static const struct net_device_ops au1000_netdev_ops = {
drivers/net/bcm63xx_enet.c +1 -1
@@ -1496,7 +1496,7 @@ static int bcm_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (priv->has_phy) {if (!priv->phydev)return -ENODEV ; -return phy_mii_ioctl (priv->phydev,if_mii (rq), cmd); +return phy_mii_ioctl (priv->phydev, rq, cmd); }else {struct mii_if_info mii;
drivers/net/cpmac.c +1 -4
@@ -846,11 +846,8 @@ static int cpmac_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)return -EINVAL ;if (!priv->phy)return -EINVAL ; -if ((cmd ==SIOCGMIIPHY ) || (cmd ==SIOCGMIIREG ) || - (cmd ==SIOCSMIIREG )) -return phy_mii_ioctl (priv->phy,if_mii (ifr), cmd); -return -EOPNOTSUPP ; +return phy_mii_ioctl (priv->phy, ifr, cmd); }static int cpmac_get_settings (struct net_device *dev,struct ethtool_cmd *cmd)
drivers/net/dnet.c +1 -1
@@ -797,7 +797,7 @@ static int dnet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!phydev)return -ENODEV ; -return phy_mii_ioctl (phydev,if_mii (rq), cmd); +return phy_mii_ioctl (phydev, rq, cmd); } static void dnet_get_drvinfo(struct net_device *dev,
drivers/net/ethoc.c +1 -1
@@ -732,7 +732,7 @@ static int ethoc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) phy = priv->phy; } -return phy_mii_ioctl (phy, mdio, cmd); +return phy_mii_ioctl (phy, ifr, cmd); }static int ethoc_config (struct net_device *dev,struct ifmap *map)
drivers/net/fec.c +1 -1
@@ -828,7 +828,7 @@ static int fec_enet_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!phydev)return -ENODEV ; -return phy_mii_ioctl (phydev,if_mii (rq), cmd); +return phy_mii_ioctl (phydev, rq, cmd); }static void fec_enet_free_buffers (struct net_device *dev)
drivers/net/fec_mpc52xx.c +1 -1
@@ -826,7 +826,7 @@ static int mpc52xx_fec_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!priv->phydev)return -ENOTSUPP ; -return phy_mii_ioctl (priv->phydev,if_mii (rq), cmd); +return phy_mii_ioctl (priv->phydev, rq, cmd); }static const struct net_device_ops mpc52xx_fec_netdev_ops = {
drivers/net/fs_enet/fs_enet-main.c +1 -2
@@ -963,12 +963,11 @@ static const struct ethtool_ops fs_ethtool_ops = {static int fs_ioctl (struct net_device *dev,struct ifreq *rq,int cmd) {struct fs_enet_private *fep =netdev_priv (dev); -struct mii_ioctl_data *mii = (struct mii_ioctl_data *)&rq->ifr_data;if (!netif_running (dev))return -EINVAL ; -return phy_mii_ioctl (fep->phydev, mii, cmd); +return phy_mii_ioctl (fep->phydev, rq, cmd); }extern int fs_mii_connect (struct net_device *dev);
drivers/net/gianfar.c +1 -1
@@ -847,7 +847,7 @@ static int gfar_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!priv->phydev)return -ENODEV ; -return phy_mii_ioctl (priv->phydev,if_mii (rq), cmd); +return phy_mii_ioctl (priv->phydev, rq, cmd); }static unsigned int reverse_bitmap (unsigned int bit_map,unsigned int max_qs)
drivers/net/macb.c +1 -1
@@ -1082,7 +1082,7 @@ static int macb_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!phydev)return -ENODEV ; -return phy_mii_ioctl (phydev,if_mii (rq), cmd); +return phy_mii_ioctl (phydev, rq, cmd); }static const struct net_device_ops macb_netdev_ops = {
drivers/net/mv643xx_eth.c +1 -1
@@ -2457,7 +2457,7 @@ static int mv643xx_eth_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)struct mv643xx_eth_private *mp =netdev_priv (dev);if (mp->phy !=NULL ) -return phy_mii_ioctl (mp->phy,if_mii (ifr), cmd); +return phy_mii_ioctl (mp->phy, ifr, cmd);return -EOPNOTSUPP ; }
drivers/net/octeon/octeon_mgmt.c +1 -1
@@ -620,7 +620,7 @@ static int octeon_mgmt_ioctl(struct net_device *netdev,if (!p->phydev)return -EINVAL ; -return phy_mii_ioctl (p->phydev,if_mii (rq), cmd); +return phy_mii_ioctl (p->phydev, rq, cmd); }static void octeon_mgmt_adjust_link (struct net_device *netdev)
drivers/net/phy/phy.c +2 -1
@@ -309,8 +309,9 @@ EXPORT_SYMBOL(phy_ethtool_gset);* current state. Use at own risk. */ int phy_mii_ioctl (struct phy_device *phydev, -struct mii_ioctl_data *mii_data,int cmd) +struct ifreq *ifr,int cmd) { +struct mii_ioctl_data *mii_data =if_mii (ifr);u16 val = mii_data->val_in;switch (cmd) {
drivers/net/sb1250-mac.c +1 -1
@@ -2532,7 +2532,7 @@ static int sbmac_mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!netif_running (dev) || !sc->phy_dev)return -EINVAL ; -return phy_mii_ioctl (sc->phy_dev,if_mii (rq), cmd); +return phy_mii_ioctl (sc->phy_dev, rq, cmd); }static int sbmac_close (struct net_device *dev)
drivers/net/sh_eth.c +1 -1
@@ -1233,7 +1233,7 @@ static int sh_eth_do_ioctl(struct net_device *ndev, struct ifreq *rq,if (!phydev)return -ENODEV ; -return phy_mii_ioctl (phydev,if_mii (rq), cmd); +return phy_mii_ioctl (phydev, rq, cmd); }#if defined(SH_ETH_HAS_TSU )
drivers/net/smsc911x.c +1 -1
@@ -1538,7 +1538,7 @@ static int smsc911x_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)if (!netif_running (dev) || !pdata->phy_dev)return -EINVAL ; -return phy_mii_ioctl (pdata->phy_dev,if_mii (ifr), cmd); +return phy_mii_ioctl (pdata->phy_dev, ifr, cmd); } static int
drivers/net/smsc9420.c +1 -1
@@ -245,7 +245,7 @@ static int smsc9420_do_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)if (!netif_running (dev) || !pd->phy_dev)return -EINVAL ; -return phy_mii_ioctl (pd->phy_dev,if_mii (ifr), cmd); +return phy_mii_ioctl (pd->phy_dev, ifr, cmd); } static int smsc9420_ethtool_get_settings(struct net_device *dev,
drivers/net/stmmac/stmmac_main.c +8 -14
@@ -1437,24 +1437,18 @@ static void stmmac_poll_controller(struct net_device *dev)static int stmmac_ioctl (struct net_device *dev,struct ifreq *rq,int cmd) {struct stmmac_priv *priv =netdev_priv (dev); -int ret = -EOPNOTSUPP ; +int ret;if (!netif_running (dev))return -EINVAL ; -switch (cmd) { -case SIOCGMIIPHY : -case SIOCGMIIREG : -case SIOCSMIIREG : -if (!priv->phydev) -return -EINVAL ; - -spin_lock (&priv->lock); - ret =phy_mii_ioctl (priv->phydev,if_mii (rq), cmd); -spin_unlock (&priv->lock); -default : -break ; - } +if (!priv->phydev) +return -EINVAL ; + +spin_lock (&priv->lock); + ret =phy_mii_ioctl (priv->phydev, rq, cmd); +spin_unlock (&priv->lock); +return ret; }
drivers/net/tc35815.c +1 -1
@@ -2066,7 +2066,7 @@ static int tc35815_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)return -EINVAL ;if (!lp->phy_dev)return -ENODEV ; -return phy_mii_ioctl (lp->phy_dev,if_mii (rq), cmd); +return phy_mii_ioctl (lp->phy_dev, rq, cmd); }static void tc35815_chip_reset (struct net_device *dev)
drivers/net/tg3.c +1 -1
@@ -10954,7 +10954,7 @@ static int tg3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)if (!(tp->tg3_flags3 &TG3_FLG3_PHY_CONNECTED ))return -EAGAIN ; phydev = tp->mdio_bus->phy_map[TG3_PHY_MII_ADDR ]; -return phy_mii_ioctl (phydev, data, cmd); +return phy_mii_ioctl (phydev, ifr, cmd); }switch (cmd) {
drivers/net/ucc_geth.c +1 -1
@@ -3714,7 +3714,7 @@ static int ucc_geth_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!ugeth->phydev)return -ENODEV ; -return phy_mii_ioctl (ugeth->phydev,if_mii (rq), cmd); +return phy_mii_ioctl (ugeth->phydev, rq, cmd); }static const struct net_device_ops ucc_geth_netdev_ops = {
drivers/staging/octeon/ethernet-mdio.c +1 -1
@@ -113,7 +113,7 @@ int cvm_oct_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)if (!priv->phydev)return -EINVAL ; -return phy_mii_ioctl (priv->phydev,if_mii (rq), cmd); +return phy_mii_ioctl (priv->phydev, rq, cmd); }static void cvm_oct_adjust_link (struct net_device *dev)
include/linux/phy.h +1 -1
@@ -498,7 +498,7 @@ void phy_stop_machine(struct phy_device *phydev);int phy_ethtool_sset (struct phy_device *phydev,struct ethtool_cmd *cmd);int phy_ethtool_gset (struct phy_device *phydev,struct ethtool_cmd *cmd);int phy_mii_ioctl (struct phy_device *phydev, -struct mii_ioctl_data *mii_data,int cmd); +struct ifreq *ifr,int cmd);int phy_start_interrupts (struct phy_device *phydev);void phy_print_status (struct phy_device *phydev);struct phy_device *phy_device_create (struct mii_bus *bus,int addr,int phy_id);
net/dsa/slave.c +1 -2
@@ -164,10 +164,9 @@ out:static int dsa_slave_ioctl (struct net_device *dev,struct ifreq *ifr,int cmd) {struct dsa_slave_priv *p =netdev_priv (dev); -struct mii_ioctl_data *mii_data =if_mii (ifr);if (p->phy !=NULL ) -return phy_mii_ioctl (p->phy, mii_data, cmd); +return phy_mii_ioctl (p->phy, ifr, cmd);return -EOPNOTSUPP ; }
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v3 3/4 net: added a BPF to help drivers detect PTP packets.
In reply to Richard CochranCertain kinds of hardware time stamping units in both MACs and PHYs have the limitation that they can only time stamp PTP packets. Drivers for such hardware are left with the task of correctly matching skbs to time stamps. This patch adds a BPF that drivers can use to classify PTP packets when needed.
--- include/linux/ptp_classify.h | 126 ++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 126 insertions(+), 0 deletions(-) create mode 100644 include/linux/ptp_classify.h
include/linux/ptp_classify.h new file +126 -0
@@ -0,0 +1,126 @@ +/* +* PTP 1588 support +* +* This file implements a BPF that recognizes PTP event messages. +* +* Copyright (C) 2010 OMICRON electronics GmbH +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write to the Free Software +* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#ifndef _PTP_CLASSIFY_H_ +#define _PTP_CLASSIFY_H_ + +#include <linux/if_ether.h> +#include <linux/if_vlan.h> +#include <linux/filter.h> +#ifdef __KERNEL__ +#include <linux/in.h> +#else +#include <netinet/in.h> +#endif + +#define PTP_CLASS_NONE 0x00/* not a PTP event message */ +#define PTP_CLASS_V1 0x01/* protocol version 1 */ +#define PTP_CLASS_V2 0x02/* protocol version 2 */ +#define PTP_CLASS_VMASK 0x0f/* max protocol version is 15 */ +#define PTP_CLASS_IPV4 0x10/* event in an IPV4 UDP packet */ +#define PTP_CLASS_IPV6 0x20/* event in an IPV6 UDP packet */ +#define PTP_CLASS_L2 0x30/* event in a L2 packet */ +#define PTP_CLASS_VLAN 0x40/* event in a VLAN tagged L2 packet */ +#define PTP_CLASS_PMASK 0xf0/* mask for the packet type field */ + +#define PTP_CLASS_V1_IPV4 (PTP_CLASS_V1 | PTP_CLASS_IPV4) +#define PTP_CLASS_V1_IPV6 (PTP_CLASS_V1 | PTP_CLASS_IPV6)/*probably DNE*/ +#define PTP_CLASS_V2_IPV4 (PTP_CLASS_V2 | PTP_CLASS_IPV4) +#define PTP_CLASS_V2_IPV6 (PTP_CLASS_V2 | PTP_CLASS_IPV6) +#define PTP_CLASS_V2_L2 (PTP_CLASS_V2 | PTP_CLASS_L2) +#define PTP_CLASS_V2_VLAN (PTP_CLASS_V2 | PTP_CLASS_VLAN) + +#define PTP_EV_PORT 319 + +#define OFF_ETYPE 12 +#define OFF_IHL 14 +#define OFF_FRAG 20 +#define OFF_PROTO4 23 +#define OFF_NEXT 6 +#define OFF_UDP_DST 2 + +#define IP6_HLEN 40 +#define UDP_HLEN 8 + +#define RELOFF_DST4 (ETH_HLEN + OFF_UDP_DST) +#define OFF_DST6 (ETH_HLEN + IP6_HLEN + OFF_UDP_DST) +#define OFF_PTP6 (ETH_HLEN + IP6_HLEN + UDP_HLEN) + +#define OP_AND (BPF_ALU | BPF_AND | BPF_K) +#define OP_JEQ (BPF_JMP | BPF_JEQ | BPF_K) +#define OP_JSET (BPF_JMP | BPF_JSET | BPF_K) +#define OP_LDB (BPF_LD | BPF_B | BPF_ABS) +#define OP_LDH (BPF_LD | BPF_H | BPF_ABS) +#define OP_LDHI (BPF_LD | BPF_H | BPF_IND) +#define OP_LDX (BPF_LDX | BPF_B | BPF_MSH) +#define OP_OR (BPF_ALU | BPF_OR | BPF_K) +#define OP_RETA (BPF_RET | BPF_A) +#define OP_RETK (BPF_RET | BPF_K) + +static inline int ptp_filter_init (struct sock_filter *f,int len) +{ +if (OP_LDH == f[0 ].code) +return sk_chk_filter (f, len); +else +return 0 ; +} + +#define PTP_FILTER \ + {OP_LDH, 0, 0, OFF_ETYPE }, /* */ \ + {OP_JEQ, 0, 12, ETH_P_IP }, /* f goto L20 */ \ + {OP_LDB, 0, 0, OFF_PROTO4 }, /* */ \ + {OP_JEQ, 0, 9, IPPROTO_UDP }, /* f goto L10 */ \ + {OP_LDH, 0, 0, OFF_FRAG }, /* */ \ + {OP_JSET, 7, 0, 0x1fff }, /* t goto L11 */ \ + {OP_LDX, 0, 0, OFF_IHL }, /* */ \ + {OP_LDHI, 0, 0, RELOFF_DST4 }, /* */ \ + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L12 */ \ + {OP_LDHI, 0, 0, ETH_HLEN + UDP_HLEN }, /* */ \ + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \ + {OP_OR, 0, 0, PTP_CLASS_IPV4 }, /* */ \ + {OP_RETA, 0, 0, 0 }, /* */ \ +/*L1x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \ +/*L20*/ {OP_JEQ, 0, 9, ETH_P_IPV6 }, /* f goto L40 */ \ + {OP_LDB, 0, 0, ETH_HLEN + OFF_NEXT }, /* */ \ + {OP_JEQ, 0, 6, IPPROTO_UDP }, /* f goto L30 */ \ + {OP_LDH, 0, 0, OFF_DST6 }, /* */ \ + {OP_JEQ, 0, 4, PTP_EV_PORT }, /* f goto L31 */ \ + {OP_LDH, 0, 0, OFF_PTP6 }, /* */ \ + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \ + {OP_OR, 0, 0, PTP_CLASS_IPV6 }, /* */ \ + {OP_RETA, 0, 0, 0 }, /* */ \ +/*L3x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, /* */ \ +/*L40*/ {OP_JEQ, 0, 6, ETH_P_8021Q }, /* f goto L50 */ \ + {OP_LDH, 0, 0, OFF_ETYPE + 4 }, /* */ \ + {OP_JEQ, 0, 9, ETH_P_1588 }, /* f goto L60 */ \ + {OP_LDH, 0, 0, ETH_HLEN + VLAN_HLEN }, /* */ \ + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \ + {OP_OR, 0, 0, PTP_CLASS_VLAN }, /* */ \ + {OP_RETA, 0, 0, 0 }, /* */ \ +/*L50*/ {OP_JEQ, 0, 4, ETH_P_1588 }, /* f goto L61 */ \ + {OP_LDH, 0, 0, ETH_HLEN }, /* */ \ + {OP_AND, 0, 0, PTP_CLASS_VMASK }, /* */ \ + {OP_OR, 0, 0, PTP_CLASS_L2 }, /* */ \ + {OP_RETA, 0, 0, 0 }, /* */ \ +/*L6x*/ {OP_RETK, 0, 0, PTP_CLASS_NONE }, + +#endif
Signature · 1 line
1.7.0.4
Richard Cochran
maintainerPATCH v3 4/4 net: support time stamping in phy devices.
In reply to Richard CochranThis patch adds a new networking option to allow hardware time stamps from PHY devices. When enabled, likely candidates among incoming and outgoing network packets are offered to the PHY driver for possible time stamping. When accepted by the PHY driver, incoming packets are deferred for later delivery by the driver.
The patch also adds phylib driver methods for the SIOCSHWTSTAMP ioctl and callbacks for transmit and receive time stamping. Drivers may optionally implement these functions.
--- drivers/net/phy/phy.c | 5 ++ drivers/net/phy/phy_device.c | 2 + include/linux/netdevice.h | 4 + include/linux/phy.h | 22 +++++++ include/linux/skbuff.h | 31 ++++++++++ net/Kconfig | 10 +++ net/core/Makefile | 2 +- net/core/dev.c | 3 + net/core/timestamping.c | 126 ++++++++++++++++++++++++++++++++++++++++++ net/socket.c | 4 + 10 files changed, 208 insertions(+), 1 deletions(-) create mode 100644 net/core/timestamping.c
drivers/net/phy/phy.c +5 -0
@@ -361,6 +361,11 @@ int phy_mii_ioctl(struct phy_device *phydev, }break ; +case SIOCSHWTSTAMP : +if (phydev->drv->hwtstamp) +return phydev->drv->hwtstamp (phydev, ifr); +/* fall through */ +default :return -EOPNOTSUPP ; }
drivers/net/phy/phy_device.c +2 -0
@@ -460,6 +460,7 @@ int phy_attach_direct(struct net_device *dev, struct phy_device *phydev, } phydev->attached_dev = dev; + dev->phydev = phydev; phydev->dev_flags = flags;
@@ -513,6 +514,7 @@ EXPORT_SYMBOL(phy_attach);*/ void phy_detach (struct phy_device *phydev) { + phydev->attached_dev->phydev =NULL ; phydev->attached_dev =NULL ;/* If the device had no specific driver before (i.e. - it
include/linux/netdevice.h +4 -0
@@ -54,6 +54,7 @@struct vlan_group ;struct netpoll_info ; +struct phy_device ;/* 802.11 specific */ struct wireless_dev ;/* source back-compat hooks */
@@ -1077,6 +1078,9 @@ struct net_device {#endif /* n-tuple filter list attached to this device */ struct ethtool_rx_ntuple_list ethtool_ntuple_list; + +/* phy device may attach itself for hardware timestamping */ +struct phy_device *phydev; };#define to_net_dev (d) container_of(d, struct net_device, dev)
include/linux/phy.h +22 -0
@@ -234,6 +234,8 @@ enum phy_state { PHY_RESUMING }; +struct sk_buff ; +/* phy_device: An instance of a PHY * * drv: Pointer to the driver for this PHY instance
@@ -402,6 +404,26 @@ struct phy_driver {/* Clears up any memory if needed */ void (*remove)(struct phy_device *phydev); +/* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */ +int (*hwtstamp)(struct phy_device *phydev,struct ifreq *ifr); + +/* +* Requests a Rx timestamp for 'skb'. If the skb is accepted, +* the phy driver promises to deliver it using netif_rx() as +* soon as a timestamp becomes available. One of the +* PTP_CLASS_ values is passed in 'type'. The function must +* return true if the skb is accepted for delivery. +*/ +bool (*rxtstamp)(struct phy_device *dev,struct sk_buff *skb,int type); + +/* +* Requests a Tx timestamp for 'skb'. The phy driver promises +* to deliver it to the socket's error queue as soon as a +* timestamp becomes available. One of the PTP_CLASS_ values +* is passed in 'type'. +*/ +void (*txtstamp)(struct phy_device *dev,struct sk_buff *skb,int type); +struct device_driver driver; };#define to_phy_driver (d) container_of(d, struct phy_driver, driver)
include/linux/skbuff.h +31 -0
@@ -1933,6 +1933,36 @@ static inline ktime_t net_invalid_timestamp(void)return ktime_set (0 ,0 ); } +extern void skb_timestamping_init (void ); + +#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING + +extern void skb_clone_tx_timestamp (struct sk_buff *skb); +extern bool skb_defer_rx_timestamp (struct sk_buff *skb); + +#else /* CONFIG_NETWORK_PHY_TIMESTAMPING */ + +static inline void skb_clone_tx_timestamp (struct sk_buff *skb) +{ +} + +static inline bool skb_defer_rx_timestamp (struct sk_buff *skb) +{ +return false; +} + +#endif /* !CONFIG_NETWORK_PHY_TIMESTAMPING */ + +/** +* skb_complete_tx_timestamp() - deliver cloned skb with tx timestamps +* +* @skb: clone of the the original outgoing packet +* @hwtstamps: hardware time stamps +* +*/ +void skb_complete_tx_timestamp (struct sk_buff *skb, +struct skb_shared_hwtstamps *hwtstamps); +/** * skb_tstamp_tx - queue clone of skb with send time stamps * @orig_skb: the original outgoing packet
@@ -1965,6 +1995,7 @@ static inline void sw_tx_timestamp(struct sk_buff *skb)*/ static inline void skb_tx_timestamp (struct sk_buff *skb) { +skb_clone_tx_timestamp (skb);sw_tx_timestamp (skb); }
net/Kconfig +10 -0
@@ -86,6 +86,16 @@ config NETWORK_SECMARK to nfmark, but designated for security purposes. If you are unsure how to answer this question, answer N. +config NETWORK_PHY_TIMESTAMPING + bool "Timestamping in PHY devices" + depends on EXPERIMENTAL + help + This allows timestamping of network packets by PHYs with + hardware timestamping capabilities. This option adds some + overhead in the transmit and receive paths. + + If you are unsure how to answer this question, answer N. + menuconfig NETFILTER bool "Network packet filtering framework (Netfilter)" ---help---
net/core/Makefile +1 -1
@@ -18,4 +18,4 @@ obj-$(CONFIG_NET_DMA) += user_dma.o obj-$(CONFIG_FIB_RULES) += fib_rules.o obj-$(CONFIG_TRACEPOINTS) += net-traces.o obj-$(CONFIG_NET_DROP_MONITOR) += drop_monitor.o - +obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += timestamping.o
net/core/dev.c +3 -0
@@ -2939,6 +2939,9 @@ int netif_receive_skb(struct sk_buff *skb)if (netdev_tstamp_prequeue)net_timestamp_check (skb); +if (skb_defer_rx_timestamp (skb)) +return NET_RX_SUCCESS ; +#ifdef CONFIG_RPS {struct rps_dev_flow voidflow, *rflow = &voidflow;
net/core/timestamping.c new file +126 -0
126 lines not on this page · raw message
net/socket.c +4 -0
@@ -2403,6 +2403,10 @@ static int __init sock_init(void)netfilter_init ();#endif +#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING +skb_timestamping_init (); +#endif +return 0 ; }
Signature · 1 line
1.7.0.4
David Miller
maintainerFrom: Richard Cochran <[email protected]>
Date: Sat, 17 Jul 2010 20:48:02 +0200
Quoted 9 lines
This patch set extends the packet time stamping capabilites of the network stack in two ways.
1. The first patch presents a work-around for the TX software time stamping fallback problem cited in
cd4d8fdad1f1. The idea is to add one inline function into each MAC driver. This function will act as hooks for current (and possible future) time stamping needs, once they are placed correctly within each MAC driver.
Quoted 7 lines
2. The other patches prepare the way for PHY drivers to offer time stamping.
I am preparing a new round of patches for PTP support, but it will require the changes in this patch set in order to function. Thus I would like to have this patch set reviewed (and hopefully merged) in order to go forward.
Ok this looks good enough to me to toss into net-next-2.6
All applied, thanks!