Skip to content

Commit b920687

Browse files
vladimirolteankuba-moo
authored andcommitted
net: dsa: lantiq_gswip: merge gswip_vlan_add_unaware() and gswip_vlan_add_aware()
The two functions largely duplicate functionality. The differences consist in: - the "fid" passed to gswip_vlan_active_create(). The unaware variant always passes -1, the aware variant passes fid = priv->vlans[i].fid, where i is an index into priv->vlans[] for which priv->vlans[i].bridge is equal to the given bridge. - the "vid" is not passed to gswip_vlan_add_unaware(). It is implicitly GSWIP_VLAN_UNAWARE_PVID (zero). - The "untagged" is not passed to gswip_vlan_add_unaware(). It is implicitly true. Also, the CPU port must not be a tag member of the PVID used for VLAN-unaware bridging. - The "pvid" is not passed to gswip_vlan_add_unaware(). It is implicitly true. - The GSWIP_PCE_DEFPVID(port) register is written by the aware variant with an "idx", but with a hardcoded 0 by the unaware variant. Merge the two functions into a single unified function without any functional changes. Signed-off-by: Vladimir Oltean <[email protected]> Signed-off-by: Daniel Golle <[email protected]> Link: https://patch.msgid.link/2be190701d4c17038ce4b8047f9fb0bdf8abdf6e.1760566491.git.daniel@makrotopia.org Signed-off-by: Jakub Kicinski <[email protected]>
1 parent 8f5c71e commit b920687

File tree

1 file changed

+17
-77
lines changed

1 file changed

+17
-77
lines changed

drivers/net/dsa/lantiq/lantiq_gswip.c

Lines changed: 17 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -750,86 +750,25 @@ static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx)
750750
return err;
751751
}
752752

