]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: l3: provide probe/remove helpers
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Thu, 25 Jun 2026 08:05:28 +0000 (10:05 +0200)
committerMarkus Stockhausen <markus.stockhausen@gmx.de>
Fri, 26 Jun 2026 16:06:55 +0000 (18:06 +0200)
The L3 code is manually initialized and finalized in the DSA
probe/remove functions. Relocate the code into seperate helpers
that encapsule all required steps. Make no longer exposed L3
functions static.

Link: https://github.com/openwrt/openwrt/pull/23937
Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/common.c
target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c
target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.h

index b72b401d8ec73c249d4eafb3fb1edec131315bf3..75529ac5f5cf16877440270856681304d0525fa4 100644 (file)
@@ -979,29 +979,9 @@ static int rtl83xx_sw_probe(struct platform_device *pdev)
        for (int i = 0; i < 4; i++)
                priv->mirror_group_ports[i] = -1;
 
-       /* Initialize hash table for L3 routing */
-       rhltable_init(&priv->routes, &otto_l3_route_ht_params);
-
-       /* Register netevent notifier callback to catch notifications about neighboring
-        * changes to update nexthop entries for L3 routing.
-        */
-       priv->ne_nb.notifier_call = otto_l3_netevent_notifier;
-       if (register_netevent_notifier(&priv->ne_nb)) {
-               priv->ne_nb.notifier_call = NULL;
-               dev_err(dev, "Failed to register netevent notifier\n");
-               goto err_register_ne_nb;
-       }
-
-       priv->fib_nb.notifier_call = otto_l3_fib_notifier;
-
-       /* Register Forwarding Information Base notifier to offload routes where
-        * possible
-        * Only FIBs pointing to our own netdevs are programmed into
-        * the device, so no need to pass a callback.
-        */
-       err = register_fib_notifier(&init_net, &priv->fib_nb, NULL, NULL);
+       err = otto_l3_probe(dev, priv);
        if (err)
-               goto err_register_fib_nb;
+               goto err_register_l3;
 
        /* TODO: put this into l2_setup() */
        switch (soc_info.family) {
@@ -1026,9 +1006,7 @@ static int rtl83xx_sw_probe(struct platform_device *pdev)
 
        return 0;
 
-err_register_fib_nb:
-       unregister_netevent_notifier(&priv->ne_nb);
-err_register_ne_nb:
+err_register_l3:
        dsa_switch_shutdown(priv->ds);
 err_register_switch:
        destroy_workqueue(priv->wq);
@@ -1075,8 +1053,7 @@ static void rtl83xx_sw_remove(struct platform_device *pdev)
         * work items to avoid them still accessing the DSA structures
         * when they are getting shut down.
         */
-       unregister_fib_notifier(&init_net, &priv->fib_nb);
-       unregister_netevent_notifier(&priv->ne_nb);
+       otto_l3_remove(priv);
        cancel_delayed_work_sync(&priv->counters_work);
 
        dsa_switch_shutdown(priv->ds);
index 7c3dd28be9c0a62a15ec40662978759f48eb9046..6cacf2252e762c45c7014eadd5965f0c855b4825 100644 (file)
@@ -565,7 +565,7 @@ static void otto_l3_fib_event_work_do(struct work_struct *work)
 
 
 /* Called with rcu_read_lock() */
-int otto_l3_fib_notifier(struct notifier_block *this, unsigned long event, void *ptr)
+static int otto_l3_fib_notifier(struct notifier_block *this, unsigned long event, void *ptr)
 {
        struct fib_notifier_info *info = ptr;
        struct rtl838x_switch_priv *priv;
@@ -645,7 +645,7 @@ static void otto_l3_net_event_work_do(struct work_struct *work)
        kfree(net_work);
 }
 
-int otto_l3_netevent_notifier(struct notifier_block *this, unsigned long event, void *ptr)
+static int otto_l3_netevent_notifier(struct notifier_block *this, unsigned long event, void *ptr)
 {
        struct rtl838x_switch_priv *priv;
        struct net_device *dev;
@@ -690,3 +690,49 @@ int otto_l3_netevent_notifier(struct notifier_block *this, unsigned long event,
 
        return NOTIFY_DONE;
 }
+
+void otto_l3_remove(struct rtl838x_switch_priv *priv)
+{
+       if (priv->ne_nb.notifier_call) {
+               unregister_netevent_notifier(&priv->ne_nb);
+               priv->ne_nb.notifier_call = NULL;
+       }
+       if (priv->fib_nb.notifier_call) {
+               unregister_fib_notifier(&init_net, &priv->fib_nb);
+               priv->fib_nb.notifier_call = NULL;
+       }
+}
+
+int otto_l3_probe(struct device *dev, struct rtl838x_switch_priv *priv)
+{
+       int err;
+
+       /* Initialize hash table for L3 routing */
+       rhltable_init(&priv->routes, &otto_l3_route_ht_params);
+
+       /*
+        * Register netevent notifier callback to catch notifications about neighboring changes
+        * to update nexthop entries for L3 routing.
+        */
+       priv->ne_nb.notifier_call = otto_l3_netevent_notifier;
+       err = register_netevent_notifier(&priv->ne_nb);
+       if (err) {
+               priv->ne_nb.notifier_call = NULL;
+               return dev_err_probe(dev, err, "Failed to register netevent notifier\n");
+       }
+
+       /*
+        * Register Forwarding Information Base notifier to offload routes where possible. Only
+        * FIBs pointing to our own netdevs are programmed into the device, so no need to pass a
+        * callback.
+        */
+       priv->fib_nb.notifier_call = otto_l3_fib_notifier;
+       err = register_fib_notifier(&init_net, &priv->fib_nb, NULL, NULL);
+       if (err) {
+               priv->fib_nb.notifier_call = NULL;
+               otto_l3_remove(priv);
+               return dev_err_probe(dev, err, "Failed to register fib event notifier\n");
+       }
+
+       return 0;
+}
index 502579840440aa95e1b480148b7e449dda36de5d..82fcbc8549e1b743e075bdcb5de57390bf931370 100644 (file)
@@ -50,7 +50,7 @@ static const struct rhashtable_params otto_l3_route_ht_params = {
        .head_offset = offsetof(struct otto_l3_route, linkage),
 };
 
-int otto_l3_fib_notifier(struct notifier_block *this, unsigned long event, void *ptr);
-int otto_l3_netevent_notifier(struct notifier_block *this, unsigned long event, void *ptr);
+int otto_l3_probe(struct device *dev, struct rtl838x_switch_priv *priv);
+void otto_l3_remove(struct rtl838x_switch_priv *priv);
 
 #endif /* _OTTO_L3_H */