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