net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
Subsystems (3)
RFC PATCH 12/23 net: dsa: lantiq_gswip: support 4k VLANs on API 2.2 or later
Dynamically allocate vlans array depending on the switch API version. Versions less than 2.2 support 64 VLANs, versions 2.2 or later support 4096 VLANs.
--- drivers/net/dsa/lantiq_gswip.c | 73 +++++++++++++++++++++++----------- drivers/net/dsa/lantiq_gswip.h | 4 +- 2 files changed, 52 insertions(+), 25 deletions(-)
drivers/net/dsa/lantiq_gswip.c +49 -24
@@ -657,6 +657,11 @@ static int gswip_setup(struct dsa_switch *ds)gswip_switch_mask (priv,0 ,GSWIP_BM_QUEUE_GCTRL_GL_MOD ,GSWIP_BM_QUEUE_GCTRL ); +if (GSWIP_VERSION_GE (priv,GSWIP_VERSION_2_2 )) +/* Enable VLANMD 2.2 for 4k VLANs entries */ +gswip_switch_mask (priv,0 ,GSWIP_PCE_GCTRL_1_VLANMD , +GSWIP_PCE_GCTRL_1 ); +/* VLAN aware Switching */ gswip_switch_mask (priv,0 ,GSWIP_PCE_GCTRL_0_VLAN ,GSWIP_PCE_GCTRL_0 );
@@ -700,8 +705,8 @@ static int gswip_vlan_active_create(struct gswip_priv *priv,int i;/* Look for a free slot */ -for (i = max_ports; i <ARRAY_SIZE (priv->vlans); i++) { -if (!priv->vlans[i].bridge) { +for (i = max_ports; i < priv->num_vlans; i++) { +if (!(*priv->vlans)[i].bridge) { idx = i;break ; }
@@ -725,9 +730,9 @@ static int gswip_vlan_active_create(struct gswip_priv *priv,return err; } - priv->vlans[idx].bridge = bridge; - priv->vlans[idx].vid = vid; - priv->vlans[idx].fid = fid; + (*priv->vlans)[idx].bridge = bridge; + (*priv->vlans)[idx].vid = vid; + (*priv->vlans)[idx].fid = fid;return idx; }
@@ -743,7 +748,7 @@ static int gswip_vlan_active_remove(struct gswip_priv *priv, int idx) err =gswip_pce_table_entry_write (priv, &vlan_active);if (err)dev_err (priv->dev,"failed to delete active VLAN: %d\n" , err); - priv->vlans[idx].bridge =NULL ; + (*priv->vlans)[idx].bridge =NULL ;return err; }
@@ -759,8 +764,8 @@ static int gswip_vlan_add_unaware(struct gswip_priv *priv,int err;/* Check if there is already a page for this bridge */ -for (i = max_ports; i <ARRAY_SIZE (priv->vlans); i++) { -if (priv->vlans[i].bridge == bridge) { +for (i = max_ports; i < priv->num_vlans; i++) { +if ((*priv->vlans)[i].bridge == bridge) { idx = i;break ; }
@@ -822,12 +827,12 @@ static int gswip_vlan_add_aware(struct gswip_priv *priv,int err;/* Check if there is already a page for this bridge */ -for (i = max_ports; i <ARRAY_SIZE (priv->vlans); i++) { -if (priv->vlans[i].bridge == bridge) { -if (fid !=-1 && fid != priv->vlans[i].fid) +for (i = max_ports; i < priv->num_vlans; i++) { +if ((*priv->vlans)[i].bridge == bridge) { +if (fid !=-1 && fid != (*priv->vlans)[i].fid)dev_err (priv->dev,"one bridge with multiple flow ids\n" ); - fid = priv->vlans[i].fid; -if (priv->vlans[i].vid == vid) { + fid = (*priv->vlans)[i].fid; +if ((*priv->vlans)[i].vid == vid) { idx = i;break ; }
@@ -894,9 +899,9 @@ static int gswip_vlan_remove(struct gswip_priv *priv,int err;/* Check if there is already a page for this bridge */ -for (i = max_ports; i <ARRAY_SIZE (priv->vlans); i++) { -if (priv->vlans[i].bridge == bridge && - (!vlan_aware || priv->vlans[i].vid == vid)) { +for (i = max_ports; i < priv->num_vlans; i++) { +if ((*priv->vlans)[i].bridge == bridge && + (!vlan_aware || (*priv->vlans)[i].vid == vid)) { idx = i;break ; }
@@ -993,9 +998,9 @@ static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,return -EOPNOTSUPP ;/* Check if there is already a page for this VLAN */ -for (i = max_ports; i <ARRAY_SIZE (priv->vlans); i++) { -if (priv->vlans[i].bridge == bridge && - priv->vlans[i].vid == vlan->vid) { +for (i = max_ports; i < priv->num_vlans; i++) { +if ((*priv->vlans)[i].bridge == bridge && + (*priv->vlans)[i].vid == vlan->vid) { idx = i;break ; }
@@ -1007,8 +1012,8 @@ static int gswip_port_vlan_prepare(struct dsa_switch *ds, int port,*/ if (idx ==-1 ) {/* Look for a free slot */ -for (; pos <ARRAY_SIZE (priv->vlans); pos++) { -if (!priv->vlans[pos].bridge) { +for (; pos < priv->num_vlans; pos++) { +if (!(*priv->vlans)[pos].bridge) { idx = pos; pos++;break ;
@@ -1149,9 +1154,9 @@ static int gswip_port_fdb(struct dsa_switch *ds, int port,switch (db.type) {case DSA_DB_BRIDGE : -for (i =0 ; i <ARRAY_SIZE (priv->vlans); i++) { -if (priv->vlans[i].bridge == db.bridge.dev) { - fid = priv->vlans[i].fid; +for (i =0 ; i < priv->num_vlans; i++) { +if ((*priv->vlans)[i].bridge == db.bridge.dev) { + fid = (*priv->vlans)[i].fid;break ; } }
@@ -1948,6 +1953,22 @@ static int gswip_validate_cpu_port(struct dsa_switch *ds)return 0 ; } +static int gswip_allocate_vlans (struct gswip_priv *priv) +{ +if (GSWIP_VERSION_GE (priv,GSWIP_VERSION_2_2 )) + priv->num_vlans =4096 ; +else + priv->num_vlans =64 ; + + priv->vlans =devm_kcalloc (priv->dev, priv->num_vlans, +sizeof ((*priv->vlans)[0 ]),GFP_KERNEL ); +if (!priv->vlans) +return dev_err_probe (priv->dev, -ENOMEM , +"VLAN allocation failed\n" ); + +return 0 ; +} +static int gswip_probe (struct platform_device *pdev) {struct device_node *np, *gphy_fw_np;
@@ -2024,6 +2045,10 @@ static int gswip_probe(struct platform_device *pdev) goto gphy_fw_remove; } + err =gswip_allocate_vlans (priv); +if (err) + goto gphy_fw_remove; + err =dsa_register_switch (priv->ds);if (err) {dev_err_probe (dev, err,"dsa switch registration failed\n" );
drivers/net/dsa/lantiq_gswip.h +3 -1
@@ -142,6 +142,7 @@#define GSWIP_PCE_GCTRL_1 0x457#define GSWIP_PCE_GCTRL_1_MAC_GLOCK BIT(2)/* MAC Address table lock */ #define GSWIP_PCE_GCTRL_1_MAC_GLOCK_MOD BIT(3)/* Mac address table lock forwarding mode */ +#define GSWIP_PCE_GCTRL_1_VLANMD BIT(9)/* VLAN MODE */ #define GSWIP_PCE_PCTRL_0p (p) (0x480 + ((p) * 0xA))#define GSWIP_PCE_PCTRL_0_TVM BIT(5)/* Transparent VLAN mode */ #define GSWIP_PCE_PCTRL_0_VREP BIT(6)/* VLAN Replace Mode */
@@ -269,7 +270,8 @@ struct gswip_priv {struct dsa_switch *ds;struct device *dev;struct regmap *rcu_regmap; -struct gswip_vlan vlans[64 ]; +struct gswip_vlan (*vlans)[]; +unsigned int num_vlans;int num_gphy_fw;struct gswip_gphy_fw *gphy_fw;u32 port_vlan_filter;
Signature · 1 line
2.50.1
Hi Daniel,
Quoted 3 lines · Daniel Golle
Dynamically allocate vlans array depending on the switch API version. Versions less than 2.2 support 64 VLANs, versions 2.2 or later support 4096 VLANs.
...
drivers/net/dsa/lantiq_gswip.c static int gswip_vlan_active_create(struct gswip_priv *priv, · line 735
Quoted 10 lines
(quoted diff) +0
-0@@ -725,9 +730,9 @@ static int gswip_vlan_active_create(struct gswip_priv *priv, return err; }drivers/net/dsa/lantiq_gswip.c +3
-3- priv->vlans[idx].bridge = bridge; - priv->vlans[idx].vid = vid; - priv->vlans[idx].fid = fid; + (*priv->vlans)[idx].bridge = bridge; + (*priv->vlans)[idx].vid = vid; + (*priv->vlans)[idx].fid = fid;
Would it be possible to leave this chunk unchanged (and all array dereferencing in the driver as well)?
drivers/net/dsa/lantiq_gswip.c static int gswip_validate_cpu_port(struct dsa_switch *ds) · line 1964
Quoted 13 lines
drivers/net/dsa/lantiq_gswip.c +0
-0@@ -1948,6 +1953,22 @@ static int gswip_validate_cpu_port(struct dsa_switch *ds) return 0; }drivers/net/dsa/lantiq_gswip.c +9
-0+static int gswip_allocate_vlans (struct gswip_priv *priv) +{ +if (GSWIP_VERSION_GE (priv,GSWIP_VERSION_2_2 )) + priv->num_vlans =4096 ; +else + priv->num_vlans =64 ; + + priv->vlans =devm_kcalloc (priv->dev, priv->num_vlans, + sizeof((*priv->vlans)[0]), GFP_KERNEL);
maybe sizeof(*priv->vlans) or sizeof(priv->vlans[0])?
drivers/net/dsa/lantiq_gswip.h struct gswip_priv { · line 273
Quoted 8 lines
drivers/net/dsa/lantiq_gswip.h +1
-1@@ -269,7 +270,8 @@ struct gswip_priv { struct dsa_switch *ds; struct device *dev; struct regmap *rcu_regmap; -struct gswip_vlan vlans[64 ]; +struct gswip_vlan (*vlans)[];
... if this would be just "struct gswip_vlan *vlans;"?
Quoted 4 lines
drivers/net/dsa/lantiq_gswip.h +1
-0+unsigned int num_vlans; int num_gphy_fw; struct gswip_gphy_fw *gphy_fw; u32 port_vlan_filter;
Signature · 3 lines
Alexander Sverdlin Siemens AG www.siemens.com
Andrew Lunn
maintainerQuoted 8 lines
drivers/net/dsa/lantiq_gswip.h struct gswip_priv { · line 273
Quoted 6 lines
drivers/net/dsa/lantiq_gswip.h +1
-1@@ -269,7 +270,8 @@ struct gswip_priv { struct dsa_switch *ds; struct device *dev; struct regmap *rcu_regmap; -struct gswip_vlan vlans[64 ]; +struct gswip_vlan (*vlans)[];... if this would be just "struct
gswip_vlan*vlans;"?
Could it be moved to the end of the structure and made into an flexible array?
Andrew
Quoted 11 lines · Andrew Lunn
Quoted 8 lines
drivers/net/dsa/lantiq_gswip.h struct gswip_priv { · line 273
Quoted 6 lines
drivers/net/dsa/lantiq_gswip.h +1
-1@@ -269,7 +270,8 @@ struct gswip_priv { struct dsa_switch *ds; struct device *dev; struct regmap *rcu_regmap; -struct gswip_vlan vlans[64 ]; +struct gswip_vlan (*vlans)[];... if this would be just "struct
gswip_vlan*vlans;"?Could it be moved to the end of the structure and made into an flexible array?
I agree that it would be nice to get rid of the additional indirection, I will implement it as flexible array when we arrive there (ie. after both series of preparations have been merged).