Skip to contentSkip to conversation

net: dsa: Add Airoha AN8855 support

RFC PATCH Superseded Christian Marangi 4 participants 13 messages Oct 21, 2024 – Oct 24, 2024

Subsystems (6)

v1 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

cover net: dsa: Add Airoha AN8855 support

This small series add the initial support for the Airoha AN8855 Switch.

It's a 5 port Gigabit Switch with SGMII/HSGMII upstream port.

This is starting to get in the wild and there are already some router having this switch chip.

It's conceptually similar to mediatek switch but register and bits are different. And there is that massive Hell that is the PCS configuration.
Saddly for that part we have absolutely NO documentation currently.

There is this special thing where PHY needs to be calibrated with values from the switch efuse. (the thing have a whole cpu timer and MCU)

Some cleanup API are used and one extra patch for mdio_mutex_nested is introduced. As suggested some time ago, the use of such API is limited to scoped variants and not the guard ones.

Posting as RFC as I expect in later version to add additional feature but this is already working and upstream-ready. So this is really to have a review of the very basic features and if I missed anything in recent implementation of DSA.

Christian Marangi (4):
net: mdio: implement mdio_mutex_nested guard() variant
dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation
net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

 .../bindings/net/dsa/airoha,an8855.yaml       |  146 ++
 MAINTAINERS                                   |   11 +
 drivers/net/dsa/Kconfig                       |    9 +
 drivers/net/dsa/Makefile                      |    1 +
 drivers/net/dsa/an8855.c                      | 2008 +++++++++++++++++
 drivers/net/dsa/an8855.h                      |  492 ++++
 drivers/net/phy/Kconfig                       |    5 +
 drivers/net/phy/Makefile                      |    1 +
 drivers/net/phy/air_an8855.c                  |  187 ++
 include/linux/mdio.h                          |    4 +
 10 files changed, 2864 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
 create mode 100644 drivers/net/dsa/an8855.c
 create mode 100644 drivers/net/dsa/an8855.h
 create mode 100644 drivers/net/phy/air_an8855.c
Signature · 1 line
2.45.2
#1 lore raw

RFC PATCH 1/4 net: mdio: implement mdio_mutex_nested guard() variant

Implement mdio_mutex_nested guard() variant.

guard() comes from the cleanup.h API that defines handy class to handle the lifecycle of a critical section.

Several drivers use of the mutex_lock_nested()/mutex_unlock() function call pair hence it is sensible to provide a variant of the generic guard(mutex), guard(mdio_mutex_nested) so that drivers can be better supported with the call variant "mutex_lock_nested(..., MDIO_MUTEX_NESTED)"

Example usage:

guard(mutex_lock_nested)(&bus->mdio_lock) scoped_guard(mutex_lock_nested, &bus->mdio_lock) { ... }

---
 include/linux/mdio.h | 4 ++++
 1 file changed, 4 insertions(+)
include/linux/mdio.h +4 -0
index efeca5bd7600..3f0691dee46a 100644
@@ -8,6 +8,7 @@
 
 #include <uapi/linux/mdio.h>
 #include <linux/bitfield.h>
+#include <linux/mutex.h>
 #include <linux/mod_devicetable.h>
 
 struct gpio_desc;
@@ -25,6 +26,9 @@ enum mdio_mutex_lock_class {
 	MDIO_MUTEX_NESTED,
 };
 
+DEFINE_GUARD(mdio_mutex_nested, struct mutex *,
+	     mutex_lock_nested(_T, MDIO_MUTEX_NESTED), mutex_unlock(_T))
+
 struct mdio_device {
 	struct device dev;
 
Signature · 1 line
2.45.2
#2 lore raw

RFC PATCH 2/4 dt-bindings: net: dsa: Add Airoha AN8855 Gigabit Switch documentation

In reply to Christian Marangi

Add Airoha AN8855 5 port Gigabit Switch documentation.

The switch node requires an additional mdio node to describe each internal PHY relative offset as the PHY address for the switch match the one for the PHY ports. On top of internal PHY address, the switch base PHY address is added.

Also the switch base PHY address can be configured and changed after the first initialization. On reset, the switch PHY address is ALWAYS 1. This can be configured with the use of "airoha,base_smi_address".

Calibration values might be stored in switch EFUSE and internal PHY might need to be calibrated, in such case, airoha,ext_surge needs to be enabled.

---
 .../bindings/net/dsa/airoha,an8855.yaml       | 146 ++++++++++++++++++
 1 file changed, 146 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml new file +146 -0
new file mode 100644
index 000000000000..861c47df5bde
@@ -0,0 +1,146 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/airoha,an8855.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Airoha AN8855 Gigabit switch
+
+maintainers:
+  - Christian Marangi <[email protected]>
+
+description:
+  Airoha AN8855 is a 5-port Gigabit Switch.
+
+  The switch node requires an additional mdio node to describe each internal
+  PHY relative offset as the PHY address for the switch match the one for
+  the PHY ports. On top of internal PHY address, the switch base PHY address
+  is added.
+
+  Also the switch base PHY address can be configured and changed after the
+  first initialization. On reset, the switch PHY address is ALWAYS 1.
+
+properties:
+  compatible:
+    const: airoha,an8855
+
+  reg:
+    maxItems: 1
+
+  reset-gpios:
+    description:
+      GPIO to be used to reset the whole device
+    maxItems: 1
+
+  airoha,base_smi_address:
+    $ref: /schemas/types.yaml#/definitions/uint32
+    description:
+      Configure and change the base switch PHY address to a new address on
+      the bus.
+      On reset, the switch PHY address is ALWAYS 1.
+    default: 1
+    maximum: 31
+
+  airoha,ext_surge:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Calibrate the internal PHY with the calibration values stored in EFUSE
+      for the r50Ohm values.
+
+  mdio:
+    $ref: /schemas/net/mdio.yaml#
+    unevaluatedProperties: false
+    description: Define the relative address of the internal PHY for each port.
+      Each reg for the PHY is relative to the switch base PHY address.
+
+$ref: dsa.yaml#
+
+required:
+  - compatible
+  - reg
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/gpio/gpio.h>
+
+    mdio {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        switch@1 {
+            compatible = "airoha,an8855";
+            reg = <1>;
+            reset-gpios = <&pio 39 0>;
+
+            airoha,ext_surge;
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                port@0 {
+                    reg = <0>;
+                    label = "lan1";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy0>;
+                };
+
+                port@1 {
+                    reg = <1>;
+                    label = "lan2";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy1>;
+                };
+
+                port@2 {
+                    reg = <2>;
+                    label = "lan3";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy2>;
+                };
+
+                port@3 {
+                    reg = <3>;
+                    label = "lan4";
+                    phy-mode = "internal";
+                    phy-handle = <&internal_phy3>;
+                };
+
+                port@5 {
+                    reg = <5>;
+                    label = "cpu";
+                    ethernet = <&gmac0>;
+                    phy-mode = "2500base-x";
+
+                    fixed-link {
+                        speed = <2500>;
+                        full-duplex;
+                        pause;
+                    };
+                };
+            };
+
+            mdio {
+                #address-cells = <1>;
+                #size-cells = <0>;
+
+                internal_phy0: phy@0 {
+                    reg = <0>;
+                };
+
+                internal_phy1: phy@1 {
+                    reg = <1>;
+                };
+
+                internal_phy2: phy@2 {
+                    reg = <2>;
+                };
+
+                internal_phy3: phy@3 {
+                    reg = <3>;
+                };
+            };
+        };
+    };
Signature · 1 line
2.45.2
#3 lore raw

RFC PATCH 3/4 net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi

Add Airoha AN8855 5-Port Gigabit DSA switch.

---
 MAINTAINERS              |   10 +
 drivers/net/dsa/Kconfig  |    9 +
 drivers/net/dsa/Makefile |    1 +
 drivers/net/dsa/an8855.c | 2008 ++++++++++++++++++++++++++++++++++++++
 drivers/net/dsa/an8855.h |  492 ++++++++++
 5 files changed, 2520 insertions(+)
 create mode 100644 drivers/net/dsa/an8855.c
 create mode 100644 drivers/net/dsa/an8855.h
