1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2018-2021 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
50 static enum rte_flow_item_type L2_next_items[] = {
51 RTE_FLOW_ITEM_TYPE_VLAN,
52 RTE_FLOW_ITEM_TYPE_IPV4,
53 RTE_FLOW_ITEM_TYPE_IPV6
56 static enum rte_flow_item_type L3_next_items[] = {
57 RTE_FLOW_ITEM_TYPE_TCP,
58 RTE_FLOW_ITEM_TYPE_UDP,
59 RTE_FLOW_ITEM_TYPE_SCTP,
60 RTE_FLOW_ITEM_TYPE_NVGRE,
61 RTE_FLOW_ITEM_TYPE_ICMP
64 static enum rte_flow_item_type L4_next_items[] = {
65 RTE_FLOW_ITEM_TYPE_VXLAN,
66 RTE_FLOW_ITEM_TYPE_GENEVE,
67 RTE_FLOW_ITEM_TYPE_VXLAN_GPE
70 static enum rte_flow_item_type tunnel_next_items[] = {
71 RTE_FLOW_ITEM_TYPE_ETH,
72 RTE_FLOW_ITEM_TYPE_VLAN
75 struct items_step_mngr {
76 enum rte_flow_item_type *items;
81 net_addr_to_host(uint32_t *dst, const rte_be32_t *src, size_t len)
85 for (i = 0; i < len; i++)
86 dst[i] = rte_be_to_cpu_32(src[i]);
90 * This function is used to find rss general action.
91 * 1. As we know RSS is used to spread packets among several queues, the flow
92 * API provide the struct rte_flow_action_rss, user could config its field
93 * sush as: func/level/types/key/queue to control RSS function.
94 * 2. The flow API also supports queue region configuration for hns3. It was
95 * implemented by FDIR + RSS in hns3 hardware, user can create one FDIR rule
96 * which action is RSS queues region.
97 * 3. When action is RSS, we use the following rule to distinguish:
98 * Case 1: pattern have ETH and action's queue_num > 0, indicate it is queue
99 * region configuration.
100 * Case other: an rss general action.
102 static const struct rte_flow_action *
103 hns3_find_rss_general_action(const struct rte_flow_item pattern[],
104 const struct rte_flow_action actions[])
106 const struct rte_flow_action *act = NULL;
107 const struct hns3_rss_conf *rss;
108 bool have_eth = false;
110 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
111 if (actions->type == RTE_FLOW_ACTION_TYPE_RSS) {
119 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
120 if (pattern->type == RTE_FLOW_ITEM_TYPE_ETH) {
127 if (have_eth && rss->conf.queue_num) {
129 * Pattern have ETH and action's queue_num > 0, indicate this is
130 * queue region configuration.
131 * Because queue region is implemented by FDIR + RSS in hns3
132 * hardware, it needs to enter FDIR process, so here return NULL
133 * to avoid enter RSS process.
141 static inline struct hns3_flow_counter *
142 hns3_counter_lookup(struct rte_eth_dev *dev, uint32_t id)
144 struct hns3_adapter *hns = dev->data->dev_private;
145 struct hns3_pf *pf = &hns->pf;
146 struct hns3_flow_counter *cnt;
148 LIST_FOREACH(cnt, &pf->flow_counters, next) {
156 hns3_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
157 struct rte_flow_error *error)
159 struct hns3_adapter *hns = dev->data->dev_private;
160 struct hns3_pf *pf = &hns->pf;
161 struct hns3_hw *hw = &hns->hw;
162 struct hns3_flow_counter *cnt;
166 cnt = hns3_counter_lookup(dev, id);
168 if (!cnt->shared || cnt->shared != shared)
169 return rte_flow_error_set(error, ENOTSUP,
170 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
172 "Counter id is used, shared flag not match");
177 /* Clear the counter by read ops because the counter is read-clear */
178 ret = hns3_get_count(hw, id, &value);
180 return rte_flow_error_set(error, EIO,
181 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
182 "Clear counter failed!");
184 cnt = rte_zmalloc("hns3 counter", sizeof(*cnt), 0);
186 return rte_flow_error_set(error, ENOMEM,
187 RTE_FLOW_ERROR_TYPE_HANDLE, cnt,
188 "Alloc mem for counter failed");
190 cnt->shared = shared;
193 LIST_INSERT_HEAD(&pf->flow_counters, cnt, next);
198 hns3_counter_query(struct rte_eth_dev *dev, struct rte_flow *flow,
199 struct rte_flow_query_count *qc,
200 struct rte_flow_error *error)
202 struct hns3_adapter *hns = dev->data->dev_private;
203 struct hns3_flow_counter *cnt;
207 /* FDIR is available only in PF driver */
209 return rte_flow_error_set(error, ENOTSUP,
210 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
211 "Fdir is not supported in VF");
212 cnt = hns3_counter_lookup(dev, flow->counter_id);
214 return rte_flow_error_set(error, EINVAL,
215 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
216 "Can't find counter id");
218 ret = hns3_get_count(&hns->hw, flow->counter_id, &value);
220 rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE,
221 NULL, "Read counter fail.");
231 hns3_counter_release(struct rte_eth_dev *dev, uint32_t id)
233 struct hns3_adapter *hns = dev->data->dev_private;
234 struct hns3_hw *hw = &hns->hw;
235 struct hns3_flow_counter *cnt;
237 cnt = hns3_counter_lookup(dev, id);
239 hns3_err(hw, "Can't find available counter to release");
243 if (cnt->ref_cnt == 0) {
244 LIST_REMOVE(cnt, next);
251 hns3_counter_flush(struct rte_eth_dev *dev)
253 struct hns3_adapter *hns = dev->data->dev_private;
254 struct hns3_pf *pf = &hns->pf;
255 struct hns3_flow_counter *cnt_ptr;
257 cnt_ptr = LIST_FIRST(&pf->flow_counters);
259 LIST_REMOVE(cnt_ptr, next);
261 cnt_ptr = LIST_FIRST(&pf->flow_counters);
266 hns3_handle_action_queue(struct rte_eth_dev *dev,
267 const struct rte_flow_action *action,
268 struct hns3_fdir_rule *rule,
269 struct rte_flow_error *error)
271 struct hns3_adapter *hns = dev->data->dev_private;
272 const struct rte_flow_action_queue *queue;
273 struct hns3_hw *hw = &hns->hw;
275 queue = (const struct rte_flow_action_queue *)action->conf;
276 if (queue->index >= hw->used_rx_queues) {
277 hns3_err(hw, "queue ID(%u) is greater than number of "
278 "available queue (%u) in driver.",
279 queue->index, hw->used_rx_queues);
280 return rte_flow_error_set(error, EINVAL,
281 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
282 action, "Invalid queue ID in PF");
285 rule->queue_id = queue->index;
287 rule->action = HNS3_FD_ACTION_ACCEPT_PACKET;
292 hns3_handle_action_queue_region(struct rte_eth_dev *dev,
293 const struct rte_flow_action *action,
294 struct hns3_fdir_rule *rule,
295 struct rte_flow_error *error)
297 struct hns3_adapter *hns = dev->data->dev_private;
298 const struct rte_flow_action_rss *conf = action->conf;
299 struct hns3_hw *hw = &hns->hw;
302 if (!hns3_dev_fd_queue_region_supported(hw))
303 return rte_flow_error_set(error, ENOTSUP,
304 RTE_FLOW_ERROR_TYPE_ACTION, action,
305 "Not support config queue region!");
307 if ((!rte_is_power_of_2(conf->queue_num)) ||
308 conf->queue_num > hw->rss_size_max ||
309 conf->queue[0] >= hw->used_rx_queues ||
310 conf->queue[0] + conf->queue_num > hw->used_rx_queues) {
311 return rte_flow_error_set(error, EINVAL,
312 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action,
313 "Invalid start queue ID and queue num! the start queue "
314 "ID must valid, the queue num must be power of 2 and "
318 for (idx = 1; idx < conf->queue_num; idx++) {
319 if (conf->queue[idx] != conf->queue[idx - 1] + 1)
320 return rte_flow_error_set(error, EINVAL,
321 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action,
322 "Invalid queue ID sequence! the queue ID "
323 "must be continuous increment.");
326 rule->queue_id = conf->queue[0];
327 rule->nb_queues = conf->queue_num;
328 rule->action = HNS3_FD_ACTION_ACCEPT_PACKET;
333 * Parse actions structure from the provided pattern.
334 * The pattern is validated as the items are copied.
338 * NIC specfilc actions derived from the actions.
342 hns3_handle_actions(struct rte_eth_dev *dev,
343 const struct rte_flow_action actions[],
344 struct hns3_fdir_rule *rule, struct rte_flow_error *error)
346 struct hns3_adapter *hns = dev->data->dev_private;
347 const struct rte_flow_action_count *act_count;
348 const struct rte_flow_action_mark *mark;
349 struct hns3_pf *pf = &hns->pf;
350 uint32_t counter_num;
353 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
354 switch (actions->type) {
355 case RTE_FLOW_ACTION_TYPE_QUEUE:
356 ret = hns3_handle_action_queue(dev, actions, rule,
361 case RTE_FLOW_ACTION_TYPE_DROP:
362 rule->action = HNS3_FD_ACTION_DROP_PACKET;
365 * Here RSS's real action is queue region.
366 * Queue region is implemented by FDIR + RSS in hns3 hardware,
367 * the FDIR's action is one queue region (start_queue_id and
368 * queue_num), then RSS spread packets to the queue region by
371 case RTE_FLOW_ACTION_TYPE_RSS:
372 ret = hns3_handle_action_queue_region(dev, actions,
377 case RTE_FLOW_ACTION_TYPE_MARK:
379 (const struct rte_flow_action_mark *)actions->conf;
380 if (mark->id >= HNS3_MAX_FILTER_ID)
381 return rte_flow_error_set(error, EINVAL,
382 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
385 rule->fd_id = mark->id;
386 rule->flags |= HNS3_RULE_FLAG_FDID;
388 case RTE_FLOW_ACTION_TYPE_FLAG:
389 rule->fd_id = HNS3_MAX_FILTER_ID;
390 rule->flags |= HNS3_RULE_FLAG_FDID;
392 case RTE_FLOW_ACTION_TYPE_COUNT:
394 (const struct rte_flow_action_count *)actions->conf;
395 counter_num = pf->fdir.fd_cfg.cnt_num[HNS3_FD_STAGE_1];
396 if (act_count->id >= counter_num)
397 return rte_flow_error_set(error, EINVAL,
398 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
400 "Invalid counter id");
401 rule->act_cnt = *act_count;
402 rule->flags |= HNS3_RULE_FLAG_COUNTER;
404 case RTE_FLOW_ACTION_TYPE_VOID:
407 return rte_flow_error_set(error, ENOTSUP,
408 RTE_FLOW_ERROR_TYPE_ACTION,
409 NULL, "Unsupported action");
417 hns3_check_attr(const struct rte_flow_attr *attr, struct rte_flow_error *error)
420 return rte_flow_error_set(error, EINVAL,
421 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
422 attr, "Ingress can't be zero");
424 return rte_flow_error_set(error, ENOTSUP,
425 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
426 attr, "Not support egress");
428 return rte_flow_error_set(error, ENOTSUP,
429 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
430 attr, "No support for transfer");
432 return rte_flow_error_set(error, ENOTSUP,
433 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
434 attr, "Not support priority");
436 return rte_flow_error_set(error, ENOTSUP,
437 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
438 attr, "Not support group");
443 hns3_parse_eth(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
444 struct rte_flow_error *error __rte_unused)
446 const struct rte_flow_item_eth *eth_spec;
447 const struct rte_flow_item_eth *eth_mask;
449 /* Only used to describe the protocol stack. */
450 if (item->spec == NULL && item->mask == NULL)
454 eth_mask = item->mask;
455 if (eth_mask->type) {
456 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
457 rule->key_conf.mask.ether_type =
458 rte_be_to_cpu_16(eth_mask->type);
460 if (!rte_is_zero_ether_addr(ð_mask->src)) {
461 hns3_set_bit(rule->input_set, INNER_SRC_MAC, 1);
462 memcpy(rule->key_conf.mask.src_mac,
463 eth_mask->src.addr_bytes, RTE_ETHER_ADDR_LEN);
465 if (!rte_is_zero_ether_addr(ð_mask->dst)) {
466 hns3_set_bit(rule->input_set, INNER_DST_MAC, 1);
467 memcpy(rule->key_conf.mask.dst_mac,
468 eth_mask->dst.addr_bytes, RTE_ETHER_ADDR_LEN);
472 eth_spec = item->spec;
473 rule->key_conf.spec.ether_type = rte_be_to_cpu_16(eth_spec->type);
474 memcpy(rule->key_conf.spec.src_mac, eth_spec->src.addr_bytes,
476 memcpy(rule->key_conf.spec.dst_mac, eth_spec->dst.addr_bytes,
482 hns3_parse_vlan(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
483 struct rte_flow_error *error)
485 const struct rte_flow_item_vlan *vlan_spec;
486 const struct rte_flow_item_vlan *vlan_mask;
488 rule->key_conf.vlan_num++;
489 if (rule->key_conf.vlan_num > VLAN_TAG_NUM_MAX)
490 return rte_flow_error_set(error, EINVAL,
491 RTE_FLOW_ERROR_TYPE_ITEM, item,
492 "Vlan_num is more than 2");
494 /* Only used to describe the protocol stack. */
495 if (item->spec == NULL && item->mask == NULL)
499 vlan_mask = item->mask;
500 if (vlan_mask->tci) {
501 if (rule->key_conf.vlan_num == 1) {
502 hns3_set_bit(rule->input_set, INNER_VLAN_TAG1,
504 rule->key_conf.mask.vlan_tag1 =
505 rte_be_to_cpu_16(vlan_mask->tci);
507 hns3_set_bit(rule->input_set, INNER_VLAN_TAG2,
509 rule->key_conf.mask.vlan_tag2 =
510 rte_be_to_cpu_16(vlan_mask->tci);
515 vlan_spec = item->spec;
516 if (rule->key_conf.vlan_num == 1)
517 rule->key_conf.spec.vlan_tag1 =
518 rte_be_to_cpu_16(vlan_spec->tci);
520 rule->key_conf.spec.vlan_tag2 =
521 rte_be_to_cpu_16(vlan_spec->tci);
526 hns3_check_ipv4_mask_supported(const struct rte_flow_item_ipv4 *ipv4_mask)
528 if (ipv4_mask->hdr.total_length || ipv4_mask->hdr.packet_id ||
529 ipv4_mask->hdr.fragment_offset || ipv4_mask->hdr.time_to_live ||
530 ipv4_mask->hdr.hdr_checksum)
537 hns3_parse_ipv4(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
538 struct rte_flow_error *error)
540 const struct rte_flow_item_ipv4 *ipv4_spec;
541 const struct rte_flow_item_ipv4 *ipv4_mask;
543 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
544 rule->key_conf.spec.ether_type = RTE_ETHER_TYPE_IPV4;
545 rule->key_conf.mask.ether_type = ETHER_TYPE_MASK;
547 /* Only used to describe the protocol stack. */
548 if (item->spec == NULL && item->mask == NULL)
552 ipv4_mask = item->mask;
553 if (!hns3_check_ipv4_mask_supported(ipv4_mask)) {
554 return rte_flow_error_set(error, EINVAL,
555 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
557 "Only support src & dst ip,tos,proto in IPV4");
560 if (ipv4_mask->hdr.src_addr) {
561 hns3_set_bit(rule->input_set, INNER_SRC_IP, 1);
562 rule->key_conf.mask.src_ip[IP_ADDR_KEY_ID] =
563 rte_be_to_cpu_32(ipv4_mask->hdr.src_addr);
566 if (ipv4_mask->hdr.dst_addr) {
567 hns3_set_bit(rule->input_set, INNER_DST_IP, 1);
568 rule->key_conf.mask.dst_ip[IP_ADDR_KEY_ID] =
569 rte_be_to_cpu_32(ipv4_mask->hdr.dst_addr);
572 if (ipv4_mask->hdr.type_of_service) {
573 hns3_set_bit(rule->input_set, INNER_IP_TOS, 1);
574 rule->key_conf.mask.ip_tos =
575 ipv4_mask->hdr.type_of_service;
578 if (ipv4_mask->hdr.next_proto_id) {
579 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
580 rule->key_conf.mask.ip_proto =
581 ipv4_mask->hdr.next_proto_id;
585 ipv4_spec = item->spec;
586 rule->key_conf.spec.src_ip[IP_ADDR_KEY_ID] =
587 rte_be_to_cpu_32(ipv4_spec->hdr.src_addr);
588 rule->key_conf.spec.dst_ip[IP_ADDR_KEY_ID] =
589 rte_be_to_cpu_32(ipv4_spec->hdr.dst_addr);
590 rule->key_conf.spec.ip_tos = ipv4_spec->hdr.type_of_service;
591 rule->key_conf.spec.ip_proto = ipv4_spec->hdr.next_proto_id;
596 hns3_parse_ipv6(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
597 struct rte_flow_error *error)
599 const struct rte_flow_item_ipv6 *ipv6_spec;
600 const struct rte_flow_item_ipv6 *ipv6_mask;
602 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
603 rule->key_conf.spec.ether_type = RTE_ETHER_TYPE_IPV6;
604 rule->key_conf.mask.ether_type = ETHER_TYPE_MASK;
606 /* Only used to describe the protocol stack. */
607 if (item->spec == NULL && item->mask == NULL)
611 ipv6_mask = item->mask;
612 if (ipv6_mask->hdr.vtc_flow || ipv6_mask->hdr.payload_len ||
613 ipv6_mask->hdr.hop_limits) {
614 return rte_flow_error_set(error, EINVAL,
615 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
617 "Only support src & dst ip,proto in IPV6");
619 net_addr_to_host(rule->key_conf.mask.src_ip,
620 (const rte_be32_t *)ipv6_mask->hdr.src_addr,
622 net_addr_to_host(rule->key_conf.mask.dst_ip,
623 (const rte_be32_t *)ipv6_mask->hdr.dst_addr,
625 rule->key_conf.mask.ip_proto = ipv6_mask->hdr.proto;
626 if (rule->key_conf.mask.src_ip[IP_ADDR_KEY_ID])
627 hns3_set_bit(rule->input_set, INNER_SRC_IP, 1);
628 if (rule->key_conf.mask.dst_ip[IP_ADDR_KEY_ID])
629 hns3_set_bit(rule->input_set, INNER_DST_IP, 1);
630 if (ipv6_mask->hdr.proto)
631 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
634 ipv6_spec = item->spec;
635 net_addr_to_host(rule->key_conf.spec.src_ip,
636 (const rte_be32_t *)ipv6_spec->hdr.src_addr,
638 net_addr_to_host(rule->key_conf.spec.dst_ip,
639 (const rte_be32_t *)ipv6_spec->hdr.dst_addr,
641 rule->key_conf.spec.ip_proto = ipv6_spec->hdr.proto;
647 hns3_check_tcp_mask_supported(const struct rte_flow_item_tcp *tcp_mask)
649 if (tcp_mask->hdr.sent_seq || tcp_mask->hdr.recv_ack ||
650 tcp_mask->hdr.data_off || tcp_mask->hdr.tcp_flags ||
651 tcp_mask->hdr.rx_win || tcp_mask->hdr.cksum ||
652 tcp_mask->hdr.tcp_urp)
659 hns3_parse_tcp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
660 struct rte_flow_error *error)
662 const struct rte_flow_item_tcp *tcp_spec;
663 const struct rte_flow_item_tcp *tcp_mask;
665 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
666 rule->key_conf.spec.ip_proto = IPPROTO_TCP;
667 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
669 /* Only used to describe the protocol stack. */
670 if (item->spec == NULL && item->mask == NULL)
674 tcp_mask = item->mask;
675 if (!hns3_check_tcp_mask_supported(tcp_mask)) {
676 return rte_flow_error_set(error, EINVAL,
677 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
679 "Only support src & dst port in TCP");
682 if (tcp_mask->hdr.src_port) {
683 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
684 rule->key_conf.mask.src_port =
685 rte_be_to_cpu_16(tcp_mask->hdr.src_port);
687 if (tcp_mask->hdr.dst_port) {
688 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
689 rule->key_conf.mask.dst_port =
690 rte_be_to_cpu_16(tcp_mask->hdr.dst_port);
694 tcp_spec = item->spec;
695 rule->key_conf.spec.src_port = rte_be_to_cpu_16(tcp_spec->hdr.src_port);
696 rule->key_conf.spec.dst_port = rte_be_to_cpu_16(tcp_spec->hdr.dst_port);
702 hns3_parse_udp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
703 struct rte_flow_error *error)
705 const struct rte_flow_item_udp *udp_spec;
706 const struct rte_flow_item_udp *udp_mask;
708 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
709 rule->key_conf.spec.ip_proto = IPPROTO_UDP;
710 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
712 /* Only used to describe the protocol stack. */
713 if (item->spec == NULL && item->mask == NULL)
717 udp_mask = item->mask;
718 if (udp_mask->hdr.dgram_len || udp_mask->hdr.dgram_cksum) {
719 return rte_flow_error_set(error, EINVAL,
720 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
722 "Only support src & dst port in UDP");
724 if (udp_mask->hdr.src_port) {
725 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
726 rule->key_conf.mask.src_port =
727 rte_be_to_cpu_16(udp_mask->hdr.src_port);
729 if (udp_mask->hdr.dst_port) {
730 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
731 rule->key_conf.mask.dst_port =
732 rte_be_to_cpu_16(udp_mask->hdr.dst_port);
736 udp_spec = item->spec;
737 rule->key_conf.spec.src_port = rte_be_to_cpu_16(udp_spec->hdr.src_port);
738 rule->key_conf.spec.dst_port = rte_be_to_cpu_16(udp_spec->hdr.dst_port);
744 hns3_parse_sctp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
745 struct rte_flow_error *error)
747 const struct rte_flow_item_sctp *sctp_spec;
748 const struct rte_flow_item_sctp *sctp_mask;
750 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
751 rule->key_conf.spec.ip_proto = IPPROTO_SCTP;
752 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
754 /* Only used to describe the protocol stack. */
755 if (item->spec == NULL && item->mask == NULL)
759 sctp_mask = item->mask;
760 if (sctp_mask->hdr.cksum)
761 return rte_flow_error_set(error, EINVAL,
762 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
764 "Only support src & dst port in SCTP");
765 if (sctp_mask->hdr.src_port) {
766 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
767 rule->key_conf.mask.src_port =
768 rte_be_to_cpu_16(sctp_mask->hdr.src_port);
770 if (sctp_mask->hdr.dst_port) {
771 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
772 rule->key_conf.mask.dst_port =
773 rte_be_to_cpu_16(sctp_mask->hdr.dst_port);
775 if (sctp_mask->hdr.tag) {
776 hns3_set_bit(rule->input_set, INNER_SCTP_TAG, 1);
777 rule->key_conf.mask.sctp_tag =
778 rte_be_to_cpu_32(sctp_mask->hdr.tag);
782 sctp_spec = item->spec;
783 rule->key_conf.spec.src_port =
784 rte_be_to_cpu_16(sctp_spec->hdr.src_port);
785 rule->key_conf.spec.dst_port =
786 rte_be_to_cpu_16(sctp_spec->hdr.dst_port);
787 rule->key_conf.spec.sctp_tag = rte_be_to_cpu_32(sctp_spec->hdr.tag);
793 * Check items before tunnel, save inner configs to outer configs, and clear
795 * The key consists of two parts: meta_data and tuple keys.
796 * Meta data uses 15 bits, including vlan_num(2bit), des_port(12bit) and tunnel
798 * Tuple keys uses 384bit, including ot_dst-mac(48bit), ot_dst-port(16bit),
799 * ot_tun_vni(24bit), ot_flow_id(8bit), src-mac(48bit), dst-mac(48bit),
800 * src-ip(32/128bit), dst-ip(32/128bit), src-port(16bit), dst-port(16bit),
801 * tos(8bit), ether-proto(16bit), ip-proto(8bit), vlantag1(16bit),
802 * Vlantag2(16bit) and sctp-tag(32bit).
805 hns3_handle_tunnel(const struct rte_flow_item *item,
806 struct hns3_fdir_rule *rule, struct rte_flow_error *error)
808 /* check eth config */
809 if (rule->input_set & (BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC)))
810 return rte_flow_error_set(error, EINVAL,
811 RTE_FLOW_ERROR_TYPE_ITEM,
812 item, "Outer eth mac is unsupported");
813 if (rule->input_set & BIT(INNER_ETH_TYPE)) {
814 hns3_set_bit(rule->input_set, OUTER_ETH_TYPE, 1);
815 rule->key_conf.spec.outer_ether_type =
816 rule->key_conf.spec.ether_type;
817 rule->key_conf.mask.outer_ether_type =
818 rule->key_conf.mask.ether_type;
819 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 0);
820 rule->key_conf.spec.ether_type = 0;
821 rule->key_conf.mask.ether_type = 0;
824 /* check vlan config */
825 if (rule->input_set & (BIT(INNER_VLAN_TAG1) | BIT(INNER_VLAN_TAG2)))
826 return rte_flow_error_set(error, EINVAL,
827 RTE_FLOW_ERROR_TYPE_ITEM,
829 "Outer vlan tags is unsupported");
831 /* clear vlan_num for inner vlan select */
832 rule->key_conf.outer_vlan_num = rule->key_conf.vlan_num;
833 rule->key_conf.vlan_num = 0;
835 /* check L3 config */
836 if (rule->input_set &
837 (BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) | BIT(INNER_IP_TOS)))
838 return rte_flow_error_set(error, EINVAL,
839 RTE_FLOW_ERROR_TYPE_ITEM,
840 item, "Outer ip is unsupported");
841 if (rule->input_set & BIT(INNER_IP_PROTO)) {
842 hns3_set_bit(rule->input_set, OUTER_IP_PROTO, 1);
843 rule->key_conf.spec.outer_proto = rule->key_conf.spec.ip_proto;
844 rule->key_conf.mask.outer_proto = rule->key_conf.mask.ip_proto;
845 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 0);
846 rule->key_conf.spec.ip_proto = 0;
847 rule->key_conf.mask.ip_proto = 0;
850 /* check L4 config */
851 if (rule->input_set & BIT(INNER_SCTP_TAG))
852 return rte_flow_error_set(error, EINVAL,
853 RTE_FLOW_ERROR_TYPE_ITEM, item,
854 "Outer sctp tag is unsupported");
856 if (rule->input_set & BIT(INNER_SRC_PORT)) {
857 hns3_set_bit(rule->input_set, OUTER_SRC_PORT, 1);
858 rule->key_conf.spec.outer_src_port =
859 rule->key_conf.spec.src_port;
860 rule->key_conf.mask.outer_src_port =
861 rule->key_conf.mask.src_port;
862 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 0);
863 rule->key_conf.spec.src_port = 0;
864 rule->key_conf.mask.src_port = 0;
866 if (rule->input_set & BIT(INNER_DST_PORT)) {
867 hns3_set_bit(rule->input_set, INNER_DST_PORT, 0);
868 rule->key_conf.spec.dst_port = 0;
869 rule->key_conf.mask.dst_port = 0;
875 hns3_parse_vxlan(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
876 struct rte_flow_error *error)
878 const struct rte_flow_item_vxlan *vxlan_spec;
879 const struct rte_flow_item_vxlan *vxlan_mask;
881 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
882 rule->key_conf.mask.tunnel_type = TUNNEL_TYPE_MASK;
883 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN)
884 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_VXLAN;
886 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_VXLAN_GPE;
888 /* Only used to describe the protocol stack. */
889 if (item->spec == NULL && item->mask == NULL)
892 vxlan_mask = item->mask;
893 vxlan_spec = item->spec;
895 if (vxlan_mask->flags)
896 return rte_flow_error_set(error, EINVAL,
897 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
898 "Flags is not supported in VxLAN");
900 /* VNI must be totally masked or not. */
901 if (memcmp(vxlan_mask->vni, full_mask, VNI_OR_TNI_LEN) &&
902 memcmp(vxlan_mask->vni, zero_mask, VNI_OR_TNI_LEN))
903 return rte_flow_error_set(error, EINVAL,
904 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
905 "VNI must be totally masked or not in VxLAN");
906 if (vxlan_mask->vni[0]) {
907 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
908 memcpy(rule->key_conf.mask.outer_tun_vni, vxlan_mask->vni,
911 memcpy(rule->key_conf.spec.outer_tun_vni, vxlan_spec->vni,
917 hns3_parse_nvgre(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
918 struct rte_flow_error *error)
920 const struct rte_flow_item_nvgre *nvgre_spec;
921 const struct rte_flow_item_nvgre *nvgre_mask;
923 hns3_set_bit(rule->input_set, OUTER_IP_PROTO, 1);
924 rule->key_conf.spec.outer_proto = IPPROTO_GRE;
925 rule->key_conf.mask.outer_proto = IPPROTO_MASK;
927 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
928 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_NVGRE;
929 rule->key_conf.mask.tunnel_type = ~HNS3_TUNNEL_TYPE_NVGRE;
930 /* Only used to describe the protocol stack. */
931 if (item->spec == NULL && item->mask == NULL)
934 nvgre_mask = item->mask;
935 nvgre_spec = item->spec;
937 if (nvgre_mask->protocol || nvgre_mask->c_k_s_rsvd0_ver)
938 return rte_flow_error_set(error, EINVAL,
939 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
940 "Ver/protocal is not supported in NVGRE");
942 /* TNI must be totally masked or not. */
943 if (memcmp(nvgre_mask->tni, full_mask, VNI_OR_TNI_LEN) &&
944 memcmp(nvgre_mask->tni, zero_mask, VNI_OR_TNI_LEN))
945 return rte_flow_error_set(error, EINVAL,
946 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
947 "TNI must be totally masked or not in NVGRE");
949 if (nvgre_mask->tni[0]) {
950 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
951 memcpy(rule->key_conf.mask.outer_tun_vni, nvgre_mask->tni,
954 memcpy(rule->key_conf.spec.outer_tun_vni, nvgre_spec->tni,
957 if (nvgre_mask->flow_id) {
958 hns3_set_bit(rule->input_set, OUTER_TUN_FLOW_ID, 1);
959 rule->key_conf.mask.outer_tun_flow_id = nvgre_mask->flow_id;
961 rule->key_conf.spec.outer_tun_flow_id = nvgre_spec->flow_id;
966 hns3_parse_geneve(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
967 struct rte_flow_error *error)
969 const struct rte_flow_item_geneve *geneve_spec;
970 const struct rte_flow_item_geneve *geneve_mask;
972 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
973 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_GENEVE;
974 rule->key_conf.mask.tunnel_type = TUNNEL_TYPE_MASK;
975 /* Only used to describe the protocol stack. */
976 if (item->spec == NULL && item->mask == NULL)
979 geneve_mask = item->mask;
980 geneve_spec = item->spec;
982 if (geneve_mask->ver_opt_len_o_c_rsvd0 || geneve_mask->protocol)
983 return rte_flow_error_set(error, EINVAL,
984 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
985 "Ver/protocal is not supported in GENEVE");
986 /* VNI must be totally masked or not. */
987 if (memcmp(geneve_mask->vni, full_mask, VNI_OR_TNI_LEN) &&
988 memcmp(geneve_mask->vni, zero_mask, VNI_OR_TNI_LEN))
989 return rte_flow_error_set(error, EINVAL,
990 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
991 "VNI must be totally masked or not in GENEVE");
992 if (geneve_mask->vni[0]) {
993 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
994 memcpy(rule->key_conf.mask.outer_tun_vni, geneve_mask->vni,
997 memcpy(rule->key_conf.spec.outer_tun_vni, geneve_spec->vni,
1003 hns3_parse_tunnel(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
1004 struct rte_flow_error *error)
1008 if (item->spec == NULL && item->mask)
1009 return rte_flow_error_set(error, EINVAL,
1010 RTE_FLOW_ERROR_TYPE_ITEM, item,
1011 "Can't configure FDIR with mask "
1012 "but without spec");
1013 else if (item->spec && (item->mask == NULL))
1014 return rte_flow_error_set(error, EINVAL,
1015 RTE_FLOW_ERROR_TYPE_ITEM, item,
1016 "Tunnel packets must configure "
1019 switch (item->type) {
1020 case RTE_FLOW_ITEM_TYPE_VXLAN:
1021 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1022 ret = hns3_parse_vxlan(item, rule, error);
1024 case RTE_FLOW_ITEM_TYPE_NVGRE:
1025 ret = hns3_parse_nvgre(item, rule, error);
1027 case RTE_FLOW_ITEM_TYPE_GENEVE:
1028 ret = hns3_parse_geneve(item, rule, error);
1031 return rte_flow_error_set(error, ENOTSUP,
1032 RTE_FLOW_ERROR_TYPE_ITEM,
1033 NULL, "Unsupported tunnel type!");
1037 return hns3_handle_tunnel(item, rule, error);
1041 hns3_parse_normal(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
1042 struct items_step_mngr *step_mngr,
1043 struct rte_flow_error *error)
1047 if (item->spec == NULL && item->mask)
1048 return rte_flow_error_set(error, EINVAL,
1049 RTE_FLOW_ERROR_TYPE_ITEM, item,
1050 "Can't configure FDIR with mask "
1051 "but without spec");
1053 switch (item->type) {
1054 case RTE_FLOW_ITEM_TYPE_ETH:
1055 ret = hns3_parse_eth(item, rule, error);
1056 step_mngr->items = L2_next_items;
1057 step_mngr->count = RTE_DIM(L2_next_items);
1059 case RTE_FLOW_ITEM_TYPE_VLAN:
1060 ret = hns3_parse_vlan(item, rule, error);
1061 step_mngr->items = L2_next_items;
1062 step_mngr->count = RTE_DIM(L2_next_items);
1064 case RTE_FLOW_ITEM_TYPE_IPV4:
1065 ret = hns3_parse_ipv4(item, rule, error);
1066 step_mngr->items = L3_next_items;
1067 step_mngr->count = RTE_DIM(L3_next_items);
1069 case RTE_FLOW_ITEM_TYPE_IPV6:
1070 ret = hns3_parse_ipv6(item, rule, error);
1071 step_mngr->items = L3_next_items;
1072 step_mngr->count = RTE_DIM(L3_next_items);
1074 case RTE_FLOW_ITEM_TYPE_TCP:
1075 ret = hns3_parse_tcp(item, rule, error);
1076 step_mngr->items = L4_next_items;
1077 step_mngr->count = RTE_DIM(L4_next_items);
1079 case RTE_FLOW_ITEM_TYPE_UDP:
1080 ret = hns3_parse_udp(item, rule, error);
1081 step_mngr->items = L4_next_items;
1082 step_mngr->count = RTE_DIM(L4_next_items);
1084 case RTE_FLOW_ITEM_TYPE_SCTP:
1085 ret = hns3_parse_sctp(item, rule, error);
1086 step_mngr->items = L4_next_items;
1087 step_mngr->count = RTE_DIM(L4_next_items);
1090 return rte_flow_error_set(error, ENOTSUP,
1091 RTE_FLOW_ERROR_TYPE_ITEM,
1092 NULL, "Unsupported normal type!");
1099 hns3_validate_item(const struct rte_flow_item *item,
1100 struct items_step_mngr step_mngr,
1101 struct rte_flow_error *error)
1106 return rte_flow_error_set(error, ENOTSUP,
1107 RTE_FLOW_ERROR_TYPE_ITEM_LAST, item,
1108 "Not supported last point for range");
1110 for (i = 0; i < step_mngr.count; i++) {
1111 if (item->type == step_mngr.items[i])
1115 if (i == step_mngr.count) {
1116 return rte_flow_error_set(error, EINVAL,
1117 RTE_FLOW_ERROR_TYPE_ITEM,
1118 item, "Inval or missing item");
1124 is_tunnel_packet(enum rte_flow_item_type type)
1126 if (type == RTE_FLOW_ITEM_TYPE_VXLAN_GPE ||
1127 type == RTE_FLOW_ITEM_TYPE_VXLAN ||
1128 type == RTE_FLOW_ITEM_TYPE_NVGRE ||
1129 type == RTE_FLOW_ITEM_TYPE_GENEVE)
1135 * Parse the rule to see if it is a IP or MAC VLAN flow director rule.
1136 * And get the flow director filter info BTW.
1137 * UDP/TCP/SCTP PATTERN:
1138 * The first not void item can be ETH or IPV4 or IPV6
1139 * The second not void item must be IPV4 or IPV6 if the first one is ETH.
1140 * The next not void item could be UDP or TCP or SCTP (optional)
1141 * The next not void item could be RAW (for flexbyte, optional)
1142 * The next not void item must be END.
1143 * A Fuzzy Match pattern can appear at any place before END.
1144 * Fuzzy Match is optional for IPV4 but is required for IPV6
1146 * The first not void item must be ETH.
1147 * The second not void item must be MAC VLAN.
1148 * The next not void item must be END.
1150 * The first not void action should be QUEUE or DROP.
1151 * The second not void optional action should be MARK,
1152 * mark_id is a uint32_t number.
1153 * The next not void action should be END.
1154 * UDP/TCP/SCTP pattern example:
1157 * IPV4 src_addr 192.168.1.20 0xFFFFFFFF
1158 * dst_addr 192.167.3.50 0xFFFFFFFF
1159 * UDP/TCP/SCTP src_port 80 0xFFFF
1160 * dst_port 80 0xFFFF
1162 * MAC VLAN pattern example:
1165 {0xAC, 0x7B, 0xA1, {0xFF, 0xFF, 0xFF,
1166 0x2C, 0x6D, 0x36} 0xFF, 0xFF, 0xFF}
1167 * MAC VLAN tci 0x2016 0xEFFF
1169 * Other members in mask and spec should set to 0x00.
1170 * Item->last should be NULL.
1173 hns3_parse_fdir_filter(struct rte_eth_dev *dev,
1174 const struct rte_flow_item pattern[],
1175 const struct rte_flow_action actions[],
1176 struct hns3_fdir_rule *rule,
1177 struct rte_flow_error *error)
1179 struct hns3_adapter *hns = dev->data->dev_private;
1180 const struct rte_flow_item *item;
1181 struct items_step_mngr step_mngr;
1184 /* FDIR is available only in PF driver */
1186 return rte_flow_error_set(error, ENOTSUP,
1187 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1188 "Fdir not supported in VF");
1190 step_mngr.items = first_items;
1191 step_mngr.count = RTE_DIM(first_items);
1192 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1193 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
1196 ret = hns3_validate_item(item, step_mngr, error);
1200 if (is_tunnel_packet(item->type)) {
1201 ret = hns3_parse_tunnel(item, rule, error);
1204 step_mngr.items = tunnel_next_items;
1205 step_mngr.count = RTE_DIM(tunnel_next_items);
1207 ret = hns3_parse_normal(item, rule, &step_mngr, error);
1213 return hns3_handle_actions(dev, actions, rule, error);
1217 hns3_flow_init(struct rte_eth_dev *dev)
1219 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1220 struct hns3_process_private *process_list = dev->process_private;
1221 pthread_mutexattr_t attr;
1223 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
1224 pthread_mutexattr_init(&attr);
1225 pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
1226 pthread_mutex_init(&hw->flows_lock, &attr);
1227 dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
1230 TAILQ_INIT(&process_list->fdir_list);
1231 TAILQ_INIT(&process_list->filter_rss_list);
1232 TAILQ_INIT(&process_list->flow_list);
1236 hns3_filterlist_flush(struct rte_eth_dev *dev)
1238 struct hns3_process_private *process_list = dev->process_private;
1239 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1240 struct hns3_rss_conf_ele *rss_filter_ptr;
1241 struct hns3_flow_mem *flow_node;
1243 fdir_rule_ptr = TAILQ_FIRST(&process_list->fdir_list);
1244 while (fdir_rule_ptr) {
1245 TAILQ_REMOVE(&process_list->fdir_list, fdir_rule_ptr, entries);
1246 rte_free(fdir_rule_ptr);
1247 fdir_rule_ptr = TAILQ_FIRST(&process_list->fdir_list);
1250 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1251 while (rss_filter_ptr) {
1252 TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr,
1254 rte_free(rss_filter_ptr);
1255 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1258 flow_node = TAILQ_FIRST(&process_list->flow_list);
1260 TAILQ_REMOVE(&process_list->flow_list, flow_node, entries);
1261 rte_free(flow_node->flow);
1262 rte_free(flow_node);
1263 flow_node = TAILQ_FIRST(&process_list->flow_list);
1268 hns3_action_rss_same(const struct rte_flow_action_rss *comp,
1269 const struct rte_flow_action_rss *with)
1274 * When user flush all RSS rule, RSS func is set invalid with
1275 * RTE_ETH_HASH_FUNCTION_MAX. Then the user create a flow after
1276 * flushed, any validate RSS func is different with it before
1277 * flushed. Others, when user create an action RSS with RSS func
1278 * specified RTE_ETH_HASH_FUNCTION_DEFAULT, the func is the same
1279 * between continuous RSS flow.
1281 if (comp->func == RTE_ETH_HASH_FUNCTION_MAX)
1282 func_is_same = false;
1284 func_is_same = with->func ? (comp->func == with->func) : true;
1286 return (func_is_same &&
1287 comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) &&
1288 comp->level == with->level && comp->key_len == with->key_len &&
1289 comp->queue_num == with->queue_num &&
1290 !memcmp(comp->key, with->key, with->key_len) &&
1291 !memcmp(comp->queue, with->queue,
1292 sizeof(*with->queue) * with->queue_num));
1296 hns3_rss_conf_copy(struct hns3_rss_conf *out,
1297 const struct rte_flow_action_rss *in)
1299 if (in->key_len > RTE_DIM(out->key) ||
1300 in->queue_num > RTE_DIM(out->queue))
1302 if (in->key == NULL && in->key_len)
1304 out->conf = (struct rte_flow_action_rss) {
1308 .key_len = in->key_len,
1309 .queue_num = in->queue_num,
1311 out->conf.queue = memcpy(out->queue, in->queue,
1312 sizeof(*in->queue) * in->queue_num);
1314 out->conf.key = memcpy(out->key, in->key, in->key_len);
1320 hns3_rss_input_tuple_supported(struct hns3_hw *hw,
1321 const struct rte_flow_action_rss *rss)
1324 * For IP packet, it is not supported to use src/dst port fields to RSS
1325 * hash for the following packet types.
1326 * - IPV4 FRAG | IPV4 NONFRAG | IPV6 FRAG | IPV6 NONFRAG
1327 * Besides, for Kunpeng920, the NIC HW is not supported to use src/dst
1328 * port fields to RSS hash for IPV6 SCTP packet type. However, the
1329 * Kunpeng930 and future kunpeng series support to use src/dst port
1330 * fields to RSS hash for IPv6 SCTP packet type.
1332 if (rss->types & (ETH_RSS_L4_DST_ONLY | ETH_RSS_L4_SRC_ONLY) &&
1333 (rss->types & ETH_RSS_IP ||
1334 (!hw->rss_info.ipv6_sctp_offload_supported &&
1335 rss->types & ETH_RSS_NONFRAG_IPV6_SCTP)))
1342 * This function is used to parse rss action validatation.
1345 hns3_parse_rss_filter(struct rte_eth_dev *dev,
1346 const struct rte_flow_action *actions,
1347 struct rte_flow_error *error)
1349 struct hns3_adapter *hns = dev->data->dev_private;
1350 struct hns3_hw *hw = &hns->hw;
1351 struct hns3_rss_conf *rss_conf = &hw->rss_info;
1352 const struct rte_flow_action_rss *rss;
1353 const struct rte_flow_action *act;
1354 uint32_t act_index = 0;
1357 NEXT_ITEM_OF_ACTION(act, actions, act_index);
1361 return rte_flow_error_set(error, EINVAL,
1362 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1363 act, "no valid queues");
1366 if (rss->queue_num > RTE_DIM(rss_conf->queue))
1367 return rte_flow_error_set(error, ENOTSUP,
1368 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1369 "queue number configured exceeds "
1370 "queue buffer size driver supported");
1372 for (n = 0; n < rss->queue_num; n++) {
1373 if (rss->queue[n] < hw->alloc_rss_size)
1375 return rte_flow_error_set(error, EINVAL,
1376 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1377 "queue id must be less than queue number allocated to a TC");
1380 if (!(rss->types & HNS3_ETH_RSS_SUPPORT) && rss->types)
1381 return rte_flow_error_set(error, EINVAL,
1382 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1384 "Flow types is unsupported by "
1386 if (rss->func >= RTE_ETH_HASH_FUNCTION_MAX)
1387 return rte_flow_error_set(error, ENOTSUP,
1388 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1389 "RSS hash func are not supported");
1391 return rte_flow_error_set(error, ENOTSUP,
1392 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1393 "a nonzero RSS encapsulation level is not supported");
1394 if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
1395 return rte_flow_error_set(error, ENOTSUP,
1396 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1397 "RSS hash key must be exactly 40 bytes");
1399 if (!hns3_rss_input_tuple_supported(hw, rss))
1400 return rte_flow_error_set(error, EINVAL,
1401 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1403 "input RSS types are not supported");
1407 /* Check if the next not void action is END */
1408 NEXT_ITEM_OF_ACTION(act, actions, act_index);
1409 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1410 memset(rss_conf, 0, sizeof(struct hns3_rss_conf));
1411 return rte_flow_error_set(error, EINVAL,
1412 RTE_FLOW_ERROR_TYPE_ACTION,
1413 act, "Not supported action.");
1420 hns3_disable_rss(struct hns3_hw *hw)
1424 /* Redirected the redirection table to queue 0 */
1425 ret = hns3_rss_reset_indir_table(hw);
1430 hw->rss_info.conf.types = 0;
1431 hw->rss_dis_flag = true;
1437 hns3_parse_rss_key(struct hns3_hw *hw, struct rte_flow_action_rss *rss_conf)
1439 if (rss_conf->key == NULL || rss_conf->key_len < HNS3_RSS_KEY_SIZE) {
1440 hns3_warn(hw, "Default RSS hash key to be set");
1441 rss_conf->key = hns3_hash_key;
1442 rss_conf->key_len = HNS3_RSS_KEY_SIZE;
1447 hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func,
1450 enum rte_eth_hash_function algo_func = *func;
1451 switch (algo_func) {
1452 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1453 /* Keep *hash_algo as what it used to be */
1454 algo_func = hw->rss_info.conf.func;
1456 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1457 *hash_algo = HNS3_RSS_HASH_ALGO_TOEPLITZ;
1459 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1460 *hash_algo = HNS3_RSS_HASH_ALGO_SIMPLE;
1462 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1463 *hash_algo = HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP;
1466 hns3_err(hw, "Invalid RSS algorithm configuration(%d)",
1476 hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config)
1478 struct hns3_rss_tuple_cfg *tuple;
1481 hns3_parse_rss_key(hw, rss_config);
1483 ret = hns3_parse_rss_algorithm(hw, &rss_config->func,
1484 &hw->rss_info.hash_algo);
1488 ret = hns3_rss_set_algo_key(hw, rss_config->key);
1492 hw->rss_info.conf.func = rss_config->func;
1494 tuple = &hw->rss_info.rss_tuple_sets;
1495 ret = hns3_set_rss_tuple_by_rss_hf(hw, tuple, rss_config->types);
1497 hns3_err(hw, "Update RSS tuples by rss hf failed %d", ret);
1503 hns3_update_indir_table(struct rte_eth_dev *dev,
1504 const struct rte_flow_action_rss *conf, uint16_t num)
1506 struct hns3_adapter *hns = dev->data->dev_private;
1507 struct hns3_hw *hw = &hns->hw;
1508 uint16_t indir_tbl[HNS3_RSS_IND_TBL_SIZE_MAX];
1512 /* Fill in redirection table */
1513 memcpy(indir_tbl, hw->rss_info.rss_indirection_tbl,
1514 sizeof(hw->rss_info.rss_indirection_tbl));
1515 for (i = 0, j = 0; i < hw->rss_ind_tbl_size; i++, j++) {
1517 if (conf->queue[j] >= hw->alloc_rss_size) {
1518 hns3_err(hw, "queue id(%u) set to redirection table "
1519 "exceeds queue number(%u) allocated to a TC.",
1520 conf->queue[j], hw->alloc_rss_size);
1523 indir_tbl[i] = conf->queue[j];
1526 return hns3_set_rss_indir_table(hw, indir_tbl, hw->rss_ind_tbl_size);
1530 hns3_config_rss_filter(struct rte_eth_dev *dev,
1531 const struct hns3_rss_conf *conf, bool add)
1533 struct hns3_process_private *process_list = dev->process_private;
1534 struct hns3_adapter *hns = dev->data->dev_private;
1535 struct hns3_rss_conf_ele *rss_filter_ptr;
1536 struct hns3_hw *hw = &hns->hw;
1537 struct hns3_rss_conf *rss_info;
1538 uint64_t flow_types;
1542 struct rte_flow_action_rss rss_flow_conf = {
1543 .func = conf->conf.func,
1544 .level = conf->conf.level,
1545 .types = conf->conf.types,
1546 .key_len = conf->conf.key_len,
1547 .queue_num = conf->conf.queue_num,
1548 .key = conf->conf.key_len ?
1549 (void *)(uintptr_t)conf->conf.key : NULL,
1550 .queue = conf->conf.queue,
1553 /* Filter the unsupported flow types */
1554 flow_types = conf->conf.types ?
1555 rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
1556 hw->rss_info.conf.types;
1557 if (flow_types != rss_flow_conf.types)
1558 hns3_warn(hw, "modified RSS types based on hardware support, "
1559 "requested:%" PRIx64 " configured:%" PRIx64,
1560 rss_flow_conf.types, flow_types);
1561 /* Update the useful flow types */
1562 rss_flow_conf.types = flow_types;
1564 rss_info = &hw->rss_info;
1569 ret = hns3_disable_rss(hw);
1571 hns3_err(hw, "RSS disable failed(%d)", ret);
1575 if (rss_flow_conf.queue_num) {
1577 * Due the content of queue pointer have been reset to
1578 * 0, the rss_info->conf.queue should be set to NULL
1580 rss_info->conf.queue = NULL;
1581 rss_info->conf.queue_num = 0;
1584 /* set RSS func invalid after flushed */
1585 rss_info->conf.func = RTE_ETH_HASH_FUNCTION_MAX;
1589 /* Set rx queues to use */
1590 num = RTE_MIN(dev->data->nb_rx_queues, rss_flow_conf.queue_num);
1591 if (rss_flow_conf.queue_num > num)
1592 hns3_warn(hw, "Config queue numbers %u are beyond the scope of truncated",
1593 rss_flow_conf.queue_num);
1594 hns3_info(hw, "Max of contiguous %u PF queues are configured", num);
1596 rte_spinlock_lock(&hw->lock);
1598 ret = hns3_update_indir_table(dev, &rss_flow_conf, num);
1600 goto rss_config_err;
1603 /* Set hash algorithm and flow types by the user's config */
1604 ret = hns3_hw_rss_hash_set(hw, &rss_flow_conf);
1606 goto rss_config_err;
1608 ret = hns3_rss_conf_copy(rss_info, &rss_flow_conf);
1610 hns3_err(hw, "RSS config init fail(%d)", ret);
1611 goto rss_config_err;
1615 * When create a new RSS rule, the old rule will be overlaid and set
1618 TAILQ_FOREACH(rss_filter_ptr, &process_list->filter_rss_list, entries)
1619 rss_filter_ptr->filter_info.valid = false;
1622 rte_spinlock_unlock(&hw->lock);
1628 hns3_clear_rss_filter(struct rte_eth_dev *dev)
1630 struct hns3_process_private *process_list = dev->process_private;
1631 struct hns3_adapter *hns = dev->data->dev_private;
1632 struct hns3_rss_conf_ele *rss_filter_ptr;
1633 struct hns3_hw *hw = &hns->hw;
1634 int rss_rule_succ_cnt = 0; /* count for success of clearing RSS rules */
1635 int rss_rule_fail_cnt = 0; /* count for failure of clearing RSS rules */
1638 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1639 while (rss_filter_ptr) {
1640 TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr,
1642 ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info,
1645 rss_rule_fail_cnt++;
1647 rss_rule_succ_cnt++;
1648 rte_free(rss_filter_ptr);
1649 rss_filter_ptr = TAILQ_FIRST(&process_list->filter_rss_list);
1652 if (rss_rule_fail_cnt) {
1653 hns3_err(hw, "fail to delete all RSS filters, success num = %d "
1654 "fail num = %d", rss_rule_succ_cnt,
1663 hns3_restore_rss_filter(struct rte_eth_dev *dev)
1665 struct hns3_adapter *hns = dev->data->dev_private;
1666 struct hns3_hw *hw = &hns->hw;
1668 /* When user flush all rules, it doesn't need to restore RSS rule */
1669 if (hw->rss_info.conf.func == RTE_ETH_HASH_FUNCTION_MAX)
1672 return hns3_config_rss_filter(dev, &hw->rss_info, true);
1676 hns3_flow_parse_rss(struct rte_eth_dev *dev,
1677 const struct hns3_rss_conf *conf, bool add)
1679 struct hns3_adapter *hns = dev->data->dev_private;
1680 struct hns3_hw *hw = &hns->hw;
1683 ret = hns3_action_rss_same(&hw->rss_info.conf, &conf->conf);
1685 hns3_err(hw, "Enter duplicate RSS configuration : %d", ret);
1689 return hns3_config_rss_filter(dev, conf, add);
1693 hns3_flow_args_check(const struct rte_flow_attr *attr,
1694 const struct rte_flow_item pattern[],
1695 const struct rte_flow_action actions[],
1696 struct rte_flow_error *error)
1698 if (pattern == NULL)
1699 return rte_flow_error_set(error, EINVAL,
1700 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1701 NULL, "NULL pattern.");
1703 if (actions == NULL)
1704 return rte_flow_error_set(error, EINVAL,
1705 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1706 NULL, "NULL action.");
1709 return rte_flow_error_set(error, EINVAL,
1710 RTE_FLOW_ERROR_TYPE_ATTR,
1711 NULL, "NULL attribute.");
1713 return hns3_check_attr(attr, error);
1717 * Check if the flow rule is supported by hns3.
1718 * It only checkes the format. Don't guarantee the rule can be programmed into
1719 * the HW. Because there can be no enough room for the rule.
1722 hns3_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1723 const struct rte_flow_item pattern[],
1724 const struct rte_flow_action actions[],
1725 struct rte_flow_error *error)
1727 struct hns3_fdir_rule fdir_rule;
1730 ret = hns3_flow_args_check(attr, pattern, actions, error);
1734 if (hns3_find_rss_general_action(pattern, actions))
1735 return hns3_parse_rss_filter(dev, actions, error);
1737 memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule));
1738 return hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error);
1742 * Create or destroy a flow rule.
1743 * Theorically one rule can match more than one filters.
1744 * We will let it use the filter which it hit first.
1745 * So, the sequence matters.
1747 static struct rte_flow *
1748 hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1749 const struct rte_flow_item pattern[],
1750 const struct rte_flow_action actions[],
1751 struct rte_flow_error *error)
1753 struct hns3_process_private *process_list = dev->process_private;
1754 struct hns3_adapter *hns = dev->data->dev_private;
1755 struct hns3_hw *hw = &hns->hw;
1756 const struct hns3_rss_conf *rss_conf;
1757 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1758 struct hns3_rss_conf_ele *rss_filter_ptr;
1759 struct hns3_flow_mem *flow_node;
1760 const struct rte_flow_action *act;
1761 struct rte_flow *flow;
1762 struct hns3_fdir_rule fdir_rule;
1765 ret = hns3_flow_validate(dev, attr, pattern, actions, error);
1769 flow = rte_zmalloc("hns3 flow", sizeof(struct rte_flow), 0);
1771 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1772 NULL, "Failed to allocate flow memory");
1775 flow_node = rte_zmalloc("hns3 flow node",
1776 sizeof(struct hns3_flow_mem), 0);
1777 if (flow_node == NULL) {
1778 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1779 NULL, "Failed to allocate flow list memory");
1784 flow_node->flow = flow;
1785 TAILQ_INSERT_TAIL(&process_list->flow_list, flow_node, entries);
1787 act = hns3_find_rss_general_action(pattern, actions);
1789 rss_conf = act->conf;
1791 ret = hns3_flow_parse_rss(dev, rss_conf, true);
1795 rss_filter_ptr = rte_zmalloc("hns3 rss filter",
1796 sizeof(struct hns3_rss_conf_ele),
1798 if (rss_filter_ptr == NULL) {
1800 "Failed to allocate hns3_rss_filter memory");
1804 hns3_rss_conf_copy(&rss_filter_ptr->filter_info,
1806 rss_filter_ptr->filter_info.valid = true;
1807 TAILQ_INSERT_TAIL(&process_list->filter_rss_list,
1808 rss_filter_ptr, entries);
1810 flow->rule = rss_filter_ptr;
1811 flow->filter_type = RTE_ETH_FILTER_HASH;
1815 memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule));
1816 ret = hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error);
1820 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) {
1821 ret = hns3_counter_new(dev, fdir_rule.act_cnt.shared,
1822 fdir_rule.act_cnt.id, error);
1826 flow->counter_id = fdir_rule.act_cnt.id;
1829 fdir_rule_ptr = rte_zmalloc("hns3 fdir rule",
1830 sizeof(struct hns3_fdir_rule_ele),
1832 if (fdir_rule_ptr == NULL) {
1833 hns3_err(hw, "failed to allocate fdir_rule memory.");
1838 ret = hns3_fdir_filter_program(hns, &fdir_rule, false);
1840 memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule,
1841 sizeof(struct hns3_fdir_rule));
1842 TAILQ_INSERT_TAIL(&process_list->fdir_list,
1843 fdir_rule_ptr, entries);
1844 flow->rule = fdir_rule_ptr;
1845 flow->filter_type = RTE_ETH_FILTER_FDIR;
1850 rte_free(fdir_rule_ptr);
1852 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
1853 hns3_counter_release(dev, fdir_rule.act_cnt.id);
1855 rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1856 "Failed to create flow");
1858 TAILQ_REMOVE(&process_list->flow_list, flow_node, entries);
1859 rte_free(flow_node);
1864 /* Destroy a flow rule on hns3. */
1866 hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
1867 struct rte_flow_error *error)
1869 struct hns3_process_private *process_list = dev->process_private;
1870 struct hns3_adapter *hns = dev->data->dev_private;
1871 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1872 struct hns3_rss_conf_ele *rss_filter_ptr;
1873 struct hns3_flow_mem *flow_node;
1874 enum rte_filter_type filter_type;
1875 struct hns3_fdir_rule fdir_rule;
1879 return rte_flow_error_set(error, EINVAL,
1880 RTE_FLOW_ERROR_TYPE_HANDLE,
1881 flow, "Flow is NULL");
1883 filter_type = flow->filter_type;
1884 switch (filter_type) {
1885 case RTE_ETH_FILTER_FDIR:
1886 fdir_rule_ptr = (struct hns3_fdir_rule_ele *)flow->rule;
1887 memcpy(&fdir_rule, &fdir_rule_ptr->fdir_conf,
1888 sizeof(struct hns3_fdir_rule));
1890 ret = hns3_fdir_filter_program(hns, &fdir_rule, true);
1892 return rte_flow_error_set(error, EIO,
1893 RTE_FLOW_ERROR_TYPE_HANDLE,
1895 "Destroy FDIR fail.Try again");
1896 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
1897 hns3_counter_release(dev, fdir_rule.act_cnt.id);
1898 TAILQ_REMOVE(&process_list->fdir_list, fdir_rule_ptr, entries);
1899 rte_free(fdir_rule_ptr);
1900 fdir_rule_ptr = NULL;
1902 case RTE_ETH_FILTER_HASH:
1903 rss_filter_ptr = (struct hns3_rss_conf_ele *)flow->rule;
1904 ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info,
1907 return rte_flow_error_set(error, EIO,
1908 RTE_FLOW_ERROR_TYPE_HANDLE,
1910 "Destroy RSS fail.Try again");
1911 TAILQ_REMOVE(&process_list->filter_rss_list, rss_filter_ptr,
1913 rte_free(rss_filter_ptr);
1914 rss_filter_ptr = NULL;
1917 return rte_flow_error_set(error, EINVAL,
1918 RTE_FLOW_ERROR_TYPE_HANDLE, flow,
1919 "Unsupported filter type");
1922 TAILQ_FOREACH(flow_node, &process_list->flow_list, entries) {
1923 if (flow_node->flow == flow) {
1924 TAILQ_REMOVE(&process_list->flow_list, flow_node,
1926 rte_free(flow_node);
1937 /* Destroy all flow rules associated with a port on hns3. */
1939 hns3_flow_flush(struct rte_eth_dev *dev, struct rte_flow_error *error)
1941 struct hns3_adapter *hns = dev->data->dev_private;
1944 /* FDIR is available only in PF driver */
1946 ret = hns3_clear_all_fdir_filter(hns);
1948 rte_flow_error_set(error, ret,
1949 RTE_FLOW_ERROR_TYPE_HANDLE,
1950 NULL, "Failed to flush rule");
1953 hns3_counter_flush(dev);
1956 ret = hns3_clear_rss_filter(dev);
1958 rte_flow_error_set(error, ret, RTE_FLOW_ERROR_TYPE_HANDLE,
1959 NULL, "Failed to flush rss filter");
1963 hns3_filterlist_flush(dev);
1968 /* Query an existing flow rule. */
1970 hns3_flow_query(struct rte_eth_dev *dev, struct rte_flow *flow,
1971 const struct rte_flow_action *actions, void *data,
1972 struct rte_flow_error *error)
1974 struct rte_flow_action_rss *rss_conf;
1975 struct hns3_rss_conf_ele *rss_rule;
1976 struct rte_flow_query_count *qc;
1980 return rte_flow_error_set(error, EINVAL,
1981 RTE_FLOW_ERROR_TYPE_HANDLE, NULL, "invalid rule");
1983 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
1984 switch (actions->type) {
1985 case RTE_FLOW_ACTION_TYPE_VOID:
1987 case RTE_FLOW_ACTION_TYPE_COUNT:
1988 qc = (struct rte_flow_query_count *)data;
1989 ret = hns3_counter_query(dev, flow, qc, error);
1993 case RTE_FLOW_ACTION_TYPE_RSS:
1994 if (flow->filter_type != RTE_ETH_FILTER_HASH) {
1995 return rte_flow_error_set(error, ENOTSUP,
1996 RTE_FLOW_ERROR_TYPE_ACTION,
1997 actions, "action is not supported");
1999 rss_conf = (struct rte_flow_action_rss *)data;
2000 rss_rule = (struct hns3_rss_conf_ele *)flow->rule;
2001 rte_memcpy(rss_conf, &rss_rule->filter_info.conf,
2002 sizeof(struct rte_flow_action_rss));
2005 return rte_flow_error_set(error, ENOTSUP,
2006 RTE_FLOW_ERROR_TYPE_ACTION,
2007 actions, "action is not supported");
2015 hns3_flow_validate_wrap(struct rte_eth_dev *dev,
2016 const struct rte_flow_attr *attr,
2017 const struct rte_flow_item pattern[],
2018 const struct rte_flow_action actions[],
2019 struct rte_flow_error *error)
2021 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2024 pthread_mutex_lock(&hw->flows_lock);
2025 ret = hns3_flow_validate(dev, attr, pattern, actions, error);
2026 pthread_mutex_unlock(&hw->flows_lock);
2031 static struct rte_flow *
2032 hns3_flow_create_wrap(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
2033 const struct rte_flow_item pattern[],
2034 const struct rte_flow_action actions[],
2035 struct rte_flow_error *error)
2037 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2038 struct rte_flow *flow;
2040 pthread_mutex_lock(&hw->flows_lock);
2041 flow = hns3_flow_create(dev, attr, pattern, actions, error);
2042 pthread_mutex_unlock(&hw->flows_lock);
2048 hns3_flow_destroy_wrap(struct rte_eth_dev *dev, struct rte_flow *flow,
2049 struct rte_flow_error *error)
2051 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2054 pthread_mutex_lock(&hw->flows_lock);
2055 ret = hns3_flow_destroy(dev, flow, error);
2056 pthread_mutex_unlock(&hw->flows_lock);
2062 hns3_flow_flush_wrap(struct rte_eth_dev *dev, struct rte_flow_error *error)
2064 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2067 pthread_mutex_lock(&hw->flows_lock);
2068 ret = hns3_flow_flush(dev, error);
2069 pthread_mutex_unlock(&hw->flows_lock);
2075 hns3_flow_query_wrap(struct rte_eth_dev *dev, struct rte_flow *flow,
2076 const struct rte_flow_action *actions, void *data,
2077 struct rte_flow_error *error)
2079 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2082 pthread_mutex_lock(&hw->flows_lock);
2083 ret = hns3_flow_query(dev, flow, actions, data, error);
2084 pthread_mutex_unlock(&hw->flows_lock);
2089 static const struct rte_flow_ops hns3_flow_ops = {
2090 .validate = hns3_flow_validate_wrap,
2091 .create = hns3_flow_create_wrap,
2092 .destroy = hns3_flow_destroy_wrap,
2093 .flush = hns3_flow_flush_wrap,
2094 .query = hns3_flow_query_wrap,
2099 hns3_dev_flow_ops_get(struct rte_eth_dev *dev,
2100 const struct rte_flow_ops **ops)
2104 hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2105 if (hw->adapter_state >= HNS3_NIC_CLOSED)
2108 *ops = &hns3_flow_ops;