Commit 74c6042a authored by David S. Miller's avatar David S. Miller

Merge branch 'dsa-port-enabling'

Vivien Didelot says:

====================
net: dsa: port enabling

This patchset makes slave open and close symmetrical and provides
helpers for enabling or disabling a given DSA port.

Changes in v3:
  - save the phy_device change for a future patchset

Changes in v2:
  - do not remove the phy argument from port enable/disable
====================
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents 6450f8f2 fb8a6a2b
......@@ -117,7 +117,8 @@ void dsa_master_ethtool_restore(struct net_device *dev);
/* port.c */
int dsa_port_set_state(struct dsa_port *dp, u8 state,
struct switchdev_trans *trans);
void dsa_port_set_state_now(struct dsa_port *dp, u8 state);
int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy);
void dsa_port_disable(struct dsa_port *dp, struct phy_device *phy);
int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br);
void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br);
int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,
......
......@@ -56,7 +56,7 @@ int dsa_port_set_state(struct dsa_port *dp, u8 state,
return 0;
}
void dsa_port_set_state_now(struct dsa_port *dp, u8 state)
static void dsa_port_set_state_now(struct dsa_port *dp, u8 state)
{
int err;
......@@ -65,6 +65,35 @@ void dsa_port_set_state_now(struct dsa_port *dp, u8 state)
pr_err("DSA: failed to set STP state %u (%d)\n", state, err);
}
int dsa_port_enable(struct dsa_port *dp, struct phy_device *phy)
{
u8 stp_state = dp->bridge_dev ? BR_STATE_BLOCKING : BR_STATE_FORWARDING;
struct dsa_switch *ds = dp->ds;
int port = dp->index;
int err;
if (ds->ops->port_enable) {
err = ds->ops->port_enable(ds, port, phy);
if (err)
return err;
}
dsa_port_set_state_now(dp, stp_state);
return 0;
}
void dsa_port_disable(struct dsa_port *dp, struct phy_device *phy)
{
struct dsa_switch *ds = dp->ds;
int port = dp->index;
dsa_port_set_state_now(dp, BR_STATE_DISABLED);
if (ds->ops->port_disable)
ds->ops->port_disable(ds, port, phy);
}
int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br)
{
struct dsa_notifier_bridge_info info = {
......
......@@ -73,9 +73,7 @@ static int dsa_slave_open(struct net_device *dev)
{
struct dsa_slave_priv *p = netdev_priv(dev);
struct dsa_port *dp = p->dp;
struct dsa_switch *ds = dp->ds;
struct net_device *master = dsa_master_netdev(p);
u8 stp_state = dp->bridge_dev ? BR_STATE_BLOCKING : BR_STATE_FORWARDING;
int err;
if (!(master->flags & IFF_UP))
......@@ -98,13 +96,9 @@ static int dsa_slave_open(struct net_device *dev)
goto clear_allmulti;
}
if (ds->ops->port_enable) {
err = ds->ops->port_enable(ds, p->dp->index, p->phy);
if (err)
goto clear_promisc;
}
dsa_port_set_state_now(p->dp, stp_state);
err = dsa_port_enable(dp, p->phy);
if (err)
goto clear_promisc;
if (p->phy)
phy_start(p->phy);
......@@ -128,11 +122,13 @@ static int dsa_slave_close(struct net_device *dev)
{
struct dsa_slave_priv *p = netdev_priv(dev);
struct net_device *master = dsa_master_netdev(p);
struct dsa_switch *ds = p->dp->ds;
struct dsa_port *dp = p->dp;
if (p->phy)
phy_stop(p->phy);
dsa_port_disable(dp, p->phy);
dev_mc_unsync(master, dev);
dev_uc_unsync(master, dev);
if (dev->flags & IFF_ALLMULTI)
......@@ -143,11 +139,6 @@ static int dsa_slave_close(struct net_device *dev)
if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
dev_uc_del(master, dev->dev_addr);
if (ds->ops->port_disable)
ds->ops->port_disable(ds, p->dp->index, p->phy);
dsa_port_set_state_now(p->dp, BR_STATE_DISABLED);
return 0;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment