By definition, RSS involves some kind of hash algorithm, usually Toeplitz.
Until now it could not be modified on a flow rule basis and PMDs had to
always assume RTE_ETH_HASH_FUNCTION_DEFAULT, which remains the default
behavior when unspecified (0).
This breaks ABI compatibility for the following public functions:
- rte_flow_copy()
- rte_flow_create()
- rte_flow_query()
- rte_flow_validate()
Signed-off-by: Adrien Mazarguil <adrien.mazarguil@6wind.com>
Acked-by: Andrew Rybchenko <arybchenko@solarflare.com>
 #include <sys/socket.h>
 
 #include <rte_common.h>
+#include <rte_eth_ctrl.h>
 #include <rte_ethdev.h>
 #include <rte_byteorder.h>
 #include <cmdline_parse.h>
        ACTION_DROP,
        ACTION_COUNT,
        ACTION_RSS,
+       ACTION_RSS_FUNC,
+       ACTION_RSS_FUNC_DEFAULT,
+       ACTION_RSS_FUNC_TOEPLITZ,
+       ACTION_RSS_FUNC_SIMPLE_XOR,
        ACTION_RSS_TYPES,
        ACTION_RSS_TYPE,
        ACTION_RSS_KEY,
 };
 
 static const enum index action_rss[] = {
+       ACTION_RSS_FUNC,
        ACTION_RSS_TYPES,
        ACTION_RSS_KEY,
        ACTION_RSS_KEY_LEN,
 static int parse_vc_action_rss(struct context *, const struct token *,
                               const char *, unsigned int, void *,
                               unsigned int);
+static int parse_vc_action_rss_func(struct context *, const struct token *,
+                                   const char *, unsigned int, void *,
+                                   unsigned int);
 static int parse_vc_action_rss_type(struct context *, const struct token *,
                                    const char *, unsigned int, void *,
                                    unsigned int);
                .next = NEXT(action_rss),
                .call = parse_vc_action_rss,
        },
