Lines Matching +full:fiber +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/mdio/mdio-i2c.h>
150 "mod-def0",
152 "tx-fault",
153 "tx-disable",
154 "rate-select0",
155 "rate-select1",
167 /* t_start_up (SFF-8431) or t_init (SFF-8472) is the time required for a
168 * non-cooled module to initialise its laser safety circuitry. We wait
200 * The SFF-8472 specifies t_serial ("Time from power on until module is
211 * 0x56 (which with mdio-i2c, translates to a PHY address of 22).
213 * via address 0x51 (mdio-i2c will use RollBall protocol on this address).
303 return id->base.phys_id == SFF8024_ID_SFF_8472 && in sff_module_supported()
304 id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP; in sff_module_supported()
314 if (id->base.phys_id == SFF8024_ID_SFP && in sfp_module_supported()
315 id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP) in sfp_module_supported()
318 /* SFP GPON module Ubiquiti U-Fiber Instant has in its EEPROM stored in sfp_module_supported()
322 if (id->base.phys_id == SFF8024_ID_SFF_8472 && in sfp_module_supported()
323 id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP && in sfp_module_supported()
324 !memcmp(id->base.vendor_name, "UBNT ", 16) && in sfp_module_supported()
325 !memcmp(id->base.vendor_pn, "UF-INSTANT ", 16)) in sfp_module_supported()
346 sfp->module_t_start_up = T_START_UP_BAD_GPON; in sfp_fixup_long_startup()
352 sfp->state_ignore_mask |= SFP_F_LOS; in sfp_fixup_ignore_los()
354 sfp->id.ext.options &= ~cpu_to_be16(SFP_OPTIONS_LOS_INVERTED | in sfp_fixup_ignore_los()
360 sfp->state_ignore_mask |= SFP_F_TX_FAULT; in sfp_fixup_ignore_tx_fault()
369 // For 10GBASE-T short-reach modules
372 sfp->id.base.connector = SFF8024_CONNECTOR_RJ45; in sfp_fixup_10gbaset_30m()
373 sfp->id.base.extended_cc = SFF8024_ECC_10GBASE_T_SR; in sfp_fixup_10gbaset_30m()
378 sfp->mdio_protocol = MDIO_I2C_ROLLBALL; in sfp_fixup_rollball()
385 sfp->phy_t_retry = msecs_to_jiffies(1000); in sfp_fixup_rollball()
396 sfp->module_t_wait = msecs_to_jiffies(4000); in sfp_fixup_fs_2_5gt()
411 sfp->state_hw_mask &= ~(SFP_F_TX_FAULT | SFP_F_LOS); in sfp_fixup_halny_gsfp()
421 sfp->id.base.extended_cc = SFF8024_ECC_10GBASE_T_SFI; in sfp_fixup_rollball_cc()
453 /* Ubiquiti U-Fiber Instant module claims that support all transceiver in sfp_quirk_ubnt_uf_instant()
455 * modes and set only one mode which module supports: 1000baseX_Full. in sfp_quirk_ubnt_uf_instant()
467 // Alcatel Lucent G-010S-P can operate at 2500base-X, but incorrectly
471 // Alcatel Lucent G-010S-A can operate at 2500base-X, but report 3.2GBd
476 // Fiberstore SFP-10G-T doesn't identify as copper, uses the Rollball
479 SFP_QUIRK_F("FS", "SFP-10G-T", sfp_fixup_fs_10gt),
481 // Fiberstore SFP-2.5G-T uses Rollball protocol to talk to the PHY and
483 SFP_QUIRK_F("FS", "SFP-2.5G-T", sfp_fixup_fs_2_5gt),
485 // Fiberstore GPON-ONU-34-20BI can operate at 2500base-X, but report 1.2GBd
487 SFP_QUIRK("FS", "GPON-ONU-34-20BI", sfp_quirk_2500basex,
490 SFP_QUIRK_F("HALNy", "HL-GSFP", sfp_fixup_halny_gsfp),
492 // HG MXPD-483II-F 2.5G supports 2500Base-X, but incorrectly reports
494 SFP_QUIRK_M("HG GENUINE", "MXPD-483II", sfp_quirk_2500basex),
496 // Huawei MA5671A can operate at 2500base-X, but report 1.2GBd NRZ in
501 // Lantech 8330-262D-E can operate at 2500base-X, but incorrectly report
503 SFP_QUIRK_M("Lantech", "8330-262D-E", sfp_quirk_2500basex),
505 SFP_QUIRK_M("UBNT", "UF-INSTANT", sfp_quirk_ubnt_uf_instant),
507 // Walsun HXSX-ATR[CI]-1 don't identify as copper, and use the
509 SFP_QUIRK_F("Walsun", "HXSX-ATRC-1", sfp_fixup_fs_10gt),
510 SFP_QUIRK_F("Walsun", "HXSX-ATRI-1", sfp_fixup_fs_10gt),
512 // OEM SFP-GE-T is a 1000Base-T module with broken TX_FAULT indicator
513 SFP_QUIRK_F("OEM", "SFP-GE-T", sfp_fixup_ignore_tx_fault),
515 SFP_QUIRK_F("OEM", "SFP-10G-T", sfp_fixup_rollball_cc),
516 SFP_QUIRK_M("OEM", "SFP-2.5G-T", sfp_quirk_oem_2_5g),
517 SFP_QUIRK_F("OEM", "RTSFP-10", sfp_fixup_rollball_cc),
518 SFP_QUIRK_F("OEM", "RTSFP-10G", sfp_fixup_rollball_cc),
519 SFP_QUIRK_F("Turris", "RTSFP-2.5G", sfp_fixup_rollball),
520 SFP_QUIRK_F("Turris", "RTSFP-10", sfp_fixup_rollball),
521 SFP_QUIRK_F("Turris", "RTSFP-10G", sfp_fixup_rollball),
529 * some manufacturers can't read SFF-8472 and use NUL. in sfp_strlen()
553 vs = sfp_strlen(id->base.vendor_name, ARRAY_SIZE(id->base.vendor_name)); in sfp_lookup_quirk()
554 ps = sfp_strlen(id->base.vendor_pn, ARRAY_SIZE(id->base.vendor_pn)); in sfp_lookup_quirk()
557 if (sfp_match(q->vendor, id->base.vendor_name, vs) && in sfp_lookup_quirk()
558 sfp_match(q->part, id->base.vendor_pn, ps)) in sfp_lookup_quirk()
571 if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) in sfp_gpio_get_state()
574 v = gpiod_get_value_cansleep(sfp->gpio[i]); in sfp_gpio_get_state()
593 drive = sfp->state_hw_drive; in sfp_gpio_set_state()
595 /* Otherwise, let them float to the pull-ups */ in sfp_gpio_set_state()
598 if (sfp->gpio[GPIO_TX_DISABLE]) { in sfp_gpio_set_state()
600 gpiod_direction_output(sfp->gpio[GPIO_TX_DISABLE], in sfp_gpio_set_state()
603 gpiod_direction_input(sfp->gpio[GPIO_TX_DISABLE]); in sfp_gpio_set_state()
606 if (sfp->gpio[GPIO_RS0]) { in sfp_gpio_set_state()
608 gpiod_direction_output(sfp->gpio[GPIO_RS0], in sfp_gpio_set_state()
611 gpiod_direction_input(sfp->gpio[GPIO_RS0]); in sfp_gpio_set_state()
614 if (sfp->gpio[GPIO_RS1]) { in sfp_gpio_set_state()
616 gpiod_direction_output(sfp->gpio[GPIO_RS1], in sfp_gpio_set_state()
619 gpiod_direction_input(sfp->gpio[GPIO_RS1]); in sfp_gpio_set_state()
628 size_t block_size = sfp->i2c_block_size; in sfp_i2c_read()
648 ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs)); in sfp_i2c_read()
657 len -= this_len; in sfp_i2c_read()
660 return msgs[1].buf - (u8 *)buf; in sfp_i2c_read()
675 return -ENOMEM; in sfp_i2c_write()
680 ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs)); in sfp_i2c_write()
693 return -EINVAL; in sfp_i2c_configure()
695 sfp->i2c = i2c; in sfp_i2c_configure()
696 sfp->read = sfp_i2c_read; in sfp_i2c_configure()
697 sfp->write = sfp_i2c_write; in sfp_i2c_configure()
707 i2c_mii = mdio_i2c_alloc(sfp->dev, sfp->i2c, sfp->mdio_protocol); in sfp_i2c_mdiobus_create()
711 i2c_mii->name = "SFP I2C Bus"; in sfp_i2c_mdiobus_create()
712 i2c_mii->phy_mask = ~0; in sfp_i2c_mdiobus_create()
720 sfp->i2c_mii = i2c_mii; in sfp_i2c_mdiobus_create()
727 mdiobus_unregister(sfp->i2c_mii); in sfp_i2c_mdiobus_destroy()
728 sfp->i2c_mii = NULL; in sfp_i2c_mdiobus_destroy()
734 return sfp->read(sfp, a2, addr, buf, len); in sfp_read()
739 return sfp->write(sfp, a2, addr, buf, len); in sfp_write()
771 dev_err_ratelimited(sfp->dev, in sfp_soft_get_state()
775 state = sfp->state; in sfp_soft_get_state()
778 return state & sfp->state_soft_mask; in sfp_soft_get_state()
812 const struct sfp_eeprom_id *id = &sfp->id; in sfp_soft_start_poll()
815 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE) in sfp_soft_start_poll()
817 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT) in sfp_soft_start_poll()
819 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS) in sfp_soft_start_poll()
821 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RATE_SELECT) in sfp_soft_start_poll()
822 mask |= sfp->rs_state_mask; in sfp_soft_start_poll()
824 mutex_lock(&sfp->st_mutex); in sfp_soft_start_poll()
826 sfp->state_soft_mask = ~sfp->state_hw_mask & ~sfp->state_ignore_mask & in sfp_soft_start_poll()
829 if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) && in sfp_soft_start_poll()
830 !sfp->need_poll) in sfp_soft_start_poll()
831 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies); in sfp_soft_start_poll()
832 mutex_unlock(&sfp->st_mutex); in sfp_soft_start_poll()
837 mutex_lock(&sfp->st_mutex); in sfp_soft_stop_poll()
838 sfp->state_soft_mask = 0; in sfp_soft_stop_poll()
839 mutex_unlock(&sfp->st_mutex); in sfp_soft_stop_poll()
842 /* sfp_get_state() - must be called with st_mutex held, or in the
847 unsigned int soft = sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT); in sfp_get_state()
850 state = sfp->get_state(sfp) & sfp->state_hw_mask; in sfp_get_state()
857 /* sfp_set_state() - must be called with st_mutex held, or in the
864 sfp->set_state(sfp, state); in sfp_set_state()
866 soft = sfp->state_soft_mask & SFP_F_OUTPUTS; in sfp_set_state()
873 mutex_lock(&sfp->st_mutex); in sfp_mod_state()
874 sfp->state = (sfp->state & ~mask) | set; in sfp_mod_state()
875 sfp_set_state(sfp, sfp->state); in sfp_mod_state()
876 mutex_unlock(&sfp->st_mutex); in sfp_mod_state()
883 for (p = buf, check = 0; len; p++, len--) in sfp_check()
908 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
927 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
946 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
962 if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL && in sfp_hwmon_is_visible()
974 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
1010 if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL) in sfp_hwmon_calibrate()
1016 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_t_slope), in sfp_hwmon_calibrate_temp()
1017 be16_to_cpu(sfp->diag.cal_t_offset), value); in sfp_hwmon_calibrate_temp()
1020 *value -= 0x10000; in sfp_hwmon_calibrate_temp()
1027 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_v_slope), in sfp_hwmon_calibrate_vcc()
1028 be16_to_cpu(sfp->diag.cal_v_offset), value); in sfp_hwmon_calibrate_vcc()
1035 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_txi_slope), in sfp_hwmon_calibrate_bias()
1036 be16_to_cpu(sfp->diag.cal_txi_offset), value); in sfp_hwmon_calibrate_bias()
1043 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_txpwr_slope), in sfp_hwmon_calibrate_tx_power()
1044 be16_to_cpu(sfp->diag.cal_txpwr_offset), value); in sfp_hwmon_calibrate_tx_power()
1124 *value = be16_to_cpu(sfp->diag.temp_low_alarm); in sfp_hwmon_temp()
1129 *value = be16_to_cpu(sfp->diag.temp_low_warn); in sfp_hwmon_temp()
1133 *value = be16_to_cpu(sfp->diag.temp_high_warn); in sfp_hwmon_temp()
1138 *value = be16_to_cpu(sfp->diag.temp_high_alarm); in sfp_hwmon_temp()
1174 return -EOPNOTSUPP; in sfp_hwmon_temp()
1177 return -EOPNOTSUPP; in sfp_hwmon_temp()
1190 *value = be16_to_cpu(sfp->diag.volt_low_alarm); in sfp_hwmon_vcc()
1195 *value = be16_to_cpu(sfp->diag.volt_low_warn); in sfp_hwmon_vcc()
1200 *value = be16_to_cpu(sfp->diag.volt_high_warn); in sfp_hwmon_vcc()
1205 *value = be16_to_cpu(sfp->diag.volt_high_alarm); in sfp_hwmon_vcc()
1241 return -EOPNOTSUPP; in sfp_hwmon_vcc()
1244 return -EOPNOTSUPP; in sfp_hwmon_vcc()
1257 *value = be16_to_cpu(sfp->diag.bias_low_alarm); in sfp_hwmon_bias()
1262 *value = be16_to_cpu(sfp->diag.bias_low_warn); in sfp_hwmon_bias()
1267 *value = be16_to_cpu(sfp->diag.bias_high_warn); in sfp_hwmon_bias()
1272 *value = be16_to_cpu(sfp->diag.bias_high_alarm); in sfp_hwmon_bias()
1308 return -EOPNOTSUPP; in sfp_hwmon_bias()
1311 return -EOPNOTSUPP; in sfp_hwmon_bias()
1324 *value = be16_to_cpu(sfp->diag.txpwr_low_alarm); in sfp_hwmon_tx_power()
1329 *value = be16_to_cpu(sfp->diag.txpwr_low_warn); in sfp_hwmon_tx_power()
1334 *value = be16_to_cpu(sfp->diag.txpwr_high_warn); in sfp_hwmon_tx_power()
1339 *value = be16_to_cpu(sfp->diag.txpwr_high_alarm); in sfp_hwmon_tx_power()
1375 return -EOPNOTSUPP; in sfp_hwmon_tx_power()
1378 return -EOPNOTSUPP; in sfp_hwmon_tx_power()
1391 *value = be16_to_cpu(sfp->diag.rxpwr_low_alarm); in sfp_hwmon_rx_power()
1396 *value = be16_to_cpu(sfp->diag.rxpwr_low_warn); in sfp_hwmon_rx_power()
1401 *value = be16_to_cpu(sfp->diag.rxpwr_high_warn); in sfp_hwmon_rx_power()
1406 *value = be16_to_cpu(sfp->diag.rxpwr_high_alarm); in sfp_hwmon_rx_power()
1442 return -EOPNOTSUPP; in sfp_hwmon_rx_power()
1445 return -EOPNOTSUPP; in sfp_hwmon_rx_power()
1467 return -EOPNOTSUPP; in sfp_hwmon_read()
1470 return -EOPNOTSUPP; in sfp_hwmon_read()
1490 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1499 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1508 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1517 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1521 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1524 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1591 if (sfp->i2c_block_size < 2) { in sfp_hwmon_probe()
1592 dev_info(sfp->dev, in sfp_hwmon_probe()
1594 dev_info(sfp->dev, in sfp_hwmon_probe()
1599 err = sfp_read(sfp, true, 0, &sfp->diag, sizeof(sfp->diag)); in sfp_hwmon_probe()
1601 if (sfp->hwmon_tries--) { in sfp_hwmon_probe()
1602 mod_delayed_work(system_wq, &sfp->hwmon_probe, in sfp_hwmon_probe()
1605 dev_warn(sfp->dev, "hwmon probe failed: %pe\n", in sfp_hwmon_probe()
1611 sfp->hwmon_name = hwmon_sanitize_name(dev_name(sfp->dev)); in sfp_hwmon_probe()
1612 if (IS_ERR(sfp->hwmon_name)) { in sfp_hwmon_probe()
1613 dev_err(sfp->dev, "out of memory for hwmon name\n"); in sfp_hwmon_probe()
1617 sfp->hwmon_dev = hwmon_device_register_with_info(sfp->dev, in sfp_hwmon_probe()
1618 sfp->hwmon_name, sfp, in sfp_hwmon_probe()
1621 if (IS_ERR(sfp->hwmon_dev)) in sfp_hwmon_probe()
1622 dev_err(sfp->dev, "failed to register hwmon device: %ld\n", in sfp_hwmon_probe()
1623 PTR_ERR(sfp->hwmon_dev)); in sfp_hwmon_probe()
1628 if (sfp->have_a2 && sfp->id.ext.diagmon & SFP_DIAGMON_DDM) { in sfp_hwmon_insert()
1629 mod_delayed_work(system_wq, &sfp->hwmon_probe, 1); in sfp_hwmon_insert()
1630 sfp->hwmon_tries = R_PROBE_RETRY_SLOW; in sfp_hwmon_insert()
1638 cancel_delayed_work_sync(&sfp->hwmon_probe); in sfp_hwmon_remove()
1639 if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) { in sfp_hwmon_remove()
1640 hwmon_device_unregister(sfp->hwmon_dev); in sfp_hwmon_remove()
1641 sfp->hwmon_dev = NULL; in sfp_hwmon_remove()
1642 kfree(sfp->hwmon_name); in sfp_hwmon_remove()
1648 INIT_DELAYED_WORK(&sfp->hwmon_probe, sfp_hwmon_probe); in sfp_hwmon_init()
1655 cancel_delayed_work_sync(&sfp->hwmon_probe); in sfp_hwmon_exit()
1680 dev_dbg(sfp->dev, "tx disable %u -> %u\n", in sfp_module_tx_disable()
1681 sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 1); in sfp_module_tx_disable()
1687 dev_dbg(sfp->dev, "tx disable %u -> %u\n", in sfp_module_tx_enable()
1688 sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 0); in sfp_module_tx_enable()
1695 struct sfp *sfp = s->private; in sfp_debug_state_show()
1698 mod_state_to_str(sfp->sm_mod_state)); in sfp_debug_state_show()
1700 R_PROBE_RETRY_INIT - sfp->sm_mod_tries_init, in sfp_debug_state_show()
1701 R_PROBE_RETRY_SLOW - sfp->sm_mod_tries); in sfp_debug_state_show()
1703 dev_state_to_str(sfp->sm_dev_state)); in sfp_debug_state_show()
1705 sm_state_to_str(sfp->sm_state)); in sfp_debug_state_show()
1707 sfp->sm_fault_retries); in sfp_debug_state_show()
1709 sfp->sm_phy_retries); in sfp_debug_state_show()
1710 seq_printf(s, "Signalling rate: %u kBd\n", sfp->rate_kbd); in sfp_debug_state_show()
1712 sfp->rs_threshold_kbd); in sfp_debug_state_show()
1713 seq_printf(s, "moddef0: %d\n", !!(sfp->state & SFP_F_PRESENT)); in sfp_debug_state_show()
1714 seq_printf(s, "rx_los: %d\n", !!(sfp->state & SFP_F_LOS)); in sfp_debug_state_show()
1715 seq_printf(s, "tx_fault: %d\n", !!(sfp->state & SFP_F_TX_FAULT)); in sfp_debug_state_show()
1716 seq_printf(s, "tx_disable: %d\n", !!(sfp->state & SFP_F_TX_DISABLE)); in sfp_debug_state_show()
1717 seq_printf(s, "rs0: %d\n", !!(sfp->state & SFP_F_RS0)); in sfp_debug_state_show()
1718 seq_printf(s, "rs1: %d\n", !!(sfp->state & SFP_F_RS1)); in sfp_debug_state_show()
1725 sfp->debugfs_dir = debugfs_create_dir(dev_name(sfp->dev), NULL); in sfp_debugfs_init()
1727 debugfs_create_file("state", 0600, sfp->debugfs_dir, sfp, in sfp_debugfs_init()
1733 debugfs_remove_recursive(sfp->debugfs_dir); in sfp_debugfs_exit()
1749 mutex_lock(&sfp->st_mutex); in sfp_module_tx_fault_reset()
1750 state = sfp->state; in sfp_module_tx_fault_reset()
1758 mutex_unlock(&sfp->st_mutex); in sfp_module_tx_fault_reset()
1765 mod_delayed_work(system_power_efficient_wq, &sfp->timeout, in sfp_sm_set_timer()
1768 cancel_delayed_work(&sfp->timeout); in sfp_sm_set_timer()
1774 sfp->sm_state = state; in sfp_sm_next()
1781 sfp->sm_mod_state = state; in sfp_sm_mod_next()
1787 sfp_remove_phy(sfp->sfp_bus); in sfp_sm_phy_detach()
1788 phy_device_remove(sfp->mod_phy); in sfp_sm_phy_detach()
1789 phy_device_free(sfp->mod_phy); in sfp_sm_phy_detach()
1790 sfp->mod_phy = NULL; in sfp_sm_phy_detach()
1798 phy = get_phy_device(sfp->i2c_mii, addr, is_c45); in sfp_sm_probe_phy()
1799 if (phy == ERR_PTR(-ENODEV)) in sfp_sm_probe_phy()
1802 dev_err(sfp->dev, "mdiobus scan returned %pe\n", phy); in sfp_sm_probe_phy()
1807 phy->is_on_sfp_module = true; in sfp_sm_probe_phy()
1812 dev_err(sfp->dev, "phy_device_register failed: %pe\n", in sfp_sm_probe_phy()
1817 err = sfp_add_phy(sfp->sfp_bus, phy); in sfp_sm_probe_phy()
1821 dev_err(sfp->dev, "sfp_add_phy failed: %pe\n", ERR_PTR(err)); in sfp_sm_probe_phy()
1825 sfp->mod_phy = phy; in sfp_sm_probe_phy()
1832 sfp_link_up(sfp->sfp_bus); in sfp_sm_link_up()
1838 sfp_link_down(sfp->sfp_bus); in sfp_sm_link_down()
1845 __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); in sfp_sm_link_check_los()
1853 los = !(sfp->state & SFP_F_LOS); in sfp_sm_link_check_los()
1855 los = !!(sfp->state & SFP_F_LOS); in sfp_sm_link_check_los()
1867 __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); in sfp_los_event_active()
1877 __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); in sfp_los_event_inactive()
1885 if (sfp->sm_fault_retries && !--sfp->sm_fault_retries) { in sfp_sm_fault()
1886 dev_err(sfp->dev, in sfp_sm_fault()
1891 dev_err(sfp->dev, "module transmit fault indicated\n"); in sfp_sm_fault()
1899 if (sfp->mdio_protocol != MDIO_I2C_NONE) in sfp_sm_add_mdio_bus()
1905 /* Probe a SFP for a PHY device if the module supports copper - the PHY
1909 * Clause 22 copper SFP modules normally operate in Cisco SGMII mode with
1910 * negotiation enabled, but some may be in 1000base-X - which is for the
1914 * mode according to the negotiated line speed.
1920 switch (sfp->mdio_protocol) { in sfp_sm_probe_for_phy()
1945 if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV10_2 && in sfp_module_parse_power()
1946 sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_POWER_DECL)) in sfp_module_parse_power()
1949 if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV11_4 && in sfp_module_parse_power()
1950 sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL)) in sfp_module_parse_power()
1955 sfp->module_power_mW = power_mW; in sfp_module_parse_power()
1959 supports_a2 = sfp->id.ext.sff8472_compliance != in sfp_module_parse_power()
1961 sfp->id.ext.diagmon & SFP_DIAGMON_DDM; in sfp_module_parse_power()
1963 if (power_mW > sfp->max_power_mW) { in sfp_module_parse_power()
1968 * indicated mode. in sfp_module_parse_power()
1970 dev_err(sfp->dev, in sfp_module_parse_power()
1973 return -EINVAL; in sfp_module_parse_power()
1975 dev_warn(sfp->dev, in sfp_module_parse_power()
1976 "Host does not support %u.%uW modules, module left in power mode 1\n", in sfp_module_parse_power()
1985 * that the module powers up in the indicated mode. in sfp_module_parse_power()
1990 /* If the module requires a higher power mode, but also requires in sfp_module_parse_power()
1994 if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) { in sfp_module_parse_power()
1995 dev_warn(sfp->dev, in sfp_module_parse_power()
2001 sfp->module_power_mW = power_mW; in sfp_module_parse_power()
2014 dev_err(sfp->dev, "failed to %sable high power: %pe\n", in sfp_sm_mod_hpower()
2016 return -EAGAIN; in sfp_sm_mod_hpower()
2020 dev_info(sfp->dev, "Module switched to %u.%uW power level\n", in sfp_sm_mod_hpower()
2021 sfp->module_power_mW / 1000, in sfp_sm_mod_hpower()
2022 (sfp->module_power_mW / 100) % 10); in sfp_sm_mod_hpower()
2031 sfp->rs_threshold_kbd = 0; in sfp_module_parse_rate_select()
2032 sfp->rs_state_mask = 0; in sfp_module_parse_rate_select()
2034 if (!(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_RATE_SELECT))) in sfp_module_parse_rate_select()
2038 /* Default to INF-8074 RateSelect operation. The signalling threshold in sfp_module_parse_rate_select()
2040 * SFF-8079 reveals that it is understood that RS0 will be low for in sfp_module_parse_rate_select()
2041 * 1.0625Gb/s and high for 2.125Gb/s. Choose a value half-way between. in sfp_module_parse_rate_select()
2042 * This method exists prior to SFF-8472. in sfp_module_parse_rate_select()
2044 sfp->rs_state_mask = SFP_F_RS0; in sfp_module_parse_rate_select()
2045 sfp->rs_threshold_kbd = 1594; in sfp_module_parse_rate_select()
2048 * SFF-8472 rev 9.5 marks this field as reserved. in sfp_module_parse_rate_select()
2049 * SFF-8079 references SFF-8472 rev 9.5 and defines bit 0. SFF-8472 in sfp_module_parse_rate_select()
2051 * SFF-8472 rev 10.2 defines this field using values 0..4 in sfp_module_parse_rate_select()
2052 * SFF-8472 rev 11.0 redefines this field with bit 0 for SFF-8079 in sfp_module_parse_rate_select()
2055 rate_id = sfp->id.base.rate_id; in sfp_module_parse_rate_select()
2060 /* SFF-8472 rev 10.0..10.4 did not account for SFF-8079 using bit 0, in sfp_module_parse_rate_select()
2061 * and allocated value 3 to SFF-8431 independent tx/rx rate select. in sfp_module_parse_rate_select()
2062 * Convert this to a SFF-8472 rev 11.0 rate identifier. in sfp_module_parse_rate_select()
2064 if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV10_2 && in sfp_module_parse_rate_select()
2065 sfp->id.ext.sff8472_compliance < SFP_SFF8472_COMPLIANCE_REV11_0 && in sfp_module_parse_rate_select()
2070 /* SFF-8079 RateSelect / Application Select in conjunction with in sfp_module_parse_rate_select()
2071 * SFF-8472 rev 9.5. SFF-8079 defines rate_id as a bitfield in sfp_module_parse_rate_select()
2072 * with only bit 0 used, which takes precedence over SFF-8472. in sfp_module_parse_rate_select()
2074 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_APP_SELECT_SFF8079)) { in sfp_module_parse_rate_select()
2075 /* SFF-8079 Part 1 - rate selection between Fibre in sfp_module_parse_rate_select()
2080 sfp->rs_threshold_kbd = 2125 - 1; in sfp_module_parse_rate_select()
2081 sfp->rs_state_mask = SFP_F_RS0; in sfp_module_parse_rate_select()
2086 /* SFF-8472 rev 9.5 does not define the rate identifier */ in sfp_module_parse_rate_select()
2087 if (sfp->id.ext.sff8472_compliance <= SFP_SFF8472_COMPLIANCE_REV9_5) in sfp_module_parse_rate_select()
2090 /* SFF-8472 rev 11.0 defines rate_id as a numerical value which will in sfp_module_parse_rate_select()
2091 * always have bit 0 clear due to SFF-8079's bitfield usage of rate_id. in sfp_module_parse_rate_select()
2095 sfp->rs_threshold_kbd = 4250; in sfp_module_parse_rate_select()
2096 sfp->rs_state_mask = SFP_F_RS0; in sfp_module_parse_rate_select()
2100 sfp->rs_threshold_kbd = 4250; in sfp_module_parse_rate_select()
2101 sfp->rs_state_mask = SFP_F_RS1; in sfp_module_parse_rate_select()
2105 sfp->rs_threshold_kbd = 4250; in sfp_module_parse_rate_select()
2106 sfp->rs_state_mask = SFP_F_RS0 | SFP_F_RS1; in sfp_module_parse_rate_select()
2110 sfp->rs_threshold_kbd = 9000; in sfp_module_parse_rate_select()
2111 sfp->rs_state_mask = SFP_F_RS0 | SFP_F_RS1; in sfp_module_parse_rate_select()
2116 /* GPON modules based on Realtek RTL8672 and RTL9601C chips (e.g. V-SOL
2117 * V2801F, CarlitoxxPro CPGOS03-0490, Ubiquiti U-Fiber Instant, ...) do
2118 * not support multibyte reads from the EEPROM. Each multi-byte read
2121 * chips. Moreover every OEM of V-SOL V2801F module puts its own vendor
2123 * module is V-SOL V2801F. Therefore check for those zeros in the read
2129 size_t i, block_size = sfp->i2c_block_size; in sfp_id_needs_byte_io()
2136 if (memchr_inv(buf + i, '\0', min(block_size - 1, len - i))) in sfp_id_needs_byte_io()
2147 if (id->base.phys_id != SFF8024_ID_SFF_8472 || in sfp_cotsworks_fixup_check()
2148 id->base.phys_ext_id != SFP_PHYS_EXT_ID_SFP || in sfp_cotsworks_fixup_check()
2149 id->base.connector != SFF8024_CONNECTOR_LC) { in sfp_cotsworks_fixup_check()
2150 dev_warn(sfp->dev, "Rewriting fiber module EEPROM with corrected values\n"); in sfp_cotsworks_fixup_check()
2151 id->base.phys_id = SFF8024_ID_SFF_8472; in sfp_cotsworks_fixup_check()
2152 id->base.phys_ext_id = SFP_PHYS_EXT_ID_SFP; in sfp_cotsworks_fixup_check()
2153 id->base.connector = SFF8024_CONNECTOR_LC; in sfp_cotsworks_fixup_check()
2154 err = sfp_write(sfp, false, SFP_PHYS_ID, &id->base, 3); in sfp_cotsworks_fixup_check()
2156 dev_err(sfp->dev, in sfp_cotsworks_fixup_check()
2166 check = sfp_check(&id->base, sizeof(id->base) - 1); in sfp_cotsworks_fixup_check()
2169 dev_err(sfp->dev, in sfp_cotsworks_fixup_check()
2170 "Failed to update base structure checksum in fiber module EEPROM: %pe\n", in sfp_cotsworks_fixup_check()
2180 /* If the module requires address swap mode, warn about it */ in sfp_module_parse_sff8472()
2181 if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) in sfp_module_parse_sff8472()
2182 dev_warn(sfp->dev, in sfp_module_parse_sff8472()
2185 sfp->have_a2 = true; in sfp_module_parse_sff8472()
2192 /* SFP module inserted - read I2C data */ in sfp_sm_mod_probe()
2200 sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE; in sfp_sm_mod_probe()
2205 dev_err(sfp->dev, "failed to read EEPROM: %pe\n", in sfp_sm_mod_probe()
2207 return -EAGAIN; in sfp_sm_mod_probe()
2211 dev_err(sfp->dev, "EEPROM short read: %pe\n", ERR_PTR(ret)); in sfp_sm_mod_probe()
2212 return -EAGAIN; in sfp_sm_mod_probe()
2216 * address 0x51 is just one byte at a time. Also SFF-8472 requires in sfp_sm_mod_probe()
2222 dev_info(sfp->dev, in sfp_sm_mod_probe()
2224 dev_info(sfp->dev, in sfp_sm_mod_probe()
2226 sfp->i2c_block_size = 1; in sfp_sm_mod_probe()
2231 dev_err(sfp->dev, in sfp_sm_mod_probe()
2234 return -EAGAIN; in sfp_sm_mod_probe()
2238 dev_err(sfp->dev, "EEPROM short read: %pe\n", in sfp_sm_mod_probe()
2240 return -EAGAIN; in sfp_sm_mod_probe()
2262 check = sfp_check(&id.base, sizeof(id.base) - 1); in sfp_sm_mod_probe()
2265 dev_warn(sfp->dev, in sfp_sm_mod_probe()
2269 dev_err(sfp->dev, in sfp_sm_mod_probe()
2274 return -EINVAL; in sfp_sm_mod_probe()
2281 dev_err(sfp->dev, "failed to read EEPROM: %pe\n", in sfp_sm_mod_probe()
2283 return -EAGAIN; in sfp_sm_mod_probe()
2287 dev_err(sfp->dev, "EEPROM short read: %pe\n", ERR_PTR(ret)); in sfp_sm_mod_probe()
2288 return -EAGAIN; in sfp_sm_mod_probe()
2291 check = sfp_check(&id.ext, sizeof(id.ext) - 1); in sfp_sm_mod_probe()
2294 dev_warn(sfp->dev, in sfp_sm_mod_probe()
2298 dev_err(sfp->dev, in sfp_sm_mod_probe()
2307 sfp->id = id; in sfp_sm_mod_probe()
2309 dev_info(sfp->dev, "module %.*s %.*s rev %.*s sn %.*s dc %.*s\n", in sfp_sm_mod_probe()
2317 if (!sfp->type->module_supported(&id)) { in sfp_sm_mod_probe()
2318 dev_err(sfp->dev, in sfp_sm_mod_probe()
2319 "module is not supported - phys id 0x%02x 0x%02x\n", in sfp_sm_mod_probe()
2320 sfp->id.base.phys_id, sfp->id.base.phys_ext_id); in sfp_sm_mod_probe()
2321 return -EINVAL; in sfp_sm_mod_probe()
2324 if (sfp->id.ext.sff8472_compliance != SFP_SFF8472_COMPLIANCE_NONE) { in sfp_sm_mod_probe()
2338 if (sfp->gpio[GPIO_TX_DISABLE]) in sfp_sm_mod_probe()
2340 if (sfp->gpio[GPIO_TX_FAULT]) in sfp_sm_mod_probe()
2342 if (sfp->gpio[GPIO_LOS]) in sfp_sm_mod_probe()
2344 if (sfp->gpio[GPIO_RS0]) in sfp_sm_mod_probe()
2346 if (sfp->gpio[GPIO_RS1]) in sfp_sm_mod_probe()
2349 sfp->module_t_start_up = T_START_UP; in sfp_sm_mod_probe()
2350 sfp->module_t_wait = T_WAIT; in sfp_sm_mod_probe()
2351 sfp->phy_t_retry = T_PHY_RETRY; in sfp_sm_mod_probe()
2353 sfp->state_ignore_mask = 0; in sfp_sm_mod_probe()
2355 if (sfp->id.base.extended_cc == SFF8024_ECC_10GBASE_T_SFI || in sfp_sm_mod_probe()
2356 sfp->id.base.extended_cc == SFF8024_ECC_10GBASE_T_SR || in sfp_sm_mod_probe()
2357 sfp->id.base.extended_cc == SFF8024_ECC_5GBASE_T || in sfp_sm_mod_probe()
2358 sfp->id.base.extended_cc == SFF8024_ECC_2_5GBASE_T) in sfp_sm_mod_probe()
2359 sfp->mdio_protocol = MDIO_I2C_C45; in sfp_sm_mod_probe()
2360 else if (sfp->id.base.e1000_base_t) in sfp_sm_mod_probe()
2361 sfp->mdio_protocol = MDIO_I2C_MARVELL_C22; in sfp_sm_mod_probe()
2363 sfp->mdio_protocol = MDIO_I2C_NONE; in sfp_sm_mod_probe()
2365 sfp->quirk = sfp_lookup_quirk(&id); in sfp_sm_mod_probe()
2367 mutex_lock(&sfp->st_mutex); in sfp_sm_mod_probe()
2369 sfp->state_hw_mask = mask; in sfp_sm_mod_probe()
2372 sfp->state_hw_drive |= sfp->rs_state_mask; in sfp_sm_mod_probe()
2374 if (sfp->quirk && sfp->quirk->fixup) in sfp_sm_mod_probe()
2375 sfp->quirk->fixup(sfp); in sfp_sm_mod_probe()
2377 sfp->state_hw_mask &= ~sfp->state_ignore_mask; in sfp_sm_mod_probe()
2378 mutex_unlock(&sfp->st_mutex); in sfp_sm_mod_probe()
2385 if (sfp->sm_mod_state > SFP_MOD_WAITDEV) in sfp_sm_mod_remove()
2386 sfp_module_remove(sfp->sfp_bus); in sfp_sm_mod_remove()
2390 memset(&sfp->id, 0, sizeof(sfp->id)); in sfp_sm_mod_remove()
2391 sfp->module_power_mW = 0; in sfp_sm_mod_remove()
2392 sfp->state_hw_drive = SFP_F_TX_DISABLE; in sfp_sm_mod_remove()
2393 sfp->have_a2 = false; in sfp_sm_mod_remove()
2395 dev_info(sfp->dev, "module removed\n"); in sfp_sm_mod_remove()
2401 switch (sfp->sm_dev_state) { in sfp_sm_device()
2404 sfp->sm_dev_state = SFP_DEV_DOWN; in sfp_sm_device()
2409 sfp->sm_dev_state = SFP_DEV_DETACHED; in sfp_sm_device()
2411 sfp->sm_dev_state = SFP_DEV_UP; in sfp_sm_device()
2416 sfp->sm_dev_state = SFP_DEV_DETACHED; in sfp_sm_device()
2418 sfp->sm_dev_state = SFP_DEV_DOWN; in sfp_sm_device()
2424 * the on-board EEPROM, and sets up the power level.
2438 if (sfp->sm_dev_state < SFP_DEV_DOWN && in sfp_sm_module()
2439 sfp->sm_mod_state > SFP_MOD_WAITDEV) { in sfp_sm_module()
2440 if (sfp->module_power_mW > 1000 && in sfp_sm_module()
2441 sfp->sm_mod_state > SFP_MOD_HPOWER) in sfp_sm_module()
2447 switch (sfp->sm_mod_state) { in sfp_sm_module()
2451 sfp->sm_mod_tries_init = R_PROBE_RETRY_INIT; in sfp_sm_module()
2452 sfp->sm_mod_tries = R_PROBE_RETRY_SLOW; in sfp_sm_module()
2461 err = sfp_sm_mod_probe(sfp, sfp->sm_mod_tries == 1); in sfp_sm_module()
2462 if (err == -EAGAIN) { in sfp_sm_module()
2463 if (sfp->sm_mod_tries_init && in sfp_sm_module()
2464 --sfp->sm_mod_tries_init) { in sfp_sm_module()
2467 } else if (sfp->sm_mod_tries && --sfp->sm_mod_tries) { in sfp_sm_module()
2468 if (sfp->sm_mod_tries == R_PROBE_RETRY_SLOW - 1) in sfp_sm_module()
2469 dev_warn(sfp->dev, in sfp_sm_module()
2480 /* Force a poll to re-read the hardware signal state after in sfp_sm_module()
2483 mod_delayed_work(system_wq, &sfp->poll, 1); in sfp_sm_module()
2487 dev_warn(sfp->dev, "hwmon probe failed: %pe\n", in sfp_sm_module()
2494 if (sfp->sm_dev_state < SFP_DEV_DOWN) in sfp_sm_module()
2498 err = sfp_module_insert(sfp->sfp_bus, &sfp->id, in sfp_sm_module()
2499 sfp->quirk); in sfp_sm_module()
2506 if (sfp->module_power_mW <= 1000) in sfp_sm_module()
2512 /* Enable high power mode */ in sfp_sm_module()
2515 if (err != -EAGAIN) { in sfp_sm_module()
2516 sfp_module_remove(sfp->sfp_bus); in sfp_sm_module()
2548 if (sfp->sm_state != SFP_S_DOWN && in sfp_sm_main()
2549 (sfp->sm_mod_state != SFP_MOD_PRESENT || in sfp_sm_main()
2550 sfp->sm_dev_state != SFP_DEV_UP)) { in sfp_sm_main()
2551 if (sfp->sm_state == SFP_S_LINK_UP && in sfp_sm_main()
2552 sfp->sm_dev_state == SFP_DEV_UP) in sfp_sm_main()
2554 if (sfp->sm_state > SFP_S_INIT) in sfp_sm_main()
2555 sfp_module_stop(sfp->sfp_bus); in sfp_sm_main()
2556 if (sfp->mod_phy) in sfp_sm_main()
2558 if (sfp->i2c_mii) in sfp_sm_main()
2567 switch (sfp->sm_state) { in sfp_sm_main()
2569 if (sfp->sm_mod_state != SFP_MOD_PRESENT || in sfp_sm_main()
2570 sfp->sm_dev_state != SFP_DEV_UP) in sfp_sm_main()
2574 * memory, which implies that we have some level of SFF-8472 in sfp_sm_main()
2577 if (sfp->have_a2) in sfp_sm_main()
2583 sfp->sm_fault_retries = N_FAULT_INIT; in sfp_sm_main()
2590 sfp_sm_next(sfp, SFP_S_WAIT, sfp->module_t_wait); in sfp_sm_main()
2597 if (sfp->state & SFP_F_TX_FAULT) { in sfp_sm_main()
2598 /* Wait up to t_init (SFF-8472) or t_start_up (SFF-8431) in sfp_sm_main()
2603 timeout = sfp->module_t_start_up; in sfp_sm_main()
2604 if (timeout > sfp->module_t_wait) in sfp_sm_main()
2605 timeout -= sfp->module_t_wait; in sfp_sm_main()
2619 if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) { in sfp_sm_main()
2624 sfp->sm_fault_retries == N_FAULT_INIT); in sfp_sm_main()
2633 sfp->sm_phy_retries = R_PHY_RETRY; in sfp_sm_main()
2646 if (ret == -ENODEV) { in sfp_sm_main()
2647 if (--sfp->sm_phy_retries) { in sfp_sm_main()
2649 sfp->phy_t_retry); in sfp_sm_main()
2650 dev_dbg(sfp->dev, in sfp_sm_main()
2652 sfp->sm_phy_retries); in sfp_sm_main()
2655 dev_info(sfp->dev, "no PHY detected\n"); in sfp_sm_main()
2661 if (sfp_module_start(sfp->sfp_bus)) { in sfp_sm_main()
2668 sfp->sm_fault_retries = N_FAULT; in sfp_sm_main()
2674 sfp_sm_next(sfp, SFP_S_INIT, sfp->module_t_start_up); in sfp_sm_main()
2698 sfp_sm_next(sfp, SFP_S_REINIT, sfp->module_t_start_up); in sfp_sm_main()
2703 if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) { in sfp_sm_main()
2706 dev_info(sfp->dev, "module transmit fault recovered\n"); in sfp_sm_main()
2718 dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n", in __sfp_sm_event()
2719 mod_state_to_str(sfp->sm_mod_state), in __sfp_sm_event()
2720 dev_state_to_str(sfp->sm_dev_state), in __sfp_sm_event()
2721 sm_state_to_str(sfp->sm_state), in __sfp_sm_event()
2728 dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n", in __sfp_sm_event()
2729 mod_state_to_str(sfp->sm_mod_state), in __sfp_sm_event()
2730 dev_state_to_str(sfp->sm_dev_state), in __sfp_sm_event()
2731 sm_state_to_str(sfp->sm_state)); in __sfp_sm_event()
2736 mutex_lock(&sfp->sm_mutex); in sfp_sm_event()
2738 mutex_unlock(&sfp->sm_mutex); in sfp_sm_event()
2765 sfp->rate_kbd = rate_kbd; in sfp_set_signal_rate()
2767 if (rate_kbd > sfp->rs_threshold_kbd) in sfp_set_signal_rate()
2768 set = sfp->rs_state_mask; in sfp_set_signal_rate()
2779 if (sfp->id.ext.sff8472_compliance && in sfp_module_info()
2780 !(sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)) { in sfp_module_info()
2781 modinfo->type = ETH_MODULE_SFF_8472; in sfp_module_info()
2782 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; in sfp_module_info()
2784 modinfo->type = ETH_MODULE_SFF_8079; in sfp_module_info()
2785 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; in sfp_module_info()
2796 if (!(sfp->state & SFP_F_PRESENT)) in sfp_module_eeprom()
2797 return -ENODEV; in sfp_module_eeprom()
2799 if (ee->len == 0) in sfp_module_eeprom()
2800 return -EINVAL; in sfp_module_eeprom()
2802 first = ee->offset; in sfp_module_eeprom()
2803 last = ee->offset + ee->len; in sfp_module_eeprom()
2806 len -= first; in sfp_module_eeprom()
2817 len -= first; in sfp_module_eeprom()
2818 first -= ETH_MODULE_SFF_8079_LEN; in sfp_module_eeprom()
2831 if (!(sfp->state & SFP_F_PRESENT)) in sfp_module_eeprom_by_page()
2832 return -ENODEV; in sfp_module_eeprom_by_page()
2834 if (page->bank) { in sfp_module_eeprom_by_page()
2836 return -EOPNOTSUPP; in sfp_module_eeprom_by_page()
2839 if (page->page) { in sfp_module_eeprom_by_page()
2841 return -EOPNOTSUPP; in sfp_module_eeprom_by_page()
2844 if (page->i2c_address != 0x50 && in sfp_module_eeprom_by_page()
2845 page->i2c_address != 0x51) { in sfp_module_eeprom_by_page()
2847 return -EOPNOTSUPP; in sfp_module_eeprom_by_page()
2850 return sfp_read(sfp, page->i2c_address == 0x51, page->offset, in sfp_module_eeprom_by_page()
2851 page->data, page->length); in sfp_module_eeprom_by_page()
2879 mutex_lock(&sfp->st_mutex); in sfp_check_state()
2881 changed = state ^ sfp->state; in sfp_check_state()
2886 dev_dbg(sfp->dev, "%s %u -> %u\n", gpio_names[i], in sfp_check_state()
2887 !!(sfp->state & BIT(i)), !!(state & BIT(i))); in sfp_check_state()
2889 state |= sfp->state & SFP_F_OUTPUTS; in sfp_check_state()
2890 sfp->state = state; in sfp_check_state()
2891 mutex_unlock(&sfp->st_mutex); in sfp_check_state()
2893 mutex_lock(&sfp->sm_mutex); in sfp_check_state()
2905 mutex_unlock(&sfp->sm_mutex); in sfp_check_state()
2926 if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) || in sfp_poll()
2927 sfp->need_poll) in sfp_poll()
2928 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies); in sfp_poll()
2937 return ERR_PTR(-ENOMEM); in sfp_alloc()
2939 sfp->dev = dev; in sfp_alloc()
2940 sfp->i2c_block_size = SFP_EEPROM_BLOCK_SIZE; in sfp_alloc()
2942 mutex_init(&sfp->sm_mutex); in sfp_alloc()
2943 mutex_init(&sfp->st_mutex); in sfp_alloc()
2944 INIT_DELAYED_WORK(&sfp->poll, sfp_poll); in sfp_alloc()
2945 INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout); in sfp_alloc()
2958 cancel_delayed_work_sync(&sfp->poll); in sfp_cleanup()
2959 cancel_delayed_work_sync(&sfp->timeout); in sfp_cleanup()
2960 if (sfp->i2c_mii) { in sfp_cleanup()
2961 mdiobus_unregister(sfp->i2c_mii); in sfp_cleanup()
2962 mdiobus_free(sfp->i2c_mii); in sfp_cleanup()
2964 if (sfp->i2c) in sfp_cleanup()
2965 i2c_put_adapter(sfp->i2c); in sfp_cleanup()
2975 h = fwnode_find_reference(dev_fwnode(sfp->dev), "i2c-bus", 0); in sfp_i2c_get()
2977 dev_err(sfp->dev, "missing 'i2c-bus' property\n"); in sfp_i2c_get()
2978 return -ENODEV; in sfp_i2c_get()
2983 err = -EPROBE_DEFER; in sfp_i2c_get()
3002 sfp = sfp_alloc(&pdev->dev); in sfp_probe()
3008 err = devm_add_action_or_reset(sfp->dev, sfp_cleanup, sfp); in sfp_probe()
3012 sff = device_get_match_data(sfp->dev); in sfp_probe()
3016 sfp->type = sff; in sfp_probe()
3023 if (sff->gpios & BIT(i)) { in sfp_probe()
3024 sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev, in sfp_probe()
3026 if (IS_ERR(sfp->gpio[i])) in sfp_probe()
3027 return PTR_ERR(sfp->gpio[i]); in sfp_probe()
3030 sfp->state_hw_mask = SFP_F_PRESENT; in sfp_probe()
3031 sfp->state_hw_drive = SFP_F_TX_DISABLE; in sfp_probe()
3033 sfp->get_state = sfp_gpio_get_state; in sfp_probe()
3034 sfp->set_state = sfp_gpio_set_state; in sfp_probe()
3037 if (!(sfp->gpio[GPIO_MODDEF0])) in sfp_probe()
3038 sfp->get_state = sff_gpio_get_state; in sfp_probe()
3040 device_property_read_u32(&pdev->dev, "maximum-power-milliwatt", in sfp_probe()
3041 &sfp->max_power_mW); in sfp_probe()
3042 if (sfp->max_power_mW < 1000) { in sfp_probe()
3043 if (sfp->max_power_mW) in sfp_probe()
3044 dev_warn(sfp->dev, in sfp_probe()
3046 sfp->max_power_mW = 1000; in sfp_probe()
3049 dev_info(sfp->dev, "Host maximum power %u.%uW\n", in sfp_probe()
3050 sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); in sfp_probe()
3055 sfp->state = sfp_get_state(sfp) | SFP_F_TX_DISABLE; in sfp_probe()
3057 if (sfp->gpio[GPIO_RS0] && in sfp_probe()
3058 gpiod_get_value_cansleep(sfp->gpio[GPIO_RS0])) in sfp_probe()
3059 sfp->state |= SFP_F_RS0; in sfp_probe()
3060 sfp_set_state(sfp, sfp->state); in sfp_probe()
3062 if (sfp->state & SFP_F_PRESENT) { in sfp_probe()
3069 if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) in sfp_probe()
3072 sfp->gpio_irq[i] = gpiod_to_irq(sfp->gpio[i]); in sfp_probe()
3073 if (sfp->gpio_irq[i] < 0) { in sfp_probe()
3074 sfp->gpio_irq[i] = 0; in sfp_probe()
3075 sfp->need_poll = true; in sfp_probe()
3079 sfp_irq_name = devm_kasprintf(sfp->dev, GFP_KERNEL, in sfp_probe()
3080 "%s-%s", dev_name(sfp->dev), in sfp_probe()
3084 return -ENOMEM; in sfp_probe()
3086 err = devm_request_threaded_irq(sfp->dev, sfp->gpio_irq[i], in sfp_probe()
3093 sfp->gpio_irq[i] = 0; in sfp_probe()
3094 sfp->need_poll = true; in sfp_probe()
3098 if (sfp->need_poll) in sfp_probe()
3099 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies); in sfp_probe()
3103 * be active when the fiber is removed. This could be a safety issue and in sfp_probe()
3106 if (!sfp->gpio[GPIO_TX_DISABLE]) in sfp_probe()
3107 dev_warn(sfp->dev, in sfp_probe()
3110 sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); in sfp_probe()
3111 if (!sfp->sfp_bus) in sfp_probe()
3112 return -ENOMEM; in sfp_probe()
3124 sfp_unregister_socket(sfp->sfp_bus); in sfp_remove()
3137 if (!sfp->gpio_irq[i]) in sfp_shutdown()
3140 devm_free_irq(sfp->dev, sfp->gpio_irq[i], sfp); in sfp_shutdown()
3143 cancel_delayed_work_sync(&sfp->poll); in sfp_shutdown()
3144 cancel_delayed_work_sync(&sfp->timeout); in sfp_shutdown()