2019-05-29 07:18:05 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2009-10-14 15:13:45 -07:00
|
|
|
/*******************************************************************************
|
|
|
|
STMMAC Ethernet Driver -- MDIO bus implementation
|
|
|
|
Provides Bus interface for MII registers
|
|
|
|
|
|
|
|
Copyright (C) 2007-2009 STMicroelectronics Ltd
|
|
|
|
|
|
|
|
|
|
|
|
Author: Carl Shaw <carl.shaw@st.com>
|
|
|
|
Maintainer: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
|
|
|
*******************************************************************************/
|
|
|
|
|
2019-06-12 21:31:15 +02:00
|
|
|
#include <linux/gpio/consumer.h>
|
2017-02-08 09:31:10 +01:00
|
|
|
#include <linux/io.h>
|
2017-02-08 09:31:12 +01:00
|
|
|
#include <linux/iopoll.h>
|
2009-10-14 15:13:45 -07:00
|
|
|
#include <linux/mii.h>
|
2015-12-14 11:31:59 +08:00
|
|
|
#include <linux/of_mdio.h>
|
2021-03-15 20:16:46 +08:00
|
|
|
#include <linux/pm_runtime.h>
|
2017-02-08 09:31:10 +01:00
|
|
|
#include <linux/phy.h>
|
2019-06-15 12:09:29 +02:00
|
|
|
#include <linux/property.h>
|
2017-02-08 09:31:10 +01:00
|
|
|
#include <linux/slab.h>
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2018-08-08 09:04:33 +01:00
|
|
|
#include "dwxgmac2.h"
|
2009-10-14 15:13:45 -07:00
|
|
|
#include "stmmac.h"
|
|
|
|
|
|
|
|
#define MII_BUSY 0x00000001
|
|
|
|
#define MII_WRITE 0x00000002
|
2019-07-06 01:33:27 +08:00
|
|
|
#define MII_DATA_MASK GENMASK(15, 0)
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2016-04-28 15:56:45 +02:00
|
|
|
/* GMAC4 defines */
|
|
|
|
#define MII_GMAC4_GOC_SHIFT 2
|
2019-07-06 01:33:27 +08:00
|
|
|
#define MII_GMAC4_REG_ADDR_SHIFT 16
|
2016-04-28 15:56:45 +02:00
|
|
|
#define MII_GMAC4_WRITE (1 << MII_GMAC4_GOC_SHIFT)
|
|
|
|
#define MII_GMAC4_READ (3 << MII_GMAC4_GOC_SHIFT)
|
2019-07-06 01:33:27 +08:00
|
|
|
#define MII_GMAC4_C45E BIT(1)
|
2016-04-28 15:56:45 +02:00
|
|
|
|
2018-08-08 09:04:33 +01:00
|
|
|
/* XGMAC defines */
|
|
|
|
#define MII_XGMAC_SADDR BIT(18)
|
|
|
|
#define MII_XGMAC_CMD_SHIFT 16
|
|
|
|
#define MII_XGMAC_WRITE (1 << MII_XGMAC_CMD_SHIFT)
|
|
|
|
#define MII_XGMAC_READ (3 << MII_XGMAC_CMD_SHIFT)
|
|
|
|
#define MII_XGMAC_BUSY BIT(22)
|
|
|
|
#define MII_XGMAC_MAX_C22ADDR 3
|
|
|
|
#define MII_XGMAC_C22P_MASK GENMASK(MII_XGMAC_MAX_C22ADDR, 0)
|
2019-11-11 15:42:36 +01:00
|
|
|
#define MII_XGMAC_PA_SHIFT 16
|
|
|
|
#define MII_XGMAC_DA_SHIFT 21
|
|
|
|
|
2023-01-12 16:15:14 +01:00
|
|
|
static void stmmac_xgmac2_c45_format(struct stmmac_priv *priv, int phyaddr,
|
|
|
|
int devad, int phyreg, u32 *hw_addr)
|
2019-11-11 15:42:36 +01:00
|
|
|
{
|
|
|
|
u32 tmp;
|
|
|
|
|
|
|
|
/* Set port as Clause 45 */
|
|
|
|
tmp = readl(priv->ioaddr + XGMAC_MDIO_C22P);
|
|
|
|
tmp &= ~BIT(phyaddr);
|
|
|
|
writel(tmp, priv->ioaddr + XGMAC_MDIO_C22P);
|
|
|
|
|
|
|
|
*hw_addr = (phyaddr << MII_XGMAC_PA_SHIFT) | (phyreg & 0xffff);
|
2023-01-12 16:15:14 +01:00
|
|
|
*hw_addr |= devad << MII_XGMAC_DA_SHIFT;
|
2019-11-11 15:42:36 +01:00
|
|
|
}
|
2018-08-08 09:04:33 +01:00
|
|
|
|
2023-01-12 16:15:14 +01:00
|
|
|
static void stmmac_xgmac2_c22_format(struct stmmac_priv *priv, int phyaddr,
|
|
|
|
int phyreg, u32 *hw_addr)
|
2018-08-08 09:04:33 +01:00
|
|
|
{
|
2023-07-31 19:50:41 +08:00
|
|
|
u32 tmp = 0;
|
|
|
|
|
|
|
|
if (priv->synopsys_id < DWXGMAC_CORE_2_20) {
|
|
|
|
/* Until ver 2.20 XGMAC does not support C22 addr >= 4. Those
|
|
|
|
* bits above bit 3 of XGMAC_MDIO_C22P register are reserved.
|
|
|
|
*/
|
|
|
|
tmp = readl(priv->ioaddr + XGMAC_MDIO_C22P);
|
|
|
|
tmp &= ~MII_XGMAC_C22P_MASK;
|
|
|
|
}
|
2018-08-08 09:04:33 +01:00
|
|
|
/* Set port as Clause 22 */
|
|
|
|
tmp |= BIT(phyaddr);
|
|
|
|
writel(tmp, priv->ioaddr + XGMAC_MDIO_C22P);
|
|
|
|
|
2019-11-11 15:42:36 +01:00
|
|
|
*hw_addr = (phyaddr << MII_XGMAC_PA_SHIFT) | (phyreg & 0x1f);
|
2018-08-08 09:04:33 +01:00
|
|
|
}
|
|
|
|
|
2023-01-12 16:15:14 +01:00
|
|
|
static int stmmac_xgmac2_mdio_read(struct stmmac_priv *priv, u32 addr,
|
|
|
|
u32 value)
|
2018-08-08 09:04:33 +01:00
|
|
|
{
|
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
|
|
|
unsigned int mii_data = priv->hw->mii.data;
|
2023-01-12 16:15:14 +01:00
|
|
|
u32 tmp;
|
2018-08-08 09:04:33 +01:00
|
|
|
int ret;
|
|
|
|
|
2022-04-08 08:12:50 +00:00
|
|
|
ret = pm_runtime_resume_and_get(priv->device);
|
|
|
|
if (ret < 0)
|
2021-03-15 20:16:46 +08:00
|
|
|
return ret;
|
|
|
|
|
2019-11-11 15:42:36 +01:00
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_data, tmp,
|
2021-03-15 20:16:46 +08:00
|
|
|
!(tmp & MII_XGMAC_BUSY), 100, 10000)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_disable_clks;
|
|
|
|
}
|
2019-11-11 15:42:36 +01:00
|
|
|
|
2018-08-08 09:04:33 +01:00
|
|
|
value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
|
|
|
|
& priv->hw->mii.clk_csr_mask;
|
2019-11-11 15:42:36 +01:00
|
|
|
value |= MII_XGMAC_READ;
|
2018-08-08 09:04:33 +01:00
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_data, tmp,
|
2021-03-15 20:16:46 +08:00
|
|
|
!(tmp & MII_XGMAC_BUSY), 100, 10000)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_disable_clks;
|
|
|
|
}
|
2018-08-08 09:04:33 +01:00
|
|
|
|
|
|
|
/* Set the MII address register to read */
|
|
|
|
writel(addr, priv->ioaddr + mii_address);
|
|
|
|
writel(value, priv->ioaddr + mii_data);
|
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_data, tmp,
|
2021-03-15 20:16:46 +08:00
|
|
|
!(tmp & MII_XGMAC_BUSY), 100, 10000)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_disable_clks;
|
|
|
|
}
|
2018-08-08 09:04:33 +01:00
|
|
|
|
|
|
|
/* Read the data from the MII data register */
|
2021-03-15 20:16:46 +08:00
|
|
|
ret = (int)readl(priv->ioaddr + mii_data) & GENMASK(15, 0);
|
|
|
|
|
|
|
|
err_disable_clks:
|
|
|
|
pm_runtime_put(priv->device);
|
|
|
|
|
|
|
|
return ret;
|
2018-08-08 09:04:33 +01:00
|
|
|
}
|
|
|
|
|
2023-01-12 16:15:14 +01:00
|
|
|
static int stmmac_xgmac2_mdio_read_c22(struct mii_bus *bus, int phyaddr,
|
|
|
|
int phyreg)
|
2018-08-08 09:04:33 +01:00
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
2023-01-12 16:15:14 +01:00
|
|
|
struct stmmac_priv *priv;
|
|
|
|
u32 addr;
|
|
|
|
|
|
|
|
priv = netdev_priv(ndev);
|
|
|
|
|
2023-07-31 19:50:41 +08:00
|
|
|
/* Until ver 2.20 XGMAC does not support C22 addr >= 4 */
|
|
|
|
if (priv->synopsys_id < DWXGMAC_CORE_2_20 &&
|
|
|
|
phyaddr > MII_XGMAC_MAX_C22ADDR)
|
2023-01-12 16:15:14 +01:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
stmmac_xgmac2_c22_format(priv, phyaddr, phyreg, &addr);
|
|
|
|
|
|
|
|
return stmmac_xgmac2_mdio_read(priv, addr, MII_XGMAC_BUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stmmac_xgmac2_mdio_read_c45(struct mii_bus *bus, int phyaddr,
|
|
|
|
int devad, int phyreg)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv;
|
|
|
|
u32 addr;
|
|
|
|
|
|
|
|
priv = netdev_priv(ndev);
|
|
|
|
|
|
|
|
stmmac_xgmac2_c45_format(priv, phyaddr, devad, phyreg, &addr);
|
|
|
|
|
|
|
|
return stmmac_xgmac2_mdio_read(priv, addr, MII_XGMAC_BUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stmmac_xgmac2_mdio_write(struct stmmac_priv *priv, u32 addr,
|
|
|
|
u32 value, u16 phydata)
|
|
|
|
{
|
2018-08-08 09:04:33 +01:00
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
|
|
|
unsigned int mii_data = priv->hw->mii.data;
|
2023-01-12 16:15:14 +01:00
|
|
|
u32 tmp;
|
2018-08-08 09:04:33 +01:00
|
|
|
int ret;
|
|
|
|
|
2022-04-08 08:12:50 +00:00
|
|
|
ret = pm_runtime_resume_and_get(priv->device);
|
|
|
|
if (ret < 0)
|
2021-03-15 20:16:46 +08:00
|
|
|
return ret;
|
|
|
|
|
2019-11-11 15:42:36 +01:00
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_data, tmp,
|
2021-03-15 20:16:46 +08:00
|
|
|
!(tmp & MII_XGMAC_BUSY), 100, 10000)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_disable_clks;
|
|
|
|
}
|
2019-11-11 15:42:36 +01:00
|
|
|
|
2018-08-08 09:04:33 +01:00
|
|
|
value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
|
|
|
|
& priv->hw->mii.clk_csr_mask;
|
2019-11-11 15:42:36 +01:00
|
|
|
value |= phydata;
|
2018-08-08 09:04:33 +01:00
|
|
|
value |= MII_XGMAC_WRITE;
|
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_data, tmp,
|
2021-03-15 20:16:46 +08:00
|
|
|
!(tmp & MII_XGMAC_BUSY), 100, 10000)) {
|
|
|
|
ret = -EBUSY;
|
|
|
|
goto err_disable_clks;
|
|
|
|
}
|
2018-08-08 09:04:33 +01:00
|
|
|
|
|
|
|
/* Set the MII address register to write */
|
|
|
|
writel(addr, priv->ioaddr + mii_address);
|
|
|
|
writel(value, priv->ioaddr + mii_data);
|
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
2021-03-15 20:16:46 +08:00
|
|
|
ret = readl_poll_timeout(priv->ioaddr + mii_data, tmp,
|
|
|
|
!(tmp & MII_XGMAC_BUSY), 100, 10000);
|
|
|
|
|
|
|
|
err_disable_clks:
|
|
|
|
pm_runtime_put(priv->device);
|
|
|
|
|
|
|
|
return ret;
|
2018-08-08 09:04:33 +01:00
|
|
|
}
|
|
|
|
|
2023-01-12 16:15:14 +01:00
|
|
|
static int stmmac_xgmac2_mdio_write_c22(struct mii_bus *bus, int phyaddr,
|
|
|
|
int phyreg, u16 phydata)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv;
|
|
|
|
u32 addr;
|
|
|
|
|
|
|
|
priv = netdev_priv(ndev);
|
|
|
|
|
2023-07-31 19:50:41 +08:00
|
|
|
/* Until ver 2.20 XGMAC does not support C22 addr >= 4 */
|
|
|
|
if (priv->synopsys_id < DWXGMAC_CORE_2_20 &&
|
|
|
|
phyaddr > MII_XGMAC_MAX_C22ADDR)
|
2023-01-12 16:15:14 +01:00
|
|
|
return -ENODEV;
|
|
|
|
|
|
|
|
stmmac_xgmac2_c22_format(priv, phyaddr, phyreg, &addr);
|
|
|
|
|
|
|
|
return stmmac_xgmac2_mdio_write(priv, addr,
|
|
|
|
MII_XGMAC_BUSY | MII_XGMAC_SADDR, phydata);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int stmmac_xgmac2_mdio_write_c45(struct mii_bus *bus, int phyaddr,
|
|
|
|
int devad, int phyreg, u16 phydata)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv;
|
|
|
|
u32 addr;
|
|
|
|
|
|
|
|
priv = netdev_priv(ndev);
|
|
|
|
|
|
|
|
stmmac_xgmac2_c45_format(priv, phyaddr, devad, phyreg, &addr);
|
|
|
|
|
|
|
|
return stmmac_xgmac2_mdio_write(priv, addr, MII_XGMAC_BUSY,
|
|
|
|
phydata);
|
|
|
|
}
|
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
static int stmmac_mdio_read(struct stmmac_priv *priv, int data, u32 value)
|
|
|
|
{
|
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
|
|
|
unsigned int mii_data = priv->hw->mii.data;
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
|
|
|
|
100, 10000))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
writel(data, priv->ioaddr + mii_data);
|
|
|
|
writel(value, priv->ioaddr + mii_address);
|
|
|
|
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
|
|
|
|
100, 10000))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* Read the data from the MII data register */
|
|
|
|
return readl(priv->ioaddr + mii_data) & MII_DATA_MASK;
|
|
|
|
}
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
/**
|
2023-01-12 16:15:15 +01:00
|
|
|
* stmmac_mdio_read_c22
|
2009-10-14 15:13:45 -07:00
|
|
|
* @bus: points to the mii_bus structure
|
2016-12-01 16:19:41 +01:00
|
|
|
* @phyaddr: MII addr
|
|
|
|
* @phyreg: MII reg
|
2009-10-14 15:13:45 -07:00
|
|
|
* Description: it reads data from the MII register from within the phy device.
|
|
|
|
* For the 7111 GMAC, we must set the bit 0 in the MII address register while
|
|
|
|
* accessing the PHY registers.
|
|
|
|
* Fortunately, it seems this has no drawback for the 7109 MAC.
|
|
|
|
*/
|
2023-01-12 16:15:15 +01:00
|
|
|
static int stmmac_mdio_read_c22(struct mii_bus *bus, int phyaddr, int phyreg)
|
2009-10-14 15:13:45 -07:00
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2016-12-01 16:19:41 +01:00
|
|
|
u32 value = MII_BUSY;
|
2019-07-06 01:33:27 +08:00
|
|
|
int data = 0;
|
2016-12-01 16:19:41 +01:00
|
|
|
|
2022-04-08 08:12:50 +00:00
|
|
|
data = pm_runtime_resume_and_get(priv->device);
|
|
|
|
if (data < 0)
|
2021-03-15 20:16:46 +08:00
|
|
|
return data;
|
|
|
|
|
2016-12-01 16:19:41 +01:00
|
|
|
value |= (phyaddr << priv->hw->mii.addr_shift)
|
|
|
|
& priv->hw->mii.addr_mask;
|
|
|
|
value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask;
|
2016-12-23 10:15:59 +00:00
|
|
|
value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
|
|
|
|
& priv->hw->mii.clk_csr_mask;
|
2023-04-11 15:04:02 -05:00
|
|
|
if (priv->plat->has_gmac4)
|
2016-12-01 16:19:41 +01:00
|
|
|
value |= MII_GMAC4_READ;
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
data = stmmac_mdio_read(priv, data, value);
|
2012-04-04 04:33:24 +00:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
pm_runtime_put(priv->device);
|
2012-04-04 04:33:24 +00:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_read_c45
|
|
|
|
* @bus: points to the mii_bus structure
|
|
|
|
* @phyaddr: MII addr
|
|
|
|
* @devad: device address to read
|
|
|
|
* @phyreg: MII reg
|
|
|
|
* Description: it reads data from the MII register from within the phy device.
|
|
|
|
* For the 7111 GMAC, we must set the bit 0 in the MII address register while
|
|
|
|
* accessing the PHY registers.
|
|
|
|
* Fortunately, it seems this has no drawback for the 7109 MAC.
|
|
|
|
*/
|
|
|
|
static int stmmac_mdio_read_c45(struct mii_bus *bus, int phyaddr, int devad,
|
|
|
|
int phyreg)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
|
|
|
u32 value = MII_BUSY;
|
|
|
|
int data = 0;
|
|
|
|
|
|
|
|
data = pm_runtime_get_sync(priv->device);
|
|
|
|
if (data < 0) {
|
|
|
|
pm_runtime_put_noidle(priv->device);
|
|
|
|
return data;
|
2021-03-15 20:16:46 +08:00
|
|
|
}
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
value |= (phyaddr << priv->hw->mii.addr_shift)
|
|
|
|
& priv->hw->mii.addr_mask;
|
|
|
|
value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask;
|
|
|
|
value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
|
|
|
|
& priv->hw->mii.clk_csr_mask;
|
|
|
|
value |= MII_GMAC4_READ;
|
|
|
|
value |= MII_GMAC4_C45E;
|
|
|
|
value &= ~priv->hw->mii.reg_mask;
|
|
|
|
value |= (devad << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask;
|
|
|
|
|
|
|
|
data |= phyreg << MII_GMAC4_REG_ADDR_SHIFT;
|
|
|
|
|
|
|
|
data = stmmac_mdio_read(priv, data, value);
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2021-03-15 20:16:46 +08:00
|
|
|
pm_runtime_put(priv->device);
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
static int stmmac_mdio_write(struct stmmac_priv *priv, int data, u32 value)
|
|
|
|
{
|
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
|
|
|
unsigned int mii_data = priv->hw->mii.data;
|
|
|
|
u32 v;
|
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
if (readl_poll_timeout(priv->ioaddr + mii_address, v, !(v & MII_BUSY),
|
|
|
|
100, 10000))
|
|
|
|
return -EBUSY;
|
|
|
|
|
|
|
|
/* Set the MII address register to write */
|
|
|
|
writel(data, priv->ioaddr + mii_data);
|
|
|
|
writel(value, priv->ioaddr + mii_address);
|
|
|
|
|
|
|
|
/* Wait until any existing MII operation is complete */
|
|
|
|
return readl_poll_timeout(priv->ioaddr + mii_address, v,
|
|
|
|
!(v & MII_BUSY), 100, 10000);
|
|
|
|
}
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
/**
|
2023-01-12 16:15:15 +01:00
|
|
|
* stmmac_mdio_write_c22
|
2009-10-14 15:13:45 -07:00
|
|
|
* @bus: points to the mii_bus structure
|
2016-12-01 16:19:41 +01:00
|
|
|
* @phyaddr: MII addr
|
|
|
|
* @phyreg: MII reg
|
2009-10-14 15:13:45 -07:00
|
|
|
* @phydata: phy data
|
|
|
|
* Description: it writes the data into the MII register from within the device.
|
|
|
|
*/
|
2023-01-12 16:15:15 +01:00
|
|
|
static int stmmac_mdio_write_c22(struct mii_bus *bus, int phyaddr, int phyreg,
|
|
|
|
u16 phydata)
|
2009-10-14 15:13:45 -07:00
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2021-03-15 20:16:46 +08:00
|
|
|
int ret, data = phydata;
|
2016-12-28 04:07:41 +08:00
|
|
|
u32 value = MII_BUSY;
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2022-04-08 08:12:50 +00:00
|
|
|
ret = pm_runtime_resume_and_get(priv->device);
|
|
|
|
if (ret < 0)
|
2021-03-15 20:16:46 +08:00
|
|
|
return ret;
|
|
|
|
|
2016-12-01 16:19:41 +01:00
|
|
|
value |= (phyaddr << priv->hw->mii.addr_shift)
|
|
|
|
& priv->hw->mii.addr_mask;
|
|
|
|
value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask;
|
2010-09-17 03:23:39 +00:00
|
|
|
|
2016-12-23 10:15:59 +00:00
|
|
|
value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
|
|
|
|
& priv->hw->mii.clk_csr_mask;
|
2023-01-12 16:15:15 +01:00
|
|
|
if (priv->plat->has_gmac4)
|
2016-12-01 16:19:41 +01:00
|
|
|
value |= MII_GMAC4_WRITE;
|
2023-01-12 16:15:15 +01:00
|
|
|
else
|
2016-12-28 04:07:41 +08:00
|
|
|
value |= MII_WRITE;
|
2016-04-28 15:56:45 +02:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
ret = stmmac_mdio_write(priv, data, value);
|
|
|
|
|
|
|
|
pm_runtime_put(priv->device);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_write_c45
|
|
|
|
* @bus: points to the mii_bus structure
|
|
|
|
* @phyaddr: MII addr
|
|
|
|
* @phyreg: MII reg
|
|
|
|
* @devad: device address to read
|
|
|
|
* @phydata: phy data
|
|
|
|
* Description: it writes the data into the MII register from within the device.
|
|
|
|
*/
|
|
|
|
static int stmmac_mdio_write_c45(struct mii_bus *bus, int phyaddr,
|
|
|
|
int devad, int phyreg, u16 phydata)
|
|
|
|
{
|
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
|
|
|
int ret, data = phydata;
|
|
|
|
u32 value = MII_BUSY;
|
|
|
|
|
|
|
|
ret = pm_runtime_get_sync(priv->device);
|
|
|
|
if (ret < 0) {
|
|
|
|
pm_runtime_put_noidle(priv->device);
|
|
|
|
return ret;
|
2021-03-15 20:16:46 +08:00
|
|
|
}
|
2016-04-28 15:56:45 +02:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
value |= (phyaddr << priv->hw->mii.addr_shift)
|
|
|
|
& priv->hw->mii.addr_mask;
|
|
|
|
value |= (phyreg << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask;
|
2016-04-28 15:56:45 +02:00
|
|
|
|
2023-01-12 16:15:15 +01:00
|
|
|
value |= (priv->clk_csr << priv->hw->mii.clk_csr_shift)
|
|
|
|
& priv->hw->mii.clk_csr_mask;
|
|
|
|
|
|
|
|
value |= MII_GMAC4_WRITE;
|
|
|
|
value |= MII_GMAC4_C45E;
|
|
|
|
value &= ~priv->hw->mii.reg_mask;
|
|
|
|
value |= (devad << priv->hw->mii.reg_shift) & priv->hw->mii.reg_mask;
|
|
|
|
|
|
|
|
data |= phyreg << MII_GMAC4_REG_ADDR_SHIFT;
|
|
|
|
|
|
|
|
ret = stmmac_mdio_write(priv, data, value);
|
2021-03-15 20:16:46 +08:00
|
|
|
|
|
|
|
pm_runtime_put(priv->device);
|
|
|
|
|
|
|
|
return ret;
|
2016-04-28 15:56:45 +02:00
|
|
|
}
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
/**
|
|
|
|
* stmmac_mdio_reset
|
|
|
|
* @bus: points to the mii_bus structure
|
|
|
|
* Description: reset the MII bus
|
|
|
|
*/
|
2014-01-16 10:52:27 +00:00
|
|
|
int stmmac_mdio_reset(struct mii_bus *bus)
|
2009-10-14 15:13:45 -07:00
|
|
|
{
|
2018-10-31 16:08:10 +01:00
|
|
|
#if IS_ENABLED(CONFIG_STMMAC_PLATFORM)
|
2009-10-14 15:13:45 -07:00
|
|
|
struct net_device *ndev = bus->priv;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2010-01-06 23:07:17 +00:00
|
|
|
unsigned int mii_address = priv->hw->mii.addr;
|
2013-07-04 10:35:48 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_OF
|
|
|
|
if (priv->device->of_node) {
|
2019-06-12 21:31:15 +02:00
|
|
|
struct gpio_desc *reset_gpio;
|
2019-06-18 22:39:27 +02:00
|
|
|
u32 delays[3] = { 0, 0, 0 };
|
2019-06-12 21:31:15 +02:00
|
|
|
|
2019-06-15 12:09:30 +02:00
|
|
|
reset_gpio = devm_gpiod_get_optional(priv->device,
|
|
|
|
"snps,reset",
|
|
|
|
GPIOD_OUT_LOW);
|
|
|
|
if (IS_ERR(reset_gpio))
|
|
|
|
return PTR_ERR(reset_gpio);
|
|
|
|
|
2019-07-02 00:42:25 +02:00
|
|
|
device_property_read_u32_array(priv->device,
|
|
|
|
"snps,reset-delays-us",
|
|
|
|
delays, ARRAY_SIZE(delays));
|
2013-07-04 10:35:48 +01:00
|
|
|
|
2019-06-15 12:09:31 +02:00
|
|
|
if (delays[0])
|
|
|
|
msleep(DIV_ROUND_UP(delays[0], 1000));
|
2015-09-11 22:25:48 +02:00
|
|
|
|
2019-06-12 21:31:15 +02:00
|
|
|
gpiod_set_value_cansleep(reset_gpio, 1);
|
2019-06-15 12:09:31 +02:00
|
|
|
if (delays[1])
|
|
|
|
msleep(DIV_ROUND_UP(delays[1], 1000));
|
2015-09-11 22:25:48 +02:00
|
|
|
|
2019-06-12 21:31:15 +02:00
|
|
|
gpiod_set_value_cansleep(reset_gpio, 0);
|
2019-06-15 12:09:31 +02:00
|
|
|
if (delays[2])
|
|
|
|
msleep(DIV_ROUND_UP(delays[2], 1000));
|
2013-07-04 10:35:48 +01:00
|
|
|
}
|
|
|
|
#endif
|
2009-10-14 15:13:45 -07:00
|
|
|
|
|
|
|
/* This is a workaround for problems with the STE101P PHY.
|
|
|
|
* It doesn't complete its reset until at least one clock cycle
|
2017-02-08 09:31:08 +01:00
|
|
|
* on MDC, so perform a dummy mdio read. To be updated for GMAC4
|
2016-04-28 15:56:45 +02:00
|
|
|
* if needed.
|
2009-10-14 15:13:45 -07:00
|
|
|
*/
|
2016-04-28 15:56:45 +02:00
|
|
|
if (!priv->plat->has_gmac4)
|
|
|
|
writel(0, priv->ioaddr + mii_address);
|
2011-12-21 03:58:19 +00:00
|
|
|
#endif
|
2009-10-14 15:13:45 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-13 09:25:14 +02:00
|
|
|
int stmmac_pcs_setup(struct net_device *ndev)
|
2021-06-08 11:51:56 +08:00
|
|
|
{
|
2024-07-01 21:28:41 +03:00
|
|
|
struct fwnode_handle *devnode, *pcsnode;
|
2024-05-13 09:25:14 +02:00
|
|
|
struct dw_xpcs *xpcs = NULL;
|
2021-06-11 23:05:20 +03:00
|
|
|
struct stmmac_priv *priv;
|
2024-10-01 17:04:51 +01:00
|
|
|
int addr, ret;
|
2021-06-08 11:51:56 +08:00
|
|
|
|
|
|
|
priv = netdev_priv(ndev);
|
2024-07-01 21:28:41 +03:00
|
|
|
devnode = priv->plat->port_node;
|
2021-06-08 11:51:56 +08:00
|
|
|
|
2024-05-13 09:25:15 +02:00
|
|
|
if (priv->plat->pcs_init) {
|
|
|
|
ret = priv->plat->pcs_init(priv);
|
2024-07-01 21:28:41 +03:00
|
|
|
} else if (fwnode_property_present(devnode, "pcs-handle")) {
|
|
|
|
pcsnode = fwnode_find_reference(devnode, "pcs-handle", 0);
|
2024-10-01 17:04:51 +01:00
|
|
|
xpcs = xpcs_create_fwnode(pcsnode);
|
2024-07-01 21:28:41 +03:00
|
|
|
fwnode_handle_put(pcsnode);
|
|
|
|
ret = PTR_ERR_OR_ZERO(xpcs);
|
2024-05-13 09:25:15 +02:00
|
|
|
} else if (priv->plat->mdio_bus_data &&
|
2024-07-01 21:28:40 +03:00
|
|
|
priv->plat->mdio_bus_data->pcs_mask) {
|
|
|
|
addr = ffs(priv->plat->mdio_bus_data->pcs_mask) - 1;
|
2024-10-01 17:04:51 +01:00
|
|
|
xpcs = xpcs_create_mdiodev(priv->mii, addr);
|
2024-07-01 21:28:40 +03:00
|
|
|
ret = PTR_ERR_OR_ZERO(xpcs);
|
2024-05-13 09:25:14 +02:00
|
|
|
} else {
|
|
|
|
return 0;
|
2021-06-08 11:51:56 +08:00
|
|
|
}
|
|
|
|
|
2024-07-01 21:28:41 +03:00
|
|
|
if (ret)
|
|
|
|
return dev_err_probe(priv->device, ret, "No xPCS found\n");
|
2021-06-08 11:51:56 +08:00
|
|
|
|
2025-03-21 11:35:01 +01:00
|
|
|
if (xpcs)
|
|
|
|
xpcs_config_eee_mult_fact(xpcs, priv->plat->mult_fact_100ns);
|
2025-02-10 10:53:50 +00:00
|
|
|
|
2024-05-13 09:25:14 +02:00
|
|
|
priv->hw->xpcs = xpcs;
|
|
|
|
|
2021-06-08 11:51:56 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2024-05-13 09:25:13 +02:00
|
|
|
void stmmac_pcs_clean(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
|
|
|
|
2024-05-13 09:25:15 +02:00
|
|
|
if (priv->plat->pcs_exit)
|
|
|
|
priv->plat->pcs_exit(priv);
|
|
|
|
|
2024-05-13 09:25:13 +02:00
|
|
|
if (!priv->hw->xpcs)
|
|
|
|
return;
|
|
|
|
|
|
|
|
xpcs_destroy(priv->hw->xpcs);
|
|
|
|
priv->hw->xpcs = NULL;
|
|
|
|
}
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
/**
|
|
|
|
* stmmac_mdio_register
|
|
|
|
* @ndev: net device structure
|
|
|
|
* Description: it registers the MII bus
|
|
|
|
*/
|
|
|
|
int stmmac_mdio_register(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
int err = 0;
|
|
|
|
struct mii_bus *new_bus;
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
2011-07-20 00:05:23 +00:00
|
|
|
struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
|
2016-04-01 09:07:16 +02:00
|
|
|
struct device_node *mdio_node = priv->plat->mdio_node;
|
2017-08-10 16:56:05 +02:00
|
|
|
struct device *dev = ndev->dev.parent;
|
2022-06-15 16:39:08 +08:00
|
|
|
struct fwnode_handle *fixed_node;
|
2023-08-24 14:37:58 +01:00
|
|
|
struct fwnode_handle *fwnode;
|
2018-08-08 09:04:33 +01:00
|
|
|
int addr, found, max_addr;
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2011-07-20 00:05:23 +00:00
|
|
|
if (!mdio_bus_data)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
new_bus = mdiobus_alloc();
|
2017-02-08 09:31:11 +01:00
|
|
|
if (!new_bus)
|
2009-10-14 15:13:45 -07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2016-01-06 20:11:15 +01:00
|
|
|
if (mdio_bus_data->irqs)
|
2016-05-26 00:40:23 +02:00
|
|
|
memcpy(new_bus->irq, mdio_bus_data->irqs, sizeof(new_bus->irq));
|
2009-10-14 15:13:45 -07:00
|
|
|
|
2012-01-23 23:26:48 +00:00
|
|
|
new_bus->name = "stmmac";
|
2018-08-08 09:04:33 +01:00
|
|
|
|
|
|
|
if (priv->plat->has_xgmac) {
|
2023-01-12 16:15:14 +01:00
|
|
|
new_bus->read = &stmmac_xgmac2_mdio_read_c22;
|
|
|
|
new_bus->write = &stmmac_xgmac2_mdio_write_c22;
|
|
|
|
new_bus->read_c45 = &stmmac_xgmac2_mdio_read_c45;
|
|
|
|
new_bus->write_c45 = &stmmac_xgmac2_mdio_write_c45;
|
2018-08-08 09:04:33 +01:00
|
|
|
|
2023-07-31 19:50:41 +08:00
|
|
|
if (priv->synopsys_id < DWXGMAC_CORE_2_20) {
|
|
|
|
/* Right now only C22 phys are supported */
|
|
|
|
max_addr = MII_XGMAC_MAX_C22ADDR + 1;
|
2018-08-08 09:04:33 +01:00
|
|
|
|
2023-07-31 19:50:41 +08:00
|
|
|
/* Check if DT specified an unsupported phy addr */
|
|
|
|
if (priv->plat->phy_addr > MII_XGMAC_MAX_C22ADDR)
|
|
|
|
dev_err(dev, "Unsupported phy_addr (max=%d)\n",
|
2018-08-08 09:04:33 +01:00
|
|
|
MII_XGMAC_MAX_C22ADDR);
|
2023-07-31 19:50:41 +08:00
|
|
|
} else {
|
|
|
|
/* XGMAC version 2.20 onwards support 32 phy addr */
|
|
|
|
max_addr = PHY_MAX_ADDR;
|
|
|
|
}
|
2018-08-08 09:04:33 +01:00
|
|
|
} else {
|
2023-01-12 16:15:15 +01:00
|
|
|
new_bus->read = &stmmac_mdio_read_c22;
|
|
|
|
new_bus->write = &stmmac_mdio_write_c22;
|
|
|
|
if (priv->plat->has_gmac4) {
|
|
|
|
new_bus->read_c45 = &stmmac_mdio_read_c45;
|
|
|
|
new_bus->write_c45 = &stmmac_mdio_write_c45;
|
|
|
|
}
|
|
|
|
|
2018-08-08 09:04:33 +01:00
|
|
|
max_addr = PHY_MAX_ADDR;
|
|
|
|
}
|
2016-04-28 15:56:45 +02:00
|
|
|
|
2019-07-26 12:27:40 +02:00
|
|
|
if (mdio_bus_data->needs_reset)
|
|
|
|
new_bus->reset = &stmmac_mdio_reset;
|
|
|
|
|
2012-01-09 23:59:20 +00:00
|
|
|
snprintf(new_bus->id, MII_BUS_ID_SIZE, "%s-%x",
|
2013-04-08 02:10:01 +00:00
|
|
|
new_bus->name, priv->plat->bus_id);
|
2009-10-14 15:13:45 -07:00
|
|
|
new_bus->priv = ndev;
|
2024-07-01 21:28:40 +03:00
|
|
|
new_bus->phy_mask = mdio_bus_data->phy_mask | mdio_bus_data->pcs_mask;
|
2009-10-14 15:13:45 -07:00
|
|
|
new_bus->parent = priv->device;
|
2015-12-14 11:31:59 +08:00
|
|
|
|
2018-05-15 16:56:19 -07:00
|
|
|
err = of_mdiobus_register(new_bus, mdio_node);
|
2023-12-12 16:18:33 -06:00
|
|
|
if (err == -ENODEV) {
|
|
|
|
err = 0;
|
|
|
|
dev_info(dev, "MDIO bus is disabled\n");
|
|
|
|
goto bus_register_fail;
|
|
|
|
} else if (err) {
|
2022-06-02 09:48:40 +02:00
|
|
|
dev_err_probe(dev, err, "Cannot register the MDIO bus\n");
|
2009-10-14 15:13:45 -07:00
|
|
|
goto bus_register_fail;
|
|
|
|
}
|
|
|
|
|
2019-11-11 15:42:36 +01:00
|
|
|
/* Looks like we need a dummy read for XGMAC only and C45 PHYs */
|
|
|
|
if (priv->plat->has_xgmac)
|
2023-01-12 16:15:14 +01:00
|
|
|
stmmac_xgmac2_mdio_read_c45(new_bus, 0, 0, 0);
|
2019-11-11 15:42:36 +01:00
|
|
|
|
2022-06-15 16:39:08 +08:00
|
|
|
/* If fixed-link is set, skip PHY scanning */
|
2023-08-24 14:37:58 +01:00
|
|
|
fwnode = priv->plat->port_node;
|
2022-06-15 16:39:08 +08:00
|
|
|
if (!fwnode)
|
|
|
|
fwnode = dev_fwnode(priv->device);
|
|
|
|
|
|
|
|
if (fwnode) {
|
|
|
|
fixed_node = fwnode_get_named_child_node(fwnode, "fixed-link");
|
|
|
|
if (fixed_node) {
|
|
|
|
fwnode_handle_put(fixed_node);
|
|
|
|
goto bus_register_done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-15 15:34:33 +08:00
|
|
|
if (priv->plat->phy_node || mdio_node)
|
|
|
|
goto bus_register_done;
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
found = 0;
|
2018-08-08 09:04:33 +01:00
|
|
|
for (addr = 0; addr < max_addr; addr++) {
|
2016-01-06 20:11:18 +01:00
|
|
|
struct phy_device *phydev = mdiobus_get_phy(new_bus, addr);
|
2017-02-15 10:46:44 +01:00
|
|
|
|
|
|
|
if (!phydev)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If an IRQ was provided to be assigned after
|
|
|
|
* the bus probe, do it here.
|
|
|
|
*/
|
|
|
|
if (!mdio_bus_data->irqs &&
|
|
|
|
(mdio_bus_data->probed_phy_irq > 0)) {
|
|
|
|
new_bus->irq[addr] = mdio_bus_data->probed_phy_irq;
|
|
|
|
phydev->irq = mdio_bus_data->probed_phy_irq;
|
|
|
|
}
|
2017-02-08 09:31:11 +01:00
|
|
|
|
2017-02-15 10:46:44 +01:00
|
|
|
/*
|
|
|
|
* If we're going to bind the MAC to this PHY bus,
|
|
|
|
* and no PHY number was provided to the MAC,
|
|
|
|
* use the one probed here.
|
|
|
|
*/
|
|
|
|
if (priv->plat->phy_addr == -1)
|
|
|
|
priv->plat->phy_addr = addr;
|
|
|
|
|
2017-08-10 16:56:05 +02:00
|
|
|
phy_attached_info(phydev);
|
2017-02-15 10:46:44 +01:00
|
|
|
found = 1;
|
2009-10-14 15:13:45 -07:00
|
|
|
}
|
|
|
|
|
net: stmmac: the XPCS obscures a potential "PHY not found" error
stmmac_mdio_register() has logic to search for PHYs on the MDIO bus and
assign them IRQ lines, as well as to set priv->plat->phy_addr.
If no PHY is found, the "found" variable remains set to 0 and the
function errors out.
After the introduction of commit f213bbe8a9d6 ("net: stmmac: Integrate
it with DesignWare XPCS"), the "found" variable was immediately reused
for searching for a PCS on the same MDIO bus.
This can result in 2 types of potential problems (none of them seems to
be seen on the only Intel system that sets has_xpcs = true, otherwise it
would have been reported):
1. If a PCS is found but a PHY is not, then the code happily exits with
no error. One might say "yes, but this is not possible, because
of_mdiobus_register will probe a PHY for all MDIO addresses,
including for the XPCS, so if an XPCS exists, then a PHY certainly
exists too". Well, that is not true, see intel_mgbe_common_data():
/* Ensure mdio bus scan skips intel serdes and pcs-xpcs */
plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR;
plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR;
2. A PHY is found but an MDIO device with the XPCS PHY ID isn't, and in
that case, the error message will be "No PHY found". Confusing.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20210527155959.3270478-1-olteanv@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-05-27 18:59:59 +03:00
|
|
|
if (!found && !mdio_node) {
|
|
|
|
dev_warn(dev, "No PHY found\n");
|
|
|
|
err = -ENODEV;
|
|
|
|
goto no_phy_found;
|
|
|
|
}
|
|
|
|
|
2016-03-15 15:34:33 +08:00
|
|
|
bus_register_done:
|
2013-02-06 20:47:52 +00:00
|
|
|
priv->mii = new_bus;
|
2009-10-14 15:13:45 -07:00
|
|
|
|
|
|
|
return 0;
|
2011-07-20 00:05:23 +00:00
|
|
|
|
net: stmmac: the XPCS obscures a potential "PHY not found" error
stmmac_mdio_register() has logic to search for PHYs on the MDIO bus and
assign them IRQ lines, as well as to set priv->plat->phy_addr.
If no PHY is found, the "found" variable remains set to 0 and the
function errors out.
After the introduction of commit f213bbe8a9d6 ("net: stmmac: Integrate
it with DesignWare XPCS"), the "found" variable was immediately reused
for searching for a PCS on the same MDIO bus.
This can result in 2 types of potential problems (none of them seems to
be seen on the only Intel system that sets has_xpcs = true, otherwise it
would have been reported):
1. If a PCS is found but a PHY is not, then the code happily exits with
no error. One might say "yes, but this is not possible, because
of_mdiobus_register will probe a PHY for all MDIO addresses,
including for the XPCS, so if an XPCS exists, then a PHY certainly
exists too". Well, that is not true, see intel_mgbe_common_data():
/* Ensure mdio bus scan skips intel serdes and pcs-xpcs */
plat->mdio_bus_data->phy_mask = 1 << INTEL_MGBE_ADHOC_ADDR;
plat->mdio_bus_data->phy_mask |= 1 << INTEL_MGBE_XPCS_ADDR;
2. A PHY is found but an MDIO device with the XPCS PHY ID isn't, and in
that case, the error message will be "No PHY found". Confusing.
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Link: https://lore.kernel.org/r/20210527155959.3270478-1-olteanv@gmail.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2021-05-27 18:59:59 +03:00
|
|
|
no_phy_found:
|
|
|
|
mdiobus_unregister(new_bus);
|
2009-10-14 15:13:45 -07:00
|
|
|
bus_register_fail:
|
2011-07-20 00:05:23 +00:00
|
|
|
mdiobus_free(new_bus);
|
2009-10-14 15:13:45 -07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* stmmac_mdio_unregister
|
|
|
|
* @ndev: net device structure
|
|
|
|
* Description: it unregisters the MII bus
|
|
|
|
*/
|
|
|
|
int stmmac_mdio_unregister(struct net_device *ndev)
|
|
|
|
{
|
|
|
|
struct stmmac_priv *priv = netdev_priv(ndev);
|
|
|
|
|
2012-08-30 05:49:58 +00:00
|
|
|
if (!priv->mii)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-14 15:13:45 -07:00
|
|
|
mdiobus_unregister(priv->mii);
|
|
|
|
priv->mii->priv = NULL;
|
2011-07-20 00:05:23 +00:00
|
|
|
mdiobus_free(priv->mii);
|
|
|
|
priv->mii = NULL;
|
2009-10-14 15:13:45 -07:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|