/* t_start_up (SFF-8431) or t_init (SFF-8472) is the time required for a *non-cooledmoduletoinitialiseitslasersafetycircuitry.Wewait *aninitialT_WAITperiodbeforewecheckthetxfaulttogiveanyPHY *onboard(foracopperSFP)timetoinitialise.
*/ #define T_WAIT msecs_to_jiffies(50) #define T_START_UP msecs_to_jiffies(300) #define T_START_UP_BAD_GPON msecs_to_jiffies(60000)
/* t_reset is the time required to assert the TX_DISABLE signal to reset *anindicatedTX_FAULT.
*/ #define T_RESET_US 10 #define T_FAULT_RECOVER msecs_to_jiffies(1000)
/* N_FAULT_INIT is the number of recovery attempts at module initialisation *time.IftheTX_FAULTsignalisnotdeassertedafterthisnumberof *attemptsatclearingit,wedecidethatthemoduleisfaulty. *N_FAULTisthesamebutafterthemodulehasinitialised.
*/ #define N_FAULT_INIT 5 #define N_FAULT 5
/* T_PHY_RETRY is the time interval between attempts to probe the PHY. *R_PHY_RETRYisthenumberofattempts.
*/ #define T_PHY_RETRY msecs_to_jiffies(50) #define R_PHY_RETRY 25
/* SFP module presence detection is poor: the three MOD DEF signals are *thesamelengthonthePCB,whichmeansit'spossibleforMODDEF0to *connectbeforetheI2CbusonMODDEF1/2. * *TheSFF-8472specifiest_serial("Timefrompoweronuntilmoduleis *readyfordatatransmissionoverthetwowireserialbus.")as300ms.
*/ #define T_SERIAL msecs_to_jiffies(300) #define T_HPOWER_LEVEL msecs_to_jiffies(300) #define T_PROBE_RETRY_INIT msecs_to_jiffies(100) #define R_PROBE_RETRY_INIT 10 #define T_PROBE_RETRY_SLOW msecs_to_jiffies(5000) #define R_PROBE_RETRY_SLOW 12
/* SFP modules appear to always have their PHY configured for bus address *0x56(whichwithmdio-i2c,translatestoaPHYaddressof22). *RollBallSFPsaccessphyviaSFPEnhancedDigitalDiagnosticInterface *viaaddress0x51(mdio-i2cwilluseRollBallprotocolonthisaddress).
*/ #define SFP_PHY_ADDR 22 #define SFP_PHY_ADDR_ROLLBALL 17
/* SFP_EEPROM_BLOCK_SIZE is the size of data chunk to read the EEPROM *atatime.SomeSFPmodulesandalsosomeLinuxI2Cdriversdonotlike *readslongerthan16bytes.
*/ #define SFP_EEPROM_BLOCK_SIZE 16
staticvoid sfp_fixup_ignore_los(struct sfp *sfp)
{ /* This forces LOS to zero, so we ignore transitions */
sfp->state_ignore_mask |= SFP_F_LOS; /* Make sure that LOS options are clear */
sfp->id.ext.options &= ~cpu_to_be16(SFP_OPTIONS_LOS_INVERTED |
SFP_OPTIONS_LOS_NORMAL);
}
/* RollBall modules may disallow access to PHY registers for up to 25 *seconds,andthereadsreturn0xffffbeforethat.Increasethetime *betweenPHYproberetriesfrom50msto1ssothatwewillwaitfor *thePHYforasufficientamountoftime.
*/
sfp->phy_t_retry = msecs_to_jiffies(1000);
}
/* The RollBall fixup is not enough for FS modules, the PHY chip inside *themdoesnotreturn0xffffforPHYIDregistersinallMMDsforthe *whileinitializing.Theyneeda4secondwaitbeforeaccessingPHY.
*/
sfp->module_t_wait = msecs_to_jiffies(4000);
}
staticvoid sfp_fixup_halny_gsfp(struct sfp *sfp)
{ /* Ignore the TX_FAULT and LOS signals on this module. *thesearepossiblyusedforotherpurposesonthis *module,e.g.aserialport.
*/
sfp_fixup_ignore_hw(sfp, SFP_F_TX_FAULT | SFP_F_LOS);
}
staticconststruct sfp_quirk sfp_quirks[] = { // Alcatel Lucent G-010S-P can operate at 2500base-X, but incorrectly // report 2500MBd NRZ in their EEPROM
SFP_QUIRK("ALCATELLUCENT", "G010SP", sfp_quirk_2500basex,
sfp_fixup_ignore_tx_fault),
// Alcatel Lucent G-010S-A can operate at 2500base-X, but report 3.2GBd // NRZ in their EEPROM
SFP_QUIRK("ALCATELLUCENT", "3FE46541AA", sfp_quirk_2500basex,
sfp_fixup_nokia),
// FLYPRO SFP-10GT-CS-30M uses Rollball protocol to talk to the PHY.
SFP_QUIRK_F("FLYPRO", "SFP-10GT-CS-30M", sfp_fixup_rollball),
// Fiberstore SFP-10G-T doesn't identify as copper, uses the Rollball // protocol to talk to the PHY and needs 4 sec wait before probing the // PHY.
SFP_QUIRK_F("FS", "SFP-10G-T", sfp_fixup_fs_10gt),
// Fiberstore SFP-2.5G-T and SFP-10GM-T uses Rollball protocol to talk // to the PHY and needs 4 sec wait before probing the PHY.
SFP_QUIRK_F("FS", "SFP-2.5G-T", sfp_fixup_rollball_wait4s),
SFP_QUIRK_F("FS", "SFP-10GM-T", sfp_fixup_rollball_wait4s),
// Fiberstore GPON-ONU-34-20BI can operate at 2500base-X, but report 1.2GBd // NRZ in their EEPROM
SFP_QUIRK("FS", "GPON-ONU-34-20BI", sfp_quirk_2500basex,
sfp_fixup_ignore_tx_fault),
// HG MXPD-483II-F 2.5G supports 2500Base-X, but incorrectly reports // 2600MBd in their EERPOM
SFP_QUIRK_M("HG GENUINE", "MXPD-483II", sfp_quirk_2500basex),
// Huawei MA5671A can operate at 2500base-X, but report 1.2GBd NRZ in // their EEPROM
SFP_QUIRK("HUAWEI", "MA5671A", sfp_quirk_2500basex,
sfp_fixup_ignore_tx_fault),
// Lantech 8330-262D-E can operate at 2500base-X, but incorrectly report // 2500MBd NRZ in their EEPROM
SFP_QUIRK_M("Lantech", "8330-262D-E", sfp_quirk_2500basex),
// Walsun HXSX-ATR[CI]-1 don't identify as copper, and use the // Rollball protocol to talk to the PHY.
SFP_QUIRK_F("Walsun", "HXSX-ATRC-1", sfp_fixup_fs_10gt),
SFP_QUIRK_F("Walsun", "HXSX-ATRI-1", sfp_fixup_fs_10gt),
/* Trailing characters should be filled with space chars, but *somemanufacturerscan'treadSFF-8472anduseNUL.
*/ for (i = 0, size = 0; i < maxlen; i++) if (str[i] != ' ' && str[i] != '\0')
size = i + 1;
if (state & SFP_F_PRESENT) /* If the module is present, drive the requested signals */
drive = sfp->state_hw_drive; else /* Otherwise, let them float to the pull-ups */
drive = 0;
if (sfp->gpio[GPIO_TX_DISABLE]) { if (drive & SFP_F_TX_DISABLE)
gpiod_direction_output(sfp->gpio[GPIO_TX_DISABLE],
state & SFP_F_TX_DISABLE); else
gpiod_direction_input(sfp->gpio[GPIO_TX_DISABLE]);
}
if (sfp->gpio[GPIO_RS0]) { if (drive & SFP_F_RS0)
gpiod_direction_output(sfp->gpio[GPIO_RS0],
state & SFP_F_RS0); else
gpiod_direction_input(sfp->gpio[GPIO_RS0]);
}
if (sfp->gpio[GPIO_RS1]) { if (drive & SFP_F_RS1)
gpiod_direction_output(sfp->gpio[GPIO_RS1],
state & SFP_F_RS1); else
gpiod_direction_input(sfp->gpio[GPIO_RS1]);
}
}
ret = sfp_read(sfp, a2, addr, &old, sizeof(old)); if (ret != sizeof(old)) return ret;
v = (old & ~mask) | (val & mask); if (v == old) returnsizeof(v);
return sfp_write(sfp, a2, addr, &v, sizeof(v));
}
staticunsignedint sfp_soft_get_state(struct sfp *sfp)
{ unsignedint state = 0;
u8 status; int ret;
ret = sfp_read(sfp, true, SFP_STATUS, &status, sizeof(status)); if (ret == sizeof(status)) { if (status & SFP_STATUS_RX_LOS)
state |= SFP_F_LOS; if (status & SFP_STATUS_TX_FAULT)
state |= SFP_F_TX_FAULT;
} else {
dev_err_ratelimited(sfp->dev, "failed to read SFP soft status: %pe\n",
ERR_PTR(ret)); /* Preserve the current state */
state = sfp->state;
}
if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_DISABLE)
mask |= SFP_F_TX_DISABLE; if (id->ext.enhopts & SFP_ENHOPTS_SOFT_TX_FAULT)
mask |= SFP_F_TX_FAULT; if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RX_LOS)
mask |= SFP_F_LOS; if (id->ext.enhopts & SFP_ENHOPTS_SOFT_RATE_SELECT)
mask |= sfp->rs_state_mask;
mutex_lock(&sfp->st_mutex); // Poll the soft state for hardware pins we want to ignore
sfp->state_soft_mask = ~sfp->state_hw_mask & ~sfp->state_ignore_mask &
mask;
/* sfp_get_state() - must be called with st_mutex held, or in the *initialisationpath.
*/ staticunsignedint sfp_get_state(struct sfp *sfp)
{ unsignedint soft = sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT); unsignedint state;
state = sfp->get_state(sfp) & sfp->state_hw_mask; if (state & SFP_F_PRESENT && soft)
state |= sfp_soft_get_state(sfp);
return state;
}
/* sfp_set_state() - must be called with st_mutex held, or in the *initialisationpath.
*/ staticvoid sfp_set_state(struct sfp *sfp, unsignedint state)
{ unsignedint soft;
switch (type) { case hwmon_temp: switch (attr) { case hwmon_temp_min_alarm: case hwmon_temp_max_alarm: case hwmon_temp_lcrit_alarm: case hwmon_temp_crit_alarm: case hwmon_temp_min: case hwmon_temp_max: case hwmon_temp_lcrit: case hwmon_temp_crit: if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) return0;
fallthrough; case hwmon_temp_input: case hwmon_temp_label: return0444; default: return0;
} case hwmon_in: switch (attr) { case hwmon_in_min_alarm: case hwmon_in_max_alarm: case hwmon_in_lcrit_alarm: case hwmon_in_crit_alarm: case hwmon_in_min: case hwmon_in_max: case hwmon_in_lcrit: case hwmon_in_crit: if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) return0;
fallthrough; case hwmon_in_input: case hwmon_in_label: return0444; default: return0;
} case hwmon_curr: switch (attr) { case hwmon_curr_min_alarm: case hwmon_curr_max_alarm: case hwmon_curr_lcrit_alarm: case hwmon_curr_crit_alarm: case hwmon_curr_min: case hwmon_curr_max: case hwmon_curr_lcrit: case hwmon_curr_crit: if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) return0;
fallthrough; case hwmon_curr_input: case hwmon_curr_label: return0444; default: return0;
} case hwmon_power: /* External calibration of receive power requires *floatingpointarithmetic.Doingthatinthekernel *isnoteasy,sojustskipit.Ifthemoduledoes *notrequireexternalcalibration,wecanhowever *showreceiverpower,sinceFPisthennotneeded.
*/ if (sfp->id.ext.diagmon & SFP_DIAGMON_EXT_CAL &&
channel == 1) return0; switch (attr) { case hwmon_power_min_alarm: case hwmon_power_max_alarm: case hwmon_power_lcrit_alarm: case hwmon_power_crit_alarm: case hwmon_power_min: case hwmon_power_max: case hwmon_power_lcrit: case hwmon_power_crit: if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_ALARMWARN)) return0;
fallthrough; case hwmon_power_input: case hwmon_power_label: return0444; default: return0;
} default: return0;
}
}
staticint sfp_hwmon_read_sensor(struct sfp *sfp, int reg, long *value)
{
__be16 val; int err;
/* hwmon interface needs to access 16bit registers in atomic way to *guaranteecoherencyofthediagnosticmonitoringdata.Ifitisnot *possibletoguaranteecoherencybecauseEEPROMisbrokeninsuchway *thatdoesnotsupportatomic16bitreadoperationthenwehaveto *skipregistrationofhwmondevice.
*/ if (sfp->i2c_block_size < 2) {
dev_info(sfp->dev, "skipping hwmon device registration\n");
dev_info(sfp->dev, "diagnostic EEPROM area cannot be read atomically to guarantee data coherency\n"); return;
}
sfp->hwmon_name = hwmon_sanitize_name(dev_name(sfp->dev)); if (IS_ERR(sfp->hwmon_name)) {
dev_err(sfp->dev, "out of memory for hwmon name\n"); return;
}
sfp->hwmon_dev = hwmon_device_register_with_info(sfp->dev,
sfp->hwmon_name, sfp,
&sfp_hwmon_chip_info,
NULL); if (IS_ERR(sfp->hwmon_dev))
dev_err(sfp->dev, "failed to register hwmon device: %ld\n",
PTR_ERR(sfp->hwmon_dev));
}
/* Probe a SFP for a PHY device if the module supports copper - the PHY *normallysitsatI2Cbusaddress0x56,andmayeitherbeaclause22 *orclause45PHY. * *Clause22copperSFPmodulesnormallyoperateinCiscoSGMIImodewith *negotiationenabled,butsomemaybein1000base-X-whichisforthe *PHYdrivertodetermine. * *Clause45copperSFP+modules(10G)appeartoswitchtheirinterface *modeaccordingtothenegotiatedlinespeed.
*/ staticint sfp_sm_probe_for_phy(struct sfp *sfp)
{ int err = 0;
switch (sfp->mdio_protocol) { case MDIO_I2C_NONE: break;
case MDIO_I2C_MARVELL_C22:
err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, false); break;
case MDIO_I2C_C45:
err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR, true); break;
case MDIO_I2C_ROLLBALL:
err = sfp_sm_probe_phy(sfp, SFP_PHY_ADDR_ROLLBALL, true); break;
}
if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV10_2 &&
sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_POWER_DECL))
power_mW = 1500; /* Added in Rev 11.9, but there is no compliance code for this */ if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV11_4 &&
sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_HIGH_POWER_LEVEL))
power_mW = 2000;
/* Power level 1 modules (max. 1W) are always supported. */ if (power_mW <= 1000) {
sfp->module_power_mW = power_mW; return0;
}
if (power_mW > sfp->max_power_mW) { /* Module power specification exceeds the allowed maximum. */ if (!supports_a2) { /* The module appears not to implement bus address *0xa2,soassumethatthemodulepowersupinthe *indicatedmode.
*/
dev_err(sfp->dev, "Host does not support %u.%uW modules\n",
power_mW / 1000, (power_mW / 100) % 10); return -EINVAL;
} else {
dev_warn(sfp->dev, "Host does not support %u.%uW modules, module left in power mode 1\n",
power_mW / 1000, (power_mW / 100) % 10); return0;
}
}
if (!supports_a2) { /* The module power level is below the host maximum and the *moduleappearsnottoimplementbusaddress0xa2,soassume *thatthemodulepowersupintheindicatedmode.
*/ return0;
}
/* If the module requires a higher power mode, but also requires *anaddresschangesequence,warntheuserthatthemodulemay *notbefunctional.
*/ if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE) {
dev_warn(sfp->dev, "Address Change Sequence not supported but module requires %u.%uW, module may not be functional\n",
power_mW / 1000, (power_mW / 100) % 10); return0;
}
sfp->module_power_mW = power_mW;
return0;
}
staticint sfp_sm_mod_hpower(struct sfp *sfp, bool enable)
{ int err;
if (!(sfp->id.ext.options & cpu_to_be16(SFP_OPTIONS_RATE_SELECT))) /* No support for RateSelect */ return;
/* Default to INF-8074 RateSelect operation. The signalling threshold *rateisnotwellspecified,soalwaysselect"FullBandwidth",but *SFF-8079revealsthatitisunderstoodthatRS0willbelowfor *1.0625Gb/sandhighfor2.125Gb/s.Chooseavaluehalf-waybetween. *ThismethodexistspriortoSFF-8472.
*/
sfp->rs_state_mask = SFP_F_RS0;
sfp->rs_threshold_kbd = 1594;
/* Parse the rate identifier, which is complicated due to history: *SFF-8472rev9.5marksthisfieldasreserved. *SFF-8079referencesSFF-8472rev9.5anddefinesbit0.SFF-8472 *complianceisnotrequired. *SFF-8472rev10.2definesthisfieldusingvalues0..4 *SFF-8472rev11.0redefinesthisfieldwithbit0forSFF-8079 *andevenvalues.
*/
rate_id = sfp->id.base.rate_id; if (rate_id == 0) /* Unspecified */ return;
/* SFF-8472 rev 10.0..10.4 did not account for SFF-8079 using bit 0, *andallocatedvalue3toSFF-8431independenttx/rxrateselect. *ConvertthistoaSFF-8472rev11.0rateidentifier.
*/ if (sfp->id.ext.sff8472_compliance >= SFP_SFF8472_COMPLIANCE_REV10_2 &&
sfp->id.ext.sff8472_compliance < SFP_SFF8472_COMPLIANCE_REV11_0 &&
rate_id == 3)
rate_id = SFF_RID_8431;
if (rate_id & SFF_RID_8079) { /* SFF-8079 RateSelect / Application Select in conjunction with *SFF-8472rev9.5.SFF-8079definesrate_idasabitfield *withonlybit0used,whichtakesprecedenceoverSFF-8472.
*/ if (!(sfp->id.ext.enhopts & SFP_ENHOPTS_APP_SELECT_SFF8079)) { /* SFF-8079 Part 1 - rate selection between Fibre *Channel1.0625/2.125/4.25Gbdmodes.NotethatRS0 *ishighfor2125,sowehavetosubtract1to *includeit.
*/
sfp->rs_threshold_kbd = 2125 - 1;
sfp->rs_state_mask = SFP_F_RS0;
} return;
}
/* SFF-8472 rev 9.5 does not define the rate identifier */ if (sfp->id.ext.sff8472_compliance <= SFP_SFF8472_COMPLIANCE_REV9_5) return;
/* SFF-8472 rev 11.0 defines rate_id as a numerical value which will *alwayshavebit0clearduetoSFF-8079'sbitfieldusageofrate_id.
*/ switch (rate_id) { case SFF_RID_8431_RX_ONLY:
sfp->rs_threshold_kbd = 4250;
sfp->rs_state_mask = SFP_F_RS0; break;
case SFF_RID_8431_TX_ONLY:
sfp->rs_threshold_kbd = 4250;
sfp->rs_state_mask = SFP_F_RS1; break;
/* Cotsworks modules have been found to require a delay between write operations. */
mdelay(50);
/* Update base structure checksum */
check = sfp_check(&id->base, sizeof(id->base) - 1);
err = sfp_write(sfp, false, SFP_CC_BASE, &check, 1); if (err != 1) {
dev_err(sfp->dev, "Failed to update base structure checksum in fiber module EEPROM: %pe\n",
ERR_PTR(err)); return err;
}
} return0;
}
staticint sfp_module_parse_sff8472(struct sfp *sfp)
{ /* If the module requires address swap mode, warn about it */ if (sfp->id.ext.diagmon & SFP_DIAGMON_ADDRMODE)
dev_warn(sfp->dev, "module address swap to access page 0xA2 is not supported.\n"); else
sfp->have_a2 = true;
ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base)); if (ret < 0) { if (report)
dev_err(sfp->dev, "failed to read EEPROM: %pe\n",
ERR_PTR(ret)); return -EAGAIN;
}
if (ret != sizeof(id.base)) {
dev_err(sfp->dev, "EEPROM short read: %pe\n", ERR_PTR(ret)); return -EAGAIN;
}
/* Some SFP modules (e.g. Nokia 3FE46541AA) lock up if read from *address0x51isjustonebyteatatime.AlsoSFF-8472requires *thatEEPROMsupportsatomic16bitreadoperationfordiagnostic *fields,sodonotswitchtoonebytereadingatatimeunlessit *isreallyrequiredandwehavenootheroption.
*/ if (sfp_id_needs_byte_io(sfp, &id.base, sizeof(id.base))) {
dev_info(sfp->dev, "Detected broken RTL8672/RTL9601C emulated EEPROM\n");
dev_info(sfp->dev, "Switching to reading EEPROM to one byte at a time\n");
sfp->i2c_block_size = 1;
ret = sfp_read(sfp, false, 0, &id.base, sizeof(id.base)); if (ret < 0) { if (report)
dev_err(sfp->dev, "failed to read EEPROM: %pe\n",
ERR_PTR(ret)); return -EAGAIN;
}
if (ret != sizeof(id.base)) {
dev_err(sfp->dev, "EEPROM short read: %pe\n",
ERR_PTR(ret)); return -EAGAIN;
}
}
/* Cotsworks do not seem to update the checksums when they *dothefinalprogrammingwiththefinalmodulepartnumber, *serialnumberanddatecode.
*/
cotsworks = !memcmp(id.base.vendor_name, "COTSWORKS ", 16);
cotsworks_sfbg = !memcmp(id.base.vendor_pn, "SFBG", 4);
/* Cotsworks SFF module EEPROM do not always have valid phys_id, *phys_ext_id,andconnectorbytes.RewriteSFFEEPROMbytesif *CotsworksPNmatchesandbytesarenotcorrect.
*/ if (cotsworks && cotsworks_sfbg) {
ret = sfp_cotsworks_fixup_check(sfp, &id); if (ret < 0) return ret;
}
/* Validate the checksum over the base structure */
check = sfp_check(&id.base, sizeof(id.base) - 1); if (check != id.base.cc_base) { if (cotsworks) {
dev_warn(sfp->dev, "EEPROM base structure checksum failure (0x%02x != 0x%02x)\n",
check, id.base.cc_base);
} else {
dev_err(sfp->dev, "EEPROM base structure checksum failure: 0x%02x != 0x%02x\n",
check, id.base.cc_base);
print_hex_dump(KERN_ERR, "sfp EE: ", DUMP_PREFIX_OFFSET, 16, 1, &id, sizeof(id), true); return -EINVAL;
}
}
ret = sfp_read(sfp, false, SFP_CC_BASE + 1, &id.ext, sizeof(id.ext)); if (ret < 0) { if (report)
dev_err(sfp->dev, "failed to read EEPROM: %pe\n",
ERR_PTR(ret)); return -EAGAIN;
}
if (ret != sizeof(id.ext)) {
dev_err(sfp->dev, "EEPROM short read: %pe\n", ERR_PTR(ret)); return -EAGAIN;
}
dev_info(sfp->dev, "module %.*s %.*s rev %.*s sn %.*s dc %.*s\n",
(int)sizeof(id.base.vendor_name), id.base.vendor_name,
(int)sizeof(id.base.vendor_pn), id.base.vendor_pn,
(int)sizeof(id.base.vendor_rev), id.base.vendor_rev,
(int)sizeof(id.ext.vendor_sn), id.ext.vendor_sn,
(int)sizeof(id.ext.datecode), id.ext.datecode);
/* Check whether we support this module */ if (!sfp->type->module_supported(&id)) {
dev_err(sfp->dev, "module is not supported - phys id 0x%02x 0x%02x\n",
sfp->id.base.phys_id, sfp->id.base.phys_ext_id); return -EINVAL;
}
if (sfp->id.ext.sff8472_compliance != SFP_SFF8472_COMPLIANCE_NONE) {
ret = sfp_module_parse_sff8472(sfp); if (ret < 0) return ret;
}
/* Parse the module power requirement */
ret = sfp_module_parse_power(sfp); if (ret < 0) return ret;
sfp_module_parse_rate_select(sfp);
mask = SFP_F_PRESENT; if (sfp->gpio[GPIO_TX_DISABLE])
mask |= SFP_F_TX_DISABLE; if (sfp->gpio[GPIO_TX_FAULT])
mask |= SFP_F_TX_FAULT; if (sfp->gpio[GPIO_LOS])
mask |= SFP_F_LOS; if (sfp->gpio[GPIO_RS0])
mask |= SFP_F_RS0; if (sfp->gpio[GPIO_RS1])
mask |= SFP_F_RS1;
/* This state machine tracks the upstream's state */ staticvoid sfp_sm_device(struct sfp *sfp, unsignedint event)
{ switch (sfp->sm_dev_state) { default: if (event == SFP_E_DEV_ATTACH)
sfp->sm_dev_state = SFP_DEV_DOWN; break;
case SFP_DEV_DOWN: if (event == SFP_E_DEV_DETACH)
sfp->sm_dev_state = SFP_DEV_DETACHED; elseif (event == SFP_E_DEV_UP)
sfp->sm_dev_state = SFP_DEV_UP; break;
case SFP_DEV_UP: if (event == SFP_E_DEV_DETACH)
sfp->sm_dev_state = SFP_DEV_DETACHED; elseif (event == SFP_E_DEV_DOWN)
sfp->sm_dev_state = SFP_DEV_DOWN; break;
}
}
/* This state machine tracks the insert/remove state of the module, probes *theon-boardEEPROM,andsetsupthepowerlevel.
*/ staticvoid sfp_sm_module(struct sfp *sfp, unsignedint event)
{ int err;
/* Handle remove event globally, it resets this state machine */ if (event == SFP_E_REMOVE) {
sfp_sm_mod_remove(sfp);
sfp_sm_mod_next(sfp, SFP_MOD_EMPTY, 0); return;
}
sfp_sm_mod_next(sfp, SFP_MOD_WAITDEV, 0);
fallthrough; case SFP_MOD_WAITDEV: /* Ensure that the device is attached before proceeding */ if (sfp->sm_dev_state < SFP_DEV_DOWN) break;
/* Report the module insertion to the upstream device */
err = sfp_module_insert(sfp->sfp_bus, &sfp->id,
sfp->quirk); if (err < 0) {
sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0); break;
}
/* If this is a power level 1 module, we are done */ if (sfp->module_power_mW <= 1000) goto insert;
sfp_sm_mod_next(sfp, SFP_MOD_HPOWER, 0);
fallthrough; case SFP_MOD_HPOWER: /* Enable high power mode */
err = sfp_sm_mod_hpower(sfp, true); if (err < 0) { if (err != -EAGAIN) {
sfp_module_remove(sfp->sfp_bus);
sfp_sm_mod_next(sfp, SFP_MOD_ERROR, 0);
} else {
sfp_sm_set_timer(sfp, T_PROBE_RETRY_INIT);
} break;
}
/* Some events are global */ if (sfp->sm_state != SFP_S_DOWN &&
(sfp->sm_mod_state != SFP_MOD_PRESENT ||
sfp->sm_dev_state != SFP_DEV_UP)) { if (sfp->sm_state == SFP_S_LINK_UP &&
sfp->sm_dev_state == SFP_DEV_UP)
sfp_sm_link_down(sfp); if (sfp->sm_state > SFP_S_INIT)
sfp_module_stop(sfp->sfp_bus); if (sfp->mod_phy)
sfp_sm_phy_detach(sfp); if (sfp->i2c_mii)
sfp_i2c_mdiobus_destroy(sfp);
sfp_module_tx_disable(sfp);
sfp_soft_stop_poll(sfp);
sfp_sm_next(sfp, SFP_S_DOWN, 0); return;
}
/* The main state machine */ switch (sfp->sm_state) { case SFP_S_DOWN: if (sfp->sm_mod_state != SFP_MOD_PRESENT ||
sfp->sm_dev_state != SFP_DEV_UP) break;
/* Only use the soft state bits if we have access to the A2h *memory,whichimpliesthatwehavesomelevelofSFF-8472 *compliance.
*/ if (sfp->have_a2)
sfp_soft_start_poll(sfp);
sfp_module_tx_enable(sfp);
/* Initialise the fault clearance retries */
sfp->sm_fault_retries = N_FAULT_INIT;
/* We need to check the TX_FAULT state, which is not defined *whileTX_DISABLEisasserted.Theearliestwewanttodo *anything(suchasprobeforaPHY)is50ms(ormoreon *specificmodules).
*/
sfp_sm_next(sfp, SFP_S_WAIT, sfp->module_t_wait); break;
case SFP_S_WAIT: if (event != SFP_E_TIMEOUT) break;
if (sfp->state & SFP_F_TX_FAULT) { /* Wait up to t_init (SFF-8472) or t_start_up (SFF-8431) *fromtheTX_DISABLEdeassertionforthemoduleto *initialise,whichisindicatedbyTX_FAULT *deasserting.
*/
timeout = sfp->module_t_start_up; if (timeout > sfp->module_t_wait)
timeout -= sfp->module_t_wait; else
timeout = 1;
sfp_sm_next(sfp, SFP_S_INIT, timeout);
} else { /* TX_FAULT is not asserted, assume the module has *finishedinitialising.
*/ goto init_done;
} break;
case SFP_S_INIT: if (event == SFP_E_TIMEOUT && sfp->state & SFP_F_TX_FAULT) { /* TX_FAULT is still asserted after t_init *ort_start_up,soassumethereisafault.
*/
sfp_sm_fault(sfp, SFP_S_INIT_TX_FAULT,
sfp->sm_fault_retries == N_FAULT_INIT);
} elseif (event == SFP_E_TIMEOUT || event == SFP_E_TX_CLEAR) {
init_done: /* Create mdiobus and start trying for PHY */
ret = sfp_sm_add_mdio_bus(sfp); if (ret < 0) {
sfp_sm_next(sfp, SFP_S_FAIL, 0); break;
}
sfp->sm_phy_retries = R_PHY_RETRY; goto phy_probe;
} break;
case SFP_S_INIT_PHY: if (event != SFP_E_TIMEOUT) break;
phy_probe: /* TX_FAULT deasserted or we timed out with TX_FAULT *clear.ProbeforthePHYandchecktheLOSstate.
*/
ret = sfp_sm_probe_for_phy(sfp); if (ret == -ENODEV) { if (--sfp->sm_phy_retries) {
sfp_sm_next(sfp, SFP_S_INIT_PHY,
sfp->phy_t_retry);
dev_dbg(sfp->dev, "no PHY detected, %u tries left\n",
sfp->sm_phy_retries); break;
} else {
dev_info(sfp->dev, "no PHY detected\n");
}
} elseif (ret) {
sfp_sm_next(sfp, SFP_S_FAIL, 0); break;
} if (sfp_module_start(sfp->sfp_bus)) {
sfp_sm_next(sfp, SFP_S_FAIL, 0); break;
}
sfp_sm_link_check_los(sfp);
staticint sfp_module_eeprom(struct sfp *sfp, struct ethtool_eeprom *ee,
u8 *data)
{ unsignedint first, last, len; int ret;
if (!(sfp->state & SFP_F_PRESENT)) return -ENODEV;
if (ee->len == 0) return -EINVAL;
first = ee->offset;
last = ee->offset + ee->len; if (first < ETH_MODULE_SFF_8079_LEN) {
len = min_t(unsignedint, last, ETH_MODULE_SFF_8079_LEN);
len -= first;
ret = sfp_read(sfp, false, first, data, len); if (ret < 0) return ret;
first += len;
data += len;
} if (first < ETH_MODULE_SFF_8472_LEN && last > ETH_MODULE_SFF_8079_LEN) {
len = min_t(unsignedint, last, ETH_MODULE_SFF_8472_LEN);
len -= first;
first -= ETH_MODULE_SFF_8079_LEN;
ret = sfp_read(sfp, true, first, data, len); if (ret < 0) return ret;
} return0;
}
// st_mutex doesn't need to be held here for state_soft_mask, // it's unimportant if we race while reading this. if (sfp->state_soft_mask & (SFP_F_LOS | SFP_F_TX_FAULT) ||
sfp->need_poll)
mod_delayed_work(system_wq, &sfp->poll, poll_jiffies);
}
sff = device_get_match_data(sfp->dev); if (!sff)
sff = &sfp_data;
sfp->type = sff;
err = sfp_i2c_get(sfp); if (err) return err;
for (i = 0; i < GPIO_MAX; i++) if (sff->gpios & BIT(i)) {
sfp->gpio[i] = devm_gpiod_get_optional(sfp->dev,
gpio_names[i], gpio_flags[i]); if (IS_ERR(sfp->gpio[i])) return PTR_ERR(sfp->gpio[i]);
}
/* Modules that have no detect signal are always present */ if (!(sfp->gpio[GPIO_MODDEF0]))
sfp->get_state = sff_gpio_get_state;
device_property_read_u32(&pdev->dev, "maximum-power-milliwatt",
&sfp->max_power_mW); if (sfp->max_power_mW < 1000) { if (sfp->max_power_mW)
dev_warn(sfp->dev, "Firmware bug: host maximum power should be at least 1W\n");
sfp->max_power_mW = 1000;
}
dev_info(sfp->dev, "Host maximum power %u.%uW\n",
sfp->max_power_mW / 1000, (sfp->max_power_mW / 100) % 10);
/* Get the initial state, and always signal TX disable, *sincethenetworkinterfacewillnotbeup.
*/
sfp->state = sfp_get_state(sfp) | SFP_F_TX_DISABLE;
if (sfp->gpio[GPIO_RS0] &&
gpiod_get_value_cansleep(sfp->gpio[GPIO_RS0]))
sfp->state |= SFP_F_RS0;
sfp_set_state(sfp, sfp->state);
sfp_module_tx_disable(sfp); if (sfp->state & SFP_F_PRESENT) {
rtnl_lock();
sfp_sm_event(sfp, SFP_E_INSERT);
rtnl_unlock();
}
for (i = 0; i < GPIO_MAX; i++) { if (gpio_flags[i] != GPIOD_IN || !sfp->gpio[i]) continue;
if (sfp->need_poll)
mod_delayed_work(system_wq, &sfp->poll, poll_jiffies);
/* We could have an issue in cases no Tx disable pin is available or *wiredasmodulesusingalaserastheirlightsourcewillcontinueto *beactivewhenthefiberisremoved.Thiscouldbeasafetyissueand *weshouldatleastwarntheuseraboutthat.
*/ if (!sfp->gpio[GPIO_TX_DISABLE])
dev_warn(sfp->dev, "No tx_disable pin: SFP modules will always be emitting.\n");
sfp->sfp_bus = sfp_register_socket(sfp->dev, sfp, &sfp_module_ops); if (!sfp->sfp_bus) return -ENOMEM;
if (sfp->i2c_max_block_size < 2)
dev_warn(sfp->dev, "Please note:\n" "This SFP cage is accessed via an SMBus only capable of single byte\n" "transactions. Some features are disabled, other may be unreliable or\n" "sporadically fail. Use with caution. There is nothing that the kernel\n" "or community can do to fix it, the kernel will try best efforts. Please\n" "verify any problems on hardware that supports multi-byte I2C transactions.\n");
¤ Diese beiden folgenden Angebotsgruppen bietet das Unternehmen0.43Angebot
(Wie Sie bei der Firma Beratungs- und Dienstleistungen beauftragen können 2026-09-29)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.