From patchwork Mon Jul 5 05:32:52 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 57863 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 750C4B6F10 for ; Mon, 5 Jul 2010 15:33:01 +1000 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751580Ab0GEFc5 (ORCPT ); Mon, 5 Jul 2010 01:32:57 -0400 Received: from mail-bw0-f46.google.com ([209.85.214.46]:52146 "EHLO mail-bw0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751323Ab0GEFc4 (ORCPT ); Mon, 5 Jul 2010 01:32:56 -0400 Received: by bwz1 with SMTP id 1so2488615bwz.19 for ; Sun, 04 Jul 2010 22:32:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:date:from:to:subject :message-id:references:mime-version:content-type:content-disposition :in-reply-to:user-agent; bh=5+1G6t4nbb6hLeJLsX7XCN/TeI7bUjQm4EG8UM4GAFc=; b=E9d2eeTXTUx+txJxh0JkgOftB3MbCuVEnsdJtDcTQW8MGStjCal6EVihDyNCP/snWH uSrV64GJEI09PhTP7SW5O6U/H1ThVJKsNrEx5Sv36+EgzIkB4WApBYuQC7sGebBo4Ji6 2ASjPhg0Gim+pWO9ImgWxRZHBoENu+4KRJvpY= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; b=QvlleIjsfBsHv32A1IknjPlxnmuMMlUWzsf3eDQzigNah5GdffM83/3tWihI5Xh1vS pO85TE6zxN/549cP0i44mKX8sCn4e/tGwRygbPFJdDEXRr1boQUmGukYoL/CRDOUOLvn DL0J4m2InF0C9LVdt3y5EZyvAOVAOdfvRc3cE= Received: by 10.204.55.65 with SMTP id t1mr1978200bkg.128.1278307974962; Sun, 04 Jul 2010 22:32:54 -0700 (PDT) Received: from riccoc20.at.omicron.at (vs162244.vserver.de [62.75.162.244]) by mx.google.com with ESMTPS id v6sm16059625bkx.23.2010.07.04.22.32.54 (version=TLSv1/SSLv3 cipher=RC4-MD5); Sun, 04 Jul 2010 22:32:54 -0700 (PDT) Date: Mon, 5 Jul 2010 07:32:52 +0200 From: Richard Cochran To: netdev@vger.kernel.org Subject: [PATCH 2/4] phylib: add a way to make PHY time stamps possible. Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.20 (2009-06-14) Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This patch adds a new networking option to allow hardware time stamps from PHY devices. Using PHY time stamps will still require adding two inline function calls to each MAC driver. The CONFIG option makes these calls safe to add, since the calls become NOOPs when the option is disabled. 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. Signed-off-by: Richard Cochran --- include/linux/phy.h | 7 +++++++ include/linux/skbuff.h | 29 +++++++++++++++++++++++++++++ net/Kconfig | 11 +++++++++++ 3 files changed, 47 insertions(+), 0 deletions(-) diff --git a/include/linux/phy.h b/include/linux/phy.h index 987e111..3566bde 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -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,11 @@ 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); + int (*rxtstamp)(struct phy_device *phydev, struct sk_buff *skb); + int (*txtstamp)(struct phy_device *phydev, struct sk_buff *skb); + struct device_driver driver; }; #define to_phy_driver(d) container_of(d, struct phy_driver, driver) diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 75323fe..8905508 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -1955,6 +1955,33 @@ static inline void sw_tx_timestamp(struct sk_buff *skb) skb_tstamp_tx(skb, NULL); } +#ifdef CONFIG_NETWORK_PHY_TIMESTAMPING + +static inline void phy_tx_timestamp(struct phy_device *phy, struct sk_buff *skb) +{ + union skb_shared_tx *shtx = skb_tx(skb); + if (shtx->hardware && phy && phy->drv->txtstamp) + phy->drv->txtstamp(phy, skb); +} + +static inline void phy_rx_timestamp(struct phy_device *phy, struct sk_buff *skb) +{ + if (phy && phy->drv->rxtstamp) + phy->drv->rxtstamp(phy, skb); +} + +#else /* CONFIG_NETWORK_PHY_TIMESTAMPING */ + +static inline void phy_tx_timestamp(struct phy_device *phy, struct sk_buff *skb) +{ +} + +static inline void phy_rx_timestamp(struct phy_device *phy, struct sk_buff *skb) +{ +} + +#endif /* !CONFIG_NETWORK_PHY_TIMESTAMPING */ + /** * skb_tx_timestamp() - Driver hook for transmit timestamping * @@ -1967,6 +1994,7 @@ static inline void sw_tx_timestamp(struct sk_buff *skb) */ static inline void skb_tx_timestamp(struct phy_device *phy, struct sk_buff *skb) { + phy_tx_timestamp(phy, skb); sw_tx_timestamp(skb); } @@ -1981,6 +2009,7 @@ static inline void skb_tx_timestamp(struct phy_device *phy, struct sk_buff *skb) */ static inline void skb_rx_timestamp(struct phy_device *phy, struct sk_buff *skb) { + phy_rx_timestamp(phy, skb); } extern __sum16 __skb_checksum_complete_head(struct sk_buff *skb, int len); diff --git a/net/Kconfig b/net/Kconfig index 0d68b40..3fa7ae3 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -86,6 +86,17 @@ 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. Note that this + option also requires support in the MAC driver. + + If you are unsure how to answer this question, answer N. + menuconfig NETFILTER bool "Network packet filtering framework (Netfilter)" ---help---