net: ethernet: ocelot: remove the need for num_stats initializer
authorColin Foster <colin.foster@in-advantage.com>
Fri, 29 Apr 2022 21:30:36 +0000 (14:30 -0700)
committerDavid S. Miller <davem@davemloft.net>
Sat, 30 Apr 2022 12:38:49 +0000 (13:38 +0100)
There is a desire to share the oclot_stats_layout struct outside of the
current vsc7514 driver. In order to do so, the length of the array needs to
be known at compile time, and defined in the struct ocelot and struct
felix_info.

Since the array is defined in a .c file and would be declared in the header
file via:
extern struct ocelot_stat_layout[];
the size of the array will not be known at compile time to outside modules.

To fix this, remove the need for defining the number of stats at compile
time and allow this number to be determined at initialization.

Signed-off-by: Colin Foster <colin.foster@in-advantage.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/ocelot/felix.c
drivers/net/dsa/ocelot/felix.h
drivers/net/dsa/ocelot/felix_vsc9959.c
drivers/net/dsa/ocelot/seville_vsc9953.c
drivers/net/ethernet/mscc/ocelot.c
drivers/net/ethernet/mscc/ocelot_vsc7514.c
include/soc/mscc/ocelot.h

index 9e28219b223df95473dd118af43cc63b85fa4a3b..33cb124ca91239d1f1a260510b583805d413dc1f 100644 (file)
@@ -1197,7 +1197,6 @@ static int felix_init_structs(struct felix *felix, int num_phys_ports)
 
        ocelot->map             = felix->info->map;
        ocelot->stats_layout    = felix->info->stats_layout;
-       ocelot->num_stats       = felix->info->num_stats;
        ocelot->num_mact_rows   = felix->info->num_mact_rows;
        ocelot->vcap            = felix->info->vcap;
        ocelot->vcap_pol.base   = felix->info->vcap_pol_base;
index f083b06fdfe93475812deabd17353d5865086c56..39faf1027965202ddc1dc85c5ef080284ab97e4a 100644 (file)
@@ -24,7 +24,6 @@ struct felix_info {
        const u32                       *port_modes;
        int                             num_mact_rows;
        const struct ocelot_stat_layout *stats_layout;
-       unsigned int                    num_stats;
        int                             num_ports;
        int                             num_tx_queues;
        struct vcap_props               *vcap;
index 52a8566071eddd8e63d79ce20febf879537a88b9..081871824eaf98d110cecfe7086585fbb2c886bc 100644 (file)
@@ -638,6 +638,7 @@ static const struct ocelot_stat_layout vsc9959_stats_layout[] = {
        { .offset = 0x10F,      .name = "drop_green_prio_5", },
        { .offset = 0x110,      .name = "drop_green_prio_6", },
        { .offset = 0x111,      .name = "drop_green_prio_7", },
+       OCELOT_STAT_END
 };
 
 static const struct vcap_field vsc9959_vcap_es0_keys[] = {
@@ -2216,7 +2217,6 @@ static const struct felix_info felix_info_vsc9959 = {
        .map                    = vsc9959_regmap,
        .ops                    = &vsc9959_ops,
        .stats_layout           = vsc9959_stats_layout,
-       .num_stats              = ARRAY_SIZE(vsc9959_stats_layout),
        .vcap                   = vsc9959_vcap_props,
        .vcap_pol_base          = VSC9959_VCAP_POLICER_BASE,
        .vcap_pol_max           = VSC9959_VCAP_POLICER_MAX,
index 68ef8f111bbe1ebcbc990fd5c56abe7bf8a8ddda..48fd43a9336457a73223f56b8047f69d73a94f95 100644 (file)
@@ -636,6 +636,7 @@ static const struct ocelot_stat_layout vsc9953_stats_layout[] = {
        { .offset = 0x8F,       .name = "drop_green_prio_5", },
        { .offset = 0x90,       .name = "drop_green_prio_6", },
        { .offset = 0x91,       .name = "drop_green_prio_7", },
+       OCELOT_STAT_END
 };
 
 static const struct vcap_field vsc9953_vcap_es0_keys[] = {
@@ -1086,7 +1087,6 @@ static const struct felix_info seville_info_vsc9953 = {
        .map                    = vsc9953_regmap,
        .ops                    = &vsc9953_ops,
        .stats_layout           = vsc9953_stats_layout,
-       .num_stats              = ARRAY_SIZE(vsc9953_stats_layout),
        .vcap                   = vsc9953_vcap_props,
        .vcap_pol_base          = VSC9953_VCAP_POLICER_BASE,
        .vcap_pol_max           = VSC9953_VCAP_POLICER_MAX,
index ca71b62a44dc3b84e8990aae13d355170726ea54..0825a92599a5499279da63cf37b6000f7ce7252a 100644 (file)
@@ -3228,6 +3228,7 @@ static void ocelot_detect_features(struct ocelot *ocelot)
 
 int ocelot_init(struct ocelot *ocelot)
 {
+       const struct ocelot_stat_layout *stat;
        char queue_name[32];
        int i, ret;
        u32 port;
@@ -3240,6 +3241,10 @@ int ocelot_init(struct ocelot *ocelot)
                }
        }
 
+       ocelot->num_stats = 0;
+       for_each_stat(ocelot, stat)
+               ocelot->num_stats++;
+
        ocelot->stats = devm_kcalloc(ocelot->dev,
                                     ocelot->num_phys_ports * ocelot->num_stats,
                                     sizeof(u64), GFP_KERNEL);
index 4f4a495a60ad5d5c0ebcb442f91818fd67a84632..961f803aca19222410e28b2806dfa068cbaad189 100644 (file)
@@ -190,6 +190,7 @@ static const struct ocelot_stat_layout ocelot_stats_layout[] = {
        { .name = "drop_green_prio_5", .offset = 0x8F, },
        { .name = "drop_green_prio_6", .offset = 0x90, },
        { .name = "drop_green_prio_7", .offset = 0x91, },
+       OCELOT_STAT_END
 };
 
 static void ocelot_pll5_init(struct ocelot *ocelot)
@@ -227,7 +228,6 @@ static int ocelot_chip_init(struct ocelot *ocelot, const struct ocelot_ops *ops)
 
        ocelot->map = ocelot_regmap;
        ocelot->stats_layout = ocelot_stats_layout;
-       ocelot->num_stats = ARRAY_SIZE(ocelot_stats_layout);
        ocelot->num_mact_rows = 1024;
        ocelot->ops = ops;
 
index 9b4e6c78d0f418cbc8516520b9300496434b28d5..5c4f57cfa7858bbd5bf7e33bb7d2720fc3f530a0 100644 (file)
 #define REG_RESERVED_ADDR              0xffffffff
 #define REG_RESERVED(reg)              REG(reg, REG_RESERVED_ADDR)
 
+#define OCELOT_STAT_FLAG_END           BIT(0)
+
+#define for_each_stat(ocelot, stat)                            \
+       for ((stat) = ocelot->stats_layout;                     \
+            !((stat)->flags & OCELOT_STAT_FLAG_END);           \
+            (stat)++)
+
 enum ocelot_target {
        ANA = 1,
        QS,
@@ -535,9 +542,12 @@ enum ocelot_ptp_pins {
 
 struct ocelot_stat_layout {
        u32 offset;
+       u32 flags;
        char name[ETH_GSTRING_LEN];
 };
 
+#define OCELOT_STAT_END { .flags = OCELOT_STAT_FLAG_END }
+
 struct ocelot_stats_region {
        struct list_head node;
        u32 offset;