On 09/06, Yahui Cao wrote: >Add ice_create_fdir_filter to create a rule. If a flow is matched by >flow director filter, filter rule will be set to HW. Only basic pattern >and queue/passthru/drop are supported.
Only basic patterns and queue/passthru/drop actions are supported? > >Add ice_destroy_fdir_filter to destroy a rule. If a flow is created >before, filter rule will be removed from HW. > >Signed-off-by: Yahui Cao <yahui....@intel.com> >--- > drivers/net/ice/ice_ethdev.h | 6 + > drivers/net/ice/ice_fdir_filter.c | 508 ++++++++++++++++++++++++++++++ > 2 files changed, 514 insertions(+) > >diff --git a/drivers/net/ice/ice_ethdev.h b/drivers/net/ice/ice_ethdev.h >index ea68858d1..bb821bc41 100644 >--- a/drivers/net/ice/ice_ethdev.h >+++ b/drivers/net/ice/ice_ethdev.h >@@ -249,6 +249,11 @@ TAILQ_HEAD(ice_flow_list, rte_flow); > struct ice_flow_parser; > TAILQ_HEAD(ice_parser_list, ice_flow_parser); > >+struct ice_fdir_filter_conf { >+ struct ice_fdir_fltr input; >+ uint64_t input_set; >+}; >+ > /** > * A structure used to define fields of a FDIR related info. > */ >@@ -258,6 +263,7 @@ struct ice_fdir_info { > struct ice_rx_queue *rxq; > void *prg_pkt; /* memory for fdir program packet */ > uint64_t dma_addr; /* physic address of packet memory*/ >+ struct ice_fdir_filter_conf conf; > }; > > struct ice_pf { >diff --git a/drivers/net/ice/ice_fdir_filter.c >b/drivers/net/ice/ice_fdir_filter.c >index 0840c3b4b..98bc1be49 100644 >--- a/drivers/net/ice/ice_fdir_filter.c >+++ b/drivers/net/ice/ice_fdir_filter.c >@@ -7,6 +7,51 @@ > #include "ice_rxtx.h" > #include "ice_generic_flow.h" > >+#define ICE_FDIR_INSET_ETH_IPV4 (\ >+ ICE_INSET_IPV4_SRC | ICE_INSET_IPV4_DST | ICE_INSET_IPV4_TOS | \ >+ ICE_INSET_IPV4_TTL | ICE_INSET_IPV4_PROTO) >+ >+#define ICE_FDIR_INSET_ETH_IPV4_UDP (\ >+ ICE_FDIR_INSET_ETH_IPV4 | \ >+ ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT) >+ >+#define ICE_FDIR_INSET_ETH_IPV4_TCP (\ >+ ICE_FDIR_INSET_ETH_IPV4 | \ >+ ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT) >+ >+#define ICE_FDIR_INSET_ETH_IPV4_SCTP (\ >+ ICE_FDIR_INSET_ETH_IPV4 | \ >+ ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT) >+ >+#define ICE_FDIR_INSET_ETH_IPV6 (\ >+ ICE_INSET_IPV6_SRC | ICE_INSET_IPV6_DST | ICE_INSET_IPV6_TC | \ >+ ICE_INSET_IPV6_HOP_LIMIT | ICE_INSET_IPV6_NEXT_HDR) >+ >+#define ICE_FDIR_INSET_ETH_IPV6_UDP (\ >+ ICE_FDIR_INSET_ETH_IPV6 | \ >+ ICE_INSET_UDP_SRC_PORT | ICE_INSET_UDP_DST_PORT) >+ >+#define ICE_FDIR_INSET_ETH_IPV6_TCP (\ >+ ICE_FDIR_INSET_ETH_IPV6 | \ >+ ICE_INSET_TCP_SRC_PORT | ICE_INSET_TCP_DST_PORT) >+ >+#define ICE_FDIR_INSET_ETH_IPV6_SCTP (\ >+ ICE_FDIR_INSET_ETH_IPV6 | \ >+ ICE_INSET_SCTP_SRC_PORT | ICE_INSET_SCTP_DST_PORT) >+ >+static struct ice_pattern_match_item ice_fdir_pattern[] = { >+ {pattern_eth_ipv4, ICE_FDIR_INSET_ETH_IPV4, >ICE_INSET_NONE}, >+ {pattern_eth_ipv4_udp, ICE_FDIR_INSET_ETH_IPV4_UDP, >ICE_INSET_NONE}, >+ {pattern_eth_ipv4_tcp, ICE_FDIR_INSET_ETH_IPV4_TCP, >ICE_INSET_NONE}, >+ {pattern_eth_ipv4_sctp, ICE_FDIR_INSET_ETH_IPV4_SCTP, >ICE_INSET_NONE}, >+ {pattern_eth_ipv6, ICE_FDIR_INSET_ETH_IPV6, >ICE_INSET_NONE}, >+ {pattern_eth_ipv6_udp, ICE_FDIR_INSET_ETH_IPV6_UDP, >ICE_INSET_NONE}, >+ {pattern_eth_ipv6_tcp, ICE_FDIR_INSET_ETH_IPV6_TCP, >ICE_INSET_NONE}, >+ {pattern_eth_ipv6_sctp, ICE_FDIR_INSET_ETH_IPV6_SCTP, >ICE_INSET_NONE}, >+}; >+ >+static struct ice_flow_parser ice_fdir_parser; >+ > static const struct rte_memzone * > ice_memzone_reserve(const char *name, uint32_t len, int socket_id) > { >@@ -400,6 +445,10 @@ ice_init_fdir_filter(struct ice_adapter *ad) > int ret; > > ret = ice_fdir_setup(pf); >+ if (ret) >+ return ret; >+ >+ ret = ice_register_parser(&ice_fdir_parser, ad); > > return ret; return ice_register_parser(&ice_fdir_parser, ad); > } >@@ -409,15 +458,474 @@ ice_uninit_fdir_filter(struct ice_adapter *ad) > { > struct ice_pf *pf = &ad->pf; > >+ ice_unregister_parser(&ice_fdir_parser, ad); >+ > ice_fdir_teardown(pf); > } > >+static int >+ice_add_del_fdir_filter(struct ice_pf *pf, >+ struct ice_fdir_filter_conf *filter, >+ bool add) >+{ >+ struct ice_fltr_desc desc; >+ struct ice_hw *hw = ICE_PF_TO_HW(pf); >+ unsigned char *pkt = (unsigned char *)pf->fdir.prg_pkt; >+ int ret = 0; >+ >+ memset(&desc, 0, sizeof(desc)); >+ ice_fdir_get_prgm_desc(hw, &filter->input, &desc, add); >+ >+ memset(pkt, 0, ICE_FDIR_PKT_LEN); >+ ret = ice_fdir_get_prgm_pkt(&filter->input, pkt, false); >+ if (ret) { >+ PMD_DRV_LOG(ERR, "Generate dummy packet failed"); >+ return -EINVAL; >+ } >+ >+ ret = ice_fdir_programming(pf, &desc); >+ if (ret) >+ return ret; >+ >+ return 0; return ice_fdir_programming(pf, &desc); >+} >+ >+static int >+ice_create_fdir_filter(struct ice_adapter *ad, >+ struct rte_flow *flow, >+ void *meta, >+ struct rte_flow_error *error) >+{ >+ struct ice_pf *pf = &ad->pf; >+ struct ice_hw *hw = ICE_PF_TO_HW(pf); >+ struct ice_fdir_filter_conf *filter = meta; >+ struct ice_fdir_filter_conf *rule; >+ int ret = 0; Unnecessary initialization for ret. Thanks, Xiaolong