1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
5 #ifndef _RTE_ETHDEV_DRIVER_H_
6 #define _RTE_ETHDEV_DRIVER_H_
11 * RTE Ethernet Device PMD API
13 * These APIs for the use from Ethernet drivers, user applications shouldn't
18 #include <rte_ethdev.h>
26 * Returns a ethdev slot specified by the unique identifier name.
29 * The pointer to the Unique identifier name for each Ethernet device
31 * - The pointer to the ethdev slot, on success. NULL on error
33 struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
37 * Allocates a new ethdev slot for an ethernet device and returns the pointer
38 * to that slot for the driver to use.
40 * @param name Unique identifier name for each Ethernet device
42 * - Slot in the rte_dev_devices array for a new device;
44 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
48 * Attach to the ethdev already initialized by the primary
51 * @param name Ethernet device's name.
53 * - Success: Slot in the rte_dev_devices array for attached
55 * - Error: Null pointer.
57 struct rte_eth_dev *rte_eth_dev_attach_secondary(const char *name);
61 * Release the specified ethdev port.
64 * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
66 * - 0 on success, negative on error
68 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
72 * Release device queues and clear its configuration to force the user
73 * application to reconfigure it. It is for internal use only.
76 * Pointer to struct rte_eth_dev.
81 void _rte_eth_dev_reset(struct rte_eth_dev *dev);
84 * @internal Executes all the user application registered callbacks for
85 * the specific device. It is for DPDK internal user only. User
86 * application should not call it directly.
89 * Pointer to struct rte_eth_dev.
91 * Eth device interrupt event type.
93 * To pass data back to user application.
94 * This allows the user application to decide if a particular function
95 * is permitted or not.
100 int _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
101 enum rte_eth_event_type event, void *ret_param);
105 * This is the last step of device probing.
106 * It must be called after a port is allocated and initialized successfully.
108 * The notification RTE_ETH_EVENT_NEW is sent to other entities
109 * (libraries and applications).
110 * The state is set as RTE_ETH_DEV_ATTACHED.
115 void rte_eth_dev_probing_finish(struct rte_eth_dev *dev);
118 * Create memzone for HW rings.
119 * malloc can't be used as the physical address is needed.
120 * If the memzone is already created, then this function returns a ptr
124 * The *eth_dev* pointer is the address of the *rte_eth_dev* structure
126 * The name of the memory zone
128 * The index of the queue to add to name
130 * The sizeof of the memory area
132 * Alignment for resulting memzone. Must be a power of 2.
134 * The *socket_id* argument is the socket identifier in case of NUMA.
136 const struct rte_memzone *
137 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
138 uint16_t queue_id, size_t size,
139 unsigned align, int socket_id);
143 * Atomically set the link status for the specific device.
144 * It is for use by DPDK device driver use only.
145 * User applications should not call it
148 * Pointer to struct rte_eth_dev.
150 * New link status value.
152 * Same convention as eth_link_update operation.
153 * 0 if link up status has changed
154 * -1 if link up status was unchanged
157 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
158 const struct rte_eth_link *new_link)
160 volatile uint64_t *dev_link
161 = (volatile uint64_t *)&(dev->data->dev_link);
164 struct rte_eth_link link;
167 RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
169 orig.val64 = rte_atomic64_exchange(dev_link,
170 *(const uint64_t *)new_link);
172 return (orig.link.link_status == new_link->link_status) ? -1 : 0;
177 * Atomically get the link speed and status.
180 * Pointer to struct rte_eth_dev.
185 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
186 struct rte_eth_link *link)
188 volatile uint64_t *src = (uint64_t *)&(dev->data->dev_link);
189 uint64_t *dst = (uint64_t *)link;
191 RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
194 /* if cpu arch has 64 bit unsigned lon then implicitly atomic */
197 /* can't use rte_atomic64_read because it returns signed int */
200 } while (!rte_atomic64_cmpset(src, *dst, *dst));
206 * @b EXPERIMENTAL: this API may change without prior notice.
208 * Allocate an unique switch domain identifier.
210 * A pool of switch domain identifiers which can be allocated on request. This
211 * will enabled devices which support the concept of switch domains to request
212 * a switch domain id which is guaranteed to be unique from other devices
213 * running in the same process.
216 * switch domain identifier parameter to pass back to application
219 * Negative errno value on error, 0 on success.
221 int __rte_experimental
222 rte_eth_switch_domain_alloc(uint16_t *domain_id);
226 * @b EXPERIMENTAL: this API may change without prior notice.
228 * Free switch domain.
230 * Return a switch domain identifier to the pool of free identifiers after it is
231 * no longer in use by device.
234 * switch domain identifier to free
237 * Negative errno value on error, 0 on success.
239 int __rte_experimental
240 rte_eth_switch_domain_free(uint16_t domain_id);
242 /** Generic Ethernet device arguments */
243 struct rte_eth_devargs {
244 uint16_t ports[RTE_MAX_ETHPORTS];
245 /** port/s number to enable on a multi-port single function */
247 /** number of ports in ports field */
248 uint16_t representor_ports[RTE_MAX_ETHPORTS];
249 /** representor port/s identifier to enable on device */
250 uint16_t nb_representor_ports;
251 /** number of ports in representor port field */
256 * @b EXPERIMENTAL: this API may change without prior notice.
258 * PMD helper function to parse ethdev arguments
263 * parsed ethdev specific arguments.
266 * Negative errno value on error, 0 on success.
268 int __rte_experimental
269 rte_eth_devargs_parse(const char *devargs, struct rte_eth_devargs *eth_devargs);
272 typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void *init_params);
273 typedef int (*ethdev_bus_specific_init)(struct rte_eth_dev *ethdev,
274 void *bus_specific_init_params);
278 * @b EXPERIMENTAL: this API may change without prior notice.
280 * PMD helper function for the creation of a new ethdev ports.
286 * @param priv_data_size
287 * size of private data required for port.
288 * @param bus_specific_init
289 * port bus specific initialisation callback function
290 * @param bus_init_params
291 * port bus specific initialisation parameters
293 * device specific port initialization callback function
295 * port initialisation parameters
298 * Negative errno value on error, 0 on success.
300 int __rte_experimental
301 rte_eth_dev_create(struct rte_device *device, const char *name,
302 size_t priv_data_size,
303 ethdev_bus_specific_init bus_specific_init, void *bus_init_params,
304 ethdev_init_t ethdev_init, void *init_params);
307 typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev);
311 * @b EXPERIMENTAL: this API may change without prior notice.
313 * PMD helper function for cleaing up the resources of a ethdev port on it's
317 * ethdev handle of port.
318 * @param ethdev_uninit
319 * device specific port un-initialise callback function
322 * Negative errno value on error, 0 on success.
324 int __rte_experimental
325 rte_eth_dev_destroy(struct rte_eth_dev *ethdev, ethdev_uninit_t ethdev_uninit);
331 #endif /* _RTE_ETHDEV_DRIVER_H_ */