net/mlx5e: Check police action rate for matchall filter
authorJianbo Liu <jianbol@nvidia.com>
Tue, 5 Sep 2023 03:48:20 +0000 (03:48 +0000)
committerSaeed Mahameed <saeedm@nvidia.com>
Wed, 20 Sep 2023 06:33:08 +0000 (23:33 -0700)
As matchall filter uses TSAR (Transmit Scheduling Arbiter) for rate
limit, the rate of police action should not be over the port's max
link speed, or the maximum aggregated speed of both ports if LAG is
configured.

Signed-off-by: Jianbo Liu <jianbol@nvidia.com>
Reviewed-by: Parav Pandit <parav@nvidia.com>
Reviewed-by: Dragos Tatulea <dtatulea@nvidia.com>
Signed-off-by: Saeed Mahameed <saeedm@nvidia.com>
drivers/net/ethernet/mellanox/mlx5/core/esw/qos.c

index f76c8f0562e9ee898a8ea6c533fd0fdb533d74fc..d2ebe56c3977cc2ec401197dafe87ce007438a35 100644 (file)
@@ -770,6 +770,7 @@ int mlx5_esw_qos_modify_vport_rate(struct mlx5_eswitch *esw, u16 vport_num, u32
 {
        u32 ctx[MLX5_ST_SZ_DW(scheduling_context)] = {};
        struct mlx5_vport *vport;
+       u32 link_speed_max;
        u32 bitmask;
        int err;
 
@@ -777,6 +778,17 @@ int mlx5_esw_qos_modify_vport_rate(struct mlx5_eswitch *esw, u16 vport_num, u32
        if (IS_ERR(vport))
                return PTR_ERR(vport);
 
+       if (rate_mbps) {
+               err = mlx5_esw_qos_max_link_speed_get(esw->dev, &link_speed_max, false, NULL);
+               if (err)
+                       return err;
+
+               err = mlx5_esw_qos_link_speed_verify(esw->dev, "Police",
+                                                    link_speed_max, rate_mbps, NULL);
+               if (err)
+                       return err;
+       }
+
        mutex_lock(&esw->state_lock);
        if (!vport->qos.enabled) {
                /* Eswitch QoS wasn't enabled yet. Enable it and vport QoS. */