[][kernel][common][eth][Add dsa_port_from_netdev API to dsa framework]
[Description]
Add dsa_port_from_netdev API to dsa framework.
This feature is a backport from kernel-5.15 that can assist the
networking driver to get DSA port from netdev pointer.
[Release-log]
N/A
Change-Id: Ic7af8c766224ed7682bde15cdafb26b674b49767
Reviewed-on: https://gerrit.mediatek.inc/c/openwrt/feeds/mtk_openwrt_feeds/+/8345749
diff --git a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch
index 2dc17ae..b9fcd0b 100644
--- a/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch
+++ b/autobuild_mac80211_release/target/linux/mediatek/patches-5.4/999-3001-mt7622-backport-nf-hw-offload-framework-and-upstream.patch
@@ -17,7 +17,6 @@
drivers/net/ppp/pppoe.c | 24 +
include/linux/netdevice.h | 60 +
include/linux/ppp_channel.h | 3 +
- include/net/dsa.h | 10 +
include/net/flow_offload.h | 4 +
include/net/ip6_route.h | 5 +-
.../net/netfilter/ipv6/nf_conntrack_ipv6.h | 3 -
@@ -32,8 +31,7 @@
net/bridge/br_private.h | 20 +
net/bridge/br_vlan.c | 55 +
net/core/dev.c | 46 +
- net/dsa/dsa.c | 9 +
- net/dsa/slave.c | 37 +-
+ net/dsa/slave.c | 36 +-
net/ipv4/netfilter/Kconfig | 4 +-
net/ipv6/ip6_output.c | 2 +-
net/ipv6/netfilter/Kconfig | 3 +-
@@ -48,7 +46,7 @@
net/netfilter/nf_flow_table_ip.c | 447 +++---
net/netfilter/nf_flow_table_offload.c | 1199 +++++++++++++++++
net/netfilter/xt_FLOWOFFLOAD.c | 794 +++++++++++
- 43 files changed, 5005 insertions(+), 435 deletions(-)
+ 41 files changed, 4985 insertions(+), 435 deletions(-)
mode change 100644 => 100755 drivers/net/ethernet/mediatek/Makefile
mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_eth_soc.c
mode change 100644 => 100755 drivers/net/ethernet/mediatek/mtk_eth_soc.h
@@ -2157,34 +2155,6 @@
};
struct ppp_channel {
-diff --git a/include/net/dsa.h b/include/net/dsa.h
-index d29ee9e..43f65cb 100644
---- a/include/net/dsa.h
-+++ b/include/net/dsa.h
-@@ -562,6 +562,8 @@ struct dsa_switch_ops {
- struct sk_buff *skb);
- };
-
-+struct dsa_port *dsa_port_from_netdev(struct net_device *netdev);
-+
- struct dsa_switch_driver {
- struct list_head list;
- const struct dsa_switch_ops *ops;
-@@ -654,6 +656,14 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
- #define BRCM_TAG_GET_PORT(v) ((v) >> 8)
- #define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff)
-
-+#if IS_ENABLED(CONFIG_NET_DSA)
-+bool dsa_slave_dev_check(const struct net_device *dev);
-+#else
-+static inline bool dsa_slave_dev_check(const struct net_device *dev)
-+{
-+ return false;
-+}
-+#endif
-
- netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
- int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
diff --git a/include/net/flow_offload.h b/include/net/flow_offload.h
index c6f7bd2..59b8736 100644
--- a/include/net/flow_offload.h
@@ -2970,26 +2940,6 @@
/**
* __dev_get_by_name - find a device by its name
* @net: the applicable net namespace
-diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
-index ca80f86..35a1249 100644
---- a/net/dsa/dsa.c
-+++ b/net/dsa/dsa.c
-@@ -329,6 +329,15 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev,
- }
- EXPORT_SYMBOL_GPL(call_dsa_notifiers);
-
-+struct dsa_port *dsa_port_from_netdev(struct net_device *netdev)
-+{
-+ if (!netdev || !dsa_slave_dev_check(netdev))
-+ return ERR_PTR(-ENODEV);
-+
-+ return dsa_slave_to_port(netdev);
-+}
-+EXPORT_SYMBOL_GPL(dsa_port_from_netdev);
-+
- static int __init dsa_init_module(void)
- {
- int rc;
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index e2b91b3..2dfaa1e 100644
--- a/net/dsa/slave.c
@@ -3058,14 +3008,6 @@
};
static struct device_type dsa_type = {
-@@ -1499,6 +1533,7 @@ bool dsa_slave_dev_check(const struct net_device *dev)
- {
- return dev->netdev_ops == &dsa_slave_netdev_ops;
- }
-+EXPORT_SYMBOL_GPL(dsa_slave_dev_check);
-
- static int dsa_slave_changeupper(struct net_device *dev,
- struct netdev_notifier_changeupper_info *info)
diff --git a/net/ipv4/netfilter/Kconfig b/net/ipv4/netfilter/Kconfig
index f17b402..803b92e 100644
--- a/net/ipv4/netfilter/Kconfig
diff --git a/target/linux/mediatek/patches-5.4/999-1713-v5.15-net-dsa-add-dsa_port_from_netdev.patch b/target/linux/mediatek/patches-5.4/999-1713-v5.15-net-dsa-add-dsa_port_from_netdev.patch
new file mode 100644
index 0000000..1b3468d
--- /dev/null
+++ b/target/linux/mediatek/patches-5.4/999-1713-v5.15-net-dsa-add-dsa_port_from_netdev.patch
@@ -0,0 +1,74 @@
+From b80c745d2b90b30558e4f5b12060af956ae8e76d Mon Sep 17 00:00:00 2001
+From: Bo Jiao <Bo.Jiao@mediatek.com>
+Date: Mon, 18 Sep 2023 10:52:27 +0800
+Subject: [PATCH] net dsa add dsa_port_from_netdev
+
+---
+ include/net/dsa.h | 10 +
+ net/dsa/dsa.c | 9 +
+ net/dsa/slave.c | 1 +
+ 3 files changed, 20 insertions(+), 0 deletions(-)
+
+diff --git a/include/net/dsa.h b/include/net/dsa.h
+index d29ee9e..43f65cb 100644
+--- a/include/net/dsa.h
++++ b/include/net/dsa.h
+@@ -562,6 +562,8 @@ struct dsa_switch_ops {
+ struct sk_buff *skb);
+ };
+
++struct dsa_port *dsa_port_from_netdev(struct net_device *netdev);
++
+ struct dsa_switch_driver {
+ struct list_head list;
+ const struct dsa_switch_ops *ops;
+@@ -654,6 +656,14 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev,
+ #define BRCM_TAG_GET_PORT(v) ((v) >> 8)
+ #define BRCM_TAG_GET_QUEUE(v) ((v) & 0xff)
+
++#if IS_ENABLED(CONFIG_NET_DSA)
++bool dsa_slave_dev_check(const struct net_device *dev);
++#else
++static inline bool dsa_slave_dev_check(const struct net_device *dev)
++{
++ return false;
++}
++#endif
+
+ netdev_tx_t dsa_enqueue_skb(struct sk_buff *skb, struct net_device *dev);
+ int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);
+diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
+index ca80f86..35a1249 100644
+--- a/net/dsa/dsa.c
++++ b/net/dsa/dsa.c
+@@ -329,6 +329,15 @@ int call_dsa_notifiers(unsigned long val, struct net_device *dev,
+ }
+ EXPORT_SYMBOL_GPL(call_dsa_notifiers);
+
++struct dsa_port *dsa_port_from_netdev(struct net_device *netdev)
++{
++ if (!netdev || !dsa_slave_dev_check(netdev))
++ return ERR_PTR(-ENODEV);
++
++ return dsa_slave_to_port(netdev);
++}
++EXPORT_SYMBOL_GPL(dsa_port_from_netdev);
++
+ static int __init dsa_init_module(void)
+ {
+ int rc;
+diff --git a/net/dsa/slave.c b/net/dsa/slave.c
+index e2b91b3..2dfaa1e 100644
+--- a/net/dsa/slave.c
++++ b/net/dsa/slave.c
+@@ -1499,6 +1533,7 @@ bool dsa_slave_dev_check(const struct net_device *dev)
+ {
+ return dev->netdev_ops == &dsa_slave_netdev_ops;
+ }
++EXPORT_SYMBOL_GPL(dsa_slave_dev_check);
+
+ static int dsa_slave_changeupper(struct net_device *dev,
+ struct netdev_notifier_changeupper_info *info)
+--
+2.18.0
+