MAINTAINERS +10 -0
index 16933f9faa0f..e3077d9feee2 100644
@@ -717,6 +717,16 @@ S:	Supported
 F:	fs/aio.c
 F:	include/linux/*aio*.h
 
+AIROHA DSA DRIVER
+M:	Christian Marangi <[email protected]>
+L:	[email protected] (moderated for non-subscribers)
+L:	[email protected] (moderated for non-subscribers)
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
+F:	drivers/net/dsa/an8855.c
+F:	drivers/net/dsa/an8855.h
+
 AIROHA ETHERNET DRIVER
 M:	Lorenzo Bianconi <[email protected]>
 L:	[email protected] (moderated for non-subscribers)
drivers/net/dsa/Kconfig +9 -0
index 2d10b4d6cfbb..6b6d0b7bae72 100644
@@ -24,6 +24,15 @@ config NET_DSA_LOOP
 	  This enables support for a fake mock-up switch chip which
 	  exercises the DSA APIs.
 
+
+config NET_DSA_AN8855
+	tristate "Airoha AN8855 Ethernet switch support"
+	depends on NET_DSA
+	select NET_DSA_TAG_MTK
+	help
+	  This enables support for the Airoha AN8855 Ethernet switch
+	  chip.
+
 source "drivers/net/dsa/hirschmann/Kconfig"
 
 config NET_DSA_LANTIQ_GSWIP
drivers/net/dsa/Makefile +1 -0
index cb9a97340e58..a74afb41a491 100644
@@ -5,6 +5,7 @@ obj-$(CONFIG_NET_DSA_LOOP)	+= dsa_loop.o
 ifdef CONFIG_NET_DSA_LOOP
 obj-$(CONFIG_FIXED_PHY)		+= dsa_loop_bdinfo.o
 endif
+obj-$(CONFIG_NET_DSA_AN8855)	+= an8855.o
 obj-$(CONFIG_NET_DSA_LANTIQ_GSWIP) += lantiq_gswip.o
 obj-$(CONFIG_NET_DSA_MT7530)	+= mt7530.o
 obj-$(CONFIG_NET_DSA_MT7530_MDIO) += mt7530-mdio.o
drivers/net/dsa/an8855.c new file +2008 -0

2,008 lines not on this page · raw message

drivers/net/dsa/an8855.h new file +492 -0

492 lines not on this page · raw message

Signature · 1 line
2.45.2
#4 lore raw

Re: [net-next RFC PATCH 3/4] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

drivers/net/dsa/an8855.c line 111

Quoted 9 lines · Christian Marangi
drivers/net/dsa/an8855.c new file +9 -0
+static int an8855_mii_read32(struct mii_bus *bus, u8 phy_id, u32 reg, u32 *val)
+{
+	u16 lo, hi;
+	int ret;
+
+	ret = bus->write(bus, phy_id, 0x1f, 0x4);
+	ret = bus->write(bus, phy_id, 0x10, 0);
+
+	ret = bus->write(bus, phy_id, 0x15, ((reg >> 16) & 0xFFFF));

These assignments above are useless on their own. What if one of them fails?

Please also consider __mdiobus_write() and __mdiobus_read() which will check that the bus lock is held, and also give the ability to trace the bus activity.

drivers/net/dsa/an8855.c line 120

Quoted 9 lines
drivers/net/dsa/an8855.c new file +9 -0
+	ret = bus->write(bus, phy_id, 0x16, (reg & 0xFFFF));
+	if (ret < 0) {
+		dev_err_ratelimited(&bus->dev,
+				    "failed to read an8855 register\n");
+		return ret;
+	}
+
+	lo = bus->read(bus, phy_id, 0x18);
+	hi = bus->read(bus, phy_id, 0x17);

What if one of these fails, and the negative value gets clamped to a u16?

Quoted 12 lines
drivers/net/dsa/an8855.c new file +12 -0
+
+	ret = bus->write(bus, phy_id, 0x1f, 0);
+	if (ret < 0) {
+		dev_err_ratelimited(&bus->dev,
+				    "failed to read an8855 register\n");
+		return ret;
+	}
+
+	*val = (hi << 16) | (lo & 0xffff);
+
+	return 0;
+}

drivers/net/dsa/an8855.c line 142

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+
+static int an8855_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
+{
+	struct an8855_priv *priv = ctx;
+	struct mii_bus *bus = priv->bus;
+	int ret;
+
+	scoped_guard(mdio_mutex_nested, &bus->mdio_lock)
+		ret = an8855_mii_read32(bus, priv->phy_base,
+					reg, val);

I'm really not a fan of these non-C like code structures that make the code harder to review, and can add (and already have resulted in) bugs, but everyone to their own. Al Viro found a whole new class of bug caused by these magic things. I'd much prefer explicit C code that can be read and reviewed over "let the compiler do magic" stuff.

Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+
+	return ret < 0 ? ret : 0;
+}
+
+static int an8855_mii_write32(struct mii_bus *bus, u8 phy_id, u32 reg, u32 val)
+{

drivers/net/dsa/an8855.c line 158

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	int ret;
+
+	ret = bus->write(bus, phy_id, 0x1f, 0x4);
+	ret = bus->write(bus, phy_id, 0x10, 0);
+
+	ret = bus->write(bus, phy_id, 0x11, ((reg >> 16) & 0xFFFF));
+	ret = bus->write(bus, phy_id, 0x12, (reg & 0xFFFF));
+
+	ret = bus->write(bus, phy_id, 0x13, ((val >> 16) & 0xFFFF));
+	ret = bus->write(bus, phy_id, 0x14, (val & 0xFFFF));

Same as above.

Quoted 8 lines
drivers/net/dsa/an8855.c new file +8 -0
+
+	ret = bus->write(bus, phy_id, 0x1f, 0);
+	if (ret < 0)
+		dev_err_ratelimited(&bus->dev,
+				    "failed to write an8855 register\n");
+
+	return 0;
+}

...

Quoted 15 lines
drivers/net/dsa/an8855.c new file +15 -0
+static int an8855_set_mac_eee(struct dsa_switch *ds, int port,
+			      struct ethtool_keee *eee)
+{
+	struct an8855_priv *priv = ds->priv;
+	u32 reg;
+	int ret;
+
+	if (eee->eee_enabled) {
+		ret = regmap_read(priv->regmap, AN8855_PMCR_P(port), &reg);
+		if (ret)
+			return ret;
+		if (reg & AN8855_PMCR_FORCE_MODE) {
+			switch (reg & AN8855_PMCR_FORCE_SPEED) {
+			case AN8855_PMCR_FORCE_SPEED_1000:
+				reg |= AN8855_PMCR_FORCE_EEE1G;

drivers/net/dsa/an8855.c line 933

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+				break;
+			case AN8855_PMCR_FORCE_SPEED_100:
+				reg |= AN8855_PMCR_FORCE_EEE100;
+				break;
+			default:
+				break;
+			}
+			ret = regmap_write(priv->regmap, AN8855_PMCR_P(port), reg);
+			if (ret)
+				return ret;

What logic are you trying to implement here? It looks like you're forcing EEE to be enabled here if AN8855_PMCR_FORCE_MODE was set, which, reading the code in link_{up,down} it always will be when the link happens to be down when the user configures EEE. This makes no sense.

EEE is supposed to be enabled as a result of the PHY's negotiation with the link partner. There shouldn't be any forcing.

drivers/net/dsa/an8855.c line 945

Quoted 12 lines
drivers/net/dsa/an8855.c new file +12 -0
+		}
+		if (eee->tx_lpi_enabled) {
+			ret = regmap_set_bits(priv->regmap, AN8855_PMEEECR_P(port),
+					      AN8855_LPI_MODE_EN);
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_clear_bits(priv->regmap, AN8855_PMEEECR_P(port),
+						AN8855_LPI_MODE_EN);
+			if (ret)
+				return ret;
+		}

Maybe:

		ret = regmap_update_bits(priv->regmap, AN8855_PMEEECR_P(port),
					 AN8855_LPI_MODE_EN,
					 eee->tx_lpi_enabled ?
					   AN8855_LPI_MODE_EN : 0);
		if (ret)
			return ret;

drivers/net/dsa/an8855.c line 956

Quoted 11 lines
drivers/net/dsa/an8855.c new file +11 -0
+	} else {
+		ret = regmap_clear_bits(priv->regmap, AN8855_PMCR_P(port),
+					AN8855_PMCR_FORCE_EEE1G |
+					AN8855_PMCR_FORCE_EEE100);
+		if (ret)
+			return ret;
+
+		ret = regmap_clear_bits(priv->regmap, AN8855_PMEEECR_P(port),
+					AN8855_LPI_MODE_EN);
+		if (ret)
+			return ret;

This probably needs to interact with the link up/down state.

Really, I need to find the time to sort out adding EEE stuff to phylink that is keyed from phylib's implementation, but not at the moment.

Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+	}
+
+	return 0;
+}
+
+static int an8855_get_mac_eee(struct dsa_switch *ds, int port,

drivers/net/dsa/an8855.c line 972

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+			      struct ethtool_keee *eee)
+{
+	struct an8855_priv *priv = ds->priv;
+	u32 reg;
+	int ret;
+
+	ret = regmap_read(priv->regmap, AN8855_PMEEECR_P(port), &reg);
+	if (ret)
+		return ret;
+	eee->tx_lpi_enabled = reg & AN8855_LPI_MODE_EN;

This is fine, the MAC is responsible for LPI transmission.

drivers/net/dsa/an8855.c line 978

Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+
+	ret = regmap_read(priv->regmap, AN8855_CKGCR, &reg);
+	if (ret)
+		return ret;
+	/* Global LPI TXIDLE Threshold, default 60ms (unit 2us) */
+	eee->tx_lpi_timer = FIELD_GET(AN8855_LPI_TXIDLE_THD_MASK, reg) / 500;

Also fine.

drivers/net/dsa/an8855.c line 983

Quoted 5 lines
drivers/net/dsa/an8855.c new file +5 -0
+
+	ret = regmap_read(priv->regmap, AN8855_PMSR_P(port), &reg);
+	if (ret)
+		return ret;
+	eee->eee_active = reg & (AN8855_PMSR_EEE1G | AN8855_PMSR_EEE100M);

This isn't. You're overwriting the value set by genphy_c45_ethtool_get_eee(), which has already determined whether EEE is active from the PHY's negotiation state, and this is what eee_active is supposed to indicate.

