ethdev: use hairpin helper functions
[dpdk.git] / lib / librte_ethdev / rte_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 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /*
25  * Definitions of all functions exported by an Ethernet driver through the
26  * generic structure of type *eth_dev_ops* supplied in the *rte_eth_dev*
27  * structure associated with an Ethernet device.
28  */
29
30 typedef int  (*eth_dev_configure_t)(struct rte_eth_dev *dev);
31 /**< @internal Ethernet device configuration. */
32
33 typedef int  (*eth_dev_start_t)(struct rte_eth_dev *dev);
34 /**< @internal Function used to start a configured Ethernet device. */
35
36 typedef void (*eth_dev_stop_t)(struct rte_eth_dev *dev);
37 /**< @internal Function used to stop a configured Ethernet device. */
38
39 typedef int  (*eth_dev_set_link_up_t)(struct rte_eth_dev *dev);
40 /**< @internal Function used to link up a configured Ethernet device. */
41
42 typedef int  (*eth_dev_set_link_down_t)(struct rte_eth_dev *dev);
43 /**< @internal Function used to link down a configured Ethernet device. */
44
45 typedef void (*eth_dev_close_t)(struct rte_eth_dev *dev);
46 /**< @internal Function used to close a configured Ethernet device. */
47
48 typedef int (*eth_dev_reset_t)(struct rte_eth_dev *dev);
49 /** <@internal Function used to reset a configured Ethernet device. */
50
51 typedef int (*eth_is_removed_t)(struct rte_eth_dev *dev);
52 /**< @internal Function used to detect an Ethernet device removal. */
53
54 /**
55  * @internal
56  * Function used to enable the Rx promiscuous mode of an Ethernet device.
57  *
58  * @param dev
59  *   ethdev handle of port.
60  *
61  * @return
62  *   Negative errno value on error, 0 on success.
63  *
64  * @retval 0
65  *   Success, promiscuous mode is enabled.
66  * @retval -ENOTSUP
67  *   Promiscuous mode is not supported.
68  * @retval -ENODEV
69  *   Device is gone.
70  * @retval -E_RTE_SECONDARY
71  *   Function was called from a secondary process instance and not supported.
72  * @retval -ETIMEDOUT
73  *   Attempt to enable promiscuos mode failed because of timeout.
74  * @retval -EAGAIN
75  *   Failed to enable promiscuous mode.
76  */
77 typedef int (*eth_promiscuous_enable_t)(struct rte_eth_dev *dev);
78
79 /**
80  * @internal
81  * Function used to disable the Rx promiscuous mode of an Ethernet device.
82  *
83  * @param dev
84  *   ethdev handle of port.
85  *
86  * @return
87  *   Negative errno value on error, 0 on success.
88  *
89  * @retval 0
90  *   Success, promiscuous mode is disabled.
91  * @retval -ENOTSUP
92  *   Promiscuous mode disabling is not supported.
93  * @retval -ENODEV
94  *   Device is gone.
95  * @retval -E_RTE_SECONDARY
96  *   Function was called from a secondary process instance and not supported.
97  * @retval -ETIMEDOUT
98  *   Attempt to disable promiscuos mode failed because of timeout.
99  * @retval -EAGAIN
100  *   Failed to disable promiscuous mode.
101  */
102 typedef int (*eth_promiscuous_disable_t)(struct rte_eth_dev *dev);
103
104 /**
105  * @internal
106  * Enable the receipt of all multicast packets by an Ethernet device.
107  *
108  * @param dev
109  *   ethdev handle of port.
110  *
111  * @return
112  *   Negative errno value on error, 0 on success.
113  *
114  * @retval 0
115  *   Success, all-multicast mode is enabled.
116  * @retval -ENOTSUP
117  *   All-multicast mode is not supported.
118  * @retval -ENODEV
119  *   Device is gone.
120  * @retval -E_RTE_SECONDARY
121  *   Function was called from a secondary process instance and not supported.
122  * @retval -ETIMEDOUT
123  *   Attempt to enable all-multicast mode failed because of timeout.
124  * @retval -EAGAIN
125  *   Failed to enable all-multicast mode.
126  */
127 typedef int (*eth_allmulticast_enable_t)(struct rte_eth_dev *dev);
128
129 /**
130  * @internal
131  * Disable the receipt of all multicast packets by an Ethernet device.
132  *
133  * @param dev
134  *   ethdev handle of port.
135  *
136  * @return
137  *   Negative errno value on error, 0 on success.
138  *
139  * @retval 0
140  *   Success, all-multicast mode is disabled.
141  * @retval -ENOTSUP
142  *   All-multicast mode disabling is not supported.
143  * @retval -ENODEV
144  *   Device is gone.
145  * @retval -E_RTE_SECONDARY
146  *   Function was called from a secondary process instance and not supported.
147  * @retval -ETIMEDOUT
148  *   Attempt to disable all-multicast mode failed because of timeout.
149  * @retval -EAGAIN
150  *   Failed to disable all-multicast mode.
151  */
152 typedef int (*eth_allmulticast_disable_t)(struct rte_eth_dev *dev);
153
154 typedef int (*eth_link_update_t)(struct rte_eth_dev *dev,
155                                 int wait_to_complete);
156 /**< @internal Get link speed, duplex mode and state (up/down) of an Ethernet device. */
157
158 typedef int (*eth_stats_get_t)(struct rte_eth_dev *dev,
159                                 struct rte_eth_stats *igb_stats);
160 /**< @internal Get global I/O statistics of an Ethernet device. */
161
162 /**
163  * @internal
164  * Reset global I/O statistics of an Ethernet device to 0.
165  *
166  * @param dev
167  *   ethdev handle of port.
168  *
169  * @return
170  *   Negative errno value on error, 0 on success.
171  *
172  * @retval 0
173  *   Success, statistics has been reset.
174  * @retval -ENOTSUP
175  *   Resetting statistics is not supported.
176  * @retval -EINVAL
177  *   Resetting statistics is not valid.
178  * @retval -ENOMEM
179  *   Not enough memory to get the stats.
180  */
181 typedef int (*eth_stats_reset_t)(struct rte_eth_dev *dev);
182
183 typedef int (*eth_xstats_get_t)(struct rte_eth_dev *dev,
184         struct rte_eth_xstat *stats, unsigned int n);
185 /**< @internal Get extended stats of an Ethernet device. */
186
187 typedef int (*eth_xstats_get_by_id_t)(struct rte_eth_dev *dev,
188                                       const uint64_t *ids,
189                                       uint64_t *values,
190                                       unsigned int n);
191 /**< @internal Get extended stats of an Ethernet device. */
192
193 /**
194  * @internal
195  * Reset extended stats of an Ethernet device.
196  *
197  * @param dev
198  *   ethdev handle of port.
199  *
200  * @return
201  *   Negative errno value on error, 0 on success.
202  *
203  * @retval 0
204  *   Success, statistics has been reset.
205  * @retval -ENOTSUP
206  *   Resetting statistics is not supported.
207  * @retval -EINVAL
208  *   Resetting statistics is not valid.
209  * @retval -ENOMEM
210  *   Not enough memory to get the stats.
211  */
212 typedef int (*eth_xstats_reset_t)(struct rte_eth_dev *dev);
213
214 typedef int (*eth_xstats_get_names_t)(struct rte_eth_dev *dev,
215         struct rte_eth_xstat_name *xstats_names, unsigned int size);
216 /**< @internal Get names of extended stats of an Ethernet device. */
217
218 typedef int (*eth_xstats_get_names_by_id_t)(struct rte_eth_dev *dev,
219         struct rte_eth_xstat_name *xstats_names, const uint64_t *ids,
220         unsigned int size);
221 /**< @internal Get names of extended stats of an Ethernet device. */
222
223 typedef int (*eth_queue_stats_mapping_set_t)(struct rte_eth_dev *dev,
224                                              uint16_t queue_id,
225                                              uint8_t stat_idx,
226                                              uint8_t is_rx);
227 /**< @internal Set a queue statistics mapping for a tx/rx queue of an Ethernet device. */
228
229 typedef int (*eth_dev_infos_get_t)(struct rte_eth_dev *dev,
230                                    struct rte_eth_dev_info *dev_info);
231 /**< @internal Get specific information of an Ethernet device. */
232
233 typedef const uint32_t *(*eth_dev_supported_ptypes_get_t)(struct rte_eth_dev *dev);
234 /**< @internal Get supported ptypes of an Ethernet device. */
235
236 /**
237  * @internal
238  * Inform Ethernet device about reduced range of packet types to handle.
239  *
240  * @param dev
241  *   The Ethernet device identifier.
242  * @param ptype_mask
243  *   The ptype family that application is interested in should be bitwise OR of
244  *   RTE_PTYPE_*_MASK or 0.
245  * @return
246  *   - (0) if Success.
247  */
248 typedef int (*eth_dev_ptypes_set_t)(struct rte_eth_dev *dev,
249                                      uint32_t ptype_mask);
250
251 typedef int (*eth_queue_start_t)(struct rte_eth_dev *dev,
252                                     uint16_t queue_id);
253 /**< @internal Start rx and tx of a queue of an Ethernet device. */
254
255 typedef int (*eth_queue_stop_t)(struct rte_eth_dev *dev,
256                                     uint16_t queue_id);
257 /**< @internal Stop rx and tx of a queue of an Ethernet device. */
258
259 typedef int (*eth_rx_queue_setup_t)(struct rte_eth_dev *dev,
260                                     uint16_t rx_queue_id,
261                                     uint16_t nb_rx_desc,
262                                     unsigned int socket_id,
263                                     const struct rte_eth_rxconf *rx_conf,
264                                     struct rte_mempool *mb_pool);
265 /**< @internal Set up a receive queue of an Ethernet device. */
266
267 typedef int (*eth_tx_queue_setup_t)(struct rte_eth_dev *dev,
268                                     uint16_t tx_queue_id,
269                                     uint16_t nb_tx_desc,
270                                     unsigned int socket_id,
271                                     const struct rte_eth_txconf *tx_conf);
272 /**< @internal Setup a transmit queue of an Ethernet device. */
273
274 typedef int (*eth_rx_enable_intr_t)(struct rte_eth_dev *dev,
275                                     uint16_t rx_queue_id);
276 /**< @internal Enable interrupt of a receive queue of an Ethernet device. */
277
278 typedef int (*eth_rx_disable_intr_t)(struct rte_eth_dev *dev,
279                                     uint16_t rx_queue_id);
280 /**< @internal Disable interrupt of a receive queue of an Ethernet device. */
281
282 typedef void (*eth_queue_release_t)(void *queue);
283 /**< @internal Release memory resources allocated by given RX/TX queue. */
284
285 typedef int (*eth_fw_version_get_t)(struct rte_eth_dev *dev,
286                                      char *fw_version, size_t fw_size);
287 /**< @internal Get firmware information of an Ethernet device. */
288
289 typedef int (*eth_tx_done_cleanup_t)(void *txq, uint32_t free_cnt);
290 /**< @internal Force mbufs to be from TX ring. */
291
292 typedef void (*eth_rxq_info_get_t)(struct rte_eth_dev *dev,
293         uint16_t rx_queue_id, struct rte_eth_rxq_info *qinfo);
294
295 typedef void (*eth_txq_info_get_t)(struct rte_eth_dev *dev,
296         uint16_t tx_queue_id, struct rte_eth_txq_info *qinfo);
297
298 typedef int (*eth_burst_mode_get_t)(struct rte_eth_dev *dev,
299         uint16_t queue_id, struct rte_eth_burst_mode *mode);
300
301 typedef int (*mtu_set_t)(struct rte_eth_dev *dev, uint16_t mtu);
302 /**< @internal Set MTU. */
303
304 typedef int (*vlan_filter_set_t)(struct rte_eth_dev *dev,
305                                   uint16_t vlan_id,
306                                   int on);
307 /**< @internal filtering of a VLAN Tag Identifier by an Ethernet device. */
308
309 typedef int (*vlan_tpid_set_t)(struct rte_eth_dev *dev,
310                                enum rte_vlan_type type, uint16_t tpid);
311 /**< @internal set the outer/inner VLAN-TPID by an Ethernet device. */
312
313 typedef int (*vlan_offload_set_t)(struct rte_eth_dev *dev, int mask);
314 /**< @internal set VLAN offload function by an Ethernet device. */
315
316 typedef int (*vlan_pvid_set_t)(struct rte_eth_dev *dev,
317                                uint16_t vlan_id,
318                                int on);
319 /**< @internal set port based TX VLAN insertion by an Ethernet device. */
320
321 typedef void (*vlan_strip_queue_set_t)(struct rte_eth_dev *dev,
322                                   uint16_t rx_queue_id,
323                                   int on);
324 /**< @internal VLAN stripping enable/disable by an queue of Ethernet device. */
325
326 typedef int (*flow_ctrl_get_t)(struct rte_eth_dev *dev,
327                                struct rte_eth_fc_conf *fc_conf);
328 /**< @internal Get current flow control parameter on an Ethernet device */
329
330 typedef int (*flow_ctrl_set_t)(struct rte_eth_dev *dev,
331                                struct rte_eth_fc_conf *fc_conf);
332 /**< @internal Setup flow control parameter on an Ethernet device */
333
334 typedef int (*priority_flow_ctrl_set_t)(struct rte_eth_dev *dev,
335                                 struct rte_eth_pfc_conf *pfc_conf);
336 /**< @internal Setup priority flow control parameter on an Ethernet device */
337
338 typedef int (*reta_update_t)(struct rte_eth_dev *dev,
339                              struct rte_eth_rss_reta_entry64 *reta_conf,
340                              uint16_t reta_size);
341 /**< @internal Update RSS redirection table on an Ethernet device */
342
343 typedef int (*reta_query_t)(struct rte_eth_dev *dev,
344                             struct rte_eth_rss_reta_entry64 *reta_conf,
345                             uint16_t reta_size);
346 /**< @internal Query RSS redirection table on an Ethernet device */
347
348 typedef int (*rss_hash_update_t)(struct rte_eth_dev *dev,
349                                  struct rte_eth_rss_conf *rss_conf);
350 /**< @internal Update RSS hash configuration of an Ethernet device */
351
352 typedef int (*rss_hash_conf_get_t)(struct rte_eth_dev *dev,
353                                    struct rte_eth_rss_conf *rss_conf);
354 /**< @internal Get current RSS hash configuration of an Ethernet device */
355
356 typedef int (*eth_dev_led_on_t)(struct rte_eth_dev *dev);
357 /**< @internal Turn on SW controllable LED on an Ethernet device */
358
359 typedef int (*eth_dev_led_off_t)(struct rte_eth_dev *dev);
360 /**< @internal Turn off SW controllable LED on an Ethernet device */
361
362 typedef void (*eth_mac_addr_remove_t)(struct rte_eth_dev *dev, uint32_t index);
363 /**< @internal Remove MAC address from receive address register */
364
365 typedef int (*eth_mac_addr_add_t)(struct rte_eth_dev *dev,
366                                   struct rte_ether_addr *mac_addr,
367                                   uint32_t index,
368                                   uint32_t vmdq);
369 /**< @internal Set a MAC address into Receive Address Register */
370
371 typedef int (*eth_mac_addr_set_t)(struct rte_eth_dev *dev,
372                                   struct rte_ether_addr *mac_addr);
373 /**< @internal Set a MAC address into Receive Address Register */
374
375 typedef int (*eth_uc_hash_table_set_t)(struct rte_eth_dev *dev,
376                                   struct rte_ether_addr *mac_addr,
377                                   uint8_t on);
378 /**< @internal Set a Unicast Hash bitmap */
379
380 typedef int (*eth_uc_all_hash_table_set_t)(struct rte_eth_dev *dev,
381                                   uint8_t on);
382 /**< @internal Set all Unicast Hash bitmap */
383
384 typedef int (*eth_set_queue_rate_limit_t)(struct rte_eth_dev *dev,
385                                 uint16_t queue_idx,
386                                 uint16_t tx_rate);
387 /**< @internal Set queue TX rate */
388
389 typedef int (*eth_mirror_rule_set_t)(struct rte_eth_dev *dev,
390                                   struct rte_eth_mirror_conf *mirror_conf,
391                                   uint8_t rule_id,
392                                   uint8_t on);
393 /**< @internal Add a traffic mirroring rule on an Ethernet device */
394
395 typedef int (*eth_mirror_rule_reset_t)(struct rte_eth_dev *dev,
396                                   uint8_t rule_id);
397 /**< @internal Remove a traffic mirroring rule on an Ethernet device */
398
399 typedef int (*eth_udp_tunnel_port_add_t)(struct rte_eth_dev *dev,
400                                          struct rte_eth_udp_tunnel *tunnel_udp);
401 /**< @internal Add tunneling UDP port */
402
403 typedef int (*eth_udp_tunnel_port_del_t)(struct rte_eth_dev *dev,
404                                          struct rte_eth_udp_tunnel *tunnel_udp);
405 /**< @internal Delete tunneling UDP port */
406
407 typedef int (*eth_set_mc_addr_list_t)(struct rte_eth_dev *dev,
408                                       struct rte_ether_addr *mc_addr_set,
409                                       uint32_t nb_mc_addr);
410 /**< @internal set the list of multicast addresses on an Ethernet device */
411
412 typedef int (*eth_timesync_enable_t)(struct rte_eth_dev *dev);
413 /**< @internal Function used to enable IEEE1588/802.1AS timestamping. */
414
415 typedef int (*eth_timesync_disable_t)(struct rte_eth_dev *dev);
416 /**< @internal Function used to disable IEEE1588/802.1AS timestamping. */
417
418 typedef int (*eth_timesync_read_rx_timestamp_t)(struct rte_eth_dev *dev,
419                                                 struct timespec *timestamp,
420                                                 uint32_t flags);
421 /**< @internal Function used to read an RX IEEE1588/802.1AS timestamp. */
422
423 typedef int (*eth_timesync_read_tx_timestamp_t)(struct rte_eth_dev *dev,
424                                                 struct timespec *timestamp);
425 /**< @internal Function used to read a TX IEEE1588/802.1AS timestamp. */
426
427 typedef int (*eth_timesync_adjust_time)(struct rte_eth_dev *dev, int64_t);
428 /**< @internal Function used to adjust the device clock */
429
430 typedef int (*eth_timesync_read_time)(struct rte_eth_dev *dev,
431                                       struct timespec *timestamp);
432 /**< @internal Function used to get time from the device clock. */
433
434 typedef int (*eth_timesync_write_time)(struct rte_eth_dev *dev,
435                                        const struct timespec *timestamp);
436 /**< @internal Function used to get time from the device clock */
437
438 typedef int (*eth_read_clock)(struct rte_eth_dev *dev,
439                                       uint64_t *timestamp);
440 /**< @internal Function used to get the current value of the device clock. */
441
442 typedef int (*eth_get_reg_t)(struct rte_eth_dev *dev,
443                                 struct rte_dev_reg_info *info);
444 /**< @internal Retrieve registers  */
445
446 typedef int (*eth_get_eeprom_length_t)(struct rte_eth_dev *dev);
447 /**< @internal Retrieve eeprom size  */
448
449 typedef int (*eth_get_eeprom_t)(struct rte_eth_dev *dev,
450                                 struct rte_dev_eeprom_info *info);
451 /**< @internal Retrieve eeprom data  */
452
453 typedef int (*eth_set_eeprom_t)(struct rte_eth_dev *dev,
454                                 struct rte_dev_eeprom_info *info);
455 /**< @internal Program eeprom data  */
456
457 typedef int (*eth_get_module_info_t)(struct rte_eth_dev *dev,
458                                      struct rte_eth_dev_module_info *modinfo);
459 /**< @internal Retrieve type and size of plugin module eeprom */
460
461 typedef int (*eth_get_module_eeprom_t)(struct rte_eth_dev *dev,
462                                        struct rte_dev_eeprom_info *info);
463 /**< @internal Retrieve plugin module eeprom data */
464
465 typedef int (*eth_l2_tunnel_eth_type_conf_t)
466         (struct rte_eth_dev *dev, struct rte_eth_l2_tunnel_conf *l2_tunnel);
467 /**< @internal config l2 tunnel ether type */
468
469 typedef int (*eth_l2_tunnel_offload_set_t)
470         (struct rte_eth_dev *dev,
471          struct rte_eth_l2_tunnel_conf *l2_tunnel,
472          uint32_t mask,
473          uint8_t en);
474 /**< @internal enable/disable the l2 tunnel offload functions */
475
476
477 typedef int (*eth_filter_ctrl_t)(struct rte_eth_dev *dev,
478                                  enum rte_filter_type filter_type,
479                                  enum rte_filter_op filter_op,
480                                  void *arg);
481 /**< @internal Take operations to assigned filter type on an Ethernet device */
482
483 typedef int (*eth_tm_ops_get_t)(struct rte_eth_dev *dev, void *ops);
484 /**< @internal Get Traffic Management (TM) operations on an Ethernet device */
485
486 typedef int (*eth_mtr_ops_get_t)(struct rte_eth_dev *dev, void *ops);
487 /**< @internal Get Traffic Metering and Policing (MTR) operations */
488
489 typedef int (*eth_get_dcb_info)(struct rte_eth_dev *dev,
490                                  struct rte_eth_dcb_info *dcb_info);
491 /**< @internal Get dcb information on an Ethernet device */
492
493 typedef int (*eth_pool_ops_supported_t)(struct rte_eth_dev *dev,
494                                                 const char *pool);
495 /**< @internal Test if a port supports specific mempool ops */
496
497 /**
498  * @internal
499  * Get the hairpin capabilities.
500  *
501  * @param dev
502  *   ethdev handle of port.
503  * @param cap
504  *   returns the hairpin capabilities from the device.
505  *
506  * @return
507  *   Negative errno value on error, 0 on success.
508  *
509  * @retval 0
510  *   Success, hairpin is supported.
511  * @retval -ENOTSUP
512  *   Hairpin is not supported.
513  */
514 typedef int (*eth_hairpin_cap_get_t)(struct rte_eth_dev *dev,
515                                      struct rte_eth_hairpin_cap *cap);
516
517 /**
518  * @internal
519  * Setup RX hairpin queue.
520  *
521  * @param dev
522  *   ethdev handle of port.
523  * @param rx_queue_id
524  *   the selected RX queue index.
525  * @param nb_rx_desc
526  *   the requested number of descriptors for this queue. 0 - use PMD default.
527  * @param conf
528  *   the RX hairpin configuration structure.
529  *
530  * @return
531  *   Negative errno value on error, 0 on success.
532  *
533  * @retval 0
534  *   Success, hairpin is supported.
535  * @retval -ENOTSUP
536  *   Hairpin is not supported.
537  * @retval -EINVAL
538  *   One of the parameters is invalid.
539  * @retval -ENOMEM
540  *   Unable to allocate resources.
541  */
542 typedef int (*eth_rx_hairpin_queue_setup_t)
543         (struct rte_eth_dev *dev, uint16_t rx_queue_id,
544          uint16_t nb_rx_desc,
545          const struct rte_eth_hairpin_conf *conf);
546
547 /**
548  * @internal
549  * Setup TX hairpin queue.
550  *
551  * @param dev
552  *   ethdev handle of port.
553  * @param tx_queue_id
554  *   the selected TX queue index.
555  * @param nb_tx_desc
556  *   the requested number of descriptors for this queue. 0 - use PMD default.
557  * @param conf
558  *   the TX hairpin configuration structure.
559  *
560  * @return
561  *   Negative errno value on error, 0 on success.
562  *
563  * @retval 0
564  *   Success, hairpin is supported.
565  * @retval -ENOTSUP
566  *   Hairpin is not supported.
567  * @retval -EINVAL
568  *   One of the parameters is invalid.
569  * @retval -ENOMEM
570  *   Unable to allocate resources.
571  */
572 typedef int (*eth_tx_hairpin_queue_setup_t)
573         (struct rte_eth_dev *dev, uint16_t tx_queue_id,
574          uint16_t nb_tx_desc,
575          const struct rte_eth_hairpin_conf *hairpin_conf);
576
577 /**
578  * @internal A structure containing the functions exported by an Ethernet driver.
579  */
580 struct eth_dev_ops {
581         eth_dev_configure_t        dev_configure; /**< Configure device. */
582         eth_dev_start_t            dev_start;     /**< Start device. */
583         eth_dev_stop_t             dev_stop;      /**< Stop device. */
584         eth_dev_set_link_up_t      dev_set_link_up;   /**< Device link up. */
585         eth_dev_set_link_down_t    dev_set_link_down; /**< Device link down. */
586         eth_dev_close_t            dev_close;     /**< Close device. */
587         eth_dev_reset_t            dev_reset;     /**< Reset device. */
588         eth_link_update_t          link_update;   /**< Get device link state. */
589         eth_is_removed_t           is_removed;
590         /**< Check if the device was physically removed. */
591
592         eth_promiscuous_enable_t   promiscuous_enable; /**< Promiscuous ON. */
593         eth_promiscuous_disable_t  promiscuous_disable;/**< Promiscuous OFF. */
594         eth_allmulticast_enable_t  allmulticast_enable;/**< RX multicast ON. */
595         eth_allmulticast_disable_t allmulticast_disable;/**< RX multicast OFF. */
596         eth_mac_addr_remove_t      mac_addr_remove; /**< Remove MAC address. */
597         eth_mac_addr_add_t         mac_addr_add;  /**< Add a MAC address. */
598         eth_mac_addr_set_t         mac_addr_set;  /**< Set a MAC address. */
599         eth_set_mc_addr_list_t     set_mc_addr_list; /**< set list of mcast addrs. */
600         mtu_set_t                  mtu_set;       /**< Set MTU. */
601
602         eth_stats_get_t            stats_get;     /**< Get generic device statistics. */
603         eth_stats_reset_t          stats_reset;   /**< Reset generic device statistics. */
604         eth_xstats_get_t           xstats_get;    /**< Get extended device statistics. */
605         eth_xstats_reset_t         xstats_reset;  /**< Reset extended device statistics. */
606         eth_xstats_get_names_t     xstats_get_names;
607         /**< Get names of extended statistics. */
608         eth_queue_stats_mapping_set_t queue_stats_mapping_set;
609         /**< Configure per queue stat counter mapping. */
610
611         eth_dev_infos_get_t        dev_infos_get; /**< Get device info. */
612         eth_rxq_info_get_t         rxq_info_get; /**< retrieve RX queue information. */
613         eth_txq_info_get_t         txq_info_get; /**< retrieve TX queue information. */
614         eth_burst_mode_get_t       rx_burst_mode_get; /**< Get RX burst mode */
615         eth_burst_mode_get_t       tx_burst_mode_get; /**< Get TX burst mode */
616         eth_fw_version_get_t       fw_version_get; /**< Get firmware version. */
617         eth_dev_supported_ptypes_get_t dev_supported_ptypes_get;
618         /**< Get packet types supported and identified by device. */
619         eth_dev_ptypes_set_t dev_ptypes_set;
620         /**< Inform Ethernet device about reduced range of packet types to handle. */
621
622         vlan_filter_set_t          vlan_filter_set; /**< Filter VLAN Setup. */
623         vlan_tpid_set_t            vlan_tpid_set; /**< Outer/Inner VLAN TPID Setup. */
624         vlan_strip_queue_set_t     vlan_strip_queue_set; /**< VLAN Stripping on queue. */
625         vlan_offload_set_t         vlan_offload_set; /**< Set VLAN Offload. */
626         vlan_pvid_set_t            vlan_pvid_set; /**< Set port based TX VLAN insertion. */
627
628         eth_queue_start_t          rx_queue_start;/**< Start RX for a queue. */
629         eth_queue_stop_t           rx_queue_stop; /**< Stop RX for a queue. */
630         eth_queue_start_t          tx_queue_start;/**< Start TX for a queue. */
631         eth_queue_stop_t           tx_queue_stop; /**< Stop TX for a queue. */
632         eth_rx_queue_setup_t       rx_queue_setup;/**< Set up device RX queue. */
633         eth_queue_release_t        rx_queue_release; /**< Release RX queue. */
634
635         eth_rx_enable_intr_t       rx_queue_intr_enable;  /**< Enable Rx queue interrupt. */
636         eth_rx_disable_intr_t      rx_queue_intr_disable; /**< Disable Rx queue interrupt. */
637         eth_tx_queue_setup_t       tx_queue_setup;/**< Set up device TX queue. */
638         eth_queue_release_t        tx_queue_release; /**< Release TX queue. */
639         eth_tx_done_cleanup_t      tx_done_cleanup;/**< Free tx ring mbufs */
640
641         eth_dev_led_on_t           dev_led_on;    /**< Turn on LED. */
642         eth_dev_led_off_t          dev_led_off;   /**< Turn off LED. */
643
644         flow_ctrl_get_t            flow_ctrl_get; /**< Get flow control. */
645         flow_ctrl_set_t            flow_ctrl_set; /**< Setup flow control. */
646         priority_flow_ctrl_set_t   priority_flow_ctrl_set; /**< Setup priority flow control. */
647
648         eth_uc_hash_table_set_t    uc_hash_table_set; /**< Set Unicast Table Array. */
649         eth_uc_all_hash_table_set_t uc_all_hash_table_set; /**< Set Unicast hash bitmap. */
650
651         eth_mirror_rule_set_t      mirror_rule_set; /**< Add a traffic mirror rule. */
652         eth_mirror_rule_reset_t    mirror_rule_reset; /**< reset a traffic mirror rule. */
653
654         eth_udp_tunnel_port_add_t  udp_tunnel_port_add; /** Add UDP tunnel port. */
655         eth_udp_tunnel_port_del_t  udp_tunnel_port_del; /** Del UDP tunnel port. */
656         eth_l2_tunnel_eth_type_conf_t l2_tunnel_eth_type_conf;
657         /** Config ether type of l2 tunnel. */
658         eth_l2_tunnel_offload_set_t   l2_tunnel_offload_set;
659         /** Enable/disable l2 tunnel offload functions. */
660
661         eth_set_queue_rate_limit_t set_queue_rate_limit; /**< Set queue rate limit. */
662
663         rss_hash_update_t          rss_hash_update; /** Configure RSS hash protocols. */
664         rss_hash_conf_get_t        rss_hash_conf_get; /** Get current RSS hash configuration. */
665         reta_update_t              reta_update;   /** Update redirection table. */
666         reta_query_t               reta_query;    /** Query redirection table. */
667
668         eth_get_reg_t              get_reg;           /**< Get registers. */
669         eth_get_eeprom_length_t    get_eeprom_length; /**< Get eeprom length. */
670         eth_get_eeprom_t           get_eeprom;        /**< Get eeprom data. */
671         eth_set_eeprom_t           set_eeprom;        /**< Set eeprom. */
672
673         eth_get_module_info_t      get_module_info;
674         /** Get plugin module eeprom attribute. */
675         eth_get_module_eeprom_t    get_module_eeprom;
676         /** Get plugin module eeprom data. */
677
678         eth_filter_ctrl_t          filter_ctrl; /**< common filter control. */
679
680         eth_get_dcb_info           get_dcb_info; /** Get DCB information. */
681
682         eth_timesync_enable_t      timesync_enable;
683         /** Turn IEEE1588/802.1AS timestamping on. */
684         eth_timesync_disable_t     timesync_disable;
685         /** Turn IEEE1588/802.1AS timestamping off. */
686         eth_timesync_read_rx_timestamp_t timesync_read_rx_timestamp;
687         /** Read the IEEE1588/802.1AS RX timestamp. */
688         eth_timesync_read_tx_timestamp_t timesync_read_tx_timestamp;
689         /** Read the IEEE1588/802.1AS TX timestamp. */
690         eth_timesync_adjust_time   timesync_adjust_time; /** Adjust the device clock. */
691         eth_timesync_read_time     timesync_read_time; /** Get the device clock time. */
692         eth_timesync_write_time    timesync_write_time; /** Set the device clock time. */
693
694         eth_read_clock             read_clock;
695
696         eth_xstats_get_by_id_t     xstats_get_by_id;
697         /**< Get extended device statistic values by ID. */
698         eth_xstats_get_names_by_id_t xstats_get_names_by_id;
699         /**< Get name of extended device statistics by ID. */
700
701         eth_tm_ops_get_t tm_ops_get;
702         /**< Get Traffic Management (TM) operations. */
703
704         eth_mtr_ops_get_t mtr_ops_get;
705         /**< Get Traffic Metering and Policing (MTR) operations. */
706
707         eth_pool_ops_supported_t pool_ops_supported;
708         /**< Test if a port supports specific mempool ops */
709
710         eth_hairpin_cap_get_t hairpin_cap_get;
711         /**< Returns the hairpin capabilities. */
712         eth_rx_hairpin_queue_setup_t rx_hairpin_queue_setup;
713         /**< Set up device RX hairpin queue. */
714         eth_tx_hairpin_queue_setup_t tx_hairpin_queue_setup;
715         /**< Set up device TX hairpin queue. */
716 };
717
718 /**
719  * RX/TX queue states
720  */
721 #define RTE_ETH_QUEUE_STATE_STOPPED 0
722 #define RTE_ETH_QUEUE_STATE_STARTED 1
723 #define RTE_ETH_QUEUE_STATE_HAIRPIN 2
724
725 /**
726  * @internal
727  * Check if the selected Rx queue is hairpin queue.
728  *
729  * @param dev
730  *  Pointer to the selected device.
731  * @param queue_id
732  *  The selected queue.
733  *
734  * @return
735  *   - (1) if the queue is hairpin queue, 0 otherwise.
736  */
737 __rte_internal
738 int rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id);
739
740 /**
741  * @internal
742  * Check if the selected Tx queue is hairpin queue.
743  *
744  * @param dev
745  *  Pointer to the selected device.
746  * @param queue_id
747  *  The selected queue.
748  *
749  * @return
750  *   - (1) if the queue is hairpin queue, 0 otherwise.
751  */
752 __rte_internal
753 int rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id);
754
755 /**
756  * @internal
757  * Returns a ethdev slot specified by the unique identifier name.
758  *
759  * @param       name
760  *  The pointer to the Unique identifier name for each Ethernet device
761  * @return
762  *   - The pointer to the ethdev slot, on success. NULL on error
763  */
764 __rte_internal
765 struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
766
767 /**
768  * @internal
769  * Allocates a new ethdev slot for an ethernet device and returns the pointer
770  * to that slot for the driver to use.
771  *
772  * @param       name    Unique identifier name for each Ethernet device
773  * @return
774  *   - Slot in the rte_dev_devices array for a new device;
775  */
776 __rte_internal
777 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
778
779 /**
780  * @internal
781  * Attach to the ethdev already initialized by the primary
782  * process.
783  *
784  * @param       name    Ethernet device's name.
785  * @return
786  *   - Success: Slot in the rte_dev_devices array for attached
787  *        device.
788  *   - Error: Null pointer.
789  */
790 __rte_internal
791 struct rte_eth_dev *rte_eth_dev_attach_secondary(const char *name);
792
793 /**
794  * @internal
795  * Notify RTE_ETH_EVENT_DESTROY and release the specified ethdev port.
796  *
797  * The following PMD-managed data fields will be freed:
798  *   - dev_private
799  *   - mac_addrs
800  *   - hash_mac_addrs
801  * If one of these fields should not be freed,
802  * it must be reset to NULL by the PMD, typically in dev_close method.
803  *
804  * @param eth_dev
805  * Device to be detached.
806  * @return
807  *   - 0 on success, negative on error
808  */
809 __rte_internal
810 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
811
812 /**
813  * @internal
814  * Release device queues and clear its configuration to force the user
815  * application to reconfigure it. It is for internal use only.
816  *
817  * @param dev
818  *  Pointer to struct rte_eth_dev.
819  *
820  * @return
821  *  void
822  */
823 __rte_internal
824 void _rte_eth_dev_reset(struct rte_eth_dev *dev);
825
826 /**
827  * @internal Executes all the user application registered callbacks for
828  * the specific device. It is for DPDK internal user only. User
829  * application should not call it directly.
830  *
831  * @param dev
832  *  Pointer to struct rte_eth_dev.
833  * @param event
834  *  Eth device interrupt event type.
835  * @param ret_param
836  *  To pass data back to user application.
837  *  This allows the user application to decide if a particular function
838  *  is permitted or not.
839  *
840  * @return
841  *  int
842  */
843 __rte_internal
844 int _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
845                 enum rte_eth_event_type event, void *ret_param);
846
847 /**
848  * @internal
849  * This is the last step of device probing.
850  * It must be called after a port is allocated and initialized successfully.
851  *
852  * The notification RTE_ETH_EVENT_NEW is sent to other entities
853  * (libraries and applications).
854  * The state is set as RTE_ETH_DEV_ATTACHED.
855  *
856  * @param dev
857  *  New ethdev port.
858  */
859 __rte_internal
860 void rte_eth_dev_probing_finish(struct rte_eth_dev *dev);
861
862 /**
863  * Create memzone for HW rings.
864  * malloc can't be used as the physical address is needed.
865  * If the memzone is already created, then this function returns a ptr
866  * to the old one.
867  *
868  * @param eth_dev
869  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
870  * @param name
871  *   The name of the memory zone
872  * @param queue_id
873  *   The index of the queue to add to name
874  * @param size
875  *   The sizeof of the memory area
876  * @param align
877  *   Alignment for resulting memzone. Must be a power of 2.
878  * @param socket_id
879  *   The *socket_id* argument is the socket identifier in case of NUMA.
880  */
881 __rte_internal
882 const struct rte_memzone *
883 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
884                          uint16_t queue_id, size_t size,
885                          unsigned align, int socket_id);
886
887 /**
888  * Free previously allocated memzone for HW rings.
889  *
890  * @param eth_dev
891  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
892  * @param name
893  *   The name of the memory zone
894  * @param queue_id
895  *   The index of the queue to add to name
896  * @return
897  *   Negative errno value on error, 0 on success.
898  */
899 __rte_internal
900 int
901 rte_eth_dma_zone_free(const struct rte_eth_dev *eth_dev, const char *name,
902                  uint16_t queue_id);
903
904 /**
905  * @internal
906  * Atomically set the link status for the specific device.
907  * It is for use by DPDK device driver use only.
908  * User applications should not call it
909  *
910  * @param dev
911  *  Pointer to struct rte_eth_dev.
912  * @param link
913  *  New link status value.
914  * @return
915  *  Same convention as eth_link_update operation.
916  *  0   if link up status has changed
917  *  -1  if link up status was unchanged
918  */
919 static inline int
920 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
921                        const struct rte_eth_link *new_link)
922 {
923         volatile uint64_t *dev_link
924                  = (volatile uint64_t *)&(dev->data->dev_link);
925         union {
926                 uint64_t val64;
927                 struct rte_eth_link link;
928         } orig;
929
930         RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
931
932         orig.val64 = rte_atomic64_exchange(dev_link,
933                                            *(const uint64_t *)new_link);
934
935         return (orig.link.link_status == new_link->link_status) ? -1 : 0;
936 }
937
938 /**
939  * @internal
940  * Atomically get the link speed and status.
941  *
942  * @param dev
943  *  Pointer to struct rte_eth_dev.
944  * @param link
945  *  link status value.
946  */
947 static inline void
948 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
949                        struct rte_eth_link *link)
950 {
951         volatile uint64_t *src = (uint64_t *)&(dev->data->dev_link);
952         uint64_t *dst = (uint64_t *)link;
953
954         RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
955
956 #ifdef __LP64__
957         /* if cpu arch has 64 bit unsigned lon then implicitly atomic */
958         *dst = *src;
959 #else
960         /* can't use rte_atomic64_read because it returns signed int */
961         do {
962                 *dst = *src;
963         } while (!rte_atomic64_cmpset(src, *dst, *dst));
964 #endif
965 }
966
967 /**
968  * Allocate an unique switch domain identifier.
969  *
970  * A pool of switch domain identifiers which can be allocated on request. This
971  * will enabled devices which support the concept of switch domains to request
972  * a switch domain id which is guaranteed to be unique from other devices
973  * running in the same process.
974  *
975  * @param domain_id
976  *  switch domain identifier parameter to pass back to application
977  *
978  * @return
979  *   Negative errno value on error, 0 on success.
980  */
981 __rte_internal
982 int
983 rte_eth_switch_domain_alloc(uint16_t *domain_id);
984
985 /**
986  * Free switch domain.
987  *
988  * Return a switch domain identifier to the pool of free identifiers after it is
989  * no longer in use by device.
990  *
991  * @param domain_id
992  *  switch domain identifier to free
993  *
994  * @return
995  *   Negative errno value on error, 0 on success.
996  */
997 __rte_internal
998 int
999 rte_eth_switch_domain_free(uint16_t domain_id);
1000
1001 /** Generic Ethernet device arguments  */
1002 struct rte_eth_devargs {
1003         uint16_t ports[RTE_MAX_ETHPORTS];
1004         /** port/s number to enable on a multi-port single function */
1005         uint16_t nb_ports;
1006         /** number of ports in ports field */
1007         uint16_t representor_ports[RTE_MAX_ETHPORTS];
1008         /** representor port/s identifier to enable on device */
1009         uint16_t nb_representor_ports;
1010         /** number of ports in representor port field */
1011 };
1012
1013 /**
1014  * PMD helper function to parse ethdev arguments
1015  *
1016  * @param devargs
1017  *  device arguments
1018  * @param eth_devargs
1019  *  parsed ethdev specific arguments.
1020  *
1021  * @return
1022  *   Negative errno value on error, 0 on success.
1023  */
1024 __rte_internal
1025 int
1026 rte_eth_devargs_parse(const char *devargs, struct rte_eth_devargs *eth_devargs);
1027
1028
1029 typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void *init_params);
1030 typedef int (*ethdev_bus_specific_init)(struct rte_eth_dev *ethdev,
1031         void *bus_specific_init_params);
1032
1033 /**
1034  * PMD helper function for the creation of a new ethdev ports.
1035  *
1036  * @param device
1037  *  rte_device handle.
1038  * @param name
1039  *  port name.
1040  * @param priv_data_size
1041  *  size of private data required for port.
1042  * @param bus_specific_init
1043  *  port bus specific initialisation callback function
1044  * @param bus_init_params
1045  *  port bus specific initialisation parameters
1046  * @param ethdev_init
1047  *  device specific port initialization callback function
1048  * @param init_params
1049  *  port initialisation parameters
1050  *
1051  * @return
1052  *   Negative errno value on error, 0 on success.
1053  */
1054 __rte_internal
1055 int
1056 rte_eth_dev_create(struct rte_device *device, const char *name,
1057         size_t priv_data_size,
1058         ethdev_bus_specific_init bus_specific_init, void *bus_init_params,
1059         ethdev_init_t ethdev_init, void *init_params);
1060
1061
1062 typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev);
1063
1064 /**
1065  * PMD helper function for cleaning up the resources of a ethdev port on it's
1066  * destruction.
1067  *
1068  * @param ethdev
1069  *   ethdev handle of port.
1070  * @param ethdev_uninit
1071  *   device specific port un-initialise callback function
1072  *
1073  * @return
1074  *   Negative errno value on error, 0 on success.
1075  */
1076 __rte_internal
1077 int
1078 rte_eth_dev_destroy(struct rte_eth_dev *ethdev, ethdev_uninit_t ethdev_uninit);
1079
1080 #ifdef __cplusplus
1081 }
1082 #endif
1083
1084 #endif /* _RTE_ETHDEV_DRIVER_H_ */