mirror of
https://github.com/openwrt/openwrt.git
synced 2026-12-05 21:45:42 +04:00
realtek: phy: set up coupled RTL8214QF together
Two RTL8214QF can share one XSGMII SerDes: the primary connects to the switch, the secondary reaches it through a link from its SerDes S0 to S1 of the primary. On an Acorid GLS7700-24F8G-4X that link stayed down after 2 of 6 cold power-ons (about half with earlier setups); the four ports of the secondary then passed no traffic while reporting a link, and no SerDes reset brought the link up. The vendor SDK finishes the setup of every chip with a write of 6 to register 21 of page 1, which reads back as 0 and so is missing from the register tables taken from dumps. On a pair left without its link, that write on both chips trained it within 110 ms. With it in the setup, the link came up in 8 of 8 cold power-ons, without a reset of the PHYs from the SoC. Require a PHY package node for the RTL8214QF, which no board in tree uses yet, and describe coupled chips as one package of eight ports, the secondary at its base address and the primary 4 above, as on that board. Set up both chips of a package in one pass, through its first port, as setting them up one by one, in the order the kernel attaches them, lost the link in about 5% of the trainings: the primary changes S1 after the secondary trained. For coupled chips, confirmed by their chip modes, keep the ports that joined the package powered down meanwhile: in tests with resets of the PHYs, the link dropped again after about a quarter of them while a port of the pair received a signal, and after none of 210 with the ports down. Then wait for the link and log it if it does not come up. Two chips whose modes are not those of coupled chips are logged and set up on their own. A package of four ports holds one chip. Rename the master and slave of the vendor SDK to primary and secondary. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Anatoliy Oleinikov <admin@wizle.tech> Link: https://github.com/openwrt/openwrt/pull/27024 Signed-off-by: Markus Stockhausen <markus.stockhausen@gmx.de>
This commit is contained in:
1 parent
043410a272
commit
0fed45c617
1 file changed
+206
-30
@@ -8,6 +8,7 @@
|
||||
#include <linux/bitfield.h>
|
||||
#include <linux/delay.h>
|
||||
#include <linux/ethtool_netlink.h>
|
||||
#include <linux/iopoll.h>
|
||||
#include <linux/of.h>
|
||||
#include <linux/phy.h>
|
||||
#include <linux/netdevice.h>
|
||||
@@ -81,7 +82,7 @@
|
||||
struct rtl821x_shared_priv {
|
||||
int base_addr;
|
||||
unsigned long ports; /* the PHYs that joined, by their offset from base_addr */
|
||||
bool setup_done; /* the chip has been set up (RTL8214QF) */
|
||||
bool setup_done; /* the package has been set up (RTL8214QF) */
|
||||
};
|
||||
|
||||
struct rtl8214fc_priv {
|
||||
@@ -452,14 +453,36 @@ static int rtl8214fc_read_status(struct phy_device *phydev)
|
||||
/*
|
||||
* RTL8214QF: quad 1000BASE-X fibre PHY with clause 37 registers, documented with a QSGMII
|
||||
* interface. Two of them can also share one XSGMII SerDes, as on the Acorid GLS7700-24F8G-4X: the
|
||||
* master carries all eight ports, the slave reaches it through the master (slave SerDes S0 to
|
||||
* master S1). Only that setup is tested, and the link between the two chips only trains when
|
||||
* they leave reset. Pages: 0x1xx SerDes S0, 0x3xx S1, 0x400-0x7ff the SerDes of ports 0-3.
|
||||
* primary carries all eight ports to the switch, the secondary reaches it through the primary
|
||||
* (secondary SerDes S0 to primary S1). Each chip is described in a PHY package node; coupled chips
|
||||
* share one of eight ports, the secondary at its base address and the primary 4 above. Only that
|
||||
* setup is tested. Pages: 0x1xx SerDes S0, 0x3xx S1, 0x400-0x7ff the SerDes of ports 0-3.
|
||||
* Undocumented registers follow the vendor SDK.
|
||||
*/
|
||||
#define RTL8214QF_PORTS 4
|
||||
#define RTL8214QF_PACKAGE_CHIPS 2
|
||||
#define RTL8214QF_PACKAGE_PORTS (RTL8214QF_PACKAGE_CHIPS * RTL8214QF_PORTS)
|
||||
|
||||
#define RTL8214QF_CHIP_MODE 0x11 /* page 0 */
|
||||
#define RTL8214QF_CHIP_MODE_MASK GENMASK(3, 0)
|
||||
#define RTL8214QF_CHIP_MODE_SLAVE 0xb
|
||||
#define RTL8214QF_CHIP_MODE_SECONDARY 0xb
|
||||
#define RTL8214QF_CHIP_MODE_PRIMARY 0xd
|
||||
|
||||
/*
|
||||
* Write-only. The vendor SDK writes 6 to finish the setup of a chip; it also (re)trains the link
|
||||
* between coupled chips, which no SerDes reset does once the link failed to train.
|
||||
*/
|
||||
#define RTL8214QF_SDS_START 0x15 /* page 1 */
|
||||
#define RTL8214QF_SDS_START_ALL 0x6
|
||||
|
||||
#define RTL8214QF_PAGE_S0_STATUS 0x107
|
||||
#define RTL8214QF_PAGE_S1_STATUS 0x307
|
||||
#define RTL8214QF_SDS_STATUS 0x15
|
||||
#define RTL8214QF_SDS_STATUS_SYNC GENMASK(8, 0) /* all XSGMII channels in sync */
|
||||
|
||||
/* The link between coupled chips is in sync within about 100 ms of a start */
|
||||
#define RTL8214QF_LINK_SYNC_POLL_US (10 * USEC_PER_MSEC)
|
||||
#define RTL8214QF_LINK_SYNC_TIMEOUT_US (500 * USEC_PER_MSEC)
|
||||
|
||||
#define RTL8214QF_PAGE_FIBRE_CTRL 0x5
|
||||
#define RTL8214QF_FIBRE_CTRL(port) (0x14 + (port))
|
||||
@@ -482,7 +505,7 @@ static int rtl8214fc_read_status(struct phy_device *phydev)
|
||||
|
||||
/*
|
||||
* Net effect of the vendor SDK patch sequence, measured by register dumps after a cold power-on
|
||||
* and after the vendor firmware setup: the changes common to all chips, and those of the master
|
||||
* and after the vendor firmware setup: the changes common to all chips, and those of a primary
|
||||
* only. Registers that ignore writes are left out. Without it autonegotiation never completes.
|
||||
*/
|
||||
static const struct rtl821x_reg_sequence rtl8214qf_init_common[] = {
|
||||
@@ -516,7 +539,7 @@ static const struct rtl821x_reg_sequence rtl8214qf_init_common[] = {
|
||||
{ 0x789, 20, 0xe002 }, { 0x790, 19, 0x5cd8 }, { 0x791, 20, 0xe002 },
|
||||
};
|
||||
|
||||
static const struct rtl821x_reg_sequence rtl8214qf_init_master[] = {
|
||||
static const struct rtl821x_reg_sequence rtl8214qf_init_primary[] = {
|
||||
{ 0x389, 20, 0x2527 }, { 0x38b, 16, 0x3e48 }, { 0x38b, 22, 0x7ffa },
|
||||
{ 0x38d, 17, 0xffd0 }, { 0x38d, 19, 0x7c17 }, { 0x38d, 20, 0x002d },
|
||||
{ 0x3b9, 20, 0x2527 }, { 0x3bb, 16, 0x3e48 }, { 0x3bb, 22, 0x7ffa },
|
||||
@@ -598,32 +621,44 @@ static int __rtl8214qf_port_sds_reset(struct phy_device *base, int port)
|
||||
return __rtl8214qf_fibre_rx_reset(base, port);
|
||||
}
|
||||
|
||||
static int __rtl8214qf_chip_init(struct phy_device *base)
|
||||
static int __rtl8214qf_start(struct phy_device *chip)
|
||||
{
|
||||
int mode, ret;
|
||||
return __rtl821x_write_paged(chip, 1, RTL8214QF_SDS_START, RTL8214QF_SDS_START_ALL);
|
||||
}
|
||||
|
||||
mode = __rtl821x_read_paged(base, 0, RTL8214QF_CHIP_MODE);
|
||||
if (mode < 0)
|
||||
return mode;
|
||||
static int __rtl8214qf_chip_mode(struct phy_device *chip)
|
||||
{
|
||||
int mode = __rtl821x_read_paged(chip, RTL8XXX_PAGE_MAIN, RTL8214QF_CHIP_MODE);
|
||||
|
||||
ret = __rtl821x_multi_reg_write(base, rtl8214qf_init_common,
|
||||
return mode < 0 ? mode : FIELD_GET(RTL8214QF_CHIP_MODE_MASK, mode);
|
||||
}
|
||||
|
||||
static int __rtl8214qf_chip_init(struct phy_device *chip, int mode)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = __rtl821x_multi_reg_write(chip, rtl8214qf_init_common,
|
||||
ARRAY_SIZE(rtl8214qf_init_common));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
if (FIELD_GET(RTL8214QF_CHIP_MODE_MASK, mode) != RTL8214QF_CHIP_MODE_SLAVE) {
|
||||
ret = __rtl821x_multi_reg_write(base, rtl8214qf_init_master,
|
||||
ARRAY_SIZE(rtl8214qf_init_master));
|
||||
if (mode != RTL8214QF_CHIP_MODE_SECONDARY) {
|
||||
ret = __rtl821x_multi_reg_write(chip, rtl8214qf_init_primary,
|
||||
ARRAY_SIZE(rtl8214qf_init_primary));
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
|
||||
ret = __rtl8214qf_s0_reset(base);
|
||||
ret = __rtl8214qf_s0_reset(chip);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
for (int port = 0; port < 4; port++) {
|
||||
ret = __rtl8214qf_port_sds_reset(base, port);
|
||||
ret = __rtl8214qf_start(chip);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
|
||||
for (int port = 0; port < RTL8214QF_PORTS; port++) {
|
||||
ret = __rtl8214qf_port_sds_reset(chip, port);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
}
|
||||
@@ -631,11 +666,152 @@ static int __rtl8214qf_chip_init(struct phy_device *base)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Powers @ports of the package of @base down; @down records those it has powered down */
|
||||
static int __rtl8214qf_ports_power_down(struct phy_device *base, unsigned long ports,
|
||||
unsigned long *down)
|
||||
{
|
||||
unsigned int port;
|
||||
int ret;
|
||||
|
||||
for_each_set_bit(port, &ports, RTL8214QF_PACKAGE_PORTS) {
|
||||
ret = __mdiobus_modify_changed(base->mdio.bus, base->mdio.addr + port, MII_BMCR,
|
||||
BMCR_PDOWN, BMCR_PDOWN);
|
||||
if (ret < 0)
|
||||
return ret;
|
||||
if (ret)
|
||||
*down |= BIT(port);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int __rtl8214qf_ports_power_up(struct phy_device *base, unsigned long down)
|
||||
{
|
||||
unsigned int port;
|
||||
int ret = 0, err;
|
||||
|
||||
for_each_set_bit(port, &down, RTL8214QF_PACKAGE_PORTS) {
|
||||
err = __mdiobus_modify(base->mdio.bus, base->mdio.addr + port, MII_BMCR,
|
||||
BMCR_PDOWN, 0);
|
||||
if (!ret)
|
||||
ret = err;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/* Returns 1 if both ends of the link between coupled chips are in sync, 0 if not, or an error */
|
||||
static int __rtl8214qf_link_synced(struct phy_device *secondary, struct phy_device *primary)
|
||||
{
|
||||
int s0, s1;
|
||||
|
||||
s0 = __rtl821x_read_paged(secondary, RTL8214QF_PAGE_S0_STATUS, RTL8214QF_SDS_STATUS);
|
||||
if (s0 < 0)
|
||||
return s0;
|
||||
|
||||
s1 = __rtl821x_read_paged(primary, RTL8214QF_PAGE_S1_STATUS, RTL8214QF_SDS_STATUS);
|
||||
if (s1 < 0)
|
||||
return s1;
|
||||
|
||||
return (s0 & s1 & RTL8214QF_SDS_STATUS_SYNC) == RTL8214QF_SDS_STATUS_SYNC;
|
||||
}
|
||||
|
||||
/* Returns 1 once the link between coupled chips is in sync, 0 if it is not in time, or an error */
|
||||
static int __rtl8214qf_link_wait(struct phy_device *secondary, struct phy_device *primary)
|
||||
{
|
||||
int ret, synced;
|
||||
|
||||
ret = read_poll_timeout(__rtl8214qf_link_synced, synced, synced != 0,
|
||||
RTL8214QF_LINK_SYNC_POLL_US, RTL8214QF_LINK_SYNC_TIMEOUT_US, false,
|
||||
secondary, primary);
|
||||
|
||||
return ret == -ETIMEDOUT ? 0 : ret ?: synced;
|
||||
}
|
||||
|
||||
struct rtl8214qf_chip {
|
||||
struct phy_device *phydev; /* its first port */
|
||||
int mode;
|
||||
};
|
||||
|
||||
/*
|
||||
* Sets up the chips of the package of @base. Coupled chips, a secondary and a primary, are set up
|
||||
* with the ports of the package powered down, as their link only trains reliably while no port
|
||||
* receives a signal.
|
||||
*/
|
||||
static int __rtl8214qf_setup(struct phy_device *base)
|
||||
{
|
||||
struct rtl821x_shared_priv *shared_priv = phy_package_get_priv(base);
|
||||
struct rtl8214qf_chip chips[RTL8214QF_PACKAGE_CHIPS] = { { .phydev = base } };
|
||||
unsigned long down = 0;
|
||||
int n = 1, ret, err;
|
||||
bool coupled;
|
||||
|
||||
/* The secondary of coupled chips is at the base, the primary 4 ports above */
|
||||
if (shared_priv->ports & GENMASK(RTL8214QF_PACKAGE_PORTS - 1, RTL8214QF_PORTS)) {
|
||||
if (!(shared_priv->ports & BIT(RTL8214QF_PORTS))) {
|
||||
phydev_err(base, "first port of the second RTL8214QF of the package is missing\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
chips[1].phydev = get_package_phy(base, RTL8214QF_PORTS);
|
||||
n = 2;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
ret = __rtl8214qf_chip_mode(chips[i].phydev);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
chips[i].mode = ret;
|
||||
}
|
||||
|
||||
coupled = n == RTL8214QF_PACKAGE_CHIPS &&
|
||||
chips[0].mode == RTL8214QF_CHIP_MODE_SECONDARY &&
|
||||
chips[1].mode == RTL8214QF_CHIP_MODE_PRIMARY;
|
||||
if (n == RTL8214QF_PACKAGE_CHIPS && !coupled)
|
||||
phydev_warn(base, "RTL8214QF chip modes %#x and %#x are not of coupled chips\n",
|
||||
chips[0].mode, chips[1].mode);
|
||||
|
||||
if (coupled) {
|
||||
ret = __rtl8214qf_ports_power_down(base, shared_priv->ports, &down);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
ret = __rtl8214qf_chip_init(chips[i].phydev, chips[i].mode);
|
||||
if (ret)
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (coupled) {
|
||||
ret = __rtl8214qf_link_wait(chips[0].phydev, chips[1].phydev);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
if (!ret)
|
||||
phydev_err(base, "RTL8214QF pair link did not train\n");
|
||||
}
|
||||
ret = 0;
|
||||
|
||||
out:
|
||||
/* Leave the chips at page 0, where phylib expects their registers */
|
||||
for (int i = 0; i < n; i++) {
|
||||
err = rtl821x_write_page(chips[i].phydev, RTL8XXX_PAGE_MAIN);
|
||||
if (!ret)
|
||||
ret = err;
|
||||
}
|
||||
|
||||
err = __rtl8214qf_ports_power_up(base, down);
|
||||
if (!ret)
|
||||
ret = err;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rtl8214qf_probe(struct phy_device *phydev)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = rtl821x_package_join(phydev, 4, false);
|
||||
ret = rtl821x_package_join(phydev, RTL8214QF_PACKAGE_PORTS, true);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
@@ -645,30 +821,30 @@ static int rtl8214qf_probe(struct phy_device *phydev)
|
||||
}
|
||||
|
||||
/*
|
||||
* The chip is set up once, through its first port, which must be described in DT. The bus stays
|
||||
* locked for the whole setup and only success is recorded, so the next port retries after an
|
||||
* error. The chip must not be reset later on; the MDIO controller only resets it before probing.
|
||||
* The chips of a package are set up once, through its first port, under one bus lock. Only success
|
||||
* is recorded, so the next port retries after an error. The chips must not be reset later on.
|
||||
*/
|
||||
static int rtl8214qf_config_init(struct phy_device *phydev)
|
||||
{
|
||||
struct rtl821x_shared_priv *shared_priv = phy_package_get_priv(phydev);
|
||||
struct phy_device *base = get_base_phy(phydev);
|
||||
int oldpage, ret = 0;
|
||||
int ret = 0;
|
||||
|
||||
if (!base) {
|
||||
phydev_err(phydev, "first port of the RTL8214QF is not described\n");
|
||||
if (!base || base->shared != phydev->shared) {
|
||||
phydev_err(phydev, "first port of the RTL8214QF package is missing\n");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
oldpage = phy_save_page(base);
|
||||
if (oldpage >= 0 && !shared_priv->setup_done) {
|
||||
ret = __rtl8214qf_chip_init(base);
|
||||
phy_lock_mdio_bus(phydev);
|
||||
if (!shared_priv->setup_done) {
|
||||
ret = __rtl8214qf_setup(base);
|
||||
if (ret)
|
||||
phydev_err(phydev, "RTL8214QF setup failed: %d\n", ret);
|
||||
shared_priv->setup_done = !ret;
|
||||
}
|
||||
phy_unlock_mdio_bus(phydev);
|
||||
|
||||
return phy_restore_page(base, oldpage, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int rtl8214qf_get_features(struct phy_device *phydev)
|
||||
|
||||
Reference in new issue
Block a user