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 4799a2dd95SBruce Richardson /* spinlock for eth device callbacks */ 4899a2dd95SBruce Richardson static rte_spinlock_t eth_dev_cb_lock = RTE_SPINLOCK_INITIALIZER; 4999a2dd95SBruce Richardson 5099a2dd95SBruce Richardson /* spinlock for add/remove rx callbacks */ 5199a2dd95SBruce Richardson static rte_spinlock_t eth_dev_rx_cb_lock = RTE_SPINLOCK_INITIALIZER; 5299a2dd95SBruce Richardson 5399a2dd95SBruce Richardson /* spinlock for add/remove tx callbacks */ 5499a2dd95SBruce Richardson static rte_spinlock_t eth_dev_tx_cb_lock = RTE_SPINLOCK_INITIALIZER; 5599a2dd95SBruce Richardson 5699a2dd95SBruce Richardson /* spinlock for shared data allocation */ 5799a2dd95SBruce Richardson static rte_spinlock_t eth_dev_shared_data_lock = RTE_SPINLOCK_INITIALIZER; 5899a2dd95SBruce Richardson 5999a2dd95SBruce Richardson /* store statistics names and its offset in stats structure */ 6099a2dd95SBruce Richardson struct rte_eth_xstats_name_off { 6199a2dd95SBruce Richardson char name[RTE_ETH_XSTATS_NAME_SIZE]; 6299a2dd95SBruce Richardson unsigned offset; 6399a2dd95SBruce Richardson }; 6499a2dd95SBruce Richardson 6599a2dd95SBruce Richardson /* Shared memory between primary and secondary processes. */ 6699a2dd95SBruce Richardson static struct { 6799a2dd95SBruce Richardson uint64_t next_owner_id; 6899a2dd95SBruce Richardson rte_spinlock_t ownership_lock; 6999a2dd95SBruce Richardson struct rte_eth_dev_data data[RTE_MAX_ETHPORTS]; 7099a2dd95SBruce Richardson } *eth_dev_shared_data; 7199a2dd95SBruce Richardson 7299a2dd95SBruce Richardson static const struct rte_eth_xstats_name_off eth_dev_stats_strings[] = { 7399a2dd95SBruce Richardson {"rx_good_packets", offsetof(struct rte_eth_stats, ipackets)}, 7499a2dd95SBruce Richardson {"tx_good_packets", offsetof(struct rte_eth_stats, opackets)}, 7599a2dd95SBruce Richardson {"rx_good_bytes", offsetof(struct rte_eth_stats, ibytes)}, 7699a2dd95SBruce Richardson {"tx_good_bytes", offsetof(struct rte_eth_stats, obytes)}, 7799a2dd95SBruce Richardson {"rx_missed_errors", offsetof(struct rte_eth_stats, imissed)}, 7899a2dd95SBruce Richardson {"rx_errors", offsetof(struct rte_eth_stats, ierrors)}, 7999a2dd95SBruce Richardson {"tx_errors", offsetof(struct rte_eth_stats, oerrors)}, 8099a2dd95SBruce Richardson {"rx_mbuf_allocation_errors", offsetof(struct rte_eth_stats, 8199a2dd95SBruce Richardson rx_nombuf)}, 8299a2dd95SBruce Richardson }; 8399a2dd95SBruce Richardson 8499a2dd95SBruce Richardson #define RTE_NB_STATS RTE_DIM(eth_dev_stats_strings) 8599a2dd95SBruce Richardson 8699a2dd95SBruce Richardson static const struct rte_eth_xstats_name_off eth_dev_rxq_stats_strings[] = { 8799a2dd95SBruce Richardson {"packets", offsetof(struct rte_eth_stats, q_ipackets)}, 8899a2dd95SBruce Richardson {"bytes", offsetof(struct rte_eth_stats, q_ibytes)}, 8999a2dd95SBruce Richardson {"errors", offsetof(struct rte_eth_stats, q_errors)}, 9099a2dd95SBruce Richardson }; 9199a2dd95SBruce Richardson 9299a2dd95SBruce Richardson #define RTE_NB_RXQ_STATS RTE_DIM(eth_dev_rxq_stats_strings) 9399a2dd95SBruce Richardson 9499a2dd95SBruce Richardson static const struct rte_eth_xstats_name_off eth_dev_txq_stats_strings[] = { 9599a2dd95SBruce Richardson {"packets", offsetof(struct rte_eth_stats, q_opackets)}, 9699a2dd95SBruce Richardson {"bytes", offsetof(struct rte_eth_stats, q_obytes)}, 9799a2dd95SBruce Richardson }; 9899a2dd95SBruce Richardson #define RTE_NB_TXQ_STATS RTE_DIM(eth_dev_txq_stats_strings) 9999a2dd95SBruce Richardson 10099a2dd95SBruce Richardson #define RTE_RX_OFFLOAD_BIT2STR(_name) \ 10199a2dd95SBruce Richardson { DEV_RX_OFFLOAD_##_name, #_name } 10299a2dd95SBruce Richardson 10399a2dd95SBruce Richardson #define RTE_ETH_RX_OFFLOAD_BIT2STR(_name) \ 10499a2dd95SBruce Richardson { RTE_ETH_RX_OFFLOAD_##_name, #_name } 10599a2dd95SBruce Richardson 10699a2dd95SBruce Richardson static const struct { 10799a2dd95SBruce Richardson uint64_t offload; 10899a2dd95SBruce Richardson const char *name; 10999a2dd95SBruce Richardson } eth_dev_rx_offload_names[] = { 11099a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(VLAN_STRIP), 11199a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(IPV4_CKSUM), 11299a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(UDP_CKSUM), 11399a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(TCP_CKSUM), 11499a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(TCP_LRO), 11599a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(QINQ_STRIP), 11699a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM), 11799a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(MACSEC_STRIP), 11899a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(HEADER_SPLIT), 11999a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(VLAN_FILTER), 12099a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(VLAN_EXTEND), 12199a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(JUMBO_FRAME), 12299a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(SCATTER), 12399a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(TIMESTAMP), 12499a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(SECURITY), 12599a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(KEEP_CRC), 12699a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(SCTP_CKSUM), 12799a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM), 12899a2dd95SBruce Richardson RTE_RX_OFFLOAD_BIT2STR(RSS_HASH), 12999a2dd95SBruce Richardson RTE_ETH_RX_OFFLOAD_BIT2STR(BUFFER_SPLIT), 13099a2dd95SBruce Richardson }; 13199a2dd95SBruce Richardson 13299a2dd95SBruce Richardson #undef RTE_RX_OFFLOAD_BIT2STR 13399a2dd95SBruce Richardson #undef RTE_ETH_RX_OFFLOAD_BIT2STR 13499a2dd95SBruce Richardson 13599a2dd95SBruce Richardson #define RTE_TX_OFFLOAD_BIT2STR(_name) \ 13699a2dd95SBruce Richardson { DEV_TX_OFFLOAD_##_name, #_name } 13799a2dd95SBruce Richardson 13899a2dd95SBruce Richardson static const struct { 13999a2dd95SBruce Richardson uint64_t offload; 14099a2dd95SBruce Richardson const char *name; 14199a2dd95SBruce Richardson } eth_dev_tx_offload_names[] = { 14299a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(VLAN_INSERT), 14399a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(IPV4_CKSUM), 14499a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(UDP_CKSUM), 14599a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(TCP_CKSUM), 14699a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(SCTP_CKSUM), 14799a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(TCP_TSO), 14899a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(UDP_TSO), 14999a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(OUTER_IPV4_CKSUM), 15099a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(QINQ_INSERT), 15199a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(VXLAN_TNL_TSO), 15299a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(GRE_TNL_TSO), 15399a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(IPIP_TNL_TSO), 15499a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(GENEVE_TNL_TSO), 15599a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MACSEC_INSERT), 15699a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MT_LOCKFREE), 15799a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MULTI_SEGS), 15899a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(MBUF_FAST_FREE), 15999a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(SECURITY), 16099a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(UDP_TNL_TSO), 16199a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(IP_TNL_TSO), 16299a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(OUTER_UDP_CKSUM), 16399a2dd95SBruce Richardson RTE_TX_OFFLOAD_BIT2STR(SEND_ON_TIMESTAMP), 16499a2dd95SBruce Richardson }; 16599a2dd95SBruce Richardson 16699a2dd95SBruce Richardson #undef RTE_TX_OFFLOAD_BIT2STR 16799a2dd95SBruce Richardson 16899a2dd95SBruce Richardson /** 16999a2dd95SBruce Richardson * The user application callback description. 17099a2dd95SBruce Richardson * 17199a2dd95SBruce Richardson * It contains callback address to be registered by user application, 17299a2dd95SBruce Richardson * the pointer to the parameters for callback, and the event type. 17399a2dd95SBruce Richardson */ 17499a2dd95SBruce Richardson struct rte_eth_dev_callback { 17599a2dd95SBruce Richardson TAILQ_ENTRY(rte_eth_dev_callback) next; /**< Callbacks list */ 17699a2dd95SBruce Richardson rte_eth_dev_cb_fn cb_fn; /**< Callback address */ 17799a2dd95SBruce Richardson void *cb_arg; /**< Parameter for callback */ 17899a2dd95SBruce Richardson void *ret_param; /**< Return parameter */ 17999a2dd95SBruce Richardson enum rte_eth_event_type event; /**< Interrupt event type */ 18099a2dd95SBruce Richardson uint32_t active; /**< Callback is executing */ 18199a2dd95SBruce Richardson }; 18299a2dd95SBruce Richardson 18399a2dd95SBruce Richardson enum { 18499a2dd95SBruce Richardson STAT_QMAP_TX = 0, 18599a2dd95SBruce Richardson STAT_QMAP_RX 18699a2dd95SBruce Richardson }; 18799a2dd95SBruce Richardson 18899a2dd95SBruce Richardson int 18999a2dd95SBruce Richardson rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str) 19099a2dd95SBruce Richardson { 19199a2dd95SBruce Richardson int ret; 19299a2dd95SBruce Richardson struct rte_devargs devargs; 19399a2dd95SBruce Richardson const char *bus_param_key; 19499a2dd95SBruce Richardson char *bus_str = NULL; 19599a2dd95SBruce Richardson char *cls_str = NULL; 19699a2dd95SBruce Richardson int str_size; 19799a2dd95SBruce Richardson 19853ef1b34SMin Hu (Connor) if (iter == NULL) { 19953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot initialize NULL iterator\n"); 20053ef1b34SMin Hu (Connor) return -EINVAL; 20153ef1b34SMin Hu (Connor) } 20253ef1b34SMin Hu (Connor) 20353ef1b34SMin Hu (Connor) if (devargs_str == NULL) { 20453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 20553ef1b34SMin Hu (Connor) "Cannot initialize iterator from NULL device description string\n"); 20653ef1b34SMin Hu (Connor) return -EINVAL; 20753ef1b34SMin Hu (Connor) } 20853ef1b34SMin Hu (Connor) 20999a2dd95SBruce Richardson memset(iter, 0, sizeof(*iter)); 21099a2dd95SBruce Richardson memset(&devargs, 0, sizeof(devargs)); 21199a2dd95SBruce Richardson 21299a2dd95SBruce Richardson /* 21399a2dd95SBruce Richardson * The devargs string may use various syntaxes: 21499a2dd95SBruce Richardson * - 0000:08:00.0,representor=[1-3] 21599a2dd95SBruce Richardson * - pci:0000:06:00.0,representor=[0,5] 21699a2dd95SBruce Richardson * - class=eth,mac=00:11:22:33:44:55 21799a2dd95SBruce Richardson * - bus=X,paramX=x/class=Y,paramY=y/driver=Z,paramZ=z 21899a2dd95SBruce Richardson */ 21999a2dd95SBruce Richardson 22099a2dd95SBruce Richardson /* 22199a2dd95SBruce Richardson * Handle pure class filter (i.e. without any bus-level argument), 22299a2dd95SBruce Richardson * from future new syntax. 22399a2dd95SBruce Richardson * rte_devargs_parse() is not yet supporting the new syntax, 22499a2dd95SBruce Richardson * that's why this simple case is temporarily parsed here. 22599a2dd95SBruce Richardson */ 22699a2dd95SBruce Richardson #define iter_anybus_str "class=eth," 22799a2dd95SBruce Richardson if (strncmp(devargs_str, iter_anybus_str, 22899a2dd95SBruce Richardson strlen(iter_anybus_str)) == 0) { 22999a2dd95SBruce Richardson iter->cls_str = devargs_str + strlen(iter_anybus_str); 23099a2dd95SBruce Richardson goto end; 23199a2dd95SBruce Richardson } 23299a2dd95SBruce Richardson 23399a2dd95SBruce Richardson /* Split bus, device and parameters. */ 23499a2dd95SBruce Richardson ret = rte_devargs_parse(&devargs, devargs_str); 23599a2dd95SBruce Richardson if (ret != 0) 23699a2dd95SBruce Richardson goto error; 23799a2dd95SBruce Richardson 23899a2dd95SBruce Richardson /* 23999a2dd95SBruce Richardson * Assume parameters of old syntax can match only at ethdev level. 24099a2dd95SBruce Richardson * Extra parameters will be ignored, thanks to "+" prefix. 24199a2dd95SBruce Richardson */ 24299a2dd95SBruce Richardson str_size = strlen(devargs.args) + 2; 24399a2dd95SBruce Richardson cls_str = malloc(str_size); 24499a2dd95SBruce Richardson if (cls_str == NULL) { 24599a2dd95SBruce Richardson ret = -ENOMEM; 24699a2dd95SBruce Richardson goto error; 24799a2dd95SBruce Richardson } 24899a2dd95SBruce Richardson ret = snprintf(cls_str, str_size, "+%s", devargs.args); 24999a2dd95SBruce Richardson if (ret != str_size - 1) { 25099a2dd95SBruce Richardson ret = -EINVAL; 25199a2dd95SBruce Richardson goto error; 25299a2dd95SBruce Richardson } 25399a2dd95SBruce Richardson iter->cls_str = cls_str; 25499a2dd95SBruce Richardson 25599a2dd95SBruce Richardson iter->bus = devargs.bus; 25699a2dd95SBruce Richardson if (iter->bus->dev_iterate == NULL) { 25799a2dd95SBruce Richardson ret = -ENOTSUP; 25899a2dd95SBruce Richardson goto error; 25999a2dd95SBruce Richardson } 26099a2dd95SBruce Richardson 26199a2dd95SBruce Richardson /* Convert bus args to new syntax for use with new API dev_iterate. */ 262a956adb2SHemant Agrawal if ((strcmp(iter->bus->name, "vdev") == 0) || 263a956adb2SHemant Agrawal (strcmp(iter->bus->name, "fslmc") == 0) || 264a956adb2SHemant Agrawal (strcmp(iter->bus->name, "dpaa_bus") == 0)) { 26599a2dd95SBruce Richardson bus_param_key = "name"; 26699a2dd95SBruce Richardson } else if (strcmp(iter->bus->name, "pci") == 0) { 26799a2dd95SBruce Richardson bus_param_key = "addr"; 26899a2dd95SBruce Richardson } else { 26999a2dd95SBruce Richardson ret = -ENOTSUP; 27099a2dd95SBruce Richardson goto error; 27199a2dd95SBruce Richardson } 27299a2dd95SBruce Richardson str_size = strlen(bus_param_key) + strlen(devargs.name) + 2; 27399a2dd95SBruce Richardson bus_str = malloc(str_size); 27499a2dd95SBruce Richardson if (bus_str == NULL) { 27599a2dd95SBruce Richardson ret = -ENOMEM; 27699a2dd95SBruce Richardson goto error; 27799a2dd95SBruce Richardson } 27899a2dd95SBruce Richardson ret = snprintf(bus_str, str_size, "%s=%s", 27999a2dd95SBruce Richardson bus_param_key, devargs.name); 28099a2dd95SBruce Richardson if (ret != str_size - 1) { 28199a2dd95SBruce Richardson ret = -EINVAL; 28299a2dd95SBruce Richardson goto error; 28399a2dd95SBruce Richardson } 28499a2dd95SBruce Richardson iter->bus_str = bus_str; 28599a2dd95SBruce Richardson 28699a2dd95SBruce Richardson end: 28799a2dd95SBruce Richardson iter->cls = rte_class_find_by_name("eth"); 28899a2dd95SBruce Richardson rte_devargs_reset(&devargs); 28999a2dd95SBruce Richardson return 0; 29099a2dd95SBruce Richardson 29199a2dd95SBruce Richardson error: 29299a2dd95SBruce Richardson if (ret == -ENOTSUP) 29399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n", 29499a2dd95SBruce Richardson iter->bus->name); 29599a2dd95SBruce Richardson rte_devargs_reset(&devargs); 29699a2dd95SBruce Richardson free(bus_str); 29799a2dd95SBruce Richardson free(cls_str); 29899a2dd95SBruce Richardson return ret; 29999a2dd95SBruce Richardson } 30099a2dd95SBruce Richardson 30199a2dd95SBruce Richardson uint16_t 30299a2dd95SBruce Richardson rte_eth_iterator_next(struct rte_dev_iterator *iter) 30399a2dd95SBruce Richardson { 30453ef1b34SMin Hu (Connor) if (iter == NULL) { 30553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 30653ef1b34SMin Hu (Connor) "Cannot get next device from NULL iterator\n"); 30753ef1b34SMin Hu (Connor) return RTE_MAX_ETHPORTS; 30853ef1b34SMin Hu (Connor) } 30953ef1b34SMin Hu (Connor) 31099a2dd95SBruce Richardson if (iter->cls == NULL) /* invalid ethdev iterator */ 31199a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 31299a2dd95SBruce Richardson 31399a2dd95SBruce Richardson do { /* loop to try all matching rte_device */ 31499a2dd95SBruce Richardson /* If not pure ethdev filter and */ 31599a2dd95SBruce Richardson if (iter->bus != NULL && 31699a2dd95SBruce Richardson /* not in middle of rte_eth_dev iteration, */ 31799a2dd95SBruce Richardson iter->class_device == NULL) { 31899a2dd95SBruce Richardson /* get next rte_device to try. */ 31999a2dd95SBruce Richardson iter->device = iter->bus->dev_iterate( 32099a2dd95SBruce Richardson iter->device, iter->bus_str, iter); 32199a2dd95SBruce Richardson if (iter->device == NULL) 32299a2dd95SBruce Richardson break; /* no more rte_device candidate */ 32399a2dd95SBruce Richardson } 32499a2dd95SBruce Richardson /* A device is matching bus part, need to check ethdev part. */ 32599a2dd95SBruce Richardson iter->class_device = iter->cls->dev_iterate( 32699a2dd95SBruce Richardson iter->class_device, iter->cls_str, iter); 32799a2dd95SBruce Richardson if (iter->class_device != NULL) 32899a2dd95SBruce Richardson return eth_dev_to_id(iter->class_device); /* match */ 32999a2dd95SBruce Richardson } while (iter->bus != NULL); /* need to try next rte_device */ 33099a2dd95SBruce Richardson 33199a2dd95SBruce Richardson /* No more ethdev port to iterate. */ 33299a2dd95SBruce Richardson rte_eth_iterator_cleanup(iter); 33399a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 33499a2dd95SBruce Richardson } 33599a2dd95SBruce Richardson 33699a2dd95SBruce Richardson void 33799a2dd95SBruce Richardson rte_eth_iterator_cleanup(struct rte_dev_iterator *iter) 33899a2dd95SBruce Richardson { 33953ef1b34SMin Hu (Connor) if (iter == NULL) { 34053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot do clean up from NULL iterator\n"); 34153ef1b34SMin Hu (Connor) return; 34253ef1b34SMin Hu (Connor) } 34353ef1b34SMin Hu (Connor) 34499a2dd95SBruce Richardson if (iter->bus_str == NULL) 34599a2dd95SBruce Richardson return; /* nothing to free in pure class filter */ 34699a2dd95SBruce Richardson free(RTE_CAST_FIELD(iter, bus_str, char *)); /* workaround const */ 34799a2dd95SBruce Richardson free(RTE_CAST_FIELD(iter, cls_str, char *)); /* workaround const */ 34899a2dd95SBruce Richardson memset(iter, 0, sizeof(*iter)); 34999a2dd95SBruce Richardson } 35099a2dd95SBruce Richardson 35199a2dd95SBruce Richardson uint16_t 35299a2dd95SBruce Richardson rte_eth_find_next(uint16_t port_id) 35399a2dd95SBruce Richardson { 35499a2dd95SBruce Richardson while (port_id < RTE_MAX_ETHPORTS && 35599a2dd95SBruce Richardson rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED) 35699a2dd95SBruce Richardson port_id++; 35799a2dd95SBruce Richardson 35899a2dd95SBruce Richardson if (port_id >= RTE_MAX_ETHPORTS) 35999a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 36099a2dd95SBruce Richardson 36199a2dd95SBruce Richardson return port_id; 36299a2dd95SBruce Richardson } 36399a2dd95SBruce Richardson 36499a2dd95SBruce Richardson /* 36599a2dd95SBruce Richardson * Macro to iterate over all valid ports for internal usage. 36699a2dd95SBruce Richardson * Note: RTE_ETH_FOREACH_DEV is different because filtering owned ports. 36799a2dd95SBruce Richardson */ 36899a2dd95SBruce Richardson #define RTE_ETH_FOREACH_VALID_DEV(port_id) \ 36999a2dd95SBruce Richardson for (port_id = rte_eth_find_next(0); \ 37099a2dd95SBruce Richardson port_id < RTE_MAX_ETHPORTS; \ 37199a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id + 1)) 37299a2dd95SBruce Richardson 37399a2dd95SBruce Richardson uint16_t 37499a2dd95SBruce Richardson rte_eth_find_next_of(uint16_t port_id, const struct rte_device *parent) 37599a2dd95SBruce Richardson { 37699a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id); 37799a2dd95SBruce Richardson while (port_id < RTE_MAX_ETHPORTS && 37899a2dd95SBruce Richardson rte_eth_devices[port_id].device != parent) 37999a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id + 1); 38099a2dd95SBruce Richardson 38199a2dd95SBruce Richardson return port_id; 38299a2dd95SBruce Richardson } 38399a2dd95SBruce Richardson 38499a2dd95SBruce Richardson uint16_t 38599a2dd95SBruce Richardson rte_eth_find_next_sibling(uint16_t port_id, uint16_t ref_port_id) 38699a2dd95SBruce Richardson { 38799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(ref_port_id, RTE_MAX_ETHPORTS); 38899a2dd95SBruce Richardson return rte_eth_find_next_of(port_id, 38999a2dd95SBruce Richardson rte_eth_devices[ref_port_id].device); 39099a2dd95SBruce Richardson } 39199a2dd95SBruce Richardson 39299a2dd95SBruce Richardson static void 39399a2dd95SBruce Richardson eth_dev_shared_data_prepare(void) 39499a2dd95SBruce Richardson { 39599a2dd95SBruce Richardson const unsigned flags = 0; 39699a2dd95SBruce Richardson const struct rte_memzone *mz; 39799a2dd95SBruce Richardson 39899a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data_lock); 39999a2dd95SBruce Richardson 40099a2dd95SBruce Richardson if (eth_dev_shared_data == NULL) { 40199a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 40299a2dd95SBruce Richardson /* Allocate port data and ownership shared memory. */ 40399a2dd95SBruce Richardson mz = rte_memzone_reserve(MZ_RTE_ETH_DEV_DATA, 40499a2dd95SBruce Richardson sizeof(*eth_dev_shared_data), 40599a2dd95SBruce Richardson rte_socket_id(), flags); 40699a2dd95SBruce Richardson } else 40799a2dd95SBruce Richardson mz = rte_memzone_lookup(MZ_RTE_ETH_DEV_DATA); 40899a2dd95SBruce Richardson if (mz == NULL) 40999a2dd95SBruce Richardson rte_panic("Cannot allocate ethdev shared data\n"); 41099a2dd95SBruce Richardson 41199a2dd95SBruce Richardson eth_dev_shared_data = mz->addr; 41299a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 41399a2dd95SBruce Richardson eth_dev_shared_data->next_owner_id = 41499a2dd95SBruce Richardson RTE_ETH_DEV_NO_OWNER + 1; 41599a2dd95SBruce Richardson rte_spinlock_init(ð_dev_shared_data->ownership_lock); 41699a2dd95SBruce Richardson memset(eth_dev_shared_data->data, 0, 41799a2dd95SBruce Richardson sizeof(eth_dev_shared_data->data)); 41899a2dd95SBruce Richardson } 41999a2dd95SBruce Richardson } 42099a2dd95SBruce Richardson 42199a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data_lock); 42299a2dd95SBruce Richardson } 42399a2dd95SBruce Richardson 42499a2dd95SBruce Richardson static bool 42599a2dd95SBruce Richardson eth_dev_is_allocated(const struct rte_eth_dev *ethdev) 42699a2dd95SBruce Richardson { 42799a2dd95SBruce Richardson return ethdev->data->name[0] != '\0'; 42899a2dd95SBruce Richardson } 42999a2dd95SBruce Richardson 43099a2dd95SBruce Richardson static struct rte_eth_dev * 43199a2dd95SBruce Richardson eth_dev_allocated(const char *name) 43299a2dd95SBruce Richardson { 43399a2dd95SBruce Richardson uint16_t i; 43499a2dd95SBruce Richardson 43599a2dd95SBruce Richardson RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX); 43699a2dd95SBruce Richardson 43799a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 43899a2dd95SBruce Richardson if (rte_eth_devices[i].data != NULL && 43999a2dd95SBruce Richardson strcmp(rte_eth_devices[i].data->name, name) == 0) 44099a2dd95SBruce Richardson return &rte_eth_devices[i]; 44199a2dd95SBruce Richardson } 44299a2dd95SBruce Richardson return NULL; 44399a2dd95SBruce Richardson } 44499a2dd95SBruce Richardson 44599a2dd95SBruce Richardson struct rte_eth_dev * 44699a2dd95SBruce Richardson rte_eth_dev_allocated(const char *name) 44799a2dd95SBruce Richardson { 44899a2dd95SBruce Richardson struct rte_eth_dev *ethdev; 44999a2dd95SBruce Richardson 45099a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 45199a2dd95SBruce Richardson 45299a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 45399a2dd95SBruce Richardson 45499a2dd95SBruce Richardson ethdev = eth_dev_allocated(name); 45599a2dd95SBruce Richardson 45699a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 45799a2dd95SBruce Richardson 45899a2dd95SBruce Richardson return ethdev; 45999a2dd95SBruce Richardson } 46099a2dd95SBruce Richardson 46199a2dd95SBruce Richardson static uint16_t 46299a2dd95SBruce Richardson eth_dev_find_free_port(void) 46399a2dd95SBruce Richardson { 46499a2dd95SBruce Richardson uint16_t i; 46599a2dd95SBruce Richardson 46699a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 46799a2dd95SBruce Richardson /* Using shared name field to find a free port. */ 46899a2dd95SBruce Richardson if (eth_dev_shared_data->data[i].name[0] == '\0') { 46999a2dd95SBruce Richardson RTE_ASSERT(rte_eth_devices[i].state == 47099a2dd95SBruce Richardson RTE_ETH_DEV_UNUSED); 47199a2dd95SBruce Richardson return i; 47299a2dd95SBruce Richardson } 47399a2dd95SBruce Richardson } 47499a2dd95SBruce Richardson return RTE_MAX_ETHPORTS; 47599a2dd95SBruce Richardson } 47699a2dd95SBruce Richardson 47799a2dd95SBruce Richardson static struct rte_eth_dev * 47899a2dd95SBruce Richardson eth_dev_get(uint16_t port_id) 47999a2dd95SBruce Richardson { 48099a2dd95SBruce Richardson struct rte_eth_dev *eth_dev = &rte_eth_devices[port_id]; 48199a2dd95SBruce Richardson 48299a2dd95SBruce Richardson eth_dev->data = ð_dev_shared_data->data[port_id]; 48399a2dd95SBruce Richardson 48499a2dd95SBruce Richardson return eth_dev; 48599a2dd95SBruce Richardson } 48699a2dd95SBruce Richardson 48799a2dd95SBruce Richardson struct rte_eth_dev * 48899a2dd95SBruce Richardson rte_eth_dev_allocate(const char *name) 48999a2dd95SBruce Richardson { 49099a2dd95SBruce Richardson uint16_t port_id; 49199a2dd95SBruce Richardson struct rte_eth_dev *eth_dev = NULL; 49299a2dd95SBruce Richardson size_t name_len; 49399a2dd95SBruce Richardson 49499a2dd95SBruce Richardson name_len = strnlen(name, RTE_ETH_NAME_MAX_LEN); 49599a2dd95SBruce Richardson if (name_len == 0) { 49699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Zero length Ethernet device name\n"); 49799a2dd95SBruce Richardson return NULL; 49899a2dd95SBruce Richardson } 49999a2dd95SBruce Richardson 50099a2dd95SBruce Richardson if (name_len >= RTE_ETH_NAME_MAX_LEN) { 50199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethernet device name is too long\n"); 50299a2dd95SBruce Richardson return NULL; 50399a2dd95SBruce Richardson } 50499a2dd95SBruce Richardson 50599a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 50699a2dd95SBruce Richardson 50799a2dd95SBruce Richardson /* Synchronize port creation between primary and secondary threads. */ 50899a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 50999a2dd95SBruce Richardson 51099a2dd95SBruce Richardson if (eth_dev_allocated(name) != NULL) { 51199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 51299a2dd95SBruce Richardson "Ethernet device with name %s already allocated\n", 51399a2dd95SBruce Richardson name); 51499a2dd95SBruce Richardson goto unlock; 51599a2dd95SBruce Richardson } 51699a2dd95SBruce Richardson 51799a2dd95SBruce Richardson port_id = eth_dev_find_free_port(); 51899a2dd95SBruce Richardson if (port_id == RTE_MAX_ETHPORTS) { 51999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 52099a2dd95SBruce Richardson "Reached maximum number of Ethernet ports\n"); 52199a2dd95SBruce Richardson goto unlock; 52299a2dd95SBruce Richardson } 52399a2dd95SBruce Richardson 52499a2dd95SBruce Richardson eth_dev = eth_dev_get(port_id); 52599a2dd95SBruce Richardson strlcpy(eth_dev->data->name, name, sizeof(eth_dev->data->name)); 52699a2dd95SBruce Richardson eth_dev->data->port_id = port_id; 527ff4e52efSViacheslav Galaktionov eth_dev->data->backer_port_id = RTE_MAX_ETHPORTS; 52899a2dd95SBruce Richardson eth_dev->data->mtu = RTE_ETHER_MTU; 52999a2dd95SBruce Richardson pthread_mutex_init(ð_dev->data->flow_ops_mutex, NULL); 53099a2dd95SBruce Richardson 53199a2dd95SBruce Richardson unlock: 53299a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 53399a2dd95SBruce Richardson 53499a2dd95SBruce Richardson return eth_dev; 53599a2dd95SBruce Richardson } 53699a2dd95SBruce Richardson 53799a2dd95SBruce Richardson /* 53899a2dd95SBruce Richardson * Attach to a port already registered by the primary process, which 53999a2dd95SBruce Richardson * makes sure that the same device would have the same port id both 54099a2dd95SBruce Richardson * in the primary and secondary process. 54199a2dd95SBruce Richardson */ 54299a2dd95SBruce Richardson struct rte_eth_dev * 54399a2dd95SBruce Richardson rte_eth_dev_attach_secondary(const char *name) 54499a2dd95SBruce Richardson { 54599a2dd95SBruce Richardson uint16_t i; 54699a2dd95SBruce Richardson struct rte_eth_dev *eth_dev = NULL; 54799a2dd95SBruce Richardson 54899a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 54999a2dd95SBruce Richardson 55099a2dd95SBruce Richardson /* Synchronize port attachment to primary port creation and release. */ 55199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 55299a2dd95SBruce Richardson 55399a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 55499a2dd95SBruce Richardson if (strcmp(eth_dev_shared_data->data[i].name, name) == 0) 55599a2dd95SBruce Richardson break; 55699a2dd95SBruce Richardson } 55799a2dd95SBruce Richardson if (i == RTE_MAX_ETHPORTS) { 55899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 55999a2dd95SBruce Richardson "Device %s is not driven by the primary process\n", 56099a2dd95SBruce Richardson name); 56199a2dd95SBruce Richardson } else { 56299a2dd95SBruce Richardson eth_dev = eth_dev_get(i); 56399a2dd95SBruce Richardson RTE_ASSERT(eth_dev->data->port_id == i); 56499a2dd95SBruce Richardson } 56599a2dd95SBruce Richardson 56699a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 56799a2dd95SBruce Richardson return eth_dev; 56899a2dd95SBruce Richardson } 56999a2dd95SBruce Richardson 57099a2dd95SBruce Richardson int 57199a2dd95SBruce Richardson rte_eth_dev_release_port(struct rte_eth_dev *eth_dev) 57299a2dd95SBruce Richardson { 57399a2dd95SBruce Richardson if (eth_dev == NULL) 57499a2dd95SBruce Richardson return -EINVAL; 57599a2dd95SBruce Richardson 57699a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 57799a2dd95SBruce Richardson 57899a2dd95SBruce Richardson if (eth_dev->state != RTE_ETH_DEV_UNUSED) 57999a2dd95SBruce Richardson rte_eth_dev_callback_process(eth_dev, 58099a2dd95SBruce Richardson RTE_ETH_EVENT_DESTROY, NULL); 58199a2dd95SBruce Richardson 58299a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 58399a2dd95SBruce Richardson 58499a2dd95SBruce Richardson eth_dev->state = RTE_ETH_DEV_UNUSED; 58599a2dd95SBruce Richardson eth_dev->device = NULL; 58699a2dd95SBruce Richardson eth_dev->process_private = NULL; 58799a2dd95SBruce Richardson eth_dev->intr_handle = NULL; 58899a2dd95SBruce Richardson eth_dev->rx_pkt_burst = NULL; 58999a2dd95SBruce Richardson eth_dev->tx_pkt_burst = NULL; 59099a2dd95SBruce Richardson eth_dev->tx_pkt_prepare = NULL; 59199a2dd95SBruce Richardson eth_dev->rx_queue_count = NULL; 59299a2dd95SBruce Richardson eth_dev->rx_descriptor_status = NULL; 59399a2dd95SBruce Richardson eth_dev->tx_descriptor_status = NULL; 59499a2dd95SBruce Richardson eth_dev->dev_ops = NULL; 59599a2dd95SBruce Richardson 59699a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 59799a2dd95SBruce Richardson rte_free(eth_dev->data->rx_queues); 59899a2dd95SBruce Richardson rte_free(eth_dev->data->tx_queues); 59999a2dd95SBruce Richardson rte_free(eth_dev->data->mac_addrs); 60099a2dd95SBruce Richardson rte_free(eth_dev->data->hash_mac_addrs); 60199a2dd95SBruce Richardson rte_free(eth_dev->data->dev_private); 60299a2dd95SBruce Richardson pthread_mutex_destroy(ð_dev->data->flow_ops_mutex); 60399a2dd95SBruce Richardson memset(eth_dev->data, 0, sizeof(struct rte_eth_dev_data)); 60499a2dd95SBruce Richardson } 60599a2dd95SBruce Richardson 60699a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 60799a2dd95SBruce Richardson 60899a2dd95SBruce Richardson return 0; 60999a2dd95SBruce Richardson } 61099a2dd95SBruce Richardson 61199a2dd95SBruce Richardson int 61299a2dd95SBruce Richardson rte_eth_dev_is_valid_port(uint16_t port_id) 61399a2dd95SBruce Richardson { 61499a2dd95SBruce Richardson if (port_id >= RTE_MAX_ETHPORTS || 61599a2dd95SBruce Richardson (rte_eth_devices[port_id].state == RTE_ETH_DEV_UNUSED)) 61699a2dd95SBruce Richardson return 0; 61799a2dd95SBruce Richardson else 61899a2dd95SBruce Richardson return 1; 61999a2dd95SBruce Richardson } 62099a2dd95SBruce Richardson 62199a2dd95SBruce Richardson static int 62299a2dd95SBruce Richardson eth_is_valid_owner_id(uint64_t owner_id) 62399a2dd95SBruce Richardson { 62499a2dd95SBruce Richardson if (owner_id == RTE_ETH_DEV_NO_OWNER || 62599a2dd95SBruce Richardson eth_dev_shared_data->next_owner_id <= owner_id) 62699a2dd95SBruce Richardson return 0; 62799a2dd95SBruce Richardson return 1; 62899a2dd95SBruce Richardson } 62999a2dd95SBruce Richardson 63099a2dd95SBruce Richardson uint64_t 63199a2dd95SBruce Richardson rte_eth_find_next_owned_by(uint16_t port_id, const uint64_t owner_id) 63299a2dd95SBruce Richardson { 63399a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id); 63499a2dd95SBruce Richardson while (port_id < RTE_MAX_ETHPORTS && 63599a2dd95SBruce Richardson rte_eth_devices[port_id].data->owner.id != owner_id) 63699a2dd95SBruce Richardson port_id = rte_eth_find_next(port_id + 1); 63799a2dd95SBruce Richardson 63899a2dd95SBruce Richardson return port_id; 63999a2dd95SBruce Richardson } 64099a2dd95SBruce Richardson 64199a2dd95SBruce Richardson int 64299a2dd95SBruce Richardson rte_eth_dev_owner_new(uint64_t *owner_id) 64399a2dd95SBruce Richardson { 64453ef1b34SMin Hu (Connor) if (owner_id == NULL) { 64553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get new owner ID to NULL\n"); 64653ef1b34SMin Hu (Connor) return -EINVAL; 64753ef1b34SMin Hu (Connor) } 64853ef1b34SMin Hu (Connor) 64999a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 65099a2dd95SBruce Richardson 65199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 65299a2dd95SBruce Richardson 65399a2dd95SBruce Richardson *owner_id = eth_dev_shared_data->next_owner_id++; 65499a2dd95SBruce Richardson 65599a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 65699a2dd95SBruce Richardson return 0; 65799a2dd95SBruce Richardson } 65899a2dd95SBruce Richardson 65999a2dd95SBruce Richardson static int 66099a2dd95SBruce Richardson eth_dev_owner_set(const uint16_t port_id, const uint64_t old_owner_id, 66199a2dd95SBruce Richardson const struct rte_eth_dev_owner *new_owner) 66299a2dd95SBruce Richardson { 66399a2dd95SBruce Richardson struct rte_eth_dev *ethdev = &rte_eth_devices[port_id]; 66499a2dd95SBruce Richardson struct rte_eth_dev_owner *port_owner; 66599a2dd95SBruce Richardson 66699a2dd95SBruce Richardson if (port_id >= RTE_MAX_ETHPORTS || !eth_dev_is_allocated(ethdev)) { 66799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n", 66899a2dd95SBruce Richardson port_id); 66999a2dd95SBruce Richardson return -ENODEV; 67099a2dd95SBruce Richardson } 67199a2dd95SBruce Richardson 67253ef1b34SMin Hu (Connor) if (new_owner == NULL) { 67353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 67453ef1b34SMin Hu (Connor) "Cannot set ethdev port %u owner from NULL owner\n", 67553ef1b34SMin Hu (Connor) port_id); 67653ef1b34SMin Hu (Connor) return -EINVAL; 67753ef1b34SMin Hu (Connor) } 67853ef1b34SMin Hu (Connor) 67999a2dd95SBruce Richardson if (!eth_is_valid_owner_id(new_owner->id) && 68099a2dd95SBruce Richardson !eth_is_valid_owner_id(old_owner_id)) { 68199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 68299a2dd95SBruce Richardson "Invalid owner old_id=%016"PRIx64" new_id=%016"PRIx64"\n", 68399a2dd95SBruce Richardson old_owner_id, new_owner->id); 68499a2dd95SBruce Richardson return -EINVAL; 68599a2dd95SBruce Richardson } 68699a2dd95SBruce Richardson 68799a2dd95SBruce Richardson port_owner = &rte_eth_devices[port_id].data->owner; 68899a2dd95SBruce Richardson if (port_owner->id != old_owner_id) { 68999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 69099a2dd95SBruce Richardson "Cannot set owner to port %u already owned by %s_%016"PRIX64"\n", 69199a2dd95SBruce Richardson port_id, port_owner->name, port_owner->id); 69299a2dd95SBruce Richardson return -EPERM; 69399a2dd95SBruce Richardson } 69499a2dd95SBruce Richardson 69599a2dd95SBruce Richardson /* can not truncate (same structure) */ 69699a2dd95SBruce Richardson strlcpy(port_owner->name, new_owner->name, RTE_ETH_MAX_OWNER_NAME_LEN); 69799a2dd95SBruce Richardson 69899a2dd95SBruce Richardson port_owner->id = new_owner->id; 69999a2dd95SBruce Richardson 70099a2dd95SBruce Richardson RTE_ETHDEV_LOG(DEBUG, "Port %u owner is %s_%016"PRIx64"\n", 70199a2dd95SBruce Richardson port_id, new_owner->name, new_owner->id); 70299a2dd95SBruce Richardson 70399a2dd95SBruce Richardson return 0; 70499a2dd95SBruce Richardson } 70599a2dd95SBruce Richardson 70699a2dd95SBruce Richardson int 70799a2dd95SBruce Richardson rte_eth_dev_owner_set(const uint16_t port_id, 70899a2dd95SBruce Richardson const struct rte_eth_dev_owner *owner) 70999a2dd95SBruce Richardson { 71099a2dd95SBruce Richardson int ret; 71199a2dd95SBruce Richardson 71299a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 71399a2dd95SBruce Richardson 71499a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 71599a2dd95SBruce Richardson 71699a2dd95SBruce Richardson ret = eth_dev_owner_set(port_id, RTE_ETH_DEV_NO_OWNER, owner); 71799a2dd95SBruce Richardson 71899a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 71999a2dd95SBruce Richardson return ret; 72099a2dd95SBruce Richardson } 72199a2dd95SBruce Richardson 72299a2dd95SBruce Richardson int 72399a2dd95SBruce Richardson rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id) 72499a2dd95SBruce Richardson { 72599a2dd95SBruce Richardson const struct rte_eth_dev_owner new_owner = (struct rte_eth_dev_owner) 72699a2dd95SBruce Richardson {.id = RTE_ETH_DEV_NO_OWNER, .name = ""}; 72799a2dd95SBruce Richardson int ret; 72899a2dd95SBruce Richardson 72999a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 73099a2dd95SBruce Richardson 73199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 73299a2dd95SBruce Richardson 73399a2dd95SBruce Richardson ret = eth_dev_owner_set(port_id, owner_id, &new_owner); 73499a2dd95SBruce Richardson 73599a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 73699a2dd95SBruce Richardson return ret; 73799a2dd95SBruce Richardson } 73899a2dd95SBruce Richardson 73999a2dd95SBruce Richardson int 74099a2dd95SBruce Richardson rte_eth_dev_owner_delete(const uint64_t owner_id) 74199a2dd95SBruce Richardson { 74299a2dd95SBruce Richardson uint16_t port_id; 74399a2dd95SBruce Richardson int ret = 0; 74499a2dd95SBruce Richardson 74599a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 74699a2dd95SBruce Richardson 74799a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 74899a2dd95SBruce Richardson 74999a2dd95SBruce Richardson if (eth_is_valid_owner_id(owner_id)) { 75099a2dd95SBruce Richardson for (port_id = 0; port_id < RTE_MAX_ETHPORTS; port_id++) 75199a2dd95SBruce Richardson if (rte_eth_devices[port_id].data->owner.id == owner_id) 75299a2dd95SBruce Richardson memset(&rte_eth_devices[port_id].data->owner, 0, 75399a2dd95SBruce Richardson sizeof(struct rte_eth_dev_owner)); 75499a2dd95SBruce Richardson RTE_ETHDEV_LOG(NOTICE, 75599a2dd95SBruce Richardson "All port owners owned by %016"PRIx64" identifier have removed\n", 75699a2dd95SBruce Richardson owner_id); 75799a2dd95SBruce Richardson } else { 75899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 75999a2dd95SBruce Richardson "Invalid owner id=%016"PRIx64"\n", 76099a2dd95SBruce Richardson owner_id); 76199a2dd95SBruce Richardson ret = -EINVAL; 76299a2dd95SBruce Richardson } 76399a2dd95SBruce Richardson 76499a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 76599a2dd95SBruce Richardson 76699a2dd95SBruce Richardson return ret; 76799a2dd95SBruce Richardson } 76899a2dd95SBruce Richardson 76999a2dd95SBruce Richardson int 77099a2dd95SBruce Richardson rte_eth_dev_owner_get(const uint16_t port_id, struct rte_eth_dev_owner *owner) 77199a2dd95SBruce Richardson { 77253ef1b34SMin Hu (Connor) struct rte_eth_dev *ethdev; 77353ef1b34SMin Hu (Connor) 77453ef1b34SMin Hu (Connor) RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 77553ef1b34SMin Hu (Connor) ethdev = &rte_eth_devices[port_id]; 77653ef1b34SMin Hu (Connor) 77753ef1b34SMin Hu (Connor) if (!eth_dev_is_allocated(ethdev)) { 77853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Port id %"PRIu16" is not allocated\n", 77953ef1b34SMin Hu (Connor) port_id); 78053ef1b34SMin Hu (Connor) return -ENODEV; 78153ef1b34SMin Hu (Connor) } 78253ef1b34SMin Hu (Connor) 78353ef1b34SMin Hu (Connor) if (owner == NULL) { 78453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u owner to NULL\n", 78553ef1b34SMin Hu (Connor) port_id); 78653ef1b34SMin Hu (Connor) return -EINVAL; 78753ef1b34SMin Hu (Connor) } 78899a2dd95SBruce Richardson 78999a2dd95SBruce Richardson eth_dev_shared_data_prepare(); 79099a2dd95SBruce Richardson 79199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_shared_data->ownership_lock); 79299a2dd95SBruce Richardson rte_memcpy(owner, ðdev->data->owner, sizeof(*owner)); 79399a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_shared_data->ownership_lock); 79453ef1b34SMin Hu (Connor) 79553ef1b34SMin Hu (Connor) return 0; 79699a2dd95SBruce Richardson } 79799a2dd95SBruce Richardson 79899a2dd95SBruce Richardson int 79999a2dd95SBruce Richardson rte_eth_dev_socket_id(uint16_t port_id) 80099a2dd95SBruce Richardson { 80199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); 80299a2dd95SBruce Richardson return rte_eth_devices[port_id].data->numa_node; 80399a2dd95SBruce Richardson } 80499a2dd95SBruce Richardson 80599a2dd95SBruce Richardson void * 80699a2dd95SBruce Richardson rte_eth_dev_get_sec_ctx(uint16_t port_id) 80799a2dd95SBruce Richardson { 80899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, NULL); 80999a2dd95SBruce Richardson return rte_eth_devices[port_id].security_ctx; 81099a2dd95SBruce Richardson } 81199a2dd95SBruce Richardson 81299a2dd95SBruce Richardson uint16_t 81399a2dd95SBruce Richardson rte_eth_dev_count_avail(void) 81499a2dd95SBruce Richardson { 81599a2dd95SBruce Richardson uint16_t p; 81699a2dd95SBruce Richardson uint16_t count; 81799a2dd95SBruce Richardson 81899a2dd95SBruce Richardson count = 0; 81999a2dd95SBruce Richardson 82099a2dd95SBruce Richardson RTE_ETH_FOREACH_DEV(p) 82199a2dd95SBruce Richardson count++; 82299a2dd95SBruce Richardson 82399a2dd95SBruce Richardson return count; 82499a2dd95SBruce Richardson } 82599a2dd95SBruce Richardson 82699a2dd95SBruce Richardson uint16_t 82799a2dd95SBruce Richardson rte_eth_dev_count_total(void) 82899a2dd95SBruce Richardson { 82999a2dd95SBruce Richardson uint16_t port, count = 0; 83099a2dd95SBruce Richardson 83199a2dd95SBruce Richardson RTE_ETH_FOREACH_VALID_DEV(port) 83299a2dd95SBruce Richardson count++; 83399a2dd95SBruce Richardson 83499a2dd95SBruce Richardson return count; 83599a2dd95SBruce Richardson } 83699a2dd95SBruce Richardson 83799a2dd95SBruce Richardson int 83899a2dd95SBruce Richardson rte_eth_dev_get_name_by_port(uint16_t port_id, char *name) 83999a2dd95SBruce Richardson { 84099a2dd95SBruce Richardson char *tmp; 84199a2dd95SBruce Richardson 84299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 84399a2dd95SBruce Richardson 84499a2dd95SBruce Richardson if (name == NULL) { 84553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u name to NULL\n", 84653ef1b34SMin Hu (Connor) port_id); 84799a2dd95SBruce Richardson return -EINVAL; 84899a2dd95SBruce Richardson } 84999a2dd95SBruce Richardson 85099a2dd95SBruce Richardson /* shouldn't check 'rte_eth_devices[i].data', 85199a2dd95SBruce Richardson * because it might be overwritten by VDEV PMD */ 85299a2dd95SBruce Richardson tmp = eth_dev_shared_data->data[port_id].name; 85399a2dd95SBruce Richardson strcpy(name, tmp); 85499a2dd95SBruce Richardson return 0; 85599a2dd95SBruce Richardson } 85699a2dd95SBruce Richardson 85799a2dd95SBruce Richardson int 85899a2dd95SBruce Richardson rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id) 85999a2dd95SBruce Richardson { 86099a2dd95SBruce Richardson uint16_t pid; 86199a2dd95SBruce Richardson 86299a2dd95SBruce Richardson if (name == NULL) { 86353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get port ID from NULL name"); 86453ef1b34SMin Hu (Connor) return -EINVAL; 86553ef1b34SMin Hu (Connor) } 86653ef1b34SMin Hu (Connor) 86753ef1b34SMin Hu (Connor) if (port_id == NULL) { 86853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 86953ef1b34SMin Hu (Connor) "Cannot get port ID to NULL for %s\n", name); 87099a2dd95SBruce Richardson return -EINVAL; 87199a2dd95SBruce Richardson } 87299a2dd95SBruce Richardson 87399a2dd95SBruce Richardson RTE_ETH_FOREACH_VALID_DEV(pid) 87499a2dd95SBruce Richardson if (!strcmp(name, eth_dev_shared_data->data[pid].name)) { 87599a2dd95SBruce Richardson *port_id = pid; 87699a2dd95SBruce Richardson return 0; 87799a2dd95SBruce Richardson } 87899a2dd95SBruce Richardson 87999a2dd95SBruce Richardson return -ENODEV; 88099a2dd95SBruce Richardson } 88199a2dd95SBruce Richardson 88299a2dd95SBruce Richardson static int 88399a2dd95SBruce Richardson eth_err(uint16_t port_id, int ret) 88499a2dd95SBruce Richardson { 88599a2dd95SBruce Richardson if (ret == 0) 88699a2dd95SBruce Richardson return 0; 88799a2dd95SBruce Richardson if (rte_eth_dev_is_removed(port_id)) 88899a2dd95SBruce Richardson return -EIO; 88999a2dd95SBruce Richardson return ret; 89099a2dd95SBruce Richardson } 89199a2dd95SBruce Richardson 89249ed3224SXueming Li static void 89349ed3224SXueming Li eth_dev_rxq_release(struct rte_eth_dev *dev, uint16_t qid) 89449ed3224SXueming Li { 89549ed3224SXueming Li void **rxq = dev->data->rx_queues; 89649ed3224SXueming Li 89749ed3224SXueming Li if (rxq[qid] == NULL) 89849ed3224SXueming Li return; 89949ed3224SXueming Li 90049ed3224SXueming Li if (dev->dev_ops->rx_queue_release != NULL) 9017483341aSXueming Li (*dev->dev_ops->rx_queue_release)(dev, qid); 90249ed3224SXueming Li rxq[qid] = NULL; 90349ed3224SXueming Li } 90449ed3224SXueming Li 90549ed3224SXueming Li static void 90649ed3224SXueming Li eth_dev_txq_release(struct rte_eth_dev *dev, uint16_t qid) 90749ed3224SXueming Li { 90849ed3224SXueming Li void **txq = dev->data->tx_queues; 90949ed3224SXueming Li 91049ed3224SXueming Li if (txq[qid] == NULL) 91149ed3224SXueming Li return; 91249ed3224SXueming Li 91349ed3224SXueming Li if (dev->dev_ops->tx_queue_release != NULL) 9147483341aSXueming Li (*dev->dev_ops->tx_queue_release)(dev, qid); 91549ed3224SXueming Li txq[qid] = NULL; 91649ed3224SXueming Li } 91749ed3224SXueming Li 91899a2dd95SBruce Richardson static int 91999a2dd95SBruce Richardson eth_dev_rx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) 92099a2dd95SBruce Richardson { 92199a2dd95SBruce Richardson uint16_t old_nb_queues = dev->data->nb_rx_queues; 92299a2dd95SBruce Richardson unsigned i; 92399a2dd95SBruce Richardson 92499a2dd95SBruce Richardson if (dev->data->rx_queues == NULL && nb_queues != 0) { /* first time configuration */ 92599a2dd95SBruce Richardson dev->data->rx_queues = rte_zmalloc("ethdev->rx_queues", 926*c024496aSKonstantin Ananyev sizeof(dev->data->rx_queues[0]) * 927*c024496aSKonstantin Ananyev RTE_MAX_QUEUES_PER_PORT, 92899a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE); 92999a2dd95SBruce Richardson if (dev->data->rx_queues == NULL) { 93099a2dd95SBruce Richardson dev->data->nb_rx_queues = 0; 93199a2dd95SBruce Richardson return -(ENOMEM); 93299a2dd95SBruce Richardson } 93399a2dd95SBruce Richardson } else if (dev->data->rx_queues != NULL && nb_queues != 0) { /* re-configure */ 93449ed3224SXueming Li for (i = nb_queues; i < old_nb_queues; i++) 93549ed3224SXueming Li eth_dev_rxq_release(dev, i); 93699a2dd95SBruce Richardson 93799a2dd95SBruce Richardson } else if (dev->data->rx_queues != NULL && nb_queues == 0) { 93899a2dd95SBruce Richardson for (i = nb_queues; i < old_nb_queues; i++) 93949ed3224SXueming Li eth_dev_rxq_release(dev, i); 94099a2dd95SBruce Richardson 94199a2dd95SBruce Richardson rte_free(dev->data->rx_queues); 94299a2dd95SBruce Richardson dev->data->rx_queues = NULL; 94399a2dd95SBruce Richardson } 94499a2dd95SBruce Richardson dev->data->nb_rx_queues = nb_queues; 94599a2dd95SBruce Richardson return 0; 94699a2dd95SBruce Richardson } 94799a2dd95SBruce Richardson 94899a2dd95SBruce Richardson static int 94999a2dd95SBruce Richardson eth_dev_validate_rx_queue(const struct rte_eth_dev *dev, uint16_t rx_queue_id) 95099a2dd95SBruce Richardson { 95199a2dd95SBruce Richardson uint16_t port_id; 95299a2dd95SBruce Richardson 95399a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 95499a2dd95SBruce Richardson port_id = dev->data->port_id; 95599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 95699a2dd95SBruce Richardson "Invalid Rx queue_id=%u of device with port_id=%u\n", 95799a2dd95SBruce Richardson rx_queue_id, port_id); 95899a2dd95SBruce Richardson return -EINVAL; 95999a2dd95SBruce Richardson } 96099a2dd95SBruce Richardson 96199a2dd95SBruce Richardson if (dev->data->rx_queues[rx_queue_id] == NULL) { 96299a2dd95SBruce Richardson port_id = dev->data->port_id; 96399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 96499a2dd95SBruce Richardson "Queue %u of device with port_id=%u has not been setup\n", 96599a2dd95SBruce Richardson rx_queue_id, port_id); 96699a2dd95SBruce Richardson return -EINVAL; 96799a2dd95SBruce Richardson } 96899a2dd95SBruce Richardson 96999a2dd95SBruce Richardson return 0; 97099a2dd95SBruce Richardson } 97199a2dd95SBruce Richardson 97299a2dd95SBruce Richardson static int 97399a2dd95SBruce Richardson eth_dev_validate_tx_queue(const struct rte_eth_dev *dev, uint16_t tx_queue_id) 97499a2dd95SBruce Richardson { 97599a2dd95SBruce Richardson uint16_t port_id; 97699a2dd95SBruce Richardson 97799a2dd95SBruce Richardson if (tx_queue_id >= dev->data->nb_tx_queues) { 97899a2dd95SBruce Richardson port_id = dev->data->port_id; 97999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 98099a2dd95SBruce Richardson "Invalid Tx queue_id=%u of device with port_id=%u\n", 98199a2dd95SBruce Richardson tx_queue_id, port_id); 98299a2dd95SBruce Richardson return -EINVAL; 98399a2dd95SBruce Richardson } 98499a2dd95SBruce Richardson 98599a2dd95SBruce Richardson if (dev->data->tx_queues[tx_queue_id] == NULL) { 98699a2dd95SBruce Richardson port_id = dev->data->port_id; 98799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 98899a2dd95SBruce Richardson "Queue %u of device with port_id=%u has not been setup\n", 98999a2dd95SBruce Richardson tx_queue_id, port_id); 99099a2dd95SBruce Richardson return -EINVAL; 99199a2dd95SBruce Richardson } 99299a2dd95SBruce Richardson 99399a2dd95SBruce Richardson return 0; 99499a2dd95SBruce Richardson } 99599a2dd95SBruce Richardson 99699a2dd95SBruce Richardson int 99799a2dd95SBruce Richardson rte_eth_dev_rx_queue_start(uint16_t port_id, uint16_t rx_queue_id) 99899a2dd95SBruce Richardson { 99999a2dd95SBruce Richardson struct rte_eth_dev *dev; 100099a2dd95SBruce Richardson int ret; 100199a2dd95SBruce Richardson 100299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 100399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 100453ef1b34SMin Hu (Connor) 100599a2dd95SBruce Richardson if (!dev->data->dev_started) { 100699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 100799a2dd95SBruce Richardson "Port %u must be started before start any queue\n", 100899a2dd95SBruce Richardson port_id); 100999a2dd95SBruce Richardson return -EINVAL; 101099a2dd95SBruce Richardson } 101199a2dd95SBruce Richardson 101299a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, rx_queue_id); 101399a2dd95SBruce Richardson if (ret != 0) 101499a2dd95SBruce Richardson return ret; 101599a2dd95SBruce Richardson 101699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_start, -ENOTSUP); 101799a2dd95SBruce Richardson 101899a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) { 101999a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 102099a2dd95SBruce Richardson "Can't start Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 102199a2dd95SBruce Richardson rx_queue_id, port_id); 102299a2dd95SBruce Richardson return -EINVAL; 102399a2dd95SBruce Richardson } 102499a2dd95SBruce Richardson 102599a2dd95SBruce Richardson if (dev->data->rx_queue_state[rx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) { 102699a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 102799a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n", 102899a2dd95SBruce Richardson rx_queue_id, port_id); 102999a2dd95SBruce Richardson return 0; 103099a2dd95SBruce Richardson } 103199a2dd95SBruce Richardson 103253ef1b34SMin Hu (Connor) return eth_err(port_id, dev->dev_ops->rx_queue_start(dev, rx_queue_id)); 103399a2dd95SBruce Richardson } 103499a2dd95SBruce Richardson 103599a2dd95SBruce Richardson int 103699a2dd95SBruce Richardson rte_eth_dev_rx_queue_stop(uint16_t port_id, uint16_t rx_queue_id) 103799a2dd95SBruce Richardson { 103899a2dd95SBruce Richardson struct rte_eth_dev *dev; 103999a2dd95SBruce Richardson int ret; 104099a2dd95SBruce Richardson 104199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 104299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 104399a2dd95SBruce Richardson 104499a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, rx_queue_id); 104599a2dd95SBruce Richardson if (ret != 0) 104699a2dd95SBruce Richardson return ret; 104799a2dd95SBruce Richardson 104899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_stop, -ENOTSUP); 104999a2dd95SBruce Richardson 105099a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, rx_queue_id)) { 105199a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 105299a2dd95SBruce Richardson "Can't stop Rx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 105399a2dd95SBruce Richardson rx_queue_id, port_id); 105499a2dd95SBruce Richardson return -EINVAL; 105599a2dd95SBruce Richardson } 105699a2dd95SBruce Richardson 105799a2dd95SBruce Richardson if (dev->data->rx_queue_state[rx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) { 105899a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 105999a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n", 106099a2dd95SBruce Richardson rx_queue_id, port_id); 106199a2dd95SBruce Richardson return 0; 106299a2dd95SBruce Richardson } 106399a2dd95SBruce Richardson 106499a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->rx_queue_stop(dev, rx_queue_id)); 106599a2dd95SBruce Richardson } 106699a2dd95SBruce Richardson 106799a2dd95SBruce Richardson int 106899a2dd95SBruce Richardson rte_eth_dev_tx_queue_start(uint16_t port_id, uint16_t tx_queue_id) 106999a2dd95SBruce Richardson { 107099a2dd95SBruce Richardson struct rte_eth_dev *dev; 107199a2dd95SBruce Richardson int ret; 107299a2dd95SBruce Richardson 107399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 107499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 107553ef1b34SMin Hu (Connor) 107699a2dd95SBruce Richardson if (!dev->data->dev_started) { 107799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 107899a2dd95SBruce Richardson "Port %u must be started before start any queue\n", 107999a2dd95SBruce Richardson port_id); 108099a2dd95SBruce Richardson return -EINVAL; 108199a2dd95SBruce Richardson } 108299a2dd95SBruce Richardson 108399a2dd95SBruce Richardson ret = eth_dev_validate_tx_queue(dev, tx_queue_id); 108499a2dd95SBruce Richardson if (ret != 0) 108599a2dd95SBruce Richardson return ret; 108699a2dd95SBruce Richardson 108799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_start, -ENOTSUP); 108899a2dd95SBruce Richardson 108999a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) { 109099a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 109199a2dd95SBruce Richardson "Can't start Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 109299a2dd95SBruce Richardson tx_queue_id, port_id); 109399a2dd95SBruce Richardson return -EINVAL; 109499a2dd95SBruce Richardson } 109599a2dd95SBruce Richardson 109699a2dd95SBruce Richardson if (dev->data->tx_queue_state[tx_queue_id] != RTE_ETH_QUEUE_STATE_STOPPED) { 109799a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 109899a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already started\n", 109999a2dd95SBruce Richardson tx_queue_id, port_id); 110099a2dd95SBruce Richardson return 0; 110199a2dd95SBruce Richardson } 110299a2dd95SBruce Richardson 110399a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->tx_queue_start(dev, tx_queue_id)); 110499a2dd95SBruce Richardson } 110599a2dd95SBruce Richardson 110699a2dd95SBruce Richardson int 110799a2dd95SBruce Richardson rte_eth_dev_tx_queue_stop(uint16_t port_id, uint16_t tx_queue_id) 110899a2dd95SBruce Richardson { 110999a2dd95SBruce Richardson struct rte_eth_dev *dev; 111099a2dd95SBruce Richardson int ret; 111199a2dd95SBruce Richardson 111299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 111399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 111499a2dd95SBruce Richardson 111599a2dd95SBruce Richardson ret = eth_dev_validate_tx_queue(dev, tx_queue_id); 111699a2dd95SBruce Richardson if (ret != 0) 111799a2dd95SBruce Richardson return ret; 111899a2dd95SBruce Richardson 111999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_stop, -ENOTSUP); 112099a2dd95SBruce Richardson 112199a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, tx_queue_id)) { 112299a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 112399a2dd95SBruce Richardson "Can't stop Tx hairpin queue %"PRIu16" of device with port_id=%"PRIu16"\n", 112499a2dd95SBruce Richardson tx_queue_id, port_id); 112599a2dd95SBruce Richardson return -EINVAL; 112699a2dd95SBruce Richardson } 112799a2dd95SBruce Richardson 112899a2dd95SBruce Richardson if (dev->data->tx_queue_state[tx_queue_id] == RTE_ETH_QUEUE_STATE_STOPPED) { 112999a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 113099a2dd95SBruce Richardson "Queue %"PRIu16" of device with port_id=%"PRIu16" already stopped\n", 113199a2dd95SBruce Richardson tx_queue_id, port_id); 113299a2dd95SBruce Richardson return 0; 113399a2dd95SBruce Richardson } 113499a2dd95SBruce Richardson 113599a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->tx_queue_stop(dev, tx_queue_id)); 113699a2dd95SBruce Richardson } 113799a2dd95SBruce Richardson 113899a2dd95SBruce Richardson static int 113999a2dd95SBruce Richardson eth_dev_tx_queue_config(struct rte_eth_dev *dev, uint16_t nb_queues) 114099a2dd95SBruce Richardson { 114199a2dd95SBruce Richardson uint16_t old_nb_queues = dev->data->nb_tx_queues; 114299a2dd95SBruce Richardson unsigned i; 114399a2dd95SBruce Richardson 114499a2dd95SBruce Richardson if (dev->data->tx_queues == NULL && nb_queues != 0) { /* first time configuration */ 114599a2dd95SBruce Richardson dev->data->tx_queues = rte_zmalloc("ethdev->tx_queues", 1146*c024496aSKonstantin Ananyev sizeof(dev->data->tx_queues[0]) * 1147*c024496aSKonstantin Ananyev RTE_MAX_QUEUES_PER_PORT, 114899a2dd95SBruce Richardson RTE_CACHE_LINE_SIZE); 114999a2dd95SBruce Richardson if (dev->data->tx_queues == NULL) { 115099a2dd95SBruce Richardson dev->data->nb_tx_queues = 0; 115199a2dd95SBruce Richardson return -(ENOMEM); 115299a2dd95SBruce Richardson } 115399a2dd95SBruce Richardson } else if (dev->data->tx_queues != NULL && nb_queues != 0) { /* re-configure */ 115449ed3224SXueming Li for (i = nb_queues; i < old_nb_queues; i++) 115549ed3224SXueming Li eth_dev_txq_release(dev, i); 115699a2dd95SBruce Richardson 115799a2dd95SBruce Richardson } else if (dev->data->tx_queues != NULL && nb_queues == 0) { 115899a2dd95SBruce Richardson for (i = nb_queues; i < old_nb_queues; i++) 115949ed3224SXueming Li eth_dev_txq_release(dev, i); 116099a2dd95SBruce Richardson 116199a2dd95SBruce Richardson rte_free(dev->data->tx_queues); 116299a2dd95SBruce Richardson dev->data->tx_queues = NULL; 116399a2dd95SBruce Richardson } 116499a2dd95SBruce Richardson dev->data->nb_tx_queues = nb_queues; 116599a2dd95SBruce Richardson return 0; 116699a2dd95SBruce Richardson } 116799a2dd95SBruce Richardson 116899a2dd95SBruce Richardson uint32_t 116999a2dd95SBruce Richardson rte_eth_speed_bitflag(uint32_t speed, int duplex) 117099a2dd95SBruce Richardson { 117199a2dd95SBruce Richardson switch (speed) { 117299a2dd95SBruce Richardson case ETH_SPEED_NUM_10M: 117399a2dd95SBruce Richardson return duplex ? ETH_LINK_SPEED_10M : ETH_LINK_SPEED_10M_HD; 117499a2dd95SBruce Richardson case ETH_SPEED_NUM_100M: 117599a2dd95SBruce Richardson return duplex ? ETH_LINK_SPEED_100M : ETH_LINK_SPEED_100M_HD; 117699a2dd95SBruce Richardson case ETH_SPEED_NUM_1G: 117799a2dd95SBruce Richardson return ETH_LINK_SPEED_1G; 117899a2dd95SBruce Richardson case ETH_SPEED_NUM_2_5G: 117999a2dd95SBruce Richardson return ETH_LINK_SPEED_2_5G; 118099a2dd95SBruce Richardson case ETH_SPEED_NUM_5G: 118199a2dd95SBruce Richardson return ETH_LINK_SPEED_5G; 118299a2dd95SBruce Richardson case ETH_SPEED_NUM_10G: 118399a2dd95SBruce Richardson return ETH_LINK_SPEED_10G; 118499a2dd95SBruce Richardson case ETH_SPEED_NUM_20G: 118599a2dd95SBruce Richardson return ETH_LINK_SPEED_20G; 118699a2dd95SBruce Richardson case ETH_SPEED_NUM_25G: 118799a2dd95SBruce Richardson return ETH_LINK_SPEED_25G; 118899a2dd95SBruce Richardson case ETH_SPEED_NUM_40G: 118999a2dd95SBruce Richardson return ETH_LINK_SPEED_40G; 119099a2dd95SBruce Richardson case ETH_SPEED_NUM_50G: 119199a2dd95SBruce Richardson return ETH_LINK_SPEED_50G; 119299a2dd95SBruce Richardson case ETH_SPEED_NUM_56G: 119399a2dd95SBruce Richardson return ETH_LINK_SPEED_56G; 119499a2dd95SBruce Richardson case ETH_SPEED_NUM_100G: 119599a2dd95SBruce Richardson return ETH_LINK_SPEED_100G; 119699a2dd95SBruce Richardson case ETH_SPEED_NUM_200G: 119799a2dd95SBruce Richardson return ETH_LINK_SPEED_200G; 119899a2dd95SBruce Richardson default: 119999a2dd95SBruce Richardson return 0; 120099a2dd95SBruce Richardson } 120199a2dd95SBruce Richardson } 120299a2dd95SBruce Richardson 120399a2dd95SBruce Richardson const char * 120499a2dd95SBruce Richardson rte_eth_dev_rx_offload_name(uint64_t offload) 120599a2dd95SBruce Richardson { 120699a2dd95SBruce Richardson const char *name = "UNKNOWN"; 120799a2dd95SBruce Richardson unsigned int i; 120899a2dd95SBruce Richardson 120999a2dd95SBruce Richardson for (i = 0; i < RTE_DIM(eth_dev_rx_offload_names); ++i) { 121099a2dd95SBruce Richardson if (offload == eth_dev_rx_offload_names[i].offload) { 121199a2dd95SBruce Richardson name = eth_dev_rx_offload_names[i].name; 121299a2dd95SBruce Richardson break; 121399a2dd95SBruce Richardson } 121499a2dd95SBruce Richardson } 121599a2dd95SBruce Richardson 121699a2dd95SBruce Richardson return name; 121799a2dd95SBruce Richardson } 121899a2dd95SBruce Richardson 121999a2dd95SBruce Richardson const char * 122099a2dd95SBruce Richardson rte_eth_dev_tx_offload_name(uint64_t offload) 122199a2dd95SBruce Richardson { 122299a2dd95SBruce Richardson const char *name = "UNKNOWN"; 122399a2dd95SBruce Richardson unsigned int i; 122499a2dd95SBruce Richardson 122599a2dd95SBruce Richardson for (i = 0; i < RTE_DIM(eth_dev_tx_offload_names); ++i) { 122699a2dd95SBruce Richardson if (offload == eth_dev_tx_offload_names[i].offload) { 122799a2dd95SBruce Richardson name = eth_dev_tx_offload_names[i].name; 122899a2dd95SBruce Richardson break; 122999a2dd95SBruce Richardson } 123099a2dd95SBruce Richardson } 123199a2dd95SBruce Richardson 123299a2dd95SBruce Richardson return name; 123399a2dd95SBruce Richardson } 123499a2dd95SBruce Richardson 123599a2dd95SBruce Richardson static inline int 123699a2dd95SBruce Richardson eth_dev_check_lro_pkt_size(uint16_t port_id, uint32_t config_size, 123799a2dd95SBruce Richardson uint32_t max_rx_pkt_len, uint32_t dev_info_size) 123899a2dd95SBruce Richardson { 123999a2dd95SBruce Richardson int ret = 0; 124099a2dd95SBruce Richardson 124199a2dd95SBruce Richardson if (dev_info_size == 0) { 124299a2dd95SBruce Richardson if (config_size != max_rx_pkt_len) { 124399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size" 124499a2dd95SBruce Richardson " %u != %u is not allowed\n", 124599a2dd95SBruce Richardson port_id, config_size, max_rx_pkt_len); 124699a2dd95SBruce Richardson ret = -EINVAL; 124799a2dd95SBruce Richardson } 124899a2dd95SBruce Richardson } else if (config_size > dev_info_size) { 124999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u " 125099a2dd95SBruce Richardson "> max allowed value %u\n", port_id, config_size, 125199a2dd95SBruce Richardson dev_info_size); 125299a2dd95SBruce Richardson ret = -EINVAL; 125399a2dd95SBruce Richardson } else if (config_size < RTE_ETHER_MIN_LEN) { 125499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%d max_lro_pkt_size %u " 125599a2dd95SBruce Richardson "< min allowed value %u\n", port_id, config_size, 125699a2dd95SBruce Richardson (unsigned int)RTE_ETHER_MIN_LEN); 125799a2dd95SBruce Richardson ret = -EINVAL; 125899a2dd95SBruce Richardson } 125999a2dd95SBruce Richardson return ret; 126099a2dd95SBruce Richardson } 126199a2dd95SBruce Richardson 126299a2dd95SBruce Richardson /* 126399a2dd95SBruce Richardson * Validate offloads that are requested through rte_eth_dev_configure against 126499a2dd95SBruce Richardson * the offloads successfully set by the ethernet device. 126599a2dd95SBruce Richardson * 126699a2dd95SBruce Richardson * @param port_id 126799a2dd95SBruce Richardson * The port identifier of the Ethernet device. 126899a2dd95SBruce Richardson * @param req_offloads 126999a2dd95SBruce Richardson * The offloads that have been requested through `rte_eth_dev_configure`. 127099a2dd95SBruce Richardson * @param set_offloads 127199a2dd95SBruce Richardson * The offloads successfully set by the ethernet device. 127299a2dd95SBruce Richardson * @param offload_type 127399a2dd95SBruce Richardson * The offload type i.e. Rx/Tx string. 127499a2dd95SBruce Richardson * @param offload_name 127599a2dd95SBruce Richardson * The function that prints the offload name. 127699a2dd95SBruce Richardson * @return 127799a2dd95SBruce Richardson * - (0) if validation successful. 127899a2dd95SBruce Richardson * - (-EINVAL) if requested offload has been silently disabled. 127999a2dd95SBruce Richardson * 128099a2dd95SBruce Richardson */ 128199a2dd95SBruce Richardson static int 128299a2dd95SBruce Richardson eth_dev_validate_offloads(uint16_t port_id, uint64_t req_offloads, 128399a2dd95SBruce Richardson uint64_t set_offloads, const char *offload_type, 128499a2dd95SBruce Richardson const char *(*offload_name)(uint64_t)) 128599a2dd95SBruce Richardson { 128699a2dd95SBruce Richardson uint64_t offloads_diff = req_offloads ^ set_offloads; 128799a2dd95SBruce Richardson uint64_t offload; 128899a2dd95SBruce Richardson int ret = 0; 128999a2dd95SBruce Richardson 129099a2dd95SBruce Richardson while (offloads_diff != 0) { 129199a2dd95SBruce Richardson /* Check if any offload is requested but not enabled. */ 129299a2dd95SBruce Richardson offload = 1ULL << __builtin_ctzll(offloads_diff); 129399a2dd95SBruce Richardson if (offload & req_offloads) { 129499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 129599a2dd95SBruce Richardson "Port %u failed to enable %s offload %s\n", 129699a2dd95SBruce Richardson port_id, offload_type, offload_name(offload)); 129799a2dd95SBruce Richardson ret = -EINVAL; 129899a2dd95SBruce Richardson } 129999a2dd95SBruce Richardson 130099a2dd95SBruce Richardson /* Check if offload couldn't be disabled. */ 130199a2dd95SBruce Richardson if (offload & set_offloads) { 130299a2dd95SBruce Richardson RTE_ETHDEV_LOG(DEBUG, 130399a2dd95SBruce Richardson "Port %u %s offload %s is not requested but enabled\n", 130499a2dd95SBruce Richardson port_id, offload_type, offload_name(offload)); 130599a2dd95SBruce Richardson } 130699a2dd95SBruce Richardson 130799a2dd95SBruce Richardson offloads_diff &= ~offload; 130899a2dd95SBruce Richardson } 130999a2dd95SBruce Richardson 131099a2dd95SBruce Richardson return ret; 131199a2dd95SBruce Richardson } 131299a2dd95SBruce Richardson 131399a2dd95SBruce Richardson int 131499a2dd95SBruce Richardson rte_eth_dev_configure(uint16_t port_id, uint16_t nb_rx_q, uint16_t nb_tx_q, 131599a2dd95SBruce Richardson const struct rte_eth_conf *dev_conf) 131699a2dd95SBruce Richardson { 131799a2dd95SBruce Richardson struct rte_eth_dev *dev; 131899a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 131999a2dd95SBruce Richardson struct rte_eth_conf orig_conf; 132099a2dd95SBruce Richardson uint16_t overhead_len; 132199a2dd95SBruce Richardson int diag; 132299a2dd95SBruce Richardson int ret; 132399a2dd95SBruce Richardson uint16_t old_mtu; 132499a2dd95SBruce Richardson 132599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 132699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 132799a2dd95SBruce Richardson 132853ef1b34SMin Hu (Connor) if (dev_conf == NULL) { 132953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 133053ef1b34SMin Hu (Connor) "Cannot configure ethdev port %u from NULL config\n", 133153ef1b34SMin Hu (Connor) port_id); 133253ef1b34SMin Hu (Connor) return -EINVAL; 133353ef1b34SMin Hu (Connor) } 133453ef1b34SMin Hu (Connor) 133599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_configure, -ENOTSUP); 133699a2dd95SBruce Richardson 133799a2dd95SBruce Richardson if (dev->data->dev_started) { 133899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 133999a2dd95SBruce Richardson "Port %u must be stopped to allow configuration\n", 134099a2dd95SBruce Richardson port_id); 134199a2dd95SBruce Richardson return -EBUSY; 134299a2dd95SBruce Richardson } 134399a2dd95SBruce Richardson 134402edbfabSHuisong Li /* 134502edbfabSHuisong Li * Ensure that "dev_configured" is always 0 each time prepare to do 134602edbfabSHuisong Li * dev_configure() to avoid any non-anticipated behaviour. 134702edbfabSHuisong Li * And set to 1 when dev_configure() is executed successfully. 134802edbfabSHuisong Li */ 134902edbfabSHuisong Li dev->data->dev_configured = 0; 135002edbfabSHuisong Li 135199a2dd95SBruce Richardson /* Store original config, as rollback required on failure */ 135299a2dd95SBruce Richardson memcpy(&orig_conf, &dev->data->dev_conf, sizeof(dev->data->dev_conf)); 135399a2dd95SBruce Richardson 135499a2dd95SBruce Richardson /* 135599a2dd95SBruce Richardson * Copy the dev_conf parameter into the dev structure. 135699a2dd95SBruce Richardson * rte_eth_dev_info_get() requires dev_conf, copy it before dev_info get 135799a2dd95SBruce Richardson */ 135899a2dd95SBruce Richardson if (dev_conf != &dev->data->dev_conf) 135999a2dd95SBruce Richardson memcpy(&dev->data->dev_conf, dev_conf, 136099a2dd95SBruce Richardson sizeof(dev->data->dev_conf)); 136199a2dd95SBruce Richardson 136299a2dd95SBruce Richardson /* Backup mtu for rollback */ 136399a2dd95SBruce Richardson old_mtu = dev->data->mtu; 136499a2dd95SBruce Richardson 136599a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 136699a2dd95SBruce Richardson if (ret != 0) 136799a2dd95SBruce Richardson goto rollback; 136899a2dd95SBruce Richardson 136999a2dd95SBruce Richardson /* Get the real Ethernet overhead length */ 137099a2dd95SBruce Richardson if (dev_info.max_mtu != UINT16_MAX && 137199a2dd95SBruce Richardson dev_info.max_rx_pktlen > dev_info.max_mtu) 137299a2dd95SBruce Richardson overhead_len = dev_info.max_rx_pktlen - dev_info.max_mtu; 137399a2dd95SBruce Richardson else 137499a2dd95SBruce Richardson overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN; 137599a2dd95SBruce Richardson 137699a2dd95SBruce Richardson /* If number of queues specified by application for both Rx and Tx is 137799a2dd95SBruce Richardson * zero, use driver preferred values. This cannot be done individually 137899a2dd95SBruce Richardson * as it is valid for either Tx or Rx (but not both) to be zero. 137999a2dd95SBruce Richardson * If driver does not provide any preferred valued, fall back on 138099a2dd95SBruce Richardson * EAL defaults. 138199a2dd95SBruce Richardson */ 138299a2dd95SBruce Richardson if (nb_rx_q == 0 && nb_tx_q == 0) { 138399a2dd95SBruce Richardson nb_rx_q = dev_info.default_rxportconf.nb_queues; 138499a2dd95SBruce Richardson if (nb_rx_q == 0) 138599a2dd95SBruce Richardson nb_rx_q = RTE_ETH_DEV_FALLBACK_RX_NBQUEUES; 138699a2dd95SBruce Richardson nb_tx_q = dev_info.default_txportconf.nb_queues; 138799a2dd95SBruce Richardson if (nb_tx_q == 0) 138899a2dd95SBruce Richardson nb_tx_q = RTE_ETH_DEV_FALLBACK_TX_NBQUEUES; 138999a2dd95SBruce Richardson } 139099a2dd95SBruce Richardson 139199a2dd95SBruce Richardson if (nb_rx_q > RTE_MAX_QUEUES_PER_PORT) { 139299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 139399a2dd95SBruce Richardson "Number of RX queues requested (%u) is greater than max supported(%d)\n", 139499a2dd95SBruce Richardson nb_rx_q, RTE_MAX_QUEUES_PER_PORT); 139599a2dd95SBruce Richardson ret = -EINVAL; 139699a2dd95SBruce Richardson goto rollback; 139799a2dd95SBruce Richardson } 139899a2dd95SBruce Richardson 139999a2dd95SBruce Richardson if (nb_tx_q > RTE_MAX_QUEUES_PER_PORT) { 140099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 140199a2dd95SBruce Richardson "Number of TX queues requested (%u) is greater than max supported(%d)\n", 140299a2dd95SBruce Richardson nb_tx_q, RTE_MAX_QUEUES_PER_PORT); 140399a2dd95SBruce Richardson ret = -EINVAL; 140499a2dd95SBruce Richardson goto rollback; 140599a2dd95SBruce Richardson } 140699a2dd95SBruce Richardson 140799a2dd95SBruce Richardson /* 140899a2dd95SBruce Richardson * Check that the numbers of RX and TX queues are not greater 140999a2dd95SBruce Richardson * than the maximum number of RX and TX queues supported by the 141099a2dd95SBruce Richardson * configured device. 141199a2dd95SBruce Richardson */ 141299a2dd95SBruce Richardson if (nb_rx_q > dev_info.max_rx_queues) { 141399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_rx_queues=%u > %u\n", 141499a2dd95SBruce Richardson port_id, nb_rx_q, dev_info.max_rx_queues); 141599a2dd95SBruce Richardson ret = -EINVAL; 141699a2dd95SBruce Richardson goto rollback; 141799a2dd95SBruce Richardson } 141899a2dd95SBruce Richardson 141999a2dd95SBruce Richardson if (nb_tx_q > dev_info.max_tx_queues) { 142099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Ethdev port_id=%u nb_tx_queues=%u > %u\n", 142199a2dd95SBruce Richardson port_id, nb_tx_q, dev_info.max_tx_queues); 142299a2dd95SBruce Richardson ret = -EINVAL; 142399a2dd95SBruce Richardson goto rollback; 142499a2dd95SBruce Richardson } 142599a2dd95SBruce Richardson 142699a2dd95SBruce Richardson /* Check that the device supports requested interrupts */ 142799a2dd95SBruce Richardson if ((dev_conf->intr_conf.lsc == 1) && 142899a2dd95SBruce Richardson (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC))) { 142999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Driver %s does not support lsc\n", 143099a2dd95SBruce Richardson dev->device->driver->name); 143199a2dd95SBruce Richardson ret = -EINVAL; 143299a2dd95SBruce Richardson goto rollback; 143399a2dd95SBruce Richardson } 143499a2dd95SBruce Richardson if ((dev_conf->intr_conf.rmv == 1) && 143599a2dd95SBruce Richardson (!(dev->data->dev_flags & RTE_ETH_DEV_INTR_RMV))) { 143699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Driver %s does not support rmv\n", 143799a2dd95SBruce Richardson dev->device->driver->name); 143899a2dd95SBruce Richardson ret = -EINVAL; 143999a2dd95SBruce Richardson goto rollback; 144099a2dd95SBruce Richardson } 144199a2dd95SBruce Richardson 144299a2dd95SBruce Richardson /* 144399a2dd95SBruce Richardson * If jumbo frames are enabled, check that the maximum RX packet 144499a2dd95SBruce Richardson * length is supported by the configured device. 144599a2dd95SBruce Richardson */ 144699a2dd95SBruce Richardson if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) { 144799a2dd95SBruce Richardson if (dev_conf->rxmode.max_rx_pkt_len > dev_info.max_rx_pktlen) { 144899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 144999a2dd95SBruce Richardson "Ethdev port_id=%u max_rx_pkt_len %u > max valid value %u\n", 145099a2dd95SBruce Richardson port_id, dev_conf->rxmode.max_rx_pkt_len, 145199a2dd95SBruce Richardson dev_info.max_rx_pktlen); 145299a2dd95SBruce Richardson ret = -EINVAL; 145399a2dd95SBruce Richardson goto rollback; 145499a2dd95SBruce Richardson } else if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN) { 145599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 145699a2dd95SBruce Richardson "Ethdev port_id=%u max_rx_pkt_len %u < min valid value %u\n", 145799a2dd95SBruce Richardson port_id, dev_conf->rxmode.max_rx_pkt_len, 145899a2dd95SBruce Richardson (unsigned int)RTE_ETHER_MIN_LEN); 145999a2dd95SBruce Richardson ret = -EINVAL; 146099a2dd95SBruce Richardson goto rollback; 146199a2dd95SBruce Richardson } 146299a2dd95SBruce Richardson 146399a2dd95SBruce Richardson /* Scale the MTU size to adapt max_rx_pkt_len */ 146499a2dd95SBruce Richardson dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len - 146599a2dd95SBruce Richardson overhead_len; 146699a2dd95SBruce Richardson } else { 146799a2dd95SBruce Richardson uint16_t pktlen = dev_conf->rxmode.max_rx_pkt_len; 146899a2dd95SBruce Richardson if (pktlen < RTE_ETHER_MIN_MTU + overhead_len || 146999a2dd95SBruce Richardson pktlen > RTE_ETHER_MTU + overhead_len) 147099a2dd95SBruce Richardson /* Use default value */ 147199a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_rx_pkt_len = 147299a2dd95SBruce Richardson RTE_ETHER_MTU + overhead_len; 147399a2dd95SBruce Richardson } 147499a2dd95SBruce Richardson 147599a2dd95SBruce Richardson /* 147699a2dd95SBruce Richardson * If LRO is enabled, check that the maximum aggregated packet 147799a2dd95SBruce Richardson * size is supported by the configured device. 147899a2dd95SBruce Richardson */ 147999a2dd95SBruce Richardson if (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_TCP_LRO) { 148099a2dd95SBruce Richardson if (dev_conf->rxmode.max_lro_pkt_size == 0) 148199a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_lro_pkt_size = 148299a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_rx_pkt_len; 148399a2dd95SBruce Richardson ret = eth_dev_check_lro_pkt_size(port_id, 148499a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_lro_pkt_size, 148599a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_rx_pkt_len, 148699a2dd95SBruce Richardson dev_info.max_lro_pkt_size); 148799a2dd95SBruce Richardson if (ret != 0) 148899a2dd95SBruce Richardson goto rollback; 148999a2dd95SBruce Richardson } 149099a2dd95SBruce Richardson 149199a2dd95SBruce Richardson /* Any requested offloading must be within its device capabilities */ 149299a2dd95SBruce Richardson if ((dev_conf->rxmode.offloads & dev_info.rx_offload_capa) != 149399a2dd95SBruce Richardson dev_conf->rxmode.offloads) { 149499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 149599a2dd95SBruce Richardson "Ethdev port_id=%u requested Rx offloads 0x%"PRIx64" doesn't match Rx offloads " 149699a2dd95SBruce Richardson "capabilities 0x%"PRIx64" in %s()\n", 149799a2dd95SBruce Richardson port_id, dev_conf->rxmode.offloads, 149899a2dd95SBruce Richardson dev_info.rx_offload_capa, 149999a2dd95SBruce Richardson __func__); 150099a2dd95SBruce Richardson ret = -EINVAL; 150199a2dd95SBruce Richardson goto rollback; 150299a2dd95SBruce Richardson } 150399a2dd95SBruce Richardson if ((dev_conf->txmode.offloads & dev_info.tx_offload_capa) != 150499a2dd95SBruce Richardson dev_conf->txmode.offloads) { 150599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 150699a2dd95SBruce Richardson "Ethdev port_id=%u requested Tx offloads 0x%"PRIx64" doesn't match Tx offloads " 150799a2dd95SBruce Richardson "capabilities 0x%"PRIx64" in %s()\n", 150899a2dd95SBruce Richardson port_id, dev_conf->txmode.offloads, 150999a2dd95SBruce Richardson dev_info.tx_offload_capa, 151099a2dd95SBruce Richardson __func__); 151199a2dd95SBruce Richardson ret = -EINVAL; 151299a2dd95SBruce Richardson goto rollback; 151399a2dd95SBruce Richardson } 151499a2dd95SBruce Richardson 151599a2dd95SBruce Richardson dev->data->dev_conf.rx_adv_conf.rss_conf.rss_hf = 151699a2dd95SBruce Richardson rte_eth_rss_hf_refine(dev_conf->rx_adv_conf.rss_conf.rss_hf); 151799a2dd95SBruce Richardson 151899a2dd95SBruce Richardson /* Check that device supports requested rss hash functions. */ 151999a2dd95SBruce Richardson if ((dev_info.flow_type_rss_offloads | 152099a2dd95SBruce Richardson dev_conf->rx_adv_conf.rss_conf.rss_hf) != 152199a2dd95SBruce Richardson dev_info.flow_type_rss_offloads) { 152299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 152399a2dd95SBruce Richardson "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n", 152499a2dd95SBruce Richardson port_id, dev_conf->rx_adv_conf.rss_conf.rss_hf, 152599a2dd95SBruce Richardson dev_info.flow_type_rss_offloads); 152699a2dd95SBruce Richardson ret = -EINVAL; 152799a2dd95SBruce Richardson goto rollback; 152899a2dd95SBruce Richardson } 152999a2dd95SBruce Richardson 153099a2dd95SBruce Richardson /* Check if Rx RSS distribution is disabled but RSS hash is enabled. */ 153199a2dd95SBruce Richardson if (((dev_conf->rxmode.mq_mode & ETH_MQ_RX_RSS_FLAG) == 0) && 153299a2dd95SBruce Richardson (dev_conf->rxmode.offloads & DEV_RX_OFFLOAD_RSS_HASH)) { 153399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 153499a2dd95SBruce Richardson "Ethdev port_id=%u config invalid Rx mq_mode without RSS but %s offload is requested\n", 153599a2dd95SBruce Richardson port_id, 153699a2dd95SBruce Richardson rte_eth_dev_rx_offload_name(DEV_RX_OFFLOAD_RSS_HASH)); 153799a2dd95SBruce Richardson ret = -EINVAL; 153899a2dd95SBruce Richardson goto rollback; 153999a2dd95SBruce Richardson } 154099a2dd95SBruce Richardson 154199a2dd95SBruce Richardson /* 154299a2dd95SBruce Richardson * Setup new number of RX/TX queues and reconfigure device. 154399a2dd95SBruce Richardson */ 154499a2dd95SBruce Richardson diag = eth_dev_rx_queue_config(dev, nb_rx_q); 154599a2dd95SBruce Richardson if (diag != 0) { 154699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 154799a2dd95SBruce Richardson "Port%u eth_dev_rx_queue_config = %d\n", 154899a2dd95SBruce Richardson port_id, diag); 154999a2dd95SBruce Richardson ret = diag; 155099a2dd95SBruce Richardson goto rollback; 155199a2dd95SBruce Richardson } 155299a2dd95SBruce Richardson 155399a2dd95SBruce Richardson diag = eth_dev_tx_queue_config(dev, nb_tx_q); 155499a2dd95SBruce Richardson if (diag != 0) { 155599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 155699a2dd95SBruce Richardson "Port%u eth_dev_tx_queue_config = %d\n", 155799a2dd95SBruce Richardson port_id, diag); 155899a2dd95SBruce Richardson eth_dev_rx_queue_config(dev, 0); 155999a2dd95SBruce Richardson ret = diag; 156099a2dd95SBruce Richardson goto rollback; 156199a2dd95SBruce Richardson } 156299a2dd95SBruce Richardson 156399a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_configure)(dev); 156499a2dd95SBruce Richardson if (diag != 0) { 156599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port%u dev_configure = %d\n", 156699a2dd95SBruce Richardson port_id, diag); 156799a2dd95SBruce Richardson ret = eth_err(port_id, diag); 156899a2dd95SBruce Richardson goto reset_queues; 156999a2dd95SBruce Richardson } 157099a2dd95SBruce Richardson 157199a2dd95SBruce Richardson /* Initialize Rx profiling if enabled at compilation time. */ 157299a2dd95SBruce Richardson diag = __rte_eth_dev_profile_init(port_id, dev); 157399a2dd95SBruce Richardson if (diag != 0) { 157499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port%u __rte_eth_dev_profile_init = %d\n", 157599a2dd95SBruce Richardson port_id, diag); 157699a2dd95SBruce Richardson ret = eth_err(port_id, diag); 157799a2dd95SBruce Richardson goto reset_queues; 157899a2dd95SBruce Richardson } 157999a2dd95SBruce Richardson 158099a2dd95SBruce Richardson /* Validate Rx offloads. */ 158199a2dd95SBruce Richardson diag = eth_dev_validate_offloads(port_id, 158299a2dd95SBruce Richardson dev_conf->rxmode.offloads, 158399a2dd95SBruce Richardson dev->data->dev_conf.rxmode.offloads, "Rx", 158499a2dd95SBruce Richardson rte_eth_dev_rx_offload_name); 158599a2dd95SBruce Richardson if (diag != 0) { 158699a2dd95SBruce Richardson ret = diag; 158799a2dd95SBruce Richardson goto reset_queues; 158899a2dd95SBruce Richardson } 158999a2dd95SBruce Richardson 159099a2dd95SBruce Richardson /* Validate Tx offloads. */ 159199a2dd95SBruce Richardson diag = eth_dev_validate_offloads(port_id, 159299a2dd95SBruce Richardson dev_conf->txmode.offloads, 159399a2dd95SBruce Richardson dev->data->dev_conf.txmode.offloads, "Tx", 159499a2dd95SBruce Richardson rte_eth_dev_tx_offload_name); 159599a2dd95SBruce Richardson if (diag != 0) { 159699a2dd95SBruce Richardson ret = diag; 159799a2dd95SBruce Richardson goto reset_queues; 159899a2dd95SBruce Richardson } 159999a2dd95SBruce Richardson 160002edbfabSHuisong Li dev->data->dev_configured = 1; 160199a2dd95SBruce Richardson rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, 0); 160299a2dd95SBruce Richardson return 0; 160399a2dd95SBruce Richardson reset_queues: 160499a2dd95SBruce Richardson eth_dev_rx_queue_config(dev, 0); 160599a2dd95SBruce Richardson eth_dev_tx_queue_config(dev, 0); 160699a2dd95SBruce Richardson rollback: 160799a2dd95SBruce Richardson memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf)); 160899a2dd95SBruce Richardson if (old_mtu != dev->data->mtu) 160999a2dd95SBruce Richardson dev->data->mtu = old_mtu; 161099a2dd95SBruce Richardson 161199a2dd95SBruce Richardson rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret); 161299a2dd95SBruce Richardson return ret; 161399a2dd95SBruce Richardson } 161499a2dd95SBruce Richardson 161599a2dd95SBruce Richardson void 161699a2dd95SBruce Richardson rte_eth_dev_internal_reset(struct rte_eth_dev *dev) 161799a2dd95SBruce Richardson { 161899a2dd95SBruce Richardson if (dev->data->dev_started) { 161999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u must be stopped to allow reset\n", 162099a2dd95SBruce Richardson dev->data->port_id); 162199a2dd95SBruce Richardson return; 162299a2dd95SBruce Richardson } 162399a2dd95SBruce Richardson 162499a2dd95SBruce Richardson eth_dev_rx_queue_config(dev, 0); 162599a2dd95SBruce Richardson eth_dev_tx_queue_config(dev, 0); 162699a2dd95SBruce Richardson 162799a2dd95SBruce Richardson memset(&dev->data->dev_conf, 0, sizeof(dev->data->dev_conf)); 162899a2dd95SBruce Richardson } 162999a2dd95SBruce Richardson 163099a2dd95SBruce Richardson static void 163199a2dd95SBruce Richardson eth_dev_mac_restore(struct rte_eth_dev *dev, 163299a2dd95SBruce Richardson struct rte_eth_dev_info *dev_info) 163399a2dd95SBruce Richardson { 163499a2dd95SBruce Richardson struct rte_ether_addr *addr; 163599a2dd95SBruce Richardson uint16_t i; 163699a2dd95SBruce Richardson uint32_t pool = 0; 163799a2dd95SBruce Richardson uint64_t pool_mask; 163899a2dd95SBruce Richardson 163999a2dd95SBruce Richardson /* replay MAC address configuration including default MAC */ 164099a2dd95SBruce Richardson addr = &dev->data->mac_addrs[0]; 164199a2dd95SBruce Richardson if (*dev->dev_ops->mac_addr_set != NULL) 164299a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_set)(dev, addr); 164399a2dd95SBruce Richardson else if (*dev->dev_ops->mac_addr_add != NULL) 164499a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_add)(dev, addr, 0, pool); 164599a2dd95SBruce Richardson 164699a2dd95SBruce Richardson if (*dev->dev_ops->mac_addr_add != NULL) { 164799a2dd95SBruce Richardson for (i = 1; i < dev_info->max_mac_addrs; i++) { 164899a2dd95SBruce Richardson addr = &dev->data->mac_addrs[i]; 164999a2dd95SBruce Richardson 165099a2dd95SBruce Richardson /* skip zero address */ 165199a2dd95SBruce Richardson if (rte_is_zero_ether_addr(addr)) 165299a2dd95SBruce Richardson continue; 165399a2dd95SBruce Richardson 165499a2dd95SBruce Richardson pool = 0; 165599a2dd95SBruce Richardson pool_mask = dev->data->mac_pool_sel[i]; 165699a2dd95SBruce Richardson 165799a2dd95SBruce Richardson do { 165899a2dd95SBruce Richardson if (pool_mask & 1ULL) 165999a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_add)(dev, 166099a2dd95SBruce Richardson addr, i, pool); 166199a2dd95SBruce Richardson pool_mask >>= 1; 166299a2dd95SBruce Richardson pool++; 166399a2dd95SBruce Richardson } while (pool_mask); 166499a2dd95SBruce Richardson } 166599a2dd95SBruce Richardson } 166699a2dd95SBruce Richardson } 166799a2dd95SBruce Richardson 166899a2dd95SBruce Richardson static int 166999a2dd95SBruce Richardson eth_dev_config_restore(struct rte_eth_dev *dev, 167099a2dd95SBruce Richardson struct rte_eth_dev_info *dev_info, uint16_t port_id) 167199a2dd95SBruce Richardson { 167299a2dd95SBruce Richardson int ret; 167399a2dd95SBruce Richardson 167499a2dd95SBruce Richardson if (!(*dev_info->dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR)) 167599a2dd95SBruce Richardson eth_dev_mac_restore(dev, dev_info); 167699a2dd95SBruce Richardson 167799a2dd95SBruce Richardson /* replay promiscuous configuration */ 167899a2dd95SBruce Richardson /* 167999a2dd95SBruce Richardson * use callbacks directly since we don't need port_id check and 168099a2dd95SBruce Richardson * would like to bypass the same value set 168199a2dd95SBruce Richardson */ 168299a2dd95SBruce Richardson if (rte_eth_promiscuous_get(port_id) == 1 && 168399a2dd95SBruce Richardson *dev->dev_ops->promiscuous_enable != NULL) { 168499a2dd95SBruce Richardson ret = eth_err(port_id, 168599a2dd95SBruce Richardson (*dev->dev_ops->promiscuous_enable)(dev)); 168699a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 168799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 168899a2dd95SBruce Richardson "Failed to enable promiscuous mode for device (port %u): %s\n", 168999a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 169099a2dd95SBruce Richardson return ret; 169199a2dd95SBruce Richardson } 169299a2dd95SBruce Richardson } else if (rte_eth_promiscuous_get(port_id) == 0 && 169399a2dd95SBruce Richardson *dev->dev_ops->promiscuous_disable != NULL) { 169499a2dd95SBruce Richardson ret = eth_err(port_id, 169599a2dd95SBruce Richardson (*dev->dev_ops->promiscuous_disable)(dev)); 169699a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 169799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 169899a2dd95SBruce Richardson "Failed to disable promiscuous mode for device (port %u): %s\n", 169999a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 170099a2dd95SBruce Richardson return ret; 170199a2dd95SBruce Richardson } 170299a2dd95SBruce Richardson } 170399a2dd95SBruce Richardson 170499a2dd95SBruce Richardson /* replay all multicast configuration */ 170599a2dd95SBruce Richardson /* 170699a2dd95SBruce Richardson * use callbacks directly since we don't need port_id check and 170799a2dd95SBruce Richardson * would like to bypass the same value set 170899a2dd95SBruce Richardson */ 170999a2dd95SBruce Richardson if (rte_eth_allmulticast_get(port_id) == 1 && 171099a2dd95SBruce Richardson *dev->dev_ops->allmulticast_enable != NULL) { 171199a2dd95SBruce Richardson ret = eth_err(port_id, 171299a2dd95SBruce Richardson (*dev->dev_ops->allmulticast_enable)(dev)); 171399a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 171499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 171599a2dd95SBruce Richardson "Failed to enable allmulticast mode for device (port %u): %s\n", 171699a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 171799a2dd95SBruce Richardson return ret; 171899a2dd95SBruce Richardson } 171999a2dd95SBruce Richardson } else if (rte_eth_allmulticast_get(port_id) == 0 && 172099a2dd95SBruce Richardson *dev->dev_ops->allmulticast_disable != NULL) { 172199a2dd95SBruce Richardson ret = eth_err(port_id, 172299a2dd95SBruce Richardson (*dev->dev_ops->allmulticast_disable)(dev)); 172399a2dd95SBruce Richardson if (ret != 0 && ret != -ENOTSUP) { 172499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 172599a2dd95SBruce Richardson "Failed to disable allmulticast mode for device (port %u): %s\n", 172699a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 172799a2dd95SBruce Richardson return ret; 172899a2dd95SBruce Richardson } 172999a2dd95SBruce Richardson } 173099a2dd95SBruce Richardson 173199a2dd95SBruce Richardson return 0; 173299a2dd95SBruce Richardson } 173399a2dd95SBruce Richardson 173499a2dd95SBruce Richardson int 173599a2dd95SBruce Richardson rte_eth_dev_start(uint16_t port_id) 173699a2dd95SBruce Richardson { 173799a2dd95SBruce Richardson struct rte_eth_dev *dev; 173899a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 173999a2dd95SBruce Richardson int diag; 174099a2dd95SBruce Richardson int ret, ret_stop; 174199a2dd95SBruce Richardson 174299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 174399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 174499a2dd95SBruce Richardson 174599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_start, -ENOTSUP); 174699a2dd95SBruce Richardson 174702edbfabSHuisong Li if (dev->data->dev_configured == 0) { 174802edbfabSHuisong Li RTE_ETHDEV_LOG(INFO, 174902edbfabSHuisong Li "Device with port_id=%"PRIu16" is not configured.\n", 175002edbfabSHuisong Li port_id); 175102edbfabSHuisong Li return -EINVAL; 175202edbfabSHuisong Li } 175302edbfabSHuisong Li 175499a2dd95SBruce Richardson if (dev->data->dev_started != 0) { 175599a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 175699a2dd95SBruce Richardson "Device with port_id=%"PRIu16" already started\n", 175799a2dd95SBruce Richardson port_id); 175899a2dd95SBruce Richardson return 0; 175999a2dd95SBruce Richardson } 176099a2dd95SBruce Richardson 176199a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 176299a2dd95SBruce Richardson if (ret != 0) 176399a2dd95SBruce Richardson return ret; 176499a2dd95SBruce Richardson 176599a2dd95SBruce Richardson /* Lets restore MAC now if device does not support live change */ 176699a2dd95SBruce Richardson if (*dev_info.dev_flags & RTE_ETH_DEV_NOLIVE_MAC_ADDR) 176799a2dd95SBruce Richardson eth_dev_mac_restore(dev, &dev_info); 176899a2dd95SBruce Richardson 176999a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_start)(dev); 177099a2dd95SBruce Richardson if (diag == 0) 177199a2dd95SBruce Richardson dev->data->dev_started = 1; 177299a2dd95SBruce Richardson else 177399a2dd95SBruce Richardson return eth_err(port_id, diag); 177499a2dd95SBruce Richardson 177599a2dd95SBruce Richardson ret = eth_dev_config_restore(dev, &dev_info, port_id); 177699a2dd95SBruce Richardson if (ret != 0) { 177799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 177899a2dd95SBruce Richardson "Error during restoring configuration for device (port %u): %s\n", 177999a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 178099a2dd95SBruce Richardson ret_stop = rte_eth_dev_stop(port_id); 178199a2dd95SBruce Richardson if (ret_stop != 0) { 178299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 178399a2dd95SBruce Richardson "Failed to stop device (port %u): %s\n", 178499a2dd95SBruce Richardson port_id, rte_strerror(-ret_stop)); 178599a2dd95SBruce Richardson } 178699a2dd95SBruce Richardson 178799a2dd95SBruce Richardson return ret; 178899a2dd95SBruce Richardson } 178999a2dd95SBruce Richardson 179099a2dd95SBruce Richardson if (dev->data->dev_conf.intr_conf.lsc == 0) { 179199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); 179299a2dd95SBruce Richardson (*dev->dev_ops->link_update)(dev, 0); 179399a2dd95SBruce Richardson } 179499a2dd95SBruce Richardson 179599a2dd95SBruce Richardson rte_ethdev_trace_start(port_id); 179699a2dd95SBruce Richardson return 0; 179799a2dd95SBruce Richardson } 179899a2dd95SBruce Richardson 179999a2dd95SBruce Richardson int 180099a2dd95SBruce Richardson rte_eth_dev_stop(uint16_t port_id) 180199a2dd95SBruce Richardson { 180299a2dd95SBruce Richardson struct rte_eth_dev *dev; 180399a2dd95SBruce Richardson int ret; 180499a2dd95SBruce Richardson 180599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 180699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 180799a2dd95SBruce Richardson 180899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_stop, -ENOTSUP); 180999a2dd95SBruce Richardson 181099a2dd95SBruce Richardson if (dev->data->dev_started == 0) { 181199a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 181299a2dd95SBruce Richardson "Device with port_id=%"PRIu16" already stopped\n", 181399a2dd95SBruce Richardson port_id); 181499a2dd95SBruce Richardson return 0; 181599a2dd95SBruce Richardson } 181699a2dd95SBruce Richardson 181799a2dd95SBruce Richardson dev->data->dev_started = 0; 181899a2dd95SBruce Richardson ret = (*dev->dev_ops->dev_stop)(dev); 181999a2dd95SBruce Richardson rte_ethdev_trace_stop(port_id, ret); 182099a2dd95SBruce Richardson 182199a2dd95SBruce Richardson return ret; 182299a2dd95SBruce Richardson } 182399a2dd95SBruce Richardson 182499a2dd95SBruce Richardson int 182599a2dd95SBruce Richardson rte_eth_dev_set_link_up(uint16_t port_id) 182699a2dd95SBruce Richardson { 182799a2dd95SBruce Richardson struct rte_eth_dev *dev; 182899a2dd95SBruce Richardson 182999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 183099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 183199a2dd95SBruce Richardson 183299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_up, -ENOTSUP); 183399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_set_link_up)(dev)); 183499a2dd95SBruce Richardson } 183599a2dd95SBruce Richardson 183699a2dd95SBruce Richardson int 183799a2dd95SBruce Richardson rte_eth_dev_set_link_down(uint16_t port_id) 183899a2dd95SBruce Richardson { 183999a2dd95SBruce Richardson struct rte_eth_dev *dev; 184099a2dd95SBruce Richardson 184199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 184299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 184399a2dd95SBruce Richardson 184499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_set_link_down, -ENOTSUP); 184599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_set_link_down)(dev)); 184699a2dd95SBruce Richardson } 184799a2dd95SBruce Richardson 184899a2dd95SBruce Richardson int 184999a2dd95SBruce Richardson rte_eth_dev_close(uint16_t port_id) 185099a2dd95SBruce Richardson { 185199a2dd95SBruce Richardson struct rte_eth_dev *dev; 185299a2dd95SBruce Richardson int firsterr, binerr; 185399a2dd95SBruce Richardson int *lasterr = &firsterr; 185499a2dd95SBruce Richardson 185599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 185699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 185799a2dd95SBruce Richardson 185899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_close, -ENOTSUP); 185999a2dd95SBruce Richardson *lasterr = (*dev->dev_ops->dev_close)(dev); 186099a2dd95SBruce Richardson if (*lasterr != 0) 186199a2dd95SBruce Richardson lasterr = &binerr; 186299a2dd95SBruce Richardson 186399a2dd95SBruce Richardson rte_ethdev_trace_close(port_id); 186499a2dd95SBruce Richardson *lasterr = rte_eth_dev_release_port(dev); 186599a2dd95SBruce Richardson 186699a2dd95SBruce Richardson return firsterr; 186799a2dd95SBruce Richardson } 186899a2dd95SBruce Richardson 186999a2dd95SBruce Richardson int 187099a2dd95SBruce Richardson rte_eth_dev_reset(uint16_t port_id) 187199a2dd95SBruce Richardson { 187299a2dd95SBruce Richardson struct rte_eth_dev *dev; 187399a2dd95SBruce Richardson int ret; 187499a2dd95SBruce Richardson 187599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 187699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 187799a2dd95SBruce Richardson 187899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_reset, -ENOTSUP); 187999a2dd95SBruce Richardson 188099a2dd95SBruce Richardson ret = rte_eth_dev_stop(port_id); 188199a2dd95SBruce Richardson if (ret != 0) { 188299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 188399a2dd95SBruce Richardson "Failed to stop device (port %u) before reset: %s - ignore\n", 188499a2dd95SBruce Richardson port_id, rte_strerror(-ret)); 188599a2dd95SBruce Richardson } 188699a2dd95SBruce Richardson ret = dev->dev_ops->dev_reset(dev); 188799a2dd95SBruce Richardson 188899a2dd95SBruce Richardson return eth_err(port_id, ret); 188999a2dd95SBruce Richardson } 189099a2dd95SBruce Richardson 189199a2dd95SBruce Richardson int 189299a2dd95SBruce Richardson rte_eth_dev_is_removed(uint16_t port_id) 189399a2dd95SBruce Richardson { 189499a2dd95SBruce Richardson struct rte_eth_dev *dev; 189599a2dd95SBruce Richardson int ret; 189699a2dd95SBruce Richardson 189799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, 0); 189899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 189999a2dd95SBruce Richardson 190099a2dd95SBruce Richardson if (dev->state == RTE_ETH_DEV_REMOVED) 190199a2dd95SBruce Richardson return 1; 190299a2dd95SBruce Richardson 190399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->is_removed, 0); 190499a2dd95SBruce Richardson 190599a2dd95SBruce Richardson ret = dev->dev_ops->is_removed(dev); 190699a2dd95SBruce Richardson if (ret != 0) 190799a2dd95SBruce Richardson /* Device is physically removed. */ 190899a2dd95SBruce Richardson dev->state = RTE_ETH_DEV_REMOVED; 190999a2dd95SBruce Richardson 191099a2dd95SBruce Richardson return ret; 191199a2dd95SBruce Richardson } 191299a2dd95SBruce Richardson 191399a2dd95SBruce Richardson static int 191499a2dd95SBruce Richardson rte_eth_rx_queue_check_split(const struct rte_eth_rxseg_split *rx_seg, 191599a2dd95SBruce Richardson uint16_t n_seg, uint32_t *mbp_buf_size, 191699a2dd95SBruce Richardson const struct rte_eth_dev_info *dev_info) 191799a2dd95SBruce Richardson { 191899a2dd95SBruce Richardson const struct rte_eth_rxseg_capa *seg_capa = &dev_info->rx_seg_capa; 191999a2dd95SBruce Richardson struct rte_mempool *mp_first; 192099a2dd95SBruce Richardson uint32_t offset_mask; 192199a2dd95SBruce Richardson uint16_t seg_idx; 192299a2dd95SBruce Richardson 192399a2dd95SBruce Richardson if (n_seg > seg_capa->max_nseg) { 192499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 192599a2dd95SBruce Richardson "Requested Rx segments %u exceed supported %u\n", 192699a2dd95SBruce Richardson n_seg, seg_capa->max_nseg); 192799a2dd95SBruce Richardson return -EINVAL; 192899a2dd95SBruce Richardson } 192999a2dd95SBruce Richardson /* 193099a2dd95SBruce Richardson * Check the sizes and offsets against buffer sizes 193199a2dd95SBruce Richardson * for each segment specified in extended configuration. 193299a2dd95SBruce Richardson */ 193399a2dd95SBruce Richardson mp_first = rx_seg[0].mp; 193499a2dd95SBruce Richardson offset_mask = (1u << seg_capa->offset_align_log2) - 1; 193599a2dd95SBruce Richardson for (seg_idx = 0; seg_idx < n_seg; seg_idx++) { 193699a2dd95SBruce Richardson struct rte_mempool *mpl = rx_seg[seg_idx].mp; 193799a2dd95SBruce Richardson uint32_t length = rx_seg[seg_idx].length; 193899a2dd95SBruce Richardson uint32_t offset = rx_seg[seg_idx].offset; 193999a2dd95SBruce Richardson 194099a2dd95SBruce Richardson if (mpl == NULL) { 194199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "null mempool pointer\n"); 194299a2dd95SBruce Richardson return -EINVAL; 194399a2dd95SBruce Richardson } 194499a2dd95SBruce Richardson if (seg_idx != 0 && mp_first != mpl && 194599a2dd95SBruce Richardson seg_capa->multi_pools == 0) { 194699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Receiving to multiple pools is not supported\n"); 194799a2dd95SBruce Richardson return -ENOTSUP; 194899a2dd95SBruce Richardson } 194999a2dd95SBruce Richardson if (offset != 0) { 195099a2dd95SBruce Richardson if (seg_capa->offset_allowed == 0) { 195199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Rx segmentation with offset is not supported\n"); 195299a2dd95SBruce Richardson return -ENOTSUP; 195399a2dd95SBruce Richardson } 195499a2dd95SBruce Richardson if (offset & offset_mask) { 195599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Rx segmentation invalid offset alignment %u, %u\n", 195699a2dd95SBruce Richardson offset, 195799a2dd95SBruce Richardson seg_capa->offset_align_log2); 195899a2dd95SBruce Richardson return -EINVAL; 195999a2dd95SBruce Richardson } 196099a2dd95SBruce Richardson } 196199a2dd95SBruce Richardson if (mpl->private_data_size < 196299a2dd95SBruce Richardson sizeof(struct rte_pktmbuf_pool_private)) { 196399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 196499a2dd95SBruce Richardson "%s private_data_size %u < %u\n", 196599a2dd95SBruce Richardson mpl->name, mpl->private_data_size, 196699a2dd95SBruce Richardson (unsigned int)sizeof 196799a2dd95SBruce Richardson (struct rte_pktmbuf_pool_private)); 196899a2dd95SBruce Richardson return -ENOSPC; 196999a2dd95SBruce Richardson } 197099a2dd95SBruce Richardson offset += seg_idx != 0 ? 0 : RTE_PKTMBUF_HEADROOM; 197199a2dd95SBruce Richardson *mbp_buf_size = rte_pktmbuf_data_room_size(mpl); 197299a2dd95SBruce Richardson length = length != 0 ? length : *mbp_buf_size; 197399a2dd95SBruce Richardson if (*mbp_buf_size < length + offset) { 197499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 197599a2dd95SBruce Richardson "%s mbuf_data_room_size %u < %u (segment length=%u + segment offset=%u)\n", 197699a2dd95SBruce Richardson mpl->name, *mbp_buf_size, 197799a2dd95SBruce Richardson length + offset, length, offset); 197899a2dd95SBruce Richardson return -EINVAL; 197999a2dd95SBruce Richardson } 198099a2dd95SBruce Richardson } 198199a2dd95SBruce Richardson return 0; 198299a2dd95SBruce Richardson } 198399a2dd95SBruce Richardson 198499a2dd95SBruce Richardson int 198599a2dd95SBruce Richardson rte_eth_rx_queue_setup(uint16_t port_id, uint16_t rx_queue_id, 198699a2dd95SBruce Richardson uint16_t nb_rx_desc, unsigned int socket_id, 198799a2dd95SBruce Richardson const struct rte_eth_rxconf *rx_conf, 198899a2dd95SBruce Richardson struct rte_mempool *mp) 198999a2dd95SBruce Richardson { 199099a2dd95SBruce Richardson int ret; 199199a2dd95SBruce Richardson uint32_t mbp_buf_size; 199299a2dd95SBruce Richardson struct rte_eth_dev *dev; 199399a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 199499a2dd95SBruce Richardson struct rte_eth_rxconf local_conf; 199599a2dd95SBruce Richardson 199699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 199799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 199853ef1b34SMin Hu (Connor) 199999a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 200099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id); 200199a2dd95SBruce Richardson return -EINVAL; 200299a2dd95SBruce Richardson } 200399a2dd95SBruce Richardson 200499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_setup, -ENOTSUP); 200599a2dd95SBruce Richardson 200699a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 200799a2dd95SBruce Richardson if (ret != 0) 200899a2dd95SBruce Richardson return ret; 200999a2dd95SBruce Richardson 201099a2dd95SBruce Richardson if (mp != NULL) { 201199a2dd95SBruce Richardson /* Single pool configuration check. */ 201299a2dd95SBruce Richardson if (rx_conf != NULL && rx_conf->rx_nseg != 0) { 201399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 201499a2dd95SBruce Richardson "Ambiguous segment configuration\n"); 201599a2dd95SBruce Richardson return -EINVAL; 201699a2dd95SBruce Richardson } 201799a2dd95SBruce Richardson /* 201899a2dd95SBruce Richardson * Check the size of the mbuf data buffer, this value 201999a2dd95SBruce Richardson * must be provided in the private data of the memory pool. 202099a2dd95SBruce Richardson * First check that the memory pool(s) has a valid private data. 202199a2dd95SBruce Richardson */ 202299a2dd95SBruce Richardson if (mp->private_data_size < 202399a2dd95SBruce Richardson sizeof(struct rte_pktmbuf_pool_private)) { 202499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "%s private_data_size %u < %u\n", 202599a2dd95SBruce Richardson mp->name, mp->private_data_size, 202699a2dd95SBruce Richardson (unsigned int) 202799a2dd95SBruce Richardson sizeof(struct rte_pktmbuf_pool_private)); 202899a2dd95SBruce Richardson return -ENOSPC; 202999a2dd95SBruce Richardson } 203099a2dd95SBruce Richardson mbp_buf_size = rte_pktmbuf_data_room_size(mp); 203199a2dd95SBruce Richardson if (mbp_buf_size < dev_info.min_rx_bufsize + 203299a2dd95SBruce Richardson RTE_PKTMBUF_HEADROOM) { 203399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 203499a2dd95SBruce Richardson "%s mbuf_data_room_size %u < %u (RTE_PKTMBUF_HEADROOM=%u + min_rx_bufsize(dev)=%u)\n", 203599a2dd95SBruce Richardson mp->name, mbp_buf_size, 203699a2dd95SBruce Richardson RTE_PKTMBUF_HEADROOM + 203799a2dd95SBruce Richardson dev_info.min_rx_bufsize, 203899a2dd95SBruce Richardson RTE_PKTMBUF_HEADROOM, 203999a2dd95SBruce Richardson dev_info.min_rx_bufsize); 204099a2dd95SBruce Richardson return -EINVAL; 204199a2dd95SBruce Richardson } 204299a2dd95SBruce Richardson } else { 204399a2dd95SBruce Richardson const struct rte_eth_rxseg_split *rx_seg; 204499a2dd95SBruce Richardson uint16_t n_seg; 204599a2dd95SBruce Richardson 204699a2dd95SBruce Richardson /* Extended multi-segment configuration check. */ 204799a2dd95SBruce Richardson if (rx_conf == NULL || rx_conf->rx_seg == NULL || rx_conf->rx_nseg == 0) { 204899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 204999a2dd95SBruce Richardson "Memory pool is null and no extended configuration provided\n"); 205099a2dd95SBruce Richardson return -EINVAL; 205199a2dd95SBruce Richardson } 205299a2dd95SBruce Richardson 205399a2dd95SBruce Richardson rx_seg = (const struct rte_eth_rxseg_split *)rx_conf->rx_seg; 205499a2dd95SBruce Richardson n_seg = rx_conf->rx_nseg; 205599a2dd95SBruce Richardson 205699a2dd95SBruce Richardson if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) { 205799a2dd95SBruce Richardson ret = rte_eth_rx_queue_check_split(rx_seg, n_seg, 205899a2dd95SBruce Richardson &mbp_buf_size, 205999a2dd95SBruce Richardson &dev_info); 206099a2dd95SBruce Richardson if (ret != 0) 206199a2dd95SBruce Richardson return ret; 206299a2dd95SBruce Richardson } else { 206399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "No Rx segmentation offload configured\n"); 206499a2dd95SBruce Richardson return -EINVAL; 206599a2dd95SBruce Richardson } 206699a2dd95SBruce Richardson } 206799a2dd95SBruce Richardson 206899a2dd95SBruce Richardson /* Use default specified by driver, if nb_rx_desc is zero */ 206999a2dd95SBruce Richardson if (nb_rx_desc == 0) { 207099a2dd95SBruce Richardson nb_rx_desc = dev_info.default_rxportconf.ring_size; 207199a2dd95SBruce Richardson /* If driver default is also zero, fall back on EAL default */ 207299a2dd95SBruce Richardson if (nb_rx_desc == 0) 207399a2dd95SBruce Richardson nb_rx_desc = RTE_ETH_DEV_FALLBACK_RX_RINGSIZE; 207499a2dd95SBruce Richardson } 207599a2dd95SBruce Richardson 207699a2dd95SBruce Richardson if (nb_rx_desc > dev_info.rx_desc_lim.nb_max || 207799a2dd95SBruce Richardson nb_rx_desc < dev_info.rx_desc_lim.nb_min || 207899a2dd95SBruce Richardson nb_rx_desc % dev_info.rx_desc_lim.nb_align != 0) { 207999a2dd95SBruce Richardson 208099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 208199a2dd95SBruce Richardson "Invalid value for nb_rx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n", 208299a2dd95SBruce Richardson nb_rx_desc, dev_info.rx_desc_lim.nb_max, 208399a2dd95SBruce Richardson dev_info.rx_desc_lim.nb_min, 208499a2dd95SBruce Richardson dev_info.rx_desc_lim.nb_align); 208599a2dd95SBruce Richardson return -EINVAL; 208699a2dd95SBruce Richardson } 208799a2dd95SBruce Richardson 208899a2dd95SBruce Richardson if (dev->data->dev_started && 208999a2dd95SBruce Richardson !(dev_info.dev_capa & 209099a2dd95SBruce Richardson RTE_ETH_DEV_CAPA_RUNTIME_RX_QUEUE_SETUP)) 209199a2dd95SBruce Richardson return -EBUSY; 209299a2dd95SBruce Richardson 209399a2dd95SBruce Richardson if (dev->data->dev_started && 209499a2dd95SBruce Richardson (dev->data->rx_queue_state[rx_queue_id] != 209599a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_STOPPED)) 209699a2dd95SBruce Richardson return -EBUSY; 209799a2dd95SBruce Richardson 209849ed3224SXueming Li eth_dev_rxq_release(dev, rx_queue_id); 209999a2dd95SBruce Richardson 210099a2dd95SBruce Richardson if (rx_conf == NULL) 210199a2dd95SBruce Richardson rx_conf = &dev_info.default_rxconf; 210299a2dd95SBruce Richardson 210399a2dd95SBruce Richardson local_conf = *rx_conf; 210499a2dd95SBruce Richardson 210599a2dd95SBruce Richardson /* 210699a2dd95SBruce Richardson * If an offloading has already been enabled in 210799a2dd95SBruce Richardson * rte_eth_dev_configure(), it has been enabled on all queues, 210899a2dd95SBruce Richardson * so there is no need to enable it in this queue again. 210999a2dd95SBruce Richardson * The local_conf.offloads input to underlying PMD only carries 211099a2dd95SBruce Richardson * those offloadings which are only enabled on this queue and 211199a2dd95SBruce Richardson * not enabled on all queues. 211299a2dd95SBruce Richardson */ 211399a2dd95SBruce Richardson local_conf.offloads &= ~dev->data->dev_conf.rxmode.offloads; 211499a2dd95SBruce Richardson 211599a2dd95SBruce Richardson /* 211699a2dd95SBruce Richardson * New added offloadings for this queue are those not enabled in 211799a2dd95SBruce Richardson * rte_eth_dev_configure() and they must be per-queue type. 211899a2dd95SBruce Richardson * A pure per-port offloading can't be enabled on a queue while 211999a2dd95SBruce Richardson * disabled on another queue. A pure per-port offloading can't 212099a2dd95SBruce Richardson * be enabled for any queue as new added one if it hasn't been 212199a2dd95SBruce Richardson * enabled in rte_eth_dev_configure(). 212299a2dd95SBruce Richardson */ 212399a2dd95SBruce Richardson if ((local_conf.offloads & dev_info.rx_queue_offload_capa) != 212499a2dd95SBruce Richardson local_conf.offloads) { 212599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 212699a2dd95SBruce Richardson "Ethdev port_id=%d rx_queue_id=%d, new added offloads 0x%"PRIx64" must be " 212799a2dd95SBruce Richardson "within per-queue offload capabilities 0x%"PRIx64" in %s()\n", 212899a2dd95SBruce Richardson port_id, rx_queue_id, local_conf.offloads, 212999a2dd95SBruce Richardson dev_info.rx_queue_offload_capa, 213099a2dd95SBruce Richardson __func__); 213199a2dd95SBruce Richardson return -EINVAL; 213299a2dd95SBruce Richardson } 213399a2dd95SBruce Richardson 213499a2dd95SBruce Richardson /* 213599a2dd95SBruce Richardson * If LRO is enabled, check that the maximum aggregated packet 213699a2dd95SBruce Richardson * size is supported by the configured device. 213799a2dd95SBruce Richardson */ 213899a2dd95SBruce Richardson if (local_conf.offloads & DEV_RX_OFFLOAD_TCP_LRO) { 213999a2dd95SBruce Richardson if (dev->data->dev_conf.rxmode.max_lro_pkt_size == 0) 214099a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_lro_pkt_size = 214199a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_rx_pkt_len; 214299a2dd95SBruce Richardson int ret = eth_dev_check_lro_pkt_size(port_id, 214399a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_lro_pkt_size, 214499a2dd95SBruce Richardson dev->data->dev_conf.rxmode.max_rx_pkt_len, 214599a2dd95SBruce Richardson dev_info.max_lro_pkt_size); 214699a2dd95SBruce Richardson if (ret != 0) 214799a2dd95SBruce Richardson return ret; 214899a2dd95SBruce Richardson } 214999a2dd95SBruce Richardson 215099a2dd95SBruce Richardson ret = (*dev->dev_ops->rx_queue_setup)(dev, rx_queue_id, nb_rx_desc, 215199a2dd95SBruce Richardson socket_id, &local_conf, mp); 215299a2dd95SBruce Richardson if (!ret) { 215399a2dd95SBruce Richardson if (!dev->data->min_rx_buf_size || 215499a2dd95SBruce Richardson dev->data->min_rx_buf_size > mbp_buf_size) 215599a2dd95SBruce Richardson dev->data->min_rx_buf_size = mbp_buf_size; 215699a2dd95SBruce Richardson } 215799a2dd95SBruce Richardson 215899a2dd95SBruce Richardson rte_ethdev_trace_rxq_setup(port_id, rx_queue_id, nb_rx_desc, mp, 215999a2dd95SBruce Richardson rx_conf, ret); 216099a2dd95SBruce Richardson return eth_err(port_id, ret); 216199a2dd95SBruce Richardson } 216299a2dd95SBruce Richardson 216399a2dd95SBruce Richardson int 216499a2dd95SBruce Richardson rte_eth_rx_hairpin_queue_setup(uint16_t port_id, uint16_t rx_queue_id, 216599a2dd95SBruce Richardson uint16_t nb_rx_desc, 216699a2dd95SBruce Richardson const struct rte_eth_hairpin_conf *conf) 216799a2dd95SBruce Richardson { 216899a2dd95SBruce Richardson int ret; 216999a2dd95SBruce Richardson struct rte_eth_dev *dev; 217099a2dd95SBruce Richardson struct rte_eth_hairpin_cap cap; 217199a2dd95SBruce Richardson int i; 217299a2dd95SBruce Richardson int count; 217399a2dd95SBruce Richardson 217499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 217599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 217653ef1b34SMin Hu (Connor) 217799a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 217899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", rx_queue_id); 217999a2dd95SBruce Richardson return -EINVAL; 218099a2dd95SBruce Richardson } 218153ef1b34SMin Hu (Connor) 218253ef1b34SMin Hu (Connor) if (conf == NULL) { 218353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 218453ef1b34SMin Hu (Connor) "Cannot setup ethdev port %u Rx hairpin queue from NULL config\n", 218553ef1b34SMin Hu (Connor) port_id); 218653ef1b34SMin Hu (Connor) return -EINVAL; 218753ef1b34SMin Hu (Connor) } 218853ef1b34SMin Hu (Connor) 218999a2dd95SBruce Richardson ret = rte_eth_dev_hairpin_capability_get(port_id, &cap); 219099a2dd95SBruce Richardson if (ret != 0) 219199a2dd95SBruce Richardson return ret; 219299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_hairpin_queue_setup, 219399a2dd95SBruce Richardson -ENOTSUP); 219499a2dd95SBruce Richardson /* if nb_rx_desc is zero use max number of desc from the driver. */ 219599a2dd95SBruce Richardson if (nb_rx_desc == 0) 219699a2dd95SBruce Richardson nb_rx_desc = cap.max_nb_desc; 219799a2dd95SBruce Richardson if (nb_rx_desc > cap.max_nb_desc) { 219899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 219999a2dd95SBruce Richardson "Invalid value for nb_rx_desc(=%hu), should be: <= %hu", 220099a2dd95SBruce Richardson nb_rx_desc, cap.max_nb_desc); 220199a2dd95SBruce Richardson return -EINVAL; 220299a2dd95SBruce Richardson } 220399a2dd95SBruce Richardson if (conf->peer_count > cap.max_rx_2_tx) { 220499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 220599a2dd95SBruce Richardson "Invalid value for number of peers for Rx queue(=%u), should be: <= %hu", 220699a2dd95SBruce Richardson conf->peer_count, cap.max_rx_2_tx); 220799a2dd95SBruce Richardson return -EINVAL; 220899a2dd95SBruce Richardson } 220999a2dd95SBruce Richardson if (conf->peer_count == 0) { 221099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 221199a2dd95SBruce Richardson "Invalid value for number of peers for Rx queue(=%u), should be: > 0", 221299a2dd95SBruce Richardson conf->peer_count); 221399a2dd95SBruce Richardson return -EINVAL; 221499a2dd95SBruce Richardson } 221599a2dd95SBruce Richardson for (i = 0, count = 0; i < dev->data->nb_rx_queues && 221699a2dd95SBruce Richardson cap.max_nb_queues != UINT16_MAX; i++) { 221799a2dd95SBruce Richardson if (i == rx_queue_id || rte_eth_dev_is_rx_hairpin_queue(dev, i)) 221899a2dd95SBruce Richardson count++; 221999a2dd95SBruce Richardson } 222099a2dd95SBruce Richardson if (count > cap.max_nb_queues) { 222199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "To many Rx hairpin queues max is %d", 222299a2dd95SBruce Richardson cap.max_nb_queues); 222399a2dd95SBruce Richardson return -EINVAL; 222499a2dd95SBruce Richardson } 222599a2dd95SBruce Richardson if (dev->data->dev_started) 222699a2dd95SBruce Richardson return -EBUSY; 222749ed3224SXueming Li eth_dev_rxq_release(dev, rx_queue_id); 222899a2dd95SBruce Richardson ret = (*dev->dev_ops->rx_hairpin_queue_setup)(dev, rx_queue_id, 222999a2dd95SBruce Richardson nb_rx_desc, conf); 223099a2dd95SBruce Richardson if (ret == 0) 223199a2dd95SBruce Richardson dev->data->rx_queue_state[rx_queue_id] = 223299a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_HAIRPIN; 223399a2dd95SBruce Richardson return eth_err(port_id, ret); 223499a2dd95SBruce Richardson } 223599a2dd95SBruce Richardson 223699a2dd95SBruce Richardson int 223799a2dd95SBruce Richardson rte_eth_tx_queue_setup(uint16_t port_id, uint16_t tx_queue_id, 223899a2dd95SBruce Richardson uint16_t nb_tx_desc, unsigned int socket_id, 223999a2dd95SBruce Richardson const struct rte_eth_txconf *tx_conf) 224099a2dd95SBruce Richardson { 224199a2dd95SBruce Richardson struct rte_eth_dev *dev; 224299a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 224399a2dd95SBruce Richardson struct rte_eth_txconf local_conf; 224499a2dd95SBruce Richardson int ret; 224599a2dd95SBruce Richardson 224699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 224799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 224853ef1b34SMin Hu (Connor) 224999a2dd95SBruce Richardson if (tx_queue_id >= dev->data->nb_tx_queues) { 225099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id); 225199a2dd95SBruce Richardson return -EINVAL; 225299a2dd95SBruce Richardson } 225399a2dd95SBruce Richardson 225499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_queue_setup, -ENOTSUP); 225599a2dd95SBruce Richardson 225699a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 225799a2dd95SBruce Richardson if (ret != 0) 225899a2dd95SBruce Richardson return ret; 225999a2dd95SBruce Richardson 226099a2dd95SBruce Richardson /* Use default specified by driver, if nb_tx_desc is zero */ 226199a2dd95SBruce Richardson if (nb_tx_desc == 0) { 226299a2dd95SBruce Richardson nb_tx_desc = dev_info.default_txportconf.ring_size; 226399a2dd95SBruce Richardson /* If driver default is zero, fall back on EAL default */ 226499a2dd95SBruce Richardson if (nb_tx_desc == 0) 226599a2dd95SBruce Richardson nb_tx_desc = RTE_ETH_DEV_FALLBACK_TX_RINGSIZE; 226699a2dd95SBruce Richardson } 226799a2dd95SBruce Richardson if (nb_tx_desc > dev_info.tx_desc_lim.nb_max || 226899a2dd95SBruce Richardson nb_tx_desc < dev_info.tx_desc_lim.nb_min || 226999a2dd95SBruce Richardson nb_tx_desc % dev_info.tx_desc_lim.nb_align != 0) { 227099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 227199a2dd95SBruce Richardson "Invalid value for nb_tx_desc(=%hu), should be: <= %hu, >= %hu, and a product of %hu\n", 227299a2dd95SBruce Richardson nb_tx_desc, dev_info.tx_desc_lim.nb_max, 227399a2dd95SBruce Richardson dev_info.tx_desc_lim.nb_min, 227499a2dd95SBruce Richardson dev_info.tx_desc_lim.nb_align); 227599a2dd95SBruce Richardson return -EINVAL; 227699a2dd95SBruce Richardson } 227799a2dd95SBruce Richardson 227899a2dd95SBruce Richardson if (dev->data->dev_started && 227999a2dd95SBruce Richardson !(dev_info.dev_capa & 228099a2dd95SBruce Richardson RTE_ETH_DEV_CAPA_RUNTIME_TX_QUEUE_SETUP)) 228199a2dd95SBruce Richardson return -EBUSY; 228299a2dd95SBruce Richardson 228399a2dd95SBruce Richardson if (dev->data->dev_started && 228499a2dd95SBruce Richardson (dev->data->tx_queue_state[tx_queue_id] != 228599a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_STOPPED)) 228699a2dd95SBruce Richardson return -EBUSY; 228799a2dd95SBruce Richardson 228849ed3224SXueming Li eth_dev_txq_release(dev, tx_queue_id); 228999a2dd95SBruce Richardson 229099a2dd95SBruce Richardson if (tx_conf == NULL) 229199a2dd95SBruce Richardson tx_conf = &dev_info.default_txconf; 229299a2dd95SBruce Richardson 229399a2dd95SBruce Richardson local_conf = *tx_conf; 229499a2dd95SBruce Richardson 229599a2dd95SBruce Richardson /* 229699a2dd95SBruce Richardson * If an offloading has already been enabled in 229799a2dd95SBruce Richardson * rte_eth_dev_configure(), it has been enabled on all queues, 229899a2dd95SBruce Richardson * so there is no need to enable it in this queue again. 229999a2dd95SBruce Richardson * The local_conf.offloads input to underlying PMD only carries 230099a2dd95SBruce Richardson * those offloadings which are only enabled on this queue and 230199a2dd95SBruce Richardson * not enabled on all queues. 230299a2dd95SBruce Richardson */ 230399a2dd95SBruce Richardson local_conf.offloads &= ~dev->data->dev_conf.txmode.offloads; 230499a2dd95SBruce Richardson 230599a2dd95SBruce Richardson /* 230699a2dd95SBruce Richardson * New added offloadings for this queue are those not enabled in 230799a2dd95SBruce Richardson * rte_eth_dev_configure() and they must be per-queue type. 230899a2dd95SBruce Richardson * A pure per-port offloading can't be enabled on a queue while 230999a2dd95SBruce Richardson * disabled on another queue. A pure per-port offloading can't 231099a2dd95SBruce Richardson * be enabled for any queue as new added one if it hasn't been 231199a2dd95SBruce Richardson * enabled in rte_eth_dev_configure(). 231299a2dd95SBruce Richardson */ 231399a2dd95SBruce Richardson if ((local_conf.offloads & dev_info.tx_queue_offload_capa) != 231499a2dd95SBruce Richardson local_conf.offloads) { 231599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 231699a2dd95SBruce Richardson "Ethdev port_id=%d tx_queue_id=%d, new added offloads 0x%"PRIx64" must be " 231799a2dd95SBruce Richardson "within per-queue offload capabilities 0x%"PRIx64" in %s()\n", 231899a2dd95SBruce Richardson port_id, tx_queue_id, local_conf.offloads, 231999a2dd95SBruce Richardson dev_info.tx_queue_offload_capa, 232099a2dd95SBruce Richardson __func__); 232199a2dd95SBruce Richardson return -EINVAL; 232299a2dd95SBruce Richardson } 232399a2dd95SBruce Richardson 232499a2dd95SBruce Richardson rte_ethdev_trace_txq_setup(port_id, tx_queue_id, nb_tx_desc, tx_conf); 232599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->tx_queue_setup)(dev, 232699a2dd95SBruce Richardson tx_queue_id, nb_tx_desc, socket_id, &local_conf)); 232799a2dd95SBruce Richardson } 232899a2dd95SBruce Richardson 232999a2dd95SBruce Richardson int 233099a2dd95SBruce Richardson rte_eth_tx_hairpin_queue_setup(uint16_t port_id, uint16_t tx_queue_id, 233199a2dd95SBruce Richardson uint16_t nb_tx_desc, 233299a2dd95SBruce Richardson const struct rte_eth_hairpin_conf *conf) 233399a2dd95SBruce Richardson { 233499a2dd95SBruce Richardson struct rte_eth_dev *dev; 233599a2dd95SBruce Richardson struct rte_eth_hairpin_cap cap; 233699a2dd95SBruce Richardson int i; 233799a2dd95SBruce Richardson int count; 233899a2dd95SBruce Richardson int ret; 233999a2dd95SBruce Richardson 234099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 234199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 234253ef1b34SMin Hu (Connor) 234399a2dd95SBruce Richardson if (tx_queue_id >= dev->data->nb_tx_queues) { 234499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", tx_queue_id); 234599a2dd95SBruce Richardson return -EINVAL; 234699a2dd95SBruce Richardson } 234753ef1b34SMin Hu (Connor) 234853ef1b34SMin Hu (Connor) if (conf == NULL) { 234953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 235053ef1b34SMin Hu (Connor) "Cannot setup ethdev port %u Tx hairpin queue from NULL config\n", 235153ef1b34SMin Hu (Connor) port_id); 235253ef1b34SMin Hu (Connor) return -EINVAL; 235353ef1b34SMin Hu (Connor) } 235453ef1b34SMin Hu (Connor) 235599a2dd95SBruce Richardson ret = rte_eth_dev_hairpin_capability_get(port_id, &cap); 235699a2dd95SBruce Richardson if (ret != 0) 235799a2dd95SBruce Richardson return ret; 235899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_hairpin_queue_setup, 235999a2dd95SBruce Richardson -ENOTSUP); 236099a2dd95SBruce Richardson /* if nb_rx_desc is zero use max number of desc from the driver. */ 236199a2dd95SBruce Richardson if (nb_tx_desc == 0) 236299a2dd95SBruce Richardson nb_tx_desc = cap.max_nb_desc; 236399a2dd95SBruce Richardson if (nb_tx_desc > cap.max_nb_desc) { 236499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 236599a2dd95SBruce Richardson "Invalid value for nb_tx_desc(=%hu), should be: <= %hu", 236699a2dd95SBruce Richardson nb_tx_desc, cap.max_nb_desc); 236799a2dd95SBruce Richardson return -EINVAL; 236899a2dd95SBruce Richardson } 236999a2dd95SBruce Richardson if (conf->peer_count > cap.max_tx_2_rx) { 237099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 237199a2dd95SBruce Richardson "Invalid value for number of peers for Tx queue(=%u), should be: <= %hu", 237299a2dd95SBruce Richardson conf->peer_count, cap.max_tx_2_rx); 237399a2dd95SBruce Richardson return -EINVAL; 237499a2dd95SBruce Richardson } 237599a2dd95SBruce Richardson if (conf->peer_count == 0) { 237699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 237799a2dd95SBruce Richardson "Invalid value for number of peers for Tx queue(=%u), should be: > 0", 237899a2dd95SBruce Richardson conf->peer_count); 237999a2dd95SBruce Richardson return -EINVAL; 238099a2dd95SBruce Richardson } 238199a2dd95SBruce Richardson for (i = 0, count = 0; i < dev->data->nb_tx_queues && 238299a2dd95SBruce Richardson cap.max_nb_queues != UINT16_MAX; i++) { 238399a2dd95SBruce Richardson if (i == tx_queue_id || rte_eth_dev_is_tx_hairpin_queue(dev, i)) 238499a2dd95SBruce Richardson count++; 238599a2dd95SBruce Richardson } 238699a2dd95SBruce Richardson if (count > cap.max_nb_queues) { 238799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "To many Tx hairpin queues max is %d", 238899a2dd95SBruce Richardson cap.max_nb_queues); 238999a2dd95SBruce Richardson return -EINVAL; 239099a2dd95SBruce Richardson } 239199a2dd95SBruce Richardson if (dev->data->dev_started) 239299a2dd95SBruce Richardson return -EBUSY; 239349ed3224SXueming Li eth_dev_txq_release(dev, tx_queue_id); 239499a2dd95SBruce Richardson ret = (*dev->dev_ops->tx_hairpin_queue_setup) 239599a2dd95SBruce Richardson (dev, tx_queue_id, nb_tx_desc, conf); 239699a2dd95SBruce Richardson if (ret == 0) 239799a2dd95SBruce Richardson dev->data->tx_queue_state[tx_queue_id] = 239899a2dd95SBruce Richardson RTE_ETH_QUEUE_STATE_HAIRPIN; 239999a2dd95SBruce Richardson return eth_err(port_id, ret); 240099a2dd95SBruce Richardson } 240199a2dd95SBruce Richardson 240299a2dd95SBruce Richardson int 240399a2dd95SBruce Richardson rte_eth_hairpin_bind(uint16_t tx_port, uint16_t rx_port) 240499a2dd95SBruce Richardson { 240599a2dd95SBruce Richardson struct rte_eth_dev *dev; 240699a2dd95SBruce Richardson int ret; 240799a2dd95SBruce Richardson 240899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV); 240999a2dd95SBruce Richardson dev = &rte_eth_devices[tx_port]; 241053ef1b34SMin Hu (Connor) 241199a2dd95SBruce Richardson if (dev->data->dev_started == 0) { 241299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Tx port %d is not started\n", tx_port); 241399a2dd95SBruce Richardson return -EBUSY; 241499a2dd95SBruce Richardson } 241599a2dd95SBruce Richardson 241699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_bind, -ENOTSUP); 241799a2dd95SBruce Richardson ret = (*dev->dev_ops->hairpin_bind)(dev, rx_port); 241899a2dd95SBruce Richardson if (ret != 0) 241999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Failed to bind hairpin Tx %d" 242099a2dd95SBruce Richardson " to Rx %d (%d - all ports)\n", 242199a2dd95SBruce Richardson tx_port, rx_port, RTE_MAX_ETHPORTS); 242299a2dd95SBruce Richardson 242399a2dd95SBruce Richardson return ret; 242499a2dd95SBruce Richardson } 242599a2dd95SBruce Richardson 242699a2dd95SBruce Richardson int 242799a2dd95SBruce Richardson rte_eth_hairpin_unbind(uint16_t tx_port, uint16_t rx_port) 242899a2dd95SBruce Richardson { 242999a2dd95SBruce Richardson struct rte_eth_dev *dev; 243099a2dd95SBruce Richardson int ret; 243199a2dd95SBruce Richardson 243299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(tx_port, -ENODEV); 243399a2dd95SBruce Richardson dev = &rte_eth_devices[tx_port]; 243453ef1b34SMin Hu (Connor) 243599a2dd95SBruce Richardson if (dev->data->dev_started == 0) { 243699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Tx port %d is already stopped\n", tx_port); 243799a2dd95SBruce Richardson return -EBUSY; 243899a2dd95SBruce Richardson } 243999a2dd95SBruce Richardson 244099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_unbind, -ENOTSUP); 244199a2dd95SBruce Richardson ret = (*dev->dev_ops->hairpin_unbind)(dev, rx_port); 244299a2dd95SBruce Richardson if (ret != 0) 244399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Failed to unbind hairpin Tx %d" 244499a2dd95SBruce Richardson " from Rx %d (%d - all ports)\n", 244599a2dd95SBruce Richardson tx_port, rx_port, RTE_MAX_ETHPORTS); 244699a2dd95SBruce Richardson 244799a2dd95SBruce Richardson return ret; 244899a2dd95SBruce Richardson } 244999a2dd95SBruce Richardson 245099a2dd95SBruce Richardson int 245199a2dd95SBruce Richardson rte_eth_hairpin_get_peer_ports(uint16_t port_id, uint16_t *peer_ports, 245299a2dd95SBruce Richardson size_t len, uint32_t direction) 245399a2dd95SBruce Richardson { 245499a2dd95SBruce Richardson struct rte_eth_dev *dev; 245599a2dd95SBruce Richardson int ret; 245699a2dd95SBruce Richardson 245799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 245899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 245953ef1b34SMin Hu (Connor) 246053ef1b34SMin Hu (Connor) if (peer_ports == NULL) { 246153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 246253ef1b34SMin Hu (Connor) "Cannot get ethdev port %u hairpin peer ports to NULL\n", 246353ef1b34SMin Hu (Connor) port_id); 246453ef1b34SMin Hu (Connor) return -EINVAL; 246553ef1b34SMin Hu (Connor) } 246653ef1b34SMin Hu (Connor) 246753ef1b34SMin Hu (Connor) if (len == 0) { 246853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 246953ef1b34SMin Hu (Connor) "Cannot get ethdev port %u hairpin peer ports to array with zero size\n", 247053ef1b34SMin Hu (Connor) port_id); 247153ef1b34SMin Hu (Connor) return -EINVAL; 247253ef1b34SMin Hu (Connor) } 247353ef1b34SMin Hu (Connor) 247499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_get_peer_ports, 247599a2dd95SBruce Richardson -ENOTSUP); 247699a2dd95SBruce Richardson 247799a2dd95SBruce Richardson ret = (*dev->dev_ops->hairpin_get_peer_ports)(dev, peer_ports, 247899a2dd95SBruce Richardson len, direction); 247999a2dd95SBruce Richardson if (ret < 0) 248099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Failed to get %d hairpin peer %s ports\n", 248199a2dd95SBruce Richardson port_id, direction ? "Rx" : "Tx"); 248299a2dd95SBruce Richardson 248399a2dd95SBruce Richardson return ret; 248499a2dd95SBruce Richardson } 248599a2dd95SBruce Richardson 248699a2dd95SBruce Richardson void 248799a2dd95SBruce Richardson rte_eth_tx_buffer_drop_callback(struct rte_mbuf **pkts, uint16_t unsent, 248899a2dd95SBruce Richardson void *userdata __rte_unused) 248999a2dd95SBruce Richardson { 249099a2dd95SBruce Richardson rte_pktmbuf_free_bulk(pkts, unsent); 249199a2dd95SBruce Richardson } 249299a2dd95SBruce Richardson 249399a2dd95SBruce Richardson void 249499a2dd95SBruce Richardson rte_eth_tx_buffer_count_callback(struct rte_mbuf **pkts, uint16_t unsent, 249599a2dd95SBruce Richardson void *userdata) 249699a2dd95SBruce Richardson { 249799a2dd95SBruce Richardson uint64_t *count = userdata; 249899a2dd95SBruce Richardson 249999a2dd95SBruce Richardson rte_pktmbuf_free_bulk(pkts, unsent); 250099a2dd95SBruce Richardson *count += unsent; 250199a2dd95SBruce Richardson } 250299a2dd95SBruce Richardson 250399a2dd95SBruce Richardson int 250499a2dd95SBruce Richardson rte_eth_tx_buffer_set_err_callback(struct rte_eth_dev_tx_buffer *buffer, 250599a2dd95SBruce Richardson buffer_tx_error_fn cbfn, void *userdata) 250699a2dd95SBruce Richardson { 250753ef1b34SMin Hu (Connor) if (buffer == NULL) { 250853ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 250953ef1b34SMin Hu (Connor) "Cannot set Tx buffer error callback to NULL buffer\n"); 251053ef1b34SMin Hu (Connor) return -EINVAL; 251153ef1b34SMin Hu (Connor) } 251253ef1b34SMin Hu (Connor) 251399a2dd95SBruce Richardson buffer->error_callback = cbfn; 251499a2dd95SBruce Richardson buffer->error_userdata = userdata; 251599a2dd95SBruce Richardson return 0; 251699a2dd95SBruce Richardson } 251799a2dd95SBruce Richardson 251899a2dd95SBruce Richardson int 251999a2dd95SBruce Richardson rte_eth_tx_buffer_init(struct rte_eth_dev_tx_buffer *buffer, uint16_t size) 252099a2dd95SBruce Richardson { 252199a2dd95SBruce Richardson int ret = 0; 252299a2dd95SBruce Richardson 252353ef1b34SMin Hu (Connor) if (buffer == NULL) { 252453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot initialize NULL buffer\n"); 252599a2dd95SBruce Richardson return -EINVAL; 252653ef1b34SMin Hu (Connor) } 252799a2dd95SBruce Richardson 252899a2dd95SBruce Richardson buffer->size = size; 252999a2dd95SBruce Richardson if (buffer->error_callback == NULL) { 253099a2dd95SBruce Richardson ret = rte_eth_tx_buffer_set_err_callback( 253199a2dd95SBruce Richardson buffer, rte_eth_tx_buffer_drop_callback, NULL); 253299a2dd95SBruce Richardson } 253399a2dd95SBruce Richardson 253499a2dd95SBruce Richardson return ret; 253599a2dd95SBruce Richardson } 253699a2dd95SBruce Richardson 253799a2dd95SBruce Richardson int 253899a2dd95SBruce Richardson rte_eth_tx_done_cleanup(uint16_t port_id, uint16_t queue_id, uint32_t free_cnt) 253999a2dd95SBruce Richardson { 254053ef1b34SMin Hu (Connor) struct rte_eth_dev *dev; 254199a2dd95SBruce Richardson int ret; 254299a2dd95SBruce Richardson 254399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 254453ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 254553ef1b34SMin Hu (Connor) 254699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_done_cleanup, -ENOTSUP); 254799a2dd95SBruce Richardson 254899a2dd95SBruce Richardson /* Call driver to free pending mbufs. */ 254999a2dd95SBruce Richardson ret = (*dev->dev_ops->tx_done_cleanup)(dev->data->tx_queues[queue_id], 255099a2dd95SBruce Richardson free_cnt); 255199a2dd95SBruce Richardson return eth_err(port_id, ret); 255299a2dd95SBruce Richardson } 255399a2dd95SBruce Richardson 255499a2dd95SBruce Richardson int 255599a2dd95SBruce Richardson rte_eth_promiscuous_enable(uint16_t port_id) 255699a2dd95SBruce Richardson { 255799a2dd95SBruce Richardson struct rte_eth_dev *dev; 255899a2dd95SBruce Richardson int diag = 0; 255999a2dd95SBruce Richardson 256099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 256199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 256299a2dd95SBruce Richardson 256399a2dd95SBruce Richardson if (dev->data->promiscuous == 1) 256499a2dd95SBruce Richardson return 0; 256599a2dd95SBruce Richardson 256699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_enable, -ENOTSUP); 256799a2dd95SBruce Richardson 256899a2dd95SBruce Richardson diag = (*dev->dev_ops->promiscuous_enable)(dev); 256999a2dd95SBruce Richardson dev->data->promiscuous = (diag == 0) ? 1 : 0; 257099a2dd95SBruce Richardson 257199a2dd95SBruce Richardson return eth_err(port_id, diag); 257299a2dd95SBruce Richardson } 257399a2dd95SBruce Richardson 257499a2dd95SBruce Richardson int 257599a2dd95SBruce Richardson rte_eth_promiscuous_disable(uint16_t port_id) 257699a2dd95SBruce Richardson { 257799a2dd95SBruce Richardson struct rte_eth_dev *dev; 257899a2dd95SBruce Richardson int diag = 0; 257999a2dd95SBruce Richardson 258099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 258199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 258299a2dd95SBruce Richardson 258399a2dd95SBruce Richardson if (dev->data->promiscuous == 0) 258499a2dd95SBruce Richardson return 0; 258599a2dd95SBruce Richardson 258699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->promiscuous_disable, -ENOTSUP); 258799a2dd95SBruce Richardson 258899a2dd95SBruce Richardson dev->data->promiscuous = 0; 258999a2dd95SBruce Richardson diag = (*dev->dev_ops->promiscuous_disable)(dev); 259099a2dd95SBruce Richardson if (diag != 0) 259199a2dd95SBruce Richardson dev->data->promiscuous = 1; 259299a2dd95SBruce Richardson 259399a2dd95SBruce Richardson return eth_err(port_id, diag); 259499a2dd95SBruce Richardson } 259599a2dd95SBruce Richardson 259699a2dd95SBruce Richardson int 259799a2dd95SBruce Richardson rte_eth_promiscuous_get(uint16_t port_id) 259899a2dd95SBruce Richardson { 259999a2dd95SBruce Richardson struct rte_eth_dev *dev; 260099a2dd95SBruce Richardson 260199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 260299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 260353ef1b34SMin Hu (Connor) 260499a2dd95SBruce Richardson return dev->data->promiscuous; 260599a2dd95SBruce Richardson } 260699a2dd95SBruce Richardson 260799a2dd95SBruce Richardson int 260899a2dd95SBruce Richardson rte_eth_allmulticast_enable(uint16_t port_id) 260999a2dd95SBruce Richardson { 261099a2dd95SBruce Richardson struct rte_eth_dev *dev; 261199a2dd95SBruce Richardson int diag; 261299a2dd95SBruce Richardson 261399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 261499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 261599a2dd95SBruce Richardson 261699a2dd95SBruce Richardson if (dev->data->all_multicast == 1) 261799a2dd95SBruce Richardson return 0; 261899a2dd95SBruce Richardson 261999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_enable, -ENOTSUP); 262099a2dd95SBruce Richardson diag = (*dev->dev_ops->allmulticast_enable)(dev); 262199a2dd95SBruce Richardson dev->data->all_multicast = (diag == 0) ? 1 : 0; 262299a2dd95SBruce Richardson 262399a2dd95SBruce Richardson return eth_err(port_id, diag); 262499a2dd95SBruce Richardson } 262599a2dd95SBruce Richardson 262699a2dd95SBruce Richardson int 262799a2dd95SBruce Richardson rte_eth_allmulticast_disable(uint16_t port_id) 262899a2dd95SBruce Richardson { 262999a2dd95SBruce Richardson struct rte_eth_dev *dev; 263099a2dd95SBruce Richardson int diag; 263199a2dd95SBruce Richardson 263299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 263399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 263499a2dd95SBruce Richardson 263599a2dd95SBruce Richardson if (dev->data->all_multicast == 0) 263699a2dd95SBruce Richardson return 0; 263799a2dd95SBruce Richardson 263899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_disable, -ENOTSUP); 263999a2dd95SBruce Richardson dev->data->all_multicast = 0; 264099a2dd95SBruce Richardson diag = (*dev->dev_ops->allmulticast_disable)(dev); 264199a2dd95SBruce Richardson if (diag != 0) 264299a2dd95SBruce Richardson dev->data->all_multicast = 1; 264399a2dd95SBruce Richardson 264499a2dd95SBruce Richardson return eth_err(port_id, diag); 264599a2dd95SBruce Richardson } 264699a2dd95SBruce Richardson 264799a2dd95SBruce Richardson int 264899a2dd95SBruce Richardson rte_eth_allmulticast_get(uint16_t port_id) 264999a2dd95SBruce Richardson { 265099a2dd95SBruce Richardson struct rte_eth_dev *dev; 265199a2dd95SBruce Richardson 265299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 265399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 265453ef1b34SMin Hu (Connor) 265599a2dd95SBruce Richardson return dev->data->all_multicast; 265699a2dd95SBruce Richardson } 265799a2dd95SBruce Richardson 265899a2dd95SBruce Richardson int 265999a2dd95SBruce Richardson rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link) 266099a2dd95SBruce Richardson { 266199a2dd95SBruce Richardson struct rte_eth_dev *dev; 266299a2dd95SBruce Richardson 266399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 266499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 266599a2dd95SBruce Richardson 266653ef1b34SMin Hu (Connor) if (eth_link == NULL) { 266753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u link to NULL\n", 266853ef1b34SMin Hu (Connor) port_id); 266953ef1b34SMin Hu (Connor) return -EINVAL; 267053ef1b34SMin Hu (Connor) } 267153ef1b34SMin Hu (Connor) 267253ef1b34SMin Hu (Connor) if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started) 267399a2dd95SBruce Richardson rte_eth_linkstatus_get(dev, eth_link); 267499a2dd95SBruce Richardson else { 267599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); 267699a2dd95SBruce Richardson (*dev->dev_ops->link_update)(dev, 1); 267799a2dd95SBruce Richardson *eth_link = dev->data->dev_link; 267899a2dd95SBruce Richardson } 267999a2dd95SBruce Richardson 268099a2dd95SBruce Richardson return 0; 268199a2dd95SBruce Richardson } 268299a2dd95SBruce Richardson 268399a2dd95SBruce Richardson int 268499a2dd95SBruce Richardson rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link) 268599a2dd95SBruce Richardson { 268699a2dd95SBruce Richardson struct rte_eth_dev *dev; 268799a2dd95SBruce Richardson 268899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 268999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 269099a2dd95SBruce Richardson 269153ef1b34SMin Hu (Connor) if (eth_link == NULL) { 269253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u link to NULL\n", 269353ef1b34SMin Hu (Connor) port_id); 269453ef1b34SMin Hu (Connor) return -EINVAL; 269553ef1b34SMin Hu (Connor) } 269653ef1b34SMin Hu (Connor) 269753ef1b34SMin Hu (Connor) if (dev->data->dev_conf.intr_conf.lsc && dev->data->dev_started) 269899a2dd95SBruce Richardson rte_eth_linkstatus_get(dev, eth_link); 269999a2dd95SBruce Richardson else { 270099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP); 270199a2dd95SBruce Richardson (*dev->dev_ops->link_update)(dev, 0); 270299a2dd95SBruce Richardson *eth_link = dev->data->dev_link; 270399a2dd95SBruce Richardson } 270499a2dd95SBruce Richardson 270599a2dd95SBruce Richardson return 0; 270699a2dd95SBruce Richardson } 270799a2dd95SBruce Richardson 270899a2dd95SBruce Richardson const char * 270999a2dd95SBruce Richardson rte_eth_link_speed_to_str(uint32_t link_speed) 271099a2dd95SBruce Richardson { 271199a2dd95SBruce Richardson switch (link_speed) { 271299a2dd95SBruce Richardson case ETH_SPEED_NUM_NONE: return "None"; 271399a2dd95SBruce Richardson case ETH_SPEED_NUM_10M: return "10 Mbps"; 271499a2dd95SBruce Richardson case ETH_SPEED_NUM_100M: return "100 Mbps"; 271599a2dd95SBruce Richardson case ETH_SPEED_NUM_1G: return "1 Gbps"; 271699a2dd95SBruce Richardson case ETH_SPEED_NUM_2_5G: return "2.5 Gbps"; 271799a2dd95SBruce Richardson case ETH_SPEED_NUM_5G: return "5 Gbps"; 271899a2dd95SBruce Richardson case ETH_SPEED_NUM_10G: return "10 Gbps"; 271999a2dd95SBruce Richardson case ETH_SPEED_NUM_20G: return "20 Gbps"; 272099a2dd95SBruce Richardson case ETH_SPEED_NUM_25G: return "25 Gbps"; 272199a2dd95SBruce Richardson case ETH_SPEED_NUM_40G: return "40 Gbps"; 272299a2dd95SBruce Richardson case ETH_SPEED_NUM_50G: return "50 Gbps"; 272399a2dd95SBruce Richardson case ETH_SPEED_NUM_56G: return "56 Gbps"; 272499a2dd95SBruce Richardson case ETH_SPEED_NUM_100G: return "100 Gbps"; 272599a2dd95SBruce Richardson case ETH_SPEED_NUM_200G: return "200 Gbps"; 272699a2dd95SBruce Richardson case ETH_SPEED_NUM_UNKNOWN: return "Unknown"; 272799a2dd95SBruce Richardson default: return "Invalid"; 272899a2dd95SBruce Richardson } 272999a2dd95SBruce Richardson } 273099a2dd95SBruce Richardson 273199a2dd95SBruce Richardson int 273299a2dd95SBruce Richardson rte_eth_link_to_str(char *str, size_t len, const struct rte_eth_link *eth_link) 273399a2dd95SBruce Richardson { 273453ef1b34SMin Hu (Connor) if (str == NULL) { 273553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot convert link to NULL string\n"); 273653ef1b34SMin Hu (Connor) return -EINVAL; 273753ef1b34SMin Hu (Connor) } 273853ef1b34SMin Hu (Connor) 273953ef1b34SMin Hu (Connor) if (len == 0) { 274053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 274153ef1b34SMin Hu (Connor) "Cannot convert link to string with zero size\n"); 274253ef1b34SMin Hu (Connor) return -EINVAL; 274353ef1b34SMin Hu (Connor) } 274453ef1b34SMin Hu (Connor) 274553ef1b34SMin Hu (Connor) if (eth_link == NULL) { 274653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot convert to string from NULL link\n"); 274753ef1b34SMin Hu (Connor) return -EINVAL; 274853ef1b34SMin Hu (Connor) } 274953ef1b34SMin Hu (Connor) 275099a2dd95SBruce Richardson if (eth_link->link_status == ETH_LINK_DOWN) 275199a2dd95SBruce Richardson return snprintf(str, len, "Link down"); 275299a2dd95SBruce Richardson else 275399a2dd95SBruce Richardson return snprintf(str, len, "Link up at %s %s %s", 275499a2dd95SBruce Richardson rte_eth_link_speed_to_str(eth_link->link_speed), 275599a2dd95SBruce Richardson (eth_link->link_duplex == ETH_LINK_FULL_DUPLEX) ? 275699a2dd95SBruce Richardson "FDX" : "HDX", 275799a2dd95SBruce Richardson (eth_link->link_autoneg == ETH_LINK_AUTONEG) ? 275899a2dd95SBruce Richardson "Autoneg" : "Fixed"); 275999a2dd95SBruce Richardson } 276099a2dd95SBruce Richardson 276199a2dd95SBruce Richardson int 276299a2dd95SBruce Richardson rte_eth_stats_get(uint16_t port_id, struct rte_eth_stats *stats) 276399a2dd95SBruce Richardson { 276499a2dd95SBruce Richardson struct rte_eth_dev *dev; 276599a2dd95SBruce Richardson 276699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 276799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 276853ef1b34SMin Hu (Connor) 276953ef1b34SMin Hu (Connor) if (stats == NULL) { 277053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u stats to NULL\n", 277153ef1b34SMin Hu (Connor) port_id); 277253ef1b34SMin Hu (Connor) return -EINVAL; 277353ef1b34SMin Hu (Connor) } 277453ef1b34SMin Hu (Connor) 277599a2dd95SBruce Richardson memset(stats, 0, sizeof(*stats)); 277699a2dd95SBruce Richardson 277799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_get, -ENOTSUP); 277899a2dd95SBruce Richardson stats->rx_nombuf = dev->data->rx_mbuf_alloc_failed; 277999a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->stats_get)(dev, stats)); 278099a2dd95SBruce Richardson } 278199a2dd95SBruce Richardson 278299a2dd95SBruce Richardson int 278399a2dd95SBruce Richardson rte_eth_stats_reset(uint16_t port_id) 278499a2dd95SBruce Richardson { 278599a2dd95SBruce Richardson struct rte_eth_dev *dev; 278699a2dd95SBruce Richardson int ret; 278799a2dd95SBruce Richardson 278899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 278999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 279099a2dd95SBruce Richardson 279199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->stats_reset, -ENOTSUP); 279299a2dd95SBruce Richardson ret = (*dev->dev_ops->stats_reset)(dev); 279399a2dd95SBruce Richardson if (ret != 0) 279499a2dd95SBruce Richardson return eth_err(port_id, ret); 279599a2dd95SBruce Richardson 279699a2dd95SBruce Richardson dev->data->rx_mbuf_alloc_failed = 0; 279799a2dd95SBruce Richardson 279899a2dd95SBruce Richardson return 0; 279999a2dd95SBruce Richardson } 280099a2dd95SBruce Richardson 280199a2dd95SBruce Richardson static inline int 280299a2dd95SBruce Richardson eth_dev_get_xstats_basic_count(struct rte_eth_dev *dev) 280399a2dd95SBruce Richardson { 280499a2dd95SBruce Richardson uint16_t nb_rxqs, nb_txqs; 280599a2dd95SBruce Richardson int count; 280699a2dd95SBruce Richardson 280799a2dd95SBruce Richardson nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 280899a2dd95SBruce Richardson nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 280999a2dd95SBruce Richardson 281099a2dd95SBruce Richardson count = RTE_NB_STATS; 281199a2dd95SBruce Richardson if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) { 281299a2dd95SBruce Richardson count += nb_rxqs * RTE_NB_RXQ_STATS; 281399a2dd95SBruce Richardson count += nb_txqs * RTE_NB_TXQ_STATS; 281499a2dd95SBruce Richardson } 281599a2dd95SBruce Richardson 281699a2dd95SBruce Richardson return count; 281799a2dd95SBruce Richardson } 281899a2dd95SBruce Richardson 281999a2dd95SBruce Richardson static int 282099a2dd95SBruce Richardson eth_dev_get_xstats_count(uint16_t port_id) 282199a2dd95SBruce Richardson { 282299a2dd95SBruce Richardson struct rte_eth_dev *dev; 282399a2dd95SBruce Richardson int count; 282499a2dd95SBruce Richardson 282599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 282699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 282799a2dd95SBruce Richardson if (dev->dev_ops->xstats_get_names != NULL) { 282899a2dd95SBruce Richardson count = (*dev->dev_ops->xstats_get_names)(dev, NULL, 0); 282999a2dd95SBruce Richardson if (count < 0) 283099a2dd95SBruce Richardson return eth_err(port_id, count); 283199a2dd95SBruce Richardson } else 283299a2dd95SBruce Richardson count = 0; 283399a2dd95SBruce Richardson 283499a2dd95SBruce Richardson 283599a2dd95SBruce Richardson count += eth_dev_get_xstats_basic_count(dev); 283699a2dd95SBruce Richardson 283799a2dd95SBruce Richardson return count; 283899a2dd95SBruce Richardson } 283999a2dd95SBruce Richardson 284099a2dd95SBruce Richardson int 284199a2dd95SBruce Richardson rte_eth_xstats_get_id_by_name(uint16_t port_id, const char *xstat_name, 284299a2dd95SBruce Richardson uint64_t *id) 284399a2dd95SBruce Richardson { 284499a2dd95SBruce Richardson int cnt_xstats, idx_xstat; 284599a2dd95SBruce Richardson 284699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 284799a2dd95SBruce Richardson 284853ef1b34SMin Hu (Connor) if (xstat_name == NULL) { 284953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 285053ef1b34SMin Hu (Connor) "Cannot get ethdev port %u xstats ID from NULL xstat name\n", 285153ef1b34SMin Hu (Connor) port_id); 285299a2dd95SBruce Richardson return -ENOMEM; 285399a2dd95SBruce Richardson } 285499a2dd95SBruce Richardson 285553ef1b34SMin Hu (Connor) if (id == NULL) { 285653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 285753ef1b34SMin Hu (Connor) "Cannot get ethdev port %u xstats ID to NULL\n", 285853ef1b34SMin Hu (Connor) port_id); 285999a2dd95SBruce Richardson return -ENOMEM; 286099a2dd95SBruce Richardson } 286199a2dd95SBruce Richardson 286299a2dd95SBruce Richardson /* Get count */ 286399a2dd95SBruce Richardson cnt_xstats = rte_eth_xstats_get_names_by_id(port_id, NULL, 0, NULL); 286499a2dd95SBruce Richardson if (cnt_xstats < 0) { 286599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Cannot get count of xstats\n"); 286699a2dd95SBruce Richardson return -ENODEV; 286799a2dd95SBruce Richardson } 286899a2dd95SBruce Richardson 286999a2dd95SBruce Richardson /* Get id-name lookup table */ 287099a2dd95SBruce Richardson struct rte_eth_xstat_name xstats_names[cnt_xstats]; 287199a2dd95SBruce Richardson 287299a2dd95SBruce Richardson if (cnt_xstats != rte_eth_xstats_get_names_by_id( 287399a2dd95SBruce Richardson port_id, xstats_names, cnt_xstats, NULL)) { 287499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Cannot get xstats lookup\n"); 287599a2dd95SBruce Richardson return -1; 287699a2dd95SBruce Richardson } 287799a2dd95SBruce Richardson 287899a2dd95SBruce Richardson for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { 287999a2dd95SBruce Richardson if (!strcmp(xstats_names[idx_xstat].name, xstat_name)) { 288099a2dd95SBruce Richardson *id = idx_xstat; 288199a2dd95SBruce Richardson return 0; 288299a2dd95SBruce Richardson }; 288399a2dd95SBruce Richardson } 288499a2dd95SBruce Richardson 288599a2dd95SBruce Richardson return -EINVAL; 288699a2dd95SBruce Richardson } 288799a2dd95SBruce Richardson 288899a2dd95SBruce Richardson /* retrieve basic stats names */ 288999a2dd95SBruce Richardson static int 289099a2dd95SBruce Richardson eth_basic_stats_get_names(struct rte_eth_dev *dev, 289199a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names) 289299a2dd95SBruce Richardson { 289399a2dd95SBruce Richardson int cnt_used_entries = 0; 289499a2dd95SBruce Richardson uint32_t idx, id_queue; 289599a2dd95SBruce Richardson uint16_t num_q; 289699a2dd95SBruce Richardson 289799a2dd95SBruce Richardson for (idx = 0; idx < RTE_NB_STATS; idx++) { 289899a2dd95SBruce Richardson strlcpy(xstats_names[cnt_used_entries].name, 289999a2dd95SBruce Richardson eth_dev_stats_strings[idx].name, 290099a2dd95SBruce Richardson sizeof(xstats_names[0].name)); 290199a2dd95SBruce Richardson cnt_used_entries++; 290299a2dd95SBruce Richardson } 290399a2dd95SBruce Richardson 290499a2dd95SBruce Richardson if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0) 290599a2dd95SBruce Richardson return cnt_used_entries; 290699a2dd95SBruce Richardson 290799a2dd95SBruce Richardson num_q = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 290899a2dd95SBruce Richardson for (id_queue = 0; id_queue < num_q; id_queue++) { 290999a2dd95SBruce Richardson for (idx = 0; idx < RTE_NB_RXQ_STATS; idx++) { 291099a2dd95SBruce Richardson snprintf(xstats_names[cnt_used_entries].name, 291199a2dd95SBruce Richardson sizeof(xstats_names[0].name), 291299a2dd95SBruce Richardson "rx_q%u_%s", 291399a2dd95SBruce Richardson id_queue, eth_dev_rxq_stats_strings[idx].name); 291499a2dd95SBruce Richardson cnt_used_entries++; 291599a2dd95SBruce Richardson } 291699a2dd95SBruce Richardson 291799a2dd95SBruce Richardson } 291899a2dd95SBruce Richardson num_q = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 291999a2dd95SBruce Richardson for (id_queue = 0; id_queue < num_q; id_queue++) { 292099a2dd95SBruce Richardson for (idx = 0; idx < RTE_NB_TXQ_STATS; idx++) { 292199a2dd95SBruce Richardson snprintf(xstats_names[cnt_used_entries].name, 292299a2dd95SBruce Richardson sizeof(xstats_names[0].name), 292399a2dd95SBruce Richardson "tx_q%u_%s", 292499a2dd95SBruce Richardson id_queue, eth_dev_txq_stats_strings[idx].name); 292599a2dd95SBruce Richardson cnt_used_entries++; 292699a2dd95SBruce Richardson } 292799a2dd95SBruce Richardson } 292899a2dd95SBruce Richardson return cnt_used_entries; 292999a2dd95SBruce Richardson } 293099a2dd95SBruce Richardson 293199a2dd95SBruce Richardson /* retrieve ethdev extended statistics names */ 293299a2dd95SBruce Richardson int 293399a2dd95SBruce Richardson rte_eth_xstats_get_names_by_id(uint16_t port_id, 293499a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names, unsigned int size, 293599a2dd95SBruce Richardson uint64_t *ids) 293699a2dd95SBruce Richardson { 293799a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names_copy; 293899a2dd95SBruce Richardson unsigned int no_basic_stat_requested = 1; 293999a2dd95SBruce Richardson unsigned int no_ext_stat_requested = 1; 294099a2dd95SBruce Richardson unsigned int expected_entries; 294199a2dd95SBruce Richardson unsigned int basic_count; 294299a2dd95SBruce Richardson struct rte_eth_dev *dev; 294399a2dd95SBruce Richardson unsigned int i; 294499a2dd95SBruce Richardson int ret; 294599a2dd95SBruce Richardson 294699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 294799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 294899a2dd95SBruce Richardson 294999a2dd95SBruce Richardson basic_count = eth_dev_get_xstats_basic_count(dev); 295099a2dd95SBruce Richardson ret = eth_dev_get_xstats_count(port_id); 295199a2dd95SBruce Richardson if (ret < 0) 295299a2dd95SBruce Richardson return ret; 295399a2dd95SBruce Richardson expected_entries = (unsigned int)ret; 295499a2dd95SBruce Richardson 295599a2dd95SBruce Richardson /* Return max number of stats if no ids given */ 295699a2dd95SBruce Richardson if (!ids) { 295799a2dd95SBruce Richardson if (!xstats_names) 295899a2dd95SBruce Richardson return expected_entries; 295999a2dd95SBruce Richardson else if (xstats_names && size < expected_entries) 296099a2dd95SBruce Richardson return expected_entries; 296199a2dd95SBruce Richardson } 296299a2dd95SBruce Richardson 296399a2dd95SBruce Richardson if (ids && !xstats_names) 296499a2dd95SBruce Richardson return -EINVAL; 296599a2dd95SBruce Richardson 296699a2dd95SBruce Richardson if (ids && dev->dev_ops->xstats_get_names_by_id != NULL && size > 0) { 296799a2dd95SBruce Richardson uint64_t ids_copy[size]; 296899a2dd95SBruce Richardson 296999a2dd95SBruce Richardson for (i = 0; i < size; i++) { 297099a2dd95SBruce Richardson if (ids[i] < basic_count) { 297199a2dd95SBruce Richardson no_basic_stat_requested = 0; 297299a2dd95SBruce Richardson break; 297399a2dd95SBruce Richardson } 297499a2dd95SBruce Richardson 297599a2dd95SBruce Richardson /* 297699a2dd95SBruce Richardson * Convert ids to xstats ids that PMD knows. 297799a2dd95SBruce Richardson * ids known by user are basic + extended stats. 297899a2dd95SBruce Richardson */ 297999a2dd95SBruce Richardson ids_copy[i] = ids[i] - basic_count; 298099a2dd95SBruce Richardson } 298199a2dd95SBruce Richardson 298299a2dd95SBruce Richardson if (no_basic_stat_requested) 298399a2dd95SBruce Richardson return (*dev->dev_ops->xstats_get_names_by_id)(dev, 29848c9f976fSAndrew Rybchenko ids_copy, xstats_names, size); 298599a2dd95SBruce Richardson } 298699a2dd95SBruce Richardson 298799a2dd95SBruce Richardson /* Retrieve all stats */ 298899a2dd95SBruce Richardson if (!ids) { 298999a2dd95SBruce Richardson int num_stats = rte_eth_xstats_get_names(port_id, xstats_names, 299099a2dd95SBruce Richardson expected_entries); 299199a2dd95SBruce Richardson if (num_stats < 0 || num_stats > (int)expected_entries) 299299a2dd95SBruce Richardson return num_stats; 299399a2dd95SBruce Richardson else 299499a2dd95SBruce Richardson return expected_entries; 299599a2dd95SBruce Richardson } 299699a2dd95SBruce Richardson 299799a2dd95SBruce Richardson xstats_names_copy = calloc(expected_entries, 299899a2dd95SBruce Richardson sizeof(struct rte_eth_xstat_name)); 299999a2dd95SBruce Richardson 300099a2dd95SBruce Richardson if (!xstats_names_copy) { 300199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Can't allocate memory\n"); 300299a2dd95SBruce Richardson return -ENOMEM; 300399a2dd95SBruce Richardson } 300499a2dd95SBruce Richardson 300599a2dd95SBruce Richardson if (ids) { 300699a2dd95SBruce Richardson for (i = 0; i < size; i++) { 300799a2dd95SBruce Richardson if (ids[i] >= basic_count) { 300899a2dd95SBruce Richardson no_ext_stat_requested = 0; 300999a2dd95SBruce Richardson break; 301099a2dd95SBruce Richardson } 301199a2dd95SBruce Richardson } 301299a2dd95SBruce Richardson } 301399a2dd95SBruce Richardson 301499a2dd95SBruce Richardson /* Fill xstats_names_copy structure */ 301599a2dd95SBruce Richardson if (ids && no_ext_stat_requested) { 301699a2dd95SBruce Richardson eth_basic_stats_get_names(dev, xstats_names_copy); 301799a2dd95SBruce Richardson } else { 301899a2dd95SBruce Richardson ret = rte_eth_xstats_get_names(port_id, xstats_names_copy, 301999a2dd95SBruce Richardson expected_entries); 302099a2dd95SBruce Richardson if (ret < 0) { 302199a2dd95SBruce Richardson free(xstats_names_copy); 302299a2dd95SBruce Richardson return ret; 302399a2dd95SBruce Richardson } 302499a2dd95SBruce Richardson } 302599a2dd95SBruce Richardson 302699a2dd95SBruce Richardson /* Filter stats */ 302799a2dd95SBruce Richardson for (i = 0; i < size; i++) { 302899a2dd95SBruce Richardson if (ids[i] >= expected_entries) { 302999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n"); 303099a2dd95SBruce Richardson free(xstats_names_copy); 303199a2dd95SBruce Richardson return -1; 303299a2dd95SBruce Richardson } 303399a2dd95SBruce Richardson xstats_names[i] = xstats_names_copy[ids[i]]; 303499a2dd95SBruce Richardson } 303599a2dd95SBruce Richardson 303699a2dd95SBruce Richardson free(xstats_names_copy); 303799a2dd95SBruce Richardson return size; 303899a2dd95SBruce Richardson } 303999a2dd95SBruce Richardson 304099a2dd95SBruce Richardson int 304199a2dd95SBruce Richardson rte_eth_xstats_get_names(uint16_t port_id, 304299a2dd95SBruce Richardson struct rte_eth_xstat_name *xstats_names, 304399a2dd95SBruce Richardson unsigned int size) 304499a2dd95SBruce Richardson { 304599a2dd95SBruce Richardson struct rte_eth_dev *dev; 304699a2dd95SBruce Richardson int cnt_used_entries; 304799a2dd95SBruce Richardson int cnt_expected_entries; 304899a2dd95SBruce Richardson int cnt_driver_entries; 304999a2dd95SBruce Richardson 305099a2dd95SBruce Richardson cnt_expected_entries = eth_dev_get_xstats_count(port_id); 305199a2dd95SBruce Richardson if (xstats_names == NULL || cnt_expected_entries < 0 || 305299a2dd95SBruce Richardson (int)size < cnt_expected_entries) 305399a2dd95SBruce Richardson return cnt_expected_entries; 305499a2dd95SBruce Richardson 305599a2dd95SBruce Richardson /* port_id checked in eth_dev_get_xstats_count() */ 305699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 305799a2dd95SBruce Richardson 305899a2dd95SBruce Richardson cnt_used_entries = eth_basic_stats_get_names(dev, xstats_names); 305999a2dd95SBruce Richardson 306099a2dd95SBruce Richardson if (dev->dev_ops->xstats_get_names != NULL) { 306199a2dd95SBruce Richardson /* If there are any driver-specific xstats, append them 306299a2dd95SBruce Richardson * to end of list. 306399a2dd95SBruce Richardson */ 306499a2dd95SBruce Richardson cnt_driver_entries = (*dev->dev_ops->xstats_get_names)( 306599a2dd95SBruce Richardson dev, 306699a2dd95SBruce Richardson xstats_names + cnt_used_entries, 306799a2dd95SBruce Richardson size - cnt_used_entries); 306899a2dd95SBruce Richardson if (cnt_driver_entries < 0) 306999a2dd95SBruce Richardson return eth_err(port_id, cnt_driver_entries); 307099a2dd95SBruce Richardson cnt_used_entries += cnt_driver_entries; 307199a2dd95SBruce Richardson } 307299a2dd95SBruce Richardson 307399a2dd95SBruce Richardson return cnt_used_entries; 307499a2dd95SBruce Richardson } 307599a2dd95SBruce Richardson 307699a2dd95SBruce Richardson 307799a2dd95SBruce Richardson static int 307899a2dd95SBruce Richardson eth_basic_stats_get(uint16_t port_id, struct rte_eth_xstat *xstats) 307999a2dd95SBruce Richardson { 308099a2dd95SBruce Richardson struct rte_eth_dev *dev; 308199a2dd95SBruce Richardson struct rte_eth_stats eth_stats; 308299a2dd95SBruce Richardson unsigned int count = 0, i, q; 308399a2dd95SBruce Richardson uint64_t val, *stats_ptr; 308499a2dd95SBruce Richardson uint16_t nb_rxqs, nb_txqs; 308599a2dd95SBruce Richardson int ret; 308699a2dd95SBruce Richardson 308799a2dd95SBruce Richardson ret = rte_eth_stats_get(port_id, ð_stats); 308899a2dd95SBruce Richardson if (ret < 0) 308999a2dd95SBruce Richardson return ret; 309099a2dd95SBruce Richardson 309199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 309299a2dd95SBruce Richardson 309399a2dd95SBruce Richardson nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 309499a2dd95SBruce Richardson nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 309599a2dd95SBruce Richardson 309699a2dd95SBruce Richardson /* global stats */ 309799a2dd95SBruce Richardson for (i = 0; i < RTE_NB_STATS; i++) { 309899a2dd95SBruce Richardson stats_ptr = RTE_PTR_ADD(ð_stats, 309999a2dd95SBruce Richardson eth_dev_stats_strings[i].offset); 310099a2dd95SBruce Richardson val = *stats_ptr; 310199a2dd95SBruce Richardson xstats[count++].value = val; 310299a2dd95SBruce Richardson } 310399a2dd95SBruce Richardson 310499a2dd95SBruce Richardson if ((dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) == 0) 310599a2dd95SBruce Richardson return count; 310699a2dd95SBruce Richardson 310799a2dd95SBruce Richardson /* per-rxq stats */ 310899a2dd95SBruce Richardson for (q = 0; q < nb_rxqs; q++) { 310999a2dd95SBruce Richardson for (i = 0; i < RTE_NB_RXQ_STATS; i++) { 311099a2dd95SBruce Richardson stats_ptr = RTE_PTR_ADD(ð_stats, 311199a2dd95SBruce Richardson eth_dev_rxq_stats_strings[i].offset + 311299a2dd95SBruce Richardson q * sizeof(uint64_t)); 311399a2dd95SBruce Richardson val = *stats_ptr; 311499a2dd95SBruce Richardson xstats[count++].value = val; 311599a2dd95SBruce Richardson } 311699a2dd95SBruce Richardson } 311799a2dd95SBruce Richardson 311899a2dd95SBruce Richardson /* per-txq stats */ 311999a2dd95SBruce Richardson for (q = 0; q < nb_txqs; q++) { 312099a2dd95SBruce Richardson for (i = 0; i < RTE_NB_TXQ_STATS; i++) { 312199a2dd95SBruce Richardson stats_ptr = RTE_PTR_ADD(ð_stats, 312299a2dd95SBruce Richardson eth_dev_txq_stats_strings[i].offset + 312399a2dd95SBruce Richardson q * sizeof(uint64_t)); 312499a2dd95SBruce Richardson val = *stats_ptr; 312599a2dd95SBruce Richardson xstats[count++].value = val; 312699a2dd95SBruce Richardson } 312799a2dd95SBruce Richardson } 312899a2dd95SBruce Richardson return count; 312999a2dd95SBruce Richardson } 313099a2dd95SBruce Richardson 313199a2dd95SBruce Richardson /* retrieve ethdev extended statistics */ 313299a2dd95SBruce Richardson int 313399a2dd95SBruce Richardson rte_eth_xstats_get_by_id(uint16_t port_id, const uint64_t *ids, 313499a2dd95SBruce Richardson uint64_t *values, unsigned int size) 313599a2dd95SBruce Richardson { 313699a2dd95SBruce Richardson unsigned int no_basic_stat_requested = 1; 313799a2dd95SBruce Richardson unsigned int no_ext_stat_requested = 1; 313899a2dd95SBruce Richardson unsigned int num_xstats_filled; 313999a2dd95SBruce Richardson unsigned int basic_count; 314099a2dd95SBruce Richardson uint16_t expected_entries; 314199a2dd95SBruce Richardson struct rte_eth_dev *dev; 314299a2dd95SBruce Richardson unsigned int i; 314399a2dd95SBruce Richardson int ret; 314499a2dd95SBruce Richardson 314599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 314653ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 314753ef1b34SMin Hu (Connor) 314899a2dd95SBruce Richardson ret = eth_dev_get_xstats_count(port_id); 314999a2dd95SBruce Richardson if (ret < 0) 315099a2dd95SBruce Richardson return ret; 315199a2dd95SBruce Richardson expected_entries = (uint16_t)ret; 315299a2dd95SBruce Richardson struct rte_eth_xstat xstats[expected_entries]; 315399a2dd95SBruce Richardson basic_count = eth_dev_get_xstats_basic_count(dev); 315499a2dd95SBruce Richardson 315599a2dd95SBruce Richardson /* Return max number of stats if no ids given */ 315699a2dd95SBruce Richardson if (!ids) { 315799a2dd95SBruce Richardson if (!values) 315899a2dd95SBruce Richardson return expected_entries; 315999a2dd95SBruce Richardson else if (values && size < expected_entries) 316099a2dd95SBruce Richardson return expected_entries; 316199a2dd95SBruce Richardson } 316299a2dd95SBruce Richardson 316399a2dd95SBruce Richardson if (ids && !values) 316499a2dd95SBruce Richardson return -EINVAL; 316599a2dd95SBruce Richardson 316699a2dd95SBruce Richardson if (ids && dev->dev_ops->xstats_get_by_id != NULL && size) { 316799a2dd95SBruce Richardson unsigned int basic_count = eth_dev_get_xstats_basic_count(dev); 316899a2dd95SBruce Richardson uint64_t ids_copy[size]; 316999a2dd95SBruce Richardson 317099a2dd95SBruce Richardson for (i = 0; i < size; i++) { 317199a2dd95SBruce Richardson if (ids[i] < basic_count) { 317299a2dd95SBruce Richardson no_basic_stat_requested = 0; 317399a2dd95SBruce Richardson break; 317499a2dd95SBruce Richardson } 317599a2dd95SBruce Richardson 317699a2dd95SBruce Richardson /* 317799a2dd95SBruce Richardson * Convert ids to xstats ids that PMD knows. 317899a2dd95SBruce Richardson * ids known by user are basic + extended stats. 317999a2dd95SBruce Richardson */ 318099a2dd95SBruce Richardson ids_copy[i] = ids[i] - basic_count; 318199a2dd95SBruce Richardson } 318299a2dd95SBruce Richardson 318399a2dd95SBruce Richardson if (no_basic_stat_requested) 318499a2dd95SBruce Richardson return (*dev->dev_ops->xstats_get_by_id)(dev, ids_copy, 318599a2dd95SBruce Richardson values, size); 318699a2dd95SBruce Richardson } 318799a2dd95SBruce Richardson 318899a2dd95SBruce Richardson if (ids) { 318999a2dd95SBruce Richardson for (i = 0; i < size; i++) { 319099a2dd95SBruce Richardson if (ids[i] >= basic_count) { 319199a2dd95SBruce Richardson no_ext_stat_requested = 0; 319299a2dd95SBruce Richardson break; 319399a2dd95SBruce Richardson } 319499a2dd95SBruce Richardson } 319599a2dd95SBruce Richardson } 319699a2dd95SBruce Richardson 319799a2dd95SBruce Richardson /* Fill the xstats structure */ 319899a2dd95SBruce Richardson if (ids && no_ext_stat_requested) 319999a2dd95SBruce Richardson ret = eth_basic_stats_get(port_id, xstats); 320099a2dd95SBruce Richardson else 320199a2dd95SBruce Richardson ret = rte_eth_xstats_get(port_id, xstats, expected_entries); 320299a2dd95SBruce Richardson 320399a2dd95SBruce Richardson if (ret < 0) 320499a2dd95SBruce Richardson return ret; 320599a2dd95SBruce Richardson num_xstats_filled = (unsigned int)ret; 320699a2dd95SBruce Richardson 320799a2dd95SBruce Richardson /* Return all stats */ 320899a2dd95SBruce Richardson if (!ids) { 320999a2dd95SBruce Richardson for (i = 0; i < num_xstats_filled; i++) 321099a2dd95SBruce Richardson values[i] = xstats[i].value; 321199a2dd95SBruce Richardson return expected_entries; 321299a2dd95SBruce Richardson } 321399a2dd95SBruce Richardson 321499a2dd95SBruce Richardson /* Filter stats */ 321599a2dd95SBruce Richardson for (i = 0; i < size; i++) { 321699a2dd95SBruce Richardson if (ids[i] >= expected_entries) { 321799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Id value isn't valid\n"); 321899a2dd95SBruce Richardson return -1; 321999a2dd95SBruce Richardson } 322099a2dd95SBruce Richardson values[i] = xstats[ids[i]].value; 322199a2dd95SBruce Richardson } 322299a2dd95SBruce Richardson return size; 322399a2dd95SBruce Richardson } 322499a2dd95SBruce Richardson 322599a2dd95SBruce Richardson int 322699a2dd95SBruce Richardson rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats, 322799a2dd95SBruce Richardson unsigned int n) 322899a2dd95SBruce Richardson { 322999a2dd95SBruce Richardson struct rte_eth_dev *dev; 323099a2dd95SBruce Richardson unsigned int count = 0, i; 323199a2dd95SBruce Richardson signed int xcount = 0; 323299a2dd95SBruce Richardson uint16_t nb_rxqs, nb_txqs; 323399a2dd95SBruce Richardson int ret; 323499a2dd95SBruce Richardson 323599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 323699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 323799a2dd95SBruce Richardson 323899a2dd95SBruce Richardson nb_rxqs = RTE_MIN(dev->data->nb_rx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 323999a2dd95SBruce Richardson nb_txqs = RTE_MIN(dev->data->nb_tx_queues, RTE_ETHDEV_QUEUE_STAT_CNTRS); 324099a2dd95SBruce Richardson 324199a2dd95SBruce Richardson /* Return generic statistics */ 324299a2dd95SBruce Richardson count = RTE_NB_STATS; 324399a2dd95SBruce Richardson if (dev->data->dev_flags & RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS) 324499a2dd95SBruce Richardson count += (nb_rxqs * RTE_NB_RXQ_STATS) + (nb_txqs * RTE_NB_TXQ_STATS); 324599a2dd95SBruce Richardson 324699a2dd95SBruce Richardson /* implemented by the driver */ 324799a2dd95SBruce Richardson if (dev->dev_ops->xstats_get != NULL) { 324899a2dd95SBruce Richardson /* Retrieve the xstats from the driver at the end of the 324999a2dd95SBruce Richardson * xstats struct. 325099a2dd95SBruce Richardson */ 325199a2dd95SBruce Richardson xcount = (*dev->dev_ops->xstats_get)(dev, 325299a2dd95SBruce Richardson xstats ? xstats + count : NULL, 325399a2dd95SBruce Richardson (n > count) ? n - count : 0); 325499a2dd95SBruce Richardson 325599a2dd95SBruce Richardson if (xcount < 0) 325699a2dd95SBruce Richardson return eth_err(port_id, xcount); 325799a2dd95SBruce Richardson } 325899a2dd95SBruce Richardson 325999a2dd95SBruce Richardson if (n < count + xcount || xstats == NULL) 326099a2dd95SBruce Richardson return count + xcount; 326199a2dd95SBruce Richardson 326299a2dd95SBruce Richardson /* now fill the xstats structure */ 326399a2dd95SBruce Richardson ret = eth_basic_stats_get(port_id, xstats); 326499a2dd95SBruce Richardson if (ret < 0) 326599a2dd95SBruce Richardson return ret; 326699a2dd95SBruce Richardson count = ret; 326799a2dd95SBruce Richardson 326899a2dd95SBruce Richardson for (i = 0; i < count; i++) 326999a2dd95SBruce Richardson xstats[i].id = i; 327099a2dd95SBruce Richardson /* add an offset to driver-specific stats */ 327199a2dd95SBruce Richardson for ( ; i < count + xcount; i++) 327299a2dd95SBruce Richardson xstats[i].id += count; 327399a2dd95SBruce Richardson 327499a2dd95SBruce Richardson return count + xcount; 327599a2dd95SBruce Richardson } 327699a2dd95SBruce Richardson 327799a2dd95SBruce Richardson /* reset ethdev extended statistics */ 327899a2dd95SBruce Richardson int 327999a2dd95SBruce Richardson rte_eth_xstats_reset(uint16_t port_id) 328099a2dd95SBruce Richardson { 328199a2dd95SBruce Richardson struct rte_eth_dev *dev; 328299a2dd95SBruce Richardson 328399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 328499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 328599a2dd95SBruce Richardson 328699a2dd95SBruce Richardson /* implemented by the driver */ 328799a2dd95SBruce Richardson if (dev->dev_ops->xstats_reset != NULL) 328899a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->xstats_reset)(dev)); 328999a2dd95SBruce Richardson 329099a2dd95SBruce Richardson /* fallback to default */ 329199a2dd95SBruce Richardson return rte_eth_stats_reset(port_id); 329299a2dd95SBruce Richardson } 329399a2dd95SBruce Richardson 329499a2dd95SBruce Richardson static int 329599a2dd95SBruce Richardson eth_dev_set_queue_stats_mapping(uint16_t port_id, uint16_t queue_id, 329699a2dd95SBruce Richardson uint8_t stat_idx, uint8_t is_rx) 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 if (is_rx && (queue_id >= dev->data->nb_rx_queues)) 330499a2dd95SBruce Richardson return -EINVAL; 330599a2dd95SBruce Richardson 330699a2dd95SBruce Richardson if (!is_rx && (queue_id >= dev->data->nb_tx_queues)) 330799a2dd95SBruce Richardson return -EINVAL; 330899a2dd95SBruce Richardson 330999a2dd95SBruce Richardson if (stat_idx >= RTE_ETHDEV_QUEUE_STAT_CNTRS) 331099a2dd95SBruce Richardson return -EINVAL; 331199a2dd95SBruce Richardson 331253ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->queue_stats_mapping_set, -ENOTSUP); 331353ef1b34SMin Hu (Connor) return (*dev->dev_ops->queue_stats_mapping_set) (dev, queue_id, stat_idx, is_rx); 331499a2dd95SBruce Richardson } 331599a2dd95SBruce Richardson 331699a2dd95SBruce Richardson int 331799a2dd95SBruce Richardson rte_eth_dev_set_tx_queue_stats_mapping(uint16_t port_id, uint16_t tx_queue_id, 331899a2dd95SBruce Richardson uint8_t stat_idx) 331999a2dd95SBruce Richardson { 332099a2dd95SBruce Richardson return eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id, 332199a2dd95SBruce Richardson tx_queue_id, 332299a2dd95SBruce Richardson stat_idx, STAT_QMAP_TX)); 332399a2dd95SBruce Richardson } 332499a2dd95SBruce Richardson 332599a2dd95SBruce Richardson int 332699a2dd95SBruce Richardson rte_eth_dev_set_rx_queue_stats_mapping(uint16_t port_id, uint16_t rx_queue_id, 332799a2dd95SBruce Richardson uint8_t stat_idx) 332899a2dd95SBruce Richardson { 332999a2dd95SBruce Richardson return eth_err(port_id, eth_dev_set_queue_stats_mapping(port_id, 333099a2dd95SBruce Richardson rx_queue_id, 333199a2dd95SBruce Richardson stat_idx, STAT_QMAP_RX)); 333299a2dd95SBruce Richardson } 333399a2dd95SBruce Richardson 333499a2dd95SBruce Richardson int 333599a2dd95SBruce Richardson rte_eth_dev_fw_version_get(uint16_t port_id, char *fw_version, size_t fw_size) 333699a2dd95SBruce Richardson { 333799a2dd95SBruce Richardson struct rte_eth_dev *dev; 333899a2dd95SBruce Richardson 333999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 334099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 334199a2dd95SBruce Richardson 334253ef1b34SMin Hu (Connor) if (fw_version == NULL && fw_size > 0) { 334353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 334453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u FW version to NULL when string size is non zero\n", 334553ef1b34SMin Hu (Connor) port_id); 334653ef1b34SMin Hu (Connor) return -EINVAL; 334753ef1b34SMin Hu (Connor) } 334853ef1b34SMin Hu (Connor) 334999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fw_version_get, -ENOTSUP); 335099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->fw_version_get)(dev, 335199a2dd95SBruce Richardson fw_version, fw_size)); 335299a2dd95SBruce Richardson } 335399a2dd95SBruce Richardson 335499a2dd95SBruce Richardson int 335599a2dd95SBruce Richardson rte_eth_dev_info_get(uint16_t port_id, struct rte_eth_dev_info *dev_info) 335699a2dd95SBruce Richardson { 335799a2dd95SBruce Richardson struct rte_eth_dev *dev; 335899a2dd95SBruce Richardson const struct rte_eth_desc_lim lim = { 335999a2dd95SBruce Richardson .nb_max = UINT16_MAX, 336099a2dd95SBruce Richardson .nb_min = 0, 336199a2dd95SBruce Richardson .nb_align = 1, 336299a2dd95SBruce Richardson .nb_seg_max = UINT16_MAX, 336399a2dd95SBruce Richardson .nb_mtu_seg_max = UINT16_MAX, 336499a2dd95SBruce Richardson }; 336599a2dd95SBruce Richardson int diag; 336699a2dd95SBruce Richardson 336753ef1b34SMin Hu (Connor) RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 336853ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 336953ef1b34SMin Hu (Connor) 337053ef1b34SMin Hu (Connor) if (dev_info == NULL) { 337153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u info to NULL\n", 337253ef1b34SMin Hu (Connor) port_id); 337353ef1b34SMin Hu (Connor) return -EINVAL; 337453ef1b34SMin Hu (Connor) } 337553ef1b34SMin Hu (Connor) 337699a2dd95SBruce Richardson /* 337799a2dd95SBruce Richardson * Init dev_info before port_id check since caller does not have 337899a2dd95SBruce Richardson * return status and does not know if get is successful or not. 337999a2dd95SBruce Richardson */ 338099a2dd95SBruce Richardson memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); 338199a2dd95SBruce Richardson dev_info->switch_info.domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 338299a2dd95SBruce Richardson 338399a2dd95SBruce Richardson dev_info->rx_desc_lim = lim; 338499a2dd95SBruce Richardson dev_info->tx_desc_lim = lim; 338599a2dd95SBruce Richardson dev_info->device = dev->device; 338699a2dd95SBruce Richardson dev_info->min_mtu = RTE_ETHER_MIN_MTU; 338799a2dd95SBruce Richardson dev_info->max_mtu = UINT16_MAX; 338899a2dd95SBruce Richardson 338999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_infos_get, -ENOTSUP); 339099a2dd95SBruce Richardson diag = (*dev->dev_ops->dev_infos_get)(dev, dev_info); 339199a2dd95SBruce Richardson if (diag != 0) { 339299a2dd95SBruce Richardson /* Cleanup already filled in device information */ 339399a2dd95SBruce Richardson memset(dev_info, 0, sizeof(struct rte_eth_dev_info)); 339499a2dd95SBruce Richardson return eth_err(port_id, diag); 339599a2dd95SBruce Richardson } 339699a2dd95SBruce Richardson 339799a2dd95SBruce Richardson /* Maximum number of queues should be <= RTE_MAX_QUEUES_PER_PORT */ 339899a2dd95SBruce Richardson dev_info->max_rx_queues = RTE_MIN(dev_info->max_rx_queues, 339999a2dd95SBruce Richardson RTE_MAX_QUEUES_PER_PORT); 340099a2dd95SBruce Richardson dev_info->max_tx_queues = RTE_MIN(dev_info->max_tx_queues, 340199a2dd95SBruce Richardson RTE_MAX_QUEUES_PER_PORT); 340299a2dd95SBruce Richardson 340399a2dd95SBruce Richardson dev_info->driver_name = dev->device->driver->name; 340499a2dd95SBruce Richardson dev_info->nb_rx_queues = dev->data->nb_rx_queues; 340599a2dd95SBruce Richardson dev_info->nb_tx_queues = dev->data->nb_tx_queues; 340699a2dd95SBruce Richardson 340799a2dd95SBruce Richardson dev_info->dev_flags = &dev->data->dev_flags; 340899a2dd95SBruce Richardson 340999a2dd95SBruce Richardson return 0; 341099a2dd95SBruce Richardson } 341199a2dd95SBruce Richardson 341299a2dd95SBruce Richardson int 341399a2dd95SBruce Richardson rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask, 341499a2dd95SBruce Richardson uint32_t *ptypes, int num) 341599a2dd95SBruce Richardson { 341699a2dd95SBruce Richardson int i, j; 341799a2dd95SBruce Richardson struct rte_eth_dev *dev; 341899a2dd95SBruce Richardson const uint32_t *all_ptypes; 341999a2dd95SBruce Richardson 342099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 342199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 342253ef1b34SMin Hu (Connor) 342353ef1b34SMin Hu (Connor) if (ptypes == NULL && num > 0) { 342453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 342553ef1b34SMin Hu (Connor) "Cannot get ethdev port %u supported packet types to NULL when array size is non zero\n", 342653ef1b34SMin Hu (Connor) port_id); 342753ef1b34SMin Hu (Connor) return -EINVAL; 342853ef1b34SMin Hu (Connor) } 342953ef1b34SMin Hu (Connor) 343099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_supported_ptypes_get, 0); 343199a2dd95SBruce Richardson all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev); 343299a2dd95SBruce Richardson 343399a2dd95SBruce Richardson if (!all_ptypes) 343499a2dd95SBruce Richardson return 0; 343599a2dd95SBruce Richardson 343699a2dd95SBruce Richardson for (i = 0, j = 0; all_ptypes[i] != RTE_PTYPE_UNKNOWN; ++i) 343799a2dd95SBruce Richardson if (all_ptypes[i] & ptype_mask) { 343899a2dd95SBruce Richardson if (j < num) 343999a2dd95SBruce Richardson ptypes[j] = all_ptypes[i]; 344099a2dd95SBruce Richardson j++; 344199a2dd95SBruce Richardson } 344299a2dd95SBruce Richardson 344399a2dd95SBruce Richardson return j; 344499a2dd95SBruce Richardson } 344599a2dd95SBruce Richardson 344699a2dd95SBruce Richardson int 344799a2dd95SBruce Richardson rte_eth_dev_set_ptypes(uint16_t port_id, uint32_t ptype_mask, 344899a2dd95SBruce Richardson uint32_t *set_ptypes, unsigned int num) 344999a2dd95SBruce Richardson { 345099a2dd95SBruce Richardson const uint32_t valid_ptype_masks[] = { 345199a2dd95SBruce Richardson RTE_PTYPE_L2_MASK, 345299a2dd95SBruce Richardson RTE_PTYPE_L3_MASK, 345399a2dd95SBruce Richardson RTE_PTYPE_L4_MASK, 345499a2dd95SBruce Richardson RTE_PTYPE_TUNNEL_MASK, 345599a2dd95SBruce Richardson RTE_PTYPE_INNER_L2_MASK, 345699a2dd95SBruce Richardson RTE_PTYPE_INNER_L3_MASK, 345799a2dd95SBruce Richardson RTE_PTYPE_INNER_L4_MASK, 345899a2dd95SBruce Richardson }; 345999a2dd95SBruce Richardson const uint32_t *all_ptypes; 346099a2dd95SBruce Richardson struct rte_eth_dev *dev; 346199a2dd95SBruce Richardson uint32_t unused_mask; 346299a2dd95SBruce Richardson unsigned int i, j; 346399a2dd95SBruce Richardson int ret; 346499a2dd95SBruce Richardson 346599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 346699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 346799a2dd95SBruce Richardson 346853ef1b34SMin Hu (Connor) if (num > 0 && set_ptypes == NULL) { 346953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 347053ef1b34SMin Hu (Connor) "Cannot get ethdev port %u set packet types to NULL when array size is non zero\n", 347153ef1b34SMin Hu (Connor) port_id); 347299a2dd95SBruce Richardson return -EINVAL; 347353ef1b34SMin Hu (Connor) } 347499a2dd95SBruce Richardson 347599a2dd95SBruce Richardson if (*dev->dev_ops->dev_supported_ptypes_get == NULL || 347699a2dd95SBruce Richardson *dev->dev_ops->dev_ptypes_set == NULL) { 347799a2dd95SBruce Richardson ret = 0; 347899a2dd95SBruce Richardson goto ptype_unknown; 347999a2dd95SBruce Richardson } 348099a2dd95SBruce Richardson 348199a2dd95SBruce Richardson if (ptype_mask == 0) { 348299a2dd95SBruce Richardson ret = (*dev->dev_ops->dev_ptypes_set)(dev, 348399a2dd95SBruce Richardson ptype_mask); 348499a2dd95SBruce Richardson goto ptype_unknown; 348599a2dd95SBruce Richardson } 348699a2dd95SBruce Richardson 348799a2dd95SBruce Richardson unused_mask = ptype_mask; 348899a2dd95SBruce Richardson for (i = 0; i < RTE_DIM(valid_ptype_masks); i++) { 348999a2dd95SBruce Richardson uint32_t mask = ptype_mask & valid_ptype_masks[i]; 349099a2dd95SBruce Richardson if (mask && mask != valid_ptype_masks[i]) { 349199a2dd95SBruce Richardson ret = -EINVAL; 349299a2dd95SBruce Richardson goto ptype_unknown; 349399a2dd95SBruce Richardson } 349499a2dd95SBruce Richardson unused_mask &= ~valid_ptype_masks[i]; 349599a2dd95SBruce Richardson } 349699a2dd95SBruce Richardson 349799a2dd95SBruce Richardson if (unused_mask) { 349899a2dd95SBruce Richardson ret = -EINVAL; 349999a2dd95SBruce Richardson goto ptype_unknown; 350099a2dd95SBruce Richardson } 350199a2dd95SBruce Richardson 350299a2dd95SBruce Richardson all_ptypes = (*dev->dev_ops->dev_supported_ptypes_get)(dev); 350399a2dd95SBruce Richardson if (all_ptypes == NULL) { 350499a2dd95SBruce Richardson ret = 0; 350599a2dd95SBruce Richardson goto ptype_unknown; 350699a2dd95SBruce Richardson } 350799a2dd95SBruce Richardson 350899a2dd95SBruce Richardson /* 350999a2dd95SBruce Richardson * Accommodate as many set_ptypes as possible. If the supplied 351099a2dd95SBruce Richardson * set_ptypes array is insufficient fill it partially. 351199a2dd95SBruce Richardson */ 351299a2dd95SBruce Richardson for (i = 0, j = 0; set_ptypes != NULL && 351399a2dd95SBruce Richardson (all_ptypes[i] != RTE_PTYPE_UNKNOWN); ++i) { 351499a2dd95SBruce Richardson if (ptype_mask & all_ptypes[i]) { 351599a2dd95SBruce Richardson if (j < num - 1) { 351699a2dd95SBruce Richardson set_ptypes[j] = all_ptypes[i]; 351799a2dd95SBruce Richardson j++; 351899a2dd95SBruce Richardson continue; 351999a2dd95SBruce Richardson } 352099a2dd95SBruce Richardson break; 352199a2dd95SBruce Richardson } 352299a2dd95SBruce Richardson } 352399a2dd95SBruce Richardson 352499a2dd95SBruce Richardson if (set_ptypes != NULL && j < num) 352599a2dd95SBruce Richardson set_ptypes[j] = RTE_PTYPE_UNKNOWN; 352699a2dd95SBruce Richardson 352799a2dd95SBruce Richardson return (*dev->dev_ops->dev_ptypes_set)(dev, ptype_mask); 352899a2dd95SBruce Richardson 352999a2dd95SBruce Richardson ptype_unknown: 353099a2dd95SBruce Richardson if (num > 0) 353199a2dd95SBruce Richardson set_ptypes[0] = RTE_PTYPE_UNKNOWN; 353299a2dd95SBruce Richardson 353399a2dd95SBruce Richardson return ret; 353499a2dd95SBruce Richardson } 353599a2dd95SBruce Richardson 353699a2dd95SBruce Richardson int 353799a2dd95SBruce Richardson rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr) 353899a2dd95SBruce Richardson { 353999a2dd95SBruce Richardson struct rte_eth_dev *dev; 354099a2dd95SBruce Richardson 354199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 354299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 354353ef1b34SMin Hu (Connor) 354453ef1b34SMin Hu (Connor) if (mac_addr == NULL) { 354553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 354653ef1b34SMin Hu (Connor) "Cannot get ethdev port %u MAC address to NULL\n", 354753ef1b34SMin Hu (Connor) port_id); 354853ef1b34SMin Hu (Connor) return -EINVAL; 354953ef1b34SMin Hu (Connor) } 355053ef1b34SMin Hu (Connor) 355199a2dd95SBruce Richardson rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr); 355299a2dd95SBruce Richardson 355399a2dd95SBruce Richardson return 0; 355499a2dd95SBruce Richardson } 355599a2dd95SBruce Richardson 355699a2dd95SBruce Richardson int 355799a2dd95SBruce Richardson rte_eth_dev_get_mtu(uint16_t port_id, uint16_t *mtu) 355899a2dd95SBruce Richardson { 355999a2dd95SBruce Richardson struct rte_eth_dev *dev; 356099a2dd95SBruce Richardson 356199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 356299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 356353ef1b34SMin Hu (Connor) 356453ef1b34SMin Hu (Connor) if (mtu == NULL) { 356553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u MTU to NULL\n", 356653ef1b34SMin Hu (Connor) port_id); 356753ef1b34SMin Hu (Connor) return -EINVAL; 356853ef1b34SMin Hu (Connor) } 356953ef1b34SMin Hu (Connor) 357099a2dd95SBruce Richardson *mtu = dev->data->mtu; 357199a2dd95SBruce Richardson return 0; 357299a2dd95SBruce Richardson } 357399a2dd95SBruce Richardson 357499a2dd95SBruce Richardson int 357599a2dd95SBruce Richardson rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu) 357699a2dd95SBruce Richardson { 357799a2dd95SBruce Richardson int ret; 357899a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 357999a2dd95SBruce Richardson struct rte_eth_dev *dev; 358099a2dd95SBruce Richardson 358199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 358299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 358399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mtu_set, -ENOTSUP); 358499a2dd95SBruce Richardson 358599a2dd95SBruce Richardson /* 358699a2dd95SBruce Richardson * Check if the device supports dev_infos_get, if it does not 358799a2dd95SBruce Richardson * skip min_mtu/max_mtu validation here as this requires values 358899a2dd95SBruce Richardson * that are populated within the call to rte_eth_dev_info_get() 358999a2dd95SBruce Richardson * which relies on dev->dev_ops->dev_infos_get. 359099a2dd95SBruce Richardson */ 359199a2dd95SBruce Richardson if (*dev->dev_ops->dev_infos_get != NULL) { 359299a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 359399a2dd95SBruce Richardson if (ret != 0) 359499a2dd95SBruce Richardson return ret; 359599a2dd95SBruce Richardson 359699a2dd95SBruce Richardson if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu) 359799a2dd95SBruce Richardson return -EINVAL; 359899a2dd95SBruce Richardson } 359999a2dd95SBruce Richardson 360099a2dd95SBruce Richardson ret = (*dev->dev_ops->mtu_set)(dev, mtu); 360199a2dd95SBruce Richardson if (!ret) 360299a2dd95SBruce Richardson dev->data->mtu = mtu; 360399a2dd95SBruce Richardson 360499a2dd95SBruce Richardson return eth_err(port_id, ret); 360599a2dd95SBruce Richardson } 360699a2dd95SBruce Richardson 360799a2dd95SBruce Richardson int 360899a2dd95SBruce Richardson rte_eth_dev_vlan_filter(uint16_t port_id, uint16_t vlan_id, int on) 360999a2dd95SBruce Richardson { 361099a2dd95SBruce Richardson struct rte_eth_dev *dev; 361199a2dd95SBruce Richardson int ret; 361299a2dd95SBruce Richardson 361399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 361499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 361553ef1b34SMin Hu (Connor) 361699a2dd95SBruce Richardson if (!(dev->data->dev_conf.rxmode.offloads & 361799a2dd95SBruce Richardson DEV_RX_OFFLOAD_VLAN_FILTER)) { 361899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: vlan-filtering disabled\n", 361999a2dd95SBruce Richardson port_id); 362099a2dd95SBruce Richardson return -ENOSYS; 362199a2dd95SBruce Richardson } 362299a2dd95SBruce Richardson 362399a2dd95SBruce Richardson if (vlan_id > 4095) { 362499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port_id=%u invalid vlan_id=%u > 4095\n", 362599a2dd95SBruce Richardson port_id, vlan_id); 362699a2dd95SBruce Richardson return -EINVAL; 362799a2dd95SBruce Richardson } 362899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_filter_set, -ENOTSUP); 362999a2dd95SBruce Richardson 363099a2dd95SBruce Richardson ret = (*dev->dev_ops->vlan_filter_set)(dev, vlan_id, on); 363199a2dd95SBruce Richardson if (ret == 0) { 363299a2dd95SBruce Richardson struct rte_vlan_filter_conf *vfc; 363399a2dd95SBruce Richardson int vidx; 363499a2dd95SBruce Richardson int vbit; 363599a2dd95SBruce Richardson 363699a2dd95SBruce Richardson vfc = &dev->data->vlan_filter_conf; 363799a2dd95SBruce Richardson vidx = vlan_id / 64; 363899a2dd95SBruce Richardson vbit = vlan_id % 64; 363999a2dd95SBruce Richardson 364099a2dd95SBruce Richardson if (on) 364199a2dd95SBruce Richardson vfc->ids[vidx] |= UINT64_C(1) << vbit; 364299a2dd95SBruce Richardson else 364399a2dd95SBruce Richardson vfc->ids[vidx] &= ~(UINT64_C(1) << vbit); 364499a2dd95SBruce Richardson } 364599a2dd95SBruce Richardson 364699a2dd95SBruce Richardson return eth_err(port_id, ret); 364799a2dd95SBruce Richardson } 364899a2dd95SBruce Richardson 364999a2dd95SBruce Richardson int 365099a2dd95SBruce Richardson rte_eth_dev_set_vlan_strip_on_queue(uint16_t port_id, uint16_t rx_queue_id, 365199a2dd95SBruce Richardson int on) 365299a2dd95SBruce Richardson { 365399a2dd95SBruce Richardson struct rte_eth_dev *dev; 365499a2dd95SBruce Richardson 365599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 365699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 365753ef1b34SMin Hu (Connor) 365899a2dd95SBruce Richardson if (rx_queue_id >= dev->data->nb_rx_queues) { 365999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid rx_queue_id=%u\n", rx_queue_id); 366099a2dd95SBruce Richardson return -EINVAL; 366199a2dd95SBruce Richardson } 366299a2dd95SBruce Richardson 366399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_strip_queue_set, -ENOTSUP); 366499a2dd95SBruce Richardson (*dev->dev_ops->vlan_strip_queue_set)(dev, rx_queue_id, on); 366599a2dd95SBruce Richardson 366699a2dd95SBruce Richardson return 0; 366799a2dd95SBruce Richardson } 366899a2dd95SBruce Richardson 366999a2dd95SBruce Richardson int 367099a2dd95SBruce Richardson rte_eth_dev_set_vlan_ether_type(uint16_t port_id, 367199a2dd95SBruce Richardson enum rte_vlan_type vlan_type, 367299a2dd95SBruce Richardson uint16_t tpid) 367399a2dd95SBruce Richardson { 367499a2dd95SBruce Richardson struct rte_eth_dev *dev; 367599a2dd95SBruce Richardson 367699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 367799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 367899a2dd95SBruce Richardson 367953ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_tpid_set, -ENOTSUP); 368099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->vlan_tpid_set)(dev, vlan_type, 368199a2dd95SBruce Richardson tpid)); 368299a2dd95SBruce Richardson } 368399a2dd95SBruce Richardson 368499a2dd95SBruce Richardson int 368599a2dd95SBruce Richardson rte_eth_dev_set_vlan_offload(uint16_t port_id, int offload_mask) 368699a2dd95SBruce Richardson { 368799a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 368899a2dd95SBruce Richardson struct rte_eth_dev *dev; 368999a2dd95SBruce Richardson int ret = 0; 369099a2dd95SBruce Richardson int mask = 0; 369199a2dd95SBruce Richardson int cur, org = 0; 369299a2dd95SBruce Richardson uint64_t orig_offloads; 369399a2dd95SBruce Richardson uint64_t dev_offloads; 369499a2dd95SBruce Richardson uint64_t new_offloads; 369599a2dd95SBruce Richardson 369699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 369799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 369899a2dd95SBruce Richardson 369999a2dd95SBruce Richardson /* save original values in case of failure */ 370099a2dd95SBruce Richardson orig_offloads = dev->data->dev_conf.rxmode.offloads; 370199a2dd95SBruce Richardson dev_offloads = orig_offloads; 370299a2dd95SBruce Richardson 370399a2dd95SBruce Richardson /* check which option changed by application */ 370499a2dd95SBruce Richardson cur = !!(offload_mask & ETH_VLAN_STRIP_OFFLOAD); 370599a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP); 370699a2dd95SBruce Richardson if (cur != org) { 370799a2dd95SBruce Richardson if (cur) 370899a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_VLAN_STRIP; 370999a2dd95SBruce Richardson else 371099a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_STRIP; 371199a2dd95SBruce Richardson mask |= ETH_VLAN_STRIP_MASK; 371299a2dd95SBruce Richardson } 371399a2dd95SBruce Richardson 371499a2dd95SBruce Richardson cur = !!(offload_mask & ETH_VLAN_FILTER_OFFLOAD); 371599a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER); 371699a2dd95SBruce Richardson if (cur != org) { 371799a2dd95SBruce Richardson if (cur) 371899a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_VLAN_FILTER; 371999a2dd95SBruce Richardson else 372099a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_FILTER; 372199a2dd95SBruce Richardson mask |= ETH_VLAN_FILTER_MASK; 372299a2dd95SBruce Richardson } 372399a2dd95SBruce Richardson 372499a2dd95SBruce Richardson cur = !!(offload_mask & ETH_VLAN_EXTEND_OFFLOAD); 372599a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND); 372699a2dd95SBruce Richardson if (cur != org) { 372799a2dd95SBruce Richardson if (cur) 372899a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_VLAN_EXTEND; 372999a2dd95SBruce Richardson else 373099a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_VLAN_EXTEND; 373199a2dd95SBruce Richardson mask |= ETH_VLAN_EXTEND_MASK; 373299a2dd95SBruce Richardson } 373399a2dd95SBruce Richardson 373499a2dd95SBruce Richardson cur = !!(offload_mask & ETH_QINQ_STRIP_OFFLOAD); 373599a2dd95SBruce Richardson org = !!(dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP); 373699a2dd95SBruce Richardson if (cur != org) { 373799a2dd95SBruce Richardson if (cur) 373899a2dd95SBruce Richardson dev_offloads |= DEV_RX_OFFLOAD_QINQ_STRIP; 373999a2dd95SBruce Richardson else 374099a2dd95SBruce Richardson dev_offloads &= ~DEV_RX_OFFLOAD_QINQ_STRIP; 374199a2dd95SBruce Richardson mask |= ETH_QINQ_STRIP_MASK; 374299a2dd95SBruce Richardson } 374399a2dd95SBruce Richardson 374499a2dd95SBruce Richardson /*no change*/ 374599a2dd95SBruce Richardson if (mask == 0) 374699a2dd95SBruce Richardson return ret; 374799a2dd95SBruce Richardson 374899a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 374999a2dd95SBruce Richardson if (ret != 0) 375099a2dd95SBruce Richardson return ret; 375199a2dd95SBruce Richardson 375299a2dd95SBruce Richardson /* Rx VLAN offloading must be within its device capabilities */ 375399a2dd95SBruce Richardson if ((dev_offloads & dev_info.rx_offload_capa) != dev_offloads) { 375499a2dd95SBruce Richardson new_offloads = dev_offloads & ~orig_offloads; 375599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 375699a2dd95SBruce Richardson "Ethdev port_id=%u requested new added VLAN offloads " 375799a2dd95SBruce Richardson "0x%" PRIx64 " must be within Rx offloads capabilities " 375899a2dd95SBruce Richardson "0x%" PRIx64 " in %s()\n", 375999a2dd95SBruce Richardson port_id, new_offloads, dev_info.rx_offload_capa, 376099a2dd95SBruce Richardson __func__); 376199a2dd95SBruce Richardson return -EINVAL; 376299a2dd95SBruce Richardson } 376399a2dd95SBruce Richardson 376499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_offload_set, -ENOTSUP); 376599a2dd95SBruce Richardson dev->data->dev_conf.rxmode.offloads = dev_offloads; 376699a2dd95SBruce Richardson ret = (*dev->dev_ops->vlan_offload_set)(dev, mask); 376799a2dd95SBruce Richardson if (ret) { 376899a2dd95SBruce Richardson /* hit an error restore original values */ 376999a2dd95SBruce Richardson dev->data->dev_conf.rxmode.offloads = orig_offloads; 377099a2dd95SBruce Richardson } 377199a2dd95SBruce Richardson 377299a2dd95SBruce Richardson return eth_err(port_id, ret); 377399a2dd95SBruce Richardson } 377499a2dd95SBruce Richardson 377599a2dd95SBruce Richardson int 377699a2dd95SBruce Richardson rte_eth_dev_get_vlan_offload(uint16_t port_id) 377799a2dd95SBruce Richardson { 377899a2dd95SBruce Richardson struct rte_eth_dev *dev; 377999a2dd95SBruce Richardson uint64_t *dev_offloads; 378099a2dd95SBruce Richardson int ret = 0; 378199a2dd95SBruce Richardson 378299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 378399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 378499a2dd95SBruce Richardson dev_offloads = &dev->data->dev_conf.rxmode.offloads; 378599a2dd95SBruce Richardson 378699a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_STRIP) 378799a2dd95SBruce Richardson ret |= ETH_VLAN_STRIP_OFFLOAD; 378899a2dd95SBruce Richardson 378999a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_FILTER) 379099a2dd95SBruce Richardson ret |= ETH_VLAN_FILTER_OFFLOAD; 379199a2dd95SBruce Richardson 379299a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_VLAN_EXTEND) 379399a2dd95SBruce Richardson ret |= ETH_VLAN_EXTEND_OFFLOAD; 379499a2dd95SBruce Richardson 379599a2dd95SBruce Richardson if (*dev_offloads & DEV_RX_OFFLOAD_QINQ_STRIP) 379699a2dd95SBruce Richardson ret |= ETH_QINQ_STRIP_OFFLOAD; 379799a2dd95SBruce Richardson 379899a2dd95SBruce Richardson return ret; 379999a2dd95SBruce Richardson } 380099a2dd95SBruce Richardson 380199a2dd95SBruce Richardson int 380299a2dd95SBruce Richardson rte_eth_dev_set_vlan_pvid(uint16_t port_id, uint16_t pvid, int on) 380399a2dd95SBruce Richardson { 380499a2dd95SBruce Richardson struct rte_eth_dev *dev; 380599a2dd95SBruce Richardson 380699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 380799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 380899a2dd95SBruce Richardson 380953ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->vlan_pvid_set, -ENOTSUP); 381099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->vlan_pvid_set)(dev, pvid, on)); 381199a2dd95SBruce Richardson } 381299a2dd95SBruce Richardson 381399a2dd95SBruce Richardson int 381499a2dd95SBruce Richardson rte_eth_dev_flow_ctrl_get(uint16_t port_id, struct rte_eth_fc_conf *fc_conf) 381599a2dd95SBruce Richardson { 381699a2dd95SBruce Richardson struct rte_eth_dev *dev; 381799a2dd95SBruce Richardson 381899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 381999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 382053ef1b34SMin Hu (Connor) 382153ef1b34SMin Hu (Connor) if (fc_conf == NULL) { 382253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 382353ef1b34SMin Hu (Connor) "Cannot get ethdev port %u flow control config to NULL\n", 382453ef1b34SMin Hu (Connor) port_id); 382553ef1b34SMin Hu (Connor) return -EINVAL; 382653ef1b34SMin Hu (Connor) } 382753ef1b34SMin Hu (Connor) 382899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_get, -ENOTSUP); 382999a2dd95SBruce Richardson memset(fc_conf, 0, sizeof(*fc_conf)); 383099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->flow_ctrl_get)(dev, fc_conf)); 383199a2dd95SBruce Richardson } 383299a2dd95SBruce Richardson 383399a2dd95SBruce Richardson int 383499a2dd95SBruce Richardson rte_eth_dev_flow_ctrl_set(uint16_t port_id, struct rte_eth_fc_conf *fc_conf) 383599a2dd95SBruce Richardson { 383699a2dd95SBruce Richardson struct rte_eth_dev *dev; 383799a2dd95SBruce Richardson 383899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 383953ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 384053ef1b34SMin Hu (Connor) 384153ef1b34SMin Hu (Connor) if (fc_conf == NULL) { 384253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 384353ef1b34SMin Hu (Connor) "Cannot set ethdev port %u flow control from NULL config\n", 384453ef1b34SMin Hu (Connor) port_id); 384553ef1b34SMin Hu (Connor) return -EINVAL; 384653ef1b34SMin Hu (Connor) } 384753ef1b34SMin Hu (Connor) 384899a2dd95SBruce Richardson if ((fc_conf->send_xon != 0) && (fc_conf->send_xon != 1)) { 384999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid send_xon, only 0/1 allowed\n"); 385099a2dd95SBruce Richardson return -EINVAL; 385199a2dd95SBruce Richardson } 385299a2dd95SBruce Richardson 385399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->flow_ctrl_set, -ENOTSUP); 385499a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->flow_ctrl_set)(dev, fc_conf)); 385599a2dd95SBruce Richardson } 385699a2dd95SBruce Richardson 385799a2dd95SBruce Richardson int 385899a2dd95SBruce Richardson rte_eth_dev_priority_flow_ctrl_set(uint16_t port_id, 385999a2dd95SBruce Richardson struct rte_eth_pfc_conf *pfc_conf) 386099a2dd95SBruce Richardson { 386199a2dd95SBruce Richardson struct rte_eth_dev *dev; 386299a2dd95SBruce Richardson 386399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 386453ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 386553ef1b34SMin Hu (Connor) 386653ef1b34SMin Hu (Connor) if (pfc_conf == NULL) { 386753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 386853ef1b34SMin Hu (Connor) "Cannot set ethdev port %u priority flow control from NULL config\n", 386953ef1b34SMin Hu (Connor) port_id); 387053ef1b34SMin Hu (Connor) return -EINVAL; 387153ef1b34SMin Hu (Connor) } 387253ef1b34SMin Hu (Connor) 387399a2dd95SBruce Richardson if (pfc_conf->priority > (ETH_DCB_NUM_USER_PRIORITIES - 1)) { 387499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid priority, only 0-7 allowed\n"); 387599a2dd95SBruce Richardson return -EINVAL; 387699a2dd95SBruce Richardson } 387799a2dd95SBruce Richardson 387899a2dd95SBruce Richardson /* High water, low water validation are device specific */ 387999a2dd95SBruce Richardson if (*dev->dev_ops->priority_flow_ctrl_set) 388099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->priority_flow_ctrl_set) 388199a2dd95SBruce Richardson (dev, pfc_conf)); 388299a2dd95SBruce Richardson return -ENOTSUP; 388399a2dd95SBruce Richardson } 388499a2dd95SBruce Richardson 388599a2dd95SBruce Richardson static int 388699a2dd95SBruce Richardson eth_check_reta_mask(struct rte_eth_rss_reta_entry64 *reta_conf, 388799a2dd95SBruce Richardson uint16_t reta_size) 388899a2dd95SBruce Richardson { 388999a2dd95SBruce Richardson uint16_t i, num; 389099a2dd95SBruce Richardson 389199a2dd95SBruce Richardson num = (reta_size + RTE_RETA_GROUP_SIZE - 1) / RTE_RETA_GROUP_SIZE; 389299a2dd95SBruce Richardson for (i = 0; i < num; i++) { 389399a2dd95SBruce Richardson if (reta_conf[i].mask) 389499a2dd95SBruce Richardson return 0; 389599a2dd95SBruce Richardson } 389699a2dd95SBruce Richardson 389799a2dd95SBruce Richardson return -EINVAL; 389899a2dd95SBruce Richardson } 389999a2dd95SBruce Richardson 390099a2dd95SBruce Richardson static int 390199a2dd95SBruce Richardson eth_check_reta_entry(struct rte_eth_rss_reta_entry64 *reta_conf, 390299a2dd95SBruce Richardson uint16_t reta_size, 390399a2dd95SBruce Richardson uint16_t max_rxq) 390499a2dd95SBruce Richardson { 390599a2dd95SBruce Richardson uint16_t i, idx, shift; 390699a2dd95SBruce Richardson 390799a2dd95SBruce Richardson if (max_rxq == 0) { 390899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "No receive queue is available\n"); 390999a2dd95SBruce Richardson return -EINVAL; 391099a2dd95SBruce Richardson } 391199a2dd95SBruce Richardson 391299a2dd95SBruce Richardson for (i = 0; i < reta_size; i++) { 391399a2dd95SBruce Richardson idx = i / RTE_RETA_GROUP_SIZE; 391499a2dd95SBruce Richardson shift = i % RTE_RETA_GROUP_SIZE; 391599a2dd95SBruce Richardson if ((reta_conf[idx].mask & (1ULL << shift)) && 391699a2dd95SBruce Richardson (reta_conf[idx].reta[shift] >= max_rxq)) { 391799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 391899a2dd95SBruce Richardson "reta_conf[%u]->reta[%u]: %u exceeds the maximum rxq index: %u\n", 391999a2dd95SBruce Richardson idx, shift, 392099a2dd95SBruce Richardson reta_conf[idx].reta[shift], max_rxq); 392199a2dd95SBruce Richardson return -EINVAL; 392299a2dd95SBruce Richardson } 392399a2dd95SBruce Richardson } 392499a2dd95SBruce Richardson 392599a2dd95SBruce Richardson return 0; 392699a2dd95SBruce Richardson } 392799a2dd95SBruce Richardson 392899a2dd95SBruce Richardson int 392999a2dd95SBruce Richardson rte_eth_dev_rss_reta_update(uint16_t port_id, 393099a2dd95SBruce Richardson struct rte_eth_rss_reta_entry64 *reta_conf, 393199a2dd95SBruce Richardson uint16_t reta_size) 393299a2dd95SBruce Richardson { 393399a2dd95SBruce Richardson struct rte_eth_dev *dev; 393499a2dd95SBruce Richardson int ret; 393599a2dd95SBruce Richardson 393699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 393753ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 393853ef1b34SMin Hu (Connor) 393953ef1b34SMin Hu (Connor) if (reta_conf == NULL) { 394053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 394153ef1b34SMin Hu (Connor) "Cannot update ethdev port %u RSS RETA to NULL\n", 394253ef1b34SMin Hu (Connor) port_id); 394353ef1b34SMin Hu (Connor) return -EINVAL; 394453ef1b34SMin Hu (Connor) } 394553ef1b34SMin Hu (Connor) 394653ef1b34SMin Hu (Connor) if (reta_size == 0) { 394753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 394853ef1b34SMin Hu (Connor) "Cannot update ethdev port %u RSS RETA with zero size\n", 394953ef1b34SMin Hu (Connor) port_id); 395053ef1b34SMin Hu (Connor) return -EINVAL; 395153ef1b34SMin Hu (Connor) } 395253ef1b34SMin Hu (Connor) 395399a2dd95SBruce Richardson /* Check mask bits */ 395499a2dd95SBruce Richardson ret = eth_check_reta_mask(reta_conf, reta_size); 395599a2dd95SBruce Richardson if (ret < 0) 395699a2dd95SBruce Richardson return ret; 395799a2dd95SBruce Richardson 395899a2dd95SBruce Richardson /* Check entry value */ 395999a2dd95SBruce Richardson ret = eth_check_reta_entry(reta_conf, reta_size, 396099a2dd95SBruce Richardson dev->data->nb_rx_queues); 396199a2dd95SBruce Richardson if (ret < 0) 396299a2dd95SBruce Richardson return ret; 396399a2dd95SBruce Richardson 396499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_update, -ENOTSUP); 396599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->reta_update)(dev, reta_conf, 396699a2dd95SBruce Richardson reta_size)); 396799a2dd95SBruce Richardson } 396899a2dd95SBruce Richardson 396999a2dd95SBruce Richardson int 397099a2dd95SBruce Richardson rte_eth_dev_rss_reta_query(uint16_t port_id, 397199a2dd95SBruce Richardson struct rte_eth_rss_reta_entry64 *reta_conf, 397299a2dd95SBruce Richardson uint16_t reta_size) 397399a2dd95SBruce Richardson { 397499a2dd95SBruce Richardson struct rte_eth_dev *dev; 397599a2dd95SBruce Richardson int ret; 397699a2dd95SBruce Richardson 397799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 397853ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 397953ef1b34SMin Hu (Connor) 398053ef1b34SMin Hu (Connor) if (reta_conf == NULL) { 398153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 398253ef1b34SMin Hu (Connor) "Cannot query ethdev port %u RSS RETA from NULL config\n", 398353ef1b34SMin Hu (Connor) port_id); 398453ef1b34SMin Hu (Connor) return -EINVAL; 398553ef1b34SMin Hu (Connor) } 398699a2dd95SBruce Richardson 398799a2dd95SBruce Richardson /* Check mask bits */ 398899a2dd95SBruce Richardson ret = eth_check_reta_mask(reta_conf, reta_size); 398999a2dd95SBruce Richardson if (ret < 0) 399099a2dd95SBruce Richardson return ret; 399199a2dd95SBruce Richardson 399299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->reta_query, -ENOTSUP); 399399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->reta_query)(dev, reta_conf, 399499a2dd95SBruce Richardson reta_size)); 399599a2dd95SBruce Richardson } 399699a2dd95SBruce Richardson 399799a2dd95SBruce Richardson int 399899a2dd95SBruce Richardson rte_eth_dev_rss_hash_update(uint16_t port_id, 399999a2dd95SBruce Richardson struct rte_eth_rss_conf *rss_conf) 400099a2dd95SBruce Richardson { 400199a2dd95SBruce Richardson struct rte_eth_dev *dev; 400299a2dd95SBruce Richardson struct rte_eth_dev_info dev_info = { .flow_type_rss_offloads = 0, }; 400399a2dd95SBruce Richardson int ret; 400499a2dd95SBruce Richardson 400599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 400653ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 400753ef1b34SMin Hu (Connor) 400853ef1b34SMin Hu (Connor) if (rss_conf == NULL) { 400953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 401053ef1b34SMin Hu (Connor) "Cannot update ethdev port %u RSS hash from NULL config\n", 401153ef1b34SMin Hu (Connor) port_id); 401253ef1b34SMin Hu (Connor) return -EINVAL; 401353ef1b34SMin Hu (Connor) } 401499a2dd95SBruce Richardson 401599a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 401699a2dd95SBruce Richardson if (ret != 0) 401799a2dd95SBruce Richardson return ret; 401899a2dd95SBruce Richardson 401999a2dd95SBruce Richardson rss_conf->rss_hf = rte_eth_rss_hf_refine(rss_conf->rss_hf); 402099a2dd95SBruce Richardson if ((dev_info.flow_type_rss_offloads | rss_conf->rss_hf) != 402199a2dd95SBruce Richardson dev_info.flow_type_rss_offloads) { 402299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 402399a2dd95SBruce Richardson "Ethdev port_id=%u invalid rss_hf: 0x%"PRIx64", valid value: 0x%"PRIx64"\n", 402499a2dd95SBruce Richardson port_id, rss_conf->rss_hf, 402599a2dd95SBruce Richardson dev_info.flow_type_rss_offloads); 402699a2dd95SBruce Richardson return -EINVAL; 402799a2dd95SBruce Richardson } 402899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_update, -ENOTSUP); 402999a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->rss_hash_update)(dev, 403099a2dd95SBruce Richardson rss_conf)); 403199a2dd95SBruce Richardson } 403299a2dd95SBruce Richardson 403399a2dd95SBruce Richardson int 403499a2dd95SBruce Richardson rte_eth_dev_rss_hash_conf_get(uint16_t port_id, 403599a2dd95SBruce Richardson struct rte_eth_rss_conf *rss_conf) 403699a2dd95SBruce Richardson { 403799a2dd95SBruce Richardson struct rte_eth_dev *dev; 403899a2dd95SBruce Richardson 403999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 404099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 404153ef1b34SMin Hu (Connor) 404253ef1b34SMin Hu (Connor) if (rss_conf == NULL) { 404353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 404453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u RSS hash config to NULL\n", 404553ef1b34SMin Hu (Connor) port_id); 404653ef1b34SMin Hu (Connor) return -EINVAL; 404753ef1b34SMin Hu (Connor) } 404853ef1b34SMin Hu (Connor) 404999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rss_hash_conf_get, -ENOTSUP); 405099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->rss_hash_conf_get)(dev, 405199a2dd95SBruce Richardson rss_conf)); 405299a2dd95SBruce Richardson } 405399a2dd95SBruce Richardson 405499a2dd95SBruce Richardson int 405599a2dd95SBruce Richardson rte_eth_dev_udp_tunnel_port_add(uint16_t port_id, 405699a2dd95SBruce Richardson struct rte_eth_udp_tunnel *udp_tunnel) 405799a2dd95SBruce Richardson { 405899a2dd95SBruce Richardson struct rte_eth_dev *dev; 405999a2dd95SBruce Richardson 406099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 406153ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 406253ef1b34SMin Hu (Connor) 406399a2dd95SBruce Richardson if (udp_tunnel == NULL) { 406453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 406553ef1b34SMin Hu (Connor) "Cannot add ethdev port %u UDP tunnel port from NULL UDP tunnel\n", 406653ef1b34SMin Hu (Connor) port_id); 406799a2dd95SBruce Richardson return -EINVAL; 406899a2dd95SBruce Richardson } 406999a2dd95SBruce Richardson 407099a2dd95SBruce Richardson if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { 407199a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n"); 407299a2dd95SBruce Richardson return -EINVAL; 407399a2dd95SBruce Richardson } 407499a2dd95SBruce Richardson 407599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_add, -ENOTSUP); 407699a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_add)(dev, 407799a2dd95SBruce Richardson udp_tunnel)); 407899a2dd95SBruce Richardson } 407999a2dd95SBruce Richardson 408099a2dd95SBruce Richardson int 408199a2dd95SBruce Richardson rte_eth_dev_udp_tunnel_port_delete(uint16_t port_id, 408299a2dd95SBruce Richardson struct rte_eth_udp_tunnel *udp_tunnel) 408399a2dd95SBruce Richardson { 408499a2dd95SBruce Richardson struct rte_eth_dev *dev; 408599a2dd95SBruce Richardson 408699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 408799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 408899a2dd95SBruce Richardson 408999a2dd95SBruce Richardson if (udp_tunnel == NULL) { 409053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 409153ef1b34SMin Hu (Connor) "Cannot delete ethdev port %u UDP tunnel port from NULL UDP tunnel\n", 409253ef1b34SMin Hu (Connor) port_id); 409399a2dd95SBruce Richardson return -EINVAL; 409499a2dd95SBruce Richardson } 409599a2dd95SBruce Richardson 409699a2dd95SBruce Richardson if (udp_tunnel->prot_type >= RTE_TUNNEL_TYPE_MAX) { 409799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n"); 409899a2dd95SBruce Richardson return -EINVAL; 409999a2dd95SBruce Richardson } 410099a2dd95SBruce Richardson 410199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->udp_tunnel_port_del, -ENOTSUP); 410299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->udp_tunnel_port_del)(dev, 410399a2dd95SBruce Richardson udp_tunnel)); 410499a2dd95SBruce Richardson } 410599a2dd95SBruce Richardson 410699a2dd95SBruce Richardson int 410799a2dd95SBruce Richardson rte_eth_led_on(uint16_t port_id) 410899a2dd95SBruce Richardson { 410999a2dd95SBruce Richardson struct rte_eth_dev *dev; 411099a2dd95SBruce Richardson 411199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 411299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 411353ef1b34SMin Hu (Connor) 411499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_on, -ENOTSUP); 411599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_led_on)(dev)); 411699a2dd95SBruce Richardson } 411799a2dd95SBruce Richardson 411899a2dd95SBruce Richardson int 411999a2dd95SBruce Richardson rte_eth_led_off(uint16_t port_id) 412099a2dd95SBruce Richardson { 412199a2dd95SBruce Richardson struct rte_eth_dev *dev; 412299a2dd95SBruce Richardson 412399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 412499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 412553ef1b34SMin Hu (Connor) 412699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->dev_led_off, -ENOTSUP); 412799a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->dev_led_off)(dev)); 412899a2dd95SBruce Richardson } 412999a2dd95SBruce Richardson 413099a2dd95SBruce Richardson int 413199a2dd95SBruce Richardson rte_eth_fec_get_capability(uint16_t port_id, 413299a2dd95SBruce Richardson struct rte_eth_fec_capa *speed_fec_capa, 413399a2dd95SBruce Richardson unsigned int num) 413499a2dd95SBruce Richardson { 413599a2dd95SBruce Richardson struct rte_eth_dev *dev; 413699a2dd95SBruce Richardson int ret; 413799a2dd95SBruce Richardson 413899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 413999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 414053ef1b34SMin Hu (Connor) 414153ef1b34SMin Hu (Connor) if (speed_fec_capa == NULL && num > 0) { 414253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 414353ef1b34SMin Hu (Connor) "Cannot get ethdev port %u FEC capability to NULL when array size is non zero\n", 414453ef1b34SMin Hu (Connor) port_id); 414553ef1b34SMin Hu (Connor) return -EINVAL; 414653ef1b34SMin Hu (Connor) } 414753ef1b34SMin Hu (Connor) 414899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get_capability, -ENOTSUP); 414999a2dd95SBruce Richardson ret = (*dev->dev_ops->fec_get_capability)(dev, speed_fec_capa, num); 415099a2dd95SBruce Richardson 415199a2dd95SBruce Richardson return ret; 415299a2dd95SBruce Richardson } 415399a2dd95SBruce Richardson 415499a2dd95SBruce Richardson int 415599a2dd95SBruce Richardson rte_eth_fec_get(uint16_t port_id, uint32_t *fec_capa) 415699a2dd95SBruce Richardson { 415799a2dd95SBruce Richardson struct rte_eth_dev *dev; 415899a2dd95SBruce Richardson 415999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 416099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 416153ef1b34SMin Hu (Connor) 416253ef1b34SMin Hu (Connor) if (fec_capa == NULL) { 416353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 416453ef1b34SMin Hu (Connor) "Cannot get ethdev port %u current FEC mode to NULL\n", 416553ef1b34SMin Hu (Connor) port_id); 416653ef1b34SMin Hu (Connor) return -EINVAL; 416753ef1b34SMin Hu (Connor) } 416853ef1b34SMin Hu (Connor) 416999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_get, -ENOTSUP); 417099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->fec_get)(dev, fec_capa)); 417199a2dd95SBruce Richardson } 417299a2dd95SBruce Richardson 417399a2dd95SBruce Richardson int 417499a2dd95SBruce Richardson rte_eth_fec_set(uint16_t port_id, uint32_t fec_capa) 417599a2dd95SBruce Richardson { 417699a2dd95SBruce Richardson struct rte_eth_dev *dev; 417799a2dd95SBruce Richardson 417899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 417999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 418053ef1b34SMin Hu (Connor) 418199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->fec_set, -ENOTSUP); 418299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->fec_set)(dev, fec_capa)); 418399a2dd95SBruce Richardson } 418499a2dd95SBruce Richardson 418599a2dd95SBruce Richardson /* 418699a2dd95SBruce Richardson * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find 418799a2dd95SBruce Richardson * an empty spot. 418899a2dd95SBruce Richardson */ 418999a2dd95SBruce Richardson static int 419099a2dd95SBruce Richardson eth_dev_get_mac_addr_index(uint16_t port_id, const struct rte_ether_addr *addr) 419199a2dd95SBruce Richardson { 419299a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 419399a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 419499a2dd95SBruce Richardson unsigned i; 419599a2dd95SBruce Richardson int ret; 419699a2dd95SBruce Richardson 419799a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 419899a2dd95SBruce Richardson if (ret != 0) 419999a2dd95SBruce Richardson return -1; 420099a2dd95SBruce Richardson 420199a2dd95SBruce Richardson for (i = 0; i < dev_info.max_mac_addrs; i++) 420299a2dd95SBruce Richardson if (memcmp(addr, &dev->data->mac_addrs[i], 420399a2dd95SBruce Richardson RTE_ETHER_ADDR_LEN) == 0) 420499a2dd95SBruce Richardson return i; 420599a2dd95SBruce Richardson 420699a2dd95SBruce Richardson return -1; 420799a2dd95SBruce Richardson } 420899a2dd95SBruce Richardson 420999a2dd95SBruce Richardson static const struct rte_ether_addr null_mac_addr; 421099a2dd95SBruce Richardson 421199a2dd95SBruce Richardson int 421299a2dd95SBruce Richardson rte_eth_dev_mac_addr_add(uint16_t port_id, struct rte_ether_addr *addr, 421399a2dd95SBruce Richardson uint32_t pool) 421499a2dd95SBruce Richardson { 421599a2dd95SBruce Richardson struct rte_eth_dev *dev; 421699a2dd95SBruce Richardson int index; 421799a2dd95SBruce Richardson uint64_t pool_mask; 421899a2dd95SBruce Richardson int ret; 421999a2dd95SBruce Richardson 422099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 422199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 422253ef1b34SMin Hu (Connor) 422353ef1b34SMin Hu (Connor) if (addr == NULL) { 422453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 422553ef1b34SMin Hu (Connor) "Cannot add ethdev port %u MAC address from NULL address\n", 422653ef1b34SMin Hu (Connor) port_id); 422753ef1b34SMin Hu (Connor) return -EINVAL; 422853ef1b34SMin Hu (Connor) } 422953ef1b34SMin Hu (Connor) 423099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_add, -ENOTSUP); 423199a2dd95SBruce Richardson 423299a2dd95SBruce Richardson if (rte_is_zero_ether_addr(addr)) { 423399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n", 423499a2dd95SBruce Richardson port_id); 423599a2dd95SBruce Richardson return -EINVAL; 423699a2dd95SBruce Richardson } 423799a2dd95SBruce Richardson if (pool >= ETH_64_POOLS) { 423899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Pool id must be 0-%d\n", ETH_64_POOLS - 1); 423999a2dd95SBruce Richardson return -EINVAL; 424099a2dd95SBruce Richardson } 424199a2dd95SBruce Richardson 424299a2dd95SBruce Richardson index = eth_dev_get_mac_addr_index(port_id, addr); 424399a2dd95SBruce Richardson if (index < 0) { 424499a2dd95SBruce Richardson index = eth_dev_get_mac_addr_index(port_id, &null_mac_addr); 424599a2dd95SBruce Richardson if (index < 0) { 424699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n", 424799a2dd95SBruce Richardson port_id); 424899a2dd95SBruce Richardson return -ENOSPC; 424999a2dd95SBruce Richardson } 425099a2dd95SBruce Richardson } else { 425199a2dd95SBruce Richardson pool_mask = dev->data->mac_pool_sel[index]; 425299a2dd95SBruce Richardson 425399a2dd95SBruce Richardson /* Check if both MAC address and pool is already there, and do nothing */ 425499a2dd95SBruce Richardson if (pool_mask & (1ULL << pool)) 425599a2dd95SBruce Richardson return 0; 425699a2dd95SBruce Richardson } 425799a2dd95SBruce Richardson 425899a2dd95SBruce Richardson /* Update NIC */ 425999a2dd95SBruce Richardson ret = (*dev->dev_ops->mac_addr_add)(dev, addr, index, pool); 426099a2dd95SBruce Richardson 426199a2dd95SBruce Richardson if (ret == 0) { 426299a2dd95SBruce Richardson /* Update address in NIC data structure */ 426399a2dd95SBruce Richardson rte_ether_addr_copy(addr, &dev->data->mac_addrs[index]); 426499a2dd95SBruce Richardson 426599a2dd95SBruce Richardson /* Update pool bitmap in NIC data structure */ 426699a2dd95SBruce Richardson dev->data->mac_pool_sel[index] |= (1ULL << pool); 426799a2dd95SBruce Richardson } 426899a2dd95SBruce Richardson 426999a2dd95SBruce Richardson return eth_err(port_id, ret); 427099a2dd95SBruce Richardson } 427199a2dd95SBruce Richardson 427299a2dd95SBruce Richardson int 427399a2dd95SBruce Richardson rte_eth_dev_mac_addr_remove(uint16_t port_id, struct rte_ether_addr *addr) 427499a2dd95SBruce Richardson { 427599a2dd95SBruce Richardson struct rte_eth_dev *dev; 427699a2dd95SBruce Richardson int index; 427799a2dd95SBruce Richardson 427899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 427999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 428053ef1b34SMin Hu (Connor) 428153ef1b34SMin Hu (Connor) if (addr == NULL) { 428253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 428353ef1b34SMin Hu (Connor) "Cannot remove ethdev port %u MAC address from NULL address\n", 428453ef1b34SMin Hu (Connor) port_id); 428553ef1b34SMin Hu (Connor) return -EINVAL; 428653ef1b34SMin Hu (Connor) } 428753ef1b34SMin Hu (Connor) 428899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_remove, -ENOTSUP); 428999a2dd95SBruce Richardson 429099a2dd95SBruce Richardson index = eth_dev_get_mac_addr_index(port_id, addr); 429199a2dd95SBruce Richardson if (index == 0) { 429299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 429399a2dd95SBruce Richardson "Port %u: Cannot remove default MAC address\n", 429499a2dd95SBruce Richardson port_id); 429599a2dd95SBruce Richardson return -EADDRINUSE; 429699a2dd95SBruce Richardson } else if (index < 0) 429799a2dd95SBruce Richardson return 0; /* Do nothing if address wasn't found */ 429899a2dd95SBruce Richardson 429999a2dd95SBruce Richardson /* Update NIC */ 430099a2dd95SBruce Richardson (*dev->dev_ops->mac_addr_remove)(dev, index); 430199a2dd95SBruce Richardson 430299a2dd95SBruce Richardson /* Update address in NIC data structure */ 430399a2dd95SBruce Richardson rte_ether_addr_copy(&null_mac_addr, &dev->data->mac_addrs[index]); 430499a2dd95SBruce Richardson 430599a2dd95SBruce Richardson /* reset pool bitmap */ 430699a2dd95SBruce Richardson dev->data->mac_pool_sel[index] = 0; 430799a2dd95SBruce Richardson 430899a2dd95SBruce Richardson return 0; 430999a2dd95SBruce Richardson } 431099a2dd95SBruce Richardson 431199a2dd95SBruce Richardson int 431299a2dd95SBruce Richardson rte_eth_dev_default_mac_addr_set(uint16_t port_id, struct rte_ether_addr *addr) 431399a2dd95SBruce Richardson { 431499a2dd95SBruce Richardson struct rte_eth_dev *dev; 431599a2dd95SBruce Richardson int ret; 431699a2dd95SBruce Richardson 431799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 431853ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 431953ef1b34SMin Hu (Connor) 432053ef1b34SMin Hu (Connor) if (addr == NULL) { 432153ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 432253ef1b34SMin Hu (Connor) "Cannot set ethdev port %u default MAC address from NULL address\n", 432353ef1b34SMin Hu (Connor) port_id); 432453ef1b34SMin Hu (Connor) return -EINVAL; 432553ef1b34SMin Hu (Connor) } 432699a2dd95SBruce Richardson 432799a2dd95SBruce Richardson if (!rte_is_valid_assigned_ether_addr(addr)) 432899a2dd95SBruce Richardson return -EINVAL; 432999a2dd95SBruce Richardson 433099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->mac_addr_set, -ENOTSUP); 433199a2dd95SBruce Richardson 433299a2dd95SBruce Richardson ret = (*dev->dev_ops->mac_addr_set)(dev, addr); 433399a2dd95SBruce Richardson if (ret < 0) 433499a2dd95SBruce Richardson return ret; 433599a2dd95SBruce Richardson 433699a2dd95SBruce Richardson /* Update default address in NIC data structure */ 433799a2dd95SBruce Richardson rte_ether_addr_copy(addr, &dev->data->mac_addrs[0]); 433899a2dd95SBruce Richardson 433999a2dd95SBruce Richardson return 0; 434099a2dd95SBruce Richardson } 434199a2dd95SBruce Richardson 434299a2dd95SBruce Richardson 434399a2dd95SBruce Richardson /* 434499a2dd95SBruce Richardson * Returns index into MAC address array of addr. Use 00:00:00:00:00:00 to find 434599a2dd95SBruce Richardson * an empty spot. 434699a2dd95SBruce Richardson */ 434799a2dd95SBruce Richardson static int 434899a2dd95SBruce Richardson eth_dev_get_hash_mac_addr_index(uint16_t port_id, 434999a2dd95SBruce Richardson const struct rte_ether_addr *addr) 435099a2dd95SBruce Richardson { 435199a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 435299a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 435399a2dd95SBruce Richardson unsigned i; 435499a2dd95SBruce Richardson int ret; 435599a2dd95SBruce Richardson 435699a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 435799a2dd95SBruce Richardson if (ret != 0) 435899a2dd95SBruce Richardson return -1; 435999a2dd95SBruce Richardson 436099a2dd95SBruce Richardson if (!dev->data->hash_mac_addrs) 436199a2dd95SBruce Richardson return -1; 436299a2dd95SBruce Richardson 436399a2dd95SBruce Richardson for (i = 0; i < dev_info.max_hash_mac_addrs; i++) 436499a2dd95SBruce Richardson if (memcmp(addr, &dev->data->hash_mac_addrs[i], 436599a2dd95SBruce Richardson RTE_ETHER_ADDR_LEN) == 0) 436699a2dd95SBruce Richardson return i; 436799a2dd95SBruce Richardson 436899a2dd95SBruce Richardson return -1; 436999a2dd95SBruce Richardson } 437099a2dd95SBruce Richardson 437199a2dd95SBruce Richardson int 437299a2dd95SBruce Richardson rte_eth_dev_uc_hash_table_set(uint16_t port_id, struct rte_ether_addr *addr, 437399a2dd95SBruce Richardson uint8_t on) 437499a2dd95SBruce Richardson { 437599a2dd95SBruce Richardson int index; 437699a2dd95SBruce Richardson int ret; 437799a2dd95SBruce Richardson struct rte_eth_dev *dev; 437899a2dd95SBruce Richardson 437999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 438099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 438153ef1b34SMin Hu (Connor) 438253ef1b34SMin Hu (Connor) if (addr == NULL) { 438353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 438453ef1b34SMin Hu (Connor) "Cannot set ethdev port %u unicast hash table from NULL address\n", 438553ef1b34SMin Hu (Connor) port_id); 438653ef1b34SMin Hu (Connor) return -EINVAL; 438753ef1b34SMin Hu (Connor) } 438853ef1b34SMin Hu (Connor) 438999a2dd95SBruce Richardson if (rte_is_zero_ether_addr(addr)) { 439099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: Cannot add NULL MAC address\n", 439199a2dd95SBruce Richardson port_id); 439299a2dd95SBruce Richardson return -EINVAL; 439399a2dd95SBruce Richardson } 439499a2dd95SBruce Richardson 439599a2dd95SBruce Richardson index = eth_dev_get_hash_mac_addr_index(port_id, addr); 439699a2dd95SBruce Richardson /* Check if it's already there, and do nothing */ 439799a2dd95SBruce Richardson if ((index >= 0) && on) 439899a2dd95SBruce Richardson return 0; 439999a2dd95SBruce Richardson 440099a2dd95SBruce Richardson if (index < 0) { 440199a2dd95SBruce Richardson if (!on) { 440299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 440399a2dd95SBruce Richardson "Port %u: the MAC address was not set in UTA\n", 440499a2dd95SBruce Richardson port_id); 440599a2dd95SBruce Richardson return -EINVAL; 440699a2dd95SBruce Richardson } 440799a2dd95SBruce Richardson 440899a2dd95SBruce Richardson index = eth_dev_get_hash_mac_addr_index(port_id, &null_mac_addr); 440999a2dd95SBruce Richardson if (index < 0) { 441099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Port %u: MAC address array full\n", 441199a2dd95SBruce Richardson port_id); 441299a2dd95SBruce Richardson return -ENOSPC; 441399a2dd95SBruce Richardson } 441499a2dd95SBruce Richardson } 441599a2dd95SBruce Richardson 441699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_hash_table_set, -ENOTSUP); 441799a2dd95SBruce Richardson ret = (*dev->dev_ops->uc_hash_table_set)(dev, addr, on); 441899a2dd95SBruce Richardson if (ret == 0) { 441999a2dd95SBruce Richardson /* Update address in NIC data structure */ 442099a2dd95SBruce Richardson if (on) 442199a2dd95SBruce Richardson rte_ether_addr_copy(addr, 442299a2dd95SBruce Richardson &dev->data->hash_mac_addrs[index]); 442399a2dd95SBruce Richardson else 442499a2dd95SBruce Richardson rte_ether_addr_copy(&null_mac_addr, 442599a2dd95SBruce Richardson &dev->data->hash_mac_addrs[index]); 442699a2dd95SBruce Richardson } 442799a2dd95SBruce Richardson 442899a2dd95SBruce Richardson return eth_err(port_id, ret); 442999a2dd95SBruce Richardson } 443099a2dd95SBruce Richardson 443199a2dd95SBruce Richardson int 443299a2dd95SBruce Richardson rte_eth_dev_uc_all_hash_table_set(uint16_t port_id, uint8_t on) 443399a2dd95SBruce Richardson { 443499a2dd95SBruce Richardson struct rte_eth_dev *dev; 443599a2dd95SBruce Richardson 443699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 443799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 443899a2dd95SBruce Richardson 443999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->uc_all_hash_table_set, -ENOTSUP); 444099a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->uc_all_hash_table_set)(dev, 444199a2dd95SBruce Richardson on)); 444299a2dd95SBruce Richardson } 444399a2dd95SBruce Richardson 444499a2dd95SBruce Richardson int rte_eth_set_queue_rate_limit(uint16_t port_id, uint16_t queue_idx, 444599a2dd95SBruce Richardson uint16_t tx_rate) 444699a2dd95SBruce Richardson { 444799a2dd95SBruce Richardson struct rte_eth_dev *dev; 444899a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 444999a2dd95SBruce Richardson struct rte_eth_link link; 445099a2dd95SBruce Richardson int ret; 445199a2dd95SBruce Richardson 445299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 445353ef1b34SMin Hu (Connor) dev = &rte_eth_devices[port_id]; 445499a2dd95SBruce Richardson 445599a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 445699a2dd95SBruce Richardson if (ret != 0) 445799a2dd95SBruce Richardson return ret; 445899a2dd95SBruce Richardson 445999a2dd95SBruce Richardson link = dev->data->dev_link; 446099a2dd95SBruce Richardson 446199a2dd95SBruce Richardson if (queue_idx > dev_info.max_tx_queues) { 446299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 446399a2dd95SBruce Richardson "Set queue rate limit:port %u: invalid queue id=%u\n", 446499a2dd95SBruce Richardson port_id, queue_idx); 446599a2dd95SBruce Richardson return -EINVAL; 446699a2dd95SBruce Richardson } 446799a2dd95SBruce Richardson 446899a2dd95SBruce Richardson if (tx_rate > link.link_speed) { 446999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 447099a2dd95SBruce Richardson "Set queue rate limit:invalid tx_rate=%u, bigger than link speed= %d\n", 447199a2dd95SBruce Richardson tx_rate, link.link_speed); 447299a2dd95SBruce Richardson return -EINVAL; 447399a2dd95SBruce Richardson } 447499a2dd95SBruce Richardson 447599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_queue_rate_limit, -ENOTSUP); 447699a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->set_queue_rate_limit)(dev, 447799a2dd95SBruce Richardson queue_idx, tx_rate)); 447899a2dd95SBruce Richardson } 447999a2dd95SBruce Richardson 448099a2dd95SBruce Richardson RTE_INIT(eth_dev_init_cb_lists) 448199a2dd95SBruce Richardson { 448299a2dd95SBruce Richardson uint16_t i; 448399a2dd95SBruce Richardson 448499a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) 448599a2dd95SBruce Richardson TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs); 448699a2dd95SBruce Richardson } 448799a2dd95SBruce Richardson 448899a2dd95SBruce Richardson int 448999a2dd95SBruce Richardson rte_eth_dev_callback_register(uint16_t port_id, 449099a2dd95SBruce Richardson enum rte_eth_event_type event, 449199a2dd95SBruce Richardson rte_eth_dev_cb_fn cb_fn, void *cb_arg) 449299a2dd95SBruce Richardson { 449399a2dd95SBruce Richardson struct rte_eth_dev *dev; 449499a2dd95SBruce Richardson struct rte_eth_dev_callback *user_cb; 449599a2dd95SBruce Richardson uint16_t next_port; 449699a2dd95SBruce Richardson uint16_t last_port; 449799a2dd95SBruce Richardson 449853ef1b34SMin Hu (Connor) if (cb_fn == NULL) { 449953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 450053ef1b34SMin Hu (Connor) "Cannot register ethdev port %u callback from NULL\n", 450153ef1b34SMin Hu (Connor) port_id); 450299a2dd95SBruce Richardson return -EINVAL; 450353ef1b34SMin Hu (Connor) } 450499a2dd95SBruce Richardson 450599a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { 450699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id); 450799a2dd95SBruce Richardson return -EINVAL; 450899a2dd95SBruce Richardson } 450999a2dd95SBruce Richardson 451099a2dd95SBruce Richardson if (port_id == RTE_ETH_ALL) { 451199a2dd95SBruce Richardson next_port = 0; 451299a2dd95SBruce Richardson last_port = RTE_MAX_ETHPORTS - 1; 451399a2dd95SBruce Richardson } else { 451499a2dd95SBruce Richardson next_port = last_port = port_id; 451599a2dd95SBruce Richardson } 451699a2dd95SBruce Richardson 451799a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 451899a2dd95SBruce Richardson 451999a2dd95SBruce Richardson do { 452099a2dd95SBruce Richardson dev = &rte_eth_devices[next_port]; 452199a2dd95SBruce Richardson 452299a2dd95SBruce Richardson TAILQ_FOREACH(user_cb, &(dev->link_intr_cbs), next) { 452399a2dd95SBruce Richardson if (user_cb->cb_fn == cb_fn && 452499a2dd95SBruce Richardson user_cb->cb_arg == cb_arg && 452599a2dd95SBruce Richardson user_cb->event == event) { 452699a2dd95SBruce Richardson break; 452799a2dd95SBruce Richardson } 452899a2dd95SBruce Richardson } 452999a2dd95SBruce Richardson 453099a2dd95SBruce Richardson /* create a new callback. */ 453199a2dd95SBruce Richardson if (user_cb == NULL) { 453299a2dd95SBruce Richardson user_cb = rte_zmalloc("INTR_USER_CALLBACK", 453399a2dd95SBruce Richardson sizeof(struct rte_eth_dev_callback), 0); 453499a2dd95SBruce Richardson if (user_cb != NULL) { 453599a2dd95SBruce Richardson user_cb->cb_fn = cb_fn; 453699a2dd95SBruce Richardson user_cb->cb_arg = cb_arg; 453799a2dd95SBruce Richardson user_cb->event = event; 453899a2dd95SBruce Richardson TAILQ_INSERT_TAIL(&(dev->link_intr_cbs), 453999a2dd95SBruce Richardson user_cb, next); 454099a2dd95SBruce Richardson } else { 454199a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 454299a2dd95SBruce Richardson rte_eth_dev_callback_unregister(port_id, event, 454399a2dd95SBruce Richardson cb_fn, cb_arg); 454499a2dd95SBruce Richardson return -ENOMEM; 454599a2dd95SBruce Richardson } 454699a2dd95SBruce Richardson 454799a2dd95SBruce Richardson } 454899a2dd95SBruce Richardson } while (++next_port <= last_port); 454999a2dd95SBruce Richardson 455099a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 455199a2dd95SBruce Richardson return 0; 455299a2dd95SBruce Richardson } 455399a2dd95SBruce Richardson 455499a2dd95SBruce Richardson int 455599a2dd95SBruce Richardson rte_eth_dev_callback_unregister(uint16_t port_id, 455699a2dd95SBruce Richardson enum rte_eth_event_type event, 455799a2dd95SBruce Richardson rte_eth_dev_cb_fn cb_fn, void *cb_arg) 455899a2dd95SBruce Richardson { 455999a2dd95SBruce Richardson int ret; 456099a2dd95SBruce Richardson struct rte_eth_dev *dev; 456199a2dd95SBruce Richardson struct rte_eth_dev_callback *cb, *next; 456299a2dd95SBruce Richardson uint16_t next_port; 456399a2dd95SBruce Richardson uint16_t last_port; 456499a2dd95SBruce Richardson 456553ef1b34SMin Hu (Connor) if (cb_fn == NULL) { 456653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 456753ef1b34SMin Hu (Connor) "Cannot unregister ethdev port %u callback from NULL\n", 456853ef1b34SMin Hu (Connor) port_id); 456999a2dd95SBruce Richardson return -EINVAL; 457053ef1b34SMin Hu (Connor) } 457199a2dd95SBruce Richardson 457299a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) && port_id != RTE_ETH_ALL) { 457399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid port_id=%d\n", port_id); 457499a2dd95SBruce Richardson return -EINVAL; 457599a2dd95SBruce Richardson } 457699a2dd95SBruce Richardson 457799a2dd95SBruce Richardson if (port_id == RTE_ETH_ALL) { 457899a2dd95SBruce Richardson next_port = 0; 457999a2dd95SBruce Richardson last_port = RTE_MAX_ETHPORTS - 1; 458099a2dd95SBruce Richardson } else { 458199a2dd95SBruce Richardson next_port = last_port = port_id; 458299a2dd95SBruce Richardson } 458399a2dd95SBruce Richardson 458499a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 458599a2dd95SBruce Richardson 458699a2dd95SBruce Richardson do { 458799a2dd95SBruce Richardson dev = &rte_eth_devices[next_port]; 458899a2dd95SBruce Richardson ret = 0; 458999a2dd95SBruce Richardson for (cb = TAILQ_FIRST(&dev->link_intr_cbs); cb != NULL; 459099a2dd95SBruce Richardson cb = next) { 459199a2dd95SBruce Richardson 459299a2dd95SBruce Richardson next = TAILQ_NEXT(cb, next); 459399a2dd95SBruce Richardson 459499a2dd95SBruce Richardson if (cb->cb_fn != cb_fn || cb->event != event || 459599a2dd95SBruce Richardson (cb_arg != (void *)-1 && cb->cb_arg != cb_arg)) 459699a2dd95SBruce Richardson continue; 459799a2dd95SBruce Richardson 459899a2dd95SBruce Richardson /* 459999a2dd95SBruce Richardson * if this callback is not executing right now, 460099a2dd95SBruce Richardson * then remove it. 460199a2dd95SBruce Richardson */ 460299a2dd95SBruce Richardson if (cb->active == 0) { 460399a2dd95SBruce Richardson TAILQ_REMOVE(&(dev->link_intr_cbs), cb, next); 460499a2dd95SBruce Richardson rte_free(cb); 460599a2dd95SBruce Richardson } else { 460699a2dd95SBruce Richardson ret = -EAGAIN; 460799a2dd95SBruce Richardson } 460899a2dd95SBruce Richardson } 460999a2dd95SBruce Richardson } while (++next_port <= last_port); 461099a2dd95SBruce Richardson 461199a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 461299a2dd95SBruce Richardson return ret; 461399a2dd95SBruce Richardson } 461499a2dd95SBruce Richardson 461599a2dd95SBruce Richardson int 461699a2dd95SBruce Richardson rte_eth_dev_callback_process(struct rte_eth_dev *dev, 461799a2dd95SBruce Richardson enum rte_eth_event_type event, void *ret_param) 461899a2dd95SBruce Richardson { 461999a2dd95SBruce Richardson struct rte_eth_dev_callback *cb_lst; 462099a2dd95SBruce Richardson struct rte_eth_dev_callback dev_cb; 462199a2dd95SBruce Richardson int rc = 0; 462299a2dd95SBruce Richardson 462399a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 462499a2dd95SBruce Richardson TAILQ_FOREACH(cb_lst, &(dev->link_intr_cbs), next) { 462599a2dd95SBruce Richardson if (cb_lst->cb_fn == NULL || cb_lst->event != event) 462699a2dd95SBruce Richardson continue; 462799a2dd95SBruce Richardson dev_cb = *cb_lst; 462899a2dd95SBruce Richardson cb_lst->active = 1; 462999a2dd95SBruce Richardson if (ret_param != NULL) 463099a2dd95SBruce Richardson dev_cb.ret_param = ret_param; 463199a2dd95SBruce Richardson 463299a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 463399a2dd95SBruce Richardson rc = dev_cb.cb_fn(dev->data->port_id, dev_cb.event, 463499a2dd95SBruce Richardson dev_cb.cb_arg, dev_cb.ret_param); 463599a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_cb_lock); 463699a2dd95SBruce Richardson cb_lst->active = 0; 463799a2dd95SBruce Richardson } 463899a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_cb_lock); 463999a2dd95SBruce Richardson return rc; 464099a2dd95SBruce Richardson } 464199a2dd95SBruce Richardson 464299a2dd95SBruce Richardson void 464399a2dd95SBruce Richardson rte_eth_dev_probing_finish(struct rte_eth_dev *dev) 464499a2dd95SBruce Richardson { 464599a2dd95SBruce Richardson if (dev == NULL) 464699a2dd95SBruce Richardson return; 464799a2dd95SBruce Richardson 464899a2dd95SBruce Richardson rte_eth_dev_callback_process(dev, RTE_ETH_EVENT_NEW, NULL); 464999a2dd95SBruce Richardson 465099a2dd95SBruce Richardson dev->state = RTE_ETH_DEV_ATTACHED; 465199a2dd95SBruce Richardson } 465299a2dd95SBruce Richardson 465399a2dd95SBruce Richardson int 465499a2dd95SBruce Richardson rte_eth_dev_rx_intr_ctl(uint16_t port_id, int epfd, int op, void *data) 465599a2dd95SBruce Richardson { 465699a2dd95SBruce Richardson uint32_t vec; 465799a2dd95SBruce Richardson struct rte_eth_dev *dev; 465899a2dd95SBruce Richardson struct rte_intr_handle *intr_handle; 465999a2dd95SBruce Richardson uint16_t qid; 466099a2dd95SBruce Richardson int rc; 466199a2dd95SBruce Richardson 466299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 466399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 466499a2dd95SBruce Richardson 466599a2dd95SBruce Richardson if (!dev->intr_handle) { 466699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n"); 466799a2dd95SBruce Richardson return -ENOTSUP; 466899a2dd95SBruce Richardson } 466999a2dd95SBruce Richardson 467099a2dd95SBruce Richardson intr_handle = dev->intr_handle; 467199a2dd95SBruce Richardson if (!intr_handle->intr_vec) { 467299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n"); 467399a2dd95SBruce Richardson return -EPERM; 467499a2dd95SBruce Richardson } 467599a2dd95SBruce Richardson 467699a2dd95SBruce Richardson for (qid = 0; qid < dev->data->nb_rx_queues; qid++) { 467799a2dd95SBruce Richardson vec = intr_handle->intr_vec[qid]; 467899a2dd95SBruce Richardson rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); 467999a2dd95SBruce Richardson if (rc && rc != -EEXIST) { 468099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 468199a2dd95SBruce Richardson "p %u q %u rx ctl error op %d epfd %d vec %u\n", 468299a2dd95SBruce Richardson port_id, qid, op, epfd, vec); 468399a2dd95SBruce Richardson } 468499a2dd95SBruce Richardson } 468599a2dd95SBruce Richardson 468699a2dd95SBruce Richardson return 0; 468799a2dd95SBruce Richardson } 468899a2dd95SBruce Richardson 468999a2dd95SBruce Richardson int 469099a2dd95SBruce Richardson rte_eth_dev_rx_intr_ctl_q_get_fd(uint16_t port_id, uint16_t queue_id) 469199a2dd95SBruce Richardson { 469299a2dd95SBruce Richardson struct rte_intr_handle *intr_handle; 469399a2dd95SBruce Richardson struct rte_eth_dev *dev; 469499a2dd95SBruce Richardson unsigned int efd_idx; 469599a2dd95SBruce Richardson uint32_t vec; 469699a2dd95SBruce Richardson int fd; 469799a2dd95SBruce Richardson 469899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -1); 469999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 470099a2dd95SBruce Richardson 470199a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 470299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 470399a2dd95SBruce Richardson return -1; 470499a2dd95SBruce Richardson } 470599a2dd95SBruce Richardson 470699a2dd95SBruce Richardson if (!dev->intr_handle) { 470799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n"); 470899a2dd95SBruce Richardson return -1; 470999a2dd95SBruce Richardson } 471099a2dd95SBruce Richardson 471199a2dd95SBruce Richardson intr_handle = dev->intr_handle; 471299a2dd95SBruce Richardson if (!intr_handle->intr_vec) { 471399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n"); 471499a2dd95SBruce Richardson return -1; 471599a2dd95SBruce Richardson } 471699a2dd95SBruce Richardson 471799a2dd95SBruce Richardson vec = intr_handle->intr_vec[queue_id]; 471899a2dd95SBruce Richardson efd_idx = (vec >= RTE_INTR_VEC_RXTX_OFFSET) ? 471999a2dd95SBruce Richardson (vec - RTE_INTR_VEC_RXTX_OFFSET) : vec; 472099a2dd95SBruce Richardson fd = intr_handle->efds[efd_idx]; 472199a2dd95SBruce Richardson 472299a2dd95SBruce Richardson return fd; 472399a2dd95SBruce Richardson } 472499a2dd95SBruce Richardson 472599a2dd95SBruce Richardson static inline int 472699a2dd95SBruce Richardson eth_dev_dma_mzone_name(char *name, size_t len, uint16_t port_id, uint16_t queue_id, 472799a2dd95SBruce Richardson const char *ring_name) 472899a2dd95SBruce Richardson { 472999a2dd95SBruce Richardson return snprintf(name, len, "eth_p%d_q%d_%s", 473099a2dd95SBruce Richardson port_id, queue_id, ring_name); 473199a2dd95SBruce Richardson } 473299a2dd95SBruce Richardson 473399a2dd95SBruce Richardson const struct rte_memzone * 473499a2dd95SBruce Richardson rte_eth_dma_zone_reserve(const struct rte_eth_dev *dev, const char *ring_name, 473599a2dd95SBruce Richardson uint16_t queue_id, size_t size, unsigned align, 473699a2dd95SBruce Richardson int socket_id) 473799a2dd95SBruce Richardson { 473899a2dd95SBruce Richardson char z_name[RTE_MEMZONE_NAMESIZE]; 473999a2dd95SBruce Richardson const struct rte_memzone *mz; 474099a2dd95SBruce Richardson int rc; 474199a2dd95SBruce Richardson 474299a2dd95SBruce Richardson rc = eth_dev_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id, 474399a2dd95SBruce Richardson queue_id, ring_name); 474499a2dd95SBruce Richardson if (rc >= RTE_MEMZONE_NAMESIZE) { 474599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "ring name too long\n"); 474699a2dd95SBruce Richardson rte_errno = ENAMETOOLONG; 474799a2dd95SBruce Richardson return NULL; 474899a2dd95SBruce Richardson } 474999a2dd95SBruce Richardson 475099a2dd95SBruce Richardson mz = rte_memzone_lookup(z_name); 475199a2dd95SBruce Richardson if (mz) { 475299a2dd95SBruce Richardson if ((socket_id != SOCKET_ID_ANY && socket_id != mz->socket_id) || 475399a2dd95SBruce Richardson size > mz->len || 475499a2dd95SBruce Richardson ((uintptr_t)mz->addr & (align - 1)) != 0) { 475599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 475699a2dd95SBruce Richardson "memzone %s does not justify the requested attributes\n", 475799a2dd95SBruce Richardson mz->name); 475899a2dd95SBruce Richardson return NULL; 475999a2dd95SBruce Richardson } 476099a2dd95SBruce Richardson 476199a2dd95SBruce Richardson return mz; 476299a2dd95SBruce Richardson } 476399a2dd95SBruce Richardson 476499a2dd95SBruce Richardson return rte_memzone_reserve_aligned(z_name, size, socket_id, 476599a2dd95SBruce Richardson RTE_MEMZONE_IOVA_CONTIG, align); 476699a2dd95SBruce Richardson } 476799a2dd95SBruce Richardson 476899a2dd95SBruce Richardson int 476999a2dd95SBruce Richardson rte_eth_dma_zone_free(const struct rte_eth_dev *dev, const char *ring_name, 477099a2dd95SBruce Richardson uint16_t queue_id) 477199a2dd95SBruce Richardson { 477299a2dd95SBruce Richardson char z_name[RTE_MEMZONE_NAMESIZE]; 477399a2dd95SBruce Richardson const struct rte_memzone *mz; 477499a2dd95SBruce Richardson int rc = 0; 477599a2dd95SBruce Richardson 477699a2dd95SBruce Richardson rc = eth_dev_dma_mzone_name(z_name, sizeof(z_name), dev->data->port_id, 477799a2dd95SBruce Richardson queue_id, ring_name); 477899a2dd95SBruce Richardson if (rc >= RTE_MEMZONE_NAMESIZE) { 477999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "ring name too long\n"); 478099a2dd95SBruce Richardson return -ENAMETOOLONG; 478199a2dd95SBruce Richardson } 478299a2dd95SBruce Richardson 478399a2dd95SBruce Richardson mz = rte_memzone_lookup(z_name); 478499a2dd95SBruce Richardson if (mz) 478599a2dd95SBruce Richardson rc = rte_memzone_free(mz); 478699a2dd95SBruce Richardson else 478799a2dd95SBruce Richardson rc = -ENOENT; 478899a2dd95SBruce Richardson 478999a2dd95SBruce Richardson return rc; 479099a2dd95SBruce Richardson } 479199a2dd95SBruce Richardson 479299a2dd95SBruce Richardson int 479399a2dd95SBruce Richardson rte_eth_dev_create(struct rte_device *device, const char *name, 479499a2dd95SBruce Richardson size_t priv_data_size, 479599a2dd95SBruce Richardson ethdev_bus_specific_init ethdev_bus_specific_init, 479699a2dd95SBruce Richardson void *bus_init_params, 479799a2dd95SBruce Richardson ethdev_init_t ethdev_init, void *init_params) 479899a2dd95SBruce Richardson { 479999a2dd95SBruce Richardson struct rte_eth_dev *ethdev; 480099a2dd95SBruce Richardson int retval; 480199a2dd95SBruce Richardson 480299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*ethdev_init, -EINVAL); 480399a2dd95SBruce Richardson 480499a2dd95SBruce Richardson if (rte_eal_process_type() == RTE_PROC_PRIMARY) { 480599a2dd95SBruce Richardson ethdev = rte_eth_dev_allocate(name); 480699a2dd95SBruce Richardson if (!ethdev) 480799a2dd95SBruce Richardson return -ENODEV; 480899a2dd95SBruce Richardson 480999a2dd95SBruce Richardson if (priv_data_size) { 481099a2dd95SBruce Richardson ethdev->data->dev_private = rte_zmalloc_socket( 481199a2dd95SBruce Richardson name, priv_data_size, RTE_CACHE_LINE_SIZE, 481299a2dd95SBruce Richardson device->numa_node); 481399a2dd95SBruce Richardson 481499a2dd95SBruce Richardson if (!ethdev->data->dev_private) { 481599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 481699a2dd95SBruce Richardson "failed to allocate private data\n"); 481799a2dd95SBruce Richardson retval = -ENOMEM; 481899a2dd95SBruce Richardson goto probe_failed; 481999a2dd95SBruce Richardson } 482099a2dd95SBruce Richardson } 482199a2dd95SBruce Richardson } else { 482299a2dd95SBruce Richardson ethdev = rte_eth_dev_attach_secondary(name); 482399a2dd95SBruce Richardson if (!ethdev) { 482499a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 482599a2dd95SBruce Richardson "secondary process attach failed, ethdev doesn't exist\n"); 482699a2dd95SBruce Richardson return -ENODEV; 482799a2dd95SBruce Richardson } 482899a2dd95SBruce Richardson } 482999a2dd95SBruce Richardson 483099a2dd95SBruce Richardson ethdev->device = device; 483199a2dd95SBruce Richardson 483299a2dd95SBruce Richardson if (ethdev_bus_specific_init) { 483399a2dd95SBruce Richardson retval = ethdev_bus_specific_init(ethdev, bus_init_params); 483499a2dd95SBruce Richardson if (retval) { 483599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 483699a2dd95SBruce Richardson "ethdev bus specific initialisation failed\n"); 483799a2dd95SBruce Richardson goto probe_failed; 483899a2dd95SBruce Richardson } 483999a2dd95SBruce Richardson } 484099a2dd95SBruce Richardson 484199a2dd95SBruce Richardson retval = ethdev_init(ethdev, init_params); 484299a2dd95SBruce Richardson if (retval) { 484399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "ethdev initialisation failed\n"); 484499a2dd95SBruce Richardson goto probe_failed; 484599a2dd95SBruce Richardson } 484699a2dd95SBruce Richardson 484799a2dd95SBruce Richardson rte_eth_dev_probing_finish(ethdev); 484899a2dd95SBruce Richardson 484999a2dd95SBruce Richardson return retval; 485099a2dd95SBruce Richardson 485199a2dd95SBruce Richardson probe_failed: 485299a2dd95SBruce Richardson rte_eth_dev_release_port(ethdev); 485399a2dd95SBruce Richardson return retval; 485499a2dd95SBruce Richardson } 485599a2dd95SBruce Richardson 485699a2dd95SBruce Richardson int 485799a2dd95SBruce Richardson rte_eth_dev_destroy(struct rte_eth_dev *ethdev, 485899a2dd95SBruce Richardson ethdev_uninit_t ethdev_uninit) 485999a2dd95SBruce Richardson { 486099a2dd95SBruce Richardson int ret; 486199a2dd95SBruce Richardson 486299a2dd95SBruce Richardson ethdev = rte_eth_dev_allocated(ethdev->data->name); 486399a2dd95SBruce Richardson if (!ethdev) 486499a2dd95SBruce Richardson return -ENODEV; 486599a2dd95SBruce Richardson 486699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*ethdev_uninit, -EINVAL); 486799a2dd95SBruce Richardson 486899a2dd95SBruce Richardson ret = ethdev_uninit(ethdev); 486999a2dd95SBruce Richardson if (ret) 487099a2dd95SBruce Richardson return ret; 487199a2dd95SBruce Richardson 487299a2dd95SBruce Richardson return rte_eth_dev_release_port(ethdev); 487399a2dd95SBruce Richardson } 487499a2dd95SBruce Richardson 487599a2dd95SBruce Richardson int 487699a2dd95SBruce Richardson rte_eth_dev_rx_intr_ctl_q(uint16_t port_id, uint16_t queue_id, 487799a2dd95SBruce Richardson int epfd, int op, void *data) 487899a2dd95SBruce Richardson { 487999a2dd95SBruce Richardson uint32_t vec; 488099a2dd95SBruce Richardson struct rte_eth_dev *dev; 488199a2dd95SBruce Richardson struct rte_intr_handle *intr_handle; 488299a2dd95SBruce Richardson int rc; 488399a2dd95SBruce Richardson 488499a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 488599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 488653ef1b34SMin Hu (Connor) 488799a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 488899a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 488999a2dd95SBruce Richardson return -EINVAL; 489099a2dd95SBruce Richardson } 489199a2dd95SBruce Richardson 489299a2dd95SBruce Richardson if (!dev->intr_handle) { 489399a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr handle unset\n"); 489499a2dd95SBruce Richardson return -ENOTSUP; 489599a2dd95SBruce Richardson } 489699a2dd95SBruce Richardson 489799a2dd95SBruce Richardson intr_handle = dev->intr_handle; 489899a2dd95SBruce Richardson if (!intr_handle->intr_vec) { 489999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "RX Intr vector unset\n"); 490099a2dd95SBruce Richardson return -EPERM; 490199a2dd95SBruce Richardson } 490299a2dd95SBruce Richardson 490399a2dd95SBruce Richardson vec = intr_handle->intr_vec[queue_id]; 490499a2dd95SBruce Richardson rc = rte_intr_rx_ctl(intr_handle, epfd, op, vec, data); 490599a2dd95SBruce Richardson if (rc && rc != -EEXIST) { 490699a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 490799a2dd95SBruce Richardson "p %u q %u rx ctl error op %d epfd %d vec %u\n", 490899a2dd95SBruce Richardson port_id, queue_id, op, epfd, vec); 490999a2dd95SBruce Richardson return rc; 491099a2dd95SBruce Richardson } 491199a2dd95SBruce Richardson 491299a2dd95SBruce Richardson return 0; 491399a2dd95SBruce Richardson } 491499a2dd95SBruce Richardson 491599a2dd95SBruce Richardson int 491699a2dd95SBruce Richardson rte_eth_dev_rx_intr_enable(uint16_t port_id, 491799a2dd95SBruce Richardson uint16_t queue_id) 491899a2dd95SBruce Richardson { 491999a2dd95SBruce Richardson struct rte_eth_dev *dev; 492099a2dd95SBruce Richardson int ret; 492199a2dd95SBruce Richardson 492299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 492399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 492499a2dd95SBruce Richardson 492599a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, queue_id); 492699a2dd95SBruce Richardson if (ret != 0) 492799a2dd95SBruce Richardson return ret; 492899a2dd95SBruce Richardson 492999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_enable, -ENOTSUP); 493053ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_enable)(dev, queue_id)); 493199a2dd95SBruce Richardson } 493299a2dd95SBruce Richardson 493399a2dd95SBruce Richardson int 493499a2dd95SBruce Richardson rte_eth_dev_rx_intr_disable(uint16_t port_id, 493599a2dd95SBruce Richardson uint16_t queue_id) 493699a2dd95SBruce Richardson { 493799a2dd95SBruce Richardson struct rte_eth_dev *dev; 493899a2dd95SBruce Richardson int ret; 493999a2dd95SBruce Richardson 494099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 494199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 494299a2dd95SBruce Richardson 494399a2dd95SBruce Richardson ret = eth_dev_validate_rx_queue(dev, queue_id); 494499a2dd95SBruce Richardson if (ret != 0) 494599a2dd95SBruce Richardson return ret; 494699a2dd95SBruce Richardson 494799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_queue_intr_disable, -ENOTSUP); 494853ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->rx_queue_intr_disable)(dev, queue_id)); 494999a2dd95SBruce Richardson } 495099a2dd95SBruce Richardson 495199a2dd95SBruce Richardson 495299a2dd95SBruce Richardson const struct rte_eth_rxtx_callback * 495399a2dd95SBruce Richardson rte_eth_add_rx_callback(uint16_t port_id, uint16_t queue_id, 495499a2dd95SBruce Richardson rte_rx_callback_fn fn, void *user_param) 495599a2dd95SBruce Richardson { 495699a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 495799a2dd95SBruce Richardson rte_errno = ENOTSUP; 495899a2dd95SBruce Richardson return NULL; 495999a2dd95SBruce Richardson #endif 496099a2dd95SBruce Richardson struct rte_eth_dev *dev; 496199a2dd95SBruce Richardson 496299a2dd95SBruce Richardson /* check input parameters */ 496399a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || 496499a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) { 496599a2dd95SBruce Richardson rte_errno = EINVAL; 496699a2dd95SBruce Richardson return NULL; 496799a2dd95SBruce Richardson } 496899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 496999a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) { 497099a2dd95SBruce Richardson rte_errno = EINVAL; 497199a2dd95SBruce Richardson return NULL; 497299a2dd95SBruce Richardson } 497399a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); 497499a2dd95SBruce Richardson 497599a2dd95SBruce Richardson if (cb == NULL) { 497699a2dd95SBruce Richardson rte_errno = ENOMEM; 497799a2dd95SBruce Richardson return NULL; 497899a2dd95SBruce Richardson } 497999a2dd95SBruce Richardson 498099a2dd95SBruce Richardson cb->fn.rx = fn; 498199a2dd95SBruce Richardson cb->param = user_param; 498299a2dd95SBruce Richardson 498399a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_rx_cb_lock); 498499a2dd95SBruce Richardson /* Add the callbacks in fifo order. */ 498599a2dd95SBruce Richardson struct rte_eth_rxtx_callback *tail = 498699a2dd95SBruce Richardson rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; 498799a2dd95SBruce Richardson 498899a2dd95SBruce Richardson if (!tail) { 498999a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 499099a2dd95SBruce Richardson * cb is visible to data plane. 499199a2dd95SBruce Richardson */ 499299a2dd95SBruce Richardson __atomic_store_n( 499399a2dd95SBruce Richardson &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], 499499a2dd95SBruce Richardson cb, __ATOMIC_RELEASE); 499599a2dd95SBruce Richardson 499699a2dd95SBruce Richardson } else { 499799a2dd95SBruce Richardson while (tail->next) 499899a2dd95SBruce Richardson tail = tail->next; 499999a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 500099a2dd95SBruce Richardson * cb is visible to data plane. 500199a2dd95SBruce Richardson */ 500299a2dd95SBruce Richardson __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE); 500399a2dd95SBruce Richardson } 500499a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_rx_cb_lock); 500599a2dd95SBruce Richardson 500699a2dd95SBruce Richardson return cb; 500799a2dd95SBruce Richardson } 500899a2dd95SBruce Richardson 500999a2dd95SBruce Richardson const struct rte_eth_rxtx_callback * 501099a2dd95SBruce Richardson rte_eth_add_first_rx_callback(uint16_t port_id, uint16_t queue_id, 501199a2dd95SBruce Richardson rte_rx_callback_fn fn, void *user_param) 501299a2dd95SBruce Richardson { 501399a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 501499a2dd95SBruce Richardson rte_errno = ENOTSUP; 501599a2dd95SBruce Richardson return NULL; 501699a2dd95SBruce Richardson #endif 501799a2dd95SBruce Richardson /* check input parameters */ 501899a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || 501999a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) { 502099a2dd95SBruce Richardson rte_errno = EINVAL; 502199a2dd95SBruce Richardson return NULL; 502299a2dd95SBruce Richardson } 502399a2dd95SBruce Richardson 502499a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); 502599a2dd95SBruce Richardson 502699a2dd95SBruce Richardson if (cb == NULL) { 502799a2dd95SBruce Richardson rte_errno = ENOMEM; 502899a2dd95SBruce Richardson return NULL; 502999a2dd95SBruce Richardson } 503099a2dd95SBruce Richardson 503199a2dd95SBruce Richardson cb->fn.rx = fn; 503299a2dd95SBruce Richardson cb->param = user_param; 503399a2dd95SBruce Richardson 503499a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_rx_cb_lock); 503599a2dd95SBruce Richardson /* Add the callbacks at first position */ 503699a2dd95SBruce Richardson cb->next = rte_eth_devices[port_id].post_rx_burst_cbs[queue_id]; 503799a2dd95SBruce Richardson /* Stores to cb->fn, cb->param and cb->next should complete before 503899a2dd95SBruce Richardson * cb is visible to data plane threads. 503999a2dd95SBruce Richardson */ 504099a2dd95SBruce Richardson __atomic_store_n( 504199a2dd95SBruce Richardson &rte_eth_devices[port_id].post_rx_burst_cbs[queue_id], 504299a2dd95SBruce Richardson cb, __ATOMIC_RELEASE); 504399a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_rx_cb_lock); 504499a2dd95SBruce Richardson 504599a2dd95SBruce Richardson return cb; 504699a2dd95SBruce Richardson } 504799a2dd95SBruce Richardson 504899a2dd95SBruce Richardson const struct rte_eth_rxtx_callback * 504999a2dd95SBruce Richardson rte_eth_add_tx_callback(uint16_t port_id, uint16_t queue_id, 505099a2dd95SBruce Richardson rte_tx_callback_fn fn, void *user_param) 505199a2dd95SBruce Richardson { 505299a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 505399a2dd95SBruce Richardson rte_errno = ENOTSUP; 505499a2dd95SBruce Richardson return NULL; 505599a2dd95SBruce Richardson #endif 505699a2dd95SBruce Richardson struct rte_eth_dev *dev; 505799a2dd95SBruce Richardson 505899a2dd95SBruce Richardson /* check input parameters */ 505999a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id) || fn == NULL || 506099a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) { 506199a2dd95SBruce Richardson rte_errno = EINVAL; 506299a2dd95SBruce Richardson return NULL; 506399a2dd95SBruce Richardson } 506499a2dd95SBruce Richardson 506599a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 506699a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) { 506799a2dd95SBruce Richardson rte_errno = EINVAL; 506899a2dd95SBruce Richardson return NULL; 506999a2dd95SBruce Richardson } 507099a2dd95SBruce Richardson 507199a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb = rte_zmalloc(NULL, sizeof(*cb), 0); 507299a2dd95SBruce Richardson 507399a2dd95SBruce Richardson if (cb == NULL) { 507499a2dd95SBruce Richardson rte_errno = ENOMEM; 507599a2dd95SBruce Richardson return NULL; 507699a2dd95SBruce Richardson } 507799a2dd95SBruce Richardson 507899a2dd95SBruce Richardson cb->fn.tx = fn; 507999a2dd95SBruce Richardson cb->param = user_param; 508099a2dd95SBruce Richardson 508199a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_tx_cb_lock); 508299a2dd95SBruce Richardson /* Add the callbacks in fifo order. */ 508399a2dd95SBruce Richardson struct rte_eth_rxtx_callback *tail = 508499a2dd95SBruce Richardson rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id]; 508599a2dd95SBruce Richardson 508699a2dd95SBruce Richardson if (!tail) { 508799a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 508899a2dd95SBruce Richardson * cb is visible to data plane. 508999a2dd95SBruce Richardson */ 509099a2dd95SBruce Richardson __atomic_store_n( 509199a2dd95SBruce Richardson &rte_eth_devices[port_id].pre_tx_burst_cbs[queue_id], 509299a2dd95SBruce Richardson cb, __ATOMIC_RELEASE); 509399a2dd95SBruce Richardson 509499a2dd95SBruce Richardson } else { 509599a2dd95SBruce Richardson while (tail->next) 509699a2dd95SBruce Richardson tail = tail->next; 509799a2dd95SBruce Richardson /* Stores to cb->fn and cb->param should complete before 509899a2dd95SBruce Richardson * cb is visible to data plane. 509999a2dd95SBruce Richardson */ 510099a2dd95SBruce Richardson __atomic_store_n(&tail->next, cb, __ATOMIC_RELEASE); 510199a2dd95SBruce Richardson } 510299a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_tx_cb_lock); 510399a2dd95SBruce Richardson 510499a2dd95SBruce Richardson return cb; 510599a2dd95SBruce Richardson } 510699a2dd95SBruce Richardson 510799a2dd95SBruce Richardson int 510899a2dd95SBruce Richardson rte_eth_remove_rx_callback(uint16_t port_id, uint16_t queue_id, 510999a2dd95SBruce Richardson const struct rte_eth_rxtx_callback *user_cb) 511099a2dd95SBruce Richardson { 511199a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 511299a2dd95SBruce Richardson return -ENOTSUP; 511399a2dd95SBruce Richardson #endif 511499a2dd95SBruce Richardson /* Check input parameters. */ 511599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 511699a2dd95SBruce Richardson if (user_cb == NULL || 511799a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_rx_queues) 511899a2dd95SBruce Richardson return -EINVAL; 511999a2dd95SBruce Richardson 512099a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 512199a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb; 512299a2dd95SBruce Richardson struct rte_eth_rxtx_callback **prev_cb; 512399a2dd95SBruce Richardson int ret = -EINVAL; 512499a2dd95SBruce Richardson 512599a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_rx_cb_lock); 512699a2dd95SBruce Richardson prev_cb = &dev->post_rx_burst_cbs[queue_id]; 512799a2dd95SBruce Richardson for (; *prev_cb != NULL; prev_cb = &cb->next) { 512899a2dd95SBruce Richardson cb = *prev_cb; 512999a2dd95SBruce Richardson if (cb == user_cb) { 513099a2dd95SBruce Richardson /* Remove the user cb from the callback list. */ 513199a2dd95SBruce Richardson __atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED); 513299a2dd95SBruce Richardson ret = 0; 513399a2dd95SBruce Richardson break; 513499a2dd95SBruce Richardson } 513599a2dd95SBruce Richardson } 513699a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_rx_cb_lock); 513799a2dd95SBruce Richardson 513899a2dd95SBruce Richardson return ret; 513999a2dd95SBruce Richardson } 514099a2dd95SBruce Richardson 514199a2dd95SBruce Richardson int 514299a2dd95SBruce Richardson rte_eth_remove_tx_callback(uint16_t port_id, uint16_t queue_id, 514399a2dd95SBruce Richardson const struct rte_eth_rxtx_callback *user_cb) 514499a2dd95SBruce Richardson { 514599a2dd95SBruce Richardson #ifndef RTE_ETHDEV_RXTX_CALLBACKS 514699a2dd95SBruce Richardson return -ENOTSUP; 514799a2dd95SBruce Richardson #endif 514899a2dd95SBruce Richardson /* Check input parameters. */ 514999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 515099a2dd95SBruce Richardson if (user_cb == NULL || 515199a2dd95SBruce Richardson queue_id >= rte_eth_devices[port_id].data->nb_tx_queues) 515299a2dd95SBruce Richardson return -EINVAL; 515399a2dd95SBruce Richardson 515499a2dd95SBruce Richardson struct rte_eth_dev *dev = &rte_eth_devices[port_id]; 515599a2dd95SBruce Richardson int ret = -EINVAL; 515699a2dd95SBruce Richardson struct rte_eth_rxtx_callback *cb; 515799a2dd95SBruce Richardson struct rte_eth_rxtx_callback **prev_cb; 515899a2dd95SBruce Richardson 515999a2dd95SBruce Richardson rte_spinlock_lock(ð_dev_tx_cb_lock); 516099a2dd95SBruce Richardson prev_cb = &dev->pre_tx_burst_cbs[queue_id]; 516199a2dd95SBruce Richardson for (; *prev_cb != NULL; prev_cb = &cb->next) { 516299a2dd95SBruce Richardson cb = *prev_cb; 516399a2dd95SBruce Richardson if (cb == user_cb) { 516499a2dd95SBruce Richardson /* Remove the user cb from the callback list. */ 516599a2dd95SBruce Richardson __atomic_store_n(prev_cb, cb->next, __ATOMIC_RELAXED); 516699a2dd95SBruce Richardson ret = 0; 516799a2dd95SBruce Richardson break; 516899a2dd95SBruce Richardson } 516999a2dd95SBruce Richardson } 517099a2dd95SBruce Richardson rte_spinlock_unlock(ð_dev_tx_cb_lock); 517199a2dd95SBruce Richardson 517299a2dd95SBruce Richardson return ret; 517399a2dd95SBruce Richardson } 517499a2dd95SBruce Richardson 517599a2dd95SBruce Richardson int 517699a2dd95SBruce Richardson rte_eth_rx_queue_info_get(uint16_t port_id, uint16_t queue_id, 517799a2dd95SBruce Richardson struct rte_eth_rxq_info *qinfo) 517899a2dd95SBruce Richardson { 517999a2dd95SBruce Richardson struct rte_eth_dev *dev; 518099a2dd95SBruce Richardson 518199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 518299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 518353ef1b34SMin Hu (Connor) 518499a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 518599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 518699a2dd95SBruce Richardson return -EINVAL; 518799a2dd95SBruce Richardson } 518899a2dd95SBruce Richardson 518953ef1b34SMin Hu (Connor) if (qinfo == NULL) { 519053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u Rx queue %u info to NULL\n", 519153ef1b34SMin Hu (Connor) port_id, queue_id); 519253ef1b34SMin Hu (Connor) return -EINVAL; 519353ef1b34SMin Hu (Connor) } 519453ef1b34SMin Hu (Connor) 519599a2dd95SBruce Richardson if (dev->data->rx_queues == NULL || 519699a2dd95SBruce Richardson dev->data->rx_queues[queue_id] == NULL) { 519799a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 519899a2dd95SBruce Richardson "Rx queue %"PRIu16" of device with port_id=%" 519999a2dd95SBruce Richardson PRIu16" has not been setup\n", 520099a2dd95SBruce Richardson queue_id, port_id); 520199a2dd95SBruce Richardson return -EINVAL; 520299a2dd95SBruce Richardson } 520399a2dd95SBruce Richardson 520499a2dd95SBruce Richardson if (rte_eth_dev_is_rx_hairpin_queue(dev, queue_id)) { 520599a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 520699a2dd95SBruce Richardson "Can't get hairpin Rx queue %"PRIu16" info of device with port_id=%"PRIu16"\n", 520799a2dd95SBruce Richardson queue_id, port_id); 520899a2dd95SBruce Richardson return -EINVAL; 520999a2dd95SBruce Richardson } 521099a2dd95SBruce Richardson 521199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rxq_info_get, -ENOTSUP); 521299a2dd95SBruce Richardson 521399a2dd95SBruce Richardson memset(qinfo, 0, sizeof(*qinfo)); 521499a2dd95SBruce Richardson dev->dev_ops->rxq_info_get(dev, queue_id, qinfo); 52159ad9ff47SLijun Ou qinfo->queue_state = dev->data->rx_queue_state[queue_id]; 52169ad9ff47SLijun Ou 521799a2dd95SBruce Richardson return 0; 521899a2dd95SBruce Richardson } 521999a2dd95SBruce Richardson 522099a2dd95SBruce Richardson int 522199a2dd95SBruce Richardson rte_eth_tx_queue_info_get(uint16_t port_id, uint16_t queue_id, 522299a2dd95SBruce Richardson struct rte_eth_txq_info *qinfo) 522399a2dd95SBruce Richardson { 522499a2dd95SBruce Richardson struct rte_eth_dev *dev; 522599a2dd95SBruce Richardson 522699a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 522799a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 522853ef1b34SMin Hu (Connor) 522999a2dd95SBruce Richardson if (queue_id >= dev->data->nb_tx_queues) { 523099a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id); 523199a2dd95SBruce Richardson return -EINVAL; 523299a2dd95SBruce Richardson } 523399a2dd95SBruce Richardson 523453ef1b34SMin Hu (Connor) if (qinfo == NULL) { 523553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot get ethdev port %u Tx queue %u info to NULL\n", 523653ef1b34SMin Hu (Connor) port_id, queue_id); 523753ef1b34SMin Hu (Connor) return -EINVAL; 523853ef1b34SMin Hu (Connor) } 523953ef1b34SMin Hu (Connor) 524099a2dd95SBruce Richardson if (dev->data->tx_queues == NULL || 524199a2dd95SBruce Richardson dev->data->tx_queues[queue_id] == NULL) { 524299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, 524399a2dd95SBruce Richardson "Tx queue %"PRIu16" of device with port_id=%" 524499a2dd95SBruce Richardson PRIu16" has not been setup\n", 524599a2dd95SBruce Richardson queue_id, port_id); 524699a2dd95SBruce Richardson return -EINVAL; 524799a2dd95SBruce Richardson } 524899a2dd95SBruce Richardson 524999a2dd95SBruce Richardson if (rte_eth_dev_is_tx_hairpin_queue(dev, queue_id)) { 525099a2dd95SBruce Richardson RTE_ETHDEV_LOG(INFO, 525199a2dd95SBruce Richardson "Can't get hairpin Tx queue %"PRIu16" info of device with port_id=%"PRIu16"\n", 525299a2dd95SBruce Richardson queue_id, port_id); 525399a2dd95SBruce Richardson return -EINVAL; 525499a2dd95SBruce Richardson } 525599a2dd95SBruce Richardson 525699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->txq_info_get, -ENOTSUP); 525799a2dd95SBruce Richardson 525899a2dd95SBruce Richardson memset(qinfo, 0, sizeof(*qinfo)); 525999a2dd95SBruce Richardson dev->dev_ops->txq_info_get(dev, queue_id, qinfo); 52609ad9ff47SLijun Ou qinfo->queue_state = dev->data->tx_queue_state[queue_id]; 526199a2dd95SBruce Richardson 526299a2dd95SBruce Richardson return 0; 526399a2dd95SBruce Richardson } 526499a2dd95SBruce Richardson 526599a2dd95SBruce Richardson int 526699a2dd95SBruce Richardson rte_eth_rx_burst_mode_get(uint16_t port_id, uint16_t queue_id, 526799a2dd95SBruce Richardson struct rte_eth_burst_mode *mode) 526899a2dd95SBruce Richardson { 526999a2dd95SBruce Richardson struct rte_eth_dev *dev; 527099a2dd95SBruce Richardson 527199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 527299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 527399a2dd95SBruce Richardson 527499a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 527599a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid RX queue_id=%u\n", queue_id); 527699a2dd95SBruce Richardson return -EINVAL; 527799a2dd95SBruce Richardson } 527899a2dd95SBruce Richardson 527953ef1b34SMin Hu (Connor) if (mode == NULL) { 528053ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 528153ef1b34SMin Hu (Connor) "Cannot get ethdev port %u Rx queue %u burst mode to NULL\n", 528253ef1b34SMin Hu (Connor) port_id, queue_id); 528353ef1b34SMin Hu (Connor) return -EINVAL; 528453ef1b34SMin Hu (Connor) } 528553ef1b34SMin Hu (Connor) 528699a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_burst_mode_get, -ENOTSUP); 528799a2dd95SBruce Richardson memset(mode, 0, sizeof(*mode)); 528899a2dd95SBruce Richardson return eth_err(port_id, 528999a2dd95SBruce Richardson dev->dev_ops->rx_burst_mode_get(dev, queue_id, mode)); 529099a2dd95SBruce Richardson } 529199a2dd95SBruce Richardson 529299a2dd95SBruce Richardson int 529399a2dd95SBruce Richardson rte_eth_tx_burst_mode_get(uint16_t port_id, uint16_t queue_id, 529499a2dd95SBruce Richardson struct rte_eth_burst_mode *mode) 529599a2dd95SBruce Richardson { 529699a2dd95SBruce Richardson struct rte_eth_dev *dev; 529799a2dd95SBruce Richardson 529899a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 529999a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 530099a2dd95SBruce Richardson 530199a2dd95SBruce Richardson if (queue_id >= dev->data->nb_tx_queues) { 530299a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid TX queue_id=%u\n", queue_id); 530399a2dd95SBruce Richardson return -EINVAL; 530499a2dd95SBruce Richardson } 530599a2dd95SBruce Richardson 530653ef1b34SMin Hu (Connor) if (mode == NULL) { 530753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 530853ef1b34SMin Hu (Connor) "Cannot get ethdev port %u Tx queue %u burst mode to NULL\n", 530953ef1b34SMin Hu (Connor) port_id, queue_id); 531053ef1b34SMin Hu (Connor) return -EINVAL; 531153ef1b34SMin Hu (Connor) } 531253ef1b34SMin Hu (Connor) 531399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->tx_burst_mode_get, -ENOTSUP); 531499a2dd95SBruce Richardson memset(mode, 0, sizeof(*mode)); 531599a2dd95SBruce Richardson return eth_err(port_id, 531699a2dd95SBruce Richardson dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode)); 531799a2dd95SBruce Richardson } 531899a2dd95SBruce Richardson 531999a2dd95SBruce Richardson int 532099a2dd95SBruce Richardson rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id, 532199a2dd95SBruce Richardson struct rte_power_monitor_cond *pmc) 532299a2dd95SBruce Richardson { 532399a2dd95SBruce Richardson struct rte_eth_dev *dev; 532499a2dd95SBruce Richardson 532599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 532699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 532799a2dd95SBruce Richardson 532899a2dd95SBruce Richardson if (queue_id >= dev->data->nb_rx_queues) { 532999a2dd95SBruce Richardson RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id); 533099a2dd95SBruce Richardson return -EINVAL; 533199a2dd95SBruce Richardson } 533299a2dd95SBruce Richardson 533399a2dd95SBruce Richardson if (pmc == NULL) { 533453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 533553ef1b34SMin Hu (Connor) "Cannot get ethdev port %u Rx queue %u power monitor condition to NULL\n", 533653ef1b34SMin Hu (Connor) port_id, queue_id); 533799a2dd95SBruce Richardson return -EINVAL; 533899a2dd95SBruce Richardson } 533999a2dd95SBruce Richardson 534053ef1b34SMin Hu (Connor) RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_monitor_addr, -ENOTSUP); 534199a2dd95SBruce Richardson return eth_err(port_id, 534253ef1b34SMin Hu (Connor) dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id], pmc)); 534399a2dd95SBruce Richardson } 534499a2dd95SBruce Richardson 534599a2dd95SBruce Richardson int 534699a2dd95SBruce Richardson rte_eth_dev_set_mc_addr_list(uint16_t port_id, 534799a2dd95SBruce Richardson struct rte_ether_addr *mc_addr_set, 534899a2dd95SBruce Richardson uint32_t nb_mc_addr) 534999a2dd95SBruce Richardson { 535099a2dd95SBruce Richardson struct rte_eth_dev *dev; 535199a2dd95SBruce Richardson 535299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 535399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 535453ef1b34SMin Hu (Connor) 535599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_mc_addr_list, -ENOTSUP); 535699a2dd95SBruce Richardson return eth_err(port_id, dev->dev_ops->set_mc_addr_list(dev, 535799a2dd95SBruce Richardson mc_addr_set, nb_mc_addr)); 535899a2dd95SBruce Richardson } 535999a2dd95SBruce Richardson 536099a2dd95SBruce Richardson int 536199a2dd95SBruce Richardson rte_eth_timesync_enable(uint16_t port_id) 536299a2dd95SBruce Richardson { 536399a2dd95SBruce Richardson struct rte_eth_dev *dev; 536499a2dd95SBruce Richardson 536599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 536699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 536799a2dd95SBruce Richardson 536899a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_enable, -ENOTSUP); 536999a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_enable)(dev)); 537099a2dd95SBruce Richardson } 537199a2dd95SBruce Richardson 537299a2dd95SBruce Richardson int 537399a2dd95SBruce Richardson rte_eth_timesync_disable(uint16_t port_id) 537499a2dd95SBruce Richardson { 537599a2dd95SBruce Richardson struct rte_eth_dev *dev; 537699a2dd95SBruce Richardson 537799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 537899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 537999a2dd95SBruce Richardson 538099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_disable, -ENOTSUP); 538199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_disable)(dev)); 538299a2dd95SBruce Richardson } 538399a2dd95SBruce Richardson 538499a2dd95SBruce Richardson int 538599a2dd95SBruce Richardson rte_eth_timesync_read_rx_timestamp(uint16_t port_id, struct timespec *timestamp, 538699a2dd95SBruce Richardson uint32_t flags) 538799a2dd95SBruce Richardson { 538899a2dd95SBruce Richardson struct rte_eth_dev *dev; 538999a2dd95SBruce Richardson 539099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 539199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 539299a2dd95SBruce Richardson 539353ef1b34SMin Hu (Connor) if (timestamp == NULL) { 539453ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 539553ef1b34SMin Hu (Connor) "Cannot read ethdev port %u Rx timestamp to NULL\n", 539653ef1b34SMin Hu (Connor) port_id); 539753ef1b34SMin Hu (Connor) return -EINVAL; 539853ef1b34SMin Hu (Connor) } 539953ef1b34SMin Hu (Connor) 540099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_rx_timestamp, -ENOTSUP); 540199a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_read_rx_timestamp) 540299a2dd95SBruce Richardson (dev, timestamp, flags)); 540399a2dd95SBruce Richardson } 540499a2dd95SBruce Richardson 540599a2dd95SBruce Richardson int 540699a2dd95SBruce Richardson rte_eth_timesync_read_tx_timestamp(uint16_t port_id, 540799a2dd95SBruce Richardson struct timespec *timestamp) 540899a2dd95SBruce Richardson { 540999a2dd95SBruce Richardson struct rte_eth_dev *dev; 541099a2dd95SBruce Richardson 541199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 541299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 541399a2dd95SBruce Richardson 541453ef1b34SMin Hu (Connor) if (timestamp == NULL) { 541553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 541653ef1b34SMin Hu (Connor) "Cannot read ethdev port %u Tx timestamp to NULL\n", 541753ef1b34SMin Hu (Connor) port_id); 541853ef1b34SMin Hu (Connor) return -EINVAL; 541953ef1b34SMin Hu (Connor) } 542053ef1b34SMin Hu (Connor) 542199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_tx_timestamp, -ENOTSUP); 542299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_read_tx_timestamp) 542399a2dd95SBruce Richardson (dev, timestamp)); 542499a2dd95SBruce Richardson } 542599a2dd95SBruce Richardson 542699a2dd95SBruce Richardson int 542799a2dd95SBruce Richardson rte_eth_timesync_adjust_time(uint16_t port_id, int64_t delta) 542899a2dd95SBruce Richardson { 542999a2dd95SBruce Richardson struct rte_eth_dev *dev; 543099a2dd95SBruce Richardson 543199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 543299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 543399a2dd95SBruce Richardson 543499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_adjust_time, -ENOTSUP); 543553ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->timesync_adjust_time)(dev, delta)); 543699a2dd95SBruce Richardson } 543799a2dd95SBruce Richardson 543899a2dd95SBruce Richardson int 543999a2dd95SBruce Richardson rte_eth_timesync_read_time(uint16_t port_id, struct timespec *timestamp) 544099a2dd95SBruce Richardson { 544199a2dd95SBruce Richardson struct rte_eth_dev *dev; 544299a2dd95SBruce Richardson 544399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 544499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 544599a2dd95SBruce Richardson 544653ef1b34SMin Hu (Connor) if (timestamp == NULL) { 544753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 544853ef1b34SMin Hu (Connor) "Cannot read ethdev port %u timesync time to NULL\n", 544953ef1b34SMin Hu (Connor) port_id); 545053ef1b34SMin Hu (Connor) return -EINVAL; 545153ef1b34SMin Hu (Connor) } 545253ef1b34SMin Hu (Connor) 545399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_read_time, -ENOTSUP); 545499a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_read_time)(dev, 545599a2dd95SBruce Richardson timestamp)); 545699a2dd95SBruce Richardson } 545799a2dd95SBruce Richardson 545899a2dd95SBruce Richardson int 545999a2dd95SBruce Richardson rte_eth_timesync_write_time(uint16_t port_id, const struct timespec *timestamp) 546099a2dd95SBruce Richardson { 546199a2dd95SBruce Richardson struct rte_eth_dev *dev; 546299a2dd95SBruce Richardson 546399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 546499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 546599a2dd95SBruce Richardson 546653ef1b34SMin Hu (Connor) if (timestamp == NULL) { 546753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 546853ef1b34SMin Hu (Connor) "Cannot write ethdev port %u timesync from NULL time\n", 546953ef1b34SMin Hu (Connor) port_id); 547053ef1b34SMin Hu (Connor) return -EINVAL; 547153ef1b34SMin Hu (Connor) } 547253ef1b34SMin Hu (Connor) 547399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->timesync_write_time, -ENOTSUP); 547499a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->timesync_write_time)(dev, 547599a2dd95SBruce Richardson timestamp)); 547699a2dd95SBruce Richardson } 547799a2dd95SBruce Richardson 547899a2dd95SBruce Richardson int 547999a2dd95SBruce Richardson rte_eth_read_clock(uint16_t port_id, uint64_t *clock) 548099a2dd95SBruce Richardson { 548199a2dd95SBruce Richardson struct rte_eth_dev *dev; 548299a2dd95SBruce Richardson 548399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 548499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 548599a2dd95SBruce Richardson 548653ef1b34SMin Hu (Connor) if (clock == NULL) { 548753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, "Cannot read ethdev port %u clock to NULL\n", 548853ef1b34SMin Hu (Connor) port_id); 548953ef1b34SMin Hu (Connor) return -EINVAL; 549053ef1b34SMin Hu (Connor) } 549153ef1b34SMin Hu (Connor) 549299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->read_clock, -ENOTSUP); 549399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->read_clock)(dev, clock)); 549499a2dd95SBruce Richardson } 549599a2dd95SBruce Richardson 549699a2dd95SBruce Richardson int 549799a2dd95SBruce Richardson rte_eth_dev_get_reg_info(uint16_t port_id, struct rte_dev_reg_info *info) 549899a2dd95SBruce Richardson { 549999a2dd95SBruce Richardson struct rte_eth_dev *dev; 550099a2dd95SBruce Richardson 550199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 550299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 550353ef1b34SMin Hu (Connor) 550453ef1b34SMin Hu (Connor) if (info == NULL) { 550553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 550653ef1b34SMin Hu (Connor) "Cannot get ethdev port %u register info to NULL\n", 550753ef1b34SMin Hu (Connor) port_id); 550853ef1b34SMin Hu (Connor) return -EINVAL; 550953ef1b34SMin Hu (Connor) } 551053ef1b34SMin Hu (Connor) 551199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP); 551299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_reg)(dev, info)); 551399a2dd95SBruce Richardson } 551499a2dd95SBruce Richardson 551599a2dd95SBruce Richardson int 551699a2dd95SBruce Richardson rte_eth_dev_get_eeprom_length(uint16_t port_id) 551799a2dd95SBruce Richardson { 551899a2dd95SBruce Richardson struct rte_eth_dev *dev; 551999a2dd95SBruce Richardson 552099a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 552199a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 552253ef1b34SMin Hu (Connor) 552399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom_length, -ENOTSUP); 552499a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_eeprom_length)(dev)); 552599a2dd95SBruce Richardson } 552699a2dd95SBruce Richardson 552799a2dd95SBruce Richardson int 552899a2dd95SBruce Richardson rte_eth_dev_get_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info) 552999a2dd95SBruce Richardson { 553099a2dd95SBruce Richardson struct rte_eth_dev *dev; 553199a2dd95SBruce Richardson 553299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 553399a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 553453ef1b34SMin Hu (Connor) 553553ef1b34SMin Hu (Connor) if (info == NULL) { 553653ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 553753ef1b34SMin Hu (Connor) "Cannot get ethdev port %u EEPROM info to NULL\n", 553853ef1b34SMin Hu (Connor) port_id); 553953ef1b34SMin Hu (Connor) return -EINVAL; 554053ef1b34SMin Hu (Connor) } 554153ef1b34SMin Hu (Connor) 554299a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP); 554399a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_eeprom)(dev, info)); 554499a2dd95SBruce Richardson } 554599a2dd95SBruce Richardson 554699a2dd95SBruce Richardson int 554799a2dd95SBruce Richardson rte_eth_dev_set_eeprom(uint16_t port_id, struct rte_dev_eeprom_info *info) 554899a2dd95SBruce Richardson { 554999a2dd95SBruce Richardson struct rte_eth_dev *dev; 555099a2dd95SBruce Richardson 555199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 555299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 555353ef1b34SMin Hu (Connor) 555453ef1b34SMin Hu (Connor) if (info == NULL) { 555553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 555653ef1b34SMin Hu (Connor) "Cannot set ethdev port %u EEPROM from NULL info\n", 555753ef1b34SMin Hu (Connor) port_id); 555853ef1b34SMin Hu (Connor) return -EINVAL; 555953ef1b34SMin Hu (Connor) } 556053ef1b34SMin Hu (Connor) 556199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP); 556299a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->set_eeprom)(dev, info)); 556399a2dd95SBruce Richardson } 556499a2dd95SBruce Richardson 556599a2dd95SBruce Richardson int 556699a2dd95SBruce Richardson rte_eth_dev_get_module_info(uint16_t port_id, 556799a2dd95SBruce Richardson struct rte_eth_dev_module_info *modinfo) 556899a2dd95SBruce Richardson { 556999a2dd95SBruce Richardson struct rte_eth_dev *dev; 557099a2dd95SBruce Richardson 557199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 557299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 557353ef1b34SMin Hu (Connor) 557453ef1b34SMin Hu (Connor) if (modinfo == NULL) { 557553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 557653ef1b34SMin Hu (Connor) "Cannot get ethdev port %u EEPROM module info to NULL\n", 557753ef1b34SMin Hu (Connor) port_id); 557853ef1b34SMin Hu (Connor) return -EINVAL; 557953ef1b34SMin Hu (Connor) } 558053ef1b34SMin Hu (Connor) 558199a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP); 558299a2dd95SBruce Richardson return (*dev->dev_ops->get_module_info)(dev, modinfo); 558399a2dd95SBruce Richardson } 558499a2dd95SBruce Richardson 558599a2dd95SBruce Richardson int 558699a2dd95SBruce Richardson rte_eth_dev_get_module_eeprom(uint16_t port_id, 558799a2dd95SBruce Richardson struct rte_dev_eeprom_info *info) 558899a2dd95SBruce Richardson { 558999a2dd95SBruce Richardson struct rte_eth_dev *dev; 559099a2dd95SBruce Richardson 559199a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 559299a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 559353ef1b34SMin Hu (Connor) 559453ef1b34SMin Hu (Connor) if (info == NULL) { 559553ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 559653ef1b34SMin Hu (Connor) "Cannot get ethdev port %u module EEPROM info to NULL\n", 559753ef1b34SMin Hu (Connor) port_id); 559853ef1b34SMin Hu (Connor) return -EINVAL; 559953ef1b34SMin Hu (Connor) } 560053ef1b34SMin Hu (Connor) 560153ef1b34SMin Hu (Connor) if (info->data == NULL) { 560253ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 560353ef1b34SMin Hu (Connor) "Cannot get ethdev port %u module EEPROM data to NULL\n", 560453ef1b34SMin Hu (Connor) port_id); 560553ef1b34SMin Hu (Connor) return -EINVAL; 560653ef1b34SMin Hu (Connor) } 560753ef1b34SMin Hu (Connor) 560853ef1b34SMin Hu (Connor) if (info->length == 0) { 560953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 561053ef1b34SMin Hu (Connor) "Cannot get ethdev port %u module EEPROM to data with zero size\n", 561153ef1b34SMin Hu (Connor) port_id); 561253ef1b34SMin Hu (Connor) return -EINVAL; 561353ef1b34SMin Hu (Connor) } 561453ef1b34SMin Hu (Connor) 561599a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP); 561699a2dd95SBruce Richardson return (*dev->dev_ops->get_module_eeprom)(dev, info); 561799a2dd95SBruce Richardson } 561899a2dd95SBruce Richardson 561999a2dd95SBruce Richardson int 562099a2dd95SBruce Richardson rte_eth_dev_get_dcb_info(uint16_t port_id, 562199a2dd95SBruce Richardson struct rte_eth_dcb_info *dcb_info) 562299a2dd95SBruce Richardson { 562399a2dd95SBruce Richardson struct rte_eth_dev *dev; 562499a2dd95SBruce Richardson 562599a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 562699a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 562753ef1b34SMin Hu (Connor) 562853ef1b34SMin Hu (Connor) if (dcb_info == NULL) { 562953ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 563053ef1b34SMin Hu (Connor) "Cannot get ethdev port %u DCB info to NULL\n", 563153ef1b34SMin Hu (Connor) port_id); 563253ef1b34SMin Hu (Connor) return -EINVAL; 563353ef1b34SMin Hu (Connor) } 563453ef1b34SMin Hu (Connor) 563599a2dd95SBruce Richardson memset(dcb_info, 0, sizeof(struct rte_eth_dcb_info)); 563699a2dd95SBruce Richardson 563799a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_dcb_info, -ENOTSUP); 563899a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info)); 563999a2dd95SBruce Richardson } 564099a2dd95SBruce Richardson 564199a2dd95SBruce Richardson static void 564299a2dd95SBruce Richardson eth_dev_adjust_nb_desc(uint16_t *nb_desc, 564399a2dd95SBruce Richardson const struct rte_eth_desc_lim *desc_lim) 564499a2dd95SBruce Richardson { 564599a2dd95SBruce Richardson if (desc_lim->nb_align != 0) 564699a2dd95SBruce Richardson *nb_desc = RTE_ALIGN_CEIL(*nb_desc, desc_lim->nb_align); 564799a2dd95SBruce Richardson 564899a2dd95SBruce Richardson if (desc_lim->nb_max != 0) 564999a2dd95SBruce Richardson *nb_desc = RTE_MIN(*nb_desc, desc_lim->nb_max); 565099a2dd95SBruce Richardson 565199a2dd95SBruce Richardson *nb_desc = RTE_MAX(*nb_desc, desc_lim->nb_min); 565299a2dd95SBruce Richardson } 565399a2dd95SBruce Richardson 565499a2dd95SBruce Richardson int 565599a2dd95SBruce Richardson rte_eth_dev_adjust_nb_rx_tx_desc(uint16_t port_id, 565699a2dd95SBruce Richardson uint16_t *nb_rx_desc, 565799a2dd95SBruce Richardson uint16_t *nb_tx_desc) 565899a2dd95SBruce Richardson { 565999a2dd95SBruce Richardson struct rte_eth_dev_info dev_info; 566099a2dd95SBruce Richardson int ret; 566199a2dd95SBruce Richardson 566299a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 566399a2dd95SBruce Richardson 566499a2dd95SBruce Richardson ret = rte_eth_dev_info_get(port_id, &dev_info); 566599a2dd95SBruce Richardson if (ret != 0) 566699a2dd95SBruce Richardson return ret; 566799a2dd95SBruce Richardson 566899a2dd95SBruce Richardson if (nb_rx_desc != NULL) 566999a2dd95SBruce Richardson eth_dev_adjust_nb_desc(nb_rx_desc, &dev_info.rx_desc_lim); 567099a2dd95SBruce Richardson 567199a2dd95SBruce Richardson if (nb_tx_desc != NULL) 567299a2dd95SBruce Richardson eth_dev_adjust_nb_desc(nb_tx_desc, &dev_info.tx_desc_lim); 567399a2dd95SBruce Richardson 567499a2dd95SBruce Richardson return 0; 567599a2dd95SBruce Richardson } 567699a2dd95SBruce Richardson 567799a2dd95SBruce Richardson int 567899a2dd95SBruce Richardson rte_eth_dev_hairpin_capability_get(uint16_t port_id, 567999a2dd95SBruce Richardson struct rte_eth_hairpin_cap *cap) 568099a2dd95SBruce Richardson { 568199a2dd95SBruce Richardson struct rte_eth_dev *dev; 568299a2dd95SBruce Richardson 568399a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 568499a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 568553ef1b34SMin Hu (Connor) 568653ef1b34SMin Hu (Connor) if (cap == NULL) { 568753ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 568853ef1b34SMin Hu (Connor) "Cannot get ethdev port %u hairpin capability to NULL\n", 568953ef1b34SMin Hu (Connor) port_id); 569053ef1b34SMin Hu (Connor) return -EINVAL; 569153ef1b34SMin Hu (Connor) } 569253ef1b34SMin Hu (Connor) 569399a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_cap_get, -ENOTSUP); 569499a2dd95SBruce Richardson memset(cap, 0, sizeof(*cap)); 569599a2dd95SBruce Richardson return eth_err(port_id, (*dev->dev_ops->hairpin_cap_get)(dev, cap)); 569699a2dd95SBruce Richardson } 569799a2dd95SBruce Richardson 569899a2dd95SBruce Richardson int 569999a2dd95SBruce Richardson rte_eth_dev_is_rx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id) 570099a2dd95SBruce Richardson { 570153ef1b34SMin Hu (Connor) if (dev->data->rx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN) 570299a2dd95SBruce Richardson return 1; 570399a2dd95SBruce Richardson return 0; 570499a2dd95SBruce Richardson } 570599a2dd95SBruce Richardson 570699a2dd95SBruce Richardson int 570799a2dd95SBruce Richardson rte_eth_dev_is_tx_hairpin_queue(struct rte_eth_dev *dev, uint16_t queue_id) 570899a2dd95SBruce Richardson { 570953ef1b34SMin Hu (Connor) if (dev->data->tx_queue_state[queue_id] == RTE_ETH_QUEUE_STATE_HAIRPIN) 571099a2dd95SBruce Richardson return 1; 571199a2dd95SBruce Richardson return 0; 571299a2dd95SBruce Richardson } 571399a2dd95SBruce Richardson 571499a2dd95SBruce Richardson int 571599a2dd95SBruce Richardson rte_eth_dev_pool_ops_supported(uint16_t port_id, const char *pool) 571699a2dd95SBruce Richardson { 571799a2dd95SBruce Richardson struct rte_eth_dev *dev; 571899a2dd95SBruce Richardson 571999a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 572099a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 572199a2dd95SBruce Richardson 572253ef1b34SMin Hu (Connor) if (pool == NULL) { 572353ef1b34SMin Hu (Connor) RTE_ETHDEV_LOG(ERR, 572453ef1b34SMin Hu (Connor) "Cannot test ethdev port %u mempool operation from NULL pool\n", 572553ef1b34SMin Hu (Connor) port_id); 572653ef1b34SMin Hu (Connor) return -EINVAL; 572753ef1b34SMin Hu (Connor) } 572853ef1b34SMin Hu (Connor) 572999a2dd95SBruce Richardson if (*dev->dev_ops->pool_ops_supported == NULL) 573099a2dd95SBruce Richardson return 1; /* all pools are supported */ 573199a2dd95SBruce Richardson 573299a2dd95SBruce Richardson return (*dev->dev_ops->pool_ops_supported)(dev, pool); 573399a2dd95SBruce Richardson } 573499a2dd95SBruce Richardson 573599a2dd95SBruce Richardson /** 573699a2dd95SBruce Richardson * A set of values to describe the possible states of a switch domain. 573799a2dd95SBruce Richardson */ 573899a2dd95SBruce Richardson enum rte_eth_switch_domain_state { 573999a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_UNUSED = 0, 574099a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_ALLOCATED 574199a2dd95SBruce Richardson }; 574299a2dd95SBruce Richardson 574399a2dd95SBruce Richardson /** 574499a2dd95SBruce Richardson * Array of switch domains available for allocation. Array is sized to 574599a2dd95SBruce Richardson * RTE_MAX_ETHPORTS elements as there cannot be more active switch domains than 574699a2dd95SBruce Richardson * ethdev ports in a single process. 574799a2dd95SBruce Richardson */ 574899a2dd95SBruce Richardson static struct rte_eth_dev_switch { 574999a2dd95SBruce Richardson enum rte_eth_switch_domain_state state; 575099a2dd95SBruce Richardson } eth_dev_switch_domains[RTE_MAX_ETHPORTS]; 575199a2dd95SBruce Richardson 575299a2dd95SBruce Richardson int 575399a2dd95SBruce Richardson rte_eth_switch_domain_alloc(uint16_t *domain_id) 575499a2dd95SBruce Richardson { 575599a2dd95SBruce Richardson uint16_t i; 575699a2dd95SBruce Richardson 575799a2dd95SBruce Richardson *domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID; 575899a2dd95SBruce Richardson 575999a2dd95SBruce Richardson for (i = 0; i < RTE_MAX_ETHPORTS; i++) { 576099a2dd95SBruce Richardson if (eth_dev_switch_domains[i].state == 576199a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_UNUSED) { 576299a2dd95SBruce Richardson eth_dev_switch_domains[i].state = 576399a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_ALLOCATED; 576499a2dd95SBruce Richardson *domain_id = i; 576599a2dd95SBruce Richardson return 0; 576699a2dd95SBruce Richardson } 576799a2dd95SBruce Richardson } 576899a2dd95SBruce Richardson 576999a2dd95SBruce Richardson return -ENOSPC; 577099a2dd95SBruce Richardson } 577199a2dd95SBruce Richardson 577299a2dd95SBruce Richardson int 577399a2dd95SBruce Richardson rte_eth_switch_domain_free(uint16_t domain_id) 577499a2dd95SBruce Richardson { 577599a2dd95SBruce Richardson if (domain_id == RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID || 577699a2dd95SBruce Richardson domain_id >= RTE_MAX_ETHPORTS) 577799a2dd95SBruce Richardson return -EINVAL; 577899a2dd95SBruce Richardson 577999a2dd95SBruce Richardson if (eth_dev_switch_domains[domain_id].state != 578099a2dd95SBruce Richardson RTE_ETH_SWITCH_DOMAIN_ALLOCATED) 578199a2dd95SBruce Richardson return -EINVAL; 578299a2dd95SBruce Richardson 578399a2dd95SBruce Richardson eth_dev_switch_domains[domain_id].state = RTE_ETH_SWITCH_DOMAIN_UNUSED; 578499a2dd95SBruce Richardson 578599a2dd95SBruce Richardson return 0; 578699a2dd95SBruce Richardson } 578799a2dd95SBruce Richardson 578899a2dd95SBruce Richardson static int 578999a2dd95SBruce Richardson eth_dev_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in) 579099a2dd95SBruce Richardson { 579199a2dd95SBruce Richardson int state; 579299a2dd95SBruce Richardson struct rte_kvargs_pair *pair; 579399a2dd95SBruce Richardson char *letter; 579499a2dd95SBruce Richardson 579599a2dd95SBruce Richardson arglist->str = strdup(str_in); 579699a2dd95SBruce Richardson if (arglist->str == NULL) 579799a2dd95SBruce Richardson return -ENOMEM; 579899a2dd95SBruce Richardson 579999a2dd95SBruce Richardson letter = arglist->str; 580099a2dd95SBruce Richardson state = 0; 580199a2dd95SBruce Richardson arglist->count = 0; 580299a2dd95SBruce Richardson pair = &arglist->pairs[0]; 580399a2dd95SBruce Richardson while (1) { 580499a2dd95SBruce Richardson switch (state) { 580599a2dd95SBruce Richardson case 0: /* Initial */ 580699a2dd95SBruce Richardson if (*letter == '=') 580799a2dd95SBruce Richardson return -EINVAL; 580899a2dd95SBruce Richardson else if (*letter == '\0') 580999a2dd95SBruce Richardson return 0; 581099a2dd95SBruce Richardson 581199a2dd95SBruce Richardson state = 1; 581299a2dd95SBruce Richardson pair->key = letter; 581399a2dd95SBruce Richardson /* fall-thru */ 581499a2dd95SBruce Richardson 581599a2dd95SBruce Richardson case 1: /* Parsing key */ 581699a2dd95SBruce Richardson if (*letter == '=') { 581799a2dd95SBruce Richardson *letter = '\0'; 581899a2dd95SBruce Richardson pair->value = letter + 1; 581999a2dd95SBruce Richardson state = 2; 582099a2dd95SBruce Richardson } else if (*letter == ',' || *letter == '\0') 582199a2dd95SBruce Richardson return -EINVAL; 582299a2dd95SBruce Richardson break; 582399a2dd95SBruce Richardson 582499a2dd95SBruce Richardson 582599a2dd95SBruce Richardson case 2: /* Parsing value */ 582699a2dd95SBruce Richardson if (*letter == '[') 582799a2dd95SBruce Richardson state = 3; 582899a2dd95SBruce Richardson else if (*letter == ',') { 582999a2dd95SBruce Richardson *letter = '\0'; 583099a2dd95SBruce Richardson arglist->count++; 583199a2dd95SBruce Richardson pair = &arglist->pairs[arglist->count]; 583299a2dd95SBruce Richardson state = 0; 583399a2dd95SBruce Richardson } else if (*letter == '\0') { 583499a2dd95SBruce Richardson letter--; 583599a2dd95SBruce Richardson arglist->count++; 583699a2dd95SBruce Richardson pair = &arglist->pairs[arglist->count]; 583799a2dd95SBruce Richardson state = 0; 583899a2dd95SBruce Richardson } 583999a2dd95SBruce Richardson break; 584099a2dd95SBruce Richardson 584199a2dd95SBruce Richardson case 3: /* Parsing list */ 584299a2dd95SBruce Richardson if (*letter == ']') 584399a2dd95SBruce Richardson state = 2; 584499a2dd95SBruce Richardson else if (*letter == '\0') 584599a2dd95SBruce Richardson return -EINVAL; 584699a2dd95SBruce Richardson break; 584799a2dd95SBruce Richardson } 584899a2dd95SBruce Richardson letter++; 584999a2dd95SBruce Richardson } 585099a2dd95SBruce Richardson } 585199a2dd95SBruce Richardson 585299a2dd95SBruce Richardson int 585399a2dd95SBruce Richardson rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) 585499a2dd95SBruce Richardson { 585599a2dd95SBruce Richardson struct rte_kvargs args; 585699a2dd95SBruce Richardson struct rte_kvargs_pair *pair; 585799a2dd95SBruce Richardson unsigned int i; 585899a2dd95SBruce Richardson int result = 0; 585999a2dd95SBruce Richardson 586099a2dd95SBruce Richardson memset(eth_da, 0, sizeof(*eth_da)); 586199a2dd95SBruce Richardson 586299a2dd95SBruce Richardson result = eth_dev_devargs_tokenise(&args, dargs); 586399a2dd95SBruce Richardson if (result < 0) 586499a2dd95SBruce Richardson goto parse_cleanup; 586599a2dd95SBruce Richardson 586699a2dd95SBruce Richardson for (i = 0; i < args.count; i++) { 586799a2dd95SBruce Richardson pair = &args.pairs[i]; 586899a2dd95SBruce Richardson if (strcmp("representor", pair->key) == 0) { 586999a2dd95SBruce Richardson if (eth_da->type != RTE_ETH_REPRESENTOR_NONE) { 587099a2dd95SBruce Richardson RTE_LOG(ERR, EAL, "duplicated representor key: %s\n", 587199a2dd95SBruce Richardson dargs); 587299a2dd95SBruce Richardson result = -1; 587399a2dd95SBruce Richardson goto parse_cleanup; 587499a2dd95SBruce Richardson } 587599a2dd95SBruce Richardson result = rte_eth_devargs_parse_representor_ports( 587699a2dd95SBruce Richardson pair->value, eth_da); 587799a2dd95SBruce Richardson if (result < 0) 587899a2dd95SBruce Richardson goto parse_cleanup; 587999a2dd95SBruce Richardson } 588099a2dd95SBruce Richardson } 588199a2dd95SBruce Richardson 588299a2dd95SBruce Richardson parse_cleanup: 588399a2dd95SBruce Richardson if (args.str) 588499a2dd95SBruce Richardson free(args.str); 588599a2dd95SBruce Richardson 588699a2dd95SBruce Richardson return result; 588799a2dd95SBruce Richardson } 588899a2dd95SBruce Richardson 588999a2dd95SBruce Richardson int 5890ff4e52efSViacheslav Galaktionov rte_eth_representor_id_get(uint16_t port_id, 589199a2dd95SBruce Richardson enum rte_eth_representor_type type, 589299a2dd95SBruce Richardson int controller, int pf, int representor_port, 589399a2dd95SBruce Richardson uint16_t *repr_id) 589499a2dd95SBruce Richardson { 589510eaf41dSViacheslav Galaktionov int ret, n, count; 589610eaf41dSViacheslav Galaktionov uint32_t i; 589799a2dd95SBruce Richardson struct rte_eth_representor_info *info = NULL; 589899a2dd95SBruce Richardson size_t size; 589999a2dd95SBruce Richardson 590099a2dd95SBruce Richardson if (type == RTE_ETH_REPRESENTOR_NONE) 590199a2dd95SBruce Richardson return 0; 590299a2dd95SBruce Richardson if (repr_id == NULL) 590399a2dd95SBruce Richardson return -EINVAL; 590499a2dd95SBruce Richardson 590599a2dd95SBruce Richardson /* Get PMD representor range info. */ 5906ff4e52efSViacheslav Galaktionov ret = rte_eth_representor_info_get(port_id, NULL); 590799a2dd95SBruce Richardson if (ret == -ENOTSUP && type == RTE_ETH_REPRESENTOR_VF && 590899a2dd95SBruce Richardson controller == -1 && pf == -1) { 590999a2dd95SBruce Richardson /* Direct mapping for legacy VF representor. */ 591099a2dd95SBruce Richardson *repr_id = representor_port; 591199a2dd95SBruce Richardson return 0; 591299a2dd95SBruce Richardson } else if (ret < 0) { 591399a2dd95SBruce Richardson return ret; 591499a2dd95SBruce Richardson } 591599a2dd95SBruce Richardson n = ret; 591699a2dd95SBruce Richardson size = sizeof(*info) + n * sizeof(info->ranges[0]); 591799a2dd95SBruce Richardson info = calloc(1, size); 591899a2dd95SBruce Richardson if (info == NULL) 591999a2dd95SBruce Richardson return -ENOMEM; 592010eaf41dSViacheslav Galaktionov info->nb_ranges_alloc = n; 5921ff4e52efSViacheslav Galaktionov ret = rte_eth_representor_info_get(port_id, info); 592299a2dd95SBruce Richardson if (ret < 0) 592399a2dd95SBruce Richardson goto out; 592499a2dd95SBruce Richardson 592599a2dd95SBruce Richardson /* Default controller and pf to caller. */ 592699a2dd95SBruce Richardson if (controller == -1) 592799a2dd95SBruce Richardson controller = info->controller; 592899a2dd95SBruce Richardson if (pf == -1) 592999a2dd95SBruce Richardson pf = info->pf; 593099a2dd95SBruce Richardson 593199a2dd95SBruce Richardson /* Locate representor ID. */ 593299a2dd95SBruce Richardson ret = -ENOENT; 593310eaf41dSViacheslav Galaktionov for (i = 0; i < info->nb_ranges; ++i) { 593499a2dd95SBruce Richardson if (info->ranges[i].type != type) 593599a2dd95SBruce Richardson continue; 593699a2dd95SBruce Richardson if (info->ranges[i].controller != controller) 593799a2dd95SBruce Richardson continue; 593899a2dd95SBruce Richardson if (info->ranges[i].id_end < info->ranges[i].id_base) { 593999a2dd95SBruce Richardson RTE_LOG(WARNING, EAL, "Port %hu invalid representor ID Range %u - %u, entry %d\n", 5940ff4e52efSViacheslav Galaktionov port_id, info->ranges[i].id_base, 594199a2dd95SBruce Richardson info->ranges[i].id_end, i); 594299a2dd95SBruce Richardson continue; 594399a2dd95SBruce Richardson 594499a2dd95SBruce Richardson } 594599a2dd95SBruce Richardson count = info->ranges[i].id_end - info->ranges[i].id_base + 1; 594699a2dd95SBruce Richardson switch (info->ranges[i].type) { 594799a2dd95SBruce Richardson case RTE_ETH_REPRESENTOR_PF: 594899a2dd95SBruce Richardson if (pf < info->ranges[i].pf || 594999a2dd95SBruce Richardson pf >= info->ranges[i].pf + count) 595099a2dd95SBruce Richardson continue; 595199a2dd95SBruce Richardson *repr_id = info->ranges[i].id_base + 595299a2dd95SBruce Richardson (pf - info->ranges[i].pf); 595399a2dd95SBruce Richardson ret = 0; 595499a2dd95SBruce Richardson goto out; 595599a2dd95SBruce Richardson case RTE_ETH_REPRESENTOR_VF: 595699a2dd95SBruce Richardson if (info->ranges[i].pf != pf) 595799a2dd95SBruce Richardson continue; 595899a2dd95SBruce Richardson if (representor_port < info->ranges[i].vf || 595999a2dd95SBruce Richardson representor_port >= info->ranges[i].vf + count) 596099a2dd95SBruce Richardson continue; 596199a2dd95SBruce Richardson *repr_id = info->ranges[i].id_base + 596299a2dd95SBruce Richardson (representor_port - info->ranges[i].vf); 596399a2dd95SBruce Richardson ret = 0; 596499a2dd95SBruce Richardson goto out; 596599a2dd95SBruce Richardson case RTE_ETH_REPRESENTOR_SF: 596699a2dd95SBruce Richardson if (info->ranges[i].pf != pf) 596799a2dd95SBruce Richardson continue; 596899a2dd95SBruce Richardson if (representor_port < info->ranges[i].sf || 596999a2dd95SBruce Richardson representor_port >= info->ranges[i].sf + count) 597099a2dd95SBruce Richardson continue; 597199a2dd95SBruce Richardson *repr_id = info->ranges[i].id_base + 597299a2dd95SBruce Richardson (representor_port - info->ranges[i].sf); 597399a2dd95SBruce Richardson ret = 0; 597499a2dd95SBruce Richardson goto out; 597599a2dd95SBruce Richardson default: 597699a2dd95SBruce Richardson break; 597799a2dd95SBruce Richardson } 597899a2dd95SBruce Richardson } 597999a2dd95SBruce Richardson out: 598099a2dd95SBruce Richardson free(info); 598199a2dd95SBruce Richardson return ret; 598299a2dd95SBruce Richardson } 598399a2dd95SBruce Richardson 598499a2dd95SBruce Richardson static int 598599a2dd95SBruce Richardson eth_dev_handle_port_list(const char *cmd __rte_unused, 598699a2dd95SBruce Richardson const char *params __rte_unused, 598799a2dd95SBruce Richardson struct rte_tel_data *d) 598899a2dd95SBruce Richardson { 598999a2dd95SBruce Richardson int port_id; 599099a2dd95SBruce Richardson 599199a2dd95SBruce Richardson rte_tel_data_start_array(d, RTE_TEL_INT_VAL); 599299a2dd95SBruce Richardson RTE_ETH_FOREACH_DEV(port_id) 599399a2dd95SBruce Richardson rte_tel_data_add_array_int(d, port_id); 599499a2dd95SBruce Richardson return 0; 599599a2dd95SBruce Richardson } 599699a2dd95SBruce Richardson 599799a2dd95SBruce Richardson static void 599899a2dd95SBruce Richardson eth_dev_add_port_queue_stats(struct rte_tel_data *d, uint64_t *q_stats, 599999a2dd95SBruce Richardson const char *stat_name) 600099a2dd95SBruce Richardson { 600199a2dd95SBruce Richardson int q; 600299a2dd95SBruce Richardson struct rte_tel_data *q_data = rte_tel_data_alloc(); 600399a2dd95SBruce Richardson rte_tel_data_start_array(q_data, RTE_TEL_U64_VAL); 600499a2dd95SBruce Richardson for (q = 0; q < RTE_ETHDEV_QUEUE_STAT_CNTRS; q++) 600599a2dd95SBruce Richardson rte_tel_data_add_array_u64(q_data, q_stats[q]); 600699a2dd95SBruce Richardson rte_tel_data_add_dict_container(d, stat_name, q_data, 0); 600799a2dd95SBruce Richardson } 600899a2dd95SBruce Richardson 600999a2dd95SBruce Richardson #define ADD_DICT_STAT(stats, s) rte_tel_data_add_dict_u64(d, #s, stats.s) 601099a2dd95SBruce Richardson 601199a2dd95SBruce Richardson static int 601299a2dd95SBruce Richardson eth_dev_handle_port_stats(const char *cmd __rte_unused, 601399a2dd95SBruce Richardson const char *params, 601499a2dd95SBruce Richardson struct rte_tel_data *d) 601599a2dd95SBruce Richardson { 601699a2dd95SBruce Richardson struct rte_eth_stats stats; 601799a2dd95SBruce Richardson int port_id, ret; 601899a2dd95SBruce Richardson 601999a2dd95SBruce Richardson if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 602099a2dd95SBruce Richardson return -1; 602199a2dd95SBruce Richardson 602299a2dd95SBruce Richardson port_id = atoi(params); 602399a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id)) 602499a2dd95SBruce Richardson return -1; 602599a2dd95SBruce Richardson 602699a2dd95SBruce Richardson ret = rte_eth_stats_get(port_id, &stats); 602799a2dd95SBruce Richardson if (ret < 0) 602899a2dd95SBruce Richardson return -1; 602999a2dd95SBruce Richardson 603099a2dd95SBruce Richardson rte_tel_data_start_dict(d); 603199a2dd95SBruce Richardson ADD_DICT_STAT(stats, ipackets); 603299a2dd95SBruce Richardson ADD_DICT_STAT(stats, opackets); 603399a2dd95SBruce Richardson ADD_DICT_STAT(stats, ibytes); 603499a2dd95SBruce Richardson ADD_DICT_STAT(stats, obytes); 603599a2dd95SBruce Richardson ADD_DICT_STAT(stats, imissed); 603699a2dd95SBruce Richardson ADD_DICT_STAT(stats, ierrors); 603799a2dd95SBruce Richardson ADD_DICT_STAT(stats, oerrors); 603899a2dd95SBruce Richardson ADD_DICT_STAT(stats, rx_nombuf); 603999a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_ipackets, "q_ipackets"); 604099a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_opackets, "q_opackets"); 604199a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_ibytes, "q_ibytes"); 604299a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_obytes, "q_obytes"); 604399a2dd95SBruce Richardson eth_dev_add_port_queue_stats(d, stats.q_errors, "q_errors"); 604499a2dd95SBruce Richardson 604599a2dd95SBruce Richardson return 0; 604699a2dd95SBruce Richardson } 604799a2dd95SBruce Richardson 604899a2dd95SBruce Richardson static int 604999a2dd95SBruce Richardson eth_dev_handle_port_xstats(const char *cmd __rte_unused, 605099a2dd95SBruce Richardson const char *params, 605199a2dd95SBruce Richardson struct rte_tel_data *d) 605299a2dd95SBruce Richardson { 605399a2dd95SBruce Richardson struct rte_eth_xstat *eth_xstats; 605499a2dd95SBruce Richardson struct rte_eth_xstat_name *xstat_names; 605599a2dd95SBruce Richardson int port_id, num_xstats; 605699a2dd95SBruce Richardson int i, ret; 605799a2dd95SBruce Richardson char *end_param; 605899a2dd95SBruce Richardson 605999a2dd95SBruce Richardson if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 606099a2dd95SBruce Richardson return -1; 606199a2dd95SBruce Richardson 606299a2dd95SBruce Richardson port_id = strtoul(params, &end_param, 0); 606399a2dd95SBruce Richardson if (*end_param != '\0') 606499a2dd95SBruce Richardson RTE_ETHDEV_LOG(NOTICE, 606599a2dd95SBruce Richardson "Extra parameters passed to ethdev telemetry command, ignoring"); 606699a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id)) 606799a2dd95SBruce Richardson return -1; 606899a2dd95SBruce Richardson 606999a2dd95SBruce Richardson num_xstats = rte_eth_xstats_get(port_id, NULL, 0); 607099a2dd95SBruce Richardson if (num_xstats < 0) 607199a2dd95SBruce Richardson return -1; 607299a2dd95SBruce Richardson 607399a2dd95SBruce Richardson /* use one malloc for both names and stats */ 607499a2dd95SBruce Richardson eth_xstats = malloc((sizeof(struct rte_eth_xstat) + 607599a2dd95SBruce Richardson sizeof(struct rte_eth_xstat_name)) * num_xstats); 607699a2dd95SBruce Richardson if (eth_xstats == NULL) 607799a2dd95SBruce Richardson return -1; 607899a2dd95SBruce Richardson xstat_names = (void *)ð_xstats[num_xstats]; 607999a2dd95SBruce Richardson 608099a2dd95SBruce Richardson ret = rte_eth_xstats_get_names(port_id, xstat_names, num_xstats); 608199a2dd95SBruce Richardson if (ret < 0 || ret > num_xstats) { 608299a2dd95SBruce Richardson free(eth_xstats); 608399a2dd95SBruce Richardson return -1; 608499a2dd95SBruce Richardson } 608599a2dd95SBruce Richardson 608699a2dd95SBruce Richardson ret = rte_eth_xstats_get(port_id, eth_xstats, num_xstats); 608799a2dd95SBruce Richardson if (ret < 0 || ret > num_xstats) { 608899a2dd95SBruce Richardson free(eth_xstats); 608999a2dd95SBruce Richardson return -1; 609099a2dd95SBruce Richardson } 609199a2dd95SBruce Richardson 609299a2dd95SBruce Richardson rte_tel_data_start_dict(d); 609399a2dd95SBruce Richardson for (i = 0; i < num_xstats; i++) 609499a2dd95SBruce Richardson rte_tel_data_add_dict_u64(d, xstat_names[i].name, 609599a2dd95SBruce Richardson eth_xstats[i].value); 609699a2dd95SBruce Richardson return 0; 609799a2dd95SBruce Richardson } 609899a2dd95SBruce Richardson 609999a2dd95SBruce Richardson static int 610099a2dd95SBruce Richardson eth_dev_handle_port_link_status(const char *cmd __rte_unused, 610199a2dd95SBruce Richardson const char *params, 610299a2dd95SBruce Richardson struct rte_tel_data *d) 610399a2dd95SBruce Richardson { 610499a2dd95SBruce Richardson static const char *status_str = "status"; 610599a2dd95SBruce Richardson int ret, port_id; 610699a2dd95SBruce Richardson struct rte_eth_link link; 610799a2dd95SBruce Richardson char *end_param; 610899a2dd95SBruce Richardson 610999a2dd95SBruce Richardson if (params == NULL || strlen(params) == 0 || !isdigit(*params)) 611099a2dd95SBruce Richardson return -1; 611199a2dd95SBruce Richardson 611299a2dd95SBruce Richardson port_id = strtoul(params, &end_param, 0); 611399a2dd95SBruce Richardson if (*end_param != '\0') 611499a2dd95SBruce Richardson RTE_ETHDEV_LOG(NOTICE, 611599a2dd95SBruce Richardson "Extra parameters passed to ethdev telemetry command, ignoring"); 611699a2dd95SBruce Richardson if (!rte_eth_dev_is_valid_port(port_id)) 611799a2dd95SBruce Richardson return -1; 611899a2dd95SBruce Richardson 611999a2dd95SBruce Richardson ret = rte_eth_link_get_nowait(port_id, &link); 612099a2dd95SBruce Richardson if (ret < 0) 612199a2dd95SBruce Richardson return -1; 612299a2dd95SBruce Richardson 612399a2dd95SBruce Richardson rte_tel_data_start_dict(d); 612499a2dd95SBruce Richardson if (!link.link_status) { 612599a2dd95SBruce Richardson rte_tel_data_add_dict_string(d, status_str, "DOWN"); 612699a2dd95SBruce Richardson return 0; 612799a2dd95SBruce Richardson } 612899a2dd95SBruce Richardson rte_tel_data_add_dict_string(d, status_str, "UP"); 612999a2dd95SBruce Richardson rte_tel_data_add_dict_u64(d, "speed", link.link_speed); 613099a2dd95SBruce Richardson rte_tel_data_add_dict_string(d, "duplex", 613199a2dd95SBruce Richardson (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? 613299a2dd95SBruce Richardson "full-duplex" : "half-duplex"); 613399a2dd95SBruce Richardson return 0; 613499a2dd95SBruce Richardson } 613599a2dd95SBruce Richardson 613699a2dd95SBruce Richardson int 613799a2dd95SBruce Richardson rte_eth_hairpin_queue_peer_update(uint16_t peer_port, uint16_t peer_queue, 613899a2dd95SBruce Richardson struct rte_hairpin_peer_info *cur_info, 613999a2dd95SBruce Richardson struct rte_hairpin_peer_info *peer_info, 614099a2dd95SBruce Richardson uint32_t direction) 614199a2dd95SBruce Richardson { 614299a2dd95SBruce Richardson struct rte_eth_dev *dev; 614399a2dd95SBruce Richardson 614499a2dd95SBruce Richardson /* Current queue information is not mandatory. */ 614599a2dd95SBruce Richardson if (peer_info == NULL) 614699a2dd95SBruce Richardson return -EINVAL; 614799a2dd95SBruce Richardson 614899a2dd95SBruce Richardson /* No need to check the validity again. */ 614999a2dd95SBruce Richardson dev = &rte_eth_devices[peer_port]; 615099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_queue_peer_update, 615199a2dd95SBruce Richardson -ENOTSUP); 615299a2dd95SBruce Richardson 615399a2dd95SBruce Richardson return (*dev->dev_ops->hairpin_queue_peer_update)(dev, peer_queue, 615499a2dd95SBruce Richardson cur_info, peer_info, direction); 615599a2dd95SBruce Richardson } 615699a2dd95SBruce Richardson 615799a2dd95SBruce Richardson int 615899a2dd95SBruce Richardson rte_eth_hairpin_queue_peer_bind(uint16_t cur_port, uint16_t cur_queue, 615999a2dd95SBruce Richardson struct rte_hairpin_peer_info *peer_info, 616099a2dd95SBruce Richardson uint32_t direction) 616199a2dd95SBruce Richardson { 616299a2dd95SBruce Richardson struct rte_eth_dev *dev; 616399a2dd95SBruce Richardson 616499a2dd95SBruce Richardson if (peer_info == NULL) 616599a2dd95SBruce Richardson return -EINVAL; 616699a2dd95SBruce Richardson 616799a2dd95SBruce Richardson /* No need to check the validity again. */ 616899a2dd95SBruce Richardson dev = &rte_eth_devices[cur_port]; 616999a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_queue_peer_bind, 617099a2dd95SBruce Richardson -ENOTSUP); 617199a2dd95SBruce Richardson 617299a2dd95SBruce Richardson return (*dev->dev_ops->hairpin_queue_peer_bind)(dev, cur_queue, 617399a2dd95SBruce Richardson peer_info, direction); 617499a2dd95SBruce Richardson } 617599a2dd95SBruce Richardson 617699a2dd95SBruce Richardson int 617799a2dd95SBruce Richardson rte_eth_hairpin_queue_peer_unbind(uint16_t cur_port, uint16_t cur_queue, 617899a2dd95SBruce Richardson uint32_t direction) 617999a2dd95SBruce Richardson { 618099a2dd95SBruce Richardson struct rte_eth_dev *dev; 618199a2dd95SBruce Richardson 618299a2dd95SBruce Richardson /* No need to check the validity again. */ 618399a2dd95SBruce Richardson dev = &rte_eth_devices[cur_port]; 618499a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->hairpin_queue_peer_unbind, 618599a2dd95SBruce Richardson -ENOTSUP); 618699a2dd95SBruce Richardson 618799a2dd95SBruce Richardson return (*dev->dev_ops->hairpin_queue_peer_unbind)(dev, cur_queue, 618899a2dd95SBruce Richardson direction); 618999a2dd95SBruce Richardson } 619099a2dd95SBruce Richardson 619199a2dd95SBruce Richardson int 619299a2dd95SBruce Richardson rte_eth_representor_info_get(uint16_t port_id, 619399a2dd95SBruce Richardson struct rte_eth_representor_info *info) 619499a2dd95SBruce Richardson { 619599a2dd95SBruce Richardson struct rte_eth_dev *dev; 619699a2dd95SBruce Richardson 619799a2dd95SBruce Richardson RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 619899a2dd95SBruce Richardson dev = &rte_eth_devices[port_id]; 619999a2dd95SBruce Richardson 620099a2dd95SBruce Richardson RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->representor_info_get, -ENOTSUP); 620153ef1b34SMin Hu (Connor) return eth_err(port_id, (*dev->dev_ops->representor_info_get)(dev, info)); 620299a2dd95SBruce Richardson } 620399a2dd95SBruce Richardson 6204f6d8a6d3SIvan Malov int 6205f6d8a6d3SIvan Malov rte_eth_rx_metadata_negotiate(uint16_t port_id, uint64_t *features) 6206f6d8a6d3SIvan Malov { 6207f6d8a6d3SIvan Malov struct rte_eth_dev *dev; 6208f6d8a6d3SIvan Malov 6209f6d8a6d3SIvan Malov RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV); 6210f6d8a6d3SIvan Malov dev = &rte_eth_devices[port_id]; 6211f6d8a6d3SIvan Malov 6212f6d8a6d3SIvan Malov if (dev->data->dev_configured != 0) { 6213f6d8a6d3SIvan Malov RTE_ETHDEV_LOG(ERR, 6214f6d8a6d3SIvan Malov "The port (id=%"PRIu16") is already configured\n", 6215f6d8a6d3SIvan Malov port_id); 6216f6d8a6d3SIvan Malov return -EBUSY; 6217f6d8a6d3SIvan Malov } 6218f6d8a6d3SIvan Malov 6219f6d8a6d3SIvan Malov if (features == NULL) { 6220f6d8a6d3SIvan Malov RTE_ETHDEV_LOG(ERR, "Invalid features (NULL)\n"); 6221f6d8a6d3SIvan Malov return -EINVAL; 6222f6d8a6d3SIvan Malov } 6223f6d8a6d3SIvan Malov 6224f6d8a6d3SIvan Malov RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->rx_metadata_negotiate, -ENOTSUP); 6225f6d8a6d3SIvan Malov return eth_err(port_id, 6226f6d8a6d3SIvan Malov (*dev->dev_ops->rx_metadata_negotiate)(dev, features)); 6227f6d8a6d3SIvan Malov } 6228f6d8a6d3SIvan Malov 6229eeded204SDavid Marchand RTE_LOG_REGISTER_DEFAULT(rte_eth_dev_logtype, INFO); 623099a2dd95SBruce Richardson 623199a2dd95SBruce Richardson RTE_INIT(ethdev_init_telemetry) 623299a2dd95SBruce Richardson { 623399a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/list", eth_dev_handle_port_list, 623499a2dd95SBruce Richardson "Returns list of available ethdev ports. Takes no parameters"); 623599a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/stats", eth_dev_handle_port_stats, 623699a2dd95SBruce Richardson "Returns the common stats for a port. Parameters: int port_id"); 623799a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/xstats", eth_dev_handle_port_xstats, 623899a2dd95SBruce Richardson "Returns the extended stats for a port. Parameters: int port_id"); 623999a2dd95SBruce Richardson rte_telemetry_register_cmd("/ethdev/link_status", 624099a2dd95SBruce Richardson eth_dev_handle_port_link_status, 624199a2dd95SBruce Richardson "Returns the link status for a port. Parameters: int port_id"); 624299a2dd95SBruce Richardson } 6243