ethdev: change allmulticast callbacks to return status
[dpdk.git] / lib / librte_ethdev / rte_ethdev.c
index f2e6b4c..5cb651e 100644 (file)
@@ -687,10 +687,11 @@ rte_eth_dev_owner_unset(const uint16_t port_id, const uint64_t owner_id)
        return ret;
 }
 
-void
+int
 rte_eth_dev_owner_delete(const uint64_t owner_id)
 {
        uint16_t port_id;
+       int ret = 0;
 
        rte_eth_dev_shared_data_prepare();
 
@@ -708,9 +709,12 @@ rte_eth_dev_owner_delete(const uint64_t owner_id)
                RTE_ETHDEV_LOG(ERR,
                               "Invalid owner id=%016"PRIx64"\n",
                               owner_id);
+               ret = -EINVAL;
        }
 
        rte_spinlock_unlock(&rte_eth_dev_shared_data->ownership_lock);
+
+       return ret;
 }
 
 int
@@ -1391,16 +1395,24 @@ rte_eth_dev_config_restore(struct rte_eth_dev *dev,
                rte_eth_dev_mac_restore(dev, dev_info);
 
        /* replay promiscuous configuration */
-       if (rte_eth_promiscuous_get(port_id) == 1) {
-               ret = rte_eth_promiscuous_enable(port_id);
+       /*
+        * use callbacks directly since we don't need port_id check and
+        * would like to bypass the same value set
+        */
+       if (rte_eth_promiscuous_get(port_id) == 1 &&
+           *dev->dev_ops->promiscuous_enable != NULL) {
+               ret = eth_err(port_id,
+                             (*dev->dev_ops->promiscuous_enable)(dev));
                if (ret != 0 && ret != -ENOTSUP) {
                        RTE_ETHDEV_LOG(ERR,
                                "Failed to enable promiscuous mode for device (port %u): %s\n",
                                port_id, rte_strerror(-ret));
                        return ret;
                }
-       } else if (rte_eth_promiscuous_get(port_id) == 0) {
-               ret = rte_eth_promiscuous_disable(port_id);
+       } else if (rte_eth_promiscuous_get(port_id) == 0 &&
+                  *dev->dev_ops->promiscuous_disable != NULL) {
+               ret = eth_err(port_id,
+                             (*dev->dev_ops->promiscuous_disable)(dev));
                if (ret != 0 && ret != -ENOTSUP) {
                        RTE_ETHDEV_LOG(ERR,
                                "Failed to disable promiscuous mode for device (port %u): %s\n",
@@ -1410,10 +1422,23 @@ rte_eth_dev_config_restore(struct rte_eth_dev *dev,
        }
 
        /* replay all multicast configuration */
-       if (rte_eth_allmulticast_get(port_id) == 1)
-               rte_eth_allmulticast_enable(port_id);
-       else if (rte_eth_allmulticast_get(port_id) == 0)
-               rte_eth_allmulticast_disable(port_id);
+       if (rte_eth_allmulticast_get(port_id) == 1) {
+               ret = rte_eth_allmulticast_enable(port_id);
+               if (ret != 0 && ret != -ENOTSUP) {
+                       RTE_ETHDEV_LOG(ERR,
+                               "Failed to enable allmulticast mode for device (port %u): %s\n",
+                               port_id, rte_strerror(-ret));
+                       return ret;
+               }
+       } else if (rte_eth_allmulticast_get(port_id) == 0) {
+               ret = rte_eth_allmulticast_disable(port_id);
+               if (ret != 0 && ret != -ENOTSUP) {
+                       RTE_ETHDEV_LOG(ERR,
+                               "Failed to disable allmulticast mode for device (port %u): %s\n",
+                               port_id, rte_strerror(-ret));
+                       return ret;
+               }
+       }
 
        return 0;
 }
@@ -1892,16 +1917,17 @@ int
 rte_eth_promiscuous_enable(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
-       uint8_t old_promiscuous;
-       int diag;
+       int diag = 0;
 
        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->promiscuous_enable, -ENOTSUP);
-       old_promiscuous = dev->data->promiscuous;
-       diag = (*dev->dev_ops->promiscuous_enable)(dev);
-       dev->data->promiscuous = (diag == 0) ? 1 : old_promiscuous;
+
+       if (dev->data->promiscuous == 0) {
+               diag = (*dev->dev_ops->promiscuous_enable)(dev);
+               dev->data->promiscuous = (diag == 0) ? 1 : 0;
+       }
 
        return eth_err(port_id, diag);
 }
@@ -1910,18 +1936,19 @@ int
 rte_eth_promiscuous_disable(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
-       uint8_t old_promiscuous;
-       int diag;
+       int diag = 0;
 
        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->promiscuous_disable, -ENOTSUP);
-       old_promiscuous = dev->data->promiscuous;
-       dev->data->promiscuous = 0;
-       diag = (*dev->dev_ops->promiscuous_disable)(dev);
-       if (diag != 0)
-               dev->data->promiscuous = old_promiscuous;
+
+       if (dev->data->promiscuous == 1) {
+               dev->data->promiscuous = 0;
+               diag = (*dev->dev_ops->promiscuous_disable)(dev);
+               if (diag != 0)
+                       dev->data->promiscuous = 1;
+       }
 
        return eth_err(port_id, diag);
 }
@@ -1937,30 +1964,42 @@ rte_eth_promiscuous_get(uint16_t port_id)
        return dev->data->promiscuous;
 }
 
-void
+int
 rte_eth_allmulticast_enable(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
+       uint8_t old_allmulticast;
+       int diag;
 
-       RTE_ETH_VALID_PORTID_OR_RET(port_id);
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
-       RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_enable);
-       (*dev->dev_ops->allmulticast_enable)(dev);
-       dev->data->all_multicast = 1;
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_enable, -ENOTSUP);
+       old_allmulticast = dev->data->all_multicast;
+       diag = (*dev->dev_ops->allmulticast_enable)(dev);
+       dev->data->all_multicast = (diag == 0) ? 1 : old_allmulticast;
+
+       return eth_err(port_id, diag);
 }
 
