eventdev: set error code in port link/unlink functions
authorGage Eads <gage.eads@intel.com>
Tue, 14 Nov 2017 22:44:10 +0000 (16:44 -0600)
committerJerin Jacob <jerin.jacob@caviumnetworks.com>
Fri, 19 Jan 2018 15:09:56 +0000 (16:09 +0100)
The return value for rte_event_port_{link, unlink}() is defined as the
"number of {links, unlinks} actually established." However, the eventdev
layer's error checking returns negative error values. This commit aligns
the eventdev code with the API definition by having it set rte_errno and
return 0 if it detects an error.

Fixes: 4f0804bbdfb9 ("eventdev: implement the northbound APIs")
Cc: stable@dpdk.org
Signed-off-by: Gage Eads <gage.eads@intel.com>
lib/librte_eventdev/rte_eventdev.c
lib/librte_eventdev/rte_eventdev_pmd.h

index f32c53f..5e2c4b1 100644 (file)
@@ -804,13 +804,19 @@ rte_event_port_link(uint8_t dev_id, uint8_t port_id,
        uint16_t *links_map;
        int i, diag;
 
-       RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+       RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, -EINVAL, 0);
        dev = &rte_eventdevs[dev_id];
-       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_link, -ENOTSUP);
+
+       if (*dev->dev_ops->port_link == NULL) {
+               RTE_PMD_DEBUG_TRACE("Function not supported\n");
+               rte_errno = -ENOTSUP;
+               return 0;
+       }
 
        if (!is_valid_port(dev, port_id)) {
                RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
-               return -EINVAL;
+               rte_errno = -EINVAL;
+               return 0;
        }
 
        if (queues == NULL) {
@@ -829,8 +835,10 @@ rte_event_port_link(uint8_t dev_id, uint8_t port_id,
        }
 
        for (i = 0; i < nb_links; i++)
-               if (queues[i] >= dev->data->nb_queues)
-                       return -EINVAL;
+               if (queues[i] >= dev->data->nb_queues) {
+                       rte_errno = -EINVAL;
+                       return 0;
+               }
 
        diag = (*dev->dev_ops->port_link)(dev, dev->data->ports[port_id],
                                                queues, priorities, nb_links);
@@ -855,13 +863,19 @@ rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
        int i, diag;
        uint16_t *links_map;
 
-       RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
+       RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, -EINVAL, 0);
        dev = &rte_eventdevs[dev_id];
-       RTE_FUNC_PTR_OR_ERR_RET(*dev->dev_ops->port_unlink, -ENOTSUP);
+
+       if (*dev->dev_ops->port_unlink == NULL) {
+               RTE_PMD_DEBUG_TRACE("Function not supported\n");
+               rte_errno = -ENOTSUP;
+               return 0;
+       }
 
        if (!is_valid_port(dev, port_id)) {
                RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
-               return -EINVAL;
+               rte_errno = -EINVAL;
+               return 0;
        }
 
        if (queues == NULL) {
@@ -872,8 +886,10 @@ rte_event_port_unlink(uint8_t dev_id, uint8_t port_id,
        }
 
        for (i = 0; i < nb_unlinks; i++)
-               if (queues[i] >= dev->data->nb_queues)
-                       return -EINVAL;
+               if (queues[i] >= dev->data->nb_queues) {
+                       rte_errno = -EINVAL;
+                       return 0;
+               }
 
        diag = (*dev->dev_ops->port_unlink)(dev, dev->data->ports[port_id],
                                        queues, nb_unlinks);
index b485a57..399a17a 100644 (file)
@@ -50,6 +50,14 @@ extern "C" {
        } \
 } while (0)
 
+#define RTE_EVENTDEV_VALID_DEVID_OR_ERRNO_RET(dev_id, errno, retval) do { \
+       if (!rte_event_pmd_is_valid_dev((dev_id))) { \
+               RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \
+               rte_errno = errno; \
+               return retval; \
+       } \
+} while (0)
+
 #define RTE_EVENTDEV_VALID_DEVID_OR_RET(dev_id) do { \
        if (!rte_event_pmd_is_valid_dev((dev_id))) { \
                RTE_EDEV_LOG_ERR("Invalid dev_id=%d\n", dev_id); \