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