[PATCH net-next v11 2/5] net: spacemit: Add K1 Ethernet MAC

Vivian Wang wangruikang at iscas.ac.cn
Sat Sep 13 20:54:38 PDT 2025


On 9/13/25 05:10, Andrew Lunn wrote:
>> +static u32 emac_rd(struct emac_priv *priv, u32 reg)
>> +{
>> +	return readl(priv->iobase + reg);
>> +}
>> +static int emac_mii_read(struct mii_bus *bus, int phy_addr, int regnum)
>> +{
>> +	struct emac_priv *priv = bus->priv;
>> +	u32 cmd = 0, val;
>> +	int ret;
>> +
>> +	cmd |= FIELD_PREP(MREGBIT_PHY_ADDRESS, phy_addr);
>> +	cmd |= FIELD_PREP(MREGBIT_REGISTER_ADDRESS, regnum);
>> +	cmd |= MREGBIT_START_MDIO_TRANS | MREGBIT_MDIO_READ_WRITE;
>> +
>> +	emac_wr(priv, MAC_MDIO_DATA, 0x0);
>> +	emac_wr(priv, MAC_MDIO_CONTROL, cmd);
>> +
>> +	ret = readl_poll_timeout(priv->iobase + MAC_MDIO_CONTROL, val,
>> +				 !(val & MREGBIT_START_MDIO_TRANS), 100, 10000);
>> +
>> +	if (ret)
>> +		return ret;
>> +
>> +	val = emac_rd(priv, MAC_MDIO_DATA);
>> +	return val;
> emac_rd() returns a u32. Is it guaranteed by the hardware that the
> upper word is 0? Maybe this needs to be masked?

This should be fine, since most of the registers only have lower 16
bits, and the upper 16 bits ignores writes and read as zeros. But I'll
change it to a FIELD_GET for v12 just so there's no question on whether
this is safe.

Thanks,
Vivian "dramforever" Wang

> 	Andrew




More information about the linux-riscv mailing list