[PATCH 00/10] net: expand time stamping, batch #1

STALE5528d

Revision v1 of 3 in this series.

16 messages, 3 authors, 2011-06-12 · open the first message on its own page

[PATCH 00/10] net: expand time stamping, batch #1

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:14

This patch series represents the start of an effort to get better
coverage of the SO_TIMESTAMPING socket API in the Ethernet drivers.
Adding time stamping support to a given driver solves two separate
issues, namely software transmit time stamping and hardware time
stamping in PHY devices.

The SO_TIMESTAMPING socket API has been around since 2.6.30, but it
turned out that getting software transmit time stamps could not be
done in one central place in the stack. Instead, a work around was
introduced whereby each MAC driver must call a skb_tx_timestamp() hook
in order to support SW Tx time stamps.

Full PTP Hardware Clock (PHC) support has been merged for Linux 3.0,
including a driver for a PHY that does HW stamping. In the receive
path, the PHY based time stamping is handled by the stack for NAPI
based MAC drivers. But for transmit time stamps, support is needed in
the Ethernet MAC driver by calling the skb_tx_timestamp() hook.

For non-NAPI drivers, PHY based receive time stamping is currently not
possible. This patch series adds yet another hook (a wrapper around
netif_rx) for such drivers.

The first two patches make minor changes in the stack in support of
MAC/PHY time stamping. The next three patches enable PHY time stamping
for two MACs which have been paired with a PHC PHY on real life
boards.

The remaining patches are for MACs that I chose because they (1) use
phylib and (2) compile for x86. However, I only compiled these, not
tested, since I do not have the hardware.

The larger goal is to eventually get the skb_tx_timestamp hook into
each and every Ethernet MAC driver, so that SO_TIMESTAMPING using SW
time stamps will be supported across the board. I have started by
picking those drivers in which adding the hook will bring the greatest
benefit, namely those using phylib, since adding hooks provides both
SW and PHY HW time stamping.

If people approve of this effort, I will follow with another patch
series adding SW Tx time stamping to yet more MACs. Adding SW Tx
support is just a single line, but still, perhaps compile testing only
is too risky. I would appreciate feedback on this issue.


Richard Cochran (10):
  net: introduce time stamping wrapper for netif_rx.
  fec: enable transmit and receive time stamping.
  davinci_emac: pass ioctls through to phy device.
  davinci_emac: enable transmit time stamping.
  tg3: enable transmit time stamping.
  dnet: enable transmit time stamping.
  ethoc: enable transmit time stamping.
  r6040: enable transmit time stamping.
  stmmac: enable transmit time stamping.
  smsc9420: enable transmit time stamping.

 drivers/net/davinci_emac.c       |    5 +++--
 drivers/net/dnet.c               |    2 ++
 drivers/net/ethoc.c              |    1 +
 drivers/net/fec.c                |    4 +++-
 drivers/net/r6040.c              |    2 ++
 drivers/net/smsc9420.c           |    2 ++
 drivers/net/stmmac/stmmac_main.c |    2 ++
 drivers/net/tg3.c                |    2 ++
 include/linux/netdevice.h        |   21 +++++++++++++++++++++
 9 files changed, 38 insertions(+), 3 deletions(-)

[PATCH 01/10] net: introduce time stamping wrapper for netif_rx.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:17

This commit adds a variation on netif_rx() designed to allow non-NAPI
Ethernet MAC drivers to support hardware time stamping in PHY devices.
Adapting a given driver requires two small changes, namely replacing
netif_rx() with netif_rx_defer() and adding a call to skb_tx_timestamp()
in the transmission path.

Signed-off-by: Richard Cochran <redacted>
---
 include/linux/netdevice.h |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ca333e7..9a56505 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2066,6 +2066,27 @@ extern void dev_kfree_skb_any(struct sk_buff *skb);
 #define HAVE_NETIF_RX 1
 extern int		netif_rx(struct sk_buff *skb);
 extern int		netif_rx_ni(struct sk_buff *skb);
