Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(C) 2021 Marvell.
3 : : */
4 : : #include <cnxk_flow.h>
5 : : #include <cnxk_rep.h>
6 : :
7 : : #define IS_REP_BIT 7
8 : :
9 : : #define TNL_DCP_MATCH_ID 5
10 : : #define NRML_MATCH_ID 1
11 : :
12 : : const struct cnxk_rte_flow_term_info term[] = {
13 : : [RTE_FLOW_ITEM_TYPE_ETH] = {ROC_NPC_ITEM_TYPE_ETH, sizeof(struct rte_flow_item_eth)},
14 : : [RTE_FLOW_ITEM_TYPE_VLAN] = {ROC_NPC_ITEM_TYPE_VLAN, sizeof(struct rte_flow_item_vlan)},
15 : : [RTE_FLOW_ITEM_TYPE_E_TAG] = {ROC_NPC_ITEM_TYPE_E_TAG, sizeof(struct rte_flow_item_e_tag)},
16 : : [RTE_FLOW_ITEM_TYPE_IPV4] = {ROC_NPC_ITEM_TYPE_IPV4, sizeof(struct rte_flow_item_ipv4)},
17 : : [RTE_FLOW_ITEM_TYPE_IPV6] = {ROC_NPC_ITEM_TYPE_IPV6, sizeof(struct rte_flow_item_ipv6)},
18 : : [RTE_FLOW_ITEM_TYPE_IPV6_FRAG_EXT] = {ROC_NPC_ITEM_TYPE_IPV6_FRAG_EXT,
19 : : sizeof(struct rte_flow_item_ipv6_frag_ext)},
20 : : [RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4] = {ROC_NPC_ITEM_TYPE_ARP_ETH_IPV4,
21 : : sizeof(struct rte_flow_item_arp_eth_ipv4)},
22 : : [RTE_FLOW_ITEM_TYPE_MPLS] = {ROC_NPC_ITEM_TYPE_MPLS, sizeof(struct rte_flow_item_mpls)},
23 : : [RTE_FLOW_ITEM_TYPE_ICMP] = {ROC_NPC_ITEM_TYPE_ICMP, sizeof(struct rte_flow_item_icmp)},
24 : : [RTE_FLOW_ITEM_TYPE_UDP] = {ROC_NPC_ITEM_TYPE_UDP, sizeof(struct rte_flow_item_udp)},
25 : : [RTE_FLOW_ITEM_TYPE_TCP] = {ROC_NPC_ITEM_TYPE_TCP, sizeof(struct rte_flow_item_tcp)},
26 : : [RTE_FLOW_ITEM_TYPE_SCTP] = {ROC_NPC_ITEM_TYPE_SCTP, sizeof(struct rte_flow_item_sctp)},
27 : : [RTE_FLOW_ITEM_TYPE_ESP] = {ROC_NPC_ITEM_TYPE_ESP, sizeof(struct rte_flow_item_esp)},
28 : : [RTE_FLOW_ITEM_TYPE_GRE] = {ROC_NPC_ITEM_TYPE_GRE, sizeof(struct rte_flow_item_gre)},
29 : : [RTE_FLOW_ITEM_TYPE_NVGRE] = {ROC_NPC_ITEM_TYPE_NVGRE, sizeof(struct rte_flow_item_nvgre)},
30 : : [RTE_FLOW_ITEM_TYPE_VXLAN] = {ROC_NPC_ITEM_TYPE_VXLAN, sizeof(struct rte_flow_item_vxlan)},
31 : : [RTE_FLOW_ITEM_TYPE_GTPC] = {ROC_NPC_ITEM_TYPE_GTPC, sizeof(struct rte_flow_item_gtp)},
32 : : [RTE_FLOW_ITEM_TYPE_GTPU] = {ROC_NPC_ITEM_TYPE_GTPU, sizeof(struct rte_flow_item_gtp)},
33 : : [RTE_FLOW_ITEM_TYPE_GENEVE] = {ROC_NPC_ITEM_TYPE_GENEVE,
34 : : sizeof(struct rte_flow_item_geneve)},
35 : : [RTE_FLOW_ITEM_TYPE_VXLAN_GPE] = {ROC_NPC_ITEM_TYPE_VXLAN_GPE,
36 : : sizeof(struct rte_flow_item_vxlan_gpe)},
37 : : [RTE_FLOW_ITEM_TYPE_IPV6_EXT] = {ROC_NPC_ITEM_TYPE_IPV6_EXT,
38 : : sizeof(struct rte_flow_item_ipv6_ext)},
39 : : [RTE_FLOW_ITEM_TYPE_VOID] = {ROC_NPC_ITEM_TYPE_VOID, 0},
40 : : [RTE_FLOW_ITEM_TYPE_ANY] = {ROC_NPC_ITEM_TYPE_ANY, 0},
41 : : [RTE_FLOW_ITEM_TYPE_GRE_KEY] = {ROC_NPC_ITEM_TYPE_GRE_KEY, sizeof(uint32_t)},
42 : : [RTE_FLOW_ITEM_TYPE_HIGIG2] = {ROC_NPC_ITEM_TYPE_HIGIG2,
43 : : sizeof(struct rte_flow_item_higig2_hdr)},
44 : : [RTE_FLOW_ITEM_TYPE_RAW] = {ROC_NPC_ITEM_TYPE_RAW, sizeof(struct rte_flow_item_raw)},
45 : : [RTE_FLOW_ITEM_TYPE_MARK] = {ROC_NPC_ITEM_TYPE_MARK, sizeof(struct rte_flow_item_mark)},
46 : : [RTE_FLOW_ITEM_TYPE_IPV6_ROUTING_EXT] = {ROC_NPC_ITEM_TYPE_IPV6_ROUTING_EXT,
47 : : sizeof(struct rte_flow_item_ipv6_routing_ext)},
48 : : [RTE_FLOW_ITEM_TYPE_TX_QUEUE] = {ROC_NPC_ITEM_TYPE_TX_QUEUE,
49 : : sizeof(struct rte_flow_item_tx_queue)},
50 : : [RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT] = {ROC_NPC_ITEM_TYPE_REPRESENTED_PORT,
51 : : sizeof(struct rte_flow_item_ethdev)},
52 : : [RTE_FLOW_ITEM_TYPE_PPPOES] = {ROC_NPC_ITEM_TYPE_PPPOES,
53 : : sizeof(struct rte_flow_item_pppoe)}};
54 : :
55 : : static int
56 : 0 : npc_rss_action_validate(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
57 : : const struct rte_flow_action *act)
58 : : {
59 : : const struct rte_flow_action_rss *rss;
60 : :
61 : 0 : rss = (const struct rte_flow_action_rss *)act->conf;
62 : :
63 [ # # ]: 0 : if (attr->egress) {
64 : 0 : plt_err("No support of RSS in egress");
65 : 0 : return -EINVAL;
66 : : }
67 : :
68 [ # # ]: 0 : if (eth_dev->data->dev_conf.rxmode.mq_mode != RTE_ETH_MQ_RX_RSS) {
69 : 0 : plt_err("multi-queue mode is disabled");
70 : 0 : return -ENOTSUP;
71 : : }
72 : :
73 [ # # # # ]: 0 : if (!rss || !rss->queue_num) {
74 : 0 : plt_err("no valid queues");
75 : 0 : return -EINVAL;
76 : : }
77 : :
78 [ # # ]: 0 : if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT) {
79 : 0 : plt_err("non-default RSS hash functions are not supported");
80 : 0 : return -ENOTSUP;
81 : : }
82 : :
83 [ # # ]: 0 : if (rss->key_len && rss->key_len > ROC_NIX_RSS_KEY_LEN) {
84 : 0 : plt_err("RSS hash key too large");
85 : 0 : return -ENOTSUP;
86 : : }
87 : :
88 : : return 0;
89 : : }
90 : :
91 : : static void
92 : : npc_rss_flowkey_get(struct cnxk_eth_dev *eth_dev, const struct roc_npc_action *rss_action,
93 : : uint32_t *flowkey_cfg, uint64_t default_rss_types)
94 : : {
95 : : const struct roc_npc_action_rss *rss;
96 : : uint64_t rss_types;
97 : :
98 : : rss = (const struct roc_npc_action_rss *)rss_action->conf;
99 : 0 : rss_types = rss->types;
100 : : /* If no RSS types are specified, use default one */
101 : 0 : if (rss_types == 0)
102 : : rss_types = default_rss_types;
103 : :
104 : 0 : *flowkey_cfg = cnxk_rss_ethdev_to_nix(eth_dev, rss_types, rss->level);
105 : 0 : }
106 : :
107 : : static int
108 : 0 : npc_parse_port_id_action(struct rte_eth_dev *eth_dev, const struct rte_flow_action *action,
109 : : uint16_t *dst_pf_func, uint16_t *dst_channel)
110 : : {
111 : : const struct rte_flow_action_port_id *port_act;
112 : : struct rte_eth_dev *portid_eth_dev;
113 : : char if_name[RTE_ETH_NAME_MAX_LEN];
114 : : struct cnxk_eth_dev *hw_dst;
115 : : struct roc_npc *roc_npc_dst;
116 : : int rc = 0;
117 : :
118 : 0 : port_act = (const struct rte_flow_action_port_id *)action->conf;
119 : :
120 : 0 : rc = rte_eth_dev_get_name_by_port(port_act->id, if_name, sizeof(if_name));
121 [ # # ]: 0 : if (rc) {
122 : 0 : plt_err("Name not found for output port id");
123 : 0 : goto err_exit;
124 : : }
125 : 0 : portid_eth_dev = rte_eth_dev_allocated(if_name);
126 [ # # ]: 0 : if (!portid_eth_dev) {
127 : 0 : plt_err("eth_dev not found for output port id");
128 : 0 : goto err_exit;
129 : : }
130 [ # # ]: 0 : if (strcmp(portid_eth_dev->device->driver->name, eth_dev->device->driver->name) != 0) {
131 : 0 : plt_err("Output port not under same driver");
132 : 0 : goto err_exit;
133 : : }
134 : 0 : hw_dst = portid_eth_dev->data->dev_private;
135 : : roc_npc_dst = &hw_dst->npc;
136 : 0 : *dst_pf_func = roc_npc_dst->pf_func;
137 : 0 : *dst_channel = hw_dst->npc.channel;
138 : :
139 : 0 : return 0;
140 : :
141 : : err_exit:
142 : : return -EINVAL;
143 : : }
144 : :
145 : : static int
146 : 0 : roc_npc_parse_sample_subaction(struct rte_eth_dev *eth_dev, const struct rte_flow_action actions[],
147 : : struct roc_npc_action_sample *sample_action)
148 : : {
149 : 0 : uint16_t dst_pf_func = 0, dst_channel = 0;
150 : : const struct roc_npc_action_vf *vf_act;
151 : : int rc = 0, count = 0;
152 : : bool is_empty = true;
153 : :
154 [ # # ]: 0 : if (sample_action->ratio != 1) {
155 : 0 : plt_err("Sample ratio must be 1");
156 : 0 : return -EINVAL;
157 : : }
158 : :
159 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
160 : : is_empty = false;
161 [ # # # # ]: 0 : switch (actions->type) {
162 : 0 : case RTE_FLOW_ACTION_TYPE_PF:
163 : 0 : count++;
164 : 0 : sample_action->action_type |= ROC_NPC_ACTION_TYPE_PF;
165 : 0 : break;
166 : 0 : case RTE_FLOW_ACTION_TYPE_VF:
167 : 0 : count++;
168 : 0 : vf_act = (const struct roc_npc_action_vf *)actions->conf;
169 : 0 : sample_action->action_type |= ROC_NPC_ACTION_TYPE_VF;
170 : 0 : sample_action->pf_func = vf_act->id & NPC_PFVF_FUNC_MASK;
171 : 0 : break;
172 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
173 : 0 : rc = npc_parse_port_id_action(eth_dev, actions, &dst_pf_func, &dst_channel);
174 [ # # ]: 0 : if (rc)
175 : : return -EINVAL;
176 : :
177 : 0 : count++;
178 : 0 : sample_action->action_type |= ROC_NPC_ACTION_TYPE_PORT_ID;
179 : 0 : sample_action->pf_func = dst_pf_func;
180 : 0 : sample_action->channel = dst_channel;
181 : 0 : break;
182 : 0 : default:
183 : 0 : continue;
184 : : }
185 : : }
186 : :
187 [ # # ]: 0 : if (count > 1 || is_empty)
188 : 0 : return -EINVAL;
189 : :
190 : : return 0;
191 : : }
192 : :
193 : : static int
194 : 0 : append_mark_action(struct roc_npc_action *in_actions, uint8_t has_tunnel_pattern,
195 : : uint64_t *free_allocs, int *act_cnt)
196 : : {
197 : : struct rte_flow_action_mark *act_mark;
198 : 0 : int i = *act_cnt, j = 0;
199 : :
200 : : /* Add Mark action */
201 : 0 : i++;
202 : 0 : act_mark = plt_zmalloc(sizeof(struct rte_flow_action_mark), 0);
203 [ # # ]: 0 : if (!act_mark) {
204 : 0 : plt_err("Error allocation memory");
205 : 0 : return -ENOMEM;
206 : : }
207 : :
208 [ # # ]: 0 : while (free_allocs[j] != 0)
209 : 0 : j++;
210 : 0 : free_allocs[j] = (uint64_t)act_mark;
211 : : /* Mark ID format: (tunnel type - VxLAN, Geneve << 6) | Tunnel decap */
212 : 0 : act_mark->id =
213 [ # # ]: 0 : has_tunnel_pattern ? ((has_tunnel_pattern << 6) | TNL_DCP_MATCH_ID) : NRML_MATCH_ID;
214 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_MARK;
215 : 0 : in_actions[i].conf = (struct rte_flow_action_mark *)act_mark;
216 : :
217 : 0 : plt_rep_dbg("Assigned mark ID %x", act_mark->id);
218 : :
219 : 0 : *act_cnt = i;
220 : :
221 : 0 : return 0;
222 : : }
223 : :
224 : : static int
225 : 0 : append_rss_action(struct cnxk_eth_dev *dev, struct roc_npc_action *in_actions, uint16_t nb_rxq,
226 : : uint32_t *flowkey_cfg, uint64_t *free_allocs, uint16_t rss_repte_pf_func,
227 : : int *act_cnt)
228 : : {
229 : : struct roc_npc_action_rss *rss_conf;
230 : 0 : int i = *act_cnt, j = 0, l, rc = 0;
231 : : uint16_t *queue_arr;
232 : :
233 : 0 : rss_conf = plt_zmalloc(sizeof(struct roc_npc_action_rss), 0);
234 [ # # ]: 0 : if (!rss_conf) {
235 : 0 : plt_err("Failed to allocate memory for rss conf");
236 : : rc = -ENOMEM;
237 : 0 : goto fail;
238 : : }
239 : :
240 : : /* Add RSS action */
241 : 0 : rss_conf->queue_num = nb_rxq;
242 : 0 : queue_arr = plt_zmalloc(rss_conf->queue_num * sizeof(uint16_t), 0);
243 [ # # ]: 0 : if (!queue_arr) {
244 : 0 : plt_err("Failed to allocate memory for rss queue");
245 : : rc = -ENOMEM;
246 : 0 : goto free_rss;
247 : : }
248 : :
249 [ # # ]: 0 : for (l = 0; l < nb_rxq; l++)
250 : 0 : queue_arr[l] = l;
251 : 0 : rss_conf->queue = queue_arr;
252 : 0 : rss_conf->key = NULL;
253 : 0 : rss_conf->types = RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP;
254 : :
255 : 0 : i++;
256 : :
257 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_RSS;
258 : 0 : in_actions[i].conf = (struct roc_npc_action_rss *)rss_conf;
259 : 0 : in_actions[i].rss_repte_pf_func = rss_repte_pf_func;
260 : :
261 : : npc_rss_flowkey_get(dev, &in_actions[i], flowkey_cfg,
262 : : RTE_ETH_RSS_IP | RTE_ETH_RSS_UDP | RTE_ETH_RSS_TCP);
263 : :
264 : 0 : *act_cnt = i;
265 : :
266 [ # # ]: 0 : while (free_allocs[j] != 0)
267 : 0 : j++;
268 : 0 : free_allocs[j] = (uint64_t)rss_conf;
269 : 0 : j++;
270 : 0 : free_allocs[j] = (uint64_t)queue_arr;
271 : :
272 : 0 : return 0;
273 : : free_rss:
274 : 0 : plt_free(rss_conf);
275 : : fail:
276 : : return rc;
277 : : }
278 : :
279 : : static int
280 [ # # ]: 0 : representor_rep_portid_action(struct roc_npc_action *in_actions, struct rte_eth_dev *eth_dev,
281 : : struct rte_eth_dev *portid_eth_dev,
282 : : enum rte_flow_action_type act_type, uint8_t rep_pattern,
283 : : uint16_t *dst_pf_func, bool is_rep, uint8_t has_tunnel_pattern,
284 : : uint64_t *free_allocs, int *act_cnt, uint32_t *flowkey_cfg)
285 : : {
286 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
287 : : struct rte_eth_dev *rep_eth_dev = portid_eth_dev;
288 : : struct rte_flow_action_of_set_vlan_vid *vlan_vid;
289 : : struct rte_flow_action_of_set_vlan_pcp *vlan_pcp;
290 : : struct rte_flow_action_of_push_vlan *push_vlan;
291 : : struct rte_flow_action_queue *act_q = NULL;
292 : : struct cnxk_rep_dev *rep_dev;
293 : : struct roc_npc *npc;
294 : : uint16_t vlan_tci;
295 : : int j = 0, rc;
296 : :
297 : : /* For inserting an action in the list */
298 [ # # ]: 0 : int i = *act_cnt;
299 : :
300 : : rep_dev = cnxk_rep_pmd_priv(rep_eth_dev);
301 [ # # ]: 0 : if (!is_rep) {
302 : : dev = cnxk_eth_pmd_priv(eth_dev);
303 : 0 : npc = &dev->npc;
304 : : } else {
305 : 0 : npc = &rep_dev->parent_dev->npc;
306 : : }
307 [ # # ]: 0 : if (rep_pattern >> IS_REP_BIT) { /* Check for normal/representor port as action */
308 [ # # ]: 0 : if ((rep_pattern & 0x7f) == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
309 : : /* Case: Repr port pattern -> Default TX rule -> LBK ->
310 : : * Pattern RX LBK rule hit -> Action: send to new pf_func
311 : : */
312 [ # # ]: 0 : if (act_type == RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR) {
313 : : /* New pf_func corresponds to ESW + queue corresponding to rep_id */
314 : 0 : act_q = plt_zmalloc(sizeof(struct rte_flow_action_queue), 0);
315 [ # # ]: 0 : if (!act_q) {
316 : 0 : plt_err("Error allocation memory");
317 : 0 : return -ENOMEM;
318 : : }
319 : 0 : act_q->index = rep_dev->rep_id;
320 : :
321 [ # # ]: 0 : while (free_allocs[j] != 0)
322 : 0 : j++;
323 : 0 : free_allocs[j] = (uint64_t)act_q;
324 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_QUEUE;
325 : 0 : in_actions[i].conf = (struct rte_flow_action_queue *)act_q;
326 : 0 : npc->rep_act_pf_func = rep_dev->parent_dev->npc.pf_func;
327 : : } else {
328 : : /* New pf_func corresponds to hw_func of representee */
329 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_PORT_ID;
330 : 0 : npc->rep_act_pf_func = rep_dev->hw_func;
331 : 0 : *dst_pf_func = rep_dev->hw_func;
332 : : }
333 : : /* Additional action to strip the VLAN from packets received by LBK */
334 : 0 : i++;
335 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VLAN_STRIP;
336 : 0 : goto done;
337 : : }
338 : : /* Case: Repd port pattern -> TX Rule with VLAN -> LBK -> Default RX LBK rule hit
339 : : * base on vlan, if packet goes to ESW or actual pf_func -> Action :
340 : : * act port_representor: send to ESW respective using 1<<8 | rep_id as tci value
341 : : * act represented_port: send to actual port using rep_id as tci value.
342 : : */
343 : : /* Add RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN action */
344 : 0 : push_vlan = plt_zmalloc(sizeof(struct rte_flow_action_of_push_vlan), 0);
345 [ # # ]: 0 : if (!push_vlan) {
346 : 0 : plt_err("Error allocation memory");
347 : 0 : return -ENOMEM;
348 : : }
349 : :
350 [ # # ]: 0 : while (free_allocs[j] != 0)
351 : 0 : j++;
352 : 0 : free_allocs[j] = (uint64_t)push_vlan;
353 : 0 : push_vlan->ethertype = ntohs(ROC_ESWITCH_VLAN_TPID);
354 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
355 : 0 : in_actions[i].conf = (struct rte_flow_action_of_push_vlan *)push_vlan;
356 : 0 : i++;
357 : :
358 : : /* Add RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP action */
359 : 0 : vlan_pcp = plt_zmalloc(sizeof(struct rte_flow_action_of_set_vlan_pcp), 0);
360 [ # # ]: 0 : if (!vlan_pcp) {
361 : 0 : plt_err("Error allocation memory");
362 : 0 : return -ENOMEM;
363 : : }
364 : :
365 : 0 : free_allocs[j + 1] = (uint64_t)vlan_pcp;
366 : 0 : vlan_pcp->vlan_pcp = 0;
367 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
368 : 0 : in_actions[i].conf = (struct rte_flow_action_of_set_vlan_pcp *)vlan_pcp;
369 : 0 : i++;
370 : :
371 : : /* Add RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID action */
372 : 0 : vlan_vid = plt_zmalloc(sizeof(struct rte_flow_action_of_set_vlan_vid), 0);
373 [ # # ]: 0 : if (!vlan_vid) {
374 : 0 : plt_err("Error allocation memory");
375 : 0 : return -ENOMEM;
376 : : }
377 : :
378 : 0 : free_allocs[j + 2] = (uint64_t)vlan_vid;
379 [ # # ]: 0 : if (act_type == RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR)
380 : 0 : vlan_tci = rep_dev->rep_id | (1ULL << CNXK_ESWITCH_VFPF_SHIFT);
381 : : else
382 : 0 : vlan_tci = rep_dev->rep_id;
383 : 0 : vlan_vid->vlan_vid = ntohs(vlan_tci);
384 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VLAN_INSERT;
385 : 0 : in_actions[i].conf = (struct rte_flow_action_of_set_vlan_vid *)vlan_vid;
386 : :
387 : : /* Change default channel to UCAST_CHAN (63) while sending */
388 : 0 : npc->rep_act_rep = true;
389 : : } else {
390 [ # # ]: 0 : if (act_type == RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR) {
391 : : /* Case: Pattern wire port -> Pattern RX rule->
392 : : * Action: pf_func = ESW. queue = rep_id
393 : : */
394 : 0 : act_q = plt_zmalloc(sizeof(struct rte_flow_action_queue), 0);
395 [ # # ]: 0 : if (!act_q) {
396 : 0 : plt_err("Error allocation memory");
397 : 0 : return -ENOMEM;
398 : : }
399 [ # # ]: 0 : while (free_allocs[j] != 0)
400 : 0 : j++;
401 : 0 : free_allocs[j] = (uint64_t)act_q;
402 : 0 : act_q->index = rep_dev->rep_id;
403 : :
404 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_QUEUE;
405 : 0 : in_actions[i].conf = (struct rte_flow_action_queue *)act_q;
406 : 0 : npc->rep_act_pf_func = rep_dev->parent_dev->npc.pf_func;
407 : : } else {
408 : : /* Case: Pattern wire port -> Pattern RX rule->
409 : : * Action: Receive at actual hw_func
410 : : */
411 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_PORT_ID;
412 : 0 : npc->rep_act_pf_func = rep_dev->hw_func;
413 : 0 : *dst_pf_func = rep_dev->hw_func;
414 : :
415 : : /* Append a mark action - needed to identify the flow */
416 : 0 : rc = append_mark_action(in_actions, has_tunnel_pattern, free_allocs, &i);
417 [ # # ]: 0 : if (rc)
418 : : return rc;
419 : : /* Append RSS action if representee has RSS enabled */
420 [ # # ]: 0 : if (rep_dev->nb_rxq > 1) {
421 : : /* PF can install rule for only its VF acting as representee */
422 [ # # # # ]: 0 : if (rep_dev->hw_func &&
423 : 0 : roc_eswitch_is_repte_pfs_vf(rep_dev->hw_func,
424 : 0 : roc_nix_get_pf_func(npc->roc_nix))) {
425 : 0 : rc = append_rss_action(dev, in_actions, rep_dev->nb_rxq,
426 : : flowkey_cfg, free_allocs,
427 : 0 : rep_dev->hw_func, &i);
428 [ # # ]: 0 : if (rc)
429 : : return rc;
430 : : }
431 : : }
432 : : }
433 : : }
434 : 0 : done:
435 : 0 : *act_cnt = i;
436 : :
437 : 0 : return 0;
438 : : }
439 : :
440 : : static int
441 : 0 : representor_portid_action(struct roc_npc_action *in_actions, struct rte_eth_dev *portid_eth_dev,
442 : : uint16_t *dst_pf_func, uint8_t has_tunnel_pattern, uint64_t *free_allocs,
443 : : int *act_cnt)
444 : : {
445 : : struct rte_eth_dev *rep_eth_dev = portid_eth_dev;
446 : : struct cnxk_rep_dev *rep_dev;
447 : : /* For inserting an action in the list */
448 : 0 : int i = *act_cnt, rc;
449 : :
450 : : rep_dev = cnxk_rep_pmd_priv(rep_eth_dev);
451 : :
452 : 0 : *dst_pf_func = rep_dev->hw_func;
453 : :
454 : 0 : rc = append_mark_action(in_actions, has_tunnel_pattern, free_allocs, &i);
455 [ # # ]: 0 : if (rc)
456 : : return rc;
457 : :
458 : 0 : *act_cnt = i;
459 : 0 : plt_rep_dbg("Rep port %d ID %d rep_dev->hw_func 0x%x", rep_dev->port_id, rep_dev->rep_id,
460 : : rep_dev->hw_func);
461 : :
462 : 0 : return 0;
463 : : }
464 : :
465 : : static int
466 : 0 : cnxk_map_actions(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
467 : : const struct rte_flow_action actions[], struct roc_npc_action in_actions[],
468 : : struct roc_npc_action_sample *in_sample_actions, uint32_t *flowkey_cfg,
469 : : uint16_t *dst_pf_func, uint64_t *npc_default_action, uint8_t has_tunnel_pattern,
470 : : bool is_rep, uint8_t rep_pattern, uint64_t *free_allocs, uint32_t flow_flags)
471 : : {
472 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
473 : : const struct rte_flow_action_queue *act_q = NULL;
474 : : const struct rte_flow_action_ethdev *act_ethdev;
475 : : const struct rte_flow_action_sample *act_sample;
476 : : const struct rte_flow_action_port_id *port_act;
477 : : struct rte_eth_dev *portid_eth_dev;
478 : : char if_name[RTE_ETH_NAME_MAX_LEN];
479 : : struct cnxk_eth_dev *hw_dst;
480 : : struct roc_npc *roc_npc_dst;
481 : : bool is_vf_action = false;
482 : 0 : int i = 0, rc = 0;
483 : : int rq;
484 : :
485 [ # # ]: 0 : for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
486 [ # # # # : 0 : switch (actions->type) {
# # # # #
# # # # #
# # # # #
# # ]
487 : 0 : case RTE_FLOW_ACTION_TYPE_VOID:
488 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VOID;
489 : 0 : break;
490 : :
491 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
492 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_MARK;
493 : 0 : in_actions[i].conf = actions->conf;
494 : 0 : break;
495 : :
496 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
497 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_FLAG;
498 : 0 : break;
499 : :
500 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
501 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_COUNT;
502 : 0 : break;
503 : :
504 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
505 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_DROP;
506 : 0 : break;
507 : :
508 : 0 : case RTE_FLOW_ACTION_TYPE_PF:
509 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_PF;
510 : 0 : break;
511 : :
512 : 0 : case RTE_FLOW_ACTION_TYPE_VF:
513 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VF;
514 : 0 : in_actions[i].conf = actions->conf;
515 : : is_vf_action = true;
516 : 0 : break;
517 : :
518 : 0 : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
519 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
520 : 0 : in_actions[i].conf = actions->conf;
521 : : act_ethdev = (const struct rte_flow_action_ethdev *)actions->conf;
522 [ # # ]: 0 : if (rte_eth_dev_get_name_by_port(act_ethdev->port_id, if_name,
523 : : sizeof(if_name))) {
524 : 0 : plt_err("Name not found for output port id");
525 : 0 : goto err_exit;
526 : : }
527 : 0 : portid_eth_dev = rte_eth_dev_allocated(if_name);
528 [ # # ]: 0 : if (!portid_eth_dev) {
529 : 0 : plt_err("eth_dev not found for output port id");
530 : 0 : goto err_exit;
531 : : }
532 : :
533 : 0 : plt_rep_dbg("Rule installed by port %d if_name %s act_ethdev->port_id %d",
534 : : eth_dev->data->port_id, if_name, act_ethdev->port_id);
535 [ # # ]: 0 : if (cnxk_ethdev_is_representor(if_name)) {
536 [ # # ]: 0 : if (representor_rep_portid_action(in_actions, eth_dev,
537 : 0 : portid_eth_dev, actions->type,
538 : : rep_pattern, dst_pf_func,
539 : : is_rep, has_tunnel_pattern,
540 : : free_allocs, &i, flowkey_cfg)) {
541 : 0 : plt_err("Representor port action set failed");
542 : 0 : goto err_exit;
543 : : }
544 : : } else {
545 [ # # ]: 0 : if (actions->type == RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT)
546 : 0 : continue;
547 : : /* Normal port as represented_port as action not supported*/
548 : : return -ENOTSUP;
549 : : }
550 : : break;
551 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
552 : : /* No port ID action on representor ethdevs */
553 [ # # ]: 0 : if (is_rep)
554 : 0 : continue;
555 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_PORT_ID;
556 : 0 : in_actions[i].conf = actions->conf;
557 : : act_ethdev = (const struct rte_flow_action_ethdev *)actions->conf;
558 : : port_act = (const struct rte_flow_action_port_id *)actions->conf;
559 [ # # ]: 0 : if (rte_eth_dev_get_name_by_port(
560 : : actions->type != RTE_FLOW_ACTION_TYPE_PORT_ID ?
561 : : act_ethdev->port_id :
562 : 0 : port_act->id,
563 : : if_name, sizeof(if_name))) {
564 : 0 : plt_err("Name not found for output port id");
565 : 0 : goto err_exit;
566 : : }
567 : 0 : portid_eth_dev = rte_eth_dev_allocated(if_name);
568 [ # # ]: 0 : if (!portid_eth_dev) {
569 : 0 : plt_err("eth_dev not found for output port id");
570 : 0 : goto err_exit;
571 : : }
572 : :
573 [ # # ]: 0 : if (cnxk_ethdev_is_representor(if_name)) {
574 : 0 : plt_rep_dbg("Representor port %d act port %d", port_act->id,
575 : : act_ethdev->port_id);
576 [ # # ]: 0 : if (representor_portid_action(in_actions, portid_eth_dev,
577 : : dst_pf_func, has_tunnel_pattern,
578 : : free_allocs, &i)) {
579 : 0 : plt_err("Representor port action set failed");
580 : 0 : goto err_exit;
581 : : }
582 : : } else {
583 : 0 : if (strcmp(portid_eth_dev->device->driver->name,
584 [ # # ]: 0 : eth_dev->device->driver->name) != 0) {
585 : 0 : plt_err("Output port not under same driver");
586 : 0 : goto err_exit;
587 : : }
588 : :
589 : 0 : hw_dst = portid_eth_dev->data->dev_private;
590 : 0 : roc_npc_mcam_default_rule_action_get(&hw_dst->npc,
591 : : npc_default_action);
592 : : roc_npc_dst = &hw_dst->npc;
593 : 0 : *dst_pf_func = roc_npc_dst->pf_func;
594 : : }
595 : : break;
596 : :
597 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
598 : 0 : act_q = (const struct rte_flow_action_queue *)actions->conf;
599 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_QUEUE;
600 : 0 : in_actions[i].conf = actions->conf;
601 : 0 : break;
602 : :
603 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
604 : : /* No RSS action on representor ethdevs */
605 [ # # ]: 0 : if (is_rep)
606 : 0 : continue;
607 : 0 : rc = npc_rss_action_validate(eth_dev, attr, actions);
608 [ # # ]: 0 : if (rc)
609 : 0 : goto err_exit;
610 : :
611 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_RSS;
612 : 0 : in_actions[i].conf = actions->conf;
613 : 0 : npc_rss_flowkey_get(dev, &in_actions[i], flowkey_cfg,
614 [ # # ]: 0 : eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf);
615 : : break;
616 : :
617 : 0 : case RTE_FLOW_ACTION_TYPE_SECURITY:
618 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_SEC;
619 : 0 : in_actions[i].conf = actions->conf;
620 : 0 : in_actions[i].is_non_inp = flow_flags & CNXK_FLOW_NON_INPLACE;
621 : 0 : in_actions[i].no_sec_action = flow_flags & CNXK_FLOW_NO_SEC_ACTION;
622 : 0 : break;
623 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
624 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VLAN_STRIP;
625 : 0 : break;
626 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
627 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_VLAN_INSERT;
628 : 0 : in_actions[i].conf = actions->conf;
629 : 0 : break;
630 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
631 : 0 : in_actions[i].type =
632 : : ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
633 : 0 : in_actions[i].conf = actions->conf;
634 : 0 : break;
635 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
636 : 0 : in_actions[i].type =
637 : : ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
638 : 0 : in_actions[i].conf = actions->conf;
639 : 0 : break;
640 : 0 : case RTE_FLOW_ACTION_TYPE_METER:
641 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_METER;
642 : 0 : in_actions[i].conf = actions->conf;
643 : 0 : break;
644 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
645 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_AGE;
646 : 0 : in_actions[i].conf = actions->conf;
647 : 0 : break;
648 : 0 : case RTE_FLOW_ACTION_TYPE_SAMPLE:
649 : 0 : act_sample = actions->conf;
650 : 0 : in_sample_actions->ratio = act_sample->ratio;
651 : 0 : rc = roc_npc_parse_sample_subaction(eth_dev, act_sample->actions,
652 : : in_sample_actions);
653 [ # # ]: 0 : if (rc) {
654 : 0 : plt_err("Sample subaction parsing failed.");
655 : 0 : goto err_exit;
656 : : }
657 : :
658 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_SAMPLE;
659 : 0 : in_actions[i].conf = in_sample_actions;
660 : 0 : break;
661 : 0 : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
662 : 0 : continue;
663 : 0 : default:
664 : 0 : plt_npc_dbg("Action is not supported = %d", actions->type);
665 : 0 : goto err_exit;
666 : : }
667 : 0 : i++;
668 : : }
669 : :
670 [ # # ]: 0 : if (!is_vf_action && act_q) {
671 : 0 : rq = act_q->index;
672 [ # # ]: 0 : if (rq >= eth_dev->data->nb_rx_queues) {
673 : 0 : plt_npc_dbg("Invalid queue index");
674 : 0 : goto err_exit;
675 : : }
676 : : }
677 : 0 : in_actions[i].type = ROC_NPC_ACTION_TYPE_END;
678 : 0 : return 0;
679 : :
680 : : err_exit:
681 : : return -EINVAL;
682 : : }
683 : :
684 : : static int
685 : 0 : cnxk_map_pattern(struct rte_eth_dev *eth_dev, const struct rte_flow_item pattern[],
686 : : struct roc_npc_item_info in_pattern[], uint8_t *has_tunnel_pattern, bool is_rep,
687 : : uint8_t *rep_pattern, uint64_t *free_allocs)
688 : : {
689 : : const struct rte_flow_item_ethdev *rep_eth_dev;
690 : : struct rte_eth_dev *portid_eth_dev;
691 : : char if_name[RTE_ETH_NAME_MAX_LEN];
692 : : struct cnxk_eth_dev *hw_dst;
693 : : struct cnxk_rep_dev *rdev;
694 : : struct cnxk_eth_dev *dev;
695 : : struct roc_npc *npc;
696 : : int i = 0, j = 0;
697 : :
698 [ # # ]: 0 : if (!is_rep) {
699 : : dev = cnxk_eth_pmd_priv(eth_dev);
700 : 0 : npc = &dev->npc;
701 : : } else {
702 : : rdev = cnxk_rep_pmd_priv(eth_dev);
703 : 0 : npc = &rdev->parent_dev->npc;
704 : :
705 : 0 : npc->rep_npc = npc;
706 : 0 : npc->rep_port_id = rdev->port_id;
707 : 0 : npc->rep_pf_func = rdev->hw_func;
708 : : }
709 : :
710 [ # # ]: 0 : while (pattern->type != RTE_FLOW_ITEM_TYPE_END) {
711 : 0 : in_pattern[i].spec = pattern->spec;
712 : 0 : in_pattern[i].last = pattern->last;
713 : 0 : in_pattern[i].mask = pattern->mask;
714 : 0 : in_pattern[i].type = term[pattern->type].item_type;
715 : 0 : in_pattern[i].size = term[pattern->type].item_size;
716 [ # # ]: 0 : if (pattern->type == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT ||
717 : : pattern->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
718 : : rep_eth_dev = (const struct rte_flow_item_ethdev *)pattern->spec;
719 [ # # ]: 0 : if (rte_eth_dev_get_name_by_port(rep_eth_dev->port_id, if_name,
720 : : sizeof(if_name))) {
721 : 0 : plt_err("Name not found for output port id");
722 : 0 : goto fail;
723 : : }
724 : 0 : portid_eth_dev = rte_eth_dev_allocated(if_name);
725 [ # # ]: 0 : if (!portid_eth_dev) {
726 : 0 : plt_err("eth_dev not found for output port id");
727 : 0 : goto fail;
728 : : }
729 : 0 : *rep_pattern = pattern->type;
730 [ # # ]: 0 : if (cnxk_ethdev_is_representor(if_name)) {
731 : : /* Case where represented port not part of same
732 : : * app and represented by a representor port.
733 : : */
734 : : struct cnxk_rep_dev *rep_dev;
735 : : struct cnxk_eswitch_dev *eswitch_dev;
736 : :
737 : : rep_dev = cnxk_rep_pmd_priv(portid_eth_dev);
738 : 0 : eswitch_dev = rep_dev->parent_dev;
739 : 0 : npc->rep_npc = &eswitch_dev->npc;
740 : 0 : npc->rep_port_id = rep_eth_dev->port_id;
741 : 0 : npc->rep_pf_func = rep_dev->hw_func;
742 : :
743 [ # # ]: 0 : if (pattern->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR) {
744 : : struct rte_flow_item_vlan *vlan;
745 : :
746 : 0 : npc->rep_pf_func = eswitch_dev->npc.pf_func;
747 : : /* Add VLAN pattern corresponding to rep_id */
748 : 0 : i++;
749 : 0 : vlan = plt_zmalloc(sizeof(struct rte_flow_item_vlan), 0);
750 [ # # ]: 0 : if (!vlan) {
751 : 0 : plt_err("error allocation memory");
752 : 0 : return -ENOMEM;
753 : : }
754 : :
755 [ # # ]: 0 : while (free_allocs[j] != 0)
756 : 0 : j++;
757 : 0 : free_allocs[j] = (uint64_t)vlan;
758 : :
759 : 0 : npc->rep_rx_channel = ROC_ESWITCH_LBK_CHAN;
760 : 0 : vlan->hdr.vlan_tci = RTE_BE16(rep_dev->rep_id);
761 : 0 : in_pattern[i].spec = (struct rte_flow_item_vlan *)vlan;
762 : 0 : in_pattern[i].last = NULL;
763 : 0 : in_pattern[i].mask = &rte_flow_item_vlan_mask;
764 : 0 : in_pattern[i].type =
765 : : term[RTE_FLOW_ITEM_TYPE_VLAN].item_type;
766 : 0 : in_pattern[i].size =
767 : : term[RTE_FLOW_ITEM_TYPE_VLAN].item_size;
768 : : }
769 : 0 : *rep_pattern |= 1 << IS_REP_BIT;
770 : 0 : plt_rep_dbg("Represented port %d act port %d rep_dev->hw_func 0x%x",
771 : : rep_eth_dev->port_id, eth_dev->data->port_id,
772 : : rep_dev->hw_func);
773 : : } else {
774 : 0 : if (strcmp(portid_eth_dev->device->driver->name,
775 [ # # ]: 0 : eth_dev->device->driver->name) != 0) {
776 : 0 : plt_err("Output port not under same driver");
777 : 0 : goto fail;
778 : : }
779 : : /* Normal port as port_representor pattern can't be supported */
780 [ # # ]: 0 : if (pattern->type == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR)
781 : : return -ENOTSUP;
782 : : /* Case where represented port part of same app
783 : : * as PF.
784 : : */
785 : 0 : hw_dst = portid_eth_dev->data->dev_private;
786 : 0 : npc->rep_npc = &hw_dst->npc;
787 : 0 : npc->rep_port_id = rep_eth_dev->port_id;
788 : 0 : npc->rep_pf_func = hw_dst->npc.pf_func;
789 : : }
790 : : }
791 : :
792 [ # # ]: 0 : if (pattern->type == RTE_FLOW_ITEM_TYPE_VXLAN ||
793 [ # # ]: 0 : pattern->type == RTE_FLOW_ITEM_TYPE_VXLAN_GPE ||
794 : : pattern->type == RTE_FLOW_ITEM_TYPE_GRE)
795 : 0 : *has_tunnel_pattern = pattern->type;
796 : :
797 : 0 : pattern++;
798 : 0 : i++;
799 : : }
800 : 0 : in_pattern[i].type = ROC_NPC_ITEM_TYPE_END;
801 : 0 : return 0;
802 : : fail:
803 : : return -EINVAL;
804 : : }
805 : :
806 : : static int
807 : 0 : cnxk_map_flow_data(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
808 : : const struct rte_flow_item pattern[], const struct rte_flow_action actions[],
809 : : struct roc_npc_attr *in_attr, struct roc_npc_item_info in_pattern[],
810 : : struct roc_npc_action in_actions[],
811 : : struct roc_npc_action_sample *in_sample_actions, uint32_t *flowkey_cfg,
812 : : uint16_t *dst_pf_func, uint64_t *def_action, bool is_rep, uint64_t *free_allocs,
813 : : uint32_t flow_flags)
814 : : {
815 : 0 : uint8_t has_tunnel_pattern = 0, rep_pattern = 0;
816 : : int rc;
817 : :
818 : 0 : in_attr->priority = attr->priority;
819 : 0 : in_attr->ingress = attr->ingress;
820 : 0 : in_attr->egress = attr->egress;
821 : :
822 : 0 : rc = cnxk_map_pattern(eth_dev, pattern, in_pattern, &has_tunnel_pattern, is_rep,
823 : : &rep_pattern, free_allocs);
824 [ # # ]: 0 : if (rc) {
825 : 0 : plt_err("Failed to map pattern list");
826 : 0 : return rc;
827 : : }
828 : :
829 [ # # ]: 0 : if (attr->transfer) {
830 : : /* rep_pattern is used to identify if RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT
831 : : * OR RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR is defined + if pattern's portid is
832 : : * normal port or representor port.
833 : : * For normal port_id, rep_pattern = pattern-> type
834 : : * For representor port, rep_pattern = pattern-> type | 1 << IS_REP_BIT
835 : : */
836 [ # # # # ]: 0 : if (is_rep || rep_pattern) {
837 [ # # # # ]: 0 : if (rep_pattern == RTE_FLOW_ITEM_TYPE_REPRESENTED_PORT ||
838 : : ((rep_pattern & 0x7f) == RTE_FLOW_ITEM_TYPE_PORT_REPRESENTOR))
839 : : /* If pattern is port_representor or pattern has normal port as
840 : : * represented port, install ingress rule.
841 : : */
842 : 0 : in_attr->ingress = attr->transfer;
843 : : else
844 : 0 : in_attr->egress = attr->transfer;
845 : : } else {
846 : 0 : in_attr->ingress = attr->transfer;
847 : : }
848 : : }
849 : :
850 : 0 : return cnxk_map_actions(eth_dev, attr, actions, in_actions, in_sample_actions, flowkey_cfg,
851 : : dst_pf_func, def_action, has_tunnel_pattern, is_rep, rep_pattern,
852 : : free_allocs, flow_flags);
853 : : }
854 : :
855 : : int
856 : 0 : cnxk_flow_validate_common(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
857 : : const struct rte_flow_item pattern[],
858 : : const struct rte_flow_action actions[], struct rte_flow_error *error,
859 : : bool is_rep, uint32_t flow_flags)
860 : : {
861 : : struct roc_npc_item_info in_pattern[ROC_NPC_ITEM_TYPE_END + 1];
862 : : struct roc_npc_action in_actions[ROC_NPC_MAX_ACTION_COUNT];
863 : : struct roc_npc_action_sample in_sample_action;
864 : 0 : uint64_t npc_default_action = 0;
865 : : struct cnxk_rep_dev *rep_dev;
866 : : struct roc_npc_attr in_attr;
867 : : uint64_t *free_allocs, sz;
868 : : struct cnxk_eth_dev *dev;
869 : : struct roc_npc_flow flow;
870 : 0 : uint16_t dst_pf_func = 0;
871 : 0 : uint32_t flowkey_cfg = 0;
872 : : struct roc_npc *npc = 0;
873 : : int rc, j;
874 : :
875 : : /* is_rep set for operation performed via representor ports */
876 [ # # ]: 0 : if (!is_rep) {
877 : : dev = cnxk_eth_pmd_priv(eth_dev);
878 : 0 : npc = &dev->npc;
879 : : /* Skip flow validation for MACsec. */
880 [ # # # # ]: 0 : if (actions[0].type == RTE_FLOW_ACTION_TYPE_SECURITY &&
881 : 0 : cnxk_eth_macsec_sess_get_by_sess(dev, actions[0].conf) != NULL)
882 : : return 0;
883 : : } else {
884 : : rep_dev = cnxk_rep_pmd_priv(eth_dev);
885 : 0 : npc = &rep_dev->parent_dev->npc;
886 : : }
887 : :
888 : : memset(&flow, 0, sizeof(flow));
889 : : memset(&in_sample_action, 0, sizeof(in_sample_action));
890 : 0 : flow.is_validate = true;
891 : :
892 : : sz = ROC_NPC_MAX_ACTION_COUNT + ROC_NPC_ITEM_TYPE_END + 1;
893 : 0 : free_allocs = plt_zmalloc(sz * sizeof(uint64_t), 0);
894 [ # # ]: 0 : if (!free_allocs) {
895 : 0 : rte_flow_error_set(error, -ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
896 : : "Failed to map flow data");
897 : 0 : return -ENOMEM;
898 : : }
899 : 0 : rc = cnxk_map_flow_data(eth_dev, attr, pattern, actions, &in_attr, in_pattern, in_actions,
900 : : &in_sample_action, &flowkey_cfg, &dst_pf_func, &npc_default_action,
901 : : is_rep, free_allocs, flow_flags);
902 [ # # ]: 0 : if (rc) {
903 : 0 : rte_flow_error_set(error, 0, RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
904 : : "Failed to map flow data");
905 : 0 : goto clean;
906 : : }
907 : :
908 : 0 : rc = roc_npc_flow_parse(npc, &in_attr, in_pattern, in_actions, &flow);
909 : :
910 [ # # ]: 0 : if (rc) {
911 : 0 : rte_flow_error_set(error, 0, rc, NULL,
912 : : "Flow validation failed");
913 : 0 : goto clean;
914 : : }
915 : 0 : clean:
916 : : /* Freeing the allocations done for additional patterns/actions */
917 [ # # # # ]: 0 : for (j = 0; (j < (int)sz) && free_allocs[j]; j++)
918 : 0 : plt_free((void *)free_allocs[j]);
919 : 0 : plt_free(free_allocs);
920 : :
921 : 0 : return rc;
922 : : }
923 : :
924 : : static int
925 [ # # ]: 0 : cnxk_flow_validate(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
926 : : const struct rte_flow_item pattern[], const struct rte_flow_action actions[],
927 : : struct rte_flow_error *error)
928 : : {
929 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
930 : : struct cnxk_eth_sec_sess *eth_sec = NULL;
931 : : uint32_t flow_flags = 0;
932 : :
933 [ # # ]: 0 : if (actions[0].type == RTE_FLOW_ACTION_TYPE_SECURITY) {
934 : 0 : eth_sec = cnxk_eth_sec_sess_get_by_sess(dev, actions[0].conf);
935 [ # # ]: 0 : if (eth_sec != NULL) {
936 [ # # ]: 0 : flow_flags = eth_sec->inb_oop ? CNXK_FLOW_NON_INPLACE : 0;
937 : 0 : flow_flags |= CNXK_FLOW_NO_SEC_ACTION;
938 : : }
939 : : }
940 : :
941 : 0 : return cnxk_flow_validate_common(eth_dev, attr, pattern, actions, error, false, flow_flags);
942 : : }
943 : :
944 : : struct roc_npc_flow *
945 : 0 : cnxk_flow_create_common(struct rte_eth_dev *eth_dev, const struct rte_flow_attr *attr,
946 : : const struct rte_flow_item pattern[],
947 : : const struct rte_flow_action actions[], struct rte_flow_error *error,
948 : : bool is_rep, uint32_t flow_flags)
949 : : {
950 : 0 : struct roc_npc_item_info in_pattern[ROC_NPC_ITEM_TYPE_END + 1] = {0};
951 : 0 : struct roc_npc_action in_actions[ROC_NPC_MAX_ACTION_COUNT] = {0};
952 : : struct roc_npc_action_sample in_sample_action;
953 : : struct cnxk_rep_dev *rep_dev = NULL;
954 : : struct roc_npc_flow *flow = NULL;
955 : : struct cnxk_eth_dev *dev = NULL;
956 : 0 : uint64_t npc_default_action = 0;
957 : : struct roc_npc_attr in_attr;
958 : : struct roc_npc *npc = NULL;
959 : : uint64_t *free_allocs, sz;
960 : 0 : uint16_t dst_pf_func = 0;
961 : 0 : int errcode = 0;
962 : : int rc, j;
963 : :
964 : : /* is_rep set for operation performed via representor ports */
965 [ # # ]: 0 : if (!is_rep) {
966 : : dev = cnxk_eth_pmd_priv(eth_dev);
967 : 0 : npc = &dev->npc;
968 : : } else {
969 : : rep_dev = cnxk_rep_pmd_priv(eth_dev);
970 : 0 : npc = &rep_dev->parent_dev->npc;
971 : : }
972 : :
973 : : sz = ROC_NPC_MAX_ACTION_COUNT + ROC_NPC_ITEM_TYPE_END + 1;
974 : 0 : free_allocs = plt_zmalloc(sz * sizeof(uint64_t), 0);
975 [ # # ]: 0 : if (!free_allocs) {
976 : 0 : rte_flow_error_set(error, -ENOMEM, RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
977 : : "Failed to map flow data");
978 : 0 : return NULL;
979 : : }
980 : : memset(&in_sample_action, 0, sizeof(in_sample_action));
981 : : memset(&in_attr, 0, sizeof(struct roc_npc_attr));
982 : 0 : rc = cnxk_map_flow_data(eth_dev, attr, pattern, actions, &in_attr, in_pattern, in_actions,
983 : : &in_sample_action, &npc->flowkey_cfg_state, &dst_pf_func,
984 : : &npc_default_action, is_rep, free_allocs, flow_flags);
985 [ # # ]: 0 : if (rc) {
986 : 0 : rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
987 : : "Failed to map flow data");
988 : 0 : goto clean;
989 : : }
990 : :
991 : 0 : flow = roc_npc_flow_create(npc, &in_attr, in_pattern, in_actions, dst_pf_func,
992 : : npc_default_action, &errcode);
993 [ # # ]: 0 : if (errcode != 0) {
994 : 0 : rte_flow_error_set(error, errcode, errcode, NULL, roc_error_msg_get(errcode));
995 : 0 : goto clean;
996 : : }
997 : :
998 : 0 : clean:
999 : : /* Freeing the allocations done for additional patterns/actions */
1000 [ # # # # ]: 0 : for (j = 0; (j < (int)sz) && free_allocs[j]; j++)
1001 : 0 : plt_free((void *)free_allocs[j]);
1002 : 0 : plt_free(free_allocs);
1003 : :
1004 : 0 : return flow;
1005 : : }
1006 : :
1007 : : int
1008 : 0 : cnxk_flow_destroy_common(struct rte_eth_dev *eth_dev, struct roc_npc_flow *flow,
1009 : : struct rte_flow_error *error, bool is_rep)
1010 : : {
1011 : : struct cnxk_rep_dev *rep_dev;
1012 : : struct cnxk_eth_dev *dev;
1013 : : struct roc_npc *npc;
1014 : : int rc;
1015 : :
1016 : : /* is_rep set for operation performed via representor ports */
1017 [ # # ]: 0 : if (!is_rep) {
1018 : : dev = cnxk_eth_pmd_priv(eth_dev);
1019 : 0 : npc = &dev->npc;
1020 : : } else {
1021 : : rep_dev = cnxk_rep_pmd_priv(eth_dev);
1022 : 0 : npc = &rep_dev->parent_dev->npc;
1023 : : }
1024 : :
1025 : 0 : rc = roc_npc_flow_destroy(npc, flow);
1026 [ # # ]: 0 : if (rc)
1027 : 0 : rte_flow_error_set(error, rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1028 : : "Flow Destroy failed");
1029 : 0 : return rc;
1030 : : }
1031 : :
1032 : : int
1033 : 0 : cnxk_flow_destroy(struct rte_eth_dev *eth_dev, struct roc_npc_flow *flow,
1034 : : struct rte_flow_error *error)
1035 : : {
1036 : 0 : return cnxk_flow_destroy_common(eth_dev, flow, error, false);
1037 : : }
1038 : :
1039 : : int
1040 : 0 : cnxk_flow_flush_common(struct rte_eth_dev *eth_dev, struct rte_flow_error *error, bool is_rep)
1041 : : {
1042 : : struct cnxk_rep_dev *rep_dev;
1043 : : struct cnxk_eth_dev *dev;
1044 : : struct roc_npc *npc;
1045 : : int rc;
1046 : :
1047 : : /* is_rep set for operation performed via representor ports */
1048 [ # # ]: 0 : if (!is_rep) {
1049 : : dev = cnxk_eth_pmd_priv(eth_dev);
1050 : 0 : npc = &dev->npc;
1051 : : } else {
1052 : : rep_dev = cnxk_rep_pmd_priv(eth_dev);
1053 : 0 : npc = &rep_dev->parent_dev->npc;
1054 : : }
1055 : :
1056 : 0 : rc = roc_npc_mcam_free_all_resources(npc);
1057 [ # # ]: 0 : if (rc) {
1058 : 0 : rte_flow_error_set(error, EIO, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1059 : : "Failed to flush filter");
1060 : 0 : return -rte_errno;
1061 : : }
1062 : :
1063 : : return 0;
1064 : : }
1065 : :
1066 : : static int
1067 : 0 : cnxk_flow_flush(struct rte_eth_dev *eth_dev, struct rte_flow_error *error)
1068 : : {
1069 : 0 : return cnxk_flow_flush_common(eth_dev, error, false);
1070 : : }
1071 : :
1072 : : int
1073 : 0 : cnxk_flow_query_common(struct rte_eth_dev *eth_dev, struct rte_flow *flow,
1074 : : const struct rte_flow_action *action, void *data,
1075 : : struct rte_flow_error *error, bool is_rep)
1076 : : {
1077 : : struct rte_flow_query_count *query = data;
1078 : : struct roc_npc_flow *in_flow;
1079 : : struct cnxk_rep_dev *rep_dev;
1080 : : const char *errmsg = NULL;
1081 : : struct cnxk_eth_dev *dev;
1082 : : int errcode = ENOTSUP;
1083 : : struct roc_npc *npc;
1084 : : int rc;
1085 : :
1086 [ # # ]: 0 : if (flow == NULL) {
1087 : : errmsg = "Invalid flow handle";
1088 : : errcode = EINVAL;
1089 : 0 : goto err_exit;
1090 : : }
1091 : :
1092 : : /* is_rep set for operation performed via representor ports */
1093 [ # # ]: 0 : if (!is_rep) {
1094 : : dev = cnxk_eth_pmd_priv(eth_dev);
1095 : 0 : npc = &dev->npc;
1096 : : } else {
1097 : : rep_dev = cnxk_rep_pmd_priv(eth_dev);
1098 : 0 : npc = &rep_dev->parent_dev->npc;
1099 : : }
1100 : :
1101 : : /* Let the roc layer resolve async/template handles to the underlying
1102 : : * roc_npc_flow (NULL until committed); else treat as a sync flow.
1103 : : */
1104 : 0 : in_flow = (struct roc_npc_flow *)flow;
1105 [ # # ]: 0 : if (!is_rep)
1106 : 0 : roc_npc_async_flow_resolve(npc, flow, &in_flow);
1107 : :
1108 [ # # ]: 0 : if (in_flow == NULL) {
1109 : : errmsg = "Flow is not committed yet";
1110 : : errcode = EINVAL;
1111 : 0 : goto err_exit;
1112 : : }
1113 : :
1114 [ # # ]: 0 : if (action->type != RTE_FLOW_ACTION_TYPE_COUNT) {
1115 : : errmsg = "Only COUNT is supported in query";
1116 : 0 : goto err_exit;
1117 : : }
1118 : :
1119 [ # # ]: 0 : if (in_flow->ctr_id == NPC_COUNTER_NONE) {
1120 : : errmsg = "Counter is not available";
1121 : 0 : goto err_exit;
1122 : : }
1123 : :
1124 [ # # ]: 0 : if (in_flow->use_pre_alloc) {
1125 : 0 : rc = roc_npc_inl_mcam_read_counter(in_flow->ctr_id, &query->hits);
1126 : : } else {
1127 [ # # ]: 0 : if (roc_model_is_cn20k())
1128 : 0 : rc = roc_npc_mcam_get_stats(npc, in_flow, &query->hits);
1129 : : else
1130 : 0 : rc = roc_npc_mcam_read_counter(npc, in_flow->ctr_id, &query->hits);
1131 : : }
1132 [ # # ]: 0 : if (rc != 0) {
1133 : : errcode = EIO;
1134 : : errmsg = "Error reading flow counter";
1135 : 0 : goto err_exit;
1136 : : }
1137 : 0 : query->hits_set = 1;
1138 : 0 : query->bytes_set = 0;
1139 : :
1140 [ # # ]: 0 : if (query->reset) {
1141 [ # # ]: 0 : if (in_flow->use_pre_alloc)
1142 : 0 : rc = roc_npc_inl_mcam_clear_counter(in_flow->ctr_id);
1143 : : else
1144 : 0 : rc = roc_npc_mcam_clear_counter(npc, in_flow->ctr_id);
1145 : : }
1146 [ # # ]: 0 : if (rc != 0) {
1147 : : errcode = EIO;
1148 : : errmsg = "Error clearing flow counter";
1149 : 0 : goto err_exit;
1150 : : }
1151 : :
1152 : : return 0;
1153 : :
1154 : 0 : err_exit:
1155 : 0 : rte_flow_error_set(error, errcode, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1156 : : NULL, errmsg);
1157 : 0 : return -rte_errno;
1158 : : }
1159 : :
1160 : : static int
1161 : 0 : cnxk_flow_query(struct rte_eth_dev *eth_dev, struct rte_flow *flow,
1162 : : const struct rte_flow_action *action, void *data, struct rte_flow_error *error)
1163 : : {
1164 : 0 : return cnxk_flow_query_common(eth_dev, flow, action, data, error, false);
1165 : : }
1166 : :
1167 : : static int
1168 : 0 : cnxk_flow_isolate(struct rte_eth_dev *eth_dev __rte_unused, int enable __rte_unused,
1169 : : struct rte_flow_error *error)
1170 : : {
1171 : : /* If we support, we need to un-install the default mcam
1172 : : * entry for this port.
1173 : : */
1174 : :
1175 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1176 : : "Flow isolation not supported");
1177 : :
1178 : 0 : return -rte_errno;
1179 : : }
1180 : :
1181 : : int
1182 : 0 : cnxk_flow_dev_dump_common(struct rte_eth_dev *eth_dev, struct rte_flow *flow, FILE *file,
1183 : : struct rte_flow_error *error, bool is_rep)
1184 : : {
1185 : 0 : struct roc_npc_flow *in_flow = NULL;
1186 : : struct cnxk_eth_dev *dev = NULL;
1187 : : struct cnxk_rep_dev *rep_dev;
1188 : : struct roc_npc *npc;
1189 : :
1190 : : /* is_rep set for operation performed via representor ports */
1191 [ # # ]: 0 : if (!is_rep) {
1192 : : dev = cnxk_eth_pmd_priv(eth_dev);
1193 : 0 : npc = &dev->npc;
1194 : : } else {
1195 : : rep_dev = cnxk_rep_pmd_priv(eth_dev);
1196 : 0 : npc = &rep_dev->parent_dev->npc;
1197 : : }
1198 : :
1199 [ # # ]: 0 : if (file == NULL) {
1200 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1201 : : "Invalid file");
1202 : 0 : return -rte_errno;
1203 : : }
1204 : :
1205 [ # # ]: 0 : if (flow != NULL) {
1206 : : /* Resolve async/template handles to the underlying roc_npc_flow;
1207 : : * else treat as a sync flow.
1208 : : */
1209 [ # # # # ]: 0 : if (is_rep || !roc_npc_async_flow_resolve(npc, flow, &in_flow))
1210 : 0 : in_flow = (struct roc_npc_flow *)flow;
1211 : :
1212 [ # # ]: 0 : if (in_flow == NULL)
1213 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1214 : : "flow is not committed yet");
1215 : :
1216 : 0 : roc_npc_flow_mcam_dump(file, npc, in_flow);
1217 : 0 : return 0;
1218 : : }
1219 : :
1220 : 0 : roc_npc_flow_dump(file, npc, -1);
1221 : :
1222 : 0 : return 0;
1223 : : }
1224 : : /* Configure async flow queues for the port. */
1225 : : int
1226 [ # # ]: 0 : cnxk_flow_configure(struct rte_eth_dev *eth_dev, const struct rte_flow_port_attr *port_attr,
1227 : : uint16_t nb_queue, const struct rte_flow_queue_attr *queue_attr[],
1228 : : struct rte_flow_error *err)
1229 : : {
1230 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1231 : : const struct roc_npc_flow_queue_attr **rptrs = NULL;
1232 : : struct roc_npc_flow_queue_attr *rattr = NULL;
1233 : 0 : struct roc_npc *npc = &dev->npc;
1234 : : uint16_t i;
1235 : : int rc;
1236 : :
1237 : : RTE_SET_USED(port_attr);
1238 : :
1239 : : /* Translate the rte queue attributes into roc_npc types; the roc
1240 : : * engine validates nb_queue == 0 and a NULL queue_attr.
1241 : : */
1242 [ # # ]: 0 : if (nb_queue != 0 && queue_attr != NULL) {
1243 : 0 : rattr = plt_zmalloc(nb_queue * sizeof(*rattr), 0);
1244 [ # # ]: 0 : if (rattr == NULL)
1245 : 0 : return rte_flow_error_set(err, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1246 : : NULL, "Failed to allocate flow queues");
1247 : :
1248 : 0 : rptrs = plt_zmalloc(nb_queue * sizeof(*rptrs), 0);
1249 [ # # ]: 0 : if (rptrs == NULL) {
1250 : 0 : plt_free(rattr);
1251 : 0 : return rte_flow_error_set(err, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
1252 : : NULL, "Failed to allocate flow queues");
1253 : : }
1254 [ # # ]: 0 : for (i = 0; i < nb_queue; i++) {
1255 [ # # ]: 0 : if (queue_attr[i] != NULL) {
1256 : 0 : rattr[i].size = queue_attr[i]->size;
1257 : 0 : rptrs[i] = &rattr[i];
1258 : : } else {
1259 : 0 : rptrs[i] = NULL;
1260 : : }
1261 : : }
1262 : : }
1263 : :
1264 : 0 : rc = roc_npc_flow_configure(npc, nb_queue, rptrs);
1265 : :
1266 : 0 : plt_free(rattr);
1267 : 0 : plt_free(rptrs);
1268 : :
1269 [ # # ]: 0 : if (rc)
1270 : 0 : return rte_flow_error_set(err, -rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1271 : : "Failed to configure flow queues");
1272 : : return 0;
1273 : : }
1274 : :
1275 : : /* Deep-copy a spec/last/mask/conf payload into template-owned memory. */
1276 : : static int
1277 : 0 : cnxk_flow_dup_conf(void **copies, uint16_t *nb_copies, const void *src, size_t sz, const void **dst)
1278 : : {
1279 : : void *copy;
1280 : :
1281 [ # # ]: 0 : if (src == NULL || sz == 0) {
1282 : 0 : *dst = NULL;
1283 : 0 : return 0;
1284 : : }
1285 : 0 : copy = plt_zmalloc(sz, 0);
1286 [ # # ]: 0 : if (copy == NULL)
1287 : : return -ENOMEM;
1288 : : memcpy(copy, src, sz);
1289 : 0 : copies[(*nb_copies)++] = copy;
1290 : 0 : *dst = copy;
1291 : 0 : return 0;
1292 : : }
1293 : :
1294 : : struct rte_flow_pattern_template *
1295 [ # # ]: 0 : cnxk_flow_pattern_template_create(struct rte_eth_dev *eth_dev,
1296 : : const struct rte_flow_pattern_template_attr *attr,
1297 : : const struct rte_flow_item pattern[],
1298 : : struct rte_flow_error *error)
1299 : : {
1300 : : const char *errmsg = "Failed to allocate pattern template";
1301 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1302 : : struct cnxk_flow_pattern_template *tmpl = NULL;
1303 : : struct roc_npc_pattern_template_attr roc_attr;
1304 : : struct roc_npc_item_info *roc_pattern = NULL;
1305 : : int i, nb_items = 0, errcode = ENOMEM;
1306 : 0 : struct roc_npc *npc = &dev->npc;
1307 : : int roc_err;
1308 : :
1309 [ # # ]: 0 : if (attr == NULL) {
1310 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1311 : : "NULL template attr");
1312 : 0 : return NULL;
1313 : : }
1314 : :
1315 [ # # ]: 0 : if (pattern == NULL) {
1316 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1317 : : "NULL pattern");
1318 : 0 : return NULL;
1319 : : }
1320 : :
1321 [ # # ]: 0 : while (pattern[nb_items].type != RTE_FLOW_ITEM_TYPE_END)
1322 : 0 : nb_items++;
1323 : :
1324 : : /* Reject oversized templates; rules are built into fixed-size stack
1325 : : * arrays (combined_items[ROC_NPC_ITEM_TYPE_END + 1]).
1326 : : */
1327 [ # # ]: 0 : if (nb_items > ROC_NPC_ITEM_TYPE_END) {
1328 : : errcode = ENOTSUP;
1329 : : errmsg = "too many pattern items for hardware";
1330 : 0 : goto err_nomem;
1331 : : }
1332 : :
1333 : 0 : tmpl = plt_zmalloc(sizeof(*tmpl), 0);
1334 [ # # ]: 0 : if (tmpl == NULL)
1335 : 0 : goto err_nomem;
1336 : :
1337 : 0 : tmpl->attr = *attr;
1338 : 0 : tmpl->nb_items = nb_items;
1339 : :
1340 : 0 : tmpl->pattern = plt_zmalloc((nb_items + 1) * sizeof(struct rte_flow_item), 0);
1341 [ # # ]: 0 : if (tmpl->pattern == NULL)
1342 : 0 : goto err_free;
1343 : :
1344 : : /* At most 3 payload copies (spec/last/mask) per item. */
1345 : 0 : tmpl->copies = plt_zmalloc(3 * (nb_items + 1) * sizeof(void *), 0);
1346 [ # # ]: 0 : if (tmpl->copies == NULL)
1347 : 0 : goto err_free;
1348 : :
1349 [ # # ]: 0 : for (i = 0; i < nb_items; i++) {
1350 : 0 : enum rte_flow_item_type t = pattern[i].type;
1351 [ # # ]: 0 : size_t sz = (t < (int)RTE_DIM(term)) ? term[t].item_size : 0;
1352 : :
1353 : : /* Reject unrepresentable item types (sz 0), which would drop
1354 : : * spec/last/mask. VOID/ANY legitimately carry no payload.
1355 : : */
1356 [ # # # # ]: 0 : if (t != RTE_FLOW_ITEM_TYPE_VOID && t != RTE_FLOW_ITEM_TYPE_ANY && sz == 0) {
1357 : : errcode = ENOTSUP;
1358 : : errmsg = "unsupported pattern item type in template";
1359 : 0 : goto err_free;
1360 : : }
1361 : :
1362 : : /* Reject items with nested variable-length payloads; a flat
1363 : : * memcpy would retain a dangling pointer into caller memory.
1364 : : */
1365 [ # # ]: 0 : if (t == RTE_FLOW_ITEM_TYPE_RAW) {
1366 : : errcode = ENOTSUP;
1367 : : errmsg = "Item type with nested pointers is not supported "
1368 : : "in pattern template (e.g. RAW)";
1369 : 0 : goto err_free;
1370 : : }
1371 : :
1372 : 0 : tmpl->pattern[i].type = t;
1373 [ # # ]: 0 : if (cnxk_flow_dup_conf(tmpl->copies, &tmpl->nb_copies, pattern[i].spec, sz,
1374 [ # # ]: 0 : &tmpl->pattern[i].spec) ||
1375 : 0 : cnxk_flow_dup_conf(tmpl->copies, &tmpl->nb_copies, pattern[i].last, sz,
1376 [ # # ]: 0 : &tmpl->pattern[i].last) ||
1377 : 0 : cnxk_flow_dup_conf(tmpl->copies, &tmpl->nb_copies, pattern[i].mask, sz,
1378 : 0 : &tmpl->pattern[i].mask))
1379 : 0 : goto err_free;
1380 : : }
1381 : 0 : tmpl->pattern[nb_items].type = RTE_FLOW_ITEM_TYPE_END;
1382 : 0 : tmpl->roc_tmpl = NULL;
1383 : 0 : tmpl->refcnt = 0;
1384 : :
1385 : 0 : roc_pattern = plt_zmalloc((nb_items + 1) * sizeof(*roc_pattern), 0);
1386 [ # # ]: 0 : if (roc_pattern == NULL)
1387 : 0 : goto err_free;
1388 : :
1389 [ # # ]: 0 : for (i = 0; i < nb_items; i++) {
1390 : 0 : enum rte_flow_item_type t = tmpl->pattern[i].type;
1391 [ # # ]: 0 : size_t sz = (t < (int)RTE_DIM(term)) ? term[t].item_size : 0;
1392 : :
1393 : 0 : roc_pattern[i].type =
1394 [ # # ]: 0 : (t < (int)RTE_DIM(term)) ? term[t].item_type : ROC_NPC_ITEM_TYPE_VOID;
1395 : 0 : roc_pattern[i].size = sz;
1396 : 0 : roc_pattern[i].spec = tmpl->pattern[i].spec;
1397 : 0 : roc_pattern[i].last = tmpl->pattern[i].last;
1398 : 0 : roc_pattern[i].mask = tmpl->pattern[i].mask;
1399 : : }
1400 : 0 : roc_pattern[nb_items].type = ROC_NPC_ITEM_TYPE_END;
1401 : :
1402 : : memset(&roc_attr, 0, sizeof(roc_attr));
1403 : 0 : roc_attr.relaxed_matching = attr->relaxed_matching;
1404 : 0 : roc_attr.ingress = attr->ingress;
1405 : 0 : roc_attr.egress = attr->egress;
1406 : 0 : roc_attr.transfer = attr->transfer;
1407 : :
1408 : 0 : roc_err = 0;
1409 : 0 : tmpl->roc_tmpl = roc_npc_pattern_template_create(npc, &roc_attr, roc_pattern, &roc_err);
1410 [ # # ]: 0 : if (tmpl->roc_tmpl == NULL) {
1411 [ # # ]: 0 : errcode = (roc_err < 0) ? -roc_err : ENOMEM;
1412 : : errmsg = "Failed to create ROC pattern template";
1413 : 0 : goto err_free;
1414 : : }
1415 : :
1416 : 0 : plt_free(roc_pattern);
1417 : :
1418 : 0 : return (struct rte_flow_pattern_template *)tmpl;
1419 : :
1420 : 0 : err_free:
1421 : 0 : plt_free(roc_pattern);
1422 : : if (tmpl != NULL) {
1423 : : uint16_t j;
1424 [ # # ]: 0 : if (tmpl->roc_tmpl != NULL)
1425 : 0 : roc_npc_pattern_template_destroy(npc, tmpl->roc_tmpl);
1426 [ # # ]: 0 : for (j = 0; j < tmpl->nb_copies; j++)
1427 : 0 : plt_free(tmpl->copies[j]);
1428 : 0 : plt_free(tmpl->copies);
1429 : 0 : plt_free(tmpl->pattern);
1430 : 0 : plt_free(tmpl);
1431 : : }
1432 : 0 : err_nomem:
1433 : 0 : rte_flow_error_set(error, errcode, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, errmsg);
1434 : 0 : return NULL;
1435 : : }
1436 : :
1437 : : int
1438 [ # # ]: 0 : cnxk_flow_pattern_template_destroy(struct rte_eth_dev *eth_dev,
1439 : : struct rte_flow_pattern_template *templ,
1440 : : struct rte_flow_error *error)
1441 : : {
1442 : : struct cnxk_flow_pattern_template *tmpl = (struct cnxk_flow_pattern_template *)templ;
1443 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1444 : 0 : struct roc_npc *npc = &dev->npc;
1445 : : uint16_t i;
1446 : : int rc;
1447 : :
1448 [ # # ]: 0 : if (tmpl == NULL)
1449 : : return 0;
1450 : :
1451 [ # # ]: 0 : if (tmpl->refcnt != 0)
1452 : 0 : return rte_flow_error_set(error, EBUSY, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1453 : : "pattern template still in use by a table");
1454 : :
1455 : 0 : rc = roc_npc_pattern_template_destroy(npc, tmpl->roc_tmpl);
1456 [ # # ]: 0 : if (rc)
1457 : 0 : return rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1458 : : "failed to destroy ROC pattern template");
1459 : :
1460 [ # # ]: 0 : for (i = 0; i < tmpl->nb_copies; i++)
1461 : 0 : plt_free(tmpl->copies[i]);
1462 : 0 : plt_free(tmpl->copies);
1463 : 0 : plt_free(tmpl->pattern);
1464 : 0 : plt_free(tmpl);
1465 : 0 : return 0;
1466 : : }
1467 : : /* Size of an action's conf for the v1-supported set; -1 = unsupported. */
1468 : : static int
1469 : : cnxk_flow_action_conf_size(enum rte_flow_action_type type)
1470 : : {
1471 : : switch (type) {
1472 : : case RTE_FLOW_ACTION_TYPE_VOID:
1473 : : case RTE_FLOW_ACTION_TYPE_DROP:
1474 : : case RTE_FLOW_ACTION_TYPE_PF:
1475 : : case RTE_FLOW_ACTION_TYPE_FLAG:
1476 : : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
1477 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
1478 : : return 0; /* no conf */
1479 : : case RTE_FLOW_ACTION_TYPE_QUEUE:
1480 : : return sizeof(struct rte_flow_action_queue);
1481 : : case RTE_FLOW_ACTION_TYPE_VF:
1482 : : return sizeof(struct rte_flow_action_vf);
1483 : : case RTE_FLOW_ACTION_TYPE_MARK:
1484 : : return sizeof(struct rte_flow_action_mark);
1485 : : case RTE_FLOW_ACTION_TYPE_COUNT:
1486 : : return sizeof(struct rte_flow_action_count);
1487 : : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
1488 : : return sizeof(struct rte_flow_action_of_push_vlan);
1489 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
1490 : : return sizeof(struct rte_flow_action_of_set_vlan_vid);
1491 : : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
1492 : : return sizeof(struct rte_flow_action_of_set_vlan_pcp);
1493 : : case RTE_FLOW_ACTION_TYPE_AGE:
1494 : : return sizeof(struct rte_flow_action_age);
1495 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
1496 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
1497 : : return sizeof(struct rte_flow_action_ethdev);
1498 : : case RTE_FLOW_ACTION_TYPE_PORT_ID:
1499 : : return sizeof(struct rte_flow_action_port_id);
1500 : : default:
1501 : : return -1;
1502 : : }
1503 : : }
1504 : :
1505 : : /* Deep-copy an action conf. RSS nests queue[]/key[] pointers, so pack them
1506 : : * into one blob and fix the pointers; other confs use a flat memcpy.
1507 : : */
1508 : : static void *
1509 : 0 : cnxk_flow_dup_action_conf(const struct rte_flow_action *act)
1510 : : {
1511 [ # # ]: 0 : if (act->conf == NULL)
1512 : : return NULL;
1513 : :
1514 [ # # ]: 0 : if (act->type == RTE_FLOW_ACTION_TYPE_RSS) {
1515 : : const struct rte_flow_action_rss *rss = act->conf;
1516 : : size_t rss_blob_bytes = sizeof(*rss);
1517 : 0 : size_t rss_queue_bytes = (size_t)rss->queue_num * sizeof(uint16_t);
1518 : 0 : size_t rss_key_bytes = rss->key_len;
1519 : : struct rte_flow_action_rss *rss_copy;
1520 : : uint8_t *rss_blob;
1521 : :
1522 : : /* Reject a non-zero length paired with a NULL pointer, which
1523 : : * would make the memcpy below dereference NULL.
1524 : : */
1525 [ # # # # : 0 : if ((rss_queue_bytes && rss->queue == NULL) || (rss_key_bytes && rss->key == NULL))
# # # # ]
1526 : : return NULL;
1527 : :
1528 : 0 : rss_blob = plt_zmalloc(rss_blob_bytes + rss_queue_bytes + rss_key_bytes, 0);
1529 [ # # ]: 0 : if (rss_blob == NULL)
1530 : : return NULL;
1531 : : rss_copy = (struct rte_flow_action_rss *)rss_blob;
1532 : 0 : *rss_copy = *rss;
1533 [ # # ]: 0 : if (rss_queue_bytes) {
1534 : 0 : memcpy(rss_blob + rss_blob_bytes, rss->queue, rss_queue_bytes);
1535 : 0 : rss_copy->queue = (const uint16_t *)(rss_blob + rss_blob_bytes);
1536 : : } else {
1537 : 0 : rss_copy->queue = NULL;
1538 : : }
1539 [ # # ]: 0 : if (rss_key_bytes) {
1540 : 0 : memcpy(rss_blob + rss_blob_bytes + rss_queue_bytes, rss->key,
1541 : : rss_key_bytes);
1542 : 0 : rss_copy->key =
1543 : : (const uint8_t *)(rss_blob + rss_blob_bytes + rss_queue_bytes);
1544 : : } else {
1545 : 0 : rss_copy->key = NULL;
1546 : : }
1547 : 0 : return rss_copy;
1548 : : }
1549 : :
1550 : : {
1551 : : int conf_size = cnxk_flow_action_conf_size(act->type);
1552 : : void *copy;
1553 : :
1554 [ # # ]: 0 : if (conf_size <= 0)
1555 : : return NULL;
1556 : 0 : copy = plt_zmalloc(conf_size, 0);
1557 [ # # ]: 0 : if (copy != NULL)
1558 : 0 : memcpy(copy, act->conf, conf_size);
1559 : : return copy;
1560 : : }
1561 : : }
1562 : :
1563 : : /* Map a supported rte_flow action type to its roc_npc action type, to mirror
1564 : : * the actions template into the roc engine for lifecycle/refcount ownership.
1565 : : */
1566 : : static int
1567 : 0 : cnxk_flow_roc_action_type(enum rte_flow_action_type type, enum roc_npc_action_type *roc_type)
1568 : : {
1569 [ # # # # : 0 : switch (type) {
# # # # #
# # # # #
# # ]
1570 : 0 : case RTE_FLOW_ACTION_TYPE_VOID:
1571 : : case RTE_FLOW_ACTION_TYPE_VXLAN_DECAP:
1572 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_VOID;
1573 : 0 : return 0;
1574 : 0 : case RTE_FLOW_ACTION_TYPE_DROP:
1575 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_DROP;
1576 : 0 : return 0;
1577 : 0 : case RTE_FLOW_ACTION_TYPE_PF:
1578 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_PF;
1579 : 0 : return 0;
1580 : 0 : case RTE_FLOW_ACTION_TYPE_VF:
1581 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_VF;
1582 : 0 : return 0;
1583 : 0 : case RTE_FLOW_ACTION_TYPE_FLAG:
1584 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_FLAG;
1585 : 0 : return 0;
1586 : 0 : case RTE_FLOW_ACTION_TYPE_MARK:
1587 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_MARK;
1588 : 0 : return 0;
1589 : 0 : case RTE_FLOW_ACTION_TYPE_COUNT:
1590 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_COUNT;
1591 : 0 : return 0;
1592 : 0 : case RTE_FLOW_ACTION_TYPE_QUEUE:
1593 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_QUEUE;
1594 : 0 : return 0;
1595 : 0 : case RTE_FLOW_ACTION_TYPE_RSS:
1596 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_RSS;
1597 : 0 : return 0;
1598 : 0 : case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
1599 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_VLAN_STRIP;
1600 : 0 : return 0;
1601 : 0 : case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
1602 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_VLAN_ETHTYPE_INSERT;
1603 : 0 : return 0;
1604 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
1605 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_VLAN_INSERT;
1606 : 0 : return 0;
1607 : 0 : case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
1608 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_VLAN_PCP_INSERT;
1609 : 0 : return 0;
1610 : 0 : case RTE_FLOW_ACTION_TYPE_AGE:
1611 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_AGE;
1612 : 0 : return 0;
1613 : 0 : case RTE_FLOW_ACTION_TYPE_PORT_ID:
1614 : : case RTE_FLOW_ACTION_TYPE_REPRESENTED_PORT:
1615 : : case RTE_FLOW_ACTION_TYPE_PORT_REPRESENTOR:
1616 : 0 : *roc_type = ROC_NPC_ACTION_TYPE_PORT_ID;
1617 : 0 : return 0;
1618 : : default:
1619 : : return -1;
1620 : : }
1621 : : }
1622 : :
1623 : : struct rte_flow_actions_template *
1624 [ # # ]: 0 : cnxk_flow_actions_template_create(struct rte_eth_dev *eth_dev,
1625 : : const struct rte_flow_actions_template_attr *attr,
1626 : : const struct rte_flow_action actions[],
1627 : : const struct rte_flow_action masks[],
1628 : : struct rte_flow_error *error)
1629 : : {
1630 : : const char *errmsg = "Failed to allocate actions template";
1631 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1632 : : struct cnxk_flow_actions_template *tmpl = NULL;
1633 : : struct roc_npc_actions_template_attr roc_attr;
1634 : : struct roc_npc_action *roc_actions = NULL;
1635 : : int i, nb_actions = 0, errcode = ENOMEM;
1636 : 0 : struct roc_npc *npc = &dev->npc;
1637 : 0 : int roc_err = 0;
1638 : :
1639 [ # # ]: 0 : if (attr == NULL) {
1640 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1641 : : "NULL template attr");
1642 : 0 : return NULL;
1643 : : }
1644 : :
1645 [ # # ]: 0 : if (actions == NULL) {
1646 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1647 : : "NULL actions");
1648 : 0 : return NULL;
1649 : : }
1650 : :
1651 [ # # ]: 0 : while (actions[nb_actions].type != RTE_FLOW_ACTION_TYPE_END)
1652 : 0 : nb_actions++;
1653 : :
1654 : : /* Reject oversized templates; rules are built into fixed-size stack
1655 : : * arrays (combined_actions[ROC_NPC_MAX_ACTION_COUNT] plus END).
1656 : : */
1657 [ # # ]: 0 : if (nb_actions > ROC_NPC_MAX_ACTION_COUNT - 1) {
1658 : : errcode = ENOTSUP;
1659 : : errmsg = "too many actions for hardware";
1660 : 0 : goto err;
1661 : : }
1662 : :
1663 : 0 : tmpl = plt_zmalloc(sizeof(*tmpl), 0);
1664 [ # # ]: 0 : if (tmpl == NULL)
1665 : 0 : goto err;
1666 : :
1667 : 0 : tmpl->attr = *attr;
1668 : 0 : tmpl->nb_actions = nb_actions;
1669 : :
1670 : 0 : tmpl->actions = plt_zmalloc((nb_actions + 1) * sizeof(struct rte_flow_action), 0);
1671 [ # # ]: 0 : if (tmpl->actions == NULL)
1672 : 0 : goto err;
1673 : :
1674 : 0 : tmpl->masks = plt_zmalloc((nb_actions + 1) * sizeof(struct rte_flow_action), 0);
1675 [ # # ]: 0 : if (tmpl->masks == NULL)
1676 : 0 : goto err;
1677 : :
1678 : : /* up to 2 conf copies (action + mask) per action */
1679 : 0 : tmpl->copies = plt_zmalloc(2 * (nb_actions + 1) * sizeof(void *), 0);
1680 [ # # ]: 0 : if (tmpl->copies == NULL)
1681 : 0 : goto err;
1682 : :
1683 [ # # ]: 0 : for (i = 0; i < nb_actions; i++) {
1684 [ # # ]: 0 : enum rte_flow_action_type t = actions[i].type;
1685 : : int sz = cnxk_flow_action_conf_size(t);
1686 : :
1687 [ # # ]: 0 : if (sz < 0 && t != RTE_FLOW_ACTION_TYPE_RSS) {
1688 : : errcode = ENOTSUP;
1689 : : errmsg = "Unsupported action in template "
1690 : : "(supports VOID/DROP/QUEUE/PF/VF/MARK/FLAG/COUNT/RSS/"
1691 : : "OF_POP_VLAN/OF_PUSH_VLAN/OF_SET_VLAN_VID/"
1692 : : "OF_SET_VLAN_PCP/AGE/REPRESENTED_PORT/"
1693 : : "PORT_REPRESENTOR/PORT_ID/VXLAN_DECAP)";
1694 : 0 : goto err;
1695 : : }
1696 : :
1697 : 0 : tmpl->actions[i].type = t;
1698 : :
1699 [ # # ]: 0 : if (t == RTE_FLOW_ACTION_TYPE_RSS) {
1700 : : /* RSS has nested pointers — use deep-copy helper. */
1701 : 0 : void *copy = cnxk_flow_dup_action_conf(&actions[i]);
1702 : :
1703 [ # # # # ]: 0 : if (copy == NULL && actions[i].conf != NULL) {
1704 : : const struct rte_flow_action_rss *rss = actions[i].conf;
1705 : :
1706 : : /* Malformed conf vs allocation failure: report a
1707 : : * precise errno instead of the default ENOMEM.
1708 : : */
1709 [ # # # # ]: 0 : if ((rss->queue_num && rss->queue == NULL) ||
1710 [ # # # # ]: 0 : (rss->key_len && rss->key == NULL)) {
1711 : : errcode = EINVAL;
1712 : : errmsg = "Malformed RSS action conf in template";
1713 : : }
1714 : 0 : goto err;
1715 : : }
1716 : 0 : tmpl->actions[i].conf = copy;
1717 [ # # ]: 0 : if (copy)
1718 : 0 : tmpl->copies[tmpl->nb_copies++] = copy;
1719 : : } else {
1720 [ # # ]: 0 : if (cnxk_flow_dup_conf(tmpl->copies, &tmpl->nb_copies, actions[i].conf, sz,
1721 : : &tmpl->actions[i].conf))
1722 : 0 : goto err;
1723 : : }
1724 : :
1725 [ # # ]: 0 : if (masks != NULL) {
1726 [ # # ]: 0 : if (masks[i].type != t) {
1727 : : errcode = EINVAL;
1728 : : errmsg = "actions/masks type mismatch in template";
1729 : 0 : goto err;
1730 : : }
1731 : 0 : tmpl->masks[i].type = t;
1732 [ # # ]: 0 : if (t == RTE_FLOW_ACTION_TYPE_RSS) {
1733 : : /* RSS nests pointers and cannot be copied by the flat
1734 : : * helper; reject a non-NULL RSS mask.
1735 : : */
1736 [ # # ]: 0 : if (masks[i].conf != NULL) {
1737 : : errcode = ENOTSUP;
1738 : : errmsg = "Non-NULL RSS mask conf is not "
1739 : : "supported in template";
1740 : 0 : goto err;
1741 : : }
1742 : 0 : tmpl->masks[i].conf = NULL;
1743 [ # # ]: 0 : } else if (cnxk_flow_dup_conf(tmpl->copies, &tmpl->nb_copies, masks[i].conf,
1744 : 0 : sz > 0 ? sz : 0, &tmpl->masks[i].conf)) {
1745 : 0 : goto err;
1746 : : }
1747 : : }
1748 : : }
1749 : :
1750 : 0 : tmpl->actions[nb_actions].type = RTE_FLOW_ACTION_TYPE_END;
1751 : 0 : tmpl->masks[nb_actions].type = RTE_FLOW_ACTION_TYPE_END;
1752 : 0 : tmpl->roc_tmpl = NULL;
1753 : 0 : tmpl->refcnt = 0;
1754 : :
1755 : : /* Mirror only action types into the roc engine for template lifecycle
1756 : : * and refcount ownership; per-rule conf translation stays in cnxk.
1757 : : */
1758 : 0 : roc_actions = plt_zmalloc((nb_actions + 1) * sizeof(*roc_actions), 0);
1759 [ # # ]: 0 : if (roc_actions == NULL)
1760 : 0 : goto err;
1761 : :
1762 [ # # ]: 0 : for (i = 0; i < nb_actions; i++) {
1763 : : enum roc_npc_action_type rt;
1764 : :
1765 [ # # ]: 0 : if (cnxk_flow_roc_action_type(tmpl->actions[i].type, &rt)) {
1766 : : errcode = ENOTSUP;
1767 : : errmsg = "Unsupported action in template";
1768 : 0 : goto err;
1769 : : }
1770 : 0 : roc_actions[i].type = rt;
1771 : 0 : roc_actions[i].conf = NULL;
1772 : : }
1773 : 0 : roc_actions[nb_actions].type = ROC_NPC_ACTION_TYPE_END;
1774 : :
1775 : : memset(&roc_attr, 0, sizeof(roc_attr));
1776 : 0 : roc_attr.ingress = attr->ingress;
1777 : 0 : roc_attr.egress = attr->egress;
1778 : 0 : roc_attr.transfer = attr->transfer;
1779 : :
1780 : 0 : tmpl->roc_tmpl =
1781 : 0 : roc_npc_actions_template_create(npc, &roc_attr, roc_actions, NULL, &roc_err);
1782 : 0 : plt_free(roc_actions);
1783 : : roc_actions = NULL;
1784 [ # # ]: 0 : if (tmpl->roc_tmpl == NULL) {
1785 [ # # ]: 0 : errcode = (roc_err < 0) ? -roc_err : ENOMEM;
1786 : : errmsg = "Failed to create ROC actions template";
1787 : 0 : goto err;
1788 : : }
1789 : :
1790 : : return (struct rte_flow_actions_template *)tmpl;
1791 : :
1792 : 0 : err:
1793 : 0 : plt_free(roc_actions);
1794 [ # # ]: 0 : if (tmpl != NULL) {
1795 : : uint16_t j;
1796 [ # # ]: 0 : if (tmpl->roc_tmpl != NULL)
1797 : 0 : roc_npc_actions_template_destroy(npc, tmpl->roc_tmpl);
1798 [ # # ]: 0 : for (j = 0; j < tmpl->nb_copies; j++)
1799 : 0 : plt_free(tmpl->copies[j]);
1800 : 0 : plt_free(tmpl->copies);
1801 : 0 : plt_free(tmpl->masks);
1802 : 0 : plt_free(tmpl->actions);
1803 : 0 : plt_free(tmpl);
1804 : : }
1805 : 0 : rte_flow_error_set(error, errcode, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, errmsg);
1806 : 0 : return NULL;
1807 : : }
1808 : :
1809 : : int
1810 [ # # ]: 0 : cnxk_flow_actions_template_destroy(struct rte_eth_dev *eth_dev,
1811 : : struct rte_flow_actions_template *templ,
1812 : : struct rte_flow_error *error)
1813 : : {
1814 : : struct cnxk_flow_actions_template *tmpl = (struct cnxk_flow_actions_template *)templ;
1815 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1816 : 0 : struct roc_npc *npc = &dev->npc;
1817 : : uint16_t i;
1818 : : int rc;
1819 : :
1820 [ # # ]: 0 : if (tmpl == NULL)
1821 : : return 0;
1822 : :
1823 [ # # ]: 0 : if (tmpl->refcnt != 0)
1824 : 0 : return rte_flow_error_set(error, EBUSY, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1825 : : "actions template still in use by a table");
1826 : :
1827 : 0 : rc = roc_npc_actions_template_destroy(npc, tmpl->roc_tmpl);
1828 [ # # ]: 0 : if (rc)
1829 : 0 : return rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1830 : : "failed to destroy ROC actions template");
1831 : :
1832 [ # # ]: 0 : for (i = 0; i < tmpl->nb_copies; i++)
1833 : 0 : plt_free(tmpl->copies[i]);
1834 : 0 : plt_free(tmpl->copies);
1835 : 0 : plt_free(tmpl->masks);
1836 : 0 : plt_free(tmpl->actions);
1837 : 0 : plt_free(tmpl);
1838 : 0 : return 0;
1839 : : }
1840 : :
1841 : : struct rte_flow_template_table *
1842 [ # # ]: 0 : cnxk_flow_template_table_create(struct rte_eth_dev *eth_dev,
1843 : : const struct rte_flow_template_table_attr *table_attr,
1844 : : struct rte_flow_pattern_template *pattern_templates[],
1845 : : uint8_t nb_pattern_templates,
1846 : : struct rte_flow_actions_template *actions_templates[],
1847 : : uint8_t nb_actions_templates, struct rte_flow_error *error)
1848 : : {
1849 : : struct roc_npc_pattern_template **roc_pattern_templates = NULL;
1850 : : struct roc_npc_actions_template **roc_actions_templates = NULL;
1851 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
1852 : : struct roc_npc_template_table_attr roc_attr;
1853 : : enum rte_flow_table_insertion_type itype;
1854 : : const struct rte_flow_attr *fattr;
1855 : 0 : struct roc_npc *npc = &dev->npc;
1856 : : struct cnxk_flow_table *table;
1857 : : uint32_t nb_flows;
1858 : 0 : int errcode = 0;
1859 : : uint8_t i;
1860 : :
1861 [ # # ]: 0 : if (table_attr == NULL) {
1862 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1863 : : "NULL table_attr");
1864 : 0 : return NULL;
1865 : : }
1866 : :
1867 : 0 : itype = table_attr->insertion_type;
1868 : : fattr = &table_attr->flow_attr;
1869 : 0 : nb_flows = table_attr->nb_flows;
1870 : :
1871 [ # # ]: 0 : if (itype == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX) {
1872 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1873 : : "pure-index insertion not supported; NPC is match-based");
1874 : 0 : return NULL;
1875 : : }
1876 : :
1877 : : /* Validate the template handles before allocating anything. */
1878 [ # # ]: 0 : for (i = 0; i < nb_pattern_templates; i++) {
1879 [ # # ]: 0 : if (pattern_templates[i] == NULL) {
1880 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1881 : : "invalid template handle");
1882 : 0 : return NULL;
1883 : : }
1884 : : }
1885 [ # # ]: 0 : for (i = 0; i < nb_actions_templates; i++) {
1886 [ # # ]: 0 : if (actions_templates[i] == NULL) {
1887 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1888 : : "invalid template handle");
1889 : 0 : return NULL;
1890 : : }
1891 : : }
1892 : :
1893 : 0 : table = plt_zmalloc(sizeof(*table), 0);
1894 [ # # ]: 0 : if (table == NULL)
1895 : 0 : goto enomem;
1896 : :
1897 : 0 : table->insertion_type = itype;
1898 : 0 : table->nb_flows = nb_flows;
1899 : :
1900 [ # # ]: 0 : memset(&table->flow_attr, 0, sizeof(table->flow_attr));
1901 : 0 : table->flow_attr.priority = fattr->priority;
1902 : 0 : table->flow_attr.ingress = fattr->ingress;
1903 : 0 : table->flow_attr.egress = fattr->egress;
1904 : 0 : table->transfer = fattr->transfer;
1905 : :
1906 [ # # ]: 0 : if (nb_pattern_templates != 0) {
1907 : 0 : table->pattern_templates =
1908 : 0 : plt_zmalloc(nb_pattern_templates * sizeof(*table->pattern_templates), 0);
1909 [ # # ]: 0 : if (table->pattern_templates == NULL)
1910 : 0 : goto free_table;
1911 : : roc_pattern_templates =
1912 : 0 : plt_zmalloc(nb_pattern_templates * sizeof(*roc_pattern_templates), 0);
1913 [ # # ]: 0 : if (roc_pattern_templates == NULL)
1914 : 0 : goto free_table;
1915 : : }
1916 [ # # ]: 0 : if (nb_actions_templates != 0) {
1917 : 0 : table->actions_templates =
1918 : 0 : plt_zmalloc(nb_actions_templates * sizeof(*table->actions_templates), 0);
1919 [ # # ]: 0 : if (table->actions_templates == NULL)
1920 : 0 : goto free_table;
1921 : : roc_actions_templates =
1922 : 0 : plt_zmalloc(nb_actions_templates * sizeof(*roc_actions_templates), 0);
1923 [ # # ]: 0 : if (roc_actions_templates == NULL)
1924 : 0 : goto free_table;
1925 : : }
1926 : :
1927 : : /* Hand the table to the roc engine, which owns rule storage, MCAM
1928 : : * reservation and the rule lifecycle; cnxk keeps per-rule translation.
1929 : : */
1930 : : memset(&roc_attr, 0, sizeof(roc_attr));
1931 : 0 : roc_attr.flow_attr = table->flow_attr;
1932 : 0 : roc_attr.transfer = table->transfer;
1933 : 0 : roc_attr.nb_flows = nb_flows;
1934 : 0 : roc_attr.insertion_type = (itype == RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN) ?
1935 : 0 : ROC_NPC_TEMPLATE_INSERTION_INDEX_WITH_PATTERN :
1936 : : ROC_NPC_TEMPLATE_INSERTION_PATTERN;
1937 : : /* Stash this wrapper as the table cookie so async_actions_update can
1938 : : * recover the rte templates from just the flow handle.
1939 : : */
1940 : 0 : roc_attr.cookie = table;
1941 : :
1942 [ # # ]: 0 : for (i = 0; i < nb_pattern_templates; i++) {
1943 : 0 : table->pattern_templates[i] =
1944 : 0 : (struct cnxk_flow_pattern_template *)pattern_templates[i];
1945 : 0 : roc_pattern_templates[i] = table->pattern_templates[i]->roc_tmpl;
1946 [ # # ]: 0 : if (roc_pattern_templates[i] == NULL)
1947 : 0 : goto bad_handle;
1948 : : }
1949 [ # # ]: 0 : for (i = 0; i < nb_actions_templates; i++) {
1950 : 0 : table->actions_templates[i] =
1951 : 0 : (struct cnxk_flow_actions_template *)actions_templates[i];
1952 : 0 : roc_actions_templates[i] = table->actions_templates[i]->roc_tmpl;
1953 [ # # ]: 0 : if (roc_actions_templates[i] == NULL)
1954 : 0 : goto bad_handle;
1955 : : }
1956 : :
1957 : : /* clang-format off */
1958 : 0 : table->roc_table = roc_npc_template_table_create(npc, &roc_attr,
1959 : : roc_pattern_templates, nb_pattern_templates,
1960 : : roc_actions_templates, nb_actions_templates, &errcode);
1961 : : /* clang-format on */
1962 : 0 : plt_free(roc_pattern_templates);
1963 : 0 : plt_free(roc_actions_templates);
1964 : : roc_pattern_templates = NULL;
1965 : : roc_actions_templates = NULL;
1966 [ # # ]: 0 : if (table->roc_table == NULL) {
1967 : 0 : plt_free(table->pattern_templates);
1968 : 0 : plt_free(table->actions_templates);
1969 : 0 : plt_free(table);
1970 [ # # ]: 0 : rte_flow_error_set(error, errcode < 0 ? -errcode : ENOMEM,
1971 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1972 : : "could not create template table");
1973 : 0 : return NULL;
1974 : : }
1975 : :
1976 [ # # ]: 0 : for (i = 0; i < nb_pattern_templates; i++)
1977 : 0 : table->pattern_templates[i]->refcnt++;
1978 : 0 : table->nb_pattern_templates = nb_pattern_templates;
1979 [ # # ]: 0 : for (i = 0; i < nb_actions_templates; i++)
1980 : 0 : table->actions_templates[i]->refcnt++;
1981 : 0 : table->nb_actions_templates = nb_actions_templates;
1982 : :
1983 : 0 : return (struct rte_flow_template_table *)table;
1984 : :
1985 : 0 : bad_handle:
1986 : 0 : plt_free(roc_pattern_templates);
1987 : 0 : plt_free(roc_actions_templates);
1988 : 0 : plt_free(table->pattern_templates);
1989 : 0 : plt_free(table->actions_templates);
1990 : 0 : plt_free(table);
1991 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
1992 : : "invalid template handle");
1993 : 0 : return NULL;
1994 : :
1995 : 0 : free_table:
1996 : 0 : plt_free(roc_pattern_templates);
1997 : 0 : plt_free(roc_actions_templates);
1998 : 0 : plt_free(table->pattern_templates);
1999 : 0 : plt_free(table->actions_templates);
2000 : 0 : plt_free(table);
2001 : :
2002 : 0 : enomem:
2003 : 0 : rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL, "out of memory");
2004 : 0 : return NULL;
2005 : : }
2006 : :
2007 : : int
2008 [ # # ]: 0 : cnxk_flow_template_table_destroy(struct rte_eth_dev *eth_dev,
2009 : : struct rte_flow_template_table *tbl_handle,
2010 : : struct rte_flow_error *error)
2011 : : {
2012 : : struct cnxk_flow_table *table = (struct cnxk_flow_table *)tbl_handle;
2013 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2014 : 0 : struct roc_npc *npc = &dev->npc;
2015 : : uint8_t i;
2016 : : int rc;
2017 : :
2018 [ # # ]: 0 : if (table == NULL)
2019 : : return 0;
2020 : :
2021 : : /* The roc engine guards teardown: a busy table returns -EBUSY and
2022 : : * nothing is freed, so the cnxk wrapper and refcounts stay intact.
2023 : : */
2024 : 0 : rc = roc_npc_template_table_destroy(npc, table->roc_table);
2025 [ # # ]: 0 : if (rc == -EBUSY)
2026 : 0 : return rte_flow_error_set(error, EBUSY, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2027 : : "table still has live flows; destroy them first");
2028 [ # # ]: 0 : if (rc)
2029 : 0 : return rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2030 : : "failed to destroy template table");
2031 : :
2032 [ # # ]: 0 : for (i = 0; i < table->nb_pattern_templates; i++)
2033 : 0 : table->pattern_templates[i]->refcnt--;
2034 [ # # ]: 0 : for (i = 0; i < table->nb_actions_templates; i++)
2035 : 0 : table->actions_templates[i]->refcnt--;
2036 : :
2037 : 0 : plt_free(table->pattern_templates);
2038 : 0 : plt_free(table->actions_templates);
2039 : 0 : plt_free(table);
2040 : 0 : return 0;
2041 : : }
2042 : :
2043 : : /* Reject per-rule pattern/actions arrays whose types/order do not mirror the
2044 : : * chosen templates; the merge takes the type from the template but the
2045 : : * spec/conf from the per-rule array. A NULL array uses template defaults.
2046 : : */
2047 : : static int
2048 : : cnxk_flow_check_items(const struct cnxk_flow_pattern_template *pt,
2049 : : const struct rte_flow_item items[])
2050 : : {
2051 : : uint16_t k;
2052 : :
2053 : 0 : if (items == NULL)
2054 : : return 0;
2055 [ # # # # ]: 0 : for (k = 0; k < pt->nb_items; k++)
2056 [ # # # # ]: 0 : if (items[k].type != pt->pattern[k].type)
2057 : : return -EINVAL;
2058 [ # # # # ]: 0 : if (items[pt->nb_items].type != RTE_FLOW_ITEM_TYPE_END)
2059 : : return -EINVAL;
2060 : : return 0;
2061 : : }
2062 : :
2063 : : static int
2064 : : cnxk_flow_check_actions(const struct cnxk_flow_actions_template *at,
2065 : : const struct rte_flow_action actions[])
2066 : : {
2067 : : uint16_t k;
2068 : :
2069 [ # # # # ]: 0 : if (actions == NULL)
2070 : : return 0;
2071 [ # # # # : 0 : for (k = 0; k < at->nb_actions; k++)
# # ]
2072 [ # # # # : 0 : if (actions[k].type != at->actions[k].type)
# # ]
2073 : : return -EINVAL;
2074 [ # # # # : 0 : if (actions[at->nb_actions].type != RTE_FLOW_ACTION_TYPE_END)
# # ]
2075 : : return -EINVAL;
2076 : : return 0;
2077 : : }
2078 : :
2079 : : /* Enqueue a PATTERN create: merge the per-rule spec with the templates,
2080 : : * translate to roc_npc types, and hand to the roc engine (programmed at push).
2081 : : */
2082 : : struct rte_flow *
2083 [ # # ]: 0 : cnxk_flow_async_create(struct rte_eth_dev *eth_dev, uint32_t queue,
2084 : : const struct rte_flow_op_attr *attr,
2085 : : struct rte_flow_template_table *tbl_handle,
2086 : : const struct rte_flow_item items[], uint8_t pattern_template_index,
2087 : : const struct rte_flow_action actions[], uint8_t action_template_index,
2088 : : void *user_data, struct rte_flow_error *error)
2089 : : {
2090 : : struct cnxk_flow_table *table = (struct cnxk_flow_table *)tbl_handle;
2091 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2092 : : struct cnxk_flow_pattern_template *pt;
2093 : : struct cnxk_flow_actions_template *at;
2094 : : struct roc_npc_template_flow *flow;
2095 : 0 : struct roc_npc *npc = &dev->npc;
2096 : :
2097 : 0 : uint64_t free_allocs[ROC_NPC_MAX_ACTION_COUNT + ROC_NPC_ITEM_TYPE_END + 1] = {0};
2098 : 0 : struct roc_npc_item_info in_pattern[ROC_NPC_ITEM_TYPE_END + 1] = {0};
2099 : : struct rte_flow_action combined_actions[ROC_NPC_MAX_ACTION_COUNT];
2100 : 0 : struct roc_npc_action in_actions[ROC_NPC_MAX_ACTION_COUNT] = {0};
2101 : : struct rte_flow_item combined_items[ROC_NPC_ITEM_TYPE_END + 1];
2102 : 0 : struct roc_npc_action_sample in_sample = {0};
2103 : : struct rte_flow_attr rte_attr;
2104 : : struct roc_npc_attr in_attr;
2105 : 0 : uint16_t dst_pf_func = 0;
2106 : 0 : uint64_t def_action = 0;
2107 : 0 : int errcode = 0;
2108 : : uint16_t k;
2109 : : int rc, j;
2110 : :
2111 : : RTE_SET_USED(attr);
2112 : :
2113 [ # # ]: 0 : if (table == NULL) {
2114 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2115 : : "bad table");
2116 : 0 : return NULL;
2117 : : }
2118 [ # # ]: 0 : if (table->insertion_type != RTE_FLOW_TABLE_INSERTION_TYPE_PATTERN) {
2119 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2120 : : "table is index-insertion; use create_by_index_with_pattern");
2121 : 0 : return NULL;
2122 : : }
2123 [ # # ]: 0 : if (pattern_template_index >= table->nb_pattern_templates ||
2124 [ # # ]: 0 : action_template_index >= table->nb_actions_templates) {
2125 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2126 : : "template index out of range");
2127 : 0 : return NULL;
2128 : : }
2129 : :
2130 : 0 : pt = table->pattern_templates[pattern_template_index];
2131 [ # # ]: 0 : at = table->actions_templates[action_template_index];
2132 : :
2133 : : if (cnxk_flow_check_items(pt, items) != 0 || cnxk_flow_check_actions(at, actions) != 0) {
2134 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2135 : : "pattern/actions do not match the selected templates");
2136 : 0 : return NULL;
2137 : : }
2138 : :
2139 : : /* Merge: spec comes from the per-rule call, last/mask from the template. */
2140 [ # # ]: 0 : for (k = 0; k < pt->nb_items; k++) {
2141 : 0 : combined_items[k].type = pt->pattern[k].type;
2142 [ # # ]: 0 : combined_items[k].spec = items ? items[k].spec : NULL;
2143 : 0 : combined_items[k].last = pt->pattern[k].last;
2144 : 0 : combined_items[k].mask = pt->pattern[k].mask;
2145 : : }
2146 : 0 : combined_items[pt->nb_items].type = RTE_FLOW_ITEM_TYPE_END;
2147 : :
2148 : : /* Merge: per-rule conf overrides the template conf. */
2149 [ # # ]: 0 : for (k = 0; k < at->nb_actions; k++) {
2150 : 0 : combined_actions[k].type = at->actions[k].type;
2151 : 0 : combined_actions[k].conf =
2152 [ # # # # ]: 0 : (actions && actions[k].conf) ? actions[k].conf : at->actions[k].conf;
2153 : : }
2154 : 0 : combined_actions[at->nb_actions].type = RTE_FLOW_ACTION_TYPE_END;
2155 : :
2156 : : memset(&rte_attr, 0, sizeof(rte_attr));
2157 : 0 : rte_attr.priority = table->flow_attr.priority;
2158 : 0 : rte_attr.ingress = table->flow_attr.ingress;
2159 : 0 : rte_attr.egress = table->flow_attr.egress;
2160 : 0 : rte_attr.transfer = table->transfer;
2161 : :
2162 : : /* Translate into roc_npc types. The RSS flow key is stashed in
2163 : : * npc->flowkey_cfg_state so the engine can restore it at push().
2164 : : */
2165 : : memset(&in_attr, 0, sizeof(in_attr));
2166 : 0 : rc = cnxk_map_flow_data(eth_dev, &rte_attr, combined_items, combined_actions, &in_attr,
2167 : : in_pattern, in_actions, &in_sample, &npc->flowkey_cfg_state,
2168 : : &dst_pf_func, &def_action, false, free_allocs, 0);
2169 [ # # ]: 0 : if (rc == 0)
2170 : 0 : flow = roc_npc_async_flow_create(npc, queue, table->roc_table, in_pattern,
2171 : : in_actions, dst_pf_func, def_action, user_data,
2172 : : &errcode);
2173 : : else
2174 : : flow = NULL;
2175 : :
2176 [ # # # # ]: 0 : for (j = 0; j < (int)RTE_DIM(free_allocs) && free_allocs[j]; j++)
2177 : 0 : plt_free((void *)free_allocs[j]);
2178 : :
2179 [ # # ]: 0 : if (rc != 0) {
2180 : 0 : rte_flow_error_set(error, rc < 0 ? -rc : rc, RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
2181 : : "Failed to map flow data");
2182 : 0 : return NULL;
2183 : : }
2184 [ # # ]: 0 : if (flow == NULL) {
2185 [ # # ]: 0 : rte_flow_error_set(error, errcode < 0 ? -errcode : EINVAL,
2186 : : RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2187 : : "async flow create failed");
2188 : 0 : return NULL;
2189 : : }
2190 : :
2191 : : return (struct rte_flow *)flow;
2192 : : }
2193 : :
2194 : : /* Enqueue a destroy operation. */
2195 : : int
2196 : 0 : cnxk_flow_async_destroy(struct rte_eth_dev *eth_dev, uint32_t queue,
2197 : : const struct rte_flow_op_attr *attr, struct rte_flow *flow, void *user_data,
2198 : : struct rte_flow_error *error)
2199 : : {
2200 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2201 : 0 : struct roc_npc *npc = &dev->npc;
2202 : : int rc;
2203 : :
2204 : : RTE_SET_USED(attr);
2205 : :
2206 : 0 : rc = roc_npc_async_flow_destroy(npc, queue, (struct roc_npc_template_flow *)flow,
2207 : : user_data);
2208 [ # # ]: 0 : if (rc)
2209 : 0 : return rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2210 : : "bad queue or flow handle");
2211 : : return 0;
2212 : : }
2213 : :
2214 : : /* Flush all pending async operations to hardware in one batch. */
2215 : : int
2216 : 0 : cnxk_flow_push(struct rte_eth_dev *eth_dev, uint32_t queue, struct rte_flow_error *error)
2217 : : {
2218 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2219 : 0 : struct roc_npc *npc = &dev->npc;
2220 : : int rc;
2221 : :
2222 : 0 : rc = roc_npc_flow_push(npc, queue);
2223 [ # # ]: 0 : if (rc)
2224 : 0 : return rte_flow_error_set(error, -rc, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2225 : : "bad queue");
2226 : : return 0;
2227 : : }
2228 : :
2229 : : /* Return results for completed ops back to the application. */
2230 : : int
2231 : 0 : cnxk_flow_pull(struct rte_eth_dev *eth_dev, uint32_t queue, struct rte_flow_op_result res[],
2232 : : uint16_t n_res, struct rte_flow_error *error)
2233 : : {
2234 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2235 : 0 : struct roc_npc *npc = &dev->npc;
2236 : : uint16_t done = 0;
2237 : :
2238 : : /* Drain roc engine results in fixed-size batches, translating each
2239 : : * roc op result into the rte op result without a per-pull allocation.
2240 : : */
2241 [ # # ]: 0 : while (done < n_res) {
2242 : : struct roc_npc_flow_op_result rres[64];
2243 : 0 : uint16_t batch = RTE_MIN((uint16_t)(n_res - done), (uint16_t)RTE_DIM(rres));
2244 : 0 : int got = roc_npc_flow_pull(npc, queue, rres, batch);
2245 : : uint16_t k;
2246 : :
2247 [ # # ]: 0 : if (got < 0) {
2248 [ # # ]: 0 : if (done != 0)
2249 : : break;
2250 : 0 : return rte_flow_error_set(error, -got, RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
2251 : : NULL, "bad queue");
2252 : : }
2253 : :
2254 [ # # ]: 0 : for (k = 0; k < (uint16_t)got; k++) {
2255 : 0 : res[done + k].status =
2256 : 0 : (rres[k].rc == 0) ? RTE_FLOW_OP_SUCCESS : RTE_FLOW_OP_ERROR;
2257 : 0 : res[done + k].user_data = rres[k].user_data;
2258 : : }
2259 : 0 : done += (uint16_t)got;
2260 : :
2261 [ # # ]: 0 : if (got < batch)
2262 : : break;
2263 : : }
2264 : :
2265 : 0 : return done;
2266 : : }
2267 : :
2268 : : struct rte_flow *
2269 : 0 : cnxk_flow_async_create_by_index(struct rte_eth_dev *eth_dev, uint32_t queue,
2270 : : const struct rte_flow_op_attr *attr,
2271 : : struct rte_flow_template_table *table, uint32_t rule_index,
2272 : : const struct rte_flow_action actions[],
2273 : : uint8_t action_template_index, void *user_data,
2274 : : struct rte_flow_error *error)
2275 : : {
2276 : : RTE_SET_USED(eth_dev);
2277 : : RTE_SET_USED(queue);
2278 : : RTE_SET_USED(attr);
2279 : : RTE_SET_USED(table);
2280 : : RTE_SET_USED(rule_index);
2281 : : RTE_SET_USED(actions);
2282 : : RTE_SET_USED(action_template_index);
2283 : : RTE_SET_USED(user_data);
2284 : :
2285 : 0 : rte_flow_error_set(error, ENOTSUP, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2286 : : "index-only insertion needs a match key; NPC is match-based");
2287 : 0 : return NULL;
2288 : : }
2289 : :
2290 : : /* Like async_create but with an app-specified index; the app must avoid
2291 : : * concurrent creates to the same index and use a valid table index.
2292 : : */
2293 : : struct rte_flow *
2294 : : /* clang-format off */
2295 [ # # ]: 0 : cnxk_flow_async_create_by_index_with_pattern(struct rte_eth_dev *eth_dev,
2296 : : uint32_t queue, const struct rte_flow_op_attr *attr,
2297 : : struct rte_flow_template_table *tbl_handle, uint32_t rule_index,
2298 : : const struct rte_flow_item items[], uint8_t pattern_template_index,
2299 : : const struct rte_flow_action actions[],
2300 : : uint8_t action_template_index, void *user_data,
2301 : : struct rte_flow_error *error)
2302 : : /* clang-format on */
2303 : : {
2304 : : struct cnxk_flow_table *table = (struct cnxk_flow_table *)tbl_handle;
2305 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2306 : : struct cnxk_flow_pattern_template *pt;
2307 : : struct cnxk_flow_actions_template *at;
2308 : : struct roc_npc_template_flow *flow;
2309 : 0 : struct roc_npc *npc = &dev->npc;
2310 : :
2311 : 0 : uint64_t free_allocs[ROC_NPC_MAX_ACTION_COUNT + ROC_NPC_ITEM_TYPE_END + 1] = {0};
2312 : 0 : struct roc_npc_item_info in_pattern[ROC_NPC_ITEM_TYPE_END + 1] = {0};
2313 : : struct rte_flow_action combined_actions[ROC_NPC_MAX_ACTION_COUNT];
2314 : 0 : struct roc_npc_action in_actions[ROC_NPC_MAX_ACTION_COUNT] = {0};
2315 : : struct rte_flow_item combined_items[ROC_NPC_ITEM_TYPE_END + 1];
2316 : 0 : struct roc_npc_action_sample in_sample = {0};
2317 : : struct rte_flow_attr rte_attr;
2318 : : struct roc_npc_attr in_attr;
2319 : 0 : uint32_t flowkey_cfg = 0;
2320 : 0 : uint16_t dst_pf_func = 0;
2321 : 0 : uint64_t def_action = 0;
2322 : 0 : int errcode = 0;
2323 : : uint16_t k;
2324 : : int rc, j;
2325 : :
2326 : : RTE_SET_USED(attr);
2327 : :
2328 [ # # ]: 0 : if (table == NULL) {
2329 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2330 : : "bad table");
2331 : 0 : return NULL;
2332 : : }
2333 [ # # ]: 0 : if (table->insertion_type != RTE_FLOW_TABLE_INSERTION_TYPE_INDEX_WITH_PATTERN) {
2334 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2335 : : "table is not index-with-pattern insertion");
2336 : 0 : return NULL;
2337 : : }
2338 [ # # ]: 0 : if (pattern_template_index >= table->nb_pattern_templates ||
2339 [ # # ]: 0 : action_template_index >= table->nb_actions_templates) {
2340 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2341 : : "template index out of range");
2342 : 0 : return NULL;
2343 : : }
2344 [ # # ]: 0 : if (rule_index >= table->nb_flows) {
2345 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2346 : : "rule_index out of range");
2347 : 0 : return NULL;
2348 : : }
2349 : :
2350 : 0 : pt = table->pattern_templates[pattern_template_index];
2351 [ # # ]: 0 : at = table->actions_templates[action_template_index];
2352 : :
2353 : : if (cnxk_flow_check_items(pt, items) != 0 || cnxk_flow_check_actions(at, actions) != 0) {
2354 : 0 : rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2355 : : "pattern/actions do not match the selected templates");
2356 : 0 : return NULL;
2357 : : }
2358 : :
2359 [ # # ]: 0 : for (k = 0; k < pt->nb_items; k++) {
2360 : 0 : combined_items[k].type = pt->pattern[k].type;
2361 [ # # ]: 0 : combined_items[k].spec = items ? items[k].spec : NULL;
2362 : 0 : combined_items[k].last = pt->pattern[k].last;
2363 : 0 : combined_items[k].mask = pt->pattern[k].mask;
2364 : : }
2365 : 0 : combined_items[pt->nb_items].type = RTE_FLOW_ITEM_TYPE_END;
2366 : :
2367 [ # # ]: 0 : for (k = 0; k < at->nb_actions; k++) {
2368 : 0 : combined_actions[k].type = at->actions[k].type;
2369 : 0 : combined_actions[k].conf =
2370 [ # # # # ]: 0 : (actions && actions[k].conf) ? actions[k].conf : at->actions[k].conf;
2371 : : }
2372 : 0 : combined_actions[at->nb_actions].type = RTE_FLOW_ACTION_TYPE_END;
2373 : :
2374 : : memset(&rte_attr, 0, sizeof(rte_attr));
2375 : 0 : rte_attr.priority = table->flow_attr.priority;
2376 : 0 : rte_attr.ingress = table->flow_attr.ingress;
2377 : 0 : rte_attr.egress = table->flow_attr.egress;
2378 : 0 : rte_attr.transfer = table->transfer;
2379 : :
2380 : : memset(&in_attr, 0, sizeof(in_attr));
2381 : 0 : rc = cnxk_map_flow_data(eth_dev, &rte_attr, combined_items, combined_actions, &in_attr,
2382 : : in_pattern, in_actions, &in_sample, &flowkey_cfg, &dst_pf_func,
2383 : : &def_action, false, free_allocs, 0);
2384 [ # # ]: 0 : if (rc == 0)
2385 : : /* clang-format off */
2386 : 0 : flow = roc_npc_async_flow_create_by_index_with_pattern(npc, queue,
2387 : : table->roc_table, rule_index, in_pattern, in_actions,
2388 : : user_data, &errcode);
2389 : : /* clang-format on */
2390 : : else
2391 : : flow = NULL;
2392 : :
2393 [ # # # # ]: 0 : for (j = 0; j < (int)RTE_DIM(free_allocs) && free_allocs[j]; j++)
2394 : 0 : plt_free((void *)free_allocs[j]);
2395 : :
2396 [ # # ]: 0 : if (rc != 0) {
2397 : 0 : rte_flow_error_set(error, rc < 0 ? -rc : rc, RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,
2398 : : "Failed to map flow data");
2399 : 0 : return NULL;
2400 : : }
2401 [ # # ]: 0 : if (flow == NULL) {
2402 [ # # ]: 0 : rte_flow_error_set(error, errcode < 0 ? -errcode : EINVAL,
2403 : : RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "flow parse failed");
2404 : 0 : return NULL;
2405 : : }
2406 : :
2407 : : return (struct rte_flow *)flow;
2408 : : }
2409 : :
2410 : : /* Update the actions of an existing flow, keeping key/mask/mcam_id/enable. */
2411 : : int
2412 [ # # ]: 0 : cnxk_flow_async_actions_update(struct rte_eth_dev *eth_dev, uint32_t queue,
2413 : : const struct rte_flow_op_attr *attr, struct rte_flow *flow,
2414 : : const struct rte_flow_action actions[],
2415 : : uint8_t action_template_index, void *user_data,
2416 : : struct rte_flow_error *error)
2417 : : {
2418 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2419 : : struct cnxk_flow_actions_template *at;
2420 : 0 : struct roc_npc *npc = &dev->npc;
2421 : : struct cnxk_flow_table *table;
2422 : :
2423 : 0 : uint64_t free_allocs[ROC_NPC_MAX_ACTION_COUNT + ROC_NPC_ITEM_TYPE_END + 1] = {0};
2424 : 0 : struct roc_npc_item_info in_pattern[ROC_NPC_ITEM_TYPE_END + 1] = {0};
2425 : : struct rte_flow_action combined_actions[ROC_NPC_MAX_ACTION_COUNT];
2426 : 0 : struct roc_npc_action in_actions[ROC_NPC_MAX_ACTION_COUNT] = {0};
2427 : 0 : struct roc_npc_action_sample in_sample = {0};
2428 : : struct rte_flow_item end_pattern[1];
2429 : : struct rte_flow_attr rte_attr;
2430 : : struct roc_npc_attr in_attr;
2431 : 0 : uint32_t flowkey_cfg = 0;
2432 : 0 : uint16_t dst_pf_func = 0;
2433 : 0 : uint64_t def_action = 0;
2434 : : uint16_t k;
2435 : : int rc, j;
2436 : :
2437 : : RTE_SET_USED(attr);
2438 : :
2439 [ # # ]: 0 : if (flow == NULL)
2440 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2441 : : "bad flow handle");
2442 : :
2443 : : /* Recover the cnxk table context from the cookie the engine kept for
2444 : : * this rule's table.
2445 : : */
2446 : 0 : table = roc_npc_async_flow_table_cookie((struct roc_npc_template_flow *)flow);
2447 [ # # ]: 0 : if (table == NULL)
2448 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
2449 : : "flow handle has no associated table");
2450 [ # # ]: 0 : if (action_template_index >= table->nb_actions_templates)
2451 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
2452 : : "actions template index out of range");
2453 : :
2454 [ # # ]: 0 : at = table->actions_templates[action_template_index];
2455 : :
2456 : : if (cnxk_flow_check_actions(at, actions) != 0)
2457 : 0 : return rte_flow_error_set(error, EINVAL, RTE_FLOW_ERROR_TYPE_ACTION, NULL,
2458 : : "actions do not match the selected template");
2459 : :
2460 [ # # ]: 0 : for (k = 0; k < at->nb_actions; k++) {
2461 : 0 : combined_actions[k].type = at->actions[k].type;
2462 : 0 : combined_actions[k].conf =
2463 [ # # # # ]: 0 : (actions && actions[k].conf) ? actions[k].conf : at->actions[k].conf;
2464 : : }
2465 : 0 : combined_actions[at->nb_actions].type = RTE_FLOW_ACTION_TYPE_END;
2466 : :
2467 : 0 : end_pattern[0].type = RTE_FLOW_ITEM_TYPE_END;
2468 : :
2469 : : memset(&rte_attr, 0, sizeof(rte_attr));
2470 : 0 : rte_attr.priority = table->flow_attr.priority;
2471 : 0 : rte_attr.ingress = table->flow_attr.ingress;
2472 : 0 : rte_attr.egress = table->flow_attr.egress;
2473 : 0 : rte_attr.transfer = table->transfer;
2474 : :
2475 : : memset(&in_attr, 0, sizeof(in_attr));
2476 : 0 : rc = cnxk_map_flow_data(eth_dev, &rte_attr, end_pattern, combined_actions, &in_attr,
2477 : : in_pattern, in_actions, &in_sample, &flowkey_cfg, &dst_pf_func,
2478 : : &def_action, false, free_allocs, 0);
2479 [ # # ]: 0 : if (rc == 0)
2480 : : /* clang-format off */
2481 : 0 : rc = roc_npc_async_flow_actions_update(npc, queue,
2482 : : (struct roc_npc_template_flow *)flow, in_actions, user_data);
2483 : : /* clang-format on */
2484 : :
2485 [ # # # # ]: 0 : for (j = 0; j < (int)RTE_DIM(free_allocs) && free_allocs[j]; j++)
2486 : 0 : plt_free((void *)free_allocs[j]);
2487 : :
2488 [ # # ]: 0 : if (rc != 0)
2489 [ # # ]: 0 : return rte_flow_error_set(error, rc < 0 ? -rc : EINVAL, RTE_FLOW_ERROR_TYPE_ACTION,
2490 : : NULL, "failed to update flow actions");
2491 : :
2492 : : return 0;
2493 : : }
2494 : :
2495 : : static int
2496 : 0 : cnxk_flow_dev_dump(struct rte_eth_dev *eth_dev, struct rte_flow *flow, FILE *file,
2497 : : struct rte_flow_error *error)
2498 : : {
2499 : 0 : return cnxk_flow_dev_dump_common(eth_dev, flow, file, error, false);
2500 : : }
2501 : :
2502 : : static int
2503 [ # # ]: 0 : cnxk_flow_get_aged_flows(struct rte_eth_dev *eth_dev, void **context, uint32_t nb_contexts,
2504 : : struct rte_flow_error *err)
2505 : : {
2506 : : struct cnxk_eth_dev *dev = cnxk_eth_pmd_priv(eth_dev);
2507 : 0 : struct roc_npc *roc_npc = &dev->npc;
2508 : : struct roc_npc_flow_age *flow_age;
2509 : : uint32_t start_id;
2510 : : uint32_t end_id;
2511 : : int cnt = 0;
2512 : : uint32_t sn;
2513 : : uint32_t i;
2514 : :
2515 : : RTE_SET_USED(err);
2516 : :
2517 : : flow_age = &roc_npc->flow_age;
2518 : :
2519 [ # # ]: 0 : if (!flow_age->age_flow_refcnt)
2520 : : return 0;
2521 : :
2522 : : do {
2523 : : sn = plt_seqcount_read_begin(&flow_age->seq_cnt);
2524 : :
2525 [ # # ]: 0 : if (nb_contexts == 0) {
2526 : 0 : cnt = flow_age->aged_flows_cnt;
2527 : : } else {
2528 : 0 : start_id = flow_age->start_id;
2529 : 0 : end_id = flow_age->end_id;
2530 [ # # ]: 0 : for (i = start_id; i <= end_id; i++) {
2531 [ # # ]: 0 : if ((int)nb_contexts == cnt)
2532 : : break;
2533 [ # # ]: 0 : if (plt_bitmap_get(flow_age->aged_flows, i)) {
2534 : 0 : context[cnt] =
2535 : 0 : roc_npc_aged_flow_ctx_get(roc_npc, i);
2536 : 0 : cnt++;
2537 : : }
2538 : : }
2539 : : }
2540 [ # # ]: 0 : } while (plt_seqcount_read_retry(&flow_age->seq_cnt, sn));
2541 : :
2542 : : return cnt;
2543 : : }
2544 : :
2545 : : static int
2546 : 0 : cnxk_flow_tunnel_decap_set(__rte_unused struct rte_eth_dev *dev, struct rte_flow_tunnel *tunnel,
2547 : : struct rte_flow_action **pmd_actions, uint32_t *num_of_actions,
2548 : : __rte_unused struct rte_flow_error *err)
2549 : : {
2550 : : struct rte_flow_action *nfp_action;
2551 : :
2552 : 0 : nfp_action = rte_zmalloc("nfp_tun_action", sizeof(struct rte_flow_action), 0);
2553 [ # # ]: 0 : if (nfp_action == NULL) {
2554 : 0 : plt_err("Alloc memory for nfp tunnel action failed.");
2555 : 0 : return -ENOMEM;
2556 : : }
2557 : :
2558 [ # # ]: 0 : if (tunnel->is_ipv6)
2559 : 0 : nfp_action->conf = (void *)~0;
2560 : :
2561 [ # # ]: 0 : switch (tunnel->type) {
2562 : 0 : case RTE_FLOW_ITEM_TYPE_VXLAN:
2563 : 0 : nfp_action->type = RTE_FLOW_ACTION_TYPE_VXLAN_DECAP;
2564 : 0 : *pmd_actions = nfp_action;
2565 : 0 : *num_of_actions = 1;
2566 : 0 : break;
2567 : 0 : default:
2568 : 0 : *pmd_actions = NULL;
2569 : 0 : *num_of_actions = 0;
2570 : 0 : rte_free(nfp_action);
2571 : 0 : break;
2572 : : }
2573 : :
2574 : : return 0;
2575 : : }
2576 : :
2577 : : static int
2578 : 0 : cnxk_flow_tunnel_action_decap_release(__rte_unused struct rte_eth_dev *dev,
2579 : : struct rte_flow_action *pmd_actions, uint32_t num_of_actions,
2580 : : __rte_unused struct rte_flow_error *err)
2581 : : {
2582 : : uint32_t i;
2583 : : struct rte_flow_action *nfp_action;
2584 : :
2585 [ # # ]: 0 : for (i = 0; i < num_of_actions; i++) {
2586 : 0 : nfp_action = &pmd_actions[i];
2587 : 0 : nfp_action->conf = NULL;
2588 : 0 : rte_free(nfp_action);
2589 : : }
2590 : :
2591 : 0 : return 0;
2592 : : }
2593 : :
2594 : : static int
2595 : 0 : cnxk_flow_tunnel_match(__rte_unused struct rte_eth_dev *dev,
2596 : : __rte_unused struct rte_flow_tunnel *tunnel,
2597 : : __rte_unused struct rte_flow_item **pmd_items, uint32_t *num_of_items,
2598 : : __rte_unused struct rte_flow_error *err)
2599 : : {
2600 : 0 : *num_of_items = 0;
2601 : :
2602 : 0 : return 0;
2603 : : }
2604 : :
2605 : : static int
2606 : 0 : cnxk_flow_tunnel_item_release(__rte_unused struct rte_eth_dev *dev,
2607 : : __rte_unused struct rte_flow_item *pmd_items,
2608 : : __rte_unused uint32_t num_of_items,
2609 : : __rte_unused struct rte_flow_error *err)
2610 : : {
2611 : 0 : return 0;
2612 : : }
2613 : :
2614 : : struct rte_flow_ops cnxk_flow_ops = {
2615 : : .validate = cnxk_flow_validate,
2616 : : .flush = cnxk_flow_flush,
2617 : : .query = cnxk_flow_query,
2618 : : .isolate = cnxk_flow_isolate,
2619 : : .dev_dump = cnxk_flow_dev_dump,
2620 : : .get_aged_flows = cnxk_flow_get_aged_flows,
2621 : : .tunnel_match = cnxk_flow_tunnel_match,
2622 : : .tunnel_item_release = cnxk_flow_tunnel_item_release,
2623 : : .tunnel_decap_set = cnxk_flow_tunnel_decap_set,
2624 : : .tunnel_action_decap_release = cnxk_flow_tunnel_action_decap_release,
2625 : : };
|