Re: [PATCH net-next] net: dsa: loop: Return VLAN table size through devlink

2020-08-18 Thread Florian Fainelli




On 8/18/2020 10:43 AM, Andrew Lunn wrote:

On Mon, Aug 17, 2020 at 09:03:54PM -0700, Florian Fainelli wrote:

We return the VLAN table size through devlink as a simple parameter, we
do not support altering it at runtime:

devlink resource show mdio_bus/fixed-0:1f
mdio_bus/fixed-0:1f:
   name VTU size 4096 occ 4096 unit entry dpipe_tables none


Hi Florian

The occ 4096 looks wrong. It is supposed to show the occupancy, how
many are in use.


+static u64 dsa_loop_devlink_vtu_get(void *priv)
+{
+   struct dsa_loop_priv *ps = priv;
+
+   return ARRAY_SIZE(ps->vlans);
+}


So this should probably be looping over all vlan IDs and counting those
with members?


Yes, I sent an incorrect version, thanks!
--
Florian


Re: [PATCH net-next] net: dsa: loop: Return VLAN table size through devlink

2020-08-18 Thread Andrew Lunn
On Mon, Aug 17, 2020 at 09:03:54PM -0700, Florian Fainelli wrote:
> We return the VLAN table size through devlink as a simple parameter, we
> do not support altering it at runtime:
> 
> devlink resource show mdio_bus/fixed-0:1f
> mdio_bus/fixed-0:1f:
>   name VTU size 4096 occ 4096 unit entry dpipe_tables none

Hi Florian

The occ 4096 looks wrong. It is supposed to show the occupancy, how
many are in use. 

> +static u64 dsa_loop_devlink_vtu_get(void *priv)
> +{
> + struct dsa_loop_priv *ps = priv;
> +
> + return ARRAY_SIZE(ps->vlans);
> +}

So this should probably be looping over all vlan IDs and counting those
with members?

Andrew


[PATCH net-next] net: dsa: loop: Return VLAN table size through devlink

2020-08-17 Thread Florian Fainelli
We return the VLAN table size through devlink as a simple parameter, we
do not support altering it at runtime:

devlink resource show mdio_bus/fixed-0:1f
mdio_bus/fixed-0:1f:
  name VTU size 4096 occ 4096 unit entry dpipe_tables none

Signed-off-by: Florian Fainelli 
---
 drivers/net/dsa/dsa_loop.c | 47 +-
 1 file changed, 46 insertions(+), 1 deletion(-)

diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c
index eb600b3dbf26..474d0747d4ed 100644
--- a/drivers/net/dsa/dsa_loop.c
+++ b/drivers/net/dsa/dsa_loop.c
@@ -28,6 +28,45 @@ static struct dsa_loop_mib_entry dsa_loop_mibs[] = {
 
 static struct phy_device *phydevs[PHY_MAX_ADDR];
 
+enum dsa_loop_devlink_resource_id {
+   DSA_LOOP_DEVLINK_PARAM_ID_VTU,
+};
+
+static u64 dsa_loop_devlink_vtu_get(void *priv)
+{
+   struct dsa_loop_priv *ps = priv;
+
+   return ARRAY_SIZE(ps->vlans);
+}
+
+static int dsa_loop_setup_devlink_resources(struct dsa_switch *ds)
+{
+   struct devlink_resource_size_params size_params;
+   struct dsa_loop_priv *ps = ds->priv;
+   int err;
+
+   devlink_resource_size_params_init(_params, ARRAY_SIZE(ps->vlans),
+ ARRAY_SIZE(ps->vlans),
+ 1, DEVLINK_RESOURCE_UNIT_ENTRY);
+
+   err = dsa_devlink_resource_register(ds, "VTU", ARRAY_SIZE(ps->vlans),
+   DSA_LOOP_DEVLINK_PARAM_ID_VTU,
+   DEVLINK_RESOURCE_ID_PARENT_TOP,
+   _params);
+   if (err)
+   goto out;
+
+   dsa_devlink_resource_occ_get_register(ds,
+ DSA_LOOP_DEVLINK_PARAM_ID_VTU,
+ dsa_loop_devlink_vtu_get, ps);
+
+   return 0;
+
+out:
+   dsa_devlink_resources_unregister(ds);
+   return err;
+}
+
 static enum dsa_tag_protocol dsa_loop_get_protocol(struct dsa_switch *ds,
   int port,
   enum dsa_tag_protocol mp)
@@ -48,7 +87,12 @@ static int dsa_loop_setup(struct dsa_switch *ds)
 
dev_dbg(ds->dev, "%s\n", __func__);
 
-   return 0;
+   return dsa_loop_setup_devlink_resources(ds);
+}
+
+static void dsa_loop_teardown(struct dsa_switch *ds)
+{
+   dsa_devlink_resources_unregister(ds);
 }
 
 static int dsa_loop_get_sset_count(struct dsa_switch *ds, int port, int sset)
@@ -243,6 +287,7 @@ static int dsa_loop_port_max_mtu(struct dsa_switch *ds, int 
port)
 static const struct dsa_switch_ops dsa_loop_driver = {
.get_tag_protocol   = dsa_loop_get_protocol,
.setup  = dsa_loop_setup,
+   .teardown   = dsa_loop_teardown,
.get_strings= dsa_loop_get_strings,
.get_ethtool_stats  = dsa_loop_get_ethtool_stats,
.get_sset_count = dsa_loop_get_sset_count,
-- 
2.25.1