diff options
Diffstat (limited to 'drivers/net/phy/sfp.c')
-rw-r--r-- | drivers/net/phy/sfp.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/drivers/net/phy/sfp.c b/drivers/net/phy/sfp.c index fd8bb998ae52..68c8fbf099f8 100644 --- a/drivers/net/phy/sfp.c +++ b/drivers/net/phy/sfp.c | |||
@@ -184,6 +184,7 @@ struct sfp { | |||
184 | 184 | ||
185 | struct gpio_desc *gpio[GPIO_MAX]; | 185 | struct gpio_desc *gpio[GPIO_MAX]; |
186 | 186 | ||
187 | bool attached; | ||
187 | unsigned int state; | 188 | unsigned int state; |
188 | struct delayed_work poll; | 189 | struct delayed_work poll; |
189 | struct delayed_work timeout; | 190 | struct delayed_work timeout; |
@@ -1475,7 +1476,7 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event) | |||
1475 | */ | 1476 | */ |
1476 | switch (sfp->sm_mod_state) { | 1477 | switch (sfp->sm_mod_state) { |
1477 | default: | 1478 | default: |
1478 | if (event == SFP_E_INSERT) { | 1479 | if (event == SFP_E_INSERT && sfp->attached) { |
1479 | sfp_module_tx_disable(sfp); | 1480 | sfp_module_tx_disable(sfp); |
1480 | sfp_sm_ins_next(sfp, SFP_MOD_PROBE, T_PROBE_INIT); | 1481 | sfp_sm_ins_next(sfp, SFP_MOD_PROBE, T_PROBE_INIT); |
1481 | } | 1482 | } |
@@ -1607,6 +1608,19 @@ static void sfp_sm_event(struct sfp *sfp, unsigned int event) | |||
1607 | mutex_unlock(&sfp->sm_mutex); | 1608 | mutex_unlock(&sfp->sm_mutex); |
1608 | } | 1609 | } |
1609 | 1610 | ||
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 | |||
1610 | static void sfp_start(struct sfp *sfp) | 1624 | static void sfp_start(struct sfp *sfp) |
1611 | { | 1625 | { |
1612 | sfp_sm_event(sfp, SFP_E_DEV_UP); | 1626 | sfp_sm_event(sfp, SFP_E_DEV_UP); |
@@ -1667,6 +1681,8 @@ static int sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee, | |||
1667 | } | 1681 | } |
1668 | 1682 | ||
1669 | static const struct sfp_socket_ops sfp_module_ops = { | 1683 | static const struct sfp_socket_ops sfp_module_ops = { |
1684 | .attach = sfp_attach, | ||
1685 | .detach = sfp_detach, | ||
1670 | .start = sfp_start, | 1686 | .start = sfp_start, |
1671 | .stop = sfp_stop, | 1687 | .stop = sfp_stop, |
1672 | .module_info = sfp_module_info, | 1688 | .module_info = sfp_module_info, |
@@ -1834,10 +1850,6 @@ static int sfp_probe(struct platform_device *pdev) | |||
1834 | dev_info(sfp->dev, "Host maximum power %u.%uW\n", | 1850 | dev_info(sfp->dev, "Host maximum power %u.%uW\n", |
1835 | sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); | 1851 | sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); |
1836 | 1852 | ||
1837 | sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); | ||
1838 | if (!sfp->sfp_bus) | ||
1839 | return -ENOMEM; | ||
1840 | |||
1841 | /* Get the initial state, and always signal TX disable, | 1853 | /* Get the initial state, and always signal TX disable, |
1842 | * since the network interface will not be up. | 1854 | * since the network interface will not be up. |
1843 | */ | 1855 | */ |
@@ -1848,10 +1860,6 @@ static int sfp_probe(struct platform_device *pdev) | |||
1848 | sfp->state |= SFP_F_RATE_SELECT; | 1860 | sfp->state |= SFP_F_RATE_SELECT; |
1849 | sfp_set_state(sfp, sfp->state); | 1861 | sfp_set_state(sfp, sfp->state); |
1850 | sfp_module_tx_disable(sfp); | 1862 | 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(); | ||
1855 | 1863 | ||
1856 | for (i = 0; i < GPIO_MAX; i++) { | 1864 | for (i = 0; i < GPIO_MAX; i++) { |
1857 | if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) | 1865 | if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) |
@@ -1884,6 +1892,10 @@ static int sfp_probe(struct platform_device *pdev) | |||
1884 | dev_warn(sfp->dev, | 1892 | dev_warn(sfp->dev, |
1885 | "No tx_disable pin: SFP modules will always be emitting.\n"); | 1893 | "No tx_disable pin: SFP modules will always be emitting.\n"); |
1886 | 1894 | ||
1895 | sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); | ||
1896 | if (!sfp->sfp_bus) | ||
1897 | return -ENOMEM; | ||
1898 | |||
1887 | return 0; | 1899 | return 0; |
1888 | } | 1900 | } |
1889 | 1901 | ||