xref: /f-stack/dpdk/drivers/net/hns3/hns3_fdir.h (revision 2d9fd380)
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2018-2019 Hisilicon Limited.
3  */
4 
5 #ifndef _HNS3_FDIR_H_
6 #define _HNS3_FDIR_H_
7 
8 #include <rte_flow.h>
9 
10 struct 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 
20 enum HNS3_FD_STAGE {
21 	HNS3_FD_STAGE_1,
22 	HNS3_FD_STAGE_2,
23 	HNS3_FD_STAGE_NUM,
24 };
25 
26 enum HNS3_FD_ACTION {
27 	HNS3_FD_ACTION_ACCEPT_PACKET,
28 	HNS3_FD_ACTION_DROP_PACKET,
29 };
30 
31 struct 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  */
43 enum 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 
83 struct 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 
104 struct 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 
127 struct 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 
139 struct 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 
146 struct 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 */
171 struct 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 */
177 struct 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 */
183 struct hns3_flow_mem {
184 	TAILQ_ENTRY(hns3_flow_mem) entries;
185 	struct rte_flow *flow;
186 };
187 
188 TAILQ_HEAD(hns3_fdir_rule_list, hns3_fdir_rule_ele);
189 TAILQ_HEAD(hns3_rss_filter_list, hns3_rss_conf_ele);
190 TAILQ_HEAD(hns3_flow_mem_list, hns3_flow_mem);
191 
192 struct hns3_process_private {
193 	struct hns3_fdir_rule_list fdir_list;
194 	struct hns3_rss_filter_list filter_rss_list;
195 	struct hns3_flow_mem_list flow_list;
196 };
197 
198 /*
199  *  A structure used to define fields of a FDIR related info.
200  */
201 struct hns3_fdir_info {
202 	rte_spinlock_t flows_lock;
203 	struct hns3_fdir_rule_list fdir_list;
204 	struct hns3_fdir_rule_ele **hash_map;
205 	struct rte_hash *hash_handle;
206 	struct hns3_fd_cfg fd_cfg;
207 };
208 
209 struct rte_flow {
210 	enum rte_filter_type filter_type;
211 	void *rule;
212 	uint32_t counter_id;
213 };
214 struct hns3_adapter;
215 
216 int hns3_init_fd_config(struct hns3_adapter *hns);
217 int hns3_fdir_filter_init(struct hns3_adapter *hns);
218 void hns3_fdir_filter_uninit(struct hns3_adapter *hns);
219 int hns3_fdir_filter_program(struct hns3_adapter *hns,
220 			     struct hns3_fdir_rule *rule, bool del);
221 int hns3_clear_all_fdir_filter(struct hns3_adapter *hns);
222 int hns3_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value);
223 void hns3_filterlist_init(struct rte_eth_dev *dev);
224 int hns3_restore_all_fdir_filter(struct hns3_adapter *hns);
225 
226 #endif /* _HNS3_FDIR_H_ */
227