diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 804102cc4366..21f40747f28b 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -25,6 +25,12 @@ config STMMAC_FULL This selects the full function, default is Y, full-featured version includes 4.10 and other versions, if it is N, only 4.10 core working. +config STMMAC_PTP + bool "PTP feature for STMMAC" + default STMMAC_ETH + help + This selects the ptp timestamp function, default is Y. + config STMMAC_PLATFORM tristate "STMMAC Platform bus support" depends on STMMAC_ETH diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index a1592b940456..f8275ed91dd8 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -2,8 +2,7 @@ obj-$(CONFIG_STMMAC_ETH) += stmmac.o stmmac-objs:= stmmac_main.o stmmac_mdio.o dwmac_lib.o \ - mmc_core.o stmmac_hwtstamp.o stmmac_ptp.o \ - dwmac4_descs.o dwmac4_dma.o \ + mmc_core.o dwmac4_descs.o dwmac4_dma.o \ dwmac4_lib.o dwmac4_core.o hwif.o \ $(stmmac-y) @@ -14,6 +13,8 @@ stmmac-$(CONFIG_STMMAC_FULL) += ring_mode.o chain_mode.o dwmac1000_core.o \ stmmac-$(CONFIG_STMMAC_ETHTOOL) += stmmac_ethtool.o +stmmac-$(CONFIG_STMMAC_PTP) += stmmac_hwtstamp.o stmmac_ptp.o + # Ordering matters. Generic driver must be last. obj-$(CONFIG_STMMAC_PLATFORM) += stmmac-platform.o obj-$(CONFIG_DWMAC_ANARION) += dwmac-anarion.o diff --git a/drivers/net/ethernet/stmicro/stmmac/hwif.c b/drivers/net/ethernet/stmicro/stmmac/hwif.c index cbc4824df399..c6b88cd9a994 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -80,7 +80,9 @@ static const struct stmmac_hwif_entry { const void *desc; const void *dma; const void *mac; +#ifdef CONFIG_STMMAC_PTP const void *hwtimestamp; +#endif const void *mode; const void *tc; int (*setup)(struct stmmac_priv *priv); @@ -100,7 +102,9 @@ static const struct stmmac_hwif_entry { .desc = NULL, .dma = &dwmac100_dma_ops, .mac = &dwmac100_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = NULL, .tc = NULL, .setup = dwmac100_setup, @@ -117,7 +121,9 @@ static const struct stmmac_hwif_entry { .desc = NULL, .dma = &dwmac1000_dma_ops, .mac = &dwmac1000_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = NULL, .tc = NULL, .setup = dwmac1000_setup, @@ -134,7 +140,9 @@ static const struct stmmac_hwif_entry { .desc = &dwmac4_desc_ops, .dma = &dwmac4_dma_ops, .mac = &dwmac4_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = NULL, .tc = NULL, .setup = dwmac4_setup, @@ -151,7 +159,9 @@ static const struct stmmac_hwif_entry { .desc = &dwmac4_desc_ops, .dma = &dwmac4_dma_ops, .mac = &dwmac410_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = &dwmac4_ring_mode_ops, .tc = NULL, .setup = dwmac4_setup, @@ -170,7 +180,9 @@ static const struct stmmac_hwif_entry { .desc = &dwmac4_desc_ops, .dma = &dwmac410_dma_ops, .mac = &dwmac410_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = &dwmac4_ring_mode_ops, .tc = NULL, .setup = dwmac4_setup, @@ -189,7 +201,9 @@ static const struct stmmac_hwif_entry { .desc = &dwmac4_desc_ops, .dma = &dwmac410_dma_ops, .mac = &dwmac510_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = &dwmac4_ring_mode_ops, .tc = &dwmac510_tc_ops, .setup = dwmac4_setup, @@ -206,7 +220,9 @@ static const struct stmmac_hwif_entry { .desc = &dwxgmac210_desc_ops, .dma = &dwxgmac210_dma_ops, .mac = &dwxgmac210_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = NULL, .tc = NULL, .setup = dwxgmac2_setup, @@ -272,7 +288,9 @@ int stmmac_hwif_init(struct stmmac_priv *priv) mac->desc = mac->desc ? : entry->desc; mac->dma = mac->dma ? : entry->dma; mac->mac = mac->mac ? : entry->mac; +#ifdef CONFIG_STMMAC_PTP mac->ptp = mac->ptp ? : entry->hwtimestamp; +#endif mac->mode = mac->mode ? : entry->mode; mac->tc = mac->tc ? : entry->tc; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index fb8ffd4c54af..1eaa1f8bdbe2 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -226,8 +226,18 @@ static inline void stmmac_set_ethtool_ops(struct net_device *netdev) } #endif +#ifdef CONFIG_STMMAC_PTP void stmmac_ptp_register(struct stmmac_priv *priv); void stmmac_ptp_unregister(struct stmmac_priv *priv); +#else +static inline void stmmac_ptp_register(struct stmmac_priv *priv) +{ +} + +static inline void stmmac_ptp_unregister(struct stmmac_priv *priv) +{ +} +#endif int stmmac_resume(struct device *dev); int stmmac_suspend(struct device *dev); int stmmac_dvr_remove(struct device *dev); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index cff46c49b72f..921edea1ee66 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -508,6 +508,7 @@ static void stmmac_get_rx_hwtstamp(struct stmmac_priv *priv, struct dma_desc *p, } } +#ifdef CONFIG_STMMAC_PTP /** * stmmac_hwtstamp_set - control hardware timestamping. * @dev: device pointer. @@ -760,6 +761,7 @@ static int stmmac_hwtstamp_get(struct net_device *dev, struct ifreq *ifr) return copy_to_user(ifr->ifr_data, config, sizeof(*config)) ? -EFAULT : 0; } +#endif /* CONFIG_STMMAC_PTP */ /** * stmmac_init_ptp - init PTP @@ -800,7 +802,7 @@ static int stmmac_init_ptp(struct stmmac_priv *priv) static void stmmac_release_ptp(struct stmmac_priv *priv) { - if (priv->plat->clk_ptp_ref) + if (priv->plat->clk_ptp_ref && IS_ENABLED(CONFIG_STMMAC_PTP)) clk_disable_unprepare(priv->plat->clk_ptp_ref); stmmac_ptp_unregister(priv); } @@ -2547,7 +2549,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) stmmac_mmc_setup(priv); - if (init_ptp) { + if (IS_ENABLED(CONFIG_STMMAC_PTP) && init_ptp) { ret = clk_prepare_enable(priv->plat->clk_ptp_ref); if (ret < 0) netdev_warn(priv->dev, "failed to enable PTP reference clock: %d\n", ret); @@ -2589,7 +2591,8 @@ static void stmmac_hw_teardown(struct net_device *dev) { struct stmmac_priv *priv = netdev_priv(dev); - clk_disable_unprepare(priv->plat->clk_ptp_ref); + if (IS_ENABLED(CONFIG_STMMAC_PTP)) + clk_disable_unprepare(priv->plat->clk_ptp_ref); } /** @@ -2757,7 +2760,8 @@ static int stmmac_release(struct net_device *dev) netif_carrier_off(dev); - stmmac_release_ptp(priv); + if (IS_ENABLED(CONFIG_STMMAC_PTP)) + stmmac_release_ptp(priv); return 0; } @@ -3801,12 +3805,14 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) return -EINVAL; ret = phy_mii_ioctl(dev->phydev, rq, cmd); break; +#ifdef CONFIG_STMMAC_PTP case SIOCSHWTSTAMP: ret = stmmac_hwtstamp_set(dev, rq); break; case SIOCGHWTSTAMP: ret = stmmac_hwtstamp_get(dev, rq); break; +#endif default: break; } @@ -4556,7 +4562,7 @@ int stmmac_suspend(struct device *dev) stmmac_mac_set(priv, priv->ioaddr, false); pinctrl_pm_select_sleep_state(priv->device); /* Disable clock in case of PWM is off */ - if (priv->plat->clk_ptp_ref) + if (priv->plat->clk_ptp_ref && IS_ENABLED(CONFIG_STMMAC_PTP)) clk_disable_unprepare(priv->plat->clk_ptp_ref); clk_disable_unprepare(priv->plat->pclk); clk_disable_unprepare(priv->plat->stmmac_clk); @@ -4628,7 +4634,7 @@ int stmmac_resume(struct device *dev) /* enable the clk previously disabled */ clk_prepare_enable(priv->plat->stmmac_clk); clk_prepare_enable(priv->plat->pclk); - if (priv->plat->clk_ptp_ref) + if (priv->plat->clk_ptp_ref && IS_ENABLED(CONFIG_STMMAC_PTP)) clk_prepare_enable(priv->plat->clk_ptp_ref); /* reset the phy so that it's ready */ if (priv->mii)