+
+/**
+ * netif_rx_defer() - post buffer to the network code
+ * @skb: buffer to post
+ *
+ * This function receives a packet from a device driver and queues it
+ * for the upper (protocol) levels to process.  All non-NAPI Ethernet
+ * MAC drivers should use this instead of netif_rx() since this method
+ * allows hardware timestamping to occur within the PHY.
+ *
+ * return values:
+ * NET_RX_SUCCESS  (no congestion)
+ * NET_RX_DROP     (packet was dropped)
+ */
+static inline int netif_rx_defer(struct sk_buff *skb)
+{
+	if (skb_defer_rx_timestamp(skb))
+		return NET_RX_SUCCESS;
+	return netif_rx(skb);
+}
+
 #define HAVE_NETIF_RECEIVE_SKB 1
 extern int		netif_receive_skb(struct sk_buff *skb);
 extern gro_result_t	dev_gro_receive(struct napi_struct *napi,
-- 
1.7.0.4

Re: [PATCH 01/10] net: introduce time stamping wrapper for netif_rx.

From: Stephen Hemminger <hidden>
Date: 2011-06-10 15:20:59

On Fri, 10 Jun 2011 17:06:59 +0200
Richard Cochran [off-list ref] wrote:
quoted hunk
This commit adds a variation on netif_rx() designed to allow non-NAPI
Ethernet MAC drivers to support hardware time stamping in PHY devices.
Adapting a given driver requires two small changes, namely replacing
netif_rx() with netif_rx_defer() and adding a call to skb_tx_timestamp()
in the transmission path.

Signed-off-by: Richard Cochran <redacted>
---
 include/linux/netdevice.h |   21 +++++++++++++++++++++
 1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
index ca333e7..9a56505 100644
--- a/include/linux/netdevice.h
+++ b/include/linux/netdevice.h
@@ -2066,6 +2066,27 @@ extern void dev_kfree_skb_any(struct sk_buff *skb);
 #define HAVE_NETIF_RX 1
 extern int		netif_rx(struct sk_buff *skb);
 extern int		netif_rx_ni(struct sk_buff *skb);
+
+/**
+ * netif_rx_defer() - post buffer to the network code
+ * @skb: buffer to post
+ *
+ * This function receives a packet from a device driver and queues it
+ * for the upper (protocol) levels to process.  All non-NAPI Ethernet
+ * MAC drivers should use this instead of netif_rx() since this method
+ * allows hardware timestamping to occur within the PHY.
+ *
+ * return values:
+ * NET_RX_SUCCESS  (no congestion)
+ * NET_RX_DROP     (packet was dropped)
+ */
+static inline int netif_rx_defer(struct sk_buff *skb)
+{
+	if (skb_defer_rx_timestamp(skb))
+		return NET_RX_SUCCESS;
+	return netif_rx(skb);
+}
Obvious question why not just put this in netif_rx.

Re: [PATCH 01/10] net: introduce time stamping wrapper for netif_rx.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 17:27:53

On Fri, Jun 10, 2011 at 08:20:56AM -0700, Stephen Hemminger wrote:
On Fri, 10 Jun 2011 17:06:59 +0200
Richard Cochran [off-list ref] wrote:
quoted
+static inline int netif_rx_defer(struct sk_buff *skb)
+{
+	if (skb_defer_rx_timestamp(skb))
+		return NET_RX_SUCCESS;
+	return netif_rx(skb);
+}
Obvious question why not just put this in netif_rx.
Well, if a packet gets defered, then that means that the PHY driver
has decided to hold the packet until it obtains the time stamp from
the PHY hardware. Then, the driver delivers the packet using netif_rx.

So, we need to have two methods to deliver a frame, one with and one
without the hook, otherwise you get packets going round in circles.

Take a look at the one PHY driver using this (so far), on line 1017 of
drivers/net/phy/dp83640.c, to see how it works.

Thanks,
Richard

PS I did consider at renaming netif_rx to __netif_rx and then
implementing netif_rx as shown above, but I found many, many callers
of netif_rx which are not drivers, so I worry that bad side effects
would appear from such a change.

Re: [PATCH 01/10] net: introduce time stamping wrapper for netif_rx.

From: Stephen Hemminger <hidden>
Date: 2011-06-10 18:19:27

On Fri, 10 Jun 2011 19:27:47 +0200
Richard Cochran [off-list ref] wrote:
On Fri, Jun 10, 2011 at 08:20:56AM -0700, Stephen Hemminger wrote:
quoted
On Fri, 10 Jun 2011 17:06:59 +0200
Richard Cochran [off-list ref] wrote:
quoted
+static inline int netif_rx_defer(struct sk_buff *skb)
+{
+	if (skb_defer_rx_timestamp(skb))
+		return NET_RX_SUCCESS;
+	return netif_rx(skb);
+}
Obvious question why not just put this in netif_rx.
Well, if a packet gets defered, then that means that the PHY driver
has decided to hold the packet until it obtains the time stamp from
the PHY hardware. Then, the driver delivers the packet using netif_rx.

So, we need to have two methods to deliver a frame, one with and one
without the hook, otherwise you get packets going round in circles.

Take a look at the one PHY driver using this (so far), on line 1017 of
drivers/net/phy/dp83640.c, to see how it works.

Thanks,
Richard

PS I did consider at renaming netif_rx to __netif_rx and then
implementing netif_rx as shown above, but I found many, many callers
of netif_rx which are not drivers, so I worry that bad side effects
would appear from such a change.
Why not use a timestamp present flag like the receive hashing code
already does.

Re: [PATCH 01/10] net: introduce time stamping wrapper for netif_rx.

From: David Miller <davem@davemloft.net>
Date: 2011-06-11 23:10:28

From: Stephen Hemminger <redacted>
Date: Fri, 10 Jun 2011 11:19:24 -0700
On Fri, 10 Jun 2011 19:27:47 +0200
Richard Cochran [off-list ref] wrote:
quoted
On Fri, Jun 10, 2011 at 08:20:56AM -0700, Stephen Hemminger wrote:
quoted
On Fri, 10 Jun 2011 17:06:59 +0200
Richard Cochran [off-list ref] wrote:
quoted
+static inline int netif_rx_defer(struct sk_buff *skb)
+{
+	if (skb_defer_rx_timestamp(skb))
+		return NET_RX_SUCCESS;
+	return netif_rx(skb);
+}
Obvious question why not just put this in netif_rx.
Well, if a packet gets defered, then that means that the PHY driver
has decided to hold the packet until it obtains the time stamp from
the PHY hardware. Then, the driver delivers the packet using netif_rx.

So, we need to have two methods to deliver a frame, one with and one
without the hook, otherwise you get packets going round in circles.

Take a look at the one PHY driver using this (so far), on line 1017 of
drivers/net/phy/dp83640.c, to see how it works.

Thanks,
Richard

PS I did consider at renaming netif_rx to __netif_rx and then
implementing netif_rx as shown above, but I found many, many callers
of netif_rx which are not drivers, so I worry that bad side effects
would appear from such a change.
Why not use a timestamp present flag like the receive hashing code
already does.
I agree with Stephen that we should be decreasing the number of driver
interfaces not increasing them.

Also, it makes no sense to add this for obsolete RX processing such
that netif_rx() is.

If drivers want to add fancy features like this timestamping stuff,
they better move on to NAPI, GRO, etc. first.  Putting support for
new features into deprecating things like netif_rx() makes no
sense at all.

Re: [PATCH 01/10] net: introduce time stamping wrapper for netif_rx.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-12 12:04:11

On Sat, Jun 11, 2011 at 04:10:25PM -0700, David Miller wrote:
Also, it makes no sense to add this for obsolete RX processing such
that netif_rx() is.

If drivers want to add fancy features like this timestamping stuff,
they better move on to NAPI, GRO, etc. first.  Putting support for
new features into deprecating things like netif_rx() makes no
sense at all.
Okay, I see your point. I won't bother trying to improve the "academy
of ancient drivers," and I'll repost without the netif_rx wrapper.

However, I do want to support the coldfire fec driver, since Freescale
is selling two coldfire development boards with the dp83640 phy. But I
don't think it makes sense to try and upgrade the fec driver to napi,
when a simple "if !skb_defer_rx_timestamp" will do there.

Thanks,
Richard

[PATCH 02/10] fec: enable transmit and receive time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:21

This patch has been tested on the Freescale M5234BCC, which includes the
National Semiconductor DP83640 with IEEE 1588 support.

Cc: Greg Ungerer <redacted>
Cc: "Uwe Kleine-König" <redacted>
Cc: Shawn Guo <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/fec.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/drivers/net/fec.c b/drivers/net/fec.c
index 885d8ba..68d479b 100644
--- a/drivers/net/fec.c
+++ b/drivers/net/fec.c
@@ -326,6 +326,8 @@ fec_enet_start_xmit(struct sk_buff *skb, struct net_device *ndev)
 
 	spin_unlock_irqrestore(&fep->hw_lock, flags);
 
+	skb_tx_timestamp(skb);
+
 	return NETDEV_TX_OK;
 }
 
