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 : 12591 : rte_eth_find_next(uint16_t port_id)
359 : : {
360 [ + + ]: 138324 : while (port_id < RTE_MAX_ETHPORTS &&
361 [ + + ]: 134133 : rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)
362 : 125733 : port_id++;
363 : :
364 [ + + ]: 12591 : if (port_id >= RTE_MAX_ETHPORTS)
365 : : return RTE_MAX_ETHPORTS;
366 : :
367 : 8400 : rte_eth_trace_find_next(port_id);
368 : :
369 : 8400 : 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 : 479 : rte_eth_dev_is_valid_port(uint16_t port_id)
419 : : {
420 : : int is_valid;
421 : :
422 [ + + ]: 479 : if (port_id >= RTE_MAX_ETHPORTS ||
423 [ + + ]: 477 : (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED))
424 : : is_valid = 0;
425 : : else
426 : : is_valid = 1;
427 : :
428 : 479 : rte_ethdev_trace_is_valid_port(port_id, is_valid);
429 : :
430 : 479 : 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 : 12561 : rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id)
446 : : {
447 : 12561 : port_id = rte_eth_find_next(port_id);
448 [ + + ]: 12561 : while (port_id < RTE_MAX_ETHPORTS &&
449 [ - + ]: 8373 : rte_eth_devices[port_id].data->owner.id != owner_id)
450 : 0 : port_id = rte_eth_find_next(port_id + 1);
451 : :
452 : 12561 : rte_eth_trace_find_next_owned_by(port_id, owner_id);
453 : :
454 : 12561 : 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 : 2 : rte_eth_dev_get_name_by_port(uint16_t port_id, char *name)
727 : : {
728 : : char *tmp;
729 : :
730 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
731 : :
732 [ - + ]: 2 : 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 : 2 : 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 : 2 : tmp = eth_dev_shared_data->data[port_id].name;
742 : 2 : rte_spinlock_unlock(rte_mcfg_ethdev_get_lock());
743 : :
744 : : strcpy(name, tmp);
745 : :
746 : 2 : rte_ethdev_trace_get_name_by_port(port_id, name);
747 : :
748 : 2 : 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 : 119 : eth_err(uint16_t port_id, int ret)
786 : : {
787 [ - + ]: 119 : if (ret == 0)
788 : : return 0;
789 [ # # ]: 0 : if (rte_eth_dev_is_removed(port_id))
790 : 0 : return -EIO;
791 : : return ret;
792 : : }
793 : :
794 : : static int
795 : 0 : eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id)
796 : : {
797 : : uint16_t port_id;
798 : :
799 [ # # ]: 0 : 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 [ # # ]: 0 : 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 : 0 : eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id)
820 : : {
821 : : uint16_t port_id;
822 : :
823 [ # # ]: 0 : 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 [ # # ]: 0 : 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 : 0 : 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 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
874 : 0 : dev = &rte_eth_devices[port_id];
875 : :
876 [ # # ]: 0 : 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 : 0 : ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
884 [ # # ]: 0 : if (ret != 0)
885 : : return ret;
886 : :
887 [ # # ]: 0 : if (dev->dev_ops->rx_queue_start == NULL)
888 : : return -ENOTSUP;
889 : :
890 [ # # ]: 0 : 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 [ # # ]: 0 : 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 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_start(dev, rx_queue_id));
905 : :
906 : 0 : rte_ethdev_trace_rx_queue_start(port_id, rx_queue_id, ret);
907 : :
908 : 0 : return ret;
909 : : }
910 : :
911 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_queue_stop)
912 : : int
913 : 0 : 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 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
919 : 0 : dev = &rte_eth_devices[port_id];
920 : :
921 : 0 : ret = eth_dev_validate_rx_queue(dev, rx_queue_id);
922 [ # # ]: 0 : if (ret != 0)
923 : : return ret;
924 : :
925 [ # # ]: 0 : if (dev->dev_ops->rx_queue_stop == NULL)
926 : : return -ENOTSUP;
927 : :
928 [ # # ]: 0 : 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 [ # # ]: 0 : 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 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id));
943 : :
944 : 0 : rte_ethdev_trace_rx_queue_stop(port_id, rx_queue_id, ret);
945 : :
946 : 0 : return ret;
947 : : }
948 : :
949 : : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_queue_start)
950 : : int
951 : 0 : 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 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
957 : 0 : dev = &rte_eth_devices[port_id];
958 : :
959 [ # # ]: 0 : 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 : 0 : ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
967 [ # # ]: 0 : if (ret != 0)
968 : : return ret;
969 : :
970 [ # # ]: 0 : if (dev->dev_ops->tx_queue_start == NULL)
971 : : return -ENOTSUP;
972 : :
973 [ # # ]: 0 : 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 [ # # ]: 0 : 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 : 0 : ret = eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id));
988 : :
989 : 0 : rte_ethdev_trace_tx_queue_start(port_id, tx_queue_id, ret);
990 : :
991 : 0 : return ret;
992 : : }
993 : :
994 : : RTE_EXPORT_SYMBOL(rte_eth_dev_tx_queue_stop)
995 : : int
996 : 0 : 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 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1002 : 0 : dev = &rte_eth_devices[port_id];
1003 : :
1004 : 0 : ret = eth_dev_validate_tx_queue(dev, tx_queue_id);
1005 [ # # ]: 0 : if (ret != 0)
1006 : : return ret;
1007 : :
1008 [ # # ]: 0 : if (dev->dev_ops->tx_queue_stop == NULL)
1009 : : return -ENOTSUP;
1010 : :
1011 [ # # ]: 0 : 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 [ # # ]: 0 : 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 : 0 : ret = eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id));
1026 : :
1027 : 0 : rte_ethdev_trace_tx_queue_stop(port_id, tx_queue_id, ret);
1028 : :
1029 : 0 : 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 : 30 : 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 : 30 : uint64_t offloads_diff = req_offloads ^ set_offloads;
1244 : : uint64_t offload;
1245 : : int ret = 0;
1246 : :
1247 [ - + ]: 30 : 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 : 30 : 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 : 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : overhead_len = eth_dev_get_overhead_len(dev_info->max_rx_pktlen,
1305 : : dev_info->max_mtu);
1306 : 15 : frame_size = mtu + overhead_len;
1307 [ - + ]: 15 : 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 [ - + ]: 15 : 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 : 15 : 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 [ - + ]: 15 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1338 : 15 : dev = &rte_eth_devices[port_id];
1339 : :
1340 [ - + ]: 15 : 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 [ + - ]: 15 : if (dev->dev_ops->dev_configure == NULL)
1348 : : return -ENOTSUP;
1349 : :
1350 [ - + ]: 15 : 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 : 15 : dev->data->dev_configured = 0;
1363 : :
1364 : : /* Store original config, as rollback required on failure */
1365 [ + - ]: 15 : 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 [ + - ]: 15 : 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 : 15 : old_mtu = dev->data->mtu;
1377 : :
1378 : : /* fields must be zero to reserve them for future ABI changes */
1379 [ + - ]: 15 : if (dev_conf->rxmode.reserved_64s[0] != 0 ||
1380 [ + - ]: 15 : dev_conf->rxmode.reserved_64s[1] != 0 ||
1381 [ + - ]: 15 : dev_conf->rxmode.reserved_ptrs[0] != NULL ||
1382 [ - + ]: 15 : 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 [ + - ]: 15 : if (dev_conf->txmode.reserved_64s[0] != 0 ||
1389 [ + - ]: 15 : dev_conf->txmode.reserved_64s[1] != 0 ||
1390 [ + - ]: 15 : dev_conf->txmode.reserved_ptrs[0] != NULL ||
1391 [ - + ]: 15 : 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 : 15 : ret = rte_eth_dev_info_get(port_id, &dev_info);
1398 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ + - ]: 15 : if (dev_conf->rxmode.mtu == 0)
1468 : 15 : dev->data->dev_conf.rxmode.mtu =
1469 [ + - ]: 15 : (dev_info.max_mtu == 0) ? RTE_ETHER_MTU :
1470 : 15 : RTE_MIN(dev_info.max_mtu, RTE_ETHER_MTU);
1471 : :
1472 : 15 : ret = eth_dev_validate_mtu(port_id, &dev_info,
1473 : 15 : dev->data->dev_conf.rxmode.mtu);
1474 [ - + ]: 15 : if (ret != 0)
1475 : 0 : goto rollback;
1476 : :
1477 : 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 [ - + ]: 15 : 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 : 30 : dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf =
1538 [ - + ]: 15 : 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 : 15 : if ((dev_info.flow_type_rss_offloads |
1542 [ - + ]: 15 : 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 [ + - ]: 15 : if (((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) == 0) &&
1554 [ - + ]: 15 : (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 [ - + ]: 15 : 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 : 15 : algorithm = dev_conf->rx_adv_conf.rss_conf.algorithm;
1574 [ + - ]: 15 : if ((size_t)algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
1575 [ - + ]: 15 : (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 : 15 : diag = eth_dev_rx_queue_config(dev, nb_rx_q);
1588 [ - + ]: 15 : 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 : 15 : diag = eth_dev_tx_queue_config(dev, nb_tx_q);
1597 [ - + ]: 15 : 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 : 15 : diag = dev->dev_ops->dev_configure(dev);
1607 [ - + ]: 15 : 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 : 15 : diag = __rte_eth_dev_profile_init(port_id, dev);
1616 [ - + ]: 15 : 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 : 15 : diag = eth_dev_validate_offloads(port_id,
1625 : 15 : dev_conf->rxmode.offloads,
1626 : 15 : dev->data->dev_conf.rxmode.offloads, "Rx",
1627 : : rte_eth_dev_rx_offload_name);
1628 [ - + ]: 15 : if (diag != 0) {
1629 : : ret = diag;
1630 : 0 : goto reset_queues;
1631 : : }
1632 : :
1633 : : /* Validate Tx offloads. */
1634 : 15 : diag = eth_dev_validate_offloads(port_id,
1635 : 15 : dev_conf->txmode.offloads,
1636 : 15 : dev->data->dev_conf.txmode.offloads, "Tx",
1637 : : rte_eth_dev_tx_offload_name);
1638 [ - + ]: 15 : if (diag != 0) {
1639 : : ret = diag;
1640 : 0 : goto reset_queues;
1641 : : }
1642 : :
1643 [ - + ]: 15 : dev->data->dev_configured = 1;
1644 : 15 : rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0);
1645 : 15 : 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 : 10 : 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 : 10 : addr = &dev->data->mac_addrs[0];
1669 [ - + ]: 10 : if (dev->dev_ops->mac_addr_set != NULL)
1670 : 0 : 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 [ + - ]: 10 : if (dev->dev_ops->mac_addr_add != NULL) {
1675 [ - + ]: 10 : for (i = 1; i < dev_info->max_mac_addrs; i++) {
1676 [ # # ]: 0 : addr = &dev->data->mac_addrs[i];
1677 : :
1678 : : /* skip zero address */
1679 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr))
1680 : 0 : 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 : 10 : }
1694 : :
1695 : : static int
1696 : 10 : 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 [ + - ]: 10 : 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 [ # # ]: 0 : } else if (rte_eth_promiscuous_get(port_id) == 0 &&
1715 [ # # ]: 0 : dev->dev_ops->promiscuous_disable != NULL) {
1716 : 0 : ret = eth_err(port_id, dev->dev_ops->promiscuous_disable(dev));
1717 [ # # ]: 0 : 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 : 10 : 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 [ + - ]: 10 : 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 [ # # ]: 0 : } else if (rte_eth_allmulticast_get(port_id) == 0 &&
1748 [ # # ]: 0 : dev->dev_ops->allmulticast_disable != NULL) {
1749 : 0 : ret = eth_err(port_id, dev->dev_ops->allmulticast_disable(dev));
1750 [ # # ]: 0 : 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 : 10 : 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 [ + - ]: 10 : if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) &&
1770 [ + - ]: 10 : (restore_flags & RTE_ETH_RESTORE_MAC_ADDR))
1771 : 10 : eth_dev_mac_restore(dev, dev_info);
1772 : :
1773 [ + - ]: 10 : if (restore_flags & RTE_ETH_RESTORE_PROMISC) {
1774 : 10 : ret = eth_dev_promiscuous_restore(dev, port_id);
1775 [ + - ]: 10 : if (ret != 0)
1776 : : return ret;
1777 : : }
1778 : :
1779 [ + - ]: 10 : if (restore_flags & RTE_ETH_RESTORE_ALLMULTI) {
1780 : 10 : ret = eth_dev_allmulticast_restore(dev, port_id);
1781 [ - + ]: 10 : 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 : 10 : 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 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1799 : 10 : dev = &rte_eth_devices[port_id];
1800 : :
1801 [ + - ]: 10 : if (dev->dev_ops->dev_start == NULL)
1802 : : return -ENOTSUP;
1803 : :
1804 [ - + ]: 10 : 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 [ - + ]: 10 : 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 : 10 : ret = rte_eth_dev_info_get(port_id, &dev_info);
1819 [ + - ]: 10 : if (ret != 0)
1820 : : return ret;
1821 : :
1822 : 10 : 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 [ - + ]: 10 : 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 : 10 : diag = dev->dev_ops->dev_start(dev);
1830 [ + - ]: 10 : if (diag == 0)
1831 : 10 : dev->data->dev_started = 1;
1832 : : else
1833 : 0 : return eth_err(port_id, diag);
1834 : :
1835 : 10 : ret = eth_dev_config_restore(dev, &dev_info, restore_flags, port_id);
1836 [ - + ]: 10 : 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 [ + - ]: 10 : if (dev->data->dev_conf.intr_conf.lsc == 0) {
1851 [ + - ]: 10 : if (dev->dev_ops->link_update == NULL)
1852 : : return -ENOTSUP;
1853 : 10 : dev->dev_ops->link_update(dev, 0);
1854 : : }
1855 : :
1856 : : /* expose selection of PMD fast-path functions */
1857 : 10 : eth_dev_fp_ops_setup(rte_eth_fp_ops + port_id, dev);
1858 : :
1859 : 10 : rte_ethdev_trace_start(port_id);
1860 : 10 : return 0;
1861 : : }
1862 : :
1863 : : RTE_EXPORT_SYMBOL(rte_eth_dev_stop)
1864 : : int
1865 : 10 : rte_eth_dev_stop(uint16_t port_id)
1866 : : {
1867 : : struct rte_eth_dev *dev;
1868 : : int ret;
1869 : :
1870 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1871 : 10 : dev = &rte_eth_devices[port_id];
1872 : :
1873 [ + - ]: 10 : if (dev->dev_ops->dev_stop == NULL)
1874 : : return -ENOTSUP;
1875 : :
1876 [ - + ]: 10 : 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 : 10 : eth_dev_fp_ops_reset(rte_eth_fp_ops + port_id);
1885 : :
1886 : 10 : ret = dev->dev_ops->dev_stop(dev);
1887 [ + - ]: 10 : if (ret == 0)
1888 : 10 : dev->data->dev_started = 0;
1889 : 10 : rte_ethdev_trace_stop(port_id, ret);
1890 : :
1891 : 10 : return ret;
1892 : : }
1893 : :
1894 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_link_up)
1895 : : int
1896 : 0 : rte_eth_dev_set_link_up(uint16_t port_id)
1897 : : {
1898 : : struct rte_eth_dev *dev;
1899 : : int ret;
1900 : :
1901 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1902 : 0 : dev = &rte_eth_devices[port_id];
1903 : :
1904 [ # # ]: 0 : if (dev->dev_ops->dev_set_link_up == NULL)
1905 : : return -ENOTSUP;
1906 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_set_link_up(dev));
1907 : :
1908 : 0 : rte_ethdev_trace_set_link_up(port_id, ret);
1909 : :
1910 : 0 : return ret;
1911 : : }
1912 : :
1913 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_link_down)
1914 : : int
1915 : 0 : rte_eth_dev_set_link_down(uint16_t port_id)
1916 : : {
1917 : : struct rte_eth_dev *dev;
1918 : : int ret;
1919 : :
1920 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1921 : 0 : dev = &rte_eth_devices[port_id];
1922 : :
1923 [ # # ]: 0 : if (dev->dev_ops->dev_set_link_down == NULL)
1924 : : return -ENOTSUP;
1925 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_set_link_down(dev));
1926 : :
1927 : 0 : rte_ethdev_trace_set_link_down(port_id, ret);
1928 : :
1929 : 0 : 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 : 0 : 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 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
1996 : 0 : 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 [ # # ]: 0 : if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
2004 [ # # ]: 0 : 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 [ # # ]: 0 : if (dev->dev_ops->dev_close == NULL)
2011 : : return -ENOTSUP;
2012 : 0 : *lasterr = dev->dev_ops->dev_close(dev);
2013 [ # # ]: 0 : if (*lasterr != 0)
2014 : : lasterr = &binerr;
2015 : :
2016 : 0 : rte_ethdev_trace_close(port_id);
2017 : 0 : *lasterr = rte_eth_dev_release_port(dev);
2018 : :
2019 : 0 : 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 : 0 : rte_eth_dev_is_removed(uint16_t port_id)
2051 : : {
2052 : : struct rte_eth_dev *dev;
2053 : : int ret;
2054 : :
2055 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0);
2056 : 0 : dev = &rte_eth_devices[port_id];
2057 : :
2058 [ # # ]: 0 : if (dev->state == RTE_ETH_DEV_REMOVED)
2059 : : return 1;
2060 : :
2061 [ # # ]: 0 : 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 : 40 : 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 [ - + ]: 40 : 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 [ - + ]: 40 : 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 : 40 : 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 : 40 : 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 [ - + ]: 40 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2292 : 40 : dev = &rte_eth_devices[port_id];
2293 : :
2294 [ - + ]: 40 : if (rx_queue_id >= dev->data->nb_rx_queues) {
2295 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", rx_queue_id);
2296 : 0 : return -EINVAL;
2297 : : }
2298 : :
2299 [ + - ]: 40 : if (dev->dev_ops->rx_queue_setup == NULL)
2300 : : return -ENOTSUP;
2301 : :
2302 [ - + ]: 40 : 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 : 40 : ret = rte_eth_dev_info_get(port_id, &dev_info);
2312 [ + - ]: 40 : if (ret != 0)
2313 : : return ret;
2314 : :
2315 : 40 : rx_offloads = dev->data->dev_conf.rxmode.offloads;
2316 [ - + ]: 40 : if (rx_conf != NULL)
2317 : 0 : rx_offloads |= rx_conf->offloads;
2318 : :
2319 : : /* Deferred start requires that device supports queue start */
2320 [ - + - - ]: 40 : 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 : 120 : if ((mp != NULL) +
2329 [ - + - - : 80 : (rx_conf != NULL && rx_conf->rx_nseg > 0) +
- + ]
2330 [ - + - - ]: 40 : (rx_conf != NULL && rx_conf->rx_nmempool > 0) != 1) {
2331 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2332 : : "Ambiguous Rx mempools configuration");
2333 : 0 : return -EINVAL;
2334 : : }
2335 : :
2336 [ + - ]: 40 : if (mp != NULL) {
2337 : : /* Single pool configuration check. */
2338 : 40 : ret = rte_eth_check_rx_mempool(mp, RTE_PKTMBUF_HEADROOM,
2339 : 40 : dev_info.min_rx_bufsize);
2340 [ + - ]: 40 : if (ret != 0)
2341 : : return ret;
2342 : :
2343 : 40 : mbp_buf_size = rte_pktmbuf_data_room_size(mp);
2344 : 40 : buf_data_size = mbp_buf_size - RTE_PKTMBUF_HEADROOM;
2345 [ - + ]: 40 : 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 [ - + ]: 40 : 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 [ + - ]: 40 : if (nb_rx_desc > dev_info.rx_desc_lim.nb_max ||
2401 [ + - ]: 40 : nb_rx_desc < dev_info.rx_desc_lim.nb_min ||
2402 [ - + ]: 40 : 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 [ - + ]: 40 : 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 [ - + ]: 40 : 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 : 40 : eth_dev_rxq_release(dev, rx_queue_id);
2423 : :
2424 [ + - ]: 40 : if (rx_conf == NULL)
2425 : : rx_conf = &dev_info.default_rxconf;
2426 : :
2427 : 40 : 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 : 40 : 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 [ - + ]: 40 : 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 [ - + ]: 40 : 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 [ - + ]: 40 : 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 : 40 : ret = dev->dev_ops->rx_queue_setup(dev, rx_queue_id, nb_rx_desc,
2489 : : socket_id, &local_conf, mp);
2490 [ + - ]: 40 : if (!ret) {
2491 [ + + ]: 40 : if (!dev->data->min_rx_buf_size ||
2492 [ - + ]: 30 : dev->data->min_rx_buf_size > mbp_buf_size)
2493 : 10 : dev->data->min_rx_buf_size = mbp_buf_size;
2494 : : }
2495 : :
2496 : 40 : rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp,
2497 : : rx_conf, ret);
2498 : 40 : 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 : 40 : 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 [ - + ]: 40 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2619 : 40 : dev = &rte_eth_devices[port_id];
2620 : :
2621 [ - + ]: 40 : 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 [ + - ]: 40 : if (dev->dev_ops->tx_queue_setup == NULL)
2627 : : return -ENOTSUP;
2628 : :
2629 [ - + ]: 40 : 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 [ - + - - ]: 40 : 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 : 40 : ret = rte_eth_dev_info_get(port_id, &dev_info);
2647 [ + - ]: 40 : if (ret != 0)
2648 : : return ret;
2649 : :
2650 : : /* Use default specified by driver, if nb_tx_desc is zero */
2651 [ - + ]: 40 : 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 [ + - ]: 40 : if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
2658 [ + - ]: 40 : nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
2659 [ - + ]: 40 : 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 [ - + ]: 40 : 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 [ - + ]: 40 : 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 : 40 : eth_dev_txq_release(dev, tx_queue_id);
2679 : :
2680 [ + - ]: 40 : if (tx_conf == NULL)
2681 : : tx_conf = &dev_info.default_txconf;
2682 : :
2683 : 40 : 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 : 40 : 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 [ - + ]: 40 : 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 [ - + ]: 40 : rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf);
2715 : 40 : 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 : 2 : rte_eth_promiscuous_enable(uint16_t port_id)
3009 : : {
3010 : : struct rte_eth_dev *dev;
3011 : : int diag = 0;
3012 : :
3013 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3014 : 2 : dev = &rte_eth_devices[port_id];
3015 : :
3016 [ - + ]: 2 : if (dev->data->promiscuous == 1)
3017 : : return 0;
3018 : :
3019 [ # # ]: 0 : if (dev->dev_ops->promiscuous_enable == NULL)
3020 : : return -ENOTSUP;
3021 : :
3022 : 0 : diag = dev->dev_ops->promiscuous_enable(dev);
3023 [ # # ]: 0 : if (diag == 0)
3024 : 0 : dev->data->promiscuous = 1;
3025 : :
3026 : 0 : diag = eth_err(port_id, diag);
3027 : :
3028 [ # # ]: 0 : rte_eth_trace_promiscuous_enable(port_id, dev->data->promiscuous,
3029 : : diag);
3030 : :
3031 : 0 : return diag;
3032 : : }
3033 : :
3034 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_disable)
3035 : : int
3036 : 0 : rte_eth_promiscuous_disable(uint16_t port_id)
3037 : : {
3038 : : struct rte_eth_dev *dev;
3039 : : int diag = 0;
3040 : :
3041 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3042 : 0 : dev = &rte_eth_devices[port_id];
3043 : :
3044 [ # # ]: 0 : if (dev->data->promiscuous == 0)
3045 : : return 0;
3046 : :
3047 [ # # ]: 0 : if (dev->dev_ops->promiscuous_disable == NULL)
3048 : : return -ENOTSUP;
3049 : :
3050 : 0 : diag = dev->dev_ops->promiscuous_disable(dev);
3051 [ # # ]: 0 : if (diag == 0)
3052 : 0 : dev->data->promiscuous = 0;
3053 : :
3054 : 0 : diag = eth_err(port_id, diag);
3055 : :
3056 [ # # ]: 0 : rte_eth_trace_promiscuous_disable(port_id, dev->data->promiscuous,
3057 : : diag);
3058 : :
3059 : 0 : return diag;
3060 : : }
3061 : :
3062 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_get)
3063 : : int
3064 : 10 : rte_eth_promiscuous_get(uint16_t port_id)
3065 : : {
3066 : : struct rte_eth_dev *dev;
3067 : :
3068 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3069 : : dev = &rte_eth_devices[port_id];
3070 : :
3071 [ - + ]: 10 : rte_eth_trace_promiscuous_get(port_id, dev->data->promiscuous);
3072 : :
3073 : 10 : return dev->data->promiscuous;
3074 : : }
3075 : :
3076 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_enable)
3077 : : int
3078 : 0 : rte_eth_allmulticast_enable(uint16_t port_id)
3079 : : {
3080 : : struct rte_eth_dev *dev;
3081 : : int diag;
3082 : :
3083 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3084 : 0 : dev = &rte_eth_devices[port_id];
3085 : :
3086 [ # # ]: 0 : if (dev->data->all_multicast == 1)
3087 : : return 0;
3088 : :
3089 [ # # ]: 0 : if (dev->dev_ops->allmulticast_enable == NULL)
3090 : : return -ENOTSUP;
3091 : 0 : diag = dev->dev_ops->allmulticast_enable(dev);
3092 [ # # ]: 0 : if (diag == 0)
3093 : 0 : dev->data->all_multicast = 1;
3094 : :
3095 : 0 : diag = eth_err(port_id, diag);
3096 : :
3097 [ # # ]: 0 : rte_eth_trace_allmulticast_enable(port_id, dev->data->all_multicast,
3098 : : diag);
3099 : :
3100 : 0 : return diag;
3101 : : }
3102 : :
3103 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_disable)
3104 : : int
3105 : 0 : rte_eth_allmulticast_disable(uint16_t port_id)
3106 : : {
3107 : : struct rte_eth_dev *dev;
3108 : : int diag;
3109 : :
3110 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3111 : 0 : dev = &rte_eth_devices[port_id];
3112 : :
3113 [ # # ]: 0 : if (dev->data->all_multicast == 0)
3114 : : return 0;
3115 : :
3116 [ # # ]: 0 : if (dev->dev_ops->allmulticast_disable == NULL)
3117 : : return -ENOTSUP;
3118 : :
3119 : 0 : diag = dev->dev_ops->allmulticast_disable(dev);
3120 [ # # ]: 0 : if (diag == 0)
3121 : 0 : dev->data->all_multicast = 0;
3122 : :
3123 : 0 : diag = eth_err(port_id, diag);
3124 : :
3125 [ # # ]: 0 : rte_eth_trace_allmulticast_disable(port_id, dev->data->all_multicast,
3126 : : diag);
3127 : :
3128 : 0 : return diag;
3129 : : }
3130 : :
3131 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_get)
3132 : : int
3133 : 10 : rte_eth_allmulticast_get(uint16_t port_id)
3134 : : {
3135 : : struct rte_eth_dev *dev;
3136 : :
3137 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3138 : : dev = &rte_eth_devices[port_id];
3139 : :
3140 [ - + ]: 10 : rte_eth_trace_allmulticast_get(port_id, dev->data->all_multicast);
3141 : :
3142 : 10 : return dev->data->all_multicast;
3143 : : }
3144 : :
3145 : : RTE_EXPORT_SYMBOL(rte_eth_link_get)
3146 : : int
3147 : 7 : rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
3148 : : {
3149 : : struct rte_eth_dev *dev;
3150 : :
3151 [ - + ]: 7 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3152 : 7 : dev = &rte_eth_devices[port_id];
3153 : :
3154 [ - + ]: 7 : 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 [ - + - - ]: 7 : if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
3161 : 0 : rte_eth_linkstatus_get(dev, eth_link);
3162 : : else {
3163 [ + - ]: 7 : if (dev->dev_ops->link_update == NULL)
3164 : : return -ENOTSUP;
3165 : 7 : dev->dev_ops->link_update(dev, 1);
3166 : 7 : *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 : 1 : rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
3177 : : {
3178 : : struct rte_eth_dev *dev;
3179 : :
3180 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3181 : 1 : dev = &rte_eth_devices[port_id];
3182 : :
3183 [ - + ]: 1 : 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 [ - + - - ]: 1 : if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
3190 : 0 : rte_eth_linkstatus_get(dev, eth_link);
3191 : : else {
3192 [ + - ]: 1 : if (dev->dev_ops->link_update == NULL)
3193 : : return -ENOTSUP;
3194 : 1 : dev->dev_ops->link_update(dev, 0);
3195 : 1 : *eth_link = dev->data->dev_link;
3196 : : }
3197 : :
3198 : 1 : rte_eth_trace_link_get_nowait(port_id, eth_link);
3199 : :
3200 : 1 : 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 : 20 : rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
3351 : : {
3352 : 20 : int ret = eth_stats_qstats_get(port_id, stats, NULL);
3353 : :
3354 : : rte_eth_trace_stats_get(port_id, stats, ret);
3355 : 20 : return ret;
3356 : : }
3357 : :
3358 : : RTE_EXPORT_SYMBOL(rte_eth_stats_reset)
3359 : : int
3360 : 4 : rte_eth_stats_reset(uint16_t port_id)
3361 : : {
3362 : : struct rte_eth_dev *dev;
3363 : : int ret;
3364 : :
3365 [ - + ]: 4 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3366 : 4 : dev = &rte_eth_devices[port_id];
3367 : :
3368 [ + - ]: 4 : if (dev->dev_ops->stats_reset == NULL)
3369 : : return -ENOTSUP;
3370 : 4 : ret = dev->dev_ops->stats_reset(dev);
3371 [ - + ]: 4 : if (ret != 0)
3372 : 0 : return eth_err(port_id, ret);
3373 : :
3374 [ - + ]: 4 : dev->data->rx_mbuf_alloc_failed = 0;
3375 : :
3376 : 4 : rte_eth_trace_stats_reset(port_id);
3377 : :
3378 : 4 : 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 : strlcpy(xstats_names[cnt_used_entries].name,
3492 : : eth_dev_stats_strings[idx].name,
3493 : : sizeof(xstats_names[0].name));
3494 : 8 : cnt_used_entries++;
3495 : : }
3496 : :
3497 [ + - ]: 1 : if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
3498 : : return cnt_used_entries;
3499 : :
3500 : 1 : num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3501 [ + + ]: 2 : for (id_queue = 0; id_queue < num_q; id_queue++) {
3502 [ + + ]: 4 : for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
3503 : 3 : snprintf(xstats_names[cnt_used_entries].name,
3504 : : sizeof(xstats_names[0].name),
3505 : : "rx_q%u_%s",
3506 : 3 : id_queue, eth_dev_rxq_stats_strings[idx].name);
3507 : 3 : cnt_used_entries++;
3508 : : }
3509 : :
3510 : : }
3511 : 1 : num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3512 [ + + ]: 2 : for (id_queue = 0; id_queue < num_q; id_queue++) {
3513 [ + + ]: 3 : for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
3514 : 2 : snprintf(xstats_names[cnt_used_entries].name,
3515 : : sizeof(xstats_names[0].name),
3516 : : "tx_q%u_%s",
3517 : 2 : id_queue, eth_dev_txq_stats_strings[idx].name);
3518 : 2 : cnt_used_entries++;
3519 : : }
3520 : : }
3521 : : return cnt_used_entries;
3522 : : }
3523 : :
3524 : : static int
3525 : 0 : eth_xstats_get_by_name_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3526 : : struct rte_eth_xstat_name *xstats_names, uint32_t size,
3527 : : uint32_t basic_count)
3528 : : {
3529 : : int32_t rc;
3530 : : uint32_t i, k, m, n;
3531 : : uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
3532 : :
3533 : : m = 0;
3534 [ # # ]: 0 : for (n = 0; n != size; n += k) {
3535 : :
3536 : 0 : k = RTE_MIN(size - n, RTE_DIM(ids_copy));
3537 : :
3538 : : /*
3539 : : * Convert ids to xstats ids that PMD knows.
3540 : : * ids known by user are basic + extended stats.
3541 : : */
3542 [ # # ]: 0 : for (i = 0; i < k; i++)
3543 : 0 : ids_copy[i] = ids[n + i] - basic_count;
3544 : :
3545 : 0 : rc = dev->dev_ops->xstats_get_names_by_id(dev, ids_copy, xstats_names + m, k);
3546 [ # # ]: 0 : if (rc < 0)
3547 : 0 : return rc;
3548 : 0 : m += rc;
3549 : : }
3550 : :
3551 : 0 : return m;
3552 : : }
3553 : :
3554 : :
3555 : : /* retrieve ethdev extended statistics names */
3556 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names_by_id)
3557 : : int
3558 : 0 : rte_eth_xstats_get_names_by_id(uint16_t port_id,
3559 : : struct rte_eth_xstat_name *xstats_names, unsigned int size,
3560 : : uint64_t *ids)
3561 : : {
3562 : : struct rte_eth_xstat_name *xstats_names_copy;
3563 : : unsigned int expected_entries;
3564 : : unsigned int nb_basic_stats;
3565 : : unsigned int basic_count;
3566 : : struct rte_eth_dev *dev;
3567 : : unsigned int i;
3568 : : int ret;
3569 : :
3570 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3571 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3572 : :
3573 : 0 : basic_count = eth_dev_get_xstats_basic_count(dev);
3574 : 0 : ret = eth_dev_get_xstats_count(port_id);
3575 [ # # ]: 0 : if (ret < 0)
3576 : : return ret;
3577 : 0 : expected_entries = (unsigned int)ret;
3578 : :
3579 : : /* Return max number of stats if no ids given */
3580 [ # # ]: 0 : if (!ids) {
3581 [ # # ]: 0 : if (!xstats_names)
3582 : : return expected_entries;
3583 [ # # ]: 0 : else if (xstats_names && size < expected_entries)
3584 : : return expected_entries;
3585 : : }
3586 : :
3587 [ # # ]: 0 : if (ids && !xstats_names)
3588 : : return -EINVAL;
3589 : :
3590 : : nb_basic_stats = 0;
3591 [ # # ]: 0 : if (ids != NULL) {
3592 [ # # ]: 0 : for (i = 0; i < size; i++)
3593 : 0 : nb_basic_stats += (ids[i] < basic_count);
3594 : : }
3595 : :
3596 : : /* no basic stats requested, devops function provided */
3597 [ # # # # ]: 0 : if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
3598 [ # # ]: 0 : dev->dev_ops->xstats_get_names_by_id != NULL)
3599 : 0 : return eth_xstats_get_by_name_by_id(dev, ids, xstats_names,
3600 : : size, basic_count);
3601 : :
3602 : : /* Retrieve all stats */
3603 [ # # ]: 0 : if (!ids) {
3604 : 0 : int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
3605 : : expected_entries);
3606 [ # # ]: 0 : if (num_stats < 0 || num_stats > (int)expected_entries)
3607 : : return num_stats;
3608 : : else
3609 : 0 : return expected_entries;
3610 : : }
3611 : :
3612 : 0 : xstats_names_copy = calloc(expected_entries,
3613 : : sizeof(struct rte_eth_xstat_name));
3614 : :
3615 [ # # ]: 0 : if (!xstats_names_copy) {
3616 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3617 : 0 : return -ENOMEM;
3618 : : }
3619 : :
3620 : : /* Fill xstats_names_copy structure */
3621 [ # # ]: 0 : if (ids && nb_basic_stats == size) {
3622 : 0 : eth_basic_stats_get_names(dev, xstats_names_copy);
3623 : : } else {
3624 : 0 : ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
3625 : : expected_entries);
3626 [ # # ]: 0 : if (ret < 0) {
3627 : 0 : free(xstats_names_copy);
3628 : 0 : return ret;
3629 : : }
3630 : : }
3631 : :
3632 : : /* Filter stats */
3633 [ # # ]: 0 : for (i = 0; i < size; i++) {
3634 [ # # ]: 0 : if (ids[i] >= expected_entries) {
3635 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
3636 : 0 : free(xstats_names_copy);
3637 : 0 : return -1;
3638 : : }
3639 [ # # ]: 0 : xstats_names[i] = xstats_names_copy[ids[i]];
3640 : :
3641 : 0 : rte_eth_trace_xstats_get_names_by_id(port_id, &xstats_names[i],
3642 : : ids[i]);
3643 : : }
3644 : :
3645 : 0 : free(xstats_names_copy);
3646 : 0 : return size;
3647 : : }
3648 : :
3649 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names)
3650 : : int
3651 : 1 : rte_eth_xstats_get_names(uint16_t port_id,
3652 : : struct rte_eth_xstat_name *xstats_names,
3653 : : unsigned int size)
3654 : : {
3655 : : struct rte_eth_dev *dev;
3656 : : int cnt_used_entries;
3657 : : int cnt_expected_entries;
3658 : : int cnt_driver_entries;
3659 : : int i;
3660 : :
3661 : 1 : cnt_expected_entries = eth_dev_get_xstats_count(port_id);
3662 [ + - ]: 1 : if (xstats_names == NULL || cnt_expected_entries < 0 ||
3663 [ + - ]: 1 : (int)size < cnt_expected_entries)
3664 : : return cnt_expected_entries;
3665 : :
3666 : : /* port_id checked in eth_dev_get_xstats_count() */
3667 : 1 : dev = &rte_eth_devices[port_id];
3668 : :
3669 : 1 : cnt_used_entries = eth_basic_stats_get_names(dev, xstats_names);
3670 : :
3671 [ - + ]: 1 : if (dev->dev_ops->xstats_get_names != NULL) {
3672 : : /* If there are any driver-specific xstats, append them
3673 : : * to end of list.
3674 : : */
3675 : 0 : cnt_driver_entries = dev->dev_ops->xstats_get_names(
3676 : : dev,
3677 : 0 : xstats_names + cnt_used_entries,
3678 : : size - cnt_used_entries);
3679 [ # # ]: 0 : if (cnt_driver_entries < 0)
3680 : 0 : return eth_err(port_id, cnt_driver_entries);
3681 : 0 : cnt_used_entries += cnt_driver_entries;
3682 : : }
3683 : :
3684 [ + + ]: 14 : for (i = 0; i < cnt_used_entries; i++)
3685 [ - + ]: 13 : rte_eth_trace_xstats_get_names(port_id, i, &xstats_names[i],
3686 : : size, cnt_used_entries);
3687 : :
3688 : : return cnt_used_entries;
3689 : : }
3690 : :
3691 : :
3692 : : static int
3693 : 1 : eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
3694 : : {
3695 : : struct rte_eth_dev *dev;
3696 : : struct rte_eth_stats eth_stats;
3697 : : struct eth_queue_stats queue_stats;
3698 : : unsigned int count = 0, i, q;
3699 : : uint64_t val, *stats_ptr;
3700 : : uint16_t nb_rxqs, nb_txqs;
3701 : : int ret;
3702 : :
3703 : 1 : ret = eth_stats_qstats_get(port_id, ð_stats, &queue_stats);
3704 [ + - ]: 1 : if (ret < 0)
3705 : : return ret;
3706 : :
3707 : : dev = &rte_eth_devices[port_id];
3708 : :
3709 : 1 : nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3710 : 1 : nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3711 : :
3712 : : /* global stats */
3713 [ + + ]: 9 : for (i = 0; i < RTE_NB_STATS; i++) {
3714 : 8 : stats_ptr = RTE_PTR_ADD(ð_stats,
3715 : : eth_dev_stats_strings[i].offset);
3716 : 8 : val = *stats_ptr;
3717 : 8 : xstats[count++].value = val;
3718 : : }
3719 : :
3720 [ + - ]: 1 : if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
3721 : : return count;
3722 : :
3723 : : /* per-rxq stats */
3724 [ + + ]: 2 : for (q = 0; q < nb_rxqs; q++) {
3725 [ + + ]: 4 : for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
3726 : 3 : stats_ptr = RTE_PTR_ADD(&queue_stats,
3727 : : eth_dev_rxq_stats_strings[i].offset +
3728 : : q * sizeof(uint64_t));
3729 : 3 : val = *stats_ptr;
3730 : 3 : xstats[count++].value = val;
3731 : : }
3732 : : }
3733 : :
3734 : : /* per-txq stats */
3735 [ + + ]: 2 : for (q = 0; q < nb_txqs; q++) {
3736 [ + + ]: 3 : for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
3737 : 2 : stats_ptr = RTE_PTR_ADD(&queue_stats,
3738 : : eth_dev_txq_stats_strings[i].offset +
3739 : : q * sizeof(uint64_t));
3740 : 2 : val = *stats_ptr;
3741 : 2 : xstats[count++].value = val;
3742 : : }
3743 : : }
3744 : 1 : return count;
3745 : : }
3746 : :
3747 : : static int
3748 : 0 : eth_xtats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3749 : : uint64_t *values, uint32_t size, uint32_t basic_count)
3750 : : {
3751 : : int32_t rc;
3752 : : uint32_t i, k, m, n;
3753 : : uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
3754 : :
3755 : : m = 0;
3756 [ # # ]: 0 : for (n = 0; n != size; n += k) {
3757 : :
3758 : 0 : k = RTE_MIN(size - n, RTE_DIM(ids_copy));
3759 : :
3760 : : /*
3761 : : * Convert ids to xstats ids that PMD knows.
3762 : : * ids known by user are basic + extended stats.
3763 : : */
3764 [ # # ]: 0 : for (i = 0; i < k; i++)
3765 : 0 : ids_copy[i] = ids[n + i] - basic_count;
3766 : :
3767 : 0 : rc = dev->dev_ops->xstats_get_by_id(dev, ids_copy, values + m, k);
3768 [ # # ]: 0 : if (rc < 0)
3769 : 0 : return rc;
3770 : 0 : m += rc;
3771 : : }
3772 : :
3773 : 0 : return m;
3774 : : }
3775 : :
3776 : : /* retrieve ethdev extended statistics */
3777 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_by_id)
3778 : : int
3779 : 0 : rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
3780 : : uint64_t *values, unsigned int size)
3781 : : {
3782 : : unsigned int nb_basic_stats;
3783 : : unsigned int num_xstats_filled;
3784 : : unsigned int basic_count;
3785 : : uint16_t expected_entries;
3786 : : struct rte_eth_dev *dev;
3787 : : struct rte_eth_xstat *xstats;
3788 : : unsigned int i;
3789 : : int ret;
3790 : :
3791 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3792 : 0 : dev = &rte_eth_devices[port_id];
3793 : :
3794 : 0 : ret = eth_dev_get_xstats_count(port_id);
3795 [ # # ]: 0 : if (ret < 0)
3796 : : return ret;
3797 [ # # ]: 0 : expected_entries = (uint16_t)ret;
3798 : 0 : basic_count = eth_dev_get_xstats_basic_count(dev);
3799 : :
3800 : : /* Return max number of stats if no ids given */
3801 [ # # ]: 0 : if (!ids) {
3802 [ # # ]: 0 : if (!values)
3803 : 0 : return expected_entries;
3804 [ # # ]: 0 : else if (values && size < expected_entries)
3805 : : return expected_entries;
3806 : : }
3807 : :
3808 [ # # ]: 0 : if (ids && !values)
3809 : : return -EINVAL;
3810 : :
3811 : : nb_basic_stats = 0;
3812 [ # # ]: 0 : if (ids != NULL) {
3813 [ # # ]: 0 : for (i = 0; i < size; i++)
3814 : 0 : nb_basic_stats += (ids[i] < basic_count);
3815 : : }
3816 : :
3817 : : /* no basic stats requested, devops function provided */
3818 [ # # # # ]: 0 : if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
3819 [ # # ]: 0 : dev->dev_ops->xstats_get_by_id != NULL)
3820 : 0 : return eth_xtats_get_by_id(dev, ids, values, size, basic_count);
3821 : :
3822 : 0 : xstats = calloc(expected_entries, sizeof(xstats[0]));
3823 [ # # ]: 0 : if (xstats == NULL) {
3824 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3825 : 0 : return -ENOMEM;
3826 : : }
3827 : :
3828 : : /* Fill the xstats structure */
3829 [ # # ]: 0 : if (ids && nb_basic_stats == size)
3830 : 0 : ret = eth_basic_stats_get(port_id, xstats);
3831 : : else
3832 : 0 : ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
3833 : :
3834 [ # # ]: 0 : if (ret < 0) {
3835 : 0 : free(xstats);
3836 : 0 : return ret;
3837 : : }
3838 : 0 : num_xstats_filled = (unsigned int)ret;
3839 : :
3840 : : /* Return all stats */
3841 [ # # ]: 0 : if (!ids) {
3842 [ # # ]: 0 : for (i = 0; i < num_xstats_filled; i++)
3843 : 0 : values[i] = xstats[i].value;
3844 : :
3845 : 0 : free(xstats);
3846 : 0 : return expected_entries;
3847 : : }
3848 : :
3849 : : /* Filter stats */
3850 [ # # ]: 0 : for (i = 0; i < size; i++) {
3851 [ # # ]: 0 : if (ids[i] >= expected_entries) {
3852 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
3853 : 0 : break;
3854 : : }
3855 : 0 : values[i] = xstats[ids[i]].value;
3856 : : }
3857 : :
3858 : 0 : rte_eth_trace_xstats_get_by_id(port_id, ids, values, size);
3859 : :
3860 : 0 : free(xstats);
3861 [ # # ]: 0 : return (i == size) ? (int32_t)size : -1;
3862 : : }
3863 : :
3864 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get)
3865 : : int
3866 : 2 : rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
3867 : : unsigned int n)
3868 : : {
3869 : : struct rte_eth_dev *dev;
3870 : : unsigned int count, i;
3871 : : signed int xcount = 0;
3872 : : int ret;
3873 : :
3874 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3875 [ + - ]: 2 : if (xstats == NULL && n > 0)
3876 : : return -EINVAL;
3877 [ + - ]: 2 : dev = &rte_eth_devices[port_id];
3878 : :
3879 : 2 : count = eth_dev_get_xstats_basic_count(dev);
3880 : :
3881 : : /* implemented by the driver */
3882 [ - + ]: 2 : if (dev->dev_ops->xstats_get != NULL) {
3883 : : /* Retrieve the xstats from the driver at the end of the
3884 : : * xstats struct.
3885 : : */
3886 [ # # # # ]: 0 : xcount = dev->dev_ops->xstats_get(dev,
3887 : 0 : (n > count) ? xstats + count : NULL,
3888 : : (n > count) ? n - count : 0);
3889 : :
3890 [ # # ]: 0 : if (xcount < 0)
3891 : 0 : return eth_err(port_id, xcount);
3892 : : }
3893 : :
3894 [ + + - + ]: 2 : if (n < count + xcount || xstats == NULL)
3895 : 1 : return count + xcount;
3896 : :
3897 : : /* now fill the xstats structure */
3898 : 1 : ret = eth_basic_stats_get(port_id, xstats);
3899 [ + - ]: 1 : if (ret < 0)
3900 : : return ret;
3901 : 1 : count = ret;
3902 : :
3903 [ + + ]: 14 : for (i = 0; i < count; i++)
3904 : 13 : xstats[i].id = i;
3905 : : /* add an offset to driver-specific stats */
3906 [ - + ]: 1 : for ( ; i < count + xcount; i++)
3907 : 0 : xstats[i].id += count;
3908 : :
3909 [ + + ]: 14 : for (i = 0; i < n; i++)
3910 [ - + ]: 13 : rte_eth_trace_xstats_get(port_id, xstats[i]);
3911 : :
3912 : 1 : return count + xcount;
3913 : : }
3914 : :
3915 : : /* reset ethdev extended statistics */
3916 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_reset)
3917 : : int
3918 : 0 : rte_eth_xstats_reset(uint16_t port_id)
3919 : : {
3920 : : struct rte_eth_dev *dev;
3921 : :
3922 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3923 : 0 : dev = &rte_eth_devices[port_id];
3924 : :
3925 : : /* implemented by the driver */
3926 [ # # ]: 0 : if (dev->dev_ops->xstats_reset != NULL) {
3927 : 0 : int ret = eth_err(port_id, dev->dev_ops->xstats_reset(dev));
3928 : :
3929 : 0 : rte_eth_trace_xstats_reset(port_id, ret);
3930 : :
3931 : 0 : return ret;
3932 : : }
3933 : :
3934 : : /* fallback to default */
3935 : 0 : return rte_eth_stats_reset(port_id);
3936 : : }
3937 : :
3938 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_set_counter, 25.03)
3939 : : int
3940 : 0 : rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off)
3941 : : {
3942 : : struct rte_eth_dev *dev;
3943 : : unsigned int basic_count;
3944 : :
3945 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3946 : :
3947 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3948 : : basic_count = eth_dev_get_xstats_basic_count(dev);
3949 [ # # ]: 0 : if (id < basic_count)
3950 : : return -EINVAL;
3951 : :
3952 [ # # ]: 0 : if (on_off == 1) {
3953 [ # # ]: 0 : if (rte_eth_xstats_query_state(port_id, id) == 1)
3954 : : return -EEXIST;
3955 [ # # ]: 0 : if (dev->dev_ops->xstats_enable != NULL)
3956 : 0 : return dev->dev_ops->xstats_enable(dev, id - basic_count);
3957 : : } else {
3958 [ # # ]: 0 : if (rte_eth_xstats_query_state(port_id, id) == 0)
3959 : : return 0;
3960 [ # # ]: 0 : if (dev->dev_ops->xstats_disable != NULL)
3961 : 0 : return dev->dev_ops->xstats_disable(dev, id - basic_count);
3962 : : }
3963 : :
3964 : : return -ENOTSUP;
3965 : : }
3966 : :
3967 : :
3968 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_query_state, 25.03)
3969 : : int
3970 : 0 : rte_eth_xstats_query_state(uint16_t port_id, uint64_t id)
3971 : : {
3972 : : struct rte_eth_dev *dev;
3973 : : unsigned int basic_count;
3974 : :
3975 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3976 : :
3977 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3978 : : basic_count = eth_dev_get_xstats_basic_count(dev);
3979 [ # # ]: 0 : if (id < basic_count)
3980 : : return -ENOTSUP;
3981 : :
3982 : : /* implemented by the driver */
3983 [ # # ]: 0 : if (dev->dev_ops->xstats_query_state != NULL)
3984 : 0 : return dev->dev_ops->xstats_query_state(dev, id - basic_count);
3985 : :
3986 : : return -ENOTSUP;
3987 : : }
3988 : :
3989 : : static int
3990 : 0 : eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id,
3991 : : uint8_t stat_idx, uint8_t is_rx)
3992 : : {
3993 : : struct rte_eth_dev *dev;
3994 : :
3995 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3996 : 0 : dev = &rte_eth_devices[port_id];
3997 : :
3998 [ # # # # ]: 0 : if (is_rx && (queue_id >= dev->data->nb_rx_queues))
3999 : : return -EINVAL;
4000 : :
4001 [ # # # # ]: 0 : if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
4002 : : return -EINVAL;
4003 : :
4004 [ # # ]: 0 : if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
4005 : : return -EINVAL;
4006 : :
4007 [ # # ]: 0 : if (dev->dev_ops->queue_stats_mapping_set == NULL)
4008 : : return -ENOTSUP;
4009 : 0 : return dev->dev_ops->queue_stats_mapping_set(dev, queue_id, stat_idx, is_rx);
4010 : : }
4011 : :
4012 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_tx_queue_stats_mapping)
4013 : : int
4014 : 0 : rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
4015 : : uint8_t stat_idx)
4016 : : {
4017 : : int ret;
4018 : :
4019 : 0 : ret = eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id,
4020 : : tx_queue_id,
4021 : : stat_idx, STAT_QMAP_TX));
4022 : :
4023 : 0 : rte_ethdev_trace_set_tx_queue_stats_mapping(port_id, tx_queue_id,
4024 : : stat_idx, ret);
4025 : :
4026 : 0 : return ret;
4027 : : }
4028 : :
4029 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_rx_queue_stats_mapping)
4030 : : int
4031 : 0 : rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
4032 : : uint8_t stat_idx)
4033 : : {
4034 : : int ret;
4035 : :
4036 : 0 : ret = eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id,
4037 : : rx_queue_id,
4038 : : stat_idx, STAT_QMAP_RX));
4039 : :
4040 : 0 : rte_ethdev_trace_set_rx_queue_stats_mapping(port_id, rx_queue_id,
4041 : : stat_idx, ret);
4042 : :
4043 : 0 : return ret;
4044 : : }
4045 : :
4046 : : RTE_EXPORT_SYMBOL(rte_eth_dev_fw_version_get)
4047 : : int
4048 : 1 : rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
4049 : : {
4050 : : struct rte_eth_dev *dev;
4051 : : int ret;
4052 : :
4053 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4054 : 1 : dev = &rte_eth_devices[port_id];
4055 : :
4056 [ - + ]: 1 : if (fw_version == NULL && fw_size > 0) {
4057 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4058 : : "Cannot get ethdev port %u FW version to NULL when string size is non zero",
4059 : : port_id);
4060 : 0 : return -EINVAL;
4061 : : }
4062 : :
4063 [ - + ]: 1 : if (dev->dev_ops->fw_version_get == NULL)
4064 : : return -ENOTSUP;
4065 : 0 : ret = eth_err(port_id, dev->dev_ops->fw_version_get(dev, fw_version, fw_size));
4066 : :
4067 : 0 : rte_ethdev_trace_fw_version_get(port_id, fw_version, fw_size, ret);
4068 : :
4069 : 0 : return ret;
4070 : : }
4071 : :
4072 : : RTE_EXPORT_SYMBOL(rte_eth_dev_info_get)
4073 : : int
4074 : 121 : rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
4075 : : {
4076 : : struct rte_eth_dev *dev;
4077 : : const struct rte_eth_desc_lim lim = {
4078 : : .nb_max = UINT16_MAX,
4079 : : .nb_min = 0,
4080 : : .nb_align = 1,
4081 : : .nb_seg_max = UINT16_MAX,
4082 : : .nb_mtu_seg_max = UINT16_MAX,
4083 : : };
4084 : : int diag;
4085 : :
4086 [ - + ]: 121 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4087 : 121 : dev = &rte_eth_devices[port_id];
4088 : :
4089 [ - + ]: 121 : if (dev_info == NULL) {
4090 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u info to NULL",
4091 : : port_id);
4092 : 0 : return -EINVAL;
4093 : : }
4094 : :
4095 : : /*
4096 : : * Init dev_info before port_id check since caller does not have
4097 : : * return status and does not know if get is successful or not.
4098 : : */
4099 : : memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
4100 : 121 : dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
4101 : :
4102 : 121 : dev_info->rx_desc_lim = lim;
4103 : 121 : dev_info->tx_desc_lim = lim;
4104 : 121 : dev_info->device = dev->device;
4105 : 121 : dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN -
4106 : : RTE_ETHER_CRC_LEN;
4107 : 121 : dev_info->max_mtu = UINT16_MAX;
4108 : 121 : dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT);
4109 : 121 : dev_info->max_rx_bufsize = UINT32_MAX;
4110 : :
4111 [ + - ]: 121 : if (dev->dev_ops->dev_infos_get == NULL)
4112 : : return -ENOTSUP;
4113 : 121 : diag = dev->dev_ops->dev_infos_get(dev, dev_info);
4114 [ - + ]: 121 : if (diag != 0) {
4115 : : /* Cleanup already filled in device information */
4116 : : memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
4117 : 0 : return eth_err(port_id, diag);
4118 : : }
4119 : :
4120 : : /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */
4121 : 121 : dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues,
4122 : : RTE_MAX_QUEUES_PER_PORT);
4123 : 121 : dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues,
4124 : : RTE_MAX_QUEUES_PER_PORT);
4125 : :
4126 : 121 : dev_info->driver_name = dev->device->driver->name;
4127 : 121 : dev_info->nb_rx_queues = dev->data->nb_rx_queues;
4128 : 121 : dev_info->nb_tx_queues = dev->data->nb_tx_queues;
4129 : :
4130 [ - + ]: 121 : dev_info->dev_flags = &dev->data->dev_flags;
4131 : :
4132 : 121 : rte_ethdev_trace_info_get(port_id, dev_info);
4133 : :
4134 : 121 : return 0;
4135 : : }
4136 : :
4137 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_conf_get, 21.11)
4138 : : int
4139 : 1 : rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf)
4140 : : {
4141 : : struct rte_eth_dev *dev;
4142 : :
4143 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4144 : : dev = &rte_eth_devices[port_id];
4145 : :
4146 [ - + ]: 1 : if (dev_conf == NULL) {
4147 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4148 : : "Cannot get ethdev port %u configuration to NULL",
4149 : : port_id);
4150 : 0 : return -EINVAL;
4151 : : }
4152 : :
4153 [ - + ]: 1 : memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf));
4154 : :
4155 : 1 : rte_ethdev_trace_conf_get(port_id, dev_conf);
4156 : :
4157 : 1 : return 0;
4158 : : }
4159 : :
4160 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_supported_ptypes)
4161 : : int
4162 : 0 : rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
4163 : : uint32_t *ptypes, int num)
4164 : : {
4165 : : size_t i;
4166 : : int j;
4167 : : struct rte_eth_dev *dev;
4168 : : const uint32_t *all_ptypes;
4169 : 0 : size_t no_of_elements = 0;
4170 : :
4171 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4172 : 0 : dev = &rte_eth_devices[port_id];
4173 : :
4174 [ # # ]: 0 : if (ptypes == NULL && num > 0) {
4175 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4176 : : "Cannot get ethdev port %u supported packet types to NULL when array size is non zero",
4177 : : port_id);
4178 : 0 : return -EINVAL;
4179 : : }
4180 : :
4181 [ # # ]: 0 : if (dev->dev_ops->dev_supported_ptypes_get == NULL)
4182 : : return 0;
4183 : 0 : all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
4184 : :
4185 [ # # ]: 0 : if (!all_ptypes)
4186 : : return 0;
4187 : :
4188 [ # # ]: 0 : for (i = 0, j = 0; i < no_of_elements; ++i)
4189 [ # # ]: 0 : if (all_ptypes[i] & ptype_mask) {
4190 [ # # ]: 0 : if (j < num) {
4191 [ # # ]: 0 : ptypes[j] = all_ptypes[i];
4192 : :
4193 : 0 : rte_ethdev_trace_get_supported_ptypes(port_id,
4194 : : j, num, ptypes[j]);
4195 : : }
4196 : 0 : j++;
4197 : : }
4198 : :
4199 : : return j;
4200 : : }
4201 : :
4202 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_ptypes)
4203 : : int
4204 : 0 : rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
4205 : : uint32_t *set_ptypes, unsigned int num)
4206 : : {
4207 : 0 : const uint32_t valid_ptype_masks[] = {
4208 : : RTE_PTYPE_L2_MASK,
4209 : : RTE_PTYPE_L3_MASK,
4210 : : RTE_PTYPE_L4_MASK,
4211 : : RTE_PTYPE_TUNNEL_MASK,
4212 : : RTE_PTYPE_INNER_L2_MASK,
4213 : : RTE_PTYPE_INNER_L3_MASK,
4214 : : RTE_PTYPE_INNER_L4_MASK,
4215 : : };
4216 : : const uint32_t *all_ptypes;
4217 : : struct rte_eth_dev *dev;
4218 : : uint32_t unused_mask;
4219 : : size_t i;
4220 : : unsigned int j;
4221 : : int ret;
4222 : 0 : size_t no_of_elements = 0;
4223 : :
4224 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4225 : 0 : dev = &rte_eth_devices[port_id];
4226 : :
4227 [ # # ]: 0 : if (num > 0 && set_ptypes == NULL) {
4228 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4229 : : "Cannot get ethdev port %u set packet types to NULL when array size is non zero",
4230 : : port_id);
4231 : 0 : return -EINVAL;
4232 : : }
4233 : :
4234 [ # # ]: 0 : if (dev->dev_ops->dev_supported_ptypes_get == NULL ||
4235 [ # # ]: 0 : dev->dev_ops->dev_ptypes_set == NULL) {
4236 : : ret = 0;
4237 : 0 : goto ptype_unknown;
4238 : : }
4239 : :
4240 [ # # ]: 0 : if (ptype_mask == 0) {
4241 : 0 : ret = dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
4242 : 0 : goto ptype_unknown;
4243 : : }
4244 : :
4245 : : unused_mask = ptype_mask;
4246 [ # # ]: 0 : for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) {
4247 : 0 : uint32_t mask = ptype_mask & valid_ptype_masks[i];
4248 [ # # # # ]: 0 : if (mask && mask != valid_ptype_masks[i]) {
4249 : : ret = -EINVAL;
4250 : 0 : goto ptype_unknown;
4251 : : }
4252 : 0 : unused_mask &= ~valid_ptype_masks[i];
4253 : : }
4254 : :
4255 [ # # ]: 0 : if (unused_mask) {
4256 : : ret = -EINVAL;
4257 : 0 : goto ptype_unknown;
4258 : : }
4259 : :
4260 : 0 : all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
4261 [ # # ]: 0 : if (all_ptypes == NULL) {
4262 : : ret = 0;
4263 : 0 : goto ptype_unknown;
4264 : : }
4265 : :
4266 : : /*
4267 : : * Accommodate as many set_ptypes as possible. If the supplied
4268 : : * set_ptypes array is insufficient fill it partially.
4269 : : */
4270 [ # # ]: 0 : for (i = 0, j = 0; set_ptypes != NULL &&
4271 [ # # ]: 0 : (i < no_of_elements); ++i) {
4272 [ # # ]: 0 : if (ptype_mask & all_ptypes[i]) {
4273 [ # # ]: 0 : if (j < num - 1) {
4274 : 0 : set_ptypes[j] = all_ptypes[i];
4275 : :
4276 [ # # ]: 0 : rte_ethdev_trace_set_ptypes(port_id, j, num,
4277 : : set_ptypes[j]);
4278 : :
4279 : 0 : j++;
4280 : 0 : continue;
4281 : : }
4282 : : break;
4283 : : }
4284 : : }
4285 : :
4286 [ # # ]: 0 : if (set_ptypes != NULL && j < num)
4287 : 0 : set_ptypes[j] = RTE_PTYPE_UNKNOWN;
4288 : :
4289 : 0 : return dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
4290 : :
4291 : 0 : ptype_unknown:
4292 [ # # ]: 0 : if (num > 0)
4293 : 0 : set_ptypes[0] = RTE_PTYPE_UNKNOWN;
4294 : :
4295 : : return ret;
4296 : : }
4297 : :
4298 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_macaddrs_get, 21.11)
4299 : : int
4300 : 0 : rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma,
4301 : : unsigned int num)
4302 : : {
4303 : : int32_t ret;
4304 : : struct rte_eth_dev *dev;
4305 : : struct rte_eth_dev_info dev_info;
4306 : :
4307 [ # # ]: 0 : if (ma == NULL) {
4308 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "%s: invalid parameters", __func__);
4309 : 0 : return -EINVAL;
4310 : : }
4311 : :
4312 : : /* will check for us that port_id is a valid one */
4313 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4314 [ # # ]: 0 : if (ret != 0)
4315 : : return ret;
4316 : :
4317 : : dev = &rte_eth_devices[port_id];
4318 : 0 : num = RTE_MIN(dev_info.max_mac_addrs, num);
4319 [ # # ]: 0 : memcpy(ma, dev->data->mac_addrs, num * sizeof(ma[0]));
4320 : :
4321 : 0 : rte_eth_trace_macaddrs_get(port_id, num);
4322 : :
4323 : 0 : return num;
4324 : : }
4325 : :
4326 : : RTE_EXPORT_SYMBOL(rte_eth_macaddr_get)
4327 : : int
4328 : 6 : rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
4329 : : {
4330 : : struct rte_eth_dev *dev;
4331 : :
4332 [ - + ]: 6 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4333 : : dev = &rte_eth_devices[port_id];
4334 : :
4335 [ - + ]: 6 : if (mac_addr == NULL) {
4336 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4337 : : "Cannot get ethdev port %u MAC address to NULL",
4338 : : port_id);
4339 : 0 : return -EINVAL;
4340 : : }
4341 : :
4342 : 6 : rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
4343 : :
4344 : : rte_eth_trace_macaddr_get(port_id, mac_addr);
4345 : :
4346 : 6 : return 0;
4347 : : }
4348 : :
4349 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_mtu)
4350 : : int
4351 : 0 : rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
4352 : : {
4353 : : struct rte_eth_dev *dev;
4354 : :
4355 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4356 : : dev = &rte_eth_devices[port_id];
4357 : :
4358 [ # # ]: 0 : if (mtu == NULL) {
4359 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u MTU to NULL",
4360 : : port_id);
4361 : 0 : return -EINVAL;
4362 : : }
4363 : :
4364 : 0 : *mtu = dev->data->mtu;
4365 : :
4366 : : rte_ethdev_trace_get_mtu(port_id, *mtu);
4367 : :
4368 : 0 : return 0;
4369 : : }
4370 : :
4371 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mtu)
4372 : : int
4373 : 0 : rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
4374 : : {
4375 : : int ret;
4376 : : struct rte_eth_dev_info dev_info;
4377 : : struct rte_eth_dev *dev;
4378 : :
4379 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4380 : 0 : dev = &rte_eth_devices[port_id];
4381 [ # # ]: 0 : if (dev->dev_ops->mtu_set == NULL)
4382 : : return -ENOTSUP;
4383 : :
4384 : : /*
4385 : : * Check if the device supports dev_infos_get, if it does not
4386 : : * skip min_mtu/max_mtu validation here as this requires values
4387 : : * that are populated within the call to rte_eth_dev_info_get()
4388 : : * which relies on dev->dev_ops->dev_infos_get.
4389 : : */
4390 [ # # ]: 0 : if (dev->dev_ops->dev_infos_get != NULL) {
4391 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4392 [ # # ]: 0 : if (ret != 0)
4393 : : return ret;
4394 : :
4395 : 0 : ret = eth_dev_validate_mtu(port_id, &dev_info, mtu);
4396 [ # # ]: 0 : if (ret != 0)
4397 : : return ret;
4398 : : }
4399 : :
4400 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
4401 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4402 : : "Port %u must be configured before MTU set",
4403 : : port_id);
4404 : 0 : return -EINVAL;
4405 : : }
4406 : :
4407 : 0 : ret = dev->dev_ops->mtu_set(dev, mtu);
4408 [ # # ]: 0 : if (ret == 0)
4409 : 0 : dev->data->mtu = mtu;
4410 : :
4411 : 0 : ret = eth_err(port_id, ret);
4412 : :
4413 : 0 : rte_ethdev_trace_set_mtu(port_id, mtu, ret);
4414 : :
4415 : 0 : return ret;
4416 : : }
4417 : :
4418 : : RTE_EXPORT_SYMBOL(rte_eth_dev_vlan_filter)
4419 : : int
4420 : 0 : rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
4421 : : {
4422 : : struct rte_eth_dev *dev;
4423 : : int ret;
4424 : :
4425 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4426 : 0 : dev = &rte_eth_devices[port_id];
4427 : :
4428 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.offloads &
4429 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
4430 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: VLAN-filtering disabled",
4431 : : port_id);
4432 : 0 : return -ENOSYS;
4433 : : }
4434 : :
4435 [ # # ]: 0 : if (vlan_id > 4095) {
4436 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port_id=%u invalid vlan_id=%u > 4095",
4437 : : port_id, vlan_id);
4438 : 0 : return -EINVAL;
4439 : : }
4440 [ # # ]: 0 : if (dev->dev_ops->vlan_filter_set == NULL)
4441 : : return -ENOTSUP;
4442 : :
4443 : 0 : ret = dev->dev_ops->vlan_filter_set(dev, vlan_id, on);
4444 [ # # ]: 0 : if (ret == 0) {
4445 : : struct rte_vlan_filter_conf *vfc;
4446 : : int vidx;
4447 : : int vbit;
4448 : :
4449 : 0 : vfc = &dev->data->vlan_filter_conf;
4450 : 0 : vidx = vlan_id / 64;
4451 : 0 : vbit = vlan_id % 64;
4452 : :
4453 [ # # ]: 0 : if (on)
4454 : 0 : vfc->ids[vidx] |= RTE_BIT64(vbit);
4455 : : else
4456 : 0 : vfc->ids[vidx] &= ~RTE_BIT64(vbit);
4457 : : }
4458 : :
4459 : 0 : ret = eth_err(port_id, ret);
4460 : :
4461 : 0 : rte_ethdev_trace_vlan_filter(port_id, vlan_id, on, ret);
4462 : :
4463 : 0 : return ret;
4464 : : }
4465 : :
4466 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_strip_on_queue)
4467 : : int
4468 : 0 : rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
4469 : : int on)
4470 : : {
4471 : : struct rte_eth_dev *dev;
4472 : :
4473 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4474 : 0 : dev = &rte_eth_devices[port_id];
4475 : :
4476 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues) {
4477 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid rx_queue_id=%u", rx_queue_id);
4478 : 0 : return -EINVAL;
4479 : : }
4480 : :
4481 [ # # ]: 0 : if (dev->dev_ops->vlan_strip_queue_set == NULL)
4482 : : return -ENOTSUP;
4483 : 0 : dev->dev_ops->vlan_strip_queue_set(dev, rx_queue_id, on);
4484 : :
4485 : 0 : rte_ethdev_trace_set_vlan_strip_on_queue(port_id, rx_queue_id, on);
4486 : :
4487 : 0 : return 0;
4488 : : }
4489 : :
4490 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_ether_type)
4491 : : int
4492 : 0 : rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
4493 : : enum rte_vlan_type vlan_type,
4494 : : uint16_t tpid)
4495 : : {
4496 : : struct rte_eth_dev *dev;
4497 : : int ret;
4498 : :
4499 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4500 : 0 : dev = &rte_eth_devices[port_id];
4501 : :
4502 [ # # ]: 0 : if (dev->dev_ops->vlan_tpid_set == NULL)
4503 : : return -ENOTSUP;
4504 : 0 : ret = eth_err(port_id, dev->dev_ops->vlan_tpid_set(dev, vlan_type, tpid));
4505 : :
4506 : 0 : rte_ethdev_trace_set_vlan_ether_type(port_id, vlan_type, tpid, ret);
4507 : :
4508 : 0 : return ret;
4509 : : }
4510 : :
4511 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_offload)
4512 : : int
4513 : 0 : rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
4514 : : {
4515 : : struct rte_eth_dev_info dev_info;
4516 : : struct rte_eth_dev *dev;
4517 : : int ret = 0;
4518 : : int mask = 0;
4519 : : int cur, org = 0;
4520 : : uint64_t orig_offloads;
4521 : : uint64_t dev_offloads;
4522 : : uint64_t new_offloads;
4523 : :
4524 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4525 : 0 : dev = &rte_eth_devices[port_id];
4526 : :
4527 : : /* save original values in case of failure */
4528 : 0 : orig_offloads = dev->data->dev_conf.rxmode.offloads;
4529 : : dev_offloads = orig_offloads;
4530 : :
4531 : : /* check which option changed by application */
4532 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_STRIP_OFFLOAD);
4533 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
4534 [ # # ]: 0 : if (cur != org) {
4535 [ # # ]: 0 : if (cur)
4536 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4537 : : else
4538 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4539 : : mask |= RTE_ETH_VLAN_STRIP_MASK;
4540 : : }
4541 : :
4542 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_FILTER_OFFLOAD);
4543 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER);
4544 [ # # ]: 0 : if (cur != org) {
4545 [ # # ]: 0 : if (cur)
4546 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4547 : : else
4548 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4549 : 0 : mask |= RTE_ETH_VLAN_FILTER_MASK;
4550 : : }
4551 : :
4552 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_EXTEND_OFFLOAD);
4553 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
4554 [ # # ]: 0 : if (cur != org) {
4555 [ # # ]: 0 : if (cur)
4556 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4557 : : else
4558 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4559 : 0 : mask |= RTE_ETH_VLAN_EXTEND_MASK;
4560 : : }
4561 : :
4562 : 0 : cur = !!(offload_mask & RTE_ETH_QINQ_STRIP_OFFLOAD);
4563 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP);
4564 [ # # ]: 0 : if (cur != org) {
4565 [ # # ]: 0 : if (cur)
4566 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4567 : : else
4568 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4569 : 0 : mask |= RTE_ETH_QINQ_STRIP_MASK;
4570 : : }
4571 : :
4572 : : /*no change*/
4573 [ # # ]: 0 : if (mask == 0)
4574 : : return ret;
4575 : :
4576 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4577 [ # # ]: 0 : if (ret != 0)
4578 : : return ret;
4579 : :
4580 : : /* Rx VLAN offloading must be within its device capabilities */
4581 [ # # ]: 0 : if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) {
4582 : 0 : new_offloads = dev_offloads & ~orig_offloads;
4583 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4584 : : "Ethdev port_id=%u requested new added VLAN offloads "
4585 : : "0x%" PRIx64 " must be within Rx offloads capabilities "
4586 : : "0x%" PRIx64 " in %s()",
4587 : : port_id, new_offloads, dev_info.rx_offload_capa,
4588 : : __func__);
4589 : 0 : return -EINVAL;
4590 : : }
4591 : :
4592 [ # # ]: 0 : if (dev->dev_ops->vlan_offload_set == NULL)
4593 : : return -ENOTSUP;
4594 : 0 : dev->data->dev_conf.rxmode.offloads = dev_offloads;
4595 : 0 : ret = dev->dev_ops->vlan_offload_set(dev, mask);
4596 [ # # ]: 0 : if (ret) {
4597 : : /* hit an error restore original values */
4598 : 0 : dev->data->dev_conf.rxmode.offloads = orig_offloads;
4599 : : }
4600 : :
4601 : 0 : ret = eth_err(port_id, ret);
4602 : :
4603 : 0 : rte_ethdev_trace_set_vlan_offload(port_id, offload_mask, ret);
4604 : :
4605 : 0 : return ret;
4606 : : }
4607 : :
4608 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_vlan_offload)
4609 : : int
4610 : 1 : rte_eth_dev_get_vlan_offload(uint16_t port_id)
4611 : : {
4612 : : struct rte_eth_dev *dev;
4613 : : uint64_t *dev_offloads;
4614 : : int ret = 0;
4615 : :
4616 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4617 : : dev = &rte_eth_devices[port_id];
4618 : 1 : dev_offloads = &dev->data->dev_conf.rxmode.offloads;
4619 : :
4620 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4621 : : ret |= RTE_ETH_VLAN_STRIP_OFFLOAD;
4622 : :
4623 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4624 : 0 : ret |= RTE_ETH_VLAN_FILTER_OFFLOAD;
4625 : :
4626 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
4627 : 0 : ret |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
4628 : :
4629 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4630 : 0 : ret |= RTE_ETH_QINQ_STRIP_OFFLOAD;
4631 : :
4632 : 1 : rte_ethdev_trace_get_vlan_offload(port_id, ret);
4633 : :
4634 : 1 : return ret;
4635 : : }
4636 : :
4637 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_pvid)
4638 : : int
4639 : 0 : rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
4640 : : {
4641 : : struct rte_eth_dev *dev;
4642 : : int ret;
4643 : :
4644 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4645 : 0 : dev = &rte_eth_devices[port_id];
4646 : :
4647 [ # # ]: 0 : if (dev->dev_ops->vlan_pvid_set == NULL)
4648 : : return -ENOTSUP;
4649 : 0 : ret = eth_err(port_id, dev->dev_ops->vlan_pvid_set(dev, pvid, on));
4650 : :
4651 : 0 : rte_ethdev_trace_set_vlan_pvid(port_id, pvid, on, ret);
4652 : :
4653 : 0 : return ret;
4654 : : }
4655 : :
4656 : : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_get)
4657 : : int
4658 : 1 : rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
4659 : : {
4660 : : struct rte_eth_dev *dev;
4661 : : int ret;
4662 : :
4663 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4664 : 1 : dev = &rte_eth_devices[port_id];
4665 : :
4666 [ - + ]: 1 : if (fc_conf == NULL) {
4667 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4668 : : "Cannot get ethdev port %u flow control config to NULL",
4669 : : port_id);
4670 : 0 : return -EINVAL;
4671 : : }
4672 : :
4673 [ - + ]: 1 : if (dev->dev_ops->flow_ctrl_get == NULL)
4674 : : return -ENOTSUP;
4675 : : memset(fc_conf, 0, sizeof(*fc_conf));
4676 : 0 : ret = eth_err(port_id, dev->dev_ops->flow_ctrl_get(dev, fc_conf));
4677 : :
4678 : 0 : rte_ethdev_trace_flow_ctrl_get(port_id, fc_conf, ret);
4679 : :
4680 : 0 : return ret;
4681 : : }
4682 : :
4683 : : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_set)
4684 : : int
4685 : 0 : rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
4686 : : {
4687 : : struct rte_eth_dev *dev;
4688 : : int ret;
4689 : :
4690 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4691 : 0 : dev = &rte_eth_devices[port_id];
4692 : :
4693 [ # # ]: 0 : if (fc_conf == NULL) {
4694 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4695 : : "Cannot set ethdev port %u flow control from NULL config",
4696 : : port_id);
4697 : 0 : return -EINVAL;
4698 : : }
4699 : :
4700 [ # # ]: 0 : if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
4701 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid send_xon, only 0/1 allowed");
4702 : 0 : return -EINVAL;
4703 : : }
4704 : :
4705 [ # # ]: 0 : if (dev->dev_ops->flow_ctrl_set == NULL)
4706 : : return -ENOTSUP;
4707 : 0 : ret = eth_err(port_id, dev->dev_ops->flow_ctrl_set(dev, fc_conf));
4708 : :
4709 : 0 : rte_ethdev_trace_flow_ctrl_set(port_id, fc_conf, ret);
4710 : :
4711 : 0 : return ret;
4712 : : }
4713 : :
4714 : : RTE_EXPORT_SYMBOL(rte_eth_dev_priority_flow_ctrl_set)
4715 : : int
4716 : 0 : rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
4717 : : struct rte_eth_pfc_conf *pfc_conf)
4718 : : {
4719 : : struct rte_eth_dev *dev;
4720 : : int ret;
4721 : :
4722 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4723 : 0 : dev = &rte_eth_devices[port_id];
4724 : :
4725 [ # # ]: 0 : if (pfc_conf == NULL) {
4726 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4727 : : "Cannot set ethdev port %u priority flow control from NULL config",
4728 : : port_id);
4729 : 0 : return -EINVAL;
4730 : : }
4731 : :
4732 [ # # ]: 0 : if (pfc_conf->priority > (RTE_ETH_DCB_NUM_USER_PRIORITIES - 1)) {
4733 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid priority, only 0-7 allowed");
4734 : 0 : return -EINVAL;
4735 : : }
4736 : :
4737 : : /* High water, low water validation are device specific */
4738 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_set == NULL)
4739 : : return -ENOTSUP;
4740 : 0 : ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_set(dev, pfc_conf));
4741 : :
4742 : 0 : rte_ethdev_trace_priority_flow_ctrl_set(port_id, pfc_conf, ret);
4743 : :
4744 : 0 : return ret;
4745 : : }
4746 : :
4747 : : static int
4748 : 0 : validate_rx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
4749 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4750 : : {
4751 [ # # ]: 0 : if ((pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) ||
4752 : : (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
4753 [ # # ]: 0 : if (pfc_queue_conf->rx_pause.tx_qid >= dev_info->nb_tx_queues) {
4754 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4755 : : "PFC Tx queue not in range for Rx pause requested:%d configured:%d",
4756 : : pfc_queue_conf->rx_pause.tx_qid,
4757 : : dev_info->nb_tx_queues);
4758 : 0 : return -EINVAL;
4759 : : }
4760 : :
4761 [ # # ]: 0 : if (pfc_queue_conf->rx_pause.tc >= tc_max) {
4762 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4763 : : "PFC TC not in range for Rx pause requested:%d max:%d",
4764 : : pfc_queue_conf->rx_pause.tc, tc_max);
4765 : 0 : return -EINVAL;
4766 : : }
4767 : : }
4768 : :
4769 : : return 0;
4770 : : }
4771 : :
4772 : : static int
4773 : 0 : validate_tx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
4774 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4775 : : {
4776 [ # # ]: 0 : if ((pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) ||
4777 : : (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
4778 [ # # ]: 0 : if (pfc_queue_conf->tx_pause.rx_qid >= dev_info->nb_rx_queues) {
4779 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4780 : : "PFC Rx queue not in range for Tx pause requested:%d configured:%d",
4781 : : pfc_queue_conf->tx_pause.rx_qid,
4782 : : dev_info->nb_rx_queues);
4783 : 0 : return -EINVAL;
4784 : : }
4785 : :
4786 [ # # ]: 0 : if (pfc_queue_conf->tx_pause.tc >= tc_max) {
4787 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4788 : : "PFC TC not in range for Tx pause requested:%d max:%d",
4789 : : pfc_queue_conf->tx_pause.tc, tc_max);
4790 : 0 : return -EINVAL;
4791 : : }
4792 : : }
4793 : :
4794 : : return 0;
4795 : : }
4796 : :
4797 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_info_get, 22.03)
4798 : : int
4799 : 0 : rte_eth_dev_priority_flow_ctrl_queue_info_get(uint16_t port_id,
4800 : : struct rte_eth_pfc_queue_info *pfc_queue_info)
4801 : : {
4802 : : struct rte_eth_dev *dev;
4803 : : int ret;
4804 : :
4805 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4806 : 0 : dev = &rte_eth_devices[port_id];
4807 : :
4808 [ # # ]: 0 : if (pfc_queue_info == NULL) {
4809 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC info param is NULL for port (%u)",
4810 : : port_id);
4811 : 0 : return -EINVAL;
4812 : : }
4813 : :
4814 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_queue_info_get == NULL)
4815 : : return -ENOTSUP;
4816 : 0 : ret = eth_err(port_id,
4817 : : dev->dev_ops->priority_flow_ctrl_queue_info_get(dev, pfc_queue_info));
4818 : :
4819 : 0 : rte_ethdev_trace_priority_flow_ctrl_queue_info_get(port_id,
4820 : : pfc_queue_info, ret);
4821 : :
4822 : 0 : return ret;
4823 : : }
4824 : :
4825 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_configure, 22.03)
4826 : : int
4827 : 0 : rte_eth_dev_priority_flow_ctrl_queue_configure(uint16_t port_id,
4828 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4829 : : {
4830 : : struct rte_eth_pfc_queue_info pfc_info;
4831 : : struct rte_eth_dev_info dev_info;
4832 : : struct rte_eth_dev *dev;
4833 : : int ret;
4834 : :
4835 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4836 : 0 : dev = &rte_eth_devices[port_id];
4837 : :
4838 [ # # ]: 0 : if (pfc_queue_conf == NULL) {
4839 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC parameters are NULL for port (%u)",
4840 : : port_id);
4841 : 0 : return -EINVAL;
4842 : : }
4843 : :
4844 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4845 [ # # ]: 0 : if (ret != 0)
4846 : : return ret;
4847 : :
4848 : 0 : ret = rte_eth_dev_priority_flow_ctrl_queue_info_get(port_id, &pfc_info);
4849 [ # # ]: 0 : if (ret != 0)
4850 : : return ret;
4851 : :
4852 [ # # ]: 0 : if (pfc_info.tc_max == 0) {
4853 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port %u does not support PFC TC values",
4854 : : port_id);
4855 : 0 : return -ENOTSUP;
4856 : : }
4857 : :
4858 : : /* Check requested mode supported or not */
4859 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE &&
4860 [ # # ]: 0 : pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) {
4861 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC Tx pause unsupported for port (%d)",
4862 : : port_id);
4863 : 0 : return -EINVAL;
4864 : : }
4865 : :
4866 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE &&
4867 [ # # ]: 0 : pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) {
4868 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC Rx pause unsupported for port (%d)",
4869 : : port_id);
4870 : 0 : return -EINVAL;
4871 : : }
4872 : :
4873 : : /* Validate Rx pause parameters */
4874 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
4875 : : pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE) {
4876 : 0 : ret = validate_rx_pause_config(&dev_info, pfc_info.tc_max,
4877 : : pfc_queue_conf);
4878 [ # # ]: 0 : if (ret != 0)
4879 : : return ret;
4880 : : }
4881 : :
4882 : : /* Validate Tx pause parameters */
4883 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
4884 : : pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE) {
4885 : 0 : ret = validate_tx_pause_config(&dev_info, pfc_info.tc_max,
4886 : : pfc_queue_conf);
4887 [ # # ]: 0 : if (ret != 0)
4888 : : return ret;
4889 : : }
4890 : :
4891 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_queue_config == NULL)
4892 : : return -ENOTSUP;
4893 : 0 : ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_queue_config(dev, pfc_queue_conf));
4894 : :
4895 : 0 : rte_ethdev_trace_priority_flow_ctrl_queue_configure(port_id,
4896 : : pfc_queue_conf, ret);
4897 : :
4898 : 0 : return ret;
4899 : : }
4900 : :
4901 : : static int
4902 : : eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
4903 : : uint16_t reta_size)
4904 : : {
4905 : : uint16_t i, num;
4906 : :
4907 : 0 : num = (reta_size + RTE_ETH_RETA_GROUP_SIZE - 1) / RTE_ETH_RETA_GROUP_SIZE;
4908 [ # # # # ]: 0 : for (i = 0; i < num; i++) {
4909 [ # # # # ]: 0 : if (reta_conf[i].mask)
4910 : : return 0;
4911 : : }
4912 : :
4913 : : return -EINVAL;
4914 : : }
4915 : :
4916 : : static int
4917 : 0 : eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
4918 : : uint16_t reta_size,
4919 : : uint16_t max_rxq)
4920 : : {
4921 : : uint16_t i, idx, shift;
4922 : :
4923 [ # # ]: 0 : if (max_rxq == 0) {
4924 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "No receive queue is available");
4925 : 0 : return -EINVAL;
4926 : : }
4927 : :
4928 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4929 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4930 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4931 [ # # ]: 0 : if ((reta_conf[idx].mask & RTE_BIT64(shift)) &&
4932 [ # # ]: 0 : (reta_conf[idx].reta[shift] >= max_rxq)) {
4933 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4934 : : "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u",
4935 : : idx, shift,
4936 : : reta_conf[idx].reta[shift], max_rxq);
4937 : 0 : return -EINVAL;
4938 : : }
4939 : : }
4940 : :
4941 : : return 0;
4942 : : }
4943 : :
4944 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_update)
4945 : : int
4946 : 0 : rte_eth_dev_rss_reta_update(uint16_t port_id,
4947 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4948 : : uint16_t reta_size)
4949 : : {
4950 : : enum rte_eth_rx_mq_mode mq_mode;
4951 : : struct rte_eth_dev *dev;
4952 : : int ret;
4953 : :
4954 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4955 : 0 : dev = &rte_eth_devices[port_id];
4956 : :
4957 [ # # ]: 0 : if (reta_conf == NULL) {
4958 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4959 : : "Cannot update ethdev port %u RSS RETA to NULL",
4960 : : port_id);
4961 : 0 : return -EINVAL;
4962 : : }
4963 : :
4964 [ # # ]: 0 : if (reta_size == 0) {
4965 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4966 : : "Cannot update ethdev port %u RSS RETA with zero size",
4967 : : port_id);
4968 : 0 : return -EINVAL;
4969 : : }
4970 : :
4971 : : /* Check mask bits */
4972 : 0 : ret = eth_check_reta_mask(reta_conf, reta_size);
4973 [ # # ]: 0 : if (ret < 0)
4974 : : return ret;
4975 : :
4976 : : /* Check entry value */
4977 : 0 : ret = eth_check_reta_entry(reta_conf, reta_size,
4978 : 0 : dev->data->nb_rx_queues);
4979 [ # # ]: 0 : if (ret < 0)
4980 : : return ret;
4981 : :
4982 : 0 : mq_mode = dev->data->dev_conf.rxmode.mq_mode;
4983 [ # # ]: 0 : if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
4984 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
4985 : 0 : return -ENOTSUP;
4986 : : }
4987 : :
4988 [ # # ]: 0 : if (dev->dev_ops->reta_update == NULL)
4989 : : return -ENOTSUP;
4990 : 0 : ret = eth_err(port_id, dev->dev_ops->reta_update(dev, reta_conf, reta_size));
4991 : :
4992 : 0 : rte_ethdev_trace_rss_reta_update(port_id, reta_conf, reta_size, ret);
4993 : :
4994 : 0 : return ret;
4995 : : }
4996 : :
4997 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_query)
4998 : : int
4999 : 0 : rte_eth_dev_rss_reta_query(uint16_t port_id,
5000 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5001 : : uint16_t reta_size)
5002 : : {
5003 : : struct rte_eth_dev *dev;
5004 : : int ret;
5005 : :
5006 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5007 : 0 : dev = &rte_eth_devices[port_id];
5008 : :
5009 [ # # ]: 0 : if (reta_conf == NULL) {
5010 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5011 : : "Cannot query ethdev port %u RSS RETA from NULL config",
5012 : : port_id);
5013 : 0 : return -EINVAL;
5014 : : }
5015 : :
5016 : : /* Check mask bits */
5017 : 0 : ret = eth_check_reta_mask(reta_conf, reta_size);
5018 [ # # ]: 0 : if (ret < 0)
5019 : : return ret;
5020 : :
5021 [ # # ]: 0 : if (dev->dev_ops->reta_query == NULL)
5022 : : return -ENOTSUP;
5023 : 0 : ret = eth_err(port_id, dev->dev_ops->reta_query(dev, reta_conf, reta_size));
5024 : :
5025 : 0 : rte_ethdev_trace_rss_reta_query(port_id, reta_conf, reta_size, ret);
5026 : :
5027 : 0 : return ret;
5028 : : }
5029 : :
5030 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_update)
5031 : : int
5032 : 0 : rte_eth_dev_rss_hash_update(uint16_t port_id,
5033 : : struct rte_eth_rss_conf *rss_conf)
5034 : : {
5035 : : struct rte_eth_dev *dev;
5036 : 0 : struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
5037 : : enum rte_eth_rx_mq_mode mq_mode;
5038 : : int ret;
5039 : :
5040 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5041 : 0 : dev = &rte_eth_devices[port_id];
5042 : :
5043 [ # # ]: 0 : if (rss_conf == NULL) {
5044 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5045 : : "Cannot update ethdev port %u RSS hash from NULL config",
5046 : : port_id);
5047 : 0 : return -EINVAL;
5048 : : }
5049 : :
5050 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5051 [ # # ]: 0 : if (ret != 0)
5052 : : return ret;
5053 : :
5054 [ # # ]: 0 : rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
5055 [ # # ]: 0 : if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
5056 : : dev_info.flow_type_rss_offloads) {
5057 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5058 : : "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64,
5059 : : port_id, rss_conf->rss_hf,
5060 : : dev_info.flow_type_rss_offloads);
5061 : 0 : return -EINVAL;
5062 : : }
5063 : :
5064 : 0 : mq_mode = dev->data->dev_conf.rxmode.mq_mode;
5065 [ # # ]: 0 : if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
5066 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
5067 : 0 : return -ENOTSUP;
5068 : : }
5069 : :
5070 [ # # ]: 0 : if (rss_conf->rss_key != NULL &&
5071 [ # # ]: 0 : rss_conf->rss_key_len != dev_info.hash_key_size) {
5072 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5073 : : "Ethdev port_id=%u invalid RSS key len: %u, valid value: %u",
5074 : : port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
5075 : 0 : return -EINVAL;
5076 : : }
5077 : :
5078 [ # # ]: 0 : if ((size_t)rss_conf->algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
5079 : 0 : (dev_info.rss_algo_capa &
5080 [ # # ]: 0 : RTE_ETH_HASH_ALGO_TO_CAPA(rss_conf->algorithm)) == 0) {
5081 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5082 : : "Ethdev port_id=%u configured RSS hash algorithm (%u)"
5083 : : "is not in the algorithm capability (0x%" PRIx32 ")",
5084 : : port_id, rss_conf->algorithm, dev_info.rss_algo_capa);
5085 : 0 : return -EINVAL;
5086 : : }
5087 : :
5088 [ # # ]: 0 : if (dev->dev_ops->rss_hash_update == NULL)
5089 : : return -ENOTSUP;
5090 : 0 : ret = eth_err(port_id, dev->dev_ops->rss_hash_update(dev, rss_conf));
5091 : :
5092 : 0 : rte_ethdev_trace_rss_hash_update(port_id, rss_conf, ret);
5093 : :
5094 : 0 : return ret;
5095 : : }
5096 : :
5097 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_conf_get)
5098 : : int
5099 : 1 : rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
5100 : : struct rte_eth_rss_conf *rss_conf)
5101 : : {
5102 : 1 : struct rte_eth_dev_info dev_info = { 0 };
5103 : : struct rte_eth_dev *dev;
5104 : : int ret;
5105 : :
5106 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5107 : 1 : dev = &rte_eth_devices[port_id];
5108 : :
5109 [ - + ]: 1 : if (rss_conf == NULL) {
5110 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5111 : : "Cannot get ethdev port %u RSS hash config to NULL",
5112 : : port_id);
5113 : 0 : return -EINVAL;
5114 : : }
5115 : :
5116 : 1 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5117 [ + - ]: 1 : if (ret != 0)
5118 : : return ret;
5119 : :
5120 [ + - ]: 1 : if (rss_conf->rss_key != NULL &&
5121 [ - + ]: 1 : rss_conf->rss_key_len < dev_info.hash_key_size) {
5122 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5123 : : "Ethdev port_id=%u invalid RSS key len: %u, should not be less than: %u",
5124 : : port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
5125 : 0 : return -EINVAL;
5126 : : }
5127 : :
5128 : 1 : rss_conf->algorithm = RTE_ETH_HASH_FUNCTION_DEFAULT;
5129 : :
5130 [ + - ]: 1 : if (dev->dev_ops->rss_hash_conf_get == NULL)
5131 : : return -ENOTSUP;
5132 : 1 : ret = eth_err(port_id, dev->dev_ops->rss_hash_conf_get(dev, rss_conf));
5133 : :
5134 : 1 : rte_ethdev_trace_rss_hash_conf_get(port_id, rss_conf, ret);
5135 : :
5136 : 1 : return ret;
5137 : : }
5138 : :
5139 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_rss_algo_name, 23.11)
5140 : : const char *
5141 : 1 : rte_eth_dev_rss_algo_name(enum rte_eth_hash_function rss_algo)
5142 : : {
5143 : : const char *name = "Unknown function";
5144 : : unsigned int i;
5145 : :
5146 [ + - ]: 1 : for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
5147 [ + - ]: 1 : if (rss_algo == rte_eth_dev_rss_algo_names[i].algo)
5148 : 1 : return rte_eth_dev_rss_algo_names[i].name;
5149 : : }
5150 : :
5151 : : return name;
5152 : : }
5153 : :
5154 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_find_rss_algo, 24.03)
5155 : : int
5156 : 0 : rte_eth_find_rss_algo(const char *name, uint32_t *algo)
5157 : : {
5158 : : unsigned int i;
5159 : :
5160 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
5161 [ # # ]: 0 : if (strcmp(name, rte_eth_dev_rss_algo_names[i].name) == 0) {
5162 : 0 : *algo = rte_eth_dev_rss_algo_names[i].algo;
5163 : 0 : return 0;
5164 : : }
5165 : : }
5166 : :
5167 : : return -EINVAL;
5168 : : }
5169 : :
5170 : : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_add)
5171 : : int
5172 : 0 : rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
5173 : : struct rte_eth_udp_tunnel *udp_tunnel)
5174 : : {
5175 : : struct rte_eth_dev *dev;
5176 : : int ret;
5177 : :
5178 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5179 : 0 : dev = &rte_eth_devices[port_id];
5180 : :
5181 [ # # ]: 0 : if (udp_tunnel == NULL) {
5182 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5183 : : "Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel",
5184 : : port_id);
5185 : 0 : return -EINVAL;
5186 : : }
5187 : :
5188 [ # # ]: 0 : if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
5189 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
5190 : 0 : return -EINVAL;
5191 : : }
5192 : :
5193 [ # # ]: 0 : if (dev->dev_ops->udp_tunnel_port_add == NULL)
5194 : : return -ENOTSUP;
5195 : 0 : ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_add(dev, udp_tunnel));
5196 : :
5197 : 0 : rte_ethdev_trace_udp_tunnel_port_add(port_id, udp_tunnel, ret);
5198 : :
5199 : 0 : return ret;
5200 : : }
5201 : :
5202 : : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_delete)
5203 : : int
5204 : 0 : rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
5205 : : struct rte_eth_udp_tunnel *udp_tunnel)
5206 : : {
5207 : : struct rte_eth_dev *dev;
5208 : : int ret;
5209 : :
5210 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5211 : 0 : dev = &rte_eth_devices[port_id];
5212 : :
5213 [ # # ]: 0 : if (udp_tunnel == NULL) {
5214 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5215 : : "Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel",
5216 : : port_id);
5217 : 0 : return -EINVAL;
5218 : : }
5219 : :
5220 [ # # ]: 0 : if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
5221 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
5222 : 0 : return -EINVAL;
5223 : : }
5224 : :
5225 [ # # ]: 0 : if (dev->dev_ops->udp_tunnel_port_del == NULL)
5226 : : return -ENOTSUP;
5227 : 0 : ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_del(dev, udp_tunnel));
5228 : :
5229 : 0 : rte_ethdev_trace_udp_tunnel_port_delete(port_id, udp_tunnel, ret);
5230 : :
5231 : 0 : return ret;
5232 : : }
5233 : :
5234 : : RTE_EXPORT_SYMBOL(rte_eth_led_on)
5235 : : int
5236 : 0 : rte_eth_led_on(uint16_t port_id)
5237 : : {
5238 : : struct rte_eth_dev *dev;
5239 : : int ret;
5240 : :
5241 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5242 : 0 : dev = &rte_eth_devices[port_id];
5243 : :
5244 [ # # ]: 0 : if (dev->dev_ops->dev_led_on == NULL)
5245 : : return -ENOTSUP;
5246 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_led_on(dev));
5247 : :
5248 : 0 : rte_eth_trace_led_on(port_id, ret);
5249 : :
5250 : 0 : return ret;
5251 : : }
5252 : :
5253 : : RTE_EXPORT_SYMBOL(rte_eth_led_off)
5254 : : int
5255 : 0 : rte_eth_led_off(uint16_t port_id)
5256 : : {
5257 : : struct rte_eth_dev *dev;
5258 : : int ret;
5259 : :
5260 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5261 : 0 : dev = &rte_eth_devices[port_id];
5262 : :
5263 [ # # ]: 0 : if (dev->dev_ops->dev_led_off == NULL)
5264 : : return -ENOTSUP;
5265 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_led_off(dev));
5266 : :
5267 : 0 : rte_eth_trace_led_off(port_id, ret);
5268 : :
5269 : 0 : return ret;
5270 : : }
5271 : :
5272 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_get_capability, 20.11)
5273 : : int
5274 : 0 : rte_eth_fec_get_capability(uint16_t port_id,
5275 : : struct rte_eth_fec_capa *speed_fec_capa,
5276 : : unsigned int num)
5277 : : {
5278 : : struct rte_eth_dev *dev;
5279 : : int ret;
5280 : :
5281 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5282 : 0 : dev = &rte_eth_devices[port_id];
5283 : :
5284 [ # # ]: 0 : if (speed_fec_capa == NULL && num > 0) {
5285 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5286 : : "Cannot get ethdev port %u FEC capability to NULL when array size is non zero",
5287 : : port_id);
5288 : 0 : return -EINVAL;
5289 : : }
5290 : :
5291 [ # # ]: 0 : if (dev->dev_ops->fec_get_capability == NULL)
5292 : : return -ENOTSUP;
5293 : 0 : ret = dev->dev_ops->fec_get_capability(dev, speed_fec_capa, num);
5294 : :
5295 : 0 : rte_eth_trace_fec_get_capability(port_id, speed_fec_capa, num, ret);
5296 : :
5297 : 0 : return ret;
5298 : : }
5299 : :
5300 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_get, 20.11)
5301 : : int
5302 : 1 : rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
5303 : : {
5304 : : struct rte_eth_dev *dev;
5305 : : int ret;
5306 : :
5307 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5308 : 1 : dev = &rte_eth_devices[port_id];
5309 : :
5310 [ - + ]: 1 : if (fec_capa == NULL) {
5311 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5312 : : "Cannot get ethdev port %u current FEC mode to NULL",
5313 : : port_id);
5314 : 0 : return -EINVAL;
5315 : : }
5316 : :
5317 [ - + ]: 1 : if (dev->dev_ops->fec_get == NULL)
5318 : : return -ENOTSUP;
5319 : 0 : ret = eth_err(port_id, dev->dev_ops->fec_get(dev, fec_capa));
5320 : :
5321 : 0 : rte_eth_trace_fec_get(port_id, fec_capa, ret);
5322 : :
5323 : 0 : return ret;
5324 : : }
5325 : :
5326 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_set, 20.11)
5327 : : int
5328 : 0 : rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
5329 : : {
5330 : : struct rte_eth_dev *dev;
5331 : : int ret;
5332 : :
5333 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5334 : 0 : dev = &rte_eth_devices[port_id];
5335 : :
5336 [ # # ]: 0 : if (fec_capa == 0) {
5337 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "At least one FEC mode should be specified");
5338 : 0 : return -EINVAL;
5339 : : }
5340 : :
5341 [ # # ]: 0 : if (dev->dev_ops->fec_set == NULL)
5342 : : return -ENOTSUP;
5343 : 0 : ret = eth_err(port_id, dev->dev_ops->fec_set(dev, fec_capa));
5344 : :
5345 : 0 : rte_eth_trace_fec_set(port_id, fec_capa, ret);
5346 : :
5347 : 0 : return ret;
5348 : : }
5349 : :
5350 : : /*
5351 : : * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
5352 : : * an empty spot.
5353 : : */
5354 : : static int
5355 : 0 : eth_dev_get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
5356 : : {
5357 : : struct rte_eth_dev_info dev_info;
5358 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
5359 : : unsigned i;
5360 : : int ret;
5361 : :
5362 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5363 [ # # ]: 0 : if (ret != 0)
5364 : : return -1;
5365 : :
5366 [ # # ]: 0 : for (i = 0; i < dev_info.max_mac_addrs; i++)
5367 [ # # ]: 0 : if (memcmp(addr, &dev->data->mac_addrs[i],
5368 : : RTE_ETHER_ADDR_LEN) == 0)
5369 : 0 : return i;
5370 : :
5371 : : return -1;
5372 : : }
5373 : :
5374 : : static const struct rte_ether_addr null_mac_addr;
5375 : :
5376 : : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_add)
5377 : : int
5378 : 0 : rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
5379 : : uint32_t pool)
5380 : : {
5381 : : struct rte_eth_dev *dev;
5382 : : int index;
5383 : : uint64_t pool_mask;
5384 : : int ret;
5385 : :
5386 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5387 : 0 : dev = &rte_eth_devices[port_id];
5388 : :
5389 [ # # ]: 0 : if (addr == NULL) {
5390 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5391 : : "Cannot add ethdev port %u MAC address from NULL address",
5392 : : port_id);
5393 : 0 : return -EINVAL;
5394 : : }
5395 : :
5396 [ # # ]: 0 : if (dev->dev_ops->mac_addr_add == NULL)
5397 : : return -ENOTSUP;
5398 : :
5399 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr)) {
5400 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
5401 : : port_id);
5402 : 0 : return -EINVAL;
5403 : : }
5404 [ # # ]: 0 : if (pool >= RTE_ETH_64_POOLS) {
5405 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Pool ID must be 0-%d", RTE_ETH_64_POOLS - 1);
5406 : 0 : return -EINVAL;
5407 : : }
5408 : :
5409 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5410 [ # # ]: 0 : if (index < 0) {
5411 : 0 : index = eth_dev_get_mac_addr_index(port_id, &null_mac_addr);
5412 [ # # ]: 0 : if (index < 0) {
5413 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
5414 : : port_id);
5415 : 0 : return -ENOSPC;
5416 : : }
5417 : : } else {
5418 : 0 : pool_mask = dev->data->mac_pool_sel[index];
5419 : :
5420 : : /* Check if both MAC address and pool is already there, and do nothing */
5421 [ # # ]: 0 : if (pool_mask & RTE_BIT64(pool))
5422 : : return 0;
5423 : : }
5424 : :
5425 : : /* Update NIC */
5426 : 0 : ret = dev->dev_ops->mac_addr_add(dev, addr, index, pool);
5427 : :
5428 [ # # ]: 0 : if (ret == 0) {
5429 : : /* Update address in NIC data structure */
5430 : 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
5431 : :
5432 : : /* Update pool bitmap in NIC data structure */
5433 : 0 : dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
5434 : : }
5435 : :
5436 : 0 : ret = eth_err(port_id, ret);
5437 : :
5438 : 0 : rte_ethdev_trace_mac_addr_add(port_id, addr, pool, ret);
5439 : :
5440 : 0 : return ret;
5441 : : }
5442 : :
5443 : : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_remove)
5444 : : int
5445 : 0 : rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
5446 : : {
5447 : : struct rte_eth_dev *dev;
5448 : : int index;
5449 : :
5450 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5451 : 0 : dev = &rte_eth_devices[port_id];
5452 : :
5453 [ # # ]: 0 : if (addr == NULL) {
5454 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5455 : : "Cannot remove ethdev port %u MAC address from NULL address",
5456 : : port_id);
5457 : 0 : return -EINVAL;
5458 : : }
5459 : :
5460 [ # # ]: 0 : if (dev->dev_ops->mac_addr_remove == NULL)
5461 : : return -ENOTSUP;
5462 : :
5463 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5464 [ # # ]: 0 : if (index == 0) {
5465 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5466 : : "Port %u: Cannot remove default MAC address",
5467 : : port_id);
5468 : 0 : return -EADDRINUSE;
5469 [ # # ]: 0 : } else if (index < 0)
5470 : : return 0; /* Do nothing if address wasn't found */
5471 : :
5472 : : /* Update NIC */
5473 : 0 : dev->dev_ops->mac_addr_remove(dev, index);
5474 : :
5475 : : /* Update address in NIC data structure */
5476 [ # # ]: 0 : rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
5477 : :
5478 : : /* reset pool bitmap */
5479 [ # # ]: 0 : dev->data->mac_pool_sel[index] = 0;
5480 : :
5481 : 0 : rte_ethdev_trace_mac_addr_remove(port_id, addr);
5482 : :
5483 : 0 : return 0;
5484 : : }
5485 : :
5486 : : RTE_EXPORT_SYMBOL(rte_eth_dev_default_mac_addr_set)
5487 : : int
5488 : 0 : rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
5489 : : {
5490 : : struct rte_eth_dev *dev;
5491 : : int index;
5492 : : int ret;
5493 : :
5494 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5495 : 0 : dev = &rte_eth_devices[port_id];
5496 : :
5497 [ # # ]: 0 : if (addr == NULL) {
5498 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5499 : : "Cannot set ethdev port %u default MAC address from NULL address",
5500 : : port_id);
5501 : 0 : return -EINVAL;
5502 : : }
5503 : :
5504 : : if (!rte_is_valid_assigned_ether_addr(addr))
5505 : : return -EINVAL;
5506 : :
5507 [ # # ]: 0 : if (dev->dev_ops->mac_addr_set == NULL)
5508 : : return -ENOTSUP;
5509 : :
5510 : : /* Keep address unique in dev->data->mac_addrs[]. */
5511 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5512 [ # # ]: 0 : if (index > 0) {
5513 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5514 : : "New default address for port %u was already in the address list. Please remove it first.",
5515 : : port_id);
5516 : 0 : return -EEXIST;
5517 : : }
5518 : :
5519 : 0 : ret = dev->dev_ops->mac_addr_set(dev, addr);
5520 [ # # ]: 0 : if (ret < 0)
5521 : : return ret;
5522 : :
5523 : : /* Update default address in NIC data structure */
5524 [ # # ]: 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
5525 : :
5526 : 0 : rte_ethdev_trace_default_mac_addr_set(port_id, addr);
5527 : :
5528 : 0 : return 0;
5529 : : }
5530 : :
5531 : :
5532 : : /*
5533 : : * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
5534 : : * an empty spot.
5535 : : */
5536 : : static int
5537 : 0 : eth_dev_get_hash_mac_addr_index(uint16_t port_id,
5538 : : const struct rte_ether_addr *addr)
5539 : : {
5540 : : struct rte_eth_dev_info dev_info;
5541 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
5542 : : unsigned i;
5543 : : int ret;
5544 : :
5545 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5546 [ # # ]: 0 : if (ret != 0)
5547 : : return -1;
5548 : :
5549 [ # # ]: 0 : if (!dev->data->hash_mac_addrs)
5550 : : return -1;
5551 : :
5552 [ # # ]: 0 : for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
5553 [ # # ]: 0 : if (memcmp(addr, &dev->data->hash_mac_addrs[i],
5554 : : RTE_ETHER_ADDR_LEN) == 0)
5555 : 0 : return i;
5556 : :
5557 : : return -1;
5558 : : }
5559 : :
5560 : : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_hash_table_set)
5561 : : int
5562 : 0 : rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
5563 : : uint8_t on)
5564 : : {
5565 : : int index;
5566 : : int ret;
5567 : : struct rte_eth_dev *dev;
5568 : :
5569 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5570 : 0 : dev = &rte_eth_devices[port_id];
5571 : :
5572 [ # # ]: 0 : if (addr == NULL) {
5573 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5574 : : "Cannot set ethdev port %u unicast hash table from NULL address",
5575 : : port_id);
5576 : 0 : return -EINVAL;
5577 : : }
5578 : :
5579 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr)) {
5580 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
5581 : : port_id);
5582 : 0 : return -EINVAL;
5583 : : }
5584 : :
5585 : 0 : index = eth_dev_get_hash_mac_addr_index(port_id, addr);
5586 : : /* Check if it's already there, and do nothing */
5587 [ # # ]: 0 : if ((index >= 0) && on)
5588 : : return 0;
5589 : :
5590 [ # # ]: 0 : if (index < 0) {
5591 [ # # ]: 0 : if (!on) {
5592 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5593 : : "Port %u: the MAC address was not set in UTA",
5594 : : port_id);
5595 : 0 : return -EINVAL;
5596 : : }
5597 : :
5598 : 0 : index = eth_dev_get_hash_mac_addr_index(port_id, &null_mac_addr);
5599 [ # # ]: 0 : if (index < 0) {
5600 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
5601 : : port_id);
5602 : 0 : return -ENOSPC;
5603 : : }
5604 : : }
5605 : :
5606 [ # # ]: 0 : if (dev->dev_ops->uc_hash_table_set == NULL)
5607 : : return -ENOTSUP;
5608 : 0 : ret = dev->dev_ops->uc_hash_table_set(dev, addr, on);
5609 [ # # ]: 0 : if (ret == 0) {
5610 : : /* Update address in NIC data structure */
5611 [ # # ]: 0 : if (on)
5612 : 0 : rte_ether_addr_copy(addr,
5613 : 0 : &dev->data->hash_mac_addrs[index]);
5614 : : else
5615 : 0 : rte_ether_addr_copy(&null_mac_addr,
5616 : 0 : &dev->data->hash_mac_addrs[index]);
5617 : : }
5618 : :
5619 : 0 : ret = eth_err(port_id, ret);
5620 : :
5621 : 0 : rte_ethdev_trace_uc_hash_table_set(port_id, on, ret);
5622 : :
5623 : 0 : return ret;
5624 : : }
5625 : :
5626 : : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_all_hash_table_set)
5627 : : int
5628 : 0 : rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
5629 : : {
5630 : : struct rte_eth_dev *dev;
5631 : : int ret;
5632 : :
5633 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5634 : 0 : dev = &rte_eth_devices[port_id];
5635 : :
5636 [ # # ]: 0 : if (dev->dev_ops->uc_all_hash_table_set == NULL)
5637 : : return -ENOTSUP;
5638 : 0 : ret = eth_err(port_id, dev->dev_ops->uc_all_hash_table_set(dev, on));
5639 : :
5640 : 0 : rte_ethdev_trace_uc_all_hash_table_set(port_id, on, ret);
5641 : :
5642 : 0 : return ret;
5643 : : }
5644 : :
5645 : : RTE_EXPORT_SYMBOL(rte_eth_set_queue_rate_limit)
5646 : 0 : int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
5647 : : uint32_t tx_rate)
5648 : : {
5649 : : struct rte_eth_dev *dev;
5650 : : struct rte_eth_dev_info dev_info;
5651 : : struct rte_eth_link link;
5652 : : int ret;
5653 : :
5654 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5655 : 0 : dev = &rte_eth_devices[port_id];
5656 : :
5657 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5658 [ # # ]: 0 : if (ret != 0)
5659 : : return ret;
5660 : :
5661 : 0 : link = dev->data->dev_link;
5662 : :
5663 [ # # ]: 0 : if (queue_idx > dev_info.max_tx_queues) {
5664 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5665 : : "Set queue rate limit:port %u: invalid queue ID=%u",
5666 : : port_id, queue_idx);
5667 : 0 : return -EINVAL;
5668 : : }
5669 : :
5670 [ # # ]: 0 : if (tx_rate > link.link_speed) {
5671 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5672 : : "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d",
5673 : : tx_rate, link.link_speed);
5674 : 0 : return -EINVAL;
5675 : : }
5676 : :
5677 [ # # ]: 0 : if (dev->dev_ops->set_queue_rate_limit == NULL)
5678 : : return -ENOTSUP;
5679 : 0 : ret = eth_err(port_id, dev->dev_ops->set_queue_rate_limit(dev, queue_idx, tx_rate));
5680 : :
5681 [ # # ]: 0 : rte_eth_trace_set_queue_rate_limit(port_id, queue_idx, tx_rate, ret);
5682 : :
5683 : 0 : return ret;
5684 : : }
5685 : :
5686 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_avail_thresh_set, 22.07)
5687 : 0 : int rte_eth_rx_avail_thresh_set(uint16_t port_id, uint16_t queue_id,
5688 : : uint8_t avail_thresh)
5689 : : {
5690 : : struct rte_eth_dev *dev;
5691 : : int ret;
5692 : :
5693 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5694 : 0 : dev = &rte_eth_devices[port_id];
5695 : :
5696 [ # # ]: 0 : if (queue_id > dev->data->nb_rx_queues) {
5697 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5698 : : "Set queue avail thresh: port %u: invalid queue ID=%u.",
5699 : : port_id, queue_id);
5700 : 0 : return -EINVAL;
5701 : : }
5702 : :
5703 [ # # ]: 0 : if (avail_thresh > 99) {
5704 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5705 : : "Set queue avail thresh: port %u: threshold should be <= 99.",
5706 : : port_id);
5707 : 0 : return -EINVAL;
5708 : : }
5709 [ # # ]: 0 : if (dev->dev_ops->rx_queue_avail_thresh_set == NULL)
5710 : : return -ENOTSUP;
5711 : 0 : ret = eth_err(port_id,
5712 : : dev->dev_ops->rx_queue_avail_thresh_set(dev, queue_id, avail_thresh));
5713 : :
5714 : 0 : rte_eth_trace_rx_avail_thresh_set(port_id, queue_id, avail_thresh, ret);
5715 : :
5716 : 0 : return ret;
5717 : : }
5718 : :
5719 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_avail_thresh_query, 22.07)
5720 : 0 : int rte_eth_rx_avail_thresh_query(uint16_t port_id, uint16_t *queue_id,
5721 : : uint8_t *avail_thresh)
5722 : : {
5723 : : struct rte_eth_dev *dev;
5724 : : int ret;
5725 : :
5726 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5727 : 0 : dev = &rte_eth_devices[port_id];
5728 : :
5729 [ # # ]: 0 : if (queue_id == NULL)
5730 : : return -EINVAL;
5731 [ # # ]: 0 : if (*queue_id >= dev->data->nb_rx_queues)
5732 : 0 : *queue_id = 0;
5733 : :
5734 [ # # ]: 0 : if (dev->dev_ops->rx_queue_avail_thresh_query == NULL)
5735 : : return -ENOTSUP;
5736 : 0 : ret = eth_err(port_id,
5737 : : dev->dev_ops->rx_queue_avail_thresh_query(dev, queue_id, avail_thresh));
5738 : :
5739 [ # # ]: 0 : rte_eth_trace_rx_avail_thresh_query(port_id, *queue_id, ret);
5740 : :
5741 : 0 : return ret;
5742 : : }
5743 : :
5744 : 258 : RTE_INIT(eth_dev_init_fp_ops)
5745 : : {
5746 : : uint32_t i;
5747 : :
5748 [ + + ]: 8514 : for (i = 0; i != RTE_DIM(rte_eth_fp_ops); i++)
5749 : 8256 : eth_dev_fp_ops_reset(rte_eth_fp_ops + i);
5750 : 258 : }
5751 : :
5752 : 258 : RTE_INIT(eth_dev_init_cb_lists)
5753 : : {
5754 : : uint16_t i;
5755 : :
5756 [ + + ]: 8514 : for (i = 0; i < RTE_MAX_ETHPORTS; i++)
5757 : 8256 : TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
5758 : 258 : }
5759 : :
5760 : : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_register)
5761 : : int
5762 : 0 : rte_eth_dev_callback_register(uint16_t port_id,
5763 : : enum rte_eth_event_type event,
5764 : : rte_eth_dev_cb_fn cb_fn, void *cb_arg)
5765 : : {
5766 : : struct rte_eth_dev *dev;
5767 : : struct rte_eth_dev_callback *user_cb;
5768 : : uint16_t next_port;
5769 : : uint16_t last_port;
5770 : :
5771 [ # # ]: 0 : if (cb_fn == NULL) {
5772 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5773 : : "Cannot register ethdev port %u callback from NULL",
5774 : : port_id);
5775 : 0 : return -EINVAL;
5776 : : }
5777 : :
5778 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
5779 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
5780 : 0 : return -EINVAL;
5781 : : }
5782 : :
5783 [ # # ]: 0 : if (port_id == RTE_ETH_ALL) {
5784 : : next_port = 0;
5785 : : last_port = RTE_MAX_ETHPORTS - 1;
5786 : : } else {
5787 : : next_port = last_port = port_id;
5788 : : }
5789 : :
5790 : : rte_spinlock_lock(ð_dev_cb_lock);
5791 : :
5792 : : do {
5793 : 0 : dev = &rte_eth_devices[next_port];
5794 : :
5795 [ # # ]: 0 : TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
5796 [ # # ]: 0 : if (user_cb->cb_fn == cb_fn &&
5797 [ # # ]: 0 : user_cb->cb_arg == cb_arg &&
5798 [ # # ]: 0 : user_cb->event == event) {
5799 : : break;
5800 : : }
5801 : : }
5802 : :
5803 : : /* create a new callback. */
5804 [ # # ]: 0 : if (user_cb == NULL) {
5805 : 0 : user_cb = rte_zmalloc("INTR_USER_CALLBACK",
5806 : : sizeof(struct rte_eth_dev_callback), 0);
5807 [ # # ]: 0 : if (user_cb != NULL) {
5808 : 0 : user_cb->cb_fn = cb_fn;
5809 : 0 : user_cb->cb_arg = cb_arg;
5810 : 0 : user_cb->event = event;
5811 : 0 : TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
5812 : : user_cb, next);
5813 : : } else {
5814 : : rte_spinlock_unlock(ð_dev_cb_lock);
5815 : 0 : rte_eth_dev_callback_unregister(port_id, event,
5816 : : cb_fn, cb_arg);
5817 : 0 : return -ENOMEM;
5818 : : }
5819 : :
5820 : : }
5821 [ # # ]: 0 : } while (++next_port <= last_port);
5822 : :
5823 : : rte_spinlock_unlock(ð_dev_cb_lock);
5824 : :
5825 : 0 : rte_ethdev_trace_callback_register(port_id, event, cb_fn, cb_arg);
5826 : :
5827 : 0 : return 0;
5828 : : }
5829 : :
5830 : : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_unregister)
5831 : : int
5832 : 0 : rte_eth_dev_callback_unregister(uint16_t port_id,
5833 : : enum rte_eth_event_type event,
5834 : : rte_eth_dev_cb_fn cb_fn, void *cb_arg)
5835 : : {
5836 : : int ret;
5837 : : struct rte_eth_dev *dev;
5838 : : struct rte_eth_dev_callback *cb, *next;
5839 : : uint16_t next_port;
5840 : : uint16_t last_port;
5841 : :
5842 [ # # ]: 0 : if (cb_fn == NULL) {
5843 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5844 : : "Cannot unregister ethdev port %u callback from NULL",
5845 : : port_id);
5846 : 0 : return -EINVAL;
5847 : : }
5848 : :
5849 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
5850 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
5851 : 0 : return -EINVAL;
5852 : : }
5853 : :
5854 [ # # ]: 0 : if (port_id == RTE_ETH_ALL) {
5855 : : next_port = 0;
5856 : : last_port = RTE_MAX_ETHPORTS - 1;
5857 : : } else {
5858 : : next_port = last_port = port_id;
5859 : : }
5860 : :
5861 : : rte_spinlock_lock(ð_dev_cb_lock);
5862 : :
5863 : : do {
5864 : 0 : dev = &rte_eth_devices[next_port];
5865 : : ret = 0;
5866 [ # # ]: 0 : for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
5867 : : cb = next) {
5868 : :
5869 : 0 : next = TAILQ_NEXT(cb, next);
5870 : :
5871 [ # # # # : 0 : if (cb->cb_fn != cb_fn || cb->event != event ||
# # ]
5872 [ # # ]: 0 : (cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
5873 : 0 : continue;
5874 : :
5875 : : /*
5876 : : * if this callback is not executing right now,
5877 : : * then remove it.
5878 : : */
5879 [ # # ]: 0 : if (cb->active == 0) {
5880 [ # # ]: 0 : TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
5881 : 0 : rte_free(cb);
5882 : : } else {
5883 : : ret = -EAGAIN;
5884 : : }
5885 : : }
5886 [ # # ]: 0 : } while (++next_port <= last_port);
5887 : :
5888 : : rte_spinlock_unlock(ð_dev_cb_lock);
5889 : :
5890 : 0 : rte_ethdev_trace_callback_unregister(port_id, event, cb_fn, cb_arg,
5891 : : ret);
5892 : :
5893 : 0 : return ret;
5894 : : }
5895 : :
5896 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl)
5897 : : int
5898 : 0 : rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
5899 : : {
5900 : : uint32_t vec;
5901 : : struct rte_eth_dev *dev;
5902 : : struct rte_intr_handle *intr_handle;
5903 : : uint16_t qid;
5904 : : int rc;
5905 : :
5906 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5907 : : dev = &rte_eth_devices[port_id];
5908 : :
5909 [ # # ]: 0 : if (!dev->intr_handle) {
5910 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5911 : 0 : return -ENOTSUP;
5912 : : }
5913 : :
5914 : : intr_handle = dev->intr_handle;
5915 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
5916 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
5917 : 0 : return -EPERM;
5918 : : }
5919 : :
5920 [ # # ]: 0 : for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
5921 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, qid);
5922 : 0 : rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
5923 : :
5924 : 0 : rte_ethdev_trace_rx_intr_ctl(port_id, qid, epfd, op, data, rc);
5925 : :
5926 [ # # ]: 0 : if (rc && rc != -EEXIST) {
5927 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5928 : : "p %u q %u Rx ctl error op %d epfd %d vec %u",
5929 : : port_id, qid, op, epfd, vec);
5930 : : }
5931 : : }
5932 : :
5933 : : return 0;
5934 : : }
5935 : :
5936 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q_get_fd)
5937 : : int
5938 : 0 : rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
5939 : : {
5940 : : struct rte_intr_handle *intr_handle;
5941 : : struct rte_eth_dev *dev;
5942 : : unsigned int efd_idx;
5943 : : uint32_t vec;
5944 : : int fd;
5945 : :
5946 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
5947 : : dev = &rte_eth_devices[port_id];
5948 : :
5949 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
5950 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
5951 : 0 : return -1;
5952 : : }
5953 : :
5954 [ # # ]: 0 : if (!dev->intr_handle) {
5955 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5956 : 0 : return -1;
5957 : : }
5958 : :
5959 : : intr_handle = dev->intr_handle;
5960 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
5961 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
5962 : 0 : return -1;
5963 : : }
5964 : :
5965 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
5966 : : efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
5967 [ # # ]: 0 : (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
5968 : 0 : fd = rte_intr_efds_index_get(intr_handle, efd_idx);
5969 : :
5970 : 0 : rte_ethdev_trace_rx_intr_ctl_q_get_fd(port_id, queue_id, fd);
5971 : :
5972 : 0 : return fd;
5973 : : }
5974 : :
5975 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q)
5976 : : int
5977 : 0 : rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
5978 : : int epfd, int op, void *data)
5979 : : {
5980 : : uint32_t vec;
5981 : : struct rte_eth_dev *dev;
5982 : : struct rte_intr_handle *intr_handle;
5983 : : int rc;
5984 : :
5985 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5986 : : dev = &rte_eth_devices[port_id];
5987 : :
5988 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
5989 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
5990 : 0 : return -EINVAL;
5991 : : }
5992 : :
5993 [ # # ]: 0 : if (!dev->intr_handle) {
5994 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5995 : 0 : return -ENOTSUP;
5996 : : }
5997 : :
5998 : : intr_handle = dev->intr_handle;
5999 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
6000 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
6001 : 0 : return -EPERM;
6002 : : }
6003 : :
6004 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
6005 : 0 : rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
6006 : :
6007 : 0 : rte_ethdev_trace_rx_intr_ctl_q(port_id, queue_id, epfd, op, data, rc);
6008 : :
6009 [ # # ]: 0 : if (rc && rc != -EEXIST) {
6010 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6011 : : "p %u q %u Rx ctl error op %d epfd %d vec %u",
6012 : : port_id, queue_id, op, epfd, vec);
6013 : 0 : return rc;
6014 : : }
6015 : :
6016 : : return 0;
6017 : : }
6018 : :
6019 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_enable)
6020 : : int
6021 : 0 : rte_eth_dev_rx_intr_enable(uint16_t port_id,
6022 : : uint16_t queue_id)
6023 : : {
6024 : : struct rte_eth_dev *dev;
6025 : : int ret;
6026 : :
6027 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6028 : 0 : dev = &rte_eth_devices[port_id];
6029 : :
6030 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6031 [ # # ]: 0 : if (ret != 0)
6032 : : return ret;
6033 : :
6034 [ # # ]: 0 : if (dev->dev_ops->rx_queue_intr_enable == NULL)
6035 : : return -ENOTSUP;
6036 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_enable(dev, queue_id));
6037 : :
6038 : : rte_ethdev_trace_rx_intr_enable(port_id, queue_id, ret);
6039 : :
6040 : 0 : return ret;
6041 : : }
6042 : :
6043 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_disable)
6044 : : int
6045 : 0 : rte_eth_dev_rx_intr_disable(uint16_t port_id,
6046 : : uint16_t queue_id)
6047 : : {
6048 : : struct rte_eth_dev *dev;
6049 : : int ret;
6050 : :
6051 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6052 : 0 : dev = &rte_eth_devices[port_id];
6053 : :
6054 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6055 [ # # ]: 0 : if (ret != 0)
6056 : : return ret;
6057 : :
6058 [ # # ]: 0 : if (dev->dev_ops->rx_queue_intr_disable == NULL)
6059 : : return -ENOTSUP;
6060 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_disable(dev, queue_id));
6061 : :
6062 : : rte_ethdev_trace_rx_intr_disable(port_id, queue_id, ret);
6063 : :
6064 : 0 : return ret;
6065 : : }
6066 : :
6067 : :
6068 : : RTE_EXPORT_SYMBOL(rte_eth_add_rx_callback)
6069 : : const struct rte_eth_rxtx_callback *
6070 : 0 : rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
6071 : : rte_rx_callback_fn fn, void *user_param)
6072 : : {
6073 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6074 : : rte_errno = ENOTSUP;
6075 : : return NULL;
6076 : : #endif
6077 : : struct rte_eth_dev *dev;
6078 : :
6079 : : /* check input parameters */
6080 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6081 [ # # ]: 0 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
6082 : 0 : rte_errno = EINVAL;
6083 : 0 : return NULL;
6084 : : }
6085 : 0 : dev = &rte_eth_devices[port_id];
6086 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
6087 : 0 : rte_errno = EINVAL;
6088 : 0 : return NULL;
6089 : : }
6090 : 0 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6091 : :
6092 [ # # ]: 0 : if (cb == NULL) {
6093 : 0 : rte_errno = ENOMEM;
6094 : 0 : return NULL;
6095 : : }
6096 : :
6097 : 0 : cb->fn.rx = fn;
6098 : 0 : cb->param = user_param;
6099 : :
6100 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6101 : : /* Add the callbacks in fifo order. */
6102 : 0 : struct rte_eth_rxtx_callback *tail =
6103 : : rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
6104 : :
6105 [ # # ]: 0 : if (!tail) {
6106 : : /* Stores to cb->fn and cb->param should complete before
6107 : : * cb is visible to data plane.
6108 : : */
6109 : 0 : rte_atomic_store_explicit(
6110 : : &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
6111 : : cb, rte_memory_order_release);
6112 : :
6113 : : } else {
6114 [ # # ]: 0 : while (tail->next)
6115 : : tail = tail->next;
6116 : : /* Stores to cb->fn and cb->param should complete before
6117 : : * cb is visible to data plane.
6118 : : */
6119 : 0 : rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
6120 : : }
6121 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6122 : :
6123 : 0 : rte_eth_trace_add_rx_callback(port_id, queue_id, fn, user_param, cb);
6124 : :
6125 : 0 : return cb;
6126 : : }
6127 : :
6128 : : RTE_EXPORT_SYMBOL(rte_eth_add_first_rx_callback)
6129 : : const struct rte_eth_rxtx_callback *
6130 : 1 : rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
6131 : : rte_rx_callback_fn fn, void *user_param)
6132 : : {
6133 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6134 : : rte_errno = ENOTSUP;
6135 : : return NULL;
6136 : : #endif
6137 : : /* check input parameters */
6138 [ + - + - ]: 1 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6139 [ - + ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
6140 : 0 : rte_errno = EINVAL;
6141 : 0 : return NULL;
6142 : : }
6143 : :
6144 : 1 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6145 : :
6146 [ - + ]: 1 : if (cb == NULL) {
6147 : 0 : rte_errno = ENOMEM;
6148 : 0 : return NULL;
6149 : : }
6150 : :
6151 : 1 : cb->fn.rx = fn;
6152 : 1 : cb->param = user_param;
6153 : :
6154 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6155 : : /* Add the callbacks at first position */
6156 : 1 : cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
6157 : : /* Stores to cb->fn, cb->param and cb->next should complete before
6158 : : * cb is visible to data plane threads.
6159 : : */
6160 : 1 : rte_atomic_store_explicit(
6161 : : &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
6162 : : cb, rte_memory_order_release);
6163 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6164 : :
6165 : 1 : rte_eth_trace_add_first_rx_callback(port_id, queue_id, fn, user_param,
6166 : : cb);
6167 : :
6168 : 1 : return cb;
6169 : : }
6170 : :
6171 : : RTE_EXPORT_SYMBOL(rte_eth_add_tx_callback)
6172 : : const struct rte_eth_rxtx_callback *
6173 : 1 : rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
6174 : : rte_tx_callback_fn fn, void *user_param)
6175 : : {
6176 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6177 : : rte_errno = ENOTSUP;
6178 : : return NULL;
6179 : : #endif
6180 : : struct rte_eth_dev *dev;
6181 : :
6182 : : /* check input parameters */
6183 [ + - + - ]: 1 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6184 [ - + ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
6185 : 0 : rte_errno = EINVAL;
6186 : 0 : return NULL;
6187 : : }
6188 : :
6189 : 1 : dev = &rte_eth_devices[port_id];
6190 [ - + ]: 1 : if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
6191 : 0 : rte_errno = EINVAL;
6192 : 0 : return NULL;
6193 : : }
6194 : :
6195 : 1 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6196 : :
6197 [ - + ]: 1 : if (cb == NULL) {
6198 : 0 : rte_errno = ENOMEM;
6199 : 0 : return NULL;
6200 : : }
6201 : :
6202 : 1 : cb->fn.tx = fn;
6203 : 1 : cb->param = user_param;
6204 : :
6205 : : rte_spinlock_lock(ð_dev_tx_cb_lock);
6206 : : /* Add the callbacks in fifo order. */
6207 : 1 : struct rte_eth_rxtx_callback *tail =
6208 : : rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
6209 : :
6210 [ + - ]: 1 : if (!tail) {
6211 : : /* Stores to cb->fn and cb->param should complete before
6212 : : * cb is visible to data plane.
6213 : : */
6214 : 1 : rte_atomic_store_explicit(
6215 : : &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id],
6216 : : cb, rte_memory_order_release);
6217 : :
6218 : : } else {
6219 [ # # ]: 0 : while (tail->next)
6220 : : tail = tail->next;
6221 : : /* Stores to cb->fn and cb->param should complete before
6222 : : * cb is visible to data plane.
6223 : : */
6224 : 0 : rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
6225 : : }
6226 : : rte_spinlock_unlock(ð_dev_tx_cb_lock);
6227 : :
6228 : 1 : rte_eth_trace_add_tx_callback(port_id, queue_id, fn, user_param, cb);
6229 : :
6230 : 1 : return cb;
6231 : : }
6232 : :
6233 : : RTE_EXPORT_SYMBOL(rte_eth_remove_rx_callback)
6234 : : int
6235 : 1 : rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
6236 : : const struct rte_eth_rxtx_callback *user_cb)
6237 : : {
6238 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6239 : : return -ENOTSUP;
6240 : : #endif
6241 : : /* Check input parameters. */
6242 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6243 [ + - ]: 1 : if (user_cb == NULL ||
6244 [ + - ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
6245 : : return -EINVAL;
6246 : :
6247 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
6248 : : struct rte_eth_rxtx_callback *cb;
6249 : : RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
6250 : : int ret = -EINVAL;
6251 : :
6252 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6253 : 1 : prev_cb = &dev->post_rx_burst_cbs[queue_id];
6254 [ + - ]: 1 : for (; *prev_cb != NULL; prev_cb = &cb->next) {
6255 : : cb = *prev_cb;
6256 [ + - ]: 1 : if (cb == user_cb) {
6257 : : /* Remove the user cb from the callback list. */
6258 : 1 : rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
6259 : : ret = 0;
6260 : 1 : break;
6261 : : }
6262 : : }
6263 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6264 : :
6265 : 1 : rte_eth_trace_remove_rx_callback(port_id, queue_id, user_cb, ret);
6266 : :
6267 : 1 : return ret;
6268 : : }
6269 : :
6270 : : RTE_EXPORT_SYMBOL(rte_eth_remove_tx_callback)
6271 : : int
6272 : 1 : rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
6273 : : const struct rte_eth_rxtx_callback *user_cb)
6274 : : {
6275 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6276 : : return -ENOTSUP;
6277 : : #endif
6278 : : /* Check input parameters. */
6279 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6280 [ + - ]: 1 : if (user_cb == NULL ||
6281 [ + - ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
6282 : : return -EINVAL;
6283 : :
6284 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
6285 : : int ret = -EINVAL;
6286 : : struct rte_eth_rxtx_callback *cb;
6287 : : RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
6288 : :
6289 : : rte_spinlock_lock(ð_dev_tx_cb_lock);
6290 : 1 : prev_cb = &dev->pre_tx_burst_cbs[queue_id];
6291 [ + - ]: 1 : for (; *prev_cb != NULL; prev_cb = &cb->next) {
6292 : : cb = *prev_cb;
6293 [ + - ]: 1 : if (cb == user_cb) {
6294 : : /* Remove the user cb from the callback list. */
6295 : 1 : rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
6296 : : ret = 0;
6297 : 1 : break;
6298 : : }
6299 : : }
6300 : : rte_spinlock_unlock(ð_dev_tx_cb_lock);
6301 : :
6302 : 1 : rte_eth_trace_remove_tx_callback(port_id, queue_id, user_cb, ret);
6303 : :
6304 : 1 : return ret;
6305 : : }
6306 : :
6307 : : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_info_get)
6308 : : int
6309 : 1 : rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6310 : : struct rte_eth_rxq_info *qinfo)
6311 : : {
6312 : : struct rte_eth_dev *dev;
6313 : :
6314 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6315 : 1 : dev = &rte_eth_devices[port_id];
6316 : :
6317 [ - + ]: 1 : if (queue_id >= dev->data->nb_rx_queues) {
6318 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6319 : 0 : return -EINVAL;
6320 : : }
6321 : :
6322 [ - + ]: 1 : if (qinfo == NULL) {
6323 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL",
6324 : : port_id, queue_id);
6325 : 0 : return -EINVAL;
6326 : : }
6327 : :
6328 [ - + ]: 1 : if (dev->data->rx_queues == NULL ||
6329 [ # # ]: 0 : dev->data->rx_queues[queue_id] == NULL) {
6330 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
6331 : : "Rx queue %"PRIu16" of device with port_id=%"
6332 : : PRIu16" has not been setup",
6333 : : queue_id, port_id);
6334 : 1 : return -EINVAL;
6335 : : }
6336 : :
6337 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
6338 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
6339 : : "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16,
6340 : : queue_id, port_id);
6341 : 0 : return -EINVAL;
6342 : : }
6343 : :
6344 [ # # ]: 0 : if (dev->dev_ops->rxq_info_get == NULL)
6345 : : return -ENOTSUP;
6346 : :
6347 : : memset(qinfo, 0, sizeof(*qinfo));
6348 : 0 : dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
6349 [ # # ]: 0 : qinfo->queue_state = dev->data->rx_queue_state[queue_id];
6350 : :
6351 : 0 : rte_eth_trace_rx_queue_info_get(port_id, queue_id, qinfo);
6352 : :
6353 : 0 : return 0;
6354 : : }
6355 : :
6356 : : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_info_get)
6357 : : int
6358 : 1 : rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6359 : : struct rte_eth_txq_info *qinfo)
6360 : : {
6361 : : struct rte_eth_dev *dev;
6362 : :
6363 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6364 : 1 : dev = &rte_eth_devices[port_id];
6365 : :
6366 [ - + ]: 1 : if (queue_id >= dev->data->nb_tx_queues) {
6367 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
6368 : 0 : return -EINVAL;
6369 : : }
6370 : :
6371 [ - + ]: 1 : if (qinfo == NULL) {
6372 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL",
6373 : : port_id, queue_id);
6374 : 0 : return -EINVAL;
6375 : : }
6376 : :
6377 [ - + ]: 1 : if (dev->data->tx_queues == NULL ||
6378 [ # # ]: 0 : dev->data->tx_queues[queue_id] == NULL) {
6379 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
6380 : : "Tx queue %"PRIu16" of device with port_id=%"
6381 : : PRIu16" has not been setup",
6382 : : queue_id, port_id);
6383 : 1 : return -EINVAL;
6384 : : }
6385 : :
6386 [ # # ]: 0 : if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
6387 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
6388 : : "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16,
6389 : : queue_id, port_id);
6390 : 0 : return -EINVAL;
6391 : : }
6392 : :
6393 [ # # ]: 0 : if (dev->dev_ops->txq_info_get == NULL)
6394 : : return -ENOTSUP;
6395 : :
6396 : : memset(qinfo, 0, sizeof(*qinfo));
6397 : 0 : dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
6398 [ # # ]: 0 : qinfo->queue_state = dev->data->tx_queue_state[queue_id];
6399 : :
6400 : 0 : rte_eth_trace_tx_queue_info_get(port_id, queue_id, qinfo);
6401 : :
6402 : 0 : return 0;
6403 : : }
6404 : :
6405 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_recycle_rx_queue_info_get, 23.11)
6406 : : int
6407 : 0 : rte_eth_recycle_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6408 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
6409 : : {
6410 : : struct rte_eth_dev *dev;
6411 : : int ret;
6412 : :
6413 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6414 : 0 : dev = &rte_eth_devices[port_id];
6415 : :
6416 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6417 [ # # ]: 0 : if (unlikely(ret != 0))
6418 : : return ret;
6419 : :
6420 [ # # ]: 0 : if (dev->dev_ops->recycle_rxq_info_get == NULL)
6421 : : return -ENOTSUP;
6422 : :
6423 : 0 : dev->dev_ops->recycle_rxq_info_get(dev, queue_id, recycle_rxq_info);
6424 : :
6425 : 0 : return 0;
6426 : : }
6427 : :
6428 : : RTE_EXPORT_SYMBOL(rte_eth_rx_burst_mode_get)
6429 : : int
6430 : 0 : rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
6431 : : struct rte_eth_burst_mode *mode)
6432 : : {
6433 : : struct rte_eth_dev *dev;
6434 : : int ret;
6435 : :
6436 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6437 : 0 : dev = &rte_eth_devices[port_id];
6438 : :
6439 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6440 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6441 : 0 : return -EINVAL;
6442 : : }
6443 : :
6444 [ # # ]: 0 : if (mode == NULL) {
6445 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6446 : : "Cannot get ethdev port %u Rx queue %u burst mode to NULL",
6447 : : port_id, queue_id);
6448 : 0 : return -EINVAL;
6449 : : }
6450 : :
6451 [ # # ]: 0 : if (dev->dev_ops->rx_burst_mode_get == NULL)
6452 : : return -ENOTSUP;
6453 : : memset(mode, 0, sizeof(*mode));
6454 : 0 : ret = eth_err(port_id,
6455 : 0 : dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
6456 : :
6457 : 0 : rte_eth_trace_rx_burst_mode_get(port_id, queue_id, mode, ret);
6458 : :
6459 : 0 : return ret;
6460 : : }
6461 : :
6462 : : RTE_EXPORT_SYMBOL(rte_eth_tx_burst_mode_get)
6463 : : int
6464 : 0 : rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
6465 : : struct rte_eth_burst_mode *mode)
6466 : : {
6467 : : struct rte_eth_dev *dev;
6468 : : int ret;
6469 : :
6470 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6471 : 0 : dev = &rte_eth_devices[port_id];
6472 : :
6473 [ # # ]: 0 : if (queue_id >= dev->data->nb_tx_queues) {
6474 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
6475 : 0 : return -EINVAL;
6476 : : }
6477 : :
6478 [ # # ]: 0 : if (mode == NULL) {
6479 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6480 : : "Cannot get ethdev port %u Tx queue %u burst mode to NULL",
6481 : : port_id, queue_id);
6482 : 0 : return -EINVAL;
6483 : : }
6484 : :
6485 [ # # ]: 0 : if (dev->dev_ops->tx_burst_mode_get == NULL)
6486 : : return -ENOTSUP;
6487 : : memset(mode, 0, sizeof(*mode));
6488 : 0 : ret = eth_err(port_id,
6489 : 0 : dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
6490 : :
6491 : 0 : rte_eth_trace_tx_burst_mode_get(port_id, queue_id, mode, ret);
6492 : :
6493 : 0 : return ret;
6494 : : }
6495 : :
6496 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_get_monitor_addr, 21.02)
6497 : : int
6498 : 0 : rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
6499 : : struct rte_power_monitor_cond *pmc)
6500 : : {
6501 : : struct rte_eth_dev *dev;
6502 : : int ret;
6503 : :
6504 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6505 : : dev = &rte_eth_devices[port_id];
6506 : :
6507 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6508 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6509 : 0 : return -EINVAL;
6510 : : }
6511 : :
6512 [ # # ]: 0 : if (pmc == NULL) {
6513 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6514 : : "Cannot get ethdev port %u Rx queue %u power monitor condition to NULL",
6515 : : port_id, queue_id);
6516 : 0 : return -EINVAL;
6517 : : }
6518 : :
6519 [ # # ]: 0 : if (dev->dev_ops->get_monitor_addr == NULL)
6520 : : return -ENOTSUP;
6521 : 0 : ret = eth_err(port_id,
6522 : 0 : dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc));
6523 : :
6524 : 0 : rte_eth_trace_get_monitor_addr(port_id, queue_id, pmc, ret);
6525 : :
6526 : 0 : return ret;
6527 : : }
6528 : :
6529 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mc_addr_list)
6530 : : int
6531 : 0 : rte_eth_dev_set_mc_addr_list(uint16_t port_id,
6532 : : struct rte_ether_addr *mc_addr_set,
6533 : : uint32_t nb_mc_addr)
6534 : : {
6535 : : struct rte_eth_dev *dev;
6536 : : int ret;
6537 : :
6538 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6539 : 0 : dev = &rte_eth_devices[port_id];
6540 : :
6541 [ # # ]: 0 : if (dev->dev_ops->set_mc_addr_list == NULL)
6542 : : return -ENOTSUP;
6543 : 0 : ret = eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
6544 : : mc_addr_set, nb_mc_addr));
6545 : :
6546 : 0 : rte_ethdev_trace_set_mc_addr_list(port_id, mc_addr_set, nb_mc_addr,
6547 : : ret);
6548 : :
6549 : 0 : return ret;
6550 : : }
6551 : :
6552 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_enable)
6553 : : int
6554 : 0 : rte_eth_timesync_enable(uint16_t port_id)
6555 : : {
6556 : : struct rte_eth_dev *dev;
6557 : : int ret;
6558 : :
6559 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6560 : 0 : dev = &rte_eth_devices[port_id];
6561 : :
6562 [ # # ]: 0 : if (dev->dev_ops->timesync_enable == NULL)
6563 : : return -ENOTSUP;
6564 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_enable(dev));
6565 : :
6566 : 0 : rte_eth_trace_timesync_enable(port_id, ret);
6567 : :
6568 : 0 : return ret;
6569 : : }
6570 : :
6571 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_disable)
6572 : : int
6573 : 0 : rte_eth_timesync_disable(uint16_t port_id)
6574 : : {
6575 : : struct rte_eth_dev *dev;
6576 : : int ret;
6577 : :
6578 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6579 : 0 : dev = &rte_eth_devices[port_id];
6580 : :
6581 [ # # ]: 0 : if (dev->dev_ops->timesync_disable == NULL)
6582 : : return -ENOTSUP;
6583 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_disable(dev));
6584 : :
6585 : 0 : rte_eth_trace_timesync_disable(port_id, ret);
6586 : :
6587 : 0 : return ret;
6588 : : }
6589 : :
6590 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_rx_timestamp)
6591 : : int
6592 : 0 : rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
6593 : : uint32_t flags)
6594 : : {
6595 : : struct rte_eth_dev *dev;
6596 : : int ret;
6597 : :
6598 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6599 : 0 : dev = &rte_eth_devices[port_id];
6600 : :
6601 [ # # ]: 0 : if (timestamp == NULL) {
6602 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6603 : : "Cannot read ethdev port %u Rx timestamp to NULL",
6604 : : port_id);
6605 : 0 : return -EINVAL;
6606 : : }
6607 : :
6608 [ # # ]: 0 : if (dev->dev_ops->timesync_read_rx_timestamp == NULL)
6609 : : return -ENOTSUP;
6610 : :
6611 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_rx_timestamp(dev, timestamp, flags));
6612 : :
6613 : : rte_eth_trace_timesync_read_rx_timestamp(port_id, timestamp, flags,
6614 : : ret);
6615 : :
6616 : 0 : return ret;
6617 : : }
6618 : :
6619 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_tx_timestamp)
6620 : : int
6621 : 0 : rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
6622 : : struct timespec *timestamp)
6623 : : {
6624 : : struct rte_eth_dev *dev;
6625 : : int ret;
6626 : :
6627 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6628 : 0 : dev = &rte_eth_devices[port_id];
6629 : :
6630 [ # # ]: 0 : if (timestamp == NULL) {
6631 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6632 : : "Cannot read ethdev port %u Tx timestamp to NULL",
6633 : : port_id);
6634 : 0 : return -EINVAL;
6635 : : }
6636 : :
6637 [ # # ]: 0 : if (dev->dev_ops->timesync_read_tx_timestamp == NULL)
6638 : : return -ENOTSUP;
6639 : :
6640 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_tx_timestamp(dev, timestamp));
6641 : :
6642 : : rte_eth_trace_timesync_read_tx_timestamp(port_id, timestamp, ret);
6643 : :
6644 : 0 : return ret;
6645 : :
6646 : : }
6647 : :
6648 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_adjust_time)
6649 : : int
6650 : 0 : rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
6651 : : {
6652 : : struct rte_eth_dev *dev;
6653 : : int ret;
6654 : :
6655 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6656 : 0 : dev = &rte_eth_devices[port_id];
6657 : :
6658 [ # # ]: 0 : if (dev->dev_ops->timesync_adjust_time == NULL)
6659 : : return -ENOTSUP;
6660 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_adjust_time(dev, delta));
6661 : :
6662 : : rte_eth_trace_timesync_adjust_time(port_id, delta, ret);
6663 : :
6664 : 0 : return ret;
6665 : : }
6666 : :
6667 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_timesync_adjust_freq, 24.11)
6668 : : int
6669 : 0 : rte_eth_timesync_adjust_freq(uint16_t port_id, int64_t ppm)
6670 : : {
6671 : : struct rte_eth_dev *dev;
6672 : : int ret;
6673 : :
6674 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6675 : 0 : dev = &rte_eth_devices[port_id];
6676 : :
6677 [ # # ]: 0 : if (dev->dev_ops->timesync_adjust_freq == NULL)
6678 : : return -ENOTSUP;
6679 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_adjust_freq(dev, ppm));
6680 : :
6681 : : rte_eth_trace_timesync_adjust_freq(port_id, ppm, ret);
6682 : :
6683 : 0 : return ret;
6684 : : }
6685 : :
6686 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_time)
6687 : : int
6688 : 0 : rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
6689 : : {
6690 : : struct rte_eth_dev *dev;
6691 : : int ret;
6692 : :
6693 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6694 : 0 : dev = &rte_eth_devices[port_id];
6695 : :
6696 [ # # ]: 0 : if (timestamp == NULL) {
6697 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6698 : : "Cannot read ethdev port %u timesync time to NULL",
6699 : : port_id);
6700 : 0 : return -EINVAL;
6701 : : }
6702 : :
6703 [ # # ]: 0 : if (dev->dev_ops->timesync_read_time == NULL)
6704 : : return -ENOTSUP;
6705 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_time(dev, timestamp));
6706 : :
6707 : : rte_eth_trace_timesync_read_time(port_id, timestamp, ret);
6708 : :
6709 : 0 : return ret;
6710 : : }
6711 : :
6712 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_write_time)
6713 : : int
6714 : 0 : rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
6715 : : {
6716 : : struct rte_eth_dev *dev;
6717 : : int ret;
6718 : :
6719 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6720 : 0 : dev = &rte_eth_devices[port_id];
6721 : :
6722 [ # # ]: 0 : if (timestamp == NULL) {
6723 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6724 : : "Cannot write ethdev port %u timesync from NULL time",
6725 : : port_id);
6726 : 0 : return -EINVAL;
6727 : : }
6728 : :
6729 [ # # ]: 0 : if (dev->dev_ops->timesync_write_time == NULL)
6730 : : return -ENOTSUP;
6731 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_write_time(dev, timestamp));
6732 : :
6733 : 0 : rte_eth_trace_timesync_write_time(port_id, timestamp, ret);
6734 : :
6735 : 0 : return ret;
6736 : : }
6737 : :
6738 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_read_clock, 19.08)
6739 : : int
6740 : 0 : rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
6741 : : {
6742 : : struct rte_eth_dev *dev;
6743 : : int ret;
6744 : :
6745 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6746 : 0 : dev = &rte_eth_devices[port_id];
6747 : :
6748 [ # # ]: 0 : if (clock == NULL) {
6749 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot read ethdev port %u clock to NULL",
6750 : : port_id);
6751 : 0 : return -EINVAL;
6752 : : }
6753 : :
6754 [ # # ]: 0 : if (dev->dev_ops->read_clock == NULL)
6755 : : return -ENOTSUP;
6756 : 0 : ret = eth_err(port_id, dev->dev_ops->read_clock(dev, clock));
6757 : :
6758 : 0 : rte_eth_trace_read_clock(port_id, clock, ret);
6759 : :
6760 : 0 : return ret;
6761 : : }
6762 : :
6763 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_reg_info)
6764 : : int
6765 : 0 : rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
6766 : : {
6767 : 0 : struct rte_dev_reg_info reg_info = { 0 };
6768 : : int ret;
6769 : :
6770 [ # # ]: 0 : if (info == NULL) {
6771 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6772 : : "Cannot get ethdev port %u register info to NULL",
6773 : : port_id);
6774 : 0 : return -EINVAL;
6775 : : }
6776 : :
6777 : 0 : reg_info.length = info->length;
6778 : 0 : reg_info.width = info->width;
6779 : 0 : reg_info.offset = info->offset;
6780 : 0 : reg_info.data = info->data;
6781 : :
6782 : 0 : ret = rte_eth_dev_get_reg_info_ext(port_id, ®_info);
6783 [ # # ]: 0 : if (ret != 0)
6784 : : return ret;
6785 : :
6786 : 0 : info->length = reg_info.length;
6787 : 0 : info->width = reg_info.width;
6788 : 0 : info->version = reg_info.version;
6789 : 0 : info->offset = reg_info.offset;
6790 : :
6791 : 0 : return 0;
6792 : : }
6793 : :
6794 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_reg_info_ext, 24.11)
6795 : : int
6796 : 1 : rte_eth_dev_get_reg_info_ext(uint16_t port_id, struct rte_dev_reg_info *info)
6797 : : {
6798 : : struct rte_eth_dev *dev;
6799 : : uint32_t i;
6800 : : int ret;
6801 : :
6802 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6803 : 1 : dev = &rte_eth_devices[port_id];
6804 : :
6805 [ - + ]: 1 : if (info == NULL) {
6806 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6807 : : "Cannot get ethdev port %u register info to NULL",
6808 : : port_id);
6809 : 0 : return -EINVAL;
6810 : : }
6811 : :
6812 [ - + - - ]: 1 : if (info->names != NULL && info->length != 0)
6813 : 0 : memset(info->names, 0, sizeof(struct rte_eth_reg_name) * info->length);
6814 : :
6815 [ - + ]: 1 : if (dev->dev_ops->get_reg == NULL)
6816 : : return -ENOTSUP;
6817 : 0 : ret = eth_err(port_id, dev->dev_ops->get_reg(dev, info));
6818 : :
6819 : 0 : rte_ethdev_trace_get_reg_info(port_id, info, ret);
6820 : :
6821 : : /* Report the default names if drivers not report. */
6822 [ # # # # : 0 : if (ret == 0 && info->names != NULL && strlen(info->names[0].name) == 0) {
# # ]
6823 [ # # ]: 0 : for (i = 0; i < info->length; i++)
6824 : 0 : snprintf(info->names[i].name, RTE_ETH_REG_NAME_SIZE,
6825 : 0 : "index_%u", info->offset + i);
6826 : : }
6827 : : return ret;
6828 : : }
6829 : :
6830 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom_length)
6831 : : int
6832 : 0 : rte_eth_dev_get_eeprom_length(uint16_t port_id)
6833 : : {
6834 : : struct rte_eth_dev *dev;
6835 : : int ret;
6836 : :
6837 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6838 : 0 : dev = &rte_eth_devices[port_id];
6839 : :
6840 [ # # ]: 0 : if (dev->dev_ops->get_eeprom_length == NULL)
6841 : : return -ENOTSUP;
6842 : 0 : ret = eth_err(port_id, dev->dev_ops->get_eeprom_length(dev));
6843 : :
6844 : 0 : rte_ethdev_trace_get_eeprom_length(port_id, ret);
6845 : :
6846 : 0 : return ret;
6847 : : }
6848 : :
6849 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom)
6850 : : int
6851 : 0 : rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
6852 : : {
6853 : : struct rte_eth_dev *dev;
6854 : : int ret;
6855 : :
6856 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6857 : 0 : dev = &rte_eth_devices[port_id];
6858 : :
6859 [ # # ]: 0 : if (info == NULL) {
6860 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6861 : : "Cannot get ethdev port %u EEPROM info to NULL",
6862 : : port_id);
6863 : 0 : return -EINVAL;
6864 : : }
6865 : :
6866 [ # # ]: 0 : if (dev->dev_ops->get_eeprom == NULL)
6867 : : return -ENOTSUP;
6868 : 0 : ret = eth_err(port_id, dev->dev_ops->get_eeprom(dev, info));
6869 : :
6870 : 0 : rte_ethdev_trace_get_eeprom(port_id, info, ret);
6871 : :
6872 : 0 : return ret;
6873 : : }
6874 : :
6875 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_eeprom)
6876 : : int
6877 : 0 : rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
6878 : : {
6879 : : struct rte_eth_dev *dev;
6880 : : int ret;
6881 : :
6882 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6883 : 0 : dev = &rte_eth_devices[port_id];
6884 : :
6885 [ # # ]: 0 : if (info == NULL) {
6886 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6887 : : "Cannot set ethdev port %u EEPROM from NULL info",
6888 : : port_id);
6889 : 0 : return -EINVAL;
6890 : : }
6891 : :
6892 [ # # ]: 0 : if (dev->dev_ops->set_eeprom == NULL)
6893 : : return -ENOTSUP;
6894 : 0 : ret = eth_err(port_id, dev->dev_ops->set_eeprom(dev, info));
6895 : :
6896 : 0 : rte_ethdev_trace_set_eeprom(port_id, info, ret);
6897 : :
6898 : 0 : return ret;
6899 : : }
6900 : :
6901 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_module_info, 18.05)
6902 : : int
6903 : 1 : rte_eth_dev_get_module_info(uint16_t port_id,
6904 : : struct rte_eth_dev_module_info *modinfo)
6905 : : {
6906 : : struct rte_eth_dev *dev;
6907 : : int ret;
6908 : :
6909 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6910 : 1 : dev = &rte_eth_devices[port_id];
6911 : :
6912 [ - + ]: 1 : if (modinfo == NULL) {
6913 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6914 : : "Cannot get ethdev port %u EEPROM module info to NULL",
6915 : : port_id);
6916 : 0 : return -EINVAL;
6917 : : }
6918 : :
6919 [ - + ]: 1 : if (dev->dev_ops->get_module_info == NULL)
6920 : : return -ENOTSUP;
6921 : 0 : ret = dev->dev_ops->get_module_info(dev, modinfo);
6922 : :
6923 : 0 : rte_ethdev_trace_get_module_info(port_id, modinfo, ret);
6924 : :
6925 : 0 : return ret;
6926 : : }
6927 : :
6928 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_module_eeprom, 18.05)
6929 : : int
6930 : 0 : rte_eth_dev_get_module_eeprom(uint16_t port_id,
6931 : : struct rte_dev_eeprom_info *info)
6932 : : {
6933 : : struct rte_eth_dev *dev;
6934 : : int ret;
6935 : :
6936 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6937 : 0 : dev = &rte_eth_devices[port_id];
6938 : :
6939 [ # # ]: 0 : if (info == NULL) {
6940 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6941 : : "Cannot get ethdev port %u module EEPROM info to NULL",
6942 : : port_id);
6943 : 0 : return -EINVAL;
6944 : : }
6945 : :
6946 [ # # ]: 0 : if (info->data == NULL) {
6947 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6948 : : "Cannot get ethdev port %u module EEPROM data to NULL",
6949 : : port_id);
6950 : 0 : return -EINVAL;
6951 : : }
6952 : :
6953 [ # # ]: 0 : if (info->length == 0) {
6954 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6955 : : "Cannot get ethdev port %u module EEPROM to data with zero size",
6956 : : port_id);
6957 : 0 : return -EINVAL;
6958 : : }
6959 : :
6960 [ # # ]: 0 : if (dev->dev_ops->get_module_eeprom == NULL)
6961 : : return -ENOTSUP;
6962 : 0 : ret = dev->dev_ops->get_module_eeprom(dev, info);
6963 : :
6964 : 0 : rte_ethdev_trace_get_module_eeprom(port_id, info, ret);
6965 : :
6966 : 0 : return ret;
6967 : : }
6968 : :
6969 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_dcb_info)
6970 : : int
6971 : 1 : rte_eth_dev_get_dcb_info(uint16_t port_id,
6972 : : struct rte_eth_dcb_info *dcb_info)
6973 : : {
6974 : : struct rte_eth_dev *dev;
6975 : : int ret;
6976 : :
6977 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6978 : 1 : dev = &rte_eth_devices[port_id];
6979 : :
6980 [ - + ]: 1 : if (dcb_info == NULL) {
6981 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6982 : : "Cannot get ethdev port %u DCB info to NULL",
6983 : : port_id);
6984 : 0 : return -EINVAL;
6985 : : }
6986 : :
6987 : : memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
6988 : :
6989 [ - + ]: 1 : if (dev->dev_ops->get_dcb_info == NULL)
6990 : : return -ENOTSUP;
6991 : 0 : ret = eth_err(port_id, dev->dev_ops->get_dcb_info(dev, dcb_info));
6992 : :
6993 : 0 : rte_ethdev_trace_get_dcb_info(port_id, dcb_info, ret);
6994 : :
6995 : 0 : return ret;
6996 : : }
6997 : :
6998 : : static void
6999 : : eth_dev_adjust_nb_desc(uint16_t *nb_desc,
7000 : : const struct rte_eth_desc_lim *desc_lim)
7001 : : {
7002 : : /* Upcast to uint32 to avoid potential overflow with RTE_ALIGN_CEIL(). */
7003 : 0 : uint32_t nb_desc_32 = (uint32_t)*nb_desc;
7004 : :
7005 [ # # # # ]: 0 : if (desc_lim->nb_align != 0)
7006 : 0 : nb_desc_32 = RTE_ALIGN_CEIL(nb_desc_32, desc_lim->nb_align);
7007 : :
7008 [ # # # # ]: 0 : if (desc_lim->nb_max != 0)
7009 : 0 : nb_desc_32 = RTE_MIN(nb_desc_32, desc_lim->nb_max);
7010 : :
7011 : 0 : nb_desc_32 = RTE_MAX(nb_desc_32, desc_lim->nb_min);
7012 : :
7013 : : /* Assign clipped u32 back to u16. */
7014 : 0 : *nb_desc = (uint16_t)nb_desc_32;
7015 : 0 : }
7016 : :
7017 : : RTE_EXPORT_SYMBOL(rte_eth_dev_adjust_nb_rx_tx_desc)
7018 : : int
7019 : 0 : rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
7020 : : uint16_t *nb_rx_desc,
7021 : : uint16_t *nb_tx_desc)
7022 : : {
7023 : : struct rte_eth_dev_info dev_info;
7024 : : int ret;
7025 : :
7026 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7027 : :
7028 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
7029 [ # # ]: 0 : if (ret != 0)
7030 : : return ret;
7031 : :
7032 [ # # ]: 0 : if (nb_rx_desc != NULL)
7033 : : eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
7034 : :
7035 [ # # ]: 0 : if (nb_tx_desc != NULL)
7036 : : eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
7037 : :
7038 : 0 : rte_ethdev_trace_adjust_nb_rx_tx_desc(port_id);
7039 : :
7040 : 0 : return 0;
7041 : : }
7042 : :
7043 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_hairpin_capability_get, 19.11)
7044 : : int
7045 : 0 : rte_eth_dev_hairpin_capability_get(uint16_t port_id,
7046 : : struct rte_eth_hairpin_cap *cap)
7047 : : {
7048 : : struct rte_eth_dev *dev;
7049 : : int ret;
7050 : :
7051 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7052 : 0 : dev = &rte_eth_devices[port_id];
7053 : :
7054 [ # # ]: 0 : if (cap == NULL) {
7055 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7056 : : "Cannot get ethdev port %u hairpin capability to NULL",
7057 : : port_id);
7058 : 0 : return -EINVAL;
7059 : : }
7060 : :
7061 [ # # ]: 0 : if (dev->dev_ops->hairpin_cap_get == NULL)
7062 : : return -ENOTSUP;
7063 : : memset(cap, 0, sizeof(*cap));
7064 : 0 : ret = eth_err(port_id, dev->dev_ops->hairpin_cap_get(dev, cap));
7065 : :
7066 : 0 : rte_ethdev_trace_hairpin_capability_get(port_id, cap, ret);
7067 : :
7068 : 0 : return ret;
7069 : : }
7070 : :
7071 : : RTE_EXPORT_SYMBOL(rte_eth_dev_pool_ops_supported)
7072 : : int
7073 : 0 : rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
7074 : : {
7075 : : struct rte_eth_dev *dev;
7076 : : int ret;
7077 : :
7078 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7079 : 0 : dev = &rte_eth_devices[port_id];
7080 : :
7081 [ # # ]: 0 : if (pool == NULL) {
7082 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7083 : : "Cannot test ethdev port %u mempool operation from NULL pool",
7084 : : port_id);
7085 : 0 : return -EINVAL;
7086 : : }
7087 : :
7088 [ # # ]: 0 : if (dev->dev_ops->pool_ops_supported == NULL)
7089 : : return 1; /* all pools are supported */
7090 : :
7091 : 0 : ret = dev->dev_ops->pool_ops_supported(dev, pool);
7092 : :
7093 : 0 : rte_ethdev_trace_pool_ops_supported(port_id, pool, ret);
7094 : :
7095 : 0 : return ret;
7096 : : }
7097 : :
7098 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_representor_info_get, 21.05)
7099 : : int
7100 : 0 : rte_eth_representor_info_get(uint16_t port_id,
7101 : : struct rte_eth_representor_info *info)
7102 : : {
7103 : : struct rte_eth_dev *dev;
7104 : : int ret;
7105 : :
7106 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7107 : 0 : dev = &rte_eth_devices[port_id];
7108 : :
7109 [ # # ]: 0 : if (dev->dev_ops->representor_info_get == NULL)
7110 : : return -ENOTSUP;
7111 : 0 : ret = eth_err(port_id, dev->dev_ops->representor_info_get(dev, info));
7112 : :
7113 : 0 : rte_eth_trace_representor_info_get(port_id, info, ret);
7114 : :
7115 : 0 : return ret;
7116 : : }
7117 : :
7118 : : RTE_EXPORT_SYMBOL(rte_eth_rx_metadata_negotiate)
7119 : : int
7120 : 0 : rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
7121 : : {
7122 : : struct rte_eth_dev *dev;
7123 : : int ret;
7124 : :
7125 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7126 : 0 : dev = &rte_eth_devices[port_id];
7127 : :
7128 [ # # ]: 0 : if (dev->data->dev_configured != 0) {
7129 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7130 : : "The port (ID=%"PRIu16") is already configured",
7131 : : port_id);
7132 : 0 : return -EBUSY;
7133 : : }
7134 : :
7135 [ # # ]: 0 : if (features == NULL) {
7136 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid features (NULL)");
7137 : 0 : return -EINVAL;
7138 : : }
7139 : :
7140 [ # # # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
7141 : 0 : rte_flow_restore_info_dynflag_register() < 0)
7142 : 0 : *features &= ~RTE_ETH_RX_METADATA_TUNNEL_ID;
7143 : :
7144 [ # # ]: 0 : if (dev->dev_ops->rx_metadata_negotiate == NULL)
7145 : : return -ENOTSUP;
7146 : 0 : ret = eth_err(port_id,
7147 : : dev->dev_ops->rx_metadata_negotiate(dev, features));
7148 : :
7149 [ # # ]: 0 : rte_eth_trace_rx_metadata_negotiate(port_id, *features, ret);
7150 : :
7151 : 0 : return ret;
7152 : : }
7153 : :
7154 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_capability_get, 22.03)
7155 : : int
7156 : 0 : rte_eth_ip_reassembly_capability_get(uint16_t port_id,
7157 : : struct rte_eth_ip_reassembly_params *reassembly_capa)
7158 : : {
7159 : : struct rte_eth_dev *dev;
7160 : : int ret;
7161 : :
7162 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7163 : 0 : dev = &rte_eth_devices[port_id];
7164 : :
7165 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7166 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7167 : : "port_id=%u is not configured, cannot get IP reassembly capability",
7168 : : port_id);
7169 : 0 : return -EINVAL;
7170 : : }
7171 : :
7172 [ # # ]: 0 : if (reassembly_capa == NULL) {
7173 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly capability to NULL");
7174 : 0 : return -EINVAL;
7175 : : }
7176 : :
7177 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_capability_get == NULL)
7178 : : return -ENOTSUP;
7179 : : memset(reassembly_capa, 0, sizeof(struct rte_eth_ip_reassembly_params));
7180 : :
7181 : 0 : ret = eth_err(port_id,
7182 : 0 : dev->dev_ops->ip_reassembly_capability_get(dev, reassembly_capa));
7183 : :
7184 : 0 : rte_eth_trace_ip_reassembly_capability_get(port_id, reassembly_capa,
7185 : : ret);
7186 : :
7187 : 0 : return ret;
7188 : : }
7189 : :
7190 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_conf_get, 22.03)
7191 : : int
7192 : 0 : rte_eth_ip_reassembly_conf_get(uint16_t port_id,
7193 : : struct rte_eth_ip_reassembly_params *conf)
7194 : : {
7195 : : struct rte_eth_dev *dev;
7196 : : int ret;
7197 : :
7198 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7199 : 0 : dev = &rte_eth_devices[port_id];
7200 : :
7201 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7202 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7203 : : "port_id=%u is not configured, cannot get IP reassembly configuration",
7204 : : port_id);
7205 : 0 : return -EINVAL;
7206 : : }
7207 : :
7208 [ # # ]: 0 : if (conf == NULL) {
7209 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly info to NULL");
7210 : 0 : return -EINVAL;
7211 : : }
7212 : :
7213 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_conf_get == NULL)
7214 : : return -ENOTSUP;
7215 : : memset(conf, 0, sizeof(struct rte_eth_ip_reassembly_params));
7216 : 0 : ret = eth_err(port_id,
7217 : 0 : dev->dev_ops->ip_reassembly_conf_get(dev, conf));
7218 : :
7219 : 0 : rte_eth_trace_ip_reassembly_conf_get(port_id, conf, ret);
7220 : :
7221 : 0 : return ret;
7222 : : }
7223 : :
7224 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_conf_set, 22.03)
7225 : : int
7226 : 0 : rte_eth_ip_reassembly_conf_set(uint16_t port_id,
7227 : : const struct rte_eth_ip_reassembly_params *conf)
7228 : : {
7229 : : struct rte_eth_dev *dev;
7230 : : int ret;
7231 : :
7232 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7233 : 0 : dev = &rte_eth_devices[port_id];
7234 : :
7235 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7236 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7237 : : "port_id=%u is not configured, cannot set IP reassembly configuration",
7238 : : port_id);
7239 : 0 : return -EINVAL;
7240 : : }
7241 : :
7242 [ # # ]: 0 : if (dev->data->dev_started != 0) {
7243 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7244 : : "port_id=%u is started, cannot configure IP reassembly params.",
7245 : : port_id);
7246 : 0 : return -EINVAL;
7247 : : }
7248 : :
7249 [ # # ]: 0 : if (conf == NULL) {
7250 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7251 : : "Invalid IP reassembly configuration (NULL)");
7252 : 0 : return -EINVAL;
7253 : : }
7254 : :
7255 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_conf_set == NULL)
7256 : : return -ENOTSUP;
7257 : 0 : ret = eth_err(port_id,
7258 : : dev->dev_ops->ip_reassembly_conf_set(dev, conf));
7259 : :
7260 : 0 : rte_eth_trace_ip_reassembly_conf_set(port_id, conf, ret);
7261 : :
7262 : 0 : return ret;
7263 : : }
7264 : :
7265 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priv_dump, 22.03)
7266 : : int
7267 : 1 : rte_eth_dev_priv_dump(uint16_t port_id, FILE *file)
7268 : : {
7269 : : struct rte_eth_dev *dev;
7270 : :
7271 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7272 : 1 : dev = &rte_eth_devices[port_id];
7273 : :
7274 [ - + ]: 1 : if (file == NULL) {
7275 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7276 : 0 : return -EINVAL;
7277 : : }
7278 : :
7279 [ - + ]: 1 : if (dev->dev_ops->eth_dev_priv_dump == NULL)
7280 : : return -ENOTSUP;
7281 : 0 : return eth_err(port_id, dev->dev_ops->eth_dev_priv_dump(dev, file));
7282 : : }
7283 : :
7284 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_descriptor_dump, 22.11)
7285 : : int
7286 : 0 : rte_eth_rx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
7287 : : uint16_t offset, uint16_t num, FILE *file)
7288 : : {
7289 : : struct rte_eth_dev *dev;
7290 : :
7291 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7292 : 0 : dev = &rte_eth_devices[port_id];
7293 : :
7294 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
7295 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
7296 : 0 : return -EINVAL;
7297 : : }
7298 : :
7299 [ # # ]: 0 : if (file == NULL) {
7300 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7301 : 0 : return -EINVAL;
7302 : : }
7303 : :
7304 [ # # ]: 0 : if (dev->dev_ops->eth_rx_descriptor_dump == NULL)
7305 : : return -ENOTSUP;
7306 : :
7307 : 0 : return eth_err(port_id,
7308 : : dev->dev_ops->eth_rx_descriptor_dump(dev, queue_id, offset, num, file));
7309 : : }
7310 : :
7311 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_tx_descriptor_dump, 22.11)
7312 : : int
7313 : 0 : rte_eth_tx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
7314 : : uint16_t offset, uint16_t num, FILE *file)
7315 : : {
7316 : : struct rte_eth_dev *dev;
7317 : :
7318 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7319 : 0 : dev = &rte_eth_devices[port_id];
7320 : :
7321 [ # # ]: 0 : if (queue_id >= dev->data->nb_tx_queues) {
7322 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
7323 : 0 : return -EINVAL;
7324 : : }
7325 : :
7326 [ # # ]: 0 : if (file == NULL) {
7327 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7328 : 0 : return -EINVAL;
7329 : : }
7330 : :
7331 [ # # ]: 0 : if (dev->dev_ops->eth_tx_descriptor_dump == NULL)
7332 : : return -ENOTSUP;
7333 : :
7334 : 0 : return eth_err(port_id,
7335 : : dev->dev_ops->eth_tx_descriptor_dump(dev, queue_id, offset, num, file));
7336 : : }
7337 : :
7338 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_buffer_split_get_supported_hdr_ptypes, 22.11)
7339 : : int
7340 : 0 : rte_eth_buffer_split_get_supported_hdr_ptypes(uint16_t port_id, uint32_t *ptypes, int num)
7341 : : {
7342 : : size_t i;
7343 : : int j;
7344 : : struct rte_eth_dev *dev;
7345 : : const uint32_t *all_types;
7346 : 0 : size_t no_of_elements = 0;
7347 : :
7348 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7349 : 0 : dev = &rte_eth_devices[port_id];
7350 : :
7351 [ # # ]: 0 : if (ptypes == NULL && num > 0) {
7352 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7353 : : "Cannot get ethdev port %u supported header protocol types to NULL when array size is non zero",
7354 : : port_id);
7355 : 0 : return -EINVAL;
7356 : : }
7357 : :
7358 [ # # ]: 0 : if (dev->dev_ops->buffer_split_supported_hdr_ptypes_get == NULL)
7359 : : return -ENOTSUP;
7360 : 0 : all_types = dev->dev_ops->buffer_split_supported_hdr_ptypes_get(dev, &no_of_elements);
7361 : :
7362 [ # # ]: 0 : if (all_types == NULL)
7363 : : return 0;
7364 : :
7365 [ # # ]: 0 : for (i = 0, j = 0; i < no_of_elements; ++i) {
7366 [ # # ]: 0 : if (j < num) {
7367 [ # # ]: 0 : ptypes[j] = all_types[i];
7368 : :
7369 : 0 : rte_eth_trace_buffer_split_get_supported_hdr_ptypes(
7370 : : port_id, j, ptypes[j]);
7371 : : }
7372 : 0 : j++;
7373 : : }
7374 : :
7375 : : return j;
7376 : : }
7377 : :
7378 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_count_aggr_ports, 23.03)
7379 : 0 : int rte_eth_dev_count_aggr_ports(uint16_t port_id)
7380 : : {
7381 : : struct rte_eth_dev *dev;
7382 : : int ret;
7383 : :
7384 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7385 : 0 : dev = &rte_eth_devices[port_id];
7386 : :
7387 [ # # ]: 0 : if (dev->dev_ops->count_aggr_ports == NULL)
7388 : : return 0;
7389 : 0 : ret = eth_err(port_id, dev->dev_ops->count_aggr_ports(dev));
7390 : :
7391 : 0 : rte_eth_trace_count_aggr_ports(port_id, ret);
7392 : :
7393 : 0 : return ret;
7394 : : }
7395 : :
7396 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_map_aggr_tx_affinity, 23.03)
7397 : 0 : int rte_eth_dev_map_aggr_tx_affinity(uint16_t port_id, uint16_t tx_queue_id,
7398 : : uint8_t affinity)
7399 : : {
7400 : : struct rte_eth_dev *dev;
7401 : : int aggr_ports;
7402 : : int ret;
7403 : :
7404 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7405 : 0 : dev = &rte_eth_devices[port_id];
7406 : :
7407 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
7408 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
7409 : 0 : return -EINVAL;
7410 : : }
7411 : :
7412 [ # # ]: 0 : if (dev->dev_ops->map_aggr_tx_affinity == NULL)
7413 : : return -ENOTSUP;
7414 : :
7415 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7416 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7417 : : "Port %u must be configured before Tx affinity mapping",
7418 : : port_id);
7419 : 0 : return -EINVAL;
7420 : : }
7421 : :
7422 [ # # ]: 0 : if (dev->data->dev_started) {
7423 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7424 : : "Port %u must be stopped to allow configuration",
7425 : : port_id);
7426 : 0 : return -EBUSY;
7427 : : }
7428 : :
7429 : 0 : aggr_ports = rte_eth_dev_count_aggr_ports(port_id);
7430 [ # # ]: 0 : if (aggr_ports == 0) {
7431 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7432 : : "Port %u has no aggregated port",
7433 : : port_id);
7434 : 0 : return -ENOTSUP;
7435 : : }
7436 : :
7437 [ # # ]: 0 : if (affinity > aggr_ports) {
7438 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7439 : : "Port %u map invalid affinity %u exceeds the maximum number %u",
7440 : : port_id, affinity, aggr_ports);
7441 : 0 : return -EINVAL;
7442 : : }
7443 : :
7444 : 0 : ret = eth_err(port_id,
7445 : 0 : dev->dev_ops->map_aggr_tx_affinity(dev, tx_queue_id, affinity));
7446 : :
7447 : 0 : rte_eth_trace_map_aggr_tx_affinity(port_id, tx_queue_id, affinity, ret);
7448 : :
7449 : 0 : return ret;
7450 : : }
7451 : :
7452 : : RTE_EXPORT_SYMBOL(rte_eth_dev_logtype)
7453 [ - + ]: 258 : RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
|