753-
static int gswip_vlan_add_unaware(struct gswip_priv *priv,
754-
struct net_device *bridge, int port)
755-
{
756-
struct gswip_pce_table_entry vlan_mapping = {0,};
757-
unsigned int max_ports = priv->hw_info->max_ports;
758-
bool active_vlan_created = false;
759-
int idx = -1;
760-
int i;
761-
int err;
762-
763-
/* Check if there is already a page for this bridge */
764-
for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
765-
if (priv->vlans[i].bridge == bridge) {
766-
idx = i;
767-
break;
768-
}
769-
}
770-
771-
/* If this bridge is not programmed yet, add a Active VLAN table
772-
* entry in a free slot and prepare the VLAN mapping table entry.
773-
*/
774-
if (idx == -1) {
775-
idx = gswip_vlan_active_create(priv, bridge, -1,
776-
GSWIP_VLAN_UNAWARE_PVID);
777-
if (idx < 0)
778-
return idx;
779-
active_vlan_created = true;
780-
781-
vlan_mapping.index = idx;
782-
vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
783-
/* VLAN ID byte, maps to the VLAN ID of vlan active table */
784-
vlan_mapping.val[0] = GSWIP_VLAN_UNAWARE_PVID;
785-
} else {
786-
/* Read the existing VLAN mapping entry from the switch */
787-
vlan_mapping.index = idx;
788-
vlan_mapping.table = GSWIP_TABLE_VLAN_MAPPING;
789-
err = gswip_pce_table_entry_read(priv, &vlan_mapping);
790-
if (err) {
791-
dev_err(priv->dev, "failed to read VLAN mapping: %d\n",
792-
err);
793-
return err;
794-
}
795-
}
796-
797-
/* Update the VLAN mapping entry and write it to the switch */
798-
vlan_mapping.val[1] |= dsa_cpu_ports(priv->ds);
799-
vlan_mapping.val[1] |= BIT(port);
800-
err = gswip_pce_table_entry_write(priv, &vlan_mapping);
801-
if (err) {
802-
dev_err(priv->dev, "failed to write VLAN mapping: %d\n", err);
803-
/* In case an Active VLAN was creaetd delete it again */
804-
if (active_vlan_created)
805-
gswip_vlan_active_remove(priv, idx);
806-
return err;
807-
}
808-
809-
gswip_switch_w(priv, 0, GSWIP_PCE_DEFPVID(port));
810-
return 0;
811-
}
812-
813-
static int gswip_vlan_add_aware(struct gswip_priv *priv,
814-
struct net_device *bridge, int port,
815-
u16 vid, bool untagged,
816-
bool pvid)
753+
static int gswip_vlan_add(struct gswip_priv *priv, struct net_device *bridge,
754+
int port, u16 vid, bool untagged, bool pvid,
755+
bool vlan_aware)
817756
{
818757
struct gswip_pce_table_entry vlan_mapping = {0,};
819758
unsigned int max_ports = priv->hw_info->max_ports;
820759
unsigned int cpu_ports = dsa_cpu_ports(priv->ds);
821760
bool active_vlan_created = false;
822-
int idx = -1;
823-
int fid = -1;
824-
int i;
825-
int err;
761+
int fid = -1, idx = -1;
762+
int i, err;
826763

827764
/* Check if there is already a page for this bridge */
828765
for (i = max_ports; i < ARRAY_SIZE(priv->vlans); i++) {
829766
if (priv->vlans[i].bridge == bridge) {
830-
if (fid != -1 && fid != priv->vlans[i].fid)
831-
dev_err(priv->dev, "one bridge with multiple flow ids\n");
832-
fid = priv->vlans[i].fid;
767+
if (vlan_aware) {
768+
if (fid != -1 && fid != priv->vlans[i].fid)
769+
dev_err(priv->dev, "one bridge with multiple flow ids\n");
770+
fid = priv->vlans[i].fid;
771+
}
833772
if (priv->vlans[i].vid == vid) {
834773
idx = i;
835774
break;
@@ -864,8 +803,9 @@ static int gswip_vlan_add_aware(struct gswip_priv *priv,
864803
vlan_mapping.val[0] = vid;
865804
/* Update the VLAN mapping entry and write it to the switch */
866805
vlan_mapping.val[1] |= cpu_ports;
867-
vlan_mapping.val[2] |= cpu_ports;
868806
vlan_mapping.val[1] |= BIT(port);
807+
if (vlan_aware)
808+
vlan_mapping.val[2] |= cpu_ports;
869809
if (untagged)
870810
vlan_mapping.val[2] &= ~BIT(port);
871811
else
@@ -879,8 +819,7 @@ static int gswip_vlan_add_aware(struct gswip_priv *priv,
879819
return err;
880820
}
881821

882-
if (pvid)
883-
gswip_switch_w(priv, idx, GSWIP_PCE_DEFPVID(port));
822+
gswip_switch_w(priv, vlan_aware ? idx : 0, GSWIP_PCE_DEFPVID(port));
884823

885824
return 0;
886825
}
@@ -955,7 +894,8 @@ static int gswip_port_bridge_join(struct dsa_switch *ds, int port,
955894
* specific bridges. No bridge is configured here.
956895
*/
957896
if (!br_vlan_enabled(br)) {
958-
err = gswip_vlan_add_unaware(priv, br, port);
897+
err = gswip_vlan_add(priv, br, port, GSWIP_VLAN_UNAWARE_PVID,
898+
true, true, false);
959899
if (err)
960900
return err;
961901
priv->port_vlan_filter &= ~BIT(port);
@@ -1049,8 +989,8 @@ static int gswip_port_vlan_add(struct dsa_switch *ds, int port,
1049989
if (dsa_is_cpu_port(ds, port))
1050990
return 0;
1051991

1052-
return gswip_vlan_add_aware(priv, bridge, port, vlan->vid,
1053-
untagged, pvid);
992+
return gswip_vlan_add(priv, bridge, port, vlan->vid, untagged, pvid,
993+
true);
1054994
}
1055995

1056996
static int gswip_port_vlan_del(struct dsa_switch *ds, int port,

0 commit comments

Comments
 (0)