Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Russell King and committed by
David S. Miller
b5bfc21a 27b4ad62

+25 -9
+2
drivers/net/phy/sfp-bus.c
··· 347 347 return ret; 348 348 } 349 349 } 350 + bus->socket_ops->attach(bus->sfp); 350 351 if (bus->started) 351 352 bus->socket_ops->start(bus->sfp); 352 353 bus->netdev->sfp_bus = bus; ··· 363 362 if (bus->registered) { 364 363 if (bus->started) 365 364 bus->socket_ops->stop(bus->sfp); 365 + bus->socket_ops->detach(bus->sfp); 366 366 if (bus->phydev && ops && ops->disconnect_phy) 367 367 ops->disconnect_phy(bus->upstream); 368 368 }
+21 -9
drivers/net/phy/sfp.c
··· 184 184 185 185 struct gpio_desc *gpio[GPIO_MAX]; 186 186 187 + bool attached; 187 188 unsigned int state; 188 189 struct delayed_work poll; 189 190 struct delayed_work timeout; ··· 1476 1475 */ 1477 1476 switch (sfp->sm_mod_state) { 1478 1477 default: 1479 - if (event == SFP_E_INSERT) { 1478 + if (event == SFP_E_INSERT && sfp->attached) { 1480 1479 sfp_module_tx_disable(sfp); 1481 1480 sfp_sm_ins_next(sfp, SFP_MOD_PROBE, T_PROBE_INIT); 1482 1481 } ··· 1608 1607 mutex_unlock(&sfp->sm_mutex); 1609 1608 } 1610 1609 1610 + static void sfp_attach(struct sfp *sfp) 1611 + { 1612 + sfp->attached = true; 1613 + if (sfp->state & SFP_F_PRESENT) 1614 + sfp_sm_event(sfp, SFP_E_INSERT); 1615 + } 1616 + 1617 + static void sfp_detach(struct sfp *sfp) 1618 + { 1619 + sfp->attached = false; 1620 + sfp_sm_event(sfp, SFP_E_REMOVE); 1621 + } 1622 + 1611 1623 static void sfp_start(struct sfp *sfp) 1612 1624 { 1613 1625 sfp_sm_event(sfp, SFP_E_DEV_UP); ··· 1681 1667 } 1682 1668 1683 1669 static const struct sfp_socket_ops sfp_module_ops = { 1670 + .attach = sfp_attach, 1671 + .detach = sfp_detach, 1684 1672 .start = sfp_start, 1685 1673 .stop = sfp_stop, 1686 1674 .module_info = sfp_module_info, ··· 1850 1834 dev_info(sfp->dev, "Host maximum power %u.%uW\n", 1851 1835 sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); 1852 1836 1853 - sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); 1854 - if (!sfp->sfp_bus) 1855 - return -ENOMEM; 1856 - 1857 1837 /* Get the initial state, and always signal TX disable, 1858 1838 * since the network interface will not be up. 1859 1839 */ ··· 1860 1848 sfp->state |= SFP_F_RATE_SELECT; 1861 1849 sfp_set_state(sfp, sfp->state); 1862 1850 sfp_module_tx_disable(sfp); 1863 - rtnl_lock(); 1864 - if (sfp->state & SFP_F_PRESENT) 1865 - sfp_sm_event(sfp, SFP_E_INSERT); 1866 - rtnl_unlock(); 1867 1851 1868 1852 for (i = 0; i < GPIO_MAX; i++) { 1869 1853 if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) ··· 1891 1883 if (!sfp->gpio[GPIO_TX_DISABLE]) 1892 1884 dev_warn(sfp->dev, 1893 1885 "No tx_disable pin: SFP modules will always be emitting.\n"); 1886 + 1887 + sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); 1888 + if (!sfp->sfp_bus) 1889 + return -ENOMEM; 1894 1890 1895 1891 return 0; 1896 1892 }
+2
drivers/net/phy/sfp.h
··· 7 7 struct sfp; 8 8 9 9 struct sfp_socket_ops { 10 + void (*attach)(struct sfp *sfp); 11 + void (*detach)(struct sfp *sfp); 10 12 void (*start)(struct sfp *sfp); 11 13 void (*stop)(struct sfp *sfp); 12 14 int (*module_info)(struct sfp *sfp, struct ethtool_modinfo *modinfo);