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