NXP SJA1105 DSA driver
Subsystems (8)
Vladimir Oltean
maintainerv5 cover NXP SJA1105 DSA driver
This patchset adds a DSA driver for the SPI-controlled NXP SJA1105 switch. Due to the hardware's unfriendliness, most of its state needs to be shadowed in kernel memory by the driver. To support this and keep a decent amount of cleanliness in the code, a new generic API for converting between CPU-accessible ("unpacked") structures and hardware-accessible ("packed") structures is proposed and used.
The driver is GPL-2.0 licensed. The source code files which are licensed as BSD-3-Clause are hardware support files and derivative of the userspace NXP sja1105-tool program, which is BSD-3-Clause licensed.
TODO items:
* Add support for traffic.
* Add full support for the P/Q/R/S series. The patches were mostly tested on a first-generation T device.
* Add timestamping support and PTP clock manipulation.
* Figure out how the tc-taprio hardware offload that was just proposed by Vinicius can be used to configure the switch's time-aware scheduler.
* Rework link state callbacks to use phylink once the SGMII port is supported.
Changes in v5:
1. Removed trailing empty lines at the end of files.
2. Moved the lib/packing.c file under a CONFIG_PACKING option instead of having it always built-in. The module is GPL licensed, which applies to its distribution in binary form, but the code is dual-licensed which means it can be used in projects with other licenses as well.
3. Made SJA1105 driver select CONFIG_PACKING and CONFIG_CRC32.
v4 patchset can be found at:
https://lwn.net/Articles/787077/
Changes in v4:
1. Previous patchset was broken apart, and for the moment the driver is configuring the switch as unmanaged. Support for regular and management traffic, as well as for PTP timestamping, will be submitted once the basic driver is accepted. Some core DSA patches were also broken out of the series, and are a dependency for this series:
https://patchwork.ozlabs.org/project/netdev/list/?series=105069
2. Addressed Jiri Pirko's feedback about too generic function and macro naming.
3. Re-introduced ETH_P_DSA_8021Q.
v3 patchset can be found at:
https://lkml.org/lkml/2019/4/12/978
Changes in v3:
1. Removed the patch for a dedicated Ethertype to use with 802.1Q DSA tagging
2. Changed the SJA1105 switch tagging protocol sysfs label from "sja1105" to "8021q" to denote to users such as tcpdump that the structure is more generic.
3. Respun previous patch "net: dsa: Allow drivers to modulate between presence and absence of tagging". Current equivalent patch is called "net: dsa: Allow drivers to filter packets they can decode source port from" and at least allows reception of management traffic during the time when switch tagging is not enabled.
4. Added DSA-level fixes for the bridge core not unsetting vlan_filtering when ports leave. The global VLAN filtering is treated as a special case. Made the mt7530 driver use this. This patch benefits the SJA1105 because otherwise traffic in standalone mode would no longer work after removing the ports from a vlan_filtering bridge, since the driver and the hardware would be in an inconsistent state.
5. Restructured the documentation as rst. This depends upon the recently submitted "[PATCH net-next] Documentation: net: dsa: transition to the rst format": https://patchwork.ozlabs.org/patch/1084658/.
v2 patchset can be found at:
https://www.spinics.net/lists/netdev/msg563454.html
Changes in v2:
1. Device ID is no longer auto-detected but enforced based on explicit DT compatible string. This helps with stricter checking of DT bindings.
2. Group all device-specific operations into a sja1105_info structure and avoid using the IS_ET() and IS_PQRS() macros at runtime as much as possible.
3. Added more verbiage to commit messages and documentation.
4. Treat the case where RGMII internal delays are requested through DT bindings and return error.
5. Miscellaneous cosmetic cleanup in sja1105_clocking.c
6. Not advertising link features that are not supported, such as pause frames and the half duplex modes.
7. Fixed a mistake in previous patchset where the switch tagging was not actually enabled (lost during a rebase). This brought up another uncaught issue where switching at runtime between tagging and no-tagging was not supported by DSA. Fixed up the mistake in "net: dsa: sja1105: Add support for traffic through standalone ports", and added the new patch "net: dsa:
Allow drivers to modulate between presence and absence of tagging" to address the other issue.
8. Added a workaround for switch resets cutting a frame in the middle of transmission, which would throw off some link partners.
9. Changed the TPID from ETH_P_EDSA (0xDADA) to a newly introduced one:
ETH_P_DSA_8021Q (0xDADB). Uncovered another mistake in the previous patchset with a missing ntohs(), which was not caught because 0xDADA is endian-agnostic.
10. Made NET_DSA_TAG_8021Q select VLAN_8021Q
11. Renamed __dsa_port_vlan_add to dsa_port_vid_add and not to dsa_port_vlan_add_trans, as suggested, because the corresponding _del function does not have a transactional phase and the naming is more uniform this way.
v1 patchset can be found at:
https://www.spinics.net/lists/netdev/msg561589.html
Changes from RFC:
1. Removed the packing code for the static configuration tables that were not currently used
2. Removed the code for unpacking a static configuration structure from a memory buffer (not used)
3. Completely removed the SGMII stubs, since the configuration is not complete anyway.
4. Moved some code from the SJA1105 introduction commit into the patch that used it.
5. Made the code for checking global VLAN filtering generic and made b53 driver use it.
6. Made mt7530 driver use the new generic dp->vlan_filtering
7. Fixed check for stringset in .get_sset_count
8. Minor cleanup in sja1105_clocking.c
9. Fixed a confusing typo in DSA
RFC can be found at:
https://www.mail-archive.com/[email protected]/msg291717.html
Vladimir Oltean (12):
lib: Add support for generic packing operations
net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
net: dsa: sja1105: Add support for FDB and MDB management
net: dsa: sja1105: Error out if RGMII delays are requested in DT
ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
net: dsa: sja1105: Add support for VLAN operations
net: dsa: sja1105: Add support for ethtool port counters
net: dsa: sja1105: Add support for configuring address aging time
net: dsa: sja1105: Prevent PHY jabbering during switch reset
net: dsa: sja1105: Reject unsupported link modes for AN
Documentation: net: dsa: Add details about NXP SJA1105 driver
dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
.../devicetree/bindings/net/dsa/sja1105.txt | 156 ++ Documentation/networking/dsa/index.rst | 1 + Documentation/networking/dsa/sja1105.rst | 166 ++ Documentation/packing.txt | 149 ++ MAINTAINERS | 14 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 16 + drivers/net/dsa/sja1105/Makefile | 9 + drivers/net/dsa/sja1105/sja1105.h | 153 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 601 +++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 532 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 43 + drivers/net/dsa/sja1105/sja1105_ethtool.c | 417 +++++ drivers/net/dsa/sja1105/sja1105_main.c | 1459 +++++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 590 +++++++ .../net/dsa/sja1105/sja1105_static_config.c | 987 +++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 253 +++ include/linux/dsa/sja1105.h | 23 + include/linux/packing.h | 49 + include/uapi/linux/if_ether.h | 1 + lib/Kconfig | 17 + lib/Makefile | 1 + lib/packing.c | 213 +++ 24 files changed, 5853 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt create mode 100644 Documentation/networking/dsa/sja1105.rst create mode 100644 Documentation/packing.txt create mode 100644 drivers/net/dsa/sja1105/Kconfig create mode 100644 drivers/net/dsa/sja1105/Makefile create mode 100644 drivers/net/dsa/sja1105/sja1105.h create mode 100644 drivers/net/dsa/sja1105/sja1105_clocking.c create mode 100644 drivers/net/dsa/sja1105/sja1105_dynamic_config.c create mode 100644 drivers/net/dsa/sja1105/sja1105_dynamic_config.h create mode 100644 drivers/net/dsa/sja1105/sja1105_ethtool.c create mode 100644 drivers/net/dsa/sja1105/sja1105_main.c create mode 100644 drivers/net/dsa/sja1105/sja1105_spi.c create mode 100644 drivers/net/dsa/sja1105/sja1105_static_config.c create mode 100644 drivers/net/dsa/sja1105/sja1105_static_config.h create mode 100644 include/linux/dsa/sja1105.h create mode 100644 include/linux/packing.h create mode 100644 lib/packing.c
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 1/12 lib: Add support for generic packing operations
This provides an unified API for accessing register bit fields regardless of memory layout. The basic unit of data for these API functions is the u64. The process of transforming an u64 from native CPU encoding into the peripheral's encoding is called 'pack', and transforming it from peripheral to native CPU encoding is 'unpack'.
---
Changes in v5:
Moved under its own CONFIG_PACKING (default N).
Stripped blank lines at the end of files and replaced some alignment spaces with tabs.
Changes in v4:
None
Changes in v3:
None
Changes in v2:
None
Documentation/packing.txt | 149 ++++++++++++++++++++++++++ MAINTAINERS | 8 ++ include/linux/packing.h | 49 +++++++++ lib/Kconfig | 17 +++ lib/Makefile | 1 + lib/packing.c | 213 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 437 insertions(+) create mode 100644 Documentation/packing.txt create mode 100644 include/linux/packing.h create mode 100644 lib/packing.c
Documentation/packing.txt new file +149 -0
@@ -0,0 +1,149 @@ +================================================ +Generic bitfield packing and unpacking functions +================================================ + +Problem statement +----------------- + +When working with hardware, one has to choose between several approaches of +interfacing with it. +One can memory-map a pointer to a carefully crafted struct over the hardware +device's memory region, and access its fields as struct members (potentially +declared as bitfields). But writing code this way would make it less portable, +due to potential endianness mismatches between the CPU and the hardware device. +Additionally, one has to pay close attention when translating register +definitions from the hardware documentation into bit field indices for the +structs. Also, some hardware (typically networking equipment) tends to group +its register fields in ways that violate any reasonable word boundaries +(sometimes even 64 bit ones). This creates the inconvenience of having to +define "high" and "low" portions of register fields within the struct. +A more robust alternative to struct field definitions would be to extract the +required fields by shifting the appropriate number of bits. But this would +still not protect from endianness mismatches, except if all memory accesses +were performed byte-by-byte. Also the code can easily get cluttered, and the +high-level idea might get lost among the many bit shifts required. +Many drivers take the bit-shifting approach and then attempt to reduce the +clutter with tailored macros, but more often than not these macros take +shortcuts that still prevent the code from being truly portable. + +The solution +------------ + +This API deals with 2 basic operations: + - Packing a CPU-usable number into a memory buffer (with hardware + constraints/quirks) + - Unpacking a memory buffer (which has hardware constraints/quirks) + into a CPU-usable number. + +The API offers an abstraction over said hardware constraints and quirks, +over CPU endianness and therefore between possible mismatches between +the two. + +The basic unit of these API functions is the u64. From the CPU's +perspective, bit 63 always means bit offset 7 of byte 7, albeit only +logically. The question is: where do we lay this bit out in memory? + +The following examples cover the memory layout of a packed u64 field. +The byte offsets in the packed buffer are always implicitly 0, 1, ... 7. +What the examples show is where the logical bytes and bits sit. + +1. Normally (no quirks), we would do it like this: + +63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 +7 6 5 4 +31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +3 2 1 0 + +That is, the MSByte (7) of the CPU-usable u64 sits at memory offset 0, and the +LSByte (0) of the u64 sits at memory offset 7. +This corresponds to what most folks would regard to as "big endian", where +bit i corresponds to the number 2^i. This is also referred to in the code +comments as "logical" notation. + + +2. If QUIRK_MSB_ON_THE_RIGHT is set, we do it like this: + +56 57 58 59 60 61 62 63 48 49 50 51 52 53 54 55 40 41 42 43 44 45 46 47 32 33 34 35 36 37 38 39 +7 6 5 4 +24 25 26 27 28 29 30 31 16 17 18 19 20 21 22 23 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 +3 2 1 0 + +That is, QUIRK_MSB_ON_THE_RIGHT does not affect byte positioning, but +inverts bit offsets inside a byte. + + +3. If QUIRK_LITTLE_ENDIAN is set, we do it like this: + +39 38 37 36 35 34 33 32 47 46 45 44 43 42 41 40 55 54 53 52 51 50 49 48 63 62 61 60 59 58 57 56 +4 5 6 7 +7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 23 22 21 20 19 18 17 16 31 30 29 28 27 26 25 24 +0 1 2 3 + +Therefore, QUIRK_LITTLE_ENDIAN means that inside the memory region, every +byte from each 4-byte word is placed at its mirrored position compared to +the boundary of that word. + +4. If QUIRK_MSB_ON_THE_RIGHT and QUIRK_LITTLE_ENDIAN are both set, we do it + like this: + +32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 +4 5 6 7 +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +0 1 2 3 + + +5. If just QUIRK_LSW32_IS_FIRST is set, we do it like this: + +31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 +3 2 1 0 +63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 +7 6 5 4 + +In this case the 8 byte memory region is interpreted as follows: first +4 bytes correspond to the least significant 4-byte word, next 4 bytes to +the more significant 4-byte word. + + +6. If QUIRK_LSW32_IS_FIRST and QUIRK_MSB_ON_THE_RIGHT are set, we do it like + this: + +24 25 26 27 28 29 30 31 16 17 18 19 20 21 22 23 8 9 10 11 12 13 14 15 0 1 2 3 4 5 6 7 +3 2 1 0 +56 57 58 59 60 61 62 63 48 49 50 51 52 53 54 55 40 41 42 43 44 45 46 47 32 33 34 35 36 37 38 39 +7 6 5 4 + + +7. If QUIRK_LSW32_IS_FIRST and QUIRK_LITTLE_ENDIAN are set, it looks like + this: + +7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8 23 22 21 20 19 18 17 16 31 30 29 28 27 26 25 24 +0 1 2 3 +39 38 37 36 35 34 33 32 47 46 45 44 43 42 41 40 55 54 53 52 51 50 49 48 63 62 61 60 59 58 57 56 +4 5 6 7 + + +8. If QUIRK_LSW32_IS_FIRST, QUIRK_LITTLE_ENDIAN and QUIRK_MSB_ON_THE_RIGHT + are set, it looks like this: + +0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 +0 1 2 3 +32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 +4 5 6 7 + + +We always think of our offsets as if there were no quirk, and we translate +them afterwards, before accessing the memory region. + +Intended use +------------ + +Drivers that opt to use this API first need to identify which of the above 3 +quirk combinations (for a total of 8) match what the hardware documentation +describes. Then they should wrap the packing() function, creating a new +xxx_packing() that calls it using the proper QUIRK_* one-hot bits set. + +The packing() function returns an int-encoded error code, which protects the +programmer against incorrect API use. The errors are not expected to occur +durring runtime, therefore it is reasonable for xxx_packing() to return void +and simply swallow those errors. Optionally it can dump stack or print the +error description.
MAINTAINERS +8 -0
@@ -11673,6 +11673,14 @@ L: [email protected] S: Orphan F: drivers/i2c/busses/i2c-pasemi.c +PACKING +M: Vladimir Oltean <[email protected]> +L: [email protected] +S: Supported +F: lib/packing.c +F: include/linux/packing.h +F: Documentation/packing.txt + PADATA PARALLEL EXECUTION MECHANISM M: Steffen Klassert <[email protected]> L: [email protected]
include/linux/packing.h new file +49 -0
49 lines not on this page · raw message
lib/Kconfig +17 -0
@@ -18,6 +18,23 @@ config RAID6_PQ_BENCHMARK Benchmark all available RAID6 PQ functions on init and choose the fastest one. +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 BITREVERSE tristate
lib/Makefile +1 -0
@@ -108,6 +108,7 @@ obj-$(CONFIG_DEBUG_LIST) += list_debug.o obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o obj-$(CONFIG_BITREVERSE) += bitrev.o +obj-$(CONFIG_PACKING) += packing.o obj-$(CONFIG_RATIONAL) += rational.o obj-$(CONFIG_CRC_CCITT) += crc-ccitt.o obj-$(CONFIG_CRC16) += crc16.o
lib/packing.c new file +213 -0
213 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 2/12 net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
In reply to Vladimir OlteanAt this moment the following is supported:
* Link state management through phylib
* Autonomous L2 forwarding managed through iproute2 bridge commands.
IP termination must be done currently through the master netdevice, since the switch is unmanaged at this point and using DSA_TAG_PROTO_NONE.
---
Changes in v5:
Stripped blank lines at the end of files.
Added Kconfig "select" for PACKING and CRC32.
Changes in v4:
Rehashed all preprocessor definitions to be prefixed with SJA1105 except OP_READ, OP_WRITE and OP_DEL.
Changes in v3:
None.
Changes in v2:
1. Device ID is no longer auto-detected but enforced based on explicit DT compatible string. This helps with stricter checking of DT bindings.
2. Group all device-specific operations into a sja1105_info structure and avoid using the IS_ET() and IS_PQRS() macros at runtime as much as possible.
5. Miscellaneous cosmetic cleanup in sja1105_clocking.c
MAINTAINERS | 6 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 16 + drivers/net/dsa/sja1105/Makefile | 8 + drivers/net/dsa/sja1105/sja1105.h | 138 +++ drivers/net/dsa/sja1105/sja1105_clocking.c | 598 +++++++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 489 +++++++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 43 + drivers/net/dsa/sja1105/sja1105_main.c | 928 +++++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 553 ++++++++++ .../net/dsa/sja1105/sja1105_static_config.c | 949 ++++++++++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 250 +++++ include/linux/dsa/sja1105.h | 19 + 14 files changed, 4000 insertions(+) create mode 100644 drivers/net/dsa/sja1105/Kconfig create mode 100644 drivers/net/dsa/sja1105/Makefile create mode 100644 drivers/net/dsa/sja1105/sja1105.h create mode 100644 drivers/net/dsa/sja1105/sja1105_clocking.c create mode 100644 drivers/net/dsa/sja1105/sja1105_dynamic_config.c create mode 100644 drivers/net/dsa/sja1105/sja1105_dynamic_config.h create mode 100644 drivers/net/dsa/sja1105/sja1105_main.c create mode 100644 drivers/net/dsa/sja1105/sja1105_spi.c create mode 100644 drivers/net/dsa/sja1105/sja1105_static_config.c create mode 100644 drivers/net/dsa/sja1105/sja1105_static_config.h create mode 100644 include/linux/dsa/sja1105.h
MAINTAINERS +6 -0
@@ -11120,6 +11120,12 @@ S: Maintained F: Documentation/devicetree/bindings/sound/sgtl5000.txt F: sound/soc/codecs/sgtl5000* +NXP SJA1105 ETHERNET SWITCH DRIVER +M: Vladimir Oltean <[email protected]> +L: [email protected] +S: Maintained +F: drivers/net/dsa/sja1105 + NXP TDA998X DRM DRIVER M: Russell King <[email protected]> S: Maintained
drivers/net/dsa/Kconfig +2 -0
@@ -51,6 +51,8 @@ source "drivers/net/dsa/microchip/Kconfig" source "drivers/net/dsa/mv88e6xxx/Kconfig" +source "drivers/net/dsa/sja1105/Kconfig" + config NET_DSA_QCA8K tristate "Qualcomm Atheros QCA8K Ethernet switch family support" depends on NET_DSA
drivers/net/dsa/Makefile +1 -0
@@ -18,3 +18,4 @@ obj-$(CONFIG_NET_DSA_VITESSE_VSC73XX) += vitesse-vsc73xx.o obj-y += b53/ obj-y += microchip/ obj-y += mv88e6xxx/ +obj-y += sja1105/
drivers/net/dsa/sja1105/Kconfig new file +16 -0
@@ -0,0 +1,16 @@ +config NET_DSA_SJA1105 +tristate "NXP SJA1105 Ethernet switch family support" + depends on NET_DSA && SPI + select PACKING + select CRC32 + 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 and so is the + linkage to phylib. 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)
drivers/net/dsa/sja1105/Makefile new file +8 -0
@@ -0,0 +1,8 @@ +obj-$(CONFIG_NET_DSA_SJA1105) += sja1105.o + +sja1105-objs := \ + sja1105_spi.o \ + sja1105_main.o \ + sja1105_clocking.o \ + sja1105_static_config.o \ + sja1105_dynamic_config.o \
drivers/net/dsa/sja1105/sja1105.h new file +138 -0
138 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_clocking.c new file +598 -0
598 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.c new file +489 -0
489 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.h new file +43 -0
43 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c new file +928 -0
928 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_spi.c new file +553 -0
553 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.c new file +949 -0
203 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.h new file +250 -0
250 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Vladimir Oltean
maintainerPATCH v5 3/12 net: dsa: sja1105: Add support for FDB and MDB management
In reply to Vladimir OlteanCurrently only the (more difficult) first generation E/T series is supported. Here the TCAM is only 4-way associative, and to know where the hardware will search for a FDB entry, we need to perform the same hash algorithm in order to install the entry in the correct bin.
On P/Q/R/S, the TCAM should be fully associative. However the SPI command interface is different, and because I don't have access to a new-generation device at the moment, support for it is TODO.
---
Changes in v5:
Stripped blank lines at the end of files.
Changes from v4:
Added prefix to crc8_add function name, renamed "index_in_bin" into "way", got rid of #undef, turned macros into functions.
Changes from v3:
None
Changes from v2:
None
drivers/net/dsa/sja1105/sja1105.h | 2 + .../net/dsa/sja1105/sja1105_dynamic_config.c | 43 ++++ drivers/net/dsa/sja1105/sja1105_main.c | 194 ++++++++++++++++++ 3 files changed, 239 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +2 -0
@@ -123,6 +123,8 @@ int sja1105_dynamic_config_write(struct sja1105_private *priv,enum sja1105_blk_idx blk_idx, int index, void *entry, bool keep); +u8 sja1105_fdb_hash (struct sja1105_private *priv,const u8 *addr,u16 vid); +/* Common implementations for the static and dynamic configs */ size_t sja1105_l2_forwarding_entry_packing (void *buf,void *entry_ptr,enum packing_op op);
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +43 -0
46 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c +194 -0
214 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 4/12 net: dsa: sja1105: Error out if RGMII delays are requested in DT
In reply to Vladimir OlteanDocumentation/devicetree/bindings/net/ethernet.txt is confusing because it says what the MAC should not do, but not what it *should* do:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
The gap in semantics is threefold:
1. Is it illegal for the MAC to apply the Rx internal delay by itself, and simplify the phy_mode (mask off "rgmii-rxid" into "rgmii") before passing it to of_phy_connect? The documentation would suggest yes.
1. For "rgmii-rxid", while the situation with the Rx clock skew is more or less clear (needs to be added by the PHY), what should the MAC driver do about the Tx delays? Is it an implicit wild card for the MAC to apply delays in the Tx direction if it can? What if those were already added as serpentine PCB traces, how could that be made more obvious through DT bindings so that the MAC doesn't attempt to add them twice and again potentially break the link?
3. If the interface is a fixed-link and therefore the PHY object is fixed (a purely software entity that obviously cannot add clock skew), what is the meaning of the above property?
So an interpretation of the RGMII bindings was chosen that hopefully does not contradict their intention but also makes them more applied. The SJA1105 driver understands to act upon "rgmii-*id" phy-mode bindings if the port is in the PHY role (either explicitly, or if it is a fixed-link). Otherwise it always passes the duty of setting up delays to the PHY driver.
The error behavior that this patch adds is required on SJA1105E/T where the MAC really cannot apply internal delays. If the other end of the fixed-link cannot apply RGMII delays either (this would be specified through its own DT bindings), then the situation requires PCB delays.
For SJA1105P/Q/R/S, this is however hardware supported and the error is thus only temporary. I created a stub function pointer for configuring delays per-port on RXC and TXC, and will implement it when I have access to a board with this hardware setup.
Meanwhile do not allow the user to select an invalid configuration.
---
Changes in v5:
None.
Changes in v4:
Moved RGMII delay settings to an array in sja1105_private. The sja1105_port structure will be used to share info with the tagger (in a future patchset), and RGMII delays are not an example of that. Not setting to NULL function pointers that don't need to.
Changes in v3:
None.
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105.h | 3 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 5 +++- drivers/net/dsa/sja1105/sja1105_main.c | 34 ++++++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-)
drivers/net/dsa/sja1105/sja1105.h +3 -0
@@ -48,11 +48,14 @@ struct sja1105_info {const struct sja1105_table_ops *static_ops;const struct sja1105_regs *regs;int (*reset_cmd)(const void *ctx,const void *data); +int (*setup_rgmii_delay)(const void *ctx,int port);const char *name; };struct sja1105_private {struct sja1105_static_config static_config; +bool rgmii_rx_delay[SJA1105_NUM_PORTS ]; +bool rgmii_tx_delay[SJA1105_NUM_PORTS ];const struct sja1105_info *info;struct gpio_desc *reset_gpio;struct spi_device *spidev;
drivers/net/dsa/sja1105/sja1105_clocking.c +4 -1
@@ -427,7 +427,10 @@ static int sja1105_rgmii_clocking_setup(struct sja1105_private *priv, int port)dev_err (dev,"Failed to configure Tx pad registers\n" );return rc; } -return 0 ; +if (!priv->info->setup_rgmii_delay) +return 0 ; + +return priv->info->setup_rgmii_delay (priv, port); } static int sja1105_cgu_rmii_ref_clk_config(struct sja1105_private *priv,
drivers/net/dsa/sja1105/sja1105_main.c +34 -0
@@ -518,6 +518,30 @@ static int sja1105_static_config_load(struct sja1105_private *priv,return sja1105_static_config_upload (priv); } +static int sja1105_parse_rgmii_delays (struct sja1105_private *priv, +const struct sja1105_dt_port *ports) +{ +int i; + +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { +if (ports->role ==XMII_MAC ) +continue ; + +if (ports->phy_mode ==PHY_INTERFACE_MODE_RGMII_RXID || + ports->phy_mode ==PHY_INTERFACE_MODE_RGMII_ID ) + priv->rgmii_rx_delay[i] = true; + +if (ports->phy_mode ==PHY_INTERFACE_MODE_RGMII_TXID || + ports->phy_mode ==PHY_INTERFACE_MODE_RGMII_ID ) + priv->rgmii_tx_delay[i] = true; + +if ((priv->rgmii_rx_delay[i] || priv->rgmii_tx_delay[i]) && + !priv->info->setup_rgmii_delay) +return -EINVAL ; + } +return 0 ; +} +static int sja1105_parse_ports_node (struct sja1105_private *priv,struct sja1105_dt_port *ports,struct device_node *ports_node)
@@ -959,6 +983,16 @@ static int sja1105_setup(struct dsa_switch *ds)dev_err (ds->dev,"Failed to parse DT: %d\n" , rc);return rc; } + +/* Error out early if internal delays are required through DT +* and we can't apply them. +*/ + rc =sja1105_parse_rgmii_delays (priv, ports); +if (rc <0 ) { +dev_err (ds->dev,"RGMII delay not supported\n" ); +return rc; + } +/* Create and send configuration down to device */ rc =sja1105_static_config_load (priv, ports);if (rc <0 ) {
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 5/12 ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
In reply to Vladimir OlteanThere are two possible utilizations so far:
- Switch devices that don't support a native insertion/extraction header on the CPU port may still enjoy the benefits of port isolation with a custom VLAN tag.
For this, they need to have a customizable TPID in hardware and a new Ethertype to distinguish between real 802.1Q traffic and the private tags used for port separation.
- Switches that don't support the deactivation of VLAN awareness, but still want to have a mode in which they accept all traffic, including frames that are tagged with a VLAN not configured on their ports, may use this as a fake to trick the hardware into thinking that the TPID for VLAN is something other than 0x8100.
What follows after the ETH_P_DSA_8021Q EtherType is a regular VLAN header (TCI), however there is no other EtherType that can be used for this purpose and doesn't already have a well-defined meaning. ETH_P_8021AD, ETH_P_QINQ1, ETH_P_QINQ2 and ETH_P_QINQ3 expect that another follow-up VLAN tag is present, which is not the case here.
---
Changes in v5:
None.
Changes in v4:
Patch was reintroduced at Andrew's request.
Changes in v3:
Patch was removed.
Changes in v2:
Patch is new.
include/uapi/linux/if_ether.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/if_ether.h +1 -0
@@ -109,6 +109,7 @@#define ETH_P_QINQ2 0x9200/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_IFE 0xED3E/* ForCES inter-FE LFB type */ #define ETH_P_AF_IUCV 0xFBFB/* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 6/12 net: dsa: sja1105: Add support for VLAN operations
In reply to Vladimir OlteanVLAN filtering cannot be properly disabled in SJA1105. So in order to emulate the "no VLAN awareness" behavior (not dropping traffic that is tagged with a VID that isn't configured on the port), we need to hack another switch feature: programmable TPID (which is 0x8100 for 802.1Q). We are reprogramming the TPID to a bogus value which leaves the switch thinking that all traffic is untagged, and therefore accepts it.
Under a vlan_filtering bridge, the proper TPID of ETH_P_8021Q is installed again, and the switch starts identifying 802.1Q-tagged traffic.
---
Changes in v5:
None.
Changes in v4:
Changed back to ETH_P_DSA_8021Q (hidden behind the ETH_P_SJA1105 macro definition).
Simplified handling of .port_vlan_filtering due to the recent extra patches on DSA core.
Changes in v3:
Changed back to ETH_P_EDSA.
Changes in v2:
Changed the TPID from ETH_P_EDSA (0xDADA) to a newly introduced one:ETH_P_DSA_8021Q (0xDADB).
drivers/net/dsa/sja1105/sja1105_main.c | 248 +++++++++++++++++- .../net/dsa/sja1105/sja1105_static_config.c | 38 +++ .../net/dsa/sja1105/sja1105_static_config.h | 3 + include/linux/dsa/sja1105.h | 4 + 4 files changed, 291 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +246 -2
@@ -251,6 +251,13 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP ];/* The static VLAN table will only contain the initial pvid of 0. +* All other VLANs are to be configured through dynamic entries, +* and kept in the static configuration table as backing memory. +* The pvid of 0 is sufficient to pass traffic while the ports are +* standalone and when vlan_filtering is disabled. When filtering +* gets enabled, the switchdev core sets up the VLAN ID 1 and sets +* it as the new pvid. Actually 'pvid 1' still comes up in 'bridge +* vlan' even when vlan_filtering is off, but it has no effect. */ if (table->entry_count) {kfree (table->entries);
@@ -391,8 +398,11 @@ static int sja1105_init_general_params(struct sja1105_private *priv) .vlmask = 0,/* Only update correctionField for 1-step PTP (L2 transport) */ .ignore2stf = 0, - .tpid = ETH_P_8021Q, - .tpid2 = ETH_P_8021Q, +/* Forcefully disable VLAN filtering by telling +* the switch that VLAN has a different EtherType. +*/ + .tpid = ETH_P_SJA1105, + .tpid2 = ETH_P_SJA1105, };struct sja1105_table *table;int i;
@@ -954,12 +964,233 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port,sja1105_bridge_member (ds, port, br, false); } +/* For situations where we need to change a setting at runtime that is only +* available through the static configuration, resetting the switch in order +* to upload the new static config is unavoidable. Back up the settings we +* modify at runtime (currently only MAC) and restore them after uploading, +* such that this operation is relatively seamless. +*/ +static int sja1105_static_config_reload (struct sja1105_private *priv) +{ +struct sja1105_mac_config_entry *mac; +int speed_mbps[SJA1105_NUM_PORTS ]; +int rc, i; + + mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG ].entries; + +/* Back up settings changed by sja1105_adjust_port_config and +* and restore their defaults. +*/ +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { + speed_mbps[i] = sja1105_speed[mac[i].speed]; + mac[i].speed =SJA1105_SPEED_AUTO ; + } + +/* Reset switch and send updated static configuration */ + rc =sja1105_static_config_upload (priv); +if (rc <0 ) + goto out; + +/* Configure the CGU (PLLs) for MII and RMII PHYs. +* For these interfaces there is no dynamic configuration +* needed, since PLLs have same settings at all speeds. +*/ + rc =sja1105_clocking_setup (priv); +if (rc <0 ) + goto out; + +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { +bool enabled = (speed_mbps[i] !=0 ); + + rc =sja1105_adjust_port_config (priv, i, speed_mbps[i], + enabled); +if (rc <0 ) + goto out; + } +out: +return rc; +} + +/* The TPID setting belongs to the General Parameters table, +* which can only be partially reconfigured at runtime (and not the TPID). +* So a switch reset is required. +*/ +static int sja1105_change_tpid (struct sja1105_private *priv, +u16 tpid,u16 tpid2) +{ +struct sja1105_general_params_entry *general_params; +struct sja1105_table *table; + + table = &priv->static_config.tables[BLK_IDX_GENERAL_PARAMS ]; + general_params = table->entries; + general_params->tpid = tpid; + general_params->tpid2 = tpid2; +return sja1105_static_config_reload (priv); +} + +static int sja1105_pvid_apply (struct sja1105_private *priv,int port,u16 pvid) +{ +struct sja1105_mac_config_entry *mac; + + mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG ].entries; + + mac[port].vlanid = pvid; + +return sja1105_dynamic_config_write (priv,BLK_IDX_MAC_CONFIG , port, + &mac[port], true); +} + +static int sja1105_is_vlan_configured (struct sja1105_private *priv,u16 vid) +{ +struct sja1105_vlan_lookup_entry *vlan; +int count, i; + + vlan = priv->static_config.tables[BLK_IDX_VLAN_LOOKUP ].entries; + count = priv->static_config.tables[BLK_IDX_VLAN_LOOKUP ].entry_count; + +for (i =0 ; i < count; i++) +if (vlan[i].vlanid == vid) +return i; + +/* Return an invalid entry index if not found */ +return -1 ; +} + +static int sja1105_vlan_apply (struct sja1105_private *priv,int port,u16 vid, +bool enabled,bool untagged) +{ +struct sja1105_vlan_lookup_entry *vlan; +struct sja1105_table *table; +bool keep = true; +int match, rc; + + table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP ]; + + match =sja1105_is_vlan_configured (priv, vid); +if (match <0 ) { +/* Can't delete a missing entry. */ +if (!enabled) +return 0 ; + rc =sja1105_table_resize (table, table->entry_count +1 ); +if (rc) +return rc; + match = table->entry_count -1 ; + } +/* Assign pointer after the resize (it's new memory) */ + vlan = table->entries; + vlan[match].vlanid = vid; +if (enabled) { + vlan[match].vlan_bc |=BIT (port); + vlan[match].vmemb_port |=BIT (port); + }else { + vlan[match].vlan_bc &= ~BIT (port); + vlan[match].vmemb_port &= ~BIT (port); + } +/* Also unset tag_port if removing this VLAN was requested, +* just so we don't have a confusing bitmap (no practical purpose). +*/ +if (untagged || !enabled) + vlan[match].tag_port &= ~BIT (port); +else + vlan[match].tag_port |=BIT (port); +/* If there's no port left as member of this VLAN, +* it's time for it to go. +*/ +if (!vlan[match].vmemb_port) + keep = false; + +dev_dbg (priv->ds->dev, +"%s: port %d, vid %llu, broadcast domain 0x%llx, " +"port members 0x%llx, tagged ports 0x%llx, keep %d\n" , + __func__, port, vlan[match].vlanid, vlan[match].vlan_bc, + vlan[match].vmemb_port, vlan[match].tag_port, keep); + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_VLAN_LOOKUP , vid, + &vlan[match], keep); +if (rc <0 ) +return rc; + +if (!keep) +return sja1105_table_delete_entry (table, match); + +return 0 ; +} +static enum dsa_tag_protocol sja1105_get_tag_protocol (struct dsa_switch *ds,int port) {return DSA_TAG_PROTO_NONE ; } +/* This callback needs to be present */ +static int sja1105_vlan_prepare (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +return 0 ; +} + +static int sja1105_vlan_filtering (struct dsa_switch *ds,int port,bool enabled) +{ +struct sja1105_private *priv = ds->priv; +int rc; + +if (enabled) +/* Enable VLAN filtering. */ + rc =sja1105_change_tpid (priv,ETH_P_8021Q ,ETH_P_8021AD ); +else +/* Disable VLAN filtering. */ + rc =sja1105_change_tpid (priv,ETH_P_SJA1105 ,ETH_P_SJA1105 ); +if (rc) +dev_err (ds->dev,"Failed to change VLAN Ethertype\n" ); + +return rc; +} + +static void sja1105_vlan_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct sja1105_private *priv = ds->priv; +u16 vid; +int rc; + +for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + rc =sja1105_vlan_apply (priv, port, vid, true, vlan->flags & +BRIDGE_VLAN_INFO_UNTAGGED ); +if (rc <0 ) { +dev_err (ds->dev,"Failed to add VLAN %d to port %d: %d\n" , + vid, port, rc); +return ; + } +if (vlan->flags &BRIDGE_VLAN_INFO_PVID ) { + rc =sja1105_pvid_apply (ds->priv, port, vid); +if (rc <0 ) { +dev_err (ds->dev,"Failed to set pvid %d on port %d: %d\n" , + vid, port, rc); +return ; + } + } + } +} + +static int sja1105_vlan_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct sja1105_private *priv = ds->priv; +u16 vid; +int rc; + +for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + rc =sja1105_vlan_apply (priv, port, vid, false, vlan->flags & +BRIDGE_VLAN_INFO_UNTAGGED ); +if (rc <0 ) { +dev_err (ds->dev,"Failed to remove VLAN %d from port %d: %d\n" , + vid, port, rc); +return rc; + } + } +return 0 ; +} +/* The programming model for the SJA1105 switch is "all-at-once" via static * configuration tables. Some of these can be dynamically modified at runtime, * but not the xMII mode parameters table.
@@ -1005,6 +1236,15 @@ static int sja1105_setup(struct dsa_switch *ds)dev_err (ds->dev,"Failed to configure MII clocking: %d\n" , rc);return rc; } +/* On SJA1105, VLAN filtering per se is always enabled in hardware. +* The only thing we can do to disable it is lie about what the 802.1Q +* EtherType is. +* So it will still try to apply VLAN filtering, but all ingress +* traffic (except frames received with EtherType of ETH_P_SJA1105) +* will be internally tagged with a distorted VLAN header where the +* TPID is ETH_P_SJA1105, and the VLAN ID is the port pvid. +*/ + ds->vlan_filtering_is_global = true;return 0 ; }
@@ -1018,6 +1258,10 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .port_fdb_del = sja1105_fdb_del, .port_bridge_join = sja1105_bridge_join, .port_bridge_leave = sja1105_bridge_leave, + .port_vlan_prepare = sja1105_vlan_prepare, + .port_vlan_filtering = sja1105_vlan_filtering, + .port_vlan_add = sja1105_vlan_add, + .port_vlan_del = sja1105_vlan_del, .port_mdb_prepare = sja1105_mdb_prepare, .port_mdb_add = sja1105_mdb_add, .port_mdb_del = sja1105_mdb_del,
drivers/net/dsa/sja1105/sja1105_static_config.c +38 -0
@@ -947,3 +947,41 @@ void sja1105_static_config_free(struct sja1105_static_config *config) } } } + +int sja1105_table_delete_entry (struct sja1105_table *table,int i) +{ +size_t entry_size = table->ops->unpacked_entry_size; +u8 *entries = table->entries; + +if (i > table->entry_count) +return -ERANGE ; + +memmove (entries + i * entry_size, entries + (i +1 ) * entry_size, + (table->entry_count - i) * entry_size); + + table->entry_count--; + +return 0 ; +} + +/* No pointers to table->entries should be kept when this is called. */ +int sja1105_table_resize (struct sja1105_table *table,size_t new_count) +{ +size_t entry_size = table->ops->unpacked_entry_size; +void *new_entries, *old_entries = table->entries; + +if (new_count > table->ops->max_entry_count) +return -ERANGE ; + + new_entries =kcalloc (new_count, entry_size,GFP_KERNEL ); +if (!new_entries) +return -ENOMEM ; + +memcpy (new_entries, old_entries,min (new_count, table->entry_count) * + entry_size); + + table->entries = new_entries; + table->entry_count = new_count; +kfree (old_entries); +return 0 ; +}
drivers/net/dsa/sja1105/sja1105_static_config.h +3 -0
@@ -240,6 +240,9 @@ int sja1105_static_config_init(struct sja1105_static_config *config, u64 device_id);void sja1105_static_config_free (struct sja1105_static_config *config); +int sja1105_table_delete_entry (struct sja1105_table *table,int i); +int sja1105_table_resize (struct sja1105_table *table,size_t new_count); +u32 sja1105_crc32 (const void *buf,size_t len);void sja1105_pack (void *buf,const u64 *val,int start,int end,size_t len);
include/linux/dsa/sja1105.h +4 -0
@@ -7,6 +7,10 @@#ifndef _NET_DSA_SJA1105_H#define _NET_DSA_SJA1105_H +#include <linux/etherdevice.h> + +#define ETH_P_SJA1105 ETH_P_DSA_8021Q +/* The switch can only be convinced to stay in unmanaged mode and not trap any * link-local traffic by actually telling it to filter frames sent at the * 00:00:00:00:00:00 destination MAC.
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 7/12 net: dsa: sja1105: Add support for ethtool port counters
In reply to Vladimir Oltean---
Changes in v5:
Stripped blank lines at the end of files.
Changes in v4:
Replaced IS_ET and IS_PQRS macros with explicit device_id checking. Added SJA1105 prefix to macro names.
Changes in v3:
None.
Changes in v2:
None functional. Moved the IS_ET() and IS_PQRS() device identification macros here since they are not used in earlier patches.
drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 7 +- drivers/net/dsa/sja1105/sja1105_ethtool.c | 417 ++++++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_main.c | 3 + 4 files changed, 427 insertions(+), 1 deletion(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_ethtool.c
drivers/net/dsa/sja1105/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_NET_DSA_SJA1105) += sja1105.o sja1105-objs := \ sja1105_spi.o \ sja1105_main.o \ + sja1105_ethtool.o \ sja1105_clocking.o \ sja1105_static_config.o \ sja1105_dynamic_config.o \
drivers/net/dsa/sja1105/sja1105.h +6 -1
@@ -117,8 +117,13 @@ typedef enum {int sja1105_clocking_setup_port (struct sja1105_private *priv,int port);int sja1105_clocking_setup (struct sja1105_private *priv); -/* From sja1105_dynamic_config.c */ +/* From sja1105_ethtool.c */ +void sja1105_get_ethtool_stats (struct dsa_switch *ds,int port,u64 *data); +void sja1105_get_strings (struct dsa_switch *ds,int port, +u32 stringset,u8 *data); +int sja1105_get_sset_count (struct dsa_switch *ds,int port,int sset); +/* From sja1105_dynamic_config.c */ int sja1105_dynamic_config_read (struct sja1105_private *priv,enum sja1105_blk_idx blk_idx,int index,void *entry);
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +417 -0
417 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c +3 -0
@@ -1253,6 +1253,9 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .get_tag_protocol = sja1105_get_tag_protocol, .setup = sja1105_setup, .adjust_link = sja1105_adjust_link, + .get_strings = sja1105_get_strings, + .get_ethtool_stats = sja1105_get_ethtool_stats, + .get_sset_count = sja1105_get_sset_count, .port_fdb_dump = sja1105_fdb_dump, .port_fdb_add = sja1105_fdb_add, .port_fdb_del = sja1105_fdb_del,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 8/12 net: dsa: sja1105: Add support for configuring address ageing time
In reply to Vladimir OlteanIf STP is active, this setting is applied on bridged ports each time an Ethernet link is established (topology changes).
Since the setting is global to the switch and a reset is required to change it, resets are prevented if the new callback does not change the value that the hardware already is programmed for.
---
Changes in v5:
Changed "aging" to "ageing" in commit message to be consistent with the code.
Changes in v4:
Patch is new.
drivers/net/dsa/sja1105/sja1105.h | 4 ++++ drivers/net/dsa/sja1105/sja1105_main.c | 29 ++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +4 -0
@@ -12,6 +12,10 @@#define SJA1105_NUM_PORTS 5#define SJA1105_NUM_TC 8#define SJA1105ET_FDB_BIN_SIZE 4 +/* The hardware value is in multiples of 10 ms. +* The passed parameter is in multiples of 1 ms. +*/ +#define SJA1105_AGEING_TIME_MS (ms) ((ms) / 10)/* Keeps the different addresses between E/T and P/Q/R/S */ struct sja1105_regs {
drivers/net/dsa/sja1105/sja1105_main.c +27 -2
@@ -193,8 +193,8 @@ static int sja1105_init_l2_lookup_params(struct sja1105_private *priv) {struct sja1105_table *table;struct sja1105_l2_lookup_params_entry default_l2_lookup_params = { -/* TODO Learned FDB entries are never forgotten */ - .maxage =0 , +/* Learned FDB entries are forgotten after 300 seconds */ + .maxage =SJA1105_AGEING_TIME_MS (300000 ),/* All entries within a FDB bin are available for learning */ .dyn_tbsz =SJA1105ET_FDB_BIN_SIZE ,/* 2^8 + 2^5 + 2^3 + 2^2 + 2^1 + 1 in Koopman notation */
@@ -1249,10 +1249,35 @@ static int sja1105_setup(struct dsa_switch *ds)return 0 ; } +/* The MAXAGE setting belongs to the L2 Forwarding Parameters table, +* which cannot be reconfigured at runtime. So a switch reset is required. +*/ +static int sja1105_set_ageing_time (struct dsa_switch *ds, +unsigned int ageing_time) +{ +struct sja1105_l2_lookup_params_entry *l2_lookup_params; +struct sja1105_private *priv = ds->priv; +struct sja1105_table *table; +unsigned int maxage; + + table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP_PARAMS ]; + l2_lookup_params = table->entries; + + maxage =SJA1105_AGEING_TIME_MS (ageing_time); + +if (l2_lookup_params->maxage == maxage) +return 0 ; + + l2_lookup_params->maxage = maxage; + +return sja1105_static_config_reload (priv); +} +static const struct dsa_switch_ops sja1105_switch_ops = { .get_tag_protocol = sja1105_get_tag_protocol, .setup = sja1105_setup, .adjust_link = sja1105_adjust_link, + .set_ageing_time = sja1105_set_ageing_time, .get_strings = sja1105_get_strings, .get_ethtool_stats = sja1105_get_ethtool_stats, .get_sset_count = sja1105_get_sset_count,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 9/12 net: dsa: sja1105: Prevent PHY jabbering during switch reset
In reply to Vladimir OlteanResetting the switch at runtime is currently done while changing the vlan_filtering setting (due to the required TPID change).
But reset is asynchronous with packet egress, and the switch core will not wait for egress to finish before carrying on with the reset operation.
As a result, a connected PHY such as the BCM5464 would see an unterminated Ethernet frame and start to jabber (repeat the last seen Ethernet symbols - jabber is by definition an oversized Ethernet frame with bad FCS). This behavior is strange in itself, but it also causes the MACs of some link partners (such as the FRDM-LS1012A) to completely lock up.
So as a remedy for this situation, when switch reset is required, simply inhibit Tx on all ports, and wait for the necessary time for the eventual one frame left in the egress queue (not even the Tx inhibit command is instantaneous) to be flushed.
---
Changes in v5:
None.
Changes in v4:
Changed SIZE_PORT_CTRL to SJA1105_SIZE_PORT_CTRL.
Changes in v3:
None.
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105.h | 1 + drivers/net/dsa/sja1105/sja1105_spi.c | 37 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +1 -0
@@ -22,6 +22,7 @@ struct sja1105_regs {u64 device_id;u64 prod_id;u64 status; +u64 port_control;u64 rgu;u64 config;u64 rmii_pll1;
drivers/net/dsa/sja1105/sja1105_spi.c +37 -0
@@ -7,6 +7,7 @@#include <linux/packing.h> #include "sja1105.h" +#define SJA1105_SIZE_PORT_CTRL 4#define SJA1105_SIZE_RESET_CMD 4#define SJA1105_SIZE_SPI_MSG_HEADER 4#define SJA1105_SIZE_SPI_MSG_MAXLEN (64 * 4)
@@ -282,6 +283,25 @@ static int sja1105_cold_reset(const struct sja1105_private *priv)return priv->info->reset_cmd (priv, &reset); } +static int sja1105_inhibit_tx (const struct sja1105_private *priv, +const unsigned long *port_bitmap) +{ +const struct sja1105_regs *regs = priv->info->regs; +u64 inhibit_cmd; +int port, rc; + + rc =sja1105_spi_send_int (priv,SPI_READ , regs->port_control, + &inhibit_cmd,SJA1105_SIZE_PORT_CTRL ); +if (rc <0 ) +return rc; + +for_each_set_bit (port, port_bitmap,SJA1105_NUM_PORTS ) + inhibit_cmd |=BIT (port); + +return sja1105_spi_send_int (priv,SPI_WRITE , regs->port_control, + &inhibit_cmd,SJA1105_SIZE_PORT_CTRL ); +} +struct sja1105_status {u64 configs;u64 crcchkl;
@@ -370,6 +390,7 @@ static_config_buf_prepare_for_upload(struct sja1105_private *priv,int sja1105_static_config_upload (struct sja1105_private *priv) { +unsigned long port_bitmap =GENMASK_ULL (SJA1105_NUM_PORTS -1 ,0 );struct sja1105_static_config *config = &priv->static_config;const struct sja1105_regs *regs = priv->info->regs;struct device *dev = &priv->spidev->dev;
@@ -388,6 +409,20 @@ int sja1105_static_config_upload(struct sja1105_private *priv)dev_err (dev,"Invalid config, cannot upload\n" );return -EINVAL ; } +/* Prevent PHY jabbering during switch reset by inhibiting +* Tx on all ports and waiting for current packet to drain. +* Otherwise, the PHY will see an unterminated Ethernet packet. +*/ + rc =sja1105_inhibit_tx (priv, &port_bitmap); +if (rc <0 ) { +dev_err (dev,"Failed to inhibit Tx on ports\n" ); +return -ENXIO ; + } +/* Wait for an eventual egress packet to finish transmission +* (reach IFG). It is guaranteed that a second one will not +* follow, and that switch cold reset is thus safe +*/ +usleep_range (500 ,1000 ); do { /* Put the SJA1105 in programming mode */ rc = sja1105_cold_reset(priv);
@@ -452,6 +487,7 @@ struct sja1105_regs sja1105et_regs = { .device_id = 0x0, .prod_id = 0x100BC3, .status = 0x1, + .port_control = 0x11, .config = 0x020000, .rgu = 0x100440, .pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808},
@@ -476,6 +512,7 @@ struct sja1105_regs sja1105pqrs_regs = { .device_id = 0x0, .prod_id = 0x100BC3, .status = 0x1, + .port_control = 0x12, .config = 0x020000, .rgu = 0x100440, .pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808},
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 10/12 net: dsa: sja1105: Reject unsupported link modes for AN
In reply to Vladimir OlteanEthernet flow control:
The switch MAC does not consume, nor does it emit pause frames. It simply forwards them as any other Ethernet frame (and since the DMAC is, per IEEE spec, 01-80-C2-00-00-01, it means they are filtered as link-local traffic and forwarded to the CPU, which can't do anything useful with them).
Duplex:
There is no duplex setting in the SJA1105 MAC. It is known to forward traffic at line rate on the same port in both directions. Therefore it must be that it only supports full duplex.
---
Changes in v5:
None.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105_main.c | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +31 -0
@@ -11,6 +11,7 @@#include <linux/spi/spi.h> #include <linux/errno.h> #include <linux/gpio/consumer.h> +#include <linux/phylink.h> #include <linux/of.h> #include <linux/of_net.h> #include <linux/of_mdio.h>
@@ -726,6 +727,35 @@ static void sja1105_adjust_link(struct dsa_switch *ds, int port,sja1105_adjust_port_config (priv, port, phydev->speed, true); } +static void sja1105_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +/* Construct a new mask which exhaustively contains all link features +* supported by the MAC, and then apply that (logical AND) to what will +* be sent to the PHY for "marketing". +*/ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; +struct sja1105_private *priv = ds->priv; +struct sja1105_xmii_params_entry *mii; + + mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS ].entries; + +/* The MAC does not support pause frames, and also doesn't +* support half-duplex traffic modes. +*/ +phylink_set (mask, Autoneg); +phylink_set (mask,MII ); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Full); +if (mii->xmii_mode[port] ==XMII_MODE_RGMII ) + phylink_set(mask, 1000baseT_Full); + +bitmap_and (supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS); +bitmap_and (state->advertising, state->advertising, mask, + __ETHTOOL_LINK_MODE_MASK_NBITS); +} +/* First-generation switches have a 4-way set associative TCAM that * holds the FDB entries. An FDB index spans from 0 to 1023 and is comprised of * a "bin" (grouping of 4 entries) and a "way" (an entry within a bin).
@@ -1278,6 +1308,7 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .setup = sja1105_setup, .adjust_link = sja1105_adjust_link, .set_ageing_time = sja1105_set_ageing_time, + .phylink_validate = sja1105_phylink_validate, .get_strings = sja1105_get_strings, .get_ethtool_stats = sja1105_get_ethtool_stats, .get_sset_count = sja1105_get_sset_count,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 11/12 Documentation: net: dsa: Add details about NXP SJA1105 driver
In reply to Vladimir Oltean---
Changes in v5:
Stripped blank lines at the end of files.
Changes in v4:
Removed the section about traffic, as well as mentions of other unsupported yet features.
Changes in v3:
Reworked as rst, added a table for traffic support, added chapter for switching features.
Changes in v2:
More verbiage at the end, regarding RGMII delays and potentially other hardware-related caveats.
Documentation/networking/dsa/index.rst | 1 + Documentation/networking/dsa/sja1105.rst | 166 +++++++++++++++++++++++ 2 files changed, 167 insertions(+) create mode 100644 Documentation/networking/dsa/sja1105.rst
Documentation/networking/dsa/index.rst +1 -0
@@ -8,3 +8,4 @@ Distributed Switch Architecture dsa bcm_sf2 lan9303 + sja1105
Documentation/networking/dsa/sja1105.rst new file +166 -0
166 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v5 12/12 dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
In reply to Vladimir Oltean---
Changes in v5:
Stripped blank lines at the end of files.
Changes in v4:
None.
Changes in v3:
None.
Changes in v2:
Renamed sja1105,phy-mode to sja1105,role-phy and similarly for mac. Clarified the switch situation with RGMII delays.
.../devicetree/bindings/net/dsa/sja1105.txt | 156 ++++++++++++++++++ 1 file changed, 156 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt
Documentation/devicetree/bindings/net/dsa/sja1105.txt new file +156 -0
@@ -0,0 +1,156 @@ +NXP SJA1105 switch driver +========================= + +Required properties: + +- compatible: + Must be one of: + - "nxp,sja1105e" + - "nxp,sja1105t" + - "nxp,sja1105p" + - "nxp,sja1105q" + - "nxp,sja1105r" + - "nxp,sja1105s" + + Although the device ID could be detected at runtime, explicit bindings + are required in order to be able to statically check their validity. + For example, SGMII can only be specified on port 4 of R and S devices, + and the non-SGMII devices, while pin-compatible, are not equal in terms + of support for RGMII internal delays (supported on P/Q/R/S, but not on + E/T). + +Optional properties: + +- sja1105,role-mac: +- sja1105,role-phy: + Boolean properties that can be assigned under each port node. By + default (unless otherwise specified) a port is configured as MAC if it + is driving a PHY (phy-handle is present) or as PHY if it is PHY-less + (fixed-link specified, presumably because it is connected to a MAC). + The effect of this property (in either its implicit or explicit form) + is: + - In the case of MII or RMII it specifies whether the SJA1105 port is a + clock source or sink for this interface (not applicable for RGMII + where there is a Tx and an Rx clock). + - In the case of RGMII it affects the behavior regarding internal + delays: + 1. If sja1105,role-mac is specified, and the phy-mode property is one + of "rgmii-id", "rgmii-txid" or "rgmii-rxid", then the entity + designated to apply the delay/clock skew necessary for RGMII + is the PHY. The SJA1105 MAC does not apply any internal delays. + 2. If sja1105,role-phy is specified, and the phy-mode property is one + of the above, the designated entity to apply the internal delays + is the SJA1105 MAC (if hardware-supported). This is only supported + by the second-generation (P/Q/R/S) hardware. On a first-generation + E or T device, it is an error to specify an RGMII phy-mode other + than "rgmii" for a port that is in fixed-link mode. In that case, + the clock skew must either be added by the MAC at the other end of + the fixed-link, or by PCB serpentine traces on the board. + These properties are required, for example, in the case where SJA1105 + ports are at both ends of a MII/RMII PHY-less setup. One end would need + to have sja1105,role-mac, while the other sja1105,role-phy. + +See Documentation/devicetree/bindings/net/dsa/dsa.txt for the list of standard +DSA required and optional properties. + +Other observations +------------------ + +The SJA1105 SPI interface requires a CS-to-CLK time (t2 in UM10944) of at least +one half of t_CLK. At an SPI frequency of 1MHz, this means a minimum +cs_sck_delay of 500ns. Ensuring that this SPI timing requirement is observed +depends on the SPI bus master driver. + +Example +------- + +Ethernet switch connected via SPI to the host, CPU port wired to enet2: + +arch/arm/boot/dts/ls1021a-tsn.dts: + +/* SPI controller of the LS1021 */ +&dspi0 { + sja1105@1 { + reg = <0x1>; + #address-cells = <1>; + #size-cells = <0>; + compatible = "nxp,sja1105t"; + spi-max-frequency = <4000000>; + fsl,spi-cs-sck-delay = <1000>; + fsl,spi-sck-cs-delay = <1000>; + ports { + #address-cells = <1>; + #size-cells = <0>; + port@0 { + /* ETH5 written on chassis */ + label = "swp5"; + phy-handle = <&rgmii_phy6>; + phy-mode = "rgmii-id"; + reg = <0>; + /* Implicit "sja1105,role-mac;" */ + }; + port@1 { + /* ETH2 written on chassis */ + label = "swp2"; + phy-handle = <&rgmii_phy3>; + phy-mode = "rgmii-id"; + reg = <1>; + /* Implicit "sja1105,role-mac;" */ + }; + port@2 { + /* ETH3 written on chassis */ + label = "swp3"; + phy-handle = <&rgmii_phy4>; + phy-mode = "rgmii-id"; + reg = <2>; + /* Implicit "sja1105,role-mac;" */ + }; + port@3 { + /* ETH4 written on chassis */ + phy-handle = <&rgmii_phy5>; + label = "swp4"; + phy-mode = "rgmii-id"; + reg = <3>; + /* Implicit "sja1105,role-mac;" */ + }; + port@4 { + /* Internal port connected to eth2 */ + ethernet = <&enet2>; + phy-mode = "rgmii"; + reg = <4>; + /* Implicit "sja1105,role-phy;" */ + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; + }; +}; + +/* MDIO controller of the LS1021 */ +&mdio0 { + /* BCM5464 */ + 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>; + }; +}; + +/* Ethernet master port of the LS1021 */ +&enet2 { + phy-connection-type = "rgmii"; + status = "ok"; + fixed-link { + speed = <1000>; + full-duplex; + }; +};
Signature · 1 line
2.17.1
David Miller
maintainerFrom: Vladimir Oltean <[email protected]>
Date: Thu, 2 May 2019 23:23:28 +0300
Quoted 2 lines
This patchset adds a DSA driver for the SPI-controlled NXP SJA1105 switch.
Series applied, thank you.
Vladimir Oltean
maintainerQuoted 9 lines · David Miller
From: Vladimir Oltean <[email protected]>
Date: Thu, 2 May 2019 23:23:28 +0300Quoted 2 lines
This patchset adds a DSA driver for the SPI-controlled NXP SJA1105 switch.
Series applied, thank you.
Thank you!
-Vladimir