From: Markus Stockhausen Date: Thu, 25 Jun 2026 08:05:28 +0000 (+0200) Subject: realtek: l3: provide probe/remove helpers X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=113103739144f7e53eb8236f23d3012f104981f3;p=thirdparty%2Fopenwrt.git realtek: l3: provide probe/remove helpers 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 --- diff --git a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/common.c b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/common.c index b72b401d8ec..75529ac5f5c 100644 --- a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/common.c +++ b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/common.c @@ -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); diff --git a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c index 7c3dd28be9c..6cacf2252e7 100644 --- a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c +++ b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.c @@ -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; +} diff --git a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.h b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.h index 50257984044..82fcbc8549e 100644 --- a/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.h +++ b/target/linux/realtek/files-6.18/drivers/net/dsa/rtl83xx/l3.h @@ -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 */