Enable SERDES power up/down
Subsystems (4)
v2 cover Enable SERDES power up/down
Changes from v1:
1.Only the configuration of the SERDES logic is kept, other SW acrh has
changed.
2.Removed the proposed new files intel_serdes.c and intel_serdes.h and
moved the SERDES configuration logic to dwmac-intel.c and dwmac_intel.h.
3.Added 2 BSP callbacks ->serdes_powerup() and ->serdes_powerup(). 4.The suggested 2 new BSP callbacks is called in stmmac_dvr_probe() and
stmmac_dvr_remove().
This platform specific SERDES configuration not able separate 100% cleanly from the main dwmac logic because mdio communication is needed for configuring the SERDES power-up sequence. As for SERDES power-down sequence, it must be configured after all dma stop and before unregister the mdio bus.
This implementation should have the least changes on the
main dwmac logic but still serve the purpose for providing BSP callback for any platform that needs to configure SERDES.
Voon Weifeng (1):
net: stmmac: Enable SERDES power up/down sequence
.../net/ethernet/stmicro/stmmac/dwmac-intel.c | 171 ++++++++++++++++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 10 + include/linux/stmmac.h | 3 + 3 files changed, 184 insertions(+)
Signature · 1 line
2.17.1
RFC v2 1/1 net: stmmac: Enable SERDES power up/down sequence
This patch is to enable Intel SERDES power up/down sequence. The SERDES converts 8/10 bits data to SGMII signal. Below is an example of HW configuration for SGMII mode. The SERDES is located in the PHY IF in the diagram below.
<-----------------GBE Controller---------->|<--External PHY chip-->
+----------+ +----+ +---+ +----------+
| EQoS | <-GMII->| DW | < ------ > |PHY| <-SGMII-> | External |
| MAC | |xPCS| |IF | | PHY |
+----------+ +----+ +---+ +----------+
^ ^ ^ ^
| | | |
+---------------------MDIO-------------------------+PHY IF configuration and status registers are accessible through mdio address 0x15 which is defined as intel_adhoc_addr. During D0, The driver will need to power up PHY IF by changing the power state to P0. Likewise, for D3, the driver sets PHY IF power state to P3.
--- .../net/ethernet/stmicro/stmmac/dwmac-intel.c | 171 ++++++++++++++++++ .../net/ethernet/stmicro/stmmac/stmmac_main.c | 10 + include/linux/stmmac.h | 3 + 3 files changed, 184 insertions(+)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c +171 -0
@@ -5,6 +5,7 @@#include <linux/clk-provider.h> #include <linux/pci.h> #include <linux/dmi.h> +#include "dwmac-intel.h" #include "stmmac.h" /* This struct is used to associate PCI Function of MAC controller on a board,
@@ -49,6 +50,170 @@ static int stmmac_pci_find_phy_addr(struct pci_dev *pdev,return -ENODEV ; } +static int serdes_status_poll (struct stmmac_priv *priv,int phyaddr, +int phyreg,u32 mask,u32 val) +{ +unsigned int retries =10 ; +int val_rd =0 ; + +do { + val_rd =mdiobus_read (priv->mii, phyaddr, phyreg); +if ((val_rd & mask) == (val & mask)) +return 0 ; +udelay (POLL_DELAY_US ); + }while (--retries); + +return -ETIMEDOUT ; +} + +static int intel_serdes_powerup (struct net_device *ndev) +{ +struct stmmac_priv *priv =netdev_priv (ndev); +int serdes_phy_addr =0 ; +u32 data =0 ; + +if (!priv->plat->intel_adhoc_addr) +return 0 ; + + serdes_phy_addr = priv->plat->intel_adhoc_addr; + +/* assert clk_req */ + data =mdiobus_read (priv->mii, serdes_phy_addr, +SERDES_GCR0 ); + + data |=SERDES_PLL_CLK ; + +mdiobus_write (priv->mii, serdes_phy_addr, +SERDES_GCR0 , data); + +/* check for clk_ack assertion */ + data =serdes_status_poll (priv, serdes_phy_addr, +SERDES_GSR0 , +SERDES_PLL_CLK , +SERDES_PLL_CLK ); + +if (data) { +dev_err (priv->device,"Serdes PLL clk request timeout\n" ); +return data; + } + +/* assert lane reset */ + data =mdiobus_read (priv->mii, serdes_phy_addr, +SERDES_GCR0 ); + + data |=SERDES_RST ; + +mdiobus_write (priv->mii, serdes_phy_addr, +SERDES_GCR0 , data); + +/* check for assert lane reset reflection */ + data =serdes_status_poll (priv, serdes_phy_addr, +SERDES_GSR0 , +SERDES_RST , +SERDES_RST ); + +if (data) { +dev_err (priv->device,"Serdes assert lane reset timeout\n" ); +return data; + } + +/* move power state to P0 */ + data =mdiobus_read (priv->mii, serdes_phy_addr, +SERDES_GCR0 ); + + data &= ~SERDES_PWR_ST_MASK ; + data |=SERDES_PWR_ST_P0 <<SERDES_PWR_ST_SHIFT ; + +mdiobus_write (priv->mii, serdes_phy_addr, +SERDES_GCR0 , data); + +/* Check for P0 state */ + data =serdes_status_poll (priv, serdes_phy_addr, +SERDES_GSR0 , +SERDES_PWR_ST_MASK , +SERDES_PWR_ST_P0 <<SERDES_PWR_ST_SHIFT ); + +if (data) { +dev_err (priv->device,"Serdes power state P0 timeout.\n" ); +return data; + } + +return 0 ; +} + +static void intel_serdes_powerdown (struct net_device *ndev) +{ +struct stmmac_priv *priv =netdev_priv (ndev); +int serdes_phy_addr =0 ; +u32 data =0 ; + + serdes_phy_addr = priv->plat->intel_adhoc_addr; + +if (!priv->plat->intel_adhoc_addr) +return ; + +/* move power state to P3 */ + data =mdiobus_read (priv->mii, serdes_phy_addr, +SERDES_GCR0 ); + + data &= ~SERDES_PWR_ST_MASK ; + data |=SERDES_PWR_ST_P3 <<SERDES_PWR_ST_SHIFT ; + +mdiobus_write (priv->mii, serdes_phy_addr, +SERDES_GCR0 , data); + +/* Check for P3 state */ + data =serdes_status_poll (priv, serdes_phy_addr, +SERDES_GSR0 , +SERDES_PWR_ST_MASK , +SERDES_PWR_ST_P3 <<SERDES_PWR_ST_SHIFT ); + +if (data) { +dev_err (priv->device,"Serdes power state P3 timeout\n" ); +return ; + } + +/* de-assert clk_req */ + data =mdiobus_read (priv->mii, serdes_phy_addr, +SERDES_GCR0 ); + + data &= ~SERDES_PLL_CLK ; + +mdiobus_write (priv->mii, serdes_phy_addr, +SERDES_GCR0 , data); + +/* check for clk_ack de-assert */ + data =serdes_status_poll (priv, serdes_phy_addr, +SERDES_GSR0 , +SERDES_PLL_CLK , + (u32 )~SERDES_PLL_CLK ); + +if (data) { +dev_err (priv->device,"Serdes PLL clk de-assert timeout\n" ); +return ; + } + +/* de-assert lane reset */ + data =mdiobus_read (priv->mii, serdes_phy_addr, +SERDES_GCR0 ); + + data &= ~SERDES_RST ; + +mdiobus_write (priv->mii, serdes_phy_addr, +SERDES_GCR0 , data); + +/* check for de-assert lane reset reflection */ + data =serdes_status_poll (priv, serdes_phy_addr, +SERDES_GSR0 , +SERDES_RST , + (u32 )~SERDES_RST ); + +if (data) { +dev_err (priv->device,"Serdes de-assert lane reset timeout\n" ); +return ; + } +} +static void common_default_data (struct plat_stmmacenet_data *plat) { plat->clk_csr =2 ;/* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
@@ -89,6 +254,9 @@ static int intel_mgbe_common_data(struct pci_dev *pdev, plat->force_sf_dma_mode =0 ; plat->tso_en =1 ; +/* intel specific adhoc (mdio) address for serdes & etc */ + plat->intel_adhoc_addr =0x15 ; + plat->rx_sched_algorithm =MTL_RX_ALGORITHM_SP ;for (i =0 ; i < plat->rx_queues_to_use; i++) {
@@ -189,6 +357,9 @@ static int ehl_sgmii_data(struct pci_dev *pdev, plat->phy_addr =0 ; plat->phy_interface =PHY_INTERFACE_MODE_SGMII ; + plat->serdes_powerup = intel_serdes_powerup; + plat->serdes_powerdown = intel_serdes_powerdown; +return ehl_common_data (pdev, plat); }
drivers/net/ethernet/stmicro/stmmac/stmmac_main.c +10 -0
@@ -4986,6 +4986,13 @@ int stmmac_dvr_probe(struct device *device, goto error_netdev_register; } +if (priv->plat->serdes_powerup) { + ret = priv->plat->serdes_powerup (ndev); + +if (ret <0 ) +return ret; + } +#ifdef CONFIG_DEBUG_FS stmmac_init_fs (ndev);#endif
@@ -5029,6 +5036,9 @@ int stmmac_dvr_remove(struct device *dev)stmmac_stop_all_dma (priv); +if (priv->plat->serdes_powerdown) + priv->plat->serdes_powerdown (ndev); +stmmac_mac_set (priv, priv->ioaddr, false);netif_carrier_off (ndev);unregister_netdev (ndev);
include/linux/stmmac.h +3 -0
@@ -147,6 +147,7 @@ struct plat_stmmacenet_data {int bus_id;int phy_addr;int interface; +int intel_adhoc_addr;phy_interface_t phy_interface;struct stmmac_mdio_bus_data *mdio_bus_data;struct device_node *phy_node;
@@ -177,6 +178,8 @@ struct plat_stmmacenet_data {struct stmmac_rxq_cfg rx_queues_cfg[MTL_MAX_RX_QUEUES ];struct stmmac_txq_cfg tx_queues_cfg[MTL_MAX_TX_QUEUES ];void (*fix_mac_speed)(void *priv,unsigned int speed); +int (*serdes_powerup)(struct net_device *ndev); +void (*serdes_powerdown)(struct net_device *ndev);int (*init)(struct platform_device *pdev,void *priv);void (*exit)(struct platform_device *pdev,void *priv);struct mac_device_info *(*setup)(void *priv);
Signature · 1 line
2.17.1
kbuild test robot
build botRe: [RFC, net-next, v2, 1/1] net: stmmac: Enable SERDES power up/down sequence
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…
Hi Voon,
[FYI, it's a private test report for your RFC patch.]
[auto build test WARNING on linus/master]
[also build test WARNING on next-20200410]
[cannot apply to v5.6]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Voon-Weifeng/Enable-SERDES-power-up-down/20200410-033839 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 5d30bcacd91af6874481129797af364a53cd9b46
If you fix the issue, kindly add following tag as appropriate
cppcheck warnings: (new ones prefixed by >>)
drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c:57:6: warning: The scope of the variable 'val_rd' can be reduced. [variableScope]
int val_rd = 0;
^
>> drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c:57:13: warning: Variable 'val_rd' is assigned a value that is never used. [unreadVariable]
int val_rd = 0;
^vim +/val_rd +57 drivers/net/ethernet/stmicro/stmmac/dwmac-intel.c
52
53 static int serdes_status_poll(struct stmmac_priv *priv, int phyaddr,
54 int phyreg, u32 mask, u32 val)
55 {
56 unsigned int retries = 10;
> 57 int val_rd = 0;
58
59 do {
60 val_rd = mdiobus_read(priv->mii, phyaddr, phyreg);
61 if ((val_rd & mask) == (val & mask))
62 return 0;
63 udelay(POLL_DELAY_US);
64 } while (--retries);
65
66 return -ETIMEDOUT;
67 }
68 ---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org
RE: [RFC,net-next,v2, 1/1] net: stmmac: Enable SERDES power up/down sequence
In reply to Voon WeifengFrom: Voon Weifeng <[email protected]>
Date: Apr/09/2020, 16:48:23 (UTC+00:00)
include/linux/stmmac.h struct plat_stmmacenet_data { · line 150
Quoted 9 lines
include/linux/stmmac.h +1
-0@@ -147,6 +147,7 @@ struct plat_stmmacenet_data {int bus_id;int phy_addr;int interface; +int intel_adhoc_addr;
No, this is not right to add. Just use the bsp_priv field.
---
Thanks,
Jose Miguel Abreu
RE: [RFC,net-next,v2, 1/1] net: stmmac: Enable SERDES power up/down sequence
Quoted 15 lines
From: Voon Weifeng <[email protected]>
Date: Apr/09/2020, 16:48:23 (UTC+00:00)include/linux/stmmac.h struct plat_stmmacenet_data { · line 150
Quoted 9 lines
include/linux/stmmac.h index renamed from include/linux/stmmac.h +0
-0
fbafb353e9be..89c8729bbe5b100644include/linux/stmmac.h +1
-0@@ -147,6 +147,7 @@ struct plat_stmmacenet_data {int bus_id;int phy_addr;int interface; +int intel_adhoc_addr;No, this is not right to add. Just use the
bsp_privfield.
Noted and thanks. I will change this and submit for v5.7. Weifeng
Quoted 3 lines
---
Thanks,
Jose Miguel Abreu