[PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-20 Thread Nicolas Pitre
In order to break the hard dependency between the PTP clock subsystem and
ethernet drivers capable of being clock providers, this patch provides
simple PTP stub functions to allow linkage of those drivers into the
kernel even when the PTP subsystem is configured out.

And to make it possible for PTP to be configured out, the select statement
in the Kconfig entry for those ethernet drivers is changed from selecting
PTP_1588_CLOCK to PTP_1588_CLOCK_SELECTED whose purpose is to indicate the
default Kconfig value for the PTP subsystem.

This way the PTP subsystem may have Kconfig dependencies of its own, such
as POSIX_TIMERS, without making those ethernet drivers unavailable if
POSIX timers are cconfigured out. And when support for POSIX timers is
selected again then PTP clock support will also be selected accordingly.

Drivers must be ready to accept NULL from ptp_clock_register().
The pch_gbe driver is a bit special as it relies on extra code in
drivers/ptp/ptp_pch.c. Therefore we let the make process descend into
drivers/ptp/ even if PTP_1588_CLOCK is unselected.

Signed-off-by: Nicolas Pitre 
Acked-by: Richard Cochran 
Reviewed-by: Eugenia Emantayev 
---
 drivers/Makefile   |  2 +-
 drivers/net/ethernet/adi/Kconfig   |  8 ++-
 drivers/net/ethernet/amd/Kconfig   |  2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-main.c  |  6 +-
 drivers/net/ethernet/broadcom/Kconfig  |  4 +-
 drivers/net/ethernet/cavium/Kconfig|  2 +-
 drivers/net/ethernet/freescale/Kconfig |  2 +-
 drivers/net/ethernet/intel/Kconfig | 10 ++--
 drivers/net/ethernet/intel/e1000e/ptp.c|  2 +-
 drivers/net/ethernet/intel/i40e/i40e_ptp.c |  2 +-
 drivers/net/ethernet/intel/igb/igb_ptp.c   |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c   |  2 +-
 drivers/net/ethernet/mellanox/mlx4/Kconfig |  2 +-
 drivers/net/ethernet/mellanox/mlx4/en_clock.c  |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/Kconfig|  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_clock.c |  2 +-
 drivers/net/ethernet/renesas/Kconfig   |  2 +-
 drivers/net/ethernet/samsung/Kconfig   |  2 +-
 drivers/net/ethernet/sfc/Kconfig   |  2 +-
 drivers/net/ethernet/sfc/ptp.c | 14 ++---
 drivers/net/ethernet/stmicro/stmmac/Kconfig|  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c   |  2 +-
 drivers/net/ethernet/ti/Kconfig|  2 +-
 drivers/net/ethernet/tile/Kconfig  |  2 +-
 drivers/ptp/Kconfig| 12 ++--
 include/linux/ptp_clock_kernel.h   | 64 --
 26 files changed, 97 insertions(+), 59 deletions(-)

diff --git a/drivers/Makefile b/drivers/Makefile
index 53abb4a5f7..8a538d0856 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -105,7 +105,7 @@ obj-$(CONFIG_INPUT) += input/
 obj-$(CONFIG_RTC_LIB)  += rtc/
 obj-y  += i2c/ media/
 obj-$(CONFIG_PPS)  += pps/
-obj-$(CONFIG_PTP_1588_CLOCK)   += ptp/
+obj-y  += ptp/
 obj-$(CONFIG_W1)   += w1/
 obj-y  += power/
 obj-$(CONFIG_HWMON)+= hwmon/
diff --git a/drivers/net/ethernet/adi/Kconfig b/drivers/net/ethernet/adi/Kconfig
index 6b94ba6103..67094a9cfe 100644
--- a/drivers/net/ethernet/adi/Kconfig
+++ b/drivers/net/ethernet/adi/Kconfig
@@ -55,10 +55,14 @@ config BFIN_RX_DESC_NUM
---help---
  Set the number of buffer packets used in driver.
 
+config BFIN_MAC_HAS_HWSTAMP
+   def_tristate BFIN_MAC
+   depends on BF518
+   select PTP_1588_CLOCK_SELECTED
+
 config BFIN_MAC_USE_HWSTAMP
bool "Use IEEE 1588 hwstamp"
-   depends on BFIN_MAC && BF518
-   select PTP_1588_CLOCK
+   depends on BFIN_MAC_HAS_HWSTAMP && PTP_1588_CLOCK
default y
---help---
  To support the IEEE 1588 Precision Time Protocol (PTP), select y here
diff --git a/drivers/net/ethernet/amd/Kconfig b/drivers/net/ethernet/amd/Kconfig
index 0038709fd3..327e71a554 100644
--- a/drivers/net/ethernet/amd/Kconfig
+++ b/drivers/net/ethernet/amd/Kconfig
@@ -177,7 +177,7 @@ config AMD_XGBE
depends on ARM64 || COMPILE_TEST
select BITREVERSE
select CRC32
-   select PTP_1588_CLOCK
+   select PTP_1588_CLOCK_SELECTED
---help---
  This driver supports the AMD 10GbE Ethernet device found on an
  AMD SoC.
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
index 3eee3201b5..4aeeb018b6 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
@@ -773,7 +773,8 @@ static int xgbe_probe(struct platform_device *pdev)
goto err_wq;
}
 
