Skip to content

Commit

Permalink
dpdk/rss: remove redundant code, MR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Adam Kiripolsky authored and Adam Kiripolsky committed Nov 12, 2024
1 parent 88eb7a7 commit c65584b
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 321 deletions.
10 changes: 5 additions & 5 deletions src/source-dpdk.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
Expand Down
51 changes: 18 additions & 33 deletions src/util-dpdk-i40e.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 };
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/util-dpdk-i40e.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */
Expand Down
56 changes: 15 additions & 41 deletions src/util-dpdk-ice.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 };
Expand All @@ -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) {
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/util-dpdk-ice.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */
Expand Down
35 changes: 9 additions & 26 deletions src/util-dpdk-ixgbe.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 };
Expand All @@ -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) {
Expand All @@ -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 */
/**
* @}
Expand Down
4 changes: 2 additions & 2 deletions src/util-dpdk-ixgbe.h
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 */
Expand Down
Loading

0 comments on commit c65584b

Please sign in to comment.