Commit fbf64c19 authored by WingMan Kwok's avatar WingMan Kwok Committed by David S. Miller

net: netcp: Consolidates statistics collection code

Different Keystone2 platforms have different number and
layouts of hw statistics modules.  This patch consolidates
the statistics processing of different Keystone2 platforms
for easy maintenance.
Signed-off-by: default avatarWingMan Kwok <w-kwok2@ti.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 208c6b9a
...@@ -1550,70 +1550,79 @@ static int keystone_get_sset_count(struct net_device *ndev, int stringset) ...@@ -1550,70 +1550,79 @@ static int keystone_get_sset_count(struct net_device *ndev, int stringset)
} }
} }
static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data) static inline void gbe_update_hw_stats_entry(struct gbe_priv *gbe_dev,
int et_stats_entry)
{ {
void __iomem *base = NULL; void __iomem *base = NULL;
u32 __iomem *p; u32 __iomem *p;
u32 tmp = 0; u32 tmp = 0;
/* The hw_stats_regs pointers are already
* properly set to point to the right base:
*/
base = gbe_dev->hw_stats_regs[gbe_dev->et_stats[et_stats_entry].type];
p = base + gbe_dev->et_stats[et_stats_entry].offset;
tmp = readl(p);
gbe_dev->hw_stats[et_stats_entry] += tmp;
/* write-to-decrement:
* new register value = old register value - write value
*/
writel(tmp, p);
}
static void gbe_update_stats(struct gbe_priv *gbe_dev, uint64_t *data)
{
int i; int i;
for (i = 0; i < gbe_dev->num_et_stats; i++) { for (i = 0; i < gbe_dev->num_et_stats; i++) {
base = gbe_dev->hw_stats_regs[gbe_dev->et_stats[i].type]; gbe_update_hw_stats_entry(gbe_dev, i);
p = base + gbe_dev->et_stats[i].offset;
tmp = readl(p);
gbe_dev->hw_stats[i] = gbe_dev->hw_stats[i] + tmp;
if (data) if (data)
data[i] = gbe_dev->hw_stats[i]; data[i] = gbe_dev->hw_stats[i];
/* write-to-decrement:
* new register value = old register value - write value
*/
writel(tmp, p);
} }
} }
static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data) static inline void gbe_stats_mod_visible_ver14(struct gbe_priv *gbe_dev,
int stats_mod)
{ {
void __iomem *gbe_statsa = gbe_dev->hw_stats_regs[0]; u32 val;
void __iomem *gbe_statsb = gbe_dev->hw_stats_regs[1];
u64 *hw_stats = &gbe_dev->hw_stats[0];
void __iomem *base = NULL;
u32 __iomem *p;
u32 tmp = 0, val, pair_size = (gbe_dev->num_et_stats / 2);
int i, j, pair;
for (pair = 0; pair < 2; pair++) { val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
val = readl(GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
if (pair == 0) switch (stats_mod) {
val &= ~GBE_STATS_CD_SEL; case GBE_STATSA_MODULE:
else case GBE_STATSB_MODULE:
val |= GBE_STATS_CD_SEL; val &= ~GBE_STATS_CD_SEL;
break;
case GBE_STATSC_MODULE:
case GBE_STATSD_MODULE:
val |= GBE_STATS_CD_SEL;
break;
default:
return;
}
/* make the stat module visible */
writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en));
}
/* make the stat modules visible */ static void gbe_update_stats_ver14(struct gbe_priv *gbe_dev, uint64_t *data)
writel(val, GBE_REG_ADDR(gbe_dev, switch_regs, stat_port_en)); {
u32 half_num_et_stats = (gbe_dev->num_et_stats / 2);
int et_entry, j, pair;
for (i = 0; i < pair_size; i++) { for (pair = 0; pair < 2; pair++) {
j = pair * pair_size + i; gbe_stats_mod_visible_ver14(gbe_dev, (pair ?
switch (gbe_dev->et_stats[j].type) { GBE_STATSC_MODULE :
case GBE_STATSA_MODULE: GBE_STATSA_MODULE));
case GBE_STATSC_MODULE:
base = gbe_statsa; for (j = 0; j < half_num_et_stats; j++) {
break; et_entry = pair * half_num_et_stats + j;
case GBE_STATSB_MODULE: gbe_update_hw_stats_entry(gbe_dev, et_entry);
case GBE_STATSD_MODULE:
base = gbe_statsb;
break;
}
p = base + gbe_dev->et_stats[j].offset;
tmp = readl(p);
hw_stats[j] += tmp;
if (data) if (data)
data[j] = hw_stats[j]; data[et_entry] = gbe_dev->hw_stats[et_entry];
/* write-to-decrement:
* new register value = old register value - write value
*/
writel(tmp, p);
} }
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment