suricata
util-dpdk-ice.c
Go to the documentation of this file.
1/* Copyright (C) 2021-2025 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18/**
19 * \defgroup dpdk DPDK Intel ICE driver helpers functions
20 *
21 * @{
22 */
23
24/**
25 * \file
26 *
27 * \author Lukas Sismis <lukas.sismis@gmail.com>
28 *
29 * DPDK driver's helper functions
30 *
31 */
32
33#include "util-dpdk-ice.h"
34#include "util-dpdk.h"
35#include "util-dpdk-rss.h"
36#include "util-debug.h"
37#include "util-dpdk-bonding.h"
38
39#ifdef HAVE_DPDK
40
41static void iceDeviceSetRSSHashFunction(uint64_t *rss_hf)
42{
43#if RTE_VERSION < RTE_VERSION_NUM(20, 0, 0, 0)
44 *rss_hf = RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_OTHER | RTE_ETH_RSS_FRAG_IPV6 |
45 RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
46#else
47 *rss_hf = RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 | RTE_ETH_RSS_NONFRAG_IPV4_OTHER |
48 RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 | RTE_ETH_RSS_NONFRAG_IPV6_OTHER;
49#endif
50}
51
52/**
53 * \brief Creates RTE_FLOW pattern to match ipv4 traffic
54 *
55 * \param port_id The port identifier of the Ethernet device
56 * \param port_name The port name of the Ethernet device
57 * \param rss_conf RSS configuration
58 * \return int 0 on success, a negative errno value otherwise
59 */
60static int iceDeviceSetRSSFlowIPv4(
61 int port_id, const char *port_name, struct rte_flow_action_rss rss_conf)
62{
63 struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 } };
64
65 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
66 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV4;
67 pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
68
69 return DPDKCreateRSSFlow(port_id, port_name, rss_conf, RTE_ETH_RSS_IPV4, pattern);
70}
71
72/**
73 * \brief Creates RTE_FLOW pattern to match ipv6 traffic
74 *
75 * \param port_id The port identifier of the Ethernet device
76 * \param port_name The port name of the Ethernet device
77 * \param rss_conf RSS configuration
78 * \return int 0 on success, a negative errno value otherwise
79 */
80
81static int iceDeviceSetRSSFlowIPv6(
82 int port_id, const char *port_name, struct rte_flow_action_rss rss_conf)
83{
84 struct rte_flow_item pattern[] = { { 0 }, { 0 }, { 0 } };
85
86 pattern[0].type = RTE_FLOW_ITEM_TYPE_ETH;
87 pattern[1].type = RTE_FLOW_ITEM_TYPE_IPV6;
88 pattern[2].type = RTE_FLOW_ITEM_TYPE_END;
89
90 return DPDKCreateRSSFlow(port_id, port_name, rss_conf, RTE_ETH_RSS_IPV6, pattern);
91}
92
93int iceDeviceSetRSS(int port_id, uint16_t nb_rx_queues, char *port_name)
94{
95 uint16_t queues[RTE_MAX_QUEUES_PER_PORT];
96 struct rte_flow_error flush_error = { 0 };
97 struct rte_eth_rss_conf rss_conf = { 0 };
98
99 if (nb_rx_queues < 1) {
100 FatalError("The number of queues for RSS configuration must be "
101 "configured with a positive number");
102 }
103
104 struct rte_flow_action_rss rss_action_conf =
105 DPDKInitRSSAction(rss_conf, 0, queues, RTE_ETH_HASH_FUNCTION_TOEPLITZ, false);
106
107 int retval = iceDeviceSetRSSFlowIPv4(port_id, port_name, rss_action_conf);
108 retval |= iceDeviceSetRSSFlowIPv6(port_id, port_name, rss_action_conf);
109 if (retval != 0) {
110 retval = rte_flow_flush(port_id, &flush_error);
111 if (retval != 0) {
112 SCLogError("%s: unable to flush rte_flow rules: %s Flush error msg: %s", port_name,
113 rte_strerror(-retval), flush_error.message);
114 }
115 return retval;
116 }
117
118 return 0;
119}
120
121void iceDeviceSetRSSConf(struct rte_eth_rss_conf *rss_conf)
122{
123 iceDeviceSetRSSHashFunction(&rss_conf->rss_hf);
124 rss_conf->rss_key_len = 52;
125}
126
127#endif /* HAVE_DPDK */
128/**
129 * @}
130 */
#define FatalError(...)
Definition util-debug.h:510
#define SCLogError(...)
Macro used to log ERROR messages.
Definition util-debug.h:267