[PATCH] remoteproc: uclass: Modify uc_pdata->name to use combination of device name and device's parent name

2024-07-19 Thread MD Danish Anwar
uc_pdata->name is populated from device tree property "remoteproc-name".
For those devcices that don't set "remoteproc-name", uc_pdata->name
falls back to dev->name.

If two devices have same name, this will result into uc_pdata->name not
being unique and rproc_init() will fail.

Fix this by using combination of dev->name and dev->parent->name instead
of using just the dev->name to populate uc_pdata->name.

Signed-off-by: MD Danish Anwar 
---
Cc: Andrew Davis 

Failure Example:
In k3-am64-main.dtsi, both pru0_0 [1] and pru1_0 [2] will have
dev->name as "pru@34000" although their parent name is different.

pru0_0 has dev->name as "pru@34000" and parent name as "icssg@3000"
pru1_0 has dev->name as "pru@34000" and parent name as "icssg@3008"

rproc_init() fails for pru1_0 as the the uc_pdata->name becomes same as the 
pru0_0.
More details on this issue can be found here [3]. It was suggested to use a
different combination if `dev->name` is not unique by Andrew Davis 
 [4]

Failure Logs:
rproc_pre_probe: 'pru@34000': using fdt
rproc_pre_probe: 'pru@34000': using fdt
rproc_pre_probe: pru@34000 duplicate name 'pru@34000'
_rproc_probe_dev: pru@34000: Failed to initialize - -22
rproc_boot: rproc_init() failed: -22

To fix it, this commit uses combination of dev and dev's parent name.

After this commit,
pru0_0 uc->pdata->name = "pru@34000:icssg@3000"
pru1_0 uc->pdata->name = "pru@34000:icssg@3008"

Both the names are unique, thus rproc_init() succeeds.

[1] 
https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1276
[2] 
https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1417
[3] https://lore.kernel.org/all/5cda289f-1d14-41f6-84e3-ff1d1034b...@ti.com/
[4] https://lore.kernel.org/all/e48f5818-182c-47ab-b384-379659830...@ti.com/

 drivers/remoteproc/rproc-uclass.c | 12 +---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 3ba2b40dca..e550292dda 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -158,9 +158,15 @@ static int rproc_pre_probe(struct udevice *dev)
uc_pdata->driver_plat_data = pdata->driver_plat_data;
}
 
-   /* Else try using device Name */
-   if (!uc_pdata->name)
-   uc_pdata->name = dev->name;
+   /* Else try using a combination of device Name and devices's parent's 
name */
+   if (!uc_pdata->name) {
+   int rproc_name_size = 256;
+   char *buf;
+
+   buf = malloc(rproc_name_size);
+   snprintf(buf, rproc_name_size, "%s-%s", dev->name, 
dev->parent->name);
+   uc_pdata->name = buf;
+   }
if (!uc_pdata->name) {
debug("Unnamed device!");
return -EINVAL;
-- 
2.34.1



[PATCH v2 2/2] board: ti: am64x: Set storage_interface and fw_dev_part ENVs

2024-06-12 Thread MD Danish Anwar
When ICSSG driver is enabled (CONFIG_TI_ICSSG_PRUETH=y) set
storage_interface and fw_dev_part env variables.

These variables need be set appropriately in order to load different
ICSSG firmwares needed for ICSSG driver. By default the storage
interface is mmc and the partition is 1:2. User can modify this based on
their needs.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am64x/am64x.env | 5 +
 1 file changed, 5 insertions(+)

diff --git a/board/ti/am64x/am64x.env b/board/ti/am64x/am64x.env
index 9a8812d4ee..8ad805a613 100644
--- a/board/ti/am64x/am64x.env
+++ b/board/ti/am64x/am64x.env
@@ -39,3 +39,8 @@ usbboot=setenv boot usb;
run get_kern_usb;
run get_fdt_usb;
run run_kern;
+
+#if CONFIG_TI_ICSSG_PRUETH
+storage_interface=mmc
+fw_dev_part=1:2
+#endif
-- 
2.34.1



[PATCH v2 1/2] configs: am64x_evm_a53: Enable ICSSG Driver

2024-06-12 Thread MD Danish Anwar
Enable ICSSG driver, DP83869 phy driver, REMOTEPROC and PRU_REMOTEPROC
in am64x_evm_a53_defconfig. All these configs are needed for ICSSG
driver.

Signed-off-by: MD Danish Anwar 
---
 configs/am64x_evm_a53_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/am64x_evm_a53_defconfig b/configs/am64x_evm_a53_defconfig
index e000549d6d..6063286798 100644
--- a/configs/am64x_evm_a53_defconfig
+++ b/configs/am64x_evm_a53_defconfig
@@ -126,8 +126,10 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_MULTIPLEXER=y
 CONFIG_MUX_MMIO=y
 CONFIG_PHY_TI_DP83867=y
+CONFIG_PHY_TI_DP83869=y
 CONFIG_PHY_FIXED=y
 CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_TI_ICSSG_PRUETH=y
 CONFIG_PHY=y
 CONFIG_SPL_PHY=y
 CONFIG_PHY_CADENCE_TORRENT=y
@@ -143,6 +145,8 @@ CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_TPS65219=y
 CONFIG_K3_SYSTEM_CONTROLLER=y
 CONFIG_REMOTEPROC_TI_K3_ARM64=y
+CONFIG_REMOTEPROC_TI_PRU=y
+CONFIG_CMD_REMOTEPROC=y
 CONFIG_RESET_TI_SCI=y
 CONFIG_DM_RTC=y
 CONFIG_RTC_EMULATION=y
@@ -150,6 +154,7 @@ CONFIG_DM_SERIAL=y
 CONFIG_SOC_DEVICE=y
 CONFIG_SOC_DEVICE_TI_K3=y
 CONFIG_SOC_TI=y
+CONFIG_TI_PRUSS=y
 CONFIG_SPI=y
 CONFIG_DM_SPI=y
 CONFIG_CADENCE_QSPI=y
-- 
2.34.1



[PATCH v2 0/2] Enable ICSSG Driver for AM64x

2024-06-12 Thread MD Danish Anwar
This series adds config changes and env changes to enable ICSSG Ethernet
Driver on AM64x.

Changes since v1:
*) Dropped the patch [0] as this needs to be fixed in driver as suggested
   by Andrew Davis 
*) Rebased on latest u-boot/next.

v1 https://lore.kernel.org/all/20240522063652.3759497-1-danishan...@ti.com/
[0] https://lore.kernel.org/all/cb53651f-a823-41b8-81e5-c3939bd33...@ti.com/

Thanks and Regards,
MD Danish Anwar 

MD Danish Anwar (2):
  configs: am64x_evm_a53: Enable ICSSG Driver
  board: ti: am64x: Set storage_interface and fw_dev_part ENVs

 board/ti/am64x/am64x.env| 5 +
 configs/am64x_evm_a53_defconfig | 5 +
 2 files changed, 10 insertions(+)


base-commit: 9cf83a7da95b70a37d0d2aba79439dc8a2944fe3
-- 
2.34.1



[PATCH 3/3] board: ti: am64x: Set storage_interface and fw_dev_part ENVs

2024-05-22 Thread MD Danish Anwar
When ICSSG driver is enabled (CONFIG_TI_ICSSG_PRUETH=y) set
storage_interface and fw_dev_part env variables.

These variables need be set appropriately in order to load different
ICSSG firmwares needed for ICSSG driver. By default the storage
interface is mmc and the partition is 1:2. User can modify this based on
their needs.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am64x/am64x.env | 5 +
 1 file changed, 5 insertions(+)

diff --git a/board/ti/am64x/am64x.env b/board/ti/am64x/am64x.env
index 9a8812d4ee..8ad805a613 100644
--- a/board/ti/am64x/am64x.env
+++ b/board/ti/am64x/am64x.env
@@ -39,3 +39,8 @@ usbboot=setenv boot usb;
run get_kern_usb;
run get_fdt_usb;
run run_kern;
+
+#if CONFIG_TI_ICSSG_PRUETH
+storage_interface=mmc
+fw_dev_part=1:2
+#endif
-- 
2.34.1



[PATCH 1/3] arm: dts: k3-am642-evm-u-boot: Add remoteproc-name for PRU cores

2024-05-22 Thread MD Danish Anwar
Add remoteproc-name property for PRU cores.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/k3-am642-evm-u-boot.dtsi | 44 +++
 1 file changed, 44 insertions(+)

diff --git a/arch/arm/dts/k3-am642-evm-u-boot.dtsi 
b/arch/arm/dts/k3-am642-evm-u-boot.dtsi
index 705b3baa81..25ddace74e 100644
--- a/arch/arm/dts/k3-am642-evm-u-boot.dtsi
+++ b/arch/arm/dts/k3-am642-evm-u-boot.dtsi
@@ -11,6 +11,50 @@
};
 };
 
+_0 {
+   remoteproc-name = "pru0_0";
+};
+
+_0 {
+   remoteproc-name = "rtu0_0";
+};
+
+_pru0_0 {
+   remoteproc-name = "tx_pru0_0";
+};
+
+_1 {
+   remoteproc-name = "pru0_1";
+};
+
+_1 {
+   remoteproc-name = "rtu0_1";
+};
+
+_pru0_1 {
+   remoteproc-name = "tx_pru0_1";
+};
+
+_0 {
+   remoteproc-name = "pru1_0";
+};
+
+_0 {
+   remoteproc-name = "rtu1_0";
+};
+
+_pru1_0 {
+   remoteproc-name = "tx_pru1_0";
+};
+
+_1 {
+   remoteproc-name = "pru1_1";
+};
+
+_1 {
+   remoteproc-name = "rtu1_1";
+};
+
 _timer0 {
clock-frequency = <2>;
 };
-- 
2.34.1



[PATCH 2/3] configs: am64x_evm_a53: Enable ICSSG Driver

2024-05-22 Thread MD Danish Anwar
Enable ICSSG driver, DP83869 phy driver, REMOTEPROC and PRU_REMOTEPROC
in am64x_evm_a53_defconfig. All these configs are needed for ICSSG
driver.

Signed-off-by: MD Danish Anwar 
---
 configs/am64x_evm_a53_defconfig | 5 +
 1 file changed, 5 insertions(+)

diff --git a/configs/am64x_evm_a53_defconfig b/configs/am64x_evm_a53_defconfig
index e000549d6d..6063286798 100644
--- a/configs/am64x_evm_a53_defconfig
+++ b/configs/am64x_evm_a53_defconfig
@@ -126,8 +126,10 @@ CONFIG_SPI_FLASH_MTD=y
 CONFIG_MULTIPLEXER=y
 CONFIG_MUX_MMIO=y
 CONFIG_PHY_TI_DP83867=y
+CONFIG_PHY_TI_DP83869=y
 CONFIG_PHY_FIXED=y
 CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_TI_ICSSG_PRUETH=y
 CONFIG_PHY=y
 CONFIG_SPL_PHY=y
 CONFIG_PHY_CADENCE_TORRENT=y
@@ -143,6 +145,8 @@ CONFIG_DM_REGULATOR=y
 CONFIG_DM_REGULATOR_TPS65219=y
 CONFIG_K3_SYSTEM_CONTROLLER=y
 CONFIG_REMOTEPROC_TI_K3_ARM64=y
+CONFIG_REMOTEPROC_TI_PRU=y
+CONFIG_CMD_REMOTEPROC=y
 CONFIG_RESET_TI_SCI=y
 CONFIG_DM_RTC=y
 CONFIG_RTC_EMULATION=y
@@ -150,6 +154,7 @@ CONFIG_DM_SERIAL=y
 CONFIG_SOC_DEVICE=y
 CONFIG_SOC_DEVICE_TI_K3=y
 CONFIG_SOC_TI=y
+CONFIG_TI_PRUSS=y
 CONFIG_SPI=y
 CONFIG_DM_SPI=y
 CONFIG_CADENCE_QSPI=y
-- 
2.34.1



[PATCH 0/3] Enable ICSSG Driver for AM64x

2024-05-22 Thread MD Danish Anwar
This series adds device-tree changes (specific to u-boot only), config
changes and env changes to enable ICSSG Ethernet Driver on AM64x.

Patch 1/3 adds remoteproc-name property to the pru cores in
k3-am642-evm-u-boot.dtsi file. This property is not needed in Linux thus
it's not part of the PRU nodes in k3-am64x-main.dtsi. Adding this in 
*u-boot.dtsi as it is only needed for u-boot. Without this different PRU
nodes can have same remoteproc-name which results into probe failure.
For example the node "pru0_0: pru@34000" and "pru1_0: pru@34000" both will
have remoteproc-name as "pru@34000" without this patch, resulting in probe
failure because of non-unique name (_rproc_name_is_unique() API) of PRU
core.

Patch 2/3 Enables necessary configs for AM64x to enable ICSSG driver
Patch 3/3 Sets env variables needed for ICSSG driver

Thanks and Regards,
MD Danish Anwar 

MD Danish Anwar (3):
  arm: dts: k3-am642-evm-u-boot: Add remoteproc-name for PRU cores
  configs: am64x_evm_a53: Enable ICSSG Driver
  board: ti: am64x: Set storage_interface and fw_dev_part ENVs

 arch/arm/dts/k3-am642-evm-u-boot.dtsi | 44 +++
 board/ti/am64x/am64x.env  |  5 +++
 configs/am64x_evm_a53_defconfig   |  5 +++
 3 files changed, 54 insertions(+)


base-commit: 7d24c3e06fa9a3b53cea593d4579886ef0eb4fe8
-- 
2.34.1



Re: [PATCH 0/2] Add AM64x Support to PRUSS and PRU_RPROC driver

2024-05-21 Thread MD Danish Anwar
Hi Tom,

On 21/05/24 10:09 pm, Tom Rini wrote:
> On Tue, May 21, 2024 at 02:31:44PM +0530, MD Danish Anwar wrote:
>> Hi Tom,
>>
>> On 11/05/24 1:02 am, Tom Rini wrote:
>>> On Tue, 30 Apr 2024 16:16:31 +0530, MD Danish Anwar wrote:
>>>
>>>> This series adds AM64x related compatibles to PRUSS and PRU_RPROC drivers.
>>>> This series is a prerequisite for ICSSG Ethernet driver.
>>>>
>>>> Once Support for AM64x is added to PRUSS and PRU_RPROC driver, I'll send
>>>> another series to enable ICSSG Ethernet driver for AM64x as well.
>>>>
>>>> MD Danish Anwar (2):
>>>>   remoteproc: pru: Add support for AM64x PRU / RTU cores
>>>>   soc: ti: pruss: Add support for AM64x
>>>>
>>>> [...]
>>>
>>> Applied to u-boot/next, thanks!
>>>
>>
>> I was working on the latest u-boot/next (d4781422d1 (origin/next) "Merge
>> tag 'v2024.07-rc3' into next") and I don't see this series being part of
>> u-boot/next.
>>
>> I checked the git logs, you had merged this series but on 18th may you
>> committed [1] ("Revert "Merge patch series "arm: dts: am62-beagleplay:
>> Fix Beagleplay Ethernet""") which reverts bunch of changes and as part
>> of this commit, this series was also reverted.
>>
>> Now when I am trying to verify ICSSG, it doesn't work as this series is
>> not part of u-boot/next anymore.
>>
>> Can you please pull / merge this series again to u-boot/next? Or do I
>> need to send these patches for merge again?
>>
>> Please let me know.
>>
>> [1]
>> https://source.denx.de/u-boot/u-boot/-/commit/d678a59d2d719da9e807495b4b021501f2836ca5
> 
> Please re-post based on current next, sorry for the rework.
> 

I see that now this series is part of u-boot/next. Your commit [1] has
restored the changes. Thanks for that.

[1]
https://source.denx.de/u-boot/u-boot/-/commit/03de305ec48b0bb28554372abb40ccd46dbe0bf9

-- 
Thanks and Regards,
Danish


Re: [PATCH 0/2] Add AM64x Support to PRUSS and PRU_RPROC driver

2024-05-21 Thread MD Danish Anwar
Hi Tom,

On 11/05/24 1:02 am, Tom Rini wrote:
> On Tue, 30 Apr 2024 16:16:31 +0530, MD Danish Anwar wrote:
> 
>> This series adds AM64x related compatibles to PRUSS and PRU_RPROC drivers.
>> This series is a prerequisite for ICSSG Ethernet driver.
>>
>> Once Support for AM64x is added to PRUSS and PRU_RPROC driver, I'll send
>> another series to enable ICSSG Ethernet driver for AM64x as well.
>>
>> MD Danish Anwar (2):
>>   remoteproc: pru: Add support for AM64x PRU / RTU cores
>>   soc: ti: pruss: Add support for AM64x
>>
>> [...]
> 
> Applied to u-boot/next, thanks!
> 

I was working on the latest u-boot/next (d4781422d1 (origin/next) "Merge
tag 'v2024.07-rc3' into next") and I don't see this series being part of
u-boot/next.

I checked the git logs, you had merged this series but on 18th may you
committed [1] ("Revert "Merge patch series "arm: dts: am62-beagleplay:
Fix Beagleplay Ethernet""") which reverts bunch of changes and as part
of this commit, this series was also reverted.

Now when I am trying to verify ICSSG, it doesn't work as this series is
not part of u-boot/next anymore.

Can you please pull / merge this series again to u-boot/next? Or do I
need to send these patches for merge again?

Please let me know.

[1]
https://source.denx.de/u-boot/u-boot/-/commit/d678a59d2d719da9e807495b4b021501f2836ca5


-- 
Thanks and Regards,
Danish


[PATCH 2/2] soc: ti: pruss: Add support for AM64x

2024-04-30 Thread MD Danish Anwar
Add support for AM64x by adding it's compatible in pruss driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/soc/ti/pruss.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/soc/ti/pruss.c b/drivers/soc/ti/pruss.c
index 461390925d..5317b8335b 100644
--- a/drivers/soc/ti/pruss.c
+++ b/drivers/soc/ti/pruss.c
@@ -205,6 +205,7 @@ static int pruss_probe(struct udevice *dev)
 
 static const struct udevice_id pruss_ids[] = {
{ .compatible = "ti,am654-icssg"},
+   { .compatible = "ti,am642-icssg"},
{}
 };
 
-- 
2.34.1



[PATCH 0/2] Add AM64x Support to PRUSS and PRU_RPROC driver

2024-04-30 Thread MD Danish Anwar
This series adds AM64x related compatibles to PRUSS and PRU_RPROC drivers.
This series is a prerequisite for ICSSG Ethernet driver.

Once Support for AM64x is added to PRUSS and PRU_RPROC driver, I'll send
another series to enable ICSSG Ethernet driver for AM64x as well.

MD Danish Anwar (2):
  remoteproc: pru: Add support for AM64x PRU / RTU cores
  soc: ti: pruss: Add support for AM64x

 drivers/remoteproc/pru_rproc.c | 9 +++--
 drivers/soc/ti/pruss.c | 1 +
 2 files changed, 8 insertions(+), 2 deletions(-)


base-commit: ff0de1f0557ed7d2dab47ba976a37347a1fdc432
-- 
2.34.1



[PATCH 1/2] remoteproc: pru: Add support for AM64x PRU / RTU cores

2024-04-30 Thread MD Danish Anwar
Add support for AM64x PRU cores by adding compatibles for AM64x.

Signed-off-by: MD Danish Anwar 
---
 drivers/remoteproc/pru_rproc.c | 9 +++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/pru_rproc.c b/drivers/remoteproc/pru_rproc.c
index 6ec55e27d9..5e9334e117 100644
--- a/drivers/remoteproc/pru_rproc.c
+++ b/drivers/remoteproc/pru_rproc.c
@@ -399,10 +399,12 @@ static void pru_set_id(struct pru_privdata *priv, struct 
udevice *dev)
 {
u32 mask2 = 0x38000;
 
-   if (device_is_compatible(dev, "ti,am654-rtu"))
+   if (device_is_compatible(dev, "ti,am654-rtu") ||
+   device_is_compatible(dev, "ti,am642-rtu"))
mask2 = 0x6000;
 
-   if (device_is_compatible(dev, "ti,am654-tx-pru"))
+   if (device_is_compatible(dev, "ti,am654-tx-pru") ||
+   device_is_compatible(dev, "ti,am642-tx-pru"))
mask2 = 0xc000;
 
if ((priv->pru_iram & mask2) == mask2)
@@ -448,6 +450,9 @@ static const struct udevice_id pru_ids[] = {
{ .compatible = "ti,am654-pru"},
{ .compatible = "ti,am654-rtu"},
{ .compatible = "ti,am654-tx-pru" },
+   { .compatible = "ti,am642-pru"},
+   { .compatible = "ti,am642-rtu"},
+   { .compatible = "ti,am642-tx-pru" },
{}
 };
 
-- 
2.34.1



[PATCH v4 5/6] board: ti: am65x: Add check for k3-am654-icssg2 in board_fit_config_match()

2024-04-16 Thread MD Danish Anwar
When CONFIG_TI_ICSSG_PRUETH is enabled, add config name check for the
icssg2 overlay in board_fit_config_match() API.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am65x/evm.c | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index 3109c9a2ac..07073a5940 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -91,10 +91,13 @@ int dram_init_banksize(void)
 #ifdef CONFIG_SPL_LOAD_FIT
 int board_fit_config_name_match(const char *name)
 {
-#ifdef CONFIG_TARGET_AM654_A53_EVM
-   if (!strcmp(name, "k3-am654-base-board"))
+   if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH) &&
+   strcmp(name, "k3-am654-icssg2") == 0)
+   return 0;
+
+   if (IS_ENABLED(CONFIG_TARGET_AM654_A53_EVM) &&
+   strcmp(name, "k3-am654-base-board") == 0)
return 0;
-#endif
 
return -1;
 }
-- 
2.34.1



[PATCH v4 3/6] configs: am65x_evm_a53: Enable ICSSG Driver

2024-04-16 Thread MD Danish Anwar
Enable ICSSG driver in am65x_evm_a53_defconfig

Signed-off-by: MD Danish Anwar 
---
 configs/am65x_evm_a53_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index 3afa80f45a..f06186ed8d 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -129,6 +129,7 @@ CONFIG_PHY_FIXED=y
 CONFIG_E1000=y
 CONFIG_CMD_E1000=y
 CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_TI_ICSSG_PRUETH=y
 CONFIG_PCI_KEYSTONE=y
 CONFIG_PHY=y
 CONFIG_SPL_PHY=y
-- 
2.34.1



[PATCH v4 6/6] board: ti: am65x: Set fw_storage_interface and fw_dev_part ENVs

2024-04-16 Thread MD Danish Anwar
When ICSSG driver is enabled (CONFIG_TI_ICSSG_PRUETH=y) set
storage_interface and fw_dev_part env variables.

These variables need be set appropriately in order to load differnet
ICSSG firmwares needed for ICSSG driver. By default the storage
interface is mmc and the partition is 1:2. User can modify this based on
their needs.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am65x/am65x.env | 4 
 1 file changed, 4 insertions(+)

diff --git a/board/ti/am65x/am65x.env b/board/ti/am65x/am65x.env
index 814374d68c..631997e4c9 100644
--- a/board/ti/am65x/am65x.env
+++ b/board/ti/am65x/am65x.env
@@ -27,3 +27,7 @@ get_fdt_ubi=ubifsload ${fdtaddr} ${bootdir}/${name_fdt}
 args_ubi=setenv bootargs console=${console} ${optargs}
 rootfstype=ubifs root=ubi0:rootfs rw ubi.mtd=ospi.rootfs
 
+#if CONFIG_TI_ICSSG_PRUETH
+storage_interface=mmc
+fw_dev_part=1:2
+#endif
-- 
2.34.1



[PATCH v4 1/6] arm: dts: k3-am654-base-board: Add ICSSG2 Ethernet support

2024-04-16 Thread MD Danish Anwar
ICSSG2 provides dual Gigabit Ethernet support.
Add ICSSG2 ethernet node to an overlay k3-am654-icssg2.dtso

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/Makefile |   4 +-
 arch/arm/dts/k3-am654-icssg2.dtso | 145 ++
 2 files changed, 148 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/k3-am654-icssg2.dtso

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index 08dfbdd557..a58e700bf7 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1326,7 +1326,9 @@ dtb-$(CONFIG_SOC_K3_AM654) += \
k3-am6548-iot2050-advanced-pg2.dtb \
k3-am6548-iot2050-advanced-m2.dtb \
k3-am6548-iot2050-advanced-m2-bkey-usb3-overlay.dtbo \
-   k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dtbo
+   k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dtbo \
+   k3-am654-icssg2.dtbo
+
 dtb-$(CONFIG_SOC_K3_J721E) += k3-j721e-common-proc-board.dtb \
  k3-j721e-r5-common-proc-board.dtb \
  k3-j7200-common-proc-board.dtb \
diff --git a/arch/arm/dts/k3-am654-icssg2.dtso 
b/arch/arm/dts/k3-am654-icssg2.dtso
new file mode 100644
index 00..faefa2febc
--- /dev/null
+++ b/arch/arm/dts/k3-am654-icssg2.dtso
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * DT overlay for enabling ICSSG2 on AM654 EVM
+ *
+ * Copyright (C) 2018-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+/dts-v1/;
+/plugin/;
+
+#include 
+#include "k3-pinctrl.h"
+
+&{/} {
+   aliases {
+   ethernet1 = "/icssg2-eth/ethernet-ports/port@0";
+   ethernet2 = "/icssg2-eth/ethernet-ports/port@1";
+   };
+
+   /* Ethernet node on PRU-ICSSG2 */
+   icssg2_eth: icssg2-eth {
+   compatible = "ti,am654-icssg-prueth";
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii_pins_default>;
+   sram = <_ram>;
+   ti,prus = <_0>, <_0>, <_pru2_0>,
+   <_1>, <_1>, <_pru2_1>;
+   firmware-name = "ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-txpru1-prueth-fw.elf";
+
+   ti,pruss-gp-mux-sel = <2>,  /* MII mode */
+ <2>,
+ <2>,
+ <2>,  /* MII mode */
+ <2>,
+ <2>;
+
+   ti,mii-g-rt = <_mii_g_rt>;
+   ti,mii-rt = <_mii_rt>;
+   ti,iep = <_iep0>, <_iep1>;
+
+   interrupt-parent = <_intc>;
+   interrupts = <24 0 2>, <25 1 3>;
+   interrupt-names = "tx_ts0", "tx_ts1";
+
+   dmas = <_udmap 0xc300>, /* egress slice 0 */
+  <_udmap 0xc301>, /* egress slice 0 */
+  <_udmap 0xc302>, /* egress slice 0 */
+  <_udmap 0xc303>, /* egress slice 0 */
+  <_udmap 0xc304>, /* egress slice 1 */
+  <_udmap 0xc305>, /* egress slice 1 */
+  <_udmap 0xc306>, /* egress slice 1 */
+  <_udmap 0xc307>, /* egress slice 1 */
+  <_udmap 0x4300>, /* ingress slice 0 */
+  <_udmap 0x4301>; /* ingress slice 1 */
+
+   dma-names = "tx0-0", "tx0-1", "tx0-2", "tx0-3",
+   "tx1-0", "tx1-1", "tx1-2", "tx1-3",
+   "rx0", "rx1";
+   ethernet-ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   icssg2_emac0: port@0 {
+   reg = <0>;
+   phy-handle = <_phy0>;
+   phy-mode = "rgmii-id";
+   ti,syscon-rgmii-delay = <_conf 0x4120>;
+   /* Filled in by bootloader */
+   local-mac-address = [00 00 00 00 00 00];
+   };
+   icssg2_emac1: port@1 {
+   reg = <1>;
+   

[PATCH v4 4/6] configs: am65x_evm_a53: add SPL_LOAD_FIT_APPLY_OVERLAY

2024-04-16 Thread MD Danish Anwar
We want SPL to apply DTB overlays (e.g. ICSSG2 overlay) so enable
SPL_LOAD_FIT_APPLY_OVERLAY.

Signed-off-by: MD Danish Anwar 
---
 configs/am65x_evm_a53_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index f06186ed8d..d2f35dc2fb 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -68,6 +68,7 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
+CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_TIME=y
 CONFIG_MTDIDS_DEFAULT="nor0=4704.spi.0"
-- 
2.34.1



[PATCH v4 0/6] Enable ICSSG Ethernet Driver for AM65x

2024-04-16 Thread MD Danish Anwar
The series introduces device tree and config changes and AM65x
to enable ICSSG driver. The series also enables SPL_LOAD_FIT_APPLY_OVERLAY
for AM65x in order to load overlay over spl.

The ICSSG2 node is added in device tree overlay so that it remains in
sync with linux kernel.

This series has been tested on AM65x SR2.0, and the ICSSG interface is
able to ping / dhcp and boot kernel using tftp in uboot.

The users need to set env variables fw_storage_interface, fw_dev_part,
fw_ubi_mtdpart, fw_ubi_volume to indicate which storage medium and
partition they want to use to load firmware files from. By default the env
fw_storage_interface=mmc and fw_dev_part=1:2 but users can modify these
envs as per their requirements.

This is the v4 of the series [1]. The series doesn't depend on any patch
and can be applied cleanly on u-boot/master

Changes from v3 to v4:
*) Separated the device tree and board specific changes into this series
   from the main series [1].
*) Added check for TARGET_AM654_A53_EVM config in board file as suggested
   by Dan Carpenter 
*) Rebased on latest u-boot/master.

[1] https://lore.kernel.org/all/20240124064930.1787929-1-danishan...@ti.com/

MD Danish Anwar (6):
  arm: dts: k3-am654-base-board: Add ICSSG2 Ethernet support
  arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration
  configs: am65x_evm_a53: Enable ICSSG Driver
  configs: am65x_evm_a53: add SPL_LOAD_FIT_APPLY_OVERLAY
  board: ti: am65x: Add check for k3-am654-icssg2 in
board_fit_config_match()
  board: ti: am65x: Set fw_storage_interface and fw_dev_part ENVs

 arch/arm/dts/Makefile |   4 +-
 arch/arm/dts/k3-am654-icssg2.dtso | 145 ++
 arch/arm/dts/k3-am65x-binman.dtsi |  65 +-
 board/ti/am65x/am65x.env  |   4 +
 board/ti/am65x/evm.c  |   9 +-
 configs/am65x_evm_a53_defconfig   |   2 +
 6 files changed, 221 insertions(+), 8 deletions(-)
 create mode 100644 arch/arm/dts/k3-am654-icssg2.dtso


base-commit: 6e316e3f397b5e01e98c5dd56cdbaab961daeedf
-- 
2.34.1



[PATCH v4 2/6] arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration

2024-04-16 Thread MD Danish Anwar
Add ICSSG2 overlay and configuration to tispl and u-boot images.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/k3-am65x-binman.dtsi | 65 +--
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
b/arch/arm/dts/k3-am65x-binman.dtsi
index 8cc24da1f3..d0cd4889cd 100644
--- a/arch/arm/dts/k3-am65x-binman.dtsi
+++ b/arch/arm/dts/k3-am65x-binman.dtsi
@@ -98,6 +98,8 @@
 #define SPL_AM654_EVM_DTB "spl/dts/k3-am654-base-board.dtb"
 #define AM654_EVM_DTB "u-boot.dtb"
 
+#define AM654_EVM_ICSSG2_DTBO "arch/arm/dts/k3-am654-icssg2.dtbo"
+
  {
ti-spl {
insert-template = <_spl_template>;
@@ -124,6 +126,20 @@
filename = SPL_AM654_EVM_DTB;
};
};
+
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = 
<_am65x_evm_icssg2_dtb>;
+   keyfile = "custMpk.pem";
+   };
+   spl_am65x_evm_icssg2_dtb: blob-ext {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   };
};
 
configurations {
@@ -133,7 +149,7 @@
description = "k3-am654-base-board";
firmware = "atf";
loadables = "tee", "dm", "spl";
-   fdt = "fdt-0";
+   fdt = "fdt-0", "fdt-1";
};
};
};
@@ -168,6 +184,24 @@
};
};
 
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = 
<_evm_icssg2_dtb>;
+   keyfile = "custMpk.pem";
+
+   };
+   am65x_evm_icssg2_dtb: blob-ext {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   hash {
+   algo = "crc32";
+   };
+   };
+
};
 
configurations {
@@ -177,7 +211,7 @@
description = "k3-am654-base-board";
firmware = "uboot";
loadables = "uboot";
-   fdt = "fdt-0";
+   fdt = "fdt-0", "fdt-1";
};
};
};
@@ -205,6 +239,16 @@
filename = SPL_AM654_EVM_DTB;
};
};
+
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   blob {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   };
};
 
configurations {
@@ -214,7 +258,7 @@
description = "k3-am654-base-board";
firmware = "atf&quo

[PATCH v5 4/5] net: ti: icssg: Add ICSSG ethernet driver

2024-04-04 Thread MD Danish Anwar
This is the PRUSS Ethernet driver for TI AM654 SR2.0 and later SoCs with
the ICSSG PRU Sub-system running EMAC firmware. ICSSG Subsystem supports
two slices per instance. This driver caters to both slices / ports of
the icssg subsystem.

Since it is not possible for Ethernet driver to register more than one
port for a given instance, this patch introduces top level PRUETH as
UCLASS_MISC and binds UCLASS_ETH to individual ports in order to support
bringing up more than one Ethernet interface in U-Boot.

Since top level driver is UCLASS_MISC, board files would need to
instantiate the driver explicitly.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/mach-k3/common.c |  11 +
 drivers/net/ti/Kconfig|  13 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icssg_prueth.c | 685 ++
 drivers/net/ti/icssg_prueth.h |   3 +
 5 files changed, 713 insertions(+)
 create mode 100644 drivers/net/ti/icssg_prueth.c

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index b0fb87b97a..d151277d6d 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -270,6 +270,17 @@ int misc_init_r(void)
printf("Failed to probe am65_cpsw_nuss driver\n");
}
 
+   if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_DRIVER_GET(prueth),
+ );
+   if (ret)
+   printf("Failed to probe prueth driver\n");
+   }
+
/* Default FIT boot on HS-SE devices */
if (get_device_type() == K3_DEVICE_TYPE_HS_SE)
env_set("boot_fit", "1");
diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index 72eccc99e5..ddfa95a0b7 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -57,3 +57,16 @@ config MDIO_TI_CPSW
help
  This driver supports the TI CPSW MDIO interface found in various
  TI SoCs.
+
+config TI_ICSSG_PRUETH
+   bool "TI Gigabit PRU Ethernet driver"
+   depends on ARCH_K3
+   imply DM_MDIO
+   imply MISC_INIT_R
+   imply MISC
+   imply MDIO_TI_CPSW
+   select PHYLIB
+   select FS_LOADER
+   help
+ Support Gigabit Ethernet ports over the ICSSG PRU Subsystem
+ This subsystem is available starting with the AM65 platform.
diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
index 30c4c4b6d5..b2b3aa3b18 100644
--- a/drivers/net/ti/Makefile
+++ b/drivers/net/ti/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
 obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
 obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o
 obj-$(CONFIG_MDIO_TI_CPSW) += cpsw_mdio.o
+obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg_prueth.o icssg_classifier.o 
icssg_config.o icssg_queues.o
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
new file mode 100644
index 00..72007aabf2
--- /dev/null
+++ b/drivers/net/ti/icssg_prueth.c
@@ -0,0 +1,685 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments K3 AM65 PRU Ethernet Driver
+ *
+ * Copyright (C) 2018-2024 Texas Instruments Incorporated - https://www.ti.com/
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "icssg_prueth.h"
+#include "icss_mii_rt.h"
+
+#define ICSS_SLICE0 0
+#define ICSS_SLICE1 1
+
+#ifdef PKTSIZE_ALIGN
+#define UDMA_RX_BUF_SIZE PKTSIZE_ALIGN
+#else
+#define UDMA_RX_BUF_SIZE ALIGN(PKTSIZE, ARCH_DMA_MINALIGN)
+#endif
+
+#ifdef PKTBUFSRX
+#define UDMA_RX_DESC_NUM PKTBUFSRX
+#else
+#define UDMA_RX_DESC_NUM 4
+#endif
+
+/* Config region lies in shared RAM */
+#define ICSS_CONFIG_OFFSET_SLICE0  0
+#define ICSS_CONFIG_OFFSET_SLICE1  0x8000
+
+/* Firmware flags */
+#define ICSS_SET_RUN_FLAG_VLAN_ENABLE  BIT(0)  /* switch only */
+#define ICSS_SET_RUN_FLAG_FLOOD_UNICASTBIT(1)  /* switch only 
*/
+#define ICSS_SET_RUN_FLAG_PROMISC  BIT(2)  /* MAC only */
+#define ICSS_SET_RUN_FLAG_MULTICAST_PROMISCBIT(3)  /* MAC only */
+
+/* CTRLMMR_ICSSG_RGMII_CTRL register bits */
+#define ICSSG_CTRL_RGMII_ID_MODE   BIT(24)
+
+/* Management packet type */
+#define PRUETH_PKT_TYPE_CMD0x10
+
+/* Number of PRU Cores per Slice */
+#define ICSSG_NUM_PRU_CORES3
+
+static int icssg_gmii_select(struct prueth_priv *priv)
+{
+   struct phy_device *phydev = priv->phydev;
+
+   if (phydev->interface != PHY_INTERFACE_MODE_MII &&
+   phydev->interface < PHY_INTERFACE_MODE_RGMII &&
+  

[PATCH v5 5/5] net: ti: icssg: Add support sending FDB command to update rx_flow_id

2024-04-04 Thread MD Danish Anwar
ICSSG firmware supports FDB commands. Add support to send FDB commands
from driver. Once rx_flow_id is obtained from dma, let firmware know that
we are using this rx_flow_id by sending a FDB command.

Reviewed-by: Ravi Gunasekaran 
Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_config.c | 68 +++
 drivers/net/ti/icssg_config.h | 18 ++
 drivers/net/ti/icssg_prueth.c |  6 
 drivers/net/ti/icssg_prueth.h |  6 
 4 files changed, 98 insertions(+)

diff --git a/drivers/net/ti/icssg_config.c b/drivers/net/ti/icssg_config.c
index 7cf3f737af..5f132d0525 100644
--- a/drivers/net/ti/icssg_config.c
+++ b/drivers/net/ti/icssg_config.c
@@ -9,6 +9,7 @@
 #include "icssg_switch_map.h"
 #include "icss_mii_rt.h"
 #include 
+#include 
 
 /* TX IPG Values to be set for 100M and 1G link speeds.  These values are
  * in ocp_clk cycles. So need change if ocp_clk is changed for a specific
@@ -404,3 +405,70 @@ int emac_set_port_state(struct prueth_priv *priv,
 
return ret;
 }
+
+int icssg_send_fdb_msg(struct prueth_priv *priv, struct mgmt_cmd *cmd,
+  struct mgmt_cmd_rsp *rsp)
+{
+   struct prueth *prueth = priv->prueth;
+   int slice = priv->port_id;
+   int ret, addr;
+
+   addr = icssg_queue_pop(prueth, slice == 0 ?
+  ICSSG_CMD_POP_SLICE0 : ICSSG_CMD_POP_SLICE1);
+   if (addr < 0)
+   return addr;
+
+   /* First 4 bytes have FW owned buffer linking info which should
+* not be touched
+*/
+   memcpy_toio((void __iomem *)prueth->shram.pa + addr + 4, cmd, 
sizeof(*cmd));
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_CMD_PUSH_SLICE0 : ICSSG_CMD_PUSH_SLICE1, addr);
+   ret = read_poll_timeout(icssg_queue_pop, addr, addr >= 0,
+   2000, 2000, prueth, slice == 0 ?
+   ICSSG_RSP_POP_SLICE0 : ICSSG_RSP_POP_SLICE1);
+
+   if (ret) {
+   dev_err(prueth->dev, "Timedout sending HWQ message\n");
+   return ret;
+   }
+
+   memcpy_fromio(rsp, (void __iomem *)prueth->shram.pa + addr, 
sizeof(*rsp));
+   /* Return buffer back for to pool */
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_RSP_PUSH_SLICE0 : ICSSG_RSP_PUSH_SLICE1, addr);
+
+   return 0;
+}
+
+int emac_fdb_flow_id_updated(struct prueth_priv *priv)
+{
+   struct mgmt_cmd_rsp fdb_cmd_rsp = { 0 };
+   struct prueth *prueth = priv->prueth;
+   struct mgmt_cmd fdb_cmd = { 0 };
+   int slice = priv->port_id;
+   int ret = 0;
+
+   fdb_cmd.header = ICSSG_FW_MGMT_CMD_HEADER;
+   fdb_cmd.type   = ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW;
+   fdb_cmd.seqnum = ++(prueth->icssg_hwcmdseq);
+   fdb_cmd.param  = 0;
+
+   fdb_cmd.param |= (slice << 4);
+   fdb_cmd.cmd_args[0] = 0;
+
+   ret = icssg_send_fdb_msg(priv, _cmd, _cmd_rsp);
+   if (ret)
+   return ret;
+
+   if (fdb_cmd.seqnum != fdb_cmd_rsp.seqnum) {
+   dev_err(prueth->dev, "seqnum doesn't match, cmd.seqnum %d != 
rsp.seqnum %d\n",
+   fdb_cmd.seqnum, fdb_cmd_rsp.seqnum);
+   return -EINVAL;
+   }
+
+   if (fdb_cmd_rsp.status == 1)
+   return 0;
+
+   return -EINVAL;
+}
diff --git a/drivers/net/ti/icssg_config.h b/drivers/net/ti/icssg_config.h
index e2859c7b51..d388484c03 100644
--- a/drivers/net/ti/icssg_config.h
+++ b/drivers/net/ti/icssg_config.h
@@ -80,6 +80,7 @@ struct icssg_rxq_ctx {
 #define ICSSG_FW_MGMT_FDB_CMD_TYPE 0x03
 #define ICSSG_FW_MGMT_CMD_TYPE 0x04
 #define ICSSG_FW_MGMT_PKT  0x8000
+#define ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW 0x05
 
 struct icssg_r30_cmd {
u32 cmd[4];
@@ -156,6 +157,23 @@ struct icssg_setclock_desc {
u32 CMP0_new;
 } __packed;
 
+struct mgmt_cmd {
+   u8 param;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
+struct mgmt_cmd_rsp {
+   u32 reserved;
+   u8 status;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
 #define ICSSG_CMD_POP_SLICE0   56
 #define ICSSG_CMD_POP_SLICE1   60
 
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
index 72007aabf2..2639f96063 100644
--- a/drivers/net/ti/icssg_prueth.c
+++ b/drivers/net/ti/icssg_prueth.c
@@ -374,6 +374,12 @@ static int prueth_start(struct udevice *dev)
dev_info(dev, "K3 ICSSG: rflow_id_base: %u, chn_name = %s\n",
 dma_rx_cfg_data->flow_id_base, chn_name);
 
+   ret = emac_fdb_flow_id_updated(priv);
+   if (ret) {
+   dev_err(dev, "Failed to update Rx Flow ID %d", ret);
+   goto phy_fail;
+   }
+
ret = phy_startup(priv->phydev);
if (ret) {
 

[PATCH v5 2/5] net: ti: icssg: Add Firmware config and classification APIs.

2024-04-04 Thread MD Danish Anwar
Add icssg_config.h / .c and icssg_classifier.c files. These are firmware
configuration and classification related files. Add MII helper APIs and
MACROs. These APIs and MACROs will be later used by ICSSG Ethernet driver.
Also introduce icssg_prueth.h which has definition of prueth related
structures.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icss_mii_rt.h  | 192 ++
 drivers/net/ti/icssg_classifier.c | 376 +++
 drivers/net/ti/icssg_config.c | 406 ++
 drivers/net/ti/icssg_config.h | 177 +
 drivers/net/ti/icssg_prueth.h |  83 ++
 5 files changed, 1234 insertions(+)
 create mode 100644 drivers/net/ti/icss_mii_rt.h
 create mode 100644 drivers/net/ti/icssg_classifier.c
 create mode 100644 drivers/net/ti/icssg_config.c
 create mode 100644 drivers/net/ti/icssg_config.h
 create mode 100644 drivers/net/ti/icssg_prueth.h

diff --git a/drivers/net/ti/icss_mii_rt.h b/drivers/net/ti/icss_mii_rt.h
new file mode 100644
index 00..fd95d4d7c1
--- /dev/null
+++ b/drivers/net/ti/icss_mii_rt.h
@@ -0,0 +1,192 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* PRU-ICSS MII_RT register definitions
+ *
+ * Copyright (C) 2015-2024 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#ifndef __NET_PRUSS_MII_RT_H__
+#define __NET_PRUSS_MII_RT_H__
+
+#include 
+
+/* PRUSS_MII_RT Registers */
+#define PRUSS_MII_RT_RXCFG00x0
+#define PRUSS_MII_RT_RXCFG10x4
+#define PRUSS_MII_RT_TXCFG00x10
+#define PRUSS_MII_RT_TXCFG10x14
+#define PRUSS_MII_RT_TX_CRC0   0x20
+#define PRUSS_MII_RT_TX_CRC1   0x24
+#define PRUSS_MII_RT_TX_IPG0   0x30
+#define PRUSS_MII_RT_TX_IPG1   0x34
+#define PRUSS_MII_RT_PRS0  0x38
+#define PRUSS_MII_RT_PRS1  0x3c
+#define PRUSS_MII_RT_RX_FRMS0  0x40
+#define PRUSS_MII_RT_RX_FRMS1  0x44
+#define PRUSS_MII_RT_RX_PCNT0  0x48
+#define PRUSS_MII_RT_RX_PCNT1  0x4c
+#define PRUSS_MII_RT_RX_ERR0   0x50
+#define PRUSS_MII_RT_RX_ERR1   0x54
+
+/* PRUSS_MII_RT_RXCFG0/1 bits */
+#define PRUSS_MII_RT_RXCFG_RX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DISBIT(1)
+#define PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE BIT(2)
+#define PRUSS_MII_RT_RXCFG_RX_MUX_SEL  BIT(3)
+#define PRUSS_MII_RT_RXCFG_RX_L2_ENBIT(4)
+#define PRUSS_MII_RT_RXCFG_RX_BYTE_SWAPBIT(5)
+#define PRUSS_MII_RT_RXCFG_RX_AUTO_FWD_PRE BIT(6)
+#define PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS  BIT(9)
+
+/* PRUSS_MII_RT_TXCFG0/1 bits */
+#define PRUSS_MII_RT_TXCFG_TX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLEBIT(1)
+#define PRUSS_MII_RT_TXCFG_TX_EN_MODE  BIT(2)
+#define PRUSS_MII_RT_TXCFG_TX_BYTE_SWAPBIT(3)
+#define PRUSS_MII_RT_TXCFG_TX_MUX_SEL  BIT(8)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_SEQUENCEBIT(9)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_ESC_ERR BIT(10)
+#define PRUSS_MII_RT_TXCFG_TX_32_MODE_EN   BIT(11)
+#define PRUSS_MII_RT_TXCFG_TX_IPG_WIRE_CLK_EN  BIT(12) /* SR2.0 onwards */
+
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT16
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_MASK GENMASK(25, 16)
+
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT  28
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK   GENMASK(30, 28)
+
+/* PRUSS_MII_RT_TX_IPG0/1 bits */
+#define PRUSS_MII_RT_TX_IPG_IPG_SHIFT  0
+#define PRUSS_MII_RT_TX_IPG_IPG_MASK   GENMASK(9, 0)
+
+/* PRUSS_MII_RT_PRS0/1 bits */
+#define PRUSS_MII_RT_PRS_COL   BIT(0)
+#define PRUSS_MII_RT_PRS_CRS   BIT(1)
+
+/* PRUSS_MII_RT_RX_FRMS0/1 bits */
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT 0
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK  GENMASK(15, 0)
+
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT 16
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK  GENMASK(31, 16)
+
+/* Min/Max in MII_RT_RX_FRMS */
+/* For EMAC and Switch */
+#define PRUSS_MII_RT_RX_FRMS_MAX   (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM   (64)
+
+/* for HSR and PRP */
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_LRE   (PRUSS_MII_RT_RX_FRMS_MAX + \
+ICSS_LRE_TAG_RCT_SIZE)
+/* PRUSS_MII_RT_RX_PCNT0/1 bits */
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_SHIFT0
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_MASK GENMASK(3, 0)
+
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_SHIFT4
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_MASK GENMASK(7, 4)
+
+/* PRUSS_MII_RT_RX_ERR0/1 bits */
+#define PRUSS_MII_RT_RX_ERR_MIN_PCNT_ERR   BIT(0)
+#define PRUSS_MII_RT_RX_ERR_MAX_PCNT_ERR   BIT(1)
+#define PRUSS_MII_RT_RX_ERR_MIN_FRM_ERRBIT(2)
+#define PRUSS_MII_RT_RX_ERR_MAX_FRM_ERRBIT(3)
+
+#define ICSSG_CFG_OFFSET   0
+#define RGMII_CFG_OFFSET   4
+
+/* Constant to choose between MII0 and MII1 */
+#define ICSS_MII0  0
+#define ICSS_MII1

[PATCH v5 3/5] net: ti: icssg: Add icssg queues APIs and macros

2024-04-04 Thread MD Danish Anwar
Add icssg_queue.c file. This file introduces macros and APIs related to
ICSSG queues. These will be used by ICSSG Ethernet driver.

Reviewed-by: Ravi Gunasekaran 
Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_prueth.h |  5 
 drivers/net/ti/icssg_queues.c | 51 +++
 2 files changed, 56 insertions(+)
 create mode 100644 drivers/net/ti/icssg_queues.c

diff --git a/drivers/net/ti/icssg_prueth.h b/drivers/net/ti/icssg_prueth.h
index 33137739a7..fc0f557db3 100644
--- a/drivers/net/ti/icssg_prueth.h
+++ b/drivers/net/ti/icssg_prueth.h
@@ -80,4 +80,9 @@ void icssg_config_ipg(struct prueth_priv *priv, int speed, 
int mii);
 int icssg_config(struct prueth_priv *priv);
 int emac_set_port_state(struct prueth_priv *priv, enum icssg_port_state_cmd 
cmd);
 
+/* Buffer queue helpers */
+int icssg_queue_pop(struct prueth *prueth, u8 queue);
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr);
+u32 icssg_queue_level(struct prueth *prueth, int queue);
+
 #endif /* __NET_TI_ICSSG_PRUETH_H */
diff --git a/drivers/net/ti/icssg_queues.c b/drivers/net/ti/icssg_queues.c
new file mode 100644
index 00..fc4d33dbb2
--- /dev/null
+++ b/drivers/net/ti/icssg_queues.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/* ICSSG Buffer queue helpers
+ *
+ * Copyright (C) 2018-2024 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include 
+#include 
+#include "icssg_prueth.h"
+
+#define ICSSG_QUEUES_MAX   64
+#define ICSSG_QUEUE_OFFSET 0xd00
+#define ICSSG_QUEUE_PEEK_OFFSET0xe00
+#define ICSSG_QUEUE_CNT_OFFSET 0xe40
+#defineICSSG_QUEUE_RESET_OFFSET0xf40
+
+int icssg_queue_pop(struct prueth *prueth, u8 queue)
+{
+   u32 val, cnt;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+   if (!cnt)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, );
+
+   return val;
+}
+
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
+{
+   if (queue >= ICSSG_QUEUES_MAX)
+   return;
+
+   regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
+}
+
+u32 icssg_queue_level(struct prueth *prueth, int queue)
+{
+   u32 reg;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return 0;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+
+   return reg;
+}
-- 
2.34.1



[PATCH v5 0/5] Introduce ICSSG Ethernet driver

2024-04-04 Thread MD Danish Anwar
Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
AM654 SR2.0.

The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
support for ICSSG driver in uboot.

This series has been tested on AM65x SR2.0, and the ICSSG interface is
able to ping / dhcp and boot kernel using tftp in uboot.

To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
cores and RPROC cores need to be booted with the firmware. This step is
done inside driver similar to kernel.

The remoteproc driver uses request_fw_into_buf() API from fs-loader driver
to load and start rproc with the required firmwares.

This series only introduces driver files. The device tree and config
changes to enable ICSSG driver will be introduced later.

This is v5 of the series [1].

Changes from v4 [4] to v5:
*) Fixed URL(s/http/https) in all the patches as asked by
   Ravi Gunasekaran 
*) Collected RB tags of Ravi Gunasekaran  for patch
   1/5, 3/5 and 5/5.
*) Used PKTSIZE macro instead of hardcoding 1522 in the definition of
   UDMA_RX_BUF_SIZE in patch 4/5

Changes from v3 [3] to v4:
*) Dropped the dependncy patches and posted them seprately.
*) Dropped the DTS and config patches, will post them seprately.
*) Modified patch 4/5 to have multi port independent MAC mode support.
*) Rebased the series on latest u-boot/next.

Changes from v2 [2] to v3:
*) No functional changes.
*) Rebased the series on latest u-boot/next.
*) Dropped the RFC tag.

Changes from v1 [1] to v2:
*) Modified the driver to load the firmware inside the driver only instead
   of loading the firmware using commands at u-boot prompt. Added patch
   3/16 for this.
*) Rebased the series on the latest u-boot/next.
*) Modified conf-0 configuration in k3-am65x-binman.dtsi as suggested by
   Roger.
*) Dropped patch [5] as the patch is no longer needed.
*) Added patch 2/15 to modify fs-loader driver to use fw_storage_interface
   env instead of storage_interface and keep the env storage_interface as
   fallback as suggested by Roger.
*) Added patch 15/15 to set default values to env fw_storage_interface and
   fw_dev_part.

[1] https://lore.kernel.org/all/20231219103418.3445886-1-danishan...@ti.com/
[2] https://lore.kernel.org/all/20240111070611.342701-1-danishan...@ti.com/
[3] https://lore.kernel.org/all/20240124064930.1787929-1-danishan...@ti.com/
[4] https://lore.kernel.org/all/20240327052841.1692469-1-danishan...@ti.com/
[5] https://lore.kernel.org/all/20231219103418.3445886-16-danishan...@ti.com/

Thanks and Regards,
MD Danish Anwar

MD Danish Anwar (5):
  net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.
  net: ti: icssg: Add Firmware config and classification APIs.
  net: ti: icssg: Add icssg queues APIs and macros
  net: ti: icssg: Add ICSSG ethernet driver
  net: ti: icssg: Add support sending FDB command to update rx_flow_id

 arch/arm/mach-k3/common.c |  11 +
 drivers/net/ti/Kconfig|  13 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icss_mii_rt.h  | 192 +
 drivers/net/ti/icssg_classifier.c | 376 
 drivers/net/ti/icssg_config.c | 474 
 drivers/net/ti/icssg_config.h | 195 +
 drivers/net/ti/icssg_prueth.c | 691 ++
 drivers/net/ti/icssg_prueth.h |  97 +
 drivers/net/ti/icssg_queues.c |  51 +++
 drivers/net/ti/icssg_switch_map.h | 209 +
 11 files changed, 2310 insertions(+)
 create mode 100644 drivers/net/ti/icss_mii_rt.h
 create mode 100644 drivers/net/ti/icssg_classifier.c
 create mode 100644 drivers/net/ti/icssg_config.c
 create mode 100644 drivers/net/ti/icssg_config.h
 create mode 100644 drivers/net/ti/icssg_prueth.c
 create mode 100644 drivers/net/ti/icssg_prueth.h
 create mode 100644 drivers/net/ti/icssg_queues.c
 create mode 100644 drivers/net/ti/icssg_switch_map.h


base-commit: bc39e06778168a34bb4e0a34fbee4edbde4414d8
-- 
2.34.1



[PATCH v5 1/5] net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.

2024-04-04 Thread MD Danish Anwar
Add firmware interface related headers and macros for ICSSG Ethernet
driver. These macros will be later used by the ICSSG ethernet driver.

Reviewed-by: Ravi Gunasekaran 
Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_switch_map.h | 209 ++
 1 file changed, 209 insertions(+)
 create mode 100644 drivers/net/ti/icssg_switch_map.h

diff --git a/drivers/net/ti/icssg_switch_map.h 
b/drivers/net/ti/icssg_switch_map.h
new file mode 100644
index 00..b62c51407b
--- /dev/null
+++ b/drivers/net/ti/icssg_switch_map.h
@@ -0,0 +1,209 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Texas Instruments ICSSG Ethernet driver
+ *
+ * Copyright (C) 2020-2024 Texas Instruments Incorporated - https://www.ti.com/
+ *
+ */
+
+#ifndef __NET_TI_ICSSG_SWITCH_MAP_H
+#define __NET_TI_ICSSG_SWITCH_MAP_H
+
+/*Time after which FDB entries are checked for aged out values. Value in 
nanoseconds*/
+#define FDB_AGEING_TIMEOUT_OFFSET  0x0014
+
+/*default VLAN tag for Host Port*/
+#define HOST_PORT_DF_VLAN_OFFSET   0x001C
+
+/*Same as HOST_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT0_DEFAULT_VLAN_OFFSET
HOST_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P1 Port*/
+#define P1_PORT_DF_VLAN_OFFSET 0x0020
+
+/*Same as P1_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT1_DEFAULT_VLAN_OFFSET
P1_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P2 Port*/
+#define P2_PORT_DF_VLAN_OFFSET 0x0024
+
+/*Same as P2_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT2_DEFAULT_VLAN_OFFSET
P2_PORT_DF_VLAN_OFFSET
+
+/*VLAN-FID Table offset. 4096 VIDs. 2B per VID = 8KB = 0x2000*/
+#define VLAN_STATIC_REG_TABLE_OFFSET   0x0100
+
+/*VLAN-FID Table offset for EMAC*/
+#define EMAC_ICSSG_SWITCH_DEFAULT_VLAN_TABLE_OFFSET
VLAN_STATIC_REG_TABLE_OFFSET
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_HI  0x2104
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_LO  0x2F6C
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_HI  0x3DD4
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_LO  0x4C3C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_HI  0x5AA4
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_LO  0x5F0C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_HI  0x6374
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_LO  0x67DC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD0 0x7AAC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD1 0x7EAC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_CYCLECOUNT_OFFSET   0x83EC
+
+/*IEP count hi roll over count*/
+#define TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET0x83F4
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET   0x83F8
+
+/*Set clock descriptor*/
+#define TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET0x83FC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET 0x843C
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_COUNT_OFFSET  0x8440
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET 0x8444
+
+/*Control variable to generate SYNC1*/
+#define TIMESYNC_FW_WC_ISOM_PIN_SIGNAL_EN_OFFSET   0x844C
+
+/*SystemTime Sync0 periodicity*/
+#define TIMESYNC_FW_ST_SYNCOUT_PERIOD_OFFSET   0x8450
+
+/*pktTxDelay for P1 = link speed dependent p1 mac delay + p1 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P1_OFFSET0x8454
+
+/*pktTxDelay for P2 = link speed dependent p2 mac delay + p2 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P2_OFFSET0x8458
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_PNFW_OFFSET0x845C
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_TIMESYNCFW_OFFSET  0x8460
+
+/*New list is copied at this time*/
+#define TAS_CONFIG_CHANGE_TIME 0x000C
+
+/*config change error counter*/
+#define TAS_CONFIG_CHANGE_ERROR_COUNTER0x0014
+
+/*TAS List update pending flag*/
+#define TAS_CONFIG_PENDING 0x0018
+
+/*TAS list update trigger flag*/
+#define TAS_CONFIG_CHANGE  0x0019
+
+/*List length for new TAS schedule*/
+#define TAS_ADMIN_LIST_LENGTH  0x001A
+
+/*Currently active

[PATCH v4 4/5] net: ti: icssg: Add ICSSG ethernet driver

2024-03-26 Thread MD Danish Anwar
This is the PRUSS Ethernet driver for TI AM654 Sr2.0 and laterSoCs with
the ICSSG PRU Sub-system running EMAC firmware. ICSSG Subsystem supports
two slices per instance. This driver caters to both slices / ports of
the icssg subsystem.

Since it is not possible for Ethernet driver to register more than one
port for a given instance, this patch introduces top level PRUETH as
UCLASS_MISC and binds UCLASS_ETH to individual ports in order to support
bringing up more than one Ethernet interface in U-Boot.

Since top level driver is UCLASS_MISC, board files would need to
instantiate the driver explicitly.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/mach-k3/common.c |  11 +
 drivers/net/ti/Kconfig|  13 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icssg_prueth.c | 685 ++
 drivers/net/ti/icssg_prueth.h |   3 +
 5 files changed, 713 insertions(+)
 create mode 100644 drivers/net/ti/icssg_prueth.c

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index b0fb87b97a..d151277d6d 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -270,6 +270,17 @@ int misc_init_r(void)
printf("Failed to probe am65_cpsw_nuss driver\n");
}
 
+   if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
+   struct udevice *dev;
+   int ret;
+
+   ret = uclass_get_device_by_driver(UCLASS_MISC,
+ DM_DRIVER_GET(prueth),
+ );
+   if (ret)
+   printf("Failed to probe prueth driver\n");
+   }
+
/* Default FIT boot on HS-SE devices */
if (get_device_type() == K3_DEVICE_TYPE_HS_SE)
env_set("boot_fit", "1");
diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index 72eccc99e5..ddfa95a0b7 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -57,3 +57,16 @@ config MDIO_TI_CPSW
help
  This driver supports the TI CPSW MDIO interface found in various
  TI SoCs.
+
+config TI_ICSSG_PRUETH
+   bool "TI Gigabit PRU Ethernet driver"
+   depends on ARCH_K3
+   imply DM_MDIO
+   imply MISC_INIT_R
+   imply MISC
+   imply MDIO_TI_CPSW
+   select PHYLIB
+   select FS_LOADER
+   help
+ Support Gigabit Ethernet ports over the ICSSG PRU Subsystem
+ This subsystem is available starting with the AM65 platform.
diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
index 30c4c4b6d5..b2b3aa3b18 100644
--- a/drivers/net/ti/Makefile
+++ b/drivers/net/ti/Makefile
@@ -7,3 +7,4 @@ obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
 obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
 obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o
 obj-$(CONFIG_MDIO_TI_CPSW) += cpsw_mdio.o
+obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg_prueth.o icssg_classifier.o 
icssg_config.o icssg_queues.o
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
new file mode 100644
index 00..d22a56c217
--- /dev/null
+++ b/drivers/net/ti/icssg_prueth.c
@@ -0,0 +1,685 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments K3 AM65 PRU Ethernet Driver
+ *
+ * Copyright (C) 2018-2024, Texas Instruments, Incorporated
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "icssg_prueth.h"
+#include "icss_mii_rt.h"
+
+#define ICSS_SLICE0 0
+#define ICSS_SLICE1 1
+
+#ifdef PKTSIZE_ALIGN
+#define UDMA_RX_BUF_SIZE PKTSIZE_ALIGN
+#else
+#define UDMA_RX_BUF_SIZE ALIGN(1522, ARCH_DMA_MINALIGN)
+#endif
+
+#ifdef PKTBUFSRX
+#define UDMA_RX_DESC_NUM PKTBUFSRX
+#else
+#define UDMA_RX_DESC_NUM 4
+#endif
+
+/* Config region lies in shared RAM */
+#define ICSS_CONFIG_OFFSET_SLICE0  0
+#define ICSS_CONFIG_OFFSET_SLICE1  0x8000
+
+/* Firmware flags */
+#define ICSS_SET_RUN_FLAG_VLAN_ENABLE  BIT(0)  /* switch only */
+#define ICSS_SET_RUN_FLAG_FLOOD_UNICASTBIT(1)  /* switch only 
*/
+#define ICSS_SET_RUN_FLAG_PROMISC  BIT(2)  /* MAC only */
+#define ICSS_SET_RUN_FLAG_MULTICAST_PROMISCBIT(3)  /* MAC only */
+
+/* CTRLMMR_ICSSG_RGMII_CTRL register bits */
+#define ICSSG_CTRL_RGMII_ID_MODE   BIT(24)
+
+/* Management packet type */
+#define PRUETH_PKT_TYPE_CMD0x10
+
+/* Number of PRU Cores per Slice */
+#define ICSSG_NUM_PRU_CORES3
+
+static int icssg_gmii_select(struct prueth_priv *priv)
+{
+   struct phy_device *phydev = priv->phydev;
+
+   if (phydev->interface != PHY_INTERFACE_MODE_MII &&
+   phydev->interface < PHY_INTERFACE_MODE_RGMII &&
+   phydev->inter

[PATCH v4 5/5] net: ti: icssg: Add support sending FDB command to update rx_flow_id

2024-03-26 Thread MD Danish Anwar
ICSSG firmware supports FDB commands. Add support to send FDB commands
from driver. Once rx_flow_id is obtained from dma, let firmware know that
we are using this rx_flow_id by sending a FDB command.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_config.c | 68 +++
 drivers/net/ti/icssg_config.h | 18 ++
 drivers/net/ti/icssg_prueth.c |  6 
 drivers/net/ti/icssg_prueth.h |  6 
 4 files changed, 98 insertions(+)

diff --git a/drivers/net/ti/icssg_config.c b/drivers/net/ti/icssg_config.c
index b0ba870189..70c67e44b9 100644
--- a/drivers/net/ti/icssg_config.c
+++ b/drivers/net/ti/icssg_config.c
@@ -9,6 +9,7 @@
 #include "icssg_switch_map.h"
 #include "icss_mii_rt.h"
 #include 
+#include 
 
 /* TX IPG Values to be set for 100M and 1G link speeds.  These values are
  * in ocp_clk cycles. So need change if ocp_clk is changed for a specific
@@ -404,3 +405,70 @@ int emac_set_port_state(struct prueth_priv *priv,
 
return ret;
 }
+
+int icssg_send_fdb_msg(struct prueth_priv *priv, struct mgmt_cmd *cmd,
+  struct mgmt_cmd_rsp *rsp)
+{
+   struct prueth *prueth = priv->prueth;
+   int slice = priv->port_id;
+   int ret, addr;
+
+   addr = icssg_queue_pop(prueth, slice == 0 ?
+  ICSSG_CMD_POP_SLICE0 : ICSSG_CMD_POP_SLICE1);
+   if (addr < 0)
+   return addr;
+
+   /* First 4 bytes have FW owned buffer linking info which should
+* not be touched
+*/
+   memcpy_toio((void __iomem *)prueth->shram.pa + addr + 4, cmd, 
sizeof(*cmd));
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_CMD_PUSH_SLICE0 : ICSSG_CMD_PUSH_SLICE1, addr);
+   ret = read_poll_timeout(icssg_queue_pop, addr, addr >= 0,
+   2000, 2000, prueth, slice == 0 ?
+   ICSSG_RSP_POP_SLICE0 : ICSSG_RSP_POP_SLICE1);
+
+   if (ret) {
+   dev_err(prueth->dev, "Timedout sending HWQ message\n");
+   return ret;
+   }
+
+   memcpy_fromio(rsp, (void __iomem *)prueth->shram.pa + addr, 
sizeof(*rsp));
+   /* Return buffer back for to pool */
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_RSP_PUSH_SLICE0 : ICSSG_RSP_PUSH_SLICE1, addr);
+
+   return 0;
+}
+
+int emac_fdb_flow_id_updated(struct prueth_priv *priv)
+{
+   struct mgmt_cmd_rsp fdb_cmd_rsp = { 0 };
+   struct prueth *prueth = priv->prueth;
+   struct mgmt_cmd fdb_cmd = { 0 };
+   int slice = priv->port_id;
+   int ret = 0;
+
+   fdb_cmd.header = ICSSG_FW_MGMT_CMD_HEADER;
+   fdb_cmd.type   = ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW;
+   fdb_cmd.seqnum = ++(prueth->icssg_hwcmdseq);
+   fdb_cmd.param  = 0;
+
+   fdb_cmd.param |= (slice << 4);
+   fdb_cmd.cmd_args[0] = 0;
+
+   ret = icssg_send_fdb_msg(priv, _cmd, _cmd_rsp);
+   if (ret)
+   return ret;
+
+   if (fdb_cmd.seqnum != fdb_cmd_rsp.seqnum) {
+   dev_err(prueth->dev, "seqnum doesn't match, cmd.seqnum %d != 
rsp.seqnum %d\n",
+   fdb_cmd.seqnum, fdb_cmd_rsp.seqnum);
+   return -EINVAL;
+   }
+
+   if (fdb_cmd_rsp.status == 1)
+   return 0;
+
+   return -EINVAL;
+}
diff --git a/drivers/net/ti/icssg_config.h b/drivers/net/ti/icssg_config.h
index 412dbf51c7..0dcf025358 100644
--- a/drivers/net/ti/icssg_config.h
+++ b/drivers/net/ti/icssg_config.h
@@ -80,6 +80,7 @@ struct icssg_rxq_ctx {
 #define ICSSG_FW_MGMT_FDB_CMD_TYPE 0x03
 #define ICSSG_FW_MGMT_CMD_TYPE 0x04
 #define ICSSG_FW_MGMT_PKT  0x8000
+#define ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW 0x05
 
 struct icssg_r30_cmd {
u32 cmd[4];
@@ -156,6 +157,23 @@ struct icssg_setclock_desc {
u32 CMP0_new;
 } __packed;
 
+struct mgmt_cmd {
+   u8 param;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
+struct mgmt_cmd_rsp {
+   u32 reserved;
+   u8 status;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
 #define ICSSG_CMD_POP_SLICE0   56
 #define ICSSG_CMD_POP_SLICE1   60
 
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
index d22a56c217..ce108129c5 100644
--- a/drivers/net/ti/icssg_prueth.c
+++ b/drivers/net/ti/icssg_prueth.c
@@ -374,6 +374,12 @@ static int prueth_start(struct udevice *dev)
dev_info(dev, "K3 ICSSG: rflow_id_base: %u, chn_name = %s\n",
 dma_rx_cfg_data->flow_id_base, chn_name);
 
+   ret = emac_fdb_flow_id_updated(priv);
+   if (ret) {
+   dev_err(dev, "Failed to update Rx Flow ID %d", ret);
+   goto phy_fail;
+   }
+
ret = phy_startup(priv->phydev);
if (ret) {
dev_err(dev, 

[PATCH v4 3/5] net: ti: icssg: Add icssg queues APIs and macros

2024-03-26 Thread MD Danish Anwar
Add icssg_queue.c file. This file introduces macros and APIs related to
ICSSG queues. These will be used by ICSSG Ethernet driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_prueth.h |  5 
 drivers/net/ti/icssg_queues.c | 51 +++
 2 files changed, 56 insertions(+)
 create mode 100644 drivers/net/ti/icssg_queues.c

diff --git a/drivers/net/ti/icssg_prueth.h b/drivers/net/ti/icssg_prueth.h
index a7627a77d8..42686b8c79 100644
--- a/drivers/net/ti/icssg_prueth.h
+++ b/drivers/net/ti/icssg_prueth.h
@@ -80,4 +80,9 @@ void icssg_config_ipg(struct prueth_priv *priv, int speed, 
int mii);
 int icssg_config(struct prueth_priv *priv);
 int emac_set_port_state(struct prueth_priv *priv, enum icssg_port_state_cmd 
cmd);
 
+/* Buffer queue helpers */
+int icssg_queue_pop(struct prueth *prueth, u8 queue);
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr);
+u32 icssg_queue_level(struct prueth *prueth, int queue);
+
 #endif /* __NET_TI_ICSSG_PRUETH_H */
diff --git a/drivers/net/ti/icssg_queues.c b/drivers/net/ti/icssg_queues.c
new file mode 100644
index 00..fc4d33dbb2
--- /dev/null
+++ b/drivers/net/ti/icssg_queues.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/* ICSSG Buffer queue helpers
+ *
+ * Copyright (C) 2018-2024 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include 
+#include 
+#include "icssg_prueth.h"
+
+#define ICSSG_QUEUES_MAX   64
+#define ICSSG_QUEUE_OFFSET 0xd00
+#define ICSSG_QUEUE_PEEK_OFFSET0xe00
+#define ICSSG_QUEUE_CNT_OFFSET 0xe40
+#defineICSSG_QUEUE_RESET_OFFSET0xf40
+
+int icssg_queue_pop(struct prueth *prueth, u8 queue)
+{
+   u32 val, cnt;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+   if (!cnt)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, );
+
+   return val;
+}
+
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
+{
+   if (queue >= ICSSG_QUEUES_MAX)
+   return;
+
+   regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
+}
+
+u32 icssg_queue_level(struct prueth *prueth, int queue)
+{
+   u32 reg;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return 0;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+
+   return reg;
+}
-- 
2.34.1



[PATCH v4 2/5] net: ti: icssg: Add Firmware config and classification APIs.

2024-03-26 Thread MD Danish Anwar
Add icssg_config.h / .c and icssg_classifier.c files. These are firmware
configuration and classification related files. Add MII helper APIs and
MACROs. These APIs and MACROs will be later used by ICSSG Ethernet driver.
Also introduce icssg_prueth.h which has definition of prueth related
structures.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icss_mii_rt.h  | 192 ++
 drivers/net/ti/icssg_classifier.c | 376 +++
 drivers/net/ti/icssg_config.c | 406 ++
 drivers/net/ti/icssg_config.h | 177 +
 drivers/net/ti/icssg_prueth.h |  83 ++
 5 files changed, 1234 insertions(+)
 create mode 100644 drivers/net/ti/icss_mii_rt.h
 create mode 100644 drivers/net/ti/icssg_classifier.c
 create mode 100644 drivers/net/ti/icssg_config.c
 create mode 100644 drivers/net/ti/icssg_config.h
 create mode 100644 drivers/net/ti/icssg_prueth.h

diff --git a/drivers/net/ti/icss_mii_rt.h b/drivers/net/ti/icss_mii_rt.h
new file mode 100644
index 00..4a78394701
--- /dev/null
+++ b/drivers/net/ti/icss_mii_rt.h
@@ -0,0 +1,192 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* PRU-ICSS MII_RT register definitions
+ *
+ * Copyright (C) 2015-2024 Texas Instruments Incorporated - http://www.ti.com
+ */
+
+#ifndef __NET_PRUSS_MII_RT_H__
+#define __NET_PRUSS_MII_RT_H__
+
+#include 
+
+/* PRUSS_MII_RT Registers */
+#define PRUSS_MII_RT_RXCFG00x0
+#define PRUSS_MII_RT_RXCFG10x4
+#define PRUSS_MII_RT_TXCFG00x10
+#define PRUSS_MII_RT_TXCFG10x14
+#define PRUSS_MII_RT_TX_CRC0   0x20
+#define PRUSS_MII_RT_TX_CRC1   0x24
+#define PRUSS_MII_RT_TX_IPG0   0x30
+#define PRUSS_MII_RT_TX_IPG1   0x34
+#define PRUSS_MII_RT_PRS0  0x38
+#define PRUSS_MII_RT_PRS1  0x3c
+#define PRUSS_MII_RT_RX_FRMS0  0x40
+#define PRUSS_MII_RT_RX_FRMS1  0x44
+#define PRUSS_MII_RT_RX_PCNT0  0x48
+#define PRUSS_MII_RT_RX_PCNT1  0x4c
+#define PRUSS_MII_RT_RX_ERR0   0x50
+#define PRUSS_MII_RT_RX_ERR1   0x54
+
+/* PRUSS_MII_RT_RXCFG0/1 bits */
+#define PRUSS_MII_RT_RXCFG_RX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DISBIT(1)
+#define PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE BIT(2)
+#define PRUSS_MII_RT_RXCFG_RX_MUX_SEL  BIT(3)
+#define PRUSS_MII_RT_RXCFG_RX_L2_ENBIT(4)
+#define PRUSS_MII_RT_RXCFG_RX_BYTE_SWAPBIT(5)
+#define PRUSS_MII_RT_RXCFG_RX_AUTO_FWD_PRE BIT(6)
+#define PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS  BIT(9)
+
+/* PRUSS_MII_RT_TXCFG0/1 bits */
+#define PRUSS_MII_RT_TXCFG_TX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLEBIT(1)
+#define PRUSS_MII_RT_TXCFG_TX_EN_MODE  BIT(2)
+#define PRUSS_MII_RT_TXCFG_TX_BYTE_SWAPBIT(3)
+#define PRUSS_MII_RT_TXCFG_TX_MUX_SEL  BIT(8)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_SEQUENCEBIT(9)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_ESC_ERR BIT(10)
+#define PRUSS_MII_RT_TXCFG_TX_32_MODE_EN   BIT(11)
+#define PRUSS_MII_RT_TXCFG_TX_IPG_WIRE_CLK_EN  BIT(12) /* SR2.0 onwards */
+
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT16
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_MASK GENMASK(25, 16)
+
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT  28
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK   GENMASK(30, 28)
+
+/* PRUSS_MII_RT_TX_IPG0/1 bits */
+#define PRUSS_MII_RT_TX_IPG_IPG_SHIFT  0
+#define PRUSS_MII_RT_TX_IPG_IPG_MASK   GENMASK(9, 0)
+
+/* PRUSS_MII_RT_PRS0/1 bits */
+#define PRUSS_MII_RT_PRS_COL   BIT(0)
+#define PRUSS_MII_RT_PRS_CRS   BIT(1)
+
+/* PRUSS_MII_RT_RX_FRMS0/1 bits */
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT 0
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK  GENMASK(15, 0)
+
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT 16
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK  GENMASK(31, 16)
+
+/* Min/Max in MII_RT_RX_FRMS */
+/* For EMAC and Switch */
+#define PRUSS_MII_RT_RX_FRMS_MAX   (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM   (64)
+
+/* for HSR and PRP */
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_LRE   (PRUSS_MII_RT_RX_FRMS_MAX + \
+ICSS_LRE_TAG_RCT_SIZE)
+/* PRUSS_MII_RT_RX_PCNT0/1 bits */
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_SHIFT0
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_MASK GENMASK(3, 0)
+
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_SHIFT4
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_MASK GENMASK(7, 4)
+
+/* PRUSS_MII_RT_RX_ERR0/1 bits */
+#define PRUSS_MII_RT_RX_ERR_MIN_PCNT_ERR   BIT(0)
+#define PRUSS_MII_RT_RX_ERR_MAX_PCNT_ERR   BIT(1)
+#define PRUSS_MII_RT_RX_ERR_MIN_FRM_ERRBIT(2)
+#define PRUSS_MII_RT_RX_ERR_MAX_FRM_ERRBIT(3)
+
+#define ICSSG_CFG_OFFSET   0
+#define RGMII_CFG_OFFSET   4
+
+/* Constant to choose between MII0 and MII1 */
+#define ICSS_MII0  0
+#define ICSS_MII1

[PATCH v4 1/5] net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.

2024-03-26 Thread MD Danish Anwar
Add firmware interface related headers and macros for ICSSG Ethernet
driver. These macros will be later used by the ICSSG ethernet driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_switch_map.h | 209 ++
 1 file changed, 209 insertions(+)
 create mode 100644 drivers/net/ti/icssg_switch_map.h

diff --git a/drivers/net/ti/icssg_switch_map.h 
b/drivers/net/ti/icssg_switch_map.h
new file mode 100644
index 00..b62c51407b
--- /dev/null
+++ b/drivers/net/ti/icssg_switch_map.h
@@ -0,0 +1,209 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Texas Instruments ICSSG Ethernet driver
+ *
+ * Copyright (C) 2020-2024 Texas Instruments Incorporated - https://www.ti.com/
+ *
+ */
+
+#ifndef __NET_TI_ICSSG_SWITCH_MAP_H
+#define __NET_TI_ICSSG_SWITCH_MAP_H
+
+/*Time after which FDB entries are checked for aged out values. Value in 
nanoseconds*/
+#define FDB_AGEING_TIMEOUT_OFFSET  0x0014
+
+/*default VLAN tag for Host Port*/
+#define HOST_PORT_DF_VLAN_OFFSET   0x001C
+
+/*Same as HOST_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT0_DEFAULT_VLAN_OFFSET
HOST_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P1 Port*/
+#define P1_PORT_DF_VLAN_OFFSET 0x0020
+
+/*Same as P1_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT1_DEFAULT_VLAN_OFFSET
P1_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P2 Port*/
+#define P2_PORT_DF_VLAN_OFFSET 0x0024
+
+/*Same as P2_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT2_DEFAULT_VLAN_OFFSET
P2_PORT_DF_VLAN_OFFSET
+
+/*VLAN-FID Table offset. 4096 VIDs. 2B per VID = 8KB = 0x2000*/
+#define VLAN_STATIC_REG_TABLE_OFFSET   0x0100
+
+/*VLAN-FID Table offset for EMAC*/
+#define EMAC_ICSSG_SWITCH_DEFAULT_VLAN_TABLE_OFFSET
VLAN_STATIC_REG_TABLE_OFFSET
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_HI  0x2104
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_LO  0x2F6C
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_HI  0x3DD4
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_LO  0x4C3C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_HI  0x5AA4
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_LO  0x5F0C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_HI  0x6374
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_LO  0x67DC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD0 0x7AAC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD1 0x7EAC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_CYCLECOUNT_OFFSET   0x83EC
+
+/*IEP count hi roll over count*/
+#define TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET0x83F4
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET   0x83F8
+
+/*Set clock descriptor*/
+#define TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET0x83FC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET 0x843C
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_COUNT_OFFSET  0x8440
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET 0x8444
+
+/*Control variable to generate SYNC1*/
+#define TIMESYNC_FW_WC_ISOM_PIN_SIGNAL_EN_OFFSET   0x844C
+
+/*SystemTime Sync0 periodicity*/
+#define TIMESYNC_FW_ST_SYNCOUT_PERIOD_OFFSET   0x8450
+
+/*pktTxDelay for P1 = link speed dependent p1 mac delay + p1 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P1_OFFSET0x8454
+
+/*pktTxDelay for P2 = link speed dependent p2 mac delay + p2 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P2_OFFSET0x8458
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_PNFW_OFFSET0x845C
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_TIMESYNCFW_OFFSET  0x8460
+
+/*New list is copied at this time*/
+#define TAS_CONFIG_CHANGE_TIME 0x000C
+
+/*config change error counter*/
+#define TAS_CONFIG_CHANGE_ERROR_COUNTER0x0014
+
+/*TAS List update pending flag*/
+#define TAS_CONFIG_PENDING 0x0018
+
+/*TAS list update trigger flag*/
+#define TAS_CONFIG_CHANGE  0x0019
+
+/*List length for new TAS schedule*/
+#define TAS_ADMIN_LIST_LENGTH  0x001A
+
+/*Currently active TAS list index*/
+#define

[PATCH v4 0/5] Introduce ICSSG Ethernet driver

2024-03-26 Thread MD Danish Anwar
Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
AM654 SR2.0.

The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
support for ICSSG driver in uboot.

This series has been tested on AM65x SR2.0, and the ICSSG interface is
able to ping / dhcp and boot kernel using tftp in uboot.

To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
cores and RPROC cores need to be booted with the firmware. This step is
done inside driver similar to kernel.

The remoteproc driver uses request_fw_into_buf() API from fs-loader driver
to load and start rproc with the required firmwares.

This series only introduces driver files. The device tree and config
changes to enable ICSSG driver will be introduced later.

This is v4 of the series [1].

Changes from v3 [3] to v4:
*) Dropped the dependncy patches and posted them seprately.
*) Dropped the DTS and config patches, will post them seprately.
*) Modified patch 4/5 to have multi port independent MAC mode support.
*) Rebased the series on latest u-boot/next.

Changes from v2 [2] to v3:
*) No functional changes.
*) Rebased the series on latest u-boot/next.
*) Dropped the RFC tag.

Changes from v1 [1] to v2:
*) Modified the driver to load the firmware inside the driver only instead
   of loading the firmware using commands at u-boot prompt. Added patch
   3/16 for this.
