aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/net/dsa/microchip/ksz_common.c
diff options
context:
space:
mode:
authorTristram Ha <Tristram.Ha@microchip.com>2019-02-22 19:36:51 -0500
committerDavid S. Miller <davem@davemloft.net>2019-02-24 20:49:59 -0500
commit7049f9b5d0529a8fefaae681e57baeb31bd2d40a (patch)
treec26ad7257c1ff015e2f2b9a6bdb55cb67874ea1a /drivers/net/dsa/microchip/ksz_common.c
parent6ca5081526228571a70ef0160fd44da3fe661ccb (diff)
net: dsa: microchip: add port_cleanup function
Add port_cleanup function to reset some device variables when the port is disabled. Add a mutex to make sure changing those variables is thread-safe. Signed-off-by: Tristram Ha <Tristram.Ha@microchip.com> Reviewed-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'drivers/net/dsa/microchip/ksz_common.c')
-rw-r--r--drivers/net/dsa/microchip/ksz_common.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 0589fc7ad09e..d89c97724c35 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -20,6 +20,16 @@
20 20
21#include "ksz_priv.h" 21#include "ksz_priv.h"
22 22
23void ksz_port_cleanup(struct ksz_device *dev, int port)
24{
25 /* Common code for port cleanup. */
26 mutex_lock(&dev->dev_mutex);
27 dev->on_ports &= ~(1 << port);
28 dev->live_ports &= ~(1 << port);
29 mutex_unlock(&dev->dev_mutex);
30}
31EXPORT_SYMBOL_GPL(ksz_port_cleanup);
32
23void ksz_update_port_member(struct ksz_device *dev, int port) 33void ksz_update_port_member(struct ksz_device *dev, int port)
24{ 34{
25 struct ksz_port *p; 35 struct ksz_port *p;
@@ -151,6 +161,13 @@ void ksz_adjust_link(struct dsa_switch *ds, int port,
151 p->read = true; 161 p->read = true;
152 schedule_work(&dev->mib_read); 162 schedule_work(&dev->mib_read);
153 } 163 }
164 mutex_lock(&dev->dev_mutex);
165 if (!phydev->link)
166 dev->live_ports &= ~(1 << port);
167 else
168 /* Remember which port is connected and active. */
169 dev->live_ports |= (1 << port) & dev->on_ports;
170 mutex_unlock(&dev->dev_mutex);
154} 171}
155EXPORT_SYMBOL_GPL(ksz_adjust_link); 172EXPORT_SYMBOL_GPL(ksz_adjust_link);
156 173
@@ -188,7 +205,9 @@ int ksz_port_bridge_join(struct dsa_switch *ds, int port,
188{ 205{
189 struct ksz_device *dev = ds->priv; 206 struct ksz_device *dev = ds->priv;
190 207
208 mutex_lock(&dev->dev_mutex);
191 dev->br_member |= (1 << port); 209 dev->br_member |= (1 << port);
210 mutex_unlock(&dev->dev_mutex);
192 211
193 /* port_stp_state_set() will be called after to put the port in 212 /* port_stp_state_set() will be called after to put the port in
194 * appropriate state so there is no need to do anything. 213 * appropriate state so there is no need to do anything.
@@ -203,8 +222,10 @@ void ksz_port_bridge_leave(struct dsa_switch *ds, int port,
203{ 222{
204 struct ksz_device *dev = ds->priv; 223 struct ksz_device *dev = ds->priv;
205 224
225 mutex_lock(&dev->dev_mutex);
206 dev->br_member &= ~(1 << port); 226 dev->br_member &= ~(1 << port);
207 dev->member &= ~(1 << port); 227 dev->member &= ~(1 << port);
228 mutex_unlock(&dev->dev_mutex);
208 229
209 /* port_stp_state_set() will be called after to put the port in 230 /* port_stp_state_set() will be called after to put the port in
210 * forwarding state so there is no need to do anything. 231 * forwarding state so there is no need to do anything.
@@ -417,6 +438,7 @@ int ksz_switch_register(struct ksz_device *dev,
417 gpiod_set_value(dev->reset_gpio, 0); 438 gpiod_set_value(dev->reset_gpio, 0);
418 } 439 }
419 440
441 mutex_init(&dev->dev_mutex);
420 mutex_init(&dev->reg_mutex); 442 mutex_init(&dev->reg_mutex);
421 mutex_init(&dev->stats_mutex); 443 mutex_init(&dev->stats_mutex);
422 mutex_init(&dev->alu_mutex); 444 mutex_init(&dev->alu_mutex);