eventdev: add device started attribute
[dpdk.git] / lib / librte_eventdev / rte_eventdev.c
index e706688..c5db32f 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *   BSD LICENSE
  *
- *   Copyright(c) 2016 Cavium networks. All rights reserved.
+ *   Copyright(c) 2016 Cavium, Inc. All rights reserved.
  *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
@@ -13,7 +13,7 @@
  *       notice, this list of conditions and the following disclaimer in
  *       the documentation and/or other materials provided with the
  *       distribution.
- *     * Neither the name of Cavium networks nor the names of its
+ *     * Neither the name of Cavium, Inc nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
  *
@@ -298,7 +298,7 @@ rte_event_dev_port_config(struct rte_eventdev *dev, uint8_t nb_ports)
                        sizeof(dev->data->links_map[0]) * nb_ports *
                        RTE_EVENT_MAX_QUEUES_PER_DEV,
                        RTE_CACHE_LINE_SIZE);
-               if (dev->data->links_map == NULL) {
+               if (links_map == NULL) {
                        dev->data->nb_ports = 0;
                        RTE_EDEV_LOG_ERR("failed to realloc mem for port_map,"
                                        "nb_ports %u", nb_ports);
@@ -519,7 +519,9 @@ rte_event_queue_default_conf_get(uint8_t dev_id, uint8_t queue_id,
 static inline int
 is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
 {
-       if (queue_conf && (
+       if (queue_conf &&
+               !(queue_conf->event_queue_cfg &
+                 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) && (
                ((queue_conf->event_queue_cfg &
                        RTE_EVENT_QUEUE_CFG_TYPE_MASK)
                        == RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
@@ -535,7 +537,9 @@ is_valid_atomic_queue_conf(const struct rte_event_queue_conf *queue_conf)
 static inline int
 is_valid_ordered_queue_conf(const struct rte_event_queue_conf *queue_conf)
 {
-       if (queue_conf && (
+       if (queue_conf &&
+               !(queue_conf->event_queue_cfg &
+                 RTE_EVENT_QUEUE_CFG_SINGLE_LINK) && (
                ((queue_conf->event_queue_cfg &
                        RTE_EVENT_QUEUE_CFG_TYPE_MASK)
                        == RTE_EVENT_QUEUE_CFG_ALL_TYPES) ||
@@ -609,27 +613,6 @@ rte_event_queue_setup(uint8_t dev_id, uint8_t queue_id,
        return (*dev->dev_ops->queue_setup)(dev, queue_id, queue_conf);
 }
 
-uint8_t
-rte_event_queue_count(uint8_t dev_id)
-{
-       struct rte_eventdev *dev;
-
-       dev = &rte_eventdevs[dev_id];
-       return dev->data->nb_queues;
-}
-
-uint8_t
-rte_event_queue_priority(uint8_t dev_id, uint8_t queue_id)
-{
-       struct rte_eventdev *dev;
-
-       dev = &rte_eventdevs[dev_id];
-       if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
-               return dev->data->queues_prio[queue_id];
-       else
-               return RTE_EVENT_DEV_PRIORITY_NORMAL;
-}
-
 static inline int
 is_valid_port(struct rte_eventdev *dev, uint8_t port_id)
 {
@@ -743,31 +726,89 @@ rte_event_port_setup(uint8_t dev_id, uint8_t port_id,
        return 0;
 }
 
-uint8_t
-rte_event_port_dequeue_depth(uint8_t dev_id, uint8_t port_id)
+int
+rte_event_dev_attr_get(uint8_t dev_id, uint32_t attr_id,
+                      uint32_t *attr_value)
 {
        struct rte_eventdev *dev;
 
+       if (!attr_value)
+               return -EINVAL;
+       RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
        dev = &rte_eventdevs[dev_id];
-       return dev->data->ports_dequeue_depth[port_id];
+
+       switch (attr_id) {
+       case RTE_EVENT_DEV_ATTR_PORT_COUNT:
+               *attr_value = dev->data->nb_ports;
+               break;
+       case RTE_EVENT_DEV_ATTR_QUEUE_COUNT:
+               *attr_value = dev->data->nb_queues;
+               break;
+       case RTE_EVENT_DEV_ATTR_STARTED:
+               *attr_value = dev->data->dev_started;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
 }
 
-uint8_t
-rte_event_port_enqueue_depth(uint8_t dev_id, uint8_t port_id)
+int
+rte_event_port_attr_get(uint8_t dev_id, uint8_t port_id, uint32_t attr_id,
+                       uint32_t *attr_value)
 {
        struct rte_eventdev *dev;
 
+       if (!attr_value)
+               return -EINVAL;
+
+       RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
        dev = &rte_eventdevs[dev_id];
-       return dev->data->ports_enqueue_depth[port_id];
+       if (!is_valid_port(dev, port_id)) {
+               RTE_EDEV_LOG_ERR("Invalid port_id=%" PRIu8, port_id);
+               return -EINVAL;
+       }
+
+       switch (attr_id) {
+       case RTE_EVENT_PORT_ATTR_ENQ_DEPTH:
+               *attr_value = dev->data->ports_enqueue_depth[port_id];
+               break;
+       case RTE_EVENT_PORT_ATTR_DEQ_DEPTH:
+               *attr_value = dev->data->ports_dequeue_depth[port_id];
+               break;
+       default:
+               return -EINVAL;
+       };
+       return 0;
 }
 
-uint8_t
-rte_event_port_count(uint8_t dev_id)
+int
+rte_event_queue_attr_get(uint8_t dev_id, uint8_t queue_id, uint32_t attr_id,
+                       uint32_t *attr_value)
 {
        struct rte_eventdev *dev;
 
+       if (!attr_value)
+               return -EINVAL;
+
+       RTE_EVENTDEV_VALID_DEVID_OR_ERR_RET(dev_id, -EINVAL);
        dev = &rte_eventdevs[dev_id];
-       return dev->data->nb_ports;
+       if (!is_valid_queue(dev, queue_id)) {
+               RTE_EDEV_LOG_ERR("Invalid queue_id=%" PRIu8, queue_id);
+               return -EINVAL;
+       }
+
+       switch (attr_id) {
+       case RTE_EVENT_QUEUE_ATTR_PRIORITY:
+               *attr_value = RTE_EVENT_DEV_PRIORITY_NORMAL;
+               if (dev->data->event_dev_cap & RTE_EVENT_DEV_CAP_QUEUE_QOS)
+                       *attr_value = dev->data->queues_prio[queue_id];
+               break;
+       default:
+               return -EINVAL;
+       };
+       return 0;
 }
 
 int