* Copyright 2017 Mellanox Technologies, Ltd
*/
+#include <stdbool.h>
+
#include <rte_alarm.h>
#include <rte_malloc.h>
-#include <rte_ethdev_driver.h>
-#include <rte_ethdev_vdev.h>
+#include <ethdev_driver.h>
+#include <ethdev_vdev.h>
#include <rte_devargs.h>
#include <rte_kvargs.h>
#include <rte_bus_vdev.h>
#include "failsafe_private.h"
-int failsafe_logtype;
-
const char pmd_failsafe_driver_name[] = FAILSAFE_DRIVER_NAME;
static const struct rte_eth_link eth_link = {
- .link_speed = ETH_SPEED_NUM_10G,
- .link_duplex = ETH_LINK_FULL_DUPLEX,
- .link_status = ETH_LINK_UP,
- .link_autoneg = ETH_LINK_AUTONEG,
+ .link_speed = RTE_ETH_SPEED_NUM_10G,
+ .link_duplex = RTE_ETH_LINK_FULL_DUPLEX,
+ .link_status = RTE_ETH_LINK_UP,
+ .link_autoneg = RTE_ETH_LINK_AUTONEG,
};
static int
uint8_t nb_subs;
int ret;
int i;
+ struct sub_device *sdev;
+ uint8_t sdev_iterator;
ret = failsafe_args_count_subdevice(dev, params);
if (ret)
for (i = 1; i < nb_subs; i++)
PRIV(dev)->subs[i - 1].next = PRIV(dev)->subs + i;
PRIV(dev)->subs[i - 1].next = PRIV(dev)->subs;
- return 0;
-}
-static void
-fs_sub_device_free(struct rte_eth_dev *dev)
-{
- rte_free(PRIV(dev)->subs);
+ FOREACH_SUBDEV(sdev, sdev_iterator, dev) {
+ sdev->sdev_port_id = RTE_MAX_ETHPORTS;
+ }
+ return 0;
}
static void fs_hotplug_alarm(void *arg);
fs_eth_dev_create(struct rte_vdev_device *vdev)
{
struct rte_eth_dev *dev;
- struct ether_addr *mac;
+ struct rte_ether_addr *mac;
struct fs_priv *priv;
struct sub_device *sdev;
const char *params;
return -1;
}
priv = PRIV(dev);
- priv->dev = dev;
+ priv->data = dev->data;
+ priv->rxp = FS_RX_PROXY_INIT;
dev->dev_ops = &failsafe_ops;
dev->data->mac_addrs = &PRIV(dev)->mac_addrs[0];
dev->data->dev_link = eth_link;
if (failsafe_mac_from_arg) {
/*
* If MAC address was provided as a parameter,
- * apply to all probed slaves.
+ * apply to all probed subdevices.
*/
FOREACH_SUBDEV_STATE(sdev, i, dev, DEV_PROBED) {
ret = rte_eth_dev_default_mac_addr_set(PORT_ID(sdev),
*/
FOREACH_SUBDEV(sdev, i, dev)
if (sdev->state >= DEV_PROBED) {
- ether_addr_copy(Ð(sdev)->data->mac_addrs[0],
- mac);
+ rte_ether_addr_copy(
+ Ð(sdev)->data->mac_addrs[0], mac);
break;
}
/*
* If no device has been probed and no ether_addr
* has been provided on the command line, use a random
* valid one.
- * It will be applied during future slave state syncs to
- * probed slaves.
+ * It will be applied during future state syncs to
+ * probed subdevices.
*/
if (i == priv->subs_tail)
- eth_random_addr(&mac->addr_bytes[0]);
+ rte_eth_random_addr(&mac->addr_bytes[0]);
}
- INFO("MAC address is %02x:%02x:%02x:%02x:%02x:%02x",
- mac->addr_bytes[0], mac->addr_bytes[1],
- mac->addr_bytes[2], mac->addr_bytes[3],
- mac->addr_bytes[4], mac->addr_bytes[5]);
- dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC;
- PRIV(dev)->intr_handle = (struct rte_intr_handle){
- .fd = -1,
- .type = RTE_INTR_HANDLE_EXT,
- };
+ INFO("MAC address is " RTE_ETHER_ADDR_PRT_FMT,
+ RTE_ETHER_ADDR_BYTES(mac));
+ dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC |
+ RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS;
+
+ /* Allocate interrupt instance */
+ PRIV(dev)->intr_handle =
+ rte_intr_instance_alloc(RTE_INTR_INSTANCE_F_SHARED);
+ if (PRIV(dev)->intr_handle == NULL) {
+ ERROR("Failed to allocate intr handle");
+ goto cancel_alarm;
+ }
+
+ if (rte_intr_fd_set(PRIV(dev)->intr_handle, -1))
+ goto cancel_alarm;
+
+ if (rte_intr_type_set(PRIV(dev)->intr_handle, RTE_INTR_HANDLE_EXT))
+ goto cancel_alarm;
+
rte_eth_dev_probing_finish(dev);
+
return 0;
cancel_alarm:
failsafe_hotplug_alarm_cancel(dev);
free_args:
failsafe_args_free(dev);
free_subs:
- fs_sub_device_free(dev);
+ rte_free(PRIV(dev)->subs);
free_dev:
/* mac_addrs must not be freed alone because part of dev_private */
dev->data->mac_addrs = NULL;
dev = rte_eth_dev_allocated(name);
if (dev == NULL)
- return -ENODEV;
- rte_eth_dev_callback_unregister(RTE_ETH_ALL, RTE_ETH_EVENT_NEW,
- failsafe_eth_new_event_callback, dev);
- ret = failsafe_eal_uninit(dev);
- if (ret)
- ERROR("Error while uninitializing sub-EAL");
- failsafe_args_free(dev);
- fs_sub_device_free(dev);
- ret = pthread_mutex_destroy(&PRIV(dev)->hotplug_mutex);
- if (ret)
- ERROR("Error while destroying hotplug mutex");
- rte_free(PRIV(dev)->mcast_addrs);
- /* mac_addrs must not be freed alone because part of dev_private */
- dev->data->mac_addrs = NULL;
+ return 0; /* port already released */
+ ret = failsafe_eth_dev_close(dev);
rte_eth_dev_release_port(dev);
+ rte_intr_instance_free(PRIV(dev)->intr_handle);
return ret;
}
+static bool
+devargs_already_listed(struct rte_devargs *devargs)
+{
+ struct rte_devargs *list_da;
+
+ RTE_EAL_DEVARGS_FOREACH(devargs->bus->name, list_da) {
+ if (strcmp(list_da->name, devargs->name) == 0)
+ /* devargs already in the list */
+ return true;
+ }
+ return false;
+}
+
static int
rte_pmd_failsafe_probe(struct rte_vdev_device *vdev)
{
const char *name;
struct rte_eth_dev *eth_dev;
+ struct sub_device *sdev;
+ struct rte_devargs devargs;
+ uint8_t i;
+ int ret;
name = rte_vdev_device_name(vdev);
INFO("Initializing " FAILSAFE_DRIVER_NAME " for %s",
name);
- if (rte_eal_process_type() == RTE_PROC_SECONDARY &&
- strlen(rte_vdev_device_args(vdev)) == 0) {
+ if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
eth_dev = rte_eth_dev_attach_secondary(name);
if (!eth_dev) {
ERROR("Failed to probe %s", name);
return -1;
}
- /* TODO: request info from primary to set up Rx and Tx */
eth_dev->dev_ops = &failsafe_ops;
eth_dev->device = &vdev->device;
+ eth_dev->rx_pkt_burst = (eth_rx_burst_t)&failsafe_rx_burst;
+ eth_dev->tx_pkt_burst = (eth_tx_burst_t)&failsafe_tx_burst;
+ /*
+ * Failsafe will attempt to probe all of its sub-devices.
+ * Any failure in sub-devices is not a fatal error.
+ * A sub-device can be plugged later.
+ */
+ FOREACH_SUBDEV(sdev, i, eth_dev) {
+ /* skip empty devargs */
+ if (sdev->devargs.name[0] == '\0')
+ continue;
+
+ /* rebuild devargs to be able to get the bus name. */
+ ret = rte_devargs_parse(&devargs,
+ sdev->devargs.name);
+ if (ret != 0) {
+ ERROR("Failed to parse devargs %s",
+ devargs.name);
+ continue;
+ }
+ if (!devargs_already_listed(&devargs)) {
+ ret = rte_dev_probe(devargs.name);
+ if (ret < 0) {
+ ERROR("Failed to probe devargs %s",
+ devargs.name);
+ continue;
+ }
+ }
+ }
rte_eth_dev_probing_finish(eth_dev);
return 0;
}
RTE_PMD_REGISTER_VDEV(net_failsafe, failsafe_drv);
RTE_PMD_REGISTER_PARAM_STRING(net_failsafe, PMD_FAILSAFE_PARAM_STRING);
-
-RTE_INIT(failsafe_init_log)
-{
- failsafe_logtype = rte_log_register("pmd.net.failsafe");
- if (failsafe_logtype >= 0)
- rte_log_set_level(failsafe_logtype, RTE_LOG_NOTICE);
-}
+RTE_LOG_REGISTER_DEFAULT(failsafe_logtype, NOTICE)