net/mlx5e: Add support to get ethtool flow rules
[cascardo/linux.git] / drivers / net / ethernet / mellanox / mlx5 / core / en_fs_ethtool.c
index 830106e..d17c242 100644 (file)
@@ -537,6 +537,40 @@ out:
        return err;
 }
 
+int mlx5e_ethtool_get_flow(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
+                          int location)
+{
+       struct mlx5e_ethtool_rule *eth_rule;
+
+       if (location < 0 || location >= MAX_NUM_OF_ETHTOOL_RULES)
+               return -EINVAL;
+
+       list_for_each_entry(eth_rule, &priv->fs.ethtool.rules, list) {
+               if (eth_rule->flow_spec.location == location) {
+                       info->fs = eth_rule->flow_spec;
+                       return 0;
+               }
+       }
+
+       return -ENOENT;
+}
+
+int mlx5e_ethtool_get_all_flows(struct mlx5e_priv *priv, struct ethtool_rxnfc *info,
+                               u32 *rule_locs)
+{
+       int location = 0;
+       int idx = 0;
+       int err = 0;
+
+       while ((!err || err == -ENOENT) && idx < info->rule_cnt) {
+               err = mlx5e_ethtool_get_flow(priv, info, location);
+               if (!err)
+                       rule_locs[idx++] = location;
+               location++;
+       }
+       return err;
+}
+
 void mlx5e_ethtool_cleanup_steering(struct mlx5e_priv *priv)
 {
        struct mlx5e_ethtool_rule *iter;