This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a5a59d84e051cac6199934763724b7128f7ede19
Author: Bowen Wang <[email protected]>
AuthorDate: Tue Dec 2 23:24:59 2025 +0800

    drivers/rptun: add RPTUN_AUTO_RESET to choose how the peers are reset
    
    - RPTUN_AUTO_RESET_DISABLE: rptun does not reset the peers by itself;
      rptun_reset() still works.
    - RPTUN_AUTO_RESET_IN_PANIC_NOTIFIER (default): panic the peers from the
      panic notifier, reboot or power them off from the reboot notifier.
      Used when the main core takes the coredump after all peers stopped.
    - RPTUN_AUTO_RESET_IN_REBOOT_NOTIFIER: do everything from the reboot
      notifier, for systems where each core takes its own coredump.
    
    Signed-off-by: Bowen Wang <[email protected]>
---
 drivers/rptun/Kconfig | 23 +++++++++++++++++++++++
 drivers/rptun/rptun.c | 18 ++++++++++++++++++
 2 files changed, 41 insertions(+)

diff --git a/drivers/rptun/Kconfig b/drivers/rptun/Kconfig
index 9c08d01c2d6..c68f68e1a50 100644
--- a/drivers/rptun/Kconfig
+++ b/drivers/rptun/Kconfig
@@ -12,6 +12,29 @@ menuconfig RPTUN
 
 if RPTUN
 
+choice RPTUN_AUTO_RESET
+       prompt "rptun auto reset peer"
+       default RPTUN_AUTO_RESET_IN_PANIC_NOTIFIER
+
+config RPTUN_AUTO_RESET_DISABLE
+       bool "rptun auto reset feature disabled"
+
+config RPTUN_AUTO_RESET_IN_PANIC_NOTIFIER
+       bool "rptun panic other core in panic notifier"
+       ---help---
+               Panic peer in the panic notifier and Reboot/Poweroff peer in
+               the reboot notifier. This mode is used for the case that the
+               main core do the coredump after panic all the peer cores.
+
+config RPTUN_AUTO_RESET_IN_REBOOT_NOTIFIER
+       bool "rptun panic other core in reboot notifier"
+       ---help---
+               Panic/Reboot/Poweroff peer all in the reboot notifier.
+               This mode is used for the case that all the core do its
+               coredump by itself.
+
+endchoice # RPTUN_AUTO_RESET
+
 config RPTUN_BMP
        bool "rptun bmp support"
        default n
diff --git a/drivers/rptun/rptun.c b/drivers/rptun/rptun.c
index e0001928f3a..ffc8dccbd67 100644
--- a/drivers/rptun/rptun.c
+++ b/drivers/rptun/rptun.c
@@ -155,8 +155,10 @@ static void rptun_unmap_buf(FAR struct virtio_device *vdev,
 static void rptun_set_status(FAR struct rptun_priv_s *priv,
                              unsigned long reason);
 
+#ifndef CONFIG_RPTUN_AUTO_RESET_DISABLE
 static int rptun_notifier(FAR struct notifier_block *block,
                           unsigned long action, void *data);
+#endif
 
 /****************************************************************************
  * Private Data
@@ -205,16 +207,20 @@ static const struct virtio_memory_ops g_rptun_mmops =
 static dq_queue_t g_rptun_priv;
 static rmutex_t g_rptun_lock = NXRMUTEX_INITIALIZER;
 
+#ifdef CONFIG_RPTUN_AUTO_RESET_IN_PANIC_NOTIFIER
 static struct notifier_block g_rptun_panic_nb =
 {
   .notifier_call = rptun_notifier,
 };
+#endif
 
+#ifndef CONFIG_RPTUN_AUTO_RESET_DISABLE
 static struct notifier_block g_rptun_reboot_nb =
 {
   .notifier_call = rptun_notifier,
   .priority = INT_MIN, /* Reboot notifier should be called at the last */
 };
+#endif
 
 /****************************************************************************
  * Private Functions
@@ -1362,6 +1368,7 @@ static metal_phys_addr_t rptun_da_to_pa(FAR struct 
rptun_dev_s *dev,
   return pa;
 }
 
+#ifndef CONFIG_RPTUN_AUTO_RESET_DISABLE
 static int rptun_notifier(FAR struct notifier_block *block,
                           unsigned long action, void *data)
 {
@@ -1375,6 +1382,10 @@ static int rptun_notifier(FAR struct notifier_block 
*block,
         }
       else if (action == SYS_HALT)
         {
+#ifdef CONFIG_RPTUN_AUTO_RESET_IN_REBOOT_NOTIFIER
+          rptun_ioctl_foreach(NULL, RPTUNIOC_RESET,
+                              (unsigned long)BOARDIOC_SOFTRESETCAUSE_PANIC);
+#endif
           val = BOARDIOC_SOFTRESETCAUSE_ASSERT;
         }
       else
@@ -1384,14 +1395,17 @@ static int rptun_notifier(FAR struct notifier_block 
*block,
 
       rptun_ioctl_foreach(NULL, RPTUNIOC_RESET, val);
     }
+#ifdef CONFIG_RPTUN_AUTO_RESET_IN_PANIC_NOTIFIER
   else if (action == PANIC_KERNEL_FINAL)
     {
       rptun_ioctl_foreach(NULL, RPTUNIOC_RESET,
                           (unsigned long)BOARDIOC_SOFTRESETCAUSE_PANIC);
     }
+#endif
 
   return 0;
 }
+#endif
 
 /****************************************************************************
  * Public Functions
@@ -1427,8 +1441,12 @@ int rptun_initialize(FAR struct rptun_dev_s *dev)
 
           if (ret >= 0)
             {
+#ifdef CONFIG_RPTUN_AUTO_RESET_IN_PANIC_NOTIFIER
               panic_notifier_chain_register(&g_rptun_panic_nb);
+#endif
+#ifndef CONFIG_RPTUN_AUTO_RESET_DISABLE
               register_reboot_notifier(&g_rptun_reboot_nb);
+#endif
 
               nxrmutex_lock(&g_rptun_lock);
               dq_addlast(&priv->entry, &g_rptun_priv);

Reply via email to