]> git.proxmox.com Git - ceph.git/blob - ceph/src/spdk/dpdk/drivers/net/hns3/hns3_fdir.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / spdk / dpdk / drivers / net / hns3 / hns3_fdir.h
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 uint8_t forward_to_direct_queue;
108 uint16_t queue_id;
109 uint8_t use_counter;
110 uint8_t counter_id;
111 uint8_t use_next_stage;
112 uint8_t write_rule_id_to_bd;
113 uint8_t next_input_key;
114 uint16_t rule_id;
115 };
116
117 struct hns3_flow_counter {
118 LIST_ENTRY(hns3_flow_counter) next; /* Pointer to the next counter. */
119 uint32_t shared:1; /* Share counter ID with other flow rules. */
120 uint32_t ref_cnt:31; /* Reference counter. */
121 uint16_t id; /* Counter ID. */
122 uint64_t hits; /* Number of packets matched by the rule. */
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
129 struct hns3_fdir_key_conf {
130 struct hns3_fd_rule_tuples spec;
131 struct hns3_fd_rule_tuples mask;
132 uint8_t vlan_num;
133 uint8_t outer_vlan_num;
134 };
135
136 struct hns3_fdir_rule {
137 struct hns3_fdir_key_conf key_conf;
138 uint32_t input_set;
139 uint32_t flags;
140 uint32_t fd_id; /* APP marked unique value for this rule. */
141 uint8_t action;
142 /* VF id, avaiblable when flags with HNS3_RULE_FLAG_VF_ID. */
143 uint8_t vf_id;
144 uint16_t queue_id;
145 uint16_t location;
146 struct rte_flow_action_count act_cnt;
147 };
148
149 /* FDIR filter list structure */
150 struct hns3_fdir_rule_ele {
151 TAILQ_ENTRY(hns3_fdir_rule_ele) entries;
152 struct hns3_fdir_rule fdir_conf;
153 };
154
155 /* rss filter list structure */
156 struct hns3_rss_conf_ele {
157 TAILQ_ENTRY(hns3_rss_conf_ele) entries;
158 struct hns3_rss_conf filter_info;
159 };
160
161 /* hns3_flow memory list structure */
162 struct hns3_flow_mem {
163 TAILQ_ENTRY(hns3_flow_mem) entries;
164 struct rte_flow *flow;
165 };
166
167 TAILQ_HEAD(hns3_fdir_rule_list, hns3_fdir_rule_ele);
168 TAILQ_HEAD(hns3_rss_filter_list, hns3_rss_conf_ele);
169 TAILQ_HEAD(hns3_flow_mem_list, hns3_flow_mem);
170
171 struct hns3_process_private {
172 struct hns3_fdir_rule_list fdir_list;
173 struct hns3_rss_filter_list filter_rss_list;
174 struct hns3_flow_mem_list flow_list;
175 };
176
177 /*
178 * A structure used to define fields of a FDIR related info.
179 */
180 struct hns3_fdir_info {
181 rte_spinlock_t flows_lock;
182 struct hns3_fdir_rule_list fdir_list;
183 struct hns3_fdir_rule_ele **hash_map;
184 struct rte_hash *hash_handle;
185 struct hns3_fd_cfg fd_cfg;
186 };
187
188 struct rte_flow {
189 enum rte_filter_type filter_type;
190 void *rule;
191 uint32_t counter_id;
192 };
193 struct hns3_adapter;
194
195 int hns3_init_fd_config(struct hns3_adapter *hns);
196 int hns3_fdir_filter_init(struct hns3_adapter *hns);
197 void hns3_fdir_filter_uninit(struct hns3_adapter *hns);
198 int hns3_fdir_filter_program(struct hns3_adapter *hns,
199 struct hns3_fdir_rule *rule, bool del);
200 int hns3_clear_all_fdir_filter(struct hns3_adapter *hns);
201 int hns3_get_count(struct hns3_hw *hw, uint32_t id, uint64_t *value);
202 void hns3_filterlist_init(struct rte_eth_dev *dev);
203 int hns3_restore_all_fdir_filter(struct hns3_adapter *hns);
204
205 #endif /* _HNS3_FDIR_H_ */