Skip to contentSkip to conversation

net: ethernet: adi: adin1110: Add OPEN Alliance TC6 support

PATCH New Iustin Stolniceanu 2 participants 11 messages Nov 23 – Nov 24

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v3 cover net: ethernet: adi: adin1110: Add OPEN Alliance TC6 support

The ADIN1110 supports two SPI host interface protocols: the generic SPI protocol, which the adin1110 driver implements today, and the OPEN Alliance TC6 protocol. Two pins select the mode, and the device latches them when it comes out of reset:

- SPI_CFG1 selects the protocol: OPEN Alliance TC6 when low (or left floating), generic SPI when high.
- SPI_CFG0 enables the CRC8 of the generic SPI protocol, or the control data protection of the OPEN Alliance protocol: enabled when low, disabled when high.

SPI_CFG0 can be read back, as the PROTE bit of CONFIG0, and the generic SPI case is already described by the adi,spi-crc property. No register reports SPI_CFG1, so the protocol cannot be detected by reading the chip.

This series adds OPEN Alliance TC6 support for the ADIN1110 using the oa_tc6 framework, selected by a new adi,spi-oa-tc6 DT property:

1: oa_tc6: forward declare struct mii_bus in oa_tc6.h
2-3: oa_tc6: configurable reset settle times, and indirect MDIO access
(MDIOACC) for MAC-PHYs without direct PHY register access
4-5: adin1100: separate phy_driver entries per model, then skip the
soft reset on ADIN1110/ADIN2111, as it resets the whole MAC-PHY
6: dt-bindings: add adi,spi-oa-tc6
7: adin1110: add the OPEN Alliance TC6 probe path

The ADIN2111 is not supported in OPEN Alliance TC6 mode yet.

If adi,spi-oa-tc6 does not match the board strapping, probe fails with -ENODEV and a message pointing at the SPI_CFG1 strap and the property.

As promised in the v1 thread, I tried the wrong framing on an EVAL-ADIN1110EBZ in both directions. OA TC6 access to a generic SPI strapped chip gets no valid reply and does not set SPI_ERR. Generic SPI access to an OA TC6 strapped chip returns garbage and sets HDRE and LOFE in STATUS0, which are write-1-to-clear, and OA TC6 access keeps working afterwards. So the protocols can be told apart, but I kept the explicit property for now. If autodetection is preferred, I can do that before the binding is merged.

Testing: Raspberry Pi 4 with an EVAL-ADIN1110EBZ, SPI at 25 MHz, against a 10BASE-T1L link partner, on a normal and a debug kernel (KASAN, lockdep, kmemleak). OPEN Alliance TC6 mode: probe/remove 20x, sysfs unbind/bind 10x, link up/down under traffic, frame sizes 42-1514 bytes, flood ping, ~9.4 Mbit/s TCP in each direction, 0% loss on 10 Mbit/s bidirectional UDP, joined multicast group and macvlan traffic. Generic SPI mode: same results with and without the series. Both mismatches (adi,spi-oa-tc6 set on a generic SPI strapped board, and the reverse) fail with -ENODEV and a clear message. OPEN Alliance TC6 was tested with and without control protection (SPI_CFG0). v3 was retested in OPEN Alliance TC6 mode with control protection, on the normal kernel.

Known limitations, unchanged by this series:
- A "Config unsync" error (e.g. after a chip reset) makes oa_tc6 disable the device until the driver is reloaded.
- On unload, a lockdep enabled kernel prints a "suspicious RCU usage" warning from phy_detach_internal(), as phy_disconnect() is called without the RTNL held. The generic SPI path of the unpatched driver does the same.

Parts of the code and of the commit messages were developed with the help of an AI assistant (Claude Opus 5.5); all changes were reviewed and tested on hardware by the submitter. The v1 patches 1-4 were also reviewed with Sashiko (Claude Opus 5.5) before sending, and the v2 findings of the Sashiko bot on the list were checked against the code and the datasheet for v3.

Changes in v3:
- 2/7: embed struct oa_tc6_quirks in struct oa_tc6 instead of copying its fields (Selvamani). Dropped Alvin's Reviewed-by, as the patch changed.

- 3/7: use indirect MDIO access only when STDCAP.IPRAC is set, and keep -ENODEV when neither DPRAC nor IPRAC is set (Sashiko)

- 4/7: use PHY_ID_MATCH_EXACT() in the phy_driver entries, so that only revision 1 binds to the driver, as with the old 0xffffffcf mask (Sashiko)

- 6/7: move allOf to the bottom and drop the '|' of the adi,spi-oa-tc6 description (Krzysztof)

- 7/7: set netdev_ops before oa_tc6_init(), which attaches the PHY and can read netdev_ops through netdev_need_ops_lock() (Sashiko); commit
message: -EPROTO covers any OA TC6 reply error during initialization, not only the first transfer (Sashiko)

v2: https://lore.kernel.org/r/[email protected]

Changes in v2:
- Reordered: the adin1100 patches now come before the adin1110 OA TC6 patch that needs them, so the series bisects cleanly.
- 1/7: new: split the struct mii_bus forward declaration out of the adin1110 patch (Alvin)

- 2/7: split reset_settle_us into hwreset_settle_us (default 1 ms) and softreset_settle_us (default 0); fsleep() unconditionally (Alvin)

- 3/7: use if (!DPRAC) mdio_indirect_mode = true (Alvin)

- 4/7: new: one phy_driver per model with PHY_ID_MATCH_MODEL() instead of a single entry with mask 0xffffffcf (Andrew, Alvin)

- 5/7: (was 5/5) omit .soft_reset on the ADIN1110/ADIN2111 entries instead of checking the PHY ID in the callback (Alvin)

- 6/7: (was 3/5) disallow adi,spi-crc together with adi,spi-oa-tc6 (Alvin)

- 7/7: (was 4/5) set 50 ms / 10 ms settle times from the datasheet; -ENODEV instead of -EOPNOTSUPP for ADIN2111; whitespace nits. Fail with -ENODEV and a clear message if adi,spi-oa-tc6 does not match the strapping (Andrew). Accept all multicast when the multicast list is not empty and don't set IFF_UNICAST_FLT, and use DEV_STATS_INC() for tx_dropped (Sashiko).

v1: https://lore.kernel.org/r/[email protected]

Ciprian Regus (4):
net: ethernet: oa_tc6: Allow custom reset settle time values
net: ethernet: oa_tc6: Add support for MDIO indirect access
dt-bindings: net: adi,adin1110: Add adi,spi-oa-tc6
net: ethernet: adi: adin1110: Add OA TC6 protocol support for ADIN1110

