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