net/i40e: add flow validate function
[dpdk.git] / drivers / net / i40e / i40e_ethdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2015 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _I40E_ETHDEV_H_
35 #define _I40E_ETHDEV_H_
36
37 #include <rte_eth_ctrl.h>
38 #include <rte_time.h>
39 #include <rte_kvargs.h>
40 #include <rte_hash.h>
41 #include <rte_flow_driver.h>
42
43 #define I40E_VLAN_TAG_SIZE        4
44
45 #define I40E_AQ_LEN               32
46 #define I40E_AQ_BUF_SZ            4096
47 /* Number of queues per TC should be one of 1, 2, 4, 8, 16, 32, 64 */
48 #define I40E_MAX_Q_PER_TC         64
49 #define I40E_NUM_DESC_DEFAULT     512
50 #define I40E_NUM_DESC_ALIGN       32
51 #define I40E_BUF_SIZE_MIN         1024
52 #define I40E_FRAME_SIZE_MAX       9728
53 #define I40E_QUEUE_BASE_ADDR_UNIT 128
54 /* number of VSIs and queue default setting */
55 #define I40E_MAX_QP_NUM_PER_VF    16
56 #define I40E_DEFAULT_QP_NUM_FDIR  1
57 #define I40E_UINT32_BIT_SIZE      (CHAR_BIT * sizeof(uint32_t))
58 #define I40E_VFTA_SIZE            (4096 / I40E_UINT32_BIT_SIZE)
59 /* Maximun number of MAC addresses */
60 #define I40E_NUM_MACADDR_MAX       64
61 /* Maximum number of VFs */
62 #define I40E_MAX_VF               128
63
64 /*
65  * vlan_id is a 12 bit number.
66  * The VFTA array is actually a 4096 bit array, 128 of 32bit elements.
67  * 2^5 = 32. The val of lower 5 bits specifies the bit in the 32bit element.
68  * The higher 7 bit val specifies VFTA array index.
69  */
70 #define I40E_VFTA_BIT(vlan_id)    (1 << ((vlan_id) & 0x1F))
71 #define I40E_VFTA_IDX(vlan_id)    ((vlan_id) >> 5)
72
73 /* Default TC traffic in case DCB is not enabled */
74 #define I40E_DEFAULT_TCMAP        0x1
75 #define I40E_FDIR_QUEUE_ID        0
76
77 /* Always assign pool 0 to main VSI, VMDQ will start from 1 */
78 #define I40E_VMDQ_POOL_BASE       1
79
80 #define I40E_DEFAULT_RX_FREE_THRESH  32
81 #define I40E_DEFAULT_RX_PTHRESH      8
82 #define I40E_DEFAULT_RX_HTHRESH      8
83 #define I40E_DEFAULT_RX_WTHRESH      0
84
85 #define I40E_DEFAULT_TX_FREE_THRESH  32
86 #define I40E_DEFAULT_TX_PTHRESH      32
87 #define I40E_DEFAULT_TX_HTHRESH      0
88 #define I40E_DEFAULT_TX_WTHRESH      0
89 #define I40E_DEFAULT_TX_RSBIT_THRESH 32
90
91 /* Bit shift and mask */
92 #define I40E_4_BIT_WIDTH  (CHAR_BIT / 2)
93 #define I40E_4_BIT_MASK   RTE_LEN2MASK(I40E_4_BIT_WIDTH, uint8_t)
94 #define I40E_8_BIT_WIDTH  CHAR_BIT
95 #define I40E_8_BIT_MASK   UINT8_MAX
96 #define I40E_16_BIT_WIDTH (CHAR_BIT * 2)
97 #define I40E_16_BIT_MASK  UINT16_MAX
98 #define I40E_32_BIT_WIDTH (CHAR_BIT * 4)
99 #define I40E_32_BIT_MASK  UINT32_MAX
100 #define I40E_48_BIT_WIDTH (CHAR_BIT * 6)
101 #define I40E_48_BIT_MASK  RTE_LEN2MASK(I40E_48_BIT_WIDTH, uint64_t)
102
103 /* Linux PF host with virtchnl version 1.1 */
104 #define PF_IS_V11(vf) \
105         (((vf)->version_major == I40E_VIRTCHNL_VERSION_MAJOR) && \
106         ((vf)->version_minor == 1))
107
108 /* index flex payload per layer */
109 enum i40e_flxpld_layer_idx {
110         I40E_FLXPLD_L2_IDX    = 0,
111         I40E_FLXPLD_L3_IDX    = 1,
112         I40E_FLXPLD_L4_IDX    = 2,
113         I40E_MAX_FLXPLD_LAYER = 3,
114 };
115 #define I40E_MAX_FLXPLD_FIED        3  /* max number of flex payload fields */
116 #define I40E_FDIR_BITMASK_NUM_WORD  2  /* max number of bitmask words */
117 #define I40E_FDIR_MAX_FLEXWORD_NUM  8  /* max number of flexpayload words */
118 #define I40E_FDIR_MAX_FLEX_LEN      16 /* len in bytes of flex payload */
119 #define I40E_INSET_MASK_NUM_REG     2  /* number of input set mask registers */
120
121 /* i40e flags */
122 #define I40E_FLAG_RSS                   (1ULL << 0)
123 #define I40E_FLAG_DCB                   (1ULL << 1)
124 #define I40E_FLAG_VMDQ                  (1ULL << 2)
125 #define I40E_FLAG_SRIOV                 (1ULL << 3)
126 #define I40E_FLAG_HEADER_SPLIT_DISABLED (1ULL << 4)
127 #define I40E_FLAG_HEADER_SPLIT_ENABLED  (1ULL << 5)
128 #define I40E_FLAG_FDIR                  (1ULL << 6)
129 #define I40E_FLAG_VXLAN                 (1ULL << 7)
130 #define I40E_FLAG_RSS_AQ_CAPABLE        (1ULL << 8)
131 #define I40E_FLAG_ALL (I40E_FLAG_RSS | \
132                        I40E_FLAG_DCB | \
133                        I40E_FLAG_VMDQ | \
134                        I40E_FLAG_SRIOV | \
135                        I40E_FLAG_HEADER_SPLIT_DISABLED | \
136                        I40E_FLAG_HEADER_SPLIT_ENABLED | \
137                        I40E_FLAG_FDIR | \
138                        I40E_FLAG_VXLAN | \
139                        I40E_FLAG_RSS_AQ_CAPABLE)
140
141 #define I40E_RSS_OFFLOAD_ALL ( \
142         ETH_RSS_FRAG_IPV4 | \
143         ETH_RSS_NONFRAG_IPV4_TCP | \
144         ETH_RSS_NONFRAG_IPV4_UDP | \
145         ETH_RSS_NONFRAG_IPV4_SCTP | \
146         ETH_RSS_NONFRAG_IPV4_OTHER | \
147         ETH_RSS_FRAG_IPV6 | \
148         ETH_RSS_NONFRAG_IPV6_TCP | \
149         ETH_RSS_NONFRAG_IPV6_UDP | \
150         ETH_RSS_NONFRAG_IPV6_SCTP | \
151         ETH_RSS_NONFRAG_IPV6_OTHER | \
152         ETH_RSS_L2_PAYLOAD)
153
154 /* All bits of RSS hash enable for X722*/
155 #define I40E_RSS_HENA_ALL_X722 ( \
156         (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP) | \
157         (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP) | \
158         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK) | \
159         (1ULL << I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP) | \
160         (1ULL << I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP) | \
161         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK) | \
162         I40E_RSS_HENA_ALL)
163
164 /* All bits of RSS hash enable */
165 #define I40E_RSS_HENA_ALL ( \
166         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \
167         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \
168         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \
169         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \
170         (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4) | \
171         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \
172         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \
173         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \
174         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \
175         (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6) | \
176         (1ULL << I40E_FILTER_PCTYPE_FCOE_OX) | \
177         (1ULL << I40E_FILTER_PCTYPE_FCOE_RX) | \
178         (1ULL << I40E_FILTER_PCTYPE_FCOE_OTHER) | \
179         (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
180
181 #define I40E_MISC_VEC_ID                RTE_INTR_VEC_ZERO_OFFSET
182 #define I40E_RX_VEC_START               RTE_INTR_VEC_RXTX_OFFSET
183
184 /* Default queue interrupt throttling time in microseconds */
185 #define I40E_ITR_INDEX_DEFAULT          0
186 #define I40E_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
187 #define I40E_QUEUE_ITR_INTERVAL_MAX     8160 /* 8160 us */
188
189 /* Special FW support this floating VEB feature */
190 #define FLOATING_VEB_SUPPORTED_FW_MAJ 5
191 #define FLOATING_VEB_SUPPORTED_FW_MIN 0
192
193 #define I40E_GL_SWT_L2TAGCTRL(_i)             (0x001C0A70 + ((_i) * 4))
194 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT 16
195 #define I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_MASK  \
196         I40E_MASK(0xFFFF, I40E_GL_SWT_L2TAGCTRL_ETHERTYPE_SHIFT)
197
198 struct i40e_adapter;
199
200 /**
201  * MAC filter structure
202  */
203 struct i40e_mac_filter_info {
204         enum rte_mac_filter_type filter_type;
205         struct ether_addr mac_addr;
206 };
207
208 TAILQ_HEAD(i40e_mac_filter_list, i40e_mac_filter);
209
210 /* MAC filter list structure */
211 struct i40e_mac_filter {
212         TAILQ_ENTRY(i40e_mac_filter) next;
213         struct i40e_mac_filter_info mac_info;
214 };
215
216 TAILQ_HEAD(i40e_vsi_list_head, i40e_vsi_list);
217
218 struct i40e_vsi;
219
220 /* VSI list structure */
221 struct i40e_vsi_list {
222         TAILQ_ENTRY(i40e_vsi_list) list;
223         struct i40e_vsi *vsi;
224 };
225
226 struct i40e_rx_queue;
227 struct i40e_tx_queue;
228
229 /* Bandwidth limit information */
230 struct i40e_bw_info {
231         uint16_t bw_limit;      /* BW Limit (0 = disabled) */
232         uint8_t  bw_max;        /* Max BW limit if enabled */
233
234         /* Relative credits within same TC with respect to other VSIs or Comps */
235         uint8_t  bw_ets_share_credits[I40E_MAX_TRAFFIC_CLASS];
236         /* Bandwidth limit per TC */
237         uint8_t  bw_ets_credits[I40E_MAX_TRAFFIC_CLASS];
238         /* Max bandwidth limit per TC */
239         uint8_t  bw_ets_max[I40E_MAX_TRAFFIC_CLASS];
240 };
241
242 /* Structure that defines a VEB */
243 struct i40e_veb {
244         struct i40e_vsi_list_head head;
245         struct i40e_vsi *associate_vsi; /* Associate VSI who owns the VEB */
246         struct i40e_pf *associate_pf; /* Associate PF who owns the VEB */
247         uint16_t seid; /* The seid of VEB itself */
248         uint16_t uplink_seid; /* The uplink seid of this VEB */
249         uint16_t stats_idx;
250         struct i40e_eth_stats stats;
251         uint8_t enabled_tc;   /* The traffic class enabled */
252         struct i40e_bw_info bw_info; /* VEB bandwidth information */
253 };
254
255 /* i40e MACVLAN filter structure */
256 struct i40e_macvlan_filter {
257         struct ether_addr macaddr;
258         enum rte_mac_filter_type filter_type;
259         uint16_t vlan_id;
260 };
261
262 /*
263  * Structure that defines a VSI, associated with a adapter.
264  */
265 struct i40e_vsi {
266         struct i40e_adapter *adapter; /* Backreference to associated adapter */
267         struct i40e_aqc_vsi_properties_data info; /* VSI properties */
268
269         struct i40e_eth_stats eth_stats_offset;
270         struct i40e_eth_stats eth_stats;
271         /*
272          * When drivers loaded, only a default main VSI exists. In case new VSI
273          * needs to add, HW needs to know the layout that VSIs are organized.
274          * Besides that, VSI isan element and can't switch packets, which needs
275          * to add new component VEB to perform switching. So, a new VSI needs
276          * to specify the the uplink VSI (Parent VSI) before created. The
277          * uplink VSI will check whether it had a VEB to switch packets. If no,
278          * it will try to create one. Then, uplink VSI will move the new VSI
279          * into its' sib_vsi_list to manage all the downlink VSI.
280          *  sib_vsi_list: the VSI list that shared the same uplink VSI.
281          *  parent_vsi  : the uplink VSI. It's NULL for main VSI.
282          *  veb         : the VEB associates with the VSI.
283          */
284         struct i40e_vsi_list sib_vsi_list; /* sibling vsi list */
285         struct i40e_vsi *parent_vsi;
286         struct i40e_veb *veb;    /* Associated veb, could be null */
287         struct i40e_veb *floating_veb; /* Associated floating veb */
288         bool offset_loaded;
289         enum i40e_vsi_type type; /* VSI types */
290         uint16_t vlan_num;       /* Total VLAN number */
291         uint16_t mac_num;        /* Total mac number */
292         uint32_t vfta[I40E_VFTA_SIZE];        /* VLAN bitmap */
293         struct i40e_mac_filter_list mac_list; /* macvlan filter list */
294         /* specific VSI-defined parameters, SRIOV stored the vf_id */
295         uint32_t user_param;
296         uint16_t seid;           /* The seid of VSI itself */
297         uint16_t uplink_seid;    /* The uplink seid of this VSI */
298         uint16_t nb_qps;         /* Number of queue pairs VSI can occupy */
299         uint16_t nb_used_qps;    /* Number of queue pairs VSI uses */
300         uint16_t max_macaddrs;   /* Maximum number of MAC addresses */
301         uint16_t base_queue;     /* The first queue index of this VSI */
302         /*
303          * The offset to visit VSI related register, assigned by HW when
304          * creating VSI
305          */
306         uint16_t vsi_id;
307         uint16_t msix_intr; /* The MSIX interrupt binds to VSI */
308         uint16_t nb_msix;   /* The max number of msix vector */
309         uint8_t enabled_tc; /* The traffic class enabled */
310         struct i40e_bw_info bw_info; /* VSI bandwidth information */
311 };
312
313 struct pool_entry {
314         LIST_ENTRY(pool_entry) next;
315         uint16_t base;
316         uint16_t len;
317 };
318
319 LIST_HEAD(res_list, pool_entry);
320
321 struct i40e_res_pool_info {
322         uint32_t base;              /* Resource start index */
323         uint32_t num_alloc;         /* Allocated resource number */
324         uint32_t num_free;          /* Total available resource number */
325         struct res_list alloc_list; /* Allocated resource list */
326         struct res_list free_list;  /* Available resource list */
327 };
328
329 enum I40E_VF_STATE {
330         I40E_VF_INACTIVE = 0,
331         I40E_VF_INRESET,
332         I40E_VF_ININIT,
333         I40E_VF_ACTIVE,
334 };
335
336 /*
337  * Structure to store private data for PF host.
338  */
339 struct i40e_pf_vf {
340         struct i40e_pf *pf;
341         struct i40e_vsi *vsi;
342         enum I40E_VF_STATE state; /* The number of queue pairs availiable */
343         uint16_t vf_idx; /* VF index in pf->vfs */
344         uint16_t lan_nb_qps; /* Actual queues allocated */
345         uint16_t reset_cnt; /* Total vf reset times */
346         struct ether_addr mac_addr;  /* Default MAC address */
347 };
348
349 /*
350  * Structure to store private data for flow control.
351  */
352 struct i40e_fc_conf {
353         uint16_t pause_time; /* Flow control pause timer */
354         /* FC high water 0-7 for pfc and 8 for lfc unit:kilobytes */
355         uint32_t high_water[I40E_MAX_TRAFFIC_CLASS + 1];
356         /* FC low water  0-7 for pfc and 8 for lfc unit:kilobytes */
357         uint32_t low_water[I40E_MAX_TRAFFIC_CLASS + 1];
358 };
359
360 /*
361  * Structure to store private data for VMDQ instance
362  */
363 struct i40e_vmdq_info {
364         struct i40e_pf *pf;
365         struct i40e_vsi *vsi;
366 };
367
368 /*
369  * Structure to store flex pit for flow diretor.
370  */
371 struct i40e_fdir_flex_pit {
372         uint8_t src_offset;    /* offset in words from the beginning of payload */
373         uint8_t size;          /* size in words */
374         uint8_t dst_offset;    /* offset in words of flexible payload */
375 };
376
377 struct i40e_fdir_flex_mask {
378         uint8_t word_mask;  /**< Bit i enables word i of flexible payload */
379         struct {
380                 uint8_t offset;
381                 uint16_t mask;
382         } bitmask[I40E_FDIR_BITMASK_NUM_WORD];
383 };
384
385 #define I40E_FILTER_PCTYPE_MAX 64
386 #define I40E_MAX_FDIR_FILTER_NUM (1024 * 8)
387
388 struct i40e_fdir_filter {
389         TAILQ_ENTRY(i40e_fdir_filter) rules;
390         struct rte_eth_fdir_filter fdir;
391 };
392
393 TAILQ_HEAD(i40e_fdir_filter_list, i40e_fdir_filter);
394 /*
395  *  A structure used to define fields of a FDIR related info.
396  */
397 struct i40e_fdir_info {
398         struct i40e_vsi *fdir_vsi;     /* pointer to fdir VSI structure */
399         uint16_t match_counter_index;  /* Statistic counter index used for fdir*/
400         struct i40e_tx_queue *txq;
401         struct i40e_rx_queue *rxq;
402         void *prg_pkt;                 /* memory for fdir program packet */
403         uint64_t dma_addr;             /* physic address of packet memory*/
404         /* input set bits for each pctype */
405         uint64_t input_set[I40E_FILTER_PCTYPE_MAX];
406         /*
407          * the rule how bytes stream is extracted as flexible payload
408          * for each payload layer, the setting can up to three elements
409          */
410         struct i40e_fdir_flex_pit flex_set[I40E_MAX_FLXPLD_LAYER * I40E_MAX_FLXPLD_FIED];
411         struct i40e_fdir_flex_mask flex_mask[I40E_FILTER_PCTYPE_MAX];
412
413         struct i40e_fdir_filter_list fdir_list;
414         struct i40e_fdir_filter **hash_map;
415         struct rte_hash *hash_table;
416 };
417
418 /* Ethertype filter number HW supports */
419 #define I40E_MAX_ETHERTYPE_FILTER_NUM 768
420
421 /* Ethertype filter struct */
422 struct i40e_ethertype_filter_input {
423         struct ether_addr mac_addr;   /* Mac address to match */
424         uint16_t ether_type;          /* Ether type to match */
425 };
426
427 struct i40e_ethertype_filter {
428         TAILQ_ENTRY(i40e_ethertype_filter) rules;
429         struct i40e_ethertype_filter_input input;
430         uint16_t flags;              /* Flags from RTE_ETHTYPE_FLAGS_* */
431         uint16_t queue;              /* Queue assigned to when match */
432 };
433
434 TAILQ_HEAD(i40e_ethertype_filter_list, i40e_ethertype_filter);
435
436 struct i40e_ethertype_rule {
437         struct i40e_ethertype_filter_list ethertype_list;
438         struct i40e_ethertype_filter  **hash_map;
439         struct rte_hash *hash_table;
440 };
441
442 /* Tunnel filter number HW supports */
443 #define I40E_MAX_TUNNEL_FILTER_NUM 400
444
445 /* Tunnel filter struct */
446 struct i40e_tunnel_filter_input {
447         uint8_t outer_mac[6];    /* Outer mac address to match */
448         uint8_t inner_mac[6];    /* Inner mac address to match */
449         uint16_t inner_vlan;     /* Inner vlan address to match */
450         uint16_t flags;          /* Filter type flag */
451         uint32_t tenant_id;      /* Tenant id to match */
452 };
453
454 struct i40e_tunnel_filter {
455         TAILQ_ENTRY(i40e_tunnel_filter) rules;
456         struct i40e_tunnel_filter_input input;
457         uint16_t queue; /* Queue assigned to when match */
458 };
459
460 TAILQ_HEAD(i40e_tunnel_filter_list, i40e_tunnel_filter);
461
462 struct i40e_tunnel_rule {
463         struct i40e_tunnel_filter_list tunnel_list;
464         struct i40e_tunnel_filter  **hash_map;
465         struct rte_hash *hash_table;
466 };
467
468 #define I40E_MIRROR_MAX_ENTRIES_PER_RULE   64
469 #define I40E_MAX_MIRROR_RULES           64
470 /*
471  * Mirror rule structure
472  */
473 struct i40e_mirror_rule {
474         TAILQ_ENTRY(i40e_mirror_rule) rules;
475         uint8_t rule_type;
476         uint16_t index;          /* the sw index of mirror rule */
477         uint16_t id;             /* the rule id assigned by firmware */
478         uint16_t dst_vsi_seid;   /* destination vsi for this mirror rule. */
479         uint16_t num_entries;
480         /* the info stores depend on the rule type.
481             If type is I40E_MIRROR_TYPE_VLAN, vlan ids are stored here.
482             If type is I40E_MIRROR_TYPE_VPORT_*, vsi's seid are stored.
483          */
484         uint16_t entries[I40E_MIRROR_MAX_ENTRIES_PER_RULE];
485 };
486
487 TAILQ_HEAD(i40e_mirror_rule_list, i40e_mirror_rule);
488
489 /*
490  * Structure to store private data specific for PF instance.
491  */
492 struct i40e_pf {
493         struct i40e_adapter *adapter; /* The adapter this PF associate to */
494         struct i40e_vsi *main_vsi; /* pointer to main VSI structure */
495         uint16_t mac_seid; /* The seid of the MAC of this PF */
496         uint16_t main_vsi_seid; /* The seid of the main VSI */
497         uint16_t max_num_vsi;
498         struct i40e_res_pool_info qp_pool;    /*Queue pair pool */
499         struct i40e_res_pool_info msix_pool;  /* MSIX interrupt pool */
500
501         struct i40e_hw_port_stats stats_offset;
502         struct i40e_hw_port_stats stats;
503         bool offset_loaded;
504
505         struct rte_eth_dev_data *dev_data; /* Pointer to the device data */
506         struct ether_addr dev_addr; /* PF device mac address */
507         uint64_t flags; /* PF feature flags */
508         /* All kinds of queue pair setting for different VSIs */
509         struct i40e_pf_vf *vfs;
510         uint16_t vf_num;
511         /* Each of below queue pairs should be power of 2 since it's the
512            precondition after TC configuration applied */
513         uint16_t lan_nb_qp_max;
514         uint16_t lan_nb_qps; /* The number of queue pairs of LAN */
515         uint16_t lan_qp_offset;
516         uint16_t vmdq_nb_qp_max;
517         uint16_t vmdq_nb_qps; /* The number of queue pairs of VMDq */
518         uint16_t vmdq_qp_offset;
519         uint16_t vf_nb_qp_max;
520         uint16_t vf_nb_qps; /* The number of queue pairs of VF */
521         uint16_t vf_qp_offset;
522         uint16_t fdir_nb_qps; /* The number of queue pairs of Flow Director */
523         uint16_t fdir_qp_offset;
524
525         uint16_t hash_lut_size; /* The size of hash lookup table */
526         /* input set bits for each pctype */
527         uint64_t hash_input_set[I40E_FILTER_PCTYPE_MAX];
528         /* store VXLAN UDP ports */
529         uint16_t vxlan_ports[I40E_MAX_PF_UDP_OFFLOAD_PORTS];
530         uint16_t vxlan_bitmap; /* Vxlan bit mask */
531
532         /* VMDQ related info */
533         uint16_t max_nb_vmdq_vsi; /* Max number of VMDQ VSIs supported */
534         uint16_t nb_cfg_vmdq_vsi; /* number of VMDQ VSIs configured */
535         struct i40e_vmdq_info *vmdq;
536
537         struct i40e_fdir_info fdir; /* flow director info */
538         struct i40e_ethertype_rule ethertype; /* Ethertype filter rule */
539         struct i40e_tunnel_rule tunnel; /* Tunnel filter rule */
540         struct i40e_fc_conf fc_conf; /* Flow control conf */
541         struct i40e_mirror_rule_list mirror_list;
542         uint16_t nb_mirror_rule;   /* The number of mirror rules */
543         bool floating_veb; /* The flag to use the floating VEB */
544         /* The floating enable flag for the specific VF */
545         bool floating_veb_list[I40E_MAX_VF];
546 };
547
548 enum pending_msg {
549         PFMSG_LINK_CHANGE = 0x1,
550         PFMSG_RESET_IMPENDING = 0x2,
551         PFMSG_DRIVER_CLOSE = 0x4,
552 };
553
554 struct i40e_vsi_vlan_pvid_info {
555         uint16_t on;            /* Enable or disable pvid */
556         union {
557                 uint16_t pvid;  /* Valid in case 'on' is set to set pvid */
558                 struct {
559                 /*  Valid in case 'on' is cleared. 'tagged' will reject tagged packets,
560                  *  while 'untagged' will reject untagged packets.
561                  */
562                         uint8_t tagged;
563                         uint8_t untagged;
564                 } reject;
565         } config;
566 };
567
568 struct i40e_vf_rx_queues {
569         uint64_t rx_dma_addr;
570         uint32_t rx_ring_len;
571         uint32_t buff_size;
572 };
573
574 struct i40e_vf_tx_queues {
575         uint64_t tx_dma_addr;
576         uint32_t tx_ring_len;
577 };
578
579 /*
580  * Structure to store private data specific for VF instance.
581  */
582 struct i40e_vf {
583         struct i40e_adapter *adapter; /* The adapter this VF associate to */
584         struct rte_eth_dev_data *dev_data; /* Pointer to the device data */
585         uint16_t num_queue_pairs;
586         uint16_t max_pkt_len; /* Maximum packet length */
587         bool promisc_unicast_enabled;
588         bool promisc_multicast_enabled;
589
590         uint32_t version_major; /* Major version number */
591         uint32_t version_minor; /* Minor version number */
592         uint16_t promisc_flags; /* Promiscuous setting */
593         uint32_t vlan[I40E_VFTA_SIZE]; /* VLAN bit map */
594
595         /* Event from pf */
596         bool dev_closed;
597         bool link_up;
598         enum i40e_aq_link_speed link_speed;
599         bool vf_reset;
600         volatile uint32_t pend_cmd; /* pending command not finished yet */
601         int32_t cmd_retval; /* return value of the cmd response from PF */
602         u16 pend_msg; /* flags indicates events from pf not handled yet */
603         uint8_t *aq_resp; /* buffer to store the adminq response from PF */
604
605         /* VSI info */
606         struct i40e_virtchnl_vf_resource *vf_res; /* All VSIs */
607         struct i40e_virtchnl_vsi_resource *vsi_res; /* LAN VSI */
608         struct i40e_vsi vsi;
609         uint64_t flags;
610 };
611
612 /*
613  * Structure to store private data for each PF/VF instance.
614  */
615 struct i40e_adapter {
616         /* Common for both PF and VF */
617         struct i40e_hw hw;
618         struct rte_eth_dev *eth_dev;
619
620         /* Specific for PF or VF */
621         union {
622                 struct i40e_pf pf;
623                 struct i40e_vf vf;
624         };
625
626         /* For vector PMD */
627         bool rx_bulk_alloc_allowed;
628         bool rx_vec_allowed;
629         bool tx_simple_allowed;
630         bool tx_vec_allowed;
631
632         /* For PTP */
633         struct rte_timecounter systime_tc;
634         struct rte_timecounter rx_tstamp_tc;
635         struct rte_timecounter tx_tstamp_tc;
636 };
637
638 extern const struct rte_flow_ops i40e_flow_ops;
639
640 union i40e_filter_t {
641         struct rte_eth_ethertype_filter ethertype_filter;
642         struct rte_eth_fdir_filter fdir_filter;
643         struct rte_eth_tunnel_filter_conf tunnel_filter;
644 };
645
646 typedef int (*parse_filter_t)(struct rte_eth_dev *dev,
647                               const struct rte_flow_attr *attr,
648                               const struct rte_flow_item pattern[],
649                               const struct rte_flow_action actions[],
650                               struct rte_flow_error *error,
651                               union i40e_filter_t *filter);
652 struct i40e_valid_pattern {
653         enum rte_flow_item_type *items;
654         parse_filter_t parse_filter;
655 };
656
657 int i40e_dev_switch_queues(struct i40e_pf *pf, bool on);
658 int i40e_vsi_release(struct i40e_vsi *vsi);
659 struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf,
660                                 enum i40e_vsi_type type,
661                                 struct i40e_vsi *uplink_vsi,
662                                 uint16_t user_param);
663 int i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on);
664 int i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on);
665 int i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan);
666 int i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan);
667 int i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *filter);
668 int i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr);
669 void i40e_update_vsi_stats(struct i40e_vsi *vsi);
670 void i40e_pf_disable_irq0(struct i40e_hw *hw);
671 void i40e_pf_enable_irq0(struct i40e_hw *hw);
672 int i40e_dev_link_update(struct rte_eth_dev *dev,
673                          __rte_unused int wait_to_complete);
674 void i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi);
675 void i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi);
676 int i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
677                            struct i40e_vsi_vlan_pvid_info *info);
678 int i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on);
679 int i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on);
680 uint64_t i40e_config_hena(uint64_t flags, enum i40e_mac_type type);
681 uint64_t i40e_parse_hena(uint64_t flags);
682 enum i40e_status_code i40e_fdir_setup_tx_resources(struct i40e_pf *pf);
683 enum i40e_status_code i40e_fdir_setup_rx_resources(struct i40e_pf *pf);
684 int i40e_fdir_setup(struct i40e_pf *pf);
685 const struct rte_memzone *i40e_memzone_reserve(const char *name,
686                                         uint32_t len,
687                                         int socket_id);
688 int i40e_fdir_configure(struct rte_eth_dev *dev);
689 void i40e_fdir_teardown(struct i40e_pf *pf);
690 enum i40e_filter_pctype i40e_flowtype_to_pctype(uint16_t flow_type);
691 uint16_t i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype);
692 int i40e_fdir_ctrl_func(struct rte_eth_dev *dev,
693                           enum rte_filter_op filter_op,
694                           void *arg);
695 int i40e_select_filter_input_set(struct i40e_hw *hw,
696                                  struct rte_eth_input_set_conf *conf,
697                                  enum rte_filter_type filter);
698 void i40e_fdir_filter_restore(struct i40e_pf *pf);
699 int i40e_hash_filter_inset_select(struct i40e_hw *hw,
700                              struct rte_eth_input_set_conf *conf);
701 int i40e_fdir_filter_inset_select(struct i40e_pf *pf,
702                              struct rte_eth_input_set_conf *conf);
703 int i40e_pf_host_send_msg_to_vf(struct i40e_pf_vf *vf, uint32_t opcode,
704                                 uint32_t retval, uint8_t *msg,
705                                 uint16_t msglen);
706 void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
707         struct rte_eth_rxq_info *qinfo);
708 void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
709         struct rte_eth_txq_info *qinfo);
710 struct i40e_ethertype_filter *
711 i40e_sw_ethertype_filter_lookup(struct i40e_ethertype_rule *ethertype_rule,
712                         const struct i40e_ethertype_filter_input *input);
713 int i40e_sw_ethertype_filter_del(struct i40e_pf *pf,
714                                  struct i40e_ethertype_filter_input *input);
715 int i40e_sw_fdir_filter_del(struct i40e_pf *pf,
716                             struct rte_eth_fdir_input *input);
717 struct i40e_tunnel_filter *
718 i40e_sw_tunnel_filter_lookup(struct i40e_tunnel_rule *tunnel_rule,
719                              const struct i40e_tunnel_filter_input *input);
720 int i40e_sw_tunnel_filter_del(struct i40e_pf *pf,
721                               struct i40e_tunnel_filter_input *input);
722
723 #define I40E_DEV_TO_PCI(eth_dev) \
724         RTE_DEV_TO_PCI((eth_dev)->device)
725
726 /* I40E_DEV_PRIVATE_TO */
727 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
728         (&((struct i40e_adapter *)adapter)->pf)
729 #define I40E_DEV_PRIVATE_TO_HW(adapter) \
730         (&((struct i40e_adapter *)adapter)->hw)
731 #define I40E_DEV_PRIVATE_TO_ADAPTER(adapter) \
732         ((struct i40e_adapter *)adapter)
733
734 /* I40EVF_DEV_PRIVATE_TO */
735 #define I40EVF_DEV_PRIVATE_TO_VF(adapter) \
736         (&((struct i40e_adapter *)adapter)->vf)
737
738 static inline struct i40e_vsi *
739 i40e_get_vsi_from_adapter(struct i40e_adapter *adapter)
740 {
741         struct i40e_hw *hw;
742
743         if (!adapter)
744                 return NULL;
745
746         hw = I40E_DEV_PRIVATE_TO_HW(adapter);
747         if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
748                 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(adapter);
749                 return &vf->vsi;
750         } else {
751                 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(adapter);
752                 return pf->main_vsi;
753         }
754 }
755 #define I40E_DEV_PRIVATE_TO_MAIN_VSI(adapter) \
756         i40e_get_vsi_from_adapter((struct i40e_adapter *)adapter)
757
758 /* I40E_VSI_TO */
759 #define I40E_VSI_TO_HW(vsi) \
760         (&(((struct i40e_vsi *)vsi)->adapter->hw))
761 #define I40E_VSI_TO_PF(vsi) \
762         (&(((struct i40e_vsi *)vsi)->adapter->pf))
763 #define I40E_VSI_TO_VF(vsi) \
764         (&(((struct i40e_vsi *)vsi)->adapter->vf))
765 #define I40E_VSI_TO_DEV_DATA(vsi) \
766         (((struct i40e_vsi *)vsi)->adapter->pf.dev_data)
767 #define I40E_VSI_TO_ETH_DEV(vsi) \
768         (((struct i40e_vsi *)vsi)->adapter->eth_dev)
769
770 /* I40E_PF_TO */
771 #define I40E_PF_TO_HW(pf) \
772         (&(((struct i40e_pf *)pf)->adapter->hw))
773 #define I40E_PF_TO_ADAPTER(pf) \
774         ((struct i40e_adapter *)pf->adapter)
775
776 /* I40E_VF_TO */
777 #define I40E_VF_TO_HW(vf) \
778         (&(((struct i40e_vf *)vf)->adapter->hw))
779
780 static inline void
781 i40e_init_adminq_parameter(struct i40e_hw *hw)
782 {
783         hw->aq.num_arq_entries = I40E_AQ_LEN;
784         hw->aq.num_asq_entries = I40E_AQ_LEN;
785         hw->aq.arq_buf_size = I40E_AQ_BUF_SZ;
786         hw->aq.asq_buf_size = I40E_AQ_BUF_SZ;
787 }
788
789 static inline int
790 i40e_align_floor(int n)
791 {
792         if (n == 0)
793                 return 0;
794         return 1 << (sizeof(n) * CHAR_BIT - 1 - __builtin_clz(n));
795 }
796
797 static inline uint16_t
798 i40e_calc_itr_interval(int16_t interval)
799 {
800         if (interval < 0 || interval > I40E_QUEUE_ITR_INTERVAL_MAX)
801                 interval = I40E_QUEUE_ITR_INTERVAL_DEFAULT;
802
803         /* Convert to hardware count, as writing each 1 represents 2 us */
804         return interval / 2;
805 }
806
807 #define I40E_VALID_FLOW(flow_type) \
808         ((flow_type) == RTE_ETH_FLOW_FRAG_IPV4 || \
809         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_TCP || \
810         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_UDP || \
811         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_SCTP || \
812         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_OTHER || \
813         (flow_type) == RTE_ETH_FLOW_FRAG_IPV6 || \
814         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_TCP || \
815         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_UDP || \
816         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_SCTP || \
817         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_OTHER || \
818         (flow_type) == RTE_ETH_FLOW_L2_PAYLOAD)
819
820 #define I40E_VALID_PCTYPE_X722(pctype) \
821         ((pctype) == I40E_FILTER_PCTYPE_FRAG_IPV4 || \
822         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_TCP || \
823         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_TCP_SYN_NO_ACK || \
824         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_UDP || \
825         (pctype) == I40E_FILTER_PCTYPE_NONF_UNICAST_IPV4_UDP || \
826         (pctype) == I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV4_UDP || \
827         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP || \
828         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER || \
829         (pctype) == I40E_FILTER_PCTYPE_FRAG_IPV6 || \
830         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_UDP || \
831         (pctype) == I40E_FILTER_PCTYPE_NONF_UNICAST_IPV6_UDP || \
832         (pctype) == I40E_FILTER_PCTYPE_NONF_MULTICAST_IPV6_UDP || \
833         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_TCP || \
834         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_TCP_SYN_NO_ACK || \
835         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP || \
836         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER || \
837         (pctype) == I40E_FILTER_PCTYPE_L2_PAYLOAD)
838
839 #define I40E_VALID_PCTYPE(pctype) \
840         ((pctype) == I40E_FILTER_PCTYPE_FRAG_IPV4 || \
841         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_TCP || \
842         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_UDP || \
843         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP || \
844         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER || \
845         (pctype) == I40E_FILTER_PCTYPE_FRAG_IPV6 || \
846         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_UDP || \
847         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_TCP || \
848         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP || \
849         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER || \
850         (pctype) == I40E_FILTER_PCTYPE_L2_PAYLOAD)
851
852 #define I40E_PHY_TYPE_SUPPORT_40G(phy_type) \
853         (((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_KR4) || \
854         ((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_CR4_CU) || \
855         ((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_AOC) || \
856         ((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_CR4) || \
857         ((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_SR4) || \
858         ((phy_type) & I40E_CAP_PHY_TYPE_40GBASE_LR4))
859
860 #define I40E_PHY_TYPE_SUPPORT_25G(phy_type) \
861         (((phy_type) & I40E_CAP_PHY_TYPE_25GBASE_KR) || \
862         ((phy_type) & I40E_CAP_PHY_TYPE_25GBASE_CR) || \
863         ((phy_type) & I40E_CAP_PHY_TYPE_25GBASE_SR) || \
864         ((phy_type) & I40E_CAP_PHY_TYPE_25GBASE_LR))
865
866 #endif /* _I40E_ETHDEV_H_ */