Imported Upstream version 16.07-rc1
[deb_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
41 #define I40E_VLAN_TAG_SIZE        4
42
43 #define I40E_AQ_LEN               32
44 #define I40E_AQ_BUF_SZ            4096
45 /* Number of queues per TC should be one of 1, 2, 4, 8, 16, 32, 64 */
46 #define I40E_MAX_Q_PER_TC         64
47 #define I40E_NUM_DESC_DEFAULT     512
48 #define I40E_NUM_DESC_ALIGN       32
49 #define I40E_BUF_SIZE_MIN         1024
50 #define I40E_FRAME_SIZE_MAX       9728
51 #define I40E_QUEUE_BASE_ADDR_UNIT 128
52 /* number of VSIs and queue default setting */
53 #define I40E_MAX_QP_NUM_PER_VF    16
54 #define I40E_DEFAULT_QP_NUM_FDIR  1
55 #define I40E_UINT32_BIT_SIZE      (CHAR_BIT * sizeof(uint32_t))
56 #define I40E_VFTA_SIZE            (4096 / I40E_UINT32_BIT_SIZE)
57 /* Maximun number of MAC addresses */
58 #define I40E_NUM_MACADDR_MAX       64
59 /* Maximum number of VFs */
60 #define I40E_MAX_VF               128
61
62 /*
63  * vlan_id is a 12 bit number.
64  * The VFTA array is actually a 4096 bit array, 128 of 32bit elements.
65  * 2^5 = 32. The val of lower 5 bits specifies the bit in the 32bit element.
66  * The higher 7 bit val specifies VFTA array index.
67  */
68 #define I40E_VFTA_BIT(vlan_id)    (1 << ((vlan_id) & 0x1F))
69 #define I40E_VFTA_IDX(vlan_id)    ((vlan_id) >> 5)
70
71 /* Default TC traffic in case DCB is not enabled */
72 #define I40E_DEFAULT_TCMAP        0x1
73 #define I40E_FDIR_QUEUE_ID        0
74
75 /* Always assign pool 0 to main VSI, VMDQ will start from 1 */
76 #define I40E_VMDQ_POOL_BASE       1
77
78 #define I40E_DEFAULT_RX_FREE_THRESH  32
79 #define I40E_DEFAULT_RX_PTHRESH      8
80 #define I40E_DEFAULT_RX_HTHRESH      8
81 #define I40E_DEFAULT_RX_WTHRESH      0
82
83 #define I40E_DEFAULT_TX_FREE_THRESH  32
84 #define I40E_DEFAULT_TX_PTHRESH      32
85 #define I40E_DEFAULT_TX_HTHRESH      0
86 #define I40E_DEFAULT_TX_WTHRESH      0
87 #define I40E_DEFAULT_TX_RSBIT_THRESH 32
88
89 /* Bit shift and mask */
90 #define I40E_4_BIT_WIDTH  (CHAR_BIT / 2)
91 #define I40E_4_BIT_MASK   RTE_LEN2MASK(I40E_4_BIT_WIDTH, uint8_t)
92 #define I40E_8_BIT_WIDTH  CHAR_BIT
93 #define I40E_8_BIT_MASK   UINT8_MAX
94 #define I40E_16_BIT_WIDTH (CHAR_BIT * 2)
95 #define I40E_16_BIT_MASK  UINT16_MAX
96 #define I40E_32_BIT_WIDTH (CHAR_BIT * 4)
97 #define I40E_32_BIT_MASK  UINT32_MAX
98 #define I40E_48_BIT_WIDTH (CHAR_BIT * 6)
99 #define I40E_48_BIT_MASK  RTE_LEN2MASK(I40E_48_BIT_WIDTH, uint64_t)
100
101 /* Linux PF host with virtchnl version 1.1 */
102 #define PF_IS_V11(vf) \
103         (((vf)->version_major == I40E_VIRTCHNL_VERSION_MAJOR) && \
104         ((vf)->version_minor == 1))
105
106 /* index flex payload per layer */
107 enum i40e_flxpld_layer_idx {
108         I40E_FLXPLD_L2_IDX    = 0,
109         I40E_FLXPLD_L3_IDX    = 1,
110         I40E_FLXPLD_L4_IDX    = 2,
111         I40E_MAX_FLXPLD_LAYER = 3,
112 };
113 #define I40E_MAX_FLXPLD_FIED        3  /* max number of flex payload fields */
114 #define I40E_FDIR_BITMASK_NUM_WORD  2  /* max number of bitmask words */
115 #define I40E_FDIR_MAX_FLEXWORD_NUM  8  /* max number of flexpayload words */
116 #define I40E_FDIR_MAX_FLEX_LEN      16 /* len in bytes of flex payload */
117 #define I40E_INSET_MASK_NUM_REG     2  /* number of input set mask registers */
118
119 /* i40e flags */
120 #define I40E_FLAG_RSS                   (1ULL << 0)
121 #define I40E_FLAG_DCB                   (1ULL << 1)
122 #define I40E_FLAG_VMDQ                  (1ULL << 2)
123 #define I40E_FLAG_SRIOV                 (1ULL << 3)
124 #define I40E_FLAG_HEADER_SPLIT_DISABLED (1ULL << 4)
125 #define I40E_FLAG_HEADER_SPLIT_ENABLED  (1ULL << 5)
126 #define I40E_FLAG_FDIR                  (1ULL << 6)
127 #define I40E_FLAG_VXLAN                 (1ULL << 7)
128 #define I40E_FLAG_RSS_AQ_CAPABLE        (1ULL << 8)
129 #define I40E_FLAG_ALL (I40E_FLAG_RSS | \
130                        I40E_FLAG_DCB | \
131                        I40E_FLAG_VMDQ | \
132                        I40E_FLAG_SRIOV | \
133                        I40E_FLAG_HEADER_SPLIT_DISABLED | \
134                        I40E_FLAG_HEADER_SPLIT_ENABLED | \
135                        I40E_FLAG_FDIR | \
136                        I40E_FLAG_VXLAN | \
137                        I40E_FLAG_RSS_AQ_CAPABLE)
138
139 #define I40E_RSS_OFFLOAD_ALL ( \
140         ETH_RSS_FRAG_IPV4 | \
141         ETH_RSS_NONFRAG_IPV4_TCP | \
142         ETH_RSS_NONFRAG_IPV4_UDP | \
143         ETH_RSS_NONFRAG_IPV4_SCTP | \
144         ETH_RSS_NONFRAG_IPV4_OTHER | \
145         ETH_RSS_FRAG_IPV6 | \
146         ETH_RSS_NONFRAG_IPV6_TCP | \
147         ETH_RSS_NONFRAG_IPV6_UDP | \
148         ETH_RSS_NONFRAG_IPV6_SCTP | \
149         ETH_RSS_NONFRAG_IPV6_OTHER | \
150         ETH_RSS_L2_PAYLOAD)
151
152 /* All bits of RSS hash enable */
153 #define I40E_RSS_HENA_ALL ( \
154         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \
155         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \
156         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \
157         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \
158         (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4) | \
159         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \
160         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \
161         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \
162         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \
163         (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6) | \
164         (1ULL << I40E_FILTER_PCTYPE_FCOE_OX) | \
165         (1ULL << I40E_FILTER_PCTYPE_FCOE_RX) | \
166         (1ULL << I40E_FILTER_PCTYPE_FCOE_OTHER) | \
167         (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
168
169 #define I40E_MISC_VEC_ID                RTE_INTR_VEC_ZERO_OFFSET
170 #define I40E_RX_VEC_START               RTE_INTR_VEC_RXTX_OFFSET
171
172 /* Default queue interrupt throttling time in microseconds */
173 #define I40E_ITR_INDEX_DEFAULT          0
174 #define I40E_QUEUE_ITR_INTERVAL_DEFAULT 32 /* 32 us */
175 #define I40E_QUEUE_ITR_INTERVAL_MAX     8160 /* 8160 us */
176
177 /* Special FW support this floating VEB feature */
178 #define FLOATING_VEB_SUPPORTED_FW_MAJ 5
179 #define FLOATING_VEB_SUPPORTED_FW_MIN 0
180
181 struct i40e_adapter;
182
183 /**
184  * MAC filter structure
185  */
186 struct i40e_mac_filter_info {
187         enum rte_mac_filter_type filter_type;
188         struct ether_addr mac_addr;
189 };
190
191 TAILQ_HEAD(i40e_mac_filter_list, i40e_mac_filter);
192
193 /* MAC filter list structure */
194 struct i40e_mac_filter {
195         TAILQ_ENTRY(i40e_mac_filter) next;
196         struct i40e_mac_filter_info mac_info;
197 };
198
199 TAILQ_HEAD(i40e_vsi_list_head, i40e_vsi_list);
200
201 struct i40e_vsi;
202
203 /* VSI list structure */
204 struct i40e_vsi_list {
205         TAILQ_ENTRY(i40e_vsi_list) list;
206         struct i40e_vsi *vsi;
207 };
208
209 struct i40e_rx_queue;
210 struct i40e_tx_queue;
211
212 /* Bandwidth limit information */
213 struct i40e_bw_info {
214         uint16_t bw_limit;      /* BW Limit (0 = disabled) */
215         uint8_t  bw_max;        /* Max BW limit if enabled */
216
217         /* Relative credits within same TC with respect to other VSIs or Comps */
218         uint8_t  bw_ets_share_credits[I40E_MAX_TRAFFIC_CLASS];
219         /* Bandwidth limit per TC */
220         uint8_t  bw_ets_credits[I40E_MAX_TRAFFIC_CLASS];
221         /* Max bandwidth limit per TC */
222         uint8_t  bw_ets_max[I40E_MAX_TRAFFIC_CLASS];
223 };
224
225 /* Structure that defines a VEB */
226 struct i40e_veb {
227         struct i40e_vsi_list_head head;
228         struct i40e_vsi *associate_vsi; /* Associate VSI who owns the VEB */
229         struct i40e_pf *associate_pf; /* Associate PF who owns the VEB */
230         uint16_t seid; /* The seid of VEB itself */
231         uint16_t uplink_seid; /* The uplink seid of this VEB */
232         uint16_t stats_idx;
233         struct i40e_eth_stats stats;
234         uint8_t enabled_tc;   /* The traffic class enabled */
235         struct i40e_bw_info bw_info; /* VEB bandwidth information */
236 };
237
238 /* i40e MACVLAN filter structure */
239 struct i40e_macvlan_filter {
240         struct ether_addr macaddr;
241         enum rte_mac_filter_type filter_type;
242         uint16_t vlan_id;
243 };
244
245 /*
246  * Structure that defines a VSI, associated with a adapter.
247  */
248 struct i40e_vsi {
249         struct i40e_adapter *adapter; /* Backreference to associated adapter */
250         struct i40e_aqc_vsi_properties_data info; /* VSI properties */
251
252         struct i40e_eth_stats eth_stats_offset;
253         struct i40e_eth_stats eth_stats;
254         /*
255          * When drivers loaded, only a default main VSI exists. In case new VSI
256          * needs to add, HW needs to know the layout that VSIs are organized.
257          * Besides that, VSI isan element and can't switch packets, which needs
258          * to add new component VEB to perform switching. So, a new VSI needs
259          * to specify the the uplink VSI (Parent VSI) before created. The
260          * uplink VSI will check whether it had a VEB to switch packets. If no,
261          * it will try to create one. Then, uplink VSI will move the new VSI
262          * into its' sib_vsi_list to manage all the downlink VSI.
263          *  sib_vsi_list: the VSI list that shared the same uplink VSI.
264          *  parent_vsi  : the uplink VSI. It's NULL for main VSI.
265          *  veb         : the VEB associates with the VSI.
266          */
267         struct i40e_vsi_list sib_vsi_list; /* sibling vsi list */
268         struct i40e_vsi *parent_vsi;
269         struct i40e_veb *veb;    /* Associated veb, could be null */
270         struct i40e_veb *floating_veb; /* Associated floating veb */
271         bool offset_loaded;
272         enum i40e_vsi_type type; /* VSI types */
273         uint16_t vlan_num;       /* Total VLAN number */
274         uint16_t mac_num;        /* Total mac number */
275         uint32_t vfta[I40E_VFTA_SIZE];        /* VLAN bitmap */
276         struct i40e_mac_filter_list mac_list; /* macvlan filter list */
277         /* specific VSI-defined parameters, SRIOV stored the vf_id */
278         uint32_t user_param;
279         uint16_t seid;           /* The seid of VSI itself */
280         uint16_t uplink_seid;    /* The uplink seid of this VSI */
281         uint16_t nb_qps;         /* Number of queue pairs VSI can occupy */
282         uint16_t nb_used_qps;    /* Number of queue pairs VSI uses */
283         uint16_t max_macaddrs;   /* Maximum number of MAC addresses */
284         uint16_t base_queue;     /* The first queue index of this VSI */
285         /*
286          * The offset to visit VSI related register, assigned by HW when
287          * creating VSI
288          */
289         uint16_t vsi_id;
290         uint16_t msix_intr; /* The MSIX interrupt binds to VSI */
291         uint16_t nb_msix;   /* The max number of msix vector */
292         uint8_t enabled_tc; /* The traffic class enabled */
293         struct i40e_bw_info bw_info; /* VSI bandwidth information */
294 };
295
296 struct pool_entry {
297         LIST_ENTRY(pool_entry) next;
298         uint16_t base;
299         uint16_t len;
300 };
301
302 LIST_HEAD(res_list, pool_entry);
303
304 struct i40e_res_pool_info {
305         uint32_t base;              /* Resource start index */
306         uint32_t num_alloc;         /* Allocated resource number */
307         uint32_t num_free;          /* Total available resource number */
308         struct res_list alloc_list; /* Allocated resource list */
309         struct res_list free_list;  /* Available resource list */
310 };
311
312 enum I40E_VF_STATE {
313         I40E_VF_INACTIVE = 0,
314         I40E_VF_INRESET,
315         I40E_VF_ININIT,
316         I40E_VF_ACTIVE,
317 };
318
319 /*
320  * Structure to store private data for PF host.
321  */
322 struct i40e_pf_vf {
323         struct i40e_pf *pf;
324         struct i40e_vsi *vsi;
325         enum I40E_VF_STATE state; /* The number of queue pairs availiable */
326         uint16_t vf_idx; /* VF index in pf->vfs */
327         uint16_t lan_nb_qps; /* Actual queues allocated */
328         uint16_t reset_cnt; /* Total vf reset times */
329         struct ether_addr mac_addr;  /* Default MAC address */
330 };
331
332 /*
333  * Structure to store private data for flow control.
334  */
335 struct i40e_fc_conf {
336         uint16_t pause_time; /* Flow control pause timer */
337         /* FC high water 0-7 for pfc and 8 for lfc unit:kilobytes */
338         uint32_t high_water[I40E_MAX_TRAFFIC_CLASS + 1];
339         /* FC low water  0-7 for pfc and 8 for lfc unit:kilobytes */
340         uint32_t low_water[I40E_MAX_TRAFFIC_CLASS + 1];
341 };
342
343 /*
344  * Structure to store private data for VMDQ instance
345  */
346 struct i40e_vmdq_info {
347         struct i40e_pf *pf;
348         struct i40e_vsi *vsi;
349 };
350
351 /*
352  * Structure to store flex pit for flow diretor.
353  */
354 struct i40e_fdir_flex_pit {
355         uint8_t src_offset;    /* offset in words from the beginning of payload */
356         uint8_t size;          /* size in words */
357         uint8_t dst_offset;    /* offset in words of flexible payload */
358 };
359
360 struct i40e_fdir_flex_mask {
361         uint8_t word_mask;  /**< Bit i enables word i of flexible payload */
362         struct {
363                 uint8_t offset;
364                 uint16_t mask;
365         } bitmask[I40E_FDIR_BITMASK_NUM_WORD];
366 };
367
368 #define I40E_FILTER_PCTYPE_MAX 64
369 /*
370  *  A structure used to define fields of a FDIR related info.
371  */
372 struct i40e_fdir_info {
373         struct i40e_vsi *fdir_vsi;     /* pointer to fdir VSI structure */
374         uint16_t match_counter_index;  /* Statistic counter index used for fdir*/
375         struct i40e_tx_queue *txq;
376         struct i40e_rx_queue *rxq;
377         void *prg_pkt;                 /* memory for fdir program packet */
378         uint64_t dma_addr;             /* physic address of packet memory*/
379         /* input set bits for each pctype */
380         uint64_t input_set[I40E_FILTER_PCTYPE_MAX];
381         /*
382          * the rule how bytes stream is extracted as flexible payload
383          * for each payload layer, the setting can up to three elements
384          */
385         struct i40e_fdir_flex_pit flex_set[I40E_MAX_FLXPLD_LAYER * I40E_MAX_FLXPLD_FIED];
386         struct i40e_fdir_flex_mask flex_mask[I40E_FILTER_PCTYPE_MAX];
387 };
388
389 #define I40E_MIRROR_MAX_ENTRIES_PER_RULE   64
390 #define I40E_MAX_MIRROR_RULES           64
391 /*
392  * Mirror rule structure
393  */
394 struct i40e_mirror_rule {
395         TAILQ_ENTRY(i40e_mirror_rule) rules;
396         uint8_t rule_type;
397         uint16_t index;          /* the sw index of mirror rule */
398         uint16_t id;             /* the rule id assigned by firmware */
399         uint16_t dst_vsi_seid;   /* destination vsi for this mirror rule. */
400         uint16_t num_entries;
401         /* the info stores depend on the rule type.
402             If type is I40E_MIRROR_TYPE_VLAN, vlan ids are stored here.
403             If type is I40E_MIRROR_TYPE_VPORT_*, vsi's seid are stored.
404          */
405         uint16_t entries[I40E_MIRROR_MAX_ENTRIES_PER_RULE];
406 };
407
408 TAILQ_HEAD(i40e_mirror_rule_list, i40e_mirror_rule);
409
410 /*
411  * Structure to store private data specific for PF instance.
412  */
413 struct i40e_pf {
414         struct i40e_adapter *adapter; /* The adapter this PF associate to */
415         struct i40e_vsi *main_vsi; /* pointer to main VSI structure */
416         uint16_t mac_seid; /* The seid of the MAC of this PF */
417         uint16_t main_vsi_seid; /* The seid of the main VSI */
418         uint16_t max_num_vsi;
419         struct i40e_res_pool_info qp_pool;    /*Queue pair pool */
420         struct i40e_res_pool_info msix_pool;  /* MSIX interrupt pool */
421
422         struct i40e_hw_port_stats stats_offset;
423         struct i40e_hw_port_stats stats;
424         bool offset_loaded;
425
426         struct rte_eth_dev_data *dev_data; /* Pointer to the device data */
427         struct ether_addr dev_addr; /* PF device mac address */
428         uint64_t flags; /* PF feature flags */
429         /* All kinds of queue pair setting for different VSIs */
430         struct i40e_pf_vf *vfs;
431         uint16_t vf_num;
432         /* Each of below queue pairs should be power of 2 since it's the
433            precondition after TC configuration applied */
434         uint16_t lan_nb_qp_max;
435         uint16_t lan_nb_qps; /* The number of queue pairs of LAN */
436         uint16_t lan_qp_offset;
437         uint16_t vmdq_nb_qp_max;
438         uint16_t vmdq_nb_qps; /* The number of queue pairs of VMDq */
439         uint16_t vmdq_qp_offset;
440         uint16_t vf_nb_qp_max;
441         uint16_t vf_nb_qps; /* The number of queue pairs of VF */
442         uint16_t vf_qp_offset;
443         uint16_t fdir_nb_qps; /* The number of queue pairs of Flow Director */
444         uint16_t fdir_qp_offset;
445
446         uint16_t hash_lut_size; /* The size of hash lookup table */
447         /* input set bits for each pctype */
448         uint64_t hash_input_set[I40E_FILTER_PCTYPE_MAX];
449         /* store VXLAN UDP ports */
450         uint16_t vxlan_ports[I40E_MAX_PF_UDP_OFFLOAD_PORTS];
451         uint16_t vxlan_bitmap; /* Vxlan bit mask */
452
453         /* VMDQ related info */
454         uint16_t max_nb_vmdq_vsi; /* Max number of VMDQ VSIs supported */
455         uint16_t nb_cfg_vmdq_vsi; /* number of VMDQ VSIs configured */
456         struct i40e_vmdq_info *vmdq;
457
458         struct i40e_fdir_info fdir; /* flow director info */
459         struct i40e_fc_conf fc_conf; /* Flow control conf */
460         struct i40e_mirror_rule_list mirror_list;
461         uint16_t nb_mirror_rule;   /* The number of mirror rules */
462         bool floating_veb; /* The flag to use the floating VEB */
463         /* The floating enable flag for the specific VF */
464         bool floating_veb_list[I40E_MAX_VF];
465 };
466
467 enum pending_msg {
468         PFMSG_LINK_CHANGE = 0x1,
469         PFMSG_RESET_IMPENDING = 0x2,
470         PFMSG_DRIVER_CLOSE = 0x4,
471 };
472
473 struct i40e_vsi_vlan_pvid_info {
474         uint16_t on;            /* Enable or disable pvid */
475         union {
476                 uint16_t pvid;  /* Valid in case 'on' is set to set pvid */
477                 struct {
478                 /*  Valid in case 'on' is cleared. 'tagged' will reject tagged packets,
479                  *  while 'untagged' will reject untagged packets.
480                  */
481                         uint8_t tagged;
482                         uint8_t untagged;
483                 } reject;
484         } config;
485 };
486
487 struct i40e_vf_rx_queues {
488         uint64_t rx_dma_addr;
489         uint32_t rx_ring_len;
490         uint32_t buff_size;
491 };
492
493 struct i40e_vf_tx_queues {
494         uint64_t tx_dma_addr;
495         uint32_t tx_ring_len;
496 };
497
498 /*
499  * Structure to store private data specific for VF instance.
500  */
501 struct i40e_vf {
502         struct i40e_adapter *adapter; /* The adapter this VF associate to */
503         struct rte_eth_dev_data *dev_data; /* Pointer to the device data */
504         uint16_t num_queue_pairs;
505         uint16_t max_pkt_len; /* Maximum packet length */
506         bool promisc_unicast_enabled;
507         bool promisc_multicast_enabled;
508
509         uint32_t version_major; /* Major version number */
510         uint32_t version_minor; /* Minor version number */
511         uint16_t promisc_flags; /* Promiscuous setting */
512         uint32_t vlan[I40E_VFTA_SIZE]; /* VLAN bit map */
513
514         /* Event from pf */
515         bool dev_closed;
516         bool link_up;
517         enum i40e_aq_link_speed link_speed;
518         bool vf_reset;
519         volatile uint32_t pend_cmd; /* pending command not finished yet */
520         uint32_t cmd_retval; /* return value of the cmd response from PF */
521         u16 pend_msg; /* flags indicates events from pf not handled yet */
522         uint8_t *aq_resp; /* buffer to store the adminq response from PF */
523
524         /* VSI info */
525         struct i40e_virtchnl_vf_resource *vf_res; /* All VSIs */
526         struct i40e_virtchnl_vsi_resource *vsi_res; /* LAN VSI */
527         struct i40e_vsi vsi;
528         uint64_t flags;
529 };
530
531 /*
532  * Structure to store private data for each PF/VF instance.
533  */
534 struct i40e_adapter {
535         /* Common for both PF and VF */
536         struct i40e_hw hw;
537         struct rte_eth_dev *eth_dev;
538
539         /* Specific for PF or VF */
540         union {
541                 struct i40e_pf pf;
542                 struct i40e_vf vf;
543         };
544
545         /* For vector PMD */
546         bool rx_bulk_alloc_allowed;
547         bool rx_vec_allowed;
548         bool tx_simple_allowed;
549         bool tx_vec_allowed;
550
551         /* For PTP */
552         struct rte_timecounter systime_tc;
553         struct rte_timecounter rx_tstamp_tc;
554         struct rte_timecounter tx_tstamp_tc;
555 };
556
557 int i40e_dev_switch_queues(struct i40e_pf *pf, bool on);
558 int i40e_vsi_release(struct i40e_vsi *vsi);
559 struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf,
560                                 enum i40e_vsi_type type,
561                                 struct i40e_vsi *uplink_vsi,
562                                 uint16_t user_param);
563 int i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on);
564 int i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on);
565 int i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan);
566 int i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan);
567 int i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *filter);
568 int i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr);
569 void i40e_update_vsi_stats(struct i40e_vsi *vsi);
570 void i40e_pf_disable_irq0(struct i40e_hw *hw);
571 void i40e_pf_enable_irq0(struct i40e_hw *hw);
572 int i40e_dev_link_update(struct rte_eth_dev *dev,
573                          __rte_unused int wait_to_complete);
574 void i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi);
575 void i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi);
576 int i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
577                            struct i40e_vsi_vlan_pvid_info *info);
578 int i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on);
579 int i40e_vsi_config_vlan_filter(struct i40e_vsi *vsi, bool on);
580 uint64_t i40e_config_hena(uint64_t flags);
581 uint64_t i40e_parse_hena(uint64_t flags);
582 enum i40e_status_code i40e_fdir_setup_tx_resources(struct i40e_pf *pf);
583 enum i40e_status_code i40e_fdir_setup_rx_resources(struct i40e_pf *pf);
584 int i40e_fdir_setup(struct i40e_pf *pf);
585 const struct rte_memzone *i40e_memzone_reserve(const char *name,
586                                         uint32_t len,
587                                         int socket_id);
588 int i40e_fdir_configure(struct rte_eth_dev *dev);
589 void i40e_fdir_teardown(struct i40e_pf *pf);
590 enum i40e_filter_pctype i40e_flowtype_to_pctype(uint16_t flow_type);
591 uint16_t i40e_pctype_to_flowtype(enum i40e_filter_pctype pctype);
592 int i40e_fdir_ctrl_func(struct rte_eth_dev *dev,
593                           enum rte_filter_op filter_op,
594                           void *arg);
595 int i40e_select_filter_input_set(struct i40e_hw *hw,
596                                  struct rte_eth_input_set_conf *conf,
597                                  enum rte_filter_type filter);
598 int i40e_hash_filter_inset_select(struct i40e_hw *hw,
599                              struct rte_eth_input_set_conf *conf);
600 int i40e_fdir_filter_inset_select(struct i40e_pf *pf,
601                              struct rte_eth_input_set_conf *conf);
602
603 void i40e_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
604         struct rte_eth_rxq_info *qinfo);
605 void i40e_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
606         struct rte_eth_txq_info *qinfo);
607
608 /* I40E_DEV_PRIVATE_TO */
609 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
610         (&((struct i40e_adapter *)adapter)->pf)
611 #define I40E_DEV_PRIVATE_TO_HW(adapter) \
612         (&((struct i40e_adapter *)adapter)->hw)
613 #define I40E_DEV_PRIVATE_TO_ADAPTER(adapter) \
614         ((struct i40e_adapter *)adapter)
615
616 /* I40EVF_DEV_PRIVATE_TO */
617 #define I40EVF_DEV_PRIVATE_TO_VF(adapter) \
618         (&((struct i40e_adapter *)adapter)->vf)
619
620 static inline struct i40e_vsi *
621 i40e_get_vsi_from_adapter(struct i40e_adapter *adapter)
622 {
623         struct i40e_hw *hw;
624
625         if (!adapter)
626                 return NULL;
627
628         hw = I40E_DEV_PRIVATE_TO_HW(adapter);
629         if (hw->mac.type == I40E_MAC_VF || hw->mac.type == I40E_MAC_X722_VF) {
630                 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(adapter);
631                 return &vf->vsi;
632         } else {
633                 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(adapter);
634                 return pf->main_vsi;
635         }
636 }
637 #define I40E_DEV_PRIVATE_TO_MAIN_VSI(adapter) \
638         i40e_get_vsi_from_adapter((struct i40e_adapter *)adapter)
639
640 /* I40E_VSI_TO */
641 #define I40E_VSI_TO_HW(vsi) \
642         (&(((struct i40e_vsi *)vsi)->adapter->hw))
643 #define I40E_VSI_TO_PF(vsi) \
644         (&(((struct i40e_vsi *)vsi)->adapter->pf))
645 #define I40E_VSI_TO_VF(vsi) \
646         (&(((struct i40e_vsi *)vsi)->adapter->vf))
647 #define I40E_VSI_TO_DEV_DATA(vsi) \
648         (((struct i40e_vsi *)vsi)->adapter->pf.dev_data)
649 #define I40E_VSI_TO_ETH_DEV(vsi) \
650         (((struct i40e_vsi *)vsi)->adapter->eth_dev)
651
652 /* I40E_PF_TO */
653 #define I40E_PF_TO_HW(pf) \
654         (&(((struct i40e_pf *)pf)->adapter->hw))
655 #define I40E_PF_TO_ADAPTER(pf) \
656         ((struct i40e_adapter *)pf->adapter)
657
658 /* I40E_VF_TO */
659 #define I40E_VF_TO_HW(vf) \
660         (&(((struct i40e_vf *)vf)->adapter->hw))
661
662 static inline void
663 i40e_init_adminq_parameter(struct i40e_hw *hw)
664 {
665         hw->aq.num_arq_entries = I40E_AQ_LEN;
666         hw->aq.num_asq_entries = I40E_AQ_LEN;
667         hw->aq.arq_buf_size = I40E_AQ_BUF_SZ;
668         hw->aq.asq_buf_size = I40E_AQ_BUF_SZ;
669 }
670
671 static inline int
672 i40e_align_floor(int n)
673 {
674         if (n == 0)
675                 return 0;
676         return 1 << (sizeof(n) * CHAR_BIT - 1 - __builtin_clz(n));
677 }
678
679 static inline uint16_t
680 i40e_calc_itr_interval(int16_t interval)
681 {
682         if (interval < 0 || interval > I40E_QUEUE_ITR_INTERVAL_MAX)
683                 interval = I40E_QUEUE_ITR_INTERVAL_DEFAULT;
684
685         /* Convert to hardware count, as writing each 1 represents 2 us */
686         return interval / 2;
687 }
688
689 #define I40E_VALID_FLOW(flow_type) \
690         ((flow_type) == RTE_ETH_FLOW_FRAG_IPV4 || \
691         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_TCP || \
692         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_UDP || \
693         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_SCTP || \
694         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV4_OTHER || \
695         (flow_type) == RTE_ETH_FLOW_FRAG_IPV6 || \
696         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_TCP || \
697         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_UDP || \
698         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_SCTP || \
699         (flow_type) == RTE_ETH_FLOW_NONFRAG_IPV6_OTHER || \
700         (flow_type) == RTE_ETH_FLOW_L2_PAYLOAD)
701
702 #define I40E_VALID_PCTYPE(pctype) \
703         ((pctype) == I40E_FILTER_PCTYPE_FRAG_IPV4 || \
704         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_TCP || \
705         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_UDP || \
706         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_SCTP || \
707         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV4_OTHER || \
708         (pctype) == I40E_FILTER_PCTYPE_FRAG_IPV6 || \
709         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_UDP || \
710         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_TCP || \
711         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_SCTP || \
712         (pctype) == I40E_FILTER_PCTYPE_NONF_IPV6_OTHER || \
713         (pctype) == I40E_FILTER_PCTYPE_L2_PAYLOAD)
714
715 #endif /* _I40E_ETHDEV_H_ */