Commit e442cfc7 authored by David S. Miller's avatar David S. Miller

Merge branch 'net-Add-support-for-Synopsys-DesignWare-XPCS'

Jose Abreu says:

====================
net: Add support for Synopsys DesignWare XPCS

This adds support for Synopsys DesignWare XPCS in net subsystem and
integrates it into stmmac.

At 1/8, we start by removing the limitation of stmmac selftests that needed
a PHY to pass all the tests.

Then at 2/8 we use some helpers in stmmac so that some code can be
simplified.

At 3/8, we fallback to dev_fwnode() so that PCI based setups wich may
not have CONFIG_OF can still use FW node.

At 4/8, we adapt stmmac to the new PHYLINK changes as suggested by Russell
King.

We proceed by doing changes in PHYLINK in order to support XPCS: At 5/8 we
add some missing speeds that USXGMII supports and at 6/8 we check if
Autoneg is supported after initial parameters are validated.

Support for XPCS is finally introduced at 7/8, along with the usage of it
in stmmac driver at 8/8.
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 6c9ee306 f213bbe8
...@@ -16117,6 +16117,13 @@ L: netdev@vger.kernel.org ...@@ -16117,6 +16117,13 @@ L: netdev@vger.kernel.org
S: Supported S: Supported
F: drivers/net/ethernet/synopsys/ F: drivers/net/ethernet/synopsys/
SYNOPSYS DESIGNWARE ETHERNET XPCS DRIVER
M: Jose Abreu <Jose.Abreu@synopsys.com>
L: netdev@vger.kernel.org
S: Supported
F: drivers/net/phy/mdio-xpcs.c
F: include/linux/mdio-xpcs.h
SYNOPSYS DESIGNWARE I2C DRIVER SYNOPSYS DESIGNWARE I2C DRIVER
M: Jarkko Nikula <jarkko.nikula@linux.intel.com> M: Jarkko Nikula <jarkko.nikula@linux.intel.com>
R: Andy Shevchenko <andriy.shevchenko@linux.intel.com> R: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
......
...@@ -3,6 +3,7 @@ config STMMAC_ETH ...@@ -3,6 +3,7 @@ config STMMAC_ETH
tristate "STMicroelectronics Multi-Gigabit Ethernet driver" tristate "STMicroelectronics Multi-Gigabit Ethernet driver"
depends on HAS_IOMEM && HAS_DMA depends on HAS_IOMEM && HAS_DMA
select MII select MII
select MDIO_XPCS
select PAGE_POOL select PAGE_POOL
select PHYLINK select PHYLINK
select CRC32 select CRC32
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <linux/netdevice.h> #include <linux/netdevice.h>
#include <linux/stmmac.h> #include <linux/stmmac.h>
#include <linux/phy.h> #include <linux/phy.h>
#include <linux/mdio-xpcs.h>
#include <linux/module.h> #include <linux/module.h>
#if IS_ENABLED(CONFIG_VLAN_8021Q) #if IS_ENABLED(CONFIG_VLAN_8021Q)
#define STMMAC_VLAN_TAG_USED #define STMMAC_VLAN_TAG_USED
...@@ -446,6 +447,8 @@ struct mac_device_info { ...@@ -446,6 +447,8 @@ struct mac_device_info {
const struct stmmac_hwtimestamp *ptp; const struct stmmac_hwtimestamp *ptp;
const struct stmmac_tc_ops *tc; const struct stmmac_tc_ops *tc;
const struct stmmac_mmc_ops *mmc; const struct stmmac_mmc_ops *mmc;
const struct mdio_xpcs_ops *xpcs;
struct mdio_xpcs_args xpcs_args;
struct mii_regs mii; /* MII register Addresses */ struct mii_regs mii; /* MII register Addresses */
struct mac_link link; struct mac_link link;
void __iomem *pcsr; /* vpointer to device CSRs */ void __iomem *pcsr; /* vpointer to device CSRs */
......
...@@ -577,6 +577,18 @@ struct stmmac_mmc_ops { ...@@ -577,6 +577,18 @@ struct stmmac_mmc_ops {
#define stmmac_mmc_read(__priv, __args...) \ #define stmmac_mmc_read(__priv, __args...) \
stmmac_do_void_callback(__priv, mmc, read, __args) stmmac_do_void_callback(__priv, mmc, read, __args)
/* XPCS callbacks */
#define stmmac_xpcs_validate(__priv, __args...) \
stmmac_do_callback(__priv, xpcs, validate, __args)
#define stmmac_xpcs_config(__priv, __args...) \
stmmac_do_callback(__priv, xpcs, config, __args)
#define stmmac_xpcs_get_state(__priv, __args...) \
stmmac_do_callback(__priv, xpcs, get_state, __args)
#define stmmac_xpcs_link_up(__priv, __args...) \
stmmac_do_callback(__priv, xpcs, link_up, __args)
#define stmmac_xpcs_probe(__priv, __args...) \
stmmac_do_callback(__priv, xpcs, probe, __args)
struct stmmac_regs_off { struct stmmac_regs_off {
u32 ptp_off; u32 ptp_off;
u32 mmc_off; u32 mmc_off;
......
...@@ -858,33 +858,65 @@ static void stmmac_validate(struct phylink_config *config, ...@@ -858,33 +858,65 @@ static void stmmac_validate(struct phylink_config *config,
phylink_set(mask, 1000baseT_Half); phylink_set(mask, 1000baseT_Half);
} }
bitmap_and(supported, supported, mac_supported, linkmode_and(supported, supported, mac_supported);
__ETHTOOL_LINK_MODE_MASK_NBITS); linkmode_andnot(supported, supported, mask);
bitmap_andnot(supported, supported, mask,
__ETHTOOL_LINK_MODE_MASK_NBITS); linkmode_and(state->advertising, state->advertising, mac_supported);
bitmap_and(state->advertising, state->advertising, mac_supported, linkmode_andnot(state->advertising, state->advertising, mask);
__ETHTOOL_LINK_MODE_MASK_NBITS);
bitmap_andnot(state->advertising, state->advertising, mask, /* If PCS is supported, check which modes it supports. */
__ETHTOOL_LINK_MODE_MASK_NBITS); stmmac_xpcs_validate(priv, &priv->hw->xpcs_args, supported, state);
} }
static void stmmac_mac_pcs_get_state(struct phylink_config *config, static void stmmac_mac_pcs_get_state(struct phylink_config *config,
struct phylink_link_state *state) struct phylink_link_state *state)
{ {
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
state->link = 0; state->link = 0;
stmmac_xpcs_get_state(priv, &priv->hw->xpcs_args, state);
} }
static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
const struct phylink_link_state *state) const struct phylink_link_state *state)
{ {
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
stmmac_xpcs_config(priv, &priv->hw->xpcs_args, state);
}
static void stmmac_mac_an_restart(struct phylink_config *config)
{
/* Not Supported */
}
static void stmmac_mac_link_down(struct phylink_config *config,
unsigned int mode, phy_interface_t interface)
{
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
stmmac_mac_set(priv, priv->ioaddr, false);
priv->eee_active = false;
stmmac_eee_init(priv);
stmmac_set_eee_pls(priv, priv->hw, false);
}
static void stmmac_mac_link_up(struct phylink_config *config,
struct phy_device *phy,
unsigned int mode, phy_interface_t interface,
int speed, int duplex,
bool tx_pause, bool rx_pause)
{
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
u32 ctrl; u32 ctrl;
stmmac_xpcs_link_up(priv, &priv->hw->xpcs_args, speed, interface);
ctrl = readl(priv->ioaddr + MAC_CTRL_REG); ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
ctrl &= ~priv->hw->link.speed_mask; ctrl &= ~priv->hw->link.speed_mask;
if (state->interface == PHY_INTERFACE_MODE_USXGMII) { if (interface == PHY_INTERFACE_MODE_USXGMII) {
switch (state->speed) { switch (speed) {
case SPEED_10000: case SPEED_10000:
ctrl |= priv->hw->link.xgmii.speed10000; ctrl |= priv->hw->link.xgmii.speed10000;
break; break;
...@@ -898,7 +930,7 @@ static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, ...@@ -898,7 +930,7 @@ static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
return; return;
} }
} else { } else {
switch (state->speed) { switch (speed) {
case SPEED_2500: case SPEED_2500:
ctrl |= priv->hw->link.speed2500; ctrl |= priv->hw->link.speed2500;
break; break;
...@@ -916,46 +948,21 @@ static void stmmac_mac_config(struct phylink_config *config, unsigned int mode, ...@@ -916,46 +948,21 @@ static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
} }
} }
priv->speed = state->speed; priv->speed = speed;
if (priv->plat->fix_mac_speed) if (priv->plat->fix_mac_speed)
priv->plat->fix_mac_speed(priv->plat->bsp_priv, state->speed); priv->plat->fix_mac_speed(priv->plat->bsp_priv, speed);
if (!state->duplex) if (!duplex)
ctrl &= ~priv->hw->link.duplex; ctrl &= ~priv->hw->link.duplex;
else else
ctrl |= priv->hw->link.duplex; ctrl |= priv->hw->link.duplex;
/* Flow Control operation */ /* Flow Control operation */
if (state->pause) if (tx_pause && rx_pause)
stmmac_mac_flow_ctrl(priv, state->duplex); stmmac_mac_flow_ctrl(priv, duplex);
writel(ctrl, priv->ioaddr + MAC_CTRL_REG); writel(ctrl, priv->ioaddr + MAC_CTRL_REG);
}
static void stmmac_mac_an_restart(struct phylink_config *config)
{
/* Not Supported */
}
static void stmmac_mac_link_down(struct phylink_config *config,
unsigned int mode, phy_interface_t interface)
{
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
stmmac_mac_set(priv, priv->ioaddr, false);
priv->eee_active = false;
stmmac_eee_init(priv);
stmmac_set_eee_pls(priv, priv->hw, false);
}
static void stmmac_mac_link_up(struct phylink_config *config,
struct phy_device *phy,
unsigned int mode, phy_interface_t interface,
int speed, int duplex,
bool tx_pause, bool rx_pause)
{
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
stmmac_mac_set(priv, priv->ioaddr, true); stmmac_mac_set(priv, priv->ioaddr, true);
if (phy && priv->dma_cap.eee) { if (phy && priv->dma_cap.eee) {
...@@ -1045,6 +1052,10 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) ...@@ -1045,6 +1052,10 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
priv->phylink_config.dev = &priv->dev->dev; priv->phylink_config.dev = &priv->dev->dev;
priv->phylink_config.type = PHYLINK_NETDEV; priv->phylink_config.type = PHYLINK_NETDEV;
priv->phylink_config.pcs_poll = true;
if (!fwnode)
fwnode = dev_fwnode(priv->device);
phylink = phylink_create(&priv->phylink_config, fwnode, phylink = phylink_create(&priv->phylink_config, fwnode,
mode, &stmmac_phylink_mac_ops); mode, &stmmac_phylink_mac_ops);
...@@ -2689,7 +2700,8 @@ static int stmmac_open(struct net_device *dev) ...@@ -2689,7 +2700,8 @@ static int stmmac_open(struct net_device *dev)
int ret; int ret;
if (priv->hw->pcs != STMMAC_PCS_TBI && if (priv->hw->pcs != STMMAC_PCS_TBI &&
priv->hw->pcs != STMMAC_PCS_RTBI) { priv->hw->pcs != STMMAC_PCS_RTBI &&
priv->hw->xpcs == NULL) {
ret = stmmac_init_phy(dev); ret = stmmac_init_phy(dev);
if (ret) { if (ret) {
netdev_err(priv->dev, netdev_err(priv->dev,
......
...@@ -382,6 +382,14 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -382,6 +382,14 @@ int stmmac_mdio_register(struct net_device *ndev)
max_addr = PHY_MAX_ADDR; max_addr = PHY_MAX_ADDR;
} }
if (mdio_bus_data->has_xpcs) {
priv->hw->xpcs = mdio_xpcs_get_ops();
if (!priv->hw->xpcs) {
err = -ENODEV;
goto bus_register_fail;
}
}
if (mdio_bus_data->needs_reset) if (mdio_bus_data->needs_reset)
new_bus->reset = &stmmac_mdio_reset; new_bus->reset = &stmmac_mdio_reset;
...@@ -433,6 +441,25 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -433,6 +441,25 @@ int stmmac_mdio_register(struct net_device *ndev)
found = 1; found = 1;
} }
/* Try to probe the XPCS by scanning all addresses. */
if (priv->hw->xpcs) {
struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args;
int ret, mode = priv->plat->phy_interface;
max_addr = PHY_MAX_ADDR;
xpcs->bus = new_bus;
for (addr = 0; addr < max_addr; addr++) {
xpcs->addr = addr;
ret = stmmac_xpcs_probe(priv, xpcs, mode);
if (!ret) {
found = 1;
break;
}
}
}
if (!found && !mdio_node) { if (!found && !mdio_node) {
dev_warn(dev, "No PHY found\n"); dev_warn(dev, "No PHY found\n");
mdiobus_unregister(new_bus); mdiobus_unregister(new_bus);
......
...@@ -380,7 +380,7 @@ static int stmmac_test_phy_loopback(struct stmmac_priv *priv) ...@@ -380,7 +380,7 @@ static int stmmac_test_phy_loopback(struct stmmac_priv *priv)
int ret; int ret;
if (!priv->dev->phydev) if (!priv->dev->phydev)
return -EBUSY; return -EOPNOTSUPP;
ret = phy_loopback(priv->dev->phydev, true); ret = phy_loopback(priv->dev->phydev, true);
if (ret) if (ret)
......
...@@ -214,6 +214,12 @@ config MDIO_XGENE ...@@ -214,6 +214,12 @@ config MDIO_XGENE
This module provides a driver for the MDIO busses found in the This module provides a driver for the MDIO busses found in the
APM X-Gene SoC's. APM X-Gene SoC's.
config MDIO_XPCS
tristate "Synopsys DesignWare XPCS controller"
help
This module provides helper functions for Synopsys DesignWare XPCS
controllers.
endif endif
endif endif
......
...@@ -44,6 +44,7 @@ obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o ...@@ -44,6 +44,7 @@ obj-$(CONFIG_MDIO_OCTEON) += mdio-octeon.o
obj-$(CONFIG_MDIO_SUN4I) += mdio-sun4i.o obj-$(CONFIG_MDIO_SUN4I) += mdio-sun4i.o
obj-$(CONFIG_MDIO_THUNDER) += mdio-thunder.o obj-$(CONFIG_MDIO_THUNDER) += mdio-thunder.o
obj-$(CONFIG_MDIO_XGENE) += mdio-xgene.o obj-$(CONFIG_MDIO_XGENE) += mdio-xgene.o
obj-$(CONFIG_MDIO_XPCS) += mdio-xpcs.o
obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += mii_timestamper.o obj-$(CONFIG_NETWORK_PHY_TIMESTAMPING) += mii_timestamper.o
......
This diff is collapsed.
...@@ -312,11 +312,13 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) ...@@ -312,11 +312,13 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
phylink_set(pl->supported, 1000baseT_Half); phylink_set(pl->supported, 1000baseT_Half);
phylink_set(pl->supported, 1000baseT_Full); phylink_set(pl->supported, 1000baseT_Full);
phylink_set(pl->supported, 1000baseX_Full); phylink_set(pl->supported, 1000baseX_Full);
phylink_set(pl->supported, 1000baseKX_Full);
phylink_set(pl->supported, 2500baseT_Full); phylink_set(pl->supported, 2500baseT_Full);
phylink_set(pl->supported, 2500baseX_Full); phylink_set(pl->supported, 2500baseX_Full);
phylink_set(pl->supported, 5000baseT_Full); phylink_set(pl->supported, 5000baseT_Full);
phylink_set(pl->supported, 10000baseT_Full); phylink_set(pl->supported, 10000baseT_Full);
phylink_set(pl->supported, 10000baseKR_Full); phylink_set(pl->supported, 10000baseKR_Full);
phylink_set(pl->supported, 10000baseKX4_Full);
phylink_set(pl->supported, 10000baseCR_Full); phylink_set(pl->supported, 10000baseCR_Full);
phylink_set(pl->supported, 10000baseSR_Full); phylink_set(pl->supported, 10000baseSR_Full);
phylink_set(pl->supported, 10000baseLR_Full); phylink_set(pl->supported, 10000baseLR_Full);
...@@ -338,6 +340,9 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode) ...@@ -338,6 +340,9 @@ static int phylink_parse_mode(struct phylink *pl, struct fwnode_handle *fwnode)
"failed to validate link configuration for in-band status\n"); "failed to validate link configuration for in-band status\n");
return -EINVAL; return -EINVAL;
} }
/* Check if MAC/PCS also supports Autoneg. */
pl->link_config.an_enabled = phylink_test(pl->supported, Autoneg);
} }
return 0; return 0;
......
/* SPDX-License-Identifier: GPL-2.0 */
/*
* Copyright (c) 2020 Synopsys, Inc. and/or its affiliates.
* Synopsys DesignWare XPCS helpers
*/
#ifndef __LINUX_MDIO_XPCS_H
#define __LINUX_MDIO_XPCS_H
#include <linux/phy.h>
#include <linux/phylink.h>
struct mdio_xpcs_args {
__ETHTOOL_DECLARE_LINK_MODE_MASK(supported);
struct mii_bus *bus;
int addr;
};
struct mdio_xpcs_ops {
int (*validate)(struct mdio_xpcs_args *xpcs,
unsigned long *supported,
struct phylink_link_state *state);
int (*config)(struct mdio_xpcs_args *xpcs,
const struct phylink_link_state *state);
int (*get_state)(struct mdio_xpcs_args *xpcs,
struct phylink_link_state *state);
int (*link_up)(struct mdio_xpcs_args *xpcs, int speed,
phy_interface_t interface);
int (*probe)(struct mdio_xpcs_args *xpcs, phy_interface_t interface);
};
#if IS_ENABLED(CONFIG_MDIO_XPCS)
struct mdio_xpcs_ops *mdio_xpcs_get_ops(void);
#else
static inline struct mdio_xpcs_ops *mdio_xpcs_get_ops(void)
{
return NULL;
}
#endif
#endif /* __LINUX_MDIO_XPCS_H */
...@@ -80,6 +80,7 @@ ...@@ -80,6 +80,7 @@
struct stmmac_mdio_bus_data { struct stmmac_mdio_bus_data {
unsigned int phy_mask; unsigned int phy_mask;
unsigned int has_xpcs;
int *irqs; int *irqs;
int probed_phy_irq; int probed_phy_irq;
bool needs_reset; bool needs_reset;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment