ethdev: add probing finish function
[dpdk.git] / lib / librte_ethdev / rte_ethdev_driver.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2017 Intel Corporation
3  */
4
5 #ifndef _RTE_ETHDEV_DRIVER_H_
6 #define _RTE_ETHDEV_DRIVER_H_
7
8 /**
9  * @file
10  *
11  * RTE Ethernet Device PMD API
12  *
13  * These APIs for the use from Ethernet drivers, user applications shouldn't
14  * use them.
15  *
16  */
17
18 #include <rte_ethdev.h>
19
20 #ifdef __cplusplus
21 extern "C" {
22 #endif
23
24 /**
25  * @internal
26  * Returns a ethdev slot specified by the unique identifier name.
27  *
28  * @param       name
29  *  The pointer to the Unique identifier name for each Ethernet device
30  * @return
31  *   - The pointer to the ethdev slot, on success. NULL on error
32  */
33 struct rte_eth_dev *rte_eth_dev_allocated(const char *name);
34
35 /**
36  * @internal
37  * Allocates a new ethdev slot for an ethernet device and returns the pointer
38  * to that slot for the driver to use.
39  *
40  * @param       name    Unique identifier name for each Ethernet device
41  * @param       type    Device type of this Ethernet device
42  * @return
43  *   - Slot in the rte_dev_devices array for a new device;
44  */
45 struct rte_eth_dev *rte_eth_dev_allocate(const char *name);
46
47 /**
48  * @internal
49  * Attach to the ethdev already initialized by the primary
50  * process.
51  *
52  * @param       name    Ethernet device's name.
53  * @return
54  *   - Success: Slot in the rte_dev_devices array for attached
55  *        device.
56  *   - Error: Null pointer.
57  */
58 struct rte_eth_dev *rte_eth_dev_attach_secondary(const char *name);
59
60 /**
61  * @internal
62  * Release the specified ethdev port.
63  *
64  * @param eth_dev
65  * The *eth_dev* pointer is the address of the *rte_eth_dev* structure.
66  * @return
67  *   - 0 on success, negative on error
68  */
69 int rte_eth_dev_release_port(struct rte_eth_dev *eth_dev);
70
71 /**
72  * @internal
73  * Release device queues and clear its configuration to force the user
74  * application to reconfigure it. It is for internal use only.
75  *
76  * @param dev
77  *  Pointer to struct rte_eth_dev.
78  *
79  * @return
80  *  void
81  */
82 void _rte_eth_dev_reset(struct rte_eth_dev *dev);
83
84 /**
85  * @internal Executes all the user application registered callbacks for
86  * the specific device. It is for DPDK internal user only. User
87  * application should not call it directly.
88  *
89  * @param dev
90  *  Pointer to struct rte_eth_dev.
91  * @param event
92  *  Eth device interrupt event type.
93  * @param ret_param
94  *  To pass data back to user application.
95  *  This allows the user application to decide if a particular function
96  *  is permitted or not.
97  *
98  * @return
99  *  int
100  */
101 int _rte_eth_dev_callback_process(struct rte_eth_dev *dev,
102                 enum rte_eth_event_type event, void *ret_param);
103
104 /**
105  * @internal
106  * This is the last step of device probing.
107  * It must be called after a port is allocated and initialized successfully.
108  *
109  * @param dev
110  *  New ethdev port.
111  */
112 void rte_eth_dev_probing_finish(struct rte_eth_dev *dev);
113
114 /**
115  * Create memzone for HW rings.
116  * malloc can't be used as the physical address is needed.
117  * If the memzone is already created, then this function returns a ptr
118  * to the old one.
119  *
120  * @param eth_dev
121  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
122  * @param name
123  *   The name of the memory zone
124  * @param queue_id
125  *   The index of the queue to add to name
126  * @param size
127  *   The sizeof of the memory area
128  * @param align
129  *   Alignment for resulting memzone. Must be a power of 2.
130  * @param socket_id
131  *   The *socket_id* argument is the socket identifier in case of NUMA.
132  */
133 const struct rte_memzone *
134 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
135                          uint16_t queue_id, size_t size,
136                          unsigned align, int socket_id);
137
138 /**
139  * @internal
140  * Atomically set the link status for the specific device.
141  * It is for use by DPDK device driver use only.
142  * User applications should not call it
143  *
144  * @param dev
145  *  Pointer to struct rte_eth_dev.
146  * @param link
147  *  New link status value.
148  * @return
149  *  Same convention as eth_link_update operation.
150  *  0   if link up status has changed
151  *  -1  if link up status was unchanged
152  */
153 static inline int
154 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
155                        const struct rte_eth_link *new_link)
156 {
157         volatile uint64_t *dev_link
158                  = (volatile uint64_t *)&(dev->data->dev_link);
159         union {
160                 uint64_t val64;
161                 struct rte_eth_link link;
162         } orig;
163
164         RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
165
166         orig.val64 = rte_atomic64_exchange(dev_link,
167                                            *(const uint64_t *)new_link);
168
169         return (orig.link.link_status == new_link->link_status) ? -1 : 0;
170 }
171
172 /**
173  * @internal
174  * Atomically get the link speed and status.
175  *
176  * @param dev
177  *  Pointer to struct rte_eth_dev.
178  * @param link
179  *  link status value.
180  */
181 static inline void
182 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
183                        struct rte_eth_link *link)
184 {
185         volatile uint64_t *src = (uint64_t *)&(dev->data->dev_link);
186         uint64_t *dst = (uint64_t *)link;
187
188         RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
189
190 #ifdef __LP64__
191         /* if cpu arch has 64 bit unsigned lon then implicitly atomic */
192         *dst = *src;
193 #else
194         /* can't use rte_atomic64_read because it returns signed int */
195         do {
196                 *dst = *src;
197         } while (!rte_atomic64_cmpset(src, *dst, *dst));
198 #endif
199 }
200
201 /**
202  * @warning
203  * @b EXPERIMENTAL: this API may change without prior notice.
204  *
205  * Allocate an unique switch domain identifier.
206  *
207  * A pool of switch domain identifiers which can be allocated on request. This
208  * will enabled devices which support the concept of switch domains to request
209  * a switch domain id which is guaranteed to be unique from other devices
210  * running in the same process.
211  *
212  * @param domain_id
213  *  switch domain identifier parameter to pass back to application
214  *
215  * @return
216  *   Negative errno value on error, 0 on success.
217  */
218 int __rte_experimental
219 rte_eth_switch_domain_alloc(uint16_t *domain_id);
220
221 /**
222  * @warning
223  * @b EXPERIMENTAL: this API may change without prior notice.
224  *
225  * Free switch domain.
226  *
227  * Return a switch domain identifier to the pool of free identifiers after it is
228  * no longer in use by device.
229  *
230  * @param domain_id
231  *  switch domain identifier to free
232  *
233  * @return
234  *   Negative errno value on error, 0 on success.
235  */
236 int __rte_experimental
237 rte_eth_switch_domain_free(uint16_t domain_id);
238
239 /** Generic Ethernet device arguments  */
240 struct rte_eth_devargs {
241         uint16_t ports[RTE_MAX_ETHPORTS];
242         /** port/s number to enable on a multi-port single function */
243         uint16_t nb_ports;
244         /** number of ports in ports field */
245         uint16_t representor_ports[RTE_MAX_ETHPORTS];
246         /** representor port/s identifier to enable on device */
247         uint16_t nb_representor_ports;
248         /** number of ports in representor port field */
249 };
250
251 /**
252  * @warning
253  * @b EXPERIMENTAL: this API may change without prior notice.
254  *
255  * PMD helper function to parse ethdev arguments
256  *
257  * @param devargs
258  *  device arguments
259  * @param eth_devargs
260  *  parsed ethdev specific arguments.
261  *
262  * @return
263  *   Negative errno value on error, 0 on success.
264  */
265 int __rte_experimental
266 rte_eth_devargs_parse(const char *devargs, struct rte_eth_devargs *eth_devargs);
267
268
269 typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void *init_params);
270 typedef int (*ethdev_bus_specific_init)(struct rte_eth_dev *ethdev,
271         void *bus_specific_init_params);
272
273 /**
274  * @warning
275  * @b EXPERIMENTAL: this API may change without prior notice.
276  *
277  * PMD helper function for the creation of a new ethdev ports.
278  *
279  * @param device
280  *  rte_device handle.
281  * @param name
282  *  port name.
283  * @param priv_data_size
284  *  size of private data required for port.
285  * @param bus_specific_init
286  *  port bus specific initialisation callback function
287  * @param bus_init_params
288  *  port bus specific initialisation parameters
289  * @param ethdev_init
290  *  device specific port initialization callback function
291  * @param init_params
292  *  port initialisation parameters
293  *
294  * @return
295  *   Negative errno value on error, 0 on success.
296  */
297 int __rte_experimental
298 rte_eth_dev_create(struct rte_device *device, const char *name,
299         size_t priv_data_size,
300         ethdev_bus_specific_init bus_specific_init, void *bus_init_params,
301         ethdev_init_t ethdev_init, void *init_params);
302
303
304 typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev);
305
306 /**
307  * @warning
308  * @b EXPERIMENTAL: this API may change without prior notice.
309  *
310  * PMD helper function for cleaing up the resources of a ethdev port on it's
311  * destruction.
312  *
313  * @param ethdev
314  *   ethdev handle of port.
315  * @param ethdev_uninit
316  *   device specific port un-initialise callback function
317  *
318  * @return
319  *   Negative errno value on error, 0 on success.
320  */
321 int __rte_experimental
322 rte_eth_dev_destroy(struct rte_eth_dev *ethdev, ethdev_uninit_t ethdev_uninit);
323
324 #ifdef __cplusplus
325 }
326 #endif
327
328 #endif /* _RTE_ETHDEV_DRIVER_H_ */