@@ -1685,7 +1685,37 @@ qca8k_get_tag_protocol(struct dsa_switch *ds, int port,
return DSA_TAG_PROTO_QCA;
}
+static u32
+qca8k_get_phys_mii_mask(struct dsa_switch *ds)
+{
+ struct device_node *mdio, *phy;
+ u32 reg, phy_mii_mask = 0;
+ int err;
+
+ mdio = of_get_child_by_name(ds->dev->of_node, "mdio");
+ if (mdio) {
+ for_each_available_child_of_node(mdio, phy) {
+ err = of_property_read_u32(phy, "reg", ®);
+ if (err) {
+ of_node_put(phy);
+ of_node_put(mdio);
+ return 0;
+ }
+
+ phy_mii_mask |= BIT(reg);
+ }
+
+ of_node_put(mdio);
+ return phy_mii_mask;
+ }
+
+ /* Fallback to the lagacy mapping if mdio node is not found */
+ dev_warn(ds->dev, "Using the legacy phys_mii_mapping. Consider updating the dts.");
+ return dsa_user_ports(ds);
+}
+
static const struct dsa_switch_ops qca8k_switch_ops = {
+ .get_phys_mii_mask = qca8k_get_phys_mii_mask,
.get_tag_protocol = qca8k_get_tag_protocol,
.setup = qca8k_setup,
.get_strings = qca8k_get_strings,
@@ -511,6 +511,13 @@ struct dsa_switch_ops {
void (*teardown)(struct dsa_switch *ds);
u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
+ /*
+ * Provide a custom phys_mii_mask for the dsa slave mdiobus instead
+ * of relying on the dsa_user_ports. Not every switch has a 1:1 map
+ * port to PHY, hence the driver can provide their fixed mask.
+ */
+ u32 (*get_phys_mii_mask)(struct dsa_switch *ds);
+
/*
* Access to the switch's PHY registers.
*/
@@ -682,8 +682,13 @@ static int dsa_switch_setup(struct dsa_switch *ds)
* driver and before ops->setup() has run, since the switch drivers and
* the slave MDIO bus driver rely on these values for probing PHY
* devices or not
+ * Driver can provide his on mask as some switch doesn't have a 1:1 map
+ * phy to port.
*/
- ds->phys_mii_mask |= dsa_user_ports(ds);
+ if (ds->ops->get_phys_mii_mask)
+ ds->phys_mii_mask = ds->ops->get_phys_mii_mask(ds);
+ else
+ ds->phys_mii_mask |= dsa_user_ports(ds);
/* Add the switch to devlink before calling setup, so that setup can
* add dpipe tables
Some switch doesn't have a 1:1 map phy to port. Permit driver to provide a custom phy_mii_mask so the internal mdiobus can correctly use the provided phy reg as it can differ from the port reg. The qca8k driver is provided as a first user of this function. Signed-off-by: Ansuel Smith <ansuelsmth@gmail.com> --- drivers/net/dsa/qca8k.c | 30 ++++++++++++++++++++++++++++++ include/net/dsa.h | 7 +++++++ net/dsa/dsa2.c | 7 ++++++- 3 files changed, 43 insertions(+), 1 deletion(-)