Reduce coupling between DSA and Broadcom SYSTEMPORT driver
Subsystems (5)
Vladimir Oltean
maintainerv2 cover Reduce coupling between DSA and Broadcom SYSTEMPORT driver
From: Vladimir Oltean <[email protected]>
Upon a quick inspection, it seems that there is some code in the generic DSA layer that is somehow specific to the Broadcom SYSTEMPORT driver. The challenge there is that the hardware integration is very tight between the switch and the DSA master interface. However this does not mean that the drivers must also be as integrated as the hardware is. We can avoid creating a DSA notifier just for the Broadcom SYSTEMPORT, and we can move some Broadcom-specific queue mapping helpers outside of the common include/net/dsa.h.
Vladimir Oltean (4):
net: dsa: move the Broadcom tag information in a separate header file
net: dsa: export dsa_slave_dev_check
net: systemport: use standard netdevice notifier to detect DSA
presence
net: dsa: remove the DSA specific notifiers
MAINTAINERS | 1 + drivers/net/ethernet/broadcom/bcmsysport.c | 82 ++++++++++------------ drivers/net/ethernet/broadcom/bcmsysport.h | 2 +- include/linux/dsa/brcm.h | 16 +++++ include/net/dsa.h | 48 +------------ net/dsa/dsa.c | 22 ------ net/dsa/dsa_priv.h | 1 - net/dsa/slave.c | 18 +---- net/dsa/tag_brcm.c | 1 + 9 files changed, 60 insertions(+), 131 deletions(-) create mode 100644 include/linux/dsa/brcm.h
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 1/4 net: dsa: move the Broadcom tag information in a separate header file
From: Vladimir Oltean <[email protected]>
It is a bit strange to see something as specific as Broadcom SYSTEMPORT bits in the main DSA include file. Move these away into a separate header, and have the tagger and the SYSTEMPORT driver include them.
---
Changes in v2:
None.
MAINTAINERS | 1 + drivers/net/ethernet/broadcom/bcmsysport.c | 1 + include/linux/dsa/brcm.h | 16 ++++++++++++++++ include/net/dsa.h | 6 ------ net/dsa/tag_brcm.c | 1 + 5 files changed, 19 insertions(+), 6 deletions(-) create mode 100644 include/linux/dsa/brcm.h
MAINTAINERS +1 -0
@@ -3400,6 +3400,7 @@ L: [email protected] (subscribers-only) S: Supported F: Documentation/devicetree/bindings/net/dsa/brcm,b53.yaml F: drivers/net/dsa/b53/* +F: include/linux/dsa/brcm.h F: include/linux/platform_data/b53.h BROADCOM BCM2711/BCM2835 ARM ARCHITECTURE
drivers/net/ethernet/broadcom/bcmsysport.c +1 -0
@@ -12,6 +12,7 @@#include <linux/module.h> #include <linux/kernel.h> #include <linux/netdevice.h> +#include <linux/dsa/brcm.h> #include <linux/etherdevice.h> #include <linux/platform_device.h> #include <linux/of.h>
include/linux/dsa/brcm.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0-only +* Copyright (C) 2014 Broadcom Corporation +*/ + +/* Included by drivers/net/ethernet/broadcom/bcmsysport.c and +* net/dsa/tag_brcm.c +*/ +#ifndef _NET_DSA_BRCM_H +#define _NET_DSA_BRCM_H + +/* Broadcom tag specific helpers to insert and extract queue/port number */ +#define BRCM_TAG_SET_PORT_QUEUE (p, q) ((p) << 8 | q) +#define BRCM_TAG_GET_PORT (v) ((v) >> 8) +#define BRCM_TAG_GET_QUEUE (v) ((v) & 0xff) + +#endif
include/net/dsa.h +0 -6
@@ -873,12 +873,6 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev, }#endif -/* Broadcom tag specific helpers to insert and extract queue/port number */ -#define BRCM_TAG_SET_PORT_QUEUE (p, q) ((p) << 8 | q) -#define BRCM_TAG_GET_PORT (v) ((v) >> 8) -#define BRCM_TAG_GET_QUEUE (v) ((v) & 0xff) - -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);int dsa_port_get_ethtool_phy_stats (struct dsa_port *dp,uint64_t *data);
net/dsa/tag_brcm.c +1 -0
@@ -5,6 +5,7 @@* Copyright (C) 2014 Broadcom Corporation */ +#include <linux/dsa/brcm.h> #include <linux/etherdevice.h> #include <linux/list.h> #include <linux/slab.h>
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 2/4 net: dsa: export dsa_slave_dev_check
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
Using the NETDEV_CHANGEUPPER notifications, drivers can be aware when they are enslaved to e.g. a bridge by calling netif_is_bridge_master().
Export this helper from DSA to get the equivalent functionality of determining whether the upper interface of a CHANGEUPPER notifier is a DSA switch interface or not.
---
Changes in v2:
None.
include/net/dsa.h | 6 ++++++ net/dsa/dsa_priv.h | 1 - net/dsa/slave.c | 1 + 3 files changed, 7 insertions(+), 1 deletion(-)
include/net/dsa.h +6 -0
@@ -855,6 +855,7 @@ int register_dsa_notifier(struct notifier_block *nb);int unregister_dsa_notifier (struct notifier_block *nb);int call_dsa_notifiers (unsigned long val,struct net_device *dev,struct dsa_notifier_info *info); +bool dsa_slave_dev_check (const struct net_device *dev);#else static inline int register_dsa_notifier (struct notifier_block *nb) {
@@ -871,6 +872,11 @@ static inline int call_dsa_notifiers(unsigned long val, struct net_device *dev, {return NOTIFY_DONE ; } + +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);
net/dsa/dsa_priv.h +0 -1
@@ -172,7 +172,6 @@ extern const struct dsa_device_ops notag_netdev_ops;void dsa_slave_mii_bus_init (struct dsa_switch *ds);int dsa_slave_create (struct dsa_port *dp);void dsa_slave_destroy (struct net_device *slave_dev); -bool dsa_slave_dev_check (const struct net_device *dev);int dsa_slave_suspend (struct net_device *slave_dev);int dsa_slave_resume (struct net_device *slave_dev);int dsa_slave_register_notifier (void );
net/dsa/slave.c +1 -0
@@ -1924,6 +1924,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)
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 3/4 net: systemport: use standard netdevice notifier to detect DSA presence
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
The SYSTEMPORT driver maps each port of the embedded Broadcom DSA switch port to a certain queue of the master Ethernet controller. For that it currently uses a dedicated notifier infrastructure which was added in commit 60724d4bae14 ("net: dsa: Add support for DSA specific notifiers").
However, since commit 2f1e8ea726e9 ("net: dsa: link interfaces with the DSA master to get rid of lockdep warnings"), DSA is actually an upper of the Broadcom SYSTEMPORT as far as the netdevice adjacency lists are concerned. So naturally, the plain NETDEV_CHANGEUPPER net device notifiers are emitted. It looks like there is enough API exposed by DSA to the outside world already to make the call_dsa_notifiers API redundant. So let's convert its only user to plain netdev notifiers.
---
Changes in v2:
Kept the container_of(nb, struct bcm_sysport_priv, dsa_notifier) in the code, which repairs an issue introduced in v1.
drivers/net/ethernet/broadcom/bcmsysport.c | 81 ++++++++++------------ drivers/net/ethernet/broadcom/bcmsysport.h | 2 +- 2 files changed, 37 insertions(+), 46 deletions(-)
drivers/net/ethernet/broadcom/bcmsysport.c +36 -45
@@ -2311,33 +2311,22 @@ static const struct net_device_ops bcm_sysport_netdev_ops = { .ndo_select_queue = bcm_sysport_select_queue, }; -static int bcm_sysport_map_queues (struct notifier_block *nb, -struct dsa_notifier_register_info *info) +static int bcm_sysport_map_queues (struct net_device *dev, +struct net_device *slave_dev) { +struct dsa_port *dp =dsa_port_from_netdev (slave_dev); +struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring; -struct bcm_sysport_priv *priv; -struct net_device *slave_dev;unsigned int num_tx_queues;unsigned int q, qp, port; -struct net_device *dev; - - priv = container_of(nb, struct bcm_sysport_priv, dsa_notifier); -if (priv->netdev != info->master) -return 0 ; - - dev = info->master;/* We can't be setting up queue inspection for non directly attached * switches */ -if (info->switch_number) +if (dp->ds->index)return 0 ; -if (dev->netdev_ops != &bcm_sysport_netdev_ops) -return 0 ; - - port = info->port_number; - slave_dev = info->info.dev; + port = dp->index;/* On SYSTEMPORT Lite we have twice as less queues, so we cannot do a * 1:1 mapping, we can only do a 2:1 mapping. By reducing the number of
@@ -2377,27 +2366,16 @@ static int bcm_sysport_map_queues(struct notifier_block *nb,return 0 ; } -static int bcm_sysport_unmap_queues (struct notifier_block *nb, -struct dsa_notifier_register_info *info) +static int bcm_sysport_unmap_queues (struct net_device *dev, +struct net_device *slave_dev) { +struct dsa_port *dp =dsa_port_from_netdev (slave_dev); +struct bcm_sysport_priv *priv =netdev_priv (dev);struct bcm_sysport_tx_ring *ring; -struct bcm_sysport_priv *priv; -struct net_device *slave_dev;unsigned int num_tx_queues; -struct net_device *dev;unsigned int q, qp, port; - priv = container_of(nb, struct bcm_sysport_priv, dsa_notifier); -if (priv->netdev != info->master) -return 0 ; - - dev = info->master; - -if (dev->netdev_ops != &bcm_sysport_netdev_ops) -return 0 ; - - port = info->port_number; - slave_dev = info->info.dev; + port = dp->index; num_tx_queues = slave_dev->real_num_tx_queues;
@@ -2418,17 +2396,30 @@ static int bcm_sysport_unmap_queues(struct notifier_block *nb,return 0 ; } -static int bcm_sysport_dsa_notifier (struct notifier_block *nb, -unsigned long event,void *ptr) +static int bcm_sysport_netdevice_event (struct notifier_block *nb, +unsigned long event,void *ptr) { -int ret =NOTIFY_DONE ; +struct net_device *dev =netdev_notifier_info_to_dev (ptr); +struct netdev_notifier_changeupper_info *info = ptr; +struct bcm_sysport_priv *priv; +int ret =0 ; + + priv = container_of(nb, struct bcm_sysport_priv, netdev_notifier); +if (priv->netdev != dev) +return NOTIFY_DONE ;switch (event) { -case DSA_PORT_REGISTER : - ret =bcm_sysport_map_queues (nb, ptr); -break ; -case DSA_PORT_UNREGISTER : - ret =bcm_sysport_unmap_queues (nb, ptr); +case NETDEV_CHANGEUPPER : +if (dev->netdev_ops != &bcm_sysport_netdev_ops) +return NOTIFY_DONE ; + +if (!dsa_slave_dev_check (info->upper_dev)) +return NOTIFY_DONE ; + +if (info->linking) + ret =bcm_sysport_map_queues (dev, info->upper_dev); +else + ret =bcm_sysport_unmap_queues (dev, info->upper_dev);break ; }
@@ -2601,9 +2592,9 @@ static int bcm_sysport_probe(struct platform_device *pdev) priv->rx_max_coalesced_frames =1 ;u64_stats_init (&priv->syncp); - priv->dsa_notifier.notifier_call = bcm_sysport_dsa_notifier; + priv->netdev_notifier.notifier_call = bcm_sysport_netdevice_event; - ret =register_dsa_notifier (&priv->dsa_notifier); + ret =register_netdevice_notifier (&priv->netdev_notifier);if (ret) {dev_err (&pdev->dev,"failed to register DSA notifier\n" ); goto err_deregister_fixed_link;
@@ -2630,7 +2621,7 @@ static int bcm_sysport_probe(struct platform_device *pdev)return 0 ; err_deregister_notifier: -unregister_dsa_notifier (&priv->dsa_notifier); +unregister_netdevice_notifier (&priv->netdev_notifier); err_deregister_fixed_link:if (of_phy_is_fixed_link (dn))of_phy_deregister_fixed_link (dn);
@@ -2648,7 +2639,7 @@ static int bcm_sysport_remove(struct platform_device *pdev)/* Not much to do, ndo_close has been called * and we use managed allocations */ -unregister_dsa_notifier (&priv->dsa_notifier); +unregister_netdevice_notifier (&priv->netdev_notifier);unregister_netdev (dev);if (of_phy_is_fixed_link (dn))of_phy_deregister_fixed_link (dn);
drivers/net/ethernet/broadcom/bcmsysport.h +1 -1
@@ -787,7 +787,7 @@ struct bcm_sysport_priv {struct u64_stats_sync syncp;/* map information between switch port queues and local queues */ -struct notifier_block dsa_notifier; +struct notifier_block netdev_notifier;unsigned int per_port_num_tx_queues;struct bcm_sysport_tx_ring *ring_map[DSA_MAX_PORTS *8 ];
Signature · 1 line
2.25.1
Vladimir Oltean
maintainerPATCH v2 4/4 net: dsa: remove the DSA specific notifiers
In reply to Vladimir OlteanFrom: Vladimir Oltean <[email protected]>
This effectively reverts commit 60724d4bae14 ("net: dsa: Add support for DSA specific notifiers"). The reason is that since commit 2f1e8ea726e9 ("net: dsa: link interfaces with the DSA master to get rid of lockdep warnings"), it appears that there is a generic way to achieve the same purpose. The only user thus far, the Broadcom SYSTEMPORT driver, was converted to use the generic notifiers.
---
Changes in v2:
None.
include/net/dsa.h | 42 ------------------------------------------ net/dsa/dsa.c | 22 ---------------------- net/dsa/slave.c | 17 ----------------- 3 files changed, 81 deletions(-)
include/net/dsa.h +0 -42
@@ -828,51 +828,9 @@ static inline int dsa_switch_resume(struct dsa_switch *ds) }#endif /* CONFIG_PM_SLEEP */ -enum dsa_notifier_type { -DSA_PORT_REGISTER , -DSA_PORT_UNREGISTER , -}; - -struct dsa_notifier_info { -struct net_device *dev; -}; - -struct dsa_notifier_register_info { -struct dsa_notifier_info info;/* must be first */ -struct net_device *master; -unsigned int port_number; -unsigned int switch_number; -}; - -static inline struct net_device * -dsa_notifier_info_to_dev (const struct dsa_notifier_info *info) -{ -return info->dev; -} -#if IS_ENABLED (CONFIG_NET_DSA ) -int register_dsa_notifier (struct notifier_block *nb); -int unregister_dsa_notifier (struct notifier_block *nb); -int call_dsa_notifiers (unsigned long val,struct net_device *dev, -struct dsa_notifier_info *info);bool dsa_slave_dev_check (const struct net_device *dev);#else -static inline int register_dsa_notifier (struct notifier_block *nb) -{ -return 0 ; -} - -static inline int unregister_dsa_notifier (struct notifier_block *nb) -{ -return 0 ; -} - -static inline int call_dsa_notifiers (unsigned long val,struct net_device *dev, -struct dsa_notifier_info *info) -{ -return NOTIFY_DONE ; -} -static inline bool dsa_slave_dev_check (const struct net_device *dev) {return false;
net/dsa/dsa.c +0 -22
@@ -309,28 +309,6 @@ bool dsa_schedule_work(struct work_struct *work)return queue_work (dsa_owq, work); } -static ATOMIC_NOTIFIER_HEAD (dsa_notif_chain); - -int register_dsa_notifier (struct notifier_block *nb) -{ -return atomic_notifier_chain_register (&dsa_notif_chain, nb); -} -EXPORT_SYMBOL_GPL (register_dsa_notifier); - -int unregister_dsa_notifier (struct notifier_block *nb) -{ -return atomic_notifier_chain_unregister (&dsa_notif_chain, nb); -} -EXPORT_SYMBOL_GPL (unregister_dsa_notifier); - -int call_dsa_notifiers (unsigned long val,struct net_device *dev, -struct dsa_notifier_info *info) -{ - info->dev = dev; -return atomic_notifier_call_chain (&dsa_notif_chain, val, info); -} -EXPORT_SYMBOL_GPL (call_dsa_notifiers); -int dsa_devlink_param_get (struct devlink *dl,u32 id,struct devlink_param_gset_ctx *ctx) {
net/dsa/slave.c +0 -17
@@ -1764,20 +1764,6 @@ int dsa_slave_resume(struct net_device *slave_dev)return 0 ; } -static void dsa_slave_notify (struct net_device *dev,unsigned long val) -{ -struct net_device *master =dsa_slave_to_master (dev); -struct dsa_port *dp =dsa_slave_to_port (dev); -struct dsa_notifier_register_info rinfo = { - .switch_number = dp->ds->index, - .port_number = dp->index, - .master = master, - .info.dev = dev, - }; - -call_dsa_notifiers (val, dev, &rinfo.info); -} -int dsa_slave_create (struct dsa_port *port) {const struct dsa_port *cpu_dp = port->cpu_dp;
@@ -1863,8 +1849,6 @@ int dsa_slave_create(struct dsa_port *port) goto out_gcells; } -dsa_slave_notify (slave_dev,DSA_PORT_REGISTER ); -rtnl_lock (); ret =register_netdevice (slave_dev);
@@ -1913,7 +1897,6 @@ void dsa_slave_destroy(struct net_device *slave_dev)phylink_disconnect_phy (dp->pl);rtnl_unlock (); -dsa_slave_notify (slave_dev,DSA_PORT_UNREGISTER );phylink_destroy (dp->pl);gro_cells_destroy (&p->gcells);free_percpu (slave_dev->tstats);
Signature · 1 line
2.25.1
This series was applied to netdev/net-next.git (refs/heads/master):
Hello:
This series was applied to netdev/net-next.git (refs/heads/master):
Quoted 11 lines · On Thu, 7 Jan 2021 03:23:59 +0200 you wrote:
From: Vladimir Oltean <[email protected]>
Upon a quick inspection, it seems that there is some code in the generic DSA layer that is somehow specific to the Broadcom SYSTEMPORT driver. The challenge there is that the hardware integration is very tight between the switch and the DSA master interface. However this does not mean that the drivers must also be as integrated as the hardware is. We can avoid creating a DSA notifier just for the Broadcom SYSTEMPORT, and we can move some Broadcom-specific queue mapping helpers outside of the common
include/net/dsa.h.
Quoted 1 line
[...]
Here is the summary with links:
- [v2,net-next,1/4] net: dsa: move the Broadcom tag information in a separate header file
https://git.kernel.org/netdev/net-next/c/f46b9b8ee89b - [v2,net-next,2/4] net: dsa: export dsa_slave_dev_check https://git.kernel.org/netdev/net-next/c/a5e3c9ba9258 - [v2,net-next,3/4] net: systemport: use standard netdevice notifier to detect DSA presence https://git.kernel.org/netdev/net-next/c/1593cd40d785 - [v2,net-next,4/4] net: dsa: remove the DSA specific notifiers https://git.kernel.org/netdev/net-next/c/1dbb130281c4
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html