From patchwork Sat Mar 17 12:12:28 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Cochran X-Patchwork-Id: 147322 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 98109B6FA1 for ; Sat, 17 Mar 2012 23:13:23 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1030873Ab2CQMNS (ORCPT ); Sat, 17 Mar 2012 08:13:18 -0400 Received: from mail-we0-f174.google.com ([74.125.82.174]:43430 "EHLO mail-we0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1030798Ab2CQMMs (ORCPT ); Sat, 17 Mar 2012 08:12:48 -0400 Received: by wejx9 with SMTP id x9so4653078wej.19 for ; Sat, 17 Mar 2012 05:12:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:x-mailer:in-reply-to:references :in-reply-to:references; bh=1GHU5HnaLgBZ1iZYg5MYfK17ZwTf/MQbBrQcm8jIuYE=; b=aJIQdwvZ0W4XJgAxqJhy3pXfLsf2a7DRCaBC/sJB3Yv3OIHsvq1MHFc6U3Fxz0bS2i /f3C8uq6pBVcTlTPesTq5BGKK6axlQ7+YpBUhuz+S6RMOtlKF717w20HREJcXmbscA7t AHX05twM97LXyHC1aSS9vdPpouy3LZcCpSq9wdffm3eZh5upQwlwPj0+w7zofLbpIQe7 9BTBS4tieILDYYPlNXPa43zPtLwk5bkOzTLvtqX2KEghkLeSxjeEtjyiEUw0l1LXEdRA u4YeoldDKGni/z6l63DMFtNRMQcqj4RmdwNopUgfT67iSF66W1AkeSTqSR7BDshvsRfo hl6w== Received: by 10.180.78.225 with SMTP id e1mr5998940wix.0.1331986366955; Sat, 17 Mar 2012 05:12:46 -0700 (PDT) Received: from localhost.localdomain (089144206229.atnat0015.highway.a1.net. [89.144.206.229]) by mx.google.com with ESMTPS id fz9sm7206096wib.3.2012.03.17.05.12.44 (version=TLSv1/SSLv3 cipher=OTHER); Sat, 17 Mar 2012 05:12:46 -0700 (PDT) From: Richard Cochran To: Cc: David Miller , Ben Hutchings Subject: [PATCH RFC 2/8] ethtool: Introduce a method for getting time stamping capabilities. Date: Sat, 17 Mar 2012 13:12:28 +0100 Message-Id: X-Mailer: git-send-email 1.7.2.5 In-Reply-To: References: In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This commit adds a new ethtool ioctl that exposes the SO_TIMESTAMPING capabilities of a network interface. In addition, user space programs can use this ioctl to discover the PTP Hardware Clock (PHC) device associated with the interface. Since software receive time stamps are handled by the stack, the generic ethtool code can answer the query correctly in case the MAC or PHY drivers lack special time stamping features. Signed-off-by: Richard Cochran --- include/linux/ethtool.h | 20 ++++++++++++++++++++ include/linux/phy.h | 3 +++ net/core/ethtool.c | 36 ++++++++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 0 deletions(-) diff --git a/include/linux/ethtool.h b/include/linux/ethtool.h index e1d9e0e..72ffda9 100644 --- a/include/linux/ethtool.h +++ b/include/linux/ethtool.h @@ -726,6 +726,24 @@ struct ethtool_sfeatures { struct ethtool_set_features_block features[0]; }; +/** + * struct ethtool_ts_info - holds a device's timestamping and PHC association + * @cmd: command number = %ETHTOOL_GET_TS_INFO + * @so_timestamping: bit mask of SO_TIMESTAMPING modes supported by the device + * @phc_index: device index of the associated PHC, or -1 if there is none + * @tx_types: bit mask of hwtstamp_tx_types modes supported by the device + * @rx_filters: bit mask of hwtstamp_rx_filters modes supported by the device + */ +struct ethtool_ts_info { + __u32 cmd; + __u32 so_timestamping; + __s32 phc_index; + __u32 tx_types; + __u32 tx_reserved[3]; + __u32 rx_filters; + __u32 rx_reserved[3]; +}; + /* * %ETHTOOL_SFEATURES changes features present in features[].valid to the * values of corresponding bits in features[].requested. Bits in .requested @@ -955,6 +973,7 @@ struct ethtool_ops { int (*get_dump_data)(struct net_device *, struct ethtool_dump *, void *); int (*set_dump)(struct net_device *, struct ethtool_dump *); + int (*get_ts_info)(struct net_device *, struct ethtool_ts_info *); }; #endif /* __KERNEL__ */ @@ -1029,6 +1048,7 @@ struct ethtool_ops { #define ETHTOOL_SET_DUMP 0x0000003e /* Set dump settings */ #define ETHTOOL_GET_DUMP_FLAG 0x0000003f /* Get dump settings */ #define ETHTOOL_GET_DUMP_DATA 0x00000040 /* Get dump data */ +#define ETHTOOL_GET_TS_INFO 0x00000041 /* Get time stamping and PHC info */ /* compatibility with older code */ #define SPARC_ETH_GSET ETHTOOL_GSET diff --git a/include/linux/phy.h b/include/linux/phy.h index c599f7ec..497b5c0 100644 --- a/include/linux/phy.h +++ b/include/linux/phy.h @@ -411,6 +411,9 @@ struct phy_driver { /* Clears up any memory if needed */ void (*remove)(struct phy_device *phydev); + /* Handles ethtool queries for hardware time stamping. */ + int (*ts_info)(struct phy_device *phydev, struct ethtool_ts_info *ti); + /* Handles SIOCSHWTSTAMP ioctl for hardware time stamping. */ int (*hwtstamp)(struct phy_device *phydev, struct ifreq *ifr); diff --git a/net/core/ethtool.c b/net/core/ethtool.c index 6d6d7d2..d6eff4b 100644 --- a/net/core/ethtool.c +++ b/net/core/ethtool.c @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include #include #include @@ -1278,6 +1280,37 @@ out: return ret; } +static int ethtool_get_ts_info(struct net_device *dev, void __user *useraddr) +{ + int err = 0; + struct ethtool_ts_info info; + const struct ethtool_ops *ops = dev->ethtool_ops; + struct phy_device *phydev = dev->phydev; + + memset(&info, 0, sizeof(info)); + info.cmd = ETHTOOL_GET_TS_INFO; + + if (phydev && phydev->drv && phydev->drv->ts_info) + err = phydev->drv->ts_info(phydev, &info); + + else if (dev->ethtool_ops->get_ts_info) + err = ops->get_ts_info(dev, &info); + else { + info.so_timestamping = + SOF_TIMESTAMPING_RX_SOFTWARE | + SOF_TIMESTAMPING_SOFTWARE; + info.phc_index = -1; + } + + if (err) + return err; + + if (copy_to_user(useraddr, &info, sizeof(info))) + err = -EFAULT; + + return err; +} + /* The main entry point in this file. Called from net/core/dev.c */ int dev_ethtool(struct net *net, struct ifreq *ifr) @@ -1496,6 +1529,9 @@ int dev_ethtool(struct net *net, struct ifreq *ifr) case ETHTOOL_GET_DUMP_DATA: rc = ethtool_get_dump_data(dev, useraddr); break; + case ETHTOOL_GET_TS_INFO: + rc = ethtool_get_ts_info(dev, useraddr); + break; default: rc = -EOPNOTSUPP; }