Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: pcs: xpcs: add support for NXP SJA1105

The NXP SJA1105 DSA switch integrates a Synopsys SGMII XPCS on port 4.
The generic code works fine, except there is an integration issue which
needs to be dealt with: in this switch, the XPCS is integrated with a
PMA that has the TX lane polarity inverted by default (PLUS is MINUS,
MINUS is PLUS).

To obtain normal non-inverted behavior, the TX lane polarity must be
inverted in the PCS, via the DIGITAL_CONTROL_2 register.

We introduce a pma_config() method in xpcs_compat which is called by the
phylink_pcs_config() implementation.

Also, the NXP SJA1105 returns all zeroes in the PHY ID registers 2 and 3.
We need to hack up an ad-hoc PHY ID (OUI is zero, device ID is 1) in
order for the XPCS driver to recognize it. This PHY ID is added to the
public include/linux/pcs/pcs-xpcs.h for that reason (for the sja1105
driver to be able to use it in a later patch).

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Signed-off-by: David S. Miller <davem@davemloft.net>

authored by

Vladimir Oltean and committed by
David S. Miller
dd0721ea 36641b04

+55 -3
+1
MAINTAINERS
··· 13203 13203 L: linux-kernel@vger.kernel.org 13204 13204 S: Maintained 13205 13205 F: drivers/net/dsa/sja1105 13206 + F: drivers/net/pcs/pcs-xpcs-nxp.c 13206 13207 13207 13208 NXP TDA998X DRM DRIVER 13208 13209 M: Russell King <linux@armlinux.org.uk>
+3 -1
drivers/net/pcs/Makefile
··· 1 1 # SPDX-License-Identifier: GPL-2.0 2 2 # Makefile for Linux PCS drivers 3 3 4 - obj-$(CONFIG_PCS_XPCS) += pcs-xpcs.o 4 + pcs_xpcs-$(CONFIG_PCS_XPCS) := pcs-xpcs.o pcs-xpcs-nxp.o 5 + 6 + obj-$(CONFIG_PCS_XPCS) += pcs_xpcs.o 5 7 obj-$(CONFIG_PCS_LYNX) += pcs-lynx.o
+16
drivers/net/pcs/pcs-xpcs-nxp.c
··· 1 + // SPDX-License-Identifier: GPL-2.0 2 + /* Copyright 2021 NXP Semiconductors 3 + */ 4 + #include <linux/pcs/pcs-xpcs.h> 5 + #include "pcs-xpcs.h" 6 + 7 + /* In NXP SJA1105, the PCS is integrated with a PMA that has the TX lane 8 + * polarity inverted by default (PLUS is MINUS, MINUS is PLUS). To obtain 9 + * normal non-inverted behavior, the TX lane polarity must be inverted in the 10 + * PCS, via the DIGITAL_CONTROL_2 register. 11 + */ 12 + int nxp_sja1105_sgmii_pma_config(struct dw_xpcs *xpcs) 13 + { 14 + return xpcs_write(xpcs, MDIO_MMD_VEND2, DW_VR_MII_DIG_CTRL2, 15 + DW_VR_MII_DIG_CTRL2_TX_POL_INV); 16 + }
+23 -2
drivers/net/pcs/pcs-xpcs.c
··· 117 117 const phy_interface_t *interface; 118 118 int num_interfaces; 119 119 int an_mode; 120 + int (*pma_config)(struct dw_xpcs *xpcs); 120 121 }; 121 122 122 123 struct xpcs_id { ··· 169 168 #define xpcs_linkmode_supported(compat, mode) \ 170 169 __xpcs_linkmode_supported(compat, ETHTOOL_LINK_MODE_ ## mode ## _BIT) 171 170 172 - static int xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg) 171 + int xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg) 173 172 { 174 173 u32 reg_addr = mdiobus_c45_addr(dev, reg); 175 174 struct mii_bus *bus = xpcs->mdiodev->bus; ··· 178 177 return mdiobus_read(bus, addr, reg_addr); 179 178 } 180 179 181 - static int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val) 180 + int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val) 182 181 { 183 182 u32 reg_addr = mdiobus_c45_addr(dev, reg); 184 183 struct mii_bus *bus = xpcs->mdiodev->bus; ··· 789 788 return -1; 790 789 } 791 790 791 + if (compat->pma_config) { 792 + ret = compat->pma_config(xpcs); 793 + if (ret) 794 + return ret; 795 + } 796 + 792 797 return 0; 793 798 } 794 799 ··· 1029 1022 }, 1030 1023 }; 1031 1024 1025 + static const struct xpcs_compat nxp_sja1105_xpcs_compat[DW_XPCS_INTERFACE_MAX] = { 1026 + [DW_XPCS_SGMII] = { 1027 + .supported = xpcs_sgmii_features, 1028 + .interface = xpcs_sgmii_interfaces, 1029 + .num_interfaces = ARRAY_SIZE(xpcs_sgmii_interfaces), 1030 + .an_mode = DW_AN_C37_SGMII, 1031 + .pma_config = nxp_sja1105_sgmii_pma_config, 1032 + }, 1033 + }; 1034 + 1032 1035 static const struct xpcs_id xpcs_id_list[] = { 1033 1036 { 1034 1037 .id = SYNOPSYS_XPCS_ID, 1035 1038 .mask = SYNOPSYS_XPCS_MASK, 1036 1039 .compat = synopsys_xpcs_compat, 1040 + }, { 1041 + .id = NXP_SJA1105_XPCS_ID, 1042 + .mask = SYNOPSYS_XPCS_MASK, 1043 + .compat = nxp_sja1105_xpcs_compat, 1037 1044 }, 1038 1045 }; 1039 1046
+10
drivers/net/pcs/pcs-xpcs.h
··· 60 60 /* EEE Mode Control Register */ 61 61 #define DW_VR_MII_EEE_MCTRL0 0x8006 62 62 #define DW_VR_MII_EEE_MCTRL1 0x800b 63 + #define DW_VR_MII_DIG_CTRL2 0x80e1 63 64 64 65 /* VR_MII_DIG_CTRL1 */ 65 66 #define DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW BIT(9) 67 + 68 + /* VR_MII_DIG_CTRL2 */ 69 + #define DW_VR_MII_DIG_CTRL2_TX_POL_INV BIT(4) 70 + #define DW_VR_MII_DIG_CTRL2_RX_POL_INV BIT(0) 66 71 67 72 /* VR_MII_AN_CTRL */ 68 73 #define DW_VR_MII_AN_CTRL_TX_CONFIG_SHIFT 3 ··· 106 101 107 102 /* VR MII EEE Control 1 defines */ 108 103 #define DW_VR_MII_EEE_TRN_LPI BIT(0) /* Transparent Mode Enable */ 104 + 105 + int xpcs_read(struct dw_xpcs *xpcs, int dev, u32 reg); 106 + int xpcs_write(struct dw_xpcs *xpcs, int dev, u32 reg, u16 val); 107 + 108 + int nxp_sja1105_sgmii_pma_config(struct dw_xpcs *xpcs);
+2
include/linux/pcs/pcs-xpcs.h
··· 10 10 #include <linux/phy.h> 11 11 #include <linux/phylink.h> 12 12 13 + #define NXP_SJA1105_XPCS_ID 0x00000010 14 + 13 15 /* AN mode */ 14 16 #define DW_AN_C73 1 15 17 #define DW_AN_C37_SGMII 2