tpm: export vlan and ethertype.

Export the following rules in yaml format:

- l2 key for vlan and ethertype.
- vlan rule.

The original tpm db does not record the rule type. This CL added rule
type so that it is easier to review the rules that are added.

Change-Id: I1e9d673aef9a2fdcf8e1adb4b323266d795d504b
diff --git a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_rule_db.c b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_rule_db.c
index cdb9456..fbaa8ab 100755
--- a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_rule_db.c
+++ b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_rule_db.c
@@ -1541,6 +1541,7 @@
             else
             {
                 strcpy(pentry->name, name);
+                pentry->l2_key_type = l2_key_type_ethertype;
                 pentry->l2_acl.ether_type  = (uint16_t)temp_ety;
             }
         }
@@ -1600,6 +1601,7 @@
             else
             {
                 strcpy(pentry->name, name);
+                pentry->l2_key_type = l2_key_type_gemport;
                 pentry->l2_acl.gem_port  = (uint16_t)temp_gemport;
             }
         }
@@ -1678,6 +1680,7 @@
             else
             {
                 strcpy(pentry->name, name);
+                pentry->l2_key_type = l2_key_type_macaddr;
                 pentry->l2_acl.mac.mac_sa[0] = (uint8_t)sa[0]; pentry->l2_acl.mac.mac_sa[1] = (uint8_t)sa[1]; pentry->l2_acl.mac.mac_sa[2] = (uint8_t)sa[2];
                 pentry->l2_acl.mac.mac_sa[3] = (uint8_t)sa[3]; pentry->l2_acl.mac.mac_sa[4] = (uint8_t)sa[4]; pentry->l2_acl.mac.mac_sa[5] = (uint8_t)sa[5];
 
@@ -1752,6 +1755,7 @@
             else
             {
                 strcpy(pentry->name, name);
+                pentry->l2_key_type = l2_key_type_pppoe;
                 pentry->l2_acl.pppoe_hdr.ppp_session = (uint16_t)temp_session;
                 pentry->l2_acl.pppoe_hdr.ppp_proto   = (uint16_t)temp_prototype;
             }
@@ -1819,6 +1823,9 @@
             else
             {
                 strcpy(pentry->name, name);
+                strcpy(pentry->vlan_rule1, vlan1_name);
+                strcpy(pentry->vlan_rule2, vlan2_name);
+                pentry->l2_key_type = l2_key_type_vlan;
 
                 if (pvlan1entry != 0)
                 {
diff --git a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_setup.c b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_setup.c
index 45274ac..c815087 100755
--- a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_setup.c
+++ b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_setup.c
@@ -309,8 +309,11 @@
     {"help_mac_learn_def_act_set",   sfs_help_mac_learn_def_act_set},
 
     {"show_frwd_rule",               sfs_show_frwd_rule},
+    {"show_l2_key_ethertype",        sfs_show_l2_key_ethertype},
     {"show_l2_key_mac_addr",         sfs_show_l2_key_mac_addr},
+    {"show_l2_key_vlan",             sfs_show_l2_key_vlan},
     {"show_l2_rule",                 sfs_show_l2_rule},
+    {"show_vlan_rule",               sfs_show_vlan_rule},
 };
 static int num_show_name_funcs = sizeof(show_sysfs_name_func_ara)/sizeof(show_sysfs_name_func_ara[0]);
 
@@ -410,12 +413,14 @@
 
 /* sysfs for dumping forwarding table in yaml. */
 static DEVICE_ATTR(show_frwd_rule,                                  S_IRUSR, tpm_cfg_show, NULL);
+static DEVICE_ATTR(show_l2_key_ethertype,                           S_IRUSR, tpm_cfg_show, NULL);
 static DEVICE_ATTR(show_l2_key_mac_addr,                            S_IRUSR, tpm_cfg_show, NULL);
+static DEVICE_ATTR(show_l2_key_vlan,                                S_IRUSR, tpm_cfg_show, NULL);
 static DEVICE_ATTR(show_l2_rule,                                    S_IRUSR, tpm_cfg_show, NULL);
+static DEVICE_ATTR(show_vlan_rule,                                  S_IRUSR, tpm_cfg_show, NULL);
 
 // rule set
 static DEVICE_ATTR(frwd_rule_set,                                   S_IWUSR, tpm_cfg_show, tpm_cfg_store);
-
 static DEVICE_ATTR(vlan_rule_set,                                   S_IWUSR, tpm_cfg_show, tpm_cfg_store);
 static DEVICE_ATTR(mod_mh_rule_set,                                 S_IWUSR, tpm_cfg_show, tpm_cfg_store);
 static DEVICE_ATTR(mod_vlan_rule_set,                               S_IWUSR, tpm_cfg_show, tpm_cfg_store);
@@ -630,7 +635,9 @@
     &dev_attr_help_mac_learn_rule_add.attr,
     &dev_attr_help_mac_learn_def_act_set.attr,
 #endif /* CONFIG_MV_TPM_SYSFS_HELP */
+    &dev_attr_show_l2_key_ethertype.attr,
     &dev_attr_show_l2_key_mac_addr.attr,
+    &dev_attr_show_l2_key_vlan.attr,
     &dev_attr_show_l2_rule.attr,
 
     &dev_attr_l2_key_ethertype_rule_set.attr,
@@ -848,6 +855,7 @@
     &dev_attr_help_rule_table_display.attr,
     &dev_attr_help_delete_entry_rule_table.attr,
 #endif /* CONFIG_MV_TPM_SYSFS_HELP */
+    &dev_attr_show_vlan_rule.attr,
 
     &dev_attr_vlan_rule_set.attr,
 
@@ -1100,7 +1108,6 @@
 #endif /* CONFIG_MV_TPM_SYSFS_HELP */
 
     &dev_attr_frwd_rule_set.attr,
-
     &dev_attr_vlan_rule_set.attr,
     &dev_attr_mod_vlan_rule_set.attr,
     &dev_attr_mod_ipv4_addr_rule_set.attr,
diff --git a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.c b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.c
index 55c2284..4928ca4 100755
--- a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.c
+++ b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.c
@@ -1937,7 +1937,8 @@
 
 int sfs_show_frwd_rule (char *buf)
 {
-    tpmcfg_frwd_entry_t *pentry = (tpmcfg_frwd_entry_t *)tpm_frwd_rule_db.entryAra;
+    tpmcfg_frwd_entry_t *pentry =
+        (tpmcfg_frwd_entry_t *)tpm_frwd_rule_db.entryAra;
     int                 indx;
     int                 off = 0;
 
@@ -1955,6 +1956,24 @@
     return off;
 }
 
+int sfs_show_l2_key_ethertype (char *buf)
+{
+    tpmcfg_l2_key_entry_t *pentry = (tpmcfg_l2_key_entry_t *)tpm_l2_key_db.entryAra;
+    int                   indx;
+    int                   off = 0;
+
+    for (indx = 0; indx < tpm_l2_key_db.max_num_entries; indx++, pentry++)
+    {
+        if (pentry->name[0] != 0 && l2_key_type_ethertype == pentry->l2_key_type)
+        {
+            off += sprintf(buf+off, "--- !L2KeyEtherType\n");
+            off += sprintf(buf+off, "rule_name: %s\n", pentry->name);
+            off += sprintf(buf+off, "ethertype: 0x%x\n", pentry->l2_acl.ether_type);
+        }
+    }
+    return off;
+}
+
 int sfs_show_l2_key_mac_addr (char *buf)
 {
     tpmcfg_l2_key_entry_t *pentry = (tpmcfg_l2_key_entry_t *)tpm_l2_key_db.entryAra;
@@ -1967,7 +1986,7 @@
 
     for (indx = 0; indx < tpm_l2_key_db.max_num_entries; indx++, pentry++)
     {
-        if (pentry->name[0] != 0)
+        if (pentry->name[0] != 0 && l2_key_type_macaddr == pentry->l2_key_type)
         {
             off += sprintf(buf+off, "--- !L2KeyMacAddr\n");
             format_mac_addr(pentry->l2_acl.mac.mac_da, d1);
@@ -1984,6 +2003,53 @@
     return off;
 }
 
+int sfs_show_l2_key_vlan (char *buf)
+{
+    tpmcfg_l2_key_entry_t *pentry = (tpmcfg_l2_key_entry_t *)tpm_l2_key_db.entryAra;
+    int                   indx;
+    int                   off = 0;
+
+    for (indx = 0; indx < tpm_l2_key_db.max_num_entries; indx++, pentry++)
+    {
+        if (pentry->name[0] != 0 && l2_key_type_vlan == pentry->l2_key_type)
+        {
+            off += sprintf(buf+off, "--- !L2KeyVlan\n");
+            off += sprintf(buf+off, "rule_name: %s\n", pentry->name);
+            off += sprintf(buf+off, "vlan_rule1: %s\n", pentry->vlan_rule1);
+            off += sprintf(buf+off, "vlan_rule2: %s\n", pentry->vlan_rule2);
+        }
+    }
+    return off;
+}
+
+int sfs_show_vlan_rule (char *buf)
+{
+    tpmcfg_vlan_entry_t *pentry =
+        (tpmcfg_vlan_entry_t *)tpm_vlan_rule_db.entryAra;
+    int                 indx;
+    int                 off = 0;
+
+    for (indx = 0; indx < tpm_vlan_rule_db.max_num_entries; indx++, pentry++)
+    {
+        if (pentry->name[0] != 0)
+        {
+            off += sprintf(buf+off, "--- !VlanRule\n");
+            off += sprintf(buf+off, "rule_name: %s\n", pentry->name);
+            off += sprintf(buf+off, "tpid: 0x%x\n", pentry->vlan.tpid);
+            off += sprintf(buf+off, "tpid_mask: 0x%x\n",
+                           pentry->vlan.tpid_mask);
+            off += sprintf(buf+off, "vid: %d\n", pentry->vlan.vid);
+            off += sprintf(buf+off, "vid_mask: 0x%x\n", pentry->vlan.vid_mask);
+            off += sprintf(buf+off, "cfi: %d\n", pentry->vlan.cfi);
+            off += sprintf(buf+off, "cfi_mask: 0x%x\n", pentry->vlan.cfi_mask);
+            off += sprintf(buf+off, "pbit: %d\n", pentry->vlan.pbit);
+            off += sprintf(buf+off, "pbit_mask: 0x%x\n",
+                           pentry->vlan.pbit_mask);
+        }
+    }
+    return off;
+}
+
 int sfs_show_l2_rule (char *buf)
 {
     tpmcfg_l2_prim_key_entry_t *pentry = (tpmcfg_l2_prim_key_entry_t *)tpm_l2_rule_db.entryAra;
diff --git a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.h b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.h
index 0f4c69c..ef23a68 100755
--- a/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.h
+++ b/arch/arm/plat-feroceon/mv_drivers_lsp/mv_tpm/perf/tpm_sysfs_utils.h
@@ -198,10 +198,28 @@
 extern GT_BOOL             del_tpm_mod_entry_by_name  (char *name);
 extern void                show_tpm_mod_db(void);
 
+typedef enum
+{
+    l2_key_type_macaddr,
+    l2_key_type_vlan,
+    l2_key_type_ethertype,
+    l2_key_type_gemport,
+    l2_key_type_pppoe
+} tpmcfg_l2_key_type_t;
+
 // L2 ACL entry and DB API
 typedef struct
 {
     char                   name[DB_TPMCFG_MAX_NAME+1];
+    tpmcfg_l2_key_type_t   l2_key_type;
+    /* This is a hack. Vlan name is not saved as part of l2_key. Therefore it is
+     * kind of hard to track which vlan rule l2_key_vlan is using. But
+     * tpm_l2_acl_key_t is actually used by tcam. The size should not be
+     * altered. We have to put aside some space just for VLAN name in case the
+     * l2_key_type is l2_key_vlan.
+     */
+    char                   vlan_rule1[DB_TPMCFG_MAX_NAME+1];
+    char                   vlan_rule2[DB_TPMCFG_MAX_NAME+1];
     tpm_l2_acl_key_t       l2_acl;
 } tpmcfg_l2_key_entry_t;
 
@@ -316,7 +334,10 @@
 tpm_error_code_t tpm_proc_send_genquery_to_uni(tpm_trg_port_type_t dest_port_bm, uint32_t packet_num);
 
 extern int sfs_show_frwd_rule(char *buf);
+extern int sfs_show_l2_key_ethertype(char *buf);
 extern int sfs_show_l2_key_mac_addr(char *buf);
+extern int sfs_show_l2_key_vlan(char *buf);
 extern int sfs_show_l2_rule(char *buf);
+extern int sfs_show_vlan_rule(char *buf);
 
 #endif  /* _TPM_USR_TPM_SYSFS_DB_H_*/