1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2019 Hisilicon Limited.
5 #include <rte_flow_driver.h>
7 #include <rte_malloc.h>
9 #include "hns3_ethdev.h"
10 #include "hns3_logs.h"
12 /* Default default keys */
13 static uint8_t hns3_hash_key[] = {
14 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
15 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
16 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
17 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
18 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA
21 static const uint8_t full_mask[VNI_OR_TNI_LEN] = { 0xFF, 0xFF, 0xFF };
22 static const uint8_t zero_mask[VNI_OR_TNI_LEN] = { 0x00, 0x00, 0x00 };
24 /* Special Filter id for non-specific packet flagging. Don't change value */
25 #define HNS3_MAX_FILTER_ID 0x0FFF
27 #define ETHER_TYPE_MASK 0xFFFF
28 #define IPPROTO_MASK 0xFF
29 #define TUNNEL_TYPE_MASK 0xFFFF
31 #define HNS3_TUNNEL_TYPE_VXLAN 0x12B5
32 #define HNS3_TUNNEL_TYPE_VXLAN_GPE 0x12B6
33 #define HNS3_TUNNEL_TYPE_GENEVE 0x17C1
34 #define HNS3_TUNNEL_TYPE_NVGRE 0x6558
36 static enum rte_flow_item_type first_items[] = {
37 RTE_FLOW_ITEM_TYPE_ETH,
38 RTE_FLOW_ITEM_TYPE_IPV4,
39 RTE_FLOW_ITEM_TYPE_IPV6,
40 RTE_FLOW_ITEM_TYPE_TCP,
41 RTE_FLOW_ITEM_TYPE_UDP,
42 RTE_FLOW_ITEM_TYPE_SCTP,
43 RTE_FLOW_ITEM_TYPE_ICMP,
44 RTE_FLOW_ITEM_TYPE_NVGRE,
45 RTE_FLOW_ITEM_TYPE_VXLAN,
46 RTE_FLOW_ITEM_TYPE_GENEVE,
47 RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
48 RTE_FLOW_ITEM_TYPE_MPLS
51 static enum rte_flow_item_type L2_next_items[] = {
52 RTE_FLOW_ITEM_TYPE_VLAN,
53 RTE_FLOW_ITEM_TYPE_IPV4,
54 RTE_FLOW_ITEM_TYPE_IPV6
57 static enum rte_flow_item_type L3_next_items[] = {
58 RTE_FLOW_ITEM_TYPE_TCP,
59 RTE_FLOW_ITEM_TYPE_UDP,
60 RTE_FLOW_ITEM_TYPE_SCTP,
61 RTE_FLOW_ITEM_TYPE_NVGRE,
62 RTE_FLOW_ITEM_TYPE_ICMP
65 static enum rte_flow_item_type L4_next_items[] = {
66 RTE_FLOW_ITEM_TYPE_VXLAN,
67 RTE_FLOW_ITEM_TYPE_GENEVE,
68 RTE_FLOW_ITEM_TYPE_VXLAN_GPE,
69 RTE_FLOW_ITEM_TYPE_MPLS
72 static enum rte_flow_item_type tunnel_next_items[] = {
73 RTE_FLOW_ITEM_TYPE_ETH,
74 RTE_FLOW_ITEM_TYPE_VLAN
77 struct items_step_mngr {
78 enum rte_flow_item_type *items;
83 net_addr_to_host(uint32_t *dst, const rte_be32_t *src, size_t len)
87 for (i = 0; i < len; i++)
88 dst[i] = rte_be_to_cpu_32(src[i]);
92 * This function is used to find rss general action.
93 * 1. As we know RSS is used to spread packets among several queues, the flow
94 * API provide the struct rte_flow_action_rss, user could config its field
95 * sush as: func/level/types/key/queue to control RSS function.
96 * 2. The flow API also supports queue region configuration for hns3. It was
97 * implemented by FDIR + RSS in hns3 hardware, user can create one FDIR rule
98 * which action is RSS queues region.
99 * 3. When action is RSS, we use the following rule to distinguish:
100 * Case 1: pattern have ETH and action's queue_num > 0, indicate it is queue
101 * region configuration.
102 * Case other: an rss general action.
104 static const struct rte_flow_action *
105 hns3_find_rss_general_action(const struct rte_flow_item pattern[],
106 const struct rte_flow_action actions[])
108 const struct rte_flow_action *act = NULL;
109 const struct hns3_rss_conf *rss;
110 bool have_eth = false;
112 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
113 if (actions->type == RTE_FLOW_ACTION_TYPE_RSS) {
121 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
122 if (pattern->type == RTE_FLOW_ITEM_TYPE_ETH) {
129 if (have_eth && rss->conf.queue_num) {
131 * Pattern have ETH and action's queue_num > 0, indicate this is
132 * queue region configuration.
133 * Because queue region is implemented by FDIR + RSS in hns3
134 * hardware, it needs to enter FDIR process, so here return NULL
135 * to avoid enter RSS process.
143 static inline struct hns3_flow_counter *
144 hns3_counter_lookup(struct rte_eth_dev *dev, uint32_t id)
146 struct hns3_adapter *hns = dev->data->dev_private;
147 struct hns3_pf *pf = &hns->pf;
148 struct hns3_flow_counter *cnt;
150 LIST_FOREACH(cnt, &pf->flow_counters, next) {
158 hns3_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
159 struct rte_flow_error *error)
161 struct hns3_adapter *hns = dev->data->dev_private;
162 struct hns3_pf *pf = &hns->pf;
163 struct hns3_flow_counter *cnt;
165 cnt = hns3_counter_lookup(dev, id);
167 if (!cnt->shared || cnt->shared != shared)
168 return rte_flow_error_set(error, ENOTSUP,
169 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
171 "Counter id is used, shared flag not match");
176 cnt = rte_zmalloc("hns3 counter", sizeof(*cnt), 0);
178 return rte_flow_error_set(error, ENOMEM,
179 RTE_FLOW_ERROR_TYPE_HANDLE, cnt,
180 "Alloc mem for counter failed");
182 cnt->shared = shared;
185 LIST_INSERT_HEAD(&pf->flow_counters, cnt, next);
190 hns3_counter_query(struct rte_eth_dev *dev, struct rte_flow *flow,
191 struct rte_flow_query_count *qc,
192 struct rte_flow_error *error)
194 struct hns3_adapter *hns = dev->data->dev_private;
195 struct hns3_flow_counter *cnt;
199 /* FDIR is available only in PF driver */
201 return rte_flow_error_set(error, ENOTSUP,
202 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
203 "Fdir is not supported in VF");
204 cnt = hns3_counter_lookup(dev, flow->counter_id);
206 return rte_flow_error_set(error, EINVAL,
207 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
208 "Can't find counter id");
210 ret = hns3_get_count(&hns->hw, flow->counter_id, &value);
212 rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE,
213 NULL, "Read counter fail.");
223 hns3_counter_release(struct rte_eth_dev *dev, uint32_t id)
225 struct hns3_adapter *hns = dev->data->dev_private;
226 struct hns3_hw *hw = &hns->hw;
227 struct hns3_flow_counter *cnt;
229 cnt = hns3_counter_lookup(dev, id);
231 hns3_err(hw, "Can't find available counter to release");
235 if (cnt->ref_cnt == 0) {
236 LIST_REMOVE(cnt, next);
243 hns3_counter_flush(struct rte_eth_dev *dev)
245 struct hns3_adapter *hns = dev->data->dev_private;
246 struct hns3_pf *pf = &hns->pf;
247 struct hns3_flow_counter *cnt_ptr;
249 cnt_ptr = LIST_FIRST(&pf->flow_counters);
251 LIST_REMOVE(cnt_ptr, next);
253 cnt_ptr = LIST_FIRST(&pf->flow_counters);
258 hns3_handle_action_queue(struct rte_eth_dev *dev,
259 const struct rte_flow_action *action,
260 struct hns3_fdir_rule *rule,
261 struct rte_flow_error *error)
263 struct hns3_adapter *hns = dev->data->dev_private;
264 const struct rte_flow_action_queue *queue;
265 struct hns3_hw *hw = &hns->hw;
267 queue = (const struct rte_flow_action_queue *)action->conf;
268 if (queue->index >= hw->used_rx_queues) {
269 hns3_err(hw, "queue ID(%u) is greater than number of "
270 "available queue (%u) in driver.",
271 queue->index, hw->used_rx_queues);
272 return rte_flow_error_set(error, EINVAL,
273 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
274 action, "Invalid queue ID in PF");
277 rule->queue_id = queue->index;
279 rule->action = HNS3_FD_ACTION_ACCEPT_PACKET;
284 hns3_handle_action_queue_region(struct rte_eth_dev *dev,
285 const struct rte_flow_action *action,
286 struct hns3_fdir_rule *rule,
287 struct rte_flow_error *error)
289 struct hns3_adapter *hns = dev->data->dev_private;
290 const struct rte_flow_action_rss *conf = action->conf;
291 struct hns3_hw *hw = &hns->hw;
294 if (!hns3_dev_fd_queue_region_supported(hw))
295 return rte_flow_error_set(error, ENOTSUP,
296 RTE_FLOW_ERROR_TYPE_ACTION, action,
297 "Not support config queue region!");
299 if ((!rte_is_power_of_2(conf->queue_num)) ||
300 conf->queue_num > hw->rss_size_max ||
301 conf->queue[0] >= hw->used_rx_queues ||
302 conf->queue[0] + conf->queue_num > hw->used_rx_queues) {
303 return rte_flow_error_set(error, EINVAL,
304 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action,
305 "Invalid start queue ID and queue num! the start queue "
306 "ID must valid, the queue num must be power of 2 and "
310 for (idx = 1; idx < conf->queue_num; idx++) {
311 if (conf->queue[idx] != conf->queue[idx - 1] + 1)
312 return rte_flow_error_set(error, EINVAL,
313 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action,
314 "Invalid queue ID sequence! the queue ID "
315 "must be continuous increment.");
318 rule->queue_id = conf->queue[0];
319 rule->nb_queues = conf->queue_num;
320 rule->action = HNS3_FD_ACTION_ACCEPT_PACKET;
325 * Parse actions structure from the provided pattern.
326 * The pattern is validated as the items are copied.
330 * NIC specfilc actions derived from the actions.
334 hns3_handle_actions(struct rte_eth_dev *dev,
335 const struct rte_flow_action actions[],
336 struct hns3_fdir_rule *rule, struct rte_flow_error *error)
338 struct hns3_adapter *hns = dev->data->dev_private;
339 const struct rte_flow_action_count *act_count;
340 const struct rte_flow_action_mark *mark;
341 struct hns3_pf *pf = &hns->pf;
342 uint32_t counter_num;
345 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
346 switch (actions->type) {
347 case RTE_FLOW_ACTION_TYPE_QUEUE:
348 ret = hns3_handle_action_queue(dev, actions, rule,
353 case RTE_FLOW_ACTION_TYPE_DROP:
354 rule->action = HNS3_FD_ACTION_DROP_PACKET;
357 * Here RSS's real action is queue region.
358 * Queue region is implemented by FDIR + RSS in hns3 hardware,
359 * the FDIR's action is one queue region (start_queue_id and
360 * queue_num), then RSS spread packets to the queue region by
363 case RTE_FLOW_ACTION_TYPE_RSS:
364 ret = hns3_handle_action_queue_region(dev, actions,
369 case RTE_FLOW_ACTION_TYPE_MARK:
371 (const struct rte_flow_action_mark *)actions->conf;
372 if (mark->id >= HNS3_MAX_FILTER_ID)
373 return rte_flow_error_set(error, EINVAL,
374 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
377 rule->fd_id = mark->id;
378 rule->flags |= HNS3_RULE_FLAG_FDID;
380 case RTE_FLOW_ACTION_TYPE_FLAG:
381 rule->fd_id = HNS3_MAX_FILTER_ID;
382 rule->flags |= HNS3_RULE_FLAG_FDID;
384 case RTE_FLOW_ACTION_TYPE_COUNT:
386 (const struct rte_flow_action_count *)actions->conf;
387 counter_num = pf->fdir.fd_cfg.cnt_num[HNS3_FD_STAGE_1];
388 if (act_count->id >= counter_num)
389 return rte_flow_error_set(error, EINVAL,
390 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
392 "Invalid counter id");
393 rule->act_cnt = *act_count;
394 rule->flags |= HNS3_RULE_FLAG_COUNTER;
396 case RTE_FLOW_ACTION_TYPE_VOID:
399 return rte_flow_error_set(error, ENOTSUP,
400 RTE_FLOW_ERROR_TYPE_ACTION,
401 NULL, "Unsupported action");
409 hns3_check_attr(const struct rte_flow_attr *attr, struct rte_flow_error *error)
412 return rte_flow_error_set(error, EINVAL,
413 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
414 attr, "Ingress can't be zero");
416 return rte_flow_error_set(error, ENOTSUP,
417 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
418 attr, "Not support egress");
420 return rte_flow_error_set(error, ENOTSUP,
421 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
422 attr, "No support for transfer");
424 return rte_flow_error_set(error, ENOTSUP,
425 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
426 attr, "Not support priority");
428 return rte_flow_error_set(error, ENOTSUP,
429 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
430 attr, "Not support group");
435 hns3_parse_eth(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
436 struct rte_flow_error *error __rte_unused)
438 const struct rte_flow_item_eth *eth_spec;
439 const struct rte_flow_item_eth *eth_mask;
441 /* Only used to describe the protocol stack. */
442 if (item->spec == NULL && item->mask == NULL)
446 eth_mask = item->mask;
447 if (eth_mask->type) {
448 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
449 rule->key_conf.mask.ether_type =
450 rte_be_to_cpu_16(eth_mask->type);
452 if (!rte_is_zero_ether_addr(ð_mask->src)) {
453 hns3_set_bit(rule->input_set, INNER_SRC_MAC, 1);
454 memcpy(rule->key_conf.mask.src_mac,
455 eth_mask->src.addr_bytes, RTE_ETHER_ADDR_LEN);
457 if (!rte_is_zero_ether_addr(ð_mask->dst)) {
458 hns3_set_bit(rule->input_set, INNER_DST_MAC, 1);
459 memcpy(rule->key_conf.mask.dst_mac,
460 eth_mask->dst.addr_bytes, RTE_ETHER_ADDR_LEN);
464 eth_spec = item->spec;
465 rule->key_conf.spec.ether_type = rte_be_to_cpu_16(eth_spec->type);
466 memcpy(rule->key_conf.spec.src_mac, eth_spec->src.addr_bytes,
468 memcpy(rule->key_conf.spec.dst_mac, eth_spec->dst.addr_bytes,
474 hns3_parse_vlan(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
475 struct rte_flow_error *error)
477 const struct rte_flow_item_vlan *vlan_spec;
478 const struct rte_flow_item_vlan *vlan_mask;
480 rule->key_conf.vlan_num++;
481 if (rule->key_conf.vlan_num > VLAN_TAG_NUM_MAX)
482 return rte_flow_error_set(error, EINVAL,
483 RTE_FLOW_ERROR_TYPE_ITEM, item,
484 "Vlan_num is more than 2");
486 /* Only used to describe the protocol stack. */
487 if (item->spec == NULL && item->mask == NULL)
491 vlan_mask = item->mask;
492 if (vlan_mask->tci) {
493 if (rule->key_conf.vlan_num == 1) {
494 hns3_set_bit(rule->input_set, INNER_VLAN_TAG1,
496 rule->key_conf.mask.vlan_tag1 =
497 rte_be_to_cpu_16(vlan_mask->tci);
499 hns3_set_bit(rule->input_set, INNER_VLAN_TAG2,
501 rule->key_conf.mask.vlan_tag2 =
502 rte_be_to_cpu_16(vlan_mask->tci);
507 vlan_spec = item->spec;
508 if (rule->key_conf.vlan_num == 1)
509 rule->key_conf.spec.vlan_tag1 =
510 rte_be_to_cpu_16(vlan_spec->tci);
512 rule->key_conf.spec.vlan_tag2 =
513 rte_be_to_cpu_16(vlan_spec->tci);
518 hns3_check_ipv4_mask_supported(const struct rte_flow_item_ipv4 *ipv4_mask)
520 if (ipv4_mask->hdr.total_length || ipv4_mask->hdr.packet_id ||
521 ipv4_mask->hdr.fragment_offset || ipv4_mask->hdr.time_to_live ||
522 ipv4_mask->hdr.hdr_checksum)
529 hns3_parse_ipv4(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
530 struct rte_flow_error *error)
532 const struct rte_flow_item_ipv4 *ipv4_spec;
533 const struct rte_flow_item_ipv4 *ipv4_mask;
535 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
536 rule->key_conf.spec.ether_type = RTE_ETHER_TYPE_IPV4;
537 rule->key_conf.mask.ether_type = ETHER_TYPE_MASK;
539 /* Only used to describe the protocol stack. */
540 if (item->spec == NULL && item->mask == NULL)
544 ipv4_mask = item->mask;
545 if (!hns3_check_ipv4_mask_supported(ipv4_mask)) {
546 return rte_flow_error_set(error, EINVAL,
547 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
549 "Only support src & dst ip,tos,proto in IPV4");
552 if (ipv4_mask->hdr.src_addr) {
553 hns3_set_bit(rule->input_set, INNER_SRC_IP, 1);
554 rule->key_conf.mask.src_ip[IP_ADDR_KEY_ID] =
555 rte_be_to_cpu_32(ipv4_mask->hdr.src_addr);
558 if (ipv4_mask->hdr.dst_addr) {
559 hns3_set_bit(rule->input_set, INNER_DST_IP, 1);
560 rule->key_conf.mask.dst_ip[IP_ADDR_KEY_ID] =
561 rte_be_to_cpu_32(ipv4_mask->hdr.dst_addr);
564 if (ipv4_mask->hdr.type_of_service) {
565 hns3_set_bit(rule->input_set, INNER_IP_TOS, 1);
566 rule->key_conf.mask.ip_tos =
567 ipv4_mask->hdr.type_of_service;
570 if (ipv4_mask->hdr.next_proto_id) {
571 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
572 rule->key_conf.mask.ip_proto =
573 ipv4_mask->hdr.next_proto_id;
577 ipv4_spec = item->spec;
578 rule->key_conf.spec.src_ip[IP_ADDR_KEY_ID] =
579 rte_be_to_cpu_32(ipv4_spec->hdr.src_addr);
580 rule->key_conf.spec.dst_ip[IP_ADDR_KEY_ID] =
581 rte_be_to_cpu_32(ipv4_spec->hdr.dst_addr);
582 rule->key_conf.spec.ip_tos = ipv4_spec->hdr.type_of_service;
583 rule->key_conf.spec.ip_proto = ipv4_spec->hdr.next_proto_id;
588 hns3_parse_ipv6(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
589 struct rte_flow_error *error)
591 const struct rte_flow_item_ipv6 *ipv6_spec;
592 const struct rte_flow_item_ipv6 *ipv6_mask;
594 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
595 rule->key_conf.spec.ether_type = RTE_ETHER_TYPE_IPV6;
596 rule->key_conf.mask.ether_type = ETHER_TYPE_MASK;
598 /* Only used to describe the protocol stack. */
599 if (item->spec == NULL && item->mask == NULL)
603 ipv6_mask = item->mask;
604 if (ipv6_mask->hdr.vtc_flow || ipv6_mask->hdr.payload_len ||
605 ipv6_mask->hdr.hop_limits) {
606 return rte_flow_error_set(error, EINVAL,
607 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
609 "Only support src & dst ip,proto in IPV6");
611 net_addr_to_host(rule->key_conf.mask.src_ip,
612 (const rte_be32_t *)ipv6_mask->hdr.src_addr,
614 net_addr_to_host(rule->key_conf.mask.dst_ip,
615 (const rte_be32_t *)ipv6_mask->hdr.dst_addr,
617 rule->key_conf.mask.ip_proto = ipv6_mask->hdr.proto;
618 if (rule->key_conf.mask.src_ip[IP_ADDR_KEY_ID])
619 hns3_set_bit(rule->input_set, INNER_SRC_IP, 1);
620 if (rule->key_conf.mask.dst_ip[IP_ADDR_KEY_ID])
621 hns3_set_bit(rule->input_set, INNER_DST_IP, 1);
622 if (ipv6_mask->hdr.proto)
623 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
626 ipv6_spec = item->spec;
627 net_addr_to_host(rule->key_conf.spec.src_ip,
628 (const rte_be32_t *)ipv6_spec->hdr.src_addr,
630 net_addr_to_host(rule->key_conf.spec.dst_ip,
631 (const rte_be32_t *)ipv6_spec->hdr.dst_addr,
633 rule->key_conf.spec.ip_proto = ipv6_spec->hdr.proto;
639 hns3_check_tcp_mask_supported(const struct rte_flow_item_tcp *tcp_mask)
641 if (tcp_mask->hdr.sent_seq || tcp_mask->hdr.recv_ack ||
642 tcp_mask->hdr.data_off || tcp_mask->hdr.tcp_flags ||
643 tcp_mask->hdr.rx_win || tcp_mask->hdr.cksum ||
644 tcp_mask->hdr.tcp_urp)
651 hns3_parse_tcp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
652 struct rte_flow_error *error)
654 const struct rte_flow_item_tcp *tcp_spec;
655 const struct rte_flow_item_tcp *tcp_mask;
657 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
658 rule->key_conf.spec.ip_proto = IPPROTO_TCP;
659 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
661 /* Only used to describe the protocol stack. */
662 if (item->spec == NULL && item->mask == NULL)
666 tcp_mask = item->mask;
667 if (!hns3_check_tcp_mask_supported(tcp_mask)) {
668 return rte_flow_error_set(error, EINVAL,
669 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
671 "Only support src & dst port in TCP");
674 if (tcp_mask->hdr.src_port) {
675 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
676 rule->key_conf.mask.src_port =
677 rte_be_to_cpu_16(tcp_mask->hdr.src_port);
679 if (tcp_mask->hdr.dst_port) {
680 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
681 rule->key_conf.mask.dst_port =
682 rte_be_to_cpu_16(tcp_mask->hdr.dst_port);
686 tcp_spec = item->spec;
687 rule->key_conf.spec.src_port = rte_be_to_cpu_16(tcp_spec->hdr.src_port);
688 rule->key_conf.spec.dst_port = rte_be_to_cpu_16(tcp_spec->hdr.dst_port);
694 hns3_parse_udp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
695 struct rte_flow_error *error)
697 const struct rte_flow_item_udp *udp_spec;
698 const struct rte_flow_item_udp *udp_mask;
700 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
701 rule->key_conf.spec.ip_proto = IPPROTO_UDP;
702 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
703 /* Only used to describe the protocol stack. */
704 if (item->spec == NULL && item->mask == NULL)
708 udp_mask = item->mask;
709 if (udp_mask->hdr.dgram_len || udp_mask->hdr.dgram_cksum) {
710 return rte_flow_error_set(error, EINVAL,
711 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
713 "Only support src & dst port in UDP");
715 if (udp_mask->hdr.src_port) {
716 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
717 rule->key_conf.mask.src_port =
718 rte_be_to_cpu_16(udp_mask->hdr.src_port);
720 if (udp_mask->hdr.dst_port) {
721 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
722 rule->key_conf.mask.dst_port =
723 rte_be_to_cpu_16(udp_mask->hdr.dst_port);
727 udp_spec = item->spec;
728 rule->key_conf.spec.src_port = rte_be_to_cpu_16(udp_spec->hdr.src_port);
729 rule->key_conf.spec.dst_port = rte_be_to_cpu_16(udp_spec->hdr.dst_port);
735 hns3_parse_sctp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
736 struct rte_flow_error *error)
738 const struct rte_flow_item_sctp *sctp_spec;
739 const struct rte_flow_item_sctp *sctp_mask;
741 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
742 rule->key_conf.spec.ip_proto = IPPROTO_SCTP;
743 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
745 /* Only used to describe the protocol stack. */
746 if (item->spec == NULL && item->mask == NULL)
750 sctp_mask = item->mask;
751 if (sctp_mask->hdr.cksum)
752 return rte_flow_error_set(error, EINVAL,
753 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
755 "Only support src & dst port in SCTP");
756 if (sctp_mask->hdr.src_port) {
757 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
758 rule->key_conf.mask.src_port =
759 rte_be_to_cpu_16(sctp_mask->hdr.src_port);
761 if (sctp_mask->hdr.dst_port) {
762 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
763 rule->key_conf.mask.dst_port =
764 rte_be_to_cpu_16(sctp_mask->hdr.dst_port);
766 if (sctp_mask->hdr.tag) {
767 hns3_set_bit(rule->input_set, INNER_SCTP_TAG, 1);
768 rule->key_conf.mask.sctp_tag =
769 rte_be_to_cpu_32(sctp_mask->hdr.tag);
773 sctp_spec = item->spec;
774 rule->key_conf.spec.src_port =
775 rte_be_to_cpu_16(sctp_spec->hdr.src_port);
776 rule->key_conf.spec.dst_port =
777 rte_be_to_cpu_16(sctp_spec->hdr.dst_port);
778 rule->key_conf.spec.sctp_tag = rte_be_to_cpu_32(sctp_spec->hdr.tag);
784 * Check items before tunnel, save inner configs to outer configs, and clear
786 * The key consists of two parts: meta_data and tuple keys.
787 * Meta data uses 15 bits, including vlan_num(2bit), des_port(12bit) and tunnel
789 * Tuple keys uses 384bit, including ot_dst-mac(48bit), ot_dst-port(16bit),
790 * ot_tun_vni(24bit), ot_flow_id(8bit), src-mac(48bit), dst-mac(48bit),
791 * src-ip(32/128bit), dst-ip(32/128bit), src-port(16bit), dst-port(16bit),
792 * tos(8bit), ether-proto(16bit), ip-proto(8bit), vlantag1(16bit),
793 * Vlantag2(16bit) and sctp-tag(32bit).
796 hns3_handle_tunnel(const struct rte_flow_item *item,
797 struct hns3_fdir_rule *rule, struct rte_flow_error *error)
799 /* check eth config */
800 if (rule->input_set & (BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC)))
801 return rte_flow_error_set(error, EINVAL,
802 RTE_FLOW_ERROR_TYPE_ITEM,
803 item, "Outer eth mac is unsupported");
804 if (rule->input_set & BIT(INNER_ETH_TYPE)) {
805 hns3_set_bit(rule->input_set, OUTER_ETH_TYPE, 1);
806 rule->key_conf.spec.outer_ether_type =
807 rule->key_conf.spec.ether_type;
808 rule->key_conf.mask.outer_ether_type =
809 rule->key_conf.mask.ether_type;
810 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 0);
811 rule->key_conf.spec.ether_type = 0;
812 rule->key_conf.mask.ether_type = 0;
815 /* check vlan config */
816 if (rule->input_set & (BIT(INNER_VLAN_TAG1) | BIT(INNER_VLAN_TAG2)))
817 return rte_flow_error_set(error, EINVAL,
818 RTE_FLOW_ERROR_TYPE_ITEM,
820 "Outer vlan tags is unsupported");
822 /* clear vlan_num for inner vlan select */
823 rule->key_conf.outer_vlan_num = rule->key_conf.vlan_num;
824 rule->key_conf.vlan_num = 0;
826 /* check L3 config */
827 if (rule->input_set &
828 (BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) | BIT(INNER_IP_TOS)))
829 return rte_flow_error_set(error, EINVAL,
830 RTE_FLOW_ERROR_TYPE_ITEM,
831 item, "Outer ip is unsupported");
832 if (rule->input_set & BIT(INNER_IP_PROTO)) {
833 hns3_set_bit(rule->input_set, OUTER_IP_PROTO, 1);
834 rule->key_conf.spec.outer_proto = rule->key_conf.spec.ip_proto;
835 rule->key_conf.mask.outer_proto = rule->key_conf.mask.ip_proto;
836 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 0);
837 rule->key_conf.spec.ip_proto = 0;
838 rule->key_conf.mask.ip_proto = 0;
841 /* check L4 config */
842 if (rule->input_set & BIT(INNER_SCTP_TAG))
843 return rte_flow_error_set(error, EINVAL,
844 RTE_FLOW_ERROR_TYPE_ITEM, item,
845 "Outer sctp tag is unsupported");
847 if (rule->input_set & BIT(INNER_SRC_PORT)) {
848 hns3_set_bit(rule->input_set, OUTER_SRC_PORT, 1);
849 rule->key_conf.spec.outer_src_port =
850 rule->key_conf.spec.src_port;
851 rule->key_conf.mask.outer_src_port =
852 rule->key_conf.mask.src_port;
853 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 0);
854 rule->key_conf.spec.src_port = 0;
855 rule->key_conf.mask.src_port = 0;
857 if (rule->input_set & BIT(INNER_DST_PORT)) {
858 hns3_set_bit(rule->input_set, INNER_DST_PORT, 0);
859 rule->key_conf.spec.dst_port = 0;
860 rule->key_conf.mask.dst_port = 0;
866 hns3_parse_vxlan(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
867 struct rte_flow_error *error)
869 const struct rte_flow_item_vxlan *vxlan_spec;
870 const struct rte_flow_item_vxlan *vxlan_mask;
872 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
873 rule->key_conf.mask.tunnel_type = TUNNEL_TYPE_MASK;
874 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN)
875 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_VXLAN;
877 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_VXLAN_GPE;
879 /* Only used to describe the protocol stack. */
880 if (item->spec == NULL && item->mask == NULL)
883 vxlan_mask = item->mask;
884 vxlan_spec = item->spec;
886 if (vxlan_mask->flags)
887 return rte_flow_error_set(error, EINVAL,
888 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
889 "Flags is not supported in VxLAN");
891 /* VNI must be totally masked or not. */
892 if (memcmp(vxlan_mask->vni, full_mask, VNI_OR_TNI_LEN) &&
893 memcmp(vxlan_mask->vni, zero_mask, VNI_OR_TNI_LEN))
894 return rte_flow_error_set(error, EINVAL,
895 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
896 "VNI must be totally masked or not in VxLAN");
897 if (vxlan_mask->vni[0]) {
898 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
899 memcpy(rule->key_conf.mask.outer_tun_vni, vxlan_mask->vni,
902 memcpy(rule->key_conf.spec.outer_tun_vni, vxlan_spec->vni,
908 hns3_parse_nvgre(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
909 struct rte_flow_error *error)
911 const struct rte_flow_item_nvgre *nvgre_spec;
912 const struct rte_flow_item_nvgre *nvgre_mask;
914 hns3_set_bit(rule->input_set, OUTER_IP_PROTO, 1);
915 rule->key_conf.spec.outer_proto = IPPROTO_GRE;
916 rule->key_conf.mask.outer_proto = IPPROTO_MASK;
918 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
919 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_NVGRE;
920 rule->key_conf.mask.tunnel_type = ~HNS3_TUNNEL_TYPE_NVGRE;
921 /* Only used to describe the protocol stack. */
922 if (item->spec == NULL && item->mask == NULL)
925 nvgre_mask = item->mask;
926 nvgre_spec = item->spec;
928 if (nvgre_mask->protocol || nvgre_mask->c_k_s_rsvd0_ver)
929 return rte_flow_error_set(error, EINVAL,
930 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
931 "Ver/protocal is not supported in NVGRE");
933 /* TNI must be totally masked or not. */
934 if (memcmp(nvgre_mask->tni, full_mask, VNI_OR_TNI_LEN) &&
935 memcmp(nvgre_mask->tni, zero_mask, VNI_OR_TNI_LEN))
936 return rte_flow_error_set(error, EINVAL,
937 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
938 "TNI must be totally masked or not in NVGRE");
940 if (nvgre_mask->tni[0]) {
941 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
942 memcpy(rule->key_conf.mask.outer_tun_vni, nvgre_mask->tni,
945 memcpy(rule->key_conf.spec.outer_tun_vni, nvgre_spec->tni,
948 if (nvgre_mask->flow_id) {
949 hns3_set_bit(rule->input_set, OUTER_TUN_FLOW_ID, 1);
950 rule->key_conf.mask.outer_tun_flow_id = nvgre_mask->flow_id;
952 rule->key_conf.spec.outer_tun_flow_id = nvgre_spec->flow_id;
957 hns3_parse_geneve(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
958 struct rte_flow_error *error)
960 const struct rte_flow_item_geneve *geneve_spec;
961 const struct rte_flow_item_geneve *geneve_mask;
963 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
964 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_GENEVE;
965 rule->key_conf.mask.tunnel_type = TUNNEL_TYPE_MASK;
966 /* Only used to describe the protocol stack. */
967 if (item->spec == NULL && item->mask == NULL)
970 geneve_mask = item->mask;
971 geneve_spec = item->spec;
973 if (geneve_mask->ver_opt_len_o_c_rsvd0 || geneve_mask->protocol)
974 return rte_flow_error_set(error, EINVAL,
975 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
976 "Ver/protocal is not supported in GENEVE");
977 /* VNI must be totally masked or not. */
978 if (memcmp(geneve_mask->vni, full_mask, VNI_OR_TNI_LEN) &&
979 memcmp(geneve_mask->vni, zero_mask, VNI_OR_TNI_LEN))
980 return rte_flow_error_set(error, EINVAL,
981 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
982 "VNI must be totally masked or not in GENEVE");
983 if (geneve_mask->vni[0]) {
984 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
985 memcpy(rule->key_conf.mask.outer_tun_vni, geneve_mask->vni,
988 memcpy(rule->key_conf.spec.outer_tun_vni, geneve_spec->vni,
994 hns3_parse_tunnel(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
995 struct rte_flow_error *error)
999 if (item->spec == NULL && item->mask)
1000 return rte_flow_error_set(error, EINVAL,
1001 RTE_FLOW_ERROR_TYPE_ITEM, item,
1002 "Can't configure FDIR with mask "
1003 "but without spec");
1004 else if (item->spec && (item->mask == NULL))
1005 return rte_flow_error_set(error, EINVAL,
1006 RTE_FLOW_ERROR_TYPE_ITEM, item,
1007 "Tunnel packets must configure "
1010 switch (item->type) {
1011 case RTE_FLOW_ITEM_TYPE_VXLAN:
1012 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1013 ret = hns3_parse_vxlan(item, rule, error);
1015 case RTE_FLOW_ITEM_TYPE_NVGRE:
1016 ret = hns3_parse_nvgre(item, rule, error);
1018 case RTE_FLOW_ITEM_TYPE_GENEVE:
1019 ret = hns3_parse_geneve(item, rule, error);
1022 return rte_flow_error_set(error, ENOTSUP,
1023 RTE_FLOW_ERROR_TYPE_ITEM,
1024 NULL, "Unsupported tunnel type!");
1028 return hns3_handle_tunnel(item, rule, error);
1032 hns3_parse_normal(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
1033 struct items_step_mngr *step_mngr,
1034 struct rte_flow_error *error)
1038 if (item->spec == NULL && item->mask)
1039 return rte_flow_error_set(error, EINVAL,
1040 RTE_FLOW_ERROR_TYPE_ITEM, item,
1041 "Can't configure FDIR with mask "
1042 "but without spec");
1044 switch (item->type) {
1045 case RTE_FLOW_ITEM_TYPE_ETH:
1046 ret = hns3_parse_eth(item, rule, error);
1047 step_mngr->items = L2_next_items;
1048 step_mngr->count = ARRAY_SIZE(L2_next_items);
1050 case RTE_FLOW_ITEM_TYPE_VLAN:
1051 ret = hns3_parse_vlan(item, rule, error);
1052 step_mngr->items = L2_next_items;
1053 step_mngr->count = ARRAY_SIZE(L2_next_items);
1055 case RTE_FLOW_ITEM_TYPE_IPV4:
1056 ret = hns3_parse_ipv4(item, rule, error);
1057 step_mngr->items = L3_next_items;
1058 step_mngr->count = ARRAY_SIZE(L3_next_items);
1060 case RTE_FLOW_ITEM_TYPE_IPV6:
1061 ret = hns3_parse_ipv6(item, rule, error);
1062 step_mngr->items = L3_next_items;
1063 step_mngr->count = ARRAY_SIZE(L3_next_items);
1065 case RTE_FLOW_ITEM_TYPE_TCP:
1066 ret = hns3_parse_tcp(item, rule, error);
1067 step_mngr->items = L4_next_items;
1068 step_mngr->count = ARRAY_SIZE(L4_next_items);
1070 case RTE_FLOW_ITEM_TYPE_UDP:
1071 ret = hns3_parse_udp(item, rule, error);
1072 step_mngr->items = L4_next_items;
1073 step_mngr->count = ARRAY_SIZE(L4_next_items);
1075 case RTE_FLOW_ITEM_TYPE_SCTP:
1076 ret = hns3_parse_sctp(item, rule, error);
1077 step_mngr->items = L4_next_items;
1078 step_mngr->count = ARRAY_SIZE(L4_next_items);
1081 return rte_flow_error_set(error, ENOTSUP,
1082 RTE_FLOW_ERROR_TYPE_ITEM,
1083 NULL, "Unsupported normal type!");
1090 hns3_validate_item(const struct rte_flow_item *item,
1091 struct items_step_mngr step_mngr,
1092 struct rte_flow_error *error)
1097 return rte_flow_error_set(error, ENOTSUP,
1098 RTE_FLOW_ERROR_TYPE_ITEM_LAST, item,
1099 "Not supported last point for range");
1101 for (i = 0; i < step_mngr.count; i++) {
1102 if (item->type == step_mngr.items[i])
1106 if (i == step_mngr.count) {
1107 return rte_flow_error_set(error, EINVAL,
1108 RTE_FLOW_ERROR_TYPE_ITEM,
1109 item, "Inval or missing item");
1115 is_tunnel_packet(enum rte_flow_item_type type)
1117 if (type == RTE_FLOW_ITEM_TYPE_VXLAN_GPE ||
1118 type == RTE_FLOW_ITEM_TYPE_VXLAN ||
1119 type == RTE_FLOW_ITEM_TYPE_NVGRE ||
1120 type == RTE_FLOW_ITEM_TYPE_GENEVE ||
1121 type == RTE_FLOW_ITEM_TYPE_MPLS)
1127 * Parse the rule to see if it is a IP or MAC VLAN flow director rule.
1128 * And get the flow director filter info BTW.
1129 * UDP/TCP/SCTP PATTERN:
1130 * The first not void item can be ETH or IPV4 or IPV6
1131 * The second not void item must be IPV4 or IPV6 if the first one is ETH.
1132 * The next not void item could be UDP or TCP or SCTP (optional)
1133 * The next not void item could be RAW (for flexbyte, optional)
1134 * The next not void item must be END.
1135 * A Fuzzy Match pattern can appear at any place before END.
1136 * Fuzzy Match is optional for IPV4 but is required for IPV6
1138 * The first not void item must be ETH.
1139 * The second not void item must be MAC VLAN.
1140 * The next not void item must be END.
1142 * The first not void action should be QUEUE or DROP.
1143 * The second not void optional action should be MARK,
1144 * mark_id is a uint32_t number.
1145 * The next not void action should be END.
1146 * UDP/TCP/SCTP pattern example:
1149 * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
1150 * dst_addr 192.167.3.50 0xFFFFFFFF
1151 * UDP/TCP/SCTP src_port 80 0xFFFF
1152 * dst_port 80 0xFFFF
1154 * MAC VLAN pattern example:
1157 {0xAC, 0x7B, 0xA1, {0xFF, 0xFF, 0xFF,
1158 0x2C, 0x6D, 0x36} 0xFF, 0xFF, 0xFF}
1159 * MAC VLAN tci 0x2016 0xEFFF
1161 * Other members in mask and spec should set to 0x00.
1162 * Item->last should be NULL.
1165 hns3_parse_fdir_filter(struct rte_eth_dev *dev,
1166 const struct rte_flow_item pattern[],
1167 const struct rte_flow_action actions[],
1168 struct hns3_fdir_rule *rule,
1169 struct rte_flow_error *error)
1171 struct hns3_adapter *hns = dev->data->dev_private;
1172 const struct rte_flow_item *item;
1173 struct items_step_mngr step_mngr;
1176 /* FDIR is available only in PF driver */
1178 return rte_flow_error_set(error, ENOTSUP,
1179 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1180 "Fdir not supported in VF");
1182 step_mngr.items = first_items;
1183 step_mngr.count = ARRAY_SIZE(first_items);
1184 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1185 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
1188 ret = hns3_validate_item(item, step_mngr, error);
1192 if (is_tunnel_packet(item->type)) {
1193 ret = hns3_parse_tunnel(item, rule, error);
1196 step_mngr.items = tunnel_next_items;
1197 step_mngr.count = ARRAY_SIZE(tunnel_next_items);
1199 ret = hns3_parse_normal(item, rule, &step_mngr, error);
1205 return hns3_handle_actions(dev, actions, rule, error);
1209 hns3_filterlist_init(struct rte_eth_dev *dev)
1211 struct hns3_process_private *process_list = dev->process_private;
1213 TAILQ_INIT(&process_list->fdir_list);
1214 TAILQ_INIT(&process_list->filter_rss_list);
1215 TAILQ_INIT(&process_list->flow_list);
1219 hns3_filterlist_flush(struct rte_eth_dev *dev)
1221 struct hns3_process_private *process_list = dev->process_private;
1222 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1223 struct hns3_rss_conf_ele *rss_filter_ptr;
1224 struct hns3_flow_mem *flow_node;
1226 fdir_rule_ptr = TAILQ_FIRST(&process_list->fdir_list);
1227 while (fdir_rule_ptr) {
1228 TAILQ_REMOVE(&process_list->fdir_list, fdir_rule_ptr, entries);
1229 rte_free(fdir_rule_ptr);
1230 fdir_rule_ptr = TAILQ_FIRST(&process_list->fdir_list);
1233 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1234 while (rss_filter_ptr) {
1235 TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr,
1237 rte_free(rss_filter_ptr);
1238 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1241 flow_node = TAILQ_FIRST(&process_list->flow_list);
1243 TAILQ_REMOVE(&process_list->flow_list, flow_node, entries);
1244 rte_free(flow_node->flow);
1245 rte_free(flow_node);
1246 flow_node = TAILQ_FIRST(&process_list->flow_list);
1251 hns3_action_rss_same(const struct rte_flow_action_rss *comp,
1252 const struct rte_flow_action_rss *with)
1257 * When user flush all RSS rule, RSS func is set invalid with
1258 * RTE_ETH_HASH_FUNCTION_MAX. Then the user create a flow after
1259 * flushed, any validate RSS func is different with it before
1260 * flushed. Others, when user create an action RSS with RSS func
1261 * specified RTE_ETH_HASH_FUNCTION_DEFAULT, the func is the same
1262 * between continuous RSS flow.
1264 if (comp->func == RTE_ETH_HASH_FUNCTION_MAX)
1265 func_is_same = false;
1267 func_is_same = (with->func ? (comp->func == with->func) : true);
1269 return (func_is_same &&
1270 comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) &&
1271 comp->level == with->level && comp->key_len == with->key_len &&
1272 comp->queue_num == with->queue_num &&
1273 !memcmp(comp->key, with->key, with->key_len) &&
1274 !memcmp(comp->queue, with->queue,
1275 sizeof(*with->queue) * with->queue_num));
1279 hns3_rss_conf_copy(struct hns3_rss_conf *out,
1280 const struct rte_flow_action_rss *in)
1282 if (in->key_len > RTE_DIM(out->key) ||
1283 in->queue_num > RTE_DIM(out->queue))
1285 if (in->key == NULL && in->key_len)
1287 out->conf = (struct rte_flow_action_rss) {
1291 .key_len = in->key_len,
1292 .queue_num = in->queue_num,
1294 out->conf.queue = memcpy(out->queue, in->queue,
1295 sizeof(*in->queue) * in->queue_num);
1297 out->conf.key = memcpy(out->key, in->key, in->key_len);
1303 hns3_rss_input_tuple_supported(struct hns3_hw *hw,
1304 const struct rte_flow_action_rss *rss)
1307 * For IP packet, it is not supported to use src/dst port fields to RSS
1308 * hash for the following packet types.
1309 * - IPV4 FRAG | IPV4 NONFRAG | IPV6 FRAG | IPV6 NONFRAG
1310 * Besides, for Kunpeng920, the NIC HW is not supported to use src/dst
1311 * port fields to RSS hash for IPV6 SCTP packet type. However, the
1312 * Kunpeng930 and future kunpeng series support to use src/dst port
1313 * fields to RSS hash for IPv6 SCTP packet type.
1315 if (rss->types & (ETH_RSS_L4_DST_ONLY | ETH_RSS_L4_SRC_ONLY) &&
1316 (rss->types & ETH_RSS_IP ||
1317 (!hw->rss_info.ipv6_sctp_offload_supported &&
1318 rss->types & ETH_RSS_NONFRAG_IPV6_SCTP)))
1325 * This function is used to parse rss action validatation.
1328 hns3_parse_rss_filter(struct rte_eth_dev *dev,
1329 const struct rte_flow_action *actions,
1330 struct rte_flow_error *error)
1332 struct hns3_adapter *hns = dev->data->dev_private;
1333 struct hns3_hw *hw = &hns->hw;
1334 struct hns3_rss_conf *rss_conf = &hw->rss_info;
1335 const struct rte_flow_action_rss *rss;
1336 const struct rte_flow_action *act;
1337 uint32_t act_index = 0;
1340 NEXT_ITEM_OF_ACTION(act, actions, act_index);
1344 return rte_flow_error_set(error, EINVAL,
1345 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1346 act, "no valid queues");
1349 if (rss->queue_num > RTE_DIM(rss_conf->queue))
1350 return rte_flow_error_set(error, ENOTSUP,
1351 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1352 "queue number configured exceeds "
1353 "queue buffer size driver supported");
1355 for (n = 0; n < rss->queue_num; n++) {
1356 if (rss->queue[n] < hw->alloc_rss_size)
1358 return rte_flow_error_set(error, EINVAL,
1359 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1360 "queue id must be less than queue number allocated to a TC");
1363 if (!(rss->types & HNS3_ETH_RSS_SUPPORT) && rss->types)
1364 return rte_flow_error_set(error, EINVAL,
1365 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1367 "Flow types is unsupported by "
1369 if (rss->func >= RTE_ETH_HASH_FUNCTION_MAX)
1370 return rte_flow_error_set(error, ENOTSUP,
1371 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1372 "RSS hash func are not supported");
1374 return rte_flow_error_set(error, ENOTSUP,
1375 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1376 "a nonzero RSS encapsulation level is not supported");
1377 if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
1378 return rte_flow_error_set(error, ENOTSUP,
1379 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1380 "RSS hash key must be exactly 40 bytes");
1382 if (!hns3_rss_input_tuple_supported(hw, rss))
1383 return rte_flow_error_set(error, EINVAL,
1384 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1386 "input RSS types are not supported");
1390 /* Check if the next not void action is END */
1391 NEXT_ITEM_OF_ACTION(act, actions, act_index);
1392 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1393 memset(rss_conf, 0, sizeof(struct hns3_rss_conf));
1394 return rte_flow_error_set(error, EINVAL,
1395 RTE_FLOW_ERROR_TYPE_ACTION,
1396 act, "Not supported action.");
1403 hns3_disable_rss(struct hns3_hw *hw)
1407 /* Redirected the redirection table to queue 0 */
1408 ret = hns3_rss_reset_indir_table(hw);
1413 hw->rss_info.conf.types = 0;
1414 hw->rss_dis_flag = true;
1420 hns3_parse_rss_key(struct hns3_hw *hw, struct rte_flow_action_rss *rss_conf)
1422 if (rss_conf->key == NULL || rss_conf->key_len < HNS3_RSS_KEY_SIZE) {
1423 hns3_warn(hw, "Default RSS hash key to be set");
1424 rss_conf->key = hns3_hash_key;
1425 rss_conf->key_len = HNS3_RSS_KEY_SIZE;
1430 hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func,
1433 enum rte_eth_hash_function algo_func = *func;
1434 switch (algo_func) {
1435 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1436 /* Keep *hash_algo as what it used to be */
1437 algo_func = hw->rss_info.conf.func;
1439 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1440 *hash_algo = HNS3_RSS_HASH_ALGO_TOEPLITZ;
1442 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1443 *hash_algo = HNS3_RSS_HASH_ALGO_SIMPLE;
1445 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1446 *hash_algo = HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP;
1449 hns3_err(hw, "Invalid RSS algorithm configuration(%u)",
1459 hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config)
1461 struct hns3_rss_tuple_cfg *tuple;
1464 hns3_parse_rss_key(hw, rss_config);
1466 ret = hns3_parse_rss_algorithm(hw, &rss_config->func,
1467 &hw->rss_info.hash_algo);
1471 ret = hns3_rss_set_algo_key(hw, rss_config->key);
1475 hw->rss_info.conf.func = rss_config->func;
1477 tuple = &hw->rss_info.rss_tuple_sets;
1478 ret = hns3_set_rss_tuple_by_rss_hf(hw, tuple, rss_config->types);
1480 hns3_err(hw, "Update RSS tuples by rss hf failed %d", ret);
1486 hns3_update_indir_table(struct rte_eth_dev *dev,
1487 const struct rte_flow_action_rss *conf, uint16_t num)
1489 struct hns3_adapter *hns = dev->data->dev_private;
1490 struct hns3_hw *hw = &hns->hw;
1491 uint16_t indir_tbl[HNS3_RSS_IND_TBL_SIZE];
1495 /* Fill in redirection table */
1496 memcpy(indir_tbl, hw->rss_info.rss_indirection_tbl,
1497 sizeof(hw->rss_info.rss_indirection_tbl));
1498 for (i = 0, j = 0; i < HNS3_RSS_IND_TBL_SIZE; i++, j++) {
1500 if (conf->queue[j] >= hw->alloc_rss_size) {
1501 hns3_err(hw, "queue id(%u) set to redirection table "
1502 "exceeds queue number(%u) allocated to a TC.",
1503 conf->queue[j], hw->alloc_rss_size);
1506 indir_tbl[i] = conf->queue[j];
1509 return hns3_set_rss_indir_table(hw, indir_tbl, HNS3_RSS_IND_TBL_SIZE);
1513 hns3_config_rss_filter(struct rte_eth_dev *dev,
1514 const struct hns3_rss_conf *conf, bool add)
1516 struct hns3_process_private *process_list = dev->process_private;
1517 struct hns3_adapter *hns = dev->data->dev_private;
1518 struct hns3_rss_conf_ele *rss_filter_ptr;
1519 struct hns3_hw *hw = &hns->hw;
1520 struct hns3_rss_conf *rss_info;
1521 uint64_t flow_types;
1525 struct rte_flow_action_rss rss_flow_conf = {
1526 .func = conf->conf.func,
1527 .level = conf->conf.level,
1528 .types = conf->conf.types,
1529 .key_len = conf->conf.key_len,
1530 .queue_num = conf->conf.queue_num,
1531 .key = conf->conf.key_len ?
1532 (void *)(uintptr_t)conf->conf.key : NULL,
1533 .queue = conf->conf.queue,
1536 /* Filter the unsupported flow types */
1537 flow_types = conf->conf.types ?
1538 rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
1539 hw->rss_info.conf.types;
1540 if (flow_types != rss_flow_conf.types)
1541 hns3_warn(hw, "modified RSS types based on hardware support, "
1542 "requested:%" PRIx64 " configured:%" PRIx64,
1543 rss_flow_conf.types, flow_types);
1544 /* Update the useful flow types */
1545 rss_flow_conf.types = flow_types;
1547 rss_info = &hw->rss_info;
1552 ret = hns3_disable_rss(hw);
1554 hns3_err(hw, "RSS disable failed(%d)", ret);
1558 if (rss_flow_conf.queue_num) {
1560 * Due the content of queue pointer have been reset to
1561 * 0, the rss_info->conf.queue should be set to NULL
1563 rss_info->conf.queue = NULL;
1564 rss_info->conf.queue_num = 0;
1567 /* set RSS func invalid after flushed */
1568 rss_info->conf.func = RTE_ETH_HASH_FUNCTION_MAX;
1572 /* Set rx queues to use */
1573 num = RTE_MIN(dev->data->nb_rx_queues, rss_flow_conf.queue_num);
1574 if (rss_flow_conf.queue_num > num)
1575 hns3_warn(hw, "Config queue numbers %u are beyond the scope of truncated",
1576 rss_flow_conf.queue_num);
1577 hns3_info(hw, "Max of contiguous %u PF queues are configured", num);
1579 rte_spinlock_lock(&hw->lock);
1581 ret = hns3_update_indir_table(dev, &rss_flow_conf, num);
1583 goto rss_config_err;
1586 /* Set hash algorithm and flow types by the user's config */
1587 ret = hns3_hw_rss_hash_set(hw, &rss_flow_conf);
1589 goto rss_config_err;
1591 ret = hns3_rss_conf_copy(rss_info, &rss_flow_conf);
1593 hns3_err(hw, "RSS config init fail(%d)", ret);
1594 goto rss_config_err;
1598 * When create a new RSS rule, the old rule will be overlaid and set
1601 TAILQ_FOREACH(rss_filter_ptr, &process_list->filter_rss_list, entries)
1602 rss_filter_ptr->filter_info.valid = false;
1605 rte_spinlock_unlock(&hw->lock);
1611 hns3_clear_rss_filter(struct rte_eth_dev *dev)
1613 struct hns3_process_private *process_list = dev->process_private;
1614 struct hns3_adapter *hns = dev->data->dev_private;
1615 struct hns3_rss_conf_ele *rss_filter_ptr;
1616 struct hns3_hw *hw = &hns->hw;
1617 int rss_rule_succ_cnt = 0; /* count for success of clearing RSS rules */
1618 int rss_rule_fail_cnt = 0; /* count for failure of clearing RSS rules */
1621 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1622 while (rss_filter_ptr) {
1623 TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr,
1625 ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info,
1628 rss_rule_fail_cnt++;
1630 rss_rule_succ_cnt++;
1631 rte_free(rss_filter_ptr);
1632 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1635 if (rss_rule_fail_cnt) {
1636 hns3_err(hw, "fail to delete all RSS filters, success num = %d "
1637 "fail num = %d", rss_rule_succ_cnt,
1646 hns3_restore_rss_filter(struct rte_eth_dev *dev)
1648 struct hns3_adapter *hns = dev->data->dev_private;
1649 struct hns3_hw *hw = &hns->hw;
1651 /* When user flush all rules, it doesn't need to restore RSS rule */
1652 if (hw->rss_info.conf.func == RTE_ETH_HASH_FUNCTION_MAX)
1655 return hns3_config_rss_filter(dev, &hw->rss_info, true);
1659 hns3_flow_parse_rss(struct rte_eth_dev *dev,
1660 const struct hns3_rss_conf *conf, bool add)
1662 struct hns3_adapter *hns = dev->data->dev_private;
1663 struct hns3_hw *hw = &hns->hw;
1666 ret = hns3_action_rss_same(&hw->rss_info.conf, &conf->conf);
1668 hns3_err(hw, "Enter duplicate RSS configuration : %d", ret);
1672 return hns3_config_rss_filter(dev, conf, add);
1676 hns3_flow_args_check(const struct rte_flow_attr *attr,
1677 const struct rte_flow_item pattern[],
1678 const struct rte_flow_action actions[],
1679 struct rte_flow_error *error)
1681 if (pattern == NULL)
1682 return rte_flow_error_set(error, EINVAL,
1683 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1684 NULL, "NULL pattern.");
1686 if (actions == NULL)
1687 return rte_flow_error_set(error, EINVAL,
1688 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1689 NULL, "NULL action.");
1692 return rte_flow_error_set(error, EINVAL,
1693 RTE_FLOW_ERROR_TYPE_ATTR,
1694 NULL, "NULL attribute.");
1696 return hns3_check_attr(attr, error);
1700 * Check if the flow rule is supported by hns3.
1701 * It only checkes the format. Don't guarantee the rule can be programmed into
1702 * the HW. Because there can be no enough room for the rule.
1705 hns3_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1706 const struct rte_flow_item pattern[],
1707 const struct rte_flow_action actions[],
1708 struct rte_flow_error *error)
1710 struct hns3_fdir_rule fdir_rule;
1713 ret = hns3_flow_args_check(attr, pattern, actions, error);
1717 if (hns3_find_rss_general_action(pattern, actions))
1718 return hns3_parse_rss_filter(dev, actions, error);
1720 memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule));
1721 return hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error);
1725 * Create or destroy a flow rule.
1726 * Theorically one rule can match more than one filters.
1727 * We will let it use the filter which it hit first.
1728 * So, the sequence matters.
1730 static struct rte_flow *
1731 hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1732 const struct rte_flow_item pattern[],
1733 const struct rte_flow_action actions[],
1734 struct rte_flow_error *error)
1736 struct hns3_process_private *process_list = dev->process_private;
1737 struct hns3_adapter *hns = dev->data->dev_private;
1738 struct hns3_hw *hw = &hns->hw;
1739 const struct hns3_rss_conf *rss_conf;
1740 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1741 struct hns3_rss_conf_ele *rss_filter_ptr;
1742 struct hns3_flow_mem *flow_node;
1743 const struct rte_flow_action *act;
1744 struct rte_flow *flow;
1745 struct hns3_fdir_rule fdir_rule;
1748 ret = hns3_flow_validate(dev, attr, pattern, actions, error);
1752 flow = rte_zmalloc("hns3 flow", sizeof(struct rte_flow), 0);
1754 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1755 NULL, "Failed to allocate flow memory");
1758 flow_node = rte_zmalloc("hns3 flow node",
1759 sizeof(struct hns3_flow_mem), 0);
1760 if (flow_node == NULL) {
1761 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1762 NULL, "Failed to allocate flow list memory");
1767 flow_node->flow = flow;
1768 TAILQ_INSERT_TAIL(&process_list->flow_list, flow_node, entries);
1770 act = hns3_find_rss_general_action(pattern, actions);
1772 rss_conf = act->conf;
1774 ret = hns3_flow_parse_rss(dev, rss_conf, true);
1778 rss_filter_ptr = rte_zmalloc("hns3 rss filter",
1779 sizeof(struct hns3_rss_conf_ele),
1781 if (rss_filter_ptr == NULL) {
1783 "Failed to allocate hns3_rss_filter memory");
1787 hns3_rss_conf_copy(&rss_filter_ptr->filter_info,
1789 rss_filter_ptr->filter_info.valid = true;
1790 TAILQ_INSERT_TAIL(&process_list->filter_rss_list,
1791 rss_filter_ptr, entries);
1793 flow->rule = rss_filter_ptr;
1794 flow->filter_type = RTE_ETH_FILTER_HASH;
1798 memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule));
1799 ret = hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error);
1803 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) {
1804 ret = hns3_counter_new(dev, fdir_rule.act_cnt.shared,
1805 fdir_rule.act_cnt.id, error);
1809 flow->counter_id = fdir_rule.act_cnt.id;
1811 ret = hns3_fdir_filter_program(hns, &fdir_rule, false);
1813 fdir_rule_ptr = rte_zmalloc("hns3 fdir rule",
1814 sizeof(struct hns3_fdir_rule_ele),
1816 if (fdir_rule_ptr == NULL) {
1817 hns3_err(hw, "Failed to allocate fdir_rule memory");
1822 memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule,
1823 sizeof(struct hns3_fdir_rule));
1824 TAILQ_INSERT_TAIL(&process_list->fdir_list,
1825 fdir_rule_ptr, entries);
1826 flow->rule = fdir_rule_ptr;
1827 flow->filter_type = RTE_ETH_FILTER_FDIR;
1833 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
1834 hns3_counter_release(dev, fdir_rule.act_cnt.id);
1837 rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1838 "Failed to create flow");
1840 TAILQ_REMOVE(&process_list->flow_list, flow_node, entries);
1841 rte_free(flow_node);
1846 /* Destroy a flow rule on hns3. */
1848 hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
1849 struct rte_flow_error *error)
1851 struct hns3_process_private *process_list = dev->process_private;
1852 struct hns3_adapter *hns = dev->data->dev_private;
1853 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1854 struct hns3_rss_conf_ele *rss_filter_ptr;
1855 struct hns3_flow_mem *flow_node;
1856 enum rte_filter_type filter_type;
1857 struct hns3_fdir_rule fdir_rule;
1861 return rte_flow_error_set(error, EINVAL,
1862 RTE_FLOW_ERROR_TYPE_HANDLE,
1863 flow, "Flow is NULL");
1864 filter_type = flow->filter_type;
1865 switch (filter_type) {
1866 case RTE_ETH_FILTER_FDIR:
1867 fdir_rule_ptr = (struct hns3_fdir_rule_ele *)flow->rule;
1868 memcpy(&fdir_rule, &fdir_rule_ptr->fdir_conf,
1869 sizeof(struct hns3_fdir_rule));
1871 ret = hns3_fdir_filter_program(hns, &fdir_rule, true);
1873 return rte_flow_error_set(error, EIO,
1874 RTE_FLOW_ERROR_TYPE_HANDLE,
1876 "Destroy FDIR fail.Try again");
1877 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
1878 hns3_counter_release(dev, fdir_rule.act_cnt.id);
1879 TAILQ_REMOVE(&process_list->fdir_list, fdir_rule_ptr, entries);
1880 rte_free(fdir_rule_ptr);
1881 fdir_rule_ptr = NULL;
1883 case RTE_ETH_FILTER_HASH:
1884 rss_filter_ptr = (struct hns3_rss_conf_ele *)flow->rule;
1885 ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info,
1888 return rte_flow_error_set(error, EIO,
1889 RTE_FLOW_ERROR_TYPE_HANDLE,
1891 "Destroy RSS fail.Try again");
1892 TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr,
1894 rte_free(rss_filter_ptr);
1895 rss_filter_ptr = NULL;
1898 return rte_flow_error_set(error, EINVAL,
1899 RTE_FLOW_ERROR_TYPE_HANDLE, flow,
1900 "Unsupported filter type");
1903 TAILQ_FOREACH(flow_node, &process_list->flow_list, entries) {
1904 if (flow_node->flow == flow) {
1905 TAILQ_REMOVE(&process_list->flow_list, flow_node,
1907 rte_free(flow_node);
1918 /* Destroy all flow rules associated with a port on hns3. */
1920 hns3_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
1922 struct hns3_adapter *hns = dev->data->dev_private;
1925 /* FDIR is available only in PF driver */
1927 ret = hns3_clear_all_fdir_filter(hns);
1929 rte_flow_error_set(error, ret,
1930 RTE_FLOW_ERROR_TYPE_HANDLE,
1931 NULL, "Failed to flush rule");
1934 hns3_counter_flush(dev);
1937 ret = hns3_clear_rss_filter(dev);
1939 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE,
1940 NULL, "Failed to flush rss filter");
1944 hns3_filterlist_flush(dev);
1949 /* Query an existing flow rule. */
1951 hns3_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow,
1952 const struct rte_flow_action *actions, void *data,
1953 struct rte_flow_error *error)
1955 struct rte_flow_action_rss *rss_conf;
1956 struct hns3_rss_conf_ele *rss_rule;
1957 struct rte_flow_query_count *qc;
1961 return rte_flow_error_set(error, EINVAL,
1962 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "invalid rule");
1964 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1965 switch (actions->type) {
1966 case RTE_FLOW_ACTION_TYPE_VOID:
1968 case RTE_FLOW_ACTION_TYPE_COUNT:
1969 qc = (struct rte_flow_query_count *)data;
1970 ret = hns3_counter_query(dev, flow, qc, error);
1974 case RTE_FLOW_ACTION_TYPE_RSS:
1975 if (flow->filter_type != RTE_ETH_FILTER_HASH) {
1976 return rte_flow_error_set(error, ENOTSUP,
1977 RTE_FLOW_ERROR_TYPE_ACTION,
1978 actions, "action is not supported");
1980 rss_conf = (struct rte_flow_action_rss *)data;
1981 rss_rule = (struct hns3_rss_conf_ele *)flow->rule;
1982 rte_memcpy(rss_conf, &rss_rule->filter_info.conf,
1983 sizeof(struct rte_flow_action_rss));
1986 return rte_flow_error_set(error, ENOTSUP,
1987 RTE_FLOW_ERROR_TYPE_ACTION,
1988 actions, "action is not supported");
1995 static const struct rte_flow_ops hns3_flow_ops = {
1996 .validate = hns3_flow_validate,
1997 .create = hns3_flow_create,
1998 .destroy = hns3_flow_destroy,
1999 .flush = hns3_flow_flush,
2000 .query = hns3_flow_query,
2005 * The entry of flow API.
2007 * Pointer to Ethernet device.
2009 * 0 on success, a negative errno value otherwise is set.
2012 hns3_dev_filter_ctrl(struct rte_eth_dev *dev, enum rte_filter_type filter_type,
2013 enum rte_filter_op filter_op, void *arg)
2018 hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2019 switch (filter_type) {
2020 case RTE_ETH_FILTER_GENERIC:
2021 if (filter_op != RTE_ETH_FILTER_GET)
2023 if (hw->adapter_state >= HNS3_NIC_CLOSED)
2025 *(const void **)arg = &hns3_flow_ops;
2028 hns3_err(hw, "Filter type (%d) not supported", filter_type);