net: mscc: ocelot: introduce conversion helpers between port and netdev
Since the mscc_ocelot_switch_lib is common between a pure switchdev and a DSA driver, the procedure of retrieving a net_device for a certain port index differs, as those are registered by their individual front-ends. Up to now that has been dealt with by always passing the port index to the switch library, but now, we're going to need to work with net_device pointers from the tc-flower offload, for things like indev, or mirred. It is not desirable to refactor that, so let's make sure that the flower offload core has the ability to translate between a net_device and a port index properly. Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Signed-off-by: David S. Miller <davem@davemloft.net>
This commit is contained in:

committed by
David S. Miller

parent
ea9d1f30b1
commit
319e4dd11a
@@ -810,3 +810,25 @@ const struct dsa_switch_ops felix_switch_ops = {
|
||||
.cls_flower_stats = felix_cls_flower_stats,
|
||||
.port_setup_tc = felix_port_setup_tc,
|
||||
};
|
||||
|
||||
struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port)
|
||||
{
|
||||
struct felix *felix = ocelot_to_felix(ocelot);
|
||||
struct dsa_switch *ds = felix->ds;
|
||||
|
||||
if (!dsa_is_user_port(ds, port))
|
||||
return NULL;
|
||||
|
||||
return dsa_to_port(ds, port)->slave;
|
||||
}
|
||||
|
||||
int felix_netdev_to_port(struct net_device *dev)
|
||||
{
|
||||
struct dsa_port *dp;
|
||||
|
||||
dp = dsa_port_from_netdev(dev);
|
||||
if (IS_ERR(dp))
|
||||
return -EINVAL;
|
||||
|
||||
return dp->index;
|
||||
}
|
||||
|
Reference in New Issue
Block a user