NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
flow_ct_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2023 NVIDIA CORPORATION AND AFFILIATES. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without modification, are permitted
5  * provided that the following conditions are met:
6  * * Redistributions of source code must retain the above copyright notice, this list of
7  * conditions and the following disclaimer.
8  * * Redistributions in binary form must reproduce the above copyright notice, this list of
9  * conditions and the following disclaimer in the documentation and/or other materials
10  * provided with the distribution.
11  * * Neither the name of the NVIDIA CORPORATION nor the names of its contributors may be used
12  * to endorse or promote products derived from this software without specific prior written
13  * permission.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
17  * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL NVIDIA CORPORATION BE LIABLE
18  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
19  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
20  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
21  * STRICT LIABILITY, OR TOR (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  *
24  */
25 
26 #ifndef FLOW_CT_COMMON_H_
27 #define FLOW_CT_COMMON_H_
28 
29 #include <doca_dev.h>
30 #include <doca_argp.h>
31 #include <doca_flow.h>
32 #include <doca_flow_ct.h>
33 
34 #include "flow_common.h"
35 
36 #define FLOW_CT_COMMON_DEVARGS \
37  "dv_flow_en=2,dv_xmeta_en=4,representor=pf[0-1],repr_matching_en=0," \
38  "fdb_def_rule_en=0,vport_match=1"
39 
40 #define DUP_FILTER_CONN_NUM 512
41 #define MAX_PORTS 4
42 #define CT_DEFAULT_QUEUE_DEPTH 512
43 
44 struct ct_config {
45  int n_ports; /* Number of ports configured */
46  char ct_dev_pci_addr[MAX_PORTS][DOCA_DEVINFO_PCI_ADDR_SIZE]; /* Flow CT DOCA device PCI address */
47 };
48 
49 /*
50  * Register the command line parameters for the DOCA Flow CT samples
51  *
52  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
53  */
55 
56 /*
57  * Initialize DOCA Flow CT library
58  *
59  * @flags [in]: Flow CT flags
60  * @nb_arm_queues [in]: Number of threads the sample will use
61  * @nb_ctrl_queues [in]: Number of control queues
62  * @nb_user_actions [in]: Number of CT user actions
63  * @entry_finalize_cb [in]: Entry finalize callback
64  * @nb_ipv4_sessions [in]: Number of IPv4 sessions
65  * @nb_ipv6_sessions [in]: Number of IPv6 sessions
66  * @dup_filter_sz [in]: Number of connections to cache in duplication filter
67  * @o_match_inner [in]: Origin match inner
68  * @o_zone_mask [in]: Origin zone mask
69  * @o_modify_mask [in]: Origin modify mask
70  * @r_match_inner [in]: Reply match inner
71  * @r_zone_mask [in]: Reply zone mask
72  * @r_modify_mask [in]: Reply modify mask
73  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
74  */
75 doca_error_t init_doca_flow_ct(uint32_t flags,
76  uint32_t nb_arm_queues,
77  uint32_t nb_ctrl_queues,
78  uint32_t nb_user_actions,
80  uint32_t nb_ipv4_sessions,
81  uint32_t nb_ipv6_sessions,
82  uint32_t dup_filter_sz,
83  bool o_match_inner,
84  struct doca_flow_meta *o_zone_mask,
85  struct doca_flow_meta *o_modify_mask,
86  bool r_match_inner,
87  struct doca_flow_meta *r_zone_mask,
88  struct doca_flow_meta *r_modify_mask);
89 
90 /*
91  * Initialize DPDK environment for DOCA Flow CT
92  *
93  * @argc [in]: Number of program command line arguments
94  * @dpdk_argv [in]: DPDK command line arguments create by argp library
95  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
96  */
97 doca_error_t flow_ct_dpdk_init(int argc, char **dpdk_argv);
98 
99 /*
100  * Verify if DOCA device is ECPF by checking all supported capabilities
101  *
102  * @dev_info [in]: DOCA device info
103  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
104  */
105 doca_error_t flow_ct_capable(struct doca_devinfo *dev_info);
106 
107 /*
108  * Calculates a 6 tuple hash for the givin match
109  *
110  * @match [in]: Doca flow ct match struct that contains the 6 tuple data
111  * @zone_field [in]: zone mask (field) in metadata
112  * @is_ipv6 [in]: Indicates ipv6 header match, otherwise ipv4 header match
113  * @return: hash value
114  */
115 uint32_t flow_ct_hash_6tuple(const struct doca_flow_ct_match *match, doca_be32_t zone_field, bool is_ipv6);
116 
117 /*
118  * Initialize DPDK environment for DOCA Flow CT
119  *
120  * @ct_pipe [in]: ct pipe to destroy
121  * @nb_ports [in]: number of doca flow ports to close
122  * @ports [in]: doca flow ports to close
123  */
124 void cleanup_procedure(struct doca_flow_pipe *ct_pipe, int nb_ports, struct doca_flow_port *ports[]);
125 
126 /*
127  * Create root pipe with IP filter dst == 1.1.1.1
128  *
129  * @port [in]: Pipe port
130  * @is_ipv4 [in]: allow IPv4 packets
131  * @is_ipv6 [in]: allow IPv6 packets
132  * @l4_type [in]: L4 type
133  * @fwd_pipe [in]: Next pipe pointer
134  * @status [in]: User context for adding entry
135  * @pipe [out]: Created pipe pointer
136  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
137  */
138 doca_error_t create_ct_root_pipe(struct doca_flow_port *port,
139  bool is_ipv4,
140  bool is_ipv6,
141  enum doca_flow_l4_meta l4_type,
142  struct doca_flow_pipe *fwd_pipe,
143  struct entries_status *status,
144  struct doca_flow_pipe **pipe);
145 
146 /*
147  * Poll the queue until expected room available.
148  *
149  * Must be called before any entry create/update/destroy.
150  * Must update status->nb_sent after each entry manipulation.
151  *
152  * @port [in] DOCA Flow port structure.
153  * @ct_queue [in] CT queue.
154  * @status [in|out] user context struct provided in entries manipulation.
155  * @room [in] expected room to be available in the queue.
156  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise.
157  */
158 doca_error_t flow_ct_queue_reserve(struct doca_flow_port *port,
159  uint16_t ct_queue,
160  struct entries_status *status,
161  uint32_t room);
162 
163 #endif /* FLOW_CT_COMMON_H_ */
struct rte_eth_dev_info dev_info
Definition: device.c:32
uint32_t flow_ct_hash_6tuple(const struct doca_flow_ct_match *match, doca_be32_t zone_field, bool is_ipv6)
#define MAX_PORTS
doca_error_t flow_ct_dpdk_init(int argc, char **dpdk_argv)
doca_error_t init_doca_flow_ct(uint32_t flags, uint32_t nb_arm_queues, uint32_t nb_ctrl_queues, uint32_t nb_user_actions, doca_flow_ct_entry_finalize_cb entry_finalize_cb, uint32_t nb_ipv4_sessions, uint32_t nb_ipv6_sessions, uint32_t dup_filter_sz, bool o_match_inner, struct doca_flow_meta *o_zone_mask, struct doca_flow_meta *o_modify_mask, bool r_match_inner, struct doca_flow_meta *r_zone_mask, struct doca_flow_meta *r_modify_mask)
doca_error_t flow_ct_capable(struct doca_devinfo *dev_info)
doca_error_t flow_ct_register_params(void)
doca_error_t create_ct_root_pipe(struct doca_flow_port *port, bool is_ipv4, bool is_ipv6, enum doca_flow_l4_meta l4_type, struct doca_flow_pipe *fwd_pipe, struct entries_status *status, struct doca_flow_pipe **pipe)
doca_error_t flow_ct_queue_reserve(struct doca_flow_port *port, uint16_t ct_queue, struct entries_status *status, uint32_t room)
void cleanup_procedure(struct doca_flow_pipe *ct_pipe, int nb_ports, struct doca_flow_port *ports[])
static void entry_finalize_cb(struct doca_flow_pipe *pipe, void *entry, uint16_t ct_queue, void *usr_ctx)
#define DOCA_DEVINFO_PCI_ADDR_SIZE
Buffer size to hold PCI BDF format: "XXXX:XX:XX.X". Including a null terminator.
Definition: doca_dev.h:313
enum doca_error doca_error_t
DOCA API return codes.
void(* doca_flow_ct_entry_finalize_cb)(struct doca_flow_pipe *pipe, void *entry, uint16_t queue, void *usr_ctx)
Definition: doca_flow_ct.h:72
doca_flow_l4_meta
doca flow l4 valid type for parser meta
Definition: doca_flow.h:305
uint32_t doca_be32_t
Definition: doca_types.h:121
char ct_dev_pci_addr[MAX_PORTS][DOCA_DEVINFO_PCI_ADDR_SIZE]
doca flow CT match pattern
Definition: doca_flow_ct.h:654
doca flow meta data
Definition: doca_flow.h:358
user context struct that will be used in entries process callback
Definition: flow_common.h:78
static int nb_ports
Definition: switch_core.c:44
static struct doca_flow_port * ports[FLOW_SWITCH_PORTS_MAX]
Definition: switch_core.c:42