Skip to contentSkip to conversation

Convert blackfin to phc and remove timecompare

RFC PATCH Superseded Richard Cochran 4 participants 22 messages Sep 28, 2012 – Nov 1, 2012 1 message not in the archive

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Convert blackfin to phc and remove timecompare

This patch series takes care of a legacy issue in the time keeping core by moving blackfin over to PHC model and removing the dubious timecompare code.

The blackfin is quite similar to the other MAC based PTP hardware clocks, and so the implementation is straightforward. However, I don't have a board to test this on, and I would really appreciate if someone would test this for me. If anyone wants to lend me a board or make one available for remote login, please let me know.

The first patch is a bug fix that should be merged in any case. Pacthes two and three convert the bfin_mac to offer a PHC device. The last patch removes the timecompare code.

Thanks,
Richard

Richard Cochran (4):
bfin_mac: only advertise hardware time stamped when enabled.
bfin_mac: replace sys time stamps with raw ones instead.
bfin_mac: offer a PTP Hardware Clock.
time: remove the timecompare code.

 drivers/net/ethernet/adi/Kconfig    |    2 +-
 drivers/net/ethernet/adi/bfin_mac.c |  259 ++++++++++++++++++++++++++---------
 drivers/net/ethernet/adi/bfin_mac.h |   13 +-
 include/linux/timecompare.h         |  125 -----------------
 kernel/time/Makefile                |    2 +-
 kernel/time/timecompare.c           |  193 --------------------------
 6 files changed, 205 insertions(+), 389 deletions(-)
 delete mode 100644 include/linux/timecompare.h
 delete mode 100644 kernel/time/timecompare.c
Signature · 1 line
1.7.2.5
#1 lore raw

RFC PATCH 1/4 bfin_mac: only advertise hardware time stamped when enabled.

The hardware time stamping code is a compile time option for the blackfin. When it is not enabled, the driver should fall back to the standard ethtool reply to the get_ts_info query.

Compile tested only.

---
 drivers/net/ethernet/adi/bfin_mac.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
drivers/net/ethernet/adi/bfin_mac.c +4 -0
index f816426..2349abb 100644
@@ -548,6 +548,7 @@ static int bfin_mac_ethtool_setwol(struct net_device *dev,
 	return 0;
 }
 
+#ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
 static int bfin_mac_ethtool_get_ts_info(struct net_device *dev,
 	struct ethtool_ts_info *info)
 {
@@ -566,6 +567,7 @@ static int bfin_mac_ethtool_get_ts_info(struct net_device *dev,
 		(1 << HWTSTAMP_FILTER_PTP_V2_L4_EVENT);
 	return 0;
 }
+#endif
 
 static const struct ethtool_ops bfin_mac_ethtool_ops = {
 	.get_settings = bfin_mac_ethtool_getsettings,
@@ -574,7 +576,9 @@ static const struct ethtool_ops bfin_mac_ethtool_ops = {
 	.get_drvinfo = bfin_mac_ethtool_getdrvinfo,
 	.get_wol = bfin_mac_ethtool_getwol,
 	.set_wol = bfin_mac_ethtool_setwol,
+#ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
 	.get_ts_info = bfin_mac_ethtool_get_ts_info,
+#endif
 };
 
 /**************************************************************************/
Signature · 1 line
1.7.2.5
#2 lore raw

RFC PATCH 2/4 bfin_mac: replace sys time stamps with raw ones instead.

In reply to Richard Cochran

This patch replaces the sys time stamps and timecompare code with simple raw hardware time stamps in nanosecond resolution. The only tricky bit is to find a PTP Hardware Clock period slower than the input clock period and a power of two.

Compile tested only.

---
 drivers/net/ethernet/adi/bfin_mac.c |   91 ++++++++++-------------------------
 drivers/net/ethernet/adi/bfin_mac.h |    7 +--
 2 files changed, 28 insertions(+), 70 deletions(-)
drivers/net/ethernet/adi/bfin_mac.c +26 -65
index 2349abb..393d1b5 100644
@@ -555,7 +555,7 @@ static int bfin_mac_ethtool_get_ts_info(struct net_device *dev,
 	info->so_timestamping =
 		SOF_TIMESTAMPING_TX_HARDWARE |
 		SOF_TIMESTAMPING_RX_HARDWARE |
-		SOF_TIMESTAMPING_SYS_HARDWARE;
+		SOF_TIMESTAMPING_RAW_HARDWARE;
 	info->phc_index = -1;
 	info->tx_types =
 		(1 << HWTSTAMP_TX_OFF) |
@@ -653,6 +653,20 @@ static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
 #ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
 #define bfin_mac_hwtstamp_is_none(cfg) ((cfg) == HWTSTAMP_FILTER_NONE)
 
+static u32 bfin_select_phc_clock(u32 input_clk, unsigned int *shift_result)
+{
+	u32 ipn = 1000000000UL / input_clk;
+	u32 ppn = 1;
+	unsigned int shift = 0;
+
+	while (ppn <= ipn) {
+		ppn <<= 1;
+		shift++;
+	}
+	*shift_result = shift;
+	return 1000000000UL / ppn;
+}
+
 static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
 		struct ifreq *ifr, int cmd)
 {
@@ -802,19 +816,7 @@ static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
 		bfin_read_EMAC_PTP_TXSNAPLO();
 		bfin_read_EMAC_PTP_TXSNAPHI();
 
-		/*
-		 * Set registers so that rollover occurs soon to test this.
-		 */
-		bfin_write_EMAC_PTP_TIMELO(0x00000000);
-		bfin_write_EMAC_PTP_TIMEHI(0xFF800000);
-
 		SSYNC();
-
-		lp->compare.last_update = 0;
-		timecounter_init(&lp->clock,
-				&lp->cycles,
-				ktime_to_ns(ktime_get_real()));
-		timecompare_update(&lp->compare, 0);
 	}
 
 	lp->stamp_cfg = config;
@@ -822,15 +824,6 @@ static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
 		-EFAULT : 0;
 }
 
-static void bfin_dump_hwtamp(char *s, ktime_t *hw, ktime_t *ts, struct timecompare *cmp)
-{
-	ktime_t sys = ktime_get_real();
-
-	pr_debug("%s %s hardware:%d,%d transform system:%d,%d system:%d,%d, cmp:%lld, %lld\n",
-			__func__, s, hw->tv.sec, hw->tv.nsec, ts->tv.sec, ts->tv.nsec, sys.tv.sec,
-			sys.tv.nsec, cmp->offset, cmp->skew);
-}
-
 static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 {
 	struct bfin_mac_local *lp = netdev_priv(netdev);
@@ -861,15 +854,9 @@ static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 			regval = bfin_read_EMAC_PTP_TXSNAPLO();
 			regval |= (u64)bfin_read_EMAC_PTP_TXSNAPHI() << 32;
 			memset(&shhwtstamps, 0, sizeof(shhwtstamps));
-			ns = timecounter_cyc2time(&lp->clock,
-					regval);
-			timecompare_update(&lp->compare, ns);
+			ns = regval >> lp->shift;
 			shhwtstamps.hwtstamp = ns_to_ktime(ns);
-			shhwtstamps.syststamp =
-				timecompare_transform(&lp->compare, ns);
 			skb_tstamp_tx(skb, &shhwtstamps);
-
-			bfin_dump_hwtamp("TX", &shhwtstamps.hwtstamp, &shhwtstamps.syststamp, &lp->compare);
 		}
 	}
 }
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
 	regval = bfin_read_EMAC_PTP_RXSNAPLO();
 	regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-	ns = timecounter_cyc2time(&lp->clock, regval);