@@ -650,7 +652,7 @@ fec_enet_rx(struct net_device *ndev)
 			skb_put(skb, pkt_len - 4);	/* Make room */
 			skb_copy_to_linear_data(skb, data, pkt_len - 4);
 			skb->protocol = eth_type_trans(skb, ndev);
-			netif_rx(skb);
+			netif_rx_defer(skb);
 		}
 
 		bdp->cbd_bufaddr = dma_map_single(&fep->pdev->dev, data,
-- 
1.7.0.4

[PATCH 03/10] davinci_emac: pass ioctls through to phy device.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:24

The DaVinci EMAC driver does not implement any ioctls, but still it can
pass them through to the phy device. This makes it possible for a phy
to offer PHC capabilities.

Cc: Anant Gole <redacted>
Cc: Kevin Hilman <redacted>
Cc: Chaithrika U S <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/davinci_emac.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index 29a4f06..efa2901 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -1489,14 +1489,14 @@ static void emac_adjust_link(struct net_device *ndev)
  */
 static int emac_devioctl(struct net_device *ndev, struct ifreq *ifrq, int cmd)
 {
-	dev_warn(&ndev->dev, "DaVinci EMAC: ioctl not supported\n");
+	struct emac_priv *priv = netdev_priv(ndev);
 
 	if (!(netif_running(ndev)))
 		return -EINVAL;
 
 	/* TODO: Add phy read and write and private statistics get feature */
 
-	return -EOPNOTSUPP;
+	return phy_mii_ioctl(priv->phydev, ifrq, cmd);
 }
 
 static int match_first_device(struct device *dev, void *data)
-- 
1.7.0.4

[PATCH 04/10] davinci_emac: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:28

This patch enables software (and phy device) transmit time stamping
for the DaVinci EMAC driver. Tested together with the dp83640 PHY.

Cc: Anant Gole <redacted>
Cc: Kevin Hilman <redacted>
Cc: Chaithrika U S <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/davinci_emac.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/net/davinci_emac.c b/drivers/net/davinci_emac.c
index efa2901..52ea30e 100644
--- a/drivers/net/davinci_emac.c
+++ b/drivers/net/davinci_emac.c
@@ -1090,6 +1090,7 @@ static int emac_dev_xmit(struct sk_buff *skb, struct net_device *ndev)
 			dev_err(emac_dev, "DaVinci EMAC: desc submit failed");
 		goto fail_tx;
 	}
