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