Skip to content

Commit 0a967b4

Browse files
hjelmelanddavem330
authored andcommitted
net: dsa: lan9303: refactor lan9303_get_ethtool_stats
In lan9303_get_ethtool_stats: Get rid of 0x400 constant magic by using new lan9303_read_switch_reg() inside loop. Reduced scope of two variables. Signed-off-by: Egil Hjelmeland <privat@egil-hjelmeland.no> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 9c84258 commit 0a967b4

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

drivers/net/dsa/lan9303-core.c

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,13 @@ static int lan9303_write_switch_port(struct lan9303 *chip, int port,
435435
chip, LAN9303_SWITCH_PORT_REG(port, regnum), val);
436436
}
437437

438+
static int lan9303_read_switch_port(struct lan9303 *chip, int port,
439+
u16 regnum, u32 *val)
440+
{
441+
return lan9303_read_switch_reg(
442+
chip, LAN9303_SWITCH_PORT_REG(port, regnum), val);
443+
}
444+
438445
static int lan9303_detect_phy_setup(struct lan9303 *chip)
439446
{
440447
int reg;
@@ -705,19 +712,18 @@ static void lan9303_get_ethtool_stats(struct dsa_switch *ds, int port,
705712
uint64_t *data)
706713
{
707714
struct lan9303 *chip = ds->priv;
708-
u32 reg;
709-
unsigned int u, poff;
710-
int ret;
711-
712-
poff = port * 0x400;
715+
unsigned int u;
713716

714717
for (u = 0; u < ARRAY_SIZE(lan9303_mib); u++) {
715-
ret = lan9303_read_switch_reg(chip,
716-
lan9303_mib[u].offset + poff,
717-
&reg);
718+
u32 reg;
719+
int ret;
720+
721+
ret = lan9303_read_switch_port(
722+
chip, port, lan9303_mib[u].offset, &reg);
723+
718724
if (ret)
719-
dev_warn(chip->dev, "Reading status reg %u failed\n",
720-
lan9303_mib[u].offset + poff);
725+
dev_warn(chip->dev, "Reading status port %d reg %u failed\n",
726+
port, lan9303_mib[u].offset);
721727
data[u] = reg;
722728
}
723729
}

0 commit comments

Comments
 (0)