ethdev: support multiple sizes of redirection table
[dpdk.git] / lib / librte_pmd_i40e / i40e_ethdev.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 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_AQ_LEN               32
40 #define I40E_AQ_BUF_SZ            4096
41 /* Number of queues per TC should be one of 1, 2, 4, 8, 16, 32, 64 */
42 #define I40E_MAX_Q_PER_TC         64
43 #define I40E_NUM_DESC_DEFAULT     512
44 #define I40E_NUM_DESC_ALIGN       32
45 #define I40E_BUF_SIZE_MIN         1024
46 #define I40E_FRAME_SIZE_MAX       9728
47 #define I40E_QUEUE_BASE_ADDR_UNIT 128
48 /* number of VSIs and queue default setting */
49 #define I40E_MAX_QP_NUM_PER_VF    16
50 #define I40E_DEFAULT_QP_NUM_FDIR  64
51 #define I40E_UINT32_BIT_SIZE      (CHAR_BIT * sizeof(uint32_t))
52 #define I40E_VFTA_SIZE            (4096 / I40E_UINT32_BIT_SIZE)
53 /* Default TC traffic in case DCB is not enabled */
54 #define I40E_DEFAULT_TCMAP        0x1
55
56 /* Always assign pool 0 to main VSI, VMDQ will start from 1 */
57 #define I40E_VMDQ_POOL_BASE       1
58
59 #define I40E_DEFAULT_RX_FREE_THRESH  32
60 #define I40E_DEFAULT_RX_PTHRESH      8
61 #define I40E_DEFAULT_RX_HTHRESH      8
62 #define I40E_DEFAULT_RX_WTHRESH      0
63
64 #define I40E_DEFAULT_TX_FREE_THRESH  32
65 #define I40E_DEFAULT_TX_PTHRESH      32
66 #define I40E_DEFAULT_TX_HTHRESH      0
67 #define I40E_DEFAULT_TX_WTHRESH      0
68 #define I40E_DEFAULT_TX_RSBIT_THRESH 32
69
70 /* Bit shift and mask */
71 #define I40E_4_BIT_WIDTH  (CHAR_BIT / 2)
72 #define I40E_4_BIT_MASK   RTE_LEN2MASK(I40E_4_BIT_WIDTH, uint8_t)
73 #define I40E_8_BIT_WIDTH  CHAR_BIT
74 #define I40E_8_BIT_MASK   UINT8_MAX
75 #define I40E_16_BIT_WIDTH (CHAR_BIT * 2)
76 #define I40E_16_BIT_MASK  UINT16_MAX
77 #define I40E_32_BIT_WIDTH (CHAR_BIT * 4)
78 #define I40E_32_BIT_MASK  UINT32_MAX
79 #define I40E_48_BIT_WIDTH (CHAR_BIT * 6)
80 #define I40E_48_BIT_MASK  RTE_LEN2MASK(I40E_48_BIT_WIDTH, uint64_t)
81
82 /* i40e flags */
83 #define I40E_FLAG_RSS                   (1ULL << 0)
84 #define I40E_FLAG_DCB                   (1ULL << 1)
85 #define I40E_FLAG_VMDQ                  (1ULL << 2)
86 #define I40E_FLAG_SRIOV                 (1ULL << 3)
87 #define I40E_FLAG_HEADER_SPLIT_DISABLED (1ULL << 4)
88 #define I40E_FLAG_HEADER_SPLIT_ENABLED  (1ULL << 5)
89 #define I40E_FLAG_FDIR                  (1ULL << 6)
90 #define I40E_FLAG_VXLAN                 (1ULL << 7)
91 #define I40E_FLAG_ALL (I40E_FLAG_RSS | \
92                        I40E_FLAG_DCB | \
93                        I40E_FLAG_VMDQ | \
94                        I40E_FLAG_SRIOV | \
95                        I40E_FLAG_HEADER_SPLIT_DISABLED | \
96                        I40E_FLAG_HEADER_SPLIT_ENABLED | \
97                        I40E_FLAG_FDIR | \
98                        I40E_FLAG_VXLAN)
99
100 #define I40E_RSS_OFFLOAD_ALL ( \
101         ETH_RSS_NONF_IPV4_UDP | \
102         ETH_RSS_NONF_IPV4_TCP | \
103         ETH_RSS_NONF_IPV4_SCTP | \
104         ETH_RSS_NONF_IPV4_OTHER | \
105         ETH_RSS_FRAG_IPV4 | \
106         ETH_RSS_NONF_IPV6_UDP | \
107         ETH_RSS_NONF_IPV6_TCP | \
108         ETH_RSS_NONF_IPV6_SCTP | \
109         ETH_RSS_NONF_IPV6_OTHER | \
110         ETH_RSS_FRAG_IPV6 | \
111         ETH_RSS_L2_PAYLOAD)
112
113 /* All bits of RSS hash enable */
114 #define I40E_RSS_HENA_ALL ( \
115         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_UDP) | \
116         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_TCP) | \
117         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_SCTP) | \
118         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV4_OTHER) | \
119         (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV4) | \
120         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_UDP) | \
121         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_TCP) | \
122         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_SCTP) | \
123         (1ULL << I40E_FILTER_PCTYPE_NONF_IPV6_OTHER) | \
124         (1ULL << I40E_FILTER_PCTYPE_FRAG_IPV6) | \
125         (1ULL << I40E_FILTER_PCTYPE_FCOE_OX) | \
126         (1ULL << I40E_FILTER_PCTYPE_FCOE_RX) | \
127         (1ULL << I40E_FILTER_PCTYPE_FCOE_OTHER) | \
128         (1ULL << I40E_FILTER_PCTYPE_L2_PAYLOAD))
129
130 struct i40e_adapter;
131
132 /**
133  * MAC filter structure
134  */
135 struct i40e_mac_filter_info {
136         enum rte_mac_filter_type filter_type;
137         struct ether_addr mac_addr;
138 };
139
140 TAILQ_HEAD(i40e_mac_filter_list, i40e_mac_filter);
141
142 /* MAC filter list structure */
143 struct i40e_mac_filter {
144         TAILQ_ENTRY(i40e_mac_filter) next;
145         struct i40e_mac_filter_info mac_info;
146 };
147
148 TAILQ_HEAD(i40e_vsi_list_head, i40e_vsi_list);
149
150 struct i40e_vsi;
151
152 /* VSI list structure */
153 struct i40e_vsi_list {
154         TAILQ_ENTRY(i40e_vsi_list) list;
155         struct i40e_vsi *vsi;
156 };
157
158 struct i40e_rx_queue;
159 struct i40e_tx_queue;
160
161 /* Structure that defines a VEB */
162 struct i40e_veb {
163         struct i40e_vsi_list_head head;
164         struct i40e_vsi *associate_vsi; /* Associate VSI who owns the VEB */
165         uint16_t seid; /* The seid of VEB itself */
166         uint16_t uplink_seid; /* The uplink seid of this VEB */
167         uint16_t stats_idx;
168         struct i40e_eth_stats stats;
169 };
170
171 /* i40e MACVLAN filter structure */
172 struct i40e_macvlan_filter {
173         struct ether_addr macaddr;
174         enum rte_mac_filter_type filter_type;
175         uint16_t vlan_id;
176 };
177
178 /*
179  * Structure that defines a VSI, associated with a adapter.
180  */
181 struct i40e_vsi {
182         struct i40e_adapter *adapter; /* Backreference to associated adapter */
183         struct i40e_aqc_vsi_properties_data info; /* VSI properties */
184
185         struct i40e_eth_stats eth_stats_offset;
186         struct i40e_eth_stats eth_stats;
187         /*
188          * When drivers loaded, only a default main VSI exists. In case new VSI
189          * needs to add, HW needs to know the layout that VSIs are organized.
190          * Besides that, VSI isan element and can't switch packets, which needs
191          * to add new component VEB to perform switching. So, a new VSI needs
192          * to specify the the uplink VSI (Parent VSI) before created. The
193          * uplink VSI will check whether it had a VEB to switch packets. If no,
194          * it will try to create one. Then, uplink VSI will move the new VSI
195          * into its' sib_vsi_list to manage all the downlink VSI.
196          *  sib_vsi_list: the VSI list that shared the same uplink VSI.
197          *  parent_vsi  : the uplink VSI. It's NULL for main VSI.
198          *  veb         : the VEB associates with the VSI.
199          */
200         struct i40e_vsi_list sib_vsi_list; /* sibling vsi list */
201         struct i40e_vsi *parent_vsi;
202         struct i40e_veb *veb;    /* Associated veb, could be null */
203         bool offset_loaded;
204         enum i40e_vsi_type type; /* VSI types */
205         uint16_t vlan_num;       /* Total VLAN number */
206         uint16_t mac_num;        /* Total mac number */
207         uint32_t vfta[I40E_VFTA_SIZE];        /* VLAN bitmap */
208         struct i40e_mac_filter_list mac_list; /* macvlan filter list */
209         /* specific VSI-defined parameters, SRIOV stored the vf_id */
210         uint32_t user_param;
211         uint16_t seid;           /* The seid of VSI itself */
212         uint16_t uplink_seid;    /* The uplink seid of this VSI */
213         uint16_t nb_qps;         /* Number of queue pairs VSI can occupy */
214         uint16_t max_macaddrs;   /* Maximum number of MAC addresses */
215         uint16_t base_queue;     /* The first queue index of this VSI */
216         /*
217          * The offset to visit VSI related register, assigned by HW when
218          * creating VSI
219          */
220         uint16_t vsi_id;
221         uint16_t msix_intr; /* The MSIX interrupt binds to VSI */
222         uint8_t enabled_tc; /* The traffic class enabled */
223 };
224
225 struct pool_entry {
226         LIST_ENTRY(pool_entry) next;
227         uint16_t base;
228         uint16_t len;
229 };
230
231 LIST_HEAD(res_list, pool_entry);
232
233 struct i40e_res_pool_info {
234         uint32_t base;              /* Resource start index */
235         uint32_t num_alloc;         /* Allocated resource number */
236         uint32_t num_free;          /* Total available resource number */
237         struct res_list alloc_list; /* Allocated resource list */
238         struct res_list free_list;  /* Available resource list */
239 };
240
241 enum I40E_VF_STATE {
242         I40E_VF_INACTIVE = 0,
243         I40E_VF_INRESET,
244         I40E_VF_ININIT,
245         I40E_VF_ACTIVE,
246 };
247
248 /*
249  * Structure to store private data for PF host.
250  */
251 struct i40e_pf_vf {
252         struct i40e_pf *pf;
253         struct i40e_vsi *vsi;
254         enum I40E_VF_STATE state; /* The number of queue pairs availiable */
255         uint16_t vf_idx; /* VF index in pf->vfs */
256         uint16_t lan_nb_qps; /* Actual queues allocated */
257         uint16_t reset_cnt; /* Total vf reset times */
258 };
259
260 /*
261  * Structure to store private data for VMDQ instance
262  */
263 struct i40e_vmdq_info {
264         struct i40e_pf *pf;
265         struct i40e_vsi *vsi;
266 };
267
268 /*
269  * Structure to store private data specific for PF instance.
270  */
271 struct i40e_pf {
272         struct i40e_adapter *adapter; /* The adapter this PF associate to */
273         struct i40e_vsi *main_vsi; /* pointer to main VSI structure */
274         uint16_t mac_seid; /* The seid of the MAC of this PF */
275         uint16_t main_vsi_seid; /* The seid of the main VSI */
276         uint16_t max_num_vsi;
277         struct i40e_res_pool_info qp_pool;    /*Queue pair pool */
278         struct i40e_res_pool_info msix_pool;  /* MSIX interrupt pool */
279
280         struct i40e_hw_port_stats stats_offset;
281         struct i40e_hw_port_stats stats;
282         bool offset_loaded;
283
284         struct rte_eth_dev_data *dev_data; /* Pointer to the device data */
285         struct ether_addr dev_addr; /* PF device mac address */
286         uint64_t flags; /* PF featuer flags */
287         /* All kinds of queue pair setting for different VSIs */
288         struct i40e_pf_vf *vfs;
289         uint16_t vf_num;
290         /* Each of below queue pairs should be power of 2 since it's the
291            precondition after TC configuration applied */
292         uint16_t lan_nb_qps; /* The number of queue pairs of LAN */
293         uint16_t vmdq_nb_qps; /* The number of queue pairs of VMDq */
294         uint16_t vf_nb_qps; /* The number of queue pairs of VF */
295         uint16_t fdir_nb_qps; /* The number of queue pairs of Flow Director */
296         uint16_t hash_lut_size; /* The size of hash lookup table */
297         /* store VXLAN UDP ports */
298         uint16_t vxlan_ports[I40E_MAX_PF_UDP_OFFLOAD_PORTS];
299         uint16_t vxlan_bitmap; /* Vxlan bit mask */
300
301         /* VMDQ related info */
302         uint16_t max_nb_vmdq_vsi; /* Max number of VMDQ VSIs supported */
303         uint16_t nb_cfg_vmdq_vsi; /* number of VMDQ VSIs configured */
304         struct i40e_vmdq_info *vmdq;
305 };
306
307 enum pending_msg {
308         PFMSG_LINK_CHANGE = 0x1,
309         PFMSG_RESET_IMPENDING = 0x2,
310         PFMSG_DRIVER_CLOSE = 0x4,
311 };
312
313 struct i40e_vsi_vlan_pvid_info {
314         uint16_t on;            /* Enable or disable pvid */
315         union {
316                 uint16_t pvid;  /* Valid in case 'on' is set to set pvid */
317                 struct {
318                 /*  Valid in case 'on' is cleared. 'tagged' will reject tagged packets,
319                  *  while 'untagged' will reject untagged packets.
320                  */
321                         uint8_t tagged;
322                         uint8_t untagged;
323                 } reject;
324         } config;
325 };
326
327 struct i40e_vf_rx_queues {
328         uint64_t rx_dma_addr;
329         uint32_t rx_ring_len;
330         uint32_t buff_size;
331 };
332
333 struct i40e_vf_tx_queues {
334         uint64_t tx_dma_addr;
335         uint32_t tx_ring_len;
336 };
337
338 /*
339  * Structure to store private data specific for VF instance.
340  */
341 struct i40e_vf {
342         struct i40e_adapter *adapter; /* The adapter this VF associate to */
343         struct rte_eth_dev_data *dev_data; /* Pointer to the device data */
344         uint16_t num_queue_pairs;
345         uint16_t max_pkt_len; /* Maximum packet length */
346         bool promisc_unicast_enabled;
347         bool promisc_multicast_enabled;
348
349         uint32_t version_major; /* Major version number */
350         uint32_t version_minor; /* Minor version number */
351         uint16_t promisc_flags; /* Promiscuous setting */
352         uint32_t vlan[I40E_VFTA_SIZE]; /* VLAN bit map */
353
354         /* Event from pf */
355         bool dev_closed;
356         bool link_up;
357         bool vf_reset;
358         volatile uint32_t pend_cmd; /* pending command not finished yet */
359         u16 pend_msg; /* flags indicates events from pf not handled yet */
360
361         /* VSI info */
362         struct i40e_virtchnl_vf_resource *vf_res; /* All VSIs */
363         struct i40e_virtchnl_vsi_resource *vsi_res; /* LAN VSI */
364         struct i40e_vsi vsi;
365 };
366
367 /*
368  * Structure to store private data for each PF/VF instance.
369  */
370 struct i40e_adapter {
371         /* Common for both PF and VF */
372         struct i40e_hw hw;
373         struct rte_eth_dev *eth_dev;
374
375         /* Specific for PF or VF */
376         union {
377                 struct i40e_pf pf;
378                 struct i40e_vf vf;
379         };
380 };
381
382 int i40e_dev_switch_queues(struct i40e_pf *pf, bool on);
383 int i40e_vsi_release(struct i40e_vsi *vsi);
384 struct i40e_vsi *i40e_vsi_setup(struct i40e_pf *pf,
385                                 enum i40e_vsi_type type,
386                                 struct i40e_vsi *uplink_vsi,
387                                 uint16_t user_param);
388 int i40e_switch_rx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on);
389 int i40e_switch_tx_queue(struct i40e_hw *hw, uint16_t q_idx, bool on);
390 int i40e_vsi_add_vlan(struct i40e_vsi *vsi, uint16_t vlan);
391 int i40e_vsi_delete_vlan(struct i40e_vsi *vsi, uint16_t vlan);
392 int i40e_vsi_add_mac(struct i40e_vsi *vsi, struct i40e_mac_filter_info *filter);
393 int i40e_vsi_delete_mac(struct i40e_vsi *vsi, struct ether_addr *addr);
394 void i40e_update_vsi_stats(struct i40e_vsi *vsi);
395 void i40e_pf_disable_irq0(struct i40e_hw *hw);
396 void i40e_pf_enable_irq0(struct i40e_hw *hw);
397 int i40e_dev_link_update(struct rte_eth_dev *dev,
398                          __rte_unused int wait_to_complete);
399 void i40e_vsi_queues_bind_intr(struct i40e_vsi *vsi);
400 void i40e_vsi_queues_unbind_intr(struct i40e_vsi *vsi);
401 int i40e_vsi_vlan_pvid_set(struct i40e_vsi *vsi,
402                            struct i40e_vsi_vlan_pvid_info *info);
403 int i40e_vsi_config_vlan_stripping(struct i40e_vsi *vsi, bool on);
404 uint64_t i40e_config_hena(uint64_t flags);
405 uint64_t i40e_parse_hena(uint64_t flags);
406
407 /* I40E_DEV_PRIVATE_TO */
408 #define I40E_DEV_PRIVATE_TO_PF(adapter) \
409         (&((struct i40e_adapter *)adapter)->pf)
410 #define I40E_DEV_PRIVATE_TO_HW(adapter) \
411         (&((struct i40e_adapter *)adapter)->hw)
412 #define I40E_DEV_PRIVATE_TO_ADAPTER(adapter) \
413         ((struct i40e_adapter *)adapter)
414
415 /* I40EVF_DEV_PRIVATE_TO */
416 #define I40EVF_DEV_PRIVATE_TO_VF(adapter) \
417         (&((struct i40e_adapter *)adapter)->vf)
418
419 static inline struct i40e_vsi *
420 i40e_get_vsi_from_adapter(struct i40e_adapter *adapter)
421 {
422         struct i40e_hw *hw;
423
424         if (!adapter)
425                 return NULL;
426
427         hw = I40E_DEV_PRIVATE_TO_HW(adapter);
428         if (hw->mac.type == I40E_MAC_VF) {
429                 struct i40e_vf *vf = I40EVF_DEV_PRIVATE_TO_VF(adapter);
430                 return &vf->vsi;
431         } else {
432                 struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(adapter);
433                 return pf->main_vsi;
434         }
435 }
436 #define I40E_DEV_PRIVATE_TO_MAIN_VSI(adapter) \
437         i40e_get_vsi_from_adapter((struct i40e_adapter *)adapter)
438
439 /* I40E_VSI_TO */
440 #define I40E_VSI_TO_HW(vsi) \
441         (&(((struct i40e_vsi *)vsi)->adapter->hw))
442 #define I40E_VSI_TO_PF(vsi) \
443         (&(((struct i40e_vsi *)vsi)->adapter->pf))
444 #define I40E_VSI_TO_DEV_DATA(vsi) \
445         (((struct i40e_vsi *)vsi)->adapter->pf.dev_data)
446 #define I40E_VSI_TO_ETH_DEV(vsi) \
447         (((struct i40e_vsi *)vsi)->adapter->eth_dev)
448
449 /* I40E_PF_TO */
450 #define I40E_PF_TO_HW(pf) \
451         (&(((struct i40e_pf *)pf)->adapter->hw))
452 #define I40E_PF_TO_ADAPTER(pf) \
453         ((struct i40e_adapter *)pf->adapter)
454
455 /* I40E_VF_TO */
456 #define I40E_VF_TO_HW(vf) \
457         (&(((struct i40e_vf *)vf)->adapter->hw))
458
459 static inline void
460 i40e_init_adminq_parameter(struct i40e_hw *hw)
461 {
462         hw->aq.num_arq_entries = I40E_AQ_LEN;
463         hw->aq.num_asq_entries = I40E_AQ_LEN;
464         hw->aq.arq_buf_size = I40E_AQ_BUF_SZ;
465         hw->aq.asq_buf_size = I40E_AQ_BUF_SZ;
466 }
467
468 #endif /* _I40E_ETHDEV_H_ */