From c65584b0546e1a6ba561e55c85b3e5c783fb8b8f Mon Sep 17 00:00:00 2001 From: Adam Kiripolsky Date: Tue, 12 Nov 2024 13:51:02 +0100 Subject: [PATCH] dpdk/rss: remove redundant code, MR changes --- src/source-dpdk.c | 10 +-- src/util-dpdk-i40e.c | 51 +++++------- src/util-dpdk-i40e.h | 4 +- src/util-dpdk-ice.c | 56 ++++--------- src/util-dpdk-ice.h | 4 +- src/util-dpdk-ixgbe.c | 35 +++------ src/util-dpdk-ixgbe.h | 4 +- src/util-dpdk-mlx5.c | 43 +++------- src/util-dpdk-mlx5.h | 6 +- src/util-dpdk-rss.c | 179 +++++++----------------------------------- src/util-dpdk-rss.h | 33 ++------ 11 files changed, 104 insertions(+), 321 deletions(-) diff --git a/src/source-dpdk.c b/src/source-dpdk.c index 8fc88fefb338..d7529ac8e02b 100644 --- a/src/source-dpdk.c +++ b/src/source-dpdk.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -200,13 +200,13 @@ static void DevicePostStartPMDSpecificActions(DPDKThreadVars *ptv, const char *d // The PMD Driver i40e has a special way to set the RSS, it can be set via rte_flow rules // and only after the start of the port if (strcmp(driver_name, "net_i40e") == 0) - i40eDeviceSetRSS(ptv->port_id, ptv->threads); + i40eDeviceSetRSS(ptv->port_id, ptv->threads, ptv->livedev->dev); if (strcmp(driver_name, "net_ice") == 0) - iceDeviceSetRSS(ptv->port_id, ptv->threads); + iceDeviceSetRSS(ptv->port_id, ptv->threads, ptv->livedev->dev); if (strcmp(driver_name, "net_ixgbe") == 0) - ixgbeDeviceSetRSS(ptv->port_id, ptv->threads); + ixgbeDeviceSetRSS(ptv->port_id, ptv->threads, ptv->livedev->dev); if (strcmp(driver_name, "mlx5_pci") == 0) - mlx5DeviceSetRSS(ptv->port_id, ptv->threads); + mlx5DeviceSetRSS(ptv->port_id, ptv->threads, ptv->livedev->dev); } static void DevicePreClosePMDSpecificActions(DPDKThreadVars *ptv, const char *driver_name) diff --git a/src/util-dpdk-i40e.c b/src/util-dpdk-i40e.c index 9246e6bbff83..6605708978f8 100644 --- a/src/util-dpdk-i40e.c +++ b/src/util-dpdk-i40e.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024s Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -168,34 +168,23 @@ static int32_t i40eDeviceSetRSSWithFilter(int port_id, const char *port_name) #else static int i40eDeviceSetRSSFlowIPv4( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { - int ret = 0; - - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4UDP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4TCP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4SCTP, port_id, port_name, rss_conf); + int ret = DeviceSetRSSFlowIPv4(port_id, port_name, rss_conf); return ret; } static int i40eDeviceSetRSSFlowIPv6( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { - int ret = 0; - - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6UDP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6TCP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6SCTP, port_id, port_name, rss_conf); + int ret = DeviceSetRSSFlowIPv6(port_id, port_name, rss_conf); return ret; } static int i40eDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_rx_queues) { - int retval; uint8_t rss_key[I40E_RSS_HKEY_LEN]; uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; @@ -205,20 +194,25 @@ static int i40eDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_ .rss_key_len = I40E_RSS_HKEY_LEN, }; - retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); + int retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); if (retval != 0) { SCLogError("Unable to get RSS hash configuration of port %s", port_name); return retval; } + + if (nb_rx_queues < 1) { + FatalError("The number of queues for RSS configuration must be " + "configured with a positive number"); + } + + rss_action_conf = DeviceInitRSSAction(rss_conf, nb_rx_queues, queues, RTE_ETH_HASH_FUNCTION_DEFAULT, false); - DeviceSetRSSAction( - &rss_action_conf, rss_conf, 0, queues, RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, true); + retval = DeviceSetRSSFlowQueues(port_id, port_name, rss_action_conf); - retval = 0; + rss_action_conf = DeviceInitRSSAction(rss_conf, 0, queues, RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, true); - retval |= DeviceSetRSSFlowQueues(port_id, port_name, rss_conf, nb_rx_queues); - retval |= i40eDeviceSetRSSFlowIPv4(port_id, port_name, &rss_action_conf); - retval |= i40eDeviceSetRSSFlowIPv6(port_id, port_name, &rss_action_conf); + retval |= i40eDeviceSetRSSFlowIPv4(port_id, port_name, rss_action_conf); + retval |= i40eDeviceSetRSSFlowIPv6(port_id, port_name, rss_action_conf); if (retval != 0) { retval = rte_flow_flush(port_id, &flush_error); if (retval != 0) { @@ -233,18 +227,9 @@ static int i40eDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_ #endif /* RTE_VERSION < RTE_VERSION_NUM(20,0,0,0) */ -int i40eDeviceSetRSS(int port_id, int nb_rx_queues) +int i40eDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name) { - int retval; (void)nb_rx_queues; // avoid unused variable warnings - char port_name[RTE_ETH_NAME_MAX_LEN]; - - retval = rte_eth_dev_get_name_by_port(port_id, port_name); - if (unlikely(retval != 0)) { - SCLogError("Failed to convert port id %d to the interface name: %s", port_id, - strerror(-retval)); - return retval; - } #if RTE_VERSION >= RTE_VERSION_NUM(20, 0, 0, 0) i40eDeviceSetRSSWithFlows(port_id, port_name, nb_rx_queues); diff --git a/src/util-dpdk-i40e.h b/src/util-dpdk-i40e.h index 6133aed5d771..964d68074752 100644 --- a/src/util-dpdk-i40e.h +++ b/src/util-dpdk-i40e.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -30,7 +30,7 @@ #include "util-dpdk.h" -int i40eDeviceSetRSS(int port_id, int nb_rx_queues); +int i40eDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); void i40eDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-ice.c b/src/util-dpdk-ice.c index fdba17c5d85b..60b43c4bd072 100644 --- a/src/util-dpdk-ice.c +++ b/src/util-dpdk-ice.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -52,33 +52,23 @@ static void iceDeviceSetRSSHashFunction(uint64_t *rss_hf) } static int iceDeviceSetRSSFlowIPv4( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { - int ret = 0; - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4UDP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4TCP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv4SCTP, port_id, port_name, rss_conf); + int ret = DeviceSetRSSFlowIPv4(port_id, port_name, rss_conf); return ret; } static int iceDeviceSetRSSFlowIPv6( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { - int ret = 0; - - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6UDP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6TCP, port_id, port_name, rss_conf); - ret |= DeviceSetRSSFlowNoQueue(DeviceSetRSSFlowIPv6SCTP, port_id, port_name, rss_conf); + int ret = DeviceSetRSSFlowIPv6(port_id, port_name, rss_conf); return ret; } -static int iceDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_rx_queues) -{ - int retval; +int iceDeviceSetRSS(int port_id, int nb_rx_queues, char* port_name) +{ uint8_t rss_key[ICE_RSS_HKEY_LEN]; uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; @@ -88,19 +78,21 @@ static int iceDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_r .rss_key_len = ICE_RSS_HKEY_LEN, }; - retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); + int retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); if (retval != 0) { SCLogError("Unable to get RSS hash configuration of port %s", port_name); return retval; } - DeviceSetRSSAction( - &rss_action_conf, rss_conf, 0, queues, RTE_ETH_HASH_FUNCTION_TOEPLITZ, false); + if (nb_rx_queues < 1) { + FatalError("The number of queues for RSS configuration must be " + "configured with a positive number"); + } - retval = 0; + rss_action_conf = DeviceInitRSSAction(rss_conf, 0, queues, RTE_ETH_HASH_FUNCTION_TOEPLITZ, false); - retval |= iceDeviceSetRSSFlowIPv4(port_id, port_name, &rss_action_conf); - retval |= iceDeviceSetRSSFlowIPv6(port_id, port_name, &rss_action_conf); + retval = iceDeviceSetRSSFlowIPv4(port_id, port_name, rss_action_conf); + retval |= iceDeviceSetRSSFlowIPv6(port_id, port_name, rss_action_conf); if (retval != 0) { retval = rte_flow_flush(port_id, &flush_error); if (retval != 0) { @@ -113,24 +105,6 @@ static int iceDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_r return 0; } -int iceDeviceSetRSS(int port_id, int nb_rx_queues) -{ - int retval; - (void)nb_rx_queues; // avoid unused variable warnings - char port_name[RTE_ETH_NAME_MAX_LEN]; - - retval = rte_eth_dev_get_name_by_port(port_id, port_name); - if (unlikely(retval != 0)) { - SCLogError("Failed to convert port id %d to the interface name: %s", port_id, - strerror(-retval)); - return retval; - } - - iceDeviceSetRSSWithFlows(port_id, port_name, nb_rx_queues); - - return 0; -} - void iceDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf) { iceDeviceSetRSSHashFunction(&rss_conf->rss_hf); diff --git a/src/util-dpdk-ice.h b/src/util-dpdk-ice.h index 42e35a4a93f2..1cf36bfecb7d 100644 --- a/src/util-dpdk-ice.h +++ b/src/util-dpdk-ice.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -30,7 +30,7 @@ #include "util-dpdk.h" -int iceDeviceSetRSS(int port_id, int nb_rx_queues); +int iceDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); void iceDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-ixgbe.c b/src/util-dpdk-ixgbe.c index 90b6ba728b3f..108b91827d9d 100644 --- a/src/util-dpdk-ixgbe.c +++ b/src/util-dpdk-ixgbe.c @@ -1,4 +1,4 @@ -// /* Copyright (C) 2021 Open Information Security Foundation +// /* Copyright (C) 2021-2024 Open Information Security Foundation // * // * You can copy, redistribute or modify this Program under the terms of // * the GNU General Public License version 2 as published by the Free @@ -45,9 +45,8 @@ void ixgbeDeviceSetRSSHashFunction(uint64_t *rss_hf) *rss_hf = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_IPV6_EX; } -static int ixgbeDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_rx_queues) +int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues, char* port_name) { - int retval; uint8_t rss_key[IXGBE_RSS_HKEY_LEN]; uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; @@ -57,18 +56,20 @@ static int ixgbeDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb .rss_key_len = IXGBE_RSS_HKEY_LEN, }; - retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); + int retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); if (retval != 0) { SCLogError("Unable to get RSS hash configuration of port %s", port_name); return retval; } - DeviceSetRSSAction( - &rss_action_conf, rss_conf, nb_rx_queues, queues, RTE_ETH_HASH_FUNCTION_DEFAULT, true); + if (nb_rx_queues < 1) { + FatalError("The number of queues for RSS configuration must be " + "configured with a positive number"); + } - retval = 0; + rss_action_conf = DeviceInitRSSAction(rss_conf, nb_rx_queues, queues, RTE_ETH_HASH_FUNCTION_DEFAULT, true); - retval |= DeviceCreateRSSFlowUniform(port_id, port_name, &rss_action_conf, nb_rx_queues); + retval = DeviceCreateRSSFlowUniform(port_id, port_name, rss_action_conf); if (retval != 0) { retval = rte_flow_flush(port_id, &flush_error); if (retval != 0) { @@ -81,24 +82,6 @@ static int ixgbeDeviceSetRSSWithFlows(int port_id, const char *port_name, int nb return 0; } -int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues) -{ - int retval; - (void)nb_rx_queues; // avoid unused variable warnings - char port_name[RTE_ETH_NAME_MAX_LEN]; - - retval = rte_eth_dev_get_name_by_port(port_id, port_name); - if (unlikely(retval != 0)) { - SCLogError("Failed to convert port id %d to the interface name: %s", port_id, - strerror(-retval)); - return retval; - } - - ixgbeDeviceSetRSSWithFlows(port_id, port_name, nb_rx_queues); - - return 0; -} - #endif /* HAVE_DPDK */ /** * @} diff --git a/src/util-dpdk-ixgbe.h b/src/util-dpdk-ixgbe.h index 2355fc052e5e..79b7d5edb87c 100644 --- a/src/util-dpdk-ixgbe.h +++ b/src/util-dpdk-ixgbe.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2021-2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -28,7 +28,7 @@ #ifdef HAVE_DPDK -int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues); +int ixgbeDeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); void ixgbeDeviceSetRSSHashFunction(uint64_t *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-mlx5.c b/src/util-dpdk-mlx5.c index 254c0feb46f2..ce4d1b7261db 100644 --- a/src/util-dpdk-mlx5.c +++ b/src/util-dpdk-mlx5.c @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -24,25 +24,25 @@ /** * \file * - * \author Adam Kiripolsky + * \author Adam Kiripolsky * * DPDK driver's helper functions * */ -#include "util-dpdk-mlx5.h" -#include "util-dpdk.h" + #include "util-debug.h" +#include "util-dpdk.h" #include "util-dpdk-bonding.h" +#include "util-dpdk-mlx5.h" #include "util-dpdk-rss.h" #ifdef HAVE_DPDK #define MLX5_RSS_HKEY_LEN 40 -static int mlx5DeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_rx_queues) +int mlx5DeviceSetRSS(int port_id, int nb_rx_queues, char *port_name) { - int retval; uint8_t rss_key[MLX5_RSS_HKEY_LEN]; uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; struct rte_flow_error flush_error = { 0 }; @@ -52,19 +52,20 @@ static int mlx5DeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_ .rss_key_len = MLX5_RSS_HKEY_LEN, }; - retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); - SCLogInfo("RSS key is: %s", rss_conf.rss_key); + int retval = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); if (retval != 0) { SCLogError("Unable to get RSS hash configuration of port %s", port_name); return retval; } - DeviceSetRSSAction( - &rss_action_conf, rss_conf, nb_rx_queues, queues, RTE_ETH_HASH_FUNCTION_TOEPLITZ, true); + if (nb_rx_queues < 1) { + FatalError("The number of queues for RSS configuration must be " + "configured with a positive number"); + } - retval = 0; + rss_action_conf = DeviceInitRSSAction(rss_conf, nb_rx_queues, queues, RTE_ETH_HASH_FUNCTION_TOEPLITZ, true); - retval |= DeviceCreateRSSFlowUniform(port_id, port_name, &rss_action_conf, nb_rx_queues); + retval = DeviceCreateRSSFlowUniform(port_id, port_name, rss_action_conf); if (retval != 0) { retval = rte_flow_flush(port_id, &flush_error); if (retval != 0) { @@ -77,24 +78,6 @@ static int mlx5DeviceSetRSSWithFlows(int port_id, const char *port_name, int nb_ return 0; } -int mlx5DeviceSetRSS(int port_id, int nb_rx_queues) -{ - int retval; - (void)nb_rx_queues; // avoid unused variable warnings - char port_name[RTE_ETH_NAME_MAX_LEN]; - - retval = rte_eth_dev_get_name_by_port(port_id, port_name); - if (unlikely(retval != 0)) { - SCLogError("Failed to convert port id %d to the interface name: %s", port_id, - strerror(-retval)); - return retval; - } - - mlx5DeviceSetRSSWithFlows(port_id, port_name, nb_rx_queues); - - return 0; -} - #endif /* HAVE_DPDK */ /** * @} diff --git a/src/util-dpdk-mlx5.h b/src/util-dpdk-mlx5.h index 48c95cf2b95b..ffd086db027e 100644 --- a/src/util-dpdk-mlx5.h +++ b/src/util-dpdk-mlx5.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Open Information Security Foundation +/* Copyright (C) 2024 Open Information Security Foundation * * You can copy, redistribute or modify this Program under the terms of * the GNU General Public License version 2 as published by the Free @@ -18,7 +18,7 @@ /** * \file * - * \author Adam Kiripolsky + * \author Adam Kiripolsky */ #ifndef UTIL_DPDK_MLX5_H @@ -28,7 +28,7 @@ #ifdef HAVE_DPDK -int mlx5DeviceSetRSS(int port_id, int nb_rx_queues); +int mlx5DeviceSetRSS(int port_id, int nb_rx_queues, char *port_name); void mlx5DeviceSetRSSHashFunction(uint64_t *rss_conf); #endif /* HAVE_DPDK */ diff --git a/src/util-dpdk-rss.c b/src/util-dpdk-rss.c index 66ddea036031..a373b76113e7 100644 --- a/src/util-dpdk-rss.c +++ b/src/util-dpdk-rss.c @@ -24,7 +24,7 @@ /** * \file * - * \author Adam Kiripolsky + * \author Adam Kiripolsky * * DPDK rte_flow RSS helper functions * @@ -36,34 +36,33 @@ #ifdef HAVE_DPDK -void DeviceSetRSSAction(struct rte_flow_action_rss *rss_action_conf, - struct rte_eth_rss_conf rss_conf, int nb_rx_queues, uint16_t *queues, +struct rte_flow_action_rss DeviceInitRSSAction(struct rte_eth_rss_conf rss_conf, int nb_rx_queues, uint16_t *queues, enum rte_eth_hash_function func, bool set_key) { - rss_action_conf->func = func; - rss_action_conf->level = 0; + struct rte_flow_action_rss rss_action_conf = { 0 }; + rss_action_conf.func = func; + rss_action_conf.level = 0; if (set_key) { - rss_action_conf->key = rss_conf.rss_key; - rss_action_conf->key_len = rss_conf.rss_key_len; + rss_action_conf.key = rss_conf.rss_key; + rss_action_conf.key_len = rss_conf.rss_key_len; } else { - rss_action_conf->key = NULL; - rss_action_conf->key_len = 0; + rss_action_conf.key_len = 0; } - if (nb_rx_queues == 0) { - rss_action_conf->queue = NULL; - } else { + if (nb_rx_queues != 0) { for (int i = 0; i < nb_rx_queues; ++i) queues[i] = i; - rss_action_conf->queue = queues; + rss_action_conf.queue = queues; } - rss_action_conf->queue_num = nb_rx_queues; + rss_action_conf.queue_num = nb_rx_queues; + + return rss_action_conf; } int DeviceCreateRSSFlowUniform( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { struct rte_flow_attr attr = { 0 }; struct rte_flow_action action[] = { { 0 }, { 0 } }; @@ -71,11 +70,11 @@ int DeviceCreateRSSFlowUniform( struct rte_flow_error flow_error = { 0 }; struct rte_flow_item pattern[] = { { 0 } }; - rss_conf->types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6; + rss_conf.types = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_IPV6; attr.ingress = 1; action[0].type = RTE_FLOW_ACTION_TYPE_RSS; - action[0].conf = rss_conf; + action[0].conf = &rss_conf; action[1].type = RTE_FLOW_ACTION_TYPE_END; pattern[0].type = RTE_FLOW_ITEM_TYPE_END; @@ -95,19 +94,18 @@ int DeviceCreateRSSFlowUniform( } static int DeviceCreateRSSFlow(int port_id, const char *port_name, - struct rte_flow_action_rss *rss_conf, uint64_t rss_type, struct rte_flow_item *pattern, - int nb_rx_queues) + struct rte_flow_action_rss rss_conf, uint64_t rss_type, struct rte_flow_item *pattern) { struct rte_flow_attr attr = { 0 }; struct rte_flow_action action[] = { { 0 }, { 0 } }; struct rte_flow *flow; struct rte_flow_error flow_error = { 0 }; - rss_conf->types = rss_type; + rss_conf.types = rss_type; attr.ingress = 1; action[0].type = RTE_FLOW_ACTION_TYPE_RSS; - action[0].conf = rss_conf; + action[0].conf = &rss_conf; action[1].type = RTE_FLOW_ACTION_TYPE_END; flow = rte_flow_create(port_id, &attr, pattern, action, &flow_error); @@ -124,42 +122,27 @@ static int DeviceCreateRSSFlow(int port_id, const char *port_name, return 0; } -/* Some drivers (mostly for intel NICs) require specific way of setting RTE_FLOW RSS rules +/** + * @brief Some drivers (mostly for intel NICs) require specific way of setting RTE_FLOW RSS rules * with one rule that sets up only queues and other rules that specify patterns to match with * queues configured. */ + int DeviceSetRSSFlowQueues( - int port_id, const char *port_name, struct rte_eth_rss_conf rss_conf, int nb_rx_queues) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { - struct rte_flow_action_rss rss_action_conf = { 0 }; struct rte_flow_attr attr = { 0 }; struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; struct rte_flow_action action[] = { { 0 }, { 0 } }; struct rte_flow *flow; struct rte_flow_error flow_error = { 0 }; - uint16_t queues[RTE_MAX_QUEUES_PER_PORT]; - for (int i = 0; i < nb_rx_queues; ++i) - queues[i] = i; - - rss_action_conf.func = RTE_ETH_HASH_FUNCTION_DEFAULT; - rss_action_conf.level = 0; - rss_action_conf.types = 0; // queues region can not be configured with types - rss_action_conf.key_len = 0; - rss_action_conf.key = NULL; - - if (nb_rx_queues < 1) { - FatalError("The number of queues for RSS configuration must be " - "configured with a positive number"); - } - - rss_action_conf.queue_num = nb_rx_queues; - rss_action_conf.queue = queues; + rss_conf.types = 0; // queues region can not be configured with types attr.ingress = 1; pattern[0].type = RTE_FLOW_ITEM_TYPE_END; action[0].type = RTE_FLOW_ACTION_TYPE_RSS; - action[0].conf = &rss_action_conf; + action[0].conf = &rss_conf; action[1].type = RTE_FLOW_ACTION_TYPE_END; flow = rte_flow_create(port_id, &attr, pattern, action, &flow_error); @@ -174,17 +157,9 @@ int DeviceSetRSSFlowQueues( } return 0; } -/* Wrapper for calling specific RSS flow rule function with 0 rx queues */ -int DeviceSetRSSFlowNoQueue(int (*DeviceSetRSSFlowProtocol)(int port_id, const char *port_name, - struct rte_flow_action_rss *rss_conf, int nb_rx_queues), - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf) -{ - - return DeviceSetRSSFlowProtocol(port_id, port_name, rss_conf, 0); -} int DeviceSetRSSFlowIPv4( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { int ret = 0; struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 } }; @@ -193,61 +168,13 @@ int DeviceSetRSSFlowIPv4( pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; pattern[2].type = RTE_FLOW_ITEM_TYPE_END; ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV4, pattern, nb_rx_queues); - - return ret; -} - -int DeviceSetRSSFlowIPv4UDP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) -{ - int ret = 0; - struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; - - pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; - pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; - pattern[2].type = RTE_FLOW_ITEM_TYPE_UDP; - pattern[3].type = RTE_FLOW_ITEM_TYPE_END; - ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV4, pattern, nb_rx_queues); - - return ret; -} - -int DeviceSetRSSFlowIPv4TCP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) -{ - int ret = 0; - struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; - - pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; - pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; - pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP; - pattern[3].type = RTE_FLOW_ITEM_TYPE_END; - ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV4, pattern, nb_rx_queues); - - return ret; -} - -int DeviceSetRSSFlowIPv4SCTP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) -{ - int ret = 0; - struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; - - pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; - pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4; - pattern[2].type = RTE_FLOW_ITEM_TYPE_SCTP; - pattern[3].type = RTE_FLOW_ITEM_TYPE_END; - ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV4, pattern, nb_rx_queues); + port_id, port_name, rss_conf, RTE_ETH_RSS_IPV4, pattern); return ret; } int DeviceSetRSSFlowIPv6( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf) { int ret = 0; struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 } }; @@ -256,55 +183,7 @@ int DeviceSetRSSFlowIPv6( pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6; pattern[2].type = RTE_FLOW_ITEM_TYPE_END; ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern, nb_rx_queues); - - return ret; -} - -int DeviceSetRSSFlowIPv6UDP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) -{ - int ret = 0; - struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; - - pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; - pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6; - pattern[2].type = RTE_FLOW_ITEM_TYPE_UDP; - pattern[3].type = RTE_FLOW_ITEM_TYPE_END; - ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern, nb_rx_queues); - - return ret; -} - -int DeviceSetRSSFlowIPv6TCP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) -{ - int ret = 0; - struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; - - pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; - pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6; - pattern[2].type = RTE_FLOW_ITEM_TYPE_TCP; - pattern[3].type = RTE_FLOW_ITEM_TYPE_END; - ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern, nb_rx_queues); - - return ret; -} - -int DeviceSetRSSFlowIPv6SCTP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues) -{ - int ret = 0; - struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 }, { 0 } }; - - pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH; - pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6; - pattern[2].type = RTE_FLOW_ITEM_TYPE_SCTP; - pattern[3].type = RTE_FLOW_ITEM_TYPE_END; - ret |= DeviceCreateRSSFlow( - port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern, nb_rx_queues); + port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern); return ret; } diff --git a/src/util-dpdk-rss.h b/src/util-dpdk-rss.h index 31b43c5ebbac..925c45278fcd 100644 --- a/src/util-dpdk-rss.h +++ b/src/util-dpdk-rss.h @@ -18,7 +18,7 @@ /** * \file * - * \author Adam Kiripolsky + * \author Adam Kiripolsky */ #ifndef UTIL_DPDK_RSS @@ -29,37 +29,16 @@ #ifdef HAVE_DPDK #include "util-dpdk.h" - -void DeviceSetRSSAction(struct rte_flow_action_rss *rss_action_conf, - struct rte_eth_rss_conf rss_conf, int nb_rx_queues, uint16_t *queues, +struct rte_flow_action_rss DeviceInitRSSAction(struct rte_eth_rss_conf rss_conf, int nb_rx_queues, uint16_t *queues, enum rte_eth_hash_function func, bool set_key); int DeviceSetRSSFlowQueues( - int port_id, const char *port_name, struct rte_eth_rss_conf rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowNoQueue(int (*DeviceSetRSSFlowProtocol)(int port_id, const char *port_name, - struct rte_flow_action_rss *rss_conf, int nb_rx_queues), - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf); + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf); int DeviceCreateRSSFlowUniform( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf); int DeviceSetRSSFlowIPv4( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv4UDP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv4TCP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv4SCTP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv4Frag( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf); int DeviceSetRSSFlowIPv6( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv6UDP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv6TCP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv6SCTP( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); -int DeviceSetRSSFlowIPv6Frag( - int port_id, const char *port_name, struct rte_flow_action_rss *rss_conf, int nb_rx_queues); + int port_id, const char *port_name, struct rte_flow_action_rss rss_conf); #endif /* HAVE_DPDK */