net/softnic: get eth device
[dpdk.git] / drivers / net / softnic / rte_eth_softnic_internals.h
index d459571..1857ec5 100644 (file)
 #include <rte_table_action.h>
 #include <rte_pipeline.h>
 
+#include <rte_ethdev_core.h>
 #include <rte_ethdev_driver.h>
 #include <rte_tm_driver.h>
+#include <rte_flow_driver.h>
 
 #include "rte_eth_softnic.h"
+#include "conn.h"
 
 #define NAME_SIZE                                            64
 
@@ -32,6 +35,7 @@
 struct pmd_params {
        const char *name;
        const char *firmware;
+       uint16_t conn_port;
        uint32_t cpu_id;
 
        /** Traffic Management (TM) */
@@ -41,6 +45,28 @@ struct pmd_params {
        } tm;
 };
 
+/**
+ * Ethdev Flow API
+ */
+struct rte_flow;
+
+TAILQ_HEAD(flow_list, rte_flow);
+
+struct flow_attr_map {
+       char pipeline_name[NAME_SIZE];
+       uint32_t table_id;
+       int valid;
+};
+
+#ifndef SOFTNIC_FLOW_MAX_GROUPS
+#define SOFTNIC_FLOW_MAX_GROUPS                            64
+#endif
+
+struct flow_internals {
+       struct flow_attr_map ingress_map[SOFTNIC_FLOW_MAX_GROUPS];
+       struct flow_attr_map egress_map[SOFTNIC_FLOW_MAX_GROUPS];
+};
+
 /**
  * MEMPOOL
  */
