1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright 2020 Mellanox Technologies, Ltd
4 * The file contains the implementations of actions generators.
5 * Each generator is responsible for preparing it's action instance
6 * and initializing it with needed data.
10 #include <rte_malloc.h>
12 #include <rte_ethdev.h>
14 #include "actions_gen.h"
18 /* Storage for additional parameters for actions */
19 struct additional_para {
23 uint16_t queues_number;
26 /* Storage for struct rte_flow_action_rss including external data. */
27 struct action_rss_data {
28 struct rte_flow_action_rss conf;
34 add_mark(struct rte_flow_action *actions,
35 uint8_t actions_counter,
36 __rte_unused struct additional_para para)
38 static struct rte_flow_action_mark mark_action;
41 mark_action.id = MARK_ID;
44 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_MARK;
45 actions[actions_counter].conf = &mark_action;
49 add_queue(struct rte_flow_action *actions,
50 uint8_t actions_counter,
51 struct additional_para para)
53 static struct rte_flow_action_queue queue_action;
56 queue_action.index = para.queue;
59 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_QUEUE;
60 actions[actions_counter].conf = &queue_action;
64 add_jump(struct rte_flow_action *actions,
65 uint8_t actions_counter,
66 struct additional_para para)
68 static struct rte_flow_action_jump jump_action;
71 jump_action.group = para.next_table;
74 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_JUMP;
75 actions[actions_counter].conf = &jump_action;
79 add_rss(struct rte_flow_action *actions,
80 uint8_t actions_counter,
81 struct additional_para para)
83 static struct rte_flow_action_rss *rss_action;
84 static struct action_rss_data *rss_data;
88 rss_data = rte_malloc("rss_data",
89 sizeof(struct action_rss_data), 0);
92 rte_exit(EXIT_FAILURE, "No Memory available!");
94 *rss_data = (struct action_rss_data){
95 .conf = (struct rte_flow_action_rss){
96 .func = RTE_ETH_HASH_FUNCTION_DEFAULT,
98 .types = GET_RSS_HF(),
99 .key_len = sizeof(rss_data->key),
100 .queue_num = para.queues_number,
101 .key = rss_data->key,
102 .queue = rss_data->queue,
108 for (queue = 0; queue < para.queues_number; queue++)
109 rss_data->queue[queue] = para.queues[queue];
111 rss_action = &rss_data->conf;
113 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_RSS;
114 actions[actions_counter].conf = rss_action;
118 add_set_meta(struct rte_flow_action *actions,
119 uint8_t actions_counter,
120 __rte_unused struct additional_para para)
122 static struct rte_flow_action_set_meta meta_action;
125 meta_action.data = RTE_BE32(META_DATA);
126 meta_action.mask = RTE_BE32(0xffffffff);
129 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_SET_META;
130 actions[actions_counter].conf = &meta_action;
134 add_set_tag(struct rte_flow_action *actions,
135 uint8_t actions_counter,
136 __rte_unused struct additional_para para)
138 static struct rte_flow_action_set_tag tag_action;
141 tag_action.data = RTE_BE32(META_DATA);
142 tag_action.mask = RTE_BE32(0xffffffff);
143 tag_action.index = TAG_INDEX;
146 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_SET_TAG;
147 actions[actions_counter].conf = &tag_action;
151 add_port_id(struct rte_flow_action *actions,
152 uint8_t actions_counter,
153 __rte_unused struct additional_para para)
155 static struct rte_flow_action_port_id port_id;
158 port_id.id = PORT_ID_DST;
161 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_PORT_ID;
162 actions[actions_counter].conf = &port_id;
166 add_drop(struct rte_flow_action *actions,
167 uint8_t actions_counter,
168 __rte_unused struct additional_para para)
170 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_DROP;
174 add_count(struct rte_flow_action *actions,
175 uint8_t actions_counter,
176 __rte_unused struct additional_para para)
178 static struct rte_flow_action_count count_action;
180 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_COUNT;
181 actions[actions_counter].conf = &count_action;
185 fill_actions(struct rte_flow_action *actions, uint64_t *flow_actions,
186 uint32_t counter, uint16_t next_table, uint16_t hairpinq)
188 struct additional_para additional_para_data;
189 uint8_t actions_counter = 0;
190 uint16_t hairpin_queues[hairpinq];
191 uint16_t queues[RXQ_NUM];
194 for (i = 0; i < RXQ_NUM; i++)
197 for (i = 0; i < hairpinq; i++)
198 hairpin_queues[i] = i + RXQ_NUM;
200 additional_para_data = (struct additional_para){
201 .queue = counter % RXQ_NUM,
202 .next_table = next_table,
204 .queues_number = RXQ_NUM,
208 additional_para_data.queues = hairpin_queues;
209 additional_para_data.queues_number = hairpinq;
210 additional_para_data.queue = (counter % hairpinq) + RXQ_NUM;
213 static const struct actions_dict {
216 struct rte_flow_action *actions,
217 uint8_t actions_counter,
218 struct additional_para para
222 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_MARK),
226 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_COUNT),
230 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_META),
231 .funct = add_set_meta,
234 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_SET_TAG),
235 .funct = add_set_tag,
238 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_QUEUE),
242 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_RSS),
246 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_JUMP),
250 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_PORT_ID),
254 .mask = FLOW_ACTION_MASK(RTE_FLOW_ACTION_TYPE_DROP),
258 .mask = HAIRPIN_QUEUE_ACTION,
262 .mask = HAIRPIN_RSS_ACTION,
267 for (j = 0; j < MAX_ACTIONS_NUM; j++) {
268 if (flow_actions[j] == 0)
270 for (i = 0; i < RTE_DIM(actions_list); i++) {
271 if ((flow_actions[j] &
272 actions_list[i].mask) == 0)
274 actions_list[i].funct(
275 actions, actions_counter++,
281 actions[actions_counter].type = RTE_FLOW_ACTION_TYPE_END;