* Copyright(c) 2010-2017 Intel Corporation
*/
-#include <sys/types.h>
-#include <sys/queue.h>
#include <ctype.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <stdarg.h>
#include <errno.h>
+#include <inttypes.h>
#include <stdbool.h>
#include <stdint.h>
-#include <inttypes.h>
-#include <netinet/in.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/queue.h>
#include <rte_byteorder.h>
#include <rte_log.h>
#include "rte_ethdev_trace.h"
#include "rte_ethdev.h"
-#include "rte_ethdev_driver.h"
+#include "ethdev_driver.h"
#include "ethdev_profile.h"
#include "ethdev_private.h"
rte_eth_iterator_init(struct rte_dev_iterator *iter, const char *devargs_str)
{
int ret;
- struct rte_devargs devargs = {.args = NULL};
+ struct rte_devargs devargs;
const char *bus_param_key;
char *bus_str = NULL;
char *cls_str = NULL;
int str_size;
memset(iter, 0, sizeof(*iter));
+ memset(&devargs, 0, sizeof(devargs));
/*
* The devargs string may use various syntaxes:
goto error;
}
iter->cls_str = cls_str;
- free(devargs.args); /* allocated by rte_devargs_parse() */
- devargs.args = NULL;
iter->bus = devargs.bus;
if (iter->bus->dev_iterate == NULL) {
end:
iter->cls = rte_class_find_by_name("eth");
+ rte_devargs_reset(&devargs);
return 0;
error:
if (ret == -ENOTSUP)
RTE_ETHDEV_LOG(ERR, "Bus %s does not support iterating.\n",
iter->bus->name);
- free(devargs.args);
+ rte_devargs_reset(&devargs);
free(bus_str);
free(cls_str);
return ret;
static struct rte_eth_dev *
eth_dev_allocated(const char *name)
{
- unsigned i;
+ uint16_t i;
+
+ RTE_BUILD_BUG_ON(RTE_MAX_ETHPORTS >= UINT16_MAX);
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
if (rte_eth_devices[i].data != NULL &&
static uint16_t
eth_dev_find_free_port(void)
{
- unsigned i;
+ uint16_t i;
for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
/* Using shared name field to find a free port. */
int
rte_eth_dev_get_port_by_name(const char *name, uint16_t *port_id)
{
- uint32_t pid;
+ uint16_t pid;
if (name == NULL) {
RTE_ETHDEV_LOG(ERR, "Null pointer is specified\n");
struct rte_eth_dev *dev;
struct rte_eth_dev_info dev_info;
struct rte_eth_conf orig_conf;
+ uint16_t overhead_len;
int diag;
int ret;
+ uint16_t old_mtu;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
memcpy(&dev->data->dev_conf, dev_conf,
sizeof(dev->data->dev_conf));
+ /* Backup mtu for rollback */
+ old_mtu = dev->data->mtu;
+
ret = rte_eth_dev_info_get(port_id, &dev_info);
if (ret != 0)
goto rollback;
+ /* Get the real Ethernet overhead length */
+ if (dev_info.max_mtu != UINT16_MAX &&
+ dev_info.max_rx_pktlen > dev_info.max_mtu)
+ overhead_len = dev_info.max_rx_pktlen - dev_info.max_mtu;
+ else
+ overhead_len = RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
+
/* If number of queues specified by application for both Rx and Tx is
* zero, use driver preferred values. This cannot be done individually
* as it is valid for either Tx or Rx (but not both) to be zero.
ret = -EINVAL;
goto rollback;
}
+
+ /* Scale the MTU size to adapt max_rx_pkt_len */
+ dev->data->mtu = dev->data->dev_conf.rxmode.max_rx_pkt_len -
+ overhead_len;
} else {
- if (dev_conf->rxmode.max_rx_pkt_len < RTE_ETHER_MIN_LEN ||
- dev_conf->rxmode.max_rx_pkt_len > RTE_ETHER_MAX_LEN)
+ uint16_t pktlen = dev_conf->rxmode.max_rx_pkt_len;
+ if (pktlen < RTE_ETHER_MIN_MTU + overhead_len ||
+ pktlen > RTE_ETHER_MTU + overhead_len)
/* Use default value */
dev->data->dev_conf.rxmode.max_rx_pkt_len =
- RTE_ETHER_MAX_LEN;
+ RTE_ETHER_MTU + overhead_len;
}
/*
eth_dev_tx_queue_config(dev, 0);
rollback:
memcpy(&dev->data->dev_conf, &orig_conf, sizeof(dev->data->dev_conf));
+ if (old_mtu != dev->data->mtu)
+ dev->data->mtu = old_mtu;
rte_ethdev_trace_configure(port_id, nb_rx_q, nb_tx_q, dev_conf, ret);
return ret;
rte_ethdev_trace_close(port_id);
*lasterr = rte_eth_dev_release_port(dev);
- return eth_err(port_id, firsterr);
+ return firsterr;
}
int
return -EINVAL;
}
} else {
- const struct rte_eth_rxseg_split *rx_seg =
- (const struct rte_eth_rxseg_split *)rx_conf->rx_seg;
- uint16_t n_seg = rx_conf->rx_nseg;
+ const struct rte_eth_rxseg_split *rx_seg;
+ uint16_t n_seg;
/* Extended multi-segment configuration check. */
if (rx_conf == NULL || rx_conf->rx_seg == NULL || rx_conf->rx_nseg == 0) {
"Memory pool is null and no extended configuration provided\n");
return -EINVAL;
}
+
+ rx_seg = (const struct rte_eth_rxseg_split *)rx_conf->rx_seg;
+ n_seg = rx_conf->rx_nseg;
+
if (rx_conf->offloads & RTE_ETH_RX_OFFLOAD_BUFFER_SPLIT) {
ret = rte_eth_rx_queue_check_split(rx_seg, n_seg,
&mbp_buf_size,
RTE_INIT(eth_dev_init_cb_lists)
{
- int i;
+ uint16_t i;
for (i = 0; i < RTE_MAX_ETHPORTS; i++)
TAILQ_INIT(&rte_eth_devices[i].link_intr_cbs);
{
struct rte_eth_dev *dev;
struct rte_eth_dev_callback *user_cb;
- uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
+ uint16_t next_port;
uint16_t last_port;
if (!cb_fn)
int ret;
struct rte_eth_dev *dev;
struct rte_eth_dev_callback *cb, *next;
- uint32_t next_port; /* size is 32-bit to prevent loop wrap-around */
+ uint16_t next_port;
uint16_t last_port;
if (!cb_fn)
dev->dev_ops->tx_burst_mode_get(dev, queue_id, mode));
}
+int
+rte_eth_get_monitor_addr(uint16_t port_id, uint16_t queue_id,
+ struct rte_power_monitor_cond *pmc)
+{
+ struct rte_eth_dev *dev;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+
+ dev = &rte_eth_devices[port_id];
+
+ RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_monitor_addr, -ENOTSUP);
+
+ if (queue_id >= dev->data->nb_rx_queues) {
+ RTE_ETHDEV_LOG(ERR, "Invalid Rx queue_id=%u\n", queue_id);
+ return -EINVAL;
+ }
+
+ if (pmc == NULL) {
+ RTE_ETHDEV_LOG(ERR, "Invalid power monitor condition=%p\n",
+ pmc);
+ return -EINVAL;
+ }
+
+ return eth_err(port_id,
+ dev->dev_ops->get_monitor_addr(dev->data->rx_queues[queue_id],
+ pmc));
+}
+
int
rte_eth_dev_set_mc_addr_list(uint16_t port_id,
struct rte_ether_addr *mc_addr_set,
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ if (info == NULL)
+ return -EINVAL;
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_reg, -ENOTSUP);
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ if (info == NULL)
+ return -EINVAL;
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_eeprom, -ENOTSUP);
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ if (info == NULL)
+ return -EINVAL;
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->set_eeprom, -ENOTSUP);
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ if (modinfo == NULL)
+ return -EINVAL;
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_info, -ENOTSUP);
struct rte_eth_dev *dev;
RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ if (info == NULL || info->data == NULL || info->length == 0)
+ return -EINVAL;
dev = &rte_eth_devices[port_id];
RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->get_module_eeprom, -ENOTSUP);
return eth_err(port_id, (*dev->dev_ops->get_dcb_info)(dev, dcb_info));
}
-int
-rte_eth_dev_l2_tunnel_eth_type_conf(uint16_t port_id,
- struct rte_eth_l2_tunnel_conf *l2_tunnel)
-{
- struct rte_eth_dev *dev;
-
- RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
- if (l2_tunnel == NULL) {
- RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
- return -EINVAL;
- }
-
- if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
- RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
- return -EINVAL;
- }
-
- dev = &rte_eth_devices[port_id];
- RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_eth_type_conf,
- -ENOTSUP);
- return eth_err(port_id, (*dev->dev_ops->l2_tunnel_eth_type_conf)(dev,
- l2_tunnel));
-}
-
-int
-rte_eth_dev_l2_tunnel_offload_set(uint16_t port_id,
- struct rte_eth_l2_tunnel_conf *l2_tunnel,
- uint32_t mask,
- uint8_t en)
-{
- struct rte_eth_dev *dev;
-
- RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
-
- if (l2_tunnel == NULL) {
- RTE_ETHDEV_LOG(ERR, "Invalid l2_tunnel parameter\n");
- return -EINVAL;
- }
-
- if (l2_tunnel->l2_tunnel_type >= RTE_TUNNEL_TYPE_MAX) {
- RTE_ETHDEV_LOG(ERR, "Invalid tunnel type\n");
- return -EINVAL;
- }
-
- if (mask == 0) {
- RTE_ETHDEV_LOG(ERR, "Mask should have a value\n");
- return -EINVAL;
- }
-
- dev = &rte_eth_devices[port_id];
- RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->l2_tunnel_offload_set,
- -ENOTSUP);
- return eth_err(port_id, (*dev->dev_ops->l2_tunnel_offload_set)(dev,
- l2_tunnel, mask, en));
-}
-
static void
eth_dev_adjust_nb_desc(uint16_t *nb_desc,
const struct rte_eth_desc_lim *desc_lim)
int
rte_eth_switch_domain_alloc(uint16_t *domain_id)
{
- unsigned int i;
+ uint16_t i;
*domain_id = RTE_ETH_DEV_SWITCH_DOMAIN_ID_INVALID;
for (i = 0; i < args.count; i++) {
pair = &args.pairs[i];
if (strcmp("representor", pair->key) == 0) {
- result = rte_eth_devargs_parse_list(pair->value,
- rte_eth_devargs_parse_representor_ports,
- eth_da);
+ if (eth_da->type != RTE_ETH_REPRESENTOR_NONE) {
+ RTE_LOG(ERR, EAL, "duplicated representor key: %s\n",
+ dargs);
+ result = -1;
+ goto parse_cleanup;
+ }
+ result = rte_eth_devargs_parse_representor_ports(
+ pair->value, eth_da);
if (result < 0)
goto parse_cleanup;
}
return result;
}
+int
+rte_eth_representor_id_get(const struct rte_eth_dev *ethdev,
+ enum rte_eth_representor_type type,
+ int controller, int pf, int representor_port,
+ uint16_t *repr_id)
+{
+ int ret, n, i, count;
+ struct rte_eth_representor_info *info = NULL;
+ size_t size;
+
+ if (type == RTE_ETH_REPRESENTOR_NONE)
+ return 0;
+ if (repr_id == NULL)
+ return -EINVAL;
+
+ /* Get PMD representor range info. */
+ ret = rte_eth_representor_info_get(ethdev->data->port_id, NULL);
+ if (ret == -ENOTSUP && type == RTE_ETH_REPRESENTOR_VF &&
+ controller == -1 && pf == -1) {
+ /* Direct mapping for legacy VF representor. */
+ *repr_id = representor_port;
+ return 0;
+ } else if (ret < 0) {
+ return ret;
+ }
+ n = ret;
+ size = sizeof(*info) + n * sizeof(info->ranges[0]);
+ info = calloc(1, size);
+ if (info == NULL)
+ return -ENOMEM;
+ ret = rte_eth_representor_info_get(ethdev->data->port_id, info);
+ if (ret < 0)
+ goto out;
+
+ /* Default controller and pf to caller. */
+ if (controller == -1)
+ controller = info->controller;
+ if (pf == -1)
+ pf = info->pf;
+
+ /* Locate representor ID. */
+ ret = -ENOENT;
+ for (i = 0; i < n; ++i) {
+ if (info->ranges[i].type != type)
+ continue;
+ if (info->ranges[i].controller != controller)
+ continue;
+ if (info->ranges[i].id_end < info->ranges[i].id_base) {
+ RTE_LOG(WARNING, EAL, "Port %hu invalid representor ID Range %u - %u, entry %d\n",
+ ethdev->data->port_id, info->ranges[i].id_base,
+ info->ranges[i].id_end, i);
+ continue;
+
+ }
+ count = info->ranges[i].id_end - info->ranges[i].id_base + 1;
+ switch (info->ranges[i].type) {
+ case RTE_ETH_REPRESENTOR_PF:
+ if (pf < info->ranges[i].pf ||
+ pf >= info->ranges[i].pf + count)
+ continue;
+ *repr_id = info->ranges[i].id_base +
+ (pf - info->ranges[i].pf);
+ ret = 0;
+ goto out;
+ case RTE_ETH_REPRESENTOR_VF:
+ if (info->ranges[i].pf != pf)
+ continue;
+ if (representor_port < info->ranges[i].vf ||
+ representor_port >= info->ranges[i].vf + count)
+ continue;
+ *repr_id = info->ranges[i].id_base +
+ (representor_port - info->ranges[i].vf);
+ ret = 0;
+ goto out;
+ case RTE_ETH_REPRESENTOR_SF:
+ if (info->ranges[i].pf != pf)
+ continue;
+ if (representor_port < info->ranges[i].sf ||
+ representor_port >= info->ranges[i].sf + count)
+ continue;
+ *repr_id = info->ranges[i].id_base +
+ (representor_port - info->ranges[i].sf);
+ ret = 0;
+ goto out;
+ default:
+ break;
+ }
+ }
+out:
+ free(info);
+ return ret;
+}
+
static int
eth_dev_handle_port_list(const char *cmd __rte_unused,
const char *params __rte_unused,
if (!rte_eth_dev_is_valid_port(port_id))
return -1;
- ret = rte_eth_link_get(port_id, &link);
+ ret = rte_eth_link_get_nowait(port_id, &link);
if (ret < 0)
return -1;
direction);
}
+int
+rte_eth_representor_info_get(uint16_t port_id,
+ struct rte_eth_representor_info *info)
+{
+ struct rte_eth_dev *dev;
+
+ RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
+ dev = &rte_eth_devices[port_id];
+
+ RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->representor_info_get, -ENOTSUP);
+ return eth_err(port_id, (*dev->dev_ops->representor_info_get)(dev,
+ info));
+}
+
RTE_LOG_REGISTER(rte_eth_dev_logtype, lib.ethdev, INFO);
RTE_INIT(ethdev_init_telemetry)