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