+       [ACTION_RSS_FUNC] = {
+               .name = "func",
+               .help = "RSS hash function to apply",
+               .next = NEXT(action_rss,
+                            NEXT_ENTRY(ACTION_RSS_FUNC_DEFAULT,
+                                       ACTION_RSS_FUNC_TOEPLITZ,
+                                       ACTION_RSS_FUNC_SIMPLE_XOR)),
+       },
+       [ACTION_RSS_FUNC_DEFAULT] = {
+               .name = "default",
+               .help = "default hash function",
+               .call = parse_vc_action_rss_func,
+       },
+       [ACTION_RSS_FUNC_TOEPLITZ] = {
+               .name = "toeplitz",
+               .help = "Toeplitz hash function",
+               .call = parse_vc_action_rss_func,
+       },
+       [ACTION_RSS_FUNC_SIMPLE_XOR] = {
+               .name = "simple_xor",
+               .help = "simple XOR hash function",
+               .call = parse_vc_action_rss_func,
+       },
        [ACTION_RSS_TYPES] = {
                .name = "types",
                .help = "specific RSS hash types",
        action_rss_data = ctx->object;
        *action_rss_data = (struct action_rss_data){
                .conf = (struct rte_flow_action_rss){
+                       .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
                        .types = rss_hf,
                        .key_len = sizeof(action_rss_data->key),
                        .queue_num = RTE_MIN(nb_rxq, ACTION_RSS_QUEUE_NUM),
        return ret;
 }
 
+/**
+ * Parse func field for RSS action.
+ *
+ * The RTE_ETH_HASH_FUNCTION_* value to assign is derived from the
+ * ACTION_RSS_FUNC_* index that called this function.
+ */
+static int
+parse_vc_action_rss_func(struct context *ctx, const struct token *token,
+                        const char *str, unsigned int len,
+                        void *buf, unsigned int size)
+{
+       struct action_rss_data *action_rss_data;
+       enum rte_eth_hash_function func;
+
+       (void)buf;
+       (void)size;
+       /* Token name must match. */
+       if (parse_default(ctx, token, str, len, NULL, 0) < 0)
+               return -1;
+       switch (ctx->curr) {
+       case ACTION_RSS_FUNC_DEFAULT:
+               func = RTE_ETH_HASH_FUNCTION_DEFAULT;
+               break;
+       case ACTION_RSS_FUNC_TOEPLITZ:
+               func = RTE_ETH_HASH_FUNCTION_TOEPLITZ;
+               break;
+       case ACTION_RSS_FUNC_SIMPLE_XOR:
+               func = RTE_ETH_HASH_FUNCTION_SIMPLE_XOR;
+               break;
+       default:
+               return -1;
+       }
+       if (!ctx->object)
+               return len;
+       action_rss_data = ctx->object;
+       action_rss_data->conf.func = func;
+       return len;
+}
+
 /**
  * Parse type field for RSS action.
  *
 
                off = 0;
                if (dst.rss)
                        *dst.rss = (struct rte_flow_action_rss){
+                               .func = src.rss->func,
                                .types = src.rss->types,
                                .key_len = src.rss->key_len,
                                .queue_num = src.rss->queue_num,
 
    +---------------+---------------------------------------------+
    | Field         | Value                                       |
    +===============+=============================================+
+   | ``func``      | RSS hash function to apply                  |
+   +---------------+---------------------------------------------+
    | ``types``     | specific RSS hash types (see ``ETH_RSS_*``) |
    +---------------+---------------------------------------------+
    | ``key_len``   | hash key length in bytes                    |
 
     (``rss_conf->rss_key`` => ``key``,
     ``rss_conf->rss_key_len`` => ``key_len``,
     ``rss_conf->rss_hf`` => ``types``,
-    ``num`` => ``queue_num``).
+    ``num`` => ``queue_num``), and the addition of missing RSS parameters
+    (``func`` for RSS hash function to apply).
 
 
 ABI Changes
 
 
 - ``rss``: spread packets among several queues.
 
+  - ``func {hash function}``: RSS hash function to apply, allowed tokens are
+    the same as `set_hash_global_config`_.
+
   - ``types [{RSS hash type} [...]] end``: specific RSS hash types, allowed
     tokens are the same as `set_hash_input_set`_, except that an empty list
     does not disable RSS but instead requests unspecified "best-effort"
 
                }
        }
 
+       if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
+               return rte_flow_error_set
+                       (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
+                        "non-default RSS hash functions are not supported");
        if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
                return rte_flow_error_set
                        (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
 
            in->queue_num > RTE_DIM(out->queue))
                return -EINVAL;
        out->conf = (struct rte_flow_action_rss){
+               .func = in->func,
                .types = in->types,
                .key_len = in->key_len,
                .queue_num = in->queue_num,
 igb_action_rss_same(const struct rte_flow_action_rss *comp,
                    const struct rte_flow_action_rss *with)
 {
-       return (comp->types == with->types &&
+       return (comp->func == with->func &&
+               comp->types == with->types &&
                comp->key_len == with->key_len &&
                comp->queue_num == with->queue_num &&
                !memcmp(comp->key, with->key, with->key_len) &&
 
            in->queue_num > RTE_DIM(out->queue))
                return -EINVAL;
        out->conf = (struct rte_flow_action_rss){
+               .func = in->func,
                .types = in->types,
                .key_len = in->key_len,
                .queue_num = in->queue_num,
 i40e_action_rss_same(const struct rte_flow_action_rss *comp,
                     const struct rte_flow_action_rss *with)
 {
-       return (comp->types == with->types &&
+       return (comp->func == with->func &&
+               comp->types == with->types &&
                comp->key_len == with->key_len &&
                comp->queue_num == with->queue_num &&
                !memcmp(comp->key, with->key, with->key_len) &&
 
        }
 
        /* Parse RSS related parameters from configuration */
+       if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
+               return rte_flow_error_set
+                       (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
+                        "non-default RSS hash functions are not supported");
        if (rss->key_len && rss->key_len > RTE_DIM(rss_config->key))
                return rte_flow_error_set
                        (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
 
                }
        }
 
+       if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
+               return rte_flow_error_set
+                       (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
+                        "non-default RSS hash functions are not supported");
        if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
                return rte_flow_error_set
                        (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
 
            in->queue_num > RTE_DIM(out->queue))
                return -EINVAL;
        out->conf = (struct rte_flow_action_rss){
+               .func = in->func,
                .types = in->types,
                .key_len = in->key_len,
                .queue_num = in->queue_num,
 ixgbe_action_rss_same(const struct rte_flow_action_rss *comp,
                      const struct rte_flow_action_rss *with)
 {
-       return (comp->types == with->types &&
+       return (comp->func == with->func &&
+               comp->types == with->types &&
                comp->key_len == with->key_len &&
                comp->queue_num == with->queue_num &&
                !memcmp(comp->key, with->key, with->key_len) &&
 
                                        " of the context size";
                                goto exit_action_not_supported;
                        }
+                       if (rss->func &&
+                           rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
+                               msg = "the only supported RSS hash function"
+                                       " is Toeplitz";
+                               goto exit_action_not_supported;
+                       }
                        rte_errno = 0;
                        fields = mlx4_conv_rss_types(priv, rss->types);
                        if (fields == (uint64_t)-1 && rte_errno) {
                rte_align32pow2(priv->dev->data->nb_rx_queues + 1) >> 1;
        uint16_t queue[queues];
        struct rte_flow_action_rss action_rss = {
+               .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
                .types = -1,
                .key_len = MLX4_RSS_HASH_KEY_SIZE,
                .queue_num = queues,
 
 #endif
 
 #include <rte_common.h>
+#include <rte_eth_ctrl.h>
 #include <rte_ethdev_driver.h>
 #include <rte_flow.h>
 #include <rte_flow_driver.h>
                        if (overlap & FATE)
                                goto exit_action_overlap;
                        overlap |= FATE;
+                       if (rss->func &&
+                           rss->func != RTE_ETH_HASH_FUNCTION_TOEPLITZ) {
+                               rte_flow_error_set(error, EINVAL,
+                                                  RTE_FLOW_ERROR_TYPE_ACTION,
+                                                  actions,
+                                                  "the only supported RSS hash"
+                                                  " function is Toeplitz");
+                               return -rte_errno;
+                       }
                        if (rss->types & MLX5_RSS_HF_MASK) {
                                rte_flow_error_set(error, EINVAL,
                                                   RTE_FLOW_ERROR_TYPE_ACTION,
                                }
                        }
                        parser->rss_conf = (struct rte_flow_action_rss){
+                               .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
                                .types = rss->types,
                                .key_len = rss_key_len,
                                .queue_num = rss->queue_num,
        /* Copy configuration. */
        flow->queues = (uint16_t (*)[])(flow + 1);
        flow->rss_conf = (struct rte_flow_action_rss){
+               .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
                .types = parser.rss_conf.types,
                .key_len = parser.rss_conf.key_len,
                .queue_num = parser.rss_conf.queue_num,
        };
        uint16_t queue[priv->reta_idx_n];
        struct rte_flow_action_rss action_rss = {
+               .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
                .types = priv->rss_conf.rss_hf,
                .key_len = priv->rss_conf.rss_key_len,
                .queue_num = priv->reta_idx_n,
 
                        rxq_hw_index_max = rxq->hw_index;
        }
 
+       switch (rss->func) {
+       case RTE_ETH_HASH_FUNCTION_DEFAULT:
+       case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
+               break;
+       default:
+               return -EINVAL;
+       }
+
        if ((rss->types & ~SFC_RSS_OFFLOADS) != 0)
                return -EINVAL;
 
 
        struct rss_key rss_entry = { .hash_fields = 0,
                                     .key_size = 0 };
 
+       /* Check supported hash functions */
+       if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
+               return rte_flow_error_set
+                       (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+                        "non-default RSS hash functions are not supported");
+
        /* Get a new map key for a new RSS rule */
        err = bpf_rss_key(KEY_CMD_GET, &flow->key_idx);
        if (err < 0) {
 
                off = 0;
                if (dst.rss)
                        *dst.rss = (struct rte_flow_action_rss){
+                               .func = src.rss->func,
                                .types = src.rss->types,
                                .key_len = src.rss->key_len,
                                .queue_num = src.rss->queue_num,
 
 
 #include <rte_arp.h>
 #include <rte_ether.h>
+#include <rte_eth_ctrl.h>
 #include <rte_icmp.h>
 #include <rte_ip.h>
 #include <rte_sctp.h>
  * both can be requested simultaneously.
  */
 struct rte_flow_action_rss {
+       enum rte_eth_hash_function func; /**< RSS hash function to apply. */
        uint64_t types; /**< Specific RSS hash types (see ETH_RSS_*). */
        uint32_t key_len; /**< Hash key length in bytes. */
        uint32_t queue_num; /**< Number of entries in @p queue. */