From bbaefbdf628176b112e360a500d3229faa5bb67d Mon Sep 17 00:00:00 2001 From: Sneh Shah Date: Wed, 28 Apr 2021 11:49:30 +0530 Subject: [PATCH] net: stmmac: Make code changes to support dlkm compilation Replace ethqos function calls with function pointer in stmmac. Makefile changes to compile all ethqos files as single ko. Change-Id: Iae8fb981b59cf14e33d31530a8798cc56c0e9926 Signed-off-by: Sneh Shah --- drivers/net/ethernet/stmicro/stmmac/Makefile | 5 +-- .../stmicro/stmmac/dwmac-qcom-ethqos.c | 37 ++++++++++++++----- .../stmicro/stmmac/dwmac-qcom-ethqos.h | 2 +- .../ethernet/stmicro/stmmac/dwmac-qcom-pps.c | 8 +++- drivers/net/ethernet/stmicro/stmmac/stmmac.h | 23 +----------- .../net/ethernet/stmicro/stmmac/stmmac_main.c | 12 +++--- .../net/ethernet/stmicro/stmmac/stmmac_mdio.c | 3 +- include/linux/stmmac.h | 18 +++++++++ 8 files changed, 65 insertions(+), 43 deletions(-) diff --git a/drivers/net/ethernet/stmicro/stmmac/Makefile b/drivers/net/ethernet/stmicro/stmmac/Makefile index eb129df30f30..3da5ca4d42b0 100644 --- a/drivers/net/ethernet/stmicro/stmmac/Makefile +++ b/drivers/net/ethernet/stmicro/stmmac/Makefile @@ -18,9 +18,8 @@ obj-$(CONFIG_DWMAC_LPC18XX) += dwmac-lpc18xx.o obj-$(CONFIG_DWMAC_MEDIATEK) += dwmac-mediatek.o obj-$(CONFIG_DWMAC_MESON) += dwmac-meson.o dwmac-meson8b.o obj-$(CONFIG_DWMAC_OXNAS) += dwmac-oxnas.o -obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-gpio.o -obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-ethqos.o -obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-pps.o +obj-$(CONFIG_DWMAC_QCOM_ETHQOS) += dwmac-qcom-eth.o +dwmac-qcom-eth-objs := dwmac-qcom-ethqos.o dwmac-qcom-gpio.o dwmac-qcom-pps.o obj-$(CONFIG_DWMAC_ROCKCHIP) += dwmac-rk.o obj-$(CONFIG_DWMAC_SOCFPGA) += dwmac-altr-socfpga.o obj-$(CONFIG_DWMAC_STI) += dwmac-sti.o diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c index a7ef075dc115..51e909acdf32 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c @@ -113,7 +113,6 @@ #define AUTONEG_STATE_MASK 0x20 #define MICREL_LINK_UP_INTR_STATUS BIT(0) -bool phy_intr_en; void *ipc_emac_log_ctxt; struct emac_emb_smmu_cb_ctx emac_emb_smmu_ctx = {0}; @@ -1011,6 +1010,7 @@ static irqreturn_t ETHQOS_PHY_ISR(int irq, void *dev_data) static int ethqos_phy_intr_enable(struct qcom_ethqos *ethqos) { int ret = 0; + struct stmmac_priv *priv = qcom_ethqos_get_priv(ethqos); INIT_WORK(ðqos->emac_phy_work, ethqos_defer_phy_isr_work); init_completion(ðqos->clk_enable_done); @@ -1022,7 +1022,7 @@ static int ethqos_phy_intr_enable(struct qcom_ethqos *ethqos) ethqos->phy_intr); return ret; } - phy_intr_en = true; + priv->plat->phy_intr_en_extn_stm = true; return ret; } @@ -1103,7 +1103,7 @@ static void qcom_ethqos_phy_suspend_clks(struct qcom_ethqos *ethqos) ETHQOSINFO("Enter\n"); - if (phy_intr_en) + if (priv->plat->phy_intr_en_extn_stm) reinit_completion(ðqos->clk_enable_done); ethqos->clks_suspended = 1; @@ -1170,17 +1170,26 @@ static void qcom_ethqos_phy_resume_clks(struct qcom_ethqos *ethqos) ethqos->clks_suspended = 0; - if (phy_intr_en) + if (priv->plat->phy_intr_en_extn_stm) complete_all(ðqos->clk_enable_done); ETHQOSINFO("Exit\n"); } -void qcom_ethqos_request_phy_wol(struct plat_stmmacenet_data *plat) +static void qcom_ethqos_request_phy_wol(void *plat_n) { - struct qcom_ethqos *ethqos = plat->bsp_priv; - struct platform_device *pdev = ethqos->pdev; - struct net_device *ndev = platform_get_drvdata(pdev); + struct plat_stmmacenet_data *plat = plat_n; + struct qcom_ethqos *ethqos; + struct platform_device *pdev; + struct net_device *ndev; + + if (!plat) + return; + + ethqos = plat->bsp_priv; + + pdev = ethqos->pdev; + ndev = platform_get_drvdata(pdev); ethqos->phy_wol_supported = 0; ethqos->phy_wol_wolopts = 0; @@ -1615,6 +1624,9 @@ static int qcom_ethqos_probe(struct platform_device *pdev) plat_dat->pmt = 1; plat_dat->tso_en = of_property_read_bool(np, "snps,tso"); plat_dat->early_eth = ethqos->early_eth_enabled; + plat_dat->handle_prv_ioctl = ethqos_handle_prv_ioctl; + plat_dat->request_phy_wol = qcom_ethqos_request_phy_wol; + plat_dat->init_pps = ethqos_init_pps; if (of_property_read_bool(pdev->dev.of_node, "emac-core-version")) { @@ -1647,6 +1659,8 @@ static int qcom_ethqos_probe(struct platform_device *pdev) } } + plat_dat->stmmac_emb_smmu_ctx = emac_emb_smmu_ctx; + ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res); if (ret) goto err_clk; @@ -1703,18 +1717,21 @@ static int qcom_ethqos_remove(struct platform_device *pdev) { struct qcom_ethqos *ethqos; int ret; + struct stmmac_priv *priv; ethqos = get_stmmac_bsp_priv(&pdev->dev); if (!ethqos) return -ENODEV; + priv = qcom_ethqos_get_priv(pethqos); + ret = stmmac_pltfr_remove(pdev); clk_disable_unprepare(ethqos->rgmii_clk); - if (phy_intr_en) + if (priv->plat->phy_intr_en_extn_stm) free_irq(ethqos->phy_intr, ethqos); - if (phy_intr_en) + if (priv->plat->phy_intr_en_extn_stm) cancel_work_sync(ðqos->emac_phy_work); emac_emb_smmu_exit(); diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.h b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.h index b3ef4ff72b65..22c582d94aab 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.h +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.h @@ -309,5 +309,5 @@ struct dwmac_qcom_avb_algorithm { void dwmac_qcom_program_avb_algorithm(struct stmmac_priv *priv, struct ifr_data_struct *req); unsigned int dwmac_qcom_get_plat_tx_coal_frames(struct sk_buff *skb); -void qcom_ethqos_request_phy_wol(struct plat_stmmacenet_data *plat); +int ethqos_init_pps(void *priv); #endif diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c index 9914399eb383..72d776335ebb 100644 --- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c +++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-pps.c @@ -254,11 +254,17 @@ int ppsout_config(struct stmmac_priv *priv, struct pps_cfg *eth_pps_cfg) return 0; } -int ethqos_init_pps(struct stmmac_priv *priv) +int ethqos_init_pps(void *priv_n) { + struct stmmac_priv *priv; u32 value; struct pps_cfg eth_pps_cfg = {0}; + if (!priv_n) + return -ENODEV; + + priv = priv_n; + priv->ptpaddr = priv->ioaddr + PTP_GMAC4_OFFSET; value = (PTP_TCR_TSENA | PTP_TCR_TSCFUPDT | PTP_TCR_TSUPDT); priv->hw->ptp->config_hw_tstamping(priv->ptpaddr, value); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac.h b/drivers/net/ethernet/stmicro/stmmac/stmmac.h index 02456e23ceb5..c36d1e85b0e3 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac.h +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac.h @@ -249,27 +249,8 @@ enum stmmac_state { STMMAC_SERVICE_SCHED, }; -struct emac_emb_smmu_cb_ctx { - bool valid; - struct platform_device *pdev_master; - struct platform_device *smmu_pdev; - struct dma_iommu_mapping *mapping; - struct iommu_domain *iommu_domain; - u32 va_start; - u32 va_size; - u32 va_end; - int ret; -}; - -extern struct emac_emb_smmu_cb_ctx emac_emb_smmu_ctx; - -#define GET_MEM_PDEV_DEV (emac_emb_smmu_ctx.valid ? \ - &emac_emb_smmu_ctx.smmu_pdev->dev : priv->device) -int ethqos_handle_prv_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); -int ethqos_init_pps(struct stmmac_priv *priv); - -extern bool phy_intr_en; -void qcom_ethqos_request_phy_wol(struct plat_stmmacenet_data *plat_dat); +#define GET_MEM_PDEV_DEV (priv->plat->stmmac_emb_smmu_ctx.valid ? \ + &priv->plat->stmmac_emb_smmu_ctx.smmu_pdev->dev : priv->device) int stmmac_mdio_unregister(struct net_device *ndev); int stmmac_mdio_register(struct net_device *ndev); diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c index c156f42c37b9..248c5f70e932 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_main.c @@ -1096,7 +1096,7 @@ static int stmmac_init_phy(struct net_device *dev) return -ENODEV; } ret = phylink_connect_phy(priv->phylink, priv->phydev); - if (phy_intr_en) { + if (priv->plat->phy_intr_en_extn_stm) { priv->phydev->irq = PHY_IGNORE_INTERRUPT; priv->phydev->interrupts = PHY_INTERRUPT_ENABLED; if (priv->phydev->drv->ack_interrupt && @@ -1113,7 +1113,7 @@ static int stmmac_init_phy(struct net_device *dev) !priv->phydev->drv->config_intr(priv->phydev)) { pr_err(" qcom-ethqos: %s config_phy_intr successful aftre connect\n", __func__); - qcom_ethqos_request_phy_wol(priv->plat); + priv->plat->request_phy_wol(priv->plat); } } else { pr_info("stmmac phy polling mode\n"); @@ -2692,7 +2692,7 @@ static int stmmac_hw_setup(struct net_device *dev, bool init_ptp) clk_set_rate(priv->plat->clk_ptp_ref, priv->plat->clk_ptp_rate); - ret = ethqos_init_pps(priv); + ret = priv->plat->init_pps(priv); } priv->tx_lpi_timer = STMMAC_DEFAULT_TWT_LS; @@ -4073,12 +4073,14 @@ static void stmmac_poll_controller(struct net_device *dev) */ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) { - struct stmmac_priv *priv = netdev_priv (dev); int ret = -EOPNOTSUPP; + struct stmmac_priv *priv; if (!netif_running(dev)) return -EINVAL; + priv = netdev_priv(dev); + switch (cmd) { case SIOCGMIIPHY: case SIOCGMIIREG: @@ -4091,7 +4093,7 @@ static int stmmac_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) case SIOCGHWTSTAMP: ret = stmmac_hwtstamp_get(dev, rq); case SIOCDEVPRIVATE: - ret = ethqos_handle_prv_ioctl(dev, rq, cmd); + ret = priv->plat->handle_prv_ioctl(dev, rq, cmd); break; default: break; diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c index 8729a3c0dfe5..f6f8d0782a71 100644 --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c @@ -266,9 +266,8 @@ int stmmac_mdio_reset(struct mii_bus *bus) unsigned int mii_address = priv->hw->mii.addr; bool active_high = true; -#ifdef CONFIG_DWMAC_QCOM_ETHQOS active_high = false; -#endif + if (priv->plat->early_eth) return 0; diff --git a/include/linux/stmmac.h b/include/linux/stmmac.h index b340385e4d41..1b1d14e015bf 100644 --- a/include/linux/stmmac.h +++ b/include/linux/stmmac.h @@ -128,6 +128,18 @@ struct stmmac_txq_cfg { u32 prio; }; +struct emac_emb_smmu_cb_ctx { + bool valid; + struct platform_device *pdev_master; + struct platform_device *smmu_pdev; + struct dma_iommu_mapping *mapping; + struct iommu_domain *iommu_domain; + u32 va_start; + u32 va_size; + u32 va_end; + int ret; +}; + struct plat_stmmacenet_data { int bus_id; int phy_addr; @@ -187,5 +199,11 @@ struct plat_stmmacenet_data { unsigned int (*get_plat_tx_coal_frames) (struct sk_buff *skb); bool early_eth; + struct emac_emb_smmu_cb_ctx stmmac_emb_smmu_ctx; + bool phy_intr_en_extn_stm; + int (*handle_prv_ioctl)(struct net_device *dev, struct ifreq *ifr, + int cmd); + void (*request_phy_wol)(void *plat); + int (*init_pps)(void *priv); }; #endif