ethdev: add switch domain allocator
[dpdk.git] / lib / librte_ether / 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  * Create memzone for HW rings.
106  * malloc can't be used as the physical address is needed.
107  * If the memzone is already created, then this function returns a ptr
108  * to the old one.
109  *
110  * @param eth_dev
111  *   The *eth_dev* pointer is the address of the *rte_eth_dev* structure
112  * @param name
113  *   The name of the memory zone
114  * @param queue_id
115  *   The index of the queue to add to name
116  * @param size
117  *   The sizeof of the memory area
118  * @param align
119  *   Alignment for resulting memzone. Must be a power of 2.
120  * @param socket_id
121  *   The *socket_id* argument is the socket identifier in case of NUMA.
122  */
123 const struct rte_memzone *
124 rte_eth_dma_zone_reserve(const struct rte_eth_dev *eth_dev, const char *name,
125                          uint16_t queue_id, size_t size,
126                          unsigned align, int socket_id);
127
128 /**
129  * @internal
130  * Atomically set the link status for the specific device.
131  * It is for use by DPDK device driver use only.
132  * User applications should not call it
133  *
134  * @param dev
135  *  Pointer to struct rte_eth_dev.
136  * @param link
137  *  New link status value.
138  * @return
139  *  Same convention as eth_link_update operation.
140  *  0   if link up status has changed
141  *  -1  if link up status was unchanged
142  */
143 static inline int
144 rte_eth_linkstatus_set(struct rte_eth_dev *dev,
145                        const struct rte_eth_link *new_link)
146 {
147         volatile uint64_t *dev_link
148                  = (volatile uint64_t *)&(dev->data->dev_link);
149         union {
150                 uint64_t val64;
151                 struct rte_eth_link link;
152         } orig;
153
154         RTE_BUILD_BUG_ON(sizeof(*new_link) != sizeof(uint64_t));
155
156         orig.val64 = rte_atomic64_exchange(dev_link,
157                                            *(const uint64_t *)new_link);
158
159         return (orig.link.link_status == new_link->link_status) ? -1 : 0;
160 }
161
162 /**
163  * @internal
164  * Atomically get the link speed and status.
165  *
166  * @param dev
167  *  Pointer to struct rte_eth_dev.
168  * @param link
169  *  link status value.
170  */
171 static inline void
172 rte_eth_linkstatus_get(const struct rte_eth_dev *dev,
173                        struct rte_eth_link *link)
174 {
175         volatile uint64_t *src = (uint64_t *)&(dev->data->dev_link);
176         uint64_t *dst = (uint64_t *)link;
177
178         RTE_BUILD_BUG_ON(sizeof(*link) != sizeof(uint64_t));
179
180 #ifdef __LP64__
181         /* if cpu arch has 64 bit unsigned lon then implicitly atomic */
182         *dst = *src;
183 #else
184         /* can't use rte_atomic64_read because it returns signed int */
185         do {
186                 *dst = *src;
187         } while (!rte_atomic64_cmpset(src, *dst, *dst));
188 #endif
189 }
190
191 /**
192  * @warning
193  * @b EXPERIMENTAL: this API may change without prior notice.
194  *
195  * Allocate an unique switch domain identifier.
196  *
197  * A pool of switch domain identifiers which can be allocated on request. This
198  * will enabled devices which support the concept of switch domains to request
199  * a switch domain id which is guaranteed to be unique from other devices
200  * running in the same process.
201  *
202  * @param domain_id
203  *  switch domain identifier parameter to pass back to application
204  *
205  * @return
206  *   Negative errno value on error, 0 on success.
207  */
208 int __rte_experimental
209 rte_eth_switch_domain_alloc(uint16_t *domain_id);
210
211 /**
212  * @warning
213  * @b EXPERIMENTAL: this API may change without prior notice.
214  *
215  * Free switch domain.
216  *
217  * Return a switch domain identifier to the pool of free identifiers after it is
218  * no longer in use by device.
219  *
220  * @param domain_id
221  *  switch domain identifier to free
222  *
223  * @return
224  *   Negative errno value on error, 0 on success.
225  */
226 int __rte_experimental
227 rte_eth_switch_domain_free(uint16_t domain_id);
228
229 /** Generic Ethernet device arguments  */
230 struct rte_eth_devargs {
231         uint16_t ports[RTE_MAX_ETHPORTS];
232         /** port/s number to enable on a multi-port single function */
233         uint16_t nb_ports;
234         /** number of ports in ports field */
235         uint16_t representor_ports[RTE_MAX_ETHPORTS];
236         /** representor port/s identifier to enable on device */
237         uint16_t nb_representor_ports;
238         /** number of ports in representor port field */
239 };
240
241 /**
242  * @warning
243  * @b EXPERIMENTAL: this API may change without prior notice.
244  *
245  * PMD helper function to parse ethdev arguments
246  *
247  * @param devargs
248  *  device arguments
249  * @param eth_devargs
250  *  parsed ethdev specific arguments.
251  *
252  * @return
253  *   Negative errno value on error, 0 on success.
254  */
255 int __rte_experimental
256 rte_eth_devargs_parse(const char *devargs, struct rte_eth_devargs *eth_devargs);
257
258
259 typedef int (*ethdev_init_t)(struct rte_eth_dev *ethdev, void *init_params);
260 typedef int (*ethdev_bus_specific_init)(struct rte_eth_dev *ethdev,
261         void *bus_specific_init_params);
262
263 /**
264  * @warning
265  * @b EXPERIMENTAL: this API may change without prior notice.
266  *
267  * PMD helper function for the creation of a new ethdev ports.
268  *
269  * @param device
270  *  rte_device handle.
271  * @param name
272  *  port name.
273  * @param priv_data_size
274  *  size of private data required for port.
275  * @param bus_specific_init
276  *  port bus specific initialisation callback function
277  * @param bus_init_params
278  *  port bus specific initialisation parameters
279  * @param ethdev_init
280  *  device specific port initialization callback function
281  * @param init_params
282  *  port initialisation parameters
283  *
284  * @return
285  *   Negative errno value on error, 0 on success.
286  */
287 int __rte_experimental
288 rte_eth_dev_create(struct rte_device *device, const char *name,
289         size_t priv_data_size,
290         ethdev_bus_specific_init bus_specific_init, void *bus_init_params,
291         ethdev_init_t ethdev_init, void *init_params);
292
293
294 typedef int (*ethdev_uninit_t)(struct rte_eth_dev *ethdev);
295
296 /**
297  * @warning
298  * @b EXPERIMENTAL: this API may change without prior notice.
299  *
300  * PMD helper function for cleaing up the resources of a ethdev port on it's
301  * destruction.
302  *
303  * @param ethdev
304  *   ethdev handle of port.
305  * @param ethdev_uninit
306  *   device specific port un-initialise callback function
307  *
308  * @return
309  *   Negative errno value on error, 0 on success.
310  */
311 int __rte_experimental
312 rte_eth_dev_destroy(struct rte_eth_dev *ethdev, ethdev_uninit_t ethdev_uninit);
313
314 #ifdef __cplusplus
315 }
316 #endif
317
318 #endif /* _RTE_ETHDEV_DRIVER_H_ */