+	skb_tx_timestamp(skb);
 
 	return NETDEV_TX_OK;
 
-- 
1.7.0.4

[PATCH 05/10] tg3: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:31

This patch enables software (and phy device) transmit time stamping
for the TIGON3 driver. Compile tested only.

Cc: Matt Carlson <redacted>
Cc: Michael Chan <mchan@broadcom.com>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/tg3.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/drivers/net/tg3.c b/drivers/net/tg3.c
index f4b01c6..e6b4f14 100644
--- a/drivers/net/tg3.c
+++ b/drivers/net/tg3.c
@@ -6091,6 +6091,8 @@ static netdev_tx_t tg3_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	/* Packets are ready, update Tx producer idx local and on card. */
 	tw32_tx_mbox(tnapi->prodmbox, entry);
 
+	skb_tx_timestamp(skb);
+
 	tnapi->tx_prod = entry;
 	if (unlikely(tg3_tx_avail(tnapi) <= (MAX_SKB_FRAGS + 1))) {
 		netif_tx_stop_queue(txq);
-- 
1.7.0.4

[PATCH 06/10] dnet: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:36

This patch enables software (and phy device) transmit time stamping
in the "Dave ethernet interface." Compile tested only.

Cc: Ilya Yanok <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/dnet.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/drivers/net/dnet.c b/drivers/net/dnet.c
index 8318ea0..c36763c 100644
--- a/drivers/net/dnet.c
+++ b/drivers/net/dnet.c
@@ -587,6 +587,8 @@ static netdev_tx_t dnet_start_xmit(struct sk_buff *skb, struct net_device *dev)
 		dnet_writel(bp, irq_enable, INTR_ENB);
 	}
 