-	timecompare_update(&lp->compare, ns);
+	ns = regval >> lp->shift;
 	memset(shhwtstamps, 0, sizeof(*shhwtstamps));
 	shhwtstamps->hwtstamp = ns_to_ktime(ns);
-	shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
-
-	bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
-}
-
-/*
- * bfin_read_clock - read raw cycle counter (to be used by time counter)
- */
-static cycle_t bfin_read_clock(const struct cyclecounter *tc)
-{
-	u64 stamp;
-
-	stamp =  bfin_read_EMAC_PTP_TIMELO();
-	stamp |= (u64)bfin_read_EMAC_PTP_TIMEHI() << 32ULL;
-
-	return stamp;
 }
 
-#define PTP_CLK 25000000
-
 static void bfin_mac_hwtstamp_init(struct net_device *netdev)
 {
 	struct bfin_mac_local *lp = netdev_priv(netdev);
-	u64 append;
+	u64 addend;
+	u32 input_clk, phc_clk;
 
 	/* Initialize hardware timer */
-	append = PTP_CLK * (1ULL << 32);
-	do_div(append, get_sclk());
-	bfin_write_EMAC_PTP_ADDEND((u32)append);
-
-	memset(&lp->cycles, 0, sizeof(lp->cycles));
-	lp->cycles.read = bfin_read_clock;
-	lp->cycles.mask = CLOCKSOURCE_MASK(64);
-	lp->cycles.mult = 1000000000 / PTP_CLK;
-	lp->cycles.shift = 0;
-
-	/* Synchronize our NIC clock against system wall clock */
-	memset(&lp->compare, 0, sizeof(lp->compare));
-	lp->compare.source = &lp->clock;
-	lp->compare.target = ktime_get_real;
-	lp->compare.num_samples = 10;
+	input_clk = get_sclk();
+	phc_clk = bfin_select_phc_clock(input_clk, &lp->shift);
+	addend = phc_clk * (1ULL << 32);
+	do_div(addend, input_clk);
+	bfin_write_EMAC_PTP_ADDEND((u32)addend);
+
+	lp->addend = addend;
 
 	/* Initialize hwstamp config */
 	lp->stamp_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
drivers/net/ethernet/adi/bfin_mac.h +2 -5
index 960905c..57f042c 100644
@@ -11,8 +11,6 @@
 #define _BFIN_MAC_H_
 
 #include <linux/net_tstamp.h>
-#include <linux/clocksource.h>
-#include <linux/timecompare.h>
 #include <linux/timer.h>
 #include <linux/etherdevice.h>
 #include <linux/bfin_mac.h>
@@ -94,9 +92,8 @@ struct bfin_mac_local {
 	struct mii_bus *mii_bus;
 
 #if defined(CONFIG_BFIN_MAC_USE_HWSTAMP)
-	struct cyclecounter cycles;
-	struct timecounter clock;
-	struct timecompare compare;
+	u32 addend;
+	unsigned int shift;
 	struct hwtstamp_config stamp_cfg;
 #endif
 };
Signature · 1 line
1.7.2.5
#3 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 103 lines · Richard Cochran

This patch replaces the sys time stamps and timecompare code with simple raw hardware time stamps in nanosecond resolution. The only tricky bit is to find a PTP Hardware Clock period slower than the input clock period and a power of two.

Compile tested only.

---
 drivers/net/ethernet/adi/bfin_mac.c |   91 ++++++++++-------------------------
 drivers/net/ethernet/adi/bfin_mac.h |    7 +--
 2 files changed, 28 insertions(+), 70 deletions(-)
drivers/net/ethernet/adi/bfin_mac.c +16 -29
index 2349abb..393d1b5 100644
@@ -555,7 +555,7 @@ static int bfin_mac_ethtool_get_ts_info(struct net_device *dev,
        info->so_timestamping =
                SOF_TIMESTAMPING_TX_HARDWARE |
                SOF_TIMESTAMPING_RX_HARDWARE |
-               SOF_TIMESTAMPING_SYS_HARDWARE;
+               SOF_TIMESTAMPING_RAW_HARDWARE;
        info->phc_index = -1;
        info->tx_types =
                (1 << HWTSTAMP_TX_OFF) |
@@ -653,6 +653,20 @@ static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
 #ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
 #define bfin_mac_hwtstamp_is_none(cfg) ((cfg) == HWTSTAMP_FILTER_NONE)
 
+static u32 bfin_select_phc_clock(u32 input_clk, unsigned int *shift_result)
+{
+       u32 ipn = 1000000000UL / input_clk;
+       u32 ppn = 1;
+       unsigned int shift = 0;
+
+       while (ppn <= ipn) {
+               ppn <<= 1;
+               shift++;
+       }
+       *shift_result = shift;
+       return 1000000000UL / ppn;
+}
+
 static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
                struct ifreq *ifr, int cmd)
 {
@@ -802,19 +816,7 @@ static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
                bfin_read_EMAC_PTP_TXSNAPLO();
                bfin_read_EMAC_PTP_TXSNAPHI();
 
-               /*
-                * Set registers so that rollover occurs soon to test this.
-                */
-               bfin_write_EMAC_PTP_TIMELO(0x00000000);
-               bfin_write_EMAC_PTP_TIMEHI(0xFF800000);
-
                SSYNC();
-
-               lp->compare.last_update = 0;
-               timecounter_init(&lp->clock,
-                               &lp->cycles,
-                               ktime_to_ns(ktime_get_real()));
-               timecompare_update(&lp->compare, 0);
        }
 
        lp->stamp_cfg = config;
@@ -822,15 +824,6 @@ static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
                -EFAULT : 0;
 }
 
-static void bfin_dump_hwtamp(char *s, ktime_t *hw, ktime_t *ts, struct timecompare *cmp)
-{
-       ktime_t sys = ktime_get_real();
-
-       pr_debug("%s %s hardware:%d,%d transform system:%d,%d system:%d,%d, cmp:%lld, %lld\n",
-                       __func__, s, hw->tv.sec, hw->tv.nsec, ts->tv.sec, ts->tv.nsec, sys.tv.sec,
-                       sys.tv.nsec, cmp->offset, cmp->skew);
-}
-
 static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 {
        struct bfin_mac_local *lp = netdev_priv(netdev);
@@ -861,15 +854,9 @@ static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
                        regval = bfin_read_EMAC_PTP_TXSNAPLO();
                        regval |= (u64)bfin_read_EMAC_PTP_TXSNAPHI() << 32;
                        memset(&shhwtstamps, 0, sizeof(shhwtstamps));
-                       ns = timecounter_cyc2time(&lp->clock,
-                                       regval);
-                       timecompare_update(&lp->compare, ns);
+                       ns = regval >> lp->shift;
                        shhwtstamps.hwtstamp = ns_to_ktime(ns);
-                       shhwtstamps.syststamp =
-                               timecompare_transform(&lp->compare, ns);
                        skb_tstamp_tx(skb, &shhwtstamps);
-
-                       bfin_dump_hwtamp("TX", &shhwtstamps.hwtstamp, &shhwtstamps.syststamp, &lp->compare);
                }
        }
 }
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
        regval = bfin_read_EMAC_PTP_RXSNAPLO();

drivers/net/ethernet/adi/bfin_mac.c static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 902

Quoted 10 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -6
        regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-       ns = timecounter_cyc2time(&lp->clock, regval);
-       timecompare_update(&lp->compare, ns);
+       ns = regval >> lp->shift;
        memset(shhwtstamps, 0, sizeof(*shhwtstamps));
        shhwtstamps->hwtstamp = ns_to_ktime(ns);
-       shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
-
-       bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
-}

In my test, system time in slave side can't be updated although here have set shhwtstamps->hwtstamp = ns_to_ktime(ns).
Any idea?

Quoted 81 lines
drivers/net/ethernet/adi/bfin_mac.c +9 -30
-
-/*
- * bfin_read_clock - read raw cycle counter (to be used by time counter)
- */
-static cycle_t bfin_read_clock(const struct cyclecounter *tc)
-{
-       u64 stamp;
-
-       stamp =  bfin_read_EMAC_PTP_TIMELO();
-       stamp |= (u64)bfin_read_EMAC_PTP_TIMEHI() << 32ULL;
-
-       return stamp;
 }
 
-#define PTP_CLK 25000000
-
 static void bfin_mac_hwtstamp_init(struct net_device *netdev)
 {
        struct bfin_mac_local *lp = netdev_priv(netdev);
-       u64 append;
+       u64 addend;
+       u32 input_clk, phc_clk;
 
        /* Initialize hardware timer */
-       append = PTP_CLK * (1ULL << 32);
-       do_div(append, get_sclk());
-       bfin_write_EMAC_PTP_ADDEND((u32)append);
-
-       memset(&lp->cycles, 0, sizeof(lp->cycles));
-       lp->cycles.read = bfin_read_clock;
-       lp->cycles.mask = CLOCKSOURCE_MASK(64);
-       lp->cycles.mult = 1000000000 / PTP_CLK;
-       lp->cycles.shift = 0;
-
-       /* Synchronize our NIC clock against system wall clock */
-       memset(&lp->compare, 0, sizeof(lp->compare));
-       lp->compare.source = &lp->clock;
-       lp->compare.target = ktime_get_real;
-       lp->compare.num_samples = 10;
+       input_clk = get_sclk();
+       phc_clk = bfin_select_phc_clock(input_clk, &lp->shift);
+       addend = phc_clk * (1ULL << 32);
+       do_div(addend, input_clk);
+       bfin_write_EMAC_PTP_ADDEND((u32)addend);
+
+       lp->addend = addend;
 
        /* Initialize hwstamp config */
        lp->stamp_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
drivers/net/ethernet/adi/bfin_mac.h +2 -6
index 960905c..57f042c 100644
@@ -11,8 +11,6 @@
 #define _BFIN_MAC_H_
 
 #include <linux/net_tstamp.h>
-#include <linux/clocksource.h>
-#include <linux/timecompare.h>
 #include <linux/timer.h>
 #include <linux/etherdevice.h>
 #include <linux/bfin_mac.h>
@@ -94,9 +92,8 @@ struct bfin_mac_local {
        struct mii_bus *mii_bus;
 
 #if defined(CONFIG_BFIN_MAC_USE_HWSTAMP)
-       struct cyclecounter cycles;
-       struct timecounter clock;
-       struct timecompare compare;
+       u32 addend;
+       unsigned int shift;
        struct hwtstamp_config stamp_cfg;
 #endif
 };
--

1.7.2.5

_______________________________________________
Uclinux-dist-devel mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/uclinux-dist-devel

Signature · 2 lines
Regards,
--Bob
#4 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 17 lines · Bob Liu

drivers/net/ethernet/adi/bfin_mac.c static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 902

Quoted 13 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -6
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
        regval = bfin_read_EMAC_PTP_RXSNAPLO();
        regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-       ns = timecounter_cyc2time(&lp->clock, regval);
-       timecompare_update(&lp->compare, ns);
+       ns = regval >> lp->shift;
        memset(shhwtstamps, 0, sizeof(*shhwtstamps));
        shhwtstamps->hwtstamp = ns_to_ktime(ns);
-       shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
-
-       bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
-}

In my test, system time in slave side can't be updated although here have set shhwtstamps->hwtstamp = ns_to_ktime(ns).
Any idea?

So the "system time" in shhwtstamps->syststamp has been removed. Only the raw value remains.

Or what do you mean by "can't be updated"?

How did you test this?

I would suggest the following:

1. test using Documentation/ptp/testptp to make sure the clock is working reasconably.

2. try ptp4l from http://linuxptp.sourceforge.net/ to make sure the time stamping is working

Thanks,
Richard

#5 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 20 lines · Richard Cochran
Quoted 17 lines · Bob Liu

drivers/net/ethernet/adi/bfin_mac.c static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 902

Quoted 13 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -6
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
        regval = bfin_read_EMAC_PTP_RXSNAPLO();
        regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-       ns = timecounter_cyc2time(&lp->clock, regval);
-       timecompare_update(&lp->compare, ns);
+       ns = regval >> lp->shift;
        memset(shhwtstamps, 0, sizeof(*shhwtstamps));
        shhwtstamps->hwtstamp = ns_to_ktime(ns);
-       shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
-
-       bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
-}

In my test, system time in slave side can't be updated although here have set shhwtstamps->hwtstamp = ns_to_ktime(ns).
Any idea?

Quoted 7 lines

So the "system time" in shhwtstamps->syststamp has been removed. Only the raw value remains.

Or what do you mean by "can't be updated"?

How did you test this?

Using ptpv2 from ptpd.sourceforge.net.
That's the tool we used to test ptp, it's out of date now?

Quoted 5 lines

I would suggest the following:

1. test using Documentation/ptp/testptp to make sure the clock is working reasconably.

Seems work fine:
---------------------
root:/> ./testptp -c
capabilities:
279999999 maximum frequency adjustment (ppb)
0 programmable alarms
0 external time stamp channels
0 programmable periodic signals
0 pulse per second
root:/> ./testptp -g
clock time: 221.372644272 or Thu Jan 1 00:03:41 1970 root:/> date
Fri Jan 2 10:52:06 UTC 1970
root:/>
root:/> date -s 2010.03.16-15:30
Tue Mar 16 15:30:00 UTC 2010
root:/>
root:/> ./testptp -g
clock time: 242.392199760 or Thu Jan 1 00:04:02 1970 root:/> ./testptp -s
set time okay
root:/> ./testptp -g
clock time: 1268753411.506626656 or Tue Mar 16 15:30:11 2010 root:/>

Quoted 3 lines

2. try ptp4l from http://linuxptp.sourceforge.net/ to make sure the time stamping is working

Any guide how to use ptp4l to sync system time between two machines over ethernet?
We used to use PTPd - Precision Time Protocol daemon.

Thanks,
--Bob

#6 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 25 lines · Bob Liu
Quoted 23 lines · Richard Cochran
Quoted 17 lines · Bob Liu

drivers/net/ethernet/adi/bfin_mac.c static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 902

Quoted 13 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -6
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
        regval = bfin_read_EMAC_PTP_RXSNAPLO();
        regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-       ns = timecounter_cyc2time(&lp->clock, regval);
-       timecompare_update(&lp->compare, ns);
+       ns = regval >> lp->shift;
        memset(shhwtstamps, 0, sizeof(*shhwtstamps));
        shhwtstamps->hwtstamp = ns_to_ktime(ns);
-       shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
-
-       bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
-}

In my test, system time in slave side can't be updated although here have set shhwtstamps->hwtstamp = ns_to_ktime(ns).
Any idea?

So the "system time" in shhwtstamps->syststamp has been removed. Only the raw value remains.

Quoted 8 lines
Quoted 4 lines

Or what do you mean by "can't be updated"?

How did you test this?

