Skip to content

Commit 1105974

Browse files
vladimirolteandavem330
authored andcommitted
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: Vladimir Oltean <vladimir.oltean@nxp.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 2cac15d commit 1105974

7 files changed

Lines changed: 78 additions & 97 deletions

File tree

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,7 @@ struct mac_device_info {
503503
const struct stmmac_hwtimestamp *ptp;
504504
const struct stmmac_tc_ops *tc;
505505
const struct stmmac_mmc_ops *mmc;
506-
const struct mdio_xpcs_ops *xpcs;
507-
struct mdio_xpcs_args *xpcs_args;
506+
struct mdio_xpcs_args *xpcs;
508507
struct mii_regs mii; /* MII register Addresses */
509508
struct mac_link link;
510509
void __iomem *pcsr; /* vpointer to device CSRs */

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

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -613,14 +613,6 @@ struct stmmac_mmc_ops {
613613
#define stmmac_mmc_read(__priv, __args...) \
614614
stmmac_do_void_callback(__priv, mmc, read, __args)
615615

616-
/* XPCS callbacks */
617-
#define stmmac_xpcs_config(__priv, __args...) \
618-
stmmac_do_callback(__priv, xpcs, config, __args)
619-
#define stmmac_xpcs_get_state(__priv, __args...) \
620-
stmmac_do_callback(__priv, xpcs, get_state, __args)
621-
#define stmmac_xpcs_link_up(__priv, __args...) \
622-
stmmac_do_callback(__priv, xpcs, link_up, __args)
623-
624616
struct stmmac_regs_off {
625617
u32 ptp_off;
626618
u32 mmc_off;

‎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,
725725
priv->plat->mult_fact_100ns,
726726
edata->eee_enabled);
727727
if (ret)

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

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -997,29 +997,13 @@ 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);
1001-
}
1002-
1003-
static void stmmac_mac_pcs_get_state(struct phylink_config *config,
1004-
struct phylink_link_state *state)
1005-
{
1006-
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
1007-
1008-
state->link = 0;
1009-
stmmac_xpcs_get_state(priv, priv->hw->xpcs_args, state);
1000+
xpcs_validate(priv->hw->xpcs, supported, state);
10101001
}
10111002

10121003
static void stmmac_mac_config(struct phylink_config *config, unsigned int mode,
10131004
const struct phylink_link_state *state)
10141005
{
1015-
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
1016-
1017-
stmmac_xpcs_config(priv, priv->hw->xpcs_args, state);
1018-
}
1019-
1020-
static void stmmac_mac_an_restart(struct phylink_config *config)
1021-
{
1022-
/* Not Supported */
1006+
/* Nothing to do, xpcs_config() handles everything */
10231007
}
10241008

10251009
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,
10611045
struct stmmac_priv *priv = netdev_priv(to_net_dev(config->dev));
10621046
u32 ctrl;
10631047

1064-
stmmac_xpcs_link_up(priv, priv->hw->xpcs_args, speed, interface);
1065-
10661048
ctrl = readl(priv->ioaddr + MAC_CTRL_REG);
10671049
ctrl &= ~priv->hw->link.speed_mask;
10681050

@@ -1155,9 +1137,7 @@ static void stmmac_mac_link_up(struct phylink_config *config,
11551137

11561138
static const struct phylink_mac_ops stmmac_phylink_mac_ops = {
11571139
.validate = stmmac_validate,
1158-
.mac_pcs_get_state = stmmac_mac_pcs_get_state,
11591140
.mac_config = stmmac_mac_config,
1160-
.mac_an_restart = stmmac_mac_an_restart,
11611141
.mac_link_down = stmmac_mac_link_down,
11621142
.mac_link_up = stmmac_mac_link_up,
11631143
};
@@ -1234,15 +1214,15 @@ static int stmmac_init_phy(struct net_device *dev)
12341214

12351215
static int stmmac_phy_setup(struct stmmac_priv *priv)
12361216
{
1217+
struct stmmac_mdio_bus_data *mdio_bus_data = priv->plat->mdio_bus_data;
12371218
struct fwnode_handle *fwnode = of_fwnode_handle(priv->plat->phylink_node);
12381219
int mode = priv->plat->phy_interface;
12391220
struct phylink *phylink;
12401221

12411222
priv->phylink_config.dev = &priv->dev->dev;
12421223
priv->phylink_config.type = PHYLINK_NETDEV;
12431224
priv->phylink_config.pcs_poll = true;
1244-
priv->phylink_config.ovr_an_inband =
1245-
priv->plat->mdio_bus_data->xpcs_an_inband;
1225+
priv->phylink_config.ovr_an_inband = mdio_bus_data->xpcs_an_inband;
12461226

12471227
if (!fwnode)
12481228
fwnode = dev_fwnode(priv->device);
@@ -1252,6 +1232,12 @@ static int stmmac_phy_setup(struct stmmac_priv *priv)
12521232
if (IS_ERR(phylink))
12531233
return PTR_ERR(phylink);
12541234

1235+
if (mdio_bus_data->has_xpcs) {
1236+
struct mdio_xpcs_args *xpcs = priv->hw->xpcs;
1237+
1238+
phylink_set_pcs(phylink, &xpcs->pcs);
1239+
}
1240+
12551241
priv->phylink = phylink;
12561242
return 0;
12571243
}
@@ -3653,7 +3639,7 @@ int stmmac_open(struct net_device *dev)
36533639
if (priv->hw->pcs != STMMAC_PCS_TBI &&
36543640
priv->hw->pcs != STMMAC_PCS_RTBI &&
36553641
(!priv->hw->xpcs ||
3656-
xpcs_get_an_mode(priv->hw->xpcs_args, mode) != DW_AN_C73)) {
3642+
xpcs_get_an_mode(priv->hw->xpcs, mode) != DW_AN_C73)) {
36573643
ret = stmmac_init_phy(dev);
36583644
if (ret) {
36593645
netdev_err(priv->dev,

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -444,14 +444,6 @@ int stmmac_mdio_register(struct net_device *ndev)
444444
max_addr = PHY_MAX_ADDR;
445445
}
446446

447-
if (mdio_bus_data->has_xpcs) {
448-
priv->hw->xpcs = mdio_xpcs_get_ops();
449-
if (!priv->hw->xpcs) {
450-
err = -ENODEV;
451-
goto bus_register_fail;
452-
}
453-
}
454-
455447
if (mdio_bus_data->needs_reset)
456448
new_bus->reset = &stmmac_mdio_reset;
457449

@@ -526,11 +518,11 @@ int stmmac_mdio_register(struct net_device *ndev)
526518
continue;
527519
}
528520

529-
priv->hw->xpcs_args = xpcs;
521+
priv->hw->xpcs = xpcs;
530522
break;
531523
}
532524

