ethdev: add shared actions to flow API
[dpdk.git] / lib / librte_ethdev / rte_flow.c
index 1b0370f..4ee802a 100644 (file)
@@ -175,6 +175,13 @@ static const struct rte_flow_desc_data rte_flow_desc_action[] = {
        MK_FLOW_ACTION(SET_IPV6_DSCP, sizeof(struct rte_flow_action_set_dscp)),
        MK_FLOW_ACTION(AGE, sizeof(struct rte_flow_action_age)),
        MK_FLOW_ACTION(SAMPLE, sizeof(struct rte_flow_action_sample)),
+       /**
+        * Shared action represented as handle of type
+        * (struct rte_flow_shared action *) stored in conf field (see
+        * struct rte_flow_action); no need for additional structure to * store
+        * shared action handle.
+        */
+       MK_FLOW_ACTION(SHARED, 0),
 };
 
 int
@@ -1036,3 +1043,86 @@ rte_flow_get_aged_flows(uint16_t port_id, void **contexts,
                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
                                  NULL, rte_strerror(ENOTSUP));
 }
+
+struct rte_flow_shared_action *
+rte_flow_shared_action_create(uint16_t port_id,
+                             const struct rte_flow_shared_action_conf *conf,
+                             const struct rte_flow_action *action,
+                             struct rte_flow_error *error)
+{
+       struct rte_flow_shared_action *shared_action;
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return NULL;
+       if (unlikely(!ops->shared_action_create)) {
+               rte_flow_error_set(error, ENOSYS,
+                                  RTE_FLOW_ERROR_TYPE_UNSPECIFIED, NULL,
+                                  rte_strerror(ENOSYS));
+               return NULL;
+       }
+       shared_action = ops->shared_action_create(&rte_eth_devices[port_id],
+                                                 conf, action, error);
+       if (shared_action == NULL)
+               flow_err(port_id, -rte_errno, error);
+       return shared_action;
+}
+
+int
+rte_flow_shared_action_destroy(uint16_t port_id,
+                             struct rte_flow_shared_action *action,
+                             struct rte_flow_error *error)
+{
+       int ret;
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (unlikely(!ops->shared_action_destroy))
+               return rte_flow_error_set(error, ENOSYS,
+                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         NULL, rte_strerror(ENOSYS));
+       ret = ops->shared_action_destroy(&rte_eth_devices[port_id], action,
+                                        error);
+       return flow_err(port_id, ret, error);
+}
+
+int
+rte_flow_shared_action_update(uint16_t port_id,
+                             struct rte_flow_shared_action *action,
+                             const struct rte_flow_action *update,
+                             struct rte_flow_error *error)
+{
+       int ret;
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (unlikely(!ops->shared_action_update))
+               return rte_flow_error_set(error, ENOSYS,
+                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         NULL, rte_strerror(ENOSYS));
+       ret = ops->shared_action_update(&rte_eth_devices[port_id], action,
+                                       update, error);
+       return flow_err(port_id, ret, error);
+}
+
+int
+rte_flow_shared_action_query(uint16_t port_id,
+                            const struct rte_flow_shared_action *action,
+                            void *data,
+                            struct rte_flow_error *error)
+{
+       int ret;
+       const struct rte_flow_ops *ops = rte_flow_ops_get(port_id, error);
+
+       if (unlikely(!ops))
+               return -rte_errno;
+       if (unlikely(!ops->shared_action_query))
+               return rte_flow_error_set(error, ENOSYS,
+                                         RTE_FLOW_ERROR_TYPE_UNSPECIFIED,
+                                         NULL, rte_strerror(ENOSYS));
+       ret = ops->shared_action_query(&rte_eth_devices[port_id], action,
+                                      data, error);
+       return flow_err(port_id, ret, error);
+}