199a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause 299a2dd95SBruce Richardson * Copyright(c) 2010-2017 Intel Corporation 399a2dd95SBruce Richardson */ 499a2dd95SBruce Richardson 599a2dd95SBruce Richardson #include <ctype.h> 699a2dd95SBruce Richardson #include <errno.h> 799a2dd95SBruce Richardson #include <inttypes.h> 899a2dd95SBruce Richardson #include <stdbool.h> 999a2dd95SBruce Richardson #include <stdint.h> 1099a2dd95SBruce Richardson #include <stdlib.h> 1199a2dd95SBruce Richardson #include <string.h> 1299a2dd95SBruce Richardson #include <sys/queue.h> 1399a2dd95SBruce Richardson 1499a2dd95SBruce Richardson #include <rte_byteorder.h> 1599a2dd95SBruce Richardson #include <rte_log.h> 1699a2dd95SBruce Richardson #include <rte_debug.h> 1799a2dd95SBruce Richardson #include <rte_interrupts.h> 1899a2dd95SBruce Richardson #include <rte_memory.h> 1999a2dd95SBruce Richardson #include <rte_memcpy.h> 2099a2dd95SBruce Richardson #include <rte_memzone.h> 2199a2dd95SBruce Richardson #include <rte_launch.h> 2299a2dd95SBruce Richardson #include <rte_eal.h> 2399a2dd95SBruce Richardson #include <rte_per_lcore.h> 2499a2dd95SBruce Richardson #include <rte_lcore.h> 2599a2dd95SBruce Richardson #include <rte_branch_prediction.h> 2699a2dd95SBruce Richardson #include <rte_common.h> 2799a2dd95SBruce Richardson #include <rte_mempool.h> 2899a2dd95SBruce Richardson #include <rte_malloc.h> 2999a2dd95SBruce Richardson #include <rte_mbuf.h> 3099a2dd95SBruce Richardson #include <rte_errno.h> 3199a2dd95SBruce Richardson #include <rte_spinlock.h> 3299a2dd95SBruce Richardson #include <rte_string_fns.h> 3399a2dd95SBruce Richardson #include <rte_kvargs.h> 3499a2dd95SBruce Richardson #include <rte_class.h> 3599a2dd95SBruce Richardson #include <rte_ether.h> 3699a2dd95SBruce Richardson #include <rte_telemetry.h> 3799a2dd95SBruce Richardson 3899a2dd95SBruce Richardson #include "rte_ethdev_trace.h" 3999a2dd95SBruce Richardson #include "rte_ethdev.h" 4099a2dd95SBruce Richardson #include "ethdev_driver.h" 4199a2dd95SBruce Richardson #include "ethdev_profile.h" 4299a2dd95SBruce Richardson #include "ethdev_private.h" 4399a2dd95SBruce Richardson 4499a2dd95SBruce Richardson static const char *MZ_RTE_ETH_DEV_DATA = "rte_eth_dev_data"; 4599a2dd95SBruce Richardson struct rte_eth_dev rte_eth_devices[RTE_MAX_ETHPORTS]; 4699a2dd95SBruce Richardson 47c87d435aSKonstantin Ananyev /* public fast-path API */ 48c87d435aSKonstantin Ananyev struct rte_eth_fp_ops rte_eth_fp_ops[RTE_MAX_ETHPORTS]; 49c87d435aSKonstantin Ananyev 5099a2dd95SBruce Richardson /* spinlock for eth device callbacks */ 5199a2dd95SBruce Richardson static rte_spinlock_t eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER; 5299a2dd95SBruce Richardson 5399a2dd95SBruce Richardson /* spinlock for add/remove rx callbacks */ 5499a2dd95SBruce Richardson static rte_spinlock_t eth_dev_rx_cb_lock = RTE_SPINLOCK_INITIALIZER; 5599a2dd95SBruce Richardson 5699a2dd95SBruce Richardson /* spinlock for add/remove tx callbacks */ 5799a2dd95SBruce Richardson static rte_spinlock_t eth_dev_tx_cb_lock = RTE_SPINLOCK_INITIALIZER; 5899a2dd95SBruce Richardson 5999a2dd95SBruce Richardson /* spinlock for shared data allocation */ 6099a2dd95SBruce Richardson static rte_spinlock_t eth_dev_shared_data_lock = RTE_SPINLOCK_INITIALIZER; 6199a2dd95SBruce Richardson 6299a2dd95SBruce Richardson /* store statistics names and its offset in stats structure */ 6399a2dd95SBruce Richardson struct rte_eth_xstats_name_off { 6499a2dd95SBruce Richardson char name[RTE_ETH_XSTATS_NAME_SIZE]; 6599a2dd95SBruce Richardson unsigned offset; 6699a2dd95SBruce Richardson }; 6799a2dd95SBruce Richardson 6899a2dd95SBruce Richardson /* Shared memory between primary and secondary processes. */ 6999a2dd95SBruce Richardson static struct { 7099a2dd95SBruce Richardson uint64_t next_owner_id; 7199a2dd95SBruce Richardson rte_spinlock_t ownership_lock; 7299a2dd95SBruce Richardson struct rte_eth_dev_data data[RTE_MAX_ETHPORTS]; 7399a2dd95SBruce Richardson } *eth_dev_shared_data; 7499a2dd95SBruce Richardson 7599a2dd95SBruce Richardson static const struct rte_eth_xstats_name_off eth_dev_stats_strings[] = { 7699a2dd95SBruce Richardson {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)}, 7799a2dd95SBruce Richardson {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)}, 7899a2dd95SBruce Richardson {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)}, 7999a2dd95SBruce Richardson {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)}, 8099a2dd95SBruce Richardson {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)}, 8199a2dd95SBruce Richardson {"rx_errors", offsetof(struct rte_eth_stats, ierrors)}, 8299a2dd95SBruce Richardson {"tx_errors", offsetof(struct rte_eth_stats, oerrors)}, 8399a2dd95SBruce Richardson {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats, 8499a2dd95SBruce Richardson rx_nombuf)}, 8599a2dd95SBruce Richardson }; 8699a2dd95SBruce Richardson 8799a2dd95SBruce Richardson #define RTE_NB_STATS RTE_DIM(eth_dev_stats_strings) 8899a2dd95SBruce Richardson 8999a2dd95SBruce Richardson static const struct rte_eth_xstats_name_off eth_dev_rxq_stats_strings[] = { 9099a2dd95SBruce Richardson {"packets", offsetof(struct rte_eth_stats, q_ipackets)}, 9199a2dd95SBruce Richardson {"bytes", offsetof(struct rte_eth_stats, q_ibytes)}, 9299a2dd95SBruce Richardson {"errors", offsetof(struct rte_eth_stats, q_errors)}, 9399a2dd95SBruce Richardson }; 9499a2dd95SBruce Richardson 9599a2dd95SBruce Richardson #define RTE_NB_RXQ_STATS RTE_DIM(eth_dev_rxq_stats_strings) 9699a2dd95SBruce Richardson 9799a2dd95SBruce Richardson static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = { 9899a2dd95SBruce Richardson {"packets", offsetof(struct rte_eth_stats, q_opackets)}, 9999a2dd95SBruce Richardson {"bytes", offsetof(struct rte_eth_stats, q_obytes)}, 10099a2dd95SBruce Richardson }; 10199a2dd95SBruce Richardson #define RTE_NB_TXQ_STATS RTE_DIM(eth_dev_txq_stats_strings) 10299a2dd95SBruce Richardson 10399a2dd95SBruce Richardson #define RTE_RX_OFFLOAD_BIT2STR(_name) \ 10499a2dd95SBruce Richardson { DEV_RX_OFFLOAD_##_name, #_name } 10599a2dd95SBruce Richardson 10699a2dd95SBruce Richardson #define RTE_ETH_RX_OFFLOAD_BIT2STR(_name) \ 10799a2dd95SBruce Richardson { RTE_ETH_RX_OFFLOAD_##_name, #_name } 10899a2dd95SBruce Richardson 10999a2dd95SBruce Richardson static const struct { 11099a2dd95SBruce Richardson uint64_t offload; 11199a2dd95SBruce Richardson const char *name; 11299a2dd95SBruce Richardson } eth_dev_rx_offload_names[] = { 11399a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP), 11499a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM), 11599a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM), 11699a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM), 11799a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(TCP_LRO), 11899a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP), 11999a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM), 12099a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP), 12199a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(HEADER_SPLIT), 12299a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER), 12399a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND), 12499a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(SCATTER), 12599a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP), 12699a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(SECURITY), 12799a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC), 12899a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM), 12999a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM), 13099a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(RSS_HASH), 13199a2dd95SBruce Richardson RTE_ETH_RX_OFFLOAD_BIT2STR(BUFFER_SPLIT), 13299a2dd95SBruce Richardson }; 13399a2dd95SBruce Richardson 13499a2dd95SBruce Richardson #undef RTE_RX_OFFLOAD_BIT2STR 13599a2dd95SBruce Richardson #undef RTE_ETH_RX_OFFLOAD_BIT2STR 13699a2dd95SBruce Richardson 13799a2dd95SBruce Richardson #define RTE_TX_OFFLOAD_BIT2STR(_name) \ 13899a2dd95SBruce Richardson { DEV_TX_OFFLOAD_##_name, #_name } 13999a2dd95SBruce Richardson 14099a2dd95SBruce Richardson static const struct { 14199a2dd95SBruce Richardson uint64_t offload; 14299a2dd95SBruce Richardson const char *name; 14399a2dd95SBruce Richardson } eth_dev_tx_offload_names[] = { 14499a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT), 14599a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM), 14699a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM), 14799a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM), 14899a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM), 14999a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(TCP_TSO), 15099a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(UDP_TSO), 15199a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM), 15299a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT), 15399a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO), 15499a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO), 15599a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO), 15699a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO), 15799a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT), 15899a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE), 15999a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS), 16099a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE), 16199a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(SECURITY), 16299a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO), 16399a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO), 16499a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM), 16599a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(SEND_ON_TIMESTAMP), 16699a2dd95SBruce Richardson }; 16799a2dd95SBruce Richardson 16899a2dd95SBruce Richardson #undef RTE_TX_OFFLOAD_BIT2STR 16999a2dd95SBruce Richardson 17099a2dd95SBruce Richardson /** 17199a2dd95SBruce Richardson * The user application callback description. 17299a2dd95SBruce Richardson * 17399a2dd95SBruce Richardson * It contains callback address to be registered by user application, 17499a2dd95SBruce Richardson * the pointer to the parameters for callback, and the event type. 17599a2dd95SBruce Richardson */ 17699a2dd95SBruce Richardson struct rte_eth_dev_callback { 17799a2dd95SBruce Richardson TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */ 17899a2dd95SBruce Richardson rte_eth_dev_cb_fn cb_fn; /**< Callback address */ 17999a2dd95SBruce Richardson void *cb_arg; /**< Parameter for callback */ 18099a2dd95SBruce Richardson void *ret_param; /**< Return parameter */ 18199a2dd95SBruce Richardson enum rte_eth_event_type event; /**< Interrupt event type */ 18299a2dd95SBruce Richardson uint32_t active; /**< Callback is executing */ 18399a2dd95SBruce Richardson }; 18499a2dd95SBruce Richardson 18599a2dd95SBruce Richardson enum { 18699a2dd95SBruce Richardson STAT_QMAP_TX = 0, 18799a2dd95SBruce Richardson STAT_QMAP_RX 18899a2dd95SBruce Richardson }; 18999a2dd95SBruce Richardson 19099a2dd95SBruce Richardson int 19199a2dd95SBruce Richardson rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) 19299a2dd95SBruce Richardson { 19399a2dd95SBruce Richardson int ret; 19499a2dd95SBruce Richardson struct rte_devargs devargs; 19599a2dd95SBruce Richardson const char *bus_param_key; 19699a2dd95SBruce Richardson char *bus_str = NULL; 19799a2dd95SBruce Richardson char *cls_str = NULL; 19899a2dd95SBruce Richardson int str_size; 19999a2dd95SBruce Richardson 20053ef1b34SMin Hu (Connor) if (iter == NULL) { 20153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot initialize NULL iterator\n"); 20253ef1b34SMin Hu (Connor) return -EINVAL; 20353ef1b34SMin Hu (Connor) } 20453ef1b34SMin Hu (Connor) 20553ef1b34SMin Hu (Connor) if (devargs_str == NULL) { 20653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 20753ef1b34SMin Hu (Connor) "Cannot initialize iterator from NULL device description string\n"); 20853ef1b34SMin Hu (Connor) return -EINVAL; 20953ef1b34SMin Hu (Connor) } 21053ef1b34SMin Hu (Connor) 21199a2dd95SBruce Richardson memset(iter, 0, sizeof(*iter)); 21299a2dd95SBruce Richardson memset(&devargs, 0, sizeof(devargs)); 21399a2dd95SBruce Richardson 21499a2dd95SBruce Richardson /* 21599a2dd95SBruce Richardson * The devargs string may use various syntaxes: 21699a2dd95SBruce Richardson * - 0000:08:00.0,representor=[1-3] 21799a2dd95SBruce Richardson * - pci:0000:06:00.0,representor=[0,5] 21899a2dd95SBruce Richardson * - class=eth,mac=00:11:22:33:44:55 21999a2dd95SBruce Richardson * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z 22099a2dd95SBruce Richardson */ 22199a2dd95SBruce Richardson 22299a2dd95SBruce Richardson /* 22399a2dd95SBruce Richardson * Handle pure class filter (i.e. without any bus-level argument), 22499a2dd95SBruce Richardson * from future new syntax. 22599a2dd95SBruce Richardson * rte_devargs_parse() is not yet supporting the new syntax, 22699a2dd95SBruce Richardson * that's why this simple case is temporarily parsed here. 22799a2dd95SBruce Richardson */ 22899a2dd95SBruce Richardson #define iter_anybus_str "class=eth," 22999a2dd95SBruce Richardson if (strncmp(devargs_str, iter_anybus_str, 23099a2dd95SBruce Richardson strlen(iter_anybus_str)) == 0) { 23199a2dd95SBruce Richardson iter->cls_str = devargs_str + strlen(iter_anybus_str); 23299a2dd95SBruce Richardson goto end; 23399a2dd95SBruce Richardson } 23499a2dd95SBruce Richardson 23599a2dd95SBruce Richardson /* Split bus, device and parameters. */ 23699a2dd95SBruce Richardson ret = rte_devargs_parse(&devargs, devargs_str); 23799a2dd95SBruce Richardson if (ret != 0) 23899a2dd95SBruce Richardson goto error; 23999a2dd95SBruce Richardson 24099a2dd95SBruce Richardson /* 24199a2dd95SBruce Richardson * Assume parameters of old syntax can match only at ethdev level. 24299a2dd95SBruce Richardson * Extra parameters will be ignored, thanks to "+" prefix. 24399a2dd95SBruce Richardson */ 24499a2dd95SBruce Richardson str_size = strlen(devargs.args) + 2; 24599a2dd95SBruce Richardson cls_str = malloc(str_size); 24699a2dd95SBruce Richardson if (cls_str == NULL) { 24799a2dd95SBruce Richardson ret = -ENOMEM; 24899a2dd95SBruce Richardson goto error; 24999a2dd95SBruce Richardson } 25099a2dd95SBruce Richardson ret = snprintf(cls_str, str_size, "+%s", devargs.args); 25199a2dd95SBruce Richardson if (ret != str_size - 1) { 25299a2dd95SBruce Richardson ret = -EINVAL; 25399a2dd95SBruce Richardson goto error; 25499a2dd95SBruce Richardson } 25599a2dd95SBruce Richardson iter->cls_str = cls_str; 25699a2dd95SBruce Richardson 25799a2dd95SBruce Richardson iter->bus = devargs.bus; 25899a2dd95SBruce Richardson if (iter->bus->dev_iterate == NULL) { 25999a2dd95SBruce Richardson ret = -ENOTSUP; 26099a2dd95SBruce Richardson goto error; 26199a2dd95SBruce Richardson } 26299a2dd95SBruce Richardson 26399a2dd95SBruce Richardson /* Convert bus args to new syntax for use with new API dev_iterate. */ 264a956adb2SHemant Agrawal if ((strcmp(iter->bus->name, "vdev") == 0) || 265a956adb2SHemant Agrawal (strcmp(iter->bus->name, "fslmc") == 0) || 266a956adb2SHemant Agrawal (strcmp(iter->bus->name, "dpaa_bus") == 0)) { 26799a2dd95SBruce Richardson bus_param_key = "name"; 26899a2dd95SBruce Richardson } else if (strcmp(iter->bus->name, "pci") == 0) { 26999a2dd95SBruce Richardson bus_param_key = "addr"; 27099a2dd95SBruce Richardson } else { 27199a2dd95SBruce Richardson ret = -ENOTSUP; 27299a2dd95SBruce Richardson goto error; 27399a2dd95SBruce Richardson } 27499a2dd95SBruce Richardson str_size = strlen(bus_param_key) + strlen(devargs.name) + 2; 27599a2dd95SBruce Richardson bus_str = malloc(str_size); 27699a2dd95SBruce Richardson if (bus_str == NULL) { 27799a2dd95SBruce Richardson ret = -ENOMEM; 27899a2dd95SBruce Richardson goto error; 27999a2dd95SBruce Richardson } 28099a2dd95SBruce Richardson ret = snprintf(bus_str, str_size, "%s=%s", 28199a2dd95SBruce Richardson bus_param_key, devargs.name); 28299a2dd95SBruce Richardson if (ret != str_size - 1) { 28399a2dd95SBruce Richardson ret = -EINVAL; 28499a2dd95SBruce Richardson goto error; 28599a2dd95SBruce Richardson } 28699a2dd95SBruce Richardson iter->bus_str = bus_str; 28799a2dd95SBruce Richardson 28899a2dd95SBruce Richardson end: 28999a2dd95SBruce Richardson iter->cls = rte_class_find_by_name("eth"); 29099a2dd95SBruce Richardson rte_devargs_reset(&devargs); 29199a2dd95SBruce Richardson return 0; 29299a2dd95SBruce Richardson 29399a2dd95SBruce Richardson error: 29499a2dd95SBruce Richardson if (ret == -ENOTSUP) 29599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n", 29699a2dd95SBruce Richardson iter->bus->name); 29799a2dd95SBruce Richardson rte_devargs_reset(&devargs); 29899a2dd95SBruce Richardson free(bus_str); 29999a2dd95SBruce Richardson free(cls_str); 30099a2dd95SBruce Richardson return ret; 30199a2dd95SBruce Richardson } 30299a2dd95SBruce Richardson 30399a2dd95SBruce Richardson uint16_t 30499a2dd95SBruce Richardson rte_eth_iterator_next(struct rte_dev_iterator *iter) 30599a2dd95SBruce Richardson { 30653ef1b34SMin Hu (Connor) if (iter == NULL) { 30753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 30853ef1b34SMin Hu (Connor) "Cannot get next device from NULL iterator\n"); 30953ef1b34SMin Hu (Connor) return RTE_MAX_ETHPORTS; 31053ef1b34SMin Hu (Connor) } 31153ef1b34SMin Hu (Connor) 31299a2dd95SBruce Richardson if (iter->cls == NULL) /* invalid ethdev iterator */ 31399a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 31499a2dd95SBruce Richardson 31599a2dd95SBruce Richardson do { /* loop to try all matching rte_device */ 31699a2dd95SBruce Richardson /* If not pure ethdev filter and */ 31799a2dd95SBruce Richardson if (iter->bus != NULL && 31899a2dd95SBruce Richardson /* not in middle of rte_eth_dev iteration, */ 31999a2dd95SBruce Richardson iter->class_device == NULL) { 32099a2dd95SBruce Richardson /* get next rte_device to try. */ 32199a2dd95SBruce Richardson iter->device = iter->bus->dev_iterate( 32299a2dd95SBruce Richardson iter->device, iter->bus_str, iter); 32399a2dd95SBruce Richardson if (iter->device == NULL) 32499a2dd95SBruce Richardson break; /* no more rte_device candidate */ 32599a2dd95SBruce Richardson } 32699a2dd95SBruce Richardson /* A device is matching bus part, need to check ethdev part. */ 32799a2dd95SBruce Richardson iter->class_device = iter->cls->dev_iterate( 32899a2dd95SBruce Richardson iter->class_device, iter->cls_str, iter); 32999a2dd95SBruce Richardson if (iter->class_device != NULL) 33099a2dd95SBruce Richardson return eth_dev_to_id(iter->class_device); /* match */ 33199a2dd95SBruce Richardson } while (iter->bus != NULL); /* need to try next rte_device */ 33299a2dd95SBruce Richardson 33399a2dd95SBruce Richardson /* No more ethdev port to iterate. */ 33499a2dd95SBruce Richardson rte_eth_iterator_cleanup(iter); 33599a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 33699a2dd95SBruce Richardson } 33799a2dd95SBruce Richardson 33899a2dd95SBruce Richardson void 33999a2dd95SBruce Richardson rte_eth_iterator_cleanup(struct rte_dev_iterator *iter) 34099a2dd95SBruce Richardson { 34153ef1b34SMin Hu (Connor) if (iter == NULL) { 34253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot do clean up from NULL iterator\n"); 34353ef1b34SMin Hu (Connor) return; 34453ef1b34SMin Hu (Connor) } 34553ef1b34SMin Hu (Connor) 34699a2dd95SBruce Richardson if (iter->bus_str == NULL) 34799a2dd95SBruce Richardson return; /* nothing to free in pure class filter */ 34899a2dd95SBruce Richardson free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */ 34999a2dd95SBruce Richardson free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */ 35099a2dd95SBruce Richardson memset(iter, 0, sizeof(*iter)); 35199a2dd95SBruce Richardson } 35299a2dd95SBruce Richardson 35399a2dd95SBruce Richardson uint16_t 35499a2dd95SBruce Richardson rte_eth_find_next(uint16_t port_id) 35599a2dd95SBruce Richardson { 35699a2dd95SBruce Richardson while (port_id < RTE_MAX_ETHPORTS && 35799a2dd95SBruce Richardson rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED) 35899a2dd95SBruce Richardson port_id++; 35999a2dd95SBruce Richardson 36099a2dd95SBruce Richardson if (port_id >= RTE_MAX_ETHPORTS) 36199a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 36299a2dd95SBruce Richardson 36399a2dd95SBruce Richardson return port_id; 36499a2dd95SBruce Richardson } 36599a2dd95SBruce Richardson 36699a2dd95SBruce Richardson /* 36799a2dd95SBruce Richardson * Macro to iterate over all valid ports for internal usage. 36899a2dd95SBruce Richardson * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports. 36999a2dd95SBruce Richardson */ 37099a2dd95SBruce Richardson #define RTE_ETH_FOREACH_VALID_DEV(port_id) \ 37199a2dd95SBruce Richardson for (port_id = rte_eth_find_next(0); \ 37299a2dd95SBruce Richardson port_id < RTE_MAX_ETHPORTS; \ 37399a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id + 1)) 37499a2dd95SBruce Richardson 37599a2dd95SBruce Richardson uint16_t 37699a2dd95SBruce Richardson rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent) 37799a2dd95SBruce Richardson { 37899a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id); 37999a2dd95SBruce Richardson while (port_id < RTE_MAX_ETHPORTS && 38099a2dd95SBruce Richardson rte_eth_devices[port_id].device != parent) 38199a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id + 1); 38299a2dd95SBruce Richardson 38399a2dd95SBruce Richardson return port_id; 38499a2dd95SBruce Richardson } 38599a2dd95SBruce Richardson 38699a2dd95SBruce Richardson uint16_t 38799a2dd95SBruce Richardson rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id) 38899a2dd95SBruce Richardson { 38999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS); 39099a2dd95SBruce Richardson return rte_eth_find_next_of(port_id, 39199a2dd95SBruce Richardson rte_eth_devices[ref_port_id].device); 39299a2dd95SBruce Richardson } 39399a2dd95SBruce Richardson 39499a2dd95SBruce Richardson static void 39599a2dd95SBruce Richardson eth_dev_shared_data_prepare(void) 39699a2dd95SBruce Richardson { 39799a2dd95SBruce Richardson const unsigned flags = 0; 39899a2dd95SBruce Richardson const struct rte_memzone *mz; 39999a2dd95SBruce Richardson 40099a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data_lock); 40199a2dd95SBruce Richardson 40299a2dd95SBruce Richardson if (eth_dev_shared_data == NULL) { 40399a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 40499a2dd95SBruce Richardson /* Allocate port data and ownership shared memory. */ 40599a2dd95SBruce Richardson mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA, 40699a2dd95SBruce Richardson sizeof(*eth_dev_shared_data), 40799a2dd95SBruce Richardson rte_socket_id(), flags); 40899a2dd95SBruce Richardson } else 40999a2dd95SBruce Richardson mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA); 41099a2dd95SBruce Richardson if (mz == NULL) 41199a2dd95SBruce Richardson rte_panic("Cannot allocate ethdev shared data\n"); 41299a2dd95SBruce Richardson 41399a2dd95SBruce Richardson eth_dev_shared_data = mz->addr; 41499a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 41599a2dd95SBruce Richardson eth_dev_shared_data->next_owner_id = 41699a2dd95SBruce Richardson RTE_ETH_DEV_NO_OWNER + 1; 41799a2dd95SBruce Richardson rte_spinlock_init(ð_dev_shared_data->ownership_lock); 41899a2dd95SBruce Richardson memset(eth_dev_shared_data->data, 0, 41999a2dd95SBruce Richardson sizeof(eth_dev_shared_data->data)); 42099a2dd95SBruce Richardson } 42199a2dd95SBruce Richardson } 42299a2dd95SBruce Richardson 42399a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data_lock); 42499a2dd95SBruce Richardson } 42599a2dd95SBruce Richardson 42699a2dd95SBruce Richardson static bool 42799a2dd95SBruce Richardson eth_dev_is_allocated(const struct rte_eth_dev *ethdev) 42899a2dd95SBruce Richardson { 42999a2dd95SBruce Richardson return ethdev->data->name[0] != '\0'; 43099a2dd95SBruce Richardson } 43199a2dd95SBruce Richardson 43299a2dd95SBruce Richardson static struct rte_eth_dev * 43399a2dd95SBruce Richardson eth_dev_allocated(const char *name) 43499a2dd95SBruce Richardson { 43599a2dd95SBruce Richardson uint16_t i; 43699a2dd95SBruce Richardson 43799a2dd95SBruce Richardson RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX); 43899a2dd95SBruce Richardson 43999a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 44099a2dd95SBruce Richardson if (rte_eth_devices[i].data != NULL && 44199a2dd95SBruce Richardson strcmp(rte_eth_devices[i].data->name, name) == 0) 44299a2dd95SBruce Richardson return &rte_eth_devices[i]; 44399a2dd95SBruce Richardson } 44499a2dd95SBruce Richardson return NULL; 44599a2dd95SBruce Richardson } 44699a2dd95SBruce Richardson 44799a2dd95SBruce Richardson struct rte_eth_dev * 44899a2dd95SBruce Richardson rte_eth_dev_allocated(const char *name) 44999a2dd95SBruce Richardson { 45099a2dd95SBruce Richardson struct rte_eth_dev *ethdev; 45199a2dd95SBruce Richardson 45299a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 45399a2dd95SBruce Richardson 45499a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 45599a2dd95SBruce Richardson 45699a2dd95SBruce Richardson ethdev = eth_dev_allocated(name); 45799a2dd95SBruce Richardson 45899a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 45999a2dd95SBruce Richardson 46099a2dd95SBruce Richardson return ethdev; 46199a2dd95SBruce Richardson } 46299a2dd95SBruce Richardson 46399a2dd95SBruce Richardson static uint16_t 46499a2dd95SBruce Richardson eth_dev_find_free_port(void) 46599a2dd95SBruce Richardson { 46699a2dd95SBruce Richardson uint16_t i; 46799a2dd95SBruce Richardson 46899a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 46999a2dd95SBruce Richardson /* Using shared name field to find a free port. */ 47099a2dd95SBruce Richardson if (eth_dev_shared_data->data[i].name[0] == '\0') { 47199a2dd95SBruce Richardson RTE_ASSERT(rte_eth_devices[i].state == 47299a2dd95SBruce Richardson RTE_ETH_DEV_UNUSED); 47399a2dd95SBruce Richardson return i; 47499a2dd95SBruce Richardson } 47599a2dd95SBruce Richardson } 47699a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 47799a2dd95SBruce Richardson } 47899a2dd95SBruce Richardson 47999a2dd95SBruce Richardson static struct rte_eth_dev * 48099a2dd95SBruce Richardson eth_dev_get(uint16_t port_id) 48199a2dd95SBruce Richardson { 48299a2dd95SBruce Richardson struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id]; 48399a2dd95SBruce Richardson 48499a2dd95SBruce Richardson eth_dev->data = ð_dev_shared_data->data[port_id]; 48599a2dd95SBruce Richardson 48699a2dd95SBruce Richardson return eth_dev; 48799a2dd95SBruce Richardson } 48899a2dd95SBruce Richardson 48999a2dd95SBruce Richardson struct rte_eth_dev * 49099a2dd95SBruce Richardson rte_eth_dev_allocate(const char *name) 49199a2dd95SBruce Richardson { 49299a2dd95SBruce Richardson uint16_t port_id; 49399a2dd95SBruce Richardson struct rte_eth_dev *eth_dev = NULL; 49499a2dd95SBruce Richardson size_t name_len; 49599a2dd95SBruce Richardson 49699a2dd95SBruce Richardson name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN); 49799a2dd95SBruce Richardson if (name_len == 0) { 49899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); 49999a2dd95SBruce Richardson return NULL; 50099a2dd95SBruce Richardson } 50199a2dd95SBruce Richardson 50299a2dd95SBruce Richardson if (name_len >= RTE_ETH_NAME_MAX_LEN) { 50399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); 50499a2dd95SBruce Richardson return NULL; 50599a2dd95SBruce Richardson } 50699a2dd95SBruce Richardson 50799a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 50899a2dd95SBruce Richardson 50999a2dd95SBruce Richardson /* Synchronize port creation between primary and secondary threads. */ 51099a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 51199a2dd95SBruce Richardson 51299a2dd95SBruce Richardson if (eth_dev_allocated(name) != NULL) { 51399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 51499a2dd95SBruce Richardson "Ethernet device with name %s already allocated\n", 51599a2dd95SBruce Richardson name); 51699a2dd95SBruce Richardson goto unlock; 51799a2dd95SBruce Richardson } 51899a2dd95SBruce Richardson 51999a2dd95SBruce Richardson port_id = eth_dev_find_free_port(); 52099a2dd95SBruce Richardson if (port_id == RTE_MAX_ETHPORTS) { 52199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 52299a2dd95SBruce Richardson "Reached maximum number of Ethernet ports\n"); 52399a2dd95SBruce Richardson goto unlock; 52499a2dd95SBruce Richardson } 52599a2dd95SBruce Richardson 52699a2dd95SBruce Richardson eth_dev = eth_dev_get(port_id); 52799a2dd95SBruce Richardson strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name)); 52899a2dd95SBruce Richardson eth_dev->data->port_id = port_id; 529ff4e52efSViacheslav Galaktionov eth_dev->data->backer_port_id = RTE_MAX_ETHPORTS; 53099a2dd95SBruce Richardson eth_dev->data->mtu = RTE_ETHER_MTU; 53199a2dd95SBruce Richardson pthread_mutex_init(ð_dev->data->flow_ops_mutex, NULL); 53299a2dd95SBruce Richardson 53399a2dd95SBruce Richardson unlock: 53499a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 53599a2dd95SBruce Richardson 53699a2dd95SBruce Richardson return eth_dev; 53799a2dd95SBruce Richardson } 53899a2dd95SBruce Richardson 53999a2dd95SBruce Richardson /* 54099a2dd95SBruce Richardson * Attach to a port already registered by the primary process, which 54199a2dd95SBruce Richardson * makes sure that the same device would have the same port id both 54299a2dd95SBruce Richardson * in the primary and secondary process. 54399a2dd95SBruce Richardson */ 54499a2dd95SBruce Richardson struct rte_eth_dev * 54599a2dd95SBruce Richardson rte_eth_dev_attach_secondary(const char *name) 54699a2dd95SBruce Richardson { 54799a2dd95SBruce Richardson uint16_t i; 54899a2dd95SBruce Richardson struct rte_eth_dev *eth_dev = NULL; 54999a2dd95SBruce Richardson 55099a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 55199a2dd95SBruce Richardson 55299a2dd95SBruce Richardson /* Synchronize port attachment to primary port creation and release. */ 55399a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 55499a2dd95SBruce Richardson 55599a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 55699a2dd95SBruce Richardson if (strcmp(eth_dev_shared_data->data[i].name, name) == 0) 55799a2dd95SBruce Richardson break; 55899a2dd95SBruce Richardson } 55999a2dd95SBruce Richardson if (i == RTE_MAX_ETHPORTS) { 56099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 56199a2dd95SBruce Richardson "Device %s is not driven by the primary process\n", 56299a2dd95SBruce Richardson name); 56399a2dd95SBruce Richardson } else { 56499a2dd95SBruce Richardson eth_dev = eth_dev_get(i); 56599a2dd95SBruce Richardson RTE_ASSERT(eth_dev->data->port_id == i); 56699a2dd95SBruce Richardson } 56799a2dd95SBruce Richardson 56899a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 56999a2dd95SBruce Richardson return eth_dev; 57099a2dd95SBruce Richardson } 57199a2dd95SBruce Richardson 57299a2dd95SBruce Richardson int 57399a2dd95SBruce Richardson rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) 57499a2dd95SBruce Richardson { 57599a2dd95SBruce Richardson if (eth_dev == NULL) 57699a2dd95SBruce Richardson return -EINVAL; 57799a2dd95SBruce Richardson 57899a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 57999a2dd95SBruce Richardson 58099a2dd95SBruce Richardson if (eth_dev->state != RTE_ETH_DEV_UNUSED) 58199a2dd95SBruce Richardson rte_eth_dev_callback_process(eth_dev, 58299a2dd95SBruce Richardson RTE_ETH_EVENT_DESTROY, NULL); 58399a2dd95SBruce Richardson 584c87d435aSKonstantin Ananyev eth_dev_fp_ops_reset(rte_eth_fp_ops + eth_dev->data->port_id); 585c87d435aSKonstantin Ananyev 58699a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 58799a2dd95SBruce Richardson 58899a2dd95SBruce Richardson eth_dev->state = RTE_ETH_DEV_UNUSED; 58999a2dd95SBruce Richardson eth_dev->device = NULL; 59099a2dd95SBruce Richardson eth_dev->process_private = NULL; 59199a2dd95SBruce Richardson eth_dev->intr_handle = NULL; 59299a2dd95SBruce Richardson eth_dev->rx_pkt_burst = NULL; 59399a2dd95SBruce Richardson eth_dev->tx_pkt_burst = NULL; 59499a2dd95SBruce Richardson eth_dev->tx_pkt_prepare = NULL; 59599a2dd95SBruce Richardson eth_dev->rx_queue_count = NULL; 59699a2dd95SBruce Richardson eth_dev->rx_descriptor_status = NULL; 59799a2dd95SBruce Richardson eth_dev->tx_descriptor_status = NULL; 59899a2dd95SBruce Richardson eth_dev->dev_ops = NULL; 59999a2dd95SBruce Richardson 60099a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 60199a2dd95SBruce Richardson rte_free(eth_dev->data->rx_queues); 60299a2dd95SBruce Richardson rte_free(eth_dev->data->tx_queues); 60399a2dd95SBruce Richardson rte_free(eth_dev->data->mac_addrs); 60499a2dd95SBruce Richardson rte_free(eth_dev->data->hash_mac_addrs); 60599a2dd95SBruce Richardson rte_free(eth_dev->data->dev_private); 60699a2dd95SBruce Richardson pthread_mutex_destroy(ð_dev->data->flow_ops_mutex); 60799a2dd95SBruce Richardson memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data)); 60899a2dd95SBruce Richardson } 60999a2dd95SBruce Richardson 61099a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 61199a2dd95SBruce Richardson 61299a2dd95SBruce Richardson return 0; 61399a2dd95SBruce Richardson } 61499a2dd95SBruce Richardson 61599a2dd95SBruce Richardson int 61699a2dd95SBruce Richardson rte_eth_dev_is_valid_port(uint16_t port_id) 61799a2dd95SBruce Richardson { 61899a2dd95SBruce Richardson if (port_id >= RTE_MAX_ETHPORTS || 61999a2dd95SBruce Richardson (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)) 62099a2dd95SBruce Richardson return 0; 62199a2dd95SBruce Richardson else 62299a2dd95SBruce Richardson return 1; 62399a2dd95SBruce Richardson } 62499a2dd95SBruce Richardson 62599a2dd95SBruce Richardson static int 62699a2dd95SBruce Richardson eth_is_valid_owner_id(uint64_t owner_id) 62799a2dd95SBruce Richardson { 62899a2dd95SBruce Richardson if (owner_id == RTE_ETH_DEV_NO_OWNER || 62999a2dd95SBruce Richardson eth_dev_shared_data->next_owner_id <= owner_id) 63099a2dd95SBruce Richardson return 0; 63199a2dd95SBruce Richardson return 1; 63299a2dd95SBruce Richardson } 63399a2dd95SBruce Richardson 63499a2dd95SBruce Richardson uint64_t 63599a2dd95SBruce Richardson rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id) 63699a2dd95SBruce Richardson { 63799a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id); 63899a2dd95SBruce Richardson while (port_id < RTE_MAX_ETHPORTS && 63999a2dd95SBruce Richardson rte_eth_devices[port_id].data->owner.id != owner_id) 64099a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id + 1); 64199a2dd95SBruce Richardson 64299a2dd95SBruce Richardson return port_id; 64399a2dd95SBruce Richardson } 64499a2dd95SBruce Richardson 64599a2dd95SBruce Richardson int 64699a2dd95SBruce Richardson rte_eth_dev_owner_new(uint64_t *owner_id) 64799a2dd95SBruce Richardson { 64853ef1b34SMin Hu (Connor) if (owner_id == NULL) { 64953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get new owner ID to NULL\n"); 65053ef1b34SMin Hu (Connor) return -EINVAL; 65153ef1b34SMin Hu (Connor) } 65253ef1b34SMin Hu (Connor) 65399a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 65499a2dd95SBruce Richardson 65599a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 65699a2dd95SBruce Richardson 65799a2dd95SBruce Richardson *owner_id = eth_dev_shared_data->next_owner_id++; 65899a2dd95SBruce Richardson 65999a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 66099a2dd95SBruce Richardson return 0; 66199a2dd95SBruce Richardson } 66299a2dd95SBruce Richardson 66399a2dd95SBruce Richardson static int 66499a2dd95SBruce Richardson eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, 66599a2dd95SBruce Richardson const struct rte_eth_dev_owner *new_owner) 66699a2dd95SBruce Richardson { 66799a2dd95SBruce Richardson struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; 66899a2dd95SBruce Richardson struct rte_eth_dev_owner *port_owner; 66999a2dd95SBruce Richardson 67099a2dd95SBruce Richardson if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) { 67199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n", 67299a2dd95SBruce Richardson port_id); 67399a2dd95SBruce Richardson return -ENODEV; 67499a2dd95SBruce Richardson } 67599a2dd95SBruce Richardson 67653ef1b34SMin Hu (Connor) if (new_owner == NULL) { 67753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 67853ef1b34SMin Hu (Connor) "Cannot set ethdev port %u owner from NULL owner\n", 67953ef1b34SMin Hu (Connor) port_id); 68053ef1b34SMin Hu (Connor) return -EINVAL; 68153ef1b34SMin Hu (Connor) } 68253ef1b34SMin Hu (Connor) 68399a2dd95SBruce Richardson if (!eth_is_valid_owner_id(new_owner->id) && 68499a2dd95SBruce Richardson !eth_is_valid_owner_id(old_owner_id)) { 68599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 68699a2dd95SBruce Richardson "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64"\n", 68799a2dd95SBruce Richardson old_owner_id, new_owner->id); 68899a2dd95SBruce Richardson return -EINVAL; 68999a2dd95SBruce Richardson } 69099a2dd95SBruce Richardson 69199a2dd95SBruce Richardson port_owner = &rte_eth_devices[port_id].data->owner; 69299a2dd95SBruce Richardson if (port_owner->id != old_owner_id) { 69399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 69499a2dd95SBruce Richardson "Cannot set owner to port %u already owned by %s_%016"PRIX64"\n", 69599a2dd95SBruce Richardson port_id, port_owner->name, port_owner->id); 69699a2dd95SBruce Richardson return -EPERM; 69799a2dd95SBruce Richardson } 69899a2dd95SBruce Richardson 69999a2dd95SBruce Richardson /* can not truncate (same structure) */ 70099a2dd95SBruce Richardson strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN); 70199a2dd95SBruce Richardson 70299a2dd95SBruce Richardson port_owner->id = new_owner->id; 70399a2dd95SBruce Richardson 70499a2dd95SBruce Richardson RTE_ETHDEV_LOG(DEBUG, "Port %u owner is %s_%016"PRIx64"\n", 70599a2dd95SBruce Richardson port_id, new_owner->name, new_owner->id); 70699a2dd95SBruce Richardson 70799a2dd95SBruce Richardson return 0; 70899a2dd95SBruce Richardson } 70999a2dd95SBruce Richardson 71099a2dd95SBruce Richardson int 71199a2dd95SBruce Richardson rte_eth_dev_owner_set(const uint16_t port_id, 71299a2dd95SBruce Richardson const struct rte_eth_dev_owner *owner) 71399a2dd95SBruce Richardson { 71499a2dd95SBruce Richardson int ret; 71599a2dd95SBruce Richardson 71699a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 71799a2dd95SBruce Richardson 71899a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 71999a2dd95SBruce Richardson 72099a2dd95SBruce Richardson ret = eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner); 72199a2dd95SBruce Richardson 72299a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 72399a2dd95SBruce Richardson return ret; 72499a2dd95SBruce Richardson } 72599a2dd95SBruce Richardson 72699a2dd95SBruce Richardson int 72799a2dd95SBruce Richardson rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id) 72899a2dd95SBruce Richardson { 72999a2dd95SBruce Richardson const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner) 73099a2dd95SBruce Richardson {.id = RTE_ETH_DEV_NO_OWNER, .name = ""}; 73199a2dd95SBruce Richardson int ret; 73299a2dd95SBruce Richardson 73399a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 73499a2dd95SBruce Richardson 73599a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 73699a2dd95SBruce Richardson 73799a2dd95SBruce Richardson ret = eth_dev_owner_set(port_id, owner_id, &new_owner); 73899a2dd95SBruce Richardson 73999a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 74099a2dd95SBruce Richardson return ret; 74199a2dd95SBruce Richardson } 74299a2dd95SBruce Richardson 74399a2dd95SBruce Richardson int 74499a2dd95SBruce Richardson rte_eth_dev_owner_delete(const uint64_t owner_id) 74599a2dd95SBruce Richardson { 74699a2dd95SBruce Richardson uint16_t port_id; 74799a2dd95SBruce Richardson int ret = 0; 74899a2dd95SBruce Richardson 74999a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 75099a2dd95SBruce Richardson 75199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 75299a2dd95SBruce Richardson 75399a2dd95SBruce Richardson if (eth_is_valid_owner_id(owner_id)) { 75499a2dd95SBruce Richardson for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) 75599a2dd95SBruce Richardson if (rte_eth_devices[port_id].data->owner.id == owner_id) 75699a2dd95SBruce Richardson memset(&rte_eth_devices[port_id].data->owner, 0, 75799a2dd95SBruce Richardson sizeof(struct rte_eth_dev_owner)); 75899a2dd95SBruce Richardson RTE_ETHDEV_LOG(NOTICE, 75999a2dd95SBruce Richardson "All port owners owned by %016"PRIx64" identifier have removed\n", 76099a2dd95SBruce Richardson owner_id); 76199a2dd95SBruce Richardson } else { 76299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 76399a2dd95SBruce Richardson "Invalid owner id=%016"PRIx64"\n", 76499a2dd95SBruce Richardson owner_id); 76599a2dd95SBruce Richardson ret = -EINVAL; 76699a2dd95SBruce Richardson } 76799a2dd95SBruce Richardson 76899a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 76999a2dd95SBruce Richardson 77099a2dd95SBruce Richardson return ret; 77199a2dd95SBruce Richardson } 77299a2dd95SBruce Richardson 77399a2dd95SBruce Richardson int 77499a2dd95SBruce Richardson rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner) 77599a2dd95SBruce Richardson { 77653ef1b34SMin Hu (Connor) struct rte_eth_dev *ethdev; 77753ef1b34SMin Hu (Connor) 77853ef1b34SMin Hu (Connor) RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 77953ef1b34SMin Hu (Connor) ethdev = &rte_eth_devices[port_id]; 78053ef1b34SMin Hu (Connor) 78153ef1b34SMin Hu (Connor) if (!eth_dev_is_allocated(ethdev)) { 78253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n", 78353ef1b34SMin Hu (Connor) port_id); 78453ef1b34SMin Hu (Connor) return -ENODEV; 78553ef1b34SMin Hu (Connor) } 78653ef1b34SMin Hu (Connor) 78753ef1b34SMin Hu (Connor) if (owner == NULL) { 78853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u owner to NULL\n", 78953ef1b34SMin Hu (Connor) port_id); 79053ef1b34SMin Hu (Connor) return -EINVAL; 79153ef1b34SMin Hu (Connor) } 79299a2dd95SBruce Richardson 79399a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 79499a2dd95SBruce Richardson 79599a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 79699a2dd95SBruce Richardson rte_memcpy(owner, ðdev->data->owner, sizeof(*owner)); 79799a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 79853ef1b34SMin Hu (Connor) 79953ef1b34SMin Hu (Connor) return 0; 80099a2dd95SBruce Richardson } 80199a2dd95SBruce Richardson 80299a2dd95SBruce Richardson int 80399a2dd95SBruce Richardson rte_eth_dev_socket_id(uint16_t port_id) 80499a2dd95SBruce Richardson { 80599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); 80699a2dd95SBruce Richardson return rte_eth_devices[port_id].data->numa_node; 80799a2dd95SBruce Richardson } 80899a2dd95SBruce Richardson 80999a2dd95SBruce Richardson void * 81099a2dd95SBruce Richardson rte_eth_dev_get_sec_ctx(uint16_t port_id) 81199a2dd95SBruce Richardson { 81299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL); 81399a2dd95SBruce Richardson return rte_eth_devices[port_id].security_ctx; 81499a2dd95SBruce Richardson } 81599a2dd95SBruce Richardson 81699a2dd95SBruce Richardson uint16_t 81799a2dd95SBruce Richardson rte_eth_dev_count_avail(void) 81899a2dd95SBruce Richardson { 81999a2dd95SBruce Richardson uint16_t p; 82099a2dd95SBruce Richardson uint16_t count; 82199a2dd95SBruce Richardson 82299a2dd95SBruce Richardson count = 0; 82399a2dd95SBruce Richardson 82499a2dd95SBruce Richardson RTE_ETH_FOREACH_DEV(p) 82599a2dd95SBruce Richardson count++; 82699a2dd95SBruce Richardson 82799a2dd95SBruce Richardson return count; 82899a2dd95SBruce Richardson } 82999a2dd95SBruce Richardson 83099a2dd95SBruce Richardson uint16_t 83199a2dd95SBruce Richardson rte_eth_dev_count_total(void) 83299a2dd95SBruce Richardson { 83399a2dd95SBruce Richardson uint16_t port, count = 0; 83499a2dd95SBruce Richardson 83599a2dd95SBruce Richardson RTE_ETH_FOREACH_VALID_DEV(port) 83699a2dd95SBruce Richardson count++; 83799a2dd95SBruce Richardson 83899a2dd95SBruce Richardson return count; 83999a2dd95SBruce Richardson } 84099a2dd95SBruce Richardson 84199a2dd95SBruce Richardson int 84299a2dd95SBruce Richardson rte_eth_dev_get_name_by_port(uint16_t port_id, char *name) 84399a2dd95SBruce Richardson { 84499a2dd95SBruce Richardson char *tmp; 84599a2dd95SBruce Richardson 84699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 84799a2dd95SBruce Richardson 84899a2dd95SBruce Richardson if (name == NULL) { 84953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u name to NULL\n", 85053ef1b34SMin Hu (Connor) port_id); 85199a2dd95SBruce Richardson return -EINVAL; 85299a2dd95SBruce Richardson } 85399a2dd95SBruce Richardson 85499a2dd95SBruce Richardson /* shouldn't check 'rte_eth_devices[i].data', 85599a2dd95SBruce Richardson * because it might be overwritten by VDEV PMD */ 85699a2dd95SBruce Richardson tmp = eth_dev_shared_data->data[port_id].name; 85799a2dd95SBruce Richardson strcpy(name, tmp); 85899a2dd95SBruce Richardson return 0; 85999a2dd95SBruce Richardson } 86099a2dd95SBruce Richardson 86199a2dd95SBruce Richardson int 86299a2dd95SBruce Richardson rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) 86399a2dd95SBruce Richardson { 86499a2dd95SBruce Richardson uint16_t pid; 86599a2dd95SBruce Richardson 86699a2dd95SBruce Richardson if (name == NULL) { 86753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name"); 86853ef1b34SMin Hu (Connor) return -EINVAL; 86953ef1b34SMin Hu (Connor) } 87053ef1b34SMin Hu (Connor) 87153ef1b34SMin Hu (Connor) if (port_id == NULL) { 87253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 87353ef1b34SMin Hu (Connor) "Cannot get port ID to NULL for %s\n", name); 87499a2dd95SBruce Richardson return -EINVAL; 87599a2dd95SBruce Richardson } 87699a2dd95SBruce Richardson 87799a2dd95SBruce Richardson RTE_ETH_FOREACH_VALID_DEV(pid) 87899a2dd95SBruce Richardson if (!strcmp(name, eth_dev_shared_data->data[pid].name)) { 87999a2dd95SBruce Richardson *port_id = pid; 88099a2dd95SBruce Richardson return 0; 88199a2dd95SBruce Richardson } 88299a2dd95SBruce Richardson 88399a2dd95SBruce Richardson return -ENODEV; 88499a2dd95SBruce Richardson } 88599a2dd95SBruce Richardson 88699a2dd95SBruce Richardson static int 88799a2dd95SBruce Richardson eth_err(uint16_t port_id, int ret) 88899a2dd95SBruce Richardson { 88999a2dd95SBruce Richardson if (ret == 0) 89099a2dd95SBruce Richardson return 0; 89199a2dd95SBruce Richardson if (rte_eth_dev_is_removed(port_id)) 89299a2dd95SBruce Richardson return -EIO; 89399a2dd95SBruce Richardson return ret; 89499a2dd95SBruce Richardson } 89599a2dd95SBruce Richardson 89649ed3224SXueming Li static void 89749ed3224SXueming Li eth_dev_rxq_release(struct rte_eth_dev *dev, uint16_t qid) 89849ed3224SXueming Li { 89949ed3224SXueming Li void **rxq = dev->data->rx_queues; 90049ed3224SXueming Li 90149ed3224SXueming Li if (rxq[qid] == NULL) 90249ed3224SXueming Li return; 90349ed3224SXueming Li 90449ed3224SXueming Li if (dev->dev_ops->rx_queue_release != NULL) 9057483341aSXueming Li (*dev->dev_ops->rx_queue_release)(dev, qid); 90649ed3224SXueming Li rxq[qid] = NULL; 90749ed3224SXueming Li } 90849ed3224SXueming Li 90949ed3224SXueming Li static void 91049ed3224SXueming Li eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid) 91149ed3224SXueming Li { 91249ed3224SXueming Li void **txq = dev->data->tx_queues; 91349ed3224SXueming Li 91449ed3224SXueming Li if (txq[qid] == NULL) 91549ed3224SXueming Li return; 91649ed3224SXueming Li 91749ed3224SXueming Li if (dev->dev_ops->tx_queue_release != NULL) 9187483341aSXueming Li (*dev->dev_ops->tx_queue_release)(dev, qid); 91949ed3224SXueming Li txq[qid] = NULL; 92049ed3224SXueming Li } 92149ed3224SXueming Li 92299a2dd95SBruce Richardson static int 92399a2dd95SBruce Richardson eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) 92499a2dd95SBruce Richardson { 92599a2dd95SBruce Richardson uint16_t old_nb_queues = dev->data->nb_rx_queues; 92699a2dd95SBruce Richardson unsigned i; 92799a2dd95SBruce Richardson 92899a2dd95SBruce Richardson if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */ 92999a2dd95SBruce Richardson dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues", 930c024496aSKonstantin Ananyev sizeof(dev->data->rx_queues[0]) * 931c024496aSKonstantin Ananyev RTE_MAX_QUEUES_PER_PORT, 93299a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE); 93399a2dd95SBruce Richardson if (dev->data->rx_queues == NULL) { 93499a2dd95SBruce Richardson dev->data->nb_rx_queues = 0; 93599a2dd95SBruce Richardson return -(ENOMEM); 93699a2dd95SBruce Richardson } 93799a2dd95SBruce Richardson } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */ 93849ed3224SXueming Li for (i = nb_queues; i < old_nb_queues; i++) 93949ed3224SXueming Li eth_dev_rxq_release(dev, i); 94099a2dd95SBruce Richardson 94199a2dd95SBruce Richardson } else if (dev->data->rx_queues != NULL && nb_queues == 0) { 94299a2dd95SBruce Richardson for (i = nb_queues; i < old_nb_queues; i++) 94349ed3224SXueming Li eth_dev_rxq_release(dev, i); 94499a2dd95SBruce Richardson 94599a2dd95SBruce Richardson rte_free(dev->data->rx_queues); 94699a2dd95SBruce Richardson dev->data->rx_queues = NULL; 94799a2dd95SBruce Richardson } 94899a2dd95SBruce Richardson dev->data->nb_rx_queues = nb_queues; 94999a2dd95SBruce Richardson return 0; 95099a2dd95SBruce Richardson } 95199a2dd95SBruce Richardson 95299a2dd95SBruce Richardson static int 95399a2dd95SBruce Richardson eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id) 95499a2dd95SBruce Richardson { 95599a2dd95SBruce Richardson uint16_t port_id; 95699a2dd95SBruce Richardson 95799a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 95899a2dd95SBruce Richardson port_id = dev->data->port_id; 95999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 96099a2dd95SBruce Richardson "Invalid Rx queue_id=%u of device with port_id=%u\n", 96199a2dd95SBruce Richardson rx_queue_id, port_id); 96299a2dd95SBruce Richardson return -EINVAL; 96399a2dd95SBruce Richardson } 96499a2dd95SBruce Richardson 96599a2dd95SBruce Richardson if (dev->data->rx_queues[rx_queue_id] == NULL) { 96699a2dd95SBruce Richardson port_id = dev->data->port_id; 96799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 96899a2dd95SBruce Richardson "Queue %u of device with port_id=%u has not been setup\n", 96999a2dd95SBruce Richardson rx_queue_id, port_id); 97099a2dd95SBruce Richardson return -EINVAL; 97199a2dd95SBruce Richardson } 97299a2dd95SBruce Richardson 97399a2dd95SBruce Richardson return 0; 97499a2dd95SBruce Richardson } 97599a2dd95SBruce Richardson 97699a2dd95SBruce Richardson static int 97799a2dd95SBruce Richardson eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id) 97899a2dd95SBruce Richardson { 97999a2dd95SBruce Richardson uint16_t port_id; 98099a2dd95SBruce Richardson 98199a2dd95SBruce Richardson if (tx_queue_id >= dev->data->nb_tx_queues) { 98299a2dd95SBruce Richardson port_id = dev->data->port_id; 98399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 98499a2dd95SBruce Richardson "Invalid Tx queue_id=%u of device with port_id=%u\n", 98599a2dd95SBruce Richardson tx_queue_id, port_id); 98699a2dd95SBruce Richardson return -EINVAL; 98799a2dd95SBruce Richardson } 98899a2dd95SBruce Richardson 98999a2dd95SBruce Richardson if (dev->data->tx_queues[tx_queue_id] == NULL) { 99099a2dd95SBruce Richardson port_id = dev->data->port_id; 99199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 99299a2dd95SBruce Richardson "Queue %u of device with port_id=%u has not been setup\n", 99399a2dd95SBruce Richardson tx_queue_id, port_id); 99499a2dd95SBruce Richardson return -EINVAL; 99599a2dd95SBruce Richardson } 99699a2dd95SBruce Richardson 99799a2dd95SBruce Richardson return 0; 99899a2dd95SBruce Richardson } 99999a2dd95SBruce Richardson 100099a2dd95SBruce Richardson int 100199a2dd95SBruce Richardson rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id) 100299a2dd95SBruce Richardson { 100399a2dd95SBruce Richardson struct rte_eth_dev *dev; 100499a2dd95SBruce Richardson int ret; 100599a2dd95SBruce Richardson 100699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 100799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 100853ef1b34SMin Hu (Connor) 100999a2dd95SBruce Richardson if (!dev->data->dev_started) { 101099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 101199a2dd95SBruce Richardson "Port %u must be started before start any queue\n", 101299a2dd95SBruce Richardson port_id); 101399a2dd95SBruce Richardson return -EINVAL; 101499a2dd95SBruce Richardson } 101599a2dd95SBruce Richardson 101699a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, rx_queue_id); 101799a2dd95SBruce Richardson if (ret != 0) 101899a2dd95SBruce Richardson return ret; 101999a2dd95SBruce Richardson 102099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP); 102199a2dd95SBruce Richardson 102299a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) { 102399a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 102499a2dd95SBruce Richardson "Can't start Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 102599a2dd95SBruce Richardson rx_queue_id, port_id); 102699a2dd95SBruce Richardson return -EINVAL; 102799a2dd95SBruce Richardson } 102899a2dd95SBruce Richardson 102999a2dd95SBruce Richardson if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) { 103099a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 103199a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n", 103299a2dd95SBruce Richardson rx_queue_id, port_id); 103399a2dd95SBruce Richardson return 0; 103499a2dd95SBruce Richardson } 103599a2dd95SBruce Richardson 103653ef1b34SMin Hu (Connor) return eth_err(port_id, dev->dev_ops->rx_queue_start(dev, rx_queue_id)); 103799a2dd95SBruce Richardson } 103899a2dd95SBruce Richardson 103999a2dd95SBruce Richardson int 104099a2dd95SBruce Richardson rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id) 104199a2dd95SBruce Richardson { 104299a2dd95SBruce Richardson struct rte_eth_dev *dev; 104399a2dd95SBruce Richardson int ret; 104499a2dd95SBruce Richardson 104599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 104699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 104799a2dd95SBruce Richardson 104899a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, rx_queue_id); 104999a2dd95SBruce Richardson if (ret != 0) 105099a2dd95SBruce Richardson return ret; 105199a2dd95SBruce Richardson 105299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP); 105399a2dd95SBruce Richardson 105499a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) { 105599a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 105699a2dd95SBruce Richardson "Can't stop Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 105799a2dd95SBruce Richardson rx_queue_id, port_id); 105899a2dd95SBruce Richardson return -EINVAL; 105999a2dd95SBruce Richardson } 106099a2dd95SBruce Richardson 106199a2dd95SBruce Richardson if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) { 106299a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 106399a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n", 106499a2dd95SBruce Richardson rx_queue_id, port_id); 106599a2dd95SBruce Richardson return 0; 106699a2dd95SBruce Richardson } 106799a2dd95SBruce Richardson 106899a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id)); 106999a2dd95SBruce Richardson } 107099a2dd95SBruce Richardson 107199a2dd95SBruce Richardson int 107299a2dd95SBruce Richardson rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id) 107399a2dd95SBruce Richardson { 107499a2dd95SBruce Richardson struct rte_eth_dev *dev; 107599a2dd95SBruce Richardson int ret; 107699a2dd95SBruce Richardson 107799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 107899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 107953ef1b34SMin Hu (Connor) 108099a2dd95SBruce Richardson if (!dev->data->dev_started) { 108199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 108299a2dd95SBruce Richardson "Port %u must be started before start any queue\n", 108399a2dd95SBruce Richardson port_id); 108499a2dd95SBruce Richardson return -EINVAL; 108599a2dd95SBruce Richardson } 108699a2dd95SBruce Richardson 108799a2dd95SBruce Richardson ret = eth_dev_validate_tx_queue(dev, tx_queue_id); 108899a2dd95SBruce Richardson if (ret != 0) 108999a2dd95SBruce Richardson return ret; 109099a2dd95SBruce Richardson 109199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP); 109299a2dd95SBruce Richardson 109399a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) { 109499a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 109599a2dd95SBruce Richardson "Can't start Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 109699a2dd95SBruce Richardson tx_queue_id, port_id); 109799a2dd95SBruce Richardson return -EINVAL; 109899a2dd95SBruce Richardson } 109999a2dd95SBruce Richardson 110099a2dd95SBruce Richardson if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) { 110199a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 110299a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n", 110399a2dd95SBruce Richardson tx_queue_id, port_id); 110499a2dd95SBruce Richardson return 0; 110599a2dd95SBruce Richardson } 110699a2dd95SBruce Richardson 110799a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id)); 110899a2dd95SBruce Richardson } 110999a2dd95SBruce Richardson 111099a2dd95SBruce Richardson int 111199a2dd95SBruce Richardson rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id) 111299a2dd95SBruce Richardson { 111399a2dd95SBruce Richardson struct rte_eth_dev *dev; 111499a2dd95SBruce Richardson int ret; 111599a2dd95SBruce Richardson 111699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 111799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 111899a2dd95SBruce Richardson 111999a2dd95SBruce Richardson ret = eth_dev_validate_tx_queue(dev, tx_queue_id); 112099a2dd95SBruce Richardson if (ret != 0) 112199a2dd95SBruce Richardson return ret; 112299a2dd95SBruce Richardson 112399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP); 112499a2dd95SBruce Richardson 112599a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) { 112699a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 112799a2dd95SBruce Richardson "Can't stop Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 112899a2dd95SBruce Richardson tx_queue_id, port_id); 112999a2dd95SBruce Richardson return -EINVAL; 113099a2dd95SBruce Richardson } 113199a2dd95SBruce Richardson 113299a2dd95SBruce Richardson if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) { 113399a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 113499a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n", 113599a2dd95SBruce Richardson tx_queue_id, port_id); 113699a2dd95SBruce Richardson return 0; 113799a2dd95SBruce Richardson } 113899a2dd95SBruce Richardson 113999a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id)); 114099a2dd95SBruce Richardson } 114199a2dd95SBruce Richardson 114299a2dd95SBruce Richardson static int 114399a2dd95SBruce Richardson eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) 114499a2dd95SBruce Richardson { 114599a2dd95SBruce Richardson uint16_t old_nb_queues = dev->data->nb_tx_queues; 114699a2dd95SBruce Richardson unsigned i; 114799a2dd95SBruce Richardson 114899a2dd95SBruce Richardson if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */ 114999a2dd95SBruce Richardson dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues", 1150c024496aSKonstantin Ananyev sizeof(dev->data->tx_queues[0]) * 1151c024496aSKonstantin Ananyev RTE_MAX_QUEUES_PER_PORT, 115299a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE); 115399a2dd95SBruce Richardson if (dev->data->tx_queues == NULL) { 115499a2dd95SBruce Richardson dev->data->nb_tx_queues = 0; 115599a2dd95SBruce Richardson return -(ENOMEM); 115699a2dd95SBruce Richardson } 115799a2dd95SBruce Richardson } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */ 115849ed3224SXueming Li for (i = nb_queues; i < old_nb_queues; i++) 115949ed3224SXueming Li eth_dev_txq_release(dev, i); 116099a2dd95SBruce Richardson 116199a2dd95SBruce Richardson } else if (dev->data->tx_queues != NULL && nb_queues == 0) { 116299a2dd95SBruce Richardson for (i = nb_queues; i < old_nb_queues; i++) 116349ed3224SXueming Li eth_dev_txq_release(dev, i); 116499a2dd95SBruce Richardson 116599a2dd95SBruce Richardson rte_free(dev->data->tx_queues); 116699a2dd95SBruce Richardson dev->data->tx_queues = NULL; 116799a2dd95SBruce Richardson } 116899a2dd95SBruce Richardson dev->data->nb_tx_queues = nb_queues; 116999a2dd95SBruce Richardson return 0; 117099a2dd95SBruce Richardson } 117199a2dd95SBruce Richardson 117299a2dd95SBruce Richardson uint32_t 117399a2dd95SBruce Richardson rte_eth_speed_bitflag(uint32_t speed, int duplex) 117499a2dd95SBruce Richardson { 117599a2dd95SBruce Richardson switch (speed) { 117699a2dd95SBruce Richardson case ETH_SPEED_NUM_10M: 117799a2dd95SBruce Richardson return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD; 117899a2dd95SBruce Richardson case ETH_SPEED_NUM_100M: 117999a2dd95SBruce Richardson return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD; 118099a2dd95SBruce Richardson case ETH_SPEED_NUM_1G: 118199a2dd95SBruce Richardson return ETH_LINK_SPEED_1G; 118299a2dd95SBruce Richardson case ETH_SPEED_NUM_2_5G: 118399a2dd95SBruce Richardson return ETH_LINK_SPEED_2_5G; 118499a2dd95SBruce Richardson case ETH_SPEED_NUM_5G: 118599a2dd95SBruce Richardson return ETH_LINK_SPEED_5G; 118699a2dd95SBruce Richardson case ETH_SPEED_NUM_10G: 118799a2dd95SBruce Richardson return ETH_LINK_SPEED_10G; 118899a2dd95SBruce Richardson case ETH_SPEED_NUM_20G: 118999a2dd95SBruce Richardson return ETH_LINK_SPEED_20G; 119099a2dd95SBruce Richardson case ETH_SPEED_NUM_25G: 119199a2dd95SBruce Richardson return ETH_LINK_SPEED_25G; 119299a2dd95SBruce Richardson case ETH_SPEED_NUM_40G: 119399a2dd95SBruce Richardson return ETH_LINK_SPEED_40G; 119499a2dd95SBruce Richardson case ETH_SPEED_NUM_50G: 119599a2dd95SBruce Richardson return ETH_LINK_SPEED_50G; 119699a2dd95SBruce Richardson case ETH_SPEED_NUM_56G: 119799a2dd95SBruce Richardson return ETH_LINK_SPEED_56G; 119899a2dd95SBruce Richardson case ETH_SPEED_NUM_100G: 119999a2dd95SBruce Richardson return ETH_LINK_SPEED_100G; 120099a2dd95SBruce Richardson case ETH_SPEED_NUM_200G: 120199a2dd95SBruce Richardson return ETH_LINK_SPEED_200G; 120299a2dd95SBruce Richardson default: 120399a2dd95SBruce Richardson return 0; 120499a2dd95SBruce Richardson } 120599a2dd95SBruce Richardson } 120699a2dd95SBruce Richardson 120799a2dd95SBruce Richardson const char * 120899a2dd95SBruce Richardson rte_eth_dev_rx_offload_name(uint64_t offload) 120999a2dd95SBruce Richardson { 121099a2dd95SBruce Richardson const char *name = "UNKNOWN"; 121199a2dd95SBruce Richardson unsigned int i; 121299a2dd95SBruce Richardson 121399a2dd95SBruce Richardson for (i = 0; i < RTE_DIM(eth_dev_rx_offload_names); ++i) { 121499a2dd95SBruce Richardson if (offload == eth_dev_rx_offload_names[i].offload) { 121599a2dd95SBruce Richardson name = eth_dev_rx_offload_names[i].name; 121699a2dd95SBruce Richardson break; 121799a2dd95SBruce Richardson } 121899a2dd95SBruce Richardson } 121999a2dd95SBruce Richardson 122099a2dd95SBruce Richardson return name; 122199a2dd95SBruce Richardson } 122299a2dd95SBruce Richardson 122399a2dd95SBruce Richardson const char * 122499a2dd95SBruce Richardson rte_eth_dev_tx_offload_name(uint64_t offload) 122599a2dd95SBruce Richardson { 122699a2dd95SBruce Richardson const char *name = "UNKNOWN"; 122799a2dd95SBruce Richardson unsigned int i; 122899a2dd95SBruce Richardson 122999a2dd95SBruce Richardson for (i = 0; i < RTE_DIM(eth_dev_tx_offload_names); ++i) { 123099a2dd95SBruce Richardson if (offload == eth_dev_tx_offload_names[i].offload) { 123199a2dd95SBruce Richardson name = eth_dev_tx_offload_names[i].name; 123299a2dd95SBruce Richardson break; 123399a2dd95SBruce Richardson } 123499a2dd95SBruce Richardson } 123599a2dd95SBruce Richardson 123699a2dd95SBruce Richardson return name; 123799a2dd95SBruce Richardson } 123899a2dd95SBruce Richardson 123999a2dd95SBruce Richardson static inline int 124099a2dd95SBruce Richardson eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size, 124199a2dd95SBruce Richardson uint32_t max_rx_pkt_len, uint32_t dev_info_size) 124299a2dd95SBruce Richardson { 124399a2dd95SBruce Richardson int ret = 0; 124499a2dd95SBruce Richardson 124599a2dd95SBruce Richardson if (dev_info_size == 0) { 124699a2dd95SBruce Richardson if (config_size != max_rx_pkt_len) { 124799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size" 124899a2dd95SBruce Richardson " %u != %u is not allowed\n", 124999a2dd95SBruce Richardson port_id, config_size, max_rx_pkt_len); 125099a2dd95SBruce Richardson ret = -EINVAL; 125199a2dd95SBruce Richardson } 125299a2dd95SBruce Richardson } else if (config_size > dev_info_size) { 125399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u " 125499a2dd95SBruce Richardson "> max allowed value %u\n", port_id, config_size, 125599a2dd95SBruce Richardson dev_info_size); 125699a2dd95SBruce Richardson ret = -EINVAL; 125799a2dd95SBruce Richardson } else if (config_size < RTE_ETHER_MIN_LEN) { 125899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u " 125999a2dd95SBruce Richardson "< min allowed value %u\n", port_id, config_size, 126099a2dd95SBruce Richardson (unsigned int)RTE_ETHER_MIN_LEN); 126199a2dd95SBruce Richardson ret = -EINVAL; 126299a2dd95SBruce Richardson } 126399a2dd95SBruce Richardson return ret; 126499a2dd95SBruce Richardson } 126599a2dd95SBruce Richardson 126699a2dd95SBruce Richardson /* 126799a2dd95SBruce Richardson * Validate offloads that are requested through rte_eth_dev_configure against 126899a2dd95SBruce Richardson * the offloads successfully set by the ethernet device. 126999a2dd95SBruce Richardson * 127099a2dd95SBruce Richardson * @param port_id 127199a2dd95SBruce Richardson * The port identifier of the Ethernet device. 127299a2dd95SBruce Richardson * @param req_offloads 127399a2dd95SBruce Richardson * The offloads that have been requested through `rte_eth_dev_configure`. 127499a2dd95SBruce Richardson * @param set_offloads 127599a2dd95SBruce Richardson * The offloads successfully set by the ethernet device. 127699a2dd95SBruce Richardson * @param offload_type 127799a2dd95SBruce Richardson * The offload type i.e. Rx/Tx string. 127899a2dd95SBruce Richardson * @param offload_name 127999a2dd95SBruce Richardson * The function that prints the offload name. 128099a2dd95SBruce Richardson * @return 128199a2dd95SBruce Richardson * - (0) if validation successful. 128299a2dd95SBruce Richardson * - (-EINVAL) if requested offload has been silently disabled. 128399a2dd95SBruce Richardson * 128499a2dd95SBruce Richardson */ 128599a2dd95SBruce Richardson static int 128699a2dd95SBruce Richardson eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads, 128799a2dd95SBruce Richardson uint64_t set_offloads, const char *offload_type, 128899a2dd95SBruce Richardson const char *(*offload_name)(uint64_t)) 128999a2dd95SBruce Richardson { 129099a2dd95SBruce Richardson uint64_t offloads_diff = req_offloads ^ set_offloads; 129199a2dd95SBruce Richardson uint64_t offload; 129299a2dd95SBruce Richardson int ret = 0; 129399a2dd95SBruce Richardson 129499a2dd95SBruce Richardson while (offloads_diff != 0) { 129599a2dd95SBruce Richardson /* Check if any offload is requested but not enabled. */ 129699a2dd95SBruce Richardson offload = 1ULL << __builtin_ctzll(offloads_diff); 129799a2dd95SBruce Richardson if (offload & req_offloads) { 129899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 129999a2dd95SBruce Richardson "Port %u failed to enable %s offload %s\n", 130099a2dd95SBruce Richardson port_id, offload_type, offload_name(offload)); 130199a2dd95SBruce Richardson ret = -EINVAL; 130299a2dd95SBruce Richardson } 130399a2dd95SBruce Richardson 130499a2dd95SBruce Richardson /* Check if offload couldn't be disabled. */ 130599a2dd95SBruce Richardson if (offload & set_offloads) { 130699a2dd95SBruce Richardson RTE_ETHDEV_LOG(DEBUG, 130799a2dd95SBruce Richardson "Port %u %s offload %s is not requested but enabled\n", 130899a2dd95SBruce Richardson port_id, offload_type, offload_name(offload)); 130999a2dd95SBruce Richardson } 131099a2dd95SBruce Richardson 131199a2dd95SBruce Richardson offloads_diff &= ~offload; 131299a2dd95SBruce Richardson } 131399a2dd95SBruce Richardson 131499a2dd95SBruce Richardson return ret; 131599a2dd95SBruce Richardson } 131699a2dd95SBruce Richardson 13171bb4a528SFerruh Yigit static uint32_t 13181bb4a528SFerruh Yigit eth_dev_get_overhead_len(uint32_t max_rx_pktlen, uint16_t max_mtu) 13191bb4a528SFerruh Yigit { 13201bb4a528SFerruh Yigit uint32_t overhead_len; 13211bb4a528SFerruh Yigit 13221bb4a528SFerruh Yigit if (max_mtu != UINT16_MAX && max_rx_pktlen > max_mtu) 13231bb4a528SFerruh Yigit overhead_len = max_rx_pktlen - max_mtu; 13241bb4a528SFerruh Yigit else 13251bb4a528SFerruh Yigit overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN; 13261bb4a528SFerruh Yigit 13271bb4a528SFerruh Yigit return overhead_len; 13281bb4a528SFerruh Yigit } 13291bb4a528SFerruh Yigit 133099a2dd95SBruce Richardson int 133199a2dd95SBruce Richardson rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, 133299a2dd95SBruce Richardson const struct rte_eth_conf *dev_conf) 133399a2dd95SBruce Richardson { 133499a2dd95SBruce Richardson struct rte_eth_dev *dev; 133599a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 133699a2dd95SBruce Richardson struct rte_eth_conf orig_conf; 13371bb4a528SFerruh Yigit uint32_t max_rx_pktlen; 13381bb4a528SFerruh Yigit uint32_t overhead_len; 133999a2dd95SBruce Richardson int diag; 134099a2dd95SBruce Richardson int ret; 134199a2dd95SBruce Richardson uint16_t old_mtu; 134299a2dd95SBruce Richardson 134399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 134499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 134599a2dd95SBruce Richardson 134653ef1b34SMin Hu (Connor) if (dev_conf == NULL) { 134753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 134853ef1b34SMin Hu (Connor) "Cannot configure ethdev port %u from NULL config\n", 134953ef1b34SMin Hu (Connor) port_id); 135053ef1b34SMin Hu (Connor) return -EINVAL; 135153ef1b34SMin Hu (Connor) } 135253ef1b34SMin Hu (Connor) 135399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP); 135499a2dd95SBruce Richardson 135599a2dd95SBruce Richardson if (dev->data->dev_started) { 135699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 135799a2dd95SBruce Richardson "Port %u must be stopped to allow configuration\n", 135899a2dd95SBruce Richardson port_id); 135999a2dd95SBruce Richardson return -EBUSY; 136099a2dd95SBruce Richardson } 136199a2dd95SBruce Richardson 136202edbfabSHuisong Li /* 136302edbfabSHuisong Li * Ensure that "dev_configured" is always 0 each time prepare to do 136402edbfabSHuisong Li * dev_configure() to avoid any non-anticipated behaviour. 136502edbfabSHuisong Li * And set to 1 when dev_configure() is executed successfully. 136602edbfabSHuisong Li */ 136702edbfabSHuisong Li dev->data->dev_configured = 0; 136802edbfabSHuisong Li 136999a2dd95SBruce Richardson /* Store original config, as rollback required on failure */ 137099a2dd95SBruce Richardson memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf)); 137199a2dd95SBruce Richardson 137299a2dd95SBruce Richardson /* 137399a2dd95SBruce Richardson * Copy the dev_conf parameter into the dev structure. 137499a2dd95SBruce Richardson * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get 137599a2dd95SBruce Richardson */ 137699a2dd95SBruce Richardson if (dev_conf != &dev->data->dev_conf) 137799a2dd95SBruce Richardson memcpy(&dev->data->dev_conf, dev_conf, 137899a2dd95SBruce Richardson sizeof(dev->data->dev_conf)); 137999a2dd95SBruce Richardson 138099a2dd95SBruce Richardson /* Backup mtu for rollback */ 138199a2dd95SBruce Richardson old_mtu = dev->data->mtu; 138299a2dd95SBruce Richardson 138399a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 138499a2dd95SBruce Richardson if (ret != 0) 138599a2dd95SBruce Richardson goto rollback; 138699a2dd95SBruce Richardson 138799a2dd95SBruce Richardson /* Get the real Ethernet overhead length */ 13881bb4a528SFerruh Yigit overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen, 13891bb4a528SFerruh Yigit dev_info.max_mtu); 139099a2dd95SBruce Richardson 139199a2dd95SBruce Richardson /* If number of queues specified by application for both Rx and Tx is 139299a2dd95SBruce Richardson * zero, use driver preferred values. This cannot be done individually 139399a2dd95SBruce Richardson * as it is valid for either Tx or Rx (but not both) to be zero. 139499a2dd95SBruce Richardson * If driver does not provide any preferred valued, fall back on 139599a2dd95SBruce Richardson * EAL defaults. 139699a2dd95SBruce Richardson */ 139799a2dd95SBruce Richardson if (nb_rx_q == 0 && nb_tx_q == 0) { 139899a2dd95SBruce Richardson nb_rx_q = dev_info.default_rxportconf.nb_queues; 139999a2dd95SBruce Richardson if (nb_rx_q == 0) 140099a2dd95SBruce Richardson nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES; 140199a2dd95SBruce Richardson nb_tx_q = dev_info.default_txportconf.nb_queues; 140299a2dd95SBruce Richardson if (nb_tx_q == 0) 140399a2dd95SBruce Richardson nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES; 140499a2dd95SBruce Richardson } 140599a2dd95SBruce Richardson 140699a2dd95SBruce Richardson if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) { 140799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 140899a2dd95SBruce Richardson "Number of RX queues requested (%u) is greater than max supported(%d)\n", 140999a2dd95SBruce Richardson nb_rx_q, RTE_MAX_QUEUES_PER_PORT); 141099a2dd95SBruce Richardson ret = -EINVAL; 141199a2dd95SBruce Richardson goto rollback; 141299a2dd95SBruce Richardson } 141399a2dd95SBruce Richardson 141499a2dd95SBruce Richardson if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) { 141599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 141699a2dd95SBruce Richardson "Number of TX queues requested (%u) is greater than max supported(%d)\n", 141799a2dd95SBruce Richardson nb_tx_q, RTE_MAX_QUEUES_PER_PORT); 141899a2dd95SBruce Richardson ret = -EINVAL; 141999a2dd95SBruce Richardson goto rollback; 142099a2dd95SBruce Richardson } 142199a2dd95SBruce Richardson 142299a2dd95SBruce Richardson /* 142399a2dd95SBruce Richardson * Check that the numbers of RX and TX queues are not greater 142499a2dd95SBruce Richardson * than the maximum number of RX and TX queues supported by the 142599a2dd95SBruce Richardson * configured device. 142699a2dd95SBruce Richardson */ 142799a2dd95SBruce Richardson if (nb_rx_q > dev_info.max_rx_queues) { 142899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u\n", 142999a2dd95SBruce Richardson port_id, nb_rx_q, dev_info.max_rx_queues); 143099a2dd95SBruce Richardson ret = -EINVAL; 143199a2dd95SBruce Richardson goto rollback; 143299a2dd95SBruce Richardson } 143399a2dd95SBruce Richardson 143499a2dd95SBruce Richardson if (nb_tx_q > dev_info.max_tx_queues) { 143599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u\n", 143699a2dd95SBruce Richardson port_id, nb_tx_q, dev_info.max_tx_queues); 143799a2dd95SBruce Richardson ret = -EINVAL; 143899a2dd95SBruce Richardson goto rollback; 143999a2dd95SBruce Richardson } 144099a2dd95SBruce Richardson 144199a2dd95SBruce Richardson /* Check that the device supports requested interrupts */ 144299a2dd95SBruce Richardson if ((dev_conf->intr_conf.lsc == 1) && 144399a2dd95SBruce Richardson (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) { 144499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Driver %s does not support lsc\n", 144599a2dd95SBruce Richardson dev->device->driver->name); 144699a2dd95SBruce Richardson ret = -EINVAL; 144799a2dd95SBruce Richardson goto rollback; 144899a2dd95SBruce Richardson } 144999a2dd95SBruce Richardson if ((dev_conf->intr_conf.rmv == 1) && 145099a2dd95SBruce Richardson (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) { 145199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Driver %s does not support rmv\n", 145299a2dd95SBruce Richardson dev->device->driver->name); 145399a2dd95SBruce Richardson ret = -EINVAL; 145499a2dd95SBruce Richardson goto rollback; 145599a2dd95SBruce Richardson } 145699a2dd95SBruce Richardson 145799a2dd95SBruce Richardson /* 14581bb4a528SFerruh Yigit * Check that the maximum RX packet length is supported by the 14591bb4a528SFerruh Yigit * configured device. 146099a2dd95SBruce Richardson */ 14611bb4a528SFerruh Yigit if (dev_conf->rxmode.mtu == 0) 14621bb4a528SFerruh Yigit dev->data->dev_conf.rxmode.mtu = RTE_ETHER_MTU; 14631bb4a528SFerruh Yigit max_rx_pktlen = dev->data->dev_conf.rxmode.mtu + overhead_len; 14641bb4a528SFerruh Yigit if (max_rx_pktlen > dev_info.max_rx_pktlen) { 146599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 14661bb4a528SFerruh Yigit "Ethdev port_id=%u max_rx_pktlen %u > max valid value %u\n", 14671bb4a528SFerruh Yigit port_id, max_rx_pktlen, dev_info.max_rx_pktlen); 146899a2dd95SBruce Richardson ret = -EINVAL; 146999a2dd95SBruce Richardson goto rollback; 14701bb4a528SFerruh Yigit } else if (max_rx_pktlen < RTE_ETHER_MIN_LEN) { 147199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 14721bb4a528SFerruh Yigit "Ethdev port_id=%u max_rx_pktlen %u < min valid value %u\n", 14731bb4a528SFerruh Yigit port_id, max_rx_pktlen, RTE_ETHER_MIN_LEN); 147499a2dd95SBruce Richardson ret = -EINVAL; 147599a2dd95SBruce Richardson goto rollback; 147699a2dd95SBruce Richardson } 147799a2dd95SBruce Richardson 14781bb4a528SFerruh Yigit dev->data->mtu = dev->data->dev_conf.rxmode.mtu; 14791bb4a528SFerruh Yigit 148099a2dd95SBruce Richardson /* 148199a2dd95SBruce Richardson * If LRO is enabled, check that the maximum aggregated packet 148299a2dd95SBruce Richardson * size is supported by the configured device. 148399a2dd95SBruce Richardson */ 148499a2dd95SBruce Richardson if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) { 148599a2dd95SBruce Richardson if (dev_conf->rxmode.max_lro_pkt_size == 0) 14861bb4a528SFerruh Yigit dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen; 148799a2dd95SBruce Richardson ret = eth_dev_check_lro_pkt_size(port_id, 148899a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_lro_pkt_size, 14891bb4a528SFerruh Yigit max_rx_pktlen, 149099a2dd95SBruce Richardson dev_info.max_lro_pkt_size); 149199a2dd95SBruce Richardson if (ret != 0) 149299a2dd95SBruce Richardson goto rollback; 149399a2dd95SBruce Richardson } 149499a2dd95SBruce Richardson 149599a2dd95SBruce Richardson /* Any requested offloading must be within its device capabilities */ 149699a2dd95SBruce Richardson if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) != 149799a2dd95SBruce Richardson dev_conf->rxmode.offloads) { 149899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 149999a2dd95SBruce Richardson "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads " 150099a2dd95SBruce Richardson "capabilities 0x%"PRIx64" in %s()\n", 150199a2dd95SBruce Richardson port_id, dev_conf->rxmode.offloads, 150299a2dd95SBruce Richardson dev_info.rx_offload_capa, 150399a2dd95SBruce Richardson __func__); 150499a2dd95SBruce Richardson ret = -EINVAL; 150599a2dd95SBruce Richardson goto rollback; 150699a2dd95SBruce Richardson } 150799a2dd95SBruce Richardson if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) != 150899a2dd95SBruce Richardson dev_conf->txmode.offloads) { 150999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 151099a2dd95SBruce Richardson "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads " 151199a2dd95SBruce Richardson "capabilities 0x%"PRIx64" in %s()\n", 151299a2dd95SBruce Richardson port_id, dev_conf->txmode.offloads, 151399a2dd95SBruce Richardson dev_info.tx_offload_capa, 151499a2dd95SBruce Richardson __func__); 151599a2dd95SBruce Richardson ret = -EINVAL; 151699a2dd95SBruce Richardson goto rollback; 151799a2dd95SBruce Richardson } 151899a2dd95SBruce Richardson 151999a2dd95SBruce Richardson dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf = 152099a2dd95SBruce Richardson rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf); 152199a2dd95SBruce Richardson 152299a2dd95SBruce Richardson /* Check that device supports requested rss hash functions. */ 152399a2dd95SBruce Richardson if ((dev_info.flow_type_rss_offloads | 152499a2dd95SBruce Richardson dev_conf->rx_adv_conf.rss_conf.rss_hf) != 152599a2dd95SBruce Richardson dev_info.flow_type_rss_offloads) { 152699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 152799a2dd95SBruce Richardson "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n", 152899a2dd95SBruce Richardson port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf, 152999a2dd95SBruce Richardson dev_info.flow_type_rss_offloads); 153099a2dd95SBruce Richardson ret = -EINVAL; 153199a2dd95SBruce Richardson goto rollback; 153299a2dd95SBruce Richardson } 153399a2dd95SBruce Richardson 153499a2dd95SBruce Richardson /* Check if Rx RSS distribution is disabled but RSS hash is enabled. */ 153599a2dd95SBruce Richardson if (((dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) == 0) && 153699a2dd95SBruce Richardson (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_RSS_HASH)) { 153799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 153899a2dd95SBruce Richardson "Ethdev port_id=%u config invalid Rx mq_mode without RSS but %s offload is requested\n", 153999a2dd95SBruce Richardson port_id, 154099a2dd95SBruce Richardson rte_eth_dev_rx_offload_name(DEV_RX_OFFLOAD_RSS_HASH)); 154199a2dd95SBruce Richardson ret = -EINVAL; 154299a2dd95SBruce Richardson goto rollback; 154399a2dd95SBruce Richardson } 154499a2dd95SBruce Richardson 154599a2dd95SBruce Richardson /* 154699a2dd95SBruce Richardson * Setup new number of RX/TX queues and reconfigure device. 154799a2dd95SBruce Richardson */ 154899a2dd95SBruce Richardson diag = eth_dev_rx_queue_config(dev, nb_rx_q); 154999a2dd95SBruce Richardson if (diag != 0) { 155099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 155199a2dd95SBruce Richardson "Port%u eth_dev_rx_queue_config = %d\n", 155299a2dd95SBruce Richardson port_id, diag); 155399a2dd95SBruce Richardson ret = diag; 155499a2dd95SBruce Richardson goto rollback; 155599a2dd95SBruce Richardson } 155699a2dd95SBruce Richardson 155799a2dd95SBruce Richardson diag = eth_dev_tx_queue_config(dev, nb_tx_q); 155899a2dd95SBruce Richardson if (diag != 0) { 155999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 156099a2dd95SBruce Richardson "Port%u eth_dev_tx_queue_config = %d\n", 156199a2dd95SBruce Richardson port_id, diag); 156299a2dd95SBruce Richardson eth_dev_rx_queue_config(dev, 0); 156399a2dd95SBruce Richardson ret = diag; 156499a2dd95SBruce Richardson goto rollback; 156599a2dd95SBruce Richardson } 156699a2dd95SBruce Richardson 156799a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_configure)(dev); 156899a2dd95SBruce Richardson if (diag != 0) { 156999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port%u dev_configure = %d\n", 157099a2dd95SBruce Richardson port_id, diag); 157199a2dd95SBruce Richardson ret = eth_err(port_id, diag); 157299a2dd95SBruce Richardson goto reset_queues; 157399a2dd95SBruce Richardson } 157499a2dd95SBruce Richardson 157599a2dd95SBruce Richardson /* Initialize Rx profiling if enabled at compilation time. */ 157699a2dd95SBruce Richardson diag = __rte_eth_dev_profile_init(port_id, dev); 157799a2dd95SBruce Richardson if (diag != 0) { 157899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port%u __rte_eth_dev_profile_init = %d\n", 157999a2dd95SBruce Richardson port_id, diag); 158099a2dd95SBruce Richardson ret = eth_err(port_id, diag); 158199a2dd95SBruce Richardson goto reset_queues; 158299a2dd95SBruce Richardson } 158399a2dd95SBruce Richardson 158499a2dd95SBruce Richardson /* Validate Rx offloads. */ 158599a2dd95SBruce Richardson diag = eth_dev_validate_offloads(port_id, 158699a2dd95SBruce Richardson dev_conf->rxmode.offloads, 158799a2dd95SBruce Richardson dev->data->dev_conf.rxmode.offloads, "Rx", 158899a2dd95SBruce Richardson rte_eth_dev_rx_offload_name); 158999a2dd95SBruce Richardson if (diag != 0) { 159099a2dd95SBruce Richardson ret = diag; 159199a2dd95SBruce Richardson goto reset_queues; 159299a2dd95SBruce Richardson } 159399a2dd95SBruce Richardson 159499a2dd95SBruce Richardson /* Validate Tx offloads. */ 159599a2dd95SBruce Richardson diag = eth_dev_validate_offloads(port_id, 159699a2dd95SBruce Richardson dev_conf->txmode.offloads, 159799a2dd95SBruce Richardson dev->data->dev_conf.txmode.offloads, "Tx", 159899a2dd95SBruce Richardson rte_eth_dev_tx_offload_name); 159999a2dd95SBruce Richardson if (diag != 0) { 160099a2dd95SBruce Richardson ret = diag; 160199a2dd95SBruce Richardson goto reset_queues; 160299a2dd95SBruce Richardson } 160399a2dd95SBruce Richardson 160402edbfabSHuisong Li dev->data->dev_configured = 1; 160599a2dd95SBruce Richardson rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0); 160699a2dd95SBruce Richardson return 0; 160799a2dd95SBruce Richardson reset_queues: 160899a2dd95SBruce Richardson eth_dev_rx_queue_config(dev, 0); 160999a2dd95SBruce Richardson eth_dev_tx_queue_config(dev, 0); 161099a2dd95SBruce Richardson rollback: 161199a2dd95SBruce Richardson memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf)); 161299a2dd95SBruce Richardson if (old_mtu != dev->data->mtu) 161399a2dd95SBruce Richardson dev->data->mtu = old_mtu; 161499a2dd95SBruce Richardson 161599a2dd95SBruce Richardson rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret); 161699a2dd95SBruce Richardson return ret; 161799a2dd95SBruce Richardson } 161899a2dd95SBruce Richardson 161999a2dd95SBruce Richardson void 162099a2dd95SBruce Richardson rte_eth_dev_internal_reset(struct rte_eth_dev *dev) 162199a2dd95SBruce Richardson { 162299a2dd95SBruce Richardson if (dev->data->dev_started) { 162399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u must be stopped to allow reset\n", 162499a2dd95SBruce Richardson dev->data->port_id); 162599a2dd95SBruce Richardson return; 162699a2dd95SBruce Richardson } 162799a2dd95SBruce Richardson 162899a2dd95SBruce Richardson eth_dev_rx_queue_config(dev, 0); 162999a2dd95SBruce Richardson eth_dev_tx_queue_config(dev, 0); 163099a2dd95SBruce Richardson 163199a2dd95SBruce Richardson memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf)); 163299a2dd95SBruce Richardson } 163399a2dd95SBruce Richardson 163499a2dd95SBruce Richardson static void 163599a2dd95SBruce Richardson eth_dev_mac_restore(struct rte_eth_dev *dev, 163699a2dd95SBruce Richardson struct rte_eth_dev_info *dev_info) 163799a2dd95SBruce Richardson { 163899a2dd95SBruce Richardson struct rte_ether_addr *addr; 163999a2dd95SBruce Richardson uint16_t i; 164099a2dd95SBruce Richardson uint32_t pool = 0; 164199a2dd95SBruce Richardson uint64_t pool_mask; 164299a2dd95SBruce Richardson 164399a2dd95SBruce Richardson /* replay MAC address configuration including default MAC */ 164499a2dd95SBruce Richardson addr = &dev->data->mac_addrs[0]; 164599a2dd95SBruce Richardson if (*dev->dev_ops->mac_addr_set != NULL) 164699a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_set)(dev, addr); 164799a2dd95SBruce Richardson else if (*dev->dev_ops->mac_addr_add != NULL) 164899a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool); 164999a2dd95SBruce Richardson 165099a2dd95SBruce Richardson if (*dev->dev_ops->mac_addr_add != NULL) { 165199a2dd95SBruce Richardson for (i = 1; i < dev_info->max_mac_addrs; i++) { 165299a2dd95SBruce Richardson addr = &dev->data->mac_addrs[i]; 165399a2dd95SBruce Richardson 165499a2dd95SBruce Richardson /* skip zero address */ 165599a2dd95SBruce Richardson if (rte_is_zero_ether_addr(addr)) 165699a2dd95SBruce Richardson continue; 165799a2dd95SBruce Richardson 165899a2dd95SBruce Richardson pool = 0; 165999a2dd95SBruce Richardson pool_mask = dev->data->mac_pool_sel[i]; 166099a2dd95SBruce Richardson 166199a2dd95SBruce Richardson do { 166299a2dd95SBruce Richardson if (pool_mask & 1ULL) 166399a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_add)(dev, 166499a2dd95SBruce Richardson addr, i, pool); 166599a2dd95SBruce Richardson pool_mask >>= 1; 166699a2dd95SBruce Richardson pool++; 166799a2dd95SBruce Richardson } while (pool_mask); 166899a2dd95SBruce Richardson } 166999a2dd95SBruce Richardson } 167099a2dd95SBruce Richardson } 167199a2dd95SBruce Richardson 167299a2dd95SBruce Richardson static int 167399a2dd95SBruce Richardson eth_dev_config_restore(struct rte_eth_dev *dev, 167499a2dd95SBruce Richardson struct rte_eth_dev_info *dev_info, uint16_t port_id) 167599a2dd95SBruce Richardson { 167699a2dd95SBruce Richardson int ret; 167799a2dd95SBruce Richardson 167899a2dd95SBruce Richardson if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR)) 167999a2dd95SBruce Richardson eth_dev_mac_restore(dev, dev_info); 168099a2dd95SBruce Richardson 168199a2dd95SBruce Richardson /* replay promiscuous configuration */ 168299a2dd95SBruce Richardson /* 168399a2dd95SBruce Richardson * use callbacks directly since we don't need port_id check and 168499a2dd95SBruce Richardson * would like to bypass the same value set 168599a2dd95SBruce Richardson */ 168699a2dd95SBruce Richardson if (rte_eth_promiscuous_get(port_id) == 1 && 168799a2dd95SBruce Richardson *dev->dev_ops->promiscuous_enable != NULL) { 168899a2dd95SBruce Richardson ret = eth_err(port_id, 168999a2dd95SBruce Richardson (*dev->dev_ops->promiscuous_enable)(dev)); 169099a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 169199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 169299a2dd95SBruce Richardson "Failed to enable promiscuous mode for device (port %u): %s\n", 169399a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 169499a2dd95SBruce Richardson return ret; 169599a2dd95SBruce Richardson } 169699a2dd95SBruce Richardson } else if (rte_eth_promiscuous_get(port_id) == 0 && 169799a2dd95SBruce Richardson *dev->dev_ops->promiscuous_disable != NULL) { 169899a2dd95SBruce Richardson ret = eth_err(port_id, 169999a2dd95SBruce Richardson (*dev->dev_ops->promiscuous_disable)(dev)); 170099a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 170199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 170299a2dd95SBruce Richardson "Failed to disable promiscuous mode for device (port %u): %s\n", 170399a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 170499a2dd95SBruce Richardson return ret; 170599a2dd95SBruce Richardson } 170699a2dd95SBruce Richardson } 170799a2dd95SBruce Richardson 170899a2dd95SBruce Richardson /* replay all multicast configuration */ 170999a2dd95SBruce Richardson /* 171099a2dd95SBruce Richardson * use callbacks directly since we don't need port_id check and 171199a2dd95SBruce Richardson * would like to bypass the same value set 171299a2dd95SBruce Richardson */ 171399a2dd95SBruce Richardson if (rte_eth_allmulticast_get(port_id) == 1 && 171499a2dd95SBruce Richardson *dev->dev_ops->allmulticast_enable != NULL) { 171599a2dd95SBruce Richardson ret = eth_err(port_id, 171699a2dd95SBruce Richardson (*dev->dev_ops->allmulticast_enable)(dev)); 171799a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 171899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 171999a2dd95SBruce Richardson "Failed to enable allmulticast mode for device (port %u): %s\n", 172099a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 172199a2dd95SBruce Richardson return ret; 172299a2dd95SBruce Richardson } 172399a2dd95SBruce Richardson } else if (rte_eth_allmulticast_get(port_id) == 0 && 172499a2dd95SBruce Richardson *dev->dev_ops->allmulticast_disable != NULL) { 172599a2dd95SBruce Richardson ret = eth_err(port_id, 172699a2dd95SBruce Richardson (*dev->dev_ops->allmulticast_disable)(dev)); 172799a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 172899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 172999a2dd95SBruce Richardson "Failed to disable allmulticast mode for device (port %u): %s\n", 173099a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 173199a2dd95SBruce Richardson return ret; 173299a2dd95SBruce Richardson } 173399a2dd95SBruce Richardson } 173499a2dd95SBruce Richardson 173599a2dd95SBruce Richardson return 0; 173699a2dd95SBruce Richardson } 173799a2dd95SBruce Richardson 173899a2dd95SBruce Richardson int 173999a2dd95SBruce Richardson rte_eth_dev_start(uint16_t port_id) 174099a2dd95SBruce Richardson { 174199a2dd95SBruce Richardson struct rte_eth_dev *dev; 174299a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 174399a2dd95SBruce Richardson int diag; 174499a2dd95SBruce Richardson int ret, ret_stop; 174599a2dd95SBruce Richardson 174699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 174799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 174899a2dd95SBruce Richardson 174999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP); 175099a2dd95SBruce Richardson 175102edbfabSHuisong Li if (dev->data->dev_configured == 0) { 175202edbfabSHuisong Li RTE_ETHDEV_LOG(INFO, 175302edbfabSHuisong Li "Device with port_id=%"PRIu16" is not configured.\n", 175402edbfabSHuisong Li port_id); 175502edbfabSHuisong Li return -EINVAL; 175602edbfabSHuisong Li } 175702edbfabSHuisong Li 175899a2dd95SBruce Richardson if (dev->data->dev_started != 0) { 175999a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 176099a2dd95SBruce Richardson "Device with port_id=%"PRIu16" already started\n", 176199a2dd95SBruce Richardson port_id); 176299a2dd95SBruce Richardson return 0; 176399a2dd95SBruce Richardson } 176499a2dd95SBruce Richardson 176599a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 176699a2dd95SBruce Richardson if (ret != 0) 176799a2dd95SBruce Richardson return ret; 176899a2dd95SBruce Richardson 176999a2dd95SBruce Richardson /* Lets restore MAC now if device does not support live change */ 177099a2dd95SBruce Richardson if (*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) 177199a2dd95SBruce Richardson eth_dev_mac_restore(dev, &dev_info); 177299a2dd95SBruce Richardson 177399a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_start)(dev); 177499a2dd95SBruce Richardson if (diag == 0) 177599a2dd95SBruce Richardson dev->data->dev_started = 1; 177699a2dd95SBruce Richardson else 177799a2dd95SBruce Richardson return eth_err(port_id, diag); 177899a2dd95SBruce Richardson 177999a2dd95SBruce Richardson ret = eth_dev_config_restore(dev, &dev_info, port_id); 178099a2dd95SBruce Richardson if (ret != 0) { 178199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 178299a2dd95SBruce Richardson "Error during restoring configuration for device (port %u): %s\n", 178399a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 178499a2dd95SBruce Richardson ret_stop = rte_eth_dev_stop(port_id); 178599a2dd95SBruce Richardson if (ret_stop != 0) { 178699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 178799a2dd95SBruce Richardson "Failed to stop device (port %u): %s\n", 178899a2dd95SBruce Richardson port_id, rte_strerror(-ret_stop)); 178999a2dd95SBruce Richardson } 179099a2dd95SBruce Richardson 179199a2dd95SBruce Richardson return ret; 179299a2dd95SBruce Richardson } 179399a2dd95SBruce Richardson 179499a2dd95SBruce Richardson if (dev->data->dev_conf.intr_conf.lsc == 0) { 179599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); 179699a2dd95SBruce Richardson (*dev->dev_ops->link_update)(dev, 0); 179799a2dd95SBruce Richardson } 179899a2dd95SBruce Richardson 1799c87d435aSKonstantin Ananyev /* expose selection of PMD fast-path functions */ 1800c87d435aSKonstantin Ananyev eth_dev_fp_ops_setup(rte_eth_fp_ops + port_id, dev); 1801c87d435aSKonstantin Ananyev 180299a2dd95SBruce Richardson rte_ethdev_trace_start(port_id); 180399a2dd95SBruce Richardson return 0; 180499a2dd95SBruce Richardson } 180599a2dd95SBruce Richardson 180699a2dd95SBruce Richardson int 180799a2dd95SBruce Richardson rte_eth_dev_stop(uint16_t port_id) 180899a2dd95SBruce Richardson { 180999a2dd95SBruce Richardson struct rte_eth_dev *dev; 181099a2dd95SBruce Richardson int ret; 181199a2dd95SBruce Richardson 181299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 181399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 181499a2dd95SBruce Richardson 181599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_stop, -ENOTSUP); 181699a2dd95SBruce Richardson 181799a2dd95SBruce Richardson if (dev->data->dev_started == 0) { 181899a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 181999a2dd95SBruce Richardson "Device with port_id=%"PRIu16" already stopped\n", 182099a2dd95SBruce Richardson port_id); 182199a2dd95SBruce Richardson return 0; 182299a2dd95SBruce Richardson } 182399a2dd95SBruce Richardson 1824c87d435aSKonstantin Ananyev /* point fast-path functions to dummy ones */ 1825c87d435aSKonstantin Ananyev eth_dev_fp_ops_reset(rte_eth_fp_ops + port_id); 1826c87d435aSKonstantin Ananyev 182799a2dd95SBruce Richardson dev->data->dev_started = 0; 182899a2dd95SBruce Richardson ret = (*dev->dev_ops->dev_stop)(dev); 182999a2dd95SBruce Richardson rte_ethdev_trace_stop(port_id, ret); 183099a2dd95SBruce Richardson 183199a2dd95SBruce Richardson return ret; 183299a2dd95SBruce Richardson } 183399a2dd95SBruce Richardson 183499a2dd95SBruce Richardson int 183599a2dd95SBruce Richardson rte_eth_dev_set_link_up(uint16_t port_id) 183699a2dd95SBruce Richardson { 183799a2dd95SBruce Richardson struct rte_eth_dev *dev; 183899a2dd95SBruce Richardson 183999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 184099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 184199a2dd95SBruce Richardson 184299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP); 184399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_set_link_up)(dev)); 184499a2dd95SBruce Richardson } 184599a2dd95SBruce Richardson 184699a2dd95SBruce Richardson int 184799a2dd95SBruce Richardson rte_eth_dev_set_link_down(uint16_t port_id) 184899a2dd95SBruce Richardson { 184999a2dd95SBruce Richardson struct rte_eth_dev *dev; 185099a2dd95SBruce Richardson 185199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 185299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 185399a2dd95SBruce Richardson 185499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP); 185599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_set_link_down)(dev)); 185699a2dd95SBruce Richardson } 185799a2dd95SBruce Richardson 185899a2dd95SBruce Richardson int 185999a2dd95SBruce Richardson rte_eth_dev_close(uint16_t port_id) 186099a2dd95SBruce Richardson { 186199a2dd95SBruce Richardson struct rte_eth_dev *dev; 186299a2dd95SBruce Richardson int firsterr, binerr; 186399a2dd95SBruce Richardson int *lasterr = &firsterr; 186499a2dd95SBruce Richardson 186599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 186699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 186799a2dd95SBruce Richardson 186899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP); 186999a2dd95SBruce Richardson *lasterr = (*dev->dev_ops->dev_close)(dev); 187099a2dd95SBruce Richardson if (*lasterr != 0) 187199a2dd95SBruce Richardson lasterr = &binerr; 187299a2dd95SBruce Richardson 187399a2dd95SBruce Richardson rte_ethdev_trace_close(port_id); 187499a2dd95SBruce Richardson *lasterr = rte_eth_dev_release_port(dev); 187599a2dd95SBruce Richardson 187699a2dd95SBruce Richardson return firsterr; 187799a2dd95SBruce Richardson } 187899a2dd95SBruce Richardson 187999a2dd95SBruce Richardson int 188099a2dd95SBruce Richardson rte_eth_dev_reset(uint16_t port_id) 188199a2dd95SBruce Richardson { 188299a2dd95SBruce Richardson struct rte_eth_dev *dev; 188399a2dd95SBruce Richardson int ret; 188499a2dd95SBruce Richardson 188599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 188699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 188799a2dd95SBruce Richardson 188899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP); 188999a2dd95SBruce Richardson 189099a2dd95SBruce Richardson ret = rte_eth_dev_stop(port_id); 189199a2dd95SBruce Richardson if (ret != 0) { 189299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 189399a2dd95SBruce Richardson "Failed to stop device (port %u) before reset: %s - ignore\n", 189499a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 189599a2dd95SBruce Richardson } 189699a2dd95SBruce Richardson ret = dev->dev_ops->dev_reset(dev); 189799a2dd95SBruce Richardson 189899a2dd95SBruce Richardson return eth_err(port_id, ret); 189999a2dd95SBruce Richardson } 190099a2dd95SBruce Richardson 190199a2dd95SBruce Richardson int 190299a2dd95SBruce Richardson rte_eth_dev_is_removed(uint16_t port_id) 190399a2dd95SBruce Richardson { 190499a2dd95SBruce Richardson struct rte_eth_dev *dev; 190599a2dd95SBruce Richardson int ret; 190699a2dd95SBruce Richardson 190799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); 190899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 190999a2dd95SBruce Richardson 191099a2dd95SBruce Richardson if (dev->state == RTE_ETH_DEV_REMOVED) 191199a2dd95SBruce Richardson return 1; 191299a2dd95SBruce Richardson 191399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0); 191499a2dd95SBruce Richardson 191599a2dd95SBruce Richardson ret = dev->dev_ops->is_removed(dev); 191699a2dd95SBruce Richardson if (ret != 0) 191799a2dd95SBruce Richardson /* Device is physically removed. */ 191899a2dd95SBruce Richardson dev->state = RTE_ETH_DEV_REMOVED; 191999a2dd95SBruce Richardson 192099a2dd95SBruce Richardson return ret; 192199a2dd95SBruce Richardson } 192299a2dd95SBruce Richardson 192399a2dd95SBruce Richardson static int 192499a2dd95SBruce Richardson rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg, 192599a2dd95SBruce Richardson uint16_t n_seg, uint32_t *mbp_buf_size, 192699a2dd95SBruce Richardson const struct rte_eth_dev_info *dev_info) 192799a2dd95SBruce Richardson { 192899a2dd95SBruce Richardson const struct rte_eth_rxseg_capa *seg_capa = &dev_info->rx_seg_capa; 192999a2dd95SBruce Richardson struct rte_mempool *mp_first; 193099a2dd95SBruce Richardson uint32_t offset_mask; 193199a2dd95SBruce Richardson uint16_t seg_idx; 193299a2dd95SBruce Richardson 193399a2dd95SBruce Richardson if (n_seg > seg_capa->max_nseg) { 193499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 193599a2dd95SBruce Richardson "Requested Rx segments %u exceed supported %u\n", 193699a2dd95SBruce Richardson n_seg, seg_capa->max_nseg); 193799a2dd95SBruce Richardson return -EINVAL; 193899a2dd95SBruce Richardson } 193999a2dd95SBruce Richardson /* 194099a2dd95SBruce Richardson * Check the sizes and offsets against buffer sizes 194199a2dd95SBruce Richardson * for each segment specified in extended configuration. 194299a2dd95SBruce Richardson */ 194399a2dd95SBruce Richardson mp_first = rx_seg[0].mp; 194499a2dd95SBruce Richardson offset_mask = (1u << seg_capa->offset_align_log2) - 1; 194599a2dd95SBruce Richardson for (seg_idx = 0; seg_idx < n_seg; seg_idx++) { 194699a2dd95SBruce Richardson struct rte_mempool *mpl = rx_seg[seg_idx].mp; 194799a2dd95SBruce Richardson uint32_t length = rx_seg[seg_idx].length; 194899a2dd95SBruce Richardson uint32_t offset = rx_seg[seg_idx].offset; 194999a2dd95SBruce Richardson 195099a2dd95SBruce Richardson if (mpl == NULL) { 195199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "null mempool pointer\n"); 195299a2dd95SBruce Richardson return -EINVAL; 195399a2dd95SBruce Richardson } 195499a2dd95SBruce Richardson if (seg_idx != 0 && mp_first != mpl && 195599a2dd95SBruce Richardson seg_capa->multi_pools == 0) { 195699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Receiving to multiple pools is not supported\n"); 195799a2dd95SBruce Richardson return -ENOTSUP; 195899a2dd95SBruce Richardson } 195999a2dd95SBruce Richardson if (offset != 0) { 196099a2dd95SBruce Richardson if (seg_capa->offset_allowed == 0) { 196199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Rx segmentation with offset is not supported\n"); 196299a2dd95SBruce Richardson return -ENOTSUP; 196399a2dd95SBruce Richardson } 196499a2dd95SBruce Richardson if (offset & offset_mask) { 196599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Rx segmentation invalid offset alignment %u, %u\n", 196699a2dd95SBruce Richardson offset, 196799a2dd95SBruce Richardson seg_capa->offset_align_log2); 196899a2dd95SBruce Richardson return -EINVAL; 196999a2dd95SBruce Richardson } 197099a2dd95SBruce Richardson } 197199a2dd95SBruce Richardson if (mpl->private_data_size < 197299a2dd95SBruce Richardson sizeof(struct rte_pktmbuf_pool_private)) { 197399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 197499a2dd95SBruce Richardson "%s private_data_size %u < %u\n", 197599a2dd95SBruce Richardson mpl->name, mpl->private_data_size, 197699a2dd95SBruce Richardson (unsigned int)sizeof 197799a2dd95SBruce Richardson (struct rte_pktmbuf_pool_private)); 197899a2dd95SBruce Richardson return -ENOSPC; 197999a2dd95SBruce Richardson } 198099a2dd95SBruce Richardson offset += seg_idx != 0 ? 0 : RTE_PKTMBUF_HEADROOM; 198199a2dd95SBruce Richardson *mbp_buf_size = rte_pktmbuf_data_room_size(mpl); 198299a2dd95SBruce Richardson length = length != 0 ? length : *mbp_buf_size; 198399a2dd95SBruce Richardson if (*mbp_buf_size < length + offset) { 198499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 198599a2dd95SBruce Richardson "%s mbuf_data_room_size %u < %u (segment length=%u + segment offset=%u)\n", 198699a2dd95SBruce Richardson mpl->name, *mbp_buf_size, 198799a2dd95SBruce Richardson length + offset, length, offset); 198899a2dd95SBruce Richardson return -EINVAL; 198999a2dd95SBruce Richardson } 199099a2dd95SBruce Richardson } 199199a2dd95SBruce Richardson return 0; 199299a2dd95SBruce Richardson } 199399a2dd95SBruce Richardson 199499a2dd95SBruce Richardson int 199599a2dd95SBruce Richardson rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id, 199699a2dd95SBruce Richardson uint16_t nb_rx_desc, unsigned int socket_id, 199799a2dd95SBruce Richardson const struct rte_eth_rxconf *rx_conf, 199899a2dd95SBruce Richardson struct rte_mempool *mp) 199999a2dd95SBruce Richardson { 200099a2dd95SBruce Richardson int ret; 200199a2dd95SBruce Richardson uint32_t mbp_buf_size; 200299a2dd95SBruce Richardson struct rte_eth_dev *dev; 200399a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 200499a2dd95SBruce Richardson struct rte_eth_rxconf local_conf; 200599a2dd95SBruce Richardson 200699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 200799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 200853ef1b34SMin Hu (Connor) 200999a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 201099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id); 201199a2dd95SBruce Richardson return -EINVAL; 201299a2dd95SBruce Richardson } 201399a2dd95SBruce Richardson 201499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP); 201599a2dd95SBruce Richardson 201699a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 201799a2dd95SBruce Richardson if (ret != 0) 201899a2dd95SBruce Richardson return ret; 201999a2dd95SBruce Richardson 202099a2dd95SBruce Richardson if (mp != NULL) { 202199a2dd95SBruce Richardson /* Single pool configuration check. */ 202299a2dd95SBruce Richardson if (rx_conf != NULL && rx_conf->rx_nseg != 0) { 202399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 202499a2dd95SBruce Richardson "Ambiguous segment configuration\n"); 202599a2dd95SBruce Richardson return -EINVAL; 202699a2dd95SBruce Richardson } 202799a2dd95SBruce Richardson /* 202899a2dd95SBruce Richardson * Check the size of the mbuf data buffer, this value 202999a2dd95SBruce Richardson * must be provided in the private data of the memory pool. 203099a2dd95SBruce Richardson * First check that the memory pool(s) has a valid private data. 203199a2dd95SBruce Richardson */ 203299a2dd95SBruce Richardson if (mp->private_data_size < 203399a2dd95SBruce Richardson sizeof(struct rte_pktmbuf_pool_private)) { 203499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "%s private_data_size %u < %u\n", 203599a2dd95SBruce Richardson mp->name, mp->private_data_size, 203699a2dd95SBruce Richardson (unsigned int) 203799a2dd95SBruce Richardson sizeof(struct rte_pktmbuf_pool_private)); 203899a2dd95SBruce Richardson return -ENOSPC; 203999a2dd95SBruce Richardson } 204099a2dd95SBruce Richardson mbp_buf_size = rte_pktmbuf_data_room_size(mp); 204199a2dd95SBruce Richardson if (mbp_buf_size < dev_info.min_rx_bufsize + 204299a2dd95SBruce Richardson RTE_PKTMBUF_HEADROOM) { 204399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 204499a2dd95SBruce Richardson "%s mbuf_data_room_size %u < %u (RTE_PKTMBUF_HEADROOM=%u + min_rx_bufsize(dev)=%u)\n", 204599a2dd95SBruce Richardson mp->name, mbp_buf_size, 204699a2dd95SBruce Richardson RTE_PKTMBUF_HEADROOM + 204799a2dd95SBruce Richardson dev_info.min_rx_bufsize, 204899a2dd95SBruce Richardson RTE_PKTMBUF_HEADROOM, 204999a2dd95SBruce Richardson dev_info.min_rx_bufsize); 205099a2dd95SBruce Richardson return -EINVAL; 205199a2dd95SBruce Richardson } 205299a2dd95SBruce Richardson } else { 205399a2dd95SBruce Richardson const struct rte_eth_rxseg_split *rx_seg; 205499a2dd95SBruce Richardson uint16_t n_seg; 205599a2dd95SBruce Richardson 205699a2dd95SBruce Richardson /* Extended multi-segment configuration check. */ 205799a2dd95SBruce Richardson if (rx_conf == NULL || rx_conf->rx_seg == NULL || rx_conf->rx_nseg == 0) { 205899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 205999a2dd95SBruce Richardson "Memory pool is null and no extended configuration provided\n"); 206099a2dd95SBruce Richardson return -EINVAL; 206199a2dd95SBruce Richardson } 206299a2dd95SBruce Richardson 206399a2dd95SBruce Richardson rx_seg = (const struct rte_eth_rxseg_split *)rx_conf->rx_seg; 206499a2dd95SBruce Richardson n_seg = rx_conf->rx_nseg; 206599a2dd95SBruce Richardson 206699a2dd95SBruce Richardson if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) { 206799a2dd95SBruce Richardson ret = rte_eth_rx_queue_check_split(rx_seg, n_seg, 206899a2dd95SBruce Richardson &mbp_buf_size, 206999a2dd95SBruce Richardson &dev_info); 207099a2dd95SBruce Richardson if (ret != 0) 207199a2dd95SBruce Richardson return ret; 207299a2dd95SBruce Richardson } else { 207399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "No Rx segmentation offload configured\n"); 207499a2dd95SBruce Richardson return -EINVAL; 207599a2dd95SBruce Richardson } 207699a2dd95SBruce Richardson } 207799a2dd95SBruce Richardson 207899a2dd95SBruce Richardson /* Use default specified by driver, if nb_rx_desc is zero */ 207999a2dd95SBruce Richardson if (nb_rx_desc == 0) { 208099a2dd95SBruce Richardson nb_rx_desc = dev_info.default_rxportconf.ring_size; 208199a2dd95SBruce Richardson /* If driver default is also zero, fall back on EAL default */ 208299a2dd95SBruce Richardson if (nb_rx_desc == 0) 208399a2dd95SBruce Richardson nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE; 208499a2dd95SBruce Richardson } 208599a2dd95SBruce Richardson 208699a2dd95SBruce Richardson if (nb_rx_desc > dev_info.rx_desc_lim.nb_max || 208799a2dd95SBruce Richardson nb_rx_desc < dev_info.rx_desc_lim.nb_min || 208899a2dd95SBruce Richardson nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) { 208999a2dd95SBruce Richardson 209099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 209199a2dd95SBruce Richardson "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n", 209299a2dd95SBruce Richardson nb_rx_desc, dev_info.rx_desc_lim.nb_max, 209399a2dd95SBruce Richardson dev_info.rx_desc_lim.nb_min, 209499a2dd95SBruce Richardson dev_info.rx_desc_lim.nb_align); 209599a2dd95SBruce Richardson return -EINVAL; 209699a2dd95SBruce Richardson } 209799a2dd95SBruce Richardson 209899a2dd95SBruce Richardson if (dev->data->dev_started && 209999a2dd95SBruce Richardson !(dev_info.dev_capa & 210099a2dd95SBruce Richardson RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP)) 210199a2dd95SBruce Richardson return -EBUSY; 210299a2dd95SBruce Richardson 210399a2dd95SBruce Richardson if (dev->data->dev_started && 210499a2dd95SBruce Richardson (dev->data->rx_queue_state[rx_queue_id] != 210599a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_STOPPED)) 210699a2dd95SBruce Richardson return -EBUSY; 210799a2dd95SBruce Richardson 210849ed3224SXueming Li eth_dev_rxq_release(dev, rx_queue_id); 210999a2dd95SBruce Richardson 211099a2dd95SBruce Richardson if (rx_conf == NULL) 211199a2dd95SBruce Richardson rx_conf = &dev_info.default_rxconf; 211299a2dd95SBruce Richardson 211399a2dd95SBruce Richardson local_conf = *rx_conf; 211499a2dd95SBruce Richardson 211599a2dd95SBruce Richardson /* 211699a2dd95SBruce Richardson * If an offloading has already been enabled in 211799a2dd95SBruce Richardson * rte_eth_dev_configure(), it has been enabled on all queues, 211899a2dd95SBruce Richardson * so there is no need to enable it in this queue again. 211999a2dd95SBruce Richardson * The local_conf.offloads input to underlying PMD only carries 212099a2dd95SBruce Richardson * those offloadings which are only enabled on this queue and 212199a2dd95SBruce Richardson * not enabled on all queues. 212299a2dd95SBruce Richardson */ 212399a2dd95SBruce Richardson local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads; 212499a2dd95SBruce Richardson 212599a2dd95SBruce Richardson /* 212699a2dd95SBruce Richardson * New added offloadings for this queue are those not enabled in 212799a2dd95SBruce Richardson * rte_eth_dev_configure() and they must be per-queue type. 212899a2dd95SBruce Richardson * A pure per-port offloading can't be enabled on a queue while 212999a2dd95SBruce Richardson * disabled on another queue. A pure per-port offloading can't 213099a2dd95SBruce Richardson * be enabled for any queue as new added one if it hasn't been 213199a2dd95SBruce Richardson * enabled in rte_eth_dev_configure(). 213299a2dd95SBruce Richardson */ 213399a2dd95SBruce Richardson if ((local_conf.offloads & dev_info.rx_queue_offload_capa) != 213499a2dd95SBruce Richardson local_conf.offloads) { 213599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 213699a2dd95SBruce Richardson "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be " 213799a2dd95SBruce Richardson "within per-queue offload capabilities 0x%"PRIx64" in %s()\n", 213899a2dd95SBruce Richardson port_id, rx_queue_id, local_conf.offloads, 213999a2dd95SBruce Richardson dev_info.rx_queue_offload_capa, 214099a2dd95SBruce Richardson __func__); 214199a2dd95SBruce Richardson return -EINVAL; 214299a2dd95SBruce Richardson } 214399a2dd95SBruce Richardson 214499a2dd95SBruce Richardson /* 214599a2dd95SBruce Richardson * If LRO is enabled, check that the maximum aggregated packet 214699a2dd95SBruce Richardson * size is supported by the configured device. 214799a2dd95SBruce Richardson */ 21481bb4a528SFerruh Yigit /* Get the real Ethernet overhead length */ 214999a2dd95SBruce Richardson if (local_conf.offloads & DEV_RX_OFFLOAD_TCP_LRO) { 21501bb4a528SFerruh Yigit uint32_t overhead_len; 21511bb4a528SFerruh Yigit uint32_t max_rx_pktlen; 21521bb4a528SFerruh Yigit int ret; 21531bb4a528SFerruh Yigit 21541bb4a528SFerruh Yigit overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen, 21551bb4a528SFerruh Yigit dev_info.max_mtu); 21561bb4a528SFerruh Yigit max_rx_pktlen = dev->data->mtu + overhead_len; 215799a2dd95SBruce Richardson if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0) 21581bb4a528SFerruh Yigit dev->data->dev_conf.rxmode.max_lro_pkt_size = max_rx_pktlen; 21591bb4a528SFerruh Yigit ret = eth_dev_check_lro_pkt_size(port_id, 216099a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_lro_pkt_size, 21611bb4a528SFerruh Yigit max_rx_pktlen, 216299a2dd95SBruce Richardson dev_info.max_lro_pkt_size); 216399a2dd95SBruce Richardson if (ret != 0) 216499a2dd95SBruce Richardson return ret; 216599a2dd95SBruce Richardson } 216699a2dd95SBruce Richardson 216799a2dd95SBruce Richardson ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc, 216899a2dd95SBruce Richardson socket_id, &local_conf, mp); 216999a2dd95SBruce Richardson if (!ret) { 217099a2dd95SBruce Richardson if (!dev->data->min_rx_buf_size || 217199a2dd95SBruce Richardson dev->data->min_rx_buf_size > mbp_buf_size) 217299a2dd95SBruce Richardson dev->data->min_rx_buf_size = mbp_buf_size; 217399a2dd95SBruce Richardson } 217499a2dd95SBruce Richardson 217599a2dd95SBruce Richardson rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp, 217699a2dd95SBruce Richardson rx_conf, ret); 217799a2dd95SBruce Richardson return eth_err(port_id, ret); 217899a2dd95SBruce Richardson } 217999a2dd95SBruce Richardson 218099a2dd95SBruce Richardson int 218199a2dd95SBruce Richardson rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id, 218299a2dd95SBruce Richardson uint16_t nb_rx_desc, 218399a2dd95SBruce Richardson const struct rte_eth_hairpin_conf *conf) 218499a2dd95SBruce Richardson { 218599a2dd95SBruce Richardson int ret; 218699a2dd95SBruce Richardson struct rte_eth_dev *dev; 218799a2dd95SBruce Richardson struct rte_eth_hairpin_cap cap; 218899a2dd95SBruce Richardson int i; 218999a2dd95SBruce Richardson int count; 219099a2dd95SBruce Richardson 219199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 219299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 219353ef1b34SMin Hu (Connor) 219499a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 219599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id); 219699a2dd95SBruce Richardson return -EINVAL; 219799a2dd95SBruce Richardson } 219853ef1b34SMin Hu (Connor) 219953ef1b34SMin Hu (Connor) if (conf == NULL) { 220053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 220153ef1b34SMin Hu (Connor) "Cannot setup ethdev port %u Rx hairpin queue from NULL config\n", 220253ef1b34SMin Hu (Connor) port_id); 220353ef1b34SMin Hu (Connor) return -EINVAL; 220453ef1b34SMin Hu (Connor) } 220553ef1b34SMin Hu (Connor) 220699a2dd95SBruce Richardson ret = rte_eth_dev_hairpin_capability_get(port_id, &cap); 220799a2dd95SBruce Richardson if (ret != 0) 220899a2dd95SBruce Richardson return ret; 220999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_hairpin_queue_setup, 221099a2dd95SBruce Richardson -ENOTSUP); 221199a2dd95SBruce Richardson /* if nb_rx_desc is zero use max number of desc from the driver. */ 221299a2dd95SBruce Richardson if (nb_rx_desc == 0) 221399a2dd95SBruce Richardson nb_rx_desc = cap.max_nb_desc; 221499a2dd95SBruce Richardson if (nb_rx_desc > cap.max_nb_desc) { 221599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 221699a2dd95SBruce Richardson "Invalid value for nb_rx_desc(=%hu), should be: <= %hu", 221799a2dd95SBruce Richardson nb_rx_desc, cap.max_nb_desc); 221899a2dd95SBruce Richardson return -EINVAL; 221999a2dd95SBruce Richardson } 222099a2dd95SBruce Richardson if (conf->peer_count > cap.max_rx_2_tx) { 222199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 222299a2dd95SBruce Richardson "Invalid value for number of peers for Rx queue(=%u), should be: <= %hu", 222399a2dd95SBruce Richardson conf->peer_count, cap.max_rx_2_tx); 222499a2dd95SBruce Richardson return -EINVAL; 222599a2dd95SBruce Richardson } 222699a2dd95SBruce Richardson if (conf->peer_count == 0) { 222799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 222899a2dd95SBruce Richardson "Invalid value for number of peers for Rx queue(=%u), should be: > 0", 222999a2dd95SBruce Richardson conf->peer_count); 223099a2dd95SBruce Richardson return -EINVAL; 223199a2dd95SBruce Richardson } 223299a2dd95SBruce Richardson for (i = 0, count = 0; i < dev->data->nb_rx_queues && 223399a2dd95SBruce Richardson cap.max_nb_queues != UINT16_MAX; i++) { 223499a2dd95SBruce Richardson if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i)) 223599a2dd95SBruce Richardson count++; 223699a2dd95SBruce Richardson } 223799a2dd95SBruce Richardson if (count > cap.max_nb_queues) { 223899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "To many Rx hairpin queues max is %d", 223999a2dd95SBruce Richardson cap.max_nb_queues); 224099a2dd95SBruce Richardson return -EINVAL; 224199a2dd95SBruce Richardson } 224299a2dd95SBruce Richardson if (dev->data->dev_started) 224399a2dd95SBruce Richardson return -EBUSY; 224449ed3224SXueming Li eth_dev_rxq_release(dev, rx_queue_id); 224599a2dd95SBruce Richardson ret = (*dev->dev_ops->rx_hairpin_queue_setup)(dev, rx_queue_id, 224699a2dd95SBruce Richardson nb_rx_desc, conf); 224799a2dd95SBruce Richardson if (ret == 0) 224899a2dd95SBruce Richardson dev->data->rx_queue_state[rx_queue_id] = 224999a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_HAIRPIN; 225099a2dd95SBruce Richardson return eth_err(port_id, ret); 225199a2dd95SBruce Richardson } 225299a2dd95SBruce Richardson 225399a2dd95SBruce Richardson int 225499a2dd95SBruce Richardson rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id, 225599a2dd95SBruce Richardson uint16_t nb_tx_desc, unsigned int socket_id, 225699a2dd95SBruce Richardson const struct rte_eth_txconf *tx_conf) 225799a2dd95SBruce Richardson { 225899a2dd95SBruce Richardson struct rte_eth_dev *dev; 225999a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 226099a2dd95SBruce Richardson struct rte_eth_txconf local_conf; 226199a2dd95SBruce Richardson int ret; 226299a2dd95SBruce Richardson 226399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 226499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 226553ef1b34SMin Hu (Connor) 226699a2dd95SBruce Richardson if (tx_queue_id >= dev->data->nb_tx_queues) { 226799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id); 226899a2dd95SBruce Richardson return -EINVAL; 226999a2dd95SBruce Richardson } 227099a2dd95SBruce Richardson 227199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP); 227299a2dd95SBruce Richardson 227399a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 227499a2dd95SBruce Richardson if (ret != 0) 227599a2dd95SBruce Richardson return ret; 227699a2dd95SBruce Richardson 227799a2dd95SBruce Richardson /* Use default specified by driver, if nb_tx_desc is zero */ 227899a2dd95SBruce Richardson if (nb_tx_desc == 0) { 227999a2dd95SBruce Richardson nb_tx_desc = dev_info.default_txportconf.ring_size; 228099a2dd95SBruce Richardson /* If driver default is zero, fall back on EAL default */ 228199a2dd95SBruce Richardson if (nb_tx_desc == 0) 228299a2dd95SBruce Richardson nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE; 228399a2dd95SBruce Richardson } 228499a2dd95SBruce Richardson if (nb_tx_desc > dev_info.tx_desc_lim.nb_max || 228599a2dd95SBruce Richardson nb_tx_desc < dev_info.tx_desc_lim.nb_min || 228699a2dd95SBruce Richardson nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) { 228799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 228899a2dd95SBruce Richardson "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n", 228999a2dd95SBruce Richardson nb_tx_desc, dev_info.tx_desc_lim.nb_max, 229099a2dd95SBruce Richardson dev_info.tx_desc_lim.nb_min, 229199a2dd95SBruce Richardson dev_info.tx_desc_lim.nb_align); 229299a2dd95SBruce Richardson return -EINVAL; 229399a2dd95SBruce Richardson } 229499a2dd95SBruce Richardson 229599a2dd95SBruce Richardson if (dev->data->dev_started && 229699a2dd95SBruce Richardson !(dev_info.dev_capa & 229799a2dd95SBruce Richardson RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP)) 229899a2dd95SBruce Richardson return -EBUSY; 229999a2dd95SBruce Richardson 230099a2dd95SBruce Richardson if (dev->data->dev_started && 230199a2dd95SBruce Richardson (dev->data->tx_queue_state[tx_queue_id] != 230299a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_STOPPED)) 230399a2dd95SBruce Richardson return -EBUSY; 230499a2dd95SBruce Richardson 230549ed3224SXueming Li eth_dev_txq_release(dev, tx_queue_id); 230699a2dd95SBruce Richardson 230799a2dd95SBruce Richardson if (tx_conf == NULL) 230899a2dd95SBruce Richardson tx_conf = &dev_info.default_txconf; 230999a2dd95SBruce Richardson 231099a2dd95SBruce Richardson local_conf = *tx_conf; 231199a2dd95SBruce Richardson 231299a2dd95SBruce Richardson /* 231399a2dd95SBruce Richardson * If an offloading has already been enabled in 231499a2dd95SBruce Richardson * rte_eth_dev_configure(), it has been enabled on all queues, 231599a2dd95SBruce Richardson * so there is no need to enable it in this queue again. 231699a2dd95SBruce Richardson * The local_conf.offloads input to underlying PMD only carries 231799a2dd95SBruce Richardson * those offloadings which are only enabled on this queue and 231899a2dd95SBruce Richardson * not enabled on all queues. 231999a2dd95SBruce Richardson */ 232099a2dd95SBruce Richardson local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads; 232199a2dd95SBruce Richardson 232299a2dd95SBruce Richardson /* 232399a2dd95SBruce Richardson * New added offloadings for this queue are those not enabled in 232499a2dd95SBruce Richardson * rte_eth_dev_configure() and they must be per-queue type. 232599a2dd95SBruce Richardson * A pure per-port offloading can't be enabled on a queue while 232699a2dd95SBruce Richardson * disabled on another queue. A pure per-port offloading can't 232799a2dd95SBruce Richardson * be enabled for any queue as new added one if it hasn't been 232899a2dd95SBruce Richardson * enabled in rte_eth_dev_configure(). 232999a2dd95SBruce Richardson */ 233099a2dd95SBruce Richardson if ((local_conf.offloads & dev_info.tx_queue_offload_capa) != 233199a2dd95SBruce Richardson local_conf.offloads) { 233299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 233399a2dd95SBruce Richardson "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be " 233499a2dd95SBruce Richardson "within per-queue offload capabilities 0x%"PRIx64" in %s()\n", 233599a2dd95SBruce Richardson port_id, tx_queue_id, local_conf.offloads, 233699a2dd95SBruce Richardson dev_info.tx_queue_offload_capa, 233799a2dd95SBruce Richardson __func__); 233899a2dd95SBruce Richardson return -EINVAL; 233999a2dd95SBruce Richardson } 234099a2dd95SBruce Richardson 234199a2dd95SBruce Richardson rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf); 234299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->tx_queue_setup)(dev, 234399a2dd95SBruce Richardson tx_queue_id, nb_tx_desc, socket_id, &local_conf)); 234499a2dd95SBruce Richardson } 234599a2dd95SBruce Richardson 234699a2dd95SBruce Richardson int 234799a2dd95SBruce Richardson rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id, 234899a2dd95SBruce Richardson uint16_t nb_tx_desc, 234999a2dd95SBruce Richardson const struct rte_eth_hairpin_conf *conf) 235099a2dd95SBruce Richardson { 235199a2dd95SBruce Richardson struct rte_eth_dev *dev; 235299a2dd95SBruce Richardson struct rte_eth_hairpin_cap cap; 235399a2dd95SBruce Richardson int i; 235499a2dd95SBruce Richardson int count; 235599a2dd95SBruce Richardson int ret; 235699a2dd95SBruce Richardson 235799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 235899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 235953ef1b34SMin Hu (Connor) 236099a2dd95SBruce Richardson if (tx_queue_id >= dev->data->nb_tx_queues) { 236199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id); 236299a2dd95SBruce Richardson return -EINVAL; 236399a2dd95SBruce Richardson } 236453ef1b34SMin Hu (Connor) 236553ef1b34SMin Hu (Connor) if (conf == NULL) { 236653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 236753ef1b34SMin Hu (Connor) "Cannot setup ethdev port %u Tx hairpin queue from NULL config\n", 236853ef1b34SMin Hu (Connor) port_id); 236953ef1b34SMin Hu (Connor) return -EINVAL; 237053ef1b34SMin Hu (Connor) } 237153ef1b34SMin Hu (Connor) 237299a2dd95SBruce Richardson ret = rte_eth_dev_hairpin_capability_get(port_id, &cap); 237399a2dd95SBruce Richardson if (ret != 0) 237499a2dd95SBruce Richardson return ret; 237599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_hairpin_queue_setup, 237699a2dd95SBruce Richardson -ENOTSUP); 237799a2dd95SBruce Richardson /* if nb_rx_desc is zero use max number of desc from the driver. */ 237899a2dd95SBruce Richardson if (nb_tx_desc == 0) 237999a2dd95SBruce Richardson nb_tx_desc = cap.max_nb_desc; 238099a2dd95SBruce Richardson if (nb_tx_desc > cap.max_nb_desc) { 238199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 238299a2dd95SBruce Richardson "Invalid value for nb_tx_desc(=%hu), should be: <= %hu", 238399a2dd95SBruce Richardson nb_tx_desc, cap.max_nb_desc); 238499a2dd95SBruce Richardson return -EINVAL; 238599a2dd95SBruce Richardson } 238699a2dd95SBruce Richardson if (conf->peer_count > cap.max_tx_2_rx) { 238799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 238899a2dd95SBruce Richardson "Invalid value for number of peers for Tx queue(=%u), should be: <= %hu", 238999a2dd95SBruce Richardson conf->peer_count, cap.max_tx_2_rx); 239099a2dd95SBruce Richardson return -EINVAL; 239199a2dd95SBruce Richardson } 239299a2dd95SBruce Richardson if (conf->peer_count == 0) { 239399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 239499a2dd95SBruce Richardson "Invalid value for number of peers for Tx queue(=%u), should be: > 0", 239599a2dd95SBruce Richardson conf->peer_count); 239699a2dd95SBruce Richardson return -EINVAL; 239799a2dd95SBruce Richardson } 239899a2dd95SBruce Richardson for (i = 0, count = 0; i < dev->data->nb_tx_queues && 239999a2dd95SBruce Richardson cap.max_nb_queues != UINT16_MAX; i++) { 240099a2dd95SBruce Richardson if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i)) 240199a2dd95SBruce Richardson count++; 240299a2dd95SBruce Richardson } 240399a2dd95SBruce Richardson if (count > cap.max_nb_queues) { 240499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "To many Tx hairpin queues max is %d", 240599a2dd95SBruce Richardson cap.max_nb_queues); 240699a2dd95SBruce Richardson return -EINVAL; 240799a2dd95SBruce Richardson } 240899a2dd95SBruce Richardson if (dev->data->dev_started) 240999a2dd95SBruce Richardson return -EBUSY; 241049ed3224SXueming Li eth_dev_txq_release(dev, tx_queue_id); 241199a2dd95SBruce Richardson ret = (*dev->dev_ops->tx_hairpin_queue_setup) 241299a2dd95SBruce Richardson (dev, tx_queue_id, nb_tx_desc, conf); 241399a2dd95SBruce Richardson if (ret == 0) 241499a2dd95SBruce Richardson dev->data->tx_queue_state[tx_queue_id] = 241599a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_HAIRPIN; 241699a2dd95SBruce Richardson return eth_err(port_id, ret); 241799a2dd95SBruce Richardson } 241899a2dd95SBruce Richardson 241999a2dd95SBruce Richardson int 242099a2dd95SBruce Richardson rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port) 242199a2dd95SBruce Richardson { 242299a2dd95SBruce Richardson struct rte_eth_dev *dev; 242399a2dd95SBruce Richardson int ret; 242499a2dd95SBruce Richardson 242599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV); 242699a2dd95SBruce Richardson dev = &rte_eth_devices[tx_port]; 242753ef1b34SMin Hu (Connor) 242899a2dd95SBruce Richardson if (dev->data->dev_started == 0) { 242999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Tx port %d is not started\n", tx_port); 243099a2dd95SBruce Richardson return -EBUSY; 243199a2dd95SBruce Richardson } 243299a2dd95SBruce Richardson 243399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_bind, -ENOTSUP); 243499a2dd95SBruce Richardson ret = (*dev->dev_ops->hairpin_bind)(dev, rx_port); 243599a2dd95SBruce Richardson if (ret != 0) 243699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Failed to bind hairpin Tx %d" 243799a2dd95SBruce Richardson " to Rx %d (%d - all ports)\n", 243899a2dd95SBruce Richardson tx_port, rx_port, RTE_MAX_ETHPORTS); 243999a2dd95SBruce Richardson 244099a2dd95SBruce Richardson return ret; 244199a2dd95SBruce Richardson } 244299a2dd95SBruce Richardson 244399a2dd95SBruce Richardson int 244499a2dd95SBruce Richardson rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port) 244599a2dd95SBruce Richardson { 244699a2dd95SBruce Richardson struct rte_eth_dev *dev; 244799a2dd95SBruce Richardson int ret; 244899a2dd95SBruce Richardson 244999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV); 245099a2dd95SBruce Richardson dev = &rte_eth_devices[tx_port]; 245153ef1b34SMin Hu (Connor) 245299a2dd95SBruce Richardson if (dev->data->dev_started == 0) { 245399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Tx port %d is already stopped\n", tx_port); 245499a2dd95SBruce Richardson return -EBUSY; 245599a2dd95SBruce Richardson } 245699a2dd95SBruce Richardson 245799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_unbind, -ENOTSUP); 245899a2dd95SBruce Richardson ret = (*dev->dev_ops->hairpin_unbind)(dev, rx_port); 245999a2dd95SBruce Richardson if (ret != 0) 246099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Failed to unbind hairpin Tx %d" 246199a2dd95SBruce Richardson " from Rx %d (%d - all ports)\n", 246299a2dd95SBruce Richardson tx_port, rx_port, RTE_MAX_ETHPORTS); 246399a2dd95SBruce Richardson 246499a2dd95SBruce Richardson return ret; 246599a2dd95SBruce Richardson } 246699a2dd95SBruce Richardson 246799a2dd95SBruce Richardson int 246899a2dd95SBruce Richardson rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports, 246999a2dd95SBruce Richardson size_t len, uint32_t direction) 247099a2dd95SBruce Richardson { 247199a2dd95SBruce Richardson struct rte_eth_dev *dev; 247299a2dd95SBruce Richardson int ret; 247399a2dd95SBruce Richardson 247499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 247599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 247653ef1b34SMin Hu (Connor) 247753ef1b34SMin Hu (Connor) if (peer_ports == NULL) { 247853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 247953ef1b34SMin Hu (Connor) "Cannot get ethdev port %u hairpin peer ports to NULL\n", 248053ef1b34SMin Hu (Connor) port_id); 248153ef1b34SMin Hu (Connor) return -EINVAL; 248253ef1b34SMin Hu (Connor) } 248353ef1b34SMin Hu (Connor) 248453ef1b34SMin Hu (Connor) if (len == 0) { 248553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 248653ef1b34SMin Hu (Connor) "Cannot get ethdev port %u hairpin peer ports to array with zero size\n", 248753ef1b34SMin Hu (Connor) port_id); 248853ef1b34SMin Hu (Connor) return -EINVAL; 248953ef1b34SMin Hu (Connor) } 249053ef1b34SMin Hu (Connor) 249199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_get_peer_ports, 249299a2dd95SBruce Richardson -ENOTSUP); 249399a2dd95SBruce Richardson 249499a2dd95SBruce Richardson ret = (*dev->dev_ops->hairpin_get_peer_ports)(dev, peer_ports, 249599a2dd95SBruce Richardson len, direction); 249699a2dd95SBruce Richardson if (ret < 0) 249799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Failed to get %d hairpin peer %s ports\n", 249899a2dd95SBruce Richardson port_id, direction ? "Rx" : "Tx"); 249999a2dd95SBruce Richardson 250099a2dd95SBruce Richardson return ret; 250199a2dd95SBruce Richardson } 250299a2dd95SBruce Richardson 250399a2dd95SBruce Richardson void 250499a2dd95SBruce Richardson rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent, 250599a2dd95SBruce Richardson void *userdata __rte_unused) 250699a2dd95SBruce Richardson { 250799a2dd95SBruce Richardson rte_pktmbuf_free_bulk(pkts, unsent); 250899a2dd95SBruce Richardson } 250999a2dd95SBruce Richardson 251099a2dd95SBruce Richardson void 251199a2dd95SBruce Richardson rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent, 251299a2dd95SBruce Richardson void *userdata) 251399a2dd95SBruce Richardson { 251499a2dd95SBruce Richardson uint64_t *count = userdata; 251599a2dd95SBruce Richardson 251699a2dd95SBruce Richardson rte_pktmbuf_free_bulk(pkts, unsent); 251799a2dd95SBruce Richardson *count += unsent; 251899a2dd95SBruce Richardson } 251999a2dd95SBruce Richardson 252099a2dd95SBruce Richardson int 252199a2dd95SBruce Richardson rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer, 252299a2dd95SBruce Richardson buffer_tx_error_fn cbfn, void *userdata) 252399a2dd95SBruce Richardson { 252453ef1b34SMin Hu (Connor) if (buffer == NULL) { 252553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 252653ef1b34SMin Hu (Connor) "Cannot set Tx buffer error callback to NULL buffer\n"); 252753ef1b34SMin Hu (Connor) return -EINVAL; 252853ef1b34SMin Hu (Connor) } 252953ef1b34SMin Hu (Connor) 253099a2dd95SBruce Richardson buffer->error_callback = cbfn; 253199a2dd95SBruce Richardson buffer->error_userdata = userdata; 253299a2dd95SBruce Richardson return 0; 253399a2dd95SBruce Richardson } 253499a2dd95SBruce Richardson 253599a2dd95SBruce Richardson int 253699a2dd95SBruce Richardson rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size) 253799a2dd95SBruce Richardson { 253899a2dd95SBruce Richardson int ret = 0; 253999a2dd95SBruce Richardson 254053ef1b34SMin Hu (Connor) if (buffer == NULL) { 254153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot initialize NULL buffer\n"); 254299a2dd95SBruce Richardson return -EINVAL; 254353ef1b34SMin Hu (Connor) } 254499a2dd95SBruce Richardson 254599a2dd95SBruce Richardson buffer->size = size; 254699a2dd95SBruce Richardson if (buffer->error_callback == NULL) { 254799a2dd95SBruce Richardson ret = rte_eth_tx_buffer_set_err_callback( 254899a2dd95SBruce Richardson buffer, rte_eth_tx_buffer_drop_callback, NULL); 254999a2dd95SBruce Richardson } 255099a2dd95SBruce Richardson 255199a2dd95SBruce Richardson return ret; 255299a2dd95SBruce Richardson } 255399a2dd95SBruce Richardson 255499a2dd95SBruce Richardson int 255599a2dd95SBruce Richardson rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt) 255699a2dd95SBruce Richardson { 255753ef1b34SMin Hu (Connor) struct rte_eth_dev *dev; 255899a2dd95SBruce Richardson int ret; 255999a2dd95SBruce Richardson 256099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 256153ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 256253ef1b34SMin Hu (Connor) 256399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP); 256499a2dd95SBruce Richardson 256599a2dd95SBruce Richardson /* Call driver to free pending mbufs. */ 256699a2dd95SBruce Richardson ret = (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id], 256799a2dd95SBruce Richardson free_cnt); 256899a2dd95SBruce Richardson return eth_err(port_id, ret); 256999a2dd95SBruce Richardson } 257099a2dd95SBruce Richardson 257199a2dd95SBruce Richardson int 257299a2dd95SBruce Richardson rte_eth_promiscuous_enable(uint16_t port_id) 257399a2dd95SBruce Richardson { 257499a2dd95SBruce Richardson struct rte_eth_dev *dev; 257599a2dd95SBruce Richardson int diag = 0; 257699a2dd95SBruce Richardson 257799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 257899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 257999a2dd95SBruce Richardson 258099a2dd95SBruce Richardson if (dev->data->promiscuous == 1) 258199a2dd95SBruce Richardson return 0; 258299a2dd95SBruce Richardson 258399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_enable, -ENOTSUP); 258499a2dd95SBruce Richardson 258599a2dd95SBruce Richardson diag = (*dev->dev_ops->promiscuous_enable)(dev); 258699a2dd95SBruce Richardson dev->data->promiscuous = (diag == 0) ? 1 : 0; 258799a2dd95SBruce Richardson 258899a2dd95SBruce Richardson return eth_err(port_id, diag); 258999a2dd95SBruce Richardson } 259099a2dd95SBruce Richardson 259199a2dd95SBruce Richardson int 259299a2dd95SBruce Richardson rte_eth_promiscuous_disable(uint16_t port_id) 259399a2dd95SBruce Richardson { 259499a2dd95SBruce Richardson struct rte_eth_dev *dev; 259599a2dd95SBruce Richardson int diag = 0; 259699a2dd95SBruce Richardson 259799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 259899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 259999a2dd95SBruce Richardson 260099a2dd95SBruce Richardson if (dev->data->promiscuous == 0) 260199a2dd95SBruce Richardson return 0; 260299a2dd95SBruce Richardson 260399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_disable, -ENOTSUP); 260499a2dd95SBruce Richardson 260599a2dd95SBruce Richardson dev->data->promiscuous = 0; 260699a2dd95SBruce Richardson diag = (*dev->dev_ops->promiscuous_disable)(dev); 260799a2dd95SBruce Richardson if (diag != 0) 260899a2dd95SBruce Richardson dev->data->promiscuous = 1; 260999a2dd95SBruce Richardson 261099a2dd95SBruce Richardson return eth_err(port_id, diag); 261199a2dd95SBruce Richardson } 261299a2dd95SBruce Richardson 261399a2dd95SBruce Richardson int 261499a2dd95SBruce Richardson rte_eth_promiscuous_get(uint16_t port_id) 261599a2dd95SBruce Richardson { 261699a2dd95SBruce Richardson struct rte_eth_dev *dev; 261799a2dd95SBruce Richardson 261899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 261999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 262053ef1b34SMin Hu (Connor) 262199a2dd95SBruce Richardson return dev->data->promiscuous; 262299a2dd95SBruce Richardson } 262399a2dd95SBruce Richardson 262499a2dd95SBruce Richardson int 262599a2dd95SBruce Richardson rte_eth_allmulticast_enable(uint16_t port_id) 262699a2dd95SBruce Richardson { 262799a2dd95SBruce Richardson struct rte_eth_dev *dev; 262899a2dd95SBruce Richardson int diag; 262999a2dd95SBruce Richardson 263099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 263199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 263299a2dd95SBruce Richardson 263399a2dd95SBruce Richardson if (dev->data->all_multicast == 1) 263499a2dd95SBruce Richardson return 0; 263599a2dd95SBruce Richardson 263699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_enable, -ENOTSUP); 263799a2dd95SBruce Richardson diag = (*dev->dev_ops->allmulticast_enable)(dev); 263899a2dd95SBruce Richardson dev->data->all_multicast = (diag == 0) ? 1 : 0; 263999a2dd95SBruce Richardson 264099a2dd95SBruce Richardson return eth_err(port_id, diag); 264199a2dd95SBruce Richardson } 264299a2dd95SBruce Richardson 264399a2dd95SBruce Richardson int 264499a2dd95SBruce Richardson rte_eth_allmulticast_disable(uint16_t port_id) 264599a2dd95SBruce Richardson { 264699a2dd95SBruce Richardson struct rte_eth_dev *dev; 264799a2dd95SBruce Richardson int diag; 264899a2dd95SBruce Richardson 264999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 265099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 265199a2dd95SBruce Richardson 265299a2dd95SBruce Richardson if (dev->data->all_multicast == 0) 265399a2dd95SBruce Richardson return 0; 265499a2dd95SBruce Richardson 265599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_disable, -ENOTSUP); 265699a2dd95SBruce Richardson dev->data->all_multicast = 0; 265799a2dd95SBruce Richardson diag = (*dev->dev_ops->allmulticast_disable)(dev); 265899a2dd95SBruce Richardson if (diag != 0) 265999a2dd95SBruce Richardson dev->data->all_multicast = 1; 266099a2dd95SBruce Richardson 266199a2dd95SBruce Richardson return eth_err(port_id, diag); 266299a2dd95SBruce Richardson } 266399a2dd95SBruce Richardson 266499a2dd95SBruce Richardson int 266599a2dd95SBruce Richardson rte_eth_allmulticast_get(uint16_t port_id) 266699a2dd95SBruce Richardson { 266799a2dd95SBruce Richardson struct rte_eth_dev *dev; 266899a2dd95SBruce Richardson 266999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 267099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 267153ef1b34SMin Hu (Connor) 267299a2dd95SBruce Richardson return dev->data->all_multicast; 267399a2dd95SBruce Richardson } 267499a2dd95SBruce Richardson 267599a2dd95SBruce Richardson int 267699a2dd95SBruce Richardson rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link) 267799a2dd95SBruce Richardson { 267899a2dd95SBruce Richardson struct rte_eth_dev *dev; 267999a2dd95SBruce Richardson 268099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 268199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 268299a2dd95SBruce Richardson 268353ef1b34SMin Hu (Connor) if (eth_link == NULL) { 268453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u link to NULL\n", 268553ef1b34SMin Hu (Connor) port_id); 268653ef1b34SMin Hu (Connor) return -EINVAL; 268753ef1b34SMin Hu (Connor) } 268853ef1b34SMin Hu (Connor) 268953ef1b34SMin Hu (Connor) if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started) 269099a2dd95SBruce Richardson rte_eth_linkstatus_get(dev, eth_link); 269199a2dd95SBruce Richardson else { 269299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); 269399a2dd95SBruce Richardson (*dev->dev_ops->link_update)(dev, 1); 269499a2dd95SBruce Richardson *eth_link = dev->data->dev_link; 269599a2dd95SBruce Richardson } 269699a2dd95SBruce Richardson 269799a2dd95SBruce Richardson return 0; 269899a2dd95SBruce Richardson } 269999a2dd95SBruce Richardson 270099a2dd95SBruce Richardson int 270199a2dd95SBruce Richardson rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) 270299a2dd95SBruce Richardson { 270399a2dd95SBruce Richardson struct rte_eth_dev *dev; 270499a2dd95SBruce Richardson 270599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 270699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 270799a2dd95SBruce Richardson 270853ef1b34SMin Hu (Connor) if (eth_link == NULL) { 270953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u link to NULL\n", 271053ef1b34SMin Hu (Connor) port_id); 271153ef1b34SMin Hu (Connor) return -EINVAL; 271253ef1b34SMin Hu (Connor) } 271353ef1b34SMin Hu (Connor) 271453ef1b34SMin Hu (Connor) if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started) 271599a2dd95SBruce Richardson rte_eth_linkstatus_get(dev, eth_link); 271699a2dd95SBruce Richardson else { 271799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); 271899a2dd95SBruce Richardson (*dev->dev_ops->link_update)(dev, 0); 271999a2dd95SBruce Richardson *eth_link = dev->data->dev_link; 272099a2dd95SBruce Richardson } 272199a2dd95SBruce Richardson 272299a2dd95SBruce Richardson return 0; 272399a2dd95SBruce Richardson } 272499a2dd95SBruce Richardson 272599a2dd95SBruce Richardson const char * 272699a2dd95SBruce Richardson rte_eth_link_speed_to_str(uint32_t link_speed) 272799a2dd95SBruce Richardson { 272899a2dd95SBruce Richardson switch (link_speed) { 272999a2dd95SBruce Richardson case ETH_SPEED_NUM_NONE: return "None"; 273099a2dd95SBruce Richardson case ETH_SPEED_NUM_10M: return "10 Mbps"; 273199a2dd95SBruce Richardson case ETH_SPEED_NUM_100M: return "100 Mbps"; 273299a2dd95SBruce Richardson case ETH_SPEED_NUM_1G: return "1 Gbps"; 273399a2dd95SBruce Richardson case ETH_SPEED_NUM_2_5G: return "2.5 Gbps"; 273499a2dd95SBruce Richardson case ETH_SPEED_NUM_5G: return "5 Gbps"; 273599a2dd95SBruce Richardson case ETH_SPEED_NUM_10G: return "10 Gbps"; 273699a2dd95SBruce Richardson case ETH_SPEED_NUM_20G: return "20 Gbps"; 273799a2dd95SBruce Richardson case ETH_SPEED_NUM_25G: return "25 Gbps"; 273899a2dd95SBruce Richardson case ETH_SPEED_NUM_40G: return "40 Gbps"; 273999a2dd95SBruce Richardson case ETH_SPEED_NUM_50G: return "50 Gbps"; 274099a2dd95SBruce Richardson case ETH_SPEED_NUM_56G: return "56 Gbps"; 274199a2dd95SBruce Richardson case ETH_SPEED_NUM_100G: return "100 Gbps"; 274299a2dd95SBruce Richardson case ETH_SPEED_NUM_200G: return "200 Gbps"; 274399a2dd95SBruce Richardson case ETH_SPEED_NUM_UNKNOWN: return "Unknown"; 274499a2dd95SBruce Richardson default: return "Invalid"; 274599a2dd95SBruce Richardson } 274699a2dd95SBruce Richardson } 274799a2dd95SBruce Richardson 274899a2dd95SBruce Richardson int 274999a2dd95SBruce Richardson rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link) 275099a2dd95SBruce Richardson { 275153ef1b34SMin Hu (Connor) if (str == NULL) { 275253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot convert link to NULL string\n"); 275353ef1b34SMin Hu (Connor) return -EINVAL; 275453ef1b34SMin Hu (Connor) } 275553ef1b34SMin Hu (Connor) 275653ef1b34SMin Hu (Connor) if (len == 0) { 275753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 275853ef1b34SMin Hu (Connor) "Cannot convert link to string with zero size\n"); 275953ef1b34SMin Hu (Connor) return -EINVAL; 276053ef1b34SMin Hu (Connor) } 276153ef1b34SMin Hu (Connor) 276253ef1b34SMin Hu (Connor) if (eth_link == NULL) { 276353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot convert to string from NULL link\n"); 276453ef1b34SMin Hu (Connor) return -EINVAL; 276553ef1b34SMin Hu (Connor) } 276653ef1b34SMin Hu (Connor) 276799a2dd95SBruce Richardson if (eth_link->link_status == ETH_LINK_DOWN) 276899a2dd95SBruce Richardson return snprintf(str, len, "Link down"); 276999a2dd95SBruce Richardson else 277099a2dd95SBruce Richardson return snprintf(str, len, "Link up at %s %s %s", 277199a2dd95SBruce Richardson rte_eth_link_speed_to_str(eth_link->link_speed), 277299a2dd95SBruce Richardson (eth_link->link_duplex == ETH_LINK_FULL_DUPLEX) ? 277399a2dd95SBruce Richardson "FDX" : "HDX", 277499a2dd95SBruce Richardson (eth_link->link_autoneg == ETH_LINK_AUTONEG) ? 277599a2dd95SBruce Richardson "Autoneg" : "Fixed"); 277699a2dd95SBruce Richardson } 277799a2dd95SBruce Richardson 277899a2dd95SBruce Richardson int 277999a2dd95SBruce Richardson rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats) 278099a2dd95SBruce Richardson { 278199a2dd95SBruce Richardson struct rte_eth_dev *dev; 278299a2dd95SBruce Richardson 278399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 278499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 278553ef1b34SMin Hu (Connor) 278653ef1b34SMin Hu (Connor) if (stats == NULL) { 278753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u stats to NULL\n", 278853ef1b34SMin Hu (Connor) port_id); 278953ef1b34SMin Hu (Connor) return -EINVAL; 279053ef1b34SMin Hu (Connor) } 279153ef1b34SMin Hu (Connor) 279299a2dd95SBruce Richardson memset(stats, 0, sizeof(*stats)); 279399a2dd95SBruce Richardson 279499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP); 279599a2dd95SBruce Richardson stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed; 279699a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->stats_get)(dev, stats)); 279799a2dd95SBruce Richardson } 279899a2dd95SBruce Richardson 279999a2dd95SBruce Richardson int 280099a2dd95SBruce Richardson rte_eth_stats_reset(uint16_t port_id) 280199a2dd95SBruce Richardson { 280299a2dd95SBruce Richardson struct rte_eth_dev *dev; 280399a2dd95SBruce Richardson int ret; 280499a2dd95SBruce Richardson 280599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 280699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 280799a2dd95SBruce Richardson 280899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP); 280999a2dd95SBruce Richardson ret = (*dev->dev_ops->stats_reset)(dev); 281099a2dd95SBruce Richardson if (ret != 0) 281199a2dd95SBruce Richardson return eth_err(port_id, ret); 281299a2dd95SBruce Richardson 281399a2dd95SBruce Richardson dev->data->rx_mbuf_alloc_failed = 0; 281499a2dd95SBruce Richardson 281599a2dd95SBruce Richardson return 0; 281699a2dd95SBruce Richardson } 281799a2dd95SBruce Richardson 281899a2dd95SBruce Richardson static inline int 281999a2dd95SBruce Richardson eth_dev_get_xstats_basic_count(struct rte_eth_dev *dev) 282099a2dd95SBruce Richardson { 282199a2dd95SBruce Richardson uint16_t nb_rxqs, nb_txqs; 282299a2dd95SBruce Richardson int count; 282399a2dd95SBruce Richardson 282499a2dd95SBruce Richardson nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 282599a2dd95SBruce Richardson nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 282699a2dd95SBruce Richardson 282799a2dd95SBruce Richardson count = RTE_NB_STATS; 282899a2dd95SBruce Richardson if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) { 282999a2dd95SBruce Richardson count += nb_rxqs * RTE_NB_RXQ_STATS; 283099a2dd95SBruce Richardson count += nb_txqs * RTE_NB_TXQ_STATS; 283199a2dd95SBruce Richardson } 283299a2dd95SBruce Richardson 283399a2dd95SBruce Richardson return count; 283499a2dd95SBruce Richardson } 283599a2dd95SBruce Richardson 283699a2dd95SBruce Richardson static int 283799a2dd95SBruce Richardson eth_dev_get_xstats_count(uint16_t port_id) 283899a2dd95SBruce Richardson { 283999a2dd95SBruce Richardson struct rte_eth_dev *dev; 284099a2dd95SBruce Richardson int count; 284199a2dd95SBruce Richardson 284299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 284399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 284499a2dd95SBruce Richardson if (dev->dev_ops->xstats_get_names != NULL) { 284599a2dd95SBruce Richardson count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0); 284699a2dd95SBruce Richardson if (count < 0) 284799a2dd95SBruce Richardson return eth_err(port_id, count); 284899a2dd95SBruce Richardson } else 284999a2dd95SBruce Richardson count = 0; 285099a2dd95SBruce Richardson 285199a2dd95SBruce Richardson 285299a2dd95SBruce Richardson count += eth_dev_get_xstats_basic_count(dev); 285399a2dd95SBruce Richardson 285499a2dd95SBruce Richardson return count; 285599a2dd95SBruce Richardson } 285699a2dd95SBruce Richardson 285799a2dd95SBruce Richardson int 285899a2dd95SBruce Richardson rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name, 285999a2dd95SBruce Richardson uint64_t *id) 286099a2dd95SBruce Richardson { 286199a2dd95SBruce Richardson int cnt_xstats, idx_xstat; 286299a2dd95SBruce Richardson 286399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 286499a2dd95SBruce Richardson 286553ef1b34SMin Hu (Connor) if (xstat_name == NULL) { 286653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 286753ef1b34SMin Hu (Connor) "Cannot get ethdev port %u xstats ID from NULL xstat name\n", 286853ef1b34SMin Hu (Connor) port_id); 286999a2dd95SBruce Richardson return -ENOMEM; 287099a2dd95SBruce Richardson } 287199a2dd95SBruce Richardson 287253ef1b34SMin Hu (Connor) if (id == NULL) { 287353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 287453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u xstats ID to NULL\n", 287553ef1b34SMin Hu (Connor) port_id); 287699a2dd95SBruce Richardson return -ENOMEM; 287799a2dd95SBruce Richardson } 287899a2dd95SBruce Richardson 287999a2dd95SBruce Richardson /* Get count */ 288099a2dd95SBruce Richardson cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL); 288199a2dd95SBruce Richardson if (cnt_xstats < 0) { 288299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Cannot get count of xstats\n"); 288399a2dd95SBruce Richardson return -ENODEV; 288499a2dd95SBruce Richardson } 288599a2dd95SBruce Richardson 288699a2dd95SBruce Richardson /* Get id-name lookup table */ 288799a2dd95SBruce Richardson struct rte_eth_xstat_name xstats_names[cnt_xstats]; 288899a2dd95SBruce Richardson 288999a2dd95SBruce Richardson if (cnt_xstats != rte_eth_xstats_get_names_by_id( 289099a2dd95SBruce Richardson port_id, xstats_names, cnt_xstats, NULL)) { 289199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Cannot get xstats lookup\n"); 289299a2dd95SBruce Richardson return -1; 289399a2dd95SBruce Richardson } 289499a2dd95SBruce Richardson 289599a2dd95SBruce Richardson for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { 289699a2dd95SBruce Richardson if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) { 289799a2dd95SBruce Richardson *id = idx_xstat; 289899a2dd95SBruce Richardson return 0; 289999a2dd95SBruce Richardson }; 290099a2dd95SBruce Richardson } 290199a2dd95SBruce Richardson 290299a2dd95SBruce Richardson return -EINVAL; 290399a2dd95SBruce Richardson } 290499a2dd95SBruce Richardson 290599a2dd95SBruce Richardson /* retrieve basic stats names */ 290699a2dd95SBruce Richardson static int 290799a2dd95SBruce Richardson eth_basic_stats_get_names(struct rte_eth_dev *dev, 290899a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names) 290999a2dd95SBruce Richardson { 291099a2dd95SBruce Richardson int cnt_used_entries = 0; 291199a2dd95SBruce Richardson uint32_t idx, id_queue; 291299a2dd95SBruce Richardson uint16_t num_q; 291399a2dd95SBruce Richardson 291499a2dd95SBruce Richardson for (idx = 0; idx < RTE_NB_STATS; idx++) { 291599a2dd95SBruce Richardson strlcpy(xstats_names[cnt_used_entries].name, 291699a2dd95SBruce Richardson eth_dev_stats_strings[idx].name, 291799a2dd95SBruce Richardson sizeof(xstats_names[0].name)); 291899a2dd95SBruce Richardson cnt_used_entries++; 291999a2dd95SBruce Richardson } 292099a2dd95SBruce Richardson 292199a2dd95SBruce Richardson if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0) 292299a2dd95SBruce Richardson return cnt_used_entries; 292399a2dd95SBruce Richardson 292499a2dd95SBruce Richardson num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 292599a2dd95SBruce Richardson for (id_queue = 0; id_queue < num_q; id_queue++) { 292699a2dd95SBruce Richardson for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) { 292799a2dd95SBruce Richardson snprintf(xstats_names[cnt_used_entries].name, 292899a2dd95SBruce Richardson sizeof(xstats_names[0].name), 292999a2dd95SBruce Richardson "rx_q%u_%s", 293099a2dd95SBruce Richardson id_queue, eth_dev_rxq_stats_strings[idx].name); 293199a2dd95SBruce Richardson cnt_used_entries++; 293299a2dd95SBruce Richardson } 293399a2dd95SBruce Richardson 293499a2dd95SBruce Richardson } 293599a2dd95SBruce Richardson num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 293699a2dd95SBruce Richardson for (id_queue = 0; id_queue < num_q; id_queue++) { 293799a2dd95SBruce Richardson for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) { 293899a2dd95SBruce Richardson snprintf(xstats_names[cnt_used_entries].name, 293999a2dd95SBruce Richardson sizeof(xstats_names[0].name), 294099a2dd95SBruce Richardson "tx_q%u_%s", 294199a2dd95SBruce Richardson id_queue, eth_dev_txq_stats_strings[idx].name); 294299a2dd95SBruce Richardson cnt_used_entries++; 294399a2dd95SBruce Richardson } 294499a2dd95SBruce Richardson } 294599a2dd95SBruce Richardson return cnt_used_entries; 294699a2dd95SBruce Richardson } 294799a2dd95SBruce Richardson 294899a2dd95SBruce Richardson /* retrieve ethdev extended statistics names */ 294999a2dd95SBruce Richardson int 295099a2dd95SBruce Richardson rte_eth_xstats_get_names_by_id(uint16_t port_id, 295199a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names, unsigned int size, 295299a2dd95SBruce Richardson uint64_t *ids) 295399a2dd95SBruce Richardson { 295499a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names_copy; 295599a2dd95SBruce Richardson unsigned int no_basic_stat_requested = 1; 295699a2dd95SBruce Richardson unsigned int no_ext_stat_requested = 1; 295799a2dd95SBruce Richardson unsigned int expected_entries; 295899a2dd95SBruce Richardson unsigned int basic_count; 295999a2dd95SBruce Richardson struct rte_eth_dev *dev; 296099a2dd95SBruce Richardson unsigned int i; 296199a2dd95SBruce Richardson int ret; 296299a2dd95SBruce Richardson 296399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 296499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 296599a2dd95SBruce Richardson 296699a2dd95SBruce Richardson basic_count = eth_dev_get_xstats_basic_count(dev); 296799a2dd95SBruce Richardson ret = eth_dev_get_xstats_count(port_id); 296899a2dd95SBruce Richardson if (ret < 0) 296999a2dd95SBruce Richardson return ret; 297099a2dd95SBruce Richardson expected_entries = (unsigned int)ret; 297199a2dd95SBruce Richardson 297299a2dd95SBruce Richardson /* Return max number of stats if no ids given */ 297399a2dd95SBruce Richardson if (!ids) { 297499a2dd95SBruce Richardson if (!xstats_names) 297599a2dd95SBruce Richardson return expected_entries; 297699a2dd95SBruce Richardson else if (xstats_names && size < expected_entries) 297799a2dd95SBruce Richardson return expected_entries; 297899a2dd95SBruce Richardson } 297999a2dd95SBruce Richardson 298099a2dd95SBruce Richardson if (ids && !xstats_names) 298199a2dd95SBruce Richardson return -EINVAL; 298299a2dd95SBruce Richardson 298399a2dd95SBruce Richardson if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) { 298499a2dd95SBruce Richardson uint64_t ids_copy[size]; 298599a2dd95SBruce Richardson 298699a2dd95SBruce Richardson for (i = 0; i < size; i++) { 298799a2dd95SBruce Richardson if (ids[i] < basic_count) { 298899a2dd95SBruce Richardson no_basic_stat_requested = 0; 298999a2dd95SBruce Richardson break; 299099a2dd95SBruce Richardson } 299199a2dd95SBruce Richardson 299299a2dd95SBruce Richardson /* 299399a2dd95SBruce Richardson * Convert ids to xstats ids that PMD knows. 299499a2dd95SBruce Richardson * ids known by user are basic + extended stats. 299599a2dd95SBruce Richardson */ 299699a2dd95SBruce Richardson ids_copy[i] = ids[i] - basic_count; 299799a2dd95SBruce Richardson } 299899a2dd95SBruce Richardson 299999a2dd95SBruce Richardson if (no_basic_stat_requested) 300099a2dd95SBruce Richardson return (*dev->dev_ops->xstats_get_names_by_id)(dev, 30018c9f976fSAndrew Rybchenko ids_copy, xstats_names, size); 300299a2dd95SBruce Richardson } 300399a2dd95SBruce Richardson 300499a2dd95SBruce Richardson /* Retrieve all stats */ 300599a2dd95SBruce Richardson if (!ids) { 300699a2dd95SBruce Richardson int num_stats = rte_eth_xstats_get_names(port_id, xstats_names, 300799a2dd95SBruce Richardson expected_entries); 300899a2dd95SBruce Richardson if (num_stats < 0 || num_stats > (int)expected_entries) 300999a2dd95SBruce Richardson return num_stats; 301099a2dd95SBruce Richardson else 301199a2dd95SBruce Richardson return expected_entries; 301299a2dd95SBruce Richardson } 301399a2dd95SBruce Richardson 301499a2dd95SBruce Richardson xstats_names_copy = calloc(expected_entries, 301599a2dd95SBruce Richardson sizeof(struct rte_eth_xstat_name)); 301699a2dd95SBruce Richardson 301799a2dd95SBruce Richardson if (!xstats_names_copy) { 301899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Can't allocate memory\n"); 301999a2dd95SBruce Richardson return -ENOMEM; 302099a2dd95SBruce Richardson } 302199a2dd95SBruce Richardson 302299a2dd95SBruce Richardson if (ids) { 302399a2dd95SBruce Richardson for (i = 0; i < size; i++) { 302499a2dd95SBruce Richardson if (ids[i] >= basic_count) { 302599a2dd95SBruce Richardson no_ext_stat_requested = 0; 302699a2dd95SBruce Richardson break; 302799a2dd95SBruce Richardson } 302899a2dd95SBruce Richardson } 302999a2dd95SBruce Richardson } 303099a2dd95SBruce Richardson 303199a2dd95SBruce Richardson /* Fill xstats_names_copy structure */ 303299a2dd95SBruce Richardson if (ids && no_ext_stat_requested) { 303399a2dd95SBruce Richardson eth_basic_stats_get_names(dev, xstats_names_copy); 303499a2dd95SBruce Richardson } else { 303599a2dd95SBruce Richardson ret = rte_eth_xstats_get_names(port_id, xstats_names_copy, 303699a2dd95SBruce Richardson expected_entries); 303799a2dd95SBruce Richardson if (ret < 0) { 303899a2dd95SBruce Richardson free(xstats_names_copy); 303999a2dd95SBruce Richardson return ret; 304099a2dd95SBruce Richardson } 304199a2dd95SBruce Richardson } 304299a2dd95SBruce Richardson 304399a2dd95SBruce Richardson /* Filter stats */ 304499a2dd95SBruce Richardson for (i = 0; i < size; i++) { 304599a2dd95SBruce Richardson if (ids[i] >= expected_entries) { 304699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n"); 304799a2dd95SBruce Richardson free(xstats_names_copy); 304899a2dd95SBruce Richardson return -1; 304999a2dd95SBruce Richardson } 305099a2dd95SBruce Richardson xstats_names[i] = xstats_names_copy[ids[i]]; 305199a2dd95SBruce Richardson } 305299a2dd95SBruce Richardson 305399a2dd95SBruce Richardson free(xstats_names_copy); 305499a2dd95SBruce Richardson return size; 305599a2dd95SBruce Richardson } 305699a2dd95SBruce Richardson 305799a2dd95SBruce Richardson int 305899a2dd95SBruce Richardson rte_eth_xstats_get_names(uint16_t port_id, 305999a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names, 306099a2dd95SBruce Richardson unsigned int size) 306199a2dd95SBruce Richardson { 306299a2dd95SBruce Richardson struct rte_eth_dev *dev; 306399a2dd95SBruce Richardson int cnt_used_entries; 306499a2dd95SBruce Richardson int cnt_expected_entries; 306599a2dd95SBruce Richardson int cnt_driver_entries; 306699a2dd95SBruce Richardson 306799a2dd95SBruce Richardson cnt_expected_entries = eth_dev_get_xstats_count(port_id); 306899a2dd95SBruce Richardson if (xstats_names == NULL || cnt_expected_entries < 0 || 306999a2dd95SBruce Richardson (int)size < cnt_expected_entries) 307099a2dd95SBruce Richardson return cnt_expected_entries; 307199a2dd95SBruce Richardson 307299a2dd95SBruce Richardson /* port_id checked in eth_dev_get_xstats_count() */ 307399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 307499a2dd95SBruce Richardson 307599a2dd95SBruce Richardson cnt_used_entries = eth_basic_stats_get_names(dev, xstats_names); 307699a2dd95SBruce Richardson 307799a2dd95SBruce Richardson if (dev->dev_ops->xstats_get_names != NULL) { 307899a2dd95SBruce Richardson /* If there are any driver-specific xstats, append them 307999a2dd95SBruce Richardson * to end of list. 308099a2dd95SBruce Richardson */ 308199a2dd95SBruce Richardson cnt_driver_entries = (*dev->dev_ops->xstats_get_names)( 308299a2dd95SBruce Richardson dev, 308399a2dd95SBruce Richardson xstats_names + cnt_used_entries, 308499a2dd95SBruce Richardson size - cnt_used_entries); 308599a2dd95SBruce Richardson if (cnt_driver_entries < 0) 308699a2dd95SBruce Richardson return eth_err(port_id, cnt_driver_entries); 308799a2dd95SBruce Richardson cnt_used_entries += cnt_driver_entries; 308899a2dd95SBruce Richardson } 308999a2dd95SBruce Richardson 309099a2dd95SBruce Richardson return cnt_used_entries; 309199a2dd95SBruce Richardson } 309299a2dd95SBruce Richardson 309399a2dd95SBruce Richardson 309499a2dd95SBruce Richardson static int 309599a2dd95SBruce Richardson eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats) 309699a2dd95SBruce Richardson { 309799a2dd95SBruce Richardson struct rte_eth_dev *dev; 309899a2dd95SBruce Richardson struct rte_eth_stats eth_stats; 309999a2dd95SBruce Richardson unsigned int count = 0, i, q; 310099a2dd95SBruce Richardson uint64_t val, *stats_ptr; 310199a2dd95SBruce Richardson uint16_t nb_rxqs, nb_txqs; 310299a2dd95SBruce Richardson int ret; 310399a2dd95SBruce Richardson 310499a2dd95SBruce Richardson ret = rte_eth_stats_get(port_id, ð_stats); 310599a2dd95SBruce Richardson if (ret < 0) 310699a2dd95SBruce Richardson return ret; 310799a2dd95SBruce Richardson 310899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 310999a2dd95SBruce Richardson 311099a2dd95SBruce Richardson nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 311199a2dd95SBruce Richardson nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 311299a2dd95SBruce Richardson 311399a2dd95SBruce Richardson /* global stats */ 311499a2dd95SBruce Richardson for (i = 0; i < RTE_NB_STATS; i++) { 311599a2dd95SBruce Richardson stats_ptr = RTE_PTR_ADD(ð_stats, 311699a2dd95SBruce Richardson eth_dev_stats_strings[i].offset); 311799a2dd95SBruce Richardson val = *stats_ptr; 311899a2dd95SBruce Richardson xstats[count++].value = val; 311999a2dd95SBruce Richardson } 312099a2dd95SBruce Richardson 312199a2dd95SBruce Richardson if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0) 312299a2dd95SBruce Richardson return count; 312399a2dd95SBruce Richardson 312499a2dd95SBruce Richardson /* per-rxq stats */ 312599a2dd95SBruce Richardson for (q = 0; q < nb_rxqs; q++) { 312699a2dd95SBruce Richardson for (i = 0; i < RTE_NB_RXQ_STATS; i++) { 312799a2dd95SBruce Richardson stats_ptr = RTE_PTR_ADD(ð_stats, 312899a2dd95SBruce Richardson eth_dev_rxq_stats_strings[i].offset + 312999a2dd95SBruce Richardson q * sizeof(uint64_t)); 313099a2dd95SBruce Richardson val = *stats_ptr; 313199a2dd95SBruce Richardson xstats[count++].value = val; 313299a2dd95SBruce Richardson } 313399a2dd95SBruce Richardson } 313499a2dd95SBruce Richardson 313599a2dd95SBruce Richardson /* per-txq stats */ 313699a2dd95SBruce Richardson for (q = 0; q < nb_txqs; q++) { 313799a2dd95SBruce Richardson for (i = 0; i < RTE_NB_TXQ_STATS; i++) { 313899a2dd95SBruce Richardson stats_ptr = RTE_PTR_ADD(ð_stats, 313999a2dd95SBruce Richardson eth_dev_txq_stats_strings[i].offset + 314099a2dd95SBruce Richardson q * sizeof(uint64_t)); 314199a2dd95SBruce Richardson val = *stats_ptr; 314299a2dd95SBruce Richardson xstats[count++].value = val; 314399a2dd95SBruce Richardson } 314499a2dd95SBruce Richardson } 314599a2dd95SBruce Richardson return count; 314699a2dd95SBruce Richardson } 314799a2dd95SBruce Richardson 314899a2dd95SBruce Richardson /* retrieve ethdev extended statistics */ 314999a2dd95SBruce Richardson int 315099a2dd95SBruce Richardson rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, 315199a2dd95SBruce Richardson uint64_t *values, unsigned int size) 315299a2dd95SBruce Richardson { 315399a2dd95SBruce Richardson unsigned int no_basic_stat_requested = 1; 315499a2dd95SBruce Richardson unsigned int no_ext_stat_requested = 1; 315599a2dd95SBruce Richardson unsigned int num_xstats_filled; 315699a2dd95SBruce Richardson unsigned int basic_count; 315799a2dd95SBruce Richardson uint16_t expected_entries; 315899a2dd95SBruce Richardson struct rte_eth_dev *dev; 315999a2dd95SBruce Richardson unsigned int i; 316099a2dd95SBruce Richardson int ret; 316199a2dd95SBruce Richardson 316299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 316353ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 316453ef1b34SMin Hu (Connor) 316599a2dd95SBruce Richardson ret = eth_dev_get_xstats_count(port_id); 316699a2dd95SBruce Richardson if (ret < 0) 316799a2dd95SBruce Richardson return ret; 316899a2dd95SBruce Richardson expected_entries = (uint16_t)ret; 316999a2dd95SBruce Richardson struct rte_eth_xstat xstats[expected_entries]; 317099a2dd95SBruce Richardson basic_count = eth_dev_get_xstats_basic_count(dev); 317199a2dd95SBruce Richardson 317299a2dd95SBruce Richardson /* Return max number of stats if no ids given */ 317399a2dd95SBruce Richardson if (!ids) { 317499a2dd95SBruce Richardson if (!values) 317599a2dd95SBruce Richardson return expected_entries; 317699a2dd95SBruce Richardson else if (values && size < expected_entries) 317799a2dd95SBruce Richardson return expected_entries; 317899a2dd95SBruce Richardson } 317999a2dd95SBruce Richardson 318099a2dd95SBruce Richardson if (ids && !values) 318199a2dd95SBruce Richardson return -EINVAL; 318299a2dd95SBruce Richardson 318399a2dd95SBruce Richardson if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) { 318499a2dd95SBruce Richardson unsigned int basic_count = eth_dev_get_xstats_basic_count(dev); 318599a2dd95SBruce Richardson uint64_t ids_copy[size]; 318699a2dd95SBruce Richardson 318799a2dd95SBruce Richardson for (i = 0; i < size; i++) { 318899a2dd95SBruce Richardson if (ids[i] < basic_count) { 318999a2dd95SBruce Richardson no_basic_stat_requested = 0; 319099a2dd95SBruce Richardson break; 319199a2dd95SBruce Richardson } 319299a2dd95SBruce Richardson 319399a2dd95SBruce Richardson /* 319499a2dd95SBruce Richardson * Convert ids to xstats ids that PMD knows. 319599a2dd95SBruce Richardson * ids known by user are basic + extended stats. 319699a2dd95SBruce Richardson */ 319799a2dd95SBruce Richardson ids_copy[i] = ids[i] - basic_count; 319899a2dd95SBruce Richardson } 319999a2dd95SBruce Richardson 320099a2dd95SBruce Richardson if (no_basic_stat_requested) 320199a2dd95SBruce Richardson return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy, 320299a2dd95SBruce Richardson values, size); 320399a2dd95SBruce Richardson } 320499a2dd95SBruce Richardson 320599a2dd95SBruce Richardson if (ids) { 320699a2dd95SBruce Richardson for (i = 0; i < size; i++) { 320799a2dd95SBruce Richardson if (ids[i] >= basic_count) { 320899a2dd95SBruce Richardson no_ext_stat_requested = 0; 320999a2dd95SBruce Richardson break; 321099a2dd95SBruce Richardson } 321199a2dd95SBruce Richardson } 321299a2dd95SBruce Richardson } 321399a2dd95SBruce Richardson 321499a2dd95SBruce Richardson /* Fill the xstats structure */ 321599a2dd95SBruce Richardson if (ids && no_ext_stat_requested) 321699a2dd95SBruce Richardson ret = eth_basic_stats_get(port_id, xstats); 321799a2dd95SBruce Richardson else 321899a2dd95SBruce Richardson ret = rte_eth_xstats_get(port_id, xstats, expected_entries); 321999a2dd95SBruce Richardson 322099a2dd95SBruce Richardson if (ret < 0) 322199a2dd95SBruce Richardson return ret; 322299a2dd95SBruce Richardson num_xstats_filled = (unsigned int)ret; 322399a2dd95SBruce Richardson 322499a2dd95SBruce Richardson /* Return all stats */ 322599a2dd95SBruce Richardson if (!ids) { 322699a2dd95SBruce Richardson for (i = 0; i < num_xstats_filled; i++) 322799a2dd95SBruce Richardson values[i] = xstats[i].value; 322899a2dd95SBruce Richardson return expected_entries; 322999a2dd95SBruce Richardson } 323099a2dd95SBruce Richardson 323199a2dd95SBruce Richardson /* Filter stats */ 323299a2dd95SBruce Richardson for (i = 0; i < size; i++) { 323399a2dd95SBruce Richardson if (ids[i] >= expected_entries) { 323499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n"); 323599a2dd95SBruce Richardson return -1; 323699a2dd95SBruce Richardson } 323799a2dd95SBruce Richardson values[i] = xstats[ids[i]].value; 323899a2dd95SBruce Richardson } 323999a2dd95SBruce Richardson return size; 324099a2dd95SBruce Richardson } 324199a2dd95SBruce Richardson 324299a2dd95SBruce Richardson int 324399a2dd95SBruce Richardson rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, 324499a2dd95SBruce Richardson unsigned int n) 324599a2dd95SBruce Richardson { 324699a2dd95SBruce Richardson struct rte_eth_dev *dev; 324799a2dd95SBruce Richardson unsigned int count = 0, i; 324899a2dd95SBruce Richardson signed int xcount = 0; 324999a2dd95SBruce Richardson uint16_t nb_rxqs, nb_txqs; 325099a2dd95SBruce Richardson int ret; 325199a2dd95SBruce Richardson 325299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 325399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 325499a2dd95SBruce Richardson 325599a2dd95SBruce Richardson nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 325699a2dd95SBruce Richardson nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 325799a2dd95SBruce Richardson 325899a2dd95SBruce Richardson /* Return generic statistics */ 325999a2dd95SBruce Richardson count = RTE_NB_STATS; 326099a2dd95SBruce Richardson if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) 326199a2dd95SBruce Richardson count += (nb_rxqs * RTE_NB_RXQ_STATS) + (nb_txqs * RTE_NB_TXQ_STATS); 326299a2dd95SBruce Richardson 326399a2dd95SBruce Richardson /* implemented by the driver */ 326499a2dd95SBruce Richardson if (dev->dev_ops->xstats_get != NULL) { 326599a2dd95SBruce Richardson /* Retrieve the xstats from the driver at the end of the 326699a2dd95SBruce Richardson * xstats struct. 326799a2dd95SBruce Richardson */ 326899a2dd95SBruce Richardson xcount = (*dev->dev_ops->xstats_get)(dev, 326999a2dd95SBruce Richardson xstats ? xstats + count : NULL, 327099a2dd95SBruce Richardson (n > count) ? n - count : 0); 327199a2dd95SBruce Richardson 327299a2dd95SBruce Richardson if (xcount < 0) 327399a2dd95SBruce Richardson return eth_err(port_id, xcount); 327499a2dd95SBruce Richardson } 327599a2dd95SBruce Richardson 327699a2dd95SBruce Richardson if (n < count + xcount || xstats == NULL) 327799a2dd95SBruce Richardson return count + xcount; 327899a2dd95SBruce Richardson 327999a2dd95SBruce Richardson /* now fill the xstats structure */ 328099a2dd95SBruce Richardson ret = eth_basic_stats_get(port_id, xstats); 328199a2dd95SBruce Richardson if (ret < 0) 328299a2dd95SBruce Richardson return ret; 328399a2dd95SBruce Richardson count = ret; 328499a2dd95SBruce Richardson 328599a2dd95SBruce Richardson for (i = 0; i < count; i++) 328699a2dd95SBruce Richardson xstats[i].id = i; 328799a2dd95SBruce Richardson /* add an offset to driver-specific stats */ 328899a2dd95SBruce Richardson for ( ; i < count + xcount; i++) 328999a2dd95SBruce Richardson xstats[i].id += count; 329099a2dd95SBruce Richardson 329199a2dd95SBruce Richardson return count + xcount; 329299a2dd95SBruce Richardson } 329399a2dd95SBruce Richardson 329499a2dd95SBruce Richardson /* reset ethdev extended statistics */ 329599a2dd95SBruce Richardson int 329699a2dd95SBruce Richardson rte_eth_xstats_reset(uint16_t port_id) 329799a2dd95SBruce Richardson { 329899a2dd95SBruce Richardson struct rte_eth_dev *dev; 329999a2dd95SBruce Richardson 330099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 330199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 330299a2dd95SBruce Richardson 330399a2dd95SBruce Richardson /* implemented by the driver */ 330499a2dd95SBruce Richardson if (dev->dev_ops->xstats_reset != NULL) 330599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->xstats_reset)(dev)); 330699a2dd95SBruce Richardson 330799a2dd95SBruce Richardson /* fallback to default */ 330899a2dd95SBruce Richardson return rte_eth_stats_reset(port_id); 330999a2dd95SBruce Richardson } 331099a2dd95SBruce Richardson 331199a2dd95SBruce Richardson static int 331299a2dd95SBruce Richardson eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, 331399a2dd95SBruce Richardson uint8_t stat_idx, uint8_t is_rx) 331499a2dd95SBruce Richardson { 331599a2dd95SBruce Richardson struct rte_eth_dev *dev; 331699a2dd95SBruce Richardson 331799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 331899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 331999a2dd95SBruce Richardson 332099a2dd95SBruce Richardson if (is_rx && (queue_id >= dev->data->nb_rx_queues)) 332199a2dd95SBruce Richardson return -EINVAL; 332299a2dd95SBruce Richardson 332399a2dd95SBruce Richardson if (!is_rx && (queue_id >= dev->data->nb_tx_queues)) 332499a2dd95SBruce Richardson return -EINVAL; 332599a2dd95SBruce Richardson 332699a2dd95SBruce Richardson if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS) 332799a2dd95SBruce Richardson return -EINVAL; 332899a2dd95SBruce Richardson 332953ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP); 333053ef1b34SMin Hu (Connor) return (*dev->dev_ops->queue_stats_mapping_set) (dev, queue_id, stat_idx, is_rx); 333199a2dd95SBruce Richardson } 333299a2dd95SBruce Richardson 333399a2dd95SBruce Richardson int 333499a2dd95SBruce Richardson rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id, 333599a2dd95SBruce Richardson uint8_t stat_idx) 333699a2dd95SBruce Richardson { 333799a2dd95SBruce Richardson return eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id, 333899a2dd95SBruce Richardson tx_queue_id, 333999a2dd95SBruce Richardson stat_idx, STAT_QMAP_TX)); 334099a2dd95SBruce Richardson } 334199a2dd95SBruce Richardson 334299a2dd95SBruce Richardson int 334399a2dd95SBruce Richardson rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id, 334499a2dd95SBruce Richardson uint8_t stat_idx) 334599a2dd95SBruce Richardson { 334699a2dd95SBruce Richardson return eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id, 334799a2dd95SBruce Richardson rx_queue_id, 334899a2dd95SBruce Richardson stat_idx, STAT_QMAP_RX)); 334999a2dd95SBruce Richardson } 335099a2dd95SBruce Richardson 335199a2dd95SBruce Richardson int 335299a2dd95SBruce Richardson rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size) 335399a2dd95SBruce Richardson { 335499a2dd95SBruce Richardson struct rte_eth_dev *dev; 335599a2dd95SBruce Richardson 335699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 335799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 335899a2dd95SBruce Richardson 335953ef1b34SMin Hu (Connor) if (fw_version == NULL && fw_size > 0) { 336053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 336153ef1b34SMin Hu (Connor) "Cannot get ethdev port %u FW version to NULL when string size is non zero\n", 336253ef1b34SMin Hu (Connor) port_id); 336353ef1b34SMin Hu (Connor) return -EINVAL; 336453ef1b34SMin Hu (Connor) } 336553ef1b34SMin Hu (Connor) 336699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP); 336799a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev, 336899a2dd95SBruce Richardson fw_version, fw_size)); 336999a2dd95SBruce Richardson } 337099a2dd95SBruce Richardson 337199a2dd95SBruce Richardson int 337299a2dd95SBruce Richardson rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info) 337399a2dd95SBruce Richardson { 337499a2dd95SBruce Richardson struct rte_eth_dev *dev; 337599a2dd95SBruce Richardson const struct rte_eth_desc_lim lim = { 337699a2dd95SBruce Richardson .nb_max = UINT16_MAX, 337799a2dd95SBruce Richardson .nb_min = 0, 337899a2dd95SBruce Richardson .nb_align = 1, 337999a2dd95SBruce Richardson .nb_seg_max = UINT16_MAX, 338099a2dd95SBruce Richardson .nb_mtu_seg_max = UINT16_MAX, 338199a2dd95SBruce Richardson }; 338299a2dd95SBruce Richardson int diag; 338399a2dd95SBruce Richardson 338453ef1b34SMin Hu (Connor) RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 338553ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 338653ef1b34SMin Hu (Connor) 338753ef1b34SMin Hu (Connor) if (dev_info == NULL) { 338853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u info to NULL\n", 338953ef1b34SMin Hu (Connor) port_id); 339053ef1b34SMin Hu (Connor) return -EINVAL; 339153ef1b34SMin Hu (Connor) } 339253ef1b34SMin Hu (Connor) 339399a2dd95SBruce Richardson /* 339499a2dd95SBruce Richardson * Init dev_info before port_id check since caller does not have 339599a2dd95SBruce Richardson * return status and does not know if get is successful or not. 339699a2dd95SBruce Richardson */ 339799a2dd95SBruce Richardson memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); 339899a2dd95SBruce Richardson dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 339999a2dd95SBruce Richardson 340099a2dd95SBruce Richardson dev_info->rx_desc_lim = lim; 340199a2dd95SBruce Richardson dev_info->tx_desc_lim = lim; 340299a2dd95SBruce Richardson dev_info->device = dev->device; 340399a2dd95SBruce Richardson dev_info->min_mtu = RTE_ETHER_MIN_MTU; 340499a2dd95SBruce Richardson dev_info->max_mtu = UINT16_MAX; 340599a2dd95SBruce Richardson 340699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); 340799a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info); 340899a2dd95SBruce Richardson if (diag != 0) { 340999a2dd95SBruce Richardson /* Cleanup already filled in device information */ 341099a2dd95SBruce Richardson memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); 341199a2dd95SBruce Richardson return eth_err(port_id, diag); 341299a2dd95SBruce Richardson } 341399a2dd95SBruce Richardson 341499a2dd95SBruce Richardson /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */ 341599a2dd95SBruce Richardson dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues, 341699a2dd95SBruce Richardson RTE_MAX_QUEUES_PER_PORT); 341799a2dd95SBruce Richardson dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues, 341899a2dd95SBruce Richardson RTE_MAX_QUEUES_PER_PORT); 341999a2dd95SBruce Richardson 342099a2dd95SBruce Richardson dev_info->driver_name = dev->device->driver->name; 342199a2dd95SBruce Richardson dev_info->nb_rx_queues = dev->data->nb_rx_queues; 342299a2dd95SBruce Richardson dev_info->nb_tx_queues = dev->data->nb_tx_queues; 342399a2dd95SBruce Richardson 342499a2dd95SBruce Richardson dev_info->dev_flags = &dev->data->dev_flags; 342599a2dd95SBruce Richardson 342699a2dd95SBruce Richardson return 0; 342799a2dd95SBruce Richardson } 342899a2dd95SBruce Richardson 342999a2dd95SBruce Richardson int 3430632be327SJie Wang rte_eth_dev_conf_get(uint16_t port_id, struct rte_eth_conf *dev_conf) 3431632be327SJie Wang { 3432632be327SJie Wang struct rte_eth_dev *dev; 3433632be327SJie Wang 3434632be327SJie Wang RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 3435632be327SJie Wang dev = &rte_eth_devices[port_id]; 3436632be327SJie Wang 3437632be327SJie Wang if (dev_conf == NULL) { 3438632be327SJie Wang RTE_ETHDEV_LOG(ERR, 3439632be327SJie Wang "Cannot get ethdev port %u configuration to NULL\n", 3440632be327SJie Wang port_id); 3441632be327SJie Wang return -EINVAL; 3442632be327SJie Wang } 3443632be327SJie Wang 3444632be327SJie Wang memcpy(dev_conf, &dev->data->dev_conf, sizeof(struct rte_eth_conf)); 3445632be327SJie Wang 3446632be327SJie Wang return 0; 3447632be327SJie Wang } 3448632be327SJie Wang 3449632be327SJie Wang int 345099a2dd95SBruce Richardson rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask, 345199a2dd95SBruce Richardson uint32_t *ptypes, int num) 345299a2dd95SBruce Richardson { 345399a2dd95SBruce Richardson int i, j; 345499a2dd95SBruce Richardson struct rte_eth_dev *dev; 345599a2dd95SBruce Richardson const uint32_t *all_ptypes; 345699a2dd95SBruce Richardson 345799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 345899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 345953ef1b34SMin Hu (Connor) 346053ef1b34SMin Hu (Connor) if (ptypes == NULL && num > 0) { 346153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 346253ef1b34SMin Hu (Connor) "Cannot get ethdev port %u supported packet types to NULL when array size is non zero\n", 346353ef1b34SMin Hu (Connor) port_id); 346453ef1b34SMin Hu (Connor) return -EINVAL; 346553ef1b34SMin Hu (Connor) } 346653ef1b34SMin Hu (Connor) 346799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0); 346899a2dd95SBruce Richardson all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev); 346999a2dd95SBruce Richardson 347099a2dd95SBruce Richardson if (!all_ptypes) 347199a2dd95SBruce Richardson return 0; 347299a2dd95SBruce Richardson 347399a2dd95SBruce Richardson for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i) 347499a2dd95SBruce Richardson if (all_ptypes[i] & ptype_mask) { 347599a2dd95SBruce Richardson if (j < num) 347699a2dd95SBruce Richardson ptypes[j] = all_ptypes[i]; 347799a2dd95SBruce Richardson j++; 347899a2dd95SBruce Richardson } 347999a2dd95SBruce Richardson 348099a2dd95SBruce Richardson return j; 348199a2dd95SBruce Richardson } 348299a2dd95SBruce Richardson 348399a2dd95SBruce Richardson int 348499a2dd95SBruce Richardson rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask, 348599a2dd95SBruce Richardson uint32_t *set_ptypes, unsigned int num) 348699a2dd95SBruce Richardson { 348799a2dd95SBruce Richardson const uint32_t valid_ptype_masks[] = { 348899a2dd95SBruce Richardson RTE_PTYPE_L2_MASK, 348999a2dd95SBruce Richardson RTE_PTYPE_L3_MASK, 349099a2dd95SBruce Richardson RTE_PTYPE_L4_MASK, 349199a2dd95SBruce Richardson RTE_PTYPE_TUNNEL_MASK, 349299a2dd95SBruce Richardson RTE_PTYPE_INNER_L2_MASK, 349399a2dd95SBruce Richardson RTE_PTYPE_INNER_L3_MASK, 349499a2dd95SBruce Richardson RTE_PTYPE_INNER_L4_MASK, 349599a2dd95SBruce Richardson }; 349699a2dd95SBruce Richardson const uint32_t *all_ptypes; 349799a2dd95SBruce Richardson struct rte_eth_dev *dev; 349899a2dd95SBruce Richardson uint32_t unused_mask; 349999a2dd95SBruce Richardson unsigned int i, j; 350099a2dd95SBruce Richardson int ret; 350199a2dd95SBruce Richardson 350299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 350399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 350499a2dd95SBruce Richardson 350553ef1b34SMin Hu (Connor) if (num > 0 && set_ptypes == NULL) { 350653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 350753ef1b34SMin Hu (Connor) "Cannot get ethdev port %u set packet types to NULL when array size is non zero\n", 350853ef1b34SMin Hu (Connor) port_id); 350999a2dd95SBruce Richardson return -EINVAL; 351053ef1b34SMin Hu (Connor) } 351199a2dd95SBruce Richardson 351299a2dd95SBruce Richardson if (*dev->dev_ops->dev_supported_ptypes_get == NULL || 351399a2dd95SBruce Richardson *dev->dev_ops->dev_ptypes_set == NULL) { 351499a2dd95SBruce Richardson ret = 0; 351599a2dd95SBruce Richardson goto ptype_unknown; 351699a2dd95SBruce Richardson } 351799a2dd95SBruce Richardson 351899a2dd95SBruce Richardson if (ptype_mask == 0) { 351999a2dd95SBruce Richardson ret = (*dev->dev_ops->dev_ptypes_set)(dev, 352099a2dd95SBruce Richardson ptype_mask); 352199a2dd95SBruce Richardson goto ptype_unknown; 352299a2dd95SBruce Richardson } 352399a2dd95SBruce Richardson 352499a2dd95SBruce Richardson unused_mask = ptype_mask; 352599a2dd95SBruce Richardson for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) { 352699a2dd95SBruce Richardson uint32_t mask = ptype_mask & valid_ptype_masks[i]; 352799a2dd95SBruce Richardson if (mask && mask != valid_ptype_masks[i]) { 352899a2dd95SBruce Richardson ret = -EINVAL; 352999a2dd95SBruce Richardson goto ptype_unknown; 353099a2dd95SBruce Richardson } 353199a2dd95SBruce Richardson unused_mask &= ~valid_ptype_masks[i]; 353299a2dd95SBruce Richardson } 353399a2dd95SBruce Richardson 353499a2dd95SBruce Richardson if (unused_mask) { 353599a2dd95SBruce Richardson ret = -EINVAL; 353699a2dd95SBruce Richardson goto ptype_unknown; 353799a2dd95SBruce Richardson } 353899a2dd95SBruce Richardson 353999a2dd95SBruce Richardson all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev); 354099a2dd95SBruce Richardson if (all_ptypes == NULL) { 354199a2dd95SBruce Richardson ret = 0; 354299a2dd95SBruce Richardson goto ptype_unknown; 354399a2dd95SBruce Richardson } 354499a2dd95SBruce Richardson 354599a2dd95SBruce Richardson /* 354699a2dd95SBruce Richardson * Accommodate as many set_ptypes as possible. If the supplied 354799a2dd95SBruce Richardson * set_ptypes array is insufficient fill it partially. 354899a2dd95SBruce Richardson */ 354999a2dd95SBruce Richardson for (i = 0, j = 0; set_ptypes != NULL && 355099a2dd95SBruce Richardson (all_ptypes[i] != RTE_PTYPE_UNKNOWN); ++i) { 355199a2dd95SBruce Richardson if (ptype_mask & all_ptypes[i]) { 355299a2dd95SBruce Richardson if (j < num - 1) { 355399a2dd95SBruce Richardson set_ptypes[j] = all_ptypes[i]; 355499a2dd95SBruce Richardson j++; 355599a2dd95SBruce Richardson continue; 355699a2dd95SBruce Richardson } 355799a2dd95SBruce Richardson break; 355899a2dd95SBruce Richardson } 355999a2dd95SBruce Richardson } 356099a2dd95SBruce Richardson 356199a2dd95SBruce Richardson if (set_ptypes != NULL && j < num) 356299a2dd95SBruce Richardson set_ptypes[j] = RTE_PTYPE_UNKNOWN; 356399a2dd95SBruce Richardson 356499a2dd95SBruce Richardson return (*dev->dev_ops->dev_ptypes_set)(dev, ptype_mask); 356599a2dd95SBruce Richardson 356699a2dd95SBruce Richardson ptype_unknown: 356799a2dd95SBruce Richardson if (num > 0) 356899a2dd95SBruce Richardson set_ptypes[0] = RTE_PTYPE_UNKNOWN; 356999a2dd95SBruce Richardson 357099a2dd95SBruce Richardson return ret; 357199a2dd95SBruce Richardson } 357299a2dd95SBruce Richardson 357399a2dd95SBruce Richardson int 357427a300e6SKonstantin Ananyev rte_eth_macaddrs_get(uint16_t port_id, struct rte_ether_addr *ma, 357527a300e6SKonstantin Ananyev unsigned int num) 357627a300e6SKonstantin Ananyev { 357727a300e6SKonstantin Ananyev int32_t ret; 357827a300e6SKonstantin Ananyev struct rte_eth_dev *dev; 357927a300e6SKonstantin Ananyev struct rte_eth_dev_info dev_info; 358027a300e6SKonstantin Ananyev 358127a300e6SKonstantin Ananyev if (ma == NULL) { 358227a300e6SKonstantin Ananyev RTE_ETHDEV_LOG(ERR, "%s: invalid parameters\n", __func__); 358327a300e6SKonstantin Ananyev return -EINVAL; 358427a300e6SKonstantin Ananyev } 358527a300e6SKonstantin Ananyev 358627a300e6SKonstantin Ananyev /* will check for us that port_id is a valid one */ 358727a300e6SKonstantin Ananyev ret = rte_eth_dev_info_get(port_id, &dev_info); 358827a300e6SKonstantin Ananyev if (ret != 0) 358927a300e6SKonstantin Ananyev return ret; 359027a300e6SKonstantin Ananyev 359127a300e6SKonstantin Ananyev dev = &rte_eth_devices[port_id]; 359227a300e6SKonstantin Ananyev num = RTE_MIN(dev_info.max_mac_addrs, num); 359327a300e6SKonstantin Ananyev memcpy(ma, dev->data->mac_addrs, num * sizeof(ma[0])); 359427a300e6SKonstantin Ananyev 359527a300e6SKonstantin Ananyev return num; 359627a300e6SKonstantin Ananyev } 359727a300e6SKonstantin Ananyev 359827a300e6SKonstantin Ananyev int 359999a2dd95SBruce Richardson rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr) 360099a2dd95SBruce Richardson { 360199a2dd95SBruce Richardson struct rte_eth_dev *dev; 360299a2dd95SBruce Richardson 360399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 360499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 360553ef1b34SMin Hu (Connor) 360653ef1b34SMin Hu (Connor) if (mac_addr == NULL) { 360753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 360853ef1b34SMin Hu (Connor) "Cannot get ethdev port %u MAC address to NULL\n", 360953ef1b34SMin Hu (Connor) port_id); 361053ef1b34SMin Hu (Connor) return -EINVAL; 361153ef1b34SMin Hu (Connor) } 361253ef1b34SMin Hu (Connor) 361399a2dd95SBruce Richardson rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr); 361499a2dd95SBruce Richardson 361599a2dd95SBruce Richardson return 0; 361699a2dd95SBruce Richardson } 361799a2dd95SBruce Richardson 361899a2dd95SBruce Richardson int 361999a2dd95SBruce Richardson rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu) 362099a2dd95SBruce Richardson { 362199a2dd95SBruce Richardson struct rte_eth_dev *dev; 362299a2dd95SBruce Richardson 362399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 362499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 362553ef1b34SMin Hu (Connor) 362653ef1b34SMin Hu (Connor) if (mtu == NULL) { 362753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u MTU to NULL\n", 362853ef1b34SMin Hu (Connor) port_id); 362953ef1b34SMin Hu (Connor) return -EINVAL; 363053ef1b34SMin Hu (Connor) } 363153ef1b34SMin Hu (Connor) 363299a2dd95SBruce Richardson *mtu = dev->data->mtu; 363399a2dd95SBruce Richardson return 0; 363499a2dd95SBruce Richardson } 363599a2dd95SBruce Richardson 363699a2dd95SBruce Richardson int 363799a2dd95SBruce Richardson rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu) 363899a2dd95SBruce Richardson { 363999a2dd95SBruce Richardson int ret; 364099a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 364199a2dd95SBruce Richardson struct rte_eth_dev *dev; 364299a2dd95SBruce Richardson 364399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 364499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 364599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP); 364699a2dd95SBruce Richardson 364799a2dd95SBruce Richardson /* 364899a2dd95SBruce Richardson * Check if the device supports dev_infos_get, if it does not 364999a2dd95SBruce Richardson * skip min_mtu/max_mtu validation here as this requires values 365099a2dd95SBruce Richardson * that are populated within the call to rte_eth_dev_info_get() 365199a2dd95SBruce Richardson * which relies on dev->dev_ops->dev_infos_get. 365299a2dd95SBruce Richardson */ 365399a2dd95SBruce Richardson if (*dev->dev_ops->dev_infos_get != NULL) { 3654f7e04f57SFerruh Yigit uint16_t overhead_len; 3655f7e04f57SFerruh Yigit uint32_t frame_size; 3656f7e04f57SFerruh Yigit 365799a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 365899a2dd95SBruce Richardson if (ret != 0) 365999a2dd95SBruce Richardson return ret; 366099a2dd95SBruce Richardson 366199a2dd95SBruce Richardson if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu) 366299a2dd95SBruce Richardson return -EINVAL; 3663dd4e429cSFerruh Yigit 3664f7e04f57SFerruh Yigit overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen, 3665f7e04f57SFerruh Yigit dev_info.max_mtu); 3666f7e04f57SFerruh Yigit frame_size = mtu + overhead_len; 3667f7e04f57SFerruh Yigit if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) 3668f7e04f57SFerruh Yigit return -EINVAL; 366999a2dd95SBruce Richardson } 367099a2dd95SBruce Richardson 367199a2dd95SBruce Richardson ret = (*dev->dev_ops->mtu_set)(dev, mtu); 3672*b563c142SFerruh Yigit if (ret == 0) 367399a2dd95SBruce Richardson dev->data->mtu = mtu; 367499a2dd95SBruce Richardson 367599a2dd95SBruce Richardson return eth_err(port_id, ret); 367699a2dd95SBruce Richardson } 367799a2dd95SBruce Richardson 367899a2dd95SBruce Richardson int 367999a2dd95SBruce Richardson rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) 368099a2dd95SBruce Richardson { 368199a2dd95SBruce Richardson struct rte_eth_dev *dev; 368299a2dd95SBruce Richardson int ret; 368399a2dd95SBruce Richardson 368499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 368599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 368653ef1b34SMin Hu (Connor) 368799a2dd95SBruce Richardson if (!(dev->data->dev_conf.rxmode.offloads & 368899a2dd95SBruce Richardson DEV_RX_OFFLOAD_VLAN_FILTER)) { 368999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n", 369099a2dd95SBruce Richardson port_id); 369199a2dd95SBruce Richardson return -ENOSYS; 369299a2dd95SBruce Richardson } 369399a2dd95SBruce Richardson 369499a2dd95SBruce Richardson if (vlan_id > 4095) { 369599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port_id=%u invalid vlan_id=%u > 4095\n", 369699a2dd95SBruce Richardson port_id, vlan_id); 369799a2dd95SBruce Richardson return -EINVAL; 369899a2dd95SBruce Richardson } 369999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP); 370099a2dd95SBruce Richardson 370199a2dd95SBruce Richardson ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on); 370299a2dd95SBruce Richardson if (ret == 0) { 370399a2dd95SBruce Richardson struct rte_vlan_filter_conf *vfc; 370499a2dd95SBruce Richardson int vidx; 370599a2dd95SBruce Richardson int vbit; 370699a2dd95SBruce Richardson 370799a2dd95SBruce Richardson vfc = &dev->data->vlan_filter_conf; 370899a2dd95SBruce Richardson vidx = vlan_id / 64; 370999a2dd95SBruce Richardson vbit = vlan_id % 64; 371099a2dd95SBruce Richardson 371199a2dd95SBruce Richardson if (on) 371299a2dd95SBruce Richardson vfc->ids[vidx] |= UINT64_C(1) << vbit; 371399a2dd95SBruce Richardson else 371499a2dd95SBruce Richardson vfc->ids[vidx] &= ~(UINT64_C(1) << vbit); 371599a2dd95SBruce Richardson } 371699a2dd95SBruce Richardson 371799a2dd95SBruce Richardson return eth_err(port_id, ret); 371899a2dd95SBruce Richardson } 371999a2dd95SBruce Richardson 372099a2dd95SBruce Richardson int 372199a2dd95SBruce Richardson rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id, 372299a2dd95SBruce Richardson int on) 372399a2dd95SBruce Richardson { 372499a2dd95SBruce Richardson struct rte_eth_dev *dev; 372599a2dd95SBruce Richardson 372699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 372799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 372853ef1b34SMin Hu (Connor) 372999a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 373099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid rx_queue_id=%u\n", rx_queue_id); 373199a2dd95SBruce Richardson return -EINVAL; 373299a2dd95SBruce Richardson } 373399a2dd95SBruce Richardson 373499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP); 373599a2dd95SBruce Richardson (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on); 373699a2dd95SBruce Richardson 373799a2dd95SBruce Richardson return 0; 373899a2dd95SBruce Richardson } 373999a2dd95SBruce Richardson 374099a2dd95SBruce Richardson int 374199a2dd95SBruce Richardson rte_eth_dev_set_vlan_ether_type(uint16_t port_id, 374299a2dd95SBruce Richardson enum rte_vlan_type vlan_type, 374399a2dd95SBruce Richardson uint16_t tpid) 374499a2dd95SBruce Richardson { 374599a2dd95SBruce Richardson struct rte_eth_dev *dev; 374699a2dd95SBruce Richardson 374799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 374899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 374999a2dd95SBruce Richardson 375053ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP); 375199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, 375299a2dd95SBruce Richardson tpid)); 375399a2dd95SBruce Richardson } 375499a2dd95SBruce Richardson 375599a2dd95SBruce Richardson int 375699a2dd95SBruce Richardson rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask) 375799a2dd95SBruce Richardson { 375899a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 375999a2dd95SBruce Richardson struct rte_eth_dev *dev; 376099a2dd95SBruce Richardson int ret = 0; 376199a2dd95SBruce Richardson int mask = 0; 376299a2dd95SBruce Richardson int cur, org = 0; 376399a2dd95SBruce Richardson uint64_t orig_offloads; 376499a2dd95SBruce Richardson uint64_t dev_offloads; 376599a2dd95SBruce Richardson uint64_t new_offloads; 376699a2dd95SBruce Richardson 376799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 376899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 376999a2dd95SBruce Richardson 377099a2dd95SBruce Richardson /* save original values in case of failure */ 377199a2dd95SBruce Richardson orig_offloads = dev->data->dev_conf.rxmode.offloads; 377299a2dd95SBruce Richardson dev_offloads = orig_offloads; 377399a2dd95SBruce Richardson 377499a2dd95SBruce Richardson /* check which option changed by application */ 377599a2dd95SBruce Richardson cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD); 377699a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP); 377799a2dd95SBruce Richardson if (cur != org) { 377899a2dd95SBruce Richardson if (cur) 377999a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP; 378099a2dd95SBruce Richardson else 378199a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP; 378299a2dd95SBruce Richardson mask |= ETH_VLAN_STRIP_MASK; 378399a2dd95SBruce Richardson } 378499a2dd95SBruce Richardson 378599a2dd95SBruce Richardson cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD); 378699a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER); 378799a2dd95SBruce Richardson if (cur != org) { 378899a2dd95SBruce Richardson if (cur) 378999a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER; 379099a2dd95SBruce Richardson else 379199a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER; 379299a2dd95SBruce Richardson mask |= ETH_VLAN_FILTER_MASK; 379399a2dd95SBruce Richardson } 379499a2dd95SBruce Richardson 379599a2dd95SBruce Richardson cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD); 379699a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND); 379799a2dd95SBruce Richardson if (cur != org) { 379899a2dd95SBruce Richardson if (cur) 379999a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND; 380099a2dd95SBruce Richardson else 380199a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND; 380299a2dd95SBruce Richardson mask |= ETH_VLAN_EXTEND_MASK; 380399a2dd95SBruce Richardson } 380499a2dd95SBruce Richardson 380599a2dd95SBruce Richardson cur = !!(offload_mask & ETH_QINQ_STRIP_OFFLOAD); 380699a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP); 380799a2dd95SBruce Richardson if (cur != org) { 380899a2dd95SBruce Richardson if (cur) 380999a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP; 381099a2dd95SBruce Richardson else 381199a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP; 381299a2dd95SBruce Richardson mask |= ETH_QINQ_STRIP_MASK; 381399a2dd95SBruce Richardson } 381499a2dd95SBruce Richardson 381599a2dd95SBruce Richardson /*no change*/ 381699a2dd95SBruce Richardson if (mask == 0) 381799a2dd95SBruce Richardson return ret; 381899a2dd95SBruce Richardson 381999a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 382099a2dd95SBruce Richardson if (ret != 0) 382199a2dd95SBruce Richardson return ret; 382299a2dd95SBruce Richardson 382399a2dd95SBruce Richardson /* Rx VLAN offloading must be within its device capabilities */ 382499a2dd95SBruce Richardson if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) { 382599a2dd95SBruce Richardson new_offloads = dev_offloads & ~orig_offloads; 382699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 382799a2dd95SBruce Richardson "Ethdev port_id=%u requested new added VLAN offloads " 382899a2dd95SBruce Richardson "0x%" PRIx64 " must be within Rx offloads capabilities " 382999a2dd95SBruce Richardson "0x%" PRIx64 " in %s()\n", 383099a2dd95SBruce Richardson port_id, new_offloads, dev_info.rx_offload_capa, 383199a2dd95SBruce Richardson __func__); 383299a2dd95SBruce Richardson return -EINVAL; 383399a2dd95SBruce Richardson } 383499a2dd95SBruce Richardson 383599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP); 383699a2dd95SBruce Richardson dev->data->dev_conf.rxmode.offloads = dev_offloads; 383799a2dd95SBruce Richardson ret = (*dev->dev_ops->vlan_offload_set)(dev, mask); 383899a2dd95SBruce Richardson if (ret) { 383999a2dd95SBruce Richardson /* hit an error restore original values */ 384099a2dd95SBruce Richardson dev->data->dev_conf.rxmode.offloads = orig_offloads; 384199a2dd95SBruce Richardson } 384299a2dd95SBruce Richardson 384399a2dd95SBruce Richardson return eth_err(port_id, ret); 384499a2dd95SBruce Richardson } 384599a2dd95SBruce Richardson 384699a2dd95SBruce Richardson int 384799a2dd95SBruce Richardson rte_eth_dev_get_vlan_offload(uint16_t port_id) 384899a2dd95SBruce Richardson { 384999a2dd95SBruce Richardson struct rte_eth_dev *dev; 385099a2dd95SBruce Richardson uint64_t *dev_offloads; 385199a2dd95SBruce Richardson int ret = 0; 385299a2dd95SBruce Richardson 385399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 385499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 385599a2dd95SBruce Richardson dev_offloads = &dev->data->dev_conf.rxmode.offloads; 385699a2dd95SBruce Richardson 385799a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP) 385899a2dd95SBruce Richardson ret |= ETH_VLAN_STRIP_OFFLOAD; 385999a2dd95SBruce Richardson 386099a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER) 386199a2dd95SBruce Richardson ret |= ETH_VLAN_FILTER_OFFLOAD; 386299a2dd95SBruce Richardson 386399a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND) 386499a2dd95SBruce Richardson ret |= ETH_VLAN_EXTEND_OFFLOAD; 386599a2dd95SBruce Richardson 386699a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP) 386799a2dd95SBruce Richardson ret |= ETH_QINQ_STRIP_OFFLOAD; 386899a2dd95SBruce Richardson 386999a2dd95SBruce Richardson return ret; 387099a2dd95SBruce Richardson } 387199a2dd95SBruce Richardson 387299a2dd95SBruce Richardson int 387399a2dd95SBruce Richardson rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on) 387499a2dd95SBruce Richardson { 387599a2dd95SBruce Richardson struct rte_eth_dev *dev; 387699a2dd95SBruce Richardson 387799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 387899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 387999a2dd95SBruce Richardson 388053ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP); 388199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on)); 388299a2dd95SBruce Richardson } 388399a2dd95SBruce Richardson 388499a2dd95SBruce Richardson int 388599a2dd95SBruce Richardson rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf) 388699a2dd95SBruce Richardson { 388799a2dd95SBruce Richardson struct rte_eth_dev *dev; 388899a2dd95SBruce Richardson 388999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 389099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 389153ef1b34SMin Hu (Connor) 389253ef1b34SMin Hu (Connor) if (fc_conf == NULL) { 389353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 389453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u flow control config to NULL\n", 389553ef1b34SMin Hu (Connor) port_id); 389653ef1b34SMin Hu (Connor) return -EINVAL; 389753ef1b34SMin Hu (Connor) } 389853ef1b34SMin Hu (Connor) 389999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP); 390099a2dd95SBruce Richardson memset(fc_conf, 0, sizeof(*fc_conf)); 390199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf)); 390299a2dd95SBruce Richardson } 390399a2dd95SBruce Richardson 390499a2dd95SBruce Richardson int 390599a2dd95SBruce Richardson rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf) 390699a2dd95SBruce Richardson { 390799a2dd95SBruce Richardson struct rte_eth_dev *dev; 390899a2dd95SBruce Richardson 390999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 391053ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 391153ef1b34SMin Hu (Connor) 391253ef1b34SMin Hu (Connor) if (fc_conf == NULL) { 391353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 391453ef1b34SMin Hu (Connor) "Cannot set ethdev port %u flow control from NULL config\n", 391553ef1b34SMin Hu (Connor) port_id); 391653ef1b34SMin Hu (Connor) return -EINVAL; 391753ef1b34SMin Hu (Connor) } 391853ef1b34SMin Hu (Connor) 391999a2dd95SBruce Richardson if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) { 392099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid send_xon, only 0/1 allowed\n"); 392199a2dd95SBruce Richardson return -EINVAL; 392299a2dd95SBruce Richardson } 392399a2dd95SBruce Richardson 392499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP); 392599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf)); 392699a2dd95SBruce Richardson } 392799a2dd95SBruce Richardson 392899a2dd95SBruce Richardson int 392999a2dd95SBruce Richardson rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id, 393099a2dd95SBruce Richardson struct rte_eth_pfc_conf *pfc_conf) 393199a2dd95SBruce Richardson { 393299a2dd95SBruce Richardson struct rte_eth_dev *dev; 393399a2dd95SBruce Richardson 393499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 393553ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 393653ef1b34SMin Hu (Connor) 393753ef1b34SMin Hu (Connor) if (pfc_conf == NULL) { 393853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 393953ef1b34SMin Hu (Connor) "Cannot set ethdev port %u priority flow control from NULL config\n", 394053ef1b34SMin Hu (Connor) port_id); 394153ef1b34SMin Hu (Connor) return -EINVAL; 394253ef1b34SMin Hu (Connor) } 394353ef1b34SMin Hu (Connor) 394499a2dd95SBruce Richardson if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) { 394599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid priority, only 0-7 allowed\n"); 394699a2dd95SBruce Richardson return -EINVAL; 394799a2dd95SBruce Richardson } 394899a2dd95SBruce Richardson 394999a2dd95SBruce Richardson /* High water, low water validation are device specific */ 395099a2dd95SBruce Richardson if (*dev->dev_ops->priority_flow_ctrl_set) 395199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set) 395299a2dd95SBruce Richardson (dev, pfc_conf)); 395399a2dd95SBruce Richardson return -ENOTSUP; 395499a2dd95SBruce Richardson } 395599a2dd95SBruce Richardson 395699a2dd95SBruce Richardson static int 395799a2dd95SBruce Richardson eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf, 395899a2dd95SBruce Richardson uint16_t reta_size) 395999a2dd95SBruce Richardson { 396099a2dd95SBruce Richardson uint16_t i, num; 396199a2dd95SBruce Richardson 396299a2dd95SBruce Richardson num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE; 396399a2dd95SBruce Richardson for (i = 0; i < num; i++) { 396499a2dd95SBruce Richardson if (reta_conf[i].mask) 396599a2dd95SBruce Richardson return 0; 396699a2dd95SBruce Richardson } 396799a2dd95SBruce Richardson 396899a2dd95SBruce Richardson return -EINVAL; 396999a2dd95SBruce Richardson } 397099a2dd95SBruce Richardson 397199a2dd95SBruce Richardson static int 397299a2dd95SBruce Richardson eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf, 397399a2dd95SBruce Richardson uint16_t reta_size, 397499a2dd95SBruce Richardson uint16_t max_rxq) 397599a2dd95SBruce Richardson { 397699a2dd95SBruce Richardson uint16_t i, idx, shift; 397799a2dd95SBruce Richardson 397899a2dd95SBruce Richardson if (max_rxq == 0) { 397999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "No receive queue is available\n"); 398099a2dd95SBruce Richardson return -EINVAL; 398199a2dd95SBruce Richardson } 398299a2dd95SBruce Richardson 398399a2dd95SBruce Richardson for (i = 0; i < reta_size; i++) { 398499a2dd95SBruce Richardson idx = i / RTE_RETA_GROUP_SIZE; 398599a2dd95SBruce Richardson shift = i % RTE_RETA_GROUP_SIZE; 398699a2dd95SBruce Richardson if ((reta_conf[idx].mask & (1ULL << shift)) && 398799a2dd95SBruce Richardson (reta_conf[idx].reta[shift] >= max_rxq)) { 398899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 398999a2dd95SBruce Richardson "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n", 399099a2dd95SBruce Richardson idx, shift, 399199a2dd95SBruce Richardson reta_conf[idx].reta[shift], max_rxq); 399299a2dd95SBruce Richardson return -EINVAL; 399399a2dd95SBruce Richardson } 399499a2dd95SBruce Richardson } 399599a2dd95SBruce Richardson 399699a2dd95SBruce Richardson return 0; 399799a2dd95SBruce Richardson } 399899a2dd95SBruce Richardson 399999a2dd95SBruce Richardson int 400099a2dd95SBruce Richardson rte_eth_dev_rss_reta_update(uint16_t port_id, 400199a2dd95SBruce Richardson struct rte_eth_rss_reta_entry64 *reta_conf, 400299a2dd95SBruce Richardson uint16_t reta_size) 400399a2dd95SBruce Richardson { 400499a2dd95SBruce Richardson struct rte_eth_dev *dev; 400599a2dd95SBruce Richardson int ret; 400699a2dd95SBruce Richardson 400799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 400853ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 400953ef1b34SMin Hu (Connor) 401053ef1b34SMin Hu (Connor) if (reta_conf == NULL) { 401153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 401253ef1b34SMin Hu (Connor) "Cannot update ethdev port %u RSS RETA to NULL\n", 401353ef1b34SMin Hu (Connor) port_id); 401453ef1b34SMin Hu (Connor) return -EINVAL; 401553ef1b34SMin Hu (Connor) } 401653ef1b34SMin Hu (Connor) 401753ef1b34SMin Hu (Connor) if (reta_size == 0) { 401853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 401953ef1b34SMin Hu (Connor) "Cannot update ethdev port %u RSS RETA with zero size\n", 402053ef1b34SMin Hu (Connor) port_id); 402153ef1b34SMin Hu (Connor) return -EINVAL; 402253ef1b34SMin Hu (Connor) } 402353ef1b34SMin Hu (Connor) 402499a2dd95SBruce Richardson /* Check mask bits */ 402599a2dd95SBruce Richardson ret = eth_check_reta_mask(reta_conf, reta_size); 402699a2dd95SBruce Richardson if (ret < 0) 402799a2dd95SBruce Richardson return ret; 402899a2dd95SBruce Richardson 402999a2dd95SBruce Richardson /* Check entry value */ 403099a2dd95SBruce Richardson ret = eth_check_reta_entry(reta_conf, reta_size, 403199a2dd95SBruce Richardson dev->data->nb_rx_queues); 403299a2dd95SBruce Richardson if (ret < 0) 403399a2dd95SBruce Richardson return ret; 403499a2dd95SBruce Richardson 403599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP); 403699a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->reta_update)(dev, reta_conf, 403799a2dd95SBruce Richardson reta_size)); 403899a2dd95SBruce Richardson } 403999a2dd95SBruce Richardson 404099a2dd95SBruce Richardson int 404199a2dd95SBruce Richardson rte_eth_dev_rss_reta_query(uint16_t port_id, 404299a2dd95SBruce Richardson struct rte_eth_rss_reta_entry64 *reta_conf, 404399a2dd95SBruce Richardson uint16_t reta_size) 404499a2dd95SBruce Richardson { 404599a2dd95SBruce Richardson struct rte_eth_dev *dev; 404699a2dd95SBruce Richardson int ret; 404799a2dd95SBruce Richardson 404899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 404953ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 405053ef1b34SMin Hu (Connor) 405153ef1b34SMin Hu (Connor) if (reta_conf == NULL) { 405253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 405353ef1b34SMin Hu (Connor) "Cannot query ethdev port %u RSS RETA from NULL config\n", 405453ef1b34SMin Hu (Connor) port_id); 405553ef1b34SMin Hu (Connor) return -EINVAL; 405653ef1b34SMin Hu (Connor) } 405799a2dd95SBruce Richardson 405899a2dd95SBruce Richardson /* Check mask bits */ 405999a2dd95SBruce Richardson ret = eth_check_reta_mask(reta_conf, reta_size); 406099a2dd95SBruce Richardson if (ret < 0) 406199a2dd95SBruce Richardson return ret; 406299a2dd95SBruce Richardson 406399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP); 406499a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf, 406599a2dd95SBruce Richardson reta_size)); 406699a2dd95SBruce Richardson } 406799a2dd95SBruce Richardson 406899a2dd95SBruce Richardson int 406999a2dd95SBruce Richardson rte_eth_dev_rss_hash_update(uint16_t port_id, 407099a2dd95SBruce Richardson struct rte_eth_rss_conf *rss_conf) 407199a2dd95SBruce Richardson { 407299a2dd95SBruce Richardson struct rte_eth_dev *dev; 407399a2dd95SBruce Richardson struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, }; 407499a2dd95SBruce Richardson int ret; 407599a2dd95SBruce Richardson 407699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 407753ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 407853ef1b34SMin Hu (Connor) 407953ef1b34SMin Hu (Connor) if (rss_conf == NULL) { 408053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 408153ef1b34SMin Hu (Connor) "Cannot update ethdev port %u RSS hash from NULL config\n", 408253ef1b34SMin Hu (Connor) port_id); 408353ef1b34SMin Hu (Connor) return -EINVAL; 408453ef1b34SMin Hu (Connor) } 408599a2dd95SBruce Richardson 408699a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 408799a2dd95SBruce Richardson if (ret != 0) 408899a2dd95SBruce Richardson return ret; 408999a2dd95SBruce Richardson 409099a2dd95SBruce Richardson rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf); 409199a2dd95SBruce Richardson if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) != 409299a2dd95SBruce Richardson dev_info.flow_type_rss_offloads) { 409399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 409499a2dd95SBruce Richardson "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n", 409599a2dd95SBruce Richardson port_id, rss_conf->rss_hf, 409699a2dd95SBruce Richardson dev_info.flow_type_rss_offloads); 409799a2dd95SBruce Richardson return -EINVAL; 409899a2dd95SBruce Richardson } 409999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP); 410099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->rss_hash_update)(dev, 410199a2dd95SBruce Richardson rss_conf)); 410299a2dd95SBruce Richardson } 410399a2dd95SBruce Richardson 410499a2dd95SBruce Richardson int 410599a2dd95SBruce Richardson rte_eth_dev_rss_hash_conf_get(uint16_t port_id, 410699a2dd95SBruce Richardson struct rte_eth_rss_conf *rss_conf) 410799a2dd95SBruce Richardson { 410899a2dd95SBruce Richardson struct rte_eth_dev *dev; 410999a2dd95SBruce Richardson 411099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 411199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 411253ef1b34SMin Hu (Connor) 411353ef1b34SMin Hu (Connor) if (rss_conf == NULL) { 411453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 411553ef1b34SMin Hu (Connor) "Cannot get ethdev port %u RSS hash config to NULL\n", 411653ef1b34SMin Hu (Connor) port_id); 411753ef1b34SMin Hu (Connor) return -EINVAL; 411853ef1b34SMin Hu (Connor) } 411953ef1b34SMin Hu (Connor) 412099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP); 412199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev, 412299a2dd95SBruce Richardson rss_conf)); 412399a2dd95SBruce Richardson } 412499a2dd95SBruce Richardson 412599a2dd95SBruce Richardson int 412699a2dd95SBruce Richardson rte_eth_dev_udp_tunnel_port_add(uint16_t port_id, 412799a2dd95SBruce Richardson struct rte_eth_udp_tunnel *udp_tunnel) 412899a2dd95SBruce Richardson { 412999a2dd95SBruce Richardson struct rte_eth_dev *dev; 413099a2dd95SBruce Richardson 413199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 413253ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 413353ef1b34SMin Hu (Connor) 413499a2dd95SBruce Richardson if (udp_tunnel == NULL) { 413553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 413653ef1b34SMin Hu (Connor) "Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel\n", 413753ef1b34SMin Hu (Connor) port_id); 413899a2dd95SBruce Richardson return -EINVAL; 413999a2dd95SBruce Richardson } 414099a2dd95SBruce Richardson 414199a2dd95SBruce Richardson if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { 414299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n"); 414399a2dd95SBruce Richardson return -EINVAL; 414499a2dd95SBruce Richardson } 414599a2dd95SBruce Richardson 414699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP); 414799a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev, 414899a2dd95SBruce Richardson udp_tunnel)); 414999a2dd95SBruce Richardson } 415099a2dd95SBruce Richardson 415199a2dd95SBruce Richardson int 415299a2dd95SBruce Richardson rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id, 415399a2dd95SBruce Richardson struct rte_eth_udp_tunnel *udp_tunnel) 415499a2dd95SBruce Richardson { 415599a2dd95SBruce Richardson struct rte_eth_dev *dev; 415699a2dd95SBruce Richardson 415799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 415899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 415999a2dd95SBruce Richardson 416099a2dd95SBruce Richardson if (udp_tunnel == NULL) { 416153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 416253ef1b34SMin Hu (Connor) "Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel\n", 416353ef1b34SMin Hu (Connor) port_id); 416499a2dd95SBruce Richardson return -EINVAL; 416599a2dd95SBruce Richardson } 416699a2dd95SBruce Richardson 416799a2dd95SBruce Richardson if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { 416899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n"); 416999a2dd95SBruce Richardson return -EINVAL; 417099a2dd95SBruce Richardson } 417199a2dd95SBruce Richardson 417299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP); 417399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_del)(dev, 417499a2dd95SBruce Richardson udp_tunnel)); 417599a2dd95SBruce Richardson } 417699a2dd95SBruce Richardson 417799a2dd95SBruce Richardson int 417899a2dd95SBruce Richardson rte_eth_led_on(uint16_t port_id) 417999a2dd95SBruce Richardson { 418099a2dd95SBruce Richardson struct rte_eth_dev *dev; 418199a2dd95SBruce Richardson 418299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 418399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 418453ef1b34SMin Hu (Connor) 418599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP); 418699a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev)); 418799a2dd95SBruce Richardson } 418899a2dd95SBruce Richardson 418999a2dd95SBruce Richardson int 419099a2dd95SBruce Richardson rte_eth_led_off(uint16_t port_id) 419199a2dd95SBruce Richardson { 419299a2dd95SBruce Richardson struct rte_eth_dev *dev; 419399a2dd95SBruce Richardson 419499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 419599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 419653ef1b34SMin Hu (Connor) 419799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP); 419899a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev)); 419999a2dd95SBruce Richardson } 420099a2dd95SBruce Richardson 420199a2dd95SBruce Richardson int 420299a2dd95SBruce Richardson rte_eth_fec_get_capability(uint16_t port_id, 420399a2dd95SBruce Richardson struct rte_eth_fec_capa *speed_fec_capa, 420499a2dd95SBruce Richardson unsigned int num) 420599a2dd95SBruce Richardson { 420699a2dd95SBruce Richardson struct rte_eth_dev *dev; 420799a2dd95SBruce Richardson int ret; 420899a2dd95SBruce Richardson 420999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 421099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 421153ef1b34SMin Hu (Connor) 421253ef1b34SMin Hu (Connor) if (speed_fec_capa == NULL && num > 0) { 421353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 421453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u FEC capability to NULL when array size is non zero\n", 421553ef1b34SMin Hu (Connor) port_id); 421653ef1b34SMin Hu (Connor) return -EINVAL; 421753ef1b34SMin Hu (Connor) } 421853ef1b34SMin Hu (Connor) 421999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get_capability, -ENOTSUP); 422099a2dd95SBruce Richardson ret = (*dev->dev_ops->fec_get_capability)(dev, speed_fec_capa, num); 422199a2dd95SBruce Richardson 422299a2dd95SBruce Richardson return ret; 422399a2dd95SBruce Richardson } 422499a2dd95SBruce Richardson 422599a2dd95SBruce Richardson int 422699a2dd95SBruce Richardson rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa) 422799a2dd95SBruce Richardson { 422899a2dd95SBruce Richardson struct rte_eth_dev *dev; 422999a2dd95SBruce Richardson 423099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 423199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 423253ef1b34SMin Hu (Connor) 423353ef1b34SMin Hu (Connor) if (fec_capa == NULL) { 423453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 423553ef1b34SMin Hu (Connor) "Cannot get ethdev port %u current FEC mode to NULL\n", 423653ef1b34SMin Hu (Connor) port_id); 423753ef1b34SMin Hu (Connor) return -EINVAL; 423853ef1b34SMin Hu (Connor) } 423953ef1b34SMin Hu (Connor) 424099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get, -ENOTSUP); 424199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->fec_get)(dev, fec_capa)); 424299a2dd95SBruce Richardson } 424399a2dd95SBruce Richardson 424499a2dd95SBruce Richardson int 424599a2dd95SBruce Richardson rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa) 424699a2dd95SBruce Richardson { 424799a2dd95SBruce Richardson struct rte_eth_dev *dev; 424899a2dd95SBruce Richardson 424999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 425099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 425153ef1b34SMin Hu (Connor) 425299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_set, -ENOTSUP); 425399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->fec_set)(dev, fec_capa)); 425499a2dd95SBruce Richardson } 425599a2dd95SBruce Richardson 425699a2dd95SBruce Richardson /* 425799a2dd95SBruce Richardson * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find 425899a2dd95SBruce Richardson * an empty spot. 425999a2dd95SBruce Richardson */ 426099a2dd95SBruce Richardson static int 426199a2dd95SBruce Richardson eth_dev_get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr) 426299a2dd95SBruce Richardson { 426399a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 426499a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 426599a2dd95SBruce Richardson unsigned i; 426699a2dd95SBruce Richardson int ret; 426799a2dd95SBruce Richardson 426899a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 426999a2dd95SBruce Richardson if (ret != 0) 427099a2dd95SBruce Richardson return -1; 427199a2dd95SBruce Richardson 427299a2dd95SBruce Richardson for (i = 0; i < dev_info.max_mac_addrs; i++) 427399a2dd95SBruce Richardson if (memcmp(addr, &dev->data->mac_addrs[i], 427499a2dd95SBruce Richardson RTE_ETHER_ADDR_LEN) == 0) 427599a2dd95SBruce Richardson return i; 427699a2dd95SBruce Richardson 427799a2dd95SBruce Richardson return -1; 427899a2dd95SBruce Richardson } 427999a2dd95SBruce Richardson 428099a2dd95SBruce Richardson static const struct rte_ether_addr null_mac_addr; 428199a2dd95SBruce Richardson 428299a2dd95SBruce Richardson int 428399a2dd95SBruce Richardson rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, 428499a2dd95SBruce Richardson uint32_t pool) 428599a2dd95SBruce Richardson { 428699a2dd95SBruce Richardson struct rte_eth_dev *dev; 428799a2dd95SBruce Richardson int index; 428899a2dd95SBruce Richardson uint64_t pool_mask; 428999a2dd95SBruce Richardson int ret; 429099a2dd95SBruce Richardson 429199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 429299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 429353ef1b34SMin Hu (Connor) 429453ef1b34SMin Hu (Connor) if (addr == NULL) { 429553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 429653ef1b34SMin Hu (Connor) "Cannot add ethdev port %u MAC address from NULL address\n", 429753ef1b34SMin Hu (Connor) port_id); 429853ef1b34SMin Hu (Connor) return -EINVAL; 429953ef1b34SMin Hu (Connor) } 430053ef1b34SMin Hu (Connor) 430199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP); 430299a2dd95SBruce Richardson 430399a2dd95SBruce Richardson if (rte_is_zero_ether_addr(addr)) { 430499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n", 430599a2dd95SBruce Richardson port_id); 430699a2dd95SBruce Richardson return -EINVAL; 430799a2dd95SBruce Richardson } 430899a2dd95SBruce Richardson if (pool >= ETH_64_POOLS) { 430999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Pool id must be 0-%d\n", ETH_64_POOLS - 1); 431099a2dd95SBruce Richardson return -EINVAL; 431199a2dd95SBruce Richardson } 431299a2dd95SBruce Richardson 431399a2dd95SBruce Richardson index = eth_dev_get_mac_addr_index(port_id, addr); 431499a2dd95SBruce Richardson if (index < 0) { 431599a2dd95SBruce Richardson index = eth_dev_get_mac_addr_index(port_id, &null_mac_addr); 431699a2dd95SBruce Richardson if (index < 0) { 431799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n", 431899a2dd95SBruce Richardson port_id); 431999a2dd95SBruce Richardson return -ENOSPC; 432099a2dd95SBruce Richardson } 432199a2dd95SBruce Richardson } else { 432299a2dd95SBruce Richardson pool_mask = dev->data->mac_pool_sel[index]; 432399a2dd95SBruce Richardson 432499a2dd95SBruce Richardson /* Check if both MAC address and pool is already there, and do nothing */ 432599a2dd95SBruce Richardson if (pool_mask & (1ULL << pool)) 432699a2dd95SBruce Richardson return 0; 432799a2dd95SBruce Richardson } 432899a2dd95SBruce Richardson 432999a2dd95SBruce Richardson /* Update NIC */ 433099a2dd95SBruce Richardson ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool); 433199a2dd95SBruce Richardson 433299a2dd95SBruce Richardson if (ret == 0) { 433399a2dd95SBruce Richardson /* Update address in NIC data structure */ 433499a2dd95SBruce Richardson rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]); 433599a2dd95SBruce Richardson 433699a2dd95SBruce Richardson /* Update pool bitmap in NIC data structure */ 433799a2dd95SBruce Richardson dev->data->mac_pool_sel[index] |= (1ULL << pool); 433899a2dd95SBruce Richardson } 433999a2dd95SBruce Richardson 434099a2dd95SBruce Richardson return eth_err(port_id, ret); 434199a2dd95SBruce Richardson } 434299a2dd95SBruce Richardson 434399a2dd95SBruce Richardson int 434499a2dd95SBruce Richardson rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr) 434599a2dd95SBruce Richardson { 434699a2dd95SBruce Richardson struct rte_eth_dev *dev; 434799a2dd95SBruce Richardson int index; 434899a2dd95SBruce Richardson 434999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 435099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 435153ef1b34SMin Hu (Connor) 435253ef1b34SMin Hu (Connor) if (addr == NULL) { 435353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 435453ef1b34SMin Hu (Connor) "Cannot remove ethdev port %u MAC address from NULL address\n", 435553ef1b34SMin Hu (Connor) port_id); 435653ef1b34SMin Hu (Connor) return -EINVAL; 435753ef1b34SMin Hu (Connor) } 435853ef1b34SMin Hu (Connor) 435999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP); 436099a2dd95SBruce Richardson 436199a2dd95SBruce Richardson index = eth_dev_get_mac_addr_index(port_id, addr); 436299a2dd95SBruce Richardson if (index == 0) { 436399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 436499a2dd95SBruce Richardson "Port %u: Cannot remove default MAC address\n", 436599a2dd95SBruce Richardson port_id); 436699a2dd95SBruce Richardson return -EADDRINUSE; 436799a2dd95SBruce Richardson } else if (index < 0) 436899a2dd95SBruce Richardson return 0; /* Do nothing if address wasn't found */ 436999a2dd95SBruce Richardson 437099a2dd95SBruce Richardson /* Update NIC */ 437199a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_remove)(dev, index); 437299a2dd95SBruce Richardson 437399a2dd95SBruce Richardson /* Update address in NIC data structure */ 437499a2dd95SBruce Richardson rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]); 437599a2dd95SBruce Richardson 437699a2dd95SBruce Richardson /* reset pool bitmap */ 437799a2dd95SBruce Richardson dev->data->mac_pool_sel[index] = 0; 437899a2dd95SBruce Richardson 437999a2dd95SBruce Richardson return 0; 438099a2dd95SBruce Richardson } 438199a2dd95SBruce Richardson 438299a2dd95SBruce Richardson int 438399a2dd95SBruce Richardson rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) 438499a2dd95SBruce Richardson { 438599a2dd95SBruce Richardson struct rte_eth_dev *dev; 438699a2dd95SBruce Richardson int ret; 438799a2dd95SBruce Richardson 438899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 438953ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 439053ef1b34SMin Hu (Connor) 439153ef1b34SMin Hu (Connor) if (addr == NULL) { 439253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 439353ef1b34SMin Hu (Connor) "Cannot set ethdev port %u default MAC address from NULL address\n", 439453ef1b34SMin Hu (Connor) port_id); 439553ef1b34SMin Hu (Connor) return -EINVAL; 439653ef1b34SMin Hu (Connor) } 439799a2dd95SBruce Richardson 439899a2dd95SBruce Richardson if (!rte_is_valid_assigned_ether_addr(addr)) 439999a2dd95SBruce Richardson return -EINVAL; 440099a2dd95SBruce Richardson 440199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP); 440299a2dd95SBruce Richardson 440399a2dd95SBruce Richardson ret = (*dev->dev_ops->mac_addr_set)(dev, addr); 440499a2dd95SBruce Richardson if (ret < 0) 440599a2dd95SBruce Richardson return ret; 440699a2dd95SBruce Richardson 440799a2dd95SBruce Richardson /* Update default address in NIC data structure */ 440899a2dd95SBruce Richardson rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); 440999a2dd95SBruce Richardson 441099a2dd95SBruce Richardson return 0; 441199a2dd95SBruce Richardson } 441299a2dd95SBruce Richardson 441399a2dd95SBruce Richardson 441499a2dd95SBruce Richardson /* 441599a2dd95SBruce Richardson * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find 441699a2dd95SBruce Richardson * an empty spot. 441799a2dd95SBruce Richardson */ 441899a2dd95SBruce Richardson static int 441999a2dd95SBruce Richardson eth_dev_get_hash_mac_addr_index(uint16_t port_id, 442099a2dd95SBruce Richardson const struct rte_ether_addr *addr) 442199a2dd95SBruce Richardson { 442299a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 442399a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 442499a2dd95SBruce Richardson unsigned i; 442599a2dd95SBruce Richardson int ret; 442699a2dd95SBruce Richardson 442799a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 442899a2dd95SBruce Richardson if (ret != 0) 442999a2dd95SBruce Richardson return -1; 443099a2dd95SBruce Richardson 443199a2dd95SBruce Richardson if (!dev->data->hash_mac_addrs) 443299a2dd95SBruce Richardson return -1; 443399a2dd95SBruce Richardson 443499a2dd95SBruce Richardson for (i = 0; i < dev_info.max_hash_mac_addrs; i++) 443599a2dd95SBruce Richardson if (memcmp(addr, &dev->data->hash_mac_addrs[i], 443699a2dd95SBruce Richardson RTE_ETHER_ADDR_LEN) == 0) 443799a2dd95SBruce Richardson return i; 443899a2dd95SBruce Richardson 443999a2dd95SBruce Richardson return -1; 444099a2dd95SBruce Richardson } 444199a2dd95SBruce Richardson 444299a2dd95SBruce Richardson int 444399a2dd95SBruce Richardson rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr, 444499a2dd95SBruce Richardson uint8_t on) 444599a2dd95SBruce Richardson { 444699a2dd95SBruce Richardson int index; 444799a2dd95SBruce Richardson int ret; 444899a2dd95SBruce Richardson struct rte_eth_dev *dev; 444999a2dd95SBruce Richardson 445099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 445199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 445253ef1b34SMin Hu (Connor) 445353ef1b34SMin Hu (Connor) if (addr == NULL) { 445453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 445553ef1b34SMin Hu (Connor) "Cannot set ethdev port %u unicast hash table from NULL address\n", 445653ef1b34SMin Hu (Connor) port_id); 445753ef1b34SMin Hu (Connor) return -EINVAL; 445853ef1b34SMin Hu (Connor) } 445953ef1b34SMin Hu (Connor) 446099a2dd95SBruce Richardson if (rte_is_zero_ether_addr(addr)) { 446199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n", 446299a2dd95SBruce Richardson port_id); 446399a2dd95SBruce Richardson return -EINVAL; 446499a2dd95SBruce Richardson } 446599a2dd95SBruce Richardson 446699a2dd95SBruce Richardson index = eth_dev_get_hash_mac_addr_index(port_id, addr); 446799a2dd95SBruce Richardson /* Check if it's already there, and do nothing */ 446899a2dd95SBruce Richardson if ((index >= 0) && on) 446999a2dd95SBruce Richardson return 0; 447099a2dd95SBruce Richardson 447199a2dd95SBruce Richardson if (index < 0) { 447299a2dd95SBruce Richardson if (!on) { 447399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 447499a2dd95SBruce Richardson "Port %u: the MAC address was not set in UTA\n", 447599a2dd95SBruce Richardson port_id); 447699a2dd95SBruce Richardson return -EINVAL; 447799a2dd95SBruce Richardson } 447899a2dd95SBruce Richardson 447999a2dd95SBruce Richardson index = eth_dev_get_hash_mac_addr_index(port_id, &null_mac_addr); 448099a2dd95SBruce Richardson if (index < 0) { 448199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n", 448299a2dd95SBruce Richardson port_id); 448399a2dd95SBruce Richardson return -ENOSPC; 448499a2dd95SBruce Richardson } 448599a2dd95SBruce Richardson } 448699a2dd95SBruce Richardson 448799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP); 448899a2dd95SBruce Richardson ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on); 448999a2dd95SBruce Richardson if (ret == 0) { 449099a2dd95SBruce Richardson /* Update address in NIC data structure */ 449199a2dd95SBruce Richardson if (on) 449299a2dd95SBruce Richardson rte_ether_addr_copy(addr, 449399a2dd95SBruce Richardson &dev->data->hash_mac_addrs[index]); 449499a2dd95SBruce Richardson else 449599a2dd95SBruce Richardson rte_ether_addr_copy(&null_mac_addr, 449699a2dd95SBruce Richardson &dev->data->hash_mac_addrs[index]); 449799a2dd95SBruce Richardson } 449899a2dd95SBruce Richardson 449999a2dd95SBruce Richardson return eth_err(port_id, ret); 450099a2dd95SBruce Richardson } 450199a2dd95SBruce Richardson 450299a2dd95SBruce Richardson int 450399a2dd95SBruce Richardson rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on) 450499a2dd95SBruce Richardson { 450599a2dd95SBruce Richardson struct rte_eth_dev *dev; 450699a2dd95SBruce Richardson 450799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 450899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 450999a2dd95SBruce Richardson 451099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP); 451199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->uc_all_hash_table_set)(dev, 451299a2dd95SBruce Richardson on)); 451399a2dd95SBruce Richardson } 451499a2dd95SBruce Richardson 451599a2dd95SBruce Richardson int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx, 451699a2dd95SBruce Richardson uint16_t tx_rate) 451799a2dd95SBruce Richardson { 451899a2dd95SBruce Richardson struct rte_eth_dev *dev; 451999a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 452099a2dd95SBruce Richardson struct rte_eth_link link; 452199a2dd95SBruce Richardson int ret; 452299a2dd95SBruce Richardson 452399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 452453ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 452599a2dd95SBruce Richardson 452699a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 452799a2dd95SBruce Richardson if (ret != 0) 452899a2dd95SBruce Richardson return ret; 452999a2dd95SBruce Richardson 453099a2dd95SBruce Richardson link = dev->data->dev_link; 453199a2dd95SBruce Richardson 453299a2dd95SBruce Richardson if (queue_idx > dev_info.max_tx_queues) { 453399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 453499a2dd95SBruce Richardson "Set queue rate limit:port %u: invalid queue id=%u\n", 453599a2dd95SBruce Richardson port_id, queue_idx); 453699a2dd95SBruce Richardson return -EINVAL; 453799a2dd95SBruce Richardson } 453899a2dd95SBruce Richardson 453999a2dd95SBruce Richardson if (tx_rate > link.link_speed) { 454099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 454199a2dd95SBruce Richardson "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d\n", 454299a2dd95SBruce Richardson tx_rate, link.link_speed); 454399a2dd95SBruce Richardson return -EINVAL; 454499a2dd95SBruce Richardson } 454599a2dd95SBruce Richardson 454699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP); 454799a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->set_queue_rate_limit)(dev, 454899a2dd95SBruce Richardson queue_idx, tx_rate)); 454999a2dd95SBruce Richardson } 455099a2dd95SBruce Richardson 4551c87d435aSKonstantin Ananyev RTE_INIT(eth_dev_init_fp_ops) 4552c87d435aSKonstantin Ananyev { 4553c87d435aSKonstantin Ananyev uint32_t i; 4554c87d435aSKonstantin Ananyev 4555c87d435aSKonstantin Ananyev for (i = 0; i != RTE_DIM(rte_eth_fp_ops); i++) 4556c87d435aSKonstantin Ananyev eth_dev_fp_ops_reset(rte_eth_fp_ops + i); 4557c87d435aSKonstantin Ananyev } 4558c87d435aSKonstantin Ananyev 455999a2dd95SBruce Richardson RTE_INIT(eth_dev_init_cb_lists) 456099a2dd95SBruce Richardson { 456199a2dd95SBruce Richardson uint16_t i; 456299a2dd95SBruce Richardson 456399a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) 456499a2dd95SBruce Richardson TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs); 456599a2dd95SBruce Richardson } 456699a2dd95SBruce Richardson 456799a2dd95SBruce Richardson int 456899a2dd95SBruce Richardson rte_eth_dev_callback_register(uint16_t port_id, 456999a2dd95SBruce Richardson enum rte_eth_event_type event, 457099a2dd95SBruce Richardson rte_eth_dev_cb_fn cb_fn, void *cb_arg) 457199a2dd95SBruce Richardson { 457299a2dd95SBruce Richardson struct rte_eth_dev *dev; 457399a2dd95SBruce Richardson struct rte_eth_dev_callback *user_cb; 457499a2dd95SBruce Richardson uint16_t next_port; 457599a2dd95SBruce Richardson uint16_t last_port; 457699a2dd95SBruce Richardson 457753ef1b34SMin Hu (Connor) if (cb_fn == NULL) { 457853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 457953ef1b34SMin Hu (Connor) "Cannot register ethdev port %u callback from NULL\n", 458053ef1b34SMin Hu (Connor) port_id); 458199a2dd95SBruce Richardson return -EINVAL; 458253ef1b34SMin Hu (Connor) } 458399a2dd95SBruce Richardson 458499a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { 458599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id); 458699a2dd95SBruce Richardson return -EINVAL; 458799a2dd95SBruce Richardson } 458899a2dd95SBruce Richardson 458999a2dd95SBruce Richardson if (port_id == RTE_ETH_ALL) { 459099a2dd95SBruce Richardson next_port = 0; 459199a2dd95SBruce Richardson last_port = RTE_MAX_ETHPORTS - 1; 459299a2dd95SBruce Richardson } else { 459399a2dd95SBruce Richardson next_port = last_port = port_id; 459499a2dd95SBruce Richardson } 459599a2dd95SBruce Richardson 459699a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 459799a2dd95SBruce Richardson 459899a2dd95SBruce Richardson do { 459999a2dd95SBruce Richardson dev = &rte_eth_devices[next_port]; 460099a2dd95SBruce Richardson 460199a2dd95SBruce Richardson TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { 460299a2dd95SBruce Richardson if (user_cb->cb_fn == cb_fn && 460399a2dd95SBruce Richardson user_cb->cb_arg == cb_arg && 460499a2dd95SBruce Richardson user_cb->event == event) { 460599a2dd95SBruce Richardson break; 460699a2dd95SBruce Richardson } 460799a2dd95SBruce Richardson } 460899a2dd95SBruce Richardson 460999a2dd95SBruce Richardson /* create a new callback. */ 461099a2dd95SBruce Richardson if (user_cb == NULL) { 461199a2dd95SBruce Richardson user_cb = rte_zmalloc("INTR_USER_CALLBACK", 461299a2dd95SBruce Richardson sizeof(struct rte_eth_dev_callback), 0); 461399a2dd95SBruce Richardson if (user_cb != NULL) { 461499a2dd95SBruce Richardson user_cb->cb_fn = cb_fn; 461599a2dd95SBruce Richardson user_cb->cb_arg = cb_arg; 461699a2dd95SBruce Richardson user_cb->event = event; 461799a2dd95SBruce Richardson TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), 461899a2dd95SBruce Richardson user_cb, next); 461999a2dd95SBruce Richardson } else { 462099a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 462199a2dd95SBruce Richardson rte_eth_dev_callback_unregister(port_id, event, 462299a2dd95SBruce Richardson cb_fn, cb_arg); 462399a2dd95SBruce Richardson return -ENOMEM; 462499a2dd95SBruce Richardson } 462599a2dd95SBruce Richardson 462699a2dd95SBruce Richardson } 462799a2dd95SBruce Richardson } while (++next_port <= last_port); 462899a2dd95SBruce Richardson 462999a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 463099a2dd95SBruce Richardson return 0; 463199a2dd95SBruce Richardson } 463299a2dd95SBruce Richardson 463399a2dd95SBruce Richardson int 463499a2dd95SBruce Richardson rte_eth_dev_callback_unregister(uint16_t port_id, 463599a2dd95SBruce Richardson enum rte_eth_event_type event, 463699a2dd95SBruce Richardson rte_eth_dev_cb_fn cb_fn, void *cb_arg) 463799a2dd95SBruce Richardson { 463899a2dd95SBruce Richardson int ret; 463999a2dd95SBruce Richardson struct rte_eth_dev *dev; 464099a2dd95SBruce Richardson struct rte_eth_dev_callback *cb, *next; 464199a2dd95SBruce Richardson uint16_t next_port; 464299a2dd95SBruce Richardson uint16_t last_port; 464399a2dd95SBruce Richardson 464453ef1b34SMin Hu (Connor) if (cb_fn == NULL) { 464553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 464653ef1b34SMin Hu (Connor) "Cannot unregister ethdev port %u callback from NULL\n", 464753ef1b34SMin Hu (Connor) port_id); 464899a2dd95SBruce Richardson return -EINVAL; 464953ef1b34SMin Hu (Connor) } 465099a2dd95SBruce Richardson 465199a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { 465299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id); 465399a2dd95SBruce Richardson return -EINVAL; 465499a2dd95SBruce Richardson } 465599a2dd95SBruce Richardson 465699a2dd95SBruce Richardson if (port_id == RTE_ETH_ALL) { 465799a2dd95SBruce Richardson next_port = 0; 465899a2dd95SBruce Richardson last_port = RTE_MAX_ETHPORTS - 1; 465999a2dd95SBruce Richardson } else { 466099a2dd95SBruce Richardson next_port = last_port = port_id; 466199a2dd95SBruce Richardson } 466299a2dd95SBruce Richardson 466399a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 466499a2dd95SBruce Richardson 466599a2dd95SBruce Richardson do { 466699a2dd95SBruce Richardson dev = &rte_eth_devices[next_port]; 466799a2dd95SBruce Richardson ret = 0; 466899a2dd95SBruce Richardson for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; 466999a2dd95SBruce Richardson cb = next) { 467099a2dd95SBruce Richardson 467199a2dd95SBruce Richardson next = TAILQ_NEXT(cb, next); 467299a2dd95SBruce Richardson 467399a2dd95SBruce Richardson if (cb->cb_fn != cb_fn || cb->event != event || 467499a2dd95SBruce Richardson (cb_arg != (void *)-1 && cb->cb_arg != cb_arg)) 467599a2dd95SBruce Richardson continue; 467699a2dd95SBruce Richardson 467799a2dd95SBruce Richardson /* 467899a2dd95SBruce Richardson * if this callback is not executing right now, 467999a2dd95SBruce Richardson * then remove it. 468099a2dd95SBruce Richardson */ 468199a2dd95SBruce Richardson if (cb->active == 0) { 468299a2dd95SBruce Richardson TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); 468399a2dd95SBruce Richardson rte_free(cb); 468499a2dd95SBruce Richardson } else { 468599a2dd95SBruce Richardson ret = -EAGAIN; 468699a2dd95SBruce Richardson } 468799a2dd95SBruce Richardson } 468899a2dd95SBruce Richardson } while (++next_port <= last_port); 468999a2dd95SBruce Richardson 469099a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 469199a2dd95SBruce Richardson return ret; 469299a2dd95SBruce Richardson } 469399a2dd95SBruce Richardson 469499a2dd95SBruce Richardson int 469599a2dd95SBruce Richardson rte_eth_dev_callback_process(struct rte_eth_dev *dev, 469699a2dd95SBruce Richardson enum rte_eth_event_type event, void *ret_param) 469799a2dd95SBruce Richardson { 469899a2dd95SBruce Richardson struct rte_eth_dev_callback *cb_lst; 469999a2dd95SBruce Richardson struct rte_eth_dev_callback dev_cb; 470099a2dd95SBruce Richardson int rc = 0; 470199a2dd95SBruce Richardson 470299a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 470399a2dd95SBruce Richardson TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) { 470499a2dd95SBruce Richardson if (cb_lst->cb_fn == NULL || cb_lst->event != event) 470599a2dd95SBruce Richardson continue; 470699a2dd95SBruce Richardson dev_cb = *cb_lst; 470799a2dd95SBruce Richardson cb_lst->active = 1; 470899a2dd95SBruce Richardson if (ret_param != NULL) 470999a2dd95SBruce Richardson dev_cb.ret_param = ret_param; 471099a2dd95SBruce Richardson 471199a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 471299a2dd95SBruce Richardson rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event, 471399a2dd95SBruce Richardson dev_cb.cb_arg, dev_cb.ret_param); 471499a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 471599a2dd95SBruce Richardson cb_lst->active = 0; 471699a2dd95SBruce Richardson } 471799a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 471899a2dd95SBruce Richardson return rc; 471999a2dd95SBruce Richardson } 472099a2dd95SBruce Richardson 472199a2dd95SBruce Richardson void 472299a2dd95SBruce Richardson rte_eth_dev_probing_finish(struct rte_eth_dev *dev) 472399a2dd95SBruce Richardson { 472499a2dd95SBruce Richardson if (dev == NULL) 472599a2dd95SBruce Richardson return; 472699a2dd95SBruce Richardson 4727c87d435aSKonstantin Ananyev /* 4728c87d435aSKonstantin Ananyev * for secondary process, at that point we expect device 4729c87d435aSKonstantin Ananyev * to be already 'usable', so shared data and all function pointers 4730c87d435aSKonstantin Ananyev * for fast-path devops have to be setup properly inside rte_eth_dev. 4731c87d435aSKonstantin Ananyev */ 4732c87d435aSKonstantin Ananyev if (rte_eal_process_type() == RTE_PROC_SECONDARY) 4733c87d435aSKonstantin Ananyev eth_dev_fp_ops_setup(rte_eth_fp_ops + dev->data->port_id, dev); 4734c87d435aSKonstantin Ananyev 473599a2dd95SBruce Richardson rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL); 473699a2dd95SBruce Richardson 473799a2dd95SBruce Richardson dev->state = RTE_ETH_DEV_ATTACHED; 473899a2dd95SBruce Richardson } 473999a2dd95SBruce Richardson 474099a2dd95SBruce Richardson int 474199a2dd95SBruce Richardson rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data) 474299a2dd95SBruce Richardson { 474399a2dd95SBruce Richardson uint32_t vec; 474499a2dd95SBruce Richardson struct rte_eth_dev *dev; 474599a2dd95SBruce Richardson struct rte_intr_handle *intr_handle; 474699a2dd95SBruce Richardson uint16_t qid; 474799a2dd95SBruce Richardson int rc; 474899a2dd95SBruce Richardson 474999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 475099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 475199a2dd95SBruce Richardson 475299a2dd95SBruce Richardson if (!dev->intr_handle) { 475399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n"); 475499a2dd95SBruce Richardson return -ENOTSUP; 475599a2dd95SBruce Richardson } 475699a2dd95SBruce Richardson 475799a2dd95SBruce Richardson intr_handle = dev->intr_handle; 475899a2dd95SBruce Richardson if (!intr_handle->intr_vec) { 475999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n"); 476099a2dd95SBruce Richardson return -EPERM; 476199a2dd95SBruce Richardson } 476299a2dd95SBruce Richardson 476399a2dd95SBruce Richardson for (qid = 0; qid < dev->data->nb_rx_queues; qid++) { 476499a2dd95SBruce Richardson vec = intr_handle->intr_vec[qid]; 476599a2dd95SBruce Richardson rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); 476699a2dd95SBruce Richardson if (rc && rc != -EEXIST) { 476799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 476899a2dd95SBruce Richardson "p %u q %u rx ctl error op %d epfd %d vec %u\n", 476999a2dd95SBruce Richardson port_id, qid, op, epfd, vec); 477099a2dd95SBruce Richardson } 477199a2dd95SBruce Richardson } 477299a2dd95SBruce Richardson 477399a2dd95SBruce Richardson return 0; 477499a2dd95SBruce Richardson } 477599a2dd95SBruce Richardson 477699a2dd95SBruce Richardson int 477799a2dd95SBruce Richardson rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id) 477899a2dd95SBruce Richardson { 477999a2dd95SBruce Richardson struct rte_intr_handle *intr_handle; 478099a2dd95SBruce Richardson struct rte_eth_dev *dev; 478199a2dd95SBruce Richardson unsigned int efd_idx; 478299a2dd95SBruce Richardson uint32_t vec; 478399a2dd95SBruce Richardson int fd; 478499a2dd95SBruce Richardson 478599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); 478699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 478799a2dd95SBruce Richardson 478899a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 478999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 479099a2dd95SBruce Richardson return -1; 479199a2dd95SBruce Richardson } 479299a2dd95SBruce Richardson 479399a2dd95SBruce Richardson if (!dev->intr_handle) { 479499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n"); 479599a2dd95SBruce Richardson return -1; 479699a2dd95SBruce Richardson } 479799a2dd95SBruce Richardson 479899a2dd95SBruce Richardson intr_handle = dev->intr_handle; 479999a2dd95SBruce Richardson if (!intr_handle->intr_vec) { 480099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n"); 480199a2dd95SBruce Richardson return -1; 480299a2dd95SBruce Richardson } 480399a2dd95SBruce Richardson 480499a2dd95SBruce Richardson vec = intr_handle->intr_vec[queue_id]; 480599a2dd95SBruce Richardson efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ? 480699a2dd95SBruce Richardson (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec; 480799a2dd95SBruce Richardson fd = intr_handle->efds[efd_idx]; 480899a2dd95SBruce Richardson 480999a2dd95SBruce Richardson return fd; 481099a2dd95SBruce Richardson } 481199a2dd95SBruce Richardson 481299a2dd95SBruce Richardson static inline int 481399a2dd95SBruce Richardson eth_dev_dma_mzone_name(char *name, size_t len, uint16_t port_id, uint16_t queue_id, 481499a2dd95SBruce Richardson const char *ring_name) 481599a2dd95SBruce Richardson { 481699a2dd95SBruce Richardson return snprintf(name, len, "eth_p%d_q%d_%s", 481799a2dd95SBruce Richardson port_id, queue_id, ring_name); 481899a2dd95SBruce Richardson } 481999a2dd95SBruce Richardson 482099a2dd95SBruce Richardson const struct rte_memzone * 482199a2dd95SBruce Richardson rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name, 482299a2dd95SBruce Richardson uint16_t queue_id, size_t size, unsigned align, 482399a2dd95SBruce Richardson int socket_id) 482499a2dd95SBruce Richardson { 482599a2dd95SBruce Richardson char z_name[RTE_MEMZONE_NAMESIZE]; 482699a2dd95SBruce Richardson const struct rte_memzone *mz; 482799a2dd95SBruce Richardson int rc; 482899a2dd95SBruce Richardson 482999a2dd95SBruce Richardson rc = eth_dev_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id, 483099a2dd95SBruce Richardson queue_id, ring_name); 483199a2dd95SBruce Richardson if (rc >= RTE_MEMZONE_NAMESIZE) { 483299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "ring name too long\n"); 483399a2dd95SBruce Richardson rte_errno = ENAMETOOLONG; 483499a2dd95SBruce Richardson return NULL; 483599a2dd95SBruce Richardson } 483699a2dd95SBruce Richardson 483799a2dd95SBruce Richardson mz = rte_memzone_lookup(z_name); 483899a2dd95SBruce Richardson if (mz) { 483999a2dd95SBruce Richardson if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) || 484099a2dd95SBruce Richardson size > mz->len || 484199a2dd95SBruce Richardson ((uintptr_t)mz->addr & (align - 1)) != 0) { 484299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 484399a2dd95SBruce Richardson "memzone %s does not justify the requested attributes\n", 484499a2dd95SBruce Richardson mz->name); 484599a2dd95SBruce Richardson return NULL; 484699a2dd95SBruce Richardson } 484799a2dd95SBruce Richardson 484899a2dd95SBruce Richardson return mz; 484999a2dd95SBruce Richardson } 485099a2dd95SBruce Richardson 485199a2dd95SBruce Richardson return rte_memzone_reserve_aligned(z_name, size, socket_id, 485299a2dd95SBruce Richardson RTE_MEMZONE_IOVA_CONTIG, align); 485399a2dd95SBruce Richardson } 485499a2dd95SBruce Richardson 485599a2dd95SBruce Richardson int 485699a2dd95SBruce Richardson rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char *ring_name, 485799a2dd95SBruce Richardson uint16_t queue_id) 485899a2dd95SBruce Richardson { 485999a2dd95SBruce Richardson char z_name[RTE_MEMZONE_NAMESIZE]; 486099a2dd95SBruce Richardson const struct rte_memzone *mz; 486199a2dd95SBruce Richardson int rc = 0; 486299a2dd95SBruce Richardson 486399a2dd95SBruce Richardson rc = eth_dev_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id, 486499a2dd95SBruce Richardson queue_id, ring_name); 486599a2dd95SBruce Richardson if (rc >= RTE_MEMZONE_NAMESIZE) { 486699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "ring name too long\n"); 486799a2dd95SBruce Richardson return -ENAMETOOLONG; 486899a2dd95SBruce Richardson } 486999a2dd95SBruce Richardson 487099a2dd95SBruce Richardson mz = rte_memzone_lookup(z_name); 487199a2dd95SBruce Richardson if (mz) 487299a2dd95SBruce Richardson rc = rte_memzone_free(mz); 487399a2dd95SBruce Richardson else 487499a2dd95SBruce Richardson rc = -ENOENT; 487599a2dd95SBruce Richardson 487699a2dd95SBruce Richardson return rc; 487799a2dd95SBruce Richardson } 487899a2dd95SBruce Richardson 487999a2dd95SBruce Richardson int 488099a2dd95SBruce Richardson rte_eth_dev_create(struct rte_device *device, const char *name, 488199a2dd95SBruce Richardson size_t priv_data_size, 488299a2dd95SBruce Richardson ethdev_bus_specific_init ethdev_bus_specific_init, 488399a2dd95SBruce Richardson void *bus_init_params, 488499a2dd95SBruce Richardson ethdev_init_t ethdev_init, void *init_params) 488599a2dd95SBruce Richardson { 488699a2dd95SBruce Richardson struct rte_eth_dev *ethdev; 488799a2dd95SBruce Richardson int retval; 488899a2dd95SBruce Richardson 488999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*ethdev_init, -EINVAL); 489099a2dd95SBruce Richardson 489199a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 489299a2dd95SBruce Richardson ethdev = rte_eth_dev_allocate(name); 489399a2dd95SBruce Richardson if (!ethdev) 489499a2dd95SBruce Richardson return -ENODEV; 489599a2dd95SBruce Richardson 489699a2dd95SBruce Richardson if (priv_data_size) { 489799a2dd95SBruce Richardson ethdev->data->dev_private = rte_zmalloc_socket( 489899a2dd95SBruce Richardson name, priv_data_size, RTE_CACHE_LINE_SIZE, 489999a2dd95SBruce Richardson device->numa_node); 490099a2dd95SBruce Richardson 490199a2dd95SBruce Richardson if (!ethdev->data->dev_private) { 490299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 490399a2dd95SBruce Richardson "failed to allocate private data\n"); 490499a2dd95SBruce Richardson retval = -ENOMEM; 490599a2dd95SBruce Richardson goto probe_failed; 490699a2dd95SBruce Richardson } 490799a2dd95SBruce Richardson } 490899a2dd95SBruce Richardson } else { 490999a2dd95SBruce Richardson ethdev = rte_eth_dev_attach_secondary(name); 491099a2dd95SBruce Richardson if (!ethdev) { 491199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 491299a2dd95SBruce Richardson "secondary process attach failed, ethdev doesn't exist\n"); 491399a2dd95SBruce Richardson return -ENODEV; 491499a2dd95SBruce Richardson } 491599a2dd95SBruce Richardson } 491699a2dd95SBruce Richardson 491799a2dd95SBruce Richardson ethdev->device = device; 491899a2dd95SBruce Richardson 491999a2dd95SBruce Richardson if (ethdev_bus_specific_init) { 492099a2dd95SBruce Richardson retval = ethdev_bus_specific_init(ethdev, bus_init_params); 492199a2dd95SBruce Richardson if (retval) { 492299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 492399a2dd95SBruce Richardson "ethdev bus specific initialisation failed\n"); 492499a2dd95SBruce Richardson goto probe_failed; 492599a2dd95SBruce Richardson } 492699a2dd95SBruce Richardson } 492799a2dd95SBruce Richardson 492899a2dd95SBruce Richardson retval = ethdev_init(ethdev, init_params); 492999a2dd95SBruce Richardson if (retval) { 493099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "ethdev initialisation failed\n"); 493199a2dd95SBruce Richardson goto probe_failed; 493299a2dd95SBruce Richardson } 493399a2dd95SBruce Richardson 493499a2dd95SBruce Richardson rte_eth_dev_probing_finish(ethdev); 493599a2dd95SBruce Richardson 493699a2dd95SBruce Richardson return retval; 493799a2dd95SBruce Richardson 493899a2dd95SBruce Richardson probe_failed: 493999a2dd95SBruce Richardson rte_eth_dev_release_port(ethdev); 494099a2dd95SBruce Richardson return retval; 494199a2dd95SBruce Richardson } 494299a2dd95SBruce Richardson 494399a2dd95SBruce Richardson int 494499a2dd95SBruce Richardson rte_eth_dev_destroy(struct rte_eth_dev *ethdev, 494599a2dd95SBruce Richardson ethdev_uninit_t ethdev_uninit) 494699a2dd95SBruce Richardson { 494799a2dd95SBruce Richardson int ret; 494899a2dd95SBruce Richardson 494999a2dd95SBruce Richardson ethdev = rte_eth_dev_allocated(ethdev->data->name); 495099a2dd95SBruce Richardson if (!ethdev) 495199a2dd95SBruce Richardson return -ENODEV; 495299a2dd95SBruce Richardson 495399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*ethdev_uninit, -EINVAL); 495499a2dd95SBruce Richardson 495599a2dd95SBruce Richardson ret = ethdev_uninit(ethdev); 495699a2dd95SBruce Richardson if (ret) 495799a2dd95SBruce Richardson return ret; 495899a2dd95SBruce Richardson 495999a2dd95SBruce Richardson return rte_eth_dev_release_port(ethdev); 496099a2dd95SBruce Richardson } 496199a2dd95SBruce Richardson 496299a2dd95SBruce Richardson int 496399a2dd95SBruce Richardson rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id, 496499a2dd95SBruce Richardson int epfd, int op, void *data) 496599a2dd95SBruce Richardson { 496699a2dd95SBruce Richardson uint32_t vec; 496799a2dd95SBruce Richardson struct rte_eth_dev *dev; 496899a2dd95SBruce Richardson struct rte_intr_handle *intr_handle; 496999a2dd95SBruce Richardson int rc; 497099a2dd95SBruce Richardson 497199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 497299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 497353ef1b34SMin Hu (Connor) 497499a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 497599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 497699a2dd95SBruce Richardson return -EINVAL; 497799a2dd95SBruce Richardson } 497899a2dd95SBruce Richardson 497999a2dd95SBruce Richardson if (!dev->intr_handle) { 498099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n"); 498199a2dd95SBruce Richardson return -ENOTSUP; 498299a2dd95SBruce Richardson } 498399a2dd95SBruce Richardson 498499a2dd95SBruce Richardson intr_handle = dev->intr_handle; 498599a2dd95SBruce Richardson if (!intr_handle->intr_vec) { 498699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n"); 498799a2dd95SBruce Richardson return -EPERM; 498899a2dd95SBruce Richardson } 498999a2dd95SBruce Richardson 499099a2dd95SBruce Richardson vec = intr_handle->intr_vec[queue_id]; 499199a2dd95SBruce Richardson rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); 499299a2dd95SBruce Richardson if (rc && rc != -EEXIST) { 499399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 499499a2dd95SBruce Richardson "p %u q %u rx ctl error op %d epfd %d vec %u\n", 499599a2dd95SBruce Richardson port_id, queue_id, op, epfd, vec); 499699a2dd95SBruce Richardson return rc; 499799a2dd95SBruce Richardson } 499899a2dd95SBruce Richardson 499999a2dd95SBruce Richardson return 0; 500099a2dd95SBruce Richardson } 500199a2dd95SBruce Richardson 500299a2dd95SBruce Richardson int 500399a2dd95SBruce Richardson rte_eth_dev_rx_intr_enable(uint16_t port_id, 500499a2dd95SBruce Richardson uint16_t queue_id) 500599a2dd95SBruce Richardson { 500699a2dd95SBruce Richardson struct rte_eth_dev *dev; 500799a2dd95SBruce Richardson int ret; 500899a2dd95SBruce Richardson 500999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 501099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 501199a2dd95SBruce Richardson 501299a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, queue_id); 501399a2dd95SBruce Richardson if (ret != 0) 501499a2dd95SBruce Richardson return ret; 501599a2dd95SBruce Richardson 501699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP); 501753ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id)); 501899a2dd95SBruce Richardson } 501999a2dd95SBruce Richardson 502099a2dd95SBruce Richardson int 502199a2dd95SBruce Richardson rte_eth_dev_rx_intr_disable(uint16_t port_id, 502299a2dd95SBruce Richardson uint16_t queue_id) 502399a2dd95SBruce Richardson { 502499a2dd95SBruce Richardson struct rte_eth_dev *dev; 502599a2dd95SBruce Richardson int ret; 502699a2dd95SBruce Richardson 502799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 502899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 502999a2dd95SBruce Richardson 503099a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, queue_id); 503199a2dd95SBruce Richardson if (ret != 0) 503299a2dd95SBruce Richardson return ret; 503399a2dd95SBruce Richardson 503499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP); 503553ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id)); 503699a2dd95SBruce Richardson } 503799a2dd95SBruce Richardson 503899a2dd95SBruce Richardson 503999a2dd95SBruce Richardson const struct rte_eth_rxtx_callback * 504099a2dd95SBruce Richardson rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id, 504199a2dd95SBruce Richardson rte_rx_callback_fn fn, void *user_param) 504299a2dd95SBruce Richardson { 504399a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 504499a2dd95SBruce Richardson rte_errno = ENOTSUP; 504599a2dd95SBruce Richardson return NULL; 504699a2dd95SBruce Richardson #endif 504799a2dd95SBruce Richardson struct rte_eth_dev *dev; 504899a2dd95SBruce Richardson 504999a2dd95SBruce Richardson /* check input parameters */ 505099a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || 505199a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) { 505299a2dd95SBruce Richardson rte_errno = EINVAL; 505399a2dd95SBruce Richardson return NULL; 505499a2dd95SBruce Richardson } 505599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 505699a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) { 505799a2dd95SBruce Richardson rte_errno = EINVAL; 505899a2dd95SBruce Richardson return NULL; 505999a2dd95SBruce Richardson } 506099a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); 506199a2dd95SBruce Richardson 506299a2dd95SBruce Richardson if (cb == NULL) { 506399a2dd95SBruce Richardson rte_errno = ENOMEM; 506499a2dd95SBruce Richardson return NULL; 506599a2dd95SBruce Richardson } 506699a2dd95SBruce Richardson 506799a2dd95SBruce Richardson cb->fn.rx = fn; 506899a2dd95SBruce Richardson cb->param = user_param; 506999a2dd95SBruce Richardson 507099a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_rx_cb_lock); 507199a2dd95SBruce Richardson /* Add the callbacks in fifo order. */ 507299a2dd95SBruce Richardson struct rte_eth_rxtx_callback *tail = 507399a2dd95SBruce Richardson rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; 507499a2dd95SBruce Richardson 507599a2dd95SBruce Richardson if (!tail) { 507699a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 507799a2dd95SBruce Richardson * cb is visible to data plane. 507899a2dd95SBruce Richardson */ 507999a2dd95SBruce Richardson __atomic_store_n( 508099a2dd95SBruce Richardson &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], 508199a2dd95SBruce Richardson cb, __ATOMIC_RELEASE); 508299a2dd95SBruce Richardson 508399a2dd95SBruce Richardson } else { 508499a2dd95SBruce Richardson while (tail->next) 508599a2dd95SBruce Richardson tail = tail->next; 508699a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 508799a2dd95SBruce Richardson * cb is visible to data plane. 508899a2dd95SBruce Richardson */ 508999a2dd95SBruce Richardson __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE); 509099a2dd95SBruce Richardson } 509199a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_rx_cb_lock); 509299a2dd95SBruce Richardson 509399a2dd95SBruce Richardson return cb; 509499a2dd95SBruce Richardson } 509599a2dd95SBruce Richardson 509699a2dd95SBruce Richardson const struct rte_eth_rxtx_callback * 509799a2dd95SBruce Richardson rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id, 509899a2dd95SBruce Richardson rte_rx_callback_fn fn, void *user_param) 509999a2dd95SBruce Richardson { 510099a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 510199a2dd95SBruce Richardson rte_errno = ENOTSUP; 510299a2dd95SBruce Richardson return NULL; 510399a2dd95SBruce Richardson #endif 510499a2dd95SBruce Richardson /* check input parameters */ 510599a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || 510699a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) { 510799a2dd95SBruce Richardson rte_errno = EINVAL; 510899a2dd95SBruce Richardson return NULL; 510999a2dd95SBruce Richardson } 511099a2dd95SBruce Richardson 511199a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); 511299a2dd95SBruce Richardson 511399a2dd95SBruce Richardson if (cb == NULL) { 511499a2dd95SBruce Richardson rte_errno = ENOMEM; 511599a2dd95SBruce Richardson return NULL; 511699a2dd95SBruce Richardson } 511799a2dd95SBruce Richardson 511899a2dd95SBruce Richardson cb->fn.rx = fn; 511999a2dd95SBruce Richardson cb->param = user_param; 512099a2dd95SBruce Richardson 512199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_rx_cb_lock); 512299a2dd95SBruce Richardson /* Add the callbacks at first position */ 512399a2dd95SBruce Richardson cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; 512499a2dd95SBruce Richardson /* Stores to cb->fn, cb->param and cb->next should complete before 512599a2dd95SBruce Richardson * cb is visible to data plane threads. 512699a2dd95SBruce Richardson */ 512799a2dd95SBruce Richardson __atomic_store_n( 512899a2dd95SBruce Richardson &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], 512999a2dd95SBruce Richardson cb, __ATOMIC_RELEASE); 513099a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_rx_cb_lock); 513199a2dd95SBruce Richardson 513299a2dd95SBruce Richardson return cb; 513399a2dd95SBruce Richardson } 513499a2dd95SBruce Richardson 513599a2dd95SBruce Richardson const struct rte_eth_rxtx_callback * 513699a2dd95SBruce Richardson rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id, 513799a2dd95SBruce Richardson rte_tx_callback_fn fn, void *user_param) 513899a2dd95SBruce Richardson { 513999a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 514099a2dd95SBruce Richardson rte_errno = ENOTSUP; 514199a2dd95SBruce Richardson return NULL; 514299a2dd95SBruce Richardson #endif 514399a2dd95SBruce Richardson struct rte_eth_dev *dev; 514499a2dd95SBruce Richardson 514599a2dd95SBruce Richardson /* check input parameters */ 514699a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || 514799a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) { 514899a2dd95SBruce Richardson rte_errno = EINVAL; 514999a2dd95SBruce Richardson return NULL; 515099a2dd95SBruce Richardson } 515199a2dd95SBruce Richardson 515299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 515399a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) { 515499a2dd95SBruce Richardson rte_errno = EINVAL; 515599a2dd95SBruce Richardson return NULL; 515699a2dd95SBruce Richardson } 515799a2dd95SBruce Richardson 515899a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); 515999a2dd95SBruce Richardson 516099a2dd95SBruce Richardson if (cb == NULL) { 516199a2dd95SBruce Richardson rte_errno = ENOMEM; 516299a2dd95SBruce Richardson return NULL; 516399a2dd95SBruce Richardson } 516499a2dd95SBruce Richardson 516599a2dd95SBruce Richardson cb->fn.tx = fn; 516699a2dd95SBruce Richardson cb->param = user_param; 516799a2dd95SBruce Richardson 516899a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_tx_cb_lock); 516999a2dd95SBruce Richardson /* Add the callbacks in fifo order. */ 517099a2dd95SBruce Richardson struct rte_eth_rxtx_callback *tail = 517199a2dd95SBruce Richardson rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id]; 517299a2dd95SBruce Richardson 517399a2dd95SBruce Richardson if (!tail) { 517499a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 517599a2dd95SBruce Richardson * cb is visible to data plane. 517699a2dd95SBruce Richardson */ 517799a2dd95SBruce Richardson __atomic_store_n( 517899a2dd95SBruce Richardson &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id], 517999a2dd95SBruce Richardson cb, __ATOMIC_RELEASE); 518099a2dd95SBruce Richardson 518199a2dd95SBruce Richardson } else { 518299a2dd95SBruce Richardson while (tail->next) 518399a2dd95SBruce Richardson tail = tail->next; 518499a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 518599a2dd95SBruce Richardson * cb is visible to data plane. 518699a2dd95SBruce Richardson */ 518799a2dd95SBruce Richardson __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE); 518899a2dd95SBruce Richardson } 518999a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_tx_cb_lock); 519099a2dd95SBruce Richardson 519199a2dd95SBruce Richardson return cb; 519299a2dd95SBruce Richardson } 519399a2dd95SBruce Richardson 519499a2dd95SBruce Richardson int 519599a2dd95SBruce Richardson rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id, 519699a2dd95SBruce Richardson const struct rte_eth_rxtx_callback *user_cb) 519799a2dd95SBruce Richardson { 519899a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 519999a2dd95SBruce Richardson return -ENOTSUP; 520099a2dd95SBruce Richardson #endif 520199a2dd95SBruce Richardson /* Check input parameters. */ 520299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 520399a2dd95SBruce Richardson if (user_cb == NULL || 520499a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) 520599a2dd95SBruce Richardson return -EINVAL; 520699a2dd95SBruce Richardson 520799a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 520899a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb; 520999a2dd95SBruce Richardson struct rte_eth_rxtx_callback **prev_cb; 521099a2dd95SBruce Richardson int ret = -EINVAL; 521199a2dd95SBruce Richardson 521299a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_rx_cb_lock); 521399a2dd95SBruce Richardson prev_cb = &dev->post_rx_burst_cbs[queue_id]; 521499a2dd95SBruce Richardson for (; *prev_cb != NULL; prev_cb = &cb->next) { 521599a2dd95SBruce Richardson cb = *prev_cb; 521699a2dd95SBruce Richardson if (cb == user_cb) { 521799a2dd95SBruce Richardson /* Remove the user cb from the callback list. */ 521899a2dd95SBruce Richardson __atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED); 521999a2dd95SBruce Richardson ret = 0; 522099a2dd95SBruce Richardson break; 522199a2dd95SBruce Richardson } 522299a2dd95SBruce Richardson } 522399a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_rx_cb_lock); 522499a2dd95SBruce Richardson 522599a2dd95SBruce Richardson return ret; 522699a2dd95SBruce Richardson } 522799a2dd95SBruce Richardson 522899a2dd95SBruce Richardson int 522999a2dd95SBruce Richardson rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id, 523099a2dd95SBruce Richardson const struct rte_eth_rxtx_callback *user_cb) 523199a2dd95SBruce Richardson { 523299a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 523399a2dd95SBruce Richardson return -ENOTSUP; 523499a2dd95SBruce Richardson #endif 523599a2dd95SBruce Richardson /* Check input parameters. */ 523699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 523799a2dd95SBruce Richardson if (user_cb == NULL || 523899a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) 523999a2dd95SBruce Richardson return -EINVAL; 524099a2dd95SBruce Richardson 524199a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 524299a2dd95SBruce Richardson int ret = -EINVAL; 524399a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb; 524499a2dd95SBruce Richardson struct rte_eth_rxtx_callback **prev_cb; 524599a2dd95SBruce Richardson 524699a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_tx_cb_lock); 524799a2dd95SBruce Richardson prev_cb = &dev->pre_tx_burst_cbs[queue_id]; 524899a2dd95SBruce Richardson for (; *prev_cb != NULL; prev_cb = &cb->next) { 524999a2dd95SBruce Richardson cb = *prev_cb; 525099a2dd95SBruce Richardson if (cb == user_cb) { 525199a2dd95SBruce Richardson /* Remove the user cb from the callback list. */ 525299a2dd95SBruce Richardson __atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED); 525399a2dd95SBruce Richardson ret = 0; 525499a2dd95SBruce Richardson break; 525599a2dd95SBruce Richardson } 525699a2dd95SBruce Richardson } 525799a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_tx_cb_lock); 525899a2dd95SBruce Richardson 525999a2dd95SBruce Richardson return ret; 526099a2dd95SBruce Richardson } 526199a2dd95SBruce Richardson 526299a2dd95SBruce Richardson int 526399a2dd95SBruce Richardson rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id, 526499a2dd95SBruce Richardson struct rte_eth_rxq_info *qinfo) 526599a2dd95SBruce Richardson { 526699a2dd95SBruce Richardson struct rte_eth_dev *dev; 526799a2dd95SBruce Richardson 526899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 526999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 527053ef1b34SMin Hu (Connor) 527199a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 527299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 527399a2dd95SBruce Richardson return -EINVAL; 527499a2dd95SBruce Richardson } 527599a2dd95SBruce Richardson 527653ef1b34SMin Hu (Connor) if (qinfo == NULL) { 527753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL\n", 527853ef1b34SMin Hu (Connor) port_id, queue_id); 527953ef1b34SMin Hu (Connor) return -EINVAL; 528053ef1b34SMin Hu (Connor) } 528153ef1b34SMin Hu (Connor) 528299a2dd95SBruce Richardson if (dev->data->rx_queues == NULL || 528399a2dd95SBruce Richardson dev->data->rx_queues[queue_id] == NULL) { 528499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 528599a2dd95SBruce Richardson "Rx queue %"PRIu16" of device with port_id=%" 528699a2dd95SBruce Richardson PRIu16" has not been setup\n", 528799a2dd95SBruce Richardson queue_id, port_id); 528899a2dd95SBruce Richardson return -EINVAL; 528999a2dd95SBruce Richardson } 529099a2dd95SBruce Richardson 529199a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) { 529299a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 529399a2dd95SBruce Richardson "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16"\n", 529499a2dd95SBruce Richardson queue_id, port_id); 529599a2dd95SBruce Richardson return -EINVAL; 529699a2dd95SBruce Richardson } 529799a2dd95SBruce Richardson 529899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP); 529999a2dd95SBruce Richardson 530099a2dd95SBruce Richardson memset(qinfo, 0, sizeof(*qinfo)); 530199a2dd95SBruce Richardson dev->dev_ops->rxq_info_get(dev, queue_id, qinfo); 53029ad9ff47SLijun Ou qinfo->queue_state = dev->data->rx_queue_state[queue_id]; 53039ad9ff47SLijun Ou 530499a2dd95SBruce Richardson return 0; 530599a2dd95SBruce Richardson } 530699a2dd95SBruce Richardson 530799a2dd95SBruce Richardson int 530899a2dd95SBruce Richardson rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id, 530999a2dd95SBruce Richardson struct rte_eth_txq_info *qinfo) 531099a2dd95SBruce Richardson { 531199a2dd95SBruce Richardson struct rte_eth_dev *dev; 531299a2dd95SBruce Richardson 531399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 531499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 531553ef1b34SMin Hu (Connor) 531699a2dd95SBruce Richardson if (queue_id >= dev->data->nb_tx_queues) { 531799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id); 531899a2dd95SBruce Richardson return -EINVAL; 531999a2dd95SBruce Richardson } 532099a2dd95SBruce Richardson 532153ef1b34SMin Hu (Connor) if (qinfo == NULL) { 532253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL\n", 532353ef1b34SMin Hu (Connor) port_id, queue_id); 532453ef1b34SMin Hu (Connor) return -EINVAL; 532553ef1b34SMin Hu (Connor) } 532653ef1b34SMin Hu (Connor) 532799a2dd95SBruce Richardson if (dev->data->tx_queues == NULL || 532899a2dd95SBruce Richardson dev->data->tx_queues[queue_id] == NULL) { 532999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 533099a2dd95SBruce Richardson "Tx queue %"PRIu16" of device with port_id=%" 533199a2dd95SBruce Richardson PRIu16" has not been setup\n", 533299a2dd95SBruce Richardson queue_id, port_id); 533399a2dd95SBruce Richardson return -EINVAL; 533499a2dd95SBruce Richardson } 533599a2dd95SBruce Richardson 533699a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) { 533799a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 533899a2dd95SBruce Richardson "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16"\n", 533999a2dd95SBruce Richardson queue_id, port_id); 534099a2dd95SBruce Richardson return -EINVAL; 534199a2dd95SBruce Richardson } 534299a2dd95SBruce Richardson 534399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP); 534499a2dd95SBruce Richardson 534599a2dd95SBruce Richardson memset(qinfo, 0, sizeof(*qinfo)); 534699a2dd95SBruce Richardson dev->dev_ops->txq_info_get(dev, queue_id, qinfo); 53479ad9ff47SLijun Ou qinfo->queue_state = dev->data->tx_queue_state[queue_id]; 534899a2dd95SBruce Richardson 534999a2dd95SBruce Richardson return 0; 535099a2dd95SBruce Richardson } 535199a2dd95SBruce Richardson 535299a2dd95SBruce Richardson int 535399a2dd95SBruce Richardson rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id, 535499a2dd95SBruce Richardson struct rte_eth_burst_mode *mode) 535599a2dd95SBruce Richardson { 535699a2dd95SBruce Richardson struct rte_eth_dev *dev; 535799a2dd95SBruce Richardson 535899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 535999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 536099a2dd95SBruce Richardson 536199a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 536299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 536399a2dd95SBruce Richardson return -EINVAL; 536499a2dd95SBruce Richardson } 536599a2dd95SBruce Richardson 536653ef1b34SMin Hu (Connor) if (mode == NULL) { 536753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 536853ef1b34SMin Hu (Connor) "Cannot get ethdev port %u Rx queue %u burst mode to NULL\n", 536953ef1b34SMin Hu (Connor) port_id, queue_id); 537053ef1b34SMin Hu (Connor) return -EINVAL; 537153ef1b34SMin Hu (Connor) } 537253ef1b34SMin Hu (Connor) 537399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_burst_mode_get, -ENOTSUP); 537499a2dd95SBruce Richardson memset(mode, 0, sizeof(*mode)); 537599a2dd95SBruce Richardson return eth_err(port_id, 537699a2dd95SBruce Richardson dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode)); 537799a2dd95SBruce Richardson } 537899a2dd95SBruce Richardson 537999a2dd95SBruce Richardson int 538099a2dd95SBruce Richardson rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id, 538199a2dd95SBruce Richardson struct rte_eth_burst_mode *mode) 538299a2dd95SBruce Richardson { 538399a2dd95SBruce Richardson struct rte_eth_dev *dev; 538499a2dd95SBruce Richardson 538599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 538699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 538799a2dd95SBruce Richardson 538899a2dd95SBruce Richardson if (queue_id >= dev->data->nb_tx_queues) { 538999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id); 539099a2dd95SBruce Richardson return -EINVAL; 539199a2dd95SBruce Richardson } 539299a2dd95SBruce Richardson 539353ef1b34SMin Hu (Connor) if (mode == NULL) { 539453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 539553ef1b34SMin Hu (Connor) "Cannot get ethdev port %u Tx queue %u burst mode to NULL\n", 539653ef1b34SMin Hu (Connor) port_id, queue_id); 539753ef1b34SMin Hu (Connor) return -EINVAL; 539853ef1b34SMin Hu (Connor) } 539953ef1b34SMin Hu (Connor) 540099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_burst_mode_get, -ENOTSUP); 540199a2dd95SBruce Richardson memset(mode, 0, sizeof(*mode)); 540299a2dd95SBruce Richardson return eth_err(port_id, 540399a2dd95SBruce Richardson dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode)); 540499a2dd95SBruce Richardson } 540599a2dd95SBruce Richardson 540699a2dd95SBruce Richardson int 540799a2dd95SBruce Richardson rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id, 540899a2dd95SBruce Richardson struct rte_power_monitor_cond *pmc) 540999a2dd95SBruce Richardson { 541099a2dd95SBruce Richardson struct rte_eth_dev *dev; 541199a2dd95SBruce Richardson 541299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 541399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 541499a2dd95SBruce Richardson 541599a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 541699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id); 541799a2dd95SBruce Richardson return -EINVAL; 541899a2dd95SBruce Richardson } 541999a2dd95SBruce Richardson 542099a2dd95SBruce Richardson if (pmc == NULL) { 542153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 542253ef1b34SMin Hu (Connor) "Cannot get ethdev port %u Rx queue %u power monitor condition to NULL\n", 542353ef1b34SMin Hu (Connor) port_id, queue_id); 542499a2dd95SBruce Richardson return -EINVAL; 542599a2dd95SBruce Richardson } 542699a2dd95SBruce Richardson 542753ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_monitor_addr, -ENOTSUP); 542899a2dd95SBruce Richardson return eth_err(port_id, 542953ef1b34SMin Hu (Connor) dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc)); 543099a2dd95SBruce Richardson } 543199a2dd95SBruce Richardson 543299a2dd95SBruce Richardson int 543399a2dd95SBruce Richardson rte_eth_dev_set_mc_addr_list(uint16_t port_id, 543499a2dd95SBruce Richardson struct rte_ether_addr *mc_addr_set, 543599a2dd95SBruce Richardson uint32_t nb_mc_addr) 543699a2dd95SBruce Richardson { 543799a2dd95SBruce Richardson struct rte_eth_dev *dev; 543899a2dd95SBruce Richardson 543999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 544099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 544153ef1b34SMin Hu (Connor) 544299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP); 544399a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev, 544499a2dd95SBruce Richardson mc_addr_set, nb_mc_addr)); 544599a2dd95SBruce Richardson } 544699a2dd95SBruce Richardson 544799a2dd95SBruce Richardson int 544899a2dd95SBruce Richardson rte_eth_timesync_enable(uint16_t port_id) 544999a2dd95SBruce Richardson { 545099a2dd95SBruce Richardson struct rte_eth_dev *dev; 545199a2dd95SBruce Richardson 545299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 545399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 545499a2dd95SBruce Richardson 545599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP); 545699a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev)); 545799a2dd95SBruce Richardson } 545899a2dd95SBruce Richardson 545999a2dd95SBruce Richardson int 546099a2dd95SBruce Richardson rte_eth_timesync_disable(uint16_t port_id) 546199a2dd95SBruce Richardson { 546299a2dd95SBruce Richardson struct rte_eth_dev *dev; 546399a2dd95SBruce Richardson 546499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 546599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 546699a2dd95SBruce Richardson 546799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP); 546899a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev)); 546999a2dd95SBruce Richardson } 547099a2dd95SBruce Richardson 547199a2dd95SBruce Richardson int 547299a2dd95SBruce Richardson rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp, 547399a2dd95SBruce Richardson uint32_t flags) 547499a2dd95SBruce Richardson { 547599a2dd95SBruce Richardson struct rte_eth_dev *dev; 547699a2dd95SBruce Richardson 547799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 547899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 547999a2dd95SBruce Richardson 548053ef1b34SMin Hu (Connor) if (timestamp == NULL) { 548153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 548253ef1b34SMin Hu (Connor) "Cannot read ethdev port %u Rx timestamp to NULL\n", 548353ef1b34SMin Hu (Connor) port_id); 548453ef1b34SMin Hu (Connor) return -EINVAL; 548553ef1b34SMin Hu (Connor) } 548653ef1b34SMin Hu (Connor) 548799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP); 548899a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp) 548999a2dd95SBruce Richardson (dev, timestamp, flags)); 549099a2dd95SBruce Richardson } 549199a2dd95SBruce Richardson 549299a2dd95SBruce Richardson int 549399a2dd95SBruce Richardson rte_eth_timesync_read_tx_timestamp(uint16_t port_id, 549499a2dd95SBruce Richardson struct timespec *timestamp) 549599a2dd95SBruce Richardson { 549699a2dd95SBruce Richardson struct rte_eth_dev *dev; 549799a2dd95SBruce Richardson 549899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 549999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 550099a2dd95SBruce Richardson 550153ef1b34SMin Hu (Connor) if (timestamp == NULL) { 550253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 550353ef1b34SMin Hu (Connor) "Cannot read ethdev port %u Tx timestamp to NULL\n", 550453ef1b34SMin Hu (Connor) port_id); 550553ef1b34SMin Hu (Connor) return -EINVAL; 550653ef1b34SMin Hu (Connor) } 550753ef1b34SMin Hu (Connor) 550899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP); 550999a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp) 551099a2dd95SBruce Richardson (dev, timestamp)); 551199a2dd95SBruce Richardson } 551299a2dd95SBruce Richardson 551399a2dd95SBruce Richardson int 551499a2dd95SBruce Richardson rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta) 551599a2dd95SBruce Richardson { 551699a2dd95SBruce Richardson struct rte_eth_dev *dev; 551799a2dd95SBruce Richardson 551899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 551999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 552099a2dd95SBruce Richardson 552199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP); 552253ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev, delta)); 552399a2dd95SBruce Richardson } 552499a2dd95SBruce Richardson 552599a2dd95SBruce Richardson int 552699a2dd95SBruce Richardson rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp) 552799a2dd95SBruce Richardson { 552899a2dd95SBruce Richardson struct rte_eth_dev *dev; 552999a2dd95SBruce Richardson 553099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 553199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 553299a2dd95SBruce Richardson 553353ef1b34SMin Hu (Connor) if (timestamp == NULL) { 553453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 553553ef1b34SMin Hu (Connor) "Cannot read ethdev port %u timesync time to NULL\n", 553653ef1b34SMin Hu (Connor) port_id); 553753ef1b34SMin Hu (Connor) return -EINVAL; 553853ef1b34SMin Hu (Connor) } 553953ef1b34SMin Hu (Connor) 554099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP); 554199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev, 554299a2dd95SBruce Richardson timestamp)); 554399a2dd95SBruce Richardson } 554499a2dd95SBruce Richardson 554599a2dd95SBruce Richardson int 554699a2dd95SBruce Richardson rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp) 554799a2dd95SBruce Richardson { 554899a2dd95SBruce Richardson struct rte_eth_dev *dev; 554999a2dd95SBruce Richardson 555099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 555199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 555299a2dd95SBruce Richardson 555353ef1b34SMin Hu (Connor) if (timestamp == NULL) { 555453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 555553ef1b34SMin Hu (Connor) "Cannot write ethdev port %u timesync from NULL time\n", 555653ef1b34SMin Hu (Connor) port_id); 555753ef1b34SMin Hu (Connor) return -EINVAL; 555853ef1b34SMin Hu (Connor) } 555953ef1b34SMin Hu (Connor) 556099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP); 556199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev, 556299a2dd95SBruce Richardson timestamp)); 556399a2dd95SBruce Richardson } 556499a2dd95SBruce Richardson 556599a2dd95SBruce Richardson int 556699a2dd95SBruce Richardson rte_eth_read_clock(uint16_t port_id, uint64_t *clock) 556799a2dd95SBruce Richardson { 556899a2dd95SBruce Richardson struct rte_eth_dev *dev; 556999a2dd95SBruce Richardson 557099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 557199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 557299a2dd95SBruce Richardson 557353ef1b34SMin Hu (Connor) if (clock == NULL) { 557453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot read ethdev port %u clock to NULL\n", 557553ef1b34SMin Hu (Connor) port_id); 557653ef1b34SMin Hu (Connor) return -EINVAL; 557753ef1b34SMin Hu (Connor) } 557853ef1b34SMin Hu (Connor) 557999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, -ENOTSUP); 558099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, clock)); 558199a2dd95SBruce Richardson } 558299a2dd95SBruce Richardson 558399a2dd95SBruce Richardson int 558499a2dd95SBruce Richardson rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info) 558599a2dd95SBruce Richardson { 558699a2dd95SBruce Richardson struct rte_eth_dev *dev; 558799a2dd95SBruce Richardson 558899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 558999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 559053ef1b34SMin Hu (Connor) 559153ef1b34SMin Hu (Connor) if (info == NULL) { 559253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 559353ef1b34SMin Hu (Connor) "Cannot get ethdev port %u register info to NULL\n", 559453ef1b34SMin Hu (Connor) port_id); 559553ef1b34SMin Hu (Connor) return -EINVAL; 559653ef1b34SMin Hu (Connor) } 559753ef1b34SMin Hu (Connor) 559899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP); 559999a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info)); 560099a2dd95SBruce Richardson } 560199a2dd95SBruce Richardson 560299a2dd95SBruce Richardson int 560399a2dd95SBruce Richardson rte_eth_dev_get_eeprom_length(uint16_t port_id) 560499a2dd95SBruce Richardson { 560599a2dd95SBruce Richardson struct rte_eth_dev *dev; 560699a2dd95SBruce Richardson 560799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 560899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 560953ef1b34SMin Hu (Connor) 561099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP); 561199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev)); 561299a2dd95SBruce Richardson } 561399a2dd95SBruce Richardson 561499a2dd95SBruce Richardson int 561599a2dd95SBruce Richardson rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info) 561699a2dd95SBruce Richardson { 561799a2dd95SBruce Richardson struct rte_eth_dev *dev; 561899a2dd95SBruce Richardson 561999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 562099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 562153ef1b34SMin Hu (Connor) 562253ef1b34SMin Hu (Connor) if (info == NULL) { 562353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 562453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u EEPROM info to NULL\n", 562553ef1b34SMin Hu (Connor) port_id); 562653ef1b34SMin Hu (Connor) return -EINVAL; 562753ef1b34SMin Hu (Connor) } 562853ef1b34SMin Hu (Connor) 562999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP); 563099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info)); 563199a2dd95SBruce Richardson } 563299a2dd95SBruce Richardson 563399a2dd95SBruce Richardson int 563499a2dd95SBruce Richardson rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info) 563599a2dd95SBruce Richardson { 563699a2dd95SBruce Richardson struct rte_eth_dev *dev; 563799a2dd95SBruce Richardson 563899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 563999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 564053ef1b34SMin Hu (Connor) 564153ef1b34SMin Hu (Connor) if (info == NULL) { 564253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 564353ef1b34SMin Hu (Connor) "Cannot set ethdev port %u EEPROM from NULL info\n", 564453ef1b34SMin Hu (Connor) port_id); 564553ef1b34SMin Hu (Connor) return -EINVAL; 564653ef1b34SMin Hu (Connor) } 564753ef1b34SMin Hu (Connor) 564899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP); 564999a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info)); 565099a2dd95SBruce Richardson } 565199a2dd95SBruce Richardson 565299a2dd95SBruce Richardson int 565399a2dd95SBruce Richardson rte_eth_dev_get_module_info(uint16_t port_id, 565499a2dd95SBruce Richardson struct rte_eth_dev_module_info *modinfo) 565599a2dd95SBruce Richardson { 565699a2dd95SBruce Richardson struct rte_eth_dev *dev; 565799a2dd95SBruce Richardson 565899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 565999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 566053ef1b34SMin Hu (Connor) 566153ef1b34SMin Hu (Connor) if (modinfo == NULL) { 566253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 566353ef1b34SMin Hu (Connor) "Cannot get ethdev port %u EEPROM module info to NULL\n", 566453ef1b34SMin Hu (Connor) port_id); 566553ef1b34SMin Hu (Connor) return -EINVAL; 566653ef1b34SMin Hu (Connor) } 566753ef1b34SMin Hu (Connor) 566899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP); 566999a2dd95SBruce Richardson return (*dev->dev_ops->get_module_info)(dev, modinfo); 567099a2dd95SBruce Richardson } 567199a2dd95SBruce Richardson 567299a2dd95SBruce Richardson int 567399a2dd95SBruce Richardson rte_eth_dev_get_module_eeprom(uint16_t port_id, 567499a2dd95SBruce Richardson struct rte_dev_eeprom_info *info) 567599a2dd95SBruce Richardson { 567699a2dd95SBruce Richardson struct rte_eth_dev *dev; 567799a2dd95SBruce Richardson 567899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 567999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 568053ef1b34SMin Hu (Connor) 568153ef1b34SMin Hu (Connor) if (info == NULL) { 568253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 568353ef1b34SMin Hu (Connor) "Cannot get ethdev port %u module EEPROM info to NULL\n", 568453ef1b34SMin Hu (Connor) port_id); 568553ef1b34SMin Hu (Connor) return -EINVAL; 568653ef1b34SMin Hu (Connor) } 568753ef1b34SMin Hu (Connor) 568853ef1b34SMin Hu (Connor) if (info->data == NULL) { 568953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 569053ef1b34SMin Hu (Connor) "Cannot get ethdev port %u module EEPROM data to NULL\n", 569153ef1b34SMin Hu (Connor) port_id); 569253ef1b34SMin Hu (Connor) return -EINVAL; 569353ef1b34SMin Hu (Connor) } 569453ef1b34SMin Hu (Connor) 569553ef1b34SMin Hu (Connor) if (info->length == 0) { 569653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 569753ef1b34SMin Hu (Connor) "Cannot get ethdev port %u module EEPROM to data with zero size\n", 569853ef1b34SMin Hu (Connor) port_id); 569953ef1b34SMin Hu (Connor) return -EINVAL; 570053ef1b34SMin Hu (Connor) } 570153ef1b34SMin Hu (Connor) 570299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP); 570399a2dd95SBruce Richardson return (*dev->dev_ops->get_module_eeprom)(dev, info); 570499a2dd95SBruce Richardson } 570599a2dd95SBruce Richardson 570699a2dd95SBruce Richardson int 570799a2dd95SBruce Richardson rte_eth_dev_get_dcb_info(uint16_t port_id, 570899a2dd95SBruce Richardson struct rte_eth_dcb_info *dcb_info) 570999a2dd95SBruce Richardson { 571099a2dd95SBruce Richardson struct rte_eth_dev *dev; 571199a2dd95SBruce Richardson 571299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 571399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 571453ef1b34SMin Hu (Connor) 571553ef1b34SMin Hu (Connor) if (dcb_info == NULL) { 571653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 571753ef1b34SMin Hu (Connor) "Cannot get ethdev port %u DCB info to NULL\n", 571853ef1b34SMin Hu (Connor) port_id); 571953ef1b34SMin Hu (Connor) return -EINVAL; 572053ef1b34SMin Hu (Connor) } 572153ef1b34SMin Hu (Connor) 572299a2dd95SBruce Richardson memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info)); 572399a2dd95SBruce Richardson 572499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP); 572599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info)); 572699a2dd95SBruce Richardson } 572799a2dd95SBruce Richardson 572899a2dd95SBruce Richardson static void 572999a2dd95SBruce Richardson eth_dev_adjust_nb_desc(uint16_t *nb_desc, 573099a2dd95SBruce Richardson const struct rte_eth_desc_lim *desc_lim) 573199a2dd95SBruce Richardson { 573299a2dd95SBruce Richardson if (desc_lim->nb_align != 0) 573399a2dd95SBruce Richardson *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align); 573499a2dd95SBruce Richardson 573599a2dd95SBruce Richardson if (desc_lim->nb_max != 0) 573699a2dd95SBruce Richardson *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max); 573799a2dd95SBruce Richardson 573899a2dd95SBruce Richardson *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min); 573999a2dd95SBruce Richardson } 574099a2dd95SBruce Richardson 574199a2dd95SBruce Richardson int 574299a2dd95SBruce Richardson rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id, 574399a2dd95SBruce Richardson uint16_t *nb_rx_desc, 574499a2dd95SBruce Richardson uint16_t *nb_tx_desc) 574599a2dd95SBruce Richardson { 574699a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 574799a2dd95SBruce Richardson int ret; 574899a2dd95SBruce Richardson 574999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 575099a2dd95SBruce Richardson 575199a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 575299a2dd95SBruce Richardson if (ret != 0) 575399a2dd95SBruce Richardson return ret; 575499a2dd95SBruce Richardson 575599a2dd95SBruce Richardson if (nb_rx_desc != NULL) 575699a2dd95SBruce Richardson eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim); 575799a2dd95SBruce Richardson 575899a2dd95SBruce Richardson if (nb_tx_desc != NULL) 575999a2dd95SBruce Richardson eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim); 576099a2dd95SBruce Richardson 576199a2dd95SBruce Richardson return 0; 576299a2dd95SBruce Richardson } 576399a2dd95SBruce Richardson 576499a2dd95SBruce Richardson int 576599a2dd95SBruce Richardson rte_eth_dev_hairpin_capability_get(uint16_t port_id, 576699a2dd95SBruce Richardson struct rte_eth_hairpin_cap *cap) 576799a2dd95SBruce Richardson { 576899a2dd95SBruce Richardson struct rte_eth_dev *dev; 576999a2dd95SBruce Richardson 577099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 577199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 577253ef1b34SMin Hu (Connor) 577353ef1b34SMin Hu (Connor) if (cap == NULL) { 577453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 577553ef1b34SMin Hu (Connor) "Cannot get ethdev port %u hairpin capability to NULL\n", 577653ef1b34SMin Hu (Connor) port_id); 577753ef1b34SMin Hu (Connor) return -EINVAL; 577853ef1b34SMin Hu (Connor) } 577953ef1b34SMin Hu (Connor) 578099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_cap_get, -ENOTSUP); 578199a2dd95SBruce Richardson memset(cap, 0, sizeof(*cap)); 578299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->hairpin_cap_get)(dev, cap)); 578399a2dd95SBruce Richardson } 578499a2dd95SBruce Richardson 578599a2dd95SBruce Richardson int 578699a2dd95SBruce Richardson rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id) 578799a2dd95SBruce Richardson { 578853ef1b34SMin Hu (Connor) if (dev->data->rx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN) 578999a2dd95SBruce Richardson return 1; 579099a2dd95SBruce Richardson return 0; 579199a2dd95SBruce Richardson } 579299a2dd95SBruce Richardson 579399a2dd95SBruce Richardson int 579499a2dd95SBruce Richardson rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id) 579599a2dd95SBruce Richardson { 579653ef1b34SMin Hu (Connor) if (dev->data->tx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN) 579799a2dd95SBruce Richardson return 1; 579899a2dd95SBruce Richardson return 0; 579999a2dd95SBruce Richardson } 580099a2dd95SBruce Richardson 580199a2dd95SBruce Richardson int 580299a2dd95SBruce Richardson rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool) 580399a2dd95SBruce Richardson { 580499a2dd95SBruce Richardson struct rte_eth_dev *dev; 580599a2dd95SBruce Richardson 580699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 580799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 580899a2dd95SBruce Richardson 580953ef1b34SMin Hu (Connor) if (pool == NULL) { 581053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 581153ef1b34SMin Hu (Connor) "Cannot test ethdev port %u mempool operation from NULL pool\n", 581253ef1b34SMin Hu (Connor) port_id); 581353ef1b34SMin Hu (Connor) return -EINVAL; 581453ef1b34SMin Hu (Connor) } 581553ef1b34SMin Hu (Connor) 581699a2dd95SBruce Richardson if (*dev->dev_ops->pool_ops_supported == NULL) 581799a2dd95SBruce Richardson return 1; /* all pools are supported */ 581899a2dd95SBruce Richardson 581999a2dd95SBruce Richardson return (*dev->dev_ops->pool_ops_supported)(dev, pool); 582099a2dd95SBruce Richardson } 582199a2dd95SBruce Richardson 582299a2dd95SBruce Richardson /** 582399a2dd95SBruce Richardson * A set of values to describe the possible states of a switch domain. 582499a2dd95SBruce Richardson */ 582599a2dd95SBruce Richardson enum rte_eth_switch_domain_state { 582699a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_UNUSED = 0, 582799a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_ALLOCATED 582899a2dd95SBruce Richardson }; 582999a2dd95SBruce Richardson 583099a2dd95SBruce Richardson /** 583199a2dd95SBruce Richardson * Array of switch domains available for allocation. Array is sized to 583299a2dd95SBruce Richardson * RTE_MAX_ETHPORTS elements as there cannot be more active switch domains than 583399a2dd95SBruce Richardson * ethdev ports in a single process. 583499a2dd95SBruce Richardson */ 583599a2dd95SBruce Richardson static struct rte_eth_dev_switch { 583699a2dd95SBruce Richardson enum rte_eth_switch_domain_state state; 583799a2dd95SBruce Richardson } eth_dev_switch_domains[RTE_MAX_ETHPORTS]; 583899a2dd95SBruce Richardson 583999a2dd95SBruce Richardson int 584099a2dd95SBruce Richardson rte_eth_switch_domain_alloc(uint16_t *domain_id) 584199a2dd95SBruce Richardson { 584299a2dd95SBruce Richardson uint16_t i; 584399a2dd95SBruce Richardson 584499a2dd95SBruce Richardson *domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 584599a2dd95SBruce Richardson 584699a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 584799a2dd95SBruce Richardson if (eth_dev_switch_domains[i].state == 584899a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_UNUSED) { 584999a2dd95SBruce Richardson eth_dev_switch_domains[i].state = 585099a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_ALLOCATED; 585199a2dd95SBruce Richardson *domain_id = i; 585299a2dd95SBruce Richardson return 0; 585399a2dd95SBruce Richardson } 585499a2dd95SBruce Richardson } 585599a2dd95SBruce Richardson 585699a2dd95SBruce Richardson return -ENOSPC; 585799a2dd95SBruce Richardson } 585899a2dd95SBruce Richardson 585999a2dd95SBruce Richardson int 586099a2dd95SBruce Richardson rte_eth_switch_domain_free(uint16_t domain_id) 586199a2dd95SBruce Richardson { 586299a2dd95SBruce Richardson if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID || 586399a2dd95SBruce Richardson domain_id >= RTE_MAX_ETHPORTS) 586499a2dd95SBruce Richardson return -EINVAL; 586599a2dd95SBruce Richardson 586699a2dd95SBruce Richardson if (eth_dev_switch_domains[domain_id].state != 586799a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_ALLOCATED) 586899a2dd95SBruce Richardson return -EINVAL; 586999a2dd95SBruce Richardson 587099a2dd95SBruce Richardson eth_dev_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED; 587199a2dd95SBruce Richardson 587299a2dd95SBruce Richardson return 0; 587399a2dd95SBruce Richardson } 587499a2dd95SBruce Richardson 587599a2dd95SBruce Richardson static int 587699a2dd95SBruce Richardson eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in) 587799a2dd95SBruce Richardson { 587899a2dd95SBruce Richardson int state; 587999a2dd95SBruce Richardson struct rte_kvargs_pair *pair; 588099a2dd95SBruce Richardson char *letter; 588199a2dd95SBruce Richardson 588299a2dd95SBruce Richardson arglist->str = strdup(str_in); 588399a2dd95SBruce Richardson if (arglist->str == NULL) 588499a2dd95SBruce Richardson return -ENOMEM; 588599a2dd95SBruce Richardson 588699a2dd95SBruce Richardson letter = arglist->str; 588799a2dd95SBruce Richardson state = 0; 588899a2dd95SBruce Richardson arglist->count = 0; 588999a2dd95SBruce Richardson pair = &arglist->pairs[0]; 589099a2dd95SBruce Richardson while (1) { 589199a2dd95SBruce Richardson switch (state) { 589299a2dd95SBruce Richardson case 0: /* Initial */ 589399a2dd95SBruce Richardson if (*letter == '=') 589499a2dd95SBruce Richardson return -EINVAL; 589599a2dd95SBruce Richardson else if (*letter == '\0') 589699a2dd95SBruce Richardson return 0; 589799a2dd95SBruce Richardson 589899a2dd95SBruce Richardson state = 1; 589999a2dd95SBruce Richardson pair->key = letter; 590099a2dd95SBruce Richardson /* fall-thru */ 590199a2dd95SBruce Richardson 590299a2dd95SBruce Richardson case 1: /* Parsing key */ 590399a2dd95SBruce Richardson if (*letter == '=') { 590499a2dd95SBruce Richardson *letter = '\0'; 590599a2dd95SBruce Richardson pair->value = letter + 1; 590699a2dd95SBruce Richardson state = 2; 590799a2dd95SBruce Richardson } else if (*letter == ',' || *letter == '\0') 590899a2dd95SBruce Richardson return -EINVAL; 590999a2dd95SBruce Richardson break; 591099a2dd95SBruce Richardson 591199a2dd95SBruce Richardson 591299a2dd95SBruce Richardson case 2: /* Parsing value */ 591399a2dd95SBruce Richardson if (*letter == '[') 591499a2dd95SBruce Richardson state = 3; 591599a2dd95SBruce Richardson else if (*letter == ',') { 591699a2dd95SBruce Richardson *letter = '\0'; 591799a2dd95SBruce Richardson arglist->count++; 591899a2dd95SBruce Richardson pair = &arglist->pairs[arglist->count]; 591999a2dd95SBruce Richardson state = 0; 592099a2dd95SBruce Richardson } else if (*letter == '\0') { 592199a2dd95SBruce Richardson letter--; 592299a2dd95SBruce Richardson arglist->count++; 592399a2dd95SBruce Richardson pair = &arglist->pairs[arglist->count]; 592499a2dd95SBruce Richardson state = 0; 592599a2dd95SBruce Richardson } 592699a2dd95SBruce Richardson break; 592799a2dd95SBruce Richardson 592899a2dd95SBruce Richardson case 3: /* Parsing list */ 592999a2dd95SBruce Richardson if (*letter == ']') 593099a2dd95SBruce Richardson state = 2; 593199a2dd95SBruce Richardson else if (*letter == '\0') 593299a2dd95SBruce Richardson return -EINVAL; 593399a2dd95SBruce Richardson break; 593499a2dd95SBruce Richardson } 593599a2dd95SBruce Richardson letter++; 593699a2dd95SBruce Richardson } 593799a2dd95SBruce Richardson } 593899a2dd95SBruce Richardson 593999a2dd95SBruce Richardson int 594099a2dd95SBruce Richardson rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) 594199a2dd95SBruce Richardson { 594299a2dd95SBruce Richardson struct rte_kvargs args; 594399a2dd95SBruce Richardson struct rte_kvargs_pair *pair; 594499a2dd95SBruce Richardson unsigned int i; 594599a2dd95SBruce Richardson int result = 0; 594699a2dd95SBruce Richardson 594799a2dd95SBruce Richardson memset(eth_da, 0, sizeof(*eth_da)); 594899a2dd95SBruce Richardson 594999a2dd95SBruce Richardson result = eth_dev_devargs_tokenise(&args, dargs); 595099a2dd95SBruce Richardson if (result < 0) 595199a2dd95SBruce Richardson goto parse_cleanup; 595299a2dd95SBruce Richardson 595399a2dd95SBruce Richardson for (i = 0; i < args.count; i++) { 595499a2dd95SBruce Richardson pair = &args.pairs[i]; 595599a2dd95SBruce Richardson if (strcmp("representor", pair->key) == 0) { 595699a2dd95SBruce Richardson if (eth_da->type != RTE_ETH_REPRESENTOR_NONE) { 595799a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "duplicated representor key: %s\n", 595899a2dd95SBruce Richardson dargs); 595999a2dd95SBruce Richardson result = -1; 596099a2dd95SBruce Richardson goto parse_cleanup; 596199a2dd95SBruce Richardson } 596299a2dd95SBruce Richardson result = rte_eth_devargs_parse_representor_ports( 596399a2dd95SBruce Richardson pair->value, eth_da); 596499a2dd95SBruce Richardson if (result < 0) 596599a2dd95SBruce Richardson goto parse_cleanup; 596699a2dd95SBruce Richardson } 596799a2dd95SBruce Richardson } 596899a2dd95SBruce Richardson 596999a2dd95SBruce Richardson parse_cleanup: 597099a2dd95SBruce Richardson if (args.str) 597199a2dd95SBruce Richardson free(args.str); 597299a2dd95SBruce Richardson 597399a2dd95SBruce Richardson return result; 597499a2dd95SBruce Richardson } 597599a2dd95SBruce Richardson 597699a2dd95SBruce Richardson int 5977ff4e52efSViacheslav Galaktionov rte_eth_representor_id_get(uint16_t port_id, 597899a2dd95SBruce Richardson enum rte_eth_representor_type type, 597999a2dd95SBruce Richardson int controller, int pf, int representor_port, 598099a2dd95SBruce Richardson uint16_t *repr_id) 598199a2dd95SBruce Richardson { 598210eaf41dSViacheslav Galaktionov int ret, n, count; 598310eaf41dSViacheslav Galaktionov uint32_t i; 598499a2dd95SBruce Richardson struct rte_eth_representor_info *info = NULL; 598599a2dd95SBruce Richardson size_t size; 598699a2dd95SBruce Richardson 598799a2dd95SBruce Richardson if (type == RTE_ETH_REPRESENTOR_NONE) 598899a2dd95SBruce Richardson return 0; 598999a2dd95SBruce Richardson if (repr_id == NULL) 599099a2dd95SBruce Richardson return -EINVAL; 599199a2dd95SBruce Richardson 599299a2dd95SBruce Richardson /* Get PMD representor range info. */ 5993ff4e52efSViacheslav Galaktionov ret = rte_eth_representor_info_get(port_id, NULL); 599499a2dd95SBruce Richardson if (ret == -ENOTSUP && type == RTE_ETH_REPRESENTOR_VF && 599599a2dd95SBruce Richardson controller == -1 && pf == -1) { 599699a2dd95SBruce Richardson /* Direct mapping for legacy VF representor. */ 599799a2dd95SBruce Richardson *repr_id = representor_port; 599899a2dd95SBruce Richardson return 0; 599999a2dd95SBruce Richardson } else if (ret < 0) { 600099a2dd95SBruce Richardson return ret; 600199a2dd95SBruce Richardson } 600299a2dd95SBruce Richardson n = ret; 600399a2dd95SBruce Richardson size = sizeof(*info) + n * sizeof(info->ranges[0]); 600499a2dd95SBruce Richardson info = calloc(1, size); 600599a2dd95SBruce Richardson if (info == NULL) 600699a2dd95SBruce Richardson return -ENOMEM; 600710eaf41dSViacheslav Galaktionov info->nb_ranges_alloc = n; 6008ff4e52efSViacheslav Galaktionov ret = rte_eth_representor_info_get(port_id, info); 600999a2dd95SBruce Richardson if (ret < 0) 601099a2dd95SBruce Richardson goto out; 601199a2dd95SBruce Richardson 601299a2dd95SBruce Richardson /* Default controller and pf to caller. */ 601399a2dd95SBruce Richardson if (controller == -1) 601499a2dd95SBruce Richardson controller = info->controller; 601599a2dd95SBruce Richardson if (pf == -1) 601699a2dd95SBruce Richardson pf = info->pf; 601799a2dd95SBruce Richardson 601899a2dd95SBruce Richardson /* Locate representor ID. */ 601999a2dd95SBruce Richardson ret = -ENOENT; 602010eaf41dSViacheslav Galaktionov for (i = 0; i < info->nb_ranges; ++i) { 602199a2dd95SBruce Richardson if (info->ranges[i].type != type) 602299a2dd95SBruce Richardson continue; 602399a2dd95SBruce Richardson if (info->ranges[i].controller != controller) 602499a2dd95SBruce Richardson continue; 602599a2dd95SBruce Richardson if (info->ranges[i].id_end < info->ranges[i].id_base) { 602699a2dd95SBruce Richardson RTE_LOG(WARNING, EAL, "Port %hu invalid representor ID Range %u - %u, entry %d\n", 6027ff4e52efSViacheslav Galaktionov port_id, info->ranges[i].id_base, 602899a2dd95SBruce Richardson info->ranges[i].id_end, i); 602999a2dd95SBruce Richardson continue; 603099a2dd95SBruce Richardson 603199a2dd95SBruce Richardson } 603299a2dd95SBruce Richardson count = info->ranges[i].id_end - info->ranges[i].id_base + 1; 603399a2dd95SBruce Richardson switch (info->ranges[i].type) { 603499a2dd95SBruce Richardson case RTE_ETH_REPRESENTOR_PF: 603599a2dd95SBruce Richardson if (pf < info->ranges[i].pf || 603699a2dd95SBruce Richardson pf >= info->ranges[i].pf + count) 603799a2dd95SBruce Richardson continue; 603899a2dd95SBruce Richardson *repr_id = info->ranges[i].id_base + 603999a2dd95SBruce Richardson (pf - info->ranges[i].pf); 604099a2dd95SBruce Richardson ret = 0; 604199a2dd95SBruce Richardson goto out; 604299a2dd95SBruce Richardson case RTE_ETH_REPRESENTOR_VF: 604399a2dd95SBruce Richardson if (info->ranges[i].pf != pf) 604499a2dd95SBruce Richardson continue; 604599a2dd95SBruce Richardson if (representor_port < info->ranges[i].vf || 604699a2dd95SBruce Richardson representor_port >= info->ranges[i].vf + count) 604799a2dd95SBruce Richardson continue; 604899a2dd95SBruce Richardson *repr_id = info->ranges[i].id_base + 604999a2dd95SBruce Richardson (representor_port - info->ranges[i].vf); 605099a2dd95SBruce Richardson ret = 0; 605199a2dd95SBruce Richardson goto out; 605299a2dd95SBruce Richardson case RTE_ETH_REPRESENTOR_SF: 605399a2dd95SBruce Richardson if (info->ranges[i].pf != pf) 605499a2dd95SBruce Richardson continue; 605599a2dd95SBruce Richardson if (representor_port < info->ranges[i].sf || 605699a2dd95SBruce Richardson representor_port >= info->ranges[i].sf + count) 605799a2dd95SBruce Richardson continue; 605899a2dd95SBruce Richardson *repr_id = info->ranges[i].id_base + 605999a2dd95SBruce Richardson (representor_port - info->ranges[i].sf); 606099a2dd95SBruce Richardson ret = 0; 606199a2dd95SBruce Richardson goto out; 606299a2dd95SBruce Richardson default: 606399a2dd95SBruce Richardson break; 606499a2dd95SBruce Richardson } 606599a2dd95SBruce Richardson } 606699a2dd95SBruce Richardson out: 606799a2dd95SBruce Richardson free(info); 606899a2dd95SBruce Richardson return ret; 606999a2dd95SBruce Richardson } 607099a2dd95SBruce Richardson 607199a2dd95SBruce Richardson static int 607299a2dd95SBruce Richardson eth_dev_handle_port_list(const char *cmd __rte_unused, 607399a2dd95SBruce Richardson const char *params __rte_unused, 607499a2dd95SBruce Richardson struct rte_tel_data *d) 607599a2dd95SBruce Richardson { 607699a2dd95SBruce Richardson int port_id; 607799a2dd95SBruce Richardson 607899a2dd95SBruce Richardson rte_tel_data_start_array(d, RTE_TEL_INT_VAL); 607999a2dd95SBruce Richardson RTE_ETH_FOREACH_DEV(port_id) 608099a2dd95SBruce Richardson rte_tel_data_add_array_int(d, port_id); 608199a2dd95SBruce Richardson return 0; 608299a2dd95SBruce Richardson } 608399a2dd95SBruce Richardson 608499a2dd95SBruce Richardson static void 608599a2dd95SBruce Richardson eth_dev_add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats, 608699a2dd95SBruce Richardson const char *stat_name) 608799a2dd95SBruce Richardson { 608899a2dd95SBruce Richardson int q; 608999a2dd95SBruce Richardson struct rte_tel_data *q_data = rte_tel_data_alloc(); 609099a2dd95SBruce Richardson rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL); 609199a2dd95SBruce Richardson for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++) 609299a2dd95SBruce Richardson rte_tel_data_add_array_u64(q_data, q_stats[q]); 609399a2dd95SBruce Richardson rte_tel_data_add_dict_container(d, stat_name, q_data, 0); 609499a2dd95SBruce Richardson } 609599a2dd95SBruce Richardson 609699a2dd95SBruce Richardson #define ADD_DICT_STAT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s) 609799a2dd95SBruce Richardson 609899a2dd95SBruce Richardson static int 609999a2dd95SBruce Richardson eth_dev_handle_port_stats(const char *cmd __rte_unused, 610099a2dd95SBruce Richardson const char *params, 610199a2dd95SBruce Richardson struct rte_tel_data *d) 610299a2dd95SBruce Richardson { 610399a2dd95SBruce Richardson struct rte_eth_stats stats; 610499a2dd95SBruce Richardson int port_id, ret; 610599a2dd95SBruce Richardson 610699a2dd95SBruce Richardson if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 610799a2dd95SBruce Richardson return -1; 610899a2dd95SBruce Richardson 610999a2dd95SBruce Richardson port_id = atoi(params); 611099a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id)) 611199a2dd95SBruce Richardson return -1; 611299a2dd95SBruce Richardson 611399a2dd95SBruce Richardson ret = rte_eth_stats_get(port_id, &stats); 611499a2dd95SBruce Richardson if (ret < 0) 611599a2dd95SBruce Richardson return -1; 611699a2dd95SBruce Richardson 611799a2dd95SBruce Richardson rte_tel_data_start_dict(d); 611899a2dd95SBruce Richardson ADD_DICT_STAT(stats, ipackets); 611999a2dd95SBruce Richardson ADD_DICT_STAT(stats, opackets); 612099a2dd95SBruce Richardson ADD_DICT_STAT(stats, ibytes); 612199a2dd95SBruce Richardson ADD_DICT_STAT(stats, obytes); 612299a2dd95SBruce Richardson ADD_DICT_STAT(stats, imissed); 612399a2dd95SBruce Richardson ADD_DICT_STAT(stats, ierrors); 612499a2dd95SBruce Richardson ADD_DICT_STAT(stats, oerrors); 612599a2dd95SBruce Richardson ADD_DICT_STAT(stats, rx_nombuf); 612699a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_ipackets, "q_ipackets"); 612799a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_opackets, "q_opackets"); 612899a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_ibytes, "q_ibytes"); 612999a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_obytes, "q_obytes"); 613099a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_errors, "q_errors"); 613199a2dd95SBruce Richardson 613299a2dd95SBruce Richardson return 0; 613399a2dd95SBruce Richardson } 613499a2dd95SBruce Richardson 613599a2dd95SBruce Richardson static int 613699a2dd95SBruce Richardson eth_dev_handle_port_xstats(const char *cmd __rte_unused, 613799a2dd95SBruce Richardson const char *params, 613899a2dd95SBruce Richardson struct rte_tel_data *d) 613999a2dd95SBruce Richardson { 614099a2dd95SBruce Richardson struct rte_eth_xstat *eth_xstats; 614199a2dd95SBruce Richardson struct rte_eth_xstat_name *xstat_names; 614299a2dd95SBruce Richardson int port_id, num_xstats; 614399a2dd95SBruce Richardson int i, ret; 614499a2dd95SBruce Richardson char *end_param; 614599a2dd95SBruce Richardson 614699a2dd95SBruce Richardson if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 614799a2dd95SBruce Richardson return -1; 614899a2dd95SBruce Richardson 614999a2dd95SBruce Richardson port_id = strtoul(params, &end_param, 0); 615099a2dd95SBruce Richardson if (*end_param != '\0') 615199a2dd95SBruce Richardson RTE_ETHDEV_LOG(NOTICE, 615299a2dd95SBruce Richardson "Extra parameters passed to ethdev telemetry command, ignoring"); 615399a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id)) 615499a2dd95SBruce Richardson return -1; 615599a2dd95SBruce Richardson 615699a2dd95SBruce Richardson num_xstats = rte_eth_xstats_get(port_id, NULL, 0); 615799a2dd95SBruce Richardson if (num_xstats < 0) 615899a2dd95SBruce Richardson return -1; 615999a2dd95SBruce Richardson 616099a2dd95SBruce Richardson /* use one malloc for both names and stats */ 616199a2dd95SBruce Richardson eth_xstats = malloc((sizeof(struct rte_eth_xstat) + 616299a2dd95SBruce Richardson sizeof(struct rte_eth_xstat_name)) * num_xstats); 616399a2dd95SBruce Richardson if (eth_xstats == NULL) 616499a2dd95SBruce Richardson return -1; 616599a2dd95SBruce Richardson xstat_names = (void *)ð_xstats[num_xstats]; 616699a2dd95SBruce Richardson 616799a2dd95SBruce Richardson ret = rte_eth_xstats_get_names(port_id, xstat_names, num_xstats); 616899a2dd95SBruce Richardson if (ret < 0 || ret > num_xstats) { 616999a2dd95SBruce Richardson free(eth_xstats); 617099a2dd95SBruce Richardson return -1; 617199a2dd95SBruce Richardson } 617299a2dd95SBruce Richardson 617399a2dd95SBruce Richardson ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats); 617499a2dd95SBruce Richardson if (ret < 0 || ret > num_xstats) { 617599a2dd95SBruce Richardson free(eth_xstats); 617699a2dd95SBruce Richardson return -1; 617799a2dd95SBruce Richardson } 617899a2dd95SBruce Richardson 617999a2dd95SBruce Richardson rte_tel_data_start_dict(d); 618099a2dd95SBruce Richardson for (i = 0; i < num_xstats; i++) 618199a2dd95SBruce Richardson rte_tel_data_add_dict_u64(d, xstat_names[i].name, 618299a2dd95SBruce Richardson eth_xstats[i].value); 618399a2dd95SBruce Richardson return 0; 618499a2dd95SBruce Richardson } 618599a2dd95SBruce Richardson 618699a2dd95SBruce Richardson static int 618799a2dd95SBruce Richardson eth_dev_handle_port_link_status(const char *cmd __rte_unused, 618899a2dd95SBruce Richardson const char *params, 618999a2dd95SBruce Richardson struct rte_tel_data *d) 619099a2dd95SBruce Richardson { 619199a2dd95SBruce Richardson static const char *status_str = "status"; 619299a2dd95SBruce Richardson int ret, port_id; 619399a2dd95SBruce Richardson struct rte_eth_link link; 619499a2dd95SBruce Richardson char *end_param; 619599a2dd95SBruce Richardson 619699a2dd95SBruce Richardson if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 619799a2dd95SBruce Richardson return -1; 619899a2dd95SBruce Richardson 619999a2dd95SBruce Richardson port_id = strtoul(params, &end_param, 0); 620099a2dd95SBruce Richardson if (*end_param != '\0') 620199a2dd95SBruce Richardson RTE_ETHDEV_LOG(NOTICE, 620299a2dd95SBruce Richardson "Extra parameters passed to ethdev telemetry command, ignoring"); 620399a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id)) 620499a2dd95SBruce Richardson return -1; 620599a2dd95SBruce Richardson 620699a2dd95SBruce Richardson ret = rte_eth_link_get_nowait(port_id, &link); 620799a2dd95SBruce Richardson if (ret < 0) 620899a2dd95SBruce Richardson return -1; 620999a2dd95SBruce Richardson 621099a2dd95SBruce Richardson rte_tel_data_start_dict(d); 621199a2dd95SBruce Richardson if (!link.link_status) { 621299a2dd95SBruce Richardson rte_tel_data_add_dict_string(d, status_str, "DOWN"); 621399a2dd95SBruce Richardson return 0; 621499a2dd95SBruce Richardson } 621599a2dd95SBruce Richardson rte_tel_data_add_dict_string(d, status_str, "UP"); 621699a2dd95SBruce Richardson rte_tel_data_add_dict_u64(d, "speed", link.link_speed); 621799a2dd95SBruce Richardson rte_tel_data_add_dict_string(d, "duplex", 621899a2dd95SBruce Richardson (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 621999a2dd95SBruce Richardson "full-duplex" : "half-duplex"); 622099a2dd95SBruce Richardson return 0; 622199a2dd95SBruce Richardson } 622299a2dd95SBruce Richardson 622358b43c1dSGowrishankar Muthukrishnan static int 622458b43c1dSGowrishankar Muthukrishnan eth_dev_handle_port_info(const char *cmd __rte_unused, 622558b43c1dSGowrishankar Muthukrishnan const char *params, 622658b43c1dSGowrishankar Muthukrishnan struct rte_tel_data *d) 622758b43c1dSGowrishankar Muthukrishnan { 622858b43c1dSGowrishankar Muthukrishnan struct rte_tel_data *rxq_state, *txq_state; 622958b43c1dSGowrishankar Muthukrishnan char mac_addr[RTE_ETHER_ADDR_LEN]; 623058b43c1dSGowrishankar Muthukrishnan struct rte_eth_dev *eth_dev; 623158b43c1dSGowrishankar Muthukrishnan char *end_param; 623258b43c1dSGowrishankar Muthukrishnan int port_id, i; 623358b43c1dSGowrishankar Muthukrishnan 623458b43c1dSGowrishankar Muthukrishnan if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 623558b43c1dSGowrishankar Muthukrishnan return -1; 623658b43c1dSGowrishankar Muthukrishnan 623758b43c1dSGowrishankar Muthukrishnan port_id = strtoul(params, &end_param, 0); 623858b43c1dSGowrishankar Muthukrishnan if (*end_param != '\0') 623958b43c1dSGowrishankar Muthukrishnan RTE_ETHDEV_LOG(NOTICE, 624058b43c1dSGowrishankar Muthukrishnan "Extra parameters passed to ethdev telemetry command, ignoring"); 624158b43c1dSGowrishankar Muthukrishnan 624258b43c1dSGowrishankar Muthukrishnan if (!rte_eth_dev_is_valid_port(port_id)) 624358b43c1dSGowrishankar Muthukrishnan return -EINVAL; 624458b43c1dSGowrishankar Muthukrishnan 624558b43c1dSGowrishankar Muthukrishnan eth_dev = &rte_eth_devices[port_id]; 624658b43c1dSGowrishankar Muthukrishnan if (!eth_dev) 624758b43c1dSGowrishankar Muthukrishnan return -EINVAL; 624858b43c1dSGowrishankar Muthukrishnan 624958b43c1dSGowrishankar Muthukrishnan rxq_state = rte_tel_data_alloc(); 625058b43c1dSGowrishankar Muthukrishnan if (!rxq_state) 625158b43c1dSGowrishankar Muthukrishnan return -ENOMEM; 625258b43c1dSGowrishankar Muthukrishnan 625358b43c1dSGowrishankar Muthukrishnan txq_state = rte_tel_data_alloc(); 625458b43c1dSGowrishankar Muthukrishnan if (!txq_state) 625558b43c1dSGowrishankar Muthukrishnan return -ENOMEM; 625658b43c1dSGowrishankar Muthukrishnan 625758b43c1dSGowrishankar Muthukrishnan rte_tel_data_start_dict(d); 625858b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_string(d, "name", eth_dev->data->name); 625958b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "state", eth_dev->state); 626058b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "nb_rx_queues", 626158b43c1dSGowrishankar Muthukrishnan eth_dev->data->nb_rx_queues); 626258b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "nb_tx_queues", 626358b43c1dSGowrishankar Muthukrishnan eth_dev->data->nb_tx_queues); 626458b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "port_id", eth_dev->data->port_id); 626558b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "mtu", eth_dev->data->mtu); 626658b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "rx_mbuf_size_min", 626758b43c1dSGowrishankar Muthukrishnan eth_dev->data->min_rx_buf_size); 626858b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "rx_mbuf_alloc_fail", 626958b43c1dSGowrishankar Muthukrishnan eth_dev->data->rx_mbuf_alloc_failed); 627058b43c1dSGowrishankar Muthukrishnan snprintf(mac_addr, RTE_ETHER_ADDR_LEN, "%02x:%02x:%02x:%02x:%02x:%02x", 627158b43c1dSGowrishankar Muthukrishnan eth_dev->data->mac_addrs->addr_bytes[0], 627258b43c1dSGowrishankar Muthukrishnan eth_dev->data->mac_addrs->addr_bytes[1], 627358b43c1dSGowrishankar Muthukrishnan eth_dev->data->mac_addrs->addr_bytes[2], 627458b43c1dSGowrishankar Muthukrishnan eth_dev->data->mac_addrs->addr_bytes[3], 627558b43c1dSGowrishankar Muthukrishnan eth_dev->data->mac_addrs->addr_bytes[4], 627658b43c1dSGowrishankar Muthukrishnan eth_dev->data->mac_addrs->addr_bytes[5]); 627758b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_string(d, "mac_addr", mac_addr); 627858b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "promiscuous", 627958b43c1dSGowrishankar Muthukrishnan eth_dev->data->promiscuous); 628058b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "scattered_rx", 628158b43c1dSGowrishankar Muthukrishnan eth_dev->data->scattered_rx); 628258b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "all_multicast", 628358b43c1dSGowrishankar Muthukrishnan eth_dev->data->all_multicast); 628458b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "dev_started", eth_dev->data->dev_started); 628558b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "lro", eth_dev->data->lro); 628658b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "dev_configured", 628758b43c1dSGowrishankar Muthukrishnan eth_dev->data->dev_configured); 628858b43c1dSGowrishankar Muthukrishnan 628958b43c1dSGowrishankar Muthukrishnan rte_tel_data_start_array(rxq_state, RTE_TEL_INT_VAL); 629058b43c1dSGowrishankar Muthukrishnan for (i = 0; i < eth_dev->data->nb_rx_queues; i++) 629158b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_array_int(rxq_state, 629258b43c1dSGowrishankar Muthukrishnan eth_dev->data->rx_queue_state[i]); 629358b43c1dSGowrishankar Muthukrishnan 629458b43c1dSGowrishankar Muthukrishnan rte_tel_data_start_array(txq_state, RTE_TEL_INT_VAL); 629558b43c1dSGowrishankar Muthukrishnan for (i = 0; i < eth_dev->data->nb_tx_queues; i++) 629658b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_array_int(txq_state, 629758b43c1dSGowrishankar Muthukrishnan eth_dev->data->tx_queue_state[i]); 629858b43c1dSGowrishankar Muthukrishnan 629958b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_container(d, "rxq_state", rxq_state, 0); 630058b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_container(d, "txq_state", txq_state, 0); 630158b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "numa_node", eth_dev->data->numa_node); 630258b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "dev_flags", eth_dev->data->dev_flags); 630358b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "rx_offloads", 630458b43c1dSGowrishankar Muthukrishnan eth_dev->data->dev_conf.rxmode.offloads); 630558b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "tx_offloads", 630658b43c1dSGowrishankar Muthukrishnan eth_dev->data->dev_conf.txmode.offloads); 630758b43c1dSGowrishankar Muthukrishnan rte_tel_data_add_dict_int(d, "ethdev_rss_hf", 630858b43c1dSGowrishankar Muthukrishnan eth_dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf); 630958b43c1dSGowrishankar Muthukrishnan 631058b43c1dSGowrishankar Muthukrishnan return 0; 631158b43c1dSGowrishankar Muthukrishnan } 631258b43c1dSGowrishankar Muthukrishnan 631399a2dd95SBruce Richardson int 631499a2dd95SBruce Richardson rte_eth_hairpin_queue_peer_update(uint16_t peer_port, uint16_t peer_queue, 631599a2dd95SBruce Richardson struct rte_hairpin_peer_info *cur_info, 631699a2dd95SBruce Richardson struct rte_hairpin_peer_info *peer_info, 631799a2dd95SBruce Richardson uint32_t direction) 631899a2dd95SBruce Richardson { 631999a2dd95SBruce Richardson struct rte_eth_dev *dev; 632099a2dd95SBruce Richardson 632199a2dd95SBruce Richardson /* Current queue information is not mandatory. */ 632299a2dd95SBruce Richardson if (peer_info == NULL) 632399a2dd95SBruce Richardson return -EINVAL; 632499a2dd95SBruce Richardson 632599a2dd95SBruce Richardson /* No need to check the validity again. */ 632699a2dd95SBruce Richardson dev = &rte_eth_devices[peer_port]; 632799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_queue_peer_update, 632899a2dd95SBruce Richardson -ENOTSUP); 632999a2dd95SBruce Richardson 633099a2dd95SBruce Richardson return (*dev->dev_ops->hairpin_queue_peer_update)(dev, peer_queue, 633199a2dd95SBruce Richardson cur_info, peer_info, direction); 633299a2dd95SBruce Richardson } 633399a2dd95SBruce Richardson 633499a2dd95SBruce Richardson int 633599a2dd95SBruce Richardson rte_eth_hairpin_queue_peer_bind(uint16_t cur_port, uint16_t cur_queue, 633699a2dd95SBruce Richardson struct rte_hairpin_peer_info *peer_info, 633799a2dd95SBruce Richardson uint32_t direction) 633899a2dd95SBruce Richardson { 633999a2dd95SBruce Richardson struct rte_eth_dev *dev; 634099a2dd95SBruce Richardson 634199a2dd95SBruce Richardson if (peer_info == NULL) 634299a2dd95SBruce Richardson return -EINVAL; 634399a2dd95SBruce Richardson 634499a2dd95SBruce Richardson /* No need to check the validity again. */ 634599a2dd95SBruce Richardson dev = &rte_eth_devices[cur_port]; 634699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_queue_peer_bind, 634799a2dd95SBruce Richardson -ENOTSUP); 634899a2dd95SBruce Richardson 634999a2dd95SBruce Richardson return (*dev->dev_ops->hairpin_queue_peer_bind)(dev, cur_queue, 635099a2dd95SBruce Richardson peer_info, direction); 635199a2dd95SBruce Richardson } 635299a2dd95SBruce Richardson 635399a2dd95SBruce Richardson int 635499a2dd95SBruce Richardson rte_eth_hairpin_queue_peer_unbind(uint16_t cur_port, uint16_t cur_queue, 635599a2dd95SBruce Richardson uint32_t direction) 635699a2dd95SBruce Richardson { 635799a2dd95SBruce Richardson struct rte_eth_dev *dev; 635899a2dd95SBruce Richardson 635999a2dd95SBruce Richardson /* No need to check the validity again. */ 636099a2dd95SBruce Richardson dev = &rte_eth_devices[cur_port]; 636199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_queue_peer_unbind, 636299a2dd95SBruce Richardson -ENOTSUP); 636399a2dd95SBruce Richardson 636499a2dd95SBruce Richardson return (*dev->dev_ops->hairpin_queue_peer_unbind)(dev, cur_queue, 636599a2dd95SBruce Richardson direction); 636699a2dd95SBruce Richardson } 636799a2dd95SBruce Richardson 636899a2dd95SBruce Richardson int 636999a2dd95SBruce Richardson rte_eth_representor_info_get(uint16_t port_id, 637099a2dd95SBruce Richardson struct rte_eth_representor_info *info) 637199a2dd95SBruce Richardson { 637299a2dd95SBruce Richardson struct rte_eth_dev *dev; 637399a2dd95SBruce Richardson 637499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 637599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 637699a2dd95SBruce Richardson 637799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->representor_info_get, -ENOTSUP); 637853ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->representor_info_get)(dev, info)); 637999a2dd95SBruce Richardson } 638099a2dd95SBruce Richardson 6381f6d8a6d3SIvan Malov int 6382f6d8a6d3SIvan Malov rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features) 6383f6d8a6d3SIvan Malov { 6384f6d8a6d3SIvan Malov struct rte_eth_dev *dev; 6385f6d8a6d3SIvan Malov 6386f6d8a6d3SIvan Malov RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 6387f6d8a6d3SIvan Malov dev = &rte_eth_devices[port_id]; 6388f6d8a6d3SIvan Malov 6389f6d8a6d3SIvan Malov if (dev->data->dev_configured != 0) { 6390f6d8a6d3SIvan Malov RTE_ETHDEV_LOG(ERR, 6391f6d8a6d3SIvan Malov "The port (id=%"PRIu16") is already configured\n", 6392f6d8a6d3SIvan Malov port_id); 6393f6d8a6d3SIvan Malov return -EBUSY; 6394f6d8a6d3SIvan Malov } 6395f6d8a6d3SIvan Malov 6396f6d8a6d3SIvan Malov if (features == NULL) { 6397f6d8a6d3SIvan Malov RTE_ETHDEV_LOG(ERR, "Invalid features (NULL)\n"); 6398f6d8a6d3SIvan Malov return -EINVAL; 6399f6d8a6d3SIvan Malov } 6400f6d8a6d3SIvan Malov 6401f6d8a6d3SIvan Malov RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_metadata_negotiate, -ENOTSUP); 6402f6d8a6d3SIvan Malov return eth_err(port_id, 6403f6d8a6d3SIvan Malov (*dev->dev_ops->rx_metadata_negotiate)(dev, features)); 6404f6d8a6d3SIvan Malov } 6405f6d8a6d3SIvan Malov 6406eeded204SDavid Marchand RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO); 640799a2dd95SBruce Richardson 640899a2dd95SBruce Richardson RTE_INIT(ethdev_init_telemetry) 640999a2dd95SBruce Richardson { 641099a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list, 641199a2dd95SBruce Richardson "Returns list of available ethdev ports. Takes no parameters"); 641299a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/stats", eth_dev_handle_port_stats, 641399a2dd95SBruce Richardson "Returns the common stats for a port. Parameters: int port_id"); 641499a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/xstats", eth_dev_handle_port_xstats, 641599a2dd95SBruce Richardson "Returns the extended stats for a port. Parameters: int port_id"); 641699a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/link_status", 641799a2dd95SBruce Richardson eth_dev_handle_port_link_status, 641899a2dd95SBruce Richardson "Returns the link status for a port. Parameters: int port_id"); 641958b43c1dSGowrishankar Muthukrishnan rte_telemetry_register_cmd("/ethdev/info", eth_dev_handle_port_info, 642058b43c1dSGowrishankar Muthukrishnan "Returns the device info for a port. Parameters: int port_id"); 642199a2dd95SBruce Richardson } 6422