Skip to content

Commit 2cac15d

Browse files
vladimirolteandavem330
authored andcommitted
net: pcs: xpcs: convert to mdio_device
Unify the 2 existing PCS drivers (lynx and xpcs) by doing a similar thing on probe, which is to have a *_create function that takes a struct mdio_device * given by the caller, and builds a private PCS structure around that. This changes stmmac to hold only a pointer to the xpcs, as opposed to the full structure. This will be used in the next patch when struct mdio_xpcs_ops is removed. Currently a pointer to struct mdio_xpcs_ops is used as a shorthand to determine whether the port has an XPCS or not. We can do the same now with the mdio_xpcs_args pointer. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 679e283 commit 2cac15d

6 files changed

Lines changed: 76 additions & 37 deletions

File tree

‎drivers/net/ethernet/stmicro/stmmac/common.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,7 @@ struct mac_device_info {
504504
const struct stmmac_tc_ops *tc;
505505
const struct stmmac_mmc_ops *mmc;
506506
const struct mdio_xpcs_ops *xpcs;
507-
struct mdio_xpcs_args xpcs_args;
507+
struct mdio_xpcs_args *xpcs_args;
508508
struct mii_regs mii; /* MII register Addresses */
509509
struct mac_link link;
510510
void __iomem *pcsr; /* vpointer to device CSRs */

‎drivers/net/ethernet/stmicro/stmmac/stmmac_ethtool.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ static int stmmac_ethtool_op_set_eee(struct net_device *dev,
721721
"Setting EEE tx-lpi is not supported\n");
722722

723723
if (priv->hw->xpcs) {
724-
ret = xpcs_config_eee(&priv->hw->xpcs_args,
724+
ret = xpcs_config_eee(priv->hw->xpcs_args,
725725
priv->plat->mult_fact_100ns,
726726
edata->eee_enabled);
727727
if (ret)

‎drivers/net/ethernet/stmicro/stmmac/stmmac_main.c‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -997,7 +997,7 @@ static void stmmac_validate(struct phylink_config *config,
997997

998998
/* If PCS is supported, check which modes it supports. */
999999
if (priv->hw->xpcs)
1000-
xpcs_validate(&priv->hw->xpcs_args, supported, state);
1000+
xpcs_validate(priv->hw->xpcs_args, supported, state);
10011001
}
10021002

10031003
static void stmmac_mac_pcs_get_state(struct phylink_config *config,
@@ -1006,15 +1006,15 @@ static void stmmac_mac_pcs_get_state(struct phylink_config *config,
10061006
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
10071007

10081008
state->link = 0;
1009-
stmmac_xpcs_get_state(priv, &priv->hw->xpcs_args, state);
1009+
stmmac_xpcs_get_state(priv, priv->hw->xpcs_args, state);
10101010
}
10111011

10121012
static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
10131013
const struct phylink_link_state *state)
10141014
{
10151015
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
10161016

1017-
stmmac_xpcs_config(priv, &priv->hw->xpcs_args, state);
1017+
stmmac_xpcs_config(priv, priv->hw->xpcs_args, state);
10181018
}
10191019

10201020
static void stmmac_mac_an_restart(struct phylink_config *config)
@@ -1061,7 +1061,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
10611061
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
10621062
u32 ctrl;
10631063

1064-
stmmac_xpcs_link_up(priv, &priv->hw->xpcs_args, speed, interface);
1064+
stmmac_xpcs_link_up(priv, priv->hw->xpcs_args, speed, interface);
10651065

10661066
ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
10671067
ctrl &= ~priv->hw->link.speed_mask;
@@ -3653,7 +3653,7 @@ int stmmac_open(struct net_device *dev)
36533653
if (priv->hw->pcs != STMMAC_PCS_TBI &&
36543654
priv->hw->pcs != STMMAC_PCS_RTBI &&
36553655
(!priv->hw->xpcs ||
3656-
xpcs_get_an_mode(&priv->hw->xpcs_args, mode) != DW_AN_C73)) {
3656+
xpcs_get_an_mode(priv->hw->xpcs_args, mode) != DW_AN_C73)) {
36573657
ret = stmmac_init_phy(dev);
36583658
if (ret) {
36593659
netdev_err(priv->dev,

‎drivers/net/ethernet/stmicro/stmmac/stmmac_mdio.c‎

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -510,25 +510,27 @@ int stmmac_mdio_register(struct net_device *ndev)
510510
}
511511

512512
/* Try to probe the XPCS by scanning all addresses. */
513-
if (priv->hw->xpcs) {
514-
struct mdio_xpcs_args *xpcs = &priv->hw->xpcs_args;
515-
int ret, mode = priv->plat->phy_interface;
516-
max_addr = PHY_MAX_ADDR;
517-
518-
xpcs->bus = new_bus;
519-
520-
found = 0;
521-
for (addr = 0; addr < max_addr; addr++) {
522-
xpcs->addr = addr;
523-
524-
ret = xpcs_probe(xpcs, mode);
525-
if (!ret) {
526-
found = 1;
527-
break;
513+
if (mdio_bus_data->has_xpcs) {
514+
int mode = priv->plat->phy_interface;
515+
struct mdio_device *mdiodev;
516+
struct mdio_xpcs_args *xpcs;
517+
518+
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
519+
mdiodev = mdio_device_create(new_bus, addr);
520+
if (IS_ERR(mdiodev))
521+
continue;
522+
523+
xpcs = xpcs_create(mdiodev, mode);
524+
if (IS_ERR_OR_NULL(xpcs)) {
525+
mdio_device_free(mdiodev);
526+
continue;
528527
}
528+
529+
priv->hw->xpcs_args = xpcs;
530+
break;
529531
}
530532

531-
if (!found && !mdio_node) {
533+
if (!priv->hw->xpcs_args) {
532534
dev_warn(dev, "No XPCS found\n");
533535
err = -ENODEV;
534536
goto no_xpcs_found;
@@ -560,6 +562,11 @@ int stmmac_mdio_unregister(struct net_device *ndev)
560562
if (!priv->mii)
561563
return 0;
562564

565+
if (priv->hw->xpcs) {
566+
mdio_device_free(priv->hw->xpcs_args->mdiodev);
567+
xpcs_destroy(priv->hw->xpcs_args);
568+
}
569+
563570
mdiobus_unregister(priv->mii);
564571
priv->mii->priv = NULL;
565572
mdiobus_free(priv->mii);

‎drivers/net/pcs/pcs-xpcs.c‎

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -241,15 +241,19 @@ static bool __xpcs_linkmode_supported(const struct xpcs_compat *compat,
241241
static int xpcs_read(struct mdio_xpcs_args *xpcs, int dev, u32 reg)
242242
{
243243
u32 reg_addr = mdiobus_c45_addr(dev, reg);
244+
struct mii_bus *bus = xpcs->mdiodev->bus;
245+
int addr = xpcs->mdiodev->addr;
244246

245-
return mdiobus_read(xpcs->bus, xpcs->addr, reg_addr);
247+
return mdiobus_read(bus, addr, reg_addr);
246248
}
247249

248250
static int xpcs_write(struct mdio_xpcs_args *xpcs, int dev, u32 reg, u16 val)
249251
{
250252
u32 reg_addr = mdiobus_c45_addr(dev, reg);
253+
struct mii_bus *bus = xpcs->mdiodev->bus;
254+
int addr = xpcs->mdiodev->addr;
251255

252-
return mdiobus_write(xpcs->bus, xpcs->addr, reg_addr, val);
256+
return mdiobus_write(bus, addr, reg_addr, val);
253257
}
254258

255259
static int xpcs_read_vendor(struct mdio_xpcs_args *xpcs, int dev, u32 reg)
@@ -315,7 +319,7 @@ static int xpcs_soft_reset(struct mdio_xpcs_args *xpcs,
315319
#define xpcs_warn(__xpcs, __state, __args...) \
316320
({ \
317321
if ((__state)->link) \
318-
dev_warn(&(__xpcs)->bus->dev, ##__args); \
322+
dev_warn(&(__xpcs)->mdiodev->dev, ##__args); \
319323
})
320324

321325
static int xpcs_read_fault_c73(struct mdio_xpcs_args *xpcs,
@@ -1005,10 +1009,20 @@ static const struct xpcs_id xpcs_id_list[] = {
10051009
},
10061010
};
10071011

1008-
int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface)
1012+
struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
1013+
phy_interface_t interface)
10091014
{
1010-
u32 xpcs_id = xpcs_get_id(xpcs);
1011-
int i;
1015+
struct mdio_xpcs_args *xpcs;
1016+
u32 xpcs_id;
1017+
int i, ret;
1018+
1019+
xpcs = kzalloc(sizeof(*xpcs), GFP_KERNEL);
1020+
if (!xpcs)
1021+
return NULL;
1022+
1023+
xpcs->mdiodev = mdiodev;
1024+
1025+
xpcs_id = xpcs_get_id(xpcs);
10121026

10131027
for (i = 0; i < ARRAY_SIZE(xpcs_id_list); i++) {
10141028
const struct xpcs_id *entry = &xpcs_id_list[i];
@@ -1020,15 +1034,32 @@ int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface)
10201034
xpcs->id = entry;
10211035

10221036
compat = xpcs_find_compat(entry, interface);
1023-
if (!compat)
1024-
return -ENODEV;
1037+
if (!compat) {
1038+
ret = -ENODEV;
1039+
goto out;
1040+
}
10251041

1026-
return xpcs_soft_reset(xpcs, compat);
1042+
ret = xpcs_soft_reset(xpcs, compat);
1043+
if (ret)
1044+
goto out;
1045+
1046+
return xpcs;
10271047
}
10281048

1029-
return -ENODEV;
1049+
ret = -ENODEV;
1050+
1051+
out:
1052+
kfree(xpcs);
1053+
1054+
return ERR_PTR(ret);
1055+
}
1056+
EXPORT_SYMBOL_GPL(xpcs_create);
1057+
1058+
void xpcs_destroy(struct mdio_xpcs_args *xpcs)
1059+
{
1060+
kfree(xpcs);
10301061
}
1031-
EXPORT_SYMBOL_GPL(xpcs_probe);
1062+
EXPORT_SYMBOL_GPL(xpcs_destroy);
10321063

10331064
static struct mdio_xpcs_ops xpcs_ops = {
10341065
.config = xpcs_config,

‎include/linux/pcs/pcs-xpcs.h‎

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
struct xpcs_id;
1818

1919
struct mdio_xpcs_args {
20-
struct mii_bus *bus;
20+
struct mdio_device *mdiodev;
2121
const struct xpcs_id *id;
22-
int addr;
2322
};
2423

2524
struct mdio_xpcs_ops {
@@ -37,6 +36,8 @@ void xpcs_validate(struct mdio_xpcs_args *xpcs, unsigned long *supported,
3736
struct phylink_link_state *state);
3837
int xpcs_config_eee(struct mdio_xpcs_args *xpcs, int mult_fact_100ns,
3938
int enable);
40-
int xpcs_probe(struct mdio_xpcs_args *xpcs, phy_interface_t interface);
39+
struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
40+
phy_interface_t interface);
41+
void xpcs_destroy(struct mdio_xpcs_args *xpcs);
4142

4243
#endif /* __LINUX_PCS_XPCS_H */

0 commit comments

Comments
 (0)