Using ptpv2 from ptpd.sourceforge.net.
That's the tool we used to test ptp, it's out of date now?

Sorry, we used to use this one:
https://github.com/richardcochran/ptpd-phc.git

Quoted 40 lines
Quoted 5 lines

I would suggest the following:

1. test using Documentation/ptp/testptp to make sure the clock is working reasconably.

Seems work fine:
---------------------
root:/> ./testptp -c
capabilities:
279999999 maximum frequency adjustment (ppb)
0 programmable alarms
0 external time stamp channels
0 programmable periodic signals
0 pulse per second
root:/> ./testptp -g
clock time: 221.372644272 or Thu Jan 1 00:03:41 1970 root:/> date
Fri Jan 2 10:52:06 UTC 1970
root:/>
root:/> date -s 2010.03.16-15:30
Tue Mar 16 15:30:00 UTC 2010
root:/>
root:/> ./testptp -g
clock time: 242.392199760 or Thu Jan 1 00:04:02 1970 root:/> ./testptp -s
set time okay
root:/> ./testptp -g
clock time: 1268753411.506626656 or Tue Mar 16 15:30:11 2010 root:/>

Quoted 3 lines

2. try ptp4l from http://linuxptp.sourceforge.net/ to make sure the time stamping is working

Any guide how to use ptp4l to sync system time between two machines over ethernet?
We used to use PTPd - Precision Time Protocol daemon.

Signature · 2 lines
Thanks,
--Bob
#7 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 2 lines · Bob Liu

Sorry, we used to use this one:
https://github.com/richardcochran/ptpd-phc.git

I removed that repo since it was only a proof-of-concept hack, and it is now out of date. However, I would think that it should still work with my new changes.

Thanks,
Richard

#8 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

In reply to Bob Liu
Quoted 2 lines · Bob Liu

Any guide how to use ptp4l to sync system time between two machines over ethernet?

You can run ptp4l on two machines like this

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave

and you should see the "master offset" on the slave converge within about 30 seconds or so.

Thanks,
Richard

#9 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 10 lines · Richard Cochran
Quoted 2 lines · Bob Liu

Any guide how to use ptp4l to sync system time between two machines over ethernet?

You can run ptp4l on two machines like this

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave

Thank you.
But i'm still failed to sync system time.

On mater:
-------------------------------
root:/> date
Wed Dec 20 01:31:02 UTC 2006
root:/>
root:/> ptp4l -i eth0 -q -v
ptp4l[33.520]: selected /dev/ptp0 as PTP clock
ptp4l[33.520]: m
ptp4l[33.520]: driver rejected most general HWTSTAMP filter ptp4l[33.520]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[33.524]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.524]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
.....

-----------------------------
On slave:
root:~> date
Fri Jan 2 13:16:07 UTC 1970

root:~> ptp4l -i eth0 -q -v -s
ptp4l[39.624]: selected /dev/ptp0 as PTP clock ptp4l[39.628]: m
ptp4l[39.628]: driver rejected most general HWTSTAMP filter ptp4l[39.628]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.632]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.664]: port 1: new foreign master 00e022.fffe.fe8529-1 ptp4l[43.672]: selected best master clock 00e022.fffe.fe8529 ptp4l[43.676]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE

ptp4l[44.688]: master offset -7968957480 s0 adj      +0 path delay       8120
ptp4l[45.692]: master offset -7968953124 s0 adj      +0 path delay       9076
ptp4l[46.696]: master offset -7968947340 s0 adj      +0 path delay       8860
ptp4l[47.700]: master offset -7968941884 s1 adj      +0 path delay       8860
ptp4l[48.704]: master offset       4564 s2 adj   +4564 path delay       8860
ptp4l[48.704]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[49.708]: master offset       5154 s2 adj   +6523 path delay       9086
ptp4l[50.712]: master offset       3686 s2 adj   +6601 path delay       9322
ptp4l[51.716]: master offset       2582 s2 adj   +6603 path delay       9322
ptp4l[52.720]: master offset       1362 s2 adj   +6158 path delay       9438
ptp4l[53.724]: master offset        658 s2 adj   +5862 path delay       9438
ptp4l[54.728]: master offset        -85 s2 adj   +5317 path delay       9685
ptp4l[55.732]: master offset       -113 s2 adj   +5263 path delay       9873
ptp4l[56.748]: master offset         86 s2 adj   +5428 path delay       9930
ptp4l[57.740]: master offset        166 s2 adj   +5534 path delay       9930
ptp4l[58.744]: master offset       -247 s2 adj   +5171 path delay      10151
ptp4l[59.748]: master offset        -39 s2 adj   +5305 path delay      10151
ptp4l[60.752]: master offset        217 s2 adj   +5549 path delay      10151
ptp4l[61.756]: master offset        256 s2 adj   +5653 path delay      10128

.....

root:~> date
Fri Jan 2 13:16:45 UTC 1970
root:~>

The system time in slave didn't change.

Signature · 2 lines
Thanks,
--Bob
#10 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 63 lines · Bob Liu
Quoted 10 lines · Richard Cochran
Quoted 2 lines · Bob Liu

Any guide how to use ptp4l to sync system time between two machines over ethernet?

You can run ptp4l on two machines like this

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave

Thank you.
But i'm still failed to sync system time.

On mater:
-------------------------------
root:/> date
Wed Dec 20 01:31:02 UTC 2006
root:/>
root:/> ptp4l -i eth0 -q -v
ptp4l[33.520]: selected /dev/ptp0 as PTP clock
ptp4l[33.520]: m
ptp4l[33.520]: driver rejected most general HWTSTAMP filter ptp4l[33.520]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[33.524]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.524]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
.....

-----------------------------
On slave:
root:~> date
Fri Jan 2 13:16:07 UTC 1970

root:~> ptp4l -i eth0 -q -v -s
ptp4l[39.624]: selected /dev/ptp0 as PTP clock ptp4l[39.628]: m
ptp4l[39.628]: driver rejected most general HWTSTAMP filter ptp4l[39.628]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.632]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.664]: port 1: new foreign master 00e022.fffe.fe8529-1 ptp4l[43.672]: selected best master clock 00e022.fffe.fe8529 ptp4l[43.676]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE

ptp4l[44.688]: master offset -7968957480 s0 adj      +0 path delay       8120
ptp4l[45.692]: master offset -7968953124 s0 adj      +0 path delay       9076
ptp4l[46.696]: master offset -7968947340 s0 adj      +0 path delay       8860
ptp4l[47.700]: master offset -7968941884 s1 adj      +0 path delay       8860
ptp4l[48.704]: master offset       4564 s2 adj   +4564 path delay       8860
ptp4l[48.704]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[49.708]: master offset       5154 s2 adj   +6523 path delay       9086
ptp4l[50.712]: master offset       3686 s2 adj   +6601 path delay       9322
ptp4l[51.716]: master offset       2582 s2 adj   +6603 path delay       9322
ptp4l[52.720]: master offset       1362 s2 adj   +6158 path delay       9438
ptp4l[53.724]: master offset        658 s2 adj   +5862 path delay       9438
ptp4l[54.728]: master offset        -85 s2 adj   +5317 path delay       9685
ptp4l[55.732]: master offset       -113 s2 adj   +5263 path delay       9873
ptp4l[56.748]: master offset         86 s2 adj   +5428 path delay       9930
ptp4l[57.740]: master offset        166 s2 adj   +5534 path delay       9930
ptp4l[58.744]: master offset       -247 s2 adj   +5171 path delay      10151
ptp4l[59.748]: master offset        -39 s2 adj   +5305 path delay      10151
ptp4l[60.752]: master offset        217 s2 adj   +5549 path delay      10151
ptp4l[61.756]: master offset        256 s2 adj   +5653 path delay      10128
Quoted 1 line

