xref: /dpdk/drivers/net/ntnic/include/flow_api.h (revision 98e40f83f49d1b37c33d59a196e20bd66c83cd81)
1 /*
2  * SPDX-License-Identifier: BSD-3-Clause
3  * Copyright(c) 2023 Napatech A/S
4  */
5 
6 #ifndef _FLOW_API_H_
7 #define _FLOW_API_H_
8 
9 #include <pthread.h>
10 
11 #include "ntlog.h"
12 
13 #include "flow_api_engine.h"
14 #include "hw_mod_backend.h"
15 #include "stream_binary_flow_api.h"
16 
17 /*
18  * Flow NIC and Eth port device management
19  */
20 
21 struct hw_mod_resource_s {
22 	uint8_t *alloc_bm;      /* allocation bitmap */
23 	uint32_t *ref;  /* reference counter for each resource element */
24 	uint32_t resource_count;/* number of total available entries */
25 };
26 
27 /*
28  * Device Management API
29  */
30 int flow_delete_eth_dev(struct flow_eth_dev *eth_dev);
31 
32 struct flow_eth_dev {
33 	/* NIC that owns this port device */
34 	struct flow_nic_dev *ndev;
35 	/* NIC port id */
36 	uint8_t port;
37 	/* App assigned port_id - may be DPDK port_id */
38 	uint32_t port_id;
39 
40 	/* 0th for exception */
41 	struct flow_queue_id_s rx_queue[FLOW_MAX_QUEUES + 1];
42 
43 	/* VSWITCH has exceptions sent on queue 0 per design */
44 	int num_queues;
45 
46 	/* QSL_HSH index if RSS needed QSL v6+ */
47 	int rss_target_id;
48 
49 	struct flow_eth_dev *next;
50 };
51 
52 /* registered NIC backends */
53 struct flow_nic_dev {
54 	uint8_t adapter_no;     /* physical adapter no in the host system */
55 	uint16_t ports; /* number of in-ports addressable on this NIC */
56 	/* flow profile this NIC is initially prepared for */
57 	enum flow_eth_dev_profile flow_profile;
58 	int flow_mgnt_prepared;
59 
60 	struct hw_mod_resource_s res[RES_COUNT];/* raw NIC resource allocation table */
61 	void *km_res_handle;
62 	void *kcc_res_handle;
63 
64 	void *group_handle;
65 	void *hw_db_handle;
66 	void *id_table_handle;
67 
68 	uint32_t flow_unique_id_counter;
69 	/* linked list of all flows created on this NIC */
70 	struct flow_handle *flow_base;
71 	/* linked list of all FLM flows created on this NIC */
72 	struct flow_handle *flow_base_flm;
73 	pthread_mutex_t flow_mtx;
74 
75 	/* NIC backend API */
76 	struct flow_api_backend_s be;
77 	/* linked list of created eth-port devices on this NIC */
78 	struct flow_eth_dev *eth_base;
79 	pthread_mutex_t mtx;
80 
81 	/* next NIC linked list */
82 	struct flow_nic_dev *next;
83 };
84 
85 enum flow_nic_err_msg_e {
86 	ERR_SUCCESS = 0,
87 	ERR_FAILED = 1,
88 	ERR_MEMORY = 2,
89 	ERR_OUTPUT_TOO_MANY = 3,
90 	ERR_RSS_TOO_MANY_QUEUES = 4,
91 	ERR_VLAN_TYPE_NOT_SUPPORTED = 5,
92 	ERR_VXLAN_HEADER_NOT_ACCEPTED = 6,
93 	ERR_VXLAN_POP_INVALID_RECIRC_PORT = 7,
94 	ERR_VXLAN_POP_FAILED_CREATING_VTEP = 8,
95 	ERR_MATCH_VLAN_TOO_MANY = 9,
96 	ERR_MATCH_INVALID_IPV6_HDR = 10,
97 	ERR_MATCH_TOO_MANY_TUNNEL_PORTS = 11,
98 	ERR_MATCH_INVALID_OR_UNSUPPORTED_ELEM = 12,
99 	ERR_MATCH_FAILED_BY_HW_LIMITS = 13,
100 	ERR_MATCH_RESOURCE_EXHAUSTION = 14,
101 	ERR_MATCH_FAILED_TOO_COMPLEX = 15,
102 	ERR_ACTION_REPLICATION_FAILED = 16,
103 	ERR_ACTION_OUTPUT_RESOURCE_EXHAUSTION = 17,
104 	ERR_ACTION_TUNNEL_HEADER_PUSH_OUTPUT_LIMIT = 18,
105 	ERR_ACTION_INLINE_MOD_RESOURCE_EXHAUSTION = 19,
106 	ERR_ACTION_RETRANSMIT_RESOURCE_EXHAUSTION = 20,
107 	ERR_ACTION_FLOW_COUNTER_EXHAUSTION = 21,
108 	ERR_ACTION_INTERNAL_RESOURCE_EXHAUSTION = 22,
109 	ERR_INTERNAL_QSL_COMPARE_FAILED = 23,
110 	ERR_INTERNAL_CAT_FUNC_REUSE_FAILED = 24,
111 	ERR_MATCH_ENTROPHY_FAILED = 25,
112 	ERR_MATCH_CAM_EXHAUSTED = 26,
113 	ERR_INTERNAL_VIRTUAL_PORT_CREATION_FAILED = 27,
114 	ERR_ACTION_UNSUPPORTED = 28,
115 	ERR_REMOVE_FLOW_FAILED = 29,
116 	ERR_ACTION_NO_OUTPUT_DEFINED_USE_DEFAULT = 30,
117 	ERR_ACTION_NO_OUTPUT_QUEUE_FOUND = 31,
118 	ERR_MATCH_UNSUPPORTED_ETHER_TYPE = 32,
119 	ERR_OUTPUT_INVALID = 33,
120 	ERR_MATCH_PARTIAL_OFFLOAD_NOT_SUPPORTED = 34,
121 	ERR_MATCH_CAT_CAM_EXHAUSTED = 35,
122 	ERR_MATCH_KCC_KEY_CLASH = 36,
123 	ERR_MATCH_CAT_CAM_FAILED = 37,
124 	ERR_PARTIAL_FLOW_MARK_TOO_BIG = 38,
125 	ERR_FLOW_PRIORITY_VALUE_INVALID = 39,
126 	ERR_ACTION_MULTIPLE_PORT_ID_UNSUPPORTED = 40,
127 	ERR_RSS_TOO_LONG_KEY = 41,
128 	ERR_ACTION_AGE_UNSUPPORTED_GROUP_0 = 42,
129 	ERR_MSG_NO_MSG
130 };
131 
132 void flow_nic_set_error(enum flow_nic_err_msg_e msg, struct rte_flow_error *error);
133 
134 /*
135  * Resources
136  */
137 
138 extern const char *dbg_res_descr[];
139 
140 #define flow_nic_set_bit(arr, x)                                                                  \
141 	do {                                                                                      \
142 		uint8_t *_temp_arr = (arr);                                                       \
143 		size_t _temp_x = (x);                                                             \
144 		_temp_arr[_temp_x / 8] =                                                          \
145 			(uint8_t)(_temp_arr[_temp_x / 8] | (uint8_t)(1 << (_temp_x % 8)));        \
146 	} while (0)
147 
148 #define flow_nic_unset_bit(arr, x)                                                                \
149 	do {                                                                                      \
150 		size_t _temp_x = (x);                                                             \
151 		arr[_temp_x / 8] &= (uint8_t)(~(1 << (_temp_x % 8)));                             \
152 	} while (0)
153 
154 #define flow_nic_is_bit_set(arr, x)                                                               \
155 	({                                                                                        \
156 		size_t _temp_x = (x);                                                             \
157 		(arr[_temp_x / 8] & (uint8_t)(1 << (_temp_x % 8)));                               \
158 	})
159 
160 #define flow_nic_mark_resource_used(_ndev, res_type, index)                                       \
161 	do {                                                                                      \
162 		struct flow_nic_dev *_temp_ndev = (_ndev);                                        \
163 		typeof(res_type) _temp_res_type = (res_type);                                     \
164 		size_t _temp_index = (index);                                                     \
165 		NT_LOG(DBG, FILTER, "mark resource used: %s idx %zu",                             \
166 		       dbg_res_descr[_temp_res_type], _temp_index);                               \
167 		assert(flow_nic_is_bit_set(_temp_ndev->res[_temp_res_type].alloc_bm,              \
168 					   _temp_index) == 0);                                    \
169 		flow_nic_set_bit(_temp_ndev->res[_temp_res_type].alloc_bm, _temp_index);          \
170 	} while (0)
171 
172 #define flow_nic_mark_resource_unused(_ndev, res_type, index)                                     \
173 	do {                                                                                      \
174 		typeof(res_type) _temp_res_type = (res_type);                                 \
175 		size_t _temp_index = (index);                                                     \
176 		NT_LOG(DBG, FILTER, "mark resource unused: %s idx %zu",                         \
177 		       dbg_res_descr[_temp_res_type], _temp_index);                               \
178 		flow_nic_unset_bit((_ndev)->res[_temp_res_type].alloc_bm, _temp_index);           \
179 	} while (0)
180 
181 #define flow_nic_is_resource_used(_ndev, res_type, index)                                         \
182 	(!!flow_nic_is_bit_set((_ndev)->res[res_type].alloc_bm, index))
183 
184 int flow_nic_alloc_resource(struct flow_nic_dev *ndev, enum res_type_e res_type,
185 	uint32_t alignment);
186 
187 int flow_nic_alloc_resource_config(struct flow_nic_dev *ndev, enum res_type_e res_type,
188 	unsigned int num, uint32_t alignment);
189 void flow_nic_free_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int idx);
190 
191 int flow_nic_ref_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int index);
192 int flow_nic_deref_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int index);
193 
194 #endif
195