1cb389d0217e45af1dc202e6f99e6c595311ef9b
[dpdk.git] / drivers / net / hinic / hinic_pmd_ethdev.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Huawei Technologies Co., Ltd
3  */
4
5 #ifndef _HINIC_PMD_ETHDEV_H_
6 #define _HINIC_PMD_ETHDEV_H_
7
8 #include <rte_ethdev.h>
9 #include <rte_ethdev_core.h>
10
11 #include "base/hinic_compat.h"
12 #include "base/hinic_pmd_cfg.h"
13
14 #define HINIC_DEV_NAME_LEN      32
15 #define HINIC_MAX_RX_QUEUES     64
16
17 /* mbuf pool for copy invalid mbuf segs */
18 #define HINIC_COPY_MEMPOOL_DEPTH        128
19 #define HINIC_COPY_MBUF_SIZE            4096
20
21 #define SIZE_8BYTES(size)       (ALIGN((u32)(size), 8) >> 3)
22
23 #define HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev) \
24         ((struct hinic_nic_dev *)(dev)->data->dev_private)
25
26 #define HINIC_MAX_QUEUE_DEPTH           4096
27 #define HINIC_MIN_QUEUE_DEPTH           128
28 #define HINIC_TXD_ALIGN                 1
29 #define HINIC_RXD_ALIGN                 1
30
31 #define HINIC_UINT32_BIT_SIZE      (CHAR_BIT * sizeof(uint32_t))
32 #define HINIC_VFTA_SIZE            (4096 / HINIC_UINT32_BIT_SIZE)
33
34 enum hinic_dev_status {
35         HINIC_DEV_INIT,
36         HINIC_DEV_CLOSE,
37         HINIC_DEV_START,
38         HINIC_DEV_INTR_EN,
39 };
40
41 #define HINIC_MAX_Q_FILTERS     64 /* hinic just support 64 filter types */
42 #define HINIC_PKT_TYPE_FIND_ID(pkt_type) ((pkt_type) - HINIC_MAX_Q_FILTERS)
43
44 /* 5tuple filter info */
45 struct hinic_5tuple_filter_info {
46         uint32_t dst_ip;
47         uint32_t src_ip;
48         uint16_t dst_port;
49         uint16_t src_port;
50         uint8_t proto; /* l4 protocol. */
51         /*
52          * seven levels (001b-111b), 111b is highest,
53          * used when more than one filter matches.
54          */
55         uint8_t priority;
56         uint8_t dst_ip_mask:1, /* if mask is 1b, do not compare dst ip. */
57                 src_ip_mask:1, /* if mask is 1b, do not compare src ip. */
58                 dst_port_mask:1, /* if mask is 1b, do not compare dst port. */
59                 src_port_mask:1, /* if mask is 1b, do not compare src port. */
60                 proto_mask:1; /* if mask is 1b, do not compare protocol. */
61 };
62
63 /* 5tuple filter structure */
64 struct hinic_5tuple_filter {
65         TAILQ_ENTRY(hinic_5tuple_filter) entries;
66         uint16_t index;       /* the index of 5tuple filter */
67         struct hinic_5tuple_filter_info filter_info;
68         uint16_t queue;       /* rx queue assigned to */
69 };
70
71 TAILQ_HEAD(hinic_5tuple_filter_list, hinic_5tuple_filter);
72
73 /*
74  * If this filter is added by configuration,
75  * it should not be removed.
76  */
77 struct hinic_pkt_filter {
78         uint16_t pkt_proto;
79         uint8_t qid;
80         bool    enable;
81 };
82
83 /* Structure to store filters' info. */
84 struct hinic_filter_info {
85         uint8_t pkt_type;
86         uint8_t qid;
87         uint64_t type_mask;  /* Bit mask for every used filter */
88         struct hinic_5tuple_filter_list fivetuple_list;
89         struct hinic_pkt_filter pkt_filters[HINIC_MAX_Q_FILTERS];
90 };
91
92 /* Information about the fdir mode. */
93 struct hinic_hw_fdir_mask {
94         uint32_t src_ipv4_mask;
95         uint32_t dst_ipv4_mask;
96         uint16_t src_port_mask;
97         uint16_t dst_port_mask;
98         uint16_t proto_mask;
99         uint16_t tunnel_flag;
100         uint16_t tunnel_inner_src_port_mask;
101         uint16_t tunnel_inner_dst_port_mask;
102         uint16_t dst_ipv6_mask;
103 };
104
105 /* Flow Director attribute */
106 struct hinic_atr_input {
107         uint32_t dst_ip;
108         uint32_t src_ip;
109         uint16_t src_port;
110         uint16_t dst_port;
111         uint16_t proto;
112         uint16_t tunnel_flag;
113         uint16_t tunnel_inner_src_port;
114         uint16_t tunnel_inner_dst_port;
115         uint8_t  dst_ipv6[16];
116 };
117
118 enum hinic_fdir_mode {
119         HINIC_FDIR_MODE_NORMAL      = 0,
120         HINIC_FDIR_MODE_TCAM        = 1,
121 };
122
123 #define HINIC_PF_MAX_TCAM_FILTERS       1024
124 #define HINIC_VF_MAX_TCAM_FILTERS       128
125 #define HINIC_SUPPORT_PF_MAX_NUM        4
126 #define HINIC_TOTAL_PF_MAX_NUM          16
127 #define HINIC_SUPPORT_VF_MAX_NUM        32
128 #define HINIC_TCAM_BLOCK_TYPE_PF        0 /* 1024 tcam index of a block */
129 #define HINIC_TCAM_BLOCK_TYPE_VF        1 /* 128 tcam index of a block */
130
131 #define HINIC_PKT_VF_TCAM_INDEX_START(block_index)  \
132                 (HINIC_PF_MAX_TCAM_FILTERS * HINIC_SUPPORT_PF_MAX_NUM + \
133                 HINIC_VF_MAX_TCAM_FILTERS * (block_index))
134
135 TAILQ_HEAD(hinic_tcam_filter_list, hinic_tcam_filter);
136
137 struct hinic_tcam_info {
138         struct hinic_tcam_filter_list tcam_list;
139         u8 tcam_index_array[HINIC_PF_MAX_TCAM_FILTERS];
140         u16 tcam_block_index;
141         u16 tcam_rule_nums;
142 };
143
144 struct tag_tcam_key_mem {
145 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN)
146
147                 u32 rsvd0:16;
148                 u32 function_id:16;
149
150                 u32 protocol:8;
151                 /*
152                  * tunnel packet, mask must be 0xff, spec value is 1;
153                  * normal packet, mask must be 0, spec value is 0;
154                  * if tunnal packet, ucode use
155                  * sip/dip/protocol/src_port/dst_dport from inner packet
156                  */
157                 u32 tunnel_flag:8;
158                 u32 sip_h:16;
159
160                 u32 sip_l:16;
161                 u32 dip_h:16;
162
163                 u32 dip_l:16;
164                 u32 src_port:16;
165
166                 u32 dst_port:16;
167                 /*
168                  * tunnel packet and normal packet,
169                  * ext_dip mask must be 0xffffffff
170                  */
171                 u32 ext_dip_h:16;
172                 u32 ext_dip_l:16;
173                 u32 rsvd2:16;
174 #else
175                 u32 function_id:16;
176                 u32 rsvd0:16;
177
178                 u32 sip_h:16;
179                 u32 tunnel_flag:8;
180                 u32 protocol:8;
181
182                 u32 dip_h:16;
183                 u32 sip_l:16;
184
185                 u32 src_port:16;
186                 u32 dip_l:16;
187
188                 u32 ext_dip_h:16;
189                 u32 dst_port:16;
190
191                 u32 rsvd2:16;
192                 u32 ext_dip_l:16;
193 #endif
194 };
195
196 struct tag_tcam_key_ipv6_mem {
197 #if (RTE_BYTE_ORDER == RTE_BIG_ENDIAN)
198                 u32 rsvd0:16;
199                 u32 ipv6_flag:1;
200                 u32 protocol:7;
201                 u32 function_id:8;
202
203                 u32 dst_port:16;
204                 u32 ipv6_key0:16;
205
206                 u32 ipv6_key1:16;
207                 u32 ipv6_key2:16;
208
209                 u32 ipv6_key3:16;
210                 u32 ipv6_key4:16;
211
212                 u32 ipv6_key5:16;
213                 u32 ipv6_key6:16;
214
215                 u32 ipv6_key7:16;
216                 u32 rsvd2:16;
217 #else
218                 u32 function_id:8;
219                 u32 protocol:7;
220                 u32 ipv6_flag:1;
221                 u32 rsvd0:16;
222
223                 u32 ipv6_key0:16;
224                 u32 dst_port:16;
225
226                 u32 ipv6_key2:16;
227                 u32 ipv6_key1:16;
228
229                 u32 ipv6_key4:16;
230                 u32 ipv6_key3:16;
231
232                 u32 ipv6_key6:16;
233                 u32 ipv6_key5:16;
234
235                 u32 rsvd2:16;
236                 u32 ipv6_key7:16;
237 #endif
238 };
239
240 struct tag_tcam_key {
241         union {
242                 struct tag_tcam_key_mem key_info;
243                 struct tag_tcam_key_ipv6_mem key_info_ipv6;
244         };
245
246         union {
247                 struct tag_tcam_key_mem key_mask;
248                 struct tag_tcam_key_ipv6_mem key_mask_ipv6;
249         };
250 };
251
252 struct hinic_fdir_rule {
253         struct hinic_hw_fdir_mask mask;
254         struct hinic_atr_input hinic_fdir; /* key of fdir filter */
255         uint8_t queue; /* queue assigned when matched */
256         enum hinic_fdir_mode mode; /* fdir type */
257         u16 tcam_index;
258 };
259
260 /* ntuple filter list structure */
261 struct hinic_ntuple_filter_ele {
262         TAILQ_ENTRY(hinic_ntuple_filter_ele) entries;
263         struct rte_eth_ntuple_filter filter_info;
264 };
265
266 /* ethertype filter list structure */
267 struct hinic_ethertype_filter_ele {
268         TAILQ_ENTRY(hinic_ethertype_filter_ele) entries;
269         struct rte_eth_ethertype_filter filter_info;
270 };
271
272 /* fdir filter list structure */
273 struct hinic_fdir_rule_ele {
274         TAILQ_ENTRY(hinic_fdir_rule_ele) entries;
275         struct hinic_fdir_rule filter_info;
276 };
277
278 struct hinic_tcam_filter {
279         TAILQ_ENTRY(hinic_tcam_filter) entries;
280         uint16_t index; /* tcam index */
281         struct tag_tcam_key tcam_key;
282         uint16_t queue; /* rx queue assigned to */
283 };
284
285 struct rte_flow {
286         enum rte_filter_type filter_type;
287         void *rule;
288 };
289
290 /* hinic_flow memory list structure */
291 struct hinic_flow_mem {
292         TAILQ_ENTRY(hinic_flow_mem) entries;
293         struct rte_flow *flow;
294 };
295
296 TAILQ_HEAD(hinic_ntuple_filter_list, hinic_ntuple_filter_ele);
297 TAILQ_HEAD(hinic_ethertype_filter_list, hinic_ethertype_filter_ele);
298 TAILQ_HEAD(hinic_fdir_rule_filter_list, hinic_fdir_rule_ele);
299 TAILQ_HEAD(hinic_flow_mem_list, hinic_flow_mem);
300
301 extern const struct rte_flow_ops hinic_flow_ops;
302
303 /* hinic nic_device */
304 struct hinic_nic_dev {
305         /* hardware device */
306         struct hinic_hwdev *hwdev;
307         struct hinic_txq **txqs;
308         struct hinic_rxq **rxqs;
309         struct rte_mempool *cpy_mpool;
310         u16 num_qps;
311         u16 num_sq;
312         u16 num_rq;
313         u16 mtu_size;
314         u8 rss_tmpl_idx;
315         u8 rss_indir_flag;
316         u8 num_rss;
317         u8 rx_queue_list[HINIC_MAX_RX_QUEUES];
318
319         bool pause_set;
320         struct nic_pause_config nic_pause;
321
322         u32 vfta[HINIC_VFTA_SIZE];      /* VLAN bitmap */
323
324         struct rte_ether_addr default_addr;
325         struct rte_ether_addr *mc_list;
326         /* info */
327         unsigned int flags;
328         struct nic_service_cap nic_cap;
329         u32 rx_mode_status;     /* promisc or allmulticast */
330         unsigned long dev_status;
331
332         char proc_dev_name[HINIC_DEV_NAME_LEN];
333         /* PF0->COS4, PF1->COS5, PF2->COS6, PF3->COS7,
334          * vf: the same with associate pf
335          */
336         u32 default_cos;
337         u32 rx_csum_en;
338
339         struct hinic_filter_info    filter;
340         struct hinic_tcam_info      tcam;
341         struct hinic_ntuple_filter_list filter_ntuple_list;
342         struct hinic_ethertype_filter_list filter_ethertype_list;
343         struct hinic_fdir_rule_filter_list filter_fdir_rule_list;
344         struct hinic_flow_mem_list hinic_flow_list;
345 };
346
347 void hinic_free_fdir_filter(struct hinic_nic_dev *nic_dev);
348
349 void hinic_destroy_fdir_filter(struct rte_eth_dev *dev);
350 #endif /* _HINIC_PMD_ETHDEV_H_ */