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"
11 #include "hns3_flow.h"
13 /* Default default keys */
14 static uint8_t hns3_hash_key[] = {
15 0x6D, 0x5A, 0x56, 0xDA, 0x25, 0x5B, 0x0E, 0xC2,
16 0x41, 0x67, 0x25, 0x3D, 0x43, 0xA3, 0x8F, 0xB0,
17 0xD0, 0xCA, 0x2B, 0xCB, 0xAE, 0x7B, 0x30, 0xB4,
18 0x77, 0xCB, 0x2D, 0xA3, 0x80, 0x30, 0xF2, 0x0C,
19 0x6A, 0x42, 0xB7, 0x3B, 0xBE, 0xAC, 0x01, 0xFA
22 static const uint8_t full_mask[VNI_OR_TNI_LEN] = { 0xFF, 0xFF, 0xFF };
23 static const uint8_t zero_mask[VNI_OR_TNI_LEN] = { 0x00, 0x00, 0x00 };
25 /* Special Filter id for non-specific packet flagging. Don't change value */
26 #define HNS3_MAX_FILTER_ID 0x0FFF
28 #define ETHER_TYPE_MASK 0xFFFF
29 #define IPPROTO_MASK 0xFF
30 #define TUNNEL_TYPE_MASK 0xFFFF
32 #define HNS3_TUNNEL_TYPE_VXLAN 0x12B5
33 #define HNS3_TUNNEL_TYPE_VXLAN_GPE 0x12B6
34 #define HNS3_TUNNEL_TYPE_GENEVE 0x17C1
35 #define HNS3_TUNNEL_TYPE_NVGRE 0x6558
37 static enum rte_flow_item_type first_items[] = {
38 RTE_FLOW_ITEM_TYPE_ETH,
39 RTE_FLOW_ITEM_TYPE_IPV4,
40 RTE_FLOW_ITEM_TYPE_IPV6,
41 RTE_FLOW_ITEM_TYPE_TCP,
42 RTE_FLOW_ITEM_TYPE_UDP,
43 RTE_FLOW_ITEM_TYPE_SCTP,
44 RTE_FLOW_ITEM_TYPE_ICMP,
45 RTE_FLOW_ITEM_TYPE_NVGRE,
46 RTE_FLOW_ITEM_TYPE_VXLAN,
47 RTE_FLOW_ITEM_TYPE_GENEVE,
48 RTE_FLOW_ITEM_TYPE_VXLAN_GPE
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
71 static enum rte_flow_item_type tunnel_next_items[] = {
72 RTE_FLOW_ITEM_TYPE_ETH,
73 RTE_FLOW_ITEM_TYPE_VLAN
76 struct items_step_mngr {
77 enum rte_flow_item_type *items;
82 net_addr_to_host(uint32_t *dst, const rte_be32_t *src, size_t len)
86 for (i = 0; i < len; i++)
87 dst[i] = rte_be_to_cpu_32(src[i]);
91 * This function is used to find rss general action.
92 * 1. As we know RSS is used to spread packets among several queues, the flow
93 * API provide the struct rte_flow_action_rss, user could config its field
94 * sush as: func/level/types/key/queue to control RSS function.
95 * 2. The flow API also supports queue region configuration for hns3. It was
96 * implemented by FDIR + RSS in hns3 hardware, user can create one FDIR rule
97 * which action is RSS queues region.
98 * 3. When action is RSS, we use the following rule to distinguish:
99 * Case 1: pattern have ETH and action's queue_num > 0, indicate it is queue
100 * region configuration.
101 * Case other: an rss general action.
103 static const struct rte_flow_action *
104 hns3_find_rss_general_action(const struct rte_flow_item pattern[],
105 const struct rte_flow_action actions[])
107 const struct rte_flow_action *act = NULL;
108 const struct hns3_rss_conf *rss;
109 bool have_eth = false;
111 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
112 if (actions->type == RTE_FLOW_ACTION_TYPE_RSS) {
120 for (; pattern->type != RTE_FLOW_ITEM_TYPE_END; pattern++) {
121 if (pattern->type == RTE_FLOW_ITEM_TYPE_ETH) {
128 if (have_eth && rss->conf.queue_num) {
130 * Pattern have ETH and action's queue_num > 0, indicate this is
131 * queue region configuration.
132 * Because queue region is implemented by FDIR + RSS in hns3
133 * hardware, it needs to enter FDIR process, so here return NULL
134 * to avoid enter RSS process.
142 static inline struct hns3_flow_counter *
143 hns3_counter_lookup(struct rte_eth_dev *dev, uint32_t id)
145 struct hns3_adapter *hns = dev->data->dev_private;
146 struct hns3_pf *pf = &hns->pf;
147 struct hns3_flow_counter *cnt;
149 LIST_FOREACH(cnt, &pf->flow_counters, next) {
157 hns3_counter_new(struct rte_eth_dev *dev, uint32_t shared, uint32_t id,
158 struct rte_flow_error *error)
160 struct hns3_adapter *hns = dev->data->dev_private;
161 struct hns3_pf *pf = &hns->pf;
162 struct hns3_hw *hw = &hns->hw;
163 struct hns3_flow_counter *cnt;
167 cnt = hns3_counter_lookup(dev, id);
169 if (!cnt->shared || cnt->shared != shared)
170 return rte_flow_error_set(error, ENOTSUP,
171 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
173 "Counter id is used, shared flag not match");
178 /* Clear the counter by read ops because the counter is read-clear */
179 ret = hns3_get_count(hw, id, &value);
181 return rte_flow_error_set(error, EIO,
182 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
183 "Clear counter failed!");
185 cnt = rte_zmalloc("hns3 counter", sizeof(*cnt), 0);
187 return rte_flow_error_set(error, ENOMEM,
188 RTE_FLOW_ERROR_TYPE_HANDLE, cnt,
189 "Alloc mem for counter failed");
191 cnt->shared = shared;
194 LIST_INSERT_HEAD(&pf->flow_counters, cnt, next);
199 hns3_counter_query(struct rte_eth_dev *dev, struct rte_flow *flow,
200 struct rte_flow_query_count *qc,
201 struct rte_flow_error *error)
203 struct hns3_adapter *hns = dev->data->dev_private;
204 struct hns3_flow_counter *cnt;
208 /* FDIR is available only in PF driver */
210 return rte_flow_error_set(error, ENOTSUP,
211 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
212 "Fdir is not supported in VF");
213 cnt = hns3_counter_lookup(dev, flow->counter_id);
215 return rte_flow_error_set(error, EINVAL,
216 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
217 "Can't find counter id");
219 ret = hns3_get_count(&hns->hw, flow->counter_id, &value);
221 rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE,
222 NULL, "Read counter fail.");
234 hns3_counter_release(struct rte_eth_dev *dev, uint32_t id)
236 struct hns3_adapter *hns = dev->data->dev_private;
237 struct hns3_hw *hw = &hns->hw;
238 struct hns3_flow_counter *cnt;
240 cnt = hns3_counter_lookup(dev, id);
242 hns3_err(hw, "Can't find available counter to release");
246 if (cnt->ref_cnt == 0) {
247 LIST_REMOVE(cnt, next);
254 hns3_counter_flush(struct rte_eth_dev *dev)
256 struct hns3_adapter *hns = dev->data->dev_private;
257 struct hns3_pf *pf = &hns->pf;
258 struct hns3_flow_counter *cnt_ptr;
260 cnt_ptr = LIST_FIRST(&pf->flow_counters);
262 LIST_REMOVE(cnt_ptr, next);
264 cnt_ptr = LIST_FIRST(&pf->flow_counters);
269 hns3_handle_action_queue(struct rte_eth_dev *dev,
270 const struct rte_flow_action *action,
271 struct hns3_fdir_rule *rule,
272 struct rte_flow_error *error)
274 struct hns3_adapter *hns = dev->data->dev_private;
275 const struct rte_flow_action_queue *queue;
276 struct hns3_hw *hw = &hns->hw;
278 queue = (const struct rte_flow_action_queue *)action->conf;
279 if (queue->index >= hw->data->nb_rx_queues) {
280 hns3_err(hw, "queue ID(%u) is greater than number of "
281 "available queue (%u) in driver.",
282 queue->index, hw->data->nb_rx_queues);
283 return rte_flow_error_set(error, EINVAL,
284 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
285 action, "Invalid queue ID in PF");
288 rule->queue_id = queue->index;
290 rule->action = HNS3_FD_ACTION_ACCEPT_PACKET;
295 hns3_handle_action_queue_region(struct rte_eth_dev *dev,
296 const struct rte_flow_action *action,
297 struct hns3_fdir_rule *rule,
298 struct rte_flow_error *error)
300 struct hns3_adapter *hns = dev->data->dev_private;
301 const struct rte_flow_action_rss *conf = action->conf;
302 struct hns3_hw *hw = &hns->hw;
305 if (!hns3_dev_get_support(hw, FD_QUEUE_REGION))
306 return rte_flow_error_set(error, ENOTSUP,
307 RTE_FLOW_ERROR_TYPE_ACTION, action,
308 "Not support config queue region!");
310 if ((!rte_is_power_of_2(conf->queue_num)) ||
311 conf->queue_num > hw->rss_size_max ||
312 conf->queue[0] >= hw->data->nb_rx_queues ||
313 conf->queue[0] + conf->queue_num > hw->data->nb_rx_queues) {
314 return rte_flow_error_set(error, EINVAL,
315 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action,
316 "Invalid start queue ID and queue num! the start queue "
317 "ID must valid, the queue num must be power of 2 and "
321 for (idx = 1; idx < conf->queue_num; idx++) {
322 if (conf->queue[idx] != conf->queue[idx - 1] + 1)
323 return rte_flow_error_set(error, EINVAL,
324 RTE_FLOW_ERROR_TYPE_ACTION_CONF, action,
325 "Invalid queue ID sequence! the queue ID "
326 "must be continuous increment.");
329 rule->queue_id = conf->queue[0];
330 rule->nb_queues = conf->queue_num;
331 rule->action = HNS3_FD_ACTION_ACCEPT_PACKET;
336 * Parse actions structure from the provided pattern.
337 * The pattern is validated as the items are copied.
341 * NIC specific actions derived from the actions.
345 hns3_handle_actions(struct rte_eth_dev *dev,
346 const struct rte_flow_action actions[],
347 struct hns3_fdir_rule *rule, struct rte_flow_error *error)
349 struct hns3_adapter *hns = dev->data->dev_private;
350 const struct rte_flow_action_count *act_count;
351 const struct rte_flow_action_mark *mark;
352 struct hns3_pf *pf = &hns->pf;
353 uint32_t counter_num;
356 for (; actions->type != RTE_FLOW_ACTION_TYPE_END; actions++) {
357 switch (actions->type) {
358 case RTE_FLOW_ACTION_TYPE_QUEUE:
359 ret = hns3_handle_action_queue(dev, actions, rule,
364 case RTE_FLOW_ACTION_TYPE_DROP:
365 rule->action = HNS3_FD_ACTION_DROP_PACKET;
368 * Here RSS's real action is queue region.
369 * Queue region is implemented by FDIR + RSS in hns3 hardware,
370 * the FDIR's action is one queue region (start_queue_id and
371 * queue_num), then RSS spread packets to the queue region by
374 case RTE_FLOW_ACTION_TYPE_RSS:
375 ret = hns3_handle_action_queue_region(dev, actions,
380 case RTE_FLOW_ACTION_TYPE_MARK:
382 (const struct rte_flow_action_mark *)actions->conf;
383 if (mark->id >= HNS3_MAX_FILTER_ID)
384 return rte_flow_error_set(error, EINVAL,
385 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
388 rule->fd_id = mark->id;
389 rule->flags |= HNS3_RULE_FLAG_FDID;
391 case RTE_FLOW_ACTION_TYPE_FLAG:
392 rule->fd_id = HNS3_MAX_FILTER_ID;
393 rule->flags |= HNS3_RULE_FLAG_FDID;
395 case RTE_FLOW_ACTION_TYPE_COUNT:
397 (const struct rte_flow_action_count *)actions->conf;
398 counter_num = pf->fdir.fd_cfg.cnt_num[HNS3_FD_STAGE_1];
399 if (act_count->id >= counter_num)
400 return rte_flow_error_set(error, EINVAL,
401 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
403 "Invalid counter id");
404 rule->act_cnt = *act_count;
405 rule->flags |= HNS3_RULE_FLAG_COUNTER;
407 case RTE_FLOW_ACTION_TYPE_VOID:
410 return rte_flow_error_set(error, ENOTSUP,
411 RTE_FLOW_ERROR_TYPE_ACTION,
412 NULL, "Unsupported action");
420 hns3_check_attr(const struct rte_flow_attr *attr, struct rte_flow_error *error)
423 return rte_flow_error_set(error, EINVAL,
424 RTE_FLOW_ERROR_TYPE_ATTR_INGRESS,
425 attr, "Ingress can't be zero");
427 return rte_flow_error_set(error, ENOTSUP,
428 RTE_FLOW_ERROR_TYPE_ATTR_EGRESS,
429 attr, "Not support egress");
431 return rte_flow_error_set(error, ENOTSUP,
432 RTE_FLOW_ERROR_TYPE_ATTR_TRANSFER,
433 attr, "No support for transfer");
435 return rte_flow_error_set(error, ENOTSUP,
436 RTE_FLOW_ERROR_TYPE_ATTR_PRIORITY,
437 attr, "Not support priority");
439 return rte_flow_error_set(error, ENOTSUP,
440 RTE_FLOW_ERROR_TYPE_ATTR_GROUP,
441 attr, "Not support group");
446 hns3_parse_eth(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
447 struct rte_flow_error *error __rte_unused)
449 const struct rte_flow_item_eth *eth_spec;
450 const struct rte_flow_item_eth *eth_mask;
452 /* Only used to describe the protocol stack. */
453 if (item->spec == NULL && item->mask == NULL)
457 eth_mask = item->mask;
458 if (eth_mask->type) {
459 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
460 rule->key_conf.mask.ether_type =
461 rte_be_to_cpu_16(eth_mask->type);
463 if (!rte_is_zero_ether_addr(ð_mask->src)) {
464 hns3_set_bit(rule->input_set, INNER_SRC_MAC, 1);
465 memcpy(rule->key_conf.mask.src_mac,
466 eth_mask->src.addr_bytes, RTE_ETHER_ADDR_LEN);
468 if (!rte_is_zero_ether_addr(ð_mask->dst)) {
469 hns3_set_bit(rule->input_set, INNER_DST_MAC, 1);
470 memcpy(rule->key_conf.mask.dst_mac,
471 eth_mask->dst.addr_bytes, RTE_ETHER_ADDR_LEN);
475 eth_spec = item->spec;
476 rule->key_conf.spec.ether_type = rte_be_to_cpu_16(eth_spec->type);
477 memcpy(rule->key_conf.spec.src_mac, eth_spec->src.addr_bytes,
479 memcpy(rule->key_conf.spec.dst_mac, eth_spec->dst.addr_bytes,
485 hns3_parse_vlan(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
486 struct rte_flow_error *error)
488 const struct rte_flow_item_vlan *vlan_spec;
489 const struct rte_flow_item_vlan *vlan_mask;
491 rule->key_conf.vlan_num++;
492 if (rule->key_conf.vlan_num > VLAN_TAG_NUM_MAX)
493 return rte_flow_error_set(error, EINVAL,
494 RTE_FLOW_ERROR_TYPE_ITEM, item,
495 "Vlan_num is more than 2");
497 /* Only used to describe the protocol stack. */
498 if (item->spec == NULL && item->mask == NULL)
502 vlan_mask = item->mask;
503 if (vlan_mask->tci) {
504 if (rule->key_conf.vlan_num == 1) {
505 hns3_set_bit(rule->input_set, INNER_VLAN_TAG1,
507 rule->key_conf.mask.vlan_tag1 =
508 rte_be_to_cpu_16(vlan_mask->tci);
510 hns3_set_bit(rule->input_set, INNER_VLAN_TAG2,
512 rule->key_conf.mask.vlan_tag2 =
513 rte_be_to_cpu_16(vlan_mask->tci);
518 vlan_spec = item->spec;
519 if (rule->key_conf.vlan_num == 1)
520 rule->key_conf.spec.vlan_tag1 =
521 rte_be_to_cpu_16(vlan_spec->tci);
523 rule->key_conf.spec.vlan_tag2 =
524 rte_be_to_cpu_16(vlan_spec->tci);
529 hns3_check_ipv4_mask_supported(const struct rte_flow_item_ipv4 *ipv4_mask)
531 if (ipv4_mask->hdr.total_length || ipv4_mask->hdr.packet_id ||
532 ipv4_mask->hdr.fragment_offset || ipv4_mask->hdr.time_to_live ||
533 ipv4_mask->hdr.hdr_checksum)
540 hns3_parse_ipv4(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
541 struct rte_flow_error *error)
543 const struct rte_flow_item_ipv4 *ipv4_spec;
544 const struct rte_flow_item_ipv4 *ipv4_mask;
546 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
547 rule->key_conf.spec.ether_type = RTE_ETHER_TYPE_IPV4;
548 rule->key_conf.mask.ether_type = ETHER_TYPE_MASK;
550 /* Only used to describe the protocol stack. */
551 if (item->spec == NULL && item->mask == NULL)
555 ipv4_mask = item->mask;
556 if (!hns3_check_ipv4_mask_supported(ipv4_mask)) {
557 return rte_flow_error_set(error, EINVAL,
558 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
560 "Only support src & dst ip,tos,proto in IPV4");
563 if (ipv4_mask->hdr.src_addr) {
564 hns3_set_bit(rule->input_set, INNER_SRC_IP, 1);
565 rule->key_conf.mask.src_ip[IP_ADDR_KEY_ID] =
566 rte_be_to_cpu_32(ipv4_mask->hdr.src_addr);
569 if (ipv4_mask->hdr.dst_addr) {
570 hns3_set_bit(rule->input_set, INNER_DST_IP, 1);
571 rule->key_conf.mask.dst_ip[IP_ADDR_KEY_ID] =
572 rte_be_to_cpu_32(ipv4_mask->hdr.dst_addr);
575 if (ipv4_mask->hdr.type_of_service) {
576 hns3_set_bit(rule->input_set, INNER_IP_TOS, 1);
577 rule->key_conf.mask.ip_tos =
578 ipv4_mask->hdr.type_of_service;
581 if (ipv4_mask->hdr.next_proto_id) {
582 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
583 rule->key_conf.mask.ip_proto =
584 ipv4_mask->hdr.next_proto_id;
588 ipv4_spec = item->spec;
589 rule->key_conf.spec.src_ip[IP_ADDR_KEY_ID] =
590 rte_be_to_cpu_32(ipv4_spec->hdr.src_addr);
591 rule->key_conf.spec.dst_ip[IP_ADDR_KEY_ID] =
592 rte_be_to_cpu_32(ipv4_spec->hdr.dst_addr);
593 rule->key_conf.spec.ip_tos = ipv4_spec->hdr.type_of_service;
594 rule->key_conf.spec.ip_proto = ipv4_spec->hdr.next_proto_id;
599 hns3_parse_ipv6(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
600 struct rte_flow_error *error)
602 const struct rte_flow_item_ipv6 *ipv6_spec;
603 const struct rte_flow_item_ipv6 *ipv6_mask;
605 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 1);
606 rule->key_conf.spec.ether_type = RTE_ETHER_TYPE_IPV6;
607 rule->key_conf.mask.ether_type = ETHER_TYPE_MASK;
609 /* Only used to describe the protocol stack. */
610 if (item->spec == NULL && item->mask == NULL)
614 ipv6_mask = item->mask;
615 if (ipv6_mask->hdr.vtc_flow || ipv6_mask->hdr.payload_len ||
616 ipv6_mask->hdr.hop_limits) {
617 return rte_flow_error_set(error, EINVAL,
618 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
620 "Only support src & dst ip,proto in IPV6");
622 net_addr_to_host(rule->key_conf.mask.src_ip,
623 (const rte_be32_t *)ipv6_mask->hdr.src_addr,
625 net_addr_to_host(rule->key_conf.mask.dst_ip,
626 (const rte_be32_t *)ipv6_mask->hdr.dst_addr,
628 rule->key_conf.mask.ip_proto = ipv6_mask->hdr.proto;
629 if (rule->key_conf.mask.src_ip[IP_ADDR_KEY_ID])
630 hns3_set_bit(rule->input_set, INNER_SRC_IP, 1);
631 if (rule->key_conf.mask.dst_ip[IP_ADDR_KEY_ID])
632 hns3_set_bit(rule->input_set, INNER_DST_IP, 1);
633 if (ipv6_mask->hdr.proto)
634 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
637 ipv6_spec = item->spec;
638 net_addr_to_host(rule->key_conf.spec.src_ip,
639 (const rte_be32_t *)ipv6_spec->hdr.src_addr,
641 net_addr_to_host(rule->key_conf.spec.dst_ip,
642 (const rte_be32_t *)ipv6_spec->hdr.dst_addr,
644 rule->key_conf.spec.ip_proto = ipv6_spec->hdr.proto;
650 hns3_check_tcp_mask_supported(const struct rte_flow_item_tcp *tcp_mask)
652 if (tcp_mask->hdr.sent_seq || tcp_mask->hdr.recv_ack ||
653 tcp_mask->hdr.data_off || tcp_mask->hdr.tcp_flags ||
654 tcp_mask->hdr.rx_win || tcp_mask->hdr.cksum ||
655 tcp_mask->hdr.tcp_urp)
662 hns3_parse_tcp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
663 struct rte_flow_error *error)
665 const struct rte_flow_item_tcp *tcp_spec;
666 const struct rte_flow_item_tcp *tcp_mask;
668 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
669 rule->key_conf.spec.ip_proto = IPPROTO_TCP;
670 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
672 /* Only used to describe the protocol stack. */
673 if (item->spec == NULL && item->mask == NULL)
677 tcp_mask = item->mask;
678 if (!hns3_check_tcp_mask_supported(tcp_mask)) {
679 return rte_flow_error_set(error, EINVAL,
680 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
682 "Only support src & dst port in TCP");
685 if (tcp_mask->hdr.src_port) {
686 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
687 rule->key_conf.mask.src_port =
688 rte_be_to_cpu_16(tcp_mask->hdr.src_port);
690 if (tcp_mask->hdr.dst_port) {
691 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
692 rule->key_conf.mask.dst_port =
693 rte_be_to_cpu_16(tcp_mask->hdr.dst_port);
697 tcp_spec = item->spec;
698 rule->key_conf.spec.src_port = rte_be_to_cpu_16(tcp_spec->hdr.src_port);
699 rule->key_conf.spec.dst_port = rte_be_to_cpu_16(tcp_spec->hdr.dst_port);
705 hns3_parse_udp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
706 struct rte_flow_error *error)
708 const struct rte_flow_item_udp *udp_spec;
709 const struct rte_flow_item_udp *udp_mask;
711 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
712 rule->key_conf.spec.ip_proto = IPPROTO_UDP;
713 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
715 /* Only used to describe the protocol stack. */
716 if (item->spec == NULL && item->mask == NULL)
720 udp_mask = item->mask;
721 if (udp_mask->hdr.dgram_len || udp_mask->hdr.dgram_cksum) {
722 return rte_flow_error_set(error, EINVAL,
723 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
725 "Only support src & dst port in UDP");
727 if (udp_mask->hdr.src_port) {
728 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
729 rule->key_conf.mask.src_port =
730 rte_be_to_cpu_16(udp_mask->hdr.src_port);
732 if (udp_mask->hdr.dst_port) {
733 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
734 rule->key_conf.mask.dst_port =
735 rte_be_to_cpu_16(udp_mask->hdr.dst_port);
739 udp_spec = item->spec;
740 rule->key_conf.spec.src_port = rte_be_to_cpu_16(udp_spec->hdr.src_port);
741 rule->key_conf.spec.dst_port = rte_be_to_cpu_16(udp_spec->hdr.dst_port);
747 hns3_parse_sctp(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
748 struct rte_flow_error *error)
750 const struct rte_flow_item_sctp *sctp_spec;
751 const struct rte_flow_item_sctp *sctp_mask;
753 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 1);
754 rule->key_conf.spec.ip_proto = IPPROTO_SCTP;
755 rule->key_conf.mask.ip_proto = IPPROTO_MASK;
757 /* Only used to describe the protocol stack. */
758 if (item->spec == NULL && item->mask == NULL)
762 sctp_mask = item->mask;
763 if (sctp_mask->hdr.cksum)
764 return rte_flow_error_set(error, EINVAL,
765 RTE_FLOW_ERROR_TYPE_ITEM_MASK,
767 "Only support src & dst port in SCTP");
768 if (sctp_mask->hdr.src_port) {
769 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 1);
770 rule->key_conf.mask.src_port =
771 rte_be_to_cpu_16(sctp_mask->hdr.src_port);
773 if (sctp_mask->hdr.dst_port) {
774 hns3_set_bit(rule->input_set, INNER_DST_PORT, 1);
775 rule->key_conf.mask.dst_port =
776 rte_be_to_cpu_16(sctp_mask->hdr.dst_port);
778 if (sctp_mask->hdr.tag) {
779 hns3_set_bit(rule->input_set, INNER_SCTP_TAG, 1);
780 rule->key_conf.mask.sctp_tag =
781 rte_be_to_cpu_32(sctp_mask->hdr.tag);
785 sctp_spec = item->spec;
786 rule->key_conf.spec.src_port =
787 rte_be_to_cpu_16(sctp_spec->hdr.src_port);
788 rule->key_conf.spec.dst_port =
789 rte_be_to_cpu_16(sctp_spec->hdr.dst_port);
790 rule->key_conf.spec.sctp_tag = rte_be_to_cpu_32(sctp_spec->hdr.tag);
796 * Check items before tunnel, save inner configs to outer configs, and clear
798 * The key consists of two parts: meta_data and tuple keys.
799 * Meta data uses 15 bits, including vlan_num(2bit), des_port(12bit) and tunnel
801 * Tuple keys uses 384bit, including ot_dst-mac(48bit), ot_dst-port(16bit),
802 * ot_tun_vni(24bit), ot_flow_id(8bit), src-mac(48bit), dst-mac(48bit),
803 * src-ip(32/128bit), dst-ip(32/128bit), src-port(16bit), dst-port(16bit),
804 * tos(8bit), ether-proto(16bit), ip-proto(8bit), vlantag1(16bit),
805 * Vlantag2(16bit) and sctp-tag(32bit).
808 hns3_handle_tunnel(const struct rte_flow_item *item,
809 struct hns3_fdir_rule *rule, struct rte_flow_error *error)
811 /* check eth config */
812 if (rule->input_set & (BIT(INNER_SRC_MAC) | BIT(INNER_DST_MAC)))
813 return rte_flow_error_set(error, EINVAL,
814 RTE_FLOW_ERROR_TYPE_ITEM,
815 item, "Outer eth mac is unsupported");
816 if (rule->input_set & BIT(INNER_ETH_TYPE)) {
817 hns3_set_bit(rule->input_set, OUTER_ETH_TYPE, 1);
818 rule->key_conf.spec.outer_ether_type =
819 rule->key_conf.spec.ether_type;
820 rule->key_conf.mask.outer_ether_type =
821 rule->key_conf.mask.ether_type;
822 hns3_set_bit(rule->input_set, INNER_ETH_TYPE, 0);
823 rule->key_conf.spec.ether_type = 0;
824 rule->key_conf.mask.ether_type = 0;
827 /* check vlan config */
828 if (rule->input_set & (BIT(INNER_VLAN_TAG1) | BIT(INNER_VLAN_TAG2)))
829 return rte_flow_error_set(error, EINVAL,
830 RTE_FLOW_ERROR_TYPE_ITEM,
832 "Outer vlan tags is unsupported");
834 /* clear vlan_num for inner vlan select */
835 rule->key_conf.outer_vlan_num = rule->key_conf.vlan_num;
836 rule->key_conf.vlan_num = 0;
838 /* check L3 config */
839 if (rule->input_set &
840 (BIT(INNER_SRC_IP) | BIT(INNER_DST_IP) | BIT(INNER_IP_TOS)))
841 return rte_flow_error_set(error, EINVAL,
842 RTE_FLOW_ERROR_TYPE_ITEM,
843 item, "Outer ip is unsupported");
844 if (rule->input_set & BIT(INNER_IP_PROTO)) {
845 hns3_set_bit(rule->input_set, OUTER_IP_PROTO, 1);
846 rule->key_conf.spec.outer_proto = rule->key_conf.spec.ip_proto;
847 rule->key_conf.mask.outer_proto = rule->key_conf.mask.ip_proto;
848 hns3_set_bit(rule->input_set, INNER_IP_PROTO, 0);
849 rule->key_conf.spec.ip_proto = 0;
850 rule->key_conf.mask.ip_proto = 0;
853 /* check L4 config */
854 if (rule->input_set & BIT(INNER_SCTP_TAG))
855 return rte_flow_error_set(error, EINVAL,
856 RTE_FLOW_ERROR_TYPE_ITEM, item,
857 "Outer sctp tag is unsupported");
859 if (rule->input_set & BIT(INNER_SRC_PORT)) {
860 hns3_set_bit(rule->input_set, OUTER_SRC_PORT, 1);
861 rule->key_conf.spec.outer_src_port =
862 rule->key_conf.spec.src_port;
863 rule->key_conf.mask.outer_src_port =
864 rule->key_conf.mask.src_port;
865 hns3_set_bit(rule->input_set, INNER_SRC_PORT, 0);
866 rule->key_conf.spec.src_port = 0;
867 rule->key_conf.mask.src_port = 0;
869 if (rule->input_set & BIT(INNER_DST_PORT)) {
870 hns3_set_bit(rule->input_set, INNER_DST_PORT, 0);
871 rule->key_conf.spec.dst_port = 0;
872 rule->key_conf.mask.dst_port = 0;
878 hns3_parse_vxlan(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
879 struct rte_flow_error *error)
881 const struct rte_flow_item_vxlan *vxlan_spec;
882 const struct rte_flow_item_vxlan *vxlan_mask;
884 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
885 rule->key_conf.mask.tunnel_type = TUNNEL_TYPE_MASK;
886 if (item->type == RTE_FLOW_ITEM_TYPE_VXLAN)
887 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_VXLAN;
889 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_VXLAN_GPE;
891 /* Only used to describe the protocol stack. */
892 if (item->spec == NULL && item->mask == NULL)
895 vxlan_mask = item->mask;
896 vxlan_spec = item->spec;
898 if (vxlan_mask->flags)
899 return rte_flow_error_set(error, EINVAL,
900 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
901 "Flags is not supported in VxLAN");
903 /* VNI must be totally masked or not. */
904 if (memcmp(vxlan_mask->vni, full_mask, VNI_OR_TNI_LEN) &&
905 memcmp(vxlan_mask->vni, zero_mask, VNI_OR_TNI_LEN))
906 return rte_flow_error_set(error, EINVAL,
907 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
908 "VNI must be totally masked or not in VxLAN");
909 if (vxlan_mask->vni[0]) {
910 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
911 memcpy(rule->key_conf.mask.outer_tun_vni, vxlan_mask->vni,
914 memcpy(rule->key_conf.spec.outer_tun_vni, vxlan_spec->vni,
920 hns3_parse_nvgre(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
921 struct rte_flow_error *error)
923 const struct rte_flow_item_nvgre *nvgre_spec;
924 const struct rte_flow_item_nvgre *nvgre_mask;
926 hns3_set_bit(rule->input_set, OUTER_IP_PROTO, 1);
927 rule->key_conf.spec.outer_proto = IPPROTO_GRE;
928 rule->key_conf.mask.outer_proto = IPPROTO_MASK;
930 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
931 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_NVGRE;
932 rule->key_conf.mask.tunnel_type = ~HNS3_TUNNEL_TYPE_NVGRE;
933 /* Only used to describe the protocol stack. */
934 if (item->spec == NULL && item->mask == NULL)
937 nvgre_mask = item->mask;
938 nvgre_spec = item->spec;
940 if (nvgre_mask->protocol || nvgre_mask->c_k_s_rsvd0_ver)
941 return rte_flow_error_set(error, EINVAL,
942 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
943 "Ver/protocol is not supported in NVGRE");
945 /* TNI must be totally masked or not. */
946 if (memcmp(nvgre_mask->tni, full_mask, VNI_OR_TNI_LEN) &&
947 memcmp(nvgre_mask->tni, zero_mask, VNI_OR_TNI_LEN))
948 return rte_flow_error_set(error, EINVAL,
949 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
950 "TNI must be totally masked or not in NVGRE");
952 if (nvgre_mask->tni[0]) {
953 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
954 memcpy(rule->key_conf.mask.outer_tun_vni, nvgre_mask->tni,
957 memcpy(rule->key_conf.spec.outer_tun_vni, nvgre_spec->tni,
960 if (nvgre_mask->flow_id) {
961 hns3_set_bit(rule->input_set, OUTER_TUN_FLOW_ID, 1);
962 rule->key_conf.mask.outer_tun_flow_id = nvgre_mask->flow_id;
964 rule->key_conf.spec.outer_tun_flow_id = nvgre_spec->flow_id;
969 hns3_parse_geneve(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
970 struct rte_flow_error *error)
972 const struct rte_flow_item_geneve *geneve_spec;
973 const struct rte_flow_item_geneve *geneve_mask;
975 hns3_set_bit(rule->input_set, OUTER_DST_PORT, 1);
976 rule->key_conf.spec.tunnel_type = HNS3_TUNNEL_TYPE_GENEVE;
977 rule->key_conf.mask.tunnel_type = TUNNEL_TYPE_MASK;
978 /* Only used to describe the protocol stack. */
979 if (item->spec == NULL && item->mask == NULL)
982 geneve_mask = item->mask;
983 geneve_spec = item->spec;
985 if (geneve_mask->ver_opt_len_o_c_rsvd0 || geneve_mask->protocol)
986 return rte_flow_error_set(error, EINVAL,
987 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
988 "Ver/protocol is not supported in GENEVE");
989 /* VNI must be totally masked or not. */
990 if (memcmp(geneve_mask->vni, full_mask, VNI_OR_TNI_LEN) &&
991 memcmp(geneve_mask->vni, zero_mask, VNI_OR_TNI_LEN))
992 return rte_flow_error_set(error, EINVAL,
993 RTE_FLOW_ERROR_TYPE_ITEM_MASK, item,
994 "VNI must be totally masked or not in GENEVE");
995 if (geneve_mask->vni[0]) {
996 hns3_set_bit(rule->input_set, OUTER_TUN_VNI, 1);
997 memcpy(rule->key_conf.mask.outer_tun_vni, geneve_mask->vni,
1000 memcpy(rule->key_conf.spec.outer_tun_vni, geneve_spec->vni,
1006 hns3_parse_tunnel(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
1007 struct rte_flow_error *error)
1011 if (item->spec == NULL && item->mask)
1012 return rte_flow_error_set(error, EINVAL,
1013 RTE_FLOW_ERROR_TYPE_ITEM, item,
1014 "Can't configure FDIR with mask "
1015 "but without spec");
1016 else if (item->spec && (item->mask == NULL))
1017 return rte_flow_error_set(error, EINVAL,
1018 RTE_FLOW_ERROR_TYPE_ITEM, item,
1019 "Tunnel packets must configure "
1022 switch (item->type) {
1023 case RTE_FLOW_ITEM_TYPE_VXLAN:
1024 case RTE_FLOW_ITEM_TYPE_VXLAN_GPE:
1025 ret = hns3_parse_vxlan(item, rule, error);
1027 case RTE_FLOW_ITEM_TYPE_NVGRE:
1028 ret = hns3_parse_nvgre(item, rule, error);
1030 case RTE_FLOW_ITEM_TYPE_GENEVE:
1031 ret = hns3_parse_geneve(item, rule, error);
1034 return rte_flow_error_set(error, ENOTSUP,
1035 RTE_FLOW_ERROR_TYPE_ITEM,
1036 NULL, "Unsupported tunnel type!");
1040 return hns3_handle_tunnel(item, rule, error);
1044 hns3_parse_normal(const struct rte_flow_item *item, struct hns3_fdir_rule *rule,
1045 struct items_step_mngr *step_mngr,
1046 struct rte_flow_error *error)
1050 if (item->spec == NULL && item->mask)
1051 return rte_flow_error_set(error, EINVAL,
1052 RTE_FLOW_ERROR_TYPE_ITEM, item,
1053 "Can't configure FDIR with mask "
1054 "but without spec");
1056 switch (item->type) {
1057 case RTE_FLOW_ITEM_TYPE_ETH:
1058 ret = hns3_parse_eth(item, rule, error);
1059 step_mngr->items = L2_next_items;
1060 step_mngr->count = RTE_DIM(L2_next_items);
1062 case RTE_FLOW_ITEM_TYPE_VLAN:
1063 ret = hns3_parse_vlan(item, rule, error);
1064 step_mngr->items = L2_next_items;
1065 step_mngr->count = RTE_DIM(L2_next_items);
1067 case RTE_FLOW_ITEM_TYPE_IPV4:
1068 ret = hns3_parse_ipv4(item, rule, error);
1069 step_mngr->items = L3_next_items;
1070 step_mngr->count = RTE_DIM(L3_next_items);
1072 case RTE_FLOW_ITEM_TYPE_IPV6:
1073 ret = hns3_parse_ipv6(item, rule, error);
1074 step_mngr->items = L3_next_items;
1075 step_mngr->count = RTE_DIM(L3_next_items);
1077 case RTE_FLOW_ITEM_TYPE_TCP:
1078 ret = hns3_parse_tcp(item, rule, error);
1079 step_mngr->items = L4_next_items;
1080 step_mngr->count = RTE_DIM(L4_next_items);
1082 case RTE_FLOW_ITEM_TYPE_UDP:
1083 ret = hns3_parse_udp(item, rule, error);
1084 step_mngr->items = L4_next_items;
1085 step_mngr->count = RTE_DIM(L4_next_items);
1087 case RTE_FLOW_ITEM_TYPE_SCTP:
1088 ret = hns3_parse_sctp(item, rule, error);
1089 step_mngr->items = L4_next_items;
1090 step_mngr->count = RTE_DIM(L4_next_items);
1093 return rte_flow_error_set(error, ENOTSUP,
1094 RTE_FLOW_ERROR_TYPE_ITEM,
1095 NULL, "Unsupported normal type!");
1102 hns3_validate_item(const struct rte_flow_item *item,
1103 struct items_step_mngr step_mngr,
1104 struct rte_flow_error *error)
1109 return rte_flow_error_set(error, ENOTSUP,
1110 RTE_FLOW_ERROR_TYPE_ITEM_LAST, item,
1111 "Not supported last point for range");
1113 for (i = 0; i < step_mngr.count; i++) {
1114 if (item->type == step_mngr.items[i])
1118 if (i == step_mngr.count) {
1119 return rte_flow_error_set(error, EINVAL,
1120 RTE_FLOW_ERROR_TYPE_ITEM,
1121 item, "Inval or missing item");
1127 is_tunnel_packet(enum rte_flow_item_type type)
1129 if (type == RTE_FLOW_ITEM_TYPE_VXLAN_GPE ||
1130 type == RTE_FLOW_ITEM_TYPE_VXLAN ||
1131 type == RTE_FLOW_ITEM_TYPE_NVGRE ||
1132 type == RTE_FLOW_ITEM_TYPE_GENEVE)
1138 * Parse the flow director rule.
1139 * The supported PATTERN:
1140 * case: non-tunnel packet:
1141 * ETH : src-mac, dst-mac, ethertype
1143 * IPv4: src-ip, dst-ip, tos, proto
1144 * IPv6: src-ip(last 32 bit addr), dst-ip(last 32 bit addr), proto
1145 * UDP : src-port, dst-port
1146 * TCP : src-port, dst-port
1147 * SCTP: src-port, dst-port, tag
1148 * case: tunnel packet:
1149 * OUTER-ETH: ethertype
1151 * OUTER-L4 : src-port, dst-port
1152 * TUNNEL : vni, flow-id(only valid when NVGRE)
1153 * INNER-ETH/VLAN/IPv4/IPv6/UDP/TCP/SCTP: same as non-tunnel packet
1154 * The supported ACTION:
1158 * MARK: the id range [0, 4094]
1160 * RSS: only valid if firmware support FD_QUEUE_REGION.
1163 hns3_parse_fdir_filter(struct rte_eth_dev *dev,
1164 const struct rte_flow_item pattern[],
1165 const struct rte_flow_action actions[],
1166 struct hns3_fdir_rule *rule,
1167 struct rte_flow_error *error)
1169 struct hns3_adapter *hns = dev->data->dev_private;
1170 const struct rte_flow_item *item;
1171 struct items_step_mngr step_mngr;
1174 /* FDIR is available only in PF driver */
1176 return rte_flow_error_set(error, ENOTSUP,
1177 RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1178 "Fdir not supported in VF");
1180 step_mngr.items = first_items;
1181 step_mngr.count = RTE_DIM(first_items);
1182 for (item = pattern; item->type != RTE_FLOW_ITEM_TYPE_END; item++) {
1183 if (item->type == RTE_FLOW_ITEM_TYPE_VOID)
1186 ret = hns3_validate_item(item, step_mngr, error);
1190 if (is_tunnel_packet(item->type)) {
1191 ret = hns3_parse_tunnel(item, rule, error);
1194 step_mngr.items = tunnel_next_items;
1195 step_mngr.count = RTE_DIM(tunnel_next_items);
1197 ret = hns3_parse_normal(item, rule, &step_mngr, error);
1203 return hns3_handle_actions(dev, actions, rule, error);
1207 hns3_filterlist_flush(struct rte_eth_dev *dev)
1209 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1210 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1211 struct hns3_rss_conf_ele *rss_filter_ptr;
1212 struct hns3_flow_mem *flow_node;
1214 fdir_rule_ptr = TAILQ_FIRST(&hw->flow_fdir_list);
1215 while (fdir_rule_ptr) {
1216 TAILQ_REMOVE(&hw->flow_fdir_list, fdir_rule_ptr, entries);
1217 rte_free(fdir_rule_ptr);
1218 fdir_rule_ptr = TAILQ_FIRST(&hw->flow_fdir_list);
1221 rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list);
1222 while (rss_filter_ptr) {
1223 TAILQ_REMOVE(&hw->flow_rss_list, rss_filter_ptr, entries);
1224 rte_free(rss_filter_ptr);
1225 rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list);
1228 flow_node = TAILQ_FIRST(&hw->flow_list);
1230 TAILQ_REMOVE(&hw->flow_list, flow_node, entries);
1231 rte_free(flow_node->flow);
1232 rte_free(flow_node);
1233 flow_node = TAILQ_FIRST(&hw->flow_list);
1238 hns3_action_rss_same(const struct rte_flow_action_rss *comp,
1239 const struct rte_flow_action_rss *with)
1244 * When user flush all RSS rule, RSS func is set invalid with
1245 * RTE_ETH_HASH_FUNCTION_MAX. Then the user create a flow after
1246 * flushed, any validate RSS func is different with it before
1247 * flushed. Others, when user create an action RSS with RSS func
1248 * specified RTE_ETH_HASH_FUNCTION_DEFAULT, the func is the same
1249 * between continuous RSS flow.
1251 if (comp->func == RTE_ETH_HASH_FUNCTION_MAX)
1252 func_is_same = false;
1254 func_is_same = (with->func != RTE_ETH_HASH_FUNCTION_DEFAULT) ?
1255 (comp->func == with->func) : true;
1257 return (func_is_same &&
1258 comp->types == (with->types & HNS3_ETH_RSS_SUPPORT) &&
1259 comp->level == with->level && comp->key_len == with->key_len &&
1260 comp->queue_num == with->queue_num &&
1261 !memcmp(comp->key, with->key, with->key_len) &&
1262 !memcmp(comp->queue, with->queue,
1263 sizeof(*with->queue) * with->queue_num));
1267 hns3_rss_conf_copy(struct hns3_rss_conf *out,
1268 const struct rte_flow_action_rss *in)
1270 if (in->key_len > RTE_DIM(out->key) ||
1271 in->queue_num > RTE_DIM(out->queue))
1273 if (in->key == NULL && in->key_len)
1275 out->conf = (struct rte_flow_action_rss) {
1279 .key_len = in->key_len,
1280 .queue_num = in->queue_num,
1282 out->conf.queue = memcpy(out->queue, in->queue,
1283 sizeof(*in->queue) * in->queue_num);
1285 out->conf.key = memcpy(out->key, in->key, in->key_len);
1291 hns3_rss_input_tuple_supported(struct hns3_hw *hw,
1292 const struct rte_flow_action_rss *rss)
1295 * For IP packet, it is not supported to use src/dst port fields to RSS
1296 * hash for the following packet types.
1297 * - IPV4 FRAG | IPV4 NONFRAG | IPV6 FRAG | IPV6 NONFRAG
1298 * Besides, for Kunpeng920, the NIC HW is not supported to use src/dst
1299 * port fields to RSS hash for IPV6 SCTP packet type. However, the
1300 * Kunpeng930 and future kunpeng series support to use src/dst port
1301 * fields to RSS hash for IPv6 SCTP packet type.
1303 if (rss->types & (RTE_ETH_RSS_L4_DST_ONLY | RTE_ETH_RSS_L4_SRC_ONLY) &&
1304 (rss->types & RTE_ETH_RSS_IP ||
1305 (!hw->rss_info.ipv6_sctp_offload_supported &&
1306 rss->types & RTE_ETH_RSS_NONFRAG_IPV6_SCTP)))
1313 * This function is used to parse rss action validation.
1316 hns3_parse_rss_filter(struct rte_eth_dev *dev,
1317 const struct rte_flow_action *actions,
1318 struct rte_flow_error *error)
1320 struct hns3_adapter *hns = dev->data->dev_private;
1321 struct hns3_hw *hw = &hns->hw;
1322 struct hns3_rss_conf *rss_conf = &hw->rss_info;
1323 const struct rte_flow_action_rss *rss;
1324 const struct rte_flow_action *act;
1325 uint32_t act_index = 0;
1328 NEXT_ITEM_OF_ACTION(act, actions, act_index);
1332 return rte_flow_error_set(error, EINVAL,
1333 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1334 act, "no valid queues");
1337 if (rss->queue_num > RTE_DIM(rss_conf->queue))
1338 return rte_flow_error_set(error, ENOTSUP,
1339 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1340 "queue number configured exceeds "
1341 "queue buffer size driver supported");
1343 for (n = 0; n < rss->queue_num; n++) {
1344 if (rss->queue[n] < hw->alloc_rss_size)
1346 return rte_flow_error_set(error, EINVAL,
1347 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1348 "queue id must be less than queue number allocated to a TC");
1351 if (!(rss->types & HNS3_ETH_RSS_SUPPORT) && rss->types)
1352 return rte_flow_error_set(error, EINVAL,
1353 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1355 "Flow types is unsupported by "
1357 if (rss->func >= RTE_ETH_HASH_FUNCTION_MAX)
1358 return rte_flow_error_set(error, ENOTSUP,
1359 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1360 "RSS hash func are not supported");
1362 return rte_flow_error_set(error, ENOTSUP,
1363 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1364 "a nonzero RSS encapsulation level is not supported");
1365 if (rss->key_len && rss->key_len != RTE_DIM(rss_conf->key))
1366 return rte_flow_error_set(error, ENOTSUP,
1367 RTE_FLOW_ERROR_TYPE_ACTION_CONF, act,
1368 "RSS hash key must be exactly 40 bytes");
1370 if (!hns3_rss_input_tuple_supported(hw, rss))
1371 return rte_flow_error_set(error, EINVAL,
1372 RTE_FLOW_ERROR_TYPE_ACTION_CONF,
1374 "input RSS types are not supported");
1378 /* Check if the next not void action is END */
1379 NEXT_ITEM_OF_ACTION(act, actions, act_index);
1380 if (act->type != RTE_FLOW_ACTION_TYPE_END) {
1381 memset(rss_conf, 0, sizeof(struct hns3_rss_conf));
1382 return rte_flow_error_set(error, EINVAL,
1383 RTE_FLOW_ERROR_TYPE_ACTION,
1384 act, "Not supported action.");
1391 hns3_disable_rss(struct hns3_hw *hw)
1395 /* Redirected the redirection table to queue 0 */
1396 ret = hns3_rss_reset_indir_table(hw);
1401 hw->rss_info.conf.types = 0;
1402 hw->rss_dis_flag = true;
1408 hns3_adjust_rss_key(struct hns3_hw *hw, struct rte_flow_action_rss *rss_conf)
1410 if (rss_conf->key == NULL || rss_conf->key_len < HNS3_RSS_KEY_SIZE) {
1411 hns3_warn(hw, "Default RSS hash key to be set");
1412 rss_conf->key = hns3_hash_key;
1413 rss_conf->key_len = HNS3_RSS_KEY_SIZE;
1418 hns3_parse_rss_algorithm(struct hns3_hw *hw, enum rte_eth_hash_function *func,
1421 enum rte_eth_hash_function algo_func = *func;
1422 switch (algo_func) {
1423 case RTE_ETH_HASH_FUNCTION_DEFAULT:
1424 /* Keep *hash_algo as what it used to be */
1425 algo_func = hw->rss_info.conf.func;
1427 case RTE_ETH_HASH_FUNCTION_TOEPLITZ:
1428 *hash_algo = HNS3_RSS_HASH_ALGO_TOEPLITZ;
1430 case RTE_ETH_HASH_FUNCTION_SIMPLE_XOR:
1431 *hash_algo = HNS3_RSS_HASH_ALGO_SIMPLE;
1433 case RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ:
1434 *hash_algo = HNS3_RSS_HASH_ALGO_SYMMETRIC_TOEP;
1437 hns3_err(hw, "Invalid RSS algorithm configuration(%d)",
1447 hns3_hw_rss_hash_set(struct hns3_hw *hw, struct rte_flow_action_rss *rss_config)
1449 struct hns3_rss_tuple_cfg *tuple;
1452 hns3_adjust_rss_key(hw, rss_config);
1454 ret = hns3_parse_rss_algorithm(hw, &rss_config->func,
1455 &hw->rss_info.hash_algo);
1459 ret = hns3_rss_set_algo_key(hw, rss_config->key);
1463 hw->rss_info.conf.func = rss_config->func;
1465 tuple = &hw->rss_info.rss_tuple_sets;
1466 ret = hns3_set_rss_tuple_by_rss_hf(hw, tuple, rss_config->types);
1468 hns3_err(hw, "Update RSS tuples by rss hf failed %d", ret);
1474 hns3_update_indir_table(struct rte_eth_dev *dev,
1475 const struct rte_flow_action_rss *conf, uint16_t num)
1477 struct hns3_adapter *hns = dev->data->dev_private;
1478 struct hns3_hw *hw = &hns->hw;
1479 uint16_t indir_tbl[HNS3_RSS_IND_TBL_SIZE_MAX];
1483 /* Fill in redirection table */
1484 memcpy(indir_tbl, hw->rss_info.rss_indirection_tbl,
1485 sizeof(hw->rss_info.rss_indirection_tbl));
1486 for (i = 0, j = 0; i < hw->rss_ind_tbl_size; i++, j++) {
1488 if (conf->queue[j] >= hw->alloc_rss_size) {
1489 hns3_err(hw, "queue id(%u) set to redirection table "
1490 "exceeds queue number(%u) allocated to a TC.",
1491 conf->queue[j], hw->alloc_rss_size);
1494 indir_tbl[i] = conf->queue[j];
1497 return hns3_set_rss_indir_table(hw, indir_tbl, hw->rss_ind_tbl_size);
1501 hns3_config_rss_filter(struct rte_eth_dev *dev,
1502 const struct hns3_rss_conf *conf, bool add)
1504 struct hns3_adapter *hns = dev->data->dev_private;
1505 struct hns3_rss_conf_ele *rss_filter_ptr;
1506 struct hns3_hw *hw = &hns->hw;
1507 struct hns3_rss_conf *rss_info;
1508 uint64_t flow_types;
1512 struct rte_flow_action_rss rss_flow_conf = {
1513 .func = conf->conf.func,
1514 .level = conf->conf.level,
1515 .types = conf->conf.types,
1516 .key_len = conf->conf.key_len,
1517 .queue_num = conf->conf.queue_num,
1518 .key = conf->conf.key_len ?
1519 (void *)(uintptr_t)conf->conf.key : NULL,
1520 .queue = conf->conf.queue,
1523 /* Filter the unsupported flow types */
1524 flow_types = conf->conf.types ?
1525 rss_flow_conf.types & HNS3_ETH_RSS_SUPPORT :
1526 hw->rss_info.conf.types;
1527 if (flow_types != rss_flow_conf.types)
1528 hns3_warn(hw, "modified RSS types based on hardware support, "
1529 "requested:0x%" PRIx64 " configured:0x%" PRIx64,
1530 rss_flow_conf.types, flow_types);
1531 /* Update the useful flow types */
1532 rss_flow_conf.types = flow_types;
1534 rss_info = &hw->rss_info;
1539 ret = hns3_disable_rss(hw);
1541 hns3_err(hw, "RSS disable failed(%d)", ret);
1545 if (rss_flow_conf.queue_num) {
1547 * Due the content of queue pointer have been reset to
1548 * 0, the rss_info->conf.queue should be set to NULL
1550 rss_info->conf.queue = NULL;
1551 rss_info->conf.queue_num = 0;
1554 /* set RSS func invalid after flushed */
1555 rss_info->conf.func = RTE_ETH_HASH_FUNCTION_MAX;
1559 /* Set rx queues to use */
1560 num = RTE_MIN(dev->data->nb_rx_queues, rss_flow_conf.queue_num);
1561 if (rss_flow_conf.queue_num > num)
1562 hns3_warn(hw, "Config queue numbers %u are beyond the scope of truncated",
1563 rss_flow_conf.queue_num);
1564 hns3_info(hw, "Max of contiguous %u PF queues are configured", num);
1566 rte_spinlock_lock(&hw->lock);
1568 ret = hns3_update_indir_table(dev, &rss_flow_conf, num);
1570 goto rss_config_err;
1573 /* Set hash algorithm and flow types by the user's config */
1574 ret = hns3_hw_rss_hash_set(hw, &rss_flow_conf);
1576 goto rss_config_err;
1578 ret = hns3_rss_conf_copy(rss_info, &rss_flow_conf);
1580 hns3_err(hw, "RSS config init fail(%d)", ret);
1581 goto rss_config_err;
1585 * When create a new RSS rule, the old rule will be overlaid and set
1588 TAILQ_FOREACH(rss_filter_ptr, &hw->flow_rss_list, entries)
1589 rss_filter_ptr->filter_info.valid = false;
1592 rte_spinlock_unlock(&hw->lock);
1598 hns3_clear_rss_filter(struct rte_eth_dev *dev)
1600 struct hns3_adapter *hns = dev->data->dev_private;
1601 struct hns3_rss_conf_ele *rss_filter_ptr;
1602 struct hns3_hw *hw = &hns->hw;
1603 int rss_rule_succ_cnt = 0; /* count for success of clearing RSS rules */
1604 int rss_rule_fail_cnt = 0; /* count for failure of clearing RSS rules */
1607 rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list);
1608 while (rss_filter_ptr) {
1609 TAILQ_REMOVE(&hw->flow_rss_list, rss_filter_ptr, entries);
1610 ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info,
1613 rss_rule_fail_cnt++;
1615 rss_rule_succ_cnt++;
1616 rte_free(rss_filter_ptr);
1617 rss_filter_ptr = TAILQ_FIRST(&hw->flow_rss_list);
1620 if (rss_rule_fail_cnt) {
1621 hns3_err(hw, "fail to delete all RSS filters, success num = %d "
1622 "fail num = %d", rss_rule_succ_cnt,
1631 hns3_restore_rss_filter(struct rte_eth_dev *dev)
1633 struct hns3_adapter *hns = dev->data->dev_private;
1634 struct hns3_hw *hw = &hns->hw;
1636 /* When user flush all rules, it doesn't need to restore RSS rule */
1637 if (hw->rss_info.conf.func == RTE_ETH_HASH_FUNCTION_MAX)
1640 return hns3_config_rss_filter(dev, &hw->rss_info, true);
1644 hns3_flow_parse_rss(struct rte_eth_dev *dev,
1645 const struct hns3_rss_conf *conf, bool add)
1647 struct hns3_adapter *hns = dev->data->dev_private;
1648 struct hns3_hw *hw = &hns->hw;
1651 ret = hns3_action_rss_same(&hw->rss_info.conf, &conf->conf);
1653 hns3_err(hw, "Enter duplicate RSS configuration : %d", ret);
1657 return hns3_config_rss_filter(dev, conf, add);
1661 hns3_flow_args_check(const struct rte_flow_attr *attr,
1662 const struct rte_flow_item pattern[],
1663 const struct rte_flow_action actions[],
1664 struct rte_flow_error *error)
1666 if (pattern == NULL)
1667 return rte_flow_error_set(error, EINVAL,
1668 RTE_FLOW_ERROR_TYPE_ITEM_NUM,
1669 NULL, "NULL pattern.");
1671 if (actions == NULL)
1672 return rte_flow_error_set(error, EINVAL,
1673 RTE_FLOW_ERROR_TYPE_ACTION_NUM,
1674 NULL, "NULL action.");
1677 return rte_flow_error_set(error, EINVAL,
1678 RTE_FLOW_ERROR_TYPE_ATTR,
1679 NULL, "NULL attribute.");
1681 return hns3_check_attr(attr, error);
1685 * Check if the flow rule is supported by hns3.
1686 * It only checks the format. Don't guarantee the rule can be programmed into
1687 * the HW. Because there can be no enough room for the rule.
1690 hns3_flow_validate(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1691 const struct rte_flow_item pattern[],
1692 const struct rte_flow_action actions[],
1693 struct rte_flow_error *error)
1695 struct hns3_fdir_rule fdir_rule;
1698 ret = hns3_flow_args_check(attr, pattern, actions, error);
1702 if (hns3_find_rss_general_action(pattern, actions))
1703 return hns3_parse_rss_filter(dev, actions, error);
1705 memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule));
1706 return hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error);
1710 hns3_flow_create_rss_rule(struct rte_eth_dev *dev,
1711 const struct rte_flow_action *act,
1712 struct rte_flow *flow)
1714 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1715 struct hns3_rss_conf_ele *rss_filter_ptr;
1716 const struct hns3_rss_conf *rss_conf;
1719 rss_filter_ptr = rte_zmalloc("hns3 rss filter",
1720 sizeof(struct hns3_rss_conf_ele), 0);
1721 if (rss_filter_ptr == NULL) {
1722 hns3_err(hw, "failed to allocate hns3_rss_filter memory");
1727 * After all the preceding tasks are successfully configured, configure
1728 * rules to the hardware to simplify the rollback of rules in the
1731 rss_conf = (const struct hns3_rss_conf *)act->conf;
1732 ret = hns3_flow_parse_rss(dev, rss_conf, true);
1734 rte_free(rss_filter_ptr);
1738 hns3_rss_conf_copy(&rss_filter_ptr->filter_info, &rss_conf->conf);
1739 rss_filter_ptr->filter_info.valid = true;
1740 TAILQ_INSERT_TAIL(&hw->flow_rss_list, rss_filter_ptr, entries);
1741 flow->rule = rss_filter_ptr;
1742 flow->filter_type = RTE_ETH_FILTER_HASH;
1748 hns3_flow_create_fdir_rule(struct rte_eth_dev *dev,
1749 const struct rte_flow_item pattern[],
1750 const struct rte_flow_action actions[],
1751 struct rte_flow_error *error,
1752 struct rte_flow *flow)
1754 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
1755 struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw);
1756 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1757 struct hns3_fdir_rule fdir_rule;
1760 memset(&fdir_rule, 0, sizeof(struct hns3_fdir_rule));
1761 ret = hns3_parse_fdir_filter(dev, pattern, actions, &fdir_rule, error);
1765 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER) {
1766 ret = hns3_counter_new(dev, 0,
1767 fdir_rule.act_cnt.id, error);
1771 flow->counter_id = fdir_rule.act_cnt.id;
1774 fdir_rule_ptr = rte_zmalloc("hns3 fdir rule",
1775 sizeof(struct hns3_fdir_rule_ele), 0);
1776 if (fdir_rule_ptr == NULL) {
1777 hns3_err(hw, "failed to allocate fdir_rule memory.");
1783 * After all the preceding tasks are successfully configured, configure
1784 * rules to the hardware to simplify the rollback of rules in the
1787 ret = hns3_fdir_filter_program(hns, &fdir_rule, false);
1789 goto err_fdir_filter;
1791 memcpy(&fdir_rule_ptr->fdir_conf, &fdir_rule,
1792 sizeof(struct hns3_fdir_rule));
1793 TAILQ_INSERT_TAIL(&hw->flow_fdir_list, fdir_rule_ptr, entries);
1794 flow->rule = fdir_rule_ptr;
1795 flow->filter_type = RTE_ETH_FILTER_FDIR;
1800 rte_free(fdir_rule_ptr);
1802 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
1803 hns3_counter_release(dev, fdir_rule.act_cnt.id);
1809 * Create or destroy a flow rule.
1810 * Theorically one rule can match more than one filters.
1811 * We will let it use the filter which it hit first.
1812 * So, the sequence matters.
1814 static struct rte_flow *
1815 hns3_flow_create(struct rte_eth_dev *dev, const struct rte_flow_attr *attr,
1816 const struct rte_flow_item pattern[],
1817 const struct rte_flow_action actions[],
1818 struct rte_flow_error *error)
1820 struct hns3_adapter *hns = dev->data->dev_private;
1821 struct hns3_hw *hw = &hns->hw;
1822 struct hns3_flow_mem *flow_node;
1823 const struct rte_flow_action *act;
1824 struct rte_flow *flow;
1827 ret = hns3_flow_validate(dev, attr, pattern, actions, error);
1831 flow = rte_zmalloc("hns3 flow", sizeof(struct rte_flow), 0);
1833 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1834 NULL, "Failed to allocate flow memory");
1837 flow_node = rte_zmalloc("hns3 flow node",
1838 sizeof(struct hns3_flow_mem), 0);
1839 if (flow_node == NULL) {
1840 rte_flow_error_set(error, ENOMEM, RTE_FLOW_ERROR_TYPE_HANDLE,
1841 NULL, "Failed to allocate flow list memory");
1846 flow_node->flow = flow;
1847 TAILQ_INSERT_TAIL(&hw->flow_list, flow_node, entries);
1849 act = hns3_find_rss_general_action(pattern, actions);
1851 ret = hns3_flow_create_rss_rule(dev, act, flow);
1853 ret = hns3_flow_create_fdir_rule(dev, pattern, actions,
1858 rte_flow_error_set(error, -ret, RTE_FLOW_ERROR_TYPE_HANDLE, NULL,
1859 "Failed to create flow");
1860 TAILQ_REMOVE(&hw->flow_list, flow_node, entries);
1861 rte_free(flow_node);
1867 /* Destroy a flow rule on hns3. */
1869 hns3_flow_destroy(struct rte_eth_dev *dev, struct rte_flow *flow,
1870 struct rte_flow_error *error)
1872 struct hns3_adapter *hns = dev->data->dev_private;
1873 struct hns3_fdir_rule_ele *fdir_rule_ptr;
1874 struct hns3_rss_conf_ele *rss_filter_ptr;
1875 struct hns3_flow_mem *flow_node;
1876 enum rte_filter_type filter_type;
1877 struct hns3_fdir_rule fdir_rule;
1878 struct hns3_hw *hw = &hns->hw;
1882 return rte_flow_error_set(error, EINVAL,
1883 RTE_FLOW_ERROR_TYPE_HANDLE,
1884 flow, "Flow is NULL");
1886 filter_type = flow->filter_type;
1887 switch (filter_type) {
1888 case RTE_ETH_FILTER_FDIR:
1889 fdir_rule_ptr = (struct hns3_fdir_rule_ele *)flow->rule;
1890 memcpy(&fdir_rule, &fdir_rule_ptr->fdir_conf,
1891 sizeof(struct hns3_fdir_rule));
1893 ret = hns3_fdir_filter_program(hns, &fdir_rule, true);
1895 return rte_flow_error_set(error, EIO,
1896 RTE_FLOW_ERROR_TYPE_HANDLE,
1898 "Destroy FDIR fail.Try again");
1899 if (fdir_rule.flags & HNS3_RULE_FLAG_COUNTER)
1900 hns3_counter_release(dev, fdir_rule.act_cnt.id);
1901 TAILQ_REMOVE(&hw->flow_fdir_list, fdir_rule_ptr, entries);
1902 rte_free(fdir_rule_ptr);
1903 fdir_rule_ptr = NULL;
1905 case RTE_ETH_FILTER_HASH:
1906 rss_filter_ptr = (struct hns3_rss_conf_ele *)flow->rule;
1907 ret = hns3_config_rss_filter(dev, &rss_filter_ptr->filter_info,
1910 return rte_flow_error_set(error, EIO,
1911 RTE_FLOW_ERROR_TYPE_HANDLE,
1913 "Destroy RSS fail.Try again");
1914 TAILQ_REMOVE(&hw->flow_rss_list, rss_filter_ptr, entries);
1915 rte_free(rss_filter_ptr);
1916 rss_filter_ptr = NULL;
1919 return rte_flow_error_set(error, EINVAL,
1920 RTE_FLOW_ERROR_TYPE_HANDLE, flow,
1921 "Unsupported filter type");
1924 TAILQ_FOREACH(flow_node, &hw->flow_list, entries) {
1925 if (flow_node->flow == flow) {
1926 TAILQ_REMOVE(&hw->flow_list, flow_node, entries);
1927 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;
2113 hns3_flow_init(struct rte_eth_dev *dev)
2115 struct hns3_hw *hw = HNS3_DEV_PRIVATE_TO_HW(dev->data->dev_private);
2116 pthread_mutexattr_t attr;
2118 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
2121 pthread_mutexattr_init(&attr);
2122 pthread_mutexattr_setpshared(&attr, PTHREAD_PROCESS_SHARED);
2123 pthread_mutex_init(&hw->flows_lock, &attr);
2124 dev->data->dev_flags |= RTE_ETH_DEV_FLOW_OPS_THREAD_SAFE;
2126 TAILQ_INIT(&hw->flow_fdir_list);
2127 TAILQ_INIT(&hw->flow_rss_list);
2128 TAILQ_INIT(&hw->flow_list);
2132 hns3_flow_uninit(struct rte_eth_dev *dev)
2134 struct rte_flow_error error;
2135 if (rte_eal_process_type() == RTE_PROC_PRIMARY)
2136 hns3_flow_flush_wrap(dev, &error);