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