356fa89d7198143590a5c8d945459c7007a05d9c
[deb_dpdk.git] / drivers / net / i40e / rte_pmd_i40e.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) 2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _PMD_I40E_H_
34 #define _PMD_I40E_H_
35
36 /**
37  * @file rte_pmd_i40e.h
38  *
39  * i40e PMD specific functions.
40  *
41  * @b EXPERIMENTAL: this API may change, or be removed, without prior notice
42  *
43  */
44
45 #include <rte_ethdev.h>
46
47 /**
48  * Response sent back to i40e driver from user app after callback
49  */
50 enum rte_pmd_i40e_mb_event_rsp {
51         RTE_PMD_I40E_MB_EVENT_NOOP_ACK,  /**< skip mbox request and ACK */
52         RTE_PMD_I40E_MB_EVENT_NOOP_NACK, /**< skip mbox request and NACK */
53         RTE_PMD_I40E_MB_EVENT_PROCEED,  /**< proceed with mbox request  */
54         RTE_PMD_I40E_MB_EVENT_MAX       /**< max value of this enum */
55 };
56
57 /**
58  * Data sent to the user application when the callback is executed.
59  */
60 struct rte_pmd_i40e_mb_event_param {
61         uint16_t vfid;     /**< Virtual Function number */
62         uint16_t msg_type; /**< VF to PF message type, see virtchnl_ops */
63         uint16_t retval;   /**< return value */
64         void *msg;         /**< pointer to message */
65         uint16_t msglen;   /**< length of the message */
66 };
67
68 /**
69  * Option of package processing.
70  */
71 enum rte_pmd_i40e_package_op {
72         RTE_PMD_I40E_PKG_OP_UNDEFINED = 0,
73         RTE_PMD_I40E_PKG_OP_WR_ADD,   /**< load package and add to info list */
74         RTE_PMD_I40E_PKG_OP_WR_DEL, /**< load package and delete from info list */
75         RTE_PMD_I40E_PKG_OP_WR_ONLY, /**< load package without modifying info list */
76         RTE_PMD_I40E_PKG_OP_MAX = 32
77 };
78
79 /**
80  * Types of package information.
81  */
82 enum rte_pmd_i40e_package_info {
83         RTE_PMD_I40E_PKG_INFO_UNDEFINED = 0,
84         RTE_PMD_I40E_PKG_INFO_GLOBAL_HEADER,
85         RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES_SIZE,
86         RTE_PMD_I40E_PKG_INFO_GLOBAL_NOTES,
87         RTE_PMD_I40E_PKG_INFO_GLOBAL_MAX = 1024,
88         RTE_PMD_I40E_PKG_INFO_HEADER,
89         RTE_PMD_I40E_PKG_INFO_DEVID_NUM,
90         RTE_PMD_I40E_PKG_INFO_DEVID_LIST,
91         RTE_PMD_I40E_PKG_INFO_MAX = 0xFFFFFFFF
92 };
93
94 #define RTE_PMD_I40E_DDP_NAME_SIZE 32
95
96 /**
97  * Version for dynamic device personalization.
98  * Version in "major.minor.update.draft" format.
99  */
100 struct rte_pmd_i40e_ddp_version {
101         uint8_t major;
102         uint8_t minor;
103         uint8_t update;
104         uint8_t draft;
105 };
106
107 /**
108  * Device ID for dynamic device personalization.
109  */
110 struct rte_pmd_i40e_ddp_device_id {
111         uint32_t vendor_dev_id;
112         uint32_t sub_vendor_dev_id;
113 };
114
115 /**
116  * Profile information in profile info list.
117  */
118 struct rte_pmd_i40e_profile_info {
119         uint32_t track_id;
120         struct rte_pmd_i40e_ddp_version version;
121         uint8_t owner;
122         uint8_t reserved[7];
123         uint8_t name[RTE_PMD_I40E_DDP_NAME_SIZE];
124 };
125
126 #define RTE_PMD_I40E_DDP_OWNER_UNKNOWN 0xFF
127
128 /**
129  * Profile information list returned from HW.
130  */
131 struct rte_pmd_i40e_profile_list {
132         uint32_t p_count;
133         struct rte_pmd_i40e_profile_info p_info[1];
134 };
135
136 /**
137  * ptype mapping table only accept RTE_PTYPE_XXX or "user defined" ptype.
138  * A ptype with MSB set will be regarded as a user defined ptype.
139  * Below macro help to create a user defined ptype.
140  */
141 #define RTE_PMD_I40E_PTYPE_USER_DEFINE_MASK 0x80000000
142
143 struct rte_pmd_i40e_ptype_mapping {
144         uint16_t hw_ptype; /**< hardware defined packet type*/
145         uint32_t sw_ptype; /**< software defined packet type */
146 };
147
148 /**
149  * Notify VF when PF link status changes.
150  *
151  * @param port
152  *   The port identifier of the Ethernet device.
153  * @param vf
154  *   VF id.
155  * @return
156  *   - (0) if successful.
157  *   - (-ENODEV) if *port* invalid.
158  *   - (-EINVAL) if *vf* invalid.
159  */
160 int rte_pmd_i40e_ping_vfs(uint8_t port, uint16_t vf);
161
162 /**
163  * Enable/Disable VF MAC anti spoofing.
164  *
165  * @param port
166  *    The port identifier of the Ethernet device.
167  * @param vf_id
168  *    VF on which to set MAC anti spoofing.
169  * @param on
170  *    1 - Enable VFs MAC anti spoofing.
171  *    0 - Disable VFs MAC anti spoofing.
172  * @return
173  *   - (0) if successful.
174  *   - (-ENODEV) if *port* invalid.
175  *   - (-EINVAL) if bad parameter.
176  */
177 int rte_pmd_i40e_set_vf_mac_anti_spoof(uint8_t port,
178                                        uint16_t vf_id,
179                                        uint8_t on);
180
181 /**
182  * Enable/Disable VF VLAN anti spoofing.
183  *
184  * @param port
185  *    The port identifier of the Ethernet device.
186  * @param vf_id
187  *    VF on which to set VLAN anti spoofing.
188  * @param on
189  *    1 - Enable VFs VLAN anti spoofing.
190  *    0 - Disable VFs VLAN anti spoofing.
191  * @return
192  *   - (0) if successful.
193  *   - (-ENODEV) if *port* invalid.
194  *   - (-EINVAL) if bad parameter.
195  */
196 int rte_pmd_i40e_set_vf_vlan_anti_spoof(uint8_t port,
197                                         uint16_t vf_id,
198                                         uint8_t on);
199
200 /**
201  * Enable/Disable TX loopback on all the PF and VFs.
202  *
203  * @param port
204  *    The port identifier of the Ethernet device.
205  * @param on
206  *    1 - Enable TX loopback.
207  *    0 - Disable TX loopback.
208  * @return
209  *   - (0) if successful.
210  *   - (-ENODEV) if *port* invalid.
211  *   - (-EINVAL) if bad parameter.
212  */
213 int rte_pmd_i40e_set_tx_loopback(uint8_t port,
214                                  uint8_t on);
215
216 /**
217  * Enable/Disable VF unicast promiscuous mode.
218  *
219  * @param port
220  *    The port identifier of the Ethernet device.
221  * @param vf_id
222  *    VF on which to set.
223  * @param on
224  *    1 - Enable.
225  *    0 - Disable.
226  * @return
227  *   - (0) if successful.
228  *   - (-ENODEV) if *port* invalid.
229  *   - (-EINVAL) if bad parameter.
230  */
231 int rte_pmd_i40e_set_vf_unicast_promisc(uint8_t port,
232                                         uint16_t vf_id,
233                                         uint8_t on);
234
235 /**
236  * Enable/Disable VF multicast promiscuous mode.
237  *
238  * @param port
239  *    The port identifier of the Ethernet device.
240  * @param vf_id
241  *    VF on which to set.
242  * @param on
243  *    1 - Enable.
244  *    0 - Disable.
245  * @return
246  *   - (0) if successful.
247  *   - (-ENODEV) if *port* invalid.
248  *   - (-EINVAL) if bad parameter.
249  */
250 int rte_pmd_i40e_set_vf_multicast_promisc(uint8_t port,
251                                           uint16_t vf_id,
252                                           uint8_t on);
253
254 /**
255  * Set the VF MAC address.
256  *
257  * PF should set MAC address before VF initialized, if PF sets the MAC
258  * address after VF initialized, new MAC address won't be effective until
259  * VF reinitialize.
260  *
261  * This will remove all existing MAC filters.
262  *
263  * @param port
264  *   The port identifier of the Ethernet device.
265  * @param vf_id
266  *   VF id.
267  * @param mac_addr
268  *   VF MAC address.
269  * @return
270  *   - (0) if successful.
271  *   - (-ENODEV) if *port* invalid.
272  *   - (-EINVAL) if *vf* or *mac_addr* is invalid.
273  */
274 int rte_pmd_i40e_set_vf_mac_addr(uint8_t port, uint16_t vf_id,
275                                  struct ether_addr *mac_addr);
276
277 /**
278  * Enable/Disable vf vlan strip for all queues in a pool
279  *
280  * @param port
281  *    The port identifier of the Ethernet device.
282  * @param vf
283  *    ID specifying VF.
284  * @param on
285  *    1 - Enable VF's vlan strip on RX queues.
286  *    0 - Disable VF's vlan strip on RX queues.
287  *
288  * @return
289  *   - (0) if successful.
290  *   - (-ENODEV) if *port* invalid.
291  *   - (-EINVAL) if bad parameter.
292  */
293 int
294 rte_pmd_i40e_set_vf_vlan_stripq(uint8_t port, uint16_t vf, uint8_t on);
295
296 /**
297  * Enable/Disable vf vlan insert
298  *
299  * @param port
300  *    The port identifier of the Ethernet device.
301  * @param vf_id
302  *    ID specifying VF.
303  * @param vlan_id
304  *    0 - Disable VF's vlan insert.
305  *    n - Enable; n is inserted as the vlan id.
306  *
307  * @return
308  *   - (0) if successful.
309  *   - (-ENODEV) if *port* invalid.
310  *   - (-EINVAL) if bad parameter.
311  */
312 int rte_pmd_i40e_set_vf_vlan_insert(uint8_t port, uint16_t vf_id,
313                                     uint16_t vlan_id);
314
315 /**
316  * Enable/Disable vf broadcast mode
317  *
318  * @param port
319  *    The port identifier of the Ethernet device.
320  * @param vf_id
321  *    ID specifying VF.
322  * @param on
323  *    0 - Disable broadcast.
324  *    1 - Enable broadcast.
325  *
326  * @return
327  *   - (0) if successful.
328  *   - (-ENODEV) if *port* invalid.
329  *   - (-EINVAL) if bad parameter.
330  */
331 int rte_pmd_i40e_set_vf_broadcast(uint8_t port, uint16_t vf_id,
332                                   uint8_t on);
333
334 /**
335  * Enable/Disable vf vlan tag
336  *
337  * @param port
338  *    The port identifier of the Ethernet device.
339  * @param vf_id
340  *    ID specifying VF.
341  * @param on
342  *    0 - Disable VF's vlan tag.
343  *    n - Enable VF's vlan tag.
344  *
345  * @return
346  *   - (0) if successful.
347  *   - (-ENODEV) if *port* invalid.
348  *   - (-EINVAL) if bad parameter.
349  */
350 int rte_pmd_i40e_set_vf_vlan_tag(uint8_t port, uint16_t vf_id, uint8_t on);
351
352 /**
353  * Enable/Disable VF VLAN filter
354  *
355  * @param port
356  *    The port identifier of the Ethernet device.
357  * @param vlan_id
358  *    ID specifying VLAN
359  * @param vf_mask
360  *    Mask to filter VF's
361  * @param on
362  *    0 - Disable VF's VLAN filter.
363  *    1 - Enable VF's VLAN filter.
364  *
365  * @return
366  *   - (0) if successful.
367  *   - (-ENODEV) if *port* invalid.
368  *   - (-EINVAL) if bad parameter.
369  *   - (-ENOTSUP) not supported by firmware.
370  */
371 int rte_pmd_i40e_set_vf_vlan_filter(uint8_t port, uint16_t vlan_id,
372                                     uint64_t vf_mask, uint8_t on);
373
374 /**
375  * Get VF's statistics
376  *
377  * @param port
378  *    The port identifier of the Ethernet device.
379  * @param vf_id
380  *    VF on which to get.
381  * @param stats
382  *    A pointer to a structure of type *rte_eth_stats* to be filled with
383  *    the values of device counters for the following set of statistics:
384  *   - *ipackets* with the total of successfully received packets.
385  *   - *opackets* with the total of successfully transmitted packets.
386  *   - *ibytes*   with the total of successfully received bytes.
387  *   - *obytes*   with the total of successfully transmitted bytes.
388  *   - *ierrors*  with the total of erroneous received packets.
389  *   - *oerrors*  with the total of failed transmitted packets.
390  * @return
391  *   - (0) if successful.
392  *   - (-ENODEV) if *port* invalid.
393  *   - (-EINVAL) if bad parameter.
394  */
395
396 int rte_pmd_i40e_get_vf_stats(uint8_t port,
397                               uint16_t vf_id,
398                               struct rte_eth_stats *stats);
399
400 /**
401  * Clear VF's statistics
402  *
403  * @param port
404  *    The port identifier of the Ethernet device.
405  * @param vf_id
406  *    VF on which to get.
407  * @return
408  *   - (0) if successful.
409  *   - (-ENODEV) if *port* invalid.
410  *   - (-EINVAL) if bad parameter.
411  */
412 int rte_pmd_i40e_reset_vf_stats(uint8_t port,
413                                 uint16_t vf_id);
414
415 /**
416  * Set VF's max bandwidth.
417  *
418  * Per VF bandwidth limitation and per TC bandwidth limitation cannot
419  * be enabled in parallel. If per TC bandwidth is enabled, this function
420  * will disable it.
421  *
422  * @param port
423  *    The port identifier of the Ethernet device.
424  * @param vf_id
425  *    ID specifying VF.
426  * @param bw
427  *    Bandwidth for this VF.
428  *    The value should be an absolute bandwidth in Mbps.
429  *    The bandwidth is a L2 bandwidth counting the bytes of ethernet packets.
430  *    Not count the bytes added by physical layer.
431  * @return
432  *   - (0) if successful.
433  *   - (-ENODEV) if *port* invalid.
434  *   - (-EINVAL) if bad parameter.
435  *   - (-ENOTSUP) not supported by firmware.
436  */
437 int rte_pmd_i40e_set_vf_max_bw(uint8_t port,
438                                uint16_t vf_id,
439                                uint32_t bw);
440
441 /**
442  * Set all the TCs' bandwidth weight on a specific VF.
443  *
444  * The bw_weight means the percentage occupied by the TC.
445  * It can be taken as the relative min bandwidth setting.
446  *
447  * @param port
448  *    The port identifier of the Ethernet device.
449  * @param vf_id
450  *    ID specifying VF.
451  * @param tc_num
452  *    Number of TCs.
453  * @param bw_weight
454  *    An array of relative bandwidth weight for all the TCs.
455  *    The summary of the bw_weight should be 100.
456  * @return
457  *   - (0) if successful.
458  *   - (-ENODEV) if *port* invalid.
459  *   - (-EINVAL) if bad parameter.
460  *   - (-ENOTSUP) not supported by firmware.
461  */
462 int rte_pmd_i40e_set_vf_tc_bw_alloc(uint8_t port,
463                                     uint16_t vf_id,
464                                     uint8_t tc_num,
465                                     uint8_t *bw_weight);
466
467 /**
468  * Set a specific TC's max bandwidth on a specific VF.
469  *
470  * @param port
471  *    The port identifier of the Ethernet device.
472  * @param vf_id
473  *    ID specifying VF.
474  * @param tc_no
475  *    Number specifying TC.
476  * @param bw
477  *    Max bandwidth for this TC.
478  *    The value should be an absolute bandwidth in Mbps.
479  *    The bandwidth is a L2 bandwidth counting the bytes of ethernet packets.
480  *    Not count the bytes added by physical layer.
481  * @return
482  *   - (0) if successful.
483  *   - (-ENODEV) if *port* invalid.
484  *   - (-EINVAL) if bad parameter.
485  *   - (-ENOTSUP) not supported by firmware.
486  */
487 int rte_pmd_i40e_set_vf_tc_max_bw(uint8_t port,
488                                   uint16_t vf_id,
489                                   uint8_t tc_no,
490                                   uint32_t bw);
491
492 /**
493  * Set some TCs to strict priority mode on a physical port.
494  *
495  * @param port
496  *    The port identifier of the Ethernet device.
497  * @param tc_map
498  *    A bit map for the TCs.
499  * @return
500  *   - (0) if successful.
501  *   - (-ENODEV) if *port* invalid.
502  *   - (-EINVAL) if bad parameter.
503  *   - (-ENOTSUP) not supported by firmware.
504  */
505 int rte_pmd_i40e_set_tc_strict_prio(uint8_t port, uint8_t tc_map);
506
507 /**
508  * Load/Unload a ddp package
509  *
510  * @param port
511  *    The port identifier of the Ethernet device.
512  * @param buff
513  *    buffer of package.
514  * @param size
515  *    size of buffer.
516  * @param op
517  *   Operation of package processing
518  * @return
519  *   - (0) if successful.
520  *   - (-ENODEV) if *port* invalid.
521  *   - (-EINVAL) if bad parameter.
522  *   - (-EEXIST) if profile exists.
523  *   - (-EACCES) if profile does not exist.
524  *   - (-ENOTSUP) if operation not supported.
525  */
526 int rte_pmd_i40e_process_ddp_package(uint8_t port, uint8_t *buff,
527                                      uint32_t size,
528                                      enum rte_pmd_i40e_package_op op);
529
530 /**
531  * rte_pmd_i40e_get_ddp_info - Get profile's info
532  * @param pkg
533  *    buffer of package.
534  * @param pkg_size
535  *    package buffer size
536  * @param info
537  *    buffer for response
538  * @param size
539  *    response buffer size
540  * @param type
541  *    type of information requested
542  * @return
543  *   - (0) if successful.
544  *   - (-ENOTSUP) if information type not supported by the profile.
545  *   - (-EINVAL) if bad parameter.
546  */
547 int rte_pmd_i40e_get_ddp_info(uint8_t *pkg, uint32_t pkg_size,
548                                      uint8_t *info, uint32_t size,
549                                      enum rte_pmd_i40e_package_info type);
550
551 /**
552  * rte_pmd_i40e_get_ddp_list - Get loaded profile list
553  * @param port
554  *    port id
555  * @param buff
556  *    buffer for response
557  * @param size
558  *    buffer size
559  * @return
560  *   - (0) if successful.
561  *   - (-ENODEV) if *port* invalid.
562  *   - (-EINVAL) if bad parameter.
563  */
564 int rte_pmd_i40e_get_ddp_list(uint8_t port, uint8_t *buff, uint32_t size);
565
566 /**
567  * Update hardware defined ptype to software defined packet type
568  * mapping table.
569  *
570  * @param port
571  *    pointer to port identifier of the device.
572  * @param mapping_items
573  *    the base address of the mapping items array.
574  * @param count
575  *    number of mapping items.
576  * @param exclusive
577  *    the flag indicate different ptype mapping update method.
578  *    -(0) only overwrite referred PTYPE mapping,
579  *      keep other PTYPEs mapping unchanged.
580  *    -(!0) overwrite referred PTYPE mapping,
581  *      set other PTYPEs maps to PTYPE_UNKNOWN.
582  */
583 int rte_pmd_i40e_ptype_mapping_update(
584                         uint8_t port,
585                         struct rte_pmd_i40e_ptype_mapping *mapping_items,
586                         uint16_t count,
587                         uint8_t exclusive);
588
589 /**
590  * Reset hardware defined ptype to software defined ptype
591  * mapping table to default.
592  *
593  * @param port
594  *    pointer to port identifier of the device
595  */
596 int rte_pmd_i40e_ptype_mapping_reset(uint8_t port);
597
598 /**
599  * Get hardware defined ptype to software defined ptype
600  * mapping items.
601  *
602  * @param port
603  *    pointer to port identifier of the device.
604  * @param mapping_items
605  *    the base address of the array to store returned items.
606  * @param size
607  *    the size of the input array.
608  * @param count
609  *    the place to store the number of returned items.
610  * @param valid_only
611  *    -(0) return full mapping table.
612  *    -(!0) only return mapping items which packet_type != RTE_PTYPE_UNKNOWN.
613  */
614 int rte_pmd_i40e_ptype_mapping_get(
615                         uint8_t port,
616                         struct rte_pmd_i40e_ptype_mapping *mapping_items,
617                         uint16_t size,
618                         uint16_t *count,
619                         uint8_t valid_only);
620
621 /**
622  * Replace a specific or a group of software defined ptypes
623  * with a new one
624  *
625  * @param port
626  *    pointer to port identifier of the device
627  * @param target
628  *    the packet type to be replaced
629  * @param mask
630  *    -(0) target represent a specific software defined ptype.
631  *    -(!0) target is a mask to represent a group of software defined ptypes.
632  * @param pkt_type
633  *    the new packet type to overwrite
634  */
635 int rte_pmd_i40e_ptype_mapping_replace(uint8_t port,
636                                        uint32_t target,
637                                        uint8_t mask,
638                                        uint32_t pkt_type);
639
640 #endif /* _PMD_I40E_H_ */