net: dsa: b53: Report VLAN table occupancy via devlink
PATCH 1/1 net: dsa: b53: Report VLAN table occupancy via devlink
We already maintain an array of VLANs used by the switch so we can simply iterate over it to report the occupancy via devlink.
--- drivers/net/dsa/b53/b53_common.c | 59 ++++++++++++++++++++++++++++++-- drivers/net/dsa/b53/b53_priv.h | 1 + drivers/net/dsa/bcm_sf2.c | 8 ++++- 3 files changed, 65 insertions(+), 3 deletions(-)
drivers/net/dsa/b53/b53_common.c +57 -2
@@ -977,6 +977,53 @@ int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) }EXPORT_SYMBOL (b53_get_sset_count); +enum b53_devlink_resource_id { +B53_DEVLINK_PARMA_ID_VLAN_TABLE , +}; + +static u64 b53_devlink_vlan_table_get (void *priv) +{ +struct b53_device *dev = priv; +unsigned int i, count =0 ; +struct b53_vlan *vl; + +for (i =0 ; i < dev->num_vlans; i++) { + vl = &dev->vlans[i]; +if (vl->members) + count++; + } + +return count; +} + +int b53_setup_devlink_resources (struct dsa_switch *ds) +{ +struct devlink_resource_size_params size_params; +struct b53_device *dev = ds->priv; +int err; + +devlink_resource_size_params_init (&size_params, dev->num_vlans, + dev->num_vlans, +1 ,DEVLINK_RESOURCE_UNIT_ENTRY ); + + err =dsa_devlink_resource_register (ds,"VLAN" , dev->num_vlans, +B53_DEVLINK_PARMA_ID_VLAN_TABLE , +DEVLINK_RESOURCE_ID_PARENT_TOP , + &size_params); +if (err) + goto out; + +dsa_devlink_resource_occ_get_register (ds, +B53_DEVLINK_PARMA_ID_VLAN_TABLE , + b53_devlink_vlan_table_get, dev); + +return 0 ; +out: +dsa_devlink_resources_unregister (ds); +return err; +} +EXPORT_SYMBOL (b53_setup_devlink_resources); +static int b53_setup (struct dsa_switch *ds) {struct b53_device *dev = ds->priv;
@@ -992,8 +1039,10 @@ static int b53_setup(struct dsa_switch *ds)b53_reset_mib (dev); ret =b53_apply_config (dev); -if (ret) +if (ret) {dev_err (ds->dev,"failed to apply configuration\n" ); +return ret; + }/* Configure IMP/CPU port, disable all other ports. Enabled * ports will be configured with .port_enable
@@ -1012,7 +1061,12 @@ static int b53_setup(struct dsa_switch *ds)*/ ds->vlan_filtering_is_global = true; -return ret; +return b53_setup_devlink_resources (ds); +} + +static void b53_teardown (struct dsa_switch *ds) +{ +dsa_devlink_resources_unregister (ds); }static void b53_force_link (struct b53_device *dev,int port,int link)
@@ -2141,6 +2195,7 @@ static int b53_get_max_mtu(struct dsa_switch *ds, int port)static const struct dsa_switch_ops b53_switch_ops = { .get_tag_protocol = b53_get_tag_protocol, .setup = b53_setup, + .teardown = b53_teardown, .get_strings = b53_get_strings, .get_ethtool_stats = b53_get_ethtool_stats, .get_sset_count = b53_get_sset_count,
drivers/net/dsa/b53/b53_priv.h +1 -0
@@ -328,6 +328,7 @@ void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);void b53_br_fast_age (struct dsa_switch *ds,int port);int b53_br_egress_floods (struct dsa_switch *ds,int port,bool unicast,bool multicast); +int b53_setup_devlink_resources (struct dsa_switch *ds);void b53_port_event (struct dsa_switch *ds,int port); void b53_phylink_validate(struct dsa_switch *ds, int port, unsigned long *supported,
drivers/net/dsa/bcm_sf2.c +7 -1
@@ -936,7 +936,12 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)b53_configure_vlan (ds);bcm_sf2_enable_acb (ds); -return 0 ; +return b53_setup_devlink_resources (ds); +} + +static void bcm_sf2_sw_teardown (struct dsa_switch *ds) +{ +dsa_devlink_resources_unregister (ds); }/* The SWITCH_CORE register space is managed by b53 but operates on a page +
@@ -1073,6 +1078,7 @@ static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds, int port,static const struct dsa_switch_ops bcm_sf2_ops = { .get_tag_protocol = b53_get_tag_protocol, .setup = bcm_sf2_sw_setup, + .teardown = bcm_sf2_sw_teardown, .get_strings = bcm_sf2_sw_get_strings, .get_ethtool_stats = bcm_sf2_sw_get_ethtool_stats, .get_sset_count = bcm_sf2_sw_get_sset_count,
Signature · 1 line
2.25.1
Quoted 4 lines · On Tue, 8 Sep 2020 21:32:34 -0700 Florian Fainelli wrote:
We already maintain an array of VLANs used by the switch so we can simply iterate over it to report the occupancy via devlink.
Signed-off-by Florian Fainelli <[email protected]>
Vladimir Oltean
maintainerQuoted 15 lines · Florian Fainelli
We already maintain an array of VLANs used by the switch so we can simply iterate over it to report the occupancy via devlink.
Signed-off-by Florian Fainelli <[email protected]>--- drivers/net/dsa/b53/b53_common.c | 59 ++++++++++++++++++++++++++++++-- drivers/net/dsa/b53/b53_priv.h | 1 + drivers/net/dsa/bcm_sf2.c | 8 ++++- 3 files changed, 65 insertions(+), 3 deletions(-)drivers/net/dsa/b53/b53_common.c +0
-0
drivers/net/dsa/b53/b53_common.c int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) · line 981
Quoted 5 lines
drivers/net/dsa/b53/b53_common.c +2
-0@@ -977,6 +977,53 @@ int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) }EXPORT_SYMBOL (b53_get_sset_count); +enum b53_devlink_resource_id { +B53_DEVLINK_PARMA_ID_VLAN_TABLE ,
Parma is a city in Italy, maybe PARAM?
drivers/net/dsa/b53/b53_common.c int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) · line 987
Quoted 6 lines
drivers/net/dsa/b53/b53_common.c +6
-0+}; + +static u64 b53_devlink_vlan_table_get (void *priv) +{ +struct b53_device *dev = priv; +unsigned int i, count =0 ;
Could you make count an u64 as well, since you're returning it into an u64?
Quoted 117 lines
drivers/net/dsa/b53/b53_common.c +49
-2+struct b53_vlan *vl; + +for (i =0 ; i < dev->num_vlans; i++) { + vl = &dev->vlans[i]; +if (vl->members) + count++; + } + +return count; +} + +int b53_setup_devlink_resources (struct dsa_switch *ds) +{ +struct devlink_resource_size_params size_params; +struct b53_device *dev = ds->priv; +int err; + +devlink_resource_size_params_init (&size_params, dev->num_vlans, + dev->num_vlans, +1 ,DEVLINK_RESOURCE_UNIT_ENTRY ); + + err =dsa_devlink_resource_register (ds,"VLAN" , dev->num_vlans, +B53_DEVLINK_PARMA_ID_VLAN_TABLE , +DEVLINK_RESOURCE_ID_PARENT_TOP , + &size_params); +if (err) + goto out; + +dsa_devlink_resource_occ_get_register (ds, +B53_DEVLINK_PARMA_ID_VLAN_TABLE , + b53_devlink_vlan_table_get, dev); + +return 0 ; +out: +dsa_devlink_resources_unregister (ds); +return err; +} +EXPORT_SYMBOL (b53_setup_devlink_resources); +static int b53_setup (struct dsa_switch *ds) {struct b53_device *dev = ds->priv;@@ -992,8 +1039,10 @@ static int b53_setup(struct dsa_switch *ds)b53_reset_mib (dev); ret =b53_apply_config (dev); -if (ret) +if (ret) {dev_err (ds->dev,"failed to apply configuration\n" ); +return ret; + }/* Configure IMP/CPU port, disable all other ports. Enabled * ports will be configured with .port_enable @@ -1012,7 +1061,12 @@ static int b53_setup(struct dsa_switch *ds)*/ ds->vlan_filtering_is_global = true; -return ret; +return b53_setup_devlink_resources (ds); +} + +static void b53_teardown (struct dsa_switch *ds) +{ +dsa_devlink_resources_unregister (ds); }static void b53_force_link (struct b53_device *dev,int port,int link)@@ -2141,6 +2195,7 @@ static int b53_get_max_mtu(struct dsa_switch *ds, int port)static const struct dsa_switch_ops b53_switch_ops = { .get_tag_protocol = b53_get_tag_protocol, .setup = b53_setup, + .teardown = b53_teardown, .get_strings = b53_get_strings, .get_ethtool_stats = b53_get_ethtool_stats, .get_sset_count = b53_get_sset_count,drivers/net/dsa/b53/b53_priv.h +1
-0@@ -328,6 +328,7 @@ void b53_br_set_stp_state(struct dsa_switch *ds, int port, u8 state);void b53_br_fast_age (struct dsa_switch *ds,int port);int b53_br_egress_floods (struct dsa_switch *ds,int port,bool unicast,bool multicast); +int b53_setup_devlink_resources (struct dsa_switch *ds);void b53_port_event (struct dsa_switch *ds,int port); void b53_phylink_validate(struct dsa_switch *ds, int port, unsigned long *supported,drivers/net/dsa/bcm_sf2.c +7
-1@@ -936,7 +936,12 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)b53_configure_vlan (ds);bcm_sf2_enable_acb (ds); -return 0 ; +return b53_setup_devlink_resources (ds); +} + +static void bcm_sf2_sw_teardown (struct dsa_switch *ds) +{ +dsa_devlink_resources_unregister (ds); }/* The SWITCH_CORE register space is managed by b53 but operates on a page + @@ -1073,6 +1078,7 @@ static int bcm_sf2_sw_get_sset_count(struct dsa_switch *ds, int port,static const struct dsa_switch_ops bcm_sf2_ops = { .get_tag_protocol = b53_get_tag_protocol, .setup = bcm_sf2_sw_setup, + .teardown = bcm_sf2_sw_teardown, .get_strings = bcm_sf2_sw_get_strings, .get_ethtool_stats = bcm_sf2_sw_get_ethtool_stats, .get_sset_count = bcm_sf2_sw_get_sset_count,Signature · 1 line
2.25.1
Thanks,
-Vladimir
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Wed, 9 Sep 2020 19:03:37 +0300
Quoted 9 lines · Florian Fainelli
drivers/net/dsa/b53/b53_common.c int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) · line 981
Quoted 6 lines
drivers/net/dsa/b53/b53_common.c +2
-0@@ -977,6 +977,53 @@ int b53_get_sset_count(struct dsa_switch *ds, int port, int sset) }EXPORT_SYMBOL (b53_get_sset_count); +enum b53_devlink_resource_id { +B53_DEVLINK_PARMA_ID_VLAN_TABLE ,Parma is a city in Italy, maybe PARAM?
:-))) Agreed.