.....

This looks perfect. Did you fixup the wrong time stamp shift?

Quoted 6 lines

root:~> date
Fri Jan 2 13:16:45 UTC 1970
root:~>

The system time in slave didn't change.

That is correct. Using RAW time stamping and PHC, the time in the PHC changes, but not the system time. The system time may be slaved to the PHC time using the phc2sys program.

Anyhow, it looks like this is working fine to me.

Thanks,
Richard

#11 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 73 lines · Richard Cochran
Quoted 63 lines · Bob Liu
Quoted 10 lines · Richard Cochran
Quoted 2 lines · Bob Liu

Any guide how to use ptp4l to sync system time between two machines over ethernet?

You can run ptp4l on two machines like this

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave

Thank you.
But i'm still failed to sync system time.

On mater:
-------------------------------
root:/> date
Wed Dec 20 01:31:02 UTC 2006
root:/>
root:/> ptp4l -i eth0 -q -v
ptp4l[33.520]: selected /dev/ptp0 as PTP clock
ptp4l[33.520]: m
ptp4l[33.520]: driver rejected most general HWTSTAMP filter ptp4l[33.520]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[33.524]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.524]: port 1: LISTENING to MASTER on ANNOUNCE_RECEIPT_TIMEOUT_EXPIRES
.....

-----------------------------
On slave:
root:~> date
Fri Jan 2 13:16:07 UTC 1970

root:~> ptp4l -i eth0 -q -v -s
ptp4l[39.624]: selected /dev/ptp0 as PTP clock ptp4l[39.628]: m
ptp4l[39.628]: driver rejected most general HWTSTAMP filter ptp4l[39.628]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.632]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[39.664]: port 1: new foreign master 00e022.fffe.fe8529-1 ptp4l[43.672]: selected best master clock 00e022.fffe.fe8529 ptp4l[43.676]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE

ptp4l[44.688]: master offset -7968957480 s0 adj      +0 path delay       8120
ptp4l[45.692]: master offset -7968953124 s0 adj      +0 path delay       9076
ptp4l[46.696]: master offset -7968947340 s0 adj      +0 path delay       8860
ptp4l[47.700]: master offset -7968941884 s1 adj      +0 path delay       8860
ptp4l[48.704]: master offset       4564 s2 adj   +4564 path delay       8860
ptp4l[48.704]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[49.708]: master offset       5154 s2 adj   +6523 path delay       9086
ptp4l[50.712]: master offset       3686 s2 adj   +6601 path delay       9322
ptp4l[51.716]: master offset       2582 s2 adj   +6603 path delay       9322
ptp4l[52.720]: master offset       1362 s2 adj   +6158 path delay       9438
ptp4l[53.724]: master offset        658 s2 adj   +5862 path delay       9438
ptp4l[54.728]: master offset        -85 s2 adj   +5317 path delay       9685
ptp4l[55.732]: master offset       -113 s2 adj   +5263 path delay       9873
ptp4l[56.748]: master offset         86 s2 adj   +5428 path delay       9930
ptp4l[57.740]: master offset        166 s2 adj   +5534 path delay       9930
ptp4l[58.744]: master offset       -247 s2 adj   +5171 path delay      10151
ptp4l[59.748]: master offset        -39 s2 adj   +5305 path delay      10151
ptp4l[60.752]: master offset        217 s2 adj   +5549 path delay      10151
ptp4l[61.756]: master offset        256 s2 adj   +5653 path delay      10128
Quoted 1 line

.....

This looks perfect. Did you fixup the wrong time stamp shift?

Quoted 5 lines

root:~> date
Fri Jan 2 13:16:45 UTC 1970
root:~>

Quoted 6 lines
Quoted 1 line

The system time in slave didn't change.

That is correct. Using RAW time stamping and PHC, the time in the PHC changes, but not the system time. The system time may be slaved to the PHC time using the phc2sys program.

How to use it?

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave
And on slave i should also start: phc2sys -s /dev/ptp0 -i eth0? But this can't work.

Quoted 4 lines

Anyhow, it looks like this is working fine to me.

Thanks,
Richard

Signature · 2 lines
Regards,
--Bob
#12 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 1 line · Bob Liu

How to use it?

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave

#
# Wait for state s2 on the slave_________
# \
ptp4l[336.203]: master offset 569 s2 adj +102784 path delay 33666
#
# Then start phc2sys.
#

phc2sys -s /dev/ptp0

Quoted 1 line

But this can't work.

Can you post the output of the ptp4l and phc2sys on the slave?

Thanks again for testing this for me,
Richard

#13 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 14 lines · Richard Cochran
Quoted 1 line · Bob Liu

How to use it?

ptp4l -i eth0 -q -v # master
ptp4l -i eth0 -q -v -s # slave

#
# Wait for state s2 on the slave_________
# \
ptp4l[336.203]: master offset 569 s2 adj +102784 path delay 33666
#
# Then start phc2sys.
#

Quoted 6 lines

phc2sys -s /dev/ptp0

Quoted 1 line

But this can't work.

Can you post the output of the ptp4l and phc2sys on the slave?

I opened three consoles on slave machine using telnet:
console 1:
root:~> ptp4l -i eth0 -q -v -s
ptp4l[75.904]: selected /dev/ptp0 as PTP clock ptp4l[75.908]: m
ptp4l[75.908]: driver rejected most general HWTSTAMP filter ptp4l[75.908]: port 1: INITIALIZING to LISTENING on INITIALIZE ptp4l[75.912]: port 0: INITIALIZING to LISTENING on INITIALIZE ptp4l[76.244]: port 1: new foreign master 00e022.fffe.fe8529-1 ptp4l[80.252]: selected best master clock 00e022.fffe.fe8529 ptp4l[80.252]: port 1: LISTENING to UNCALIBRATED on RS_SLAVE

ptp4l[81.288]: master offset -17688624512 s0 adj      +0 path delay       7456
ptp4l[82.292]: master offset -17688618592 s0 adj      +0 path delay       7456
ptp4l[83.296]: master offset -17688613232 s0 adj      +0 path delay       7584
ptp4l[84.300]: master offset -17688607696 s1 adj      +0 path delay       7584
ptp4l[85.304]: master offset       4736 s2 adj   +4736 path delay
 7584
ptp4l[85.308]: port 1: UNCALIBRATED to SLAVE on MASTER_CLOCK_SELECTED
ptp4l[86.308]: master offset       5600 s2 adj   +7021 path delay       7584
ptp4l[87.312]: master offset       2582 s2 adj   +5683 path delay       9066
ptp4l[88.316]: master offset       2370 s2 adj   +6245 path delay       9262
ptp4l[89.320]: master offset       1568 s2 adj   +6154 path delay       9424
ptp4l[90.324]: master offset        880 s2 adj   +5937 path delay       9424
ptp4l[91.328]: master offset        680 s2 adj   +6001 path delay       9512
ptp4l[92.332]: master offset        165 s2 adj   +5690 path delay       9595
ptp4l[93.336]: master offset        -59 s2 adj   +5515 path delay       9595
ptp4l[94.340]: master offset        -12 s2 adj   +5545 path delay       9644
ptp4l[95.344]: master offset        -95 s2 adj   +5458 path delay       9679
ptp4l[96.348]: master offset         49 s2 adj   +5574 path delay       9679
ptp4l[97.352]: master offset       -143 s2 adj   +5396 path delay       9935

