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