[openwrt/openwrt] realtek: eth: move netdev_ops to config structure

LEDE Commits lede-commits at lists.infradead.org
Sun Jan 4 10:06:34 PST 2026


robimarko pushed a commit to openwrt/openwrt.git, branch main:
https://git.openwrt.org/f14fed9a92a651395ae3986dc7441e9dd4f71b7d

commit f14fed9a92a651395ae3986dc7441e9dd4f71b7d
Author: Markus Stockhausen <markus.stockhausen at gmx.de>
AuthorDate: Wed Dec 31 14:49:05 2025 +0100

    realtek: eth: move netdev_ops to config structure
    
    Simplify netdev_ops initialization by moving the data
    into the configuration structure.
    
    Signed-off-by: Markus Stockhausen <markus.stockhausen at gmx.de>
    Link: https://github.com/openwrt/openwrt/pull/21345
    Signed-off-by: Robert Marko <robimarko at gmail.com>
---
 .../files-6.12/drivers/net/ethernet/rtl838x_eth.c  | 34 +++++++---------------
 .../files-6.12/drivers/net/ethernet/rtl838x_eth.h  |  1 +
 2 files changed, 12 insertions(+), 23 deletions(-)

diff --git a/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.c b/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.c
index 0bd55f76d8..ca1caa3e89 100644
--- a/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.c
+++ b/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.c
@@ -1450,7 +1450,7 @@ static struct phylink_pcs *rtl838x_mac_select_pcs(struct phylink_config *config,
 	return &priv->pcs;
 }
 
-static const struct net_device_ops rtl838x_eth_netdev_ops = {
+static const struct net_device_ops rteth_838x_netdev_ops = {
 	.ndo_open = rtl838x_eth_open,
 	.ndo_stop = rtl838x_eth_stop,
 	.ndo_start_xmit = rtl838x_eth_tx,
@@ -1489,9 +1489,10 @@ static const struct rteth_config rteth_838x_cfg = {
 	.update_cntr = rtl838x_update_cntr,
 	.create_tx_header = rtl838x_create_tx_header,
 	.decode_tag = rtl838x_decode_tag,
+	.netdev_ops = &rteth_838x_netdev_ops,
 };
 
-static const struct net_device_ops rtl839x_eth_netdev_ops = {
+static const struct net_device_ops rteth_839x_netdev_ops = {
 	.ndo_open = rtl838x_eth_open,
 	.ndo_stop = rtl838x_eth_stop,
 	.ndo_start_xmit = rtl838x_eth_tx,
@@ -1530,9 +1531,10 @@ static const struct rteth_config rteth_839x_cfg = {
 	.update_cntr = rtl839x_update_cntr,
 	.create_tx_header = rtl839x_create_tx_header,
 	.decode_tag = rtl839x_decode_tag,
+	.netdev_ops = &rteth_839x_netdev_ops,
 };
 
-static const struct net_device_ops rtl930x_eth_netdev_ops = {
+static const struct net_device_ops rteth_930x_netdev_ops = {
 	.ndo_open = rtl838x_eth_open,
 	.ndo_stop = rtl838x_eth_stop,
 	.ndo_start_xmit = rtl838x_eth_tx,
@@ -1577,9 +1579,10 @@ static const struct rteth_config rteth_930x_cfg = {
 	.update_cntr = rtl930x_update_cntr,
 	.create_tx_header = rtl930x_create_tx_header,
 	.decode_tag = rtl930x_decode_tag,
+	.netdev_ops = &rteth_930x_netdev_ops,
 };
 
-static const struct net_device_ops rtl931x_eth_netdev_ops = {
+static const struct net_device_ops rteth_931x_netdev_ops = {
 	.ndo_open = rtl838x_eth_open,
 	.ndo_stop = rtl838x_eth_stop,
 	.ndo_start_xmit = rtl838x_eth_tx,
@@ -1623,6 +1626,7 @@ static const struct rteth_config rteth_931x_cfg = {
 	.update_cntr = rtl931x_update_cntr,
 	.create_tx_header = rtl931x_create_tx_header,
 	.decode_tag = rtl931x_decode_tag,
+	.netdev_ops = &rteth_931x_netdev_ops,
 };
 
 static const struct phylink_pcs_ops rtl838x_pcs_ops = {
@@ -1698,27 +1702,11 @@ static int __init rtl838x_eth_probe(struct platform_device *pdev)
 	dev->max_mtu = DEFAULT_MTU;
 	dev->features = NETIF_F_RXCSUM | NETIF_F_HW_CSUM;
 	dev->hw_features = NETIF_F_RXCSUM;
+	dev->netdev_ops = priv->r->netdev_ops;
 
-	pr_info("Found SoC family %x\n", priv->r->family_id);
-
-	switch (priv->r->family_id) {
-	case RTL8380_FAMILY_ID:
-		dev->netdev_ops = &rtl838x_eth_netdev_ops;
-		break;
-	case RTL8390_FAMILY_ID:
-		dev->netdev_ops = &rtl839x_eth_netdev_ops;
-		break;
-	case RTL9300_FAMILY_ID:
-		dev->netdev_ops = &rtl930x_eth_netdev_ops;
-		break;
-	case RTL9310_FAMILY_ID:
-		dev->netdev_ops = &rtl931x_eth_netdev_ops;
+	if (priv->r->family_id == RTL9310_FAMILY_ID)
 		rtl931x_chip_init(priv);
-		break;
-	default:
-		pr_err("Unknown SoC family\n");
-		return -ENODEV;
-	}
+
 	priv->rxringlen = rxringlen;
 	priv->rxrings = rxrings;
 
diff --git a/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.h b/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.h
index 99f154f0ee..144680f7d7 100644
--- a/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.h
+++ b/target/linux/realtek/files-6.12/drivers/net/ethernet/rtl838x_eth.h
@@ -480,6 +480,7 @@ struct rteth_config {
 	void (*update_cntr)(int r, int work_done);
 	void (*create_tx_header)(struct p_hdr *h, unsigned int dest_port, int prio);
 	bool (*decode_tag)(struct p_hdr *h, struct dsa_tag *tag);
+	const struct net_device_ops *netdev_ops;
 };
 
 #endif /* _RTL838X_ETH_H */




More information about the lede-commits mailing list