net: usb: lan78xx: Add error handling to lan78xx_init_mac_address

Convert `lan78xx_init_mac_address` to return error codes and handle
failures in register read and write operations. Update `lan78xx_reset`
to check for errors during MAC address initialization and propagate them
appropriately.

Signed-off-by: Oleksij Rempel <o.rempel@pengutronix.de>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Link: https://patch.msgid.link/20241209130751.703182-3-o.rempel@pengutronix.de
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
This commit is contained in:
Oleksij Rempel 2024-12-09 14:07:42 +01:00 committed by Jakub Kicinski
parent d354d00825
commit 6f31135894

View File

@ -2153,13 +2153,19 @@ static const struct ethtool_ops lan78xx_ethtool_ops = {
.get_regs = lan78xx_get_regs,
};
static void lan78xx_init_mac_address(struct lan78xx_net *dev)
static int lan78xx_init_mac_address(struct lan78xx_net *dev)
{
u32 addr_lo, addr_hi;
u8 addr[6];
int ret;
lan78xx_read_reg(dev, RX_ADDRL, &addr_lo);
lan78xx_read_reg(dev, RX_ADDRH, &addr_hi);
ret = lan78xx_read_reg(dev, RX_ADDRL, &addr_lo);
if (ret < 0)
return ret;
ret = lan78xx_read_reg(dev, RX_ADDRH, &addr_hi);
if (ret < 0)
return ret;
addr[0] = addr_lo & 0xFF;
addr[1] = (addr_lo >> 8) & 0xFF;
@ -2192,14 +2198,26 @@ static void lan78xx_init_mac_address(struct lan78xx_net *dev)
(addr[2] << 16) | (addr[3] << 24);
addr_hi = addr[4] | (addr[5] << 8);
lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
ret = lan78xx_write_reg(dev, RX_ADDRL, addr_lo);
if (ret < 0)
return ret;
ret = lan78xx_write_reg(dev, RX_ADDRH, addr_hi);
if (ret < 0)
return ret;
}
lan78xx_write_reg(dev, MAF_LO(0), addr_lo);
lan78xx_write_reg(dev, MAF_HI(0), addr_hi | MAF_HI_VALID_);
ret = lan78xx_write_reg(dev, MAF_LO(0), addr_lo);
if (ret < 0)
return ret;
ret = lan78xx_write_reg(dev, MAF_HI(0), addr_hi | MAF_HI_VALID_);
if (ret < 0)
return ret;
eth_hw_addr_set(dev->net, addr);
return 0;
}
/* MDIO read and write wrappers for phylib */
@ -2990,7 +3008,9 @@ static int lan78xx_reset(struct lan78xx_net *dev)
}
} while (buf & HW_CFG_LRST_);
lan78xx_init_mac_address(dev);
ret = lan78xx_init_mac_address(dev);
if (ret < 0)
return ret;
/* save DEVID for later usage */
ret = lan78xx_read_reg(dev, ID_REV, &buf);