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