From: Patrick Ohly <patrick.ohly@intel.com>
To: netdev@vger.kernel.org
Cc: Octavian Purdila <opurdila@ixiacom.com>,
Stephen Hemminger <shemminger@vyatta.com>,
Ingo Oeser <netdev@axxeo.de>, Andi Kleen <ak@linux.intel.com>,
John Ronciak <john.ronciak@intel.com>,
Eric Dumazet <dada1@cosmosbay.com>,
Oliver Hartkopp <oliver@hartkopp.net>
Subject: [RFC PATCH 07/13] net: add SIOCSHWTSTAMP - hardware time stamping of packets
Date: Fri, 31 Oct 2008 12:43:36 +0100 [thread overview]
Message-ID: <1226415430.31699.6.camel@ecld0pohly> (raw)
In-Reply-To: <1226414697.17450.852.camel@ecld0pohly>
In its current form the new ioctl allows time stamping
PTP packets (all currently useful flavors) and all packets.
This should be good enough for the use cases discussed
on Linux netdev so far.
It does not yet allow user space control over the clock
in the NIC. If this should become necessary, then it will
have to be extended.
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
---
Documentation/networking/timestamping.txt | 23 ++++++++++++++++-
.../networking/timestamping/timestamping.c | 26 ++++++++++++++++++++
fs/compat_ioctl.c | 1 +
include/net/timestamping.h | 7 ++++-
net/core/dev.c | 2 +
5 files changed, 56 insertions(+), 3 deletions(-)
diff --git a/Documentation/networking/timestamping.txt b/Documentation/networking/timestamping.txt
index 6a87a96..537e55b 100644
--- a/Documentation/networking/timestamping.txt
+++ b/Documentation/networking/timestamping.txt
@@ -96,6 +96,24 @@ struct hwtstamp_config {
int rx_filter_type; /**< HWTSTAMP_RX_* */
};
+Desired behavior is passed into the kernel and to a specific device by
+calling ioctl(SIOCSHWTSTAMP) with a pointer to a struct ifreq whose
+ifr_data points to a struct hwtstamp_config. The tx_type and
+rx_filter_type are hints to the driver what it is expected to do. If
+the requested fine-grained filtering for incoming packets is not
+supported, the driver may time stamp more than just the requested types
+of packets.
+
+A driver which supports hardware time stamping shall update the struct
+with the actual, possibly more permissive configuration. If the
+requested packets cannot be time stamped, then nothing should be
+changed and ERANGE shall be returned (in contrast to EINVAL, which
+indicates that SIOCSHWTSTAMP is not supported at all).
+
+Only a processes with admin rights may change the configuration. User
+space is responsible to ensure that multiple processes don't interfere
+with each other and that the settings are reset.
+
/** possible values for hwtstamp_config->tx_type */
enum {
/**
@@ -111,7 +129,7 @@ enum {
* time stamped by setting SOF_TIMESTAMPING_TX_SOFTWARE
* before sending the packet
*/
- HWSTAMP_TX_ON,
+ HWTSTAMP_TX_ON,
};
/** possible values for hwtstamp_config->rx_filter_type */
@@ -122,6 +140,9 @@ enum {
/** time stamp any incoming packet */
HWTSTAMP_FILTER_ALL,
+ /** return value: time stamp all packets requested plus some others */
+ HWTSTAMP_FILTER_SOME,
+
/** PTP v1, UDP, any kind of event packet */
HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
diff --git a/Documentation/networking/timestamping/timestamping.c b/Documentation/networking/timestamping/timestamping.c
index abb2b79..bfb6cd6 100644
--- a/Documentation/networking/timestamping/timestamping.c
+++ b/Documentation/networking/timestamping/timestamping.c
@@ -270,6 +270,8 @@ int main(int argc, char **argv)
int enabled = 1;
int sock;
struct ifreq device;
+ struct ifreq hwtstamp;
+ struct hwtstamp_config hwconfig, hwconfig_requested;
struct sockaddr_in addr;
struct ip_mreq imr;
struct in_addr iaddr;
@@ -323,6 +325,30 @@ int main(int argc, char **argv)
bail("getting interface IP address");
}
+ memset(&hwtstamp, 0, sizeof(hwtstamp));
+ strncpy(hwtstamp.ifr_name, interface, sizeof(hwtstamp.ifr_name));
+ hwtstamp.ifr_data = (void *)&hwconfig;
+ memset(&hwconfig, 0, sizeof(&hwconfig));
+ hwconfig.tx_type =
+ (so_timestamping_flags & SOF_TIMESTAMPING_TX_HARDWARE) ?
+ HWTSTAMP_TX_ON : HWTSTAMP_TX_OFF;
+ hwconfig.rx_filter_type =
+ (so_timestamping_flags & SOF_TIMESTAMPING_RX_HARDWARE) ?
+ HWTSTAMP_FILTER_PTP_V1_L4_SYNC : HWTSTAMP_FILTER_NONE;
+ hwconfig_requested = hwconfig;
+ if (ioctl(sock, SIOCSHWTSTAMP, &hwtstamp) < 0) {
+ if (errno == EINVAL &&
+ hwconfig_requested.tx_type == HWTSTAMP_TX_OFF &&
+ hwconfig_requested.rx_filter_type == HWTSTAMP_FILTER_NONE) {
+ printf("SIOCSHWTSTAMP: disabling hardware time stamping not possible\n");
+ } else {
+ bail("SIOCSHWTSTAMP");
+ }
+ }
+ printf("SIOCSHWTSTAMP: tx_type %d requested, got %d; rx_filter_type %d requested, got %d\n",
+ hwconfig_requested.tx_type, hwconfig.tx_type,
+ hwconfig_requested.rx_filter_type, hwconfig.rx_filter_type);
+
/* bind to PTP port */
addr.sin_family = AF_INET;
addr.sin_addr.s_addr = htonl(INADDR_ANY);
diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
index 5235c67..a5001a6 100644
--- a/fs/compat_ioctl.c
+++ b/fs/compat_ioctl.c
@@ -2555,6 +2555,7 @@ HANDLE_IOCTL(SIOCSIFMAP, dev_ifsioc)
HANDLE_IOCTL(SIOCGIFADDR, dev_ifsioc)
HANDLE_IOCTL(SIOCSIFADDR, dev_ifsioc)
HANDLE_IOCTL(SIOCSIFHWBROADCAST, dev_ifsioc)
+HANDLE_IOCTL(SIOCSHWTSTAMP, dev_ifsioc)
/* ioctls used by appletalk ddp.c */
HANDLE_IOCTL(SIOCATALKDIFADDR, dev_ifsioc)
diff --git a/include/net/timestamping.h b/include/net/timestamping.h
index 53cb603..c271caa 100644
--- a/include/net/timestamping.h
+++ b/include/net/timestamping.h
@@ -28,7 +28,7 @@ enum {
# define SIOCSHWTSTAMP 0x89b0
#endif
-/** %SIOCSHWTSTAMP expects a pointer to this struct */
+/** %SIOCSHWTSTAMP expects a struct ifreq with a ifr_data pointer to this struct */
struct hwtstamp_config {
int flags; /**< no flags defined right now, must be zero */
int tx_type; /**< one of HWTSTAMP_TX_* */
@@ -50,7 +50,7 @@ enum {
* time stamped by setting SOF_TIMESTAMPING_TX_SOFTWARE
* before sending the packet
*/
- HWSTAMP_TX_ON,
+ HWTSTAMP_TX_ON,
};
/** possible values for hwtstamp_config->rx_filter_type */
@@ -61,6 +61,9 @@ enum {
/** time stamp any incoming packet */
HWTSTAMP_FILTER_ALL,
+ /** return value: time stamp all packets requested plus some others */
+ HWTSTAMP_FILTER_SOME,
+
/** PTP v1, UDP, any kind of event packet */
HWTSTAMP_FILTER_PTP_V1_L4_EVENT,
/** PTP v1, UDP, Sync packet */
diff --git a/net/core/dev.c b/net/core/dev.c
index 7cf31fb..69d7c04 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -3621,6 +3621,7 @@ static int dev_ifsioc(struct net *net, struct ifreq *ifr, unsigned int cmd)
cmd == SIOCSMIIREG ||
cmd == SIOCBRADDIF ||
cmd == SIOCBRDELIF ||
+ cmd == SIOCSHWTSTAMP ||
cmd == SIOCWANDEV) {
err = -EOPNOTSUPP;
if (dev->do_ioctl) {
@@ -3776,6 +3777,7 @@ int dev_ioctl(struct net *net, unsigned int cmd, void __user *arg)
case SIOCBONDCHANGEACTIVE:
case SIOCBRADDIF:
case SIOCBRDELIF:
+ case SIOCSHWTSTAMP:
if (!capable(CAP_NET_ADMIN))
return -EPERM;
/* fall through */
--
1.6.0.4
next prev parent reply other threads:[~2008-11-11 14:57 UTC|newest]
Thread overview: 48+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-11 14:44 [RFC PATCH 00/13] hardware time stamping + igb example implementation Patrick Ohly
2008-10-22 8:17 ` [RFC PATCH 02/13] extended semantic of sk_buff::tstamp: lowest bit marks hardware time stamps Patrick Ohly
2008-11-12 7:41 ` Eric Dumazet
2008-11-12 8:09 ` Patrick Ohly
2008-11-12 10:09 ` David Miller
2008-11-12 9:58 ` David Miller
2008-11-19 12:50 ` Patrick Ohly
2008-10-22 12:46 ` [RFC PATCH 01/13] put_cmsg_compat + SO_TIMESTAMP[NS]: use same name for value as caller Patrick Ohly
2008-11-12 9:55 ` David Miller
2008-10-22 15:01 ` [RFC PATCH 03/13] user space API for time stamping of incoming and outgoing packets Patrick Ohly
2008-11-12 10:02 ` David Miller
2008-10-24 13:41 ` [RFC PATCH 04/13] net: implement generic SOF_TIMESTAMPING_TX_* support Patrick Ohly
2008-11-11 23:15 ` Octavian Purdila
2008-11-12 8:38 ` Patrick Ohly
2008-10-24 13:49 ` [RFC PATCH 05/13] ip: support for TX timestamps on UDP and RAW sockets Patrick Ohly
2008-11-12 9:59 ` David Miller
2008-10-29 14:48 ` [RFC PATCH 06/13] workaround: detect time stamp when command flags are expected Patrick Ohly
2008-11-12 10:00 ` David Miller
2008-10-31 11:43 ` Patrick Ohly [this message]
2008-10-31 12:21 ` [RFC PATCH 08/13] igb: stub support for SIOCSHWTSTAMP Patrick Ohly
2008-11-04 9:23 ` [RFC PATCH 09/13] clocksource: allow usage independent of timekeeping.c Patrick Ohly
2008-11-12 10:04 ` David Miller
2008-11-04 9:27 ` [RFC PATCH 10/13] igb: infrastructure for hardware time stamping Patrick Ohly
2008-11-05 9:58 ` [RFC PATCH 11/13] time sync: generic infrastructure to map between time stamps generated by a clock source and system time Patrick Ohly
2008-11-11 16:18 ` Andi Kleen
2008-11-12 8:01 ` Patrick Ohly
2008-11-12 10:08 ` David Miller
2008-11-12 16:14 ` Patrick Ohly
2008-11-12 16:28 ` Eric Dumazet
2008-11-12 10:05 ` David Miller
2008-11-06 11:13 ` [RFC PATCH 12/13] igb: use clocksync to implement hardware time stamping Patrick Ohly
2008-11-07 9:26 ` [RFC PATCH 13/13] skbuff: optionally store hardware time stamps in new field Patrick Ohly
2008-11-12 16:06 ` [RFC PATCH 00/13] hardware time stamping + igb example implementation Andi Kleen
2008-11-12 16:25 ` Patrick Ohly
2008-11-12 18:44 ` Oliver Hartkopp
2008-11-12 19:22 ` Eric Dumazet
2008-11-12 20:23 ` Andi Kleen
2008-11-12 20:23 ` Andi Kleen
2008-11-12 20:56 ` Eric Dumazet
2008-11-12 21:34 ` Andi Kleen
2008-11-12 22:26 ` Oliver Hartkopp
2008-11-13 15:53 ` Ohly, Patrick
2008-11-13 6:15 ` Oliver Hartkopp
2008-11-13 6:29 ` Eric Dumazet
2008-11-13 16:05 ` Ohly, Patrick
2008-11-16 8:15 ` Andrew Shewmaker
2008-11-12 22:17 ` David Miller
2008-11-19 12:39 ` Patrick Ohly
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1226415430.31699.6.camel@ecld0pohly \
--to=patrick.ohly@intel.com \
--cc=ak@linux.intel.com \
--cc=dada1@cosmosbay.com \
--cc=john.ronciak@intel.com \
--cc=netdev@axxeo.de \
--cc=netdev@vger.kernel.org \
--cc=oliver@hartkopp.net \
--cc=opurdila@ixiacom.com \
--cc=shemminger@vyatta.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox