Skip to contentSkip to conversation

some mvneta changes, cleanups, fixes

PATCH In review Marek Behún 3 participants 58 messages Apr 27, 2022 – May 4, 2022

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

cover some mvneta changes, cleanups, fixes

From: Marek Behún <[email protected]>

Hello Stefan,

here come some refactors, cleanups and fixed for the mvneta driver.

Marek Behún (19):
net: mvneta: Get rid of platdata
net: mvneta: Fix 10Mbps speed
net: mvneta: Use DM MDIO API for connecting PHY
net: mvneta: Remember fixed link instead of PHY address in priv data
arm: mvebu: Espressobin: Use DM registered MDIO to configure switch
net: mdio-uclass: add dm_phy_find_by_ofnode() helper
arm: mvebu: turris_mox: Use DM registered MDIO
net: mvneta: Don't register MDIO bus
net: mvneta: Fix unused variable warning if DM_GPIO is disabled
net: mvneta: Drop one indentation level in mvneta_adjust_link()
net: mvneta: Use bool instead of int for boolean variable
net: mvneta: Drop unnecessary space
net: mventa: Don't check for CONFIG_PHYLIB
net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS
net: mvneta: Convert to use PHY_FIXED for fixed-link
net: mvneta: Write PHY address just before enabling HW polling
net: mvneta: Drop fixed_link member from private struct
net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in
net: mvneta: Drop unneeded macro

 .../dts/armada-3720-turris-mox-u-boot.dtsi    |  19 -
 board/CZ.NIC/turris_mox/turris_mox.c          |  88 ++---
 board/Marvell/mvebu_armada-37xx/board.c       |  26 +-
 configs/clearfog_defconfig                    |   1 +
 configs/controlcenterdc_defconfig             |   1 +
 configs/db-88f6820-amc_defconfig              |   1 +
 configs/db-88f6820-gp_defconfig               |   1 +
 configs/db-mv784mp-gp_defconfig               |   1 +
 configs/ds414_defconfig                       |   1 +
 configs/helios4_defconfig                     |   1 +
 configs/maxbcm_defconfig                      |   1 +
 configs/mvebu_espressobin-88f3720_defconfig   |   3 +
 configs/theadorable_debug_defconfig           |   1 +
 configs/turris_mox_defconfig                  |   1 +
 configs/turris_omnia_defconfig                |   2 +
 configs/uDPU_defconfig                        |   1 +
 drivers/net/Kconfig                           |   1 +
 drivers/net/mvneta.c                          | 343 ++++--------------
 include/miiphy.h                              |   9 +
 net/mdio-uclass.c                             |  22 ++
 20 files changed, 181 insertions(+), 343 deletions(-)
Signature · 1 line
2.35.1
#1 lore raw

PATCH 1/19 net: mvneta: Get rid of platdata

From: Marek Behún <[email protected]>

Drop .of_to_plat() from the mvneta driver and parse the two properties in .probe().

---
 drivers/net/mvneta.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
drivers/net/mvneta.c +4 -20
index 15dc714058..d1c5f7930d 100644
@@ -1692,7 +1692,6 @@ static int mvneta_recv(struct udevice *dev, int flags, uchar **packetp)
 
 static int mvneta_probe(struct udevice *dev)
 {
-	struct eth_pdata *pdata = dev_get_plat(dev);
 	struct mvneta_port *pp = dev_get_priv(dev);
 #if CONFIG_IS_ENABLED(DM_GPIO)
 	struct ofnode_phandle_args sfp_args;
@@ -1729,7 +1728,10 @@ static int mvneta_probe(struct udevice *dev)
 		buffer_loc.rx_buffers = (phys_addr_t)(bd_space + size);
 	}
 
-	pp->base = (void __iomem *)pdata->iobase;
+	pp->base = dev_read_addr_ptr(dev);
+	pp->phy_interface = dev_read_phy_mode(dev);
+	if (pp->phy_interface == PHY_INTERFACE_MODE_NA)
+		return -EINVAL;
 
 	/* Configure MBUS address windows */
 	if (device_is_compatible(dev, "marvell,armada-3700-neta"))
@@ -1737,9 +1739,6 @@ static int mvneta_probe(struct udevice *dev)
 	else
 		mvneta_conf_mbus_windows(pp);
 
-	/* PHY interface is already decoded in mvneta_of_to_plat() */
-	pp->phy_interface = pdata->phy_interface;
-
 	/* fetch 'fixed-link' property from 'neta' node */
 	fl_node = fdt_subnode_offset(blob, node, "fixed-link");
 	if (fl_node != -FDT_ERR_NOTFOUND) {
@@ -1808,20 +1807,6 @@ static const struct eth_ops mvneta_ops = {
 	.write_hwaddr	= mvneta_write_hwaddr,
 };
 
-static int mvneta_of_to_plat(struct udevice *dev)
-{
-	struct eth_pdata *pdata = dev_get_plat(dev);
-
-	pdata->iobase = dev_read_addr(dev);
-
-	/* Get phy-mode / phy_interface from DT */
-	pdata->phy_interface = dev_read_phy_mode(dev);
-	if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
-		return -EINVAL;
-
-	return 0;
-}
-
 static const struct udevice_id mvneta_ids[] = {
 	{ .compatible = "marvell,armada-370-neta" },
 	{ .compatible = "marvell,armada-xp-neta" },
@@ -1833,7 +1818,6 @@ U_BOOT_DRIVER(mvneta) = {
 	.name	= "mvneta",
 	.id	= UCLASS_ETH,
 	.of_match = mvneta_ids,
-	.of_to_plat = mvneta_of_to_plat,
 	.probe	= mvneta_probe,
 	.ops	= &mvneta_ops,
 	.priv_auto	= sizeof(struct mvneta_port),
Signature · 1 line
2.35.1
#4 lore raw

PATCH 2/19 net: mvneta: Fix 10Mbps speed

In reply to Marek Behún

From: Marek Behún <[email protected]>

In mvneta_adjust_link() we need to set MII_SPEED bit only if PHY reports the speed at 100Mbps.

---
 drivers/net/mvneta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvneta.c +1 -1
index d1c5f7930d..79cdb93341 100644
@@ -1195,7 +1195,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 
 			if (phydev->speed == SPEED_1000)
 				val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-			else
+			else if (pp->speed == SPEED_100)
 				val |= MVNETA_GMAC_CONFIG_MII_SPEED;
 
 			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
Signature · 1 line
2.35.1
#7 lore raw

PATCH 3/19 net: mvneta: Use DM MDIO API for connecting PHY

In reply to Marek Behún

From: Marek Behún <[email protected]>

Use the modern DM MDIO API for connecting PHY in the mvneta driver.

This requires enabling MVMDIO driver in several config files.

---
 configs/clearfog_defconfig                  |  1 +
 configs/controlcenterdc_defconfig           |  1 +
 configs/db-88f6820-amc_defconfig            |  1 +
 configs/db-88f6820-gp_defconfig             |  1 +
 configs/db-mv784mp-gp_defconfig             |  1 +
 configs/ds414_defconfig                     |  1 +
 configs/helios4_defconfig                   |  1 +
 configs/maxbcm_defconfig                    |  1 +
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/theadorable_debug_defconfig         |  1 +
 configs/turris_mox_defconfig                |  1 +
 configs/turris_omnia_defconfig              |  1 +
 configs/uDPU_defconfig                      |  1 +
 drivers/net/Kconfig                         |  1 +
 drivers/net/mvneta.c                        | 11 +++++------
 15 files changed, 19 insertions(+), 6 deletions(-)
configs/clearfog_defconfig +1 -0
index 880f16a6e0..b8f59d2962 100644
@@ -63,6 +63,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SCSI=y
configs/controlcenterdc_defconfig +1 -0
index d4b966b93f..df38b2c54f 100644
@@ -77,6 +77,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_MVEBU=y
configs/db-88f6820-amc_defconfig +1 -0
index 46c822fccd..9b77b4a5f0 100644
@@ -67,6 +67,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_DEBUG_UART_SHIFT=2
configs/db-88f6820-gp_defconfig +1 -0
index 2dcbc2f29a..f56d1fbf25 100644
@@ -62,6 +62,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SCSI=y
configs/db-mv784mp-gp_defconfig +1 -0
index f19cc54975..5683f11836 100644
@@ -65,6 +65,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_DEBUG_UART_SHIFT=2
configs/ds414_defconfig +1 -0
index a3279c15c5..a83fe079b3 100644
@@ -65,6 +65,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_DEBUG_UART_SHIFT=2
configs/helios4_defconfig +1 -0
index 7d812e8fab..c2130bacb4 100644
@@ -63,6 +63,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SCSI=y
configs/maxbcm_defconfig +1 -0
index 8dd6adf247..40f79d47ea 100644
@@ -47,6 +47,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index ff05630d20..af30f1b363 100644
@@ -76,6 +76,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI=y
 CONFIG_PCI_AARDVARK=y
configs/theadorable_debug_defconfig +1 -0
index 86129e7d2d..9a03a0a7a3 100644
@@ -70,6 +70,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_MVEBU=y
configs/turris_mox_defconfig +1 -0
index 9a76a118c2..bcd3699a4f 100644
@@ -82,6 +82,7 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI=y
 CONFIG_PCI_AARDVARK=y
configs/turris_omnia_defconfig +1 -0
index ad56d3824b..6b218bd7a7 100644
@@ -82,6 +82,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
configs/uDPU_defconfig +1 -0
index c07bad5076..f2852ad29b 100644
@@ -73,6 +73,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_AARDVARK=y
 CONFIG_PHY=y
drivers/net/Kconfig +1 -0
index 347fe8aa42..47f7a262f2 100644
@@ -445,6 +445,7 @@ config MVNETA
 	bool "Marvell Armada XP/385/3700 network interface support"
 	depends on ARMADA_XP || ARMADA_38X || ARMADA_3700
 	select PHYLIB
+	select DM_MDIO
 	help
 	  This driver supports the network interface units in the
 	  Marvell ARMADA XP, ARMADA 38X and ARMADA 3700 SoCs
drivers/net/mvneta.c +5 -6
index 79cdb93341..24a491dcde 100644
@@ -1571,16 +1571,15 @@ static int mvneta_start(struct udevice *dev)
 
 			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 		} else {
-			/* Set phy address of the port */
-			mvreg_write(pp, MVNETA_PHY_ADDR, pp->phyaddr);
-
-			phydev = phy_connect(pp->bus, pp->phyaddr, dev,
-					     pp->phy_interface);
+			phydev = dm_eth_phy_connect(dev);
 			if (!phydev) {
-				printf("phy_connect failed\n");
+				printf("dm_eth_phy_connect failed\n");
 				return -ENODEV;
 			}
 
+			/* Set PHY address in case we will enable HW polling */
+			mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
+
 			pp->phydev = phydev;
 			phy_config(phydev);
 			phy_startup(phydev);
Signature · 1 line
2.35.1
#10 lore raw

PATCH 4/19 net: mvneta: Remember fixed link instead of PHY address in priv data

In reply to Marek Behún

From: Marek Behún <[email protected]>

We don't need to remember PHY address anymore, because since using DM MDIO for connecting PHY, the address is parsed by mdio-uclass from the ofnode.

But the driver uses a special value of the address to signal fixed link usage.

Drop phyaddr add fixed_link in driver private structure. This simplifies code a little.

---
 drivers/net/mvneta.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
drivers/net/mvneta.c +5 -18
index 24a491dcde..83e9629138 100644
@@ -277,12 +277,12 @@ struct mvneta_port {
 	u16 rx_ring_size;
 
 	phy_interface_t phy_interface;
+	bool fixed_link;
 	unsigned int link;
 	unsigned int duplex;
 	unsigned int speed;
 
 	int init;
-	int phyaddr;
 	struct phy_device *phydev;
 #if CONFIG_IS_ENABLED(DM_GPIO)
 	struct gpio_desc phy_reset_gpio;
@@ -576,13 +576,6 @@ static void mvneta_rxq_buf_size_set(struct mvneta_port *pp,
 	mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val);
 }
 
-static int mvneta_port_is_fixed_link(struct mvneta_port *pp)
-{
-	/* phy_addr is set to invalid value for fixed link */
-	return pp->phyaddr > PHY_MAX_ADDR;
-}
-
-
 /* Start the Ethernet port RX and TX activity */
 static void mvneta_port_up(struct mvneta_port *pp)
 {
@@ -834,7 +827,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 	mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
 	/* Enable PHY polling in hardware if not in fixed-link mode */
-	if (!mvneta_port_is_fixed_link(pp)) {
+	if (!pp->fixed_link) {
 		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
 		val |= MVNETA_PHY_POLLING_ENABLE;
 		mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
@@ -1173,7 +1166,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 	struct phy_device *phydev = pp->phydev;
 	int status_change = 0;
 
-	if (mvneta_port_is_fixed_link(pp)) {
+	if (pp->fixed_link) {
 		debug("Using fixed link, skip link adjust\n");
 		return;
 	}
@@ -1548,7 +1541,7 @@ static int mvneta_start(struct udevice *dev)
 	mvneta_port_power_up(pp, pp->phy_interface);
 
 	if (!pp->init || pp->link == 0) {
-		if (mvneta_port_is_fixed_link(pp)) {
+		if (pp->fixed_link) {
 			u32 val;
 
 			pp->init = 1;
@@ -1698,7 +1691,6 @@ static int mvneta_probe(struct udevice *dev)
 	void *blob = (void *)gd->fdt_blob;
 	int node = dev_of_offset(dev);
 	struct mii_dev *bus;
-	unsigned long addr;
 	void *bd_space;
 	int ret;
 	int fl_node;
@@ -1742,14 +1734,9 @@ static int mvneta_probe(struct udevice *dev)
 	fl_node = fdt_subnode_offset(blob, node, "fixed-link");
 	if (fl_node != -FDT_ERR_NOTFOUND) {
 		/* set phy_addr to invalid value for fixed link */
-		pp->phyaddr = PHY_MAX_ADDR + 1;
 		pp->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex");
 		pp->speed = fdtdec_get_int(blob, fl_node, "speed", 0);
-	} else {
-		/* Now read phyaddr from DT */
-		addr = fdtdec_get_int(blob, node, "phy", 0);
-		addr = fdt_node_offset_by_phandle(blob, addr);
-		pp->phyaddr = fdtdec_get_int(blob, addr, "reg", 0);
+		pp->fixed_link = true;
 	}
 
 	bus = mdio_alloc();
Signature · 1 line
2.35.1
#13 lore raw

PATCH 5/19 arm: mvebu: Espressobin: Use DM registered MDIO to configure switch

In reply to Marek Behún

From: Marek Behún <[email protected]>

In order to be able to get rid of the non-DM MDIO bus registered in mvneta driver, we need to stop using board_network_enable() and instead use the DM registered MDIO device to configure switch in last_stage_init().

---
 board/Marvell/mvebu_armada-37xx/board.c     | 26 ++++++++++++++++-----
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 2 files changed, 21 insertions(+), 6 deletions(-)
board/Marvell/mvebu_armada-37xx/board.c +20 -6
index 98e1b36d11..3e5e0a0b5c 100644
@@ -11,6 +11,7 @@
 #include <i2c.h>
 #include <init.h>
 #include <mmc.h>
+#include <miiphy.h>
 #include <phy.h>
 #include <asm/global_data.h>
 #include <asm/io.h>
@@ -254,14 +255,15 @@ int board_xhci_enable(fdt_addr_t base)
 	return 0;
 }
 
+#ifdef CONFIG_LAST_STAGE_INIT
 /* Helper function for accessing switch devices in multi-chip connection mode */
-static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
+static int mii_multi_chip_mode_write(struct udevice *bus, int dev_smi_addr,
 				     int smi_addr, int reg, u16 value)
 {
 	u16 smi_cmd = 0;
 
-	if (bus->write(bus, dev_smi_addr, 0,
-		       MVEBU_SW_SMI_DATA_REG, value) != 0) {
+	if (dm_mdio_write(bus, dev_smi_addr, MDIO_DEVAD_NONE,
+			  MVEBU_SW_SMI_DATA_REG, value) != 0) {
 		printf("Error writing to the PHY addr=%02x reg=%02x\n",
 		       smi_addr, reg);
 		return -EFAULT;
@@ -272,8 +274,8 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
 		  (1 << SW_SMI_CMD_SMI_OP_OFF) |
 		  (smi_addr << SW_SMI_CMD_DEV_ADDR_OFF) |
 		  (reg << SW_SMI_CMD_REG_ADDR_OFF);
-	if (bus->write(bus, dev_smi_addr, 0,
-		       MVEBU_SW_SMI_CMD_REG, smi_cmd) != 0) {
+	if (dm_mdio_write(bus, dev_smi_addr, MDIO_DEVAD_NONE,
+			  MVEBU_SW_SMI_CMD_REG, smi_cmd) != 0) {
 		printf("Error writing to the PHY addr=%02x reg=%02x\n",
 		       smi_addr, reg);
 		return -EFAULT;
@@ -283,11 +285,22 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
 }
 
 /* Bring-up board-specific network stuff */
-int board_network_enable(struct mii_dev *bus)
+int last_stage_init(void)
 {
+	struct udevice *bus;
+	ofnode node;
+
 	if (!of_machine_is_compatible("globalscale,espressobin"))
 		return 0;
 
+	node = ofnode_by_compatible(ofnode_null(), "marvell,orion-mdio");
+	if (!ofnode_valid(node) ||
+	    uclass_get_device_by_ofnode(UCLASS_MDIO, node, &bus) ||
+	    device_probe(bus)) {
+		printf("Cannot find MDIO bus\n");
+		return 0;
+	}
+
 	/*
 	 * FIXME: remove this code once Topaz driver gets available
 	 * A3720 Community Board Only
@@ -327,6 +340,7 @@ int board_network_enable(struct mii_dev *bus)
 
 	return 0;
 }
+#endif
 
 #ifdef CONFIG_OF_BOARD_SETUP
 int ft_board_setup(void *blob, struct bd_info *bd)
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index af30f1b363..37e4fdc41e 100644
@@ -25,6 +25,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
 CONFIG_ARCH_EARLY_INIT_R=y
 CONFIG_BOARD_EARLY_INIT_F=y
 CONFIG_BOARD_LATE_INIT=y
+CONFIG_LAST_STAGE_INIT=y
 # CONFIG_CMD_FLASH is not set
 CONFIG_CMD_FUSE=y
 CONFIG_CMD_GPIO=y
Signature · 1 line
2.35.1
#15 lore raw

PATCH 6/19 net: mdio-uclass: add dm_phy_find_by_ofnode() helper

In reply to Marek Behún

From: Marek Behún <[email protected]>

Add helper to resolve PHY node from it's ofnode via DM MDIO subsystem.

---
 include/miiphy.h  |  9 +++++++++
 net/mdio-uclass.c | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+)
include/miiphy.h +9 -0
index 110921f20d..c66a1845b5 100644
@@ -188,6 +188,15 @@ int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 va
  */
 int dm_mdio_reset(struct udevice *mdio_dev);
 
+/**
+ * dm_phy_find_by_ofnode - Find PHY device by ofnode
+ *
+ * @phynode: PHY's ofnode
+ *
+ * Return: pointer to phy_device, or NULL on error
+ */
+struct phy_device *dm_phy_find_by_ofnode(ofnode phynode);
+
 /**
  * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
  *
net/mdio-uclass.c +22 -0
index 7593618d9a..4401492ca0 100644
@@ -129,6 +129,28 @@ static int dm_mdio_pre_remove(struct udevice *dev)
 	return 0;
 }
 
+struct phy_device *dm_phy_find_by_ofnode(ofnode phynode)
+{
+	struct mdio_perdev_priv *pdata;
+	struct udevice *mdiodev;
+	u32 phy_addr;
+
+	if (ofnode_read_u32(phynode, "reg", &phy_addr))
+		return NULL;
+
+	if (uclass_get_device_by_ofnode(UCLASS_MDIO,
+					ofnode_get_parent(phynode),
+					&mdiodev))
+		return NULL;
+
+	if (device_probe(mdiodev))
+		return NULL;
+
+	pdata = dev_get_uclass_priv(mdiodev);
+
+	return phy_find_by_mask(pdata->mii_bus, BIT(phy_addr));
+}
+
 struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr,
 				       struct udevice *ethdev,
 				       phy_interface_t interface)
Signature · 1 line
2.35.1
#20 lore raw

PATCH 8/19 net: mvneta: Don't register MDIO bus

In reply to Marek Behún

From: Marek Behún <[email protected]>

This MDIO bus is now handled by a proper mvmdio DM driver. Remove it from mvneta.

---
 drivers/net/mvneta.c | 143 +------------------------------------------
 1 file changed, 2 insertions(+), 141 deletions(-)
drivers/net/mvneta.c +2 -141
index 83e9629138..19f8145fc0 100644
@@ -288,7 +288,6 @@ struct mvneta_port {
 	struct gpio_desc phy_reset_gpio;
 	struct gpio_desc sfp_tx_disable_gpio;
 #endif
-	struct mii_dev *bus;
 };
 
 /* The mvneta_tx_desc and mvneta_rx_desc structures describe the
@@ -414,15 +413,6 @@ static struct buffer_location buffer_loc;
  */
 #define BD_SPACE	(1 << 20)
 
-/*
- * Dummy implementation that can be overwritten by a board
- * specific function
- */
-__weak int board_network_enable(struct mii_dev *bus)
-{
-	return 0;
-}
-
 /* Utility/helper methods */
 
 /* Write helper method */
@@ -1421,118 +1411,6 @@ static int mvneta_init(struct udevice *dev)
 
 /* U-Boot only functions follow here */
 
-/* SMI / MDIO functions */
-
-static int smi_wait_ready(struct mvneta_port *pp)
-{
-	u32 timeout = MVNETA_SMI_TIMEOUT;
-	u32 smi_reg;
-
-	/* wait till the SMI is not busy */
-	do {
-		/* read smi register */
-		smi_reg = mvreg_read(pp, MVNETA_SMI);
-		if (timeout-- == 0) {
-			printf("Error: SMI busy timeout\n");
-			return -EFAULT;
-		}
-	} while (smi_reg & MVNETA_SMI_BUSY);
-
-	return 0;
-}
-
-/*
- * mvneta_mdio_read - miiphy_read callback function.
- *
- * Returns 16bit phy register value, or 0xffff on error
- */
-static int mvneta_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
-{
-	struct mvneta_port *pp = bus->priv;
-	u32 smi_reg;
-	u32 timeout;
-
-	/* check parameters */
-	if (addr > MVNETA_PHY_ADDR_MASK) {
-		printf("Error: Invalid PHY address %d\n", addr);
-		return -EFAULT;
-	}
-
-	if (reg > MVNETA_PHY_REG_MASK) {
-		printf("Err: Invalid register offset %d\n", reg);
-		return -EFAULT;
-	}
-
-	/* wait till the SMI is not busy */
-	if (smi_wait_ready(pp) < 0)
-		return -EFAULT;
-
-	/* fill the phy address and regiser offset and read opcode */
-	smi_reg = (addr << MVNETA_SMI_DEV_ADDR_OFFS)
-		| (reg << MVNETA_SMI_REG_ADDR_OFFS)
-		| MVNETA_SMI_OPCODE_READ;
-
-	/* write the smi register */
-	mvreg_write(pp, MVNETA_SMI, smi_reg);
-
-	/* wait till read value is ready */
-	timeout = MVNETA_SMI_TIMEOUT;
-
-	do {
-		/* read smi register */
-		smi_reg = mvreg_read(pp, MVNETA_SMI);
-		if (timeout-- == 0) {
-			printf("Err: SMI read ready timeout\n");
-			return -EFAULT;
-		}
-	} while (!(smi_reg & MVNETA_SMI_READ_VALID));
-
-	/* Wait for the data to update in the SMI register */
-	for (timeout = 0; timeout < MVNETA_SMI_TIMEOUT; timeout++)
-		;
-
-	return mvreg_read(pp, MVNETA_SMI) & MVNETA_SMI_DATA_MASK;
-}
-
-/*
- * mvneta_mdio_write - miiphy_write callback function.
- *
- * Returns 0 if write succeed, -EINVAL on bad parameters
- * -ETIME on timeout
- */
-static int mvneta_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
-			     u16 value)
-{
-	struct mvneta_port *pp = bus->priv;
-	u32 smi_reg;
-
-	/* check parameters */
-	if (addr > MVNETA_PHY_ADDR_MASK) {
-		printf("Error: Invalid PHY address %d\n", addr);
-		return -EFAULT;
-	}
-
-	if (reg > MVNETA_PHY_REG_MASK) {
-		printf("Err: Invalid register offset %d\n", reg);
-		return -EFAULT;
-	}
-
-	/* wait till the SMI is not busy */
-	if (smi_wait_ready(pp) < 0)
-		return -EFAULT;
-
-	/* fill the phy addr and reg offset and write opcode and data */
-	smi_reg = value << MVNETA_SMI_DATA_OFFS;
-	smi_reg |= (addr << MVNETA_SMI_DEV_ADDR_OFFS)
-		| (reg << MVNETA_SMI_REG_ADDR_OFFS);
-	smi_reg &= ~MVNETA_SMI_OPCODE_READ;
-
-	/* write the smi register */
-	mvreg_write(pp, MVNETA_SMI, smi_reg);
-
-	return 0;
-}
-
 static int mvneta_start(struct udevice *dev)
 {
 	struct mvneta_port *pp = dev_get_priv(dev);
@@ -1690,10 +1568,9 @@ static int mvneta_probe(struct udevice *dev)
 #endif
 	void *blob = (void *)gd->fdt_blob;
 	int node = dev_of_offset(dev);
-	struct mii_dev *bus;
 	void *bd_space;
-	int ret;
 	int fl_node;
+	int ret;
 
 	/*
 	 * Allocate buffer area for descs and rx_buffers. This is only
@@ -1739,22 +1616,6 @@ static int mvneta_probe(struct udevice *dev)
 		pp->fixed_link = true;
 	}
 
-	bus = mdio_alloc();
-	if (!bus) {
-		printf("Failed to allocate MDIO bus\n");
-		return -ENOMEM;
-	}
-
-	bus->read = mvneta_mdio_read;
-	bus->write = mvneta_mdio_write;
-	snprintf(bus->name, sizeof(bus->name), dev->name);
-	bus->priv = (void *)pp;
-	pp->bus = bus;
-
-	ret = mdio_register(bus);
-	if (ret)
-		return ret;
-
 #if CONFIG_IS_ENABLED(DM_GPIO)
 	ret = dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args);
 	if (!ret && ofnode_is_enabled(sfp_args.node))
@@ -1774,7 +1635,7 @@ static int mvneta_probe(struct udevice *dev)
 		dm_gpio_set_value(&pp->sfp_tx_disable_gpio, 0);
 #endif
 
-	return board_network_enable(bus);
+	return 0;
 }
 
 static void mvneta_stop(struct udevice *dev)
Signature · 1 line
2.35.1
#18 lore raw

PATCH 7/19 arm: mvebu: turris_mox: Use DM registered MDIO

In reply to Marek Behún

From: Marek Behún <[email protected]>

In order to be able to get rid of the non-DM MDIO bus registered in mvneta driver, start using the DM registered one in Turris MOX board code.

This also allows us to drop the hack introduced in MOX' -u-boot.dtsi file.

---
 .../dts/armada-3720-turris-mox-u-boot.dtsi    | 19 ----
 board/CZ.NIC/turris_mox/turris_mox.c          | 88 +++++++++----------
 2 files changed, 44 insertions(+), 63 deletions(-)
arch/arm/dts/armada-3720-turris-mox-u-boot.dtsi +0 -19
index 28a36a6103..71d5e70ca4 100644
@@ -3,25 +3,6 @@
  * 2022 by Marek Behún <[email protected]>
  */
 
-/ {
-	mdio {
-		#address-cells = <1>;
-		#size-cells = <0>;
-
-		old_binding_phy1: ethernet-phy@1 {
-			reg = <1>;
-		};
-	};
-};
-
-&eth0 {
-	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
-	/delete-property/ phy-handle;
-	phy = <&old_binding_phy1>;
-};
-
-/delete-node/ &mdio;
-
 &usb3 {
 	vbus-supply = <&exp_usb3_vbus>;
 };
board/CZ.NIC/turris_mox/turris_mox.c +44 -44

150 lines not on this page · raw message

Signature · 1 line
2.35.1
#23 lore raw

PATCH 9/19 net: mvneta: Fix unused variable warning if DM_GPIO is disabled

In reply to Marek Behún

From: Marek Behún <[email protected]>

The ret variable in mvneta_probe() is unused if DM_GPIO is disabled.

Since the variable is used only once after assigning value, we can inline the usage and drop the variable.

---
 drivers/net/mvneta.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/mvneta.c +2 -3
index 19f8145fc0..72789fc5c6 100644
@@ -1570,7 +1570,6 @@ static int mvneta_probe(struct udevice *dev)
 	int node = dev_of_offset(dev);
 	void *bd_space;
 	int fl_node;
-	int ret;
 
 	/*
 	 * Allocate buffer area for descs and rx_buffers. This is only
@@ -1617,8 +1616,8 @@ static int mvneta_probe(struct udevice *dev)
 	}
 
 #if CONFIG_IS_ENABLED(DM_GPIO)
-	ret = dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args);
-	if (!ret && ofnode_is_enabled(sfp_args.node))
+	if (!dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args) &&
+	    ofnode_is_enabled(sfp_args.node))
 		gpio_request_by_name_nodev(sfp_args.node, "tx-disable-gpio", 0,
 					   &pp->sfp_tx_disable_gpio, GPIOD_IS_OUT);
 
Signature · 1 line
2.35.1
#32 lore raw

PATCH 12/19 net: mvneta: Drop unnecessary space

In reply to Marek Behún

From: Marek Behún <[email protected]>

Drop unnecessary space in mvneta_adjust_link().

---
 drivers/net/mvneta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvneta.c +1 -1
index 7d582c1206..5c3f7125b5 100644
@@ -1183,7 +1183,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 		mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 
 		pp->duplex = phydev->duplex;
-		pp->speed  = phydev->speed;
+		pp->speed = phydev->speed;
 	}
 
 	if (phydev->link != pp->link) {
Signature · 1 line
2.35.1
#26 lore raw

PATCH 10/19 net: mvneta: Drop one indentation level in mvneta_adjust_link()

In reply to Marek Behún

From: Marek Behún <[email protected]>

Drop one indentation level in the mvneta_adjust_link() function.

---
 drivers/net/mvneta.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/net/mvneta.c +18 -20
index 72789fc5c6..66d5e10174 100644
@@ -1161,31 +1161,29 @@ static void mvneta_adjust_link(struct udevice *dev)
 		return;
 	}
 
-	if (phydev->link) {
-		if ((pp->speed != phydev->speed) ||
-		    (pp->duplex != phydev->duplex)) {
-			u32 val;
+	if (phydev->link &&
+	    (pp->speed != phydev->speed || pp->duplex != phydev->duplex)) {
+		u32 val;
 
-			val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
-			val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
-				 MVNETA_GMAC_CONFIG_GMII_SPEED |
-				 MVNETA_GMAC_CONFIG_FULL_DUPLEX |
-				 MVNETA_GMAC_AN_SPEED_EN |
-				 MVNETA_GMAC_AN_DUPLEX_EN);
+		val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
+		val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
+			 MVNETA_GMAC_CONFIG_GMII_SPEED |
+			 MVNETA_GMAC_CONFIG_FULL_DUPLEX |
+			 MVNETA_GMAC_AN_SPEED_EN |
+			 MVNETA_GMAC_AN_DUPLEX_EN);
 
-			if (phydev->duplex)
-				val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
+		if (phydev->duplex)
+			val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
 
-			if (phydev->speed == SPEED_1000)
-				val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-			else if (pp->speed == SPEED_100)
-				val |= MVNETA_GMAC_CONFIG_MII_SPEED;
+		if (phydev->speed == SPEED_1000)
+			val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
+		else if (pp->speed == SPEED_100)
+			val |= MVNETA_GMAC_CONFIG_MII_SPEED;
 
-			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
+		mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 
-			pp->duplex = phydev->duplex;
-			pp->speed  = phydev->speed;
-		}
+		pp->duplex = phydev->duplex;
+		pp->speed  = phydev->speed;
 	}
 
 	if (phydev->link != pp->link) {
Signature · 1 line
2.35.1
#38 lore raw

PATCH 14/19 net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS

In reply to Marek Behún

From: Marek Behún <[email protected]>

The CONFIG_* macros are reserved for Kconfig. This was probably done when this driver was being imported from Linux. Rename the macro.

---
 drivers/net/mvneta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +2 -2
index 0ec9d2957c..519e06ff01 100644
@@ -40,7 +40,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define CONFIG_NR_CPUS		1
+#define MVNETA_NR_CPUS		1
 #define ETH_HLEN		14	/* Total octets in header */
 
 /* 2(HW hdr) 14(MAC hdr) 4(CRC) 32(extra for cache prefetch) */
@@ -770,7 +770,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 	/* Set CPU queue access map - all CPUs have access to all RX
 	 * queues and to all TX queues
 	 */
-	for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++)
+	for (cpu = 0; cpu < MVNETA_NR_CPUS; cpu++)
 		mvreg_write(pp, MVNETA_CPU_MAP(cpu),
 			    (MVNETA_CPU_RXQ_ACCESS_ALL_MASK |
 			     MVNETA_CPU_TXQ_ACCESS_ALL_MASK));
Signature · 1 line
2.35.1
#35 lore raw

PATCH 13/19 net: mvneta: Don't check for CONFIG_PHYLIB

In reply to Marek Behún

From: Marek Behún <[email protected]>

Drop checking for CONFIG_PHYLIB in mvneta, this is already done in Kconfig.

---
 drivers/net/mvneta.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/net/mvneta.c +0 -4
index 5c3f7125b5..0ec9d2957c 100644
@@ -40,10 +40,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if !defined(CONFIG_PHYLIB)
-# error Marvell mvneta requires PHYLIB
-#endif
-
 #define CONFIG_NR_CPUS		1
 #define ETH_HLEN		14	/* Total octets in header */
 
Signature · 1 line
2.35.1
#44 lore raw

PATCH 16/19 net: mvneta: Write PHY address just before enabling HW polling

In reply to Marek Behún

From: Marek Behún <[email protected]>

Write PHY address just before enabling HW polling of the PHY.

---
 drivers/net/mvneta.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/mvneta.c +2 -4
index 5b1c4fe5fc..4917857681 100644
@@ -814,6 +814,8 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 
 	/* Enable PHY polling in hardware if not in fixed-link mode */
 	if (!pp->fixed_link) {
+		mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
+
 		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
 		val |= MVNETA_PHY_POLLING_ENABLE;
 		mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
@@ -1431,10 +1433,6 @@ static int mvneta_start(struct udevice *dev)
 
 		pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
 
-		/* Set PHY address in case we will enable HW polling */
-		if (!pp->fixed_link)
-			mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
-
 		pp->phydev = phydev;
 		phy_config(phydev);
 		phy_startup(phydev);
Signature · 1 line
2.35.1
#47 lore raw

PATCH 17/19 net: mvneta: Drop fixed_link member from private struct

In reply to Marek Behún

From: Marek Behún <[email protected]>

Since this member is checked only at two places drop it and inline it's usage.

---
 drivers/net/mvneta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/mvneta.c +2 -5
index 4917857681..378789b632 100644
@@ -273,7 +273,6 @@ struct mvneta_port {
 	u16 rx_ring_size;
 
 	phy_interface_t phy_interface;
-	bool fixed_link;
 	unsigned int link;
 	unsigned int duplex;
 	unsigned int speed;
@@ -813,7 +812,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 	mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
 	/* Enable PHY polling in hardware if not in fixed-link mode */
-	if (!pp->fixed_link) {
+	if (pp->phydev->phy_id != PHY_FIXED_ID) {
 		mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
 
 		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
@@ -1173,7 +1172,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 		 * be added). Also, why is ADVERT_FC enabled if we don't enable
 		 * inband AN at all?
 		 */
-		if (pp->fixed_link)
+		if (pp->phydev->phy_id == PHY_FIXED_ID)
 			val = MVNETA_GMAC_FORCE_LINK_UP |
 			      MVNETA_GMAC_IB_BYPASS_AN_EN |
 			      MVNETA_GMAC_SET_FC_EN |
@@ -1431,8 +1430,6 @@ static int mvneta_start(struct udevice *dev)
 			return -ENODEV;
 		}
 
-		pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
-
 		pp->phydev = phydev;
 		phy_config(phydev);
 		phy_startup(phydev);
Signature · 1 line
2.35.1
#50 lore raw

PATCH 18/19 net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in

In reply to Marek Behún

From: Marek Behún <[email protected]>

Guard the code handling the fixed PHY case by
CONFIG_IS_ENABLED(PHY_FIXED).

---
 drivers/net/mvneta.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +4 -2
index 378789b632..292c364e5e 100644
@@ -812,7 +812,8 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 	mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
 	/* Enable PHY polling in hardware if not in fixed-link mode */
-	if (pp->phydev->phy_id != PHY_FIXED_ID) {
+	if (!CONFIG_IS_ENABLED(PHY_FIXED) ||
+	    pp->phydev->phy_id != PHY_FIXED_ID) {
 		mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
 
 		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
@@ -1172,7 +1173,8 @@ static void mvneta_adjust_link(struct udevice *dev)
 		 * be added). Also, why is ADVERT_FC enabled if we don't enable
 		 * inband AN at all?
 		 */
-		if (pp->phydev->phy_id == PHY_FIXED_ID)
+		if (CONFIG_IS_ENABLED(PHY_FIXED) &&
+		    pp->phydev->phy_id == PHY_FIXED_ID)
 			val = MVNETA_GMAC_FORCE_LINK_UP |
 			      MVNETA_GMAC_IB_BYPASS_AN_EN |
 			      MVNETA_GMAC_SET_FC_EN |
Signature · 1 line
2.35.1
#53 lore raw

PATCH 19/19 net: mvneta: Drop unneeded macro

In reply to Marek Behún

From: Marek Behún <[email protected]>

Macro MVNETA_GMAC_FORCE_LINK_UP can be dropped from value assignment in fixed link case, since it's value is written into the register later in the function for link-down-to-link-up case. The value is written as MVNETA_GMAC_FORCE_LINK_DOWN | MVNETA_GMAC_FORCE_LINK_PASS, and so the macro definition can also be dropped.

---
 drivers/net/mvneta.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/mvneta.c +1 -3
index 292c364e5e..d2c42c4396 100644
@@ -188,7 +188,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define MVNETA_GMAC_AUTONEG_CONFIG               0x2c0c
 #define      MVNETA_GMAC_FORCE_LINK_DOWN         BIT(0)
 #define      MVNETA_GMAC_FORCE_LINK_PASS         BIT(1)
-#define      MVNETA_GMAC_FORCE_LINK_UP           (BIT(0) | BIT(1))
 #define      MVNETA_GMAC_IB_BYPASS_AN_EN         BIT(3)
 #define      MVNETA_GMAC_CONFIG_MII_SPEED        BIT(5)
 #define      MVNETA_GMAC_CONFIG_GMII_SPEED       BIT(6)
@@ -1175,8 +1174,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 		 */
 		if (CONFIG_IS_ENABLED(PHY_FIXED) &&
 		    pp->phydev->phy_id == PHY_FIXED_ID)
-			val = MVNETA_GMAC_FORCE_LINK_UP |
-			      MVNETA_GMAC_IB_BYPASS_AN_EN |
+			val = MVNETA_GMAC_IB_BYPASS_AN_EN |
 			      MVNETA_GMAC_SET_FC_EN |
 			      MVNETA_GMAC_ADVERT_FC_EN |
 			      MVNETA_GMAC_SAMPLE_TX_CFG_EN;
Signature · 1 line
2.35.1
#41 lore raw

PATCH 15/19 net: mvneta: Convert to use PHY_FIXED for fixed-link

In reply to Marek Behún

From: Marek Behún <[email protected]>

Stop parsing fixed-link in the MAC driver. Instead support only PHY mode and let the fixed PHY driver handle the fixed-link case.

Enable CONFIG_PHY_FIXED for mvneta boards that need it: Turris Omnia and ESPRESSObin.

---
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/turris_omnia_defconfig              |  1 +
 drivers/net/mvneta.c                        | 98 ++++++++-------------
 3 files changed, 39 insertions(+), 61 deletions(-)
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index 37e4fdc41e..8d7d57ff1b 100644
@@ -74,6 +74,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_MARVELL=y
+CONFIG_PHY_FIXED=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_MVNETA=y
configs/turris_omnia_defconfig +1 -0
index 6b218bd7a7..bdd70f2ba7 100644
@@ -79,6 +79,7 @@ CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_MARVELL=y
+CONFIG_PHY_FIXED=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
drivers/net/mvneta.c +37 -61

135 lines not on this page · raw message

Signature · 1 line
2.35.1
#29 lore raw

PATCH 11/19 net: mvneta: Use bool instead of int for boolean variable

In reply to Marek Behún

From: Marek Behún <[email protected]>

Use the bool type instead of int for status_change variable.

---
 drivers/net/mvneta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +2 -2
index 66d5e10174..7d582c1206 100644
@@ -1154,7 +1154,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 {
 	struct mvneta_port *pp = dev_get_priv(dev);
 	struct phy_device *phydev = pp->phydev;
-	int status_change = 0;
+	bool status_change = false;
 
 	if (pp->fixed_link) {
 		debug("Using fixed link, skip link adjust\n");
@@ -1193,7 +1193,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 		}
 
 		pp->link = phydev->link;
-		status_change = 1;
+		status_change = true;
 	}
 
 	if (status_change) {
Signature · 1 line
2.35.1
Reviewed-by on v1 1/19
#2 lore raw

Re: [PATCH u-boot-marvell 01/19] net: mvneta: Get rid of platdata

In reply to Marek Behún
Quoted 75 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop .of_to_plat() from the mvneta driver and parse the two properties in .probe().

---
 drivers/net/mvneta.c | 24 ++++--------------------
 1 file changed, 4 insertions(+), 20 deletions(-)
drivers/net/mvneta.c +4 -21
index 15dc714058..d1c5f7930d 100644
@@ -1692,7 +1692,6 @@ static int mvneta_recv(struct udevice *dev, int flags, uchar **packetp)
 
 static int mvneta_probe(struct udevice *dev)
 {
-       struct eth_pdata *pdata = dev_get_plat(dev);
        struct mvneta_port *pp = dev_get_priv(dev);
 #if CONFIG_IS_ENABLED(DM_GPIO)
        struct ofnode_phandle_args sfp_args;
@@ -1729,7 +1728,10 @@ static int mvneta_probe(struct udevice *dev)
                buffer_loc.rx_buffers = (phys_addr_t)(bd_space + size);
        }
 
-       pp->base = (void __iomem *)pdata->iobase;
+       pp->base = dev_read_addr_ptr(dev);
+       pp->phy_interface = dev_read_phy_mode(dev);
+       if (pp->phy_interface == PHY_INTERFACE_MODE_NA)
+               return -EINVAL;
 
        /* Configure MBUS address windows */
        if (device_is_compatible(dev, "marvell,armada-3700-neta"))
@@ -1737,9 +1739,6 @@ static int mvneta_probe(struct udevice *dev)
        else
                mvneta_conf_mbus_windows(pp);
 
-       /* PHY interface is already decoded in mvneta_of_to_plat() */
-       pp->phy_interface = pdata->phy_interface;
-
        /* fetch 'fixed-link' property from 'neta' node */
        fl_node = fdt_subnode_offset(blob, node, "fixed-link");
        if (fl_node != -FDT_ERR_NOTFOUND) {
@@ -1808,20 +1807,6 @@ static const struct eth_ops mvneta_ops = {
        .write_hwaddr   = mvneta_write_hwaddr,
 };
 
-static int mvneta_of_to_plat(struct udevice *dev)
-{
-       struct eth_pdata *pdata = dev_get_plat(dev);
-
-       pdata->iobase = dev_read_addr(dev);
-
-       /* Get phy-mode / phy_interface from DT */
-       pdata->phy_interface = dev_read_phy_mode(dev);
-       if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
-               return -EINVAL;
-
-       return 0;
-}
-
 static const struct udevice_id mvneta_ids[] = {
        { .compatible = "marvell,armada-370-neta" },
        { .compatible = "marvell,armada-xp-neta" },
@@ -1833,7 +1818,6 @@ U_BOOT_DRIVER(mvneta) = {
        .name   = "mvneta",
        .id     = UCLASS_ETH,
        .of_match = mvneta_ids,
-       .of_to_plat = mvneta_of_to_plat,
        .probe  = mvneta_probe,
        .ops    = &mvneta_ops,
        .priv_auto      = sizeof(struct mvneta_port),
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 6/19
#16 lore raw

Re: [PATCH u-boot-marvell 06/19] net: mdio-uclass: add dm_phy_find_by_ofnode() helper

In reply to Marek Behún
Quoted 65 lines · Marek Behún

From: Marek Behún <[email protected]>

Add helper to resolve PHY node from it's ofnode via DM MDIO subsystem.

---
 include/miiphy.h  |  9 +++++++++
 net/mdio-uclass.c | 22 ++++++++++++++++++++++
 2 files changed, 31 insertions(+)
include/miiphy.h +9 -0
index 110921f20d..c66a1845b5 100644
@@ -188,6 +188,15 @@ int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 va
  */
 int dm_mdio_reset(struct udevice *mdio_dev);
 
+/**
+ * dm_phy_find_by_ofnode - Find PHY device by ofnode
+ *
+ * @phynode: PHY's ofnode
+ *
+ * Return: pointer to phy_device, or NULL on error
+ */
+struct phy_device *dm_phy_find_by_ofnode(ofnode phynode);
+
 /**
  * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
  *
net/mdio-uclass.c +22 -1
index 7593618d9a..4401492ca0 100644
@@ -129,6 +129,28 @@ static int dm_mdio_pre_remove(struct udevice *dev)
        return 0;
 }
 
+struct phy_device *dm_phy_find_by_ofnode(ofnode phynode)
+{
+       struct mdio_perdev_priv *pdata;
+       struct udevice *mdiodev;
+       u32 phy_addr;
+
+       if (ofnode_read_u32(phynode, "reg", &phy_addr))
+               return NULL;
+
+       if (uclass_get_device_by_ofnode(UCLASS_MDIO,
+                                       ofnode_get_parent(phynode),
+                                       &mdiodev))
+               return NULL;
+
+       if (device_probe(mdiodev))
+               return NULL;
+
+       pdata = dev_get_uclass_priv(mdiodev);
+
+       return phy_find_by_mask(pdata->mii_bus, BIT(phy_addr));
+}
+
 struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr,
                                       struct udevice *ethdev,
                                       phy_interface_t interface)
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 2/19
#5 lore raw

Re: [PATCH u-boot-marvell 02/19] net: mvneta: Fix 10Mbps speed

In reply to Marek Behún
Quoted 25 lines · Marek Behún

From: Marek Behún <[email protected]>

In mvneta_adjust_link() we need to set MII_SPEED bit only if PHY reports the speed at 100Mbps.

---
 drivers/net/mvneta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvneta.c +1 -2
index d1c5f7930d..79cdb93341 100644
@@ -1195,7 +1195,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 
                        if (phydev->speed == SPEED_1000)
                                val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-                       else
+                       else if (pp->speed == SPEED_100)
                                val |= MVNETA_GMAC_CONFIG_MII_SPEED;
 
                        mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 3/19
#8 lore raw

Re: [PATCH u-boot-marvell 03/19] net: mvneta: Use DM MDIO API for connecting PHY

In reply to Marek Behún
Quoted 221 lines · Marek Behún

From: Marek Behún <[email protected]>

Use the modern DM MDIO API for connecting PHY in the mvneta driver.

This requires enabling MVMDIO driver in several config files.

---
 configs/clearfog_defconfig                  |  1 +
 configs/controlcenterdc_defconfig           |  1 +
 configs/db-88f6820-amc_defconfig            |  1 +
 configs/db-88f6820-gp_defconfig             |  1 +
 configs/db-mv784mp-gp_defconfig             |  1 +
 configs/ds414_defconfig                     |  1 +
 configs/helios4_defconfig                   |  1 +
 configs/maxbcm_defconfig                    |  1 +
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/theadorable_debug_defconfig         |  1 +
 configs/turris_mox_defconfig                |  1 +
 configs/turris_omnia_defconfig              |  1 +
 configs/uDPU_defconfig                      |  1 +
 drivers/net/Kconfig                         |  1 +
 drivers/net/mvneta.c                        | 11 +++++------
 15 files changed, 19 insertions(+), 6 deletions(-)
configs/clearfog_defconfig +1 -0
index 880f16a6e0..b8f59d2962 100644
@@ -63,6 +63,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SCSI=y
configs/controlcenterdc_defconfig +1 -0
index d4b966b93f..df38b2c54f 100644
@@ -77,6 +77,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_MVEBU=y
configs/db-88f6820-amc_defconfig +1 -0
index 46c822fccd..9b77b4a5f0 100644
@@ -67,6 +67,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_DEBUG_UART_SHIFT=2
configs/db-88f6820-gp_defconfig +1 -0
index 2dcbc2f29a..f56d1fbf25 100644
@@ -62,6 +62,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SCSI=y
configs/db-mv784mp-gp_defconfig +1 -0
index f19cc54975..5683f11836 100644
@@ -65,6 +65,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_DEBUG_UART_SHIFT=2
configs/ds414_defconfig +1 -0
index a3279c15c5..a83fe079b3 100644
@@ -65,6 +65,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_DEBUG_UART_SHIFT=2
configs/helios4_defconfig +1 -0
index 7d812e8fab..c2130bacb4 100644
@@ -63,6 +63,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
 CONFIG_SCSI=y
configs/maxbcm_defconfig +1 -0
index 8dd6adf247..40f79d47ea 100644
@@ -47,6 +47,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_DEBUG_UART_SHIFT=2
 CONFIG_SYS_NS16550=y
 CONFIG_KIRKWOOD_SPI=y
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index ff05630d20..af30f1b363 100644
@@ -76,6 +76,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI=y
 CONFIG_PCI_AARDVARK=y
configs/theadorable_debug_defconfig +1 -0
index 86129e7d2d..9a03a0a7a3 100644
@@ -70,6 +70,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_DM_PCI_COMPAT=y
 CONFIG_PCI_MVEBU=y
configs/turris_mox_defconfig +1 -0
index 9a76a118c2..bcd3699a4f 100644
@@ -82,6 +82,7 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI=y
 CONFIG_PCI_AARDVARK=y
configs/turris_omnia_defconfig +1 -0
index ad56d3824b..6b218bd7a7 100644
@@ -82,6 +82,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
+CONFIG_MVMDIO=y
 CONFIG_NVME_PCI=y
 CONFIG_PCI=y
 CONFIG_PCI_MVEBU=y
configs/uDPU_defconfig +1 -0
index c07bad5076..f2852ad29b 100644
@@ -73,6 +73,7 @@ CONFIG_PHY_MARVELL=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
 CONFIG_PCI=y
 CONFIG_PCI_AARDVARK=y
 CONFIG_PHY=y
drivers/net/Kconfig +1 -0
index 347fe8aa42..47f7a262f2 100644
@@ -445,6 +445,7 @@ config MVNETA
        bool "Marvell Armada XP/385/3700 network interface support"
        depends on ARMADA_XP || ARMADA_38X || ARMADA_3700
        select PHYLIB
+       select DM_MDIO
        help
          This driver supports the network interface units in the
          Marvell ARMADA XP, ARMADA 38X and ARMADA 3700 SoCs
drivers/net/mvneta.c +5 -7
index 79cdb93341..24a491dcde 100644
@@ -1571,16 +1571,15 @@ static int mvneta_start(struct udevice *dev)
 
                        mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
                } else {
-                       /* Set phy address of the port */
-                       mvreg_write(pp, MVNETA_PHY_ADDR, pp->phyaddr);
-
-                       phydev = phy_connect(pp->bus, pp->phyaddr, dev,
-                                            pp->phy_interface);
+                       phydev = dm_eth_phy_connect(dev);
                        if (!phydev) {
-                               printf("phy_connect failed\n");
+                               printf("dm_eth_phy_connect failed\n");
                                return -ENODEV;
                        }
 
+                       /* Set PHY address in case we will enable HW polling */
+                       mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
+
                        pp->phydev = phydev;
                        phy_config(phydev);
                        phy_startup(phydev);
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 4/19
#11 lore raw

Re: [PATCH u-boot-marvell 04/19] net: mvneta: Remember fixed link instead of PHY address in priv data

In reply to Marek Behún
Quoted 102 lines · Marek Behún

From: Marek Behún <[email protected]>

We don't need to remember PHY address anymore, because since using DM MDIO for connecting PHY, the address is parsed by mdio-uclass from the ofnode.

But the driver uses a special value of the address to signal fixed link usage.

Drop phyaddr add fixed_link in driver private structure. This simplifies code a little.

---
 drivers/net/mvneta.c | 23 +++++------------------
 1 file changed, 5 insertions(+), 18 deletions(-)
drivers/net/mvneta.c +5 -19
index 24a491dcde..83e9629138 100644
@@ -277,12 +277,12 @@ struct mvneta_port {
        u16 rx_ring_size;
 
        phy_interface_t phy_interface;
+       bool fixed_link;
        unsigned int link;
        unsigned int duplex;
        unsigned int speed;
 
        int init;
-       int phyaddr;
        struct phy_device *phydev;
 #if CONFIG_IS_ENABLED(DM_GPIO)
        struct gpio_desc phy_reset_gpio;
@@ -576,13 +576,6 @@ static void mvneta_rxq_buf_size_set(struct mvneta_port *pp,
        mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val);
 }
 
-static int mvneta_port_is_fixed_link(struct mvneta_port *pp)
-{
-       /* phy_addr is set to invalid value for fixed link */
-       return pp->phyaddr > PHY_MAX_ADDR;
-}
-
-
 /* Start the Ethernet port RX and TX activity */
 static void mvneta_port_up(struct mvneta_port *pp)
 {
@@ -834,7 +827,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
        mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
        /* Enable PHY polling in hardware if not in fixed-link mode */
-       if (!mvneta_port_is_fixed_link(pp)) {
+       if (!pp->fixed_link) {
                val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
                val |= MVNETA_PHY_POLLING_ENABLE;
                mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
@@ -1173,7 +1166,7 @@ static void mvneta_adjust_link(struct udevice *dev)
        struct phy_device *phydev = pp->phydev;
        int status_change = 0;
 
-       if (mvneta_port_is_fixed_link(pp)) {
+       if (pp->fixed_link) {
                debug("Using fixed link, skip link adjust\n");
                return;
        }
@@ -1548,7 +1541,7 @@ static int mvneta_start(struct udevice *dev)
        mvneta_port_power_up(pp, pp->phy_interface);
 
        if (!pp->init || pp->link == 0) {
-               if (mvneta_port_is_fixed_link(pp)) {
+               if (pp->fixed_link) {
                        u32 val;
 
                        pp->init = 1;
@@ -1698,7 +1691,6 @@ static int mvneta_probe(struct udevice *dev)
        void *blob = (void *)gd->fdt_blob;
        int node = dev_of_offset(dev);
        struct mii_dev *bus;
-       unsigned long addr;
        void *bd_space;
        int ret;
        int fl_node;
@@ -1742,14 +1734,9 @@ static int mvneta_probe(struct udevice *dev)
        fl_node = fdt_subnode_offset(blob, node, "fixed-link");
        if (fl_node != -FDT_ERR_NOTFOUND) {
                /* set phy_addr to invalid value for fixed link */
-               pp->phyaddr = PHY_MAX_ADDR + 1;
                pp->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex");
                pp->speed = fdtdec_get_int(blob, fl_node, "speed", 0);
-       } else {
-               /* Now read phyaddr from DT */
-               addr = fdtdec_get_int(blob, node, "phy", 0);
-               addr = fdt_node_offset_by_phandle(blob, addr);
-               pp->phyaddr = fdtdec_get_int(blob, addr, "reg", 0);
+               pp->fixed_link = true;
        }
 
        bus = mdio_alloc();
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 8/19
#21 lore raw

Re: [PATCH u-boot-marvell 08/19] net: mvneta: Don't register MDIO bus

In reply to Marek Behún
Quoted 203 lines · Marek Behún

From: Marek Behún <[email protected]>

This MDIO bus is now handled by a proper mvmdio DM driver. Remove it from mvneta.

---
 drivers/net/mvneta.c | 143 +------------------------------------------
 1 file changed, 2 insertions(+), 141 deletions(-)
drivers/net/mvneta.c +2 -142
index 83e9629138..19f8145fc0 100644
@@ -288,7 +288,6 @@ struct mvneta_port {
        struct gpio_desc phy_reset_gpio;
        struct gpio_desc sfp_tx_disable_gpio;
 #endif
-       struct mii_dev *bus;
 };
 
 /* The mvneta_tx_desc and mvneta_rx_desc structures describe the
@@ -414,15 +413,6 @@ static struct buffer_location buffer_loc;
  */
 #define BD_SPACE       (1 << 20)
 
-/*
- * Dummy implementation that can be overwritten by a board
- * specific function
- */
-__weak int board_network_enable(struct mii_dev *bus)
-{
-       return 0;
-}
-
 /* Utility/helper methods */
 
 /* Write helper method */
@@ -1421,118 +1411,6 @@ static int mvneta_init(struct udevice *dev)
 
 /* U-Boot only functions follow here */
 
-/* SMI / MDIO functions */
-
-static int smi_wait_ready(struct mvneta_port *pp)
-{
-       u32 timeout = MVNETA_SMI_TIMEOUT;
-       u32 smi_reg;
-
-       /* wait till the SMI is not busy */
-       do {
-               /* read smi register */
-               smi_reg = mvreg_read(pp, MVNETA_SMI);
-               if (timeout-- == 0) {
-                       printf("Error: SMI busy timeout\n");
-                       return -EFAULT;
-               }
-       } while (smi_reg & MVNETA_SMI_BUSY);
-
-       return 0;
-}
-
-/*
- * mvneta_mdio_read - miiphy_read callback function.
- *
- * Returns 16bit phy register value, or 0xffff on error
- */
-static int mvneta_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
-{
-       struct mvneta_port *pp = bus->priv;
-       u32 smi_reg;
-       u32 timeout;
-
-       /* check parameters */
-       if (addr > MVNETA_PHY_ADDR_MASK) {
-               printf("Error: Invalid PHY address %d\n", addr);
-               return -EFAULT;
-       }
-
-       if (reg > MVNETA_PHY_REG_MASK) {
-               printf("Err: Invalid register offset %d\n", reg);
-               return -EFAULT;
-       }
-
-       /* wait till the SMI is not busy */
-       if (smi_wait_ready(pp) < 0)
-               return -EFAULT;
-
-       /* fill the phy address and regiser offset and read opcode */
-       smi_reg = (addr << MVNETA_SMI_DEV_ADDR_OFFS)
-               | (reg << MVNETA_SMI_REG_ADDR_OFFS)
-               | MVNETA_SMI_OPCODE_READ;
-
-       /* write the smi register */
-       mvreg_write(pp, MVNETA_SMI, smi_reg);
-
-       /* wait till read value is ready */
-       timeout = MVNETA_SMI_TIMEOUT;
-
-       do {
-               /* read smi register */
-               smi_reg = mvreg_read(pp, MVNETA_SMI);
-               if (timeout-- == 0) {
-                       printf("Err: SMI read ready timeout\n");
-                       return -EFAULT;
-               }
-       } while (!(smi_reg & MVNETA_SMI_READ_VALID));
-
-       /* Wait for the data to update in the SMI register */
-       for (timeout = 0; timeout < MVNETA_SMI_TIMEOUT; timeout++)
-               ;
-
-       return mvreg_read(pp, MVNETA_SMI) & MVNETA_SMI_DATA_MASK;
-}
-
-/*
- * mvneta_mdio_write - miiphy_write callback function.
- *
- * Returns 0 if write succeed, -EINVAL on bad parameters
- * -ETIME on timeout
- */
-static int mvneta_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
-                            u16 value)
-{
-       struct mvneta_port *pp = bus->priv;
-       u32 smi_reg;
-
-       /* check parameters */
-       if (addr > MVNETA_PHY_ADDR_MASK) {
-               printf("Error: Invalid PHY address %d\n", addr);
-               return -EFAULT;
-       }
-
-       if (reg > MVNETA_PHY_REG_MASK) {
-               printf("Err: Invalid register offset %d\n", reg);
-               return -EFAULT;
-       }
-
-       /* wait till the SMI is not busy */
-       if (smi_wait_ready(pp) < 0)
-               return -EFAULT;
-
-       /* fill the phy addr and reg offset and write opcode and data */
-       smi_reg = value << MVNETA_SMI_DATA_OFFS;
-       smi_reg |= (addr << MVNETA_SMI_DEV_ADDR_OFFS)
-               | (reg << MVNETA_SMI_REG_ADDR_OFFS);
-       smi_reg &= ~MVNETA_SMI_OPCODE_READ;
-
-       /* write the smi register */
-       mvreg_write(pp, MVNETA_SMI, smi_reg);
-
-       return 0;
-}
-
 static int mvneta_start(struct udevice *dev)
 {
        struct mvneta_port *pp = dev_get_priv(dev);
@@ -1690,10 +1568,9 @@ static int mvneta_probe(struct udevice *dev)
 #endif
        void *blob = (void *)gd->fdt_blob;
        int node = dev_of_offset(dev);
-       struct mii_dev *bus;
        void *bd_space;
-       int ret;
        int fl_node;
+       int ret;
 
        /*
         * Allocate buffer area for descs and rx_buffers. This is only
@@ -1739,22 +1616,6 @@ static int mvneta_probe(struct udevice *dev)
                pp->fixed_link = true;
        }
 
-       bus = mdio_alloc();
-       if (!bus) {
-               printf("Failed to allocate MDIO bus\n");
-               return -ENOMEM;
-       }
-
-       bus->read = mvneta_mdio_read;
-       bus->write = mvneta_mdio_write;
-       snprintf(bus->name, sizeof(bus->name), dev->name);
-       bus->priv = (void *)pp;
-       pp->bus = bus;
-
-       ret = mdio_register(bus);
-       if (ret)
-               return ret;
-
 #if CONFIG_IS_ENABLED(DM_GPIO)
        ret = dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args);
        if (!ret && ofnode_is_enabled(sfp_args.node))
@@ -1774,7 +1635,7 @@ static int mvneta_probe(struct udevice *dev)
                dm_gpio_set_value(&pp->sfp_tx_disable_gpio, 0);
 #endif
 
-       return board_network_enable(bus);
+       return 0;
 }
 
 static void mvneta_stop(struct udevice *dev)
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 9/19
#24 lore raw

Re: [PATCH u-boot-marvell 09/19] net: mvneta: Fix unused variable warning if DM_GPIO is disabled

In reply to Marek Behún
Quoted 37 lines · Marek Behún

From: Marek Behún <[email protected]>

The ret variable in mvneta_probe() is unused if DM_GPIO is disabled.

Since the variable is used only once after assigning value, we can inline the usage and drop the variable.

---
 drivers/net/mvneta.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/mvneta.c +2 -4
index 19f8145fc0..72789fc5c6 100644
@@ -1570,7 +1570,6 @@ static int mvneta_probe(struct udevice *dev)
        int node = dev_of_offset(dev);
        void *bd_space;
        int fl_node;
-       int ret;
 
        /*
         * Allocate buffer area for descs and rx_buffers. This is only
@@ -1617,8 +1616,8 @@ static int mvneta_probe(struct udevice *dev)
        }
 
 #if CONFIG_IS_ENABLED(DM_GPIO)
-       ret = dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args);
-       if (!ret && ofnode_is_enabled(sfp_args.node))
+       if (!dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args) &&
+           ofnode_is_enabled(sfp_args.node))
                gpio_request_by_name_nodev(sfp_args.node, "tx-disable-gpio", 0,
                                           &pp->sfp_tx_disable_gpio, GPIOD_IS_OUT);
 
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 10/19
#27 lore raw

Re: [PATCH u-boot-marvell 10/19] net: mvneta: Drop one indentation level in mvneta_adjust_link()

In reply to Marek Behún
Quoted 65 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop one indentation level in the mvneta_adjust_link() function.

---
 drivers/net/mvneta.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)
drivers/net/mvneta.c +18 -21
index 72789fc5c6..66d5e10174 100644
@@ -1161,31 +1161,29 @@ static void mvneta_adjust_link(struct udevice *dev)
                return;
        }
 
-       if (phydev->link) {
-               if ((pp->speed != phydev->speed) ||
-                   (pp->duplex != phydev->duplex)) {
-                       u32 val;
+       if (phydev->link &&
+           (pp->speed != phydev->speed || pp->duplex != phydev->duplex)) {
+               u32 val;
 
-                       val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
-                       val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
-                                MVNETA_GMAC_CONFIG_GMII_SPEED |
-                                MVNETA_GMAC_CONFIG_FULL_DUPLEX |
-                                MVNETA_GMAC_AN_SPEED_EN |
-                                MVNETA_GMAC_AN_DUPLEX_EN);
+               val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
+               val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
+                        MVNETA_GMAC_CONFIG_GMII_SPEED |
+                        MVNETA_GMAC_CONFIG_FULL_DUPLEX |
+                        MVNETA_GMAC_AN_SPEED_EN |
+                        MVNETA_GMAC_AN_DUPLEX_EN);
 
-                       if (phydev->duplex)
-                               val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
+               if (phydev->duplex)
+                       val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
 
-                       if (phydev->speed == SPEED_1000)
-                               val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-                       else if (pp->speed == SPEED_100)
-                               val |= MVNETA_GMAC_CONFIG_MII_SPEED;
+               if (phydev->speed == SPEED_1000)
+                       val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
+               else if (pp->speed == SPEED_100)
+                       val |= MVNETA_GMAC_CONFIG_MII_SPEED;
 
-                       mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
+               mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 
-                       pp->duplex = phydev->duplex;
-                       pp->speed  = phydev->speed;
-               }
+               pp->duplex = phydev->duplex;
+               pp->speed  = phydev->speed;
        }
 
        if (phydev->link != pp->link) {
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 11/19
#30 lore raw

Re: [PATCH u-boot-marvell 11/19] net: mvneta: Use bool instead of int for boolean variable

In reply to Marek Behún
Quoted 33 lines · Marek Behún

From: Marek Behún <[email protected]>

Use the bool type instead of int for status_change variable.

---
 drivers/net/mvneta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +2 -3
index 66d5e10174..7d582c1206 100644
@@ -1154,7 +1154,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 {
        struct mvneta_port *pp = dev_get_priv(dev);
        struct phy_device *phydev = pp->phydev;
-       int status_change = 0;
+       bool status_change = false;
 
        if (pp->fixed_link) {
                debug("Using fixed link, skip link adjust\n");
@@ -1193,7 +1193,7 @@ static void mvneta_adjust_link(struct udevice *dev)
                }
 
                pp->link = phydev->link;
-               status_change = 1;
+               status_change = true;
        }
 
        if (status_change) {
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 12/19
#33 lore raw

Re: [PATCH u-boot-marvell 12/19] net: mvneta: Drop unnecessary space

In reply to Marek Behún
Quoted 24 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop unnecessary space in mvneta_adjust_link().

---
 drivers/net/mvneta.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvneta.c +1 -2
index 7d582c1206..5c3f7125b5 100644
@@ -1183,7 +1183,7 @@ static void mvneta_adjust_link(struct udevice *dev)
                mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 
                pp->duplex = phydev->duplex;
-               pp->speed  = phydev->speed;
+               pp->speed = phydev->speed;
        }
 
        if (phydev->link != pp->link) {
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 13/19
#36 lore raw

Re: [PATCH u-boot-marvell 13/19] net: mvneta: Don't check for CONFIG_PHYLIB

In reply to Marek Behún
Quoted 27 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop checking for CONFIG_PHYLIB in mvneta, this is already done in Kconfig.

---
 drivers/net/mvneta.c | 4 ----
 1 file changed, 4 deletions(-)
drivers/net/mvneta.c +0 -5
index 5c3f7125b5..0ec9d2957c 100644
@@ -40,10 +40,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#if !defined(CONFIG_PHYLIB)
-# error Marvell mvneta requires PHYLIB
-#endif
-
 #define CONFIG_NR_CPUS         1
 #define ETH_HLEN               14      /* Total octets in header */
 
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 14/19
#39 lore raw

Re: [PATCH u-boot-marvell 14/19] net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS

In reply to Marek Behún
Quoted 34 lines · Marek Behún

From: Marek Behún <[email protected]>

The CONFIG_* macros are reserved for Kconfig. This was probably done when this driver was being imported from Linux. Rename the macro.

---
 drivers/net/mvneta.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +2 -3
index 0ec9d2957c..519e06ff01 100644
@@ -40,7 +40,7 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-#define CONFIG_NR_CPUS         1
+#define MVNETA_NR_CPUS         1
 #define ETH_HLEN               14      /* Total octets in header */
 
 /* 2(HW hdr) 14(MAC hdr) 4(CRC) 32(extra for cache prefetch) */
@@ -770,7 +770,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
        /* Set CPU queue access map - all CPUs have access to all RX
         * queues and to all TX queues
         */
-       for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++)
+       for (cpu = 0; cpu < MVNETA_NR_CPUS; cpu++)
                mvreg_write(pp, MVNETA_CPU_MAP(cpu),
                            (MVNETA_CPU_RXQ_ACCESS_ALL_MASK |
                             MVNETA_CPU_TXQ_ACCESS_ALL_MASK));
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 15/19
#42 lore raw

Re: [PATCH u-boot-marvell 15/19] net: mvneta: Convert to use PHY_FIXED for fixed-link

In reply to Marek Behún
Quoted 185 lines · Marek Behún

From: Marek Behún <[email protected]>

Stop parsing fixed-link in the MAC driver. Instead support only PHY mode and let the fixed PHY driver handle the fixed-link case.

Enable CONFIG_PHY_FIXED for mvneta boards that need it: Turris Omnia and ESPRESSObin.

---
 configs/mvebu_espressobin-88f3720_defconfig |  1 +
 configs/turris_omnia_defconfig              |  1 +
 drivers/net/mvneta.c                        | 98 ++++++++-------------
 3 files changed, 39 insertions(+), 61 deletions(-)
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index 37e4fdc41e..8d7d57ff1b 100644
@@ -74,6 +74,7 @@ CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_WINBOND=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_MARVELL=y
+CONFIG_PHY_FIXED=y
 CONFIG_PHY_GIGE=y
 CONFIG_E1000=y
 CONFIG_MVNETA=y
configs/turris_omnia_defconfig +1 -0
index 6b218bd7a7..bdd70f2ba7 100644
@@ -79,6 +79,7 @@ CONFIG_SPI_FLASH_MACRONIX=y
 CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_MTD=y
 CONFIG_PHY_MARVELL=y
+CONFIG_PHY_FIXED=y
 CONFIG_PHY_GIGE=y
 CONFIG_MVNETA=y
 CONFIG_MII=y
drivers/net/mvneta.c +37 -62
index 519e06ff01..5b1c4fe5fc 100644
@@ -1152,11 +1152,6 @@ static void mvneta_adjust_link(struct udevice *dev)
        struct phy_device *phydev = pp->phydev;
        bool status_change = false;
 
-       if (pp->fixed_link) {
-               debug("Using fixed link, skip link adjust\n");
-               return;
-       }
-
        if (phydev->link &&
            (pp->speed != phydev->speed || pp->duplex != phydev->duplex)) {
                u32 val;
@@ -1168,6 +1163,21 @@ static void mvneta_adjust_link(struct udevice *dev)
                         MVNETA_GMAC_AN_SPEED_EN |
                         MVNETA_GMAC_AN_DUPLEX_EN);
 
+               /* FIXME: For fixed-link case, these were the initial settings
+                * used before the code was converted to use PHY_FIXED. Some of
+                * these may look nonsensical (for example BYPASS_AN makes sense
+                * for 1000base-x and 2500base-x modes, AFAIK), and in fact this
+                * may be changed in the future (when support for inband AN will
+                * be added). Also, why is ADVERT_FC enabled if we don't enable
+                * inband AN at all?
+                */
+               if (pp->fixed_link)
+                       val = MVNETA_GMAC_FORCE_LINK_UP |
+                             MVNETA_GMAC_IB_BYPASS_AN_EN |
+                             MVNETA_GMAC_SET_FC_EN |
+                             MVNETA_GMAC_ADVERT_FC_EN |
+                             MVNETA_GMAC_SAMPLE_TX_CFG_EN;
+
                if (phydev->duplex)
                        val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
 
@@ -1413,56 +1423,34 @@ static int mvneta_start(struct udevice *dev)
        mvneta_port_power_up(pp, pp->phy_interface);
 
        if (!pp->init || pp->link == 0) {
-               if (pp->fixed_link) {
-                       u32 val;
-
-                       pp->init = 1;
-                       pp->link = 1;
-                       mvneta_init(dev);
-
-                       val = MVNETA_GMAC_FORCE_LINK_UP |
-                             MVNETA_GMAC_IB_BYPASS_AN_EN |
-                             MVNETA_GMAC_SET_FC_EN |
-                             MVNETA_GMAC_ADVERT_FC_EN |
-                             MVNETA_GMAC_SAMPLE_TX_CFG_EN;
-
-                       if (pp->duplex)
-                               val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
-
-                       if (pp->speed == SPEED_1000)
-                               val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-                       else if (pp->speed == SPEED_100)
-                               val |= MVNETA_GMAC_CONFIG_MII_SPEED;
+               phydev = dm_eth_phy_connect(dev);
+               if (!phydev) {
+                       printf("dm_eth_phy_connect failed\n");
+                       return -ENODEV;
+               }
 
-                       mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
-               } else {
-                       phydev = dm_eth_phy_connect(dev);
-                       if (!phydev) {
-                               printf("dm_eth_phy_connect failed\n");
-                               return -ENODEV;
-                       }
+               pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
 
-                       /* Set PHY address in case we will enable HW polling */
+               /* Set PHY address in case we will enable HW polling */
+               if (!pp->fixed_link)
                        mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
 
-                       pp->phydev = phydev;
-                       phy_config(phydev);
-                       phy_startup(phydev);
-                       if (!phydev->link) {
-                               printf("%s: No link.\n", phydev->dev->name);
-                               return -1;
-                       }
-
-                       /* Full init on first call */
-                       mvneta_init(dev);
-                       pp->init = 1;
-                       return 0;
+               pp->phydev = phydev;
+               phy_config(phydev);
+               phy_startup(phydev);
+               if (!phydev->link) {
+                       printf("%s: No link.\n", phydev->dev->name);
+                       return -1;
                }
-       }
 
-       /* Upon all following calls, this is enough */
-       mvneta_port_up(pp);
-       mvneta_port_enable(pp);
+               /* Full init on first call */
+               mvneta_init(dev);
+               pp->init = 1;
+       } else {
+               /* Upon all following calls, this is enough */
+               mvneta_port_up(pp);
+               mvneta_port_enable(pp);
+       }
 
        return 0;
 }
@@ -1560,10 +1548,7 @@ static int mvneta_probe(struct udevice *dev)
 #if CONFIG_IS_ENABLED(DM_GPIO)
        struct ofnode_phandle_args sfp_args;
 #endif
-       void *blob = (void *)gd->fdt_blob;
-       int node = dev_of_offset(dev);
        void *bd_space;
-       int fl_node;
 
        /*
         * Allocate buffer area for descs and rx_buffers. This is only
@@ -1600,15 +1585,6 @@ static int mvneta_probe(struct udevice *dev)
        else
                mvneta_conf_mbus_windows(pp);
 
-       /* fetch 'fixed-link' property from 'neta' node */
-       fl_node = fdt_subnode_offset(blob, node, "fixed-link");
-       if (fl_node != -FDT_ERR_NOTFOUND) {
-               /* set phy_addr to invalid value for fixed link */
-               pp->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex");
-               pp->speed = fdtdec_get_int(blob, fl_node, "speed", 0);
-               pp->fixed_link = true;
-       }
-
 #if CONFIG_IS_ENABLED(DM_GPIO)
        if (!dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args) &&
            ofnode_is_enabled(sfp_args.node))
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 16/19
#45 lore raw

Re: [PATCH u-boot-marvell 16/19] net: mvneta: Write PHY address just before enabling HW polling

In reply to Marek Behún
Quoted 35 lines · Marek Behún

From: Marek Behún <[email protected]>

Write PHY address just before enabling HW polling of the PHY.

---
 drivers/net/mvneta.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/mvneta.c +2 -5
index 5b1c4fe5fc..4917857681 100644
@@ -814,6 +814,8 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 
        /* Enable PHY polling in hardware if not in fixed-link mode */
        if (!pp->fixed_link) {
+               mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
+
                val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
                val |= MVNETA_PHY_POLLING_ENABLE;
                mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
@@ -1431,10 +1433,6 @@ static int mvneta_start(struct udevice *dev)
 
                pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
 
-               /* Set PHY address in case we will enable HW polling */
-               if (!pp->fixed_link)
-                       mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
-
                pp->phydev = phydev;
                phy_config(phydev);
                phy_startup(phydev);
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 17/19
#48 lore raw

Re: [PATCH u-boot-marvell 17/19] net: mvneta: Drop fixed_link member from private struct

In reply to Marek Behún
Quoted 51 lines · Marek Behún

From: Marek Behún <[email protected]>

Since this member is checked only at two places drop it and inline it's usage.

---
 drivers/net/mvneta.c | 7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/mvneta.c +2 -6
index 4917857681..378789b632 100644
@@ -273,7 +273,6 @@ struct mvneta_port {
        u16 rx_ring_size;
 
        phy_interface_t phy_interface;
-       bool fixed_link;
        unsigned int link;
        unsigned int duplex;
        unsigned int speed;
@@ -813,7 +812,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
        mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
        /* Enable PHY polling in hardware if not in fixed-link mode */
-       if (!pp->fixed_link) {
+       if (pp->phydev->phy_id != PHY_FIXED_ID) {
                mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
 
                val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
@@ -1173,7 +1172,7 @@ static void mvneta_adjust_link(struct udevice *dev)
                 * be added). Also, why is ADVERT_FC enabled if we don't enable
                 * inband AN at all?
                 */
-               if (pp->fixed_link)
+               if (pp->phydev->phy_id == PHY_FIXED_ID)
                        val = MVNETA_GMAC_FORCE_LINK_UP |
                              MVNETA_GMAC_IB_BYPASS_AN_EN |
                              MVNETA_GMAC_SET_FC_EN |
@@ -1431,8 +1430,6 @@ static int mvneta_start(struct udevice *dev)
                        return -ENODEV;
                }
 
-               pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
-
                pp->phydev = phydev;
                phy_config(phydev);
                phy_startup(phydev);
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 18/19
#51 lore raw

Re: [PATCH u-boot-marvell 18/19] net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in

In reply to Marek Behún
Quoted 36 lines · Marek Behún

From: Marek Behún <[email protected]>

Guard the code handling the fixed PHY case by
CONFIG_IS_ENABLED(PHY_FIXED).

---
 drivers/net/mvneta.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +4 -3
index 378789b632..292c364e5e 100644
@@ -812,7 +812,8 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
        mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
        /* Enable PHY polling in hardware if not in fixed-link mode */
-       if (pp->phydev->phy_id != PHY_FIXED_ID) {
+       if (!CONFIG_IS_ENABLED(PHY_FIXED) ||
+           pp->phydev->phy_id != PHY_FIXED_ID) {
                mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
 
                val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
@@ -1172,7 +1173,8 @@ static void mvneta_adjust_link(struct udevice *dev)
                 * be added). Also, why is ADVERT_FC enabled if we don't enable
                 * inband AN at all?
                 */
-               if (pp->phydev->phy_id == PHY_FIXED_ID)
+               if (CONFIG_IS_ENABLED(PHY_FIXED) &&
+                   pp->phydev->phy_id == PHY_FIXED_ID)
                        val = MVNETA_GMAC_FORCE_LINK_UP |
                              MVNETA_GMAC_IB_BYPASS_AN_EN |
                              MVNETA_GMAC_SET_FC_EN |
--
Quoted 2 lines

2.35.1

Reviewed-by on v1 19/19
#54 lore raw

Re: [PATCH u-boot-marvell 19/19] net: mvneta: Drop unneeded macro

In reply to Marek Behún
Quoted 37 lines · Marek Behún

From: Marek Behún <[email protected]>

Macro MVNETA_GMAC_FORCE_LINK_UP can be dropped from value assignment in fixed link case, since it's value is written into the register later in the function for link-down-to-link-up case. The value is written as MVNETA_GMAC_FORCE_LINK_DOWN | MVNETA_GMAC_FORCE_LINK_PASS, and so the macro definition can also be dropped.

---
 drivers/net/mvneta.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/mvneta.c +1 -4
index 292c364e5e..d2c42c4396 100644
@@ -188,7 +188,6 @@ DECLARE_GLOBAL_DATA_PTR;
 #define MVNETA_GMAC_AUTONEG_CONFIG               0x2c0c
 #define      MVNETA_GMAC_FORCE_LINK_DOWN         BIT(0)
 #define      MVNETA_GMAC_FORCE_LINK_PASS         BIT(1)
-#define      MVNETA_GMAC_FORCE_LINK_UP           (BIT(0) | BIT(1))
 #define      MVNETA_GMAC_IB_BYPASS_AN_EN         BIT(3)
 #define      MVNETA_GMAC_CONFIG_MII_SPEED        BIT(5)
 #define      MVNETA_GMAC_CONFIG_GMII_SPEED       BIT(6)
@@ -1175,8 +1174,7 @@ static void mvneta_adjust_link(struct udevice *dev)
                 */
                if (CONFIG_IS_ENABLED(PHY_FIXED) &&
                    pp->phydev->phy_id == PHY_FIXED_ID)
-                       val = MVNETA_GMAC_FORCE_LINK_UP |
-                             MVNETA_GMAC_IB_BYPASS_AN_EN |
+                       val = MVNETA_GMAC_IB_BYPASS_AN_EN |
                              MVNETA_GMAC_SET_FC_EN |
                              MVNETA_GMAC_ADVERT_FC_EN |
                              MVNETA_GMAC_SAMPLE_TX_CFG_EN;
--
Quoted 2 lines

2.35.1

#56 lore raw
In reply to Marek Behún

Hi Ramon,

Quoted 5 lines · Marek Behún

From: Marek Behún <[email protected]>

Hello Stefan,

here come some refactors, cleanups and fixed for the mvneta driver.

Ramon, you've already reviewed those patches. Thanks for this. The patches are assigned to me in patchwork, which makes perhaps sense, as some touch the ARM related files. Are you okay with me pulling these patches via the marvell tree?

Thanks,
Stefan

Quoted 34 lines

Marek Behún (19):
net: mvneta: Get rid of platdata
net: mvneta: Fix 10Mbps speed
net: mvneta: Use DM MDIO API for connecting PHY
net: mvneta: Remember fixed link instead of PHY address in priv data
arm: mvebu: Espressobin: Use DM registered MDIO to configure switch
net: mdio-uclass: add dm_phy_find_by_ofnode() helper
arm: mvebu: turris_mox: Use DM registered MDIO
net: mvneta: Don't register MDIO bus
net: mvneta: Fix unused variable warning if DM_GPIO is disabled
net: mvneta: Drop one indentation level in mvneta_adjust_link()
net: mvneta: Use bool instead of int for boolean variable
net: mvneta: Drop unnecessary space
net: mventa: Don't check for CONFIG_PHYLIB
net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS
net: mvneta: Convert to use PHY_FIXED for fixed-link
net: mvneta: Write PHY address just before enabling HW polling
net: mvneta: Drop fixed_link member from private struct
net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in
net: mvneta: Drop unneeded macro

  .../dts/armada-3720-turris-mox-u-boot.dtsi    |  19 -
  board/CZ.NIC/turris_mox/turris_mox.c          |  88 ++---
  board/Marvell/mvebu_armada-37xx/board.c       |  26 +-
  configs/clearfog_defconfig                    |   1 +
  configs/controlcenterdc_defconfig             |   1 +
  configs/db-88f6820-amc_defconfig              |   1 +
  configs/db-88f6820-gp_defconfig               |   1 +
  configs/db-mv784mp-gp_defconfig               |   1 +
  configs/ds414_defconfig                       |   1 +
  configs/helios4_defconfig                     |   1 +
  configs/maxbcm_defconfig                      |   1 +
  configs/mvebu_espressobin-88f3720_defconfig   |   3 +
  configs/theadorable_debug_defconfig           |   1 +
Quoted 9 lines
  configs/turris_mox_defconfig                  |   1 +
  configs/turris_omnia_defconfig                |   2 +
  configs/uDPU_defconfig                        |   1 +
  drivers/net/Kconfig                           |   1 +
  drivers/net/mvneta.c                          | 343 ++++--------------
  include/miiphy.h                              |   9 +
  net/mdio-uclass.c                             |  22 ++
  20 files changed, 181 insertions(+), 343 deletions(-)

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 1/19
#3 lore raw

Re: [PATCH u-boot-marvell 01/19] net: mvneta: Get rid of platdata

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop .of_to_plat() from the mvneta driver and parse the two properties in .probe().

Thanks,
Stefan

Quoted 60 lines
---
  drivers/net/mvneta.c | 24 ++++--------------------
  1 file changed, 4 insertions(+), 20 deletions(-)
drivers/net/mvneta.c +4 -19
index 15dc714058..d1c5f7930d 100644
@@ -1692,7 +1692,6 @@ static int mvneta_recv(struct udevice *dev, int flags, uchar **packetp)
 
  static int mvneta_probe(struct udevice *dev)
  {
-	struct eth_pdata *pdata = dev_get_plat(dev);
  	struct mvneta_port *pp = dev_get_priv(dev);
  #if CONFIG_IS_ENABLED(DM_GPIO)
  	struct ofnode_phandle_args sfp_args;
@@ -1729,7 +1728,10 @@ static int mvneta_probe(struct udevice *dev)
  		buffer_loc.rx_buffers = (phys_addr_t)(bd_space + size);
  	}
 
-	pp->base = (void __iomem *)pdata->iobase;
+	pp->base = dev_read_addr_ptr(dev);
+	pp->phy_interface = dev_read_phy_mode(dev);
+	if (pp->phy_interface == PHY_INTERFACE_MODE_NA)
+		return -EINVAL;
 
  	/* Configure MBUS address windows */
  	if (device_is_compatible(dev, "marvell,armada-3700-neta"))
@@ -1737,9 +1739,6 @@ static int mvneta_probe(struct udevice *dev)
  	else
  		mvneta_conf_mbus_windows(pp);
 
-	/* PHY interface is already decoded in mvneta_of_to_plat() */
-	pp->phy_interface = pdata->phy_interface;
-
  	/* fetch 'fixed-link' property from 'neta' node */
  	fl_node = fdt_subnode_offset(blob, node, "fixed-link");
  	if (fl_node != -FDT_ERR_NOTFOUND) {
@@ -1808,20 +1807,6 @@ static const struct eth_ops mvneta_ops = {
  	.write_hwaddr	= mvneta_write_hwaddr,
  };
 
-static int mvneta_of_to_plat(struct udevice *dev)
-{
-	struct eth_pdata *pdata = dev_get_plat(dev);
-
-	pdata->iobase = dev_read_addr(dev);
-
-	/* Get phy-mode / phy_interface from DT */
-	pdata->phy_interface = dev_read_phy_mode(dev);
-	if (pdata->phy_interface == PHY_INTERFACE_MODE_NA)
-		return -EINVAL;
-
-	return 0;
-}
-
  static const struct udevice_id mvneta_ids[] = {
  	{ .compatible = "marvell,armada-370-neta" },
  	{ .compatible = "marvell,armada-xp-neta" },

drivers/net/mvneta.c U_BOOT_DRIVER(mvneta) = { · line 1823

Quoted 7 lines
drivers/net/mvneta.c +0 -1
@@ -1833,7 +1818,6 @@ U_BOOT_DRIVER(mvneta) = {
  	.name	= "mvneta",
  	.id	= UCLASS_ETH,
  	.of_match = mvneta_ids,
-	.of_to_plat = mvneta_of_to_plat,
  	.probe	= mvneta_probe,
  	.ops	= &mvneta_ops,
  	.priv_auto	= sizeof(struct mvneta_port),

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 2/19
#6 lore raw

Re: [PATCH u-boot-marvell 02/19] net: mvneta: Fix 10Mbps speed

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

In mvneta_adjust_link() we need to set MII_SPEED bit only if PHY reports the speed at 100Mbps.

Thanks,
Stefan

Quoted 9 lines
---
  drivers/net/mvneta.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvneta.c +0 -0
index d1c5f7930d..79cdb93341 100644

drivers/net/mvneta.c static void mvneta_adjust_link(struct udevice *dev) · line 1201

Quoted 8 lines
drivers/net/mvneta.c +1 -1
@@ -1195,7 +1195,7 @@ static void mvneta_adjust_link(struct udevice *dev)
 
  			if (phydev->speed == SPEED_1000)
  				val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-			else
+			else if (pp->speed == SPEED_100)
  				val |= MVNETA_GMAC_CONFIG_MII_SPEED;
 
  			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 3/19
#9 lore raw

Re: [PATCH u-boot-marvell 03/19] net: mvneta: Use DM MDIO API for connecting PHY

In reply to Marek Behún
Quoted 7 lines · Marek Behún

From: Marek Behún <[email protected]>

Use the modern DM MDIO API for connecting PHY in the mvneta driver.

This requires enabling MVMDIO driver in several config files.

Thanks,
Stefan

Quoted 202 lines
---
  configs/clearfog_defconfig                  |  1 +
  configs/controlcenterdc_defconfig           |  1 +
  configs/db-88f6820-amc_defconfig            |  1 +
  configs/db-88f6820-gp_defconfig             |  1 +
  configs/db-mv784mp-gp_defconfig             |  1 +
  configs/ds414_defconfig                     |  1 +
  configs/helios4_defconfig                   |  1 +
  configs/maxbcm_defconfig                    |  1 +
  configs/mvebu_espressobin-88f3720_defconfig |  1 +
  configs/theadorable_debug_defconfig         |  1 +
  configs/turris_mox_defconfig                |  1 +
  configs/turris_omnia_defconfig              |  1 +
  configs/uDPU_defconfig                      |  1 +
  drivers/net/Kconfig                         |  1 +
  drivers/net/mvneta.c                        | 11 +++++------
  15 files changed, 19 insertions(+), 6 deletions(-)
configs/clearfog_defconfig +1 -0
index 880f16a6e0..b8f59d2962 100644
@@ -63,6 +63,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
  CONFIG_SCSI=y
configs/controlcenterdc_defconfig +1 -0
index d4b966b93f..df38b2c54f 100644
@@ -77,6 +77,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_DM_PCI_COMPAT=y
  CONFIG_PCI_MVEBU=y
configs/db-88f6820-amc_defconfig +1 -0
index 46c822fccd..9b77b4a5f0 100644
@@ -67,6 +67,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
  CONFIG_DEBUG_UART_SHIFT=2
configs/db-88f6820-gp_defconfig +1 -0
index 2dcbc2f29a..f56d1fbf25 100644
@@ -62,6 +62,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
  CONFIG_SCSI=y
configs/db-mv784mp-gp_defconfig +1 -0
index f19cc54975..5683f11836 100644
@@ -65,6 +65,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
  CONFIG_DEBUG_UART_SHIFT=2
configs/ds414_defconfig +1 -0
index a3279c15c5..a83fe079b3 100644
@@ -65,6 +65,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
  CONFIG_DEBUG_UART_SHIFT=2
configs/helios4_defconfig +1 -0
index 7d812e8fab..c2130bacb4 100644
@@ -63,6 +63,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
  CONFIG_SCSI=y
configs/maxbcm_defconfig +1 -0
index 8dd6adf247..40f79d47ea 100644
@@ -47,6 +47,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_DEBUG_UART_SHIFT=2
  CONFIG_SYS_NS16550=y
  CONFIG_KIRKWOOD_SPI=y
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index ff05630d20..af30f1b363 100644
@@ -76,6 +76,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_E1000=y
  CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
  CONFIG_NVME_PCI=y
  CONFIG_PCI=y
  CONFIG_PCI_AARDVARK=y
configs/theadorable_debug_defconfig +1 -0
index 86129e7d2d..9a03a0a7a3 100644
@@ -70,6 +70,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_DM_PCI_COMPAT=y
  CONFIG_PCI_MVEBU=y
configs/turris_mox_defconfig +1 -0
index 9a76a118c2..bcd3699a4f 100644
@@ -82,6 +82,7 @@ CONFIG_SPI_FLASH_MTD=y
  CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
  CONFIG_NVME_PCI=y
  CONFIG_PCI=y
  CONFIG_PCI_AARDVARK=y
configs/turris_omnia_defconfig +1 -0
index ad56d3824b..6b218bd7a7 100644
@@ -82,6 +82,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
+CONFIG_MVMDIO=y
  CONFIG_NVME_PCI=y
  CONFIG_PCI=y
  CONFIG_PCI_MVEBU=y
configs/uDPU_defconfig +1 -0
index c07bad5076..f2852ad29b 100644
@@ -73,6 +73,7 @@ CONFIG_PHY_MARVELL=y
  CONFIG_PHY_GIGE=y
  CONFIG_E1000=y
  CONFIG_MVNETA=y
+CONFIG_MVMDIO=y
  CONFIG_PCI=y
  CONFIG_PCI_AARDVARK=y
  CONFIG_PHY=y
drivers/net/Kconfig +1 -0
index 347fe8aa42..47f7a262f2 100644
@@ -445,6 +445,7 @@ config MVNETA
  	bool "Marvell Armada XP/385/3700 network interface support"
  	depends on ARMADA_XP || ARMADA_38X || ARMADA_3700
  	select PHYLIB
+	select DM_MDIO
  	help
  	  This driver supports the network interface units in the
  	  Marvell ARMADA XP, ARMADA 38X and ARMADA 3700 SoCs
drivers/net/mvneta.c +1 -6
index 79cdb93341..24a491dcde 100644
@@ -1571,16 +1571,15 @@ static int mvneta_start(struct udevice *dev)
 
  			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
  		} else {
-			/* Set phy address of the port */
-			mvreg_write(pp, MVNETA_PHY_ADDR, pp->phyaddr);
-
-			phydev = phy_connect(pp->bus, pp->phyaddr, dev,
-					     pp->phy_interface);
+			phydev = dm_eth_phy_connect(dev);
  			if (!phydev) {
-				printf("phy_connect failed\n");

drivers/net/mvneta.c static int mvneta_start(struct udevice *dev) · line 1585

Quoted 10 lines
drivers/net/mvneta.c +4 -0
+				printf("dm_eth_phy_connect failed\n");
  				return -ENODEV;
  			}
 
+			/* Set PHY address in case we will enable HW polling */
+			mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
+
  			pp->phydev = phydev;
  			phy_config(phydev);
  			phy_startup(phydev);

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 4/19
#12 lore raw

Re: [PATCH u-boot-marvell 04/19] net: mvneta: Remember fixed link instead of PHY address in priv data

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

We don't need to remember PHY address anymore, because since using DM MDIO for connecting PHY, the address is parsed by mdio-uclass from the ofnode.

Quoted 7 lines

But the driver uses a special value of the address to signal fixed link usage.

Drop phyaddr add fixed_link in driver private structure. This simplifies code a little.

Thanks,
Stefan

Quoted 77 lines
---
  drivers/net/mvneta.c | 23 +++++------------------
  1 file changed, 5 insertions(+), 18 deletions(-)
drivers/net/mvneta.c +4 -13
index 24a491dcde..83e9629138 100644
@@ -277,12 +277,12 @@ struct mvneta_port {
  	u16 rx_ring_size;
 
  	phy_interface_t phy_interface;
+	bool fixed_link;
  	unsigned int link;
  	unsigned int duplex;
  	unsigned int speed;
 
  	int init;
-	int phyaddr;
  	struct phy_device *phydev;
  #if CONFIG_IS_ENABLED(DM_GPIO)
  	struct gpio_desc phy_reset_gpio;
@@ -576,13 +576,6 @@ static void mvneta_rxq_buf_size_set(struct mvneta_port *pp,
  	mvreg_write(pp, MVNETA_RXQ_SIZE_REG(rxq->id), val);
  }
 
-static int mvneta_port_is_fixed_link(struct mvneta_port *pp)
-{
-	/* phy_addr is set to invalid value for fixed link */
-	return pp->phyaddr > PHY_MAX_ADDR;
-}
-
-
  /* Start the Ethernet port RX and TX activity */
  static void mvneta_port_up(struct mvneta_port *pp)
  {
@@ -834,7 +827,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
  	mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
  	/* Enable PHY polling in hardware if not in fixed-link mode */
-	if (!mvneta_port_is_fixed_link(pp)) {
+	if (!pp->fixed_link) {
  		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
  		val |= MVNETA_PHY_POLLING_ENABLE;
  		mvreg_write(pp, MVNETA_UNIT_CONTROL, val);
@@ -1173,7 +1166,7 @@ static void mvneta_adjust_link(struct udevice *dev)
  	struct phy_device *phydev = pp->phydev;
  	int status_change = 0;
 
-	if (mvneta_port_is_fixed_link(pp)) {
+	if (pp->fixed_link) {
  		debug("Using fixed link, skip link adjust\n");
  		return;
  	}
@@ -1548,7 +1541,7 @@ static int mvneta_start(struct udevice *dev)
  	mvneta_port_power_up(pp, pp->phy_interface);
 
  	if (!pp->init || pp->link == 0) {
-		if (mvneta_port_is_fixed_link(pp)) {
+		if (pp->fixed_link) {
  			u32 val;
 
  			pp->init = 1;
@@ -1698,7 +1691,6 @@ static int mvneta_probe(struct udevice *dev)
  	void *blob = (void *)gd->fdt_blob;
  	int node = dev_of_offset(dev);
  	struct mii_dev *bus;
-	unsigned long addr;
  	void *bd_space;
  	int ret;
  	int fl_node;
@@ -1742,14 +1734,9 @@ static int mvneta_probe(struct udevice *dev)
  	fl_node = fdt_subnode_offset(blob, node, "fixed-link");
  	if (fl_node != -FDT_ERR_NOTFOUND) {
  		/* set phy_addr to invalid value for fixed link */
-		pp->phyaddr = PHY_MAX_ADDR + 1;
  		pp->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex");

drivers/net/mvneta.c static int mvneta_probe(struct udevice *dev) · line 1742

Quoted 10 lines
drivers/net/mvneta.c +1 -5
  		pp->speed = fdtdec_get_int(blob, fl_node, "speed", 0);
-	} else {
-		/* Now read phyaddr from DT */
-		addr = fdtdec_get_int(blob, node, "phy", 0);
-		addr = fdt_node_offset_by_phandle(blob, addr);
-		pp->phyaddr = fdtdec_get_int(blob, addr, "reg", 0);
+		pp->fixed_link = true;
  	}
 
  	bus = mdio_alloc();

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 5/19
#14 lore raw

Re: [PATCH u-boot-marvell 05/19] arm: mvebu: Espressobin: Use DM registered MDIO to configure switch

In reply to Marek Behún
Quoted 8 lines · Marek Behún

From: Marek Behún <[email protected]>

In order to be able to get rid of the non-DM MDIO bus registered in mvneta driver, we need to stop using board_network_enable() and instead use the DM registered MDIO device to configure switch in last_stage_init().

Thanks,
Stefan

Quoted 84 lines
---
  board/Marvell/mvebu_armada-37xx/board.c     | 26 ++++++++++++++++-----
  configs/mvebu_espressobin-88f3720_defconfig |  1 +
  2 files changed, 21 insertions(+), 6 deletions(-)
board/Marvell/mvebu_armada-37xx/board.c +20 -6
index 98e1b36d11..3e5e0a0b5c 100644
@@ -11,6 +11,7 @@
  #include <i2c.h>
  #include <init.h>
  #include <mmc.h>
+#include <miiphy.h>
  #include <phy.h>
  #include <asm/global_data.h>
  #include <asm/io.h>
@@ -254,14 +255,15 @@ int board_xhci_enable(fdt_addr_t base)
  	return 0;
  }
 
+#ifdef CONFIG_LAST_STAGE_INIT
  /* Helper function for accessing switch devices in multi-chip connection mode */
-static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
+static int mii_multi_chip_mode_write(struct udevice *bus, int dev_smi_addr,
  				     int smi_addr, int reg, u16 value)
  {
  	u16 smi_cmd = 0;
 
-	if (bus->write(bus, dev_smi_addr, 0,
-		       MVEBU_SW_SMI_DATA_REG, value) != 0) {
+	if (dm_mdio_write(bus, dev_smi_addr, MDIO_DEVAD_NONE,
+			  MVEBU_SW_SMI_DATA_REG, value) != 0) {
  		printf("Error writing to the PHY addr=%02x reg=%02x\n",
  		       smi_addr, reg);
  		return -EFAULT;
@@ -272,8 +274,8 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
  		  (1 << SW_SMI_CMD_SMI_OP_OFF) |
  		  (smi_addr << SW_SMI_CMD_DEV_ADDR_OFF) |
  		  (reg << SW_SMI_CMD_REG_ADDR_OFF);
-	if (bus->write(bus, dev_smi_addr, 0,
-		       MVEBU_SW_SMI_CMD_REG, smi_cmd) != 0) {
+	if (dm_mdio_write(bus, dev_smi_addr, MDIO_DEVAD_NONE,
+			  MVEBU_SW_SMI_CMD_REG, smi_cmd) != 0) {
  		printf("Error writing to the PHY addr=%02x reg=%02x\n",
  		       smi_addr, reg);
  		return -EFAULT;
@@ -283,11 +285,22 @@ static int mii_multi_chip_mode_write(struct mii_dev *bus, int dev_smi_addr,
  }
 
  /* Bring-up board-specific network stuff */
-int board_network_enable(struct mii_dev *bus)
+int last_stage_init(void)
  {
+	struct udevice *bus;
+	ofnode node;
+
  	if (!of_machine_is_compatible("globalscale,espressobin"))
  		return 0;
 
+	node = ofnode_by_compatible(ofnode_null(), "marvell,orion-mdio");
+	if (!ofnode_valid(node) ||
+	    uclass_get_device_by_ofnode(UCLASS_MDIO, node, &bus) ||
+	    device_probe(bus)) {
+		printf("Cannot find MDIO bus\n");
+		return 0;
+	}
+
  	/*
  	 * FIXME: remove this code once Topaz driver gets available
  	 * A3720 Community Board Only
@@ -327,6 +340,7 @@ int board_network_enable(struct mii_dev *bus)
 
  	return 0;
  }
+#endif
 
  #ifdef CONFIG_OF_BOARD_SETUP
  int ft_board_setup(void *blob, struct bd_info *bd)
configs/mvebu_espressobin-88f3720_defconfig +0 -0
index af30f1b363..37e4fdc41e 100644

configs/mvebu_espressobin-88f3720_defconfig CONFIG_DISPLAY_BOARDINFO_LATE=y · line 31

Quoted 7 lines
configs/mvebu_espressobin-88f3720_defconfig +1 -0
@@ -25,6 +25,7 @@ CONFIG_DISPLAY_BOARDINFO_LATE=y
  CONFIG_ARCH_EARLY_INIT_R=y
  CONFIG_BOARD_EARLY_INIT_F=y
  CONFIG_BOARD_LATE_INIT=y
+CONFIG_LAST_STAGE_INIT=y
  # CONFIG_CMD_FLASH is not set
  CONFIG_CMD_FUSE=y
  CONFIG_CMD_GPIO=y

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 7/19
#19 lore raw

Re: [PATCH u-boot-marvell 07/19] arm: mvebu: turris_mox: Use DM registered MDIO

In reply to Marek Behún
Quoted 10 lines · Marek Behún

From: Marek Behún <[email protected]>

In order to be able to get rid of the non-DM MDIO bus registered in mvneta driver, start using the DM registered one in Turris MOX board code.

This also allows us to drop the hack introduced in MOX' -u-boot.dtsi file.

Thanks,
Stefan

Quoted 185 lines
---
  .../dts/armada-3720-turris-mox-u-boot.dtsi    | 19 ----
  board/CZ.NIC/turris_mox/turris_mox.c          | 88 +++++++++----------
  2 files changed, 44 insertions(+), 63 deletions(-)
arch/arm/dts/armada-3720-turris-mox-u-boot.dtsi +0 -19
index 28a36a6103..71d5e70ca4 100644
@@ -3,25 +3,6 @@
   * 2022 by Marek Behún <[email protected]>
   */
 
-/ {
-	mdio {
-		#address-cells = <1>;
-		#size-cells = <0>;
-
-		old_binding_phy1: ethernet-phy@1 {
-			reg = <1>;
-		};
-	};
-};
-
-&eth0 {
-	pinctrl-0 = <&rgmii_pins>, <&smi_pins>;
-	/delete-property/ phy-handle;
-	phy = <&old_binding_phy1>;
-};
-
-/delete-node/ &mdio;
-
  &usb3 {
  	vbus-supply = <&exp_usb3_vbus>;
  };
board/CZ.NIC/turris_mox/turris_mox.c +43 -38
index 9702d1fc78..a4738b3a3c 100644
@@ -13,6 +13,7 @@
  #include <button.h>
  #include <clk.h>
  #include <dm.h>
+#include <dm/of_extra.h>
  #include <env.h>
  #include <fdt_support.h>
  #include <init.h>
@@ -216,35 +217,35 @@ static int mox_get_topology(const u8 **ptopology, int *psize, int *pis_sd)
  #define SW_SMI_CMD_R(d, r)	(0x9800 | (((d) & 0x1f) << 5) | ((r) & 0x1f))
  #define SW_SMI_CMD_W(d, r)	(0x9400 | (((d) & 0x1f) << 5) | ((r) & 0x1f))
 
-static int sw_multi_read(struct mii_dev *bus, int sw, int dev, int reg)
+static int sw_multi_read(struct udevice *bus, int sw, int dev, int reg)
  {
-	bus->write(bus, sw, 0, 0, SW_SMI_CMD_R(dev, reg));
+	dm_mdio_write(bus, sw, MDIO_DEVAD_NONE, 0, SW_SMI_CMD_R(dev, reg));
  	mdelay(5);
-	return bus->read(bus, sw, 0, 1);
+	return dm_mdio_read(bus, sw, MDIO_DEVAD_NONE, 1);
  }
 
-static void sw_multi_write(struct mii_dev *bus, int sw, int dev, int reg,
+static void sw_multi_write(struct udevice *bus, int sw, int dev, int reg,
  			   u16 val)
  {
-	bus->write(bus, sw, 0, 1, val);
-	bus->write(bus, sw, 0, 0, SW_SMI_CMD_W(dev, reg));
+	dm_mdio_write(bus, sw, MDIO_DEVAD_NONE, 1, val);
+	dm_mdio_write(bus, sw, MDIO_DEVAD_NONE, 0, SW_SMI_CMD_W(dev, reg));
  	mdelay(5);
  }
 
-static int sw_scratch_read(struct mii_dev *bus, int sw, int reg)
+static int sw_scratch_read(struct udevice *bus, int sw, int reg)
  {
  	sw_multi_write(bus, sw, 0x1c, 0x1a, (reg & 0x7f) << 8);
  	return sw_multi_read(bus, sw, 0x1c, 0x1a) & 0xff;
  }
 
-static void sw_led_write(struct mii_dev *bus, int sw, int port, int reg,
+static void sw_led_write(struct udevice *bus, int sw, int port, int reg,
  			 u16 val)
  {
  	sw_multi_write(bus, sw, port, 0x16, 0x8000 | ((reg & 7) << 12)
  					    | (val & 0x7ff));
  }
 
-static void sw_blink_leds(struct mii_dev *bus, int peridot, int topaz)
+static void sw_blink_leds(struct udevice *bus, int peridot, int topaz)
  {
  	int i, p;
  	struct {
@@ -275,7 +276,7 @@ static void sw_blink_leds(struct mii_dev *bus, int peridot, int topaz)
  	}
  }
 
-static void check_switch_address(struct mii_dev *bus, int addr)
+static void check_switch_address(struct udevice *bus, int addr)
  {
  	if (sw_scratch_read(bus, addr, 0x70) >> 3 != addr)
  		printf("Check of switch MDIO address failed for 0x%02x\n",
@@ -374,36 +375,22 @@ static void mox_phy_modify(struct phy_device *phydev, int page, int reg,
  static void mox_phy_leds_start_blinking(void)
  {
  	struct phy_device *phydev;
-	struct mii_dev *bus;
-	const char *node_name;
-	int node;
+	ofnode phy_node;
 
-	node = fdt_path_offset(gd->fdt_blob, "ethernet0");
-	if (node < 0) {
-		printf("Cannot get eth0!\n");
-		return;
-	}
+	phy_node = ofnode_get_phy_node(ofnode_path("ethernet0"));
+	if (!ofnode_valid(phy_node))
+		goto err;
 
-	node_name = fdt_get_name(gd->fdt_blob, node, NULL);
-	if (!node_name) {
-		printf("Cannot get eth0 node name!\n");
-		return;
-	}
-
-	bus = miiphy_get_dev_by_name(node_name);
-	if (!bus) {
-		printf("Cannot get MDIO bus device!\n");
-		return;
-	}
-
-	phydev = phy_find_by_mask(bus, BIT(1));
-	if (!phydev) {
-		printf("Cannot get ethernet PHY!\n");
-		return;
-	}
+	phydev = dm_phy_find_by_ofnode(phy_node);
+	if (!phydev)
+		goto err;
 
  	mox_phy_modify(phydev, 3, 0x12, 0x700, 0x400);
  	mox_phy_modify(phydev, 3, 0x10, 0xff, 0xbb);
+
+	return;
+err:
+	printf("Cannot get ethernet PHY!\n");
  }
 
  static bool read_reset_button(void)
@@ -611,6 +598,26 @@ int show_board_info(void)
  	return 0;
  }
 
+static struct udevice *mox_mdio_bus(void)
+{
+	struct udevice *bus;
+	ofnode node;
+
+	node = ofnode_by_compatible(ofnode_null(), "marvell,orion-mdio");
+	if (!ofnode_valid(node))
+		goto err;
+
+	dm_mdio_probe_devices();
+
+	if (uclass_get_device_by_ofnode(UCLASS_MDIO, node, &bus))
+		goto err;
+
+	return bus;
+err:
+	printf("Cannot get MDIO bus device!\n");
+	return NULL;
+}
+
  int last_stage_init(void)
  {
  	struct gpio_desc reset_gpio = {};
@@ -636,16 +643,9 @@ int last_stage_init(void)
  	 * 0x70 of Peridot (and potentially Topaz) modules
  	 */
  	if (peridot || topaz) {
-		struct mii_dev *bus;
-		const char *node_name;
-		int node;
+		struct udevice *bus = mox_mdio_bus();
 

board/CZ.NIC/turris_mox/turris_mox.c int last_stage_init(void) · line 651

Quoted 10 lines
board/CZ.NIC/turris_mox/turris_mox.c +1 -6
-		node = fdt_path_offset(gd->fdt_blob, "ethernet0");
-		node_name = (node >= 0) ? fdt_get_name(gd->fdt_blob, node, NULL) : NULL;
-		bus = node_name ? miiphy_get_dev_by_name(node_name) : NULL;
-		if (!bus) {
-			printf("Cannot get MDIO bus device!\n");
-		} else {
+		if (bus) {
  			int i;
 
  			for (i = 0; i < peridot; ++i)

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 6/19
#17 lore raw

Re: [PATCH u-boot-marvell 06/19] net: mdio-uclass: add dm_phy_find_by_ofnode() helper

In reply to Marek Behún
Quoted 5 lines · Marek Behún

From: Marek Behún <[email protected]>

Add helper to resolve PHY node from it's ofnode via DM MDIO subsystem.

Thanks,
Stefan

Quoted 48 lines
---
  include/miiphy.h  |  9 +++++++++
  net/mdio-uclass.c | 22 ++++++++++++++++++++++
  2 files changed, 31 insertions(+)
include/miiphy.h +9 -0
index 110921f20d..c66a1845b5 100644
@@ -188,6 +188,15 @@ int dm_mdio_write(struct udevice *mdio_dev, int addr, int devad, int reg, u16 va
   */
  int dm_mdio_reset(struct udevice *mdio_dev);
 
+/**
+ * dm_phy_find_by_ofnode - Find PHY device by ofnode
+ *
+ * @phynode: PHY's ofnode
+ *
+ * Return: pointer to phy_device, or NULL on error
+ */
+struct phy_device *dm_phy_find_by_ofnode(ofnode phynode);
+
  /**
   * dm_mdio_phy_connect - Wrapper over phy_connect for DM MDIO
   *
net/mdio-uclass.c +15 -0
index 7593618d9a..4401492ca0 100644
@@ -129,6 +129,28 @@ static int dm_mdio_pre_remove(struct udevice *dev)
  	return 0;
  }
 
+struct phy_device *dm_phy_find_by_ofnode(ofnode phynode)
+{
+	struct mdio_perdev_priv *pdata;
+	struct udevice *mdiodev;
+	u32 phy_addr;
+
+	if (ofnode_read_u32(phynode, "reg", &phy_addr))
+		return NULL;
+
+	if (uclass_get_device_by_ofnode(UCLASS_MDIO,
+					ofnode_get_parent(phynode),
+					&mdiodev))
+		return NULL;
+
+	if (device_probe(mdiodev))

net/mdio-uclass.c static int dm_mdio_pre_remove(struct udevice *dev) · line 156

Quoted 10 lines
net/mdio-uclass.c +7 -0
+		return NULL;
+
+	pdata = dev_get_uclass_priv(mdiodev);
+
+	return phy_find_by_mask(pdata->mii_bus, BIT(phy_addr));
+}
+
  struct phy_device *dm_mdio_phy_connect(struct udevice *mdiodev, int phyaddr,
  				       struct udevice *ethdev,
  				       phy_interface_t interface)

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 8/19
#22 lore raw

Re: [PATCH u-boot-marvell 08/19] net: mvneta: Don't register MDIO bus

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

This MDIO bus is now handled by a proper mvmdio DM driver. Remove it from mvneta.

Thanks,
Stefan

Quoted 187 lines
---
  drivers/net/mvneta.c | 143 +------------------------------------------
  1 file changed, 2 insertions(+), 141 deletions(-)
drivers/net/mvneta.c +1 -140
index 83e9629138..19f8145fc0 100644
@@ -288,7 +288,6 @@ struct mvneta_port {
  	struct gpio_desc phy_reset_gpio;
  	struct gpio_desc sfp_tx_disable_gpio;
  #endif
-	struct mii_dev *bus;
  };
 
  /* The mvneta_tx_desc and mvneta_rx_desc structures describe the
@@ -414,15 +413,6 @@ static struct buffer_location buffer_loc;
   */
  #define BD_SPACE	(1 << 20)
 
-/*
- * Dummy implementation that can be overwritten by a board
- * specific function
- */
-__weak int board_network_enable(struct mii_dev *bus)
-{
-	return 0;
-}
-
  /* Utility/helper methods */
 
  /* Write helper method */
@@ -1421,118 +1411,6 @@ static int mvneta_init(struct udevice *dev)
 
  /* U-Boot only functions follow here */
 
-/* SMI / MDIO functions */
-
-static int smi_wait_ready(struct mvneta_port *pp)
-{
-	u32 timeout = MVNETA_SMI_TIMEOUT;
-	u32 smi_reg;
-
-	/* wait till the SMI is not busy */
-	do {
-		/* read smi register */
-		smi_reg = mvreg_read(pp, MVNETA_SMI);
-		if (timeout-- == 0) {
-			printf("Error: SMI busy timeout\n");
-			return -EFAULT;
-		}
-	} while (smi_reg & MVNETA_SMI_BUSY);
-
-	return 0;
-}
-
-/*
- * mvneta_mdio_read - miiphy_read callback function.
- *
- * Returns 16bit phy register value, or 0xffff on error
- */
-static int mvneta_mdio_read(struct mii_dev *bus, int addr, int devad, int reg)
-{
-	struct mvneta_port *pp = bus->priv;
-	u32 smi_reg;
-	u32 timeout;
-
-	/* check parameters */
-	if (addr > MVNETA_PHY_ADDR_MASK) {
-		printf("Error: Invalid PHY address %d\n", addr);
-		return -EFAULT;
-	}
-
-	if (reg > MVNETA_PHY_REG_MASK) {
-		printf("Err: Invalid register offset %d\n", reg);
-		return -EFAULT;
-	}
-
-	/* wait till the SMI is not busy */
-	if (smi_wait_ready(pp) < 0)
-		return -EFAULT;
-
-	/* fill the phy address and regiser offset and read opcode */
-	smi_reg = (addr << MVNETA_SMI_DEV_ADDR_OFFS)
-		| (reg << MVNETA_SMI_REG_ADDR_OFFS)
-		| MVNETA_SMI_OPCODE_READ;
-
-	/* write the smi register */
-	mvreg_write(pp, MVNETA_SMI, smi_reg);
-
-	/* wait till read value is ready */
-	timeout = MVNETA_SMI_TIMEOUT;
-
-	do {
-		/* read smi register */
-		smi_reg = mvreg_read(pp, MVNETA_SMI);
-		if (timeout-- == 0) {
-			printf("Err: SMI read ready timeout\n");
-			return -EFAULT;
-		}
-	} while (!(smi_reg & MVNETA_SMI_READ_VALID));
-
-	/* Wait for the data to update in the SMI register */
-	for (timeout = 0; timeout < MVNETA_SMI_TIMEOUT; timeout++)
-		;
-
-	return mvreg_read(pp, MVNETA_SMI) & MVNETA_SMI_DATA_MASK;
-}
-
-/*
- * mvneta_mdio_write - miiphy_write callback function.
- *
- * Returns 0 if write succeed, -EINVAL on bad parameters
- * -ETIME on timeout
- */
-static int mvneta_mdio_write(struct mii_dev *bus, int addr, int devad, int reg,
-			     u16 value)
-{
-	struct mvneta_port *pp = bus->priv;
-	u32 smi_reg;
-
-	/* check parameters */
-	if (addr > MVNETA_PHY_ADDR_MASK) {
-		printf("Error: Invalid PHY address %d\n", addr);
-		return -EFAULT;
-	}
-
-	if (reg > MVNETA_PHY_REG_MASK) {
-		printf("Err: Invalid register offset %d\n", reg);
-		return -EFAULT;
-	}
-
-	/* wait till the SMI is not busy */
-	if (smi_wait_ready(pp) < 0)
-		return -EFAULT;
-
-	/* fill the phy addr and reg offset and write opcode and data */
-	smi_reg = value << MVNETA_SMI_DATA_OFFS;
-	smi_reg |= (addr << MVNETA_SMI_DEV_ADDR_OFFS)
-		| (reg << MVNETA_SMI_REG_ADDR_OFFS);
-	smi_reg &= ~MVNETA_SMI_OPCODE_READ;
-
-	/* write the smi register */
-	mvreg_write(pp, MVNETA_SMI, smi_reg);
-
-	return 0;
-}
-
  static int mvneta_start(struct udevice *dev)
  {
  	struct mvneta_port *pp = dev_get_priv(dev);
@@ -1690,10 +1568,9 @@ static int mvneta_probe(struct udevice *dev)
  #endif
  	void *blob = (void *)gd->fdt_blob;
  	int node = dev_of_offset(dev);
-	struct mii_dev *bus;
  	void *bd_space;
-	int ret;
  	int fl_node;
+	int ret;
 
  	/*
  	 * Allocate buffer area for descs and rx_buffers. This is only
@@ -1739,22 +1616,6 @@ static int mvneta_probe(struct udevice *dev)
  		pp->fixed_link = true;
  	}
 
-	bus = mdio_alloc();
-	if (!bus) {
-		printf("Failed to allocate MDIO bus\n");
-		return -ENOMEM;
-	}
-
-	bus->read = mvneta_mdio_read;
-	bus->write = mvneta_mdio_write;
-	snprintf(bus->name, sizeof(bus->name), dev->name);
-	bus->priv = (void *)pp;
-	pp->bus = bus;
-
-	ret = mdio_register(bus);
-	if (ret)
-		return ret;
-
  #if CONFIG_IS_ENABLED(DM_GPIO)
  	ret = dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args);
  	if (!ret && ofnode_is_enabled(sfp_args.node))

drivers/net/mvneta.c static int mvneta_probe(struct udevice *dev) · line 1641

Quoted 8 lines
drivers/net/mvneta.c +1 -1
@@ -1774,7 +1635,7 @@ static int mvneta_probe(struct udevice *dev)
  		dm_gpio_set_value(&pp->sfp_tx_disable_gpio, 0);
  #endif
 
-	return board_network_enable(bus);
+	return 0;
  }
 
  static void mvneta_stop(struct udevice *dev)

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 9/19
#25 lore raw

Re: [PATCH u-boot-marvell 09/19] net: mvneta: Fix unused variable warning if DM_GPIO is disabled

In reply to Marek Behún
Quoted 8 lines · Marek Behún

From: Marek Behún <[email protected]>

The ret variable in mvneta_probe() is unused if DM_GPIO is disabled.

Since the variable is used only once after assigning value, we can inline the usage and drop the variable.

Thanks,
Stefan

Quoted 17 lines
---
  drivers/net/mvneta.c | 5 ++---
  1 file changed, 2 insertions(+), 3 deletions(-)
drivers/net/mvneta.c +0 -1
index 19f8145fc0..72789fc5c6 100644
@@ -1570,7 +1570,6 @@ static int mvneta_probe(struct udevice *dev)
  	int node = dev_of_offset(dev);
  	void *bd_space;
  	int fl_node;
-	int ret;
 
  	/*
  	 * Allocate buffer area for descs and rx_buffers. This is only

drivers/net/mvneta.c static int mvneta_probe(struct udevice *dev) · line 1623

Quoted 10 lines
drivers/net/mvneta.c +2 -2
@@ -1617,8 +1616,8 @@ static int mvneta_probe(struct udevice *dev)
  	}
 
  #if CONFIG_IS_ENABLED(DM_GPIO)
-	ret = dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args);
-	if (!ret && ofnode_is_enabled(sfp_args.node))
+	if (!dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args) &&
+	    ofnode_is_enabled(sfp_args.node))
  		gpio_request_by_name_nodev(sfp_args.node, "tx-disable-gpio", 0,
  					   &pp->sfp_tx_disable_gpio, GPIOD_IS_OUT);
 

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 10/19
#28 lore raw

Re: [PATCH u-boot-marvell 10/19] net: mvneta: Drop one indentation level in mvneta_adjust_link()

In reply to Marek Behún
Quoted 5 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop one indentation level in the mvneta_adjust_link() function.

Thanks,
Stefan

Quoted 48 lines
---
  drivers/net/mvneta.c | 38 ++++++++++++++++++--------------------
  1 file changed, 18 insertions(+), 20 deletions(-)
drivers/net/mvneta.c +15 -17
index 72789fc5c6..66d5e10174 100644
@@ -1161,31 +1161,29 @@ static void mvneta_adjust_link(struct udevice *dev)
  		return;
  	}
 
-	if (phydev->link) {
-		if ((pp->speed != phydev->speed) ||
-		    (pp->duplex != phydev->duplex)) {
-			u32 val;
+	if (phydev->link &&
+	    (pp->speed != phydev->speed || pp->duplex != phydev->duplex)) {
+		u32 val;
 
-			val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
-			val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
-				 MVNETA_GMAC_CONFIG_GMII_SPEED |
-				 MVNETA_GMAC_CONFIG_FULL_DUPLEX |
-				 MVNETA_GMAC_AN_SPEED_EN |
-				 MVNETA_GMAC_AN_DUPLEX_EN);
+		val = mvreg_read(pp, MVNETA_GMAC_AUTONEG_CONFIG);
+		val &= ~(MVNETA_GMAC_CONFIG_MII_SPEED |
+			 MVNETA_GMAC_CONFIG_GMII_SPEED |
+			 MVNETA_GMAC_CONFIG_FULL_DUPLEX |
+			 MVNETA_GMAC_AN_SPEED_EN |
+			 MVNETA_GMAC_AN_DUPLEX_EN);
 
-			if (phydev->duplex)
-				val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
+		if (phydev->duplex)
+			val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
 
-			if (phydev->speed == SPEED_1000)
-				val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-			else if (pp->speed == SPEED_100)
-				val |= MVNETA_GMAC_CONFIG_MII_SPEED;
+		if (phydev->speed == SPEED_1000)
+			val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
+		else if (pp->speed == SPEED_100)
+			val |= MVNETA_GMAC_CONFIG_MII_SPEED;
 
-			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);

drivers/net/mvneta.c static void mvneta_adjust_link(struct udevice *dev) · line 1189

Quoted 10 lines
drivers/net/mvneta.c +3 -3
+		mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 
-			pp->duplex = phydev->duplex;
-			pp->speed  = phydev->speed;
-		}
+		pp->duplex = phydev->duplex;
+		pp->speed  = phydev->speed;
  	}
 
  	if (phydev->link != pp->link) {

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 11/19
#31 lore raw

Re: [PATCH u-boot-marvell 11/19] net: mvneta: Use bool instead of int for boolean variable

In reply to Marek Behún
Quoted 5 lines · Marek Behún

From: Marek Behún <[email protected]>

Use the bool type instead of int for status_change variable.

Thanks,
Stefan

Quoted 18 lines
---
  drivers/net/mvneta.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +1 -1
index 66d5e10174..7d582c1206 100644
@@ -1154,7 +1154,7 @@ static void mvneta_adjust_link(struct udevice *dev)
  {
  	struct mvneta_port *pp = dev_get_priv(dev);
  	struct phy_device *phydev = pp->phydev;
-	int status_change = 0;
+	bool status_change = false;
 
  	if (pp->fixed_link) {
  		debug("Using fixed link, skip link adjust\n");

drivers/net/mvneta.c static void mvneta_adjust_link(struct udevice *dev) · line 1199

Quoted 8 lines
drivers/net/mvneta.c +1 -1
@@ -1193,7 +1193,7 @@ static void mvneta_adjust_link(struct udevice *dev)
  		}
 
  		pp->link = phydev->link;
-		status_change = 1;
+		status_change = true;
  	}
 
  	if (status_change) {

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 12/19
#34 lore raw

Re: [PATCH u-boot-marvell 12/19] net: mvneta: Drop unnecessary space

In reply to Marek Behún
Quoted 5 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop unnecessary space in mvneta_adjust_link().

Thanks,
Stefan

Quoted 9 lines
---
  drivers/net/mvneta.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/mvneta.c +0 -0
index 7d582c1206..5c3f7125b5 100644

drivers/net/mvneta.c static void mvneta_adjust_link(struct udevice *dev) · line 1189

Quoted 8 lines
drivers/net/mvneta.c +1 -1
@@ -1183,7 +1183,7 @@ static void mvneta_adjust_link(struct udevice *dev)
  		mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
 
  		pp->duplex = phydev->duplex;
-		pp->speed  = phydev->speed;
+		pp->speed = phydev->speed;
  	}
 
  	if (phydev->link != pp->link) {

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 14/19
#40 lore raw

Re: [PATCH u-boot-marvell 14/19] net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

The CONFIG_* macros are reserved for Kconfig. This was probably done when this driver was being imported from Linux. Rename the macro.

Thanks,
Stefan

Quoted 18 lines
---
  drivers/net/mvneta.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +1 -1
index 0ec9d2957c..519e06ff01 100644
@@ -40,7 +40,7 @@
 
  DECLARE_GLOBAL_DATA_PTR;
 
-#define CONFIG_NR_CPUS		1
+#define MVNETA_NR_CPUS		1
  #define ETH_HLEN		14	/* Total octets in header */
 
  /* 2(HW hdr) 14(MAC hdr) 4(CRC) 32(extra for cache prefetch) */

drivers/net/mvneta.c static void mvneta_defaults_set(struct mvneta_port *pp) · line 776

Quoted 8 lines
drivers/net/mvneta.c +1 -1
@@ -770,7 +770,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
  	/* Set CPU queue access map - all CPUs have access to all RX
  	 * queues and to all TX queues
  	 */
-	for (cpu = 0; cpu < CONFIG_NR_CPUS; cpu++)
+	for (cpu = 0; cpu < MVNETA_NR_CPUS; cpu++)
  		mvreg_write(pp, MVNETA_CPU_MAP(cpu),
  			    (MVNETA_CPU_RXQ_ACCESS_ALL_MASK |
  			     MVNETA_CPU_TXQ_ACCESS_ALL_MASK));

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 15/19
#43 lore raw

Re: [PATCH u-boot-marvell 15/19] net: mvneta: Convert to use PHY_FIXED for fixed-link

In reply to Marek Behún
Quoted 9 lines · Marek Behún

From: Marek Behún <[email protected]>

Stop parsing fixed-link in the MAC driver. Instead support only PHY mode and let the fixed PHY driver handle the fixed-link case.

Enable CONFIG_PHY_FIXED for mvneta boards that need it: Turris Omnia and ESPRESSObin.

Thanks,
Stefan

Quoted 164 lines
---
  configs/mvebu_espressobin-88f3720_defconfig |  1 +
  configs/turris_omnia_defconfig              |  1 +
  drivers/net/mvneta.c                        | 98 ++++++++-------------
  3 files changed, 39 insertions(+), 61 deletions(-)
configs/mvebu_espressobin-88f3720_defconfig +1 -0
index 37e4fdc41e..8d7d57ff1b 100644
@@ -74,6 +74,7 @@ CONFIG_SPI_FLASH_STMICRO=y
  CONFIG_SPI_FLASH_WINBOND=y
  CONFIG_SPI_FLASH_MTD=y
  CONFIG_PHY_MARVELL=y
+CONFIG_PHY_FIXED=y
  CONFIG_PHY_GIGE=y
  CONFIG_E1000=y
  CONFIG_MVNETA=y
configs/turris_omnia_defconfig +1 -0
index 6b218bd7a7..bdd70f2ba7 100644
@@ -79,6 +79,7 @@ CONFIG_SPI_FLASH_MACRONIX=y
  CONFIG_SPI_FLASH_SPANSION=y
  CONFIG_SPI_FLASH_MTD=y
  CONFIG_PHY_MARVELL=y
+CONFIG_PHY_FIXED=y
  CONFIG_PHY_GIGE=y
  CONFIG_MVNETA=y
  CONFIG_MII=y
drivers/net/mvneta.c +37 -54
index 519e06ff01..5b1c4fe5fc 100644
@@ -1152,11 +1152,6 @@ static void mvneta_adjust_link(struct udevice *dev)
  	struct phy_device *phydev = pp->phydev;
  	bool status_change = false;
 
-	if (pp->fixed_link) {
-		debug("Using fixed link, skip link adjust\n");
-		return;
-	}
-
  	if (phydev->link &&
  	    (pp->speed != phydev->speed || pp->duplex != phydev->duplex)) {
  		u32 val;
@@ -1168,6 +1163,21 @@ static void mvneta_adjust_link(struct udevice *dev)
  			 MVNETA_GMAC_AN_SPEED_EN |
  			 MVNETA_GMAC_AN_DUPLEX_EN);
 
+		/* FIXME: For fixed-link case, these were the initial settings
+		 * used before the code was converted to use PHY_FIXED. Some of
+		 * these may look nonsensical (for example BYPASS_AN makes sense
+		 * for 1000base-x and 2500base-x modes, AFAIK), and in fact this
+		 * may be changed in the future (when support for inband AN will
+		 * be added). Also, why is ADVERT_FC enabled if we don't enable
+		 * inband AN at all?
+		 */
+		if (pp->fixed_link)
+			val = MVNETA_GMAC_FORCE_LINK_UP |
+			      MVNETA_GMAC_IB_BYPASS_AN_EN |
+			      MVNETA_GMAC_SET_FC_EN |
+			      MVNETA_GMAC_ADVERT_FC_EN |
+			      MVNETA_GMAC_SAMPLE_TX_CFG_EN;
+
  		if (phydev->duplex)
  			val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
 
@@ -1413,56 +1423,34 @@ static int mvneta_start(struct udevice *dev)
  	mvneta_port_power_up(pp, pp->phy_interface);
 
  	if (!pp->init || pp->link == 0) {
-		if (pp->fixed_link) {
-			u32 val;
-
-			pp->init = 1;
-			pp->link = 1;
-			mvneta_init(dev);
-
-			val = MVNETA_GMAC_FORCE_LINK_UP |
-			      MVNETA_GMAC_IB_BYPASS_AN_EN |
-			      MVNETA_GMAC_SET_FC_EN |
-			      MVNETA_GMAC_ADVERT_FC_EN |
-			      MVNETA_GMAC_SAMPLE_TX_CFG_EN;
-
-			if (pp->duplex)
-				val |= MVNETA_GMAC_CONFIG_FULL_DUPLEX;
-
-			if (pp->speed == SPEED_1000)
-				val |= MVNETA_GMAC_CONFIG_GMII_SPEED;
-			else if (pp->speed == SPEED_100)
-				val |= MVNETA_GMAC_CONFIG_MII_SPEED;
+		phydev = dm_eth_phy_connect(dev);
+		if (!phydev) {
+			printf("dm_eth_phy_connect failed\n");
+			return -ENODEV;
+		}
 
-			mvreg_write(pp, MVNETA_GMAC_AUTONEG_CONFIG, val);
-		} else {
-			phydev = dm_eth_phy_connect(dev);
-			if (!phydev) {
-				printf("dm_eth_phy_connect failed\n");
-				return -ENODEV;
-			}
+		pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
 
-			/* Set PHY address in case we will enable HW polling */
+		/* Set PHY address in case we will enable HW polling */
+		if (!pp->fixed_link)
  			mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
 
-			pp->phydev = phydev;
-			phy_config(phydev);
-			phy_startup(phydev);
-			if (!phydev->link) {
-				printf("%s: No link.\n", phydev->dev->name);
-				return -1;
-			}
-
-			/* Full init on first call */
-			mvneta_init(dev);
-			pp->init = 1;
-			return 0;
+		pp->phydev = phydev;
+		phy_config(phydev);
+		phy_startup(phydev);
+		if (!phydev->link) {
+			printf("%s: No link.\n", phydev->dev->name);
+			return -1;
  		}
-	}
 
-	/* Upon all following calls, this is enough */
-	mvneta_port_up(pp);
-	mvneta_port_enable(pp);
+		/* Full init on first call */
+		mvneta_init(dev);
+		pp->init = 1;
+	} else {
+		/* Upon all following calls, this is enough */
+		mvneta_port_up(pp);
+		mvneta_port_enable(pp);
+	}
 
  	return 0;
  }
@@ -1560,10 +1548,7 @@ static int mvneta_probe(struct udevice *dev)
  #if CONFIG_IS_ENABLED(DM_GPIO)
  	struct ofnode_phandle_args sfp_args;
  #endif
-	void *blob = (void *)gd->fdt_blob;
-	int node = dev_of_offset(dev);
  	void *bd_space;
-	int fl_node;
 
  	/*
  	 * Allocate buffer area for descs and rx_buffers. This is only
@@ -1600,15 +1585,6 @@ static int mvneta_probe(struct udevice *dev)
  	else
  		mvneta_conf_mbus_windows(pp);
 
-	/* fetch 'fixed-link' property from 'neta' node */
-	fl_node = fdt_subnode_offset(blob, node, "fixed-link");

drivers/net/mvneta.c static int mvneta_probe(struct udevice *dev) · line 1590

Quoted 10 lines
drivers/net/mvneta.c +0 -7
-	if (fl_node != -FDT_ERR_NOTFOUND) {
-		/* set phy_addr to invalid value for fixed link */
-		pp->duplex = fdtdec_get_bool(blob, fl_node, "full-duplex");
-		pp->speed = fdtdec_get_int(blob, fl_node, "speed", 0);
-		pp->fixed_link = true;
-	}
-
  #if CONFIG_IS_ENABLED(DM_GPIO)
  	if (!dev_read_phandle_with_args(dev, "sfp", NULL, 0, 0, &sfp_args) &&
  	    ofnode_is_enabled(sfp_args.node))

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 17/19
#49 lore raw

Re: [PATCH u-boot-marvell 17/19] net: mvneta: Drop fixed_link member from private struct

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

Since this member is checked only at two places drop it and inline it's usage.

Thanks,
Stefan

Quoted 35 lines
---
  drivers/net/mvneta.c | 7 ++-----
  1 file changed, 2 insertions(+), 5 deletions(-)
drivers/net/mvneta.c +2 -3
index 4917857681..378789b632 100644
@@ -273,7 +273,6 @@ struct mvneta_port {
  	u16 rx_ring_size;
 
  	phy_interface_t phy_interface;
-	bool fixed_link;
  	unsigned int link;
  	unsigned int duplex;
  	unsigned int speed;
@@ -813,7 +812,7 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
  	mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
  	/* Enable PHY polling in hardware if not in fixed-link mode */
-	if (!pp->fixed_link) {
+	if (pp->phydev->phy_id != PHY_FIXED_ID) {
  		mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
 
  		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
@@ -1173,7 +1172,7 @@ static void mvneta_adjust_link(struct udevice *dev)
  		 * be added). Also, why is ADVERT_FC enabled if we don't enable
  		 * inband AN at all?
  		 */
-		if (pp->fixed_link)
+		if (pp->phydev->phy_id == PHY_FIXED_ID)
  			val = MVNETA_GMAC_FORCE_LINK_UP |
  			      MVNETA_GMAC_IB_BYPASS_AN_EN |
  			      MVNETA_GMAC_SET_FC_EN |

drivers/net/mvneta.c static int mvneta_start(struct udevice *dev) · line 1435

Quoted 8 lines
drivers/net/mvneta.c +0 -2
@@ -1431,8 +1430,6 @@ static int mvneta_start(struct udevice *dev)
  			return -ENODEV;
  		}
 
-		pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
-
  		pp->phydev = phydev;
  		phy_config(phydev);
  		phy_startup(phydev);

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 16/19
#46 lore raw

Re: [PATCH u-boot-marvell 16/19] net: mvneta: Write PHY address just before enabling HW polling

In reply to Marek Behún
Quoted 5 lines · Marek Behún

From: Marek Behún <[email protected]>

Write PHY address just before enabling HW polling of the PHY.

Thanks,
Stefan

Quoted 18 lines
---
  drivers/net/mvneta.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
drivers/net/mvneta.c +2 -0
index 5b1c4fe5fc..4917857681 100644
@@ -814,6 +814,8 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
 
  	/* Enable PHY polling in hardware if not in fixed-link mode */
  	if (!pp->fixed_link) {
+		mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
+
  		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);
  		val |= MVNETA_PHY_POLLING_ENABLE;
  		mvreg_write(pp, MVNETA_UNIT_CONTROL, val);

drivers/net/mvneta.c static int mvneta_start(struct udevice *dev) · line 1438

Quoted 10 lines
drivers/net/mvneta.c +0 -4
@@ -1431,10 +1433,6 @@ static int mvneta_start(struct udevice *dev)
 
  		pp->fixed_link = phydev->phy_id == PHY_FIXED_ID;
 
-		/* Set PHY address in case we will enable HW polling */
-		if (!pp->fixed_link)
-			mvreg_write(pp, MVNETA_PHY_ADDR, phydev->addr);
-
  		pp->phydev = phydev;
  		phy_config(phydev);
  		phy_startup(phydev);

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 18/19
#52 lore raw

Re: [PATCH u-boot-marvell 18/19] net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

Guard the code handling the fixed PHY case by
CONFIG_IS_ENABLED(PHY_FIXED).

Thanks,
Stefan

Quoted 19 lines
---
  drivers/net/mvneta.c | 6 ++++--
  1 file changed, 4 insertions(+), 2 deletions(-)
drivers/net/mvneta.c +2 -1
index 378789b632..292c364e5e 100644
@@ -812,7 +812,8 @@ static void mvneta_defaults_set(struct mvneta_port *pp)
  	mvreg_write(pp, MVNETA_SDMA_CONFIG, val);
 
  	/* Enable PHY polling in hardware if not in fixed-link mode */
-	if (pp->phydev->phy_id != PHY_FIXED_ID) {
+	if (!CONFIG_IS_ENABLED(PHY_FIXED) ||
+	    pp->phydev->phy_id != PHY_FIXED_ID) {
  		mvreg_write(pp, MVNETA_PHY_ADDR, pp->phydev->addr);
 
  		val = mvreg_read(pp, MVNETA_UNIT_CONTROL);

drivers/net/mvneta.c static void mvneta_adjust_link(struct udevice *dev) · line 1180

Quoted 9 lines
drivers/net/mvneta.c +2 -1
@@ -1172,7 +1173,8 @@ static void mvneta_adjust_link(struct udevice *dev)
  		 * be added). Also, why is ADVERT_FC enabled if we don't enable
  		 * inband AN at all?
  		 */
-		if (pp->phydev->phy_id == PHY_FIXED_ID)
+		if (CONFIG_IS_ENABLED(PHY_FIXED) &&
+		    pp->phydev->phy_id == PHY_FIXED_ID)
  			val = MVNETA_GMAC_FORCE_LINK_UP |
  			      MVNETA_GMAC_IB_BYPASS_AN_EN |
  			      MVNETA_GMAC_SET_FC_EN |

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 19/19
#55 lore raw

Re: [PATCH u-boot-marvell 19/19] net: mvneta: Drop unneeded macro

In reply to Marek Behún
Quoted 9 lines · Marek Behún

From: Marek Behún <[email protected]>

Macro MVNETA_GMAC_FORCE_LINK_UP can be dropped from value assignment in fixed link case, since it's value is written into the register later in the function for link-down-to-link-up case. The value is written as MVNETA_GMAC_FORCE_LINK_DOWN | MVNETA_GMAC_FORCE_LINK_PASS, and so the macro definition can also be dropped.

Thanks,
Stefan

Quoted 17 lines
---
  drivers/net/mvneta.c | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)
drivers/net/mvneta.c +0 -1
index 292c364e5e..d2c42c4396 100644
@@ -188,7 +188,6 @@ DECLARE_GLOBAL_DATA_PTR;
  #define MVNETA_GMAC_AUTONEG_CONFIG               0x2c0c
  #define      MVNETA_GMAC_FORCE_LINK_DOWN         BIT(0)
  #define      MVNETA_GMAC_FORCE_LINK_PASS         BIT(1)
-#define      MVNETA_GMAC_FORCE_LINK_UP           (BIT(0) | BIT(1))
  #define      MVNETA_GMAC_IB_BYPASS_AN_EN         BIT(3)
  #define      MVNETA_GMAC_CONFIG_MII_SPEED        BIT(5)
  #define      MVNETA_GMAC_CONFIG_GMII_SPEED       BIT(6)

drivers/net/mvneta.c static void mvneta_adjust_link(struct udevice *dev) · line 1180

Quoted 9 lines
drivers/net/mvneta.c +1 -2
@@ -1175,8 +1174,7 @@ static void mvneta_adjust_link(struct udevice *dev)
  		 */
  		if (CONFIG_IS_ENABLED(PHY_FIXED) &&
  		    pp->phydev->phy_id == PHY_FIXED_ID)
-			val = MVNETA_GMAC_FORCE_LINK_UP |
-			      MVNETA_GMAC_IB_BYPASS_AN_EN |
+			val = MVNETA_GMAC_IB_BYPASS_AN_EN |
  			      MVNETA_GMAC_SET_FC_EN |
  			      MVNETA_GMAC_ADVERT_FC_EN |
  			      MVNETA_GMAC_SAMPLE_TX_CFG_EN;

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
Reviewed-by on v1 13/19
#37 lore raw

Re: [PATCH u-boot-marvell 13/19] net: mvneta: Don't check for CONFIG_PHYLIB

In reply to Marek Behún
Quoted 6 lines · Marek Behún

From: Marek Behún <[email protected]>

Drop checking for CONFIG_PHYLIB in mvneta, this is already done in Kconfig.

Thanks,
Stefan

Quoted 9 lines
---
  drivers/net/mvneta.c | 4 ----
  1 file changed, 4 deletions(-)
drivers/net/mvneta.c +0 -0
index 5c3f7125b5..0ec9d2957c 100644

drivers/net/mvneta.c line 45

Quoted 10 lines
drivers/net/mvneta.c +0 -4
@@ -40,10 +40,6 @@
 
  DECLARE_GLOBAL_DATA_PTR;
 
-#if !defined(CONFIG_PHYLIB)
-# error Marvell mvneta requires PHYLIB
-#endif
-
  #define CONFIG_NR_CPUS		1
  #define ETH_HLEN		14	/* Total octets in header */
 

Viele Grüße,
Stefan Roese

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-51 Fax: (+49)-8142-66989-80 Email: [email protected]
#57 lore raw
In reply to Marek Behún
Quoted 40 lines · Marek Behún

From: Marek Behún <[email protected]>

Hello Stefan,

here come some refactors, cleanups and fixed for the mvneta driver.

Marek Behún (19):
net: mvneta: Get rid of platdata
net: mvneta: Fix 10Mbps speed
net: mvneta: Use DM MDIO API for connecting PHY
net: mvneta: Remember fixed link instead of PHY address in priv data
arm: mvebu: Espressobin: Use DM registered MDIO to configure switch
net: mdio-uclass: add dm_phy_find_by_ofnode() helper
arm: mvebu: turris_mox: Use DM registered MDIO
net: mvneta: Don't register MDIO bus
net: mvneta: Fix unused variable warning if DM_GPIO is disabled
net: mvneta: Drop one indentation level in mvneta_adjust_link()
net: mvneta: Use bool instead of int for boolean variable
net: mvneta: Drop unnecessary space
net: mventa: Don't check for CONFIG_PHYLIB
net: mvneta: Rename CONFIG_NR_CPUS to MVNETA_NR_CPUS
net: mvneta: Convert to use PHY_FIXED for fixed-link
net: mvneta: Write PHY address just before enabling HW polling
net: mvneta: Drop fixed_link member from private struct
net: mvneta: Disable fixed PHY code if PHY_FIXED is not compiled in
net: mvneta: Drop unneeded macro

  .../dts/armada-3720-turris-mox-u-boot.dtsi    |  19 -
  board/CZ.NIC/turris_mox/turris_mox.c          |  88 ++---
  board/Marvell/mvebu_armada-37xx/board.c       |  26 +-
  configs/clearfog_defconfig                    |   1 +
  configs/controlcenterdc_defconfig             |   1 +
  configs/db-88f6820-amc_defconfig              |   1 +
  configs/db-88f6820-gp_defconfig               |   1 +
  configs/db-mv784mp-gp_defconfig               |   1 +
  configs/ds414_defconfig                       |   1 +
  configs/helios4_defconfig                     |   1 +
  configs/maxbcm_defconfig                      |   1 +
  configs/mvebu_espressobin-88f3720_defconfig   |   3 +
  configs/theadorable_debug_defconfig           |   1 +
Quoted 9 lines
  configs/turris_mox_defconfig                  |   1 +
  configs/turris_omnia_defconfig                |   2 +
  configs/uDPU_defconfig                        |   1 +
  drivers/net/Kconfig                           |   1 +
  drivers/net/mvneta.c                          | 343 ++++--------------
  include/miiphy.h                              |   9 +
  net/mdio-uclass.c                             |  22 ++
  20 files changed, 181 insertions(+), 343 deletions(-)

Applied to u-boot-marvell/master

Thanks,
Stefan