X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=drivers%2Fnet%2Ffailsafe%2Ffailsafe.c;h=e3bda0df2bf9e62944e64cfc77608af261a31a7b;hb=56175f74eaa565cdfde931d83be1db9faaa81667;hp=06e859e9fdc2fda872defffa84cac0eee3bedc3f;hpb=520dd9923b351ea7a3b7476d3a04542ab0d9ad0c;p=dpdk.git diff --git a/drivers/net/failsafe/failsafe.c b/drivers/net/failsafe/failsafe.c index 06e859e9fd..e3bda0df2b 100644 --- a/drivers/net/failsafe/failsafe.c +++ b/drivers/net/failsafe/failsafe.c @@ -3,18 +3,18 @@ * Copyright 2017 Mellanox Technologies, Ltd */ +#include + #include #include -#include -#include +#include +#include #include #include #include #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, @@ -30,6 +30,8 @@ fs_sub_device_alloc(struct rte_eth_dev *dev, 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) @@ -51,13 +53,11 @@ fs_sub_device_alloc(struct rte_eth_dev *dev, 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); @@ -158,7 +158,7 @@ static int 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; @@ -181,7 +181,8 @@ fs_eth_dev_create(struct rte_vdev_device *vdev) 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; @@ -228,7 +229,7 @@ fs_eth_dev_create(struct rte_vdev_device *vdev) 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), @@ -245,25 +246,26 @@ fs_eth_dev_create(struct rte_vdev_device *vdev) */ 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; + dev->data->dev_flags |= RTE_ETH_DEV_INTR_LSC | + RTE_ETH_DEV_AUTOFILL_QUEUE_XSTATS; PRIV(dev)->intr_handle = (struct rte_intr_handle){ .fd = -1, .type = RTE_INTR_HANDLE_EXT, @@ -278,7 +280,7 @@ unregister_new_callback: 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; @@ -294,29 +296,34 @@ fs_rte_eth_free(const char *name) 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); 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", @@ -329,9 +336,37 @@ rte_pmd_failsafe_probe(struct rte_vdev_device *vdev) 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; } @@ -356,10 +391,4 @@ static struct rte_vdev_driver failsafe_drv = { 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(failsafe_logtype, pmd.net.failsafe, NOTICE)