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

From
Vivian Wang <hidden>
Date
2025-09-14 03:56:01
Also in
linux-riscv, lkml, netdev, spacemit
Reply to
Andrew Lunn, 2025-09-12
On 9/13/25 05:10, Andrew Lunn wrote:
quoted
+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
  
Thread (10 messages) 10 messages, 2 authors, last reply 2025-09-14
Keyboard shortcuts
hback out one level
jnext message in thread / next series-diff position
kprevious message in thread / previous series-diff position
ldrill in
Escclose help / fold thread tree
?toggle this help