* [PATCH net-next v2] net: macb: Add shutdown operation support
@ 2025-06-07 7:57 Abin Joseph
2025-06-07 12:28 ` Claudiu Beznea
2025-06-09 21:20 ` Jakub Kicinski
0 siblings, 2 replies; 4+ messages in thread
From: Abin Joseph @ 2025-06-07 7:57 UTC (permalink / raw)
To: nicolas.ferre, claudiu.beznea, andrew+netdev, davem, edumazet,
kuba, pabeni
Cc: git, abin.joseph, netdev, linux-kernel
Implement the shutdown hook to ensure clean and complete deactivation of
MACB controller. The shutdown sequence is protected with 'rtnl_lock()'
to serialize access and prevent race conditions while detaching and
closing the network device. This ensure a safe transition when the Kexec
utility calls the shutdown hook, facilitating seamless loading and
booting of a new kernel from the currently running one.
Signed-off-by: Abin Joseph <abin.joseph@amd.com>
---
Changes in v2:
Update the commit description
Update the code to call the close only when admin is up
---
drivers/net/ethernet/cadence/macb_main.c | 14 ++++++++++++++
1 file changed, 14 insertions(+)
diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
index e1e8bd2ec155..5bb08f518d54 100644
--- a/drivers/net/ethernet/cadence/macb_main.c
+++ b/drivers/net/ethernet/cadence/macb_main.c
@@ -5650,6 +5650,19 @@ static int __maybe_unused macb_runtime_resume(struct device *dev)
return 0;
}
+static void macb_shutdown(struct platform_device *pdev)
+{
+ struct net_device *netdev = platform_get_drvdata(pdev);
+
+ rtnl_lock();
+ netif_device_detach(netdev);
+
+ if (netif_running(netdev))
+ dev_close(netdev);
+
+ rtnl_unlock();
+}
+
static const struct dev_pm_ops macb_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(macb_suspend, macb_resume)
SET_RUNTIME_PM_OPS(macb_runtime_suspend, macb_runtime_resume, NULL)
@@ -5663,6 +5676,7 @@ static struct platform_driver macb_driver = {
.of_match_table = of_match_ptr(macb_dt_ids),
.pm = &macb_pm_ops,
},
+ .shutdown = macb_shutdown,
};
module_platform_driver(macb_driver);
--
2.34.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net: macb: Add shutdown operation support
2025-06-07 7:57 [PATCH net-next v2] net: macb: Add shutdown operation support Abin Joseph
@ 2025-06-07 12:28 ` Claudiu Beznea
2025-06-07 16:24 ` Heiner Kallweit
2025-06-09 21:20 ` Jakub Kicinski
1 sibling, 1 reply; 4+ messages in thread
From: Claudiu Beznea @ 2025-06-07 12:28 UTC (permalink / raw)
To: Abin Joseph, nicolas.ferre, andrew+netdev, davem, edumazet, kuba,
pabeni
Cc: git, netdev, linux-kernel
Hi, Abin,
On 07.06.2025 10:57, Abin Joseph wrote:
> Implement the shutdown hook to ensure clean and complete deactivation of
> MACB controller. The shutdown sequence is protected with 'rtnl_lock()'
> to serialize access and prevent race conditions while detaching and
> closing the network device. This ensure a safe transition when the Kexec
> utility calls the shutdown hook, facilitating seamless loading and
> booting of a new kernel from the currently running one.
>
> Signed-off-by: Abin Joseph <abin.joseph@amd.com>
> ---
>
> Changes in v2:
> Update the commit description
> Update the code to call the close only when admin is up
>
> ---
> drivers/net/ethernet/cadence/macb_main.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
> index e1e8bd2ec155..5bb08f518d54 100644
> --- a/drivers/net/ethernet/cadence/macb_main.c
> +++ b/drivers/net/ethernet/cadence/macb_main.c
> @@ -5650,6 +5650,19 @@ static int __maybe_unused macb_runtime_resume(struct device *dev)
> return 0;
> }
>
> +static void macb_shutdown(struct platform_device *pdev)
> +{
> + struct net_device *netdev = platform_get_drvdata(pdev);
> +
> + rtnl_lock();
> + netif_device_detach(netdev);
> +
> + if (netif_running(netdev))
> + dev_close(netdev);
Apart from closing the interface should we also invoke the remove?
Consider the new loaded kernel will not use this interface and some
hardware resources may remain on while not used by the newly loaded kernel.
E.g., there is this code in macb_remove():
if (!pm_runtime_suspended(&pdev->dev)) {
macb_clks_disable(bp->pclk, bp->hclk, bp->tx_clk,
bp->rx_clk, bp->tsu_clk);
pm_runtime_set_suspended(&pdev->dev);
}
Thank you,
Claudiu
> +
> + rtnl_unlock();
> +}
> +
> static const struct dev_pm_ops macb_pm_ops = {
> SET_SYSTEM_SLEEP_PM_OPS(macb_suspend, macb_resume)
> SET_RUNTIME_PM_OPS(macb_runtime_suspend, macb_runtime_resume, NULL)
> @@ -5663,6 +5676,7 @@ static struct platform_driver macb_driver = {
> .of_match_table = of_match_ptr(macb_dt_ids),
> .pm = &macb_pm_ops,
> },
> + .shutdown = macb_shutdown,
> };
>
> module_platform_driver(macb_driver);
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net: macb: Add shutdown operation support
2025-06-07 12:28 ` Claudiu Beznea
@ 2025-06-07 16:24 ` Heiner Kallweit
0 siblings, 0 replies; 4+ messages in thread
From: Heiner Kallweit @ 2025-06-07 16:24 UTC (permalink / raw)
To: Claudiu Beznea, Abin Joseph, nicolas.ferre, andrew+netdev, davem,
edumazet, kuba, pabeni
Cc: git, netdev, linux-kernel
On 07.06.2025 14:28, Claudiu Beznea wrote:
> Hi, Abin,
>
> On 07.06.2025 10:57, Abin Joseph wrote:
>> Implement the shutdown hook to ensure clean and complete deactivation of
>> MACB controller. The shutdown sequence is protected with 'rtnl_lock()'
>> to serialize access and prevent race conditions while detaching and
>> closing the network device. This ensure a safe transition when the Kexec
>> utility calls the shutdown hook, facilitating seamless loading and
>> booting of a new kernel from the currently running one.
>>
>> Signed-off-by: Abin Joseph <abin.joseph@amd.com>
>> ---
>>
>> Changes in v2:
>> Update the commit description
>> Update the code to call the close only when admin is up
>>
>> ---
>> drivers/net/ethernet/cadence/macb_main.c | 14 ++++++++++++++
>> 1 file changed, 14 insertions(+)
>>
>> diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
>> index e1e8bd2ec155..5bb08f518d54 100644
>> --- a/drivers/net/ethernet/cadence/macb_main.c
>> +++ b/drivers/net/ethernet/cadence/macb_main.c
>> @@ -5650,6 +5650,19 @@ static int __maybe_unused macb_runtime_resume(struct device *dev)
>> return 0;
>> }
>>
>> +static void macb_shutdown(struct platform_device *pdev)
>> +{
>> + struct net_device *netdev = platform_get_drvdata(pdev);
>> +
>> + rtnl_lock();
>> + netif_device_detach(netdev);
>> +
>> + if (netif_running(netdev))
>> + dev_close(netdev);
>
> Apart from closing the interface should we also invoke the remove?
>
As part of closing the interface dev_close() sends notifiers.
I don't think that's something we want during shutdown.
Typically the shutdown() callback just has to quiesce the device.
> Consider the new loaded kernel will not use this interface and some
> hardware resources may remain on while not used by the newly loaded kernel.
>
> E.g., there is this code in macb_remove():
>
> if (!pm_runtime_suspended(&pdev->dev)) {
> macb_clks_disable(bp->pclk, bp->hclk, bp->tx_clk,
> bp->rx_clk, bp->tsu_clk);
> pm_runtime_set_suspended(&pdev->dev);
> }
>
>
> Thank you,
> Claudiu
>
>> +
>> + rtnl_unlock();
>> +}
>> +
>> static const struct dev_pm_ops macb_pm_ops = {
>> SET_SYSTEM_SLEEP_PM_OPS(macb_suspend, macb_resume)
>> SET_RUNTIME_PM_OPS(macb_runtime_suspend, macb_runtime_resume, NULL)
>> @@ -5663,6 +5676,7 @@ static struct platform_driver macb_driver = {
>> .of_match_table = of_match_ptr(macb_dt_ids),
>> .pm = &macb_pm_ops,
>> },
>> + .shutdown = macb_shutdown,
>> };
>>
>> module_platform_driver(macb_driver);
>
>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net: macb: Add shutdown operation support
2025-06-07 7:57 [PATCH net-next v2] net: macb: Add shutdown operation support Abin Joseph
2025-06-07 12:28 ` Claudiu Beznea
@ 2025-06-09 21:20 ` Jakub Kicinski
1 sibling, 0 replies; 4+ messages in thread
From: Jakub Kicinski @ 2025-06-09 21:20 UTC (permalink / raw)
To: Abin Joseph
Cc: nicolas.ferre, claudiu.beznea, andrew+netdev, davem, edumazet,
pabeni, git, netdev, linux-kernel
On Sat, 7 Jun 2025 13:27:13 +0530 Abin Joseph wrote:
> + rtnl_lock();
> + netif_device_detach(netdev);
> +
> + if (netif_running(netdev))
> + dev_close(netdev);
> +
> + rtnl_unlock();
nit: could you move the netif_device_detach() after
the dev_close() call? It feels a little backwards, even
tho I think it will work just fine with current code.
Also nit2: you added an empty line before the unlock
but not after lock?
--
pw-bot: cr
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-06-09 21:20 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-07 7:57 [PATCH net-next v2] net: macb: Add shutdown operation support Abin Joseph
2025-06-07 12:28 ` Claudiu Beznea
2025-06-07 16:24 ` Heiner Kallweit
2025-06-09 21:20 ` Jakub Kicinski
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).