NT specific flow filter API for create/destroy flow

Signed-off-by: Serhii Iliushyk <sil-...@napatech.com>
---
 drivers/net/ntnic/nthw/flow_api/flow_api.c    | 49 +++++++++++++++
 drivers/net/ntnic/ntnic_filter/ntnic_filter.c | 63 ++++++++++++++++++-
 drivers/net/ntnic/ntnic_mod_reg.h             | 14 +++++
 3 files changed, 124 insertions(+), 2 deletions(-)

diff --git a/drivers/net/ntnic/nthw/flow_api/flow_api.c 
b/drivers/net/ntnic/nthw/flow_api/flow_api.c
index f49aca79c1..776c8e4407 100644
--- a/drivers/net/ntnic/nthw/flow_api/flow_api.c
+++ b/drivers/net/ntnic/nthw/flow_api/flow_api.c
@@ -117,6 +117,50 @@ static struct flow_nic_dev 
*get_nic_dev_from_adapter_no(uint8_t adapter_no)
 
        return ndev;
 }
+/*
+ * Flow API
+ */
+
+static struct flow_handle *flow_create(struct flow_eth_dev *dev,
+       const struct rte_flow_attr *attr,
+       uint16_t forced_vlan_vid,
+       uint16_t caller_id,
+       const struct rte_flow_item item[],
+       const struct rte_flow_action action[],
+       struct rte_flow_error *error)
+{
+       (void)dev;
+       (void)attr;
+       (void)forced_vlan_vid;
+       (void)caller_id;
+       (void)item;
+       (void)action;
+       (void)error;
+       const struct profile_inline_ops *profile_inline_ops = 
get_profile_inline_ops();
+
+       if (profile_inline_ops == NULL) {
+               NT_LOG(ERR, FILTER, "%s: profile_inline module uninitialized", 
__func__);
+               return NULL;
+       }
+
+       return NULL;
+}
+
+static int flow_destroy(struct flow_eth_dev *dev, struct flow_handle *flow,
+       struct rte_flow_error *error)
+{
+       (void)dev;
+       (void)flow;
+       (void)error;
+       const struct profile_inline_ops *profile_inline_ops = 
get_profile_inline_ops();
+
+       if (profile_inline_ops == NULL) {
+               NT_LOG(ERR, FILTER, "%s: profile_inline module uninitialized", 
__func__);
+               return -1;
+       }
+
+       return -1;
+}
 
 /*
  * Device Management API
@@ -604,6 +648,11 @@ static const struct flow_filter_ops ops = {
         * Device Management API
         */
        .flow_get_eth_dev = flow_get_eth_dev,
+       /*
+        * NT Flow API
+        */
+       .flow_create = flow_create,
+       .flow_destroy = flow_destroy,
 };
 
 void init_flow_filter(void)
diff --git a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c 
b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c
index 816ab0cd5c..83ca52a2ad 100644
--- a/drivers/net/ntnic/ntnic_filter/ntnic_filter.c
+++ b/drivers/net/ntnic/ntnic_filter/ntnic_filter.c
@@ -114,6 +114,13 @@ static inline uint16_t get_caller_id(uint16_t port)
        return MAX_VDPA_PORTS + port + 1;
 }
 
