Skip to content

Commit 80c4627

Browse files
lunndavem330
authored andcommitted
dsa: mv88x6xxx: Refactor getting a single statistic
Move the code to retrieve a statistics counter into a function of its own, so it can later be reused. Signed-off-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8a0a265 commit 80c4627

File tree

2 files changed

+40
-27
lines changed

2 files changed

+40
-27
lines changed

drivers/net/dsa/mv88e6xxx.c

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,40 @@ static void _mv88e6xxx_get_strings(struct dsa_switch *ds,
681681
}
682682
}
683683

684+
static uint64_t _mv88e6xxx_get_ethtool_stat(struct dsa_switch *ds,
685+
int stat,
686+
struct mv88e6xxx_hw_stat *stats,
687+
int port)
688+
{
689+
struct mv88e6xxx_hw_stat *s = stats + stat;
690+
u32 low;
691+
u32 high = 0;
692+
int ret;
693+
u64 value;
694+
695+
if (s->reg >= 0x100) {
696+
ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
697+
s->reg - 0x100);
698+
if (ret < 0)
699+
return UINT64_MAX;
700+
701+
low = ret;
702+
if (s->sizeof_stat == 4) {
703+
ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
704+
s->reg - 0x100 + 1);
705+
if (ret < 0)
706+
return UINT64_MAX;
707+
high = ret;
708+
}
709+
} else {
710+
_mv88e6xxx_stats_read(ds, s->reg, &low);
711+
if (s->sizeof_stat == 8)
712+
_mv88e6xxx_stats_read(ds, s->reg + 1, &high);
713+
}
714+
value = (((u64)high) << 16) | low;
715+
return value;
716+
}
717+
684718
static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
685719
int nr_stats,
686720
struct mv88e6xxx_hw_stat *stats,
@@ -699,34 +733,9 @@ static void _mv88e6xxx_get_ethtool_stats(struct dsa_switch *ds,
699733
}
700734

701735
/* Read each of the counters. */
702-
for (i = 0; i < nr_stats; i++) {
703-
struct mv88e6xxx_hw_stat *s = stats + i;
704-
u32 low;
705-
u32 high = 0;
736+
for (i = 0; i < nr_stats; i++)
737+
data[i] = _mv88e6xxx_get_ethtool_stat(ds, i, stats, port);
706738

707-
if (s->reg >= 0x100) {
708-
ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
709-
s->reg - 0x100);
710-
if (ret < 0)
711-
goto error;
712-
low = ret;
713-
if (s->sizeof_stat == 4) {
714-
ret = _mv88e6xxx_reg_read(ds, REG_PORT(port),
715-
s->reg - 0x100 + 1);
716-
if (ret < 0)
717-
goto error;
718-
high = ret;
719-
}
720-
data[i] = (((u64)high) << 16) | low;
721-
continue;
722-
}
723-
_mv88e6xxx_stats_read(ds, s->reg, &low);
724-
if (s->sizeof_stat == 8)
725-
_mv88e6xxx_stats_read(ds, s->reg + 1, &high);
726-
727-
data[i] = (((u64)high) << 32) | low;
728-
}
729-
error:
730739
mutex_unlock(&ps->smi_mutex);
731740
}
732741

drivers/net/dsa/mv88e6xxx.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
#ifndef __MV88E6XXX_H
1212
#define __MV88E6XXX_H
1313

14+
#ifndef UINT64_MAX
15+
#define UINT64_MAX (u64)(~((u64)0))
16+
#endif
17+
1418
#define SMI_CMD 0x00
1519
#define SMI_CMD_BUSY BIT(15)
1620
#define SMI_CMD_CLAUSE_22 BIT(12)

0 commit comments

Comments
 (0)