Skip to content

Commit b5bfc21

Browse files
Russell Kingdavem330
authored andcommitted
net: sfp: do not probe SFP module before we're attached
When we probe a SFP module, we expect to be able to call the upstream device's module_insert() function so that the upstream link can be configured. However, when the upstream device is delayed, we currently may end up probing the module before the upstream device is available, and lose the module_insert() call. Avoid this by holding off probing the module until the SFP bus is properly connected to both the SFP socket driver and the upstream driver. Signed-off-by: Russell King <rmk+kernel@armlinux.org.uk> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 27b4ad6 commit b5bfc21

3 files changed

Lines changed: 25 additions & 9 deletions

File tree

‎drivers/net/phy/sfp-bus.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ static int sfp_register_bus(struct sfp_bus *bus)
347347
return ret;
348348
}
349349
}
350+
bus->socket_ops->attach(bus->sfp);
350351
if (bus->started)
351352
bus->socket_ops->start(bus->sfp);
352353
bus->netdev->sfp_bus = bus;
@@ -362,6 +363,7 @@ static void sfp_unregister_bus(struct sfp_bus *bus)
362363
if (bus->registered) {
363364
if (bus->started)
364365
bus->socket_ops->stop(bus->sfp);
366+
bus->socket_ops->detach(bus->sfp);
365367
if (bus->phydev && ops && ops->disconnect_phy)
366368
ops->disconnect_phy(bus->upstream);
367369
}

‎drivers/net/phy/sfp.c‎

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ struct sfp {
184184

185185
struct gpio_desc *gpio[GPIO_MAX];
186186

187+
bool attached;
187188
unsigned int state;
188189
struct delayed_work poll;
189190
struct delayed_work timeout;
@@ -1475,7 +1476,7 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event)
14751476
*/
14761477
switch (sfp->sm_mod_state) {
14771478
default:
1478-
if (event == SFP_E_INSERT) {
1479+
if (event == SFP_E_INSERT && sfp->attached) {
14791480
sfp_module_tx_disable(sfp);
14801481
sfp_sm_ins_next(sfp, SFP_MOD_PROBE, T_PROBE_INIT);
14811482
}
@@ -1607,6 +1608,19 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event)
16071608
mutex_unlock(&sfp->sm_mutex);
16081609
}
16091610

1611+
static void sfp_attach(struct sfp *sfp)
1612+
{
1613+
sfp->attached = true;
1614+
if (sfp->state & SFP_F_PRESENT)
1615+
sfp_sm_event(sfp, SFP_E_INSERT);
1616+
}
1617+
1618+
static void sfp_detach(struct sfp *sfp)
1619+
{
1620+
sfp->attached = false;
1621+
sfp_sm_event(sfp, SFP_E_REMOVE);
1622+
}
1623+
16101624
static void sfp_start(struct sfp *sfp)
16111625
{
16121626
sfp_sm_event(sfp, SFP_E_DEV_UP);
@@ -1667,6 +1681,8 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
16671681
}
16681682

16691683
static const struct sfp_socket_ops sfp_module_ops = {
1684+
.attach = sfp_attach,
1685+
.detach = sfp_detach,
16701686
.start = sfp_start,
16711687
.stop = sfp_stop,
16721688
.module_info = sfp_module_info,
@@ -1834,10 +1850,6 @@ static int sfp_probe(struct platform_device *pdev)
18341850
dev_info(sfp->dev, "Host maximum power %u.%uW\n",
18351851
sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10);
18361852

1837-
sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops);
1838-
if (!sfp->sfp_bus)
1839-
return -ENOMEM;
1840-
18411853
/* Get the initial state, and always signal TX disable,
18421854
* since the network interface will not be up.
18431855
*/
@@ -1848,10 +1860,6 @@ static int sfp_probe(struct platform_device *pdev)
18481860
sfp->state |= SFP_F_RATE_SELECT;
18491861
sfp_set_state(sfp, sfp->state);
18501862
sfp_module_tx_disable(sfp);
1851-
rtnl_lock();
1852-
if (sfp->state & SFP_F_PRESENT)
1853-
sfp_sm_event(sfp, SFP_E_INSERT);
1854-
rtnl_unlock();
18551863

18561864
for (i = 0; i < GPIO_MAX; i++) {
18571865
if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i])
@@ -1884,6 +1892,10 @@ static int sfp_probe(struct platform_device *pdev)
18841892
dev_warn(sfp->dev,
18851893
"No tx_disable pin: SFP modules will always be emitting.\n");
18861894

1895+
sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops);
1896+
if (!sfp->sfp_bus)
1897+
return -ENOMEM;
1898+
18871899
return 0;
18881900
}
18891901

‎drivers/net/phy/sfp.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
struct sfp;
88

99
struct sfp_socket_ops {
10+
void (*attach)(struct sfp *sfp);
11+
void (*detach)(struct sfp *sfp);
1012
void (*start)(struct sfp *sfp);
1113
void (*stop)(struct sfp *sfp);
1214
int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo);

0 commit comments

Comments
 (0)