*) Rebased the series on the latest u-boot/next.
*) Modified conf-0 configuration in k3-am65x-binman.dtsi as suggested by
   Roger.
*) Dropped patch [4] as the patch is no longer needed.
*) Added patch 2/15 to modify fs-loader driver to use fw_storage_interface
   env instead of storage_interface and keep the env storage_interface as
   fallback as suggested by Roger.
*) Added patch 15/15 to set default values to env fw_storage_interface and
   fw_dev_part.

[1] https://lore.kernel.org/all/20231219103418.3445886-1-danishan...@ti.com/
[2] https://lore.kernel.org/all/20240111070611.342701-1-danishan...@ti.com/
[3] https://lore.kernel.org/all/20240124064930.1787929-1-danishan...@ti.com/
[4] https://lore.kernel.org/all/20231219103418.3445886-16-danishan...@ti.com/

Thanks and Regards,
MD Danish Anwar

MD Danish Anwar (5):
  net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.
  net: ti: icssg: Add Firmware config and classification APIs.
  net: ti: icssg: Add icssg queues APIs and macros
  net: ti: icssg: Add ICSSG ethernet driver
  net: ti: icssg: Add support sending FDB command to update rx_flow_id

 arch/arm/mach-k3/common.c |  11 +
 drivers/net/ti/Kconfig|  13 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icss_mii_rt.h  | 192 +
 drivers/net/ti/icssg_classifier.c | 376 
 drivers/net/ti/icssg_config.c | 474 
 drivers/net/ti/icssg_config.h | 195 +
 drivers/net/ti/icssg_prueth.c | 691 ++
 drivers/net/ti/icssg_prueth.h |  97 +
 drivers/net/ti/icssg_queues.c |  51 +++
 drivers/net/ti/icssg_switch_map.h | 209 +
 11 files changed, 2310 insertions(+)
 create mode 100644 drivers/net/ti/icss_mii_rt.h
 create mode 100644 drivers/net/ti/icssg_classifier.c
 create mode 100644 drivers/net/ti/icssg_config.c
 create mode 100644 drivers/net/ti/icssg_config.h
 create mode 100644 drivers/net/ti/icssg_prueth.c
 create mode 100644 drivers/net/ti/icssg_prueth.h
 create mode 100644 drivers/net/ti/icssg_queues.c
 create mode 100644 drivers/net/ti/icssg_switch_map.h


base-commit: 8ef8dcc54a0d507912ee57e15a541c5cebcfca76
-- 
2.34.1



Re: [PATCH v6] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-03-21 Thread MD Danish Anwar



On 20/03/24 6:08 pm, Tom Rini wrote:
> On Wed, Mar 20, 2024 at 11:19:01AM +0530, MD Danish Anwar wrote:
>> Hi Tom,
>>
>> On 20/03/24 4:10 am, Tom Rini wrote:
>>> On Wed, Feb 28, 2024 at 05:36:45PM +0530, MD Danish Anwar wrote:
>>>
>>>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>>>> same firmware.
>>>>
>>>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>>>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>>>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>>>> load the firmware file to the remote processor and start the remote
>>>> processor.
>>>>
>>>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>>>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>>>> driver.
>>>>
>>>> Signed-off-by: MD Danish Anwar 
>>>> Acked-by: Ravi Gunasekaran 
>>>> Reviewed-by: Roger Quadros 
>>>> ---
>>>> Changes from v5 to v6:
>>>> *) Collected Acked-by tag from Ravi Gunasekaran 
>>>> *) Fixed few typos as pointed out by Roger Quadros 
>>>> *) Added if condition to check if uc_pdata->fw_name exists and free it
>>>>before the strndup as suggested by Roger Quadros 
>>>>
>>>> Changes from v4 to v5:
>>>> *) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
>>>>that can be loaded to a rproc.
>>>> *) Added freeing of address in rproc_boot() as pointed out by Ravi.
>>>> *) Allocating the address at a later point in rproc_boot()
>>>> *) Rebased on latest u-boot/master [commit 
>>>>9e00b6993f724da9699ef12573307afea8c19284]
>>>>
>>>> Changes from v3 to v4:
>>>> *) No functional change. Splitted the patch out of the series as suggested
>>>>by Nishant.
>>>> *) Droppped the RFC tag.
>>>>
>>>> v5: 
>>>> https://lore.kernel.org/all/20240217122602.3402774-1-danishan...@ti.com/
>>>> v4: 
>>>> https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
>>>> v3: 
>>>> https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/
>>>>
>>>>  drivers/remoteproc/Kconfig|   8 +++
>>>>  drivers/remoteproc/rproc-uclass.c | 102 ++
>>>>  include/remoteproc.h  |  34 ++
>>>>  3 files changed, 144 insertions(+)
>>>>
>>>> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
>>>> index 781de530af..9f9877931c 100644
>>>> --- a/drivers/remoteproc/Kconfig
>>>> +++ b/drivers/remoteproc/Kconfig
>>>> @@ -10,6 +10,7 @@ menu "Remote Processor drivers"
>>>>  # All users should depend on DM
>>>>  config REMOTEPROC
>>>>bool
>>>> +  select FS_LOADER
>>>>depends on DM
>>>>  
>>>>  # Please keep the configuration alphabetically sorted.
>>>
>>> Can we not make the FS_LOADER portion optional? I didn't realize how
>>> many non-TI platforms this impacted. And even then it's possible I
>>> assume that custom designs will load the firmwares in other manners.
>>>
>>
>> Yes we can. We can wrap the remoteproc APIs using FS_LOADER in #ifdef
>> CONFIG_FS_LOADER. And instead of REMOTEPROC driver selecting FS_LOADER,
>> the clinet driver (ICSSG in this case) who is calling those remoteproc
>> APIs will select FS_LOADER and enable it.
>>
>> This will make sure that other platforms (ti or non-ti) that doesn't
>> support ICSSG but enables Remoteproc, will not enable FS_LOADER. This
>> way we are not forcing other platforms using remoteproc to enable
>> FS_LOADER. In this case the APIs will not get built.
>>
>> Now FS_LOADER will only be enabled when there is a client driver that
>> uses rproc_boot() APIs. It's upto the client driver to enable FS_LOADER
>>
>> below is the diff,
>>
>> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
>> index 9f9877931c..a49802c132 100644
>> --- a/drivers/remoteproc/Kconfig
>> +++ b/drivers/remoteproc/Kconfig
>> @@ -10,7 +10,6 @@ menu "Remote Processor drivers"
>>  # All users should depend on DM
>>  config REMOTEPROC
>> bool
>> -   select FS_LOADER
>> depends on DM
>>
>>  # Please keep the configuration alphabetically sorted.
>> diff --git a/drivers/remoteproc/rproc-uclass.c
>> b/drivers/remoteproc/rproc-uclass.c
>> index f4f22a3851..a6a8be5009 100644
>> --- a/drivers/remoteproc/rproc-uclass.c
>> +++ b/drivers/remoteproc/rproc-uclass.c
>> @@ -994,6 +994,7 @@ int rproc_set_firmware(struct udevice *rproc_dev,
>> const char *fw_name)
>> return 0;
>>  }
>>
>> +#ifdef CONFIG_FS_LOADER
>>  int rproc_boot(struct udevice *rproc_dev)
>>  {
>> struct dm_rproc_uclass_pdata *uc_pdata;
>> @@ -1063,3 +1064,4 @@ free_buffer:
>> free(addr);
>> return ret;
>>  }
>> +#endif
>>
>> Let me know if this looks ok. If it's ok I will post v7 with this change.
> 
> Yes please, thanks.
> 

Posted v7 with the above changes
https://lore.kernel.org/all/20240321102819.1011011-1-danishan...@ti.com/

Please check.

-- 
Thanks and Regards,
Danish


[PATCH v7] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-03-21 Thread MD Danish Anwar
Add APIs to set a firmware_name to a rproc and boot the rproc with the
same firmware.

Clients can call rproc_set_firmware() API to set firmware_name for a rproc
whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
a buffer by calling request_firmware_into_buf(). rproc_boot() will then
load the firmware file to the remote processor and start the remote
processor.

Signed-off-by: MD Danish Anwar 
Acked-by: Ravi Gunasekaran 
Reviewed-by: Roger Quadros 
---
Changes from v6 to v7:
*) Removed selecting FS_LOADER by default in remoteproc Kconfig.
*) Wrapped the rproc APIs using FS_LOADER inside #ifdef CONFIG_FS_LOADER.
*) Added Reviewed-by tag from Roger Quadros 

Changes from v5 to v6:
*) Collected Acked-by tag from Ravi Gunasekaran 
*) Fixed few typos as pointed out by Roger Quadros 
*) Added if condition to check if uc_pdata->fw_name exists and free it
   before the strndup as suggested by Roger Quadros 

Changes from v4 to v5:
*) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
   that can be loaded to a rproc.
*) Added freeing of address in rproc_boot() as pointed out by Ravi.
*) Allocating the address at a later point in rproc_boot()
*) Rebased on latest u-boot/master [commit 
   9e00b6993f724da9699ef12573307afea8c19284]

Changes from v3 to v4:
*) No functional change. Splitted the patch out of the series as suggested
   by Nishant.
*) Droppped the RFC tag.

v6: https://lore.kernel.org/all/20240228120645.958316-1-danishan...@ti.com/
v5: https://lore.kernel.org/all/20240217122602.3402774-1-danishan...@ti.com/
v4: https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
v3: https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/

 drivers/remoteproc/Kconfig|   7 ++
 drivers/remoteproc/rproc-uclass.c | 104 ++
 include/remoteproc.h  |  34 ++
 3 files changed, 145 insertions(+)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 781de530af..a49802c132 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -102,4 +102,11 @@ config REMOTEPROC_TI_IPU
help
  Say 'y' here to add support for TI' K3 remoteproc driver.
 
+config REMOTEPROC_MAX_FW_SIZE
+   hex "Maximum size of firmware file that needs to be loaded to the 
remote processor"
+   default 0x1
+   help
+ Maximum size of the firmware file (elf, binary) that needs to be
+ loaded to the remote processor.
+
 endmenu
diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 28b362c887..aa7f7586a8 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -961,3 +962,106 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev, struct rproc *cfg)
 
return 1;
 }
+
+int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   int len;
+   char *p;
+
+   if (!rproc_dev || !fw_name)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   if (!uc_pdata)
+   return -EINVAL;
+
+   len = strcspn(fw_name, "\n");
+   if (!len) {
+   debug("invalid firmware name\n");
+   return -EINVAL;
+   }
+
+   if (uc_pdata->fw_name)
+   free(uc_pdata->fw_name);
+
+   p = strndup(fw_name, len);
+   if (!p)
+   return -ENOMEM;
+
+   uc_pdata->fw_name = p;
+
+   return 0;
+}
+
+#if CONFIG_IS_ENABLED(FS_LOADER)
+int rproc_boot(struct udevice *rproc_dev)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   struct udevice *fs_loader;
+   int core_id, ret = 0;
+   char *firmware;
+   void *addr;
+
+   if (!rproc_dev)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   if (!uc_pdata)
+   return -EINVAL;
+
+   core_id = dev_seq(rproc_dev);
+   firmware = uc_pdata->fw_name;
+   if (!firmware) {
+   debug("No firmware name set for rproc core %d\n", core_id);
+   return -EINVAL;
+   }
+
+   /* Initialize all rproc cores */
+   if (!rproc_is_initialized()) {
+   ret = rproc_init();
+   if (ret) {
+   debug("rproc_init() failed: %d\n", ret);
+   return ret;
+   }
+   }
+
+   /* Loading firmware to a given address */
+   ret = get_fs_loader(_loader);
+   if (ret) {
+   debug("could not get fs loader: %d\n", ret);
+   return ret;
+   }
+
+   if (CONFIG_REMOTEPROC_MAX_FW_SIZE) {
+   addr = malloc(CONFIG_REMOTEPROC_MAX_FW_SIZE);
+   if (!addr)
+  

Re: [PATCH v6] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-03-19 Thread MD Danish Anwar
Hi Tom,

On 20/03/24 4:10 am, Tom Rini wrote:
> On Wed, Feb 28, 2024 at 05:36:45PM +0530, MD Danish Anwar wrote:
> 
>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>> same firmware.
>>
>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>> load the firmware file to the remote processor and start the remote
>> processor.
>>
>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>> driver.
>>
>> Signed-off-by: MD Danish Anwar 
>> Acked-by: Ravi Gunasekaran 
>> Reviewed-by: Roger Quadros 
>> ---
>> Changes from v5 to v6:
>> *) Collected Acked-by tag from Ravi Gunasekaran 
>> *) Fixed few typos as pointed out by Roger Quadros 
>> *) Added if condition to check if uc_pdata->fw_name exists and free it
>>before the strndup as suggested by Roger Quadros 
>>
>> Changes from v4 to v5:
>> *) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
>>that can be loaded to a rproc.
>> *) Added freeing of address in rproc_boot() as pointed out by Ravi.
>> *) Allocating the address at a later point in rproc_boot()
>> *) Rebased on latest u-boot/master [commit 
>>9e00b6993f724da9699ef12573307afea8c19284]
>>
>> Changes from v3 to v4:
>> *) No functional change. Splitted the patch out of the series as suggested
>>by Nishant.
>> *) Droppped the RFC tag.
>>
>> v5: https://lore.kernel.org/all/20240217122602.3402774-1-danishan...@ti.com/
>> v4: https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
>> v3: https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/
>>
>>  drivers/remoteproc/Kconfig|   8 +++
>>  drivers/remoteproc/rproc-uclass.c | 102 ++
>>  include/remoteproc.h  |  34 ++
>>  3 files changed, 144 insertions(+)
>>
>> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
>> index 781de530af..9f9877931c 100644
>> --- a/drivers/remoteproc/Kconfig
>> +++ b/drivers/remoteproc/Kconfig
>> @@ -10,6 +10,7 @@ menu "Remote Processor drivers"
>>  # All users should depend on DM
>>  config REMOTEPROC
>>  bool
>> +select FS_LOADER
>>  depends on DM
>>  
>>  # Please keep the configuration alphabetically sorted.
> 
> Can we not make the FS_LOADER portion optional? I didn't realize how
> many non-TI platforms this impacted. And even then it's possible I
> assume that custom designs will load the firmwares in other manners.
> 

Yes we can. We can wrap the remoteproc APIs using FS_LOADER in #ifdef
CONFIG_FS_LOADER. And instead of REMOTEPROC driver selecting FS_LOADER,
the clinet driver (ICSSG in this case) who is calling those remoteproc
APIs will select FS_LOADER and enable it.

This will make sure that other platforms (ti or non-ti) that doesn't
support ICSSG but enables Remoteproc, will not enable FS_LOADER. This
way we are not forcing other platforms using remoteproc to enable
FS_LOADER. In this case the APIs will not get built.

Now FS_LOADER will only be enabled when there is a client driver that
uses rproc_boot() APIs. It's upto the client driver to enable FS_LOADER

below is the diff,

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 9f9877931c..a49802c132 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -10,7 +10,6 @@ menu "Remote Processor drivers"
 # All users should depend on DM
 config REMOTEPROC
bool
-   select FS_LOADER
depends on DM

 # Please keep the configuration alphabetically sorted.
diff --git a/drivers/remoteproc/rproc-uclass.c
b/drivers/remoteproc/rproc-uclass.c
index f4f22a3851..a6a8be5009 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -994,6 +994,7 @@ int rproc_set_firmware(struct udevice *rproc_dev,
const char *fw_name)
return 0;
 }

+#ifdef CONFIG_FS_LOADER
 int rproc_boot(struct udevice *rproc_dev)
 {
struct dm_rproc_uclass_pdata *uc_pdata;
@@ -1063,3 +1064,4 @@ free_buffer:
free(addr);
return ret;
 }
+#endif

Let me know if this looks ok. If it's ok I will post v7 with this change.

-- 
Thanks and Regards,
Danish


[PATCH] arm: mach-k3: Fix config check for FS_LOADER

2024-03-14 Thread MD Danish Anwar
load_firmware() API calls fs-loader APIs and checks for CONFIG_FS_LOADER
before calling those APIs. The if check only checks for CONFIG_FS_LOADER
but not for CONFIG_SPL_FS_LOADER.

When CONFIG_FS_LOADER is enabled, load_firmware() API calls fs-loader APIs
but this is done at SPL stage and at this time FS_LOADER is not built yet
as a result we see below build error.

  AR  spl/boot/built-in.o
  LD  spl/u-boot-spl
arm-none-linux-gnueabihf-ld.bfd: arch/arm/mach-k3/common.o: in function
`load_firmware':
/home/danish/workspace/u-boot/arch/arm/mach-k3/common.c:184: undefined
reference to `get_fs_loader'
arm-none-linux-gnueabihf-ld.bfd:
/home/danish/workspace/u-boot/arch/arm/mach-k3/common.c:185: undefined
reference to `request_firmware_into_buf'
make[2]: *** [/home/danish/workspace/u-boot/scripts/Makefile.spl:527:
spl/u-boot-spl] Error 1
make[1]: *** [/home/danish/workspace/u-boot/Makefile:2055:
spl/u-boot-spl] Error 2
make[1]: Leaving directory '/home/danish/uboot_images/am64x/r5'
make: *** [Makefile:177: sub-make] Error 2

Fix this by modifying the if check to CONFIG_IS_ENABLED(FS_LOADER) instead
of IS_ENABLED(CONFIG_FS_LOADER) as the former will check for the
appropriate config option (CONFIG_SPL_FS_LOADER / CONFIG_FS_LOADER) based
on the build stage.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/mach-k3/r5/common.c  | 2 +-
 arch/arm/mach-omap2/boot-common.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-k3/r5/common.c b/arch/arm/mach-k3/r5/common.c
index 7309573a3f..c02f8d3309 100644
--- a/arch/arm/mach-k3/r5/common.c
+++ b/arch/arm/mach-k3/r5/common.c
@@ -70,7 +70,7 @@ int load_firmware(char *name_fw, char *name_loadaddr, u32 
*loadaddr)
char *name = NULL;
int size = 0;
 
-   if (!IS_ENABLED(CONFIG_FS_LOADER))
+   if (!CONFIG_IS_ENABLED(FS_LOADER))
return 0;
 
*loadaddr = 0;
diff --git a/arch/arm/mach-omap2/boot-common.c 
b/arch/arm/mach-omap2/boot-common.c
index 57917da25c..aa0ab13d5f 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -190,7 +190,7 @@ int load_firmware(char *name_fw, u32 *loadaddr)
struct udevice *fsdev;
int size = 0;
 
-   if (!IS_ENABLED(CONFIG_FS_LOADER))
+   if (!CONFIG_IS_ENABLED(FS_LOADER))
return 0;
 
if (!*loadaddr)
-- 
2.34.1



[PATCH] arm: mach-k3: Fix config check for FS_LOADER

2024-03-14 Thread MD Danish Anwar
load_firmware() API calls fs-loader APIs and checks for CONFIG_FS_LOADER
before calling those APIs. The if check only checks for CONFIG_FS_LOADER
but not for CONFIG_SPL_FS_LOADER.

When CONFIG_FS_LOADER is enabled, load_firmware() API calls fs-loader APIs
but this is done at SPL stage and at this time FS_LOADER is not built yet
as a result we see below build error.

  AR  spl/boot/built-in.o
  LD  spl/u-boot-spl
arm-none-linux-gnueabihf-ld.bfd: arch/arm/mach-k3/common.o: in function
`load_firmware':
/home/danish/workspace/u-boot/arch/arm/mach-k3/common.c:184: undefined
reference to `get_fs_loader'
arm-none-linux-gnueabihf-ld.bfd:
/home/danish/workspace/u-boot/arch/arm/mach-k3/common.c:185: undefined
reference to `request_firmware_into_buf'
make[2]: *** [/home/danish/workspace/u-boot/scripts/Makefile.spl:527:
spl/u-boot-spl] Error 1
make[1]: *** [/home/danish/workspace/u-boot/Makefile:2055:
spl/u-boot-spl] Error 2
make[1]: Leaving directory '/home/danish/uboot_images/am64x/r5'
make: *** [Makefile:177: sub-make] Error 2

Fix this by modifying the if check to CONFIG_IS_ENABLED(FS_LOADER) instead
of IS_ENABLED(CONFIG_FS_LOADER) as the former will check for the
appropriate config option (CONFIG_SPL_FS_LOADER / CONFIG_FS_LOADER) based
on the build stage.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/mach-k3/r5/common.c  | 2 +-
 arch/arm/mach-omap2/boot-common.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/arch/arm/mach-k3/r5/common.c b/arch/arm/mach-k3/r5/common.c
index 7309573a3f..c02f8d3309 100644
--- a/arch/arm/mach-k3/r5/common.c
+++ b/arch/arm/mach-k3/r5/common.c
@@ -70,7 +70,7 @@ int load_firmware(char *name_fw, char *name_loadaddr, u32 
*loadaddr)
char *name = NULL;
int size = 0;
 
-   if (!IS_ENABLED(CONFIG_FS_LOADER))
+   if (!CONFIG_IS_ENABLED(FS_LOADER))
return 0;
 
*loadaddr = 0;
diff --git a/arch/arm/mach-omap2/boot-common.c 
b/arch/arm/mach-omap2/boot-common.c
index 57917da25c..aa0ab13d5f 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -190,7 +190,7 @@ int load_firmware(char *name_fw, u32 *loadaddr)
struct udevice *fsdev;
int size = 0;
 
-   if (!IS_ENABLED(CONFIG_FS_LOADER))
+   if (!CONFIG_IS_ENABLED(FS_LOADER))
return 0;
 
if (!*loadaddr)
-- 
2.34.1



Re: [PATCH v6] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-03-12 Thread MD Danish Anwar



On 11/03/24 10:34 am, Anwar, Md Danish wrote:
> 
> 
> On 3/7/2024 6:16 PM, Tom Rini wrote:
>> On Wed, Feb 28, 2024 at 05:36:45PM +0530, MD Danish Anwar wrote:
>>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>>
>>> same firmware.
>>>
>>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>>> load the firmware file to the remote processor and start the remote
>>> processor.
>>>
>>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>>> driver.
>>>
>>> Signed-off-by: MD Danish Anwar 
>>> Acked-by: Ravi Gunasekaran 
>>> Reviewed-by: Roger Quadros 
>>
>> This breaks building on am64x_evm_r5 am65x_evm_r5_usbdfu
>> am65x_evm_r5_usbmsc in next currently, thanks.
>>
> I will work on fixing this build error and re-spin the patch.
> 

Hi Tom, Roger,

This patch adds "request_firmware_into_buf()" in the rproc driver. To
use this API, FS_LOADER is needed. So I am adding "select FS_LOADER" in
REMOTEPROC Kconfig option. As a result whenever REMOTEPROC is enabled,
FS_LOADER also gets enabled.

Now arch/arm/mach-k3/common.c [1] and arch/arm/mach-omap2/boot-common.c
[2] has a "load_firmware()" API which calls fs-loader APIs and they have
below if condition before calling fs-loader APIs.

if (!IS_ENABLED(CONFIG_FS_LOADER))
return 0;

Till now, CONFIG_FS_LOADER was not set as a result the load_firmware()
API in above mentioned files, was returning 0.

Now as this patch enables CONFIG_FS_LOADER, as a result the code after
the if check starts getting executed and it tries to look for
get_fs_loader() and other fs-loader APIs but this is done at SPL and at
this time FS_LOADER is not built yet as a result we see below error.
The if checks only checks for CONFIG_FS_LOADER but not for
CONFIG_SPL_FS_LOADER.

  AR  spl/boot/built-in.o
  LD  spl/u-boot-spl