+static int is_flow_handle_typecast(struct rte_flow *flow)
+{
+       const void *first_element = &nt_flows[0];
+       const void *last_element = &nt_flows[MAX_RTE_FLOWS - 1];
+       return (void *)flow < first_element || (void *)flow > last_element;
+}
+
 static int convert_flow(struct rte_eth_dev *eth_dev,
        const struct rte_flow_attr *attr,
        const struct rte_flow_item items[],
@@ -179,7 +186,14 @@ static int convert_flow(struct rte_eth_dev *eth_dev,
 static int
 eth_flow_destroy(struct rte_eth_dev *eth_dev, struct rte_flow *flow, struct 
rte_flow_error *error)
 {
-       (void)eth_dev;
+       const struct flow_filter_ops *flow_filter_ops = get_flow_filter_ops();
+
+       if (flow_filter_ops == NULL) {
+               NT_LOG_DBGX(ERR, FILTER, "flow_filter module uninitialized");
+               return -1;
+       }
+
+       struct pmd_internals *internals = (struct pmd_internals 
*)eth_dev->data->dev_private;
 
        static struct rte_flow_error flow_error = {
                .type = RTE_FLOW_ERROR_TYPE_NONE, .message = "none" };
@@ -190,6 +204,20 @@ eth_flow_destroy(struct rte_eth_dev *eth_dev, struct 
rte_flow *flow, struct rte_
        if (!flow)
                return 0;
 
+       if (is_flow_handle_typecast(flow)) {
+               res = flow_filter_ops->flow_destroy(internals->flw_dev, (void 
*)flow, &flow_error);
+               convert_error(error, &flow_error);
+
+       } else {
+               res = flow_filter_ops->flow_destroy(internals->flw_dev, 
flow->flw_hdl,
+                       &flow_error);
+               convert_error(error, &flow_error);
+
+               rte_spinlock_lock(&flow_lock);
+               flow->used = 0;
+               rte_spinlock_unlock(&flow_lock);
+       }
+
        return res;
 }
 
@@ -199,6 +227,13 @@ static struct rte_flow *eth_flow_create(struct rte_eth_dev 
*eth_dev,
        const struct rte_flow_action actions[],
        struct rte_flow_error *error)
 {
+       const struct flow_filter_ops *flow_filter_ops = get_flow_filter_ops();
+
+       if (flow_filter_ops == NULL) {
+               NT_LOG_DBGX(ERR, FILTER, "flow_filter module uninitialized");
+               return NULL;
+       }
+
        struct pmd_internals *internals = (struct pmd_internals 
*)eth_dev->data->dev_private;
 
        struct fpga_info_s *fpga_info = 
&internals->p_drv->ntdrv.adapter_info.fpga_info;
@@ -218,8 +253,12 @@ static struct rte_flow *eth_flow_create(struct rte_eth_dev 
*eth_dev,
        attribute.caller_id = get_caller_id(eth_dev->data->port_id);
 
        if (fpga_info->profile == FPGA_INFO_PROFILE_INLINE && 
attribute.attr.group > 0) {
+               void *flw_hdl = 
flow_filter_ops->flow_create(internals->flw_dev, &attribute.attr,
+                       attribute.forced_vlan_vid, attribute.caller_id,
+                       match.rte_flow_item, action.flow_actions,
+                       &flow_error);
                convert_error(error, &flow_error);
-               return (struct rte_flow *)NULL;
+               return (struct rte_flow *)flw_hdl;
        }
 
        struct rte_flow *flow = NULL;
@@ -241,6 +280,26 @@ static struct rte_flow *eth_flow_create(struct rte_eth_dev 
*eth_dev,
 
        rte_spinlock_unlock(&flow_lock);
 
+       if (flow) {
+               flow->flw_hdl = 
flow_filter_ops->flow_create(internals->flw_dev, &attribute.attr,
+                       attribute.forced_vlan_vid, attribute.caller_id,
+                       match.rte_flow_item, action.flow_actions,
+                       &flow_error);
+               convert_error(error, &flow_error);
+
+               if (!flow->flw_hdl) {
+                       rte_spinlock_lock(&flow_lock);
+                       flow->used = 0;
+                       flow = NULL;
+                       rte_spinlock_unlock(&flow_lock);
+
+               } else {
+                       rte_spinlock_lock(&flow_lock);
+                       flow->caller_id = attribute.caller_id;
+                       rte_spinlock_unlock(&flow_lock);
+               }
+       }
+
        return flow;
 }
 
diff --git a/drivers/net/ntnic/ntnic_mod_reg.h 
b/drivers/net/ntnic/ntnic_mod_reg.h
index 457dc58794..ec8c1612d1 100644
--- a/drivers/net/ntnic/ntnic_mod_reg.h
+++ b/drivers/net/ntnic/ntnic_mod_reg.h
@@ -242,6 +242,20 @@ struct flow_filter_ops {
                int *rss_target_id,
                enum flow_eth_dev_profile flow_profile,
                uint32_t exception_path);
+       /*
+        * NT Flow API
+        */
+       struct flow_handle *(*flow_create)(struct flow_eth_dev *dev,
+               const struct rte_flow_attr *attr,
+               uint16_t forced_vlan_vid,
+               uint16_t caller_id,
+               const struct rte_flow_item item[],
+               const struct rte_flow_action action[],
+               struct rte_flow_error *error);
+
+       int (*flow_destroy)(struct flow_eth_dev *dev,
+               struct flow_handle *flow,
+               struct rte_flow_error *error);
 };
 
 void register_dev_flow_ops(const struct rte_flow_ops *ops);
-- 
2.45.0

Reply via email to