-   

Re: [PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-19 Thread Nicolas Pitre
On Mon, 19 Sep 2016, Josh Triplett wrote:

> But it does seem unfortunate that this can't happen at build time via
> Kconfig.  CCing linux-kbuild in case someone has an idea for how to fix
> this.

I hoped something like this could work:

config FOO
prompt "Blah-blah"
tristate if (BAR != y)
bool if (BAR = y)
default BAR

This way FOO could be y, m or n when BAR is m or n, otherwise FOO could 
be y or n only.

But that didn't work.


Nicolas


Re: [PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-19 Thread Josh Triplett
On Mon, Sep 19, 2016 at 07:04:15PM +0200, Jiri Benc wrote:
> On Mon, 19 Sep 2016 10:10:21 -0400 (EDT), Nicolas Pitre wrote:
> > --- a/include/linux/ptp_clock_kernel.h
> > +++ b/include/linux/ptp_clock_kernel.h
> > @@ -207,7 +207,16 @@ int ptp_find_pin(struct ptp_clock *ptp,
> >  #else
> >  static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info 
> > *info,
> >struct device *parent)
> > -{ return NULL; }
> > +{
> > +   if (IS_MODULE(CONFIG_PTP_1588_CLOCK)) {
> > +   pr_warn("%s is built-in while PTP clock subsystem is modular, "
> > +   "PTP clock ignored\n", KBUILD_MODNAME);
> > +   } else {
> > +   pr_warn("ignoring PTP clock from %s as PTP clock subsystem "
> > +   "is configured out\n", KBUILD_MODNAME);
> > +   }
> > +   return NULL;
> > +}
> 
> I think the else part is not needed. If PTP is disabled, it is
> disabled, nobody should be surprised by that. Looks good otherwise.

This works, and it should compile away to nothing in the normal case.
But it does seem unfortunate that this can't happen at build time via
Kconfig.  CCing linux-kbuild in case someone has an idea for how to fix
this.


Re: [PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-19 Thread Jiri Benc
On Mon, 19 Sep 2016 10:10:21 -0400 (EDT), Nicolas Pitre wrote:
> --- a/include/linux/ptp_clock_kernel.h
> +++ b/include/linux/ptp_clock_kernel.h
> @@ -207,7 +207,16 @@ int ptp_find_pin(struct ptp_clock *ptp,
>  #else
>  static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info 
> *info,
>  struct device *parent)
> -{ return NULL; }
> +{
> + if (IS_MODULE(CONFIG_PTP_1588_CLOCK)) {
> + pr_warn("%s is built-in while PTP clock subsystem is modular, "
> + "PTP clock ignored\n", KBUILD_MODNAME);
> + } else {
> + pr_warn("ignoring PTP clock from %s as PTP clock subsystem "
> + "is configured out\n", KBUILD_MODNAME);
> + }
> + return NULL;
> +}

I think the else part is not needed. If PTP is disabled, it is
disabled, nobody should be surprised by that. Looks good otherwise.

Thanks,

 Jiri


Re: [PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-19 Thread Nicolas Pitre
On Mon, 19 Sep 2016, Jiri Benc wrote:

> On Sun, 18 Sep 2016 23:51:09 -0400, Nicolas Pitre wrote:
> > And to make it possible for PTP to be configured out, the select statement
> > in the Kconfig entry for those ethernet drivers is changed from selecting
> > PTP_1588_CLOCK to PTP_1588_CLOCK_SELECTED whose purpose is to indicate the
> > default Kconfig value for the PTP subsystem.
> 
> With this patch applied, the user is free to set a NIC driver as built
> in and PTP_1588_CLOCK as a module, right? If so, that would lead to
> non-functional PTP without any warning due to the use of IS_REACHABLE.
> That doesn't sound right. Could easily cause hours of headache to
> someone.
> 
> Or is this handled somehow?

I don't see how to remove the ability to select m for PTP_1588_CLOCK 
based on (PTP_1588_CLOCK_SELECTED = y).

What about this on top then:

diff --git a/include/linux/ptp_clock_kernel.h b/include/linux/ptp_clock_kernel.h
index 4c29eb8e53..74079b2fcf 100644
--- a/include/linux/ptp_clock_kernel.h
+++ b/include/linux/ptp_clock_kernel.h
@@ -207,7 +207,16 @@ int ptp_find_pin(struct ptp_clock *ptp,
 #else
 static inline struct ptp_clock *ptp_clock_register(struct ptp_clock_info *info,
   struct device *parent)
-{ return NULL; }
+{
+   if (IS_MODULE(CONFIG_PTP_1588_CLOCK)) {
+   pr_warn("%s is built-in while PTP clock subsystem is modular, "
+   "PTP clock ignored\n", KBUILD_MODNAME);
+   } else {
+   pr_warn("ignoring PTP clock from %s as PTP clock subsystem "
+   "is configured out\n", KBUILD_MODNAME);
+   }
+   return NULL;
+}
 static inline int ptp_clock_unregister(struct ptp_clock *ptp)
 { return 0; }
 static inline void ptp_clock_event(struct ptp_clock *ptp,


Re: [PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-19 Thread Jiri Benc
On Sun, 18 Sep 2016 23:51:09 -0400, Nicolas Pitre wrote:
> And to make it possible for PTP to be configured out, the select statement
> in the Kconfig entry for those ethernet drivers is changed from selecting
> PTP_1588_CLOCK to PTP_1588_CLOCK_SELECTED whose purpose is to indicate the
> default Kconfig value for the PTP subsystem.

With this patch applied, the user is free to set a NIC driver as built
in and PTP_1588_CLOCK as a module, right? If so, that would lead to
non-functional PTP without any warning due to the use of IS_REACHABLE.
That doesn't sound right. Could easily cause hours of headache to
someone.

Or is this handled somehow?

Thanks,

 Jiri


Re: [PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-19 Thread Eugenia Emantayev
Reviewed-by: Eugenia Emantayev 


[PATCH 1/2] ptp_clock: allow for it to be optional

2016-09-18 Thread Nicolas Pitre
In order to break the hard dependency between the PTP clock subsystem and
ethernet drivers capable of being clock providers, this patch provides
simple PTP stub functions to allow linkage of those drivers into the
kernel even when the PTP subsystem is configured out.

And to make it possible for PTP to be configured out, the select statement
in the Kconfig entry for those ethernet drivers is changed from selecting
PTP_1588_CLOCK to PTP_1588_CLOCK_SELECTED whose purpose is to indicate the
default Kconfig value for the PTP subsystem.

This way the PTP subsystem may have Kconfig dependencies of its own, such
as POSIX_TIMERS, without making those ethernet drivers unavailable if
POSIX timers are cconfigured out. And when support for POSIX timers is
selected again then PTP clock support will also be selected accordingly.

Drivers must be ready to accept NULL from ptp_clock_register().
The pch_gbe driver is a bit special as it relies on extra code in
drivers/ptp/ptp_pch.c. Therefore we let the make process descend into
drivers/ptp/ even if PTP_1588_CLOCK is unselected.

Signed-off-by: Nicolas Pitre 
Acked-by: Richard Cochran 
---
 drivers/Makefile   |  2 +-
 drivers/net/ethernet/adi/Kconfig   |  8 ++-
 drivers/net/ethernet/amd/Kconfig   |  2 +-
 drivers/net/ethernet/amd/xgbe/xgbe-main.c  |  6 ++-
 drivers/net/ethernet/broadcom/Kconfig  |  4 +-
 drivers/net/ethernet/cavium/Kconfig|  2 +-
 drivers/net/ethernet/freescale/Kconfig |  2 +-
 drivers/net/ethernet/intel/Kconfig | 10 ++--
 drivers/net/ethernet/intel/e1000e/ptp.c|  2 +-
 drivers/net/ethernet/intel/i40e/i40e_ptp.c |  2 +-
 drivers/net/ethernet/intel/igb/igb_ptp.c   |  2 +-
 drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c   |  2 +-
 drivers/net/ethernet/mellanox/mlx4/Kconfig |  2 +-
 drivers/net/ethernet/mellanox/mlx4/en_clock.c  |  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/Kconfig|  2 +-
 drivers/net/ethernet/mellanox/mlx5/core/en_clock.c |  2 +-
 drivers/net/ethernet/renesas/Kconfig   |  2 +-
 drivers/net/ethernet/samsung/Kconfig   |  2 +-
 drivers/net/ethernet/sfc/Kconfig   |  2 +-
 drivers/net/ethernet/sfc/ptp.c | 14 ++---
 drivers/net/ethernet/stmicro/stmmac/Kconfig|  2 +-
 drivers/net/ethernet/stmicro/stmmac/stmmac_ptp.c   |  2 +-
 drivers/net/ethernet/ti/Kconfig|  2 +-
 drivers/net/ethernet/tile/Kconfig  |  2 +-
 drivers/ptp/Kconfig| 12 +++--
 include/linux/ptp_clock_kernel.h   | 59 +++---
 26 files changed, 92 insertions(+), 59 deletions(-)

diff --git a/drivers/Makefile b/drivers/Makefile
index 53abb4a5f7..8a538d0856 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -105,7 +105,7 @@ obj-$(CONFIG_INPUT) += input/
 obj-$(CONFIG_RTC_LIB)  += rtc/
 obj-y  += i2c/ media/
 obj-$(CONFIG_PPS)  += pps/
-obj-$(CONFIG_PTP_1588_CLOCK)   += ptp/
+obj-y  += ptp/
 obj-$(CONFIG_W1)   += w1/
 obj-y  += power/
 obj-$(CONFIG_HWMON)+= hwmon/
diff --git a/drivers/net/ethernet/adi/Kconfig b/drivers/net/ethernet/adi/Kconfig
index 6b94ba6103..67094a9cfe 100644
--- a/drivers/net/ethernet/adi/Kconfig
+++ b/drivers/net/ethernet/adi/Kconfig
@@ -55,10 +55,14 @@ config BFIN_RX_DESC_NUM
---help---
  Set the number of buffer packets used in driver.
 
+config BFIN_MAC_HAS_HWSTAMP
+   def_tristate BFIN_MAC
+   depends on BF518
+   select PTP_1588_CLOCK_SELECTED
+
 config BFIN_MAC_USE_HWSTAMP
bool "Use IEEE 1588 hwstamp"
-   depends on BFIN_MAC && BF518
-   select PTP_1588_CLOCK
+   depends on BFIN_MAC_HAS_HWSTAMP && PTP_1588_CLOCK
default y
---help---
  To support the IEEE 1588 Precision Time Protocol (PTP), select y here
diff --git a/drivers/net/ethernet/amd/Kconfig b/drivers/net/ethernet/amd/Kconfig
index 0038709fd3..327e71a554 100644
--- a/drivers/net/ethernet/amd/Kconfig
+++ b/drivers/net/ethernet/amd/Kconfig
@@ -177,7 +177,7 @@ config AMD_XGBE
depends on ARM64 || COMPILE_TEST
select BITREVERSE
select CRC32
-   select PTP_1588_CLOCK
+   select PTP_1588_CLOCK_SELECTED
---help---
  This driver supports the AMD 10GbE Ethernet device found on an
  AMD SoC.
diff --git a/drivers/net/ethernet/amd/xgbe/xgbe-main.c 
b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
index 3eee3201b5..4aeeb018b6 100644
--- a/drivers/net/ethernet/amd/xgbe/xgbe-main.c
+++ b/drivers/net/ethernet/amd/xgbe/xgbe-main.c
@@ -773,7 +773,8 @@ static int xgbe_probe(struct platform_device *pdev)
goto err_wq;
}
 
-   xgbe_ptp_register(pdata);
+   if