dpdk/drivers/net/hns3/hns3_fdir.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: BSD-3-Clause
   2 * Copyright(c) 2018-2021 HiSilicon Limited.
   3 */
   4
   5#ifndef _HNS3_FDIR_H_
   6#define _HNS3_FDIR_H_
   7
   8#include <rte_flow.h>
   9
  10struct hns3_fd_key_cfg {
  11        uint8_t key_sel;
  12        uint8_t inner_sipv6_word_en;
  13        uint8_t inner_dipv6_word_en;
  14        uint8_t outer_sipv6_word_en;
  15        uint8_t outer_dipv6_word_en;
  16        uint32_t tuple_active;
  17        uint32_t meta_data_active;
  18};
  19
  20enum HNS3_FD_STAGE {
  21        HNS3_FD_STAGE_1,
  22        HNS3_FD_STAGE_2,
  23        HNS3_FD_STAGE_NUM,
  24};
  25
  26enum HNS3_FD_ACTION {
  27        HNS3_FD_ACTION_ACCEPT_PACKET,
  28        HNS3_FD_ACTION_DROP_PACKET,
  29};
  30
  31struct hns3_fd_cfg {
  32        uint8_t fd_mode;
  33        uint16_t max_key_length;
  34        uint32_t rule_num[HNS3_FD_STAGE_NUM]; /* rule entry number */
  35        uint16_t cnt_num[HNS3_FD_STAGE_NUM];  /* rule hit counter number */
  36        struct hns3_fd_key_cfg key_cfg[HNS3_FD_STAGE_NUM];
  37};
  38
  39/* OUTER_XXX indicates tuples in tunnel header of tunnel packet
  40 * INNER_XXX indicate tuples in tunneled header of tunnel packet or
  41 *           tuples of non-tunnel packet
  42 */
  43enum HNS3_FD_TUPLE {
  44        OUTER_DST_MAC,
  45        OUTER_SRC_MAC,
  46        OUTER_VLAN_TAG_FST,
  47        OUTER_VLAN_TAG_SEC,
  48        OUTER_ETH_TYPE,
  49        OUTER_L2_RSV,
  50        OUTER_IP_TOS,
  51        OUTER_IP_PROTO,
  52        OUTER_SRC_IP,
  53        OUTER_DST_IP,
  54        OUTER_L3_RSV,
  55        OUTER_SRC_PORT,
  56        OUTER_DST_PORT,
  57        OUTER_L4_RSV,
  58        OUTER_TUN_VNI,
  59        OUTER_TUN_FLOW_ID,
  60        INNER_DST_MAC,
  61        INNER_SRC_MAC,
  62        INNER_VLAN_TAG1,
  63        INNER_VLAN_TAG2,
  64        INNER_ETH_TYPE,
  65        INNER_L2_RSV,
  66        INNER_IP_TOS,
  67        INNER_IP_PROTO,
  68        INNER_SRC_IP,
  69        INNER_DST_IP,
  70        INNER_L3_RSV,
  71        INNER_SRC_PORT,
  72        INNER_DST_PORT,
  73        INNER_SCTP_TAG,
  74        MAX_TUPLE,
  75};
  76
  77#define VLAN_TAG_NUM_MAX 2
  78#define VNI_OR_TNI_LEN 3
  79#define IP_ADDR_LEN    4 /* Length of IPv6 address. */
  80#define IP_ADDR_KEY_ID 3 /* The last 32bit of IP address as FDIR search key */
  81#define IPV6_ADDR_WORD_MASK 3 /* The last two word of IPv6 as FDIR search key */
  82
  83struct hns3_fd_rule_tuples {
  84        uint8_t src_mac[RTE_ETHER_ADDR_LEN];
  85        uint8_t dst_mac[RTE_ETHER_ADDR_LEN];
  86        uint32_t src_ip[IP_ADDR_LEN];
  87        uint32_t dst_ip[IP_ADDR_LEN];
  88        uint16_t src_port;
  89        uint16_t dst_port;
  90        uint16_t vlan_tag1;
  91        uint16_t vlan_tag2;
  92        uint16_t ether_type;
  93        uint8_t ip_tos;
  94        uint8_t ip_proto;
  95        uint32_t sctp_tag;
  96        uint16_t outer_src_port;
  97        uint16_t tunnel_type;
  98        uint16_t outer_ether_type;
  99        uint8_t outer_proto;
 100        uint8_t outer_tun_vni[VNI_OR_TNI_LEN];
 101        uint8_t outer_tun_flow_id;
 102};
 103
 104struct hns3_fd_ad_data {
 105        uint16_t ad_id;
 106        uint8_t drop_packet;
 107        /*
 108         * equal 0 when action is drop.
 109         * index of queue when action is queue.
 110         * index of first queue of queue region when action is queue region.
 111         */
 112        uint16_t queue_id;
 113        /*
 114         * equal 0 when action is drop.
 115         * equal 1 when action is queue.
 116         * numbers of queues of queue region when action is queue region.
 117         */
 118        uint16_t nb_queues;
 119        uint8_t use_counter;
 120        uint8_t counter_id;
 121        uint8_t use_next_stage;
 122        uint8_t write_rule_id_to_bd;
 123        uint8_t next_input_key;
 124        uint16_t rule_id;
 125};
 126
 127struct hns3_flow_counter {
 128        LIST_ENTRY(hns3_flow_counter) next; /* Pointer to the next counter. */
 129        uint32_t shared:1;   /* Share counter ID with other flow rules. */
 130        uint32_t ref_cnt:31; /* Reference counter. */
 131        uint16_t id;   /* Counter ID. */
 132        uint64_t hits; /* Number of packets matched by the rule. */
 133};
 134
 135#define HNS3_RULE_FLAG_FDID             0x1
 136#define HNS3_RULE_FLAG_VF_ID            0x2
 137#define HNS3_RULE_FLAG_COUNTER          0x4
 138
 139struct hns3_fdir_key_conf {
 140        struct hns3_fd_rule_tuples spec;
 141        struct hns3_fd_rule_tuples mask;
 142        uint8_t vlan_num;
 143        uint8_t outer_vlan_num;
 144};
 145
 146struct hns3_fdir_rule {
 147        struct hns3_fdir_key_conf key_conf;
 148        uint32_t input_set;
 149        uint32_t flags;
 150        uint32_t fd_id; /* APP marked unique value for this rule. */
 151        uint8_t action;
 152        /* VF id, avaiblable when flags with HNS3_RULE_FLAG_VF_ID. */
 153        uint8_t vf_id;
 154        /*
 155         * equal 0 when action is drop.
 156         * index of queue when action is queue.
 157         * index of first queue of queue region when action is queue region.
 158         */
 159        uint16_t queue_id;
 160        /*
 161         * equal 0 when action is drop.
 162         * equal 1 when action is queue.
 163         * numbers of queues of queue region when action is queue region.
 164         */
 165        uint16_t nb_queues;
 166        uint16_t location;
 167        struct rte_flow_action_count act_cnt;
 168};
 169
 170/* FDIR filter list structure */
 171struct hns3_fdir_rule_ele {
 172        TAILQ_ENTRY(hns3_fdir_rule_ele) entries;
 173        struct hns3_fdir_rule fdir_conf;
 174};
 175
 176/* rss filter list structure */
 177struct hns3_rss_conf_ele {
 178        TAILQ_ENTRY(hns3_rss_conf_ele) entries;
 179        struct hns3_rss_conf filter_info;
 180};
 181
 182/* hns3_flow memory list structure */
 183struct hns3_flow_mem {
 184        TAILQ_ENTRY(hns3_flow_mem) entries;
 185        struct rte_flow *flow;
 186};
 187
 188TAILQ_HEAD(hns3_fdir_rule_list, hns3_fdir_rule_ele);
 189TAILQ_HEAD(hns3_rss_filter_list, hns3_rss_conf_ele);
 190TAILQ_HEAD(hns3_flow_mem_list, hns3_flow_mem);
 191
 192/*
 193 *  A structure used to define fields of a FDIR related info.
 194 */
 195struct hns3_fdir_info {
 196        struct hns3_fdir_rule_list fdir_list;
 197        struct hns3_fdir_rule_ele **hash_map;
 198        struct rte_hash *hash_handle;
 199        struct hns3_fd_cfg fd_cfg;
 200};
 201
 202struct rte_flow {
 203        enum rte_filter_type filter_type;
 204        void *rule;
 205        uint32_t counter_id;
 206};
 207struct hns3_adapter;
 208
 209int hns3_init_fd_config(struct hns3_adapter *hns);
 210int hns3_fdir_filter_init(struct hns3_adapter *hns);
 211void hns3_fdir_filter_uninit(struct hns3_adapter *hns);
 212int hns3_fdir_filter_program(struct hns3_adapter *hns,
 213                             struct hns3_fdir_rule *rule, bool del);
 214int hns3_clear_all_fdir_filter(struct hns3_adapter *hns);
 215int hns3_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value);
 216void hns3_flow_init(struct rte_eth_dev *dev);
 217void hns3_flow_uninit(struct rte_eth_dev *dev);
 218int hns3_restore_all_fdir_filter(struct hns3_adapter *hns);
 219
 220#endif /* _HNS3_FDIR_H_ */
 221