DM DSA driver for NXP SJA1105 Ethernet switch
Subsystems (3)
Vladimir Oltean
maintainercover DM DSA driver for NXP SJA1105 Ethernet switch
This is a driver for the SJA1105 automotive L2 switch. It uses the DSA uclass proposed by Alex Marginean (but not yet merged) here [0]. This is convenient because with this framework, the switch acts as a 4-port Ethernet multiplexer capable of TFTP, but does not do switching, which is not unnecessary in the bootloader, and which would also cause issues in complex networks that rely on STP to block loops.
[0]: https://patchwork.ozlabs.org/patch/1203754/
Vladimir Oltean (3):
lib: import packing API from Linux
include: import if_vlan.h from Linux
net: add driver for NXP SJA1105 DSA L2 switch
drivers/net/Kconfig | 17 + drivers/net/Makefile | 1 + drivers/net/sja1105.c | 2309 +++++++++++++++++++++++++++++++++++++++ include/linux/if_vlan.h | 26 + include/linux/packing.h | 49 + lib/Kconfig | 17 + lib/Makefile | 1 + lib/packing.c | 208 ++++ 8 files changed, 2628 insertions(+) create mode 100644 drivers/net/sja1105.c create mode 100644 include/linux/if_vlan.h create mode 100644 include/linux/packing.h create mode 100644 lib/packing.c
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 1/3 lib: import packing API from Linux
This is needed to support the sja1105 DSA driver.
--- include/linux/packing.h | 49 ++++++++++ lib/Kconfig | 17 ++++ lib/Makefile | 1 + lib/packing.c | 208 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 275 insertions(+) create mode 100644 include/linux/packing.h create mode 100644 lib/packing.c
include/linux/packing.h new file +49 -0
@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: BSD-3-Clause +* Copyright (c) 2016-2018, NXP Semiconductors +* Copyright (c) 2018-2019, Vladimir Oltean <[email protected]> +*/ +#ifndef _LINUX_PACKING_H +#define _LINUX_PACKING_H + +#include <linux/types.h> +#include <linux/bitops.h> + +#define QUIRK_MSB_ON_THE_RIGHT BIT(0) +#define QUIRK_LITTLE_ENDIAN BIT(1) +#define QUIRK_LSW32_IS_FIRST BIT(2) + +enum packing_op { +PACK , +UNPACK , +}; + +/** +* packing - Convert numbers (currently u64) between a packed and an unpacked +* format. Unpacked means laid out in memory in the CPU's native +* understanding of integers, while packed means anything else that +* requires translation. +* +* @pbuf: Pointer to a buffer holding the packed value. +* @uval: Pointer to an u64 holding the unpacked value. +* @startbit: The index (in logical notation, compensated for quirks) where +* the packed value starts within pbuf. Must be larger than, or +* equal to, endbit. +* @endbit: The index (in logical notation, compensated for quirks) where +* the packed value ends within pbuf. Must be smaller than, or equal +* to, startbit. +* @op: If PACK, then uval will be treated as const pointer and copied (packed) +* into pbuf, between startbit and endbit. +* If UNPACK, then pbuf will be treated as const pointer and the logical +* value between startbit and endbit will be copied (unpacked) to uval. +* @quirks: A bit mask of QUIRK_LITTLE_ENDIAN, QUIRK_LSW32_IS_FIRST and +* QUIRK_MSB_ON_THE_RIGHT. +* +* Return: 0 on success, EINVAL or ERANGE if called incorrectly. Assuming +* correct usage, return code may be discarded. +* If op is PACK, pbuf is modified. +* If op is UNPACK, uval is modified. +*/ +int packing (void *pbuf,u64 *uval,int startbit,int endbit,size_t pbuflen, +enum packing_op op,u8 quirks); + +#endif
lib/Kconfig +17 -0
@@ -33,6 +33,23 @@ config HAVE_PRIVATE_LIBGCC config LIB_UUID bool +config PACKING + bool "Generic bitfield packing and unpacking" + default n + help + This option provides the packing() helper function, which permits + converting bitfields between a CPU-usable representation and a + memory representation that can have any combination of these quirks: + - Is little endian (bytes are reversed within a 32-bit group) + - The least-significant 32-bit word comes first (within a 64-bit + group) + - The most significant bit of a byte is at its right (bit 0 of a + register description is numerically 2^7). + Drivers may use these helpers to match the bit indices as described + in the data sheets of the peripherals they are in control of. + + When in doubt, say N. + config PRINTF bool default y
lib/Makefile +1 -0
@@ -104,6 +104,7 @@ obj-y += hexdump.o obj-$(CONFIG_TRACE) += trace.o obj-$(CONFIG_LIB_UUID) += uuid.o obj-$(CONFIG_LIB_RAND) += rand.o +obj-$(CONFIG_PACKING) += packing.o obj-y += panic.o ifeq ($(CONFIG_$(SPL_TPL_)BUILD),y)
lib/packing.c new file +208 -0
208 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH 2/3 include: import if_vlan.h from Linux
In reply to Vladimir OlteanThis is needed for the VLAN header structure.
--- 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.17.1
Vladimir Oltean
maintainerPATCH 3/3 net: add driver for NXP SJA1105 DSA 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 dsa_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, sans the custom sja1105,role-mac and sja1105,role-phy which are not implemented yet since I saw no immediate need for them.
--- drivers/net/Kconfig | 17 + drivers/net/Makefile | 1 + drivers/net/sja1105.c | 2309 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 2327 insertions(+) create mode 100644 drivers/net/sja1105.c
drivers/net/Kconfig +17 -0
@@ -381,6 +381,23 @@ 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 + select PACKING + 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
@@ -22,6 +22,7 @@ obj-$(CONFIG_DNET) += dnet.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 +2309 -0
2,309 lines not on this page · raw message
Signature · 1 line
2.17.1