Re: [Intel-wired-lan] [PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct

2018-01-09 Thread Sagar Arun Kamble

Thanks Aaron.

Regards,
Sagar

On 1/9/2018 3:50 AM, Brown, Aaron F wrote:

From: Intel-wired-lan [mailto:intel-wired-lan-boun...@osuosl.org] On
Behalf Of Sagar Arun Kamble
Sent: Thursday, December 14, 2017 11:38 PM
To: linux-ker...@vger.kernel.org
Cc: alsa-de...@alsa-project.org; linux-r...@vger.kernel.org;
netdev@vger.kernel.org; Richard Cochran <richardcoch...@gmail.com>;
Stephen Boyd <sb...@codeaurora.org>; Chris Wilson <chris@chris-
wilson.co.uk>; John Stultz <john.stu...@linaro.org>; intel-wired-
l...@lists.osuosl.org; Thomas Gleixner <t...@linutronix.de>; Kamble, Sagar A
<sagar.a.kam...@intel.com>; kvm...@lists.cs.columbia.edu; linux-arm-
ker...@lists.infradead.org
Subject: [Intel-wired-lan] [PATCH 01/27] timecounter: Make cyclecounter
struct part of timecounter struct

There is no real need for the users of timecounters to define cyclecounter
and timecounter variables separately. Since timecounter will always be
based on cyclecounter, have cyclecounter struct as member of timecounter
struct.

v2: Rebase.

Suggested-by: Chris Wilson <ch...@chris-wilson.co.uk>
Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: John Stultz <john.stu...@linaro.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Stephen Boyd <sb...@codeaurora.org>
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: netdev@vger.kernel.org
Cc: intel-wired-...@lists.osuosl.org
Cc: linux-r...@vger.kernel.org
Cc: alsa-de...@alsa-project.org
Cc: kvm...@lists.cs.columbia.edu
Acked-by: Jeff Kirsher <jeffrey.t.kirs...@intel.com> (Intel drivers)
---
  arch/microblaze/kernel/timer.c | 20 ++--
  drivers/clocksource/arm_arch_timer.c   | 19 ++--
  drivers/net/ethernet/amd/xgbe/xgbe-dev.c   |  3 +-
  drivers/net/ethernet/amd/xgbe/xgbe-ptp.c   |  9 +++---
  drivers/net/ethernet/amd/xgbe/xgbe.h   |  1 -
  drivers/net/ethernet/broadcom/bnx2x/bnx2x.h|  1 -
  drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++--
  drivers/net/ethernet/freescale/fec.h   |  1 -
  drivers/net/ethernet/freescale/fec_ptp.c   | 30 +-
  drivers/net/ethernet/intel/e1000e/e1000.h  |  1 -
  drivers/net/ethernet/intel/e1000e/netdev.c | 27 
  drivers/net/ethernet/intel/e1000e/ptp.c|  2 +-
  drivers/net/ethernet/intel/igb/igb.h   |  1 -
  drivers/net/ethernet/intel/igb/igb_ptp.c   | 25 ---
  drivers/net/ethernet/intel/ixgbe/ixgbe.h   |  1 -
  drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c   | 17 +-
  drivers/net/ethernet/mellanox/mlx4/en_clock.c  | 28 -
  drivers/net/ethernet/mellanox/mlx4/mlx4_en.h   |  1 -
  .../net/ethernet/mellanox/mlx5/core/lib/clock.c| 34 ++--
  drivers/net/ethernet/qlogic/qede/qede_ptp.c| 20 ++--
  drivers/net/ethernet/ti/cpts.c | 36 --
  drivers/net/ethernet/ti/cpts.h |  1 -
  include/linux/mlx5/driver.h|  1 -
  include/linux/timecounter.h|  4 +--
  include/sound/hdaudio.h|  1 -
  kernel/time/timecounter.c  | 28 -
  sound/hda/hdac_stream.c|  7 +++--
  virt/kvm/arm/arch_timer.c  |  6 ++--
  28 files changed, 163 insertions(+), 182 deletions(-)


For Intel e1000e and igb drivers:
Tested-by: Aaron Brown <aaron.f.br...@intel.com>




[PATCH 01/27] timecounter: Make cyclecounter struct part of timecounter struct

2017-12-14 Thread Sagar Arun Kamble
There is no real need for the users of timecounters to define cyclecounter
and timecounter variables separately. Since timecounter will always be
based on cyclecounter, have cyclecounter struct as member of timecounter
struct.

v2: Rebase.

Suggested-by: Chris Wilson <ch...@chris-wilson.co.uk>
Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: John Stultz <john.stu...@linaro.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Stephen Boyd <sb...@codeaurora.org>
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: netdev@vger.kernel.org
Cc: intel-wired-...@lists.osuosl.org
Cc: linux-r...@vger.kernel.org
Cc: alsa-de...@alsa-project.org
Cc: kvm...@lists.cs.columbia.edu
Acked-by: Jeff Kirsher <jeffrey.t.kirs...@intel.com> (Intel drivers)
---
 arch/microblaze/kernel/timer.c | 20 ++--
 drivers/clocksource/arm_arch_timer.c   | 19 ++--
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c   |  3 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c   |  9 +++---
 drivers/net/ethernet/amd/xgbe/xgbe.h   |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h|  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++--
 drivers/net/ethernet/freescale/fec.h   |  1 -
 drivers/net/ethernet/freescale/fec_ptp.c   | 30 +-
 drivers/net/ethernet/intel/e1000e/e1000.h  |  1 -
 drivers/net/ethernet/intel/e1000e/netdev.c | 27 
 drivers/net/ethernet/intel/e1000e/ptp.c|  2 +-
 drivers/net/ethernet/intel/igb/igb.h   |  1 -
 drivers/net/ethernet/intel/igb/igb_ptp.c   | 25 ---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h   |  1 -
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c   | 17 +-
 drivers/net/ethernet/mellanox/mlx4/en_clock.c  | 28 -
 drivers/net/ethernet/mellanox/mlx4/mlx4_en.h   |  1 -
 .../net/ethernet/mellanox/mlx5/core/lib/clock.c| 34 ++--
 drivers/net/ethernet/qlogic/qede/qede_ptp.c| 20 ++--
 drivers/net/ethernet/ti/cpts.c | 36 --
 drivers/net/ethernet/ti/cpts.h |  1 -
 include/linux/mlx5/driver.h|  1 -
 include/linux/timecounter.h|  4 +--
 include/sound/hdaudio.h|  1 -
 kernel/time/timecounter.c  | 28 -
 sound/hda/hdac_stream.c|  7 +++--
 virt/kvm/arm/arch_timer.c  |  6 ++--
 28 files changed, 163 insertions(+), 182 deletions(-)

diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
index 7de941c..b7f89e9 100644
--- a/arch/microblaze/kernel/timer.c
+++ b/arch/microblaze/kernel/timer.c
@@ -199,27 +199,25 @@ static u64 xilinx_read(struct clocksource *cs)
return (u64)xilinx_clock_read();
 }
 
-static struct timecounter xilinx_tc = {
-   .cc = NULL,
-};
-
 static u64 xilinx_cc_read(const struct cyclecounter *cc)
 {
return xilinx_read(NULL);
 }
 
-static struct cyclecounter xilinx_cc = {
-   .read = xilinx_cc_read,
-   .mask = CLOCKSOURCE_MASK(32),
-   .shift = 8,
+static struct timecounter xilinx_tc = {
+   .cc.read = xilinx_cc_read,
+   .cc.mask = CLOCKSOURCE_MASK(32),
+   .cc.mult = 0,
+   .cc.shift = 8,
 };
 
 static int __init init_xilinx_timecounter(void)
 {
-   xilinx_cc.mult = div_sc(timer_clock_freq, NSEC_PER_SEC,
-   xilinx_cc.shift);
+   struct cyclecounter *cc = _tc.cc;
+
+   cc->mult = div_sc(timer_clock_freq, NSEC_PER_SEC, cc->shift);
 
-   timecounter_init(_tc, _cc, sched_clock());
+   timecounter_init(_tc, sched_clock());
 
return 0;
 }
diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 57cb2f0..31543e5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -179,11 +179,6 @@ static u64 arch_counter_read_cc(const struct cyclecounter 
*cc)
.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static struct cyclecounter cyclecounter __ro_after_init = {
-   .read   = arch_counter_read_cc,
-   .mask   = CLOCKSOURCE_MASK(56),
-};
-
 struct ate_acpi_oem_info {
char oem_id[ACPI_OEM_ID_SIZE + 1];
char oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1];
@@ -915,7 +910,10 @@ static u64 arch_counter_get_cntvct_mem(void)
return ((u64) vct_hi << 32) | vct_lo;
 }
 
-static struct arch_timer_kvm_info arch_timer_kvm_info;
+static struct arch_timer_kvm_info arch_timer_kvm_info = {
+   .timecounter.cc.read = arch_counter_read_cc,
+   .timecounter.cc.mask = CLOCKSOURCE_MASK(56),
+};
 
 struct arch_timer_kvm_info 

[PATCH 05/27] amd-xgbe: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update xgbe tstamp_tc
timecounter init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Tom Lendacky <thomas.lenda...@amd.com>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
index 5ea4edf..486437b 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
@@ -228,7 +228,6 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
 {
struct ptp_clock_info *info = >ptp_clock_info;
struct ptp_clock *clock;
-   struct cyclecounter *cc = >tstamp_tc.cc;
u64 dividend;
 
snprintf(info->name, sizeof(info->name), "%s",
@@ -258,12 +257,12 @@ void xgbe_ptp_register(struct xgbe_prv_data *pdata)
pdata->tstamp_addend = div_u64(dividend, pdata->ptpclk_rate);
 
/* Setup the timecounter */
-   cc->read = xgbe_cc_read;
-   cc->mask = CLOCKSOURCE_MASK(64);
-   cc->mult = 1;
-   cc->shift = 0;
-
-   timecounter_init(>tstamp_tc, ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>tstamp_tc,
+  xgbe_cc_read,
+  CLOCKSOURCE_MASK(64),
+  1,
+  0,
+  ktime_to_ns(ktime_get_real()));
 
/* Disable all timestamping to start */
XGMAC_IOWRITE(pdata, MAC_TSCR, 0);
-- 
1.9.1



[PATCH 07/27] fec: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update fec ethernet
timecounter init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Fugang Duan <fugang.d...@nxp.com>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/freescale/fec_ptp.c | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_ptp.c 
b/drivers/net/ethernet/freescale/fec_ptp.c
index b1261d1..1ba7216 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -278,14 +278,13 @@ void fec_ptp_start_cyclecounter(struct net_device *ndev)
writel(FEC_T_CTRL_ENABLE | FEC_T_CTRL_PERIOD_RST,
fep->hwp + FEC_ATIME_CTRL);
 
-   memset(>tc.cc, 0, sizeof(fep->tc.cc));
-   fep->tc.cc.read = fec_ptp_read;
-   fep->tc.cc.mask = CLOCKSOURCE_MASK(31);
-   fep->tc.cc.shift = 31;
-   fep->tc.cc.mult = FEC_CC_MULT;
-
-   /* reset the ns time counter */
-   timecounter_init(>tc, ktime_to_ns(ktime_get_real()));
+   /* Initialize the ns time counter */
+   timecounter_initialize(>tc,
+  fec_ptp_read,
+  CLOCKSOURCE_MASK(31),
+  FEC_CC_MULT,
+  31,
+  ktime_to_ns(ktime_get_real()));
 
spin_unlock_irqrestore(>tmreg_lock, flags);
 }
-- 
1.9.1



[PATCH 08/27] e1000e: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update e1000e timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
Cc: intel-wired-...@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/intel/e1000e/e1000.h  |  4 
 drivers/net/ethernet/intel/e1000e/netdev.c | 31 +-
 2 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h 
b/drivers/net/ethernet/intel/e1000e/e1000.h
index b59f82a..d6b0e59 100644
--- a/drivers/net/ethernet/intel/e1000e/e1000.h
+++ b/drivers/net/ethernet/intel/e1000e/e1000.h
@@ -341,6 +341,10 @@ struct e1000_adapter {
struct work_struct tx_hwtstamp_work;
spinlock_t systim_lock; /* protects SYSTIML/H regsters */
struct timecounter tc;
+   u64 (*cc_read)(const struct cyclecounter *cc);
+   u64 cc_mask;
+   u32 cc_mult;
+   u32 cc_shift;
struct ptp_clock *ptp_clock;
struct ptp_clock_info ptp_clock_info;
struct pm_qos_request pm_qos_req;
diff --git a/drivers/net/ethernet/intel/e1000e/netdev.c 
b/drivers/net/ethernet/intel/e1000e/netdev.c
index c9f7ba3..6be1327 100644
--- a/drivers/net/ethernet/intel/e1000e/netdev.c
+++ b/drivers/net/ethernet/intel/e1000e/netdev.c
@@ -3536,7 +3536,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter 
*adapter, u32 *timinca)
incperiod = INCPERIOD_96MHZ;
incvalue = INCVALUE_96MHZ;
shift = INCVALUE_SHIFT_96MHZ;
-   adapter->tc.cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
+   adapter->cc_shift = shift + INCPERIOD_SHIFT_96MHZ;
break;
case e1000_pch_lpt:
if (er32(TSYNCRXCTL) & E1000_TSYNCRXCTL_SYSCFI) {
@@ -3544,13 +3544,13 @@ s32 e1000e_get_base_timinca(struct e1000_adapter 
*adapter, u32 *timinca)
incperiod = INCPERIOD_96MHZ;
incvalue = INCVALUE_96MHZ;
shift = INCVALUE_SHIFT_96MHZ;
-   adapter->tc.cc.shift = shift + INCPERIOD_SHIFT_96MHZ;
+   adapter->cc_shift = shift + INCPERIOD_SHIFT_96MHZ;
} else {
/* Stable 25MHz frequency */
incperiod = INCPERIOD_25MHZ;
incvalue = INCVALUE_25MHZ;
shift = INCVALUE_SHIFT_25MHZ;
-   adapter->tc.cc.shift = shift;
+   adapter->cc_shift = shift;
}
break;
case e1000_pch_spt:
@@ -3559,7 +3559,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter 
*adapter, u32 *timinca)
incperiod = INCPERIOD_24MHZ;
incvalue = INCVALUE_24MHZ;
shift = INCVALUE_SHIFT_24MHZ;
-   adapter->tc.cc.shift = shift;
+   adapter->cc_shift = shift;
break;
}
return -EINVAL;
@@ -3569,13 +3569,13 @@ s32 e1000e_get_base_timinca(struct e1000_adapter 
*adapter, u32 *timinca)
incperiod = INCPERIOD_24MHZ;
incvalue = INCVALUE_24MHZ;
shift = INCVALUE_SHIFT_24MHZ;
-   adapter->tc.cc.shift = shift;
+   adapter->cc_shift = shift;
} else {
/* Stable 38400KHz frequency */
incperiod = INCPERIOD_38400KHZ;
incvalue = INCVALUE_38400KHZ;
shift = INCVALUE_SHIFT_38400KHZ;
-   adapter->tc.cc.shift = shift;
+   adapter->cc_shift = shift;
}
break;
case e1000_82574:
@@ -3584,7 +3584,7 @@ s32 e1000e_get_base_timinca(struct e1000_adapter 
*adapter, u32 *timinca)
incperiod = INCPERIOD_25MHZ;
incvalue = INCVALUE_25MHZ;
shift = INCVALUE_SHIFT_25MHZ;
-   adapter->tc.cc.shift = shift;
+   adapter->cc_shift = shift;
break;
default:
return -EINVAL;
@@ -3953,9 +3953,14 @@ static void e1000e_systim_reset(struct e1000_adapter 
*adapter)
return;
}
 
