]> git.ipfire.org Git - thirdparty/openwrt.git/commitdiff
realtek: l3: move nexthop helper to new struture
authorMarkus Stockhausen <markus.stockhausen@gmx.de>
Sat, 27 Jun 2026 19:16:32 +0000 (21:16 +0200)
committerMarkus Stockhausen <markus.stockhausen@gmx.de>
Sun, 28 Jun 2026 06:46:37 +0000 (08:46 +0200)
Another two layer 3 functions that do not belong into the DSA
space. Move them over to the L3 configuration structure.

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

index 8270a765cd41ee534ea9393a375a46e6e1e664fa..9083ffe0b216bd552611027be2de68d1663902bb 100644 (file)
@@ -95,6 +95,49 @@ static void otto_l3_839x_route_write(struct otto_l3_ctrl *ctrl, int idx, struct
        rtl_table_release(r);
 }
 
+
+/* Destination MAC and L3 egress interface ID of a nexthop entry from the SoC's L3_NEXTHOP table */
+__maybe_unused
+static void otto_l3_930x_get_nexthop(struct otto_l3_ctrl *ctrl,
+                                    int idx, u16 *dmac_id, u16 *interface)
+{
+       struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 3);
+       u32 v;
+
+       rtl_table_read(r, idx);
+       /* The table has a size of 1 register */
+       v = sw_r32(rtl_table_data(r, 0));
+       rtl_table_release(r);
+
+       *dmac_id = (v >> 7) & 0x7fff;
+       *interface = v & 0x7f;
+}
+
+/*
+ * Set the destination MAC and L3 egress interface ID for a nexthop entry in the SoC's L3_NEXTHOP
+ * table. The nexthop entry is identified by idx. dmac_id is the reference to the L2 entry in the
+ * L2 forwarding table, special values are
+ * 0x7ffe: TRAP2CPU
+ * 0x7ffd: TRAP2MASTERCPU
+ * 0x7fff: DMAC_ID_DROP
+ */
+__maybe_unused
+static void otto_l3_930x_set_nexthop(struct otto_l3_ctrl *ctrl,
+                                    int idx, u16 dmac_id, u16 interface)
+{
+       /* Access L3_NEXTHOP table (3) via register RTL9300_TBL_1 */
+       struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 3);
+
+       dev_dbg(ctrl->dev, "Writing to L3_NEXTHOP table, index %d, dmac_id %d, interface %d\n",
+               idx, dmac_id, interface);
+       sw_w32(((dmac_id & 0x7fff) << 7) | (interface & 0x7f), rtl_table_data(r, 0));
+
+       dev_dbg(ctrl->dev, "value at index 0: %08x\n", sw_r32(rtl_table_data(r, 0)));
+       rtl_table_write(r, idx);
+       rtl_table_release(r);
+}
+
+
 /* Read a prefix route entry from the L3_PREFIX_ROUTE_IPUC table
  * We currently only support IPv4 and IPv6 unicast route
  */
@@ -436,8 +479,8 @@ static int otto_l3_nexthop_update(struct otto_l3_ctrl *ctrl, __be32 ip_addr, u64
                        r->pr.fwd_act = PIE_ACT_ROUTE_UC;
                }
 
