Instead of N-tuple filter RTE flow API should be used.
Preserve struct rte_eth_ntuple_filter in ethdev API since
the structure and related defines are used in flow classify
library and a number of drivers.
Preserve RTE_ETH_FILTER_NTUPLE because of usage in drivers.
Signed-off-by: Andrew Rybchenko <arybchenko@solarflare.com>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>
Acked-by: Haiyue Wang <haiyue.wang@intel.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
"filters:\n"
"--------\n\n"
- "2tuple_filter (port_id) (add|del)"
- " dst_port (dst_port_value) protocol (protocol_value)"
- " mask (mask_value) tcp_flags (tcp_flags_value)"
- " priority (prio_value) queue (queue_id)\n"
- " Add/Del a 2tuple filter.\n\n"
-
- "5tuple_filter (port_id) (add|del)"
- " dst_ip (dst_address) src_ip (src_address)"
- " dst_port (dst_port_value) src_port (src_port_value)"
- " protocol (protocol_value)"
- " mask (mask_value) tcp_flags (tcp_flags_value)"
- " priority (prio_value) queue (queue_id)\n"
- " Add/Del a 5tuple filter.\n\n"
-
"flow_director_filter (port_id) mode IP (add|del|update)"
" flow (ipv4-other|ipv4-frag|ipv6-other|ipv6-frag)"
" src (src_ip_address) dst (dst_ip_address)"
},
};
-/* *** ADD/REMOVE A 2tuple FILTER *** */
-struct cmd_2tuple_filter_result {
- cmdline_fixed_string_t filter;
- portid_t port_id;
- cmdline_fixed_string_t ops;
- cmdline_fixed_string_t dst_port;
- uint16_t dst_port_value;
- cmdline_fixed_string_t protocol;
- uint8_t protocol_value;
- cmdline_fixed_string_t mask;
- uint8_t mask_value;
- cmdline_fixed_string_t tcp_flags;
- uint8_t tcp_flags_value;
- cmdline_fixed_string_t priority;
- uint8_t priority_value;
- cmdline_fixed_string_t queue;
- uint16_t queue_id;
-};
-
-static void
-cmd_2tuple_filter_parsed(void *parsed_result,
- __rte_unused struct cmdline *cl,
- __rte_unused void *data)
-{
- struct rte_eth_ntuple_filter filter;
- struct cmd_2tuple_filter_result *res = parsed_result;
- int ret = 0;
-
- ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
- if (ret < 0) {
- printf("ntuple filter is not supported on port %u.\n",
- res->port_id);
- return;
- }
-
- memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
-
- filter.flags = RTE_2TUPLE_FLAGS;
- filter.dst_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
- filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
- filter.proto = res->protocol_value;
- filter.priority = res->priority_value;
- if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
- printf("nonzero tcp_flags is only meaningful"
- " when protocol is TCP.\n");
- return;
- }
- if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
- printf("invalid TCP flags.\n");
- return;
- }
-
- if (res->tcp_flags_value != 0) {
- filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
- filter.tcp_flags = res->tcp_flags_value;
- }
-
- /* need convert to big endian. */
- filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
- filter.queue = res->queue_id;
-
- if (!strcmp(res->ops, "add"))
- ret = rte_eth_dev_filter_ctrl(res->port_id,
- RTE_ETH_FILTER_NTUPLE,
- RTE_ETH_FILTER_ADD,
- &filter);
- else
- ret = rte_eth_dev_filter_ctrl(res->port_id,
- RTE_ETH_FILTER_NTUPLE,
- RTE_ETH_FILTER_DELETE,
- &filter);
- if (ret < 0)
- printf("2tuple filter programming error: (%s)\n",
- strerror(-ret));
-
-}
-
-cmdline_parse_token_string_t cmd_2tuple_filter_filter =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- filter, "2tuple_filter");
-cmdline_parse_token_num_t cmd_2tuple_filter_port_id =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- port_id, UINT16);
-cmdline_parse_token_string_t cmd_2tuple_filter_ops =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- ops, "add#del");
-cmdline_parse_token_string_t cmd_2tuple_filter_dst_port =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- dst_port, "dst_port");
-cmdline_parse_token_num_t cmd_2tuple_filter_dst_port_value =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- dst_port_value, UINT16);
-cmdline_parse_token_string_t cmd_2tuple_filter_protocol =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- protocol, "protocol");
-cmdline_parse_token_num_t cmd_2tuple_filter_protocol_value =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- protocol_value, UINT8);
-cmdline_parse_token_string_t cmd_2tuple_filter_mask =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- mask, "mask");
-cmdline_parse_token_num_t cmd_2tuple_filter_mask_value =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- mask_value, INT8);
-cmdline_parse_token_string_t cmd_2tuple_filter_tcp_flags =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- tcp_flags, "tcp_flags");
-cmdline_parse_token_num_t cmd_2tuple_filter_tcp_flags_value =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- tcp_flags_value, UINT8);
-cmdline_parse_token_string_t cmd_2tuple_filter_priority =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- priority, "priority");
-cmdline_parse_token_num_t cmd_2tuple_filter_priority_value =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- priority_value, UINT8);
-cmdline_parse_token_string_t cmd_2tuple_filter_queue =
- TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result,
- queue, "queue");
-cmdline_parse_token_num_t cmd_2tuple_filter_queue_id =
- TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result,
- queue_id, UINT16);
-
-cmdline_parse_inst_t cmd_2tuple_filter = {
- .f = cmd_2tuple_filter_parsed,
- .data = NULL,
- .help_str = "2tuple_filter <port_id> add|del dst_port <value> protocol "
- "<value> mask <value> tcp_flags <value> priority <value> queue "
- "<queue_id>: Add a 2tuple filter",
- .tokens = {
- (void *)&cmd_2tuple_filter_filter,
- (void *)&cmd_2tuple_filter_port_id,
- (void *)&cmd_2tuple_filter_ops,
- (void *)&cmd_2tuple_filter_dst_port,
- (void *)&cmd_2tuple_filter_dst_port_value,
- (void *)&cmd_2tuple_filter_protocol,
- (void *)&cmd_2tuple_filter_protocol_value,
- (void *)&cmd_2tuple_filter_mask,
- (void *)&cmd_2tuple_filter_mask_value,
- (void *)&cmd_2tuple_filter_tcp_flags,
- (void *)&cmd_2tuple_filter_tcp_flags_value,
- (void *)&cmd_2tuple_filter_priority,
- (void *)&cmd_2tuple_filter_priority_value,
- (void *)&cmd_2tuple_filter_queue,
- (void *)&cmd_2tuple_filter_queue_id,
- NULL,
- },
-};
-
-/* *** ADD/REMOVE A 5tuple FILTER *** */
-struct cmd_5tuple_filter_result {
- cmdline_fixed_string_t filter;
- portid_t port_id;
- cmdline_fixed_string_t ops;
- cmdline_fixed_string_t dst_ip;
- cmdline_ipaddr_t dst_ip_value;
- cmdline_fixed_string_t src_ip;
- cmdline_ipaddr_t src_ip_value;
- cmdline_fixed_string_t dst_port;
- uint16_t dst_port_value;
- cmdline_fixed_string_t src_port;
- uint16_t src_port_value;
- cmdline_fixed_string_t protocol;
- uint8_t protocol_value;
- cmdline_fixed_string_t mask;
- uint8_t mask_value;
- cmdline_fixed_string_t tcp_flags;
- uint8_t tcp_flags_value;
- cmdline_fixed_string_t priority;
- uint8_t priority_value;
- cmdline_fixed_string_t queue;
- uint16_t queue_id;
-};
-
-static void
-cmd_5tuple_filter_parsed(void *parsed_result,
- __rte_unused struct cmdline *cl,
- __rte_unused void *data)
-{
- struct rte_eth_ntuple_filter filter;
- struct cmd_5tuple_filter_result *res = parsed_result;
- int ret = 0;
-
- ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_NTUPLE);
- if (ret < 0) {
- printf("ntuple filter is not supported on port %u.\n",
- res->port_id);
- return;
- }
-
- memset(&filter, 0, sizeof(struct rte_eth_ntuple_filter));
-
- filter.flags = RTE_5TUPLE_FLAGS;
- filter.dst_ip_mask = (res->mask_value & 0x10) ? UINT32_MAX : 0;
- filter.src_ip_mask = (res->mask_value & 0x08) ? UINT32_MAX : 0;
- filter.dst_port_mask = (res->mask_value & 0x04) ? UINT16_MAX : 0;
- filter.src_port_mask = (res->mask_value & 0x02) ? UINT16_MAX : 0;
- filter.proto_mask = (res->mask_value & 0x01) ? UINT8_MAX : 0;
- filter.proto = res->protocol_value;
- filter.priority = res->priority_value;
- if (res->tcp_flags_value != 0 && filter.proto != IPPROTO_TCP) {
- printf("nonzero tcp_flags is only meaningful"
- " when protocol is TCP.\n");
- return;
- }
- if (res->tcp_flags_value > RTE_NTUPLE_TCP_FLAGS_MASK) {
- printf("invalid TCP flags.\n");
- return;
- }
-
- if (res->tcp_flags_value != 0) {
- filter.flags |= RTE_NTUPLE_FLAGS_TCP_FLAG;
- filter.tcp_flags = res->tcp_flags_value;
- }
-
- if (res->dst_ip_value.family == AF_INET)
- /* no need to convert, already big endian. */
- filter.dst_ip = res->dst_ip_value.addr.ipv4.s_addr;
- else {
- if (filter.dst_ip_mask == 0) {
- printf("can not support ipv6 involved compare.\n");
- return;
- }
- filter.dst_ip = 0;
- }
-
- if (res->src_ip_value.family == AF_INET)
- /* no need to convert, already big endian. */
- filter.src_ip = res->src_ip_value.addr.ipv4.s_addr;
- else {
- if (filter.src_ip_mask == 0) {
- printf("can not support ipv6 involved compare.\n");
- return;
- }
- filter.src_ip = 0;
- }
- /* need convert to big endian. */
- filter.dst_port = rte_cpu_to_be_16(res->dst_port_value);
- filter.src_port = rte_cpu_to_be_16(res->src_port_value);
- filter.queue = res->queue_id;
-
- if (!strcmp(res->ops, "add"))
- ret = rte_eth_dev_filter_ctrl(res->port_id,
- RTE_ETH_FILTER_NTUPLE,
- RTE_ETH_FILTER_ADD,
- &filter);
- else
- ret = rte_eth_dev_filter_ctrl(res->port_id,
- RTE_ETH_FILTER_NTUPLE,
- RTE_ETH_FILTER_DELETE,
- &filter);
- if (ret < 0)
- printf("5tuple filter programming error: (%s)\n",
- strerror(-ret));
-}
-
-cmdline_parse_token_string_t cmd_5tuple_filter_filter =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- filter, "5tuple_filter");
-cmdline_parse_token_num_t cmd_5tuple_filter_port_id =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- port_id, UINT16);
-cmdline_parse_token_string_t cmd_5tuple_filter_ops =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- ops, "add#del");
-cmdline_parse_token_string_t cmd_5tuple_filter_dst_ip =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- dst_ip, "dst_ip");
-cmdline_parse_token_ipaddr_t cmd_5tuple_filter_dst_ip_value =
- TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
- dst_ip_value);
-cmdline_parse_token_string_t cmd_5tuple_filter_src_ip =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- src_ip, "src_ip");
-cmdline_parse_token_ipaddr_t cmd_5tuple_filter_src_ip_value =
- TOKEN_IPADDR_INITIALIZER(struct cmd_5tuple_filter_result,
- src_ip_value);
-cmdline_parse_token_string_t cmd_5tuple_filter_dst_port =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- dst_port, "dst_port");
-cmdline_parse_token_num_t cmd_5tuple_filter_dst_port_value =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- dst_port_value, UINT16);
-cmdline_parse_token_string_t cmd_5tuple_filter_src_port =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- src_port, "src_port");
-cmdline_parse_token_num_t cmd_5tuple_filter_src_port_value =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- src_port_value, UINT16);
-cmdline_parse_token_string_t cmd_5tuple_filter_protocol =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- protocol, "protocol");
-cmdline_parse_token_num_t cmd_5tuple_filter_protocol_value =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- protocol_value, UINT8);
-cmdline_parse_token_string_t cmd_5tuple_filter_mask =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- mask, "mask");
-cmdline_parse_token_num_t cmd_5tuple_filter_mask_value =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- mask_value, INT8);
-cmdline_parse_token_string_t cmd_5tuple_filter_tcp_flags =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- tcp_flags, "tcp_flags");
-cmdline_parse_token_num_t cmd_5tuple_filter_tcp_flags_value =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- tcp_flags_value, UINT8);
-cmdline_parse_token_string_t cmd_5tuple_filter_priority =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- priority, "priority");
-cmdline_parse_token_num_t cmd_5tuple_filter_priority_value =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- priority_value, UINT8);
-cmdline_parse_token_string_t cmd_5tuple_filter_queue =
- TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result,
- queue, "queue");
-cmdline_parse_token_num_t cmd_5tuple_filter_queue_id =
- TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result,
- queue_id, UINT16);
-
-cmdline_parse_inst_t cmd_5tuple_filter = {
- .f = cmd_5tuple_filter_parsed,
- .data = NULL,
- .help_str = "5tuple_filter <port_id> add|del dst_ip <value> "
- "src_ip <value> dst_port <value> src_port <value> "
- "protocol <value> mask <value> tcp_flags <value> "
- "priority <value> queue <queue_id>: Add/Del a 5tuple filter",
- .tokens = {
- (void *)&cmd_5tuple_filter_filter,
- (void *)&cmd_5tuple_filter_port_id,
- (void *)&cmd_5tuple_filter_ops,
- (void *)&cmd_5tuple_filter_dst_ip,
- (void *)&cmd_5tuple_filter_dst_ip_value,
- (void *)&cmd_5tuple_filter_src_ip,
- (void *)&cmd_5tuple_filter_src_ip_value,
- (void *)&cmd_5tuple_filter_dst_port,
- (void *)&cmd_5tuple_filter_dst_port_value,
- (void *)&cmd_5tuple_filter_src_port,
- (void *)&cmd_5tuple_filter_src_port_value,
- (void *)&cmd_5tuple_filter_protocol,
- (void *)&cmd_5tuple_filter_protocol_value,
- (void *)&cmd_5tuple_filter_mask,
- (void *)&cmd_5tuple_filter_mask_value,
- (void *)&cmd_5tuple_filter_tcp_flags,
- (void *)&cmd_5tuple_filter_tcp_flags_value,
- (void *)&cmd_5tuple_filter_priority,
- (void *)&cmd_5tuple_filter_priority_value,
- (void *)&cmd_5tuple_filter_queue,
- (void *)&cmd_5tuple_filter_queue_id,
- NULL,
- },
-};
-
/* *** Filters Control *** */
/* *** deal with flow director filter *** */
(cmdline_parse_inst_t *)&cmd_config_rss_hash_key,
(cmdline_parse_inst_t *)&cmd_dump,
(cmdline_parse_inst_t *)&cmd_dump_one,
- (cmdline_parse_inst_t *)&cmd_2tuple_filter,
- (cmdline_parse_inst_t *)&cmd_5tuple_filter,
(cmdline_parse_inst_t *)&cmd_add_del_ip_flow_director,
(cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director,
(cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director,
* ethdev: the legacy filter API, including
``rte_eth_dev_filter_supported()``, ``rte_eth_dev_filter_ctrl()`` as well
- as filter types NTUPLE, TUNNEL, FDIR,
+ as filter types TUNNEL, FDIR,
HASH and L2_TUNNEL, is superseded by the generic flow API (rte_flow) in
PMDs that implement the latter.
The legacy API will be removed in DPDK 20.11.
Note these functions interface the deprecated legacy filtering framework,
superseded by *rte_flow*. See `Flow rules management`_.
-2tuple_filter
-~~~~~~~~~~~~~~~~~
-
-Add or delete a 2-tuple filter,
-which identifies packets by specific protocol and destination TCP/UDP port
-and forwards packets into one of the receive queues::
-
- 2tuple_filter (port_id) (add|del) dst_port (dst_port_value) \
- protocol (protocol_value) mask (mask_value) \
- tcp_flags (tcp_flags_value) priority (prio_value) \
- queue (queue_id)
-
-The available information parameters are:
-
-* ``port_id``: The port which the 2-tuple filter assigned on.
-
-* ``dst_port_value``: Destination port in L4.
-
-* ``protocol_value``: IP L4 protocol.
-
-* ``mask_value``: Participates in the match or not by bit for field above, 1b means participate.
-
-* ``tcp_flags_value``: TCP control bits. The non-zero value is invalid, when the pro_value is not set to 0x06 (TCP).
-
-* ``prio_value``: Priority of this filter.
-
-* ``queue_id``: The receive queue associated with this 2-tuple filter.
-
-Example, to add/remove an 2tuple filter rule::
-
- testpmd> 2tuple_filter 0 add dst_port 32 protocol 0x06 mask 0x03 \
- tcp_flags 0x02 priority 3 queue 3
-
- testpmd> 2tuple_filter 0 del dst_port 32 protocol 0x06 mask 0x03 \
- tcp_flags 0x02 priority 3 queue 3
-
-5tuple_filter
-~~~~~~~~~~~~~~~~~
-
-Add or delete a 5-tuple filter,
-which consists of a 5-tuple (protocol, source and destination IP addresses, source and destination TCP/UDP/SCTP port)
-and routes packets into one of the receive queues::
-
- 5tuple_filter (port_id) (add|del) dst_ip (dst_address) src_ip \
- (src_address) dst_port (dst_port_value) \
- src_port (src_port_value) protocol (protocol_value) \
- mask (mask_value) tcp_flags (tcp_flags_value) \
- priority (prio_value) queue (queue_id)
-
-The available information parameters are:
-
-* ``port_id``: The port which the 5-tuple filter assigned on.
-
-* ``dst_address``: Destination IP address.
-
-* ``src_address``: Source IP address.
-
-* ``dst_port_value``: TCP/UDP destination port.
-
-* ``src_port_value``: TCP/UDP source port.
-
-* ``protocol_value``: L4 protocol.
-
-* ``mask_value``: Participates in the match or not by bit for field above, 1b means participate
-
-* ``tcp_flags_value``: TCP control bits. The non-zero value is invalid, when the protocol_value is not set to 0x06 (TCP).
-
-* ``prio_value``: The priority of this filter.
-
-* ``queue_id``: The receive queue associated with this 5-tuple filter.
-
-Example, to add/remove an 5tuple filter rule::
-
- testpmd> 5tuple_filter 0 add dst_ip 2.2.2.5 src_ip 2.2.2.4 \
- dst_port 64 src_port 32 protocol 0x06 mask 0x1F \
- flags 0x0 priority 3 queue 3
-
- testpmd> 5tuple_filter 0 del dst_ip 2.2.2.5 src_ip 2.2.2.4 \
- dst_port 64 src_port 32 protocol 0x06 mask 0x1F \
- flags 0x0 priority 3 queue 3
-
.. _testpmd_flow_director:
flow_director_filter
return RTE_ETH_TX_DESC_FULL;
}
-static inline int
-parse_ntuple_filter(struct bnxt *bp,
- struct rte_eth_ntuple_filter *nfilter,
- struct bnxt_filter_info *bfilter)
-{
- uint32_t en = 0;
-
- if (nfilter->queue >= bp->rx_nr_rings) {
- PMD_DRV_LOG(ERR, "Invalid queue %d\n", nfilter->queue);
- return -EINVAL;
- }
-
- switch (nfilter->dst_port_mask) {
- case UINT16_MAX:
- bfilter->dst_port_mask = -1;
- bfilter->dst_port = nfilter->dst_port;
- en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT |
- NTUPLE_FLTR_ALLOC_INPUT_EN_DST_PORT_MASK;
- break;
- default:
- PMD_DRV_LOG(ERR, "invalid dst_port mask.");
- return -EINVAL;
- }
-
- bfilter->ip_addr_type = NTUPLE_FLTR_ALLOC_INPUT_IP_ADDR_TYPE_IPV4;
- en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
-
- switch (nfilter->proto_mask) {
- case UINT8_MAX:
- if (nfilter->proto == 17) /* IPPROTO_UDP */
- bfilter->ip_protocol = 17;
- else if (nfilter->proto == 6) /* IPPROTO_TCP */
- bfilter->ip_protocol = 6;
- else
- return -EINVAL;
- en |= NTUPLE_FLTR_ALLOC_IN_EN_IP_PROTO;
- break;
- default:
- PMD_DRV_LOG(ERR, "invalid protocol mask.");
- return -EINVAL;
- }
-
- switch (nfilter->dst_ip_mask) {
- case UINT32_MAX:
- bfilter->dst_ipaddr_mask[0] = -1;
- bfilter->dst_ipaddr[0] = nfilter->dst_ip;
- en |= NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR |
- NTUPLE_FLTR_ALLOC_INPUT_EN_DST_IPADDR_MASK;
- break;
- default:
- PMD_DRV_LOG(ERR, "invalid dst_ip mask.");
- return -EINVAL;
- }
-
- switch (nfilter->src_ip_mask) {
- case UINT32_MAX:
- bfilter->src_ipaddr_mask[0] = -1;
- bfilter->src_ipaddr[0] = nfilter->src_ip;
- en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR |
- NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_IPADDR_MASK;
- break;
- default:
- PMD_DRV_LOG(ERR, "invalid src_ip mask.");
- return -EINVAL;
- }
-
- switch (nfilter->src_port_mask) {
- case UINT16_MAX:
- bfilter->src_port_mask = -1;
- bfilter->src_port = nfilter->src_port;
- en |= NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT |
- NTUPLE_FLTR_ALLOC_INPUT_EN_SRC_PORT_MASK;
- break;
- default:
- PMD_DRV_LOG(ERR, "invalid src_port mask.");
- return -EINVAL;
- }
-
- bfilter->enables = en;
- return 0;
-}
-
-static struct bnxt_filter_info*
-bnxt_match_ntuple_filter(struct bnxt *bp,
- struct bnxt_filter_info *bfilter,
- struct bnxt_vnic_info **mvnic)
-{
- struct bnxt_filter_info *mfilter = NULL;
- int i;
-
- for (i = bp->nr_vnics - 1; i >= 0; i--) {
- struct bnxt_vnic_info *vnic = &bp->vnic_info[i];
- STAILQ_FOREACH(mfilter, &vnic->filter, next) {
- if (bfilter->src_ipaddr[0] == mfilter->src_ipaddr[0] &&
- bfilter->src_ipaddr_mask[0] ==
- mfilter->src_ipaddr_mask[0] &&
- bfilter->src_port == mfilter->src_port &&
- bfilter->src_port_mask == mfilter->src_port_mask &&
- bfilter->dst_ipaddr[0] == mfilter->dst_ipaddr[0] &&
- bfilter->dst_ipaddr_mask[0] ==
- mfilter->dst_ipaddr_mask[0] &&
- bfilter->dst_port == mfilter->dst_port &&
- bfilter->dst_port_mask == mfilter->dst_port_mask &&
- bfilter->flags == mfilter->flags &&
- bfilter->enables == mfilter->enables) {
- if (mvnic)
- *mvnic = vnic;
- return mfilter;
- }
- }
- }
- return NULL;
-}
-
-static int
-bnxt_cfg_ntuple_filter(struct bnxt *bp,
- struct rte_eth_ntuple_filter *nfilter,
- enum rte_filter_op filter_op)
-{
- struct bnxt_filter_info *bfilter, *mfilter, *filter1;
- struct bnxt_vnic_info *vnic, *vnic0, *mvnic;
- int ret;
-
- if (nfilter->flags != RTE_5TUPLE_FLAGS) {
- PMD_DRV_LOG(ERR, "only 5tuple is supported.");
- return -EINVAL;
- }
-
- if (nfilter->flags & RTE_NTUPLE_FLAGS_TCP_FLAG) {
- PMD_DRV_LOG(ERR, "Ntuple filter: TCP flags not supported\n");
- return -EINVAL;
- }
-
- bfilter = bnxt_get_unused_filter(bp);
- if (bfilter == NULL) {
- PMD_DRV_LOG(ERR,
- "Not enough resources for a new filter.\n");
- return -ENOMEM;
- }
- ret = parse_ntuple_filter(bp, nfilter, bfilter);
- if (ret < 0)
- goto free_filter;
-
- vnic = &bp->vnic_info[nfilter->queue];
- vnic0 = BNXT_GET_DEFAULT_VNIC(bp);
- filter1 = STAILQ_FIRST(&vnic0->filter);
- if (filter1 == NULL) {
- ret = -EINVAL;
- goto free_filter;
- }
-
- bfilter->dst_id = vnic->fw_vnic_id;
- bfilter->fw_l2_filter_id = filter1->fw_l2_filter_id;
- bfilter->enables |=
- HWRM_CFA_NTUPLE_FILTER_ALLOC_INPUT_ENABLES_L2_FILTER_ID;
- bfilter->ethertype = 0x800;
- bfilter->enables |= NTUPLE_FLTR_ALLOC_INPUT_EN_ETHERTYPE;
-
- mfilter = bnxt_match_ntuple_filter(bp, bfilter, &mvnic);
-
- if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
- bfilter->dst_id == mfilter->dst_id) {
- PMD_DRV_LOG(ERR, "filter exists.\n");
- ret = -EEXIST;
- goto free_filter;
- } else if (mfilter != NULL && filter_op == RTE_ETH_FILTER_ADD &&
- bfilter->dst_id != mfilter->dst_id) {
- mfilter->dst_id = vnic->fw_vnic_id;
- ret = bnxt_hwrm_set_ntuple_filter(bp, mfilter->dst_id, mfilter);
- STAILQ_REMOVE(&mvnic->filter, mfilter, bnxt_filter_info, next);
- STAILQ_INSERT_TAIL(&vnic->filter, mfilter, next);
- PMD_DRV_LOG(ERR, "filter with matching pattern exists.\n");
- PMD_DRV_LOG(ERR, " Updated it to the new destination queue\n");
- goto free_filter;
- }
- if (mfilter == NULL && filter_op == RTE_ETH_FILTER_DELETE) {
- PMD_DRV_LOG(ERR, "filter doesn't exist.");
- ret = -ENOENT;
- goto free_filter;
- }
-
- if (filter_op == RTE_ETH_FILTER_ADD) {
- bfilter->filter_type = HWRM_CFA_NTUPLE_FILTER;
- ret = bnxt_hwrm_set_ntuple_filter(bp, bfilter->dst_id, bfilter);
- if (ret)
- goto free_filter;
- STAILQ_INSERT_TAIL(&vnic->filter, bfilter, next);
- } else {
- if (mfilter == NULL) {
- /* This should not happen. But for Coverity! */
- ret = -ENOENT;
- goto free_filter;
- }
- ret = bnxt_hwrm_clear_ntuple_filter(bp, mfilter);
-
- STAILQ_REMOVE(&vnic->filter, mfilter, bnxt_filter_info, next);
- bnxt_free_filter(bp, mfilter);
- bnxt_free_filter(bp, bfilter);
- }
-
- return 0;
-free_filter:
- bnxt_free_filter(bp, bfilter);
- return ret;
-}
-
-static int
-bnxt_ntuple_filter(struct rte_eth_dev *dev,
- enum rte_filter_op filter_op,
- void *arg)
-{
- struct bnxt *bp = dev->data->dev_private;
- int ret;
-
- if (filter_op == RTE_ETH_FILTER_NOP)
- return 0;
-
- if (arg == NULL) {
- PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
- filter_op);
- return -EINVAL;
- }
-
- switch (filter_op) {
- case RTE_ETH_FILTER_ADD:
- ret = bnxt_cfg_ntuple_filter(bp,
- (struct rte_eth_ntuple_filter *)arg,
- filter_op);
- break;
- case RTE_ETH_FILTER_DELETE:
- ret = bnxt_cfg_ntuple_filter(bp,
- (struct rte_eth_ntuple_filter *)arg,
- filter_op);
- break;
- default:
- PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
- ret = -EINVAL;
- break;
- }
- return ret;
-}
-
static int
bnxt_parse_fdir_filter(struct bnxt *bp,
struct rte_eth_fdir_filter *fdir,
case RTE_ETH_FILTER_FDIR:
ret = bnxt_fdir_filter(dev, filter_op, arg);
break;
- case RTE_ETH_FILTER_NTUPLE:
- ret = bnxt_ntuple_filter(dev, filter_op, arg);
- break;
case RTE_ETH_FILTER_GENERIC:
if (filter_op != RTE_ETH_FILTER_GET)
return -EINVAL;
struct rte_eth_ntuple_filter *ntuple_filter);
static int igb_remove_5tuple_filter_82576(struct rte_eth_dev *dev,
struct rte_eth_ntuple_filter *ntuple_filter);
-static int igb_get_ntuple_filter(struct rte_eth_dev *dev,
- struct rte_eth_ntuple_filter *filter);
-static int igb_ntuple_filter_handle(struct rte_eth_dev *dev,
- enum rte_filter_op filter_op,
- void *arg);
static int eth_igb_filter_ctrl(struct rte_eth_dev *dev,
enum rte_filter_type filter_type,
enum rte_filter_op filter_op,
return ret;
}
-/*
- * igb_get_ntuple_filter - get a ntuple filter
- *
- * @param
- * dev: Pointer to struct rte_eth_dev.
- * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
- *
- * @return
- * - On success, zero.
- * - On failure, a negative value.
- */
-static int
-igb_get_ntuple_filter(struct rte_eth_dev *dev,
- struct rte_eth_ntuple_filter *ntuple_filter)
-{
- struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
- struct e1000_filter_info *filter_info =
- E1000_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
- struct e1000_5tuple_filter_info filter_5tuple;
- struct e1000_2tuple_filter_info filter_2tuple;
- struct e1000_5tuple_filter *p_5tuple_filter;
- struct e1000_2tuple_filter *p_2tuple_filter;
- int ret;
-
- switch (ntuple_filter->flags) {
- case RTE_5TUPLE_FLAGS:
- case (RTE_5TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
- if (hw->mac.type != e1000_82576)
- return -ENOTSUP;
- memset(&filter_5tuple,
- 0,
- sizeof(struct e1000_5tuple_filter_info));
- ret = ntuple_filter_to_5tuple_82576(ntuple_filter,
- &filter_5tuple);
- if (ret < 0)
- return ret;
- p_5tuple_filter = igb_5tuple_filter_lookup_82576(
- &filter_info->fivetuple_list,
- &filter_5tuple);
- if (p_5tuple_filter == NULL) {
- PMD_DRV_LOG(ERR, "filter doesn't exist.");
- return -ENOENT;
- }
- ntuple_filter->queue = p_5tuple_filter->queue;
- break;
- case RTE_2TUPLE_FLAGS:
- case (RTE_2TUPLE_FLAGS | RTE_NTUPLE_FLAGS_TCP_FLAG):
- if (hw->mac.type != e1000_82580 && hw->mac.type != e1000_i350)
- return -ENOTSUP;
- memset(&filter_2tuple,
- 0,
- sizeof(struct e1000_2tuple_filter_info));
- ret = ntuple_filter_to_2tuple(ntuple_filter, &filter_2tuple);
- if (ret < 0)
- return ret;
- p_2tuple_filter = igb_2tuple_filter_lookup(
- &filter_info->twotuple_list,
- &filter_2tuple);
- if (p_2tuple_filter == NULL) {
- PMD_DRV_LOG(ERR, "filter doesn't exist.");
- return -ENOENT;
- }
- ntuple_filter->queue = p_2tuple_filter->queue;
- break;
- default:
- ret = -EINVAL;
- break;
- }
-
- return 0;
-}
-
-/*
- * igb_ntuple_filter_handle - Handle operations for ntuple filter.
- * @dev: pointer to rte_eth_dev structure
- * @filter_op:operation will be taken.
- * @arg: a pointer to specific structure corresponding to the filter_op
- */
-static int
-igb_ntuple_filter_handle(struct rte_eth_dev *dev,
- enum rte_filter_op filter_op,
- void *arg)
-{
- struct e1000_hw *hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
- int ret;
-
- MAC_TYPE_FILTER_SUP(hw->mac.type);
-
- if (filter_op == RTE_ETH_FILTER_NOP)
- return 0;
-
- if (arg == NULL) {
- PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
- filter_op);
- return -EINVAL;
- }
-
- switch (filter_op) {
- case RTE_ETH_FILTER_ADD:
- ret = igb_add_del_ntuple_filter(dev,
- (struct rte_eth_ntuple_filter *)arg,
- TRUE);
- break;
- case RTE_ETH_FILTER_DELETE:
- ret = igb_add_del_ntuple_filter(dev,
- (struct rte_eth_ntuple_filter *)arg,
- FALSE);
- break;
- case RTE_ETH_FILTER_GET:
- ret = igb_get_ntuple_filter(dev,
- (struct rte_eth_ntuple_filter *)arg);
- break;
- default:
- PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
- ret = -EINVAL;
- break;
- }
- return ret;
-}
-
static inline int
igb_ethertype_filter_lookup(struct e1000_filter_info *filter_info,
uint16_t ethertype)
}
static int
-eth_igb_filter_ctrl(struct rte_eth_dev *dev,
+eth_igb_filter_ctrl(struct rte_eth_dev *dev __rte_unused,
enum rte_filter_type filter_type,
enum rte_filter_op filter_op,
void *arg)
int ret = 0;
switch (filter_type) {
- case RTE_ETH_FILTER_NTUPLE:
- ret = igb_ntuple_filter_handle(dev, filter_op, arg);
- break;
case RTE_ETH_FILTER_GENERIC:
if (filter_op != RTE_ETH_FILTER_GET)
return -EINVAL;
struct ixgbe_5tuple_filter *filter);
static void ixgbe_remove_5tuple_filter(struct rte_eth_dev *dev,
struct ixgbe_5tuple_filter *filter);
-static int ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
- enum rte_filter_op filter_op,
- void *arg);
-static int ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
- struct rte_eth_ntuple_filter *filter);
static int ixgbe_dev_filter_ctrl(struct rte_eth_dev *dev,
enum rte_filter_type filter_type,
enum rte_filter_op filter_op,
return 0;
}
-/*
- * get a ntuple filter
- *
- * @param
- * dev: Pointer to struct rte_eth_dev.
- * ntuple_filter: Pointer to struct rte_eth_ntuple_filter
- *
- * @return
- * - On success, zero.
- * - On failure, a negative value.
- */
-static int
-ixgbe_get_ntuple_filter(struct rte_eth_dev *dev,
- struct rte_eth_ntuple_filter *ntuple_filter)
-{
- struct ixgbe_filter_info *filter_info =
- IXGBE_DEV_PRIVATE_TO_FILTER_INFO(dev->data->dev_private);
- struct ixgbe_5tuple_filter_info filter_5tuple;
- struct ixgbe_5tuple_filter *filter;
- int ret;
-
- if (ntuple_filter->flags != RTE_5TUPLE_FLAGS) {
- PMD_DRV_LOG(ERR, "only 5tuple is supported.");
- return -EINVAL;
- }
-
- memset(&filter_5tuple, 0, sizeof(struct ixgbe_5tuple_filter_info));
- ret = ntuple_filter_to_5tuple(ntuple_filter, &filter_5tuple);
- if (ret < 0)
- return ret;
-
- filter = ixgbe_5tuple_filter_lookup(&filter_info->fivetuple_list,
- &filter_5tuple);
- if (filter == NULL) {
- PMD_DRV_LOG(ERR, "filter doesn't exist.");
- return -ENOENT;
- }
- ntuple_filter->queue = filter->queue;
- return 0;
-}
-
-/*
- * ixgbe_ntuple_filter_handle - Handle operations for ntuple filter.
- * @dev: pointer to rte_eth_dev structure
- * @filter_op:operation will be taken.
- * @arg: a pointer to specific structure corresponding to the filter_op
- *
- * @return
- * - On success, zero.
- * - On failure, a negative value.
- */
-static int
-ixgbe_ntuple_filter_handle(struct rte_eth_dev *dev,
- enum rte_filter_op filter_op,
- void *arg)
-{
- struct ixgbe_hw *hw = IXGBE_DEV_PRIVATE_TO_HW(dev->data->dev_private);
- int ret;
-
- MAC_TYPE_FILTER_SUP_EXT(hw->mac.type);
-
- if (filter_op == RTE_ETH_FILTER_NOP)
- return 0;
-
- if (arg == NULL) {
- PMD_DRV_LOG(ERR, "arg shouldn't be NULL for operation %u.",
- filter_op);
- return -EINVAL;
- }
-
- switch (filter_op) {
- case RTE_ETH_FILTER_ADD:
- ret = ixgbe_add_del_ntuple_filter(dev,
- (struct rte_eth_ntuple_filter *)arg,
- TRUE);
- break;
- case RTE_ETH_FILTER_DELETE:
- ret = ixgbe_add_del_ntuple_filter(dev,
- (struct rte_eth_ntuple_filter *)arg,
- FALSE);
- break;
- case RTE_ETH_FILTER_GET:
- ret = ixgbe_get_ntuple_filter(dev,
- (struct rte_eth_ntuple_filter *)arg);
- break;
- default:
- PMD_DRV_LOG(ERR, "unsupported operation %u.", filter_op);
- ret = -EINVAL;
- break;
- }
- return ret;
-}
-
int
ixgbe_add_del_ethertype_filter(struct rte_eth_dev *dev,
struct rte_eth_ethertype_filter *filter,
int ret = 0;
switch (filter_type) {
- case RTE_ETH_FILTER_NTUPLE:
- ret = ixgbe_ntuple_filter_handle(dev, filter_op, arg);
- break;
case RTE_ETH_FILTER_FDIR:
ret = ixgbe_fdir_ctrl_func(dev, filter_op, arg);
break;
return ret;
}
-int qede_ntuple_filter_conf(struct rte_eth_dev *eth_dev,
- enum rte_filter_op filter_op,
- void *arg)
-{
- struct qede_dev *qdev = QEDE_INIT_QDEV(eth_dev);
- struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
- struct rte_eth_ntuple_filter *ntuple;
- struct rte_eth_fdir_filter fdir_entry;
- struct rte_eth_tcpv4_flow *tcpv4_flow;
- struct rte_eth_udpv4_flow *udpv4_flow;
- bool add = false;
-
- switch (filter_op) {
- case RTE_ETH_FILTER_NOP:
- /* Typically used to query fdir support */
- if (ECORE_IS_CMT(edev)) {
- DP_ERR(edev, "flowdir is not supported in 100G mode\n");
- return -ENOTSUP;
- }
- return 0; /* means supported */
- case RTE_ETH_FILTER_ADD:
- add = true;
- break;
- case RTE_ETH_FILTER_DELETE:
- break;
- case RTE_ETH_FILTER_INFO:
- case RTE_ETH_FILTER_GET:
- case RTE_ETH_FILTER_UPDATE:
- case RTE_ETH_FILTER_FLUSH:
- case RTE_ETH_FILTER_SET:
- case RTE_ETH_FILTER_STATS:
- case RTE_ETH_FILTER_OP_MAX:
- DP_ERR(edev, "Unsupported filter_op %d\n", filter_op);
- return -ENOTSUP;
- }
- ntuple = (struct rte_eth_ntuple_filter *)arg;
- /* Internally convert ntuple to fdir entry */
- memset(&fdir_entry, 0, sizeof(fdir_entry));
- if (ntuple->proto == IPPROTO_TCP) {
- fdir_entry.input.flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_TCP;
- tcpv4_flow = &fdir_entry.input.flow.tcp4_flow;
- tcpv4_flow->ip.src_ip = ntuple->src_ip;
- tcpv4_flow->ip.dst_ip = ntuple->dst_ip;
- tcpv4_flow->ip.proto = IPPROTO_TCP;
- tcpv4_flow->src_port = ntuple->src_port;
- tcpv4_flow->dst_port = ntuple->dst_port;
- } else {
- fdir_entry.input.flow_type = RTE_ETH_FLOW_NONFRAG_IPV4_UDP;
- udpv4_flow = &fdir_entry.input.flow.udp4_flow;
- udpv4_flow->ip.src_ip = ntuple->src_ip;
- udpv4_flow->ip.dst_ip = ntuple->dst_ip;
- udpv4_flow->ip.proto = IPPROTO_TCP;
- udpv4_flow->src_port = ntuple->src_port;
- udpv4_flow->dst_port = ntuple->dst_port;
- }
-
- fdir_entry.action.rx_queue = ntuple->queue;
-
- return qede_config_cmn_fdir_filter(eth_dev, &fdir_entry, add);
-}
-
static int
qede_tunnel_update(struct qede_dev *qdev,
struct ecore_tunnel_info *tunn_info)
break;
case RTE_ETH_FILTER_FDIR:
return qede_fdir_filter_conf(eth_dev, filter_op, arg);
- case RTE_ETH_FILTER_NTUPLE:
- return qede_ntuple_filter_conf(eth_dev, filter_op, arg);
case RTE_ETH_FILTER_GENERIC:
if (ECORE_IS_CMT(edev)) {
DP_ERR(edev, "flowdir is not supported in 100G mode\n");
case RTE_ETH_FILTER_NONE:
sfc_err(sa, "Global filters configuration not supported");
break;
- case RTE_ETH_FILTER_NTUPLE:
- sfc_err(sa, "NTUPLE filters not supported");
- break;
case RTE_ETH_FILTER_TUNNEL:
sfc_err(sa, "Tunnel filters not supported");
break;
/**
* A structure used to define the ntuple filter entry
- * to support RTE_ETH_FILTER_NTUPLE with RTE_ETH_FILTER_ADD,
- * RTE_ETH_FILTER_DELETE and RTE_ETH_FILTER_GET operations.
+ * to support RTE_ETH_FILTER_NTUPLE data representation.
*/
struct rte_eth_ntuple_filter {
uint16_t flags; /**< Flags from RTE_NTUPLE_FLAGS_* */