Commit 11059740 authored by Vladimir Oltean's avatar Vladimir Oltean Committed by David S. Miller

net: pcs: xpcs: convert to phylink_pcs_ops

Since all the remaining members of struct mdio_xpcs_ops have direct
equivalents in struct phylink_pcs_ops, it is about time we remove it
altogether.

Since the phylink ops return void, we need to remove the error
propagation from the various xpcs methods and simply print an error
message where appropriate.

Since xpcs_get_state_c73() detects link faults and attempts to reset the
link on its own by calling xpcs_config(), but xpcs_config() now has a
lot of phylink arguments which are not needed and cannot be simply
fabricated by anybody else except phylink, the actual implementation has
been moved into a smaller xpcs_do_config().

The const struct mdio_xpcs_ops *priv->hw->xpcs has been removed, so we
need to look at the struct mdio_xpcs_args pointer now as an indication
whether the port has an XPCS or not.
Signed-off-by: default avatarVladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 2cac15da
...@@ -503,8 +503,7 @@ struct mac_device_info { ...@@ -503,8 +503,7 @@ 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;
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 */
......
...@@ -613,14 +613,6 @@ struct stmmac_mmc_ops { ...@@ -613,14 +613,6 @@ 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_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)
struct stmmac_regs_off { struct stmmac_regs_off {
u32 ptp_off; u32 ptp_off;
u32 mmc_off; u32 mmc_off;
......
...@@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev, ...@@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
"Setting EEE tx-lpi is not supported\n"); "Setting EEE tx-lpi is not supported\n");
if (priv->hw->xpcs) { if (priv->hw->xpcs) {
ret = xpcs_config_eee(priv->hw->xpcs_args, ret = xpcs_config_eee(priv->hw->xpcs,
priv->plat->mult_fact_100ns, priv->plat->mult_fact_100ns,
edata->eee_enabled); edata->eee_enabled);
if (ret) if (ret)
......
...@@ -997,29 +997,13 @@ static void stmmac_validate(struct phylink_config *config, ...@@ -997,29 +997,13 @@ static void stmmac_validate(struct phylink_config *config,
/* If PCS is supported, check which modes it supports. */ /* If PCS is supported, check which modes it supports. */
if (priv->hw->xpcs) if (priv->hw->xpcs)
xpcs_validate(priv->hw->xpcs_args, supported, state); xpcs_validate(priv->hw->xpcs, supported, state);
}
static void stmmac_mac_pcs_get_state(struct phylink_config *config,
struct phylink_link_state *state)
{
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
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)); /* Nothing to do, xpcs_config() handles everything */
stmmac_xpcs_config(priv, priv->hw->xpcs_args, state);
}
static void stmmac_mac_an_restart(struct phylink_config *config)
{
/* Not Supported */
} }
static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool is_up) static void stmmac_fpe_link_state_handle(struct stmmac_priv *priv, bool is_up)
...@@ -1061,8 +1045,6 @@ static void stmmac_mac_link_up(struct phylink_config *config, ...@@ -1061,8 +1045,6 @@ static void stmmac_mac_link_up(struct phylink_config *config,
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev)); 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;
...@@ -1155,9 +1137,7 @@ static void stmmac_mac_link_up(struct phylink_config *config, ...@@ -1155,9 +1137,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
static const struct phylink_mac_ops stmmac_phylink_mac_ops = { static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
.validate = stmmac_validate, .validate = stmmac_validate,
.mac_pcs_get_state = stmmac_mac_pcs_get_state,
.mac_config = stmmac_mac_config, .mac_config = stmmac_mac_config,
.mac_an_restart = stmmac_mac_an_restart,
.mac_link_down = stmmac_mac_link_down, .mac_link_down = stmmac_mac_link_down,
.mac_link_up = stmmac_mac_link_up, .mac_link_up = stmmac_mac_link_up,
}; };
...@@ -1234,6 +1214,7 @@ static int stmmac_init_phy(struct net_device *dev) ...@@ -1234,6 +1214,7 @@ static int stmmac_init_phy(struct net_device *dev)
static int stmmac_phy_setup(struct stmmac_priv *priv) static int stmmac_phy_setup(struct stmmac_priv *priv)
{ {
struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
struct fwnode_handle *fwnode = of_fwnode_handle(priv->plat->phylink_node); struct fwnode_handle *fwnode = of_fwnode_handle(priv->plat->phylink_node);
int mode = priv->plat->phy_interface; int mode = priv->plat->phy_interface;
struct phylink *phylink; struct phylink *phylink;
...@@ -1241,8 +1222,7 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) ...@@ -1241,8 +1222,7 @@ 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; priv->phylink_config.pcs_poll = true;
priv->phylink_config.ovr_an_inband = priv->phylink_config.ovr_an_inband = mdio_bus_data->xpcs_an_inband;
priv->plat->mdio_bus_data->xpcs_an_inband;
if (!fwnode) if (!fwnode)
fwnode = dev_fwnode(priv->device); fwnode = dev_fwnode(priv->device);
...@@ -1252,6 +1232,12 @@ static int stmmac_phy_setup(struct stmmac_priv *priv) ...@@ -1252,6 +1232,12 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
if (IS_ERR(phylink)) if (IS_ERR(phylink))
return PTR_ERR(phylink); return PTR_ERR(phylink);
if (mdio_bus_data->has_xpcs) {
struct mdio_xpcs_args *xpcs = priv->hw->xpcs;
phylink_set_pcs(phylink, &xpcs->pcs);
}
priv->phylink = phylink; priv->phylink = phylink;
return 0; return 0;
} }
...@@ -3653,7 +3639,7 @@ int stmmac_open(struct net_device *dev) ...@@ -3653,7 +3639,7 @@ int stmmac_open(struct net_device *dev)
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 || (!priv->hw->xpcs ||
xpcs_get_an_mode(priv->hw->xpcs_args, mode) != DW_AN_C73)) { xpcs_get_an_mode(priv->hw->xpcs, mode) != DW_AN_C73)) {
ret = stmmac_init_phy(dev); ret = stmmac_init_phy(dev);
if (ret) { if (ret) {
netdev_err(priv->dev, netdev_err(priv->dev,
......
...@@ -444,14 +444,6 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -444,14 +444,6 @@ 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;
...@@ -526,11 +518,11 @@ int stmmac_mdio_register(struct net_device *ndev) ...@@ -526,11 +518,11 @@ int stmmac_mdio_register(struct net_device *ndev)
continue; continue;
} }
priv->hw->xpcs_args = xpcs; priv->hw->xpcs = xpcs;
break; break;
} }
if (!priv->hw->xpcs_args) { if (!priv->hw->xpcs) {
dev_warn(dev, "No XPCS found\n"); dev_warn(dev, "No XPCS found\n");
err = -ENODEV; err = -ENODEV;
goto no_xpcs_found; goto no_xpcs_found;
...@@ -563,8 +555,8 @@ int stmmac_mdio_unregister(struct net_device *ndev) ...@@ -563,8 +555,8 @@ int stmmac_mdio_unregister(struct net_device *ndev)
return 0; return 0;
if (priv->hw->xpcs) { if (priv->hw->xpcs) {
mdio_device_free(priv->hw->xpcs_args->mdiodev); mdio_device_free(priv->hw->xpcs->mdiodev);
xpcs_destroy(priv->hw->xpcs_args); xpcs_destroy(priv->hw->xpcs);
} }
mdiobus_unregister(priv->mii); mdiobus_unregister(priv->mii);
......
...@@ -100,6 +100,9 @@ ...@@ -100,6 +100,9 @@
/* VR MII EEE Control 1 defines */ /* VR MII EEE Control 1 defines */
#define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */ #define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */
#define phylink_pcs_to_xpcs(pl_pcs) \
container_of((pl_pcs), struct mdio_xpcs_args, pcs)
static const int xpcs_usxgmii_features[] = { static const int xpcs_usxgmii_features[] = {
ETHTOOL_LINK_MODE_Pause_BIT, ETHTOOL_LINK_MODE_Pause_BIT,
ETHTOOL_LINK_MODE_Asym_Pause_BIT, ETHTOOL_LINK_MODE_Asym_Pause_BIT,
...@@ -413,7 +416,7 @@ static int xpcs_get_max_usxgmii_speed(const unsigned long *supported) ...@@ -413,7 +416,7 @@ static int xpcs_get_max_usxgmii_speed(const unsigned long *supported)
return max; return max;
} }
static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed) static void xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed)
{ {
int ret, speed_sel; int ret, speed_sel;
...@@ -438,33 +441,40 @@ static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed) ...@@ -438,33 +441,40 @@ static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed)
break; break;
default: default:
/* Nothing to do here */ /* Nothing to do here */
return -EINVAL; return;
} }
ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1); ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1);
if (ret < 0) if (ret < 0)
return ret; goto out;
ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_EN); ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_EN);
if (ret < 0) if (ret < 0)
return ret; goto out;
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1); ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1);
if (ret < 0) if (ret < 0)
return ret; goto out;
ret &= ~DW_USXGMII_SS_MASK; ret &= ~DW_USXGMII_SS_MASK;
ret |= speed_sel | DW_USXGMII_FULL; ret |= speed_sel | DW_USXGMII_FULL;
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, ret); ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, ret);
if (ret < 0) if (ret < 0)
return ret; goto out;
ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1); ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1);
if (ret < 0) if (ret < 0)
return ret; goto out;
ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST);
if (ret < 0)
goto out;
return;
return xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST); out:
pr_err("%s: XPCS access returned %pe\n", __func__, ERR_PTR(ret));
} }
static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs, static int _xpcs_config_aneg_c73(struct mdio_xpcs_args *xpcs,
...@@ -794,19 +804,19 @@ static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs) ...@@ -794,19 +804,19 @@ static int xpcs_config_aneg_c37_sgmii(struct mdio_xpcs_args *xpcs)
return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret); return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret);
} }
static int xpcs_config(struct mdio_xpcs_args *xpcs, static int xpcs_do_config(struct mdio_xpcs_args *xpcs,
const struct phylink_link_state *state) phy_interface_t interface, unsigned int mode)
{ {
const struct xpcs_compat *compat; const struct xpcs_compat *compat;
int ret; int ret;
compat = xpcs_find_compat(xpcs->id, state->interface); compat = xpcs_find_compat(xpcs->id, interface);
if (!compat) if (!compat)
return -ENODEV; return -ENODEV;
switch (compat->an_mode) { switch (compat->an_mode) {
case DW_AN_C73: case DW_AN_C73:
if (state->an_enabled) { if (phylink_autoneg_inband(mode)) {
ret = xpcs_config_aneg_c73(xpcs, compat); ret = xpcs_config_aneg_c73(xpcs, compat);
if (ret) if (ret)
return ret; return ret;
...@@ -824,6 +834,16 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs, ...@@ -824,6 +834,16 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs,
return 0; return 0;
} }
static int xpcs_config(struct phylink_pcs *pcs, unsigned int mode,
phy_interface_t interface,
const unsigned long *advertising,
bool permit_pause_to_mac)
{
struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs);
return xpcs_do_config(xpcs, interface, mode);
}
static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs,
struct phylink_link_state *state, struct phylink_link_state *state,
const struct xpcs_compat *compat) const struct xpcs_compat *compat)
...@@ -842,7 +862,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs, ...@@ -842,7 +862,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs,
state->link = 0; state->link = 0;
return xpcs_config(xpcs, state); return xpcs_do_config(xpcs, state->interface, MLO_AN_INBAND);
} }
if (state->an_enabled && xpcs_aneg_done_c73(xpcs, state, compat)) { if (state->an_enabled && xpcs_aneg_done_c73(xpcs, state, compat)) {
...@@ -899,41 +919,45 @@ static int xpcs_get_state_c37_sgmii(struct mdio_xpcs_args *xpcs, ...@@ -899,41 +919,45 @@ static int xpcs_get_state_c37_sgmii(struct mdio_xpcs_args *xpcs,
return 0; return 0;
} }
static int xpcs_get_state(struct mdio_xpcs_args *xpcs, static void xpcs_get_state(struct phylink_pcs *pcs,
struct phylink_link_state *state) struct phylink_link_state *state)
{ {
struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs);
const struct xpcs_compat *compat; const struct xpcs_compat *compat;
int ret; int ret;
compat = xpcs_find_compat(xpcs->id, state->interface); compat = xpcs_find_compat(xpcs->id, state->interface);
if (!compat) if (!compat)
return -ENODEV; return;
switch (compat->an_mode) { switch (compat->an_mode) {
case DW_AN_C73: case DW_AN_C73:
ret = xpcs_get_state_c73(xpcs, state, compat); ret = xpcs_get_state_c73(xpcs, state, compat);
if (ret) if (ret) {
return ret; pr_err("xpcs_get_state_c73 returned %pe\n",
ERR_PTR(ret));
return;
}
break; break;
case DW_AN_C37_SGMII: case DW_AN_C37_SGMII:
ret = xpcs_get_state_c37_sgmii(xpcs, state); ret = xpcs_get_state_c37_sgmii(xpcs, state);
if (ret) if (ret) {
return ret; pr_err("xpcs_get_state_c37_sgmii returned %pe\n",
ERR_PTR(ret));
}
break; break;
default: default:
return -1; return;
} }
return 0;
} }
static int xpcs_link_up(struct mdio_xpcs_args *xpcs, int speed, static void xpcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
phy_interface_t interface) phy_interface_t interface, int speed, int duplex)
{ {
struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs);
if (interface == PHY_INTERFACE_MODE_USXGMII) if (interface == PHY_INTERFACE_MODE_USXGMII)
return xpcs_config_usxgmii(xpcs, speed); return xpcs_config_usxgmii(xpcs, speed);
return 0;
} }
static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs) static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs)
...@@ -1009,6 +1033,12 @@ static const struct xpcs_id xpcs_id_list[] = { ...@@ -1009,6 +1033,12 @@ static const struct xpcs_id xpcs_id_list[] = {
}, },
}; };
static const struct phylink_pcs_ops xpcs_phylink_ops = {
.pcs_config = xpcs_config,
.pcs_get_state = xpcs_get_state,
.pcs_link_up = xpcs_link_up,
};
struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev, struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
phy_interface_t interface) phy_interface_t interface)
{ {
...@@ -1039,6 +1069,9 @@ struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev, ...@@ -1039,6 +1069,9 @@ struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
goto out; goto out;
} }
xpcs->pcs.ops = &xpcs_phylink_ops;
xpcs->pcs.poll = true;
ret = xpcs_soft_reset(xpcs, compat); ret = xpcs_soft_reset(xpcs, compat);
if (ret) if (ret)
goto out; goto out;
...@@ -1061,16 +1094,4 @@ void xpcs_destroy(struct mdio_xpcs_args *xpcs) ...@@ -1061,16 +1094,4 @@ void xpcs_destroy(struct mdio_xpcs_args *xpcs)
} }
EXPORT_SYMBOL_GPL(xpcs_destroy); EXPORT_SYMBOL_GPL(xpcs_destroy);
static struct mdio_xpcs_ops xpcs_ops = {
.config = xpcs_config,
.get_state = xpcs_get_state,
.link_up = xpcs_link_up,
};
struct mdio_xpcs_ops *mdio_xpcs_get_ops(void)
{
return &xpcs_ops;
}
EXPORT_SYMBOL_GPL(mdio_xpcs_get_ops);
MODULE_LICENSE("GPL v2"); MODULE_LICENSE("GPL v2");
...@@ -19,19 +19,10 @@ struct xpcs_id; ...@@ -19,19 +19,10 @@ struct xpcs_id;
struct mdio_xpcs_args { struct mdio_xpcs_args {
struct mdio_device *mdiodev; struct mdio_device *mdiodev;
const struct xpcs_id *id; const struct xpcs_id *id;
}; struct phylink_pcs pcs;
struct mdio_xpcs_ops {
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 xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface); int xpcs_get_an_mode(struct mdio_xpcs_args *xpcs, phy_interface_t interface);
struct mdio_xpcs_ops *mdio_xpcs_get_ops(void);
void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported, void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported,
struct phylink_link_state *state); struct phylink_link_state *state);
int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns, int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns,
......
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