After see s2 state, i start phc2sys in console 2:
root:~> phc2sys -s /dev/ptp0

phc   3421792 s1 46.828595280 drift 0.00
phc   3430512 s2 47.832595280 drift 0.00
phc   3436256 s3 48.836595280 drift 0.00
phc   3454080 s4 49.840595280 drift 10719.79
phc    -37919 s4 50.841130481 drift -655.91
phc     10983 s4 51.845157639 drift 2638.99
phc      7277 s4 52.849147421 drift 4822.09
phc     12694 s4 53.853137462 drift 8630.29
phc     -6028 s4 54.857119908 drift 6821.89
phc     -7998 s4 55.861117234 drift 4422.49
phc     -2657 s4 56.865118399 drift 3625.39
phc     -5072 s4 57.869116640 drift 2103.79
phc     23391 s4 58.873118079 drift 9121.09
phc     -8035 s4 59.877092589 drift 6710.59
phc    -68278 s4 60.881091402 drift -13772.81
phc     53773 s4 61.881152717 drift 2359.09
phc     25317 s4 62.885112965 drift 9954.19
phc     19080 s4 63.889085128 drift 15678.19
phc     -6000 s4 64.893055984 drift 13878.19

phc -17746 s4 65.897046190 drift 8554.39
phc -13533 s4 66.901050019 drift 4494.49
phc 14260 s4 67.905055012 drift 8772.49
phc -7786 s4 68.909036278 drift 6436.69

Then in console 3:
root:~> date
Thu Jan 1 00:00:58 UTC 1970
root:~> date
Thu Jan 1 00:00:59 UTC 1970
root:~> date
Thu Jan 1 00:00:59 UTC 1970
root:~> date
Thu Jan 1 00:01:01 UTC 1970
root:~> date
Thu Jan 1 00:01:01 UTC 1970
root:~> date
Thu Jan 1 00:01:14 UTC 1970

date in master side is:
root:/> date
Thu Dec 21 01:34:26 UTC 2006
root:/>

So the system time didn't sync.

Signature · 2 lines
Thanks,
--Bob
#14 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 5 lines · Bob Liu

date in master side is:
root:/> date
Thu Dec 21 01:34:26 UTC 2006
root:/>

What is the time on the master from the 'testptp -g' command?

Quoted 1 line

So the system time didn't sync.

I guess that you need to set the PHC time on the master, using 'testptp -s'.

[ There are always two clocks on each host, the Linux system time and
the PHC time in the hardware clock. ]

Thanks,
Richard

A message that is not in the archive (sent off-list or not yet received): 20121101093540.GB5949-TJb37gCd1q6chkuNt9O67llkmcu1nq/[email protected]

#16 lore raw

Re: [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 7 lines · Richard Cochran
Quoted 5 lines · Bob Liu

date in master side is:
root:/> date
Thu Dec 21 01:34:26 UTC 2006
root:/>

Quoted 9 lines

What is the time on the master from the 'testptp -g' command?

Quoted 1 line

So the system time didn't sync.

I guess that you need to set the PHC time on the master, using 'testptp -s'.

[ There are always two clocks on each host, the Linux system time and
the PHC time in the hardware clock. ]

Thank you very much.
It works.

Signature · 2 lines
Regards,
--Bob
#17 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 3 lines · Bob Liu

Thank you very much.
It works.

Thanks, Bob.

Can you add your Acked- or Tested-by to the V2 series that I posted?

Richard

#18 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

In reply to Richard Cochran
Quoted 84 lines · Richard Cochran

This patch replaces the sys time stamps and timecompare code with simple raw hardware time stamps in nanosecond resolution. The only tricky bit is to find a PTP Hardware Clock period slower than the input clock period and a power of two.

Compile tested only.

---
 drivers/net/ethernet/adi/bfin_mac.c |   91 ++++++++++-------------------------
 drivers/net/ethernet/adi/bfin_mac.h |    7 +--
 2 files changed, 28 insertions(+), 70 deletions(-)
drivers/net/ethernet/adi/bfin_mac.c +15 -22
index 2349abb..393d1b5 100644
@@ -555,7 +555,7 @@ static int bfin_mac_ethtool_get_ts_info(struct net_device *dev,
        info->so_timestamping =
                SOF_TIMESTAMPING_TX_HARDWARE |
                SOF_TIMESTAMPING_RX_HARDWARE |
-               SOF_TIMESTAMPING_SYS_HARDWARE;
+               SOF_TIMESTAMPING_RAW_HARDWARE;
        info->phc_index = -1;
        info->tx_types =
                (1 << HWTSTAMP_TX_OFF) |
@@ -653,6 +653,20 @@ static int bfin_mac_set_mac_address(struct net_device *dev, void *p)
 #ifdef CONFIG_BFIN_MAC_USE_HWSTAMP
 #define bfin_mac_hwtstamp_is_none(cfg) ((cfg) == HWTSTAMP_FILTER_NONE)
 
+static u32 bfin_select_phc_clock(u32 input_clk, unsigned int *shift_result)
+{
+       u32 ipn = 1000000000UL / input_clk;
+       u32 ppn = 1;
+       unsigned int shift = 0;
+
+       while (ppn <= ipn) {
+               ppn <<= 1;
+               shift++;
+       }
+       *shift_result = shift;
+       return 1000000000UL / ppn;
+}
+
 static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
                struct ifreq *ifr, int cmd)
 {
@@ -802,19 +816,7 @@ static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
                bfin_read_EMAC_PTP_TXSNAPLO();
                bfin_read_EMAC_PTP_TXSNAPHI();
 
-               /*
-                * Set registers so that rollover occurs soon to test this.
-                */
-               bfin_write_EMAC_PTP_TIMELO(0x00000000);
-               bfin_write_EMAC_PTP_TIMEHI(0xFF800000);
-
                SSYNC();
-
-               lp->compare.last_update = 0;
-               timecounter_init(&lp->clock,
-                               &lp->cycles,
-                               ktime_to_ns(ktime_get_real()));
-               timecompare_update(&lp->compare, 0);
        }
 
        lp->stamp_cfg = config;
@@ -822,15 +824,6 @@ static int bfin_mac_hwtstamp_ioctl(struct net_device *netdev,
                -EFAULT : 0;
 }
 
-static void bfin_dump_hwtamp(char *s, ktime_t *hw, ktime_t *ts, struct timecompare *cmp)
-{
-       ktime_t sys = ktime_get_real();
-
-       pr_debug("%s %s hardware:%d,%d transform system:%d,%d system:%d,%d, cmp:%lld, %lld\n",
-                       __func__, s, hw->tv.sec, hw->tv.nsec, ts->tv.sec, ts->tv.nsec, sys.tv.sec,
-                       sys.tv.nsec, cmp->offset, cmp->skew);
-}
-
 static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 {
        struct bfin_mac_local *lp = netdev_priv(netdev);

drivers/net/ethernet/adi/bfin_mac.c static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 857

Quoted 7 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -3
@@ -861,15 +854,9 @@ static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
                        regval = bfin_read_EMAC_PTP_TXSNAPLO();
                        regval |= (u64)bfin_read_EMAC_PTP_TXSNAPHI() << 32;
                        memset(&shhwtstamps, 0, sizeof(shhwtstamps));
-                       ns = timecounter_cyc2time(&lp->clock,
-                                       regval);
-                       timecompare_update(&lp->compare, ns);
+                       ns = regval >> lp->shift;

Why not set ns = regval << lp->shift?
I think it's conflicted with patch [3/4]
+static u64 bfin_ptp_time_read(struct bfin_mac_local *lp) +{
+ u64 ns;
+ u32 lo, hi;
+
+ lo = bfin_read_EMAC_PTP_TIMELO();
+ hi = bfin_read_EMAC_PTP_TIMEHI();
+

+       ns = ((u64) hi) << 32;
+       ns |= lo;
+       ns <<= lp->shift;

+
+ return ns;
+}

Quoted 10 lines
drivers/net/ethernet/adi/bfin_mac.c +0 -4
                        shhwtstamps.hwtstamp = ns_to_ktime(ns);
-                       shhwtstamps.syststamp =
-                               timecompare_transform(&lp->compare, ns);
                        skb_tstamp_tx(skb, &shhwtstamps);
-
-                       bfin_dump_hwtamp("TX", &shhwtstamps.hwtstamp, &shhwtstamps.syststamp, &lp->compare);
                }
        }
 }

