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