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