-   /* reset the systim ns time counter */
+   /* reinitialize the systim ns time counter */
spin_lock_irqsave(>systim_lock, flags);
-   timecounter_init(>tc, ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>tc,
+  adapter->cc_read,
+  adapter->cc_mask,
+ 

[PATCH 09/27] igb: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update igb ptp timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
Cc: intel-wired-...@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/intel/igb/igb.h |  4 
 drivers/net/ethernet/intel/igb/igb_ptp.c | 23 ++-
 2 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/drivers/net/ethernet/intel/igb/igb.h 
b/drivers/net/ethernet/intel/igb/igb.h
index 4eac4f2..4ef5632 100644
--- a/drivers/net/ethernet/intel/igb/igb.h
+++ b/drivers/net/ethernet/intel/igb/igb.h
@@ -566,6 +566,10 @@ struct igb_adapter {
unsigned int ptp_flags;
spinlock_t tmreg_lock;
struct timecounter tc;
+   u64 (*cc_read)(const struct cyclecounter *cc);
+   u64 cc_mask;
+   u32 cc_mult;
+   u32 cc_shift;
u32 tx_hwtstamp_timeouts;
u32 tx_hwtstamp_skipped;
u32 rx_hwtstamp_cleared;
diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c 
b/drivers/net/ethernet/intel/igb/igb_ptp.c
index 0745eff..f6c1a8d 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -1126,10 +1126,10 @@ void igb_ptp_init(struct igb_adapter *adapter)
adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
adapter->ptp_caps.enable = igb_ptp_feature_enable;
-   adapter->tc.cc.read = igb_ptp_read_82576;
-   adapter->tc.cc.mask = CYCLECOUNTER_MASK(64);
-   adapter->tc.cc.mult = 1;
-   adapter->tc.cc.shift = IGB_82576_TSYNC_SHIFT;
+   adapter->cc_read = igb_ptp_read_82576;
+   adapter->cc_mask = CYCLECOUNTER_MASK(64);
+   adapter->cc_mult = 1;
+   adapter->cc_shift = IGB_82576_TSYNC_SHIFT;
adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
break;
case e1000_82580:
@@ -1145,10 +1145,10 @@ void igb_ptp_init(struct igb_adapter *adapter)
adapter->ptp_caps.gettime64 = igb_ptp_gettime_82576;
adapter->ptp_caps.settime64 = igb_ptp_settime_82576;
adapter->ptp_caps.enable = igb_ptp_feature_enable;
-   adapter->tc.cc.read = igb_ptp_read_82580;
-   adapter->tc.cc.mask = CYCLECOUNTER_MASK(IGB_NBITS_82580);
-   adapter->tc.cc.mult = 1;
-   adapter->tc.cc.shift = 0;
+   adapter->cc_read = igb_ptp_read_82580;
+   adapter->cc_mask = CYCLECOUNTER_MASK(IGB_NBITS_82580);
+   adapter->cc_mult = 1;
+   adapter->cc_shift = 0;
adapter->ptp_flags |= IGB_PTP_OVERFLOW_CHECK;
break;
case e1000_i210:
@@ -1289,7 +1289,12 @@ void igb_ptp_reset(struct igb_adapter *adapter)
 
igb_ptp_write_i210(adapter, );
} else {
-   timecounter_init(>tc, ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>tc,
+  adapter->cc_read,
+  adapter->cc_mask,
+  adapter->cc_mult,
+  adapter->cc_shift,
+  ktime_to_ns(ktime_get_real()));
}
 out:
spin_unlock_irqrestore(>tmreg_lock, flags);
-- 
1.9.1



[PATCH 11/27] net/mlx4: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update mlx4 timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Tariq Toukan <tar...@mellanox.com>
Cc: netdev@vger.kernel.org
Cc: linux-r...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 17 +
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c 
b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index 35987b5..dd736cc 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -264,6 +264,7 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
 {
struct mlx4_dev *dev = mdev->dev;
unsigned long flags;
+   u32 mult, shift;
 
/* mlx4_en_init_timestamp is called for each netdev.
 * mdev->ptp_clock is common for all ports, skip initialization if
@@ -274,17 +275,17 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
 
seqlock_init(>clock_lock);
 
-   memset(>clock.cc, 0, sizeof(mdev->clock.cc));
-   mdev->clock.cc.read = mlx4_en_read_clock;
-   mdev->clock.cc.mask = CLOCKSOURCE_MASK(48);
-   mdev->clock.cc.shift = freq_to_shift(dev->caps.hca_core_clock);
-   mdev->clock.cc.mult =
-   clocksource_khz2mult(1000 * dev->caps.hca_core_clock,
-mdev->clock.cc.shift);
+   shift = freq_to_shift(dev->caps.hca_core_clock);
+   mult = clocksource_khz2mult(1000 * dev->caps.hca_core_clock, shift);
mdev->nominal_c_mult = mdev->clock.cc.mult;
 
write_seqlock_irqsave(>clock_lock, flags);
-   timecounter_init(>clock, ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>clock,
+  mlx4_en_read_clock,
+  CLOCKSOURCE_MASK(48),
+  mult,
+  shift,
+  ktime_to_ns(ktime_get_real()));
write_sequnlock_irqrestore(>clock_lock, flags);
 
/* Configure the PHC */
-- 
1.9.1



[PATCH 12/27] net/mlx5: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update mlx5 timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Saeed Mahameed <sae...@mellanox.com>
Cc: Matan Barak <mat...@mellanox.com>
Cc: Leon Romanovsky <leo...@mellanox.com>
Cc: Eugenia Emantayev <euge...@mellanox.com>
Cc: Eitan Rabin <ra...@mellanox.com>
Cc: Feras Daoud <fera...@mellanox.com>
Cc: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Miroslav Lichvar <mlich...@redhat.com>
Cc: netdev@vger.kernel.org
Cc: linux-r...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 18 +++---
 1 file changed, 11 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c 
b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index 8cb6838..071f78a 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -458,6 +458,7 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
u64 ns;
u64 frac = 0;
u32 dev_freq;
+   u32 mult, shift;
 
dev_freq = MLX5_CAP_GEN(mdev, device_frequency_khz);
if (!dev_freq) {
@@ -465,13 +466,16 @@ void mlx5_init_clock(struct mlx5_core_dev *mdev)
return;
}
rwlock_init(>lock);
-   cc->read = read_internal_timer;
-   cc->shift = MLX5_CYCLES_SHIFT;
-   cc->mult = clocksource_khz2mult(dev_freq, cc->shift);
-   clock->nominal_c_mult = cc->mult;
-   cc->mask = CLOCKSOURCE_MASK(41);
-
-   timecounter_init(>tc, ktime_to_ns(ktime_get_real()));
+   shift = MLX5_CYCLES_SHIFT;
+   mult = clocksource_khz2mult(dev_freq, shift);
+   clock->nominal_c_mult = mult;
+
+   timecounter_initialize(>tc,
+  read_internal_timer,
+  CLOCKSOURCE_MASK(41),
+  mult,
+  shift,
+  ktime_to_ns(ktime_get_real()));
 
/* Calculate period in seconds to call the overflow watchdog - to make
 * sure counter is checked at least once every wrap around.
-- 
1.9.1



[PATCH 10/27] ixgbe: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update ixgbe ptp timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
Cc: intel-wired-...@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h  |  6 +++-
 drivers/net/ethernet/intel/ixgbe/ixgbe_main.c |  4 +--
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c  | 45 +++
 3 files changed, 32 insertions(+), 23 deletions(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe.h 
b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
index 5c391a0..67e8b5c 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe.h
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe.h
@@ -739,6 +739,10 @@ struct ixgbe_adapter {
unsigned long last_rx_timestamp;
spinlock_t tmreg_lock;
struct timecounter hw_tc;
+   u64 (*cc_read)(const struct cyclecounter *cc);
+   u64 cc_mask;
+   u32 cc_mult;
+   u32 cc_shift;
u32 base_incval;
u32 tx_hwtstamp_timeouts;
u32 tx_hwtstamp_skipped;
@@ -994,7 +998,7 @@ static inline void ixgbe_ptp_rx_hwtstamp(struct ixgbe_ring 
*rx_ring,
 
 int ixgbe_ptp_set_ts_config(struct ixgbe_adapter *adapter, struct ifreq *ifr);
 int ixgbe_ptp_get_ts_config(struct ixgbe_adapter *adapter, struct ifreq *ifr);
-void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter);
+void ixgbe_ptp_start_timecounter(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_reset(struct ixgbe_adapter *adapter);
 void ixgbe_ptp_check_pps_event(struct ixgbe_adapter *adapter);
 #ifdef CONFIG_PCI_IOV
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
index 62a1891..86a337b 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
@@ -7332,7 +7332,7 @@ static void ixgbe_watchdog_link_is_up(struct 
ixgbe_adapter *adapter)
adapter->last_rx_ptp_check = jiffies;
 
if (test_bit(__IXGBE_PTP_RUNNING, >state))
-   ixgbe_ptp_start_cyclecounter(adapter);
+   ixgbe_ptp_start_timecounter(adapter);
 
switch (link_speed) {
case IXGBE_LINK_SPEED_10GB_FULL:
@@ -7400,7 +7400,7 @@ static void ixgbe_watchdog_link_is_down(struct 
ixgbe_adapter *adapter)
adapter->flags2 |= IXGBE_FLAG2_SEARCH_FOR_SFP;
 
if (test_bit(__IXGBE_PTP_RUNNING, >state))
-   ixgbe_ptp_start_cyclecounter(adapter);
+   ixgbe_ptp_start_timecounter(adapter);
 
e_info(drv, "NIC Link is Down\n");
netif_carrier_off(netdev);
diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 6e9f2c0..073c1ef 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -1075,7 +1075,8 @@ static void ixgbe_ptp_link_speed_adjust(struct 
ixgbe_adapter *adapter,
 }
 
 /**
- * ixgbe_ptp_start_cyclecounter - create the cycle counter from hw
+ * ixgbe_ptp_start_timecounter - create the cycle counter from hw and
+ *  initialize corresponding timecounter.
  * @adapter: pointer to the adapter structure
  *
  * This function should be called to set the proper values for the TIMINCA
@@ -1084,10 +1085,9 @@ static void ixgbe_ptp_link_speed_adjust(struct 
ixgbe_adapter *adapter,
  * structure. It should be called whenever a new TIMINCA value is necessary,
  * such as during initialization or when the link speed changes.
  */
-void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
+void ixgbe_ptp_start_timecounter(struct ixgbe_adapter *adapter)
 {
struct ixgbe_hw *hw = >hw;
-   struct cyclecounter cc;
unsigned long flags;
u32 incval = 0;
u32 tsauxc = 0;
@@ -1104,9 +1104,9 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter 
*adapter)
 * proper fix to this problem would require modification of the
 * timecounter delta calculations.
 */
-   cc.mask = CLOCKSOURCE_MASK(64);
-   cc.mult = 1;
-   cc.shift = 0;
+   adapter->cc_mask = CLOCKSOURCE_MASK(64);
+   adapter->cc_mult = 1;
+   adapter->cc_shift = 0;
 
switch (hw->mac.type) {
case ixgbe_mac_X550EM_x:
@@ -1118,13 +1118,13 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter 
*adapter)
 */
fuse0 = IXGBE_READ_REG(hw, IXGBE_FUSES0_GROUP(0));
if (!(fuse0 & IXGBE_FUSES0_300MHZ)) {
-   cc.mult = 3;
-   cc.shift = 2;
+   adapter->cc_mult = 3;
+   adapter->cc_shift = 2;
}
/* fallthroug

[PATCH 14/27] net: cpts: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update cpts timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: "David S. Miller" <da...@davemloft.net>
Cc: Grygorii Strashko <grygorii.stras...@ti.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Bhumika Goyal <bhumi...@gmail.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Ivan Khoronzhuk <ivan.khoronz...@linaro.org>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/ti/cpts.c | 29 +
 drivers/net/ethernet/ti/cpts.h |  3 +++
 2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index b8fe843..e6afc94 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -447,7 +447,12 @@ int cpts_register(struct cpts *cpts)
cpts_write32(cpts, CPTS_EN, control);
cpts_write32(cpts, TS_PEND_EN, int_enable);
 
-   timecounter_init(>tc, ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>tc,
+  cpts_systim_read,
+  cpts->mask,
+  cpts->mult,
+  cpts->shift,
+  ktime_to_ns(ktime_get_real()));
 
cpts->clock = ptp_clock_register(>info, cpts->dev);
if (IS_ERR(cpts->clock)) {
@@ -484,7 +489,8 @@ void cpts_unregister(struct cpts *cpts)
 }
 EXPORT_SYMBOL_GPL(cpts_unregister);
 
-static void cpts_calc_mult_shift(struct cpts *cpts)
+static void cpts_calc_mult_shift(struct cpts *cpts, u64 mask,
+u32 *mult, u32 *shift)
 {
struct cyclecounter *cc = >tc.cc;
u64 frac, maxsec, ns;
@@ -495,7 +501,7 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
/* Calc the maximum number of seconds which we can run before
 * wrapping around.
 */
-   maxsec = cc->mask;
+   maxsec = mask;
do_div(maxsec, freq);
/* limit conversation rate to 10 sec as higher values will produce
 * too small mult factors and so reduce the conversion accuracy
@@ -508,18 +514,18 @@ static void cpts_calc_mult_shift(struct cpts *cpts)
dev_info(cpts->dev, "cpts: overflow check period %lu (jiffies)\n",
 cpts->ov_check_period);
 
-   if (cc->mult || cc->shift)
+   if (*mult || *shift)
return;
 
-   clocks_calc_mult_shift(>mult, >shift,
+   clocks_calc_mult_shift(mult, shift,
   freq, NSEC_PER_SEC, maxsec);
 
frac = 0;
-   ns = cyclecounter_cyc2ns(cc, freq, cc->mask, );
+   ns = cyclecounter_cyc2ns(cc, freq, mask, );
 
dev_info(cpts->dev,
 "CPTS: ref_clk_freq:%u calc_mult:%u calc_shift:%u error:%lld 
nsec/sec\n",
-freq, cc->mult, cc->shift,
+freq, *mult, *shift,
 (ns - NSEC_PER_SEC));
 }
 
@@ -571,15 +577,14 @@ struct cpts *cpts_create(struct device *dev, void __iomem 
*regs,
 
clk_prepare(cpts->refclk);
 
-   cpts->tc.cc.read = cpts_systim_read;
-   cpts->tc.cc.mask = CLOCKSOURCE_MASK(32);
+   cpts->mask = CLOCKSOURCE_MASK(32);
cpts->info = cpts_info;
 
-   cpts_calc_mult_shift(cpts);
-   /* save tc.cc.mult original value as it can be modified
+   cpts_calc_mult_shift(cpts, cpts->mask, >mult, >shift);
+   /* save mult original value as it can be modified
 * by cpts_ptp_adjfreq().
 */
-   cpts->cc_mult = cpts->tc.cc.mult;
+   cpts->cc_mult = cpts->mult;
 
return cpts;
 }
diff --git a/drivers/net/ethernet/ti/cpts.h b/drivers/net/ethernet/ti/cpts.h
index a7174eb..da50d34 100644
--- a/drivers/net/ethernet/ti/cpts.h
+++ b/drivers/net/ethernet/ti/cpts.h
@@ -118,6 +118,9 @@ struct cpts {
spinlock_t lock; /* protects time registers */
u32 cc_mult; /* for the nominal frequency */
struct timecounter tc;
+   u64 mask;
+   u32 mult;
+   u32 shift;
int phc_index;
struct clk *refclk;
struct list_head events;
-- 
1.9.1



[PATCH 13/27] qede: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update qede timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Ariel Elior <ariel.el...@cavium.com>
Cc: everest-linux...@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/qlogic/qede/qede_ptp.c | 13 ++---
 1 file changed, 6 insertions(+), 7 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c 
b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 95bb8a8..0d054dc 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -427,13 +427,12 @@ static int qede_ptp_init(struct qede_dev *edev, bool 
init_tc)
 * unload / load (e.g. MTU change) while it is running.
 */
if (init_tc) {
-   memset(>tc.cc, 0, sizeof(ptp->tc.cc));
-   ptp->tc.cc.read = qede_ptp_read_cc;
-   ptp->tc.cc.mask = CYCLECOUNTER_MASK(64);
-   ptp->tc.cc.shift = 0;
-   ptp->tc.cc.mult = 1;
-
-   timecounter_init(>tc, ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>tc,
+  qede_ptp_read_cc,
+  CYCLECOUNTER_MASK(64),
+  1,
+  0,
+  ktime_to_ns(ktime_get_real()));
}
 
return rc;
-- 
1.9.1



[PATCH 18/27] bnx2x: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update bnx2x_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Ariel Elior <ariel.el...@cavium.com>
Cc: everest-linux...@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 1e10a81..e30e736 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -13849,8 +13849,8 @@ static int bnx2x_ptp_settime(struct ptp_clock_info *ptp,
 
DP(BNX2X_MSG_PTP, "PTP settime called, ns = %llu\n", ns);
 
-   /* Re-init the timecounter */
-   timecounter_init(>timecounter, ns);
+   /* Reset the timecounter */
+   timecounter_reset(>timecounter, ns);
 
return 0;
 }
-- 
1.9.1



[PATCH 17/27] amd-xgbe: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update xgbe_config_tstamp and xgbe_settime with this new
function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Tom Lendacky <thomas.lenda...@amd.com>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c | 4 ++--
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c | 2 +-
 2 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
index 5005c87..aee99de 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-dev.c
@@ -1621,8 +1621,8 @@ static int xgbe_config_tstamp(struct xgbe_prv_data *pdata,
xgbe_update_tstamp_addend(pdata, pdata->tstamp_addend);
xgbe_set_tstamp_time(pdata, 0, 0);
 
-   /* Initialize the timecounter */
-   timecounter_init(>tstamp_tc, ktime_to_ns(ktime_get_real()));
+   /* Reset the timecounter */
+   timecounter_reset(>tstamp_tc, ktime_to_ns(ktime_get_real()));
 
return 0;
 }
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
index 486437b..5fcde50 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-ptp.c
@@ -211,7 +211,7 @@ static int xgbe_settime(struct ptp_clock_info *info,
 
spin_lock_irqsave(>tstamp_lock, flags);
 
-   timecounter_init(>tstamp_tc, nsec);
+   timecounter_reset(>tstamp_tc, nsec);
 
spin_unlock_irqrestore(>tstamp_lock, flags);
 
-- 
1.9.1



[PATCH 20/27] e1000e: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update e1000e_phc_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
Cc: intel-wired-...@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/intel/e1000e/ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/e1000e/ptp.c 
b/drivers/net/ethernet/intel/e1000e/ptp.c
index 03d5f2a..5b368aa 100644
--- a/drivers/net/ethernet/intel/e1000e/ptp.c
+++ b/drivers/net/ethernet/intel/e1000e/ptp.c
@@ -222,7 +222,7 @@ static int e1000e_phc_settime(struct ptp_clock_info *ptp,
 
/* reset the timecounter */
spin_lock_irqsave(>systim_lock, flags);
-   timecounter_init(>tc, ns);
+   timecounter_reset(>tc, ns);
spin_unlock_irqrestore(>systim_lock, flags);
 
return 0;
-- 
1.9.1



[PATCH 22/27] ixgbe: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update ixgbe_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
Cc: intel-wired-...@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c 
b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
index 073c1ef..35f85ef 100644
--- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
+++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
@@ -508,7 +508,7 @@ static int ixgbe_ptp_settime(struct ptp_clock_info *ptp,
 
/* reset the timecounter */
spin_lock_irqsave(>tmreg_lock, flags);
-   timecounter_init(>hw_tc, ns);
+   timecounter_reset(>hw_tc, ns);
spin_unlock_irqrestore(>tmreg_lock, flags);
 
if (adapter->ptp_setup_sdp)
-- 
1.9.1



[PATCH 21/27] igb: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update igb_ptp_settime_82576 with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Jeff Kirsher <jeffrey.t.kirs...@intel.com>
Cc: intel-wired-...@lists.osuosl.org
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/intel/igb/igb_ptp.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/intel/igb/igb_ptp.c 
b/drivers/net/ethernet/intel/igb/igb_ptp.c
index f6c1a8d..90344b2 100644
--- a/drivers/net/ethernet/intel/igb/igb_ptp.c
+++ b/drivers/net/ethernet/intel/igb/igb_ptp.c
@@ -330,7 +330,7 @@ static int igb_ptp_settime_82576(struct ptp_clock_info *ptp,
 
spin_lock_irqsave(>tmreg_lock, flags);
 
-   timecounter_init(>tc, ns);
+   timecounter_reset(>tc, ns);
 
spin_unlock_irqrestore(>tmreg_lock, flags);
 
-- 
1.9.1



[PATCH 23/27] net/mlx4: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update mlx4_en_phc_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Tariq Toukan <tar...@mellanox.com>
Cc: netdev@vger.kernel.org
Cc: linux-r...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx4/en_clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c 
b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index dd736cc..bfed4ac 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
@@ -207,7 +207,7 @@ static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
 
/* reset the timecounter */
write_seqlock_irqsave(>clock_lock, flags);
-   timecounter_init(>clock, ns);
+   timecounter_reset(>clock, ns);
write_sequnlock_irqrestore(>clock_lock, flags);
 
return 0;
-- 
1.9.1



[PATCH 19/27] net: fec: ptp: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update fec_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Fugang Duan <fugang.d...@nxp.com>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/freescale/fec_ptp.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/freescale/fec_ptp.c 
b/drivers/net/ethernet/freescale/fec_ptp.c
index 1ba7216..d03ea0e 100644
--- a/drivers/net/ethernet/freescale/fec_ptp.c
+++ b/drivers/net/ethernet/freescale/fec_ptp.c
@@ -419,7 +419,6 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
 {
struct fec_enet_private *fep =
container_of(ptp, struct fec_enet_private, ptp_caps);
-
u64 ns;
unsigned long flags;
u32 counter;
@@ -439,7 +438,7 @@ static int fec_ptp_settime(struct ptp_clock_info *ptp,
 
spin_lock_irqsave(>tmreg_lock, flags);
writel(counter, fep->hwp + FEC_ATIME);
-   timecounter_init(>tc, ns);
+   timecounter_reset(>tc, ns);
spin_unlock_irqrestore(>tmreg_lock, flags);
mutex_unlock(>ptp_clk_mutex);
return 0;
-- 
1.9.1



[PATCH 24/27] net/mlx5: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update mlx5_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Saeed Mahameed <sae...@mellanox.com>
Cc: Matan Barak <mat...@mellanox.com>
Cc: Leon Romanovsky <leo...@mellanox.com>
Cc: Eugenia Emantayev <euge...@mellanox.com>
Cc: Eitan Rabin <ra...@mellanox.com>
Cc: Feras Daoud <fera...@mellanox.com>
Cc: Tariq Toukan <tar...@mellanox.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: netdev@vger.kernel.org
Cc: linux-r...@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c 
b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
index 071f78a..e490522 100644
--- a/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
+++ b/drivers/net/ethernet/mellanox/mlx5/core/lib/clock.c
@@ -122,7 +122,7 @@ static int mlx5_ptp_settime(struct ptp_clock_info *ptp,
unsigned long flags;
 
write_lock_irqsave(>lock, flags);
-   timecounter_init(>tc, ns);
+   timecounter_reset(>tc, ns);
write_unlock_irqrestore(>lock, flags);
 
return 0;
-- 
1.9.1



[PATCH 25/27] qede: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update qede_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Ariel Elior <ariel.el...@cavium.com>
Cc: everest-linux...@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/qlogic/qede/qede_ptp.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ethernet/qlogic/qede/qede_ptp.c 
b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
index 0d054dc..c2de311 100644
--- a/drivers/net/ethernet/qlogic/qede/qede_ptp.c
+++ b/drivers/net/ethernet/qlogic/qede/qede_ptp.c
@@ -129,9 +129,9 @@ static int qede_ptp_settime(struct ptp_clock_info *info,
 
DP_VERBOSE(edev, QED_MSG_DEBUG, "PTP settime called, ns = %llu\n", ns);
 
-   /* Re-init the timecounter */
+   /* Reset the timecounter */
spin_lock_bh(>lock);
-   timecounter_init(>tc, ns);
+   timecounter_reset(>tc, ns);
spin_unlock_bh(>lock);
 
return 0;
-- 
1.9.1



[PATCH 26/27] net: cpts: Use timecounter_reset interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_reset we can update the start time for
timecounter. Update cpts_ptp_settime with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: "David S. Miller" <da...@davemloft.net>
Cc: Grygorii Strashko <grygorii.stras...@ti.com>
Cc: Bhumika Goyal <bhumi...@gmail.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/ti/cpts.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/ti/cpts.c b/drivers/net/ethernet/ti/cpts.c
index e6afc94..41bac4d 100644
--- a/drivers/net/ethernet/ti/cpts.c
+++ b/drivers/net/ethernet/ti/cpts.c
@@ -268,7 +268,7 @@ static int cpts_ptp_settime(struct ptp_clock_info *ptp,
ns = timespec64_to_ns(ts);
 
spin_lock_irqsave(>lock, flags);
-   timecounter_init(>tc, ns);
+   timecounter_reset(>tc, ns);
spin_unlock_irqrestore(>lock, flags);
 
return 0;
-- 
1.9.1



[PATCH 06/27] bnx2x: Use timecounter_initialize interface

2017-12-14 Thread Sagar Arun Kamble
With new interface timecounter_initialize we can initialize timecounter
fields and underlying cyclecounter together. Update bnx2x timecounter
init with this new function.

Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: Ariel Elior <ariel.el...@cavium.com>
Cc: everest-linux...@cavium.com
Cc: netdev@vger.kernel.org
Cc: linux-ker...@vger.kernel.org
---
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c | 18 ++
 1 file changed, 6 insertions(+), 12 deletions(-)

diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c 
b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
index 83624ad..1e10a81 100644
--- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
+++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c
@@ -15269,15 +15269,6 @@ static u64 bnx2x_cyclecounter_read(const struct 
cyclecounter *cc)
return phc_cycles;
 }
 
-static void bnx2x_init_cyclecounter(struct cyclecounter *cc)
-{
-   memset(cc, 0, sizeof(*cc));
-   cc->read = bnx2x_cyclecounter_read;
-   cc->mask = CYCLECOUNTER_MASK(64);
-   cc->shift = 0;
-   cc->mult = 1;
-}
-
 static int bnx2x_send_reset_timesync_ramrod(struct bnx2x *bp)
 {
struct bnx2x_func_state_params func_params = {NULL};
@@ -15511,9 +15502,12 @@ void bnx2x_init_ptp(struct bnx2x *bp)
 * unload / load (e.g. MTU change) while it is running.
 */
if (!bp->timecounter_init_done) {
-   bnx2x_init_cyclecounter(>timecounter.cc);
-   timecounter_init(>timecounter,
-ktime_to_ns(ktime_get_real()));
+   timecounter_initialize(>timecounter,
+  bnx2x_cyclecounter_read,
+  CYCLECOUNTER_MASK(64),
+  1,
+  0,
+  ktime_to_ns(ktime_get_real()));
bp->timecounter_init_done = 1;
}
 
-- 
1.9.1



Re: [PATCH 1/1] timecounter: Make cyclecounter struct part of timecounter struct

2017-12-03 Thread Sagar Arun Kamble



On 12/2/2017 11:34 PM, Richard Cochran wrote:

On Sat, Dec 02, 2017 at 10:01:35AM +0530, Sagar Arun Kamble wrote:

There is no real need for the users of timecounters to define cyclecounter
and timecounter variables separately. Since timecounter will always be
based on cyclecounter, have cyclecounter struct as member of timecounter
struct.

Overall, this is a welcome change.  However, it doesn't go far enough,
IMHO, and I'll explain that more below.


diff --git a/drivers/net/ethernet/mellanox/mlx4/en_clock.c 
b/drivers/net/ethernet/mellanox/mlx4/en_clock.c
index 0247885..35987b5 100644
--- a/drivers/net/ethernet/mellanox/mlx4/en_clock.c
+++ b/drivers/net/ethernet/mellanox/mlx4/en_clock.c

...

As it stands now, timecounter_init() is used for two totally different
reasons.  Some callers only want to set the time, ...


@@ -207,7 +207,7 @@ static int mlx4_en_phc_settime(struct ptp_clock_info *ptp,
  
  	/* reset the timecounter */

write_seqlock_irqsave(>clock_lock, flags);
-   timecounter_init(>clock, >cycles, ns);
+   timecounter_init(>clock, ns);
write_sequnlock_irqrestore(>clock_lock, flags);
  
  	return 0;

... while others initialize the data structure the first time:


@@ -274,17 +274,17 @@ void mlx4_en_init_timestamp(struct mlx4_en_dev *mdev)
  
  	seqlock_init(>clock_lock);
  
-	memset(>cycles, 0, sizeof(mdev->cycles));

-   mdev->cycles.read = mlx4_en_read_clock;
-   mdev->cycles.mask = CLOCKSOURCE_MASK(48);
-   mdev->cycles.shift = freq_to_shift(dev->caps.hca_core_clock);
-   mdev->cycles.mult =
-   clocksource_khz2mult(1000 * dev->caps.hca_core_clock, 
mdev->cycles.shift);
-   mdev->nominal_c_mult = mdev->cycles.mult;
+   memset(>clock.cc, 0, sizeof(mdev->clock.cc));
+   mdev->clock.cc.read = mlx4_en_read_clock;
+   mdev->clock.cc.mask = CLOCKSOURCE_MASK(48);
+   mdev->clock.cc.shift = freq_to_shift(dev->caps.hca_core_clock);
+   mdev->clock.cc.mult =
+   clocksource_khz2mult(1000 * dev->caps.hca_core_clock,
+mdev->clock.cc.shift);
+   mdev->nominal_c_mult = mdev->clock.cc.mult;
  
  	write_seqlock_irqsave(>clock_lock, flags);

-   timecounter_init(>clock, >cycles,
-ktime_to_ns(ktime_get_real()));
+   timecounter_init(>clock, ktime_to_ns(ktime_get_real()));

I'd like to see two followup patches to this one:

1. Convert timecounter_init() callers to a new timecounter_reset()
function where the intent is to reset the time.

2. Change timecounter_init() to take the cyclecounter fields as
arguments.

void timecounter_init(struct timecounter *tc,
  u64 (*read)(const struct cyclecounter *cc),
  u64 mask,
  u32 mult,
  u32 shift,
  u64 start_tstamp);

Then we can clean up all this stuff:

mdev->clock.cc.read = mlx4_en_read_clock;
mdev->clock.cc.mask = CLOCKSOURCE_MASK(48);
mdev->clock.cc.shift = freq_to_shift(dev->caps.hca_core_clock);
mdev->clock.cc.mult = clocksource_khz2mult(...);

This second step can be phased in by calling the new function
timecounter_initialize() and converting the drivers one by one.


Yes. Will make these changes and share new patchset.

Thank you for the review Richard.

Regards,
Sagar


diff --git a/include/linux/timecounter.h b/include/linux/timecounter.h
index 2496ad4..6daca06 100644
--- a/include/linux/timecounter.h
+++ b/include/linux/timecounter.h

...

@@ -98,7 +98,6 @@ static inline void timecounter_adjtime(struct timecounter 
*tc, s64 delta)
  /**
   * timecounter_init - initialize a time counter
   * @tc:   Pointer to time counter which is to be 
initialized/reset
- * @cc:A cycle counter, ready to be used.

This "ready to used" requirement should go.  The init() function
should make the instance ready to be used all at once.

Thanks,
Richard




[PATCH 1/1] timecounter: Make cyclecounter struct part of timecounter struct

2017-12-01 Thread Sagar Arun Kamble
There is no real need for the users of timecounters to define cyclecounter
and timecounter variables separately. Since timecounter will always be
based on cyclecounter, have cyclecounter struct as member of timecounter
struct.

Suggested-by: Chris Wilson <ch...@chris-wilson.co.uk>
Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: Richard Cochran <richardcoch...@gmail.com>
Cc: John Stultz <john.stu...@linaro.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Stephen Boyd <sb...@codeaurora.org>
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: netdev@vger.kernel.org
Cc: intel-wired-...@lists.osuosl.org
Cc: linux-r...@vger.kernel.org
Cc: alsa-de...@alsa-project.org
Cc: kvm...@lists.cs.columbia.edu
---
 arch/microblaze/kernel/timer.c | 20 ++--
 drivers/clocksource/arm_arch_timer.c   | 19 ++--
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c   |  3 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c   |  9 +++---
 drivers/net/ethernet/amd/xgbe/xgbe.h   |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h|  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++--
 drivers/net/ethernet/freescale/fec.h   |  1 -
 drivers/net/ethernet/freescale/fec_ptp.c   | 30 +-
 drivers/net/ethernet/intel/e1000e/e1000.h  |  1 -
 drivers/net/ethernet/intel/e1000e/netdev.c | 27 
 drivers/net/ethernet/intel/e1000e/ptp.c|  2 +-
 drivers/net/ethernet/intel/igb/igb.h   |  1 -
 drivers/net/ethernet/intel/igb/igb_ptp.c   | 25 ---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h   |  1 -
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c   | 17 +-
 drivers/net/ethernet/mellanox/mlx4/en_clock.c  | 28 -
 drivers/net/ethernet/mellanox/mlx4/mlx4_en.h   |  1 -
 .../net/ethernet/mellanox/mlx5/core/lib/clock.c| 34 ++--
 drivers/net/ethernet/qlogic/qede/qede_ptp.c| 20 ++--
 drivers/net/ethernet/ti/cpts.c | 36 --
 drivers/net/ethernet/ti/cpts.h |  1 -
 include/linux/mlx5/driver.h|  1 -
 include/linux/timecounter.h|  4 +--
 include/sound/hdaudio.h|  1 -
 kernel/time/timecounter.c  | 28 -
 sound/hda/hdac_stream.c|  7 +++--
 virt/kvm/arm/arch_timer.c  |  6 ++--
 28 files changed, 163 insertions(+), 182 deletions(-)

diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
index 7de941c..b7f89e9 100644
--- a/arch/microblaze/kernel/timer.c
+++ b/arch/microblaze/kernel/timer.c
@@ -199,27 +199,25 @@ static u64 xilinx_read(struct clocksource *cs)
return (u64)xilinx_clock_read();
 }
 
-static struct timecounter xilinx_tc = {
-   .cc = NULL,
-};
-
 static u64 xilinx_cc_read(const struct cyclecounter *cc)
 {
return xilinx_read(NULL);
 }
 
-static struct cyclecounter xilinx_cc = {
-   .read = xilinx_cc_read,
-   .mask = CLOCKSOURCE_MASK(32),
-   .shift = 8,
+static struct timecounter xilinx_tc = {
+   .cc.read = xilinx_cc_read,
+   .cc.mask = CLOCKSOURCE_MASK(32),
+   .cc.mult = 0,
+   .cc.shift = 8,
 };
 
 static int __init init_xilinx_timecounter(void)
 {
-   xilinx_cc.mult = div_sc(timer_clock_freq, NSEC_PER_SEC,
-   xilinx_cc.shift);
+   struct cyclecounter *cc = _tc.cc;
+
+   cc->mult = div_sc(timer_clock_freq, NSEC_PER_SEC, cc->shift);
 
-   timecounter_init(_tc, _cc, sched_clock());
+   timecounter_init(_tc, sched_clock());
 
return 0;
 }
diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 57cb2f0..31543e5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -179,11 +179,6 @@ static u64 arch_counter_read_cc(const struct cyclecounter 
*cc)
.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static struct cyclecounter cyclecounter __ro_after_init = {
-   .read   = arch_counter_read_cc,
-   .mask   = CLOCKSOURCE_MASK(56),
-};
-
 struct ate_acpi_oem_info {
char oem_id[ACPI_OEM_ID_SIZE + 1];
char oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1];
@@ -915,7 +910,10 @@ static u64 arch_counter_get_cntvct_mem(void)
return ((u64) vct_hi << 32) | vct_lo;
 }
 
-static struct arch_timer_kvm_info arch_timer_kvm_info;
+static struct arch_timer_kvm_info arch_timer_kvm_info = {
+   .timecounter.cc.read = arch_counter_read_cc,
+   .timecounter.cc.mask = CLOCKSOURCE_MASK(56),
+};
 
 struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 {
@@ -925,6 +923,7 @@ struct arch_timer_kvm_info *arch_timer_get_kv

[PATCH 1/1] timecounter: Make cyclecounter struct part of timecounter struct

2017-11-30 Thread Sagar Arun Kamble
There is no real need for the users of timecounters to define cyclecounter
and timecounter variables separately. Since timecounter will always be
based on cyclecounter, have cyclecounter struct as member of timecounter
struct.

Suggested-by: Chris Wilson <ch...@chris-wilson.co.uk>
Signed-off-by: Sagar Arun Kamble <sagar.a.kam...@intel.com>
Cc: Chris Wilson <ch...@chris-wilson.co.uk>
Cc: John Stultz <john.stu...@linaro.org>
Cc: Thomas Gleixner <t...@linutronix.de>
Cc: Stephen Boyd <sb...@codeaurora.org>
Cc: linux-ker...@vger.kernel.org
Cc: linux-arm-ker...@lists.infradead.org
Cc: netdev@vger.kernel.org
Cc: intel-wired-...@lists.osuosl.org
Cc: linux-r...@vger.kernel.org
Cc: alsa-de...@alsa-project.org
Cc: kvm...@lists.cs.columbia.edu
---
 arch/microblaze/kernel/timer.c | 20 ++--
 drivers/clocksource/arm_arch_timer.c   | 19 ++--
 drivers/net/ethernet/amd/xgbe/xgbe-dev.c   |  3 +-
 drivers/net/ethernet/amd/xgbe/xgbe-ptp.c   |  9 +++---
 drivers/net/ethernet/amd/xgbe/xgbe.h   |  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x.h|  1 -
 drivers/net/ethernet/broadcom/bnx2x/bnx2x_main.c   | 20 ++--
 drivers/net/ethernet/freescale/fec.h   |  1 -
 drivers/net/ethernet/freescale/fec_ptp.c   | 30 +-
 drivers/net/ethernet/intel/e1000e/e1000.h  |  1 -
 drivers/net/ethernet/intel/e1000e/netdev.c | 27 
 drivers/net/ethernet/intel/e1000e/ptp.c|  2 +-
 drivers/net/ethernet/intel/igb/igb.h   |  1 -
 drivers/net/ethernet/intel/igb/igb_ptp.c   | 25 ---
 drivers/net/ethernet/intel/ixgbe/ixgbe.h   |  1 -
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c   | 17 +-
 drivers/net/ethernet/mellanox/mlx4/en_clock.c  | 28 -
 drivers/net/ethernet/mellanox/mlx4/mlx4_en.h   |  1 -
 .../net/ethernet/mellanox/mlx5/core/lib/clock.c| 34 ++--
 drivers/net/ethernet/qlogic/qede/qede_ptp.c| 20 ++--
 drivers/net/ethernet/ti/cpts.c | 36 --
 drivers/net/ethernet/ti/cpts.h |  1 -
 include/linux/mlx5/driver.h|  1 -
 include/linux/timecounter.h|  4 +--
 include/sound/hdaudio.h|  1 -
 kernel/time/timecounter.c  | 28 -
 sound/hda/hdac_stream.c|  7 +++--
 virt/kvm/arm/arch_timer.c  |  6 ++--
 28 files changed, 163 insertions(+), 182 deletions(-)

diff --git a/arch/microblaze/kernel/timer.c b/arch/microblaze/kernel/timer.c
index 7de941c..b7f89e9 100644
--- a/arch/microblaze/kernel/timer.c
+++ b/arch/microblaze/kernel/timer.c
@@ -199,27 +199,25 @@ static u64 xilinx_read(struct clocksource *cs)
return (u64)xilinx_clock_read();
 }
 
-static struct timecounter xilinx_tc = {
-   .cc = NULL,
-};
-
 static u64 xilinx_cc_read(const struct cyclecounter *cc)
 {
return xilinx_read(NULL);
 }
 
-static struct cyclecounter xilinx_cc = {
-   .read = xilinx_cc_read,
-   .mask = CLOCKSOURCE_MASK(32),
-   .shift = 8,
+static struct timecounter xilinx_tc = {
+   .cc.read = xilinx_cc_read,
+   .cc.mask = CLOCKSOURCE_MASK(32),
+   .cc.mult = 0,
+   .cc.shift = 8,
 };
 
 static int __init init_xilinx_timecounter(void)
 {
-   xilinx_cc.mult = div_sc(timer_clock_freq, NSEC_PER_SEC,
-   xilinx_cc.shift);
+   struct cyclecounter *cc = _tc.cc;
+
+   cc->mult = div_sc(timer_clock_freq, NSEC_PER_SEC, cc->shift);
 
-   timecounter_init(_tc, _cc, sched_clock());
+   timecounter_init(_tc, sched_clock());
 
return 0;
 }
diff --git a/drivers/clocksource/arm_arch_timer.c 
b/drivers/clocksource/arm_arch_timer.c
index 57cb2f0..31543e5 100644
--- a/drivers/clocksource/arm_arch_timer.c
+++ b/drivers/clocksource/arm_arch_timer.c
@@ -179,11 +179,6 @@ static u64 arch_counter_read_cc(const struct cyclecounter 
*cc)
.flags  = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static struct cyclecounter cyclecounter __ro_after_init = {
-   .read   = arch_counter_read_cc,
-   .mask   = CLOCKSOURCE_MASK(56),
-};
-
 struct ate_acpi_oem_info {
char oem_id[ACPI_OEM_ID_SIZE + 1];
char oem_table_id[ACPI_OEM_TABLE_ID_SIZE + 1];
@@ -915,7 +910,10 @@ static u64 arch_counter_get_cntvct_mem(void)
return ((u64) vct_hi << 32) | vct_lo;
 }
 
-static struct arch_timer_kvm_info arch_timer_kvm_info;
+static struct arch_timer_kvm_info arch_timer_kvm_info = {
+   .timecounter.cc.read = arch_counter_read_cc,
+   .timecounter.cc.mask = CLOCKSOURCE_MASK(56),
+};
 
 struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 {
@@ -925,6 +923,7 @@ struct arch_timer_kvm_info *arch_timer_get_kvm_info(void)
 static void __init arch_counter_re

Re: Creating cyclecounter and lock member in timecounter structure [ Was Re: [RFC 1/4] drm/i915/perf: Add support to correlate GPU timestamp with system time]

2017-11-30 Thread Sagar Arun Kamble



On 12/1/2017 2:33 AM, Saeed Mahameed wrote:

On Mon, Nov 27, 2017 at 2:05 AM, Sagar Arun Kamble
<sagar.a.kam...@intel.com> wrote:


On 11/24/2017 7:01 PM, Thomas Gleixner wrote:

On Fri, 24 Nov 2017, Sagar Arun Kamble wrote:

On 11/24/2017 12:29 AM, Thomas Gleixner wrote:

On Thu, 23 Nov 2017, Sagar Arun Kamble wrote:

We needed inputs on possible optimization that can be done to
timecounter/cyclecounter structures/usage.
This mail is in response to review of patch
https://patchwork.freedesktop.org/patch/188448/.

As Chris's observation below, about dozen of timecounter users in the
kernel
have below structures
defined individually:

spinlock_t lock;
struct cyclecounter cc;
struct timecounter tc;

Can we move lock and cc to tc? That way it will be convenient.
Also it will allow unifying the locking/overflow watchdog handling
across
all
drivers.

Looks like none of the timecounter usage sites has a real need to
separate
timecounter and cyclecounter.

Yes. Will share patch for this change.


The lock is a different question. The locking of the various drivers
differs and I have no idea how you want to handle that. Just sticking
the
lock into the datastructure and then not making use of it in the
timercounter code and leave it to the callsites does not make sense.

Most of the locks are held around timecounter_read. In some instances it
is held when cyclecounter is updated standalone or is updated along with
timecounter calls.  Was thinking if we move the lock in timecounter
functions, drivers just have to do locking around its operations on
cyclecounter. But then another problem I see is there are variation of
locking calls like lock_irqsave, lock_bh, write_lock_irqsave (some using
rwlock_t). Should this all locking be left to driver only then?

You could have the lock in the struct and protect the inner workings in
the
related core functions.

That might remove locking requirements from some of the callers and the
others still have their own thing around it.


For drivers having static/fixed cyclecounter, we can rely only on lock
inside timecounter.
Most of the network drivers update cyclecounter at runtime and they will
have to rely on two locks if
we add one to timecounter. This may not be efficient for them. Also the lock
in timecounter has to be less restrictive (may be seqlock) I guess.

Cc'd Mellanox list for inputs on this.

I have started feeling that the current approach of drivers managing the
locks is the right one so better leave the
lock out of timecounter.


I agree here,

In mlx5 we rely on our own read/write lock to serialize access to
mlx5_clock struct (mlx5 timecounter and cyclecounter).
the access is not as simple as
lock()
call time_counter_API
unlock()

Sometimes we also explicitly update/adjust timecycles counters with
mlx5 specific calculations after we read the timecounter all inside
our lock.
e.g.
@mlx5_ptp_adjfreq()

 write_lock_irqsave(>lock, flags);
 timecounter_read(>tc);
 clock->cycles.mult = neg_adj ? clock->nominal_c_mult - diff :
clock->nominal_c_mult + diff;
 write_unlock_irqrestore(>lock, flags);

So i don't think it will be a simple task to have a generic thread
safe timecounter API, without the need to specifically adjust it for
all driver use-cases.
Also as said above, in runtime it is not obvious in which context the
timecounter will be accessed irq/soft irq/user.

let's keep it as is, and let the driver decide which locking scheme is
most suitable for it.


Yes. Thanks for your inputs Saeed.

Regards
Sagar



Thanks,
Saeed.


Thanks,

 tglx


--
To unsubscribe from this list: send the line "unsubscribe linux-rdma" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html




Re: Creating cyclecounter and lock member in timecounter structure [ Was Re: [RFC 1/4] drm/i915/perf: Add support to correlate GPU timestamp with system time]

2017-11-27 Thread Sagar Arun Kamble



On 11/24/2017 7:01 PM, Thomas Gleixner wrote:

On Fri, 24 Nov 2017, Sagar Arun Kamble wrote:

On 11/24/2017 12:29 AM, Thomas Gleixner wrote:

On Thu, 23 Nov 2017, Sagar Arun Kamble wrote:

We needed inputs on possible optimization that can be done to
timecounter/cyclecounter structures/usage.
This mail is in response to review of patch
https://patchwork.freedesktop.org/patch/188448/.

As Chris's observation below, about dozen of timecounter users in the
kernel
have below structures
defined individually:

spinlock_t lock;
struct cyclecounter cc;
struct timecounter tc;

Can we move lock and cc to tc? That way it will be convenient.
Also it will allow unifying the locking/overflow watchdog handling across
all
drivers.

Looks like none of the timecounter usage sites has a real need to separate
timecounter and cyclecounter.

Yes. Will share patch for this change.


The lock is a different question. The locking of the various drivers
differs and I have no idea how you want to handle that. Just sticking the
lock into the datastructure and then not making use of it in the
timercounter code and leave it to the callsites does not make sense.

Most of the locks are held around timecounter_read. In some instances it
is held when cyclecounter is updated standalone or is updated along with
timecounter calls.  Was thinking if we move the lock in timecounter
functions, drivers just have to do locking around its operations on
cyclecounter. But then another problem I see is there are variation of
locking calls like lock_irqsave, lock_bh, write_lock_irqsave (some using
rwlock_t). Should this all locking be left to driver only then?

You could have the lock in the struct and protect the inner workings in the
related core functions.

That might remove locking requirements from some of the callers and the
others still have their own thing around it.


For drivers having static/fixed cyclecounter, we can rely only on lock inside 
timecounter.
Most of the network drivers update cyclecounter at runtime and they will have 
to rely on two locks if
we add one to timecounter. This may not be efficient for them. Also the lock in 
timecounter has to be less restrictive (may be seqlock) I guess.

Cc'd Mellanox list for inputs on this.

I have started feeling that the current approach of drivers managing the locks 
is the right one so better leave the
lock out of timecounter.


Thanks,

tglx