1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(C) 2019 Marvell International Ltd.
5 #include "otx2_ethdev.h"
8 const struct rte_flow_item *
9 otx2_flow_skip_void_and_any_items(const struct rte_flow_item *pattern)
11 while ((pattern->type == RTE_FLOW_ITEM_TYPE_VOID) ||
12 (pattern->type == RTE_FLOW_ITEM_TYPE_ANY))
19 * Tunnel+ESP, Tunnel+ICMP4/6, Tunnel+TCP, Tunnel+UDP,
23 otx2_flow_parse_lh(struct otx2_parse_state *pst)
25 struct otx2_flow_item_info info;
33 info.hw_mask = &hw_mask;
39 switch (pst->pattern->type) {
40 case RTE_FLOW_ITEM_TYPE_UDP:
41 lt = NPC_LT_LH_TU_UDP;
42 info.def_mask = &rte_flow_item_udp_mask;
43 info.len = sizeof(struct rte_flow_item_udp);
45 case RTE_FLOW_ITEM_TYPE_TCP:
46 lt = NPC_LT_LH_TU_TCP;
47 info.def_mask = &rte_flow_item_tcp_mask;
48 info.len = sizeof(struct rte_flow_item_tcp);
50 case RTE_FLOW_ITEM_TYPE_SCTP:
51 lt = NPC_LT_LH_TU_SCTP;
52 info.def_mask = &rte_flow_item_sctp_mask;
53 info.len = sizeof(struct rte_flow_item_sctp);
55 case RTE_FLOW_ITEM_TYPE_ESP:
56 lt = NPC_LT_LH_TU_ESP;
57 info.def_mask = &rte_flow_item_esp_mask;
58 info.len = sizeof(struct rte_flow_item_esp);
64 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
65 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
69 return otx2_flow_update_parse_state(pst, &info, lid, lt, 0);
72 /* Tunnel+IPv4, Tunnel+IPv6 */
74 otx2_flow_parse_lg(struct otx2_parse_state *pst)
76 struct otx2_flow_item_info info;
84 info.hw_mask = &hw_mask;
90 if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_IPV4) {
92 info.def_mask = &rte_flow_item_ipv4_mask;
93 info.len = sizeof(struct rte_flow_item_ipv4);
94 } else if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_IPV6) {
95 lt = NPC_LT_LG_TU_IP6;
96 info.def_mask = &rte_flow_item_ipv6_mask;
97 info.len = sizeof(struct rte_flow_item_ipv6);
99 /* There is no tunneled IP header */
103 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
104 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
108 return otx2_flow_update_parse_state(pst, &info, lid, lt, 0);
113 otx2_flow_parse_lf(struct otx2_parse_state *pst)
115 const struct rte_flow_item *pattern, *last_pattern;
116 struct rte_flow_item_eth hw_mask;
117 struct otx2_flow_item_info info;
122 /* We hit this layer if there is a tunneling protocol */
126 if (pst->pattern->type != RTE_FLOW_ITEM_TYPE_ETH)
130 lt = NPC_LT_LF_TU_ETHER;
133 info.def_mask = &rte_flow_item_vlan_mask;
134 /* No match support for vlan tags */
136 info.len = sizeof(struct rte_flow_item_vlan);
141 /* Look ahead and find out any VLAN tags. These can be
142 * detected but no data matching is available.
144 last_pattern = pst->pattern;
145 pattern = pst->pattern + 1;
146 pattern = otx2_flow_skip_void_and_any_items(pattern);
147 while (pattern->type == RTE_FLOW_ITEM_TYPE_VLAN) {
149 rc = otx2_flow_parse_item_basic(pattern, &info, pst->error);
152 last_pattern = pattern;
154 pattern = otx2_flow_skip_void_and_any_items(pattern);
156 otx2_npc_dbg("Nr_vlans = %d", nr_vlans);
161 lflags = NPC_F_TU_ETHER_CTAG;
164 lflags = NPC_F_TU_ETHER_STAG_CTAG;
167 rte_flow_error_set(pst->error, ENOTSUP,
168 RTE_FLOW_ERROR_TYPE_ITEM,
170 "more than 2 vlans with tunneled Ethernet "
175 info.def_mask = &rte_flow_item_eth_mask;
176 info.hw_mask = &hw_mask;
177 info.len = sizeof(struct rte_flow_item_eth);
179 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
183 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
187 pst->pattern = last_pattern;
189 return otx2_flow_update_parse_state(pst, &info, lid, lt, lflags);
193 otx2_flow_parse_le(struct otx2_parse_state *pst)
196 * We are positioned at UDP. Scan ahead and look for
197 * UDP encapsulated tunnel protocols. If available,
198 * parse them. In that case handle this:
199 * - RTE spec assumes we point to tunnel header.
200 * - NPC parser provides offset from UDP header.
204 * Note: Add support to GENEVE, VXLAN_GPE when we
207 * Note: Better to split flags into two nibbles:
208 * - Higher nibble can have flags
209 * - Lower nibble to further enumerate protocols
210 * and have flags based extraction
212 const struct rte_flow_item *pattern = pst->pattern;
213 struct otx2_flow_item_info info;
221 if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_MPLS)
222 return otx2_flow_parse_mpls(pst, NPC_LID_LE);
227 info.def_mask = NULL;
233 /* Ensure we are not matching anything in UDP */
234 rc = otx2_flow_parse_item_basic(pattern, &info, pst->error);
238 info.hw_mask = &hw_mask;
239 pattern = otx2_flow_skip_void_and_any_items(pattern);
240 otx2_npc_dbg("Pattern->type = %d", pattern->type);
241 switch (pattern->type) {
242 case RTE_FLOW_ITEM_TYPE_VXLAN:
243 lflags = NPC_F_UDP_VXLAN;
244 info.def_mask = &rte_flow_item_vxlan_mask;
245 info.len = sizeof(struct rte_flow_item_vxlan);
246 lt = NPC_LT_LE_VXLAN;
248 case RTE_FLOW_ITEM_TYPE_ESP:
250 info.def_mask = &rte_flow_item_esp_mask;
251 info.len = sizeof(struct rte_flow_item_esp);
253 case RTE_FLOW_ITEM_TYPE_GTPC:
254 lflags = NPC_F_UDP_GTP_GTPC;
255 info.def_mask = &rte_flow_item_gtp_mask;
256 info.len = sizeof(struct rte_flow_item_gtp);
259 case RTE_FLOW_ITEM_TYPE_GTPU:
260 lflags = NPC_F_UDP_GTP_GTPU_G_PDU;
261 info.def_mask = &rte_flow_item_gtp_mask;
262 info.len = sizeof(struct rte_flow_item_gtp);
265 case RTE_FLOW_ITEM_TYPE_GENEVE:
266 lflags = NPC_F_UDP_GENEVE;
267 info.def_mask = &rte_flow_item_geneve_mask;
268 info.len = sizeof(struct rte_flow_item_geneve);
269 lt = NPC_LT_LE_GENEVE;
271 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
272 lflags = NPC_F_UDP_VXLANGPE;
273 info.def_mask = &rte_flow_item_vxlan_gpe_mask;
274 info.len = sizeof(struct rte_flow_item_vxlan_gpe);
275 lt = NPC_LT_LE_VXLANGPE;
283 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
284 rc = otx2_flow_parse_item_basic(pattern, &info, pst->error);
288 return otx2_flow_update_parse_state(pst, &info, lid, lt, lflags);
292 flow_parse_mpls_label_stack(struct otx2_parse_state *pst, int *flag)
295 const struct rte_flow_item *pattern = pst->pattern;
296 struct otx2_flow_item_info info;
298 uint8_t flag_list[] = {0, NPC_F_MPLS_2_LABELS,
299 NPC_F_MPLS_3_LABELS, NPC_F_MPLS_4_LABELS};
302 * pst->pattern points to first MPLS label. We only check
303 * that subsequent labels do not have anything to match.
305 info.def_mask = &rte_flow_item_mpls_mask;
307 info.len = sizeof(struct rte_flow_item_mpls);
312 while (pattern->type == RTE_FLOW_ITEM_TYPE_MPLS) {
315 /* Basic validation of 2nd/3rd/4th mpls item */
317 rc = otx2_flow_parse_item_basic(pattern, &info,
322 pst->last_pattern = pattern;
324 pattern = otx2_flow_skip_void_and_any_items(pattern);
328 rte_flow_error_set(pst->error, ENOTSUP,
329 RTE_FLOW_ERROR_TYPE_ITEM,
331 "more than 4 mpls labels not supported");
335 *flag = flag_list[nr_labels - 1];
340 otx2_flow_parse_mpls(struct otx2_parse_state *pst, int lid)
342 /* Find number of MPLS labels */
343 struct rte_flow_item_mpls hw_mask;
344 struct otx2_flow_item_info info;
350 if (lid == NPC_LID_LC)
352 else if (lid == NPC_LID_LD)
353 lt = NPC_LT_LD_TU_MPLS_IN_IP;
355 lt = NPC_LT_LE_TU_MPLS_IN_UDP;
357 /* Prepare for parsing the first item */
358 info.def_mask = &rte_flow_item_mpls_mask;
359 info.hw_mask = &hw_mask;
360 info.len = sizeof(struct rte_flow_item_mpls);
365 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
366 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
371 * Parse for more labels.
372 * This sets lflags and pst->last_pattern correctly.
374 rc = flow_parse_mpls_label_stack(pst, &lflags);
379 pst->pattern = pst->last_pattern;
381 return otx2_flow_update_parse_state(pst, &info, lid, lt, lflags);
385 * ICMP, ICMP6, UDP, TCP, SCTP, VXLAN, GRE, NVGRE,
386 * GTP, GTPC, GTPU, ESP
388 * Note: UDP tunnel protocols are identified by flags.
389 * LPTR for these protocol still points to UDP
390 * header. Need flag based extraction to support
394 otx2_flow_parse_ld(struct otx2_parse_state *pst)
396 char hw_mask[NPC_MAX_EXTRACT_DATA_LEN];
397 uint32_t gre_key_mask = 0xffffffff;
398 struct otx2_flow_item_info info;
403 /* We have already parsed MPLS or IPv4/v6 followed
404 * by MPLS or IPv4/v6. Subsequent TCP/UDP etc
405 * would be parsed as tunneled versions. Skip
406 * this layer, except for tunneled MPLS. If LC is
407 * MPLS, we have anyway skipped all stacked MPLS
410 if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_MPLS)
411 return otx2_flow_parse_mpls(pst, NPC_LID_LD);
414 info.hw_mask = &hw_mask;
417 info.def_mask = NULL;
424 otx2_npc_dbg("Pst->pattern->type = %d", pst->pattern->type);
425 switch (pst->pattern->type) {
426 case RTE_FLOW_ITEM_TYPE_ICMP:
427 if (pst->lt[NPC_LID_LC] == NPC_LT_LC_IP6)
428 lt = NPC_LT_LD_ICMP6;
431 info.def_mask = &rte_flow_item_icmp_mask;
432 info.len = sizeof(struct rte_flow_item_icmp);
434 case RTE_FLOW_ITEM_TYPE_UDP:
436 info.def_mask = &rte_flow_item_udp_mask;
437 info.len = sizeof(struct rte_flow_item_udp);
439 case RTE_FLOW_ITEM_TYPE_TCP:
441 info.def_mask = &rte_flow_item_tcp_mask;
442 info.len = sizeof(struct rte_flow_item_tcp);
444 case RTE_FLOW_ITEM_TYPE_SCTP:
446 info.def_mask = &rte_flow_item_sctp_mask;
447 info.len = sizeof(struct rte_flow_item_sctp);
449 case RTE_FLOW_ITEM_TYPE_GRE:
451 info.def_mask = &rte_flow_item_gre_mask;
452 info.len = sizeof(struct rte_flow_item_gre);
454 case RTE_FLOW_ITEM_TYPE_GRE_KEY:
456 info.def_mask = &gre_key_mask;
457 info.len = sizeof(gre_key_mask);
460 case RTE_FLOW_ITEM_TYPE_NVGRE:
461 lt = NPC_LT_LD_NVGRE;
462 lflags = NPC_F_GRE_NVGRE;
463 info.def_mask = &rte_flow_item_nvgre_mask;
464 info.len = sizeof(struct rte_flow_item_nvgre);
465 /* Further IP/Ethernet are parsed as tunneled */
472 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
473 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
477 return otx2_flow_update_parse_state(pst, &info, lid, lt, lflags);
481 flow_check_lc_ip_tunnel(struct otx2_parse_state *pst)
483 const struct rte_flow_item *pattern = pst->pattern + 1;
485 pattern = otx2_flow_skip_void_and_any_items(pattern);
486 if (pattern->type == RTE_FLOW_ITEM_TYPE_MPLS ||
487 pattern->type == RTE_FLOW_ITEM_TYPE_IPV4 ||
488 pattern->type == RTE_FLOW_ITEM_TYPE_IPV6)
492 /* Outer IPv4, Outer IPv6, MPLS, ARP */
494 otx2_flow_parse_lc(struct otx2_parse_state *pst)
496 uint8_t hw_mask[NPC_MAX_EXTRACT_DATA_LEN];
497 struct otx2_flow_item_info info;
501 if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_MPLS)
502 return otx2_flow_parse_mpls(pst, NPC_LID_LC);
504 info.hw_mask = &hw_mask;
510 switch (pst->pattern->type) {
511 case RTE_FLOW_ITEM_TYPE_IPV4:
513 info.def_mask = &rte_flow_item_ipv4_mask;
514 info.len = sizeof(struct rte_flow_item_ipv4);
516 case RTE_FLOW_ITEM_TYPE_IPV6:
519 info.def_mask = &rte_flow_item_ipv6_mask;
520 info.len = sizeof(struct rte_flow_item_ipv6);
522 case RTE_FLOW_ITEM_TYPE_ARP_ETH_IPV4:
524 info.def_mask = &rte_flow_item_arp_eth_ipv4_mask;
525 info.len = sizeof(struct rte_flow_item_arp_eth_ipv4);
527 case RTE_FLOW_ITEM_TYPE_IPV6_EXT:
529 lt = NPC_LT_LC_IP6_EXT;
530 info.def_mask = &rte_flow_item_ipv6_ext_mask;
531 info.len = sizeof(struct rte_flow_item_ipv6_ext);
532 info.hw_hdr_len = 40;
535 /* No match at this layer */
539 /* Identify if IP tunnels MPLS or IPv4/v6 */
540 flow_check_lc_ip_tunnel(pst);
542 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
543 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
547 return otx2_flow_update_parse_state(pst, &info, lid, lt, 0);
552 otx2_flow_parse_lb(struct otx2_parse_state *pst)
554 const struct rte_flow_item *pattern = pst->pattern;
555 const struct rte_flow_item *last_pattern;
556 char hw_mask[NPC_MAX_EXTRACT_DATA_LEN];
557 struct otx2_flow_item_info info;
564 info.hw_hdr_len = NPC_TPID_LENGTH;
568 last_pattern = pattern;
570 if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_VLAN) {
571 /* RTE vlan is either 802.1q or 802.1ad,
572 * this maps to either CTAG/STAG. We need to decide
573 * based on number of VLANS present. Matching is
574 * supported on first tag only.
576 info.def_mask = &rte_flow_item_vlan_mask;
578 info.len = sizeof(struct rte_flow_item_vlan);
580 pattern = pst->pattern;
581 while (pattern->type == RTE_FLOW_ITEM_TYPE_VLAN) {
584 /* Basic validation of 2nd/3rd vlan item */
586 otx2_npc_dbg("Vlans = %d", nr_vlans);
587 rc = otx2_flow_parse_item_basic(pattern, &info,
592 last_pattern = pattern;
594 pattern = otx2_flow_skip_void_and_any_items(pattern);
602 lt = NPC_LT_LB_STAG_QINQ;
603 lflags = NPC_F_STAG_CTAG;
606 lt = NPC_LT_LB_STAG_QINQ;
607 lflags = NPC_F_STAG_STAG_CTAG;
610 rte_flow_error_set(pst->error, ENOTSUP,
611 RTE_FLOW_ERROR_TYPE_ITEM,
613 "more than 3 vlans not supported");
616 } else if (pst->pattern->type == RTE_FLOW_ITEM_TYPE_E_TAG) {
617 /* we can support ETAG and match a subsequent CTAG
618 * without any matching support.
623 last_pattern = pst->pattern;
624 pattern = otx2_flow_skip_void_and_any_items(pst->pattern + 1);
625 if (pattern->type == RTE_FLOW_ITEM_TYPE_VLAN) {
626 info.def_mask = &rte_flow_item_vlan_mask;
627 /* set supported mask to NULL for vlan tag */
629 info.len = sizeof(struct rte_flow_item_vlan);
630 rc = otx2_flow_parse_item_basic(pattern, &info,
635 lflags = NPC_F_ETAG_CTAG;
636 last_pattern = pattern;
639 info.def_mask = &rte_flow_item_e_tag_mask;
640 info.len = sizeof(struct rte_flow_item_e_tag);
645 info.hw_mask = &hw_mask;
648 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
650 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
654 /* Point pattern to last item consumed */
655 pst->pattern = last_pattern;
656 return otx2_flow_update_parse_state(pst, &info, lid, lt, lflags);
660 otx2_flow_parse_la(struct otx2_parse_state *pst)
662 struct rte_flow_item_eth hw_mask;
663 struct otx2_flow_item_info info;
667 /* Identify the pattern type into lid, lt */
668 if (pst->pattern->type != RTE_FLOW_ITEM_TYPE_ETH)
672 lt = NPC_LT_LA_ETHER;
675 if (pst->flow->nix_intf == NIX_INTF_TX) {
676 lt = NPC_LT_LA_IH_NIX_ETHER;
677 info.hw_hdr_len = NPC_IH_LENGTH;
678 if (pst->npc->switch_header_type == OTX2_PRIV_FLAGS_HIGIG) {
679 lt = NPC_LT_LA_IH_NIX_HIGIG2_ETHER;
680 info.hw_hdr_len += NPC_HIGIG2_LENGTH;
683 if (pst->npc->switch_header_type == OTX2_PRIV_FLAGS_HIGIG) {
684 lt = NPC_LT_LA_HIGIG2_ETHER;
685 info.hw_hdr_len = NPC_HIGIG2_LENGTH;
689 /* Prepare for parsing the item */
690 info.def_mask = &rte_flow_item_eth_mask;
691 info.hw_mask = &hw_mask;
692 info.len = sizeof(struct rte_flow_item_eth);
693 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
697 /* Basic validation of item parameters */
698 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
702 /* Update pst if not validate only? clash check? */
703 return otx2_flow_update_parse_state(pst, &info, lid, lt, 0);
707 otx2_flow_parse_higig2_hdr(struct otx2_parse_state *pst)
709 struct rte_flow_item_higig2_hdr hw_mask;
710 struct otx2_flow_item_info info;
714 /* Identify the pattern type into lid, lt */
715 if (pst->pattern->type != RTE_FLOW_ITEM_TYPE_HIGIG2)
719 lt = NPC_LT_LA_HIGIG2_ETHER;
722 if (pst->flow->nix_intf == NIX_INTF_TX) {
723 lt = NPC_LT_LA_IH_NIX_HIGIG2_ETHER;
724 info.hw_hdr_len = NPC_IH_LENGTH;
727 /* Prepare for parsing the item */
728 info.def_mask = &rte_flow_item_higig2_hdr_mask;
729 info.hw_mask = &hw_mask;
730 info.len = sizeof(struct rte_flow_item_higig2_hdr);
731 otx2_flow_get_hw_supp_mask(pst, &info, lid, lt);
735 /* Basic validation of item parameters */
736 rc = otx2_flow_parse_item_basic(pst->pattern, &info, pst->error);
740 /* Update pst if not validate only? clash check? */
741 return otx2_flow_update_parse_state(pst, &info, lid, lt, 0);
745 parse_rss_action(struct rte_eth_dev *dev,
746 const struct rte_flow_attr *attr,
747 const struct rte_flow_action *act,
748 struct rte_flow_error *error)
750 struct otx2_eth_dev *hw = dev->data->dev_private;
751 struct otx2_rss_info *rss_info = &hw->rss_info;
752 const struct rte_flow_action_rss *rss;
755 rss = (const struct rte_flow_action_rss *)act->conf;
759 return rte_flow_error_set(error, EINVAL,
760 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
761 attr, "No support of RSS in egress");
764 if (dev->data->dev_conf.rxmode.mq_mode != ETH_MQ_RX_RSS)
765 return rte_flow_error_set(error, ENOTSUP,
766 RTE_FLOW_ERROR_TYPE_ACTION,
767 act, "multi-queue mode is disabled");
769 /* Parse RSS related parameters from configuration */
770 if (!rss || !rss->queue_num)
771 return rte_flow_error_set(error, EINVAL,
772 RTE_FLOW_ERROR_TYPE_ACTION,
773 act, "no valid queues");
775 if (rss->func != RTE_ETH_HASH_FUNCTION_DEFAULT)
776 return rte_flow_error_set(error, ENOTSUP,
777 RTE_FLOW_ERROR_TYPE_ACTION, act,
778 "non-default RSS hash functions"
779 " are not supported");
781 if (rss->key_len && rss->key_len > RTE_DIM(rss_info->key))
782 return rte_flow_error_set(error, ENOTSUP,
783 RTE_FLOW_ERROR_TYPE_ACTION, act,
784 "RSS hash key too large");
786 if (rss->queue_num > rss_info->rss_size)
787 return rte_flow_error_set
788 (error, ENOTSUP, RTE_FLOW_ERROR_TYPE_ACTION, act,
789 "too many queues for RSS context");
791 for (i = 0; i < rss->queue_num; i++) {
792 if (rss->queue[i] >= dev->data->nb_rx_queues)
793 return rte_flow_error_set(error, EINVAL,
794 RTE_FLOW_ERROR_TYPE_ACTION,
796 "queue id > max number"
804 otx2_flow_parse_actions(struct rte_eth_dev *dev,
805 const struct rte_flow_attr *attr,
806 const struct rte_flow_action actions[],
807 struct rte_flow_error *error,
808 struct rte_flow *flow)
810 struct otx2_eth_dev *hw = dev->data->dev_private;
811 struct otx2_npc_flow_info *npc = &hw->npc_flow;
812 const struct rte_flow_action_count *act_count;
813 const struct rte_flow_action_mark *act_mark;
814 const struct rte_flow_action_queue *act_q;
815 const struct rte_flow_action_vf *vf_act;
816 bool vlan_insert_action = false;
817 const char *errmsg = NULL;
818 int sel_act, req_act = 0;
819 uint16_t pf_func, vf_id;
824 /* Initialize actions */
825 flow->ctr_id = NPC_COUNTER_NONE;
826 pf_func = otx2_pfvf_func(hw->pf, hw->vf);
828 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
829 otx2_npc_dbg("Action type = %d", actions->type);
831 switch (actions->type) {
832 case RTE_FLOW_ACTION_TYPE_VOID:
834 case RTE_FLOW_ACTION_TYPE_MARK:
836 (const struct rte_flow_action_mark *)actions->conf;
838 /* We have only 16 bits. Use highest val for flag */
839 if (act_mark->id > (OTX2_FLOW_FLAG_VAL - 2)) {
840 errmsg = "mark value must be < 0xfffe";
844 mark = act_mark->id + 1;
845 req_act |= OTX2_FLOW_ACT_MARK;
846 rte_atomic32_inc(&npc->mark_actions);
849 case RTE_FLOW_ACTION_TYPE_FLAG:
850 mark = OTX2_FLOW_FLAG_VAL;
851 req_act |= OTX2_FLOW_ACT_FLAG;
852 rte_atomic32_inc(&npc->mark_actions);
855 case RTE_FLOW_ACTION_TYPE_COUNT:
857 (const struct rte_flow_action_count *)
860 if (act_count->shared == 1) {
861 errmsg = "Shared Counters not supported";
865 /* Indicates, need a counter */
867 req_act |= OTX2_FLOW_ACT_COUNT;
870 case RTE_FLOW_ACTION_TYPE_DROP:
871 req_act |= OTX2_FLOW_ACT_DROP;
874 case RTE_FLOW_ACTION_TYPE_PF:
875 req_act |= OTX2_FLOW_ACT_PF;
879 case RTE_FLOW_ACTION_TYPE_VF:
880 vf_act = (const struct rte_flow_action_vf *)
882 req_act |= OTX2_FLOW_ACT_VF;
883 if (vf_act->original == 0) {
884 vf_id = vf_act->id & RVU_PFVF_FUNC_MASK;
885 if (vf_id >= hw->maxvf) {
886 errmsg = "invalid vf specified";
891 pf_func = (pf_func | (vf_id + 1));
895 case RTE_FLOW_ACTION_TYPE_QUEUE:
896 /* Applicable only to ingress flow */
897 act_q = (const struct rte_flow_action_queue *)
900 if (rq >= dev->data->nb_rx_queues) {
901 errmsg = "invalid queue index";
905 req_act |= OTX2_FLOW_ACT_QUEUE;
908 case RTE_FLOW_ACTION_TYPE_RSS:
909 errcode = parse_rss_action(dev, attr, actions, error);
913 req_act |= OTX2_FLOW_ACT_RSS;
916 case RTE_FLOW_ACTION_TYPE_SECURITY:
917 /* Assumes user has already configured security
918 * session for this flow. Associated conf is
919 * opaque. When RTE security is implemented for otx2,
920 * we need to verify that for specified security
923 * RTE_SECURITY_ACTION_TYPE_INLINE_PROTOCOL &&
924 * session_protocol ==
925 * RTE_SECURITY_PROTOCOL_IPSEC
927 * RSS is not supported with inline ipsec. Get the
928 * rq from associated conf, or make
929 * RTE_FLOW_ACTION_TYPE_QUEUE compulsory with this
931 * Currently, rq = 0 is assumed.
933 req_act |= OTX2_FLOW_ACT_SEC;
936 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_VID:
937 req_act |= OTX2_FLOW_ACT_VLAN_INSERT;
939 case RTE_FLOW_ACTION_TYPE_OF_POP_VLAN:
940 req_act |= OTX2_FLOW_ACT_VLAN_STRIP;
942 case RTE_FLOW_ACTION_TYPE_OF_PUSH_VLAN:
943 req_act |= OTX2_FLOW_ACT_VLAN_ETHTYPE_INSERT;
945 case RTE_FLOW_ACTION_TYPE_OF_SET_VLAN_PCP:
946 req_act |= OTX2_FLOW_ACT_VLAN_PCP_INSERT;
949 errmsg = "Unsupported action specified";
956 (OTX2_FLOW_ACT_VLAN_INSERT | OTX2_FLOW_ACT_VLAN_ETHTYPE_INSERT |
957 OTX2_FLOW_ACT_VLAN_PCP_INSERT))
958 vlan_insert_action = true;
961 (OTX2_FLOW_ACT_VLAN_INSERT | OTX2_FLOW_ACT_VLAN_ETHTYPE_INSERT |
962 OTX2_FLOW_ACT_VLAN_PCP_INSERT)) ==
963 OTX2_FLOW_ACT_VLAN_PCP_INSERT) {
964 errmsg = " PCP insert action can't be supported alone";
969 /* Both STRIP and INSERT actions are not supported */
970 if (vlan_insert_action && (req_act & OTX2_FLOW_ACT_VLAN_STRIP)) {
971 errmsg = "Both VLAN insert and strip actions not supported"
977 /* Check if actions specified are compatible */
979 if (req_act & OTX2_FLOW_ACT_VLAN_STRIP) {
980 errmsg = "VLAN pop action is not supported on Egress";
985 if (req_act & OTX2_FLOW_ACT_DROP) {
986 flow->npc_action = NIX_TX_ACTIONOP_DROP;
987 } else if ((req_act & OTX2_FLOW_ACT_COUNT) ||
988 vlan_insert_action) {
989 flow->npc_action = NIX_TX_ACTIONOP_UCAST_DEFAULT;
991 errmsg = "Unsupported action for egress";
998 /* We have already verified the attr, this is ingress.
999 * - Exactly one terminating action is supported
1000 * - Exactly one of MARK or FLAG is supported
1001 * - If terminating action is DROP, only count is valid.
1003 sel_act = req_act & OTX2_FLOW_ACT_TERM;
1004 if ((sel_act & (sel_act - 1)) != 0) {
1005 errmsg = "Only one terminating action supported";
1010 if (req_act & OTX2_FLOW_ACT_DROP) {
1011 sel_act = req_act & ~OTX2_FLOW_ACT_COUNT;
1012 if ((sel_act & (sel_act - 1)) != 0) {
1013 errmsg = "Only COUNT action is supported "
1014 "with DROP ingress action";
1020 if ((req_act & (OTX2_FLOW_ACT_FLAG | OTX2_FLOW_ACT_MARK))
1021 == (OTX2_FLOW_ACT_FLAG | OTX2_FLOW_ACT_MARK)) {
1022 errmsg = "Only one of FLAG or MARK action is supported";
1027 if (vlan_insert_action) {
1028 errmsg = "VLAN push/Insert action is not supported on Ingress";
1033 if (req_act & OTX2_FLOW_ACT_VLAN_STRIP)
1034 npc->vtag_actions++;
1036 /* Only VLAN action is provided */
1037 if (req_act == OTX2_FLOW_ACT_VLAN_STRIP)
1038 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1039 /* Set NIX_RX_ACTIONOP */
1040 else if (req_act & (OTX2_FLOW_ACT_PF | OTX2_FLOW_ACT_VF)) {
1041 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1042 if (req_act & OTX2_FLOW_ACT_QUEUE)
1043 flow->npc_action |= (uint64_t)rq << 20;
1044 } else if (req_act & OTX2_FLOW_ACT_DROP) {
1045 flow->npc_action = NIX_RX_ACTIONOP_DROP;
1046 } else if (req_act & OTX2_FLOW_ACT_QUEUE) {
1047 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1048 flow->npc_action |= (uint64_t)rq << 20;
1049 } else if (req_act & OTX2_FLOW_ACT_RSS) {
1050 /* When user added a rule for rss, first we will add the
1051 *rule in MCAM and then update the action, once if we have
1052 *FLOW_KEY_ALG index. So, till we update the action with
1053 *flow_key_alg index, set the action to drop.
1055 if (dev->data->dev_conf.rxmode.mq_mode == ETH_MQ_RX_RSS)
1056 flow->npc_action = NIX_RX_ACTIONOP_DROP;
1058 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1059 } else if (req_act & OTX2_FLOW_ACT_SEC) {
1060 flow->npc_action = NIX_RX_ACTIONOP_UCAST_IPSEC;
1061 flow->npc_action |= (uint64_t)rq << 20;
1062 } else if (req_act & (OTX2_FLOW_ACT_FLAG | OTX2_FLOW_ACT_MARK)) {
1063 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1064 } else if (req_act & OTX2_FLOW_ACT_COUNT) {
1065 /* Keep OTX2_FLOW_ACT_COUNT always at the end
1066 * This is default action, when user specify only
1069 flow->npc_action = NIX_RX_ACTIONOP_UCAST;
1071 /* Should never reach here */
1072 errmsg = "Invalid action specified";
1078 flow->npc_action |= (uint64_t)mark << 40;
1080 if (rte_atomic32_read(&npc->mark_actions) == 1) {
1081 hw->rx_offload_flags |=
1082 NIX_RX_OFFLOAD_MARK_UPDATE_F;
1083 otx2_eth_set_rx_function(dev);
1086 if (npc->vtag_actions == 1) {
1087 hw->rx_offload_flags |= NIX_RX_OFFLOAD_VLAN_STRIP_F;
1088 otx2_eth_set_rx_function(dev);
1092 /* Ideally AF must ensure that correct pf_func is set */
1094 flow->npc_action |= (uint64_t)pf_func << 48;
1096 flow->npc_action |= (uint64_t)pf_func << 4;
1101 rte_flow_error_set(error, errcode,
1102 RTE_FLOW_ERROR_TYPE_ACTION_NUM, NULL,