| 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 |
| |