/* It takes 3 seconds to fully switch out of loopback mode before * it can safely re-enter loopback mode. Record the time when * loopback is disabled. Check and wait if necessary before loopback * is enabled.
*/
u64 lb_dis_to;
};
staticconststruct { int major; int minor;
} ver_need_sgmii_reaneg[] = {
{7, 0x6D},
{8, 0x6D},
{9, 0x73},
};
#if IS_ENABLED(CONFIG_HWMON) /* The original translation formulae of the temperature (in degrees of Celsius) * are as follows: * * T = -2.5761e-11*(N^4) + 9.7332e-8*(N^3) + -1.9165e-4*(N^2) + * 3.0762e-1*(N^1) + -5.2156e1 * * where [-52.156, 137.961]C and N = [0, 1023]. * * They must be accordingly altered to be suitable for the integer arithmetics. * The technique is called 'factor redistribution', which just makes sure the * multiplications and divisions are made so to have a result of the operations * within the integer numbers limit. In addition we need to translate the * formulae to accept millidegrees of Celsius. Here what it looks like after * the alterations: * * T = -25761e-12*(N^4) + 97332e-9*(N^3) + -191650e-6*(N^2) + * 307620e-3*(N^1) + -52156 * * where T = [-52156, 137961]mC and N = [0, 1023].
*/ staticconststruct polynomial poly_N_to_temp = {
.terms = {
{4, -25761, 1000, 1},
{3, 97332, 1000, 1},
{2, -191650, 1000, 1},
{1, 307620, 1000, 1},
{0, -52156, 1, 1}
}
};
staticint gpy_hwmon_read(struct device *dev, enum hwmon_sensor_types type,
u32 attr, int channel, long *value)
{ struct phy_device *phydev = dev_get_drvdata(dev); int ret;
ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_TEMP_STA); if (ret < 0) return ret; if (!ret) return -ENODATA;
ret = phy_write_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_MBOX_CMD, cmd); if (ret) goto out;
/* The mbox read is used in the interrupt workaround. It was observed * that a read might take up to 2.5ms. This is also the time for which * the interrupt line is stuck low. To be on the safe side, poll the * ready bit for 10ms.
*/
ret = phy_read_mmd_poll_timeout(phydev, MDIO_MMD_VEND1,
VSPEC1_MBOX_CMD, val,
(val & VSPEC1_MBOX_CMD_READY),
500, 10000, false); if (ret) goto out;
ret = phy_read_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_MBOX_DATA);
for (i = 0; i < ARRAY_SIZE(ver_need_sgmii_reaneg); i++) { if (priv->fw_major != ver_need_sgmii_reaneg[i].major) continue; if (priv->fw_minor < ver_need_sgmii_reaneg[i].minor) returntrue; break;
}
returnfalse;
}
staticbool gpy_2500basex_chk(struct phy_device *phydev)
{ int ret;
ret = phy_read(phydev, PHY_MIISTAT); if (ret < 0) {
phydev_err(phydev, "Error: MDIO register access failed: %d\n",
ret); returnfalse;
}
if (!(ret & PHY_MIISTAT_LS) ||
FIELD_GET(PHY_MIISTAT_SPD_MASK, ret) != PHY_MIISTAT_SPD_2500) returnfalse;
switch (ctrl) { case ETH_TP_MDI_AUTO:
val = PHY_CTL1_AMDIX; break; case ETH_TP_MDI_X:
val = (PHY_CTL1_MDIAB | PHY_CTL1_MDICD); break; case ETH_TP_MDI:
val = 0; break; default: return 0;
}
ret = phy_modify(phydev, PHY_CTL1, PHY_CTL1_AMDIX | PHY_CTL1_MDIAB |
PHY_CTL1_MDICD, val); if (ret < 0) return ret;
if (phydev->autoneg == AUTONEG_DISABLE) { /* Configure half duplex with genphy_setup_forced, * because genphy_c45_pma_setup_forced does not support.
*/ return phydev->duplex != DUPLEX_FULL
? genphy_setup_forced(phydev)
: genphy_c45_pma_setup_forced(phydev);
}
ret = gpy_config_mdix(phydev, phydev->mdix_ctrl); if (ret < 0) return ret;
ret = genphy_c45_an_config_aneg(phydev); if (ret < 0) return ret; if (ret > 0)
changed = true;
adv = linkmode_adv_to_mii_ctrl1000_t(phydev->advertising);
ret = phy_modify_changed(phydev, MII_CTRL1000,
ADVERTISE_1000FULL | ADVERTISE_1000HALF,
adv); if (ret < 0) return ret; if (ret > 0)
changed = true;
ret = genphy_c45_check_and_restart_aneg(phydev, changed); if (ret < 0) return ret;
if (phydev->interface == PHY_INTERFACE_MODE_USXGMII ||
phydev->interface == PHY_INTERFACE_MODE_INTERNAL) return 0;
/* No need to trigger re-ANEG if link speed is 2.5G or SGMII ANEG is * disabled.
*/ if (!gpy_sgmii_need_reaneg(phydev) || gpy_2500basex_chk(phydev) ||
!gpy_sgmii_aneg_en(phydev)) return 0;
/* There is a design constraint in GPY2xx device where SGMII AN is * only triggered when there is change of speed. If, PHY link * partner`s speed is still same even after PHY TPI is down and up * again, SGMII AN is not triggered and hence no new in-band message * from GPY to MAC side SGMII. * This could cause an issue during power up, when PHY is up prior to * MAC. At this condition, once MAC side SGMII is up, MAC side SGMII * wouldn`t receive new in-band message from GPY with correct link * status, speed and duplex info. * * 1) If PHY is already up and TPI link status is still down (such as * hard reboot), TPI link status is polled for 4 seconds before * retriggerring SGMII AN. * 2) If PHY is already up and TPI link status is also up (such as soft * reboot), polling of TPI link status is not needed and SGMII AN is * immediately retriggered. * 3) Other conditions such as PHY is down, speed change etc, skip * retriggering SGMII AN. Note: in case of speed change, GPY FW will * initiate SGMII AN.
*/
if (phydev->state != PHY_UP) return 0;
ret = phy_read_poll_timeout(phydev, MII_BMSR, ret, ret & BMSR_LSTATUS,
20000, 4000000, false); if (ret == -ETIMEDOUT) return 0; elseif (ret < 0) return ret;
staticint gpy_update_interface(struct phy_device *phydev)
{ int ret;
/* Interface mode is fixed for USXGMII and integrated PHY */ if (phydev->interface == PHY_INTERFACE_MODE_USXGMII ||
phydev->interface == PHY_INTERFACE_MODE_INTERNAL) return -EINVAL;
/* Automatically switch SERDES interface between SGMII and 2500-BaseX * according to speed. Disable ANEG in 2500-BaseX mode.
*/ switch (phydev->speed) { case SPEED_2500:
phydev->interface = PHY_INTERFACE_MODE_2500BASEX;
ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
VSPEC1_SGMII_CTRL_ANEN, 0); if (ret < 0) {
phydev_err(phydev, "Error: Disable of SGMII ANEG failed: %d\n",
ret); return ret;
} break; case SPEED_1000: case SPEED_100: case SPEED_10:
phydev->interface = PHY_INTERFACE_MODE_SGMII; if (gpy_sgmii_aneg_en(phydev)) break; /* Enable and restart SGMII ANEG for 10/100/1000Mbps link speed * if ANEG is disabled (in 2500-BaseX mode).
*/
ret = phy_modify_mmd(phydev, MDIO_MMD_VEND1, VSPEC1_SGMII_CTRL,
VSPEC1_SGMII_ANEN_ANRS,
VSPEC1_SGMII_ANEN_ANRS); if (ret < 0) {
phydev_err(phydev, "Error: Enable of SGMII ANEG failed: %d\n",
ret); return ret;
} break;
}
if (phydev->speed == SPEED_2500 || phydev->speed == SPEED_1000) {
ret = genphy_read_master_slave(phydev); if (ret < 0) return ret;
}
return gpy_update_mdix(phydev);
}
staticint gpy_read_status(struct phy_device *phydev)
{ int ret;
ret = genphy_update_link(phydev); if (ret) return ret;
/* The PHY might leave the interrupt line asserted even after PHY_ISTAT * is read. To avoid interrupt storms, delay the interrupt handling as * long as the PHY drives the interrupt line. An internal bus read will * stall as long as the interrupt line is asserted, thus just read a * random register here. * Because we cannot access the internal bus at all while the interrupt * is driven by the PHY, there is no way to make the interrupt line * unstuck (e.g. by changing the pinmux to GPIO input) during that time * frame. Therefore, polling is the best we can do and won't do any more * harm. * It was observed that this bug happens on link state and link speed * changes independent of the firmware version.
*/ if (reg & (PHY_IMASK_LSTC | PHY_IMASK_LSPC)) {
reg = gpy_mbox_read(phydev, REG_GPIO0_OUT); if (reg < 0) {
phy_error(phydev); return IRQ_NONE;
}
}
/* Disable the WOL interrupt */
ret = phy_clear_bits(phydev, PHY_IMASK, PHY_IMASK_WOL); if (ret < 0) return ret;
priv->wolopts &= ~WAKE_MAGIC;
}
if (wol->wolopts & WAKE_PHY) { /* Enable the link state change interrupt */
ret = phy_set_bits(phydev, PHY_IMASK, PHY_IMASK_LSTC); if (ret < 0) return ret;
/* Clear the interrupt status register */
ret = phy_read(phydev, PHY_ISTAT); if (ret < 0) return ret;
if (ret & (PHY_IMASK_MASK & ~PHY_IMASK_LSTC))
phy_trigger_machine(phydev);
priv->wolopts |= WAKE_PHY; return 0;
}
priv->wolopts &= ~WAKE_PHY; /* Disable the link state change interrupt */ return phy_clear_bits(phydev, PHY_IMASK, PHY_IMASK_LSTC);
}
staticint gpy_loopback(struct phy_device *phydev, bool enable, int speed)
{ struct gpy_priv *priv = phydev->priv;
u16 set = 0; int ret;
if (enable) {
u64 now = get_jiffies_64();
if (speed) return -EOPNOTSUPP;
/* wait until 3 seconds from last disable */ if (time_before64(now, priv->lb_dis_to))
msleep(jiffies64_to_msecs(priv->lb_dis_to - now));
set = BMCR_LOOPBACK;
}
ret = phy_modify(phydev, MII_BMCR, BMCR_LOOPBACK, set); if (ret <= 0) return ret;
if (enable) { /* It takes some time for PHY device to switch into * loopback mode.
*/
msleep(100);
} else {
priv->lb_dis_to = get_jiffies_64() + HZ * 3;
}
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.