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 <stdint.h> 9 10 #include <rte_flow.h> 11 12 struct hns3_fd_key_cfg { 13 uint8_t key_sel; 14 uint8_t inner_sipv6_word_en; 15 uint8_t inner_dipv6_word_en; 16 uint8_t outer_sipv6_word_en; 17 uint8_t outer_dipv6_word_en; 18 uint32_t tuple_active; 19 uint32_t meta_data_active; 20 }; 21 22 enum HNS3_FD_STAGE { 23 HNS3_FD_STAGE_1, 24 HNS3_FD_STAGE_2, 25 HNS3_FD_STAGE_NUM, 26 }; 27 28 enum HNS3_FD_ACTION { 29 HNS3_FD_ACTION_ACCEPT_PACKET, 30 HNS3_FD_ACTION_DROP_PACKET, 31 }; 32 33 struct hns3_fd_cfg { 34 uint8_t fd_mode; 35 uint16_t max_key_length; 36 uint32_t rule_num[HNS3_FD_STAGE_NUM]; /* rule entry number */ 37 uint16_t cnt_num[HNS3_FD_STAGE_NUM]; /* rule hit counter number */ 38 struct hns3_fd_key_cfg key_cfg[HNS3_FD_STAGE_NUM]; 39 }; 40 41 /* OUTER_XXX indicates tuples in tunnel header of tunnel packet 42 * INNER_XXX indicate tuples in tunneled header of tunnel packet or 43 * tuples of non-tunnel packet 44 */ 45 enum HNS3_FD_TUPLE { 46 OUTER_DST_MAC, 47 OUTER_SRC_MAC, 48 OUTER_VLAN_TAG_FST, 49 OUTER_VLAN_TAG_SEC, 50 OUTER_ETH_TYPE, 51 OUTER_L2_RSV, 52 OUTER_IP_TOS, 53 OUTER_IP_PROTO, 54 OUTER_SRC_IP, 55 OUTER_DST_IP, 56 OUTER_L3_RSV, 57 OUTER_SRC_PORT, 58 OUTER_DST_PORT, 59 OUTER_L4_RSV, 60 OUTER_TUN_VNI, 61 OUTER_TUN_FLOW_ID, 62 INNER_DST_MAC, 63 INNER_SRC_MAC, 64 INNER_VLAN_TAG1, 65 INNER_VLAN_TAG2, 66 INNER_ETH_TYPE, 67 INNER_L2_RSV, 68 INNER_IP_TOS, 69 INNER_IP_PROTO, 70 INNER_SRC_IP, 71 INNER_DST_IP, 72 INNER_L3_RSV, 73 INNER_SRC_PORT, 74 INNER_DST_PORT, 75 INNER_SCTP_TAG, 76 MAX_TUPLE, 77 }; 78 79 #define VLAN_TAG_NUM_MAX 2 80 #define VNI_OR_TNI_LEN 3 81 #define IP_ADDR_LEN 4 /* Length of IPv6 address. */ 82 #define IP_ADDR_KEY_ID 3 /* The last 32bit of IP address as FDIR search key */ 83 #define IPV6_ADDR_WORD_MASK 3 /* The last two word of IPv6 as FDIR search key */ 84 85 struct hns3_fd_rule_tuples { 86 uint8_t src_mac[RTE_ETHER_ADDR_LEN]; 87 uint8_t dst_mac[RTE_ETHER_ADDR_LEN]; 88 uint32_t src_ip[IP_ADDR_LEN]; 89 uint32_t dst_ip[IP_ADDR_LEN]; 90 uint16_t src_port; 91 uint16_t dst_port; 92 uint16_t vlan_tag1; 93 uint16_t vlan_tag2; 94 uint16_t ether_type; 95 uint8_t ip_tos; 96 uint8_t ip_proto; 97 uint32_t sctp_tag; 98 uint16_t outer_src_port; 99 uint16_t tunnel_type; 100 uint16_t outer_vlan_tag1; 101 uint16_t outer_vlan_tag2; 102 uint16_t outer_ether_type; 103 uint8_t outer_proto; 104 uint8_t outer_tun_vni[VNI_OR_TNI_LEN]; 105 uint8_t outer_tun_flow_id; 106 }; 107 108 struct hns3_fd_ad_data { 109 uint16_t ad_id; 110 uint8_t drop_packet; 111 /* 112 * equal 0 when action is drop. 113 * index of queue when action is queue. 114 * index of first queue of queue region when action is queue region. 115 */ 116 uint16_t queue_id; 117 /* 118 * equal 0 when action is drop. 119 * equal 1 when action is queue. 120 * numbers of queues of queue region when action is queue region. 121 */ 122 uint16_t nb_queues; 123 uint8_t use_counter; 124 uint8_t counter_id; 125 uint8_t use_next_stage; 126 uint8_t write_rule_id_to_bd; 127 uint8_t next_input_key; 128 uint16_t rule_id; 129 }; 130 131 #define HNS3_RULE_FLAG_FDID 0x1 132 #define HNS3_RULE_FLAG_VF_ID 0x2 133 #define HNS3_RULE_FLAG_COUNTER 0x4 134 #define HNS3_RULE_FLAG_COUNTER_INDIR 0x8 135 136 struct hns3_fdir_key_conf { 137 struct hns3_fd_rule_tuples spec; 138 struct hns3_fd_rule_tuples mask; 139 uint8_t vlan_num; 140 uint8_t outer_vlan_num; 141 }; 142 143 struct hns3_fdir_rule { 144 struct hns3_fdir_key_conf key_conf; 145 uint32_t input_set; 146 uint32_t flags; 147 uint32_t fd_id; /* APP marked unique value for this rule. */ 148 uint8_t action; 149 /* VF id, available when flags with HNS3_RULE_FLAG_VF_ID. */ 150 uint8_t vf_id; 151 /* 152 * equal 0 when action is drop. 153 * index of queue when action is queue. 154 * index of first queue of queue region when action is queue region. 155 */ 156 uint16_t queue_id; 157 /* 158 * equal 0 when action is drop. 159 * equal 1 when action is queue. 160 * numbers of queues of queue region when action is queue region. 161 */ 162 uint16_t nb_queues; 163 uint16_t location; 164 struct rte_flow_action_count act_cnt; 165 bool has_vlan_m; 166 bool has_vlan_v; 167 bool has_more_vlan_m; 168 bool has_more_vlan_v; 169 }; 170 171 /* FDIR filter list structure */ 172 struct hns3_fdir_rule_ele { 173 TAILQ_ENTRY(hns3_fdir_rule_ele) entries; 174 struct hns3_fdir_rule fdir_conf; 175 }; 176 177 TAILQ_HEAD(hns3_fdir_rule_list, hns3_fdir_rule_ele); 178 179 /* 180 * On 'strict' mode, hardware bases on VLAN number to exactly match the 181 * input flow. 182 */ 183 #define HNS3_FDIR_VLAN_STRICT_MATCH 1 184 #define HNS3_FDIR_VLAN_NOSTRICT_MATCH 0 185 186 /* 187 * The hardware supports many tuples match (see @enum HNS3_FD_TUPLE), 188 * however, the width of hardware entries is limited, therefore, only part 189 * of tuples are enabled (see as @hns3_init_fd_config). 190 * 191 * We should replace the existing tuples if we want to enable other tuples 192 * because the width capacity is insufficient. 193 */ 194 enum hns3_fdir_tuple_config { 195 /* Default tuple config (see as @hns3_init_fd_config). */ 196 HNS3_FDIR_TUPLE_CONFIG_DEFAULT, 197 /* 198 * Based on the default tuple config, disable the inner src-mac tuple, 199 * and enable the outer VLAN tuple. 200 */ 201 HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSMAC, 202 /* 203 * Based on the default tuple config, disable the inner dst-mac tuple, 204 * and enable the outer VLAN tuple. 205 */ 206 HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDMAC, 207 /* 208 * Based on the default tuple config, disable the inner src-ip tuple, 209 * and enable the outer VLAN tuple. 210 */ 211 HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INSIP, 212 /* 213 * Based on the default tuple config, disable the inner dst-ip tuple, 214 * and enable the outer VLAN tuple. 215 */ 216 HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_INDIP, 217 /* 218 * Based on the default tuple config, disable the sctp-tag tuple, 219 * and enable the outer VLAN tuple. 220 */ 221 HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_SCTPTAG, 222 /* 223 * Based on the default tuple config, disable the tunnel vni tuple, 224 * and enable the outer VLAN tuple. 225 */ 226 HNS3_FDIR_TUPLE_OUTVLAN_REPLACE_TUNVNI, 227 228 HNS3_FDIR_TUPLE_CONFIG_BUTT 229 }; 230 231 enum hns3_fdir_index_config { 232 /* Generate the hardware flow director index based on rte_hash (Default) */ 233 HNS3_FDIR_INDEX_CONFIG_HASH, 234 235 /* Use the rte_flow priority field as the hardware flow director index. */ 236 HNS3_FDIR_INDEX_CONFIG_PRIORITY 237 }; 238 239 /* 240 * A structure used to define fields of a FDIR related info. 241 */ 242 struct hns3_fdir_info { 243 struct hns3_fdir_rule_list fdir_list; 244 struct hns3_fdir_rule_ele **hash_map; 245 struct rte_hash *hash_handle; 246 struct hns3_fd_cfg fd_cfg; 247 uint8_t vlan_match_mode; 248 enum hns3_fdir_tuple_config tuple_cfg; 249 enum hns3_fdir_index_config index_cfg; 250 }; 251 252 struct hns3_adapter; 253 struct hns3_hw; 254 255 int hns3_init_fd_config(struct hns3_adapter *hns); 256 int hns3_fdir_filter_init(struct hns3_adapter *hns); 257 void hns3_fdir_filter_uninit(struct hns3_adapter *hns); 258 int hns3_fdir_filter_program(struct hns3_adapter *hns, 259 struct hns3_fdir_rule *rule, bool del); 260 int hns3_clear_all_fdir_filter(struct hns3_adapter *hns); 261 int hns3_fd_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value); 262 int hns3_restore_all_fdir_filter(struct hns3_adapter *hns); 263 264 enum hns3_fdir_tuple_config hns3_parse_tuple_config(const char *name); 265 const char *hns3_tuple_config_name(enum hns3_fdir_tuple_config tuple_cfg); 266 const char *hns3_fdir_index_config_name(enum hns3_fdir_index_config cfg); 267 268 #endif /* HNS3_FDIR_H */ 269