Quoted 20 lines
drivers/net/dsa/an8855.c new file +20 -0
+
+	return 0;
+}
+
+static u32 en8855_get_phy_flags(struct dsa_switch *ds, int port)
+{
+	struct an8855_priv *priv = ds->priv;
+	u8 calibration_data[4] = { };
+	u8 shift_sel;
+	u32 val;
+	int ret;
+	int i;
+
+	/* PHY doesn't need calibration */
+	if (!priv->phy_require_calib)
+		return 0;
+
+	/* Read Calibration value */
+	for (i = 0; i < sizeof(u32); i++) {
+		ret = regmap_read(priv->regmap, AN8855_EFUSE_DATA0 +

drivers/net/dsa/an8855.c line 1013

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+				  ((3 + i + (4 * port)) * 4), &val);
+		if (ret)
+			return 0;
+
+		shift_sel = FIELD_GET(AN8855_EFUSE_R50O, val);
+		calibration_data[i] = en8855_get_r50ohm_val(shift_sel);
+	}
+
+	memcpy(&val, calibration_data, sizeof(u32));
+	return val;

Ewwwwwww.

So you're reading from fuses, and then passing them as phy flags. PHY flags are no longer 100% available for whatever you want to use them for - some have standard meanings:

* - Bits [15:0] are free to use by the PHY driver to communicate
* driver specific behavior.
* - Bits [23:16] are currently reserved for future use.
* - Bits [31:24] are reserved for defining generic
* PHY driver behavior.

For example, PHY_F_NO_IRQ and PHY_F_RXC_ALWAYS_ON are already allocated in the top 8 bits.

Quoted 18 lines
drivers/net/dsa/an8855.c new file +18 -0
+static void
+an8855_phylink_mac_config(struct phylink_config *config, unsigned int mode,
+			  const struct phylink_link_state *state)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct dsa_switch *ds = dp->ds;
+	struct an8855_priv *priv;
+	int port = dp->index;
+
+	priv = ds->priv;
+
+	switch (port) {
+	case 0:
+	case 1:
+	case 2:
+	case 3:
+	case 4:
+		return;

drivers/net/dsa/an8855.c line 1209

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	case 5:
+		break;
+	default:
+		dev_err(ds->dev, "unsupported port: %d", port);
+		return;
+	}
+
+	if (state->interface == PHY_INTERFACE_MODE_2500BASEX &&
+	    phylink_autoneg_inband(mode))
+		dev_err(ds->dev, "in-band negotiation unsupported");

Please check this in the PCS code.

Quoted 38 lines
drivers/net/dsa/an8855.c new file +38 -0
+
+	regmap_update_bits(priv->regmap, AN8855_PMCR_P(port),
+			   AN8855_PMCR_IFG_XMIT | AN8855_PMCR_MAC_MODE |
+			   AN8855_PMCR_BACKOFF_EN | AN8855_PMCR_BACKPR_EN,
+			   FIELD_PREP(AN8855_PMCR_IFG_XMIT, 0x1) |
+			   AN8855_PMCR_MAC_MODE | AN8855_PMCR_BACKOFF_EN |
+			   AN8855_PMCR_BACKPR_EN);
+}
+
+static void an8855_phylink_get_caps(struct dsa_switch *ds, int port,
+				    struct phylink_config *config)
+{
+	switch (port) {
+	case 0:
+	case 1:
+	case 2:
+	case 3:
+	case 4:
+		__set_bit(PHY_INTERFACE_MODE_GMII,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+			  config->supported_interfaces);
+		break;
+	case 5:
+		phy_interface_set_rgmii(config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_SGMII,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_2500BASEX,
+			  config->supported_interfaces);
+		break;
+	}
+
+	config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
+				   MAC_10 | MAC_100 | MAC_1000FD;
+}
+
+static void
+an8855_phylink_mac_link_down(struct phylink_config *config, unsigned int mode,

drivers/net/dsa/an8855.c line 1257

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+			     phy_interface_t interface)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct an8855_priv *priv = dp->ds->priv;
+
+	/* Disable TX/RX, force link down */
+	regmap_update_bits(priv->regmap, AN8855_PMCR_P(dp->index),
+			   AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN |
+			   AN8855_PMCR_FORCE_MODE | AN8855_PMCR_FORCE_LNK,
+			   AN8855_PMCR_FORCE_MODE);

Does forcing the link down prevent the AN8855_PMSR_LNK bit being set? If not, please document that here because the current code goes against what's documented in phylink:

* If @mode is not an in-band negotiation mode (as defined by ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* phylink_autoneg_inband()), force the link down and disable any
* Energy Efficient Ethernet MAC configuration. ...

Quoted 460 lines
drivers/net/dsa/an8855.c new file +460 -0
+}
+
+static void
+an8855_phylink_mac_link_up(struct phylink_config *config,
+			   struct phy_device *phydev, unsigned int mode,
+			   phy_interface_t interface, int speed, int duplex,
+			   bool tx_pause, bool rx_pause)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct an8855_priv *priv = dp->ds->priv;
+	int port = dp->index;
+	u32 reg;
+
+	reg = regmap_read(priv->regmap, AN8855_PMCR_P(port), &reg);
+	if (phylink_autoneg_inband(mode)) {
+		reg &= ~AN8855_PMCR_FORCE_MODE;
+	} else {
+		reg |= AN8855_PMCR_FORCE_MODE | AN8855_PMCR_FORCE_LNK;
+
+		reg &= ~AN8855_PMCR_FORCE_SPEED;
+		switch (speed) {
+		case SPEED_10:
+			reg |= AN8855_PMCR_FORCE_SPEED_10;
+			break;
+		case SPEED_100:
+			reg |= AN8855_PMCR_FORCE_SPEED_100;
+			break;
+		case SPEED_1000:
+			reg |= AN8855_PMCR_FORCE_SPEED_1000;
+			break;
+		case SPEED_2500:
+			reg |= AN8855_PMCR_FORCE_SPEED_2500;
+			break;
+		case SPEED_5000:
+			reg |= AN8855_PMCR_FORCE_SPEED_5000;
+			break;
+		}
+
+		reg &= AN8855_PMCR_FORCE_FDX;
+		if (duplex == DUPLEX_FULL)
+			reg |= AN8855_PMCR_FORCE_FDX;
+
+		reg &= AN8855_PMCR_RX_FC_EN;
+		if (rx_pause || dsa_port_is_cpu(dp))
+			reg |= AN8855_PMCR_RX_FC_EN;
+
+		reg &= AN8855_PMCR_TX_FC_EN;
+		if (rx_pause || dsa_port_is_cpu(dp))
+			reg |= AN8855_PMCR_TX_FC_EN;
+
+		/* Disable any EEE options */
+		reg &= ~(AN8855_PMCR_FORCE_EEE5G | AN8855_PMCR_FORCE_EEE2P5G |
+			 AN8855_PMCR_FORCE_EEE1G | AN8855_PMCR_FORCE_EEE100);
+	}
+
+	reg |= AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN;
+
+	regmap_write(priv->regmap, AN8855_PMCR_P(port), reg);
+}
+
+static void an8855_pcs_get_state(struct phylink_pcs *pcs,
+				 struct phylink_link_state *state)
+{
+	struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs);
+	u32 val;
+	int ret;
+
+	ret = regmap_read(priv->regmap, AN8855_PMSR_P(AN8855_CPU_PORT), &val);
+	if (ret < 0) {
+		state->link = false;
+		return;
+	}
+
+	state->link = !!(val & AN8855_PMSR_LNK);
+	state->an_complete = state->link;
+	state->duplex = (val & AN8855_PMSR_DPX) ? DUPLEX_FULL :
+						  DUPLEX_HALF;
+
+	switch (val & AN8855_PMSR_SPEED) {
+	case AN8855_PMSR_SPEED_10:
+		state->speed = SPEED_10;
+		break;
+	case AN8855_PMSR_SPEED_100:
+		state->speed = SPEED_100;
+		break;
+	case AN8855_PMSR_SPEED_1000:
+		state->speed = SPEED_1000;
+		break;
+	case AN8855_PMSR_SPEED_2500:
+		state->speed = SPEED_2500;
+		break;
+	case AN8855_PMSR_SPEED_5000:
+		state->speed = SPEED_5000;
+		break;
+	default:
+		state->speed = SPEED_UNKNOWN;
+		break;
+	}
+
+	if (val & AN8855_PMSR_RX_FC)
+		state->pause |= MLO_PAUSE_RX;
+	if (val & AN8855_PMSR_TX_FC)
+		state->pause |= MLO_PAUSE_TX;
+}
+
+static int an8855_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
+			     phy_interface_t interface,
+			     const unsigned long *advertising,
+			     bool permit_pause_to_mac)
+{
+	struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs);
+	u32 val;
+	int ret;
+
+	switch (interface) {
+	case PHY_INTERFACE_MODE_RGMII:
+		return 0;
+	case PHY_INTERFACE_MODE_SGMII:
+		break;
+	case PHY_INTERFACE_MODE_2500BASEX:
+		if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
+			return -EINVAL;
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*                   !!! WELCOME TO HELL !!!                   */
+
+	/* TX FIR - improve TX EYE */
+	ret = regmap_update_bits(priv->regmap, AN8855_INTF_CTRL_10, GENMASK(21, 16),
+				 FIELD_PREP(GENMASK(21, 16), 0x20));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_INTF_CTRL_10, GENMASK(28, 24),
+				 FIELD_PREP(GENMASK(28, 24), 0x4));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_INTF_CTRL_10, BIT(29));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x0;
+	else
+		val = 0xd;
+	ret = regmap_update_bits(priv->regmap, AN8855_INTF_CTRL_11, GENMASK(5, 0),
+				 FIELD_PREP(GENMASK(5, 0), val));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_INTF_CTRL_11, BIT(6));
+	if (ret)
+		return ret;
+
+	/* RX CDR - improve RX Jitter Tolerance */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x5;
+	else
+		val = 0x6;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_BOT_LIM, GENMASK(26, 24),
+				 FIELD_PREP(GENMASK(26, 24), val));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_BOT_LIM, GENMASK(22, 20),
+				 FIELD_PREP(GENMASK(22, 20), val));
+	if (ret)
+		return ret;
+
+	/* PLL */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x1;
+	else
+		val = 0x0;
+	ret = regmap_update_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_1, GENMASK(3, 2),
+				 FIELD_PREP(GENMASK(3, 2), val));
+	if (ret)
+		return ret;
+
+	/* PLL - LPF */
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(1, 0),
+				 FIELD_PREP(GENMASK(1, 0), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(4, 2),
+				 FIELD_PREP(GENMASK(4, 2), 0x5));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(6) | BIT(7));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(10, 8),
+				 FIELD_PREP(GENMASK(10, 8), 0x3));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(29));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(12) | BIT(13));
+	if (ret)
+		return ret;
+
+	/* PLL - ICO */
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_4, BIT(2));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(14));
+	if (ret)
+		return ret;
+
+	/* PLL - CHP */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x6;
+	else
+		val = 0x4;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(19, 16),
+				 FIELD_PREP(GENMASK(19, 16), val));
+	if (ret)
+		return ret;
+
+	/* PLL - PFD */
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(21, 20),
+				 FIELD_PREP(GENMASK(21, 20), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(25, 24),
+				 FIELD_PREP(GENMASK(25, 24), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(26));
+	if (ret)
+		return ret;
+
+	/* PLL - POSTDIV */
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(22));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(27));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(28));
+	if (ret)
+		return ret;
+
+	/* PLL - SDM */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_4, BIT(3) | BIT(4));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(30));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_SS_LCPLL_PWCTL_SETTING_2,
+				 GENMASK(17, 16),
+				 FIELD_PREP(GENMASK(17, 16), 0x1));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x7a000000;
+	else
+		val = 0x48000000;
+	ret = regmap_write(priv->regmap, AN8855_SS_LCPLL_TDC_FLT_2, val);
+	if (ret)
+		return ret;
+	ret = regmap_write(priv->regmap, AN8855_SS_LCPLL_TDC_PCW_1, val);
+	if (ret)
+		return ret;
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_SS_LCPLL_TDC_FLT_5, BIT(24));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CK_CTRL_0, BIT(8));
+	if (ret)
+		return ret;
+
+	/* PLL - SS */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_3, GENMASK(15, 0));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_4, GENMASK(1, 0));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_3, GENMASK(31, 16));
+	if (ret)
+		return ret;
+
+	/* PLL - TDC */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CK_CTRL_0, BIT(9));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_QP_PLL_SDM_ORD, BIT(3));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_QP_PLL_SDM_ORD, BIT(4));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_RX_DAC_EN, GENMASK(17, 16),
+				 FIELD_PREP(GENMASK(17, 16), 0x2));
+	if (ret)
+		return ret;
+
+	/* TCL Disable (only for Co-SIM) */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PON_RXFEDIG_CTRL_0, BIT(12));
+	if (ret)
+		return ret;
+
+	/* TX Init */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x4;
+	else
+		val = 0x0;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_TX_MODE_16B_EN, BIT(0));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_TX_MODE_16B_EN,
+				 GENMASK(31, 16),
+				 FIELD_PREP(GENMASK(31, 16), val));
+	if (ret)
+		return ret;
+
+	/* RX Control/Init */
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_QP_RXAFE_RESERVE, BIT(11));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x1;
+	else
+		val = 0x2;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_MJV_LIM,
+				 GENMASK(5, 4),
+				 FIELD_PREP(GENMASK(5, 4), val));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_SETVALUE,
+				 GENMASK(28, 25),
+				 FIELD_PREP(GENMASK(28, 25), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_SETVALUE,
+				 GENMASK(31, 29),
+				 FIELD_PREP(GENMASK(31, 29), 0x6));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0xf;
+	else
+		val = 0xc;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_PR_CKREF_DIV1,
+				 GENMASK(12, 8),
+				 FIELD_PREP(GENMASK(12, 8), val));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_PR_KBAND_DIV_PCIE,
+				 GENMASK(12, 8),
+				 FIELD_PREP(GENMASK(12, 8), 0x19));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_CDR_PR_KBAND_DIV_PCIE, BIT(6));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_FORCE_IBANDLPF_R_OFF,
+				 GENMASK(12, 6),
+				 FIELD_PREP(GENMASK(12, 6), 0x21));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_FORCE_IBANDLPF_R_OFF,
+				 GENMASK(17, 16),
+				 FIELD_PREP(GENMASK(17, 16), 0x2));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_CDR_FORCE_IBANDLPF_R_OFF, BIT(13));
+	if (ret)
+		return ret;
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_CDR_PR_KBAND_DIV_PCIE, BIT(30));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_PR_CKREF_DIV1,
+				 GENMASK(26, 24),
+				 FIELD_PREP(GENMASK(26, 24), 0x4));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(priv->regmap, AN8855_RX_CTRL_26, BIT(23));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RX_CTRL_26, BIT(24));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RX_CTRL_26, BIT(26));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_DLY_0, GENMASK(7, 0),
+				 FIELD_PREP(GENMASK(7, 0), 0x6f));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RX_DLY_0, GENMASK(13, 8));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_42, GENMASK(12, 0),
+				 FIELD_PREP(GENMASK(12, 0), 0x150));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_2, GENMASK(28, 16),
+				 FIELD_PREP(GENMASK(28, 16), 0x150));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_PON_RXFEDIG_CTRL_9,
+				 GENMASK(2, 0),
+				 FIELD_PREP(GENMASK(2, 0), 0x1));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_8, GENMASK(27, 16),
+				 FIELD_PREP(GENMASK(27, 16), 0x200));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_8, GENMASK(14, 0),
+				 FIELD_PREP(GENMASK(14, 0), 0xfff));
+	if (ret)
+		return ret;
+
+	/* Frequency meter */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x10;
+	else
+		val = 0x28;
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_5, GENMASK(29, 10),
+				 FIELD_PREP(GENMASK(29, 10), val));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_6, GENMASK(19, 0),
+				 FIELD_PREP(GENMASK(19, 0), 0x64));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_7, GENMASK(19, 0),
+				 FIELD_PREP(GENMASK(19, 0), 0x2710));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_0, BIT(0));
+	if (ret)
+		return ret;
+
+	/* PCS Init */

