xref: /dpdk/lib/table/rte_swx_table_selector.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
1f7598a62SCristian Dumitrescu /* SPDX-License-Identifier: BSD-3-Clause
2f7598a62SCristian Dumitrescu  * Copyright(c) 2021 Intel Corporation
3f7598a62SCristian Dumitrescu  */
4f7598a62SCristian Dumitrescu #ifndef __INCLUDE_RTE_SWX_TABLE_SELECTOR_H__
5f7598a62SCristian Dumitrescu #define __INCLUDE_RTE_SWX_TABLE_SELECTOR_H__
6f7598a62SCristian Dumitrescu 
7f7598a62SCristian Dumitrescu /**
8f7598a62SCristian Dumitrescu  * @file
9f7598a62SCristian Dumitrescu  * RTE SWX Selector Table
10f7598a62SCristian Dumitrescu  *
11f7598a62SCristian Dumitrescu  * Selector table interface.
12f7598a62SCristian Dumitrescu  */
13f7598a62SCristian Dumitrescu 
14f7598a62SCristian Dumitrescu #include <stdint.h>
15f7598a62SCristian Dumitrescu 
16f7598a62SCristian Dumitrescu #include <rte_compat.h>
17f7598a62SCristian Dumitrescu 
18f7598a62SCristian Dumitrescu #include "rte_swx_table.h"
19f7598a62SCristian Dumitrescu 
20*719834a6SMattias Rönnblom #ifdef __cplusplus
21*719834a6SMattias Rönnblom extern "C" {
22*719834a6SMattias Rönnblom #endif
23*719834a6SMattias Rönnblom 
24f7598a62SCristian Dumitrescu /** Selector table creation parameters. */
25f7598a62SCristian Dumitrescu struct rte_swx_table_selector_params {
26f7598a62SCristian Dumitrescu 	/** Group ID offset. */
27f7598a62SCristian Dumitrescu 	uint32_t group_id_offset;
28f7598a62SCristian Dumitrescu 
29f7598a62SCristian Dumitrescu 	/** Selector size in bytes. Must be non-zero. */
30f7598a62SCristian Dumitrescu 	uint32_t selector_size;
31f7598a62SCristian Dumitrescu 
32f7598a62SCristian Dumitrescu 	/** Offset of the first byte of the selector within the selector buffer. */
33f7598a62SCristian Dumitrescu 	uint32_t selector_offset;
34f7598a62SCristian Dumitrescu 
35f7598a62SCristian Dumitrescu 	/** Mask of *selector_size* bytes logically laid over the bytes at positions
36f7598a62SCristian Dumitrescu 	 * selector_offset* .. (*selector_offset* + *selector_size* - 1) of the selector buffer in
37f7598a62SCristian Dumitrescu 	 * order to specify which bits from the selector buffer are part of the selector and which
38f7598a62SCristian Dumitrescu 	 * ones are not. A bit value of 1 in the *selector_mask* means the respective bit in the
39f7598a62SCristian Dumitrescu 	 * selector buffer is part of the selector, while a bit value of 0 means the opposite. A
40f7598a62SCristian Dumitrescu 	 * NULL value means that all the bits are part of the selector, i.e. the *selector_mask*
41f7598a62SCristian Dumitrescu 	 * is an all-ones mask.
42f7598a62SCristian Dumitrescu 	 */
43f7598a62SCristian Dumitrescu 	uint8_t *selector_mask;
44f7598a62SCristian Dumitrescu 
45f7598a62SCristian Dumitrescu 	/** Member ID offset. */
46f7598a62SCristian Dumitrescu 	uint32_t member_id_offset;
47f7598a62SCristian Dumitrescu 
48f7598a62SCristian Dumitrescu 	/** Maximum number of groups. Must be non-zero. */
49f7598a62SCristian Dumitrescu 	uint32_t n_groups_max;
50f7598a62SCristian Dumitrescu 
51f7598a62SCristian Dumitrescu 	/** Maximum number of members per group. Must be non-zero. */
52f7598a62SCristian Dumitrescu 	uint32_t n_members_per_group_max;
53f7598a62SCristian Dumitrescu };
54f7598a62SCristian Dumitrescu 
55f7598a62SCristian Dumitrescu /** Group member parameters. */
56f7598a62SCristian Dumitrescu struct rte_swx_table_selector_member {
57f7598a62SCristian Dumitrescu 	/** Linked list connectivity. */
58f1f6ebc0SWilliam Tu 	RTE_TAILQ_ENTRY(rte_swx_table_selector_member) node;
59f7598a62SCristian Dumitrescu 
60f7598a62SCristian Dumitrescu 	/** Member ID. */
61f7598a62SCristian Dumitrescu 	uint32_t member_id;
62f7598a62SCristian Dumitrescu 
63f7598a62SCristian Dumitrescu 	/** Member weight. */
64f7598a62SCristian Dumitrescu 	uint32_t member_weight;
65f7598a62SCristian Dumitrescu };
66f7598a62SCristian Dumitrescu 
67f7598a62SCristian Dumitrescu /** List of group members. */
68f1f6ebc0SWilliam Tu RTE_TAILQ_HEAD(rte_swx_table_selector_member_list, rte_swx_table_selector_member);
69f7598a62SCristian Dumitrescu 
70f7598a62SCristian Dumitrescu /** Group parameters. */
71f7598a62SCristian Dumitrescu struct rte_swx_table_selector_group {
72f7598a62SCristian Dumitrescu 	/** List of group members. */
73f7598a62SCristian Dumitrescu 	struct rte_swx_table_selector_member_list members;
74f7598a62SCristian Dumitrescu };
75f7598a62SCristian Dumitrescu 
76f7598a62SCristian Dumitrescu /**
77f7598a62SCristian Dumitrescu  * Selector table memory footprint get
78f7598a62SCristian Dumitrescu  *
79f7598a62SCristian Dumitrescu  * @param[in] n_groups_max
80f7598a62SCristian Dumitrescu  *   Maximum number of groups. Must be non-zero.
81f7598a62SCristian Dumitrescu  * @param[in] n_members_per_group_max
82f7598a62SCristian Dumitrescu  *   Maximum number of members per group. Must be non-zero.
83f7598a62SCristian Dumitrescu  * @return
84f7598a62SCristian Dumitrescu  *   Selector table memory footprint in bytes.
85f7598a62SCristian Dumitrescu  */
86f7598a62SCristian Dumitrescu __rte_experimental
87f7598a62SCristian Dumitrescu uint64_t
88f7598a62SCristian Dumitrescu rte_swx_table_selector_footprint_get(uint32_t n_groups_max, uint32_t n_members_per_group_max);
89f7598a62SCristian Dumitrescu 
90f7598a62SCristian Dumitrescu /**
91f7598a62SCristian Dumitrescu  * Selector table mailbox size get
92f7598a62SCristian Dumitrescu  *
93f7598a62SCristian Dumitrescu  * The mailbox is used to store the context of a select operation that is in
94f7598a62SCristian Dumitrescu  * progress and it is passed as a parameter to the select operation. This allows
95f7598a62SCristian Dumitrescu  * for multiple concurrent select operations into the same table.
96f7598a62SCristian Dumitrescu  *
97f7598a62SCristian Dumitrescu  * @return
98f7598a62SCristian Dumitrescu  *   Selector table mailbox footprint in bytes.
99f7598a62SCristian Dumitrescu  */
100f7598a62SCristian Dumitrescu __rte_experimental
101f7598a62SCristian Dumitrescu uint64_t
102f7598a62SCristian Dumitrescu rte_swx_table_selector_mailbox_size_get(void);
103f7598a62SCristian Dumitrescu 
104f7598a62SCristian Dumitrescu /**
105f7598a62SCristian Dumitrescu  * Selector table create
106f7598a62SCristian Dumitrescu  *
107f7598a62SCristian Dumitrescu  * @param[in] params
108f7598a62SCristian Dumitrescu  *   Selector table creation parameters.
109f7598a62SCristian Dumitrescu  * @param[in] groups
110f7598a62SCristian Dumitrescu  *   Groups to be added to the table at creation time. When NULL, it signifies that all groups are
111f7598a62SCristian Dumitrescu  *   invalid, otherwise it points to a pre-allocated array of size *n_groups_max*, where a NULL
112f7598a62SCristian Dumitrescu  *   element indicates that the associated group is invalid.
113f7598a62SCristian Dumitrescu  * @param[in] numa_node
114f7598a62SCristian Dumitrescu  *   Non-Uniform Memory Access (NUMA) node.
115f7598a62SCristian Dumitrescu  * @return
116f7598a62SCristian Dumitrescu  *   Table handle, on success, or NULL, on error.
117f7598a62SCristian Dumitrescu  */
118f7598a62SCristian Dumitrescu __rte_experimental
119f7598a62SCristian Dumitrescu void *
120f7598a62SCristian Dumitrescu rte_swx_table_selector_create(struct rte_swx_table_selector_params *params,
121f7598a62SCristian Dumitrescu 			      struct rte_swx_table_selector_group **groups,
122f7598a62SCristian Dumitrescu 			      int numa_node);
123f7598a62SCristian Dumitrescu 
124f7598a62SCristian Dumitrescu /**
125f7598a62SCristian Dumitrescu  * Group set
126f7598a62SCristian Dumitrescu  *
127f7598a62SCristian Dumitrescu  * @param[in] table
128f7598a62SCristian Dumitrescu  *   Selector table handle.
129f7598a62SCristian Dumitrescu  * @param[in] group_id
130f7598a62SCristian Dumitrescu  *   Group ID.
131f7598a62SCristian Dumitrescu  * @param[in] group
132f7598a62SCristian Dumitrescu  *   Group parameters.
133f7598a62SCristian Dumitrescu  * @return
134f7598a62SCristian Dumitrescu  *   0 on success or the following error codes otherwise:
135f7598a62SCristian Dumitrescu  *   -EINVAL: Invalid argument(s);
136f7598a62SCristian Dumitrescu  *   -ENOSPC: Too many group members.
137f7598a62SCristian Dumitrescu  */
138f7598a62SCristian Dumitrescu __rte_experimental
139f7598a62SCristian Dumitrescu int
140f7598a62SCristian Dumitrescu rte_swx_table_selector_group_set(void *table,
141f7598a62SCristian Dumitrescu 				 uint32_t group_id,
142f7598a62SCristian Dumitrescu 				 struct rte_swx_table_selector_group *group);
143f7598a62SCristian Dumitrescu 
144f7598a62SCristian Dumitrescu /**
145f7598a62SCristian Dumitrescu  * Selector table select
146f7598a62SCristian Dumitrescu  *
147f7598a62SCristian Dumitrescu  * This operation selects a member from the given group based on a hasing scheme.
148f7598a62SCristian Dumitrescu  *
149f7598a62SCristian Dumitrescu  * Multiple invocations of this function may be required in order to complete a single select
150f7598a62SCristian Dumitrescu  * operation for a given table and a given group ID. The completion of the operation is flagged by
151f7598a62SCristian Dumitrescu  * a return value of 1; in case of a return value of 0, the function must be invoked again with
152f7598a62SCristian Dumitrescu  * exactly the same arguments.
153f7598a62SCristian Dumitrescu  *
154f7598a62SCristian Dumitrescu  * The mailbox argument is used to store the context of each on-going  operation. The mailbox
155f7598a62SCristian Dumitrescu  * mechanism allows for multiple concurrent select operations into the same table.
156f7598a62SCristian Dumitrescu  *
157f7598a62SCristian Dumitrescu  * The typical reason an implementation may choose to split the operation into multiple steps is to
1587be78d02SJosh Soref  * hide the latency of the inherent memory read operations: before a read operation with the
159f7598a62SCristian Dumitrescu  * source data likely not in the CPU cache, the source data prefetch is issued and the operation is
160f7598a62SCristian Dumitrescu  * postponed in favor of some other unrelated work, which the CPU executes in parallel with the
161f7598a62SCristian Dumitrescu  * source data being fetched into the CPU cache; later on, the operation is resumed, this time with
162f7598a62SCristian Dumitrescu  * the source data likely to be read from the CPU cache with no CPU pipeline stall, which
163f7598a62SCristian Dumitrescu  * significantly improves the operation performance.
164f7598a62SCristian Dumitrescu  *
165f7598a62SCristian Dumitrescu  * @param[in] table
166f7598a62SCristian Dumitrescu  *   Selector table handle.
167f7598a62SCristian Dumitrescu  * @param[in] mailbox
168f7598a62SCristian Dumitrescu  *   Mailbox for the current operation.
169f7598a62SCristian Dumitrescu  * @param[in] group_id_buffer
170f7598a62SCristian Dumitrescu  *   Buffer where the input group ID is located at offset *group_id_offset*.
171f7598a62SCristian Dumitrescu  * @param[in] selector_buffer
172f7598a62SCristian Dumitrescu  *   Buffer where the key to select a member within the identified group is located starting from
173f7598a62SCristian Dumitrescu  *   offset *selector_offset*. Its size must be equal to the table *selector_size*.
174f7598a62SCristian Dumitrescu  * @param[in] member_id_buffer
175f7598a62SCristian Dumitrescu  *   Buffer where the output member ID is to be placed at offset *member_id_offset*.
176f7598a62SCristian Dumitrescu  * @return
177f7598a62SCristian Dumitrescu  *   0 when the operation is not yet completed, and 1 when the operation is complete. No other
178f7598a62SCristian Dumitrescu  *   return values are allowed.
179f7598a62SCristian Dumitrescu  */
180f7598a62SCristian Dumitrescu __rte_experimental
181f7598a62SCristian Dumitrescu int
182f7598a62SCristian Dumitrescu rte_swx_table_selector_select(void *table,
183f7598a62SCristian Dumitrescu 			      void *mailbox,
184f7598a62SCristian Dumitrescu 			      uint8_t **group_id_buffer,
185f7598a62SCristian Dumitrescu 			      uint8_t **selector_buffer,
186f7598a62SCristian Dumitrescu 			      uint8_t **member_id_buffer);
187f7598a62SCristian Dumitrescu 
188f7598a62SCristian Dumitrescu /**
189f7598a62SCristian Dumitrescu  * Selector table free
190f7598a62SCristian Dumitrescu  *
191f7598a62SCristian Dumitrescu  * @param[in] table
192f7598a62SCristian Dumitrescu  *   Selector table handle.
193f7598a62SCristian Dumitrescu  */
194f7598a62SCristian Dumitrescu __rte_experimental
195f7598a62SCristian Dumitrescu void
196f7598a62SCristian Dumitrescu rte_swx_table_selector_free(void *table);
197f7598a62SCristian Dumitrescu 
198f7598a62SCristian Dumitrescu #ifdef __cplusplus
199f7598a62SCristian Dumitrescu }
200f7598a62SCristian Dumitrescu #endif
201f7598a62SCristian Dumitrescu 
202f7598a62SCristian Dumitrescu #endif
203