Skip to content

Commit cae425c

Browse files
Russell King (Oracle)kuba-moo
authored andcommitted
net: dsa: allow DSA switch drivers to provide their own phylink mac ops
Rather than having a shim for each and every phylink MAC operation, allow DSA switch drivers to provide their own ops structure. When a DSA driver provides the phylink MAC operations, the shimmed ops must not be provided, so fail an attempt to register a switch with both the phylink_mac_ops in struct dsa_switch and the phylink_mac_* operations populated in dsa_switch_ops populated. Signed-off-by: Russell King (Oracle) <[email protected]> Reviewed-by: Vladimir Oltean <[email protected]> Reviewed-by: Florian Fainelli <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent dd0c985 commit cae425c

File tree

3 files changed

+36
-6
lines changed

3 files changed

+36
-6
lines changed

include/net/dsa.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -457,6 +457,11 @@ struct dsa_switch {
457457
*/
458458
const struct dsa_switch_ops *ops;
459459

460+
/*
461+
* Allow a DSA switch driver to override the phylink MAC ops
462+
*/
463+
const struct phylink_mac_ops *phylink_mac_ops;
464+
460465
/*
461466
* User mii_bus and devices for the individual ports.
462467
*/

net/dsa/dsa.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1505,6 +1505,17 @@ static int dsa_switch_probe(struct dsa_switch *ds)
15051505
if (!ds->num_ports)
15061506
return -EINVAL;
15071507

1508+
if (ds->phylink_mac_ops) {
1509+
if (ds->ops->phylink_mac_select_pcs ||
1510+
ds->ops->phylink_mac_prepare ||
1511+
ds->ops->phylink_mac_config ||
1512+
ds->ops->phylink_mac_finish ||
1513+
ds->ops->phylink_mac_link_down ||
1514+
ds->ops->phylink_mac_link_up ||
1515+
ds->ops->adjust_link)
1516+
return -EINVAL;
1517+
}
1518+
15081519
if (np) {
15091520
err = dsa_switch_parse_of(ds, np);
15101521
if (err)

net/dsa/port.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1662,6 +1662,7 @@ static const struct phylink_mac_ops dsa_port_phylink_mac_ops = {
16621662

16631663
int dsa_port_phylink_create(struct dsa_port *dp)
16641664
{
1665+
const struct phylink_mac_ops *mac_ops;
16651666
struct dsa_switch *ds = dp->ds;
16661667
phy_interface_t mode;
16671668
struct phylink *pl;
@@ -1685,8 +1686,12 @@ int dsa_port_phylink_create(struct dsa_port *dp)
16851686
}
16861687
}
16871688

1688-
pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn),
1689-
mode, &dsa_port_phylink_mac_ops);
1689+
mac_ops = &dsa_port_phylink_mac_ops;
1690+
if (ds->phylink_mac_ops)
1691+
mac_ops = ds->phylink_mac_ops;
1692+
1693+
pl = phylink_create(&dp->pl_config, of_fwnode_handle(dp->dn), mode,
1694+
mac_ops);
16901695
if (IS_ERR(pl)) {
16911696
pr_err("error creating PHYLINK: %ld\n", PTR_ERR(pl));
16921697
return PTR_ERR(pl);
@@ -1952,12 +1957,23 @@ static void dsa_shared_port_validate_of(struct dsa_port *dp,
19521957
dn, dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
19531958
}
19541959

1960+
static void dsa_shared_port_link_down(struct dsa_port *dp)
1961+
{
1962+
struct dsa_switch *ds = dp->ds;
1963+
1964+
if (ds->phylink_mac_ops && ds->phylink_mac_ops->mac_link_down)
1965+
ds->phylink_mac_ops->mac_link_down(&dp->pl_config, MLO_AN_FIXED,
1966+
PHY_INTERFACE_MODE_NA);
1967+
else if (ds->ops->phylink_mac_link_down)
1968+
ds->ops->phylink_mac_link_down(ds, dp->index, MLO_AN_FIXED,
1969+
PHY_INTERFACE_MODE_NA);
1970+
}
1971+
19551972
int dsa_shared_port_link_register_of(struct dsa_port *dp)
19561973
{
19571974
struct dsa_switch *ds = dp->ds;
19581975
bool missing_link_description;
19591976
bool missing_phy_mode;
1960-
int port = dp->index;
19611977

19621978
dsa_shared_port_validate_of(dp, &missing_phy_mode,
19631979
&missing_link_description);
@@ -1973,9 +1989,7 @@ int dsa_shared_port_link_register_of(struct dsa_port *dp)
19731989
"Skipping phylink registration for %s port %d\n",
19741990
dsa_port_is_cpu(dp) ? "CPU" : "DSA", dp->index);
19751991
} else {
1976-
if (ds->ops->phylink_mac_link_down)
1977-
ds->ops->phylink_mac_link_down(ds, port,
1978-
MLO_AN_FIXED, PHY_INTERFACE_MODE_NA);
1992+
dsa_shared_port_link_down(dp);
19791993

19801994
return dsa_shared_port_phylink_register(dp);
19811995
}

0 commit comments

Comments
 (0)