b.liu | e958203 | 2025-04-17 19:18:16 +0800 | [diff] [blame] | 1 | From 829d9def89b452c4d13d15fd578dea524d9f8521 Mon Sep 17 00:00:00 2001 |
| 2 | From: Vladimir Oltean <vladimir.oltean@nxp.com> |
| 3 | Date: Sat, 9 Nov 2019 15:02:48 +0200 |
| 4 | Subject: [PATCH] net: mscc: ocelot: break apart vlan operations into |
| 5 | ocelot_vlan_{add, del} |
| 6 | |
| 7 | We need an implementation of these functions that is agnostic to the |
| 8 | higher layer (switchdev or dsa). |
| 9 | |
| 10 | Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com> |
| 11 | Signed-off-by: David S. Miller <davem@davemloft.net> |
| 12 | --- |
| 13 | drivers/net/ethernet/mscc/ocelot.c | 60 ++++++++++++++++++++++++++------------ |
| 14 | 1 file changed, 42 insertions(+), 18 deletions(-) |
| 15 | |
| 16 | --- a/drivers/net/ethernet/mscc/ocelot.c |
| 17 | +++ b/drivers/net/ethernet/mscc/ocelot.c |
| 18 | @@ -270,18 +270,11 @@ static void ocelot_port_set_pvid(struct |
| 19 | ocelot_port->pvid = pvid; |
| 20 | } |
| 21 | |
| 22 | -static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid, |
| 23 | - bool untagged) |
| 24 | +static int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, |
| 25 | + bool untagged) |
| 26 | { |
| 27 | - struct ocelot_port *ocelot_port = netdev_priv(dev); |
| 28 | - struct ocelot *ocelot = ocelot_port->ocelot; |
| 29 | - int port = ocelot_port->chip_port; |
| 30 | int ret; |
| 31 | |
| 32 | - /* Add the port MAC address to with the right VLAN information */ |
| 33 | - ocelot_mact_learn(ocelot, PGID_CPU, dev->dev_addr, vid, |
| 34 | - ENTRYTYPE_LOCKED); |
| 35 | - |
| 36 | /* Make the port a member of the VLAN */ |
| 37 | ocelot->vlan_mask[vid] |= BIT(port); |
| 38 | ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); |
| 39 | @@ -302,22 +295,29 @@ static int ocelot_vlan_vid_add(struct ne |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | -static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid) |
| 44 | +static int ocelot_vlan_vid_add(struct net_device *dev, u16 vid, bool pvid, |
| 45 | + bool untagged) |
| 46 | { |
| 47 | struct ocelot_port *ocelot_port = netdev_priv(dev); |
| 48 | struct ocelot *ocelot = ocelot_port->ocelot; |
| 49 | int port = ocelot_port->chip_port; |
| 50 | int ret; |
| 51 | |
| 52 | - /* 8021q removes VID 0 on module unload for all interfaces |
| 53 | - * with VLAN filtering feature. We need to keep it to receive |
| 54 | - * untagged traffic. |
| 55 | - */ |
| 56 | - if (vid == 0) |
| 57 | - return 0; |
| 58 | + ret = ocelot_vlan_add(ocelot, port, vid, pvid, untagged); |
| 59 | + if (ret) |
| 60 | + return ret; |
| 61 | |
| 62 | - /* Del the port MAC address to with the right VLAN information */ |
| 63 | - ocelot_mact_forget(ocelot, dev->dev_addr, vid); |
| 64 | + /* Add the port MAC address to with the right VLAN information */ |
| 65 | + ocelot_mact_learn(ocelot, PGID_CPU, dev->dev_addr, vid, |
| 66 | + ENTRYTYPE_LOCKED); |
| 67 | + |
| 68 | + return 0; |
| 69 | +} |
| 70 | + |
| 71 | +static int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid) |
| 72 | +{ |
| 73 | + struct ocelot_port *ocelot_port = ocelot->ports[port]; |
| 74 | + int ret; |
| 75 | |
| 76 | /* Stop the port from being a member of the vlan */ |
| 77 | ocelot->vlan_mask[vid] &= ~BIT(port); |
| 78 | @@ -335,6 +335,30 @@ static int ocelot_vlan_vid_del(struct ne |
| 79 | |
| 80 | return 0; |
| 81 | } |
| 82 | + |
| 83 | +static int ocelot_vlan_vid_del(struct net_device *dev, u16 vid) |
| 84 | +{ |
| 85 | + struct ocelot_port *ocelot_port = netdev_priv(dev); |
| 86 | + struct ocelot *ocelot = ocelot_port->ocelot; |
| 87 | + int port = ocelot_port->chip_port; |
| 88 | + int ret; |
| 89 | + |
| 90 | + /* 8021q removes VID 0 on module unload for all interfaces |
| 91 | + * with VLAN filtering feature. We need to keep it to receive |
| 92 | + * untagged traffic. |
| 93 | + */ |
| 94 | + if (vid == 0) |
| 95 | + return 0; |
| 96 | + |
| 97 | + ret = ocelot_vlan_del(ocelot, port, vid); |
| 98 | + if (ret) |
| 99 | + return ret; |
| 100 | + |
| 101 | + /* Del the port MAC address to with the right VLAN information */ |
| 102 | + ocelot_mact_forget(ocelot, dev->dev_addr, vid); |
| 103 | + |
| 104 | + return 0; |
| 105 | +} |
| 106 | |
| 107 | static void ocelot_vlan_init(struct ocelot *ocelot) |
| 108 | { |