Skip to content

Commit b2f2af2

Browse files
ffainellidavem330
authored andcommitted
net: dsa: allow enabling and disable switch ports
Whenever a per-port network device is used/unused, invoke the switch driver port_enable/port_disable callbacks to allow saving as much power as possible by disabling unused parts of the switch (RX/TX logic, memory arrays, PHYs...). We supply a PHY device argument to make sure the switch driver can act on the PHY device if needed (like putting/taking the PHY out of deep low power mode). Signed-off-by: Florian Fainelli <f.fainelli@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent f7f1de5 commit b2f2af2

2 files changed

Lines changed: 22 additions & 0 deletions

File tree

‎include/net/dsa.h‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,14 @@ struct dsa_switch_driver {
224224
*/
225225
int (*suspend)(struct dsa_switch *ds);
226226
int (*resume)(struct dsa_switch *ds);
227+
228+
/*
229+
* Port enable/disable
230+
*/
231+
int (*port_enable)(struct dsa_switch *ds, int port,
232+
struct phy_device *phy);
233+
void (*port_disable)(struct dsa_switch *ds, int port,
234+
struct phy_device *phy);
227235
};
228236

229237
void register_switch_driver(struct dsa_switch_driver *type);

‎net/dsa/slave.c‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ static int dsa_slave_open(struct net_device *dev)
6262
{
6363
struct dsa_slave_priv *p = netdev_priv(dev);
6464
struct net_device *master = p->parent->dst->master_netdev;
65+
struct dsa_switch *ds = p->parent;
6566
int err;
6667

6768
if (!(master->flags & IFF_UP))
@@ -84,11 +85,20 @@ static int dsa_slave_open(struct net_device *dev)
8485
goto clear_allmulti;
8586
}
8687

88+
if (ds->drv->port_enable) {
89+
err = ds->drv->port_enable(ds, p->port, p->phy);
90+
if (err)
91+
goto clear_promisc;
92+
}
93+
8794
if (p->phy)
8895
phy_start(p->phy);
8996

9097
return 0;
9198

99+
clear_promisc:
100+
if (dev->flags & IFF_PROMISC)
101+
dev_set_promiscuity(master, 0);
92102
clear_allmulti:
93103
if (dev->flags & IFF_ALLMULTI)
94104
dev_set_allmulti(master, -1);
@@ -103,6 +113,7 @@ static int dsa_slave_close(struct net_device *dev)
103113
{
104114
struct dsa_slave_priv *p = netdev_priv(dev);
105115
struct net_device *master = p->parent->dst->master_netdev;
116+
struct dsa_switch *ds = p->parent;
106117

107118
if (p->phy)
108119
phy_stop(p->phy);
@@ -117,6 +128,9 @@ static int dsa_slave_close(struct net_device *dev)
117128
if (!ether_addr_equal(dev->dev_addr, master->dev_addr))
118129
dev_uc_del(master, dev->dev_addr);
119130

131+
if (ds->drv->port_disable)
132+
ds->drv->port_disable(ds, p->port, p->phy);
133+
120134
return 0;
121135
}
122136

0 commit comments

Comments
 (0)