arm-none-linux-gnueabihf-ld.bfd: arch/arm/mach-k3/common.o: in function
`load_firmware':
/home/danish/workspace/u-boot/arch/arm/mach-k3/common.c:184: undefined
reference to `get_fs_loader'
arm-none-linux-gnueabihf-ld.bfd:
/home/danish/workspace/u-boot/arch/arm/mach-k3/common.c:185: undefined
reference to `request_firmware_into_buf'
make[2]: *** [/home/danish/workspace/u-boot/scripts/Makefile.spl:527:
spl/u-boot-spl] Error 1
make[1]: *** [/home/danish/workspace/u-boot/Makefile:2055:
spl/u-boot-spl] Error 2
make[1]: Leaving directory '/home/danish/uboot_images/am64x/r5'
make: *** [Makefile:177: sub-make] Error 2

This bug has always been there but as CONFIG_FS_LOADER was never
enabled, this build error was never seen as the load_firmware() API will
return 0 without calling fs-loader APIs.

Now that this patch enables CONFIG_FS_LOADER, the bug gets exposed and
build error is seen.

My opinion here would be, to check for CONFIG_IS_ENABLED(FS_LOADER)
instead of IS_ENABLED(CONFIG_FS_LOADER) as the former will check for the
appropriate config option (CONFIG_SPL_FS_LOADER / CONFIG_FS_LOADER)
based on the build stage.

I tested with the below diff and I don't see build errors with
am64x_evm_r5, am65x_evm_r5_usbdfu, am65x_evm_r5_usbmsc configs.

diff --git a/arch/arm/mach-k3/common.c b/arch/arm/mach-k3/common.c
index f411366778..6792ff7467 100644
--- a/arch/arm/mach-k3/common.c
+++ b/arch/arm/mach-k3/common.c
@@ -162,7 +162,7 @@ int load_firmware(char *name_fw, char
*name_loadaddr, u32 *loadaddr)
char *name = NULL;
int size = 0;

-   if (!IS_ENABLED(CONFIG_FS_LOADER))
+   if (!CONFIG_IS_ENABLED(FS_LOADER))
return 0;

*loadaddr = 0;
diff --git a/arch/arm/mach-omap2/boot-common.c
b/arch/arm/mach-omap2/boot-common.c
index 57917da25c..aa0ab13d5f 100644
--- a/arch/arm/mach-omap2/boot-common.c
+++ b/arch/arm/mach-omap2/boot-common.c
@@ -190,7 +190,7 @@ int load_firmware(char *name_fw, u32 *loadaddr)
struct udevice *fsdev;
int size = 0;

-   if (!IS_ENABLED(CONFIG_FS_LOADER))
+   if (!CONFIG_IS_ENABLED(FS_LOADER))
return 0;

if (!*loadaddr)


Tom, Roger, Please let me know if this looks ok.
If it's ok, I will post this diff as a separate patch and once that is
merged Tom can merge this patch or I can send a v7 if needed.

[1]
https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-k3/common.c#L159
[2]
https://elixir.bootlin.com/u-boot/latest/source/arch/arm/mach-omap2/boot-common.c#L188

-- 
Thanks and Regards,
Danish


Re: [PATCH v6] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-03-05 Thread MD Danish Anwar
On 29/02/24 3:43 pm, Roger Quadros wrote:
> 
> 
> On 28/02/2024 14:06, MD Danish Anwar wrote:
>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>> same firmware.
>>
>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>> load the firmware file to the remote processor and start the remote
>> processor.
>>
>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>> driver.
>>
>> Signed-off-by: MD Danish Anwar 
>> Acked-by: Ravi Gunasekaran 
> 
> Reviewed-by: Roger Quadros 

Hi Tom,

Can you please pick this patch. There are no active comments on this
patch and Roger and Ravi has reviewed / acked the patch.

-- 
Thanks and Regards,
Danish


[PATCH v6] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-28 Thread MD Danish Anwar
Add APIs to set a firmware_name to a rproc and boot the rproc with the
same firmware.

Clients can call rproc_set_firmware() API to set firmware_name for a rproc
whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
a buffer by calling request_firmware_into_buf(). rproc_boot() will then
load the firmware file to the remote processor and start the remote
processor.

Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
Kconfig so that we can call request_firmware_into_buf() from remoteproc
driver.

Signed-off-by: MD Danish Anwar 
Acked-by: Ravi Gunasekaran 
---
Changes from v5 to v6:
*) Collected Acked-by tag from Ravi Gunasekaran 
*) Fixed few typos as pointed out by Roger Quadros 
*) Added if condition to check if uc_pdata->fw_name exists and free it
   before the strndup as suggested by Roger Quadros 

Changes from v4 to v5:
*) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
   that can be loaded to a rproc.
*) Added freeing of address in rproc_boot() as pointed out by Ravi.
*) Allocating the address at a later point in rproc_boot()
*) Rebased on latest u-boot/master [commit 
   9e00b6993f724da9699ef12573307afea8c19284]

Changes from v3 to v4:
*) No functional change. Splitted the patch out of the series as suggested
   by Nishant.
*) Droppped the RFC tag.

v5: https://lore.kernel.org/all/20240217122602.3402774-1-danishan...@ti.com/
v4: https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
v3: https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/

 drivers/remoteproc/Kconfig|   8 +++
 drivers/remoteproc/rproc-uclass.c | 102 ++
 include/remoteproc.h  |  34 ++
 3 files changed, 144 insertions(+)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 781de530af..9f9877931c 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -10,6 +10,7 @@ menu "Remote Processor drivers"
 # All users should depend on DM
 config REMOTEPROC
bool
+   select FS_LOADER
depends on DM
 
 # Please keep the configuration alphabetically sorted.
@@ -102,4 +103,11 @@ config REMOTEPROC_TI_IPU
help
  Say 'y' here to add support for TI' K3 remoteproc driver.
 
+config REMOTEPROC_MAX_FW_SIZE
+   hex "Maximum size of firmware file that needs to be loaded to the 
remote processor"
+   default 0x1
+   help
+ Maximum size of the firmware file (elf, binary) that needs to be
+ loaded to the remote processor.
+
 endmenu
diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 28b362c887..f4f22a3851 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -961,3 +962,104 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev, struct rproc *cfg)
 
return 1;
 }
+
+int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   int len;
+   char *p;
+
+   if (!rproc_dev || !fw_name)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   if (!uc_pdata)
+   return -EINVAL;
+
+   len = strcspn(fw_name, "\n");
+   if (!len) {
+   debug("invalid firmware name\n");
+   return -EINVAL;
+   }
+
+   if (uc_pdata->fw_name)
+   free(uc_pdata->fw_name);
+
+   p = strndup(fw_name, len);
+   if (!p)
+   return -ENOMEM;
+
+   uc_pdata->fw_name = p;
+
+   return 0;
+}
+
+int rproc_boot(struct udevice *rproc_dev)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   struct udevice *fs_loader;
+   int core_id, ret = 0;
+   char *firmware;
+   void *addr;
+
+   if (!rproc_dev)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   if (!uc_pdata)
+   return -EINVAL;
+
+   core_id = dev_seq(rproc_dev);
+   firmware = uc_pdata->fw_name;
+   if (!firmware) {
+   debug("No firmware name set for rproc core %d\n", core_id);
+   return -EINVAL;
+   }
+
+   /* Initialize all rproc cores */
+   if (!rproc_is_initialized()) {
+   ret = rproc_init();
+   if (ret) {
+   debug("rproc_init() failed: %d\n", ret);
+   return ret;
+   }
+   }
+
+   /* Loading firmware to a given address */
+   ret = get_fs_loader(_loader);
+   if (ret) {
+   debug("could not get fs loader: %d\n", ret);
+   return ret;
+   }
+
+   if (CONFIG_REMOTEPROC_MAX_FW_SIZE) {
+   addr = malloc(CONFIG_REMOTEPROC_

Re: [PATCH v5] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-28 Thread MD Danish Anwar



On 28/02/24 4:12 pm, Roger Quadros wrote:
> 
> 
> On 28/02/2024 12:35, MD Danish Anwar wrote:
>>
>>
>> On 28/02/24 3:30 pm, Roger Quadros wrote:
>>>
>>>
>>> On 17/02/2024 14:26, MD Danish Anwar wrote:
>>>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>>>> same firmware.
>>>>
>>>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>>>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>>>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>>>> load the firmware file to the remote processor and start the remote
>>>> processor.
>>>>
>>>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>>>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>>>> driver.
>>>>
>>>> Signed-off-by: MD Danish Anwar 
>>>> ---
>>>> Changes from v4 to v5:
>>>> *) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
>>>>that can be loaded to a rproc.
>>>> *) Added freeing of address in rproc_boot() as pointed out by Ravi.
>>>> *) Allocating the address at a later point in rproc_boot()
>>>> *) Rebased on latest u-boot/master [commit 
>>>>9e00b6993f724da9699ef12573307afea8c19284]
>>>>
>>>> Changes from v3 to v4:
>>>> *) No functional change. Splitted the patch out of the series as suggested
>>>>by Nishant.
>>>> *) Droppped the RFC tag.
>>>>
>>>> v4: 
>>>> https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
>>>> v3: 
>>>> https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/
>>>>
>>>>  drivers/remoteproc/Kconfig|   8 +++
>>>>  drivers/remoteproc/rproc-uclass.c | 100 ++
>>>>  include/remoteproc.h  |  34 ++
>>>>  3 files changed, 142 insertions(+)
>>>>
>>>> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
>>>> index 781de530af..759d21437a 100644
>>>> --- a/drivers/remoteproc/Kconfig
>>>> +++ b/drivers/remoteproc/Kconfig
>>>> @@ -10,6 +10,7 @@ menu "Remote Processor drivers"
>>>>  # All users should depend on DM
>>>>  config REMOTEPROC
>>>>bool
>>>> +  select FS_LOADER
>>>>depends on DM
>>>>  
>>>>  # Please keep the configuration alphabetically sorted.
>>>> @@ -102,4 +103,11 @@ config REMOTEPROC_TI_IPU
>>>>help
>>>>  Say 'y' here to add support for TI' K3 remoteproc driver.
>>>>  
>>>> +config REMOTEPROC_MAX_FW_SIZE
>>>> +  hex "Maximum size of firmware that needs to be loaded to rproc"
>>>
>>> firmware file?
>>>
>>> /rproc/the remote processor
>>>
>>>> +  default 0x1
>>>> +  help
>>>> +Maximum size of the firmware file (elf, binary) that needs to be
>>>> +loaded to th rproc core.
>>>
>>> s/th/the
>>> s/rproc/remote processor
>>>
>>
>> Will fix these typos.
>>
>>>> +
>>>>  endmenu
>>>> diff --git a/drivers/remoteproc/rproc-uclass.c 
>>>> b/drivers/remoteproc/rproc-uclass.c
>>>> index 28b362c887..784361cef9 100644
>>>> --- a/drivers/remoteproc/rproc-uclass.c
>>>> +++ b/drivers/remoteproc/rproc-uclass.c
>>>> @@ -13,6 +13,7 @@
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> +#include 
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> @@ -961,3 +962,102 @@ unsigned long rproc_parse_resource_table(struct 
>>>> udevice *dev, struct rproc *cfg)
>>>>  
>>>>return 1;
>>>>  }
>>>> +
>>>> +int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
>>>> +{
>>>> +  struct dm_rproc_uclass_pdata *uc_pdata;
>>>> +  int len;
>>>> +  char *p;
>>>> +
>>>> +  if (!rproc_dev || !fw_name)
>>>> +  return -EINVAL;
>>>> +
>>>> +  uc_pdata = dev_get_uclass_plat(rproc_dev);
>>>> +  if (!uc_pdata)
>>>> +  return -EINVAL;
>>>>

Re: [PATCH v5] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-28 Thread MD Danish Anwar



On 28/02/24 3:30 pm, Roger Quadros wrote:
> 
> 
> On 17/02/2024 14:26, MD Danish Anwar wrote:
>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>> same firmware.
>>
>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>> load the firmware file to the remote processor and start the remote
>> processor.
>>
>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>> driver.
>>
>> Signed-off-by: MD Danish Anwar 
>> ---
>> Changes from v4 to v5:
>> *) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
>>that can be loaded to a rproc.
>> *) Added freeing of address in rproc_boot() as pointed out by Ravi.
>> *) Allocating the address at a later point in rproc_boot()
>> *) Rebased on latest u-boot/master [commit 
>>9e00b6993f724da9699ef12573307afea8c19284]
>>
>> Changes from v3 to v4:
>> *) No functional change. Splitted the patch out of the series as suggested
>>by Nishant.
>> *) Droppped the RFC tag.
>>
>> v4: https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
>> v3: https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/
>>
>>  drivers/remoteproc/Kconfig|   8 +++
>>  drivers/remoteproc/rproc-uclass.c | 100 ++
>>  include/remoteproc.h  |  34 ++
>>  3 files changed, 142 insertions(+)
>>
>> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
>> index 781de530af..759d21437a 100644
>> --- a/drivers/remoteproc/Kconfig
>> +++ b/drivers/remoteproc/Kconfig
>> @@ -10,6 +10,7 @@ menu "Remote Processor drivers"
>>  # All users should depend on DM
>>  config REMOTEPROC
>>  bool
>> +select FS_LOADER
>>  depends on DM
>>  
>>  # Please keep the configuration alphabetically sorted.
>> @@ -102,4 +103,11 @@ config REMOTEPROC_TI_IPU
>>  help
>>Say 'y' here to add support for TI' K3 remoteproc driver.
>>  
>> +config REMOTEPROC_MAX_FW_SIZE
>> +hex "Maximum size of firmware that needs to be loaded to rproc"
> 
> firmware file?
> 
> /rproc/the remote processor
> 
>> +default 0x1
>> +help
>> +  Maximum size of the firmware file (elf, binary) that needs to be
>> +  loaded to th rproc core.
> 
> s/th/the
> s/rproc/remote processor
> 

Will fix these typos.

>> +
>>  endmenu
>> diff --git a/drivers/remoteproc/rproc-uclass.c 
>> b/drivers/remoteproc/rproc-uclass.c
>> index 28b362c887..784361cef9 100644
>> --- a/drivers/remoteproc/rproc-uclass.c
>> +++ b/drivers/remoteproc/rproc-uclass.c
>> @@ -13,6 +13,7 @@
>>  #include 
>>  #include 
>>  #include 
>> +#include 
>>  #include 
>>  #include 
>>  #include 
>> @@ -961,3 +962,102 @@ unsigned long rproc_parse_resource_table(struct 
>> udevice *dev, struct rproc *cfg)
>>  
>>  return 1;
>>  }
>> +
>> +int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
>> +{
>> +struct dm_rproc_uclass_pdata *uc_pdata;
>> +int len;
>> +char *p;
>> +
>> +if (!rproc_dev || !fw_name)
>> +return -EINVAL;
>> +
>> +uc_pdata = dev_get_uclass_plat(rproc_dev);
>> +if (!uc_pdata)
>> +return -EINVAL;
>> +
>> +len = strcspn(fw_name, "\n");
>> +if (!len) {
>> +debug("invalid firmware name\n");
>> +return -EINVAL;
>> +}
>> +
>> +p = strndup(fw_name, len);
>> +if (!p)
>> +return -ENOMEM;
> 
> Aren't we leaking memory if rproc_set_firmware() is called multiple times?
> Can we check if uc_pdata->fw_name exists and free it before the strndup?
> 

Sure, How does the below diff looks to you?

diff --git a/drivers/remoteproc/rproc-uclass.c
b/drivers/remoteproc/rproc-uclass.c
index 784361cef9..f373b64da4 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -982,6 +982,9 @@ int rproc_set_firmware(struct udevice *rproc_dev,
const char *fw_name)
return -EINVAL;
}

+   if (uc_pdata->fw_name)
+   free(uc_pdata->fw_name);
+
p = strndup(fw_name, le

Re: [PATCH v5] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-02-28 Thread MD Danish Anwar


On 27/02/24 7:33 pm, Sean Anderson wrote:
> Hi Danish,
> 
> On 2/27/24 05:26, MD Danish Anwar wrote:
>> On 09/02/24 3:38 pm, MD Danish Anwar wrote:
>>> The fs-loader driver reads env storage_interface and uses it to load
>>> firmware file into memory using the medium set by env. Update the driver
>>> to use env fw_storage_interface as this variable is only used to load
>>> firmwares. This is to keep all variables used by fs-loader driver with
>>> 'fw_' prefix. All other variables have 'fw_' prefix except for
>>> storage_interface.
>>>
>>> The env storage_interface will act as fallback so that the
>>> existing implementations do not break.
>>>
>>> Also update the FS Loader documentation accordingly.
>>>
>>> Signed-off-by: MD Danish Anwar 
>>> ---
>>
>> Hi Tom / Sean, can you please pick this patch if there is no pending
>> comments to address.
>>
> 
> Sorry, I forgot to respond to this earlier.
> 
> To be honest, I'm not really convinced. We have plenty of environmental
> variables which are inconsistent (e.g. ethaddr, eth2addr, eth3addr) and it
> doesn't cause any issues. While fixing code has no cost, the environment
> is an ABI which we can't break. So we'd have to support both of these
> variables forever. I'm not really a fan of doing that without good reason,
> and I think aesthetics of the variable name isn't really compelling.
> 

Roger, should I keep the env variable name as it is and don't rename it?
Sean's concern seems valid, can you please comment here.

> --Sean

-- 
Thanks and Regards,
Danish


Re: [PATCH v5] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-02-27 Thread MD Danish Anwar
On 09/02/24 3:38 pm, MD Danish Anwar wrote:
> The fs-loader driver reads env storage_interface and uses it to load
> firmware file into memory using the medium set by env. Update the driver
> to use env fw_storage_interface as this variable is only used to load
> firmwares. This is to keep all variables used by fs-loader driver with
> 'fw_' prefix. All other variables have 'fw_' prefix except for
> storage_interface.
> 
> The env storage_interface will act as fallback so that the
> existing implementations do not break.
> 
> Also update the FS Loader documentation accordingly.
> 
> Signed-off-by: MD Danish Anwar 
> ---

Hi Tom / Sean, can you please pick this patch if there is no pending
comments to address.

> Cc: Sean Anderson 
> Changes from v4 to v5:
> *) Modified commit message to make the motive cleared for this commit.
> *) Added RB tag of Ravi.
> *) Rebased on the latest u-boot/master [commit
>a4650bf65e4b7d3ef04c90ba8031374428e4a682]
> 
> v4: https://lore.kernel.org/all/20240130062627.2344282-1-danishan...@ti.com/
> 
>  doc/develop/driver-model/fs_firmware_loader.rst | 5 -
>  drivers/misc/fs_loader.c| 5 -
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/doc/develop/driver-model/fs_firmware_loader.rst 
> b/doc/develop/driver-model/fs_firmware_loader.rst
> index 149b8b436e..410cc1442d 100644
> --- a/doc/develop/driver-model/fs_firmware_loader.rst
> +++ b/doc/develop/driver-model/fs_firmware_loader.rst
> @@ -98,8 +98,11 @@ through the U-Boot environment variable during run time.
>  
>  For examples:
>  
> +fw_storage_interface:
> +  Firmware storage interface, it can be "mmc", "usb", "sata" or "ubi".
>  storage_interface:
> -  Storage interface, it can be "mmc", "usb", "sata" or "ubi".
> +  Storage interface, it can be "mmc", "usb", "sata" or "ubi". This acts
> +  as a fallback if fw_storage_interface is not set.
>  fw_dev_part:
>Block device number and its partition, it can be "0:1".
>  fw_ubi_mtdpart:
> diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
> index 1ffc199ba1..3798dab5b6 100644
> --- a/drivers/misc/fs_loader.c
> +++ b/drivers/misc/fs_loader.c
> @@ -153,7 +153,10 @@ static int fw_get_filesystem_firmware(struct udevice 
> *dev)
>   char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume;
>   int ret;
>  
> - storage_interface = env_get("storage_interface");
> + storage_interface = env_get("fw_storage_interface");
> + if (!storage_interface)
> + storage_interface = env_get("storage_interface");
> +
>   dev_part = env_get("fw_dev_part");
>   ubi_mtdpart = env_get("fw_ubi_mtdpart");
>   ubi_volume = env_get("fw_ubi_volume");

-- 
Thanks and Regards,
Danish


[PATCH v5] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-17 Thread MD Danish Anwar
Add APIs to set a firmware_name to a rproc and boot the rproc with the
same firmware.

Clients can call rproc_set_firmware() API to set firmware_name for a rproc
whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
a buffer by calling request_firmware_into_buf(). rproc_boot() will then
load the firmware file to the remote processor and start the remote
processor.

Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
Kconfig so that we can call request_firmware_into_buf() from remoteproc
driver.

Signed-off-by: MD Danish Anwar 
---
Changes from v4 to v5:
*) Added Kconfig option REMOTEPROC_MAX_FW_SIZE to set max firmware size
   that can be loaded to a rproc.
*) Added freeing of address in rproc_boot() as pointed out by Ravi.
*) Allocating the address at a later point in rproc_boot()
*) Rebased on latest u-boot/master [commit 
   9e00b6993f724da9699ef12573307afea8c19284]

Changes from v3 to v4:
*) No functional change. Splitted the patch out of the series as suggested
   by Nishant.
*) Droppped the RFC tag.

v4: https://lore.kernel.org/all/20240130063322.2345057-1-danishan...@ti.com/
v3: https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/

 drivers/remoteproc/Kconfig|   8 +++
 drivers/remoteproc/rproc-uclass.c | 100 ++
 include/remoteproc.h  |  34 ++
 3 files changed, 142 insertions(+)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 781de530af..759d21437a 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -10,6 +10,7 @@ menu "Remote Processor drivers"
 # All users should depend on DM
 config REMOTEPROC
bool
+   select FS_LOADER
depends on DM
 
 # Please keep the configuration alphabetically sorted.
@@ -102,4 +103,11 @@ config REMOTEPROC_TI_IPU
help
  Say 'y' here to add support for TI' K3 remoteproc driver.
 
+config REMOTEPROC_MAX_FW_SIZE
+   hex "Maximum size of firmware that needs to be loaded to rproc"
+   default 0x1
+   help
+ Maximum size of the firmware file (elf, binary) that needs to be
+ loaded to th rproc core.
+
 endmenu
diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 28b362c887..784361cef9 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -961,3 +962,102 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev, struct rproc *cfg)
 
return 1;
 }
+
+int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   int len;
+   char *p;
+
+   if (!rproc_dev || !fw_name)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   if (!uc_pdata)
+   return -EINVAL;
+
+   len = strcspn(fw_name, "\n");
+   if (!len) {
+   debug("invalid firmware name\n");
+   return -EINVAL;
+   }
+
+   p = strndup(fw_name, len);
+   if (!p)
+   return -ENOMEM;
+
+   uc_pdata->fw_name = p;
+
+   return 0;
+}
+
+int rproc_boot(struct udevice *rproc_dev)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   struct udevice *fs_loader;
+   int core_id, ret = 0;
+   char *firmware;
+   void *addr;
+
+   if (!rproc_dev)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   if (!uc_pdata)
+   return -EINVAL;
+
+   core_id = dev_seq(rproc_dev);
+   firmware = uc_pdata->fw_name;
+
+   if (!firmware) {
+   debug("No firmware set for rproc core %d\n", core_id);
+   return -EINVAL;
+   }
+
+   /* Initialize all rproc cores */
+   if (!rproc_is_initialized()) {
+   ret = rproc_init();
+   if (ret) {
+   debug("rproc_init() failed: %d\n", ret);
+   return ret;
+   }
+   }
+
+   /* Loading firmware to a given address */
+   ret = get_fs_loader(_loader);
+   if (ret) {
+   debug("could not get fs loader: %d\n", ret);
+   return ret;
+   }
+
+   if (CONFIG_REMOTEPROC_MAX_FW_SIZE) {
+   addr = malloc(CONFIG_REMOTEPROC_MAX_FW_SIZE);
+   if (!addr)
+   return -ENOMEM;
+   } else {
+   debug("CONFIG_REMOTEPROC_MAX_FW_SIZE not defined\n");
+   return -EINVAL;
+   }
+
+   ret = request_firmware_into_buf(fs_loader, firmware, addr, 
CONFIG_REMOTEPROC_MAX_FW_SIZE,
+   0);
+   if (ret < 0) {
+   debug("could not request %s: %d\n", firmware, ret);
+

[PATCH v5] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-02-09 Thread MD Danish Anwar
The fs-loader driver reads env storage_interface and uses it to load
firmware file into memory using the medium set by env. Update the driver
to use env fw_storage_interface as this variable is only used to load
firmwares. This is to keep all variables used by fs-loader driver with
'fw_' prefix. All other variables have 'fw_' prefix except for
storage_interface.

The env storage_interface will act as fallback so that the
existing implementations do not break.

Also update the FS Loader documentation accordingly.

Signed-off-by: MD Danish Anwar 
---
Cc: Sean Anderson 
Changes from v4 to v5:
*) Modified commit message to make the motive cleared for this commit.
*) Added RB tag of Ravi.
*) Rebased on the latest u-boot/master [commit
   a4650bf65e4b7d3ef04c90ba8031374428e4a682]

v4: https://lore.kernel.org/all/20240130062627.2344282-1-danishan...@ti.com/

 doc/develop/driver-model/fs_firmware_loader.rst | 5 -
 drivers/misc/fs_loader.c| 5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/develop/driver-model/fs_firmware_loader.rst 
b/doc/develop/driver-model/fs_firmware_loader.rst
index 149b8b436e..410cc1442d 100644
--- a/doc/develop/driver-model/fs_firmware_loader.rst
+++ b/doc/develop/driver-model/fs_firmware_loader.rst
@@ -98,8 +98,11 @@ through the U-Boot environment variable during run time.
 
 For examples:
 
+fw_storage_interface:
+  Firmware storage interface, it can be "mmc", "usb", "sata" or "ubi".
 storage_interface:
-  Storage interface, it can be "mmc", "usb", "sata" or "ubi".
+  Storage interface, it can be "mmc", "usb", "sata" or "ubi". This acts
+  as a fallback if fw_storage_interface is not set.
 fw_dev_part:
   Block device number and its partition, it can be "0:1".
 fw_ubi_mtdpart:
diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
index 1ffc199ba1..3798dab5b6 100644
--- a/drivers/misc/fs_loader.c
+++ b/drivers/misc/fs_loader.c
@@ -153,7 +153,10 @@ static int fw_get_filesystem_firmware(struct udevice *dev)
char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume;
int ret;
 
-   storage_interface = env_get("storage_interface");
+   storage_interface = env_get("fw_storage_interface");
+   if (!storage_interface)
+   storage_interface = env_get("storage_interface");
+
dev_part = env_get("fw_dev_part");
ubi_mtdpart = env_get("fw_ubi_mtdpart");
ubi_volume = env_get("fw_ubi_volume");
-- 
2.34.1



Re: [PATCH v4] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-02-09 Thread MD Danish Anwar



On 08/02/24 5:28 pm, Roger Quadros wrote:
> 
> 
> On 08/02/2024 07:19, MD Danish Anwar wrote:
>> Hi Sean,
>>
>> On 07/02/24 11:14 pm, Sean Anderson wrote:
>>> On 1/30/24 01:26, MD Danish Anwar wrote:
>>>> The fs-loader driver reads env storage_interface and uses it to load
>>>> firmware file into memory using the medium set by env. Update the driver
>>>> to use env fw_storage_interface as this variable is only used to load
>>>> firmwares. The env storage_interface will act as fallback so that the
>>>> existing implementations do not break.
>>>>
>>>> Also update the FS Loader documentation accordingly.
>>>
>>> So why do you want to do this? I don't see what the point of renaming the
>>> variable is, since you are not e.g. adding any new functionality, and we
>>> have to pay for the rename in code size.
>>>
>>
>> I am upstreaming TI's ICSSG driver for u-boot and during code review
>> Roger Quadros  commented asking to rename this
>> variable [1]. I think the motive here was to keep all variables used by
>> fs-loader driver with 'fw_' prefix. All other variables had 'fw_' prefix
>> except for storage_interface.
> 
> Can you please mention this motive in the Commit message?
> 

Sure Roger, I will resend the patch after updating commit message.

>>
>> [1]
>> https://lore.kernel.org/all/4721f3b9-f823-47f3-b4f3-ed40002af...@kernel.org/
>>
>>> --Sean
>>
> 

-- 
Thanks and Regards,
Danish


Re: [PATCH v4] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-09 Thread MD Danish Anwar
On 07/02/24 6:27 pm, Anwar, Md Danish wrote:
> On 2/7/2024 6:05 PM, Roger Quadros wrote:
>>
>>
>> On 07/02/2024 09:15, MD Danish Anwar wrote:
>>> Hi Roger
>>>
>>> On 06/02/24 7:11 pm, Roger Quadros wrote:
>>>>
>>>>
>>>> On 06/02/2024 07:31, MD Danish Anwar wrote:
>>>>>
>>>>>
>>>>> On 05/02/24 6:07 pm, Roger Quadros wrote:
>>>>>>
>>>>>>
>>>>>> On 05/02/2024 12:20, MD Danish Anwar wrote:
>>>>>>>
>>>>>>>
>>>>>>> On 05/02/24 3:36 pm, Roger Quadros wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> On 02/02/2024 18:40, Anwar, Md Danish wrote:
>>>>>>>>> Hi Roger,
>>>>>>>>>
>>>>>>>>> On 2/2/2024 4:49 PM, Roger Quadros wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 30/01/2024 08:33, MD Danish Anwar wrote:
>>>>>>>>>>> Add APIs to set a firmware_name to a rproc and boot the rproc with 
>>>>>>>>>>> the
>>>>>>>>>>> same firmware.
>>>>>>>>>>>
>>>>>
>>>>> 
>>>>>
>>>>>>>>>
>>>>>>>>>> How does caller know what firmware size to set to?
>>>>>>>>>> This should already be private to the rproc as it knows 
>>>>>>>>>> how large is its program memory.
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Caller is trying to boot the rproc with a firmware binary. Caller 
>>>>>>>>> should
>>>>>>>>> know the size of binary that it wants to load to rproc core. Caller 
>>>>>>>>> will
>>>>>>>>> specify the binary size to rproc_boot(). Based on the size provided by
>>>>>>>>> caller, rproc_boot() will then allocate that much memory and call
>>>>>>>>> request_firmware_into_buf() with the size and allocated buffer. If the
>>>>>>>>> caller doesn't provide minimum size rproc_load() will fail.
>>>>>>>>
>>>>>>>> Caller only knows the filename. It need not know more details.
>>>>>>>
>>>>>>> Caller is trying to load a file of it's choice to a rproc. Caller should
>>>>>>> know the size of file it is trying to load or atleast the max size that
>>>>>>> the firmware file could be of.
>>>>>>>
>>>>>>>
>>>>>>>> Also see my comment below about rproc_boot() API.
>>>>>>>>
>>>>>>>>>
>>>>>>>>> rproc_load() calls respective driver ops, for example: pru_load().
>>>>>>>>> pru_load() [1] API checks the required size of firmware to load by
>>>>>>>>> casting the buffer into Elf32_Ehdr and Elf32_Phdr and returns error if
>>>>>>>>> size provided by caller is less than this.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>   if (offset + filesz > size) {
>>>>>>>>>   dev_dbg(dev, "truncated fw: need 0x%x avail 0x%zx\n",
>>>>>>>>>   offset + filesz, size);
>>>>>>>>>   ret = -EINVAL;
>>>>>>>>>   break;
>>>>>>>>>   }
>>>>>>>>>
>>>>>>>>>>> + *
>>>>>>>>>>> + * Boot a remote processor (i.e. load its firmware, power it on, 
>>>>>>>>>>> ...).
>>>>>>>>>>> + *
>>>>>>>>>>> + * This function first loads the firmware set in the uclass pdata 
>>>>>>>>>>> of Remote
>>>>>>>>>>> + * processor to a buffer and then loads firmware to the remote 
>>>>>>>>>>> processor
>>>>>>>>>>> + * using rproc_load().
>>>>>>>>>>> + *
>>>>>>>>>>> + * Return: 0 on success, and an appropriate error value oth

Re: [PATCH v4] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-02-07 Thread MD Danish Anwar
Hi Sean,

On 07/02/24 11:14 pm, Sean Anderson wrote:
> On 1/30/24 01:26, MD Danish Anwar wrote:
>> The fs-loader driver reads env storage_interface and uses it to load
>> firmware file into memory using the medium set by env. Update the driver
>> to use env fw_storage_interface as this variable is only used to load
>> firmwares. The env storage_interface will act as fallback so that the
>> existing implementations do not break.
>>
>> Also update the FS Loader documentation accordingly.
> 
> So why do you want to do this? I don't see what the point of renaming the
> variable is, since you are not e.g. adding any new functionality, and we
> have to pay for the rename in code size.
> 

I am upstreaming TI's ICSSG driver for u-boot and during code review
Roger Quadros  commented asking to rename this
variable [1]. I think the motive here was to keep all variables used by
fs-loader driver with 'fw_' prefix. All other variables had 'fw_' prefix
except for storage_interface.

[1]
https://lore.kernel.org/all/4721f3b9-f823-47f3-b4f3-ed40002af...@kernel.org/

> --Sean

-- 
Thanks and Regards,
Danish


Re: [PATCH v4] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-06 Thread MD Danish Anwar
Hi Roger

On 06/02/24 7:11 pm, Roger Quadros wrote:
> 
> 
> On 06/02/2024 07:31, MD Danish Anwar wrote:
>>
>>
>> On 05/02/24 6:07 pm, Roger Quadros wrote:
>>>
>>>
>>> On 05/02/2024 12:20, MD Danish Anwar wrote:
>>>>
>>>>
>>>> On 05/02/24 3:36 pm, Roger Quadros wrote:
>>>>>
>>>>>
>>>>> On 02/02/2024 18:40, Anwar, Md Danish wrote:
>>>>>> Hi Roger,
>>>>>>
>>>>>> On 2/2/2024 4:49 PM, Roger Quadros wrote:
>>>>>>>
>>>>>>>
>>>>>>> On 30/01/2024 08:33, MD Danish Anwar wrote:
>>>>>>>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>>>>>>>> same firmware.
>>>>>>>>
>>
>> 
>>
>>>>>>
>>>>>>> How does caller know what firmware size to set to?
>>>>>>> This should already be private to the rproc as it knows 
>>>>>>> how large is its program memory.
>>>>>>>
>>>>>>
>>>>>> Caller is trying to boot the rproc with a firmware binary. Caller should
>>>>>> know the size of binary that it wants to load to rproc core. Caller will
>>>>>> specify the binary size to rproc_boot(). Based on the size provided by
>>>>>> caller, rproc_boot() will then allocate that much memory and call
>>>>>> request_firmware_into_buf() with the size and allocated buffer. If the
>>>>>> caller doesn't provide minimum size rproc_load() will fail.
>>>>>
>>>>> Caller only knows the filename. It need not know more details.
>>>>
>>>> Caller is trying to load a file of it's choice to a rproc. Caller should
>>>> know the size of file it is trying to load or atleast the max size that
>>>> the firmware file could be of.
>>>>
>>>>
>>>>> Also see my comment below about rproc_boot() API.
>>>>>
>>>>>>
>>>>>> rproc_load() calls respective driver ops, for example: pru_load().
>>>>>> pru_load() [1] API checks the required size of firmware to load by
>>>>>> casting the buffer into Elf32_Ehdr and Elf32_Phdr and returns error if
>>>>>> size provided by caller is less than this.
>>>>>>
>>>>>>
>>>>>>  if (offset + filesz > size) {
>>>>>>  dev_dbg(dev, "truncated fw: need 0x%x avail 0x%zx\n",
>>>>>>  offset + filesz, size);
>>>>>>  ret = -EINVAL;
>>>>>>  break;
>>>>>>  }
>>>>>>
>>>>>>>> + *
>>>>>>>> + * Boot a remote processor (i.e. load its firmware, power it on, ...).
>>>>>>>> + *
>>>>>>>> + * This function first loads the firmware set in the uclass pdata of 
>>>>>>>> Remote
>>>>>>>> + * processor to a buffer and then loads firmware to the remote 
>>>>>>>> processor
>>>>>>>> + * using rproc_load().
>>>>>>>> + *
>>>>>>>> + * Return: 0 on success, and an appropriate error value otherwise
>>>>>>>> + */
>>>>>>>> +int rproc_boot(struct udevice *rproc_dev, size_t fw_size);
>>>>>>>
>>>>>>> Was wondering if you need separate API for rproc_set_firmware or we can 
>>>>>>> just
>>>>>>> pass firmware name as argument to rproc_boot()?
>>>>>>>
>>>>>>
>>>>>> Technically we can. But when we discussed this approach first in v1, you
>>>>>> had asked to keep the APIs similar to upstream linux. Upstream linux has
>>>>>> these two APIs so I kept it that way. If you want I can drop the first
>>>>>> API. Please let me know.
>>>>>
>>>>> Sure you can keep it as it is in Linux, but there, rproc_boot doesn't
>>>>> take fw_size argument. So wondering why you should have it in u-boot.
>>>>>
>>>>
>>>> For loading firmware to a rproc core in u-boot, it's first neccassry to
>>>> load the firmware into buffer and then load that buffer into rproc core
>>>> using rproc_load() API. Now to load the firmware to a buf

Re: [PATCH v4] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-05 Thread MD Danish Anwar



On 05/02/24 6:07 pm, Roger Quadros wrote:
> 
> 
> On 05/02/2024 12:20, MD Danish Anwar wrote:
>>
>>
>> On 05/02/24 3:36 pm, Roger Quadros wrote:
>>>
>>>
>>> On 02/02/2024 18:40, Anwar, Md Danish wrote:
>>>> Hi Roger,
>>>>
>>>> On 2/2/2024 4:49 PM, Roger Quadros wrote:
>>>>>
>>>>>
>>>>> On 30/01/2024 08:33, MD Danish Anwar wrote:
>>>>>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>>>>>> same firmware.
>>>>>>



>>>>
>>>>> How does caller know what firmware size to set to?
>>>>> This should already be private to the rproc as it knows 
>>>>> how large is its program memory.
>>>>>
>>>>
>>>> Caller is trying to boot the rproc with a firmware binary. Caller should
>>>> know the size of binary that it wants to load to rproc core. Caller will
>>>> specify the binary size to rproc_boot(). Based on the size provided by
>>>> caller, rproc_boot() will then allocate that much memory and call
>>>> request_firmware_into_buf() with the size and allocated buffer. If the
>>>> caller doesn't provide minimum size rproc_load() will fail.
>>>
>>> Caller only knows the filename. It need not know more details.
>>
>> Caller is trying to load a file of it's choice to a rproc. Caller should
>> know the size of file it is trying to load or atleast the max size that
>> the firmware file could be of.
>>
>>
>>> Also see my comment below about rproc_boot() API.
>>>
>>>>
>>>> rproc_load() calls respective driver ops, for example: pru_load().
>>>> pru_load() [1] API checks the required size of firmware to load by
>>>> casting the buffer into Elf32_Ehdr and Elf32_Phdr and returns error if
>>>> size provided by caller is less than this.
>>>>
>>>>
>>>>if (offset + filesz > size) {
>>>>dev_dbg(dev, "truncated fw: need 0x%x avail 0x%zx\n",
>>>>offset + filesz, size);
>>>>ret = -EINVAL;
>>>>break;
>>>>}
>>>>
>>>>>> + *
>>>>>> + * Boot a remote processor (i.e. load its firmware, power it on, ...).
>>>>>> + *
>>>>>> + * This function first loads the firmware set in the uclass pdata of 
>>>>>> Remote
>>>>>> + * processor to a buffer and then loads firmware to the remote processor
>>>>>> + * using rproc_load().
>>>>>> + *
>>>>>> + * Return: 0 on success, and an appropriate error value otherwise
>>>>>> + */
>>>>>> +int rproc_boot(struct udevice *rproc_dev, size_t fw_size);
>>>>>
>>>>> Was wondering if you need separate API for rproc_set_firmware or we can 
>>>>> just
>>>>> pass firmware name as argument to rproc_boot()?
>>>>>
>>>>
>>>> Technically we can. But when we discussed this approach first in v1, you
>>>> had asked to keep the APIs similar to upstream linux. Upstream linux has
>>>> these two APIs so I kept it that way. If you want I can drop the first
>>>> API. Please let me know.
>>>
>>> Sure you can keep it as it is in Linux, but there, rproc_boot doesn't
>>> take fw_size argument. So wondering why you should have it in u-boot.
>>>
>>
>> For loading firmware to a rproc core in u-boot, it's first neccassry to
>> load the firmware into buffer and then load that buffer into rproc core
>> using rproc_load() API. Now to load the firmware to a buffer ther is an
>> API request_firmware_into_buf(). This API takes size of firmware as one
>> of it's argument. So in order to call this API from rproc_boot() we need
>> to pass fw_size to rproc_boot()
>>
>> Other u-boot drivers using request_firmware_into_buf() are also passing
>> size of firmware from their driver.
> 
> But in your driver you didn't use size of firmware but some 64K
> https://lore.kernel.org/all/20240124064930.1787929-8-danishan...@ti.com/
> 

Yes, in driver I am hardcoding the size to 64K. That's because I know
the size of ICSSG firmwares are less than 64K. Instead of hardcoding I
can also define macro or provide a config option where we set the size
and the driver will read the size from the config and call rproc_boot()
with size.

For example, fm.c driver reads the size f

Re: [PATCH v4] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-02-05 Thread MD Danish Anwar



On 05/02/24 3:36 pm, Roger Quadros wrote:
> 
> 
> On 02/02/2024 18:40, Anwar, Md Danish wrote:
>> Hi Roger,
>>
>> On 2/2/2024 4:49 PM, Roger Quadros wrote:
>>>
>>>
>>> On 30/01/2024 08:33, MD Danish Anwar wrote:
>>>> Add APIs to set a firmware_name to a rproc and boot the rproc with the
>>>> same firmware.
>>>>
>>>> Clients can call rproc_set_firmware() API to set firmware_name for a rproc
>>>> whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
>>>> a buffer by calling request_firmware_into_buf(). rproc_boot() will then
>>>> load the firmware file to the remote processor and start the remote
>>>> processor.
>>>>
>>>> Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
>>>> Kconfig so that we can call request_firmware_into_buf() from remoteproc
>>>> driver.
>>>>
>>>> Signed-off-by: MD Danish Anwar 
>>>> ---
>>>> Changes from v3 to v4:
>>>> *) No functional change. Splitted the patch out of the series as suggested
>>>>by Nishant.
>>>> *) Droppped the RFC tag.
>>>>
>>>> v3: 
>>>> https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/
>>>>
>>>>  drivers/remoteproc/Kconfig|  1 +
>>>>  drivers/remoteproc/rproc-uclass.c | 85 +++
>>>>  include/remoteproc.h  | 35 +
>>>>  3 files changed, 121 insertions(+)
>>>>
>>>> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
>>>> index 781de530af..0fdf1b38ea 100644
>>>> --- a/drivers/remoteproc/Kconfig
>>>> +++ b/drivers/remoteproc/Kconfig
>>>> @@ -10,6 +10,7 @@ menu "Remote Processor drivers"
>>>>  # All users should depend on DM
>>>>  config REMOTEPROC
>>>>bool
>>>> +  select FS_LOADER
>>>>depends on DM
>>>>  
>>>>  # Please keep the configuration alphabetically sorted.
>>>> diff --git a/drivers/remoteproc/rproc-uclass.c 
>>>> b/drivers/remoteproc/rproc-uclass.c
>>>> index 28b362c887..76db4157f7 100644
>>>> --- a/drivers/remoteproc/rproc-uclass.c
>>>> +++ b/drivers/remoteproc/rproc-uclass.c
>>>> @@ -13,6 +13,7 @@
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> +#include 
>>>>  #include 
>>>>  #include 
>>>>  #include 
>>>> @@ -961,3 +962,87 @@ unsigned long rproc_parse_resource_table(struct 
>>>> udevice *dev, struct rproc *cfg)
>>>>  
>>>>return 1;
>>>>  }
>>>> +
>>>> +int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
>>>> +{
>>>> +  struct dm_rproc_uclass_pdata *uc_pdata;
>>>> +  int len;
>>>> +  char *p;
>>>> +
>>>> +  if (!rproc_dev || !fw_name)
>>>> +  return -EINVAL;
>>>> +
>>>> +  uc_pdata = dev_get_uclass_plat(rproc_dev);
>>>
>>> This can return NULL and you shuould error out if it does.
>>>
>>
>> Sure.
>>
>>>> +
>>>> +  len = strcspn(fw_name, "\n");
>>>> +  if (!len) {
>>>> +  debug("can't provide empty string for firmware name\n");
>>>
>>> how about "invalid filename" ?
>>>
>>
>> Sure.
>>
>>>> +  return -EINVAL;
>>>> +  }
>>>> +
>>>> +  p = strndup(fw_name, len);
>>>> +  if (!p)
>>>> +  return -ENOMEM;
>>>> +
>>>> +  uc_pdata->fw_name = p;
>>>> +
>>>> +  return 0;
>>>> +}
>>>> +
>>>> +int rproc_boot(struct udevice *rproc_dev, size_t fw_size)
>>>> +{
>>>> +  struct dm_rproc_uclass_pdata *uc_pdata;
>>>> +  struct udevice *fs_loader;
>>>> +  void *addr = malloc(fw_size);
>>>
>>> I will suggest to do malloc just before you need the buffer.
>>> You need to free up the buffer an all return paths after that.
>>>
>>
>> That is correct. I will do malloc just before calling
>> request_firmware_into_buf() API.
>>
>>>> +  int core_id, ret = 0;
>>>> +  char *firmware;
>>>> +  ulong rproc_addr;
>>>
&g

[PATCH v4] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-01-29 Thread MD Danish Anwar
Add APIs to set a firmware_name to a rproc and boot the rproc with the
same firmware.

Clients can call rproc_set_firmware() API to set firmware_name for a rproc
whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
a buffer by calling request_firmware_into_buf(). rproc_boot() will then
load the firmware file to the remote processor and start the remote
processor.

Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
Kconfig so that we can call request_firmware_into_buf() from remoteproc
driver.

Signed-off-by: MD Danish Anwar 
---
Changes from v3 to v4:
*) No functional change. Splitted the patch out of the series as suggested
   by Nishant.
*) Droppped the RFC tag.

v3: https://lore.kernel.org/all/20240124064930.1787929-4-danishan...@ti.com/

 drivers/remoteproc/Kconfig|  1 +
 drivers/remoteproc/rproc-uclass.c | 85 +++
 include/remoteproc.h  | 35 +
 3 files changed, 121 insertions(+)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 781de530af..0fdf1b38ea 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -10,6 +10,7 @@ menu "Remote Processor drivers"
 # All users should depend on DM
 config REMOTEPROC
bool
+   select FS_LOADER
depends on DM
 
 # Please keep the configuration alphabetically sorted.
diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 28b362c887..76db4157f7 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -961,3 +962,87 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev, struct rproc *cfg)
 
return 1;
 }
+
+int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   int len;
+   char *p;
+
+   if (!rproc_dev || !fw_name)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+
+   len = strcspn(fw_name, "\n");
+   if (!len) {
+   debug("can't provide empty string for firmware name\n");
+   return -EINVAL;
+   }
+
+   p = strndup(fw_name, len);
+   if (!p)
+   return -ENOMEM;
+
+   uc_pdata->fw_name = p;
+
+   return 0;
+}
+
+int rproc_boot(struct udevice *rproc_dev, size_t fw_size)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   struct udevice *fs_loader;
+   void *addr = malloc(fw_size);
+   int core_id, ret = 0;
+   char *firmware;
+   ulong rproc_addr;
+
+   if (!rproc_dev)
+   return -EINVAL;
+
+   if (!addr)
+   return -ENOMEM;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   core_id = dev_seq(rproc_dev);
+   firmware = uc_pdata->fw_name;
+
+   if (!firmware) {
+   debug("No firmware set for rproc core %d\n", core_id);
+   return -EINVAL;
+   }
+
+   /* Initialize all rproc cores */
+   rproc_init();
+
+   /* Loading firmware to a given address */
+   ret = get_fs_loader(_loader);
+   if (ret) {
+   debug("could not get fs loader: %d\n", ret);
+   return ret;
+   }
+
+   ret = request_firmware_into_buf(fs_loader, firmware, addr, fw_size, 0);
+   if (ret < 0) {
+   debug("could not request %s: %d\n", firmware, ret);
+   return ret;
+   }
+
+   rproc_addr = (ulong)addr;
+
+   ret = rproc_load(core_id, rproc_addr, ret);
+   if (ret) {
+   debug("failed to load %s to rproc core %d from addr 0x%08lX err 
%d\n",
+ uc_pdata->fw_name, core_id, rproc_addr, ret);
+   return ret;
+   }
+
+   ret = rproc_start(core_id);
+   if (ret) {
+   debug("failed to start rproc core %d\n", core_id);
+   return ret;
+   }
+
+   return ret;
+}
diff --git a/include/remoteproc.h b/include/remoteproc.h
index 91a88791a4..e53f85ba51 100644
--- a/include/remoteproc.h
+++ b/include/remoteproc.h
@@ -403,6 +403,7 @@ enum rproc_mem_type {
  * @name: Platform-specific way of naming the Remote proc
  * @mem_type: one of 'enum rproc_mem_type'
  * @driver_plat_data: driver specific platform data that may be needed.
+ * @fw_name: firmware name
  *
  * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
  * device.
@@ -412,6 +413,7 @@ struct dm_rproc_uclass_pdata {
const char *name;
enum rproc_mem_type mem_type;
void *driver_plat_data;
+   char *fw_name;
 };
 
 /**
@@ -705,6 +707,35 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev,
 struct resource_table *rproc_find_resource_table(struct udevice *dev,
   

[PATCH v4] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-01-29 Thread MD Danish Anwar
The fs-loader driver reads env storage_interface and uses it to load
firmware file into memory using the medium set by env. Update the driver
to use env fw_storage_interface as this variable is only used to load
firmwares. The env storage_interface will act as fallback so that the
existing implementations do not break.

Also update the FS Loader documentation accordingly.

Signed-off-by: MD Danish Anwar 
---
Changes from v3 to v4:
*) No functional change. Splitted the patch out of the series as suggested
   by Nishant.
*) Droppped the RFC tag.

v3: https://lore.kernel.org/all/20240124064930.1787929-3-danishan...@ti.com/

 doc/develop/driver-model/fs_firmware_loader.rst | 5 -
 drivers/misc/fs_loader.c| 5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/develop/driver-model/fs_firmware_loader.rst 
b/doc/develop/driver-model/fs_firmware_loader.rst
index 149b8b436e..410cc1442d 100644
--- a/doc/develop/driver-model/fs_firmware_loader.rst
+++ b/doc/develop/driver-model/fs_firmware_loader.rst
@@ -98,8 +98,11 @@ through the U-Boot environment variable during run time.
 
 For examples:
 
+fw_storage_interface:
+  Firmware storage interface, it can be "mmc", "usb", "sata" or "ubi".
 storage_interface:
-  Storage interface, it can be "mmc", "usb", "sata" or "ubi".
+  Storage interface, it can be "mmc", "usb", "sata" or "ubi". This acts
+  as a fallback if fw_storage_interface is not set.
 fw_dev_part:
   Block device number and its partition, it can be "0:1".
 fw_ubi_mtdpart:
diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
index 1ffc199ba1..3798dab5b6 100644
--- a/drivers/misc/fs_loader.c
+++ b/drivers/misc/fs_loader.c
@@ -153,7 +153,10 @@ static int fw_get_filesystem_firmware(struct udevice *dev)
char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume;
int ret;
 
-   storage_interface = env_get("storage_interface");
+   storage_interface = env_get("fw_storage_interface");
+   if (!storage_interface)
+   storage_interface = env_get("storage_interface");
+
dev_part = env_get("fw_dev_part");
ubi_mtdpart = env_get("fw_ubi_mtdpart");
ubi_volume = env_get("fw_ubi_volume");
-- 
2.34.1



[PATCH v4] dma: ti: k3-udma: Use ring_idx to pair k3 nav rings

2024-01-29 Thread MD Danish Anwar
Use ring_idx to pair rings. ring_idx will be same as tx flow_id for all
non-negative flow_ids. For negative flow_ids, ring_idx will be tchan->id
added with bchan_cnt.

Signed-off-by: MD Danish Anwar 
---
Changes from v3 to v4:
*) No functional change. Splitted the patch out of the series as suggested
   by Nishant.

v3: https://lore.kernel.org/all/20240124064930.1787929-2-danishan...@ti.com/

 drivers/dma/ti/k3-udma.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 8a62d63dfe..eea9ec9659 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -876,13 +876,20 @@ static int udma_alloc_tx_resources(struct udma_chan *uc)
 {
struct k3_nav_ring_cfg ring_cfg;
struct udma_dev *ud = uc->ud;
-   int ret;
+   struct udma_tchan *tchan;
+   int ring_idx, ret;
 
ret = udma_get_tchan(uc);
if (ret)
return ret;
 
-   ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, uc->tchan->id, -1,
+   tchan = uc->tchan;
+   if (tchan->tflow_id >= 0)
+   ring_idx = tchan->tflow_id;
+   else
+   ring_idx = ud->bchan_cnt + tchan->id;
+
+   ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, ring_idx, -1,
>tchan->t_ring,
>tchan->tc_ring);
if (ret) {
-- 
2.34.1



Re: [RFC PATCH v3 14/15] board: ti: am65x: Add check for k3-am654-icssg2 in board_fit_config_match()

2024-01-24 Thread MD Danish Anwar



On 24/01/24 1:57 pm, Dan Carpenter wrote:
> On Wed, Jan 24, 2024 at 12:19:29PM +0530, MD Danish Anwar wrote:
>> When CONFIG_TI_ICSSG_PRUETH is enabled, add config name check for the
>> icssg2 overlay in board_fit_config_match() API.
>>
>> Signed-off-by: MD Danish Anwar 
>> ---
>>  board/ti/am65x/evm.c | 11 +++
>>  1 file changed, 7 insertions(+), 4 deletions(-)
>>
>> diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
>> index df209021c1..0b661f0084 100644
>> --- a/board/ti/am65x/evm.c
>> +++ b/board/ti/am65x/evm.c
>> @@ -90,10 +90,13 @@ int dram_init_banksize(void)
>>  #ifdef CONFIG_SPL_LOAD_FIT
>>  int board_fit_config_name_match(const char *name)
>>  {
>> -#ifdef CONFIG_TARGET_AM654_A53_EVM
>> -if (!strcmp(name, "k3-am654-base-board"))
>> -return 0;
>> -#endif
>> +if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
>> +if (!strcmp(name, "k3-am654-icssg2"))
>> +return 0;
>> +} else {
>> +if (!strcmp(name, "k3-am654-base-board"))
>> +return 0;
>> +}
>>  
>>  return -1;
>>  }
> 
> It probably should support both configs being enabled.
> 
>   if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH) &&
>   strcmp(name, "k3-am654-icssg2") == 0)
>   return 0;
> 
>   if (IS_ENABLED(TARGET_AM654_A53_EVM) &&
>   strcmp(name, "k3-am654-base-board"))
>   return 0;
> 
>   return -1;
> 

Sure Dan. This seems reasonable. I will add check for both configs in
next revision. Thanks for the review.

> regards,
> dan carpenter

-- 
Thanks and Regards,
Danish


[RFC PATCH v3 11/15] arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration

2024-01-24 Thread MD Danish Anwar
Add ICSSG2 overlay and configuration to tispl and u-boot images.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/k3-am65x-binman.dtsi | 65 +--
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
b/arch/arm/dts/k3-am65x-binman.dtsi
index 8cc24da1f3..d0cd4889cd 100644
--- a/arch/arm/dts/k3-am65x-binman.dtsi
+++ b/arch/arm/dts/k3-am65x-binman.dtsi
@@ -98,6 +98,8 @@
 #define SPL_AM654_EVM_DTB "spl/dts/k3-am654-base-board.dtb"
 #define AM654_EVM_DTB "u-boot.dtb"
 
+#define AM654_EVM_ICSSG2_DTBO "arch/arm/dts/k3-am654-icssg2.dtbo"
+
  {
ti-spl {
insert-template = <_spl_template>;
@@ -124,6 +126,20 @@
filename = SPL_AM654_EVM_DTB;
};
};
+
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = 
<_am65x_evm_icssg2_dtb>;
+   keyfile = "custMpk.pem";
+   };
+   spl_am65x_evm_icssg2_dtb: blob-ext {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   };
};
 
configurations {
@@ -133,7 +149,7 @@
description = "k3-am654-base-board";
firmware = "atf";
loadables = "tee", "dm", "spl";
-   fdt = "fdt-0";
+   fdt = "fdt-0", "fdt-1";
};
};
};
@@ -168,6 +184,24 @@
};
};
 
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = 
<_evm_icssg2_dtb>;
+   keyfile = "custMpk.pem";
+
+   };
+   am65x_evm_icssg2_dtb: blob-ext {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   hash {
+   algo = "crc32";
+   };
+   };
+
};
 
configurations {
@@ -177,7 +211,7 @@
description = "k3-am654-base-board";
firmware = "uboot";
loadables = "uboot";
-   fdt = "fdt-0";
+   fdt = "fdt-0", "fdt-1";
};
};
};
@@ -205,6 +239,16 @@
filename = SPL_AM654_EVM_DTB;
};
};
+
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   blob {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   };
};
 
configurations {
@@ -214,7 +258,7 @@
description = "k3-am654-base-board";
firmware = "atf&quo

[RFC PATCH v3 15/15] board: ti: am65x: Set fw_storage_interface and fw_dev_part ENVs

2024-01-24 Thread MD Danish Anwar
When ICSSG driver is enabled (CONFIG_TI_ICSSG_PRUETH=y) set
fw_storage_interface and fw_dev_part env variables.

These variables need be set appropriately in order to load differnet
ICSSG firmwares needed for ICSSG driver. By default the storage
interface is mmc and the partition is 1:2. User can modify this based on
their needs.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am65x/am65x.env | 4 
 1 file changed, 4 insertions(+)

diff --git a/board/ti/am65x/am65x.env b/board/ti/am65x/am65x.env
index 286b9c300c..5d6b98b87c 100644
--- a/board/ti/am65x/am65x.env
+++ b/board/ti/am65x/am65x.env
@@ -30,3 +30,7 @@ get_fdt_ubi=ubifsload ${fdtaddr} ${bootdir}/${name_fdt}
 args_ubi=setenv bootargs console=${console} ${optargs}
 rootfstype=ubifs root=ubi0:rootfs rw ubi.mtd=ospi.rootfs
 
+#if CONFIG_TI_ICSSG_PRUETH
+fw_storage_interface=mmc
+fw_dev_part=1:2
+#endif
-- 
2.34.1



[RFC PATCH v3 14/15] board: ti: am65x: Add check for k3-am654-icssg2 in board_fit_config_match()

2024-01-24 Thread MD Danish Anwar
When CONFIG_TI_ICSSG_PRUETH is enabled, add config name check for the
icssg2 overlay in board_fit_config_match() API.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am65x/evm.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index df209021c1..0b661f0084 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -90,10 +90,13 @@ int dram_init_banksize(void)
 #ifdef CONFIG_SPL_LOAD_FIT
 int board_fit_config_name_match(const char *name)
 {
-#ifdef CONFIG_TARGET_AM654_A53_EVM
-   if (!strcmp(name, "k3-am654-base-board"))
-   return 0;
-#endif
+   if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
+   if (!strcmp(name, "k3-am654-icssg2"))
+   return 0;
+   } else {
+   if (!strcmp(name, "k3-am654-base-board"))
+   return 0;
+   }
 
return -1;
 }
-- 
2.34.1



[RFC PATCH v3 13/15] configs: am65x_evm_a53: add SPL_LOAD_FIT_APPLY_OVERLAY

2024-01-24 Thread MD Danish Anwar
We want SPL to apply DTB overlays (e.g. ICSSG2 overlay) so enable
SPL_LOAD_FIT_APPLY_OVERLAY.

Signed-off-by: MD Danish Anwar 
---
 configs/am65x_evm_a53_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index aeea24d773..329973de68 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -69,6 +69,7 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
+CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_TIME=y
 CONFIG_MTDIDS_DEFAULT="nor0=4704.spi.0"
-- 
2.34.1



[RFC PATCH v3 12/15] configs: am65x_evm_a53: Enable ICSSG Driver

2024-01-24 Thread MD Danish Anwar
Enable ICSSG driver in am65x_evm_a53_defconfig

Signed-off-by: MD Danish Anwar 
---
 configs/am65x_evm_a53_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index 529bda283d..aeea24d773 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -129,6 +129,7 @@ CONFIG_PHY_FIXED=y
 CONFIG_E1000=y
 CONFIG_CMD_E1000=y
 CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_TI_ICSSG_PRUETH=y
 CONFIG_PCI_KEYSTONE=y
 CONFIG_PHY=y
 CONFIG_SPL_PHY=y
-- 
2.34.1



[RFC PATCH v3 10/15] arm: dts: k3-am654-base-board: Add ICSSG2 Ethernet support

2024-01-24 Thread MD Danish Anwar
ICSSG2 provides dual Gigabit Ethernet support.
Add ICSSG2 ethernet node to an overlay k3-am654-icssg2.dtso

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/Makefile |   3 +-
 arch/arm/dts/k3-am654-icssg2.dtso | 145 ++
 2 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/k3-am654-icssg2.dtso

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index e9e58c5478..2bc53fba89 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1396,7 +1396,8 @@ dtb-$(CONFIG_SOC_K3_AM654) += \
k3-am6548-iot2050-advanced-pg2.dtb \
k3-am6548-iot2050-advanced-m2.dtb \
k3-am6548-iot2050-advanced-m2-bkey-usb3-overlay.dtbo \
-   k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dtbo
+   k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dtbo \
+   k3-am654-icssg2.dtbo
 dtb-$(CONFIG_SOC_K3_J721E) += k3-j721e-common-proc-board.dtb \
  k3-j721e-r5-common-proc-board.dtb \
  k3-j7200-common-proc-board.dtb \
diff --git a/arch/arm/dts/k3-am654-icssg2.dtso 
b/arch/arm/dts/k3-am654-icssg2.dtso
new file mode 100644
index 00..faefa2febc
--- /dev/null
+++ b/arch/arm/dts/k3-am654-icssg2.dtso
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * DT overlay for enabling ICSSG2 on AM654 EVM
+ *
+ * Copyright (C) 2018-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+/dts-v1/;
+/plugin/;
+
+#include 
+#include "k3-pinctrl.h"
+
+&{/} {
+   aliases {
+   ethernet1 = "/icssg2-eth/ethernet-ports/port@0";
+   ethernet2 = "/icssg2-eth/ethernet-ports/port@1";
+   };
+
+   /* Ethernet node on PRU-ICSSG2 */
+   icssg2_eth: icssg2-eth {
+   compatible = "ti,am654-icssg-prueth";
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii_pins_default>;
+   sram = <_ram>;
+   ti,prus = <_0>, <_0>, <_pru2_0>,
+   <_1>, <_1>, <_pru2_1>;
+   firmware-name = "ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-txpru1-prueth-fw.elf";
+
+   ti,pruss-gp-mux-sel = <2>,  /* MII mode */
+ <2>,
+ <2>,
+ <2>,  /* MII mode */
+ <2>,
+ <2>;
+
+   ti,mii-g-rt = <_mii_g_rt>;
+   ti,mii-rt = <_mii_rt>;
+   ti,iep = <_iep0>, <_iep1>;
+
+   interrupt-parent = <_intc>;
+   interrupts = <24 0 2>, <25 1 3>;
+   interrupt-names = "tx_ts0", "tx_ts1";
+
+   dmas = <_udmap 0xc300>, /* egress slice 0 */
+  <_udmap 0xc301>, /* egress slice 0 */
+  <_udmap 0xc302>, /* egress slice 0 */
+  <_udmap 0xc303>, /* egress slice 0 */
+  <_udmap 0xc304>, /* egress slice 1 */
+  <_udmap 0xc305>, /* egress slice 1 */
+  <_udmap 0xc306>, /* egress slice 1 */
+  <_udmap 0xc307>, /* egress slice 1 */
+  <_udmap 0x4300>, /* ingress slice 0 */
+  <_udmap 0x4301>; /* ingress slice 1 */
+
+   dma-names = "tx0-0", "tx0-1", "tx0-2", "tx0-3",
+   "tx1-0", "tx1-1", "tx1-2", "tx1-3",
+   "rx0", "rx1";
+   ethernet-ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   icssg2_emac0: port@0 {
+   reg = <0>;
+   phy-handle = <_phy0>;
+   phy-mode = "rgmii-id";
+   ti,syscon-rgmii-delay = <_conf 0x4120>;
+   /* Filled in by bootloader */
+   local-mac-address = [00 00 00 00 00 00];
+   };
+   icssg2_emac1: port@1 {
+   reg = <1>;
+   

[RFC PATCH v3 09/15] net: ti: icssg: Enforce pinctrl state on the MDIO child node

2024-01-24 Thread MD Danish Anwar
The binding represents the MDIO controller as a child device tree
node of the MAC device tree node.

The U-Boot driver mostly ignores that child device tree node and just
hardcodes the resources it uses to support both the MAC and MDIO in a
single driver.

However, some resources like pinctrl muxing states are thus ignored.
This has been a problem with some device trees that will put some
pinctrl states on the MDIO device tree node.

Let's rework the driver a bit to create a dummy MDIO driver that we will
then get during our initialization to force the core to select the right
muxing.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/Kconfig|  1 +
 drivers/net/ti/icssg_prueth.c | 59 +++
 2 files changed, 60 insertions(+)

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index 9fead2c7ce..6935b70e12 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -53,6 +53,7 @@ config TI_AM65_CPSW_NUSS
 config TI_ICSSG_PRUETH
bool "TI Gigabit PRU Ethernet driver"
depends on ARCH_K3
+   imply DM_MDIO
select PHYLIB
help
  Support Gigabit Ethernet ports over the ICSSG PRU Subsystem
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
index 50af9a2bc6..225928e477 100644
--- a/drivers/net/ti/icssg_prueth.c
+++ b/drivers/net/ti/icssg_prueth.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -103,9 +104,56 @@ static int icssg_phy_init(struct udevice *dev)
return ret;
 }
 
+static ofnode prueth_find_mdio(ofnode parent)
+{
+   ofnode node;
+
+   ofnode_for_each_subnode(node, parent)
+   if (ofnode_device_is_compatible(node, "ti,davinci_mdio"))
+   return node;
+
+   return ofnode_null();
+}
+
+static int prueth_mdio_setup(struct udevice *dev)
+{
+   struct prueth *priv = dev_get_priv(dev);
+   struct udevice *mdio_dev;
+   ofnode mdio;
+   int ret;
+
+   mdio = prueth_find_mdio(dev_ofnode(priv->pruss));
+   if (!ofnode_valid(mdio))
+   return 0;
+
+   /*
+* The MDIO controller is represented in the DT binding by a
+* subnode of the MAC controller.
+*
+* We don't have a DM driver for the MDIO device yet, and thus any
+* pinctrl setting on its node will be ignored.
+*
+* However, we do need to make sure the pins states tied to the
+* MDIO node are configured properly. Fortunately, the core DM
+* does that for use when we get a device, so we can work around
+* that whole issue by just requesting a dummy MDIO driver to
+* probe, and our pins will get muxed.
+*/
+   ret = uclass_get_device_by_ofnode(UCLASS_MDIO, mdio, _dev);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
 static int icssg_mdio_init(struct udevice *dev)
 {
struct prueth *prueth = dev_get_priv(dev);
+   int ret;
+
+   ret = prueth_mdio_setup(dev);
+   if (ret)
+   return ret;
 
prueth->bus = cpsw_mdio_init(dev->name, prueth->mdio_base,
 prueth->mdio_freq,
@@ -701,3 +749,14 @@ U_BOOT_DRIVER(prueth) = {
.plat_auto = sizeof(struct eth_pdata),
.flags = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static const struct udevice_id prueth_mdio_ids[] = {
+   { .compatible = "ti,davinci_mdio" },
+   { }
+};
+
+U_BOOT_DRIVER(prueth_mdio) = {
+   .name   = "prueth_mdio",
+   .id = UCLASS_MDIO,
+   .of_match   = prueth_mdio_ids,
+};
-- 
2.34.1



[RFC PATCH v3 08/15] net: ti: icssg: Add support sending FDB command to update rx_flow_id

2024-01-24 Thread MD Danish Anwar
ICSSG firmware supports FDB commands. Add support to send FDB commands
from driver. Once rx_flow_id is obtained from dma, let firmware know that
we are using this rx_flow_id by sending a FDB command.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_config.c | 66 +++
 drivers/net/ti/icssg_config.h | 18 ++
 drivers/net/ti/icssg_prueth.c |  6 
 drivers/net/ti/icssg_prueth.h |  6 
 4 files changed, 96 insertions(+)

diff --git a/drivers/net/ti/icssg_config.c b/drivers/net/ti/icssg_config.c
index 0dc2c0fa3a..630698add4 100644
--- a/drivers/net/ti/icssg_config.c
+++ b/drivers/net/ti/icssg_config.c
@@ -9,6 +9,7 @@
 #include "icssg_switch_map.h"
 #include "icss_mii_rt.h"
 #include 
+#include 
 
 /* TX IPG Values to be set for 100M and 1G link speeds.  These values are
  * in ocp_clk cycles. So need change if ocp_clk is changed for a specific
@@ -395,3 +396,68 @@ int emac_set_port_state(struct prueth *prueth,
 
return ret;
 }
+
+int icssg_send_fdb_msg(struct prueth *prueth, struct mgmt_cmd *cmd,
+  struct mgmt_cmd_rsp *rsp)
+{
+   int slice = prueth->slice;
+   int ret, addr;
+
+   addr = icssg_queue_pop(prueth, slice == 0 ?
+  ICSSG_CMD_POP_SLICE0 : ICSSG_CMD_POP_SLICE1);
+   if (addr < 0)
+   return addr;
+
+   /* First 4 bytes have FW owned buffer linking info which should
+* not be touched
+*/
+   memcpy_toio((void __iomem *)prueth->shram.pa + addr + 4, cmd, 
sizeof(*cmd));
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_CMD_PUSH_SLICE0 : ICSSG_CMD_PUSH_SLICE1, addr);
+   ret = read_poll_timeout(icssg_queue_pop, addr, addr >= 0,
+   2000, 2000, prueth, slice == 0 ?
+   ICSSG_RSP_POP_SLICE0 : ICSSG_RSP_POP_SLICE1);
+
+   if (ret) {
+   dev_err(prueth->dev, "Timedout sending HWQ message\n");
+   return ret;
+   }
+
+   memcpy_fromio(rsp, (void __iomem *)prueth->shram.pa + addr, 
sizeof(*rsp));
+   /* Return buffer back for to pool */
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_RSP_PUSH_SLICE0 : ICSSG_RSP_PUSH_SLICE1, addr);
+
+   return 0;
+}
+
+int emac_fdb_flow_id_updated(struct prueth *prueth)
+{
+   struct mgmt_cmd_rsp fdb_cmd_rsp = { 0 };
+   int slice = prueth->slice;
+   struct mgmt_cmd fdb_cmd = { 0 };
+   int ret = 0;
+
+   fdb_cmd.header = ICSSG_FW_MGMT_CMD_HEADER;
+   fdb_cmd.type   = ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW;
+   fdb_cmd.seqnum = ++(prueth->icssg_hwcmdseq);
+   fdb_cmd.param  = 0;
+
+   fdb_cmd.param |= (slice << 4);
+   fdb_cmd.cmd_args[0] = 0;
+
+   ret = icssg_send_fdb_msg(prueth, _cmd, _cmd_rsp);
+   if (ret)
+   return ret;
+
+   if (fdb_cmd.seqnum != fdb_cmd_rsp.seqnum) {
+   dev_err(prueth->dev, "seqnum doesn't match, cmd.seqnum %d != 
rsp.seqnum %d\n",
+   fdb_cmd.seqnum, fdb_cmd_rsp.seqnum);
+   return -EINVAL;
+   }
+
+   if (fdb_cmd_rsp.status == 1)
+   return 0;
+
+   return -EINVAL;
+}
diff --git a/drivers/net/ti/icssg_config.h b/drivers/net/ti/icssg_config.h
index fc6eae0426..156127bd3d 100644
--- a/drivers/net/ti/icssg_config.h
+++ b/drivers/net/ti/icssg_config.h
@@ -80,6 +80,7 @@ struct icssg_rxq_ctx {
 #define ICSSG_FW_MGMT_FDB_CMD_TYPE 0x03
 #define ICSSG_FW_MGMT_CMD_TYPE 0x04
 #define ICSSG_FW_MGMT_PKT  0x8000
+#define ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW 0x05
 
 struct icssg_r30_cmd {
u32 cmd[4];
@@ -156,6 +157,23 @@ struct icssg_setclock_desc {
u32 CMP0_new;
 } __packed;
 
+struct mgmt_cmd {
+   u8 param;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
+struct mgmt_cmd_rsp {
+   u32 reserved;
+   u8 status;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
 #define ICSSG_CMD_POP_SLICE0   56
 #define ICSSG_CMD_POP_SLICE1   60
 
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
index cd6ff1a7fe..50af9a2bc6 100644
--- a/drivers/net/ti/icssg_prueth.c
+++ b/drivers/net/ti/icssg_prueth.c
@@ -351,6 +351,12 @@ static int prueth_start(struct udevice *dev)
dev_info(dev, "K3 ICSSG: rflow_id_base: %u, chn_name = %s\n",
 dma_rx_cfg_data->flow_id_base, chn_name);
 
+   ret = emac_fdb_flow_id_updated(priv);
+   if (ret) {
+   dev_err(dev, "Failed to update Rx Flow ID %d", ret);
+   goto phy_fail;
+   }
+
ret = phy_startup(priv->phydev);
if (ret) {
dev_err(dev, "phy_startup failed\n");
diff --git a/drivers/net/ti/icssg_prueth.h b/drivers/net/ti/icssg_prueth.

[RFC PATCH v3 07/15] net: ti: icssg: Add ICSSG ethernet driver

2024-01-24 Thread MD Danish Anwar
This is the PURSS Ethernet driver for TI AM654 Sr2.0 and laterSoCs with
the ICSSG PRU Sub-system running EMAC firmware. This driver caters to
either of the slices of the icssg subsystem.

One and exactly one of the slices is supported as the u-boot ethernet
supports probing one interface at a time.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/Kconfig|   8 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icssg_prueth.c | 697 ++
 drivers/net/ti/icssg_prueth.h |   3 +
 4 files changed, 709 insertions(+)
 create mode 100644 drivers/net/ti/icssg_prueth.c

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index c75f418628..9fead2c7ce 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -49,3 +49,11 @@ config TI_AM65_CPSW_NUSS
help
  This driver supports TI K3 MCU CPSW Nuss Ethernet controller
  in Texas Instruments K3 AM65x SoCs.
+
+config TI_ICSSG_PRUETH
+   bool "TI Gigabit PRU Ethernet driver"
+   depends on ARCH_K3
+   select PHYLIB
+   help
+ Support Gigabit Ethernet ports over the ICSSG PRU Subsystem
+ This subsystem is available starting with the AM65 platform.
diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
index 0ce0cf2828..5af760572f 100644
--- a/drivers/net/ti/Makefile
+++ b/drivers/net/ti/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o cpsw_mdio.o
 obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
 obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
 obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o cpsw_mdio.o
+obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg_prueth.o cpsw_mdio.o icssg_classifier.o 
icssg_config.o icssg_queues.o
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
new file mode 100644
index 00..cd6ff1a7fe
--- /dev/null
+++ b/drivers/net/ti/icssg_prueth.c
@@ -0,0 +1,697 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments K3 AM65 PRU Ethernet Driver
+ *
+ * Copyright (C) 2019-2021, Texas Instruments, Incorporated
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "cpsw_mdio.h"
+#include "icssg_prueth.h"
+#include "icss_mii_rt.h"
+
+#define ICSS_SLICE0 0
+#define ICSS_SLICE1 1
+
+#ifdef PKTSIZE_ALIGN
+#define UDMA_RX_BUF_SIZE PKTSIZE_ALIGN
+#else
+#define UDMA_RX_BUF_SIZE ALIGN(1522, ARCH_DMA_MINALIGN)
+#endif
+
+#ifdef PKTBUFSRX
+#define UDMA_RX_DESC_NUM PKTBUFSRX
+#else
+#define UDMA_RX_DESC_NUM 4
+#endif
+
+/* Config region lies in shared RAM */
+#define ICSS_CONFIG_OFFSET_SLICE0  0
+#define ICSS_CONFIG_OFFSET_SLICE1  0x8000
+
+/* Firmware flags */
+#define ICSS_SET_RUN_FLAG_VLAN_ENABLE  BIT(0)  /* switch only */
+#define ICSS_SET_RUN_FLAG_FLOOD_UNICASTBIT(1)  /* switch only 
*/
+#define ICSS_SET_RUN_FLAG_PROMISC  BIT(2)  /* MAC only */
+#define ICSS_SET_RUN_FLAG_MULTICAST_PROMISCBIT(3)  /* MAC only */
+
+/* CTRLMMR_ICSSG_RGMII_CTRL register bits */
+#define ICSSG_CTRL_RGMII_ID_MODE   BIT(24)
+
+/* Management packet type */
+#define PRUETH_PKT_TYPE_CMD0x10
+
+/* Number of PRU Cores per Slice */
+#define ICSSG_NUM_PRU_CORES3
+
+static int icssg_phy_init(struct udevice *dev)
+{
+   struct prueth *priv = dev_get_priv(dev);
+   struct phy_device *phydev;
+   u32 supported = PHY_GBIT_FEATURES;
+   int ret;
+
+   phydev = phy_connect(priv->bus,
+priv->phy_addr,
+priv->dev,
+priv->phy_interface);
+
+   if (!phydev) {
+   dev_err(dev, "phy_connect() failed\n");
+   return -ENODEV;
+   }
+
+   /* disable unsupported features */
+   supported &= ~(PHY_10BT_FEATURES |
+   SUPPORTED_100baseT_Half |
+   SUPPORTED_1000baseT_Half |
+   SUPPORTED_Pause |
+   SUPPORTED_Asym_Pause);
+
+   phydev->supported &= supported;
+   phydev->advertising = phydev->supported;
+
+   if (IS_ENABLED(CONFIG_DM_ETH))
+   if (ofnode_valid(priv->phy_node))
+   phydev->node = priv->phy_node;
+
+   priv->phydev = phydev;
+   ret = phy_config(phydev);
+   if (ret < 0)
+   pr_err("phy_config() failed: %d", ret);
+
+   return ret;
+}
+
+static int icssg_mdio_init(struct udevice *dev)
+{
+   struct prueth *prueth = dev_get_priv(dev);
+
+   prueth->bus = cpsw_mdio_init(dev->name, prueth->mdio_base,
+prueth->mdio_freq,
+clk_get_rate(>mdiofck),
+

[RFC PATCH v3 05/15] net: ti: icssg: Add Firmware config and classification APIs.

2024-01-24 Thread MD Danish Anwar
Add icssg_config.h / .c and icssg_classifier.c files. These are firmware
configuration and classification related files. Add MII helper APIs and
MACROs. These APIs and MACROs will be later used by ICSSG Ethernet driver.
Also introduce icssg_prueth.h which has definition of prueth related
structures.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icss_mii_rt.h  | 192 +++
 drivers/net/ti/icssg_classifier.c | 376 
 drivers/net/ti/icssg_config.c | 397 ++
 drivers/net/ti/icssg_config.h | 177 +
 drivers/net/ti/icssg_prueth.h |  78 ++
 5 files changed, 1220 insertions(+)
 create mode 100644 drivers/net/ti/icss_mii_rt.h
 create mode 100644 drivers/net/ti/icssg_classifier.c
 create mode 100644 drivers/net/ti/icssg_config.c
 create mode 100644 drivers/net/ti/icssg_config.h
 create mode 100644 drivers/net/ti/icssg_prueth.h

diff --git a/drivers/net/ti/icss_mii_rt.h b/drivers/net/ti/icss_mii_rt.h
new file mode 100644
index 00..6b2449e736
--- /dev/null
+++ b/drivers/net/ti/icss_mii_rt.h
@@ -0,0 +1,192 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* PRU-ICSS MII_RT register definitions
+ *
+ * Copyright (C) 2015-2020 Texas Instruments Incorporated - http://www.ti.com
+ */
+
+#ifndef __NET_PRUSS_MII_RT_H__
+#define __NET_PRUSS_MII_RT_H__
+
+#include 
+
+/* PRUSS_MII_RT Registers */
+#define PRUSS_MII_RT_RXCFG00x0
+#define PRUSS_MII_RT_RXCFG10x4
+#define PRUSS_MII_RT_TXCFG00x10
+#define PRUSS_MII_RT_TXCFG10x14
+#define PRUSS_MII_RT_TX_CRC0   0x20
+#define PRUSS_MII_RT_TX_CRC1   0x24
+#define PRUSS_MII_RT_TX_IPG0   0x30
+#define PRUSS_MII_RT_TX_IPG1   0x34
+#define PRUSS_MII_RT_PRS0  0x38
+#define PRUSS_MII_RT_PRS1  0x3c
+#define PRUSS_MII_RT_RX_FRMS0  0x40
+#define PRUSS_MII_RT_RX_FRMS1  0x44
+#define PRUSS_MII_RT_RX_PCNT0  0x48
+#define PRUSS_MII_RT_RX_PCNT1  0x4c
+#define PRUSS_MII_RT_RX_ERR0   0x50
+#define PRUSS_MII_RT_RX_ERR1   0x54
+
+/* PRUSS_MII_RT_RXCFG0/1 bits */
+#define PRUSS_MII_RT_RXCFG_RX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DISBIT(1)
+#define PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE BIT(2)
+#define PRUSS_MII_RT_RXCFG_RX_MUX_SEL  BIT(3)
+#define PRUSS_MII_RT_RXCFG_RX_L2_ENBIT(4)
+#define PRUSS_MII_RT_RXCFG_RX_BYTE_SWAPBIT(5)
+#define PRUSS_MII_RT_RXCFG_RX_AUTO_FWD_PRE BIT(6)
+#define PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS  BIT(9)
+
+/* PRUSS_MII_RT_TXCFG0/1 bits */
+#define PRUSS_MII_RT_TXCFG_TX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLEBIT(1)
+#define PRUSS_MII_RT_TXCFG_TX_EN_MODE  BIT(2)
+#define PRUSS_MII_RT_TXCFG_TX_BYTE_SWAPBIT(3)
+#define PRUSS_MII_RT_TXCFG_TX_MUX_SEL  BIT(8)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_SEQUENCEBIT(9)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_ESC_ERR BIT(10)
+#define PRUSS_MII_RT_TXCFG_TX_32_MODE_EN   BIT(11)
+#define PRUSS_MII_RT_TXCFG_TX_IPG_WIRE_CLK_EN  BIT(12) /* SR2.0 onwards */
+
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT16
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_MASK GENMASK(25, 16)
+
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT  28
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK   GENMASK(30, 28)
+
+/* PRUSS_MII_RT_TX_IPG0/1 bits */
+#define PRUSS_MII_RT_TX_IPG_IPG_SHIFT  0
+#define PRUSS_MII_RT_TX_IPG_IPG_MASK   GENMASK(9, 0)
+
+/* PRUSS_MII_RT_PRS0/1 bits */
+#define PRUSS_MII_RT_PRS_COL   BIT(0)
+#define PRUSS_MII_RT_PRS_CRS   BIT(1)
+
+/* PRUSS_MII_RT_RX_FRMS0/1 bits */
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT 0
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK  GENMASK(15, 0)
+
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT 16
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK  GENMASK(31, 16)
+
+/* Min/Max in MII_RT_RX_FRMS */
+/* For EMAC and Switch */
+#define PRUSS_MII_RT_RX_FRMS_MAX   (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM   (64)
+
+/* for HSR and PRP */
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_LRE   (PRUSS_MII_RT_RX_FRMS_MAX + \
+ICSS_LRE_TAG_RCT_SIZE)
+/* PRUSS_MII_RT_RX_PCNT0/1 bits */
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_SHIFT0
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_MASK GENMASK(3, 0)
+
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_SHIFT4
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_MASK GENMASK(7, 4)
+
+/* PRUSS_MII_RT_RX_ERR0/1 bits */
+#define PRUSS_MII_RT_RX_ERR_MIN_PCNT_ERR   BIT(0)
+#define PRUSS_MII_RT_RX_ERR_MAX_PCNT_ERR   BIT(1)
+#define PRUSS_MII_RT_RX_ERR_MIN_FRM_ERRBIT(2)
+#define PRUSS_MII_RT_RX_ERR_MAX_FRM_ERRBIT(3)
+
+#define ICSSG_CFG_OFFSET   0
+#define RGMII_CFG_OFFSET   4
+
+/* Constant to choose between MII0 and MII1 */
+#define ICSS_MII0  0
+#define ICSS_MII1

[RFC PATCH v3 06/15] net: ti: icssg: Add icssg queues APIs and macros

2024-01-24 Thread MD Danish Anwar
Add icssg_queue.c file. This file introduces macros and APIs related to
ICSSG queues. These will be used by ICSSG Ethernet driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_prueth.h |  5 
 drivers/net/ti/icssg_queues.c | 51 +++
 2 files changed, 56 insertions(+)
 create mode 100644 drivers/net/ti/icssg_queues.c

diff --git a/drivers/net/ti/icssg_prueth.h b/drivers/net/ti/icssg_prueth.h
index 26b77dd8f3..f34ab5d6d4 100644
--- a/drivers/net/ti/icssg_prueth.h
+++ b/drivers/net/ti/icssg_prueth.h
@@ -75,4 +75,9 @@ void icssg_config_ipg(struct prueth *prueth, int speed, int 
mii);
 int icssg_config(struct prueth *prueth);
 int emac_set_port_state(struct prueth *prueth, enum icssg_port_state_cmd cmd);
 
+/* Buffer queue helpers */
+int icssg_queue_pop(struct prueth *prueth, u8 queue);
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr);
+u32 icssg_queue_level(struct prueth *prueth, int queue);
+
 #endif /* __NET_TI_ICSSG_PRUETH_H */
diff --git a/drivers/net/ti/icssg_queues.c b/drivers/net/ti/icssg_queues.c
new file mode 100644
index 00..6a95ef5d58
--- /dev/null
+++ b/drivers/net/ti/icssg_queues.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/* ICSSG Buffer queue helpers
+ *
+ * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include 
+#include 
+#include "icssg_prueth.h"
+
+#define ICSSG_QUEUES_MAX   64
+#define ICSSG_QUEUE_OFFSET 0xd00
+#define ICSSG_QUEUE_PEEK_OFFSET0xe00
+#define ICSSG_QUEUE_CNT_OFFSET 0xe40
+#defineICSSG_QUEUE_RESET_OFFSET0xf40
+
+int icssg_queue_pop(struct prueth *prueth, u8 queue)
+{
+   u32 val, cnt;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+   if (!cnt)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, );
+
+   return val;
+}
+
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
+{
+   if (queue >= ICSSG_QUEUES_MAX)
+   return;
+
+   regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
+}
+
+u32 icssg_queue_level(struct prueth *prueth, int queue)
+{
+   u32 reg;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return 0;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+
+   return reg;
+}
-- 
2.34.1



[RFC PATCH v3 04/15] net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.

2024-01-24 Thread MD Danish Anwar
Add firmware interface related headers and macros for ICSSG Ethernet
driver. These macros will be later used by the ICSSG ethernet driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_switch_map.h | 209 ++
 1 file changed, 209 insertions(+)
 create mode 100644 drivers/net/ti/icssg_switch_map.h

diff --git a/drivers/net/ti/icssg_switch_map.h 
b/drivers/net/ti/icssg_switch_map.h
new file mode 100644
index 00..ba87a44023
--- /dev/null
+++ b/drivers/net/ti/icssg_switch_map.h
@@ -0,0 +1,209 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Texas Instruments ICSSG Ethernet driver
+ *
+ * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
+ *
+ */
+
+#ifndef __NET_TI_ICSSG_SWITCH_MAP_H
+#define __NET_TI_ICSSG_SWITCH_MAP_H
+
+/*Time after which FDB entries are checked for aged out values. Value in 
nanoseconds*/
+#define FDB_AGEING_TIMEOUT_OFFSET  0x0014
+
+/*default VLAN tag for Host Port*/
+#define HOST_PORT_DF_VLAN_OFFSET   0x001C
+
+/*Same as HOST_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT0_DEFAULT_VLAN_OFFSET
HOST_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P1 Port*/
+#define P1_PORT_DF_VLAN_OFFSET 0x0020
+
+/*Same as P1_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT1_DEFAULT_VLAN_OFFSET
P1_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P2 Port*/
+#define P2_PORT_DF_VLAN_OFFSET 0x0024
+
+/*Same as P2_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT2_DEFAULT_VLAN_OFFSET
P2_PORT_DF_VLAN_OFFSET
+
+/*VLAN-FID Table offset. 4096 VIDs. 2B per VID = 8KB = 0x2000*/
+#define VLAN_STATIC_REG_TABLE_OFFSET   0x0100
+
+/*VLAN-FID Table offset for EMAC*/
+#define EMAC_ICSSG_SWITCH_DEFAULT_VLAN_TABLE_OFFSET
VLAN_STATIC_REG_TABLE_OFFSET
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_HI  0x2104
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_LO  0x2F6C
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_HI  0x3DD4
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_LO  0x4C3C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_HI  0x5AA4
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_LO  0x5F0C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_HI  0x6374
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_LO  0x67DC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD0 0x7AAC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD1 0x7EAC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_CYCLECOUNT_OFFSET   0x83EC
+
+/*IEP count hi roll over count*/
+#define TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET0x83F4
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET   0x83F8
+
+/*Set clock descriptor*/
+#define TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET0x83FC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET 0x843C
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_COUNT_OFFSET  0x8440
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET 0x8444
+
+/*Control variable to generate SYNC1*/
+#define TIMESYNC_FW_WC_ISOM_PIN_SIGNAL_EN_OFFSET   0x844C
+
+/*SystemTime Sync0 periodicity*/
+#define TIMESYNC_FW_ST_SYNCOUT_PERIOD_OFFSET   0x8450
+
+/*pktTxDelay for P1 = link speed dependent p1 mac delay + p1 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P1_OFFSET0x8454
+
+/*pktTxDelay for P2 = link speed dependent p2 mac delay + p2 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P2_OFFSET0x8458
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_PNFW_OFFSET0x845C
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_TIMESYNCFW_OFFSET  0x8460
+
+/*New list is copied at this time*/
+#define TAS_CONFIG_CHANGE_TIME 0x000C
+
+/*config change error counter*/
+#define TAS_CONFIG_CHANGE_ERROR_COUNTER0x0014
+
+/*TAS List update pending flag*/
+#define TAS_CONFIG_PENDING 0x0018
+
+/*TAS list update trigger flag*/
+#define TAS_CONFIG_CHANGE  0x0019
+
+/*List length for new TAS schedule*/
+#define TAS_ADMIN_LIST_LENGTH  0x001A
+
+/*Currently active TAS list index*/
+#define

[RFC PATCH v3 03/15] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-01-24 Thread MD Danish Anwar
Add APIs to set a firmware_name to a rproc and boot the rproc with the
same firmware.

Clients can call rproc_set_firmware() API to set firmware_name for a rproc
whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
a buffer by calling request_firmware_into_buf(). rproc_boot() will then
load the firmware file to the remote processor and start the remote
processor.

Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
Kconfig so that we can call request_firmware_into_buf() from remoteproc
driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/remoteproc/Kconfig|  1 +
 drivers/remoteproc/rproc-uclass.c | 85 +++
 include/remoteproc.h  | 35 +
 3 files changed, 121 insertions(+)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 781de530af..0fdf1b38ea 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -10,6 +10,7 @@ menu "Remote Processor drivers"
 # All users should depend on DM
 config REMOTEPROC
bool
+   select FS_LOADER
depends on DM
 
 # Please keep the configuration alphabetically sorted.
diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 28b362c887..76db4157f7 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -961,3 +962,87 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev, struct rproc *cfg)
 
return 1;
 }
+
+int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   int len;
+   char *p;
+
+   if (!rproc_dev || !fw_name)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+
+   len = strcspn(fw_name, "\n");
+   if (!len) {
+   debug("can't provide empty string for firmware name\n");
+   return -EINVAL;
+   }
+
+   p = strndup(fw_name, len);
+   if (!p)
+   return -ENOMEM;
+
+   uc_pdata->fw_name = p;
+
+   return 0;
+}
+
+int rproc_boot(struct udevice *rproc_dev, size_t fw_size)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   struct udevice *fs_loader;
+   void *addr = malloc(fw_size);
+   int core_id, ret = 0;
+   char *firmware;
+   ulong rproc_addr;
+
+   if (!rproc_dev)
+   return -EINVAL;
+
+   if (!addr)
+   return -ENOMEM;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   core_id = dev_seq(rproc_dev);
+   firmware = uc_pdata->fw_name;
+
+   if (!firmware) {
+   debug("No firmware set for rproc core %d\n", core_id);
+   return -EINVAL;
+   }
+
+   /* Initialize all rproc cores */
+   rproc_init();
+
+   /* Loading firmware to a given address */
+   ret = get_fs_loader(_loader);
+   if (ret) {
+   debug("could not get fs loader: %d\n", ret);
+   return ret;
+   }
+
+   ret = request_firmware_into_buf(fs_loader, firmware, addr, fw_size, 0);
+   if (ret < 0) {
+   debug("could not request %s: %d\n", firmware, ret);
+   return ret;
+   }
+
+   rproc_addr = (ulong)addr;
+
+   ret = rproc_load(core_id, rproc_addr, ret);
+   if (ret) {
+   debug("failed to load %s to rproc core %d from addr 0x%08lX err 
%d\n",
+ uc_pdata->fw_name, core_id, rproc_addr, ret);
+   return ret;
+   }
+
+   ret = rproc_start(core_id);
+   if (ret) {
+   debug("failed to start rproc core %d\n", core_id);
+   return ret;
+   }
+
+   return ret;
+}
diff --git a/include/remoteproc.h b/include/remoteproc.h
index a11dc8a9b6..65b0ff7477 100644
--- a/include/remoteproc.h
+++ b/include/remoteproc.h
@@ -402,6 +402,7 @@ enum rproc_mem_type {
  * @name: Platform-specific way of naming the Remote proc
  * @mem_type: one of 'enum rproc_mem_type'
  * @driver_plat_data: driver specific platform data that may be needed.
+ * @fw_name: firmware name
  *
  * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
  * device.
@@ -411,6 +412,7 @@ struct dm_rproc_uclass_pdata {
const char *name;
enum rproc_mem_type mem_type;
void *driver_plat_data;
+   char *fw_name;
 };
 
 /**
@@ -704,6 +706,35 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev,
 struct resource_table *rproc_find_resource_table(struct udevice *dev,
 unsigned int addr,
 int *tablesz);
+/**
+ * rproc_set_firmware() - assign a new firmware
+ * @rproc_dev: device for wich new firmware is being assigned
+ *

[RFC PATCH v3 01/15] dma: ti: k3-udma: Use ring_idx to pair k3 nav rings

2024-01-24 Thread MD Danish Anwar
Use ring_idx to pair rings. ring_idx will be same as tx flow_id for all
non-negative flow_ids. For negative flow_ids, ring_idx will be tchan->id
added with bchan_cnt.

Signed-off-by: MD Danish Anwar 
---
 drivers/dma/ti/k3-udma.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 8a62d63dfe..eea9ec9659 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -876,13 +876,20 @@ static int udma_alloc_tx_resources(struct udma_chan *uc)
 {
struct k3_nav_ring_cfg ring_cfg;
struct udma_dev *ud = uc->ud;
-   int ret;
+   struct udma_tchan *tchan;
+   int ring_idx, ret;
 
ret = udma_get_tchan(uc);
if (ret)
return ret;
 
-   ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, uc->tchan->id, -1,
+   tchan = uc->tchan;
+   if (tchan->tflow_id >= 0)
+   ring_idx = tchan->tflow_id;
+   else
+   ring_idx = ud->bchan_cnt + tchan->id;
+
+   ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, ring_idx, -1,
>tchan->t_ring,
>tchan->tc_ring);
if (ret) {
-- 
2.34.1



[RFC PATCH v3 00/15] Introduce ICSSG Ethernet driver

2024-01-24 Thread MD Danish Anwar
Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
AM654 SR2.0.

The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
support for ICSSG driver in uboot. This series also adds the driver's
dependencies.

The ICSSG2 node is added in device tree overlay so that it remains in
sync with linux kernel.

The series introduces device tree and config changes and AM65x
to enable ICSSG driver. The series also enables SPL_LOAD_FIT_APPLY_OVERLAY
for AM65x in order to load overlay over spl.

This series has been tested on AM65x SR2.0, and the ICSSG interface is
able to ping / dhcp and boot kernel using tftp in uboot.

To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
cores and RPROC cores need to be booted with the firmware. This step is
done inside driver similar to kernel.

The remoteproc driver uses request_fw_into_buf() API from fs-loader driver
to load and start rproc with the required firmwares.

The users need to set env variables fw_storage_interface, fw_dev_part,
fw_ubi_mtdpart, fw_ubi_volume to indicate which storage medium and
partition they want to use to load firmware files from. By default the env
fw_storage_interface=mmc and fw_dev_part=1:2 but users can modify these
envs as per their requirements.

Log while running dhcp at u-boot:

k3-navss-ringacc ringacc@3c00: Ring Accelerator probed rings:818, 
gp-rings[304,100] sci-dev-id:187
k3-navss-ringacc ringacc@3c00: dma-ring-reset-quirk: disabled
prueth icssg2-eth: K3 ICSSG: rflow_id_base: 8, chn_name = rx0
link up on port 0, speed 1000, full duplex
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.4.97 (1037 ms)

This is v3 of the series [1].

Changes from v2 [2] to v3:
*) No functional changes.
*) Rebased the series on latest u-boot/next.
*) Dropped the RFC tag.

Changes from v1 to v2:
*) Modified the driver to load the firmware inside the driver only instead
   of loading the firmware using commands at u-boot prompt. Added patch
   3/16 for this.
*) Rebased the series on the latest u-boot/next.
*) Modified conf-0 configuration in k3-am65x-binman.dtsi as suggested by
   Roger.
*) Dropped patch [3] as the patch is no longer needed.
*) Added patch 2/15 to modify fs-loader driver to use fw_storage_interface
   env instead of storage_interface and keep the env storage_interface as
   fallback as suggested by Roger.
*) Added patch 15/15 to set default values to env fw_storage_interface and
   fw_dev_part.

[1] https://lore.kernel.org/all/20231219103418.3445886-1-danishan...@ti.com/
[2] https://lore.kernel.org/all/20240111070611.342701-1-danishan...@ti.com/
[3] https://lore.kernel.org/all/20231219103418.3445886-16-danishan...@ti.com/

NOTE: All the device tree changes introduced in this patch are already
part of upstream linux kernel.

Thanks and Regards,
MD Danish Anwar

MD Danish Anwar (15):
  dma: ti: k3-udma: Use ring_idx to pair k3 nav rings
  misc: fs-loader: Use fw_storage_interface instead of storage_interface
  remoteproc: uclass: Add methods to load firmware to rproc and boot
rproc
  net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.
  net: ti: icssg: Add Firmware config and classification APIs.
  net: ti: icssg: Add icssg queues APIs and macros
  net: ti: icssg: Add ICSSG ethernet driver
  net: ti: icssg: Add support sending FDB command to update rx_flow_id
  net: ti: icssg: Enforce pinctrl state on the MDIO child node
  arm: dts: k3-am654-base-board: Add ICSSG2 Ethernet support
  arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration
  configs: am65x_evm_a53: Enable ICSSG Driver
  configs: am65x_evm_a53: add SPL_LOAD_FIT_APPLY_OVERLAY
  board: ti: am65x: Add check for k3-am654-icssg2 in
board_fit_config_match()
  board: ti: am65x: Set fw_storage_interface and fw_dev_part ENVs

 arch/arm/dts/Makefile |   3 +-
 arch/arm/dts/k3-am654-icssg2.dtso | 145 
 arch/arm/dts/k3-am65x-binman.dtsi |  65 +-
 board/ti/am65x/am65x.env  |   4 +
 board/ti/am65x/evm.c  |  11 +-
 configs/am65x_evm_a53_defconfig   |   2 +
 .../driver-model/fs_firmware_loader.rst   |   5 +-
 drivers/dma/ti/k3-udma.c  |  11 +-
 drivers/misc/fs_loader.c  |   5 +-
 drivers/net/ti/Kconfig|   9 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icss_mii_rt.h  | 192 +
 drivers/net/ti/icssg_classifier.c | 376 +
 drivers/net/ti/icssg_config.c | 463 +++
 drivers/net/ti/icssg_config.h | 195 +
 drivers/net/ti/icssg_prueth.c | 762 ++
 drivers/net/ti/icssg_prueth.h |  92 +++
 drivers/net/ti/icssg_queues.c |  51 ++
 drivers/net/ti/icssg_switch_map.h | 209 +
 drivers/remoteproc/Kconfig

[RFC PATCH v3 02/15] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-01-24 Thread MD Danish Anwar
The fs-loader driver reads env storage_interface and uses it to load
firmware file into memory using the medium set by env. Update the driver
to use env fw_storage_interface as this variable is only used to load
firmwares. The env storage_interface will act as fallback so that the
existing implementations do not break.

Also update the FS Loader documentation accordingly.

Signed-off-by: MD Danish Anwar 
---
 doc/develop/driver-model/fs_firmware_loader.rst | 5 -
 drivers/misc/fs_loader.c| 5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/develop/driver-model/fs_firmware_loader.rst 
b/doc/develop/driver-model/fs_firmware_loader.rst
index 149b8b436e..410cc1442d 100644
--- a/doc/develop/driver-model/fs_firmware_loader.rst
+++ b/doc/develop/driver-model/fs_firmware_loader.rst
@@ -98,8 +98,11 @@ through the U-Boot environment variable during run time.
 
 For examples:
 
+fw_storage_interface:
+  Firmware storage interface, it can be "mmc", "usb", "sata" or "ubi".
 storage_interface:
-  Storage interface, it can be "mmc", "usb", "sata" or "ubi".
+  Storage interface, it can be "mmc", "usb", "sata" or "ubi". This acts
+  as a fallback if fw_storage_interface is not set.
 fw_dev_part:
   Block device number and its partition, it can be "0:1".
 fw_ubi_mtdpart:
diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
index 1ffc199ba1..3798dab5b6 100644
--- a/drivers/misc/fs_loader.c
+++ b/drivers/misc/fs_loader.c
@@ -153,7 +153,10 @@ static int fw_get_filesystem_firmware(struct udevice *dev)
char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume;
int ret;
 
-   storage_interface = env_get("storage_interface");
+   storage_interface = env_get("fw_storage_interface");
+   if (!storage_interface)
+   storage_interface = env_get("storage_interface");
+
dev_part = env_get("fw_dev_part");
ubi_mtdpart = env_get("fw_ubi_mtdpart");
ubi_volume = env_get("fw_ubi_volume");
-- 
2.34.1



[RFC PATCH v2 15/15] board: ti: am65x: Set fw_storage_interface and fw_dev_part ENVs

2024-01-11 Thread MD Danish Anwar
When ICSSG driver is enabled (CONFIG_TI_ICSSG_PRUETH=y) set
fw_storage_interface and fw_dev_part env variables.

These variables need be set appropriately in order to load differnet
ICSSG firmwares needed for ICSSG driver. By default the storage
interface is mmc and the partition is 1:2. User can modify this based on
their needs.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am65x/am65x.env | 4 
 1 file changed, 4 insertions(+)

diff --git a/board/ti/am65x/am65x.env b/board/ti/am65x/am65x.env
index 286b9c300c..5d6b98b87c 100644
--- a/board/ti/am65x/am65x.env
+++ b/board/ti/am65x/am65x.env
@@ -30,3 +30,7 @@ get_fdt_ubi=ubifsload ${fdtaddr} ${bootdir}/${name_fdt}
 args_ubi=setenv bootargs console=${console} ${optargs}
 rootfstype=ubifs root=ubi0:rootfs rw ubi.mtd=ospi.rootfs
 
+#if CONFIG_TI_ICSSG_PRUETH
+fw_storage_interface=mmc
+fw_dev_part=1:2
+#endif
-- 
2.34.1



[RFC PATCH v2 14/15] board: ti: am65x: Add check for k3-am654-icssg2 in board_fit_config_match()

2024-01-11 Thread MD Danish Anwar
When CONFIG_TI_ICSSG_PRUETH is enabled, add config name check for the
icssg2 overlay in board_fit_config_match() API.

Signed-off-by: MD Danish Anwar 
---
 board/ti/am65x/evm.c | 11 +++
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/board/ti/am65x/evm.c b/board/ti/am65x/evm.c
index df209021c1..0b661f0084 100644
--- a/board/ti/am65x/evm.c
+++ b/board/ti/am65x/evm.c
@@ -90,10 +90,13 @@ int dram_init_banksize(void)
 #ifdef CONFIG_SPL_LOAD_FIT
 int board_fit_config_name_match(const char *name)
 {
-#ifdef CONFIG_TARGET_AM654_A53_EVM
-   if (!strcmp(name, "k3-am654-base-board"))
-   return 0;
-#endif
+   if (IS_ENABLED(CONFIG_TI_ICSSG_PRUETH)) {
+   if (!strcmp(name, "k3-am654-icssg2"))
+   return 0;
+   } else {
+   if (!strcmp(name, "k3-am654-base-board"))
+   return 0;
+   }
 
return -1;
 }
-- 
2.34.1



[RFC PATCH v2 11/15] arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration

2024-01-11 Thread MD Danish Anwar
Add ICSSG2 overlay and configuration to tispl and u-boot images.

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/k3-am65x-binman.dtsi | 65 +--
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
b/arch/arm/dts/k3-am65x-binman.dtsi
index 8cc24da1f3..d0cd4889cd 100644
--- a/arch/arm/dts/k3-am65x-binman.dtsi
+++ b/arch/arm/dts/k3-am65x-binman.dtsi
@@ -98,6 +98,8 @@
 #define SPL_AM654_EVM_DTB "spl/dts/k3-am654-base-board.dtb"
 #define AM654_EVM_DTB "u-boot.dtb"
 
+#define AM654_EVM_ICSSG2_DTBO "arch/arm/dts/k3-am654-icssg2.dtbo"
+
  {
ti-spl {
insert-template = <_spl_template>;
@@ -124,6 +126,20 @@
filename = SPL_AM654_EVM_DTB;
};
};
+
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = 
<_am65x_evm_icssg2_dtb>;
+   keyfile = "custMpk.pem";
+   };
+   spl_am65x_evm_icssg2_dtb: blob-ext {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   };
};
 
configurations {
@@ -133,7 +149,7 @@
description = "k3-am654-base-board";
firmware = "atf";
loadables = "tee", "dm", "spl";
-   fdt = "fdt-0";
+   fdt = "fdt-0", "fdt-1";
};
};
};
@@ -168,6 +184,24 @@
};
};
 
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   ti-secure {
+   content = 
<_evm_icssg2_dtb>;
+   keyfile = "custMpk.pem";
+
+   };
+   am65x_evm_icssg2_dtb: blob-ext {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   hash {
+   algo = "crc32";
+   };
+   };
+
};
 
configurations {
@@ -177,7 +211,7 @@
description = "k3-am654-base-board";
firmware = "uboot";
loadables = "uboot";
-   fdt = "fdt-0";
+   fdt = "fdt-0", "fdt-1";
};
};
};
@@ -205,6 +239,16 @@
filename = SPL_AM654_EVM_DTB;
};
};
+
+   fdt-1 {
+   description = "k3-am654-icssg2 overlay";
+   type = "flat_dt";
+   arch = "arm";
+   compression = "none";
+   blob {
+   filename = 
AM654_EVM_ICSSG2_DTBO;
+   };
+   };
};
 
configurations {
@@ -214,7 +258,7 @@
description = "k3-am654-base-board";
firmware = "atf&quo

[RFC PATCH v2 10/15] arm: dts: k3-am654-base-board: Add ICSSG2 Ethernet support

2024-01-11 Thread MD Danish Anwar
ICSSG2 provides dual Gigabit Ethernet support.
Add ICSSG2 ethernet node to an overlay k3-am654-icssg2.dtso

Signed-off-by: MD Danish Anwar 
---
 arch/arm/dts/Makefile |   3 +-
 arch/arm/dts/k3-am654-icssg2.dtso | 145 ++
 2 files changed, 147 insertions(+), 1 deletion(-)
 create mode 100644 arch/arm/dts/k3-am654-icssg2.dtso

diff --git a/arch/arm/dts/Makefile b/arch/arm/dts/Makefile
index e9e58c5478..2bc53fba89 100644
--- a/arch/arm/dts/Makefile
+++ b/arch/arm/dts/Makefile
@@ -1396,7 +1396,8 @@ dtb-$(CONFIG_SOC_K3_AM654) += \
k3-am6548-iot2050-advanced-pg2.dtb \
k3-am6548-iot2050-advanced-m2.dtb \
k3-am6548-iot2050-advanced-m2-bkey-usb3-overlay.dtbo \
-   k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dtbo
+   k3-am6548-iot2050-advanced-m2-bkey-ekey-pcie-overlay.dtbo \
+   k3-am654-icssg2.dtbo
 dtb-$(CONFIG_SOC_K3_J721E) += k3-j721e-common-proc-board.dtb \
  k3-j721e-r5-common-proc-board.dtb \
  k3-j7200-common-proc-board.dtb \
diff --git a/arch/arm/dts/k3-am654-icssg2.dtso 
b/arch/arm/dts/k3-am654-icssg2.dtso
new file mode 100644
index 00..faefa2febc
--- /dev/null
+++ b/arch/arm/dts/k3-am654-icssg2.dtso
@@ -0,0 +1,145 @@
+// SPDX-License-Identifier: GPL-2.0
+/**
+ * DT overlay for enabling ICSSG2 on AM654 EVM
+ *
+ * Copyright (C) 2018-2023 Texas Instruments Incorporated - https://www.ti.com/
+ */
+
+/dts-v1/;
+/plugin/;
+
+#include 
+#include "k3-pinctrl.h"
+
+&{/} {
+   aliases {
+   ethernet1 = "/icssg2-eth/ethernet-ports/port@0";
+   ethernet2 = "/icssg2-eth/ethernet-ports/port@1";
+   };
+
+   /* Ethernet node on PRU-ICSSG2 */
+   icssg2_eth: icssg2-eth {
+   compatible = "ti,am654-icssg-prueth";
+   pinctrl-names = "default";
+   pinctrl-0 = <_rgmii_pins_default>;
+   sram = <_ram>;
+   ti,prus = <_0>, <_0>, <_pru2_0>,
+   <_1>, <_1>, <_pru2_1>;
+   firmware-name = "ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
+   "ti-pruss/am65x-sr2-txpru1-prueth-fw.elf";
+
+   ti,pruss-gp-mux-sel = <2>,  /* MII mode */
+ <2>,
+ <2>,
+ <2>,  /* MII mode */
+ <2>,
+ <2>;
+
+   ti,mii-g-rt = <_mii_g_rt>;
+   ti,mii-rt = <_mii_rt>;
+   ti,iep = <_iep0>, <_iep1>;
+
+   interrupt-parent = <_intc>;
+   interrupts = <24 0 2>, <25 1 3>;
+   interrupt-names = "tx_ts0", "tx_ts1";
+
+   dmas = <_udmap 0xc300>, /* egress slice 0 */
+  <_udmap 0xc301>, /* egress slice 0 */
+  <_udmap 0xc302>, /* egress slice 0 */
+  <_udmap 0xc303>, /* egress slice 0 */
+  <_udmap 0xc304>, /* egress slice 1 */
+  <_udmap 0xc305>, /* egress slice 1 */
+  <_udmap 0xc306>, /* egress slice 1 */
+  <_udmap 0xc307>, /* egress slice 1 */
+  <_udmap 0x4300>, /* ingress slice 0 */
+  <_udmap 0x4301>; /* ingress slice 1 */
+
+   dma-names = "tx0-0", "tx0-1", "tx0-2", "tx0-3",
+   "tx1-0", "tx1-1", "tx1-2", "tx1-3",
+   "rx0", "rx1";
+   ethernet-ports {
+   #address-cells = <1>;
+   #size-cells = <0>;
+   icssg2_emac0: port@0 {
+   reg = <0>;
+   phy-handle = <_phy0>;
+   phy-mode = "rgmii-id";
+   ti,syscon-rgmii-delay = <_conf 0x4120>;
+   /* Filled in by bootloader */
+   local-mac-address = [00 00 00 00 00 00];
+   };
+   icssg2_emac1: port@1 {
+   reg = <1>;
+   

[RFC PATCH v2 13/15] configs: am65x_evm_a53: add SPL_LOAD_FIT_APPLY_OVERLAY

2024-01-11 Thread MD Danish Anwar
We want SPL to apply DTB overlays (e.g. ICSSG2 overlay) so enable
SPL_LOAD_FIT_APPLY_OVERLAY.

Signed-off-by: MD Danish Anwar 
---
 configs/am65x_evm_a53_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index aeea24d773..329973de68 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -69,6 +69,7 @@ CONFIG_CMD_I2C=y
 CONFIG_CMD_MMC=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_REMOTEPROC=y
+CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY=y
 CONFIG_CMD_USB=y
 CONFIG_CMD_TIME=y
 CONFIG_MTDIDS_DEFAULT="nor0=4704.spi.0"
-- 
2.34.1



[RFC PATCH v2 12/15] configs: am65x_evm_a53: Enable ICSSG Driver

2024-01-11 Thread MD Danish Anwar
Enable ICSSG driver in am65x_evm_a53_defconfig

Signed-off-by: MD Danish Anwar 
---
 configs/am65x_evm_a53_defconfig | 1 +
 1 file changed, 1 insertion(+)

diff --git a/configs/am65x_evm_a53_defconfig b/configs/am65x_evm_a53_defconfig
index 529bda283d..aeea24d773 100644
--- a/configs/am65x_evm_a53_defconfig
+++ b/configs/am65x_evm_a53_defconfig
@@ -129,6 +129,7 @@ CONFIG_PHY_FIXED=y
 CONFIG_E1000=y
 CONFIG_CMD_E1000=y
 CONFIG_TI_AM65_CPSW_NUSS=y
+CONFIG_TI_ICSSG_PRUETH=y
 CONFIG_PCI_KEYSTONE=y
 CONFIG_PHY=y
 CONFIG_SPL_PHY=y
-- 
2.34.1



[RFC PATCH v2 08/15] net: ti: icssg: Add support sending FDB command to update rx_flow_id

2024-01-11 Thread MD Danish Anwar
ICSSG firmware supports FDB commands. Add support to send FDB commands
from driver. Once rx_flow_id is obtained from dma, let firmware know that
we are using this rx_flow_id by sending a FDB command.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_config.c | 66 +++
 drivers/net/ti/icssg_config.h | 18 ++
 drivers/net/ti/icssg_prueth.c |  6 
 drivers/net/ti/icssg_prueth.h |  6 
 4 files changed, 96 insertions(+)

diff --git a/drivers/net/ti/icssg_config.c b/drivers/net/ti/icssg_config.c
index 0dc2c0fa3a..630698add4 100644
--- a/drivers/net/ti/icssg_config.c
+++ b/drivers/net/ti/icssg_config.c
@@ -9,6 +9,7 @@
 #include "icssg_switch_map.h"
 #include "icss_mii_rt.h"
 #include 
+#include 
 
 /* TX IPG Values to be set for 100M and 1G link speeds.  These values are
  * in ocp_clk cycles. So need change if ocp_clk is changed for a specific
@@ -395,3 +396,68 @@ int emac_set_port_state(struct prueth *prueth,
 
return ret;
 }
+
+int icssg_send_fdb_msg(struct prueth *prueth, struct mgmt_cmd *cmd,
+  struct mgmt_cmd_rsp *rsp)
+{
+   int slice = prueth->slice;
+   int ret, addr;
+
+   addr = icssg_queue_pop(prueth, slice == 0 ?
+  ICSSG_CMD_POP_SLICE0 : ICSSG_CMD_POP_SLICE1);
+   if (addr < 0)
+   return addr;
+
+   /* First 4 bytes have FW owned buffer linking info which should
+* not be touched
+*/
+   memcpy_toio((void __iomem *)prueth->shram.pa + addr + 4, cmd, 
sizeof(*cmd));
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_CMD_PUSH_SLICE0 : ICSSG_CMD_PUSH_SLICE1, addr);
+   ret = read_poll_timeout(icssg_queue_pop, addr, addr >= 0,
+   2000, 2000, prueth, slice == 0 ?
+   ICSSG_RSP_POP_SLICE0 : ICSSG_RSP_POP_SLICE1);
+
+   if (ret) {
+   dev_err(prueth->dev, "Timedout sending HWQ message\n");
+   return ret;
+   }
+
+   memcpy_fromio(rsp, (void __iomem *)prueth->shram.pa + addr, 
sizeof(*rsp));
+   /* Return buffer back for to pool */
+   icssg_queue_push(prueth, slice == 0 ?
+ICSSG_RSP_PUSH_SLICE0 : ICSSG_RSP_PUSH_SLICE1, addr);
+
+   return 0;
+}
+
+int emac_fdb_flow_id_updated(struct prueth *prueth)
+{
+   struct mgmt_cmd_rsp fdb_cmd_rsp = { 0 };
+   int slice = prueth->slice;
+   struct mgmt_cmd fdb_cmd = { 0 };
+   int ret = 0;
+
+   fdb_cmd.header = ICSSG_FW_MGMT_CMD_HEADER;
+   fdb_cmd.type   = ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW;
+   fdb_cmd.seqnum = ++(prueth->icssg_hwcmdseq);
+   fdb_cmd.param  = 0;
+
+   fdb_cmd.param |= (slice << 4);
+   fdb_cmd.cmd_args[0] = 0;
+
+   ret = icssg_send_fdb_msg(prueth, _cmd, _cmd_rsp);
+   if (ret)
+   return ret;
+
+   if (fdb_cmd.seqnum != fdb_cmd_rsp.seqnum) {
+   dev_err(prueth->dev, "seqnum doesn't match, cmd.seqnum %d != 
rsp.seqnum %d\n",
+   fdb_cmd.seqnum, fdb_cmd_rsp.seqnum);
+   return -EINVAL;
+   }
+
+   if (fdb_cmd_rsp.status == 1)
+   return 0;
+
+   return -EINVAL;
+}
diff --git a/drivers/net/ti/icssg_config.h b/drivers/net/ti/icssg_config.h
index fc6eae0426..156127bd3d 100644
--- a/drivers/net/ti/icssg_config.h
+++ b/drivers/net/ti/icssg_config.h
@@ -80,6 +80,7 @@ struct icssg_rxq_ctx {
 #define ICSSG_FW_MGMT_FDB_CMD_TYPE 0x03
 #define ICSSG_FW_MGMT_CMD_TYPE 0x04
 #define ICSSG_FW_MGMT_PKT  0x8000
+#define ICSSG_FW_MGMT_FDB_CMD_TYPE_RX_FLOW 0x05
 
 struct icssg_r30_cmd {
u32 cmd[4];
@@ -156,6 +157,23 @@ struct icssg_setclock_desc {
u32 CMP0_new;
 } __packed;
 
+struct mgmt_cmd {
+   u8 param;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
+struct mgmt_cmd_rsp {
+   u32 reserved;
+   u8 status;
+   u8 seqnum;
+   u8 type;
+   u8 header;
+   u32 cmd_args[3];
+} __packed;
+
 #define ICSSG_CMD_POP_SLICE0   56
 #define ICSSG_CMD_POP_SLICE1   60
 
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
index cd6ff1a7fe..50af9a2bc6 100644
--- a/drivers/net/ti/icssg_prueth.c
+++ b/drivers/net/ti/icssg_prueth.c
@@ -351,6 +351,12 @@ static int prueth_start(struct udevice *dev)
dev_info(dev, "K3 ICSSG: rflow_id_base: %u, chn_name = %s\n",
 dma_rx_cfg_data->flow_id_base, chn_name);
 
+   ret = emac_fdb_flow_id_updated(priv);
+   if (ret) {
+   dev_err(dev, "Failed to update Rx Flow ID %d", ret);
+   goto phy_fail;
+   }
+
ret = phy_startup(priv->phydev);
if (ret) {
dev_err(dev, "phy_startup failed\n");
diff --git a/drivers/net/ti/icssg_prueth.h b/drivers/net/ti/icssg_prueth.

[RFC PATCH v2 05/15] net: ti: icssg: Add Firmware config and classification APIs.

2024-01-11 Thread MD Danish Anwar
Add icssg_config.h / .c and icssg_classifier.c files. These are firmware
configuration and classification related files. Add MII helper APIs and
MACROs. These APIs and MACROs will be later used by ICSSG Ethernet driver.
Also introduce icssg_prueth.h which has definition of prueth related
structures.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icss_mii_rt.h  | 192 +++
 drivers/net/ti/icssg_classifier.c | 376 
 drivers/net/ti/icssg_config.c | 397 ++
 drivers/net/ti/icssg_config.h | 177 +
 drivers/net/ti/icssg_prueth.h |  78 ++
 5 files changed, 1220 insertions(+)
 create mode 100644 drivers/net/ti/icss_mii_rt.h
 create mode 100644 drivers/net/ti/icssg_classifier.c
 create mode 100644 drivers/net/ti/icssg_config.c
 create mode 100644 drivers/net/ti/icssg_config.h
 create mode 100644 drivers/net/ti/icssg_prueth.h

diff --git a/drivers/net/ti/icss_mii_rt.h b/drivers/net/ti/icss_mii_rt.h
new file mode 100644
index 00..6b2449e736
--- /dev/null
+++ b/drivers/net/ti/icss_mii_rt.h
@@ -0,0 +1,192 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+/* PRU-ICSS MII_RT register definitions
+ *
+ * Copyright (C) 2015-2020 Texas Instruments Incorporated - http://www.ti.com
+ */
+
+#ifndef __NET_PRUSS_MII_RT_H__
+#define __NET_PRUSS_MII_RT_H__
+
+#include 
+
+/* PRUSS_MII_RT Registers */
+#define PRUSS_MII_RT_RXCFG00x0
+#define PRUSS_MII_RT_RXCFG10x4
+#define PRUSS_MII_RT_TXCFG00x10
+#define PRUSS_MII_RT_TXCFG10x14
+#define PRUSS_MII_RT_TX_CRC0   0x20
+#define PRUSS_MII_RT_TX_CRC1   0x24
+#define PRUSS_MII_RT_TX_IPG0   0x30
+#define PRUSS_MII_RT_TX_IPG1   0x34
+#define PRUSS_MII_RT_PRS0  0x38
+#define PRUSS_MII_RT_PRS1  0x3c
+#define PRUSS_MII_RT_RX_FRMS0  0x40
+#define PRUSS_MII_RT_RX_FRMS1  0x44
+#define PRUSS_MII_RT_RX_PCNT0  0x48
+#define PRUSS_MII_RT_RX_PCNT1  0x4c
+#define PRUSS_MII_RT_RX_ERR0   0x50
+#define PRUSS_MII_RT_RX_ERR1   0x54
+
+/* PRUSS_MII_RT_RXCFG0/1 bits */
+#define PRUSS_MII_RT_RXCFG_RX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DISBIT(1)
+#define PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE BIT(2)
+#define PRUSS_MII_RT_RXCFG_RX_MUX_SEL  BIT(3)
+#define PRUSS_MII_RT_RXCFG_RX_L2_ENBIT(4)
+#define PRUSS_MII_RT_RXCFG_RX_BYTE_SWAPBIT(5)
+#define PRUSS_MII_RT_RXCFG_RX_AUTO_FWD_PRE BIT(6)
+#define PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS  BIT(9)
+
+/* PRUSS_MII_RT_TXCFG0/1 bits */
+#define PRUSS_MII_RT_TXCFG_TX_ENABLE   BIT(0)
+#define PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLEBIT(1)
+#define PRUSS_MII_RT_TXCFG_TX_EN_MODE  BIT(2)
+#define PRUSS_MII_RT_TXCFG_TX_BYTE_SWAPBIT(3)
+#define PRUSS_MII_RT_TXCFG_TX_MUX_SEL  BIT(8)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_SEQUENCEBIT(9)
+#define PRUSS_MII_RT_TXCFG_PRE_TX_AUTO_ESC_ERR BIT(10)
+#define PRUSS_MII_RT_TXCFG_TX_32_MODE_EN   BIT(11)
+#define PRUSS_MII_RT_TXCFG_TX_IPG_WIRE_CLK_EN  BIT(12) /* SR2.0 onwards */
+
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT16
+#define PRUSS_MII_RT_TXCFG_TX_START_DELAY_MASK GENMASK(25, 16)
+
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT  28
+#define PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK   GENMASK(30, 28)
+
+/* PRUSS_MII_RT_TX_IPG0/1 bits */
+#define PRUSS_MII_RT_TX_IPG_IPG_SHIFT  0
+#define PRUSS_MII_RT_TX_IPG_IPG_MASK   GENMASK(9, 0)
+
+/* PRUSS_MII_RT_PRS0/1 bits */
+#define PRUSS_MII_RT_PRS_COL   BIT(0)
+#define PRUSS_MII_RT_PRS_CRS   BIT(1)
+
+/* PRUSS_MII_RT_RX_FRMS0/1 bits */
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT 0
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK  GENMASK(15, 0)
+
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT 16
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK  GENMASK(31, 16)
+
+/* Min/Max in MII_RT_RX_FRMS */
+/* For EMAC and Switch */
+#define PRUSS_MII_RT_RX_FRMS_MAX   (VLAN_ETH_FRAME_LEN + ETH_FCS_LEN)
+#define PRUSS_MII_RT_RX_FRMS_MIN_FRM   (64)
+
+/* for HSR and PRP */
+#define PRUSS_MII_RT_RX_FRMS_MAX_FRM_LRE   (PRUSS_MII_RT_RX_FRMS_MAX + \
+ICSS_LRE_TAG_RCT_SIZE)
+/* PRUSS_MII_RT_RX_PCNT0/1 bits */
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_SHIFT0
+#define PRUSS_MII_RT_RX_PCNT_MIN_PCNT_MASK GENMASK(3, 0)
+
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_SHIFT4
+#define PRUSS_MII_RT_RX_PCNT_MAX_PCNT_MASK GENMASK(7, 4)
+
+/* PRUSS_MII_RT_RX_ERR0/1 bits */
+#define PRUSS_MII_RT_RX_ERR_MIN_PCNT_ERR   BIT(0)
+#define PRUSS_MII_RT_RX_ERR_MAX_PCNT_ERR   BIT(1)
+#define PRUSS_MII_RT_RX_ERR_MIN_FRM_ERRBIT(2)
+#define PRUSS_MII_RT_RX_ERR_MAX_FRM_ERRBIT(3)
+
+#define ICSSG_CFG_OFFSET   0
+#define RGMII_CFG_OFFSET   4
+
+/* Constant to choose between MII0 and MII1 */
+#define ICSS_MII0  0
+#define ICSS_MII1

[RFC PATCH v2 09/15] net: ti: icssg: Enforce pinctrl state on the MDIO child node

2024-01-11 Thread MD Danish Anwar
The binding represents the MDIO controller as a child device tree
node of the MAC device tree node.

The U-Boot driver mostly ignores that child device tree node and just
hardcodes the resources it uses to support both the MAC and MDIO in a
single driver.

However, some resources like pinctrl muxing states are thus ignored.
This has been a problem with some device trees that will put some
pinctrl states on the MDIO device tree node.

Let's rework the driver a bit to create a dummy MDIO driver that we will
then get during our initialization to force the core to select the right
muxing.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/Kconfig|  1 +
 drivers/net/ti/icssg_prueth.c | 59 +++
 2 files changed, 60 insertions(+)

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index 9fead2c7ce..6935b70e12 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -53,6 +53,7 @@ config TI_AM65_CPSW_NUSS
 config TI_ICSSG_PRUETH
bool "TI Gigabit PRU Ethernet driver"
depends on ARCH_K3
+   imply DM_MDIO
select PHYLIB
help
  Support Gigabit Ethernet ports over the ICSSG PRU Subsystem
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
index 50af9a2bc6..225928e477 100644
--- a/drivers/net/ti/icssg_prueth.c
+++ b/drivers/net/ti/icssg_prueth.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -103,9 +104,56 @@ static int icssg_phy_init(struct udevice *dev)
return ret;
 }
 
+static ofnode prueth_find_mdio(ofnode parent)
+{
+   ofnode node;
+
+   ofnode_for_each_subnode(node, parent)
+   if (ofnode_device_is_compatible(node, "ti,davinci_mdio"))
+   return node;
+
+   return ofnode_null();
+}
+
+static int prueth_mdio_setup(struct udevice *dev)
+{
+   struct prueth *priv = dev_get_priv(dev);
+   struct udevice *mdio_dev;
+   ofnode mdio;
+   int ret;
+
+   mdio = prueth_find_mdio(dev_ofnode(priv->pruss));
+   if (!ofnode_valid(mdio))
+   return 0;
+
+   /*
+* The MDIO controller is represented in the DT binding by a
+* subnode of the MAC controller.
+*
+* We don't have a DM driver for the MDIO device yet, and thus any
+* pinctrl setting on its node will be ignored.
+*
+* However, we do need to make sure the pins states tied to the
+* MDIO node are configured properly. Fortunately, the core DM
+* does that for use when we get a device, so we can work around
+* that whole issue by just requesting a dummy MDIO driver to
+* probe, and our pins will get muxed.
+*/
+   ret = uclass_get_device_by_ofnode(UCLASS_MDIO, mdio, _dev);
+   if (ret)
+   return ret;
+
+   return 0;
+}
+
 static int icssg_mdio_init(struct udevice *dev)
 {
struct prueth *prueth = dev_get_priv(dev);
+   int ret;
+
+   ret = prueth_mdio_setup(dev);
+   if (ret)
+   return ret;
 
prueth->bus = cpsw_mdio_init(dev->name, prueth->mdio_base,
 prueth->mdio_freq,
@@ -701,3 +749,14 @@ U_BOOT_DRIVER(prueth) = {
.plat_auto = sizeof(struct eth_pdata),
.flags = DM_FLAG_ALLOC_PRIV_DMA,
 };
+
+static const struct udevice_id prueth_mdio_ids[] = {
+   { .compatible = "ti,davinci_mdio" },
+   { }
+};
+
+U_BOOT_DRIVER(prueth_mdio) = {
+   .name   = "prueth_mdio",
+   .id = UCLASS_MDIO,
+   .of_match   = prueth_mdio_ids,
+};
-- 
2.34.1



[RFC PATCH v2 06/15] net: ti: icssg: Add icssg queues APIs and macros

2024-01-11 Thread MD Danish Anwar
Add icssg_queue.c file. This file introduces macros and APIs related to
ICSSG queues. These will be used by ICSSG Ethernet driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_prueth.h |  5 
 drivers/net/ti/icssg_queues.c | 51 +++
 2 files changed, 56 insertions(+)
 create mode 100644 drivers/net/ti/icssg_queues.c

diff --git a/drivers/net/ti/icssg_prueth.h b/drivers/net/ti/icssg_prueth.h
index 26b77dd8f3..f34ab5d6d4 100644
--- a/drivers/net/ti/icssg_prueth.h
+++ b/drivers/net/ti/icssg_prueth.h
@@ -75,4 +75,9 @@ void icssg_config_ipg(struct prueth *prueth, int speed, int 
mii);
 int icssg_config(struct prueth *prueth);
 int emac_set_port_state(struct prueth *prueth, enum icssg_port_state_cmd cmd);
 
+/* Buffer queue helpers */
+int icssg_queue_pop(struct prueth *prueth, u8 queue);
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr);
+u32 icssg_queue_level(struct prueth *prueth, int queue);
+
 #endif /* __NET_TI_ICSSG_PRUETH_H */
diff --git a/drivers/net/ti/icssg_queues.c b/drivers/net/ti/icssg_queues.c
new file mode 100644
index 00..6a95ef5d58
--- /dev/null
+++ b/drivers/net/ti/icssg_queues.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0
+/* ICSSG Buffer queue helpers
+ *
+ * Copyright (C) 2021 Texas Instruments Incorporated - https://www.ti.com
+ */
+
+#include 
+#include 
+#include "icssg_prueth.h"
+
+#define ICSSG_QUEUES_MAX   64
+#define ICSSG_QUEUE_OFFSET 0xd00
+#define ICSSG_QUEUE_PEEK_OFFSET0xe00
+#define ICSSG_QUEUE_CNT_OFFSET 0xe40
+#defineICSSG_QUEUE_RESET_OFFSET0xf40
+
+int icssg_queue_pop(struct prueth *prueth, u8 queue)
+{
+   u32 val, cnt;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+   if (!cnt)
+   return -EINVAL;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, );
+
+   return val;
+}
+
+void icssg_queue_push(struct prueth *prueth, int queue, u16 addr)
+{
+   if (queue >= ICSSG_QUEUES_MAX)
+   return;
+
+   regmap_write(prueth->miig_rt, ICSSG_QUEUE_OFFSET + 4 * queue, addr);
+}
+
+u32 icssg_queue_level(struct prueth *prueth, int queue)
+{
+   u32 reg;
+
+   if (queue >= ICSSG_QUEUES_MAX)
+   return 0;
+
+   regmap_read(prueth->miig_rt, ICSSG_QUEUE_CNT_OFFSET + 4 * queue, );
+
+   return reg;
+}
-- 
2.34.1



[RFC PATCH v2 07/15] net: ti: icssg: Add ICSSG ethernet driver

2024-01-11 Thread MD Danish Anwar
This is the PURSS Ethernet driver for TI AM654 Sr2.0 and laterSoCs with
the ICSSG PRU Sub-system running EMAC firmware. This driver caters to
either of the slices of the icssg subsystem.

One and exactly one of the slices is supported as the u-boot ethernet
supports probing one interface at a time.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/Kconfig|   8 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icssg_prueth.c | 697 ++
 drivers/net/ti/icssg_prueth.h |   3 +
 4 files changed, 709 insertions(+)
 create mode 100644 drivers/net/ti/icssg_prueth.c

diff --git a/drivers/net/ti/Kconfig b/drivers/net/ti/Kconfig
index c75f418628..9fead2c7ce 100644
--- a/drivers/net/ti/Kconfig
+++ b/drivers/net/ti/Kconfig
@@ -49,3 +49,11 @@ config TI_AM65_CPSW_NUSS
help
  This driver supports TI K3 MCU CPSW Nuss Ethernet controller
  in Texas Instruments K3 AM65x SoCs.
+
+config TI_ICSSG_PRUETH
+   bool "TI Gigabit PRU Ethernet driver"
+   depends on ARCH_K3
+   select PHYLIB
+   help
+ Support Gigabit Ethernet ports over the ICSSG PRU Subsystem
+ This subsystem is available starting with the AM65 platform.
diff --git a/drivers/net/ti/Makefile b/drivers/net/ti/Makefile
index 0ce0cf2828..5af760572f 100644
--- a/drivers/net/ti/Makefile
+++ b/drivers/net/ti/Makefile
@@ -6,3 +6,4 @@ obj-$(CONFIG_DRIVER_TI_CPSW) += cpsw.o cpsw-common.o cpsw_mdio.o
 obj-$(CONFIG_DRIVER_TI_EMAC) += davinci_emac.o
 obj-$(CONFIG_DRIVER_TI_KEYSTONE_NET) += keystone_net.o cpsw_mdio.o
 obj-$(CONFIG_TI_AM65_CPSW_NUSS) += am65-cpsw-nuss.o cpsw_mdio.o
+obj-$(CONFIG_TI_ICSSG_PRUETH) += icssg_prueth.o cpsw_mdio.o icssg_classifier.o 
icssg_config.o icssg_queues.o
diff --git a/drivers/net/ti/icssg_prueth.c b/drivers/net/ti/icssg_prueth.c
new file mode 100644
index 00..cd6ff1a7fe
--- /dev/null
+++ b/drivers/net/ti/icssg_prueth.c
@@ -0,0 +1,697 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Texas Instruments K3 AM65 PRU Ethernet Driver
+ *
+ * Copyright (C) 2019-2021, Texas Instruments, Incorporated
+ *
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "cpsw_mdio.h"
+#include "icssg_prueth.h"
+#include "icss_mii_rt.h"
+
+#define ICSS_SLICE0 0
+#define ICSS_SLICE1 1
+
+#ifdef PKTSIZE_ALIGN
+#define UDMA_RX_BUF_SIZE PKTSIZE_ALIGN
+#else
+#define UDMA_RX_BUF_SIZE ALIGN(1522, ARCH_DMA_MINALIGN)
+#endif
+
+#ifdef PKTBUFSRX
+#define UDMA_RX_DESC_NUM PKTBUFSRX
+#else
+#define UDMA_RX_DESC_NUM 4
+#endif
+
+/* Config region lies in shared RAM */
+#define ICSS_CONFIG_OFFSET_SLICE0  0
+#define ICSS_CONFIG_OFFSET_SLICE1  0x8000
+
+/* Firmware flags */
+#define ICSS_SET_RUN_FLAG_VLAN_ENABLE  BIT(0)  /* switch only */
+#define ICSS_SET_RUN_FLAG_FLOOD_UNICASTBIT(1)  /* switch only 
*/
+#define ICSS_SET_RUN_FLAG_PROMISC  BIT(2)  /* MAC only */
+#define ICSS_SET_RUN_FLAG_MULTICAST_PROMISCBIT(3)  /* MAC only */
+
+/* CTRLMMR_ICSSG_RGMII_CTRL register bits */
+#define ICSSG_CTRL_RGMII_ID_MODE   BIT(24)
+
+/* Management packet type */
+#define PRUETH_PKT_TYPE_CMD0x10
+
+/* Number of PRU Cores per Slice */
+#define ICSSG_NUM_PRU_CORES3
+
+static int icssg_phy_init(struct udevice *dev)
+{
+   struct prueth *priv = dev_get_priv(dev);
+   struct phy_device *phydev;
+   u32 supported = PHY_GBIT_FEATURES;
+   int ret;
+
+   phydev = phy_connect(priv->bus,
+priv->phy_addr,
+priv->dev,
+priv->phy_interface);
+
+   if (!phydev) {
+   dev_err(dev, "phy_connect() failed\n");
+   return -ENODEV;
+   }
+
+   /* disable unsupported features */
+   supported &= ~(PHY_10BT_FEATURES |
+   SUPPORTED_100baseT_Half |
+   SUPPORTED_1000baseT_Half |
+   SUPPORTED_Pause |
+   SUPPORTED_Asym_Pause);
+
+   phydev->supported &= supported;
+   phydev->advertising = phydev->supported;
+
+   if (IS_ENABLED(CONFIG_DM_ETH))
+   if (ofnode_valid(priv->phy_node))
+   phydev->node = priv->phy_node;
+
+   priv->phydev = phydev;
+   ret = phy_config(phydev);
+   if (ret < 0)
+   pr_err("phy_config() failed: %d", ret);
+
+   return ret;
+}
+
+static int icssg_mdio_init(struct udevice *dev)
+{
+   struct prueth *prueth = dev_get_priv(dev);
+
+   prueth->bus = cpsw_mdio_init(dev->name, prueth->mdio_base,
+prueth->mdio_freq,
+clk_get_rate(>mdiofck),
+

[RFC PATCH v2 00/15] Introduce ICSSG Ethernet driver

2024-01-11 Thread MD Danish Anwar
Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
AM654 SR2.0.

The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
support for ICSSG driver in uboot. This series also adds the driver's
dependencies.

The ICSSG2 node is added in device tree overlay so that it remains in
sync with linux kernel.

The series introduces device tree and config changes and AM65x
to enable ICSSG driver. The series also enables SPL_LOAD_FIT_APPLY_OVERLAY
for AM65x in order to load overlay over spl.

This series has been tested on AM65x SR2.0, and the ICSSG interface is
able to ping / dhcp and boot kernel using tftp in uboot.

To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
cores and RPROC cores need to be booted with the firmware. This step is
done inside driver similar to kernel.

The remoteproc driver uses request_fw_into_buf() API from fs-loader driver
to load and start rproc with the required firmwares.

The users need to set env variables fw_storage_interface, fw_dev_part,
fw_ubi_mtdpart, fw_ubi_volume to indicate which storage medium and
partition they want to use to load firmware files from. By default the env
fw_storage_interface=mmc and fw_dev_part=1:2 but users can modify these
envs as per their requirements.

Log while running dhcp at u-boot:

k3-navss-ringacc ringacc@3c00: Ring Accelerator probed rings:818, 
gp-rings[304,100] sci-dev-id:187
k3-navss-ringacc ringacc@3c00: dma-ring-reset-quirk: disabled
prueth icssg2-eth: K3 ICSSG: rflow_id_base: 8, chn_name = rx0
link up on port 0, speed 1000, full duplex
BOOTP broadcast 1
BOOTP broadcast 2
BOOTP broadcast 3
DHCP client bound to address 192.168.4.97 (1037 ms)

This is v2 of the series [1]. This addresses comments made on v1.

Changes from v1 to v2:
*) Modified the driver to load the firmware inside the driver only instead
   of loading the firmware using commands at u-boot prompt. Added patch
   3/16 for this.
*) Rebased the series on the latest u-boot/next.
*) Modified conf-0 configuration in k3-am65x-binman.dtsi as suggested by
   Roger.
*) Dropped patch [2] as the patch is no longer needed.
*) Added patch 2/15 to modify fs-loader driver to use fw_storage_interface
   env instead of storage_interface and keep the env storage_interface as
   fallback as suggested by Roger.
*) Added patch 15/15 to set default values to env fw_storage_interface and
   fw_dev_part.

[1] https://lore.kernel.org/all/20231219103418.3445886-1-danishan...@ti.com/
[2] https://lore.kernel.org/all/20231219103418.3445886-16-danishan...@ti.com/

NOTE: All the device tree changes introduced in this patch are already
part of linux kernel.

Thanks and Regards,
MD Danish Anwar

MD Danish Anwar (15):
  dma: ti: k3-udma: Use ring_idx to pair k3 nav rings
  misc: fs-loader: Use fw_storage_interface instead of storage_interface
  remoteproc: uclass: Add methods to load firmware to rproc and boot
rproc
  net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.
  net: ti: icssg: Add Firmware config and classification APIs.
  net: ti: icssg: Add icssg queues APIs and macros
  net: ti: icssg: Add ICSSG ethernet driver
  net: ti: icssg: Add support sending FDB command to update rx_flow_id
  net: ti: icssg: Enforce pinctrl state on the MDIO child node
  arm: dts: k3-am654-base-board: Add ICSSG2 Ethernet support
  arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration
  configs: am65x_evm_a53: Enable ICSSG Driver
  configs: am65x_evm_a53: add SPL_LOAD_FIT_APPLY_OVERLAY
  board: ti: am65x: Add check for k3-am654-icssg2 in
board_fit_config_match()
  board: ti: am65x: Set fw_storage_interface and fw_dev_part ENVs

 arch/arm/dts/Makefile |   3 +-
 arch/arm/dts/k3-am654-icssg2.dtso | 145 
 arch/arm/dts/k3-am65x-binman.dtsi |  65 +-
 board/ti/am65x/am65x.env  |   4 +
 board/ti/am65x/evm.c  |  11 +-
 configs/am65x_evm_a53_defconfig   |   2 +
 .../driver-model/fs_firmware_loader.rst   |   5 +-
 drivers/dma/ti/k3-udma.c  |  11 +-
 drivers/misc/fs_loader.c  |   5 +-
 drivers/net/ti/Kconfig|   9 +
 drivers/net/ti/Makefile   |   1 +
 drivers/net/ti/icss_mii_rt.h  | 192 +
 drivers/net/ti/icssg_classifier.c | 376 +
 drivers/net/ti/icssg_config.c | 463 +++
 drivers/net/ti/icssg_config.h | 195 +
 drivers/net/ti/icssg_prueth.c | 762 ++
 drivers/net/ti/icssg_prueth.h |  92 +++
 drivers/net/ti/icssg_queues.c |  51 ++
 drivers/net/ti/icssg_switch_map.h | 209 +
 drivers/remoteproc/Kconfig|   1 +
 drivers/remoteproc/rproc-uclass.c |  85 ++
 include/remoteproc.h  |  35 +
 22 files changed, 2709 insertions(+), 13 deletions

[RFC PATCH v2 01/15] dma: ti: k3-udma: Use ring_idx to pair k3 nav rings

2024-01-11 Thread MD Danish Anwar
Use ring_idx to pair rings. ring_idx will be same as tx flow_id for all
non-negative flow_ids. For negative flow_ids, ring_idx will be tchan->id
added with bchan_cnt.

Signed-off-by: MD Danish Anwar 
---
 drivers/dma/ti/k3-udma.c | 11 +--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/drivers/dma/ti/k3-udma.c b/drivers/dma/ti/k3-udma.c
index 8a62d63dfe..eea9ec9659 100644
--- a/drivers/dma/ti/k3-udma.c
+++ b/drivers/dma/ti/k3-udma.c
@@ -876,13 +876,20 @@ static int udma_alloc_tx_resources(struct udma_chan *uc)
 {
struct k3_nav_ring_cfg ring_cfg;
struct udma_dev *ud = uc->ud;
-   int ret;
+   struct udma_tchan *tchan;
+   int ring_idx, ret;
 
ret = udma_get_tchan(uc);
if (ret)
return ret;
 
-   ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, uc->tchan->id, -1,
+   tchan = uc->tchan;
+   if (tchan->tflow_id >= 0)
+   ring_idx = tchan->tflow_id;
+   else
+   ring_idx = ud->bchan_cnt + tchan->id;
+
+   ret = k3_nav_ringacc_request_rings_pair(ud->ringacc, ring_idx, -1,
>tchan->t_ring,
>tchan->tc_ring);
if (ret) {
-- 
2.34.1



[RFC PATCH v2 03/15] remoteproc: uclass: Add methods to load firmware to rproc and boot rproc

2024-01-11 Thread MD Danish Anwar
Add APIs to set a firmware_name to a rproc and boot the rproc with the
same firmware.

Clients can call rproc_set_firmware() API to set firmware_name for a rproc
whereas rproc_boot() will load the firmware set by rproc_set_firmware() to
a buffer by calling request_firmware_into_buf(). rproc_boot() will then
load the firmware file to the remote processor and start the remote
processor.

Also include "fs-loader.h" and make remoteproc driver select FS_LOADER in
Kconfig so that we can call request_firmware_into_buf() from remoteproc
driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/remoteproc/Kconfig|  1 +
 drivers/remoteproc/rproc-uclass.c | 85 +++
 include/remoteproc.h  | 35 +
 3 files changed, 121 insertions(+)

diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
index 781de530af..0fdf1b38ea 100644
--- a/drivers/remoteproc/Kconfig
+++ b/drivers/remoteproc/Kconfig
@@ -10,6 +10,7 @@ menu "Remote Processor drivers"
 # All users should depend on DM
 config REMOTEPROC
bool
+   select FS_LOADER
depends on DM
 
 # Please keep the configuration alphabetically sorted.
diff --git a/drivers/remoteproc/rproc-uclass.c 
b/drivers/remoteproc/rproc-uclass.c
index 28b362c887..76db4157f7 100644
--- a/drivers/remoteproc/rproc-uclass.c
+++ b/drivers/remoteproc/rproc-uclass.c
@@ -13,6 +13,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -961,3 +962,87 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev, struct rproc *cfg)
 
return 1;
 }
+
+int rproc_set_firmware(struct udevice *rproc_dev, const char *fw_name)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   int len;
+   char *p;
+
+   if (!rproc_dev || !fw_name)
+   return -EINVAL;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+
+   len = strcspn(fw_name, "\n");
+   if (!len) {
+   debug("can't provide empty string for firmware name\n");
+   return -EINVAL;
+   }
+
+   p = strndup(fw_name, len);
+   if (!p)
+   return -ENOMEM;
+
+   uc_pdata->fw_name = p;
+
+   return 0;
+}
+
+int rproc_boot(struct udevice *rproc_dev, size_t fw_size)
+{
+   struct dm_rproc_uclass_pdata *uc_pdata;
+   struct udevice *fs_loader;
+   void *addr = malloc(fw_size);
+   int core_id, ret = 0;
+   char *firmware;
+   ulong rproc_addr;
+
+   if (!rproc_dev)
+   return -EINVAL;
+
+   if (!addr)
+   return -ENOMEM;
+
+   uc_pdata = dev_get_uclass_plat(rproc_dev);
+   core_id = dev_seq(rproc_dev);
+   firmware = uc_pdata->fw_name;
+
+   if (!firmware) {
+   debug("No firmware set for rproc core %d\n", core_id);
+   return -EINVAL;
+   }
+
+   /* Initialize all rproc cores */
+   rproc_init();
+
+   /* Loading firmware to a given address */
+   ret = get_fs_loader(_loader);
+   if (ret) {
+   debug("could not get fs loader: %d\n", ret);
+   return ret;
+   }
+
+   ret = request_firmware_into_buf(fs_loader, firmware, addr, fw_size, 0);
+   if (ret < 0) {
+   debug("could not request %s: %d\n", firmware, ret);
+   return ret;
+   }
+
+   rproc_addr = (ulong)addr;
+
+   ret = rproc_load(core_id, rproc_addr, ret);
+   if (ret) {
+   debug("failed to load %s to rproc core %d from addr 0x%08lX err 
%d\n",
+ uc_pdata->fw_name, core_id, rproc_addr, ret);
+   return ret;
+   }
+
+   ret = rproc_start(core_id);
+   if (ret) {
+   debug("failed to start rproc core %d\n", core_id);
+   return ret;
+   }
+
+   return ret;
+}
diff --git a/include/remoteproc.h b/include/remoteproc.h
index a11dc8a9b6..65b0ff7477 100644
--- a/include/remoteproc.h
+++ b/include/remoteproc.h
@@ -402,6 +402,7 @@ enum rproc_mem_type {
  * @name: Platform-specific way of naming the Remote proc
  * @mem_type: one of 'enum rproc_mem_type'
  * @driver_plat_data: driver specific platform data that may be needed.
+ * @fw_name: firmware name
  *
  * This can be accessed with dev_get_uclass_plat() for any UCLASS_REMOTEPROC
  * device.
@@ -411,6 +412,7 @@ struct dm_rproc_uclass_pdata {
const char *name;
enum rproc_mem_type mem_type;
void *driver_plat_data;
+   char *fw_name;
 };
 
 /**
@@ -704,6 +706,35 @@ unsigned long rproc_parse_resource_table(struct udevice 
*dev,
 struct resource_table *rproc_find_resource_table(struct udevice *dev,
 unsigned int addr,
 int *tablesz);
+/**
+ * rproc_set_firmware() - assign a new firmware
+ * @rproc_dev: device for wich new firmware is being assigned
+ *

[RFC PATCH v2 04/15] net: ti: icssg: Add Firmware Interface for ICSSG Ethernet driver.

2024-01-11 Thread MD Danish Anwar
Add firmware interface related headers and macros for ICSSG Ethernet
driver. These macros will be later used by the ICSSG ethernet driver.

Signed-off-by: MD Danish Anwar 
---
 drivers/net/ti/icssg_switch_map.h | 209 ++
 1 file changed, 209 insertions(+)
 create mode 100644 drivers/net/ti/icssg_switch_map.h

diff --git a/drivers/net/ti/icssg_switch_map.h 
b/drivers/net/ti/icssg_switch_map.h
new file mode 100644
index 00..ba87a44023
--- /dev/null
+++ b/drivers/net/ti/icssg_switch_map.h
@@ -0,0 +1,209 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Texas Instruments ICSSG Ethernet driver
+ *
+ * Copyright (C) 2020 Texas Instruments Incorporated - https://www.ti.com/
+ *
+ */
+
+#ifndef __NET_TI_ICSSG_SWITCH_MAP_H
+#define __NET_TI_ICSSG_SWITCH_MAP_H
+
+/*Time after which FDB entries are checked for aged out values. Value in 
nanoseconds*/
+#define FDB_AGEING_TIMEOUT_OFFSET  0x0014
+
+/*default VLAN tag for Host Port*/
+#define HOST_PORT_DF_VLAN_OFFSET   0x001C
+
+/*Same as HOST_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT0_DEFAULT_VLAN_OFFSET
HOST_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P1 Port*/
+#define P1_PORT_DF_VLAN_OFFSET 0x0020
+
+/*Same as P1_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT1_DEFAULT_VLAN_OFFSET
P1_PORT_DF_VLAN_OFFSET
+
+/*default VLAN tag for P2 Port*/
+#define P2_PORT_DF_VLAN_OFFSET 0x0024
+
+/*Same as P2_PORT_DF_VLAN_OFFSET*/
+#define EMAC_ICSSG_SWITCH_PORT2_DEFAULT_VLAN_OFFSET
P2_PORT_DF_VLAN_OFFSET
+
+/*VLAN-FID Table offset. 4096 VIDs. 2B per VID = 8KB = 0x2000*/
+#define VLAN_STATIC_REG_TABLE_OFFSET   0x0100
+
+/*VLAN-FID Table offset for EMAC*/
+#define EMAC_ICSSG_SWITCH_DEFAULT_VLAN_TABLE_OFFSET
VLAN_STATIC_REG_TABLE_OFFSET
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_HI  0x2104
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC0_LO  0x2F6C
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_HI  0x3DD4
+
+/*packet descriptor Q reserved memory*/
+#define PORT_DESC1_LO  0x4C3C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_HI  0x5AA4
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC0_LO  0x5F0C
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_HI  0x6374
+
+/*packet descriptor Q reserved memory*/
+#define HOST_DESC1_LO  0x67DC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD0 0x7AAC
+
+/*special packet descriptor Q reserved memory*/
+#define HOST_SPPD1 0x7EAC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_CYCLECOUNT_OFFSET   0x83EC
+
+/*IEP count hi roll over count*/
+#define TIMESYNC_FW_WC_HI_ROLLOVER_COUNT_OFFSET0x83F4
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_COUNT_HI_SW_OFFSET_OFFSET   0x83F8
+
+/*Set clock descriptor*/
+#define TIMESYNC_FW_WC_SETCLOCK_DESC_OFFSET0x83FC
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_FACTOR_OFFSET 0x843C
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_REDUCTION_COUNT_OFFSET  0x8440
+
+/*_Small_Description_*/
+#define TIMESYNC_FW_WC_SYNCOUT_START_TIME_CYCLECOUNT_OFFSET 0x8444
+
+/*Control variable to generate SYNC1*/
+#define TIMESYNC_FW_WC_ISOM_PIN_SIGNAL_EN_OFFSET   0x844C
+
+/*SystemTime Sync0 periodicity*/
+#define TIMESYNC_FW_ST_SYNCOUT_PERIOD_OFFSET   0x8450
+
+/*pktTxDelay for P1 = link speed dependent p1 mac delay + p1 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P1_OFFSET0x8454
+
+/*pktTxDelay for P2 = link speed dependent p2 mac delay + p2 phy delay*/
+#define TIMESYNC_FW_WC_PKTTXDELAY_P2_OFFSET0x8458
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_PNFW_OFFSET0x845C
+
+/*Set clock operation done signal for next task*/
+#define TIMESYNC_FW_SIG_TIMESYNCFW_OFFSET  0x8460
+
+/*New list is copied at this time*/
+#define TAS_CONFIG_CHANGE_TIME 0x000C
+
+/*config change error counter*/
+#define TAS_CONFIG_CHANGE_ERROR_COUNTER0x0014
+
+/*TAS List update pending flag*/
+#define TAS_CONFIG_PENDING 0x0018
+
+/*TAS list update trigger flag*/
+#define TAS_CONFIG_CHANGE  0x0019
+
+/*List length for new TAS schedule*/
+#define TAS_ADMIN_LIST_LENGTH  0x001A
+
+/*Currently active TAS list index*/
+#define

[RFC PATCH v2 02/15] misc: fs-loader: Use fw_storage_interface instead of storage_interface

2024-01-11 Thread MD Danish Anwar
The fs-loader driver reads env storage_interface and uses it to load
firmware file into memory using the medium set by env. Update the driver
to use env fw_storage_interface as this variable is only used to load
firmwares. The env storage_interface will act as fallback so that the
existing implementations do not break.

Also update the FS Loader documentation accordingly.

Signed-off-by: MD Danish Anwar 
---
 doc/develop/driver-model/fs_firmware_loader.rst | 5 -
 drivers/misc/fs_loader.c| 5 -
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/doc/develop/driver-model/fs_firmware_loader.rst 
b/doc/develop/driver-model/fs_firmware_loader.rst
index 149b8b436e..410cc1442d 100644
--- a/doc/develop/driver-model/fs_firmware_loader.rst
+++ b/doc/develop/driver-model/fs_firmware_loader.rst
@@ -98,8 +98,11 @@ through the U-Boot environment variable during run time.
 
 For examples:
 
+fw_storage_interface:
+  Firmware storage interface, it can be "mmc", "usb", "sata" or "ubi".
 storage_interface:
-  Storage interface, it can be "mmc", "usb", "sata" or "ubi".
+  Storage interface, it can be "mmc", "usb", "sata" or "ubi". This acts
+  as a fallback if fw_storage_interface is not set.
 fw_dev_part:
   Block device number and its partition, it can be "0:1".
 fw_ubi_mtdpart:
diff --git a/drivers/misc/fs_loader.c b/drivers/misc/fs_loader.c
index 1ffc199ba1..3798dab5b6 100644
--- a/drivers/misc/fs_loader.c
+++ b/drivers/misc/fs_loader.c
@@ -153,7 +153,10 @@ static int fw_get_filesystem_firmware(struct udevice *dev)
char *storage_interface, *dev_part, *ubi_mtdpart, *ubi_volume;
int ret;
 
-   storage_interface = env_get("storage_interface");
+   storage_interface = env_get("fw_storage_interface");
+   if (!storage_interface)
+   storage_interface = env_get("storage_interface");
+
dev_part = env_get("fw_dev_part");
ubi_mtdpart = env_get("fw_ubi_mtdpart");
ubi_volume = env_get("fw_ubi_volume");
-- 
2.34.1



Re: [RFC PATCH 15/16] tools/fdtgrep: Include __symbols__ table

2024-01-10 Thread MD Danish Anwar
Hi Simon,

On 26/12/23 3:17 pm, Simon Glass wrote:
> Hi,
> 
> On Tue, Dec 19, 2023 at 10:34 AM MD Danish Anwar  wrote:
>>
>> This is required for overlays to work at SPL.
>>
>> Loading of symbol table depends on DT Overlay support in SPL
>> so make it compile-time dependent. Without this SPL fails to
>> boot some platforms where this feature is not enabled
>> (e.g. dra71-evm.)
>>
>> Without including the  file, the symbol
>> CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY will not be visible and
>> we will never include the symbol table.
>>
>> So include 
>>
>> Due to some reason it needs to be included after
>> [#include "fdt_host.h"] otherwise it causes a build error.
>>
>> Signed-off-by: MD Danish Anwar 
>> ---
>>  tools/fdtgrep.c | 8 
>>  1 file changed, 8 insertions(+)
>>
>> diff --git a/tools/fdtgrep.c b/tools/fdtgrep.c
>> index 7eabcab439..706b4a35f4 100644
>> --- a/tools/fdtgrep.c
>> +++ b/tools/fdtgrep.c
>> @@ -22,6 +22,8 @@
>>  #include "fdt_host.h"
>>  #include "libfdt_internal.h"
>>
>> +#include 
>> +
>>  /* Define DEBUG to get some debugging output on stderr */
>>  #ifdef DEBUG
>>  #define debug(a, b...) fprintf(stderr, a, ## b)
>> @@ -1234,6 +1236,12 @@ int main(int argc, char *argv[])
>> disp.fout = stdout;
>> }
>>
>> +   if (IS_ENABLED(CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY)) {
>> +   /* include symbol table */
>> +   if (value_add(, _head, FDT_IS_NODE, 1, 
>> "/__symbols__"))
>> +   usage("Cannot add __symbols__ value");
>> +   }
>> +
>> /* Run the grep and output the results */
>> ret = do_fdtgrep(, filename);
>> if (disp.output_fname)
>> --
>> 2.34.1
>>
> 
> I may have replied elsewhere, but please use a new fdtgrep option for this.
> 
> Regards,
> Simon

This patch is actually not needed. Without this patch also I am able to
apply overlays at SPL. Even without this patch I see symbols table
getting included while using fdtgrep tool. I will drop this patch in v2.

-- 
Thanks and Regards,
Danish


Re: [RFC PATCH 12/16] arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration

2024-01-10 Thread MD Danish Anwar



On 10/01/24 2:24 pm, Roger Quadros wrote:
> On 10/01/2024 08:50, MD Danish Anwar wrote:
>> Hi Roger,
>>
>> On 27/12/23 3:49 pm, MD Danish Anwar wrote:
>>> On 20/12/23 4:10 pm, Roger Quadros wrote:
>>>>
>>>>
>>>> On 19/12/2023 12:34, MD Danish Anwar wrote:
>>>>> Add ICSSG2 overlay and configuration to tispl and u-boot images.
>>>>>
>>>>> Signed-off-by: MD Danish Anwar 
>>>>> ---
>>>>>  arch/arm/dts/k3-am65x-binman.dtsi | 85 +++
>>>>>  1 file changed, 85 insertions(+)
>>>>>
>>>>> diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
>>>>> b/arch/arm/dts/k3-am65x-binman.dtsi
>>>>> index 8cc24da1f3..9a0c0fca47 100644
>>>>> --- a/arch/arm/dts/k3-am65x-binman.dtsi
>>>>> +++ b/arch/arm/dts/k3-am65x-binman.dtsi
>>>>> @@ -98,6 +98,8 @@
>>>>>  #define SPL_AM654_EVM_DTB "spl/dts/k3-am654-base-board.dtb"
>>>>>  #define AM654_EVM_DTB "u-boot.dtb"
>>>>>  
>>>>> +#define AM654_EVM_ICSSG2_DTBO "arch/arm/dts/k3-am654-icssg2.dtbo"
>>>>> +
>>>>>   {
>>>>>   ti-spl {
>>>>>   insert-template = <_spl_template>;
>>>>> @@ -124,6 +126,20 @@
>>>>>   filename = SPL_AM654_EVM_DTB;
>>>>>   };
>>>>>   };
>>>>> +
>>>>> + fdt-1 {
>>>>> + description = "k3-am654-icssg2 overlay";
>>>>> + type = "flat_dt";
>>>>> + arch = "arm";
>>>>> + compression = "none";
>>>>> + ti-secure {
>>>>> + content = 
>>>>> <_am65x_evm_icssg2_dtb>;
>>>>> + keyfile = "custMpk.pem";
>>>>> + };
>>>>> + spl_am65x_evm_icssg2_dtb: blob-ext {
>>>>> + filename = 
>>>>> AM654_EVM_ICSSG2_DTBO;
>>>>> + };
>>>>
>>>> This is wrong.
>>>>
>>>> ICSSG2 Ethernet should be part of the fdt-0 configuration as the 2 
>>>> Ethernet ports
>>>> on the board are hardwired to ICSSG2. Not having them working by default
>>>> is an invalid configuration.
>>>>
>>>
>>> ICSSG2 ethernet ports should be enabled by default. But the ICSSG2 nodes
>>> is added in the overlay file (k3-am654-icssg2.dtso) in kernel so they
>>> are added in same overlay file in u-boot as well.
>>>
>>> I am keeping,
>>> fdt-0  as k3-am654-base-board dtb,
>>> fdt-1  as k3-am654-icssg2 dtbo,
>>> conf-0 as k3-am654-base-board and
>>> conf-1 as k3-am654-icssg2.
>>>
>>> Do you want me to keep k3-am654-icssg2 dtbo as fdt-0 and
>>> k3-am654-base-board as fdt-1? I tried doing this but this results into
>>> u-boot getting stuck. The tispl and u-boot images are not able to load
>>> if I swap fdt-0 and fdt-1 , and conf-0 and conf-1.
>>>
>>> If the current combination doesn't look OK, please let me know what
>>> should be the correct combinations for fdt-0, fdt-1, conf-0 and conf-1.
>>>
>>
>> Can you please comment on this. I'll send v2 with all the suggested
>> changes once you confirm the correct fdt and configurations.
>>
> Sorry, I missed this.
> 
> fdt-0 = k3-am654-base-board dtb
> fdt-1 = k3-am654-icssg2 dtbo
> 
> conf-0 = fdt-0 and ftd-1
> 

What about conf-1? Should I leave it as it is(currently conf-1 is fdt-0
and fdt-1)?

> as icssg2 ethernet is present on the base board, and should be part of the 
> base board configuration.
> 

-- 
Thanks and Regards,
Danish


Re: [RFC PATCH 12/16] arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration

2024-01-09 Thread MD Danish Anwar
Hi Roger,

On 27/12/23 3:49 pm, MD Danish Anwar wrote:
> On 20/12/23 4:10 pm, Roger Quadros wrote:
>>
>>
>> On 19/12/2023 12:34, MD Danish Anwar wrote:
>>> Add ICSSG2 overlay and configuration to tispl and u-boot images.
>>>
>>> Signed-off-by: MD Danish Anwar 
>>> ---
>>>  arch/arm/dts/k3-am65x-binman.dtsi | 85 +++
>>>  1 file changed, 85 insertions(+)
>>>
>>> diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
>>> b/arch/arm/dts/k3-am65x-binman.dtsi
>>> index 8cc24da1f3..9a0c0fca47 100644
>>> --- a/arch/arm/dts/k3-am65x-binman.dtsi
>>> +++ b/arch/arm/dts/k3-am65x-binman.dtsi
>>> @@ -98,6 +98,8 @@
>>>  #define SPL_AM654_EVM_DTB "spl/dts/k3-am654-base-board.dtb"
>>>  #define AM654_EVM_DTB "u-boot.dtb"
>>>  
>>> +#define AM654_EVM_ICSSG2_DTBO "arch/arm/dts/k3-am654-icssg2.dtbo"
>>> +
>>>   {
>>> ti-spl {
>>> insert-template = <_spl_template>;
>>> @@ -124,6 +126,20 @@
>>> filename = SPL_AM654_EVM_DTB;
>>> };
>>> };
>>> +
>>> +   fdt-1 {
>>> +   description = "k3-am654-icssg2 overlay";
>>> +   type = "flat_dt";
>>> +   arch = "arm";
>>> +   compression = "none";
>>> +   ti-secure {
>>> +   content = 
>>> <_am65x_evm_icssg2_dtb>;
>>> +   keyfile = "custMpk.pem";
>>> +   };
>>> +   spl_am65x_evm_icssg2_dtb: blob-ext {
>>> +   filename = 
>>> AM654_EVM_ICSSG2_DTBO;
>>> +   };
>>
>> This is wrong.
>>
>> ICSSG2 Ethernet should be part of the fdt-0 configuration as the 2 Ethernet 
>> ports
>> on the board are hardwired to ICSSG2. Not having them working by default
>> is an invalid configuration.
>>
> 
> ICSSG2 ethernet ports should be enabled by default. But the ICSSG2 nodes
> is added in the overlay file (k3-am654-icssg2.dtso) in kernel so they
> are added in same overlay file in u-boot as well.
> 
> I am keeping,
> fdt-0  as k3-am654-base-board dtb,
> fdt-1  as k3-am654-icssg2 dtbo,
> conf-0 as k3-am654-base-board and
> conf-1 as k3-am654-icssg2.
> 
> Do you want me to keep k3-am654-icssg2 dtbo as fdt-0 and
> k3-am654-base-board as fdt-1? I tried doing this but this results into
> u-boot getting stuck. The tispl and u-boot images are not able to load
> if I swap fdt-0 and fdt-1 , and conf-0 and conf-1.
> 
> If the current combination doesn't look OK, please let me know what
> should be the correct combinations for fdt-0, fdt-1, conf-0 and conf-1.
> 

Can you please comment on this. I'll send v2 with all the suggested
changes once you confirm the correct fdt and configurations.



-- 
Thanks and Regards,
Danish


Re: [RFC PATCH 00/16] Introduce ICSSG Ethernet driver

2024-01-09 Thread MD Danish Anwar



On 09/01/24 2:56 pm, Roger Quadros wrote:
> 
> 
> On 08/01/2024 12:25, MD Danish Anwar wrote:
>> On 08/01/24 3:00 pm, Roger Quadros wrote:
>>>
>>>
>>> On 05/01/2024 12:15, Anwar, Md Danish wrote:
>>>>
>>>>
>>>> On 1/5/2024 1:49 PM, Roger Quadros wrote:
>>>>>
>>>>>
>>>>> On 03/01/2024 12:27, MD Danish Anwar wrote:
>>>>>>
>>>>>>
>>>>>> On 02/01/24 7:26 pm, Andrew Davis wrote:
>>>>>>> On 12/27/23 12:56 AM, MD Danish Anwar wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>> On 22/12/23 6:13 pm, Roger Quadros wrote:
>>>>>>>>>
>>>>>>>>> On 22/12/2023 12:26, MD Danish Anwar wrote:
>>>>>>>>>> Hi Roger,
>>>>>>>>>>
>>>>>>>>>> On 20/12/23 3:29 pm, Roger Quadros wrote:
>>>>>>>>>>> Hi,
>>>>>>>>>>>
>>>>>>>>>>> On 19/12/2023 12:11, MD Danish Anwar wrote:
>>>>>>>>>>>> Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used
>>>>>>>>>>>> in TI
>>>>>>>>>>>> AM654 SR2.0.
>>>>>>>>>>>>
>>>>>>>>>>>> The ICSSG PRU Sub-system runs on EMAC firmware. This series
>>>>>>>>>>>> Introduces
>>>>>>>>>>>> support for ICSSG driver in uboot. This series also adds the 
>>>>>>>>>>>> driver's
>>>>>>>>>>>> dependencies.
>>>>>>>>>>>>
>>>>>>>>>>>> The ICSSG2 node is added in device tree overlay so that it remains 
>>>>>>>>>>>> in
>>>>>>>>>>>> sync with linux kernel.
>>>>>>>>>>>>
>>>>>>>>>>>> The series introduces device tree and config changes and AM65x
>>>>>>>>>>>> to enable ICSSG driver. The series also enables
>>>>>>>>>>>> SPL_LOAD_FIT_APPLY_OVERLAY
>>>>>>>>>>>> for AM65x in order to load overlay over spl.
>>>>>>>>>>>>
>>>>>>>>>>>> This series has been tested on AM65x SR2.0, and the ICSSG
>>>>>>>>>>>> interface is
>>>>>>>>>>>> able to ping / dhcp and boot kernel using tftp in uboot.
>>>>>>>>>>>>
>>>>>>>>>>>> To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to
>>>>>>>>>>>> PRU RPROC
>>>>>>>>>>>> cores and RPROC cores need to be booted with the firmware. This
>>>>>>>>>>>> step is
>>>>>>>>>>>> done inside driver in kernel as kernel supports APIs like
>>>>>>>>>>>> rproc_set_firmware() and rproc_fw_boot(). But as u-boot doesn't
>>>>>>>>>>>> have these
>>>>>>>>>>>> APIs, the same needs to be done via u-boot cmds.
>>>>>>>>>>>>
>>>>>>>>>>>> To make sure icssg-eth works we need to do below steps.
>>>>>>>>>>>>
>>>>>>>>>>>> 1. Initialize rproc cores i.e. rproc_init()
>>>>>>>>>>>> 2. Load $firmware_file from partition '1:2' (root) on device (mmc
>>>>>>>>>>>> in this
>>>>>>>>>>>>     example)
>>>>>>>>>>>> 3. Load the firmware file to rproc cores passing. i.e. rproc_load()
>>>>>>>>>>>>     taking rproc_id, loadaddr and file size as arguments.
>>>>>>>>>>>> 4. Start rproc cores. i.e. rproc_start() taking rproc_id as 
>>>>>>>>>>>> arguments
>>>>>>>>>>>>
>>>>>>>>>>>> The above steps are done by running the below commands at u-boot
>>>>>>>>>>>> prompt.
>>>>>>>>>>>>
>>>>>>>>>>>> => setenv s

Re: [RFC PATCH 00/16] Introduce ICSSG Ethernet driver

2024-01-08 Thread MD Danish Anwar
On 08/01/24 3:00 pm, Roger Quadros wrote:
> 
> 
> On 05/01/2024 12:15, Anwar, Md Danish wrote:
>>
>>
>> On 1/5/2024 1:49 PM, Roger Quadros wrote:
>>>
>>>
>>> On 03/01/2024 12:27, MD Danish Anwar wrote:
>>>>
>>>>
>>>> On 02/01/24 7:26 pm, Andrew Davis wrote:
>>>>> On 12/27/23 12:56 AM, MD Danish Anwar wrote:
>>>>>>
>>>>>>
>>>>>> On 22/12/23 6:13 pm, Roger Quadros wrote:
>>>>>>>
>>>>>>> On 22/12/2023 12:26, MD Danish Anwar wrote:
>>>>>>>> Hi Roger,
>>>>>>>>
>>>>>>>> On 20/12/23 3:29 pm, Roger Quadros wrote:
>>>>>>>>> Hi,
>>>>>>>>>
>>>>>>>>> On 19/12/2023 12:11, MD Danish Anwar wrote:
>>>>>>>>>> Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used
>>>>>>>>>> in TI
>>>>>>>>>> AM654 SR2.0.
>>>>>>>>>>
>>>>>>>>>> The ICSSG PRU Sub-system runs on EMAC firmware. This series
>>>>>>>>>> Introduces
>>>>>>>>>> support for ICSSG driver in uboot. This series also adds the driver's
>>>>>>>>>> dependencies.
>>>>>>>>>>
>>>>>>>>>> The ICSSG2 node is added in device tree overlay so that it remains in
>>>>>>>>>> sync with linux kernel.
>>>>>>>>>>
>>>>>>>>>> The series introduces device tree and config changes and AM65x
>>>>>>>>>> to enable ICSSG driver. The series also enables
>>>>>>>>>> SPL_LOAD_FIT_APPLY_OVERLAY
>>>>>>>>>> for AM65x in order to load overlay over spl.
>>>>>>>>>>
>>>>>>>>>> This series has been tested on AM65x SR2.0, and the ICSSG
>>>>>>>>>> interface is
>>>>>>>>>> able to ping / dhcp and boot kernel using tftp in uboot.
>>>>>>>>>>
>>>>>>>>>> To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to
>>>>>>>>>> PRU RPROC
>>>>>>>>>> cores and RPROC cores need to be booted with the firmware. This
>>>>>>>>>> step is
>>>>>>>>>> done inside driver in kernel as kernel supports APIs like
>>>>>>>>>> rproc_set_firmware() and rproc_fw_boot(). But as u-boot doesn't
>>>>>>>>>> have these
>>>>>>>>>> APIs, the same needs to be done via u-boot cmds.
>>>>>>>>>>
>>>>>>>>>> To make sure icssg-eth works we need to do below steps.
>>>>>>>>>>
>>>>>>>>>> 1. Initialize rproc cores i.e. rproc_init()
>>>>>>>>>> 2. Load $firmware_file from partition '1:2' (root) on device (mmc
>>>>>>>>>> in this
>>>>>>>>>>     example)
>>>>>>>>>> 3. Load the firmware file to rproc cores passing. i.e. rproc_load()
>>>>>>>>>>     taking rproc_id, loadaddr and file size as arguments.
>>>>>>>>>> 4. Start rproc cores. i.e. rproc_start() taking rproc_id as arguments
>>>>>>>>>>
>>>>>>>>>> The above steps are done by running the below commands at u-boot
>>>>>>>>>> prompt.
>>>>>>>>>>
>>>>>>>>>> => setenv start_icssg2 'rproc start 14; rproc start 15; rproc
>>>>>>>>>> start 16; rproc start 17; rproc start 18; rproc start 19'
>>>>>>>>>> => setenv stop_icssg2 'rproc stop 14; rproc stop 15; rproc stop
>>>>>>>>>> 16; rproc stop 17; rproc stop 18; rproc stop 19'
>>>>>>>>>> => setenv firmware_dir '/lib/firmware/ti-pruss'
>>>>>>>>>> => setenv get_firmware_mmc 'load mmc ${bootpart} ${loadaddr}
>>>>>>>>>> ${firmware_dir}/${firmware_file}'
>>>>>>>>>>
>>>>>>>>>> => setenv init_icssg2 'setenv ethact icssg2-eth; setenv autoload
>>>>>>>>>

Re: [RFC PATCH 00/16] Introduce ICSSG Ethernet driver

2024-01-03 Thread MD Danish Anwar



On 02/01/24 7:26 pm, Andrew Davis wrote:
> On 12/27/23 12:56 AM, MD Danish Anwar wrote:
>>
>>
>> On 22/12/23 6:13 pm, Roger Quadros wrote:
>>>
>>> On 22/12/2023 12:26, MD Danish Anwar wrote:
>>>> Hi Roger,
>>>>
>>>> On 20/12/23 3:29 pm, Roger Quadros wrote:
>>>>> Hi,
>>>>>
>>>>> On 19/12/2023 12:11, MD Danish Anwar wrote:
>>>>>> Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used
>>>>>> in TI
>>>>>> AM654 SR2.0.
>>>>>>
>>>>>> The ICSSG PRU Sub-system runs on EMAC firmware. This series
>>>>>> Introduces
>>>>>> support for ICSSG driver in uboot. This series also adds the driver's
>>>>>> dependencies.
>>>>>>
>>>>>> The ICSSG2 node is added in device tree overlay so that it remains in
>>>>>> sync with linux kernel.
>>>>>>
>>>>>> The series introduces device tree and config changes and AM65x
>>>>>> to enable ICSSG driver. The series also enables
>>>>>> SPL_LOAD_FIT_APPLY_OVERLAY
>>>>>> for AM65x in order to load overlay over spl.
>>>>>>
>>>>>> This series has been tested on AM65x SR2.0, and the ICSSG
>>>>>> interface is
>>>>>> able to ping / dhcp and boot kernel using tftp in uboot.
>>>>>>
>>>>>> To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to
>>>>>> PRU RPROC
>>>>>> cores and RPROC cores need to be booted with the firmware. This
>>>>>> step is
>>>>>> done inside driver in kernel as kernel supports APIs like
>>>>>> rproc_set_firmware() and rproc_fw_boot(). But as u-boot doesn't
>>>>>> have these
>>>>>> APIs, the same needs to be done via u-boot cmds.
>>>>>>
>>>>>> To make sure icssg-eth works we need to do below steps.
>>>>>>
>>>>>> 1. Initialize rproc cores i.e. rproc_init()
>>>>>> 2. Load $firmware_file from partition '1:2' (root) on device (mmc
>>>>>> in this
>>>>>>     example)
>>>>>> 3. Load the firmware file to rproc cores passing. i.e. rproc_load()
>>>>>>     taking rproc_id, loadaddr and file size as arguments.
>>>>>> 4. Start rproc cores. i.e. rproc_start() taking rproc_id as arguments
>>>>>>
>>>>>> The above steps are done by running the below commands at u-boot
>>>>>> prompt.
>>>>>>
>>>>>> => setenv start_icssg2 'rproc start 14; rproc start 15; rproc
>>>>>> start 16; rproc start 17; rproc start 18; rproc start 19'
>>>>>> => setenv stop_icssg2 'rproc stop 14; rproc stop 15; rproc stop
>>>>>> 16; rproc stop 17; rproc stop 18; rproc stop 19'
>>>>>> => setenv firmware_dir '/lib/firmware/ti-pruss'
>>>>>> => setenv get_firmware_mmc 'load mmc ${bootpart} ${loadaddr}
>>>>>> ${firmware_dir}/${firmware_file}'
>>>>>>
>>>>>> => setenv init_icssg2 'setenv ethact icssg2-eth; setenv autoload
>>>>>> no; rproc init; setenv loadaddr 0x8000; \
>>>>>>  setenv firmware_file am65x-sr2-pru0-prueth-fw.elf; run
>>>>>> get_firmware_mmc;  rproc load 14 0x8000 ${filesize}; \
>>>>>>  setenv loadaddr 0x8900; setenv firmware_file
>>>>>> am65x-sr2-rtu0-prueth-fw.elf; run get_firmware_mmc; rproc load 15
>>>>>> 0x8900 ${filesize}; \
>>>>>>  setenv loadaddr 0x9000; setenv firmware_file
>>>>>> am65x-sr2-txpru0-prueth-fw.elf; run get_firmware_mmc; rproc load
>>>>>> 16 0x9000 ${filesize}; \
>>>>>>  setenv loadaddr 0x8000; setenv firmware_file
>>>>>> am65x-sr2-pru1-prueth-fw.elf; run get_firmware_mmc; rproc load 17
>>>>>> 0x8000 ${filesize}; \
>>>>>>  setenv loadaddr 0x8900; setenv firmware_file
>>>>>> am65x-sr2-rtu1-prueth-fw.elf; run get_firmware_mmc; rproc load 18
>>>>>> 0x8900 ${filesize}; \
>>>>>>  setenv loadaddr 0x9000; setenv firmware_file
>>>>>> am65x-sr2-txpru1-prueth-fw.elf; run get_firmware_mmc; rproc load
>>>>>> 19 0x9000 ${filesize}; \
>>>>

Re: [RFC PATCH 12/16] arm: dts: k3-am65x-binman: Add ICSSG2 overlay and configuration

2023-12-27 Thread MD Danish Anwar
On 20/12/23 4:10 pm, Roger Quadros wrote:
> 
> 
> On 19/12/2023 12:34, MD Danish Anwar wrote:
>> Add ICSSG2 overlay and configuration to tispl and u-boot images.
>>
>> Signed-off-by: MD Danish Anwar 
>> ---
>>  arch/arm/dts/k3-am65x-binman.dtsi | 85 +++
>>  1 file changed, 85 insertions(+)
>>
>> diff --git a/arch/arm/dts/k3-am65x-binman.dtsi 
>> b/arch/arm/dts/k3-am65x-binman.dtsi
>> index 8cc24da1f3..9a0c0fca47 100644
>> --- a/arch/arm/dts/k3-am65x-binman.dtsi
>> +++ b/arch/arm/dts/k3-am65x-binman.dtsi
>> @@ -98,6 +98,8 @@
>>  #define SPL_AM654_EVM_DTB "spl/dts/k3-am654-base-board.dtb"
>>  #define AM654_EVM_DTB "u-boot.dtb"
>>  
>> +#define AM654_EVM_ICSSG2_DTBO "arch/arm/dts/k3-am654-icssg2.dtbo"
>> +
>>   {
>>  ti-spl {
>>  insert-template = <_spl_template>;
>> @@ -124,6 +126,20 @@
>>  filename = SPL_AM654_EVM_DTB;
>>  };
>>  };
>> +
>> +fdt-1 {
>> +description = "k3-am654-icssg2 overlay";
>> +type = "flat_dt";
>> +arch = "arm";
>> +compression = "none";
>> +ti-secure {
>> +content = 
>> <_am65x_evm_icssg2_dtb>;
>> +keyfile = "custMpk.pem";
>> +};
>> +spl_am65x_evm_icssg2_dtb: blob-ext {
>> +filename = 
>> AM654_EVM_ICSSG2_DTBO;
>> +};
> 
> This is wrong.
> 
> ICSSG2 Ethernet should be part of the fdt-0 configuration as the 2 Ethernet 
> ports
> on the board are hardwired to ICSSG2. Not having them working by default
> is an invalid configuration.
> 

ICSSG2 ethernet ports should be enabled by default. But the ICSSG2 nodes
is added in the overlay file (k3-am654-icssg2.dtso) in kernel so they
are added in same overlay file in u-boot as well.

I am keeping,
fdt-0  as k3-am654-base-board dtb,
fdt-1  as k3-am654-icssg2 dtbo,
conf-0 as k3-am654-base-board and
conf-1 as k3-am654-icssg2.

Do you want me to keep k3-am654-icssg2 dtbo as fdt-0 and
k3-am654-base-board as fdt-1? I tried doing this but this results into
u-boot getting stuck. The tispl and u-boot images are not able to load
if I swap fdt-0 and fdt-1 , and conf-0 and conf-1.

If the current combination doesn't look OK, please let me know what
should be the correct combinations for fdt-0, fdt-1, conf-0 and conf-1.

>> +};
>>  };
>>  
>>  configurations {
>> @@ -135,6 +151,13 @@
>>  loadables = "tee", "dm", "spl";
>>  fdt = "fdt-0";
>>  };
>> +
>> +conf-1 {
>> +description = "k3-am654-icssg2";
>> +firmware = "atf";
>> +loadables = "tee", "dm", "spl";
>> +fdt = "fdt-0", "fdt-1";
>> +};
>>  };
>>  };
>>  };s
>> @@ -168,6 +191,24 @@
>>  };
>>  };
>>  
>> +fdt-1 {
>> +description = "k3-am654-icssg2 overlay";
>> +type = "flat_dt";
>> +arch = "arm";
>> +compression = "none";
>> +ti-secure {
>> +content = 
>> <_evm_icssg2_dtb>;
>> +keyfile = "custMpk.pem";
>> +
>> +};
>> +am65x_evm_icssg2_dtb: blob-ext {
>> +filename = 
>> AM654_EVM_ICSSG2_DTBO;
>> +

Re: [RFC PATCH 00/16] Introduce ICSSG Ethernet driver

2023-12-26 Thread MD Danish Anwar



On 22/12/23 6:13 pm, Roger Quadros wrote:
> 
> On 22/12/2023 12:26, MD Danish Anwar wrote:
>> Hi Roger,
>>
>> On 20/12/23 3:29 pm, Roger Quadros wrote:
>>> Hi,
>>>
>>> On 19/12/2023 12:11, MD Danish Anwar wrote:
>>>> Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
>>>> AM654 SR2.0.
>>>>
>>>> The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
>>>> support for ICSSG driver in uboot. This series also adds the driver's
>>>> dependencies.
>>>>
>>>> The ICSSG2 node is added in device tree overlay so that it remains in
>>>> sync with linux kernel.
>>>>
>>>> The series introduces device tree and config changes and AM65x
>>>> to enable ICSSG driver. The series also enables SPL_LOAD_FIT_APPLY_OVERLAY
>>>> for AM65x in order to load overlay over spl.
>>>>
>>>> This series has been tested on AM65x SR2.0, and the ICSSG interface is
>>>> able to ping / dhcp and boot kernel using tftp in uboot.
>>>>
>>>> To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
>>>> cores and RPROC cores need to be booted with the firmware. This step is
>>>> done inside driver in kernel as kernel supports APIs like
>>>> rproc_set_firmware() and rproc_fw_boot(). But as u-boot doesn't have these
>>>> APIs, the same needs to be done via u-boot cmds.
>>>>
>>>> To make sure icssg-eth works we need to do below steps.
>>>>
>>>> 1. Initialize rproc cores i.e. rproc_init()
>>>> 2. Load $firmware_file from partition '1:2' (root) on device (mmc in this
>>>>example)
>>>> 3. Load the firmware file to rproc cores passing. i.e. rproc_load()
>>>>taking rproc_id, loadaddr and file size as arguments.
>>>> 4. Start rproc cores. i.e. rproc_start() taking rproc_id as arguments
>>>>
>>>> The above steps are done by running the below commands at u-boot prompt.
>>>>
>>>> => setenv start_icssg2 'rproc start 14; rproc start 15; rproc start 16; 
>>>> rproc start 17; rproc start 18; rproc start 19'
>>>> => setenv stop_icssg2 'rproc stop 14; rproc stop 15; rproc stop 16; rproc 
>>>> stop 17; rproc stop 18; rproc stop 19'
>>>> => setenv firmware_dir '/lib/firmware/ti-pruss'
>>>> => setenv get_firmware_mmc 'load mmc ${bootpart} ${loadaddr} 
>>>> ${firmware_dir}/${firmware_file}'
>>>>
>>>> => setenv init_icssg2 'setenv ethact icssg2-eth; setenv autoload no; rproc 
>>>> init; setenv loadaddr 0x8000; \
>>>> setenv firmware_file am65x-sr2-pru0-prueth-fw.elf; run 
>>>> get_firmware_mmc;  rproc load 14 0x8000 ${filesize}; \
>>>> setenv loadaddr 0x8900; setenv firmware_file 
>>>> am65x-sr2-rtu0-prueth-fw.elf; run get_firmware_mmc; rproc load 15 
>>>> 0x8900 ${filesize}; \
>>>> setenv loadaddr 0x9000; setenv firmware_file 
>>>> am65x-sr2-txpru0-prueth-fw.elf; run get_firmware_mmc; rproc load 16 
>>>> 0x9000 ${filesize}; \
>>>> setenv loadaddr 0x8000; setenv firmware_file 
>>>> am65x-sr2-pru1-prueth-fw.elf; run get_firmware_mmc; rproc load 17 
>>>> 0x8000 ${filesize}; \
>>>> setenv loadaddr 0x8900; setenv firmware_file 
>>>> am65x-sr2-rtu1-prueth-fw.elf; run get_firmware_mmc; rproc load 18 
>>>> 0x8900 ${filesize}; \
>>>> setenv loadaddr 0x9000; setenv firmware_file 
>>>> am65x-sr2-txpru1-prueth-fw.elf; run get_firmware_mmc; rproc load 19 
>>>> 0x9000 ${filesize}; \
>>>> run start_icssg2;'
>>>
>>> A whole bunch of commands are required to get ethernet functional.
>>> This is not at all user friendly and will be a maintenance nightmare.
>>> What worries me is tracking the 6 different rproc cores and the 6 different 
>>> firmware files to start 1 ethernet device.
>>> This will get even more interesting when we have to deal with different 
>>> ICSSG instances on different boards.
>>>
>>> What is preventing the driver from starting the rproc cores it needs so 
>>> user doesn't need to care about it?
>>> All the necessary information is in the Device tree. At least this is how 
>>> it is done on Linux.
>>>
>>
>> I tried removing the need for these commands and implementing them
>> inside the driver on

Re: [RFC PATCH 00/16] Introduce ICSSG Ethernet driver

2023-12-22 Thread MD Danish Anwar
Hi Roger,

On 20/12/23 3:29 pm, Roger Quadros wrote:
> Hi,
> 
> On 19/12/2023 12:11, MD Danish Anwar wrote:
>> Introduce ICSSG PRUETH support in uboot. The ICSSG driver is used in TI
>> AM654 SR2.0.
>>
>> The ICSSG PRU Sub-system runs on EMAC firmware. This series Introduces
>> support for ICSSG driver in uboot. This series also adds the driver's
>> dependencies.
>>
>> The ICSSG2 node is added in device tree overlay so that it remains in
>> sync with linux kernel.
>>
>> The series introduces device tree and config changes and AM65x
>> to enable ICSSG driver. The series also enables SPL_LOAD_FIT_APPLY_OVERLAY
>> for AM65x in order to load overlay over spl.
>>
>> This series has been tested on AM65x SR2.0, and the ICSSG interface is
>> able to ping / dhcp and boot kernel using tftp in uboot.
>>
>> To use ICSSG2 ethernet, the ICSSG firmware needs to be loaded to PRU RPROC
>> cores and RPROC cores need to be booted with the firmware. This step is
>> done inside driver in kernel as kernel supports APIs like
>> rproc_set_firmware() and rproc_fw_boot(). But as u-boot doesn't have these
>> APIs, the same needs to be done via u-boot cmds.
>>
>> To make sure icssg-eth works we need to do below steps.
>>
>> 1. Initialize rproc cores i.e. rproc_init()
>> 2. Load $firmware_file from partition '1:2' (root) on device (mmc in this
>>example)
>> 3. Load the firmware file to rproc cores passing. i.e. rproc_load()
>>taking rproc_id, loadaddr and file size as arguments.
>> 4. Start rproc cores. i.e. rproc_start() taking rproc_id as arguments
>>
>> The above steps are done by running the below commands at u-boot prompt.
>>
>> => setenv start_icssg2 'rproc start 14; rproc start 15; rproc start 16; 
>> rproc start 17; rproc start 18; rproc start 19'
>> => setenv stop_icssg2 'rproc stop 14; rproc stop 15; rproc stop 16; rproc 
>> stop 17; rproc stop 18; rproc stop 19'
>> => setenv firmware_dir '/lib/firmware/ti-pruss'
>> => setenv get_firmware_mmc 'load mmc ${bootpart} ${loadaddr} 
>> ${firmware_dir}/${firmware_file}'
>>
>> => setenv init_icssg2 'setenv ethact icssg2-eth; setenv autoload no; rproc 
>> init; setenv loadaddr 0x8000; \
>> setenv firmware_file am65x-sr2-pru0-prueth-fw.elf; run get_firmware_mmc; 
>>  rproc load 14 0x8000 ${filesize}; \
>> setenv loadaddr 0x8900; setenv firmware_file 
>> am65x-sr2-rtu0-prueth-fw.elf; run get_firmware_mmc; rproc load 15 0x8900 
>> ${filesize}; \
>> setenv loadaddr 0x9000; setenv firmware_file 
>> am65x-sr2-txpru0-prueth-fw.elf; run get_firmware_mmc; rproc load 16 
>> 0x9000 ${filesize}; \
>> setenv loadaddr 0x8000; setenv firmware_file 
>> am65x-sr2-pru1-prueth-fw.elf; run get_firmware_mmc; rproc load 17 0x8000 
>> ${filesize}; \
>> setenv loadaddr 0x8900; setenv firmware_file 
>> am65x-sr2-rtu1-prueth-fw.elf; run get_firmware_mmc; rproc load 18 0x8900 
>> ${filesize}; \
>> setenv loadaddr 0x9000; setenv firmware_file 
>> am65x-sr2-txpru1-prueth-fw.elf; run get_firmware_mmc; rproc load 19 
>> 0x9000 ${filesize}; \
>> run start_icssg2;'
> 
> A whole bunch of commands are required to get ethernet functional.
> This is not at all user friendly and will be a maintenance nightmare.
> What worries me is tracking the 6 different rproc cores and the 6 different 
> firmware files to start 1 ethernet device.
> This will get even more interesting when we have to deal with different ICSSG 
> instances on different boards.
> 
> What is preventing the driver from starting the rproc cores it needs so user 
> doesn't need to care about it?
> All the necessary information is in the Device tree. At least this is how it 
> is done on Linux.
> 

I tried removing the need for these commands and implementing them
inside the driver only. I am able to load the firmware from driver using
the fs_loader API request_firmware_into_buf(). It requires changes to
dt. A DT node called fs-loader needs to be added also CONFIG_FS_LOADER
needs to enabled. In the DT node we need to specify the storage media
that we are using i.e. mmc, ospi, usb. It's upto user to modify the
storage media, the driver will take the media from DT and try to laod
firmware from their.

For loading firmwares to rproc cores, rproc_load() API is needed. Now
this API takes rproc_id, loadaddr and firmware_size as arguments.
loadaddr is fixed for all three pru cores. firmware_size is obtained
from request_firmware_into_buf() but I couldn't find a way to get the
rproc_id. For now based on the ICSSG instance and slice number I am
figuring out 

Re: [RFC PATCH 14/16] configs: am65x_evm_a53_defconfig: add SPL_LOAD_FIT_APPLY_OVERLAY

2023-12-21 Thread MD Danish Anwar
Roger,

On 20/12/23 3:32 pm, Roger Quadros wrote:
> 
> 
> On 19/12/2023 12:34, MD Danish Anwar wrote:
>> We want SPL to apply DTB overlays (e.g. NAND card overlay) so
>> enable SPL_LOAD_FIT_APPLY_OVERLAY.
>> Increase SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ and
>> SPL_STACK_R_MALLOC_SIMPLE_LEN. Without this SPL hangs.
>>
>> Signed-off-by: MD Danish Anwar 
>> ---
>>  configs/am65x_evm_a53_defconfig | 3 +++
>>  1 file changed, 3 insertions(+)
>>
>> diff --git a/configs/am65x_evm_a53_defconfig 
>> b/configs/am65x_evm_a53_defconfig
>> index e79a961317..2755d7082f 100644
>> --- a/configs/am65x_evm_a53_defconfig
>> +++ b/configs/am65x_evm_a53_defconfig
>> @@ -70,6 +70,9 @@ CONFIG_CMD_I2C=y
>>  CONFIG_CMD_MMC=y
>>  CONFIG_CMD_PCI=y
>>  CONFIG_CMD_REMOTEPROC=y
>> +CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY=y
>> +CONFIG_SPL_LOAD_FIT_APPLY_OVERLAY_BUF_SZ=0x10
>> +CONFIG_SPL_STACK_R_MALLOC_SIMPLE_LEN=0x100
> 
> This change to 16MB is not required. I suppose default is 4MB.
> Did you face issues with it?
> 

Without these I see below error in uboot,

U-Boot SPL 2024.01-rc5-00539-gdc3afd4d5b (Dec 21 2023 - 11:23:56 +0530)
SYSFW ABI: 3.1 (firmware rev 0x0009 '9.1.6--v09.01.06 (Kool Koala)')
Trying to boot from MMC2
spl_register_fat_device: fat register err - -1
spl_load_image_fat: error reading image u-boot.img, err - -1
SPL: failed to boot from all boot devices
### ERROR ### Please RESET the board ###

The only way to recover from here is to do a power cycle reset. But when
you boot again, the issue is seen again. So I think these changes are
also needed. Without this, SPL doesn't work properly.

>>  CONFIG_CMD_USB=y
>>  CONFIG_CMD_TIME=y
>>  CONFIG_MTDIDS_DEFAULT="nor0=4704.spi.0"
> 

-- 
Thanks and Regards,
Danish


Re: [RFC PATCH 16/16] Revert "dm: core: Report bootph-pre-ram/sram node as pre-reloc after relocation"

2023-12-20 Thread MD Danish Anwar
Hi Simon,
Please ignore this thread. This patch is actually not part of the series
and I mistakenly posted it. I have reposted this series. Please review
that. Sorry for the inconvinience.

On 20/12/23 10:16 am, Simon Glass wrote:
> Hi,
> 
> On Tue, 19 Dec 2023 at 03:13, MD Danish Anwar  wrote:
>>
>> This reverts commit 9e644284ab812f2db23f6185af77c0e771b0be73.
>> ---
>>  drivers/core/ofnode.c | 2 +-
>>  include/dm/ofnode.h   | 8 
>>  2 files changed, 5 insertions(+), 5 deletions(-)
>>
> 
> Can you please add some info more info about why this is needed?
> 
> Regards,
> Simon
> 
> 
>> diff --git a/drivers/core/ofnode.c b/drivers/core/ofnode.c
>> index 21a233f90f..cc2029e62d 100644
>> --- a/drivers/core/ofnode.c
>> +++ b/drivers/core/ofnode.c
>> @@ -1485,7 +1485,7 @@ bool ofnode_pre_reloc(ofnode node)
>>  */
>> if (ofnode_read_bool(node, "bootph-pre-ram") ||
>> ofnode_read_bool(node, "bootph-pre-sram"))
>> -   return gd->flags & GD_FLG_RELOC;
>> +   return true;
>>
>> if (IS_ENABLED(CONFIG_OF_TAG_MIGRATE)) {
>> /* detect and handle old tags */
>> diff --git a/include/dm/ofnode.h b/include/dm/ofnode.h
>> index 5795115c49..5f1c8c2787 100644
>> --- a/include/dm/ofnode.h
>> +++ b/include/dm/ofnode.h
>> @@ -1254,15 +1254,15 @@ int ofnode_read_simple_size_cells(ofnode node);
>>   * determine if a node was bound in one of SPL/TPL stages.
>>   *
>>   * There are 4 settings currently in use
>> - * - bootph-some-ram: U-Boot proper pre-relocation phase
>> + * - bootph-some-ram: U-Boot proper pre-relocation only
>>   * - bootph-all: all phases
>>   * Existing platforms only use it to indicate nodes needed in
>>   * SPL. Should probably be replaced by bootph-pre-ram for new platforms.
>> - * - bootph-pre-ram: SPL phase
>> - * - bootph-pre-sram: TPL phase
>> + * - bootph-pre-ram: SPL and U-Boot pre-relocation
>> + * - bootph-pre-sram: TPL and U-Boot pre-relocation
>>   *
>>   * @node: node to check
>> - * Return: true if node should be or was bound, false otherwise
>> + * Return: true if node is needed in SPL/TL, false otherwise
>>   */
>>  bool ofnode_pre_reloc(ofnode node);
>>
>> --
>> 2.34.1
>>

-- 
Thanks and Regards,
Danish


Re: [RFC PATCH 10/16] arm: dts: k3-am65-main: Add ICSSG IEP nodes

2023-12-20 Thread MD Danish Anwar
Hi Tom,

On 19/12/23 11:16 pm, Tom Rini wrote:
> On Tue, Dec 19, 2023 at 04:04:12PM +0530, MD Danish Anwar wrote:
> 
>> The ICSSG IP on AM65x SoCs have two Industrial Ethernet Peripherals (IEPs)
>> to manage/generate Industrial Ethernet functions such as time stamping.
>> Each IEP sub-module is sourced from an internal clock mux that can be
>> sourced from either of the IP instance's ICSSG_IEP_GCLK or ICSSG_ICLK.
>> Add the IEP nodes for all the ICSSG instances.
>>
>> Signed-off-by: MD Danish Anwar 
>> ---
>>  arch/arm/dts/k3-am65-main.dtsi | 36 ++
>>  1 file changed, 36 insertions(+)
> 
> What's the status of all of the DT side of this, upstream?
> 

All of the DT patches are already part of upstream linux kernel except
for patch 08/16. This patch is currently in linux-next and will be in
linux in 6.8-rc1.

-- 
Thanks and Regards,
Danish


  1   2   >