NXP SJA1105 DSA driver
Subsystems (11)
Vladimir Oltean
maintainerv2 cover NXP SJA1105 DSA driver
This patchset adds a DSA driver for the SPI-managed NXP SJA1105 switch. Due to the hardware's unfriendliness, most of its state needs to be shadowed in kernel memory by the driver. To support this and keep a decent amount of cleanliness in the code, a new generic API for converting between CPU-accessible ("unpacked") structures and hardware-accessible ("packed") structures is proposed and used.
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 how the tc-taprio hardware offload that was just proposed by Vinicius can be used to configure the switch's time-aware scheduler.
* Rework link state callbacks to use phylink once the SGMII port is supported.
Changes in v2:
1. Device ID is no longer auto-detected but enforced based on explicit DT compatible string. This helps with stricter checking of DT bindings.
2. Group all device-specific operations into a sja1105_info structure and avoid using the IS_ET() and IS_PQRS() macros at runtime as much as possible.
3. Added more verbiage to commit messages and documentation.
4. Treat the case where RGMII internal delays are requested through DT bindings and return error.
5. Miscellaneous cosmetic cleanup in sja1105_clocking.c
6. Not advertising link features that are not supported, such as pause frames and the half duplex modes.
7. Fixed a mistake in previous patchset where the switch tagging was not actually enabled (lost during a rebase). This brought up another uncaught issue where switching at runtime between tagging and no-tagging was not supported by DSA. Fixed up the mistake in "net: dsa: sja1105: Add support for traffic through standalone ports", and added the new patch "net: dsa:
Allow drivers to modulate between presence and absence of tagging" to address the other issue.
8. Added a workaround for switch resets cutting a frame in the middle of transmission, which would throw off some link partners.
9. Changed the TPID from ETH_P_EDSA (0xDADA) to a newly introduced one:
ETH_P_DSA_8021Q (0xDADB). Uncovered another mistake in the previous patchset with a missing ntohs(), which was not caught because 0xDADA is endian-agnostic.
10. Made NET_DSA_TAG_8021Q select VLAN_8021Q
11. Renamed __dsa_port_vlan_add to dsa_port_vid_add and not to dsa_port_vlan_add_trans, as suggested, because the corresponding _del function does not have a transactional phase and the naming is more uniform this way.
v1 patchset can be found at:
https://www.spinics.net/lists/netdev/msg561589.html
Changes from RFC:
1. Removed the packing code for the static configuration tables that were not currently used
2. Removed the code for unpacking a static configuration structure from a memory buffer (not used)
3. Completely removed the SGMII stubs, since the configuration is not complete anyway.
4. Moved some code from the SJA1105 introduction commit into the patch that used it.
5. Made the code for checking global VLAN filtering generic and made b53 driver use it.
6. Made mt7530 driver use the new generic dp->vlan_filtering
7. Fixed check for stringset in .get_sset_count
8. Minor cleanup in sja1105_clocking.c
9. Fixed a confusing typo in DSA
RFC can be found at:
https://www.mail-archive.com/[email protected]/msg291717.html
Vladimir Oltean (22):
lib: Add support for generic packing operations
net: dsa: Fix pharse -> phase typo
net: dsa: Store vlan_filtering as a property of dsa_port
net: dsa: mt7530: Use vlan_filtering property from dsa_port
net: dsa: Add more convenient functions for installing port VLANs
net: dsa: Call driver's setup callback after setting up its switchdev
notifier
ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
net: dsa: Optional VLAN-based port separation for switches without
tagging
net: dsa: Be aware of switches where VLAN filtering is a global
setting
net: dsa: b53: Let DSA handle mismatched VLAN filtering settings
net: dsa: Allow drivers to modulate between presence and absence of
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
net: dsa: sja1105: Error out if RGMII delays are requested in DT
net: dsa: sja1105: Prevent PHY jabbering during switch reset
net: dsa: sja1105: Reject unsupported link modes for AN
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 | 157 ++ Documentation/networking/dsa/sja1105.txt | 153 ++ Documentation/packing.txt | 150 ++ MAINTAINERS | 14 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/b53/b53_common.c | 25 +- drivers/net/dsa/mt7530.c | 14 +- drivers/net/dsa/mt7530.h | 1 - drivers/net/dsa/sja1105/Kconfig | 17 + drivers/net/dsa/sja1105/Makefile | 10 + drivers/net/dsa/sja1105/sja1105.h | 164 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 612 ++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 504 +++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 43 + drivers/net/dsa/sja1105/sja1105_ethtool.c | 414 ++++ drivers/net/dsa/sja1105/sja1105_main.c | 1667 +++++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 594 ++++++ .../net/dsa/sja1105/sja1105_static_config.c | 1042 +++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 305 +++ include/linux/dsa/sja1105.h | 52 + include/linux/packing.h | 49 + include/net/dsa.h | 19 +- include/uapi/linux/if_ether.h | 1 + lib/Makefile | 2 +- lib/packing.c | 211 +++ net/dsa/Kconfig | 13 + net/dsa/Makefile | 2 + net/dsa/dsa.c | 6 + net/dsa/dsa2.c | 15 +- net/dsa/dsa_priv.h | 15 + net/dsa/legacy.c | 7 + net/dsa/port.c | 75 +- net/dsa/slave.c | 16 +- net/dsa/switch.c | 3 +- net/dsa/tag_8021q.c | 203 ++ net/dsa/tag_sja1105.c | 148 ++ 37 files changed, 6673 insertions(+), 53 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
maintainerPATCH v2 1/22 lib: Add support for generic packing operations
This provides an unified API for accessing register bit fields regardless of memory layout. The basic unit of data for these API functions is the u64. The process of transforming an u64 from native CPU encoding into the peripheral's encoding is called 'pack', and transforming it from peripheral to native CPU encoding is 'unpack'.
---
Changes in v2:
None
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
@@ -11671,6 +11671,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
Vladimir Oltean
maintainerPATCH v2 3/22 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.
---
Changes in v2:
None
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
Vladimir Oltean
maintainerPATCH v2 4/22 net: dsa: mt7530: Use vlan_filtering property from dsa_port
In reply to Vladimir OlteanThis field was recently introduced, so keeping state inside the driver is no longer necessary.
---
Changes in v2:
None
drivers/net/dsa/mt7530.c | 14 ++++---------- drivers/net/dsa/mt7530.h | 1 - 2 files changed, 4 insertions(+), 11 deletions(-)
drivers/net/dsa/mt7530.c +4 -10
@@ -828,11 +828,9 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port)mt7530_rmw (priv,MT7530_PVC_P (port),VLAN_ATTR_MASK ,VLAN_ATTR (MT7530_VLAN_TRANSPARENT )); - priv->ports[port].vlan_filtering = false; -for (i =0 ; i <MT7530_NUM_PORTS ; i++) {if (dsa_is_user_port (ds, i) && - priv->ports[i].vlan_filtering) { + ds->ports[i].vlan_filtering) { all_user_ports_removed = false;break ; }
@@ -891,7 +889,7 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port,* And the other port's port matrix cannot be broken when the * other port is still a VLAN-aware port. */ -if (!priv->ports[i].vlan_filtering && +if (!ds->ports[i].vlan_filtering &&dsa_is_user_port (ds, i) && i != port) {if (dsa_to_port (ds, i)->bridge_dev != bridge)continue ;
@@ -1013,10 +1011,6 @@ static int mt7530_port_vlan_filtering(struct dsa_switch *ds, int port, bool vlan_filtering) { - struct mt7530_priv *priv = ds->priv; - - priv->ports[port].vlan_filtering = vlan_filtering; - if (vlan_filtering) {/* The port is being kept as VLAN-unaware port when bridge is * set up with vlan_filtering not being set, Otherwise, the
@@ -1139,7 +1133,7 @@ mt7530_port_vlan_add(struct dsa_switch *ds, int port,/* The port is kept as VLAN-unaware if bridge with vlan_filtering not * being set. */ -if (!priv->ports[port].vlan_filtering) +if (!ds->ports[port].vlan_filtering)return ;mutex_lock (&priv->reg_mutex);
@@ -1170,7 +1164,7 @@ mt7530_port_vlan_del(struct dsa_switch *ds, int port,/* The port is kept as VLAN-unaware if bridge with vlan_filtering not * being set. */ -if (!priv->ports[port].vlan_filtering) +if (!ds->ports[port].vlan_filtering)return 0 ;mutex_lock (&priv->reg_mutex);
drivers/net/dsa/mt7530.h +0 -1
@@ -410,7 +410,6 @@ struct mt7530_port {bool enable;u32 pm;u16 pvid; -bool vlan_filtering; };/* struct mt7530_priv - This is the main data structure for holding the state
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 5/22 net: dsa: Add more convenient functions for installing port VLANs
In reply to Vladimir OlteanThis hides the need to perform a two-phase transaction and construct a switchdev_obj_port_vlan struct.
Call graph (including a function that will be introduced in a follow-up patch) looks like this now (same for the *_vlan_del function):
dsa_slave_vlan_rx_add_vid dsa_port_setup_8021q_tagging
| |
| |
| +-------------+
| |
v v
dsa_port_vid_add dsa_slave_port_obj_add
| |
+-------+ +-------+
| |
v v dsa_port_vlan_add
---
Changes in v2:
Renamed __dsa_port_vlan_add to dsa_port_vid_add and not to dsa_port_vlan_add_trans, as suggested, because the corresponding _del function does not have a transactional phase and the naming is more uniform this way.
net/dsa/dsa_priv.h | 2 ++ net/dsa/port.c | 31 +++++++++++++++++++++++++++++++ net/dsa/slave.c | 16 ++-------------- 3 files changed, 35 insertions(+), 14 deletions(-)
net/dsa/dsa_priv.h +2 -0
@@ -169,6 +169,8 @@ int dsa_port_vlan_add(struct dsa_port *dp, struct switchdev_trans *trans);int dsa_port_vlan_del (struct dsa_port *dp,const struct switchdev_obj_port_vlan *vlan); +int dsa_port_vid_add (struct dsa_port *dp,u16 vid,u16 flags); +int dsa_port_vid_del (struct dsa_port *dp,u16 vid);int dsa_port_link_register_of (struct dsa_port *dp);void dsa_port_link_unregister_of (struct dsa_port *dp);
net/dsa/port.c +31 -0
@@ -326,6 +326,37 @@ int dsa_port_vlan_del(struct dsa_port *dp,return 0 ; } +int dsa_port_vid_add (struct dsa_port *dp,u16 vid,u16 flags) +{ +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; + + 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); +} + +int dsa_port_vid_del (struct dsa_port *dp,u16 vid) +{ +struct switchdev_obj_port_vlan vlan = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .vid_begin = vid, + .vid_end = vid, + }; + +return dsa_port_vlan_del (dp, &vlan); +} +static struct phy_device *dsa_port_get_phy_device (struct dsa_port *dp) {struct device_node *phy_dn;
net/dsa/slave.c +2 -14
@@ -994,13 +994,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;
@@ -1017,13 +1010,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_vid_add (dp, vid,0 ); } static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 7/22 ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
In reply to Vladimir OlteanWith the newly added DSA_TAG_PROTO_8021Q, switch devices that don't support a native insertion/extraction header on the CPU port may still enjoy the benefits of port isolation with a custom VLAN tag.
For this, they need to have a customizable TPID in hardware and a new Ethertype to distinguish between real 802.1Q traffic and the private tags used for port separation.
---
Changes in v2:
New patch.
include/uapi/linux/if_ether.h | 1 + 1 file changed, 1 insertion(+)
include/uapi/linux/if_ether.h +1 -0
@@ -109,6 +109,7 @@#define ETH_P_QINQ2 0x9200/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_QINQ3 0x9300/* deprecated QinQ VLAN [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_EDSA 0xDADA/* Ethertype DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ +#define ETH_P_DSA_8021Q 0xDADB/* Fake VLAN Header for DSA [ NOT AN OFFICIALLY REGISTERED ID ] */ #define ETH_P_IFE 0xED3E/* ForCES inter-FE LFB type */ #define ETH_P_AF_IUCV 0xFBFB/* IBM af_iucv [ NOT AN OFFICIALLY REGISTERED ID ] */
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 15/22 net: dsa: sja1105: Add support for ethtool port counters
In reply to Vladimir Oltean---
Changes in v2:
None functional. Moved the IS_ET() and IS_PQRS() device identification macros here since they are not used in earlier patches.
drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 7 +- drivers/net/dsa/sja1105/sja1105_ethtool.c | 414 ++++++++++++++++++ drivers/net/dsa/sja1105/sja1105_main.c | 3 + .../net/dsa/sja1105/sja1105_static_config.h | 21 + 5 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 drivers/net/dsa/sja1105/sja1105_ethtool.c
drivers/net/dsa/sja1105/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_NET_DSA_SJA1105) += sja1105.o sja1105-objs := \ sja1105_spi.o \ sja1105_main.o \ + sja1105_ethtool.o \ sja1105_clocking.o \ sja1105_static_config.o \ sja1105_dynamic_config.o \
drivers/net/dsa/sja1105/sja1105.h +6 -1
@@ -120,8 +120,13 @@ typedef enum {int sja1105_clocking_setup_port (struct sja1105_private *priv,int port);int sja1105_clocking_setup (struct sja1105_private *priv); -/* From sja1105_dynamic_config.c */ +/* From sja1105_ethtool.c */ +void sja1105_get_ethtool_stats (struct dsa_switch *ds,int port,u64 *data); +void sja1105_get_strings (struct dsa_switch *ds,int port, +u32 stringset,u8 *data); +int sja1105_get_sset_count (struct dsa_switch *ds,int port,int sset); +/* From sja1105_dynamic_config.c */ int sja1105_dynamic_config_read (struct sja1105_private *priv,enum sja1105_blk_idx blk_idx,int index,void *entry);
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +414 -0
414 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c +3 -0
@@ -1242,6 +1242,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,
drivers/net/dsa/sja1105/sja1105_static_config.h +21 -0
@@ -78,6 +78,27 @@ enum sja1105_blk_idx {#define SJA1105R_PART_NO 0x9A86#define SJA1105S_PART_NO 0x9A87 +#define IS_PQRS (device_id) \ + (((device_id) == SJA1105PR_DEVICE_ID) || \ + ((device_id) == SJA1105QS_DEVICE_ID)) +#define IS_ET (device_id) \ + (((device_id) == SJA1105E_DEVICE_ID) || \ + ((device_id) == SJA1105T_DEVICE_ID)) +/* P and R have same Device ID, and differ by Part Number */ +#define IS_P (device_id, part_nr) \ + (((device_id) == SJA1105PR_DEVICE_ID) && \ + ((part_nr) == SJA1105P_PART_NR)) +#define IS_R (device_id, part_nr) \ + (((device_id) == SJA1105PR_DEVICE_ID) && \ + ((part_nr) == SJA1105R_PART_NR)) +/* Same do Q and S */ +#define IS_Q (device_id, part_nr) \ + (((device_id) == SJA1105QS_DEVICE_ID) && \ + ((part_nr) == SJA1105Q_PART_NR)) +#define IS_S (device_id, part_nr) \ + (((device_id) == SJA1105QS_DEVICE_ID) && \ + ((part_nr) == SJA1105S_PART_NR)) +struct sja1105_general_params_entry {u64 vllupformat;u64 mirr_ptacu;
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 20/22 net: dsa: sja1105: Reject unsupported link modes for AN
In reply to Vladimir OlteanEthernet flow control:
The switch MAC does not consume, nor does it emit pause frames. It simply forwards them as any other Ethernet frame (and since the DMAC is, per IEEE spec, 01-80-C2-00-00-01, it means they are filtered as link-local traffic and forwarded to the CPU, which can't do anything useful with them).
Duplex:
There is no duplex setting in the SJA1105 MAC. It is known to forward traffic at line rate on the same port in both directions. Therefore it must be that it only supports full duplex.
---
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105_main.c | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +31 -0
@@ -11,6 +11,7 @@#include <linux/spi/spi.h> #include <linux/errno.h> #include <linux/gpio/consumer.h> +#include <linux/phylink.h> #include <linux/of.h> #include <linux/of_net.h> #include <linux/of_mdio.h>
@@ -747,6 +748,35 @@ static void sja1105_adjust_link(struct dsa_switch *ds, int port,sja1105_adjust_port_config (priv, port, phydev->speed, true); } +static void sja1105_phylink_validate (struct dsa_switch *ds,int port, +unsigned long *supported, +struct phylink_link_state *state) +{ +/* Construct a new mask which exhaustively contains all link features +* supported by the MAC, and then apply that (logical AND) to what will +* be sent to the PHY for "marketing". +*/ +__ETHTOOL_DECLARE_LINK_MODE_MASK (mask) = {0 , }; +struct sja1105_private *priv = ds->priv; +struct sja1105_xmii_params_entry *mii; + + mii = priv->static_config.tables[BLK_IDX_XMII_PARAMS ].entries; + +/* The MAC does not support pause frames, and also doesn't +* support half-duplex traffic modes. +*/ +phylink_set (mask, Autoneg); +phylink_set (mask,MII ); + phylink_set(mask, 10baseT_Full); + phylink_set(mask, 100baseT_Full); +if (mii->xmii_mode[port] ==XMII_MODE_RGMII ) + phylink_set(mask, 1000baseT_Full); + +bitmap_and (supported, supported, mask, __ETHTOOL_LINK_MODE_MASK_NBITS); +bitmap_and (state->advertising, state->advertising, mask, + __ETHTOOL_LINK_MODE_MASK_NBITS); +} +#define fdb (bin, index) \ ((bin) * SJA1105ET_FDB_BIN_SIZE + (index))#define is_bin_index_valid (i) \
@@ -1482,6 +1512,7 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .get_tag_protocol = sja1105_get_tag_protocol, .setup = sja1105_setup, .adjust_link = sja1105_adjust_link, + .phylink_validate = sja1105_phylink_validate, .get_strings = sja1105_get_strings, .get_ethtool_stats = sja1105_get_ethtool_stats, .get_sset_count = sja1105_get_sset_count,
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 21/22 Documentation: networking: dsa: Add details about NXP SJA1105 driver
In reply to Vladimir Oltean---
Changes in v2:
More verbiage at the end, regarding RGMII delays and potentially other hardware-related caveats.
Documentation/networking/dsa/sja1105.txt | 153 +++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 Documentation/networking/dsa/sja1105.txt
Documentation/networking/dsa/sja1105.txt new file +153 -0
@@ -0,0 +1,153 @@ +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 management traffic 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 somewhat +similar in behavior to IEEE TSN (time-aware shaping, time-based policing). +Configuring these features is currently not supported in the driver. + +Heads up for board designers +---------------------------- + +This section references Documentation/devicetree/bindings/net/dsa/sja1105.txt +and aims to show how some switch oddities relate to the DT bindings. + +1. RMII PHY role and out-of-band signaling + +In the RMII spec, the 50 MHz clock signals are either driven by the MAC or by +an external oscillator (but not by the PHY). +But the spec is rather loose and devices go outside it in several ways. +Some PHYs go against the spec and may provide an output pin where they source +the 50 MHz clock themselves, in an attempt to be helpful. +On the other hand, the SJA1105 is only binary configurable - when in the RMII +MAC role it will also attempt to drive the clock signal. To prevent this from +happening it must be put in RMII PHY role. +But doing so has some unintended consequences. +In the RMII spec, the PHY can transmit extra out-of-band signals via RXD[1:0]. +These are practically some extra code words (/J/ and /K/) sent prior to the +preamble of each frame. The MAC does not have this out-of-band signaling +mechanism defined by the RMII spec. +So when the SJA1105 port is put in PHY role to avoid having 2 drivers on the +clock signal, inevitably an RMII PHY-to-PHY connection is created. The SJA1105 +emulates a PHY interface fully and generates the /J/ and /K/ symbols prior to +frame preambles, which the real PHY is not expected to understand. So the PHY +simply encodes the extra symbols received from the SJA1105-as-PHY onto the +100Base-Tx wire. +On the other side of the wire, some link partners might discard these extra +symbols, while others might choke on them and discard the entire Ethernet +frames that follow along. This looks like packet loss with some link partners +but not with others. +The take-away is that in RMII mode, the SJA1105 must be let to drive the +reference clock if connected to a PHY. + +2. RGMII fixed-link and internal delays + +As already mentioned in this document, the second generation of devices has +tunable delay lines as part of the MAC, which can be used to establish the +correct RGMII timing budget. +When powered up, these can shift the Rx and Tx clocks with a phase difference +between 73.8 and 101.7 degrees. +The catch is that the delay lines need to lock onto a clock signal with a +stable frequency. This means that there must be at least 2 microseconds of +silence between the clock at the old vs at the new frequency. Otherwise the +lock is lost and the delay lines must be reset (powered down and back up). +In RGMII the clock frequency changes with link speed (125 MHz at 1000 Mbps, 25 +MHz at 100 Mbps and 2.5 MHz at 10 Mbps), and link speed might change during the +AN process. +In the situation where the switch port is connected through an RGMII fixed-link +to a link partner whose link state life cycle is outside the control of Linux +(such as a different SoC), then the delay lines would remain unlocked (and +inactive) until there is manual intervention (ifdown/ifup on the switch port). +The take-away is that in RGMII mode, the switch's internal delays are only +reliable if the link partner never changes link speeds, or if it does, it does +so in a way that is coordinated with the switch port (practically, both ends of +the fixed-link are under control of the same Linux system). +As to why would a fixed-link interface ever change link speeds: there are +Ethernet controllers out there which come out of reset in 100 Mbps mode, and +their driver inevitably needs to change it if it's required to work at gigabit. + +3. MDIO bus and PHY management + +The SJA1105 does not have an MDIO bus and does not perform in-band AN either. +Therefore there is no link state notification coming from the switch device. +A board would need to hook up the PHYs connected to the switch to any other +MDIO bus available to Linux within the system (e.g. to the DSA master's MDIO +bus). Link state management then works by the driver manually keeping in sync +(over SPI commands) the MAC link speed with the settings negotiated by the PHY. +
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 22/22 dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
In reply to Vladimir Oltean---
Changes in v2:
Renamed sja1105,phy-mode to sja1105,role-phy and similarly for mac. Clarified the switch situation with RGMII delays.
.../devicetree/bindings/net/dsa/sja1105.txt | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt
Documentation/devicetree/bindings/net/dsa/sja1105.txt new file +157 -0
@@ -0,0 +1,157 @@ +NXP SJA1105 switch driver +========================= + +Required properties: + +- compatible: + Must be one of: + - "nxp,sja1105e" + - "nxp,sja1105t" + - "nxp,sja1105p" + - "nxp,sja1105q" + - "nxp,sja1105r" + - "nxp,sja1105s" + + Although the device ID could be detected at runtime, explicit bindings + are required in order to be able to statically check their validity. + For example, SGMII can only be specified on port 4 of R and S devices, + and the non-SGMII devices, while pin-compatible, are not equal in terms + of support for RGMII internal delays (supported on P/Q/R/S, but not on + E/T). + +Optional properties: + +- sja1105,role-mac: +- sja1105,role-phy: + Boolean properties that can be assigned under each port node. By + default (unless otherwise specified) a port is configured as MAC if it + is driving a PHY (phy-handle is present) or as PHY if it is PHY-less + (fixed-link specified, presumably because it is connected to a MAC). + The effect of this property (in either its implicit or explicit form) + is: + - In the case of MII or RMII it specifies whether the SJA1105 port is a + clock source or sink for this interface (not applicable for RGMII + where there is a Tx and an Rx clock). + - In the case of RGMII it affects the behavior regarding internal + delays: + 1. If sja1105,role-mac is specified, and the phy-mode property is one + of "rgmii-id", "rgmii-txid" or "rgmii-rxid", then the entity + designated to apply the delay/clock skew necessary for RGMII + is the PHY. The SJA1105 MAC does not apply any internal delays. + 2. If sja1105,role-phy is specified, and the phy-mode property is one + of the above, the designated entity to apply the internal delays + is the SJA1105 MAC (if hardware-supported). This is only supported + by the second-generation (P/Q/R/S) hardware. On a first-generation + E or T device, it is an error to specify an RGMII phy-mode other + than "rgmii" for a port that is in fixed-link mode. In that case, + the clock skew must either be added by the MAC at the other end of + the fixed-link, or by PCB serpentine traces on the board. + These properties are required, for example, in the case where SJA1105 + ports are at both ends of a MII/RMII PHY-less setup. One end would need + to have sja1105,role-mac, while the other sja1105,role-phy. + +See Documentation/devicetree/bindings/net/dsa/dsa.txt for the list of standard +DSA required and optional properties. + +Other observations +------------------ + +The SJA1105 SPI interface requires a CS-to-CLK time (t2 in UM10944) of at least +one half of t_CLK. At an SPI frequency of 1MHz, this means a minimum +cs_sck_delay of 500ns. Ensuring that this SPI timing requirement is observed +depends on the SPI bus master driver. + +Example +------- + +Ethernet switch connected via SPI to the host, CPU port wired to enet2: + +arch/arm/boot/dts/ls1021a-tsn.dts: + +/* SPI controller of the LS1021 */ +&dspi0 { + sja1105@1 { + reg = <0x1>; + #address-cells = <1>; + #size-cells = <0>; + compatible = "nxp,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,role-mac;" */ + }; + port@1 { + /* ETH2 written on chassis */ + label = "swp2"; + phy-handle = <&rgmii_phy3>; + phy-mode = "rgmii"; + reg = <1>; + /* Implicit "sja1105,role-mac;" */ + }; + port@2 { + /* ETH3 written on chassis */ + label = "swp3"; + phy-handle = <&rgmii_phy4>; + phy-mode = "rgmii"; + reg = <2>; + /* Implicit "sja1105,role-mac;" */ + }; + port@3 { + /* ETH4 written on chassis */ + phy-handle = <&rgmii_phy5>; + label = "swp4"; + phy-mode = "rgmii"; + reg = <3>; + /* Implicit "sja1105,role-mac;" */ + }; + port@4 { + /* Internal port connected to eth2 */ + ethernet = <&enet2>; + phy-mode = "rgmii"; + reg = <4>; + /* Implicit "sja1105,role-phy;" */ + fixed-link { + speed = <1000>; + full-duplex; + }; + }; + }; + }; +}; + +/* MDIO controller of the LS1021 */ +&mdio0 { + /* BCM5464 */ + rgmii_phy3: ethernet-phy@3 { + reg = <0x3>; + }; + rgmii_phy4: ethernet-phy@4 { + reg = <0x4>; + }; + rgmii_phy5: ethernet-phy@5 { + reg = <0x5>; + }; + rgmii_phy6: ethernet-phy@6 { + reg = <0x6>; + }; +}; + +/* Ethernet master port of the LS1021 */ +&enet2 { + phy-connection-type = "rgmii"; + status = "ok"; + fixed-link { + speed = <1000>; + full-duplex; + }; +}; +
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 19/22 net: dsa: sja1105: Prevent PHY jabbering during switch reset
In reply to Vladimir OlteanResetting the switch at runtime is currently done while changing the vlan_filtering setting (due to the required TPID change).
But reset is asynchronous with packet egress, and the switch core will not wait for egress to finish before carrying on with the reset operation.
As a result, a connected PHY such as the BCM5464 would see an unterminated Ethernet frame and start to jabber (repeat the last seen Ethernet symbols - jabber is by definition an oversized Ethernet frame with bad FCS). This behavior is strange in itself, but it also causes the MACs of some link partners (such as the FRDM-LS1012A) to completely lock up.
So as a remedy for this situation, when switch reset is required, simply inhibit Tx on all ports, and wait for the necessary time for the eventual one frame left in the egress queue (not even the Tx inhibit command is instantaneous) to be flushed.
---
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105.h | 1 + drivers/net/dsa/sja1105/sja1105_spi.c | 37 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +1 -0
@@ -33,6 +33,7 @@ struct sja1105_regs {u64 device_id;u64 prod_id;u64 status; +u64 port_control;u64 rgu;u64 config;u64 rmii_pll1;
drivers/net/dsa/sja1105/sja1105_spi.c +37 -0
@@ -10,6 +10,7 @@#define SIZE_SPI_MSG_HEADER 4#define SIZE_SPI_MSG_MAXLEN (64 * 4)#define SPI_TRANSFER_SIZE_MAX (SIZE_SPI_MSG_HEADER + SIZE_SPI_MSG_MAXLEN) +#define SIZE_PORT_CTRL 4static int sja1105_spi_transfer (const struct sja1105_private *priv,const void *tx,void *rx,int size)
@@ -278,6 +279,25 @@ static int sja1105_cold_reset(const struct sja1105_private *priv)return priv->info->reset_cmd (priv, &reset); } +static int sja1105_inhibit_tx (const struct sja1105_private *priv, +const unsigned long *port_bitmap) +{ +const struct sja1105_regs *regs = priv->info->regs; +u64 inhibit_cmd; +int port, rc; + + rc =sja1105_spi_send_int (priv,SPI_READ , regs->port_control, + &inhibit_cmd,SIZE_PORT_CTRL ); +if (rc <0 ) +return rc; + +for_each_set_bit (port, port_bitmap,SJA1105_NUM_PORTS ) + inhibit_cmd |=BIT (port); + +return sja1105_spi_send_int (priv,SPI_WRITE , regs->port_control, + &inhibit_cmd,SIZE_PORT_CTRL ); +} +struct sja1105_status {u64 configs;u64 crcchkl;
@@ -366,6 +386,7 @@ static_config_buf_prepare_for_upload(struct sja1105_private *priv,int sja1105_static_config_upload (struct sja1105_private *priv) {#define RETRIES 10 +unsigned long port_bitmap =GENMASK_ULL (SJA1105_NUM_PORTS -1 ,0 );struct sja1105_static_config *config = &priv->static_config;const struct sja1105_regs *regs = priv->info->regs;struct device *dev = &priv->spidev->dev;
@@ -384,6 +405,20 @@ int sja1105_static_config_upload(struct sja1105_private *priv)dev_err (dev,"Invalid config, cannot upload\n" );return -EINVAL ; } +/* Prevent PHY jabbering during switch reset by inhibiting +* Tx on all ports and waiting for current packet to drain. +* Otherwise, the PHY will see an unterminated Ethernet packet. +*/ + rc =sja1105_inhibit_tx (priv, &port_bitmap); +if (rc <0 ) { +dev_err (dev,"Failed to inhibit Tx on ports\n" ); +return -ENXIO ; + } +/* Wait for an eventual egress packet to finish transmission +* (reach IFG). It is guaranteed that a second one will not +* follow, and that switch cold reset is thus safe +*/ +udelay (1000 ); do { /* Put the SJA1105 in programming mode */ rc = sja1105_cold_reset(priv);
@@ -449,6 +484,7 @@ struct sja1105_regs sja1105et_regs = { .device_id = 0x0, .prod_id = 0x100BC3, .status = 0x1, + .port_control = 0x11, .config = 0x020000, .rgu = 0x100440, .pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808},
@@ -473,6 +509,7 @@ struct sja1105_regs sja1105pqrs_regs = { .device_id = 0x0, .prod_id = 0x100BC3, .status = 0x1, + .port_control = 0x12, .config = 0x020000, .rgu = 0x100440, .pad_mii_tx = {0x100800, 0x100802, 0x100804, 0x100806, 0x100808},
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 11/22 net: dsa: Allow drivers to modulate between presence and absence of tagging
In reply to Vladimir OlteanFrames get processed by DSA and redirected to switch port net devices based on the ETH_P_XDSA multiplexed packet_type handler found by the network stack when calling eth_type_trans().
The running assumption is that once the DSA .rcv function is called, DSA is always able to decode the switch tag in order to change the skb->dev from its master.
However there are tagging protocols (such as the new DSA_TAG_PROTO_SJA1105) where this assumption is not completely true, since switch tagging piggybacks on the absence of a vlan_filtering bridge.
Having DSA receive untagged traffic would put it in an impossible
situation: the eth_type_trans() function would invoke the DSA .rcv(), which could not change skb->dev, then eth_type_trans() would be invoked again, which again would call the DSA .rcv, and the packet would never be able to exit the DSA filter and would spiral in a loop until the whole system dies.
This happens because eth_type_trans() doesn't actually look at the skb (so as to identify a potential tag) when it deems it as being ETH_P_XDSA. It just checks whether skb->dev has a DSA private pointer installed (therefore it's a DSA master) and that there exists a .rcv callback (everybody except DSA_TAG_PROTO_NONE has that). This is understandable as there are many switch tags out there, and exhaustively checking for all of them is far from ideal.
The solution lies in the observation that a more nuanced check can be made when eth_type_trans() determines that switch tagging is used or not. In a way, this reverts patch "717ffbfb28ac net: dsa: remove dsa_uses_tagged_protocol", but instead of adding it back as a DSA function, it is now a boolean property. This is because the driver might actually know better when it can and can't support switch tagging.
With this patch, all tagging protocols can morph at runtime into the DSA_TAG_PROTO_NONE on receive, by setting cpu_dp->uses_tag_protocol = 0. This permits them to at least terminate traffic through the master net device. Their .rcv callback no longer even gets called in this mode.
---
Changes in v2:
Patch is new.
include/net/dsa.h | 8 +++++++- net/dsa/dsa2.c | 7 +++++++ net/dsa/legacy.c | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-)
include/net/dsa.h +7 -1
@@ -156,6 +156,12 @@ struct dsa_port {* Original copy of the master netdev net_device_ops */ const struct net_device_ops *orig_ndo_ops; + +/* Property used to allow traffic at runtime to bypass the DSA +* filter in eth_type_trans and be processed as regular on the +* master net device. +*/ +bool uses_tag_protocol; };struct dsa_switch {
@@ -502,7 +508,7 @@ struct net_device *dsa_dev_to_net_device(struct device *dev);static inline bool netdev_uses_dsa (struct net_device *dev) {#if IS_ENABLED (CONFIG_NET_DSA ) -return dev->dsa_ptr && dev->dsa_ptr->rcv; +return dev->dsa_ptr && dev->dsa_ptr->uses_tag_protocol;#endif return false; }
net/dsa/dsa2.c +7 -0
@@ -585,6 +585,13 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master) dp->tag_ops = tag_ops; dp->master = master; dp->dst = dst; +/* Initially tell DSA to filter all traffic on the master net +* device in eth_type_trans unconditionally if we have a +* packet_type handler (true for all tagging protocols except +* DSA_TAG_PROTO_NONE). Then drivers can later change this +* property. +*/ + dp->uses_tag_protocol = !!dp->rcv;return 0 ; }
net/dsa/legacy.c +7 -0
@@ -161,6 +161,13 @@ static int dsa_switch_setup_one(struct dsa_switch *ds,/* Few copies for faster access in master receive hot path */ dst->cpu_dp->rcv = dst->cpu_dp->tag_ops->rcv; dst->cpu_dp->dst = dst; +/* Initially tell DSA to filter all traffic on the master net +* device in eth_type_trans unconditionally if we have a +* packet_type handler (true for all tagging protocols except +* DSA_TAG_PROTO_NONE). Then drivers can later change this +* property. +*/ + dst->cpu_dp->uses_tag_protocol = !!dst->cpu_dp->rcv; }memcpy (ds->rtable, cd->rtable,sizeof (ds->rtable));
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 18/22 net: dsa: sja1105: Error out if RGMII delays are requested in DT
In reply to Vladimir OlteanDocumentation/devicetree/bindings/net/ethernet.txt is confusing because it says what the MAC should not do, but not what it *should* do:
* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
The gap in semantics is threefold:
1. Is it illegal for the MAC to apply the Rx internal delay by itself, and simplify the phy_mode (mask off "rgmii-rxid" into "rgmii") before passing it to of_phy_connect? The documentation would suggest yes.
1. For "rgmii-rxid", while the situation with the Rx clock skew is more or less clear (needs to be added by the PHY), what should the MAC driver do about the Tx delays? Is it an implicit wild card for the MAC to apply delays in the Tx direction if it can? What if those were already added as serpentine PCB traces, how could that be made more obvious through DT bindings so that the MAC doesn't attempt to add them twice and again potentially break the link?
3. If the interface is a fixed-link and therefore the PHY object is fixed (a purely software entity that obviously cannot add clock skew), what is the meaning of the above property?
So an interpretation of the RGMII bindings was chosen that hopefully does not contradict their intention but also makes them more applied. The SJA1105 driver understands to act upon "rgmii-*id" phy-mode bindings if the port is in the PHY role (either explicitly, or if it is a fixed-link). Otherwise it always passes the duty of setting up delays to the PHY driver.
The error behavior that this patch adds is required on SJA1105E/T where the MAC really cannot apply internal delays. If the other end of the fixed-link cannot apply RGMII delays either (this would be specified through its own DT bindings), then the situation requires PCB delays.
For SJA1105P/Q/R/S, this is however hardware supported and the error is thus only temporary. I created a stub function pointer for configuring delays per-port on RXC and TXC, and will implement it when I have access to a board with this hardware setup.
Meanwhile do not allow the user to select an invalid configuration.
---
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105.h | 3 ++ drivers/net/dsa/sja1105/sja1105_clocking.c | 7 ++++- drivers/net/dsa/sja1105/sja1105_main.c | 32 +++++++++++++++++++++- drivers/net/dsa/sja1105/sja1105_spi.c | 6 ++++ 4 files changed, 46 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105.h +3 -0
@@ -22,6 +22,8 @@struct sja1105_port {struct dsa_port *dp; +bool rgmii_rx_delay; +bool rgmii_tx_delay;struct work_struct xmit_work;struct sja1105_skb_ring xmit_ring; };
@@ -61,6 +63,7 @@ struct sja1105_info {const struct sja1105_table_ops *static_ops;const struct sja1105_regs *regs;int (*reset_cmd)(const void *ctx,const void *data); +int (*setup_rgmii_delay)(const void *ctx,int port,bool rx,bool tx);const char *name; };
drivers/net/dsa/sja1105/sja1105_clocking.c +6 -1
@@ -432,7 +432,12 @@ static int rgmii_clocking_setup(struct sja1105_private *priv, int port)dev_err (dev,"Failed to configure Tx pad registers\n" );return rc; } -return 0 ; +if (!priv->info->setup_rgmii_delay) +return 0 ; + +return priv->info->setup_rgmii_delay (priv, port, + priv->ports[port].rgmii_rx_delay, + priv->ports[port].rgmii_tx_delay); } static int sja1105_cgu_rmii_ref_clk_config(struct sja1105_private *priv,
drivers/net/dsa/sja1105/sja1105_main.c +31 -1
@@ -555,6 +555,21 @@ static int sja1105_static_config_load(struct sja1105_private *priv,return sja1105_static_config_upload (priv); } +static void sja1105_parse_rgmii_delay (const struct sja1105_dt_port *in, +struct sja1105_port *out) +{ +if (in->role ==XMII_MAC ) +return ; + +if (in->phy_mode ==PHY_INTERFACE_MODE_RGMII_RXID || + in->phy_mode ==PHY_INTERFACE_MODE_RGMII_ID ) + out->rgmii_rx_delay = true; + +if (in->phy_mode ==PHY_INTERFACE_MODE_RGMII_TXID || + in->phy_mode ==PHY_INTERFACE_MODE_RGMII_ID ) + out->rgmii_tx_delay = true; +} +static int sja1105_parse_ports_node (struct sja1105_private *priv,struct sja1105_dt_port *ports,struct device_node *ports_node)
@@ -1318,13 +1333,28 @@ static int sja1105_setup(struct dsa_switch *ds) {struct sja1105_dt_port ports[SJA1105_NUM_PORTS ];struct sja1105_private *priv = ds->priv; -int rc; +int rc, i; rc =sja1105_parse_dt (priv, ports);if (rc <0 ) {dev_err (ds->dev,"Failed to parse DT: %d\n" , rc);return rc; } + +/* Error out early if internal delays are required through DT +* and we can't apply them. +*/ +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { +sja1105_parse_rgmii_delay (&ports[i], &priv->ports[i]); + +if ((priv->ports[i].rgmii_rx_delay || + priv->ports[i].rgmii_tx_delay) && + !priv->info->setup_rgmii_delay) { +dev_err (ds->dev,"RGMII delay not supported\n" ); +return -EINVAL ; + } + } +/* Create and send configuration down to device */ rc =sja1105_static_config_load (priv, ports);if (rc <0 ) {
drivers/net/dsa/sja1105/sja1105_spi.c +6 -0
@@ -499,6 +499,7 @@ struct sja1105_info sja1105e_info = { .part_no = SJA1105ET_PART_NO, .static_ops = sja1105e_table_ops, .dyn_ops = sja1105et_dyn_ops, + .setup_rgmii_delay = NULL, .reset_cmd = sja1105et_reset_cmd, .regs = &sja1105et_regs, .name = "SJA1105E",
@@ -508,6 +509,7 @@ struct sja1105_info sja1105t_info = { .part_no = SJA1105ET_PART_NO, .static_ops = sja1105t_table_ops, .dyn_ops = sja1105et_dyn_ops, + .setup_rgmii_delay = NULL, .reset_cmd = sja1105et_reset_cmd, .regs = &sja1105et_regs, .name = "SJA1105T",
@@ -517,6 +519,7 @@ struct sja1105_info sja1105p_info = { .part_no = SJA1105P_PART_NO, .static_ops = sja1105p_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, + .setup_rgmii_delay = NULL, .reset_cmd = sja1105pqrs_reset_cmd, .regs = &sja1105pqrs_regs, .name = "SJA1105P",
@@ -526,6 +529,7 @@ struct sja1105_info sja1105q_info = { .part_no = SJA1105Q_PART_NO, .static_ops = sja1105q_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, + .setup_rgmii_delay = NULL, .reset_cmd = sja1105pqrs_reset_cmd, .regs = &sja1105pqrs_regs, .name = "SJA1105Q",
@@ -535,6 +539,7 @@ struct sja1105_info sja1105r_info = { .part_no = SJA1105R_PART_NO, .static_ops = sja1105r_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, + .setup_rgmii_delay = NULL, .reset_cmd = sja1105pqrs_reset_cmd, .regs = &sja1105pqrs_regs, .name = "SJA1105R",
@@ -545,6 +550,7 @@ struct sja1105_info sja1105s_info = { .static_ops = sja1105s_table_ops, .dyn_ops = sja1105pqrs_dyn_ops, .regs = &sja1105pqrs_regs, + .setup_rgmii_delay = NULL, .reset_cmd = sja1105pqrs_reset_cmd, .name = "SJA1105S", };
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 12/22 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.
---
Changes in v2:
1. Device ID is no longer auto-detected but enforced based on explicit DT compatible string. This helps with stricter checking of DT bindings.
2. Group all device-specific operations into a sja1105_info structure and avoid using the IS_ET() and IS_PQRS() macros at runtime as much as possible.
5. Miscellaneous cosmetic cleanup in sja1105_clocking.c
MAINTAINERS | 6 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 17 + drivers/net/dsa/sja1105/Makefile | 9 + drivers/net/dsa/sja1105/sja1105.h | 145 +++ drivers/net/dsa/sja1105/sja1105_clocking.c | 607 ++++++++++ .../net/dsa/sja1105/sja1105_dynamic_config.c | 464 ++++++++ .../net/dsa/sja1105/sja1105_dynamic_config.h | 43 + drivers/net/dsa/sja1105/sja1105_main.c | 945 ++++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 551 +++++++++ .../net/dsa/sja1105/sja1105_static_config.c | 1004 +++++++++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 281 +++++ 13 files changed, 4075 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
@@ -11118,6 +11118,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 && SPI + 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 +145 -0
145 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_clocking.c new file +607 -0
607 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.c new file +464 -0
464 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_dynamic_config.h new file +43 -0
43 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_main.c new file +945 -0
945 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_spi.c new file +551 -0
551 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.c new file +1004 -0
195 lines not on this page · raw message
drivers/net/dsa/sja1105/sja1105_static_config.h new file +281 -0
281 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
Vladimir Oltean
maintainerPATCH v2 17/22 net: dsa: sja1105: Add support for Spanning Tree Protocol
In reply to Vladimir Oltean---
Changes in v2:
None.
drivers/net/dsa/sja1105/sja1105_main.c | 108 ++++++++++++++++++++++--- 1 file changed, 99 insertions(+), 9 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +99 -9
@@ -94,8 +94,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,
@@ -126,8 +128,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 ; }
@@ -642,12 +653,14 @@ static sja1105_speed_t 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;
@@ -680,12 +693,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;
@@ -943,6 +957,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) {
@@ -955,6 +1013,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
@@ -965,16 +1040,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 */
@@ -993,6 +1079,9 @@ static int sja1105_static_config_reload(struct sja1105_private *priv)for (i =0 ; i <SJA1105_NUM_PORTS ; i++) {bool enabled = (speed_mbps[i] !=0 ); +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 )
@@ -1371,6 +1460,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
maintainerPATCH v2 16/22 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.
---
Changes in v2:
Fixed a mistake with a missing ntohs(), which was not caught because the previously used EtherType (0xDADA) was endian-agnostic.
drivers/net/dsa/sja1105/sja1105.h | 8 ++ drivers/net/dsa/sja1105/sja1105_main.c | 127 ++++++++++++++++++++- 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 | 148 +++++++++++++++++++++++++ 9 files changed, 347 insertions(+), 2 deletions(-) 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 device_id;
@@ -63,6 +70,7 @@ struct sja1105_private {struct gpio_desc *reset_gpio;struct spi_device *spidev;struct dsa_switch *ds; +struct sja1105_port ports[SJA1105_NUM_PORTS ]; };#include "sja1105_dynamic_config.h"
drivers/net/dsa/sja1105/sja1105_main.c +125 -2
163 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
@@ -65,6 +65,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 +148 -0
148 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 14/22 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.
---
Changes from v2:
Changed the TPID from ETH_P_EDSA (0xDADA) to a newly introduced one:ETH_P_DSA_8021Q (0xDADB).
drivers/net/dsa/sja1105/sja1105_main.c | 256 +++++++++++++++++- .../net/dsa/sja1105/sja1105_static_config.c | 38 +++ .../net/dsa/sja1105/sja1105_static_config.h | 3 + 3 files changed, 295 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +254 -2
@@ -261,6 +261,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);
@@ -401,8 +408,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_DSA_8021Q, + .tpid2 = ETH_P_DSA_8021Q,/* P/Q/R/S only */ .queue_ts = 0, .egrmirrvid = 0,
@@ -945,12 +955,241 @@ static void sja1105_bridge_leave(struct dsa_switch *ds, int port,sja1105_bridge_member (ds, port, br, false); } +/* For situations where we need to change a setting at runtime that is only +* available through the static configuration, resetting the switch in order +* to upload the new static config is unavoidable. Back up the settings we +* modify at runtime (currently only MAC) and restore them after uploading, +* such that this operation is relatively seamless. +*/ +static int sja1105_static_config_reload (struct sja1105_private *priv) +{ +struct sja1105_mac_config_entry *mac; +int speed_mbps[SJA1105_NUM_PORTS ]; +int rc, i; + + mac = priv->static_config.tables[BLK_IDX_MAC_CONFIG ].entries; + +/* Back up settings changed by sja1105_adjust_port_config and +* and restore their defaults. +*/ +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { + speed_mbps[i] = sja1105_speed[mac[i].speed]; + mac[i].speed =SJA1105_SPEED_AUTO ; + } + +/* Reset switch and send updated static configuration */ + rc =sja1105_static_config_upload (priv); +if (rc <0 ) + goto out; + +/* Configure the CGU (PLLs) for MII and RMII PHYs. +* For these interfaces there is no dynamic configuration +* needed, since PLLs have same settings at all speeds. +*/ + rc =sja1105_clocking_setup (priv); +if (rc <0 ) + goto out; + +for (i =0 ; i <SJA1105_NUM_PORTS ; i++) { +bool enabled = (speed_mbps[i] !=0 ); + + rc =sja1105_adjust_port_config (priv, i, speed_mbps[i], + enabled); +if (rc <0 ) + goto out; + } +out: +return rc; +} + +#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; + +if (enabled && !sja1105_vlan_filtering_enabled (priv)) +/* Enable VLAN filtering. */ + rc =sja1105_change_tpid (priv,ETH_P_8021Q ,ETH_P_8021AD ); +else if (!enabled &&sja1105_vlan_filtering_enabled (priv)) +/* Disable VLAN filtering. */ + rc =sja1105_change_tpid (priv,ETH_P_DSA_8021Q , +ETH_P_DSA_8021Q ); +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.
@@ -986,6 +1225,15 @@ static int sja1105_setup(struct dsa_switch *ds)dev_err (ds->dev,"Failed to configure MII clocking: %d\n" , rc);return rc; } +/* On SJA1105, VLAN filtering per se is always enabled in hardware. +* The only thing we can do to disable it is lie about what the 802.1Q +* EtherType is. So it will still try to apply VLAN filtering, but all +* ingress traffic (except frames received with EtherType of +* ETH_P_DSA_8021Q) will be internally tagged with a distorted VLAN +* header where the TPID is ETH_P_DSA_8021Q, and the VLAN ID is the +* port pvid. +*/ + ds->vlan_filtering_is_global = true;return 0 ; }
@@ -999,6 +1247,10 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .port_fdb_del = sja1105_fdb_del, .port_bridge_join = sja1105_bridge_join, .port_bridge_leave = sja1105_bridge_leave, + .port_vlan_prepare = sja1105_vlan_prepare, + .port_vlan_filtering = sja1105_vlan_filtering, + .port_vlan_add = sja1105_vlan_add, + .port_vlan_del = sja1105_vlan_del, .port_mdb_prepare = sja1105_mdb_prepare, .port_mdb_add = sja1105_mdb_add, .port_mdb_del = sja1105_mdb_del,
drivers/net/dsa/sja1105/sja1105_static_config.c +38 -0
@@ -1002,3 +1002,41 @@ void sja1105_static_config_free(struct sja1105_static_config *config) } } +int sja1105_table_delete_entry (struct sja1105_table *table,int i) +{ +size_t entry_size = table->ops->unpacked_entry_size; +u8 *entries = table->entries; + +if (i > table->entry_count) +return -ERANGE ; + +memmove (entries + i * entry_size, entries + (i +1 ) * entry_size, + (table->entry_count - i) * entry_size); + + table->entry_count--; + +return 0 ; +} + +/* No pointers to table->entries should be kept when this is called. */ +int sja1105_table_resize (struct sja1105_table *table,size_t new_count) +{ +size_t entry_size = table->ops->unpacked_entry_size; +void *new_entries, *old_entries = table->entries; + +if (new_count > table->ops->max_entry_count) +return -ERANGE ; + + new_entries =kcalloc (new_count, entry_size,GFP_KERNEL ); +if (!new_entries) +return -ENOMEM ; + +memcpy (new_entries, old_entries,min (new_count, table->entry_count) * + entry_size); + + table->entries = new_entries; + table->entry_count = new_count; +kfree (old_entries); +return 0 ; +} +
drivers/net/dsa/sja1105/sja1105_static_config.h +3 -0
@@ -270,6 +270,9 @@ int sja1105_static_config_init(struct sja1105_static_config *config, u64 device_id);void sja1105_static_config_free (struct sja1105_static_config *config); +int sja1105_table_delete_entry (struct sja1105_table *table,int i); +int sja1105_table_resize (struct sja1105_table *table,size_t new_count); +u32 sja1105_crc32 (const void *buf,size_t len);void sja1105_pack (void *buf,const u64 *val,int start,int end,size_t len);
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 13/22 net: dsa: sja1105: Add support for FDB and MDB management
In reply to Vladimir OlteanCurrently only the (more difficult) first generation E/T series is supported. Here the TCAM is only 4-way associative, and to know where the hardware will search for a FDB entry, we need to perform the same hash algorithm in order to install the entry in the correct bin.
On P/Q/R/S, the TCAM should be fully associative. However the SPI command interface is different, and because I don't have access to a new-generation device at the moment, support for it is TODO.
---
Changes from v2:
None
drivers/net/dsa/sja1105/sja1105.h | 2 + .../net/dsa/sja1105/sja1105_dynamic_config.c | 40 ++++ drivers/net/dsa/sja1105/sja1105_main.c | 193 ++++++++++++++++++ 3 files changed, 235 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +2 -0
@@ -129,6 +129,8 @@ int sja1105_dynamic_config_write(struct sja1105_private *priv,enum sja1105_blk_idx blk_idx, int index, void *entry, bool keep); +u8 sja1105_fdb_hash (struct sja1105_private *priv,const u8 *addr,u16 vid); +/* Common implementations for the static and dynamic configs */ size_t sja1105_l2_forwarding_entry_packing (void *buf,void *entry_ptr,enum packing_op op);
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +40 -0
@@ -462,3 +462,43 @@ int sja1105_dynamic_config_write(struct sja1105_private *priv,return 0 ; } + +static u8 crc8_add (u8 crc,u8 byte,u8 poly) +{ +int i; + +for (i =0 ; i <8 ; i++) { +if ((crc ^ byte) & (1 <<7 )) { + crc <<=1 ; + crc ^= poly; + }else { + crc <<=1 ; + } + byte <<=1 ; + } +return crc; +} + +/* CRC8 algorithm with non-reversed input, non-reversed output, +* no input xor and no output xor. Code customized for receiving +* the SJA1105 E/T FDB keys (vlanid, macaddr) as input. CRC polynomial +* is also received as argument in the Koopman notation that the switch +* hardware stores it in. +*/ +u8 sja1105_fdb_hash (struct sja1105_private *priv,const u8 *addr,u16 vid) +{ +struct sja1105_l2_lookup_params_entry *l2_lookup_params = + priv->static_config.tables[BLK_IDX_L2_LOOKUP_PARAMS ].entries; +u64 poly_koopman = l2_lookup_params->poly; +/* Convert polynomial from Koopman to 'normal' notation */ +u8 poly = (u8)(1 + (poly_koopman <<1 )); +u64 vlanid = l2_lookup_params->shared_learn ?0 : vid; +u64 input = (vlanid <<48 ) |ether_addr_to_u64 (addr); +u8 crc =0 ;/* seed */ +int i; + +/* Mask the eight bytes starting from MSB one at a time */ +for (i =56 ; i >=0 ; i -=8 ) + crc =crc8_add (crc, (input & (0xffull << i)) >> i, poly); +return crc; +}
drivers/net/dsa/sja1105/sja1105_main.c +193 -0
213 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 8/22 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. Can be called from another tagging protocol's xmit function. Currently the LAN9303 driver is inserting headers that are simply 802.1Q with custom fields, so this is an opportunity for code reuse.
- 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 (task difficult in itself since the current setting is per-bridge but we would need it per-port), 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 (which would make an O(1) translation impossible), or to a non-unique value within this DSA switch tree (which would make any translation impossible)?
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 VLAN semantics observed by the user.
In the current implementation a VLAN range ending at 4095 (VLAN_N_VID) is reserved for this purpose. Each port receives a unique Rx VLAN and a unique Tx VLAN. Separate VLANs are needed for Rx and Tx because they serve different purposes: on Rx the switch must process traffic as untagged and process it with a port-based VLAN, but with care not to hinder bridging. On the other hand, the Tx VLAN is where the reachability restrictions are imposed, since by tagging frames in the xmit callback we are telling the switch onto which port to steer the frame.
Some general guidance on how this support might be employed for real-life hardware (some comments made by Florian Fainelli):
- If the hardware supports VLAN tag stacking, it should somehow back up its private VLAN settings when the bridge tries to override them. Then the driver could re-apply them as outer tags. Dedicating an outer tag per bridge device would allow identical inner tag VID numbers to co-exist, yet preserve broadcast domain isolation.
- If the switch cannot handle VLAN tag stacking, it should disable this port separation when added as slave to a vlan_filtering bridge, in that case having reduced functionality.
- Drivers for old switches that don't support the entire VLAN_N_VID range will need to rework the current range selection mechanism.
---
Changes in v2:
Made NET_DSA_TAG_8021Q select VLAN_8021Q
More verbiage in commit message
More comments
Adapted to the function name change from 05/22.
include/net/dsa.h | 4 + net/dsa/Kconfig | 10 +++ net/dsa/Makefile | 1 + net/dsa/dsa_priv.h | 10 +++ net/dsa/tag_8021q.c | 203 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 228 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 +10 -0
@@ -27,6 +27,16 @@ config NET_DSA_LEGACY This feature is scheduled for removal in 4.17. # tagging formats +config NET_DSA_TAG_8021Q + select VLAN_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 +203 -0
203 lines not on this page · raw message
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 10/22 net: dsa: b53: Let DSA handle mismatched VLAN filtering settings
In reply to Vladimir OlteanThe DSA core is now able to do this check prior to calling the .port_vlan_filtering callback, so tell it that VLAN filtering is global for this particular hardware.
---
Changes in v2:
None
drivers/net/dsa/b53/b53_common.c | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-)
drivers/net/dsa/b53/b53_common.c +7 -18
@@ -966,6 +966,13 @@ static int b53_setup(struct dsa_switch *ds)b53_disable_port (ds, port); } +/* Let DSA handle the case were multiple bridges span the same switch +* device and different VLAN awareness settings are requested, which +* would be breaking filtering semantics for any of the other bridge +* devices. (not hardware supported) +*/ + ds->vlan_filtering_is_global = true; +return ret; }
@@ -1275,26 +1282,8 @@ EXPORT_SYMBOL(b53_phylink_mac_link_up);int b53_vlan_filtering (struct dsa_switch *ds,int port,bool vlan_filtering) {struct b53_device *dev = ds->priv; -struct net_device *bridge_dev; -unsigned int i;u16 pvid, new_pvid; -/* Handle the case were multiple bridges span the same switch device -* and one of them has a different setting than what is being requested -* which would be breaking filtering semantics for any of the other -* bridge devices. -*/ -b53_for_each_port (dev, i) { - 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) != vlan_filtering) { -netdev_err (bridge_dev, -"VLAN filtering is global to the switch!\n" ); -return -EINVAL ; - } - } -b53_read16 (dev,B53_VLAN_PAGE ,B53_VLAN_PORT_DEF_TAG (port), &pvid); new_pvid = pvid;if (dev->vlan_filtering_enabled && !vlan_filtering) {
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 9/22 net: dsa: Be aware of switches where VLAN filtering is a global setting
In reply to Vladimir OlteanOn some switches, the action of whether to parse VLAN frame headers and use that information for ingress admission is configurable, but not per port. Such is the case for the Broadcom BCM53xx and the NXP SJA1105 families, for example. In that case, DSA can prevent the bridge core from trying to apply different VLAN filtering settings on net devices that belong to the same switch.
---
Changes in v2:
None
include/net/dsa.h | 5 +++++ net/dsa/port.c | 34 ++++++++++++++++++++++++++++++++++ net/dsa/switch.c | 1 + 3 files changed, 40 insertions(+)
include/net/dsa.h +5 -0
@@ -209,6 +209,11 @@ struct dsa_switch {/* Number of switch port queues */ unsigned int num_tx_queues; +/* Disallow bridge core from requesting different VLAN awareness +* settings on ports if not hardware-supported +*/ +bool vlan_filtering_is_global; +unsigned long *bitmap;unsigned long _bitmap;
net/dsa/port.c +34 -0
@@ -154,6 +154,37 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br)dsa_port_set_state_now (dp,BR_STATE_FORWARDING ); } +static bool dsa_port_can_apply_vlan_filtering (struct dsa_port *dp, +bool vlan_filtering) +{ +struct dsa_switch *ds = dp->ds; +int i; + +if (!ds->vlan_filtering_is_global) +return true; + +/* For cases where enabling/disabling VLAN awareness is global to the +* switch, we need to handle the case where multiple bridges span +* different ports of the same switch device and one of them has a +* different setting than what is being requested. +*/ +for (i =0 ; i < ds->num_ports; i++) { +struct net_device *other_bridge; + + other_bridge =dsa_to_port (ds, i)->bridge_dev; +if (!other_bridge) +continue ; +/* If it's the same bridge, it also has same +* vlan_filtering setting => no need to check +*/ +if (other_bridge == dp->bridge_dev) +continue ; +if (br_vlan_enabled (other_bridge) != vlan_filtering) +return false; + } +return true; +} +int dsa_port_vlan_filtering (struct dsa_port *dp,bool vlan_filtering,struct switchdev_trans *trans) {
@@ -165,6 +196,9 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,return 0 ;if (ds->ops->port_vlan_filtering) { +if (!dsa_port_can_apply_vlan_filtering (dp, vlan_filtering)) +return -EINVAL ; + err = ds->ops->port_vlan_filtering (ds, dp->index, vlan_filtering);if (err)
net/dsa/switch.c +1 -0
@@ -10,6 +10,7 @@* (at your option) any later version. */ +#include <linux/if_bridge.h> #include <linux/netdevice.h> #include <linux/notifier.h> #include <linux/if_vlan.h>
Signature · 1 line
2.17.1
Vladimir Oltean
maintainerPATCH v2 6/22 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 switchdev calls. Having the notifiers registered at setup time is important because otherwise any switchdev transaction emitted during this time would be ignored (dispatched to an empty call chain).
One current usage scenario is for the driver to request DSA to set up 802.1Q based switch tagging for its ports.
There is no danger for the driver setup code to start racing now with switchdev events emitted from the network stack (such as bridge core) even if the notifier is registered earlier. This is because the network stack needs a net_device as a vehicle to perform switchdev operations, and the slave net_devices are registered later than the core driver setup anyway (ds->ops->setup in dsa_switch_setup vs dsa_port_setup).
Luckily DSA doesn't need a net_device to carry out switchdev callbacks, and therefore drivers shouldn't assume either that net_devices are available at the time their switchdev callbacks get invoked.
---
Changes in v2:
More verbiage in commit message.
net/dsa/dsa2.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
net/dsa/dsa2.c +4 -4
@@ -366,14 +366,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
Vladimir Oltean
maintainerPATCH v2 2/22 net: dsa: Fix pharse -> phase typo
In reply to Vladimir Oltean---
Changes in v2:
None
net/dsa/switch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
net/dsa/switch.c +1 -1
@@ -196,7 +196,7 @@ static int dsa_port_vlan_check(struct dsa_switch *ds, int port,if (!dp->bridge_dev)return err; -/* dsa_slave_vlan_rx_{add,kill}_vid() cannot use the prepare pharse and +/* dsa_slave_vlan_rx_{add,kill}_vid() cannot use the prepare phase and * already checks whether there is an overlapping bridge VLAN entry * with the same VID, so here we only need to check that if we are * adding a bridge VLAN entry there is not an overlapping VLAN device
Signature · 1 line
2.17.1
Re: [PATCH v2 net-next 02/22] net: dsa: Fix pharse -> phase typo
Quoted 2 lines · Vladimir Oltean
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Andrew Lunn <[email protected]>
Signature · 1 line
Florian
Re: [PATCH v2 net-next 04/22] net: dsa: mt7530: Use vlan_filtering property from dsa_port
In reply to Vladimir OlteanQuoted 6 lines · Vladimir Oltean
This field was recently introduced, so keeping state inside the driver is no longer necessary.
Signed-off-by Vladimir Oltean <[email protected]>Suggested-by Andrew Lunn <[email protected]>Reviewed-by Andrew Lunn <[email protected]>
Signature · 1 line
Florian
Re: [PATCH v2 net-next 05/22] net: dsa: Add more convenient functions for installing port VLANs
In reply to Vladimir OlteanQuoted 17 lines · Vladimir Oltean
This hides the need to perform a two-phase transaction and construct a
switchdev_obj_port_vlanstruct.Call graph (including a function that will be introduced in a follow-up patch) looks like this now (same for the
*_vlan_delfunction):
dsa_slave_vlan_rx_add_viddsa_port_setup_8021q_tagging| | | | | +-------------+ | | v v dsa_port_vid_add dsa_slave_port_obj_add | | +-------+ +-------+ | | v v
Quoted 8 lines
dsa_port_vlan_addSigned-off-by Vladimir Oltean <[email protected]>---
Changes in v2:
Renamed__dsa_port_vlan_addtodsa_port_vid_addand not todsa_port_vlan_add_trans, as suggested, because the corresponding_delfunction does not have a transactional phase and the naming is more uniform this way.
Thanks the name does look a lot better now.
[snip]
net/dsa/port.c int dsa_port_vlan_del(struct dsa_port *dp, · line 355
Quoted 7 lines
net/dsa/port.c +7
-0+int dsa_port_vid_del (struct dsa_port *dp,u16 vid) +{ +struct switchdev_obj_port_vlan vlan = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .vid_begin = vid, + .vid_end = vid, + };
Any reasons why this function does not take a flags argument? Also, did you intend to migrate dsa_slave_vlan_rx_kill_vid() to use this helper for deleting a VLAN ID?
Signature · 1 line
Florian
Re: [PATCH v2 net-next 07/22] ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
In reply to Vladimir OlteanQuoted 9 lines · Vladimir Oltean
With the newly added
DSA_TAG_PROTO_8021Q, switch devices that don't support a native insertion/extraction header on the CPU port may still enjoy the benefits of port isolation with a custom VLAN tag.For this, they need to have a customizable TPID in hardware and a new Ethertype to distinguish between real 802.1Q traffic and the private tags used for port separation.
Signed-off-by Vladimir Oltean <[email protected]>
Why was not using ETH_P_EDSA not suitable? Also how do we intend to use this from user-space? The latest libpcap/tcpdump changes essentially look at the dsa/tagging sysfs attribute for the master network device to determine what type of underlying tagging protocol is used, since you allocated a new one (NET_DSA_TAG_8021Q) you could have added a matching string in sysfs so we can recognize it?
Signature · 1 line
Florian
Re: [PATCH v2 net-next 20/22] net: dsa: sja1105: Reject unsupported link modes for AN
In reply to Vladimir OlteanQuoted 8 lines · Vladimir Oltean
Ethernet flow control:
The switch MAC does not consume, nor does it emit pause frames. It simply forwards them as any other Ethernet frame (and since the DMAC is, per IEEE spec, 01-80-C2-00-00-01, it means they are filtered as link-local traffic and forwarded to the CPU, which can't do anything useful with them).
Quoted 7 lines
Duplex:
There is no duplex setting in the SJA1105 MAC. It is known to forward traffic at line rate on the same port in both directions. Therefore it must be that it only supports full duplex.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Re: [PATCH v2 net-next 18/22] net: dsa: sja1105: Error out if RGMII delays are requested in DT
In reply to Vladimir OlteanQuoted 10 lines · Vladimir Oltean
Documentation/devicetree/bindings/net/ethernet.txtis confusing because it says what the MAC should not do, but not what it *should* do:* "rgmii-rxid" (RGMII with internal RX delay provided by the PHY, the MAC should not add an RX delay in this case)
The gap in semantics is threefold:
1. Is it illegal for the MAC to apply the Rx internal delay by itself, and simplify thephy_mode(mask off "rgmii-rxid" into "rgmii") before passing it toof_phy_connect? The documentation would suggest yes.
I would agree with that statement.
Quoted 7 lines
1. For "rgmii-rxid", while the situation with the Rx clock skew is more or less clear (needs to be added by the PHY), what should the MAC driver do about the Tx delays? Is it an implicit wild card for the MAC to apply delays in the Tx direction if it can? What if those were already added as serpentine PCB traces, how could that be made more obvious through DT bindings so that the MAC doesn't attempt to add them twice and again potentially break the link?
I would say it can be either the MAC adding the TX delay, or the PCB traces doing that, in that case you would have to change the property to "rgmii-id" to account for that. Which is still ambiguous I agree...
Quoted 3 lines
3. If the interface is a fixed-link and therefore the PHY object is fixed (a purely software entity that obviously cannot add clock skew), what is the meaning of the above property?
fixed-link really should denote a MAC to MAC connection so if you have "rgmii-id" on one side, you would expect "rgmii" on the other side (unless PCB traces account for delays, grrr).
Quoted 13 lines
So an interpretation of the RGMII bindings was chosen that hopefully does not contradict their intention but also makes them more applied. The SJA1105 driver understands to act upon "rgmii-*id" phy-mode bindings if the port is in the PHY role (either explicitly, or if it is a fixed-link). Otherwise it always passes the duty of setting up delays to the PHY driver.
The error behavior that this patch adds is required on SJA1105E/T where the MAC really cannot apply internal delays. If the other end of the fixed-link cannot apply RGMII delays either (this would be specified through its own DT bindings), then the situation requires PCB delays.
Quoted 8 lines
For SJA1105P/Q/R/S, this is however hardware supported and the error is thus only temporary. I created a stub function pointer for configuring delays per-port on RXC and TXC, and will implement it when I have access to a board with this hardware setup.
Meanwhile do not allow the user to select an invalid configuration.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Re: [PATCH v2 net-next 11/22] net: dsa: Allow drivers to modulate between presence and absence of tagging
In reply to Vladimir OlteanQuoted 42 lines · Vladimir Oltean
Frames get processed by DSA and redirected to switch port net devices based on the
ETH_P_XDSAmultiplexedpacket_typehandler found by the network stack when callingeth_type_trans().The running assumption is that once the DSA .rcv function is called, DSA is always able to decode the switch tag in order to change the
skb->devfrom its master.However there are tagging protocols (such as the new
DSA_TAG_PROTO_SJA1105) where this assumption is not completely true, since switch tagging piggybacks on the absence of avlan_filteringbridge.Having DSA receive untagged traffic would put it in an impossible
situation: theeth_type_trans()function would invoke the DSA .rcv(), which could not changeskb->dev, theneth_type_trans()would be invoked again, which again would call the DSA .rcv, and the packet would never be able to exit the DSA filter and would spiral in a loop until the whole system dies.This happens because
eth_type_trans()doesn't actually look at the skb (so as to identify a potential tag) when it deems it as beingETH_P_XDSA. It just checks whetherskb->devhas a DSA private pointer installed (therefore it's a DSA master) and that there exists a .rcv callback (everybody exceptDSA_TAG_PROTO_NONEhas that). This is understandable as there are many switch tags out there, and exhaustively checking for all of them is far from ideal.The solution lies in the observation that a more nuanced check can be made when
eth_type_trans()determines that switch tagging is used or not. In a way, this reverts patch "717ffbfb28acnet: dsa: removedsa_uses_tagged_protocol", but instead of adding it back as a DSA function, it is now a boolean property. This is because the driver might actually know better when it can and can't support switch tagging.With this patch, all tagging protocols can morph at runtime into the
DSA_TAG_PROTO_NONEon receive, by settingcpu_dp->uses_tag_protocol= 0. This permits them to at least terminate traffic through the master net device. Their .rcv callback no longer even gets called in this mode.Signed-off-by Vladimir Oltean <[email protected]>---
[snip]
include/net/dsa.h struct dsa_port { · line 164
Quoted 5 lines
include/net/dsa.h +5
-0+/* Property used to allow traffic at runtime to bypass the DSA +* filter in eth_type_trans and be processed as regular on the +* master net device. +*/ +bool uses_tag_protocol;
This gets used in the hot path can you make sure this is part of the first cache line of a dsa_port? pahole is a good tool for determining where a member is in a given structure. With that:
Signature · 1 line
Florian
Vladimir Oltean
maintainerRe: [PATCH v2 net-next 05/22] net: dsa: Add more convenient functions for installing port VLANs
In reply to Florian FainelliQuoted 31 lines · Florian Fainelli
Quoted 17 lines · Vladimir Oltean
This hides the need to perform a two-phase transaction and construct a
switchdev_obj_port_vlanstruct.Call graph (including a function that will be introduced in a follow-up patch) looks like this now (same for the
*_vlan_delfunction):
dsa_slave_vlan_rx_add_viddsa_port_setup_8021q_tagging| | | | | +-------------+ | | v v dsa_port_vid_add dsa_slave_port_obj_add | | +-------+ +-------+ | | v vQuoted 8 lines
dsa_port_vlan_addSigned-off-by Vladimir Oltean <[email protected]>---
Changes in v2:
Renamed__dsa_port_vlan_addtodsa_port_vid_addand not todsa_port_vlan_add_trans, as suggested, because the corresponding_delfunction does not have a transactional phase and the naming is more uniform this way.Thanks the name does look a lot better now.
[snip]
Quoted 12 lines
net/dsa/port.c int dsa_port_vlan_del(struct dsa_port *dp, · line 355
Quoted 7 lines
net/dsa/port.c +7
-0+int dsa_port_vid_del (struct dsa_port *dp,u16 vid) +{ +struct switchdev_obj_port_vlan vlan = { + .obj.id =SWITCHDEV_OBJ_ID_PORT_VLAN , + .vid_begin = vid, + .vid_end = vid, + };Any reasons why this function does not take a flags argument? Also, did you intend to migrate
dsa_slave_vlan_rx_kill_vid()to use this helper for deleting a VLAN ID?
Hi Florian,
I don't think there's any semantics associated to deleting a VLAN with flags. The br_switchdev_port_vlan_del() function doesn't set the flags either.
And as for the dsa_slave_vlan_rx_kill_vid(), it wasn't an oversight, I just thought that the benefits weren't as great as in the case of *_add. I do see that not doing it somewhat breaks the uniformity and makes the commit message slightly inaccurate, so I can fix that up if you think it's necessary.
Thanks,
-Vladimir
Vladimir Oltean
maintainerRe: [PATCH v2 net-next 07/22] ether: Add dedicated Ethertype for pseudo-802.1Q DSA tagging
In reply to Florian FainelliQuoted 9 lines · Florian Fainelli
Quoted 8 lines · Vladimir Oltean
With the newly added
DSA_TAG_PROTO_8021Q, switch devices that don't support a native insertion/extraction header on the CPU port may still enjoy the benefits of port isolation with a custom VLAN tag.For this, they need to have a customizable TPID in hardware and a new Ethertype to distinguish between real 802.1Q traffic and the private tags used for port separation.
Quoted 9 lines
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>Why was not using
ETH_P_EDSAnot suitable? Also how do we intend to use this from user-space? The latest libpcap/tcpdump changes essentially look at the dsa/tagging sysfs attribute for the master network device to determine what type of underlying tagging protocol is used, since you allocated a new one (NET_DSA_TAG_8021Q) you could have added a matching string in sysfs so we can recognize it?
I'll freely admit that I hardly gave a second thoughts to Andrew's previous reply, who said that tcpdump will parse these frames as MEDSA and not much can be done about it.
But thanks for the hint, I was completely unaware of the recent pull requests you guys made for DSA data link types in libpcap. As a pleb I am only using the latest tcpdump/libpcap release tag. I didn't look closely at the pull requests, but you're saying that it's possible to discern based on /sys/class/net/eth2/dsa/tagging (which returns "sja1105") and figure out that it's not MEDSA?
Also remember that NET_DSA_TAG_8021Q in my proposal is not a real tagging protocol and therefore you won't see it in sysfs.
Awaiting some further advice on this, as I have obviously missed out on quite a lot.
Thanks,
-Vladimir
Vladimir Oltean
maintainerRe: [PATCH v2 net-next 11/22] net: dsa: Allow drivers to modulate between presence and absence of tagging
In reply to Florian FainelliQuoted 58 lines · Florian Fainelli
Quoted 42 lines · Vladimir Oltean
Frames get processed by DSA and redirected to switch port net devices based on the
ETH_P_XDSAmultiplexedpacket_typehandler found by the network stack when callingeth_type_trans().The running assumption is that once the DSA .rcv function is called, DSA is always able to decode the switch tag in order to change the
skb->devfrom its master.However there are tagging protocols (such as the new
DSA_TAG_PROTO_SJA1105) where this assumption is not completely true, since switch tagging piggybacks on the absence of avlan_filteringbridge.Having DSA receive untagged traffic would put it in an impossible
situation: theeth_type_trans()function would invoke the DSA .rcv(), which could not changeskb->dev, theneth_type_trans()would be invoked again, which again would call the DSA .rcv, and the packet would never be able to exit the DSA filter and would spiral in a loop until the whole system dies.This happens because
eth_type_trans()doesn't actually look at the skb (so as to identify a potential tag) when it deems it as beingETH_P_XDSA. It just checks whetherskb->devhas a DSA private pointer installed (therefore it's a DSA master) and that there exists a .rcv callback (everybody exceptDSA_TAG_PROTO_NONEhas that). This is understandable as there are many switch tags out there, and exhaustively checking for all of them is far from ideal.The solution lies in the observation that a more nuanced check can be made when
eth_type_trans()determines that switch tagging is used or not. In a way, this reverts patch "717ffbfb28acnet: dsa: removedsa_uses_tagged_protocol", but instead of adding it back as a DSA function, it is now a boolean property. This is because the driver might actually know better when it can and can't support switch tagging.With this patch, all tagging protocols can morph at runtime into the
DSA_TAG_PROTO_NONEon receive, by settingcpu_dp->uses_tag_protocol= 0. This permits them to at least terminate traffic through the master net device. Their .rcv callback no longer even gets called in this mode.Signed-off-by Vladimir Oltean <[email protected]>---
[snip]
include/net/dsa.h struct dsa_port { · line 164
Quoted 5 lines
include/net/dsa.h +5
-0+/* Property used to allow traffic at runtime to bypass the DSA +* filter in eth_type_trans and be processed as regular on the +* master net device. +*/ +bool uses_tag_protocol;This gets used in the hot path can you make sure this is part of the first cache line of a
dsa_port? pahole is a good tool for determining where a member is in a given structure. With that:
Quoted 2 lines
Reviewed-by Florian Fainelli <[email protected]>
Can you give a bit more context about what makes the first cache line special?
Also I am not all that satisfied with my own solution here, maybe you could share a thought? Basically the SJA1105 *can* actually do a very crude form of switch tagging, but only for MAC filtered traffic, and it actually mangles bytes 4 and 5 of the DMAC in the process (sort of 01-80-C2-XX-XX-00). (the irony is that then I can configure it to send me a follow-up "meta frame" where it gives me back the value of my XX-XX bytes it overwrote). So receiving MAC filtered frames can be made to not require the 8021Q switch tagging. But the fundamental problem is that when I set uses_tag_protocol = 0 because I can no longer process 8021Q tags, I inherently break my reception of MAC filtered traffic too. Having to terminate traffic on the master port is not a big deal, but turning the switch back into an unmanaged brick is not that nice, especially since it's an unnecessary loss. Ideally what I would like to have is a way to let DSA (drivers) classify skb's and determine whether they can decode a port from them (individually) or not.
Thanks,
-Vladimir