-void
+int
 rte_eth_allmulticast_disable(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
+       uint8_t old_allmulticast;
+       int diag;
 
-       RTE_ETH_VALID_PORTID_OR_RET(port_id);
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
-       RTE_FUNC_PTR_OR_RET(*dev->dev_ops->allmulticast_disable);
+       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->allmulticast_disable, -ENOTSUP);
+       old_allmulticast = dev->data->all_multicast;
        dev->data->all_multicast = 0;
-       (*dev->dev_ops->allmulticast_disable)(dev);
+       diag = (*dev->dev_ops->allmulticast_disable)(dev);
+       if (diag != 0)
+               dev->data->all_multicast = old_allmulticast;
+
+       return eth_err(port_id, diag);
 }
 
 int
@@ -1974,40 +2013,44 @@ rte_eth_allmulticast_get(uint16_t port_id)
        return dev->data->all_multicast;
 }
 
-void
+int
 rte_eth_link_get(uint16_t port_id, struct rte_eth_link *eth_link)
 {
        struct rte_eth_dev *dev;
 
-       RTE_ETH_VALID_PORTID_OR_RET(port_id);
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
        if (dev->data->dev_conf.intr_conf.lsc &&
            dev->data->dev_started)
                rte_eth_linkstatus_get(dev, eth_link);
        else {
-               RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
+               RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
                (*dev->dev_ops->link_update)(dev, 1);
                *eth_link = dev->data->dev_link;
        }
+
+       return 0;
 }
 
-void
+int
 rte_eth_link_get_nowait(uint16_t port_id, struct rte_eth_link *eth_link)
 {
        struct rte_eth_dev *dev;
 
-       RTE_ETH_VALID_PORTID_OR_RET(port_id);
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
        if (dev->data->dev_conf.intr_conf.lsc &&
            dev->data->dev_started)
                rte_eth_linkstatus_get(dev, eth_link);
        else {
-               RTE_FUNC_PTR_OR_RET(*dev->dev_ops->link_update);
+               RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->link_update, -ENOTSUP);
                (*dev->dev_ops->link_update)(dev, 0);
                *eth_link = dev->data->dev_link;
        }
+
+       return 0;
 }
 
 int
@@ -2029,12 +2072,16 @@ int
 rte_eth_stats_reset(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
+       int ret;
 
        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->stats_reset, -ENOTSUP);
-       (*dev->dev_ops->stats_reset)(dev);
+       ret = (*dev->dev_ops->stats_reset)(dev);
+       if (ret != 0)
+               return eth_err(port_id, ret);
+
        dev->data->rx_mbuf_alloc_failed = 0;
 
        return 0;
@@ -2510,22 +2557,20 @@ rte_eth_xstats_get(uint16_t port_id, struct rte_eth_xstat *xstats,
 }
 
 /* reset ethdev extended statistics */
-void
+int
 rte_eth_xstats_reset(uint16_t port_id)
 {
        struct rte_eth_dev *dev;
 
-       RTE_ETH_VALID_PORTID_OR_RET(port_id);
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
 
        /* implemented by the driver */
-       if (dev->dev_ops->xstats_reset != NULL) {
-               (*dev->dev_ops->xstats_reset)(dev);
-               return;
-       }
+       if (dev->dev_ops->xstats_reset != NULL)
+               return eth_err(port_id, (*dev->dev_ops->xstats_reset)(dev));
 
        /* fallback to default */
-       rte_eth_stats_reset(port_id);
+       return rte_eth_stats_reset(port_id);
 }
 
 static int
@@ -2655,14 +2700,16 @@ rte_eth_dev_get_supported_ptypes(uint16_t port_id, uint32_t ptype_mask,
        return j;
 }
 
-void
+int
 rte_eth_macaddr_get(uint16_t port_id, struct rte_ether_addr *mac_addr)
 {
        struct rte_eth_dev *dev;
 
-       RTE_ETH_VALID_PORTID_OR_RET(port_id);
+       RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
        dev = &rte_eth_devices[port_id];
        rte_ether_addr_copy(&dev->data->mac_addrs[0], mac_addr);
+
+       return 0;
 }