-               if (priv->r->set_l3_nexthop)
-                       priv->r->set_l3_nexthop(r->nh.id, r->nh.l2_id, r->nh.if_id);
+               if (ctrl->cfg->set_nexthop)
+                       ctrl->cfg->set_nexthop(ctrl, r->nh.id, r->nh.l2_id, r->nh.if_id);
 
                if (r->pr.id < 0) {
                        r->pr.packet_cntr = rtl83xx_packet_cntr_alloc(priv);
@@ -933,6 +976,8 @@ const struct otto_l3_config otto_l3_839x_cfg = {
 
 const struct otto_l3_config otto_l3_930x_cfg = {
 #ifdef CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD
+       .get_nexthop = otto_l3_930x_get_nexthop,
+       .set_nexthop = otto_l3_930x_set_nexthop,
        .route_read = otto_l3_930x_route_read,
        .route_write = otto_l3_930x_route_write,
 #endif
index e92cc47fba7e619310ee0a51d6d61d17b8175b2a..6c8d0e730bbcb1074202c95fd2cd30bd14ed4ace 100644 (file)
@@ -6,6 +6,8 @@
 #include "rtl-otto.h"
 
 struct otto_l3_config {
+       void (*get_nexthop)(struct otto_l3_ctrl *ctrl, int idx, u16 *dmac_id, u16 *interface);
+       void (*set_nexthop)(struct otto_l3_ctrl *ctrl, int idx, u16 dmac_id, u16 interface);
        void (*route_read)(struct otto_l3_ctrl *ctrl, int idx, struct otto_l3_route *rt);
        void (*route_write)(struct otto_l3_ctrl *ctrl, int idx, struct otto_l3_route *rt);
 };
index 6cd5b9aa2c3a75f27f349c196cc9ded9660a1315..36a6641b8bb9a6ab7002eae2457bec07390f791d 100644 (file)
@@ -1439,8 +1439,6 @@ struct rtldsa_config {
        void (*packet_cntr_clear)(int counter);
        void (*host_route_write)(int idx, struct otto_l3_route *rt);
        int (*l3_setup)(struct rtl838x_switch_priv *priv);
-       void (*set_l3_nexthop)(int idx, u16 dmac_id, u16 interface);
-       void (*get_l3_nexthop)(int idx, u16 *dmac_id, u16 *interface);
        u64 (*get_l3_egress_mac)(u32 idx);
        void (*set_l3_egress_mac)(u32 idx, u64 mac);
        int (*find_l3_slot)(struct otto_l3_route *rt, bool must_exist);
index de0cef88b4e09cb0149eb365056a9adbc622a146..fd11e3adfe8a091ed26cc30d910e1997a5f4f9e8 100644 (file)
@@ -1460,24 +1460,6 @@ static int rtl930x_find_l3_slot(struct otto_l3_route *rt, bool must_exist)
        return -1;
 }
 
-/* Get the destination MAC and L3 egress interface ID of a nexthop entry from
- * the SoC's L3_NEXTHOP table
- */
-static void rtl930x_get_l3_nexthop(int idx, u16 *dmac_id, u16 *interface)
-{
-       u32 v;
-       /* Read L3_NEXTHOP table (3) via register RTL9300_TBL_1 */
-       struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 3);
-
-       rtl_table_read(r, idx);
-       /* The table has a size of 1 register */
-       v = sw_r32(rtl_table_data(r, 0));
-       rtl_table_release(r);
-
-       *dmac_id = (v >> 7) & 0x7fff;
-       *interface = v & 0x7f;
-}
-
 // Currently not used
 // static int rtl930x_l3_mtu_del(struct rtl838x_switch_priv *priv, int mtu)
 // {
@@ -1562,27 +1544,6 @@ static void rtl930x_get_l3_nexthop(int idx, u16 *dmac_id, u16 *interface)
 //     }
 // }
 
-/* Set the destination MAC and L3 egress interface ID for a nexthop entry in the SoC's
- * L3_NEXTHOP table. The nexthop entry is identified by idx.
- * dmac_id is the reference to the L2 entry in the L2 forwarding table, special values are
- * 0x7ffe: TRAP2CPU
- * 0x7ffd: TRAP2MASTERCPU
- * 0x7fff: DMAC_ID_DROP
- */
-static void rtl930x_set_l3_nexthop(int idx, u16 dmac_id, u16 interface)
-{
-       /* Access L3_NEXTHOP table (3) via register RTL9300_TBL_1 */
-       struct table_reg *r = rtl_table_get(RTL9300_TBL_1, 3);
-
-       pr_debug("%s: Writing to L3_NEXTHOP table, index %d, dmac_id %d, interface %d\n",
-                __func__, idx, dmac_id, interface);
-       sw_w32(((dmac_id & 0x7fff) << 7) | (interface & 0x7f), rtl_table_data(r, 0));
-
-       pr_debug("%s: %08x\n", __func__, sw_r32(rtl_table_data(r, 0)));
-       rtl_table_write(r, idx);
-       rtl_table_release(r);
-}
-
 #endif /* CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD */
 
 static void rtl930x_pie_lookup_enable(struct rtl838x_switch_priv *priv, int index)
@@ -2742,8 +2703,6 @@ const struct rtldsa_config rtldsa_930x_cfg = {
 #ifdef CONFIG_NET_DSA_RTL83XX_RTL930X_L3_OFFLOAD
        .host_route_write = rtl930x_host_route_write,
        .l3_setup = rtl930x_l3_setup,
-       .set_l3_nexthop = rtl930x_set_l3_nexthop,
-       .get_l3_nexthop = rtl930x_get_l3_nexthop,
        .get_l3_egress_mac = rtl930x_get_l3_egress_mac,
        .set_l3_egress_mac = rtl930x_set_l3_egress_mac,
        .find_l3_slot = rtl930x_find_l3_slot,