OSDN Git Service

net: ethernet: ti: ale: add cpsw_ale_get_num_entries api
authorGrygorii Strashko <grygorii.strashko@ti.com>
Thu, 10 Sep 2020 20:27:59 +0000 (23:27 +0300)
committerDavid S. Miller <davem@davemloft.net>
Sat, 12 Sep 2020 00:34:39 +0000 (17:34 -0700)
Add cpsw_ale_get_num_entries() API to return number of ALE table entries
and update existing drivers to use it.

Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/ti/am65-cpsw-ethtool.c
drivers/net/ethernet/ti/cpsw_ale.c
drivers/net/ethernet/ti/cpsw_ale.h
drivers/net/ethernet/ti/cpsw_ethtool.c

index 496dafb..6e4d4f9 100644 (file)
@@ -572,13 +572,14 @@ static int am65_cpsw_nway_reset(struct net_device *ndev)
 static int am65_cpsw_get_regs_len(struct net_device *ndev)
 {
        struct am65_cpsw_common *common = am65_ndev_to_common(ndev);
-       u32 i, regdump_len = 0;
+       u32 ale_entries, i, regdump_len = 0;
 
+       ale_entries = cpsw_ale_get_num_entries(common->ale);
        for (i = 0; i < ARRAY_SIZE(am65_cpsw_regdump); i++) {
                if (am65_cpsw_regdump[i].hdr.module_id ==
                    AM65_CPSW_REGDUMP_MOD_CPSW_ALE_TBL) {
                        regdump_len += sizeof(struct am65_cpsw_regdump_hdr);
-                       regdump_len += common->ale->params.ale_entries *
+                       regdump_len += ale_entries *
                                       ALE_ENTRY_WORDS * sizeof(u32);
                        continue;
                }
@@ -592,10 +593,11 @@ static void am65_cpsw_get_regs(struct net_device *ndev,
                               struct ethtool_regs *regs, void *p)
 {
        struct am65_cpsw_common *common = am65_ndev_to_common(ndev);
-       u32 i, j, pos, *reg = p;
+       u32 ale_entries, i, j, pos, *reg = p;
 
        /* update CPSW IP version */
        regs->version = AM65_CPSW_REGDUMP_VER;
+       ale_entries = cpsw_ale_get_num_entries(common->ale);
 
        pos = 0;
        for (i = 0; i < ARRAY_SIZE(am65_cpsw_regdump); i++) {
@@ -603,7 +605,7 @@ static void am65_cpsw_get_regs(struct net_device *ndev,
 
                if (am65_cpsw_regdump[i].hdr.module_id ==
                    AM65_CPSW_REGDUMP_MOD_CPSW_ALE_TBL) {
-                       u32 ale_tbl_len = common->ale->params.ale_entries *
+                       u32 ale_tbl_len = ale_entries *
                                          ALE_ENTRY_WORDS * sizeof(u32) +
                                          sizeof(struct am65_cpsw_regdump_hdr);
                        reg[pos++] = ale_tbl_len;
index 9ad872b..a94aef3 100644 (file)
@@ -1079,3 +1079,8 @@ void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data)
                data += ALE_ENTRY_WORDS;
        }
 }
+
+u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale)
+{
+       return ale ? ale->params.ale_entries : 0;
+}
index 6a3cb68..735692f 100644 (file)
@@ -119,6 +119,7 @@ int cpsw_ale_control_get(struct cpsw_ale *ale, int port, int control);
 int cpsw_ale_control_set(struct cpsw_ale *ale, int port,
                         int control, int value);
 void cpsw_ale_dump(struct cpsw_ale *ale, u32 *data);
+u32 cpsw_ale_get_num_entries(struct cpsw_ale *ale);
 
 static inline int cpsw_ale_get_vlan_p0_untag(struct cpsw_ale *ale, u16 vid)
 {
index fa54efe..4d02c51 100644 (file)
@@ -339,7 +339,8 @@ int cpsw_get_regs_len(struct net_device *ndev)
 {
        struct cpsw_common *cpsw = ndev_to_cpsw(ndev);
 
-       return cpsw->data.ale_entries * ALE_ENTRY_WORDS * sizeof(u32);
+       return cpsw_ale_get_num_entries(cpsw->ale) *
+              ALE_ENTRY_WORDS * sizeof(u32);
 }
 
 void cpsw_get_regs(struct net_device *ndev, struct ethtool_regs *regs, void *p)