* [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree
@ 2025-06-10 5:25 MD Danish Anwar
2025-06-12 0:02 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: MD Danish Anwar @ 2025-06-10 5:25 UTC (permalink / raw)
To: Meghana Malladi, Paolo Abeni, Jakub Kicinski, Eric Dumazet,
David S. Miller, Andrew Lunn
Cc: linux-kernel, netdev, linux-arm-kernel, srk, Vignesh Raghavendra,
Roger Quadros, danishanwar
Refactor the way firmware names are handled for the ICSSG PRUETH driver.
Instead of using hardcoded firmware name arrays for different modes (EMAC,
SWITCH, HSR), the driver now reads the firmware names from the device tree
property "firmware-name". Only the EMAC firmware names are specified in the
device tree property. The firmware names for all other supported modes are
generated dynamically based on the EMAC firmware names by replacing
substrings (e.g., "eth" with "sw" or "hsr") as appropriate.
This improves flexibility and allows firmware names to be customized via
the device tree, reducing the need for code changes when firmware names
change for different platforms.
Signed-off-by: MD Danish Anwar <danishanwar@ti.com>
---
drivers/net/ethernet/ti/icssg/icssg_prueth.c | 135 +++++++++++++------
drivers/net/ethernet/ti/icssg/icssg_prueth.h | 12 +-
2 files changed, 102 insertions(+), 45 deletions(-)
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.c b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
index 86fc1278127c..a1e013b0a0eb 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.c
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.c
@@ -125,45 +125,6 @@ static irqreturn_t prueth_tx_ts_irq(int irq, void *dev_id)
return IRQ_HANDLED;
}
-static struct icssg_firmwares icssg_hsr_firmwares[] = {
- {
- .pru = "ti-pruss/am65x-sr2-pru0-pruhsr-fw.elf",
- .rtu = "ti-pruss/am65x-sr2-rtu0-pruhsr-fw.elf",
- .txpru = "ti-pruss/am65x-sr2-txpru0-pruhsr-fw.elf",
- },
- {
- .pru = "ti-pruss/am65x-sr2-pru1-pruhsr-fw.elf",
- .rtu = "ti-pruss/am65x-sr2-rtu1-pruhsr-fw.elf",
- .txpru = "ti-pruss/am65x-sr2-txpru1-pruhsr-fw.elf",
- }
-};
-
-static struct icssg_firmwares icssg_switch_firmwares[] = {
- {
- .pru = "ti-pruss/am65x-sr2-pru0-prusw-fw.elf",
- .rtu = "ti-pruss/am65x-sr2-rtu0-prusw-fw.elf",
- .txpru = "ti-pruss/am65x-sr2-txpru0-prusw-fw.elf",
- },
- {
- .pru = "ti-pruss/am65x-sr2-pru1-prusw-fw.elf",
- .rtu = "ti-pruss/am65x-sr2-rtu1-prusw-fw.elf",
- .txpru = "ti-pruss/am65x-sr2-txpru1-prusw-fw.elf",
- }
-};
-
-static struct icssg_firmwares icssg_emac_firmwares[] = {
- {
- .pru = "ti-pruss/am65x-sr2-pru0-prueth-fw.elf",
- .rtu = "ti-pruss/am65x-sr2-rtu0-prueth-fw.elf",
- .txpru = "ti-pruss/am65x-sr2-txpru0-prueth-fw.elf",
- },
- {
- .pru = "ti-pruss/am65x-sr2-pru1-prueth-fw.elf",
- .rtu = "ti-pruss/am65x-sr2-rtu1-prueth-fw.elf",
- .txpru = "ti-pruss/am65x-sr2-txpru1-prueth-fw.elf",
- }
-};
-
static int prueth_start(struct rproc *rproc, const char *fw_name)
{
int ret;
@@ -186,11 +147,11 @@ static int prueth_emac_start(struct prueth *prueth)
int ret, slice;
if (prueth->is_switch_mode)
- firmwares = icssg_switch_firmwares;
+ firmwares = prueth->icssg_switch_firmwares;
else if (prueth->is_hsr_offload_mode)
- firmwares = icssg_hsr_firmwares;
+ firmwares = prueth->icssg_hsr_firmwares;
else
- firmwares = icssg_emac_firmwares;
+ firmwares = prueth->icssg_emac_firmwares;
for (slice = 0; slice < PRUETH_NUM_MACS; slice++) {
ret = prueth_start(prueth->pru[slice], firmwares[slice].pru);
@@ -1632,6 +1593,87 @@ static void prueth_unregister_notifiers(struct prueth *prueth)
unregister_netdevice_notifier(&prueth->prueth_netdevice_nb);
}
+static void icssg_read_firmware_names(struct device_node *np,
+ struct icssg_firmwares *fw)
+{
+ int i;
+
+ for (i = 0; i < PRUETH_NUM_MACS; i++) {
+ of_property_read_string_index(np, "firmware-name", i * 3 + 0,
+ &fw[i].pru);
+ of_property_read_string_index(np, "firmware-name", i * 3 + 1,
+ &fw[i].rtu);
+ of_property_read_string_index(np, "firmware-name", i * 3 + 2,
+ &fw[i].txpru);
+ }
+}
+
+/* icssg_firmware_name_replace - Replace a substring in firmware name
+ * @dev: device pointer for memory allocation
+ * @src: source firmware name string
+ * @from: substring to replace
+ * @to: replacement substring
+ *
+ * Return: a newly allocated string with the replacement, or the original
+ * string if replacement is not possible.
+ */
+static const char *icssg_firmware_name_replace(struct device *dev,
+ const char *src,
+ const char *from,
+ const char *to)
+{
+ size_t prefix, from_len, to_len, total;
+ const char *p = strstr(src, from);
+ char *buf;
+
+ if (!p)
+ return src; /* fallback: no replacement, use original */
+
+ prefix = p - src;
+ from_len = strlen(from);
+ to_len = strlen(to);
+ total = strlen(src) - from_len + to_len + 1;
+
+ buf = devm_kzalloc(dev, total, GFP_KERNEL);
+ if (!buf)
+ return src; /* fallback: allocation failed, use original */
+
+ strscpy(buf, src, prefix + 1);
+ strscpy(buf + prefix, to, to_len + 1);
+ strscpy(buf + prefix + to_len, p + from_len, total - prefix - to_len);
+
+ return buf;
+}
+
+/**
+ * icssg_mode_firmware_names - Generate firmware names for a specific mode
+ * @dev: device pointer for logging and context
+ * @src: source array of firmware name structures
+ * @dst: destination array to store updated firmware name structures
+ * @from: substring in firmware names to be replaced
+ * @to: substring to replace @from in firmware names
+ *
+ * Iterates over all MACs and replaces occurrences of the @from substring
+ * with @to in the firmware names (pru, rtu, txpru) for each MAC. The
+ * updated firmware names are stored in the @dst array.
+ */
+static void icssg_mode_firmware_names(struct device *dev,
+ struct icssg_firmwares *src,
+ struct icssg_firmwares *dst,
+ const char *from, const char *to)
+{
+ int i;
+
+ for (i = 0; i < PRUETH_NUM_MACS; i++) {
+ dst[i].pru = icssg_firmware_name_replace(dev, src[i].pru,
+ from, to);
+ dst[i].rtu = icssg_firmware_name_replace(dev, src[i].rtu,
+ from, to);
+ dst[i].txpru = icssg_firmware_name_replace(dev, src[i].txpru,
+ from, to);
+ }
+}
+
static int prueth_probe(struct platform_device *pdev)
{
struct device_node *eth_node, *eth_ports_node;
@@ -1808,6 +1850,15 @@ static int prueth_probe(struct platform_device *pdev)
icss_iep_init_fw(prueth->iep1);
}
+ /* Read EMAC firmware names from device tree */
+ icssg_read_firmware_names(np, prueth->icssg_emac_firmwares);
+
+ /* Generate other mode firmware names based on EMAC firmware names */
+ icssg_mode_firmware_names(dev, prueth->icssg_emac_firmwares,
+ prueth->icssg_switch_firmwares, "eth", "sw");
+ icssg_mode_firmware_names(dev, prueth->icssg_emac_firmwares,
+ prueth->icssg_hsr_firmwares, "eth", "hsr");
+
spin_lock_init(&prueth->vtbl_lock);
spin_lock_init(&prueth->stats_lock);
/* setup netdev interfaces */
diff --git a/drivers/net/ethernet/ti/icssg/icssg_prueth.h b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
index 23c465f1ce7f..c03e3b3626c1 100644
--- a/drivers/net/ethernet/ti/icssg/icssg_prueth.h
+++ b/drivers/net/ethernet/ti/icssg/icssg_prueth.h
@@ -259,9 +259,9 @@ struct prueth_pdata {
};
struct icssg_firmwares {
- char *pru;
- char *rtu;
- char *txpru;
+ const char *pru;
+ const char *rtu;
+ const char *txpru;
};
/**
@@ -300,6 +300,9 @@ struct icssg_firmwares {
* @is_switchmode_supported: indicates platform support for switch mode
* @switch_id: ID for mapping switch ports to bridge
* @default_vlan: Default VLAN for host
+ * @icssg_emac_firmwares: Firmware names for EMAC mode, indexed per MAC
+ * @icssg_switch_firmwares: Firmware names for SWITCH mode, indexed per MAC
+ * @icssg_hsr_firmwares: Firmware names for HSR mode, indexed per MAC
*/
struct prueth {
struct device *dev;
@@ -343,6 +346,9 @@ struct prueth {
spinlock_t vtbl_lock;
/** @stats_lock: Lock for reading icssg stats */
spinlock_t stats_lock;
+ struct icssg_firmwares icssg_emac_firmwares[PRUETH_NUM_MACS];
+ struct icssg_firmwares icssg_switch_firmwares[PRUETH_NUM_MACS];
+ struct icssg_firmwares icssg_hsr_firmwares[PRUETH_NUM_MACS];
};
struct emac_tx_ts_response {
base-commit: 2c7e4a2663a1ab5a740c59c31991579b6b865a26
--
2.34.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree
2025-06-10 5:25 [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree MD Danish Anwar
@ 2025-06-12 0:02 ` Jakub Kicinski
2025-06-12 5:19 ` MD Danish Anwar
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-06-12 0:02 UTC (permalink / raw)
To: MD Danish Anwar
Cc: Meghana Malladi, Paolo Abeni, Eric Dumazet, David S. Miller,
Andrew Lunn, linux-kernel, netdev, linux-arm-kernel, srk,
Vignesh Raghavendra, Roger Quadros
On Tue, 10 Jun 2025 10:55:01 +0530 MD Danish Anwar wrote:
> Refactor the way firmware names are handled for the ICSSG PRUETH driver.
> Instead of using hardcoded firmware name arrays for different modes (EMAC,
> SWITCH, HSR), the driver now reads the firmware names from the device tree
> property "firmware-name". Only the EMAC firmware names are specified in the
> device tree property. The firmware names for all other supported modes are
> generated dynamically based on the EMAC firmware names by replacing
> substrings (e.g., "eth" with "sw" or "hsr") as appropriate.
Could you include an example?
> This improves flexibility and allows firmware names to be customized via
> the device tree, reducing the need for code changes when firmware names
> change for different platforms.
You seem to be deleting the old constants. Is there no need to keep
backward compatibility with DT blobs which don't have the firmware-name
properties ?
--
pw-bot: cr
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree
2025-06-12 0:02 ` Jakub Kicinski
@ 2025-06-12 5:19 ` MD Danish Anwar
2025-06-12 14:37 ` Jakub Kicinski
0 siblings, 1 reply; 5+ messages in thread
From: MD Danish Anwar @ 2025-06-12 5:19 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Meghana Malladi, Paolo Abeni, Eric Dumazet, David S. Miller,
Andrew Lunn, linux-kernel, netdev, linux-arm-kernel, srk,
Vignesh Raghavendra, Roger Quadros
Hi Jakub
On 12/06/25 5:32 am, Jakub Kicinski wrote:
> On Tue, 10 Jun 2025 10:55:01 +0530 MD Danish Anwar wrote:
>> Refactor the way firmware names are handled for the ICSSG PRUETH driver.
>> Instead of using hardcoded firmware name arrays for different modes (EMAC,
>> SWITCH, HSR), the driver now reads the firmware names from the device tree
>> property "firmware-name". Only the EMAC firmware names are specified in the
>> device tree property. The firmware names for all other supported modes are
>> generated dynamically based on the EMAC firmware names by replacing
>> substrings (e.g., "eth" with "sw" or "hsr") as appropriate.
>
> Could you include an example?
Sure. Below are the firmwares used currently for PRU0 core
EMAC: ti-pruss/am65x-sr2-pru0-prueth-fw.elf
SW : ti-pruss/am65x-sr2-pru0-prusw-fw.elf
HSR : ti-pruss/am65x-sr2-pru0-pruhsr-fw.elf
If you look closely you'll see the names of all three firmwares are same
except for the operating mode.
In general for PRU0 core, firmware name is,
ti-pruss/am65x-sr2-pru0-pru<mode>-fw.elf
Since the EMAC firmware names are defined in DT, I am reading those
directly and for other modes just swapping mode name. i.e. eth -> sw or
eth -> hsr.
I will add this example in commit msg in next revision.
>
>> This improves flexibility and allows firmware names to be customized via
>> the device tree, reducing the need for code changes when firmware names
>> change for different platforms.
>
> You seem to be deleting the old constants. Is there no need to keep
> backward compatibility with DT blobs which don't have the firmware-name
> properties ?
ICSSG-PRUETH driver is only supported by AM65x and AM64x and both the
DTs have the firmware name property. So I don't think there is any need
to maintain the older hard coded values.
AM65x -
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/arch/arm64/boot/dts/ti/k3-am654-icssg2.dtso#n28:~:text=pru2_1%3E%2C%20%3C%26rtu2_1%3E%2C%20%3C%26tx_pru2_1%3E%3B-,firmware%2Dname,-%3D%20%22ti%2Dpruss/am65x
AM64x -
https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/arch/arm64/boot/dts/ti/k3-am642-evm.dts#:~:text=tx_pru1_1%3E%3B-,firmware%2Dname,-%3D%20%22ti%2Dpruss
Let me know if this is okay.
--
Thanks and Regards,
Danish
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree
2025-06-12 5:19 ` MD Danish Anwar
@ 2025-06-12 14:37 ` Jakub Kicinski
2025-06-13 4:27 ` MD Danish Anwar
0 siblings, 1 reply; 5+ messages in thread
From: Jakub Kicinski @ 2025-06-12 14:37 UTC (permalink / raw)
To: MD Danish Anwar
Cc: Meghana Malladi, Paolo Abeni, Eric Dumazet, David S. Miller,
Andrew Lunn, linux-kernel, netdev, linux-arm-kernel, srk,
Vignesh Raghavendra, Roger Quadros
On Thu, 12 Jun 2025 10:49:17 +0530 MD Danish Anwar wrote:
> > You seem to be deleting the old constants. Is there no need to keep
> > backward compatibility with DT blobs which don't have the firmware-name
> > properties ?
>
> ICSSG-PRUETH driver is only supported by AM65x and AM64x and both the
> DTs have the firmware name property. So I don't think there is any need
> to maintain the older hard coded values.
>
> AM65x -
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/arch/arm64/boot/dts/ti/k3-am654-icssg2.dtso#n28:~:text=pru2_1%3E%2C%20%3C%26rtu2_1%3E%2C%20%3C%26tx_pru2_1%3E%3B-,firmware%2Dname,-%3D%20%22ti%2Dpruss/am65x
>
> AM64x -
> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/arch/arm64/boot/dts/ti/k3-am642-evm.dts#:~:text=tx_pru1_1%3E%3B-,firmware%2Dname,-%3D%20%22ti%2Dpruss
>
> Let me know if this is okay.
IDK much about embedded but what you say sounds convincing to me :)
Just also add that paragraph to the commit msg? (without the links)
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree
2025-06-12 14:37 ` Jakub Kicinski
@ 2025-06-13 4:27 ` MD Danish Anwar
0 siblings, 0 replies; 5+ messages in thread
From: MD Danish Anwar @ 2025-06-13 4:27 UTC (permalink / raw)
To: Jakub Kicinski
Cc: Meghana Malladi, Paolo Abeni, Eric Dumazet, David S. Miller,
Andrew Lunn, linux-kernel, netdev, linux-arm-kernel, srk,
Vignesh Raghavendra, Roger Quadros
On 12/06/25 8:07 pm, Jakub Kicinski wrote:
> On Thu, 12 Jun 2025 10:49:17 +0530 MD Danish Anwar wrote:
>>> You seem to be deleting the old constants. Is there no need to keep
>>> backward compatibility with DT blobs which don't have the firmware-name
>>> properties ?
>>
>> ICSSG-PRUETH driver is only supported by AM65x and AM64x and both the
>> DTs have the firmware name property. So I don't think there is any need
>> to maintain the older hard coded values.
>>
>> AM65x -
>> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/arch/arm64/boot/dts/ti/k3-am654-icssg2.dtso#n28:~:text=pru2_1%3E%2C%20%3C%26rtu2_1%3E%2C%20%3C%26tx_pru2_1%3E%3B-,firmware%2Dname,-%3D%20%22ti%2Dpruss/am65x
>>
>> AM64x -
>> https://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next.git/tree/arch/arm64/boot/dts/ti/k3-am642-evm.dts#:~:text=tx_pru1_1%3E%3B-,firmware%2Dname,-%3D%20%22ti%2Dpruss
>>
>> Let me know if this is okay.
>
> IDK much about embedded but what you say sounds convincing to me :)
> Just also add that paragraph to the commit msg? (without the links)
Sure. Will send out v2 soon with these changes to commit msg.
--
Thanks and Regards,
Danish
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2025-06-13 4:27 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-10 5:25 [PATCH net-next] net: ti: icssg-prueth: Read firmware-names from device tree MD Danish Anwar
2025-06-12 0:02 ` Jakub Kicinski
2025-06-12 5:19 ` MD Danish Anwar
2025-06-12 14:37 ` Jakub Kicinski
2025-06-13 4:27 ` MD Danish Anwar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).