Support the SJA1105 DSA switch on the NXP LS1021A-TSN board
Subsystems (4)
v2 cover Support the SJA1105 DSA switch on the NXP LS1021A-TSN board
The NXP LS1021A-TSN board (and many others) contains an automotive Ethernet switch. Some boards only have Ethernet ports routed through the switch, and it is therefore desirable to have TFTP functional.
These patches add support for the SJA1105 and SJA1110 switch family (tested on first-gen SJA1105T, second-gen SJA1105S, but not on third-gen SJA1110A yet, the support for that is blind). Along the way, fixes and improvements to the DSA framework are also made.
I have not added documentation for the device tree bindings, the driver is compatible with the device tree bindings from Linux, for which a YAML schema-based validator exists.
Changes in v2:
- split sja1105 driver in 2 patches: basic driver and SGMII support
- rebased on top of the "sgmii-2500" -> "2500base-x" change in felix
- improved the sja1105 xpcs initialization sequence to work with in-band autoneg enabled as well
Vladimir Oltean (10):
net: tsec: add support for promiscuous mode
include: import if_vlan.h from Linux
net: dsa: allow drivers to get the port OF node
net: introduce a helper to determine whether to use in-band autoneg
net: dsa: felix: configure the in-band autoneg property based on OF
node info
net: dsa: add driver for NXP SJA1105 L2 switch
net: dsa: sja1105: add support for SGMII
arm: dts: ls1021a-tsn: add sja1105 and eth2 bindings
configs: ls1021a-tsn: enable sja1105 switch driver
configs: ls1021a-tsn: enable the generation of random Ethernet MAC
addresses
arch/arm/dts/ls1021a-tsn.dts | 103 + configs/ls1021atsn_qspi_defconfig | 3 + configs/ls1021atsn_sdcard_defconfig | 3 + drivers/core/of_extra.c | 12 + drivers/net/Kconfig | 16 + drivers/net/Makefile | 1 + drivers/net/mscc_eswitch/felix_switch.c | 10 +- drivers/net/sja1105.c | 3376 +++++++++++++++++++++++ drivers/net/tsec.c | 20 +- include/dm/of_extra.h | 14 + include/linux/if_vlan.h | 26 + include/net/dsa.h | 12 + include/tsec.h | 2 + net/dsa-uclass.c | 20 + 14 files changed, 3608 insertions(+), 10 deletions(-) create mode 100644 drivers/net/sja1105.c create mode 100644 include/linux/if_vlan.h
Signature · 1 line
2.25.1
PATCH v2 1/10 net: tsec: add support for promiscuous mode
The Freescale TSEC can be a DSA master, and the ports of the attached DSA switch can have different MAC addresses compared to the TSEC. Nonetheless, the TSEC must receive the packets on behalf of those switch ports. Therefore, implement the promiscuous mode method to allow DSA to set this.
Note that the init_registers() function called from eth_ops :: start overwrites this setting. There is no reason why the RCTRL register should be zero-initialized, so just stop clearing it so that the setting we applied in eth_ops :: set_promisc sticks.
---v1->v2: none
drivers/net/tsec.c | 20 ++++++++++++++++---- include/tsec.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-)
drivers/net/tsec.c +16 -4
@@ -156,6 +156,19 @@ static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)return 0 ; } +static int tsec_set_promisc (struct udevice *dev,bool enable) +{ +struct tsec_private *priv =dev_get_priv (dev); +struct tsec __iomem *regs = priv->regs; + +if (enable) +setbits_be32 (®s->rctrl,RCTRL_PROM ); +else +clrbits_be32 (®s->rctrl,RCTRL_PROM ); + +return 0 ; +} +/* * Initialized required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case,
@@ -186,8 +199,6 @@ static void init_registers(struct tsec __iomem *regs)out_be32 (®s->hash.gaddr6,0 );out_be32 (®s->hash.gaddr7,0 ); -out_be32 (®s->rctrl,0x00000000 ); -/* Init RMON mib registers */ memset ((void *)®s->rmon,0 ,sizeof (regs->rmon));
@@ -454,7 +465,7 @@ void redundant_init(struct tsec_private *priv) 0x71, 0x72};/* Enable promiscuous mode */ -setbits_be32 (®s->rctrl,0x8 ); +setbits_be32 (®s->rctrl,RCTRL_PROM );/* Enable loopback mode */ setbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK );/* Enable transmit and receive */
@@ -506,7 +517,7 @@ void redundant_init(struct tsec_private *priv)if (fail)panic ("eTSEC init fail!\n" );/* Disable promiscuous mode */ -clrbits_be32 (®s->rctrl,0x8 ); +clrbits_be32 (®s->rctrl,RCTRL_PROM );/* Disable loopback mode */ clrbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK ); }
@@ -932,6 +943,7 @@ static const struct eth_ops tsec_ops = { .free_pkt = tsec_free_pkt, .stop = tsec_halt, .mcast = tsec_mcast_addr, + .set_promisc = tsec_set_promisc, };static struct tsec_data etsec2_data = {
include/tsec.h +2 -0
@@ -122,6 +122,8 @@#define ECNTRL_REDUCED_MII_MODE 0x00000004#define ECNTRL_SGMII_MODE 0x00000002 +#define RCTRL_PROM 0x00000008 +#ifndef CONFIG_SYS_TBIPA_VALUE # define CONFIG_SYS_TBIPA_VALUE 0x1f#endif
Signature · 1 line
2.25.1
Re: [PATCH v2 01/10] net: tsec: add support for promiscuous mode
Quoted 95 lines · Vladimir Oltean
The Freescale TSEC can be a DSA master, and the ports of the attached DSA switch can have different MAC addresses compared to the TSEC. Nonetheless, the TSEC must receive the packets on behalf of those switch ports. Therefore, implement the promiscuous mode method to allow DSA to set this.
Note that the
init_registers()function called frometh_ops:: start overwrites this setting. There is no reason why the RCTRL register should be zero-initialized, so just stop clearing it so that the setting we applied ineth_ops::set_promiscsticks.Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>---
v1->v2: nonedrivers/net/tsec.c | 20 ++++++++++++++++---- include/tsec.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-)drivers/net/tsec.c +16
-4@@ -156,6 +156,19 @@ static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)return 0 ; } +static int tsec_set_promisc (struct udevice *dev,bool enable) +{ +struct tsec_private *priv =dev_get_priv (dev); +struct tsec __iomem *regs = priv->regs; + +if (enable) +setbits_be32 (®s->rctrl,RCTRL_PROM ); +else +clrbits_be32 (®s->rctrl,RCTRL_PROM ); + +return 0 ; +} +/* * Initialized required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case, @@ -186,8 +199,6 @@ static void init_registers(struct tsec __iomem *regs)out_be32 (®s->hash.gaddr6,0 );out_be32 (®s->hash.gaddr7,0 ); -out_be32 (®s->rctrl,0x00000000 ); -/* Init RMON mib registers */ memset ((void *)®s->rmon,0 ,sizeof (regs->rmon));@@ -454,7 +465,7 @@ void redundant_init(struct tsec_private *priv) 0x71, 0x72};/* Enable promiscuous mode */ -setbits_be32 (®s->rctrl,0x8 ); +setbits_be32 (®s->rctrl,RCTRL_PROM );/* Enable loopback mode */ setbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK );/* Enable transmit and receive */ @@ -506,7 +517,7 @@ void redundant_init(struct tsec_private *priv)if (fail)panic ("eTSEC init fail!\n" );/* Disable promiscuous mode */ -clrbits_be32 (®s->rctrl,0x8 ); +clrbits_be32 (®s->rctrl,RCTRL_PROM );/* Disable loopback mode */ clrbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK ); }@@ -932,6 +943,7 @@ static const struct eth_ops tsec_ops = { .free_pkt = tsec_free_pkt, .stop = tsec_halt, .mcast = tsec_mcast_addr, + .set_promisc = tsec_set_promisc, };static struct tsec_data etsec2_data = {include/tsec.h +2
-1@@ -122,6 +122,8 @@#define ECNTRL_REDUCED_MII_MODE 0x00000004#define ECNTRL_SGMII_MODE 0x00000002 +#define RCTRL_PROM 0x00000008 +#ifndef CONFIG_SYS_TBIPA_VALUE # define CONFIG_SYS_TBIPA_VALUE 0x1f#endif --
Quoted 2 lines
2.25.1
Re: [PATCH v2 01/10] net: tsec: add support for promiscuous mode
Quoted 91 lines · Ramon Fried
Quoted 89 lines · Vladimir Oltean
The Freescale TSEC can be a DSA master, and the ports of the attached DSA switch can have different MAC addresses compared to the TSEC. Nonetheless, the TSEC must receive the packets on behalf of those switch ports. Therefore, implement the promiscuous mode method to allow DSA to set this.
Note that the
init_registers()function called frometh_ops:: start overwrites this setting. There is no reason why the RCTRL register should be zero-initialized, so just stop clearing it so that the setting we applied ineth_ops::set_promiscsticks.Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>---
v1->v2: nonedrivers/net/tsec.c | 20 ++++++++++++++++---- include/tsec.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-)drivers/net/tsec.c +16
-4@@ -156,6 +156,19 @@ static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)return 0 ; } +static int tsec_set_promisc (struct udevice *dev,bool enable) +{ +struct tsec_private *priv =dev_get_priv (dev); +struct tsec __iomem *regs = priv->regs; + +if (enable) +setbits_be32 (®s->rctrl,RCTRL_PROM ); +else +clrbits_be32 (®s->rctrl,RCTRL_PROM ); + +return 0 ; +} +/* * Initialized required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case, @@ -186,8 +199,6 @@ static void init_registers(struct tsec __iomem *regs)out_be32 (®s->hash.gaddr6,0 );out_be32 (®s->hash.gaddr7,0 ); -out_be32 (®s->rctrl,0x00000000 ); -/* Init RMON mib registers */ memset ((void *)®s->rmon,0 ,sizeof (regs->rmon));@@ -454,7 +465,7 @@ void redundant_init(struct tsec_private *priv) 0x71, 0x72};/* Enable promiscuous mode */ -setbits_be32 (®s->rctrl,0x8 ); +setbits_be32 (®s->rctrl,RCTRL_PROM );/* Enable loopback mode */ setbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK );/* Enable transmit and receive */ @@ -506,7 +517,7 @@ void redundant_init(struct tsec_private *priv)if (fail)panic ("eTSEC init fail!\n" );/* Disable promiscuous mode */ -clrbits_be32 (®s->rctrl,0x8 ); +clrbits_be32 (®s->rctrl,RCTRL_PROM );/* Disable loopback mode */ clrbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK ); }@@ -932,6 +943,7 @@ static const struct eth_ops tsec_ops = { .free_pkt = tsec_free_pkt, .stop = tsec_halt, .mcast = tsec_mcast_addr, + .set_promisc = tsec_set_promisc, };static struct tsec_data etsec2_data = {include/tsec.h +0
-0@@ -122,6 +122,8 @@#define ECNTRL_REDUCED_MII_MODE 0x00000004#define ECNTRL_SGMII_MODE 0x00000002
Quoted 9 lines
Quoted 8 lines
include/tsec.h +2
-1+#define RCTRL_PROM 0x00000008 +#ifndef CONFIG_SYS_TBIPA_VALUE # define CONFIG_SYS_TBIPA_VALUE 0x1f#endif --2.25.1
Reviewed-by Ramon Fried <[email protected]>
Series applied to u-boot-net/next
Thanks,
Ramon.
Re: [PATCH v2 01/10] net: tsec: add support for promiscuous mode
Quoted 102 lines · Ramon Fried
Quoted 91 lines · Ramon Fried
Quoted 89 lines · Vladimir Oltean
The Freescale TSEC can be a DSA master, and the ports of the attached DSA switch can have different MAC addresses compared to the TSEC. Nonetheless, the TSEC must receive the packets on behalf of those switch ports. Therefore, implement the promiscuous mode method to allow DSA to set this.
Note that the
init_registers()function called frometh_ops:: start overwrites this setting. There is no reason why the RCTRL register should be zero-initialized, so just stop clearing it so that the setting we applied ineth_ops::set_promiscsticks.Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Ramon Fried <[email protected]>Reviewed-by Bin Meng <[email protected]>---
v1->v2: nonedrivers/net/tsec.c | 20 ++++++++++++++++---- include/tsec.h | 2 ++ 2 files changed, 18 insertions(+), 4 deletions(-)drivers/net/tsec.c +16
-4@@ -156,6 +156,19 @@ static int tsec_mcast_addr(struct udevice *dev, const u8 *mcast_mac, int join)return 0 ; } +static int tsec_set_promisc (struct udevice *dev,bool enable) +{ +struct tsec_private *priv =dev_get_priv (dev); +struct tsec __iomem *regs = priv->regs; + +if (enable) +setbits_be32 (®s->rctrl,RCTRL_PROM ); +else +clrbits_be32 (®s->rctrl,RCTRL_PROM ); + +return 0 ; +} +/* * Initialized required registers to appropriate values, zeroing * those we don't care about (unless zero is bad, in which case, @@ -186,8 +199,6 @@ static void init_registers(struct tsec __iomem *regs)out_be32 (®s->hash.gaddr6,0 );out_be32 (®s->hash.gaddr7,0 ); -out_be32 (®s->rctrl,0x00000000 ); -/* Init RMON mib registers */ memset ((void *)®s->rmon,0 ,sizeof (regs->rmon));@@ -454,7 +465,7 @@ void redundant_init(struct tsec_private *priv) 0x71, 0x72};/* Enable promiscuous mode */ -setbits_be32 (®s->rctrl,0x8 ); +setbits_be32 (®s->rctrl,RCTRL_PROM );/* Enable loopback mode */ setbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK );/* Enable transmit and receive */ @@ -506,7 +517,7 @@ void redundant_init(struct tsec_private *priv)if (fail)panic ("eTSEC init fail!\n" );/* Disable promiscuous mode */ -clrbits_be32 (®s->rctrl,0x8 ); +clrbits_be32 (®s->rctrl,RCTRL_PROM );/* Disable loopback mode */ clrbits_be32 (®s->maccfg1,MACCFG1_LOOPBACK ); }@@ -932,6 +943,7 @@ static const struct eth_ops tsec_ops = { .free_pkt = tsec_free_pkt, .stop = tsec_halt, .mcast = tsec_mcast_addr, + .set_promisc = tsec_set_promisc, };static struct tsec_data etsec2_data = {include/tsec.h +0
-0@@ -122,6 +122,8 @@#define ECNTRL_REDUCED_MII_MODE 0x00000004#define ECNTRL_SGMII_MODE 0x00000002Quoted 9 lines
Quoted 8 lines
include/tsec.h +2
-1+#define RCTRL_PROM 0x00000008 +#ifndef CONFIG_SYS_TBIPA_VALUE # define CONFIG_SYS_TBIPA_VALUE 0x1f#endif --2.25.1
Reviewed-by Ramon Fried <[email protected]>
Quoted 3 lines
Series applied to u-boot-net/next
Thanks,
Ramon.
CI Build for 32bit ARM targets failed for this patch:drivers/net/tsec.c:159:12: error: 'tsec_set_promisc' defined but not used [-Werror=unused-function]
159 | static int tsec_set_promisc(struct udevice *dev, bool enable) | ^~~~~~~~~~~~~~~~
PATCH v2 2/10 include: import if_vlan.h from Linux
In reply to Vladimir OlteanThis is needed for the VLAN header structure.
---v1->v2: none
include/linux/if_vlan.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 include/linux/if_vlan.h
include/linux/if_vlan.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* +* VLAN An implementation of 802.1Q VLAN tagging. +* +* Authors: Ben Greear <[email protected]> +*/ +#ifndef _LINUX_IF_VLAN_H_ +#define _LINUX_IF_VLAN_H_ + +/** +* struct vlan_ethhdr - vlan ethernet header (ethhdr + vlan_hdr) +* @h_dest: destination ethernet address +* @h_source: source ethernet address +* @h_vlan_proto: ethernet protocol +* @h_vlan_TCI: priority and VLAN ID +* @h_vlan_encapsulated_proto: packet type ID or len +*/ +struct vlan_ethhdr { +unsigned char h_dest[ETH_ALEN ]; +unsigned char h_source[ETH_ALEN ]; +__be16 h_vlan_proto; +__be16 h_vlan_TCI; +__be16 h_vlan_encapsulated_proto; +}; + +#endif /* !(_LINUX_IF_VLAN_H_) */
Signature · 1 line
2.25.1
PATCH v2 3/10 net: dsa: allow drivers to get the port OF node
In reply to Vladimir OlteanIn the current DSA switch driver API, only the udevice of the switch (belonging to UCLASS_DSA) is exposed, as well as an "int port" argument. So drivers do not have access to the udevice of individual ports (belonging to UCLASS_ETH), one of the reasons being that not all ports have an associated UCLASS_ETH udevice.
However, all DSA ports have an OF node, and in some cases the driver needs a handle to it, for all ports including the CPU port. Example: the following Linux per-port device tree property:
managed = "in-band-status";
states whether a port should operate with clause 37 in-band autoneg enabled or not.
This patch exposes a function which can be called by individual drivers as needed.
---v1->v2: none
include/net/dsa.h | 12 ++++++++++++ net/dsa-uclass.c | 20 ++++++++++++++++++++ 2 files changed, 32 insertions(+)
include/net/dsa.h +12 -0
@@ -6,6 +6,7 @@#ifndef __DSA_H__#define __DSA_H__ +#include <dm/ofnode.h> #include <phy.h> #include <net.h>
@@ -145,6 +146,17 @@ int dsa_set_tagging(struct udevice *dev, ushort headroom, ushort tailroom);*/ struct udevice *dsa_get_master (struct udevice *dev); +/** +* dsa_port_get_ofnode() - Return a reference to the given port's OF node +* +* Can be called at driver probe time or later. +* +* @dev: DSA switch udevice pointer +* @port: Port index +* @return OF node reference if OK, NULL on error +*/ +ofnode dsa_port_get_ofnode (struct udevice *dev,int port); +/** * dsa_port_get_pdata() - Helper that returns the platdata of an active * (non-CPU) DSA port device.
net/dsa-uclass.c +20 -0
@@ -44,6 +44,26 @@ int dsa_set_tagging(struct udevice *dev, ushort headroom, ushort tailroom)return 0 ; } +ofnode dsa_port_get_ofnode (struct udevice *dev,int port) +{ +struct dsa_pdata *pdata =dev_get_uclass_plat (dev); +struct dsa_port_pdata *port_pdata; +struct udevice *pdev; + +if (port == pdata->cpu_port) +return pdata->cpu_port_node; + +for (device_find_first_child (dev, &pdev); + pdev; +device_find_next_child (&pdev)) { + port_pdata =dev_get_parent_plat (pdev); +if (port_pdata->index == port) +return dev_ofnode (pdev); + } + +return ofnode_null (); +} +/* returns the DSA master Ethernet device */ struct udevice *dsa_get_master (struct udevice *dev) {
Signature · 1 line
2.25.1
PATCH v2 4/10 net: introduce a helper to determine whether to use in-band autoneg
In reply to Vladimir OlteanCertain serial SERDES protocols like 1000base-x, 2500base-x, SGMII, USXGMII can operate either in a mode where the PHY (be it on-board or inside an SFP module) passes the link parameters (speed, duplex, pause) to the MAC through in-band through control words standardized by IEEE 802.3 clause 37, or in a mode where the MAC must configure (force) its link parameters based on information obtained out-of-band (MDIO reads, guesswork etc).
In Linux, the OF node property named "managed" is parsed by the phylink framework, and the convention is that if a driver uses phylink, then the presence of this property means that in-band autoneg should be enabled, otherwise it shouldn't.
To be compatible with the OF node bindings of drivers that use phylink in Linux, introduce parsing support for this property in U-Boot too.
---v1->v2: none
drivers/core/of_extra.c | 12 ++++++++++++ include/dm/of_extra.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+)
drivers/core/of_extra.c +12 -0
@@ -155,3 +155,15 @@ bool ofnode_phy_is_fixed_link(ofnode eth_node, ofnode *phy_node)return true; } + +bool ofnode_eth_uses_inband_aneg (ofnode eth_node) +{ +bool inband_aneg = false; +const char *managed; + + managed =ofnode_read_string (eth_node,"managed" ); +if (managed && !strcmp (managed,"in-band-status" )) + inband_aneg = true; + +return inband_aneg; +}
include/dm/of_extra.h +14 -0
@@ -114,4 +114,18 @@ int ofnode_decode_memory_region(ofnode config_node, const char *mem_type,*/ bool ofnode_phy_is_fixed_link (ofnode eth_node,ofnode *phy_node); +/** +* ofnode_eth_uses_inband_aneg() - Detect whether MAC should use in-band autoneg +* +* This function detects whether the Ethernet controller should use IEEE 802.3 +* clause 37 in-band autonegotiation for serial protocols such as 1000base-x, +* SGMII, USXGMII, etc. The property is relevant when the Ethernet controller +* is connected to an on-board PHY or an SFP cage, and is not relevant when it +* has a fixed link (in that case, in-band autoneg should not be used). +* +* @param eth_node ofnode belonging to the Ethernet controller +* @return true if in-band autoneg should be used, false otherwise +*/ +bool ofnode_eth_uses_inband_aneg (ofnode eth_node); +#endif
Signature · 1 line
2.25.1
Re: [PATCH v2 04/10] net: introduce a helper to determine whether to use in-band autoneg
Quoted 17 lines · Vladimir Oltean
Certain serial SERDES protocols like 1000base-x, 2500base-x, SGMII, USXGMII can operate either in a mode where the PHY (be it on-board or inside an SFP module) passes the link parameters (speed, duplex, pause) to the MAC through in-band through control words standardized by IEEE 802.3 clause 37, or in a mode where the MAC must configure (force) its link parameters based on information obtained out-of-band (MDIO reads, guesswork etc).
In Linux, the OF node property named "managed" is parsed by the phylink framework, and the convention is that if a driver uses phylink, then the presence of this property means that in-band autoneg should be enabled, otherwise it shouldn't.
To be compatible with the OF node bindings of drivers that use phylink in Linux, introduce parsing support for this property in U-Boot too.
Quoted 9 lines
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Ramon Fried <[email protected]>---
v1->v2: nonedrivers/core/of_extra.c | 12 ++++++++++++ include/dm/of_extra.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+)
Ramon Fried
Reviewed-byRe: [PATCH v2 04/10] net: introduce a helper to determine whether to use in-band autoneg
Quoted 25 lines · Bin Meng
Quoted 22 lines · Vladimir Oltean
Certain serial SERDES protocols like 1000base-x, 2500base-x, SGMII, USXGMII can operate either in a mode where the PHY (be it on-board or inside an SFP module) passes the link parameters (speed, duplex, pause) to the MAC through in-band through control words standardized by IEEE 802.3 clause 37, or in a mode where the MAC must configure (force) its link parameters based on information obtained out-of-band (MDIO reads, guesswork etc).
In Linux, the OF node property named "managed" is parsed by the phylink framework, and the convention is that if a driver uses phylink, then the presence of this property means that in-band autoneg should be enabled, otherwise it shouldn't.
To be compatible with the OF node bindings of drivers that use phylink in Linux, introduce parsing support for this property in U-Boot too.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Ramon Fried <[email protected]>---
v1->v2: none
Quoted 6 lines
Quoted 4 lines
drivers/core/of_extra.c | 12 ++++++++++++ include/dm/of_extra.h | 14 ++++++++++++++ 2 files changed, 26 insertions(+)Reviewed-by Bin Meng <[email protected]>
PATCH v2 5/10 net: dsa: felix: configure the in-band autoneg property based on OF node info
In reply to Vladimir OlteanInstead of trying to guess which operating modes need in-band negotiation to be active and which ones don't, parse the available information from the device tree. That will be correct in the cases we can already guess, and more.
---v1->v2: none
drivers/net/mscc_eswitch/felix_switch.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
drivers/net/mscc_eswitch/felix_switch.c +4 -6
@@ -16,6 +16,7 @@*/ #include <dm/device_compat.h> +#include <dm/of_extra.h> #include <linux/delay.h> #include <net/dsa.h> #include <asm/io.h>
@@ -210,17 +211,14 @@ static int felix_init_sxgmii(struct mii_dev *imdio, int pidx)static void felix_start_pcs (struct udevice *dev,int port,struct phy_device *phy,struct mii_dev *imdio) { -bool autoneg = true; - -if (phy->phy_id ==PHY_FIXED_ID || - phy->interface ==PHY_INTERFACE_MODE_2500BASEX ) - autoneg = false; +ofnode node =dsa_port_get_ofnode (dev, port); +bool inband_an =ofnode_eth_uses_inband_aneg (node);switch (phy->interface) {case PHY_INTERFACE_MODE_SGMII :case PHY_INTERFACE_MODE_2500BASEX :case PHY_INTERFACE_MODE_QSGMII : -felix_init_sgmii (imdio, port, autoneg); +felix_init_sgmii (imdio, port, inband_an);break ;case PHY_INTERFACE_MODE_10GBASER :case PHY_INTERFACE_MODE_USXGMII :
Signature · 1 line
2.25.1
PATCH v2 6/10 net: dsa: add driver for NXP SJA1105 L2 switch
In reply to Vladimir OlteanThe SJA1105 driver is largely reused from Linux. Its programming model is that it is blank out of reset, and it waits for a static configuration stream over SPI, which contains all runtime parameters (it has no notion of "default values").
Keeping a binary array for the configuration stream would have meant that aspects such as the CPU port and the MAC speeds could have not been configured easily, and would have been static and board-dependent. Live-patching the binary array means recalculating the static config table CRCs, which is not a fun process.
So we create an abstraction over the static config tables, using the packing API, same as in Linux. The tables are kept as C structures, and the binary configuration stream is constructed on-the-go, with CRC and all.
All static config tables instantiated in this driver are mandatory. The hardware reference manual can be found at:
https://www.nxp.com/docs/en/user-guide/UM10944.pdf
For tagging, a simplified version of tag_8021q from Linux is used. The VLAN EtherType is the same (0xdadb) but since we don't want switching in U-Boot, there is no reason to have a TX VLAN and an RX VLAN for each port. We just need the RX VLANs to act as the unique pvid of each front-panel port, to decode the switch port number. The RX VLAN is used for both RX and TX.
The device tree bindings are the same as in Linux.
---v1->v2: removed sgmii support from this patch
drivers/net/Kconfig | 16 + drivers/net/Makefile | 1 + drivers/net/sja1105.c | 2807 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2824 insertions(+) create mode 100644 drivers/net/sja1105.c
drivers/net/Kconfig +16 -0
@@ -542,6 +542,22 @@ config RTL8169 This driver supports Realtek 8169 series gigabit ethernet family of PCI/PCIe chipsets/adapters. +config SJA1105 + bool "NXP SJA1105 Ethernet switch family driver" + depends on DM_DSA && DM_SPI + select BITREVERSE + help + This is the driver for the NXP SJA1105 automotive Ethernet switch + family. These are 5-port devices and are managed over an SPI + interface. Probing is handled based on OF bindings. The driver + supports the following revisions: + - SJA1105E (Gen. 1, No TT-Ethernet) + - SJA1105T (Gen. 1, TT-Ethernet) + - SJA1105P (Gen. 2, No SGMII, No TT-Ethernet) + - SJA1105Q (Gen. 2, No SGMII, TT-Ethernet) + - SJA1105R (Gen. 2, SGMII, No TT-Ethernet) + - SJA1105S (Gen. 2, SGMII, TT-Ethernet) + config SMC911X bool "SMSC LAN911x and LAN921x controller driver"
drivers/net/Makefile +1 -0
@@ -28,6 +28,7 @@ obj-$(CONFIG_DM_ETH_PHY) += eth-phy-uclass.o obj-$(CONFIG_E1000) += e1000.o obj-$(CONFIG_E1000_SPI) += e1000_spi.o obj-$(CONFIG_EEPRO100) += eepro100.o +obj-$(CONFIG_SJA1105) += sja1105.o obj-$(CONFIG_SUN4I_EMAC) += sunxi_emac.o obj-$(CONFIG_SUN8I_EMAC) += sun8i_emac.o obj-$(CONFIG_EP93XX) += ep93xx_eth.o
drivers/net/sja1105.c new file +2807 -0
2,807 lines not on this page · raw message
Signature · 1 line
2.25.1
PATCH v2 7/10 net: dsa: sja1105: add support for SGMII
In reply to Vladimir OlteanThe list of ports which support SGMII depending on switch generation is available here:
https://www.kernel.org/doc/html/latest/networking/dsa/sja1105.html#port-compatibility-matrix
SGMII can either be used to connect to an external PHY or to the host port. In the first case, the use of in-band autoneg is expected, in the last, in-band autoneg is expected to be turned off (fixed-link). So the driver supports both cases.
SGMII support means configuring the PCS and PMA. The PCS is a Synopsys Designware XPCS, in Linux this has a separate driver but here it is embedded within the sja1105 driver. If needed it can be taken out later, although we would need a UCLASS_PCS for it, which we don't have atm.
Nonetheless, I did go all the way to export an internal MDIO bus for PCS access, because it is nice to be able to debug the PCS through commands such as:
=> mdio read ethernet-switch@1-pcs 4 1f.0
Reading from bus ethernet-switch@1-pcs
PHY at address 4:
31.0 - 0x1140
The internal MDIO bus is not registered with DM because there is no udevice on it, as mentioned. But the XPCS code can still be ripped out, as needed.
I did not add support for 2500base-x because I do not expect this interface type to be used as a boot source for anybody, it would just add unnecessary bloat.
---v1->v2:
- split from the previous patch.
- fixed the XPCS initialization sequence to be the same as what it is going to be in Linux when this patch gets applied:
https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/
drivers/net/sja1105.c | 571 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 570 insertions(+), 1 deletion(-)
drivers/net/sja1105.c +570 -1
@@ -37,6 +37,7 @@ enum packing_op {#define SJA1105ET_FDB_BIN_SIZE 4#define SJA1105_SIZE_CGU_CMD 4#define SJA1105_SIZE_RESET_CMD 4 +#define SJA1105_SIZE_MDIO_CMD 4#define SJA1105_SIZE_SPI_MSG_HEADER 4#define SJA1105_SIZE_SPI_MSG_MAXLEN (64 * 4)#define SJA1105_SIZE_DEVICE_ID 4
@@ -95,6 +96,8 @@ enum packing_op {#define SJA1105_RSV_ADDR 0xffffffffffffffffull +#define SJA1110_PCS_BANK_REG SJA1110_SPI_ADDR(0x3fc) +#define DSA_8021Q_DIR_TX BIT(11)#define DSA_8021Q_PORT_SHIFT 0#define DSA_8021Q_PORT_MASK GENMASK(3, 0)
@@ -103,6 +106,89 @@ enum packing_op {#define SJA1105_RATE_MBPS (speed) (((speed) * 64000) / 1000) +/* XPCS registers */ + +/* VR MII MMD registers offsets */ +#define DW_VR_MII_DIG_CTRL1 0x8000 +#define DW_VR_MII_AN_CTRL 0x8001 +#define DW_VR_MII_DIG_CTRL2 0x80e1 + +/* VR_MII_DIG_CTRL1 */ +#define DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW BIT(9) + +/* VR_MII_DIG_CTRL2 */ +#define DW_VR_MII_DIG_CTRL2_TX_POL_INV BIT(4) + +/* VR_MII_AN_CTRL */ +#define DW_VR_MII_AN_CTRL_TX_CONFIG_SHIFT 3 +#define DW_VR_MII_TX_CONFIG_MASK BIT(3) +#define DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII 0x0 +#define DW_VR_MII_AN_CTRL_PCS_MODE_SHIFT 1 +#define DW_VR_MII_PCS_MODE_MASK GENMASK(2, 1) +#define DW_VR_MII_PCS_MODE_C37_SGMII 0x2 + +/* PMA registers */ + +/* LANE_DRIVER1_0 register */ +#define SJA1110_LANE_DRIVER1_0 0x8038 +#define SJA1110_TXDRV (x) (((x) << 12) & GENMASK(14, 12)) + +/* LANE_DRIVER2_0 register */ +#define SJA1110_LANE_DRIVER2_0 0x803a +#define SJA1110_TXDRVTRIM_LSB (x) ((x) & GENMASK_ULL(15, 0)) + +/* LANE_DRIVER2_1 register */ +#define SJA1110_LANE_DRIVER2_1 0x803b +#define SJA1110_LANE_DRIVER2_1_RSV BIT(9) +#define SJA1110_TXDRVTRIM_MSB (x) (((x) & GENMASK_ULL(23, 16)) >> 16) + +/* LANE_TRIM register */ +#define SJA1110_LANE_TRIM 0x8040 +#define SJA1110_TXTEN BIT(11) +#define SJA1110_TXRTRIM (x) (((x) << 8) & GENMASK(10, 8)) +#define SJA1110_TXPLL_BWSEL BIT(7) +#define SJA1110_RXTEN BIT(6) +#define SJA1110_RXRTRIM (x) (((x) << 3) & GENMASK(5, 3)) +#define SJA1110_CDR_GAIN BIT(2) +#define SJA1110_ACCOUPLE_RXVCM_EN BIT(0) + +/* LANE_DATAPATH_1 register */ +#define SJA1110_LANE_DATAPATH_1 0x8037 + +/* POWERDOWN_ENABLE register */ +#define SJA1110_POWERDOWN_ENABLE 0x8041 +#define SJA1110_TXPLL_PD BIT(12) +#define SJA1110_TXPD BIT(11) +#define SJA1110_RXPKDETEN BIT(10) +#define SJA1110_RXCH_PD BIT(9) +#define SJA1110_RXBIAS_PD BIT(8) +#define SJA1110_RESET_SER_EN BIT(7) +#define SJA1110_RESET_SER BIT(6) +#define SJA1110_RESET_DES BIT(5) +#define SJA1110_RCVEN BIT(4) + +/* RXPLL_CTRL0 register */ +#define SJA1110_RXPLL_CTRL0 0x8065 +#define SJA1110_RXPLL_FBDIV (x) (((x) << 2) & GENMASK(9, 2)) + +/* RXPLL_CTRL1 register */ +#define SJA1110_RXPLL_CTRL1 0x8066 +#define SJA1110_RXPLL_REFDIV (x) ((x) & GENMASK(4, 0)) + +/* TXPLL_CTRL0 register */ +#define SJA1110_TXPLL_CTRL0 0x806d +#define SJA1110_TXPLL_FBDIV (x) ((x) & GENMASK(11, 0)) + +/* TXPLL_CTRL1 register */ +#define SJA1110_TXPLL_CTRL1 0x806e +#define SJA1110_TXPLL_REFDIV (x) ((x) & GENMASK(5, 0)) + +/* RX_DATA_DETECT register */ +#define SJA1110_RX_DATA_DETECT 0x8045 + +/* RX_CDR_CTLE register */ +#define SJA1110_RX_CDR_CTLE 0x8042 +/* UM10944.pdf Page 11, Table 2. Configuration Blocks */ enum {BLKID_L2_POLICING =0x06 ,
@@ -203,11 +289,18 @@ struct sja1105_static_config {struct sja1105_table tables[BLK_IDX_MAX ]; }; +struct sja1105_xpcs_cfg { +bool inband_an; +int speed; +}; +struct sja1105_private {struct sja1105_static_config static_config;bool rgmii_rx_delay[SJA1105_MAX_NUM_PORTS ];bool rgmii_tx_delay[SJA1105_MAX_NUM_PORTS ];u16 pvid[SJA1105_MAX_NUM_PORTS ]; +struct sja1105_xpcs_cfg xpcs_cfg[SJA1105_MAX_NUM_PORTS ]; +struct mii_dev *mdio_pcs;const struct sja1105_info *info;struct udevice *dev; };
@@ -226,6 +319,7 @@ typedef enum {XMII_MODE_MII =0 ,XMII_MODE_RMII =1 ,XMII_MODE_RGMII =2 , +XMII_MODE_SGMII =3 , } sja1105_phy_interface_t; enum {
@@ -263,6 +357,7 @@ struct sja1105_regs {u64 rgmii_tx_clk[SJA1105_MAX_NUM_PORTS ];u64 rmii_ref_clk[SJA1105_MAX_NUM_PORTS ];u64 rmii_ext_tx_clk[SJA1105_MAX_NUM_PORTS ]; +u64 pcs_base[SJA1105_MAX_NUM_PORTS ]; };struct sja1105_info {
@@ -272,10 +367,15 @@ struct sja1105_info {const struct sja1105_regs *regs;int (*reset_cmd)(struct sja1105_private *priv);int (*setup_rgmii_delay)(struct sja1105_private *priv,int port); +int (*pcs_mdio_read)(struct mii_dev *bus,int phy,int mmd,int reg); +int (*pcs_mdio_write)(struct mii_dev *bus,int phy,int mmd,int reg, +u16 val); +int (*pma_config)(struct sja1105_private *priv,int port);const char *name;bool supports_mii[SJA1105_MAX_NUM_PORTS ];bool supports_rmii[SJA1105_MAX_NUM_PORTS ];bool supports_rgmii[SJA1105_MAX_NUM_PORTS ]; +bool supports_sgmii[SJA1105_MAX_NUM_PORTS ];const u64 port_speed[SJA1105_SPEED_MAX ]; };
@@ -2030,6 +2130,233 @@ static int sja1105_rmii_clocking_setup(struct sja1105_private *priv, int port,return 0 ; } +static int sja1105_pcs_read (struct sja1105_private *priv,int addr, +int devad,int regnum) +{ +return priv->mdio_pcs->read (priv->mdio_pcs, addr, devad, regnum); +} + +static int sja1105_pcs_write (struct sja1105_private *priv,int addr, +int devad,int regnum,u16 val) +{ +return priv->mdio_pcs->write (priv->mdio_pcs, addr, devad, regnum, val); +} + +/* In NXP SJA1105, the PCS 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. +*/ +static int sja1105_pma_config (struct sja1105_private *priv,int port) +{ +return sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +DW_VR_MII_DIG_CTRL2 , +DW_VR_MII_DIG_CTRL2_TX_POL_INV ); +} + +static int sja1110_pma_config (struct sja1105_private *priv,int port) +{ +u16 txpll_fbdiv =0x19 , txpll_refdiv =0x1 ; +u16 rxpll_fbdiv =0x19 , rxpll_refdiv =0x1 ; +u16 rx_cdr_ctle =0x212a ; +u16 val; +int rc; + +/* Program TX PLL feedback divider and reference divider settings for +* correct oscillation frequency. +*/ + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,SJA1110_TXPLL_CTRL0 , +SJA1110_TXPLL_FBDIV (txpll_fbdiv)); +if (rc <0 ) +return rc; + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,SJA1110_TXPLL_CTRL1 , +SJA1110_TXPLL_REFDIV (txpll_refdiv)); +if (rc <0 ) +return rc; + +/* Program transmitter amplitude and disable amplitude trimming */ + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +SJA1110_LANE_DRIVER1_0 ,SJA1110_TXDRV (0x5 )); +if (rc <0 ) +return rc; + + val =SJA1110_TXDRVTRIM_LSB (0xffffffull ); + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +SJA1110_LANE_DRIVER2_0 , val); +if (rc <0 ) +return rc; + + val =SJA1110_TXDRVTRIM_MSB (0xffffffull ) |SJA1110_LANE_DRIVER2_1_RSV ; + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +SJA1110_LANE_DRIVER2_1 , val); +if (rc <0 ) +return rc; + +/* Enable input and output resistor terminations for low BER. */ + val =SJA1110_ACCOUPLE_RXVCM_EN |SJA1110_CDR_GAIN | +SJA1110_RXRTRIM (4 ) |SJA1110_RXTEN |SJA1110_TXPLL_BWSEL | +SJA1110_TXRTRIM (3 ) |SJA1110_TXTEN ; + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,SJA1110_LANE_TRIM , + val); +if (rc <0 ) +return rc; + +/* Select PCS as transmitter data source. */ + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +SJA1110_LANE_DATAPATH_1 ,0 ); +if (rc <0 ) +return rc; + +/* Program RX PLL feedback divider and reference divider for correct +* oscillation frequency. +*/ + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,SJA1110_RXPLL_CTRL0 , +SJA1110_RXPLL_FBDIV (rxpll_fbdiv)); +if (rc <0 ) +return rc; + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,SJA1110_RXPLL_CTRL1 , +SJA1110_RXPLL_REFDIV (rxpll_refdiv)); +if (rc <0 ) +return rc; + +/* Program threshold for receiver signal detector. +* Enable control of RXPLL by receiver signal detector to disable RXPLL +* when an input signal is not present. +*/ + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +SJA1110_RX_DATA_DETECT ,0x0005 ); +if (rc <0 ) +return rc; + +/* Enable TX and RX PLLs and circuits. +* Release reset of PMA to enable data flow to/from PCS. +*/ + rc =sja1105_pcs_read (priv, port,MDIO_MMD_VEND2 , +SJA1110_POWERDOWN_ENABLE ); +if (rc <0 ) +return rc; + + val = rc & ~(SJA1110_TXPLL_PD |SJA1110_TXPD |SJA1110_RXCH_PD | +SJA1110_RXBIAS_PD |SJA1110_RESET_SER_EN | +SJA1110_RESET_SER |SJA1110_RESET_DES ); + val |=SJA1110_RXPKDETEN |SJA1110_RCVEN ; + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 , +SJA1110_POWERDOWN_ENABLE , val); +if (rc <0 ) +return rc; + +/* Program continuous-time linear equalizer (CTLE) settings. */ + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,SJA1110_RX_CDR_CTLE , + rx_cdr_ctle); +if (rc <0 ) +return rc; + +return 0 ; +} + +static int sja1105_xpcs_config_aneg_c37_sgmii (struct sja1105_private *priv, +int port) +{ +int rc; + + rc =sja1105_pcs_read (priv, port,MDIO_MMD_VEND2 ,MDIO_CTRL1 ); +if (rc <0 ) +return rc; + rc &= ~MDIO_AN_CTRL1_ENABLE ; + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,MDIO_CTRL1 , + rc); +if (rc <0 ) +return rc; + + rc =sja1105_pcs_read (priv, port,MDIO_MMD_VEND2 ,DW_VR_MII_AN_CTRL ); +if (rc <0 ) +return rc; + + rc &= ~(DW_VR_MII_PCS_MODE_MASK |DW_VR_MII_TX_CONFIG_MASK ); + rc |= (DW_VR_MII_PCS_MODE_C37_SGMII << +DW_VR_MII_AN_CTRL_PCS_MODE_SHIFT & +DW_VR_MII_PCS_MODE_MASK ); + rc |= (DW_VR_MII_TX_CONFIG_MAC_SIDE_SGMII << +DW_VR_MII_AN_CTRL_TX_CONFIG_SHIFT & +DW_VR_MII_TX_CONFIG_MASK ); + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,DW_VR_MII_AN_CTRL , + rc); +if (rc <0 ) +return rc; + + rc =sja1105_pcs_read (priv, port,MDIO_MMD_VEND2 ,DW_VR_MII_DIG_CTRL1 ); +if (rc <0 ) +return rc; + +if (priv->xpcs_cfg[port].inband_an) + rc |=DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW ; +else + rc &= ~DW_VR_MII_DIG_CTRL1_MAC_AUTO_SW ; + + rc =sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,DW_VR_MII_DIG_CTRL1 , + rc); +if (rc <0 ) +return rc; + + rc =sja1105_pcs_read (priv, port,MDIO_MMD_VEND2 ,MDIO_CTRL1 ); +if (rc <0 ) +return rc; + +if (priv->xpcs_cfg[port].inband_an) + rc |=MDIO_AN_CTRL1_ENABLE ; +else + rc &= ~MDIO_AN_CTRL1_ENABLE ; + +return sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,MDIO_CTRL1 , rc); +} + +static int sja1105_xpcs_link_up_sgmii (struct sja1105_private *priv,int port) +{ +int val =BMCR_FULLDPLX ; + +if (priv->xpcs_cfg[port].inband_an) +return 0 ; + +switch (priv->xpcs_cfg[port].speed) { +case SPEED_1000 : + val =BMCR_SPEED1000 ; +break ; +case SPEED_100 : + val =BMCR_SPEED100 ; +break ; +case SPEED_10 : + val =BMCR_SPEED10 ; +break ; +default : +dev_err (priv->dev,"Invalid PCS speed %d\n" , + priv->xpcs_cfg[port].speed); +return -EINVAL ; + } + +return sja1105_pcs_write (priv, port,MDIO_MMD_VEND2 ,MDIO_CTRL1 , val); +} + +static int sja1105_sgmii_setup (struct sja1105_private *priv,int port) +{ +int rc; + + rc =sja1105_xpcs_config_aneg_c37_sgmii (priv, port); +if (rc) +return rc; + + rc =sja1105_xpcs_link_up_sgmii (priv, port); +if (rc) +return rc; + +return priv->info->pma_config (priv, port); +} +static int sja1105_clocking_setup_port (struct sja1105_private *priv,int port) {struct sja1105_xmii_params_entry *mii;
@@ -2054,6 +2381,9 @@ static int sja1105_clocking_setup_port(struct sja1105_private *priv, int port)case XMII_MODE_RGMII : rc =sja1105_rgmii_clocking_setup (priv, port, role);break ; +case XMII_MODE_SGMII : + rc =sja1105_sgmii_setup (priv, port); +break ;default :return -EINVAL ; }
@@ -2077,6 +2407,188 @@ static int sja1105_clocking_setup(struct sja1105_private *priv)return 0 ; } +static int sja1105_pcs_mdio_read (struct mii_dev *bus,int phy,int mmd,int reg) +{ +u8 packed_buf[SJA1105_SIZE_MDIO_CMD ] = {0 }; +struct sja1105_private *priv = bus->priv; +const int size =SJA1105_SIZE_MDIO_CMD ; +u64 addr, tmp; +int rc; + +if (mmd ==MDIO_DEVAD_NONE ) +return -ENODEV ; + +if (!priv->info->supports_sgmii[phy]) +return -ENODEV ; + + addr = (mmd <<16 ) | (reg &GENMASK (15 ,0 )); + +if (mmd !=MDIO_MMD_VEND1 && mmd !=MDIO_MMD_VEND2 ) +return 0xffff ; + + rc =sja1105_xfer_buf (priv,SPI_READ , addr, packed_buf, size); +if (rc <0 ) +return rc; + +sja1105_packing (packed_buf, &tmp,31 ,0 , size,UNPACK ); + +return tmp &0xffff ; +} + +static int sja1105_pcs_mdio_write (struct mii_dev *bus,int phy,int mmd, +int reg,u16 val) +{ +u8 packed_buf[SJA1105_SIZE_MDIO_CMD ] = {0 }; +struct sja1105_private *priv = bus->priv; +const int size =SJA1105_SIZE_MDIO_CMD ; +u64 addr, tmp; + +if (mmd ==MDIO_DEVAD_NONE ) +return -ENODEV ; + +if (!priv->info->supports_sgmii[phy]) +return -ENODEV ; + + addr = (mmd <<16 ) | (reg &GENMASK (15 ,0 )); + tmp = val; + +if (mmd !=MDIO_MMD_VEND1 && mmd !=MDIO_MMD_VEND2 ) +return -ENODEV ; + +sja1105_packing (packed_buf, &tmp,31 ,0 , size,PACK ); + +return sja1105_xfer_buf (priv,SPI_WRITE , addr, packed_buf, size); +} + +static int sja1110_pcs_mdio_read (struct mii_dev *bus,int phy,int mmd,int reg) +{ +struct sja1105_private *priv = bus->priv; +const struct sja1105_regs *regs = priv->info->regs; +u8 packed_buf[SJA1105_SIZE_MDIO_CMD ] = {0 }; +const int size =SJA1105_SIZE_MDIO_CMD ; +int offset, bank; +u64 addr, tmp; +int rc; + +if (mmd ==MDIO_DEVAD_NONE ) +return -ENODEV ; + +if (regs->pcs_base[phy] ==SJA1105_RSV_ADDR ) +return -ENODEV ; + + addr = (mmd <<16 ) | (reg &GENMASK (15 ,0 )); + + bank = addr >>8 ; + offset = addr &GENMASK (7 ,0 ); + +/* This addressing scheme reserves register 0xff for the bank address +* register, so that can never be addressed. +*/ +if (offset ==0xff ) +return -ENODEV ; + + tmp = bank; + +sja1105_packing (packed_buf, &tmp,31 ,0 , size,PACK ); + + rc =sja1105_xfer_buf (priv,SPI_WRITE , + regs->pcs_base[phy] +SJA1110_PCS_BANK_REG , + packed_buf, size); +if (rc <0 ) +return rc; + + rc =sja1105_xfer_buf (priv,SPI_READ , regs->pcs_base[phy] + offset, + packed_buf, size); +if (rc <0 ) +return rc; + +sja1105_packing (packed_buf, &tmp,31 ,0 , size,UNPACK ); + +return tmp &0xffff ; +} + +static int sja1110_pcs_mdio_write (struct mii_dev *bus,int phy,int mmd, +int reg,u16 val) +{ +struct sja1105_private *priv = bus->priv; +const struct sja1105_regs *regs = priv->info->regs; +u8 packed_buf[SJA1105_SIZE_MDIO_CMD ] = {0 }; +const int size =SJA1105_SIZE_MDIO_CMD ; +int offset, bank; +u64 addr, tmp; +int rc; + +if (mmd ==MDIO_DEVAD_NONE ) +return -ENODEV ; + +if (regs->pcs_base[phy] ==SJA1105_RSV_ADDR ) +return -ENODEV ; + + addr = (mmd <<16 ) | (reg &GENMASK (15 ,0 )); + + bank = addr >>8 ; + offset = addr &GENMASK (7 ,0 ); + +/* This addressing scheme reserves register 0xff for the bank address +* register, so that can never be addressed. +*/ +if (offset ==0xff ) +return -ENODEV ; + + tmp = bank; +sja1105_packing (packed_buf, &tmp,31 ,0 , size,PACK ); + + rc =sja1105_xfer_buf (priv,SPI_WRITE , + regs->pcs_base[phy] +SJA1110_PCS_BANK_REG , + packed_buf, size); +if (rc <0 ) +return rc; + + tmp = val; +sja1105_packing (packed_buf, &tmp,31 ,0 , size,PACK ); + +return sja1105_xfer_buf (priv,SPI_WRITE , regs->pcs_base[phy] + offset, + packed_buf, size); +} + +static int sja1105_mdiobus_register (struct sja1105_private *priv) +{ +struct udevice *dev = priv->dev; +struct mii_dev *bus; +int rc; + +if (!priv->info->pcs_mdio_read || !priv->info->pcs_mdio_write) +return 0 ; + + bus =mdio_alloc (); +if (!bus) +return -ENOMEM ; + +snprintf (bus->name,MDIO_NAME_LEN ,"%s-pcs" , dev->name); + bus->read = priv->info->pcs_mdio_read; + bus->write = priv->info->pcs_mdio_write; + bus->priv = priv; + + rc =mdio_register (bus); +if (rc) { +mdio_free (bus); +return rc; + } + + priv->mdio_pcs = bus; + +return 0 ; +} + +static void sja1105_mdiobus_unregister (struct sja1105_private *priv) +{ +if (!priv->mdio_pcs) +return ; + +mdio_unregister (priv->mdio_pcs); +mdio_free (priv->mdio_pcs); +} +static const struct sja1105_regs sja1105et_regs = { .device_id =0x0 , .prod_id =0x100BC3 ,
@@ -2185,6 +2697,9 @@ static const struct sja1105_regs sja1110_regs = {SJA1105_RSV_ADDR ,SJA1105_RSV_ADDR ,SJA1105_RSV_ADDR ,SJA1105_RSV_ADDR , SJA1105_RSV_ADDR}, + .pcs_base = {SJA1105_RSV_ADDR, 0x1c1400, 0x1c1800, 0x1c1c00, 0x1c2000, +SJA1105_RSV_ADDR ,SJA1105_RSV_ADDR ,SJA1105_RSV_ADDR , + SJA1105_RSV_ADDR, SJA1105_RSV_ADDR, SJA1105_RSV_ADDR}, }; enum sja1105_switch_id {
@@ -2279,6 +2794,9 @@ static const struct sja1105_info sja1105_info[] = { .setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay, .reset_cmd = sja1105pqrs_reset_cmd, .regs = &sja1105pqrs_regs, + .pcs_mdio_read = sja1105_pcs_mdio_read, + .pcs_mdio_write = sja1105_pcs_mdio_write, + .pma_config = sja1105_pma_config, .port_speed = { [SJA1105_SPEED_AUTO] = 0, [SJA1105_SPEED_10MBPS] = 3,
@@ -2288,6 +2806,7 @@ static const struct sja1105_info sja1105_info[] = { .supports_mii = {true, true, true, true, true}, .supports_rmii = {true, true, true, true, true}, .supports_rgmii = {true, true, true, true, true}, + .supports_sgmii = {false, false, false, false, true}, .name = "SJA1105R", }, [SJA1105S] = {
@@ -2297,6 +2816,9 @@ static const struct sja1105_info sja1105_info[] = { .setup_rgmii_delay = sja1105pqrs_setup_rgmii_delay, .reset_cmd = sja1105pqrs_reset_cmd, .regs = &sja1105pqrs_regs, + .pcs_mdio_read = sja1105_pcs_mdio_read, + .pcs_mdio_write = sja1105_pcs_mdio_write, + .pma_config = sja1105_pma_config, .port_speed = { [SJA1105_SPEED_AUTO] = 0, [SJA1105_SPEED_10MBPS] = 3,
@@ -2306,6 +2828,7 @@ static const struct sja1105_info sja1105_info[] = { .supports_mii = {true, true, true, true, true}, .supports_rmii = {true, true, true, true, true}, .supports_rgmii = {true, true, true, true, true}, + .supports_sgmii = {false, false, false, false, true}, .name = "SJA1105S", }, [SJA1110A] = {
@@ -2315,6 +2838,9 @@ static const struct sja1105_info sja1105_info[] = { .setup_rgmii_delay = sja1110_setup_rgmii_delay, .reset_cmd = sja1110_reset_cmd, .regs = &sja1110_regs, + .pcs_mdio_read = sja1110_pcs_mdio_read, + .pcs_mdio_write = sja1110_pcs_mdio_write, + .pma_config = sja1110_pma_config, .port_speed = { [SJA1105_SPEED_AUTO] = 0, [SJA1105_SPEED_10MBPS] = 4,
@@ -2327,6 +2853,8 @@ static const struct sja1105_info sja1105_info[] = { false, false, false, false, false, false}, .supports_rgmii = {false, false, true, true, false, false, false, false, false, false, false}, + .supports_sgmii = {false, true, true, true, true, + false, false, false, false, false, false}, .name = "SJA1110A", }, [SJA1110B] = {
@@ -2336,6 +2864,9 @@ static const struct sja1105_info sja1105_info[] = { .setup_rgmii_delay = sja1110_setup_rgmii_delay, .reset_cmd = sja1110_reset_cmd, .regs = &sja1110_regs, + .pcs_mdio_read = sja1110_pcs_mdio_read, + .pcs_mdio_write = sja1110_pcs_mdio_write, + .pma_config = sja1110_pma_config, .port_speed = { [SJA1105_SPEED_AUTO] = 0, [SJA1105_SPEED_10MBPS] = 4,
@@ -2348,6 +2879,8 @@ static const struct sja1105_info sja1105_info[] = { false, false, false, false, false, false}, .supports_rgmii = {false, false, true, true, false, false, false, false, false, false, false}, + .supports_sgmii = {false, false, false, true, true, + false, false, false, false, false, false}, .name = "SJA1110B", }, [SJA1110C] = {
@@ -2357,6 +2890,9 @@ static const struct sja1105_info sja1105_info[] = { .setup_rgmii_delay = sja1110_setup_rgmii_delay, .reset_cmd = sja1110_reset_cmd, .regs = &sja1110_regs, + .pcs_mdio_read = sja1110_pcs_mdio_read, + .pcs_mdio_write = sja1110_pcs_mdio_write, + .pma_config = sja1110_pma_config, .port_speed = { [SJA1105_SPEED_AUTO] = 0, [SJA1105_SPEED_10MBPS] = 4,
@@ -2369,6 +2905,8 @@ static const struct sja1105_info sja1105_info[] = { false, false, false, false, false, false}, .supports_rgmii = {false, false, true, true, false, false, false, false, false, false, false}, + .supports_sgmii = {false, false, false, false, true, + false, false, false, false, false, false}, .name = "SJA1110C", }, [SJA1110D] = {
@@ -2378,6 +2916,9 @@ static const struct sja1105_info sja1105_info[] = { .setup_rgmii_delay = sja1110_setup_rgmii_delay, .reset_cmd = sja1110_reset_cmd, .regs = &sja1110_regs, + .pcs_mdio_read = sja1110_pcs_mdio_read, + .pcs_mdio_write = sja1110_pcs_mdio_write, + .pma_config = sja1110_pma_config, .port_speed = { [SJA1105_SPEED_AUTO] = 0, [SJA1105_SPEED_10MBPS] = 4,
@@ -2390,6 +2931,8 @@ static const struct sja1105_info sja1105_info[] = { false, false, false, false, false, false}, .supports_rgmii = {false, false, true, false, false, false, false, false, false, false, false}, + .supports_sgmii = {false, true, true, true, true, + false, false, false, false, false, false}, .name = "SJA1110D", }, };
@@ -2541,8 +3084,12 @@ static int sja1105_static_config_reload(struct sja1105_private *priv)static int sja1105_port_probe (struct udevice *dev,int port,struct phy_device *phy) { +struct sja1105_private *priv =dev_get_priv (dev); +ofnode node =dsa_port_get_ofnode (dev, port);phy_interface_t phy_mode = phy->interface; + priv->xpcs_cfg[port].inband_an =ofnode_eth_uses_inband_aneg (node); +if (phy_mode ==PHY_INTERFACE_MODE_MII || phy_mode ==PHY_INTERFACE_MODE_RMII ) { phy->supported &=PHY_BASIC_FEATURES ;
@@ -2593,6 +3140,13 @@ static int sja1105_port_enable(struct udevice *dev, int port, mii->xmii_mode[port] =XMII_MODE_RGMII ;break ; +case PHY_INTERFACE_MODE_SGMII : +if (!priv->info->supports_sgmii[port]) + goto unsupported; + + mii->xmii_mode[port] =XMII_MODE_SGMII ; + mii->special[port] = true; +break ; unsupported:default : dev_err(dev, "Unsupported PHY mode %d on port %d!\n",
@@ -2621,7 +3175,10 @@ unsupported: } } -if (phy->speed ==SPEED_1000 ) { +if (mii->xmii_mode[port] ==XMII_MODE_SGMII ) { + mac[port].speed = priv->info->port_speed[SJA1105_SPEED_1000MBPS ]; + priv->xpcs_cfg[port].speed = phy->speed; + }else if (phy->speed ==SPEED_1000 ) { mac[port].speed = priv->info->port_speed[SJA1105_SPEED_1000MBPS ]; }else if (phy->speed ==SPEED_100 ) { mac[port].speed = priv->info->port_speed[SJA1105_SPEED_100MBPS ];
@@ -2688,7 +3245,18 @@ static int sja1105_init(struct sja1105_private *priv)return rc; } + rc =sja1105_mdiobus_register (priv); +if (rc) { +printf ("Failed to register MDIO bus: %d\n" , rc); + goto err_mdiobus_register; + } +return 0 ; + +err_mdiobus_register: +sja1105_static_config_free (&priv->static_config); + +return rc; }static int sja1105_check_device_id (struct sja1105_private *priv)
@@ -2777,6 +3345,7 @@ static int sja1105_remove(struct udevice *dev) {struct sja1105_private *priv =dev_get_priv (dev); +sja1105_mdiobus_unregister (priv);sja1105_static_config_free (&priv->static_config);return 0 ;
Signature · 1 line
2.25.1
PATCH v2 8/10 arm: dts: ls1021a-tsn: add sja1105 and eth2 bindings
In reply to Vladimir OlteanThe eth aliases are for correct probing order, so that each Ethernet port will get a predictable MAC address from the environment.
---v1->v2: none
arch/arm/dts/ls1021a-tsn.dts | 103 +++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+)
arch/arm/dts/ls1021a-tsn.dts +103 -0
@@ -14,6 +14,81 @@ enet1-sgmii-phy = &sgmii_phy1; spi0 = &qspi; spi1 = &dspi1; + ethernet0 = &enet0; + ethernet1 = &enet1; + ethernet2 = &enet2; + ethernet3 = &swp2; + ethernet4 = &swp3; + ethernet5 = &swp4; + ethernet6 = &swp5; + }; +}; + +&dspi0 { + bus-num = <0>; + status = "okay"; + + sja1105: ethernet-switch@1 { + reg = <0x1>; + #address-cells = <1>; + #size-cells = <0>; + compatible = "nxp,sja1105t"; + /* 12 MHz */ + spi-max-frequency = <12000000>; + /* Sample data on trailing clock edge */ + spi-cpha; + /* SPI controller settings for SJA1105 timing requirements */ + fsl,spi-cs-sck-delay = <1000>; + fsl,spi-sck-cs-delay = <1000>; + + ports { + #address-cells = <1>; + #size-cells = <0>; + + swp5: port@0 { + /* ETH5 written on chassis */ + label = "swp5"; + phy-handle = <&rgmii_phy6>; + phy-mode = "rgmii-id"; + reg = <0>; + }; + + swp2: port@1 { + /* ETH2 written on chassis */ + label = "swp2"; + phy-handle = <&rgmii_phy3>; + phy-mode = "rgmii-id"; + reg = <1>; + }; + + swp3: port@2 { + /* ETH3 written on chassis */ + label = "swp3"; + phy-handle = <&rgmii_phy4>; + phy-mode = "rgmii-id"; + reg = <2>; + }; + + swp4: port@3 { + /* ETH4 written on chassis */ + label = "swp4"; + phy-handle = <&rgmii_phy5>; + phy-mode = "rgmii-id"; + reg = <3>; + }; + + port@4 { + /* Internal port connected to eth2 */ + ethernet = <&enet2>; + phy-mode = "rgmii"; + reg = <4>; + + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; }; };
@@ -31,6 +106,17 @@ status = "okay"; }; +/* RGMII delays added via PCB traces */ +&enet2 { + phy-mode = "rgmii"; + status = "okay"; + + fixed-link { + speed = <1000>; + full-duplex; + }; +}; + &i2c0 { status = "okay"; };
@@ -46,6 +132,23 @@ reg = <0x2>; }; + /* BCM5464 quad PHY */ + rgmii_phy3: ethernet-phy@3 { + reg = <0x3>; + }; + + rgmii_phy4: ethernet-phy@4 { + reg = <0x4>; + }; + + rgmii_phy5: ethernet-phy@5 { + reg = <0x5>; + }; + + rgmii_phy6: ethernet-phy@6 { + reg = <0x6>; + }; + /* SGMII PCS for enet0 */ tbi0: tbi-phy@1f { reg = <0x1f>;
Signature · 1 line
2.25.1
PATCH v2 9/10 configs: ls1021a-tsn: enable sja1105 switch driver
In reply to Vladimir OlteanThe sja1105 is a 5-port switch that uses a DM_DSA driver. Its 5th (CPU) port is connected internally to the eth2 port of the LS1021A SoC.
---v1->v2: none
configs/ls1021atsn_qspi_defconfig | 2 ++ configs/ls1021atsn_sdcard_defconfig | 2 ++ 2 files changed, 4 insertions(+)
configs/ls1021atsn_qspi_defconfig +2 -0
@@ -44,6 +44,8 @@ CONFIG_PHY_BROADCOM=y CONFIG_PHY_FIXED=y CONFIG_DM_ETH=y CONFIG_DM_MDIO=y +CONFIG_DM_DSA=y +CONFIG_SJA1105=y CONFIG_PHY_GIGE=y CONFIG_MII=y CONFIG_TSEC_ENET=y
configs/ls1021atsn_sdcard_defconfig +2 -0
@@ -55,6 +55,8 @@ CONFIG_PHY_BROADCOM=y CONFIG_PHY_FIXED=y CONFIG_DM_ETH=y CONFIG_DM_MDIO=y +CONFIG_DM_DSA=y +CONFIG_SJA1105=y CONFIG_PHY_GIGE=y CONFIG_MII=y CONFIG_TSEC_ENET=y
Signature · 1 line
2.25.1
PATCH v2 10/10 configs: ls1021a-tsn: enable the generation of random Ethernet MAC addresses
In reply to Vladimir OlteanDon't fail when booting a board with an empty EEPROM for MAC addresses.
---v1->v2: none
configs/ls1021atsn_qspi_defconfig | 1 + configs/ls1021atsn_sdcard_defconfig | 1 + 2 files changed, 2 insertions(+)
configs/ls1021atsn_qspi_defconfig +1 -0
@@ -42,6 +42,7 @@ CONFIG_SPI_FLASH_DATAFLASH=y CONFIG_PHY_ATHEROS=y CONFIG_PHY_BROADCOM=y CONFIG_PHY_FIXED=y +CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM_ETH=y CONFIG_DM_MDIO=y CONFIG_DM_DSA=y
configs/ls1021atsn_sdcard_defconfig +1 -0
@@ -53,6 +53,7 @@ CONFIG_SPI_FLASH_DATAFLASH=y CONFIG_PHY_ATHEROS=y CONFIG_PHY_BROADCOM=y CONFIG_PHY_FIXED=y +CONFIG_NET_RANDOM_ETHADDR=y CONFIG_DM_ETH=y CONFIG_DM_MDIO=y CONFIG_DM_DSA=y
Signature · 1 line
2.25.1