533-
if (!priv->hw->xpcs_args) {
525+
if (!priv->hw->xpcs) {
534526
dev_warn(dev, "No XPCS found\n");
535527
err = -ENODEV;
536528
goto no_xpcs_found;
@@ -563,8 +555,8 @@ int stmmac_mdio_unregister(struct net_device *ndev)
563555
return 0;
564556

565557
if (priv->hw->xpcs) {
566-
mdio_device_free(priv->hw->xpcs_args->mdiodev);
567-
xpcs_destroy(priv->hw->xpcs_args);
558+
mdio_device_free(priv->hw->xpcs->mdiodev);
559+
xpcs_destroy(priv->hw->xpcs);
568560
}
569561

570562
mdiobus_unregister(priv->mii);

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

Lines changed: 60 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@
100100
/* VR MII EEE Control 1 defines */
101101
#define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */
102102

103+
#define phylink_pcs_to_xpcs(pl_pcs) \
104+
container_of((pl_pcs), struct mdio_xpcs_args, pcs)
105+
103106
static const int xpcs_usxgmii_features[] = {
104107
ETHTOOL_LINK_MODE_Pause_BIT,
105108
ETHTOOL_LINK_MODE_Asym_Pause_BIT,
@@ -413,7 +416,7 @@ static int xpcs_get_max_usxgmii_speed(const unsigned long *supported)
413416
return max;
414417
}
415418

416-
static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed)
419+
static void xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed)
417420
{
418421
int ret, speed_sel;
419422

@@ -438,33 +441,40 @@ static int xpcs_config_usxgmii(struct mdio_xpcs_args *xpcs, int speed)
438441
break;
439442
default:
440443
/* Nothing to do here */
441-
return -EINVAL;
444+
return;
442445
}
443446

444447
ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1);
445448
if (ret < 0)
446-
return ret;
449+
goto out;
447450

448451
ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_EN);
449452
if (ret < 0)
450-
return ret;
453+
goto out;
451454

452455
ret = xpcs_read(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1);
453456
if (ret < 0)
454-
return ret;
457+
goto out;
455458

456459
ret &= ~DW_USXGMII_SS_MASK;
457460
ret |= speed_sel | DW_USXGMII_FULL;
458461

459462
ret = xpcs_write(xpcs, MDIO_MMD_VEND2, MDIO_CTRL1, ret);
460463
if (ret < 0)
461-
return ret;
464+
goto out;
462465

463466
ret = xpcs_read_vpcs(xpcs, MDIO_CTRL1);
464467
if (ret < 0)
465-
return ret;
468+
goto out;
469+
470+
ret = xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST);
471+
if (ret < 0)
472+
goto out;
473+
474+
return;
466475

467-
return xpcs_write_vpcs(xpcs, MDIO_CTRL1, ret | DW_USXGMII_RST);
476+
out:
477+
pr_err("%s: XPCS access returned %pe\n", __func__, ERR_PTR(ret));
468478
}
469479

470480
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)
794804
return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL1, ret);
795805
}
796806