drivers/net/ethernet/adi/bfin_mac.c static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 882

Quoted 6 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -2
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
        regval = bfin_read_EMAC_PTP_RXSNAPLO();
        regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-       ns = timecounter_cyc2time(&lp->clock, regval);
-       timecompare_update(&lp->compare, ns);
+       ns = regval >> lp->shift;

So is here.

Quoted 87 lines
drivers/net/ethernet/adi/bfin_mac.c +9 -34
        memset(shhwtstamps, 0, sizeof(*shhwtstamps));
        shhwtstamps->hwtstamp = ns_to_ktime(ns);
-       shhwtstamps->syststamp = timecompare_transform(&lp->compare, ns);
-
-       bfin_dump_hwtamp("RX", &shhwtstamps->hwtstamp, &shhwtstamps->syststamp, &lp->compare);
-}
-
-/*
- * bfin_read_clock - read raw cycle counter (to be used by time counter)
- */
-static cycle_t bfin_read_clock(const struct cyclecounter *tc)
-{
-       u64 stamp;
-
-       stamp =  bfin_read_EMAC_PTP_TIMELO();
-       stamp |= (u64)bfin_read_EMAC_PTP_TIMEHI() << 32ULL;
-
-       return stamp;
 }
 
-#define PTP_CLK 25000000
-
 static void bfin_mac_hwtstamp_init(struct net_device *netdev)
 {
        struct bfin_mac_local *lp = netdev_priv(netdev);
-       u64 append;
+       u64 addend;
+       u32 input_clk, phc_clk;
 
        /* Initialize hardware timer */
-       append = PTP_CLK * (1ULL << 32);
-       do_div(append, get_sclk());
-       bfin_write_EMAC_PTP_ADDEND((u32)append);
-
-       memset(&lp->cycles, 0, sizeof(lp->cycles));
-       lp->cycles.read = bfin_read_clock;
-       lp->cycles.mask = CLOCKSOURCE_MASK(64);
-       lp->cycles.mult = 1000000000 / PTP_CLK;
-       lp->cycles.shift = 0;
-
-       /* Synchronize our NIC clock against system wall clock */
-       memset(&lp->compare, 0, sizeof(lp->compare));
-       lp->compare.source = &lp->clock;
-       lp->compare.target = ktime_get_real;
-       lp->compare.num_samples = 10;
+       input_clk = get_sclk();
+       phc_clk = bfin_select_phc_clock(input_clk, &lp->shift);
+       addend = phc_clk * (1ULL << 32);
+       do_div(addend, input_clk);
+       bfin_write_EMAC_PTP_ADDEND((u32)addend);
+
+       lp->addend = addend;
 
        /* Initialize hwstamp config */
        lp->stamp_cfg.rx_filter = HWTSTAMP_FILTER_NONE;
drivers/net/ethernet/adi/bfin_mac.h +2 -6
index 960905c..57f042c 100644
@@ -11,8 +11,6 @@
 #define _BFIN_MAC_H_
 
 #include <linux/net_tstamp.h>
-#include <linux/clocksource.h>
-#include <linux/timecompare.h>
 #include <linux/timer.h>
 #include <linux/etherdevice.h>
 #include <linux/bfin_mac.h>
@@ -94,9 +92,8 @@ struct bfin_mac_local {
        struct mii_bus *mii_bus;
 
 #if defined(CONFIG_BFIN_MAC_USE_HWSTAMP)
-       struct cyclecounter cycles;
-       struct timecounter clock;
-       struct timecompare compare;
+       u32 addend;
+       unsigned int shift;
        struct hwtstamp_config stamp_cfg;
 #endif
 };
--

1.7.2.5

_______________________________________________
Uclinux-dist-devel mailing list
[email protected]
https://blackfin.uclinux.org/mailman/listinfo/uclinux-dist-devel

Signature · 2 lines
Regards,
--Bob
#19 lore raw

Re: [uclinux-dist-devel] [PATCH RFC net-next 2/4] bfin_mac: replace sys time stamps with raw ones instead.

Quoted 11 lines · Bob Liu

drivers/net/ethernet/adi/bfin_mac.c static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 857

Quoted 8 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -3
@@ -861,15 +854,9 @@ static void bfin_tx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
                        regval = bfin_read_EMAC_PTP_TXSNAPLO();
                        regval |= (u64)bfin_read_EMAC_PTP_TXSNAPHI() << 32;
                        memset(&shhwtstamps, 0, sizeof(shhwtstamps));
-                       ns = timecounter_cyc2time(&lp->clock,
-                                       regval);
-                       timecompare_update(&lp->compare, ns);
+                       ns = regval >> lp->shift;

Why not set ns = regval << lp->shift?
I think it's conflicted with patch [3/4]

Yes, you are right. I will fix this in V2.

Quoted 9 lines

drivers/net/ethernet/adi/bfin_mac.c static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb) · line 882

Quoted 7 lines
drivers/net/ethernet/adi/bfin_mac.c +1 -2
@@ -892,51 +879,25 @@ static void bfin_rx_hwtstamp(struct net_device *netdev, struct sk_buff *skb)
 
        regval = bfin_read_EMAC_PTP_RXSNAPLO();
        regval |= (u64)bfin_read_EMAC_PTP_RXSNAPHI() << 32;
-       ns = timecounter_cyc2time(&lp->clock, regval);
-       timecompare_update(&lp->compare, ns);
+       ns = regval >> lp->shift;

So is here.

Thanks for the careful review,
Richard

#20 lore raw

RFC PATCH 3/4 bfin_mac: offer a PTP Hardware Clock.

In reply to Richard Cochran

The BF518 has a PTP time unit that works in a similar way to other MAC based clocks, like gianfar, ixp46x, and igb. This patch adds support for using the blackfin as a PHC. Although the blackfin hardware does offer a few ancillary features, this patch implements only the basic operations.

Compile tested only.

---
 drivers/net/ethernet/adi/Kconfig    |    2 +-
 drivers/net/ethernet/adi/bfin_mac.c |  170 ++++++++++++++++++++++++++++++++++-
 drivers/net/ethernet/adi/bfin_mac.h |    6 ++
 3 files changed, 175 insertions(+), 3 deletions(-)
drivers/net/ethernet/adi/Kconfig +1 -1
index 49a30d3..175c38c 100644
@@ -61,7 +61,7 @@ config BFIN_RX_DESC_NUM
 
 config BFIN_MAC_USE_HWSTAMP
 	bool "Use IEEE 1588 hwstamp"
-	depends on BFIN_MAC && BF518
+	depends on BFIN_MAC && BF518 && PTP_1588_CLOCK && !(BFIN_MAC=y && PTP_1588_CLOCK=m)
 	default y
 	---help---
 	  To support the IEEE 1588 Precision Time Protocol (PTP), select y here
