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