797-
static int xpcs_config(struct mdio_xpcs_args *xpcs,
798-
const struct phylink_link_state *state)
807+
static int xpcs_do_config(struct mdio_xpcs_args *xpcs,
808+
phy_interface_t interface, unsigned int mode)
799809
{
800810
const struct xpcs_compat *compat;
801811
int ret;
802812

803-
compat = xpcs_find_compat(xpcs->id, state->interface);
813+
compat = xpcs_find_compat(xpcs->id, interface);
804814
if (!compat)
805815
return -ENODEV;
806816

807817
switch (compat->an_mode) {
808818
case DW_AN_C73:
809-
if (state->an_enabled) {
819+
if (phylink_autoneg_inband(mode)) {
810820
ret = xpcs_config_aneg_c73(xpcs, compat);
811821
if (ret)
812822
return ret;
@@ -824,6 +834,16 @@ static int xpcs_config(struct mdio_xpcs_args *xpcs,
824834
return 0;
825835
}
826836

837+
static int xpcs_config(struct phylink_pcs *pcs, unsigned int mode,
838+
phy_interface_t interface,
839+
const unsigned long *advertising,
840+
bool permit_pause_to_mac)
841+
{
842+
struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs);
843+
844+
return xpcs_do_config(xpcs, interface, mode);
845+
}
846+
827847
static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs,
828848
struct phylink_link_state *state,
829849
const struct xpcs_compat *compat)
@@ -842,7 +862,7 @@ static int xpcs_get_state_c73(struct mdio_xpcs_args *xpcs,
842862

843863
state->link = 0;
844864

845-
return xpcs_config(xpcs, state);
865+
return xpcs_do_config(xpcs, state->interface, MLO_AN_INBAND);
846866
}
847867

848868
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,
899919
return 0;
900920
}
901921

902-
static int xpcs_get_state(struct mdio_xpcs_args *xpcs,
903-
struct phylink_link_state *state)
922+
static void xpcs_get_state(struct phylink_pcs *pcs,
923+
struct phylink_link_state *state)
904924
{
925+
struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs);
905926
const struct xpcs_compat *compat;
906927
int ret;
907928

908929
compat = xpcs_find_compat(xpcs->id, state->interface);
909930
if (!compat)
910-
return -ENODEV;
931+
return;
911932

912933
switch (compat->an_mode) {
913934
case DW_AN_C73:
914935
ret = xpcs_get_state_c73(xpcs, state, compat);
915-
if (ret)
916-
return ret;
936+
if (ret) {
937+
pr_err("xpcs_get_state_c73 returned %pe\n",
938+
ERR_PTR(ret));
939+
return;
940+
}
917941
break;
918942
case DW_AN_C37_SGMII:
919943
ret = xpcs_get_state_c37_sgmii(xpcs, state);
920-
if (ret)
921-
return ret;
944+
if (ret) {
945+
pr_err("xpcs_get_state_c37_sgmii returned %pe\n",
946+
ERR_PTR(ret));
947+
}
922948
break;
923949
default:
924-
return -1;
950+
return;
925951
}
926-
927-
return 0;
928952
}
929953

930-
static int xpcs_link_up(struct mdio_xpcs_args *xpcs, int speed,
931-
phy_interface_t interface)
954+
static void xpcs_link_up(struct phylink_pcs *pcs, unsigned int mode,
955+
phy_interface_t interface, int speed, int duplex)
932956
{
957+
struct mdio_xpcs_args *xpcs = phylink_pcs_to_xpcs(pcs);
958+
933959
if (interface == PHY_INTERFACE_MODE_USXGMII)
934960
return xpcs_config_usxgmii(xpcs, speed);
935-
936-
return 0;
937961
}
938962

939963
static u32 xpcs_get_id(struct mdio_xpcs_args *xpcs)
@@ -1009,6 +1033,12 @@ static const struct xpcs_id xpcs_id_list[] = {
10091033
},
10101034
};
10111035

1036+
static const struct phylink_pcs_ops xpcs_phylink_ops = {
1037+
.pcs_config = xpcs_config,
1038+
.pcs_get_state = xpcs_get_state,
1039+
.pcs_link_up = xpcs_link_up,
1040+
};
1041+
10121042
struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
10131043
phy_interface_t interface)
10141044
{
@@ -1039,6 +1069,9 @@ struct mdio_xpcs_args *xpcs_create(struct mdio_device *mdiodev,
10391069
goto out;
10401070
}
10411071

1072+
xpcs->pcs.ops = &xpcs_phylink_ops;
1073+
xpcs->pcs.poll = true;
1074+
10421075
ret = xpcs_soft_reset(xpcs, compat);
10431076
if (ret)
10441077
goto out;
@@ -1061,16 +1094,4 @@ void xpcs_destroy(struct mdio_xpcs_args *xpcs)
10611094
}
10621095
EXPORT_SYMBOL_GPL(xpcs_destroy);
10631096

1064-
static struct mdio_xpcs_ops xpcs_ops = {
1065-
.config = xpcs_config,
1066-
.get_state = xpcs_get_state,
1067-
.link_up = xpcs_link_up,
1068-
};
1069-
1070-
struct mdio_xpcs_ops *mdio_xpcs_get_ops(void)
1071-
{
1072-
return &xpcs_ops;
1073-
}
1074-
EXPORT_SYMBOL_GPL(mdio_xpcs_get_ops);
1075-
10761097
MODULE_LICENSE("GPL v2");

0 commit comments

Comments
 (0)