NVIDIA DOCA SDK Data Center on a Chip Framework Documentation
rmax_common.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2022-2024 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 RMAX_COMMON_H_
27 #define RMAX_COMMON_H_
28 
29 #include <stdbool.h>
30 #include <stdint.h>
31 #include <stdlib.h>
32 
33 #include <doca_argp.h>
34 #include <doca_buf.h>
35 #include <doca_buf_inventory.h>
36 #include <doca_ctx.h>
37 #include <doca_pe.h>
38 #include <doca_dev.h>
39 #include <doca_error.h>
40 #include <doca_log.h>
41 #include <doca_mmap.h>
42 #include <doca_rmax.h>
43 
44 #include "common.h"
45 
46 #define MAX_BUFFERS 2 /* max number of buffers used by the samples */
47 
48 /*
49  * Struct containing all the configurations that needed to set stream and flow parameters.
50  */
52  char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]; /* device PCI address */
53 
54  /* used when setting stream attributes */
55  bool scatter_all; /* scatter all packet data including network headers */
56  uint16_t hdr_size; /* header size */
57  uint16_t data_size; /* payload size */
58  uint32_t num_elements; /* number of elements in the stream buffer */
59 
60  /* used when setting flow attributes */
61  struct in_addr dst_ip; /* destination IP address */
62  struct in_addr src_ip; /* source IP address */
63  uint16_t dst_port; /* destination port */
64 };
65 
66 /*
67  * Struct containing state of a rivermax sample
68  */
70  struct rmax_stream_config *config; /* pointer to the stream configurations */
71  struct program_core_objects core_objects; /* the DOCA core objects */
72  uint16_t stride_size[MAX_BUFFERS]; /* the stride sizes queried from doca_rmax_in_stream */
73  bool run_pe_progress; /* controls whether to keep progressing the PE */
74  doca_error_t exit_status; /* reflects status of last event */
75 };
76 
77 /*
78  * Register the command line parameter for the sample.
79  *
80  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
81  */
83 
84 /*
85  * Set DOCA Rivermax flow relevant parameters, such as src/dst port and IP addresses.
86  *
87  * @config [in]: ca configurations containing all parameters of the flow that needed to be set
88  * @flow [in]: the flow to set its parameters
89  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
90  */
91 doca_error_t rmax_flow_set_attributes(struct rmax_stream_config *config, struct doca_rmax_flow *flow);
92 
93 /*
94  * Set DOCA Rivermax stream relevant parameters, such as buffer size, packet size.
95  *
96  * @stream [in]: the stream to set its attributes
97  * @config [in]: configurations containing all parameters of the stream that needed to be set
98  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
99  */
100 doca_error_t rmax_stream_set_attributes(struct doca_rmax_in_stream *stream, struct rmax_stream_config *config);
101 
102 /*
103  * Start the DOCA rivermax context.
104  *
105  * @state [in]: struct rmax_program_state containing all the program state
106  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
107  */
109 
110 /*
111  * Allocate buffers for received data storage, query stride size.
112  *
113  * @state [in]: struct rmax_program_state containing all the program state
114  * @stream [in]: the stream to set its attributes
115  * @config [in]: configurations containing all parameters of the stream that needed to be set
116  * @buffer [out]: the allocated stream buffer
117  * @stride_size [out]: stride size of memory block
118  * @return: DOCA_SUCCESS on success and DOCA_ERROR otherwise
119  */
121  struct doca_rmax_in_stream *stream,
122  struct rmax_stream_config *config,
123  struct doca_buf **buffer,
124  uint16_t *stride_size);
125 
126 /*
127  * Clean all the sample resources
128  *
129  * @state [in]: struct rmax_program_state containing all the program state
130  * @stream [in]: DOCA Rivermax stream to destroy
131  * @flow [in]: rmax flow to destroy
132  * @buf [in]: allocated DOCA buffer that should be destroyed
133  */
135  struct doca_rmax_in_stream *stream,
136  struct doca_rmax_flow *flow,
137  struct doca_buf *buf);
138 
139 #endif /* RMAX_COMMON_H_ */
#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 rmax_create_stream_cleanup(struct rmax_program_state *state, struct doca_rmax_in_stream *stream, struct doca_rmax_flow *flow, struct doca_buf *buf)
Definition: rmax_common.c:375
doca_error_t rmax_stream_allocate_buf(struct rmax_program_state *state, struct doca_rmax_in_stream *stream, struct rmax_stream_config *config, struct doca_buf **buffer, uint16_t *stride_size)
Definition: rmax_common.c:284
doca_error_t rmax_stream_set_attributes(struct doca_rmax_in_stream *stream, struct rmax_stream_config *config)
Definition: rmax_common.c:226
#define MAX_BUFFERS
Definition: rmax_common.h:46
doca_error_t rmax_flow_set_attributes(struct rmax_stream_config *config, struct doca_rmax_flow *flow)
Definition: rmax_common.c:207
doca_error_t register_create_stream_params(void)
Definition: rmax_common.c:116
doca_error_t rmax_stream_start(struct rmax_program_state *state)
Definition: rmax_common.c:267
struct program_core_objects core_objects
Definition: rmax_common.h:71
struct rmax_stream_config * config
Definition: rmax_common.h:70
uint16_t stride_size[MAX_BUFFERS]
Definition: rmax_common.h:72
doca_error_t exit_status
Definition: rmax_common.h:74
struct in_addr dst_ip
Definition: rmax_common.h:61
uint16_t data_size
Definition: rmax_common.h:57
uint32_t num_elements
Definition: rmax_common.h:58
char pci_address[DOCA_DEVINFO_PCI_ADDR_SIZE]
Definition: rmax_common.h:52
struct in_addr src_ip
Definition: rmax_common.h:62