+	skb_tx_timestamp(skb);
+
 	/* free the buffer */
 	dev_kfree_skb(skb);
 
-- 
1.7.0.4

[PATCH 07/10] ethoc: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:39

This patch enables software (and phy device) transmit time stamping
for the OpenCores 10/100 MAC driver. Compile tested only.

Cc: Thierry Reding <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/ethoc.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
index a83dd31..8645ec8 100644
--- a/drivers/net/ethoc.c
+++ b/drivers/net/ethoc.c
@@ -874,6 +874,7 @@ static netdev_tx_t ethoc_start_xmit(struct sk_buff *skb, struct net_device *dev)
 	}
 
 	spin_unlock_irq(&priv->lock);
+	skb_tx_timestamp(skb);
 out:
 	dev_kfree_skb(skb);
 	return NETDEV_TX_OK;
-- 
1.7.0.4

[PATCH 08/10] r6040: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:42

This patch enables software (and phy device) transmit time stamping
for the RDC R6040 Fast Ethernet MAC. Compile tested only.

Cc: Florian Fainelli <florian@openwrt.org>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/r6040.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/drivers/net/r6040.c b/drivers/net/r6040.c
index 200a363..5ee5f8f 100644
--- a/drivers/net/r6040.c
+++ b/drivers/net/r6040.c
@@ -846,6 +846,8 @@ static netdev_tx_t r6040_start_xmit(struct sk_buff *skb,
 
 	spin_unlock_irqrestore(&lp->lock, flags);
 
+	skb_tx_timestamp(skb);
+
 	return NETDEV_TX_OK;
 }
 
-- 
1.7.0.4

[PATCH 09/10] stmmac: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:49

This patch enables software (and phy device) transmit time stamping
for the STMicroelectronics Ethernet driver. Compile tested only.

Cc: Giuseppe Cavallaro <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/stmmac/stmmac_main.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/drivers/net/stmmac/stmmac_main.c b/drivers/net/stmmac/stmmac_main.c
index e25e44a..5b85f4c 100644
--- a/drivers/net/stmmac/stmmac_main.c
+++ b/drivers/net/stmmac/stmmac_main.c
@@ -1081,6 +1081,8 @@ static netdev_tx_t stmmac_xmit(struct sk_buff *skb, struct net_device *dev)
 
 	priv->hw->dma->enable_dma_transmission(priv->ioaddr);
 
+	skb_tx_timestamp(skb);
+
 	return NETDEV_TX_OK;
 }
 
-- 
1.7.0.4

[PATCH 10/10] smsc9420: enable transmit time stamping.

From: Richard Cochran <richardcochran@gmail.com>
Date: 2011-06-10 15:07:51

This patch enables software (and phy device) transmit time stamping
for the smsc9420. Compile tested only.

Cc: Steve Glendinning <redacted>
Signed-off-by: Richard Cochran <redacted>
---
 drivers/net/smsc9420.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/drivers/net/smsc9420.c b/drivers/net/smsc9420.c
index 4c92ad8..2d84f92 100644
--- a/drivers/net/smsc9420.c
+++ b/drivers/net/smsc9420.c
@@ -1034,6 +1034,8 @@ static netdev_tx_t smsc9420_hard_start_xmit(struct sk_buff *skb,
 	smsc9420_reg_write(pd, TX_POLL_DEMAND, 1);
 	smsc9420_pci_flush_write(pd);
 
+	skb_tx_timestamp(skb);
+
 	return NETDEV_TX_OK;
 }
 
-- 
1.7.0.4
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help