From e4aa9cf635afdfbe604c5fa61c3801653404713b Mon Sep 17 00:00:00 2001
From: Alessandro Rubini <rubini@gnudd.com>
Date: Sat, 18 Dec 2010 17:45:41 +0100
Subject: [PATCH] r8169: added rx timestamp

Like the previous patch, this adds fake hw-timestamp to the RTL8169 device.

Signed-off-by: Alessandro Rubini <rubini@gnudd.com>
---
 drivers/net/r8169.c |   16 ++++++++++++++++
 1 files changed, 16 insertions(+), 0 deletions(-)

diff --git a/drivers/net/r8169.c b/drivers/net/r8169.c
index 2a85588..9b37f02 100644
--- a/drivers/net/r8169.c
+++ b/drivers/net/r8169.c
@@ -4563,6 +4563,20 @@ out:
 	return done;
 }
 
+static inline void __tstamp_rx(struct sk_buff *skb)
+{
+	struct skb_shared_hwtstamps *shhwtstamps = skb_hwtstamps(skb);
+	struct timespec ts;
+
+	getnstimeofday(&ts);
+
+	memset(shhwtstamps, 0, sizeof(*shhwtstamps));
+	ts.tv_sec %=10000; /* sys tstamp different from sw one */
+	shhwtstamps->syststamp = timespec_to_ktime(ts);
+	ts.tv_sec %=100; /* and hw tstamp is still different */
+	shhwtstamps->hwtstamp = timespec_to_ktime(ts);
+}
+
 /*
  * Warning : rtl8169_rx_interrupt() might be called :
  * 1) from NAPI (softirq) context
@@ -4639,6 +4653,8 @@ static int rtl8169_rx_interrupt(struct net_device *dev,
 			skb->protocol = eth_type_trans(skb, dev);
 
 			if (rtl8169_rx_vlan_skb(tp, desc, skb, polling) < 0) {
+				if (unlikely(tp->hwtstamp & TSTAMP_RX))
+					__tstamp_rx(skb);
 				if (likely(polling))
 					netif_receive_skb(skb);
 				else
-- 
1.5.6.5

