Re: [PATCH net-next v5] net: dsa: microchip: enable the SGMII port of the KSZ9897S

From: Linus Walleij

Date: Sat Sep 05 2026 - 02:22:39 EST


On Fri, Sep 4, 2026 at 8:03 AM Tapio Reijonen
<tapio.reijonen@xxxxxxxxxxx> wrote:

> The KSZ9897 has an SGMII/1000BASE-X capable port 7, but its chip_info
> entry never set .sgmii_port. ksz_has_sgmii_port() is therefore false,
> ksz9477_pcs_create() is never called and ksz9477_phylink_mac_select_pcs()
> returns NULL for port 7, so a phy-mode = "sgmii" or "1000base-x" link on
> that port cannot come up.
>
> Only the KSZ9897S has that port; the KSZ9897R has a second RGMII port
> instead. Both report chip ID 0x00989700, so the port cannot be enabled
> from the chip ID alone, and enabling it unconditionally breaks the
> KSZ9897R badly: ksz9477_setup() propagates the failure of
> xpcs_create_pcs_mdiodev() on a part without an XPCS, so the switch as a
> whole stops probing.
>
> The variants do differ in the read-only bit 7 of the port 7 XMII control
> 0 register, which reads one on the KSZ9897S and zero on the KSZ9897R.
> Compare the KSZ9897S data sheet DS00002394C section 5.2.4.1 with the
> KSZ9897R data sheet DS00002330D section 5.2.3.1.
>
> Read that bit in ksz_switch_register() and use it to select a KSZ9897S
> chip_data entry, which is the KSZ9897 one plus .sgmii_port = 7, with
> port 7 no longer marked as supporting MII, RMII and RGMII. On the
> KSZ9897S that port is permanently an SGMII port and only its
> differential pairs are brought out, so advertising the xMII modes on it
> would let phylink accept a mode the driver never programs:
> ksz_phylink_need_config() skips the XMII control registers for the SGMII
> port. The KSZ9477, which also has SGMII on port 7, is described the same
> way. See DS00002394C section 4.11.
>
> KSZ9897S_CHIP_ID selects that chip_data entry and nothing else.
> dev->chip_id keeps the KSZ9897 chip ID that both parts report, so no
> other chip ID comparison has to know about the variant,
> ksz_check_device_id() is unchanged, and a device tree naming the KSZ9897
> keeps matching whichever part is fitted. No binding change is needed and
> existing device trees keep working.
>
> Tested on a KSZ9897S with a 1000BASE-LX fibre SFP on port 7: bit 7 of
> the port 7 XMII control 0 register reads one, the switch is identified
> as a KSZ9897S and the PCS is created. The port advertises
> 1000baseX/Full, clause 37 in-band autonegotiation completes against the
> link partner, and the link comes up at 1Gbps/full duplex and passes
> traffic.
>
> Suggested-by: Nicolai Buchwitz <nb@xxxxxxxxxxx>
> Suggested-by: Jerry Ray <Jerry.Ray@xxxxxxxxxxxxx>
> Suggested-by: Tristram Ha <Tristram.Ha@xxxxxxxxxxxxx>
> Signed-off-by: Tapio Reijonen <tapio.reijonen@xxxxxxxxxxx>

I think this approach looks good.
Reviewed-by: Linus Walleij <linusw@xxxxxxxxxx>

Yours,
Linus Walleij