net/softnic: add table action profile
authorJasvinder Singh <jasvinder.singh@intel.com>
Fri, 6 Jul 2018 17:21:01 +0000 (18:21 +0100)
committerCristian Dumitrescu <cristian.dumitrescu@intel.com>
Thu, 12 Jul 2018 11:51:00 +0000 (13:51 +0200)
Add pipeline's table action profile implementation to the softnic.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
drivers/net/softnic/rte_eth_softnic.c
drivers/net/softnic/rte_eth_softnic_action.c
drivers/net/softnic/rte_eth_softnic_internals.h

index 0f010c8..cd0e02b 100644 (file)
@@ -236,6 +236,7 @@ pmd_init(struct pmd_params *params)
        softnic_tmgr_init(p);
        softnic_tap_init(p);
        softnic_port_in_action_profile_init(p);
+       softnic_table_action_profile_init(p);
 
        return p;
 }
@@ -246,6 +247,7 @@ pmd_free(struct pmd_internals *p)
        if (p == NULL)
                return;
 
+       softnic_table_action_profile_free(p);
        softnic_port_in_action_profile_free(p);
        softnic_tap_free(p);
        softnic_tmgr_free(p);
index acc0f79..c25f4dd 100644 (file)
@@ -160,3 +160,230 @@ softnic_port_in_action_profile_create(struct pmd_internals *p,
 
        return profile;
 }
+
+/**
+ * Table
+ */
+int
+softnic_table_action_profile_init(struct pmd_internals *p)
+{
+       TAILQ_INIT(&p->table_action_profile_list);
+
+       return 0;
+}
+
+void
+softnic_table_action_profile_free(struct pmd_internals *p)
+{
+       for ( ; ; ) {
+               struct softnic_table_action_profile *profile;
+
+               profile = TAILQ_FIRST(&p->table_action_profile_list);
+               if (profile == NULL)
+                       break;
+
+               TAILQ_REMOVE(&p->table_action_profile_list, profile, node);
+               free(profile);
+       }
+}
+
+struct softnic_table_action_profile *
+softnic_table_action_profile_find(struct pmd_internals *p,
+       const char *name)
+{
+       struct softnic_table_action_profile *profile;
+
+       if (name == NULL)
+               return NULL;
+
+       TAILQ_FOREACH(profile, &p->table_action_profile_list, node)
+               if (strcmp(profile->name, name) == 0)
+                       return profile;
+
+       return NULL;
+}
+
+struct softnic_table_action_profile *
+softnic_table_action_profile_create(struct pmd_internals *p,
+       const char *name,
+       struct softnic_table_action_profile_params *params)
+{
+       struct softnic_table_action_profile *profile;
+       struct rte_table_action_profile *ap;
+       int status;
+
+       /* Check input params */
+       if (name == NULL ||
+               softnic_table_action_profile_find(p, name) ||
+               params == NULL ||
+               ((params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) == 0))
+               return NULL;
+
+       if ((params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) &&
+               params->lb.f_hash == NULL) {
+               switch (params->lb.key_size) {
+               case 8:
+                       params->lb.f_hash = hash_default_key8;
+                       break;
+
+               case 16:
+                       params->lb.f_hash = hash_default_key16;
+                       break;
+
+               case 24:
+                       params->lb.f_hash = hash_default_key24;
+                       break;
+
+               case 32:
+                       params->lb.f_hash = hash_default_key32;
+                       break;
+
+               case 40:
+                       params->lb.f_hash = hash_default_key40;
+                       break;
+
+               case 48:
+                       params->lb.f_hash = hash_default_key48;
+                       break;
+
+               case 56:
+                       params->lb.f_hash = hash_default_key56;
+                       break;
+
+               case 64:
+                       params->lb.f_hash = hash_default_key64;
+                       break;
+
+               default:
+                       return NULL;
+               }
+
+               params->lb.seed = 0;
+       }
+
+       /* Resource */
+       ap = rte_table_action_profile_create(&params->common);
+       if (ap == NULL)
+               return NULL;
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_FWD)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_FWD,
+                       NULL);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_LB)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_LB,
+                       &params->lb);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_MTR)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_MTR,
+                       &params->mtr);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TM)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_TM,
+                       &params->tm);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_ENCAP)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_ENCAP,
+                       &params->encap);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_NAT)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_NAT,
+                       &params->nat);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TTL)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_TTL,
+                       &params->ttl);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_STATS)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_STATS,
+                       &params->stats);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+       if (params->action_mask & (1LLU << RTE_TABLE_ACTION_TIME)) {
+               status = rte_table_action_profile_action_register(ap,
+                       RTE_TABLE_ACTION_TIME,
+                       NULL);
+
+               if (status) {
+                       rte_table_action_profile_free(ap);
+                       return NULL;
+               }
+       }
+
+       status = rte_table_action_profile_freeze(ap);
+       if (status) {
+               rte_table_action_profile_free(ap);
+               return NULL;
+       }
+
+       /* Node allocation */
+       profile = calloc(1, sizeof(struct softnic_table_action_profile));
+       if (profile == NULL) {
+               rte_table_action_profile_free(ap);
+               return NULL;
+       }
+
+       /* Node fill in */
+       strlcpy(profile->name, name, sizeof(profile->name));
+       memcpy(&profile->params, params, sizeof(*params));
+       profile->ap = ap;
+
+       /* Node add to list */
+       TAILQ_INSERT_TAIL(&p->table_action_profile_list, profile, node);
+
+       return profile;
+}
index bbf299e..a1ebced 100644 (file)
@@ -15,6 +15,7 @@
 #include <rte_ethdev.h>
 #include <rte_sched.h>
 #include <rte_port_in_action.h>
