NXP SJA1105 DSA driver
Subsystems (8)
Vladimir Oltean
maintainercover NXP SJA1105 DSA driver
This patchset adds a DSA driver for the SPI-managed NXP SJA1105 driver. 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.
Then several small modifications are done to the DSA core, like changing the order of two calls during initialization, or permitting driver access to the dp->vlan_filtering property.
These small modifications are done for the greater goal of adding support for 802.1Q pseudo-switch tagging. The limitations of this type of tagging are discussed in the commit that adds it, and in the code comments.
The SJA1105 driver then proceeds to extend this 8021q switch tagging protocol while adding its own (tag_sja1105). This is done because SJA1105 needs SPI intervention during transmission of link-local traffic, which cannot be done from the xmit handler but requires a deferred worker thread.
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 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 what the current state of tc-taprio hw offload is, and attempt to configure the switch's time-aware scheduler using that.
Vladimir Oltean (13):
lib: Add support for generic packing operations
net: dsa: Store vlan_filtering as a property of dsa_port
net: dsa: Create a more convenient function for installing port VLANs
net: dsa: Call driver's setup callback after setting up its switchdev
notifier
net: dsa: Optional VLAN-based port separation for switches without
tagging
net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
net: dsa: sja1105: Add support for FDB and MDB management
net: dsa: sja1105: Add support for VLAN operations
net: dsa: sja1105: Add support for ethtool port counters
net: dsa: sja1105: Add support for traffic through standalone ports
net: dsa: sja1105: Add support for Spanning Tree Protocol
Documentation: networking: dsa: Add details about NXP SJA1105 driver
dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
.../devicetree/bindings/net/dsa/sja1105.txt | 123 ++ Documentation/networking/dsa/sja1105.txt | 83 + Documentation/packing.txt | 150 ++ MAINTAINERS | 14 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 17 + drivers/net/dsa/sja1105/Makefile | 10 + drivers/net/dsa/sja1105/sja1105.h | 148 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 677 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 607 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 40 + drivers/net/dsa/sja1105/sja1105_ethtool.c | 420 ++++ drivers/net/dsa/sja1105/sja1105_main.c | 1580 ++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 667 ++++++ .../net/dsa/sja1105/sja1105_static_config.c | 1810 +++++++++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 500 +++++ include/linux/dsa/sja1105.h | 52 + include/linux/packing.h | 49 + include/net/dsa.h | 6 + lib/Makefile | 2 +- lib/packing.c | 211 ++ net/dsa/Kconfig | 12 + net/dsa/Makefile | 2 + net/dsa/dsa.c | 6 + net/dsa/dsa2.c | 8 +- net/dsa/dsa_priv.h | 15 + net/dsa/port.c | 36 +- net/dsa/slave.c | 16 +- net/dsa/tag_8021q.c | 185 ++ net/dsa/tag_sja1105.c | 142 ++ 31 files changed, 7568 insertions(+), 23 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt create mode 100644 Documentation/networking/dsa/sja1105.txt 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 create mode 100644 net/dsa/tag_8021q.c create mode 100644 net/dsa/tag_sja1105.c
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRFC PATCH 1/13 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'.
--- Documentation/packing.txt | 150 +++++++++++++++++++++++++++ MAINTAINERS | 8 ++ include/linux/packing.h | 49 +++++++++ lib/Makefile | 2 +- lib/packing.c | 211 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 419 insertions(+), 1 deletion(-) create mode 100644 Documentation/packing.txt create mode 100644 include/linux/packing.h create mode 100644 lib/packing.c
Documentation/packing.txt new file +150 -0
@@ -0,0 +1,150 @@ +============================================= +Generic field 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 bit fields). 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
@@ -11670,6 +11670,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/Makefile +1 -1
@@ -37,7 +37,7 @@ obj-y += bcd.o div64.o sort.o parser.o debug_locks.o random32.o \ bust_spinlocks.o kasprintf.o bitmap.o scatterlist.o \ gcd.o lcm.o list_sort.o uuid.o iov_iter.o clz_ctz.o \ bsearch.o find_bit.o llist.o memweight.o kfifo.o \ - percpu-refcount.o rhashtable.o reciprocal_div.o \ + packing.o percpu-refcount.o rhashtable.o reciprocal_div.o \ once.o refcount.o usercopy.o errseq.o bucket_locks.o \ generic-radix-tree.o obj-$(CONFIG_STRING_SELFTEST) += test_string.o
lib/packing.c new file +211 -0
211 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 01/13] lib: Add support for generic packing operations
Quoted 6 lines · Vladimir Oltean
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'.
Quoted 7 lines
Signed-off-by Vladimir Oltean <[email protected]>--- Documentation/packing.txt | 150 +++++++++++++++++++++++++++ MAINTAINERS | 8 ++ include/linux/packing.h | 49 +++++++++ lib/Makefile | 2 +- lib/packing.c | 211 ++++++++++++++++++++++++++++++++++++++
For this kind of generic infrastructure, you really should CC the lkml to get proper review.
Thanks,
Richard
Vladimir Oltean
maintainerRe: [RFC PATCH net-next 01/13] lib: Add support for generic packing operations
Quoted 15 lines · Richard Cochran
Quoted 6 lines · Vladimir Oltean
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'.
Quoted 7 lines
Signed-off-by Vladimir Oltean <[email protected]>--- Documentation/packing.txt | 150 +++++++++++++++++++++++++++ MAINTAINERS | 8 ++ include/linux/packing.h | 49 +++++++++ lib/Makefile | 2 +- lib/packing.c | 211 ++++++++++++++++++++++++++++++++++++++
Quoted 6 lines
For this kind of generic infrastructure, you really should CC the lkml to get proper review.
Thanks,
Richard
Hi Richard,
I didn't want to pollute LKML with the entire driver patchset from the get-go, just receive some initial feedback from netdev first (hence the RFC). How should I proceed? Should I resend just this patch to LKML, or a v2 patchset with LKML copied on the lib patch?
Thanks,
-Vladimir
Re: [RFC PATCH net-next 01/13] lib: Add support for generic packing operations
Quoted 5 lines · Vladimir Oltean
I didn't want to pollute LKML with the entire driver patchset from the get-go, just receive some initial feedback from netdev first (hence the RFC).
How should I proceed? Should I resend just this patch to LKML, or a v2 patchset with LKML copied on the lib patch?
I would send the entire series, so that the context is clear.
(There is no danger of polluting lkml ;^)
Thanks,
Richard
Vladimir Oltean
maintainerRFC PATCH 2/13 net: dsa: Store vlan_filtering as a property of dsa_port
In reply to Vladimir OlteanThis allows drivers to query the VLAN setting imposed by the bridge driver directly from DSA, instead of keeping their own state based on the .port_vlan_filtering callback.
--- include/net/dsa.h | 1 + net/dsa/port.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 4 deletions(-)
include/net/dsa.h +1 -0
@@ -142,6 +142,7 @@ struct dsa_port {const struct dsa_port *cpu_dp;struct device_node *dn;unsigned int ageing_time; +bool vlan_filtering;u8 stp_state;struct net_device *bridge_dev;struct devlink_port devlink_port;
net/dsa/port.c +8 -4
@@ -158,15 +158,19 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering, struct switchdev_trans *trans) {struct dsa_switch *ds = dp->ds; +int err;/* bridge skips -EOPNOTSUPP, so skip the prepare phase */ if (switchdev_trans_ph_prepare (trans))return 0 ; -if (ds->ops->port_vlan_filtering) -return ds->ops->port_vlan_filtering (ds, dp->index, - vlan_filtering); - +if (ds->ops->port_vlan_filtering) { + err = ds->ops->port_vlan_filtering (ds, dp->index, + vlan_filtering); +if (err) +return err; + dp->vlan_filtering = vlan_filtering; + }return 0 ; }
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [RFC PATCH net-next 02/13] net: dsa: Store vlan_filtering as a property of dsa_port
Quoted 3 lines · Vladimir Oltean
This allows drivers to query the VLAN setting imposed by the bridge driver directly from DSA, instead of keeping their own state based on the .port_vlan_filtering callback.
Hi Vladimir
It would be good to modify the mt7530 driver to make use of this new member.
Andrew
Re: [RFC PATCH net-next 02/13] net: dsa: Store vlan_filtering as a property of dsa_port
In reply to Vladimir OlteanQuoted 5 lines · Vladimir Oltean
This allows drivers to query the VLAN setting imposed by the bridge driver directly from DSA, instead of keeping their own state based on the .port_vlan_filtering callback.
Signed-off-by Vladimir Oltean <[email protected]>
After you address Andrew's comment:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 3/13 net: dsa: Create a more convenient function for installing port VLANs
In reply to Vladimir OlteanThis refactors the two-phase transaction from dsa_slave_vlan_rx_add_vid and also makes that code available for other functions from within DSA. The newly exposed function either adds or deletes the specified VLAN entry based on a boolean argument.
--- net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 24 ++++++++++++++++++++++++ net/dsa/slave.c | 16 ++-------------- 3 files changed, 28 insertions(+), 14 deletions(-)
net/dsa/dsa_priv.h +2 -0
@@ -164,6 +164,8 @@ int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, struct switchdev_trans *trans);int dsa_port_bridge_flags (const struct dsa_port *dp,unsigned long flags,struct switchdev_trans *trans); +int dsa_port_trans_vlan_apply (struct dsa_port *dp,u16 vid,u16 flags, +bool enabled);int dsa_port_vlan_add (struct dsa_port *dp,const struct switchdev_obj_port_vlan *vlan,struct switchdev_trans *trans);
net/dsa/port.c +24 -0
@@ -326,6 +326,30 @@ int dsa_port_vlan_del(struct dsa_port *dp,return 0 ; } +int dsa_port_trans_vlan_apply (struct dsa_port *dp,u16 vid,u16 flags, +bool enabled) +{ +struct switchdev_obj_port_vlan vlan = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .flags = flags, + .vid_begin = vid, + .vid_end = vid, + }; +struct switchdev_trans trans; +int err; + +if (!enabled) +return dsa_port_vlan_del (dp, &vlan); + + trans.ph_prepare = true; + err =dsa_port_vlan_add (dp, &vlan, &trans); +if (err == -EOPNOTSUPP ) +return 0 ; + + trans.ph_prepare = false; +return dsa_port_vlan_add (dp, &vlan, &trans); +} +static struct phy_device *dsa_port_get_phy_device (struct dsa_port *dp) {struct device_node *phy_dn;
net/dsa/slave.c +2 -14
@@ -987,13 +987,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid) {struct dsa_port *dp =dsa_slave_to_port (dev); -struct switchdev_obj_port_vlan vlan = { - .vid_begin = vid, - .vid_end = vid, -/* This API only allows programming tagged, non-PVID VIDs */ - .flags =0 , - }; -struct switchdev_trans trans;struct bridge_vlan_info info;int ret;
@@ -1010,13 +1003,8 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,return -EBUSY ; } - trans.ph_prepare = true; - ret =dsa_port_vlan_add (dp, &vlan, &trans); -if (ret == -EOPNOTSUPP ) -return 0 ; - - trans.ph_prepare = false; -return dsa_port_vlan_add (dp, &vlan, &trans); +/* This API only allows programming tagged, non-PVID VIDs */ +return dsa_port_trans_vlan_apply (dp, vid,0 , true); } static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 03/13] net: dsa: Create a more convenient function for installing port VLANs
Quoted 6 lines · Vladimir Oltean
This refactors the two-phase transaction from
dsa_slave_vlan_rx_add_vidand also makes that code available for other functions from within DSA. The newly exposed function either adds or deletes the specified VLAN entry based on a boolean argument.Signed-off-by Vladimir Oltean <[email protected]>
The name of the function does not make it particularly clear that passing false results in deleting the VLAN. Can you just wrap this under a different function name that is only doing the two-step adding of VLANs and keep using dsa_port_vlan_del() explicitly when you want to remove a VLAN?
Quoted 89 lines
--- net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 24 ++++++++++++++++++++++++ net/dsa/slave.c | 16 ++-------------- 3 files changed, 28 insertions(+), 14 deletions(-)net/dsa/dsa_priv.h +2
-0@@ -164,6 +164,8 @@ int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, struct switchdev_trans *trans);int dsa_port_bridge_flags (const struct dsa_port *dp,unsigned long flags,struct switchdev_trans *trans); +int dsa_port_trans_vlan_apply (struct dsa_port *dp,u16 vid,u16 flags, +bool enabled);int dsa_port_vlan_add (struct dsa_port *dp,const struct switchdev_obj_port_vlan *vlan,struct switchdev_trans *trans);net/dsa/port.c +24
-0@@ -326,6 +326,30 @@ int dsa_port_vlan_del(struct dsa_port *dp,return 0 ; } +int dsa_port_trans_vlan_apply (struct dsa_port *dp,u16 vid,u16 flags, +bool enabled) +{ +struct switchdev_obj_port_vlan vlan = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .flags = flags, + .vid_begin = vid, + .vid_end = vid, + }; +struct switchdev_trans trans; +int err; + +if (!enabled) +return dsa_port_vlan_del (dp, &vlan); + + trans.ph_prepare = true; + err =dsa_port_vlan_add (dp, &vlan, &trans); +if (err == -EOPNOTSUPP ) +return 0 ; + + trans.ph_prepare = false; +return dsa_port_vlan_add (dp, &vlan, &trans); +} +static struct phy_device *dsa_port_get_phy_device (struct dsa_port *dp) {struct device_node *phy_dn;net/dsa/slave.c +2
-14@@ -987,13 +987,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid) {struct dsa_port *dp =dsa_slave_to_port (dev); -struct switchdev_obj_port_vlan vlan = { - .vid_begin = vid, - .vid_end = vid, -/* This API only allows programming tagged, non-PVID VIDs */ - .flags =0 , - }; -struct switchdev_trans trans;struct bridge_vlan_info info;int ret;@@ -1010,13 +1003,8 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,return -EBUSY ; } - trans.ph_prepare = true; - ret =dsa_port_vlan_add (dp, &vlan, &trans); -if (ret == -EOPNOTSUPP ) -return 0 ; - - trans.ph_prepare = false; -return dsa_port_vlan_add (dp, &vlan, &trans); +/* This API only allows programming tagged, non-PVID VIDs */ +return dsa_port_trans_vlan_apply (dp, vid,0 , true); } static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [RFC PATCH net-next 03/13] net: dsa: Create a more convenient function for installing port VLANs
Quoted 6 lines · Florian Fainelli
Quoted 5 lines · Vladimir Oltean
This refactors the two-phase transaction from
dsa_slave_vlan_rx_add_vidand also makes that code available for other functions from within DSA. The newly exposed function either adds or deletes the specified VLAN entry based on a boolean argument.
Quoted 8 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>The name of the function does not make it particularly clear that passing false results in deleting the VLAN. Can you just wrap this under a different function name that is only doing the two-step adding of VLANs and keep using
dsa_port_vlan_del()explicitly when you want to remove a VLAN?
The reason why I made it this way was mainly to make the switchdev_obj_port_vlan struct an implementation detail. That being so I wouldn't need to keep and continuously modify this struct during the 3 times I'm calling the function from within the 05/13 patch ("net: dsa: Optional VLAN-based port separation for switches without tagging"). I did try to make use of the .vid_begin/.vid_end feature and batch some of the function calls, but doing so would restrict possible values that the rx_vid and tx_vid functions may return - dsa_port_setup_8021q_tagging() would need to ensure that they are contiguous prior to batching them into a single vlan object. By the way, I don't think anybody is making any good use of this feature, it's just creating useless boilerplate as of now. The other thing is that if I were to wrap around dsa_port_vlan_add() and get rid of the switchdev_obj_port_vlan and just pass the vid as u16, I'd have to do the same wrapping for the dsa_port_vlan_del() function too. Plus I'd have to keep 3 'if' conditions just to decide whether to call *_add or *_del.
Quoted 31 lines
net/dsa/tag_8021q.c +9
-4@@ -120,8 +120,10 @@ int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int port, bool enabled)/* The Rx VID is a regular VLAN on all others */ flags =BRIDGE_VLAN_INFO_UNTAGGED ; - err =dsa_port_trans_vlan_apply (other_dp, rx_vid, flags, - enabled); +if (enabled) + err =__dsa_port_vlan_add (other_dp, rx_vid, flags); +else + err =__dsa_port_vlan_del (other_dp, rx_vid);if (err) {dev_err (ds->dev,"Failed to apply Rx VID %d to port %d: %d\n" , rx_vid, port, err);@@ -129,14 +131,20 @@ int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int port, bool enabled) } }/* Finally apply the Tx VID on this port and on the CPU port */ - err =dsa_port_trans_vlan_apply (dp, tx_vid,BRIDGE_VLAN_INFO_UNTAGGED , - enabled); +if (enabled) + err =__dsa_port_vlan_add (dp, tx_vid, +BRIDGE_VLAN_INFO_UNTAGGED ); +else + err =__dsa_port_vlan_del (dp, tx_vid);if (err) {dev_err (ds->dev,"Failed to apply Tx VID %d on port %d: %d\n" , tx_vid, port, err);
net/dsa/tag_8021q.c int dsa_port_setup_8021q_tagging(struct dsa_switch *ds, int port, bool enabled) · line 150
Quoted 10 lines
net/dsa/tag_8021q.c +4
-1return err; } - err =dsa_port_trans_vlan_apply (upstream_dp, tx_vid,0 , enabled); +if (enabled) + err =__dsa_port_vlan_add (upstream_dp, tx_vid,0 ); +else + err =__dsa_port_vlan_del (upstream_dp, tx_vid);if (err) {dev_err (ds->dev,"Failed to apply Tx VID %d on port %d: %d\n" , tx_vid, upstream, err);
How does something like the above look like?
Thanks,
-Vladimir
Quoted 91 lines
Quoted 89 lines
--- net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 24 ++++++++++++++++++++++++ net/dsa/slave.c | 16 ++-------------- 3 files changed, 28 insertions(+), 14 deletions(-)net/dsa/dsa_priv.h +2
-0@@ -164,6 +164,8 @@ int dsa_port_pre_bridge_flags(const struct dsa_port *dp, unsigned long flags, struct switchdev_trans *trans);int dsa_port_bridge_flags (const struct dsa_port *dp,unsigned long flags,struct switchdev_trans *trans); +int dsa_port_trans_vlan_apply (struct dsa_port *dp,u16 vid,u16 flags, +bool enabled);int dsa_port_vlan_add (struct dsa_port *dp,const struct switchdev_obj_port_vlan *vlan,struct switchdev_trans *trans);net/dsa/port.c +24
-0@@ -326,6 +326,30 @@ int dsa_port_vlan_del(struct dsa_port *dp,return 0 ; } +int dsa_port_trans_vlan_apply (struct dsa_port *dp,u16 vid,u16 flags, +bool enabled) +{ +struct switchdev_obj_port_vlan vlan = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .flags = flags, + .vid_begin = vid, + .vid_end = vid, + }; +struct switchdev_trans trans; +int err; + +if (!enabled) +return dsa_port_vlan_del (dp, &vlan); + + trans.ph_prepare = true; + err =dsa_port_vlan_add (dp, &vlan, &trans); +if (err == -EOPNOTSUPP ) +return 0 ; + + trans.ph_prepare = false; +return dsa_port_vlan_add (dp, &vlan, &trans); +} +static struct phy_device *dsa_port_get_phy_device (struct dsa_port *dp) {struct device_node *phy_dn;net/dsa/slave.c +2
-14@@ -987,13 +987,6 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto, u16 vid) {struct dsa_port *dp =dsa_slave_to_port (dev); -struct switchdev_obj_port_vlan vlan = { - .vid_begin = vid, - .vid_end = vid, -/* This API only allows programming tagged, non-PVID VIDs */ - .flags =0 , - }; -struct switchdev_trans trans;struct bridge_vlan_info info;int ret;@@ -1010,13 +1003,8 @@ static int dsa_slave_vlan_rx_add_vid(struct net_device *dev, __be16 proto,return -EBUSY ; } - trans.ph_prepare = true; - ret =dsa_port_vlan_add (dp, &vlan, &trans); -if (ret == -EOPNOTSUPP ) -return 0 ; - - trans.ph_prepare = false; -return dsa_port_vlan_add (dp, &vlan, &trans); +/* This API only allows programming tagged, non-PVID VIDs */ +return dsa_port_trans_vlan_apply (dp, vid,0 , true); } static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
Vladimir Oltean
maintainerRFC PATCH 4/13 net: dsa: Call driver's setup callback after setting up its switchdev notifier
In reply to Vladimir OlteanThis allows the driver to perform some manipulations of its own during setup, using generic code.
One current usage scenario is for the driver to request DSA to set up 802.1Q based switch tagging for its ports.
--- net/dsa/dsa2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/dsa/dsa2.c +4 -4
@@ -360,14 +360,14 @@ static int dsa_switch_setup(struct dsa_switch *ds)if (err)return err; - err = ds->ops->setup (ds); -if (err <0 ) -return err; - err =dsa_switch_register_notifier (ds);if (err)return err; + err = ds->ops->setup (ds); +if (err <0 ) +return err; +if (!ds->slave_mii_bus && ds->ops->phy_read) { ds->slave_mii_bus =devm_mdiobus_alloc (ds->dev);if (!ds->slave_mii_bus)
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 04/13] net: dsa: Call driver's setup callback after setting up its switchdev notifier
Quoted 6 lines · Vladimir Oltean
This allows the driver to perform some manipulations of its own during setup, using generic code.
One current usage scenario is for the driver to request DSA to set up 802.1Q based switch tagging for its ports.Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 5/13 net: dsa: Optional VLAN-based port separation for switches without tagging
In reply to Vladimir OlteanThis patch provides generic DSA code for using VLAN (802.1Q) tags for the same purpose as a dedicated switch tag for injection/extraction. It is based on the discussions and interest that has been so far expressed in https://www.spinics.net/lists/netdev/msg556125.html.
Unlike all other DSA-supported tagging protocols, CONFIG_NET_DSA_TAG_8021Q does not offer a complete solution for drivers (nor can it). Instead, it provides generic code that driver can opt into calling:
- dsa_8021q_xmit: Inserts a VLAN header with the specified contents. Currently a few driver are inserting headers that are simply 802.1Q with custom fields. Can be called from another tagging protocol's xmit function.
- dsa_8021q_rcv: Retrieves the TPID and TCI from a VLAN-tagged skb. Removing the VLAN header is left as a decision for the caller to make.
- dsa_port_setup_8021q_tagging: For each user port, installs an Rx VID and a Tx VID, for proper untagged traffic identification on ingress and steering on egress. Also sets up the VLAN trunk on the upstream (CPU or DSA) port. Drivers are intentionally left to call this function explicitly, depending on the context and hardware support. The expected switch behavior and VLAN semantics should not be violated under any conditions. That is, after calling dsa_port_setup_8021q_tagging, the hardware should still pass all ingress traffic, be it tagged or untagged.
This only works when switch ports are standalone, or when they are added to a VLAN-unaware bridge. It will probably remain this way for the reasons below.
When added to a bridge that has vlan_filtering 1, the bridge core will install its own VLANs and reset the pvids through switchdev. For the bridge core, switchdev is a write-only pipe. All VLAN-related state is kept in the bridge core and nothing is read from DSA/switchdev or from the driver. So the bridge core will break this port separation because it will install the vlan_default_pvid into all switchdev ports.
Even if we could teach the bridge driver about switchdev preference of a certain vlan_default_pvid, there would still exist many other challenges.
Firstly, in the DSA rcv callback, a driver would have to perform an iterative reverse lookup to find the correct switch port. That is because the port is a bridge slave, so its Rx VID (port PVID) is subject to user configuration. How would we ensure that the user doesn't reset the pvid to a different value, or to a non-unique value within this DSA switch tree?
Finally, not all switch ports are equal in DSA, and that makes it difficult for the bridge to be completely aware of this anyway. The CPU port needs to transmit tagged packets (VLAN trunk) in order for the DSA rcv code to be able to decode source information. But the bridge code has absolutely no idea which switch port is the CPU port, if nothing else then just because there is no netdevice registered by DSA for the CPU port.
Also DSA does not currently allow the user to specify that they want the CPU port to do VLAN trunking anyway. VLANs are added to the CPU port using the same flags as they were added on the user port.
So the VLANs installed by dsa_port_setup_8021q_tagging per driver request should remain private from the bridge's and user's perspective, and should not alter the hardware's behavior with VLAN-tagged traffic. If the hardware cannot handle VLAN tag stacking, it should also disable this port separation when added as slave to a vlan_filtering bridge. If the hardware does support VLAN tag stacking, it should somehow back up its private VLAN settings when the bridge tries to override them.
--- include/net/dsa.h | 4 + net/dsa/Kconfig | 9 +++ net/dsa/Makefile | 1 + net/dsa/dsa_priv.h | 10 +++ net/dsa/tag_8021q.c | 185 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 209 insertions(+) create mode 100644 net/dsa/tag_8021q.c
include/net/dsa.h +4 -0
@@ -574,5 +574,9 @@ int dsa_port_get_phy_strings(struct dsa_port *dp, uint8_t *data);int dsa_port_get_ethtool_phy_stats (struct dsa_port *dp,uint64_t *data);int dsa_port_get_phy_sset_count (struct dsa_port *dp);void dsa_port_phylink_mac_change (struct dsa_switch *ds,int port,bool up); +#ifdef CONFIG_NET_DSA_TAG_8021Q +int dsa_port_setup_8021q_tagging (struct dsa_switch *ds,int index, +bool enabled); +#endif #endif
net/dsa/Kconfig +9 -0
@@ -26,6 +26,15 @@ config NET_DSA_LEGACY This feature is scheduled for removal in 4.17. # tagging formats +config NET_DSA_TAG_8021Q + bool + help + Unlike the other tagging protocols, the 802.1Q config option simply + provides helpers for other tagging implementations that might rely on + VLAN in one way or another. It is not a complete solution. + + Drivers which use these helpers should select this as dependency. + config NET_DSA_TAG_BRCM bool
net/dsa/Makefile +1 -0
@@ -5,6 +5,7 @@ dsa_core-y += dsa.o dsa2.o master.o port.o slave.o switch.o dsa_core-$(CONFIG_NET_DSA_LEGACY) += legacy.o # tagging formats +dsa_core-$(CONFIG_NET_DSA_TAG_8021Q) += tag_8021q.o dsa_core-$(CONFIG_NET_DSA_TAG_BRCM) += tag_brcm.o dsa_core-$(CONFIG_NET_DSA_TAG_BRCM_PREPEND) += tag_brcm.o dsa_core-$(CONFIG_NET_DSA_TAG_DSA) += tag_dsa.o
net/dsa/dsa_priv.h +10 -0
@@ -203,6 +203,16 @@ dsa_slave_to_master(const struct net_device *dev)int dsa_switch_register_notifier (struct dsa_switch *ds);void dsa_switch_unregister_notifier (struct dsa_switch *ds); +/* tag_8021q.c */ +struct sk_buff *dsa_8021q_xmit (struct sk_buff *skb,struct net_device *netdev, +u16 tpid,u16 tci); +struct sk_buff *dsa_8021q_rcv (struct sk_buff *skb,struct net_device *netdev, +struct packet_type *pt,u16 *tpid,u16 *tci); +u16 dsa_tagging_tx_vid (struct dsa_switch *ds,int port); +u16 dsa_tagging_rx_vid (struct dsa_switch *ds,int port); +int dsa_tagging_rx_switch_id (u16 vid); +int dsa_tagging_rx_source_port (u16 vid); +/* tag_brcm.c */ extern const struct dsa_device_ops brcm_netdev_ops;extern const struct dsa_device_ops brcm_prepend_netdev_ops;
net/dsa/tag_8021q.c new file +185 -0
185 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 05/13] net: dsa: Optional VLAN-based port separation for switches without tagging
Quoted 45 lines · Vladimir Oltean
This patch provides generic DSA code for using VLAN (802.1Q) tags for the same purpose as a dedicated switch tag for injection/extraction. It is based on the discussions and interest that has been so far expressed in https://www.spinics.net/lists/netdev/msg556125.html.
Unlike all other DSA-supported tagging protocols,
CONFIG_NET_DSA_TAG_8021Qdoes not offer a complete solution for drivers (nor can it). Instead, it provides generic code that driver can opt into calling:
-dsa_8021q_xmit: Inserts a VLAN header with the specified contents. Currently a few driver are inserting headers that are simply 802.1Q with custom fields. Can be called from another tagging protocol's xmit function.
-dsa_8021q_rcv: Retrieves the TPID and TCI from a VLAN-tagged skb. Removing the VLAN header is left as a decision for the caller to make.
-dsa_port_setup_8021q_tagging: For each user port, installs an Rx VID and a Tx VID, for proper untagged traffic identification on ingress and steering on egress. Also sets up the VLAN trunk on the upstream (CPU or DSA) port. Drivers are intentionally left to call this function explicitly, depending on the context and hardware support. The expected switch behavior and VLAN semantics should not be violated under any conditions. That is, after callingdsa_port_setup_8021q_tagging, the hardware should still pass all ingress traffic, be it tagged or untagged.This only works when switch ports are standalone, or when they are added to a VLAN-unaware bridge. It will probably remain this way for the reasons below.
When added to a bridge that has
vlan_filtering1, the bridge core will install its own VLANs and reset the pvids through switchdev. For the bridge core, switchdev is a write-only pipe. All VLAN-related state is kept in the bridge core and nothing is read from DSA/switchdev or from the driver. So the bridge core will break this port separation because it will install thevlan_default_pvidinto all switchdev ports.Even if we could teach the bridge driver about switchdev preference of a certain
vlan_default_pvid, there would still exist many other challenges.Firstly, in the DSA rcv callback, a driver would have to perform an iterative reverse lookup to find the correct switch port. That is because the port is a bridge slave, so its Rx VID (port PVID) is subject to user configuration. How would we ensure that the user doesn't reset the pvid to a different value, or to a non-unique value within this DSA switch tree?
Quoted 7 lines
Finally, not all switch ports are equal in DSA, and that makes it difficult for the bridge to be completely aware of this anyway. The CPU port needs to transmit tagged packets (VLAN trunk) in order for the DSA rcv code to be able to decode source information. But the bridge code has absolutely no idea which switch port is the CPU port, if nothing else then just because there is no netdevice registered by DSA for the CPU port.
That is true, although we can use the bridge master device as a substitute for targeting the CPU port (we don't have any for the DSA ports though, so they will have to remain in a mode where they forward all VIDs), see .
We don't support that just yet in DSA though.
Quoted 11 lines
Also DSA does not currently allow the user to specify that they want the CPU port to do VLAN trunking anyway. VLANs are added to the CPU port using the same flags as they were added on the user port.
So the VLANs installed by
dsa_port_setup_8021q_taggingper driver request should remain private from the bridge's and user's perspective, and should not alter the hardware's behavior with VLAN-tagged traffic. If the hardware cannot handle VLAN tag stacking, it should also disable this port separation when added as slave to avlan_filteringbridge. If the hardware does support VLAN tag stacking, it should somehow back up its private VLAN settings when the bridge tries to override them.
This is an excellent commit message and it captures really well the challenges involved in trying to coerce 802.1Q only switches into offering separate DSA slave network devices. Here are a few ideas on how this can be solved now or later, with possibly a reduction in functionality:
- if the switch internally performs double VLAN tag normalization, then we could dedicate an outer tag per bridge device, which would allow identical inner tag VID numbers to co-exist, yet preserve broadcast domain isolation
- when only 802.1Q is supported (single tagging), we could somehow enforce that all ports must be part of a VLAN aware bridge, which would eliminate the need to have standalone DSA network devices alongside bridged DSA network devices
Your solution clearly works and is a clever way to solve that problem.
[snip]
net/dsa/Kconfig config NET_DSA_LEGACY · line 31
Quoted 3 lines
net/dsa/Kconfig +3
-0+config NET_DSA_TAG_8021Q + bool + help
This probably needs a depends on/select VLAN_8021Q to be functional.
net/dsa/tag_8021q.c line 10
Quoted 11 lines
net/dsa/tag_8021q.c new file +10
-0@@ -0,0 +1,185 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2019, Vladimir Oltean <[email protected]> +*/ +#include <linux/if_bridge.h> +#include <linux/if_vlan.h> + +#include "dsa_priv.h" + +#define DSA_TAGGING_VID_RANGE (DSA_MAX_SWITCHES * DSA_MAX_PORTS) +#define DSA_TAGGING_VID_BASE (VLAN_N_VID - 2 * DSA_TAGGING_VID_RANGE - 1)
VLAN_N_VID may not be a range supported on all switches (e.g.: the ones that were once popular 15 years ago, like BCM5325/5365) but that can be changed later on to incorporate per-switch VLAN range limitations.
I would add a comment about why you reserving two times the space, for which you provide an explanation down below.
With the Kconfig changed:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 6/13 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. The switch ports are initialized in a mode where they can only talk to the CPU port. However, IP termination must be done currently through the master netdevice.
--- MAINTAINERS | 6 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 17 + drivers/net/dsa/sja1105/Makefile | 9 + drivers/net/dsa/sja1105/sja1105.h | 134 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 677 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 607 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 40 + drivers/net/dsa/sja1105/sja1105_main.c | 904 ++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 667 ++++++ .../net/dsa/sja1105/sja1105_static_config.c | 1810 +++++++++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 500 +++++ 13 files changed, 5374 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
MAINTAINERS +6 -0
@@ -11117,6 +11117,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 +17 -0
@@ -0,0 +1,17 @@ +config NET_DSA_SJA1105 +tristate "NXP SJA1105 Ethernet switch family support" + depends on NET_DSA + select NET_DSA_TAG_SJA1105 + select NET_DSA_TAG_8021Q + 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 +9 -0
@@ -0,0 +1,9 @@ +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 +134 -0
134 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_clocking.c new file +677 -0
677 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.c new file +607 -0
607 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0 +* Copyright (c) 2019, Vladimir Oltean <[email protected]> +*/ +#ifndef _SJA1105_DYNAMIC_CONFIG_H +#define _SJA1105_DYNAMIC_CONFIG_H + +#include "sja1105.h" +#include <linux/packing.h> + +struct sja1105_dyn_cmd { +u64 valid; +u64 rdwrset; +u64 errors; +u64 valident; +u64 index; +}; + +struct sja1105_dynamic_table_ops { +/* This returns size_t just to keep same prototype as the +* static config ops, of which we are reusing some functions. +*/ +size_t (*entry_packing)(void *buf,void *entry_ptr,enum packing_op op); +void (*cmd_packing)(void *buf,struct sja1105_dyn_cmd *cmd, +enum packing_op op); +size_t max_entry_count; +size_t packed_size; +u64 addr; +u8 access; +}; + +struct sja1105_mgmt_entry { +u64 tsreg; +u64 takets; +u64 macaddr; +u64 destports; +u64 enfport; +u64 index; +}; + +#endif
drivers/net/dsa/sja1105/sja1105_main.c new file +904 -0
904 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_spi.c new file +667 -0
588 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.c new file +1810 -0
1,810 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.h new file +500 -0
500 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.
Re: [RFC PATCH net-next 06/13] net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
Quoted 2 lines · Vladimir Oltean
At this moment the following is supported:
* Link state management through phylib
Not a show stopper for now, and your implementation looks sane, though I would recommend implementing phylink to be future proof, and especially since you support SGMII.
I was not able to review everything deeply so:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [RFC PATCH net-next 06/13] net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
Hi Florian,
I am grateful for the thorough review you made to the entire patchset. It's nice to meet passionate people whom I can share ideas with.
Quoted 8 lines · Florian Fainelli
Quoted 2 lines · Vladimir Oltean
At this moment the following is supported:
* Link state management through phylibNot a show stopper for now, and your implementation looks sane, though I would recommend implementing phylink to be future proof, and especially since you support SGMII.
Quoted 5 lines
I was not able to review everything deeply so:
Acked-by Florian Fainelli <[email protected]>--
Florian
I don't think SGMII works at this point, with the current enablement. When I send the first non-RFC patchset I think I'm going to completely remove it (along with some other momentarily unused code). I'll add it back when I can put my hands on a board where the SGMII interface is actually routed - hopefully in a few weeks at most. Then I can also rework the MAC adaptation to PHY portion to use phylink instead of phylib, for "future-proofing".
Thank you!
-Vladimir
Vladimir Oltean
maintainerRFC PATCH 7/13 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.
--- drivers/net/dsa/sja1105/sja1105_main.c | 193 +++++++++++++++++++++++++ 1 file changed, 193 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +193 -0
@@ -190,6 +190,9 @@ static int sja1105_init_static_fdb(struct sja1105_private *priv) table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP ]; +/* We only populate the FDB table through dynamic +* L2 Address Lookup entries +*/ if (table->entry_count) {kfree (table->entries); table->entry_count =0 ;
@@ -703,6 +706,190 @@ static void sja1105_adjust_link(struct dsa_switch *ds, int port,sja1105_adjust_port_config (priv, port, phydev->speed, true); } +#define fdb (bin, index) \ + ((bin) * SJA1105ET_FDB_BIN_SIZE + (index)) +#define is_bin_index_valid (i) \ + ((i) >= 0 && (i) < SJA1105ET_FDB_BIN_SIZE) + +static int +sja1105_is_fdb_entry_in_bin (struct sja1105_private *priv,int bin, +const u8 *addr,u16 vid, +struct sja1105_l2_lookup_entry *fdb_match, +int *last_unused) +{ +int index_in_bin; + +for (index_in_bin =0 ; index_in_bin <SJA1105ET_FDB_BIN_SIZE ; + index_in_bin++) { +struct sja1105_l2_lookup_entry l2_lookup = {0 }; + +/* Skip unused entries, optionally marking them +* into the return value +*/ +if (sja1105_dynamic_config_read (priv,BLK_IDX_L2_LOOKUP , +fdb (bin, index_in_bin), + &l2_lookup)) { +if (last_unused) + *last_unused = index_in_bin; +continue ; + } + +if (l2_lookup.macaddr ==ether_addr_to_u64 (addr) && + l2_lookup.vlanid == vid) { +if (fdb_match) + *fdb_match = l2_lookup; +return index_in_bin; + } + } +/* Return an invalid entry index if not found */ +return SJA1105ET_FDB_BIN_SIZE ; +} + +static int sja1105_fdb_add (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid) +{ +struct sja1105_l2_lookup_entry l2_lookup = {0 }; +struct sja1105_private *priv = ds->priv; +struct device *dev = ds->dev; +int bin, index_in_bin; +int last_unused; + + bin =sja1105_fdb_hash (priv, addr, vid); + + index_in_bin =sja1105_is_fdb_entry_in_bin (priv, bin, addr, vid, + &l2_lookup, &last_unused); +if (is_bin_index_valid (index_in_bin)) { +/* We have an FDB entry. Is our port in the destination +* mask? If yes, we need to do nothing. If not, we need +* to rewrite the entry by adding this port to it. +*/ +if (l2_lookup.destports &BIT (port)) +return 0 ; + l2_lookup.destports |=BIT (port); + }else { +/* We don't have an FDB entry. We construct a new one and +* try to find a place for it within the FDB table. +*/ + l2_lookup.macaddr =ether_addr_to_u64 (addr); + l2_lookup.destports =BIT (port); + l2_lookup.vlanid = vid; + +if (is_bin_index_valid (last_unused)) { + index_in_bin = last_unused; + }else { +/* Bin is full, need to evict somebody. +* Choose victim at random. If you get these messages +* often, you may need to consider changing the +* distribution function: +* static_config[BLK_IDX_L2_LOOKUP_PARAMS].entries->poly +*/ +get_random_bytes (&index_in_bin,sizeof (u8)); + index_in_bin %=SJA1105ET_FDB_BIN_SIZE ; +dev_warn (dev,"Warning, FDB bin %d full while adding entry for %pM. Evicting entry %u.\n" , + bin, addr, index_in_bin); +/* Evict entry */ +sja1105_dynamic_config_write (priv,BLK_IDX_L2_LOOKUP , +fdb (bin, index_in_bin), +NULL , false); + } + } + l2_lookup.index =fdb (bin, index_in_bin); + +return sja1105_dynamic_config_write (priv,BLK_IDX_L2_LOOKUP , + l2_lookup.index, &l2_lookup, true); +} + +static int sja1105_fdb_del (struct dsa_switch *ds,int port, +const unsigned char *addr,u16 vid) +{ +struct sja1105_l2_lookup_entry l2_lookup = {0 }; +struct sja1105_private *priv = ds->priv; +u8 bin, index_in_bin; +bool keep; + + bin =sja1105_fdb_hash (priv, addr, vid); + + index_in_bin =sja1105_is_fdb_entry_in_bin (priv, bin, addr, vid, + &l2_lookup,NULL ); +if (!is_bin_index_valid (index_in_bin)) +return 0 ; + +/* We have an FDB entry. Is our port in the destination mask? If yes, +* we need to remove it. If the resulting port mask becomes empty, we +* need to completely evict the FDB entry. +* Otherwise we just write it back. +*/ +if (l2_lookup.destports &BIT (port)) + l2_lookup.destports &= ~BIT (port); +if (l2_lookup.destports) + keep = true; +else + keep = false; + +return sja1105_dynamic_config_write (priv,BLK_IDX_L2_LOOKUP , +fdb (bin, index_in_bin), + &l2_lookup, keep); +} + +static int sja1105_fdb_dump (struct dsa_switch *ds,int port, +dsa_fdb_dump_cb_t *cb,void *data) +{ +struct sja1105_private *priv = ds->priv; +struct device *dev = ds->dev; +int i; + +for (i =0 ; i <MAX_L2_LOOKUP_COUNT ; i++) { +struct sja1105_l2_lookup_entry l2_lookup; +u8 macaddr[ETH_ALEN ]; +int rc; + +memset (&l2_lookup,0 ,sizeof (l2_lookup)); + rc =sja1105_dynamic_config_read (priv,BLK_IDX_L2_LOOKUP , + i, &l2_lookup); +/* No fdb entry at i, not an issue */ +if (rc == -EINVAL ) +continue ; +if (rc) { +dev_err (dev,"Failed to dump FDB: %d\n" , rc); +return rc; + } + +/* FDB dump callback is per port. This means we have to +* disregard a valid entry if it's not for this port, even if +* only to revisit it later. This is inefficient because the +* 1024-sized FDB table needs to be traversed 4 times through +* SPI during a 'bridge fdb show' command. +*/ +if (!(l2_lookup.destports &BIT (port))) +continue ; +u64_to_ether_addr (l2_lookup.macaddr, macaddr); +cb (macaddr, l2_lookup.vlanid, false, data); + } +return 0 ; +} + +#undef fdb +#undef is_bin_index_valid + +/* This callback needs to be present */ +static int sja1105_mdb_prepare (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb) +{ +return 0 ; +} + +static void sja1105_mdb_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb) +{ +sja1105_fdb_add (ds, port, mdb->addr, mdb->vid); +} + +static int sja1105_mdb_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_mdb *mdb) +{ +return sja1105_fdb_del (ds, port, mdb->addr, mdb->vid); +} +static int sja1105_bridge_member (struct dsa_switch *ds,int port,struct net_device *br,bool member) {
@@ -796,8 +983,14 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .get_tag_protocol = sja1105_get_tag_protocol, .setup = sja1105_setup, .adjust_link = sja1105_adjust_link, + .port_fdb_dump = sja1105_fdb_dump, + .port_fdb_add = sja1105_fdb_add, + .port_fdb_del = sja1105_fdb_del, .port_bridge_join = sja1105_bridge_join, .port_bridge_leave = sja1105_bridge_leave, + .port_mdb_prepare = sja1105_mdb_prepare, + .port_mdb_add = sja1105_mdb_add, + .port_mdb_del = sja1105_mdb_del, };static int sja1105_probe (struct spi_device *spi)
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 07/13] net: dsa: sja1105: Add support for FDB and MDB management
Quoted 10 lines · Vladimir Oltean
Currently 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.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 8/13 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 (ETH_P_EDSA) 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.
--- drivers/net/dsa/sja1105/sja1105_main.c | 275 ++++++++++++++++++++++++- 1 file changed, 273 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +273 -2
@@ -263,6 +263,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);
@@ -403,8 +410,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_EDSA, + .tpid2 = ETH_P_EDSA,/* P/Q/R/S only */ .queue_ts = 0, .egrmirrvid = 0,
@@ -934,12 +944,269 @@ 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] !=SJA1105_SPEED_AUTO ); + + rc =sja1105_adjust_port_config (priv, i, speed_mbps[i], + enabled); +if (rc <0 ) + goto out; + } +out: +return rc; +} + +#define sja1105_vlan_filtering_enabled (priv) \ + (((struct sja1105_general_params_entry *) \ + ((struct sja1105_private *)priv)->static_config. \ + tables[BLK_IDX_GENERAL_PARAMS].entries)->tpid == ETH_P_8021Q) + +/* 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 =0 , i; + +/* 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_EDSA, which are invalid) will be internally tagged with a +* distorted VLAN header where the TPID is ETH_P_EDSA, and the VLAN ID +* is the port pvid. So since this operation is global to the switch, +* we need to handle the case where multiple bridges span the same +* switch device and one of them has a different setting than what is +* being requested. +*/ +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { +struct net_device *bridge_dev; + + bridge_dev =dsa_to_port (ds, i)->bridge_dev; +if (bridge_dev && + bridge_dev !=dsa_to_port (ds, port)->bridge_dev && +br_vlan_enabled (bridge_dev) != enabled) { +netdev_err (bridge_dev, +"VLAN filtering is global to the switch!\n" ); +return -EINVAL ; + } + } + +if (enabled && !sja1105_vlan_filtering_enabled (priv)) +/* Enable VLAN filtering. +* TODO read these from bridge_dev->protocol. +*/ + rc =sja1105_change_tpid (priv,ETH_P_8021Q ,ETH_P_8021AD ); +else if (!enabled &&sja1105_vlan_filtering_enabled (priv)) +/* Disable VLAN filtering. TODO: Install a TPID +* that also encodes the switch ID (aka ds->index) +* so that stacking switch tags will be supported. +*/ + rc =sja1105_change_tpid (priv,ETH_P_EDSA ,ETH_P_EDSA ); +else +return 0 ; +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.
@@ -988,6 +1255,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,
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 08/13] net: dsa: sja1105: Add support for VLAN operations
Quoted 14 lines · Vladimir Oltean
VLAN 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
0x8100for 802.1Q). We are reprogramming the TPID to a bogus value (ETH_P_EDSA) which leaves the switch thinking that all traffic is untagged, and therefore accepts it.Under a
vlan_filteringbridge, the proper TPID ofETH_P_8021Qis installed again, and the switch starts identifying 802.1Q-tagged traffic.Signed-off-by Vladimir Oltean <[email protected]>---
[snip]
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_bridge_leave(struct dsa_switch *ds, int port, · line 1143
Quoted 11 lines
drivers/net/dsa/sja1105/sja1105_main.c +11
-0+for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { +struct net_device *bridge_dev; + + bridge_dev =dsa_to_port (ds, i)->bridge_dev; +if (bridge_dev && + bridge_dev !=dsa_to_port (ds, port)->bridge_dev && +br_vlan_enabled (bridge_dev) != enabled) { +netdev_err (bridge_dev, +"VLAN filtering is global to the switch!\n" ); +return -EINVAL ; + }
We might want to move this to the DSA core at some point, I had some patches lying around for doing that but got side tracked with adding management support for b53/bcm_sf2. Not a big problem for now.
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 9/13 net: dsa: sja1105: Add support for ethtool port counters
In reply to Vladimir Oltean--- drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 6 + drivers/net/dsa/sja1105/sja1105_ethtool.c | 420 ++++++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_main.c | 3 + 4 files changed, 430 insertions(+) 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 -0
@@ -102,6 +102,12 @@ const char *sja1105_device_id_string_get(u64 device_id, u64 part_nr);int sja1105_clocking_setup_port (struct sja1105_private *priv,int port);int sja1105_clocking_setup (struct sja1105_private *priv); +/* 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,
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +420 -0
420 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c +3 -0
@@ -1250,6 +1250,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
Re: [RFC PATCH net-next 09/13] net: dsa: sja1105: Add support for ethtool port counters
Quoted 2 lines · Vladimir Oltean
Signed-off-by Vladimir Oltean <[email protected]>---
[snip]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 413
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +5
-0+ +int sja1105_get_sset_count (struct dsa_switch *ds,int port,int sset) +{ +int count =ARRAY_SIZE (sja1105_port_stats); +struct sja1105_private *priv = ds->priv;
There is a missing if (sset != ETH_SS_STATS) return here potentially. With that:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 10/13 net: dsa: sja1105: Add support for traffic through standalone ports
In reply to Vladimir OlteanIn order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination on switch ports only works when not under a vlan_filtering bridge. We are making use of the generic CONFIG_NET_DSA_TAG_8021Q code and leveraging it from our own CONFIG_NET_DSA_TAG_SJA1105.
There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.
For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
--- drivers/net/dsa/sja1105/sja1105.h | 8 ++ drivers/net/dsa/sja1105/sja1105_main.c | 119 +++++++++++++++++++++ include/linux/dsa/sja1105.h | 52 +++++++++ include/net/dsa.h | 1 + net/dsa/Kconfig | 3 + net/dsa/Makefile | 1 + net/dsa/dsa.c | 6 ++ net/dsa/dsa_priv.h | 3 + net/dsa/tag_sja1105.c | 142 +++++++++++++++++++++++++ 9 files changed, 335 insertions(+) create mode 100644 include/linux/dsa/sja1105.h create mode 100644 net/dsa/tag_sja1105.c
drivers/net/dsa/sja1105/sja1105.h +8 -0
@@ -5,6 +5,7 @@#ifndef _SJA1105_H#define _SJA1105_H +#include <linux/dsa/sja1105.h> #include <net/dsa.h> #include "sja1105_static_config.h"
@@ -19,6 +20,12 @@#define SJA1105_NUM_TC 8#define SJA1105ET_FDB_BIN_SIZE 4 +struct sja1105_port { +struct dsa_port *dp; +struct work_struct xmit_work; +struct sja1105_skb_ring xmit_ring; +}; +/* Keeps the different addresses between E/T and P/Q/R/S */ struct sja1105_regs {u64 general_status;
@@ -50,6 +57,7 @@ struct sja1105_private {struct dsa_switch *ds;u64 device_id;u64 part_nr;/* Needed for P/R distinction (same switch core) */ +struct sja1105_port ports[SJA1105_NUM_PORTS ]; };#include "sja1105_dynamic_config.h"
drivers/net/dsa/sja1105/sja1105_main.c +119 -0
143 lines not on this page · raw message
include/linux/dsa/sja1105.h new file +52 -0
52 lines not on this page · raw message
include/net/dsa.h +1 -0
@@ -41,6 +41,7 @@ enum dsa_tag_protocol {DSA_TAG_PROTO_KSZ9893 ,DSA_TAG_PROTO_LAN9303 ,DSA_TAG_PROTO_MTK , +DSA_TAG_PROTO_SJA1105 ,DSA_TAG_PROTO_QCA ,DSA_TAG_PROTO_TRAILER , DSA_TAG_LAST, /* MUST BE LAST */
net/dsa/Kconfig +3 -0
@@ -63,6 +63,9 @@ config NET_DSA_TAG_LAN9303 config NET_DSA_TAG_MTK bool +config NET_DSA_TAG_SJA1105 + bool + config NET_DSA_TAG_TRAILER bool
net/dsa/Makefile +1 -0
@@ -15,4 +15,5 @@ dsa_core-$(CONFIG_NET_DSA_TAG_KSZ) += tag_ksz.o dsa_core-$(CONFIG_NET_DSA_TAG_LAN9303) += tag_lan9303.o dsa_core-$(CONFIG_NET_DSA_TAG_MTK) += tag_mtk.o dsa_core-$(CONFIG_NET_DSA_TAG_QCA) += tag_qca.o +dsa_core-$(CONFIG_NET_DSA_TAG_SJA1105) += tag_sja1105.o dsa_core-$(CONFIG_NET_DSA_TAG_TRAILER) += tag_trailer.o
net/dsa/dsa.c +6 -0
@@ -65,6 +65,9 @@ const struct dsa_device_ops *dsa_device_ops[DSA_TAG_LAST] = { #ifdef CONFIG_NET_DSA_TAG_MTK [DSA_TAG_PROTO_MTK ] = &mtk_netdev_ops, #endif +#ifdef CONFIG_NET_DSA_TAG_SJA1105 + [DSA_TAG_PROTO_SJA1105 ] = &sja1105_netdev_ops, +#endif #ifdef CONFIG_NET_DSA_TAG_QCA [DSA_TAG_PROTO_QCA] = &qca_netdev_ops, #endif
@@ -102,6 +105,9 @@ const char *dsa_tag_protocol_to_str(const struct dsa_device_ops *ops) #ifdef CONFIG_NET_DSA_TAG_MTK [DSA_TAG_PROTO_MTK ] ="mtk" , #endif +#ifdef CONFIG_NET_DSA_TAG_SJA1105 + [DSA_TAG_PROTO_SJA1105 ] ="sja1105" , +#endif #ifdef CONFIG_NET_DSA_TAG_QCA [DSA_TAG_PROTO_QCA] = "qca", #endif
net/dsa/dsa_priv.h +3 -0
@@ -236,6 +236,9 @@ extern const struct dsa_device_ops lan9303_netdev_ops;/* tag_mtk.c */ extern const struct dsa_device_ops mtk_netdev_ops; +/* tag_sja1105.c */ +extern const struct dsa_device_ops sja1105_netdev_ops; +/* tag_qca.c */ extern const struct dsa_device_ops qca_netdev_ops;
net/dsa/tag_sja1105.c new file +142 -0
142 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 10/13] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 26 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination on switch ports only works when not under a
vlan_filteringbridge. We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>
I do like the idea of setting up specific management queue later on, although it is not clear to me how you would go about integrating it as a network device, given the DSA slave and master devices, do you know roughly how you would proceed?
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [RFC PATCH net-next 10/13] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 29 lines · Florian Fainelli
Quoted 26 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination on switch ports only works when not under a
vlan_filteringbridge. We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Quoted 9 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>I do like the idea of setting up specific management queue later on, although it is not clear to me how you would go about integrating it as a network device, given the DSA slave and master devices, do you know roughly how you would proceed?
Actually I was thinking about leveraging the multiqueue support that you added in 55199df6d2af ("net: dsa: Allow switch drivers to indicate number of TX queues") and expose the slave netdev .ndo_select_queue callback towards DSA ports. There I would return queue #0 if sja1105_is_link_local(skb), and queue #1 otherwise. Are there any complications that I'm missing?
Thanks,
-Vladimir
Re: [RFC PATCH net-next 10/13] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 41 lines · Vladimir Oltean
Quoted 30 lines · Florian Fainelli
Quoted 27 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination on switch ports only works when not under a
vlan_filteringbridge. We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame. So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Quoted 9 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>I do like the idea of setting up specific management queue later on, although it is not clear to me how you would go about integrating it as a network device, given the DSA slave and master devices, do you know roughly how you would proceed?
Quoted 6 lines
Actually I was thinking about leveraging the multiqueue support that you added in
55199df6d2af("net: dsa: Allow switch drivers to indicate number of TX queues") and expose the slave netdev .ndo_select_queue callback towards DSA ports. There I would return queue #0 ifsja1105_is_link_local(skb), and queue #1 otherwise.
Are there any complications that I'm missing?
So that queue could be used to steer management traffic, but it would still attempt to perform a dev_queue_xmit() using the master DSA network device unless you somehow change that and/or parent that queue to a different network device that the sja1105 switch driver creates (which is doable).
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [RFC PATCH net-next 10/13] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 49 lines · Florian Fainelli
Quoted 41 lines · Vladimir Oltean
Quoted 30 lines · Florian Fainelli
Quoted 27 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination on switch ports only works when not under a
vlan_filteringbridge. We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame. So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Quoted 9 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>I do like the idea of setting up specific management queue later on, although it is not clear to me how you would go about integrating it as a network device, given the DSA slave and master devices, do you know roughly how you would proceed?
Quoted 6 lines
Actually I was thinking about leveraging the multiqueue support that you added in
55199df6d2af("net: dsa: Allow switch drivers to indicate number of TX queues") and expose the slave netdev .ndo_select_queue callback towards DSA ports. There I would return queue #0 ifsja1105_is_link_local(skb), and queue #1 otherwise.
Are there any complications that I'm missing?
Quoted 6 lines
So that queue could be used to steer management traffic, but it would still attempt to perform a
dev_queue_xmit()using the master DSA network device unless you somehow change that and/or parent that queue to a different network device that the sja1105 switch driver creates (which is doable).
But the problem I'm trying to solve with the management queue is not congestion on the master port or inside the switch, but a problem that I myself have created by putting some skb's in a ring that is finite (and small) in size: the DSA xmit racing with my xmit worker. Congestion management on the switch is a much ampler issue that I don't yet know how to handle. The MACs don't appear to generate pause frames, and the pause frames that they receive are trapped to the CPU as link-local traffic (DMAC 01-80-C2-00-00-01) where they are simply consumed by the master's MAC.
-Vladimir
Re: [RFC PATCH net-next 10/13] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 65 lines · Vladimir Oltean
Quoted 57 lines · Florian Fainelli
Quoted 49 lines · Vladimir Oltean
Quoted 38 lines · Florian Fainelli
Quoted 35 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of
a VLAN trunk configured on the CPU port. Termination on switch ports only works when not under avlan_filteringbridge. We are making use of
the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local. The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two
DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by
default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame. So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a
consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate
netdev queue that I can stop when the skb ring got full and hardware is
busy processing, so that we are not forced to drop traffic.Quoted 9 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>I do like the idea of setting up specific management queue later on, although it is not clear to me how you would go about integrating it as a network device, given the DSA slave and master devices, do you know roughly how you would proceed?
Quoted 6 lines
Actually I was thinking about leveraging the multiqueue support that you added in
55199df6d2af("net: dsa: Allow switch drivers to indicate number of TX queues") and expose the slave netdev .ndo_select_queue callback towards DSA ports. There I would return queue #0 ifsja1105_is_link_local(skb), and queue #1 otherwise.
Are there any complications that I'm missing?Quoted 6 lines
So that queue could be used to steer management traffic, but it would still attempt to perform a
dev_queue_xmit()using the master DSA network device unless you somehow change that and/or parent that queue to a different network device that the sja1105 switch driver creates (which is doable).
Quoted 4 lines
But the problem I'm trying to solve with the management queue is not congestion on the master port or inside the switch, but a problem that I myself have created by putting some skb's in a ring that is finite (and small) in size: the DSA xmit racing with my xmit worker.
Oh I understood that part, which is why I was wondering if it even made sense to make use of a particular queue and the flow control that is offered with that given that this is already quite an ad-hoc solution and what you proposed seems to do the job alright.
Quoted 5 lines
Congestion management on the switch is a much ampler issue that I don't yet know how to handle. The MACs don't appear to generate pause frames, and the pause frames that they receive are trapped to the CPU as link-local traffic (DMAC 01-80-C2-00-00-01) where they are simply consumed by the master's MAC.
Woah, okay :) I suppose this can be made to work if you accept loading your host CPU a little bit and have it perform flow control instead of the switch itself. There is no way to have the switch's internal buffering automatically deal with pause frames?
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 11/13 net: dsa: sja1105: Add support for Spanning Tree Protocol
In reply to Vladimir Oltean--- drivers/net/dsa/sja1105/sja1105_main.c | 108 ++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 9 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +99 -9
@@ -93,8 +93,10 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv) .drpuntag = false,/* Don't retag 802.1p (VID 0) traffic with the pvid */ .retag = false, -/* Enable learning and I/O on user ports by default. */ - .dyn_learn = true, +/* Disable learning and I/O on user ports by default - +* STP will enable it. +*/ + .dyn_learn = false, .egress = false, .ingress = false, .mirrcie = 0,
@@ -125,8 +127,17 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv) mac = table->entries; -for (i =0 ; i <SJA1105_NUM_PORTS ; i++) +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { mac[i] = default_mac; +if (i ==dsa_upstream_port (priv->ds, i)) { +/* STP doesn't get called for CPU port, so we need to +* set the I/O parameters statically. +*/ + mac[i].dyn_learn = true; + mac[i].ingress = true; + mac[i].egress = true; + } + }return 0 ; }
@@ -639,12 +650,14 @@ static int sja1105_get_speed_cfg(unsigned int speed_mbps)* for a specific port. * * @speed_mbps: If 0, leave the speed unchanged, else adapt MAC to PHY speed. -* @enabled: Manage Rx and Tx settings for this port. Overrides the static -* configuration settings. +* @enabled: Manage Rx and Tx settings for this port. If false, overrides the +* settings from the STP state, but not persistently (does not +* overwrite the static MAC info for this port). */ static int sja1105_adjust_port_config (struct sja1105_private *priv,int port,int speed_mbps,bool enabled) { +struct sja1105_mac_config_entry dyn_mac;struct sja1105_xmii_params_entry *mii;struct sja1105_mac_config_entry *mac;struct device *dev = priv->ds->dev;
@@ -677,12 +690,13 @@ static int sja1105_adjust_port_config(struct sja1105_private *priv, int port,* the code common, we'll use the static configuration tables as a * reasonable approximation for both E/T and P/Q/R/S. */ - mac[port].ingress = enabled; - mac[port].egress = enabled; + dyn_mac = mac[port]; + dyn_mac.ingress = enabled && mac[port].ingress; + dyn_mac.egress = enabled && mac[port].egress;/* Write to the dynamic reconfiguration tables */ rc =sja1105_dynamic_config_write (priv,BLK_IDX_MAC_CONFIG , - port, &mac[port], true); + port, &dyn_mac, true);if (rc <0 ) {dev_err (dev,"Failed to write MAC config: %d\n" , rc);return rc;
@@ -932,6 +946,50 @@ static int sja1105_bridge_member(struct dsa_switch *ds, int port, port, &l2_fwd[port], true); } +static void sja1105_bridge_stp_state_set (struct dsa_switch *ds,int port, +u8 state) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_mac_config_entry *mac; + + mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG ].entries; + +switch (state) { +case BR_STATE_DISABLED : +case BR_STATE_BLOCKING : +/* From UM10944 description of DRPDTAG (why put this there?): +* "Management traffic flows to the port regardless of the state +* of the INGRESS flag". So BPDUs are still be allowed to pass. +* At the moment no difference between DISABLED and BLOCKING. +*/ + mac[port].ingress = false; + mac[port].egress = false; + mac[port].dyn_learn = false; +break ; +case BR_STATE_LISTENING : + mac[port].ingress = true; + mac[port].egress = false; + mac[port].dyn_learn = false; +break ; +case BR_STATE_LEARNING : + mac[port].ingress = true; + mac[port].egress = false; + mac[port].dyn_learn = true; +break ; +case BR_STATE_FORWARDING : + mac[port].ingress = true; + mac[port].egress = true; + mac[port].dyn_learn = true; +break ; +default : +dev_err (ds->dev,"invalid STP state: %d\n" , state); +return ; + } + +sja1105_dynamic_config_write (priv,BLK_IDX_MAC_CONFIG , port, + &mac[port], true); +} +static int sja1105_bridge_join (struct dsa_switch *ds,int port,struct net_device *br) {
@@ -944,6 +1002,23 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port,sja1105_bridge_member (ds, port, br, false); } +static u8 sja1105_stp_state_get (struct sja1105_private *priv,int port) +{ +struct sja1105_mac_config_entry *mac; + + mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG ].entries; + +if (!mac[port].ingress && !mac[port].egress && !mac[port].dyn_learn) +return BR_STATE_BLOCKING ; +if (mac[port].ingress && !mac[port].egress && !mac[port].dyn_learn) +return BR_STATE_LISTENING ; +if (mac[port].ingress && !mac[port].egress && mac[port].dyn_learn) +return BR_STATE_LEARNING ; +if (mac[port].ingress && mac[port].egress && mac[port].dyn_learn) +return BR_STATE_FORWARDING ; +return -EINVAL ; +} +/* 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
@@ -954,16 +1029,27 @@ static int sja1105_static_config_reload(struct sja1105_private *priv) {struct sja1105_mac_config_entry *mac;int speed_mbps[SJA1105_NUM_PORTS ]; +u8 stp_state[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. +* sja1105_bridge_stp_state_set 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 ; +if (i ==dsa_upstream_port (priv->ds, i)) { + mac[i].ingress = true; + mac[i].egress = true; + mac[i].dyn_learn = true; + }else { + stp_state[i] =sja1105_stp_state_get (priv, i); + mac[i].ingress = false; + mac[i].egress = false; + mac[i].dyn_learn = false; + } }/* Reset switch and send updated static configuration */
@@ -982,6 +1068,9 @@ static int sja1105_static_config_reload(struct sja1105_private *priv)for (i =0 ; i <SJA1105_NUM_PORTS ; i++) {bool enabled = (speed_mbps[i] !=SJA1105_SPEED_AUTO ); +if (i !=dsa_upstream_port (priv->ds, i)) +sja1105_bridge_stp_state_set (priv->ds, i, stp_state[i]); + rc =sja1105_adjust_port_config (priv, i, speed_mbps[i], enabled);if (rc <0 )
@@ -1375,6 +1464,7 @@ 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_stp_state_set = sja1105_bridge_stp_state_set, .port_vlan_prepare = sja1105_vlan_prepare, .port_vlan_filtering = sja1105_vlan_filtering, .port_vlan_add = sja1105_vlan_add,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRFC PATCH 12/13 Documentation: networking: dsa: Add details about NXP SJA1105 driver
In reply to Vladimir Oltean--- Documentation/networking/dsa/sja1105.txt | 83 ++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 Documentation/networking/dsa/sja1105.txt
Documentation/networking/dsa/sja1105.txt new file +83 -0
@@ -0,0 +1,83 @@ +NXP SJA1105 switch driver +========================= + +The NXP SJA1105 is a family of 6 devices: +* SJA1105E: First generation, no TTEthernet +* SJA1105T: First generation, TTEthernet +* SJA1105P: Second generation, no TTEthernet, no SGMII +* SJA1105Q: Second generation, TTEthernet, no SGMII +* SJA1105R: Second generation, no TTEthernet, SGMII +* SJA1105S: Second generation, TTEthernet, SGMII + +These are SPI-managed automotive switches, with all ports being gigabit +capable, and supporting MII/RMII/RGMII and optionally SGMII on one port. + +The switches do not have an MDIO bus of their own and do not support +in-band autonegotiation, so for proper PHY management, the host's MDIO +bus controller needs to be used. + +Being automotive parts, their configuration interface is geared towards +set-and-forget use, with minimal dynamic interaction at runtime. They +require a static configuration to be composed by software and packed +with CRC and table headers, and sent over SPI. + +The static configuration is composed of several configuration tables. Each +table takes a number of entries. Some configuration tables can be (partially) +reconfigured at runtime, some not. Some tables are mandatory, some not. + +Table | Mandatory | Reconfigurable +-----------------------------+------------------+----------------------------- +Schedule | no | no +Schedule entry points | if Scheduling | no +VL Lookup | no | no +VL Policing | if VL Lookup | no +VL Forwarding | if VL Lookup | no +L2 Lookup | no | no +L2 Policing | yes | no +VLAN Lookup | yes | yes +L2 Forwarding | yes | partially (fully on P/Q/R/S) +MAC Config | yes | partially (fully on P/Q/R/S) +Schedule Params | if Scheduling | no +Schedule Entry Points Params | if Scheduling | no +VL Forwarding Params | if VL Forwarding | no +L2 Lookup Params | no | partially (fully on P/Q/R/S) +L2 Forwarding Params | yes | no +Clock Sync Params | no | no +AVB Params | no | no +General Params | yes | partially +Retagging | no | yes +xMII Params | yes | no +SGMII | no | yes + +Also the configuration is write-only (software cannot read it back from the +switch except for very few exceptions). + +So the driver creates the static configuration at probe time, and keeps it at +all times in memory, as a shadow for the hardware state. When required to +change a hardware setting, the static configuration is also updated. +If that changed setting can be transmitted to the switch through the dynamic +reconfiguration interface, it is; otherwise the switch is reset and +reprogrammed with the updated static configuration. + +The switches do not support switch tagging in hardware. But they do support +customizing the TPID by which VLAN traffic is identified as such. The switch +driver is leveraging CONFIG_NET_DSA_TAG_8021Q by requesting that special VLANs +(with a custom TPID of ETH_P_EDSA instead of ETH_P_8021Q) are installed on its +ports when not in vlan_filtering mode. This does not interfere with the +reception and transmission of real 802.1Q-tagged traffic, because the switch +does no longer parse those packets as VLAN after the TPID change. +The TPID is restored when vlan_filtering is requested, and IP termination +becomes no longer possible through the switch netdevices in this mode. + +The switches have two programmable filters for link-local destination MACs. +These are used to trap BPDUs and PTP traffic to the master netdevice, and are +further used to support STP and 1588 ordinary clock/boundary clock +functionality. + +Among other notable features, the switches have a PTP Hardware Clock that can +be steered through SPI and used for timestamping on ingress and egress. +Also, the T, Q and S devices support TTEthernet (an implementation of +SAE AS6802 from TTTech), which is a set of Ethernet QoS enhancements similar in +behavior to IEEE TSN. Configuring these features is currently not supported in +the driver. +
Signature · 1 line
2.17.1
Re: [RFC PATCH net-next 12/13] Documentation: networking: dsa: Add details about NXP SJA1105 driver
Quoted 1 line · Vladimir Oltean
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerRFC PATCH 13/13 dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
In reply to Vladimir Oltean--- .../devicetree/bindings/net/dsa/sja1105.txt | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt
Documentation/devicetree/bindings/net/dsa/sja1105.txt new file +123 -0
@@ -0,0 +1,123 @@ +NXP SJA1105 switch driver +========================= + +Required properties: + +- compatible: Must be "nxp,sja1105". Device ID identification (one of + E/T/P/Q/R/S) is performed by driver at probe time. Swapping pin-compatible + parts is possible with no DTS change. + +Optional properties: + +- sja1105,mac-mode, sja1105,phy-mode: Boolean properties that can be assigned + under each port node that is MII or RMII (has no effect for RGMII). 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). These properties + are required in the case where SJA1105 ports are at both ends of an MII/RMII + PHY-less setup. One end would need to have sja1105,mac-mode, while the other + sja1105,phy-mode. + +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 eth0: + +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,sja1105"; + 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"; + reg = <0>; + /* Implicit "sja1105,mac-mode;" */ + }; + port@1 { + /* ETH2 written on chassis */ + label = "swp2"; + phy-handle = <&rgmii_phy3>; + phy-mode = "rgmii"; + reg = <1>; + /* Implicit "sja1105,mac-mode;" */ + }; + port@2 { + /* ETH3 written on chassis */ + label = "swp3"; + phy-handle = <&rgmii_phy4>; + phy-mode = "rgmii"; + reg = <2>; + /* Implicit "sja1105,mac-mode;" */ + }; + port@3 { + /* ETH4 written on chassis */ + phy-handle = <&rgmii_phy5>; + label = "swp4"; + phy-mode = "rgmii"; + reg = <3>; + /* Implicit "sja1105,mac-mode;" */ + }; + port@4 { + /* Internal port connected to eth2 */ + ethernet = <&enet2>; + phy-mode = "rgmii"; + reg = <4>; + /* Implicit "sja1105,phy-mode;" */ + 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
Re: [RFC PATCH net-next 13/13] dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
Quoted 21 lines · Vladimir Oltean
Signed-off-by Vladimir Oltean <[email protected]>--- .../devicetree/bindings/net/dsa/sja1105.txt | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txtDocumentation/devicetree/bindings/net/dsa/sja1105.txt new file +9
-0@@ -0,0 +1,123 @@ +NXP SJA1105 switch driver +========================= + +Required properties: + +- compatible: Must be "nxp,sja1105". Device ID identification (one of + E/T/P/Q/R/S) is performed by driver at probe time. Swapping pin-compatible + parts is possible with no DTS change. +
Documentation/devicetree/bindings/net/dsa/sja1105.txt line 19
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/sja1105.txt new file +10
-0+Optional properties: + +- sja1105,mac-mode, sja1105,phy-mode: Boolean properties that can be assigned + under each port node that is MII or RMII (has no effect for RGMII). 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). These properties + are required in the case where SJA1105 ports are at both ends of an MII/RMII + PHY-less setup. One end would need to have sja1105,mac-mode, while the other + sja1105,phy-mode.
Typically we would be using a fixed-link with an appropriate 'phy-mode' property to describe a MAC to MAC connection, this may be seen as a re-purposing PHY-oriented properties though, so I am fine with that binding:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [RFC PATCH net-next 13/13] dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
Quoted 39 lines · Florian Fainelli
Quoted 21 lines · Vladimir Oltean
Signed-off-by Vladimir Oltean <[email protected]>--- .../devicetree/bindings/net/dsa/sja1105.txt | 123 ++++++++++++++++++ 1 file changed, 123 insertions(+)create mode 100644
Documentation/devicetree/bindings/net/dsa/sja1105.txtDocumentation/devicetree/bindings/net/dsa/sja1105.txt new file +9
-0@@ -0,0 +1,123 @@ +NXP SJA1105 switch driver +========================= + +Required properties: + +- compatible: Must be "nxp,sja1105". Device ID identification (one of + E/T/P/Q/R/S) is performed by driver at probe time. Swapping pin-compatible + parts is possible with no DTS change. +Documentation/devicetree/bindings/net/dsa/sja1105.txt line 19
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/sja1105.txt new file +10
-0+Optional properties: + +- sja1105,mac-mode, sja1105,phy-mode: Boolean properties that can be assigned + under each port node that is MII or RMII (has no effect for RGMII). 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). These properties + are required in the case where SJA1105 ports are at both ends of an MII/RMII + PHY-less setup. One end would need to have sja1105,mac-mode, while the other + sja1105,phy-mode.Typically we would be using a fixed-link with an appropriate 'phy-mode' property to describe a MAC to MAC connection, this may be seen as a re-purposing PHY-oriented properties though, so I am fine with that binding:
Quoted 2 lines
Reviewed-by Florian Fainelli <[email protected]>
Hi Florian,
I don't feel amazing about my solution either, but I don't think I'm understanding what you propose. Something like phy-mode = "rmii-mac" or "rmii-phy" or "mii-mac" or "mii-phy"?
Would that require an update of the phy_modes() function and strings?
I think the last time when an interface type was split into further subdivisions (RGMII with all its internal delay flavors) it didn't go too well - with lots of bugs introduced simply because drivers failed to grok the newly introduced subtypes as still being RGMII.
Thank you,
-Vladimir
Quoted 26 lines · Vladimir Oltean
This patchset adds a DSA driver for the SPI-managed NXP SJA1105 driver. 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.
Then several small modifications are done to the DSA core, like changing the order of two calls during initialization, or permitting driver access to the
dp->vlan_filteringproperty.These small modifications are done for the greater goal of adding support for 802.1Q pseudo-switch tagging. The limitations of this type of tagging are discussed in the commit that adds it, and in the code comments.
The SJA1105 driver then proceeds to extend this 8021q switch tagging protocol while adding its own (
tag_sja1105). This is done because SJA1105 needs SPI intervention during transmission of link-local traffic, which cannot be done from the xmit handler but requires a deferred worker thread.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.
Quoted 6 lines
TODO items:
* 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 what the current state of tc-taprio hw offload is, and attempt to configure the switch's time-aware scheduler using that.
Overall this is a very clean and impressive piece of work, especially given the constraints you have to work with, I will follow-up with comments in individual patches thanks Vladimir!
Quoted 70 lines
Vladimir Oltean (13):
lib: Add support for generic packing operations
net: dsa: Storevlan_filteringas a property ofdsa_port
net: dsa: Create a more convenient function for installing port VLANs
net: dsa: Call driver's setup callback after setting up its switchdev
notifier
net: dsa: Optional VLAN-based port separation for switches without
tagging
net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
net: dsa: sja1105: Add support for FDB and MDB management
net: dsa: sja1105: Add support for VLAN operations
net: dsa: sja1105: Add support for ethtool port counters
net: dsa: sja1105: Add support for traffic through standalone ports
net: dsa: sja1105: Add support for Spanning Tree Protocol
Documentation: networking: dsa: Add details about NXP SJA1105 driver
dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver.../devicetree/bindings/net/dsa/sja1105.txt | 123 ++ Documentation/networking/dsa/sja1105.txt | 83 + Documentation/packing.txt | 150 ++ MAINTAINERS | 14 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 17 + drivers/net/dsa/sja1105/Makefile | 10 + drivers/net/dsa/sja1105/sja1105.h | 148 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 677 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 607 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 40 + drivers/net/dsa/sja1105/sja1105_ethtool.c | 420 ++++ drivers/net/dsa/sja1105/sja1105_main.c | 1580 ++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 667 ++++++ .../net/dsa/sja1105/sja1105_static_config.c | 1810 +++++++++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 500 +++++ include/linux/dsa/sja1105.h | 52 + include/linux/packing.h | 49 + include/net/dsa.h | 6 + lib/Makefile | 2 +- lib/packing.c | 211 ++ net/dsa/Kconfig | 12 + net/dsa/Makefile | 2 + net/dsa/dsa.c | 6 + net/dsa/dsa2.c | 8 +- net/dsa/dsa_priv.h | 15 + net/dsa/port.c | 36 +- net/dsa/slave.c | 16 +- net/dsa/tag_8021q.c | 185 ++ net/dsa/tag_sja1105.c | 142 ++ 31 files changed, 7568 insertions(+), 23 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt create mode 100644 Documentation/networking/dsa/sja1105.txt 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 create mode 100644 net/dsa/tag_8021q.c create mode 100644 net/dsa/tag_sja1105.c
Signature · 1 line
Florian
Hi Vladmir,
Quoted 26 lines · Vladimir Oltean
This patchset adds a DSA driver for the SPI-managed NXP SJA1105 driver. 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.
Then several small modifications are done to the DSA core, like changing the order of two calls during initialization, or permitting driver access to the
dp->vlan_filteringproperty.These small modifications are done for the greater goal of adding support for 802.1Q pseudo-switch tagging. The limitations of this type of tagging are discussed in the commit that adds it, and in the code comments.
The SJA1105 driver then proceeds to extend this 8021q switch tagging protocol while adding its own (
tag_sja1105). This is done because SJA1105 needs SPI intervention during transmission of link-local traffic, which cannot be done from the xmit handler but requires a deferred worker thread.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.
Quoted 6 lines
TODO items:
* 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 what the current state of tc-taprio hw offload is, and attempt to configure the switch's time-aware scheduler using that.
At this point, there's no support for hw offloading in taprio. I am planning on sending an RFC suggesting a interface soon (this week, I hope). That RFC should at least be useful to get this conversation started.
By the way, Is there a publicly available datasheet I can take a look?
Cheers,
--
Vinicius
Vladimir Oltean
maintainerQuoted 43 lines · Vinicius Costa Gomes
Hi Vladmir,
Quoted 26 lines · Vladimir Oltean
This patchset adds a DSA driver for the SPI-managed NXP SJA1105 driver. 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.
Then several small modifications are done to the DSA core, like changing the order of two calls during initialization, or permitting driver access to the
dp->vlan_filteringproperty.These small modifications are done for the greater goal of adding support for 802.1Q pseudo-switch tagging. The limitations of this type of tagging are discussed in the commit that adds it, and in the code comments.
The SJA1105 driver then proceeds to extend this 8021q switch tagging protocol while adding its own (
tag_sja1105). This is done because SJA1105 needs SPI intervention during transmission of link-local traffic, which cannot be done from the xmit handler but requires a deferred worker thread.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.
Quoted 6 lines
TODO items:
* 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 what the current state of tc-taprio hw offload is, and attempt to configure the switch's time-aware scheduler using that.At this point, there's no support for hw offloading in taprio. I am planning on sending an RFC suggesting a interface soon (this week, I hope). That RFC should at least be useful to get this conversation started.
Quoted 6 lines
By the way, Is there a publicly available datasheet I can take a look?
Cheers,
--
Vinicius
Hi Vinicius,
I knew you'd appear at some point since I mentioned tc-taprio offload :) The documentation for the 1st generation SJA1105 switches is at
https://www.nxp.com/docs/en/user-guide/UM10944.pdf (for the 2nd generation it is not publicly available, but for the most part it's the same IP).
It's not a perfect match with 802.1Qbv and there are some (perhaps workable) limitations, but it does offer the concept of scheduled transmission (8 gated traffic classes per port) based on a PTP clock. Do send your RFC and feel free to ignore the SJA1105 implementation for now, since it would probably only cause endless confusion anyway. :)
I myself am a bit conflicted about how traffic would be scheduled in-band with the hardware Qbv window (PHC time domain) but that is more a question about software architecture rather than hardware details, so I'm really eager to see your proposal.
Thanks!
-Vladimir