drivers/net/dsa/an8855.c line 1727

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	if (interface == PHY_INTERFACE_MODE_SGMII &&
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_DISABLED) {
+		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
+					BIT(0));
+		if (ret)
+			return ret;
+		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
+					GENMASK(5, 4));
+		if (ret)
+			return ret;

Do these really need to be done separately, or can the two be combined?

		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
					GENMASK(5, 4) | BIT(0));

?

Quoted 11 lines
drivers/net/dsa/an8855.c new file +11 -0
+	}
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_HSGMII_PCS_CTROL_1, BIT(30));
+	if (ret)
+		return ret;
+
+	if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		/* Set AN Ability - Interrupt */
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN_FORCE_CL37, BIT(0));
+		if (ret)
+			return ret;

drivers/net/dsa/an8855.c line 1748

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+
+		ret = regmap_update_bits(priv->regmap, AN8855_SGMII_REG_AN_13,
+					 GENMASK(5, 0),
+					 FIELD_PREP(GENMASK(5, 0), 0xb));
+		if (ret)
+			return ret;
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN_13, BIT(8));
+		if (ret)
+			return ret;
+	}

Eh?

Quoted 44 lines
drivers/net/dsa/an8855.c new file +44 -0
+
+	/* Rate Adaption - GMII path config. */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+		ret = regmap_clear_bits(priv->regmap, AN8855_RATE_ADP_P0_CTRL_0, BIT(31));
+		if (ret)
+			return ret;
+	} else {
+		if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+			ret = regmap_set_bits(priv->regmap, AN8855_MII_RA_AN_ENABLE, BIT(0));
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_set_bits(priv->regmap, AN8855_RG_AN_SGMII_MODE_FORCE,
+					      BIT(0));
+			if (ret)
+				return ret;
+			ret = regmap_clear_bits(priv->regmap, AN8855_RG_AN_SGMII_MODE_FORCE,
+						GENMASK(5, 4));
+			if (ret)
+				return ret;
+
+			ret = regmap_clear_bits(priv->regmap, AN8855_RATE_ADP_P0_CTRL_0,
+						GENMASK(3, 0));
+			if (ret)
+				return ret;
+		}
+
+		ret = regmap_set_bits(priv->regmap, AN8855_RATE_ADP_P0_CTRL_0, BIT(28));
+		if (ret)
+			return ret;
+	}
+
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_RATE_ADAPT_CTRL_0, BIT(0));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_RATE_ADAPT_CTRL_0, BIT(4));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_RATE_ADAPT_CTRL_0, GENMASK(27, 26));
+	if (ret)
+		return ret;
+
+	/* Disable AN */
+	if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {

drivers/net/dsa/an8855.c line 1802

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN0,
+				      AN8855_SGMII_AN_ENABLE);
+		if (ret)
+			return ret;
+	} else {
+		ret = regmap_clear_bits(priv->regmap, AN8855_SGMII_REG_AN0,
+					AN8855_SGMII_AN_ENABLE);
+		if (ret)
+			return ret;
+	}

Again, using regmap_update_bits() with a mask and value is probably more readable here. This looks like it's twiddling a standard BMCR_ANENABLE bit.

drivers/net/dsa/an8855.c line 1809

Quoted 7 lines
drivers/net/dsa/an8855.c new file +7 -0
+
+	if (interface == PHY_INTERFACE_MODE_SGMII &&
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_DISABLED) {
+		ret = regmap_set_bits(priv->regmap, AN8855_PHY_RX_FORCE_CTRL_0, BIT(4));
+		if (ret)
+			return ret;
+	}

Eh?

Quoted 7 lines
drivers/net/dsa/an8855.c new file +7 -0
+
+	/* Force Speed */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX ||
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX)
+			val = 0x3;
+		else

drivers/net/dsa/an8855.c line 1826

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+			val = 0x2;
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_STS_CTRL_0, BIT(2));
+		if (ret)
+			return ret;
+		ret = regmap_update_bits(priv->regmap, AN8855_SGMII_STS_CTRL_0,
+					 GENMASK(5, 4),
+					 FIELD_PREP(GENMASK(5, 4), val));
+		if (ret)
+			return ret;
+	}

I don't understand why speed should be forced if inband is enabled or we're using 2500base-X.

drivers/net/dsa/an8855.c line 1834

Quoted 8 lines
drivers/net/dsa/an8855.c new file +8 -0
+
+	/* bypass flow control to MAC */
+	ret = regmap_write(priv->regmap, AN8855_MSG_RX_LIK_STS_0, 0x01010107);
+	if (ret)
+		return ret;
+	ret = regmap_write(priv->regmap, AN8855_MSG_RX_LIK_STS_2, 0x00000EEF);
+	if (ret)
+		return ret;

Overall, I'd like more comments about what stuff is doing, especially the AN stuff. I can't make head nor tail of e.g. is there any advertisement being programmed or not.

Also, given that this will be called _on its own_ if the user requests the inband advertisement to be changed, we don't want to unnecessarily disrupt the link. What would happen if this code runs when the link is up?

drivers/net/dsa/an8855.c line 1844

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+
+	return 0;
+}
+
+static void an8855_pcs_an_restart(struct phylink_pcs *pcs)
+{
+	struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs);
+
+	regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN0,
+			AN8855_SGMII_AN_RESTART);

Again, looks like a standard PHY BMCR.

I haven't done a full review, but these are just what I've spotted so far.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!
#5 lore raw

Re: [net-next RFC PATCH 3/4] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

Quoted 51 lines · Russell King (Oracle)

drivers/net/dsa/an8855.c line 111

