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