Iustin Stolniceanu (3):
net: ethernet: oa_tc6: Forward declare struct mii_bus
net: phy: adin1100: Add separate driver entries for ADIN1110/ADIN2111
net: phy: adin1100: Skip the soft reset on ADIN1110/ADIN2111

 .../devicetree/bindings/net/adi,adin1110.yaml |  20 +-
 drivers/net/ethernet/adi/Kconfig              |   1 +
 drivers/net/ethernet/adi/adin1110.c           | 208 +++++++++++++++++-
 drivers/net/ethernet/oa_tc6.c                 | 194 ++++++++++++++--
 drivers/net/phy/adin1100.c                    |  33 ++-
 include/linux/oa_tc6.h                        |  21 ++
 6 files changed, 445 insertions(+), 32 deletions(-)

base-commit: 7ccc5e05043b1bb84326b19a2b05938d8f7a2ae6

Signature · 1 line
2.43.0
#1 lore raw

PATCH v3 1/7 net: ethernet: oa_tc6: Forward declare struct mii_bus

The Clause 45 MDIO accessors in oa_tc6.h take a struct mii_bus pointer, but the header does not declare the type. A file that includes oa_tc6.h before linux/phy.h or linux/mdio.h gets a "'struct mii_bus' declared inside parameter list" warning, which is an error with CONFIG_WERROR.

lan865x and adin1140 are not affected, as they include one of those first. The adin1110 driver, which gets OA TC6 support later in this series, does not, and hits the warning.

---
 include/linux/oa_tc6.h | 1 +
 1 file changed, 1 insertion(+)
include/linux/oa_tc6.h +1 -0
index 27f652d4920b..6eac6b842156 100644
@@ -64,6 +64,7 @@
 #define OA_TC6_PHY_C45_AUTO_NEG_MMS5		5	/* MMD 7 */
 #define OA_TC6_PHY_C45_POWER_UNIT_MMS6		6	/* MMD 13 */
 
+struct mii_bus;
 struct oa_tc6;
 
 enum oa_tc6_quirk_flag {
Signature · 1 line
2.43.0
#2 lore raw

PATCH v3 2/7 net: ethernet: oa_tc6: Allow custom reset settle time values

In reply to Iustin Stolniceanu

From: Ciprian Regus <[email protected]>

oa_tc6_init() waits a fixed 1 ms after deasserting the reset GPIO before accessing the MAC-PHY, and polls STATUS0 for RESETC right after the software reset. The reset timing parameters of a MAC-PHY device are outside of the OA TC6 scope. For example, the ADIN1110 needs up to 50 ms after RESET is deasserted and up to 10 ms after a software reset before its registers can be accessed, and it tristates its SDO pin during the reset.

Add hwreset_settle_us and softreset_settle_us fields to struct oa_tc6_quirks so drivers can set these times. If hwreset_settle_us is not set, the GPIO reset keeps the existing 1 ms wait. If softreset_settle_us is not set, there is no wait after the software reset, as before.

---
 drivers/net/ethernet/oa_tc6.c | 18 +++++++++++-------
 include/linux/oa_tc6.h        |  4 ++++
 2 files changed, 15 insertions(+), 7 deletions(-)
drivers/net/ethernet/oa_tc6.c +11 -7
index 8e86cfde6d1c..c05480b7920e 100644
@@ -89,7 +89,7 @@ struct oa_tc6 {
 	bool int_flag;
 	bool disable_traffic;
 	bool prot_ctrl;
-	enum oa_tc6_quirk_flag quirk_flags;
+	struct oa_tc6_quirks quirks;
 	struct gpio_desc *reset_gpio;
 };
 
@@ -582,7 +582,7 @@ static int oa_tc6_phy_init(struct oa_tc6 *tc6)
 {
 	int ret;
 
-	if (tc6->quirk_flags & OA_TC6_BROKEN_PHY)
+	if (tc6->quirks.quirk_flags & OA_TC6_BROKEN_PHY)
 		return 0;
 
 	ret = oa_tc6_check_phy_reg_direct_access_capability(tc6);
@@ -621,7 +621,7 @@ static int oa_tc6_phy_init(struct oa_tc6 *tc6)
 
 static void oa_tc6_phy_exit(struct oa_tc6 *tc6)
 {
-	if (tc6->quirk_flags & OA_TC6_BROKEN_PHY)
+	if (tc6->quirks.quirk_flags & OA_TC6_BROKEN_PHY)
 		return;
 
 	phy_disconnect(tc6->phydev);
@@ -652,6 +652,8 @@ static int oa_tc6_sw_reset_macphy(struct oa_tc6 *tc6)
 	if (ret)
 		return ret;
 
+	fsleep(tc6->quirks.softreset_settle_us);
+
 	/* Poll for soft reset complete for every 1ms until 1s timeout */
 	ret = readx_poll_timeout(oa_tc6_read_status0, tc6, regval,
 				 regval & OA_TC6_STATUS0_RESETC,
@@ -1475,7 +1477,9 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev,
 	spin_lock_init(&tc6->tx_skb_lock);
 
 	if (quirks)
-		tc6->quirk_flags = quirks->quirk_flags;
+		tc6->quirks = *quirks;
+	if (!tc6->quirks.hwreset_settle_us)
+		tc6->quirks.hwreset_settle_us = 1000;
 
 	/* Set the SPI controller to pump at realtime priority */
 	tc6->spi->rt = true;
@@ -1515,12 +1519,12 @@ struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev,
 					     "failed to get reset gpio\n"));
 
 	if (tc6->reset_gpio) {
-		/* Keep the reset asserted for 10 us and then allow 1 ms of
-		 * settle time for the crystal oscillator startup.
+		/* Keep the reset asserted for 10 us and then allow the reset
+		 * settle time (1 ms by default).
 		 */
 		fsleep(10);
 		gpiod_set_value_cansleep(tc6->reset_gpio, 0);
-		fsleep(1000);
+		fsleep(tc6->quirks.hwreset_settle_us);
 	}
 
 	/* Check the PROTE bit status so that we can reset the device */
include/linux/oa_tc6.h +4 -0
index 6eac6b842156..f676e712e75d 100644
@@ -73,6 +73,10 @@ enum oa_tc6_quirk_flag {
 
 struct oa_tc6_quirks {
 	enum oa_tc6_quirk_flag quirk_flags;
+	/* Wait after deasserting the reset GPIO, 1 ms if not set */
+	u32 hwreset_settle_us;
+	/* Wait after the software reset, before polling for RESETC */
+	u32 softreset_settle_us;
 };
 
 struct oa_tc6 *oa_tc6_init(struct spi_device *spi, struct net_device *netdev,
Signature · 1 line
2.43.0
#3 lore raw

PATCH v3 3/7 net: ethernet: oa_tc6: Add support for MDIO indirect access

In reply to Iustin Stolniceanu

From: Ciprian Regus <[email protected]>

The OPEN Alliance TC6 specification defines two ways for the SPI host to access the registers of the PHY integrated in a MAC-PHY: direct access, where the PHY registers are mapped into the MAC-PHY register space, and indirect access, through the MDIOACC registers. A MAC-PHY reports support for direct access through the DPRAC bit in the STDCAP register.

The framework currently supports only direct access and fails to register the MDIO bus when DPRAC is not set.

Read STDCAP when registering the MDIO bus. If direct access is not supported but indirect access is, reported by the IPRAC bit, implement the Clause 22 and Clause 45 MDIO operations as indirect transactions through MDIOACC. If neither is supported, keep failing with -ENODEV. For Clause 45, write the address command to MDIOACC0 and the read or write command to MDIOACC1; for Clause 22, write the command to MDIOACC1. Then poll for TRDONE.

If TAERR (turnaround error) is set, no PHY answered at that address and the DATA field must be ignored. Return 0xffff in that case, as for an empty address on an MDIO bus, so that the PHY bus scan skips the address instead of failing. Return -EIO for a write.

---
 drivers/net/ethernet/oa_tc6.c | 176 +++++++++++++++++++++++++++++++---
 include/linux/oa_tc6.h        |  16 ++++
 2 files changed, 177 insertions(+), 15 deletions(-)
drivers/net/ethernet/oa_tc6.c +161 -15
index c05480b7920e..ca33df9f045e 100644
@@ -89,6 +89,7 @@ struct oa_tc6 {
 	bool int_flag;
 	bool disable_traffic;
 	bool prot_ctrl;
+	bool mdio_indirect_mode;
 	struct oa_tc6_quirks quirks;
 	struct gpio_desc *reset_gpio;
 };
@@ -434,24 +435,149 @@ int oa_tc6_write_register_mms(struct oa_tc6 *tc6, u8 mms, u16 address,
 }
 EXPORT_SYMBOL_GPL(oa_tc6_write_register_mms);
 
-static int oa_tc6_check_phy_reg_direct_access_capability(struct oa_tc6 *tc6)
+static void oa_tc6_handle_link_change(struct net_device *netdev)
 {
-	u32 regval;
+	phy_print_status(netdev->phydev);
+}
+
+static int oa_tc6_mdioacc_wait_done(struct oa_tc6 *tc6, u32 *regval)
+{
+	int ret, err;
+
+	ret = read_poll_timeout(oa_tc6_read_register, err,
+				err || (*regval & OA_TC6_MDIOACC_TRDONE),
+				100, 30000, false, tc6, OA_TC6_REG_MDIOACC(1),
+				regval);
+	if (ret)
+		return ret;
+
+	return err;
+}
+
+/* On a turnaround error no PHY answered and the DATA field must be ignored.
+ * Return all ones, like an MDIO bus with no PHY at that address, so that
+ * bus scanning skips the address instead of failing.
+ */
+static int oa_tc6_mdioacc_read_data(u32 reg_val)
+{
+	if (reg_val & OA_TC6_MDIOACC_TAERR)
+		return 0xffff;
+
+	return FIELD_GET(OA_TC6_MDIOACC_DATA, reg_val);
+}
+
+static int oa_tc6_mdioacc_write_done(struct oa_tc6 *tc6)
+{
+	u32 reg_val;
 	int ret;
 
-	ret = oa_tc6_read_register(tc6, OA_TC6_REG_STDCAP, &regval);
+	ret = oa_tc6_mdioacc_wait_done(tc6, &reg_val);
 	if (ret)
 		return ret;
 
-	if (!(regval & OA_TC6_STDCAP_DIRECT_PHY_REG_ACCESS))
-		return -ENODEV;
+	return reg_val & OA_TC6_MDIOACC_TAERR ? -EIO : 0;
+}
 
-	return 0;
+static int oa_tc6_indirect_mdiobus_read_c45(struct oa_tc6 *tc6, int addr,
+					    int devnum, int regnum)
+{
+	u32 reg_val;
+	int ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_ADDR);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C45);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, devnum);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DATA, regnum);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(0), reg_val);
+	if (ret)
+		return ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_RD);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C45);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, devnum);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(1), reg_val);
+	if (ret)
+		return ret;
+
+	ret = oa_tc6_mdioacc_wait_done(tc6, &reg_val);
+	if (ret)
+		return ret;
+
+	return oa_tc6_mdioacc_read_data(reg_val);
 }
 
