xref: /dpdk/drivers/net/ntnic/include/flow_api.h (revision 7917b0d38e92e8b9ec5a870415b791420e10f11a)
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 
38 	/* 0th for exception */
39 	struct flow_queue_id_s rx_queue[FLOW_MAX_QUEUES + 1];
40 
41 	/* VSWITCH has exceptions sent on queue 0 per design */
42 	int num_queues;
43 
44 	struct flow_eth_dev *next;
45 };
46 
47 /* registered NIC backends */
48 struct flow_nic_dev {
49 	uint8_t adapter_no;     /* physical adapter no in the host system */
50 	uint16_t ports; /* number of in-ports addressable on this NIC */
51 
52 	struct hw_mod_resource_s res[RES_COUNT];/* raw NIC resource allocation table */
53 	void *km_res_handle;
54 	void *kcc_res_handle;
55 
56 	uint32_t flow_unique_id_counter;
57 	/* linked list of all flows created on this NIC */
58 	struct flow_handle *flow_base;
59 
60 	/* NIC backend API */
61 	struct flow_api_backend_s be;
62 	/* linked list of created eth-port devices on this NIC */
63 	struct flow_eth_dev *eth_base;
64 	pthread_mutex_t mtx;
65 
66 	/* next NIC linked list */
67 	struct flow_nic_dev *next;
68 };
69 
70 /*
71  * Resources
72  */
73 
74 extern const char *dbg_res_descr[];
75 
76 #define flow_nic_unset_bit(arr, x)                                                                \
77 	do {                                                                                      \
78 		size_t _temp_x = (x);                                                             \
79 		arr[_temp_x / 8] &= (uint8_t)(~(1 << (_temp_x % 8)));                             \
80 	} while (0)
81 
82 #define flow_nic_is_bit_set(arr, x)                                                               \
83 	({                                                                                        \
84 		size_t _temp_x = (x);                                                             \
85 		(arr[_temp_x / 8] & (uint8_t)(1 << (_temp_x % 8)));                               \
86 	})
87 
88 #define flow_nic_mark_resource_unused(_ndev, res_type, index)                                     \
89 	do {                                                                                      \
90 		typeof(res_type) _temp_res_type = (res_type);                                 \
91 		size_t _temp_index = (index);                                                     \
92 		NT_LOG(DBG, FILTER, "mark resource unused: %s idx %zu",                         \
93 		       dbg_res_descr[_temp_res_type], _temp_index);                               \
94 		flow_nic_unset_bit((_ndev)->res[_temp_res_type].alloc_bm, _temp_index);           \
95 	} while (0)
96 
97 #define flow_nic_is_resource_used(_ndev, res_type, index)                                         \
98 	(!!flow_nic_is_bit_set((_ndev)->res[res_type].alloc_bm, index))
99 
100 void flow_nic_free_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int idx);
101 
102 int flow_nic_deref_resource(struct flow_nic_dev *ndev, enum res_type_e res_type, int index);
103 
104 #endif
105