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