Quoted 9 lines · Christian Marangi
drivers/net/dsa/an8855.c new file +9 -0
+static int an8855_mii_read32(struct mii_bus *bus, u8 phy_id, u32 reg, u32 *val)
+{
+	u16 lo, hi;
+	int ret;
+
+	ret = bus->write(bus, phy_id, 0x1f, 0x4);
+	ret = bus->write(bus, phy_id, 0x10, 0);
+
+	ret = bus->write(bus, phy_id, 0x15, ((reg >> 16) & 0xFFFF));

These assignments above are useless on their own. What if one of them fails?

Please also consider __mdiobus_write() and __mdiobus_read() which will check that the bus lock is held, and also give the ability to trace the bus activity.

drivers/net/dsa/an8855.c line 120

Quoted 9 lines
drivers/net/dsa/an8855.c new file +9 -0
+	ret = bus->write(bus, phy_id, 0x16, (reg & 0xFFFF));
+	if (ret < 0) {
+		dev_err_ratelimited(&bus->dev,
+				    "failed to read an8855 register\n");
+		return ret;
+	}
+
+	lo = bus->read(bus, phy_id, 0x18);
+	hi = bus->read(bus, phy_id, 0x17);

What if one of these fails, and the negative value gets clamped to a u16?

Quoted 20 lines
drivers/net/dsa/an8855.c new file +20 -0
+
+	ret = bus->write(bus, phy_id, 0x1f, 0);
+	if (ret < 0) {
+		dev_err_ratelimited(&bus->dev,
+				    "failed to read an8855 register\n");
+		return ret;
+	}
+
+	*val = (hi << 16) | (lo & 0xffff);
+
+	return 0;
+}
+
+static int an8855_regmap_read(void *ctx, uint32_t reg, uint32_t *val)
+{
+	struct an8855_priv *priv = ctx;
+	struct mii_bus *bus = priv->bus;
+	int ret;
+
+	scoped_guard(mdio_mutex_nested, &bus->mdio_lock)
Quoted 9 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+		ret = an8855_mii_read32(bus, priv->phy_base,
+					reg, val);

I'm really not a fan of these non-C like code structures that make the code harder to review, and can add (and already have resulted in) bugs, but everyone to their own. Al Viro found a whole new class of bug caused by these magic things. I'd much prefer explicit C code that can be read and reviewed over "let the compiler do magic" stuff.

Eh I hoped some of the cleanup API could be used... I received some request to start using it. I will drop them entirely ok.

Quoted 175 lines
Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+
+	return ret < 0 ? ret : 0;
+}
+
+static int an8855_mii_write32(struct mii_bus *bus, u8 phy_id, u32 reg, u32 val)
+{

drivers/net/dsa/an8855.c line 158

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	int ret;
+
+	ret = bus->write(bus, phy_id, 0x1f, 0x4);
+	ret = bus->write(bus, phy_id, 0x10, 0);
+
+	ret = bus->write(bus, phy_id, 0x11, ((reg >> 16) & 0xFFFF));
+	ret = bus->write(bus, phy_id, 0x12, (reg & 0xFFFF));
+
+	ret = bus->write(bus, phy_id, 0x13, ((val >> 16) & 0xFFFF));
+	ret = bus->write(bus, phy_id, 0x14, (val & 0xFFFF));

Same as above.

Quoted 8 lines
drivers/net/dsa/an8855.c new file +8 -0
+
+	ret = bus->write(bus, phy_id, 0x1f, 0);
+	if (ret < 0)
+		dev_err_ratelimited(&bus->dev,
+				    "failed to write an8855 register\n");
+
+	return 0;
+}

...

Quoted 15 lines
drivers/net/dsa/an8855.c new file +15 -0
+static int an8855_set_mac_eee(struct dsa_switch *ds, int port,
+			      struct ethtool_keee *eee)
+{
+	struct an8855_priv *priv = ds->priv;
+	u32 reg;
+	int ret;
+
+	if (eee->eee_enabled) {
+		ret = regmap_read(priv->regmap, AN8855_PMCR_P(port), &reg);
+		if (ret)
+			return ret;
+		if (reg & AN8855_PMCR_FORCE_MODE) {
+			switch (reg & AN8855_PMCR_FORCE_SPEED) {
+			case AN8855_PMCR_FORCE_SPEED_1000:
+				reg |= AN8855_PMCR_FORCE_EEE1G;

drivers/net/dsa/an8855.c line 933

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+				break;
+			case AN8855_PMCR_FORCE_SPEED_100:
+				reg |= AN8855_PMCR_FORCE_EEE100;
+				break;
+			default:
+				break;
+			}
+			ret = regmap_write(priv->regmap, AN8855_PMCR_P(port), reg);
+			if (ret)
+				return ret;

What logic are you trying to implement here? It looks like you're forcing EEE to be enabled here if AN8855_PMCR_FORCE_MODE was set, which, reading the code in link_{up,down} it always will be when the link happens to be down when the user configures EEE. This makes no sense.

EEE is supposed to be enabled as a result of the PHY's negotiation with the link partner. There shouldn't be any forcing.

drivers/net/dsa/an8855.c line 945

Quoted 12 lines
drivers/net/dsa/an8855.c new file +12 -0
+		}
+		if (eee->tx_lpi_enabled) {
+			ret = regmap_set_bits(priv->regmap, AN8855_PMEEECR_P(port),
+					      AN8855_LPI_MODE_EN);
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_clear_bits(priv->regmap, AN8855_PMEEECR_P(port),
+						AN8855_LPI_MODE_EN);
+			if (ret)
+				return ret;
+		}

Maybe:

		ret = regmap_update_bits(priv->regmap, AN8855_PMEEECR_P(port),
					 AN8855_LPI_MODE_EN,
					 eee->tx_lpi_enabled ?
					   AN8855_LPI_MODE_EN : 0);
		if (ret)
			return ret;

drivers/net/dsa/an8855.c line 956

Quoted 11 lines
drivers/net/dsa/an8855.c new file +11 -0
+	} else {
+		ret = regmap_clear_bits(priv->regmap, AN8855_PMCR_P(port),
+					AN8855_PMCR_FORCE_EEE1G |
+					AN8855_PMCR_FORCE_EEE100);
+		if (ret)
+			return ret;
+
+		ret = regmap_clear_bits(priv->regmap, AN8855_PMEEECR_P(port),
+					AN8855_LPI_MODE_EN);
+		if (ret)
+			return ret;

This probably needs to interact with the link up/down state.

Really, I need to find the time to sort out adding EEE stuff to phylink that is keyed from phylib's implementation, but not at the moment.

Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+	}
+
+	return 0;
+}
+
+static int an8855_get_mac_eee(struct dsa_switch *ds, int port,

drivers/net/dsa/an8855.c line 972

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+			      struct ethtool_keee *eee)
+{
+	struct an8855_priv *priv = ds->priv;
+	u32 reg;
+	int ret;
+
+	ret = regmap_read(priv->regmap, AN8855_PMEEECR_P(port), &reg);
+	if (ret)
+		return ret;
+	eee->tx_lpi_enabled = reg & AN8855_LPI_MODE_EN;

This is fine, the MAC is responsible for LPI transmission.

drivers/net/dsa/an8855.c line 978

Quoted 6 lines
drivers/net/dsa/an8855.c new file +6 -0
+
+	ret = regmap_read(priv->regmap, AN8855_CKGCR, &reg);
+	if (ret)
+		return ret;
+	/* Global LPI TXIDLE Threshold, default 60ms (unit 2us) */
+	eee->tx_lpi_timer = FIELD_GET(AN8855_LPI_TXIDLE_THD_MASK, reg) / 500;

Also fine.

drivers/net/dsa/an8855.c line 983

Quoted 5 lines
drivers/net/dsa/an8855.c new file +5 -0
+
+	ret = regmap_read(priv->regmap, AN8855_PMSR_P(port), &reg);
+	if (ret)
+		return ret;
+	eee->eee_active = reg & (AN8855_PMSR_EEE1G | AN8855_PMSR_EEE100M);

This isn't. You're overwriting the value set by genphy_c45_ethtool_get_eee(), which has already determined whether EEE is active from the PHY's negotiation state, and this is what eee_active is supposed to indicate.

Quoted 20 lines
drivers/net/dsa/an8855.c new file +20 -0
+
+	return 0;
+}
+
+static u32 en8855_get_phy_flags(struct dsa_switch *ds, int port)
+{
+	struct an8855_priv *priv = ds->priv;
+	u8 calibration_data[4] = { };
+	u8 shift_sel;
+	u32 val;
+	int ret;
+	int i;
+
+	/* PHY doesn't need calibration */
+	if (!priv->phy_require_calib)
+		return 0;
+
+	/* Read Calibration value */
+	for (i = 0; i < sizeof(u32); i++) {
+		ret = regmap_read(priv->regmap, AN8855_EFUSE_DATA0 +

drivers/net/dsa/an8855.c line 1013

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+				  ((3 + i + (4 * port)) * 4), &val);
+		if (ret)
+			return 0;
+
+		shift_sel = FIELD_GET(AN8855_EFUSE_R50O, val);
+		calibration_data[i] = en8855_get_r50ohm_val(shift_sel);
+	}
+
+	memcpy(&val, calibration_data, sizeof(u32));
+	return val;

Ewwwwwww.

Quoted 4 lines

So you're reading from fuses, and then passing them as phy flags. PHY flags are no longer 100% available for whatever you want to use them for - some have standard meanings:

Yep this is the main reason of RFC... Any hint on how to handle this?

Actually the Switch have some special regs to access the PHY indirectly so maybe I can do the calibration from the switch but I would really love to find a way to pass these kind of data and handle them entirely in the PHY driver code.

The first solution that comes to mind is shared global header in include/linux/dsa and implement some kind of OPs or additional entry in struct phy to declare a pointer and the size of it? Or with the global header a struct directly? But this would be very special and just for these case of internal PHY.

Quoted 9 lines

* - Bits [15:0] are free to use by the PHY driver to communicate
* driver specific behavior.
* - Bits [23:16] are currently reserved for future use.
* - Bits [31:24] are reserved for defining generic
* PHY driver behavior.

For example, PHY_F_NO_IRQ and PHY_F_RXC_ALWAYS_ON are already allocated in the top 8 bits.

I checked the DSA code and hoped I could use the full register.

Quoted 84 lines
Quoted 18 lines
drivers/net/dsa/an8855.c new file +18 -0
+static void
+an8855_phylink_mac_config(struct phylink_config *config, unsigned int mode,
+			  const struct phylink_link_state *state)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct dsa_switch *ds = dp->ds;
+	struct an8855_priv *priv;
+	int port = dp->index;
+
+	priv = ds->priv;
+
+	switch (port) {
+	case 0:
+	case 1:
+	case 2:
+	case 3:
+	case 4:
+		return;

drivers/net/dsa/an8855.c line 1209

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	case 5:
+		break;
+	default:
+		dev_err(ds->dev, "unsupported port: %d", port);
+		return;
+	}
+
+	if (state->interface == PHY_INTERFACE_MODE_2500BASEX &&
+	    phylink_autoneg_inband(mode))
+		dev_err(ds->dev, "in-band negotiation unsupported");

Please check this in the PCS code.

Quoted 38 lines
drivers/net/dsa/an8855.c new file +38 -0
+
+	regmap_update_bits(priv->regmap, AN8855_PMCR_P(port),
+			   AN8855_PMCR_IFG_XMIT | AN8855_PMCR_MAC_MODE |
+			   AN8855_PMCR_BACKOFF_EN | AN8855_PMCR_BACKPR_EN,
+			   FIELD_PREP(AN8855_PMCR_IFG_XMIT, 0x1) |
+			   AN8855_PMCR_MAC_MODE | AN8855_PMCR_BACKOFF_EN |
+			   AN8855_PMCR_BACKPR_EN);
+}
+
+static void an8855_phylink_get_caps(struct dsa_switch *ds, int port,
+				    struct phylink_config *config)
+{
+	switch (port) {
+	case 0:
+	case 1:
+	case 2:
+	case 3:
+	case 4:
+		__set_bit(PHY_INTERFACE_MODE_GMII,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_INTERNAL,
+			  config->supported_interfaces);
+		break;
+	case 5:
+		phy_interface_set_rgmii(config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_SGMII,
+			  config->supported_interfaces);
+		__set_bit(PHY_INTERFACE_MODE_2500BASEX,
+			  config->supported_interfaces);
+		break;
+	}
+
+	config->mac_capabilities = MAC_ASYM_PAUSE | MAC_SYM_PAUSE |
+				   MAC_10 | MAC_100 | MAC_1000FD;
+}
+
+static void
+an8855_phylink_mac_link_down(struct phylink_config *config, unsigned int mode,

drivers/net/dsa/an8855.c line 1257

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+			     phy_interface_t interface)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct an8855_priv *priv = dp->ds->priv;
+
+	/* Disable TX/RX, force link down */
+	regmap_update_bits(priv->regmap, AN8855_PMCR_P(dp->index),
+			   AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN |
+			   AN8855_PMCR_FORCE_MODE | AN8855_PMCR_FORCE_LNK,
+			   AN8855_PMCR_FORCE_MODE);

