* [PATCH net-next 0/8] net: dsa: modular build fixes and improvements
@ 2015-01-12 21:57 Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 1/8] net: dsa: add missing netdevice.h include Florian Fainelli
` (7 more replies)
0 siblings, 8 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
Hi David,
This patch series fixes some problems seen when using DSA as a module. There was
a circular functional dependency which made it impossible to successfully load a
DSA switch driver module, and impossible re-insert it afterwards. Some other
problems appearing where the lack of resource cleanup, leading to various leaks
and -EEXIST errors upon module re-insertion.
Thanks!
Florian Fainelli (8):
net: dsa: add missing netdevice.h include
net: dsa: make module builds work
net: phy: fixed: allow setting no update_link callback
net: dsa: cleanup resources upon module removal
net: dsa: allow switch drivers to cleanup their resources
net: dsa: bcm_sf2: factor interrupt disabling in a function
net: dsa: bcm_sf2: cleanup resources in remove callback
net: dsa: free distributed switch tree pointer in dsa_remove
drivers/net/dsa/bcm_sf2.c | 44 ++++++++++++++++++++--------
drivers/net/phy/fixed_phy.c | 2 +-
include/net/dsa.h | 1 +
net/dsa/Makefile | 2 ++
net/dsa/dsa.c | 71 ++++++++++++++-------------------------------
net/dsa/dsa_lib.c | 68 +++++++++++++++++++++++++++++++++++++++++++
net/dsa/dsa_priv.h | 6 ++++
net/dsa/slave.c | 14 +++++++++
8 files changed, 146 insertions(+), 62 deletions(-)
create mode 100644 net/dsa/dsa_lib.c
--
2.1.0
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH net-next 1/8] net: dsa: add missing netdevice.h include
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 2/8] net: dsa: make module builds work Florian Fainelli
` (6 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
dsa_priv.h contains function prototypes which use a netdev_tx_t return
type, include netdevice.h to get that definition.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/dsa_priv.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index dc9756d3154c..e560ae53996c 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -11,6 +11,7 @@
#ifndef __DSA_PRIV_H
#define __DSA_PRIV_H
+#include <linux/netdevice.h>
#include <linux/phy.h>
#include <linux/netdevice.h>
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 2/8] net: dsa: make module builds work
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 1/8] net: dsa: add missing netdevice.h include Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-13 21:38 ` David Miller
2015-01-12 21:57 ` [PATCH net-next 3/8] net: phy: fixed: allow setting no update_link callback Florian Fainelli
` (5 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
Building any DSA driver as a module will work from a compilation/linking
perspective, but the resulting modules produced are not functional.
Any DSA driver references register_switch_driver and
unregister_switch_driver which are provided by net/dsa/dsa.c, so loading
any of these modules prior to dsa_core.ko being loaded will faill.
Unfortunately, loading dsa_core.ko will make us call dsa_switch_probe()
which will find no DSA switch driver and return an error so we are stuck
there because there is no switch driver available. So this is getting us
nowhere.
This patch introduces a separate module, named dsa_lib which contains
register_switch_driver, unregister_switch_driver and dsa_switch_probe
(to avoid exposing the list and mutex used for walking switch drivers),
such that the following can be done:
- load dsa_lib
- load the dsa switch driver, e.g: mv88e6060, bcm_sf2
- load the dsa_core module
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/Makefile | 2 ++
net/dsa/dsa.c | 49 ---------------------------------------
net/dsa/dsa_lib.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
net/dsa/dsa_priv.h | 4 ++++
4 files changed, 74 insertions(+), 49 deletions(-)
create mode 100644 net/dsa/dsa_lib.c
diff --git a/net/dsa/Makefile b/net/dsa/Makefile
index da06ed1df620..17827194754d 100644
--- a/net/dsa/Makefile
+++ b/net/dsa/Makefile
@@ -2,6 +2,8 @@
obj-$(CONFIG_NET_DSA) += dsa_core.o
dsa_core-y += dsa.o slave.o
+obj-$(CONFIG_NET_DSA) += dsa_lib.o
+
# tagging formats
dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o
dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 37317149f918..de77c83cfd9a 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -26,55 +26,6 @@
char dsa_driver_version[] = "0.1";
-/* switch driver registration ***********************************************/
-static DEFINE_MUTEX(dsa_switch_drivers_mutex);
-static LIST_HEAD(dsa_switch_drivers);
-
-void register_switch_driver(struct dsa_switch_driver *drv)
-{
- mutex_lock(&dsa_switch_drivers_mutex);
- list_add_tail(&drv->list, &dsa_switch_drivers);
- mutex_unlock(&dsa_switch_drivers_mutex);
-}
-EXPORT_SYMBOL_GPL(register_switch_driver);
-
-void unregister_switch_driver(struct dsa_switch_driver *drv)
-{
- mutex_lock(&dsa_switch_drivers_mutex);
- list_del_init(&drv->list);
- mutex_unlock(&dsa_switch_drivers_mutex);
-}
-EXPORT_SYMBOL_GPL(unregister_switch_driver);
-
-static struct dsa_switch_driver *
-dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
-{
- struct dsa_switch_driver *ret;
- struct list_head *list;
- char *name;
-
- ret = NULL;
- name = NULL;
-
- mutex_lock(&dsa_switch_drivers_mutex);
- list_for_each(list, &dsa_switch_drivers) {
- struct dsa_switch_driver *drv;
-
- drv = list_entry(list, struct dsa_switch_driver, list);
-
- name = drv->probe(host_dev, sw_addr);
- if (name != NULL) {
- ret = drv;
- break;
- }
- }
- mutex_unlock(&dsa_switch_drivers_mutex);
-
- *_name = name;
-
- return ret;
-}
-
/* hwmon support ************************************************************/
#ifdef CONFIG_NET_DSA_HWMON
diff --git a/net/dsa/dsa_lib.c b/net/dsa/dsa_lib.c
new file mode 100644
index 000000000000..2c496203c797
--- /dev/null
+++ b/net/dsa/dsa_lib.c
@@ -0,0 +1,68 @@
+/*
+ * net/dsa/dsa_lib.c - Hardware switch handling
+ * Copyright (c) 2008-2009 Marvell Semiconductor
+ * Copyright (c) 2015 Florian Fainelli <florian@openwrt.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ */
+
+#include <linux/list.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <net/dsa.h>
+#include "dsa_priv.h"
+
+/* switch driver registration ***********************************************/
+static DEFINE_MUTEX(dsa_switch_drivers_mutex);
+static LIST_HEAD(dsa_switch_drivers);
+
+void register_switch_driver(struct dsa_switch_driver *drv)
+{
+ mutex_lock(&dsa_switch_drivers_mutex);
+ list_add_tail(&drv->list, &dsa_switch_drivers);
+ mutex_unlock(&dsa_switch_drivers_mutex);
+}
+EXPORT_SYMBOL_GPL(register_switch_driver);
+
+void unregister_switch_driver(struct dsa_switch_driver *drv)
+{
+ mutex_lock(&dsa_switch_drivers_mutex);
+ list_del_init(&drv->list);
+ mutex_unlock(&dsa_switch_drivers_mutex);
+}
+EXPORT_SYMBOL_GPL(unregister_switch_driver);
+
+struct dsa_switch_driver *
+dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name)
+{
+ struct dsa_switch_driver *ret;
+ struct list_head *list;
+ char *name;
+
+ ret = NULL;
+ name = NULL;
+
+ mutex_lock(&dsa_switch_drivers_mutex);
+ list_for_each(list, &dsa_switch_drivers) {
+ struct dsa_switch_driver *drv;
+
+ drv = list_entry(list, struct dsa_switch_driver, list);
+
+ name = drv->probe(host_dev, sw_addr);
+ if (name != NULL) {
+ ret = drv;
+ break;
+ }
+ }
+ mutex_unlock(&dsa_switch_drivers_mutex);
+
+ *_name = name;
+
+ return ret;
+}
+EXPORT_SYMBOL_GPL(dsa_switch_probe);
+
+MODULE_LICENSE("GPL");
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index e560ae53996c..1397b2894c1f 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -51,6 +51,10 @@ struct dsa_slave_priv {
/* dsa.c */
extern char dsa_driver_version[];
+/* dsa_lib.c */
+struct dsa_switch_driver *
+dsa_switch_probe(struct device *host_dev, int sw_addr, char **_name);
+
/* slave.c */
extern const struct dsa_device_ops notag_netdev_ops;
void dsa_slave_mii_bus_init(struct dsa_switch *ds);
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 3/8] net: phy: fixed: allow setting no update_link callback
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 1/8] net: dsa: add missing netdevice.h include Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 2/8] net: dsa: make module builds work Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal Florian Fainelli
` (4 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
fixed_phy_set_link_update() contains an early check against a NULL
callback pointer, which basically prevents us from removing any
previous callback we may have set. The users of the fp->link_update
callback deal with a NULL callback just fine.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/phy/fixed_phy.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/net/phy/fixed_phy.c b/drivers/net/phy/fixed_phy.c
index 3ad0e6e16c39..a08a3c78ba97 100644
--- a/drivers/net/phy/fixed_phy.c
+++ b/drivers/net/phy/fixed_phy.c
@@ -168,7 +168,7 @@ int fixed_phy_set_link_update(struct phy_device *phydev,
struct fixed_mdio_bus *fmb = &platform_fmb;
struct fixed_phy *fp;
- if (!link_update || !phydev || !phydev->bus)
+ if (!phydev || !phydev->bus)
return -EINVAL;
list_for_each_entry(fp, &fmb->phys, node) {
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
` (2 preceding siblings ...)
2015-01-12 21:57 ` [PATCH net-next 3/8] net: phy: fixed: allow setting no update_link callback Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-13 13:31 ` Sergei Shtylyov
2015-01-12 21:57 ` [PATCH net-next 5/8] net: dsa: allow switch drivers to cleanup their resources Florian Fainelli
` (3 subsequent siblings)
7 siblings, 1 reply; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
We were not doing anything while removing the dsa module, which means
that we were leaving dangling network devices without any sort of driver
backing them, leading to all sorts of crashes. Make sure that we do
cleanup the slave network devices, slave MII bus we created, and
unassign the master_netdev dsa_ptr to make the packet processing go
through the regulard Ethernet receive path.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/dsa.c | 19 +++++++++++++++++++
net/dsa/dsa_priv.h | 1 +
net/dsa/slave.c | 14 ++++++++++++++
3 files changed, 34 insertions(+)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index de77c83cfd9a..df7ec066ac64 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -316,10 +316,22 @@ out:
static void dsa_switch_destroy(struct dsa_switch *ds)
{
+ int i;
#ifdef CONFIG_NET_DSA_HWMON
if (ds->hwmon_dev)
hwmon_device_unregister(ds->hwmon_dev);
#endif
+
+ for (i = 0; i < DSA_MAX_PORTS; i++) {
+ if (!(ds->phys_port_mask & (1 << i)))
+ continue;
+
+ dsa_slave_destroy(ds->ports[i]);
+ }
+
+ mdiobus_unregister(ds->slave_mii_bus);
+ mdiobus_free(ds->slave_mii_bus);
+ kfree(ds);
}
#ifdef CONFIG_PM_SLEEP
@@ -754,6 +766,13 @@ static int dsa_remove(struct platform_device *pdev)
dsa_switch_destroy(ds);
}
+ dst->master_netdev->dsa_ptr = NULL;
+ /* If we used a tagging format that doesn't have an ethertype
+ * field, make sure that all packets from this point get sent
+ * without the tag and go through the regular receive path.
+ */
+ wmb();
+
dsa_of_remove(pdev);
return 0;
diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h
index 1397b2894c1f..1773b2a20d90 100644
--- a/net/dsa/dsa_priv.h
+++ b/net/dsa/dsa_priv.h
@@ -61,6 +61,7 @@ void dsa_slave_mii_bus_init(struct dsa_switch *ds);
struct net_device *dsa_slave_create(struct dsa_switch *ds,
struct device *parent,
int port, char *name);
+void dsa_slave_destroy(struct net_device *slave_dev);
int dsa_slave_suspend(struct net_device *slave_dev);
int dsa_slave_resume(struct net_device *slave_dev);
diff --git a/net/dsa/slave.c b/net/dsa/slave.c
index 515569ffde8a..043cffcb1a3a 100644
--- a/net/dsa/slave.c
+++ b/net/dsa/slave.c
@@ -690,3 +690,17 @@ dsa_slave_create(struct dsa_switch *ds, struct device *parent,
return slave_dev;
}
+
+void dsa_slave_destroy(struct net_device *slave_dev)
+{
+ struct dsa_slave_priv *p = netdev_priv(slave_dev);
+
+ if (p->phy) {
+ /* Prevent further updates */
+ fixed_phy_set_link_update(p->phy, NULL);
+ phy_disconnect(p->phy);
+ }
+
+ unregister_netdev(slave_dev);
+ free_netdev(slave_dev);
+}
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 5/8] net: dsa: allow switch drivers to cleanup their resources
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
` (3 preceding siblings ...)
2015-01-12 21:57 ` [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 6/8] net: dsa: bcm_sf2: factor interrupt disabling in a function Florian Fainelli
` (2 subsequent siblings)
7 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
Some switch drivers might request interrupts, remap register ranges,
allow such drivers to implement a "remove" callback doing just that.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
include/net/dsa.h | 1 +
net/dsa/dsa.c | 2 ++
2 files changed, 3 insertions(+)
diff --git a/include/net/dsa.h b/include/net/dsa.h
index ed3c34bbb67a..cace02a4cbdd 100644
--- a/include/net/dsa.h
+++ b/include/net/dsa.h
@@ -192,6 +192,7 @@ struct dsa_switch_driver {
*/
char *(*probe)(struct device *host_dev, int sw_addr);
int (*setup)(struct dsa_switch *ds);
+ void (*remove)(struct dsa_switch *ds);
int (*set_addr)(struct dsa_switch *ds, u8 *addr);
u32 (*get_phy_flags)(struct dsa_switch *ds, int port);
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index df7ec066ac64..008a1a58cf0c 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -331,6 +331,8 @@ static void dsa_switch_destroy(struct dsa_switch *ds)
mdiobus_unregister(ds->slave_mii_bus);
mdiobus_free(ds->slave_mii_bus);
+ if (ds->drv->remove)
+ ds->drv->remove(ds);
kfree(ds);
}
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 6/8] net: dsa: bcm_sf2: factor interrupt disabling in a function
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
` (4 preceding siblings ...)
2015-01-12 21:57 ` [PATCH net-next 5/8] net: dsa: allow switch drivers to cleanup their resources Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 7/8] net: dsa: bcm_sf2: cleanup resources in remove callback Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 8/8] net: dsa: free distributed switch tree pointer in dsa_remove Florian Fainelli
7 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
Factor the interrupt disabling in a function: bcm_sf2_intr_disable()
since we are doing the same thing in the setup and suspend paths.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/bcm_sf2.c | 24 ++++++++++++------------
1 file changed, 12 insertions(+), 12 deletions(-)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index feb29c4526f7..09f6b3cc1f66 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -400,6 +400,16 @@ static int bcm_sf2_sw_rst(struct bcm_sf2_priv *priv)
return 0;
}
+static void bcm_sf2_intr_disable(struct bcm_sf2_priv *priv)
+{
+ intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
+ intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
+ intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+ intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
+ intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
+ intrl2_1_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+}
+
static int bcm_sf2_sw_setup(struct dsa_switch *ds)
{
const char *reg_names[BCM_SF2_REGS_NUM] = BCM_SF2_REGS_NAME;
@@ -440,12 +450,7 @@ static int bcm_sf2_sw_setup(struct dsa_switch *ds)
}
/* Disable all interrupts and request them */
- intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
- intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
- intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
- intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
- intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
- intrl2_1_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+ bcm_sf2_intr_disable(priv);
ret = request_irq(priv->irq0, bcm_sf2_switch_0_isr, 0,
"switch_0", priv);
@@ -747,12 +752,7 @@ static int bcm_sf2_sw_suspend(struct dsa_switch *ds)
struct bcm_sf2_priv *priv = ds_to_priv(ds);
unsigned int port;
- intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
- intrl2_0_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
- intrl2_0_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
- intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_MASK_SET);
- intrl2_1_writel(priv, 0xffffffff, INTRL2_CPU_CLEAR);
- intrl2_1_writel(priv, 0, INTRL2_CPU_MASK_CLEAR);
+ bcm_sf2_intr_disable(priv);
/* Disable all ports physically present including the IMP
* port, the other ones have already been disabled during
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 7/8] net: dsa: bcm_sf2: cleanup resources in remove callback
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
` (5 preceding siblings ...)
2015-01-12 21:57 ` [PATCH net-next 6/8] net: dsa: bcm_sf2: factor interrupt disabling in a function Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 8/8] net: dsa: free distributed switch tree pointer in dsa_remove Florian Fainelli
7 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
Implement a remove callback allowing the switch driver to cleanup
resources it used: interrupts and remapped register ranges.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
drivers/net/dsa/bcm_sf2.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c
index 09f6b3cc1f66..a41b20c7d602 100644
--- a/drivers/net/dsa/bcm_sf2.c
+++ b/drivers/net/dsa/bcm_sf2.c
@@ -526,6 +526,25 @@ out_unmap:
return ret;
}
+static void bcm_sf2_sw_remove(struct dsa_switch *ds)
+{
+ struct bcm_sf2_priv *priv = ds_to_priv(ds);
+ void __iomem **base;
+ unsigned int i;
+
+ /* Disable all interrupts and free them */
+ bcm_sf2_intr_disable(priv);
+
+ free_irq(priv->irq0, priv);
+ free_irq(priv->irq1, priv);
+
+ base = &priv->core;
+ for (i = 0; i < BCM_SF2_REGS_NUM; i++) {
+ iounmap(*base);
+ base++;
+ }
+}
+
static int bcm_sf2_sw_set_addr(struct dsa_switch *ds, u8 *addr)
{
return 0;
@@ -858,6 +877,7 @@ static struct dsa_switch_driver bcm_sf2_switch_driver = {
.tag_protocol = DSA_TAG_PROTO_BRCM,
.priv_size = sizeof(struct bcm_sf2_priv),
.probe = bcm_sf2_sw_probe,
+ .remove = bcm_sf2_sw_remove,
.setup = bcm_sf2_sw_setup,
.set_addr = bcm_sf2_sw_set_addr,
.get_phy_flags = bcm_sf2_sw_get_phy_flags,
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH net-next 8/8] net: dsa: free distributed switch tree pointer in dsa_remove
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
` (6 preceding siblings ...)
2015-01-12 21:57 ` [PATCH net-next 7/8] net: dsa: bcm_sf2: cleanup resources in remove callback Florian Fainelli
@ 2015-01-12 21:57 ` Florian Fainelli
7 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-12 21:57 UTC (permalink / raw)
To: netdev; +Cc: davem, buytenh, Florian Fainelli
We allocate a "dst" pointer in dsa_probe(), but we are not freeing it
accordingly in dsa_remove(), do that to avoid leaking it.
Fixes: 91da11f870f00 ("net: Distributed Switch Architecture protocol support")
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
net/dsa/dsa.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
index 008a1a58cf0c..b511713b8885 100644
--- a/net/dsa/dsa.c
+++ b/net/dsa/dsa.c
@@ -776,6 +776,7 @@ static int dsa_remove(struct platform_device *pdev)
wmb();
dsa_of_remove(pdev);
+ kfree(dst);
return 0;
}
--
2.1.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal
2015-01-12 21:57 ` [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal Florian Fainelli
@ 2015-01-13 13:31 ` Sergei Shtylyov
0 siblings, 0 replies; 12+ messages in thread
From: Sergei Shtylyov @ 2015-01-13 13:31 UTC (permalink / raw)
To: Florian Fainelli, netdev; +Cc: davem, buytenh
Hello.
On 1/13/2015 12:57 AM, Florian Fainelli wrote:
> We were not doing anything while removing the dsa module, which means
> that we were leaving dangling network devices without any sort of driver
> backing them, leading to all sorts of crashes. Make sure that we do
> cleanup the slave network devices, slave MII bus we created, and
> unassign the master_netdev dsa_ptr to make the packet processing go
> through the regulard Ethernet receive path.
Regular. :-)
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
[...]
> diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c
> index de77c83cfd9a..df7ec066ac64 100644
> --- a/net/dsa/dsa.c
> +++ b/net/dsa/dsa.c
> @@ -316,10 +316,22 @@ out:
>
> static void dsa_switch_destroy(struct dsa_switch *ds)
> {
> + int i;
Need empty line here.
> #ifdef CONFIG_NET_DSA_HWMON
> if (ds->hwmon_dev)
> hwmon_device_unregister(ds->hwmon_dev);
> #endif
[...]
WBR, Sergei
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/8] net: dsa: make module builds work
2015-01-12 21:57 ` [PATCH net-next 2/8] net: dsa: make module builds work Florian Fainelli
@ 2015-01-13 21:38 ` David Miller
2015-01-13 22:27 ` Florian Fainelli
0 siblings, 1 reply; 12+ messages in thread
From: David Miller @ 2015-01-13 21:38 UTC (permalink / raw)
To: f.fainelli; +Cc: netdev, buytenh
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Mon, 12 Jan 2015 13:57:40 -0800
> Building any DSA driver as a module will work from a compilation/linking
> perspective, but the resulting modules produced are not functional.
>
> Any DSA driver references register_switch_driver and
> unregister_switch_driver which are provided by net/dsa/dsa.c, so loading
> any of these modules prior to dsa_core.ko being loaded will faill.
>
> Unfortunately, loading dsa_core.ko will make us call dsa_switch_probe()
> which will find no DSA switch driver and return an error so we are stuck
> there because there is no switch driver available. So this is getting us
> nowhere.
>
> This patch introduces a separate module, named dsa_lib which contains
> register_switch_driver, unregister_switch_driver and dsa_switch_probe
> (to avoid exposing the list and mutex used for walking switch drivers),
> such that the following can be done:
>
> - load dsa_lib
> - load the dsa switch driver, e.g: mv88e6060, bcm_sf2
> - load the dsa_core module
>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
This looks worse to me.
Really, the match table and probing should not be in dsa_core at all.
It should only be done in individual drivers.
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH net-next 2/8] net: dsa: make module builds work
2015-01-13 21:38 ` David Miller
@ 2015-01-13 22:27 ` Florian Fainelli
0 siblings, 0 replies; 12+ messages in thread
From: Florian Fainelli @ 2015-01-13 22:27 UTC (permalink / raw)
To: David Miller; +Cc: netdev, buytenh
On 13/01/15 13:38, David Miller wrote:
> From: Florian Fainelli <f.fainelli@gmail.com>
> Date: Mon, 12 Jan 2015 13:57:40 -0800
>
>> Building any DSA driver as a module will work from a compilation/linking
>> perspective, but the resulting modules produced are not functional.
>>
>> Any DSA driver references register_switch_driver and
>> unregister_switch_driver which are provided by net/dsa/dsa.c, so loading
>> any of these modules prior to dsa_core.ko being loaded will faill.
>>
>> Unfortunately, loading dsa_core.ko will make us call dsa_switch_probe()
>> which will find no DSA switch driver and return an error so we are stuck
>> there because there is no switch driver available. So this is getting us
>> nowhere.
>>
>> This patch introduces a separate module, named dsa_lib which contains
>> register_switch_driver, unregister_switch_driver and dsa_switch_probe
>> (to avoid exposing the list and mutex used for walking switch drivers),
>> such that the following can be done:
>>
>> - load dsa_lib
>> - load the dsa switch driver, e.g: mv88e6060, bcm_sf2
>> - load the dsa_core module
>>
>> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
>
> This looks worse to me.
>
> Really, the match table and probing should not be in dsa_core at all.
>
> It should only be done in individual drivers.
Right, I guess enough procrastination on my side is enough, time to get
this plan submitted: http://marc.info/?t=141038714600002&r=1&w=2.
--
Florian
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2015-01-13 22:27 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-01-12 21:57 [PATCH net-next 0/8] net: dsa: modular build fixes and improvements Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 1/8] net: dsa: add missing netdevice.h include Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 2/8] net: dsa: make module builds work Florian Fainelli
2015-01-13 21:38 ` David Miller
2015-01-13 22:27 ` Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 3/8] net: phy: fixed: allow setting no update_link callback Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 4/8] net: dsa: cleanup resources upon module removal Florian Fainelli
2015-01-13 13:31 ` Sergei Shtylyov
2015-01-12 21:57 ` [PATCH net-next 5/8] net: dsa: allow switch drivers to cleanup their resources Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 6/8] net: dsa: bcm_sf2: factor interrupt disabling in a function Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 7/8] net: dsa: bcm_sf2: cleanup resources in remove callback Florian Fainelli
2015-01-12 21:57 ` [PATCH net-next 8/8] net: dsa: free distributed switch tree pointer in dsa_remove Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).