xref: /dpdk/lib/eal/include/rte_dev.h (revision 719834a6849e1daf4a70ff7742bbcc3ae7e25607)
199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
299a2dd95SBruce Richardson  * Copyright(c) 2014 6WIND S.A.
399a2dd95SBruce Richardson  */
499a2dd95SBruce Richardson 
599a2dd95SBruce Richardson #ifndef _RTE_DEV_H_
699a2dd95SBruce Richardson #define _RTE_DEV_H_
799a2dd95SBruce Richardson 
899a2dd95SBruce Richardson /**
999a2dd95SBruce Richardson  * @file
1099a2dd95SBruce Richardson  *
11f8dbaebbSSean Morrissey  * RTE PMD Registration Interface
1299a2dd95SBruce Richardson  *
1399a2dd95SBruce Richardson  * This file manages the list of device drivers.
1499a2dd95SBruce Richardson  */
1599a2dd95SBruce Richardson 
1699a2dd95SBruce Richardson #include <stdio.h>
1799a2dd95SBruce Richardson 
1899a2dd95SBruce Richardson #include <rte_config.h>
198f1d23ecSDavid Marchand #include <rte_common.h>
2099a2dd95SBruce Richardson #include <rte_log.h>
2199a2dd95SBruce Richardson 
22*719834a6SMattias Rönnblom #ifdef __cplusplus
23*719834a6SMattias Rönnblom extern "C" {
24*719834a6SMattias Rönnblom #endif
25*719834a6SMattias Rönnblom 
26ec5ecd7eSDavid Marchand struct rte_bus;
27ec5ecd7eSDavid Marchand struct rte_devargs;
28ec5ecd7eSDavid Marchand struct rte_device;
291acb7f54SDavid Marchand struct rte_driver;
301acb7f54SDavid Marchand 
3199a2dd95SBruce Richardson /**
3299a2dd95SBruce Richardson  * The device event type.
3399a2dd95SBruce Richardson  */
3499a2dd95SBruce Richardson enum rte_dev_event_type {
3599a2dd95SBruce Richardson 	RTE_DEV_EVENT_ADD,	/**< device being added */
3699a2dd95SBruce Richardson 	RTE_DEV_EVENT_REMOVE,	/**< device being removed */
3799a2dd95SBruce Richardson 	RTE_DEV_EVENT_MAX	/**< max value of this enum */
3899a2dd95SBruce Richardson };
3999a2dd95SBruce Richardson 
4099a2dd95SBruce Richardson typedef void (*rte_dev_event_cb_fn)(const char *device_name,
4199a2dd95SBruce Richardson 					enum rte_dev_event_type event,
4299a2dd95SBruce Richardson 					void *cb_arg);
4399a2dd95SBruce Richardson 
4499a2dd95SBruce Richardson /**
4599a2dd95SBruce Richardson  * Device policies.
4699a2dd95SBruce Richardson  */
4799a2dd95SBruce Richardson enum rte_dev_policy {
4899a2dd95SBruce Richardson 	RTE_DEV_ALLOWED,
4999a2dd95SBruce Richardson 	RTE_DEV_BLOCKED,
5099a2dd95SBruce Richardson };
5199a2dd95SBruce Richardson 
5299a2dd95SBruce Richardson /**
5399a2dd95SBruce Richardson  * A generic memory resource representation.
5499a2dd95SBruce Richardson  */
5599a2dd95SBruce Richardson struct rte_mem_resource {
5699a2dd95SBruce Richardson 	uint64_t phys_addr; /**< Physical address, 0 if not resource. */
5799a2dd95SBruce Richardson 	uint64_t len;       /**< Length of the resource. */
5899a2dd95SBruce Richardson 	void *addr;         /**< Virtual address, NULL when not mapped. */
5999a2dd95SBruce Richardson };
6099a2dd95SBruce Richardson 
6199a2dd95SBruce Richardson /**
6297bbdba3SDavid Marchand  * Retrieve a driver name.
6397bbdba3SDavid Marchand  *
6497bbdba3SDavid Marchand  * @param driver
6597bbdba3SDavid Marchand  *   A pointer to a driver structure.
6697bbdba3SDavid Marchand  * @return
6797bbdba3SDavid Marchand  *   A pointer to the driver name string.
6897bbdba3SDavid Marchand  */
6997bbdba3SDavid Marchand const char *
7097bbdba3SDavid Marchand rte_driver_name(const struct rte_driver *driver);
7197bbdba3SDavid Marchand 
72ec5ecd7eSDavid Marchand /**
73ec5ecd7eSDavid Marchand  * Retrieve a device bus.
74ec5ecd7eSDavid Marchand  *
75ec5ecd7eSDavid Marchand  * @param dev
76ec5ecd7eSDavid Marchand  *   A pointer to a device structure.
77ec5ecd7eSDavid Marchand  * @return
78ec5ecd7eSDavid Marchand  *   A pointer to this device bus.
79ec5ecd7eSDavid Marchand  */
80ec5ecd7eSDavid Marchand const struct rte_bus *
81ec5ecd7eSDavid Marchand rte_dev_bus(const struct rte_device *dev);
82ec5ecd7eSDavid Marchand 
83ec5ecd7eSDavid Marchand /**
845b569f2eSDavid Marchand  * Retrieve bus specific information for a device.
855b569f2eSDavid Marchand  *
865b569f2eSDavid Marchand  * @param dev
875b569f2eSDavid Marchand  *   A pointer to a device structure.
885b569f2eSDavid Marchand  * @return
895b569f2eSDavid Marchand  *   A string describing this device or NULL if none is available.
905b569f2eSDavid Marchand  */
915b569f2eSDavid Marchand const char *
925b569f2eSDavid Marchand rte_dev_bus_info(const struct rte_device *dev);
935b569f2eSDavid Marchand 
945b569f2eSDavid Marchand /**
95ec5ecd7eSDavid Marchand  * Retrieve a device arguments.
96ec5ecd7eSDavid Marchand  *
97ec5ecd7eSDavid Marchand  * @param dev
98ec5ecd7eSDavid Marchand  *   A pointer to a device structure.
99ec5ecd7eSDavid Marchand  * @return
100ec5ecd7eSDavid Marchand  *   A pointer to this device devargs.
101ec5ecd7eSDavid Marchand  */
102ec5ecd7eSDavid Marchand const struct rte_devargs *
103ec5ecd7eSDavid Marchand rte_dev_devargs(const struct rte_device *dev);
104ec5ecd7eSDavid Marchand 
105ec5ecd7eSDavid Marchand /**
106ec5ecd7eSDavid Marchand  * Retrieve a device driver.
107ec5ecd7eSDavid Marchand  *
108ec5ecd7eSDavid Marchand  * @param dev
109ec5ecd7eSDavid Marchand  *   A pointer to a device structure.
110ec5ecd7eSDavid Marchand  * @return
111ec5ecd7eSDavid Marchand  *   A pointer to this device driver.
112ec5ecd7eSDavid Marchand  */
113ec5ecd7eSDavid Marchand const struct rte_driver *
114ec5ecd7eSDavid Marchand rte_dev_driver(const struct rte_device *dev);
115ec5ecd7eSDavid Marchand 
116ec5ecd7eSDavid Marchand /**
117ec5ecd7eSDavid Marchand  * Retrieve a device name.
118ec5ecd7eSDavid Marchand  *
119ec5ecd7eSDavid Marchand  * @param dev
120ec5ecd7eSDavid Marchand  *   A pointer to a device structure.
121ec5ecd7eSDavid Marchand  * @return
122ec5ecd7eSDavid Marchand  *   A pointer to this device name.
123ec5ecd7eSDavid Marchand  */
124ec5ecd7eSDavid Marchand const char *
125ec5ecd7eSDavid Marchand rte_dev_name(const struct rte_device *dev);
126ec5ecd7eSDavid Marchand 
127ec5ecd7eSDavid Marchand /**
128ec5ecd7eSDavid Marchand  * Retrieve a device numa node.
129ec5ecd7eSDavid Marchand  *
130ec5ecd7eSDavid Marchand  * @param dev
131ec5ecd7eSDavid Marchand  *   A pointer to a device structure.
132ec5ecd7eSDavid Marchand  * @return
133ec5ecd7eSDavid Marchand  *   A pointer to this device numa node.
134ec5ecd7eSDavid Marchand  */
135ec5ecd7eSDavid Marchand int
136ec5ecd7eSDavid Marchand rte_dev_numa_node(const struct rte_device *dev);
137ec5ecd7eSDavid Marchand 
13899a2dd95SBruce Richardson /*
13999a2dd95SBruce Richardson  * Internal identifier length
14099a2dd95SBruce Richardson  * Sufficiently large to allow for UUID or PCI address
14199a2dd95SBruce Richardson  */
14299a2dd95SBruce Richardson #define RTE_DEV_NAME_MAX_LEN 64
14399a2dd95SBruce Richardson 
14499a2dd95SBruce Richardson /**
14599a2dd95SBruce Richardson  * Query status of a device.
14699a2dd95SBruce Richardson  *
14799a2dd95SBruce Richardson  * @param dev
14899a2dd95SBruce Richardson  *   Generic device pointer.
14999a2dd95SBruce Richardson  * @return
15099a2dd95SBruce Richardson  *   (int)true if already probed successfully, 0 otherwise.
15199a2dd95SBruce Richardson  */
15299a2dd95SBruce Richardson int rte_dev_is_probed(const struct rte_device *dev);
15399a2dd95SBruce Richardson 
15499a2dd95SBruce Richardson /**
15599a2dd95SBruce Richardson  * Hotplug add a given device to a specific bus.
15699a2dd95SBruce Richardson  *
15799a2dd95SBruce Richardson  * In multi-process, it will request other processes to add the same device.
15899a2dd95SBruce Richardson  * A failure, in any process, will rollback the action
15999a2dd95SBruce Richardson  *
16099a2dd95SBruce Richardson  * @param busname
16199a2dd95SBruce Richardson  *   The bus name the device is added to.
16299a2dd95SBruce Richardson  * @param devname
16399a2dd95SBruce Richardson  *   The device name. Based on this device name, eal will identify a driver
16499a2dd95SBruce Richardson  *   capable of handling it and pass it to the driver probing function.
16599a2dd95SBruce Richardson  * @param drvargs
16699a2dd95SBruce Richardson  *   Device arguments to be passed to the driver.
16799a2dd95SBruce Richardson  * @return
16899a2dd95SBruce Richardson  *   0 on success, negative on error.
16999a2dd95SBruce Richardson  */
17099a2dd95SBruce Richardson int rte_eal_hotplug_add(const char *busname, const char *devname,
17199a2dd95SBruce Richardson 			const char *drvargs);
17299a2dd95SBruce Richardson 
17399a2dd95SBruce Richardson /**
17499a2dd95SBruce Richardson  * Add matching devices.
17599a2dd95SBruce Richardson  *
17699a2dd95SBruce Richardson  * In multi-process, it will request other processes to add the same device.
17799a2dd95SBruce Richardson  * A failure, in any process, will rollback the action
17899a2dd95SBruce Richardson  *
17999a2dd95SBruce Richardson  * @param devargs
18099a2dd95SBruce Richardson  *   Device arguments including bus, class and driver properties.
18199a2dd95SBruce Richardson  * @return
18299a2dd95SBruce Richardson  *   0 on success, negative on error.
18399a2dd95SBruce Richardson  */
18499a2dd95SBruce Richardson int rte_dev_probe(const char *devargs);
18599a2dd95SBruce Richardson 
18699a2dd95SBruce Richardson /**
18799a2dd95SBruce Richardson  * Hotplug remove a given device from a specific bus.
18899a2dd95SBruce Richardson  *
18999a2dd95SBruce Richardson  * In multi-process, it will request other processes to remove the same device.
19099a2dd95SBruce Richardson  * A failure, in any process, will rollback the action
19199a2dd95SBruce Richardson  *
19299a2dd95SBruce Richardson  * @param busname
19399a2dd95SBruce Richardson  *   The bus name the device is removed from.
19499a2dd95SBruce Richardson  * @param devname
19599a2dd95SBruce Richardson  *   The device name being removed.
19699a2dd95SBruce Richardson  * @return
19799a2dd95SBruce Richardson  *   0 on success, negative on error.
19899a2dd95SBruce Richardson  */
19999a2dd95SBruce Richardson int rte_eal_hotplug_remove(const char *busname, const char *devname);
20099a2dd95SBruce Richardson 
20199a2dd95SBruce Richardson /**
20299a2dd95SBruce Richardson  * Remove one device.
20399a2dd95SBruce Richardson  *
20499a2dd95SBruce Richardson  * In multi-process, it will request other processes to remove the same device.
20599a2dd95SBruce Richardson  * A failure, in any process, will rollback the action
20699a2dd95SBruce Richardson  *
20799a2dd95SBruce Richardson  * @param dev
20899a2dd95SBruce Richardson  *   Data structure of the device to remove.
20999a2dd95SBruce Richardson  * @return
21099a2dd95SBruce Richardson  *   0 on success, negative on error.
21199a2dd95SBruce Richardson  */
21299a2dd95SBruce Richardson int rte_dev_remove(struct rte_device *dev);
21399a2dd95SBruce Richardson 
21499a2dd95SBruce Richardson /**
21599a2dd95SBruce Richardson  * Device comparison function.
21699a2dd95SBruce Richardson  *
21799a2dd95SBruce Richardson  * This type of function is used to compare an rte_device with arbitrary
21899a2dd95SBruce Richardson  * data.
21999a2dd95SBruce Richardson  *
22099a2dd95SBruce Richardson  * @param dev
22199a2dd95SBruce Richardson  *   Device handle.
22299a2dd95SBruce Richardson  *
22399a2dd95SBruce Richardson  * @param data
22499a2dd95SBruce Richardson  *   Data to compare against. The type of this parameter is determined by
22599a2dd95SBruce Richardson  *   the kind of comparison performed by the function.
22699a2dd95SBruce Richardson  *
22799a2dd95SBruce Richardson  * @return
22899a2dd95SBruce Richardson  *   0 if the device matches the data.
22999a2dd95SBruce Richardson  *   !0 if the device does not match.
23099a2dd95SBruce Richardson  *   <0 if ordering is possible and the device is lower than the data.
23199a2dd95SBruce Richardson  *   >0 if ordering is possible and the device is greater than the data.
23299a2dd95SBruce Richardson  */
23399a2dd95SBruce Richardson typedef int (*rte_dev_cmp_t)(const struct rte_device *dev, const void *data);
23499a2dd95SBruce Richardson 
23599a2dd95SBruce Richardson #define RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]
23699a2dd95SBruce Richardson 
23799a2dd95SBruce Richardson #define RTE_PMD_EXPORT_NAME(name, idx) \
23899a2dd95SBruce Richardson static const char RTE_PMD_EXPORT_NAME_ARRAY(this_pmd_name, idx) \
23999a2dd95SBruce Richardson __rte_used = RTE_STR(name)
24099a2dd95SBruce Richardson 
24199a2dd95SBruce Richardson #define DRV_EXP_TAG(name, tag) __##name##_##tag
24299a2dd95SBruce Richardson 
24399a2dd95SBruce Richardson #define RTE_PMD_REGISTER_PCI_TABLE(name, table) \
24499a2dd95SBruce Richardson static const char DRV_EXP_TAG(name, pci_tbl_export)[] __rte_used = \
24599a2dd95SBruce Richardson RTE_STR(table)
24699a2dd95SBruce Richardson 
24799a2dd95SBruce Richardson #define RTE_PMD_REGISTER_PARAM_STRING(name, str) \
24899a2dd95SBruce Richardson static const char DRV_EXP_TAG(name, param_string_export)[] \
24999a2dd95SBruce Richardson __rte_used = str
25099a2dd95SBruce Richardson 
25199a2dd95SBruce Richardson /**
25299a2dd95SBruce Richardson  * Advertise the list of kernel modules required to run this driver
25399a2dd95SBruce Richardson  *
25499a2dd95SBruce Richardson  * This string lists the kernel modules required for the devices
25599a2dd95SBruce Richardson  * associated to a PMD. The format of each line of the string is:
25699a2dd95SBruce Richardson  * "<device-pattern> <kmod-expression>".
25799a2dd95SBruce Richardson  *
25899a2dd95SBruce Richardson  * The possible formats for the device pattern are:
25999a2dd95SBruce Richardson  *   "*"                     all devices supported by this driver
26099a2dd95SBruce Richardson  *   "pci:*"                 all PCI devices supported by this driver
26199a2dd95SBruce Richardson  *   "pci:v8086:d*:sv*:sd*"  all PCI devices supported by this driver
26299a2dd95SBruce Richardson  *                           whose vendor id is 0x8086.
26399a2dd95SBruce Richardson  *
26499a2dd95SBruce Richardson  * The format of the kernel modules list is a parenthesized expression
26599a2dd95SBruce Richardson  * containing logical-and (&) and logical-or (|).
26699a2dd95SBruce Richardson  *
26799a2dd95SBruce Richardson  * The device pattern and the kmod expression are separated by a space.
26899a2dd95SBruce Richardson  *
26999a2dd95SBruce Richardson  * Example:
27099a2dd95SBruce Richardson  * - "* igb_uio | uio_pci_generic | vfio"
27199a2dd95SBruce Richardson  */
27299a2dd95SBruce Richardson #define RTE_PMD_REGISTER_KMOD_DEP(name, str) \
27399a2dd95SBruce Richardson static const char DRV_EXP_TAG(name, kmod_dep_export)[] \
27499a2dd95SBruce Richardson __rte_used = str
27599a2dd95SBruce Richardson 
27699a2dd95SBruce Richardson /**
27799a2dd95SBruce Richardson  * Iteration context.
27899a2dd95SBruce Richardson  *
27999a2dd95SBruce Richardson  * This context carries over the current iteration state.
28099a2dd95SBruce Richardson  */
28199a2dd95SBruce Richardson struct rte_dev_iterator {
28299a2dd95SBruce Richardson 	const char *dev_str; /**< device string. */
28399a2dd95SBruce Richardson 	const char *bus_str; /**< bus-related part of device string. */
28499a2dd95SBruce Richardson 	const char *cls_str; /**< class-related part of device string. */
28599a2dd95SBruce Richardson 	struct rte_bus *bus; /**< bus handle. */
28699a2dd95SBruce Richardson 	struct rte_class *cls; /**< class handle. */
28799a2dd95SBruce Richardson 	struct rte_device *device; /**< current position. */
28899a2dd95SBruce Richardson 	void *class_device; /**< additional specialized context. */
28999a2dd95SBruce Richardson };
29099a2dd95SBruce Richardson 
29199a2dd95SBruce Richardson /**
29299a2dd95SBruce Richardson  * Device iteration function.
29399a2dd95SBruce Richardson  *
29499a2dd95SBruce Richardson  * Find the next device matching properties passed in parameters.
29599a2dd95SBruce Richardson  * The function takes an additional ``start`` parameter, that is
29699a2dd95SBruce Richardson  * used as starting context when relevant.
29799a2dd95SBruce Richardson  *
29899a2dd95SBruce Richardson  * The function returns the current element in the iteration.
29999a2dd95SBruce Richardson  * This return value will potentially be used as a start parameter
30099a2dd95SBruce Richardson  * in subsequent calls to the function.
30199a2dd95SBruce Richardson  *
30299a2dd95SBruce Richardson  * The additional iterator parameter is only there if a specific
30399a2dd95SBruce Richardson  * implementation needs additional context. It must not be modified by
30499a2dd95SBruce Richardson  * the iteration function itself.
30599a2dd95SBruce Richardson  *
30699a2dd95SBruce Richardson  * @param start
30799a2dd95SBruce Richardson  *   Starting iteration context.
30899a2dd95SBruce Richardson  *
30999a2dd95SBruce Richardson  * @param devstr
31099a2dd95SBruce Richardson  *   Device description string.
31199a2dd95SBruce Richardson  *
31299a2dd95SBruce Richardson  * @param it
31399a2dd95SBruce Richardson  *   Device iterator.
31499a2dd95SBruce Richardson  *
31599a2dd95SBruce Richardson  * @return
31699a2dd95SBruce Richardson  *   The address of the current element matching the device description
31799a2dd95SBruce Richardson  *   string.
31899a2dd95SBruce Richardson  */
31999a2dd95SBruce Richardson typedef void *(*rte_dev_iterate_t)(const void *start,
32099a2dd95SBruce Richardson 				   const char *devstr,
32199a2dd95SBruce Richardson 				   const struct rte_dev_iterator *it);
32299a2dd95SBruce Richardson 
32399a2dd95SBruce Richardson /**
32499a2dd95SBruce Richardson  * Initializes a device iterator.
32599a2dd95SBruce Richardson  *
32699a2dd95SBruce Richardson  * This iterator allows accessing a list of devices matching a criteria.
32799a2dd95SBruce Richardson  * The device matching is made among all buses and classes currently registered,
32899a2dd95SBruce Richardson  * filtered by the device description given as parameter.
32999a2dd95SBruce Richardson  *
33099a2dd95SBruce Richardson  * This function will not allocate any memory. It is safe to stop the
33199a2dd95SBruce Richardson  * iteration at any moment and let the iterator go out of context.
33299a2dd95SBruce Richardson  *
33399a2dd95SBruce Richardson  * @param it
33499a2dd95SBruce Richardson  *   Device iterator handle.
33599a2dd95SBruce Richardson  *
33699a2dd95SBruce Richardson  * @param str
33799a2dd95SBruce Richardson  *   Device description string.
33899a2dd95SBruce Richardson  *
33999a2dd95SBruce Richardson  * @return
34099a2dd95SBruce Richardson  *   0 on successful initialization.
34199a2dd95SBruce Richardson  *   <0 on error.
34299a2dd95SBruce Richardson  */
34399a2dd95SBruce Richardson int
34499a2dd95SBruce Richardson rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str);
34599a2dd95SBruce Richardson 
34699a2dd95SBruce Richardson /**
34799a2dd95SBruce Richardson  * Iterates on a device iterator.
34899a2dd95SBruce Richardson  *
34999a2dd95SBruce Richardson  * Generates a new rte_device handle corresponding to the next element
35099a2dd95SBruce Richardson  * in the list described in comprehension by the iterator.
35199a2dd95SBruce Richardson  *
35299a2dd95SBruce Richardson  * The next object is returned, and the iterator is updated.
35399a2dd95SBruce Richardson  *
35499a2dd95SBruce Richardson  * @param it
35599a2dd95SBruce Richardson  *   Device iterator handle.
35699a2dd95SBruce Richardson  *
35799a2dd95SBruce Richardson  * @return
35899a2dd95SBruce Richardson  *   An rte_device handle if found.
35999a2dd95SBruce Richardson  *   NULL if an error occurred (rte_errno is set).
36099a2dd95SBruce Richardson  *   NULL if no device could be found (rte_errno is not set).
36199a2dd95SBruce Richardson  */
36299a2dd95SBruce Richardson struct rte_device *
36399a2dd95SBruce Richardson rte_dev_iterator_next(struct rte_dev_iterator *it);
36499a2dd95SBruce Richardson 
36599a2dd95SBruce Richardson #define RTE_DEV_FOREACH(dev, devstr, it) \
36699a2dd95SBruce Richardson 	for (rte_dev_iterator_init(it, devstr), \
36799a2dd95SBruce Richardson 	     dev = rte_dev_iterator_next(it); \
36899a2dd95SBruce Richardson 	     dev != NULL; \
36999a2dd95SBruce Richardson 	     dev = rte_dev_iterator_next(it))
37099a2dd95SBruce Richardson 
37199a2dd95SBruce Richardson /**
37299a2dd95SBruce Richardson  * It registers the callback for the specific device.
37399a2dd95SBruce Richardson  * Multiple callbacks can be registered at the same time.
37499a2dd95SBruce Richardson  *
37599a2dd95SBruce Richardson  * @param device_name
37699a2dd95SBruce Richardson  *  The device name, that is the param name of the struct rte_device,
37799a2dd95SBruce Richardson  *  null value means for all devices.
37899a2dd95SBruce Richardson  * @param cb_fn
37999a2dd95SBruce Richardson  *  callback address.
38099a2dd95SBruce Richardson  * @param cb_arg
38199a2dd95SBruce Richardson  *  address of parameter for callback.
38299a2dd95SBruce Richardson  *
38399a2dd95SBruce Richardson  * @return
38499a2dd95SBruce Richardson  *  - On success, zero.
38599a2dd95SBruce Richardson  *  - On failure, a negative value.
38699a2dd95SBruce Richardson  */
38799a2dd95SBruce Richardson int
38899a2dd95SBruce Richardson rte_dev_event_callback_register(const char *device_name,
38999a2dd95SBruce Richardson 				rte_dev_event_cb_fn cb_fn,
39099a2dd95SBruce Richardson 				void *cb_arg);
39199a2dd95SBruce Richardson 
39299a2dd95SBruce Richardson /**
39399a2dd95SBruce Richardson  * It unregisters the callback according to the specified device.
39499a2dd95SBruce Richardson  *
39599a2dd95SBruce Richardson  * @param device_name
39699a2dd95SBruce Richardson  *  The device name, that is the param name of the struct rte_device,
39799a2dd95SBruce Richardson  *  null value means for all devices and their callbacks.
39899a2dd95SBruce Richardson  * @param cb_fn
39999a2dd95SBruce Richardson  *  callback address.
40099a2dd95SBruce Richardson  * @param cb_arg
40199a2dd95SBruce Richardson  *  address of parameter for callback, (void *)-1 means to remove all
40299a2dd95SBruce Richardson  *  registered which has the same callback address.
40399a2dd95SBruce Richardson  *
40499a2dd95SBruce Richardson  * @return
40599a2dd95SBruce Richardson  *  - On success, return the number of callback entities removed.
40699a2dd95SBruce Richardson  *  - On failure, a negative value.
40799a2dd95SBruce Richardson  */
40899a2dd95SBruce Richardson int
40999a2dd95SBruce Richardson rte_dev_event_callback_unregister(const char *device_name,
41099a2dd95SBruce Richardson 				  rte_dev_event_cb_fn cb_fn,
41199a2dd95SBruce Richardson 				  void *cb_arg);
41299a2dd95SBruce Richardson 
41399a2dd95SBruce Richardson /**
41499a2dd95SBruce Richardson  * Executes all the user application registered callbacks for
41599a2dd95SBruce Richardson  * the specific device.
41699a2dd95SBruce Richardson  *
41799a2dd95SBruce Richardson  * @param device_name
41899a2dd95SBruce Richardson  *  The device name.
41999a2dd95SBruce Richardson  * @param event
42099a2dd95SBruce Richardson  *  the device event type.
42199a2dd95SBruce Richardson  */
42299a2dd95SBruce Richardson void
42399a2dd95SBruce Richardson rte_dev_event_callback_process(const char *device_name,
42499a2dd95SBruce Richardson 			       enum rte_dev_event_type event);
42599a2dd95SBruce Richardson 
42699a2dd95SBruce Richardson /**
42799a2dd95SBruce Richardson  * Start the device event monitoring.
42899a2dd95SBruce Richardson  *
42999a2dd95SBruce Richardson  * @return
43099a2dd95SBruce Richardson  *   - On success, zero.
43199a2dd95SBruce Richardson  *   - On failure, a negative value.
43299a2dd95SBruce Richardson  */
43399a2dd95SBruce Richardson int
43499a2dd95SBruce Richardson rte_dev_event_monitor_start(void);
43599a2dd95SBruce Richardson 
43699a2dd95SBruce Richardson /**
43799a2dd95SBruce Richardson  * Stop the device event monitoring.
43899a2dd95SBruce Richardson  *
43999a2dd95SBruce Richardson  * @return
44099a2dd95SBruce Richardson  *   - On success, zero.
44199a2dd95SBruce Richardson  *   - On failure, a negative value.
44299a2dd95SBruce Richardson  */
44399a2dd95SBruce Richardson int
44499a2dd95SBruce Richardson rte_dev_event_monitor_stop(void);
44599a2dd95SBruce Richardson 
44699a2dd95SBruce Richardson /**
44799a2dd95SBruce Richardson  * Enable hotplug handling for devices.
44899a2dd95SBruce Richardson  *
44999a2dd95SBruce Richardson  * @return
45099a2dd95SBruce Richardson  *   - On success, zero.
45199a2dd95SBruce Richardson  *   - On failure, a negative value.
45299a2dd95SBruce Richardson  */
45399a2dd95SBruce Richardson int
45499a2dd95SBruce Richardson rte_dev_hotplug_handle_enable(void);
45599a2dd95SBruce Richardson 
45699a2dd95SBruce Richardson /**
45799a2dd95SBruce Richardson  * Disable hotplug handling for devices.
45899a2dd95SBruce Richardson  *
45999a2dd95SBruce Richardson  * @return
46099a2dd95SBruce Richardson  *   - On success, zero.
46199a2dd95SBruce Richardson  *   - On failure, a negative value.
46299a2dd95SBruce Richardson  */
46399a2dd95SBruce Richardson int
46499a2dd95SBruce Richardson rte_dev_hotplug_handle_disable(void);
46599a2dd95SBruce Richardson 
46699a2dd95SBruce Richardson /**
46799a2dd95SBruce Richardson  * Device level DMA map function.
46899a2dd95SBruce Richardson  * After a successful call, the memory segment will be mapped to the
46999a2dd95SBruce Richardson  * given device.
47099a2dd95SBruce Richardson  *
47199a2dd95SBruce Richardson  * @note: Memory must be registered in advance using rte_extmem_* APIs.
47299a2dd95SBruce Richardson  *
47399a2dd95SBruce Richardson  * @param dev
47499a2dd95SBruce Richardson  *	Device pointer.
47599a2dd95SBruce Richardson  * @param addr
47699a2dd95SBruce Richardson  *	Virtual address to map.
47799a2dd95SBruce Richardson  * @param iova
47899a2dd95SBruce Richardson  *	IOVA address to map.
47999a2dd95SBruce Richardson  * @param len
48099a2dd95SBruce Richardson  *	Length of the memory segment being mapped.
48199a2dd95SBruce Richardson  *
48299a2dd95SBruce Richardson  * @return
48399a2dd95SBruce Richardson  *	0 if mapping was successful.
48499a2dd95SBruce Richardson  *	Negative value and rte_errno is set otherwise.
48599a2dd95SBruce Richardson  */
48699a2dd95SBruce Richardson int
48799a2dd95SBruce Richardson rte_dev_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len);
48899a2dd95SBruce Richardson 
48999a2dd95SBruce Richardson /**
49099a2dd95SBruce Richardson  * Device level DMA unmap function.
49199a2dd95SBruce Richardson  * After a successful call, the memory segment will no longer be
49299a2dd95SBruce Richardson  * accessible by the given device.
49399a2dd95SBruce Richardson  *
49499a2dd95SBruce Richardson  * @note: Memory must be registered in advance using rte_extmem_* APIs.
49599a2dd95SBruce Richardson  *
49699a2dd95SBruce Richardson  * @param dev
49799a2dd95SBruce Richardson  *	Device pointer.
49899a2dd95SBruce Richardson  * @param addr
49999a2dd95SBruce Richardson  *	Virtual address to unmap.
50099a2dd95SBruce Richardson  * @param iova
50199a2dd95SBruce Richardson  *	IOVA address to unmap.
50299a2dd95SBruce Richardson  * @param len
50399a2dd95SBruce Richardson  *	Length of the memory segment being mapped.
50499a2dd95SBruce Richardson  *
50599a2dd95SBruce Richardson  * @return
50699a2dd95SBruce Richardson  *	0 if un-mapping was successful.
50799a2dd95SBruce Richardson  *	Negative value and rte_errno is set otherwise.
50899a2dd95SBruce Richardson  */
50999a2dd95SBruce Richardson int
51099a2dd95SBruce Richardson rte_dev_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova,
51199a2dd95SBruce Richardson 		  size_t len);
51299a2dd95SBruce Richardson 
51328c5d600STianhao Chai #ifdef __cplusplus
51428c5d600STianhao Chai }
51528c5d600STianhao Chai #endif
51628c5d600STianhao Chai 
51799a2dd95SBruce Richardson #endif /* _RTE_DEV_H_ */
518