mlxsw: spectrum: Move handling of HW stats events to router code
authorPetr Machata <petrm@nvidia.com>
Sun, 8 May 2022 08:08:17 +0000 (11:08 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sun, 8 May 2022 10:46:20 +0000 (11:46 +0100)
L3 HW stats are implemented in mlxsw as RIF counters, and therefore the
code resides in spectrum_router. Exclude the offload xstats events from the
mlxsw_sp_netdevice_event_is_router() predicate, and instead recreate the
glue code in the router module.

Previously, the order of dispatch was that for events on tunnels, a
dedicated handler was called, which however did not handle HW stats events.
But there is nothing special about tunnel devices as far as HW stats: there
is a RIF associated with the tunnel netdevice, and that RIF is where the
counter should be installed. Therefore now, HW stats events are tested
first, independent of netdevice type. The upshot is that as of this commit,
mlxsw supports L3 HW stats work on GRE tunnels.

Signed-off-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/mellanox/mlxsw/spectrum.c
drivers/net/ethernet/mellanox/mlxsw/spectrum_router.c

index 867c1f3..367b9b6 100644 (file)
@@ -5010,10 +5010,6 @@ static bool mlxsw_sp_netdevice_event_is_router(unsigned long event)
        case NETDEV_PRE_CHANGEADDR:
        case NETDEV_CHANGEADDR:
        case NETDEV_CHANGEMTU:
-       case NETDEV_OFFLOAD_XSTATS_ENABLE:
-       case NETDEV_OFFLOAD_XSTATS_DISABLE:
-       case NETDEV_OFFLOAD_XSTATS_REPORT_USED:
-       case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA:
                return true;
        default:
                return false;
index fa4d9bf..01f1020 100644 (file)
@@ -9378,6 +9378,19 @@ static int mlxsw_sp_router_port_pre_changeaddr_event(struct mlxsw_sp_rif *rif,
        return -ENOBUFS;
 }
 
+static bool mlxsw_sp_is_offload_xstats_event(unsigned long event)
+{
+       switch (event) {
+       case NETDEV_OFFLOAD_XSTATS_ENABLE:
+       case NETDEV_OFFLOAD_XSTATS_DISABLE:
+       case NETDEV_OFFLOAD_XSTATS_REPORT_USED:
+       case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA:
+               return true;
+       }
+
+       return false;
+}
+
 static int
 mlxsw_sp_router_port_offload_xstats_cmd(struct mlxsw_sp_rif *rif,
                                        unsigned long event,
@@ -9407,6 +9420,24 @@ mlxsw_sp_router_port_offload_xstats_cmd(struct mlxsw_sp_rif *rif,
        return 0;
 }
 
+static int
+mlxsw_sp_netdevice_offload_xstats_cmd(struct mlxsw_sp *mlxsw_sp,
+                                     struct net_device *dev,
+                                     unsigned long event,
+                                     struct netdev_notifier_offload_xstats_info *info)
+{
+       struct mlxsw_sp_rif *rif;
+       int err = 0;
+
+       mutex_lock(&mlxsw_sp->router->lock);
+       rif = mlxsw_sp_rif_find_by_dev(mlxsw_sp, dev);
+       if (rif)
+               err = mlxsw_sp_router_port_offload_xstats_cmd(rif, event, info);
+       mutex_unlock(&mlxsw_sp->router->lock);
+
+       return err;
+}
+
 int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
                                         unsigned long event, void *ptr)
 {
@@ -9432,12 +9463,6 @@ int mlxsw_sp_netdevice_router_port_event(struct net_device *dev,
        case NETDEV_PRE_CHANGEADDR:
                err = mlxsw_sp_router_port_pre_changeaddr_event(rif, ptr);
                break;
-       case NETDEV_OFFLOAD_XSTATS_ENABLE:
-       case NETDEV_OFFLOAD_XSTATS_DISABLE:
-       case NETDEV_OFFLOAD_XSTATS_REPORT_USED:
-       case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA:
-               err = mlxsw_sp_router_port_offload_xstats_cmd(rif, event, ptr);
-               break;
        default:
                WARN_ON_ONCE(1);
                break;
@@ -9522,9 +9547,17 @@ static int mlxsw_sp_router_netdevice_event(struct notifier_block *nb,
                                           unsigned long event, void *ptr)
 {
        struct net_device *dev = netdev_notifier_info_to_dev(ptr);
+       struct mlxsw_sp_router *router;
+       struct mlxsw_sp *mlxsw_sp;
        int err = 0;
 
-       if (mlxsw_sp_is_vrf_event(event, ptr))
+       router = container_of(nb, struct mlxsw_sp_router, netdevice_nb);
+       mlxsw_sp = router->mlxsw_sp;
+
+       if (mlxsw_sp_is_offload_xstats_event(event))
+               err = mlxsw_sp_netdevice_offload_xstats_cmd(mlxsw_sp, dev,
+                                                           event, ptr);
+       else if (mlxsw_sp_is_vrf_event(event, ptr))
                err = mlxsw_sp_netdevice_vrf_event(dev, event, ptr);
 
        return notifier_from_errno(err);