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>
27 #define RTE_ETH_QUEUE_STATE_STOPPED 0
28 #define RTE_ETH_QUEUE_STATE_STARTED 1
32 * Returns a ethdev slot specified by the unique identifier name.
35 * The pointer to the Unique identifier name for each Ethernet device
37 * - The pointer to the ethdev slot, on success. NULL on error
39 struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
43 * Allocates a new ethdev slot for an ethernet device and returns the pointer
44 * to that slot for the driver to use.
46 * @param name Unique identifier name for each Ethernet device
48 * - Slot in the rte_dev_devices array for a new device;
50 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
54 * Attach to the ethdev already initialized by the primary
57 * @param name Ethernet device's name.
59 * - Success: Slot in the rte_dev_devices array for attached
61 * - Error: Null pointer.
63 struct rte_eth_dev *rte_eth_dev_attach_secondary(const char *name);
67 * Notify RTE_ETH_EVENT_DESTROY and release the specified ethdev port.
69 * The following PMD-managed data fields will be freed:
73 * If one of these fields should not be freed,
74 * it must be reset to NULL by the PMD, typically in dev_close method.
77 * Device to be detached.
79 * - 0 on success, negative on error
81 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
85 * Release device queues and clear its configuration to force the user
86 * application to reconfigure it. It is for internal use only.
89 * Pointer to struct rte_eth_dev.
94 void _rte_eth_dev_reset(struct rte_eth_dev *dev);
97 * @internal Executes all the user application registered callbacks for
98 * the specific device. It is for DPDK internal user only. User
99 * application should not call it directly.
102 * Pointer to struct rte_eth_dev.
104 * Eth device interrupt event type.
106 * To pass data back to user application.
107 * This allows the user application to decide if a particular function
108 * is permitted or not.
113 int _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
114 enum rte_eth_event_type event, void *ret_param);
118 * This is the last step of device probing.
119 * It must be called after a port is allocated and initialized successfully.
121 * The notification RTE_ETH_EVENT_NEW is sent to other entities
122 * (libraries and applications).
123 * The state is set as RTE_ETH_DEV_ATTACHED.
128 void rte_eth_dev_probing_finish(struct rte_eth_dev *dev);
131 * Create memzone for HW rings.
132 * malloc can't be used as the physical address is needed.
133 * If the memzone is already created, then this function returns a ptr
137 * The *eth_dev* pointer is the address of the *rte_eth_dev* structure
139 * The name of the memory zone
141 * The index of the queue to add to name
143 * The sizeof of the memory area
145 * Alignment for resulting memzone. Must be a power of 2.
147 * The *socket_id* argument is the socket identifier in case of NUMA.
149 const struct rte_memzone *
150 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
151 uint16_t queue_id, size_t size,
152 unsigned align, int socket_id);
156 * Atomically set the link status for the specific device.
157 * It is for use by DPDK device driver use only.
158 * User applications should not call it
161 * Pointer to struct rte_eth_dev.
163 * New link status value.
165 * Same convention as eth_link_update operation.
166 * 0 if link up status has changed
167 * -1 if link up status was unchanged
170 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
171 const struct rte_eth_link *new_link)
173 volatile uint64_t *dev_link
174 = (volatile uint64_t *)&(dev->data->dev_link);
177 struct rte_eth_link link;
180 RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
182 orig.val64 = rte_atomic64_exchange(dev_link,
183 *(const uint64_t *)new_link);
185 return (orig.link.link_status == new_link->link_status) ? -1 : 0;
190 * Atomically get the link speed and status.
193 * Pointer to struct rte_eth_dev.
198 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
199 struct rte_eth_link *link)
201 volatile uint64_t *src = (uint64_t *)&(dev->data->dev_link);
202 uint64_t *dst = (uint64_t *)link;
204 RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
207 /* if cpu arch has 64 bit unsigned lon then implicitly atomic */
210 /* can't use rte_atomic64_read because it returns signed int */
213 } while (!rte_atomic64_cmpset(src, *dst, *dst));
219 * @b EXPERIMENTAL: this API may change without prior notice.
221 * Allocate an unique switch domain identifier.
223 * A pool of switch domain identifiers which can be allocated on request. This
224 * will enabled devices which support the concept of switch domains to request
225 * a switch domain id which is guaranteed to be unique from other devices
226 * running in the same process.
229 * switch domain identifier parameter to pass back to application
232 * Negative errno value on error, 0 on success.
236 rte_eth_switch_domain_alloc(uint16_t *domain_id);
240 * @b EXPERIMENTAL: this API may change without prior notice.
242 * Free switch domain.
244 * Return a switch domain identifier to the pool of free identifiers after it is
245 * no longer in use by device.
248 * switch domain identifier to free
251 * Negative errno value on error, 0 on success.
255 rte_eth_switch_domain_free(uint16_t domain_id);
257 /** Generic Ethernet device arguments */
258 struct rte_eth_devargs {
259 uint16_t ports[RTE_MAX_ETHPORTS];
260 /** port/s number to enable on a multi-port single function */
262 /** number of ports in ports field */
263 uint16_t representor_ports[RTE_MAX_ETHPORTS];
264 /** representor port/s identifier to enable on device */
265 uint16_t nb_representor_ports;
266 /** number of ports in representor port field */
271 * @b EXPERIMENTAL: this API may change without prior notice.
273 * PMD helper function to parse ethdev arguments
278 * parsed ethdev specific arguments.
281 * Negative errno value on error, 0 on success.
285 rte_eth_devargs_parse(const char *devargs, struct rte_eth_devargs *eth_devargs);
288 typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void *init_params);
289 typedef int (*ethdev_bus_specific_init)(struct rte_eth_dev *ethdev,
290 void *bus_specific_init_params);
294 * @b EXPERIMENTAL: this API may change without prior notice.
296 * PMD helper function for the creation of a new ethdev ports.
302 * @param priv_data_size
303 * size of private data required for port.
304 * @param bus_specific_init
305 * port bus specific initialisation callback function
306 * @param bus_init_params
307 * port bus specific initialisation parameters
309 * device specific port initialization callback function
311 * port initialisation parameters
314 * Negative errno value on error, 0 on success.
318 rte_eth_dev_create(struct rte_device *device, const char *name,
319 size_t priv_data_size,
320 ethdev_bus_specific_init bus_specific_init, void *bus_init_params,
321 ethdev_init_t ethdev_init, void *init_params);
324 typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev);
328 * @b EXPERIMENTAL: this API may change without prior notice.
330 * PMD helper function for cleaning up the resources of a ethdev port on it's
334 * ethdev handle of port.
335 * @param ethdev_uninit
336 * device specific port un-initialise callback function
339 * Negative errno value on error, 0 on success.
343 rte_eth_dev_destroy(struct rte_eth_dev *ethdev, ethdev_uninit_t ethdev_uninit);
349 #endif /* _RTE_ETHDEV_DRIVER_H_ */