Lines Matching +full:fiber +full:- +full:mode
1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/mdio/mdio-i2c.h>
147 "mod-def0",
149 "tx-fault",
150 "tx-disable",
151 "rate-select0",
162 /* t_start_up (SFF-8431) or t_init (SFF-8472) is the time required for a
163 * non-cooled module to initialise its laser safety circuitry. We wait
195 * The SFF-8472 specifies t_serial ("Time from power on until module is
206 * 0x56 (which with mdio-i2c, translates to a PHY address of 22).
265 return id->base.phys_id == SFF8024_ID_SFF_8472 && in sff_module_supported()
266 id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP; in sff_module_supported()
276 if (id->base.phys_id == SFF8024_ID_SFP && in sfp_module_supported()
277 id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP) in sfp_module_supported()
280 /* SFP GPON module Ubiquiti U-Fiber Instant has in its EEPROM stored in sfp_module_supported()
284 if (id->base.phys_id == SFF8024_ID_SFF_8472 && in sfp_module_supported()
285 id->base.phys_ext_id == SFP_PHYS_EXT_ID_SFP && in sfp_module_supported()
286 !memcmp(id->base.vendor_name, "UBNT ", 16) && in sfp_module_supported()
287 !memcmp(id->base.vendor_pn, "UF-INSTANT ", 16)) in sfp_module_supported()
313 if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) in sfp_gpio_get_state()
316 v = gpiod_get_value_cansleep(sfp->gpio[i]); in sfp_gpio_get_state()
333 if (sfp->gpio[GPIO_TX_DISABLE]) in sfp_gpio_set_state()
334 gpiod_direction_output(sfp->gpio[GPIO_TX_DISABLE], in sfp_gpio_set_state()
337 gpiod_direction_output(sfp->gpio[GPIO_RATE_SELECT], in sfp_gpio_set_state()
340 /* Otherwise, let them float to the pull-ups */ in sfp_gpio_set_state()
341 if (sfp->gpio[GPIO_TX_DISABLE]) in sfp_gpio_set_state()
342 gpiod_direction_input(sfp->gpio[GPIO_TX_DISABLE]); in sfp_gpio_set_state()
344 gpiod_direction_input(sfp->gpio[GPIO_RATE_SELECT]); in sfp_gpio_set_state()
353 size_t block_size = sfp->i2c_block_size; in sfp_i2c_read()
373 ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs)); in sfp_i2c_read()
382 len -= this_len; in sfp_i2c_read()
385 return msgs[1].buf - (u8 *)buf; in sfp_i2c_read()
400 return -ENOMEM; in sfp_i2c_write()
405 ret = i2c_transfer(sfp->i2c, msgs, ARRAY_SIZE(msgs)); in sfp_i2c_write()
421 return -EINVAL; in sfp_i2c_configure()
423 sfp->i2c = i2c; in sfp_i2c_configure()
424 sfp->read = sfp_i2c_read; in sfp_i2c_configure()
425 sfp->write = sfp_i2c_write; in sfp_i2c_configure()
427 i2c_mii = mdio_i2c_alloc(sfp->dev, i2c); in sfp_i2c_configure()
431 i2c_mii->name = "SFP I2C Bus"; in sfp_i2c_configure()
432 i2c_mii->phy_mask = ~0; in sfp_i2c_configure()
440 sfp->i2c_mii = i2c_mii; in sfp_i2c_configure()
448 return sfp->read(sfp, a2, addr, buf, len); in sfp_read()
453 return sfp->write(sfp, a2, addr, buf, len); in sfp_write()
469 dev_err_ratelimited(sfp->dev, in sfp_soft_get_state()
473 state = sfp->state; in sfp_soft_get_state()
476 return state & sfp->state_soft_mask; in sfp_soft_get_state()
496 const struct sfp_eeprom_id *id = &sfp->id; in sfp_soft_start_poll()
498 sfp->state_soft_mask = 0; in sfp_soft_start_poll()
499 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE && in sfp_soft_start_poll()
500 !sfp->gpio[GPIO_TX_DISABLE]) in sfp_soft_start_poll()
501 sfp->state_soft_mask |= SFP_F_TX_DISABLE; in sfp_soft_start_poll()
502 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT && in sfp_soft_start_poll()
503 !sfp->gpio[GPIO_TX_FAULT]) in sfp_soft_start_poll()
504 sfp->state_soft_mask |= SFP_F_TX_FAULT; in sfp_soft_start_poll()
505 if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS && in sfp_soft_start_poll()
506 !sfp->gpio[GPIO_LOS]) in sfp_soft_start_poll()
507 sfp->state_soft_mask |= SFP_F_LOS; in sfp_soft_start_poll()
509 if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) && in sfp_soft_start_poll()
510 !sfp->need_poll) in sfp_soft_start_poll()
511 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies); in sfp_soft_start_poll()
516 sfp->state_soft_mask = 0; in sfp_soft_stop_poll()
521 unsigned int state = sfp->get_state(sfp); in sfp_get_state()
524 sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT)) in sfp_get_state()
532 sfp->set_state(sfp, state); in sfp_set_state()
535 sfp->state_soft_mask & SFP_F_TX_DISABLE) in sfp_set_state()
543 for (p = buf, check = 0; len; p++, len--) in sfp_check()
568 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
587 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
606 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
622 if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL && in sfp_hwmon_is_visible()
634 if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) in sfp_hwmon_is_visible()
670 if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL) in sfp_hwmon_calibrate()
676 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_t_slope), in sfp_hwmon_calibrate_temp()
677 be16_to_cpu(sfp->diag.cal_t_offset), value); in sfp_hwmon_calibrate_temp()
680 *value -= 0x10000; in sfp_hwmon_calibrate_temp()
687 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_v_slope), in sfp_hwmon_calibrate_vcc()
688 be16_to_cpu(sfp->diag.cal_v_offset), value); in sfp_hwmon_calibrate_vcc()
695 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_txi_slope), in sfp_hwmon_calibrate_bias()
696 be16_to_cpu(sfp->diag.cal_txi_offset), value); in sfp_hwmon_calibrate_bias()
703 sfp_hwmon_calibrate(sfp, be16_to_cpu(sfp->diag.cal_txpwr_slope), in sfp_hwmon_calibrate_tx_power()
704 be16_to_cpu(sfp->diag.cal_txpwr_offset), value); in sfp_hwmon_calibrate_tx_power()
784 *value = be16_to_cpu(sfp->diag.temp_low_alarm); in sfp_hwmon_temp()
789 *value = be16_to_cpu(sfp->diag.temp_low_warn); in sfp_hwmon_temp()
793 *value = be16_to_cpu(sfp->diag.temp_high_warn); in sfp_hwmon_temp()
798 *value = be16_to_cpu(sfp->diag.temp_high_alarm); in sfp_hwmon_temp()
834 return -EOPNOTSUPP; in sfp_hwmon_temp()
837 return -EOPNOTSUPP; in sfp_hwmon_temp()
850 *value = be16_to_cpu(sfp->diag.volt_low_alarm); in sfp_hwmon_vcc()
855 *value = be16_to_cpu(sfp->diag.volt_low_warn); in sfp_hwmon_vcc()
860 *value = be16_to_cpu(sfp->diag.volt_high_warn); in sfp_hwmon_vcc()
865 *value = be16_to_cpu(sfp->diag.volt_high_alarm); in sfp_hwmon_vcc()
901 return -EOPNOTSUPP; in sfp_hwmon_vcc()
904 return -EOPNOTSUPP; in sfp_hwmon_vcc()
917 *value = be16_to_cpu(sfp->diag.bias_low_alarm); in sfp_hwmon_bias()
922 *value = be16_to_cpu(sfp->diag.bias_low_warn); in sfp_hwmon_bias()
927 *value = be16_to_cpu(sfp->diag.bias_high_warn); in sfp_hwmon_bias()
932 *value = be16_to_cpu(sfp->diag.bias_high_alarm); in sfp_hwmon_bias()
968 return -EOPNOTSUPP; in sfp_hwmon_bias()
971 return -EOPNOTSUPP; in sfp_hwmon_bias()
984 *value = be16_to_cpu(sfp->diag.txpwr_low_alarm); in sfp_hwmon_tx_power()
989 *value = be16_to_cpu(sfp->diag.txpwr_low_warn); in sfp_hwmon_tx_power()
994 *value = be16_to_cpu(sfp->diag.txpwr_high_warn); in sfp_hwmon_tx_power()
999 *value = be16_to_cpu(sfp->diag.txpwr_high_alarm); in sfp_hwmon_tx_power()
1035 return -EOPNOTSUPP; in sfp_hwmon_tx_power()
1038 return -EOPNOTSUPP; in sfp_hwmon_tx_power()
1051 *value = be16_to_cpu(sfp->diag.rxpwr_low_alarm); in sfp_hwmon_rx_power()
1056 *value = be16_to_cpu(sfp->diag.rxpwr_low_warn); in sfp_hwmon_rx_power()
1061 *value = be16_to_cpu(sfp->diag.rxpwr_high_warn); in sfp_hwmon_rx_power()
1066 *value = be16_to_cpu(sfp->diag.rxpwr_high_alarm); in sfp_hwmon_rx_power()
1102 return -EOPNOTSUPP; in sfp_hwmon_rx_power()
1105 return -EOPNOTSUPP; in sfp_hwmon_rx_power()
1127 return -EOPNOTSUPP; in sfp_hwmon_read()
1130 return -EOPNOTSUPP; in sfp_hwmon_read()
1150 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1159 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1168 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1177 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1181 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1184 return -EOPNOTSUPP; in sfp_hwmon_read_string()
1296 if (sfp->i2c_block_size < 2) { in sfp_hwmon_probe()
1297 dev_info(sfp->dev, in sfp_hwmon_probe()
1299 dev_info(sfp->dev, in sfp_hwmon_probe()
1304 err = sfp_read(sfp, true, 0, &sfp->diag, sizeof(sfp->diag)); in sfp_hwmon_probe()
1306 if (sfp->hwmon_tries--) { in sfp_hwmon_probe()
1307 mod_delayed_work(system_wq, &sfp->hwmon_probe, in sfp_hwmon_probe()
1310 dev_warn(sfp->dev, "hwmon probe failed: %d\n", err); in sfp_hwmon_probe()
1315 sfp->hwmon_name = kstrdup(dev_name(sfp->dev), GFP_KERNEL); in sfp_hwmon_probe()
1316 if (!sfp->hwmon_name) { in sfp_hwmon_probe()
1317 dev_err(sfp->dev, "out of memory for hwmon name\n"); in sfp_hwmon_probe()
1321 for (i = 0; sfp->hwmon_name[i]; i++) in sfp_hwmon_probe()
1322 if (hwmon_is_bad_char(sfp->hwmon_name[i])) in sfp_hwmon_probe()
1323 sfp->hwmon_name[i] = '_'; in sfp_hwmon_probe()
1325 sfp->hwmon_dev = hwmon_device_register_with_info(sfp->dev, in sfp_hwmon_probe()
1326 sfp->hwmon_name, sfp, in sfp_hwmon_probe()
1329 if (IS_ERR(sfp->hwmon_dev)) in sfp_hwmon_probe()
1330 dev_err(sfp->dev, "failed to register hwmon device: %ld\n", in sfp_hwmon_probe()
1331 PTR_ERR(sfp->hwmon_dev)); in sfp_hwmon_probe()
1336 if (sfp->id.ext.sff8472_compliance == SFP_SFF8472_COMPLIANCE_NONE) in sfp_hwmon_insert()
1339 if (!(sfp->id.ext.diagmon & SFP_DIAGMON_DDM)) in sfp_hwmon_insert()
1342 if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) in sfp_hwmon_insert()
1348 mod_delayed_work(system_wq, &sfp->hwmon_probe, 1); in sfp_hwmon_insert()
1349 sfp->hwmon_tries = R_PROBE_RETRY_SLOW; in sfp_hwmon_insert()
1356 cancel_delayed_work_sync(&sfp->hwmon_probe); in sfp_hwmon_remove()
1357 if (!IS_ERR_OR_NULL(sfp->hwmon_dev)) { in sfp_hwmon_remove()
1358 hwmon_device_unregister(sfp->hwmon_dev); in sfp_hwmon_remove()
1359 sfp->hwmon_dev = NULL; in sfp_hwmon_remove()
1360 kfree(sfp->hwmon_name); in sfp_hwmon_remove()
1366 INIT_DELAYED_WORK(&sfp->hwmon_probe, sfp_hwmon_probe); in sfp_hwmon_init()
1373 cancel_delayed_work_sync(&sfp->hwmon_probe); in sfp_hwmon_exit()
1398 dev_dbg(sfp->dev, "tx disable %u -> %u\n", in sfp_module_tx_disable()
1399 sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 1); in sfp_module_tx_disable()
1400 sfp->state |= SFP_F_TX_DISABLE; in sfp_module_tx_disable()
1401 sfp_set_state(sfp, sfp->state); in sfp_module_tx_disable()
1406 dev_dbg(sfp->dev, "tx disable %u -> %u\n", in sfp_module_tx_enable()
1407 sfp->state & SFP_F_TX_DISABLE ? 1 : 0, 0); in sfp_module_tx_enable()
1408 sfp->state &= ~SFP_F_TX_DISABLE; in sfp_module_tx_enable()
1409 sfp_set_state(sfp, sfp->state); in sfp_module_tx_enable()
1414 unsigned int state = sfp->state; in sfp_module_tx_fault_reset()
1430 mod_delayed_work(system_power_efficient_wq, &sfp->timeout, in sfp_sm_set_timer()
1433 cancel_delayed_work(&sfp->timeout); in sfp_sm_set_timer()
1439 sfp->sm_state = state; in sfp_sm_next()
1446 sfp->sm_mod_state = state; in sfp_sm_mod_next()
1452 sfp_remove_phy(sfp->sfp_bus); in sfp_sm_phy_detach()
1453 phy_device_remove(sfp->mod_phy); in sfp_sm_phy_detach()
1454 phy_device_free(sfp->mod_phy); in sfp_sm_phy_detach()
1455 sfp->mod_phy = NULL; in sfp_sm_phy_detach()
1463 phy = get_phy_device(sfp->i2c_mii, SFP_PHY_ADDR, is_c45); in sfp_sm_probe_phy()
1464 if (phy == ERR_PTR(-ENODEV)) in sfp_sm_probe_phy()
1467 dev_err(sfp->dev, "mdiobus scan returned %ld\n", PTR_ERR(phy)); in sfp_sm_probe_phy()
1474 dev_err(sfp->dev, "phy_device_register failed: %d\n", err); in sfp_sm_probe_phy()
1478 err = sfp_add_phy(sfp->sfp_bus, phy); in sfp_sm_probe_phy()
1482 dev_err(sfp->dev, "sfp_add_phy failed: %d\n", err); in sfp_sm_probe_phy()
1486 sfp->mod_phy = phy; in sfp_sm_probe_phy()
1493 sfp_link_up(sfp->sfp_bus); in sfp_sm_link_up()
1499 sfp_link_down(sfp->sfp_bus); in sfp_sm_link_down()
1506 __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); in sfp_sm_link_check_los()
1514 los = !(sfp->state & SFP_F_LOS); in sfp_sm_link_check_los()
1516 los = !!(sfp->state & SFP_F_LOS); in sfp_sm_link_check_los()
1528 __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); in sfp_los_event_active()
1538 __be16 los_options = sfp->id.ext.options & (los_inverted | los_normal); in sfp_los_event_inactive()
1546 if (sfp->sm_fault_retries && !--sfp->sm_fault_retries) { in sfp_sm_fault()
1547 dev_err(sfp->dev, in sfp_sm_fault()
1552 dev_err(sfp->dev, "module transmit fault indicated\n"); in sfp_sm_fault()
1558 /* Probe a SFP for a PHY device if the module supports copper - the PHY
1562 * Clause 22 copper SFP modules normally operate in Cisco SGMII mode with
1563 * negotiation enabled, but some may be in 1000base-X - which is for the
1567 * mode according to the negotiated line speed.
1573 switch (sfp->id.base.extended_cc) { in sfp_sm_probe_for_phy()
1582 if (sfp->id.base.e1000_base_t) in sfp_sm_probe_for_phy()
1594 if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_POWER_DECL)) in sfp_module_parse_power()
1596 if (sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL)) in sfp_module_parse_power()
1599 supports_a2 = sfp->id.ext.sff8472_compliance != in sfp_module_parse_power()
1601 sfp->id.ext.diagmon & SFP_DIAGMON_DDM; in sfp_module_parse_power()
1603 if (power_mW > sfp->max_power_mW) { in sfp_module_parse_power()
1608 * indicated mode. in sfp_module_parse_power()
1610 dev_err(sfp->dev, in sfp_module_parse_power()
1613 return -EINVAL; in sfp_module_parse_power()
1615 dev_warn(sfp->dev, in sfp_module_parse_power()
1616 "Host does not support %u.%uW modules, module left in power mode 1\n", in sfp_module_parse_power()
1624 sfp->module_power_mW = power_mW; in sfp_module_parse_power()
1631 * that the module powers up in the indicated mode. in sfp_module_parse_power()
1636 /* If the module requires a higher power mode, but also requires in sfp_module_parse_power()
1640 if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) { in sfp_module_parse_power()
1641 dev_warn(sfp->dev, in sfp_module_parse_power()
1647 sfp->module_power_mW = power_mW; in sfp_module_parse_power()
1659 dev_err(sfp->dev, "Failed to read EEPROM: %d\n", err); in sfp_sm_mod_hpower()
1660 return -EAGAIN; in sfp_sm_mod_hpower()
1665 * if the bit is already set, we're already in high power mode. in sfp_sm_mod_hpower()
1677 dev_err(sfp->dev, "Failed to write EEPROM: %d\n", err); in sfp_sm_mod_hpower()
1678 return -EAGAIN; in sfp_sm_mod_hpower()
1682 dev_info(sfp->dev, "Module switched to %u.%uW power level\n", in sfp_sm_mod_hpower()
1683 sfp->module_power_mW / 1000, in sfp_sm_mod_hpower()
1684 (sfp->module_power_mW / 100) % 10); in sfp_sm_mod_hpower()
1689 /* GPON modules based on Realtek RTL8672 and RTL9601C chips (e.g. V-SOL
1690 * V2801F, CarlitoxxPro CPGOS03-0490, Ubiquiti U-Fiber Instant, ...) do
1691 * not support multibyte reads from the EEPROM. Each multi-byte read
1694 * chips. Moreover every OEM of V-SOL V2801F module puts its own vendor
1696 * module is V-SOL V2801F. Therefore check for those zeros in the read
1702 size_t i, block_size = sfp->i2c_block_size; in sfp_id_needs_byte_io()
1709 if (memchr_inv(buf + i, '\0', min(block_size - 1, len - i))) in sfp_id_needs_byte_io()
1720 if (id->base.phys_id != SFF8024_ID_SFF_8472 || in sfp_cotsworks_fixup_check()
1721 id->base.phys_ext_id != SFP_PHYS_EXT_ID_SFP || in sfp_cotsworks_fixup_check()
1722 id->base.connector != SFF8024_CONNECTOR_LC) { in sfp_cotsworks_fixup_check()
1723 dev_warn(sfp->dev, "Rewriting fiber module EEPROM with corrected values\n"); in sfp_cotsworks_fixup_check()
1724 id->base.phys_id = SFF8024_ID_SFF_8472; in sfp_cotsworks_fixup_check()
1725 id->base.phys_ext_id = SFP_PHYS_EXT_ID_SFP; in sfp_cotsworks_fixup_check()
1726 id->base.connector = SFF8024_CONNECTOR_LC; in sfp_cotsworks_fixup_check()
1727 err = sfp_write(sfp, false, SFP_PHYS_ID, &id->base, 3); in sfp_cotsworks_fixup_check()
1729 dev_err(sfp->dev, "Failed to rewrite module EEPROM: %d\n", err); in sfp_cotsworks_fixup_check()
1737 check = sfp_check(&id->base, sizeof(id->base) - 1); in sfp_cotsworks_fixup_check()
1740 dev_err(sfp->dev, "Failed to update base structure checksum in fiber module EEPROM: %d\n", err); in sfp_cotsworks_fixup_check()
1749 /* SFP module inserted - read I2C data */ in sfp_sm_mod_probe()
1760 sfp->i2c_block_size = 16; in sfp_sm_mod_probe()
1765 dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret); in sfp_sm_mod_probe()
1766 return -EAGAIN; in sfp_sm_mod_probe()
1770 dev_err(sfp->dev, "EEPROM short read: %d\n", ret); in sfp_sm_mod_probe()
1771 return -EAGAIN; in sfp_sm_mod_probe()
1775 * address 0x51 is just one byte at a time. Also SFF-8472 requires in sfp_sm_mod_probe()
1781 dev_info(sfp->dev, in sfp_sm_mod_probe()
1783 dev_info(sfp->dev, in sfp_sm_mod_probe()
1785 sfp->i2c_block_size = 1; in sfp_sm_mod_probe()
1790 dev_err(sfp->dev, "failed to read EEPROM: %d\n", in sfp_sm_mod_probe()
1792 return -EAGAIN; in sfp_sm_mod_probe()
1796 dev_err(sfp->dev, "EEPROM short read: %d\n", ret); in sfp_sm_mod_probe()
1797 return -EAGAIN; in sfp_sm_mod_probe()
1819 check = sfp_check(&id.base, sizeof(id.base) - 1); in sfp_sm_mod_probe()
1822 dev_warn(sfp->dev, in sfp_sm_mod_probe()
1826 dev_err(sfp->dev, in sfp_sm_mod_probe()
1831 return -EINVAL; in sfp_sm_mod_probe()
1838 dev_err(sfp->dev, "failed to read EEPROM: %d\n", ret); in sfp_sm_mod_probe()
1839 return -EAGAIN; in sfp_sm_mod_probe()
1843 dev_err(sfp->dev, "EEPROM short read: %d\n", ret); in sfp_sm_mod_probe()
1844 return -EAGAIN; in sfp_sm_mod_probe()
1847 check = sfp_check(&id.ext, sizeof(id.ext) - 1); in sfp_sm_mod_probe()
1850 dev_warn(sfp->dev, in sfp_sm_mod_probe()
1854 dev_err(sfp->dev, in sfp_sm_mod_probe()
1863 sfp->id = id; in sfp_sm_mod_probe()
1865 dev_info(sfp->dev, "module %.*s %.*s rev %.*s sn %.*s dc %.*s\n", in sfp_sm_mod_probe()
1873 if (!sfp->type->module_supported(&id)) { in sfp_sm_mod_probe()
1874 dev_err(sfp->dev, in sfp_sm_mod_probe()
1875 "module is not supported - phys id 0x%02x 0x%02x\n", in sfp_sm_mod_probe()
1876 sfp->id.base.phys_id, sfp->id.base.phys_ext_id); in sfp_sm_mod_probe()
1877 return -EINVAL; in sfp_sm_mod_probe()
1880 /* If the module requires address swap mode, warn about it */ in sfp_sm_mod_probe()
1881 if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) in sfp_sm_mod_probe()
1882 dev_warn(sfp->dev, in sfp_sm_mod_probe()
1892 sfp->module_t_start_up = T_START_UP_BAD_GPON; in sfp_sm_mod_probe()
1894 sfp->module_t_start_up = T_START_UP; in sfp_sm_mod_probe()
1901 if (sfp->sm_mod_state > SFP_MOD_WAITDEV) in sfp_sm_mod_remove()
1902 sfp_module_remove(sfp->sfp_bus); in sfp_sm_mod_remove()
1906 memset(&sfp->id, 0, sizeof(sfp->id)); in sfp_sm_mod_remove()
1907 sfp->module_power_mW = 0; in sfp_sm_mod_remove()
1909 dev_info(sfp->dev, "module removed\n"); in sfp_sm_mod_remove()
1915 switch (sfp->sm_dev_state) { in sfp_sm_device()
1918 sfp->sm_dev_state = SFP_DEV_DOWN; in sfp_sm_device()
1923 sfp->sm_dev_state = SFP_DEV_DETACHED; in sfp_sm_device()
1925 sfp->sm_dev_state = SFP_DEV_UP; in sfp_sm_device()
1930 sfp->sm_dev_state = SFP_DEV_DETACHED; in sfp_sm_device()
1932 sfp->sm_dev_state = SFP_DEV_DOWN; in sfp_sm_device()
1938 * the on-board EEPROM, and sets up the power level.
1946 if (sfp->sm_mod_state > SFP_MOD_PROBE) in sfp_sm_module()
1953 if (sfp->sm_dev_state < SFP_DEV_DOWN && in sfp_sm_module()
1954 sfp->sm_mod_state > SFP_MOD_WAITDEV) { in sfp_sm_module()
1955 if (sfp->module_power_mW > 1000 && in sfp_sm_module()
1956 sfp->sm_mod_state > SFP_MOD_HPOWER) in sfp_sm_module()
1962 switch (sfp->sm_mod_state) { in sfp_sm_module()
1966 sfp->sm_mod_tries_init = R_PROBE_RETRY_INIT; in sfp_sm_module()
1967 sfp->sm_mod_tries = R_PROBE_RETRY_SLOW; in sfp_sm_module()
1976 err = sfp_sm_mod_probe(sfp, sfp->sm_mod_tries == 1); in sfp_sm_module()
1977 if (err == -EAGAIN) { in sfp_sm_module()
1978 if (sfp->sm_mod_tries_init && in sfp_sm_module()
1979 --sfp->sm_mod_tries_init) { in sfp_sm_module()
1982 } else if (sfp->sm_mod_tries && --sfp->sm_mod_tries) { in sfp_sm_module()
1983 if (sfp->sm_mod_tries == R_PROBE_RETRY_SLOW - 1) in sfp_sm_module()
1984 dev_warn(sfp->dev, in sfp_sm_module()
1997 dev_warn(sfp->dev, "hwmon probe failed: %d\n", err); in sfp_sm_module()
2003 if (sfp->sm_dev_state < SFP_DEV_DOWN) in sfp_sm_module()
2007 err = sfp_module_insert(sfp->sfp_bus, &sfp->id); in sfp_sm_module()
2014 if (sfp->module_power_mW <= 1000) in sfp_sm_module()
2020 /* Enable high power mode */ in sfp_sm_module()
2023 if (err != -EAGAIN) { in sfp_sm_module()
2024 sfp_module_remove(sfp->sfp_bus); in sfp_sm_module()
2056 if (sfp->sm_state != SFP_S_DOWN && in sfp_sm_main()
2057 (sfp->sm_mod_state != SFP_MOD_PRESENT || in sfp_sm_main()
2058 sfp->sm_dev_state != SFP_DEV_UP)) { in sfp_sm_main()
2059 if (sfp->sm_state == SFP_S_LINK_UP && in sfp_sm_main()
2060 sfp->sm_dev_state == SFP_DEV_UP) in sfp_sm_main()
2062 if (sfp->sm_state > SFP_S_INIT) in sfp_sm_main()
2063 sfp_module_stop(sfp->sfp_bus); in sfp_sm_main()
2064 if (sfp->mod_phy) in sfp_sm_main()
2073 switch (sfp->sm_state) { in sfp_sm_main()
2075 if (sfp->sm_mod_state != SFP_MOD_PRESENT || in sfp_sm_main()
2076 sfp->sm_dev_state != SFP_DEV_UP) in sfp_sm_main()
2079 if (!(sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)) in sfp_sm_main()
2085 sfp->sm_fault_retries = N_FAULT_INIT; in sfp_sm_main()
2098 if (sfp->state & SFP_F_TX_FAULT) { in sfp_sm_main()
2099 /* Wait up to t_init (SFF-8472) or t_start_up (SFF-8431) in sfp_sm_main()
2104 timeout = sfp->module_t_start_up; in sfp_sm_main()
2106 timeout -= T_WAIT; in sfp_sm_main()
2120 if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) { in sfp_sm_main()
2125 sfp->sm_fault_retries == N_FAULT_INIT); in sfp_sm_main()
2128 sfp->sm_phy_retries = R_PHY_RETRY; in sfp_sm_main()
2141 if (ret == -ENODEV) { in sfp_sm_main()
2142 if (--sfp->sm_phy_retries) { in sfp_sm_main()
2146 dev_info(sfp->dev, "no PHY detected\n"); in sfp_sm_main()
2152 if (sfp_module_start(sfp->sfp_bus)) { in sfp_sm_main()
2159 sfp->sm_fault_retries = N_FAULT; in sfp_sm_main()
2165 sfp_sm_next(sfp, SFP_S_INIT, sfp->module_t_start_up); in sfp_sm_main()
2189 sfp_sm_next(sfp, SFP_S_REINIT, sfp->module_t_start_up); in sfp_sm_main()
2194 if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) { in sfp_sm_main()
2197 dev_info(sfp->dev, "module transmit fault recovered\n"); in sfp_sm_main()
2209 mutex_lock(&sfp->sm_mutex); in sfp_sm_event()
2211 dev_dbg(sfp->dev, "SM: enter %s:%s:%s event %s\n", in sfp_sm_event()
2212 mod_state_to_str(sfp->sm_mod_state), in sfp_sm_event()
2213 dev_state_to_str(sfp->sm_dev_state), in sfp_sm_event()
2214 sm_state_to_str(sfp->sm_state), in sfp_sm_event()
2221 dev_dbg(sfp->dev, "SM: exit %s:%s:%s\n", in sfp_sm_event()
2222 mod_state_to_str(sfp->sm_mod_state), in sfp_sm_event()
2223 dev_state_to_str(sfp->sm_dev_state), in sfp_sm_event()
2224 sm_state_to_str(sfp->sm_state)); in sfp_sm_event()
2226 mutex_unlock(&sfp->sm_mutex); in sfp_sm_event()
2253 if (sfp->id.ext.sff8472_compliance && in sfp_module_info()
2254 !(sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)) { in sfp_module_info()
2255 modinfo->type = ETH_MODULE_SFF_8472; in sfp_module_info()
2256 modinfo->eeprom_len = ETH_MODULE_SFF_8472_LEN; in sfp_module_info()
2258 modinfo->type = ETH_MODULE_SFF_8079; in sfp_module_info()
2259 modinfo->eeprom_len = ETH_MODULE_SFF_8079_LEN; in sfp_module_info()
2270 if (ee->len == 0) in sfp_module_eeprom()
2271 return -EINVAL; in sfp_module_eeprom()
2273 first = ee->offset; in sfp_module_eeprom()
2274 last = ee->offset + ee->len; in sfp_module_eeprom()
2277 len -= first; in sfp_module_eeprom()
2288 len -= first; in sfp_module_eeprom()
2289 first -= ETH_MODULE_SFF_8079_LEN; in sfp_module_eeprom()
2320 mutex_lock(&sfp->st_mutex); in sfp_check_state()
2322 changed = state ^ sfp->state; in sfp_check_state()
2327 dev_dbg(sfp->dev, "%s %u -> %u\n", gpio_of_names[i], in sfp_check_state()
2328 !!(sfp->state & BIT(i)), !!(state & BIT(i))); in sfp_check_state()
2330 state |= sfp->state & (SFP_F_TX_DISABLE | SFP_F_RATE_SELECT); in sfp_check_state()
2331 sfp->state = state; in sfp_check_state()
2346 mutex_unlock(&sfp->st_mutex); in sfp_check_state()
2364 if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) || in sfp_poll()
2365 sfp->need_poll) in sfp_poll()
2366 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies); in sfp_poll()
2375 return ERR_PTR(-ENOMEM); in sfp_alloc()
2377 sfp->dev = dev; in sfp_alloc()
2379 mutex_init(&sfp->sm_mutex); in sfp_alloc()
2380 mutex_init(&sfp->st_mutex); in sfp_alloc()
2381 INIT_DELAYED_WORK(&sfp->poll, sfp_poll); in sfp_alloc()
2382 INIT_DELAYED_WORK(&sfp->timeout, sfp_timeout); in sfp_alloc()
2395 cancel_delayed_work_sync(&sfp->poll); in sfp_cleanup()
2396 cancel_delayed_work_sync(&sfp->timeout); in sfp_cleanup()
2397 if (sfp->i2c_mii) { in sfp_cleanup()
2398 mdiobus_unregister(sfp->i2c_mii); in sfp_cleanup()
2399 mdiobus_free(sfp->i2c_mii); in sfp_cleanup()
2401 if (sfp->i2c) in sfp_cleanup()
2402 i2c_put_adapter(sfp->i2c); in sfp_cleanup()
2414 sfp = sfp_alloc(&pdev->dev); in sfp_probe()
2420 err = devm_add_action(sfp->dev, sfp_cleanup, sfp); in sfp_probe()
2424 sff = sfp->type = &sfp_data; in sfp_probe()
2426 if (pdev->dev.of_node) { in sfp_probe()
2427 struct device_node *node = pdev->dev.of_node; in sfp_probe()
2433 return -EINVAL; in sfp_probe()
2435 sff = sfp->type = id->data; in sfp_probe()
2437 np = of_parse_phandle(node, "i2c-bus", 0); in sfp_probe()
2439 dev_err(sfp->dev, "missing 'i2c-bus' property\n"); in sfp_probe()
2440 return -ENODEV; in sfp_probe()
2445 } else if (has_acpi_companion(&pdev->dev)) { in sfp_probe()
2446 struct acpi_device *adev = ACPI_COMPANION(&pdev->dev); in sfp_probe()
2452 ret = acpi_node_get_property_reference(fw, "i2c-bus", 0, &args); in sfp_probe()
2454 dev_err(&pdev->dev, "missing 'i2c-bus' property\n"); in sfp_probe()
2455 return -ENODEV; in sfp_probe()
2461 return -EINVAL; in sfp_probe()
2465 return -EPROBE_DEFER; in sfp_probe()
2474 if (sff->gpios & BIT(i)) { in sfp_probe()
2475 sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev, in sfp_probe()
2477 if (IS_ERR(sfp->gpio[i])) in sfp_probe()
2478 return PTR_ERR(sfp->gpio[i]); in sfp_probe()
2481 sfp->get_state = sfp_gpio_get_state; in sfp_probe()
2482 sfp->set_state = sfp_gpio_set_state; in sfp_probe()
2485 if (!(sfp->gpio[GPIO_MODDEF0])) in sfp_probe()
2486 sfp->get_state = sff_gpio_get_state; in sfp_probe()
2488 device_property_read_u32(&pdev->dev, "maximum-power-milliwatt", in sfp_probe()
2489 &sfp->max_power_mW); in sfp_probe()
2490 if (!sfp->max_power_mW) in sfp_probe()
2491 sfp->max_power_mW = 1000; in sfp_probe()
2493 dev_info(sfp->dev, "Host maximum power %u.%uW\n", in sfp_probe()
2494 sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10); in sfp_probe()
2499 sfp->state = sfp_get_state(sfp) | SFP_F_TX_DISABLE; in sfp_probe()
2501 if (sfp->gpio[GPIO_RATE_SELECT] && in sfp_probe()
2502 gpiod_get_value_cansleep(sfp->gpio[GPIO_RATE_SELECT])) in sfp_probe()
2503 sfp->state |= SFP_F_RATE_SELECT; in sfp_probe()
2504 sfp_set_state(sfp, sfp->state); in sfp_probe()
2506 if (sfp->state & SFP_F_PRESENT) { in sfp_probe()
2513 if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) in sfp_probe()
2516 sfp->gpio_irq[i] = gpiod_to_irq(sfp->gpio[i]); in sfp_probe()
2517 if (sfp->gpio_irq[i] < 0) { in sfp_probe()
2518 sfp->gpio_irq[i] = 0; in sfp_probe()
2519 sfp->need_poll = true; in sfp_probe()
2523 sfp_irq_name = devm_kasprintf(sfp->dev, GFP_KERNEL, in sfp_probe()
2524 "%s-%s", dev_name(sfp->dev), in sfp_probe()
2528 return -ENOMEM; in sfp_probe()
2530 err = devm_request_threaded_irq(sfp->dev, sfp->gpio_irq[i], in sfp_probe()
2537 sfp->gpio_irq[i] = 0; in sfp_probe()
2538 sfp->need_poll = true; in sfp_probe()
2542 if (sfp->need_poll) in sfp_probe()
2543 mod_delayed_work(system_wq, &sfp->poll, poll_jiffies); in sfp_probe()
2547 * be active when the fiber is removed. This could be a safety issue and in sfp_probe()
2550 if (!sfp->gpio[GPIO_TX_DISABLE]) in sfp_probe()
2551 dev_warn(sfp->dev, in sfp_probe()
2554 sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); in sfp_probe()
2555 if (!sfp->sfp_bus) in sfp_probe()
2556 return -ENOMEM; in sfp_probe()
2565 sfp_unregister_socket(sfp->sfp_bus); in sfp_remove()
2580 if (!sfp->gpio_irq[i]) in sfp_shutdown()
2583 devm_free_irq(sfp->dev, sfp->gpio_irq[i], sfp); in sfp_shutdown()
2586 cancel_delayed_work_sync(&sfp->poll); in sfp_shutdown()
2587 cancel_delayed_work_sync(&sfp->timeout); in sfp_shutdown()