+#include <rte_table_action.h>
 #include <rte_ethdev_driver.h>
 #include <rte_tm_driver.h>
 
@@ -238,6 +239,30 @@ struct softnic_port_in_action_profile {
 
 TAILQ_HEAD(softnic_port_in_action_profile_list, softnic_port_in_action_profile);
 
+/**
+ * Table action
+ */
+struct softnic_table_action_profile_params {
+       uint64_t action_mask;
+       struct rte_table_action_common_config common;
+       struct rte_table_action_lb_config lb;
+       struct rte_table_action_mtr_config mtr;
+       struct rte_table_action_tm_config tm;
+       struct rte_table_action_encap_config encap;
+       struct rte_table_action_nat_config nat;
+       struct rte_table_action_ttl_config ttl;
+       struct rte_table_action_stats_config stats;
+};
+
+struct softnic_table_action_profile {
+       TAILQ_ENTRY(softnic_table_action_profile) node;
+       char name[NAME_SIZE];
+       struct softnic_table_action_profile_params params;
+       struct rte_table_action_profile *ap;
+};
+
+TAILQ_HEAD(softnic_table_action_profile_list, softnic_table_action_profile);
+
 /**
  * PMD Internals
  */
@@ -255,6 +280,7 @@ struct pmd_internals {
        struct softnic_tmgr_port_list tmgr_port_list;
        struct softnic_tap_list tap_list;
        struct softnic_port_in_action_profile_list port_in_action_profile_list;
+       struct softnic_table_action_profile_list table_action_profile_list;
 };
 
 /**
@@ -386,4 +412,22 @@ softnic_port_in_action_profile_create(struct pmd_internals *p,
        const char *name,
        struct softnic_port_in_action_profile_params *params);
 
+/**
+ * Table action
+ */
+int
+softnic_table_action_profile_init(struct pmd_internals *p);
+
+void
+softnic_table_action_profile_free(struct pmd_internals *p);
+
+struct softnic_table_action_profile *
+softnic_table_action_profile_find(struct pmd_internals *p,
+       const char *name);
+
+struct softnic_table_action_profile *
+softnic_table_action_profile_create(struct pmd_internals *p,
+       const char *name,
+       struct softnic_table_action_profile_params *params);
+
 #endif /* __INCLUDE_RTE_ETH_SOFTNIC_INTERNALS_H__ */