-static void oa_tc6_handle_link_change(struct net_device *netdev)
+static int oa_tc6_indirect_mdiobus_write_c45(struct oa_tc6 *tc6, int addr,
+					     int devnum, int regnum, u16 val)
 {
-	phy_print_status(netdev->phydev);
+	u32 reg_val;
+	int ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_ADDR);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C45);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, devnum);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DATA, regnum);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(0), reg_val);
+	if (ret)
+		return ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_WR);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C45);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, devnum);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DATA, val);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(1), reg_val);
+	if (ret)
+		return ret;
+
+	return oa_tc6_mdioacc_write_done(tc6);
+}
+
+static int oa_tc6_indirect_mdiobus_read(struct oa_tc6 *tc6, int addr,
+					int regnum)
+{
+	u32 reg_val;
+	int ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_RD);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C22);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, regnum);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(1), reg_val);
+	if (ret)
+		return ret;
+
+	ret = oa_tc6_mdioacc_wait_done(tc6, &reg_val);
+	if (ret)
+		return ret;
+
+	return oa_tc6_mdioacc_read_data(reg_val);
+}
+
+static int oa_tc6_indirect_mdiobus_write(struct oa_tc6 *tc6, int addr,
+					 int regnum, u16 val)
+{
+	u32 reg_val;
+	int ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_WR);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C22);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, regnum);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DATA, val);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(1), reg_val);
+	if (ret)
+		return ret;
+
+	return oa_tc6_mdioacc_write_done(tc6);
 }
 
 static int oa_tc6_mdiobus_read(struct mii_bus *bus, int addr, int regnum)
@@ -460,6 +586,9 @@ static int oa_tc6_mdiobus_read(struct mii_bus *bus, int addr, int regnum)
 	u32 regval;
 	int ret;
 
+	if (tc6->mdio_indirect_mode)
+		return oa_tc6_indirect_mdiobus_read(tc6, addr, regnum);
+
 	ret = oa_tc6_read_register(tc6, OA_TC6_PHY_STD_REG_ADDR_BASE |
 				   (regnum & OA_TC6_PHY_STD_REG_ADDR_MASK),
 				   &regval);
