diff --git a/drivers/net/ethernet/stmicro/stmmac/Kconfig b/drivers/net/ethernet/stmicro/stmmac/Kconfig index 0aecb267fb31..89ca65c38a5e 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Kconfig +++ b/drivers/net/ethernet/stmicro/stmmac/Kconfig @@ -38,6 +38,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 05c792eb473f..0244b5985309 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) @@ -15,6 +14,8 @@ stmmac-$(CONFIG_STMMAC_FULL) += ring_mode.o chain_mode.o dwmac1000_core.o \ stmmac-$(CONFIG_STMMAC_SELFTESTS) += stmmac_selftests.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 e609de3609bf..704b60ec57f9 100644 --- a/drivers/net/ethernet/stmicro/stmmac/hwif.c +++ b/drivers/net/ethernet/stmicro/stmmac/hwif.c @@ -99,7 +99,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; const void *mmc; @@ -120,7 +122,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, .mmc = &dwmac_mmc_ops, @@ -138,7 +142,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, .mmc = &dwmac_mmc_ops, @@ -156,7 +162,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 = &dwmac510_tc_ops, .mmc = &dwmac_mmc_ops, @@ -174,7 +182,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 = &dwmac510_tc_ops, .mmc = &dwmac_mmc_ops, @@ -194,7 +204,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, #ifdef CONFIG_STMMAC_FULL .tc = &dwmac510_tc_ops, @@ -216,7 +228,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, .mmc = &dwmac_mmc_ops, @@ -235,7 +249,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 = &dwmac510_tc_ops, .mmc = &dwxgmac_mmc_ops, @@ -254,7 +270,9 @@ static const struct stmmac_hwif_entry { .desc = &dwxgmac210_desc_ops, .dma = &dwxgmac210_dma_ops, .mac = &dwxlgmac2_ops, +#ifdef CONFIG_STMMAC_PTP .hwtimestamp = &stmmac_ptp, +#endif .mode = NULL, .tc = &dwmac510_tc_ops, .mmc = &dwxgmac_mmc_ops, @@ -325,7 +343,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; mac->mmc = mac->mmc ? : entry->mmc; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 8608984f7cf5..b57c83b2460c 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -265,8 +265,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 5e8314b857cd..a51d453432de 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -470,6 +470,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. @@ -723,6 +724,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 @@ -763,7 +765,8 @@ static int stmmac_init_ptp(struct stmmac_priv *priv) static void stmmac_release_ptp(struct stmmac_priv *priv) { - clk_disable_unprepare(priv->plat->clk_ptp_ref); + if (IS_ENABLED(CONFIG_STMMAC_PTP)) + clk_disable_unprepare(priv->plat->clk_ptp_ref); stmmac_ptp_unregister(priv); } @@ -2704,7 +2707,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); @@ -2780,7 +2783,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); } /** @@ -2970,7 +2974,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; } @@ -4216,12 +4221,14 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) case SIOCSMIIREG: ret = phylink_mii_ioctl(priv->phylink, 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; } @@ -5229,7 +5236,8 @@ 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 */ - clk_disable_unprepare(priv->plat->clk_ptp_ref); + if (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); } @@ -5299,7 +5307,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 (IS_ENABLED(CONFIG_STMMAC_PTP) && priv->plat->clk_ptp_ref) clk_prepare_enable(priv->plat->clk_ptp_ref); /* reset the phy so that it's ready */ if (priv->mii)