Does forcing the link down prevent the AN8855_PMSR_LNK bit being set? If not, please document that here because the current code goes against what's documented in phylink:

Quoted 5 lines

* If @mode is not an in-band negotiation mode (as defined by ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
* phylink_autoneg_inband()), force the link down and disable any
* Energy Efficient Ethernet MAC configuration. ...

Mhhh the force bit just "force" the configutation, AKA it does set the link down. We can keep the link up and just disable TX and RX.

In the current code, I enable force bit, and clear the LINK bit if it was set prev and disable TX and RX.

Soo with the comments, with autoneg I should just disable TX and RX correct?

Quoted 473 lines
Quoted 460 lines
drivers/net/dsa/an8855.c new file +460 -0
+}
+
+static void
+an8855_phylink_mac_link_up(struct phylink_config *config,
+			   struct phy_device *phydev, unsigned int mode,
+			   phy_interface_t interface, int speed, int duplex,
+			   bool tx_pause, bool rx_pause)
+{
+	struct dsa_port *dp = dsa_phylink_to_port(config);
+	struct an8855_priv *priv = dp->ds->priv;
+	int port = dp->index;
+	u32 reg;
+
+	reg = regmap_read(priv->regmap, AN8855_PMCR_P(port), &reg);
+	if (phylink_autoneg_inband(mode)) {
+		reg &= ~AN8855_PMCR_FORCE_MODE;
+	} else {
+		reg |= AN8855_PMCR_FORCE_MODE | AN8855_PMCR_FORCE_LNK;
+
+		reg &= ~AN8855_PMCR_FORCE_SPEED;
+		switch (speed) {
+		case SPEED_10:
+			reg |= AN8855_PMCR_FORCE_SPEED_10;
+			break;
+		case SPEED_100:
+			reg |= AN8855_PMCR_FORCE_SPEED_100;
+			break;
+		case SPEED_1000:
+			reg |= AN8855_PMCR_FORCE_SPEED_1000;
+			break;
+		case SPEED_2500:
+			reg |= AN8855_PMCR_FORCE_SPEED_2500;
+			break;
+		case SPEED_5000:
+			reg |= AN8855_PMCR_FORCE_SPEED_5000;
+			break;
+		}
+
+		reg &= AN8855_PMCR_FORCE_FDX;
+		if (duplex == DUPLEX_FULL)
+			reg |= AN8855_PMCR_FORCE_FDX;
+
+		reg &= AN8855_PMCR_RX_FC_EN;
+		if (rx_pause || dsa_port_is_cpu(dp))
+			reg |= AN8855_PMCR_RX_FC_EN;
+
+		reg &= AN8855_PMCR_TX_FC_EN;
+		if (rx_pause || dsa_port_is_cpu(dp))
+			reg |= AN8855_PMCR_TX_FC_EN;
+
+		/* Disable any EEE options */
+		reg &= ~(AN8855_PMCR_FORCE_EEE5G | AN8855_PMCR_FORCE_EEE2P5G |
+			 AN8855_PMCR_FORCE_EEE1G | AN8855_PMCR_FORCE_EEE100);
+	}
+
+	reg |= AN8855_PMCR_TX_EN | AN8855_PMCR_RX_EN;
+
+	regmap_write(priv->regmap, AN8855_PMCR_P(port), reg);
+}
+
+static void an8855_pcs_get_state(struct phylink_pcs *pcs,
+				 struct phylink_link_state *state)
+{
+	struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs);
+	u32 val;
+	int ret;
+
+	ret = regmap_read(priv->regmap, AN8855_PMSR_P(AN8855_CPU_PORT), &val);
+	if (ret < 0) {
+		state->link = false;
+		return;
+	}
+
+	state->link = !!(val & AN8855_PMSR_LNK);
+	state->an_complete = state->link;
+	state->duplex = (val & AN8855_PMSR_DPX) ? DUPLEX_FULL :
+						  DUPLEX_HALF;
+
+	switch (val & AN8855_PMSR_SPEED) {
+	case AN8855_PMSR_SPEED_10:
+		state->speed = SPEED_10;
+		break;
+	case AN8855_PMSR_SPEED_100:
+		state->speed = SPEED_100;
+		break;
+	case AN8855_PMSR_SPEED_1000:
+		state->speed = SPEED_1000;
+		break;
+	case AN8855_PMSR_SPEED_2500:
+		state->speed = SPEED_2500;
+		break;
+	case AN8855_PMSR_SPEED_5000:
+		state->speed = SPEED_5000;
+		break;
+	default:
+		state->speed = SPEED_UNKNOWN;
+		break;
+	}
+
+	if (val & AN8855_PMSR_RX_FC)
+		state->pause |= MLO_PAUSE_RX;
+	if (val & AN8855_PMSR_TX_FC)
+		state->pause |= MLO_PAUSE_TX;
+}
+
+static int an8855_pcs_config(struct phylink_pcs *pcs, unsigned int neg_mode,
+			     phy_interface_t interface,
+			     const unsigned long *advertising,
+			     bool permit_pause_to_mac)
+{
+	struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs);
+	u32 val;
+	int ret;
+
+	switch (interface) {
+	case PHY_INTERFACE_MODE_RGMII:
+		return 0;
+	case PHY_INTERFACE_MODE_SGMII:
+		break;
+	case PHY_INTERFACE_MODE_2500BASEX:
+		if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED)
+			return -EINVAL;
+
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	/*                   !!! WELCOME TO HELL !!!                   */
+
+	/* TX FIR - improve TX EYE */
+	ret = regmap_update_bits(priv->regmap, AN8855_INTF_CTRL_10, GENMASK(21, 16),
+				 FIELD_PREP(GENMASK(21, 16), 0x20));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_INTF_CTRL_10, GENMASK(28, 24),
+				 FIELD_PREP(GENMASK(28, 24), 0x4));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_INTF_CTRL_10, BIT(29));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x0;
+	else
+		val = 0xd;
+	ret = regmap_update_bits(priv->regmap, AN8855_INTF_CTRL_11, GENMASK(5, 0),
+				 FIELD_PREP(GENMASK(5, 0), val));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_INTF_CTRL_11, BIT(6));
+	if (ret)
+		return ret;
+
+	/* RX CDR - improve RX Jitter Tolerance */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x5;
+	else
+		val = 0x6;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_BOT_LIM, GENMASK(26, 24),
+				 FIELD_PREP(GENMASK(26, 24), val));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_BOT_LIM, GENMASK(22, 20),
+				 FIELD_PREP(GENMASK(22, 20), val));
+	if (ret)
+		return ret;
+
+	/* PLL */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x1;
+	else
+		val = 0x0;
+	ret = regmap_update_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_1, GENMASK(3, 2),
+				 FIELD_PREP(GENMASK(3, 2), val));
+	if (ret)
+		return ret;
+
+	/* PLL - LPF */
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(1, 0),
+				 FIELD_PREP(GENMASK(1, 0), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(4, 2),
+				 FIELD_PREP(GENMASK(4, 2), 0x5));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(6) | BIT(7));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(10, 8),
+				 FIELD_PREP(GENMASK(10, 8), 0x3));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(29));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(12) | BIT(13));
+	if (ret)
+		return ret;
+
+	/* PLL - ICO */
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_4, BIT(2));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(14));
+	if (ret)
+		return ret;
+
+	/* PLL - CHP */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x6;
+	else
+		val = 0x4;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(19, 16),
+				 FIELD_PREP(GENMASK(19, 16), val));
+	if (ret)
+		return ret;
+
+	/* PLL - PFD */
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(21, 20),
+				 FIELD_PREP(GENMASK(21, 20), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_PLL_CTRL_2, GENMASK(25, 24),
+				 FIELD_PREP(GENMASK(25, 24), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(26));
+	if (ret)
+		return ret;
+
+	/* PLL - POSTDIV */
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(22));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(27));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(28));
+	if (ret)
+		return ret;
+
+	/* PLL - SDM */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_4, BIT(3) | BIT(4));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_2, BIT(30));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_SS_LCPLL_PWCTL_SETTING_2,
+				 GENMASK(17, 16),
+				 FIELD_PREP(GENMASK(17, 16), 0x1));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x7a000000;
+	else
+		val = 0x48000000;
+	ret = regmap_write(priv->regmap, AN8855_SS_LCPLL_TDC_FLT_2, val);
+	if (ret)
+		return ret;
+	ret = regmap_write(priv->regmap, AN8855_SS_LCPLL_TDC_PCW_1, val);
+	if (ret)
+		return ret;
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_SS_LCPLL_TDC_FLT_5, BIT(24));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CK_CTRL_0, BIT(8));
+	if (ret)
+		return ret;
+
+	/* PLL - SS */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_3, GENMASK(15, 0));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_4, GENMASK(1, 0));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CTRL_3, GENMASK(31, 16));
+	if (ret)
+		return ret;
+
+	/* PLL - TDC */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PLL_CK_CTRL_0, BIT(9));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_QP_PLL_SDM_ORD, BIT(3));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_QP_PLL_SDM_ORD, BIT(4));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_RX_DAC_EN, GENMASK(17, 16),
+				 FIELD_PREP(GENMASK(17, 16), 0x2));
+	if (ret)
+		return ret;
+
+	/* TCL Disable (only for Co-SIM) */
+	ret = regmap_clear_bits(priv->regmap, AN8855_PON_RXFEDIG_CTRL_0, BIT(12));
+	if (ret)
+		return ret;
+
+	/* TX Init */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x4;
+	else
+		val = 0x0;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_TX_MODE_16B_EN, BIT(0));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_TX_MODE_16B_EN,
+				 GENMASK(31, 16),
+				 FIELD_PREP(GENMASK(31, 16), val));
+	if (ret)
+		return ret;
+
+	/* RX Control/Init */
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_QP_RXAFE_RESERVE, BIT(11));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x1;
+	else
+		val = 0x2;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_MJV_LIM,
+				 GENMASK(5, 4),
+				 FIELD_PREP(GENMASK(5, 4), val));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_SETVALUE,
+				 GENMASK(28, 25),
+				 FIELD_PREP(GENMASK(28, 25), 0x1));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_LPF_SETVALUE,
+				 GENMASK(31, 29),
+				 FIELD_PREP(GENMASK(31, 29), 0x6));
+	if (ret)
+		return ret;
+
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0xf;
+	else
+		val = 0xc;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_PR_CKREF_DIV1,
+				 GENMASK(12, 8),
+				 FIELD_PREP(GENMASK(12, 8), val));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_PR_KBAND_DIV_PCIE,
+				 GENMASK(12, 8),
+				 FIELD_PREP(GENMASK(12, 8), 0x19));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_CDR_PR_KBAND_DIV_PCIE, BIT(6));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_FORCE_IBANDLPF_R_OFF,
+				 GENMASK(12, 6),
+				 FIELD_PREP(GENMASK(12, 6), 0x21));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_FORCE_IBANDLPF_R_OFF,
+				 GENMASK(17, 16),
+				 FIELD_PREP(GENMASK(17, 16), 0x2));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_CDR_FORCE_IBANDLPF_R_OFF, BIT(13));
+	if (ret)
+		return ret;
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_QP_CDR_PR_KBAND_DIV_PCIE, BIT(30));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RG_QP_CDR_PR_CKREF_DIV1,
+				 GENMASK(26, 24),
+				 FIELD_PREP(GENMASK(26, 24), 0x4));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(priv->regmap, AN8855_RX_CTRL_26, BIT(23));
+	if (ret)
+		return ret;
+	ret = regmap_clear_bits(priv->regmap, AN8855_RX_CTRL_26, BIT(24));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RX_CTRL_26, BIT(26));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_DLY_0, GENMASK(7, 0),
+				 FIELD_PREP(GENMASK(7, 0), 0x6f));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RX_DLY_0, GENMASK(13, 8));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_42, GENMASK(12, 0),
+				 FIELD_PREP(GENMASK(12, 0), 0x150));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_2, GENMASK(28, 16),
+				 FIELD_PREP(GENMASK(28, 16), 0x150));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_PON_RXFEDIG_CTRL_9,
+				 GENMASK(2, 0),
+				 FIELD_PREP(GENMASK(2, 0), 0x1));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_8, GENMASK(27, 16),
+				 FIELD_PREP(GENMASK(27, 16), 0x200));
+	if (ret)
+		return ret;
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_8, GENMASK(14, 0),
+				 FIELD_PREP(GENMASK(14, 0), 0xfff));
+	if (ret)
+		return ret;
+
+	/* Frequency meter */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX)
+		val = 0x10;
+	else
+		val = 0x28;
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_5, GENMASK(29, 10),
+				 FIELD_PREP(GENMASK(29, 10), val));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_6, GENMASK(19, 0),
+				 FIELD_PREP(GENMASK(19, 0), 0x64));
+	if (ret)
+		return ret;
+
+	ret = regmap_update_bits(priv->regmap, AN8855_RX_CTRL_7, GENMASK(19, 0),
+				 FIELD_PREP(GENMASK(19, 0), 0x2710));
+	if (ret)
+		return ret;
+
+	ret = regmap_set_bits(priv->regmap, AN8855_PLL_CTRL_0, BIT(0));
+	if (ret)
+		return ret;
+
+	/* PCS Init */