@@ -474,6 +603,9 @@ static int oa_tc6_mdiobus_write(struct mii_bus *bus, int addr, int regnum,
 {
 	struct oa_tc6 *tc6 = bus->priv;
 
+	if (tc6->mdio_indirect_mode)
+		return oa_tc6_indirect_mdiobus_write(tc6, addr, regnum, val);
+
 	return oa_tc6_write_register(tc6, OA_TC6_PHY_STD_REG_ADDR_BASE |
 				     (regnum & OA_TC6_PHY_STD_REG_ADDR_MASK),
 				     val);
@@ -505,6 +637,10 @@ int oa_tc6_mdiobus_read_c45(struct mii_bus *bus, int addr, int devnum,
 	int mms;
 	int ret;
 
+	if (tc6->mdio_indirect_mode)
+		return oa_tc6_indirect_mdiobus_read_c45(tc6, addr, devnum,
+							regnum);
+
 	mms = oa_tc6_get_phy_c45_mms(devnum);
 	if (mms < 0)
 		return mms;
@@ -523,6 +659,10 @@ int oa_tc6_mdiobus_write_c45(struct mii_bus *bus, int addr, int devnum,
 	struct oa_tc6 *tc6 = bus->priv;
 	int mms;
 
+	if (tc6->mdio_indirect_mode)
+		return oa_tc6_indirect_mdiobus_write_c45(tc6, addr, devnum,
+							 regnum, val);
+
 	mms = oa_tc6_get_phy_c45_mms(devnum);
 	if (mms < 0)
 		return mms;
@@ -533,8 +673,21 @@ EXPORT_SYMBOL_GPL(oa_tc6_mdiobus_write_c45);
 
 static int oa_tc6_mdiobus_register(struct oa_tc6 *tc6)
 {
+	u32 regval;
 	int ret;
 
+	ret = oa_tc6_read_register(tc6, OA_TC6_REG_STDCAP, &regval);
+	if (ret)
+		return ret;
+
+	if (!(regval & OA_TC6_STDCAP_DIRECT_PHY_REG_ACCESS)) {
+		if (!(regval & OA_TC6_STDCAP_INDIRECT_PHY_REG_ACCESS)) {
+			netdev_err(tc6->netdev, "MDIO direct/indirect access not supported\n");
+			return -ENODEV;
+		}
+		tc6->mdio_indirect_mode = true;
+	}
+
 	tc6->mdiobus = mdiobus_alloc();
 	if (!tc6->mdiobus) {
 		netdev_err(tc6->netdev, "MDIO bus alloc failed\n");
@@ -585,13 +738,6 @@ static int oa_tc6_phy_init(struct oa_tc6 *tc6)
 	if (tc6->quirks.quirk_flags & OA_TC6_BROKEN_PHY)
 		return 0;
 
-	ret = oa_tc6_check_phy_reg_direct_access_capability(tc6);
-	if (ret) {
-		netdev_err(tc6->netdev,
-			   "Direct PHY register access is not supported by the MAC-PHY\n");
-		return ret;
-	}
-
 	ret = oa_tc6_mdiobus_register(tc6);
 	if (ret)
 		return ret;
include/linux/oa_tc6.h +16 -0
index f676e712e75d..caafc17eff59 100644
@@ -13,6 +13,7 @@
 /* OPEN Alliance TC6 registers */
 /* Standard Capabilities Register */
 #define OA_TC6_REG_STDCAP			0x0002
+#define OA_TC6_STDCAP_INDIRECT_PHY_REG_ACCESS	BIT(9)
 #define OA_TC6_STDCAP_DIRECT_PHY_REG_ACCESS	BIT(8)
 
 /* Reset Control and Status Register */
@@ -50,6 +51,21 @@
 #define OA_TC6_INT_MASK0_ALL_INTERRUPTS                 (GENMASK(5, 0) | \
 							 GENMASK(12, 7))
 
+#define OA_TC6_REG_MDIOACC(x)	(0x20 + (x))
+#define OA_TC6_MDIOACC_TRDONE	BIT(31)
+#define OA_TC6_MDIOACC_TAERR	BIT(30)
+#define OA_TC6_MDIOACC_ST	GENMASK(29, 28)
+#define OA_TC6_MDIOACC_OP	GENMASK(27, 26)
+#define OA_TC6_MDIOACC_PRTAD	GENMASK(25, 21)
+#define OA_TC6_MDIOACC_DEVAD	GENMASK(20, 16)
+#define OA_TC6_MDIOACC_DATA	GENMASK(15, 0)
+
+#define OA_TC6_MDIOACC_ST_C45		0x0
+#define OA_TC6_MDIOACC_ST_C22		0x1
+#define OA_TC6_MDIOACC_OP_ADDR		0x0
+#define OA_TC6_MDIOACC_OP_WR		0x1
+#define OA_TC6_MDIOACC_OP_RD		0x3
+
 /* PHY Clause 22 registers base address and mask */
 #define OA_TC6_PHY_STD_REG_ADDR_BASE		0xFF00
 #define OA_TC6_PHY_STD_REG_ADDR_MASK		0x1F
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH net-next v3 3/7] net: ethernet: oa_tc6: Add support for MDIO indirect access

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] SPECULATIVE (this depends on MAC-PHY MDIOACC trigger semantics that I could not check against the OA TC6 specification).
- [Low] In indirect mode, oa_tc6_mdiobus_register() (drivers/net/ethernet/oa_tc6.c:674) installs read_c45/write_c45, which…

--

net: ethernet: oa_tc6: Add support for MDIO indirect access

This patch reads STDCAP when the OA TC6 MDIO bus is registered. If direct PHY register access (DPRAC) is not supported but indirect access (IPRAC) is, the Clause 22 and Clause 45 MDIO operations go through the MDIOACC registers. On a turnaround error, reads return 0xffff so the PHY bus scan skips the address, and writes return -EIO.

Quoted 4 lines
drivers/net/ethernet/oa_tc6.c +0 -0
index c05480b7920ea..ca33df9f045eb 100644

[ ... ]

Quoted 24 lines
drivers/net/ethernet/oa_tc6.c +17 -2
@@ -434,24 +435,149 @@ int oa_tc6_write_register_mms(struct oa_tc6 *tc6, u8 mms, u16 address,
 }
 EXPORT_SYMBOL_GPL(oa_tc6_write_register_mms);
 
-static int oa_tc6_check_phy_reg_direct_access_capability(struct oa_tc6 *tc6)
+static void oa_tc6_handle_link_change(struct net_device *netdev)
 {
-	u32 regval;
+	phy_print_status(netdev->phydev);
+}
+
+static int oa_tc6_mdioacc_wait_done(struct oa_tc6 *tc6, u32 *regval)
+{
+	int ret, err;
+
+	ret = read_poll_timeout(oa_tc6_read_register, err,
+				err || (*regval & OA_TC6_MDIOACC_TRDONE),
+				100, 30000, false, tc6, OA_TC6_REG_MDIOACC(1),
+				regval);
+	if (ret)
+		return ret;
+
+	return err;
+}

[ ... ]

Quoted 17 lines
drivers/net/ethernet/oa_tc6.c +16 -1
-	return 0;
+static int oa_tc6_indirect_mdiobus_read_c45(struct oa_tc6 *tc6, int addr,
+					    int devnum, int regnum)
+{
+	u32 reg_val;
+	int ret;
+
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_ADDR);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C45);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, devnum);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DATA, regnum);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(0), reg_val);
+	if (ret)
+		return ret;
+

