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 : : int ret;
2475 : :
2476 : 0 : overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
2477 [ # # ]: 0 : dev_info.max_mtu);
2478 : 0 : max_rx_pktlen = dev->data->mtu + overhead_len;
2479 [ # # ]: 0 : if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0)
2480 : 0 : dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen;
2481 : 0 : ret = eth_dev_check_lro_pkt_size(port_id,
2482 : : dev->data->dev_conf.rxmode.max_lro_pkt_size,
2483 : : max_rx_pktlen,
2484 : : dev_info.max_lro_pkt_size);
2485 [ # # ]: 0 : if (ret != 0)
2486 : : return ret;
2487 : : }
2488 : :
2489 : 40 : ret = dev->dev_ops->rx_queue_setup(dev, rx_queue_id, nb_rx_desc,
2490 : : socket_id, &local_conf, mp);
2491 [ + - ]: 40 : if (!ret) {
2492 [ + + ]: 40 : if (!dev->data->min_rx_buf_size ||
2493 [ - + ]: 30 : dev->data->min_rx_buf_size > mbp_buf_size)
2494 : 10 : dev->data->min_rx_buf_size = mbp_buf_size;
2495 : : }
2496 : :
2497 : 40 : rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp,
2498 : : rx_conf, ret);
2499 : 40 : return eth_err(port_id, ret);
2500 : : }
2501 : :
2502 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_hairpin_queue_setup, 19.11)
2503 : : int
2504 : 0 : rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id,
2505 : : uint16_t nb_rx_desc,
2506 : : const struct rte_eth_hairpin_conf *conf)
2507 : : {
2508 : : int ret;
2509 : : struct rte_eth_dev *dev;
2510 : : struct rte_eth_hairpin_cap cap;
2511 : : int i;
2512 : : int count;
2513 : :
2514 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2515 : 0 : dev = &rte_eth_devices[port_id];
2516 : :
2517 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues) {
2518 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", rx_queue_id);
2519 : 0 : return -EINVAL;
2520 : : }
2521 : :
2522 [ # # ]: 0 : if (conf == NULL) {
2523 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2524 : : "Cannot setup ethdev port %u Rx hairpin queue from NULL config",
2525 : : port_id);
2526 : 0 : return -EINVAL;
2527 : : }
2528 : :
2529 [ # # ]: 0 : if (conf->reserved != 0) {
2530 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2531 : : "Rx hairpin reserved field not zero");
2532 : 0 : return -EINVAL;
2533 : : }
2534 : :
2535 : 0 : ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
2536 [ # # ]: 0 : if (ret != 0)
2537 : : return ret;
2538 [ # # ]: 0 : if (dev->dev_ops->rx_hairpin_queue_setup == NULL)
2539 : : return -ENOTSUP;
2540 : : /* if nb_rx_desc is zero use max number of desc from the driver. */
2541 [ # # ]: 0 : if (nb_rx_desc == 0)
2542 : 0 : nb_rx_desc = cap.max_nb_desc;
2543 [ # # ]: 0 : if (nb_rx_desc > cap.max_nb_desc) {
2544 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2545 : : "Invalid value for nb_rx_desc(=%hu), should be: <= %hu",
2546 : : nb_rx_desc, cap.max_nb_desc);
2547 : 0 : return -EINVAL;
2548 : : }
2549 [ # # ]: 0 : if (conf->peer_count > cap.max_rx_2_tx) {
2550 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2551 : : "Invalid value for number of peers for Rx queue(=%u), should be: <= %hu",
2552 : : conf->peer_count, cap.max_rx_2_tx);
2553 : 0 : return -EINVAL;
2554 : : }
2555 [ # # # # ]: 0 : if (conf->use_locked_device_memory && !cap.rx_cap.locked_device_memory) {
2556 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2557 : : "Attempt to use locked device memory for Rx queue, which is not supported");
2558 : 0 : return -EINVAL;
2559 : : }
2560 [ # # # # ]: 0 : if (conf->use_rte_memory && !cap.rx_cap.rte_memory) {
2561 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2562 : : "Attempt to use DPDK memory for Rx queue, which is not supported");
2563 : 0 : return -EINVAL;
2564 : : }
2565 [ # # ]: 0 : if (conf->use_locked_device_memory && conf->use_rte_memory) {
2566 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2567 : : "Attempt to use mutually exclusive memory settings for Rx queue");
2568 : 0 : return -EINVAL;
2569 : : }
2570 : 0 : if (conf->force_memory &&
2571 [ # # ]: 0 : !conf->use_locked_device_memory &&
2572 : : !conf->use_rte_memory) {
2573 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2574 : : "Attempt to force Rx queue memory settings, but none is set");
2575 : 0 : return -EINVAL;
2576 : : }
2577 [ # # ]: 0 : if (conf->peer_count == 0) {
2578 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2579 : : "Invalid value for number of peers for Rx queue(=%u), should be: > 0",
2580 : : conf->peer_count);
2581 : 0 : return -EINVAL;
2582 : : }
2583 [ # # ]: 0 : for (i = 0, count = 0; i < dev->data->nb_rx_queues &&
2584 [ # # ]: 0 : cap.max_nb_queues != UINT16_MAX; i++) {
2585 [ # # # # ]: 0 : if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i))
2586 : 0 : count++;
2587 : : }
2588 [ # # ]: 0 : if (count > cap.max_nb_queues) {
2589 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "To many Rx hairpin queues max is %d",
2590 : : cap.max_nb_queues);
2591 : 0 : return -EINVAL;
2592 : : }
2593 [ # # ]: 0 : if (dev->data->dev_started)
2594 : : return -EBUSY;
2595 : 0 : eth_dev_rxq_release(dev, rx_queue_id);
2596 : 0 : ret = dev->dev_ops->rx_hairpin_queue_setup(dev, rx_queue_id, nb_rx_desc, conf);
2597 [ # # ]: 0 : if (ret == 0)
2598 : 0 : dev->data->rx_queue_state[rx_queue_id] =
2599 : : RTE_ETH_QUEUE_STATE_HAIRPIN;
2600 : 0 : ret = eth_err(port_id, ret);
2601 : :
2602 : 0 : rte_eth_trace_rx_hairpin_queue_setup(port_id, rx_queue_id, nb_rx_desc,
2603 : : conf, ret);
2604 : :
2605 : 0 : return ret;
2606 : : }
2607 : :
2608 : : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_setup)
2609 : : int
2610 : 40 : rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2611 : : uint16_t nb_tx_desc, unsigned int socket_id,
2612 : : const struct rte_eth_txconf *tx_conf)
2613 : : {
2614 : : struct rte_eth_dev *dev;
2615 : : struct rte_eth_dev_info dev_info;
2616 : : struct rte_eth_txconf local_conf;
2617 : : int ret;
2618 : :
2619 [ - + ]: 40 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2620 : 40 : dev = &rte_eth_devices[port_id];
2621 : :
2622 [ - + ]: 40 : if (tx_queue_id >= dev->data->nb_tx_queues) {
2623 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
2624 : 0 : return -EINVAL;
2625 : : }
2626 : :
2627 [ + - ]: 40 : if (dev->dev_ops->tx_queue_setup == NULL)
2628 : : return -ENOTSUP;
2629 : :
2630 [ - + ]: 40 : if (tx_conf != NULL &&
2631 [ # # ]: 0 : (tx_conf->reserved_64s[0] != 0 ||
2632 [ # # ]: 0 : tx_conf->reserved_64s[1] != 0 ||
2633 [ # # ]: 0 : tx_conf->reserved_ptrs[0] != NULL ||
2634 [ # # ]: 0 : tx_conf->reserved_ptrs[1] != NULL)) {
2635 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Tx conf reserved fields not zero");
2636 : 0 : return -EINVAL;
2637 : : }
2638 : :
2639 : : /* Deferred start requires that device supports queue start */
2640 [ - + - - ]: 40 : if (tx_conf != NULL && tx_conf->tx_deferred_start &&
2641 [ # # ]: 0 : dev->dev_ops->tx_queue_start == NULL) {
2642 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2643 : : "Deferred start requested, but driver does not support Tx queue start");
2644 : 0 : return -ENOTSUP;
2645 : : }
2646 : :
2647 : 40 : ret = rte_eth_dev_info_get(port_id, &dev_info);
2648 [ + - ]: 40 : if (ret != 0)
2649 : : return ret;
2650 : :
2651 : : /* Use default specified by driver, if nb_tx_desc is zero */
2652 [ - + ]: 40 : if (nb_tx_desc == 0) {
2653 : 0 : nb_tx_desc = dev_info.default_txportconf.ring_size;
2654 : : /* If driver default is zero, fall back on EAL default */
2655 [ # # ]: 0 : if (nb_tx_desc == 0)
2656 : : nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE;
2657 : : }
2658 [ + - ]: 40 : if (nb_tx_desc > dev_info.tx_desc_lim.nb_max ||
2659 [ + - ]: 40 : nb_tx_desc < dev_info.tx_desc_lim.nb_min ||
2660 [ - + ]: 40 : nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) {
2661 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2662 : : "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu",
2663 : : nb_tx_desc, dev_info.tx_desc_lim.nb_max,
2664 : : dev_info.tx_desc_lim.nb_min,
2665 : : dev_info.tx_desc_lim.nb_align);
2666 : 0 : return -EINVAL;
2667 : : }
2668 : :
2669 [ - + ]: 40 : if (dev->data->dev_started &&
2670 [ # # ]: 0 : !(dev_info.dev_capa &
2671 : : RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP))
2672 : : return -EBUSY;
2673 : :
2674 [ - + ]: 40 : if (dev->data->dev_started &&
2675 [ # # ]: 0 : (dev->data->tx_queue_state[tx_queue_id] !=
2676 : : RTE_ETH_QUEUE_STATE_STOPPED))
2677 : : return -EBUSY;
2678 : :
2679 : 40 : eth_dev_txq_release(dev, tx_queue_id);
2680 : :
2681 [ + - ]: 40 : if (tx_conf == NULL)
2682 : : tx_conf = &dev_info.default_txconf;
2683 : :
2684 : 40 : local_conf = *tx_conf;
2685 : :
2686 : : /*
2687 : : * If an offloading has already been enabled in
2688 : : * rte_eth_dev_configure(), it has been enabled on all queues,
2689 : : * so there is no need to enable it in this queue again.
2690 : : * The local_conf.offloads input to underlying PMD only carries
2691 : : * those offloadings which are only enabled on this queue and
2692 : : * not enabled on all queues.
2693 : : */
2694 : 40 : local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads;
2695 : :
2696 : : /*
2697 : : * New added offloadings for this queue are those not enabled in
2698 : : * rte_eth_dev_configure() and they must be per-queue type.
2699 : : * A pure per-port offloading can't be enabled on a queue while
2700 : : * disabled on another queue. A pure per-port offloading can't
2701 : : * be enabled for any queue as new added one if it hasn't been
2702 : : * enabled in rte_eth_dev_configure().
2703 : : */
2704 [ - + ]: 40 : if ((local_conf.offloads & dev_info.tx_queue_offload_capa) !=
2705 : : local_conf.offloads) {
2706 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2707 : : "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be "
2708 : : "within per-queue offload capabilities 0x%"PRIx64" in %s()",
2709 : : port_id, tx_queue_id, local_conf.offloads,
2710 : : dev_info.tx_queue_offload_capa,
2711 : : __func__);
2712 : 0 : return -EINVAL;
2713 : : }
2714 : :
2715 [ - + ]: 40 : rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf);
2716 : 40 : return eth_err(port_id, dev->dev_ops->tx_queue_setup(dev,
2717 : : tx_queue_id, nb_tx_desc, socket_id, &local_conf));
2718 : : }
2719 : :
2720 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_tx_hairpin_queue_setup, 19.11)
2721 : : int
2722 : 0 : rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id,
2723 : : uint16_t nb_tx_desc,
2724 : : const struct rte_eth_hairpin_conf *conf)
2725 : : {
2726 : : struct rte_eth_dev *dev;
2727 : : struct rte_eth_hairpin_cap cap;
2728 : : int i;
2729 : : int count;
2730 : : int ret;
2731 : :
2732 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2733 : 0 : dev = &rte_eth_devices[port_id];
2734 : :
2735 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
2736 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
2737 : 0 : return -EINVAL;
2738 : : }
2739 : :
2740 [ # # ]: 0 : if (conf == NULL) {
2741 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2742 : : "Cannot setup ethdev port %u Tx hairpin queue from NULL config",
2743 : : port_id);
2744 : 0 : return -EINVAL;
2745 : : }
2746 : :
2747 : 0 : ret = rte_eth_dev_hairpin_capability_get(port_id, &cap);
2748 [ # # ]: 0 : if (ret != 0)
2749 : : return ret;
2750 [ # # ]: 0 : if (dev->dev_ops->tx_hairpin_queue_setup == NULL)
2751 : : return -ENOTSUP;
2752 : : /* if nb_rx_desc is zero use max number of desc from the driver. */
2753 [ # # ]: 0 : if (nb_tx_desc == 0)
2754 : 0 : nb_tx_desc = cap.max_nb_desc;
2755 [ # # ]: 0 : if (nb_tx_desc > cap.max_nb_desc) {
2756 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2757 : : "Invalid value for nb_tx_desc(=%hu), should be: <= %hu",
2758 : : nb_tx_desc, cap.max_nb_desc);
2759 : 0 : return -EINVAL;
2760 : : }
2761 [ # # ]: 0 : if (conf->peer_count > cap.max_tx_2_rx) {
2762 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2763 : : "Invalid value for number of peers for Tx queue(=%u), should be: <= %hu",
2764 : : conf->peer_count, cap.max_tx_2_rx);
2765 : 0 : return -EINVAL;
2766 : : }
2767 [ # # # # ]: 0 : if (conf->use_locked_device_memory && !cap.tx_cap.locked_device_memory) {
2768 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2769 : : "Attempt to use locked device memory for Tx queue, which is not supported");
2770 : 0 : return -EINVAL;
2771 : : }
2772 [ # # # # ]: 0 : if (conf->use_rte_memory && !cap.tx_cap.rte_memory) {
2773 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2774 : : "Attempt to use DPDK memory for Tx queue, which is not supported");
2775 : 0 : return -EINVAL;
2776 : : }
2777 [ # # ]: 0 : if (conf->use_locked_device_memory && conf->use_rte_memory) {
2778 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2779 : : "Attempt to use mutually exclusive memory settings for Tx queue");
2780 : 0 : return -EINVAL;
2781 : : }
2782 : 0 : if (conf->force_memory &&
2783 [ # # ]: 0 : !conf->use_locked_device_memory &&
2784 : : !conf->use_rte_memory) {
2785 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2786 : : "Attempt to force Tx queue memory settings, but none is set");
2787 : 0 : return -EINVAL;
2788 : : }
2789 [ # # ]: 0 : if (conf->peer_count == 0) {
2790 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2791 : : "Invalid value for number of peers for Tx queue(=%u), should be: > 0",
2792 : : conf->peer_count);
2793 : 0 : return -EINVAL;
2794 : : }
2795 [ # # ]: 0 : for (i = 0, count = 0; i < dev->data->nb_tx_queues &&
2796 [ # # ]: 0 : cap.max_nb_queues != UINT16_MAX; i++) {
2797 [ # # # # ]: 0 : if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i))
2798 : 0 : count++;
2799 : : }
2800 [ # # ]: 0 : if (count > cap.max_nb_queues) {
2801 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "To many Tx hairpin queues max is %d",
2802 : : cap.max_nb_queues);
2803 : 0 : return -EINVAL;
2804 : : }
2805 [ # # ]: 0 : if (dev->data->dev_started)
2806 : : return -EBUSY;
2807 : 0 : eth_dev_txq_release(dev, tx_queue_id);
2808 : 0 : ret = dev->dev_ops->tx_hairpin_queue_setup(dev, tx_queue_id, nb_tx_desc, conf);
2809 [ # # ]: 0 : if (ret == 0)
2810 : 0 : dev->data->tx_queue_state[tx_queue_id] =
2811 : : RTE_ETH_QUEUE_STATE_HAIRPIN;
2812 : 0 : ret = eth_err(port_id, ret);
2813 : :
2814 : 0 : rte_eth_trace_tx_hairpin_queue_setup(port_id, tx_queue_id, nb_tx_desc,
2815 : : conf, ret);
2816 : :
2817 : 0 : return ret;
2818 : : }
2819 : :
2820 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_hairpin_bind, 20.11)
2821 : : int
2822 : 0 : rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port)
2823 : : {
2824 : : struct rte_eth_dev *dev;
2825 : : int ret;
2826 : :
2827 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
2828 : 0 : dev = &rte_eth_devices[tx_port];
2829 : :
2830 [ # # ]: 0 : if (dev->data->dev_started == 0) {
2831 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Tx port %d is not started", tx_port);
2832 : 0 : return -EBUSY;
2833 : : }
2834 : :
2835 [ # # ]: 0 : if (dev->dev_ops->hairpin_bind == NULL)
2836 : : return -ENOTSUP;
2837 : 0 : ret = dev->dev_ops->hairpin_bind(dev, rx_port);
2838 [ # # ]: 0 : if (ret != 0)
2839 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Failed to bind hairpin Tx %d"
2840 : : " to Rx %d (%d - all ports)",
2841 : : tx_port, rx_port, RTE_MAX_ETHPORTS);
2842 : :
2843 : 0 : rte_eth_trace_hairpin_bind(tx_port, rx_port, ret);
2844 : :
2845 : 0 : return ret;
2846 : : }
2847 : :
2848 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_hairpin_unbind, 20.11)
2849 : : int
2850 : 0 : rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port)
2851 : : {
2852 : : struct rte_eth_dev *dev;
2853 : : int ret;
2854 : :
2855 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV);
2856 : 0 : dev = &rte_eth_devices[tx_port];
2857 : :
2858 [ # # ]: 0 : if (dev->data->dev_started == 0) {
2859 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Tx port %d is already stopped", tx_port);
2860 : 0 : return -EBUSY;
2861 : : }
2862 : :
2863 [ # # ]: 0 : if (dev->dev_ops->hairpin_unbind == NULL)
2864 : : return -ENOTSUP;
2865 : 0 : ret = dev->dev_ops->hairpin_unbind(dev, rx_port);
2866 [ # # ]: 0 : if (ret != 0)
2867 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Failed to unbind hairpin Tx %d"
2868 : : " from Rx %d (%d - all ports)",
2869 : : tx_port, rx_port, RTE_MAX_ETHPORTS);
2870 : :
2871 : 0 : rte_eth_trace_hairpin_unbind(tx_port, rx_port, ret);
2872 : :
2873 : 0 : return ret;
2874 : : }
2875 : :
2876 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_hairpin_get_peer_ports, 20.11)
2877 : : int
2878 : 0 : rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports,
2879 : : size_t len, uint32_t direction)
2880 : : {
2881 : : struct rte_eth_dev *dev;
2882 : : int ret;
2883 : :
2884 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2885 : 0 : dev = &rte_eth_devices[port_id];
2886 : :
2887 [ # # ]: 0 : if (peer_ports == NULL) {
2888 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2889 : : "Cannot get ethdev port %u hairpin peer ports to NULL",
2890 : : port_id);
2891 : 0 : return -EINVAL;
2892 : : }
2893 : :
2894 [ # # ]: 0 : if (len == 0) {
2895 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2896 : : "Cannot get ethdev port %u hairpin peer ports to array with zero size",
2897 : : port_id);
2898 : 0 : return -EINVAL;
2899 : : }
2900 : :
2901 [ # # ]: 0 : if (dev->dev_ops->hairpin_get_peer_ports == NULL)
2902 : : return -ENOTSUP;
2903 : :
2904 : 0 : ret = dev->dev_ops->hairpin_get_peer_ports(dev, peer_ports, len, direction);
2905 [ # # ]: 0 : if (ret < 0)
2906 [ # # ]: 0 : RTE_ETHDEV_LOG_LINE(ERR, "Failed to get %d hairpin peer %s ports",
2907 : : port_id, direction ? "Rx" : "Tx");
2908 : :
2909 : 0 : rte_eth_trace_hairpin_get_peer_ports(port_id, peer_ports, len,
2910 : : direction, ret);
2911 : :
2912 : 0 : return ret;
2913 : : }
2914 : :
2915 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_drop_callback)
2916 : : void
2917 : 0 : rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent,
2918 : : void *userdata __rte_unused)
2919 : : {
2920 : 0 : rte_pktmbuf_free_bulk(pkts, unsent);
2921 : :
2922 : : rte_eth_trace_tx_buffer_drop_callback((void **)pkts, unsent);
2923 : 0 : }
2924 : :
2925 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_count_callback)
2926 : : void
2927 : 0 : rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent,
2928 : : void *userdata)
2929 : : {
2930 : : uint64_t *count = userdata;
2931 : :
2932 : 0 : rte_pktmbuf_free_bulk(pkts, unsent);
2933 : 0 : *count += unsent;
2934 : :
2935 : : rte_eth_trace_tx_buffer_count_callback((void **)pkts, unsent, *count);
2936 : 0 : }
2937 : :
2938 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_set_err_callback)
2939 : : int
2940 : 108 : rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer,
2941 : : buffer_tx_error_fn cbfn, void *userdata)
2942 : : {
2943 [ - + ]: 108 : if (buffer == NULL) {
2944 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
2945 : : "Cannot set Tx buffer error callback to NULL buffer");
2946 : 0 : return -EINVAL;
2947 : : }
2948 : :
2949 : 108 : buffer->error_callback = cbfn;
2950 [ - + ]: 108 : buffer->error_userdata = userdata;
2951 : :
2952 : : rte_eth_trace_tx_buffer_set_err_callback(buffer);
2953 : :
2954 : : return 0;
2955 : : }
2956 : :
2957 : : RTE_EXPORT_SYMBOL(rte_eth_tx_buffer_init)
2958 : : int
2959 : 54 : rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size)
2960 : : {
2961 : : int ret = 0;
2962 : :
2963 [ - + ]: 54 : if (buffer == NULL) {
2964 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot initialize NULL buffer");
2965 : 0 : return -EINVAL;
2966 : : }
2967 : :
2968 : 54 : buffer->size = size;
2969 [ + - ]: 54 : if (buffer->error_callback == NULL) {
2970 : 54 : ret = rte_eth_tx_buffer_set_err_callback(
2971 : : buffer, rte_eth_tx_buffer_drop_callback, NULL);
2972 : : }
2973 : :
2974 : 54 : rte_eth_trace_tx_buffer_init(buffer, size, ret);
2975 : :
2976 : 54 : return ret;
2977 : : }
2978 : :
2979 : : RTE_EXPORT_SYMBOL(rte_eth_tx_done_cleanup)
2980 : : int
2981 : 0 : rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt)
2982 : : {
2983 : : struct rte_eth_dev *dev;
2984 : : int ret;
2985 : :
2986 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
2987 : : dev = &rte_eth_devices[port_id];
2988 : :
2989 : : #ifdef RTE_ETHDEV_DEBUG_TX
2990 : : ret = eth_dev_validate_tx_queue(dev, queue_id);
2991 : : if (ret != 0)
2992 : : return ret;
2993 : : #endif
2994 : :
2995 [ # # ]: 0 : if (dev->dev_ops->tx_done_cleanup == NULL)
2996 : : return -ENOTSUP;
2997 : :
2998 : : /* Call driver to free pending mbufs. */
2999 : 0 : ret = dev->dev_ops->tx_done_cleanup(dev->data->tx_queues[queue_id], free_cnt);
3000 : 0 : ret = eth_err(port_id, ret);
3001 : :
3002 : 0 : rte_eth_trace_tx_done_cleanup(port_id, queue_id, free_cnt, ret);
3003 : :
3004 : 0 : return ret;
3005 : : }
3006 : :
3007 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_enable)
3008 : : int
3009 : 2 : rte_eth_promiscuous_enable(uint16_t port_id)
3010 : : {
3011 : : struct rte_eth_dev *dev;
3012 : : int diag = 0;
3013 : :
3014 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3015 : 2 : dev = &rte_eth_devices[port_id];
3016 : :
3017 [ - + ]: 2 : if (dev->data->promiscuous == 1)
3018 : : return 0;
3019 : :
3020 [ # # ]: 0 : if (dev->dev_ops->promiscuous_enable == NULL)
3021 : : return -ENOTSUP;
3022 : :
3023 : 0 : diag = dev->dev_ops->promiscuous_enable(dev);
3024 [ # # ]: 0 : if (diag == 0)
3025 : 0 : dev->data->promiscuous = 1;
3026 : :
3027 : 0 : diag = eth_err(port_id, diag);
3028 : :
3029 [ # # ]: 0 : rte_eth_trace_promiscuous_enable(port_id, dev->data->promiscuous,
3030 : : diag);
3031 : :
3032 : 0 : return diag;
3033 : : }
3034 : :
3035 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_disable)
3036 : : int
3037 : 0 : rte_eth_promiscuous_disable(uint16_t port_id)
3038 : : {
3039 : : struct rte_eth_dev *dev;
3040 : : int diag = 0;
3041 : :
3042 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3043 : 0 : dev = &rte_eth_devices[port_id];
3044 : :
3045 [ # # ]: 0 : if (dev->data->promiscuous == 0)
3046 : : return 0;
3047 : :
3048 [ # # ]: 0 : if (dev->dev_ops->promiscuous_disable == NULL)
3049 : : return -ENOTSUP;
3050 : :
3051 : 0 : diag = dev->dev_ops->promiscuous_disable(dev);
3052 [ # # ]: 0 : if (diag == 0)
3053 : 0 : dev->data->promiscuous = 0;
3054 : :
3055 : 0 : diag = eth_err(port_id, diag);
3056 : :
3057 [ # # ]: 0 : rte_eth_trace_promiscuous_disable(port_id, dev->data->promiscuous,
3058 : : diag);
3059 : :
3060 : 0 : return diag;
3061 : : }
3062 : :
3063 : : RTE_EXPORT_SYMBOL(rte_eth_promiscuous_get)
3064 : : int
3065 : 10 : rte_eth_promiscuous_get(uint16_t port_id)
3066 : : {
3067 : : struct rte_eth_dev *dev;
3068 : :
3069 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3070 : : dev = &rte_eth_devices[port_id];
3071 : :
3072 [ - + ]: 10 : rte_eth_trace_promiscuous_get(port_id, dev->data->promiscuous);
3073 : :
3074 : 10 : return dev->data->promiscuous;
3075 : : }
3076 : :
3077 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_enable)
3078 : : int
3079 : 0 : rte_eth_allmulticast_enable(uint16_t port_id)
3080 : : {
3081 : : struct rte_eth_dev *dev;
3082 : : int diag;
3083 : :
3084 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3085 : 0 : dev = &rte_eth_devices[port_id];
3086 : :
3087 [ # # ]: 0 : if (dev->data->all_multicast == 1)
3088 : : return 0;
3089 : :
3090 [ # # ]: 0 : if (dev->dev_ops->allmulticast_enable == NULL)
3091 : : return -ENOTSUP;
3092 : 0 : diag = dev->dev_ops->allmulticast_enable(dev);
3093 [ # # ]: 0 : if (diag == 0)
3094 : 0 : dev->data->all_multicast = 1;
3095 : :
3096 : 0 : diag = eth_err(port_id, diag);
3097 : :
3098 [ # # ]: 0 : rte_eth_trace_allmulticast_enable(port_id, dev->data->all_multicast,
3099 : : diag);
3100 : :
3101 : 0 : return diag;
3102 : : }
3103 : :
3104 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_disable)
3105 : : int
3106 : 0 : rte_eth_allmulticast_disable(uint16_t port_id)
3107 : : {
3108 : : struct rte_eth_dev *dev;
3109 : : int diag;
3110 : :
3111 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3112 : 0 : dev = &rte_eth_devices[port_id];
3113 : :
3114 [ # # ]: 0 : if (dev->data->all_multicast == 0)
3115 : : return 0;
3116 : :
3117 [ # # ]: 0 : if (dev->dev_ops->allmulticast_disable == NULL)
3118 : : return -ENOTSUP;
3119 : :
3120 : 0 : diag = dev->dev_ops->allmulticast_disable(dev);
3121 [ # # ]: 0 : if (diag == 0)
3122 : 0 : dev->data->all_multicast = 0;
3123 : :
3124 : 0 : diag = eth_err(port_id, diag);
3125 : :
3126 [ # # ]: 0 : rte_eth_trace_allmulticast_disable(port_id, dev->data->all_multicast,
3127 : : diag);
3128 : :
3129 : 0 : return diag;
3130 : : }
3131 : :
3132 : : RTE_EXPORT_SYMBOL(rte_eth_allmulticast_get)
3133 : : int
3134 : 10 : rte_eth_allmulticast_get(uint16_t port_id)
3135 : : {
3136 : : struct rte_eth_dev *dev;
3137 : :
3138 [ - + ]: 10 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3139 : : dev = &rte_eth_devices[port_id];
3140 : :
3141 [ - + ]: 10 : rte_eth_trace_allmulticast_get(port_id, dev->data->all_multicast);
3142 : :
3143 : 10 : return dev->data->all_multicast;
3144 : : }
3145 : :
3146 : : RTE_EXPORT_SYMBOL(rte_eth_link_get)
3147 : : int
3148 : 7 : rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
3149 : : {
3150 : : struct rte_eth_dev *dev;
3151 : :
3152 [ - + ]: 7 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3153 : 7 : dev = &rte_eth_devices[port_id];
3154 : :
3155 [ - + ]: 7 : if (eth_link == NULL) {
3156 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u link to NULL",
3157 : : port_id);
3158 : 0 : return -EINVAL;
3159 : : }
3160 : :
3161 [ - + - - ]: 7 : if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
3162 : 0 : rte_eth_linkstatus_get(dev, eth_link);
3163 : : else {
3164 [ + - ]: 7 : if (dev->dev_ops->link_update == NULL)
3165 : : return -ENOTSUP;
3166 : 7 : dev->dev_ops->link_update(dev, 1);
3167 : 7 : *eth_link = dev->data->dev_link;
3168 : : }
3169 : :
3170 : : rte_eth_trace_link_get(port_id, eth_link);
3171 : :
3172 : : return 0;
3173 : : }
3174 : :
3175 : : RTE_EXPORT_SYMBOL(rte_eth_link_get_nowait)
3176 : : int
3177 : 1 : rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
3178 : : {
3179 : : struct rte_eth_dev *dev;
3180 : :
3181 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3182 : 1 : dev = &rte_eth_devices[port_id];
3183 : :
3184 [ - + ]: 1 : if (eth_link == NULL) {
3185 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u link to NULL",
3186 : : port_id);
3187 : 0 : return -EINVAL;
3188 : : }
3189 : :
3190 [ - + - - ]: 1 : if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started)
3191 : 0 : rte_eth_linkstatus_get(dev, eth_link);
3192 : : else {
3193 [ + - ]: 1 : if (dev->dev_ops->link_update == NULL)
3194 : : return -ENOTSUP;
3195 : 1 : dev->dev_ops->link_update(dev, 0);
3196 : 1 : *eth_link = dev->data->dev_link;
3197 : : }
3198 : :
3199 : 1 : rte_eth_trace_link_get_nowait(port_id, eth_link);
3200 : :
3201 : 1 : return 0;
3202 : : }
3203 : :
3204 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_speed_to_str, 20.11)
3205 : : const char *
3206 : 24 : rte_eth_link_speed_to_str(uint32_t link_speed)
3207 : : {
3208 : : const char *ret;
3209 : :
3210 [ + + + + : 24 : switch (link_speed) {
+ + + + +
+ + + + +
+ + + + ]
3211 : : case RTE_ETH_SPEED_NUM_NONE:
3212 : : ret = "None";
3213 : : break;
3214 : 2 : case RTE_ETH_SPEED_NUM_10M:
3215 : : ret = "10 Mbps";
3216 : 2 : break;
3217 : 1 : case RTE_ETH_SPEED_NUM_100M:
3218 : : ret = "100 Mbps";
3219 : 1 : break;
3220 : 1 : case RTE_ETH_SPEED_NUM_1G:
3221 : : ret = "1 Gbps";
3222 : 1 : break;
3223 : 2 : case RTE_ETH_SPEED_NUM_2_5G:
3224 : : ret = "2.5 Gbps";
3225 : 2 : break;
3226 : 1 : case RTE_ETH_SPEED_NUM_5G:
3227 : : ret = "5 Gbps";
3228 : 1 : break;
3229 : 1 : case RTE_ETH_SPEED_NUM_10G:
3230 : : ret = "10 Gbps";
3231 : 1 : break;
3232 : 1 : case RTE_ETH_SPEED_NUM_20G:
3233 : : ret = "20 Gbps";
3234 : 1 : break;
3235 : 1 : case RTE_ETH_SPEED_NUM_25G:
3236 : : ret = "25 Gbps";
3237 : 1 : break;
3238 : 1 : case RTE_ETH_SPEED_NUM_40G:
3239 : : ret = "40 Gbps";
3240 : 1 : break;
3241 : 1 : case RTE_ETH_SPEED_NUM_50G:
3242 : : ret = "50 Gbps";
3243 : 1 : break;
3244 : 1 : case RTE_ETH_SPEED_NUM_56G:
3245 : : ret = "56 Gbps";
3246 : 1 : break;
3247 : 1 : case RTE_ETH_SPEED_NUM_100G:
3248 : : ret = "100 Gbps";
3249 : 1 : break;
3250 : 1 : case RTE_ETH_SPEED_NUM_200G:
3251 : : ret = "200 Gbps";
3252 : 1 : break;
3253 : 1 : case RTE_ETH_SPEED_NUM_400G:
3254 : : ret = "400 Gbps";
3255 : 1 : break;
3256 : 2 : case RTE_ETH_SPEED_NUM_800G:
3257 : : ret = "800 Gbps";
3258 : 2 : break;
3259 : 2 : case RTE_ETH_SPEED_NUM_UNKNOWN:
3260 : : ret = "Unknown";
3261 : 2 : break;
3262 : 2 : default:
3263 : : ret = "Invalid";
3264 : : }
3265 : :
3266 : : rte_eth_trace_link_speed_to_str(link_speed, ret);
3267 : :
3268 : 24 : return ret;
3269 : : }
3270 : :
3271 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_to_str, 20.11)
3272 : : int
3273 : 7 : rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link)
3274 : : {
3275 : : int ret;
3276 : :
3277 [ - + ]: 7 : if (str == NULL) {
3278 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot convert link to NULL string");
3279 : 0 : return -EINVAL;
3280 : : }
3281 : :
3282 [ - + ]: 7 : if (len == 0) {
3283 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
3284 : : "Cannot convert link to string with zero size");
3285 : 0 : return -EINVAL;
3286 : : }
3287 : :
3288 [ - + ]: 7 : if (eth_link == NULL) {
3289 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot convert to string from NULL link");
3290 : 0 : return -EINVAL;
3291 : : }
3292 : :
3293 [ + + ]: 7 : if (eth_link->link_status == RTE_ETH_LINK_DOWN)
3294 : : ret = snprintf(str, len, "Link down");
3295 : : else
3296 : 24 : ret = snprintf(str, len, "Link up at %s %s %s %s",
3297 : 6 : rte_eth_link_speed_to_str(eth_link->link_speed),
3298 [ + + ]: 6 : (eth_link->link_duplex == RTE_ETH_LINK_FULL_DUPLEX) ?
3299 : : "FDX" : "HDX",
3300 [ + + ]: 6 : (eth_link->link_autoneg == RTE_ETH_LINK_AUTONEG) ?
3301 : : "Autoneg" : "Fixed",
3302 : 6 : rte_eth_link_connector_to_str(eth_link->link_connector));
3303 : :
3304 : 7 : rte_eth_trace_link_to_str(len, eth_link, str, ret);
3305 : :
3306 : 7 : return ret;
3307 : : }
3308 : :
3309 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_link_connector_to_str, 25.11)
3310 : : const char *
3311 : 6 : rte_eth_link_connector_to_str(enum rte_eth_link_connector link_connector)
3312 : : {
3313 : : static const char * const link_connector_str[] = {
3314 : : [RTE_ETH_LINK_CONNECTOR_NONE] = "None",
3315 : : [RTE_ETH_LINK_CONNECTOR_TP] = "Twisted Pair",
3316 : : [RTE_ETH_LINK_CONNECTOR_AUI] = "Attachment Unit Interface",
3317 : : [RTE_ETH_LINK_CONNECTOR_MII] = "Media Independent Interface",
3318 : : [RTE_ETH_LINK_CONNECTOR_FIBER] = "Fiber",
3319 : : [RTE_ETH_LINK_CONNECTOR_BNC] = "BNC",
3320 : : [RTE_ETH_LINK_CONNECTOR_DAC] = "Direct Attach Copper",
3321 : : [RTE_ETH_LINK_CONNECTOR_SGMII] = "SGMII",
3322 : : [RTE_ETH_LINK_CONNECTOR_QSGMII] = "QSGMII",
3323 : : [RTE_ETH_LINK_CONNECTOR_XFI] = "XFI",
3324 : : [RTE_ETH_LINK_CONNECTOR_SFI] = "SFI",
3325 : : [RTE_ETH_LINK_CONNECTOR_XLAUI] = "XLAUI",
3326 : : [RTE_ETH_LINK_CONNECTOR_GAUI] = "GAUI",
3327 : : [RTE_ETH_LINK_CONNECTOR_XAUI] = "XAUI",
3328 : : [RTE_ETH_LINK_CONNECTOR_CAUI] = "CAUI",
3329 : : [RTE_ETH_LINK_CONNECTOR_LAUI] = "LAUI",
3330 : : [RTE_ETH_LINK_CONNECTOR_SFP] = "SFP",
3331 : : [RTE_ETH_LINK_CONNECTOR_SFP_DD] = "SFP-DD",
3332 : : [RTE_ETH_LINK_CONNECTOR_SFP_PLUS] = "SFP+",
3333 : : [RTE_ETH_LINK_CONNECTOR_SFP28] = "SFP28",
3334 : : [RTE_ETH_LINK_CONNECTOR_QSFP] = "QSFP",
3335 : : [RTE_ETH_LINK_CONNECTOR_QSFP_PLUS] = "QSFP+",
3336 : : [RTE_ETH_LINK_CONNECTOR_QSFP28] = "QSFP28",
3337 : : [RTE_ETH_LINK_CONNECTOR_QSFP56] = "QSFP56",
3338 : : [RTE_ETH_LINK_CONNECTOR_QSFP_DD] = "QSFP-DD",
3339 : : [RTE_ETH_LINK_CONNECTOR_OTHER] = "Other",
3340 : : };
3341 : : const char *str = NULL;
3342 : :
3343 [ + - ]: 6 : if (link_connector < ((enum rte_eth_link_connector)RTE_DIM(link_connector_str)))
3344 : 6 : str = link_connector_str[link_connector];
3345 : :
3346 : 6 : return str;
3347 : : }
3348 : :
3349 : : RTE_EXPORT_SYMBOL(rte_eth_stats_get)
3350 : : int
3351 : 20 : rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats)
3352 : : {
3353 : 20 : int ret = eth_stats_qstats_get(port_id, stats, NULL);
3354 : :
3355 : : rte_eth_trace_stats_get(port_id, stats, ret);
3356 : 20 : return ret;
3357 : : }
3358 : :
3359 : : RTE_EXPORT_SYMBOL(rte_eth_stats_reset)
3360 : : int
3361 : 4 : rte_eth_stats_reset(uint16_t port_id)
3362 : : {
3363 : : struct rte_eth_dev *dev;
3364 : : int ret;
3365 : :
3366 [ - + ]: 4 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3367 : 4 : dev = &rte_eth_devices[port_id];
3368 : :
3369 [ + - ]: 4 : if (dev->dev_ops->stats_reset == NULL)
3370 : : return -ENOTSUP;
3371 : 4 : ret = dev->dev_ops->stats_reset(dev);
3372 [ - + ]: 4 : if (ret != 0)
3373 : 0 : return eth_err(port_id, ret);
3374 : :
3375 [ - + ]: 4 : dev->data->rx_mbuf_alloc_failed = 0;
3376 : :
3377 : 4 : rte_eth_trace_stats_reset(port_id);
3378 : :
3379 : 4 : return 0;
3380 : : }
3381 : :
3382 : : static inline int
3383 : : eth_dev_get_xstats_basic_count(struct rte_eth_dev *dev)
3384 : : {
3385 : : uint16_t nb_rxqs, nb_txqs;
3386 : : int count;
3387 : :
3388 : 3 : nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3389 : 3 : nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3390 : :
3391 : : count = RTE_NB_STATS;
3392 [ + - ]: 1 : if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) {
3393 : 3 : count += nb_rxqs * RTE_NB_RXQ_STATS;
3394 : 3 : count += nb_txqs * RTE_NB_TXQ_STATS;
3395 : : }
3396 : :
3397 : : return count;
3398 : : }
3399 : :
3400 : : static int
3401 : 1 : eth_dev_get_xstats_count(uint16_t port_id)
3402 : : {
3403 : : struct rte_eth_dev *dev;
3404 : : int count;
3405 : :
3406 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3407 : 1 : dev = &rte_eth_devices[port_id];
3408 [ - + ]: 1 : if (dev->dev_ops->xstats_get_names != NULL) {
3409 : 0 : count = dev->dev_ops->xstats_get_names(dev, NULL, 0);
3410 [ # # ]: 0 : if (count < 0)
3411 : 0 : return eth_err(port_id, count);
3412 : : } else
3413 : : count = 0;
3414 : :
3415 : :
3416 : 1 : count += eth_dev_get_xstats_basic_count(dev);
3417 : :
3418 : 1 : return count;
3419 : : }
3420 : :
3421 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_id_by_name)
3422 : : int
3423 : 0 : rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name,
3424 : : uint64_t *id)
3425 : : {
3426 : : int cnt_xstats, idx_xstat, rc;
3427 : : struct rte_eth_xstat_name *xstats_names;
3428 : :
3429 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3430 : :
3431 [ # # ]: 0 : if (xstat_name == NULL) {
3432 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
3433 : : "Cannot get ethdev port %u xstats ID from NULL xstat name",
3434 : : port_id);
3435 : 0 : return -ENOMEM;
3436 : : }
3437 : :
3438 [ # # ]: 0 : if (id == NULL) {
3439 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
3440 : : "Cannot get ethdev port %u xstats ID to NULL",
3441 : : port_id);
3442 : 0 : return -ENOMEM;
3443 : : }
3444 : :
3445 : : /* Get count */
3446 : 0 : cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL);
3447 [ # # ]: 0 : if (cnt_xstats < 0) {
3448 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get count of xstats");
3449 : 0 : return -ENODEV;
3450 : : }
3451 : :
3452 : : /* Get id-name lookup table */
3453 : 0 : xstats_names = calloc(cnt_xstats, sizeof(xstats_names[0]));
3454 [ # # ]: 0 : if (xstats_names == NULL) {
3455 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3456 : 0 : return -ENOMEM;
3457 : : }
3458 : :
3459 [ # # ]: 0 : if (cnt_xstats != rte_eth_xstats_get_names_by_id(
3460 : : port_id, xstats_names, cnt_xstats, NULL)) {
3461 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get xstats lookup");
3462 : 0 : free(xstats_names);
3463 : 0 : return -1;
3464 : : }
3465 : :
3466 : : rc = -EINVAL;
3467 [ # # ]: 0 : for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) {
3468 [ # # ]: 0 : if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) {
3469 [ # # ]: 0 : *id = idx_xstat;
3470 : :
3471 : 0 : rte_eth_trace_xstats_get_id_by_name(port_id,
3472 : : xstat_name, *id);
3473 : : rc = 0;
3474 : 0 : break;
3475 : : };
3476 : : }
3477 : :
3478 : 0 : free(xstats_names);
3479 : 0 : return rc;
3480 : : }
3481 : :
3482 : : /* retrieve basic stats names */
3483 : : static int
3484 : 1 : eth_basic_stats_get_names(struct rte_eth_dev *dev,
3485 : : struct rte_eth_xstat_name *xstats_names)
3486 : : {
3487 : : int cnt_used_entries = 0;
3488 : : uint32_t idx, id_queue;
3489 : : uint16_t num_q;
3490 : :
3491 [ + + ]: 9 : for (idx = 0; idx < RTE_NB_STATS; idx++) {
3492 : 8 : strlcpy(xstats_names[cnt_used_entries].name,
3493 : : eth_dev_stats_strings[idx].name,
3494 : : sizeof(xstats_names[0].name));
3495 : 8 : cnt_used_entries++;
3496 : : }
3497 : :
3498 [ + - ]: 1 : if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
3499 : : return cnt_used_entries;
3500 : :
3501 : 1 : num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3502 [ + + ]: 2 : for (id_queue = 0; id_queue < num_q; id_queue++) {
3503 [ + + ]: 4 : for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) {
3504 : 3 : snprintf(xstats_names[cnt_used_entries].name,
3505 : : sizeof(xstats_names[0].name),
3506 : : "rx_q%u_%s",
3507 : 3 : id_queue, eth_dev_rxq_stats_strings[idx].name);
3508 : 3 : cnt_used_entries++;
3509 : : }
3510 : :
3511 : : }
3512 : 1 : num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3513 [ + + ]: 2 : for (id_queue = 0; id_queue < num_q; id_queue++) {
3514 [ + + ]: 3 : for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) {
3515 : 2 : snprintf(xstats_names[cnt_used_entries].name,
3516 : : sizeof(xstats_names[0].name),
3517 : : "tx_q%u_%s",
3518 : 2 : id_queue, eth_dev_txq_stats_strings[idx].name);
3519 : 2 : cnt_used_entries++;
3520 : : }
3521 : : }
3522 : : return cnt_used_entries;
3523 : : }
3524 : :
3525 : : static int
3526 : 0 : eth_xstats_get_by_name_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3527 : : struct rte_eth_xstat_name *xstats_names, uint32_t size,
3528 : : uint32_t basic_count)
3529 : : {
3530 : : int32_t rc;
3531 : : uint32_t i, k, m, n;
3532 : : uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
3533 : :
3534 : : m = 0;
3535 [ # # ]: 0 : for (n = 0; n != size; n += k) {
3536 : :
3537 : 0 : k = RTE_MIN(size - n, RTE_DIM(ids_copy));
3538 : :
3539 : : /*
3540 : : * Convert ids to xstats ids that PMD knows.
3541 : : * ids known by user are basic + extended stats.
3542 : : */
3543 [ # # ]: 0 : for (i = 0; i < k; i++)
3544 : 0 : ids_copy[i] = ids[n + i] - basic_count;
3545 : :
3546 : 0 : rc = dev->dev_ops->xstats_get_names_by_id(dev, ids_copy, xstats_names + m, k);
3547 [ # # ]: 0 : if (rc < 0)
3548 : 0 : return rc;
3549 : 0 : m += rc;
3550 : : }
3551 : :
3552 : 0 : return m;
3553 : : }
3554 : :
3555 : :
3556 : : /* retrieve ethdev extended statistics names */
3557 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names_by_id)
3558 : : int
3559 : 0 : rte_eth_xstats_get_names_by_id(uint16_t port_id,
3560 : : struct rte_eth_xstat_name *xstats_names, unsigned int size,
3561 : : uint64_t *ids)
3562 : : {
3563 : : struct rte_eth_xstat_name *xstats_names_copy;
3564 : : unsigned int expected_entries;
3565 : : unsigned int nb_basic_stats;
3566 : : unsigned int basic_count;
3567 : : struct rte_eth_dev *dev;
3568 : : unsigned int i;
3569 : : int ret;
3570 : :
3571 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3572 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3573 : :
3574 : 0 : basic_count = eth_dev_get_xstats_basic_count(dev);
3575 : 0 : ret = eth_dev_get_xstats_count(port_id);
3576 [ # # ]: 0 : if (ret < 0)
3577 : : return ret;
3578 : 0 : expected_entries = (unsigned int)ret;
3579 : :
3580 : : /* Return max number of stats if no ids given */
3581 [ # # ]: 0 : if (!ids) {
3582 [ # # ]: 0 : if (!xstats_names)
3583 : : return expected_entries;
3584 [ # # ]: 0 : else if (xstats_names && size < expected_entries)
3585 : : return expected_entries;
3586 : : }
3587 : :
3588 [ # # ]: 0 : if (ids && !xstats_names)
3589 : : return -EINVAL;
3590 : :
3591 : : nb_basic_stats = 0;
3592 [ # # ]: 0 : if (ids != NULL) {
3593 [ # # ]: 0 : for (i = 0; i < size; i++)
3594 : 0 : nb_basic_stats += (ids[i] < basic_count);
3595 : : }
3596 : :
3597 : : /* no basic stats requested, devops function provided */
3598 [ # # # # ]: 0 : if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
3599 [ # # ]: 0 : dev->dev_ops->xstats_get_names_by_id != NULL)
3600 : 0 : return eth_xstats_get_by_name_by_id(dev, ids, xstats_names,
3601 : : size, basic_count);
3602 : :
3603 : : /* Retrieve all stats */
3604 [ # # ]: 0 : if (!ids) {
3605 : 0 : int num_stats = rte_eth_xstats_get_names(port_id, xstats_names,
3606 : : expected_entries);
3607 [ # # ]: 0 : if (num_stats < 0 || num_stats > (int)expected_entries)
3608 : : return num_stats;
3609 : : else
3610 : 0 : return expected_entries;
3611 : : }
3612 : :
3613 : 0 : xstats_names_copy = calloc(expected_entries,
3614 : : sizeof(struct rte_eth_xstat_name));
3615 : :
3616 [ # # ]: 0 : if (!xstats_names_copy) {
3617 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3618 : 0 : return -ENOMEM;
3619 : : }
3620 : :
3621 : : /* Fill xstats_names_copy structure */
3622 [ # # ]: 0 : if (ids && nb_basic_stats == size) {
3623 : 0 : eth_basic_stats_get_names(dev, xstats_names_copy);
3624 : : } else {
3625 : 0 : ret = rte_eth_xstats_get_names(port_id, xstats_names_copy,
3626 : : expected_entries);
3627 [ # # ]: 0 : if (ret < 0) {
3628 : 0 : free(xstats_names_copy);
3629 : 0 : return ret;
3630 : : }
3631 : : }
3632 : :
3633 : : /* Filter stats */
3634 [ # # ]: 0 : for (i = 0; i < size; i++) {
3635 [ # # ]: 0 : if (ids[i] >= expected_entries) {
3636 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
3637 : 0 : free(xstats_names_copy);
3638 : 0 : return -1;
3639 : : }
3640 [ # # ]: 0 : xstats_names[i] = xstats_names_copy[ids[i]];
3641 : :
3642 : 0 : rte_eth_trace_xstats_get_names_by_id(port_id, &xstats_names[i],
3643 : : ids[i]);
3644 : : }
3645 : :
3646 : 0 : free(xstats_names_copy);
3647 : 0 : return size;
3648 : : }
3649 : :
3650 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_names)
3651 : : int
3652 : 1 : rte_eth_xstats_get_names(uint16_t port_id,
3653 : : struct rte_eth_xstat_name *xstats_names,
3654 : : unsigned int size)
3655 : : {
3656 : : struct rte_eth_dev *dev;
3657 : : int cnt_used_entries;
3658 : : int cnt_expected_entries;
3659 : : int cnt_driver_entries;
3660 : : int i;
3661 : :
3662 : 1 : cnt_expected_entries = eth_dev_get_xstats_count(port_id);
3663 [ + - ]: 1 : if (xstats_names == NULL || cnt_expected_entries < 0 ||
3664 [ + - ]: 1 : (int)size < cnt_expected_entries)
3665 : : return cnt_expected_entries;
3666 : :
3667 : : /* port_id checked in eth_dev_get_xstats_count() */
3668 : 1 : dev = &rte_eth_devices[port_id];
3669 : :
3670 : 1 : cnt_used_entries = eth_basic_stats_get_names(dev, xstats_names);
3671 : :
3672 [ - + ]: 1 : if (dev->dev_ops->xstats_get_names != NULL) {
3673 : : /* If there are any driver-specific xstats, append them
3674 : : * to end of list.
3675 : : */
3676 : 0 : cnt_driver_entries = dev->dev_ops->xstats_get_names(
3677 : : dev,
3678 : 0 : xstats_names + cnt_used_entries,
3679 : : size - cnt_used_entries);
3680 [ # # ]: 0 : if (cnt_driver_entries < 0)
3681 : 0 : return eth_err(port_id, cnt_driver_entries);
3682 : 0 : cnt_used_entries += cnt_driver_entries;
3683 : : }
3684 : :
3685 [ + + ]: 14 : for (i = 0; i < cnt_used_entries; i++)
3686 [ - + ]: 13 : rte_eth_trace_xstats_get_names(port_id, i, &xstats_names[i],
3687 : : size, cnt_used_entries);
3688 : :
3689 : : return cnt_used_entries;
3690 : : }
3691 : :
3692 : :
3693 : : static int
3694 : 1 : eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats)
3695 : : {
3696 : : struct rte_eth_dev *dev;
3697 : : struct rte_eth_stats eth_stats;
3698 : : struct eth_queue_stats queue_stats;
3699 : : unsigned int count = 0, i, q;
3700 : : uint64_t val, *stats_ptr;
3701 : : uint16_t nb_rxqs, nb_txqs;
3702 : : int ret;
3703 : :
3704 : 1 : ret = eth_stats_qstats_get(port_id, ð_stats, &queue_stats);
3705 [ + - ]: 1 : if (ret < 0)
3706 : : return ret;
3707 : :
3708 : : dev = &rte_eth_devices[port_id];
3709 : :
3710 : 1 : nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3711 : 1 : nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS);
3712 : :
3713 : : /* global stats */
3714 [ + + ]: 9 : for (i = 0; i < RTE_NB_STATS; i++) {
3715 : 8 : stats_ptr = RTE_PTR_ADD(ð_stats,
3716 : : eth_dev_stats_strings[i].offset);
3717 : 8 : val = *stats_ptr;
3718 : 8 : xstats[count++].value = val;
3719 : : }
3720 : :
3721 [ + - ]: 1 : if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0)
3722 : : return count;
3723 : :
3724 : : /* per-rxq stats */
3725 [ + + ]: 2 : for (q = 0; q < nb_rxqs; q++) {
3726 [ + + ]: 4 : for (i = 0; i < RTE_NB_RXQ_STATS; i++) {
3727 : 3 : stats_ptr = RTE_PTR_ADD(&queue_stats,
3728 : : eth_dev_rxq_stats_strings[i].offset +
3729 : : q * sizeof(uint64_t));
3730 : 3 : val = *stats_ptr;
3731 : 3 : xstats[count++].value = val;
3732 : : }
3733 : : }
3734 : :
3735 : : /* per-txq stats */
3736 [ + + ]: 2 : for (q = 0; q < nb_txqs; q++) {
3737 [ + + ]: 3 : for (i = 0; i < RTE_NB_TXQ_STATS; i++) {
3738 : 2 : stats_ptr = RTE_PTR_ADD(&queue_stats,
3739 : : eth_dev_txq_stats_strings[i].offset +
3740 : : q * sizeof(uint64_t));
3741 : 2 : val = *stats_ptr;
3742 : 2 : xstats[count++].value = val;
3743 : : }
3744 : : }
3745 : 1 : return count;
3746 : : }
3747 : :
3748 : : static int
3749 : 0 : eth_xtats_get_by_id(struct rte_eth_dev *dev, const uint64_t *ids,
3750 : : uint64_t *values, uint32_t size, uint32_t basic_count)
3751 : : {
3752 : : int32_t rc;
3753 : : uint32_t i, k, m, n;
3754 : : uint64_t ids_copy[ETH_XSTATS_ITER_NUM];
3755 : :
3756 : : m = 0;
3757 [ # # ]: 0 : for (n = 0; n != size; n += k) {
3758 : :
3759 : 0 : k = RTE_MIN(size - n, RTE_DIM(ids_copy));
3760 : :
3761 : : /*
3762 : : * Convert ids to xstats ids that PMD knows.
3763 : : * ids known by user are basic + extended stats.
3764 : : */
3765 [ # # ]: 0 : for (i = 0; i < k; i++)
3766 : 0 : ids_copy[i] = ids[n + i] - basic_count;
3767 : :
3768 : 0 : rc = dev->dev_ops->xstats_get_by_id(dev, ids_copy, values + m, k);
3769 [ # # ]: 0 : if (rc < 0)
3770 : 0 : return rc;
3771 : 0 : m += rc;
3772 : : }
3773 : :
3774 : 0 : return m;
3775 : : }
3776 : :
3777 : : /* retrieve ethdev extended statistics */
3778 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get_by_id)
3779 : : int
3780 : 0 : rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids,
3781 : : uint64_t *values, unsigned int size)
3782 : : {
3783 : : unsigned int nb_basic_stats;
3784 : : unsigned int num_xstats_filled;
3785 : : unsigned int basic_count;
3786 : : uint16_t expected_entries;
3787 : : struct rte_eth_dev *dev;
3788 : : struct rte_eth_xstat *xstats;
3789 : : unsigned int i;
3790 : : int ret;
3791 : :
3792 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3793 : 0 : dev = &rte_eth_devices[port_id];
3794 : :
3795 : 0 : ret = eth_dev_get_xstats_count(port_id);
3796 [ # # ]: 0 : if (ret < 0)
3797 : : return ret;
3798 [ # # ]: 0 : expected_entries = (uint16_t)ret;
3799 : 0 : basic_count = eth_dev_get_xstats_basic_count(dev);
3800 : :
3801 : : /* Return max number of stats if no ids given */
3802 [ # # ]: 0 : if (!ids) {
3803 [ # # ]: 0 : if (!values)
3804 : 0 : return expected_entries;
3805 [ # # ]: 0 : else if (values && size < expected_entries)
3806 : : return expected_entries;
3807 : : }
3808 : :
3809 [ # # ]: 0 : if (ids && !values)
3810 : : return -EINVAL;
3811 : :
3812 : : nb_basic_stats = 0;
3813 [ # # ]: 0 : if (ids != NULL) {
3814 [ # # ]: 0 : for (i = 0; i < size; i++)
3815 : 0 : nb_basic_stats += (ids[i] < basic_count);
3816 : : }
3817 : :
3818 : : /* no basic stats requested, devops function provided */
3819 [ # # # # ]: 0 : if (nb_basic_stats == 0 && ids != NULL && size != 0 &&
3820 [ # # ]: 0 : dev->dev_ops->xstats_get_by_id != NULL)
3821 : 0 : return eth_xtats_get_by_id(dev, ids, values, size, basic_count);
3822 : :
3823 : 0 : xstats = calloc(expected_entries, sizeof(xstats[0]));
3824 [ # # ]: 0 : if (xstats == NULL) {
3825 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Can't allocate memory");
3826 : 0 : return -ENOMEM;
3827 : : }
3828 : :
3829 : : /* Fill the xstats structure */
3830 [ # # ]: 0 : if (ids && nb_basic_stats == size)
3831 : 0 : ret = eth_basic_stats_get(port_id, xstats);
3832 : : else
3833 : 0 : ret = rte_eth_xstats_get(port_id, xstats, expected_entries);
3834 : :
3835 [ # # ]: 0 : if (ret < 0) {
3836 : 0 : free(xstats);
3837 : 0 : return ret;
3838 : : }
3839 : 0 : num_xstats_filled = (unsigned int)ret;
3840 : :
3841 : : /* Return all stats */
3842 [ # # ]: 0 : if (!ids) {
3843 [ # # ]: 0 : for (i = 0; i < num_xstats_filled; i++)
3844 : 0 : values[i] = xstats[i].value;
3845 : :
3846 : 0 : free(xstats);
3847 : 0 : return expected_entries;
3848 : : }
3849 : :
3850 : : /* Filter stats */
3851 [ # # ]: 0 : for (i = 0; i < size; i++) {
3852 [ # # ]: 0 : if (ids[i] >= expected_entries) {
3853 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Id value isn't valid");
3854 : 0 : break;
3855 : : }
3856 : 0 : values[i] = xstats[ids[i]].value;
3857 : : }
3858 : :
3859 : 0 : rte_eth_trace_xstats_get_by_id(port_id, ids, values, size);
3860 : :
3861 : 0 : free(xstats);
3862 [ # # ]: 0 : return (i == size) ? (int32_t)size : -1;
3863 : : }
3864 : :
3865 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_get)
3866 : : int
3867 : 2 : rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
3868 : : unsigned int n)
3869 : : {
3870 : : struct rte_eth_dev *dev;
3871 : : unsigned int count, i;
3872 : : signed int xcount = 0;
3873 : : int ret;
3874 : :
3875 [ - + ]: 2 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3876 [ + - ]: 2 : if (xstats == NULL && n > 0)
3877 : : return -EINVAL;
3878 [ + - ]: 2 : dev = &rte_eth_devices[port_id];
3879 : :
3880 : 2 : count = eth_dev_get_xstats_basic_count(dev);
3881 : :
3882 : : /* implemented by the driver */
3883 [ - + ]: 2 : if (dev->dev_ops->xstats_get != NULL) {
3884 : : /* Retrieve the xstats from the driver at the end of the
3885 : : * xstats struct.
3886 : : */
3887 [ # # # # ]: 0 : xcount = dev->dev_ops->xstats_get(dev,
3888 : 0 : (n > count) ? xstats + count : NULL,
3889 : : (n > count) ? n - count : 0);
3890 : :
3891 [ # # ]: 0 : if (xcount < 0)
3892 : 0 : return eth_err(port_id, xcount);
3893 : : }
3894 : :
3895 [ + + - + ]: 2 : if (n < count + xcount || xstats == NULL)
3896 : 1 : return count + xcount;
3897 : :
3898 : : /* now fill the xstats structure */
3899 : 1 : ret = eth_basic_stats_get(port_id, xstats);
3900 [ + - ]: 1 : if (ret < 0)
3901 : : return ret;
3902 : 1 : count = ret;
3903 : :
3904 [ + + ]: 14 : for (i = 0; i < count; i++)
3905 : 13 : xstats[i].id = i;
3906 : : /* add an offset to driver-specific stats */
3907 [ - + ]: 1 : for ( ; i < count + xcount; i++)
3908 : 0 : xstats[i].id += count;
3909 : :
3910 [ + + ]: 14 : for (i = 0; i < n; i++)
3911 [ - + ]: 13 : rte_eth_trace_xstats_get(port_id, xstats[i]);
3912 : :
3913 : 1 : return count + xcount;
3914 : : }
3915 : :
3916 : : /* reset ethdev extended statistics */
3917 : : RTE_EXPORT_SYMBOL(rte_eth_xstats_reset)
3918 : : int
3919 : 0 : rte_eth_xstats_reset(uint16_t port_id)
3920 : : {
3921 : : struct rte_eth_dev *dev;
3922 : :
3923 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3924 : 0 : dev = &rte_eth_devices[port_id];
3925 : :
3926 : : /* implemented by the driver */
3927 [ # # ]: 0 : if (dev->dev_ops->xstats_reset != NULL) {
3928 : 0 : int ret = eth_err(port_id, dev->dev_ops->xstats_reset(dev));
3929 : :
3930 : 0 : rte_eth_trace_xstats_reset(port_id, ret);
3931 : :
3932 : 0 : return ret;
3933 : : }
3934 : :
3935 : : /* fallback to default */
3936 : 0 : return rte_eth_stats_reset(port_id);
3937 : : }
3938 : :
3939 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_set_counter, 25.03)
3940 : : int
3941 : 0 : rte_eth_xstats_set_counter(uint16_t port_id, uint64_t id, int on_off)
3942 : : {
3943 : : struct rte_eth_dev *dev;
3944 : : unsigned int basic_count;
3945 : :
3946 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3947 : :
3948 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3949 : : basic_count = eth_dev_get_xstats_basic_count(dev);
3950 [ # # ]: 0 : if (id < basic_count)
3951 : : return -EINVAL;
3952 : :
3953 [ # # ]: 0 : if (on_off == 1) {
3954 [ # # ]: 0 : if (rte_eth_xstats_query_state(port_id, id) == 1)
3955 : : return -EEXIST;
3956 [ # # ]: 0 : if (dev->dev_ops->xstats_enable != NULL)
3957 : 0 : return dev->dev_ops->xstats_enable(dev, id - basic_count);
3958 : : } else {
3959 [ # # ]: 0 : if (rte_eth_xstats_query_state(port_id, id) == 0)
3960 : : return 0;
3961 [ # # ]: 0 : if (dev->dev_ops->xstats_disable != NULL)
3962 : 0 : return dev->dev_ops->xstats_disable(dev, id - basic_count);
3963 : : }
3964 : :
3965 : : return -ENOTSUP;
3966 : : }
3967 : :
3968 : :
3969 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_xstats_query_state, 25.03)
3970 : : int
3971 : 0 : rte_eth_xstats_query_state(uint16_t port_id, uint64_t id)
3972 : : {
3973 : : struct rte_eth_dev *dev;
3974 : : unsigned int basic_count;
3975 : :
3976 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3977 : :
3978 [ # # ]: 0 : dev = &rte_eth_devices[port_id];
3979 : : basic_count = eth_dev_get_xstats_basic_count(dev);
3980 [ # # ]: 0 : if (id < basic_count)
3981 : : return -ENOTSUP;
3982 : :
3983 : : /* implemented by the driver */
3984 [ # # ]: 0 : if (dev->dev_ops->xstats_query_state != NULL)
3985 : 0 : return dev->dev_ops->xstats_query_state(dev, id - basic_count);
3986 : :
3987 : : return -ENOTSUP;
3988 : : }
3989 : :
3990 : : static int
3991 : 0 : eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id,
3992 : : uint8_t stat_idx, uint8_t is_rx)
3993 : : {
3994 : : struct rte_eth_dev *dev;
3995 : :
3996 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
3997 : 0 : dev = &rte_eth_devices[port_id];
3998 : :
3999 [ # # # # ]: 0 : if (is_rx && (queue_id >= dev->data->nb_rx_queues))
4000 : : return -EINVAL;
4001 : :
4002 [ # # # # ]: 0 : if (!is_rx && (queue_id >= dev->data->nb_tx_queues))
4003 : : return -EINVAL;
4004 : :
4005 [ # # ]: 0 : if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS)
4006 : : return -EINVAL;
4007 : :
4008 [ # # ]: 0 : if (dev->dev_ops->queue_stats_mapping_set == NULL)
4009 : : return -ENOTSUP;
4010 : 0 : return dev->dev_ops->queue_stats_mapping_set(dev, queue_id, stat_idx, is_rx);
4011 : : }
4012 : :
4013 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_tx_queue_stats_mapping)
4014 : : int
4015 : 0 : rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id,
4016 : : uint8_t stat_idx)
4017 : : {
4018 : : int ret;
4019 : :
4020 : 0 : ret = eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id,
4021 : : tx_queue_id,
4022 : : stat_idx, STAT_QMAP_TX));
4023 : :
4024 : 0 : rte_ethdev_trace_set_tx_queue_stats_mapping(port_id, tx_queue_id,
4025 : : stat_idx, ret);
4026 : :
4027 : 0 : return ret;
4028 : : }
4029 : :
4030 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_rx_queue_stats_mapping)
4031 : : int
4032 : 0 : rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id,
4033 : : uint8_t stat_idx)
4034 : : {
4035 : : int ret;
4036 : :
4037 : 0 : ret = eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id,
4038 : : rx_queue_id,
4039 : : stat_idx, STAT_QMAP_RX));
4040 : :
4041 : 0 : rte_ethdev_trace_set_rx_queue_stats_mapping(port_id, rx_queue_id,
4042 : : stat_idx, ret);
4043 : :
4044 : 0 : return ret;
4045 : : }
4046 : :
4047 : : RTE_EXPORT_SYMBOL(rte_eth_dev_fw_version_get)
4048 : : int
4049 : 1 : rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size)
4050 : : {
4051 : : struct rte_eth_dev *dev;
4052 : : int ret;
4053 : :
4054 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4055 : 1 : dev = &rte_eth_devices[port_id];
4056 : :
4057 [ - + ]: 1 : if (fw_version == NULL && fw_size > 0) {
4058 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4059 : : "Cannot get ethdev port %u FW version to NULL when string size is non zero",
4060 : : port_id);
4061 : 0 : return -EINVAL;
4062 : : }
4063 : :
4064 [ - + ]: 1 : if (dev->dev_ops->fw_version_get == NULL)
4065 : : return -ENOTSUP;
4066 : 0 : ret = eth_err(port_id, dev->dev_ops->fw_version_get(dev, fw_version, fw_size));
4067 : :
4068 : 0 : rte_ethdev_trace_fw_version_get(port_id, fw_version, fw_size, ret);
4069 : :
4070 : 0 : return ret;
4071 : : }
4072 : :
4073 : : RTE_EXPORT_SYMBOL(rte_eth_dev_info_get)
4074 : : int
4075 : 121 : rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info)
4076 : : {
4077 : : struct rte_eth_dev *dev;
4078 : : const struct rte_eth_desc_lim lim = {
4079 : : .nb_max = UINT16_MAX,
4080 : : .nb_min = 0,
4081 : : .nb_align = 1,
4082 : : .nb_seg_max = UINT16_MAX,
4083 : : .nb_mtu_seg_max = UINT16_MAX,
4084 : : };
4085 : : int diag;
4086 : :
4087 [ - + ]: 121 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4088 : 121 : dev = &rte_eth_devices[port_id];
4089 : :
4090 [ - + ]: 121 : if (dev_info == NULL) {
4091 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u info to NULL",
4092 : : port_id);
4093 : 0 : return -EINVAL;
4094 : : }
4095 : :
4096 : : /*
4097 : : * Init dev_info before port_id check since caller does not have
4098 : : * return status and does not know if get is successful or not.
4099 : : */
4100 : : memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
4101 : 121 : dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
4102 : :
4103 : 121 : dev_info->rx_desc_lim = lim;
4104 : 121 : dev_info->tx_desc_lim = lim;
4105 : 121 : dev_info->device = dev->device;
4106 : 121 : dev_info->min_mtu = RTE_ETHER_MIN_LEN - RTE_ETHER_HDR_LEN -
4107 : : RTE_ETHER_CRC_LEN;
4108 : 121 : dev_info->max_mtu = UINT16_MAX;
4109 : 121 : dev_info->rss_algo_capa = RTE_ETH_HASH_ALGO_CAPA_MASK(DEFAULT);
4110 : 121 : dev_info->max_rx_bufsize = UINT32_MAX;
4111 : :
4112 [ + - ]: 121 : if (dev->dev_ops->dev_infos_get == NULL)
4113 : : return -ENOTSUP;
4114 : 121 : diag = dev->dev_ops->dev_infos_get(dev, dev_info);
4115 [ - + ]: 121 : if (diag != 0) {
4116 : : /* Cleanup already filled in device information */
4117 : : memset(dev_info, 0, sizeof(struct rte_eth_dev_info));
4118 : 0 : return eth_err(port_id, diag);
4119 : : }
4120 : :
4121 : : /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */
4122 : 121 : dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues,
4123 : : RTE_MAX_QUEUES_PER_PORT);
4124 : 121 : dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues,
4125 : : RTE_MAX_QUEUES_PER_PORT);
4126 : :
4127 : 121 : dev_info->driver_name = dev->device->driver->name;
4128 : 121 : dev_info->nb_rx_queues = dev->data->nb_rx_queues;
4129 : 121 : dev_info->nb_tx_queues = dev->data->nb_tx_queues;
4130 : :
4131 [ - + ]: 121 : dev_info->dev_flags = &dev->data->dev_flags;
4132 : :
4133 : 121 : rte_ethdev_trace_info_get(port_id, dev_info);
4134 : :
4135 : 121 : return 0;
4136 : : }
4137 : :
4138 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_conf_get, 21.11)
4139 : : int
4140 : 1 : rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf)
4141 : : {
4142 : : struct rte_eth_dev *dev;
4143 : :
4144 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4145 : : dev = &rte_eth_devices[port_id];
4146 : :
4147 [ - + ]: 1 : if (dev_conf == NULL) {
4148 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4149 : : "Cannot get ethdev port %u configuration to NULL",
4150 : : port_id);
4151 : 0 : return -EINVAL;
4152 : : }
4153 : :
4154 [ - + ]: 1 : memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf));
4155 : :
4156 : 1 : rte_ethdev_trace_conf_get(port_id, dev_conf);
4157 : :
4158 : 1 : return 0;
4159 : : }
4160 : :
4161 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_supported_ptypes)
4162 : : int
4163 : 0 : rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
4164 : : uint32_t *ptypes, int num)
4165 : : {
4166 : : size_t i;
4167 : : int j;
4168 : : struct rte_eth_dev *dev;
4169 : : const uint32_t *all_ptypes;
4170 : 0 : size_t no_of_elements = 0;
4171 : :
4172 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4173 : 0 : dev = &rte_eth_devices[port_id];
4174 : :
4175 [ # # ]: 0 : if (ptypes == NULL && num > 0) {
4176 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4177 : : "Cannot get ethdev port %u supported packet types to NULL when array size is non zero",
4178 : : port_id);
4179 : 0 : return -EINVAL;
4180 : : }
4181 : :
4182 [ # # ]: 0 : if (dev->dev_ops->dev_supported_ptypes_get == NULL)
4183 : : return 0;
4184 : 0 : all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
4185 : :
4186 [ # # ]: 0 : if (!all_ptypes)
4187 : : return 0;
4188 : :
4189 [ # # ]: 0 : for (i = 0, j = 0; i < no_of_elements; ++i)
4190 [ # # ]: 0 : if (all_ptypes[i] & ptype_mask) {
4191 [ # # ]: 0 : if (j < num) {
4192 [ # # ]: 0 : ptypes[j] = all_ptypes[i];
4193 : :
4194 : 0 : rte_ethdev_trace_get_supported_ptypes(port_id,
4195 : : j, num, ptypes[j]);
4196 : : }
4197 : 0 : j++;
4198 : : }
4199 : :
4200 : : return j;
4201 : : }
4202 : :
4203 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_ptypes)
4204 : : int
4205 : 0 : rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask,
4206 : : uint32_t *set_ptypes, unsigned int num)
4207 : : {
4208 : 0 : const uint32_t valid_ptype_masks[] = {
4209 : : RTE_PTYPE_L2_MASK,
4210 : : RTE_PTYPE_L3_MASK,
4211 : : RTE_PTYPE_L4_MASK,
4212 : : RTE_PTYPE_TUNNEL_MASK,
4213 : : RTE_PTYPE_INNER_L2_MASK,
4214 : : RTE_PTYPE_INNER_L3_MASK,
4215 : : RTE_PTYPE_INNER_L4_MASK,
4216 : : };
4217 : : const uint32_t *all_ptypes;
4218 : : struct rte_eth_dev *dev;
4219 : : uint32_t unused_mask;
4220 : : size_t i;
4221 : : unsigned int j;
4222 : : int ret;
4223 : 0 : size_t no_of_elements = 0;
4224 : :
4225 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4226 : 0 : dev = &rte_eth_devices[port_id];
4227 : :
4228 [ # # ]: 0 : if (num > 0 && set_ptypes == NULL) {
4229 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4230 : : "Cannot get ethdev port %u set packet types to NULL when array size is non zero",
4231 : : port_id);
4232 : 0 : return -EINVAL;
4233 : : }
4234 : :
4235 [ # # ]: 0 : if (dev->dev_ops->dev_supported_ptypes_get == NULL ||
4236 [ # # ]: 0 : dev->dev_ops->dev_ptypes_set == NULL) {
4237 : : ret = 0;
4238 : 0 : goto ptype_unknown;
4239 : : }
4240 : :
4241 [ # # ]: 0 : if (ptype_mask == 0) {
4242 : 0 : ret = dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
4243 : 0 : goto ptype_unknown;
4244 : : }
4245 : :
4246 : : unused_mask = ptype_mask;
4247 [ # # ]: 0 : for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) {
4248 : 0 : uint32_t mask = ptype_mask & valid_ptype_masks[i];
4249 [ # # # # ]: 0 : if (mask && mask != valid_ptype_masks[i]) {
4250 : : ret = -EINVAL;
4251 : 0 : goto ptype_unknown;
4252 : : }
4253 : 0 : unused_mask &= ~valid_ptype_masks[i];
4254 : : }
4255 : :
4256 [ # # ]: 0 : if (unused_mask) {
4257 : : ret = -EINVAL;
4258 : 0 : goto ptype_unknown;
4259 : : }
4260 : :
4261 : 0 : all_ptypes = dev->dev_ops->dev_supported_ptypes_get(dev, &no_of_elements);
4262 [ # # ]: 0 : if (all_ptypes == NULL) {
4263 : : ret = 0;
4264 : 0 : goto ptype_unknown;
4265 : : }
4266 : :
4267 : : /*
4268 : : * Accommodate as many set_ptypes as possible. If the supplied
4269 : : * set_ptypes array is insufficient fill it partially.
4270 : : */
4271 [ # # ]: 0 : for (i = 0, j = 0; set_ptypes != NULL &&
4272 [ # # ]: 0 : (i < no_of_elements); ++i) {
4273 [ # # ]: 0 : if (ptype_mask & all_ptypes[i]) {
4274 [ # # ]: 0 : if (j < num - 1) {
4275 : 0 : set_ptypes[j] = all_ptypes[i];
4276 : :
4277 [ # # ]: 0 : rte_ethdev_trace_set_ptypes(port_id, j, num,
4278 : : set_ptypes[j]);
4279 : :
4280 : 0 : j++;
4281 : 0 : continue;
4282 : : }
4283 : : break;
4284 : : }
4285 : : }
4286 : :
4287 [ # # ]: 0 : if (set_ptypes != NULL && j < num)
4288 : 0 : set_ptypes[j] = RTE_PTYPE_UNKNOWN;
4289 : :
4290 : 0 : return dev->dev_ops->dev_ptypes_set(dev, ptype_mask);
4291 : :
4292 : 0 : ptype_unknown:
4293 [ # # ]: 0 : if (num > 0)
4294 : 0 : set_ptypes[0] = RTE_PTYPE_UNKNOWN;
4295 : :
4296 : : return ret;
4297 : : }
4298 : :
4299 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_macaddrs_get, 21.11)
4300 : : int
4301 : 0 : rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma,
4302 : : unsigned int num)
4303 : : {
4304 : : int32_t ret;
4305 : : struct rte_eth_dev *dev;
4306 : : struct rte_eth_dev_info dev_info;
4307 : :
4308 [ # # ]: 0 : if (ma == NULL) {
4309 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "%s: invalid parameters", __func__);
4310 : 0 : return -EINVAL;
4311 : : }
4312 : :
4313 : : /* will check for us that port_id is a valid one */
4314 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4315 [ # # ]: 0 : if (ret != 0)
4316 : : return ret;
4317 : :
4318 : : dev = &rte_eth_devices[port_id];
4319 : 0 : num = RTE_MIN(dev_info.max_mac_addrs, num);
4320 [ # # ]: 0 : memcpy(ma, dev->data->mac_addrs, num * sizeof(ma[0]));
4321 : :
4322 : 0 : rte_eth_trace_macaddrs_get(port_id, num);
4323 : :
4324 : 0 : return num;
4325 : : }
4326 : :
4327 : : RTE_EXPORT_SYMBOL(rte_eth_macaddr_get)
4328 : : int
4329 : 6 : rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
4330 : : {
4331 : : struct rte_eth_dev *dev;
4332 : :
4333 [ - + ]: 6 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4334 : : dev = &rte_eth_devices[port_id];
4335 : :
4336 [ - + ]: 6 : if (mac_addr == NULL) {
4337 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4338 : : "Cannot get ethdev port %u MAC address to NULL",
4339 : : port_id);
4340 : 0 : return -EINVAL;
4341 : : }
4342 : :
4343 : 6 : rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
4344 : :
4345 : : rte_eth_trace_macaddr_get(port_id, mac_addr);
4346 : :
4347 : 6 : return 0;
4348 : : }
4349 : :
4350 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_mtu)
4351 : : int
4352 : 0 : rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu)
4353 : : {
4354 : : struct rte_eth_dev *dev;
4355 : :
4356 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4357 : : dev = &rte_eth_devices[port_id];
4358 : :
4359 [ # # ]: 0 : if (mtu == NULL) {
4360 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u MTU to NULL",
4361 : : port_id);
4362 : 0 : return -EINVAL;
4363 : : }
4364 : :
4365 : 0 : *mtu = dev->data->mtu;
4366 : :
4367 : : rte_ethdev_trace_get_mtu(port_id, *mtu);
4368 : :
4369 : 0 : return 0;
4370 : : }
4371 : :
4372 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mtu)
4373 : : int
4374 : 0 : rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
4375 : : {
4376 : : int ret;
4377 : : struct rte_eth_dev_info dev_info;
4378 : : struct rte_eth_dev *dev;
4379 : :
4380 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4381 : 0 : dev = &rte_eth_devices[port_id];
4382 [ # # ]: 0 : if (dev->dev_ops->mtu_set == NULL)
4383 : : return -ENOTSUP;
4384 : :
4385 : : /*
4386 : : * Check if the device supports dev_infos_get, if it does not
4387 : : * skip min_mtu/max_mtu validation here as this requires values
4388 : : * that are populated within the call to rte_eth_dev_info_get()
4389 : : * which relies on dev->dev_ops->dev_infos_get.
4390 : : */
4391 [ # # ]: 0 : if (dev->dev_ops->dev_infos_get != NULL) {
4392 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4393 [ # # ]: 0 : if (ret != 0)
4394 : : return ret;
4395 : :
4396 : 0 : ret = eth_dev_validate_mtu(port_id, &dev_info, mtu);
4397 [ # # ]: 0 : if (ret != 0)
4398 : : return ret;
4399 : : }
4400 : :
4401 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
4402 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4403 : : "Port %u must be configured before MTU set",
4404 : : port_id);
4405 : 0 : return -EINVAL;
4406 : : }
4407 : :
4408 : 0 : ret = dev->dev_ops->mtu_set(dev, mtu);
4409 [ # # ]: 0 : if (ret == 0)
4410 : 0 : dev->data->mtu = mtu;
4411 : :
4412 : 0 : ret = eth_err(port_id, ret);
4413 : :
4414 : 0 : rte_ethdev_trace_set_mtu(port_id, mtu, ret);
4415 : :
4416 : 0 : return ret;
4417 : : }
4418 : :
4419 : : RTE_EXPORT_SYMBOL(rte_eth_dev_vlan_filter)
4420 : : int
4421 : 0 : rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on)
4422 : : {
4423 : : struct rte_eth_dev *dev;
4424 : : int ret;
4425 : :
4426 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4427 : 0 : dev = &rte_eth_devices[port_id];
4428 : :
4429 [ # # ]: 0 : if (!(dev->data->dev_conf.rxmode.offloads &
4430 : : RTE_ETH_RX_OFFLOAD_VLAN_FILTER)) {
4431 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: VLAN-filtering disabled",
4432 : : port_id);
4433 : 0 : return -ENOSYS;
4434 : : }
4435 : :
4436 [ # # ]: 0 : if (vlan_id > 4095) {
4437 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port_id=%u invalid vlan_id=%u > 4095",
4438 : : port_id, vlan_id);
4439 : 0 : return -EINVAL;
4440 : : }
4441 [ # # ]: 0 : if (dev->dev_ops->vlan_filter_set == NULL)
4442 : : return -ENOTSUP;
4443 : :
4444 : 0 : ret = dev->dev_ops->vlan_filter_set(dev, vlan_id, on);
4445 [ # # ]: 0 : if (ret == 0) {
4446 : : struct rte_vlan_filter_conf *vfc;
4447 : : int vidx;
4448 : : int vbit;
4449 : :
4450 : 0 : vfc = &dev->data->vlan_filter_conf;
4451 : 0 : vidx = vlan_id / 64;
4452 : 0 : vbit = vlan_id % 64;
4453 : :
4454 [ # # ]: 0 : if (on)
4455 : 0 : vfc->ids[vidx] |= RTE_BIT64(vbit);
4456 : : else
4457 : 0 : vfc->ids[vidx] &= ~RTE_BIT64(vbit);
4458 : : }
4459 : :
4460 : 0 : ret = eth_err(port_id, ret);
4461 : :
4462 : 0 : rte_ethdev_trace_vlan_filter(port_id, vlan_id, on, ret);
4463 : :
4464 : 0 : return ret;
4465 : : }
4466 : :
4467 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_strip_on_queue)
4468 : : int
4469 : 0 : rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id,
4470 : : int on)
4471 : : {
4472 : : struct rte_eth_dev *dev;
4473 : :
4474 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4475 : 0 : dev = &rte_eth_devices[port_id];
4476 : :
4477 [ # # ]: 0 : if (rx_queue_id >= dev->data->nb_rx_queues) {
4478 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid rx_queue_id=%u", rx_queue_id);
4479 : 0 : return -EINVAL;
4480 : : }
4481 : :
4482 [ # # ]: 0 : if (dev->dev_ops->vlan_strip_queue_set == NULL)
4483 : : return -ENOTSUP;
4484 : 0 : dev->dev_ops->vlan_strip_queue_set(dev, rx_queue_id, on);
4485 : :
4486 : 0 : rte_ethdev_trace_set_vlan_strip_on_queue(port_id, rx_queue_id, on);
4487 : :
4488 : 0 : return 0;
4489 : : }
4490 : :
4491 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_ether_type)
4492 : : int
4493 : 0 : rte_eth_dev_set_vlan_ether_type(uint16_t port_id,
4494 : : enum rte_vlan_type vlan_type,
4495 : : uint16_t tpid)
4496 : : {
4497 : : struct rte_eth_dev *dev;
4498 : : int ret;
4499 : :
4500 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4501 : 0 : dev = &rte_eth_devices[port_id];
4502 : :
4503 [ # # ]: 0 : if (dev->dev_ops->vlan_tpid_set == NULL)
4504 : : return -ENOTSUP;
4505 : 0 : ret = eth_err(port_id, dev->dev_ops->vlan_tpid_set(dev, vlan_type, tpid));
4506 : :
4507 : 0 : rte_ethdev_trace_set_vlan_ether_type(port_id, vlan_type, tpid, ret);
4508 : :
4509 : 0 : return ret;
4510 : : }
4511 : :
4512 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_offload)
4513 : : int
4514 : 0 : rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask)
4515 : : {
4516 : : struct rte_eth_dev_info dev_info;
4517 : : struct rte_eth_dev *dev;
4518 : : int ret = 0;
4519 : : int mask = 0;
4520 : : int cur, org = 0;
4521 : : uint64_t orig_offloads;
4522 : : uint64_t dev_offloads;
4523 : : uint64_t new_offloads;
4524 : :
4525 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4526 : 0 : dev = &rte_eth_devices[port_id];
4527 : :
4528 : : /* save original values in case of failure */
4529 : 0 : orig_offloads = dev->data->dev_conf.rxmode.offloads;
4530 : : dev_offloads = orig_offloads;
4531 : :
4532 : : /* check which option changed by application */
4533 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_STRIP_OFFLOAD);
4534 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP);
4535 [ # # ]: 0 : if (cur != org) {
4536 [ # # ]: 0 : if (cur)
4537 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4538 : : else
4539 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
4540 : : mask |= RTE_ETH_VLAN_STRIP_MASK;
4541 : : }
4542 : :
4543 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_FILTER_OFFLOAD);
4544 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER);
4545 [ # # ]: 0 : if (cur != org) {
4546 [ # # ]: 0 : if (cur)
4547 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4548 : : else
4549 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
4550 : 0 : mask |= RTE_ETH_VLAN_FILTER_MASK;
4551 : : }
4552 : :
4553 : 0 : cur = !!(offload_mask & RTE_ETH_VLAN_EXTEND_OFFLOAD);
4554 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND);
4555 [ # # ]: 0 : if (cur != org) {
4556 [ # # ]: 0 : if (cur)
4557 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4558 : : else
4559 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_VLAN_EXTEND;
4560 : 0 : mask |= RTE_ETH_VLAN_EXTEND_MASK;
4561 : : }
4562 : :
4563 : 0 : cur = !!(offload_mask & RTE_ETH_QINQ_STRIP_OFFLOAD);
4564 : 0 : org = !!(dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP);
4565 [ # # ]: 0 : if (cur != org) {
4566 [ # # ]: 0 : if (cur)
4567 : 0 : dev_offloads |= RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4568 : : else
4569 : 0 : dev_offloads &= ~RTE_ETH_RX_OFFLOAD_QINQ_STRIP;
4570 : 0 : mask |= RTE_ETH_QINQ_STRIP_MASK;
4571 : : }
4572 : :
4573 : : /*no change*/
4574 [ # # ]: 0 : if (mask == 0)
4575 : : return ret;
4576 : :
4577 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4578 [ # # ]: 0 : if (ret != 0)
4579 : : return ret;
4580 : :
4581 : : /* Rx VLAN offloading must be within its device capabilities */
4582 [ # # ]: 0 : if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) {
4583 : 0 : new_offloads = dev_offloads & ~orig_offloads;
4584 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4585 : : "Ethdev port_id=%u requested new added VLAN offloads "
4586 : : "0x%" PRIx64 " must be within Rx offloads capabilities "
4587 : : "0x%" PRIx64 " in %s()",
4588 : : port_id, new_offloads, dev_info.rx_offload_capa,
4589 : : __func__);
4590 : 0 : return -EINVAL;
4591 : : }
4592 : :
4593 [ # # ]: 0 : if (dev->dev_ops->vlan_offload_set == NULL)
4594 : : return -ENOTSUP;
4595 : 0 : dev->data->dev_conf.rxmode.offloads = dev_offloads;
4596 : 0 : ret = dev->dev_ops->vlan_offload_set(dev, mask);
4597 [ # # ]: 0 : if (ret) {
4598 : : /* hit an error restore original values */
4599 : 0 : dev->data->dev_conf.rxmode.offloads = orig_offloads;
4600 : : }
4601 : :
4602 : 0 : ret = eth_err(port_id, ret);
4603 : :
4604 : 0 : rte_ethdev_trace_set_vlan_offload(port_id, offload_mask, ret);
4605 : :
4606 : 0 : return ret;
4607 : : }
4608 : :
4609 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_vlan_offload)
4610 : : int
4611 : 1 : rte_eth_dev_get_vlan_offload(uint16_t port_id)
4612 : : {
4613 : : struct rte_eth_dev *dev;
4614 : : uint64_t *dev_offloads;
4615 : : int ret = 0;
4616 : :
4617 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4618 : : dev = &rte_eth_devices[port_id];
4619 : 1 : dev_offloads = &dev->data->dev_conf.rxmode.offloads;
4620 : :
4621 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP)
4622 : : ret |= RTE_ETH_VLAN_STRIP_OFFLOAD;
4623 : :
4624 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
4625 : 0 : ret |= RTE_ETH_VLAN_FILTER_OFFLOAD;
4626 : :
4627 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_VLAN_EXTEND)
4628 : 0 : ret |= RTE_ETH_VLAN_EXTEND_OFFLOAD;
4629 : :
4630 [ - + ]: 1 : if (*dev_offloads & RTE_ETH_RX_OFFLOAD_QINQ_STRIP)
4631 : 0 : ret |= RTE_ETH_QINQ_STRIP_OFFLOAD;
4632 : :
4633 : 1 : rte_ethdev_trace_get_vlan_offload(port_id, ret);
4634 : :
4635 : 1 : return ret;
4636 : : }
4637 : :
4638 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_vlan_pvid)
4639 : : int
4640 : 0 : rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on)
4641 : : {
4642 : : struct rte_eth_dev *dev;
4643 : : int ret;
4644 : :
4645 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4646 : 0 : dev = &rte_eth_devices[port_id];
4647 : :
4648 [ # # ]: 0 : if (dev->dev_ops->vlan_pvid_set == NULL)
4649 : : return -ENOTSUP;
4650 : 0 : ret = eth_err(port_id, dev->dev_ops->vlan_pvid_set(dev, pvid, on));
4651 : :
4652 : 0 : rte_ethdev_trace_set_vlan_pvid(port_id, pvid, on, ret);
4653 : :
4654 : 0 : return ret;
4655 : : }
4656 : :
4657 : : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_get)
4658 : : int
4659 : 1 : rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
4660 : : {
4661 : : struct rte_eth_dev *dev;
4662 : : int ret;
4663 : :
4664 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4665 : 1 : dev = &rte_eth_devices[port_id];
4666 : :
4667 [ - + ]: 1 : if (fc_conf == NULL) {
4668 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4669 : : "Cannot get ethdev port %u flow control config to NULL",
4670 : : port_id);
4671 : 0 : return -EINVAL;
4672 : : }
4673 : :
4674 [ - + ]: 1 : if (dev->dev_ops->flow_ctrl_get == NULL)
4675 : : return -ENOTSUP;
4676 : : memset(fc_conf, 0, sizeof(*fc_conf));
4677 : 0 : ret = eth_err(port_id, dev->dev_ops->flow_ctrl_get(dev, fc_conf));
4678 : :
4679 : 0 : rte_ethdev_trace_flow_ctrl_get(port_id, fc_conf, ret);
4680 : :
4681 : 0 : return ret;
4682 : : }
4683 : :
4684 : : RTE_EXPORT_SYMBOL(rte_eth_dev_flow_ctrl_set)
4685 : : int
4686 : 0 : rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf)
4687 : : {
4688 : : struct rte_eth_dev *dev;
4689 : : int ret;
4690 : :
4691 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4692 : 0 : dev = &rte_eth_devices[port_id];
4693 : :
4694 [ # # ]: 0 : if (fc_conf == NULL) {
4695 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4696 : : "Cannot set ethdev port %u flow control from NULL config",
4697 : : port_id);
4698 : 0 : return -EINVAL;
4699 : : }
4700 : :
4701 [ # # ]: 0 : if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) {
4702 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid send_xon, only 0/1 allowed");
4703 : 0 : return -EINVAL;
4704 : : }
4705 : :
4706 [ # # ]: 0 : if (dev->dev_ops->flow_ctrl_set == NULL)
4707 : : return -ENOTSUP;
4708 : 0 : ret = eth_err(port_id, dev->dev_ops->flow_ctrl_set(dev, fc_conf));
4709 : :
4710 : 0 : rte_ethdev_trace_flow_ctrl_set(port_id, fc_conf, ret);
4711 : :
4712 : 0 : return ret;
4713 : : }
4714 : :
4715 : : RTE_EXPORT_SYMBOL(rte_eth_dev_priority_flow_ctrl_set)
4716 : : int
4717 : 0 : rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id,
4718 : : struct rte_eth_pfc_conf *pfc_conf)
4719 : : {
4720 : : struct rte_eth_dev *dev;
4721 : : int ret;
4722 : :
4723 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4724 : 0 : dev = &rte_eth_devices[port_id];
4725 : :
4726 [ # # ]: 0 : if (pfc_conf == NULL) {
4727 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4728 : : "Cannot set ethdev port %u priority flow control from NULL config",
4729 : : port_id);
4730 : 0 : return -EINVAL;
4731 : : }
4732 : :
4733 [ # # ]: 0 : if (pfc_conf->priority > (RTE_ETH_DCB_NUM_USER_PRIORITIES - 1)) {
4734 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid priority, only 0-7 allowed");
4735 : 0 : return -EINVAL;
4736 : : }
4737 : :
4738 : : /* High water, low water validation are device specific */
4739 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_set == NULL)
4740 : : return -ENOTSUP;
4741 : 0 : ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_set(dev, pfc_conf));
4742 : :
4743 : 0 : rte_ethdev_trace_priority_flow_ctrl_set(port_id, pfc_conf, ret);
4744 : :
4745 : 0 : return ret;
4746 : : }
4747 : :
4748 : : static int
4749 : 0 : validate_rx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
4750 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4751 : : {
4752 [ # # ]: 0 : if ((pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) ||
4753 : : (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
4754 [ # # ]: 0 : if (pfc_queue_conf->rx_pause.tx_qid >= dev_info->nb_tx_queues) {
4755 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4756 : : "PFC Tx queue not in range for Rx pause requested:%d configured:%d",
4757 : : pfc_queue_conf->rx_pause.tx_qid,
4758 : : dev_info->nb_tx_queues);
4759 : 0 : return -EINVAL;
4760 : : }
4761 : :
4762 [ # # ]: 0 : if (pfc_queue_conf->rx_pause.tc >= tc_max) {
4763 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4764 : : "PFC TC not in range for Rx pause requested:%d max:%d",
4765 : : pfc_queue_conf->rx_pause.tc, tc_max);
4766 : 0 : return -EINVAL;
4767 : : }
4768 : : }
4769 : :
4770 : : return 0;
4771 : : }
4772 : :
4773 : : static int
4774 : 0 : validate_tx_pause_config(struct rte_eth_dev_info *dev_info, uint8_t tc_max,
4775 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4776 : : {
4777 [ # # ]: 0 : if ((pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) ||
4778 : : (pfc_queue_conf->mode == RTE_ETH_FC_FULL)) {
4779 [ # # ]: 0 : if (pfc_queue_conf->tx_pause.rx_qid >= dev_info->nb_rx_queues) {
4780 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4781 : : "PFC Rx queue not in range for Tx pause requested:%d configured:%d",
4782 : : pfc_queue_conf->tx_pause.rx_qid,
4783 : : dev_info->nb_rx_queues);
4784 : 0 : return -EINVAL;
4785 : : }
4786 : :
4787 [ # # ]: 0 : if (pfc_queue_conf->tx_pause.tc >= tc_max) {
4788 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4789 : : "PFC TC not in range for Tx pause requested:%d max:%d",
4790 : : pfc_queue_conf->tx_pause.tc, tc_max);
4791 : 0 : return -EINVAL;
4792 : : }
4793 : : }
4794 : :
4795 : : return 0;
4796 : : }
4797 : :
4798 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_info_get, 22.03)
4799 : : int
4800 : 0 : rte_eth_dev_priority_flow_ctrl_queue_info_get(uint16_t port_id,
4801 : : struct rte_eth_pfc_queue_info *pfc_queue_info)
4802 : : {
4803 : : struct rte_eth_dev *dev;
4804 : : int ret;
4805 : :
4806 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4807 : 0 : dev = &rte_eth_devices[port_id];
4808 : :
4809 [ # # ]: 0 : if (pfc_queue_info == NULL) {
4810 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC info param is NULL for port (%u)",
4811 : : port_id);
4812 : 0 : return -EINVAL;
4813 : : }
4814 : :
4815 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_queue_info_get == NULL)
4816 : : return -ENOTSUP;
4817 : 0 : ret = eth_err(port_id,
4818 : : dev->dev_ops->priority_flow_ctrl_queue_info_get(dev, pfc_queue_info));
4819 : :
4820 : 0 : rte_ethdev_trace_priority_flow_ctrl_queue_info_get(port_id,
4821 : : pfc_queue_info, ret);
4822 : :
4823 : 0 : return ret;
4824 : : }
4825 : :
4826 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priority_flow_ctrl_queue_configure, 22.03)
4827 : : int
4828 : 0 : rte_eth_dev_priority_flow_ctrl_queue_configure(uint16_t port_id,
4829 : : struct rte_eth_pfc_queue_conf *pfc_queue_conf)
4830 : : {
4831 : : struct rte_eth_pfc_queue_info pfc_info;
4832 : : struct rte_eth_dev_info dev_info;
4833 : : struct rte_eth_dev *dev;
4834 : : int ret;
4835 : :
4836 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4837 : 0 : dev = &rte_eth_devices[port_id];
4838 : :
4839 [ # # ]: 0 : if (pfc_queue_conf == NULL) {
4840 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC parameters are NULL for port (%u)",
4841 : : port_id);
4842 : 0 : return -EINVAL;
4843 : : }
4844 : :
4845 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
4846 [ # # ]: 0 : if (ret != 0)
4847 : : return ret;
4848 : :
4849 : 0 : ret = rte_eth_dev_priority_flow_ctrl_queue_info_get(port_id, &pfc_info);
4850 [ # # ]: 0 : if (ret != 0)
4851 : : return ret;
4852 : :
4853 [ # # ]: 0 : if (pfc_info.tc_max == 0) {
4854 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Ethdev port %u does not support PFC TC values",
4855 : : port_id);
4856 : 0 : return -ENOTSUP;
4857 : : }
4858 : :
4859 : : /* Check requested mode supported or not */
4860 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE &&
4861 [ # # ]: 0 : pfc_queue_conf->mode == RTE_ETH_FC_TX_PAUSE) {
4862 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC Tx pause unsupported for port (%d)",
4863 : : port_id);
4864 : 0 : return -EINVAL;
4865 : : }
4866 : :
4867 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE &&
4868 [ # # ]: 0 : pfc_queue_conf->mode == RTE_ETH_FC_RX_PAUSE) {
4869 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "PFC Rx pause unsupported for port (%d)",
4870 : : port_id);
4871 : 0 : return -EINVAL;
4872 : : }
4873 : :
4874 : : /* Validate Rx pause parameters */
4875 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
4876 : : pfc_info.mode_capa == RTE_ETH_FC_RX_PAUSE) {
4877 : 0 : ret = validate_rx_pause_config(&dev_info, pfc_info.tc_max,
4878 : : pfc_queue_conf);
4879 [ # # ]: 0 : if (ret != 0)
4880 : : return ret;
4881 : : }
4882 : :
4883 : : /* Validate Tx pause parameters */
4884 [ # # ]: 0 : if (pfc_info.mode_capa == RTE_ETH_FC_FULL ||
4885 : : pfc_info.mode_capa == RTE_ETH_FC_TX_PAUSE) {
4886 : 0 : ret = validate_tx_pause_config(&dev_info, pfc_info.tc_max,
4887 : : pfc_queue_conf);
4888 [ # # ]: 0 : if (ret != 0)
4889 : : return ret;
4890 : : }
4891 : :
4892 [ # # ]: 0 : if (dev->dev_ops->priority_flow_ctrl_queue_config == NULL)
4893 : : return -ENOTSUP;
4894 : 0 : ret = eth_err(port_id, dev->dev_ops->priority_flow_ctrl_queue_config(dev, pfc_queue_conf));
4895 : :
4896 : 0 : rte_ethdev_trace_priority_flow_ctrl_queue_configure(port_id,
4897 : : pfc_queue_conf, ret);
4898 : :
4899 : 0 : return ret;
4900 : : }
4901 : :
4902 : : static int
4903 : : eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf,
4904 : : uint16_t reta_size)
4905 : : {
4906 : : uint16_t i, num;
4907 : :
4908 : 0 : num = (reta_size + RTE_ETH_RETA_GROUP_SIZE - 1) / RTE_ETH_RETA_GROUP_SIZE;
4909 [ # # # # ]: 0 : for (i = 0; i < num; i++) {
4910 [ # # # # ]: 0 : if (reta_conf[i].mask)
4911 : : return 0;
4912 : : }
4913 : :
4914 : : return -EINVAL;
4915 : : }
4916 : :
4917 : : static int
4918 : 0 : eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf,
4919 : : uint16_t reta_size,
4920 : : uint16_t max_rxq)
4921 : : {
4922 : : uint16_t i, idx, shift;
4923 : :
4924 [ # # ]: 0 : if (max_rxq == 0) {
4925 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "No receive queue is available");
4926 : 0 : return -EINVAL;
4927 : : }
4928 : :
4929 [ # # ]: 0 : for (i = 0; i < reta_size; i++) {
4930 : 0 : idx = i / RTE_ETH_RETA_GROUP_SIZE;
4931 : 0 : shift = i % RTE_ETH_RETA_GROUP_SIZE;
4932 [ # # ]: 0 : if ((reta_conf[idx].mask & RTE_BIT64(shift)) &&
4933 [ # # ]: 0 : (reta_conf[idx].reta[shift] >= max_rxq)) {
4934 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4935 : : "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u",
4936 : : idx, shift,
4937 : : reta_conf[idx].reta[shift], max_rxq);
4938 : 0 : return -EINVAL;
4939 : : }
4940 : : }
4941 : :
4942 : : return 0;
4943 : : }
4944 : :
4945 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_update)
4946 : : int
4947 : 0 : rte_eth_dev_rss_reta_update(uint16_t port_id,
4948 : : struct rte_eth_rss_reta_entry64 *reta_conf,
4949 : : uint16_t reta_size)
4950 : : {
4951 : : enum rte_eth_rx_mq_mode mq_mode;
4952 : : struct rte_eth_dev *dev;
4953 : : int ret;
4954 : :
4955 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
4956 : 0 : dev = &rte_eth_devices[port_id];
4957 : :
4958 [ # # ]: 0 : if (reta_conf == NULL) {
4959 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4960 : : "Cannot update ethdev port %u RSS RETA to NULL",
4961 : : port_id);
4962 : 0 : return -EINVAL;
4963 : : }
4964 : :
4965 [ # # ]: 0 : if (reta_size == 0) {
4966 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
4967 : : "Cannot update ethdev port %u RSS RETA with zero size",
4968 : : port_id);
4969 : 0 : return -EINVAL;
4970 : : }
4971 : :
4972 : : /* Check mask bits */
4973 : 0 : ret = eth_check_reta_mask(reta_conf, reta_size);
4974 [ # # ]: 0 : if (ret < 0)
4975 : : return ret;
4976 : :
4977 : : /* Check entry value */
4978 : 0 : ret = eth_check_reta_entry(reta_conf, reta_size,
4979 : 0 : dev->data->nb_rx_queues);
4980 [ # # ]: 0 : if (ret < 0)
4981 : : return ret;
4982 : :
4983 : 0 : mq_mode = dev->data->dev_conf.rxmode.mq_mode;
4984 [ # # ]: 0 : if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
4985 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
4986 : 0 : return -ENOTSUP;
4987 : : }
4988 : :
4989 [ # # ]: 0 : if (dev->dev_ops->reta_update == NULL)
4990 : : return -ENOTSUP;
4991 : 0 : ret = eth_err(port_id, dev->dev_ops->reta_update(dev, reta_conf, reta_size));
4992 : :
4993 : 0 : rte_ethdev_trace_rss_reta_update(port_id, reta_conf, reta_size, ret);
4994 : :
4995 : 0 : return ret;
4996 : : }
4997 : :
4998 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_reta_query)
4999 : : int
5000 : 0 : rte_eth_dev_rss_reta_query(uint16_t port_id,
5001 : : struct rte_eth_rss_reta_entry64 *reta_conf,
5002 : : uint16_t reta_size)
5003 : : {
5004 : : struct rte_eth_dev *dev;
5005 : : int ret;
5006 : :
5007 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5008 : 0 : dev = &rte_eth_devices[port_id];
5009 : :
5010 [ # # ]: 0 : if (reta_conf == NULL) {
5011 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5012 : : "Cannot query ethdev port %u RSS RETA from NULL config",
5013 : : port_id);
5014 : 0 : return -EINVAL;
5015 : : }
5016 : :
5017 : : /* Check mask bits */
5018 : 0 : ret = eth_check_reta_mask(reta_conf, reta_size);
5019 [ # # ]: 0 : if (ret < 0)
5020 : : return ret;
5021 : :
5022 [ # # ]: 0 : if (dev->dev_ops->reta_query == NULL)
5023 : : return -ENOTSUP;
5024 : 0 : ret = eth_err(port_id, dev->dev_ops->reta_query(dev, reta_conf, reta_size));
5025 : :
5026 : 0 : rte_ethdev_trace_rss_reta_query(port_id, reta_conf, reta_size, ret);
5027 : :
5028 : 0 : return ret;
5029 : : }
5030 : :
5031 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_update)
5032 : : int
5033 : 0 : rte_eth_dev_rss_hash_update(uint16_t port_id,
5034 : : struct rte_eth_rss_conf *rss_conf)
5035 : : {
5036 : : struct rte_eth_dev *dev;
5037 : 0 : struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, };
5038 : : enum rte_eth_rx_mq_mode mq_mode;
5039 : : int ret;
5040 : :
5041 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5042 : 0 : dev = &rte_eth_devices[port_id];
5043 : :
5044 [ # # ]: 0 : if (rss_conf == NULL) {
5045 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5046 : : "Cannot update ethdev port %u RSS hash from NULL config",
5047 : : port_id);
5048 : 0 : return -EINVAL;
5049 : : }
5050 : :
5051 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5052 [ # # ]: 0 : if (ret != 0)
5053 : : return ret;
5054 : :
5055 [ # # ]: 0 : rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf);
5056 [ # # ]: 0 : if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) !=
5057 : : dev_info.flow_type_rss_offloads) {
5058 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5059 : : "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64,
5060 : : port_id, rss_conf->rss_hf,
5061 : : dev_info.flow_type_rss_offloads);
5062 : 0 : return -EINVAL;
5063 : : }
5064 : :
5065 : 0 : mq_mode = dev->data->dev_conf.rxmode.mq_mode;
5066 [ # # ]: 0 : if (!(mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)) {
5067 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Multi-queue RSS mode isn't enabled.");
5068 : 0 : return -ENOTSUP;
5069 : : }
5070 : :
5071 [ # # ]: 0 : if (rss_conf->rss_key != NULL &&
5072 [ # # ]: 0 : rss_conf->rss_key_len != dev_info.hash_key_size) {
5073 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5074 : : "Ethdev port_id=%u invalid RSS key len: %u, valid value: %u",
5075 : : port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
5076 : 0 : return -EINVAL;
5077 : : }
5078 : :
5079 [ # # ]: 0 : if ((size_t)rss_conf->algorithm >= CHAR_BIT * sizeof(dev_info.rss_algo_capa) ||
5080 : 0 : (dev_info.rss_algo_capa &
5081 [ # # ]: 0 : RTE_ETH_HASH_ALGO_TO_CAPA(rss_conf->algorithm)) == 0) {
5082 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5083 : : "Ethdev port_id=%u configured RSS hash algorithm (%u)"
5084 : : "is not in the algorithm capability (0x%" PRIx32 ")",
5085 : : port_id, rss_conf->algorithm, dev_info.rss_algo_capa);
5086 : 0 : return -EINVAL;
5087 : : }
5088 : :
5089 [ # # ]: 0 : if (dev->dev_ops->rss_hash_update == NULL)
5090 : : return -ENOTSUP;
5091 : 0 : ret = eth_err(port_id, dev->dev_ops->rss_hash_update(dev, rss_conf));
5092 : :
5093 : 0 : rte_ethdev_trace_rss_hash_update(port_id, rss_conf, ret);
5094 : :
5095 : 0 : return ret;
5096 : : }
5097 : :
5098 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rss_hash_conf_get)
5099 : : int
5100 : 1 : rte_eth_dev_rss_hash_conf_get(uint16_t port_id,
5101 : : struct rte_eth_rss_conf *rss_conf)
5102 : : {
5103 : 1 : struct rte_eth_dev_info dev_info = { 0 };
5104 : : struct rte_eth_dev *dev;
5105 : : int ret;
5106 : :
5107 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5108 : 1 : dev = &rte_eth_devices[port_id];
5109 : :
5110 [ - + ]: 1 : if (rss_conf == NULL) {
5111 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5112 : : "Cannot get ethdev port %u RSS hash config to NULL",
5113 : : port_id);
5114 : 0 : return -EINVAL;
5115 : : }
5116 : :
5117 : 1 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5118 [ + - ]: 1 : if (ret != 0)
5119 : : return ret;
5120 : :
5121 [ + - ]: 1 : if (rss_conf->rss_key != NULL &&
5122 [ - + ]: 1 : rss_conf->rss_key_len < dev_info.hash_key_size) {
5123 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5124 : : "Ethdev port_id=%u invalid RSS key len: %u, should not be less than: %u",
5125 : : port_id, rss_conf->rss_key_len, dev_info.hash_key_size);
5126 : 0 : return -EINVAL;
5127 : : }
5128 : :
5129 : 1 : rss_conf->algorithm = RTE_ETH_HASH_FUNCTION_DEFAULT;
5130 : :
5131 [ + - ]: 1 : if (dev->dev_ops->rss_hash_conf_get == NULL)
5132 : : return -ENOTSUP;
5133 : 1 : ret = eth_err(port_id, dev->dev_ops->rss_hash_conf_get(dev, rss_conf));
5134 : :
5135 : 1 : rte_ethdev_trace_rss_hash_conf_get(port_id, rss_conf, ret);
5136 : :
5137 : 1 : return ret;
5138 : : }
5139 : :
5140 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_rss_algo_name, 23.11)
5141 : : const char *
5142 : 0 : rte_eth_dev_rss_algo_name(enum rte_eth_hash_function rss_algo)
5143 : : {
5144 : : const char *name = "Unknown function";
5145 : : unsigned int i;
5146 : :
5147 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
5148 [ # # ]: 0 : if (rss_algo == rte_eth_dev_rss_algo_names[i].algo)
5149 : 0 : return rte_eth_dev_rss_algo_names[i].name;
5150 : : }
5151 : :
5152 : : return name;
5153 : : }
5154 : :
5155 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_find_rss_algo, 24.03)
5156 : : int
5157 : 0 : rte_eth_find_rss_algo(const char *name, uint32_t *algo)
5158 : : {
5159 : : unsigned int i;
5160 : :
5161 [ # # ]: 0 : for (i = 0; i < RTE_DIM(rte_eth_dev_rss_algo_names); i++) {
5162 [ # # ]: 0 : if (strcmp(name, rte_eth_dev_rss_algo_names[i].name) == 0) {
5163 : 0 : *algo = rte_eth_dev_rss_algo_names[i].algo;
5164 : 0 : return 0;
5165 : : }
5166 : : }
5167 : :
5168 : : return -EINVAL;
5169 : : }
5170 : :
5171 : : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_add)
5172 : : int
5173 : 0 : rte_eth_dev_udp_tunnel_port_add(uint16_t port_id,
5174 : : struct rte_eth_udp_tunnel *udp_tunnel)
5175 : : {
5176 : : struct rte_eth_dev *dev;
5177 : : int ret;
5178 : :
5179 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5180 : 0 : dev = &rte_eth_devices[port_id];
5181 : :
5182 [ # # ]: 0 : if (udp_tunnel == NULL) {
5183 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5184 : : "Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel",
5185 : : port_id);
5186 : 0 : return -EINVAL;
5187 : : }
5188 : :
5189 [ # # ]: 0 : if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
5190 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
5191 : 0 : return -EINVAL;
5192 : : }
5193 : :
5194 [ # # ]: 0 : if (dev->dev_ops->udp_tunnel_port_add == NULL)
5195 : : return -ENOTSUP;
5196 : 0 : ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_add(dev, udp_tunnel));
5197 : :
5198 : 0 : rte_ethdev_trace_udp_tunnel_port_add(port_id, udp_tunnel, ret);
5199 : :
5200 : 0 : return ret;
5201 : : }
5202 : :
5203 : : RTE_EXPORT_SYMBOL(rte_eth_dev_udp_tunnel_port_delete)
5204 : : int
5205 : 0 : rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id,
5206 : : struct rte_eth_udp_tunnel *udp_tunnel)
5207 : : {
5208 : : struct rte_eth_dev *dev;
5209 : : int ret;
5210 : :
5211 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5212 : 0 : dev = &rte_eth_devices[port_id];
5213 : :
5214 [ # # ]: 0 : if (udp_tunnel == NULL) {
5215 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5216 : : "Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel",
5217 : : port_id);
5218 : 0 : return -EINVAL;
5219 : : }
5220 : :
5221 [ # # ]: 0 : if (udp_tunnel->prot_type >= RTE_ETH_TUNNEL_TYPE_MAX) {
5222 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid tunnel type");
5223 : 0 : return -EINVAL;
5224 : : }
5225 : :
5226 [ # # ]: 0 : if (dev->dev_ops->udp_tunnel_port_del == NULL)
5227 : : return -ENOTSUP;
5228 : 0 : ret = eth_err(port_id, dev->dev_ops->udp_tunnel_port_del(dev, udp_tunnel));
5229 : :
5230 : 0 : rte_ethdev_trace_udp_tunnel_port_delete(port_id, udp_tunnel, ret);
5231 : :
5232 : 0 : return ret;
5233 : : }
5234 : :
5235 : : RTE_EXPORT_SYMBOL(rte_eth_led_on)
5236 : : int
5237 : 0 : rte_eth_led_on(uint16_t port_id)
5238 : : {
5239 : : struct rte_eth_dev *dev;
5240 : : int ret;
5241 : :
5242 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5243 : 0 : dev = &rte_eth_devices[port_id];
5244 : :
5245 [ # # ]: 0 : if (dev->dev_ops->dev_led_on == NULL)
5246 : : return -ENOTSUP;
5247 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_led_on(dev));
5248 : :
5249 : 0 : rte_eth_trace_led_on(port_id, ret);
5250 : :
5251 : 0 : return ret;
5252 : : }
5253 : :
5254 : : RTE_EXPORT_SYMBOL(rte_eth_led_off)
5255 : : int
5256 : 0 : rte_eth_led_off(uint16_t port_id)
5257 : : {
5258 : : struct rte_eth_dev *dev;
5259 : : int ret;
5260 : :
5261 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5262 : 0 : dev = &rte_eth_devices[port_id];
5263 : :
5264 [ # # ]: 0 : if (dev->dev_ops->dev_led_off == NULL)
5265 : : return -ENOTSUP;
5266 : 0 : ret = eth_err(port_id, dev->dev_ops->dev_led_off(dev));
5267 : :
5268 : 0 : rte_eth_trace_led_off(port_id, ret);
5269 : :
5270 : 0 : return ret;
5271 : : }
5272 : :
5273 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_get_capability, 20.11)
5274 : : int
5275 : 0 : rte_eth_fec_get_capability(uint16_t port_id,
5276 : : struct rte_eth_fec_capa *speed_fec_capa,
5277 : : unsigned int num)
5278 : : {
5279 : : struct rte_eth_dev *dev;
5280 : : int ret;
5281 : :
5282 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5283 : 0 : dev = &rte_eth_devices[port_id];
5284 : :
5285 [ # # ]: 0 : if (speed_fec_capa == NULL && num > 0) {
5286 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5287 : : "Cannot get ethdev port %u FEC capability to NULL when array size is non zero",
5288 : : port_id);
5289 : 0 : return -EINVAL;
5290 : : }
5291 : :
5292 [ # # ]: 0 : if (dev->dev_ops->fec_get_capability == NULL)
5293 : : return -ENOTSUP;
5294 : 0 : ret = dev->dev_ops->fec_get_capability(dev, speed_fec_capa, num);
5295 : :
5296 : 0 : rte_eth_trace_fec_get_capability(port_id, speed_fec_capa, num, ret);
5297 : :
5298 : 0 : return ret;
5299 : : }
5300 : :
5301 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_get, 20.11)
5302 : : int
5303 : 1 : rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa)
5304 : : {
5305 : : struct rte_eth_dev *dev;
5306 : : int ret;
5307 : :
5308 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5309 : 1 : dev = &rte_eth_devices[port_id];
5310 : :
5311 [ - + ]: 1 : if (fec_capa == NULL) {
5312 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5313 : : "Cannot get ethdev port %u current FEC mode to NULL",
5314 : : port_id);
5315 : 0 : return -EINVAL;
5316 : : }
5317 : :
5318 [ - + ]: 1 : if (dev->dev_ops->fec_get == NULL)
5319 : : return -ENOTSUP;
5320 : 0 : ret = eth_err(port_id, dev->dev_ops->fec_get(dev, fec_capa));
5321 : :
5322 : 0 : rte_eth_trace_fec_get(port_id, fec_capa, ret);
5323 : :
5324 : 0 : return ret;
5325 : : }
5326 : :
5327 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_fec_set, 20.11)
5328 : : int
5329 : 0 : rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa)
5330 : : {
5331 : : struct rte_eth_dev *dev;
5332 : : int ret;
5333 : :
5334 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5335 : 0 : dev = &rte_eth_devices[port_id];
5336 : :
5337 [ # # ]: 0 : if (fec_capa == 0) {
5338 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "At least one FEC mode should be specified");
5339 : 0 : return -EINVAL;
5340 : : }
5341 : :
5342 [ # # ]: 0 : if (dev->dev_ops->fec_set == NULL)
5343 : : return -ENOTSUP;
5344 : 0 : ret = eth_err(port_id, dev->dev_ops->fec_set(dev, fec_capa));
5345 : :
5346 : 0 : rte_eth_trace_fec_set(port_id, fec_capa, ret);
5347 : :
5348 : 0 : return ret;
5349 : : }
5350 : :
5351 : : /*
5352 : : * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
5353 : : * an empty spot.
5354 : : */
5355 : : static int
5356 : 0 : eth_dev_get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr)
5357 : : {
5358 : : struct rte_eth_dev_info dev_info;
5359 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
5360 : : unsigned i;
5361 : : int ret;
5362 : :
5363 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5364 [ # # ]: 0 : if (ret != 0)
5365 : : return -1;
5366 : :
5367 [ # # ]: 0 : for (i = 0; i < dev_info.max_mac_addrs; i++)
5368 [ # # ]: 0 : if (memcmp(addr, &dev->data->mac_addrs[i],
5369 : : RTE_ETHER_ADDR_LEN) == 0)
5370 : 0 : return i;
5371 : :
5372 : : return -1;
5373 : : }
5374 : :
5375 : : static const struct rte_ether_addr null_mac_addr;
5376 : :
5377 : : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_add)
5378 : : int
5379 : 0 : rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr,
5380 : : uint32_t pool)
5381 : : {
5382 : : struct rte_eth_dev *dev;
5383 : : int index;
5384 : : uint64_t pool_mask;
5385 : : int ret;
5386 : :
5387 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5388 : 0 : dev = &rte_eth_devices[port_id];
5389 : :
5390 [ # # ]: 0 : if (addr == NULL) {
5391 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5392 : : "Cannot add ethdev port %u MAC address from NULL address",
5393 : : port_id);
5394 : 0 : return -EINVAL;
5395 : : }
5396 : :
5397 [ # # ]: 0 : if (dev->dev_ops->mac_addr_add == NULL)
5398 : : return -ENOTSUP;
5399 : :
5400 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr)) {
5401 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
5402 : : port_id);
5403 : 0 : return -EINVAL;
5404 : : }
5405 [ # # ]: 0 : if (pool >= RTE_ETH_64_POOLS) {
5406 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Pool ID must be 0-%d", RTE_ETH_64_POOLS - 1);
5407 : 0 : return -EINVAL;
5408 : : }
5409 : :
5410 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5411 [ # # ]: 0 : if (index < 0) {
5412 : 0 : index = eth_dev_get_mac_addr_index(port_id, &null_mac_addr);
5413 [ # # ]: 0 : if (index < 0) {
5414 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
5415 : : port_id);
5416 : 0 : return -ENOSPC;
5417 : : }
5418 : : } else {
5419 : 0 : pool_mask = dev->data->mac_pool_sel[index];
5420 : :
5421 : : /* Check if both MAC address and pool is already there, and do nothing */
5422 [ # # ]: 0 : if (pool_mask & RTE_BIT64(pool))
5423 : : return 0;
5424 : : }
5425 : :
5426 : : /* Update NIC */
5427 : 0 : ret = dev->dev_ops->mac_addr_add(dev, addr, index, pool);
5428 : :
5429 [ # # ]: 0 : if (ret == 0) {
5430 : : /* Update address in NIC data structure */
5431 : 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]);
5432 : :
5433 : : /* Update pool bitmap in NIC data structure */
5434 : 0 : dev->data->mac_pool_sel[index] |= RTE_BIT64(pool);
5435 : : }
5436 : :
5437 : 0 : ret = eth_err(port_id, ret);
5438 : :
5439 : 0 : rte_ethdev_trace_mac_addr_add(port_id, addr, pool, ret);
5440 : :
5441 : 0 : return ret;
5442 : : }
5443 : :
5444 : : RTE_EXPORT_SYMBOL(rte_eth_dev_mac_addr_remove)
5445 : : int
5446 : 0 : rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr)
5447 : : {
5448 : : struct rte_eth_dev *dev;
5449 : : int index;
5450 : :
5451 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5452 : 0 : dev = &rte_eth_devices[port_id];
5453 : :
5454 [ # # ]: 0 : if (addr == NULL) {
5455 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5456 : : "Cannot remove ethdev port %u MAC address from NULL address",
5457 : : port_id);
5458 : 0 : return -EINVAL;
5459 : : }
5460 : :
5461 [ # # ]: 0 : if (dev->dev_ops->mac_addr_remove == NULL)
5462 : : return -ENOTSUP;
5463 : :
5464 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5465 [ # # ]: 0 : if (index == 0) {
5466 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5467 : : "Port %u: Cannot remove default MAC address",
5468 : : port_id);
5469 : 0 : return -EADDRINUSE;
5470 [ # # ]: 0 : } else if (index < 0)
5471 : : return 0; /* Do nothing if address wasn't found */
5472 : :
5473 : : /* Update NIC */
5474 : 0 : dev->dev_ops->mac_addr_remove(dev, index);
5475 : :
5476 : : /* Update address in NIC data structure */
5477 [ # # ]: 0 : rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]);
5478 : :
5479 : : /* reset pool bitmap */
5480 [ # # ]: 0 : dev->data->mac_pool_sel[index] = 0;
5481 : :
5482 : 0 : rte_ethdev_trace_mac_addr_remove(port_id, addr);
5483 : :
5484 : 0 : return 0;
5485 : : }
5486 : :
5487 : : RTE_EXPORT_SYMBOL(rte_eth_dev_default_mac_addr_set)
5488 : : int
5489 : 0 : rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr)
5490 : : {
5491 : : struct rte_eth_dev *dev;
5492 : : int index;
5493 : : int ret;
5494 : :
5495 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5496 : 0 : dev = &rte_eth_devices[port_id];
5497 : :
5498 [ # # ]: 0 : if (addr == NULL) {
5499 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5500 : : "Cannot set ethdev port %u default MAC address from NULL address",
5501 : : port_id);
5502 : 0 : return -EINVAL;
5503 : : }
5504 : :
5505 : : if (!rte_is_valid_assigned_ether_addr(addr))
5506 : : return -EINVAL;
5507 : :
5508 [ # # ]: 0 : if (dev->dev_ops->mac_addr_set == NULL)
5509 : : return -ENOTSUP;
5510 : :
5511 : : /* Keep address unique in dev->data->mac_addrs[]. */
5512 : 0 : index = eth_dev_get_mac_addr_index(port_id, addr);
5513 [ # # ]: 0 : if (index > 0) {
5514 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5515 : : "New default address for port %u was already in the address list. Please remove it first.",
5516 : : port_id);
5517 : 0 : return -EEXIST;
5518 : : }
5519 : :
5520 : 0 : ret = dev->dev_ops->mac_addr_set(dev, addr);
5521 [ # # ]: 0 : if (ret < 0)
5522 : : return ret;
5523 : :
5524 : : /* Update default address in NIC data structure */
5525 [ # # ]: 0 : rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]);
5526 : :
5527 : 0 : rte_ethdev_trace_default_mac_addr_set(port_id, addr);
5528 : :
5529 : 0 : return 0;
5530 : : }
5531 : :
5532 : :
5533 : : /*
5534 : : * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find
5535 : : * an empty spot.
5536 : : */
5537 : : static int
5538 : 0 : eth_dev_get_hash_mac_addr_index(uint16_t port_id,
5539 : : const struct rte_ether_addr *addr)
5540 : : {
5541 : : struct rte_eth_dev_info dev_info;
5542 : 0 : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
5543 : : unsigned i;
5544 : : int ret;
5545 : :
5546 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5547 [ # # ]: 0 : if (ret != 0)
5548 : : return -1;
5549 : :
5550 [ # # ]: 0 : if (!dev->data->hash_mac_addrs)
5551 : : return -1;
5552 : :
5553 [ # # ]: 0 : for (i = 0; i < dev_info.max_hash_mac_addrs; i++)
5554 [ # # ]: 0 : if (memcmp(addr, &dev->data->hash_mac_addrs[i],
5555 : : RTE_ETHER_ADDR_LEN) == 0)
5556 : 0 : return i;
5557 : :
5558 : : return -1;
5559 : : }
5560 : :
5561 : : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_hash_table_set)
5562 : : int
5563 : 0 : rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr,
5564 : : uint8_t on)
5565 : : {
5566 : : int index;
5567 : : int ret;
5568 : : struct rte_eth_dev *dev;
5569 : :
5570 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5571 : 0 : dev = &rte_eth_devices[port_id];
5572 : :
5573 [ # # ]: 0 : if (addr == NULL) {
5574 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5575 : : "Cannot set ethdev port %u unicast hash table from NULL address",
5576 : : port_id);
5577 : 0 : return -EINVAL;
5578 : : }
5579 : :
5580 [ # # ]: 0 : if (rte_is_zero_ether_addr(addr)) {
5581 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: Cannot add NULL MAC address",
5582 : : port_id);
5583 : 0 : return -EINVAL;
5584 : : }
5585 : :
5586 : 0 : index = eth_dev_get_hash_mac_addr_index(port_id, addr);
5587 : : /* Check if it's already there, and do nothing */
5588 [ # # ]: 0 : if ((index >= 0) && on)
5589 : : return 0;
5590 : :
5591 [ # # ]: 0 : if (index < 0) {
5592 [ # # ]: 0 : if (!on) {
5593 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5594 : : "Port %u: the MAC address was not set in UTA",
5595 : : port_id);
5596 : 0 : return -EINVAL;
5597 : : }
5598 : :
5599 : 0 : index = eth_dev_get_hash_mac_addr_index(port_id, &null_mac_addr);
5600 [ # # ]: 0 : if (index < 0) {
5601 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Port %u: MAC address array full",
5602 : : port_id);
5603 : 0 : return -ENOSPC;
5604 : : }
5605 : : }
5606 : :
5607 [ # # ]: 0 : if (dev->dev_ops->uc_hash_table_set == NULL)
5608 : : return -ENOTSUP;
5609 : 0 : ret = dev->dev_ops->uc_hash_table_set(dev, addr, on);
5610 [ # # ]: 0 : if (ret == 0) {
5611 : : /* Update address in NIC data structure */
5612 [ # # ]: 0 : if (on)
5613 : 0 : rte_ether_addr_copy(addr,
5614 : 0 : &dev->data->hash_mac_addrs[index]);
5615 : : else
5616 : 0 : rte_ether_addr_copy(&null_mac_addr,
5617 : 0 : &dev->data->hash_mac_addrs[index]);
5618 : : }
5619 : :
5620 : 0 : ret = eth_err(port_id, ret);
5621 : :
5622 : 0 : rte_ethdev_trace_uc_hash_table_set(port_id, on, ret);
5623 : :
5624 : 0 : return ret;
5625 : : }
5626 : :
5627 : : RTE_EXPORT_SYMBOL(rte_eth_dev_uc_all_hash_table_set)
5628 : : int
5629 : 0 : rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on)
5630 : : {
5631 : : struct rte_eth_dev *dev;
5632 : : int ret;
5633 : :
5634 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5635 : 0 : dev = &rte_eth_devices[port_id];
5636 : :
5637 [ # # ]: 0 : if (dev->dev_ops->uc_all_hash_table_set == NULL)
5638 : : return -ENOTSUP;
5639 : 0 : ret = eth_err(port_id, dev->dev_ops->uc_all_hash_table_set(dev, on));
5640 : :
5641 : 0 : rte_ethdev_trace_uc_all_hash_table_set(port_id, on, ret);
5642 : :
5643 : 0 : return ret;
5644 : : }
5645 : :
5646 : : RTE_EXPORT_SYMBOL(rte_eth_set_queue_rate_limit)
5647 : 0 : int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx,
5648 : : uint32_t tx_rate)
5649 : : {
5650 : : struct rte_eth_dev *dev;
5651 : : struct rte_eth_dev_info dev_info;
5652 : : struct rte_eth_link link;
5653 : : int ret;
5654 : :
5655 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5656 : 0 : dev = &rte_eth_devices[port_id];
5657 : :
5658 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
5659 [ # # ]: 0 : if (ret != 0)
5660 : : return ret;
5661 : :
5662 : 0 : link = dev->data->dev_link;
5663 : :
5664 [ # # ]: 0 : if (queue_idx > dev_info.max_tx_queues) {
5665 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5666 : : "Set queue rate limit:port %u: invalid queue ID=%u",
5667 : : port_id, queue_idx);
5668 : 0 : return -EINVAL;
5669 : : }
5670 : :
5671 [ # # ]: 0 : if (tx_rate > link.link_speed) {
5672 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5673 : : "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d",
5674 : : tx_rate, link.link_speed);
5675 : 0 : return -EINVAL;
5676 : : }
5677 : :
5678 [ # # ]: 0 : if (dev->dev_ops->set_queue_rate_limit == NULL)
5679 : : return -ENOTSUP;
5680 : 0 : ret = eth_err(port_id, dev->dev_ops->set_queue_rate_limit(dev, queue_idx, tx_rate));
5681 : :
5682 [ # # ]: 0 : rte_eth_trace_set_queue_rate_limit(port_id, queue_idx, tx_rate, ret);
5683 : :
5684 : 0 : return ret;
5685 : : }
5686 : :
5687 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_avail_thresh_set, 22.07)
5688 : 0 : int rte_eth_rx_avail_thresh_set(uint16_t port_id, uint16_t queue_id,
5689 : : uint8_t avail_thresh)
5690 : : {
5691 : : struct rte_eth_dev *dev;
5692 : : int ret;
5693 : :
5694 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5695 : 0 : dev = &rte_eth_devices[port_id];
5696 : :
5697 [ # # ]: 0 : if (queue_id > dev->data->nb_rx_queues) {
5698 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5699 : : "Set queue avail thresh: port %u: invalid queue ID=%u.",
5700 : : port_id, queue_id);
5701 : 0 : return -EINVAL;
5702 : : }
5703 : :
5704 [ # # ]: 0 : if (avail_thresh > 99) {
5705 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5706 : : "Set queue avail thresh: port %u: threshold should be <= 99.",
5707 : : port_id);
5708 : 0 : return -EINVAL;
5709 : : }
5710 [ # # ]: 0 : if (dev->dev_ops->rx_queue_avail_thresh_set == NULL)
5711 : : return -ENOTSUP;
5712 : 0 : ret = eth_err(port_id,
5713 : : dev->dev_ops->rx_queue_avail_thresh_set(dev, queue_id, avail_thresh));
5714 : :
5715 : 0 : rte_eth_trace_rx_avail_thresh_set(port_id, queue_id, avail_thresh, ret);
5716 : :
5717 : 0 : return ret;
5718 : : }
5719 : :
5720 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_avail_thresh_query, 22.07)
5721 : 0 : int rte_eth_rx_avail_thresh_query(uint16_t port_id, uint16_t *queue_id,
5722 : : uint8_t *avail_thresh)
5723 : : {
5724 : : struct rte_eth_dev *dev;
5725 : : int ret;
5726 : :
5727 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5728 : 0 : dev = &rte_eth_devices[port_id];
5729 : :
5730 [ # # ]: 0 : if (queue_id == NULL)
5731 : : return -EINVAL;
5732 [ # # ]: 0 : if (*queue_id >= dev->data->nb_rx_queues)
5733 : 0 : *queue_id = 0;
5734 : :
5735 [ # # ]: 0 : if (dev->dev_ops->rx_queue_avail_thresh_query == NULL)
5736 : : return -ENOTSUP;
5737 : 0 : ret = eth_err(port_id,
5738 : : dev->dev_ops->rx_queue_avail_thresh_query(dev, queue_id, avail_thresh));
5739 : :
5740 [ # # ]: 0 : rte_eth_trace_rx_avail_thresh_query(port_id, *queue_id, ret);
5741 : :
5742 : 0 : return ret;
5743 : : }
5744 : :
5745 : 253 : RTE_INIT(eth_dev_init_fp_ops)
5746 : : {
5747 : : uint32_t i;
5748 : :
5749 [ + + ]: 8349 : for (i = 0; i != RTE_DIM(rte_eth_fp_ops); i++)
5750 : 8096 : eth_dev_fp_ops_reset(rte_eth_fp_ops + i);
5751 : 253 : }
5752 : :
5753 : 253 : RTE_INIT(eth_dev_init_cb_lists)
5754 : : {
5755 : : uint16_t i;
5756 : :
5757 [ + + ]: 8349 : for (i = 0; i < RTE_MAX_ETHPORTS; i++)
5758 : 8096 : TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
5759 : 253 : }
5760 : :
5761 : : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_register)
5762 : : int
5763 : 0 : rte_eth_dev_callback_register(uint16_t port_id,
5764 : : enum rte_eth_event_type event,
5765 : : rte_eth_dev_cb_fn cb_fn, void *cb_arg)
5766 : : {
5767 : : struct rte_eth_dev *dev;
5768 : : struct rte_eth_dev_callback *user_cb;
5769 : : uint16_t next_port;
5770 : : uint16_t last_port;
5771 : :
5772 [ # # ]: 0 : if (cb_fn == NULL) {
5773 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5774 : : "Cannot register ethdev port %u callback from NULL",
5775 : : port_id);
5776 : 0 : return -EINVAL;
5777 : : }
5778 : :
5779 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
5780 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
5781 : 0 : return -EINVAL;
5782 : : }
5783 : :
5784 [ # # ]: 0 : if (port_id == RTE_ETH_ALL) {
5785 : : next_port = 0;
5786 : : last_port = RTE_MAX_ETHPORTS - 1;
5787 : : } else {
5788 : : next_port = last_port = port_id;
5789 : : }
5790 : :
5791 : : rte_spinlock_lock(ð_dev_cb_lock);
5792 : :
5793 : : do {
5794 : 0 : dev = &rte_eth_devices[next_port];
5795 : :
5796 [ # # ]: 0 : TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) {
5797 [ # # ]: 0 : if (user_cb->cb_fn == cb_fn &&
5798 [ # # ]: 0 : user_cb->cb_arg == cb_arg &&
5799 [ # # ]: 0 : user_cb->event == event) {
5800 : : break;
5801 : : }
5802 : : }
5803 : :
5804 : : /* create a new callback. */
5805 [ # # ]: 0 : if (user_cb == NULL) {
5806 : 0 : user_cb = rte_zmalloc("INTR_USER_CALLBACK",
5807 : : sizeof(struct rte_eth_dev_callback), 0);
5808 [ # # ]: 0 : if (user_cb != NULL) {
5809 : 0 : user_cb->cb_fn = cb_fn;
5810 : 0 : user_cb->cb_arg = cb_arg;
5811 : 0 : user_cb->event = event;
5812 : 0 : TAILQ_INSERT_TAIL(&(dev->link_intr_cbs),
5813 : : user_cb, next);
5814 : : } else {
5815 : : rte_spinlock_unlock(ð_dev_cb_lock);
5816 : 0 : rte_eth_dev_callback_unregister(port_id, event,
5817 : : cb_fn, cb_arg);
5818 : 0 : return -ENOMEM;
5819 : : }
5820 : :
5821 : : }
5822 [ # # ]: 0 : } while (++next_port <= last_port);
5823 : :
5824 : : rte_spinlock_unlock(ð_dev_cb_lock);
5825 : :
5826 : 0 : rte_ethdev_trace_callback_register(port_id, event, cb_fn, cb_arg);
5827 : :
5828 : 0 : return 0;
5829 : : }
5830 : :
5831 : : RTE_EXPORT_SYMBOL(rte_eth_dev_callback_unregister)
5832 : : int
5833 : 0 : rte_eth_dev_callback_unregister(uint16_t port_id,
5834 : : enum rte_eth_event_type event,
5835 : : rte_eth_dev_cb_fn cb_fn, void *cb_arg)
5836 : : {
5837 : : int ret;
5838 : : struct rte_eth_dev *dev;
5839 : : struct rte_eth_dev_callback *cb, *next;
5840 : : uint16_t next_port;
5841 : : uint16_t last_port;
5842 : :
5843 [ # # ]: 0 : if (cb_fn == NULL) {
5844 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5845 : : "Cannot unregister ethdev port %u callback from NULL",
5846 : : port_id);
5847 : 0 : return -EINVAL;
5848 : : }
5849 : :
5850 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) {
5851 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid port_id=%d", port_id);
5852 : 0 : return -EINVAL;
5853 : : }
5854 : :
5855 [ # # ]: 0 : if (port_id == RTE_ETH_ALL) {
5856 : : next_port = 0;
5857 : : last_port = RTE_MAX_ETHPORTS - 1;
5858 : : } else {
5859 : : next_port = last_port = port_id;
5860 : : }
5861 : :
5862 : : rte_spinlock_lock(ð_dev_cb_lock);
5863 : :
5864 : : do {
5865 : 0 : dev = &rte_eth_devices[next_port];
5866 : : ret = 0;
5867 [ # # ]: 0 : for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL;
5868 : : cb = next) {
5869 : :
5870 : 0 : next = TAILQ_NEXT(cb, next);
5871 : :
5872 [ # # # # : 0 : if (cb->cb_fn != cb_fn || cb->event != event ||
# # ]
5873 [ # # ]: 0 : (cb_arg != (void *)-1 && cb->cb_arg != cb_arg))
5874 : 0 : continue;
5875 : :
5876 : : /*
5877 : : * if this callback is not executing right now,
5878 : : * then remove it.
5879 : : */
5880 [ # # ]: 0 : if (cb->active == 0) {
5881 [ # # ]: 0 : TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next);
5882 : 0 : rte_free(cb);
5883 : : } else {
5884 : : ret = -EAGAIN;
5885 : : }
5886 : : }
5887 [ # # ]: 0 : } while (++next_port <= last_port);
5888 : :
5889 : : rte_spinlock_unlock(ð_dev_cb_lock);
5890 : :
5891 : 0 : rte_ethdev_trace_callback_unregister(port_id, event, cb_fn, cb_arg,
5892 : : ret);
5893 : :
5894 : 0 : return ret;
5895 : : }
5896 : :
5897 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl)
5898 : : int
5899 : 0 : rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data)
5900 : : {
5901 : : uint32_t vec;
5902 : : struct rte_eth_dev *dev;
5903 : : struct rte_intr_handle *intr_handle;
5904 : : uint16_t qid;
5905 : : int rc;
5906 : :
5907 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5908 : : dev = &rte_eth_devices[port_id];
5909 : :
5910 [ # # ]: 0 : if (!dev->intr_handle) {
5911 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5912 : 0 : return -ENOTSUP;
5913 : : }
5914 : :
5915 : : intr_handle = dev->intr_handle;
5916 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
5917 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
5918 : 0 : return -EPERM;
5919 : : }
5920 : :
5921 [ # # ]: 0 : for (qid = 0; qid < dev->data->nb_rx_queues; qid++) {
5922 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, qid);
5923 : 0 : rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
5924 : :
5925 : 0 : rte_ethdev_trace_rx_intr_ctl(port_id, qid, epfd, op, data, rc);
5926 : :
5927 [ # # ]: 0 : if (rc && rc != -EEXIST) {
5928 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
5929 : : "p %u q %u Rx ctl error op %d epfd %d vec %u",
5930 : : port_id, qid, op, epfd, vec);
5931 : : }
5932 : : }
5933 : :
5934 : : return 0;
5935 : : }
5936 : :
5937 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q_get_fd)
5938 : : int
5939 : 0 : rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id)
5940 : : {
5941 : : struct rte_intr_handle *intr_handle;
5942 : : struct rte_eth_dev *dev;
5943 : : unsigned int efd_idx;
5944 : : uint32_t vec;
5945 : : int fd;
5946 : :
5947 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1);
5948 : : dev = &rte_eth_devices[port_id];
5949 : :
5950 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
5951 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
5952 : 0 : return -1;
5953 : : }
5954 : :
5955 [ # # ]: 0 : if (!dev->intr_handle) {
5956 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5957 : 0 : return -1;
5958 : : }
5959 : :
5960 : : intr_handle = dev->intr_handle;
5961 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
5962 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
5963 : 0 : return -1;
5964 : : }
5965 : :
5966 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
5967 : : efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ?
5968 [ # # ]: 0 : (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec;
5969 : 0 : fd = rte_intr_efds_index_get(intr_handle, efd_idx);
5970 : :
5971 : 0 : rte_ethdev_trace_rx_intr_ctl_q_get_fd(port_id, queue_id, fd);
5972 : :
5973 : 0 : return fd;
5974 : : }
5975 : :
5976 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_ctl_q)
5977 : : int
5978 : 0 : rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id,
5979 : : int epfd, int op, void *data)
5980 : : {
5981 : : uint32_t vec;
5982 : : struct rte_eth_dev *dev;
5983 : : struct rte_intr_handle *intr_handle;
5984 : : int rc;
5985 : :
5986 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
5987 : : dev = &rte_eth_devices[port_id];
5988 : :
5989 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
5990 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
5991 : 0 : return -EINVAL;
5992 : : }
5993 : :
5994 [ # # ]: 0 : if (!dev->intr_handle) {
5995 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr handle unset");
5996 : 0 : return -ENOTSUP;
5997 : : }
5998 : :
5999 : : intr_handle = dev->intr_handle;
6000 [ # # ]: 0 : if (rte_intr_vec_list_index_get(intr_handle, 0) < 0) {
6001 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Rx Intr vector unset");
6002 : 0 : return -EPERM;
6003 : : }
6004 : :
6005 : 0 : vec = rte_intr_vec_list_index_get(intr_handle, queue_id);
6006 : 0 : rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data);
6007 : :
6008 : 0 : rte_ethdev_trace_rx_intr_ctl_q(port_id, queue_id, epfd, op, data, rc);
6009 : :
6010 [ # # ]: 0 : if (rc && rc != -EEXIST) {
6011 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6012 : : "p %u q %u Rx ctl error op %d epfd %d vec %u",
6013 : : port_id, queue_id, op, epfd, vec);
6014 : 0 : return rc;
6015 : : }
6016 : :
6017 : : return 0;
6018 : : }
6019 : :
6020 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_enable)
6021 : : int
6022 : 0 : rte_eth_dev_rx_intr_enable(uint16_t port_id,
6023 : : uint16_t queue_id)
6024 : : {
6025 : : struct rte_eth_dev *dev;
6026 : : int ret;
6027 : :
6028 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6029 : 0 : dev = &rte_eth_devices[port_id];
6030 : :
6031 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6032 [ # # ]: 0 : if (ret != 0)
6033 : : return ret;
6034 : :
6035 [ # # ]: 0 : if (dev->dev_ops->rx_queue_intr_enable == NULL)
6036 : : return -ENOTSUP;
6037 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_enable(dev, queue_id));
6038 : :
6039 : : rte_ethdev_trace_rx_intr_enable(port_id, queue_id, ret);
6040 : :
6041 : 0 : return ret;
6042 : : }
6043 : :
6044 : : RTE_EXPORT_SYMBOL(rte_eth_dev_rx_intr_disable)
6045 : : int
6046 : 0 : rte_eth_dev_rx_intr_disable(uint16_t port_id,
6047 : : uint16_t queue_id)
6048 : : {
6049 : : struct rte_eth_dev *dev;
6050 : : int ret;
6051 : :
6052 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6053 : 0 : dev = &rte_eth_devices[port_id];
6054 : :
6055 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6056 [ # # ]: 0 : if (ret != 0)
6057 : : return ret;
6058 : :
6059 [ # # ]: 0 : if (dev->dev_ops->rx_queue_intr_disable == NULL)
6060 : : return -ENOTSUP;
6061 : 0 : ret = eth_err(port_id, dev->dev_ops->rx_queue_intr_disable(dev, queue_id));
6062 : :
6063 : : rte_ethdev_trace_rx_intr_disable(port_id, queue_id, ret);
6064 : :
6065 : 0 : return ret;
6066 : : }
6067 : :
6068 : :
6069 : : RTE_EXPORT_SYMBOL(rte_eth_add_rx_callback)
6070 : : const struct rte_eth_rxtx_callback *
6071 : 0 : rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id,
6072 : : rte_rx_callback_fn fn, void *user_param)
6073 : : {
6074 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6075 : : rte_errno = ENOTSUP;
6076 : : return NULL;
6077 : : #endif
6078 : : struct rte_eth_dev *dev;
6079 : :
6080 : : /* check input parameters */
6081 [ # # # # ]: 0 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6082 [ # # ]: 0 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
6083 : 0 : rte_errno = EINVAL;
6084 : 0 : return NULL;
6085 : : }
6086 : 0 : dev = &rte_eth_devices[port_id];
6087 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
6088 : 0 : rte_errno = EINVAL;
6089 : 0 : return NULL;
6090 : : }
6091 : 0 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6092 : :
6093 [ # # ]: 0 : if (cb == NULL) {
6094 : 0 : rte_errno = ENOMEM;
6095 : 0 : return NULL;
6096 : : }
6097 : :
6098 : 0 : cb->fn.rx = fn;
6099 : 0 : cb->param = user_param;
6100 : :
6101 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6102 : : /* Add the callbacks in fifo order. */
6103 : 0 : struct rte_eth_rxtx_callback *tail =
6104 : : rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
6105 : :
6106 [ # # ]: 0 : if (!tail) {
6107 : : /* Stores to cb->fn and cb->param should complete before
6108 : : * cb is visible to data plane.
6109 : : */
6110 : 0 : rte_atomic_store_explicit(
6111 : : &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
6112 : : cb, rte_memory_order_release);
6113 : :
6114 : : } else {
6115 [ # # ]: 0 : while (tail->next)
6116 : : tail = tail->next;
6117 : : /* Stores to cb->fn and cb->param should complete before
6118 : : * cb is visible to data plane.
6119 : : */
6120 : 0 : rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
6121 : : }
6122 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6123 : :
6124 : 0 : rte_eth_trace_add_rx_callback(port_id, queue_id, fn, user_param, cb);
6125 : :
6126 : 0 : return cb;
6127 : : }
6128 : :
6129 : : RTE_EXPORT_SYMBOL(rte_eth_add_first_rx_callback)
6130 : : const struct rte_eth_rxtx_callback *
6131 : 1 : rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id,
6132 : : rte_rx_callback_fn fn, void *user_param)
6133 : : {
6134 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6135 : : rte_errno = ENOTSUP;
6136 : : return NULL;
6137 : : #endif
6138 : : /* check input parameters */
6139 [ + - + - ]: 1 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6140 [ - + ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) {
6141 : 0 : rte_errno = EINVAL;
6142 : 0 : return NULL;
6143 : : }
6144 : :
6145 : 1 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6146 : :
6147 [ - + ]: 1 : if (cb == NULL) {
6148 : 0 : rte_errno = ENOMEM;
6149 : 0 : return NULL;
6150 : : }
6151 : :
6152 : 1 : cb->fn.rx = fn;
6153 : 1 : cb->param = user_param;
6154 : :
6155 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6156 : : /* Add the callbacks at first position */
6157 : 1 : cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id];
6158 : : /* Stores to cb->fn, cb->param and cb->next should complete before
6159 : : * cb is visible to data plane threads.
6160 : : */
6161 : 1 : rte_atomic_store_explicit(
6162 : : &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id],
6163 : : cb, rte_memory_order_release);
6164 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6165 : :
6166 : 1 : rte_eth_trace_add_first_rx_callback(port_id, queue_id, fn, user_param,
6167 : : cb);
6168 : :
6169 : 1 : return cb;
6170 : : }
6171 : :
6172 : : RTE_EXPORT_SYMBOL(rte_eth_add_tx_callback)
6173 : : const struct rte_eth_rxtx_callback *
6174 : 1 : rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id,
6175 : : rte_tx_callback_fn fn, void *user_param)
6176 : : {
6177 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6178 : : rte_errno = ENOTSUP;
6179 : : return NULL;
6180 : : #endif
6181 : : struct rte_eth_dev *dev;
6182 : :
6183 : : /* check input parameters */
6184 [ + - + - ]: 1 : if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL ||
6185 [ - + ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) {
6186 : 0 : rte_errno = EINVAL;
6187 : 0 : return NULL;
6188 : : }
6189 : :
6190 : 1 : dev = &rte_eth_devices[port_id];
6191 [ - + ]: 1 : if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
6192 : 0 : rte_errno = EINVAL;
6193 : 0 : return NULL;
6194 : : }
6195 : :
6196 : 1 : struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0);
6197 : :
6198 [ - + ]: 1 : if (cb == NULL) {
6199 : 0 : rte_errno = ENOMEM;
6200 : 0 : return NULL;
6201 : : }
6202 : :
6203 : 1 : cb->fn.tx = fn;
6204 : 1 : cb->param = user_param;
6205 : :
6206 : : rte_spinlock_lock(ð_dev_tx_cb_lock);
6207 : : /* Add the callbacks in fifo order. */
6208 : 1 : struct rte_eth_rxtx_callback *tail =
6209 : : rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id];
6210 : :
6211 [ + - ]: 1 : if (!tail) {
6212 : : /* Stores to cb->fn and cb->param should complete before
6213 : : * cb is visible to data plane.
6214 : : */
6215 : 1 : rte_atomic_store_explicit(
6216 : : &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id],
6217 : : cb, rte_memory_order_release);
6218 : :
6219 : : } else {
6220 [ # # ]: 0 : while (tail->next)
6221 : : tail = tail->next;
6222 : : /* Stores to cb->fn and cb->param should complete before
6223 : : * cb is visible to data plane.
6224 : : */
6225 : 0 : rte_atomic_store_explicit(&tail->next, cb, rte_memory_order_release);
6226 : : }
6227 : : rte_spinlock_unlock(ð_dev_tx_cb_lock);
6228 : :
6229 : 1 : rte_eth_trace_add_tx_callback(port_id, queue_id, fn, user_param, cb);
6230 : :
6231 : 1 : return cb;
6232 : : }
6233 : :
6234 : : RTE_EXPORT_SYMBOL(rte_eth_remove_rx_callback)
6235 : : int
6236 : 1 : rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id,
6237 : : const struct rte_eth_rxtx_callback *user_cb)
6238 : : {
6239 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6240 : : return -ENOTSUP;
6241 : : #endif
6242 : : /* Check input parameters. */
6243 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6244 [ + - ]: 1 : if (user_cb == NULL ||
6245 [ + - ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_rx_queues)
6246 : : return -EINVAL;
6247 : :
6248 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
6249 : : struct rte_eth_rxtx_callback *cb;
6250 : : RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
6251 : : int ret = -EINVAL;
6252 : :
6253 : : rte_spinlock_lock(ð_dev_rx_cb_lock);
6254 : 1 : prev_cb = &dev->post_rx_burst_cbs[queue_id];
6255 [ + - ]: 1 : for (; *prev_cb != NULL; prev_cb = &cb->next) {
6256 : : cb = *prev_cb;
6257 [ + - ]: 1 : if (cb == user_cb) {
6258 : : /* Remove the user cb from the callback list. */
6259 : 1 : rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
6260 : : ret = 0;
6261 : 1 : break;
6262 : : }
6263 : : }
6264 : : rte_spinlock_unlock(ð_dev_rx_cb_lock);
6265 : :
6266 : 1 : rte_eth_trace_remove_rx_callback(port_id, queue_id, user_cb, ret);
6267 : :
6268 : 1 : return ret;
6269 : : }
6270 : :
6271 : : RTE_EXPORT_SYMBOL(rte_eth_remove_tx_callback)
6272 : : int
6273 : 1 : rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id,
6274 : : const struct rte_eth_rxtx_callback *user_cb)
6275 : : {
6276 : : #ifndef RTE_ETHDEV_RXTX_CALLBACKS
6277 : : return -ENOTSUP;
6278 : : #endif
6279 : : /* Check input parameters. */
6280 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6281 [ + - ]: 1 : if (user_cb == NULL ||
6282 [ + - ]: 1 : queue_id >= rte_eth_devices[port_id].data->nb_tx_queues)
6283 : : return -EINVAL;
6284 : :
6285 : : struct rte_eth_dev *dev = &rte_eth_devices[port_id];
6286 : : int ret = -EINVAL;
6287 : : struct rte_eth_rxtx_callback *cb;
6288 : : RTE_ATOMIC(struct rte_eth_rxtx_callback *) *prev_cb;
6289 : :
6290 : : rte_spinlock_lock(ð_dev_tx_cb_lock);
6291 : 1 : prev_cb = &dev->pre_tx_burst_cbs[queue_id];
6292 [ + - ]: 1 : for (; *prev_cb != NULL; prev_cb = &cb->next) {
6293 : : cb = *prev_cb;
6294 [ + - ]: 1 : if (cb == user_cb) {
6295 : : /* Remove the user cb from the callback list. */
6296 : 1 : rte_atomic_store_explicit(prev_cb, cb->next, rte_memory_order_relaxed);
6297 : : ret = 0;
6298 : 1 : break;
6299 : : }
6300 : : }
6301 : : rte_spinlock_unlock(ð_dev_tx_cb_lock);
6302 : :
6303 : 1 : rte_eth_trace_remove_tx_callback(port_id, queue_id, user_cb, ret);
6304 : :
6305 : 1 : return ret;
6306 : : }
6307 : :
6308 : : RTE_EXPORT_SYMBOL(rte_eth_rx_queue_info_get)
6309 : : int
6310 : 1 : rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6311 : : struct rte_eth_rxq_info *qinfo)
6312 : : {
6313 : : struct rte_eth_dev *dev;
6314 : :
6315 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6316 : 1 : dev = &rte_eth_devices[port_id];
6317 : :
6318 [ - + ]: 1 : if (queue_id >= dev->data->nb_rx_queues) {
6319 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6320 : 0 : return -EINVAL;
6321 : : }
6322 : :
6323 [ - + ]: 1 : if (qinfo == NULL) {
6324 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL",
6325 : : port_id, queue_id);
6326 : 0 : return -EINVAL;
6327 : : }
6328 : :
6329 [ - + ]: 1 : if (dev->data->rx_queues == NULL ||
6330 [ # # ]: 0 : dev->data->rx_queues[queue_id] == NULL) {
6331 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
6332 : : "Rx queue %"PRIu16" of device with port_id=%"
6333 : : PRIu16" has not been setup",
6334 : : queue_id, port_id);
6335 : 1 : return -EINVAL;
6336 : : }
6337 : :
6338 [ # # ]: 0 : if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) {
6339 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
6340 : : "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16,
6341 : : queue_id, port_id);
6342 : 0 : return -EINVAL;
6343 : : }
6344 : :
6345 [ # # ]: 0 : if (dev->dev_ops->rxq_info_get == NULL)
6346 : : return -ENOTSUP;
6347 : :
6348 : : memset(qinfo, 0, sizeof(*qinfo));
6349 : 0 : dev->dev_ops->rxq_info_get(dev, queue_id, qinfo);
6350 [ # # ]: 0 : qinfo->queue_state = dev->data->rx_queue_state[queue_id];
6351 : :
6352 : 0 : rte_eth_trace_rx_queue_info_get(port_id, queue_id, qinfo);
6353 : :
6354 : 0 : return 0;
6355 : : }
6356 : :
6357 : : RTE_EXPORT_SYMBOL(rte_eth_tx_queue_info_get)
6358 : : int
6359 : 1 : rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6360 : : struct rte_eth_txq_info *qinfo)
6361 : : {
6362 : : struct rte_eth_dev *dev;
6363 : :
6364 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6365 : 1 : dev = &rte_eth_devices[port_id];
6366 : :
6367 [ - + ]: 1 : if (queue_id >= dev->data->nb_tx_queues) {
6368 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
6369 : 0 : return -EINVAL;
6370 : : }
6371 : :
6372 [ - + ]: 1 : if (qinfo == NULL) {
6373 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL",
6374 : : port_id, queue_id);
6375 : 0 : return -EINVAL;
6376 : : }
6377 : :
6378 [ - + ]: 1 : if (dev->data->tx_queues == NULL ||
6379 [ # # ]: 0 : dev->data->tx_queues[queue_id] == NULL) {
6380 : 1 : RTE_ETHDEV_LOG_LINE(ERR,
6381 : : "Tx queue %"PRIu16" of device with port_id=%"
6382 : : PRIu16" has not been setup",
6383 : : queue_id, port_id);
6384 : 1 : return -EINVAL;
6385 : : }
6386 : :
6387 [ # # ]: 0 : if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) {
6388 : 0 : RTE_ETHDEV_LOG_LINE(INFO,
6389 : : "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16,
6390 : : queue_id, port_id);
6391 : 0 : return -EINVAL;
6392 : : }
6393 : :
6394 [ # # ]: 0 : if (dev->dev_ops->txq_info_get == NULL)
6395 : : return -ENOTSUP;
6396 : :
6397 : : memset(qinfo, 0, sizeof(*qinfo));
6398 : 0 : dev->dev_ops->txq_info_get(dev, queue_id, qinfo);
6399 [ # # ]: 0 : qinfo->queue_state = dev->data->tx_queue_state[queue_id];
6400 : :
6401 : 0 : rte_eth_trace_tx_queue_info_get(port_id, queue_id, qinfo);
6402 : :
6403 : 0 : return 0;
6404 : : }
6405 : :
6406 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_recycle_rx_queue_info_get, 23.11)
6407 : : int
6408 : 0 : rte_eth_recycle_rx_queue_info_get(uint16_t port_id, uint16_t queue_id,
6409 : : struct rte_eth_recycle_rxq_info *recycle_rxq_info)
6410 : : {
6411 : : struct rte_eth_dev *dev;
6412 : : int ret;
6413 : :
6414 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6415 : 0 : dev = &rte_eth_devices[port_id];
6416 : :
6417 : 0 : ret = eth_dev_validate_rx_queue(dev, queue_id);
6418 [ # # ]: 0 : if (unlikely(ret != 0))
6419 : : return ret;
6420 : :
6421 [ # # ]: 0 : if (dev->dev_ops->recycle_rxq_info_get == NULL)
6422 : : return -ENOTSUP;
6423 : :
6424 : 0 : dev->dev_ops->recycle_rxq_info_get(dev, queue_id, recycle_rxq_info);
6425 : :
6426 : 0 : return 0;
6427 : : }
6428 : :
6429 : : RTE_EXPORT_SYMBOL(rte_eth_rx_burst_mode_get)
6430 : : int
6431 : 0 : rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
6432 : : struct rte_eth_burst_mode *mode)
6433 : : {
6434 : : struct rte_eth_dev *dev;
6435 : : int ret;
6436 : :
6437 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6438 : 0 : dev = &rte_eth_devices[port_id];
6439 : :
6440 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6441 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6442 : 0 : return -EINVAL;
6443 : : }
6444 : :
6445 [ # # ]: 0 : if (mode == NULL) {
6446 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6447 : : "Cannot get ethdev port %u Rx queue %u burst mode to NULL",
6448 : : port_id, queue_id);
6449 : 0 : return -EINVAL;
6450 : : }
6451 : :
6452 [ # # ]: 0 : if (dev->dev_ops->rx_burst_mode_get == NULL)
6453 : : return -ENOTSUP;
6454 : : memset(mode, 0, sizeof(*mode));
6455 : 0 : ret = eth_err(port_id,
6456 : 0 : dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode));
6457 : :
6458 : 0 : rte_eth_trace_rx_burst_mode_get(port_id, queue_id, mode, ret);
6459 : :
6460 : 0 : return ret;
6461 : : }
6462 : :
6463 : : RTE_EXPORT_SYMBOL(rte_eth_tx_burst_mode_get)
6464 : : int
6465 : 0 : rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id,
6466 : : struct rte_eth_burst_mode *mode)
6467 : : {
6468 : : struct rte_eth_dev *dev;
6469 : : int ret;
6470 : :
6471 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6472 : 0 : dev = &rte_eth_devices[port_id];
6473 : :
6474 [ # # ]: 0 : if (queue_id >= dev->data->nb_tx_queues) {
6475 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
6476 : 0 : return -EINVAL;
6477 : : }
6478 : :
6479 [ # # ]: 0 : if (mode == NULL) {
6480 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6481 : : "Cannot get ethdev port %u Tx queue %u burst mode to NULL",
6482 : : port_id, queue_id);
6483 : 0 : return -EINVAL;
6484 : : }
6485 : :
6486 [ # # ]: 0 : if (dev->dev_ops->tx_burst_mode_get == NULL)
6487 : : return -ENOTSUP;
6488 : : memset(mode, 0, sizeof(*mode));
6489 : 0 : ret = eth_err(port_id,
6490 : 0 : dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
6491 : :
6492 : 0 : rte_eth_trace_tx_burst_mode_get(port_id, queue_id, mode, ret);
6493 : :
6494 : 0 : return ret;
6495 : : }
6496 : :
6497 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_get_monitor_addr, 21.02)
6498 : : int
6499 : 0 : rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
6500 : : struct rte_power_monitor_cond *pmc)
6501 : : {
6502 : : struct rte_eth_dev *dev;
6503 : : int ret;
6504 : :
6505 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6506 : : dev = &rte_eth_devices[port_id];
6507 : :
6508 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
6509 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
6510 : 0 : return -EINVAL;
6511 : : }
6512 : :
6513 [ # # ]: 0 : if (pmc == NULL) {
6514 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6515 : : "Cannot get ethdev port %u Rx queue %u power monitor condition to NULL",
6516 : : port_id, queue_id);
6517 : 0 : return -EINVAL;
6518 : : }
6519 : :
6520 [ # # ]: 0 : if (dev->dev_ops->get_monitor_addr == NULL)
6521 : : return -ENOTSUP;
6522 : 0 : ret = eth_err(port_id,
6523 : 0 : dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc));
6524 : :
6525 : 0 : rte_eth_trace_get_monitor_addr(port_id, queue_id, pmc, ret);
6526 : :
6527 : 0 : return ret;
6528 : : }
6529 : :
6530 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_mc_addr_list)
6531 : : int
6532 : 0 : rte_eth_dev_set_mc_addr_list(uint16_t port_id,
6533 : : struct rte_ether_addr *mc_addr_set,
6534 : : uint32_t nb_mc_addr)
6535 : : {
6536 : : struct rte_eth_dev *dev;
6537 : : int ret;
6538 : :
6539 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6540 : 0 : dev = &rte_eth_devices[port_id];
6541 : :
6542 [ # # ]: 0 : if (dev->dev_ops->set_mc_addr_list == NULL)
6543 : : return -ENOTSUP;
6544 : 0 : ret = eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev,
6545 : : mc_addr_set, nb_mc_addr));
6546 : :
6547 : 0 : rte_ethdev_trace_set_mc_addr_list(port_id, mc_addr_set, nb_mc_addr,
6548 : : ret);
6549 : :
6550 : 0 : return ret;
6551 : : }
6552 : :
6553 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_enable)
6554 : : int
6555 : 0 : rte_eth_timesync_enable(uint16_t port_id)
6556 : : {
6557 : : struct rte_eth_dev *dev;
6558 : : int ret;
6559 : :
6560 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6561 : 0 : dev = &rte_eth_devices[port_id];
6562 : :
6563 [ # # ]: 0 : if (dev->dev_ops->timesync_enable == NULL)
6564 : : return -ENOTSUP;
6565 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_enable(dev));
6566 : :
6567 : 0 : rte_eth_trace_timesync_enable(port_id, ret);
6568 : :
6569 : 0 : return ret;
6570 : : }
6571 : :
6572 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_disable)
6573 : : int
6574 : 0 : rte_eth_timesync_disable(uint16_t port_id)
6575 : : {
6576 : : struct rte_eth_dev *dev;
6577 : : int ret;
6578 : :
6579 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6580 : 0 : dev = &rte_eth_devices[port_id];
6581 : :
6582 [ # # ]: 0 : if (dev->dev_ops->timesync_disable == NULL)
6583 : : return -ENOTSUP;
6584 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_disable(dev));
6585 : :
6586 : 0 : rte_eth_trace_timesync_disable(port_id, ret);
6587 : :
6588 : 0 : return ret;
6589 : : }
6590 : :
6591 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_rx_timestamp)
6592 : : int
6593 : 0 : rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp,
6594 : : uint32_t flags)
6595 : : {
6596 : : struct rte_eth_dev *dev;
6597 : : int ret;
6598 : :
6599 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6600 : 0 : dev = &rte_eth_devices[port_id];
6601 : :
6602 [ # # ]: 0 : if (timestamp == NULL) {
6603 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6604 : : "Cannot read ethdev port %u Rx timestamp to NULL",
6605 : : port_id);
6606 : 0 : return -EINVAL;
6607 : : }
6608 : :
6609 [ # # ]: 0 : if (dev->dev_ops->timesync_read_rx_timestamp == NULL)
6610 : : return -ENOTSUP;
6611 : :
6612 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_rx_timestamp(dev, timestamp, flags));
6613 : :
6614 : : rte_eth_trace_timesync_read_rx_timestamp(port_id, timestamp, flags,
6615 : : ret);
6616 : :
6617 : 0 : return ret;
6618 : : }
6619 : :
6620 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_tx_timestamp)
6621 : : int
6622 : 0 : rte_eth_timesync_read_tx_timestamp(uint16_t port_id,
6623 : : struct timespec *timestamp)
6624 : : {
6625 : : struct rte_eth_dev *dev;
6626 : : int ret;
6627 : :
6628 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6629 : 0 : dev = &rte_eth_devices[port_id];
6630 : :
6631 [ # # ]: 0 : if (timestamp == NULL) {
6632 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6633 : : "Cannot read ethdev port %u Tx timestamp to NULL",
6634 : : port_id);
6635 : 0 : return -EINVAL;
6636 : : }
6637 : :
6638 [ # # ]: 0 : if (dev->dev_ops->timesync_read_tx_timestamp == NULL)
6639 : : return -ENOTSUP;
6640 : :
6641 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_tx_timestamp(dev, timestamp));
6642 : :
6643 : : rte_eth_trace_timesync_read_tx_timestamp(port_id, timestamp, ret);
6644 : :
6645 : 0 : return ret;
6646 : :
6647 : : }
6648 : :
6649 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_adjust_time)
6650 : : int
6651 : 0 : rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta)
6652 : : {
6653 : : struct rte_eth_dev *dev;
6654 : : int ret;
6655 : :
6656 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6657 : 0 : dev = &rte_eth_devices[port_id];
6658 : :
6659 [ # # ]: 0 : if (dev->dev_ops->timesync_adjust_time == NULL)
6660 : : return -ENOTSUP;
6661 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_adjust_time(dev, delta));
6662 : :
6663 : : rte_eth_trace_timesync_adjust_time(port_id, delta, ret);
6664 : :
6665 : 0 : return ret;
6666 : : }
6667 : :
6668 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_timesync_adjust_freq, 24.11)
6669 : : int
6670 : 0 : rte_eth_timesync_adjust_freq(uint16_t port_id, int64_t ppm)
6671 : : {
6672 : : struct rte_eth_dev *dev;
6673 : : int ret;
6674 : :
6675 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6676 : 0 : dev = &rte_eth_devices[port_id];
6677 : :
6678 [ # # ]: 0 : if (dev->dev_ops->timesync_adjust_freq == NULL)
6679 : : return -ENOTSUP;
6680 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_adjust_freq(dev, ppm));
6681 : :
6682 : : rte_eth_trace_timesync_adjust_freq(port_id, ppm, ret);
6683 : :
6684 : 0 : return ret;
6685 : : }
6686 : :
6687 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_read_time)
6688 : : int
6689 : 0 : rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp)
6690 : : {
6691 : : struct rte_eth_dev *dev;
6692 : : int ret;
6693 : :
6694 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6695 : 0 : dev = &rte_eth_devices[port_id];
6696 : :
6697 [ # # ]: 0 : if (timestamp == NULL) {
6698 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6699 : : "Cannot read ethdev port %u timesync time to NULL",
6700 : : port_id);
6701 : 0 : return -EINVAL;
6702 : : }
6703 : :
6704 [ # # ]: 0 : if (dev->dev_ops->timesync_read_time == NULL)
6705 : : return -ENOTSUP;
6706 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_read_time(dev, timestamp));
6707 : :
6708 : : rte_eth_trace_timesync_read_time(port_id, timestamp, ret);
6709 : :
6710 : 0 : return ret;
6711 : : }
6712 : :
6713 : : RTE_EXPORT_SYMBOL(rte_eth_timesync_write_time)
6714 : : int
6715 : 0 : rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp)
6716 : : {
6717 : : struct rte_eth_dev *dev;
6718 : : int ret;
6719 : :
6720 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6721 : 0 : dev = &rte_eth_devices[port_id];
6722 : :
6723 [ # # ]: 0 : if (timestamp == NULL) {
6724 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6725 : : "Cannot write ethdev port %u timesync from NULL time",
6726 : : port_id);
6727 : 0 : return -EINVAL;
6728 : : }
6729 : :
6730 [ # # ]: 0 : if (dev->dev_ops->timesync_write_time == NULL)
6731 : : return -ENOTSUP;
6732 : 0 : ret = eth_err(port_id, dev->dev_ops->timesync_write_time(dev, timestamp));
6733 : :
6734 : 0 : rte_eth_trace_timesync_write_time(port_id, timestamp, ret);
6735 : :
6736 : 0 : return ret;
6737 : : }
6738 : :
6739 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_read_clock, 19.08)
6740 : : int
6741 : 0 : rte_eth_read_clock(uint16_t port_id, uint64_t *clock)
6742 : : {
6743 : : struct rte_eth_dev *dev;
6744 : : int ret;
6745 : :
6746 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6747 : 0 : dev = &rte_eth_devices[port_id];
6748 : :
6749 [ # # ]: 0 : if (clock == NULL) {
6750 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot read ethdev port %u clock to NULL",
6751 : : port_id);
6752 : 0 : return -EINVAL;
6753 : : }
6754 : :
6755 [ # # ]: 0 : if (dev->dev_ops->read_clock == NULL)
6756 : : return -ENOTSUP;
6757 : 0 : ret = eth_err(port_id, dev->dev_ops->read_clock(dev, clock));
6758 : :
6759 : 0 : rte_eth_trace_read_clock(port_id, clock, ret);
6760 : :
6761 : 0 : return ret;
6762 : : }
6763 : :
6764 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_reg_info)
6765 : : int
6766 : 0 : rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info)
6767 : : {
6768 : 0 : struct rte_dev_reg_info reg_info = { 0 };
6769 : : int ret;
6770 : :
6771 [ # # ]: 0 : if (info == NULL) {
6772 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6773 : : "Cannot get ethdev port %u register info to NULL",
6774 : : port_id);
6775 : 0 : return -EINVAL;
6776 : : }
6777 : :
6778 : 0 : reg_info.length = info->length;
6779 : 0 : reg_info.width = info->width;
6780 : 0 : reg_info.offset = info->offset;
6781 : 0 : reg_info.data = info->data;
6782 : :
6783 : 0 : ret = rte_eth_dev_get_reg_info_ext(port_id, ®_info);
6784 [ # # ]: 0 : if (ret != 0)
6785 : : return ret;
6786 : :
6787 : 0 : info->length = reg_info.length;
6788 : 0 : info->width = reg_info.width;
6789 : 0 : info->version = reg_info.version;
6790 : 0 : info->offset = reg_info.offset;
6791 : :
6792 : 0 : return 0;
6793 : : }
6794 : :
6795 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_reg_info_ext, 24.11)
6796 : : int
6797 : 1 : rte_eth_dev_get_reg_info_ext(uint16_t port_id, struct rte_dev_reg_info *info)
6798 : : {
6799 : : struct rte_eth_dev *dev;
6800 : : uint32_t i;
6801 : : int ret;
6802 : :
6803 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6804 : 1 : dev = &rte_eth_devices[port_id];
6805 : :
6806 [ - + ]: 1 : if (info == NULL) {
6807 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6808 : : "Cannot get ethdev port %u register info to NULL",
6809 : : port_id);
6810 : 0 : return -EINVAL;
6811 : : }
6812 : :
6813 [ - + - - ]: 1 : if (info->names != NULL && info->length != 0)
6814 : 0 : memset(info->names, 0, sizeof(struct rte_eth_reg_name) * info->length);
6815 : :
6816 [ - + ]: 1 : if (dev->dev_ops->get_reg == NULL)
6817 : : return -ENOTSUP;
6818 : 0 : ret = eth_err(port_id, dev->dev_ops->get_reg(dev, info));
6819 : :
6820 : 0 : rte_ethdev_trace_get_reg_info(port_id, info, ret);
6821 : :
6822 : : /* Report the default names if drivers not report. */
6823 [ # # # # : 0 : if (ret == 0 && info->names != NULL && strlen(info->names[0].name) == 0) {
# # ]
6824 [ # # ]: 0 : for (i = 0; i < info->length; i++)
6825 : 0 : snprintf(info->names[i].name, RTE_ETH_REG_NAME_SIZE,
6826 : 0 : "index_%u", info->offset + i);
6827 : : }
6828 : : return ret;
6829 : : }
6830 : :
6831 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom_length)
6832 : : int
6833 : 0 : rte_eth_dev_get_eeprom_length(uint16_t port_id)
6834 : : {
6835 : : struct rte_eth_dev *dev;
6836 : : int ret;
6837 : :
6838 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6839 : 0 : dev = &rte_eth_devices[port_id];
6840 : :
6841 [ # # ]: 0 : if (dev->dev_ops->get_eeprom_length == NULL)
6842 : : return -ENOTSUP;
6843 : 0 : ret = eth_err(port_id, dev->dev_ops->get_eeprom_length(dev));
6844 : :
6845 : 0 : rte_ethdev_trace_get_eeprom_length(port_id, ret);
6846 : :
6847 : 0 : return ret;
6848 : : }
6849 : :
6850 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_eeprom)
6851 : : int
6852 : 0 : rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
6853 : : {
6854 : : struct rte_eth_dev *dev;
6855 : : int ret;
6856 : :
6857 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6858 : 0 : dev = &rte_eth_devices[port_id];
6859 : :
6860 [ # # ]: 0 : if (info == NULL) {
6861 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6862 : : "Cannot get ethdev port %u EEPROM info to NULL",
6863 : : port_id);
6864 : 0 : return -EINVAL;
6865 : : }
6866 : :
6867 [ # # ]: 0 : if (dev->dev_ops->get_eeprom == NULL)
6868 : : return -ENOTSUP;
6869 : 0 : ret = eth_err(port_id, dev->dev_ops->get_eeprom(dev, info));
6870 : :
6871 : 0 : rte_ethdev_trace_get_eeprom(port_id, info, ret);
6872 : :
6873 : 0 : return ret;
6874 : : }
6875 : :
6876 : : RTE_EXPORT_SYMBOL(rte_eth_dev_set_eeprom)
6877 : : int
6878 : 0 : rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info)
6879 : : {
6880 : : struct rte_eth_dev *dev;
6881 : : int ret;
6882 : :
6883 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6884 : 0 : dev = &rte_eth_devices[port_id];
6885 : :
6886 [ # # ]: 0 : if (info == NULL) {
6887 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6888 : : "Cannot set ethdev port %u EEPROM from NULL info",
6889 : : port_id);
6890 : 0 : return -EINVAL;
6891 : : }
6892 : :
6893 [ # # ]: 0 : if (dev->dev_ops->set_eeprom == NULL)
6894 : : return -ENOTSUP;
6895 : 0 : ret = eth_err(port_id, dev->dev_ops->set_eeprom(dev, info));
6896 : :
6897 : 0 : rte_ethdev_trace_set_eeprom(port_id, info, ret);
6898 : :
6899 : 0 : return ret;
6900 : : }
6901 : :
6902 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_module_info, 18.05)
6903 : : int
6904 : 1 : rte_eth_dev_get_module_info(uint16_t port_id,
6905 : : struct rte_eth_dev_module_info *modinfo)
6906 : : {
6907 : : struct rte_eth_dev *dev;
6908 : : int ret;
6909 : :
6910 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6911 : 1 : dev = &rte_eth_devices[port_id];
6912 : :
6913 [ - + ]: 1 : if (modinfo == NULL) {
6914 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6915 : : "Cannot get ethdev port %u EEPROM module info to NULL",
6916 : : port_id);
6917 : 0 : return -EINVAL;
6918 : : }
6919 : :
6920 [ - + ]: 1 : if (dev->dev_ops->get_module_info == NULL)
6921 : : return -ENOTSUP;
6922 : 0 : ret = dev->dev_ops->get_module_info(dev, modinfo);
6923 : :
6924 : 0 : rte_ethdev_trace_get_module_info(port_id, modinfo, ret);
6925 : :
6926 : 0 : return ret;
6927 : : }
6928 : :
6929 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_get_module_eeprom, 18.05)
6930 : : int
6931 : 0 : rte_eth_dev_get_module_eeprom(uint16_t port_id,
6932 : : struct rte_dev_eeprom_info *info)
6933 : : {
6934 : : struct rte_eth_dev *dev;
6935 : : int ret;
6936 : :
6937 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6938 : 0 : dev = &rte_eth_devices[port_id];
6939 : :
6940 [ # # ]: 0 : if (info == NULL) {
6941 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6942 : : "Cannot get ethdev port %u module EEPROM info to NULL",
6943 : : port_id);
6944 : 0 : return -EINVAL;
6945 : : }
6946 : :
6947 [ # # ]: 0 : if (info->data == NULL) {
6948 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6949 : : "Cannot get ethdev port %u module EEPROM data to NULL",
6950 : : port_id);
6951 : 0 : return -EINVAL;
6952 : : }
6953 : :
6954 [ # # ]: 0 : if (info->length == 0) {
6955 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6956 : : "Cannot get ethdev port %u module EEPROM to data with zero size",
6957 : : port_id);
6958 : 0 : return -EINVAL;
6959 : : }
6960 : :
6961 [ # # ]: 0 : if (dev->dev_ops->get_module_eeprom == NULL)
6962 : : return -ENOTSUP;
6963 : 0 : ret = dev->dev_ops->get_module_eeprom(dev, info);
6964 : :
6965 : 0 : rte_ethdev_trace_get_module_eeprom(port_id, info, ret);
6966 : :
6967 : 0 : return ret;
6968 : : }
6969 : :
6970 : : RTE_EXPORT_SYMBOL(rte_eth_dev_get_dcb_info)
6971 : : int
6972 : 1 : rte_eth_dev_get_dcb_info(uint16_t port_id,
6973 : : struct rte_eth_dcb_info *dcb_info)
6974 : : {
6975 : : struct rte_eth_dev *dev;
6976 : : int ret;
6977 : :
6978 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
6979 : 1 : dev = &rte_eth_devices[port_id];
6980 : :
6981 [ - + ]: 1 : if (dcb_info == NULL) {
6982 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
6983 : : "Cannot get ethdev port %u DCB info to NULL",
6984 : : port_id);
6985 : 0 : return -EINVAL;
6986 : : }
6987 : :
6988 : : memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info));
6989 : :
6990 [ - + ]: 1 : if (dev->dev_ops->get_dcb_info == NULL)
6991 : : return -ENOTSUP;
6992 : 0 : ret = eth_err(port_id, dev->dev_ops->get_dcb_info(dev, dcb_info));
6993 : :
6994 : 0 : rte_ethdev_trace_get_dcb_info(port_id, dcb_info, ret);
6995 : :
6996 : 0 : return ret;
6997 : : }
6998 : :
6999 : : static void
7000 : : eth_dev_adjust_nb_desc(uint16_t *nb_desc,
7001 : : const struct rte_eth_desc_lim *desc_lim)
7002 : : {
7003 : : /* Upcast to uint32 to avoid potential overflow with RTE_ALIGN_CEIL(). */
7004 : 0 : uint32_t nb_desc_32 = (uint32_t)*nb_desc;
7005 : :
7006 [ # # # # ]: 0 : if (desc_lim->nb_align != 0)
7007 : 0 : nb_desc_32 = RTE_ALIGN_CEIL(nb_desc_32, desc_lim->nb_align);
7008 : :
7009 [ # # # # ]: 0 : if (desc_lim->nb_max != 0)
7010 : 0 : nb_desc_32 = RTE_MIN(nb_desc_32, desc_lim->nb_max);
7011 : :
7012 : 0 : nb_desc_32 = RTE_MAX(nb_desc_32, desc_lim->nb_min);
7013 : :
7014 : : /* Assign clipped u32 back to u16. */
7015 : 0 : *nb_desc = (uint16_t)nb_desc_32;
7016 : 0 : }
7017 : :
7018 : : RTE_EXPORT_SYMBOL(rte_eth_dev_adjust_nb_rx_tx_desc)
7019 : : int
7020 : 0 : rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id,
7021 : : uint16_t *nb_rx_desc,
7022 : : uint16_t *nb_tx_desc)
7023 : : {
7024 : : struct rte_eth_dev_info dev_info;
7025 : : int ret;
7026 : :
7027 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7028 : :
7029 : 0 : ret = rte_eth_dev_info_get(port_id, &dev_info);
7030 [ # # ]: 0 : if (ret != 0)
7031 : : return ret;
7032 : :
7033 [ # # ]: 0 : if (nb_rx_desc != NULL)
7034 : : eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim);
7035 : :
7036 [ # # ]: 0 : if (nb_tx_desc != NULL)
7037 : : eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim);
7038 : :
7039 : 0 : rte_ethdev_trace_adjust_nb_rx_tx_desc(port_id);
7040 : :
7041 : 0 : return 0;
7042 : : }
7043 : :
7044 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_hairpin_capability_get, 19.11)
7045 : : int
7046 : 0 : rte_eth_dev_hairpin_capability_get(uint16_t port_id,
7047 : : struct rte_eth_hairpin_cap *cap)
7048 : : {
7049 : : struct rte_eth_dev *dev;
7050 : : int ret;
7051 : :
7052 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7053 : 0 : dev = &rte_eth_devices[port_id];
7054 : :
7055 [ # # ]: 0 : if (cap == NULL) {
7056 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7057 : : "Cannot get ethdev port %u hairpin capability to NULL",
7058 : : port_id);
7059 : 0 : return -EINVAL;
7060 : : }
7061 : :
7062 [ # # ]: 0 : if (dev->dev_ops->hairpin_cap_get == NULL)
7063 : : return -ENOTSUP;
7064 : : memset(cap, 0, sizeof(*cap));
7065 : 0 : ret = eth_err(port_id, dev->dev_ops->hairpin_cap_get(dev, cap));
7066 : :
7067 : 0 : rte_ethdev_trace_hairpin_capability_get(port_id, cap, ret);
7068 : :
7069 : 0 : return ret;
7070 : : }
7071 : :
7072 : : RTE_EXPORT_SYMBOL(rte_eth_dev_pool_ops_supported)
7073 : : int
7074 : 0 : rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool)
7075 : : {
7076 : : struct rte_eth_dev *dev;
7077 : : int ret;
7078 : :
7079 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7080 : 0 : dev = &rte_eth_devices[port_id];
7081 : :
7082 [ # # ]: 0 : if (pool == NULL) {
7083 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7084 : : "Cannot test ethdev port %u mempool operation from NULL pool",
7085 : : port_id);
7086 : 0 : return -EINVAL;
7087 : : }
7088 : :
7089 [ # # ]: 0 : if (dev->dev_ops->pool_ops_supported == NULL)
7090 : : return 1; /* all pools are supported */
7091 : :
7092 : 0 : ret = dev->dev_ops->pool_ops_supported(dev, pool);
7093 : :
7094 : 0 : rte_ethdev_trace_pool_ops_supported(port_id, pool, ret);
7095 : :
7096 : 0 : return ret;
7097 : : }
7098 : :
7099 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_representor_info_get, 21.05)
7100 : : int
7101 : 0 : rte_eth_representor_info_get(uint16_t port_id,
7102 : : struct rte_eth_representor_info *info)
7103 : : {
7104 : : struct rte_eth_dev *dev;
7105 : : int ret;
7106 : :
7107 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7108 : 0 : dev = &rte_eth_devices[port_id];
7109 : :
7110 [ # # ]: 0 : if (dev->dev_ops->representor_info_get == NULL)
7111 : : return -ENOTSUP;
7112 : 0 : ret = eth_err(port_id, dev->dev_ops->representor_info_get(dev, info));
7113 : :
7114 : 0 : rte_eth_trace_representor_info_get(port_id, info, ret);
7115 : :
7116 : 0 : return ret;
7117 : : }
7118 : :
7119 : : RTE_EXPORT_SYMBOL(rte_eth_rx_metadata_negotiate)
7120 : : int
7121 : 0 : rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features)
7122 : : {
7123 : : struct rte_eth_dev *dev;
7124 : : int ret;
7125 : :
7126 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7127 : 0 : dev = &rte_eth_devices[port_id];
7128 : :
7129 [ # # ]: 0 : if (dev->data->dev_configured != 0) {
7130 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7131 : : "The port (ID=%"PRIu16") is already configured",
7132 : : port_id);
7133 : 0 : return -EBUSY;
7134 : : }
7135 : :
7136 [ # # ]: 0 : if (features == NULL) {
7137 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid features (NULL)");
7138 : 0 : return -EINVAL;
7139 : : }
7140 : :
7141 [ # # # # ]: 0 : if ((*features & RTE_ETH_RX_METADATA_TUNNEL_ID) != 0 &&
7142 : 0 : rte_flow_restore_info_dynflag_register() < 0)
7143 : 0 : *features &= ~RTE_ETH_RX_METADATA_TUNNEL_ID;
7144 : :
7145 [ # # ]: 0 : if (dev->dev_ops->rx_metadata_negotiate == NULL)
7146 : : return -ENOTSUP;
7147 : 0 : ret = eth_err(port_id,
7148 : : dev->dev_ops->rx_metadata_negotiate(dev, features));
7149 : :
7150 [ # # ]: 0 : rte_eth_trace_rx_metadata_negotiate(port_id, *features, ret);
7151 : :
7152 : 0 : return ret;
7153 : : }
7154 : :
7155 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_capability_get, 22.03)
7156 : : int
7157 : 0 : rte_eth_ip_reassembly_capability_get(uint16_t port_id,
7158 : : struct rte_eth_ip_reassembly_params *reassembly_capa)
7159 : : {
7160 : : struct rte_eth_dev *dev;
7161 : : int ret;
7162 : :
7163 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7164 : 0 : dev = &rte_eth_devices[port_id];
7165 : :
7166 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7167 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7168 : : "port_id=%u is not configured, cannot get IP reassembly capability",
7169 : : port_id);
7170 : 0 : return -EINVAL;
7171 : : }
7172 : :
7173 [ # # ]: 0 : if (reassembly_capa == NULL) {
7174 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly capability to NULL");
7175 : 0 : return -EINVAL;
7176 : : }
7177 : :
7178 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_capability_get == NULL)
7179 : : return -ENOTSUP;
7180 : : memset(reassembly_capa, 0, sizeof(struct rte_eth_ip_reassembly_params));
7181 : :
7182 : 0 : ret = eth_err(port_id,
7183 : 0 : dev->dev_ops->ip_reassembly_capability_get(dev, reassembly_capa));
7184 : :
7185 : 0 : rte_eth_trace_ip_reassembly_capability_get(port_id, reassembly_capa,
7186 : : ret);
7187 : :
7188 : 0 : return ret;
7189 : : }
7190 : :
7191 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_conf_get, 22.03)
7192 : : int
7193 : 0 : rte_eth_ip_reassembly_conf_get(uint16_t port_id,
7194 : : struct rte_eth_ip_reassembly_params *conf)
7195 : : {
7196 : : struct rte_eth_dev *dev;
7197 : : int ret;
7198 : :
7199 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7200 : 0 : dev = &rte_eth_devices[port_id];
7201 : :
7202 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7203 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7204 : : "port_id=%u is not configured, cannot get IP reassembly configuration",
7205 : : port_id);
7206 : 0 : return -EINVAL;
7207 : : }
7208 : :
7209 [ # # ]: 0 : if (conf == NULL) {
7210 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Cannot get reassembly info to NULL");
7211 : 0 : return -EINVAL;
7212 : : }
7213 : :
7214 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_conf_get == NULL)
7215 : : return -ENOTSUP;
7216 : : memset(conf, 0, sizeof(struct rte_eth_ip_reassembly_params));
7217 : 0 : ret = eth_err(port_id,
7218 : 0 : dev->dev_ops->ip_reassembly_conf_get(dev, conf));
7219 : :
7220 : 0 : rte_eth_trace_ip_reassembly_conf_get(port_id, conf, ret);
7221 : :
7222 : 0 : return ret;
7223 : : }
7224 : :
7225 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_ip_reassembly_conf_set, 22.03)
7226 : : int
7227 : 0 : rte_eth_ip_reassembly_conf_set(uint16_t port_id,
7228 : : const struct rte_eth_ip_reassembly_params *conf)
7229 : : {
7230 : : struct rte_eth_dev *dev;
7231 : : int ret;
7232 : :
7233 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7234 : 0 : dev = &rte_eth_devices[port_id];
7235 : :
7236 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7237 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7238 : : "port_id=%u is not configured, cannot set IP reassembly configuration",
7239 : : port_id);
7240 : 0 : return -EINVAL;
7241 : : }
7242 : :
7243 [ # # ]: 0 : if (dev->data->dev_started != 0) {
7244 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7245 : : "port_id=%u is started, cannot configure IP reassembly params.",
7246 : : port_id);
7247 : 0 : return -EINVAL;
7248 : : }
7249 : :
7250 [ # # ]: 0 : if (conf == NULL) {
7251 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7252 : : "Invalid IP reassembly configuration (NULL)");
7253 : 0 : return -EINVAL;
7254 : : }
7255 : :
7256 [ # # ]: 0 : if (dev->dev_ops->ip_reassembly_conf_set == NULL)
7257 : : return -ENOTSUP;
7258 : 0 : ret = eth_err(port_id,
7259 : : dev->dev_ops->ip_reassembly_conf_set(dev, conf));
7260 : :
7261 : 0 : rte_eth_trace_ip_reassembly_conf_set(port_id, conf, ret);
7262 : :
7263 : 0 : return ret;
7264 : : }
7265 : :
7266 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_priv_dump, 22.03)
7267 : : int
7268 : 1 : rte_eth_dev_priv_dump(uint16_t port_id, FILE *file)
7269 : : {
7270 : : struct rte_eth_dev *dev;
7271 : :
7272 [ - + ]: 1 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7273 : 1 : dev = &rte_eth_devices[port_id];
7274 : :
7275 [ - + ]: 1 : if (file == NULL) {
7276 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7277 : 0 : return -EINVAL;
7278 : : }
7279 : :
7280 [ - + ]: 1 : if (dev->dev_ops->eth_dev_priv_dump == NULL)
7281 : : return -ENOTSUP;
7282 : 0 : return eth_err(port_id, dev->dev_ops->eth_dev_priv_dump(dev, file));
7283 : : }
7284 : :
7285 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_rx_descriptor_dump, 22.11)
7286 : : int
7287 : 0 : rte_eth_rx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
7288 : : uint16_t offset, uint16_t num, FILE *file)
7289 : : {
7290 : : struct rte_eth_dev *dev;
7291 : :
7292 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7293 : 0 : dev = &rte_eth_devices[port_id];
7294 : :
7295 [ # # ]: 0 : if (queue_id >= dev->data->nb_rx_queues) {
7296 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Rx queue_id=%u", queue_id);
7297 : 0 : return -EINVAL;
7298 : : }
7299 : :
7300 [ # # ]: 0 : if (file == NULL) {
7301 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7302 : 0 : return -EINVAL;
7303 : : }
7304 : :
7305 [ # # ]: 0 : if (dev->dev_ops->eth_rx_descriptor_dump == NULL)
7306 : : return -ENOTSUP;
7307 : :
7308 : 0 : return eth_err(port_id,
7309 : : dev->dev_ops->eth_rx_descriptor_dump(dev, queue_id, offset, num, file));
7310 : : }
7311 : :
7312 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_tx_descriptor_dump, 22.11)
7313 : : int
7314 : 0 : rte_eth_tx_descriptor_dump(uint16_t port_id, uint16_t queue_id,
7315 : : uint16_t offset, uint16_t num, FILE *file)
7316 : : {
7317 : : struct rte_eth_dev *dev;
7318 : :
7319 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7320 : 0 : dev = &rte_eth_devices[port_id];
7321 : :
7322 [ # # ]: 0 : if (queue_id >= dev->data->nb_tx_queues) {
7323 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", queue_id);
7324 : 0 : return -EINVAL;
7325 : : }
7326 : :
7327 [ # # ]: 0 : if (file == NULL) {
7328 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid file (NULL)");
7329 : 0 : return -EINVAL;
7330 : : }
7331 : :
7332 [ # # ]: 0 : if (dev->dev_ops->eth_tx_descriptor_dump == NULL)
7333 : : return -ENOTSUP;
7334 : :
7335 : 0 : return eth_err(port_id,
7336 : : dev->dev_ops->eth_tx_descriptor_dump(dev, queue_id, offset, num, file));
7337 : : }
7338 : :
7339 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_buffer_split_get_supported_hdr_ptypes, 22.11)
7340 : : int
7341 : 0 : rte_eth_buffer_split_get_supported_hdr_ptypes(uint16_t port_id, uint32_t *ptypes, int num)
7342 : : {
7343 : : size_t i;
7344 : : int j;
7345 : : struct rte_eth_dev *dev;
7346 : : const uint32_t *all_types;
7347 : 0 : size_t no_of_elements = 0;
7348 : :
7349 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7350 : 0 : dev = &rte_eth_devices[port_id];
7351 : :
7352 [ # # ]: 0 : if (ptypes == NULL && num > 0) {
7353 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7354 : : "Cannot get ethdev port %u supported header protocol types to NULL when array size is non zero",
7355 : : port_id);
7356 : 0 : return -EINVAL;
7357 : : }
7358 : :
7359 [ # # ]: 0 : if (dev->dev_ops->buffer_split_supported_hdr_ptypes_get == NULL)
7360 : : return -ENOTSUP;
7361 : 0 : all_types = dev->dev_ops->buffer_split_supported_hdr_ptypes_get(dev, &no_of_elements);
7362 : :
7363 [ # # ]: 0 : if (all_types == NULL)
7364 : : return 0;
7365 : :
7366 [ # # ]: 0 : for (i = 0, j = 0; i < no_of_elements; ++i) {
7367 [ # # ]: 0 : if (j < num) {
7368 [ # # ]: 0 : ptypes[j] = all_types[i];
7369 : :
7370 : 0 : rte_eth_trace_buffer_split_get_supported_hdr_ptypes(
7371 : : port_id, j, ptypes[j]);
7372 : : }
7373 : 0 : j++;
7374 : : }
7375 : :
7376 : : return j;
7377 : : }
7378 : :
7379 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_count_aggr_ports, 23.03)
7380 : 0 : int rte_eth_dev_count_aggr_ports(uint16_t port_id)
7381 : : {
7382 : : struct rte_eth_dev *dev;
7383 : : int ret;
7384 : :
7385 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7386 : 0 : dev = &rte_eth_devices[port_id];
7387 : :
7388 [ # # ]: 0 : if (dev->dev_ops->count_aggr_ports == NULL)
7389 : : return 0;
7390 : 0 : ret = eth_err(port_id, dev->dev_ops->count_aggr_ports(dev));
7391 : :
7392 : 0 : rte_eth_trace_count_aggr_ports(port_id, ret);
7393 : :
7394 : 0 : return ret;
7395 : : }
7396 : :
7397 : : RTE_EXPORT_EXPERIMENTAL_SYMBOL(rte_eth_dev_map_aggr_tx_affinity, 23.03)
7398 : 0 : int rte_eth_dev_map_aggr_tx_affinity(uint16_t port_id, uint16_t tx_queue_id,
7399 : : uint8_t affinity)
7400 : : {
7401 : : struct rte_eth_dev *dev;
7402 : : int aggr_ports;
7403 : : int ret;
7404 : :
7405 [ # # ]: 0 : RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
7406 : 0 : dev = &rte_eth_devices[port_id];
7407 : :
7408 [ # # ]: 0 : if (tx_queue_id >= dev->data->nb_tx_queues) {
7409 : 0 : RTE_ETHDEV_LOG_LINE(ERR, "Invalid Tx queue_id=%u", tx_queue_id);
7410 : 0 : return -EINVAL;
7411 : : }
7412 : :
7413 [ # # ]: 0 : if (dev->dev_ops->map_aggr_tx_affinity == NULL)
7414 : : return -ENOTSUP;
7415 : :
7416 [ # # ]: 0 : if (dev->data->dev_configured == 0) {
7417 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7418 : : "Port %u must be configured before Tx affinity mapping",
7419 : : port_id);
7420 : 0 : return -EINVAL;
7421 : : }
7422 : :
7423 [ # # ]: 0 : if (dev->data->dev_started) {
7424 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7425 : : "Port %u must be stopped to allow configuration",
7426 : : port_id);
7427 : 0 : return -EBUSY;
7428 : : }
7429 : :
7430 : 0 : aggr_ports = rte_eth_dev_count_aggr_ports(port_id);
7431 [ # # ]: 0 : if (aggr_ports == 0) {
7432 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7433 : : "Port %u has no aggregated port",
7434 : : port_id);
7435 : 0 : return -ENOTSUP;
7436 : : }
7437 : :
7438 [ # # ]: 0 : if (affinity > aggr_ports) {
7439 : 0 : RTE_ETHDEV_LOG_LINE(ERR,
7440 : : "Port %u map invalid affinity %u exceeds the maximum number %u",
7441 : : port_id, affinity, aggr_ports);
7442 : 0 : return -EINVAL;
7443 : : }
7444 : :
7445 : 0 : ret = eth_err(port_id,
7446 : 0 : dev->dev_ops->map_aggr_tx_affinity(dev, tx_queue_id, affinity));
7447 : :
7448 : 0 : rte_eth_trace_map_aggr_tx_affinity(port_id, tx_queue_id, affinity, ret);
7449 : :
7450 : 0 : return ret;
7451 : : }
7452 : :
7453 : : RTE_EXPORT_SYMBOL(rte_eth_dev_logtype)
7454 [ - + ]: 253 : RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO);
|