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