drivers/net/ethernet/oa_tc6.c int oa_tc6_write_register_mms(struct oa_tc6 *tc6, u8 mms, u16 address, · line 506

Quoted 10 lines
drivers/net/ethernet/oa_tc6.c +10 -0
+	reg_val = FIELD_PREP(OA_TC6_MDIOACC_OP, OA_TC6_MDIOACC_OP_RD);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_ST, OA_TC6_MDIOACC_ST_C45);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_PRTAD, addr);
+	reg_val |= FIELD_PREP(OA_TC6_MDIOACC_DEVAD, devnum);
+
+	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(1), reg_val);
+	if (ret)
+		return ret;
+
+	ret = oa_tc6_mdioacc_wait_done(tc6, &reg_val);

[Severity: Medium]
This one depends on how a MAC-PHY executes the MDIOACC frames. The code doesn't describe that, and I couldn't check it against the OA TC6 specification, so this may well be fine.

The ADDRESS frame is written to MDIOACC0 and the READ frame to MDIOACC1, in two separate SPI control transactions. Nothing waits for TRDONE in MDIOACC0, and oa_tc6_mdioacc_wait_done() only polls MDIOACC1. oa_tc6_indirect_mdiobus_write_c45() uses the same split sequence.

For Clause 22, oa_tc6_indirect_mdiobus_read() and oa_tc6_indirect_mdiobus_write() write their only frame to MDIOACC1:

	ret = oa_tc6_write_register(tc6, OA_TC6_REG_MDIOACC(1), reg_val);

The adin1110.c driver uses the same register layout. It puts its single C22 frame in MDIOACC0 (ADIN1110_MDIOACC, 0x20) and polls that register.

Suppose a MAC-PHY starts at MDIOACC0 and stops at the first entry that already has TRDONE set. Would a C22 frame written only to MDIOACC1 ever run? Would the C45 sequence stop after the ADDRESS frame, because MDIOACC1 still has TRDONE set from the previous transaction?

In that case oa_tc6_mdioacc_wait_done() would time out after 30ms. The error would propagate out of the C22/C45 bus scan, and mdiobus_register() and oa_tc6_init() would fail.

On a MAC-PHY that runs one frame per register write, could the MDIOACC1 write arrive while the ADDRESS frame is still on the wire?

This sequence apparently works on the ADIN1110. The framework, though, claims support for any MAC-PHY that reports IPRAC. Would it be more robust to write both C45 frames in one burst with oa_tc6_write_registers(tc6, OA_TC6_REG_MDIOACC(0), vals, 2), and to use MDIOACC0 for C22 as adin1110.c does? That would also save one SPI transfer per C45 access.

Quoted 5 lines
drivers/net/ethernet/oa_tc6.c +4 -0
+	if (ret)
+		return ret;
+
+	return oa_tc6_mdioacc_read_data(reg_val);
 }

[ ... ]