drivers/net/dsa/an8855.c line 1727

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+	if (interface == PHY_INTERFACE_MODE_SGMII &&
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_DISABLED) {
+		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
+					BIT(0));
+		if (ret)
+			return ret;
+		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
+					GENMASK(5, 4));
+		if (ret)
+			return ret;

Do these really need to be done separately, or can the two be combined?

Quoted 4 lines
		ret = regmap_clear_bits(priv->regmap, AN8855_QP_DIG_MODE_CTRL_0,
					GENMASK(5, 4) | BIT(0));

?

I decided to separate them as much as possible following the pattern used in SDK to make this mess more readable. If needed yes I can combine the 2.

Quoted 75 lines
Quoted 12 lines
drivers/net/dsa/an8855.c new file +11 -0
+	}
+
+	ret = regmap_clear_bits(priv->regmap, AN8855_RG_HSGMII_PCS_CTROL_1, BIT(30));
+	if (ret)
+		return ret;
+
+	if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		/* Set AN Ability - Interrupt */
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN_FORCE_CL37, BIT(0));
+		if (ret)
+			return ret;

drivers/net/dsa/an8855.c line 1748

Quoted 10 lines
drivers/net/dsa/an8855.c new file +10 -0
+
+		ret = regmap_update_bits(priv->regmap, AN8855_SGMII_REG_AN_13,
+					 GENMASK(5, 0),
+					 FIELD_PREP(GENMASK(5, 0), 0xb));
+		if (ret)
+			return ret;
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN_13, BIT(8));
+		if (ret)
+			return ret;
+	}

Eh?

Quoted 50 lines
drivers/net/dsa/an8855.c new file +50 -0
+
+	/* Rate Adaption - GMII path config. */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX) {
+		ret = regmap_clear_bits(priv->regmap, AN8855_RATE_ADP_P0_CTRL_0, BIT(31));
+		if (ret)
+			return ret;
+	} else {
+		if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+			ret = regmap_set_bits(priv->regmap, AN8855_MII_RA_AN_ENABLE, BIT(0));
+			if (ret)
+				return ret;
+		} else {
+			ret = regmap_set_bits(priv->regmap, AN8855_RG_AN_SGMII_MODE_FORCE,
+					      BIT(0));
+			if (ret)
+				return ret;
+			ret = regmap_clear_bits(priv->regmap, AN8855_RG_AN_SGMII_MODE_FORCE,
+						GENMASK(5, 4));
+			if (ret)
+				return ret;
+
+			ret = regmap_clear_bits(priv->regmap, AN8855_RATE_ADP_P0_CTRL_0,
+						GENMASK(3, 0));
+			if (ret)
+				return ret;
+		}
+
+		ret = regmap_set_bits(priv->regmap, AN8855_RATE_ADP_P0_CTRL_0, BIT(28));
+		if (ret)
+			return ret;
+	}
+
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_RATE_ADAPT_CTRL_0, BIT(0));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_RATE_ADAPT_CTRL_0, BIT(4));
+	if (ret)
+		return ret;
+	ret = regmap_set_bits(priv->regmap, AN8855_RG_RATE_ADAPT_CTRL_0, GENMASK(27, 26));
+	if (ret)
+		return ret;
+
+	/* Disable AN */
+	if (neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN0,
+				      AN8855_SGMII_AN_ENABLE);
+		if (ret)
+			return ret;
+	} else {
+		ret = regmap_clear_bits(priv->regmap, AN8855_SGMII_REG_AN0,
Quoted 9 lines

drivers/net/dsa/an8855.c line 1802

Quoted 4 lines
drivers/net/dsa/an8855.c new file +4 -0
+					AN8855_SGMII_AN_ENABLE);
+		if (ret)
+			return ret;
+	}

Again, using regmap_update_bits() with a mask and value is probably more readable here. This looks like it's twiddling a standard BMCR_ANENABLE bit.

Looks like so... the 2 bit are the same... (btw these are the ONLY bits I have in documentation...)

Quoted 22 lines

drivers/net/dsa/an8855.c line 1809

Quoted 7 lines
drivers/net/dsa/an8855.c new file +7 -0
+
+	if (interface == PHY_INTERFACE_MODE_SGMII &&
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_DISABLED) {
+		ret = regmap_set_bits(priv->regmap, AN8855_PHY_RX_FORCE_CTRL_0, BIT(4));
+		if (ret)
+			return ret;
+	}

Eh?

Quoted 12 lines
drivers/net/dsa/an8855.c new file +12 -0
+
+	/* Force Speed */
+	if (interface == PHY_INTERFACE_MODE_2500BASEX ||
+	    neg_mode == PHYLINK_PCS_NEG_INBAND_ENABLED) {
+		if (interface == PHY_INTERFACE_MODE_2500BASEX)
+			val = 0x3;
+		else
+			val = 0x2;
+		ret = regmap_set_bits(priv->regmap, AN8855_SGMII_STS_CTRL_0, BIT(2));
+		if (ret)
+			return ret;
+		ret = regmap_update_bits(priv->regmap, AN8855_SGMII_STS_CTRL_0,
Quoted 9 lines

drivers/net/dsa/an8855.c line 1826

Quoted 5 lines
drivers/net/dsa/an8855.c new file +5 -0
+					 GENMASK(5, 4),
+					 FIELD_PREP(GENMASK(5, 4), val));
+		if (ret)
+			return ret;
+	}