drivers/net/ethernet/adi/bfin_mac.c +168 -2

222 lines not on this page · raw message

drivers/net/ethernet/adi/bfin_mac.h +6 -0
index 57f042c..7a07ee0 100644
@@ -11,6 +11,7 @@
 #define _BFIN_MAC_H_
 
 #include <linux/net_tstamp.h>
+#include <linux/ptp_clock_kernel.h>
 #include <linux/timer.h>
 #include <linux/etherdevice.h>
 #include <linux/bfin_mac.h>
@@ -94,7 +95,12 @@ struct bfin_mac_local {
 #if defined(CONFIG_BFIN_MAC_USE_HWSTAMP)
 	u32 addend;
 	unsigned int shift;
+	s32 max_ppb;
 	struct hwtstamp_config stamp_cfg;
+	struct ptp_clock_info caps;
+	struct ptp_clock *clock;
+	int phc_index;
+	spinlock_t phc_lock; /* protects time lo/hi registers */
 #endif
 };
 
Signature · 1 line
1.7.2.5
#21 lore raw

RFC PATCH 4/4 time: remove the timecompare code.

In reply to Richard Cochran

This patch removes the timecompare code from the kernel. The top five reasons to do this are:

1. There are no more users of this code.
2. The original idea was a bit weak.
3. The original author has disappeared.
4. The code was not general purpose but tuned to a particular hardware,
5. There are better ways to accomplish clock synchronization.

---
 include/linux/timecompare.h |  125 ----------------------------
 kernel/time/Makefile        |    2 +-
 kernel/time/timecompare.c   |  193 -------------------------------------------
 3 files changed, 1 insertions(+), 319 deletions(-)
 delete mode 100644 include/linux/timecompare.h
 delete mode 100644 kernel/time/timecompare.c
include/linux/timecompare.h deleted +0 -125
deleted file mode 100644
index 546e223..0000000
@@ -1,125 +0,0 @@
-/*
- * Utility code which helps transforming between two different time
- * bases, called "source" and "target" time in this code.
- *
- * Source time has to be provided via the timecounter API while target
- * time is accessed via a function callback whose prototype
- * intentionally matches ktime_get() and ktime_get_real(). These
- * interfaces where chosen like this so that the code serves its
- * initial purpose without additional glue code.
- *
- * This purpose is synchronizing a hardware clock in a NIC with system
- * time, in order to implement the Precision Time Protocol (PTP,
- * IEEE1588) with more accurate hardware assisted time stamping.  In
- * that context only synchronization against system time (=
- * ktime_get_real()) is currently needed. But this utility code might
- * become useful in other situations, which is why it was written as
- * general purpose utility code.
- *
- * The source timecounter is assumed to return monotonically
- * increasing time (but this code does its best to compensate if that
- * is not the case) whereas target time may jump.
- *
- * The target time corresponding to a source time is determined by
- * reading target time, reading source time, reading target time
- * again, then assuming that average target time corresponds to source
- * time. In other words, the assumption is that reading the source
- * time is slow and involves equal time for sending the request and
- * receiving the reply, whereas reading target time is assumed to be
- * fast.
- *
- * Copyright (C) 2009 Intel Corporation.
- * Author: Patrick Ohly <[email protected]>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms and conditions of the GNU General Public License,
- * version 2, as published by the Free Software Foundation.
- *
- * This program is distributed in the hope it will be useful, but WITHOUT
- * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
- * FITNESS FOR A PARTICULAR PURPOSE. * See the GNU General Public License for
- * more details.
- *
- * You should have received a copy of the GNU General Public License along with
- * this program; if not, write to the Free Software Foundation, Inc.,
- * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
- */
-#ifndef _LINUX_TIMECOMPARE_H
-#define _LINUX_TIMECOMPARE_H
-
-#include <linux/clocksource.h>
-#include <linux/ktime.h>
-
-/**
- * struct timecompare - stores state and configuration for the two clocks
- *
- * Initialize to zero, then set source/target/num_samples.
- *
- * Transformation between source time and target time is done with:
- * target_time = source_time + offset +
- *               (source_time - last_update) * skew /
- *               TIMECOMPARE_SKEW_RESOLUTION
- *
- * @source:          used to get source time stamps via timecounter_read()
- * @target:          function returning target time (for example, ktime_get
- *                   for monotonic time, or ktime_get_real for wall clock)
- * @num_samples:     number of times that source time and target time are to
- *                   be compared when determining their offset
- * @offset:          (target time - source time) at the time of the last update
- * @skew:            average (target time - source time) / delta source time *
- *                   TIMECOMPARE_SKEW_RESOLUTION
- * @last_update:     last source time stamp when time offset was measured
- */
-struct timecompare {
-	struct timecounter *source;
-	ktime_t (*target)(void);
-	int num_samples;
-
-	s64 offset;
-	s64 skew;
-	u64 last_update;
-};
-
-/**
- * timecompare_transform - transform source time stamp into target time base
- * @sync:            context for time sync
- * @source_tstamp:   the result of timecounter_read() or
- *                   timecounter_cyc2time()
- */
-extern ktime_t timecompare_transform(struct timecompare *sync,
-				     u64 source_tstamp);
-
-/**
- * timecompare_offset - measure current (target time - source time) offset
- * @sync:            context for time sync
- * @offset:          average offset during sample period returned here
- * @source_tstamp:   average source time during sample period returned here
- *
- * Returns number of samples used. Might be zero (= no result) in the
- * unlikely case that target time was monotonically decreasing for all
- * samples (= broken).
- */
-extern int timecompare_offset(struct timecompare *sync,
-			      s64 *offset,
-			      u64 *source_tstamp);
-
-extern void __timecompare_update(struct timecompare *sync,
-				 u64 source_tstamp);
-
-/**
- * timecompare_update - update offset and skew by measuring current offset
- * @sync:            context for time sync
- * @source_tstamp:   the result of timecounter_read() or
- *                   timecounter_cyc2time(), pass zero to force update
- *
- * Updates are only done at most once per second.
- */
-static inline void timecompare_update(struct timecompare *sync,
-				      u64 source_tstamp)
-{
-	if (!source_tstamp ||
-	    (s64)(source_tstamp - sync->last_update) >= NSEC_PER_SEC)
-		__timecompare_update(sync, source_tstamp);
-}
-
-#endif /* _LINUX_TIMECOMPARE_H */
kernel/time/Makefile +1 -1
index e2fd74b..ff7d9d2 100644
@@ -1,4 +1,4 @@
-obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o timecompare.o
+obj-y += timekeeping.o ntp.o clocksource.o jiffies.o timer_list.o
 obj-y += timeconv.o posix-clock.o alarmtimer.o
 
 obj-$(CONFIG_GENERIC_CLOCKEVENTS_BUILD)		+= clockevents.o
kernel/time/timecompare.c deleted +0 -193

193 lines not on this page · raw message

Signature · 1 line
1.7.2.5
Acked-by on v1 4/4
#22 lore raw

Re: [PATCH RFC net-next 4/4] time: remove the timecompare code.

Quoted 10 lines · Richard Cochran

This patch removes the timecompare code from the kernel. The top five reasons to do this are:

1. There are no more users of this code.
2. The original idea was a bit weak.
3. The original author has disappeared.
4. The code was not general purpose but tuned to a particular hardware,
5. There are better ways to accomplish clock synchronization.

Nice cleanup!

thanks!
-john