Quoted 8 lines
drivers/net/ethernet/oa_tc6.c +2 -0
@@ -533,8 +673,21 @@ EXPORT_SYMBOL_GPL(oa_tc6_mdiobus_write_c45);
 
 static int oa_tc6_mdiobus_register(struct oa_tc6 *tc6)
 {
+	u32 regval;
 	int ret;
 
+	ret = oa_tc6_read_register(tc6, OA_TC6_REG_STDCAP, &regval);

drivers/net/ethernet/oa_tc6.c EXPORT_SYMBOL_GPL(oa_tc6_mdiobus_write_c45); · line 689

Quoted 10 lines
drivers/net/ethernet/oa_tc6.c +10 -0
+	if (ret)
+		return ret;
+
+	if (!(regval & OA_TC6_STDCAP_DIRECT_PHY_REG_ACCESS)) {
+		if (!(regval & OA_TC6_STDCAP_INDIRECT_PHY_REG_ACCESS)) {
+			netdev_err(tc6->netdev, "MDIO direct/indirect access not supported\n");
+			return -ENODEV;
+		}
+		tc6->mdio_indirect_mode = true;
+	}

[Severity: Low]
In indirect mode, oa_tc6_mdiobus_register() still installs read_c45 and write_c45, and it doesn't set phy_mask. Does this make the phylib C45 bus scan very expensive over SPI?

In direct mode, oa_tc6_mdiobus_read() ignores addr. The C22 scan fills mdio_map[] at every address, and mdiobus_scan_bus_c45() then skips all of them because they are already populated.

In indirect mode, PRTAD is encoded, so the integrated PHY answers at only one address. __mdiobus_register() then runs the C45 scan over the other 31 addresses:

drivers/net/phy/mdio_bus_provider.c:__mdiobus_register() {
    ...
	prevent_c45_scan = mdiobus_prevent_c45_scan(bus);

	if (!prevent_c45_scan && bus->read_c45) {
		err = mdiobus_scan_bus_c45(bus);
    ...
}

mdiobus_prevent_c45_scan() only blocks the scan for Micrel OUIs.

At each empty address, oa_tc6_mdioacc_read_data() returns 0xffff on TAERR. get_phy_c45_ids() therefore sees devices-in-package as all ones and walks every MMD, which is about 62 indirect C45 reads per address.

Each of those reads is an MDIOACC0 write, an MDIOACC1 write and at least one MDIOACC1 poll read, usually with a 100us sleep in read_poll_timeout(). That comes to roughly 31 * 62 * 3, or more than 5,700 SPI control transactions during probe.

adin1140.c sets phy_mask = GENMASK(31, 1) on its OA TC6 MDIO bus, and adin1110.c sets phy_mask = ~GENMASK(2, 0). Could the scan be limited with phy_mask here as well? Alternatively, could the C45 pass be skipped once the C22 scan has found the PHY?

Quoted 3 lines
drivers/net/ethernet/oa_tc6.c +0 -0
 	tc6->mdiobus = mdiobus_alloc();
 	if (!tc6->mdiobus) {
 		netdev_err(tc6->netdev, "MDIO bus alloc failed\n");

[ ... ]

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123115743.29523-1-iustin.stolniceanu%40analog.com
#5 lore raw

PATCH v3 4/7 net: phy: adin1100: Add separate driver entries for ADIN1110/ADIN2111

In reply to Iustin Stolniceanu

The ADIN1100, ADIN1110 and ADIN2111 report different model numbers in bits [9:4] of PHY_ID2 (0x8, 0x9 and 0xa), with the silicon revision in bits [3:0]. A single phy_driver entry with the 0xffffffcf mask currently binds all three by ignoring bits [5:4] of the model number.

Use one phy_driver entry per device, matched with PHY_ID_MATCH_EXACT(), so that, as before, only revision 1 of each device binds to this driver. The old mask also matched model 0xb, which no datasheet lists, so no known device is affected. This allows device specific callbacks to be set in a following patch. The callbacks are unchanged, so this is not a functional change apart from the reported driver name.

---
 drivers/net/phy/adin1100.c | 35 +++++++++++++++++++++++++++++++++--
 1 file changed, 33 insertions(+), 2 deletions(-)
drivers/net/phy/adin1100.c +33 -2
index f845b440aaef..a69c3228961e 100644
@@ -322,8 +322,7 @@ static int adin_probe(struct phy_device *phydev)
 
 static struct phy_driver adin_driver[] = {
 	{
-		.phy_id			= PHY_ID_ADIN1100,
-		.phy_id_mask		= 0xffffffcf,
+		PHY_ID_MATCH_EXACT(PHY_ID_ADIN1100),
 		.name			= "ADIN1100",
 		.get_features		= adin_get_features,
 		.soft_reset		= adin_soft_reset,
@@ -338,6 +337,38 @@ static struct phy_driver adin_driver[] = {
 		.get_sqi		= adin_get_sqi,
 		.get_sqi_max		= adin_get_sqi_max,
 	},
+	{
+		PHY_ID_MATCH_EXACT(PHY_ID_ADIN1110),
+		.name			= "ADIN1110",
+		.get_features		= adin_get_features,
+		.soft_reset		= adin_soft_reset,
+		.probe			= adin_probe,
+		.config_aneg		= adin_config_aneg,
+		.read_status		= adin_read_status,
+		.config_intr		= adin_config_intr,
+		.handle_interrupt	= adin_phy_handle_interrupt,
+		.set_loopback		= adin_set_loopback,
+		.suspend		= adin_suspend,
+		.resume			= adin_resume,
+		.get_sqi		= adin_get_sqi,
+		.get_sqi_max		= adin_get_sqi_max,
+	},
+	{
+		PHY_ID_MATCH_EXACT(PHY_ID_ADIN2111),
+		.name			= "ADIN2111",
+		.get_features		= adin_get_features,
+		.soft_reset		= adin_soft_reset,
+		.probe			= adin_probe,
+		.config_aneg		= adin_config_aneg,
+		.read_status		= adin_read_status,
+		.config_intr		= adin_config_intr,
+		.handle_interrupt	= adin_phy_handle_interrupt,
+		.set_loopback		= adin_set_loopback,
+		.suspend		= adin_suspend,
+		.resume			= adin_resume,
+		.get_sqi		= adin_get_sqi,
+		.get_sqi_max		= adin_get_sqi_max,
+	},
 };
 
 module_phy_driver(adin_driver);
Signature · 1 line
2.43.0
#6 lore raw

PATCH v3 5/7 net: phy: adin1100: Skip the soft reset on ADIN1110/ADIN2111

In reply to Iustin Stolniceanu

The ADIN1110 and ADIN2111 MAC-PHYs integrate the ADIN1100 PHY and use this driver. On these devices, CRSM_SFT_RST resets the whole chip, not only the PHY, undoing the configuration done by the MAC driver before the PHY is attached. MDIO reads also return stale data until the reset completes.

This is not an issue with the generic SPI protocol, where the adin1110 driver configures the MAC in ndo_open, after phy_connect(). The OPEN Alliance TC6 protocol support, added in a following patch, configures the device in oa_tc6_init() before the PHY is attached, and the configuration would be lost.

The MAC driver already resets the chip before attaching the PHY, so don't set .soft_reset for these devices.

---
 drivers/net/phy/adin1100.c | 2 --
 1 file changed, 2 deletions(-)
drivers/net/phy/adin1100.c +0 -2
index a69c3228961e..bc7214b73505 100644
@@ -341,7 +341,6 @@ static struct phy_driver adin_driver[] = {
 		PHY_ID_MATCH_EXACT(PHY_ID_ADIN1110),
 		.name			= "ADIN1110",
 		.get_features		= adin_get_features,
-		.soft_reset		= adin_soft_reset,
 		.probe			= adin_probe,
 		.config_aneg		= adin_config_aneg,
 		.read_status		= adin_read_status,
@@ -357,7 +356,6 @@ static struct phy_driver adin_driver[] = {
 		PHY_ID_MATCH_EXACT(PHY_ID_ADIN2111),
 		.name			= "ADIN2111",
 		.get_features		= adin_get_features,
-		.soft_reset		= adin_soft_reset,
 		.probe			= adin_probe,
 		.config_aneg		= adin_config_aneg,
 		.read_status		= adin_read_status,
Signature · 1 line
2.43.0
#7 lore raw

Re: [PATCH net-next v3 5/7] net: phy: adin1100: Skip the soft reset on ADIN1110/ADIN2111

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you…

Thank you for your contribution! Sashiko AI review found more severe issue(s) in other patches of this series. This mail is only an FYI, in case you want to address the nit picks below when you respin.

Low priority / nit picks for your consideration:

- [Low] The commit message claims the whole-chip reset done by CRSM_SFT_RST "is not an issue with the generic SPI protocol" because…
- [Low] The patch justifies dropping .soft_reset with "The MAC driver already resets the chip before attaching the PHY".

--

net: phy: adin1100: Skip the soft reset on ADIN1110/ADIN2111

This commit removes .soft_reset from the ADIN1110 and ADIN2111 entries in the adin1100 PHY driver. On these chips CRSM_SFT_RST resets the whole MAC-PHY, not only the PHY. The change prepares for OPEN Alliance TC6 support, which configures the device before the PHY is attached.

Quoted 5 lines

This is not an issue with the generic SPI protocol, where the adin1110 driver configures the MAC in ndo_open, after phy_connect(). The OPEN Alliance TC6 protocol support, added in a following patch, configures the device in oa_tc6_init() before the PHY is attached, and the configuration would be lost.

[Severity: Low]
Is this accurate for the existing generic SPI driver? After ndo_open, phylib can still call phy_init_hw() -> drv->soft_reset on at least two paths.

The first path is system resume. adin1110 has no PM callbacks and does not set phydev->mac_managed_pm, and adin_suspend is set. With WoL off this gives:

mdio_bus_phy_suspend()
...
mdio_bus_phy_resume()
phy_init_hw()
adin_soft_reset()

On ADIN2111 this happens once for each PHY.

The second path is an SIOCSMIIREG write of BMCR_RESET while the interface is up:

adin1110_ioctl() /* only when netif_running() */
phy_do_ioctl()

    phy_mii_ioctl()
      phy_init_hw()
        adin_soft_reset()

On both paths the whole-chip reset would wipe the setup done in adin1110_net_open():

	ret = adin1110_write_reg(priv, ADIN1110_CONFIG2, ADIN1110_CRC_APPEND);

It would also wipe the IMASK1 interrupt enables and the MAC address/filter slots. The interface would stay broken until it is reopened.

If that's right, this patch also fixes a runtime problem for current generic SPI users. Could the commit message describe that, and add a
Fixes: tag so the change can be considered for stable? .soft_reset has been set for these PHY IDs since the IDs were added.

Quoted 13 lines
drivers/net/phy/adin1100.c +0 -1
index a69c3228961e9..bc7214b735057 100644
@@ -341,7 +341,6 @@ static struct phy_driver adin_driver[] = {
 		PHY_ID_MATCH_EXACT(PHY_ID_ADIN1110),
 		.name			= "ADIN1110",
 		.get_features		= adin_get_features,
-		.soft_reset		= adin_soft_reset,
 		.probe			= adin_probe,
 		.config_aneg		= adin_config_aneg,
 		.read_status		= adin_read_status,

drivers/net/phy/adin1100.c static struct phy_driver adin_driver[] = { · line 361

Quoted 7 lines
drivers/net/phy/adin1100.c +0 -1
@@ -357,7 +356,6 @@ static struct phy_driver adin_driver[] = {
 		PHY_ID_MATCH_EXACT(PHY_ID_ADIN2111),
 		.name			= "ADIN2111",
 		.get_features		= adin_get_features,
-		.soft_reset		= adin_soft_reset,
 		.probe			= adin_probe,
 		.config_aneg		= adin_config_aneg,
 		.read_status		= adin_read_status,

[Severity: Low]
The commit message says "The MAC driver already resets the chip before attaching the PHY". On the generic SPI path, does anything wait for that reset to finish?

adin1110_probe() checks only the return value of the SPI write, then registers the MDIO bus and connects the PHYs:

drivers/net/ethernet/adi/adin1110.c:adin1110_probe() {
    ...
	ret = adin1110_write_reg(priv, ADIN1110_RESET, ADIN1110_SWRESET);
	if (ret < 0)
		return ret;

	ret = adin1110_register_mdiobus(priv, dev);
    ...
	return adin1110_probe_netdevs(priv);
}

There is no STATUS0 RESETC poll and no delay here. The 90 ms fsleep in adin1110_check_spi() only runs with the optional reset GPIO, and it runs before the SWRESET.

Before this patch, adin_soft_reset() polled ADIN_CRSM_STAT for ADIN_CRSM_SYS_RDY, for up to 30 ms, before any PHY register write at attach time. With .soft_reset now NULL, the attach path is:

adin1110_probe_netdevs()
phy_connect()
phy_attach_direct()
phy_init_hw()
adin_config_intr() /* read IRQ status, RMW IRQ mask */
phy_resume()
adin_resume() /* writes CRSM_SFT_PD_CNTRL */

The commit message itself says MDIO data is stale until the reset completes. Could these writes race with the unconfirmed SWRESET and be lost?

The impact today looks limited:

- phy_start() calls __phy_resume() again at ndo_open, so adin_resume() runs a second time.
- The adin1110 mii_bus leaves irq[] at PHY_POLL, so the IRQ mask write has no functional effect.
- Before this patch, the MDIO bus scan and the adin_get_features() reads already ran right after the SWRESET without any wait.

Still, any PHY configuration added at attach time for these IDs could be silently lost. Should adin1110_probe() wait for the reset to complete before calling adin1110_register_mdiobus()?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123115743.29523-1-iustin.stolniceanu%40analog.com
#8 lore raw

PATCH v3 6/7 dt-bindings: net: adi,adin1110: Add adi,spi-oa-tc6

In reply to Iustin Stolniceanu

From: Ciprian Regus <[email protected]>

The ADIN1110 and ADIN2111 support two SPI host interface protocols:
the generic SPI protocol and the OPEN Alliance TC6 protocol. The protocol is selected by the state of the SPI_CFG1 pin, which the device latches when it comes out of reset, together with SPI_CFG0, which selects CRC (generic SPI) or protection (OPEN Alliance) mode.

The protocol is set by the board hardware, so the driver must know it in advance. Add a boolean property to describe a device configured for the OPEN Alliance TC6 protocol. Without it, the generic SPI protocol is assumed, as before.

adi,spi-crc enables the CRC of the generic SPI protocol, so it is not allowed together with adi,spi-oa-tc6. The OPEN Alliance protection mode needs no property, as the driver reads it from the PROTE bit in CONFIG0.

---
 .../devicetree/bindings/net/adi,adin1110.yaml | 20 +++++++++++++++----
 1 file changed, 16 insertions(+), 4 deletions(-)
Documentation/devicetree/bindings/net/adi,adin1110.yaml +16 -4
index 0a73e01d7f97..f9efa0e614d6 100644
@@ -25,10 +25,6 @@ description: |
   The device has a 4-wire SPI interface for communication
   between the MAC and host processor.
 
-allOf:
-  - $ref: ethernet-controller.yaml#
-  - $ref: /schemas/spi/spi-peripheral-props.yaml#
-
 properties:
   compatible:
     enum:
@@ -43,6 +39,12 @@ properties:
       Enable CRC8 checks on SPI read/writes.
     type: boolean
 
+  adi,spi-oa-tc6:
+    description:
+      The device is configured, through the SPI_CFG1 pin, for the
+      OPEN Alliance TC6 protocol instead of the generic SPI one.
+    type: boolean
+
   interrupts:
     maxItems: 1
 
@@ -55,6 +57,16 @@ required:
   - reg
   - interrupts
 
+allOf:
+  - $ref: ethernet-controller.yaml#
+  - $ref: /schemas/spi/spi-peripheral-props.yaml#
+  - if:
+      required:
+        - adi,spi-oa-tc6
+    then:
+      properties:
+        adi,spi-crc: false
+
 unevaluatedProperties: false
 
 examples:
Signature · 1 line
2.43.0
#9 lore raw

PATCH v3 7/7 net: ethernet: adi: adin1110: Add OA TC6 protocol support for ADIN1110

In reply to Iustin Stolniceanu

From: Ciprian Regus <[email protected]>

The ADIN1110 and ADIN2111 support two SPI host interface protocols, the generic SPI protocol and the OPEN Alliance TC6 protocol. The protocol is selected by the state of the SPI_CFG1 pin, which the device latches when it comes out of reset. The driver currently supports only the generic SPI protocol.

Add support for the OPEN Alliance TC6 protocol on the ADIN1110, using the oa_tc6 framework, when the adi,spi-oa-tc6 property is set. The framework handles the data transfers and the MDIO bus. Register accesses go through read_reg/write_reg callbacks, so the existing MAC configuration code is shared by both protocols. The ADIN1110 specific MAC registers are in MMS 1.

The framework does not append the FCS to transmitted frames, so set CRC_APPEND in CONFIG2 to let the MAC append it. Also set the port state to forwarding on open, as the generic SPI path does, otherwise the broadcast and multicast filters drop all received frames.

The MAC filter is not programmed with the unicast and multicast address lists, so accept all multicast frames when the multicast list is not empty, and do not set IFF_UNICAST_FLT. The core then enables promiscuous mode for secondary unicast addresses.

The ADIN2111 is not supported in OPEN Alliance TC6 mode yet, and probe fails with -ENODEV.

No register reports the selected protocol, so the driver relies on adi,spi-oa-tc6 matching the board strapping. If the MAC-PHY gives no valid OA TC6 reply during initialization, or the PHY ID does not match, probe fails with -ENODEV and a message pointing at the strap and the property. The generic SPI path now does the same on a PHY ID mismatch, instead of returning -EIO.

---
 drivers/net/ethernet/adi/Kconfig    |   1 +
 drivers/net/ethernet/adi/adin1110.c | 208 +++++++++++++++++++++++++++-
 2 files changed, 205 insertions(+), 4 deletions(-)
drivers/net/ethernet/adi/Kconfig +1 -0
index bdb8ff7d15da..c35f68814c21 100644
@@ -22,6 +22,7 @@ config ADIN1110
 	depends on SPI && NET_SWITCHDEV
 	select CRC8
 	select PHYLIB
+	select OA_TC6
 	help
 	  Say yes here to build support for Analog Devices ADIN1110
 	  Low Power 10BASE-T1L Ethernet MAC-PHY.
drivers/net/ethernet/adi/adin1110.c +204 -4

309 lines not on this page · raw message

Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH net-next v3 7/7] net: ethernet: adi: adin1110: Add OA TC6 protocol support for ADIN1110

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider.

Critical: 0 · High: 0 · Medium: 1 · Low: 1

If you believe none of the issues are legitimate, please reply to each issue of Medium severity or higher and explain why the AI is wrong. If any of them are legitimate and you plan to respin, please let patchwork know by including "pw-bot: cr" as a separate line at the end of your reply (one such reply per series is enough).

- [Medium] On the new OA TC6 path, the ADIN1110 hardware reset is left to oa_tc6_init(), which does not follow the reset constraints the driver…
- [Low] The strap/property hint in adin1110_oa_tc6_probe() (drivers/net/ethernet/adi/adin1110.c) is printed in the wrong cases.

--

net: ethernet: adi: adin1110: Add OA TC6 protocol support for ADIN1110

This adds OPEN Alliance TC6 SPI protocol support for the ADIN1110. It uses the oa_tc6 framework and is enabled by the adi,spi-oa-tc6 property. Register accesses go through read_reg/write_reg callbacks so the MAC configuration code is shared by both protocols, and the ADIN2111 is rejected with -ENODEV in TC6 mode.

Quoted 4 lines
drivers/net/ethernet/adi/adin1110.c +0 -0
index 10e7ef33be108..72710d3edd7b3 100644

[ ... ]

Quoted 1 line
drivers/net/ethernet/adi/adin1110.c +0 -0
@@ -1115,14 +1230,91 @@ static int adin1110_check_spi(struct adin1110_priv *priv)

[ ... ]

Quoted 2 lines
drivers/net/ethernet/adi/adin1110.c +2 -0
+static int adin1110_oa_tc6_probe(struct adin1110_priv *priv)
+{

[ ... ]

drivers/net/ethernet/adi/adin1110.c static int adin1110_check_spi(struct adin1110_priv *priv) · line 1280

Quoted 7 lines
drivers/net/ethernet/adi/adin1110.c +7 -0
+	/* oa_tc6_init() attaches the PHY, which looks at netdev_ops. */
+	netdev->netdev_ops = &adin1110_tc6_netdev_ops;
+
+	quirks.hwreset_settle_us = 50000;
+	quirks.softreset_settle_us = 10000;
+
+	port_priv->tc6 = oa_tc6_init(priv->spidev, netdev, &quirks);

[Severity: Medium]
Does the reset done by oa_tc6_init() meet the ADIN1110 reset requirements that this driver documents?

The generic SPI path does this in adin1110_check_spi():

	if (reset_gpio) {
		/* MISO pin is used for internal configuration, can't have
		 * anyone else disturbing the SDO line.
		 */
		spi_bus_lock(priv->spidev->controller);

		gpiod_set_value(reset_gpio, 1);
		fsleep(10000);
		gpiod_set_value(reset_gpio, 0);

		/* Need to wait 90 ms before interacting with
		 * the MAC after a HW reset.
		 */
		fsleep(90000);

		spi_bus_unlock(priv->spidev->controller);
	}

The TC6 path does this in oa_tc6_init():

	if (tc6->reset_gpio) {
		...
		fsleep(10);
		gpiod_set_value_cansleep(tc6->reset_gpio, 0);
		fsleep(tc6->quirks.hwreset_settle_us);
	}

The two sequences differ in three ways:

- Reset is held for about 10 us instead of 10 ms.
- The SPI bus is not locked. On a shared bus, another device's transfer could drive MISO while the ADIN1110 comes out of reset. The earlier commit in this series, "net: ethernet: oa_tc6: Allow custom reset settle time values", says the ADIN1110 tristates its SDO pin during reset.
- hwreset_settle_us is 50 ms here. The comment in adin1110_check_spi() says 90 ms is needed.

If the 90 ms wait or the bus lock is really required, could the first control access in oa_tc6_check_ctrl_protection() reach a device that is not ready? That would return -EPROTO, which is then reported as a strap problem with -ENODEV. Or is the 90 ms comment in adin1110_check_spi() stale?

Quoted 5 lines
drivers/net/ethernet/adi/adin1110.c +5 -0
+	if (PTR_ERR_OR_ZERO(port_priv->tc6) == -EPROTO)
+		return dev_err_probe(dev, -ENODEV,
+				     "no OA TC6 reply, check the SPI_CFG1 strap and adi,spi-oa-tc6\n");
+	if (IS_ERR(port_priv->tc6))
+		return PTR_ERR(port_priv->tc6);

[ ... ]

drivers/net/ethernet/adi/adin1110.c static int adin1110_check_spi(struct adin1110_priv *priv) · line 1300

Quoted 7 lines
drivers/net/ethernet/adi/adin1110.c +7 -0
+	ret = adin1110_read_reg(priv, ADIN1110_PHY_ID, &val);
+	if (ret < 0)
+		return ret;
+
+	if (val != priv->cfg->phy_id_val)
+		return dev_err_probe(dev, -ENODEV, "PHY ID expected: %x, read: %x\n",
+				     priv->cfg->phy_id_val, val);

[Severity: Low]
The commit message says:

If the MAC-PHY gives no valid OA TC6 reply during initialization, or the PHY ID does not match, probe fails with -ENODEV and a message pointing at the strap and the property.

This PHY ID mismatch message in adin1110_oa_tc6_probe() has no strap or property hint. The matching check in adin1110_check_spi() gains one in this same patch:

"PHY ID expected: %x, read: %x, check the SPI_CFG1 strap and adi,spi-oa-tc6\n"

Should the two messages match?

There is a related question about the -EPROTO check above it. Does -EPROTO from oa_tc6_init() really mean "no OA TC6 reply"? In oa_tc6.c it is the generic result of any failed control reply check. For example, oa_tc6_check_ctrl_read_reply() has:

	if (*tx_buf != *rx_buf)
		return -EPROTO;
	...
			if (complement != ~reply)
				return -EPROTO;

oa_tc6_check_ctrl_write_reply() also returns -EPROTO when its memcmp() fails.

These checks run on every control access in every phase of oa_tc6_init(): the protection check, soft reset, interrupt unmask, PHY/MDIO init and enabling data transfer. oa_tc6_init() passes the errno up unchanged.

A correctly strapped device could get one corrupted reply later in init. Would that be reported as a strap or DT misconfiguration, with probe returning -ENODEV instead of -EPROTO?

Signature · 1 line
Sashiko AI review · https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261123115743.29523-1-iustin.stolniceanu%40analog.com