Re: [PULL] u-boot-sh/next_net/phy_connect_dev

2023-06-10 Thread Tom Rini
On Sat, Jun 10, 2023 at 03:38:07PM +0200, Marek Vasut wrote:

> The following changes since commit 5f41ef792c307dedc12647cdde2ade273aa11805:
> 
>   Merge branch '2023-06-09-fwu-updates' into next (2023-06-09 20:35:02 -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-sh.git 
> next_net/phy_connect_dev
> 
> for you to fetch changes up to 32d2461e0467b50abeb5662fce41fdd686e88b61:
> 
>   ARM: renesas: Enable DM_ETH_PHY and SMSC PHY driver (2023-06-10 13:34:06 
> +0200)
> 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


Re: [PULL] u-boot-sh/next_mtd/rpc-spi

2023-06-10 Thread Tom Rini
On Sat, Jun 10, 2023 at 03:37:23PM +0200, Marek Vasut wrote:

> The following changes since commit 5f41ef792c307dedc12647cdde2ade273aa11805:
> 
>   Merge branch '2023-06-09-fwu-updates' into next (2023-06-09 20:35:02 -0400)
> 
> are available in the Git repository at:
> 
>   https://source.denx.de/u-boot/custodians/u-boot-sh.git next_mtd/rpc-spi
> 
> for you to fetch changes up to 2e6a1f9fde934ac15eab28fa46495e8d31a29bce:
> 
>   mtd: spi: renesas: Add 4 bytes address mode support (2023-06-10 11:50:45 
> +0200)
> 

Applied to u-boot/next, thanks!

-- 
Tom


signature.asc
Description: PGP signature


[PATCH v2 1/1] efi_selftest: ReinstallProtocolInterface test

2023-06-10 Thread Heinrich Schuchardt
Test ReinstallProtocolInterface() more rigorously.

Replacing the sole installed protocol interface must not result in deleting
the handle and creating a new one.

Check which interface is actually installed before and after
ReinstallProtocolInterface().

Signed-off-by: Heinrich Schuchardt 
---
v2:
Use OpenProtocol instead of deprecated HandleProtocol
---
 .../efi_selftest_register_notify.c| 25 +++
 1 file changed, 25 insertions(+)

diff --git a/lib/efi_selftest/efi_selftest_register_notify.c 
b/lib/efi_selftest/efi_selftest_register_notify.c
index ad4bcce1a1..adf5dd00a1 100644
--- a/lib/efi_selftest/efi_selftest_register_notify.c
+++ b/lib/efi_selftest/efi_selftest_register_notify.c
@@ -124,6 +124,7 @@ static int execute(void)
 {
efi_status_t ret;
efi_handle_t handle1 = NULL, handle2 = NULL;
+   struct interface *interface;
struct interface interface1, interface2;
 
ret = boottime->install_protocol_interface(, ,
@@ -145,6 +146,18 @@ static int execute(void)
efi_st_error("LocateHandle failed\n");
return EFI_ST_FAILURE;
}
+   interface = NULL;
+   ret = boottime->open_protocol(handle1, , (void**),
+ NULL, NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("Cannot find installed protocol on handle\n");
+   return EFI_ST_FAILURE;
+   }
+   if (interface != ) {
+   efi_st_error("Wrong interface after install\n");
+   return EFI_ST_FAILURE;
+   }
ret = boottime->free_pool(context.handles);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
@@ -186,6 +199,18 @@ static int execute(void)
efi_st_error("FreePool failed\n");
return EFI_ST_FAILURE;
}
+   interface = NULL;
+   ret = boottime->open_protocol(handle1, , (void**),
+ NULL, NULL,
+ EFI_OPEN_PROTOCOL_GET_PROTOCOL);
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("Cannot find reinstalled protocol on handle\n");
+   return EFI_ST_FAILURE;
+   }
+   if (interface != ) {
+   efi_st_error("Wrong interface after reinstall\n");
+   return EFI_ST_FAILURE;
+   }
context.notify_count = 0;
ret = boottime->install_protocol_interface(, ,
   EFI_NATIVE_INTERFACE,
-- 
2.40.1



[PATCH 1/1] efi_selftest: ReinstallProtocolInterface test

2023-06-10 Thread Heinrich Schuchardt
Test ReinstallProtocolInterface() more rigorously.

Replacing the sole installed protocol interface must not result in deleting
the handle and creating a new one.

Check which interface is actually installed before and after
ReinstallProtocolInterface().

Signed-off-by: Heinrich Schuchardt 
---
 .../efi_selftest_register_notify.c| 21 +++
 1 file changed, 21 insertions(+)

diff --git a/lib/efi_selftest/efi_selftest_register_notify.c 
b/lib/efi_selftest/efi_selftest_register_notify.c
index ad4bcce1a1..2c6b625ddf 100644
--- a/lib/efi_selftest/efi_selftest_register_notify.c
+++ b/lib/efi_selftest/efi_selftest_register_notify.c
@@ -124,6 +124,7 @@ static int execute(void)
 {
efi_status_t ret;
efi_handle_t handle1 = NULL, handle2 = NULL;
+   struct interface *interface;
struct interface interface1, interface2;
 
ret = boottime->install_protocol_interface(, ,
@@ -145,6 +146,16 @@ static int execute(void)
efi_st_error("LocateHandle failed\n");
return EFI_ST_FAILURE;
}
+   interface = NULL;
+   ret = boottime->handle_protocol(handle1, , (void **));
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("Cannot find installed protocol on handle\n");
+   return EFI_ST_FAILURE;
+   }
+   if (interface != ) {
+   efi_st_error("Wrong interface after install\n");
+   return EFI_ST_FAILURE;
+   }
ret = boottime->free_pool(context.handles);
if (ret != EFI_SUCCESS) {
efi_st_error("FreePool failed\n");
@@ -186,6 +197,16 @@ static int execute(void)
efi_st_error("FreePool failed\n");
return EFI_ST_FAILURE;
}
+   interface = NULL;
+   ret = boottime->handle_protocol(handle1, , (void **));
+   if (ret != EFI_SUCCESS) {
+   efi_st_error("Cannot find reinstalled protocol on handle\n");
+   return EFI_ST_FAILURE;
+   }
+   if (interface != ) {
+   efi_st_error("Wrong interface after reinstall\n");
+   return EFI_ST_FAILURE;
+   }
context.notify_count = 0;
ret = boottime->install_protocol_interface(, ,
   EFI_NATIVE_INTERFACE,
-- 
2.40.1



Re: [PATCH v1 2/2] net: designware: Add bitbang feature for designware driver

2023-06-10 Thread Ramon Fried
On Tue, Feb 14, 2023 at 10:20 AM Jim Liu  wrote:
>
> Add bb_miiphy_bus function for designware bitbang feature.
>
> Signed-off-by: Jim Liu 
> ---
>  drivers/net/designware.c | 109 ++-
>  drivers/net/designware.h |   3 ++
>  2 files changed, 111 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/net/designware.c b/drivers/net/designware.c
> index e09ca3313d..c539afc620 100644
> --- a/drivers/net/designware.c
> +++ b/drivers/net/designware.c
> @@ -757,6 +757,32 @@ int designware_eth_probe(struct udevice *dev)
> }
> priv->bus = miiphy_get_dev_by_name(dev->name);
>
> +#if defined(CONFIG_BITBANGMII) && defined(CONFIG_DM_GPIO)
> +   if (dev_read_bool(dev, "snps,bitbang-mii")) {
> +   printf("\n%s: use bitbang mii..\n", dev->name);
debug
> +   ret = gpio_request_by_name(dev, "snps,mdc-gpio", 0,
> +  >mdc_gpio, GPIOD_IS_OUT);
> +   if (ret) {
> +   printf("no mdc-gpio\n");
> +   return ret;
> +   }
> +
> +   ret = gpio_request_by_name(dev, "snps,mdio-gpio", 0,
> +  >mdio_gpio, GPIOD_IS_OUT);
> +
> +   if (ret) {
> +   printf("no mdio-gpio\n");
> +   return ret;
> +   }
> +   dm_gpio_set_value(>mdc_gpio, 1);
> +   bb_miiphy_buses[0].priv = priv;
> +   sprintf(bb_miiphy_buses[0].name, dev->name);
> +   priv->bus->read = bb_miiphy_read;
> +   priv->bus->write = bb_miiphy_write;
> +   priv->bus->reset = NULL;
> +   }
> +#endif
> +
> ret = dw_phy_init(priv, dev);
> debug("%s, ret=%d\n", __func__, ret);
> if (!ret)
> @@ -826,7 +852,7 @@ int designware_eth_of_to_plat(struct udevice *dev)
> reset_flags |= GPIOD_ACTIVE_LOW;
>
> ret = gpio_request_by_name(dev, "snps,reset-gpio", 0,
> -   >reset_gpio, reset_flags);
> +  >reset_gpio, reset_flags);
What has changed here ?
> if (ret == 0) {
> ret = dev_read_u32_array(dev, "snps,reset-delays-us",
>  dw_pdata->reset_delays, 3);
> @@ -866,3 +892,84 @@ static struct pci_device_id supported[] = {
>  };
>
>  U_BOOT_PCI_DEVICE(eth_designware, supported);
> +
> +#if defined(CONFIG_BITBANGMII) && CONFIG_IS_ENABLED(DM_GPIO)
> +int dw_eth_bb_init(struct bb_miiphy_bus *bus)
> +{
> +   return 0;
> +}
> +
> +static int dw_eth_bb_mdio_active(struct bb_miiphy_bus *bus)
> +{
> +   struct dw_eth_dev *priv = bus->priv;
> +   struct gpio_desc *desc = >mdio_gpio;
> +   desc->flags = 0;
> +   dm_gpio_set_dir_flags(>mdio_gpio, GPIOD_IS_OUT);
> +
> +   return 0;
> +}
> +
> +static int dw_eth_bb_mdio_tristate(struct bb_miiphy_bus *bus)
> +{
> +   struct dw_eth_dev *priv = bus->priv;
> +   struct gpio_desc *desc = >mdio_gpio;
> +   desc->flags = 0;
> +   dm_gpio_set_dir_flags(>mdio_gpio, GPIOD_IS_IN);
> +
> +   return 0;
> +}
> +
> +static int dw_eth_bb_set_mdio(struct bb_miiphy_bus *bus, int v)
> +{
> +   struct dw_eth_dev *priv = bus->priv;
> +
> +   if (v)
> +   dm_gpio_set_value(>mdio_gpio, 1);
> +   else
> +   dm_gpio_set_value(>mdio_gpio, 0);
> +
> +   return 0;
> +}
> +
> +static int dw_eth_bb_get_mdio(struct bb_miiphy_bus *bus, int *v)
> +{
> +   struct dw_eth_dev *priv = bus->priv;
> +
> +   *v = dm_gpio_get_value(>mdio_gpio);
> +   return 0;
> +}
> +
> +static int dw_eth_bb_set_mdc(struct bb_miiphy_bus *bus, int v)
> +{
> +   struct dw_eth_dev *priv = bus->priv;
> +
> +   if (v)
> +   dm_gpio_set_value(>mdc_gpio, 1);
> +   else
> +   dm_gpio_set_value(>mdc_gpio, 0);
> +
> +   return 0;
> +}
> +
> +static int dw_eth_bb_delay(struct bb_miiphy_bus *bus)
> +{
> +   udelay(1);
Where is this 1 usec coming from ? should it be configurable ?
> +
> +   return 0;
> +}
> +
> +struct bb_miiphy_bus bb_miiphy_buses[] = {
> +   {
> +   .name   = "dw_eth_bb",
> +   .init   = dw_eth_bb_init,
> +   .mdio_active= dw_eth_bb_mdio_active,
> +   .mdio_tristate  = dw_eth_bb_mdio_tristate,
> +   .set_mdio   = dw_eth_bb_set_mdio,
> +   .get_mdio   = dw_eth_bb_get_mdio,
> +   .set_mdc= dw_eth_bb_set_mdc,
> +   .delay  = dw_eth_bb_delay,
> +   }
> +};
> +
> +int bb_miiphy_buses_num = ARRAY_SIZE(bb_miiphy_buses);
> +#endif
> diff --git a/drivers/net/designware.h b/drivers/net/designware.h
> index 9da4e902cb..68ca5d9cd0 100644
> --- a/drivers/net/designware.h
> +++ b/drivers/net/designware.h
> @@ -235,6 +235,9 @@ struct dw_eth_dev {
> struct eth_dma_regs *dma_regs_p;
>  #if CONFIG_IS_ENABLED(DM_GPIO)
>  

[PULL] u-boot-sh/master_reserved

2023-06-10 Thread Marek Vasut
The following changes since commit addd47379df54a3eb247c6db4f799f14af43e523:

  Merge https://source.denx.de/u-boot/custodians/u-boot-usb (2023-06-08 
18:23:06 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-sh.git master_reserved

for you to fetch changes up to fd3e2b4de366a32cd342675bdcd43b72159913ee:

  renesas: rcar: Apply ATF overlay for reserved-memory (2023-06-10 17:06:38 
+0200)


Detlev Casanova (1):
  renesas: rcar: Apply ATF overlay for reserved-memory

 board/renesas/rcar-common/common.c | 10 --
 1 file changed, 8 insertions(+), 2 deletions(-)


bootmenu regression

2023-06-10 Thread Mark Kettenis
Hi Simon,

In commit 32bab0eae51 you added a

  #define ansi 0

and put the code that positions the cursor to print the "Hit any key
to stop autoboot" message behind an

  if (ansi)

condition.  As a result that message is now printed in whatever place
the cursor happens to be, which happens to be the last menu entry that
gets printed, making that menu option confusing.

The commit message makes no mention of any intended side-effect of the
change, so am I right assuming that this is debugging code that
accidentally made it out of your tree?


Re: [PATCH] renesas: rcar: Apply ATF overlay for reserved-memory

2023-06-10 Thread Adam Ford
On Fri, Jun 9, 2023 at 10:41 AM Detlev Casanova
 wrote:
>
> The function fdtdec_board_setup() is called early and adds the overlay
> from ATF to the u-boot device tree. That is necessary so that u-boot
> doesn't use reserved memory.
>
> Linux also needs to know about that reserved memory so the overlay from
> ATF needs to be aplied on the linux device tree as well.
>
> This commit makes sure that the ATF overlay is applied to both device trees.
>

Thanks for this.  I was trying to do this very same thing, but your
solution looks cleaner than mine.

Reviewed-by: Adam Ford 
> Signed-off-by: Detlev Casanova 
> ---
>  board/renesas/rcar-common/common.c | 10 --
>  1 file changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/board/renesas/rcar-common/common.c 
> b/board/renesas/rcar-common/common.c
> index f38453af82c..f976c99028a 100644
> --- a/board/renesas/rcar-common/common.c
> +++ b/board/renesas/rcar-common/common.c
> @@ -25,12 +25,17 @@ extern u64 rcar_atf_boot_args[];
>
>  #define FDT_RPC_PATH   "/soc/spi@ee20"
>
> -int fdtdec_board_setup(const void *fdt_blob)
> +static void apply_atf_overlay(void *fdt_blob)
>  {
> void *atf_fdt_blob = (void *)(rcar_atf_boot_args[1]);
>
> if (fdt_magic(atf_fdt_blob) == FDT_MAGIC)
> -   fdt_overlay_apply_node((void *)fdt_blob, 0, atf_fdt_blob, 0);
> +   fdt_overlay_apply_node(fdt_blob, 0, atf_fdt_blob, 0);
> +}
> +
> +int fdtdec_board_setup(const void *fdt_blob)
> +{
> +   apply_atf_overlay((void *)fdt_blob);
>
> return 0;
>  }
> @@ -159,6 +164,7 @@ static void update_rpc_status(void *blob)
>
>  int ft_board_setup(void *blob, struct bd_info *bd)
>  {
> +   apply_atf_overlay(blob);
> scrub_duplicate_memory(blob);
> update_rpc_status(blob);
>
> --
> 2.39.3
>


[PULL] u-boot-sh/next_net/phy_connect_dev

2023-06-10 Thread Marek Vasut
The following changes since commit 5f41ef792c307dedc12647cdde2ade273aa11805:

  Merge branch '2023-06-09-fwu-updates' into next (2023-06-09 20:35:02 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-sh.git 
next_net/phy_connect_dev

for you to fetch changes up to 32d2461e0467b50abeb5662fce41fdd686e88b61:

  ARM: renesas: Enable DM_ETH_PHY and SMSC PHY driver (2023-06-10 13:34:06 
+0200)


Geert Uytterhoeven (1):
  ARM: dts: renesas: Add compatible properties to LAN8710A Ethernet PHYs

Marek Vasut (13):
  net: eth-phy: staticize eth_phy_reset()
  net: altera_tsa: Switch to new U-Boot PHY API
  net: ave: Switch to new U-Boot PHY API
  net: ethoc: Switch to new U-Boot PHY API
  net: pch_gbe: Switch to new U-Boot PHY API
  net: sh_eth: Switch to new U-Boot PHY API
  net: sunxi_emac: Switch to new U-Boot PHY API
  net: phy: Unpublish phy_connect_dev()
  net: phy: Bind ETH_PHY uclass driver to each new PHY
  net: phy: Handle reset-delay-us/reset-post-delay-us properties
  net: ravb: Drop reset GPIO handling in favor of common code
  net: sh_eth: Drop reset GPIO handling in favor of common code
  ARM: renesas: Enable DM_ETH_PHY and SMSC PHY driver

Valentine Barshak (2):
  net: sh_eth: Workaround cache issues
  net: sh_eth: Fix RX error handling

 arch/arm/dts/r7s72100-gr-peach.dts |  2 ++
 configs/grpeach_defconfig  |  3 +++
 drivers/net/Kconfig|  2 ++
 drivers/net/altera_tse.c   |  8 +--
 drivers/net/eth-phy-uclass.c   | 10 +++-
 drivers/net/ethoc.c|  8 +++
 drivers/net/pch_gbe.c  |  5 +---
 drivers/net/phy/ethernet_id.c  | 17 ++
 drivers/net/phy/phy.c  |  4 ++--
 drivers/net/ravb.c | 22 -
 drivers/net/sh_eth.c   | 48 +++---
 drivers/net/sni_ave.c  |  6 ++---
 drivers/net/sunxi_emac.c   |  7 +++---
 include/phy.h  |  9 ---
 14 files changed, 59 insertions(+), 92 deletions(-)


[PULL] u-boot-sh/next_mtd/rpc-spi

2023-06-10 Thread Marek Vasut
The following changes since commit 5f41ef792c307dedc12647cdde2ade273aa11805:

  Merge branch '2023-06-09-fwu-updates' into next (2023-06-09 20:35:02 -0400)

are available in the Git repository at:

  https://source.denx.de/u-boot/custodians/u-boot-sh.git next_mtd/rpc-spi

for you to fetch changes up to 2e6a1f9fde934ac15eab28fa46495e8d31a29bce:

  mtd: spi: renesas: Add 4 bytes address mode support (2023-06-10 11:50:45 
+0200)


Cong Dang (1):
  mtd: spi: renesas: Add 4 bytes address mode support

Hai Pham (3):
  mtd: spi: renesas: Extract strobe delay setting code into separate 
function
  mtd: spi: renesas: Enable SPI_FLASH_SFDP_SUPPORT
  mtd: spi: renesas: Add R-Car Gen4 support

 drivers/spi/Kconfig   |   2 +-
 drivers/spi/renesas_rpc_spi.c | 206 +-
 2 files changed, 105 insertions(+), 103 deletions(-)


Re: [PATCH] renesas: rcar: Apply ATF overlay for reserved-memory

2023-06-10 Thread Marek Vasut

On 6/9/23 17:19, Detlev Casanova wrote:

The function fdtdec_board_setup() is called early and adds the overlay
from ATF to the u-boot device tree. That is necessary so that u-boot
doesn't use reserved memory.

Linux also needs to know about that reserved memory so the overlay from
ATF needs to be aplied on the linux device tree as well.

This commit makes sure that the ATF overlay is applied to both device trees.

Signed-off-by: Detlev Casanova 


Reviewed-by: Marek Vasut 


Re: [PATCH 2/2] renesas: rcar3: Load the correct device tree

2023-06-10 Thread Marek Vasut

On 6/9/23 18:00, Detlev Casanova wrote:

The Renesas R-Car Gen3 H3e (Starter Kit Premier) uses a different
device tree than the default one.

This uses the sysinfo's board id to determine if the board needs a
specific device tree.

Signed-off-by: Detlev Casanova 
---
  board/renesas/ulcb/ulcb.c| 34 ++
  configs/rcar3_ulcb_defconfig |  1 +
  2 files changed, 35 insertions(+)

diff --git a/board/renesas/ulcb/ulcb.c b/board/renesas/ulcb/ulcb.c
index 1477750f921..3e2fe3a3ca9 100644
--- a/board/renesas/ulcb/ulcb.c
+++ b/board/renesas/ulcb/ulcb.c
@@ -28,6 +28,8 @@
  #include 
  #include 
  
+#include "../../../drivers/sysinfo/rcar3.h"

+
  DECLARE_GLOBAL_DATA_PTR;
  
  #define DVFS_MSTP926		BIT(26)

@@ -65,6 +67,38 @@ int board_init(void)
return 0;
  }
  
+int misc_init_r(void)

+{
+   struct udevice *dev;
+   int board_id;
+   int ret = sysinfo_get();
+if (ret) {
+   debug("Cannot get sysinfo: %d\n", ret);
+   return 0;
+   }
+
+   ret = sysinfo_detect(dev);
+   if (ret) {
+   debug("Cannot detect sysinfo: %d\n", ret);
+   return 0;
+   }
+
+   ret = sysinfo_get_int(dev,
+   SYSINFO_ID_BOARD_MODEL,
+   _id);
+
+   if (ret) {
+   debug("Cannot get sysinfo int: %d\n", ret);
+   return 0;
+   }
+
+   if (board_id == BOARD_STARTER_KIT_PRE) {
+   env_set("fdtfile", "renesas/r8a779m1-ulcb.dtb");


About this, BOARD_STARTER_KIT_PRE is just H3 ULCB . I suspect the ID is 
the same on H3e ULCB ? I think we need some other method to discern the 
two board variants. Here is the sysinfo EEPROM from H3 ULCB:


CPU:   Renesas Electronics R8A7795 rev 2.0
Model: Renesas Starter Kit Premier board rev 2.0
DRAM:  896 MiB (effective 3.9 GiB)
...
=> i2c dev 7 ; i2c md 0x50 0 0x80
Setting bus to 7
: 8e 17 52 5d e6 e6 b1 35 e4 e4 e4 e4 35 20 20 0a..R]...55  .
0010: f4 f4 44 44 f4 f4 44 44 44 44 f4 f4 f4 4f 01 52..DD.....O.R
0020: 52 52 52 53 51 4f 4d 01 52 53 60 00 00 00 00 00RRRSQOM.RS`.
0030: 00 00 11 00 01 2d ff ff ff ff ff ff ff ff ff ff.-..
0040: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0050: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0060: ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
0070: 5a ff ff ff ff ff ff ff ff ff ff ff ff ff ff ffZ...

Can you dump and share the H3e ULCB EEPROM content ?


Re: [PATCH 1/2] renesas: rcar3: Expose the board id in sysinfo

2023-06-10 Thread Marek Vasut

On 6/9/23 18:00, Detlev Casanova wrote:

This is a preparation commit for selecting the correct device tree name
to be loaded depending on the board id.


I am not opposed to this patch itself (with a few tweaks, see below), 
but please see 2/2, I suspect this method of selecting the DT is not 
gonna work.



Signed-off-by: Detlev Casanova 
---
  drivers/sysinfo/rcar3.c | 31 ++-
  drivers/sysinfo/rcar3.h | 21 +
  2 files changed, 39 insertions(+), 13 deletions(-)
  create mode 100644 drivers/sysinfo/rcar3.h

diff --git a/drivers/sysinfo/rcar3.c b/drivers/sysinfo/rcar3.c
index 7b127986da7..4252f8d452c 100644
--- a/drivers/sysinfo/rcar3.c
+++ b/drivers/sysinfo/rcar3.c
@@ -7,24 +7,12 @@
  #include 
  #include 
  #include 
-#include 
+#include "rcar3.h"
  
  #define BOARD_CODE_MASK		0xF8

  #define BOARD_REV_MASK0x07
  #define BOARD_CODE_SHIFT  0x03
  
-#define BOARD_SALVATOR_X	0x0

-#define BOARD_KRIEK0x1
-#define BOARD_STARTER_KIT  0x2
-#define BOARD_EAGLE0x3
-#define BOARD_SALVATOR_XS  0x4
-#define BOARD_CONDOR   0x6
-#define BOARD_DRAAK0x7
-#define BOARD_EBISU0x8
-#define BOARD_STARTER_KIT_PRE  0xB
-#define BOARD_EBISU_4D 0xD
-#define BOARD_CONDOR_I 0x10
-
  /**
   * struct sysinfo_rcar_priv - sysinfo private data
   * @boardname: board model and revision
@@ -32,6 +20,7 @@
   */
  struct sysinfo_rcar_priv {
charboardmodel[64];
+   u8  board_id;
u8  val;
  };
  
@@ -42,6 +31,19 @@ static int sysinfo_rcar_detect(struct udevice *dev)

return priv->val == 0xff;
  }
  
+static int sysinfo_rcar_get_int(struct udevice *dev, int id, int *val)

+{
+   struct sysinfo_rcar_priv *priv = dev_get_priv(dev);
+
+   switch (id) {
+   case SYSINFO_ID_BOARD_MODEL:
+   *val = priv->board_id;
+   return 0;
+   default:
+   return -EINVAL;
+   };
+}
+
  static int sysinfo_rcar_get_str(struct udevice *dev, int id, size_t size, 
char *val)
  {
struct sysinfo_rcar_priv *priv = dev_get_priv(dev);
@@ -59,6 +61,7 @@ static int sysinfo_rcar_get_str(struct udevice *dev, int id, 
size_t size, char *
  static const struct sysinfo_ops sysinfo_rcar_ops = {
.detect = sysinfo_rcar_detect,
.get_str = sysinfo_rcar_get_str,
+   .get_int = sysinfo_rcar_get_int,
  };
  
  static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)

@@ -68,6 +71,8 @@ static void sysinfo_rcar_parse(struct sysinfo_rcar_priv *priv)
bool salvator_xs = false;
bool ebisu_4d = false;
bool condor_i = false;
+
+   priv->board_id = board_id;
char rev_major = '?';
char rev_minor = '?';
  
diff --git a/drivers/sysinfo/rcar3.h b/drivers/sysinfo/rcar3.h

new file mode 100644
index 000..21ae918d9bb
--- /dev/null
+++ b/drivers/sysinfo/rcar3.h
@@ -0,0 +1,21 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2023 Detlev Casanova 
+ */
+
+#include 


This should not be here, the header is using nothing from sysinfo.h

Also, this rcar3.h header should be in 
arch/arm/mach-rmobile/include/mach/ and potentially just part of 
sys_proto.h .



+#define BOARD_SALVATOR_X   0x0
+#define BOARD_KRIEK0x1
+#define BOARD_STARTER_KIT  0x2
+#define BOARD_EAGLE0x3
+#define BOARD_SALVATOR_XS  0x4
+#define BOARD_CONDOR   0x6
+#define BOARD_DRAAK0x7
+#define BOARD_EBISU0x8
+#define BOARD_STARTER_KIT_PRE  0xB
+#define BOARD_EBISU_4D 0xD
+#define BOARD_CONDOR_I 0x10
+
+
+


Does ./scripts/checkpatch.pl complain about those three extra trailing 
newlines ?


[PATCH 2/2] mmc: renesas-sdhi: Send stop when MMC tuning command fails

2023-06-10 Thread Marek Vasut
From: Hai Pham 

When tuning command (CMD21) fails with command error, call
mmc_send_stop_transmission() to send stop command (CMD12).

Reviewed-by: Takeshi Kihara 
Reviewed-by: Marek Vasut 
Signed-off-by: Hai Pham 
Signed-off-by: Marek Vasut 
[Marek: Add dev_dbg() message in case tuning abort fails
Move tuning opcode check from mmc_abort_tuning()]
---
Cc: "Ying-Chun Liu (PaulLiu)" 
Cc: Hai Pham 
Cc: Jaehoon Chung 
Cc: Loic Poulain 
Cc: Peng Fan 
Cc: Simon Glass 
Cc: Takeshi Kihara 
---
 drivers/mmc/renesas-sdhi.c | 11 +++
 1 file changed, 11 insertions(+)

diff --git a/drivers/mmc/renesas-sdhi.c b/drivers/mmc/renesas-sdhi.c
index 280d96dbc2d..74d98795838 100644
--- a/drivers/mmc/renesas-sdhi.c
+++ b/drivers/mmc/renesas-sdhi.c
@@ -611,6 +611,17 @@ int renesas_sdhi_execute_tuning(struct udevice *dev, uint 
opcode)
priv->smpcmp |= BIT(i);
 
mdelay(1);
+
+   /*
+* eMMC specification specifies that CMD12 can be used to stop 
a tuning
+* command, but SD specification does not, so do nothing unless 
it is
+* eMMC.
+*/
+   if (ret && (opcode == MMC_CMD_SEND_TUNING_BLOCK_HS200)) {
+   ret = mmc_send_stop_transmission(mmc);
+   if (ret < 0)
+   dev_dbg(dev, "Tuning abort fail (%d)\n", ret);
+   }
}
 
ret = renesas_sdhi_select_tuning(priv, taps);
-- 
2.39.2



[PATCH 1/2] mmc: Introduce mmc_send_stop_transmission()

2023-06-10 Thread Marek Vasut
From: Hai Pham 

If a tuning command times out, the card could still be processing it,
which will cause problems for recovery. The eMMC specification section
6.6 Data transfer mode (cont’d) claims that CMD12 can be used to stop
CMD21:
"
The relationship between the various data transfer modes is summarized (see 
Figure 27):
- All data read commands can be aborted any time by the stop command (CMD12).
  The data transfer will terminate and the Device will return to the Transfer 
State.
  The read commands are: ... send tuning block (CMD21) 
"
Add a function that does that.

Based on Linux commit [1] and [2].

[1] e711f0309109 ("mmc: mmc: Introduce mmc_abort_tuning()")
[2] 21adc2e45f4e ("mmc: Improve function name when aborting a tuning
cmd")

Reviewed-by: Takeshi Kihara 
Reviewed-by: Marek Vasut 
Signed-off-by: Hai Pham 
Signed-off-by: Marek Vasut 
[Marek: Update commit message, quote relevant part of the specification.
Rename to mmc_send_stop_transmission().
Remove tuning opcode check, this is controller driver specific.
Deduplicate part of mmc_read_blocks() using this function.]
---
Cc: "Ying-Chun Liu (PaulLiu)" 
Cc: Hai Pham 
Cc: Jaehoon Chung 
Cc: Loic Poulain 
Cc: Peng Fan 
Cc: Simon Glass 
Cc: Takeshi Kihara 
---
 drivers/mmc/mmc.c | 16 
 include/mmc.h |  2 ++
 2 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 1af6af82e6b..68a76aa3e94 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -398,6 +398,17 @@ int mmc_send_tuning(struct mmc *mmc, u32 opcode, int 
*cmd_error)
 }
 #endif
 
+int mmc_send_stop_transmission(struct mmc *mmc)
+{
+   struct mmc_cmd cmd;
+
+   cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
+   cmd.cmdarg = 0;
+   cmd.resp_type = MMC_RSP_R1;
+
+   return mmc_send_cmd(mmc, , NULL);
+}
+
 static int mmc_read_blocks(struct mmc *mmc, void *dst, lbaint_t start,
   lbaint_t blkcnt)
 {
@@ -425,10 +436,7 @@ static int mmc_read_blocks(struct mmc *mmc, void *dst, 
lbaint_t start,
return 0;
 
if (blkcnt > 1) {
-   cmd.cmdidx = MMC_CMD_STOP_TRANSMISSION;
-   cmd.cmdarg = 0;
-   cmd.resp_type = MMC_RSP_R1b;
-   if (mmc_send_cmd(mmc, , NULL)) {
+   if (mmc_send_stop_transmission(mmc)) {
 #if !defined(CONFIG_SPL_BUILD) || defined(CONFIG_SPL_LIBCOMMON_SUPPORT)
pr_err("mmc fail to send stop cmd\n");
 #endif
diff --git a/include/mmc.h b/include/mmc.h
index b8fbff150de..a413dc2af4d 100644
--- a/include/mmc.h
+++ b/include/mmc.h
@@ -558,6 +558,8 @@ int mmc_deferred_probe(struct mmc *mmc);
 int mmc_reinit(struct mmc *mmc);
 int mmc_get_b_max(struct mmc *mmc, void *dst, lbaint_t blkcnt);
 int mmc_hs400_prepare_ddr(struct mmc *mmc);
+int mmc_send_stop_transmission(struct mmc *mmc);
+
 #else
 struct mmc_ops {
int (*send_cmd)(struct mmc *mmc,
-- 
2.39.2



[PATCH] mmc: Set clock when reverting to safe bus mode

2023-06-10 Thread Marek Vasut
From: Valentine Barshak 

Set MMC clock when reverting to safe bus mode and speed
in case current MMC mode fails. Otherwise, trying out
the other modes may fail as well.

Reviewed-by: Marek Vasut 
Signed-off-by: Valentine Barshak 
[hp: fallback to legacy_speed]
Signed-off-by: Hai Pham 
---
Cc: "Ying-Chun Liu (PaulLiu)" 
Cc: Hai Pham 
Cc: Jaehoon Chung 
Cc: Loic Poulain 
Cc: Peng Fan 
Cc: Simon Glass 
Cc: Takeshi Kihara 
---
 drivers/mmc/mmc.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/mmc/mmc.c b/drivers/mmc/mmc.c
index 68a76aa3e94..79d0d37c240 100644
--- a/drivers/mmc/mmc.c
+++ b/drivers/mmc/mmc.c
@@ -2231,6 +2231,7 @@ error:
mmc_switch(mmc, EXT_CSD_CMD_SET_NORMAL,
   EXT_CSD_BUS_WIDTH, EXT_CSD_BUS_WIDTH_1);
mmc_select_mode(mmc, MMC_LEGACY);
+   mmc_set_clock(mmc, mmc->legacy_speed, MMC_CLK_ENABLE);
mmc_set_bus_width(mmc, 1);
}
}
-- 
2.39.2



Re: [PATCH 0/6] Add the 'net stats' command to dump network statistics

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 4:19 AM Peng Fan  wrote:
>
> Hi Joe, Ramon
>
> I see this patchset is delegated to me, would you take care this
> patchset or let me handle?
>
> Thanks,
> Peng.
>
> On 5/23/2023 9:47 PM, Ioana Ciornei wrote:
>
> >
> >
> > This patch set extends the 'net' command so that it can be used to dump
> > network statistics on the available devices. The first user of this new
> > API is the ldpaa_eth driver which, in the last patch, implements the 3
> > new callbacks added.
> >
> > Since the ldpaa_eth driver already had some debug printing of counters,
> > the first 4 patches are there to extend the existing list of counters
> > and to reorganize the code so that it fits better with the new eth_ops
> > callbacks.
> >
> > Ioana Ciornei (6):
> >net: ldpaa_eth: fix the memory layout of the dpmac_get_counters() API
> >net: ldpaa_eth: transform dpni_statistics from a struct to a union
> >net: ldpaa_eth: extend debug capabilities with DPNI statistics
> >net: ldpaa_eth: extend debug capabilities with DPMAC statistics
> >cmd: net: add a 'net stats' command to dump network statistics
> >net: ldpaa_eth: export DPNI and DPMAC counters through 'net stats'
> >
> >   cmd/net.c |  54 ++-
> >   drivers/net/fsl-mc/dpni.c |   2 +-
> >   drivers/net/ldpaa_eth/ldpaa_eth.c | 248 +++---
> >   drivers/net/ldpaa_eth/ldpaa_eth.h |  64 
> >   include/fsl-mc/fsl_dpmac.h|   7 +-
> >   include/fsl-mc/fsl_dpni.h | 143 -
> >   include/net.h |   6 +
> >   7 files changed, 353 insertions(+), 171 deletions(-)
> >
> > --
> > 2.25.1
> >
Hi Peng, I reviewed everything.
Tom will pick this up.
Thanks,
Ramon


Re: [PATCH 14/14] net: sh_eth: Fix RX error handling

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> From: Valentine Barshak 
>
> In case RX error occurs, and the RD_RFE bit is set, the descriptor
> is never returned back to the queue. Make sh_eth_recv_start return
> zero length in this case so that the descriptor can be released
> and pushed back to the list. Also return the more appropriate
> -EAGAIN instead of -EINVAL if the descriptor is not ready yet.
>
> Signed-off-by: Valentine Barshak 
> Reviewed-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/sh_eth.c | 16 +++-
>  1 file changed, 7 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
> index 7314caadfdc..7b1f59dc498 100644
> --- a/drivers/net/sh_eth.c
> +++ b/drivers/net/sh_eth.c
> @@ -129,11 +129,11 @@ static int sh_eth_recv_start(struct sh_eth_dev *eth)
> /* Check if the rx descriptor is ready */
> invalidate_cache(port_info->rx_desc_cur, sizeof(struct rx_desc_s));
> if (port_info->rx_desc_cur->rd0 & RD_RACT)
> -   return -EINVAL;
> +   return -EAGAIN;
>
> /* Check for errors */
> if (port_info->rx_desc_cur->rd0 & RD_RFE)
> -   return -EINVAL;
> +   return 0;
>
> return port_info->rx_desc_cur->rd1 & 0x;
>  }
> @@ -556,15 +556,13 @@ static int sh_ether_recv(struct udevice *dev, int 
> flags, uchar **packetp)
> *packetp = packet;
>
> return len;
> -   } else {
> -   len = 0;
> +   }
>
> -   /* Restart the receiver if disabled */
> -   if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))
> -   sh_eth_write(port_info, EDRRR_R, EDRRR);
> +   /* Restart the receiver if disabled */
> +   if (!(sh_eth_read(port_info, EDRRR) & EDRRR_R))
> +   sh_eth_write(port_info, EDRRR_R, EDRRR);
>
> -   return -EAGAIN;
> -   }
> +   return len;
>  }
>
>  static int sh_ether_free_pkt(struct udevice *dev, uchar *packet, int length)
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 13/14] net: sh_eth: Workaround cache issues

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> From: Valentine Barshak 
>
> U-Boot writes to RX packets when constructing replies.
> This can cause stale cached data to be written to RX
> buffer while we're receiving a packet. This causes RX
> packet corruption because we invalidate the cache right
> before processing the packet. Invalidate packet buffer
> cache when preparing RX descriptor as well. This seems
> to fix RX packet drops with high RX traffic.
>
> While at it flush the descriptors right before enabling
> RX/TX in sh_eth_tx_desc_init/sh_eth_rx_desc_init callbacks
> when they are ready instead of flushing after allocation.
>
> Signed-off-by: Valentine Barshak 
> Reviewed-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/sh_eth.c | 10 ++
>  1 file changed, 6 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
> index 95042daade0..7314caadfdc 100644
> --- a/drivers/net/sh_eth.c
> +++ b/drivers/net/sh_eth.c
> @@ -142,6 +142,8 @@ static void sh_eth_recv_finish(struct sh_eth_dev *eth)
>  {
> struct sh_eth_info *port_info = >port_info[eth->port];
>
> +   invalidate_cache(ADDR_TO_P2(port_info->rx_desc_cur->rd2), 
> MAX_BUF_SIZE);
> +
> /* Make current descriptor available again */
> if (port_info->rx_desc_cur->rd0 & RD_RDLE)
> port_info->rx_desc_cur->rd0 = RD_RACT | RD_RDLE;
> @@ -210,8 +212,6 @@ static int sh_eth_tx_desc_init(struct sh_eth_dev *eth)
> goto err;
> }
>
> -   flush_cache_wback(port_info->tx_desc_alloc, alloc_desc_size);
> -
> /* Make sure we use a P2 address (non-cacheable) */
> port_info->tx_desc_base =
> (struct tx_desc_s 
> *)ADDR_TO_P2((uintptr_t)port_info->tx_desc_alloc);
> @@ -229,6 +229,7 @@ static int sh_eth_tx_desc_init(struct sh_eth_dev *eth)
> cur_tx_desc--;
> cur_tx_desc->td0 |= TD_TDLE;
>
> +   flush_cache_wback(port_info->tx_desc_alloc, alloc_desc_size);
> /*
>  * Point the controller to the tx descriptor list. Must use physical
>  * addresses
> @@ -264,8 +265,6 @@ static int sh_eth_rx_desc_init(struct sh_eth_dev *eth)
> goto err;
> }
>
> -   flush_cache_wback(port_info->rx_desc_alloc, alloc_desc_size);
> -
> /* Make sure we use a P2 address (non-cacheable) */
> port_info->rx_desc_base =
> (struct rx_desc_s 
> *)ADDR_TO_P2((uintptr_t)port_info->rx_desc_alloc);
> @@ -299,6 +298,9 @@ static int sh_eth_rx_desc_init(struct sh_eth_dev *eth)
> cur_rx_desc--;
> cur_rx_desc->rd0 |= RD_RDLE;
>
> +   invalidate_cache(port_info->rx_buf_alloc, NUM_RX_DESC * MAX_BUF_SIZE);
> +   flush_cache_wback(port_info->rx_desc_alloc, alloc_desc_size);
> +
> /* Point the controller to the rx descriptor list */
> sh_eth_write(port_info, ADDR_TO_PHY(port_info->rx_desc_base), RDLAR);
>  #if defined(SH_ETH_TYPE_GETHER) || defined(SH_ETH_TYPE_RZ)
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 12/14] net: sh_eth: Drop reset GPIO handling in favor of common code

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> The common code is now capable of handling reset GPIO associated
> with PHY. Drop the local ad-hoc code in favor of common code.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/Kconfig  |  1 +
>  drivers/net/sh_eth.c | 17 -
>  2 files changed, 1 insertion(+), 17 deletions(-)
>
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index 48f9efcc94f..7d482cb7745 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -695,6 +695,7 @@ config SUN8I_EMAC
>  config SH_ETHER
> bool "Renesas SH Ethernet MAC"
> select PHYLIB
> +   select PHY_ETHERNET_ID
> help
>   This driver supports the Ethernet for Renesas SH and ARM SoCs.
>
> diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
> index 14f7fd1bcc0..95042daade0 100644
> --- a/drivers/net/sh_eth.c
> +++ b/drivers/net/sh_eth.c
> @@ -530,7 +530,6 @@ struct sh_ether_priv {
> struct mii_dev  *bus;
> phys_addr_t iobase;
> struct clk  clk;
> -   struct gpio_descreset_gpio;
>  };
>
>  static int sh_ether_send(struct udevice *dev, void *packet, int len)
> @@ -650,7 +649,6 @@ static int sh_ether_probe(struct udevice *udev)
> struct eth_pdata *pdata = dev_get_plat(udev);
> struct sh_ether_priv *priv = dev_get_priv(udev);
> struct sh_eth_dev *eth = >shdev;
> -   struct ofnode_phandle_args phandle_args;
> struct mii_dev *mdiodev;
> int ret;
>
> @@ -661,18 +659,6 @@ static int sh_ether_probe(struct udevice *udev)
> if (ret < 0)
> return ret;
>  #endif
> -
> -   ret = dev_read_phandle_with_args(udev, "phy-handle", NULL, 0, 0, 
> _args);
> -   if (!ret) {
> -   gpio_request_by_name_nodev(phandle_args.node, "reset-gpios", 
> 0,
> -  >reset_gpio, GPIOD_IS_OUT);
> -   }
> -
> -   if (!dm_gpio_is_valid(>reset_gpio)) {
> -   gpio_request_by_name(udev, "reset-gpios", 0, 
> >reset_gpio,
> -GPIOD_IS_OUT);
> -   }
> -
> mdiodev = mdio_alloc();
> if (!mdiodev) {
> ret = -ENOMEM;
> @@ -735,9 +721,6 @@ static int sh_ether_remove(struct udevice *udev)
> mdio_unregister(priv->bus);
> mdio_free(priv->bus);
>
> -   if (dm_gpio_is_valid(>reset_gpio))
> -   dm_gpio_free(udev, >reset_gpio);
> -
> return 0;
>  }
>
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 11/14] net: ravb: Drop reset GPIO handling in favor of common code

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> The common code is now capable of handling reset GPIO associated
> with PHY. Drop the local ad-hoc code in favor of common code.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/Kconfig |  1 +
>  drivers/net/ravb.c  | 22 --
>  2 files changed, 1 insertion(+), 22 deletions(-)
>
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index 09039a283eb..48f9efcc94f 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -764,6 +764,7 @@ config RENESAS_RAVB
> bool "Renesas Ethernet AVB MAC"
> depends on RCAR_64
> select PHYLIB
> +   select PHY_ETHERNET_ID
> help
>   This driver implements support for the Ethernet AVB block in
>   Renesas M3 and H3 SoCs.
> diff --git a/drivers/net/ravb.c b/drivers/net/ravb.c
> index c74c8a81f94..0bcd6cfd3f3 100644
> --- a/drivers/net/ravb.c
> +++ b/drivers/net/ravb.c
> @@ -131,7 +131,6 @@ struct ravb_priv {
> struct mii_dev  *bus;
> void __iomem*iobase;
> struct clk_bulk clks;
> -   struct gpio_descreset_gpio;
>  };
>
>  static inline void ravb_flush_dcache(u32 addr, u32 len)
> @@ -312,13 +311,6 @@ static int ravb_phy_config(struct udevice *dev)
> struct phy_device *phydev;
> int reg;
>
> -   if (dm_gpio_is_valid(>reset_gpio)) {
> -   dm_gpio_set_value(>reset_gpio, 1);
> -   mdelay(20);
> -   dm_gpio_set_value(>reset_gpio, 0);
> -   mdelay(1);
> -   }
> -
> phydev = phy_connect(eth->bus, -1, dev, pdata->phy_interface);
> if (!phydev)
> return -ENODEV;
> @@ -503,7 +495,6 @@ static int ravb_probe(struct udevice *dev)
>  {
> struct eth_pdata *pdata = dev_get_plat(dev);
> struct ravb_priv *eth = dev_get_priv(dev);
> -   struct ofnode_phandle_args phandle_args;
> struct mii_dev *mdiodev;
> void __iomem *iobase;
> int ret;
> @@ -515,17 +506,6 @@ static int ravb_probe(struct udevice *dev)
> if (ret < 0)
> goto err_mdio_alloc;
>
> -   ret = dev_read_phandle_with_args(dev, "phy-handle", NULL, 0, 0, 
> _args);
> -   if (!ret) {
> -   gpio_request_by_name_nodev(phandle_args.node, "reset-gpios", 
> 0,
> -  >reset_gpio, GPIOD_IS_OUT);
> -   }
> -
> -   if (!dm_gpio_is_valid(>reset_gpio)) {
> -   gpio_request_by_name(dev, "reset-gpios", 0, >reset_gpio,
> -GPIOD_IS_OUT);
> -   }
> -
> mdiodev = mdio_alloc();
> if (!mdiodev) {
> ret = -ENOMEM;
> @@ -576,8 +556,6 @@ static int ravb_remove(struct udevice *dev)
> free(eth->phydev);
> mdio_unregister(eth->bus);
> mdio_free(eth->bus);
> -   if (dm_gpio_is_valid(>reset_gpio))
> -   dm_gpio_free(dev, >reset_gpio);
> unmap_physmem(eth->iobase, MAP_NOCACHE);
>
> return 0;
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 10/14] net: phy: Handle reset-delay-us/reset-post-delay-us properties

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> These two properties are used by various DTs in place of
> current reset-assert-us/reset-deassert-us , handle both .
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/eth-phy-uclass.c | 8 
>  1 file changed, 8 insertions(+)
>
> diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c
> index 231bad66514..9d1e8d38ffa 100644
> --- a/drivers/net/eth-phy-uclass.c
> +++ b/drivers/net/eth-phy-uclass.c
> @@ -144,6 +144,14 @@ static int eth_phy_of_to_plat(struct udevice *dev)
> uc_priv->reset_assert_delay = dev_read_u32_default(dev, 
> "reset-assert-us", 0);
> uc_priv->reset_deassert_delay = dev_read_u32_default(dev, 
> "reset-deassert-us", 0);
>
> +   /* These are used by some DTs, try these as a fallback. */
> +   if (!uc_priv->reset_assert_delay && !uc_priv->reset_deassert_delay) {
> +   uc_priv->reset_assert_delay =
> +   dev_read_u32_default(dev, "reset-delay-us", 0);
> +   uc_priv->reset_deassert_delay =
> +   dev_read_u32_default(dev, "reset-post-delay-us", 0);
> +   }
> +
> return 0;
>  }
>
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 09/14] net: phy: Bind ETH_PHY uclass driver to each new PHY

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> In case a new PHY is created and DM_ETH_PHY is enabled, bind a
> generic PHY driver from ETH_PHY uclass to the PHY to have a
> matching DM representation of that PHY.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/phy/ethernet_id.c | 17 +
>  1 file changed, 17 insertions(+)
>
> diff --git a/drivers/net/phy/ethernet_id.c b/drivers/net/phy/ethernet_id.c
> index a715e83db98..877a51c3d00 100644
> --- a/drivers/net/phy/ethernet_id.c
> +++ b/drivers/net/phy/ethernet_id.c
> @@ -7,6 +7,8 @@
>
>  #include 
>  #include 
> +#include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -17,6 +19,8 @@ struct phy_device *phy_connect_phy_id(struct mii_dev *bus, 
> struct udevice *dev,
> struct phy_device *phydev;
> struct ofnode_phandle_args phandle_args;
> struct gpio_desc gpio;
> +   const char *node_name;
> +   struct udevice *pdev;
> ofnode node;
> u32 id, assert, deassert;
> u16 vendor, device;
> @@ -72,5 +76,18 @@ struct phy_device *phy_connect_phy_id(struct mii_dev *bus, 
> struct udevice *dev,
> if (phydev)
> phydev->node = node;
>
> +   if (IS_ENABLED(CONFIG_DM_ETH_PHY) && ofnode_valid(node)) {
> +   node_name = ofnode_get_name(node);
> +   ret = device_bind_driver_to_node(dev, "eth_phy_generic_drv",
> +node_name, node,
> +);
> +   if (ret)
> +   return NULL;
> +
> +   ret = device_probe(pdev);
> +   if (ret)
> +   return NULL;
> +   }
> +
> return phydev;
>  }
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 08/14] net: phy: Unpublish phy_connect_dev()

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> The phy_connect_dev() is legacy API, now that there are no users,
> make it internal to phy.c and unpublish it from headers.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/phy/phy.c | 4 ++--
>  include/phy.h | 9 -
>  2 files changed, 2 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/net/phy/phy.c b/drivers/net/phy/phy.c
> index 0eeb0cb3a85..ae21acb059b 100644
> --- a/drivers/net/phy/phy.c
> +++ b/drivers/net/phy/phy.c
> @@ -812,8 +812,8 @@ struct phy_device *phy_find_by_mask(struct mii_dev *bus, 
> uint phy_mask)
> return get_phy_device_by_mask(bus, phy_mask);
>  }
>
> -void phy_connect_dev(struct phy_device *phydev, struct udevice *dev,
> -phy_interface_t interface)
> +static void phy_connect_dev(struct phy_device *phydev, struct udevice *dev,
> +   phy_interface_t interface)
>  {
> /* Soft Reset the PHY */
> phy_reset(phydev);
> diff --git a/include/phy.h b/include/phy.h
> index 247223d92be..f023a3c2685 100644
> --- a/include/phy.h
> +++ b/include/phy.h
> @@ -223,15 +223,6 @@ static inline struct phy_device *fixed_phy_create(ofnode 
> node)
>
>  #endif
>
> -/**
> - * phy_connect_dev() - Associates the given pair of PHY and Ethernet devices
> - * @phydev:PHY device
> - * @dev:   Ethernet device
> - * @interface: type of MAC-PHY interface
> - */
> -void phy_connect_dev(struct phy_device *phydev, struct udevice *dev,
> -phy_interface_t interface);
> -
>  /**
>   * phy_connect() - Creates a PHY device for the Ethernet interface
>   * Creates a PHY device for the PHY at the given address, if one doesn't 
> exist
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 07/14] net: sunxi_emac: Switch to new U-Boot PHY API

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> Use new U-Boot phy_connect() API which also supports fixed PHYs.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/sunxi_emac.c | 7 +++
>  1 file changed, 3 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/sunxi_emac.c b/drivers/net/sunxi_emac.c
> index ad9e1abd161..4c90d4b4981 100644
> --- a/drivers/net/sunxi_emac.c
> +++ b/drivers/net/sunxi_emac.c
> @@ -248,10 +248,10 @@ static int emac_mdio_write(struct mii_dev *bus, int 
> addr, int devad, int reg,
>
>  static int sunxi_emac_init_phy(struct emac_eth_dev *priv, void *dev)
>  {
> -   int ret, mask = 0x;
> +   int ret, mask = -1;
>
>  #ifdef CONFIG_PHY_ADDR
> -   mask = 1 << CONFIG_PHY_ADDR;
> +   mask = CONFIG_PHY_ADDR;
>  #endif
>
> priv->bus = mdio_alloc();
> @@ -269,11 +269,10 @@ static int sunxi_emac_init_phy(struct emac_eth_dev 
> *priv, void *dev)
> if (ret)
> return ret;
>
> -   priv->phydev = phy_find_by_mask(priv->bus, mask);
> +   priv->phydev = phy_connect(priv->bus, mask, dev, 
> PHY_INTERFACE_MODE_MII);
> if (!priv->phydev)
> return -ENODEV;
>
> -   phy_connect_dev(priv->phydev, dev, PHY_INTERFACE_MODE_MII);
> phy_config(priv->phydev);
>
> return 0;
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 06/14] net: sh_eth: Switch to new U-Boot PHY API

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> Use new U-Boot phy_connect() API which also supports fixed PHYs.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/sh_eth.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/net/sh_eth.c b/drivers/net/sh_eth.c
> index 8f162ca58fb..14f7fd1bcc0 100644
> --- a/drivers/net/sh_eth.c
> +++ b/drivers/net/sh_eth.c
> @@ -601,14 +601,11 @@ static int sh_eth_phy_config(struct udevice *dev)
> int ret = 0;
> struct sh_eth_info *port_info = >port_info[eth->port];
> struct phy_device *phydev;
> -   int mask = 0x;
>
> -   phydev = phy_find_by_mask(priv->bus, mask);
> +   phydev = phy_connect(priv->bus, -1, dev, pdata->phy_interface);
> if (!phydev)
> return -ENODEV;
>
> -   phy_connect_dev(phydev, dev, pdata->phy_interface);
> -
> port_info->phydev = phydev;
> phy_config(phydev);
>
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 05/14] net: pch_gbe: Switch to new U-Boot PHY API

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> Use new U-Boot phy_connect() API which also supports fixed PHYs.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/pch_gbe.c | 5 +
>  1 file changed, 1 insertion(+), 4 deletions(-)
>
> diff --git a/drivers/net/pch_gbe.c b/drivers/net/pch_gbe.c
> index ad7b5b8e99b..ecf8c28fe41 100644
> --- a/drivers/net/pch_gbe.c
> +++ b/drivers/net/pch_gbe.c
> @@ -414,16 +414,13 @@ static int pch_gbe_phy_init(struct udevice *dev)
> struct pch_gbe_priv *priv = dev_get_priv(dev);
> struct eth_pdata *plat = dev_get_plat(dev);
> struct phy_device *phydev;
> -   int mask = 0x;
>
> -   phydev = phy_find_by_mask(priv->bus, mask);
> +   phydev = phy_connect(priv->bus, -1, dev, plat->phy_interface);
> if (!phydev) {
> printf("pch_gbe: cannot find the phy\n");
> return -1;
> }
>
> -   phy_connect_dev(phydev, dev, plat->phy_interface);
> -
> phydev->supported &= PHY_GBIT_FEATURES;
> phydev->advertising = phydev->supported;
>
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 04/14] net: ethoc: Switch to new U-Boot PHY API

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> Use new U-Boot phy_connect() API which also supports fixed PHYs.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/ethoc.c | 8 +++-
>  1 file changed, 3 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/net/ethoc.c b/drivers/net/ethoc.c
> index 29067e9e949..13fad8119bb 100644
> --- a/drivers/net/ethoc.c
> +++ b/drivers/net/ethoc.c
> @@ -608,18 +608,16 @@ static int ethoc_mdio_init(const char *name, struct 
> ethoc *priv)
>  static int ethoc_phy_init(struct ethoc *priv, void *dev)
>  {
> struct phy_device *phydev;
> -   int mask = 0x;
> +   int mask = -1;
>
>  #ifdef CONFIG_PHY_ADDR
> -   mask = 1 << CONFIG_PHY_ADDR;
> +   mask = CONFIG_PHY_ADDR;
>  #endif
>
> -   phydev = phy_find_by_mask(priv->bus, mask);
> +   phydev = phy_connect(priv->bus, mask, dev, PHY_INTERFACE_MODE_MII);
> if (!phydev)
> return -ENODEV;
>
> -   phy_connect_dev(phydev, dev, PHY_INTERFACE_MODE_MII);
> -
> phydev->supported &= PHY_BASIC_FEATURES;
> phydev->advertising = phydev->supported;
>
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 03/14] net: ave: Switch to new U-Boot PHY API

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> Use new U-Boot phy_connect() API which also supports fixed PHYs.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/sni_ave.c | 6 ++
>  1 file changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/sni_ave.c b/drivers/net/sni_ave.c
> index 014b070d9e5..f5a0d80af7a 100644
> --- a/drivers/net/sni_ave.c
> +++ b/drivers/net/sni_ave.c
> @@ -391,14 +391,12 @@ static int ave_mdiobus_init(struct ave_private *priv, 
> const char *name)
>  static int ave_phy_init(struct ave_private *priv, void *dev)
>  {
> struct phy_device *phydev;
> -   int mask = GENMASK(31, 0), ret;
> +   int ret;
>
> -   phydev = phy_find_by_mask(priv->bus, mask);
> +   phydev = phy_connect(priv->bus, -1, dev, priv->phy_mode);
> if (!phydev)
> return -ENODEV;
>
> -   phy_connect_dev(phydev, dev, priv->phy_mode);
> -
> phydev->supported &= PHY_GBIT_FEATURES;
> if (priv->max_speed) {
> ret = phy_set_supported(phydev, priv->max_speed);
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 02/14] net: altera_tsa: Switch to new U-Boot PHY API

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> Use new U-Boot phy_connect() API which also supports fixed PHYs.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/altera_tse.c | 8 +---
>  1 file changed, 1 insertion(+), 7 deletions(-)
>
> diff --git a/drivers/net/altera_tse.c b/drivers/net/altera_tse.c
> index 912d28fca2e..e2340936fa6 100644
> --- a/drivers/net/altera_tse.c
> +++ b/drivers/net/altera_tse.c
> @@ -430,17 +430,11 @@ static int tse_mdio_init(const char *name, struct 
> altera_tse_priv *priv)
>  static int tse_phy_init(struct altera_tse_priv *priv, void *dev)
>  {
> struct phy_device *phydev;
> -   unsigned int mask = 0x;
>
> -   if (priv->phyaddr)
> -   mask = 1 << priv->phyaddr;
> -
> -   phydev = phy_find_by_mask(priv->bus, mask);
> +   phydev = phy_connect(priv->bus, -1, dev, priv->interface);
> if (!phydev)
> return -ENODEV;
>
> -   phy_connect_dev(phydev, dev, priv->interface);
> -
> phydev->supported &= PHY_GBIT_FEATURES;
> phydev->advertising = phydev->supported;
>
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 01/14] net: eth-phy: staticize eth_phy_reset()

2023-06-10 Thread Ramon Fried
On Wed, May 31, 2023 at 1:51 AM Marek Vasut
 wrote:
>
> The eth_phy_reset() is not used outside of this file, staticize it.
> No functional change.
>
> Signed-off-by: Marek Vasut 
> ---
> Cc: Geert Uytterhoeven 
> Cc: Joe Hershberger 
> Cc: Michal Simek 
> Cc: Nishanth Menon 
> Cc: Ramon Fried 
> ---
>  drivers/net/eth-phy-uclass.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/net/eth-phy-uclass.c b/drivers/net/eth-phy-uclass.c
> index 27b77444a0c..231bad66514 100644
> --- a/drivers/net/eth-phy-uclass.c
> +++ b/drivers/net/eth-phy-uclass.c
> @@ -147,7 +147,7 @@ static int eth_phy_of_to_plat(struct udevice *dev)
> return 0;
>  }
>
> -void eth_phy_reset(struct udevice *dev, int value)
> +static void eth_phy_reset(struct udevice *dev, int value)
>  {
> struct eth_phy_device_priv *uc_priv = dev_get_uclass_priv(dev);
> u32 delay;
> --
> 2.39.2
>
Reviewed-by: Ramon Fried 


Re: [PATCH 6/6] net: ldpaa_eth: export DPNI and DPMAC counters through 'net stats'

2023-06-10 Thread Ramon Fried
On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei  wrote:
>
> Export the already existing DPNI and DPMAC counters through the newly
> added callbacks.
>
> Signed-off-by: Ioana Ciornei 
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 44 ---
>  1 file changed, 40 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c 
> b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 53c5b8ba2b1d..8c0b5a3b6fd2 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -998,11 +998,47 @@ static int ldpaa_eth_of_to_plat(struct udevice *dev)
> return 0;
>  }
>
> +static int ldpaa_eth_get_sset_count(struct udevice *dev)
> +{
> +   return LDPAA_ETH_DPNI_NUM_STATS + LDPAA_ETH_DPMAC_NUM_STATS;
> +}
> +
> +static void ldpaa_eth_get_strings(struct udevice *dev, u8 *data)
> +{
> +   u8 *p = data;
> +   int i;
> +
> +   for (i = 0; i < LDPAA_ETH_DPNI_NUM_STATS; i++) {
> +   strlcpy(p, ldpaa_eth_dpni_stat_strings[i], ETH_GSTRING_LEN);
> +   p += ETH_GSTRING_LEN;
> +   }
> +
> +   for (i = 0; i < LDPAA_ETH_DPMAC_NUM_STATS; i++) {
> +   strlcpy(p, ldpaa_eth_dpmac_stat_strings[i], ETH_GSTRING_LEN);
> +   p += ETH_GSTRING_LEN;
> +   }
> +}
> +
> +static void ldpaa_eth_get_stats(struct udevice *dev, u64 *data)
> +{
> +   struct ldpaa_eth_priv *priv = dev_get_priv(dev);
> +   int i, j = 0;
> +
> +   for (i = 0; i < LDPAA_ETH_DPNI_NUM_STATS; i++)
> +   *(data + j++) = priv->dpni_stats[i];
> +
> +   for (i = 0; i < LDPAA_ETH_DPMAC_NUM_STATS; i++)
> +   *(data + j++) = priv->dpmac_stats[i];
> +}
> +
>  static const struct eth_ops ldpaa_eth_ops = {
> -   .start  = ldpaa_eth_open,
> -   .send   = ldpaa_eth_tx,
> -   .recv   = ldpaa_eth_pull_dequeue_rx,
> -   .stop   = ldpaa_eth_stop,
> +   .start = ldpaa_eth_open,
> +   .send = ldpaa_eth_tx,
> +   .recv = ldpaa_eth_pull_dequeue_rx,
> +   .stop = ldpaa_eth_stop,
> +   .get_sset_count = ldpaa_eth_get_sset_count,
> +   .get_strings = ldpaa_eth_get_strings,
> +   .get_stats = ldpaa_eth_get_stats,
>  };
>
>  static const struct udevice_id ldpaa_eth_of_ids[] = {
> --
> 2.25.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH 5/6] cmd: net: add a 'net stats' command to dump network statistics

2023-06-10 Thread Ramon Fried
On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei  wrote:
>
> Add a new option to the 'net' command which can be used to dump network
> statistics.
>
> To do this, 3 new callbacks are added to the eth_ops structure:
> .get_sset_count(), .get_strings(), .get_stats(). These callbacks
> have the same functions as in Linux: to return the number of counters,
> the strings which describe those counters and the actual values.
>
> Signed-off-by: Ioana Ciornei 
> ---
>  cmd/net.c | 54 ++-
>  include/net.h |  6 ++
>  2 files changed, 59 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/net.c b/cmd/net.c
> index 68d406291ef1..dfe811f41acf 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -13,6 +13,7 @@
>  #include 
>  #include 
>  #include 
> +#include 
>  #include 
>  #include 
>  #include 
> @@ -691,8 +692,58 @@ static int do_net_list(struct cmd_tbl *cmdtp, int flag, 
> int argc, char *const ar
> return CMD_RET_SUCCESS;
>  }
>
> +static int do_net_stats(struct cmd_tbl *cmdtp, int flag, int argc, char 
> *const argv[])
> +{
> +   int nstats, err, i, off;
> +   struct udevice *dev;
> +   u64 *values;
> +   u8 *strings;
> +
> +   if (argc < 2)
> +   return CMD_RET_USAGE;
> +
> +   err = uclass_get_device_by_name(UCLASS_ETH, argv[1], );
> +   if (err) {
> +   printf("Could not find device %s\n", argv[1]);
> +   return CMD_RET_FAILURE;
> +   }
> +
> +   if (!eth_get_ops(dev)->get_sset_count ||
> +   !eth_get_ops(dev)->get_strings ||
> +   !eth_get_ops(dev)->get_stats) {
> +   printf("Driver does not implement stats dump!\n");
> +   return CMD_RET_FAILURE;
> +   }
> +
> +   nstats = eth_get_ops(dev)->get_sset_count(dev);
> +   strings = kcalloc(nstats, ETH_GSTRING_LEN, GFP_KERNEL);
> +   if (!strings)
> +   return CMD_RET_FAILURE;
> +
> +   values = kcalloc(nstats, sizeof(u64), GFP_KERNEL);
> +   if (!values)
> +   goto err_free_strings;
> +
> +   eth_get_ops(dev)->get_strings(dev, strings);
> +   eth_get_ops(dev)->get_stats(dev, values);
> +
> +   off = 0;
> +   for (i = 0; i < nstats; i++) {
> +   printf("  %s: %llu\n", [off], values[i]);
> +   off += ETH_GSTRING_LEN;
> +   };
> +
> +   return CMD_RET_SUCCESS;
> +
> +err_free_strings:
> +   kfree(strings);
> +
> +   return CMD_RET_FAILURE;
> +}
> +
>  static struct cmd_tbl cmd_net[] = {
> U_BOOT_CMD_MKENT(list, 1, 0, do_net_list, "", ""),
> +   U_BOOT_CMD_MKENT(stats, 2, 0, do_net_stats, "", ""),
>  };
>
>  static int do_net(struct cmd_tbl *cmdtp, int flag, int argc, char *const 
> argv[])
> @@ -714,9 +765,10 @@ static int do_net(struct cmd_tbl *cmdtp, int flag, int 
> argc, char *const argv[])
>  }
>
>  U_BOOT_CMD(
> -   net, 2, 1, do_net,
> +   net, 3, 1, do_net,
> "NET sub-system",
> "list - list available devices\n"
> +   "stats  - dump statistics for specified device\n"
>  );
>
>  #if defined(CONFIG_CMD_NCSI)
> diff --git a/include/net.h b/include/net.h
> index 785cb1059ef9..e254df7d7f43 100644
> --- a/include/net.h
> +++ b/include/net.h
> @@ -167,6 +167,9 @@ enum eth_recv_flags {
>   * to the network stack. This function should fill in the
>   * eth_pdata::enetaddr field - optional
>   * set_promisc: Enable or Disable promiscuous mode
> + * get_sset_count: Number of statistics counters
> + * get_string: Names of the statistic counters
> + * get_stats: The values of the statistic counters
>   */
>  struct eth_ops {
> int (*start)(struct udevice *dev);
> @@ -178,6 +181,9 @@ struct eth_ops {
> int (*write_hwaddr)(struct udevice *dev);
> int (*read_rom_hwaddr)(struct udevice *dev);
> int (*set_promisc)(struct udevice *dev, bool enable);
> +   int (*get_sset_count)(struct udevice *dev);
> +   void (*get_strings)(struct udevice *dev, u8 *data);
> +   void (*get_stats)(struct udevice *dev, u64 *data);
>  };
>
>  #define eth_get_ops(dev) ((struct eth_ops *)(dev)->driver->ops)
> --
> 2.25.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH 4/6] net: ldpaa_eth: extend debug capabilities with DPMAC statistics

2023-06-10 Thread Ramon Fried
On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei  wrote:
>
> The ldpaa_eth driver already had a DPMAC statistics dump, this patch
> extends the list of stats and adds a bit more structure to the code.
>
> For a bit more context, the DPAA2 u-boot software architecture uses a
> default network interface object - a DPNI - which, at runtime, will get
> connected to the currently used DPMAC object.
> Each time the .stop() eth callback is called, the DPMAC is destroyed
> thus any previous counters will get lost.
>
> As a preparation for the next patches, we add a software kept set of
> DPMAC counters which will get updated before each destroy operation
> takes place.
>
> Signed-off-by: Ioana Ciornei 
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 114 ++
>  drivers/net/ldpaa_eth/ldpaa_eth.h |  34 +
>  include/fsl-mc/fsl_dpmac.h|   5 +-
>  3 files changed, 76 insertions(+), 77 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c 
> b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 907e51da6e1e..53c5b8ba2b1d 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -79,8 +79,33 @@ static void ldpaa_eth_add_dpni_stats(struct udevice *dev, 
> u64 *data)
> priv->dpni_stats[i] += data[i];
>  }
>
> -#ifdef DEBUG
> +static void ldpaa_eth_collect_dpmac_stats(struct udevice *dev, u64 *data)
> +{
> +   struct ldpaa_eth_priv *priv = dev_get_priv(dev);
> +   int err, i;
> +   u64 value;
>
> +   for (i = 0; i < LDPAA_ETH_DPMAC_NUM_STATS; i++) {
> +   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> +   priv->dpmac_handle, i,
> +   );
> +   if (err)
> +   printf("dpmac_get_counter(%d) failed\n", i);
> +
> +   *(data + i) = value;
> +   }
> +}
> +
> +static void ldpaa_eth_add_dpmac_stats(struct udevice *dev, u64 *data)
> +{
> +   struct ldpaa_eth_priv *priv = dev_get_priv(dev);
> +   int i;
> +
> +   for (i = 0; i < LDPAA_ETH_DPMAC_NUM_STATS; i++)
> +   priv->dpmac_stats[i] += data[i];
> +}
> +
> +#ifdef DEBUG
>  static void ldpaa_eth_dump_dpni_stats(struct udevice *dev, u64 *data)
>  {
> int i;
> @@ -90,82 +115,13 @@ static void ldpaa_eth_dump_dpni_stats(struct udevice 
> *dev, u64 *data)
> printf("  %s: %llu\n", ldpaa_eth_dpni_stat_strings[i], 
> data[i]);
>  }
>
> -static void ldpaa_eth_get_dpmac_counter(struct udevice *dev)
> +static void ldpaa_eth_dump_dpmac_stats(struct udevice *dev, u64 *data)
>  {
> -   struct ldpaa_eth_priv *priv = dev_get_priv(dev);
> -   int err = 0;
> -   u64 value;
> -
> -   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> -priv->dpmac_handle,
> -DPMAC_CNT_ING_BYTE,
> -);
> -   if (err < 0) {
> -   printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
> -   return;
> -   }
> -   printf("\nDPMAC counters ..\n");
> -   printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
> -
> -   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> -priv->dpmac_handle,
> -DPMAC_CNT_ING_FRAME_DISCARD,
> -);
> -   if (err < 0) {
> -   printf("dpmac_get_counter: DPMAC_CNT_ING_FRAME_DISCARD 
> failed\n");
> -   return;
> -   }
> -   printf("DPMAC_CNT_ING_FRAME_DISCARD=%lld\n", value);
> -
> -   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> -priv->dpmac_handle,
> -DPMAC_CNT_ING_ALIGN_ERR,
> -);
> -   if (err < 0) {
> -   printf("dpmac_get_counter: DPMAC_CNT_ING_ALIGN_ERR failed\n");
> -   return;
> -   }
> -   printf("DPMAC_CNT_ING_ALIGN_ERR =%lld\n", value);
> -
> -   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> -priv->dpmac_handle,
> -DPMAC_CNT_ING_BYTE,
> -);
> -   if (err < 0) {
> -   printf("dpmac_get_counter: DPMAC_CNT_ING_BYTE failed\n");
> -   return;
> -   }
> -   printf("DPMAC_CNT_ING_BYTE=%lld\n", value);
> -
> -   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> -priv->dpmac_handle,
> -DPMAC_CNT_ING_ERR_FRAME,
> -);
> -   if (err < 0) {
> -   printf("dpmac_get_counter: DPMAC_CNT_ING_ERR_FRAME failed\n");
> -   return;
> -   }
> -   printf("DPMAC_CNT_ING_ERR_FRAME=%lld\n", value);
> -
> -   err = dpmac_get_counter(dflt_mc_io, MC_CMD_NO_FLAGS,
> -priv->dpmac_handle,
> -DPMAC_CNT_EGR_BYTE ,
> -);
> -   if (err < 0) {
> -   printf("dpmac_get_counter: DPMAC_CNT_EGR_BYTE failed\n");
> -   return;

Re: [PATCH 3/6] net: ldpaa_eth: extend debug capabilities with DPNI statistics

2023-06-10 Thread Ramon Fried
On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei  wrote:
>
> The ldpaa_eth driver already had a DPNI statistics dump, this patch
> extends the list of stats and adds a bit more structure to the code.
>
> For a bit more context, the DPAA2 u-boot software architecture uses a
> default network interface object - a DPNI - which, at runtime, will get
> connected to the currently used DPMAC object.
> Each time the .stop() eth callback is called, the DPNI is reset to its
> original state, including its counters.
>
> As a preparation for the next patches, we add a software kept set of
> DPNI counters which will get updated before each reset operation takes
> place.
>
> Signed-off-by: Ioana Ciornei 
> ---
>  drivers/net/ldpaa_eth/ldpaa_eth.c | 106 +++---
>  drivers/net/ldpaa_eth/ldpaa_eth.h |  30 +
>  2 files changed, 82 insertions(+), 54 deletions(-)
>
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c 
> b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index fe901baf5a4e..907e51da6e1e 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -38,68 +38,56 @@ static void init_phy(struct udevice *dev)
>  }
>  #endif
>
> -#ifdef DEBUG
> +static void ldpaa_eth_collect_dpni_stats(struct udevice *dev, u64 *data)
> +{
> +   union dpni_statistics dpni_stats;
> +   int dpni_stats_page_size[DPNI_STATISTICS_CNT] = {
> +   sizeof(dpni_stats.page_0),
> +   sizeof(dpni_stats.page_1),
> +   sizeof(dpni_stats.page_2),
> +   sizeof(dpni_stats.page_3),
> +   sizeof(dpni_stats.page_4),
> +   sizeof(dpni_stats.page_5),
> +   sizeof(dpni_stats.page_6),
> +   };
> +   int j, k, num_cnt, err, i = 0;
>
> -#define DPNI_STATS_PER_PAGE 6
> -
> -static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = {
> -   {
> -   "DPNI_CNT_ING_ALL_FRAMES",
> -   "DPNI_CNT_ING_ALL_BYTES",
> -   "DPNI_CNT_ING_MCAST_FRAMES",
> -   "DPNI_CNT_ING_MCAST_BYTES",
> -   "DPNI_CNT_ING_BCAST_FRAMES",
> -   "DPNI_CNT_ING_BCAST_BYTES",
> -   }, {
> -   "DPNI_CNT_EGR_ALL_FRAMES",
> -   "DPNI_CNT_EGR_ALL_BYTES",
> -   "DPNI_CNT_EGR_MCAST_FRAMES",
> -   "DPNI_CNT_EGR_MCAST_BYTES",
> -   "DPNI_CNT_EGR_BCAST_FRAMES",
> -   "DPNI_CNT_EGR_BCAST_BYTES",
> -   }, {
> -   "DPNI_CNT_ING_FILTERED_FRAMES",
> -   "DPNI_CNT_ING_DISCARDED_FRAMES",
> -   "DPNI_CNT_ING_NOBUFFER_DISCARDS",
> -   "DPNI_CNT_EGR_DISCARDED_FRAMES",
> -   "DPNI_CNT_EGR_CNF_FRAMES",
> -   ""
> -   },
> -};
> +   for (j = 0; j <= 6; j++) {
> +   /* We're not interested in pages 4 & 5 for now */
> +   if (j == 4 || j == 5)
> +   continue;
> +   err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
> + dflt_dpni->dpni_handle,
> + j, _stats);
> +   if (err) {
> +   memset(_stats, 0, sizeof(dpni_stats));
> +   printf("dpni_get_stats(%d) failed\n", j);
> +   }
> +
> +   num_cnt = dpni_stats_page_size[j] / sizeof(u64);
> +   for (k = 0; k < num_cnt; k++)
> +   *(data + i++) = dpni_stats.raw.counter[k];
> +   }
> +}
>
> -static void print_dpni_stats(const char *strings[],
> -union dpni_statistics dpni_stats)
> +static void ldpaa_eth_add_dpni_stats(struct udevice *dev, u64 *data)
>  {
> -   uint64_t *stat;
> +   struct ldpaa_eth_priv *priv = dev_get_priv(dev);
> int i;
>
> -   stat = (uint64_t *)_stats;
> -   for (i = 0; i < DPNI_STATS_PER_PAGE; i++) {
> -   if (strcmp(strings[i], "\0") == 0)
> -   break;
> -   printf("%s= %llu\n", strings[i], *stat);
> -   stat++;
> -   }
> +   for (i = 0; i < LDPAA_ETH_DPNI_NUM_STATS; i++)
> +   priv->dpni_stats[i] += data[i];
>  }
>
> -static void ldpaa_eth_get_dpni_counter(void)
> +#ifdef DEBUG
> +
> +static void ldpaa_eth_dump_dpni_stats(struct udevice *dev, u64 *data)
>  {
> -   int err = 0;
> -   unsigned int page = 0;
> -   union dpni_statistics dpni_stats;
> +   int i;
>
> -   printf("DPNI counters ..\n");
> -   for (page = 0; page < 3; page++) {
> -   err = dpni_get_statistics(dflt_mc_io, MC_CMD_NO_FLAGS,
> - dflt_dpni->dpni_handle, page,
> - _stats);
> -   if (err < 0) {
> -   printf("dpni_get_statistics: failed:");
> -   printf("%d for page[%d]\n", err, page);
> -   return;
> -   }
> -   print_dpni_stats(dpni_statistics[page], dpni_stats);
> -   }
> +   printf("DPNI counters:\n");
> +   for (i = 0; i < LDPAA_ETH_DPNI_NUM_STATS; i++)
> + 

Re: [PATCH 2/6] net: ldpaa_eth: transform dpni_statistics from a struct to a union

2023-06-10 Thread Ramon Fried
On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei  wrote:
>
> In order to simplify code, dpni_statistics can be written as a union.
> Using the raw accessors we can just loop through all the statistics from
> a page without trying to access each an every one independently.
> Make this change to a union.
>
> Signed-off-by: Ioana Ciornei 
> ---
>  drivers/net/fsl-mc/dpni.c |   2 +-
>  drivers/net/ldpaa_eth/ldpaa_eth.c |   4 +-
>  include/fsl-mc/fsl_dpni.h | 143 +-
>  3 files changed, 105 insertions(+), 44 deletions(-)
>
> diff --git a/drivers/net/fsl-mc/dpni.c b/drivers/net/fsl-mc/dpni.c
> index 5290be20c85e..a31abbff71b9 100644
> --- a/drivers/net/fsl-mc/dpni.c
> +++ b/drivers/net/fsl-mc/dpni.c
> @@ -491,7 +491,7 @@ int dpni_get_statistics(struct fsl_mc_io *mc_io,
> uint32_t cmd_flags,
> uint16_t token,
> uint8_t  page,
> -   struct dpni_statistics *stat)
> +   union dpni_statistics *stat)
>  {
> struct mc_command cmd = { 0 };
> int err;
> diff --git a/drivers/net/ldpaa_eth/ldpaa_eth.c 
> b/drivers/net/ldpaa_eth/ldpaa_eth.c
> index 2cb6e9b7d705..fe901baf5a4e 100644
> --- a/drivers/net/ldpaa_eth/ldpaa_eth.c
> +++ b/drivers/net/ldpaa_eth/ldpaa_eth.c
> @@ -68,7 +68,7 @@ static const char *dpni_statistics[][DPNI_STATS_PER_PAGE] = 
> {
>  };
>
>  static void print_dpni_stats(const char *strings[],
> -struct dpni_statistics dpni_stats)
> +union dpni_statistics dpni_stats)
>  {
> uint64_t *stat;
> int i;
> @@ -86,7 +86,7 @@ static void ldpaa_eth_get_dpni_counter(void)
>  {
> int err = 0;
> unsigned int page = 0;
> -   struct dpni_statistics dpni_stats;
> +   union dpni_statistics dpni_stats;
>
> printf("DPNI counters ..\n");
> for (page = 0; page < 3; page++) {
> diff --git a/include/fsl-mc/fsl_dpni.h b/include/fsl-mc/fsl_dpni.h
> index e5e7338192f6..fc57c375ac14 100644
> --- a/include/fsl-mc/fsl_dpni.h
> +++ b/include/fsl-mc/fsl_dpni.h
> @@ -258,13 +258,13 @@ do { \
>  /*cmd, param, offset, width, type, arg_name */
>  #define DPNI_RSP_GET_STATISTICS(cmd, stat) \
>  do { \
> -   MC_RSP_OP(cmd, 0, 0, 64, uint64_t, (stat)->counter0); \
> -   MC_RSP_OP(cmd, 1, 0, 64, uint64_t, (stat)->counter1); \
> -   MC_RSP_OP(cmd, 2, 0, 64, uint64_t, (stat)->counter2); \
> -   MC_RSP_OP(cmd, 3, 0, 64, uint64_t, (stat)->counter3); \
> -   MC_RSP_OP(cmd, 4, 0, 64, uint64_t, (stat)->counter4); \
> -   MC_RSP_OP(cmd, 5, 0, 64, uint64_t, (stat)->counter5); \
> -   MC_RSP_OP(cmd, 6, 0, 64, uint64_t, (stat)->counter6); \
> +   MC_RSP_OP(cmd, 0, 0, 64, uint64_t, (stat)->raw.counter[0]); \
> +   MC_RSP_OP(cmd, 1, 0, 64, uint64_t, (stat)->raw.counter[1]); \
> +   MC_RSP_OP(cmd, 2, 0, 64, uint64_t, (stat)->raw.counter[2]); \
> +   MC_RSP_OP(cmd, 3, 0, 64, uint64_t, (stat)->raw.counter[3]); \
> +   MC_RSP_OP(cmd, 4, 0, 64, uint64_t, (stat)->raw.counter[4]); \
> +   MC_RSP_OP(cmd, 5, 0, 64, uint64_t, (stat)->raw.counter[5]); \
> +   MC_RSP_OP(cmd, 6, 0, 64, uint64_t, (stat)->raw.counter[6]); \
>  } while (0)
>
>  enum net_prot {
> @@ -1257,40 +1257,101 @@ int dpni_set_tx_confirmation_mode(struct fsl_mc_io   
>   *mc_io,
>   uint32_t  cmd_flags,
>   uint16_t  token,
>   enum dpni_confirmation_mode mode);
> -struct dpni_statistics {
> -   /**
> -* Page_0 statistics structure
> -* @ingress_all_frames: Ingress frame count
> -* @ingress_all_bytes: Ingress byte count
> -* @ingress_multicast_frames: Ingress multicast frame count
> -* @ingress_multicast_bytes: Ingress multicast byte count
> -* @ingress_broadcast_frames: Ingress broadcast frame count
> -* @ingress_broadcast_bytes: Ingress broadcast byte count
> -*
> -* Page_1 statistics structure
> -* @egress_all_frames: Egress frame count
> -* @egress_all_bytes: Egress byte count
> -* @egress_multicast_frames: Egress multicast frame count
> -* @egress_multicast_bytes: Egress multicast byte count
> -* @egress_broadcast_frames: Egress broadcast frame count
> -* @egress_broadcast_bytes: Egress broadcast byte count
> -*
> -* Page_2 statistics structure
> -* @ingress_filtered_frames: Ingress filtered frame count
> -* @ingress_discarded_frames: Ingress discarded frame count
> -* @ingress_nobuffer_discards: Ingress discarded frame count due to
> -*  lack of buffers.
> -* @egress_discarded_frames: Egress discarded frame count
> -* @egress_confirmed_frames: Egress confirmed frame count
> -*/
>
> -   uint64_t counter0;
> -   uint64_t counter1;
> 

Re: [PATCH 1/6] net: ldpaa_eth: fix the memory layout of the dpmac_get_counters() API

2023-06-10 Thread Ramon Fried
On Tue, May 23, 2023 at 4:48 PM Ioana Ciornei  wrote:
>
> Each MC commands has a specific predefined memory layout that gets
> interpreted by the firmware. The dpmac_get_counters() API memory layout
> is wrong, thus the results returned by the command are incorrect.
>
> Fix this by updating the offset of the counter field.
>
> Signed-off-by: Ioana Ciornei 
> ---
>  include/fsl-mc/fsl_dpmac.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/fsl-mc/fsl_dpmac.h b/include/fsl-mc/fsl_dpmac.h
> index 1cea123a3164..8f5e17fe222a 100644
> --- a/include/fsl-mc/fsl_dpmac.h
> +++ b/include/fsl-mc/fsl_dpmac.h
> @@ -84,7 +84,7 @@ do { \
>
>  /*cmd, param, offset, width, type, arg_name */
>  #define DPMAC_CMD_GET_COUNTER(cmd, type) \
> -   MC_CMD_OP(cmd, 1, 0,  64, enum dpmac_counter, type)
> +   MC_CMD_OP(cmd, 0, 0,  8, enum dpmac_counter, type)
>
>  /*cmd, param, offset, width, type, arg_name */
>  #define DPMAC_RSP_GET_COUNTER(cmd, counter) \
> --
> 2.25.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH 2/2] net: ipv6: network protocol structures should be packed

2023-06-10 Thread Ramon Fried
On Thu, May 18, 2023 at 9:24 PM  wrote:
>
> From: Ehsan Mohandesi 
>
> The structure icmp6_ra_prefix_info needs to be packed because it is read
> from a network stream.
>
> Signed-off-by: Ehsan Mohandesi 
> ---
>  include/net6.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/include/net6.h b/include/net6.h
> index beafc05..1e766aa 100644
> --- a/include/net6.h
> +++ b/include/net6.h
> @@ -204,7 +204,7 @@ struct icmp6_ra_prefix_info {
>  * be initialized to zero by the sender and ignored by the receiver.
>  */
> struct in6_addr prefix;
> -};
> +} __packed;
>
>  extern struct in6_addr const net_null_addr_ip6;/* NULL IPv6 address 
> */
>  extern struct in6_addr net_gateway6;   /* Our gateways IPv6 address */
> --
> 1.8.3.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH 1/2] net: ipv6: router advertisement message length should be within limits

2023-06-10 Thread Ramon Fried
On Thu, May 18, 2023 at 9:24 PM  wrote:
>
> From: Ehsan Mohandesi 
>
> The argument len passed to function process_ra is the length of the IPv6
> router advertisement message and needs to be between 0 and MTU because
> it is assigned to remaining_option_len and used as a loop variable.
>
> Addresses-Coverity-ID: 450971 ("TAINTED_SCALAR")
> Signed-off-by: Ehsan Mohandesi 
> ---
>  net/ndisc.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/net/ndisc.c b/net/ndisc.c
> index 0b27779..d1cec06 100644
> --- a/net/ndisc.c
> +++ b/net/ndisc.c
> @@ -382,6 +382,8 @@ int process_ra(struct ip6_hdr *ip6, int len)
> unsigned char type = 0;
> struct icmp6_ra_prefix_info *prefix = NULL;
>
> +   if (len > ETH_MAX_MTU)
> +   return -EMSGSIZE;
> /* Ignore the packet if router lifetime is 0. */
> if (!icmp->icmp6_rt_lifetime)
> return -EOPNOTSUPP;
> --
> 1.8.3.1
>
Reviewed-by: Ramon Fried 


Re: [PATCH 2/2] net: dhcp6: Fix VCI string

2023-06-10 Thread Ramon Fried
On Thu, May 18, 2023 at 10:35 PM  wrote:
>
> From: Sean Edmond 
>
> Change VCI string from "U-boot" to "U-Boot".
>
> Signed-off-by: Sean Edmond 
> ---
>  net/dhcpv6.h | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/net/dhcpv6.h b/net/dhcpv6.h
> index 80ca520432..65c8e4c71d 100644
> --- a/net/dhcpv6.h
> +++ b/net/dhcpv6.h
> @@ -38,7 +38,7 @@
>  #define DUID_MAX_SIZE  DUID_LL_SIZE /* only supports DUID-LL 
> currently */
>
>  /* vendor-class-data to send in vendor clas option */
> -#define DHCP6_VCI_STRING   "U-boot"
> +#define DHCP6_VCI_STRING   "U-Boot"
>
>  #define DHCP6_MULTICAST_ADDR   "ff02::1:2" /* DHCP multicast address */
>
> --
> 2.40.0
>
Reviewed-by: Ramon Fried 


Re: [PATCH 1/2] net: ipv6: Fix CID 453851 and CID 436278

2023-06-10 Thread Ramon Fried
On Thu, May 18, 2023 at 10:35 PM  wrote:
>
> From: Sean Edmond 
>
> CID 453851 : sprintf() shouldn't copy from/to tmp
> CID 436278 : DHCP6 option_len should be checked before use
>
> Signed-off-by: Sean Edmond 
> ---
>  cmd/net.c| 12 ++--
>  net/dhcpv6.c |  5 +
>  2 files changed, 11 insertions(+), 6 deletions(-)
>
> diff --git a/cmd/net.c b/cmd/net.c
> index 68d406291e..9e1f40a56e 100644
> --- a/cmd/net.c
> +++ b/cmd/net.c
> @@ -209,7 +209,7 @@ U_BOOT_CMD(
>
>  static void netboot_update_env(void)
>  {
> -   char tmp[44];
> +   char tmp[46];
>
> if (net_gateway.s_addr) {
> ip_to_string(net_gateway, tmp);
> @@ -274,20 +274,20 @@ static void netboot_update_env(void)
> if (IS_ENABLED(CONFIG_IPV6)) {
> if (!ip6_is_unspecified_addr(_ip6) ||
> net_prefix_length != 0) {
> -   sprintf(tmp, "%pI6c", _ip6);
> if (net_prefix_length != 0)
> -   sprintf(tmp, "%s/%d", tmp, net_prefix_length);
> -
> +   snprintf(tmp, sizeof(tmp), "%pI6c/%d", 
> _ip6, net_prefix_length);
> +   else
> +   snprintf(tmp, sizeof(tmp), "%pI6c", _ip6);
> env_set("ip6addr", tmp);
> }
>
> if (!ip6_is_unspecified_addr(_server_ip6)) {
> -   sprintf(tmp, "%pI6c", _server_ip6);
> +   snprintf(tmp, sizeof(tmp), "%pI6c", _server_ip6);
> env_set("serverip6", tmp);
> }
>
> if (!ip6_is_unspecified_addr(_gateway6)) {
> -   sprintf(tmp, "%pI6c", _gateway6);
> +   snprintf(tmp, sizeof(tmp), "%pI6c", _gateway6);
> env_set("gatewayip6", tmp);
> }
> }
> diff --git a/net/dhcpv6.c b/net/dhcpv6.c
> index 0d1c600632..73a1067877 100644
> --- a/net/dhcpv6.c
> +++ b/net/dhcpv6.c
> @@ -316,6 +316,11 @@ static void dhcp6_parse_options(uchar *rx_pkt, unsigned 
> int len)
> option_ptr = ((uchar *)option_hdr) + sizeof(struct dhcp6_hdr);
> option_len = ntohs(option_hdr->option_len);
>
> +   if (option_ptr + option_len > rx_pkt + len) {
> +   debug("Invalid option length\n");
> +   return;
> +   }
> +
> switch (ntohs(option_hdr->option_id)) {
> case DHCP6_OPTION_CLIENTID:
> if (memcmp(option_ptr, sm_params.duid, option_len)
> --
> 2.40.0
>
Reviewed-by: Ramon Fried 


Re: [PATCH] net: rtl8169: add depends on PCI

2023-06-10 Thread Ramon Fried
On Wed, May 17, 2023 at 1:41 PM Eugen Hristev
 wrote:
>
> The rtl8169 driver uses calls to dm_pci_bus_to_phys,
> which are compiled under CONFIG_PCI.
>
> Without CONFIG_PCI, this happens:
>
> drivers/net/rtl8169.o: in function `rtl_recv_common':
> drivers/net/rtl8169.c:555: undefined reference to `dm_pci_bus_to_phys'
>
> It is only natural that this driver depends on CONFIG_PCI then.
> The device does not work connected in another way anyway, and the driver
> does not assume anything else at this moment.
>
> Signed-off-by: Eugen Hristev 
> ---
>  drivers/net/Kconfig | 1 +
>  1 file changed, 1 insertion(+)
>
> diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
> index 09039a283eb5..39eee98ca79f 100644
> --- a/drivers/net/Kconfig
> +++ b/drivers/net/Kconfig
> @@ -633,6 +633,7 @@ config RTL8139
>
>  config RTL8169
> bool "Realtek 8169 series Ethernet controller driver"
> +   depends on PCI
> help
>   This driver supports Realtek 8169 series gigabit ethernet family of
>   PCI/PCIe chipsets/adapters.
> --
> 2.34.1
>
Reviewed-by: Ramon Fried 


[RFC PATCH] i2c: mvtwsi: reinitialize controller to clear bus errors

2023-06-10 Thread Sam Edwards
Hi I²C maintainers,

My target has the following devices sharing one bus:
- 24C02 EEPROM
- Realtek 8370 Ethernet switch
- Allwinner T113-s3 (running U-Boot, interfacing via MVTWSI)

The RTL8370 is configured in "EEPROM autoload" mode, so on reset
it will load the full contents of the EEPROM. During this sequence,
it does an odd move where it sends a re-start, stop, pulses scl low,
and then a fresh start.

Something about this sequence (I'm betting the scl pulse after stop)
upsets the MVTWSI controller, causing it to retreat into state 0x00,
which the documentation for my chip names "bus error." I'd guess this
is a feature for slave operation: in slave mode, the controller FSM
is completely at the mercy of the bus, and so a misbehaving/glitching
bus can result in essentially a random walk through the states. Rather
than allow that (and risk a potentially dangerous accidental write),
the controller goes to a failsafe "bus error" state and remains there,
effectively shutting down the whole controller.

However, in master mode (which U-Boot uses exclusively), this feature
is a nuisance. We do not care what another master was doing on the bus
previously, as long as it is in the proper idle state when we want to
use it. We also don't care if the bus error was our fault in a previous
transaction, since the error would have been reported at that time. I
reckon that it makes sense to check for this "bus error" state at the
beginning of each new read/write and clear it if detected.

Unfortunately, I couldn't find any way to coax the FSM out of the error
state just by poking at the control register. It's possible I didn't
look hard enough (I'm willing to try other things), but I'm otherwise
left with only the obvious way out: a reset. Since that also resets the
baud and address registers, I have to save and restore those too.

Attached here is my RFC patch (which DOES resolve my problem), for
feedback and suggestions on what I might try differently, as I'm not
sure whether or not I like this approach:
- I would be happier if the code did a fresh init instead of saving
  and restoring register state, but this driver is plumbed in a way
  that the config struct isn't readily accessible at the low level.
- I don't really like having to duplicate the state check in the read
  and write functions; is there anything I can do that's more DRY?
- Avoiding a reset would be nice, ideally avoiding the "bus error"
  state altogether by disabling the error detection somehow.

Thoughts?

Cheers,
Sam
---
 drivers/i2c/mvtwsi.c | 42 ++
 1 file changed, 42 insertions(+)

diff --git a/drivers/i2c/mvtwsi.c b/drivers/i2c/mvtwsi.c
index d088ea75b9..38a3bdade0 100644
--- a/drivers/i2c/mvtwsi.c
+++ b/drivers/i2c/mvtwsi.c
@@ -142,6 +142,8 @@ enum mvtwsi_ctrl_register_fields {
  * code.
  */
 enum mvstwsi_status_values {
+   /* Protocol violation on bus; this is a terminal state */
+   MVTWSI_BUS_ERROR= 0x00,
/* START condition transmitted */
MVTWSI_STATUS_START = 0x08,
/* Repeated START condition transmitted */
@@ -525,6 +527,36 @@ static void __twsi_i2c_init(struct mvtwsi_registers *twsi, 
int speed,
 #endif
 }
 
+/*
+ * __twsi_i2c_reinit() - Reset and reinitialize the I2C controller.
+ *
+ * This function should be called to get the MVTWSI controller out of the
+ * "bus error" state. It saves and restores the baud and address registers.
+ *
+ * @twsi:  The MVTWSI register structure to use.
+ * @tick:  The duration of a clock cycle at the current I2C speed.
+ */
+static void __twsi_i2c_reinit(struct mvtwsi_registers *twsi, uint tick)
+{
+   uint baud;
+   uint slaveadd;
+
+   /* Save baud, address registers */
+   baud = readl(>baudrate);
+   slaveadd = readl(>slave_address);
+
+   /* Reset controller */
+   twsi_reset(twsi);
+
+   /* Restore baud, address registers */
+   writel(baud, >baudrate);
+   writel(slaveadd, >slave_address);
+   writel(0, >xtnd_slave_addr);
+
+   /* Assert STOP, but don't care for the result */
+   (void) twsi_stop(twsi, tick);
+}
+
 /*
  * i2c_begin() - Start a I2C transaction.
  *
@@ -621,6 +653,11 @@ static int __twsi_i2c_read(struct mvtwsi_registers *twsi, 
uchar chip,
int stop_status;
int expected_start = MVTWSI_STATUS_START;
 
+   /* Check for (and clear) a bus error from a previous failed transaction
+* or another master on the same bus */
+   if (readl(>status) == MVTWSI_BUS_ERROR)
+   __twsi_i2c_reinit(twsi, tick);
+
if (alen > 0) {
/* Begin i2c write to send the address bytes */
status = i2c_begin(twsi, expected_start, (chip << 1), tick);
@@ -668,6 +705,11 @@ static int __twsi_i2c_write(struct mvtwsi_registers *twsi, 
uchar chip,
 {
int status, stop_status;
 
+   /* Check for (and clear) a bus error from a previous failed transaction
+* or