dbd32bc1cdbfef219e43bd6c8c445b9b5efebe70
[dpdk.git] / lib / ethdev / ethdev_driver.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _RTE_ETHDEV_DRIVER_H_
6 #define _RTE_ETHDEV_DRIVER_H_
7
8 /**
9  * @file
10  *
11  * RTE Ethernet Device PMD API
12  *
13  * These APIs for the use from Ethernet drivers, user applications shouldn't
14  * use them.
15  *
16  */
17
18 #include <rte_ethdev.h>
19
20 /**
21  * @internal
22  * Structure used to hold information about the callbacks to be called for a
23  * queue on Rx and Tx.
24  */
25 struct rte_eth_rxtx_callback {
26         struct rte_eth_rxtx_callback *next;
27         union{
28                 rte_rx_callback_fn rx;
29                 rte_tx_callback_fn tx;
30         } fn;
31         void *param;
32 };
33
34 /**
35  * @internal
36  * The generic data structure associated with each Ethernet device.
37  *
38  * Pointers to burst-oriented packet receive and transmit functions are
39  * located at the beginning of the structure, along with the pointer to
40  * where all the data elements for the particular device are stored in shared
41  * memory. This split allows the function pointer and driver data to be per-
42  * process, while the actual configuration data for the device is shared.
43  */
44 struct rte_eth_dev {
45         eth_rx_burst_t rx_pkt_burst; /**< Pointer to PMD receive function. */
46         eth_tx_burst_t tx_pkt_burst; /**< Pointer to PMD transmit function. */
47         /** Pointer to PMD transmit prepare function */
48         eth_tx_prep_t tx_pkt_prepare;
49         /** Get the number of used Rx descriptors */
50         eth_rx_queue_count_t rx_queue_count;
51         /** Check the status of a Rx descriptor */
52         eth_rx_descriptor_status_t rx_descriptor_status;
53         /** Check the status of a Tx descriptor */
54         eth_tx_descriptor_status_t tx_descriptor_status;
55
56         /**
57          * Device data that is shared between primary and secondary processes
58          */
59         struct rte_eth_dev_data *data;
60         void *process_private; /**< Pointer to per-process device data. */
61         const struct eth_dev_ops *dev_ops; /**< Functions exported by PMD */
62         struct rte_device *device; /**< Backing device */
63         struct rte_intr_handle *intr_handle; /**< Device interrupt handle */
64         /** User application callbacks for NIC interrupts */
65         struct rte_eth_dev_cb_list link_intr_cbs;
66         /**
67          * User-supplied functions called from rx_burst to post-process
68          * received packets before passing them to the user
69          */
70         struct rte_eth_rxtx_callback *post_rx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
71         /**
72          * User-supplied functions called from tx_burst to pre-process
73          * received packets before passing them to the driver for transmission.
74          */
75         struct rte_eth_rxtx_callback *pre_tx_burst_cbs[RTE_MAX_QUEUES_PER_PORT];
76         enum rte_eth_dev_state state; /**< Flag indicating the port state */
77         void *security_ctx; /**< Context for security ops */
78
79         uint64_t reserved_64s[4]; /**< Reserved for future fields */
80         void *reserved_ptrs[4];   /**< Reserved for future fields */
81 } __rte_cache_aligned;
82
83 struct rte_eth_dev_sriov;
84 struct rte_eth_dev_owner;
85
86 /**
87  * @internal
88  * The data part, with no function pointers, associated with each Ethernet
89  * device. This structure is safe to place in shared memory to be common
90  * among different processes in a multi-process configuration.
91  */
92 struct rte_eth_dev_data {
93         char name[RTE_ETH_NAME_MAX_LEN]; /**< Unique identifier name */
94
95         void **rx_queues; /**< Array of pointers to Rx queues. */
96         void **tx_queues; /**< Array of pointers to Tx queues. */
97         uint16_t nb_rx_queues; /**< Number of Rx queues. */
98         uint16_t nb_tx_queues; /**< Number of Tx queues. */
99
100         struct rte_eth_dev_sriov sriov;    /**< SRIOV data */
101
102         /** PMD-specific private data. @see rte_eth_dev_release_port() */
103         void *dev_private;
104
105         struct rte_eth_link dev_link;   /**< Link-level information & status. */
106         struct rte_eth_conf dev_conf;   /**< Configuration applied to device. */
107         uint16_t mtu;                   /**< Maximum Transmission Unit. */
108         /** Common Rx buffer size handled by all queues */
109         uint32_t min_rx_buf_size;
110
111         uint64_t rx_mbuf_alloc_failed; /**< Rx ring mbuf allocation failures */
112         /** Device Ethernet link address. @see rte_eth_dev_release_port() */
113         struct rte_ether_addr *mac_addrs;
114         /** Bitmap associating MAC addresses to pools */
115         uint64_t mac_pool_sel[ETH_NUM_RECEIVE_MAC_ADDR];
116         /**
117          * Device Ethernet MAC addresses of hash filtering.
118          * @see rte_eth_dev_release_port()
119          */
120         struct rte_ether_addr *hash_mac_addrs;
121         uint16_t port_id;           /**< Device [external] port identifier. */
122
123         __extension__
124         uint8_t /** Rx promiscuous mode ON(1) / OFF(0) */
125                 promiscuous   : 1,
126                 /** Rx of scattered packets is ON(1) / OFF(0) */
127                 scattered_rx : 1,
128                 /** Rx all multicast mode ON(1) / OFF(0) */
129                 all_multicast : 1,
130                 /** Device state: STARTED(1) / STOPPED(0) */
131                 dev_started : 1,
132                 /** Rx LRO is ON(1) / OFF(0) */
133                 lro         : 1,
134                 /**
135                  * Indicates whether the device is configured:
136                  * CONFIGURED(1) / NOT CONFIGURED(0)
137                  */
138                 dev_configured : 1;
139         /** Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0) */
140         uint8_t rx_queue_state[RTE_MAX_QUEUES_PER_PORT];
141         /** Queues state: HAIRPIN(2) / STARTED(1) / STOPPED(0) */
142         uint8_t tx_queue_state[RTE_MAX_QUEUES_PER_PORT];
143         uint32_t dev_flags;             /**< Capabilities. */
144         int numa_node;                  /**< NUMA node connection. */
145         /** VLAN filter configuration */
146         struct rte_vlan_filter_conf vlan_filter_conf;
147         struct rte_eth_dev_owner owner; /**< The port owner. */
148         /**
149          * Switch-specific identifier.
150          * Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
151          */
152         uint16_t representor_id;
153         /**
154          * Port ID of the backing device.
155          * This device will be used to query representor info and calculate
156          * representor IDs. Valid if RTE_ETH_DEV_REPRESENTOR in dev_flags.
157          */
158         uint16_t backer_port_id;
159
160         pthread_mutex_t flow_ops_mutex; /**< rte_flow ops mutex. */
161         uint64_t reserved_64s[4]; /**< Reserved for future fields */
162         void *reserved_ptrs[4];   /**< Reserved for future fields */
163 } __rte_cache_aligned;
164
165 /**
166  * @internal
167  * The pool of *rte_eth_dev* structures. The size of the pool
168  * is configured at compile-time in the <rte_ethdev.c> file.
169  */
170 extern struct rte_eth_dev rte_eth_devices[];
171
172 /** @internal Declaration of the hairpin peer queue information structure. */
173 struct rte_hairpin_peer_info;
174
175 /*
176  * Definitions of all functions exported by an Ethernet driver through the
177  * generic structure of type *eth_dev_ops* supplied in the *rte_eth_dev*
178  * structure associated with an Ethernet device.
179  */
180
181 /** @internal Ethernet device configuration. */
182 typedef int  (*eth_dev_configure_t)(struct rte_eth_dev *dev);
183
184 /** @internal Function used to start a configured Ethernet device. */
185 typedef int  (*eth_dev_start_t)(struct rte_eth_dev *dev);
186
187 /** @internal Function used to stop a configured Ethernet device. */
188 typedef int (*eth_dev_stop_t)(struct rte_eth_dev *dev);
189
190 /** @internal Function used to link up a configured Ethernet device. */
191 typedef int  (*eth_dev_set_link_up_t)(struct rte_eth_dev *dev);
192
193 /** @internal Function used to link down a configured Ethernet device. */
194 typedef int  (*eth_dev_set_link_down_t)(struct rte_eth_dev *dev);
195
196 /** @internal Function used to close a configured Ethernet device. */
197 typedef int (*eth_dev_close_t)(struct rte_eth_dev *dev);
198
199 /** @internal Function used to reset a configured Ethernet device. */
200 typedef int (*eth_dev_reset_t)(struct rte_eth_dev *dev);
201
202 /** @internal Function used to detect an Ethernet device removal. */
203 typedef int (*eth_is_removed_t)(struct rte_eth_dev *dev);
204
205 /**
206  * @internal
207  * Function used to enable the Rx promiscuous mode of an Ethernet device.
208  *
209  * @param dev
210  *   ethdev handle of port.
211  *
212  * @return
213  *   Negative errno value on error, 0 on success.
214  *
215  * @retval 0
216  *   Success, promiscuous mode is enabled.
217  * @retval -ENOTSUP
218  *   Promiscuous mode is not supported.
219  * @retval -ENODEV
220  *   Device is gone.
221  * @retval -E_RTE_SECONDARY
222  *   Function was called from a secondary process instance and not supported.
223  * @retval -ETIMEDOUT
224  *   Attempt to enable promiscuos mode failed because of timeout.
225  * @retval -EAGAIN
226  *   Failed to enable promiscuous mode.
227  */
228 typedef int (*eth_promiscuous_enable_t)(struct rte_eth_dev *dev);
229
230 /**
231  * @internal
232  * Function used to disable the Rx promiscuous mode of an Ethernet device.
233  *
234  * @param dev
235  *   ethdev handle of port.
236  *
237  * @return
238  *   Negative errno value on error, 0 on success.
239  *
240  * @retval 0
241  *   Success, promiscuous mode is disabled.
242  * @retval -ENOTSUP
243  *   Promiscuous mode disabling is not supported.
244  * @retval -ENODEV
245  *   Device is gone.
246  * @retval -E_RTE_SECONDARY
247  *   Function was called from a secondary process instance and not supported.
248  * @retval -ETIMEDOUT
249  *   Attempt to disable promiscuos mode failed because of timeout.
250  * @retval -EAGAIN
251  *   Failed to disable promiscuous mode.
252  */
253 typedef int (*eth_promiscuous_disable_t)(struct rte_eth_dev *dev);
254
255 /**
256  * @internal
257  * Enable the receipt of all multicast packets by an Ethernet device.
258  *
259  * @param dev
260  *   ethdev handle of port.
261  *
262  * @return
263  *   Negative errno value on error, 0 on success.
264  *
265  * @retval 0
266  *   Success, all-multicast mode is enabled.
267  * @retval -ENOTSUP
268  *   All-multicast mode is not supported.
269  * @retval -ENODEV
270  *   Device is gone.
271  * @retval -E_RTE_SECONDARY
272  *   Function was called from a secondary process instance and not supported.
273  * @retval -ETIMEDOUT
274  *   Attempt to enable all-multicast mode failed because of timeout.
275  * @retval -EAGAIN
276  *   Failed to enable all-multicast mode.
277  */
278 typedef int (*eth_allmulticast_enable_t)(struct rte_eth_dev *dev);
279
280 /**
281  * @internal
282  * Disable the receipt of all multicast packets by an Ethernet device.
283  *
284  * @param dev
285  *   ethdev handle of port.
286  *
287  * @return
288  *   Negative errno value on error, 0 on success.
289  *
290  * @retval 0
291  *   Success, all-multicast mode is disabled.
292  * @retval -ENOTSUP
293  *   All-multicast mode disabling is not supported.
294  * @retval -ENODEV
295  *   Device is gone.
296  * @retval -E_RTE_SECONDARY
297  *   Function was called from a secondary process instance and not supported.
298  * @retval -ETIMEDOUT
299  *   Attempt to disable all-multicast mode failed because of timeout.
300  * @retval -EAGAIN
301  *   Failed to disable all-multicast mode.
302  */
303 typedef int (*eth_allmulticast_disable_t)(struct rte_eth_dev *dev);
304
305 /**
306  * @internal
307  * Get link speed, duplex mode and state (up/down) of an Ethernet device.
308  */
309 typedef int (*eth_link_update_t)(struct rte_eth_dev *dev,
310                                 int wait_to_complete);
311
312 /** @internal Get global I/O statistics of an Ethernet device. */
313 typedef int (*eth_stats_get_t)(struct rte_eth_dev *dev,
314                                 struct rte_eth_stats *igb_stats);
315
316 /**
317  * @internal
318  * Reset global I/O statistics of an Ethernet device to 0.
319  *
320  * @param dev
321  *   ethdev handle of port.
322  *
323  * @return
324  *   Negative errno value on error, 0 on success.
325  *
326  * @retval 0
327  *   Success, statistics has been reset.
328  * @retval -ENOTSUP
329  *   Resetting statistics is not supported.
330  * @retval -EINVAL
331  *   Resetting statistics is not valid.
332  * @retval -ENOMEM
333  *   Not enough memory to get the stats.
334  */
335 typedef int (*eth_stats_reset_t)(struct rte_eth_dev *dev);
336
337 /** @internal Get extended stats of an Ethernet device. */
338 typedef int (*eth_xstats_get_t)(struct rte_eth_dev *dev,
339         struct rte_eth_xstat *stats, unsigned int n);
340
341 /**
342  * @internal
343  * Get extended stats of an Ethernet device.
344  *
345  * @param dev
346  *   ethdev handle of port.
347  * @param ids
348  *   IDs array to retrieve specific statistics. Must not be NULL.
349  * @param values
350  *   A pointer to a table to be filled with device statistics values.
351  *   Must not be NULL.
352  * @param n
353  *   Element count in @p ids and @p values.
354  *
355  * @return
356  *   - A number of filled in stats.
357  *   - A negative value on error.
358  */
359 typedef int (*eth_xstats_get_by_id_t)(struct rte_eth_dev *dev,
360                                       const uint64_t *ids,
361                                       uint64_t *values,
362                                       unsigned int n);
363
364 /**
365  * @internal
366  * Reset extended stats of an Ethernet device.
367  *
368  * @param dev
369  *   ethdev handle of port.
370  *
371  * @return
372  *   Negative errno value on error, 0 on success.
373  *
374  * @retval 0
375  *   Success, statistics has been reset.
376  * @retval -ENOTSUP
377  *   Resetting statistics is not supported.
378  * @retval -EINVAL
379  *   Resetting statistics is not valid.
380  * @retval -ENOMEM
381  *   Not enough memory to get the stats.
382  */
383 typedef int (*eth_xstats_reset_t)(struct rte_eth_dev *dev);
384
385 /** @internal Get names of extended stats of an Ethernet device. */
386 typedef int (*eth_xstats_get_names_t)(struct rte_eth_dev *dev,
387         struct rte_eth_xstat_name *xstats_names, unsigned int size);
388
389 /**
390  * @internal
391  * Get names of extended stats of an Ethernet device.
392  *
393  * @param dev
394  *   ethdev handle of port.
395  * @param ids
396  *   IDs array to retrieve specific statistics. Must not be NULL.
397  * @param xstats_names
398  *   An rte_eth_xstat_name array of at least @p size elements to be filled.
399  *   Must not be NULL.
400  * @param size
401  *   Element count in @p ids and @p xstats_names.
402  *
403  * @return
404  *   - A number of filled in stats.
405  *   - A negative value on error.
406  */
407 typedef int (*eth_xstats_get_names_by_id_t)(struct rte_eth_dev *dev,
408         const uint64_t *ids, struct rte_eth_xstat_name *xstats_names,
409         unsigned int size);
410
411 /**
412  * @internal
413  * Set a queue statistics mapping for a Tx/Rx queue of an Ethernet device.
414  */
415 typedef int (*eth_queue_stats_mapping_set_t)(struct rte_eth_dev *dev,
416                                              uint16_t queue_id,
417                                              uint8_t stat_idx,
418                                              uint8_t is_rx);
419
420 /** @internal Get specific information of an Ethernet device. */
421 typedef int (*eth_dev_infos_get_t)(struct rte_eth_dev *dev,
422                                    struct rte_eth_dev_info *dev_info);
423
424 /** @internal Get supported ptypes of an Ethernet device. */
425 typedef const uint32_t *(*eth_dev_supported_ptypes_get_t)(struct rte_eth_dev *dev);
426
427 /**
428  * @internal
429  * Inform Ethernet device about reduced range of packet types to handle.
430  *
431  * @param dev
432  *   The Ethernet device identifier.
433  * @param ptype_mask
434  *   The ptype family that application is interested in should be bitwise OR of
435  *   RTE_PTYPE_*_MASK or 0.
436  * @return
437  *   - (0) if Success.
438  */
439 typedef int (*eth_dev_ptypes_set_t)(struct rte_eth_dev *dev,
440                                      uint32_t ptype_mask);
441
442 /** @internal Start Rx and Tx of a queue of an Ethernet device. */
443 typedef int (*eth_queue_start_t)(struct rte_eth_dev *dev,
444                                     uint16_t queue_id);
445
446 /** @internal Stop Rx and Tx of a queue of an Ethernet device. */
447 typedef int (*eth_queue_stop_t)(struct rte_eth_dev *dev,
448                                     uint16_t queue_id);
449
450 /** @internal Set up a receive queue of an Ethernet device. */
451 typedef int (*eth_rx_queue_setup_t)(struct rte_eth_dev *dev,
452                                     uint16_t rx_queue_id,
453                                     uint16_t nb_rx_desc,
454                                     unsigned int socket_id,
455                                     const struct rte_eth_rxconf *rx_conf,
456                                     struct rte_mempool *mb_pool);
457
458 /** @internal Setup a transmit queue of an Ethernet device. */
459 typedef int (*eth_tx_queue_setup_t)(struct rte_eth_dev *dev,
460                                     uint16_t tx_queue_id,
461                                     uint16_t nb_tx_desc,
462                                     unsigned int socket_id,
463                                     const struct rte_eth_txconf *tx_conf);
464
465 /** @internal Enable interrupt of a receive queue of an Ethernet device. */
466 typedef int (*eth_rx_enable_intr_t)(struct rte_eth_dev *dev,
467                                     uint16_t rx_queue_id);
468
469 /** @internal Disable interrupt of a receive queue of an Ethernet device. */
470 typedef int (*eth_rx_disable_intr_t)(struct rte_eth_dev *dev,
471                                     uint16_t rx_queue_id);
472
473 /** @internal Release memory resources allocated by given Rx/Tx queue. */
474 typedef void (*eth_queue_release_t)(struct rte_eth_dev *dev,
475                                     uint16_t queue_id);
476
477 /** @internal Get firmware information of an Ethernet device. */
478 typedef int (*eth_fw_version_get_t)(struct rte_eth_dev *dev,
479                                      char *fw_version, size_t fw_size);
480
481 /** @internal Force mbufs to be from Tx ring. */
482 typedef int (*eth_tx_done_cleanup_t)(void *txq, uint32_t free_cnt);
483
484 typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,
485         uint16_t rx_queue_id, struct rte_eth_rxq_info *qinfo);
486
487 typedef void (*eth_txq_info_get_t)(struct rte_eth_dev *dev,
488         uint16_t tx_queue_id, struct rte_eth_txq_info *qinfo);
489
490 typedef int (*eth_burst_mode_get_t)(struct rte_eth_dev *dev,
491         uint16_t queue_id, struct rte_eth_burst_mode *mode);
492
493 /** @internal Set MTU. */
494 typedef int (*mtu_set_t)(struct rte_eth_dev *dev, uint16_t mtu);
495
496 /** @internal Filtering of a VLAN Tag Identifier by an Ethernet device. */
497 typedef int (*vlan_filter_set_t)(struct rte_eth_dev *dev,
498                                   uint16_t vlan_id,
499                                   int on);
500
501 /** @internal Set the outer/inner VLAN-TPID by an Ethernet device. */
502 typedef int (*vlan_tpid_set_t)(struct rte_eth_dev *dev,
503                                enum rte_vlan_type type, uint16_t tpid);
504
505 /** @internal Set VLAN offload function by an Ethernet device. */
506 typedef int (*vlan_offload_set_t)(struct rte_eth_dev *dev, int mask);
507
508 /** @internal Set port based Tx VLAN insertion by an Ethernet device. */
509 typedef int (*vlan_pvid_set_t)(struct rte_eth_dev *dev,
510                                uint16_t vlan_id,
511                                int on);
512
513 /** @internal VLAN stripping enable/disable by an queue of Ethernet device. */
514 typedef void (*vlan_strip_queue_set_t)(struct rte_eth_dev *dev,
515                                   uint16_t rx_queue_id,
516                                   int on);
517
518 /** @internal Get current flow control parameter on an Ethernet device. */
519 typedef int (*flow_ctrl_get_t)(struct rte_eth_dev *dev,
520                                struct rte_eth_fc_conf *fc_conf);
521
522 /** @internal Setup flow control parameter on an Ethernet device. */
523 typedef int (*flow_ctrl_set_t)(struct rte_eth_dev *dev,
524                                struct rte_eth_fc_conf *fc_conf);
525
526 /** @internal Setup priority flow control parameter on an Ethernet device. */
527 typedef int (*priority_flow_ctrl_set_t)(struct rte_eth_dev *dev,
528                                 struct rte_eth_pfc_conf *pfc_conf);
529
530 /** @internal Update RSS redirection table on an Ethernet device. */
531 typedef int (*reta_update_t)(struct rte_eth_dev *dev,
532                              struct rte_eth_rss_reta_entry64 *reta_conf,
533                              uint16_t reta_size);
534
535 /** @internal Query RSS redirection table on an Ethernet device. */
536 typedef int (*reta_query_t)(struct rte_eth_dev *dev,
537                             struct rte_eth_rss_reta_entry64 *reta_conf,
538                             uint16_t reta_size);
539
540 /** @internal Update RSS hash configuration of an Ethernet device. */
541 typedef int (*rss_hash_update_t)(struct rte_eth_dev *dev,
542                                  struct rte_eth_rss_conf *rss_conf);
543
544 /** @internal Get current RSS hash configuration of an Ethernet device. */
545 typedef int (*rss_hash_conf_get_t)(struct rte_eth_dev *dev,
546                                    struct rte_eth_rss_conf *rss_conf);
547
548 /** @internal Turn on SW controllable LED on an Ethernet device. */
549 typedef int (*eth_dev_led_on_t)(struct rte_eth_dev *dev);
550
551 /** @internal Turn off SW controllable LED on an Ethernet device. */
552 typedef int (*eth_dev_led_off_t)(struct rte_eth_dev *dev);
553
554 /** @internal Remove MAC address from receive address register. */
555 typedef void (*eth_mac_addr_remove_t)(struct rte_eth_dev *dev, uint32_t index);
556
557 /** @internal Set a MAC address into Receive Address Register. */
558 typedef int (*eth_mac_addr_add_t)(struct rte_eth_dev *dev,
559                                   struct rte_ether_addr *mac_addr,
560                                   uint32_t index,
561                                   uint32_t vmdq);
562
563 /** @internal Set a MAC address into Receive Address Register. */
564 typedef int (*eth_mac_addr_set_t)(struct rte_eth_dev *dev,
565                                   struct rte_ether_addr *mac_addr);
566
567 /** @internal Set a Unicast Hash bitmap. */
568 typedef int (*eth_uc_hash_table_set_t)(struct rte_eth_dev *dev,
569                                   struct rte_ether_addr *mac_addr,
570                                   uint8_t on);
571
572 /** @internal Set all Unicast Hash bitmap. */
573 typedef int (*eth_uc_all_hash_table_set_t)(struct rte_eth_dev *dev,
574                                   uint8_t on);
575
576 /** @internal Set queue Tx rate. */
577 typedef int (*eth_set_queue_rate_limit_t)(struct rte_eth_dev *dev,
578                                 uint16_t queue_idx,
579                                 uint16_t tx_rate);
580
581 /** @internal Add tunneling UDP port. */
582 typedef int (*eth_udp_tunnel_port_add_t)(struct rte_eth_dev *dev,
583                                          struct rte_eth_udp_tunnel *tunnel_udp);
584
585 /** @internal Delete tunneling UDP port. */
586 typedef int (*eth_udp_tunnel_port_del_t)(struct rte_eth_dev *dev,
587                                          struct rte_eth_udp_tunnel *tunnel_udp);
588
589 /** @internal set the list of multicast addresses on an Ethernet device. */
590 typedef int (*eth_set_mc_addr_list_t)(struct rte_eth_dev *dev,
591                                       struct rte_ether_addr *mc_addr_set,
592                                       uint32_t nb_mc_addr);
593
594 /** @internal Function used to enable IEEE1588/802.1AS timestamping. */
595 typedef int (*eth_timesync_enable_t)(struct rte_eth_dev *dev);
596
597 /** @internal Function used to disable IEEE1588/802.1AS timestamping. */
598 typedef int (*eth_timesync_disable_t)(struct rte_eth_dev *dev);
599
600 /** @internal Function used to read an Rx IEEE1588/802.1AS timestamp. */
601 typedef int (*eth_timesync_read_rx_timestamp_t)(struct rte_eth_dev *dev,
602                                                 struct timespec *timestamp,
603                                                 uint32_t flags);
604
605 /** @internal Function used to read a Tx IEEE1588/802.1AS timestamp. */
606 typedef int (*eth_timesync_read_tx_timestamp_t)(struct rte_eth_dev *dev,
607                                                 struct timespec *timestamp);
608
609 /** @internal Function used to adjust the device clock. */
610 typedef int (*eth_timesync_adjust_time)(struct rte_eth_dev *dev, int64_t);
611
612 /** @internal Function used to get time from the device clock. */
613 typedef int (*eth_timesync_read_time)(struct rte_eth_dev *dev,
614                                       struct timespec *timestamp);
615
616 /** @internal Function used to get time from the device clock. */
617 typedef int (*eth_timesync_write_time)(struct rte_eth_dev *dev,
618                                        const struct timespec *timestamp);
619
620 /** @internal Function used to get the current value of the device clock. */
621 typedef int (*eth_read_clock)(struct rte_eth_dev *dev,
622                                       uint64_t *timestamp);
623
624 /** @internal Retrieve registers. */
625 typedef int (*eth_get_reg_t)(struct rte_eth_dev *dev,
626                                 struct rte_dev_reg_info *info);
627
628 /** @internal Retrieve eeprom size. */
629 typedef int (*eth_get_eeprom_length_t)(struct rte_eth_dev *dev);
630
631 /** @internal Retrieve eeprom data. */
632 typedef int (*eth_get_eeprom_t)(struct rte_eth_dev *dev,
633                                 struct rte_dev_eeprom_info *info);
634
635 /** @internal Program eeprom data. */
636 typedef int (*eth_set_eeprom_t)(struct rte_eth_dev *dev,
637                                 struct rte_dev_eeprom_info *info);
638
639 /** @internal Retrieve type and size of plugin module eeprom. */
640 typedef int (*eth_get_module_info_t)(struct rte_eth_dev *dev,
641                                      struct rte_eth_dev_module_info *modinfo);
642
643 /** @internal Retrieve plugin module eeprom data. */
644 typedef int (*eth_get_module_eeprom_t)(struct rte_eth_dev *dev,
645                                        struct rte_dev_eeprom_info *info);
646
647 struct rte_flow_ops;
648 /**
649  * @internal
650  * Get flow operations.
651  *
652  * If the flow API is not supported for the specified device,
653  * the driver can return NULL.
654  */
655 typedef int (*eth_flow_ops_get_t)(struct rte_eth_dev *dev,
656                                   const struct rte_flow_ops **ops);
657
658 /** @internal Get Traffic Management (TM) operations on an Ethernet device. */
659 typedef int (*eth_tm_ops_get_t)(struct rte_eth_dev *dev, void *ops);
660
661 /** @internal Get Traffic Metering and Policing (MTR) operations. */
662 typedef int (*eth_mtr_ops_get_t)(struct rte_eth_dev *dev, void *ops);
663
664 /** @internal Get dcb information on an Ethernet device. */
665 typedef int (*eth_get_dcb_info)(struct rte_eth_dev *dev,
666                                  struct rte_eth_dcb_info *dcb_info);
667
668 /** @internal Test if a port supports specific mempool ops. */
669 typedef int (*eth_pool_ops_supported_t)(struct rte_eth_dev *dev,
670                                                 const char *pool);
671
672 /**
673  * @internal
674  * Get the hairpin capabilities.
675  *
676  * @param dev
677  *   ethdev handle of port.
678  * @param cap
679  *   returns the hairpin capabilities from the device.
680  *
681  * @return
682  *   Negative errno value on error, 0 on success.
683  *
684  * @retval 0
685  *   Success, hairpin is supported.
686  * @retval -ENOTSUP
687  *   Hairpin is not supported.
688  */
689 typedef int (*eth_hairpin_cap_get_t)(struct rte_eth_dev *dev,
690                                      struct rte_eth_hairpin_cap *cap);
691
692 /**
693  * @internal
694  * Setup Rx hairpin queue.
695  *
696  * @param dev
697  *   ethdev handle of port.
698  * @param rx_queue_id
699  *   the selected Rx queue index.
700  * @param nb_rx_desc
701  *   the requested number of descriptors for this queue. 0 - use PMD default.
702  * @param conf
703  *   the Rx hairpin configuration structure.
704  *
705  * @return
706  *   Negative errno value on error, 0 on success.
707  *
708  * @retval 0
709  *   Success, hairpin is supported.
710  * @retval -ENOTSUP
711  *   Hairpin is not supported.
712  * @retval -EINVAL
713  *   One of the parameters is invalid.
714  * @retval -ENOMEM
715  *   Unable to allocate resources.
716  */
717 typedef int (*eth_rx_hairpin_queue_setup_t)
718         (struct rte_eth_dev *dev, uint16_t rx_queue_id,
719          uint16_t nb_rx_desc,
720          const struct rte_eth_hairpin_conf *conf);
721
722 /**
723  * @internal
724  * Setup Tx hairpin queue.
725  *
726  * @param dev
727  *   ethdev handle of port.
728  * @param tx_queue_id
729  *   the selected Tx queue index.
730  * @param nb_tx_desc
731  *   the requested number of descriptors for this queue. 0 - use PMD default.
732  * @param conf
733  *   the Tx hairpin configuration structure.
734  *
735  * @return
736  *   Negative errno value on error, 0 on success.
737  *
738  * @retval 0
739  *   Success, hairpin is supported.
740  * @retval -ENOTSUP
741  *   Hairpin is not supported.
742  * @retval -EINVAL
743  *   One of the parameters is invalid.
744  * @retval -ENOMEM
745  *   Unable to allocate resources.
746  */
747 typedef int (*eth_tx_hairpin_queue_setup_t)
748         (struct rte_eth_dev *dev, uint16_t tx_queue_id,
749          uint16_t nb_tx_desc,
750          const struct rte_eth_hairpin_conf *hairpin_conf);
751
752 /**
753  * @internal
754  * Get Forward Error Correction(FEC) capability.
755  *
756  * @param dev
757  *   ethdev handle of port.
758  * @param speed_fec_capa
759  *   speed_fec_capa is out only with per-speed capabilities.
760  * @param num
761  *   a number of elements in an speed_fec_capa array.
762  *
763  * @return
764  *   Negative errno value on error, positive value on success.
765  *
766  * @retval positive value
767  *   A non-negative value lower or equal to num: success. The return value
768  *   is the number of entries filled in the fec capa array.
769  *   A non-negative value higher than num: error, the given fec capa array
770  *   is too small. The return value corresponds to the num that should
771  *   be given to succeed. The entries in the fec capa array are not valid
772  *   and shall not be used by the caller.
773  * @retval -ENOTSUP
774  *   Operation is not supported.
775  * @retval -EIO
776  *   Device is removed.
777  * @retval -EINVAL
778  *   *num* or *speed_fec_capa* invalid.
779  */
780 typedef int (*eth_fec_get_capability_t)(struct rte_eth_dev *dev,
781                 struct rte_eth_fec_capa *speed_fec_capa, unsigned int num);
782
783 /**
784  * @internal
785  * Get Forward Error Correction(FEC) mode.
786  *
787  * @param dev
788  *   ethdev handle of port.
789  * @param fec_capa
790  *   a bitmask of enabled FEC modes. If AUTO bit is set, other
791  *   bits specify FEC modes which may be negotiated. If AUTO
792  *   bit is clear, specify FEC modes to be used (only one valid
793  *   mode per speed may be set).
794  *
795  * @return
796  *   Negative errno value on error, 0 on success.
797  *
798  * @retval 0
799  *   Success, get FEC success.
800  * @retval -ENOTSUP
801  *   Operation is not supported.
802  * @retval -EIO
803  *   Device is removed.
804  */
805 typedef int (*eth_fec_get_t)(struct rte_eth_dev *dev,
806                              uint32_t *fec_capa);
807
808 /**
809  * @internal
810  * Set Forward Error Correction(FEC) mode.
811  *
812  * @param dev
813  *   ethdev handle of port.
814  * @param fec_capa
815  *   bitmask of allowed FEC modes. It must be only one
816  *   if AUTO is disabled. If AUTO is enabled, other
817  *   bits specify FEC modes which may be negotiated.
818  *
819  * @return
820  *   Negative errno value on error, 0 on success.
821  *
822  * @retval 0
823  *   Success, set FEC success.
824  * @retval -ENOTSUP
825  *   Operation is not supported.
826  * @retval -EINVAL
827  *   Unsupported FEC mode requested.
828  * @retval -EIO
829  *   Device is removed.
830  */
831 typedef int (*eth_fec_set_t)(struct rte_eth_dev *dev, uint32_t fec_capa);
832
833 /**
834  * @internal
835  * Get all hairpin Tx/Rx peer ports of the current device, if any.
836  *
837  * @param dev
838  *   ethdev handle of port.
839  * @param peer_ports
840  *   array to save the ports list.
841  * @param len
842  *   array length.
843  * @param direction
844  *   value to decide the current to peer direction
845  *   positive - used as Tx to get all peer Rx ports.
846  *   zero - used as Rx to get all peer Tx ports.
847  *
848  * @return
849  *   Negative errno value on error, 0 or positive on success.
850  *
851  * @retval 0
852  *   Success, no peer ports.
853  * @retval >0
854  *   Actual number of the peer ports.
855  * @retval -ENOTSUP
856  *   Get peer ports API is not supported.
857  * @retval -EINVAL
858  *   One of the parameters is invalid.
859  */
860 typedef int (*hairpin_get_peer_ports_t)(struct rte_eth_dev *dev,
861                                         uint16_t *peer_ports, size_t len,
862                                         uint32_t direction);
863
864 /**
865  * @internal
866  * Bind all hairpin Tx queues of one port to the Rx queues of the peer port.
867  *
868  * @param dev
869  *   ethdev handle of port.
870  * @param rx_port
871  *   the peer Rx port.
872  *
873  * @return
874  *   Negative errno value on error, 0 on success.
875  *
876  * @retval 0
877  *   Success, bind successfully.
878  * @retval -ENOTSUP
879  *   Bind API is not supported.
880  * @retval -EINVAL
881  *   One of the parameters is invalid.
882  * @retval -EBUSY
883  *   Device is not started.
884  */
885 typedef int (*eth_hairpin_bind_t)(struct rte_eth_dev *dev,
886                                 uint16_t rx_port);
887
888 /**
889  * @internal
890  * Unbind all hairpin Tx queues of one port from the Rx queues of the peer port.
891  *
892  * @param dev
893  *   ethdev handle of port.
894  * @param rx_port
895  *   the peer Rx port.
896  *
897  * @return
898  *   Negative errno value on error, 0 on success.
899  *
900  * @retval 0
901  *   Success, unbind successfully.
902  * @retval -ENOTSUP
903  *   Bind API is not supported.
904  * @retval -EINVAL
905  *   One of the parameters is invalid.
906  * @retval -EBUSY
907  *   Device is already stopped.
908  */
909 typedef int (*eth_hairpin_unbind_t)(struct rte_eth_dev *dev,
910                                   uint16_t rx_port);
911
912 /** @internal Update and fetch peer queue information. */
913 typedef int (*eth_hairpin_queue_peer_update_t)
914         (struct rte_eth_dev *dev, uint16_t peer_queue,
915          struct rte_hairpin_peer_info *current_info,
916          struct rte_hairpin_peer_info *peer_info, uint32_t direction);
917
918 /** @internal Bind peer queue to the current queue with fetched information. */
919 typedef int (*eth_hairpin_queue_peer_bind_t)
920         (struct rte_eth_dev *dev, uint16_t cur_queue,
921          struct rte_hairpin_peer_info *peer_info, uint32_t direction);
922
923 /** @internal Unbind peer queue from the current queue. */
924 typedef int (*eth_hairpin_queue_peer_unbind_t)
925         (struct rte_eth_dev *dev, uint16_t cur_queue, uint32_t direction);
926
927 /**
928  * @internal
929  * Get address of memory location whose contents will change whenever there is
930  * new data to be received on an Rx queue.
931  *
932  * @param rxq
933  *   Ethdev queue pointer.
934  * @param pmc
935  *   The pointer to power-optimized monitoring condition structure.
936  * @return
937  *   Negative errno value on error, 0 on success.
938  *
939  * @retval 0
940  *   Success
941  * @retval -EINVAL
942  *   Invalid parameters
943  */
944 typedef int (*eth_get_monitor_addr_t)(void *rxq,
945                 struct rte_power_monitor_cond *pmc);
946
947 /**
948  * @internal
949  * Get representor info to be able to calculate the unique representor ID.
950  *
951  * Caller should pass NULL as pointer of info to get number of entries,
952  * allocate info buffer according to returned entry number, then call
953  * again with buffer to get real info.
954  *
955  * To calculate the representor ID, caller should iterate each entry,
956  * match controller index, pf index, vf or sf start index and range,
957  * then calculate representor ID from offset to vf/sf start index.
958  * @see rte_eth_representor_id_get.
959  *
960  * @param dev
961  *   Ethdev handle of port.
962  * @param [out] info
963  *   Pointer to memory to save device representor info.
964  * @return
965  *   Negative errno value on error, number of info entries otherwise.
966  */
967
968 typedef int (*eth_representor_info_get_t)(struct rte_eth_dev *dev,
969         struct rte_eth_representor_info *info);
970
971 /**
972  * @internal
973  * Negotiate the NIC's ability to deliver specific kinds of metadata to the PMD.
974  *
975  * @param dev
976  *   Port (ethdev) handle
977  *
978  * @param[inout] features
979  *   Feature selection buffer
980  *
981  * @return
982  *   Negative errno value on error, zero otherwise
983  */
984 typedef int (*eth_rx_metadata_negotiate_t)(struct rte_eth_dev *dev,
985                                        uint64_t *features);
986
987 /**
988  * @internal A structure containing the functions exported by an Ethernet driver.
989  */
990 struct eth_dev_ops {
991         eth_dev_configure_t        dev_configure; /**< Configure device. */
992         eth_dev_start_t            dev_start;     /**< Start device. */
993         eth_dev_stop_t             dev_stop;      /**< Stop device. */
994         eth_dev_set_link_up_t      dev_set_link_up;   /**< Device link up. */
995         eth_dev_set_link_down_t    dev_set_link_down; /**< Device link down. */
996         eth_dev_close_t            dev_close;     /**< Close device. */
997         eth_dev_reset_t            dev_reset;     /**< Reset device. */
998         eth_link_update_t          link_update;   /**< Get device link state. */
999         /** Check if the device was physically removed */
1000         eth_is_removed_t           is_removed;
1001
1002         eth_promiscuous_enable_t   promiscuous_enable; /**< Promiscuous ON. */
1003         eth_promiscuous_disable_t  promiscuous_disable;/**< Promiscuous OFF. */
1004         eth_allmulticast_enable_t  allmulticast_enable;/**< Rx multicast ON. */
1005         eth_allmulticast_disable_t allmulticast_disable;/**< Rx multicast OFF. */
1006         eth_mac_addr_remove_t      mac_addr_remove; /**< Remove MAC address. */
1007         eth_mac_addr_add_t         mac_addr_add;  /**< Add a MAC address. */
1008         eth_mac_addr_set_t         mac_addr_set;  /**< Set a MAC address. */
1009         /** Set list of multicast addresses */
1010         eth_set_mc_addr_list_t     set_mc_addr_list;
1011         mtu_set_t                  mtu_set;       /**< Set MTU. */
1012
1013         /** Get generic device statistics */
1014         eth_stats_get_t            stats_get;
1015         /** Reset generic device statistics */
1016         eth_stats_reset_t          stats_reset;
1017         /** Get extended device statistics */
1018         eth_xstats_get_t           xstats_get;
1019         /** Reset extended device statistics */
1020         eth_xstats_reset_t         xstats_reset;
1021         /** Get names of extended statistics */
1022         eth_xstats_get_names_t     xstats_get_names;
1023         /** Configure per queue stat counter mapping */
1024         eth_queue_stats_mapping_set_t queue_stats_mapping_set;
1025
1026         eth_dev_infos_get_t        dev_infos_get; /**< Get device info. */
1027         /** Retrieve Rx queue information */
1028         eth_rxq_info_get_t         rxq_info_get;
1029         /** Retrieve Tx queue information */
1030         eth_txq_info_get_t         txq_info_get;
1031         eth_burst_mode_get_t       rx_burst_mode_get; /**< Get Rx burst mode */
1032         eth_burst_mode_get_t       tx_burst_mode_get; /**< Get Tx burst mode */
1033         eth_fw_version_get_t       fw_version_get; /**< Get firmware version. */
1034
1035         /** Get packet types supported and identified by device */
1036         eth_dev_supported_ptypes_get_t dev_supported_ptypes_get;
1037         /**
1038          * Inform Ethernet device about reduced range of packet types to
1039          * handle
1040          */
1041         eth_dev_ptypes_set_t dev_ptypes_set;
1042
1043         /** Filter VLAN Setup */
1044         vlan_filter_set_t          vlan_filter_set;
1045         /** Outer/Inner VLAN TPID Setup */
1046         vlan_tpid_set_t            vlan_tpid_set;
1047         /** VLAN Stripping on queue */
1048         vlan_strip_queue_set_t     vlan_strip_queue_set;
1049         /** Set VLAN Offload */
1050         vlan_offload_set_t         vlan_offload_set;
1051         /** Set port based Tx VLAN insertion */
1052         vlan_pvid_set_t            vlan_pvid_set;
1053
1054         eth_queue_start_t          rx_queue_start;/**< Start Rx for a queue. */
1055         eth_queue_stop_t           rx_queue_stop; /**< Stop Rx for a queue. */
1056         eth_queue_start_t          tx_queue_start;/**< Start Tx for a queue. */
1057         eth_queue_stop_t           tx_queue_stop; /**< Stop Tx for a queue. */
1058         eth_rx_queue_setup_t       rx_queue_setup;/**< Set up device Rx queue. */
1059         eth_queue_release_t        rx_queue_release; /**< Release Rx queue. */
1060
1061         /** Enable Rx queue interrupt */
1062         eth_rx_enable_intr_t       rx_queue_intr_enable;
1063         /** Disable Rx queue interrupt */
1064         eth_rx_disable_intr_t      rx_queue_intr_disable;
1065
1066         eth_tx_queue_setup_t       tx_queue_setup;/**< Set up device Tx queue */
1067         eth_queue_release_t        tx_queue_release; /**< Release Tx queue */
1068         eth_tx_done_cleanup_t      tx_done_cleanup;/**< Free Tx ring mbufs */
1069
1070         eth_dev_led_on_t           dev_led_on;    /**< Turn on LED. */
1071         eth_dev_led_off_t          dev_led_off;   /**< Turn off LED. */
1072
1073         flow_ctrl_get_t            flow_ctrl_get; /**< Get flow control. */
1074         flow_ctrl_set_t            flow_ctrl_set; /**< Setup flow control. */
1075         /** Setup priority flow control */
1076         priority_flow_ctrl_set_t   priority_flow_ctrl_set;
1077
1078         /** Set Unicast Table Array */
1079         eth_uc_hash_table_set_t    uc_hash_table_set;
1080         /** Set Unicast hash bitmap */
1081         eth_uc_all_hash_table_set_t uc_all_hash_table_set;
1082
1083         /** Add UDP tunnel port */
1084         eth_udp_tunnel_port_add_t  udp_tunnel_port_add;
1085         /** Delete UDP tunnel port */
1086         eth_udp_tunnel_port_del_t  udp_tunnel_port_del;
1087
1088         /** Set queue rate limit */
1089         eth_set_queue_rate_limit_t set_queue_rate_limit;
1090
1091         /** Configure RSS hash protocols and hashing key */
1092         rss_hash_update_t          rss_hash_update;
1093         /** Get current RSS hash configuration */
1094         rss_hash_conf_get_t        rss_hash_conf_get;
1095         /** Update redirection table */
1096         reta_update_t              reta_update;
1097         /** Query redirection table */
1098         reta_query_t               reta_query;
1099
1100         eth_get_reg_t              get_reg;           /**< Get registers. */
1101         eth_get_eeprom_length_t    get_eeprom_length; /**< Get eeprom length. */
1102         eth_get_eeprom_t           get_eeprom;        /**< Get eeprom data. */
1103         eth_set_eeprom_t           set_eeprom;        /**< Set eeprom. */
1104
1105         /** Get plugin module eeprom attribute */
1106         eth_get_module_info_t      get_module_info;
1107         /** Get plugin module eeprom data */
1108         eth_get_module_eeprom_t    get_module_eeprom;
1109
1110         eth_flow_ops_get_t         flow_ops_get; /**< Get flow operations. */
1111
1112         eth_get_dcb_info           get_dcb_info; /**< Get DCB information */
1113
1114         /** Turn IEEE1588/802.1AS timestamping on */
1115         eth_timesync_enable_t      timesync_enable;
1116         /** Turn IEEE1588/802.1AS timestamping off */
1117         eth_timesync_disable_t     timesync_disable;
1118         /** Read the IEEE1588/802.1AS Rx timestamp */
1119         eth_timesync_read_rx_timestamp_t timesync_read_rx_timestamp;
1120         /** Read the IEEE1588/802.1AS Tx timestamp */
1121         eth_timesync_read_tx_timestamp_t timesync_read_tx_timestamp;
1122         /** Adjust the device clock */
1123         eth_timesync_adjust_time   timesync_adjust_time;
1124         /** Get the device clock time */
1125         eth_timesync_read_time     timesync_read_time;
1126         /** Set the device clock time */
1127         eth_timesync_write_time    timesync_write_time;
1128
1129         eth_read_clock             read_clock;
1130
1131         /** Get extended device statistic values by ID */
1132         eth_xstats_get_by_id_t     xstats_get_by_id;
1133         /** Get name of extended device statistics by ID */
1134         eth_xstats_get_names_by_id_t xstats_get_names_by_id;
1135
1136         /** Get Traffic Management (TM) operations */
1137         eth_tm_ops_get_t tm_ops_get;
1138
1139         /** Get Traffic Metering and Policing (MTR) operations */
1140         eth_mtr_ops_get_t mtr_ops_get;
1141
1142         /** Test if a port supports specific mempool ops */
1143         eth_pool_ops_supported_t pool_ops_supported;
1144
1145         /** Returns the hairpin capabilities */
1146         eth_hairpin_cap_get_t hairpin_cap_get;
1147         /** Set up device Rx hairpin queue */
1148         eth_rx_hairpin_queue_setup_t rx_hairpin_queue_setup;
1149         /** Set up device Tx hairpin queue */
1150         eth_tx_hairpin_queue_setup_t tx_hairpin_queue_setup;
1151
1152         /** Get Forward Error Correction(FEC) capability */
1153         eth_fec_get_capability_t fec_get_capability;
1154         /** Get Forward Error Correction(FEC) mode */
1155         eth_fec_get_t fec_get;
1156         /** Set Forward Error Correction(FEC) mode */
1157         eth_fec_set_t fec_set;
1158
1159         /** Get hairpin peer ports list */
1160         hairpin_get_peer_ports_t hairpin_get_peer_ports;
1161         /** Bind all hairpin Tx queues of device to the peer port Rx queues */
1162         eth_hairpin_bind_t hairpin_bind;
1163         /** Unbind all hairpin Tx queues from the peer port Rx queues */
1164         eth_hairpin_unbind_t hairpin_unbind;
1165         /** Pass the current queue info and get the peer queue info */
1166         eth_hairpin_queue_peer_update_t hairpin_queue_peer_update;
1167         /** Set up the connection between the pair of hairpin queues */
1168         eth_hairpin_queue_peer_bind_t hairpin_queue_peer_bind;
1169         /** Disconnect the hairpin queues of a pair from each other */
1170         eth_hairpin_queue_peer_unbind_t hairpin_queue_peer_unbind;
1171
1172         /** Get power monitoring condition for Rx queue */
1173         eth_get_monitor_addr_t get_monitor_addr;
1174
1175         /** Get representor info */
1176         eth_representor_info_get_t representor_info_get;
1177
1178         /**
1179          * Negotiate the NIC's ability to deliver specific
1180          * kinds of metadata to the PMD.
1181          */
1182         eth_rx_metadata_negotiate_t rx_metadata_negotiate;
1183 };
1184
1185 /**
1186  * @internal
1187  * Check if the selected Rx queue is hairpin queue.
1188  *
1189  * @param dev
1190  *  Pointer to the selected device.
1191  * @param queue_id
1192  *  The selected queue.
1193  *
1194  * @return
1195  *   - (1) if the queue is hairpin queue, 0 otherwise.
1196  */
1197 __rte_internal
1198 int rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id);
1199
1200 /**
1201  * @internal
1202  * Check if the selected Tx queue is hairpin queue.
1203  *
1204  * @param dev
1205  *  Pointer to the selected device.
1206  * @param queue_id
1207  *  The selected queue.
1208  *
1209  * @return
1210  *   - (1) if the queue is hairpin queue, 0 otherwise.
1211  */
1212 __rte_internal
1213 int rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id);
1214
1215 /**
1216  * @internal
1217  * Returns a ethdev slot specified by the unique identifier name.
1218  *
1219  * @param       name
1220  *  The pointer to the Unique identifier name for each Ethernet device
1221  * @return
1222  *   - The pointer to the ethdev slot, on success. NULL on error
1223  */
1224 __rte_internal
1225 struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
1226
1227 /**
1228  * @internal
1229  * Allocates a new ethdev slot for an Ethernet device and returns the pointer
1230  * to that slot for the driver to use.
1231  *
1232  * @param       name    Unique identifier name for each Ethernet device
1233  * @return
1234  *   - Slot in the rte_dev_devices array for a new device;
1235  */
1236 __rte_internal
1237 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
1238
1239 /**
1240  * @internal
1241  * Attach to the ethdev already initialized by the primary
1242  * process.
1243  *
1244  * @param       name    Ethernet device's name.
1245  * @return
1246  *   - Success: Slot in the rte_dev_devices array for attached
1247  *        device.
1248  *   - Error: Null pointer.
1249  */
1250 __rte_internal
1251 struct rte_eth_dev *rte_eth_dev_attach_secondary(const char *name);
1252
1253 /**
1254  * @internal
1255  * Notify RTE_ETH_EVENT_DESTROY and release the specified ethdev port.
1256  *
1257  * The following PMD-managed data fields will be freed:
1258  *   - dev_private
1259  *   - mac_addrs
1260  *   - hash_mac_addrs
1261  * If one of these fields should not be freed,
1262  * it must be reset to NULL by the PMD, typically in dev_close method.
1263  *
1264  * @param eth_dev
1265  * Device to be detached.
1266  * @return
1267  *   - 0 on success, negative on error
1268  */
1269 __rte_internal
1270 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
1271
1272 /**
1273  * @internal
1274  * Release device queues and clear its configuration to force the user
1275  * application to reconfigure it. It is for internal use only.
1276  *
1277  * @param dev
1278  *  Pointer to struct rte_eth_dev.
1279  *
1280  * @return
1281  *  void
1282  */
1283 __rte_internal
1284 void rte_eth_dev_internal_reset(struct rte_eth_dev *dev);
1285
1286 /**
1287  * @internal Executes all the user application registered callbacks for
1288  * the specific device. It is for DPDK internal user only. User
1289  * application should not call it directly.
1290  *
1291  * @param dev
1292  *  Pointer to struct rte_eth_dev.
1293  * @param event
1294  *  Eth device interrupt event type.
1295  * @param ret_param
1296  *  To pass data back to user application.
1297  *  This allows the user application to decide if a particular function
1298  *  is permitted or not.
1299  *
1300  * @return
1301  *  int
1302  */
1303 __rte_internal
1304 int rte_eth_dev_callback_process(struct rte_eth_dev *dev,
1305                 enum rte_eth_event_type event, void *ret_param);
1306
1307 /**
1308  * @internal
1309  * This is the last step of device probing.
1310  * It must be called after a port is allocated and initialized successfully.
1311  *
1312  * The notification RTE_ETH_EVENT_NEW is sent to other entities
1313  * (libraries and applications).
1314  * The state is set as RTE_ETH_DEV_ATTACHED.
1315  *
1316  * @param dev
1317  *  New ethdev port.
1318  */
1319 __rte_internal
1320 void rte_eth_dev_probing_finish(struct rte_eth_dev *dev);
1321
1322 /**
1323  * Create memzone for HW rings.
1324  * malloc can't be used as the physical address is needed.
1325  * If the memzone is already created, then this function returns a ptr
1326  * to the old one.
1327  *
1328  * @param eth_dev
1329  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
1330  * @param name
1331  *   The name of the memory zone
1332  * @param queue_id
1333  *   The index of the queue to add to name
1334  * @param size
1335  *   The sizeof of the memory area
1336  * @param align
1337  *   Alignment for resulting memzone. Must be a power of 2.
1338  * @param socket_id
1339  *   The *socket_id* argument is the socket identifier in case of NUMA.
1340  */
1341 __rte_internal
1342 const struct rte_memzone *
1343 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
1344                          uint16_t queue_id, size_t size,
1345                          unsigned align, int socket_id);
1346
1347 /**
1348  * Free previously allocated memzone for HW rings.
1349  *
1350  * @param eth_dev
1351  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
1352  * @param name
1353  *   The name of the memory zone
1354  * @param queue_id
1355  *   The index of the queue to add to name
1356  * @return
1357  *   Negative errno value on error, 0 on success.
1358  */
1359 __rte_internal
1360 int
1361 rte_eth_dma_zone_free(const struct rte_eth_dev *eth_dev, const char *name,
1362                  uint16_t queue_id);
1363
1364 /**
1365  * @internal
1366  * Atomically set the link status for the specific device.
1367  * It is for use by DPDK device driver use only.
1368  * User applications should not call it
1369  *
1370  * @param dev
1371  *  Pointer to struct rte_eth_dev.
1372  * @param link
1373  *  New link status value.
1374  * @return
1375  *  Same convention as eth_link_update operation.
1376  *  0   if link up status has changed
1377  *  -1  if link up status was unchanged
1378  */
1379 static inline int
1380 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
1381                        const struct rte_eth_link *new_link)
1382 {
1383         uint64_t *dev_link = (uint64_t *)&(dev->data->dev_link);
1384         union {
1385                 uint64_t val64;
1386                 struct rte_eth_link link;
1387         } orig;
1388
1389         RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
1390
1391         orig.val64 = __atomic_exchange_n(dev_link, *(const uint64_t *)new_link,
1392                                         __ATOMIC_SEQ_CST);
1393
1394         return (orig.link.link_status == new_link->link_status) ? -1 : 0;
1395 }
1396
1397 /**
1398  * @internal
1399  * Atomically get the link speed and status.
1400  *
1401  * @param dev
1402  *  Pointer to struct rte_eth_dev.
1403  * @param link
1404  *  link status value.
1405  */
1406 static inline void
1407 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
1408                        struct rte_eth_link *link)
1409 {
1410         uint64_t *src = (uint64_t *)&(dev->data->dev_link);
1411         uint64_t *dst = (uint64_t *)link;
1412
1413         RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
1414
1415         *dst = __atomic_load_n(src, __ATOMIC_SEQ_CST);
1416 }
1417
1418 /**
1419  * Allocate an unique switch domain identifier.
1420  *
1421  * A pool of switch domain identifiers which can be allocated on request. This
1422  * will enabled devices which support the concept of switch domains to request
1423  * a switch domain id which is guaranteed to be unique from other devices
1424  * running in the same process.
1425  *
1426  * @param domain_id
1427  *  switch domain identifier parameter to pass back to application
1428  *
1429  * @return
1430  *   Negative errno value on error, 0 on success.
1431  */
1432 __rte_internal
1433 int
1434 rte_eth_switch_domain_alloc(uint16_t *domain_id);
1435
1436 /**
1437  * Free switch domain.
1438  *
1439  * Return a switch domain identifier to the pool of free identifiers after it is
1440  * no longer in use by device.
1441  *
1442  * @param domain_id
1443  *  switch domain identifier to free
1444  *
1445  * @return
1446  *   Negative errno value on error, 0 on success.
1447  */
1448 __rte_internal
1449 int
1450 rte_eth_switch_domain_free(uint16_t domain_id);
1451
1452 /**
1453  * Generic Ethernet device arguments
1454  *
1455  * One type of representor each structure.
1456  */
1457 struct rte_eth_devargs {
1458         uint16_t mh_controllers[RTE_MAX_MULTI_HOST_CTRLS];
1459         /** controller/s number in case of multi-host */
1460         uint16_t nb_mh_controllers;
1461         /** number of controllers in multi-host controllers field */
1462         uint16_t ports[RTE_MAX_ETHPORTS];
1463         /** port/s number to enable on a multi-port single function */
1464         uint16_t nb_ports;
1465         /** number of ports in ports field */
1466         uint16_t representor_ports[RTE_MAX_ETHPORTS];
1467         /** representor port/s identifier to enable on device */
1468         uint16_t nb_representor_ports;
1469         /** number of ports in representor port field */
1470         enum rte_eth_representor_type type; /* type of representor */
1471 };
1472
1473 /**
1474  * PMD helper function to get representor ID from location detail.
1475  *
1476  * Get representor ID from controller, pf and (sf or vf).
1477  * The mapping is retrieved from rte_eth_representor_info_get().
1478  *
1479  * For backward compatibility, if no representor info, direct
1480  * map legacy VF (no controller and pf).
1481  *
1482  * @param port_id
1483  *  Port ID of the backing device.
1484  * @param type
1485  *  Representor type.
1486  * @param controller
1487  *  Controller ID, -1 if unspecified.
1488  * @param pf
1489  *  PF port ID, -1 if unspecified.
1490  * @param representor_port
1491  *  VF or SF representor port number, -1 if unspecified.
1492  * @param repr_id
1493  *  Pointer to output representor ID.
1494  *
1495  * @return
1496  *  Negative errno value on error, 0 on success.
1497  */
1498 __rte_internal
1499 int
1500 rte_eth_representor_id_get(uint16_t port_id,
1501                            enum rte_eth_representor_type type,
1502                            int controller, int pf, int representor_port,
1503                            uint16_t *repr_id);
1504
1505 /**
1506  * PMD helper function to parse ethdev arguments
1507  *
1508  * @param devargs
1509  *  device arguments
1510  * @param eth_devargs
1511  *  parsed ethdev specific arguments.
1512  *
1513  * @return
1514  *   Negative errno value on error, 0 on success.
1515  */
1516 __rte_internal
1517 int
1518 rte_eth_devargs_parse(const char *devargs, struct rte_eth_devargs *eth_devargs);
1519
1520
1521 typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void *init_params);
1522 typedef int (*ethdev_bus_specific_init)(struct rte_eth_dev *ethdev,
1523         void *bus_specific_init_params);
1524
1525 /**
1526  * PMD helper function for the creation of a new ethdev ports.
1527  *
1528  * @param device
1529  *  rte_device handle.
1530  * @param name
1531  *  port name.
1532  * @param priv_data_size
1533  *  size of private data required for port.
1534  * @param bus_specific_init
1535  *  port bus specific initialisation callback function
1536  * @param bus_init_params
1537  *  port bus specific initialisation parameters
1538  * @param ethdev_init
1539  *  device specific port initialization callback function
1540  * @param init_params
1541  *  port initialisation parameters
1542  *
1543  * @return
1544  *   Negative errno value on error, 0 on success.
1545  */
1546 __rte_internal
1547 int
1548 rte_eth_dev_create(struct rte_device *device, const char *name,
1549         size_t priv_data_size,
1550         ethdev_bus_specific_init bus_specific_init, void *bus_init_params,
1551         ethdev_init_t ethdev_init, void *init_params);
1552
1553
1554 typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev);
1555
1556 /**
1557  * PMD helper function for cleaning up the resources of a ethdev port on it's
1558  * destruction.
1559  *
1560  * @param ethdev
1561  *   ethdev handle of port.
1562  * @param ethdev_uninit
1563  *   device specific port un-initialise callback function
1564  *
1565  * @return
1566  *   Negative errno value on error, 0 on success.
1567  */
1568 __rte_internal
1569 int
1570 rte_eth_dev_destroy(struct rte_eth_dev *ethdev, ethdev_uninit_t ethdev_uninit);
1571
1572 /**
1573  * @internal
1574  * Pass the current hairpin queue HW and/or SW information to the peer queue
1575  * and fetch back the information of the peer queue.
1576  *
1577  * @param peer_port
1578  *  Peer port identifier of the Ethernet device.
1579  * @param peer_queue
1580  *  Peer queue index of the port.
1581  * @param cur_info
1582  *  Pointer to the current information structure.
1583  * @param peer_info
1584  *  Pointer to the peer information, output.
1585  * @param direction
1586  *  Direction to pass the information.
1587  *  positive - pass Tx queue information and get peer Rx queue information
1588  *  zero - pass Rx queue information and get peer Tx queue information
1589  *
1590  * @return
1591  *  Negative errno value on error, 0 on success.
1592  */
1593 __rte_internal
1594 int
1595 rte_eth_hairpin_queue_peer_update(uint16_t peer_port, uint16_t peer_queue,
1596                                   struct rte_hairpin_peer_info *cur_info,
1597                                   struct rte_hairpin_peer_info *peer_info,
1598                                   uint32_t direction);
1599
1600 /**
1601  * @internal
1602  * Configure current hairpin queue with the peer information fetched to create
1603  * the connection (bind) with peer queue in the specified direction.
1604  * This function might need to be called twice to fully create the connections.
1605  *
1606  * @param cur_port
1607  *  Current port identifier of the Ethernet device.
1608  * @param cur_queue
1609  *  Current queue index of the port.
1610  * @param peer_info
1611  *  Pointer to the peer information, input.
1612  * @param direction
1613  *  Direction to create the connection.
1614  *  positive - bind current Tx queue to peer Rx queue
1615  *  zero - bind current Rx queue to peer Tx queue
1616  *
1617  * @return
1618  *  Negative errno value on error, 0 on success.
1619  */
1620 __rte_internal
1621 int
1622 rte_eth_hairpin_queue_peer_bind(uint16_t cur_port, uint16_t cur_queue,
1623                                 struct rte_hairpin_peer_info *peer_info,
1624                                 uint32_t direction);
1625
1626 /**
1627  * @internal
1628  * Reset the current queue state and configuration to disconnect (unbind) it
1629  * from the peer queue.
1630  * This function might need to be called twice to disconnect each other.
1631  *
1632  * @param cur_port
1633  *  Current port identifier of the Ethernet device.
1634  * @param cur_queue
1635  *  Current queue index of the port.
1636  * @param direction
1637  *  Direction to destroy the connection.
1638  *  positive - unbind current Tx queue from peer Rx queue
1639  *  zero - unbind current Rx queue from peer Tx queue
1640  *
1641  * @return
1642  *  Negative errno value on error, 0 on success.
1643  */
1644 __rte_internal
1645 int
1646 rte_eth_hairpin_queue_peer_unbind(uint16_t cur_port, uint16_t cur_queue,
1647                                   uint32_t direction);
1648
1649
1650 /*
1651  * Legacy ethdev API used internally by drivers.
1652  */
1653
1654 enum rte_filter_type {
1655         RTE_ETH_FILTER_NONE = 0,
1656         RTE_ETH_FILTER_ETHERTYPE,
1657         RTE_ETH_FILTER_FLEXIBLE,
1658         RTE_ETH_FILTER_SYN,
1659         RTE_ETH_FILTER_NTUPLE,
1660         RTE_ETH_FILTER_TUNNEL,
1661         RTE_ETH_FILTER_FDIR,
1662         RTE_ETH_FILTER_HASH,
1663         RTE_ETH_FILTER_L2_TUNNEL,
1664 };
1665
1666 /**
1667  * Define all structures for Ethertype Filter type.
1668  */
1669
1670 #define RTE_ETHTYPE_FLAGS_MAC    0x0001 /**< If set, compare mac */
1671 #define RTE_ETHTYPE_FLAGS_DROP   0x0002 /**< If set, drop packet when match */
1672
1673 /**
1674  * A structure used to define the ethertype filter entry
1675  * to support RTE_ETH_FILTER_ETHERTYPE data representation.
1676  */
1677 struct rte_eth_ethertype_filter {
1678         struct rte_ether_addr mac_addr;   /**< Mac address to match. */
1679         uint16_t ether_type;          /**< Ether type to match */
1680         uint16_t flags;               /**< Flags from RTE_ETHTYPE_FLAGS_* */
1681         uint16_t queue;               /**< Queue assigned to when match*/
1682 };
1683
1684 /**
1685  * A structure used to define the TCP syn filter entry
1686  * to support RTE_ETH_FILTER_SYN data representation.
1687  */
1688 struct rte_eth_syn_filter {
1689         /** 1 - higher priority than other filters, 0 - lower priority. */
1690         uint8_t hig_pri;
1691         uint16_t queue;      /**< Queue assigned to when match */
1692 };
1693
1694 /**
1695  * filter type of tunneling packet
1696  */
1697 #define ETH_TUNNEL_FILTER_OMAC  0x01 /**< filter by outer MAC addr */
1698 #define ETH_TUNNEL_FILTER_OIP   0x02 /**< filter by outer IP Addr */
1699 #define ETH_TUNNEL_FILTER_TENID 0x04 /**< filter by tenant ID */
1700 #define ETH_TUNNEL_FILTER_IMAC  0x08 /**< filter by inner MAC addr */
1701 #define ETH_TUNNEL_FILTER_IVLAN 0x10 /**< filter by inner VLAN ID */
1702 #define ETH_TUNNEL_FILTER_IIP   0x20 /**< filter by inner IP addr */
1703
1704 #define RTE_TUNNEL_FILTER_IMAC_IVLAN (ETH_TUNNEL_FILTER_IMAC | \
1705                                         ETH_TUNNEL_FILTER_IVLAN)
1706 #define RTE_TUNNEL_FILTER_IMAC_IVLAN_TENID (ETH_TUNNEL_FILTER_IMAC | \
1707                                         ETH_TUNNEL_FILTER_IVLAN | \
1708                                         ETH_TUNNEL_FILTER_TENID)
1709 #define RTE_TUNNEL_FILTER_IMAC_TENID (ETH_TUNNEL_FILTER_IMAC | \
1710                                         ETH_TUNNEL_FILTER_TENID)
1711 #define RTE_TUNNEL_FILTER_OMAC_TENID_IMAC (ETH_TUNNEL_FILTER_OMAC | \
1712                                         ETH_TUNNEL_FILTER_TENID | \
1713                                         ETH_TUNNEL_FILTER_IMAC)
1714
1715 /**
1716  *  Select IPv4 or IPv6 for tunnel filters.
1717  */
1718 enum rte_tunnel_iptype {
1719         RTE_TUNNEL_IPTYPE_IPV4 = 0, /**< IPv4. */
1720         RTE_TUNNEL_IPTYPE_IPV6,     /**< IPv6. */
1721 };
1722
1723 /**
1724  * Tunneling Packet filter configuration.
1725  */
1726 struct rte_eth_tunnel_filter_conf {
1727         struct rte_ether_addr outer_mac;    /**< Outer MAC address to match. */
1728         struct rte_ether_addr inner_mac;    /**< Inner MAC address to match. */
1729         uint16_t inner_vlan;            /**< Inner VLAN to match. */
1730         enum rte_tunnel_iptype ip_type; /**< IP address type. */
1731         /**
1732          * Outer destination IP address to match if ETH_TUNNEL_FILTER_OIP
1733          * is set in filter_type, or inner destination IP address to match
1734          * if ETH_TUNNEL_FILTER_IIP is set in filter_type.
1735          */
1736         union {
1737                 uint32_t ipv4_addr;     /**< IPv4 address in big endian. */
1738                 uint32_t ipv6_addr[4];  /**< IPv6 address in big endian. */
1739         } ip_addr;
1740         /** Flags from ETH_TUNNEL_FILTER_XX - see above. */
1741         uint16_t filter_type;
1742         enum rte_eth_tunnel_type tunnel_type; /**< Tunnel Type. */
1743         uint32_t tenant_id;     /**< Tenant ID to match. VNI, GRE key... */
1744         uint16_t queue_id;      /**< Queue assigned to if match. */
1745 };
1746
1747 #endif /* _RTE_ETHDEV_DRIVER_H_ */