Branch data Line data Source code
1 : : /* SPDX-License-Identifier: BSD-3-Clause
2 : : * Copyright(c) 2010-2017 Intel Corporation
3 : : */
4 : :
5 : : #include <errno.h>
6 : : #include <inttypes.h>
7 : : #include <stdbool.h>
8 : : #include <stdint.h>
9 : : #include <stdio.h>
10 : : #include <stdlib.h>
11 : : #include <string.h>
12 : : #include <sys/queue.h>
13 : :
14 : : #include <bus_driver.h>
15 : : #include <eal_export.h>
16 : : #include <rte_log.h>
17 : : #include <rte_interrupts.h>
18 : : #include <rte_kvargs.h>
19 : : #include <rte_memcpy.h>
20 : : #include <rte_common.h>
21 : : #include <rte_mempool.h>
22 : : #include <rte_malloc.h>
23 : : #include <rte_mbuf.h>
24 : : #include <rte_errno.h>
25 : : #include <rte_spinlock.h>
26 : : #include <rte_string_fns.h>
27 : : #include <rte_class.h>
28 : : #include <rte_ether.h>
29 : : #include <rte_telemetry.h>
30 : :
31 : : #include "rte_ethdev.h"
32 : : #include "rte_ethdev_trace_fp.h"
33 : : #include "ethdev_driver.h"
34 : : #include "rte_flow_driver.h"
35 : : #include "ethdev_profile.h"
36 : : #include "ethdev_private.h"
37 : : #include "ethdev_trace.h"
38 : : #include "sff_telemetry.h"
39 : :
40 : : #define ETH_XSTATS_ITER_NUM 0x100
41 : :
42 : : RTE_EXPORT_INTERNAL_SYMBOL(rte_eth_devices)
43 : : struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS];
44 : :
45 : : /* public fast-path API */
46 : : RTE_EXPORT_SYMBOL(rte_eth_fp_ops)
47 : : struct rte_eth_fp_ops rte_eth_fp_ops[RTE_MAX_ETHPORTS];
48 : :
49 : : /* spinlock for add/remove Rx callbacks */
50 : : static rte_spinlock_t eth_dev_rx_cb_lock = RTE_SPINLOCK_INITIALIZER;
51 : :
52 : : /* spinlock for add/remove Tx callbacks */
53 : : static rte_spinlock_t eth_dev_tx_cb_lock = RTE_SPINLOCK_INITIALIZER;
54 : :
55 : : /* store statistics names and its offset in stats structure */
56 : : struct rte_eth_xstats_name_off {
57 : : char name[RTE_ETH_XSTATS_NAME_SIZE];
58 : : unsigned offset;
59 : : };
60 : :
61 : : static const struct rte_eth_xstats_name_off eth_dev_stats_strings[] = {
62 : : {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)},
63 : : {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)},
64 : : {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)},
65 : : {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)},
66 : : {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)},
67 : : {"rx_errors", offsetof(struct rte_eth_stats, ierrors)},
68 : : {"tx_errors", offsetof(struct rte_eth_stats, oerrors)},
69 : : {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats,
70 : : rx_nombuf)},
71 : : };
72 : :
73 : : #define RTE_NB_STATS RTE_DIM(eth_dev_stats_strings)
74 : :
75 : : static const struct rte_eth_xstats_name_off eth_dev_rxq_stats_strings[] = {
76 : : {"packets", offsetof(struct eth_queue_stats, q_ipackets)},
77 : : {"bytes", offsetof(struct eth_queue_stats, q_ibytes)},
78 : : {"errors", offsetof(struct eth_queue_stats, q_errors)},
79 : : };
80 : :
81 : : #define RTE_NB_RXQ_STATS RTE_DIM(eth_dev_rxq_stats_strings)
82 : :
83 : : static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = {
84 : : {"packets", offsetof(struct eth_queue_stats, q_opackets)},
85 : : {"bytes", offsetof(struct eth_queue_stats, q_obytes)},
86 : : };
87 : : #define RTE_NB_TXQ_STATS RTE_DIM(eth_dev_txq_stats_strings)
88 : :
89 : : #define RTE_RX_OFFLOAD_BIT2STR(_name) \
90 : : { RTE_ETH_RX_OFFLOAD_##_name, #_name }
91 : :
92 : : static const struct {
93 : : uint64_t offload;
94 : : const char *name;
95 : : } eth_dev_rx_offload_names[] = {
96 : : RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP),
97 : : RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM),
98 : : RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM),
99 : : RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM),
100 : : RTE_RX_OFFLOAD_BIT2STR(TCP_LRO),
101 : : RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP),
102 : : RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
103 : : RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP),
104 : : RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER),
105 : : RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND),
106 : : RTE_RX_OFFLOAD_BIT2STR(SCATTER),
107 : : RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP),
108 : : RTE_RX_OFFLOAD_BIT2STR(SECURITY),
109 : : RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC),
110 : : RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM),
111 : : RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
112 : : RTE_RX_OFFLOAD_BIT2STR(RSS_HASH),
113 : : RTE_RX_OFFLOAD_BIT2STR(BUFFER_SPLIT),
114 : : };
115 : :
116 : : #undef RTE_RX_OFFLOAD_BIT2STR
117 : : #undef RTE_ETH_RX_OFFLOAD_BIT2STR
118 : :
119 : : #define RTE_TX_OFFLOAD_BIT2STR(_name) \
120 : : { RTE_ETH_TX_OFFLOAD_##_name, #_name }
121 : :
122 : : static const struct {
123 : : uint64_t offload;
124 : : const char *name;
125 : : } eth_dev_tx_offload_names[] = {
126 : : RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT),
127 : : RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM),
128 : : RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM),
129 : : RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM),
130 : : RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM),
131 : : RTE_TX_OFFLOAD_BIT2STR(TCP_TSO),
132 : : RTE_TX_OFFLOAD_BIT2STR(UDP_TSO),
133 : : RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM),
134 : : RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT),
135 : : RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO),
136 : : RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO),
137 : : RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO),
138 : : RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO),
139 : : RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT),
140 : : RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE),
141 : : RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS),
142 : : RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE),
143 : : RTE_TX_OFFLOAD_BIT2STR(SECURITY),
144 : : RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO),
145 : : RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO),
146 : : RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM),
147 : : RTE_TX_OFFLOAD_BIT2STR(SEND_ON_TIMESTAMP),
148 : : };
149 : :
150 : : #undef RTE_TX_OFFLOAD_BIT2STR
151 : :
152 : : static const struct {
153 : : uint64_t offload;
154 : : const char *name;
155 : : } rte_eth_dev_capa_names[] = {
156 : : {RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP, "RUNTIME_RX_QUEUE_SETUP"},
157 : : {RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP, "RUNTIME_TX_QUEUE_SETUP"},
158 : : {RTE_ETH_DEV_CAPA_RXQ_SHARE, "RXQ_SHARE"},
159 : : {RTE_ETH_DEV_CAPA_FLOW_RULE_KEEP, "FLOW_RULE_KEEP"},
160 : : {RTE_ETH_DEV_CAPA_FLOW_SHARED_OBJECT_KEEP, "FLOW_SHARED_OBJECT_KEEP"},
161 : : };
162 : :
163 : : enum {
164 : : STAT_QMAP_TX = 0,
165 : : STAT_QMAP_RX
166 : : };
167 : :
168 : : static const struct {
169 : : enum rte_eth_hash_function algo;
170 : : const char *name;
171 : : } rte_eth_dev_rss_algo_names[] = {
172 : : {RTE_ETH_HASH_FUNCTION_DEFAULT, "default"},
173 : : {RTE_ETH_HASH_FUNCTION_SIMPLE_XOR, "simple_xor"},
174 : : {RTE_ETH_HASH_FUNCTION_TOEPLITZ, "toeplitz"},
175 : : {RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ, "symmetric_toeplitz"},
176 : : {RTE_ETH_HASH_FUNCTION_SYMMETRIC_TOEPLITZ_SORT, "symmetric_toeplitz_sort"},
177 : : };
178 : :
179 : : RTE_EXPORT_SYMBOL(rte_eth_iterator_init)
180 : : int
181 : 0 : rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
182 : : {
183 : : int ret;
184 : : struct rte_devargs devargs;
185 : : const char *bus_param_key;
186 : : char *bus_str = NULL;
187 : : char *cls_str = NULL;
188 : : int str_size;
189 : :
190 [ # # ]: 0 : if (iter == NULL) {
191 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize NULL iterator");
192 : 0 : return -EINVAL;
193 : : }
194 : :
195 [ # # ]: 0 : if (devargs_str == NULL) {
196 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
197 : : "Cannot initialize iterator from NULL device description string");
198 : 0 : return -EINVAL;
199 : : }
200 : :
201 : : memset(iter, 0, sizeof(*iter));
202 : : memset(&devargs, 0, sizeof(devargs));
203 : :
204 : : /*
205 : : * The devargs string may use various syntaxes:
206 : : * - 0000:08:00.0,representor=[1-3]
207 : : * - pci:0000:06:00.0,representor=[0,5]
208 : : * - class=eth,mac=00:11:22:33:44:55
209 : : * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z
210 : : */
211 : :
212 : : /*
213 : : * Handle pure class filter (i.e. without any bus-level argument),
214 : : * from future new syntax.
215 : : * rte_devargs_parse() is not yet supporting the new syntax,
216 : : * that's why this simple case is temporarily parsed here.
217 : : */
218 : : #define iter_anybus_str "class=eth,"
219 [ # # ]: 0 : if (strncmp(devargs_str, iter_anybus_str,
220 : : strlen(iter_anybus_str)) == 0) {
221 : 0 : iter->cls_str = devargs_str + strlen(iter_anybus_str);
222 : 0 : goto end;
223 : : }
224 : :
225 : : /* Split bus, device and parameters. */
226 : 0 : ret = rte_devargs_parse(&devargs, devargs_str);
227 [ # # ]: 0 : if (ret != 0)
228 : 0 : goto error;
229 : :
230 : : /*
231 : : * Assume parameters of old syntax can match only at ethdev level.
232 : : * Extra parameters will be ignored, thanks to "+" prefix.
233 : : */
234 : 0 : str_size = strlen(devargs.args) + 2;
235 : 0 : cls_str = malloc(str_size);
236 [ # # ]: 0 : if (cls_str == NULL) {
237 : : ret = -ENOMEM;
238 : 0 : goto error;
239 : : }
240 : : ret = snprintf(cls_str, str_size, "+%s", devargs.args);
241 [ # # ]: 0 : if (ret != str_size - 1) {
242 : : ret = -EINVAL;
243 : 0 : goto error;
244 : : }
245 : 0 : iter->cls_str = cls_str;
246 : :
247 : 0 : iter->bus = devargs.bus;
248 [ # # ]: 0 : if (iter->bus->dev_iterate == NULL) {
249 : : ret = -ENOTSUP;
250 : 0 : goto error;
251 : : }
252 : :
253 : : /* Convert bus args to new syntax for use with new API dev_iterate. */
254 [ # # ]: 0 : if ((strcmp(iter->bus->name, "vdev") == 0) ||
255 [ # # ]: 0 : (strcmp(iter->bus->name, "fslmc") == 0) ||
256 [ # # ]: 0 : (strcmp(iter->bus->name, "dpaa_bus") == 0)) {
257 : : bus_param_key = "name";
258 [ # # ]: 0 : } else if (strcmp(iter->bus->name, "pci") == 0) {
259 : : bus_param_key = "addr";
260 : : } else {
261 : : ret = -ENOTSUP;
262 : 0 : goto error;
263 : : }
264 : 0 : str_size = strlen(bus_param_key) + strlen(devargs.name) + 2;
265 : 0 : bus_str = malloc(str_size);
266 [ # # ]: 0 : if (bus_str == NULL) {
267 : : ret = -ENOMEM;
268 : 0 : goto error;
269 : : }
270 : : ret = snprintf(bus_str, str_size, "%s=%s",
271 : : bus_param_key, devargs.name);
272 [ # # ]: 0 : if (ret != str_size - 1) {
273 : : ret = -EINVAL;
274 : 0 : goto error;
275 : : }
276 : 0 : iter->bus_str = bus_str;
277 : :
278 : 0 : end:
279 : 0 : iter->cls = rte_class_find_by_name("eth");
280 : 0 : rte_devargs_reset(&devargs);
281 : :
282 : : rte_eth_trace_iterator_init(devargs_str);
283 : :
284 : : return 0;
285 : :
286 : 0 : error:
287 [ # # ]: 0 : if (ret == -ENOTSUP)
288 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Bus %s does not support iterating.",
289 : : iter->bus->name);
290 : 0 : rte_devargs_reset(&devargs);
291 : 0 : free(bus_str);
292 : 0 : free(cls_str);
293 : 0 : return ret;
294 : : }
295 : :
296 : : RTE_EXPORT_SYMBOL(rte_eth_iterator_next)
297 : : uint16_t
298 : 0 : rte_eth_iterator_next(struct rte_dev_iterator *iter)
299 : : {
300 [ # # ]: 0 : if (iter == NULL) {
301 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
302 : : "Cannot get next device from NULL iterator");
303 : 0 : return RTE_MAX_ETHPORTS;
304 : : }
305 : :
306 [ # # ]: 0 : if (iter->cls == NULL) /* invalid ethdev iterator */
307 : : return RTE_MAX_ETHPORTS;
308 : :
309 : : do { /* loop to try all matching rte_device */
310 : : /* If not pure ethdev filter and */
311 [ # # ]: 0 : if (iter->bus != NULL &&
312 : : /* not in middle of rte_eth_dev iteration, */
313 [ # # ]: 0 : iter->class_device == NULL) {
314 : : /* get next rte_device to try. */
315 : 0 : iter->device = iter->bus->dev_iterate(
316 : 0 : iter->device, iter->bus_str, iter);
317 [ # # ]: 0 : if (iter->device == NULL)
318 : : break; /* no more rte_device candidate */
319 : : }
320 : : /* A device is matching bus part, need to check ethdev part. */
321 : 0 : iter->class_device = iter->cls->dev_iterate(
322 : 0 : iter->class_device, iter->cls_str, iter);
323 [ # # ]: 0 : if (iter->class_device != NULL) {
324 : 0 : uint16_t id = eth_dev_to_id(iter->class_device);
325 : :
326 : 0 : rte_eth_trace_iterator_next(iter, id);
327 : :
328 : 0 : return id; /* match */
329 : : }
330 [ # # ]: 0 : } while (iter->bus != NULL); /* need to try next rte_device */
331 : :
332 : : /* No more ethdev port to iterate. */
333 : 0 : rte_eth_iterator_cleanup(iter);
334 : 0 : return RTE_MAX_ETHPORTS;
335 : : }
336 : :
337 : : RTE_EXPORT_SYMBOL(rte_eth_iterator_cleanup)
338 : : void
339 : 0 : rte_eth_iterator_cleanup(struct rte_dev_iterator *iter)
340 : : {
341 [ # # ]: 0 : if (iter == NULL) {
342 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot do clean up from NULL iterator");
343 : 0 : return;
344 : : }
345 : :
346 [ # # ]: 0 : if (iter->bus_str == NULL)
347 : : return; /* nothing to free in pure class filter */
348 : :
349 : 0 : rte_eth_trace_iterator_cleanup(iter);
350 : :
351 : 0 : free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */
352 : 0 : free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */
353 : : memset(iter, 0, sizeof(*iter));
354 : : }
355 : :
356 : : RTE_EXPORT_SYMBOL(rte_eth_find_next)
357 : : uint16_t
358 : 12600 : rte_eth_find_next(uint16_t port_id)
359 : : {
360 [ + + ]: 138363 : while (port_id < RTE_MAX_ETHPORTS &&
361 [ + + ]: 134171 : rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
362 : 125763 : port_id++;
363 : :
364 [ + + ]: 12600 : if (port_id >= RTE_MAX_ETHPORTS)
365 : : return RTE_MAX_ETHPORTS;
366 : :
367 : 8408 : rte_eth_trace_find_next(port_id);
368 : :
369 : 8408 : return port_id;
370 : : }
371 : :
372 : : /*
373 : : * Macro to iterate over all valid ports for internal usage.
374 : : * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports.
375 : : */
376 : : #define RTE_ETH_FOREACH_VALID_DEV(port_id) \
377 : : for (port_id = rte_eth_find_next(0); \
378 : : port_id < RTE_MAX_ETHPORTS; \
379 : : port_id = rte_eth_find_next(port_id + 1))
380 : :
381 : : RTE_EXPORT_SYMBOL(rte_eth_find_next_of)
382 : : uint16_t
383 : 0 : rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent)
384 : : {
385 : 0 : port_id = rte_eth_find_next(port_id);
386 [ # # ]: 0 : while (port_id < RTE_MAX_ETHPORTS &&
387 [ # # ]: 0 : rte_eth_devices[port_id].device != parent)
388 : 0 : port_id = rte_eth_find_next(port_id + 1);
389 : :
390 : 0 : rte_eth_trace_find_next_of(port_id, parent);
391 : :
392 : 0 : return port_id;
393 : : }
394 : :
395 : : RTE_EXPORT_SYMBOL(rte_eth_find_next_sibling)
396 : : uint16_t
397 : 0 : rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id)
398 : : {
399 : : uint16_t ret;
400 : :
401 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS);
402 : 0 : ret = rte_eth_find_next_of(port_id,
403 : 0 : rte_eth_devices[ref_port_id].device);
404 : :
405 : 0 : rte_eth_trace_find_next_sibling(port_id, ref_port_id, ret);
406 : :
407 : 0 : return ret;
408 : : }
409 : :
410 : : static bool
411 : : eth_dev_is_allocated(const struct rte_eth_dev *ethdev)
412 : : {
413 [ - + - - : 118 : return ethdev->data != NULL && ethdev->data->name[0] != '\0';
- - - - ]
414 : : }
415 : :
416 : : RTE_EXPORT_SYMBOL(rte_eth_dev_is_valid_port)
417 : : int
418 : 614 : rte_eth_dev_is_valid_port(uint16_t port_id)
419 : : {
420 : : int is_valid;
421 : :
422 [ + + ]: 614 : if (port_id >= RTE_MAX_ETHPORTS ||
423 [ + + ]: 612 : (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
424 : : is_valid = 0;
425 : : else
426 : : is_valid = 1;
427 : :
428 : 614 : rte_ethdev_trace_is_valid_port(port_id, is_valid);
429 : :
430 : 614 : return is_valid;
431 : : }
432 : :
433 : : static int
434 : : eth_is_valid_owner_id(uint64_t owner_id)
435 : : __rte_requires_capability(rte_mcfg_ethdev_get_lock())
436 : : {
437 [ # # # # ]: 0 : if (owner_id == RTE_ETH_DEV_NO_OWNER ||
438 [ # # # # : 0 : eth_dev_shared_data->next_owner_id <= owner_id)
# # ]
439 : : return 0;
440 : : return 1;
441 : : }
442 : :
443 : : RTE_EXPORT_SYMBOL(rte_eth_find_next_owned_by)
444 : : uint64_t
445 : 12570 : rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
446 : : {
447 : 12570 : port_id = rte_eth_find_next(port_id);
448 [ + + ]: 12570 : while (port_id < RTE_MAX_ETHPORTS &&
449 [ - + ]: 8381 : rte_eth_devices[port_id].data->owner.id != owner_id)
450 : 0 : port_id = rte_eth_find_next(port_id + 1);
451 : :
452 : 12570 : rte_eth_trace_find_next_owned_by(port_id, owner_id);
453 : :
454 : 12570 : return port_id;
455 : : }
456 : :
457 : : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_new)
458 : : int
459 : 0 : rte_eth_dev_owner_new(uint64_t *owner_id)
460 : : {
461 : : int ret;
462 : :
463 [ # # ]: 0 : if (owner_id == NULL) {
464 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get new owner ID to NULL");
465 : 0 : return -EINVAL;
466 : : }
467 : :
468 : 0 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
469 : :
470 [ # # ]: 0 : if (eth_dev_shared_data_prepare() != NULL) {
471 : 0 : *owner_id = eth_dev_shared_data->next_owner_id++;
472 : 0 : eth_dev_shared_data->allocated_owners++;
473 : : ret = 0;
474 : : } else {
475 : : ret = -ENOMEM;
476 : : }
477 : :
478 : 0 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
479 : :
480 [ # # ]: 0 : rte_ethdev_trace_owner_new(*owner_id, ret);
481 : :
482 : 0 : return ret;
483 : : }
484 : :
485 : : static int
486 : 0 : eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id,
487 : : const struct rte_eth_dev_owner *new_owner)
488 : : __rte_requires_capability(rte_mcfg_ethdev_get_lock())
489 : : {
490 : 0 : struct rte_eth_dev *ethdev = &rte_eth_devices[port_id];
491 : : struct rte_eth_dev_owner *port_owner;
492 : :
493 [ # # # # ]: 0 : if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) {
494 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port ID %"PRIu16" is not allocated",
495 : : port_id);
496 : 0 : return -ENODEV;
497 : : }
498 : :
499 [ # # ]: 0 : if (new_owner == NULL) {
500 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
501 : : "Cannot set ethdev port %u owner from NULL owner",
502 : : port_id);
503 : 0 : return -EINVAL;
504 : : }
505 : :
506 [ # # ]: 0 : if (!eth_is_valid_owner_id(new_owner->id) &&
507 : : !eth_is_valid_owner_id(old_owner_id)) {
508 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
509 : : "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64,
510 : : old_owner_id, new_owner->id);
511 : 0 : return -EINVAL;
512 : : }
513 : :
514 : : port_owner = &rte_eth_devices[port_id].data->owner;
515 [ # # ]: 0 : if (port_owner->id != old_owner_id) {
516 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
517 : : "Cannot set owner to port %u already owned by %s_%016"PRIX64,
518 : : port_id, port_owner->name, port_owner->id);
519 : 0 : return -EPERM;
520 : : }
521 : :
522 : : /* can not truncate (same structure) */
523 : 0 : strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN);
524 : :
525 : 0 : port_owner->id = new_owner->id;
526 : :
527 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG, "Port %u owner is %s_%016"PRIx64,
528 : : port_id, new_owner->name, new_owner->id);
529 : :
530 : 0 : return 0;
531 : : }
532 : :
533 : : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_set)
534 : : int
535 : 0 : rte_eth_dev_owner_set(const uint16_t port_id,
536 : : const struct rte_eth_dev_owner *owner)
537 : : {
538 : : int ret;
539 : :
540 : 0 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
541 : :
542 [ # # ]: 0 : if (eth_dev_shared_data_prepare() != NULL)
543 : 0 : ret = eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner);
544 : : else
545 : : ret = -ENOMEM;
546 : :
547 : 0 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
548 : :
549 : 0 : rte_ethdev_trace_owner_set(port_id, owner, ret);
550 : :
551 : 0 : return ret;
552 : : }
553 : :
554 : : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_unset)
555 : : int
556 : 0 : rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
557 : : {
558 : 0 : const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner)
559 : : {.id = RTE_ETH_DEV_NO_OWNER, .name = ""};
560 : : int ret;
561 : :
562 : 0 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
563 : :
564 [ # # ]: 0 : if (eth_dev_shared_data_prepare() != NULL)
565 : 0 : ret = eth_dev_owner_set(port_id, owner_id, &new_owner);
566 : : else
567 : : ret = -ENOMEM;
568 : :
569 : 0 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
570 : :
571 : 0 : rte_ethdev_trace_owner_unset(port_id, owner_id, ret);
572 : :
573 : 0 : return ret;
574 : : }
575 : :
576 : : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_delete)
577 : : int
578 : 0 : rte_eth_dev_owner_delete(const uint64_t owner_id)
579 : : {
580 : : uint16_t port_id;
581 : : int ret = 0;
582 : :
583 : 0 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
584 : :
585 [ # # ]: 0 : if (eth_dev_shared_data_prepare() == NULL) {
586 : : ret = -ENOMEM;
587 : : } else if (eth_is_valid_owner_id(owner_id)) {
588 [ # # ]: 0 : for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) {
589 : 0 : struct rte_eth_dev_data *data =
590 : 0 : rte_eth_devices[port_id].data;
591 [ # # # # ]: 0 : if (data != NULL && data->owner.id == owner_id)
592 : 0 : memset(&data->owner, 0,
593 : : sizeof(struct rte_eth_dev_owner));
594 : : }
595 : 0 : RTE_ETHDEV_LOG_LINE(NOTICE,
596 : : "All port owners owned by %016"PRIx64" identifier have removed",
597 : : owner_id);
598 : 0 : eth_dev_shared_data->allocated_owners--;
599 : 0 : eth_dev_shared_data_release();
600 : : } else {
601 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
602 : : "Invalid owner ID=%016"PRIx64,
603 : : owner_id);
604 : : ret = -EINVAL;
605 : : }
606 : :
607 : 0 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
608 : :
609 : 0 : rte_ethdev_trace_owner_delete(owner_id, ret);
610 : :
611 : 0 : return ret;
612 : : }
613 : :
614 : : RTE_EXPORT_SYMBOL(rte_eth_dev_owner_get)
615 : : int
616 : 0 : rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner)
617 : : {
618 : : struct rte_eth_dev *ethdev;
619 : : int ret;
620 : :
621 [ # # ]: 0 : if (port_id >= RTE_MAX_ETHPORTS)
622 : : return -ENODEV;
623 : :
624 [ # # ]: 0 : ethdev = &rte_eth_devices[port_id];
625 [ # # ]: 0 : if (!eth_dev_is_allocated(ethdev)) {
626 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port ID %"PRIu16" is not allocated",
627 : : port_id);
628 : 0 : return -ENODEV;
629 : : }
630 : :
631 [ # # ]: 0 : if (owner == NULL) {
632 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u owner to NULL",
633 : : port_id);
634 : 0 : return -EINVAL;
635 : : }
636 : :
637 : 0 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
638 : :
639 [ # # ]: 0 : if (eth_dev_shared_data_prepare() != NULL) {
640 [ # # ]: 0 : rte_memcpy(owner, ðdev->data->owner, sizeof(*owner));
641 : : ret = 0;
642 : : } else {
643 : : ret = -ENOMEM;
644 : : }
645 : :
646 : 0 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
647 : :
648 : 0 : rte_ethdev_trace_owner_get(port_id, owner, ret);
649 : :
650 : 0 : return ret;
651 : : }
652 : :
653 : : RTE_EXPORT_SYMBOL(rte_eth_dev_socket_id)
654 : : int
655 : 118 : rte_eth_dev_socket_id(uint16_t port_id)
656 : : {
657 : : int socket_id = SOCKET_ID_ANY;
658 : : struct rte_eth_dev *ethdev;
659 : :
660 [ - + ]: 118 : if (port_id >= RTE_MAX_ETHPORTS) {
661 : 0 : rte_errno = EINVAL;
662 : 0 : return socket_id;
663 : : }
664 : :
665 [ + - ]: 118 : ethdev = &rte_eth_devices[port_id];
666 [ - + ]: 118 : if (!eth_dev_is_allocated(ethdev)) {
667 : 0 : rte_errno = EINVAL;
668 : : } else {
669 : 118 : socket_id = rte_eth_devices[port_id].data->numa_node;
670 [ - + ]: 118 : if (socket_id == SOCKET_ID_ANY)
671 : 0 : rte_errno = 0;
672 : : }
673 : :
674 : 118 : rte_ethdev_trace_socket_id(port_id, socket_id);
675 : :
676 : 118 : return socket_id;
677 : : }
678 : :
679 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_sec_ctx)
680 : : void *
681 : 0 : rte_eth_dev_get_sec_ctx(uint16_t port_id)
682 : : {
683 : : void *ctx;
684 : :
685 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL);
686 [ # # ]: 0 : ctx = rte_eth_devices[port_id].security_ctx;
687 : :
688 : 0 : rte_ethdev_trace_get_sec_ctx(port_id, ctx);
689 : :
690 : 0 : return ctx;
691 : : }
692 : :
693 : : RTE_EXPORT_SYMBOL(rte_eth_dev_count_avail)
694 : : uint16_t
695 : 78 : rte_eth_dev_count_avail(void)
696 : : {
697 : : uint16_t p;
698 : : uint16_t count;
699 : :
700 : : count = 0;
701 : :
702 [ + + ]: 230 : RTE_ETH_FOREACH_DEV(p)
703 : 152 : count++;
704 : :
705 : 78 : rte_ethdev_trace_count_avail(count);
706 : :
707 : 78 : return count;
708 : : }
709 : :
710 : : RTE_EXPORT_SYMBOL(rte_eth_dev_count_total)
711 : : uint16_t
712 : 3 : rte_eth_dev_count_total(void)
713 : : {
714 : : uint16_t port, count = 0;
715 : :
716 [ + + ]: 9 : RTE_ETH_FOREACH_VALID_DEV(port)
717 : 6 : count++;
718 : :
719 : 3 : rte_ethdev_trace_count_total(count);
720 : :
721 : 3 : return count;
722 : : }
723 : :
724 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_name_by_port)
725 : : int
726 : 10 : rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
727 : : {
728 : : char *tmp;
729 : :
730 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
731 : :
732 [ - + ]: 10 : if (name == NULL) {
733 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u name to NULL",
734 : : port_id);
735 : 0 : return -EINVAL;
736 : : }
737 : :
738 : 10 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
739 : : /* shouldn't check 'rte_eth_devices[i].data',
740 : : * because it might be overwritten by VDEV PMD */
741 : 10 : tmp = eth_dev_shared_data->data[port_id].name;
742 : 10 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
743 : :
744 : : strcpy(name, tmp);
745 : :
746 : 10 : rte_ethdev_trace_get_name_by_port(port_id, name);
747 : :
748 : 10 : return 0;
749 : : }
750 : :
751 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_port_by_name)
752 : : int
753 : 10 : rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
754 : : {
755 : : int ret = -ENODEV;
756 : : uint16_t pid;
757 : :
758 [ - + ]: 10 : if (name == NULL) {
759 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get port ID from NULL name");
760 : 0 : return -EINVAL;
761 : : }
762 : :
763 [ - + ]: 10 : if (port_id == NULL) {
764 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
765 : : "Cannot get port ID to NULL for %s", name);
766 : 0 : return -EINVAL;
767 : : }
768 : :
769 : 10 : rte_spinlock_lock(rte_mcfg_ethdev_get_lock());
770 [ + - ]: 21 : RTE_ETH_FOREACH_VALID_DEV(pid) {
771 [ + + ]: 21 : if (strcmp(name, eth_dev_shared_data->data[pid].name) != 0)
772 : : continue;
773 : :
774 [ - + ]: 10 : *port_id = pid;
775 : 10 : rte_ethdev_trace_get_port_by_name(name, *port_id);
776 : : ret = 0;
777 : 10 : break;
778 : : }
779 : 10 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
780 : :
781 : 10 : return ret;
782 : : }
783 : :
784 : : int
785 : 166 : eth_err(uint16_t port_id, int ret)
786 : : {
787 [ + + ]: 166 : if (ret == 0)
788 : : return 0;
789 [ - + ]: 1 : if (rte_eth_dev_is_removed(port_id))
790 : 0 : return -EIO;
791 : : return ret;
792 : : }
793 : :
794 : : static int
795 : 2 : eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id)
796 : : {
797 : : uint16_t port_id;
798 : :
799 [ - + ]: 2 : if (rx_queue_id >= dev->data->nb_rx_queues) {
800 : 0 : port_id = dev->data->port_id;
801 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
802 : : "Invalid Rx queue_id=%u of device with port_id=%u",
803 : : rx_queue_id, port_id);
804 : 0 : return -EINVAL;
805 : : }
806 : :
807 [ - + ]: 2 : if (dev->data->rx_queues[rx_queue_id] == NULL) {
808 : 0 : port_id = dev->data->port_id;
809 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
810 : : "Queue %u of device with port_id=%u has not been setup",
811 : : rx_queue_id, port_id);
812 : 0 : return -EINVAL;
813 : : }
814 : :
815 : : return 0;
816 : : }
817 : :
818 : : static int
819 : 2 : eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id)
820 : : {
821 : : uint16_t port_id;
822 : :
823 [ - + ]: 2 : if (tx_queue_id >= dev->data->nb_tx_queues) {
824 : 0 : port_id = dev->data->port_id;
825 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
826 : : "Invalid Tx queue_id=%u of device with port_id=%u",
827 : : tx_queue_id, port_id);
828 : 0 : return -EINVAL;
829 : : }
830 : :
831 [ - + ]: 2 : if (dev->data->tx_queues[tx_queue_id] == NULL) {
832 : 0 : port_id = dev->data->port_id;
833 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
834 : : "Queue %u of device with port_id=%u has not been setup",
835 : : tx_queue_id, port_id);
836 : 0 : return -EINVAL;
837 : : }
838 : :
839 : : return 0;
840 : : }
841 : :
842 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_queue_is_valid, 23.07)
843 : : int
844 : 0 : rte_eth_rx_queue_is_valid(uint16_t port_id, uint16_t queue_id)
845 : : {
846 : : struct rte_eth_dev *dev;
847 : :
848 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
849 : 0 : dev = &rte_eth_devices[port_id];
850 : :
851 : 0 : return eth_dev_validate_rx_queue(dev, queue_id);
852 : : }
853 : :
854 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_tx_queue_is_valid, 23.07)
855 : : int
856 : 0 : rte_eth_tx_queue_is_valid(uint16_t port_id, uint16_t queue_id)
857 : : {
858 : : struct rte_eth_dev *dev;
859 : :
860 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
861 : 0 : dev = &rte_eth_devices[port_id];
862 : :
863 : 0 : return eth_dev_validate_tx_queue(dev, queue_id);
864 : : }
865 : :
866 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_queue_start)
867 : : int
868 : 1 : rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id)
869 : : {
870 : : struct rte_eth_dev *dev;
871 : : int ret;
872 : :
873 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
874 : 1 : dev = &rte_eth_devices[port_id];
875 : :
876 [ - + ]: 1 : if (!dev->data->dev_started) {
877 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
878 : : "Port %u must be started before start any queue",
879 : : port_id);
880 : 0 : return -EINVAL;
881 : : }
882 : :
883 : 1 : ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
884 [ + - ]: 1 : if (ret != 0)
885 : : return ret;
886 : :
887 [ + - ]: 1 : if (dev->dev_ops->rx_queue_start == NULL)
888 : : return -ENOTSUP;
889 : :
890 [ - + ]: 1 : if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
891 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
892 : : "Can't start Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
893 : : rx_queue_id, port_id);
894 : 0 : return -EINVAL;
895 : : }
896 : :
897 [ - + ]: 1 : if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
898 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
899 : : "Queue %"PRIu16" of device with port_id=%"PRIu16" already started",
900 : : rx_queue_id, port_id);
901 : 0 : return 0;
902 : : }
903 : :
904 : 1 : ret = eth_err(port_id, dev->dev_ops->rx_queue_start(dev, rx_queue_id));
905 : :
906 : 1 : rte_ethdev_trace_rx_queue_start(port_id, rx_queue_id, ret);
907 : :
908 : 1 : return ret;
909 : : }
910 : :
911 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_queue_stop)
912 : : int
913 : 1 : rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id)
914 : : {
915 : : struct rte_eth_dev *dev;
916 : : int ret;
917 : :
918 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
919 : 1 : dev = &rte_eth_devices[port_id];
920 : :
921 : 1 : ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
922 [ + - ]: 1 : if (ret != 0)
923 : : return ret;
924 : :
925 [ + - ]: 1 : if (dev->dev_ops->rx_queue_stop == NULL)
926 : : return -ENOTSUP;
927 : :
928 [ - + ]: 1 : if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) {
929 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
930 : : "Can't stop Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
931 : : rx_queue_id, port_id);
932 : 0 : return -EINVAL;
933 : : }
934 : :
935 [ - + ]: 1 : if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
936 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
937 : : "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped",
938 : : rx_queue_id, port_id);
939 : 0 : return 0;
940 : : }
941 : :
942 : 1 : ret = eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
943 : :
944 : 1 : rte_ethdev_trace_rx_queue_stop(port_id, rx_queue_id, ret);
945 : :
946 : 1 : return ret;
947 : : }
948 : :
949 : : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_queue_start)
950 : : int
951 : 1 : rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id)
952 : : {
953 : : struct rte_eth_dev *dev;
954 : : int ret;
955 : :
956 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
957 : 1 : dev = &rte_eth_devices[port_id];
958 : :
959 [ - + ]: 1 : if (!dev->data->dev_started) {
960 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
961 : : "Port %u must be started before start any queue",
962 : : port_id);
963 : 0 : return -EINVAL;
964 : : }
965 : :
966 : 1 : ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
967 [ + - ]: 1 : if (ret != 0)
968 : : return ret;
969 : :
970 [ + - ]: 1 : if (dev->dev_ops->tx_queue_start == NULL)
971 : : return -ENOTSUP;
972 : :
973 [ - + ]: 1 : if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
974 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
975 : : "Can't start Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
976 : : tx_queue_id, port_id);
977 : 0 : return -EINVAL;
978 : : }
979 : :
980 [ - + ]: 1 : if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) {
981 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
982 : : "Queue %"PRIu16" of device with port_id=%"PRIu16" already started",
983 : : tx_queue_id, port_id);
984 : 0 : return 0;
985 : : }
986 : :
987 : 1 : ret = eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id));
988 : :
989 : 1 : rte_ethdev_trace_tx_queue_start(port_id, tx_queue_id, ret);
990 : :
991 : 1 : return ret;
992 : : }
993 : :
994 : : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_queue_stop)
995 : : int
996 : 1 : rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id)
997 : : {
998 : : struct rte_eth_dev *dev;
999 : : int ret;
1000 : :
1001 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1002 : 1 : dev = &rte_eth_devices[port_id];
1003 : :
1004 : 1 : ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
1005 [ + - ]: 1 : if (ret != 0)
1006 : : return ret;
1007 : :
1008 [ + - ]: 1 : if (dev->dev_ops->tx_queue_stop == NULL)
1009 : : return -ENOTSUP;
1010 : :
1011 [ - + ]: 1 : if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) {
1012 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
1013 : : "Can't stop Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16,
1014 : : tx_queue_id, port_id);
1015 : 0 : return -EINVAL;
1016 : : }
1017 : :
1018 [ - + ]: 1 : if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) {
1019 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
1020 : : "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped",
1021 : : tx_queue_id, port_id);
1022 : 0 : return 0;
1023 : : }
1024 : :
1025 : 1 : ret = eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
1026 : :
1027 : 1 : rte_ethdev_trace_tx_queue_stop(port_id, tx_queue_id, ret);
1028 : :
1029 : 1 : return ret;
1030 : : }
1031 : :
1032 : : RTE_EXPORT_SYMBOL(rte_eth_speed_bitflag)
1033 : : uint32_t
1034 : 0 : rte_eth_speed_bitflag(uint32_t speed, int duplex)
1035 : : {
1036 : : uint32_t ret;
1037 : :
1038 [ # # # # : 0 : switch (speed) {
# # # # #
# # # # #
# # ]
1039 : 0 : case RTE_ETH_SPEED_NUM_10M:
1040 [ # # ]: 0 : ret = duplex ? RTE_ETH_LINK_SPEED_10M : RTE_ETH_LINK_SPEED_10M_HD;
1041 : : break;
1042 : 0 : case RTE_ETH_SPEED_NUM_100M:
1043 [ # # ]: 0 : ret = duplex ? RTE_ETH_LINK_SPEED_100M : RTE_ETH_LINK_SPEED_100M_HD;
1044 : : break;
1045 : : case RTE_ETH_SPEED_NUM_1G:
1046 : : ret = RTE_ETH_LINK_SPEED_1G;
1047 : : break;
1048 : 0 : case RTE_ETH_SPEED_NUM_2_5G:
1049 : : ret = RTE_ETH_LINK_SPEED_2_5G;
1050 : 0 : break;
1051 : 0 : case RTE_ETH_SPEED_NUM_5G:
1052 : : ret = RTE_ETH_LINK_SPEED_5G;
1053 : 0 : break;
1054 : 0 : case RTE_ETH_SPEED_NUM_10G:
1055 : : ret = RTE_ETH_LINK_SPEED_10G;
1056 : 0 : break;
1057 : 0 : case RTE_ETH_SPEED_NUM_20G:
1058 : : ret = RTE_ETH_LINK_SPEED_20G;
1059 : 0 : break;
1060 : 0 : case RTE_ETH_SPEED_NUM_25G:
1061 : : ret = RTE_ETH_LINK_SPEED_25G;
1062 : 0 : break;
1063 : 0 : case RTE_ETH_SPEED_NUM_40G:
1064 : : ret = RTE_ETH_LINK_SPEED_40G;
1065 : 0 : break;
1066 : 0 : case RTE_ETH_SPEED_NUM_50G:
1067 : : ret = RTE_ETH_LINK_SPEED_50G;
1068 : 0 : break;
1069 : 0 : case RTE_ETH_SPEED_NUM_56G:
1070 : : ret = RTE_ETH_LINK_SPEED_56G;
1071 : 0 : break;
1072 : 0 : case RTE_ETH_SPEED_NUM_100G:
1073 : : ret = RTE_ETH_LINK_SPEED_100G;
1074 : 0 : break;
1075 : 0 : case RTE_ETH_SPEED_NUM_200G:
1076 : : ret = RTE_ETH_LINK_SPEED_200G;
1077 : 0 : break;
1078 : 0 : case RTE_ETH_SPEED_NUM_400G:
1079 : : ret = RTE_ETH_LINK_SPEED_400G;
1080 : 0 : break;
1081 : 0 : case RTE_ETH_SPEED_NUM_800G:
1082 : : ret = RTE_ETH_LINK_SPEED_800G;
1083 : 0 : break;
1084 : 0 : default:
1085 : : ret = 0;
1086 : : }
1087 : :
1088 : 0 : rte_eth_trace_speed_bitflag(speed, duplex, ret);
1089 : :
1090 : 0 : return ret;
1091 : : }
1092 : :
1093 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_offload_name)
1094 : : const char *
1095 : 0 : rte_eth_dev_rx_offload_name(uint64_t offload)
1096 : : {
1097 : : const char *name = "UNKNOWN";
1098 : : unsigned int i;
1099 : :
1100 [ # # ]: 0 : for (i = 0; i < RTE_DIM(eth_dev_rx_offload_names); ++i) {
1101 [ # # ]: 0 : if (offload == eth_dev_rx_offload_names[i].offload) {
1102 : 0 : name = eth_dev_rx_offload_names[i].name;
1103 : 0 : break;
1104 : : }
1105 : : }
1106 : :
1107 : 0 : rte_ethdev_trace_rx_offload_name(offload, name);
1108 : :
1109 : 0 : return name;
1110 : : }
1111 : :
1112 : : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_offload_name)
1113 : : const char *
1114 : 0 : rte_eth_dev_tx_offload_name(uint64_t offload)
1115 : : {
1116 : : const char *name = "UNKNOWN";
1117 : : unsigned int i;
1118 : :
1119 [ # # ]: 0 : for (i = 0; i < RTE_DIM(eth_dev_tx_offload_names); ++i) {
1120 [ # # ]: 0 : if (offload == eth_dev_tx_offload_names[i].offload) {
1121 : 0 : name = eth_dev_tx_offload_names[i].name;
1122 : 0 : break;
1123 : : }
1124 : : }
1125 : :
1126 : 0 : rte_ethdev_trace_tx_offload_name(offload, name);
1127 : :
1128 : 0 : return name;
1129 : : }
1130 : :
1131 : : static char *
1132 : 0 : eth_dev_offload_names(uint64_t bitmask, char *buf, size_t size,
1133 : : const char *(*offload_name)(uint64_t))
1134 : : {
1135 : : unsigned int pos = 0;
1136 : : int ret;
1137 : :
1138 : : /* There should be at least enough space to handle those cases */
1139 : : RTE_ASSERT(size >= sizeof("none") && size >= sizeof("..."));
1140 : :
1141 [ # # ]: 0 : if (bitmask == 0) {
1142 : : ret = snprintf(&buf[pos], size - pos, "none");
1143 [ # # # # ]: 0 : if (ret < 0 || pos + ret >= size)
1144 : : ret = 0;
1145 : 0 : pos += ret;
1146 : 0 : goto out;
1147 : : }
1148 : :
1149 [ # # ]: 0 : while (bitmask != 0) {
1150 : 0 : uint64_t offload = RTE_BIT64(rte_ctz64(bitmask));
1151 : 0 : const char *name = offload_name(offload);
1152 : :
1153 [ # # ]: 0 : ret = snprintf(&buf[pos], size - pos, "%s,", name);
1154 [ # # # # ]: 0 : if (ret < 0 || pos + ret >= size) {
1155 [ # # ]: 0 : if (pos + sizeof("...") >= size)
1156 : 0 : pos = size - sizeof("...");
1157 [ # # ]: 0 : ret = snprintf(&buf[pos], size - pos, "...");
1158 [ # # # # ]: 0 : if (ret > 0 && pos + ret < size)
1159 : : pos += ret;
1160 : 0 : goto out;
1161 : : }
1162 : :
1163 : : pos += ret;
1164 : 0 : bitmask &= ~offload;
1165 : : }
1166 : :
1167 : : /* Eliminate trailing comma */
1168 : 0 : pos--;
1169 : 0 : out:
1170 : 0 : buf[pos] = '\0';
1171 : 0 : return buf;
1172 : : }
1173 : :
1174 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_capability_name, 21.11)
1175 : : const char *
1176 : 0 : rte_eth_dev_capability_name(uint64_t capability)
1177 : : {
1178 : : const char *name = "UNKNOWN";
1179 : : unsigned int i;
1180 : :
1181 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rte_eth_dev_capa_names); ++i) {
1182 [ # # ]: 0 : if (capability == rte_eth_dev_capa_names[i].offload) {
1183 : 0 : name = rte_eth_dev_capa_names[i].name;
1184 : 0 : break;
1185 : : }
1186 : : }
1187 : :
1188 : 0 : rte_ethdev_trace_capability_name(capability, name);
1189 : :
1190 : 0 : return name;
1191 : : }
1192 : :
1193 : : static inline int
1194 : 0 : eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size,
1195 : : uint32_t max_rx_pkt_len, uint32_t dev_info_size)
1196 : : {
1197 : : int ret = 0;
1198 : :
1199 [ # # ]: 0 : if (dev_info_size == 0) {
1200 [ # # ]: 0 : if (config_size != max_rx_pkt_len) {
1201 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%d max_lro_pkt_size"
1202 : : " %u != %u is not allowed",
1203 : : port_id, config_size, max_rx_pkt_len);
1204 : : ret = -EINVAL;
1205 : : }
1206 [ # # ]: 0 : } else if (config_size > dev_info_size) {
1207 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
1208 : : "> max allowed value %u", port_id, config_size,
1209 : : dev_info_size);
1210 : : ret = -EINVAL;
1211 [ # # ]: 0 : } else if (config_size < RTE_ETHER_MIN_LEN) {
1212 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%d max_lro_pkt_size %u "
1213 : : "< min allowed value %u", port_id, config_size,
1214 : : (unsigned int)RTE_ETHER_MIN_LEN);
1215 : : ret = -EINVAL;
1216 : : }
1217 : 0 : return ret;
1218 : : }
1219 : :
1220 : : /*
1221 : : * Validate offloads that are requested through rte_eth_dev_configure against
1222 : : * the offloads successfully set by the Ethernet device.
1223 : : *
1224 : : * @param port_id
1225 : : * The port identifier of the Ethernet device.
1226 : : * @param req_offloads
1227 : : * The offloads that have been requested through `rte_eth_dev_configure`.
1228 : : * @param set_offloads
1229 : : * The offloads successfully set by the Ethernet device.
1230 : : * @param offload_type
1231 : : * The offload type i.e. Rx/Tx string.
1232 : : * @param offload_name
1233 : : * The function that prints the offload name.
1234 : : * @return
1235 : : * - (0) if validation successful.
1236 : : * - (-EINVAL) if requested offload has been silently disabled.
1237 : : */
1238 : : static int
1239 : 38 : eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads,
1240 : : uint64_t set_offloads, const char *offload_type,
1241 : : const char *(*offload_name)(uint64_t))
1242 : : {
1243 : 38 : uint64_t offloads_diff = req_offloads ^ set_offloads;
1244 : : uint64_t offload;
1245 : : int ret = 0;
1246 : :
1247 [ - + ]: 38 : while (offloads_diff != 0) {
1248 : : /* Check if any offload is requested but not enabled. */
1249 : 0 : offload = RTE_BIT64(rte_ctz64(offloads_diff));
1250 [ # # ]: 0 : if (offload & req_offloads) {
1251 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1252 : : "Port %u failed to enable %s offload %s",
1253 : : port_id, offload_type, offload_name(offload));
1254 : : ret = -EINVAL;
1255 : : }
1256 : :
1257 : : /* Check if offload couldn't be disabled. */
1258 [ # # ]: 0 : if (offload & set_offloads) {
1259 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG,
1260 : : "Port %u %s offload %s is not requested but enabled",
1261 : : port_id, offload_type, offload_name(offload));
1262 : : }
1263 : :
1264 : 0 : offloads_diff &= ~offload;
1265 : : }
1266 : :
1267 : 38 : return ret;
1268 : : }
1269 : :
1270 : : static uint32_t
1271 : : eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu)
1272 : : {
1273 : : uint32_t overhead_len;
1274 : :
1275 [ # # # # : 0 : if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu)
# # ]
1276 : 0 : overhead_len = max_rx_pktlen - max_mtu;
1277 : : else
1278 : : overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
1279 : :
1280 : : return overhead_len;
1281 : : }
1282 : :
1283 : : /* rte_eth_dev_info_get() should be called prior to this function */
1284 : : static int
1285 : 21 : eth_dev_validate_mtu(uint16_t port_id, struct rte_eth_dev_info *dev_info,
1286 : : uint16_t mtu)
1287 : : {
1288 : : uint32_t overhead_len;
1289 : : uint32_t frame_size;
1290 : :
1291 [ - + ]: 21 : if (mtu < dev_info->min_mtu) {
1292 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1293 : : "MTU (%u) < device min MTU (%u) for port_id %u",
1294 : : mtu, dev_info->min_mtu, port_id);
1295 : 0 : return -EINVAL;
1296 : : }
1297 [ - + ]: 21 : if (mtu > dev_info->max_mtu) {
1298 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1299 : : "MTU (%u) > device max MTU (%u) for port_id %u",
1300 : : mtu, dev_info->max_mtu, port_id);
1301 : 0 : return -EINVAL;
1302 : : }
1303 : :
1304 [ - + ]: 21 : overhead_len = eth_dev_get_overhead_len(dev_info->max_rx_pktlen,
1305 : : dev_info->max_mtu);
1306 : 21 : frame_size = mtu + overhead_len;
1307 [ - + ]: 21 : if (frame_size < RTE_ETHER_MIN_LEN) {
1308 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1309 : : "Frame size (%u) < min frame size (%u) for port_id %u",
1310 : : frame_size, RTE_ETHER_MIN_LEN, port_id);
1311 : 0 : return -EINVAL;
1312 : : }
1313 : :
1314 [ - + ]: 21 : if (frame_size > dev_info->max_rx_pktlen) {
1315 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1316 : : "Frame size (%u) > device max frame size (%u) for port_id %u",
1317 : : frame_size, dev_info->max_rx_pktlen, port_id);
1318 : 0 : return -EINVAL;
1319 : : }
1320 : :
1321 : : return 0;
1322 : : }
1323 : :
1324 : : RTE_EXPORT_SYMBOL(rte_eth_dev_configure)
1325 : : int
1326 : 19 : rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q,
1327 : : const struct rte_eth_conf *dev_conf)
1328 : : {
1329 : : enum rte_eth_hash_function algorithm;
1330 : : struct rte_eth_dev *dev;
1331 : : struct rte_eth_dev_info dev_info;
1332 : : struct rte_eth_conf orig_conf;
1333 : : int diag;
1334 : : int ret;
1335 : : uint16_t old_mtu;
1336 : :
1337 [ - + ]: 19 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1338 : 19 : dev = &rte_eth_devices[port_id];
1339 : :
1340 [ - + ]: 19 : if (dev_conf == NULL) {
1341 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1342 : : "Cannot configure ethdev port %u from NULL config",
1343 : : port_id);
1344 : 0 : return -EINVAL;
1345 : : }
1346 : :
1347 [ + - ]: 19 : if (dev->dev_ops->dev_configure == NULL)
1348 : : return -ENOTSUP;
1349 : :
1350 [ - + ]: 19 : if (dev->data->dev_started) {
1351 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1352 : : "Port %u must be stopped to allow configuration",
1353 : : port_id);
1354 : 0 : return -EBUSY;
1355 : : }
1356 : :
1357 : : /*
1358 : : * Ensure that "dev_configured" is always 0 each time prepare to do
1359 : : * dev_configure() to avoid any non-anticipated behaviour.
1360 : : * And set to 1 when dev_configure() is executed successfully.
1361 : : */
1362 : 19 : dev->data->dev_configured = 0;
1363 : :
1364 : : /* Store original config, as rollback required on failure */
1365 [ + - ]: 19 : memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf));
1366 : :
1367 : : /*
1368 : : * Copy the dev_conf parameter into the dev structure.
1369 : : * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get
1370 : : */
1371 [ + - ]: 19 : if (dev_conf != &dev->data->dev_conf)
1372 : : memcpy(&dev->data->dev_conf, dev_conf,
1373 : : sizeof(dev->data->dev_conf));
1374 : :
1375 : : /* Backup mtu for rollback */
1376 : 19 : old_mtu = dev->data->mtu;
1377 : :
1378 : : /* fields must be zero to reserve them for future ABI changes */
1379 [ + - ]: 19 : if (dev_conf->rxmode.reserved_64s[0] != 0 ||
1380 [ + - ]: 19 : dev_conf->rxmode.reserved_64s[1] != 0 ||
1381 [ + - ]: 19 : dev_conf->rxmode.reserved_ptrs[0] != NULL ||
1382 [ - + ]: 19 : dev_conf->rxmode.reserved_ptrs[1] != NULL) {
1383 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rxmode reserved fields not zero");
1384 : : ret = -EINVAL;
1385 : 0 : goto rollback;
1386 : : }
1387 : :
1388 [ + - ]: 19 : if (dev_conf->txmode.reserved_64s[0] != 0 ||
1389 [ + - ]: 19 : dev_conf->txmode.reserved_64s[1] != 0 ||
1390 [ + - ]: 19 : dev_conf->txmode.reserved_ptrs[0] != NULL ||
1391 [ - + ]: 19 : dev_conf->txmode.reserved_ptrs[1] != NULL) {
1392 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "txmode reserved fields not zero");
1393 : : ret = -EINVAL;
1394 : 0 : goto rollback;
1395 : : }
1396 : :
1397 : 19 : ret = rte_eth_dev_info_get(port_id, &dev_info);
1398 [ - + ]: 19 : if (ret != 0)
1399 : 0 : goto rollback;
1400 : :
1401 : : /* If number of queues specified by application for both Rx and Tx is
1402 : : * zero, use driver preferred values. This cannot be done individually
1403 : : * as it is valid for either Tx or Rx (but not both) to be zero.
1404 : : * If driver does not provide any preferred valued, fall back on
1405 : : * EAL defaults.
1406 : : */
1407 [ - + ]: 19 : if (nb_rx_q == 0 && nb_tx_q == 0) {
1408 : 0 : nb_rx_q = dev_info.default_rxportconf.nb_queues;
1409 : : if (nb_rx_q == 0)
1410 : : nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES;
1411 : 0 : nb_tx_q = dev_info.default_txportconf.nb_queues;
1412 : : if (nb_tx_q == 0)
1413 : : nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES;
1414 : : }
1415 : :
1416 [ - + ]: 19 : if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) {
1417 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1418 : : "Number of Rx queues requested (%u) is greater than max supported(%d)",
1419 : : nb_rx_q, RTE_MAX_QUEUES_PER_PORT);
1420 : : ret = -EINVAL;
1421 : 0 : goto rollback;
1422 : : }
1423 : :
1424 [ - + ]: 19 : if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) {
1425 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1426 : : "Number of Tx queues requested (%u) is greater than max supported(%d)",
1427 : : nb_tx_q, RTE_MAX_QUEUES_PER_PORT);
1428 : : ret = -EINVAL;
1429 : 0 : goto rollback;
1430 : : }
1431 : :
1432 : : /*
1433 : : * Check that the numbers of Rx and Tx queues are not greater
1434 : : * than the maximum number of Rx and Tx queues supported by the
1435 : : * configured device.
1436 : : */
1437 [ - + ]: 19 : if (nb_rx_q > dev_info.max_rx_queues) {
1438 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u",
1439 : : port_id, nb_rx_q, dev_info.max_rx_queues);
1440 : : ret = -EINVAL;
1441 : 0 : goto rollback;
1442 : : }
1443 : :
1444 [ - + ]: 19 : if (nb_tx_q > dev_info.max_tx_queues) {
1445 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u",
1446 : : port_id, nb_tx_q, dev_info.max_tx_queues);
1447 : : ret = -EINVAL;
1448 : 0 : goto rollback;
1449 : : }
1450 : :
1451 : : /* Check that the device supports requested interrupts */
1452 [ - + ]: 19 : if ((dev_conf->intr_conf.lsc == 1) &&
1453 [ # # ]: 0 : (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) {
1454 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Driver %s does not support lsc",
1455 : : dev->device->driver->name);
1456 : : ret = -EINVAL;
1457 : 0 : goto rollback;
1458 : : }
1459 [ - + ]: 19 : if ((dev_conf->intr_conf.rmv == 1) &&
1460 [ # # ]: 0 : (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) {
1461 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Driver %s does not support rmv",
1462 : : dev->device->driver->name);
1463 : : ret = -EINVAL;
1464 : 0 : goto rollback;
1465 : : }
1466 : :
1467 [ + - ]: 19 : if (dev_conf->rxmode.mtu == 0)
1468 : 19 : dev->data->dev_conf.rxmode.mtu =
1469 [ + - ]: 19 : (dev_info.max_mtu == 0) ? RTE_ETHER_MTU :
1470 : 19 : RTE_MIN(dev_info.max_mtu, RTE_ETHER_MTU);
1471 : :
1472 : 19 : ret = eth_dev_validate_mtu(port_id, &dev_info,
1473 : 19 : dev->data->dev_conf.rxmode.mtu);
1474 [ - + ]: 19 : if (ret != 0)
1475 : 0 : goto rollback;
1476 : :
1477 : 19 : dev->data->mtu = dev->data->dev_conf.rxmode.mtu;
1478 : :
1479 : : /*
1480 : : * If LRO is enabled, check that the maximum aggregated packet
1481 : : * size is supported by the configured device.
1482 : : */
1483 [ - + ]: 19 : if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
1484 : : uint32_t max_rx_pktlen;
1485 : : uint32_t overhead_len;
1486 : :
1487 : 0 : overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
1488 [ # # ]: 0 : dev_info.max_mtu);
1489 : 0 : max_rx_pktlen = dev->data->dev_conf.rxmode.mtu + overhead_len;
1490 [ # # ]: 0 : if (dev_conf->rxmode.max_lro_pkt_size == 0)
1491 : 0 : dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen;
1492 : 0 : ret = eth_dev_check_lro_pkt_size(port_id,
1493 : : dev->data->dev_conf.rxmode.max_lro_pkt_size,
1494 : : max_rx_pktlen,
1495 : : dev_info.max_lro_pkt_size);
1496 [ # # ]: 0 : if (ret != 0)
1497 : 0 : goto rollback;
1498 : : }
1499 : :
1500 : : /* Any requested offloading must be within its device capabilities */
1501 [ - + ]: 19 : if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) !=
1502 : : dev_conf->rxmode.offloads) {
1503 : : char buffer[512];
1504 : :
1505 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support Rx offloads %s",
1506 : : port_id, eth_dev_offload_names(
1507 : : dev_conf->rxmode.offloads & ~dev_info.rx_offload_capa,
1508 : : buffer, sizeof(buffer), rte_eth_dev_rx_offload_name));
1509 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u was requested Rx offloads %s",
1510 : : port_id, eth_dev_offload_names(dev_conf->rxmode.offloads,
1511 : : buffer, sizeof(buffer), rte_eth_dev_rx_offload_name));
1512 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u supports Rx offloads %s",
1513 : : port_id, eth_dev_offload_names(dev_info.rx_offload_capa,
1514 : : buffer, sizeof(buffer), rte_eth_dev_rx_offload_name));
1515 : :
1516 : : ret = -EINVAL;
1517 : 0 : goto rollback;
1518 : : }
1519 [ - + ]: 19 : if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) !=
1520 : : dev_conf->txmode.offloads) {
1521 : : char buffer[512];
1522 : :
1523 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port_id=%u does not support Tx offloads %s",
1524 : : port_id, eth_dev_offload_names(
1525 : : dev_conf->txmode.offloads & ~dev_info.tx_offload_capa,
1526 : : buffer, sizeof(buffer), rte_eth_dev_tx_offload_name));
1527 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u was requested Tx offloads %s",
1528 : : port_id, eth_dev_offload_names(dev_conf->txmode.offloads,
1529 : : buffer, sizeof(buffer), rte_eth_dev_tx_offload_name));
1530 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG, "Ethdev port_id=%u supports Tx offloads %s",
1531 : : port_id, eth_dev_offload_names(dev_info.tx_offload_capa,
1532 : : buffer, sizeof(buffer), rte_eth_dev_tx_offload_name));
1533 : : ret = -EINVAL;
1534 : 0 : goto rollback;
1535 : : }
1536 : :
1537 : 38 : dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
1538 [ - + ]: 19 : rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf);
1539 : :
1540 : : /* Check that device supports requested rss hash functions. */
1541 : 19 : if ((dev_info.flow_type_rss_offloads |
1542 [ - + ]: 19 : dev_conf->rx_adv_conf.rss_conf.rss_hf) !=
1543 : : dev_info.flow_type_rss_offloads) {
1544 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1545 : : "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64,
1546 : : port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf,
1547 : : dev_info.flow_type_rss_offloads);
1548 : : ret = -EINVAL;
1549 : 0 : goto rollback;
1550 : : }
1551 : :
1552 : : /* Check if Rx RSS distribution is disabled but RSS hash is enabled. */
1553 [ + - ]: 19 : if (((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) == 0) &&
1554 [ - + ]: 19 : (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_RSS_HASH)) {
1555 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1556 : : "Ethdev port_id=%u config invalid Rx mq_mode without RSS but %s offload is requested",
1557 : : port_id,
1558 : : rte_eth_dev_rx_offload_name(RTE_ETH_RX_OFFLOAD_RSS_HASH));
1559 : : ret = -EINVAL;
1560 : 0 : goto rollback;
1561 : : }
1562 : :
1563 [ - + ]: 19 : if (dev_conf->rx_adv_conf.rss_conf.rss_key != NULL &&
1564 [ # # ]: 0 : dev_conf->rx_adv_conf.rss_conf.rss_key_len != dev_info.hash_key_size) {
1565 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1566 : : "Ethdev port_id=%u invalid RSS key len: %u, valid value: %u",
1567 : : port_id, dev_conf->rx_adv_conf.rss_conf.rss_key_len,
1568 : : dev_info.hash_key_size);
1569 : : ret = -EINVAL;
1570 : 0 : goto rollback;
1571 : : }
1572 : :
1573 : 19 : algorithm = dev_conf->rx_adv_conf.rss_conf.algorithm;
1574 [ + - ]: 19 : if ((size_t)algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
1575 [ - + ]: 19 : (dev_info.rss_algo_capa & RTE_ETH_HASH_ALGO_TO_CAPA(algorithm)) == 0) {
1576 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1577 : : "Ethdev port_id=%u configured RSS hash algorithm (%u)"
1578 : : "is not in the algorithm capability (0x%" PRIx32 ")",
1579 : : port_id, algorithm, dev_info.rss_algo_capa);
1580 : : ret = -EINVAL;
1581 : 0 : goto rollback;
1582 : : }
1583 : :
1584 : : /*
1585 : : * Setup new number of Rx/Tx queues and reconfigure device.
1586 : : */
1587 : 19 : diag = eth_dev_rx_queue_config(dev, nb_rx_q);
1588 [ - + ]: 19 : if (diag != 0) {
1589 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1590 : : "Port%u eth_dev_rx_queue_config = %d",
1591 : : port_id, diag);
1592 : : ret = diag;
1593 : 0 : goto rollback;
1594 : : }
1595 : :
1596 : 19 : diag = eth_dev_tx_queue_config(dev, nb_tx_q);
1597 [ - + ]: 19 : if (diag != 0) {
1598 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1599 : : "Port%u eth_dev_tx_queue_config = %d",
1600 : : port_id, diag);
1601 : 0 : eth_dev_rx_queue_config(dev, 0);
1602 : : ret = diag;
1603 : 0 : goto rollback;
1604 : : }
1605 : :
1606 : 19 : diag = dev->dev_ops->dev_configure(dev);
1607 [ - + ]: 19 : if (diag != 0) {
1608 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port%u dev_configure = %d",
1609 : : port_id, diag);
1610 : 0 : ret = eth_err(port_id, diag);
1611 : 0 : goto reset_queues;
1612 : : }
1613 : :
1614 : : /* Initialize Rx profiling if enabled at compilation time. */
1615 : 19 : diag = __rte_eth_dev_profile_init(port_id, dev);
1616 [ - + ]: 19 : if (diag != 0) {
1617 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port%u __rte_eth_dev_profile_init = %d",
1618 : : port_id, diag);
1619 : 0 : ret = eth_err(port_id, diag);
1620 : 0 : goto reset_queues;
1621 : : }
1622 : :
1623 : : /* Validate Rx offloads. */
1624 : 19 : diag = eth_dev_validate_offloads(port_id,
1625 : 19 : dev_conf->rxmode.offloads,
1626 : 19 : dev->data->dev_conf.rxmode.offloads, "Rx",
1627 : : rte_eth_dev_rx_offload_name);
1628 [ - + ]: 19 : if (diag != 0) {
1629 : : ret = diag;
1630 : 0 : goto reset_queues;
1631 : : }
1632 : :
1633 : : /* Validate Tx offloads. */
1634 : 19 : diag = eth_dev_validate_offloads(port_id,
1635 : 19 : dev_conf->txmode.offloads,
1636 : 19 : dev->data->dev_conf.txmode.offloads, "Tx",
1637 : : rte_eth_dev_tx_offload_name);
1638 [ - + ]: 19 : if (diag != 0) {
1639 : : ret = diag;
1640 : 0 : goto reset_queues;
1641 : : }
1642 : :
1643 [ - + ]: 19 : dev->data->dev_configured = 1;
1644 : 19 : rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
1645 : 19 : return 0;
1646 : 0 : reset_queues:
1647 : 0 : eth_dev_rx_queue_config(dev, 0);
1648 : 0 : eth_dev_tx_queue_config(dev, 0);
1649 : 0 : rollback:
1650 [ # # ]: 0 : memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
1651 [ # # ]: 0 : if (old_mtu != dev->data->mtu)
1652 : 0 : dev->data->mtu = old_mtu;
1653 : :
1654 : 0 : rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
1655 : 0 : return ret;
1656 : : }
1657 : :
1658 : : static void
1659 : 14 : eth_dev_mac_restore(struct rte_eth_dev *dev,
1660 : : struct rte_eth_dev_info *dev_info)
1661 : : {
1662 : : struct rte_ether_addr *addr;
1663 : : uint16_t i;
1664 : : uint32_t pool = 0;
1665 : : uint64_t pool_mask;
1666 : :
1667 : : /* replay MAC address configuration including default MAC */
1668 : 14 : addr = &dev->data->mac_addrs[0];
1669 [ + + ]: 14 : if (dev->dev_ops->mac_addr_set != NULL)
1670 : 4 : dev->dev_ops->mac_addr_set(dev, addr);
1671 [ + - ]: 10 : else if (dev->dev_ops->mac_addr_add != NULL)
1672 : 10 : dev->dev_ops->mac_addr_add(dev, addr, 0, pool);
1673 : :
1674 [ + - ]: 14 : if (dev->dev_ops->mac_addr_add != NULL) {
1675 [ + + ]: 74 : for (i = 1; i < dev_info->max_mac_addrs; i++) {
1676 [ + - ]: 60 : addr = &dev->data->mac_addrs[i];
1677 : :
1678 : : /* skip zero address */
1679 [ + - ]: 60 : if (rte_is_zero_ether_addr(addr))
1680 : 60 : continue;
1681 : :
1682 : : pool = 0;
1683 : 0 : pool_mask = dev->data->mac_pool_sel[i];
1684 : :
1685 : : do {
1686 [ # # ]: 0 : if (pool_mask & UINT64_C(1))
1687 : 0 : dev->dev_ops->mac_addr_add(dev, addr, i, pool);
1688 : 0 : pool_mask >>= 1;
1689 : 0 : pool++;
1690 [ # # ]: 0 : } while (pool_mask);
1691 : : }
1692 : : }
1693 : 14 : }
1694 : :
1695 : : static int
1696 : 14 : eth_dev_promiscuous_restore(struct rte_eth_dev *dev, uint16_t port_id)
1697 : : {
1698 : : int ret;
1699 : :
1700 : : /* replay promiscuous configuration */
1701 : : /*
1702 : : * use callbacks directly since we don't need port_id check and
1703 : : * would like to bypass the same value set
1704 : : */
1705 [ + + ]: 14 : if (rte_eth_promiscuous_get(port_id) == 1 &&
1706 [ + - ]: 10 : dev->dev_ops->promiscuous_enable != NULL) {
1707 : 10 : ret = eth_err(port_id, dev->dev_ops->promiscuous_enable(dev));
1708 [ - + ]: 10 : if (ret != 0 && ret != -ENOTSUP) {
1709 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1710 : : "Failed to enable promiscuous mode for device (port %u): %s",
1711 : : port_id, rte_strerror(-ret));
1712 : 0 : return ret;
1713 : : }
1714 [ + - ]: 4 : } else if (rte_eth_promiscuous_get(port_id) == 0 &&
1715 [ + - ]: 4 : dev->dev_ops->promiscuous_disable != NULL) {
1716 : 4 : ret = eth_err(port_id, dev->dev_ops->promiscuous_disable(dev));
1717 [ - + ]: 4 : if (ret != 0 && ret != -ENOTSUP) {
1718 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1719 : : "Failed to disable promiscuous mode for device (port %u): %s",
1720 : : port_id, rte_strerror(-ret));
1721 : 0 : return ret;
1722 : : }
1723 : : }
1724 : :
1725 : : return 0;
1726 : : }
1727 : :
1728 : : static int
1729 : 14 : eth_dev_allmulticast_restore(struct rte_eth_dev *dev, uint16_t port_id)
1730 : : {
1731 : : int ret;
1732 : :
1733 : : /* replay all multicast configuration */
1734 : : /*
1735 : : * use callbacks directly since we don't need port_id check and
1736 : : * would like to bypass the same value set
1737 : : */
1738 [ + + ]: 14 : if (rte_eth_allmulticast_get(port_id) == 1 &&
1739 [ + - ]: 10 : dev->dev_ops->allmulticast_enable != NULL) {
1740 : 10 : ret = eth_err(port_id, dev->dev_ops->allmulticast_enable(dev));
1741 [ - + ]: 10 : if (ret != 0 && ret != -ENOTSUP) {
1742 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1743 : : "Failed to enable allmulticast mode for device (port %u): %s",
1744 : : port_id, rte_strerror(-ret));
1745 : 0 : return ret;
1746 : : }
1747 [ + - ]: 4 : } else if (rte_eth_allmulticast_get(port_id) == 0 &&
1748 [ + - ]: 4 : dev->dev_ops->allmulticast_disable != NULL) {
1749 : 4 : ret = eth_err(port_id, dev->dev_ops->allmulticast_disable(dev));
1750 [ - + ]: 4 : if (ret != 0 && ret != -ENOTSUP) {
1751 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1752 : : "Failed to disable allmulticast mode for device (port %u): %s",
1753 : : port_id, rte_strerror(-ret));
1754 : 0 : return ret;
1755 : : }
1756 : : }
1757 : :
1758 : : return 0;
1759 : : }
1760 : :
1761 : : static int
1762 : 14 : eth_dev_config_restore(struct rte_eth_dev *dev,
1763 : : struct rte_eth_dev_info *dev_info,
1764 : : uint64_t restore_flags,
1765 : : uint16_t port_id)
1766 : : {
1767 : : int ret;
1768 : :
1769 [ + - ]: 14 : if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) &&
1770 [ + - ]: 14 : (restore_flags & RTE_ETH_RESTORE_MAC_ADDR))
1771 : 14 : eth_dev_mac_restore(dev, dev_info);
1772 : :
1773 [ + - ]: 14 : if (restore_flags & RTE_ETH_RESTORE_PROMISC) {
1774 : 14 : ret = eth_dev_promiscuous_restore(dev, port_id);
1775 [ + - ]: 14 : if (ret != 0)
1776 : : return ret;
1777 : : }
1778 : :
1779 [ + - ]: 14 : if (restore_flags & RTE_ETH_RESTORE_ALLMULTI) {
1780 : 14 : ret = eth_dev_allmulticast_restore(dev, port_id);
1781 [ - + ]: 14 : if (ret != 0)
1782 : 0 : return ret;
1783 : : }
1784 : :
1785 : : return 0;
1786 : : }
1787 : :
1788 : : RTE_EXPORT_SYMBOL(rte_eth_dev_start)
1789 : : int
1790 : 14 : rte_eth_dev_start(uint16_t port_id)
1791 : : {
1792 : : struct rte_eth_dev *dev;
1793 : : struct rte_eth_dev_info dev_info;
1794 : : uint64_t restore_flags;
1795 : : int diag;
1796 : : int ret, ret_stop;
1797 : :
1798 [ - + ]: 14 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1799 : 14 : dev = &rte_eth_devices[port_id];
1800 : :
1801 [ + - ]: 14 : if (dev->dev_ops->dev_start == NULL)
1802 : : return -ENOTSUP;
1803 : :
1804 [ - + ]: 14 : if (dev->data->dev_configured == 0) {
1805 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
1806 : : "Device with port_id=%"PRIu16" is not configured.",
1807 : : port_id);
1808 : 0 : return -EINVAL;
1809 : : }
1810 : :
1811 [ - + ]: 14 : if (dev->data->dev_started != 0) {
1812 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
1813 : : "Device with port_id=%"PRIu16" already started",
1814 : : port_id);
1815 : 0 : return 0;
1816 : : }
1817 : :
1818 : 14 : ret = rte_eth_dev_info_get(port_id, &dev_info);
1819 [ + - ]: 14 : if (ret != 0)
1820 : : return ret;
1821 : :
1822 : 14 : restore_flags = rte_eth_get_restore_flags(dev, RTE_ETH_START);
1823 : :
1824 : : /* Lets restore MAC now if device does not support live change */
1825 [ - + ]: 14 : if ((*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) &&
1826 [ # # ]: 0 : (restore_flags & RTE_ETH_RESTORE_MAC_ADDR))
1827 : 0 : eth_dev_mac_restore(dev, &dev_info);
1828 : :
1829 : 14 : diag = dev->dev_ops->dev_start(dev);
1830 [ + - ]: 14 : if (diag == 0)
1831 : 14 : dev->data->dev_started = 1;
1832 : : else
1833 : 0 : return eth_err(port_id, diag);
1834 : :
1835 : 14 : ret = eth_dev_config_restore(dev, &dev_info, restore_flags, port_id);
1836 [ - + ]: 14 : if (ret != 0) {
1837 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1838 : : "Error during restoring configuration for device (port %u): %s",
1839 : : port_id, rte_strerror(-ret));
1840 : 0 : ret_stop = rte_eth_dev_stop(port_id);
1841 [ # # ]: 0 : if (ret_stop != 0) {
1842 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1843 : : "Failed to stop device (port %u): %s",
1844 : : port_id, rte_strerror(-ret_stop));
1845 : : }
1846 : :
1847 : 0 : return ret;
1848 : : }
1849 : :
1850 [ + - ]: 14 : if (dev->data->dev_conf.intr_conf.lsc == 0) {
1851 [ + - ]: 14 : if (dev->dev_ops->link_update == NULL)
1852 : : return -ENOTSUP;
1853 : 14 : dev->dev_ops->link_update(dev, 0);
1854 : : }
1855 : :
1856 : : /* expose selection of PMD fast-path functions */
1857 : 14 : eth_dev_fp_ops_setup(rte_eth_fp_ops + port_id, dev);
1858 : :
1859 : 14 : rte_ethdev_trace_start(port_id);
1860 : 14 : return 0;
1861 : : }
1862 : :
1863 : : RTE_EXPORT_SYMBOL(rte_eth_dev_stop)
1864 : : int
1865 : 14 : rte_eth_dev_stop(uint16_t port_id)
1866 : : {
1867 : : struct rte_eth_dev *dev;
1868 : : int ret;
1869 : :
1870 [ - + ]: 14 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1871 : 14 : dev = &rte_eth_devices[port_id];
1872 : :
1873 [ + - ]: 14 : if (dev->dev_ops->dev_stop == NULL)
1874 : : return -ENOTSUP;
1875 : :
1876 [ - + ]: 14 : if (dev->data->dev_started == 0) {
1877 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
1878 : : "Device with port_id=%"PRIu16" already stopped",
1879 : : port_id);
1880 : 0 : return 0;
1881 : : }
1882 : :
1883 : : /* point fast-path functions to dummy ones */
1884 : 14 : eth_dev_fp_ops_reset(rte_eth_fp_ops + port_id);
1885 : :
1886 : 14 : ret = dev->dev_ops->dev_stop(dev);
1887 [ + - ]: 14 : if (ret == 0)
1888 : 14 : dev->data->dev_started = 0;
1889 : 14 : rte_ethdev_trace_stop(port_id, ret);
1890 : :
1891 : 14 : return ret;
1892 : : }
1893 : :
1894 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_link_up)
1895 : : int
1896 : 1 : rte_eth_dev_set_link_up(uint16_t port_id)
1897 : : {
1898 : : struct rte_eth_dev *dev;
1899 : : int ret;
1900 : :
1901 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1902 : 1 : dev = &rte_eth_devices[port_id];
1903 : :
1904 [ + - ]: 1 : if (dev->dev_ops->dev_set_link_up == NULL)
1905 : : return -ENOTSUP;
1906 : 1 : ret = eth_err(port_id, dev->dev_ops->dev_set_link_up(dev));
1907 : :
1908 : 1 : rte_ethdev_trace_set_link_up(port_id, ret);
1909 : :
1910 : 1 : return ret;
1911 : : }
1912 : :
1913 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_link_down)
1914 : : int
1915 : 1 : rte_eth_dev_set_link_down(uint16_t port_id)
1916 : : {
1917 : : struct rte_eth_dev *dev;
1918 : : int ret;
1919 : :
1920 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1921 : 1 : dev = &rte_eth_devices[port_id];
1922 : :
1923 [ + - ]: 1 : if (dev->dev_ops->dev_set_link_down == NULL)
1924 : : return -ENOTSUP;
1925 : 1 : ret = eth_err(port_id, dev->dev_ops->dev_set_link_down(dev));
1926 : :
1927 : 1 : rte_ethdev_trace_set_link_down(port_id, ret);
1928 : :
1929 : 1 : return ret;
1930 : : }
1931 : :
1932 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_speed_lanes_get, 24.11)
1933 : : int
1934 : 0 : rte_eth_speed_lanes_get(uint16_t port_id, uint32_t *lane)
1935 : : {
1936 : : struct rte_eth_dev *dev;
1937 : :
1938 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1939 : 0 : dev = &rte_eth_devices[port_id];
1940 : :
1941 [ # # ]: 0 : if (dev->dev_ops->speed_lanes_get == NULL)
1942 : : return -ENOTSUP;
1943 : 0 : return eth_err(port_id, dev->dev_ops->speed_lanes_get(dev, lane));
1944 : : }
1945 : :
1946 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_speed_lanes_get_capability, 24.11)
1947 : : int
1948 : 0 : rte_eth_speed_lanes_get_capability(uint16_t port_id,
1949 : : struct rte_eth_speed_lanes_capa *speed_lanes_capa,
1950 : : unsigned int num)
1951 : : {
1952 : : struct rte_eth_dev *dev;
1953 : : int ret;
1954 : :
1955 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1956 : 0 : dev = &rte_eth_devices[port_id];
1957 : :
1958 [ # # ]: 0 : if (dev->dev_ops->speed_lanes_get_capa == NULL)
1959 : : return -ENOTSUP;
1960 : :
1961 [ # # ]: 0 : if (speed_lanes_capa == NULL && num > 0) {
1962 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
1963 : : "Cannot get ethdev port %u speed lanes capability to NULL when array size is non zero",
1964 : : port_id);
1965 : 0 : return -EINVAL;
1966 : : }
1967 : :
1968 : 0 : ret = dev->dev_ops->speed_lanes_get_capa(dev, speed_lanes_capa, num);
1969 : :
1970 : 0 : return ret;
1971 : : }
1972 : :
1973 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_speed_lanes_set, 24.11)
1974 : : int
1975 : 0 : rte_eth_speed_lanes_set(uint16_t port_id, uint32_t speed_lanes_capa)
1976 : : {
1977 : : struct rte_eth_dev *dev;
1978 : :
1979 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1980 : 0 : dev = &rte_eth_devices[port_id];
1981 : :
1982 [ # # ]: 0 : if (dev->dev_ops->speed_lanes_set == NULL)
1983 : : return -ENOTSUP;
1984 : 0 : return eth_err(port_id, dev->dev_ops->speed_lanes_set(dev, speed_lanes_capa));
1985 : : }
1986 : :
1987 : : RTE_EXPORT_SYMBOL(rte_eth_dev_close)
1988 : : int
1989 : 4 : rte_eth_dev_close(uint16_t port_id)
1990 : : {
1991 : : struct rte_eth_dev *dev;
1992 : : int firsterr, binerr;
1993 : : int *lasterr = &firsterr;
1994 : :
1995 [ - + ]: 4 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1996 : 4 : dev = &rte_eth_devices[port_id];
1997 : :
1998 : : /*
1999 : : * Secondary process needs to close device to release process private
2000 : : * resources. But secondary process should not be obliged to wait
2001 : : * for device stop before closing ethdev.
2002 : : */
2003 [ + - ]: 4 : if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
2004 [ - + ]: 4 : dev->data->dev_started) {
2005 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot close started device (port %u)",
2006 : : port_id);
2007 : 0 : return -EINVAL;
2008 : : }
2009 : :
2010 [ + - ]: 4 : if (dev->dev_ops->dev_close == NULL)
2011 : : return -ENOTSUP;
2012 : 4 : *lasterr = dev->dev_ops->dev_close(dev);
2013 [ - + ]: 4 : if (*lasterr != 0)
2014 : : lasterr = &binerr;
2015 : :
2016 : 4 : rte_ethdev_trace_close(port_id);
2017 : 4 : *lasterr = rte_eth_dev_release_port(dev);
2018 : :
2019 : 4 : return firsterr;
2020 : : }
2021 : :
2022 : : RTE_EXPORT_SYMBOL(rte_eth_dev_reset)
2023 : : int
2024 : 0 : rte_eth_dev_reset(uint16_t port_id)
2025 : : {
2026 : : struct rte_eth_dev *dev;
2027 : : int ret;
2028 : :
2029 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2030 : 0 : dev = &rte_eth_devices[port_id];
2031 : :
2032 [ # # ]: 0 : if (dev->dev_ops->dev_reset == NULL)
2033 : : return -ENOTSUP;
2034 : :
2035 : 0 : ret = rte_eth_dev_stop(port_id);
2036 [ # # ]: 0 : if (ret != 0) {
2037 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2038 : : "Failed to stop device (port %u) before reset: %s - ignore",
2039 : : port_id, rte_strerror(-ret));
2040 : : }
2041 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_reset(dev));
2042 : :
2043 : 0 : rte_ethdev_trace_reset(port_id, ret);
2044 : :
2045 : 0 : return ret;
2046 : : }
2047 : :
2048 : : RTE_EXPORT_SYMBOL(rte_eth_dev_is_removed)
2049 : : int
2050 : 1 : rte_eth_dev_is_removed(uint16_t port_id)
2051 : : {
2052 : : struct rte_eth_dev *dev;
2053 : : int ret;
2054 : :
2055 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2056 : 1 : dev = &rte_eth_devices[port_id];
2057 : :
2058 [ + - ]: 1 : if (dev->state == RTE_ETH_DEV_REMOVED)
2059 : : return 1;
2060 : :
2061 [ - + ]: 1 : if (dev->dev_ops->is_removed == NULL)
2062 : : return 0;
2063 : :
2064 : 0 : ret = dev->dev_ops->is_removed(dev);
2065 [ # # ]: 0 : if (ret != 0)
2066 : : /* Device is physically removed. */
2067 : 0 : dev->state = RTE_ETH_DEV_REMOVED;
2068 : :
2069 : 0 : rte_ethdev_trace_is_removed(port_id, ret);
2070 : :
2071 : 0 : return ret;
2072 : : }
2073 : :
2074 : : static int
2075 : 46 : rte_eth_check_rx_mempool(struct rte_mempool *mp, uint16_t offset,
2076 : : uint16_t min_length)
2077 : : {
2078 : : uint16_t data_room_size;
2079 : :
2080 : : /*
2081 : : * Check the size of the mbuf data buffer, this value
2082 : : * must be provided in the private data of the memory pool.
2083 : : * First check that the memory pool(s) has a valid private data.
2084 : : */
2085 [ - + ]: 46 : if (mp->private_data_size <
2086 : : sizeof(struct rte_pktmbuf_pool_private)) {
2087 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "%s private_data_size %u < %u",
2088 : : mp->name, mp->private_data_size,
2089 : : (unsigned int)
2090 : : sizeof(struct rte_pktmbuf_pool_private));
2091 : 0 : return -ENOSPC;
2092 : : }
2093 : : data_room_size = rte_pktmbuf_data_room_size(mp);
2094 [ - + ]: 46 : if (data_room_size < offset + min_length) {
2095 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2096 : : "%s mbuf_data_room_size %u < %u (%u + %u)",
2097 : : mp->name, data_room_size,
2098 : : offset + min_length, offset, min_length);
2099 : 0 : return -EINVAL;
2100 : : }
2101 : : return 0;
2102 : : }
2103 : :
2104 : : static int
2105 : 0 : eth_dev_buffer_split_get_supported_hdrs_helper(uint16_t port_id, uint32_t **ptypes)
2106 : : {
2107 : : int cnt;
2108 : :
2109 : 0 : cnt = rte_eth_buffer_split_get_supported_hdr_ptypes(port_id, NULL, 0);
2110 [ # # ]: 0 : if (cnt <= 0)
2111 : : return cnt;
2112 : :
2113 : 0 : *ptypes = malloc(sizeof(uint32_t) * cnt);
2114 [ # # ]: 0 : if (*ptypes == NULL)
2115 : : return -ENOMEM;
2116 : :
2117 : 0 : cnt = rte_eth_buffer_split_get_supported_hdr_ptypes(port_id, *ptypes, cnt);
2118 [ # # ]: 0 : if (cnt <= 0) {
2119 : 0 : free(*ptypes);
2120 : 0 : *ptypes = NULL;
2121 : : }
2122 : : return cnt;
2123 : : }
2124 : :
2125 : : static int
2126 : 0 : rte_eth_rx_queue_check_split(uint16_t port_id,
2127 : : const struct rte_eth_rxseg_split *rx_seg,
2128 : : uint16_t n_seg, uint32_t *mbp_buf_size,
2129 : : const struct rte_eth_dev_info *dev_info)
2130 : : {
2131 : : const struct rte_eth_rxseg_capa *seg_capa = &dev_info->rx_seg_capa;
2132 : : struct rte_mempool *mp_first;
2133 : : uint32_t offset_mask;
2134 : : uint16_t seg_idx;
2135 : : int ret = 0;
2136 : : int ptype_cnt;
2137 : : uint32_t *ptypes;
2138 : : uint32_t prev_proto_hdrs = RTE_PTYPE_UNKNOWN;
2139 : : int i;
2140 : :
2141 [ # # ]: 0 : if (n_seg > seg_capa->max_nseg) {
2142 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2143 : : "Requested Rx segments %u exceed supported %u",
2144 : : n_seg, seg_capa->max_nseg);
2145 : 0 : return -EINVAL;
2146 : : }
2147 : : /*
2148 : : * Check the sizes and offsets against buffer sizes
2149 : : * for each segment specified in extended configuration.
2150 : : */
2151 : 0 : mp_first = rx_seg[0].mp;
2152 : 0 : offset_mask = RTE_BIT32(seg_capa->offset_align_log2) - 1;
2153 : :
2154 : 0 : ptypes = NULL;
2155 : 0 : ptype_cnt = eth_dev_buffer_split_get_supported_hdrs_helper(port_id, &ptypes);
2156 : :
2157 [ # # ]: 0 : for (seg_idx = 0; seg_idx < n_seg; seg_idx++) {
2158 : 0 : struct rte_mempool *mpl = rx_seg[seg_idx].mp;
2159 : 0 : uint32_t length = rx_seg[seg_idx].length;
2160 : 0 : uint32_t offset = rx_seg[seg_idx].offset;
2161 : 0 : uint32_t proto_hdr = rx_seg[seg_idx].proto_hdr;
2162 : :
2163 [ # # ]: 0 : if (mpl == NULL) {
2164 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "null mempool pointer");
2165 : : ret = -EINVAL;
2166 : 0 : goto out;
2167 : : }
2168 [ # # ]: 0 : if (seg_idx != 0 && mp_first != mpl &&
2169 [ # # ]: 0 : seg_capa->multi_pools == 0) {
2170 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Receiving to multiple pools is not supported");
2171 : : ret = -ENOTSUP;
2172 : 0 : goto out;
2173 : : }
2174 [ # # ]: 0 : if (offset != 0) {
2175 [ # # ]: 0 : if (seg_capa->offset_allowed == 0) {
2176 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx segmentation with offset is not supported");
2177 : : ret = -ENOTSUP;
2178 : 0 : goto out;
2179 : : }
2180 [ # # ]: 0 : if (offset & offset_mask) {
2181 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx segmentation invalid offset alignment %u, %u",
2182 : : offset,
2183 : : seg_capa->offset_align_log2);
2184 : : ret = -EINVAL;
2185 : 0 : goto out;
2186 : : }
2187 : : }
2188 : :
2189 [ # # # # ]: 0 : offset += seg_idx != 0 ? 0 : RTE_PKTMBUF_HEADROOM;
2190 : 0 : *mbp_buf_size = rte_pktmbuf_data_room_size(mpl);
2191 [ # # ]: 0 : if (proto_hdr != 0) {
2192 : : /* Split based on protocol headers. */
2193 [ # # ]: 0 : if (length != 0) {
2194 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2195 : : "Do not set length split and protocol split within a segment"
2196 : : );
2197 : : ret = -EINVAL;
2198 : 0 : goto out;
2199 : : }
2200 [ # # ]: 0 : if ((proto_hdr & prev_proto_hdrs) != 0) {
2201 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2202 : : "Repeat with previous protocol headers or proto-split after length-based split"
2203 : : );
2204 : : ret = -EINVAL;
2205 : 0 : goto out;
2206 : : }
2207 [ # # ]: 0 : if (ptype_cnt <= 0) {
2208 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2209 : : "Port %u failed to get supported buffer split header protocols",
2210 : : port_id);
2211 : : ret = -ENOTSUP;
2212 : 0 : goto out;
2213 : : }
2214 [ # # ]: 0 : for (i = 0; i < ptype_cnt; i++) {
2215 [ # # ]: 0 : if ((prev_proto_hdrs | proto_hdr) == ptypes[i])
2216 : : break;
2217 : : }
2218 [ # # ]: 0 : if (i == ptype_cnt) {
2219 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2220 : : "Requested Rx split header protocols 0x%x is not supported.",
2221 : : proto_hdr);
2222 : : ret = -EINVAL;
2223 : 0 : goto out;
2224 : : }
2225 : 0 : prev_proto_hdrs |= proto_hdr;
2226 : : } else {
2227 : : /* Split at fixed length. */
2228 [ # # ]: 0 : length = length != 0 ? length : *mbp_buf_size;
2229 : : prev_proto_hdrs = RTE_PTYPE_ALL_MASK;
2230 : : }
2231 : :
2232 : 0 : ret = rte_eth_check_rx_mempool(mpl, offset, length);
2233 [ # # ]: 0 : if (ret != 0)
2234 : 0 : goto out;
2235 : : }
2236 : 0 : out:
2237 : 0 : free(ptypes);
2238 : 0 : return ret;
2239 : : }
2240 : :
2241 : : static int
2242 : 0 : rte_eth_rx_queue_check_mempools(struct rte_mempool **rx_mempools,
2243 : : uint16_t n_mempools, uint32_t *min_buf_size,
2244 : : const struct rte_eth_dev_info *dev_info)
2245 : : {
2246 : : uint16_t pool_idx;
2247 : : int ret;
2248 : :
2249 [ # # ]: 0 : if (n_mempools > dev_info->max_rx_mempools) {
2250 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2251 : : "Too many Rx mempools %u vs maximum %u",
2252 : : n_mempools, dev_info->max_rx_mempools);
2253 : 0 : return -EINVAL;
2254 : : }
2255 : :
2256 [ # # ]: 0 : for (pool_idx = 0; pool_idx < n_mempools; pool_idx++) {
2257 : 0 : struct rte_mempool *mp = rx_mempools[pool_idx];
2258 : :
2259 [ # # ]: 0 : if (mp == NULL) {
2260 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "null Rx mempool pointer");
2261 : 0 : return -EINVAL;
2262 : : }
2263 : :
2264 : 0 : ret = rte_eth_check_rx_mempool(mp, RTE_PKTMBUF_HEADROOM,
2265 : 0 : dev_info->min_rx_bufsize);
2266 [ # # ]: 0 : if (ret != 0)
2267 : 0 : return ret;
2268 : :
2269 [ # # ]: 0 : *min_buf_size = RTE_MIN(*min_buf_size,
2270 : : rte_pktmbuf_data_room_size(mp));
2271 : : }
2272 : :
2273 : : return 0;
2274 : : }
2275 : :
2276 : : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_setup)
2277 : : int
2278 : 48 : rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
2279 : : uint16_t nb_rx_desc, unsigned int socket_id,
2280 : : const struct rte_eth_rxconf *rx_conf,
2281 : : struct rte_mempool *mp)
2282 : : {
2283 : : int ret;
2284 : : uint64_t rx_offloads;
2285 : 48 : uint32_t mbp_buf_size = UINT32_MAX;
2286 : : struct rte_eth_dev *dev;
2287 : : struct rte_eth_dev_info dev_info;
2288 : : struct rte_eth_rxconf local_conf;
2289 : : uint32_t buf_data_size;
2290 : :
2291 [ - + ]: 48 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2292 : 48 : dev = &rte_eth_devices[port_id];
2293 : :
2294 [ + + ]: 48 : if (rx_queue_id >= dev->data->nb_rx_queues) {
2295 : 1 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", rx_queue_id);
2296 : 1 : return -EINVAL;
2297 : : }
2298 : :
2299 [ + - ]: 47 : if (dev->dev_ops->rx_queue_setup == NULL)
2300 : : return -ENOTSUP;
2301 : :
2302 [ - + ]: 47 : if (rx_conf != NULL &&
2303 [ # # ]: 0 : (rx_conf->reserved_64s[0] != 0 ||
2304 [ # # ]: 0 : rx_conf->reserved_64s[1] != 0 ||
2305 [ # # ]: 0 : rx_conf->reserved_ptrs[0] != NULL ||
2306 [ # # ]: 0 : rx_conf->reserved_ptrs[1] != NULL)) {
2307 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx conf reserved fields not zero");
2308 : 0 : return -EINVAL;
2309 : : }
2310 : :
2311 : 47 : ret = rte_eth_dev_info_get(port_id, &dev_info);
2312 [ + - ]: 47 : if (ret != 0)
2313 : : return ret;
2314 : :
2315 : 47 : rx_offloads = dev->data->dev_conf.rxmode.offloads;
2316 [ - + ]: 47 : if (rx_conf != NULL)
2317 : 0 : rx_offloads |= rx_conf->offloads;
2318 : :
2319 : : /* Deferred start requires that device supports queue start */
2320 [ - + - - ]: 47 : if (rx_conf != NULL && rx_conf->rx_deferred_start &&
2321 [ # # ]: 0 : dev->dev_ops->rx_queue_start == NULL) {
2322 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2323 : : "Deferred start requested, but driver does not support Rx queue start");
2324 : 0 : return -ENOTSUP;
2325 : : }
2326 : :
2327 : : /* Ensure that we have one and only one source of Rx buffers */
2328 : 141 : if ((mp != NULL) +
2329 [ - + - - : 94 : (rx_conf != NULL && rx_conf->rx_nseg > 0) +
+ + ]
2330 [ - + - - ]: 47 : (rx_conf != NULL && rx_conf->rx_nmempool > 0) != 1) {
2331 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
2332 : : "Ambiguous Rx mempools configuration");
2333 : 1 : return -EINVAL;
2334 : : }
2335 : :
2336 [ + - ]: 46 : if (mp != NULL) {
2337 : : /* Single pool configuration check. */
2338 : 46 : ret = rte_eth_check_rx_mempool(mp, RTE_PKTMBUF_HEADROOM,
2339 : 46 : dev_info.min_rx_bufsize);
2340 [ + - ]: 46 : if (ret != 0)
2341 : : return ret;
2342 : :
2343 : 46 : mbp_buf_size = rte_pktmbuf_data_room_size(mp);
2344 : 46 : buf_data_size = mbp_buf_size - RTE_PKTMBUF_HEADROOM;
2345 [ - + ]: 46 : if (buf_data_size > dev_info.max_rx_bufsize)
2346 : 0 : RTE_ETHDEV_LOG_LINE(DEBUG,
2347 : : "For port_id=%u, the mbuf data buffer size (%u) is bigger than "
2348 : : "max buffer size (%u) device can utilize, so mbuf size can be reduced.",
2349 : : port_id, buf_data_size, dev_info.max_rx_bufsize);
2350 [ # # # # ]: 0 : } else if (rx_conf != NULL && rx_conf->rx_nseg > 0) {
2351 : : const struct rte_eth_rxseg_split *rx_seg;
2352 : : uint16_t n_seg;
2353 : :
2354 : : /* Extended multi-segment configuration check. */
2355 [ # # ]: 0 : if (rx_conf->rx_seg == NULL) {
2356 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2357 : : "Memory pool is null and no multi-segment configuration provided");
2358 : 0 : return -EINVAL;
2359 : : }
2360 : :
2361 : : rx_seg = (const struct rte_eth_rxseg_split *)rx_conf->rx_seg;
2362 : : n_seg = rx_conf->rx_nseg;
2363 : :
2364 [ # # ]: 0 : if (rx_offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
2365 : 0 : ret = rte_eth_rx_queue_check_split(port_id, rx_seg, n_seg,
2366 : : &mbp_buf_size,
2367 : : &dev_info);
2368 [ # # ]: 0 : if (ret != 0)
2369 : : return ret;
2370 : : } else {
2371 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "No Rx segmentation offload configured");
2372 : 0 : return -EINVAL;
2373 : : }
2374 [ # # # # ]: 0 : } else if (rx_conf != NULL && rx_conf->rx_nmempool > 0) {
2375 : : /* Extended multi-pool configuration check. */
2376 [ # # ]: 0 : if (rx_conf->rx_mempools == NULL) {
2377 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Memory pools array is null");
2378 : 0 : return -EINVAL;
2379 : : }
2380 : :
2381 : 0 : ret = rte_eth_rx_queue_check_mempools(rx_conf->rx_mempools,
2382 : : rx_conf->rx_nmempool,
2383 : : &mbp_buf_size,
2384 : : &dev_info);
2385 [ # # ]: 0 : if (ret != 0)
2386 : : return ret;
2387 : : } else {
2388 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Missing Rx mempool configuration");
2389 : 0 : return -EINVAL;
2390 : : }
2391 : :
2392 : : /* Use default specified by driver, if nb_rx_desc is zero */
2393 [ - + ]: 46 : if (nb_rx_desc == 0) {
2394 : 0 : nb_rx_desc = dev_info.default_rxportconf.ring_size;
2395 : : /* If driver default is also zero, fall back on EAL default */
2396 [ # # ]: 0 : if (nb_rx_desc == 0)
2397 : : nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE;
2398 : : }
2399 : :
2400 [ + - ]: 46 : if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
2401 [ + - ]: 46 : nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
2402 [ - + ]: 46 : nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) {
2403 : :
2404 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2405 : : "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu",
2406 : : nb_rx_desc, dev_info.rx_desc_lim.nb_max,
2407 : : dev_info.rx_desc_lim.nb_min,
2408 : : dev_info.rx_desc_lim.nb_align);
2409 : 0 : return -EINVAL;
2410 : : }
2411 : :
2412 [ - + ]: 46 : if (dev->data->dev_started &&
2413 [ # # ]: 0 : !(dev_info.dev_capa &
2414 : : RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP))
2415 : : return -EBUSY;
2416 : :
2417 [ - + ]: 46 : if (dev->data->dev_started &&
2418 [ # # ]: 0 : (dev->data->rx_queue_state[rx_queue_id] !=
2419 : : RTE_ETH_QUEUE_STATE_STOPPED))
2420 : : return -EBUSY;
2421 : :
2422 : 46 : eth_dev_rxq_release(dev, rx_queue_id);
2423 : :
2424 [ + - ]: 46 : if (rx_conf == NULL)
2425 : : rx_conf = &dev_info.default_rxconf;
2426 : :
2427 : 46 : local_conf = *rx_conf;
2428 : :
2429 : : /*
2430 : : * If an offloading has already been enabled in
2431 : : * rte_eth_dev_configure(), it has been enabled on all queues,
2432 : : * so there is no need to enable it in this queue again.
2433 : : * The local_conf.offloads input to underlying PMD only carries
2434 : : * those offloadings which are only enabled on this queue and
2435 : : * not enabled on all queues.
2436 : : */
2437 : 46 : local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads;
2438 : :
2439 : : /*
2440 : : * New added offloadings for this queue are those not enabled in
2441 : : * rte_eth_dev_configure() and they must be per-queue type.
2442 : : * A pure per-port offloading can't be enabled on a queue while
2443 : : * disabled on another queue. A pure per-port offloading can't
2444 : : * be enabled for any queue as new added one if it hasn't been
2445 : : * enabled in rte_eth_dev_configure().
2446 : : */
2447 [ - + ]: 46 : if ((local_conf.offloads & dev_info.rx_queue_offload_capa) !=
2448 : : local_conf.offloads) {
2449 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2450 : : "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
2451 : : "within per-queue offload capabilities 0x%"PRIx64" in %s()",
2452 : : port_id, rx_queue_id, local_conf.offloads,
2453 : : dev_info.rx_queue_offload_capa,
2454 : : __func__);
2455 : 0 : return -EINVAL;
2456 : : }
2457 : :
2458 [ - + ]: 46 : if (local_conf.share_group > 0 &&
2459 [ # # ]: 0 : (dev_info.dev_capa & RTE_ETH_DEV_CAPA_RXQ_SHARE) == 0) {
2460 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2461 : : "Ethdev port_id=%d rx_queue_id=%d, enabled share_group=%hu while device doesn't support Rx queue share",
2462 : : port_id, rx_queue_id, local_conf.share_group);
2463 : 0 : return -EINVAL;
2464 : : }
2465 : :
2466 : : /*
2467 : : * If LRO is enabled, check that the maximum aggregated packet
2468 : : * size is supported by the configured device.
2469 : : */
2470 : : /* Get the real Ethernet overhead length */
2471 [ - + ]: 46 : if (local_conf.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO) {
2472 : : uint32_t overhead_len;
2473 : : uint32_t max_rx_pktlen;
2474 : :
2475 : 0 : overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
2476 [ # # ]: 0 : dev_info.max_mtu);
2477 : 0 : max_rx_pktlen = dev->data->mtu + overhead_len;
2478 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0)
2479 : 0 : dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen;
2480 : 0 : ret = eth_dev_check_lro_pkt_size(port_id,
2481 : : dev->data->dev_conf.rxmode.max_lro_pkt_size,
2482 : : max_rx_pktlen,
2483 : : dev_info.max_lro_pkt_size);
2484 [ # # ]: 0 : if (ret != 0)
2485 : : return ret;
2486 : : }
2487 : :
2488 : 46 : ret = dev->dev_ops->rx_queue_setup(dev, rx_queue_id, nb_rx_desc,
2489 : : socket_id, &local_conf, mp);
2490 [ + + ]: 46 : if (!ret) {
2491 [ + + ]: 45 : if (!dev->data->min_rx_buf_size ||
2492 [ - + ]: 31 : dev->data->min_rx_buf_size > mbp_buf_size)
2493 : 14 : dev->data->min_rx_buf_size = mbp_buf_size;
2494 : : }
2495 : :
2496 : 46 : rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp,
2497 : : rx_conf, ret);
2498 : 46 : return eth_err(port_id, ret);
2499 : : }
2500 : :
2501 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_hairpin_queue_setup, 19.11)
2502 : : int
2503 : 0 : rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
2504 : : uint16_t nb_rx_desc,
2505 : : const struct rte_eth_hairpin_conf *conf)
2506 : : {
2507 : : int ret;
2508 : : struct rte_eth_dev *dev;
2509 : : struct rte_eth_hairpin_cap cap;
2510 : : int i;
2511 : : int count;
2512 : :
2513 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2514 : 0 : dev = &rte_eth_devices[port_id];
2515 : :
2516 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues) {
2517 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", rx_queue_id);
2518 : 0 : return -EINVAL;
2519 : : }
2520 : :
2521 [ # # ]: 0 : if (conf == NULL) {
2522 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2523 : : "Cannot setup ethdev port %u Rx hairpin queue from NULL config",
2524 : : port_id);
2525 : 0 : return -EINVAL;
2526 : : }
2527 : :
2528 [ # # ]: 0 : if (conf->reserved != 0) {
2529 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2530 : : "Rx hairpin reserved field not zero");
2531 : 0 : return -EINVAL;
2532 : : }
2533 : :
2534 : 0 : ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
2535 [ # # ]: 0 : if (ret != 0)
2536 : : return ret;
2537 [ # # ]: 0 : if (dev->dev_ops->rx_hairpin_queue_setup == NULL)
2538 : : return -ENOTSUP;
2539 : : /* if nb_rx_desc is zero use max number of desc from the driver. */
2540 [ # # ]: 0 : if (nb_rx_desc == 0)
2541 : 0 : nb_rx_desc = cap.max_nb_desc;
2542 [ # # ]: 0 : if (nb_rx_desc > cap.max_nb_desc) {
2543 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2544 : : "Invalid value for nb_rx_desc(=%hu), should be: <= %hu",
2545 : : nb_rx_desc, cap.max_nb_desc);
2546 : 0 : return -EINVAL;
2547 : : }
2548 [ # # ]: 0 : if (conf->peer_count > cap.max_rx_2_tx) {
2549 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2550 : : "Invalid value for number of peers for Rx queue(=%u), should be: <= %hu",
2551 : : conf->peer_count, cap.max_rx_2_tx);
2552 : 0 : return -EINVAL;
2553 : : }
2554 [ # # # # ]: 0 : if (conf->use_locked_device_memory && !cap.rx_cap.locked_device_memory) {
2555 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2556 : : "Attempt to use locked device memory for Rx queue, which is not supported");
2557 : 0 : return -EINVAL;
2558 : : }
2559 [ # # # # ]: 0 : if (conf->use_rte_memory && !cap.rx_cap.rte_memory) {
2560 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2561 : : "Attempt to use DPDK memory for Rx queue, which is not supported");
2562 : 0 : return -EINVAL;
2563 : : }
2564 [ # # ]: 0 : if (conf->use_locked_device_memory && conf->use_rte_memory) {
2565 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2566 : : "Attempt to use mutually exclusive memory settings for Rx queue");
2567 : 0 : return -EINVAL;
2568 : : }
2569 : 0 : if (conf->force_memory &&
2570 [ # # ]: 0 : !conf->use_locked_device_memory &&
2571 : : !conf->use_rte_memory) {
2572 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2573 : : "Attempt to force Rx queue memory settings, but none is set");
2574 : 0 : return -EINVAL;
2575 : : }
2576 [ # # ]: 0 : if (conf->peer_count == 0) {
2577 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2578 : : "Invalid value for number of peers for Rx queue(=%u), should be: > 0",
2579 : : conf->peer_count);
2580 : 0 : return -EINVAL;
2581 : : }
2582 [ # # ]: 0 : for (i = 0, count = 0; i < dev->data->nb_rx_queues &&
2583 [ # # ]: 0 : cap.max_nb_queues != UINT16_MAX; i++) {
2584 [ # # # # ]: 0 : if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i))
2585 : 0 : count++;
2586 : : }
2587 [ # # ]: 0 : if (count > cap.max_nb_queues) {
2588 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "To many Rx hairpin queues max is %d",
2589 : : cap.max_nb_queues);
2590 : 0 : return -EINVAL;
2591 : : }
2592 [ # # ]: 0 : if (dev->data->dev_started)
2593 : : return -EBUSY;
2594 : 0 : eth_dev_rxq_release(dev, rx_queue_id);
2595 : 0 : ret = dev->dev_ops->rx_hairpin_queue_setup(dev, rx_queue_id, nb_rx_desc, conf);
2596 [ # # ]: 0 : if (ret == 0)
2597 : 0 : dev->data->rx_queue_state[rx_queue_id] =
2598 : : RTE_ETH_QUEUE_STATE_HAIRPIN;
2599 : 0 : ret = eth_err(port_id, ret);
2600 : :
2601 : 0 : rte_eth_trace_rx_hairpin_queue_setup(port_id, rx_queue_id, nb_rx_desc,
2602 : : conf, ret);
2603 : :
2604 : 0 : return ret;
2605 : : }
2606 : :
2607 : : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_setup)
2608 : : int
2609 : 45 : rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2610 : : uint16_t nb_tx_desc, unsigned int socket_id,
2611 : : const struct rte_eth_txconf *tx_conf)
2612 : : {
2613 : : struct rte_eth_dev *dev;
2614 : : struct rte_eth_dev_info dev_info;
2615 : : struct rte_eth_txconf local_conf;
2616 : : int ret;
2617 : :
2618 [ - + ]: 45 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2619 : 45 : dev = &rte_eth_devices[port_id];
2620 : :
2621 [ - + ]: 45 : if (tx_queue_id >= dev->data->nb_tx_queues) {
2622 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
2623 : 0 : return -EINVAL;
2624 : : }
2625 : :
2626 [ + - ]: 45 : if (dev->dev_ops->tx_queue_setup == NULL)
2627 : : return -ENOTSUP;
2628 : :
2629 [ - + ]: 45 : if (tx_conf != NULL &&
2630 [ # # ]: 0 : (tx_conf->reserved_64s[0] != 0 ||
2631 [ # # ]: 0 : tx_conf->reserved_64s[1] != 0 ||
2632 [ # # ]: 0 : tx_conf->reserved_ptrs[0] != NULL ||
2633 [ # # ]: 0 : tx_conf->reserved_ptrs[1] != NULL)) {
2634 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Tx conf reserved fields not zero");
2635 : 0 : return -EINVAL;
2636 : : }
2637 : :
2638 : : /* Deferred start requires that device supports queue start */
2639 [ - + - - ]: 45 : if (tx_conf != NULL && tx_conf->tx_deferred_start &&
2640 [ # # ]: 0 : dev->dev_ops->tx_queue_start == NULL) {
2641 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2642 : : "Deferred start requested, but driver does not support Tx queue start");
2643 : 0 : return -ENOTSUP;
2644 : : }
2645 : :
2646 : 45 : ret = rte_eth_dev_info_get(port_id, &dev_info);
2647 [ + - ]: 45 : if (ret != 0)
2648 : : return ret;
2649 : :
2650 : : /* Use default specified by driver, if nb_tx_desc is zero */
2651 [ - + ]: 45 : if (nb_tx_desc == 0) {
2652 : 0 : nb_tx_desc = dev_info.default_txportconf.ring_size;
2653 : : /* If driver default is zero, fall back on EAL default */
2654 [ # # ]: 0 : if (nb_tx_desc == 0)
2655 : : nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2656 : : }
2657 [ + - ]: 45 : if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
2658 [ + - ]: 45 : nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
2659 [ - + ]: 45 : nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
2660 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2661 : : "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu",
2662 : : nb_tx_desc, dev_info.tx_desc_lim.nb_max,
2663 : : dev_info.tx_desc_lim.nb_min,
2664 : : dev_info.tx_desc_lim.nb_align);
2665 : 0 : return -EINVAL;
2666 : : }
2667 : :
2668 [ - + ]: 45 : if (dev->data->dev_started &&
2669 [ # # ]: 0 : !(dev_info.dev_capa &
2670 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP))
2671 : : return -EBUSY;
2672 : :
2673 [ - + ]: 45 : if (dev->data->dev_started &&
2674 [ # # ]: 0 : (dev->data->tx_queue_state[tx_queue_id] !=
2675 : : RTE_ETH_QUEUE_STATE_STOPPED))
2676 : : return -EBUSY;
2677 : :
2678 : 45 : eth_dev_txq_release(dev, tx_queue_id);
2679 : :
2680 [ + - ]: 45 : if (tx_conf == NULL)
2681 : : tx_conf = &dev_info.default_txconf;
2682 : :
2683 : 45 : local_conf = *tx_conf;
2684 : :
2685 : : /*
2686 : : * If an offloading has already been enabled in
2687 : : * rte_eth_dev_configure(), it has been enabled on all queues,
2688 : : * so there is no need to enable it in this queue again.
2689 : : * The local_conf.offloads input to underlying PMD only carries
2690 : : * those offloadings which are only enabled on this queue and
2691 : : * not enabled on all queues.
2692 : : */
2693 : 45 : local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads;
2694 : :
2695 : : /*
2696 : : * New added offloadings for this queue are those not enabled in
2697 : : * rte_eth_dev_configure() and they must be per-queue type.
2698 : : * A pure per-port offloading can't be enabled on a queue while
2699 : : * disabled on another queue. A pure per-port offloading can't
2700 : : * be enabled for any queue as new added one if it hasn't been
2701 : : * enabled in rte_eth_dev_configure().
2702 : : */
2703 [ - + ]: 45 : if ((local_conf.offloads & dev_info.tx_queue_offload_capa) !=
2704 : : local_conf.offloads) {
2705 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2706 : : "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
2707 : : "within per-queue offload capabilities 0x%"PRIx64" in %s()",
2708 : : port_id, tx_queue_id, local_conf.offloads,
2709 : : dev_info.tx_queue_offload_capa,
2710 : : __func__);
2711 : 0 : return -EINVAL;
2712 : : }
2713 : :
2714 [ - + ]: 45 : rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf);
2715 : 45 : return eth_err(port_id, dev->dev_ops->tx_queue_setup(dev,
2716 : : tx_queue_id, nb_tx_desc, socket_id, &local_conf));
2717 : : }
2718 : :
2719 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_tx_hairpin_queue_setup, 19.11)
2720 : : int
2721 : 0 : rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2722 : : uint16_t nb_tx_desc,
2723 : : const struct rte_eth_hairpin_conf *conf)
2724 : : {
2725 : : struct rte_eth_dev *dev;
2726 : : struct rte_eth_hairpin_cap cap;
2727 : : int i;
2728 : : int count;
2729 : : int ret;
2730 : :
2731 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2732 : 0 : dev = &rte_eth_devices[port_id];
2733 : :
2734 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
2735 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
2736 : 0 : return -EINVAL;
2737 : : }
2738 : :
2739 [ # # ]: 0 : if (conf == NULL) {
2740 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2741 : : "Cannot setup ethdev port %u Tx hairpin queue from NULL config",
2742 : : port_id);
2743 : 0 : return -EINVAL;
2744 : : }
2745 : :
2746 : 0 : ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
2747 [ # # ]: 0 : if (ret != 0)
2748 : : return ret;
2749 [ # # ]: 0 : if (dev->dev_ops->tx_hairpin_queue_setup == NULL)
2750 : : return -ENOTSUP;
2751 : : /* if nb_rx_desc is zero use max number of desc from the driver. */
2752 [ # # ]: 0 : if (nb_tx_desc == 0)
2753 : 0 : nb_tx_desc = cap.max_nb_desc;
2754 [ # # ]: 0 : if (nb_tx_desc > cap.max_nb_desc) {
2755 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2756 : : "Invalid value for nb_tx_desc(=%hu), should be: <= %hu",
2757 : : nb_tx_desc, cap.max_nb_desc);
2758 : 0 : return -EINVAL;
2759 : : }
2760 [ # # ]: 0 : if (conf->peer_count > cap.max_tx_2_rx) {
2761 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2762 : : "Invalid value for number of peers for Tx queue(=%u), should be: <= %hu",
2763 : : conf->peer_count, cap.max_tx_2_rx);
2764 : 0 : return -EINVAL;
2765 : : }
2766 [ # # # # ]: 0 : if (conf->use_locked_device_memory && !cap.tx_cap.locked_device_memory) {
2767 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2768 : : "Attempt to use locked device memory for Tx queue, which is not supported");
2769 : 0 : return -EINVAL;
2770 : : }
2771 [ # # # # ]: 0 : if (conf->use_rte_memory && !cap.tx_cap.rte_memory) {
2772 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2773 : : "Attempt to use DPDK memory for Tx queue, which is not supported");
2774 : 0 : return -EINVAL;
2775 : : }
2776 [ # # ]: 0 : if (conf->use_locked_device_memory && conf->use_rte_memory) {
2777 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2778 : : "Attempt to use mutually exclusive memory settings for Tx queue");
2779 : 0 : return -EINVAL;
2780 : : }
2781 : 0 : if (conf->force_memory &&
2782 [ # # ]: 0 : !conf->use_locked_device_memory &&
2783 : : !conf->use_rte_memory) {
2784 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2785 : : "Attempt to force Tx queue memory settings, but none is set");
2786 : 0 : return -EINVAL;
2787 : : }
2788 [ # # ]: 0 : if (conf->peer_count == 0) {
2789 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2790 : : "Invalid value for number of peers for Tx queue(=%u), should be: > 0",
2791 : : conf->peer_count);
2792 : 0 : return -EINVAL;
2793 : : }
2794 [ # # ]: 0 : for (i = 0, count = 0; i < dev->data->nb_tx_queues &&
2795 [ # # ]: 0 : cap.max_nb_queues != UINT16_MAX; i++) {
2796 [ # # # # ]: 0 : if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i))
2797 : 0 : count++;
2798 : : }
2799 [ # # ]: 0 : if (count > cap.max_nb_queues) {
2800 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "To many Tx hairpin queues max is %d",
2801 : : cap.max_nb_queues);
2802 : 0 : return -EINVAL;
2803 : : }
2804 [ # # ]: 0 : if (dev->data->dev_started)
2805 : : return -EBUSY;
2806 : 0 : eth_dev_txq_release(dev, tx_queue_id);
2807 : 0 : ret = dev->dev_ops->tx_hairpin_queue_setup(dev, tx_queue_id, nb_tx_desc, conf);
2808 [ # # ]: 0 : if (ret == 0)
2809 : 0 : dev->data->tx_queue_state[tx_queue_id] =
2810 : : RTE_ETH_QUEUE_STATE_HAIRPIN;
2811 : 0 : ret = eth_err(port_id, ret);
2812 : :
2813 : 0 : rte_eth_trace_tx_hairpin_queue_setup(port_id, tx_queue_id, nb_tx_desc,
2814 : : conf, ret);
2815 : :
2816 : 0 : return ret;
2817 : : }
2818 : :
2819 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_hairpin_bind, 20.11)
2820 : : int
2821 : 0 : rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port)
2822 : : {
2823 : : struct rte_eth_dev *dev;
2824 : : int ret;
2825 : :
2826 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
2827 : 0 : dev = &rte_eth_devices[tx_port];
2828 : :
2829 [ # # ]: 0 : if (dev->data->dev_started == 0) {
2830 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Tx port %d is not started", tx_port);
2831 : 0 : return -EBUSY;
2832 : : }
2833 : :
2834 [ # # ]: 0 : if (dev->dev_ops->hairpin_bind == NULL)
2835 : : return -ENOTSUP;
2836 : 0 : ret = dev->dev_ops->hairpin_bind(dev, rx_port);
2837 [ # # ]: 0 : if (ret != 0)
2838 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Failed to bind hairpin Tx %d"
2839 : : " to Rx %d (%d - all ports)",
2840 : : tx_port, rx_port, RTE_MAX_ETHPORTS);
2841 : :
2842 : 0 : rte_eth_trace_hairpin_bind(tx_port, rx_port, ret);
2843 : :
2844 : 0 : return ret;
2845 : : }
2846 : :
2847 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_hairpin_unbind, 20.11)
2848 : : int
2849 : 0 : rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port)
2850 : : {
2851 : : struct rte_eth_dev *dev;
2852 : : int ret;
2853 : :
2854 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
2855 : 0 : dev = &rte_eth_devices[tx_port];
2856 : :
2857 [ # # ]: 0 : if (dev->data->dev_started == 0) {
2858 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Tx port %d is already stopped", tx_port);
2859 : 0 : return -EBUSY;
2860 : : }
2861 : :
2862 [ # # ]: 0 : if (dev->dev_ops->hairpin_unbind == NULL)
2863 : : return -ENOTSUP;
2864 : 0 : ret = dev->dev_ops->hairpin_unbind(dev, rx_port);
2865 [ # # ]: 0 : if (ret != 0)
2866 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Failed to unbind hairpin Tx %d"
2867 : : " from Rx %d (%d - all ports)",
2868 : : tx_port, rx_port, RTE_MAX_ETHPORTS);
2869 : :
2870 : 0 : rte_eth_trace_hairpin_unbind(tx_port, rx_port, ret);
2871 : :
2872 : 0 : return ret;
2873 : : }
2874 : :
2875 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_hairpin_get_peer_ports, 20.11)
2876 : : int
2877 : 0 : rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports,
2878 : : size_t len, uint32_t direction)
2879 : : {
2880 : : struct rte_eth_dev *dev;
2881 : : int ret;
2882 : :
2883 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2884 : 0 : dev = &rte_eth_devices[port_id];
2885 : :
2886 [ # # ]: 0 : if (peer_ports == NULL) {
2887 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2888 : : "Cannot get ethdev port %u hairpin peer ports to NULL",
2889 : : port_id);
2890 : 0 : return -EINVAL;
2891 : : }
2892 : :
2893 [ # # ]: 0 : if (len == 0) {
2894 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2895 : : "Cannot get ethdev port %u hairpin peer ports to array with zero size",
2896 : : port_id);
2897 : 0 : return -EINVAL;
2898 : : }
2899 : :
2900 [ # # ]: 0 : if (dev->dev_ops->hairpin_get_peer_ports == NULL)
2901 : : return -ENOTSUP;
2902 : :
2903 : 0 : ret = dev->dev_ops->hairpin_get_peer_ports(dev, peer_ports, len, direction);
2904 [ # # ]: 0 : if (ret < 0)
2905 [ # # ]: 0 : RTE_ETHDEV_LOG_LINE(ERR, "Failed to get %d hairpin peer %s ports",
2906 : : port_id, direction ? "Rx" : "Tx");
2907 : :
2908 : 0 : rte_eth_trace_hairpin_get_peer_ports(port_id, peer_ports, len,
2909 : : direction, ret);
2910 : :
2911 : 0 : return ret;
2912 : : }
2913 : :
2914 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_drop_callback)
2915 : : void
2916 : 0 : rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
2917 : : void *userdata __rte_unused)
2918 : : {
2919 : 0 : rte_pktmbuf_free_bulk(pkts, unsent);
2920 : :
2921 : : rte_eth_trace_tx_buffer_drop_callback((void **)pkts, unsent);
2922 : 0 : }
2923 : :
2924 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_count_callback)
2925 : : void
2926 : 0 : rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
2927 : : void *userdata)
2928 : : {
2929 : : uint64_t *count = userdata;
2930 : :
2931 : 0 : rte_pktmbuf_free_bulk(pkts, unsent);
2932 : 0 : *count += unsent;
2933 : :
2934 : : rte_eth_trace_tx_buffer_count_callback((void **)pkts, unsent, *count);
2935 : 0 : }
2936 : :
2937 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_set_err_callback)
2938 : : int
2939 : 108 : rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
2940 : : buffer_tx_error_fn cbfn, void *userdata)
2941 : : {
2942 [ - + ]: 108 : if (buffer == NULL) {
2943 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2944 : : "Cannot set Tx buffer error callback to NULL buffer");
2945 : 0 : return -EINVAL;
2946 : : }
2947 : :
2948 : 108 : buffer->error_callback = cbfn;
2949 [ - + ]: 108 : buffer->error_userdata = userdata;
2950 : :
2951 : : rte_eth_trace_tx_buffer_set_err_callback(buffer);
2952 : :
2953 : : return 0;
2954 : : }
2955 : :
2956 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_init)
2957 : : int
2958 : 54 : rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
2959 : : {
2960 : : int ret = 0;
2961 : :
2962 [ - + ]: 54 : if (buffer == NULL) {
2963 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize NULL buffer");
2964 : 0 : return -EINVAL;
2965 : : }
2966 : :
2967 : 54 : buffer->size = size;
2968 [ + - ]: 54 : if (buffer->error_callback == NULL) {
2969 : 54 : ret = rte_eth_tx_buffer_set_err_callback(
2970 : : buffer, rte_eth_tx_buffer_drop_callback, NULL);
2971 : : }
2972 : :
2973 : 54 : rte_eth_trace_tx_buffer_init(buffer, size, ret);
2974 : :
2975 : 54 : return ret;
2976 : : }
2977 : :
2978 : : RTE_EXPORT_SYMBOL(rte_eth_tx_done_cleanup)
2979 : : int
2980 : 0 : rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
2981 : : {
2982 : : struct rte_eth_dev *dev;
2983 : : int ret;
2984 : :
2985 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2986 : : dev = &rte_eth_devices[port_id];
2987 : :
2988 : : #ifdef RTE_ETHDEV_DEBUG_TX
2989 : : ret = eth_dev_validate_tx_queue(dev, queue_id);
2990 : : if (ret != 0)
2991 : : return ret;
2992 : : #endif
2993 : :
2994 [ # # ]: 0 : if (dev->dev_ops->tx_done_cleanup == NULL)
2995 : : return -ENOTSUP;
2996 : :
2997 : : /* Call driver to free pending mbufs. */
2998 : 0 : ret = dev->dev_ops->tx_done_cleanup(dev->data->tx_queues[queue_id], free_cnt);
2999 : 0 : ret = eth_err(port_id, ret);
3000 : :
3001 : 0 : rte_eth_trace_tx_done_cleanup(port_id, queue_id, free_cnt, ret);
3002 : :
3003 : 0 : return ret;
3004 : : }
3005 : :
3006 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_enable)
3007 : : int
3008 : 5 : rte_eth_promiscuous_enable(uint16_t port_id)
3009 : : {
3010 : : struct rte_eth_dev *dev;
3011 : : int diag = 0;
3012 : :
3013 [ - + ]: 5 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3014 : 5 : dev = &rte_eth_devices[port_id];
3015 : :
3016 [ + + ]: 5 : if (dev->data->promiscuous == 1)
3017 : : return 0;
3018 : :
3019 [ + - ]: 3 : if (dev->dev_ops->promiscuous_enable == NULL)
3020 : : return -ENOTSUP;
3021 : :
3022 : 3 : diag = dev->dev_ops->promiscuous_enable(dev);
3023 [ + - ]: 3 : if (diag == 0)
3024 : 3 : dev->data->promiscuous = 1;
3025 : :
3026 : 3 : diag = eth_err(port_id, diag);
3027 : :
3028 [ - + ]: 3 : rte_eth_trace_promiscuous_enable(port_id, dev->data->promiscuous,
3029 : : diag);
3030 : :
3031 : 3 : return diag;
3032 : : }
3033 : :
3034 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_disable)
3035 : : int
3036 : 3 : rte_eth_promiscuous_disable(uint16_t port_id)
3037 : : {
3038 : : struct rte_eth_dev *dev;
3039 : : int diag = 0;
3040 : :
3041 [ - + ]: 3 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3042 : 3 : dev = &rte_eth_devices[port_id];
3043 : :
3044 [ + + ]: 3 : if (dev->data->promiscuous == 0)
3045 : : return 0;
3046 : :
3047 [ + - ]: 2 : if (dev->dev_ops->promiscuous_disable == NULL)
3048 : : return -ENOTSUP;
3049 : :
3050 : 2 : diag = dev->dev_ops->promiscuous_disable(dev);
3051 [ + - ]: 2 : if (diag == 0)
3052 : 2 : dev->data->promiscuous = 0;
3053 : :
3054 : 2 : diag = eth_err(port_id, diag);
3055 : :
3056 [ - + ]: 2 : rte_eth_trace_promiscuous_disable(port_id, dev->data->promiscuous,
3057 : : diag);
3058 : :
3059 : 2 : return diag;
3060 : : }
3061 : :
3062 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_get)
3063 : : int
3064 : 21 : rte_eth_promiscuous_get(uint16_t port_id)
3065 : : {
3066 : : struct rte_eth_dev *dev;
3067 : :
3068 [ - + ]: 21 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3069 : : dev = &rte_eth_devices[port_id];
3070 : :
3071 [ - + ]: 21 : rte_eth_trace_promiscuous_get(port_id, dev->data->promiscuous);
3072 : :
3073 : 21 : return dev->data->promiscuous;
3074 : : }
3075 : :
3076 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_enable)
3077 : : int
3078 : 2 : rte_eth_allmulticast_enable(uint16_t port_id)
3079 : : {
3080 : : struct rte_eth_dev *dev;
3081 : : int diag;
3082 : :
3083 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3084 : 2 : dev = &rte_eth_devices[port_id];
3085 : :
3086 [ + - ]: 2 : if (dev->data->all_multicast == 1)
3087 : : return 0;
3088 : :
3089 [ + - ]: 2 : if (dev->dev_ops->allmulticast_enable == NULL)
3090 : : return -ENOTSUP;
3091 : 2 : diag = dev->dev_ops->allmulticast_enable(dev);
3092 [ + - ]: 2 : if (diag == 0)
3093 : 2 : dev->data->all_multicast = 1;
3094 : :
3095 : 2 : diag = eth_err(port_id, diag);
3096 : :
3097 [ - + ]: 2 : rte_eth_trace_allmulticast_enable(port_id, dev->data->all_multicast,
3098 : : diag);
3099 : :
3100 : 2 : return diag;
3101 : : }
3102 : :
3103 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_disable)
3104 : : int
3105 : 3 : rte_eth_allmulticast_disable(uint16_t port_id)
3106 : : {
3107 : : struct rte_eth_dev *dev;
3108 : : int diag;
3109 : :
3110 [ - + ]: 3 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3111 : 3 : dev = &rte_eth_devices[port_id];
3112 : :
3113 [ + + ]: 3 : if (dev->data->all_multicast == 0)
3114 : : return 0;
3115 : :
3116 [ + - ]: 2 : if (dev->dev_ops->allmulticast_disable == NULL)
3117 : : return -ENOTSUP;
3118 : :
3119 : 2 : diag = dev->dev_ops->allmulticast_disable(dev);
3120 [ + - ]: 2 : if (diag == 0)
3121 : 2 : dev->data->all_multicast = 0;
3122 : :
3123 : 2 : diag = eth_err(port_id, diag);
3124 : :
3125 [ - + ]: 2 : rte_eth_trace_allmulticast_disable(port_id, dev->data->all_multicast,
3126 : : diag);
3127 : :
3128 : 2 : return diag;
3129 : : }
3130 : :
3131 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_get)
3132 : : int
3133 : 21 : rte_eth_allmulticast_get(uint16_t port_id)
3134 : : {
3135 : : struct rte_eth_dev *dev;
3136 : :
3137 [ - + ]: 21 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3138 : : dev = &rte_eth_devices[port_id];
3139 : :
3140 [ - + ]: 21 : rte_eth_trace_allmulticast_get(port_id, dev->data->all_multicast);
3141 : :
3142 : 21 : return dev->data->all_multicast;
3143 : : }
3144 : :
3145 : : RTE_EXPORT_SYMBOL(rte_eth_link_get)
3146 : : int
3147 : 10 : rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
3148 : : {
3149 : : struct rte_eth_dev *dev;
3150 : :
3151 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3152 : 10 : dev = &rte_eth_devices[port_id];
3153 : :
3154 [ - + ]: 10 : if (eth_link == NULL) {
3155 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u link to NULL",
3156 : : port_id);
3157 : 0 : return -EINVAL;
3158 : : }
3159 : :
3160 [ - + - - ]: 10 : if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
3161 : 0 : rte_eth_linkstatus_get(dev, eth_link);
3162 : : else {
3163 [ + - ]: 10 : if (dev->dev_ops->link_update == NULL)
3164 : : return -ENOTSUP;
3165 : 10 : dev->dev_ops->link_update(dev, 1);
3166 : 10 : *eth_link = dev->data->dev_link;
3167 : : }
3168 : :
3169 : : rte_eth_trace_link_get(port_id, eth_link);
3170 : :
3171 : : return 0;
3172 : : }
3173 : :
3174 : : RTE_EXPORT_SYMBOL(rte_eth_link_get_nowait)
3175 : : int
3176 : 5 : rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
3177 : : {
3178 : : struct rte_eth_dev *dev;
3179 : :
3180 [ - + ]: 5 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3181 : 5 : dev = &rte_eth_devices[port_id];
3182 : :
3183 [ - + ]: 5 : if (eth_link == NULL) {
3184 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u link to NULL",
3185 : : port_id);
3186 : 0 : return -EINVAL;
3187 : : }
3188 : :
3189 [ - + - - ]: 5 : if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
3190 : 0 : rte_eth_linkstatus_get(dev, eth_link);
3191 : : else {
3192 [ + - ]: 5 : if (dev->dev_ops->link_update == NULL)
3193 : : return -ENOTSUP;
3194 : 5 : dev->dev_ops->link_update(dev, 0);
3195 : 5 : *eth_link = dev->data->dev_link;
3196 : : }
3197 : :
3198 : 5 : rte_eth_trace_link_get_nowait(port_id, eth_link);
3199 : :
3200 : 5 : return 0;
3201 : : }
3202 : :
3203 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_speed_to_str, 20.11)
3204 : : const char *
3205 : 24 : rte_eth_link_speed_to_str(uint32_t link_speed)
3206 : : {
3207 : : const char *ret;
3208 : :
3209 [ + + + + : 24 : switch (link_speed) {
+ + + + +
+ + + + +
+ + + + ]
3210 : : case RTE_ETH_SPEED_NUM_NONE:
3211 : : ret = "None";
3212 : : break;
3213 : 2 : case RTE_ETH_SPEED_NUM_10M:
3214 : : ret = "10 Mbps";
3215 : 2 : break;
3216 : 1 : case RTE_ETH_SPEED_NUM_100M:
3217 : : ret = "100 Mbps";
3218 : 1 : break;
3219 : 1 : case RTE_ETH_SPEED_NUM_1G:
3220 : : ret = "1 Gbps";
3221 : 1 : break;
3222 : 2 : case RTE_ETH_SPEED_NUM_2_5G:
3223 : : ret = "2.5 Gbps";
3224 : 2 : break;
3225 : 1 : case RTE_ETH_SPEED_NUM_5G:
3226 : : ret = "5 Gbps";
3227 : 1 : break;
3228 : 1 : case RTE_ETH_SPEED_NUM_10G:
3229 : : ret = "10 Gbps";
3230 : 1 : break;
3231 : 1 : case RTE_ETH_SPEED_NUM_20G:
3232 : : ret = "20 Gbps";
3233 : 1 : break;
3234 : 1 : case RTE_ETH_SPEED_NUM_25G:
3235 : : ret = "25 Gbps";
3236 : 1 : break;
3237 : 1 : case RTE_ETH_SPEED_NUM_40G:
3238 : : ret = "40 Gbps";
3239 : 1 : break;
3240 : 1 : case RTE_ETH_SPEED_NUM_50G:
3241 : : ret = "50 Gbps";
3242 : 1 : break;
3243 : 1 : case RTE_ETH_SPEED_NUM_56G:
3244 : : ret = "56 Gbps";
3245 : 1 : break;
3246 : 1 : case RTE_ETH_SPEED_NUM_100G:
3247 : : ret = "100 Gbps";
3248 : 1 : break;
3249 : 1 : case RTE_ETH_SPEED_NUM_200G:
3250 : : ret = "200 Gbps";
3251 : 1 : break;
3252 : 1 : case RTE_ETH_SPEED_NUM_400G:
3253 : : ret = "400 Gbps";
3254 : 1 : break;
3255 : 2 : case RTE_ETH_SPEED_NUM_800G:
3256 : : ret = "800 Gbps";
3257 : 2 : break;
3258 : 2 : case RTE_ETH_SPEED_NUM_UNKNOWN:
3259 : : ret = "Unknown";
3260 : 2 : break;
3261 : 2 : default:
3262 : : ret = "Invalid";
3263 : : }
3264 : :
3265 : : rte_eth_trace_link_speed_to_str(link_speed, ret);
3266 : :
3267 : 24 : return ret;
3268 : : }
3269 : :
3270 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_to_str, 20.11)
3271 : : int
3272 : 7 : rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
3273 : : {
3274 : : int ret;
3275 : :
3276 [ - + ]: 7 : if (str == NULL) {
3277 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot convert link to NULL string");
3278 : 0 : return -EINVAL;
3279 : : }
3280 : :
3281 [ - + ]: 7 : if (len == 0) {
3282 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
3283 : : "Cannot convert link to string with zero size");
3284 : 0 : return -EINVAL;
3285 : : }
3286 : :
3287 [ - + ]: 7 : if (eth_link == NULL) {
3288 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot convert to string from NULL link");
3289 : 0 : return -EINVAL;
3290 : : }
3291 : :
3292 [ + + ]: 7 : if (eth_link->link_status == RTE_ETH_LINK_DOWN)
3293 : : ret = snprintf(str, len, "Link down");
3294 : : else
3295 : 24 : ret = snprintf(str, len, "Link up at %s %s %s %s",
3296 : 6 : rte_eth_link_speed_to_str(eth_link->link_speed),
3297 [ + + ]: 6 : (eth_link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
3298 : : "FDX" : "HDX",
3299 [ + + ]: 6 : (eth_link->link_autoneg == RTE_ETH_LINK_AUTONEG) ?
3300 : : "Autoneg" : "Fixed",
3301 : 6 : rte_eth_link_connector_to_str(eth_link->link_connector));
3302 : :
3303 : 7 : rte_eth_trace_link_to_str(len, eth_link, str, ret);
3304 : :
3305 : 7 : return ret;
3306 : : }
3307 : :
3308 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_connector_to_str, 25.11)
3309 : : const char *
3310 : 6 : rte_eth_link_connector_to_str(enum rte_eth_link_connector link_connector)
3311 : : {
3312 : : static const char * const link_connector_str[] = {
3313 : : [RTE_ETH_LINK_CONNECTOR_NONE] = "None",
3314 : : [RTE_ETH_LINK_CONNECTOR_TP] = "Twisted Pair",
3315 : : [RTE_ETH_LINK_CONNECTOR_AUI] = "Attachment Unit Interface",
3316 : : [RTE_ETH_LINK_CONNECTOR_MII] = "Media Independent Interface",
3317 : : [RTE_ETH_LINK_CONNECTOR_FIBER] = "Fiber",
3318 : : [RTE_ETH_LINK_CONNECTOR_BNC] = "BNC",
3319 : : [RTE_ETH_LINK_CONNECTOR_DAC] = "Direct Attach Copper",
3320 : : [RTE_ETH_LINK_CONNECTOR_SGMII] = "SGMII",
3321 : : [RTE_ETH_LINK_CONNECTOR_QSGMII] = "QSGMII",
3322 : : [RTE_ETH_LINK_CONNECTOR_XFI] = "XFI",
3323 : : [RTE_ETH_LINK_CONNECTOR_SFI] = "SFI",
3324 : : [RTE_ETH_LINK_CONNECTOR_XLAUI] = "XLAUI",
3325 : : [RTE_ETH_LINK_CONNECTOR_GAUI] = "GAUI",
3326 : : [RTE_ETH_LINK_CONNECTOR_XAUI] = "XAUI",
3327 : : [RTE_ETH_LINK_CONNECTOR_CAUI] = "CAUI",
3328 : : [RTE_ETH_LINK_CONNECTOR_LAUI] = "LAUI",
3329 : : [RTE_ETH_LINK_CONNECTOR_SFP] = "SFP",
3330 : : [RTE_ETH_LINK_CONNECTOR_SFP_DD] = "SFP-DD",
3331 : : [RTE_ETH_LINK_CONNECTOR_SFP_PLUS] = "SFP+",
3332 : : [RTE_ETH_LINK_CONNECTOR_SFP28] = "SFP28",
3333 : : [RTE_ETH_LINK_CONNECTOR_QSFP] = "QSFP",
3334 : : [RTE_ETH_LINK_CONNECTOR_QSFP_PLUS] = "QSFP+",
3335 : : [RTE_ETH_LINK_CONNECTOR_QSFP28] = "QSFP28",
3336 : : [RTE_ETH_LINK_CONNECTOR_QSFP56] = "QSFP56",
3337 : : [RTE_ETH_LINK_CONNECTOR_QSFP_DD] = "QSFP-DD",
3338 : : [RTE_ETH_LINK_CONNECTOR_OTHER] = "Other",
3339 : : };
3340 : : const char *str = NULL;
3341 : :
3342 [ + - ]: 6 : if (link_connector < ((enum rte_eth_link_connector)RTE_DIM(link_connector_str)))
3343 : 6 : str = link_connector_str[link_connector];
3344 : :
3345 : 6 : return str;
3346 : : }
3347 : :
3348 : : RTE_EXPORT_SYMBOL(rte_eth_stats_get)
3349 : : int
3350 : 28 : rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
3351 : : {
3352 : 28 : int ret = eth_stats_qstats_get(port_id, stats, NULL);
3353 : :
3354 : : rte_eth_trace_stats_get(port_id, stats, ret);
3355 : 28 : return ret;
3356 : : }
3357 : :
3358 : : RTE_EXPORT_SYMBOL(rte_eth_stats_reset)
3359 : : int
3360 : 7 : rte_eth_stats_reset(uint16_t port_id)
3361 : : {
3362 : : struct rte_eth_dev *dev;
3363 : : int ret;
3364 : :
3365 [ - + ]: 7 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3366 : 7 : dev = &rte_eth_devices[port_id];
3367 : :
3368 [ + - ]: 7 : if (dev->dev_ops->stats_reset == NULL)
3369 : : return -ENOTSUP;
3370 : 7 : ret = dev->dev_ops->stats_reset(dev);
3371 [ - + ]: 7 : if (ret != 0)
3372 : 0 : return eth_err(port_id, ret);
3373 : :
3374 [ - + ]: 7 : dev->data->rx_mbuf_alloc_failed = 0;
3375 : :
3376 : 7 : rte_eth_trace_stats_reset(port_id);
3377 : :
3378 : 7 : return 0;
3379 : : }
3380 : :
3381 : : static inline int
3382 : : eth_dev_get_xstats_basic_count(struct rte_eth_dev *dev)
3383 : : {
3384 : : uint16_t nb_rxqs, nb_txqs;
3385 : : int count;
3386 : :
3387 : 3 : nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3388 : 3 : nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3389 : :
3390 : : count = RTE_NB_STATS;
3391 [ + - ]: 1 : if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) {
3392 : 3 : count += nb_rxqs * RTE_NB_RXQ_STATS;
3393 : 3 : count += nb_txqs * RTE_NB_TXQ_STATS;
3394 : : }
3395 : :
3396 : : return count;
3397 : : }
3398 : :
3399 : : static int
3400 : 1 : eth_dev_get_xstats_count(uint16_t port_id)
3401 : : {
3402 : : struct rte_eth_dev *dev;
3403 : : int count;
3404 : :
3405 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3406 : 1 : dev = &rte_eth_devices[port_id];
3407 [ - + ]: 1 : if (dev->dev_ops->xstats_get_names != NULL) {
3408 : 0 : count = dev->dev_ops->xstats_get_names(dev, NULL, 0);
3409 [ # # ]: 0 : if (count < 0)
3410 : 0 : return eth_err(port_id, count);
3411 : : } else
3412 : : count = 0;
3413 : :
3414 : :
3415 : 1 : count += eth_dev_get_xstats_basic_count(dev);
3416 : :
3417 : 1 : return count;
3418 : : }
3419 : :
3420 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_id_by_name)
3421 : : int
3422 : 0 : rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
3423 : : uint64_t *id)
3424 : : {
3425 : : int cnt_xstats, idx_xstat, rc;
3426 : : struct rte_eth_xstat_name *xstats_names;
3427 : :
3428 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3429 : :
3430 [ # # ]: 0 : if (xstat_name == NULL) {
3431 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
3432 : : "Cannot get ethdev port %u xstats ID from NULL xstat name",
3433 : : port_id);
3434 : 0 : return -ENOMEM;
3435 : : }
3436 : :
3437 [ # # ]: 0 : if (id == NULL) {
3438 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
3439 : : "Cannot get ethdev port %u xstats ID to NULL",
3440 : : port_id);
3441 : 0 : return -ENOMEM;
3442 : : }
3443 : :
3444 : : /* Get count */
3445 : 0 : cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
3446 [ # # ]: 0 : if (cnt_xstats < 0) {
3447 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get count of xstats");
3448 : 0 : return -ENODEV;
3449 : : }
3450 : :
3451 : : /* Get id-name lookup table */
3452 : 0 : xstats_names = calloc(cnt_xstats, sizeof(xstats_names[0]));
3453 [ # # ]: 0 : if (xstats_names == NULL) {
3454 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3455 : 0 : return -ENOMEM;
3456 : : }
3457 : :
3458 [ # # ]: 0 : if (cnt_xstats != rte_eth_xstats_get_names_by_id(
3459 : : port_id, xstats_names, cnt_xstats, NULL)) {
3460 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get xstats lookup");
3461 : 0 : free(xstats_names);
3462 : 0 : return -1;
3463 : : }
3464 : :
3465 : : rc = -EINVAL;
3466 [ # # ]: 0 : for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
3467 [ # # ]: 0 : if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
3468 [ # # ]: 0 : *id = idx_xstat;
3469 : :
3470 : 0 : rte_eth_trace_xstats_get_id_by_name(port_id,
3471 : : xstat_name, *id);
3472 : : rc = 0;
3473 : 0 : break;
3474 : : };
3475 : : }
3476 : :
3477 : 0 : free(xstats_names);
3478 : 0 : return rc;
3479 : : }
3480 : :
3481 : : /* retrieve basic stats names */
3482 : : static int
3483 : 1 : eth_basic_stats_get_names(struct rte_eth_dev *dev,
3484 : : struct rte_eth_xstat_name *xstats_names)
3485 : : {
3486 : : int cnt_used_entries = 0;
3487 : : uint32_t idx, id_queue;
3488 : : uint16_t num_q;
3489 : :
3490 [ + + ]: 9 : for (idx = 0; idx < RTE_NB_STATS; idx++) {
3491 [ - + ]: 8 : if (strlcpy(xstats_names[cnt_used_entries].name, eth_dev_stats_strings[idx].name,
3492 : : sizeof(xstats_names[0].name)) >= sizeof(xstats_names[0].name))
3493 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "statistic name '%s' will be truncated",
3494 : : xstats_names[cnt_used_entries].name);
3495 : 8 : cnt_used_entries++;
3496 : : }
3497 : :
3498 [ + - ]: 1 : if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
3499 : : return cnt_used_entries;
3500 : :
3501 : 1 : num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3502 [ + + ]: 2 : for (id_queue = 0; id_queue < num_q; id_queue++) {
3503 [ + + ]: 4 : for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
3504 : : unsigned int cc;
3505 : :
3506 : 3 : cc = snprintf(xstats_names[cnt_used_entries].name,
3507 : : sizeof(xstats_names[0].name), "rx_q%u_%s", id_queue,
3508 [ - + ]: 3 : eth_dev_rxq_stats_strings[idx].name);
3509 : :
3510 : : /* could only happen if a long string was added */
3511 [ - + ]: 3 : if (cc >= sizeof(xstats_names[0].name))
3512 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "truncated rxq stat string '%s'",
3513 : : eth_dev_rxq_stats_strings[idx].name);
3514 : 3 : cnt_used_entries++;
3515 : : }
3516 : :
3517 : : }
3518 : 1 : num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3519 [ + + ]: 2 : for (id_queue = 0; id_queue < num_q; id_queue++) {
3520 [ + + ]: 3 : for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
3521 : : unsigned int cc;
3522 : :
3523 : 2 : cc = snprintf(xstats_names[cnt_used_entries].name,
3524 : : sizeof(xstats_names[0].name), "tx_q%u_%s", id_queue,
3525 [ - + ]: 2 : eth_dev_txq_stats_strings[idx].name);
3526 [ - + ]: 2 : if (cc >= sizeof(xstats_names[0].name))
3527 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "truncated txq stat string '%s'",
3528 : : eth_dev_txq_stats_strings[idx].name);
3529 : 2 : cnt_used_entries++;
3530 : : }
3531 : : }
3532 : : return cnt_used_entries;
3533 : : }
3534 : :
3535 : : static int
3536 : 0 : eth_xstats_get_by_name_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3537 : : struct rte_eth_xstat_name *xstats_names, uint32_t size,
3538 : : uint32_t basic_count)
3539 : : {
3540 : : int32_t rc;
3541 : : uint32_t i, k, m, n;
3542 : : uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
3543 : :
3544 : : m = 0;
3545 [ # # ]: 0 : for (n = 0; n != size; n += k) {
3546 : :
3547 : 0 : k = RTE_MIN(size - n, RTE_DIM(ids_copy));
3548 : :
3549 : : /*
3550 : : * Convert ids to xstats ids that PMD knows.
3551 : : * ids known by user are basic + extended stats.
3552 : : */
3553 [ # # ]: 0 : for (i = 0; i < k; i++)
3554 : 0 : ids_copy[i] = ids[n + i] - basic_count;
3555 : :
3556 : 0 : rc = dev->dev_ops->xstats_get_names_by_id(dev, ids_copy, xstats_names + m, k);
3557 [ # # ]: 0 : if (rc < 0)
3558 : 0 : return rc;
3559 : 0 : m += rc;
3560 : : }
3561 : :
3562 : 0 : return m;
3563 : : }
3564 : :
3565 : :
3566 : : /* retrieve ethdev extended statistics names */
3567 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names_by_id)
3568 : : int
3569 : 0 : rte_eth_xstats_get_names_by_id(uint16_t port_id,
3570 : : struct rte_eth_xstat_name *xstats_names, unsigned int size,
3571 : : uint64_t *ids)
3572 : : {
3573 : : struct rte_eth_xstat_name *xstats_names_copy;
3574 : : unsigned int expected_entries;
3575 : : unsigned int nb_basic_stats;
3576 : : unsigned int basic_count;
3577 : : struct rte_eth_dev *dev;
3578 : : unsigned int i;
3579 : : int ret;
3580 : :
3581 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3582 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3583 : :
3584 : 0 : basic_count = eth_dev_get_xstats_basic_count(dev);
3585 : 0 : ret = eth_dev_get_xstats_count(port_id);
3586 [ # # ]: 0 : if (ret < 0)
3587 : : return ret;
3588 : 0 : expected_entries = (unsigned int)ret;
3589 : :
3590 : : /* Return max number of stats if no ids given */
3591 [ # # ]: 0 : if (!ids) {
3592 [ # # ]: 0 : if (!xstats_names)
3593 : : return expected_entries;
3594 [ # # ]: 0 : else if (xstats_names && size < expected_entries)
3595 : : return expected_entries;
3596 : : }
3597 : :
3598 [ # # ]: 0 : if (ids && !xstats_names)
3599 : : return -EINVAL;
3600 : :
3601 : : nb_basic_stats = 0;
3602 [ # # ]: 0 : if (ids != NULL) {
3603 [ # # ]: 0 : for (i = 0; i < size; i++)
3604 : 0 : nb_basic_stats += (ids[i] < basic_count);
3605 : : }
3606 : :
3607 : : /* no basic stats requested, devops function provided */
3608 [ # # # # ]: 0 : if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
3609 [ # # ]: 0 : dev->dev_ops->xstats_get_names_by_id != NULL)
3610 : 0 : return eth_xstats_get_by_name_by_id(dev, ids, xstats_names,
3611 : : size, basic_count);
3612 : :
3613 : : /* Retrieve all stats */
3614 [ # # ]: 0 : if (!ids) {
3615 : 0 : int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
3616 : : expected_entries);
3617 [ # # ]: 0 : if (num_stats < 0 || num_stats > (int)expected_entries)
3618 : : return num_stats;
3619 : : else
3620 : 0 : return expected_entries;
3621 : : }
3622 : :
3623 : 0 : xstats_names_copy = calloc(expected_entries,
3624 : : sizeof(struct rte_eth_xstat_name));
3625 : :
3626 [ # # ]: 0 : if (!xstats_names_copy) {
3627 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3628 : 0 : return -ENOMEM;
3629 : : }
3630 : :
3631 : : /* Fill xstats_names_copy structure */
3632 [ # # ]: 0 : if (ids && nb_basic_stats == size) {
3633 : 0 : eth_basic_stats_get_names(dev, xstats_names_copy);
3634 : : } else {
3635 : 0 : ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
3636 : : expected_entries);
3637 [ # # ]: 0 : if (ret < 0) {
3638 : 0 : free(xstats_names_copy);
3639 : 0 : return ret;
3640 : : }
3641 : : }
3642 : :
3643 : : /* Filter stats */
3644 [ # # ]: 0 : for (i = 0; i < size; i++) {
3645 [ # # ]: 0 : if (ids[i] >= expected_entries) {
3646 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
3647 : 0 : free(xstats_names_copy);
3648 : 0 : return -1;
3649 : : }
3650 [ # # ]: 0 : xstats_names[i] = xstats_names_copy[ids[i]];
3651 : :
3652 : 0 : rte_eth_trace_xstats_get_names_by_id(port_id, &xstats_names[i],
3653 : : ids[i]);
3654 : : }
3655 : :
3656 : 0 : free(xstats_names_copy);
3657 : 0 : return size;
3658 : : }
3659 : :
3660 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names)
3661 : : int
3662 : 1 : rte_eth_xstats_get_names(uint16_t port_id,
3663 : : struct rte_eth_xstat_name *xstats_names,
3664 : : unsigned int size)
3665 : : {
3666 : : struct rte_eth_dev *dev;
3667 : : int cnt_used_entries;
3668 : : int cnt_expected_entries;
3669 : : int cnt_driver_entries;
3670 : : int i;
3671 : :
3672 : 1 : cnt_expected_entries = eth_dev_get_xstats_count(port_id);
3673 [ + - ]: 1 : if (xstats_names == NULL || cnt_expected_entries < 0 ||
3674 [ + - ]: 1 : (int)size < cnt_expected_entries)
3675 : : return cnt_expected_entries;
3676 : :
3677 : : /* port_id checked in eth_dev_get_xstats_count() */
3678 : 1 : dev = &rte_eth_devices[port_id];
3679 : :
3680 : 1 : cnt_used_entries = eth_basic_stats_get_names(dev, xstats_names);
3681 : :
3682 [ - + ]: 1 : if (dev->dev_ops->xstats_get_names != NULL) {
3683 : : /* If there are any driver-specific xstats, append them
3684 : : * to end of list.
3685 : : */
3686 : 0 : cnt_driver_entries = dev->dev_ops->xstats_get_names(
3687 : : dev,
3688 : 0 : xstats_names + cnt_used_entries,
3689 : : size - cnt_used_entries);
3690 [ # # ]: 0 : if (cnt_driver_entries < 0)
3691 : 0 : return eth_err(port_id, cnt_driver_entries);
3692 : 0 : cnt_used_entries += cnt_driver_entries;
3693 : : }
3694 : :
3695 [ + + ]: 14 : for (i = 0; i < cnt_used_entries; i++)
3696 [ - + ]: 13 : rte_eth_trace_xstats_get_names(port_id, i, &xstats_names[i],
3697 : : size, cnt_used_entries);
3698 : :
3699 : : return cnt_used_entries;
3700 : : }
3701 : :
3702 : :
3703 : : static int
3704 : 1 : eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
3705 : : {
3706 : : struct rte_eth_dev *dev;
3707 : : struct rte_eth_stats eth_stats;
3708 : : struct eth_queue_stats queue_stats;
3709 : : unsigned int count = 0, i, q;
3710 : : uint64_t val, *stats_ptr;
3711 : : uint16_t nb_rxqs, nb_txqs;
3712 : : int ret;
3713 : :
3714 : 1 : ret = eth_stats_qstats_get(port_id, ð_stats, &queue_stats);
3715 [ + - ]: 1 : if (ret < 0)
3716 : : return ret;
3717 : :
3718 : : dev = &rte_eth_devices[port_id];
3719 : :
3720 : 1 : nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3721 : 1 : nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3722 : :
3723 : : /* global stats */
3724 [ + + ]: 9 : for (i = 0; i < RTE_NB_STATS; i++) {
3725 : 8 : stats_ptr = RTE_PTR_ADD(ð_stats,
3726 : : eth_dev_stats_strings[i].offset);
3727 : 8 : val = *stats_ptr;
3728 : 8 : xstats[count++].value = val;
3729 : : }
3730 : :
3731 [ + - ]: 1 : if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
3732 : : return count;
3733 : :
3734 : : /* per-rxq stats */
3735 [ + + ]: 2 : for (q = 0; q < nb_rxqs; q++) {
3736 [ + + ]: 4 : for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
3737 : 3 : stats_ptr = RTE_PTR_ADD(&queue_stats,
3738 : : eth_dev_rxq_stats_strings[i].offset +
3739 : : q * sizeof(uint64_t));
3740 : 3 : val = *stats_ptr;
3741 : 3 : xstats[count++].value = val;
3742 : : }
3743 : : }
3744 : :
3745 : : /* per-txq stats */
3746 [ + + ]: 2 : for (q = 0; q < nb_txqs; q++) {
3747 [ + + ]: 3 : for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
3748 : 2 : stats_ptr = RTE_PTR_ADD(&queue_stats,
3749 : : eth_dev_txq_stats_strings[i].offset +
3750 : : q * sizeof(uint64_t));
3751 : 2 : val = *stats_ptr;
3752 : 2 : xstats[count++].value = val;
3753 : : }
3754 : : }
3755 : 1 : return count;
3756 : : }
3757 : :
3758 : : static int
3759 : 0 : eth_xtats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3760 : : uint64_t *values, uint32_t size, uint32_t basic_count)
3761 : : {
3762 : : int32_t rc;
3763 : : uint32_t i, k, m, n;
3764 : : uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
3765 : :
3766 : : m = 0;
3767 [ # # ]: 0 : for (n = 0; n != size; n += k) {
3768 : :
3769 : 0 : k = RTE_MIN(size - n, RTE_DIM(ids_copy));
3770 : :
3771 : : /*
3772 : : * Convert ids to xstats ids that PMD knows.
3773 : : * ids known by user are basic + extended stats.
3774 : : */
3775 [ # # ]: 0 : for (i = 0; i < k; i++)
3776 : 0 : ids_copy[i] = ids[n + i] - basic_count;
3777 : :
3778 : 0 : rc = dev->dev_ops->xstats_get_by_id(dev, ids_copy, values + m, k);
3779 [ # # ]: 0 : if (rc < 0)
3780 : 0 : return rc;
3781 : 0 : m += rc;
3782 : : }
3783 : :
3784 : 0 : return m;
3785 : : }
3786 : :
3787 : : /* retrieve ethdev extended statistics */
3788 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_by_id)
3789 : : int
3790 : 0 : rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
3791 : : uint64_t *values, unsigned int size)
3792 : : {
3793 : : unsigned int nb_basic_stats;
3794 : : unsigned int num_xstats_filled;
3795 : : unsigned int basic_count;
3796 : : uint16_t expected_entries;
3797 : : struct rte_eth_dev *dev;
3798 : : struct rte_eth_xstat *xstats;
3799 : : unsigned int i;
3800 : : int ret;
3801 : :
3802 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3803 : 0 : dev = &rte_eth_devices[port_id];
3804 : :
3805 : 0 : ret = eth_dev_get_xstats_count(port_id);
3806 [ # # ]: 0 : if (ret < 0)
3807 : : return ret;
3808 [ # # ]: 0 : expected_entries = (uint16_t)ret;
3809 : 0 : basic_count = eth_dev_get_xstats_basic_count(dev);
3810 : :
3811 : : /* Return max number of stats if no ids given */
3812 [ # # ]: 0 : if (!ids) {
3813 [ # # ]: 0 : if (!values)
3814 : 0 : return expected_entries;
3815 [ # # ]: 0 : else if (values && size < expected_entries)
3816 : : return expected_entries;
3817 : : }
3818 : :
3819 [ # # ]: 0 : if (ids && !values)
3820 : : return -EINVAL;
3821 : :
3822 : : nb_basic_stats = 0;
3823 [ # # ]: 0 : if (ids != NULL) {
3824 [ # # ]: 0 : for (i = 0; i < size; i++)
3825 : 0 : nb_basic_stats += (ids[i] < basic_count);
3826 : : }
3827 : :
3828 : : /* no basic stats requested, devops function provided */
3829 [ # # # # ]: 0 : if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
3830 [ # # ]: 0 : dev->dev_ops->xstats_get_by_id != NULL)
3831 : 0 : return eth_xtats_get_by_id(dev, ids, values, size, basic_count);
3832 : :
3833 : 0 : xstats = calloc(expected_entries, sizeof(xstats[0]));
3834 [ # # ]: 0 : if (xstats == NULL) {
3835 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3836 : 0 : return -ENOMEM;
3837 : : }
3838 : :
3839 : : /* Fill the xstats structure */
3840 [ # # ]: 0 : if (ids && nb_basic_stats == size)
3841 : 0 : ret = eth_basic_stats_get(port_id, xstats);
3842 : : else
3843 : 0 : ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
3844 : :
3845 [ # # ]: 0 : if (ret < 0) {
3846 : 0 : free(xstats);
3847 : 0 : return ret;
3848 : : }
3849 : 0 : num_xstats_filled = (unsigned int)ret;
3850 : :
3851 : : /* Return all stats */
3852 [ # # ]: 0 : if (!ids) {
3853 [ # # ]: 0 : for (i = 0; i < num_xstats_filled; i++)
3854 : 0 : values[i] = xstats[i].value;
3855 : :
3856 : 0 : free(xstats);
3857 : 0 : return expected_entries;
3858 : : }
3859 : :
3860 : : /* Filter stats */
3861 [ # # ]: 0 : for (i = 0; i < size; i++) {
3862 [ # # ]: 0 : if (ids[i] >= expected_entries) {
3863 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
3864 : 0 : break;
3865 : : }
3866 : 0 : values[i] = xstats[ids[i]].value;
3867 : : }
3868 : :
3869 : 0 : rte_eth_trace_xstats_get_by_id(port_id, ids, values, size);
3870 : :
3871 : 0 : free(xstats);
3872 [ # # ]: 0 : return (i == size) ? (int32_t)size : -1;
3873 : : }
3874 : :
3875 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get)
3876 : : int
3877 : 2 : rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
3878 : : unsigned int n)
3879 : : {
3880 : : struct rte_eth_dev *dev;
3881 : : unsigned int count, i;
3882 : : signed int xcount = 0;
3883 : : int ret;
3884 : :
3885 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3886 [ + - ]: 2 : if (xstats == NULL && n > 0)
3887 : : return -EINVAL;
3888 [ + - ]: 2 : dev = &rte_eth_devices[port_id];
3889 : :
3890 : 2 : count = eth_dev_get_xstats_basic_count(dev);
3891 : :
3892 : : /* implemented by the driver */
3893 [ - + ]: 2 : if (dev->dev_ops->xstats_get != NULL) {
3894 : : /* Retrieve the xstats from the driver at the end of the
3895 : : * xstats struct.
3896 : : */
3897 [ # # # # ]: 0 : xcount = dev->dev_ops->xstats_get(dev,
3898 : 0 : (n > count) ? xstats + count : NULL,
3899 : : (n > count) ? n - count : 0);
3900 : :
3901 [ # # ]: 0 : if (xcount < 0)
3902 : 0 : return eth_err(port_id, xcount);
3903 : : }
3904 : :
3905 [ + + - + ]: 2 : if (n < count + xcount || xstats == NULL)
3906 : 1 : return count + xcount;
3907 : :
3908 : : /* now fill the xstats structure */
3909 : 1 : ret = eth_basic_stats_get(port_id, xstats);
3910 [ + - ]: 1 : if (ret < 0)
3911 : : return ret;
3912 : 1 : count = ret;
3913 : :
3914 [ + + ]: 14 : for (i = 0; i < count; i++)
3915 : 13 : xstats[i].id = i;
3916 : : /* add an offset to driver-specific stats */
3917 [ - + ]: 1 : for ( ; i < count + xcount; i++)
3918 : 0 : xstats[i].id += count;
3919 : :
3920 [ + + ]: 14 : for (i = 0; i < n; i++)
3921 [ - + ]: 13 : rte_eth_trace_xstats_get(port_id, xstats[i]);
3922 : :
3923 : 1 : return count + xcount;
3924 : : }
3925 : :
3926 : : /* reset ethdev extended statistics */
3927 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_reset)
3928 : : int
3929 : 0 : rte_eth_xstats_reset(uint16_t port_id)
3930 : : {
3931 : : struct rte_eth_dev *dev;
3932 : :
3933 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3934 : 0 : dev = &rte_eth_devices[port_id];
3935 : :
3936 : : /* implemented by the driver */
3937 [ # # ]: 0 : if (dev->dev_ops->xstats_reset != NULL) {
3938 : 0 : int ret = eth_err(port_id, dev->dev_ops->xstats_reset(dev));
3939 : :
3940 : 0 : rte_eth_trace_xstats_reset(port_id, ret);
3941 : :
3942 : 0 : return ret;
3943 : : }
3944 : :
3945 : : /* fallback to default */
3946 : 0 : return rte_eth_stats_reset(port_id);
3947 : : }
3948 : :
3949 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_set_counter, 25.03)
3950 : : int
3951 : 0 : rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off)
3952 : : {
3953 : : struct rte_eth_dev *dev;
3954 : : unsigned int basic_count;
3955 : :
3956 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3957 : :
3958 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3959 : : basic_count = eth_dev_get_xstats_basic_count(dev);
3960 [ # # ]: 0 : if (id < basic_count)
3961 : : return -EINVAL;
3962 : :
3963 [ # # ]: 0 : if (on_off == 1) {
3964 [ # # ]: 0 : if (rte_eth_xstats_query_state(port_id, id) == 1)
3965 : : return -EEXIST;
3966 [ # # ]: 0 : if (dev->dev_ops->xstats_enable != NULL)
3967 : 0 : return dev->dev_ops->xstats_enable(dev, id - basic_count);
3968 : : } else {
3969 [ # # ]: 0 : if (rte_eth_xstats_query_state(port_id, id) == 0)
3970 : : return 0;
3971 [ # # ]: 0 : if (dev->dev_ops->xstats_disable != NULL)
3972 : 0 : return dev->dev_ops->xstats_disable(dev, id - basic_count);
3973 : : }
3974 : :
3975 : : return -ENOTSUP;
3976 : : }
3977 : :
3978 : :
3979 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_query_state, 25.03)
3980 : : int
3981 : 0 : rte_eth_xstats_query_state(uint16_t port_id, uint64_t id)
3982 : : {
3983 : : struct rte_eth_dev *dev;
3984 : : unsigned int basic_count;
3985 : :
3986 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3987 : :
3988 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3989 : : basic_count = eth_dev_get_xstats_basic_count(dev);
3990 [ # # ]: 0 : if (id < basic_count)
3991 : : return -ENOTSUP;
3992 : :
3993 : : /* implemented by the driver */
3994 [ # # ]: 0 : if (dev->dev_ops->xstats_query_state != NULL)
3995 : 0 : return dev->dev_ops->xstats_query_state(dev, id - basic_count);
3996 : :
3997 : : return -ENOTSUP;
3998 : : }
3999 : :
4000 : : static int
4001 : 0 : eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id,
4002 : : uint8_t stat_idx, uint8_t is_rx)
4003 : : {
4004 : : struct rte_eth_dev *dev;
4005 : :
4006 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4007 : 0 : dev = &rte_eth_devices[port_id];
4008 : :
4009 [ # # # # ]: 0 : if (is_rx && (queue_id >= dev->data->nb_rx_queues))
4010 : : return -EINVAL;
4011 : :
4012 [ # # # # ]: 0 : if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
4013 : : return -EINVAL;
4014 : :
4015 [ # # ]: 0 : if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
4016 : : return -EINVAL;
4017 : :
4018 [ # # ]: 0 : if (dev->dev_ops->queue_stats_mapping_set == NULL)
4019 : : return -ENOTSUP;
4020 : 0 : return dev->dev_ops->queue_stats_mapping_set(dev, queue_id, stat_idx, is_rx);
4021 : : }
4022 : :
4023 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_tx_queue_stats_mapping)
4024 : : int
4025 : 0 : rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
4026 : : uint8_t stat_idx)
4027 : : {
4028 : : int ret;
4029 : :
4030 : 0 : ret = eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id,
4031 : : tx_queue_id,
4032 : : stat_idx, STAT_QMAP_TX));
4033 : :
4034 : 0 : rte_ethdev_trace_set_tx_queue_stats_mapping(port_id, tx_queue_id,
4035 : : stat_idx, ret);
4036 : :
4037 : 0 : return ret;
4038 : : }
4039 : :
4040 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_rx_queue_stats_mapping)
4041 : : int
4042 : 0 : rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
4043 : : uint8_t stat_idx)
4044 : : {
4045 : : int ret;
4046 : :
4047 : 0 : ret = eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id,
4048 : : rx_queue_id,
4049 : : stat_idx, STAT_QMAP_RX));
4050 : :
4051 : 0 : rte_ethdev_trace_set_rx_queue_stats_mapping(port_id, rx_queue_id,
4052 : : stat_idx, ret);
4053 : :
4054 : 0 : return ret;
4055 : : }
4056 : :
4057 : : RTE_EXPORT_SYMBOL(rte_eth_dev_fw_version_get)
4058 : : int
4059 : 1 : rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
4060 : : {
4061 : : struct rte_eth_dev *dev;
4062 : : int ret;
4063 : :
4064 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4065 : 1 : dev = &rte_eth_devices[port_id];
4066 : :
4067 [ - + ]: 1 : if (fw_version == NULL && fw_size > 0) {
4068 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4069 : : "Cannot get ethdev port %u FW version to NULL when string size is non zero",
4070 : : port_id);
4071 : 0 : return -EINVAL;
4072 : : }
4073 : :
4074 [ - + ]: 1 : if (dev->dev_ops->fw_version_get == NULL)
4075 : : return -ENOTSUP;
4076 : 0 : ret = eth_err(port_id, dev->dev_ops->fw_version_get(dev, fw_version, fw_size));
4077 : :
4078 : 0 : rte_ethdev_trace_fw_version_get(port_id, fw_version, fw_size, ret);
4079 : :
4080 : 0 : return ret;
4081 : : }
4082 : :
4083 : : RTE_EXPORT_SYMBOL(rte_eth_dev_info_get)
4084 : : int
4085 : 149 : rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
4086 : : {
4087 : : struct rte_eth_dev *dev;
4088 : : const struct rte_eth_desc_lim lim = {
4089 : : .nb_max = UINT16_MAX,
4090 : : .nb_min = 0,
4091 : : .nb_align = 1,
4092 : : .nb_seg_max = UINT16_MAX,
4093 : : .nb_mtu_seg_max = UINT16_MAX,
4094 : : };
4095 : : int diag;
4096 : :
4097 [ - + ]: 149 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4098 : 149 : dev = &rte_eth_devices[port_id];
4099 : :
4100 [ - + ]: 149 : if (dev_info == NULL) {
4101 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u info to NULL",
4102 : : port_id);
4103 : 0 : return -EINVAL;
4104 : : }
4105 : :
4106 : : /*
4107 : : * Init dev_info before port_id check since caller does not have
4108 : : * return status and does not know if get is successful or not.
4109 : : */
4110 : : memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
4111 : 149 : dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
4112 : :
4113 : 149 : dev_info->rx_desc_lim = lim;
4114 : 149 : dev_info->tx_desc_lim = lim;
4115 : 149 : dev_info->device = dev->device;
4116 : 149 : dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN -
4117 : : RTE_ETHER_CRC_LEN;
4118 : 149 : dev_info->max_mtu = UINT16_MAX;
4119 : 149 : dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT);
4120 : 149 : dev_info->max_rx_bufsize = UINT32_MAX;
4121 : :
4122 [ + - ]: 149 : if (dev->dev_ops->dev_infos_get == NULL)
4123 : : return -ENOTSUP;
4124 : 149 : diag = dev->dev_ops->dev_infos_get(dev, dev_info);
4125 [ - + ]: 149 : if (diag != 0) {
4126 : : /* Cleanup already filled in device information */
4127 : : memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
4128 : 0 : return eth_err(port_id, diag);
4129 : : }
4130 : :
4131 : : /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */
4132 : 149 : dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues,
4133 : : RTE_MAX_QUEUES_PER_PORT);
4134 : 149 : dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues,
4135 : : RTE_MAX_QUEUES_PER_PORT);
4136 : :
4137 : 149 : dev_info->driver_name = dev->device->driver->name;
4138 : 149 : dev_info->nb_rx_queues = dev->data->nb_rx_queues;
4139 : 149 : dev_info->nb_tx_queues = dev->data->nb_tx_queues;
4140 : :
4141 [ - + ]: 149 : dev_info->dev_flags = &dev->data->dev_flags;
4142 : :
4143 : 149 : rte_ethdev_trace_info_get(port_id, dev_info);
4144 : :
4145 : 149 : return 0;
4146 : : }
4147 : :
4148 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_conf_get, 21.11)
4149 : : int
4150 : 1 : rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf)
4151 : : {
4152 : : struct rte_eth_dev *dev;
4153 : :
4154 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4155 : : dev = &rte_eth_devices[port_id];
4156 : :
4157 [ - + ]: 1 : if (dev_conf == NULL) {
4158 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4159 : : "Cannot get ethdev port %u configuration to NULL",
4160 : : port_id);
4161 : 0 : return -EINVAL;
4162 : : }
4163 : :
4164 [ - + ]: 1 : memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf));
4165 : :
4166 : 1 : rte_ethdev_trace_conf_get(port_id, dev_conf);
4167 : :
4168 : 1 : return 0;
4169 : : }
4170 : :
4171 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_supported_ptypes)
4172 : : int
4173 : 0 : rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
4174 : : uint32_t *ptypes, int num)
4175 : : {
4176 : : size_t i;
4177 : : int j;
4178 : : struct rte_eth_dev *dev;
4179 : : const uint32_t *all_ptypes;
4180 : 0 : size_t no_of_elements = 0;
4181 : :
4182 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4183 : 0 : dev = &rte_eth_devices[port_id];
4184 : :
4185 [ # # ]: 0 : if (ptypes == NULL && num > 0) {
4186 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4187 : : "Cannot get ethdev port %u supported packet types to NULL when array size is non zero",
4188 : : port_id);
4189 : 0 : return -EINVAL;
4190 : : }
4191 : :
4192 [ # # ]: 0 : if (dev->dev_ops->dev_supported_ptypes_get == NULL)
4193 : : return 0;
4194 : 0 : all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
4195 : :
4196 [ # # ]: 0 : if (!all_ptypes)
4197 : : return 0;
4198 : :
4199 [ # # ]: 0 : for (i = 0, j = 0; i < no_of_elements; ++i)
4200 [ # # ]: 0 : if (all_ptypes[i] & ptype_mask) {
4201 [ # # ]: 0 : if (j < num) {
4202 [ # # ]: 0 : ptypes[j] = all_ptypes[i];
4203 : :
4204 : 0 : rte_ethdev_trace_get_supported_ptypes(port_id,
4205 : : j, num, ptypes[j]);
4206 : : }
4207 : 0 : j++;
4208 : : }
4209 : :
4210 : : return j;
4211 : : }
4212 : :
4213 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_ptypes)
4214 : : int
4215 : 0 : rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
4216 : : uint32_t *set_ptypes, unsigned int num)
4217 : : {
4218 : 0 : const uint32_t valid_ptype_masks[] = {
4219 : : RTE_PTYPE_L2_MASK,
4220 : : RTE_PTYPE_L3_MASK,
4221 : : RTE_PTYPE_L4_MASK,
4222 : : RTE_PTYPE_TUNNEL_MASK,
4223 : : RTE_PTYPE_INNER_L2_MASK,
4224 : : RTE_PTYPE_INNER_L3_MASK,
4225 : : RTE_PTYPE_INNER_L4_MASK,
4226 : : };
4227 : : const uint32_t *all_ptypes;
4228 : : struct rte_eth_dev *dev;
4229 : : uint32_t unused_mask;
4230 : : size_t i;
4231 : : unsigned int j;
4232 : : int ret;
4233 : 0 : size_t no_of_elements = 0;
4234 : :
4235 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4236 : 0 : dev = &rte_eth_devices[port_id];
4237 : :
4238 [ # # ]: 0 : if (num > 0 && set_ptypes == NULL) {
4239 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4240 : : "Cannot get ethdev port %u set packet types to NULL when array size is non zero",
4241 : : port_id);
4242 : 0 : return -EINVAL;
4243 : : }
4244 : :
4245 [ # # ]: 0 : if (dev->dev_ops->dev_supported_ptypes_get == NULL ||
4246 [ # # ]: 0 : dev->dev_ops->dev_ptypes_set == NULL) {
4247 : : ret = 0;
4248 : 0 : goto ptype_unknown;
4249 : : }
4250 : :
4251 [ # # ]: 0 : if (ptype_mask == 0) {
4252 : 0 : ret = dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
4253 : 0 : goto ptype_unknown;
4254 : : }
4255 : :
4256 : : unused_mask = ptype_mask;
4257 [ # # ]: 0 : for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) {
4258 : 0 : uint32_t mask = ptype_mask & valid_ptype_masks[i];
4259 [ # # # # ]: 0 : if (mask && mask != valid_ptype_masks[i]) {
4260 : : ret = -EINVAL;
4261 : 0 : goto ptype_unknown;
4262 : : }
4263 : 0 : unused_mask &= ~valid_ptype_masks[i];
4264 : : }
4265 : :
4266 [ # # ]: 0 : if (unused_mask) {
4267 : : ret = -EINVAL;
4268 : 0 : goto ptype_unknown;
4269 : : }
4270 : :
4271 : 0 : all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
4272 [ # # ]: 0 : if (all_ptypes == NULL) {
4273 : : ret = 0;
4274 : 0 : goto ptype_unknown;
4275 : : }
4276 : :
4277 : : /*
4278 : : * Accommodate as many set_ptypes as possible. If the supplied
4279 : : * set_ptypes array is insufficient fill it partially.
4280 : : */
4281 [ # # ]: 0 : for (i = 0, j = 0; set_ptypes != NULL &&
4282 [ # # ]: 0 : (i < no_of_elements); ++i) {
4283 [ # # ]: 0 : if (ptype_mask & all_ptypes[i]) {
4284 [ # # ]: 0 : if (j < num - 1) {
4285 : 0 : set_ptypes[j] = all_ptypes[i];
4286 : :
4287 [ # # ]: 0 : rte_ethdev_trace_set_ptypes(port_id, j, num,
4288 : : set_ptypes[j]);
4289 : :
4290 : 0 : j++;
4291 : 0 : continue;
4292 : : }
4293 : : break;
4294 : : }
4295 : : }
4296 : :
4297 [ # # ]: 0 : if (set_ptypes != NULL && j < num)
4298 : 0 : set_ptypes[j] = RTE_PTYPE_UNKNOWN;
4299 : :
4300 : 0 : return dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
4301 : :
4302 : 0 : ptype_unknown:
4303 [ # # ]: 0 : if (num > 0)
4304 : 0 : set_ptypes[0] = RTE_PTYPE_UNKNOWN;
4305 : :
4306 : : return ret;
4307 : : }
4308 : :
4309 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_macaddrs_get, 21.11)
4310 : : int
4311 : 0 : rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma,
4312 : : unsigned int num)
4313 : : {
4314 : : int32_t ret;
4315 : : struct rte_eth_dev *dev;
4316 : : struct rte_eth_dev_info dev_info;
4317 : :
4318 [ # # ]: 0 : if (ma == NULL) {
4319 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "%s: invalid parameters", __func__);
4320 : 0 : return -EINVAL;
4321 : : }
4322 : :
4323 : : /* will check for us that port_id is a valid one */
4324 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4325 [ # # ]: 0 : if (ret != 0)
4326 : : return ret;
4327 : :
4328 : : dev = &rte_eth_devices[port_id];
4329 : 0 : num = RTE_MIN(dev_info.max_mac_addrs, num);
4330 [ # # ]: 0 : memcpy(ma, dev->data->mac_addrs, num * sizeof(ma[0]));
4331 : :
4332 : 0 : rte_eth_trace_macaddrs_get(port_id, num);
4333 : :
4334 : 0 : return num;
4335 : : }
4336 : :
4337 : : RTE_EXPORT_SYMBOL(rte_eth_macaddr_get)
4338 : : int
4339 : 10 : rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
4340 : : {
4341 : : struct rte_eth_dev *dev;
4342 : :
4343 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4344 : : dev = &rte_eth_devices[port_id];
4345 : :
4346 [ - + ]: 10 : if (mac_addr == NULL) {
4347 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4348 : : "Cannot get ethdev port %u MAC address to NULL",
4349 : : port_id);
4350 : 0 : return -EINVAL;
4351 : : }
4352 : :
4353 : 10 : rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
4354 : :
4355 : : rte_eth_trace_macaddr_get(port_id, mac_addr);
4356 : :
4357 : 10 : return 0;
4358 : : }
4359 : :
4360 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_mtu)
4361 : : int
4362 : 1 : rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
4363 : : {
4364 : : struct rte_eth_dev *dev;
4365 : :
4366 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4367 : : dev = &rte_eth_devices[port_id];
4368 : :
4369 [ - + ]: 1 : if (mtu == NULL) {
4370 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u MTU to NULL",
4371 : : port_id);
4372 : 0 : return -EINVAL;
4373 : : }
4374 : :
4375 : 1 : *mtu = dev->data->mtu;
4376 : :
4377 : : rte_ethdev_trace_get_mtu(port_id, *mtu);
4378 : :
4379 : 1 : return 0;
4380 : : }
4381 : :
4382 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mtu)
4383 : : int
4384 : 2 : rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
4385 : : {
4386 : : int ret;
4387 : : struct rte_eth_dev_info dev_info;
4388 : : struct rte_eth_dev *dev;
4389 : :
4390 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4391 : 2 : dev = &rte_eth_devices[port_id];
4392 [ + - ]: 2 : if (dev->dev_ops->mtu_set == NULL)
4393 : : return -ENOTSUP;
4394 : :
4395 : : /*
4396 : : * Check if the device supports dev_infos_get, if it does not
4397 : : * skip min_mtu/max_mtu validation here as this requires values
4398 : : * that are populated within the call to rte_eth_dev_info_get()
4399 : : * which relies on dev->dev_ops->dev_infos_get.
4400 : : */
4401 [ + - ]: 2 : if (dev->dev_ops->dev_infos_get != NULL) {
4402 : 2 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4403 [ + - ]: 2 : if (ret != 0)
4404 : : return ret;
4405 : :
4406 : 2 : ret = eth_dev_validate_mtu(port_id, &dev_info, mtu);
4407 [ + - ]: 2 : if (ret != 0)
4408 : : return ret;
4409 : : }
4410 : :
4411 [ - + ]: 2 : if (dev->data->dev_configured == 0) {
4412 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4413 : : "Port %u must be configured before MTU set",
4414 : : port_id);
4415 : 0 : return -EINVAL;
4416 : : }
4417 : :
4418 : 2 : ret = dev->dev_ops->mtu_set(dev, mtu);
4419 [ + - ]: 2 : if (ret == 0)
4420 : 2 : dev->data->mtu = mtu;
4421 : :
4422 : 2 : ret = eth_err(port_id, ret);
4423 : :
4424 : 2 : rte_ethdev_trace_set_mtu(port_id, mtu, ret);
4425 : :
4426 : 2 : return ret;
4427 : : }
4428 : :
4429 : : RTE_EXPORT_SYMBOL(rte_eth_dev_vlan_filter)
4430 : : int
4431 : 0 : rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
4432 : : {
4433 : : struct rte_eth_dev *dev;
4434 : : int ret;
4435 : :
4436 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4437 : 0 : dev = &rte_eth_devices[port_id];
4438 : :
4439 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.offloads &
4440 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
4441 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: VLAN-filtering disabled",
4442 : : port_id);
4443 : 0 : return -ENOSYS;
4444 : : }
4445 : :
4446 [ # # ]: 0 : if (vlan_id > 4095) {
4447 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port_id=%u invalid vlan_id=%u > 4095",
4448 : : port_id, vlan_id);
4449 : 0 : return -EINVAL;
4450 : : }
4451 [ # # ]: 0 : if (dev->dev_ops->vlan_filter_set == NULL)
4452 : : return -ENOTSUP;
4453 : :
4454 : 0 : ret = dev->dev_ops->vlan_filter_set(dev, vlan_id, on);
4455 [ # # ]: 0 : if (ret == 0) {
4456 : : struct rte_vlan_filter_conf *vfc;
4457 : : int vidx;
4458 : : int vbit;
4459 : :
4460 : 0 : vfc = &dev->data->vlan_filter_conf;
4461 : 0 : vidx = vlan_id / 64;
4462 : 0 : vbit = vlan_id % 64;
4463 : :
4464 [ # # ]: 0 : if (on)
4465 : 0 : vfc->ids[vidx] |= RTE_BIT64(vbit);
4466 : : else
4467 : 0 : vfc->ids[vidx] &= ~RTE_BIT64(vbit);
4468 : : }
4469 : :
4470 : 0 : ret = eth_err(port_id, ret);
4471 : :
4472 : 0 : rte_ethdev_trace_vlan_filter(port_id, vlan_id, on, ret);
4473 : :
4474 : 0 : return ret;
4475 : : }
4476 : :
4477 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_strip_on_queue)
4478 : : int
4479 : 0 : rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
4480 : : int on)
4481 : : {
4482 : : struct rte_eth_dev *dev;
4483 : :
4484 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4485 : 0 : dev = &rte_eth_devices[port_id];
4486 : :
4487 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues) {
4488 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid rx_queue_id=%u", rx_queue_id);
4489 : 0 : return -EINVAL;
4490 : : }
4491 : :
4492 [ # # ]: 0 : if (dev->dev_ops->vlan_strip_queue_set == NULL)
4493 : : return -ENOTSUP;
4494 : 0 : dev->dev_ops->vlan_strip_queue_set(dev, rx_queue_id, on);
4495 : :
4496 : 0 : rte_ethdev_trace_set_vlan_strip_on_queue(port_id, rx_queue_id, on);
4497 : :
4498 : 0 : return 0;
4499 : : }
4500 : :
4501 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_ether_type)
4502 : : int
4503 : 0 : rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
4504 : : enum rte_vlan_type vlan_type,
4505 : : uint16_t tpid)
4506 : : {
4507 : : struct rte_eth_dev *dev;
4508 : : int ret;
4509 : :
4510 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4511 : 0 : dev = &rte_eth_devices[port_id];
4512 : :
4513 [ # # ]: 0 : if (dev->dev_ops->vlan_tpid_set == NULL)
4514 : : return -ENOTSUP;
4515 : 0 : ret = eth_err(port_id, dev->dev_ops->vlan_tpid_set(dev, vlan_type, tpid));
4516 : :
4517 : 0 : rte_ethdev_trace_set_vlan_ether_type(port_id, vlan_type, tpid, ret);
4518 : :
4519 : 0 : return ret;
4520 : : }
4521 : :
4522 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_offload)
4523 : : int
4524 : 0 : rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
4525 : : {
4526 : : struct rte_eth_dev_info dev_info;
4527 : : struct rte_eth_dev *dev;
4528 : : int ret = 0;
4529 : : int mask = 0;
4530 : : int cur, org = 0;
4531 : : uint64_t orig_offloads;
4532 : : uint64_t dev_offloads;
4533 : : uint64_t new_offloads;
4534 : :
4535 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4536 : 0 : dev = &rte_eth_devices[port_id];
4537 : :
4538 : : /* save original values in case of failure */
4539 : 0 : orig_offloads = dev->data->dev_conf.rxmode.offloads;
4540 : : dev_offloads = orig_offloads;
4541 : :
4542 : : /* check which option changed by application */
4543 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_STRIP_OFFLOAD);
4544 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
4545 [ # # ]: 0 : if (cur != org) {
4546 [ # # ]: 0 : if (cur)
4547 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4548 : : else
4549 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4550 : : mask |= RTE_ETH_VLAN_STRIP_MASK;
4551 : : }
4552 : :
4553 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_FILTER_OFFLOAD);
4554 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER);
4555 [ # # ]: 0 : if (cur != org) {
4556 [ # # ]: 0 : if (cur)
4557 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4558 : : else
4559 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4560 : 0 : mask |= RTE_ETH_VLAN_FILTER_MASK;
4561 : : }
4562 : :
4563 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_EXTEND_OFFLOAD);
4564 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
4565 [ # # ]: 0 : if (cur != org) {
4566 [ # # ]: 0 : if (cur)
4567 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4568 : : else
4569 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4570 : 0 : mask |= RTE_ETH_VLAN_EXTEND_MASK;
4571 : : }
4572 : :
4573 : 0 : cur = !!(offload_mask & RTE_ETH_QINQ_STRIP_OFFLOAD);
4574 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP);
4575 [ # # ]: 0 : if (cur != org) {
4576 [ # # ]: 0 : if (cur)
4577 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4578 : : else
4579 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4580 : 0 : mask |= RTE_ETH_QINQ_STRIP_MASK;
4581 : : }
4582 : :
4583 : : /*no change*/
4584 [ # # ]: 0 : if (mask == 0)
4585 : : return ret;
4586 : :
4587 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4588 [ # # ]: 0 : if (ret != 0)
4589 : : return ret;
4590 : :
4591 : : /* Rx VLAN offloading must be within its device capabilities */
4592 [ # # ]: 0 : if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) {
4593 : 0 : new_offloads = dev_offloads & ~orig_offloads;
4594 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4595 : : "Ethdev port_id=%u requested new added VLAN offloads "
4596 : : "0x%" PRIx64 " must be within Rx offloads capabilities "
4597 : : "0x%" PRIx64 " in %s()",
4598 : : port_id, new_offloads, dev_info.rx_offload_capa,
4599 : : __func__);
4600 : 0 : return -EINVAL;
4601 : : }
4602 : :
4603 [ # # ]: 0 : if (dev->dev_ops->vlan_offload_set == NULL)
4604 : : return -ENOTSUP;
4605 : 0 : dev->data->dev_conf.rxmode.offloads = dev_offloads;
4606 : 0 : ret = dev->dev_ops->vlan_offload_set(dev, mask);
4607 [ # # ]: 0 : if (ret) {
4608 : : /* hit an error restore original values */
4609 : 0 : dev->data->dev_conf.rxmode.offloads = orig_offloads;
4610 : : }
4611 : :
4612 : 0 : ret = eth_err(port_id, ret);
4613 : :
4614 : 0 : rte_ethdev_trace_set_vlan_offload(port_id, offload_mask, ret);
4615 : :
4616 : 0 : return ret;
4617 : : }
4618 : :
4619 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_vlan_offload)
4620 : : int
4621 : 1 : rte_eth_dev_get_vlan_offload(uint16_t port_id)
4622 : : {
4623 : : struct rte_eth_dev *dev;
4624 : : uint64_t *dev_offloads;
4625 : : int ret = 0;
4626 : :
4627 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4628 : : dev = &rte_eth_devices[port_id];
4629 : 1 : dev_offloads = &dev->data->dev_conf.rxmode.offloads;
4630 : :
4631 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4632 : : ret |= RTE_ETH_VLAN_STRIP_OFFLOAD;
4633 : :
4634 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4635 : 0 : ret |= RTE_ETH_VLAN_FILTER_OFFLOAD;
4636 : :
4637 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
4638 : 0 : ret |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
4639 : :
4640 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4641 : 0 : ret |= RTE_ETH_QINQ_STRIP_OFFLOAD;
4642 : :
4643 : 1 : rte_ethdev_trace_get_vlan_offload(port_id, ret);
4644 : :
4645 : 1 : return ret;
4646 : : }
4647 : :
4648 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_pvid)
4649 : : int
4650 : 0 : rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
4651 : : {
4652 : : struct rte_eth_dev *dev;
4653 : : int ret;
4654 : :
4655 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4656 : 0 : dev = &rte_eth_devices[port_id];
4657 : :
4658 [ # # ]: 0 : if (dev->dev_ops->vlan_pvid_set == NULL)
4659 : : return -ENOTSUP;
4660 : 0 : ret = eth_err(port_id, dev->dev_ops->vlan_pvid_set(dev, pvid, on));
4661 : :
4662 : 0 : rte_ethdev_trace_set_vlan_pvid(port_id, pvid, on, ret);
4663 : :
4664 : 0 : return ret;
4665 : : }
4666 : :
4667 : : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_get)
4668 : : int
4669 : 1 : rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
4670 : : {
4671 : : struct rte_eth_dev *dev;
4672 : : int ret;
4673 : :
4674 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4675 : 1 : dev = &rte_eth_devices[port_id];
4676 : :
4677 [ - + ]: 1 : if (fc_conf == NULL) {
4678 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4679 : : "Cannot get ethdev port %u flow control config to NULL",
4680 : : port_id);
4681 : 0 : return -EINVAL;
4682 : : }
4683 : :
4684 [ - + ]: 1 : if (dev->dev_ops->flow_ctrl_get == NULL)
4685 : : return -ENOTSUP;
4686 : : memset(fc_conf, 0, sizeof(*fc_conf));
4687 : 0 : ret = eth_err(port_id, dev->dev_ops->flow_ctrl_get(dev, fc_conf));
4688 : :
4689 : 0 : rte_ethdev_trace_flow_ctrl_get(port_id, fc_conf, ret);
4690 : :
4691 : 0 : return ret;
4692 : : }
4693 : :
4694 : : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_set)
4695 : : int
4696 : 0 : rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
4697 : : {
4698 : : struct rte_eth_dev *dev;
4699 : : int ret;
4700 : :
4701 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4702 : 0 : dev = &rte_eth_devices[port_id];
4703 : :
4704 [ # # ]: 0 : if (fc_conf == NULL) {
4705 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4706 : : "Cannot set ethdev port %u flow control from NULL config",
4707 : : port_id);
4708 : 0 : return -EINVAL;
4709 : : }
4710 : :
4711 [ # # ]: 0 : if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
4712 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid send_xon, only 0/1 allowed");
4713 : 0 : return -EINVAL;
4714 : : }
4715 : :
4716 [ # # ]: 0 : if (dev->dev_ops->flow_ctrl_set == NULL)
4717 : : return -ENOTSUP;
4718 : 0 : ret = eth_err(port_id, dev->dev_ops->flow_ctrl_set(dev, fc_conf));
4719 : :
4720 : 0 : rte_ethdev_trace_flow_ctrl_set(port_id, fc_conf, ret);
4721 : :
4722 : 0 : return ret;
4723 : : }
4724 : :
4725 : : RTE_EXPORT_SYMBOL(rte_eth_dev_priority_flow_ctrl_set)
4726 : : int
4727 : 0 : rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
4728 : : struct rte_eth_pfc_conf *pfc_conf)
4729 : : {
4730 : : struct rte_eth_dev *dev;
4731 : : int ret;
4732 : :
4733 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4734 : 0 : dev = &rte_eth_devices[port_id];
4735 : :
4736 [ # # ]: 0 : if (pfc_conf == NULL) {
4737 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4738 : : "Cannot set ethdev port %u priority flow control from NULL config",
4739 : : port_id);
4740 : 0 : return -EINVAL;
4741 : : }
4742 : :
4743 [ # # ]: 0 : if (pfc_conf->priority > (RTE_ETH_DCB_NUM_USER_PRIORITIES - 1)) {
4744 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid priority, only 0-7 allowed");
4745 : 0 : return -EINVAL;
4746 : : }
4747 : :
4748 : : /* High water, low water validation are device specific */
4749 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_set == NULL)
4750 : : return -ENOTSUP;
4751 : 0 : ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_set(dev, pfc_conf));
4752 : :
4753 : 0 : rte_ethdev_trace_priority_flow_ctrl_set(port_id, pfc_conf, ret);
4754 : :
4755 : 0 : return ret;
4756 : : }
4757 : :
4758 : : static int
4759 : 0 : validate_rx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
4760 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4761 : : {
4762 [ # # ]: 0 : if ((pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) ||
4763 : : (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
4764 [ # # ]: 0 : if (pfc_queue_conf->rx_pause.tx_qid >= dev_info->nb_tx_queues) {
4765 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4766 : : "PFC Tx queue not in range for Rx pause requested:%d configured:%d",
4767 : : pfc_queue_conf->rx_pause.tx_qid,
4768 : : dev_info->nb_tx_queues);
4769 : 0 : return -EINVAL;
4770 : : }
4771 : :
4772 [ # # ]: 0 : if (pfc_queue_conf->rx_pause.tc >= tc_max) {
4773 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4774 : : "PFC TC not in range for Rx pause requested:%d max:%d",
4775 : : pfc_queue_conf->rx_pause.tc, tc_max);
4776 : 0 : return -EINVAL;
4777 : : }
4778 : : }
4779 : :
4780 : : return 0;
4781 : : }
4782 : :
4783 : : static int
4784 : 0 : validate_tx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
4785 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4786 : : {
4787 [ # # ]: 0 : if ((pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) ||
4788 : : (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
4789 [ # # ]: 0 : if (pfc_queue_conf->tx_pause.rx_qid >= dev_info->nb_rx_queues) {
4790 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4791 : : "PFC Rx queue not in range for Tx pause requested:%d configured:%d",
4792 : : pfc_queue_conf->tx_pause.rx_qid,
4793 : : dev_info->nb_rx_queues);
4794 : 0 : return -EINVAL;
4795 : : }
4796 : :
4797 [ # # ]: 0 : if (pfc_queue_conf->tx_pause.tc >= tc_max) {
4798 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4799 : : "PFC TC not in range for Tx pause requested:%d max:%d",
4800 : : pfc_queue_conf->tx_pause.tc, tc_max);
4801 : 0 : return -EINVAL;
4802 : : }
4803 : : }
4804 : :
4805 : : return 0;
4806 : : }
4807 : :
4808 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_info_get, 22.03)
4809 : : int
4810 : 0 : rte_eth_dev_priority_flow_ctrl_queue_info_get(uint16_t port_id,
4811 : : struct rte_eth_pfc_queue_info *pfc_queue_info)
4812 : : {
4813 : : struct rte_eth_dev *dev;
4814 : : int ret;
4815 : :
4816 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4817 : 0 : dev = &rte_eth_devices[port_id];
4818 : :
4819 [ # # ]: 0 : if (pfc_queue_info == NULL) {
4820 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC info param is NULL for port (%u)",
4821 : : port_id);
4822 : 0 : return -EINVAL;
4823 : : }
4824 : :
4825 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_queue_info_get == NULL)
4826 : : return -ENOTSUP;
4827 : 0 : ret = eth_err(port_id,
4828 : : dev->dev_ops->priority_flow_ctrl_queue_info_get(dev, pfc_queue_info));
4829 : :
4830 : 0 : rte_ethdev_trace_priority_flow_ctrl_queue_info_get(port_id,
4831 : : pfc_queue_info, ret);
4832 : :
4833 : 0 : return ret;
4834 : : }
4835 : :
4836 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_configure, 22.03)
4837 : : int
4838 : 0 : rte_eth_dev_priority_flow_ctrl_queue_configure(uint16_t port_id,
4839 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4840 : : {
4841 : : struct rte_eth_pfc_queue_info pfc_info;
4842 : : struct rte_eth_dev_info dev_info;
4843 : : struct rte_eth_dev *dev;
4844 : : int ret;
4845 : :
4846 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4847 : 0 : dev = &rte_eth_devices[port_id];
4848 : :
4849 [ # # ]: 0 : if (pfc_queue_conf == NULL) {
4850 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC parameters are NULL for port (%u)",
4851 : : port_id);
4852 : 0 : return -EINVAL;
4853 : : }
4854 : :
4855 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4856 [ # # ]: 0 : if (ret != 0)
4857 : : return ret;
4858 : :
4859 : 0 : ret = rte_eth_dev_priority_flow_ctrl_queue_info_get(port_id, &pfc_info);
4860 [ # # ]: 0 : if (ret != 0)
4861 : : return ret;
4862 : :
4863 [ # # ]: 0 : if (pfc_info.tc_max == 0) {
4864 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port %u does not support PFC TC values",
4865 : : port_id);
4866 : 0 : return -ENOTSUP;
4867 : : }
4868 : :
4869 : : /* Check requested mode supported or not */
4870 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE &&
4871 [ # # ]: 0 : pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) {
4872 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC Tx pause unsupported for port (%d)",
4873 : : port_id);
4874 : 0 : return -EINVAL;
4875 : : }
4876 : :
4877 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE &&
4878 [ # # ]: 0 : pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) {
4879 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC Rx pause unsupported for port (%d)",
4880 : : port_id);
4881 : 0 : return -EINVAL;
4882 : : }
4883 : :
4884 : : /* Validate Rx pause parameters */
4885 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
4886 : : pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE) {
4887 : 0 : ret = validate_rx_pause_config(&dev_info, pfc_info.tc_max,
4888 : : pfc_queue_conf);
4889 [ # # ]: 0 : if (ret != 0)
4890 : : return ret;
4891 : : }
4892 : :
4893 : : /* Validate Tx pause parameters */
4894 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
4895 : : pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE) {
4896 : 0 : ret = validate_tx_pause_config(&dev_info, pfc_info.tc_max,
4897 : : pfc_queue_conf);
4898 [ # # ]: 0 : if (ret != 0)
4899 : : return ret;
4900 : : }
4901 : :
4902 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_queue_config == NULL)
4903 : : return -ENOTSUP;
4904 : 0 : ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_queue_config(dev, pfc_queue_conf));
4905 : :
4906 : 0 : rte_ethdev_trace_priority_flow_ctrl_queue_configure(port_id,
4907 : : pfc_queue_conf, ret);
4908 : :
4909 : 0 : return ret;
4910 : : }
4911 : :
4912 : : static int
4913 : : eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
4914 : : uint16_t reta_size)
4915 : : {
4916 : : uint16_t i, num;
4917 : :
4918 : 0 : num = (reta_size + RTE_ETH_RETA_GROUP_SIZE - 1) / RTE_ETH_RETA_GROUP_SIZE;
4919 [ # # # # ]: 0 : for (i = 0; i < num; i++) {
4920 [ # # # # ]: 0 : if (reta_conf[i].mask)
4921 : : return 0;
4922 : : }
4923 : :
4924 : : return -EINVAL;
4925 : : }
4926 : :
4927 : : static int
4928 : 0 : eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
4929 : : uint16_t reta_size,
4930 : : uint16_t max_rxq)
4931 : : {
4932 : : uint16_t i, idx, shift;
4933 : :
4934 [ # # ]: 0 : if (max_rxq == 0) {
4935 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "No receive queue is available");
4936 : 0 : return -EINVAL;
4937 : : }
4938 : :
4939 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4940 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4941 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4942 [ # # ]: 0 : if ((reta_conf[idx].mask & RTE_BIT64(shift)) &&
4943 [ # # ]: 0 : (reta_conf[idx].reta[shift] >= max_rxq)) {
4944 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4945 : : "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u",
4946 : : idx, shift,
4947 : : reta_conf[idx].reta[shift], max_rxq);
4948 : 0 : return -EINVAL;
4949 : : }
4950 : : }
4951 : :
4952 : : return 0;
4953 : : }
4954 : :
4955 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_update)
4956 : : int
4957 : 0 : rte_eth_dev_rss_reta_update(uint16_t port_id,
4958 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4959 : : uint16_t reta_size)
4960 : : {
4961 : : enum rte_eth_rx_mq_mode mq_mode;
4962 : : struct rte_eth_dev *dev;
4963 : : int ret;
4964 : :
4965 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4966 : 0 : dev = &rte_eth_devices[port_id];
4967 : :
4968 [ # # ]: 0 : if (reta_conf == NULL) {
4969 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4970 : : "Cannot update ethdev port %u RSS RETA to NULL",
4971 : : port_id);
4972 : 0 : return -EINVAL;
4973 : : }
4974 : :
4975 [ # # ]: 0 : if (reta_size == 0) {
4976 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4977 : : "Cannot update ethdev port %u RSS RETA with zero size",
4978 : : port_id);
4979 : 0 : return -EINVAL;
4980 : : }
4981 : :
4982 : : /* Check mask bits */
4983 : 0 : ret = eth_check_reta_mask(reta_conf, reta_size);
4984 [ # # ]: 0 : if (ret < 0)
4985 : : return ret;
4986 : :
4987 : : /* Check entry value */
4988 : 0 : ret = eth_check_reta_entry(reta_conf, reta_size,
4989 : 0 : dev->data->nb_rx_queues);
4990 [ # # ]: 0 : if (ret < 0)
4991 : : return ret;
4992 : :
4993 : 0 : mq_mode = dev->data->dev_conf.rxmode.mq_mode;
4994 [ # # ]: 0 : if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
4995 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
4996 : 0 : return -ENOTSUP;
4997 : : }
4998 : :
4999 [ # # ]: 0 : if (dev->dev_ops->reta_update == NULL)
5000 : : return -ENOTSUP;
5001 : 0 : ret = eth_err(port_id, dev->dev_ops->reta_update(dev, reta_conf, reta_size));
5002 : :
5003 : 0 : rte_ethdev_trace_rss_reta_update(port_id, reta_conf, reta_size, ret);
5004 : :
5005 : 0 : return ret;
5006 : : }
5007 : :
5008 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_query)
5009 : : int
5010 : 0 : rte_eth_dev_rss_reta_query(uint16_t port_id,
5011 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5012 : : uint16_t reta_size)
5013 : : {
5014 : : struct rte_eth_dev *dev;
5015 : : int ret;
5016 : :
5017 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5018 : 0 : dev = &rte_eth_devices[port_id];
5019 : :
5020 [ # # ]: 0 : if (reta_conf == NULL) {
5021 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5022 : : "Cannot query ethdev port %u RSS RETA from NULL config",
5023 : : port_id);
5024 : 0 : return -EINVAL;
5025 : : }
5026 : :
5027 : : /* Check mask bits */
5028 : 0 : ret = eth_check_reta_mask(reta_conf, reta_size);
5029 [ # # ]: 0 : if (ret < 0)
5030 : : return ret;
5031 : :
5032 [ # # ]: 0 : if (dev->dev_ops->reta_query == NULL)
5033 : : return -ENOTSUP;
5034 : 0 : ret = eth_err(port_id, dev->dev_ops->reta_query(dev, reta_conf, reta_size));
5035 : :
5036 : 0 : rte_ethdev_trace_rss_reta_query(port_id, reta_conf, reta_size, ret);
5037 : :
5038 : 0 : return ret;
5039 : : }
5040 : :
5041 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_update)
5042 : : int
5043 : 0 : rte_eth_dev_rss_hash_update(uint16_t port_id,
5044 : : struct rte_eth_rss_conf *rss_conf)
5045 : : {
5046 : : struct rte_eth_dev *dev;
5047 : 0 : struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
5048 : : enum rte_eth_rx_mq_mode mq_mode;
5049 : : int ret;
5050 : :
5051 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5052 : 0 : dev = &rte_eth_devices[port_id];
5053 : :
5054 [ # # ]: 0 : if (rss_conf == NULL) {
5055 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5056 : : "Cannot update ethdev port %u RSS hash from NULL config",
5057 : : port_id);
5058 : 0 : return -EINVAL;
5059 : : }
5060 : :
5061 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5062 [ # # ]: 0 : if (ret != 0)
5063 : : return ret;
5064 : :
5065 [ # # ]: 0 : rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
5066 [ # # ]: 0 : if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
5067 : : dev_info.flow_type_rss_offloads) {
5068 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5069 : : "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64,
5070 : : port_id, rss_conf->rss_hf,
5071 : : dev_info.flow_type_rss_offloads);
5072 : 0 : return -EINVAL;
5073 : : }
5074 : :
5075 : 0 : mq_mode = dev->data->dev_conf.rxmode.mq_mode;
5076 [ # # ]: 0 : if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
5077 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
5078 : 0 : return -ENOTSUP;
5079 : : }
5080 : :
5081 [ # # ]: 0 : if (rss_conf->rss_key != NULL &&
5082 [ # # ]: 0 : rss_conf->rss_key_len != dev_info.hash_key_size) {
5083 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5084 : : "Ethdev port_id=%u invalid RSS key len: %u, valid value: %u",
5085 : : port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
5086 : 0 : return -EINVAL;
5087 : : }
5088 : :
5089 [ # # ]: 0 : if ((size_t)rss_conf->algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
5090 : 0 : (dev_info.rss_algo_capa &
5091 [ # # ]: 0 : RTE_ETH_HASH_ALGO_TO_CAPA(rss_conf->algorithm)) == 0) {
5092 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5093 : : "Ethdev port_id=%u configured RSS hash algorithm (%u)"
5094 : : "is not in the algorithm capability (0x%" PRIx32 ")",
5095 : : port_id, rss_conf->algorithm, dev_info.rss_algo_capa);
5096 : 0 : return -EINVAL;
5097 : : }
5098 : :
5099 [ # # ]: 0 : if (dev->dev_ops->rss_hash_update == NULL)
5100 : : return -ENOTSUP;
5101 : 0 : ret = eth_err(port_id, dev->dev_ops->rss_hash_update(dev, rss_conf));
5102 : :
5103 : 0 : rte_ethdev_trace_rss_hash_update(port_id, rss_conf, ret);
5104 : :
5105 : 0 : return ret;
5106 : : }
5107 : :
5108 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_conf_get)
5109 : : int
5110 : 1 : rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
5111 : : struct rte_eth_rss_conf *rss_conf)
5112 : : {
5113 : 1 : struct rte_eth_dev_info dev_info = { 0 };
5114 : : struct rte_eth_dev *dev;
5115 : : int ret;
5116 : :
5117 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5118 : 1 : dev = &rte_eth_devices[port_id];
5119 : :
5120 [ - + ]: 1 : if (rss_conf == NULL) {
5121 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5122 : : "Cannot get ethdev port %u RSS hash config to NULL",
5123 : : port_id);
5124 : 0 : return -EINVAL;
5125 : : }
5126 : :
5127 : 1 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5128 [ + - ]: 1 : if (ret != 0)
5129 : : return ret;
5130 : :
5131 [ + - ]: 1 : if (rss_conf->rss_key != NULL &&
5132 [ - + ]: 1 : rss_conf->rss_key_len < dev_info.hash_key_size) {
5133 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5134 : : "Ethdev port_id=%u invalid RSS key len: %u, should not be less than: %u",
5135 : : port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
5136 : 0 : return -EINVAL;
5137 : : }
5138 : :
5139 : 1 : rss_conf->algorithm = RTE_ETH_HASH_FUNCTION_DEFAULT;
5140 : :
5141 [ + - ]: 1 : if (dev->dev_ops->rss_hash_conf_get == NULL)
5142 : : return -ENOTSUP;
5143 : 1 : ret = eth_err(port_id, dev->dev_ops->rss_hash_conf_get(dev, rss_conf));
5144 : :
5145 : 1 : rte_ethdev_trace_rss_hash_conf_get(port_id, rss_conf, ret);
5146 : :
5147 : 1 : return ret;
5148 : : }
5149 : :
5150 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_rss_algo_name, 23.11)
5151 : : const char *
5152 : 1 : rte_eth_dev_rss_algo_name(enum rte_eth_hash_function rss_algo)
5153 : : {
5154 : : const char *name = "Unknown function";
5155 : : unsigned int i;
5156 : :
5157 [ + - ]: 1 : for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
5158 [ + - ]: 1 : if (rss_algo == rte_eth_dev_rss_algo_names[i].algo)
5159 : 1 : return rte_eth_dev_rss_algo_names[i].name;
5160 : : }
5161 : :
5162 : : return name;
5163 : : }
5164 : :
5165 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_find_rss_algo, 24.03)
5166 : : int
5167 : 0 : rte_eth_find_rss_algo(const char *name, uint32_t *algo)
5168 : : {
5169 : : unsigned int i;
5170 : :
5171 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
5172 [ # # ]: 0 : if (strcmp(name, rte_eth_dev_rss_algo_names[i].name) == 0) {
5173 : 0 : *algo = rte_eth_dev_rss_algo_names[i].algo;
5174 : 0 : return 0;
5175 : : }
5176 : : }
5177 : :
5178 : : return -EINVAL;
5179 : : }
5180 : :
5181 : : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_add)
5182 : : int
5183 : 0 : rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
5184 : : struct rte_eth_udp_tunnel *udp_tunnel)
5185 : : {
5186 : : struct rte_eth_dev *dev;
5187 : : int ret;
5188 : :
5189 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5190 : 0 : dev = &rte_eth_devices[port_id];
5191 : :
5192 [ # # ]: 0 : if (udp_tunnel == NULL) {
5193 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5194 : : "Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel",
5195 : : port_id);
5196 : 0 : return -EINVAL;
5197 : : }
5198 : :
5199 [ # # ]: 0 : if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
5200 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
5201 : 0 : return -EINVAL;
5202 : : }
5203 : :
5204 [ # # ]: 0 : if (dev->dev_ops->udp_tunnel_port_add == NULL)
5205 : : return -ENOTSUP;
5206 : 0 : ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_add(dev, udp_tunnel));
5207 : :
5208 : 0 : rte_ethdev_trace_udp_tunnel_port_add(port_id, udp_tunnel, ret);
5209 : :
5210 : 0 : return ret;
5211 : : }
5212 : :
5213 : : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_delete)
5214 : : int
5215 : 0 : rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
5216 : : struct rte_eth_udp_tunnel *udp_tunnel)
5217 : : {
5218 : : struct rte_eth_dev *dev;
5219 : : int ret;
5220 : :
5221 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5222 : 0 : dev = &rte_eth_devices[port_id];
5223 : :
5224 [ # # ]: 0 : if (udp_tunnel == NULL) {
5225 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5226 : : "Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel",
5227 : : port_id);
5228 : 0 : return -EINVAL;
5229 : : }
5230 : :
5231 [ # # ]: 0 : if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
5232 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
5233 : 0 : return -EINVAL;
5234 : : }
5235 : :
5236 [ # # ]: 0 : if (dev->dev_ops->udp_tunnel_port_del == NULL)
5237 : : return -ENOTSUP;
5238 : 0 : ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_del(dev, udp_tunnel));
5239 : :
5240 : 0 : rte_ethdev_trace_udp_tunnel_port_delete(port_id, udp_tunnel, ret);
5241 : :
5242 : 0 : return ret;
5243 : : }
5244 : :
5245 : : RTE_EXPORT_SYMBOL(rte_eth_led_on)
5246 : : int
5247 : 0 : rte_eth_led_on(uint16_t port_id)
5248 : : {
5249 : : struct rte_eth_dev *dev;
5250 : : int ret;
5251 : :
5252 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5253 : 0 : dev = &rte_eth_devices[port_id];
5254 : :
5255 [ # # ]: 0 : if (dev->dev_ops->dev_led_on == NULL)
5256 : : return -ENOTSUP;
5257 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_led_on(dev));
5258 : :
5259 : 0 : rte_eth_trace_led_on(port_id, ret);
5260 : :
5261 : 0 : return ret;
5262 : : }
5263 : :
5264 : : RTE_EXPORT_SYMBOL(rte_eth_led_off)
5265 : : int
5266 : 0 : rte_eth_led_off(uint16_t port_id)
5267 : : {
5268 : : struct rte_eth_dev *dev;
5269 : : int ret;
5270 : :
5271 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5272 : 0 : dev = &rte_eth_devices[port_id];
5273 : :
5274 [ # # ]: 0 : if (dev->dev_ops->dev_led_off == NULL)
5275 : : return -ENOTSUP;
5276 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_led_off(dev));
5277 : :
5278 : 0 : rte_eth_trace_led_off(port_id, ret);
5279 : :
5280 : 0 : return ret;
5281 : : }
5282 : :
5283 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_get_capability, 20.11)
5284 : : int
5285 : 0 : rte_eth_fec_get_capability(uint16_t port_id,
5286 : : struct rte_eth_fec_capa *speed_fec_capa,
5287 : : unsigned int num)
5288 : : {
5289 : : struct rte_eth_dev *dev;
5290 : : int ret;
5291 : :
5292 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5293 : 0 : dev = &rte_eth_devices[port_id];
5294 : :
5295 [ # # ]: 0 : if (speed_fec_capa == NULL && num > 0) {
5296 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5297 : : "Cannot get ethdev port %u FEC capability to NULL when array size is non zero",
5298 : : port_id);
5299 : 0 : return -EINVAL;
5300 : : }
5301 : :
5302 [ # # ]: 0 : if (dev->dev_ops->fec_get_capability == NULL)
5303 : : return -ENOTSUP;
5304 : 0 : ret = dev->dev_ops->fec_get_capability(dev, speed_fec_capa, num);
5305 : :
5306 : 0 : rte_eth_trace_fec_get_capability(port_id, speed_fec_capa, num, ret);
5307 : :
5308 : 0 : return ret;
5309 : : }
5310 : :
5311 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_get, 20.11)
5312 : : int
5313 : 1 : rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
5314 : : {
5315 : : struct rte_eth_dev *dev;
5316 : : int ret;
5317 : :
5318 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5319 : 1 : dev = &rte_eth_devices[port_id];
5320 : :
5321 [ - + ]: 1 : if (fec_capa == NULL) {
5322 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5323 : : "Cannot get ethdev port %u current FEC mode to NULL",
5324 : : port_id);
5325 : 0 : return -EINVAL;
5326 : : }
5327 : :
5328 [ - + ]: 1 : if (dev->dev_ops->fec_get == NULL)
5329 : : return -ENOTSUP;
5330 : 0 : ret = eth_err(port_id, dev->dev_ops->fec_get(dev, fec_capa));
5331 : :
5332 : 0 : rte_eth_trace_fec_get(port_id, fec_capa, ret);
5333 : :
5334 : 0 : return ret;
5335 : : }
5336 : :
5337 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_set, 20.11)
5338 : : int
5339 : 0 : rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
5340 : : {
5341 : : struct rte_eth_dev *dev;
5342 : : int ret;
5343 : :
5344 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5345 : 0 : dev = &rte_eth_devices[port_id];
5346 : :
5347 [ # # ]: 0 : if (fec_capa == 0) {
5348 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "At least one FEC mode should be specified");
5349 : 0 : return -EINVAL;
5350 : : }
5351 : :
5352 [ # # ]: 0 : if (dev->dev_ops->fec_set == NULL)
5353 : : return -ENOTSUP;
5354 : 0 : ret = eth_err(port_id, dev->dev_ops->fec_set(dev, fec_capa));
5355 : :
5356 : 0 : rte_eth_trace_fec_set(port_id, fec_capa, ret);
5357 : :
5358 : 0 : return ret;
5359 : : }
5360 : :
5361 : : /*
5362 : : * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
5363 : : * an empty spot.
5364 : : */
5365 : : static int
5366 : 3 : eth_dev_get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
5367 : : {
5368 : : struct rte_eth_dev_info dev_info;
5369 : 3 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
5370 : : unsigned i;
5371 : : int ret;
5372 : :
5373 : 3 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5374 [ + - ]: 3 : if (ret != 0)
5375 : : return -1;
5376 : :
5377 [ + + ]: 21 : for (i = 0; i < dev_info.max_mac_addrs; i++)
5378 [ + + ]: 20 : if (memcmp(addr, &dev->data->mac_addrs[i],
5379 : : RTE_ETHER_ADDR_LEN) == 0)
5380 : 2 : return i;
5381 : :
5382 : : return -1;
5383 : : }
5384 : :
5385 : : static const struct rte_ether_addr null_mac_addr;
5386 : :
5387 : : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_add)
5388 : : int
5389 : 1 : rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
5390 : : uint32_t pool)
5391 : : {
5392 : : struct rte_eth_dev *dev;
5393 : : int index;
5394 : : uint64_t pool_mask;
5395 : : int ret;
5396 : :
5397 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5398 : 1 : dev = &rte_eth_devices[port_id];
5399 : :
5400 [ - + ]: 1 : if (addr == NULL) {
5401 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5402 : : "Cannot add ethdev port %u MAC address from NULL address",
5403 : : port_id);
5404 : 0 : return -EINVAL;
5405 : : }
5406 : :
5407 [ + - ]: 1 : if (dev->dev_ops->mac_addr_add == NULL)
5408 : : return -ENOTSUP;
5409 : :
5410 [ - + ]: 1 : if (rte_is_zero_ether_addr(addr)) {
5411 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
5412 : : port_id);
5413 : 0 : return -EINVAL;
5414 : : }
5415 [ - + ]: 1 : if (pool >= RTE_ETH_64_POOLS) {
5416 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Pool ID must be 0-%d", RTE_ETH_64_POOLS - 1);
5417 : 0 : return -EINVAL;
5418 : : }
5419 : :
5420 : 1 : index = eth_dev_get_mac_addr_index(port_id, addr);
5421 [ + - ]: 1 : if (index < 0) {
5422 : 1 : index = eth_dev_get_mac_addr_index(port_id, &null_mac_addr);
5423 [ - + ]: 1 : if (index < 0) {
5424 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
5425 : : port_id);
5426 : 0 : return -ENOSPC;
5427 : : }
5428 : : } else {
5429 : 0 : pool_mask = dev->data->mac_pool_sel[index];
5430 : :
5431 : : /* Check if both MAC address and pool is already there, and do nothing */
5432 [ # # ]: 0 : if (pool_mask & RTE_BIT64(pool))
5433 : : return 0;
5434 : : }
5435 : :
5436 : : /* Update NIC */
5437 : 1 : ret = dev->dev_ops->mac_addr_add(dev, addr, index, pool);
5438 : :
5439 [ + - ]: 1 : if (ret == 0) {
5440 : : /* Update address in NIC data structure */
5441 : 1 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
5442 : :
5443 : : /* Update pool bitmap in NIC data structure */
5444 : 1 : dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
5445 : : }
5446 : :
5447 : 1 : ret = eth_err(port_id, ret);
5448 : :
5449 : 1 : rte_ethdev_trace_mac_addr_add(port_id, addr, pool, ret);
5450 : :
5451 : 1 : return ret;
5452 : : }
5453 : :
5454 : : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_remove)
5455 : : int
5456 : 1 : rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
5457 : : {
5458 : : struct rte_eth_dev *dev;
5459 : : int index;
5460 : :
5461 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5462 : 1 : dev = &rte_eth_devices[port_id];
5463 : :
5464 [ - + ]: 1 : if (addr == NULL) {
5465 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5466 : : "Cannot remove ethdev port %u MAC address from NULL address",
5467 : : port_id);
5468 : 0 : return -EINVAL;
5469 : : }
5470 : :
5471 [ + - ]: 1 : if (dev->dev_ops->mac_addr_remove == NULL)
5472 : : return -ENOTSUP;
5473 : :
5474 : 1 : index = eth_dev_get_mac_addr_index(port_id, addr);
5475 [ - + ]: 1 : if (index == 0) {
5476 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5477 : : "Port %u: Cannot remove default MAC address",
5478 : : port_id);
5479 : 0 : return -EADDRINUSE;
5480 [ + - ]: 1 : } else if (index < 0)
5481 : : return 0; /* Do nothing if address wasn't found */
5482 : :
5483 : : /* Update NIC */
5484 : 1 : dev->dev_ops->mac_addr_remove(dev, index);
5485 : :
5486 : : /* Update address in NIC data structure */
5487 [ - + ]: 1 : rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
5488 : :
5489 : : /* reset pool bitmap */
5490 [ - + ]: 1 : dev->data->mac_pool_sel[index] = 0;
5491 : :
5492 : 1 : rte_ethdev_trace_mac_addr_remove(port_id, addr);
5493 : :
5494 : 1 : return 0;
5495 : : }
5496 : :
5497 : : RTE_EXPORT_SYMBOL(rte_eth_dev_default_mac_addr_set)
5498 : : int
5499 : 0 : rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
5500 : : {
5501 : : struct rte_eth_dev *dev;
5502 : : int index;
5503 : : int ret;
5504 : :
5505 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5506 : 0 : dev = &rte_eth_devices[port_id];
5507 : :
5508 [ # # ]: 0 : if (addr == NULL) {
5509 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5510 : : "Cannot set ethdev port %u default MAC address from NULL address",
5511 : : port_id);
5512 : 0 : return -EINVAL;
5513 : : }
5514 : :
5515 : : if (!rte_is_valid_assigned_ether_addr(addr))
5516 : : return -EINVAL;
5517 : :
5518 [ # # ]: 0 : if (dev->dev_ops->mac_addr_set == NULL)
5519 : : return -ENOTSUP;
5520 : :
5521 : : /* Keep address unique in dev->data->mac_addrs[]. */
5522 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5523 [ # # ]: 0 : if (index > 0) {
5524 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5525 : : "New default address for port %u was already in the address list. Please remove it first.",
5526 : : port_id);
5527 : 0 : return -EEXIST;
5528 : : }
5529 : :
5530 : 0 : ret = dev->dev_ops->mac_addr_set(dev, addr);
5531 [ # # ]: 0 : if (ret < 0)
5532 : : return ret;
5533 : :
5534 : : /* Update default address in NIC data structure */
5535 [ # # ]: 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
5536 : :
5537 : 0 : rte_ethdev_trace_default_mac_addr_set(port_id, addr);
5538 : :
5539 : 0 : return 0;
5540 : : }
5541 : :
5542 : :
5543 : : /*
5544 : : * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
5545 : : * an empty spot.
5546 : : */
5547 : : static int
5548 : 0 : eth_dev_get_hash_mac_addr_index(uint16_t port_id,
5549 : : const struct rte_ether_addr *addr)
5550 : : {
5551 : : struct rte_eth_dev_info dev_info;
5552 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
5553 : : unsigned i;
5554 : : int ret;
5555 : :
5556 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5557 [ # # ]: 0 : if (ret != 0)
5558 : : return -1;
5559 : :
5560 [ # # ]: 0 : if (!dev->data->hash_mac_addrs)
5561 : : return -1;
5562 : :
5563 [ # # ]: 0 : for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
5564 [ # # ]: 0 : if (memcmp(addr, &dev->data->hash_mac_addrs[i],
5565 : : RTE_ETHER_ADDR_LEN) == 0)
5566 : 0 : return i;
5567 : :
5568 : : return -1;
5569 : : }
5570 : :
5571 : : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_hash_table_set)
5572 : : int
5573 : 0 : rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
5574 : : uint8_t on)
5575 : : {
5576 : : int index;
5577 : : int ret;
5578 : : struct rte_eth_dev *dev;
5579 : :
5580 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5581 : 0 : dev = &rte_eth_devices[port_id];
5582 : :
5583 [ # # ]: 0 : if (addr == NULL) {
5584 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5585 : : "Cannot set ethdev port %u unicast hash table from NULL address",
5586 : : port_id);
5587 : 0 : return -EINVAL;
5588 : : }
5589 : :
5590 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr)) {
5591 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
5592 : : port_id);
5593 : 0 : return -EINVAL;
5594 : : }
5595 : :
5596 : 0 : index = eth_dev_get_hash_mac_addr_index(port_id, addr);
5597 : : /* Check if it's already there, and do nothing */
5598 [ # # ]: 0 : if ((index >= 0) && on)
5599 : : return 0;
5600 : :
5601 [ # # ]: 0 : if (index < 0) {
5602 [ # # ]: 0 : if (!on) {
5603 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5604 : : "Port %u: the MAC address was not set in UTA",
5605 : : port_id);
5606 : 0 : return -EINVAL;
5607 : : }
5608 : :
5609 : 0 : index = eth_dev_get_hash_mac_addr_index(port_id, &null_mac_addr);
5610 [ # # ]: 0 : if (index < 0) {
5611 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
5612 : : port_id);
5613 : 0 : return -ENOSPC;
5614 : : }
5615 : : }
5616 : :
5617 [ # # ]: 0 : if (dev->dev_ops->uc_hash_table_set == NULL)
5618 : : return -ENOTSUP;
5619 : 0 : ret = dev->dev_ops->uc_hash_table_set(dev, addr, on);
5620 [ # # ]: 0 : if (ret == 0) {
5621 : : /* Update address in NIC data structure */
5622 [ # # ]: 0 : if (on)
5623 : 0 : rte_ether_addr_copy(addr,
5624 : 0 : &dev->data->hash_mac_addrs[index]);
5625 : : else
5626 : 0 : rte_ether_addr_copy(&null_mac_addr,
5627 : 0 : &dev->data->hash_mac_addrs[index]);
5628 : : }
5629 : :
5630 : 0 : ret = eth_err(port_id, ret);
5631 : :
5632 : 0 : rte_ethdev_trace_uc_hash_table_set(port_id, on, ret);
5633 : :
5634 : 0 : return ret;
5635 : : }
5636 : :
5637 : : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_all_hash_table_set)
5638 : : int
5639 : 0 : rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
5640 : : {
5641 : : struct rte_eth_dev *dev;
5642 : : int ret;
5643 : :
5644 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5645 : 0 : dev = &rte_eth_devices[port_id];
5646 : :
5647 [ # # ]: 0 : if (dev->dev_ops->uc_all_hash_table_set == NULL)
5648 : : return -ENOTSUP;
5649 : 0 : ret = eth_err(port_id, dev->dev_ops->uc_all_hash_table_set(dev, on));
5650 : :
5651 : 0 : rte_ethdev_trace_uc_all_hash_table_set(port_id, on, ret);
5652 : :
5653 : 0 : return ret;
5654 : : }
5655 : :
5656 : : RTE_EXPORT_SYMBOL(rte_eth_set_queue_rate_limit)
5657 : 0 : int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
5658 : : uint32_t tx_rate)
5659 : : {
5660 : : struct rte_eth_dev *dev;
5661 : : struct rte_eth_dev_info dev_info;
5662 : : struct rte_eth_link link;
5663 : : int ret;
5664 : :
5665 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5666 : 0 : dev = &rte_eth_devices[port_id];
5667 : :
5668 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5669 [ # # ]: 0 : if (ret != 0)
5670 : : return ret;
5671 : :
5672 : 0 : link = dev->data->dev_link;
5673 : :
5674 [ # # ]: 0 : if (queue_idx > dev_info.max_tx_queues) {
5675 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5676 : : "Set queue rate limit:port %u: invalid queue ID=%u",
5677 : : port_id, queue_idx);
5678 : 0 : return -EINVAL;
5679 : : }
5680 : :
5681 [ # # ]: 0 : if (tx_rate > link.link_speed) {
5682 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5683 : : "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d",
5684 : : tx_rate, link.link_speed);
5685 : 0 : return -EINVAL;
5686 : : }
5687 : :
5688 [ # # ]: 0 : if (dev->dev_ops->set_queue_rate_limit == NULL)
5689 : : return -ENOTSUP;
5690 : 0 : ret = eth_err(port_id, dev->dev_ops->set_queue_rate_limit(dev, queue_idx, tx_rate));
5691 : :
5692 [ # # ]: 0 : rte_eth_trace_set_queue_rate_limit(port_id, queue_idx, tx_rate, ret);
5693 : :
5694 : 0 : return ret;
5695 : : }
5696 : :
5697 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_avail_thresh_set, 22.07)
5698 : 0 : int rte_eth_rx_avail_thresh_set(uint16_t port_id, uint16_t queue_id,
5699 : : uint8_t avail_thresh)
5700 : : {
5701 : : struct rte_eth_dev *dev;
5702 : : int ret;
5703 : :
5704 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5705 : 0 : dev = &rte_eth_devices[port_id];
5706 : :
5707 [ # # ]: 0 : if (queue_id > dev->data->nb_rx_queues) {
5708 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5709 : : "Set queue avail thresh: port %u: invalid queue ID=%u.",
5710 : : port_id, queue_id);
5711 : 0 : return -EINVAL;
5712 : : }
5713 : :
5714 [ # # ]: 0 : if (avail_thresh > 99) {
5715 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5716 : : "Set queue avail thresh: port %u: threshold should be <= 99.",
5717 : : port_id);
5718 : 0 : return -EINVAL;
5719 : : }
5720 [ # # ]: 0 : if (dev->dev_ops->rx_queue_avail_thresh_set == NULL)
5721 : : return -ENOTSUP;
5722 : 0 : ret = eth_err(port_id,
5723 : : dev->dev_ops->rx_queue_avail_thresh_set(dev, queue_id, avail_thresh));
5724 : :
5725 : 0 : rte_eth_trace_rx_avail_thresh_set(port_id, queue_id, avail_thresh, ret);
5726 : :
5727 : 0 : return ret;
5728 : : }
5729 : :
5730 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_avail_thresh_query, 22.07)
5731 : 0 : int rte_eth_rx_avail_thresh_query(uint16_t port_id, uint16_t *queue_id,
5732 : : uint8_t *avail_thresh)
5733 : : {
5734 : : struct rte_eth_dev *dev;
5735 : : int ret;
5736 : :
5737 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5738 : 0 : dev = &rte_eth_devices[port_id];
5739 : :
5740 [ # # ]: 0 : if (queue_id == NULL)
5741 : : return -EINVAL;
5742 [ # # ]: 0 : if (*queue_id >= dev->data->nb_rx_queues)
5743 : 0 : *queue_id = 0;
5744 : :
5745 [ # # ]: 0 : if (dev->dev_ops->rx_queue_avail_thresh_query == NULL)
5746 : : return -ENOTSUP;
5747 : 0 : ret = eth_err(port_id,
5748 : : dev->dev_ops->rx_queue_avail_thresh_query(dev, queue_id, avail_thresh));
5749 : :
5750 [ # # ]: 0 : rte_eth_trace_rx_avail_thresh_query(port_id, *queue_id, ret);
5751 : :
5752 : 0 : return ret;
5753 : : }
5754 : :
5755 : 276 : RTE_INIT(eth_dev_init_fp_ops)
5756 : : {
5757 : : uint32_t i;
5758 : :
5759 [ + + ]: 9108 : for (i = 0; i != RTE_DIM(rte_eth_fp_ops); i++)
5760 : 8832 : eth_dev_fp_ops_reset(rte_eth_fp_ops + i);
5761 : 276 : }
5762 : :
5763 : 276 : RTE_INIT(eth_dev_init_cb_lists)
5764 : : {
5765 : : uint16_t i;
5766 : :
5767 [ + + ]: 9108 : for (i = 0; i < RTE_MAX_ETHPORTS; i++)
5768 : 8832 : TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
5769 : 276 : }
5770 : :
5771 : : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_register)
5772 : : int
5773 : 0 : rte_eth_dev_callback_register(uint16_t port_id,
5774 : : enum rte_eth_event_type event,
5775 : : rte_eth_dev_cb_fn cb_fn, void *cb_arg)
5776 : : {
5777 : : struct rte_eth_dev *dev;
5778 : : struct rte_eth_dev_callback *user_cb;
5779 : : uint16_t next_port;
5780 : : uint16_t last_port;
5781 : :
5782 [ # # ]: 0 : if (cb_fn == NULL) {
5783 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5784 : : "Cannot register ethdev port %u callback from NULL",
5785 : : port_id);
5786 : 0 : return -EINVAL;
5787 : : }
5788 : :
5789 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
5790 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
5791 : 0 : return -EINVAL;
5792 : : }
5793 : :
5794 [ # # ]: 0 : if (port_id == RTE_ETH_ALL) {
5795 : : next_port = 0;
5796 : : last_port = RTE_MAX_ETHPORTS - 1;
5797 : : } else {
5798 : : next_port = last_port = port_id;
5799 : : }
5800 : :
5801 : : rte_spinlock_lock(ð_dev_cb_lock);
5802 : :
5803 : : do {
5804 : 0 : dev = &rte_eth_devices[next_port];
5805 : :
5806 [ # # ]: 0 : TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
5807 [ # # ]: 0 : if (user_cb->cb_fn == cb_fn &&
5808 [ # # ]: 0 : user_cb->cb_arg == cb_arg &&
5809 [ # # ]: 0 : user_cb->event == event) {
5810 : : break;
5811 : : }
5812 : : }
5813 : :
5814 : : /* create a new callback. */
5815 [ # # ]: 0 : if (user_cb == NULL) {
5816 : 0 : user_cb = rte_zmalloc("INTR_USER_CALLBACK",
5817 : : sizeof(struct rte_eth_dev_callback), 0);
5818 [ # # ]: 0 : if (user_cb != NULL) {
5819 : 0 : user_cb->cb_fn = cb_fn;
5820 : 0 : user_cb->cb_arg = cb_arg;
5821 : 0 : user_cb->event = event;
5822 : 0 : TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
5823 : : user_cb, next);
5824 : : } else {
5825 : : rte_spinlock_unlock(ð_dev_cb_lock);
5826 : 0 : rte_eth_dev_callback_unregister(port_id, event,
5827 : : cb_fn, cb_arg);
5828 : 0 : return -ENOMEM;
5829 : : }
5830 : :
5831 : : }
5832 [ # # ]: 0 : } while (++next_port <= last_port);
5833 : :
5834 : : rte_spinlock_unlock(ð_dev_cb_lock);
5835 : :
5836 : 0 : rte_ethdev_trace_callback_register(port_id, event, cb_fn, cb_arg);
5837 : :
5838 : 0 : return 0;
5839 : : }
5840 : :
5841 : : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_unregister)
5842 : : int
5843 : 0 : rte_eth_dev_callback_unregister(uint16_t port_id,
5844 : : enum rte_eth_event_type event,
5845 : : rte_eth_dev_cb_fn cb_fn, void *cb_arg)
5846 : : {
5847 : : int ret;
5848 : : struct rte_eth_dev *dev;
5849 : : struct rte_eth_dev_callback *cb, *next;
5850 : : uint16_t next_port;
5851 : : uint16_t last_port;
5852 : :
5853 [ # # ]: 0 : if (cb_fn == NULL) {
5854 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5855 : : "Cannot unregister ethdev port %u callback from NULL",
5856 : : port_id);
5857 : 0 : return -EINVAL;
5858 : : }
5859 : :
5860 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
5861 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
5862 : 0 : return -EINVAL;
5863 : : }
5864 : :
5865 [ # # ]: 0 : if (port_id == RTE_ETH_ALL) {
5866 : : next_port = 0;
5867 : : last_port = RTE_MAX_ETHPORTS - 1;
5868 : : } else {
5869 : : next_port = last_port = port_id;
5870 : : }
5871 : :
5872 : : rte_spinlock_lock(ð_dev_cb_lock);
5873 : :
5874 : : do {
5875 : 0 : dev = &rte_eth_devices[next_port];
5876 : : ret = 0;
5877 [ # # ]: 0 : for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
5878 : : cb = next) {
5879 : :
5880 : 0 : next = TAILQ_NEXT(cb, next);
5881 : :
5882 [ # # # # : 0 : if (cb->cb_fn != cb_fn || cb->event != event ||
# # ]
5883 [ # # ]: 0 : (cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
5884 : 0 : continue;
5885 : :
5886 : : /*
5887 : : * if this callback is not executing right now,
5888 : : * then remove it.
5889 : : */
5890 [ # # ]: 0 : if (cb->active == 0) {
5891 [ # # ]: 0 : TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
5892 : 0 : rte_free(cb);
5893 : : } else {
5894 : : ret = -EAGAIN;
5895 : : }
5896 : : }
5897 [ # # ]: 0 : } while (++next_port <= last_port);
5898 : :
5899 : : rte_spinlock_unlock(ð_dev_cb_lock);
5900 : :
5901 : 0 : rte_ethdev_trace_callback_unregister(port_id, event, cb_fn, cb_arg,
5902 : : ret);
5903 : :
5904 : 0 : return ret;
5905 : : }
5906 : :
5907 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl)
5908 : : int
5909 : 0 : rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
5910 : : {
5911 : : uint32_t vec;
5912 : : struct rte_eth_dev *dev;
5913 : : struct rte_intr_handle *intr_handle;
5914 : : uint16_t qid;
5915 : : int rc;
5916 : :
5917 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5918 : : dev = &rte_eth_devices[port_id];
5919 : :
5920 [ # # ]: 0 : if (!dev->intr_handle) {
5921 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5922 : 0 : return -ENOTSUP;
5923 : : }
5924 : :
5925 : : intr_handle = dev->intr_handle;
5926 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
5927 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
5928 : 0 : return -EPERM;
5929 : : }
5930 : :
5931 [ # # ]: 0 : for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
5932 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, qid);
5933 : 0 : rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
5934 : :
5935 : 0 : rte_ethdev_trace_rx_intr_ctl(port_id, qid, epfd, op, data, rc);
5936 : :
5937 [ # # ]: 0 : if (rc && rc != -EEXIST) {
5938 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5939 : : "p %u q %u Rx ctl error op %d epfd %d vec %u",
5940 : : port_id, qid, op, epfd, vec);
5941 : : }
5942 : : }
5943 : :
5944 : : return 0;
5945 : : }
5946 : :
5947 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q_get_fd)
5948 : : int
5949 : 0 : rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
5950 : : {
5951 : : struct rte_intr_handle *intr_handle;
5952 : : struct rte_eth_dev *dev;
5953 : : unsigned int efd_idx;
5954 : : uint32_t vec;
5955 : : int fd;
5956 : :
5957 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
5958 : : dev = &rte_eth_devices[port_id];
5959 : :
5960 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
5961 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
5962 : 0 : return -1;
5963 : : }
5964 : :
5965 [ # # ]: 0 : if (!dev->intr_handle) {
5966 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5967 : 0 : return -1;
5968 : : }
5969 : :
5970 : : intr_handle = dev->intr_handle;
5971 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
5972 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
5973 : 0 : return -1;
5974 : : }
5975 : :
5976 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
5977 : : efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
5978 [ # # ]: 0 : (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
5979 : 0 : fd = rte_intr_efds_index_get(intr_handle, efd_idx);
5980 : :
5981 : 0 : rte_ethdev_trace_rx_intr_ctl_q_get_fd(port_id, queue_id, fd);
5982 : :
5983 : 0 : return fd;
5984 : : }
5985 : :
5986 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q)
5987 : : int
5988 : 0 : rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
5989 : : int epfd, int op, void *data)
5990 : : {
5991 : : uint32_t vec;
5992 : : struct rte_eth_dev *dev;
5993 : : struct rte_intr_handle *intr_handle;
5994 : : int rc;
5995 : :
5996 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5997 : : dev = &rte_eth_devices[port_id];
5998 : :
5999 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6000 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6001 : 0 : return -EINVAL;
6002 : : }
6003 : :
6004 [ # # ]: 0 : if (!dev->intr_handle) {
6005 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
6006 : 0 : return -ENOTSUP;
6007 : : }
6008 : :
6009 : : intr_handle = dev->intr_handle;
6010 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
6011 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
6012 : 0 : return -EPERM;
6013 : : }
6014 : :
6015 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
6016 : 0 : rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
6017 : :
6018 : 0 : rte_ethdev_trace_rx_intr_ctl_q(port_id, queue_id, epfd, op, data, rc);
6019 : :
6020 [ # # ]: 0 : if (rc && rc != -EEXIST) {
6021 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6022 : : "p %u q %u Rx ctl error op %d epfd %d vec %u",
6023 : : port_id, queue_id, op, epfd, vec);
6024 : 0 : return rc;
6025 : : }
6026 : :
6027 : : return 0;
6028 : : }
6029 : :
6030 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_enable)
6031 : : int
6032 : 0 : rte_eth_dev_rx_intr_enable(uint16_t port_id,
6033 : : uint16_t queue_id)
6034 : : {
6035 : : struct rte_eth_dev *dev;
6036 : : int ret;
6037 : :
6038 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6039 : 0 : dev = &rte_eth_devices[port_id];
6040 : :
6041 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6042 [ # # ]: 0 : if (ret != 0)
6043 : : return ret;
6044 : :
6045 [ # # ]: 0 : if (dev->dev_ops->rx_queue_intr_enable == NULL)
6046 : : return -ENOTSUP;
6047 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_enable(dev, queue_id));
6048 : :
6049 : : rte_ethdev_trace_rx_intr_enable(port_id, queue_id, ret);
6050 : :
6051 : 0 : return ret;
6052 : : }
6053 : :
6054 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_disable)
6055 : : int
6056 : 0 : rte_eth_dev_rx_intr_disable(uint16_t port_id,
6057 : : uint16_t queue_id)
6058 : : {
6059 : : struct rte_eth_dev *dev;
6060 : : int ret;
6061 : :
6062 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6063 : 0 : dev = &rte_eth_devices[port_id];
6064 : :
6065 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6066 [ # # ]: 0 : if (ret != 0)
6067 : : return ret;
6068 : :
6069 [ # # ]: 0 : if (dev->dev_ops->rx_queue_intr_disable == NULL)
6070 : : return -ENOTSUP;
6071 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_disable(dev, queue_id));
6072 : :
6073 : : rte_ethdev_trace_rx_intr_disable(port_id, queue_id, ret);
6074 : :
6075 : 0 : return ret;
6076 : : }
6077 : :
6078 : :
6079 : : RTE_EXPORT_SYMBOL(rte_eth_add_rx_callback)
6080 : : const struct rte_eth_rxtx_callback *
6081 : 0 : rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
6082 : : rte_rx_callback_fn fn, void *user_param)
6083 : : {
6084 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6085 : : rte_errno = ENOTSUP;
6086 : : return NULL;
6087 : : #endif
6088 : : struct rte_eth_dev *dev;
6089 : :
6090 : : /* check input parameters */
6091 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6092 [ # # ]: 0 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
6093 : 0 : rte_errno = EINVAL;
6094 : 0 : return NULL;
6095 : : }
6096 : 0 : dev = &rte_eth_devices[port_id];
6097 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
6098 : 0 : rte_errno = EINVAL;
6099 : 0 : return NULL;
6100 : : }
6101 : 0 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6102 : :
6103 [ # # ]: 0 : if (cb == NULL) {
6104 : 0 : rte_errno = ENOMEM;
6105 : 0 : return NULL;
6106 : : }
6107 : :
6108 : 0 : cb->fn.rx = fn;
6109 : 0 : cb->param = user_param;
6110 : :
6111 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6112 : : /* Add the callbacks in fifo order. */
6113 : 0 : struct rte_eth_rxtx_callback *tail =
6114 : : rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
6115 : :
6116 [ # # ]: 0 : if (!tail) {
6117 : : /* Stores to cb->fn and cb->param should complete before
6118 : : * cb is visible to data plane.
6119 : : */
6120 : 0 : rte_atomic_store_explicit(
6121 : : &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
6122 : : cb, rte_memory_order_release);
6123 : :
6124 : : } else {
6125 [ # # ]: 0 : while (tail->next)
6126 : : tail = tail->next;
6127 : : /* Stores to cb->fn and cb->param should complete before
6128 : : * cb is visible to data plane.
6129 : : */
6130 : 0 : rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
6131 : : }
6132 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6133 : :
6134 : 0 : rte_eth_trace_add_rx_callback(port_id, queue_id, fn, user_param, cb);
6135 : :
6136 : 0 : return cb;
6137 : : }
6138 : :
6139 : : RTE_EXPORT_SYMBOL(rte_eth_add_first_rx_callback)
6140 : : const struct rte_eth_rxtx_callback *
6141 : 1 : rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
6142 : : rte_rx_callback_fn fn, void *user_param)
6143 : : {
6144 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6145 : : rte_errno = ENOTSUP;
6146 : : return NULL;
6147 : : #endif
6148 : : /* check input parameters */
6149 [ + - + - ]: 1 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6150 [ - + ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
6151 : 0 : rte_errno = EINVAL;
6152 : 0 : return NULL;
6153 : : }
6154 : :
6155 : 1 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6156 : :
6157 [ - + ]: 1 : if (cb == NULL) {
6158 : 0 : rte_errno = ENOMEM;
6159 : 0 : return NULL;
6160 : : }
6161 : :
6162 : 1 : cb->fn.rx = fn;
6163 : 1 : cb->param = user_param;
6164 : :
6165 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6166 : : /* Add the callbacks at first position */
6167 : 1 : cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
6168 : : /* Stores to cb->fn, cb->param and cb->next should complete before
6169 : : * cb is visible to data plane threads.
6170 : : */
6171 : 1 : rte_atomic_store_explicit(
6172 : : &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
6173 : : cb, rte_memory_order_release);
6174 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6175 : :
6176 : 1 : rte_eth_trace_add_first_rx_callback(port_id, queue_id, fn, user_param,
6177 : : cb);
6178 : :
6179 : 1 : return cb;
6180 : : }
6181 : :
6182 : : RTE_EXPORT_SYMBOL(rte_eth_add_tx_callback)
6183 : : const struct rte_eth_rxtx_callback *
6184 : 1 : rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
6185 : : rte_tx_callback_fn fn, void *user_param)
6186 : : {
6187 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6188 : : rte_errno = ENOTSUP;
6189 : : return NULL;
6190 : : #endif
6191 : : struct rte_eth_dev *dev;
6192 : :
6193 : : /* check input parameters */
6194 [ + - + - ]: 1 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6195 [ - + ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
6196 : 0 : rte_errno = EINVAL;
6197 : 0 : return NULL;
6198 : : }
6199 : :
6200 : 1 : dev = &rte_eth_devices[port_id];
6201 [ - + ]: 1 : if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
6202 : 0 : rte_errno = EINVAL;
6203 : 0 : return NULL;
6204 : : }
6205 : :
6206 : 1 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6207 : :
6208 [ - + ]: 1 : if (cb == NULL) {
6209 : 0 : rte_errno = ENOMEM;
6210 : 0 : return NULL;
6211 : : }
6212 : :
6213 : 1 : cb->fn.tx = fn;
6214 : 1 : cb->param = user_param;
6215 : :
6216 : : rte_spinlock_lock(ð_dev_tx_cb_lock);
6217 : : /* Add the callbacks in fifo order. */
6218 : 1 : struct rte_eth_rxtx_callback *tail =
6219 : : rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
6220 : :
6221 [ + - ]: 1 : if (!tail) {
6222 : : /* Stores to cb->fn and cb->param should complete before
6223 : : * cb is visible to data plane.
6224 : : */
6225 : 1 : rte_atomic_store_explicit(
6226 : : &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id],
6227 : : cb, rte_memory_order_release);
6228 : :
6229 : : } else {
6230 [ # # ]: 0 : while (tail->next)
6231 : : tail = tail->next;
6232 : : /* Stores to cb->fn and cb->param should complete before
6233 : : * cb is visible to data plane.
6234 : : */
6235 : 0 : rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
6236 : : }
6237 : : rte_spinlock_unlock(ð_dev_tx_cb_lock);
6238 : :
6239 : 1 : rte_eth_trace_add_tx_callback(port_id, queue_id, fn, user_param, cb);
6240 : :
6241 : 1 : return cb;
6242 : : }
6243 : :
6244 : : RTE_EXPORT_SYMBOL(rte_eth_remove_rx_callback)
6245 : : int
6246 : 1 : rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
6247 : : const struct rte_eth_rxtx_callback *user_cb)
6248 : : {
6249 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6250 : : return -ENOTSUP;
6251 : : #endif
6252 : : /* Check input parameters. */
6253 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6254 [ + - ]: 1 : if (user_cb == NULL ||
6255 [ + - ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
6256 : : return -EINVAL;
6257 : :
6258 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
6259 : : struct rte_eth_rxtx_callback *cb;
6260 : : RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
6261 : : int ret = -EINVAL;
6262 : :
6263 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6264 : 1 : prev_cb = &dev->post_rx_burst_cbs[queue_id];
6265 [ + - ]: 1 : for (; *prev_cb != NULL; prev_cb = &cb->next) {
6266 : : cb = *prev_cb;
6267 [ + - ]: 1 : if (cb == user_cb) {
6268 : : /* Remove the user cb from the callback list. */
6269 : 1 : rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
6270 : : ret = 0;
6271 : 1 : break;
6272 : : }
6273 : : }
6274 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6275 : :
6276 : 1 : rte_eth_trace_remove_rx_callback(port_id, queue_id, user_cb, ret);
6277 : :
6278 : 1 : return ret;
6279 : : }
6280 : :
6281 : : RTE_EXPORT_SYMBOL(rte_eth_remove_tx_callback)
6282 : : int
6283 : 1 : rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
6284 : : const struct rte_eth_rxtx_callback *user_cb)
6285 : : {
6286 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6287 : : return -ENOTSUP;
6288 : : #endif
6289 : : /* Check input parameters. */
6290 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6291 [ + - ]: 1 : if (user_cb == NULL ||
6292 [ + - ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
6293 : : return -EINVAL;
6294 : :
6295 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
6296 : : int ret = -EINVAL;
6297 : : struct rte_eth_rxtx_callback *cb;
6298 : : RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
6299 : :
6300 : : rte_spinlock_lock(ð_dev_tx_cb_lock);
6301 : 1 : prev_cb = &dev->pre_tx_burst_cbs[queue_id];
6302 [ + - ]: 1 : for (; *prev_cb != NULL; prev_cb = &cb->next) {
6303 : : cb = *prev_cb;
6304 [ + - ]: 1 : if (cb == user_cb) {
6305 : : /* Remove the user cb from the callback list. */
6306 : 1 : rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
6307 : : ret = 0;
6308 : 1 : break;
6309 : : }
6310 : : }
6311 : : rte_spinlock_unlock(ð_dev_tx_cb_lock);
6312 : :
6313 : 1 : rte_eth_trace_remove_tx_callback(port_id, queue_id, user_cb, ret);
6314 : :
6315 : 1 : return ret;
6316 : : }
6317 : :
6318 : : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_info_get)
6319 : : int
6320 : 1 : rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6321 : : struct rte_eth_rxq_info *qinfo)
6322 : : {
6323 : : struct rte_eth_dev *dev;
6324 : :
6325 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6326 : 1 : dev = &rte_eth_devices[port_id];
6327 : :
6328 [ - + ]: 1 : if (queue_id >= dev->data->nb_rx_queues) {
6329 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6330 : 0 : return -EINVAL;
6331 : : }
6332 : :
6333 [ - + ]: 1 : if (qinfo == NULL) {
6334 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL",
6335 : : port_id, queue_id);
6336 : 0 : return -EINVAL;
6337 : : }
6338 : :
6339 [ - + ]: 1 : if (dev->data->rx_queues == NULL ||
6340 [ # # ]: 0 : dev->data->rx_queues[queue_id] == NULL) {
6341 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
6342 : : "Rx queue %"PRIu16" of device with port_id=%"
6343 : : PRIu16" has not been setup",
6344 : : queue_id, port_id);
6345 : 1 : return -EINVAL;
6346 : : }
6347 : :
6348 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
6349 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
6350 : : "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16,
6351 : : queue_id, port_id);
6352 : 0 : return -EINVAL;
6353 : : }
6354 : :
6355 [ # # ]: 0 : if (dev->dev_ops->rxq_info_get == NULL)
6356 : : return -ENOTSUP;
6357 : :
6358 : : memset(qinfo, 0, sizeof(*qinfo));
6359 : 0 : dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
6360 [ # # ]: 0 : qinfo->queue_state = dev->data->rx_queue_state[queue_id];
6361 : :
6362 : 0 : rte_eth_trace_rx_queue_info_get(port_id, queue_id, qinfo);
6363 : :
6364 : 0 : return 0;
6365 : : }
6366 : :
6367 : : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_info_get)
6368 : : int
6369 : 1 : rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6370 : : struct rte_eth_txq_info *qinfo)
6371 : : {
6372 : : struct rte_eth_dev *dev;
6373 : :
6374 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6375 : 1 : dev = &rte_eth_devices[port_id];
6376 : :
6377 [ - + ]: 1 : if (queue_id >= dev->data->nb_tx_queues) {
6378 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
6379 : 0 : return -EINVAL;
6380 : : }
6381 : :
6382 [ - + ]: 1 : if (qinfo == NULL) {
6383 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL",
6384 : : port_id, queue_id);
6385 : 0 : return -EINVAL;
6386 : : }
6387 : :
6388 [ - + ]: 1 : if (dev->data->tx_queues == NULL ||
6389 [ # # ]: 0 : dev->data->tx_queues[queue_id] == NULL) {
6390 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
6391 : : "Tx queue %"PRIu16" of device with port_id=%"
6392 : : PRIu16" has not been setup",
6393 : : queue_id, port_id);
6394 : 1 : return -EINVAL;
6395 : : }
6396 : :
6397 [ # # ]: 0 : if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
6398 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
6399 : : "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16,
6400 : : queue_id, port_id);
6401 : 0 : return -EINVAL;
6402 : : }
6403 : :
6404 [ # # ]: 0 : if (dev->dev_ops->txq_info_get == NULL)
6405 : : return -ENOTSUP;
6406 : :
6407 : : memset(qinfo, 0, sizeof(*qinfo));
6408 : 0 : dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
6409 [ # # ]: 0 : qinfo->queue_state = dev->data->tx_queue_state[queue_id];
6410 : :
6411 : 0 : rte_eth_trace_tx_queue_info_get(port_id, queue_id, qinfo);
6412 : :
6413 : 0 : return 0;
6414 : : }
6415 : :
6416 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_recycle_rx_queue_info_get, 23.11)
6417 : : int
6418 : 0 : rte_eth_recycle_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6419 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
6420 : : {
6421 : : struct rte_eth_dev *dev;
6422 : : int ret;
6423 : :
6424 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6425 : 0 : dev = &rte_eth_devices[port_id];
6426 : :
6427 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6428 [ # # ]: 0 : if (unlikely(ret != 0))
6429 : : return ret;
6430 : :
6431 [ # # ]: 0 : if (dev->dev_ops->recycle_rxq_info_get == NULL)
6432 : : return -ENOTSUP;
6433 : :
6434 : 0 : dev->dev_ops->recycle_rxq_info_get(dev, queue_id, recycle_rxq_info);
6435 : :
6436 : 0 : return 0;
6437 : : }
6438 : :
6439 : : RTE_EXPORT_SYMBOL(rte_eth_rx_burst_mode_get)
6440 : : int
6441 : 0 : rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
6442 : : struct rte_eth_burst_mode *mode)
6443 : : {
6444 : : struct rte_eth_dev *dev;
6445 : : int ret;
6446 : :
6447 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6448 : 0 : dev = &rte_eth_devices[port_id];
6449 : :
6450 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6451 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6452 : 0 : return -EINVAL;
6453 : : }
6454 : :
6455 [ # # ]: 0 : if (mode == NULL) {
6456 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6457 : : "Cannot get ethdev port %u Rx queue %u burst mode to NULL",
6458 : : port_id, queue_id);
6459 : 0 : return -EINVAL;
6460 : : }
6461 : :
6462 [ # # ]: 0 : if (dev->dev_ops->rx_burst_mode_get == NULL)
6463 : : return -ENOTSUP;
6464 : : memset(mode, 0, sizeof(*mode));
6465 : 0 : ret = eth_err(port_id,
6466 : 0 : dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
6467 : :
6468 : 0 : rte_eth_trace_rx_burst_mode_get(port_id, queue_id, mode, ret);
6469 : :
6470 : 0 : return ret;
6471 : : }
6472 : :
6473 : : RTE_EXPORT_SYMBOL(rte_eth_tx_burst_mode_get)
6474 : : int
6475 : 0 : rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
6476 : : struct rte_eth_burst_mode *mode)
6477 : : {
6478 : : struct rte_eth_dev *dev;
6479 : : int ret;
6480 : :
6481 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6482 : 0 : dev = &rte_eth_devices[port_id];
6483 : :
6484 [ # # ]: 0 : if (queue_id >= dev->data->nb_tx_queues) {
6485 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
6486 : 0 : return -EINVAL;
6487 : : }
6488 : :
6489 [ # # ]: 0 : if (mode == NULL) {
6490 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6491 : : "Cannot get ethdev port %u Tx queue %u burst mode to NULL",
6492 : : port_id, queue_id);
6493 : 0 : return -EINVAL;
6494 : : }
6495 : :
6496 [ # # ]: 0 : if (dev->dev_ops->tx_burst_mode_get == NULL)
6497 : : return -ENOTSUP;
6498 : : memset(mode, 0, sizeof(*mode));
6499 : 0 : ret = eth_err(port_id,
6500 : 0 : dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
6501 : :
6502 : 0 : rte_eth_trace_tx_burst_mode_get(port_id, queue_id, mode, ret);
6503 : :
6504 : 0 : return ret;
6505 : : }
6506 : :
6507 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_get_monitor_addr, 21.02)
6508 : : int
6509 : 0 : rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
6510 : : struct rte_power_monitor_cond *pmc)
6511 : : {
6512 : : struct rte_eth_dev *dev;
6513 : : int ret;
6514 : :
6515 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6516 : : dev = &rte_eth_devices[port_id];
6517 : :
6518 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6519 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6520 : 0 : return -EINVAL;
6521 : : }
6522 : :
6523 [ # # ]: 0 : if (pmc == NULL) {
6524 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6525 : : "Cannot get ethdev port %u Rx queue %u power monitor condition to NULL",
6526 : : port_id, queue_id);
6527 : 0 : return -EINVAL;
6528 : : }
6529 : :
6530 [ # # ]: 0 : if (dev->dev_ops->get_monitor_addr == NULL)
6531 : : return -ENOTSUP;
6532 : 0 : ret = eth_err(port_id,
6533 : 0 : dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc));
6534 : :
6535 : 0 : rte_eth_trace_get_monitor_addr(port_id, queue_id, pmc, ret);
6536 : :
6537 : 0 : return ret;
6538 : : }
6539 : :
6540 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mc_addr_list)
6541 : : int
6542 : 2 : rte_eth_dev_set_mc_addr_list(uint16_t port_id,
6543 : : struct rte_ether_addr *mc_addr_set,
6544 : : uint32_t nb_mc_addr)
6545 : : {
6546 : : struct rte_eth_dev *dev;
6547 : : int ret;
6548 : :
6549 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6550 : 2 : dev = &rte_eth_devices[port_id];
6551 : :
6552 [ + - ]: 2 : if (dev->dev_ops->set_mc_addr_list == NULL)
6553 : : return -ENOTSUP;
6554 : 2 : ret = eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
6555 : : mc_addr_set, nb_mc_addr));
6556 : :
6557 : 2 : rte_ethdev_trace_set_mc_addr_list(port_id, mc_addr_set, nb_mc_addr,
6558 : : ret);
6559 : :
6560 : 2 : return ret;
6561 : : }
6562 : :
6563 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_enable)
6564 : : int
6565 : 0 : rte_eth_timesync_enable(uint16_t port_id)
6566 : : {
6567 : : struct rte_eth_dev *dev;
6568 : : int ret;
6569 : :
6570 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6571 : 0 : dev = &rte_eth_devices[port_id];
6572 : :
6573 [ # # ]: 0 : if (dev->dev_ops->timesync_enable == NULL)
6574 : : return -ENOTSUP;
6575 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_enable(dev));
6576 : :
6577 : 0 : rte_eth_trace_timesync_enable(port_id, ret);
6578 : :
6579 : 0 : return ret;
6580 : : }
6581 : :
6582 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_disable)
6583 : : int
6584 : 0 : rte_eth_timesync_disable(uint16_t port_id)
6585 : : {
6586 : : struct rte_eth_dev *dev;
6587 : : int ret;
6588 : :
6589 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6590 : 0 : dev = &rte_eth_devices[port_id];
6591 : :
6592 [ # # ]: 0 : if (dev->dev_ops->timesync_disable == NULL)
6593 : : return -ENOTSUP;
6594 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_disable(dev));
6595 : :
6596 : 0 : rte_eth_trace_timesync_disable(port_id, ret);
6597 : :
6598 : 0 : return ret;
6599 : : }
6600 : :
6601 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_rx_timestamp)
6602 : : int
6603 : 0 : rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
6604 : : uint32_t flags)
6605 : : {
6606 : : struct rte_eth_dev *dev;
6607 : : int ret;
6608 : :
6609 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6610 : 0 : dev = &rte_eth_devices[port_id];
6611 : :
6612 [ # # ]: 0 : if (timestamp == NULL) {
6613 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6614 : : "Cannot read ethdev port %u Rx timestamp to NULL",
6615 : : port_id);
6616 : 0 : return -EINVAL;
6617 : : }
6618 : :
6619 [ # # ]: 0 : if (dev->dev_ops->timesync_read_rx_timestamp == NULL)
6620 : : return -ENOTSUP;
6621 : :
6622 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_rx_timestamp(dev, timestamp, flags));
6623 : :
6624 : : rte_eth_trace_timesync_read_rx_timestamp(port_id, timestamp, flags,
6625 : : ret);
6626 : :
6627 : 0 : return ret;
6628 : : }
6629 : :
6630 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_tx_timestamp)
6631 : : int
6632 : 0 : rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
6633 : : struct timespec *timestamp)
6634 : : {
6635 : : struct rte_eth_dev *dev;
6636 : : int ret;
6637 : :
6638 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6639 : 0 : dev = &rte_eth_devices[port_id];
6640 : :
6641 [ # # ]: 0 : if (timestamp == NULL) {
6642 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6643 : : "Cannot read ethdev port %u Tx timestamp to NULL",
6644 : : port_id);
6645 : 0 : return -EINVAL;
6646 : : }
6647 : :
6648 [ # # ]: 0 : if (dev->dev_ops->timesync_read_tx_timestamp == NULL)
6649 : : return -ENOTSUP;
6650 : :
6651 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_tx_timestamp(dev, timestamp));
6652 : :
6653 : : rte_eth_trace_timesync_read_tx_timestamp(port_id, timestamp, ret);
6654 : :
6655 : 0 : return ret;
6656 : :
6657 : : }
6658 : :
6659 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_adjust_time)
6660 : : int
6661 : 0 : rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
6662 : : {
6663 : : struct rte_eth_dev *dev;
6664 : : int ret;
6665 : :
6666 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6667 : 0 : dev = &rte_eth_devices[port_id];
6668 : :
6669 [ # # ]: 0 : if (dev->dev_ops->timesync_adjust_time == NULL)
6670 : : return -ENOTSUP;
6671 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_adjust_time(dev, delta));
6672 : :
6673 : : rte_eth_trace_timesync_adjust_time(port_id, delta, ret);
6674 : :
6675 : 0 : return ret;
6676 : : }
6677 : :
6678 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_timesync_adjust_freq, 24.11)
6679 : : int
6680 : 0 : rte_eth_timesync_adjust_freq(uint16_t port_id, int64_t ppm)
6681 : : {
6682 : : struct rte_eth_dev *dev;
6683 : : int ret;
6684 : :
6685 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6686 : 0 : dev = &rte_eth_devices[port_id];
6687 : :
6688 [ # # ]: 0 : if (dev->dev_ops->timesync_adjust_freq == NULL)
6689 : : return -ENOTSUP;
6690 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_adjust_freq(dev, ppm));
6691 : :
6692 : : rte_eth_trace_timesync_adjust_freq(port_id, ppm, ret);
6693 : :
6694 : 0 : return ret;
6695 : : }
6696 : :
6697 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_time)
6698 : : int
6699 : 0 : rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
6700 : : {
6701 : : struct rte_eth_dev *dev;
6702 : : int ret;
6703 : :
6704 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6705 : 0 : dev = &rte_eth_devices[port_id];
6706 : :
6707 [ # # ]: 0 : if (timestamp == NULL) {
6708 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6709 : : "Cannot read ethdev port %u timesync time to NULL",
6710 : : port_id);
6711 : 0 : return -EINVAL;
6712 : : }
6713 : :
6714 [ # # ]: 0 : if (dev->dev_ops->timesync_read_time == NULL)
6715 : : return -ENOTSUP;
6716 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_time(dev, timestamp));
6717 : :
6718 : : rte_eth_trace_timesync_read_time(port_id, timestamp, ret);
6719 : :
6720 : 0 : return ret;
6721 : : }
6722 : :
6723 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_write_time)
6724 : : int
6725 : 0 : rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
6726 : : {
6727 : : struct rte_eth_dev *dev;
6728 : : int ret;
6729 : :
6730 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6731 : 0 : dev = &rte_eth_devices[port_id];
6732 : :
6733 [ # # ]: 0 : if (timestamp == NULL) {
6734 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6735 : : "Cannot write ethdev port %u timesync from NULL time",
6736 : : port_id);
6737 : 0 : return -EINVAL;
6738 : : }
6739 : :
6740 [ # # ]: 0 : if (dev->dev_ops->timesync_write_time == NULL)
6741 : : return -ENOTSUP;
6742 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_write_time(dev, timestamp));
6743 : :
6744 : 0 : rte_eth_trace_timesync_write_time(port_id, timestamp, ret);
6745 : :
6746 : 0 : return ret;
6747 : : }
6748 : :
6749 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_read_clock, 19.08)
6750 : : int
6751 : 0 : rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
6752 : : {
6753 : : struct rte_eth_dev *dev;
6754 : : int ret;
6755 : :
6756 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6757 : 0 : dev = &rte_eth_devices[port_id];
6758 : :
6759 [ # # ]: 0 : if (clock == NULL) {
6760 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot read ethdev port %u clock to NULL",
6761 : : port_id);
6762 : 0 : return -EINVAL;
6763 : : }
6764 : :
6765 [ # # ]: 0 : if (dev->dev_ops->read_clock == NULL)
6766 : : return -ENOTSUP;
6767 : 0 : ret = eth_err(port_id, dev->dev_ops->read_clock(dev, clock));
6768 : :
6769 : 0 : rte_eth_trace_read_clock(port_id, clock, ret);
6770 : :
6771 : 0 : return ret;
6772 : : }
6773 : :
6774 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_reg_info)
6775 : : int
6776 : 0 : rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
6777 : : {
6778 : 0 : struct rte_dev_reg_info reg_info = { 0 };
6779 : : int ret;
6780 : :
6781 [ # # ]: 0 : if (info == NULL) {
6782 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6783 : : "Cannot get ethdev port %u register info to NULL",
6784 : : port_id);
6785 : 0 : return -EINVAL;
6786 : : }
6787 : :
6788 : 0 : reg_info.length = info->length;
6789 : 0 : reg_info.width = info->width;
6790 : 0 : reg_info.offset = info->offset;
6791 : 0 : reg_info.data = info->data;
6792 : :
6793 : 0 : ret = rte_eth_dev_get_reg_info_ext(port_id, ®_info);
6794 [ # # ]: 0 : if (ret != 0)
6795 : : return ret;
6796 : :
6797 : 0 : info->length = reg_info.length;
6798 : 0 : info->width = reg_info.width;
6799 : 0 : info->version = reg_info.version;
6800 : 0 : info->offset = reg_info.offset;
6801 : :
6802 : 0 : return 0;
6803 : : }
6804 : :
6805 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_reg_info_ext, 24.11)
6806 : : int
6807 : 1 : rte_eth_dev_get_reg_info_ext(uint16_t port_id, struct rte_dev_reg_info *info)
6808 : : {
6809 : : struct rte_eth_dev *dev;
6810 : : uint32_t i;
6811 : : int ret;
6812 : :
6813 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6814 : 1 : dev = &rte_eth_devices[port_id];
6815 : :
6816 [ - + ]: 1 : if (info == NULL) {
6817 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6818 : : "Cannot get ethdev port %u register info to NULL",
6819 : : port_id);
6820 : 0 : return -EINVAL;
6821 : : }
6822 : :
6823 [ - + - - ]: 1 : if (info->names != NULL && info->length != 0)
6824 : 0 : memset(info->names, 0, sizeof(struct rte_eth_reg_name) * info->length);
6825 : :
6826 [ - + ]: 1 : if (dev->dev_ops->get_reg == NULL)
6827 : : return -ENOTSUP;
6828 : 0 : ret = eth_err(port_id, dev->dev_ops->get_reg(dev, info));
6829 : :
6830 : 0 : rte_ethdev_trace_get_reg_info(port_id, info, ret);
6831 : :
6832 : : /* Report the default names if drivers not report. */
6833 [ # # # # : 0 : if (ret == 0 && info->names != NULL && strlen(info->names[0].name) == 0) {
# # ]
6834 [ # # ]: 0 : for (i = 0; i < info->length; i++)
6835 : 0 : snprintf(info->names[i].name, RTE_ETH_REG_NAME_SIZE,
6836 : 0 : "index_%u", info->offset + i);
6837 : : }
6838 : : return ret;
6839 : : }
6840 : :
6841 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom_length)
6842 : : int
6843 : 0 : rte_eth_dev_get_eeprom_length(uint16_t port_id)
6844 : : {
6845 : : struct rte_eth_dev *dev;
6846 : : int ret;
6847 : :
6848 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6849 : 0 : dev = &rte_eth_devices[port_id];
6850 : :
6851 [ # # ]: 0 : if (dev->dev_ops->get_eeprom_length == NULL)
6852 : : return -ENOTSUP;
6853 : 0 : ret = eth_err(port_id, dev->dev_ops->get_eeprom_length(dev));
6854 : :
6855 : 0 : rte_ethdev_trace_get_eeprom_length(port_id, ret);
6856 : :
6857 : 0 : return ret;
6858 : : }
6859 : :
6860 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom)
6861 : : int
6862 : 0 : rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
6863 : : {
6864 : : struct rte_eth_dev *dev;
6865 : : int ret;
6866 : :
6867 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6868 : 0 : dev = &rte_eth_devices[port_id];
6869 : :
6870 [ # # ]: 0 : if (info == NULL) {
6871 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6872 : : "Cannot get ethdev port %u EEPROM info to NULL",
6873 : : port_id);
6874 : 0 : return -EINVAL;
6875 : : }
6876 : :
6877 [ # # ]: 0 : if (dev->dev_ops->get_eeprom == NULL)
6878 : : return -ENOTSUP;
6879 : 0 : ret = eth_err(port_id, dev->dev_ops->get_eeprom(dev, info));
6880 : :
6881 : 0 : rte_ethdev_trace_get_eeprom(port_id, info, ret);
6882 : :
6883 : 0 : return ret;
6884 : : }
6885 : :
6886 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_eeprom)
6887 : : int
6888 : 0 : rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
6889 : : {
6890 : : struct rte_eth_dev *dev;
6891 : : int ret;
6892 : :
6893 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6894 : 0 : dev = &rte_eth_devices[port_id];
6895 : :
6896 [ # # ]: 0 : if (info == NULL) {
6897 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6898 : : "Cannot set ethdev port %u EEPROM from NULL info",
6899 : : port_id);
6900 : 0 : return -EINVAL;
6901 : : }
6902 : :
6903 [ # # ]: 0 : if (dev->dev_ops->set_eeprom == NULL)
6904 : : return -ENOTSUP;
6905 : 0 : ret = eth_err(port_id, dev->dev_ops->set_eeprom(dev, info));
6906 : :
6907 : 0 : rte_ethdev_trace_set_eeprom(port_id, info, ret);
6908 : :
6909 : 0 : return ret;
6910 : : }
6911 : :
6912 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_module_info, 18.05)
6913 : : int
6914 : 1 : rte_eth_dev_get_module_info(uint16_t port_id,
6915 : : struct rte_eth_dev_module_info *modinfo)
6916 : : {
6917 : : struct rte_eth_dev *dev;
6918 : : int ret;
6919 : :
6920 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6921 : 1 : dev = &rte_eth_devices[port_id];
6922 : :
6923 [ - + ]: 1 : if (modinfo == NULL) {
6924 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6925 : : "Cannot get ethdev port %u EEPROM module info to NULL",
6926 : : port_id);
6927 : 0 : return -EINVAL;
6928 : : }
6929 : :
6930 [ - + ]: 1 : if (dev->dev_ops->get_module_info == NULL)
6931 : : return -ENOTSUP;
6932 : 0 : ret = dev->dev_ops->get_module_info(dev, modinfo);
6933 : :
6934 : 0 : rte_ethdev_trace_get_module_info(port_id, modinfo, ret);
6935 : :
6936 : 0 : return ret;
6937 : : }
6938 : :
6939 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_module_eeprom, 18.05)
6940 : : int
6941 : 0 : rte_eth_dev_get_module_eeprom(uint16_t port_id,
6942 : : struct rte_dev_eeprom_info *info)
6943 : : {
6944 : : struct rte_eth_dev *dev;
6945 : : int ret;
6946 : :
6947 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6948 : 0 : dev = &rte_eth_devices[port_id];
6949 : :
6950 [ # # ]: 0 : if (info == NULL) {
6951 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6952 : : "Cannot get ethdev port %u module EEPROM info to NULL",
6953 : : port_id);
6954 : 0 : return -EINVAL;
6955 : : }
6956 : :
6957 [ # # ]: 0 : if (info->data == NULL) {
6958 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6959 : : "Cannot get ethdev port %u module EEPROM data to NULL",
6960 : : port_id);
6961 : 0 : return -EINVAL;
6962 : : }
6963 : :
6964 [ # # ]: 0 : if (info->length == 0) {
6965 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6966 : : "Cannot get ethdev port %u module EEPROM to data with zero size",
6967 : : port_id);
6968 : 0 : return -EINVAL;
6969 : : }
6970 : :
6971 [ # # ]: 0 : if (dev->dev_ops->get_module_eeprom == NULL)
6972 : : return -ENOTSUP;
6973 : 0 : ret = dev->dev_ops->get_module_eeprom(dev, info);
6974 : :
6975 : 0 : rte_ethdev_trace_get_module_eeprom(port_id, info, ret);
6976 : :
6977 : 0 : return ret;
6978 : : }
6979 : :
6980 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_dcb_info)
6981 : : int
6982 : 1 : rte_eth_dev_get_dcb_info(uint16_t port_id,
6983 : : struct rte_eth_dcb_info *dcb_info)
6984 : : {
6985 : : struct rte_eth_dev *dev;
6986 : : int ret;
6987 : :
6988 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6989 : 1 : dev = &rte_eth_devices[port_id];
6990 : :
6991 [ - + ]: 1 : if (dcb_info == NULL) {
6992 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6993 : : "Cannot get ethdev port %u DCB info to NULL",
6994 : : port_id);
6995 : 0 : return -EINVAL;
6996 : : }
6997 : :
6998 : : memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
6999 : :
7000 [ - + ]: 1 : if (dev->dev_ops->get_dcb_info == NULL)
7001 : : return -ENOTSUP;
7002 : 0 : ret = eth_err(port_id, dev->dev_ops->get_dcb_info(dev, dcb_info));
7003 : :
7004 : 0 : rte_ethdev_trace_get_dcb_info(port_id, dcb_info, ret);
7005 : :
7006 : 0 : return ret;
7007 : : }
7008 : :
7009 : : static void
7010 : : eth_dev_adjust_nb_desc(uint16_t *nb_desc,
7011 : : const struct rte_eth_desc_lim *desc_lim)
7012 : : {
7013 : : /* Upcast to uint32 to avoid potential overflow with RTE_ALIGN_CEIL(). */
7014 : 0 : uint32_t nb_desc_32 = (uint32_t)*nb_desc;
7015 : :
7016 [ # # # # ]: 0 : if (desc_lim->nb_align != 0)
7017 : 0 : nb_desc_32 = RTE_ALIGN_CEIL(nb_desc_32, desc_lim->nb_align);
7018 : :
7019 [ # # # # ]: 0 : if (desc_lim->nb_max != 0)
7020 : 0 : nb_desc_32 = RTE_MIN(nb_desc_32, desc_lim->nb_max);
7021 : :
7022 : 0 : nb_desc_32 = RTE_MAX(nb_desc_32, desc_lim->nb_min);
7023 : :
7024 : : /* Assign clipped u32 back to u16. */
7025 : 0 : *nb_desc = (uint16_t)nb_desc_32;
7026 : 0 : }
7027 : :
7028 : : RTE_EXPORT_SYMBOL(rte_eth_dev_adjust_nb_rx_tx_desc)
7029 : : int
7030 : 0 : rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
7031 : : uint16_t *nb_rx_desc,
7032 : : uint16_t *nb_tx_desc)
7033 : : {
7034 : : struct rte_eth_dev_info dev_info;
7035 : : int ret;
7036 : :
7037 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7038 : :
7039 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
7040 [ # # ]: 0 : if (ret != 0)
7041 : : return ret;
7042 : :
7043 [ # # ]: 0 : if (nb_rx_desc != NULL)
7044 : : eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
7045 : :
7046 [ # # ]: 0 : if (nb_tx_desc != NULL)
7047 : : eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
7048 : :
7049 : 0 : rte_ethdev_trace_adjust_nb_rx_tx_desc(port_id);
7050 : :
7051 : 0 : return 0;
7052 : : }
7053 : :
7054 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_hairpin_capability_get, 19.11)
7055 : : int
7056 : 0 : rte_eth_dev_hairpin_capability_get(uint16_t port_id,
7057 : : struct rte_eth_hairpin_cap *cap)
7058 : : {
7059 : : struct rte_eth_dev *dev;
7060 : : int ret;
7061 : :
7062 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7063 : 0 : dev = &rte_eth_devices[port_id];
7064 : :
7065 [ # # ]: 0 : if (cap == NULL) {
7066 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7067 : : "Cannot get ethdev port %u hairpin capability to NULL",
7068 : : port_id);
7069 : 0 : return -EINVAL;
7070 : : }
7071 : :
7072 [ # # ]: 0 : if (dev->dev_ops->hairpin_cap_get == NULL)
7073 : : return -ENOTSUP;
7074 : : memset(cap, 0, sizeof(*cap));
7075 : 0 : ret = eth_err(port_id, dev->dev_ops->hairpin_cap_get(dev, cap));
7076 : :
7077 : 0 : rte_ethdev_trace_hairpin_capability_get(port_id, cap, ret);
7078 : :
7079 : 0 : return ret;
7080 : : }
7081 : :
7082 : : RTE_EXPORT_SYMBOL(rte_eth_dev_pool_ops_supported)
7083 : : int
7084 : 0 : rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
7085 : : {
7086 : : struct rte_eth_dev *dev;
7087 : : int ret;
7088 : :
7089 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7090 : 0 : dev = &rte_eth_devices[port_id];
7091 : :
7092 [ # # ]: 0 : if (pool == NULL) {
7093 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7094 : : "Cannot test ethdev port %u mempool operation from NULL pool",
7095 : : port_id);
7096 : 0 : return -EINVAL;
7097 : : }
7098 : :
7099 [ # # ]: 0 : if (dev->dev_ops->pool_ops_supported == NULL)
7100 : : return 1; /* all pools are supported */
7101 : :
7102 : 0 : ret = dev->dev_ops->pool_ops_supported(dev, pool);
7103 : :
7104 : 0 : rte_ethdev_trace_pool_ops_supported(port_id, pool, ret);
7105 : :
7106 : 0 : return ret;
7107 : : }
7108 : :
7109 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_representor_info_get, 21.05)
7110 : : int
7111 : 0 : rte_eth_representor_info_get(uint16_t port_id,
7112 : : struct rte_eth_representor_info *info)
7113 : : {
7114 : : struct rte_eth_dev *dev;
7115 : : int ret;
7116 : :
7117 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7118 : 0 : dev = &rte_eth_devices[port_id];
7119 : :
7120 [ # # ]: 0 : if (dev->dev_ops->representor_info_get == NULL)
7121 : : return -ENOTSUP;
7122 : 0 : ret = eth_err(port_id, dev->dev_ops->representor_info_get(dev, info));
7123 : :
7124 : 0 : rte_eth_trace_representor_info_get(port_id, info, ret);
7125 : :
7126 : 0 : return ret;
7127 : : }
7128 : :
7129 : : RTE_EXPORT_SYMBOL(rte_eth_rx_metadata_negotiate)
7130 : : int
7131 : 0 : rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
7132 : : {
7133 : : struct rte_eth_dev *dev;
7134 : : int ret;
7135 : :
7136 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7137 : 0 : dev = &rte_eth_devices[port_id];
7138 : :
7139 [ # # ]: 0 : if (dev->data->dev_configured != 0) {
7140 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7141 : : "The port (ID=%"PRIu16") is already configured",
7142 : : port_id);
7143 : 0 : return -EBUSY;
7144 : : }
7145 : :
7146 [ # # ]: 0 : if (features == NULL) {
7147 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid features (NULL)");
7148 : 0 : return -EINVAL;
7149 : : }
7150 : :
7151 [ # # # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
7152 : 0 : rte_flow_restore_info_dynflag_register() < 0)
7153 : 0 : *features &= ~RTE_ETH_RX_METADATA_TUNNEL_ID;
7154 : :
7155 [ # # ]: 0 : if (dev->dev_ops->rx_metadata_negotiate == NULL)
7156 : : return -ENOTSUP;
7157 : 0 : ret = eth_err(port_id,
7158 : : dev->dev_ops->rx_metadata_negotiate(dev, features));
7159 : :
7160 [ # # ]: 0 : rte_eth_trace_rx_metadata_negotiate(port_id, *features, ret);
7161 : :
7162 : 0 : return ret;
7163 : : }
7164 : :
7165 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_capability_get, 22.03)
7166 : : int
7167 : 0 : rte_eth_ip_reassembly_capability_get(uint16_t port_id,
7168 : : struct rte_eth_ip_reassembly_params *reassembly_capa)
7169 : : {
7170 : : struct rte_eth_dev *dev;
7171 : : int ret;
7172 : :
7173 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7174 : 0 : dev = &rte_eth_devices[port_id];
7175 : :
7176 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7177 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7178 : : "port_id=%u is not configured, cannot get IP reassembly capability",
7179 : : port_id);
7180 : 0 : return -EINVAL;
7181 : : }
7182 : :
7183 [ # # ]: 0 : if (reassembly_capa == NULL) {
7184 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly capability to NULL");
7185 : 0 : return -EINVAL;
7186 : : }
7187 : :
7188 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_capability_get == NULL)
7189 : : return -ENOTSUP;
7190 : : memset(reassembly_capa, 0, sizeof(struct rte_eth_ip_reassembly_params));
7191 : :
7192 : 0 : ret = eth_err(port_id,
7193 : 0 : dev->dev_ops->ip_reassembly_capability_get(dev, reassembly_capa));
7194 : :
7195 : 0 : rte_eth_trace_ip_reassembly_capability_get(port_id, reassembly_capa,
7196 : : ret);
7197 : :
7198 : 0 : return ret;
7199 : : }
7200 : :
7201 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_conf_get, 22.03)
7202 : : int
7203 : 0 : rte_eth_ip_reassembly_conf_get(uint16_t port_id,
7204 : : struct rte_eth_ip_reassembly_params *conf)
7205 : : {
7206 : : struct rte_eth_dev *dev;
7207 : : int ret;
7208 : :
7209 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7210 : 0 : dev = &rte_eth_devices[port_id];
7211 : :
7212 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7213 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7214 : : "port_id=%u is not configured, cannot get IP reassembly configuration",
7215 : : port_id);
7216 : 0 : return -EINVAL;
7217 : : }
7218 : :
7219 [ # # ]: 0 : if (conf == NULL) {
7220 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly info to NULL");
7221 : 0 : return -EINVAL;
7222 : : }
7223 : :
7224 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_conf_get == NULL)
7225 : : return -ENOTSUP;
7226 : : memset(conf, 0, sizeof(struct rte_eth_ip_reassembly_params));
7227 : 0 : ret = eth_err(port_id,
7228 : 0 : dev->dev_ops->ip_reassembly_conf_get(dev, conf));
7229 : :
7230 : 0 : rte_eth_trace_ip_reassembly_conf_get(port_id, conf, ret);
7231 : :
7232 : 0 : return ret;
7233 : : }
7234 : :
7235 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_conf_set, 22.03)
7236 : : int
7237 : 0 : rte_eth_ip_reassembly_conf_set(uint16_t port_id,
7238 : : const struct rte_eth_ip_reassembly_params *conf)
7239 : : {
7240 : : struct rte_eth_dev *dev;
7241 : : int ret;
7242 : :
7243 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7244 : 0 : dev = &rte_eth_devices[port_id];
7245 : :
7246 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7247 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7248 : : "port_id=%u is not configured, cannot set IP reassembly configuration",
7249 : : port_id);
7250 : 0 : return -EINVAL;
7251 : : }
7252 : :
7253 [ # # ]: 0 : if (dev->data->dev_started != 0) {
7254 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7255 : : "port_id=%u is started, cannot configure IP reassembly params.",
7256 : : port_id);
7257 : 0 : return -EINVAL;
7258 : : }
7259 : :
7260 [ # # ]: 0 : if (conf == NULL) {
7261 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7262 : : "Invalid IP reassembly configuration (NULL)");
7263 : 0 : return -EINVAL;
7264 : : }
7265 : :
7266 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_conf_set == NULL)
7267 : : return -ENOTSUP;
7268 : 0 : ret = eth_err(port_id,
7269 : : dev->dev_ops->ip_reassembly_conf_set(dev, conf));
7270 : :
7271 : 0 : rte_eth_trace_ip_reassembly_conf_set(port_id, conf, ret);
7272 : :
7273 : 0 : return ret;
7274 : : }
7275 : :
7276 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priv_dump, 22.03)
7277 : : int
7278 : 1 : rte_eth_dev_priv_dump(uint16_t port_id, FILE *file)
7279 : : {
7280 : : struct rte_eth_dev *dev;
7281 : :
7282 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7283 : 1 : dev = &rte_eth_devices[port_id];
7284 : :
7285 [ - + ]: 1 : if (file == NULL) {
7286 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7287 : 0 : return -EINVAL;
7288 : : }
7289 : :
7290 [ - + ]: 1 : if (dev->dev_ops->eth_dev_priv_dump == NULL)
7291 : : return -ENOTSUP;
7292 : 0 : return eth_err(port_id, dev->dev_ops->eth_dev_priv_dump(dev, file));
7293 : : }
7294 : :
7295 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_descriptor_dump, 22.11)
7296 : : int
7297 : 0 : rte_eth_rx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
7298 : : uint16_t offset, uint16_t num, FILE *file)
7299 : : {
7300 : : struct rte_eth_dev *dev;
7301 : :
7302 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7303 : 0 : dev = &rte_eth_devices[port_id];
7304 : :
7305 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
7306 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
7307 : 0 : return -EINVAL;
7308 : : }
7309 : :
7310 [ # # ]: 0 : if (file == NULL) {
7311 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7312 : 0 : return -EINVAL;
7313 : : }
7314 : :
7315 [ # # ]: 0 : if (dev->dev_ops->eth_rx_descriptor_dump == NULL)
7316 : : return -ENOTSUP;
7317 : :
7318 : 0 : return eth_err(port_id,
7319 : : dev->dev_ops->eth_rx_descriptor_dump(dev, queue_id, offset, num, file));
7320 : : }
7321 : :
7322 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_tx_descriptor_dump, 22.11)
7323 : : int
7324 : 0 : rte_eth_tx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
7325 : : uint16_t offset, uint16_t num, FILE *file)
7326 : : {
7327 : : struct rte_eth_dev *dev;
7328 : :
7329 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7330 : 0 : dev = &rte_eth_devices[port_id];
7331 : :
7332 [ # # ]: 0 : if (queue_id >= dev->data->nb_tx_queues) {
7333 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
7334 : 0 : return -EINVAL;
7335 : : }
7336 : :
7337 [ # # ]: 0 : if (file == NULL) {
7338 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7339 : 0 : return -EINVAL;
7340 : : }
7341 : :
7342 [ # # ]: 0 : if (dev->dev_ops->eth_tx_descriptor_dump == NULL)
7343 : : return -ENOTSUP;
7344 : :
7345 : 0 : return eth_err(port_id,
7346 : : dev->dev_ops->eth_tx_descriptor_dump(dev, queue_id, offset, num, file));
7347 : : }
7348 : :
7349 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_buffer_split_get_supported_hdr_ptypes, 22.11)
7350 : : int
7351 : 0 : rte_eth_buffer_split_get_supported_hdr_ptypes(uint16_t port_id, uint32_t *ptypes, int num)
7352 : : {
7353 : : size_t i;
7354 : : int j;
7355 : : struct rte_eth_dev *dev;
7356 : : const uint32_t *all_types;
7357 : 0 : size_t no_of_elements = 0;
7358 : :
7359 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7360 : 0 : dev = &rte_eth_devices[port_id];
7361 : :
7362 [ # # ]: 0 : if (ptypes == NULL && num > 0) {
7363 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7364 : : "Cannot get ethdev port %u supported header protocol types to NULL when array size is non zero",
7365 : : port_id);
7366 : 0 : return -EINVAL;
7367 : : }
7368 : :
7369 [ # # ]: 0 : if (dev->dev_ops->buffer_split_supported_hdr_ptypes_get == NULL)
7370 : : return -ENOTSUP;
7371 : 0 : all_types = dev->dev_ops->buffer_split_supported_hdr_ptypes_get(dev, &no_of_elements);
7372 : :
7373 [ # # ]: 0 : if (all_types == NULL)
7374 : : return 0;
7375 : :
7376 [ # # ]: 0 : for (i = 0, j = 0; i < no_of_elements; ++i) {
7377 [ # # ]: 0 : if (j < num) {
7378 [ # # ]: 0 : ptypes[j] = all_types[i];
7379 : :
7380 : 0 : rte_eth_trace_buffer_split_get_supported_hdr_ptypes(
7381 : : port_id, j, ptypes[j]);
7382 : : }
7383 : 0 : j++;
7384 : : }
7385 : :
7386 : : return j;
7387 : : }
7388 : :
7389 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_count_aggr_ports, 23.03)
7390 : 0 : int rte_eth_dev_count_aggr_ports(uint16_t port_id)
7391 : : {
7392 : : struct rte_eth_dev *dev;
7393 : : int ret;
7394 : :
7395 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7396 : 0 : dev = &rte_eth_devices[port_id];
7397 : :
7398 [ # # ]: 0 : if (dev->dev_ops->count_aggr_ports == NULL)
7399 : : return 0;
7400 : 0 : ret = eth_err(port_id, dev->dev_ops->count_aggr_ports(dev));
7401 : :
7402 : 0 : rte_eth_trace_count_aggr_ports(port_id, ret);
7403 : :
7404 : 0 : return ret;
7405 : : }
7406 : :
7407 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_map_aggr_tx_affinity, 23.03)
7408 : 0 : int rte_eth_dev_map_aggr_tx_affinity(uint16_t port_id, uint16_t tx_queue_id,
7409 : : uint8_t affinity)
7410 : : {
7411 : : struct rte_eth_dev *dev;
7412 : : int aggr_ports;
7413 : : int ret;
7414 : :
7415 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7416 : 0 : dev = &rte_eth_devices[port_id];
7417 : :
7418 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
7419 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
7420 : 0 : return -EINVAL;
7421 : : }
7422 : :
7423 [ # # ]: 0 : if (dev->dev_ops->map_aggr_tx_affinity == NULL)
7424 : : return -ENOTSUP;
7425 : :
7426 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7427 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7428 : : "Port %u must be configured before Tx affinity mapping",
7429 : : port_id);
7430 : 0 : return -EINVAL;
7431 : : }
7432 : :
7433 [ # # ]: 0 : if (dev->data->dev_started) {
7434 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7435 : : "Port %u must be stopped to allow configuration",
7436 : : port_id);
7437 : 0 : return -EBUSY;
7438 : : }
7439 : :
7440 : 0 : aggr_ports = rte_eth_dev_count_aggr_ports(port_id);
7441 [ # # ]: 0 : if (aggr_ports == 0) {
7442 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7443 : : "Port %u has no aggregated port",
7444 : : port_id);
7445 : 0 : return -ENOTSUP;
7446 : : }
7447 : :
7448 [ # # ]: 0 : if (affinity > aggr_ports) {
7449 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7450 : : "Port %u map invalid affinity %u exceeds the maximum number %u",
7451 : : port_id, affinity, aggr_ports);
7452 : 0 : return -EINVAL;
7453 : : }
7454 : :
7455 : 0 : ret = eth_err(port_id,
7456 : 0 : dev->dev_ops->map_aggr_tx_affinity(dev, tx_queue_id, affinity));
7457 : :
7458 : 0 : rte_eth_trace_map_aggr_tx_affinity(port_id, tx_queue_id, affinity, ret);
7459 : :
7460 : 0 : return ret;
7461 : : }
7462 : :
7463 : : RTE_EXPORT_SYMBOL(rte_eth_dev_logtype)
7464 [ - + ]: 276 : RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
|