@@ -201,7 +227,6 @@ struct tm_internals {
 
        /** Blueprints */
        struct tm_params params;
-       struct rte_sched_port *sched;
 };
 
 struct softnic_tmgr_port {
@@ -284,7 +309,7 @@ enum softnic_port_in_type {
 struct softnic_port_in_params {
        /* Read */
        enum softnic_port_in_type type;
-       const char *dev_name;
+       char dev_name[NAME_SIZE];
        union {
                struct {
                        uint16_t queue_id;
@@ -304,7 +329,7 @@ struct softnic_port_in_params {
        uint32_t burst_size;
 
        /* Action */
-       const char *action_profile_name;
+       char action_profile_name[NAME_SIZE];
 };
 
 enum softnic_port_out_type {
@@ -317,7 +342,7 @@ enum softnic_port_out_type {
 
 struct softnic_port_out_params {
        enum softnic_port_out_type type;
-       const char *dev_name;
+       char dev_name[NAME_SIZE];
        union {
                struct {
                        uint16_t queue_id;
@@ -352,11 +377,15 @@ struct softnic_table_array_params {
        uint32_t key_offset;
 };
 
+#ifndef TABLE_RULE_MATCH_SIZE_MAX
+#define TABLE_RULE_MATCH_SIZE_MAX                          256
+#endif
+
 struct softnic_table_hash_params {
        uint32_t n_keys;
        uint32_t key_offset;
        uint32_t key_size;
-       uint8_t *key_mask;
+       uint8_t key_mask[TABLE_RULE_MATCH_SIZE_MAX];
        uint32_t n_buckets;
        int extendable_bucket;
 };
@@ -378,7 +407,7 @@ struct softnic_table_params {
        } match;
 
        /* Action */
-       const char *action_profile_name;
+       char action_profile_name[NAME_SIZE];
 };
 
 struct softnic_port_in {
@@ -387,10 +416,15 @@ struct softnic_port_in {
        struct rte_port_in_action *a;
 };
 
+struct softnic_port_out {
+       struct softnic_port_out_params params;
+};
+
 struct softnic_table {
        struct softnic_table_params params;
        struct softnic_table_action_profile *ap;
        struct rte_table_action *a;
+       struct flow_list flows;
 };
 
 struct pipeline {
@@ -398,7 +432,9 @@ struct pipeline {
        char name[NAME_SIZE];
 
        struct rte_pipeline *p;
+       struct pipeline_params params;
        struct softnic_port_in port_in[RTE_PIPELINE_PORT_IN_MAX];
+       struct softnic_port_out port_out[RTE_PIPELINE_PORT_OUT_MAX];
        struct softnic_table table[RTE_PIPELINE_TABLE_MAX];
        uint32_t n_ports_in;
        uint32_t n_ports_out;
@@ -488,6 +524,8 @@ struct pmd_internals {
                struct tm_internals tm; /**< Traffic Management */
        } soft;
 
+       struct flow_internals flow;
+       struct softnic_conn *conn;
        struct softnic_mempool_list mempool_list;
        struct softnic_swq_list swq_list;
        struct softnic_link_list link_list;
@@ -500,6 +538,37 @@ struct pmd_internals {
        struct softnic_thread_data thread_data[RTE_MAX_LCORE];
 };
 
+static inline struct rte_eth_dev *
+ETHDEV(struct pmd_internals *softnic)
+{
+       uint16_t port_id;
+       int status;
+
+       if (softnic == NULL)
+               return NULL;
+
+       status = rte_eth_dev_get_port_by_name(softnic->params.name, &port_id);
+       if (status)
+               return NULL;
+
+       return &rte_eth_devices[port_id];
+}
+
+/**
+ * Ethdev Flow API
+ */
+int
+flow_attr_map_set(struct pmd_internals *softnic,
+               uint32_t group_id,
+               int ingress,
+               const char *pipeline_name,
+               uint32_t table_id);
+
+struct flow_attr_map *
+flow_attr_map_get(struct pmd_internals *softnic,
+               uint32_t group_id,
+               int ingress);
+
 /**
  * MEMPOOL
  */
@@ -527,6 +596,9 @@ softnic_swq_init(struct pmd_internals *p);
 void
 softnic_swq_free(struct pmd_internals *p);
 
+void
+softnic_softnic_swq_free_keep_rxq_txq(struct pmd_internals *p);
+
 struct softnic_swq *
 softnic_swq_find(struct pmd_internals *p,
        const char *name);
@@ -569,20 +641,13 @@ softnic_tmgr_port_find(struct pmd_internals *p,
 
 struct softnic_tmgr_port *
 softnic_tmgr_port_create(struct pmd_internals *p,
-       const char *name,
-       struct rte_sched_port *sched);
-
-int
-tm_init(struct pmd_internals *p);
+       const char *name);
 
 void
-tm_free(struct pmd_internals *p);
-
-int
-tm_start(struct pmd_internals *p);
+tm_hierarchy_init(struct pmd_internals *p);
 
 void
-tm_stop(struct pmd_internals *p);
+tm_hierarchy_free(struct pmd_internals *p);
 
 static inline int
 tm_used(struct rte_eth_dev *dev)
@@ -656,6 +721,9 @@ softnic_pipeline_init(struct pmd_internals *p);
 void
 softnic_pipeline_free(struct pmd_internals *p);
 
+void
+softnic_pipeline_disable_all(struct pmd_internals *p);
+
 struct pipeline *
 softnic_pipeline_find(struct pmd_internals *p, const char *name);
 
@@ -681,11 +749,208 @@ softnic_pipeline_port_out_create(struct pmd_internals *p,
        const char *pipeline_name,
        struct softnic_port_out_params *params);
 
+int
+softnic_pipeline_port_out_find(struct pmd_internals *softnic,
+               const char *pipeline_name,
+               const char *name,
+               uint32_t *port_id);
+
 int
 softnic_pipeline_table_create(struct pmd_internals *p,
        const char *pipeline_name,
        struct softnic_table_params *params);
 
+struct softnic_table_rule_match_acl {
+       int ip_version;
+
+       RTE_STD_C11
+       union {
+               struct {
+                       uint32_t sa;
+                       uint32_t da;
+               } ipv4;
+
+               struct {
+                       uint8_t sa[16];
+                       uint8_t da[16];
+               } ipv6;
+       };
+
+       uint32_t sa_depth;
+       uint32_t da_depth;
+       uint16_t sp0;
+       uint16_t sp1;
+       uint16_t dp0;
+       uint16_t dp1;
+       uint8_t proto;
+       uint8_t proto_mask;
+       uint32_t priority;
+};
+
+struct softnic_table_rule_match_array {
+       uint32_t pos;
+};
+
+struct softnic_table_rule_match_hash {
+       uint8_t key[TABLE_RULE_MATCH_SIZE_MAX];
+};
+
+struct softnic_table_rule_match_lpm {
+       int ip_version;
+
+       RTE_STD_C11
+       union {
+               uint32_t ipv4;
+               uint8_t ipv6[16];
+       };
+
+       uint8_t depth;
+};
+
+struct softnic_table_rule_match {
+       enum softnic_table_type match_type;
+
+       union {
+               struct softnic_table_rule_match_acl acl;
+               struct softnic_table_rule_match_array array;
+               struct softnic_table_rule_match_hash hash;
+               struct softnic_table_rule_match_lpm lpm;
+       } match;
+};
+
+struct softnic_table_rule_action {
+       uint64_t action_mask;
+       struct rte_table_action_fwd_params fwd;
+       struct rte_table_action_lb_params lb;
+       struct rte_table_action_mtr_params mtr;
+       struct rte_table_action_tm_params tm;
+       struct rte_table_action_encap_params encap;
+       struct rte_table_action_nat_params nat;
+       struct rte_table_action_ttl_params ttl;
+       struct rte_table_action_stats_params stats;
+       struct rte_table_action_time_params time;
+};
+
+struct rte_flow {
+       TAILQ_ENTRY(rte_flow) node;
+       struct softnic_table_rule_match match;
+       struct softnic_table_rule_action action;
+       void *data;
+       struct pipeline *pipeline;
+       uint32_t table_id;
+};
+
+int
+softnic_pipeline_port_in_stats_read(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t port_id,
+       struct rte_pipeline_port_in_stats *stats,
+       int clear);
+
+int
+softnic_pipeline_port_in_enable(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t port_id);
+
+int
+softnic_pipeline_port_in_disable(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t port_id);
+
+int
+softnic_pipeline_port_out_stats_read(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t port_id,
+       struct rte_pipeline_port_out_stats *stats,
+       int clear);
+
+int
+softnic_pipeline_table_stats_read(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       struct rte_pipeline_table_stats *stats,
+       int clear);
+
+int
+softnic_pipeline_table_rule_add(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       struct softnic_table_rule_match *match,
+       struct softnic_table_rule_action *action,
+       void **data);
+
+int
+softnic_pipeline_table_rule_add_bulk(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       struct softnic_table_rule_match *match,
+       struct softnic_table_rule_action *action,
+       void **data,
+       uint32_t *n_rules);
+
+int
+softnic_pipeline_table_rule_add_default(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       struct softnic_table_rule_action *action,
+       void **data);
+
+int
+softnic_pipeline_table_rule_delete(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       struct softnic_table_rule_match *match);
+
+int
+softnic_pipeline_table_rule_delete_default(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id);
+
+int
+softnic_pipeline_table_rule_stats_read(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       void *data,
+       struct rte_table_action_stats_counters *stats,
+       int clear);
+
+int
+softnic_pipeline_table_mtr_profile_add(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       uint32_t meter_profile_id,
+       struct rte_table_action_meter_profile *profile);
+
+int
+softnic_pipeline_table_mtr_profile_delete(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       uint32_t meter_profile_id);
+
+int
+softnic_pipeline_table_rule_mtr_read(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       void *data,
+       uint32_t tc_mask,
+       struct rte_table_action_mtr_counters *stats,
+       int clear);
+
+int
+softnic_pipeline_table_dscp_table_update(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       uint64_t dscp_mask,
+       struct rte_table_action_dscp_table *dscp_table);
+
+int
+softnic_pipeline_table_rule_ttl_read(struct pmd_internals *p,
+       const char *pipeline_name,
+       uint32_t table_id,
+       void *data,
+       struct rte_table_action_ttl_counters *stats,
+       int clear);
+
 /**
  * Thread
  */
@@ -695,6 +960,16 @@ softnic_thread_init(struct pmd_internals *p);
 void
 softnic_thread_free(struct pmd_internals *p);
 
+int
+softnic_thread_pipeline_enable(struct pmd_internals *p,
+       uint32_t thread_id,
+       const char *pipeline_name);
+
+int
+softnic_thread_pipeline_disable(struct pmd_internals *p,
+       uint32_t thread_id,
+       const char *pipeline_name);
+
 /**
  * CLI
  */