I don't understand why speed should be forced if inband is enabled or we're using 2500base-X.

Again no documentation. From my test with the value set to 0 CPU port can't send traffic.

I assume this is some kind of max speed value.

3 2500
2 1000
1 100
0 10

Maybe?

Quoted 13 lines

drivers/net/dsa/an8855.c line 1834

Quoted 8 lines
drivers/net/dsa/an8855.c new file +8 -0
+
+	/* bypass flow control to MAC */
+	ret = regmap_write(priv->regmap, AN8855_MSG_RX_LIK_STS_0, 0x01010107);
+	if (ret)
+		return ret;
+	ret = regmap_write(priv->regmap, AN8855_MSG_RX_LIK_STS_2, 0x00000EEF);
+	if (ret)
+		return ret;

Overall, I'd like more comments about what stuff is doing, especially the AN stuff. I can't make head nor tail of e.g. is there any advertisement being programmed or not.

Quoted 4 lines

Also, given that this will be called _on its own_ if the user requests the inband advertisement to be changed, we don't want to unnecessarily disrupt the link. What would happen if this code runs when the link is up?

I will try to gather more info about all of these configuration but honestly chance are very low...

From what I observed these values doesn't interrupt the link but maybe this code can be moved in different OPs to better handle changing case?

Quoted 14 lines

drivers/net/dsa/an8855.c line 1844

Quoted 11 lines
drivers/net/dsa/an8855.c new file +10 -0
+
+	return 0;
+}
+
+static void an8855_pcs_an_restart(struct phylink_pcs *pcs)
+{
+	struct an8855_priv *priv = container_of(pcs, struct an8855_priv, pcs);
+
+	regmap_set_bits(priv->regmap, AN8855_SGMII_REG_AN0,
+			AN8855_SGMII_AN_RESTART);

Again, looks like a standard PHY BMCR.

Quoted 3 lines

I haven't done a full review, but these are just what I've spotted so far.

Thanks a lot for the initial review, I will check the EEE part better.

Again the big problem is the PCS setup with all that nightmares values... The Documentation is empty (only AN value are there) and the values from the SDK by compacting the sgmii(inband and forced)/hsgmii in one single code by checking all the common piece.

This if why you have all those if condition and all... They comes from compacting the functions, that part of code is still a blackbox more or less currently...

Signature · 1 line
	Ansuel
#6 lore raw

Re: [net-next RFC PATCH 3/4] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/net-mdio-implement-mdio_mutex_nested-guard-variant/20241021-210643
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241021130209.15660-4-ansuelsmth%40gmail.com
patch subject: [net-next RFC PATCH 3/4] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
config: i386-allmodconfig (https://download.01.org/0day-ci/archive/20241024/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241024/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>, old ones prefixed by <<):

>> ERROR: modpost: "__ffsdi2" [drivers/net/dsa/an8855.ko] undefined!

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [m]:
- RESOURCE_KUNIT_TEST [=m] && RUNTIME_TESTING_MENU [=y] && KUNIT [=m]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#7 lore raw

Re: [net-next RFC PATCH 3/4] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver

In reply to Christian Marangi
kernel test robot noticed the following build errors:

Hi Christian,

[This is a private test report for your RFC patch.] kernel test robot noticed the following build errors:

[auto build test ERROR on net-next/main]

url:    https://github.com/intel-lab-lkp/linux/commits/Christian-Marangi/net-mdio-implement-mdio_mutex_nested-guard-variant/20241021-210643
base:   net-next/main
patch link:    https://lore.kernel.org/r/20241021130209.15660-4-ansuelsmth%40gmail.com
patch subject: [net-next RFC PATCH 3/4] net: dsa: Add Airoha AN8855 5-Port Gigabit DSA Switch driver
config: i386-allyesconfig (https://download.01.org/0day-ci/archive/20241024/[email protected]/config)
compiler: gcc-12 (Debian 12.2.0-14) 12.2.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20241024/[email protected]/reproduce)

If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/

All errors (new ones prefixed by >>):

ld: drivers/net/dsa/an8855.o: in function `an8855_vlan_add':

>> an8855.c:(.text+0x1010): undefined reference to `__ffsdi2'
   ld: drivers/net/dsa/an8855.o: in function `an8855_vlan_add.cold':
>> an8855.c:(.text.unlikely+0x91): undefined reference to `__ffsdi2'

Kconfig warnings: (for reference only)
WARNING: unmet direct dependencies detected for GET_FREE_REGION Depends on [n]: SPARSEMEM [=n]
Selected by [y]:
- RESOURCE_KUNIT_TEST [=y] && RUNTIME_TESTING_MENU [=y] && KUNIT [=y]

Signature · 2 lines
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
#8 lore raw

RFC PATCH 4/4 net: phy: Add Airoha AN8855 Internal Switch Gigabit PHY

In reply to Christian Marangi

Add support for Airoha AN8855 Internal Switch Gigabit PHY.

This is a simple PHY driver to configure and calibrate the PHY for the AN8855 Switch.

---
 MAINTAINERS                  |   1 +
 drivers/net/phy/Kconfig      |   5 +
 drivers/net/phy/Makefile     |   1 +
 drivers/net/phy/air_an8855.c | 187 +++++++++++++++++++++++++++++++++++
 4 files changed, 194 insertions(+)
 create mode 100644 drivers/net/phy/air_an8855.c
MAINTAINERS +1 -0
index e3077d9feee2..cf34add2a0bb 100644
@@ -726,6 +726,7 @@ S:	Maintained
 F:	Documentation/devicetree/bindings/net/dsa/airoha,an8855.yaml
 F:	drivers/net/dsa/an8855.c
 F:	drivers/net/dsa/an8855.h
+F:	drivers/net/phy/air_an8855.c
 
 AIROHA ETHERNET DRIVER
 M:	Lorenzo Bianconi <[email protected]>
drivers/net/phy/Kconfig +5 -0
index ee3ea0b56d48..1d474038ea7f 100644
@@ -79,6 +79,11 @@ config SFP
 
 comment "MII PHY device drivers"
 
+config AIR_AN8855_PHY
+	tristate "Airoha AN8855 Internal Gigabit PHY"
+	help
+	  Currently supports the internal Airoha AN8855 Switch PHY.
+
 config AIR_EN8811H_PHY
 	tristate "Airoha EN8811H 2.5 Gigabit PHY"
 	help
drivers/net/phy/Makefile +1 -0
index 90f886844381..baba7894785b 100644
@@ -35,6 +35,7 @@ obj-y				+= $(sfp-obj-y) $(sfp-obj-m)
 
 obj-$(CONFIG_ADIN_PHY)		+= adin.o
 obj-$(CONFIG_ADIN1100_PHY)	+= adin1100.o
+obj-$(CONFIG_AIR_AN8855_PHY)   += air_an8855.o
 obj-$(CONFIG_AIR_EN8811H_PHY)   += air_en8811h.o
 obj-$(CONFIG_AMD_PHY)		+= amd.o
 obj-$(CONFIG_AMCC_QT2025_PHY)	+= qt2025.o
drivers/net/phy/air_an8855.c new file +187 -0

187 lines not on this page · raw message

Signature · 1 line
2.45.2
maintainer
#9 lore raw
In reply to Christian Marangi
Quoted 2 lines · Christian Marangi

It's conceptually similar to mediatek switch but register and bits are different.

Is it impractical to use struct regmap_field to abstract those differences away and reuse the mt7530 driver's control flow? What is the relationship between the Airoha and Mediatek IP anyway? The mt7530 maintainers should also be consulted w.r.t. whether code sharing is in the common interest (I copied them).

#10 lore raw
Quoted 9 lines · Vladimir Oltean
Quoted 2 lines · Christian Marangi

It's conceptually similar to mediatek switch but register and bits are different.

Is it impractical to use struct regmap_field to abstract those differences away and reuse the mt7530 driver's control flow? What is the relationship between the Airoha and Mediatek IP anyway? The mt7530 maintainers should also be consulted w.r.t. whether code sharing is in the common interest (I copied them).

Some logic are similar for ATU or VLAN handling but then they added bits in the middle of the register and moved some in other place.

Happy of being contradicted but from what I checked adapting the mtk code would introduce lots of condition and wrapper and I feel it would be actually worse than keeping the 2 codebase alone.

Would love some help by mt7530 to catch some very common case.

Signature · 1 line
	Ansuel
maintainer
#11 lore raw
Quoted 11 lines · Christian Marangi
Quoted 9 lines · Vladimir Oltean
Quoted 2 lines · Christian Marangi

It's conceptually similar to mediatek switch but register and bits are different.

Is it impractical to use struct regmap_field to abstract those differences away and reuse the mt7530 driver's control flow? What is the relationship between the Airoha and Mediatek IP anyway? The mt7530 maintainers should also be consulted w.r.t. whether code sharing is in the common interest (I copied them).

Quoted 8 lines

Some logic are similar for ATU or VLAN handling but then they added bits in the middle of the register and moved some in other place.

Happy of being contradicted but from what I checked adapting the mtk code would introduce lots of condition and wrapper and I feel it would be actually worse than keeping the 2 codebase alone.

Would love some help by mt7530 to catch some very common case.

As long as the control flow is reasonably similar, the REG_FIELD() macro is able to deal with register fields which have moved from one place to another between hardware variants.

#12 lore raw
In reply to Vladimir Oltean
Quoted 9 lines · Vladimir Oltean
Quoted 2 lines · Christian Marangi

It's conceptually similar to mediatek switch but register and bits are different.

Is it impractical to use struct regmap_field to abstract those differences away and reuse the mt7530 driver's control flow? What is the relationship between the Airoha and Mediatek IP anyway? The mt7530 maintainers should also be consulted w.r.t. whether code sharing is in the common interest (I copied them).

That thought crossed my mind while reviewing patch 3. I compared the PMCR and PMSR, a lot of the bits are in completely different places between the two. I didn't check further, but I got the feeling that would invite more complexity.

Signature · 2 lines
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTP is here! 80Mbps down 10Mbps up. Decent connectivity at last!