NXP SJA1105 DSA driver
Subsystems (11)
Vladimir Oltean
maintainerv3 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.
Supporting a fully-featured (traffic-capable) driver for this switch requires some rework in DSA and also leaves behind a more generic infrastructure for other dumb switches that rely on 802.1Q pseudo-switch tagging for port separation. Among the DSA changes required are:
* Permitting the .setup callback to invoke switchdev operations that will loop back into the driver through the switchdev notifier chain.
* Adding DSA awareness of switches where VLAN filtering is a global property and saving that setting in cpu_dp->vlan_filtering.
* Generic xmit and rcv functions for DSA interaction with 802.1Q tags on skb's. This is modeled as a tagging protocol of its own but must be customized by drivers to fit their own hardware possibilities.
* Intervention in the DSA receive hotpath, where a new filtering function called from eth_type_trans() is needed. This is because switches that employ 802.1Q tagging might actually have some limited means of source port decoding, such as only for management traffic. In order for the 802.1Q tagging protocol (which cannot be enabled under all conditions, unlike the management traffic decoding) to not be an all-or-nothing choice, the filtering function matches everything that can be decoded, and everything else is left to pass to the master netdevice.
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 v3:
1. Removed the patch for a dedicated Ethertype to use with 802.1Q DSA tagging
2. Changed the SJA1105 switch tagging protocol sysfs label from "sja1105" to "8021q" to denote to users such as tcpdump that the structure is more generic.
3. Respun previous patch "net: dsa: Allow drivers to modulate between presence and absence of tagging". Current equivalent patch is called "net: dsa: Allow drivers to filter packets they can decode source port from" and at least allows reception of management traffic during the time when switch tagging is not enabled.
4. Added DSA-level fixes for the bridge core not unsetting vlan_filtering when ports leave. The global VLAN filtering is treated as a special case. Made the mt7530 driver use this. This patch benefits the SJA1105 because otherwise traffic in standalone mode would no longer work after removing the ports from a vlan_filtering bridge, since the driver and the hardware would be in an inconsistent state.
5. Restructured the documentation as rst. This depends upon the recently submitted "[PATCH net-next] Documentation: net: dsa: transition to the rst format": https://patchwork.ozlabs.org/patch/1084658/.
v2 patchset can be found at:
https://www.spinics.net/lists/netdev/msg563454.html
Changes in v2:
1. Device ID is no longer auto-detected but enforced based on explicit DT compatible string. This helps with stricter checking of DT bindings.
2. Group all device-specific operations into a sja1105_info structure and avoid using the IS_ET() and IS_PQRS() macros at runtime as much as possible.
3. Added more verbiage to commit messages and documentation.
4. Treat the case where RGMII internal delays are requested through DT bindings and return error.
5. Miscellaneous cosmetic cleanup in sja1105_clocking.c
6. Not advertising link features that are not supported, such as pause frames and the half duplex modes.
7. Fixed a mistake in previous patchset where the switch tagging was not actually enabled (lost during a rebase). This brought up another uncaught issue where switching at runtime between tagging and no-tagging was not supported by DSA. Fixed up the mistake in "net: dsa: sja1105: Add support for traffic through standalone ports", and added the new patch "net: dsa:
Allow drivers to modulate between presence and absence of tagging" to address the other issue.
8. Added a workaround for switch resets cutting a frame in the middle of transmission, which would throw off some link partners.
9. Changed the TPID from ETH_P_EDSA (0xDADA) to a newly introduced one:
ETH_P_DSA_8021Q (0xDADB). Uncovered another mistake in the previous patchset with a missing ntohs(), which was not caught because 0xDADA is endian-agnostic.
10. Made NET_DSA_TAG_8021Q select VLAN_8021Q
11. Renamed __dsa_port_vlan_add to dsa_port_vid_add and not to dsa_port_vlan_add_trans, as suggested, because the corresponding _del function does not have a transactional phase and the naming is more uniform this way.
v1 patchset can be found at:
https://www.spinics.net/lists/netdev/msg561589.html
Changes from RFC:
1. Removed the packing code for the static configuration tables that were not currently used
2. Removed the code for unpacking a static configuration structure from a memory buffer (not used)
3. Completely removed the SGMII stubs, since the configuration is not complete anyway.
4. Moved some code from the SJA1105 introduction commit into the patch that used it.
5. Made the code for checking global VLAN filtering generic and made b53 driver use it.
6. Made mt7530 driver use the new generic dp->vlan_filtering
7. Fixed check for stringset in .get_sset_count
8. Minor cleanup in sja1105_clocking.c
9. Fixed a confusing typo in DSA
RFC can be found at:
https://www.mail-archive.com/[email protected]/msg291717.html
Vladimir Oltean (24):
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
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: Unset vlan_filtering when ports leave the bridge
net: dsa: mt7530: Let DSA handle the unsetting of vlan_filtering
net: dsa: Copy the vlan_filtering setting on the CPU port if it's
global
net: dsa: Allow drivers to filter packets they can decode source port
from
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: net: 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/index.rst | 1 + Documentation/networking/dsa/sja1105.rst | 216 +++ 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 | 18 +- 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 | 1663 +++++++++++++++++ drivers/net/dsa/sja1105/sja1105_spi.c | 594 ++++++ .../net/dsa/sja1105/sja1105_static_config.c | 1042 +++++++++++ .../net/dsa/sja1105/sja1105_static_config.h | 298 +++ include/linux/dsa/sja1105.h | 52 + include/linux/packing.h | 49 + include/net/dsa.h | 26 + lib/Makefile | 2 +- lib/packing.c | 211 +++ net/dsa/Kconfig | 13 + net/dsa/Makefile | 2 + net/dsa/dsa.c | 6 + net/dsa/dsa2.c | 9 +- net/dsa/dsa_priv.h | 15 + net/dsa/legacy.c | 1 + net/dsa/port.c | 87 +- net/dsa/slave.c | 24 +- net/dsa/switch.c | 31 +- net/dsa/tag_8021q.c | 203 ++ net/dsa/tag_sja1105.c | 148 ++ net/ethernet/eth.c | 6 +- 38 files changed, 6769 insertions(+), 62 deletions(-) create mode 100644 Documentation/devicetree/bindings/net/dsa/sja1105.txt create mode 100644 Documentation/networking/dsa/sja1105.rst create mode 100644 Documentation/packing.txt create mode 100644 drivers/net/dsa/sja1105/Kconfig create mode 100644 drivers/net/dsa/sja1105/Makefile create mode 100644 drivers/net/dsa/sja1105/sja1105.h create mode 100644 drivers/net/dsa/sja1105/sja1105_clocking.c create mode 100644 drivers/net/dsa/sja1105/sja1105_dynamic_config.c create mode 100644 drivers/net/dsa/sja1105/sja1105_dynamic_config.h create mode 100644 drivers/net/dsa/sja1105/sja1105_ethtool.c create mode 100644 drivers/net/dsa/sja1105/sja1105_main.c create mode 100644 drivers/net/dsa/sja1105/sja1105_spi.c create mode 100644 drivers/net/dsa/sja1105/sja1105_static_config.c create mode 100644 drivers/net/dsa/sja1105/sja1105_static_config.h create mode 100644 include/linux/dsa/sja1105.h create mode 100644 include/linux/packing.h create mode 100644 lib/packing.c 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 v3 1/24 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 v3:
None
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 v3 2/24 net: dsa: Fix pharse -> phase typo
In reply to Vladimir Oltean---
Changes in v3:
None
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
Vladimir Oltean
maintainerPATCH v3 3/24 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 v3:
None
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
@@ -143,6 +143,7 @@ struct dsa_port {const char *mac;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 v3 4/24 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 v3:
None
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 v3 5/24 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 v3:
Reworked dsa_slave_vlan_rx_kill_vid so that symmetry of the calling graph is kept with the vlan_add functions.
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 | 24 +++--------------------- 3 files changed, 36 insertions(+), 21 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 +3 -21
@@ -1001,13 +1001,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;
@@ -1024,25 +1017,14 @@ 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,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 bridge_vlan_info info;int ret;
@@ -1059,7 +1041,7 @@ static int dsa_slave_vlan_rx_kill_vid(struct net_device *dev, __be16 proto,return -EBUSY ; } - ret =dsa_port_vlan_del (dp, &vlan); + ret =dsa_port_vid_del (dp, vid);if (ret == -EOPNOTSUPP ) ret =0 ;
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 05/24] net: dsa: Add more convenient functions for installing port VLANs
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 v
Quoted 3 lines
dsa_port_vlan_addSigned-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 6/24 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 v3:
None.
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
@@ -369,14 +369,14 @@ static int dsa_switch_setup(struct dsa_switch *ds)if (err)return err; - err = ds->ops->setup (ds); -if (err <0 ) -return err; - err =dsa_switch_register_notifier (ds);if (err)return err; + err = ds->ops->setup (ds); +if (err <0 ) +return err; +if (!ds->slave_mii_bus && ds->ops->phy_read) { ds->slave_mii_bus =devm_mdiobus_alloc (ds->dev);if (!ds->slave_mii_bus)
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 06/24] net: dsa: Call driver's setup callback after setting up its switchdev notifier
Quoted 16 lines · Vladimir Oltean
This 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_deviceas a vehicle to perform switchdev operations, and the slavenet_devicesare registered later than the core driver setup anyway (ds->ops->setupindsa_switch_setupvsdsa_port_setup).
Quoted 3 lines
Luckily DSA doesn't need a
net_deviceto carry out switchdev callbacks, and therefore drivers shouldn't assume either thatnet_devicesare available at the time their switchdev callbacks get invoked.
Hi Vladimir
Thanks for adding this explanation to the commit message.
Andrew
Vladimir Oltean
maintainerPATCH v3 7/24 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 v3:
None.
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
@@ -575,5 +575,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 v3 8/24 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 v3:
Reduced the indentation level by 1 in dsa_port_vlan_filtering().
Changes in v2:
None
include/net/dsa.h | 5 +++++ net/dsa/port.c | 52 ++++++++++++++++++++++++++++++++++++++++------- net/dsa/switch.c | 1 + 3 files changed, 51 insertions(+), 7 deletions(-)
include/net/dsa.h +5 -0
@@ -210,6 +210,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 +45 -7
64 lines not on this page · raw message
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
Re: [PATCH v3 net-next 08/24] net: dsa: Be aware of switches where VLAN filtering is a global setting
Quoted 9 lines · Vladimir Oltean
On 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.
Signed-off-by Vladimir Oltean <[email protected]>Suggested-by Florian Fainelli <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 9/24 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 v3:
None
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
Re: [PATCH v3 net-next 09/24] net: dsa: b53: Let DSA handle mismatched VLAN filtering settings
Quoted 6 lines · Vladimir Oltean
The 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.
Signed-off-by Vladimir Oltean <[email protected]>Suggested-by Florian Fainelli <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 10/24 net: dsa: Unset vlan_filtering when ports leave the bridge
In reply to Vladimir OlteanWhen ports are standalone (after they left the bridge), they should have no VLAN filtering semantics (they should pass all traffic to the CPU). Currently this is not true for switchdev drivers, because the bridge "forgets" to unset that.
Normally one would think that doing this at the bridge layer would be a better idea, i.e. call br_vlan_filter_toggle() from br_del_if(), similar to how nbp_vlan_init() is called from br_add_if().
However what complicates that approach, and makes this one preferable, is the fact that for the bridge core, vlan_filtering is a per-bridge setting, whereas for switchdev/DSA it is per-port. Also there are switches where the setting is per the entire device, and unsetting vlan_filtering one by one, for each leaving port, would not be possible from the bridge core without a certain level of awareness. So do this in DSA and let drivers be unaware of it.
---
Changes in v3:
Patch is new.
net/dsa/switch.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
net/dsa/switch.c +28 -0
@@ -72,6 +72,9 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds,static int dsa_switch_bridge_leave (struct dsa_switch *ds,struct dsa_notifier_bridge_info *info) { +bool unset_vlan_filtering =br_vlan_enabled (info->br); +int err, i; +if (ds->index == info->sw_index && ds->ops->port_bridge_leave) ds->ops->port_bridge_leave (ds, info->port, info->br);
@@ -79,6 +82,31 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, ds->ops->crosschip_bridge_leave (ds, info->sw_index, info->port, info->br); +/* If the bridge was vlan_filtering, the bridge core doesn't trigger an +* event for changing vlan_filtering setting upon slave ports leaving +* it. That is a good thing, because that lets us handle it and also +* handle the case where the switch's vlan_filtering setting is global +* (not per port). When that happens, the correct moment to trigger the +* vlan_filtering callback is only when the last port left this bridge. +*/ +if (unset_vlan_filtering && ds->vlan_filtering_is_global) { +for (i =0 ; i < ds->num_ports; i++) { +if (i == info->port) +continue ; +if (dsa_to_port (ds, i)->bridge_dev == info->br) { + unset_vlan_filtering = false; +break ; + } + } + } +if (unset_vlan_filtering) { +struct switchdev_trans trans = {0 }; + + err =dsa_port_vlan_filtering (&ds->ports[info->port], + false, &trans); +if (err && err !=EOPNOTSUPP ) +return err; + }return 0 ; }
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 10/24] net: dsa: Unset vlan_filtering when ports leave the bridge
Quoted 17 lines · Vladimir Oltean
When ports are standalone (after they left the bridge), they should have no VLAN filtering semantics (they should pass all traffic to the CPU). Currently this is not true for switchdev drivers, because the bridge "forgets" to unset that.
Normally one would think that doing this at the bridge layer would be a better idea, i.e. call
br_vlan_filter_toggle()frombr_del_if(), similar to hownbp_vlan_init()is called frombr_add_if().However what complicates that approach, and makes this one preferable, is the fact that for the bridge core,
vlan_filteringis a per-bridge setting, whereas for switchdev/DSA it is per-port. Also there are switches where the setting is per the entire device, and unsettingvlan_filteringone by one, for each leaving port, would not be possible from the bridge core without a certain level of awareness. So do this in DSA and let drivers be unaware of it.
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>
Andrew
Re: [PATCH v3 net-next 10/24] net: dsa: Unset vlan_filtering when ports leave the bridge
In reply to Vladimir OlteanQuoted 2 lines · Vladimir Oltean
When ports are standalone (after they left the bridge), they should have no VLAN filtering semantics (they should pass all traffic to the CPU).
The reset of the commit message is fine but this particular sentence sort of conflicts with the fact that we set NETIF_F_VLAN_RX_CTAG after my recent changes in order to support standalone ports + bridge ports w/ VLAN filtering on. What this feature flag means is that ingress VLAN filtering is active/supported.
On that particular topic this also means that for things like tcpdump to keep working on standalone ports while we have bridged ports w/ VLAN filtering turned on, we might have to re-configure how the switch performs ingress VLAN filtering checking when we have a standalone port in promiscuous mode. On BCM53xx we can achieve that by having the CPU port be part of all VLANs (there is a shorthand register for that purpose) and doing ingress VID checking + copy violated frames to CPU port. Food for thought...
Quoted 15 lines
Currently this is not true for switchdev drivers, because the bridge "forgets" to unset that.
Normally one would think that doing this at the bridge layer would be a better idea, i.e. call
br_vlan_filter_toggle()frombr_del_if(), similar to hownbp_vlan_init()is called frombr_add_if().However what complicates that approach, and makes this one preferable, is the fact that for the bridge core,
vlan_filteringis a per-bridge setting, whereas for switchdev/DSA it is per-port. Also there are switches where the setting is per the entire device, and unsettingvlan_filteringone by one, for each leaving port, would not be possible from the bridge core without a certain level of awareness. So do this in DSA and let drivers be unaware of it.
Quoted 1 line
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 11/24 net: dsa: mt7530: Let DSA handle the unsetting of vlan_filtering
In reply to Vladimir OlteanThe driver, recognizing that the .port_vlan_filtering callback was never coming after the port left its parent bridge, decided to take that duty in its own hands. DSA now takes care of this condition, so fix that.
---
Changes in v3:
Patch is new.
drivers/net/dsa/mt7530.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/net/dsa/mt7530.c +2 -2
@@ -908,8 +908,6 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port, PCR_MATRIX(BIT(MT7530_CPU_PORT))); priv->ports[port].pm =PCR_MATRIX (BIT (MT7530_CPU_PORT )); -mt7530_port_set_vlan_unaware (ds, port); -mutex_unlock (&priv->reg_mutex); }
@@ -1019,6 +1017,8 @@ mt7530_port_vlan_filtering(struct dsa_switch *ds, int port,*/ mt7530_port_set_vlan_aware (ds, port);mt7530_port_set_vlan_aware (ds,MT7530_CPU_PORT ); + }else { +mt7530_port_set_vlan_unaware (ds, port); }return 0 ;
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 11/24] net: dsa: mt7530: Let DSA handle the unsetting of vlan_filtering
Quoted 5 lines · Vladimir Oltean
The driver, recognizing that the .port_vlan_filtering callback was never coming after the port left its parent bridge, decided to take that duty in its own hands. DSA now takes care of this condition, so fix that.
Signed-off-by Vladimir Oltean <[email protected]>
Andrew
Re: [PATCH v3 net-next 11/24] net: dsa: mt7530: Let DSA handle the unsetting of vlan_filtering
In reply to Vladimir OlteanQuoted 5 lines · Vladimir Oltean
The driver, recognizing that the .port_vlan_filtering callback was never coming after the port left its parent bridge, decided to take that duty in its own hands. DSA now takes care of this condition, so fix that.
Signed-off-by Vladimir Oltean <[email protected]>
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 12/24 net: dsa: Copy the vlan_filtering setting on the CPU port if it's global
In reply to Vladimir OlteanThe current behavior is not as obvious as one would assume (which is that, if the driver set vlan_filtering_is_global = 1, then checking any dp->vlan_filtering would yield the same result). Only the ports which are actively enslaved into a bridge would have vlan_filtering set.
This makes it tricky for drivers to check what the global state is. Moreover, the most obvious place to check for this setting, the CPU port, is not populated since it's not being enslaved to the bridge. So fix this and make the CPU port hold the global state of VLAN filtering on this switch.
---
Changes in v3:
Patch is new.
net/dsa/port.c | 8 ++++++++ 1 file changed, 8 insertions(+)
net/dsa/port.c +8 -0
@@ -190,6 +190,8 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,int dsa_port_vlan_filtering (struct dsa_port *dp,bool vlan_filtering,struct switchdev_trans *trans) { +/* Violate a const pointer here */ +struct dsa_port *cpu_dp = (struct dsa_port *)dp->cpu_dp;struct dsa_switch *ds = dp->ds;int err;
@@ -209,6 +211,12 @@ int dsa_port_vlan_filtering(struct dsa_port *dp, bool vlan_filtering,return err; dp->vlan_filtering = vlan_filtering; +/* In case of switches where VLAN filtering is not per-port, +* also put the setting in the most unambiguous place to +* retrieve it from. +*/ +if (ds->vlan_filtering_is_global) + cpu_dp->vlan_filtering = vlan_filtering;return 0 ; }
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [PATCH v3 net-next 12/24] net: dsa: Copy the vlan_filtering setting on the CPU port if it's global
Quoted 24 lines · Vladimir Oltean
The current behavior is not as obvious as one would assume (which is that, if the driver set
vlan_filtering_is_global= 1, then checking anydp->vlan_filteringwould yield the same result). Only the ports which are actively enslaved into a bridge would havevlan_filteringset.This makes it tricky for drivers to check what the global state is. Moreover, the most obvious place to check for this setting, the CPU port, is not populated since it's not being enslaved to the bridge. So fix this and make the CPU port hold the global state of VLAN filtering on this switch.
Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v3:
Patch is new.net/dsa/port.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/dsa/port.c +0
-0
net/dsa/port.c static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, · line 194
Quoted 5 lines
net/dsa/port.c +2
-0@@ -190,6 +190,8 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,int dsa_port_vlan_filtering (struct dsa_port *dp,bool vlan_filtering,struct switchdev_trans *trans) { +/* Violate a const pointer here */ +struct dsa_port *cpu_dp = (struct dsa_port *)dp->cpu_dp;
Hi Vladimir
As compilers get more picky, i expect that is going to result in a warning.
Since this is a switch global attribute, putting it in dsa_switch would be better, next to vlan_filteris_is_global.
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 12/24] net: dsa: Copy the vlan_filtering setting on the CPU port if it's global
Quoted 34 lines · Andrew Lunn
Quoted 24 lines · Vladimir Oltean
The current behavior is not as obvious as one would assume (which is that, if the driver set
vlan_filtering_is_global= 1, then checking anydp->vlan_filteringwould yield the same result). Only the ports which are actively enslaved into a bridge would havevlan_filteringset.This makes it tricky for drivers to check what the global state is. Moreover, the most obvious place to check for this setting, the CPU port, is not populated since it's not being enslaved to the bridge. So fix this and make the CPU port hold the global state of VLAN filtering on this switch.
Signed-off-by Vladimir Oltean <[email protected]>---
Changes in v3:
Patch is new.net/dsa/port.c | 8 ++++++++ 1 file changed, 8 insertions(+)net/dsa/port.c +0
-0net/dsa/port.c static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, · line 194
Quoted 5 lines
net/dsa/port.c +2
-0@@ -190,6 +190,8 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp,int dsa_port_vlan_filtering (struct dsa_port *dp,bool vlan_filtering,struct switchdev_trans *trans) { +/* Violate a const pointer here */ +struct dsa_port *cpu_dp = (struct dsa_port *)dp->cpu_dp;Hi Vladimir
Quoted 7 lines
As compilers get more picky, i expect that is going to result in a warning.
Since this is a switch global attribute, putting it in
dsa_switchwould be better, next tovlan_filteris_is_global.Andrew
Hi Andrew,
Creating a bool ds->vlan_filtering wouldn't make a lot of sense for the majority of drivers.
Additionally in my sja1105_filter() function, that would require me to pass through one more pointer (dev->dsa_ptr->vlan_filtering vs dev->dsa_ptr->*ds->*vlan_filtering) to reach the same information. I don't think that keeping it in cpu_dp->vlan_filtering has any semantical overlap with anything else that might appear in the future. And I don't know why the cpu_dp pointer is const. In the dsa_switch_tree it isn't.
Thanks,
-Vladimir
Vladimir Oltean
maintainerPATCH v3 13/24 net: dsa: Allow drivers to filter packets they can decode source port from
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, user of DSA_TAG_PROTO_8021Q) where this assumption is not completely true, since switch tagging piggybacks on the absence of a vlan_filtering bridge. Moreover, management traffic (BPDU, PTP) for this switch doesn't rely on switch tagging, but on a different mechanism. So it would make sense to at least be able to terminate that.
Having DSA receive traffic it can't decode 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 introducing a filtering function for each tagging protocol. In the absence of a filtering function, all traffic is passed to the .rcv DSA callback. The tagging protocol should see the filtering function as a pre-validation that it can decode the incoming skb. The traffic that doesn't match the filter will bypass the DSA .rcv callback and be left on the master netdevice, which wasn't previously possible.
---
Changes in v3:
Reworked from a simple boolean (uses_tag_protocol) into a function where the driver has full insight into both the skb as well as the state of the master netdevice (and implicitly the cpu_dp and the entire DSA switch tree).
Changes in v2:
Patch is new.
include/net/dsa.h | 15 +++++++++++++++ net/dsa/dsa2.c | 1 + net/dsa/legacy.c | 1 + net/ethernet/eth.c | 6 +++++- 4 files changed, 22 insertions(+), 1 deletion(-)
include/net/dsa.h +15 -0
@@ -55,6 +55,11 @@ struct dsa_device_ops { struct packet_type *pt);int (*flow_dissect)(const struct sk_buff *skb,__be16 *proto,int *offset); +/* Used to determine which traffic should match the DSA filter in +* eth_type_trans, and which, if any, should bypass it and be processed +* as regular on the master net device. +*/ +bool (*filter)(const struct sk_buff *skb,struct net_device *dev);unsigned int overhead; };
@@ -128,6 +133,7 @@ struct dsa_port {struct dsa_switch_tree *dst;struct sk_buff *(*rcv)(struct sk_buff *skb,struct net_device *dev,struct packet_type *pt); +bool (*filter)(const struct sk_buff *skb,struct net_device *dev);enum {DSA_PORT_TYPE_UNUSED =0 ,
@@ -508,6 +514,15 @@ static inline bool netdev_uses_dsa(struct net_device *dev)return false; } +static inline bool dsa_can_decode (const struct sk_buff *skb, +struct net_device *dev) +{ +#if IS_ENABLED (CONFIG_NET_DSA ) +return !dev->dsa_ptr->filter || dev->dsa_ptr->filter (skb, dev); +#endif +return false; +} +struct dsa_switch *dsa_switch_alloc (struct device *dev,size_t n);void dsa_unregister_switch (struct dsa_switch *ds);int dsa_register_switch (struct dsa_switch *ds);
net/dsa/dsa2.c +1 -0
@@ -584,6 +584,7 @@ static int dsa_port_parse_cpu(struct dsa_port *dp, struct net_device *master) } dp->type =DSA_PORT_TYPE_CPU ; + dp->filter = tag_ops->filter; dp->rcv = tag_ops->rcv; dp->tag_ops = tag_ops; dp->master = master;
net/dsa/legacy.c +1 -0
@@ -159,6 +159,7 @@ static int dsa_switch_setup_one(struct dsa_switch *ds, dst->cpu_dp->tag_ops = tag_ops;/* Few copies for faster access in master receive hot path */ + dst->cpu_dp->filter = dst->cpu_dp->tag_ops->filter; dst->cpu_dp->rcv = dst->cpu_dp->tag_ops->rcv; dst->cpu_dp->dst = dst; }
net/ethernet/eth.c +5 -1
@@ -183,8 +183,12 @@ __be16 eth_type_trans(struct sk_buff *skb, struct net_device *dev)* at all, so we check here whether one of those tagging * variants has been configured on the receiving interface, * and if so, set skb->protocol without looking at the packet. +* The DSA tagging protocol may be able to decode some but not all +* traffic (for example only for management). In that case give it the +* option to filter the packets from which it can decode source port +* information. */ -if (unlikely (netdev_uses_dsa (dev))) +if (unlikely (netdev_uses_dsa (dev)) &&dsa_can_decode (skb, dev))return htons (ETH_P_XDSA );if (likely (eth_proto_is_802_3 (eth->h_proto)))
Signature · 1 line
2.17.1
Andrew Lunn
maintainerRe: [PATCH v3 net-next 13/24] net: dsa: Allow drivers to filter packets they can decode source port from
Quoted 8 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.
Quoted 6 lines
However there are tagging protocols (such as the new
DSA_TAG_PROTO_SJA1105, user ofDSA_TAG_PROTO_8021Q) where this assumption is not completely true, since switch tagging piggybacks on the absence of avlan_filteringbridge. Moreover, management traffic (BPDU, PTP) for this switch doesn't rely on switch tagging, but on a different mechanism. So it would make sense to at least be able to terminate that.
Hi Vladimir
Let me see if i get this correct.
If the filter fails to match, the frame is received on the master interface? So BPDUs and PTT packets are going to go to the master interface?
How does the bridge get these BPDUs, and associated to the correct slave port?
How does the PTP core code get these frames, and associated to the correct slave port?
You say there is a different mechanism to do this. Maybe a later patch i've not yet looked at. But cannot this mechanism be built into the tagger? That is what the tagger is there for, to demultiplex a frame to the correct slave. The current code assume the needed information is in the header, but there is nothing to stop it looking deeper into the packet if needed. So far, we have been reluctant for a tagger to call into the DSA driver, but if need be, it could happen.
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 13/24] net: dsa: Allow drivers to filter packets they can decode source port from
Quoted 39 lines · Andrew Lunn
Quoted 8 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.Quoted 6 lines
However there are tagging protocols (such as the new
DSA_TAG_PROTO_SJA1105, user ofDSA_TAG_PROTO_8021Q) where this assumption is not completely true, since switch tagging piggybacks on the absence of avlan_filteringbridge. Moreover, management traffic (BPDU, PTP) for this switch doesn't rely on switch tagging, but on a different mechanism. So it would make sense to at least be able to terminate that.Hi Vladimir
Let me see if i get this correct.
If the filter fails to match, the frame is received on the master interface? So BPDUs and PTT packets are going to go to the master interface?
How does the bridge get these BPDUs, and associated to the correct slave port?
How does the PTP core code get these frames, and associated to the correct slave port?
You say there is a different mechanism to do this. Maybe a later patch i've not yet looked at. But cannot this mechanism be built into the tagger? That is what the tagger is there for, to demultiplex a frame to the correct slave. The current code assume the needed information is in the header, but there is nothing to stop it looking deeper into the packet if needed. So far, we have been reluctant for a tagger to call into the DSA driver, but if need be, it could happen.
Quoted 1 line
Andrew
Hi Andrew,
Yes it's explained in a further patch. See the checks for sja1105_is_link_local() in patch 18/24.
There's also a table in the documentation patch (23/24).
Thanks,
-Vladimir
Vladimir Oltean
maintainerPATCH v3 14/24 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 v3:
None.
Changes in v2:
1. Device ID is no longer auto-detected but enforced based on explicit DT compatible string. This helps with stricter checking of DT bindings.
2. Group all device-specific operations into a sja1105_info structure and avoid using the IS_ET() and IS_PQRS() macros at runtime as much as possible.
5. Miscellaneous cosmetic cleanup in sja1105_clocking.c
MAINTAINERS | 6 + drivers/net/dsa/Kconfig | 2 + drivers/net/dsa/Makefile | 1 + drivers/net/dsa/sja1105/Kconfig | 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 | 274 +++++ 13 files changed, 4068 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 +274 -0
274 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.
Andrew Lunn
maintainerRe: [PATCH v3 net-next 14/24] net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
Quoted 6 lines · Vladimir Oltean
At 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.
Please could you explain that last sentence in more detail. Normally the master device is just a dumb pipe. Nothing, except tcpdump, uses it.
Thanks
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 14/24] net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
Hi Andrew,
All I'm saying is that at this point in time (patch 14/24), the driver is being introduced with DSA_TAG_PROTO_NONE. Then support for traffic and switch tagging is added later on (18/24). I was just explaining what can be done with the driver up to this point in the patchset.
Thanks,
-Vladimir
Quoted 16 lines · Andrew Lunn
Quoted 6 lines · Vladimir Oltean
At 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.Please could you explain that last sentence in more detail. Normally the master device is just a dumb pipe. Nothing, except tcpdump, uses it.
Thanks
Andrew
Andrew Lunn
maintainerRe: [PATCH v3 net-next 14/24] net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
Quoted 6 lines · Vladimir Oltean
Hi Andrew,
All I'm saying is that at this point in time (patch 14/24), the driver is being introduced with
DSA_TAG_PROTO_NONE. Then support for traffic and switch tagging is added later on (18/24). I was just explaining what can be done with the driver up to this point in the patchset.
O.K. So at this point in time, the driver is unusable. Too much other stuff is missing. So i don't see any point in mentioning this.
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 14/24] net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch
Quoted 9 lines · Andrew Lunn
Quoted 6 lines · Vladimir Oltean
Hi Andrew,
All I'm saying is that at this point in time (patch 14/24), the driver is being introduced with
DSA_TAG_PROTO_NONE. Then support for traffic and switch tagging is added later on (18/24). I was just explaining what can be done with the driver up to this point in the patchset.
Quoted 4 lines
O.K. So at this point in time, the driver is unusable. Too much other stuff is missing. So i don't see any point in mentioning this.
Andrew
At this point the driver sees an unmanaged switch. Whether you consider that unusable or not is debatable.
Thanks,
-Vladimir
Vladimir Oltean
maintainerPATCH v3 15/24 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 v3:
None
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
Re: [PATCH v3 net-next 15/24] net: dsa: sja1105: Add support for FDB and MDB management
Quoted 41 lines · Sat, Apr 13, 2019 at 03:28:13AM CEST, [email protected] wrote:
Currently only the (more difficult) first generation E/T series is supported. Here the TCAM is only 4-way associative, and to know where the hardware will search for a FDB entry, we need to perform the same hash algorithm in order to install the entry in the correct bin.
On P/Q/R/S, the TCAM should be fully associative. However the SPI command interface is different, and because I don't have access to a new-generation device at the moment, support for it is TODO.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes from v3:
NoneChanges from v2:
Nonedrivers/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 +0
-0
drivers/net/dsa/sja1105/sja1105_dynamic_config.c int sja1105_dynamic_config_write(struct sja1105_private *priv, · line 466
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +2
-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)
Prefix please.
Quoted 14 lines
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +14
-0+{ +int i; + +for (i =0 ; i <8 ; i++) { +if ((crc ^ byte) & (1 <<7 )) { + crc <<=1 ; + crc ^= poly; + }else { + crc <<=1 ; + } + byte <<=1 ; + } +return crc; +}
[...]
drivers/net/dsa/sja1105/sja1105_dynamic_config.c
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +4
-0+#define fdb (bin, index) \ + ((bin) * SJA1105ET_FDB_BIN_SIZE + (index)) +#define is_bin_index_valid (i) \ + ((i) >= 0 && (i) < SJA1105ET_FDB_BIN_SIZE)
Please use prefixes and sane names. Also, consider using functions instead of macros.
[...]
drivers/net/dsa/sja1105/sja1105_dynamic_config.c
Quoted 3 lines
drivers/net/dsa/sja1105/sja1105_dynamic_config.c +3
-0+ +#undef fdb +#undef is_bin_index_valid
Odd.
Vladimir Oltean
maintainerPATCH v3 16/24 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 v3:
Changed back to ETH_P_EDSA.
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 | 254 +++++++++++++++++- .../net/dsa/sja1105/sja1105_static_config.c | 38 +++ .../net/dsa/sja1105/sja1105_static_config.h | 3 + 3 files changed, 293 insertions(+), 2 deletions(-)
drivers/net/dsa/sja1105/sja1105_main.c +252 -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_EDSA, + .tpid2 = ETH_P_EDSA,/* P/Q/R/S only */ .queue_ts = 0, .egrmirrvid = 0,
@@ -945,12 +955,240 @@ 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_EDSA ,ETH_P_EDSA ); +else +return 0 ; +if (rc) +dev_err (ds->dev,"Failed to change VLAN Ethertype\n" ); + +return rc; +} + +static void sja1105_vlan_add (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct sja1105_private *priv = ds->priv; +u16 vid; +int rc; + +for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + rc =sja1105_vlan_apply (priv, port, vid, true, vlan->flags & +BRIDGE_VLAN_INFO_UNTAGGED ); +if (rc <0 ) { +dev_err (ds->dev,"Failed to add VLAN %d to port %d: %d\n" , + vid, port, rc); +return ; + } +if (vlan->flags &BRIDGE_VLAN_INFO_PVID ) { + rc =sja1105_pvid_apply (ds->priv, port, vid); +if (rc <0 ) { +dev_err (ds->dev,"Failed to set pvid %d on port %d: %d\n" , + vid, port, rc); +return ; + } + } + } +} + +static int sja1105_vlan_del (struct dsa_switch *ds,int port, +const struct switchdev_obj_port_vlan *vlan) +{ +struct sja1105_private *priv = ds->priv; +u16 vid; +int rc; + +for (vid = vlan->vid_begin; vid <= vlan->vid_end; vid++) { + rc =sja1105_vlan_apply (priv, port, vid, false, vlan->flags & +BRIDGE_VLAN_INFO_UNTAGGED ); +if (rc <0 ) { +dev_err (ds->dev,"Failed to remove VLAN %d from port %d: %d\n" , + vid, port, rc); +return rc; + } + } +return 0 ; +} +/* The programming model for the SJA1105 switch is "all-at-once" via static * configuration tables. Some of these can be dynamically modified at runtime, * but not the xMII mode parameters table.
@@ -986,6 +1224,14 @@ 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_EDSA) will be internally tagged with a distorted VLAN header +* where the TPID is ETH_P_EDSA, and the VLAN ID is the port pvid. +*/ + ds->vlan_filtering_is_global = true;return 0 ; }
@@ -999,6 +1245,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
@@ -263,6 +263,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
Re: [PATCH v3 net-next 16/24] net: dsa: sja1105: Add support for VLAN operations
Quoted 27 lines · Sat, Apr 13, 2019 at 03:28:14AM CEST, [email protected] wrote:
VLAN filtering cannot be properly disabled in SJA1105. So in order to emulate the "no VLAN awareness" behavior (not dropping traffic that is tagged with a VID that isn't configured on the port), we need to hack another switch feature: programmable TPID (which is
0x8100for 802.1Q). We are reprogramming the TPID to a bogus value (ETH_P_EDSA) which leaves the switch thinking that all traffic is untagged, and therefore accepts it.Under a
vlan_filteringbridge, the proper TPID ofETH_P_8021Qis installed again, and the switch starts identifying 802.1Q-tagged traffic.Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes from v3:
Changed back toETH_P_EDSA.Changes from v2:
Changed the TPID fromETH_P_EDSA(0xDADA) to a newly introduced one:ETH_P_DSA_8021Q(0xDADB).drivers/net/dsa/sja1105/sja1105_main.c | 254 +++++++++++++++++- .../net/dsa/sja1105/sja1105_static_config.c | 38 +++ .../net/dsa/sja1105/sja1105_static_config.h | 3 + 3 files changed, 293 insertions(+), 2 deletions(-)
[...]
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_bridge_leave(struct dsa_switch *ds, int port, · line 1008
Quoted 4 lines
drivers/net/dsa/sja1105/sja1105_main.c +4
-0+#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)
This is unreadable. Please have it as function.
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 16/24] net: dsa: sja1105: Add support for VLAN operations
Quoted 33 lines · Jiri Pirko
Quoted 27 lines · Sat, Apr 13, 2019 at 03:28:14AM CEST, [email protected] wrote:
VLAN filtering cannot be properly disabled in SJA1105. So in order to emulate the "no VLAN awareness" behavior (not dropping traffic that is tagged with a VID that isn't configured on the port), we need to hack another switch feature: programmable TPID (which is
0x8100for 802.1Q). We are reprogramming the TPID to a bogus value (ETH_P_EDSA) which leaves the switch thinking that all traffic is untagged, and therefore accepts it.Under a
vlan_filteringbridge, the proper TPID ofETH_P_8021Qis installed again, and the switch starts identifying 802.1Q-tagged traffic.Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes from v3:
Changed back toETH_P_EDSA.Changes from v2:
Changed the TPID fromETH_P_EDSA(0xDADA) to a newly introduced one:ETH_P_DSA_8021Q(0xDADB).drivers/net/dsa/sja1105/sja1105_main.c | 254 +++++++++++++++++- .../net/dsa/sja1105/sja1105_static_config.c | 38 +++ .../net/dsa/sja1105/sja1105_static_config.h | 3 + 3 files changed, 293 insertions(+), 2 deletions(-)[...]
Quoted 7 lines
drivers/net/dsa/sja1105/sja1105_main.c static void sja1105_bridge_leave(struct dsa_switch *ds, int port, · line 1008
Quoted 4 lines
drivers/net/dsa/sja1105/sja1105_main.c +4
-0+#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)This is unreadable. Please have it as function.
I admit to that. If I reach to a consensus with Andrew on 12/24 ideally I could just say cpu_dp->vlan_filtering.
Thanks,
-Vladimir
Vladimir Oltean
maintainerPATCH v3 17/24 net: dsa: sja1105: Add support for ethtool port counters
In reply to Vladimir Oltean---
Changes in v3:
None.
Changes in v2:
None functional. Moved the IS_ET() and IS_PQRS() device identification macros here since they are not used in earlier patches.
drivers/net/dsa/sja1105/Makefile | 1 + drivers/net/dsa/sja1105/sja1105.h | 7 +- drivers/net/dsa/sja1105/sja1105_ethtool.c | 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
@@ -1240,6 +1240,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
Re: [PATCH v3 net-next 17/24] net: dsa: sja1105: Add support for ethtool port counters
Quoted 55 lines · Sat, Apr 13, 2019 at 03:28:15AM CEST, [email protected] wrote:
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in v3:
None.Changes in v2:
None functional. Moved theIS_ET()andIS_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.cdrivers/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 +0
-0
drivers/net/dsa/sja1105/sja1105_ethtool.c line 9
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +9
-0@@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2018-2019, Vladimir Oltean <[email protected]> +*/ +#include "sja1105.h" + +#define SIZE_MAC_AREA (0x02 * 4) +#define SIZE_HL1_AREA (0x10 * 4) +#define SIZE_HL2_AREA (0x4 * 4) +#define SIZE_QLEVEL_AREA (0x8 * 4)/* 0x4 to 0xB */
Please use prefixes for defines like this. For example "SIZE_MAC_AREA" sounds way too generic.
[...]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 110
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +6
-0+static void +sja1105_port_status_hl1_unpack (void *buf, +struct sja1105_port_status_hl1 *status) +{ +/* Make pointer arithmetic work on 4 bytes */ +u32 *p = (u32 *)buf;
You don't need to cast void *. Please avoid it in the whole patchset.
[...]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 371
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +6
-0+if (!IS_PQRS (priv->info->device_id)) +return ; + +memset (data + k,0 ,ARRAY_SIZE (sja1105pqrs_extra_port_stats) * +sizeof (u64)); +for (i =0 ; i <8 ; i++) {
Array size instead of "8"?
Quoted 3 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +3
-0+ data[k++] = status.hl2.qlevel_hwm[i]; + data[k++] = status.hl2.qlevel[i]; + }
[...]
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +8
-0+#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) \
drivers/net/dsa/sja1105/sja1105_ethtool.c
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +10
-0+ (((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) \
Please have a prefix for macros like this. "IS_S" sounds way too generic...
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +3
-0+ (((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
maintainerRe: [PATCH v3 net-next 17/24] net: dsa: sja1105: Add support for ethtool port counters
Quoted 61 lines · Jiri Pirko
Quoted 59 lines · Sat, Apr 13, 2019 at 03:28:15AM CEST, [email protected] wrote:
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in v3:
None.Changes in v2:
None functional. Moved theIS_ET()andIS_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.cdrivers/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 +4
-0@@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2018-2019, Vladimir Oltean <[email protected]> +*/ +#include "sja1105.h"
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c line 9
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +5
-0+ +#define SIZE_MAC_AREA (0x02 * 4) +#define SIZE_HL1_AREA (0x10 * 4) +#define SIZE_HL2_AREA (0x4 * 4) +#define SIZE_QLEVEL_AREA (0x8 * 4)/* 0x4 to 0xB */ Please use prefixes for defines like this. For example "
SIZE_MAC_AREA" sounds way too generic.
What you propose sounds nice but then consistency would be a concern, so I'd have to redo the entire driver. And then there are tables named like "L2 Address Lookup Parameters Table", and as if SIZE_L2_LOOKUP_PARAMS_DYN_CMD_ET wasn't long enough, a prefix would top it off.
I don't think it's as much of an issue for the reader (for the compiler it clearly isn't, as it's restricted to this C file only) as it is for tools like ctags?
Quoted 12 lines
[...]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 110
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +6
-0+static void +sja1105_port_status_hl1_unpack (void *buf, +struct sja1105_port_status_hl1 *status) +{ +/* Make pointer arithmetic work on 4 bytes */ +u32 *p = (u32 *)buf;You don't need to cast void *. Please avoid it in the whole patchset.
Ok.
Quoted 12 lines
[...]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 371
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +6
-0+if (!IS_PQRS (priv->info->device_id)) +return ; + +memset (data + k,0 ,ARRAY_SIZE (sja1105pqrs_extra_port_stats) * +sizeof (u64)); +for (i =0 ; i <8 ; i++) {Array size instead of "8"?
Perhaps SJA1105_NUM_TC, since the egress queue occupancy levels are per traffic class. The size of the array is 16.
Quoted 22 lines
Quoted 4 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +3
-0+ data[k++] = status.hl2.qlevel_hwm[i]; + data[k++] = status.hl2.qlevel[i]; + }[...]
Quoted 14 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +13
-0+#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))
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +5
-0+/* 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) \Please have a prefix for macros like this. "
IS_S" sounds way too generic...
Ok, I can think of a more descriptive name, since there are under 5 occurrences of these macros after the reorg, now that I have the sja1105_info structure which also holds per-revision function pointers.
Quoted 10 lines
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +3
-0+ (((device_id) ==SJA1105QS_DEVICE_ID ) && \ + ((part_nr) ==SJA1105S_PART_NR )) +struct sja1105_general_params_entry { u64 vllupformat; u64 mirr_ptacu;--
2.17.1
Thanks!
-Vladimir
Re: [PATCH v3 net-next 17/24] net: dsa: sja1105: Add support for ethtool port counters
Quoted 72 lines · Sat, Apr 13, 2019 at 11:55:52PM CEST, [email protected] wrote:
Quoted 61 lines · Jiri Pirko
Quoted 59 lines · Sat, Apr 13, 2019 at 03:28:15AM CEST, [email protected] wrote:
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in v3:
None.Changes in v2:
None functional. Moved theIS_ET()andIS_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.cdrivers/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 +4
-0@@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2018-2019, Vladimir Oltean <[email protected]> +*/ +#include "sja1105.h" Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c line 9
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +5
-0+ +#define SIZE_MAC_AREA (0x02 * 4) +#define SIZE_HL1_AREA (0x10 * 4) +#define SIZE_HL2_AREA (0x4 * 4) +#define SIZE_QLEVEL_AREA (0x8 * 4)/* 0x4 to 0xB */ Please use prefixes for defines like this. For example "
SIZE_MAC_AREA" sounds way too generic.
Quoted 2 lines
What you propose sounds nice but then consistency would be a concern, so I'd have to redo the entire driver. And then there are tables named
Yep
Quoted 3 lines
like "L2 Address Lookup Parameters Table", and as if
SIZE_L2_LOOKUP_PARAMS_DYN_CMD_ETwasn't long enough, a prefix would top it off.
It's a tradeoff. But most of the time, it is doable. Then the code is easier to read.
Quoted 86 lines
I don't think it's as much of an issue for the reader (for the compiler it clearly isn't, as it's restricted to this C file only) as it is for tools like ctags?
Quoted 12 lines
[...]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 110
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +6
-0+static void +sja1105_port_status_hl1_unpack (void *buf, +struct sja1105_port_status_hl1 *status) +{ +/* Make pointer arithmetic work on 4 bytes */ +u32 *p = (u32 *)buf;You don't need to cast void *. Please avoid it in the whole patchset.
Ok.
Quoted 12 lines
[...]
drivers/net/dsa/sja1105/sja1105_ethtool.c line 371
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +6
-0+if (!IS_PQRS (priv->info->device_id)) +return ; + +memset (data + k,0 ,ARRAY_SIZE (sja1105pqrs_extra_port_stats) * +sizeof (u64)); +for (i =0 ; i <8 ; i++) {Array size instead of "8"?
Perhaps
SJA1105_NUM_TC, since the egress queue occupancy levels are per traffic class. The size of the array is 16.Quoted 22 lines
Quoted 4 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +3
-0+ data[k++] = status.hl2.qlevel_hwm[i]; + data[k++] = status.hl2.qlevel[i]; + }[...]
Quoted 14 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +13
-0+#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))Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c
Quoted 5 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +5
-0+/* 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) \Please have a prefix for macros like this. "
IS_S" sounds way too generic...Ok, I can think of a more descriptive name, since there are under 5 occurrences of these macros after the reorg, now that I have the
sja1105_infostructure which also holds per-revision function pointers.Quoted 10 lines
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_ethtool.c new file +3
-0+ (((device_id) ==SJA1105QS_DEVICE_ID ) && \ + ((part_nr) ==SJA1105S_PART_NR )) +struct sja1105_general_params_entry { u64 vllupformat; u64 mirr_ptacu;--
2.17.1Thanks!
-Vladimir
Vladimir Oltean
maintainerPATCH v3 18/24 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 of normal traffic on switch ports only works when not under a vlan_filtering bridge. Termination of management (PTP, BPDU) traffic works under all circumstances because it uses a different tagging mechanism (incl_srcpt). 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 v3:
Made management traffic be receivable on the DSA netdevices even when switch tagging is disabled, as well as regular traffic be receivable on the master netdevice in the same scenario. Both are accomplished using the sja1105_filter() function and some small touch-ups in the .rcv callback.
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 | 125 ++++++++++++++++++++- 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, 345 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 +123 -2
155 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 ] ="8021q" , +#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
Andrew Lunn
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 30 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination of normal traffic on switch ports only works when not under a
vlan_filteringbridge. Termination of management (PTP, BPDU) traffic works under all circumstances because it uses a different tagging mechanism (incl_srcpt). We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Quoted 7 lines
---
Changes in v3:
Made management traffic be receivable on the DSA netdevices even when switch tagging is disabled, as well as regular traffic be receivable on the master netdevice in the same scenario. Both are accomplished using thesja1105_filter()function and some small touch-ups in the .rcv callback.
It seems like you made major changes to this. When you do that, you should drop any reviewed-by tags you have. They are no longer valid because of the major changes.
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) · line 1161
Quoted 7 lines
/* This callback needs to be present */
drivers/net/dsa/sja1105/sja1105_main.c +1
-1@@ -1141,7 +1158,11 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)if (rc)dev_err (ds->dev,"Failed to change VLAN Ethertype\n" ); -return rc; +/* Switch port identification based on 802.1Q is only passable
possible, not passable.
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_main.c +4
-0+* if we are not under a vlan_filtering bridge. So make sure +* the two configurations are mutually exclusive. +*/ +return sja1105_setup_8021q_tagging (ds, !enabled); } static void sja1105_vlan_add(struct dsa_switch *ds, int port,@@ -1233,9 +1254,107 @@ static int sja1105_setup(struct dsa_switch *ds)*/
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1264
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0ds->vlan_filtering_is_global = true; +/* The DSA/switchdev model brings up switch ports in standalone mode by +* default, and that means vlan_filtering is 0 since they're not under +* a bridge, so it's safe to set up switch tagging at this time. +*/ +return sja1105_setup_8021q_tagging (ds, true); +} + +#include "../../../net/dsa/dsa_priv.h"
No. Don't use relative includes like this.
What do you need from the header? Maybe move it into include/linux/net/dsa.h
Quoted 71 lines
drivers/net/dsa/sja1105/sja1105_main.c +71
-0+/* Deferred work is unfortunately necessary because setting up the management +* route cannot be done from atomit context (SPI transfer takes a sleepable +* lock on the bus) +*/ +static void sja1105_xmit_work_handler (struct work_struct *work) +{ + struct sja1105_port *sp = container_of(work, struct sja1105_port, + xmit_work); +struct sja1105_private *priv = sp->dp->ds->priv; +struct net_device *slave = sp->dp->slave; +struct net_device *master =dsa_slave_to_master (slave); +int port = (uintptr_t )(sp - priv->ports); +struct sk_buff *skb; +int i, rc; + +while ((i =sja1105_skb_ring_get (&sp->xmit_ring, &skb)) >=0 ) { +struct sja1105_mgmt_entry mgmt_route = {0 }; +struct ethhdr *hdr; +int timeout =10 ; +int skb_len; + + skb_len = skb->len; + hdr =eth_hdr (skb); + + mgmt_route.macaddr =ether_addr_to_u64 (hdr->h_dest); + mgmt_route.destports =BIT (port); + mgmt_route.enfport =1 ; + mgmt_route.tsreg =0 ; + mgmt_route.takets = false; + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true); +if (rc <0 ) { +kfree_skb (skb); + slave->stats.tx_dropped++; +continue ; + } + +/* Transfer skb to the host port. */ + skb->dev = master; +dev_queue_xmit (skb); + +/* Wait until the switch has processed the frame */ +do { + rc =sja1105_dynamic_config_read (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route); +if (rc <0 ) { + slave->stats.tx_errors++; +dev_err (priv->ds->dev, +"xmit: failed to poll for mgmt route\n" ); +continue ; + } + +/* UM10944: The ENFPORT flag of the respective entry is +* cleared when a match is found. The host can use this +* flag as an acknowledgment. +*/ +cpu_relax (); + }while (mgmt_route.enfport && --timeout); + +if (!timeout) { +dev_err (priv->ds->dev,"xmit timed out\n" ); + slave->stats.tx_errors++; +continue ; + } + + slave->stats.tx_packets++; + slave->stats.tx_bytes += skb_len; + } +} +
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1345
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0+static int sja1105_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phydev) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; + + sp->dp = &ds->ports[port]; +INIT_WORK (&sp->xmit_work, sja1105_xmit_work_handler);return 0 ; }
I think i'm missing something here. You have a per port queue of link local frames which need special handling. And you have a per-port work queue. To send such a frame, you need to write some register, send the frame, and then wait until the mgmt_route.enfport is reset.
Why are you doing this per port? How do you stop two ports/work queues running at the same time? It seems like one queue, with one work queue would be a better structure.
Also, please move all this code into the tagger. Just add exports for sja1105_dynamic_config_write() and sja1105_dynamic_config_read().
Quoted 17 lines
drivers/net/dsa/sja1105/sja1105_main.c +11
-0+static void sja1105_port_disable (struct dsa_switch *ds,int port) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; +struct sk_buff *skb; + +cancel_work_sync (&sp->xmit_work); +while (sja1105_skb_ring_get (&sp->xmit_ring, &skb) >=0 ) +kfree_skb (skb); +} +net/dsa/tag_sja1105.c new file +0
-0
net/dsa/tag_sja1105.c line 7
Quoted 7 lines
net/dsa/tag_sja1105.c new file +7
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright (c) 2019, Vladimir Oltean <[email protected]> +*/ +#include <linux/etherdevice.h> +#include <linux/if_vlan.h> +#include <linux/dsa/sja1105.h> +#include "../../drivers/net/dsa/sja1105/sja1105.h"
Again, no, don't do this.
Quoted 16 lines
net/dsa/tag_sja1105.c new file +16
-0+ +#include "dsa_priv.h" + +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false;
net/dsa/tag_sja1105.c line 33
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+} + +static bool sja1105_filter (const struct sk_buff *skb,struct net_device *dev) +{ +if (sja1105_is_link_local (skb)) +return true; +if (!dev->dsa_ptr->vlan_filtering) +return true; +return false; +}
Please add a comment here about what frames cannot be handled by the tagger. However, i'm not too happy about this design...
Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ +static struct sk_buff *sja1105_xmit (struct sk_buff *skb, +struct net_device *netdev) +{ +struct dsa_port *dp =dsa_slave_to_port (netdev); +struct dsa_switch *ds = dp->ds; +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[dp->index]; +struct sk_buff *clone; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ +u16 tx_vid =dsa_tagging_tx_vid (ds, dp->index); +u8 pcp = skb->priority; +
net/dsa/tag_sja1105.c line 58
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+/* If we are under a vlan_filtering bridge, IP termination on +* switch ports based on 802.1Q tags is simply too brittle to +* be passable. So just defer to the dsa_slave_notag_xmit +* implementation. +*/ +if (dp->vlan_filtering) +return skb; + +return dsa_8021q_xmit (skb, netdev,ETH_P_EDSA , + ((pcp <<VLAN_PRIO_SHIFT ) | tx_vid));
Please don't reuse ETH_P_EDSA. Define an ETH_P_SJA1105.
Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ } + +/* Code path for transmitting management traffic. This does not rely +* upon switch tagging, but instead SPI-installed management routes. +*/ + clone =skb_clone (skb,GFP_ATOMIC ); +if (!clone) { +dev_err (ds->dev,"xmit: failed to clone skb\n" ); +return NULL ; + } + +if (sja1105_skb_ring_add (&sp->xmit_ring, clone) <0 ) { +dev_err (ds->dev,"xmit: skb ring full\n" ); +kfree_skb (clone); +return NULL ;
net/dsa/tag_sja1105.c line 83
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+ } + +if (sp->xmit_ring.count ==SJA1105_SKB_RING_SIZE ) +/* TODO setup a dedicated netdev queue for management traffic +* so that we can selectively apply backpressure and not be +* required to stop the entire traffic when the software skb +* ring is full. This requires hooking the ndo_select_queue +* from DSA and matching on mac_fltres. +*/ +dev_err (ds->dev,"xmit: reached maximum skb ring size\n" );
This should be rate limited.
Andrew
Quoted 68 lines
net/dsa/tag_sja1105.c new file +65
-0+ +schedule_work (&sp->xmit_work); +/* Let DSA free its reference to the skb and we will free +* the clone in the deferred worker +*/ +return NULL ; +} + +static struct sk_buff *sja1105_rcv (struct sk_buff *skb, +struct net_device *netdev, +struct packet_type *pt) +{ +unsigned int source_port, switch_id; +struct ethhdr *hdr =eth_hdr (skb); +struct sk_buff *nskb; +u16 tpid, vid, tci; +bool is_tagged; + + nskb =dsa_8021q_rcv (skb, netdev, pt, &tpid, &tci); + is_tagged = (nskb && tpid ==ETH_P_EDSA ); + + skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; + vid = tci &VLAN_VID_MASK ; + + skb->offload_fwd_mark =1 ; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ + source_port =dsa_tagging_rx_source_port (vid); + switch_id =dsa_tagging_rx_switch_id (vid); + }else { +/* Management traffic path. Switch embeds the switch ID and +* port ID into bytes of the destination MAC, courtesy of +* the incl_srcpt options. +*/ + source_port = hdr->h_dest[3 ]; + switch_id = hdr->h_dest[4 ]; +/* Clear the DMAC bytes that were mangled by the switch */ + hdr->h_dest[3 ] =0 ; + hdr->h_dest[4 ] =0 ; + } + + skb->dev =dsa_master_find_slave (netdev, switch_id, source_port); +if (!skb->dev) { +netdev_warn (netdev,"Couldn't decode source port\n" ); +return NULL ; + } + +/* Delete/overwrite fake VLAN header, DSA expects to not find +* it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN). +*/ +if (is_tagged) +memmove (skb->data -ETH_HLEN , skb->data -ETH_HLEN -VLAN_HLEN , +ETH_HLEN -VLAN_HLEN ); + +return skb; +} + +const struct dsa_device_ops sja1105_netdev_ops = { + .xmit = sja1105_xmit, + .rcv = sja1105_rcv, + .filter = sja1105_filter, + .overhead =VLAN_HLEN , +}; +Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 40 lines · Andrew Lunn
Quoted 30 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination of normal traffic on switch ports only works when not under a
vlan_filteringbridge. Termination of management (PTP, BPDU) traffic works under all circumstances because it uses a different tagging mechanism (incl_srcpt). We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>Quoted 7 lines
---
Changes in v3:
Made management traffic be receivable on the DSA netdevices even when switch tagging is disabled, as well as regular traffic be receivable on the master netdevice in the same scenario. Both are accomplished using thesja1105_filter()function and some small touch-ups in the .rcv callback.
Quoted 4 lines
It seems like you made major changes to this. When you do that, you should drop any reviewed-by tags you have. They are no longer valid because of the major changes.
Ok, noted.
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) · line 1161
Quoted 7 lines
/* This callback needs to be present */
drivers/net/dsa/sja1105/sja1105_main.c +1
-1@@ -1141,7 +1158,11 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)if (rc)dev_err (ds->dev,"Failed to change VLAN Ethertype\n" ); -return rc; +/* Switch port identification based on 802.1Q is only passable possible, not passable.
Passable (satisfactory, decent, acceptable) is what I wanted to say. Tagging using VLANs is possible even when the bridge wants to use them, but it's smarter not to go there. But I get your point, maybe I'll rephrase.
Quoted 22 lines
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_main.c +4
-0+* if we are not under a vlan_filtering bridge. So make sure +* the two configurations are mutually exclusive. +*/ +return sja1105_setup_8021q_tagging (ds, !enabled); } static void sja1105_vlan_add(struct dsa_switch *ds, int port,@@ -1233,9 +1254,107 @@ static int sja1105_setup(struct dsa_switch *ds)*/ drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1264
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0ds->vlan_filtering_is_global = true; +/* The DSA/switchdev model brings up switch ports in standalone mode by +* default, and that means vlan_filtering is 0 since they're not under +* a bridge, so it's safe to set up switch tagging at this time. +*/ +return sja1105_setup_8021q_tagging (ds, true); +} + +#include "../../../net/dsa/dsa_priv.h" No. Don't use relative includes like this.
Quoted 3 lines
What do you need from the header? Maybe move it into
include/linux/net/dsa.h
dsa_slave_to_master()
Quoted 87 lines
Quoted 71 lines
drivers/net/dsa/sja1105/sja1105_main.c +71
-0+/* Deferred work is unfortunately necessary because setting up the management +* route cannot be done from atomit context (SPI transfer takes a sleepable +* lock on the bus) +*/ +static void sja1105_xmit_work_handler (struct work_struct *work) +{ + struct sja1105_port *sp = container_of(work, struct sja1105_port, + xmit_work); +struct sja1105_private *priv = sp->dp->ds->priv; +struct net_device *slave = sp->dp->slave; +struct net_device *master =dsa_slave_to_master (slave); +int port = (uintptr_t )(sp - priv->ports); +struct sk_buff *skb; +int i, rc; + +while ((i =sja1105_skb_ring_get (&sp->xmit_ring, &skb)) >=0 ) { +struct sja1105_mgmt_entry mgmt_route = {0 }; +struct ethhdr *hdr; +int timeout =10 ; +int skb_len; + + skb_len = skb->len; + hdr =eth_hdr (skb); + + mgmt_route.macaddr =ether_addr_to_u64 (hdr->h_dest); + mgmt_route.destports =BIT (port); + mgmt_route.enfport =1 ; + mgmt_route.tsreg =0 ; + mgmt_route.takets = false; + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true); +if (rc <0 ) { +kfree_skb (skb); + slave->stats.tx_dropped++; +continue ; + } + +/* Transfer skb to the host port. */ + skb->dev = master; +dev_queue_xmit (skb); + +/* Wait until the switch has processed the frame */ +do { + rc =sja1105_dynamic_config_read (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route); +if (rc <0 ) { + slave->stats.tx_errors++; +dev_err (priv->ds->dev, +"xmit: failed to poll for mgmt route\n" ); +continue ; + } + +/* UM10944: The ENFPORT flag of the respective entry is +* cleared when a match is found. The host can use this +* flag as an acknowledgment. +*/ +cpu_relax (); + }while (mgmt_route.enfport && --timeout); + +if (!timeout) { +dev_err (priv->ds->dev,"xmit timed out\n" ); + slave->stats.tx_errors++; +continue ; + } + + slave->stats.tx_packets++; + slave->stats.tx_bytes += skb_len; + } +} +drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1345
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0+static int sja1105_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phydev) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; + + sp->dp = &ds->ports[port]; +INIT_WORK (&sp->xmit_work, sja1105_xmit_work_handler);return 0 ; }I think i'm missing something here. You have a per port queue of link local frames which need special handling. And you have a per-port work queue. To send such a frame, you need to write some register, send the frame, and then wait until the mgmt_route.enfport is reset.
Quoted 4 lines
Why are you doing this per port? How do you stop two ports/work queues running at the same time? It seems like one queue, with one work queue would be a better structure.
See the "port" parameter to this call here:
rc = sja1105_dynamic_config_write(priv, BLK_IDX_MGMT_ROUTE,
*port*, &mgmt_route, true);
The switch IP aptly allocates 4 slots for management routes. And it's a 5-port switch where 1 port is the management port. I think the structure is fine.
Quoted 3 lines
Also, please move all this code into the tagger. Just add exports for
sja1105_dynamic_config_write()andsja1105_dynamic_config_read().
Well, you see, the tagger code is part of the dsa_core object. If I export function symbols from the driver, those still won't be there if I compile the driver as a module. On the other hand, the way I'm doing it, I think the schedule_work() gives me a pretty good separation.
Quoted 18 lines
Quoted 18 lines
drivers/net/dsa/sja1105/sja1105_main.c +11
-0+static void sja1105_port_disable (struct dsa_switch *ds,int port) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; +struct sk_buff *skb; + +cancel_work_sync (&sp->xmit_work); +while (sja1105_skb_ring_get (&sp->xmit_ring, &skb) >=0 ) +kfree_skb (skb); +} +net/dsa/tag_sja1105.c new file +1
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0
Quoted 9 lines
net/dsa/tag_sja1105.c line 7
Quoted 6 lines
net/dsa/tag_sja1105.c new file +6
-0+/* Copyright (c) 2019, Vladimir Oltean <[email protected]> +*/ +#include <linux/etherdevice.h> +#include <linux/if_vlan.h> +#include <linux/dsa/sja1105.h> +#include "../../drivers/net/dsa/sja1105/sja1105.h" Again, no, don't do this.
This separation between driver and tagger is fairly arbitrary. I need access to the driver's private structure, in order to get a hold of the private shadow of the dsa_port. Moving the driver private structure to include/linux/dsa/ would pull in quite a number of dependencies. Maybe I could provide declarations for the most of them, but anyway the private structure wouldn't be so private any longer, would it?
Otherwise put, would you prefer a dp->priv similar to the already existing ds->priv? struct sja1105_port is much more lightweight to keep in include/linux/dsa/.
Quoted 21 lines
Quoted 21 lines
net/dsa/tag_sja1105.c new file +21
-0+ +#include "dsa_priv.h" + +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false; +} + +static bool sja1105_filter (const struct sk_buff *skb,struct net_device *dev) +{ +if (sja1105_is_link_local (skb))
Quoted 9 lines
net/dsa/tag_sja1105.c line 33
Quoted 5 lines
net/dsa/tag_sja1105.c new file +5
-0+return true; +if (!dev->dsa_ptr->vlan_filtering) +return true; +return false; +}Please add a comment here about what frames cannot be handled by the tagger. However, i'm not too happy about this design...
Ok, let's put this another way.
A switch is primarily a device used to offload the forwarding of traffic based on L2 rules. Additionally there may be some management traffic for stuff like STP that needs to be terminated on the host port of the switch. For that, the hardware's job is to filter and tag management frames on their way to the host port, and the software's job is to process the source port and switch id information in a meaningful way.
Now both this particular switch hardware, and DSA, are taking the above definitions to extremes.
The switch says: "that's all you want to see? ok, so that's all I'm going to give you". So its native (hardware) tagging protocol is to trap link-local traffic and overwrite two bytes of its destination MAC with the switch ID and the source port. No more, no less. It is an incomplete solution, but it does the job for practical use cases. Now DSA says: "I want these to be fully capable net devices, I want the user to not even realize what's going on under the hood". I don't think that terminating iperf traffic through switch ports is a realistic usage scenario. So in a way discussions about performance and optimizations on DSA hotpath are slightly pointless IMO. Now what my driver says is that it offers a bit of both. It speaks the hardware's tagging protocol so it is capable of management traffic, but it also speaks the DSA paradigm, so in a way pushes the hardware to work in a mode it was never intended to, by repurposing VLANs when the user doesn't request them. So on one hand there is some overlap between the hardware tagging protocol and the VLAN one (in standalone mode and in VLAN-unaware bridged mode, management traffic *could* use VLAN tagging but it doesn't rely on it), and on the other hand the reunion of the two tagging protocols is decent, but still doesn't cover the entire spectrum (when put under a VLAN-aware bridge, you lose the ability to decode general traffic). So you'd better not rely on VLANs to decode the management traffic, because you won't be able to always rely on that, and that is a shame since a bridge with both vlan_filtering 1 and stp_state 1 is a real usage scenario, and the hardware is capable of that combination.
But all of that is secondary. Let's forget about VLAN tagging for a second and concentrate on the tagging of management traffic. The limiting factor here is the software architecture of DSA, because in order for me to decode that in the driver/tagger, I'd have to drop everything else coming on the master net device (I explained in 13/24 why). I believe that DSA being all-or-nothing about switch tagging is turning a blind eye to the devices that don't go overboard with features, and give you what's needed in a real-world design but not much else.
What would you improve about this design (assuming you're talking about the filter function)?
Thanks,
-Vladimir
Quoted 126 lines
Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ +static struct sk_buff *sja1105_xmit (struct sk_buff *skb, +struct net_device *netdev) +{ +struct dsa_port *dp =dsa_slave_to_port (netdev); +struct dsa_switch *ds = dp->ds; +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[dp->index]; +struct sk_buff *clone; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ +u16 tx_vid =dsa_tagging_tx_vid (ds, dp->index); +u8 pcp = skb->priority; +net/dsa/tag_sja1105.c line 58
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+/* If we are under a vlan_filtering bridge, IP termination on +* switch ports based on 802.1Q tags is simply too brittle to +* be passable. So just defer to the dsa_slave_notag_xmit +* implementation. +*/ +if (dp->vlan_filtering) +return skb; + +return dsa_8021q_xmit (skb, netdev,ETH_P_EDSA , + ((pcp <<VLAN_PRIO_SHIFT ) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ } + +/* Code path for transmitting management traffic. This does not rely +* upon switch tagging, but instead SPI-installed management routes. +*/ + clone =skb_clone (skb,GFP_ATOMIC ); +if (!clone) { +dev_err (ds->dev,"xmit: failed to clone skb\n" ); +return NULL ; + } + +if (sja1105_skb_ring_add (&sp->xmit_ring, clone) <0 ) { +dev_err (ds->dev,"xmit: skb ring full\n" ); +kfree_skb (clone); +return NULL ;net/dsa/tag_sja1105.c line 83
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+ } + +if (sp->xmit_ring.count ==SJA1105_SKB_RING_SIZE ) +/* TODO setup a dedicated netdev queue for management traffic +* so that we can selectively apply backpressure and not be +* required to stop the entire traffic when the software skb +* ring is full. This requires hooking the ndo_select_queue +* from DSA and matching on mac_fltres. +*/ +dev_err (ds->dev,"xmit: reached maximum skb ring size\n" );This should be rate limited.
Andrew
Quoted 68 lines
net/dsa/tag_sja1105.c new file +65
-1+ +schedule_work (&sp->xmit_work); +/* Let DSA free its reference to the skb and we will free +* the clone in the deferred worker +*/ +return NULL ; +} + +static struct sk_buff *sja1105_rcv (struct sk_buff *skb, +struct net_device *netdev, +struct packet_type *pt) +{ +unsigned int source_port, switch_id; +struct ethhdr *hdr =eth_hdr (skb); +struct sk_buff *nskb; +u16 tpid, vid, tci; +bool is_tagged; + + nskb =dsa_8021q_rcv (skb, netdev, pt, &tpid, &tci); + is_tagged = (nskb && tpid ==ETH_P_EDSA ); + + skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; + vid = tci &VLAN_VID_MASK ; + + skb->offload_fwd_mark =1 ; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ + source_port =dsa_tagging_rx_source_port (vid); + switch_id =dsa_tagging_rx_switch_id (vid); + }else { +/* Management traffic path. Switch embeds the switch ID and +* port ID into bytes of the destination MAC, courtesy of +* the incl_srcpt options. +*/ + source_port = hdr->h_dest[3 ]; + switch_id = hdr->h_dest[4 ]; +/* Clear the DMAC bytes that were mangled by the switch */ + hdr->h_dest[3 ] =0 ; + hdr->h_dest[4 ] =0 ; + } + + skb->dev =dsa_master_find_slave (netdev, switch_id, source_port); +if (!skb->dev) { +netdev_warn (netdev,"Couldn't decode source port\n" ); +return NULL ; + } + +/* Delete/overwrite fake VLAN header, DSA expects to not find +* it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN). +*/ +if (is_tagged) +memmove (skb->data -ETH_HLEN , skb->data -ETH_HLEN -VLAN_HLEN , +ETH_HLEN -VLAN_HLEN ); + +return skb; +} + +const struct dsa_device_ops sja1105_netdev_ops = { + .xmit = sja1105_xmit, + .rcv = sja1105_rcv, + .filter = sja1105_filter, + .overhead =VLAN_HLEN , +}; + --2.17.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 185 lines · Vladimir Oltean
Quoted 40 lines · Andrew Lunn
Quoted 30 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination of normal traffic on switch ports only works when not under a
vlan_filteringbridge. Termination of management (PTP, BPDU) traffic works under all circumstances because it uses a different tagging mechanism (incl_srcpt). We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>Quoted 7 lines
---
Changes in v3:
Made management traffic be receivable on the DSA netdevices even when switch tagging is disabled, as well as regular traffic be receivable on the master netdevice in the same scenario. Both are accomplished using thesja1105_filter()function and some small touch-ups in the .rcv callback.Quoted 4 lines
It seems like you made major changes to this. When you do that, you should drop any reviewed-by tags you have. They are no longer valid because of the major changes.
Ok, noted.
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) · line 1161
Quoted 7 lines
/* This callback needs to be present */
drivers/net/dsa/sja1105/sja1105_main.c +1
-1@@ -1141,7 +1158,11 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)if (rc)dev_err (ds->dev,"Failed to change VLAN Ethertype\n" ); -return rc; +/* Switch port identification based on 802.1Q is only passable possible, not passable.
Passable (satisfactory, decent, acceptable) is what I wanted to say. Tagging using VLANs is possible even when the bridge wants to use them, but it's smarter not to go there. But I get your point, maybe I'll rephrase.
Quoted 22 lines
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_main.c +4
-0+* if we are not under a vlan_filtering bridge. So make sure +* the two configurations are mutually exclusive. +*/ +return sja1105_setup_8021q_tagging (ds, !enabled); } static void sja1105_vlan_add(struct dsa_switch *ds, int port,@@ -1233,9 +1254,107 @@ static int sja1105_setup(struct dsa_switch *ds)*/ drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1264
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0ds->vlan_filtering_is_global = true; +/* The DSA/switchdev model brings up switch ports in standalone mode by +* default, and that means vlan_filtering is 0 since they're not under +* a bridge, so it's safe to set up switch tagging at this time. +*/ +return sja1105_setup_8021q_tagging (ds, true); +} + +#include "../../../net/dsa/dsa_priv.h" No. Don't use relative includes like this.
Quoted 3 lines
What do you need from the header? Maybe move it into
include/linux/net/dsa.h
dsa_slave_to_master()Quoted 87 lines
Quoted 71 lines
drivers/net/dsa/sja1105/sja1105_main.c +71
-0+/* Deferred work is unfortunately necessary because setting up the management +* route cannot be done from atomit context (SPI transfer takes a sleepable +* lock on the bus) +*/ +static void sja1105_xmit_work_handler (struct work_struct *work) +{ + struct sja1105_port *sp = container_of(work, struct sja1105_port, + xmit_work); +struct sja1105_private *priv = sp->dp->ds->priv; +struct net_device *slave = sp->dp->slave; +struct net_device *master =dsa_slave_to_master (slave); +int port = (uintptr_t )(sp - priv->ports); +struct sk_buff *skb; +int i, rc; + +while ((i =sja1105_skb_ring_get (&sp->xmit_ring, &skb)) >=0 ) { +struct sja1105_mgmt_entry mgmt_route = {0 }; +struct ethhdr *hdr; +int timeout =10 ; +int skb_len; + + skb_len = skb->len; + hdr =eth_hdr (skb); + + mgmt_route.macaddr =ether_addr_to_u64 (hdr->h_dest); + mgmt_route.destports =BIT (port); + mgmt_route.enfport =1 ; + mgmt_route.tsreg =0 ; + mgmt_route.takets = false; + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true); +if (rc <0 ) { +kfree_skb (skb); + slave->stats.tx_dropped++; +continue ; + } + +/* Transfer skb to the host port. */ + skb->dev = master; +dev_queue_xmit (skb); + +/* Wait until the switch has processed the frame */ +do { + rc =sja1105_dynamic_config_read (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route); +if (rc <0 ) { + slave->stats.tx_errors++; +dev_err (priv->ds->dev, +"xmit: failed to poll for mgmt route\n" ); +continue ; + } + +/* UM10944: The ENFPORT flag of the respective entry is +* cleared when a match is found. The host can use this +* flag as an acknowledgment. +*/ +cpu_relax (); + }while (mgmt_route.enfport && --timeout); + +if (!timeout) { +dev_err (priv->ds->dev,"xmit timed out\n" ); + slave->stats.tx_errors++; +continue ; + } + + slave->stats.tx_packets++; + slave->stats.tx_bytes += skb_len; + } +} +drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1345
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0+static int sja1105_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phydev) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; + + sp->dp = &ds->ports[port]; +INIT_WORK (&sp->xmit_work, sja1105_xmit_work_handler);return 0 ; }I think i'm missing something here. You have a per port queue of link local frames which need special handling. And you have a per-port work queue. To send such a frame, you need to write some register, send the frame, and then wait until the mgmt_route.enfport is reset.
Quoted 4 lines
Why are you doing this per port? How do you stop two ports/work queues running at the same time? It seems like one queue, with one work queue would be a better structure.
Quoted 9 lines
See the "port" parameter to this call here:
rc = sja1105_dynamic_config_write(priv,
BLK_IDX_MGMT_ROUTE,
*port*,&mgmt_route, true);The switch IP aptly allocates 4 slots for management routes. And it's a 5-port switch where 1 port is the management port. I think the structure is fine.
"How do stop two work queues": if you're talking about contention on the hardware management route, I responded to that.
If you're talking about netif_stop_queue(), I think I'm going to avoid that altogether by not having a finite sized ring structure. While studying the Marvell 88e6060 driver I found out that sk_buff_head exists. Now I'm part of the elite club of wheel reinventors with my struct sja1105_skb_ring :)
Quoted 259 lines
Quoted 3 lines
Also, please move all this code into the tagger. Just add exports for
sja1105_dynamic_config_write()andsja1105_dynamic_config_read().Well, you see, the tagger code is part of the
dsa_coreobject. If I export function symbols from the driver, those still won't be there if I compile the driver as a module. On the other hand, the way I'm doing it, I think theschedule_work()gives me a pretty good separation.Quoted 18 lines
Quoted 18 lines
drivers/net/dsa/sja1105/sja1105_main.c +11
-0+static void sja1105_port_disable (struct dsa_switch *ds,int port) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; +struct sk_buff *skb; + +cancel_work_sync (&sp->xmit_work); +while (sja1105_skb_ring_get (&sp->xmit_ring, &skb) >=0 ) +kfree_skb (skb); +} +net/dsa/tag_sja1105.c new file +1
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 Quoted 9 lines
net/dsa/tag_sja1105.c line 7
Quoted 6 lines
net/dsa/tag_sja1105.c new file +6
-0+/* Copyright (c) 2019, Vladimir Oltean <[email protected]> +*/ +#include <linux/etherdevice.h> +#include <linux/if_vlan.h> +#include <linux/dsa/sja1105.h> +#include "../../drivers/net/dsa/sja1105/sja1105.h" Again, no, don't do this.
This separation between driver and tagger is fairly arbitrary. I need access to the driver's private structure, in order to get a hold of the private shadow of the
dsa_port. Moving the driver private structure toinclude/linux/dsa/would pull in quite a number of dependencies. Maybe I could provide declarations for the most of them, but anyway the private structure wouldn't be so private any longer, would it?
Otherwise put, would you prefer adp->privsimilar to the already existingds->priv? structsja1105_portis much more lightweight to keep ininclude/linux/dsa/.Quoted 21 lines
Quoted 21 lines
net/dsa/tag_sja1105.c new file +21
-0+ +#include "dsa_priv.h" + +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false; +} + +static bool sja1105_filter (const struct sk_buff *skb,struct net_device *dev) +{ +if (sja1105_is_link_local (skb))Quoted 9 lines
net/dsa/tag_sja1105.c line 33
Quoted 5 lines
net/dsa/tag_sja1105.c new file +5
-0+return true; +if (!dev->dsa_ptr->vlan_filtering) +return true; +return false; +}Please add a comment here about what frames cannot be handled by the tagger. However, i'm not too happy about this design...
Ok, let's put this another way.
A switch is primarily a device used to offload the forwarding of traffic based on L2 rules. Additionally there may be some management traffic for stuff like STP that needs to be terminated on the host port of the switch. For that, the hardware's job is to filter and tag management frames on their way to the host port, and the software's job is to process the source port and switch id information in a meaningful way.
Now both this particular switch hardware, and DSA, are taking the above definitions to extremes.
The switch says: "that's all you want to see? ok, so that's all I'm going to give you". So its native (hardware) tagging protocol is to trap link-local traffic and overwrite two bytes of its destination MAC with the switch ID and the source port. No more, no less. It is an incomplete solution, but it does the job for practical use cases. Now DSA says: "I want these to be fully capable net devices, I want the user to not even realize what's going on under the hood". I don't think that terminating iperf traffic through switch ports is a realistic usage scenario. So in a way discussions about performance and optimizations on DSA hotpath are slightly pointless IMO. Now what my driver says is that it offers a bit of both. It speaks the hardware's tagging protocol so it is capable of management traffic, but it also speaks the DSA paradigm, so in a way pushes the hardware to work in a mode it was never intended to, by repurposing VLANs when the user doesn't request them. So on one hand there is some overlap between the hardware tagging protocol and the VLAN one (in standalone mode and in VLAN-unaware bridged mode, management traffic *could* use VLAN tagging but it doesn't rely on it), and on the other hand the reunion of the two tagging protocols is decent, but still doesn't cover the entire spectrum (when put under a VLAN-aware bridge, you lose the ability to decode general traffic). So you'd better not rely on VLANs to decode the management traffic, because you won't be able to always rely on that, and that is a shame since a bridge with bothvlan_filtering1 andstp_state1 is a real usage scenario, and the hardware is capable of that combination.
But all of that is secondary. Let's forget about VLAN tagging for a second and concentrate on the tagging of management traffic. The limiting factor here is the software architecture of DSA, because in order for me to decode that in the driver/tagger, I'd have to drop everything else coming on the master net device (I explained in 13/24 why). I believe that DSA being all-or-nothing about switch tagging is turning a blind eye to the devices that don't go overboard with features, and give you what's needed in a real-world design but not much else.
What would you improve about this design (assuming you're talking about the filter function)?Thanks,
-VladimirQuoted 126 lines
Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ +static struct sk_buff *sja1105_xmit (struct sk_buff *skb, +struct net_device *netdev) +{ +struct dsa_port *dp =dsa_slave_to_port (netdev); +struct dsa_switch *ds = dp->ds; +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[dp->index]; +struct sk_buff *clone; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ +u16 tx_vid =dsa_tagging_tx_vid (ds, dp->index); +u8 pcp = skb->priority; +net/dsa/tag_sja1105.c line 58
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+/* If we are under a vlan_filtering bridge, IP termination on +* switch ports based on 802.1Q tags is simply too brittle to +* be passable. So just defer to the dsa_slave_notag_xmit +* implementation. +*/ +if (dp->vlan_filtering) +return skb; + +return dsa_8021q_xmit (skb, netdev,ETH_P_EDSA , + ((pcp <<VLAN_PRIO_SHIFT ) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ } + +/* Code path for transmitting management traffic. This does not rely +* upon switch tagging, but instead SPI-installed management routes. +*/ + clone =skb_clone (skb,GFP_ATOMIC ); +if (!clone) { +dev_err (ds->dev,"xmit: failed to clone skb\n" ); +return NULL ; + } + +if (sja1105_skb_ring_add (&sp->xmit_ring, clone) <0 ) { +dev_err (ds->dev,"xmit: skb ring full\n" ); +kfree_skb (clone); +return NULL ;net/dsa/tag_sja1105.c line 83
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+ } + +if (sp->xmit_ring.count ==SJA1105_SKB_RING_SIZE ) +/* TODO setup a dedicated netdev queue for management traffic +* so that we can selectively apply backpressure and not be +* required to stop the entire traffic when the software skb +* ring is full. This requires hooking the ndo_select_queue +* from DSA and matching on mac_fltres. +*/ +dev_err (ds->dev,"xmit: reached maximum skb ring size\n" );This should be rate limited.
Andrew
Quoted 68 lines
net/dsa/tag_sja1105.c new file +65
-1+ +schedule_work (&sp->xmit_work); +/* Let DSA free its reference to the skb and we will free +* the clone in the deferred worker +*/ +return NULL ; +} + +static struct sk_buff *sja1105_rcv (struct sk_buff *skb, +struct net_device *netdev, +struct packet_type *pt) +{ +unsigned int source_port, switch_id; +struct ethhdr *hdr =eth_hdr (skb); +struct sk_buff *nskb; +u16 tpid, vid, tci; +bool is_tagged; + + nskb =dsa_8021q_rcv (skb, netdev, pt, &tpid, &tci); + is_tagged = (nskb && tpid ==ETH_P_EDSA ); + + skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; + vid = tci &VLAN_VID_MASK ; + + skb->offload_fwd_mark =1 ; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ + source_port =dsa_tagging_rx_source_port (vid); + switch_id =dsa_tagging_rx_switch_id (vid); + }else { +/* Management traffic path. Switch embeds the switch ID and +* port ID into bytes of the destination MAC, courtesy of +* the incl_srcpt options. +*/ + source_port = hdr->h_dest[3 ]; + switch_id = hdr->h_dest[4 ]; +/* Clear the DMAC bytes that were mangled by the switch */ + hdr->h_dest[3 ] =0 ; + hdr->h_dest[4 ] =0 ; + } + + skb->dev =dsa_master_find_slave (netdev, switch_id, source_port); +if (!skb->dev) { +netdev_warn (netdev,"Couldn't decode source port\n" ); +return NULL ; + } + +/* Delete/overwrite fake VLAN header, DSA expects to not find +* it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN). +*/ +if (is_tagged) +memmove (skb->data -ETH_HLEN , skb->data -ETH_HLEN -VLAN_HLEN , +ETH_HLEN -VLAN_HLEN ); + +return skb; +} + +const struct dsa_device_ops sja1105_netdev_ops = { + .xmit = sja1105_xmit, + .rcv = sja1105_rcv, + .filter = sja1105_filter, + .overhead =VLAN_HLEN , +}; + --2.17.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 197 lines · Vladimir Oltean
Quoted 185 lines · Vladimir Oltean
Quoted 40 lines · Andrew Lunn
Quoted 30 lines · Vladimir Oltean
In order to support this, we are creating a make-shift switch tag out of a VLAN trunk configured on the CPU port. Termination of normal traffic on switch ports only works when not under a
vlan_filteringbridge. Termination of management (PTP, BPDU) traffic works under all circumstances because it uses a different tagging mechanism (incl_srcpt). We are making use of the genericCONFIG_NET_DSA_TAG_8021Qcode and leveraging it from our ownCONFIG_NET_DSA_TAG_SJA1105.There are two types of traffic: regular and link-local.
The link-local traffic received on the CPU port is trapped from the switch's regular forwarding decisions because it matched one of the two DMAC filters for management traffic.
On transmission, the switch requires special massaging for these link-local frames. Due to a weird implementation of the switching IP, by default it drops link-local frames that originate on the CPU port. It needs to be told where to forward them to, through an SPI command ("management route") that is valid for only a single frame.
So when we're sending link-local traffic, we need to clone skb's from DSA and send them in our custom xmit worker that also performs SPI access.For that purpose, the DSA xmit handler and the xmit worker communicate through a per-port "skb ring" software structure, with a producer and a consumer index. At the moment this structure is rather fragile (ping-flooding to a link-local DMAC would cause most of the frames to get dropped). I would like to move the management traffic on a separate netdev queue that I can stop when the skb ring got full and hardware is busy processing, so that we are not forced to drop traffic.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>Quoted 7 lines
---
Changes in v3:
Made management traffic be receivable on the DSA netdevices even when switch tagging is disabled, as well as regular traffic be receivable on the master netdevice in the same scenario. Both are accomplished using thesja1105_filter()function and some small touch-ups in the .rcv callback.Quoted 4 lines
It seems like you made major changes to this. When you do that, you should drop any reviewed-by tags you have. They are no longer valid because of the major changes.
Ok, noted.
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled) · line 1161
Quoted 7 lines
/* This callback needs to be present */
drivers/net/dsa/sja1105/sja1105_main.c +1
-1@@ -1141,7 +1158,11 @@ static int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled)if (rc)dev_err (ds->dev,"Failed to change VLAN Ethertype\n" ); -return rc; +/* Switch port identification based on 802.1Q is only passable possible, not passable.
Passable (satisfactory, decent, acceptable) is what I wanted to say. Tagging using VLANs is possible even when the bridge wants to use them, but it's smarter not to go there. But I get your point, maybe I'll rephrase.
Quoted 22 lines
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_main.c +4
-0+* if we are not under a vlan_filtering bridge. So make sure +* the two configurations are mutually exclusive. +*/ +return sja1105_setup_8021q_tagging (ds, !enabled); } static void sja1105_vlan_add(struct dsa_switch *ds, int port,@@ -1233,9 +1254,107 @@ static int sja1105_setup(struct dsa_switch *ds)*/ drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1264
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0ds->vlan_filtering_is_global = true; +/* The DSA/switchdev model brings up switch ports in standalone mode by +* default, and that means vlan_filtering is 0 since they're not under +* a bridge, so it's safe to set up switch tagging at this time. +*/ +return sja1105_setup_8021q_tagging (ds, true); +} + +#include "../../../net/dsa/dsa_priv.h" No. Don't use relative includes like this.
Quoted 3 lines
What do you need from the header? Maybe move it into
include/linux/net/dsa.h
dsa_slave_to_master()Quoted 87 lines
Quoted 71 lines
drivers/net/dsa/sja1105/sja1105_main.c +71
-0+/* Deferred work is unfortunately necessary because setting up the management +* route cannot be done from atomit context (SPI transfer takes a sleepable +* lock on the bus) +*/ +static void sja1105_xmit_work_handler (struct work_struct *work) +{ + struct sja1105_port *sp = container_of(work, struct sja1105_port, + xmit_work); +struct sja1105_private *priv = sp->dp->ds->priv; +struct net_device *slave = sp->dp->slave; +struct net_device *master =dsa_slave_to_master (slave); +int port = (uintptr_t )(sp - priv->ports); +struct sk_buff *skb; +int i, rc; + +while ((i =sja1105_skb_ring_get (&sp->xmit_ring, &skb)) >=0 ) { +struct sja1105_mgmt_entry mgmt_route = {0 }; +struct ethhdr *hdr; +int timeout =10 ; +int skb_len; + + skb_len = skb->len; + hdr =eth_hdr (skb); + + mgmt_route.macaddr =ether_addr_to_u64 (hdr->h_dest); + mgmt_route.destports =BIT (port); + mgmt_route.enfport =1 ; + mgmt_route.tsreg =0 ; + mgmt_route.takets = false; + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true); +if (rc <0 ) { +kfree_skb (skb); + slave->stats.tx_dropped++; +continue ; + } + +/* Transfer skb to the host port. */ + skb->dev = master; +dev_queue_xmit (skb); + +/* Wait until the switch has processed the frame */ +do { + rc =sja1105_dynamic_config_read (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route); +if (rc <0 ) { + slave->stats.tx_errors++; +dev_err (priv->ds->dev, +"xmit: failed to poll for mgmt route\n" ); +continue ; + } + +/* UM10944: The ENFPORT flag of the respective entry is +* cleared when a match is found. The host can use this +* flag as an acknowledgment. +*/ +cpu_relax (); + }while (mgmt_route.enfport && --timeout); + +if (!timeout) { +dev_err (priv->ds->dev,"xmit timed out\n" ); + slave->stats.tx_errors++; +continue ; + } + + slave->stats.tx_packets++; + slave->stats.tx_bytes += skb_len; + } +} +drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1345
Quoted 10 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0+static int sja1105_port_enable (struct dsa_switch *ds,int port, +struct phy_device *phydev) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; + + sp->dp = &ds->ports[port]; +INIT_WORK (&sp->xmit_work, sja1105_xmit_work_handler);return 0 ; }I think i'm missing something here. You have a per port queue of link local frames which need special handling. And you have a per-port work queue. To send such a frame, you need to write some register, send the frame, and then wait until the mgmt_route.enfport is reset.
Quoted 4 lines
Why are you doing this per port? How do you stop two ports/work queues running at the same time? It seems like one queue, with one work queue would be a better structure.
Quoted 9 lines
See the "port" parameter to this call here:
rc = sja1105_dynamic_config_write(priv,
BLK_IDX_MGMT_ROUTE,
*port*,&mgmt_route, true);The switch IP aptly allocates 4 slots for management routes. And it's a 5-port switch where 1 port is the management port. I think the structure is fine.
Quoted 170 lines
"How do stop two work queues": if you're talking about contention on the hardware management route, I responded to that.
If you're talking aboutnetif_stop_queue(), I think I'm going to avoid that altogether by not having a finite sized ring structure. While studying the Marvell 88e6060 driver I found out thatsk_buff_headexists. Now I'm part of the elite club of wheel reinventors with my structsja1105_skb_ring:)Quoted 161 lines
Quoted 3 lines
Also, please move all this code into the tagger. Just add exports for
sja1105_dynamic_config_write()andsja1105_dynamic_config_read().Well, you see, the tagger code is part of the
dsa_coreobject. If I export function symbols from the driver, those still won't be there if I compile the driver as a module. On the other hand, the way I'm doing it, I think theschedule_work()gives me a pretty good separation.Quoted 18 lines
Quoted 18 lines
drivers/net/dsa/sja1105/sja1105_main.c +11
-0+static void sja1105_port_disable (struct dsa_switch *ds,int port) +{ +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[port]; +struct sk_buff *skb; + +cancel_work_sync (&sp->xmit_work); +while (sja1105_skb_ring_get (&sp->xmit_ring, &skb) >=0 ) +kfree_skb (skb); +} +net/dsa/tag_sja1105.c new file +1
-0@@ -0,0 +1,148 @@ +// SPDX-License-Identifier: GPL-2.0 Quoted 9 lines
net/dsa/tag_sja1105.c line 7
Quoted 6 lines
net/dsa/tag_sja1105.c new file +6
-0+/* Copyright (c) 2019, Vladimir Oltean <[email protected]> +*/ +#include <linux/etherdevice.h> +#include <linux/if_vlan.h> +#include <linux/dsa/sja1105.h> +#include "../../drivers/net/dsa/sja1105/sja1105.h" Again, no, don't do this.
This separation between driver and tagger is fairly arbitrary. I need access to the driver's private structure, in order to get a hold of the private shadow of the
dsa_port. Moving the driver private structure toinclude/linux/dsa/would pull in quite a number of dependencies. Maybe I could provide declarations for the most of them, but anyway the private structure wouldn't be so private any longer, would it?
Otherwise put, would you prefer adp->privsimilar to the already existingds->priv? structsja1105_portis much more lightweight to keep ininclude/linux/dsa/.Quoted 21 lines
Quoted 21 lines
net/dsa/tag_sja1105.c new file +21
-0+ +#include "dsa_priv.h" + +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false; +} + +static bool sja1105_filter (const struct sk_buff *skb,struct net_device *dev) +{ +if (sja1105_is_link_local (skb))Quoted 9 lines
net/dsa/tag_sja1105.c line 33
Quoted 5 lines
net/dsa/tag_sja1105.c new file +5
-0+return true; +if (!dev->dsa_ptr->vlan_filtering) +return true; +return false; +}Please add a comment here about what frames cannot be handled by the tagger. However, i'm not too happy about this design...
Ok, let's put this another way.
A switch is primarily a device used to offload the forwarding of traffic based on L2 rules. Additionally there may be some management traffic for stuff like STP that needs to be terminated on the host port of the switch. For that, the hardware's job is to filter and tag management frames on their way to the host port, and the software's job is to process the source port and switch id information in a meaningful way.
Now both this particular switch hardware, and DSA, are taking the above definitions to extremes.
The switch says: "that's all you want to see? ok, so that's all I'm going to give you". So its native (hardware) tagging protocol is to trap link-local traffic and overwrite two bytes of its destination MAC with the switch ID and the source port. No more, no less. It is an incomplete solution, but it does the job for practical use cases. Now DSA says: "I want these to be fully capable net devices, I want the user to not even realize what's going on under the hood". I don't think that terminating iperf traffic through switch ports is a realistic usage scenario. So in a way discussions about performance and optimizations on DSA hotpath are slightly pointless IMO. Now what my driver says is that it offers a bit of both. It speaks the hardware's tagging protocol so it is capable of management traffic, but it also speaks the DSA paradigm, so in a way pushes the hardware to work in a mode it was never intended to, by repurposing VLANs when the user doesn't request them. So on one hand there is some overlap between the hardware tagging protocol and the VLAN one (in standalone mode and in VLAN-unaware bridged mode, management traffic *could* use VLAN tagging but it doesn't rely on it), and on the other hand the reunion of the two tagging protocols is decent, but still doesn't cover the entire spectrum (when put under a VLAN-aware bridge, you lose the ability to decode general traffic). So you'd better not rely on VLANs to decode the management traffic, because you won't be able to always rely on that, and that is a shame since a bridge with bothvlan_filtering1 andstp_state1 is a real usage scenario, and the hardware is capable of that combination.
But all of that is secondary. Let's forget about VLAN tagging for a second and concentrate on the tagging of management traffic. The limiting factor here is the software architecture of DSA, because in order for me to decode that in the driver/tagger, I'd have to drop everything else coming on the master net device (I explained in 13/24 why). I believe that DSA being all-or-nothing about switch tagging is turning a blind eye to the devices that don't go overboard with features, and give you what's needed in a real-world design but not much else.
What would you improve about this design (assuming you're talking about the filter function)?Thanks,
-VladimirQuoted 28 lines
Quoted 15 lines
net/dsa/tag_sja1105.c new file +15
-0+ +static struct sk_buff *sja1105_xmit (struct sk_buff *skb, +struct net_device *netdev) +{ +struct dsa_port *dp =dsa_slave_to_port (netdev); +struct dsa_switch *ds = dp->ds; +struct sja1105_private *priv = ds->priv; +struct sja1105_port *sp = &priv->ports[dp->index]; +struct sk_buff *clone; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ +u16 tx_vid =dsa_tagging_tx_vid (ds, dp->index); +u8 pcp = skb->priority; +net/dsa/tag_sja1105.c line 58
Quoted 10 lines
net/dsa/tag_sja1105.c new file +10
-0+/* If we are under a vlan_filtering bridge, IP termination on +* switch ports based on 802.1Q tags is simply too brittle to +* be passable. So just defer to the dsa_slave_notag_xmit +* implementation. +*/ +if (dp->vlan_filtering) +return skb; + +return dsa_8021q_xmit (skb, netdev,ETH_P_EDSA , + ((pcp <<VLAN_PRIO_SHIFT ) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.
I'm receiving contradictory advice on this. Why should I define a new ethertype, and if I do, what scope should the definition have (local to the driver and the tagger, local to DSA, UAPI)?
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
Quoted 20 lines
net/dsa/tag_sja1105.c new file +20
-0+ } + +/* Code path for transmitting management traffic. This does not rely +* upon switch tagging, but instead SPI-installed management routes. +*/ + clone =skb_clone (skb,GFP_ATOMIC ); +if (!clone) { +dev_err (ds->dev,"xmit: failed to clone skb\n" ); +return NULL ; + } + +if (sja1105_skb_ring_add (&sp->xmit_ring, clone) <0 ) { +dev_err (ds->dev,"xmit: skb ring full\n" ); +kfree_skb (clone); +return NULL ; + } + +if (sp->xmit_ring.count ==SJA1105_SKB_RING_SIZE ) +/* TODO setup a dedicated netdev queue for management traffic +* so that we can selectively apply backpressure and not be
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
net/dsa/tag_sja1105.c line 83
Quoted 5 lines
net/dsa/tag_sja1105.c new file +5
-0+* required to stop the entire traffic when the software skb +* ring is full. This requires hooking the ndo_select_queue +* from DSA and matching on mac_fltres. +*/ +dev_err (ds->dev,"xmit: reached maximum skb ring size\n" );This should be rate limited.
Again, with sk_buff_head it'll probably completely go away.
Quoted 70 lines
Quoted 70 lines
Quoted 70 lines
Andrew
Quoted 68 lines
net/dsa/tag_sja1105.c new file +65
-1+ +schedule_work (&sp->xmit_work); +/* Let DSA free its reference to the skb and we will free +* the clone in the deferred worker +*/ +return NULL ; +} + +static struct sk_buff *sja1105_rcv (struct sk_buff *skb, +struct net_device *netdev, +struct packet_type *pt) +{ +unsigned int source_port, switch_id; +struct ethhdr *hdr =eth_hdr (skb); +struct sk_buff *nskb; +u16 tpid, vid, tci; +bool is_tagged; + + nskb =dsa_8021q_rcv (skb, netdev, pt, &tpid, &tci); + is_tagged = (nskb && tpid ==ETH_P_EDSA ); + + skb->priority = (tci &VLAN_PRIO_MASK ) >>VLAN_PRIO_SHIFT ; + vid = tci &VLAN_VID_MASK ; + + skb->offload_fwd_mark =1 ; + +if (likely (!sja1105_is_link_local (skb))) { +/* Normal traffic path. */ + source_port =dsa_tagging_rx_source_port (vid); + switch_id =dsa_tagging_rx_switch_id (vid); + }else { +/* Management traffic path. Switch embeds the switch ID and +* port ID into bytes of the destination MAC, courtesy of +* the incl_srcpt options. +*/ + source_port = hdr->h_dest[3 ]; + switch_id = hdr->h_dest[4 ]; +/* Clear the DMAC bytes that were mangled by the switch */ + hdr->h_dest[3 ] =0 ; + hdr->h_dest[4 ] =0 ; + } + + skb->dev =dsa_master_find_slave (netdev, switch_id, source_port); +if (!skb->dev) { +netdev_warn (netdev,"Couldn't decode source port\n" ); +return NULL ; + } + +/* Delete/overwrite fake VLAN header, DSA expects to not find +* it there, see dsa_switch_rcv: skb_push(skb, ETH_HLEN). +*/ +if (is_tagged) +memmove (skb->data -ETH_HLEN , skb->data -ETH_HLEN -VLAN_HLEN , +ETH_HLEN -VLAN_HLEN ); + +return skb; +} + +const struct dsa_device_ops sja1105_netdev_ops = { + .xmit = sja1105_xmit, + .rcv = sja1105_rcv, + .filter = sja1105_filter, + .overhead =VLAN_HLEN , +}; + --2.17.1
Andrew Lunn
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 9 lines
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines
net/dsa/tag_sja1105.c line 58
Quoted 2 lines
net/dsa/tag_sja1105.c new file +2
-0+return dsa_8021q_xmit (skb, netdev,ETH_P_EDSA , + ((pcp <<VLAN_PRIO_SHIFT ) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.I'm receiving contradictory advice on this. Why should I define a new ethertype, and if I do, what scope should the definition have (local to the driver and the tagger, local to DSA, UAPI)?
ETH_P_EDSA has a well defined meaning. It is a true global EtherType, and means a Marvell EtherType DSA header follows.
You are polluting this meaning of ETH_P_EDSA. Would you put ETH_P_IP or ETH_P_8021AD here?
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 11 lines · Andrew Lunn
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
net/dsa/tag_sja1105.c line 58
Quoted 3 lines
net/dsa/tag_sja1105.c new file +2
-0+return dsa_8021q_xmit (skb, netdev,ETH_P_EDSA , + ((pcp <<VLAN_PRIO_SHIFT ) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.I'm receiving contradictory advice on this. Why should I define a new ethertype, and if I do, what scope should the definition have (local to the driver and the tagger, local to DSA, UAPI)?
Quoted 7 lines
ETH_P_EDSAhas a well defined meaning. It is a true global EtherType, and means a Marvell EtherType DSA header follows.You are polluting this meaning of
ETH_P_EDSA. Would you putETH_P_IPorETH_P_8021ADhere?Andrew
You are putting an equality sign here between things that are not quite equal. The MEDSA EtherType is used for the same purpose as what I'm using it for. The only situation when I can receive ETH_P_EDSA frames is if somebody designed a system with a cascaded SJA1105 and a MV88E6xx. I think that's unlikely but I might be wrong.
Don't get me wrong, I could use literally any EtherType and that's exactly why I'm reluctant to define a new one.
The only thing is that if I pick an EtherType smaller than 1500 (LLC/SNAP) like ETH_P_XDSA (or even zero works), then I get the hardware incrementing the n_sizeerr counter for each received tagged frame (it doesn't drop it, though).
-Vladimir
Andrew Lunn
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 15 lines · Vladimir Oltean
Quoted 14 lines · Andrew Lunn
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return dsa_8021q_xmit(skb, netdev, ETH_P_EDSA, + ((pcp << VLAN_PRIO_SHIFT) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.I'm receiving contradictory advice on this. Why should I define a new ethertype, and if I do, what scope should the definition have (local to the driver and the tagger, local to DSA, UAPI)?
ETH_P_EDSAhas a well defined meaning. It is a true global EtherType, and means a Marvell EtherType DSA header follows.
Quoted 7 lines
Quoted 4 lines
You are polluting this meaning of
ETH_P_EDSA. Would you putETH_P_IPorETH_P_8021ADhere?Andrew
You are putting an equality sign here between things that are not quite equal. The MEDSA EtherType is used for the same purpose as what I'm using it for.
I don't think it is. tcpdump will match on this EtherType and decode what follows as an EDSA header, just in the same way it matches a ETH_P_IP and decodes what comes next as an IP packet. I also have wireshark patches, which i never submitted, which do the same.
Please run tcpdump on the master interface with your test system and see what it does.
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 30 lines · Andrew Lunn
Quoted 15 lines · Vladimir Oltean
Quoted 14 lines · Andrew Lunn
Quoted 10 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Review
Quoted 3 lines
(quoted diff) +2
-0+ return dsa_8021q_xmit(skb, netdev, ETH_P_EDSA, + ((pcp << VLAN_PRIO_SHIFT) | tx_vid));Please don't reuse
ETH_P_EDSA. Define anETH_P_SJA1105.I'm receiving contradictory advice on this. Why should I define a new ethertype, and if I do, what scope should the definition have (local to the driver and the tagger, local to DSA, UAPI)?
ETH_P_EDSAhas a well defined meaning. It is a true global EtherType, and means a Marvell EtherType DSA header follows.Quoted 7 lines
Quoted 4 lines
You are polluting this meaning of
ETH_P_EDSA. Would you putETH_P_IPorETH_P_8021ADhere?Andrew
You are putting an equality sign here between things that are not quite equal. The MEDSA EtherType is used for the same purpose as what I'm using it for.
I don't think it is. tcpdump will match on this EtherType and decode what follows as an EDSA header, just in the same way it matches a
ETH_P_IPand decodes what comes next as an IP packet. I also have wireshark patches, which i never submitted, which do the same.
Quoted 4 lines
Please run tcpdump on the master interface with your test system and see what it does.
Andrew
It fails to decode the frames, obviously. But so does any other EtherType. Florian was hinting
(https://lwn.net/ml/netdev/[email protected]/)
at the recent pull requests submitted to tcpdump and libpcap that make it possible to decode based on the string in /sys/class/net/${master}/dsa/tagging. I admit I haven't actually tested or studied those closely yet (there are more important things to focus on ATM), but since my driver returns "8021q" in sysfs and yours returns "edsa", I would presume tcpdump could use that information. Anyway, since you obviously know more on this topic than I do, please make me understand what are the real problems in spoofing the Ethertype as a Marvell one.
Thanks,
-Vladimir
Andrew Lunn
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 11 lines
It fails to decode the frames, obviously. But so does any other EtherType.
Florian was hinting
(https://lwn.net/ml/netdev/[email protected]/)
at the recent pull requests submitted to tcpdump and libpcap that make it possible to decode based on the string in/sys/class/net/${master}/dsa/tagging. I admit I haven't actually tested or studied those closely yet (there are more important things to focus on ATM), but since my driver returns "8021q" in sysfs and yours returns "edsa", I would presume tcpdump could use that information.
No it does not. It is a valid EtherType, that is what is used to trigger the decoding, it takes no notice of what is in /sys/class/net/${master}/dsa/tagging, nor the extra meta-data added to the pcap file. There is no need. you can identify it is a Marvell EDSA header from the EtherType.
In fact, this tcpdump code for decoding EDSA pre-dated Florians patches by a few years.
You only need the code which Florian added when you cannot identify the header directly from the packet. And that is true for most of the tagging protocols. But EDSA you can.
Quoted 3 lines
Anyway, since you obviously know more on this topic than I do, please make me understand what are the real problems in spoofing the Ethertype as a Marvell one.
Despite there being an EDSA EtherType in the frame, what follows is not an ESDA header. It is like having the IPv4 EtherType but what following is not an IP header. Broken.
Andrew
Re: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 18 lines · Andrew Lunn
Quoted 11 lines
It fails to decode the frames, obviously. But so does any other EtherType.
Florian was hinting
(https://lwn.net/ml/netdev/[email protected]/)
at the recent pull requests submitted to tcpdump and libpcap that make it possible to decode based on the string in/sys/class/net/${master}/dsa/tagging. I admit I haven't actually tested or studied those closely yet (there are more important things to focus on ATM), but since my driver returns "8021q" in sysfs and yours returns "edsa", I would presume tcpdump could use that information.No it does not. It is a valid EtherType, that is what is used to trigger the decoding, it takes no notice of what is in
/sys/class/net/${master}/dsa/tagging, nor the extra meta-data added to the pcap file. There is no need. you can identify it is a Marvell EDSA header from the EtherType.
Quoted 6 lines
In fact, this tcpdump code for decoding EDSA pre-dated Florians patches by a few years.
You only need the code which Florian added when you cannot identify the header directly from the packet. And that is true for most of the tagging protocols. But EDSA you can.
Correct.
Quoted 8 lines
Quoted 4 lines
Anyway, since you obviously know more on this topic than I do, please make me understand what are the real problems in spoofing the Ethertype as a Marvell one.
Despite there being an EDSA EtherType in the frame, what follows is not an ESDA header. It is like having the IPv4 EtherType but what following is not an IP header. Broken.
I suppose this is a valid point, but in that case any EtherType would do and technically using ETH_P_EDSA is just an one of the many possible choices for configuring the Marvell EDSA EtherType, you just need to pick one that is not going to trick the switching into thinking this is invalid LLC/SNAP.
With Vivien's latest tcpdump changes, I don't think we need to rely on ETH_P_EDSA to be present anyway since the kernel tells us (when available).
Signature · 1 line
Florian
Andrew Lunn
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
In reply to Vladimir OlteanQuoted 9 lines · Vladimir Oltean
Quoted 8 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1296
Quoted 8 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0+ mgmt_route.macaddr =ether_addr_to_u64 (hdr->h_dest); + mgmt_route.destports =BIT (port); + mgmt_route.enfport =1 ; + mgmt_route.tsreg =0 ; + mgmt_route.takets = false; + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true);
Quoted 6 lines
rc = sja1105_dynamic_config_write(priv,
BLK_IDX_MGMT_ROUTE,
*port*,&mgmt_route, true);The switch IP aptly allocates 4 slots for management routes. And it's a 5-port switch where 1 port is the management port. I think the structure is fine.
So does the hardware look over all the slots and find the first one which has a matching mgmt_route.macaddr destination MAC address? You wait for the enfport to be cleared. I assume a slot with enfport cleared is not active and won't match?
So we need to consider if there is a race condition where we have multiple slots with the same destination MAC address, but different destination ports? Say the bridge sends out BPDU to all ports of a bridge in quick succession.
These work queues run in any order, and can sleep. Can we get into a situation where we get the two slots setup, and then the frames sent in reverse order? The match then happens backwards, and the frames get sent out the wrong port?
Or say the two slots are setup, the two frames are sent in order, but the stack decided to drop the first frame because buffers are full. Can the second frame make it to the switch and match on the first slot and go out the wrong port?
Quoted 8 lines
Quoted 3 lines
Also, please move all this code into the tagger. Just add exports for
sja1105_dynamic_config_write()andsja1105_dynamic_config_read().Well, you see, the tagger code is part of the
dsa_coreobject. If I export function symbols from the driver, those still won't be there if I compile the driver as a module. On the other hand, the way I'm doing it, I think theschedule_work()gives me a pretty good separation.
That is solvable via Kconfig, don't allow it to be built as a module.
Also, DSA has been very successful, we keep getting more switches from different vendors, and hence more taggers. So at some point, we should turn the taggers into modules. I'm not saying that should happen now, but when it does happen, this driver can then become a module.
The real reason is, tagger as all about handling frames, where as drivers are all about configuring the switch. The majority of this code is about frames, so it belongs in the tagger.
Quoted 8 lines
Quoted 7 lines
net/dsa/tag_sja1105.c line 7
Quoted 4 lines
net/dsa/tag_sja1105.c new file +4
-0+#include <linux/etherdevice.h> +#include <linux/if_vlan.h> +#include <linux/dsa/sja1105.h> +#include "../../drivers/net/dsa/sja1105/sja1105.h" Again, no, don't do this.
Quoted 10 lines
This separation between driver and tagger is fairly arbitrary. I need access to the driver's private structure, in order to get a hold of the private shadow of the
dsa_port. Moving the driver private structure toinclude/linux/dsa/would pull in quite a number of dependencies. Maybe I could provide declarations for the most of them, but anyway the private structure wouldn't be so private any longer, would it?
Otherwise put, would you prefer adp->privsimilar to the already existingds->priv? structsja1105_portis much more lightweight to keep ininclude/linux/dsa/.
Linux simply does not make use of relative paths going between directories like this. That is the key point here. Whatever you need to share between the tagger and the driver has to be put into include/linux/dsa/.
Assuming we are just exporting something likesja1105_dynamic_config_write() and _read()
Quoted 2 lines
Quoted 2 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1296
Quoted 2 lines
drivers/net/dsa/sja1105/sja1105_main.c +2
-0+ rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true);
priv can be replaced with ds, which the tagger has. port is known. BLK_IDX_MGMT_ROUTE is implicit, and all that the tagger needs to pass for mgmt_route is the destination MAC address, which it has.
The tagger does need somewhere to keep the queue of frames to be sent and its workqueue. I would probably add a void *tagger_priv to dsa_switch, and two new methods to dsa_device_ops, .probe and .release, to allow it to create and destroy what it needs in tagger_priv.
Quoted 30 lines
Quoted 20 lines
Quoted 20 lines
net/dsa/tag_sja1105.c new file +20
-0+#include "dsa_priv.h" + +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false; +} + +static bool sja1105_filter (const struct sk_buff *skb,struct net_device *dev) +{ +if (sja1105_is_link_local (skb))Quoted 9 lines
net/dsa/tag_sja1105.c line 33
Quoted 5 lines
net/dsa/tag_sja1105.c new file +5
-0+return true; +if (!dev->dsa_ptr->vlan_filtering) +return true; +return false; +}Please add a comment here about what frames cannot be handled by the tagger. However, i'm not too happy about this design...
Quoted 2 lines
What would you improve about this design (assuming you're talking about the filter function)?
I want to understand what frames get passed via the master device, and how ultimately they get to where they should be going.
Once i understand what sort of frames they are and what is generating/consuming them, maybe we can find a better solution which preserves the DSA concepts.
To me, it looks like they are not management frames, at least not BPDU or PTP, since they are link local. If VLAN filtering is off, the VLAN tag tells us which port they came in, so we can strip the tag and pass them to the correct slave.
So it looks like real user frames with a VLAN tag are getting passed to the master device. So i then assume you put vlan interfaces on top of the master device, and your application then uses the vlan interfaces? Your application does not care where the frames came from, it is using the switch as a dumb switch. The DSA slaves are unused?
Could we enforce that a VLAN can only be assigned to a single port? The tagger could then pass the tagged frame to the correct slave? Is that too restrictive for your use case? Do you need the same VLAN on multiple ports.
Andrew
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 28 lines · Andrew Lunn
Quoted 9 lines · Vladimir Oltean
Quoted 8 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1296
Quoted 8 lines
drivers/net/dsa/sja1105/sja1105_main.c +8
-0+ mgmt_route.macaddr =ether_addr_to_u64 (hdr->h_dest); + mgmt_route.destports =BIT (port); + mgmt_route.enfport =1 ; + mgmt_route.tsreg =0 ; + mgmt_route.takets = false; + + rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true);Quoted 6 lines
rc = sja1105_dynamic_config_write(priv,
BLK_IDX_MGMT_ROUTE,
*port*,&mgmt_route, true);The switch IP aptly allocates 4 slots for management routes. And it's a 5-port switch where 1 port is the management port. I think the structure is fine.
So does the hardware look over all the slots and find the first one which has a matching mgmt_route.macaddr destination MAC address? You wait for the enfport to be cleared. I assume a slot with enfport cleared is not active and won't match?
So we need to consider if there is a race condition where we have multiple slots with the same destination MAC address, but different destination ports? Say the bridge sends out BPDU to all ports of a bridge in quick succession.
Quoted 5 lines
These work queues run in any order, and can sleep. Can we get into a situation where we get the two slots setup, and then the frames sent in reverse order? The match then happens backwards, and the frames get sent out the wrong port?
Yes, it looks like the hardware isn't doing me any favors on this one. From UM10944: "If the host provides several management route entries with identical values for the MACADDR, the one at the lowest index is used first."
So the 4 hardware management slots serve no purpose unless I'm willing to lock the sja1105_xmit_work_handler with a mutex. And even then there's no reason to use separate slots since the workers are serialized anyway. Weird.
Quoted 5 lines
Or say the two slots are setup, the two frames are sent in order, but the stack decided to drop the first frame because buffers are full. Can the second frame make it to the switch and match on the first slot and go out the wrong port?
Yes if waiting for enfport times out there's some cleanup work I'm currently not doing.
Quoted 11 lines
Quoted 8 lines
Quoted 3 lines
Also, please move all this code into the tagger. Just add exports for
sja1105_dynamic_config_write()andsja1105_dynamic_config_read().Well, you see, the tagger code is part of the
dsa_coreobject. If I export function symbols from the driver, those still won't be there if I compile the driver as a module. On the other hand, the way I'm doing it, I think theschedule_work()gives me a pretty good separation.That is solvable via
Kconfig, don't allow it to be built as a module.
Quoted 9 lines
Also, DSA has been very successful, we keep getting more switches from different vendors, and hence more taggers. So at some point, we should turn the taggers into modules. I'm not saying that should happen now, but when it does happen, this driver can then become a module.
The real reason is, tagger as all about handling frames, where as drivers are all about configuring the switch. The majority of this code is about frames, so it belongs in the tagger.
The xmit worker needs to configure the switch to be able to handle frames. Why doesn't that belong in the driver?
Not allowing the driver to be built as module is hardly any cleaner than a schedule_work().
I only need dsa_slave_to_master for the delayed enqueue. And if DSA supported a delayed enqueue method natively I wouldn't need it at all.
Quoted 35 lines
Quoted 8 lines
Quoted 7 lines
net/dsa/tag_sja1105.c line 7
Quoted 4 lines
net/dsa/tag_sja1105.c new file +4
-0+#include <linux/etherdevice.h> +#include <linux/if_vlan.h> +#include <linux/dsa/sja1105.h> +#include "../../drivers/net/dsa/sja1105/sja1105.h" Again, no, don't do this.
Quoted 10 lines
This separation between driver and tagger is fairly arbitrary. I need access to the driver's private structure, in order to get a hold of the private shadow of the
dsa_port. Moving the driver private structure toinclude/linux/dsa/would pull in quite a number of dependencies. Maybe I could provide declarations for the most of them, but anyway the private structure wouldn't be so private any longer, would it?
Otherwise put, would you prefer adp->privsimilar to the already existingds->priv? structsja1105_portis much more lightweight to keep ininclude/linux/dsa/.Linux simply does not make use of relative paths going between directories like this. That is the key point here. Whatever you need to share between the tagger and the driver has to be put into
include/linux/dsa/.Assuming we are just exporting something like
sja1105_dynamic_config_write()and_read()Quoted 2 lines
Quoted 2 lines
drivers/net/dsa/sja1105/sja1105_main.c static int sja1105_setup(struct dsa_switch *ds) · line 1296
Quoted 2 lines
drivers/net/dsa/sja1105/sja1105_main.c +2
-0+ rc =sja1105_dynamic_config_write (priv,BLK_IDX_MGMT_ROUTE , + port, &mgmt_route, true);priv can be replaced with ds, which the tagger has. port is known.
BLK_IDX_MGMT_ROUTEis implicit, and all that the tagger needs to pass formgmt_routeis the destination MAC address, which it has.
Quoted 6 lines
The tagger does need somewhere to keep the queue of frames to be sent and its workqueue. I would probably add a void
*tagger_privtodsa_switch, and two new methods todsa_device_ops, .probe and .release, to allow it to create and destroy what it needs intagger_priv.
I need to think about this.
Quoted 45 lines
Quoted 30 lines
Quoted 20 lines
Quoted 20 lines
net/dsa/tag_sja1105.c new file +20
-0+#include "dsa_priv.h" + +/* Similar to is_link_local_ether_addr(hdr->h_dest) but also covers PTP */ +static inline bool sja1105_is_link_local (const struct sk_buff *skb) +{ +const struct ethhdr *hdr =eth_hdr (skb); +u64 dmac =ether_addr_to_u64 (hdr->h_dest); + +if ((dmac &SJA1105_LINKLOCAL_FILTER_A_MASK ) == +SJA1105_LINKLOCAL_FILTER_A ) +return true; +if ((dmac &SJA1105_LINKLOCAL_FILTER_B_MASK ) == +SJA1105_LINKLOCAL_FILTER_B ) +return true; +return false; +} + +static bool sja1105_filter (const struct sk_buff *skb,struct net_device *dev) +{ +if (sja1105_is_link_local (skb))Quoted 9 lines
net/dsa/tag_sja1105.c line 33
Quoted 5 lines
net/dsa/tag_sja1105.c new file +5
-0+return true; +if (!dev->dsa_ptr->vlan_filtering) +return true; +return false; +}Please add a comment here about what frames cannot be handled by the tagger. However, i'm not too happy about this design...
Quoted 2 lines
What would you improve about this design (assuming you're talking about the filter function)?
I want to understand what frames get passed via the master device, and how ultimately they get to where they should be going.
Once i understand what sort of frames they are and what is generating/consuming them, maybe we can find a better solution which preserves the DSA concepts.
To me, it looks like they are not management frames, at least not BPDU or PTP, since they are link local. If VLAN filtering is off, the VLAN tag tells us which port they came in, so we can strip the tag and pass them to the correct slave.
Quoted 6 lines
So it looks like real user frames with a VLAN tag are getting passed to the master device. So i then assume you put vlan interfaces on top of the master device, and your application then uses the vlan interfaces? Your application does not care where the frames came from, it is using the switch as a dumb switch. The DSA slaves are unused?
Whatever the application may be, the DSA solution to switches that can't decode all incoming traffic is to drop the rest. In this case it means that the host port is no longer a valid destination for the L2 switching process.
Quoted 6 lines
Could we enforce that a VLAN can only be assigned to a single port? The tagger could then pass the tagged frame to the correct slave? Is that too restrictive for your use case? Do you need the same VLAN on multiple ports.
Andrew
No we can't enforce that. The commit message of 07/24 has a pretty lengthy explanation why.
Thanks,
-Vladimir
Andrew Lunn
maintainerRe: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
Quoted 8 lines
Yes, it looks like the hardware isn't doing me any favors on this one.
Quoted 1 line
From UM10944: "If the host provides several management route entries
with identical values for the MACADDR, the one at the lowest index is used first."
So the 4 hardware management slots serve no purpose unless I'm willing to lock thesja1105_xmit_work_handlerwith a mutex. And even then there's no reason to use separate slots since the workers are serialized anyway. Weird.
So you can simply this down to just using one queue. Maybe even one queue for all instances of this switch. You can then keep it all as static private structures in the tag driver, maybe not even needing ds->tag_priv.
Quoted 4 lines
Quoted 4 lines
Also, DSA has been very successful, we keep getting more switches from different vendors, and hence more taggers. So at some point, we should turn the taggers into modules. I'm not saying that should happen now, but when it does happen, this driver can then become a module.
FYI: I started on this already. There might be patches today to allow the tag drivers to be kernel modules.
Andrew
Re: [PATCH v3 net-next 18/24] net: dsa: sja1105: Add support for traffic through standalone ports
In reply to Vladimir OlteanQuoted 16 lines · Vladimir Oltean
Ok, let's put this another way.
A switch is primarily a device used to offload the forwarding of traffic based on L2 rules. Additionally there may be some management traffic for stuff like STP that needs to be terminated on the host port of the switch. For that, the hardware's job is to filter and tag management frames on their way to the host port, and the software's job is to process the source port and switch id information in a meaningful way.
Now both this particular switch hardware, and DSA, are taking the above definitions to extremes.
The switch says: "that's all you want to see? ok, so that's all I'm going to give you". So its native (hardware) tagging protocol is to trap link-local traffic and overwrite two bytes of its destination MAC with the switch ID and the source port. No more, no less. It is an incomplete solution, but it does the job for practical use cases.
Indeed.
Quoted 5 lines
Now DSA says: "I want these to be fully capable net devices, I want the user to not even realize what's going on under the hood". I don't think that terminating iperf traffic through switch ports is a realistic usage scenario. So in a way discussions about performance and optimizations on DSA hotpath are slightly pointless IMO.
Actually it is on Broadcom devices that I directly or indirectly helped to support with bcm_sf2/b53 we have 2Gb/sec capable management ports and we run iperf directly on the host CPUs. Some ports remain standalone (e.g.: WAN) and the others can be bridged together (LAN + WLAN).
Quoted 16 lines
Now what my driver says is that it offers a bit of both. It speaks the hardware's tagging protocol so it is capable of management traffic, but it also speaks the DSA paradigm, so in a way pushes the hardware to work in a mode it was never intended to, by repurposing VLANs when the user doesn't request them. So on one hand there is some overlap between the hardware tagging protocol and the VLAN one (in standalone mode and in VLAN-unaware bridged mode, management traffic *could* use VLAN tagging but it doesn't rely on it), and on the other hand the reunion of the two tagging protocols is decent, but still doesn't cover the entire spectrum (when put under a VLAN-aware bridge, you lose the ability to decode general traffic). So you'd better not rely on VLANs to decode the management traffic, because you won't be able to always rely on that, and that is a shame since a bridge with both
vlan_filtering1 andstp_state1 is a real usage scenario, and the hardware is capable of that combination.
But all of that is secondary. Let's forget about VLAN tagging for a
Quoted 8 lines
second and concentrate on the tagging of management traffic. The limiting factor here is the software architecture of DSA, because in order for me to decode that in the driver/tagger, I'd have to drop everything else coming on the master net device (I explained in 13/24 why). I believe that DSA being all-or-nothing about switch tagging is turning a blind eye to the devices that don't go overboard with features, and give you what's needed in a real-world design but not much else.
I would word it differently and say that up until now, whatever DSA assumed about switches was something that was supportable and with the sja1105 we are faced with an interesting of limits on both designs. I don't think DSA is unreasonable in assuming that management frame is always tagged with a proprietary switch protocol; because that's what has happened across a wide variety of vendors. The NXP SJA1105 is not unreasonable but it does present some challenges.
Quoted 2 lines
What would you improve about this design (assuming you're talking about the filter function)?
Would assigning different MAC addresses to each standalone port help in any way such that you could leverage filtering in HW based on MAC DA?
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 19/24 net: dsa: sja1105: Add support for Spanning Tree Protocol
In reply to Vladimir OlteanWhile not explicitly documented as supported in UM10944, compliance with the STP states can be obtained by manipulating 3 settings at the (per-port) MAC config level: dynamic learning, inhibiting reception of regular traffic, and inhibiting transmission of regular traffic.
In all these modes, transmission and reception of special BPDU frames from the stack is still enabled (not inhibited by the MAC-level settings).
On ingress, BPDUs are classified by the MAC filter as link-local (01-80-C2-00-00-00) and forwarded to the CPU port. This mechanism works under all conditions (even without the custom 802.1Q tagging) because the switch hardware inserts the source port and switch ID into bytes 4 and 5 of the MAC-filtered frames. Then the DSA .rcv handler needs to put back zeroes into the MAC address after decoding the source port information.
On egress, BPDUs are transmitted using management routes from the xmit worker thread. Again this does not require switch tagging, as the switch port is programmed through SPI to hold a temporary (single-fire) route for a frame with the programmed destination MAC (01-80-C2-00-00-00).
STP is activated using the following commands and was tested by connecting two front-panel ports together and noticing that switching loops were prevented (one port remains in the blocking state):
$ ip link add name br0 type bridge stp_state 1 && ip link set br0 up
$ for eth in $(ls /sys/devices/platform/soc/2100000.spi/spi_master/spi0/spi0.1/net/);
do ip link set ${eth} master br0 && ip link set ${eth} up; done---
Changes in v3:
Added verbiage to the commit message.
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 )
@@ -1367,6 +1456,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
Re: [PATCH v3 net-next 19/24] net: dsa: sja1105: Add support for Spanning Tree Protocol
Quoted 26 lines · Vladimir Oltean
While not explicitly documented as supported in UM10944, compliance with the STP states can be obtained by manipulating 3 settings at the (per-port) MAC config level: dynamic learning, inhibiting reception of regular traffic, and inhibiting transmission of regular traffic.
In all these modes, transmission and reception of special BPDU frames from the stack is still enabled (not inhibited by the MAC-level settings).
On ingress, BPDUs are classified by the MAC filter as link-local (01-80-C2-00-00-00) and forwarded to the CPU port. This mechanism works under all conditions (even without the custom 802.1Q tagging) because the switch hardware inserts the source port and switch ID into bytes 4 and 5 of the MAC-filtered frames. Then the DSA .rcv handler needs to put back zeroes into the MAC address after decoding the source port information.
On egress, BPDUs are transmitted using management routes from the xmit worker thread. Again this does not require switch tagging, as the switch port is programmed through SPI to hold a temporary (single-fire) route for a frame with the programmed destination MAC (01-80-C2-00-00-00).
STP is activated using the following commands and was tested by connecting two front-panel ports together and noticing that switching loops were prevented (one port remains in the blocking state):
Quoted 5 lines
$ ip link add name br0 type bridge stp_state 1 && ip link set br0 up $ for eth in $(ls /sys/devices/platform/soc/2100000.spi/spi_master/spi0/spi0.1/net/); do ip link set ${eth} master br0 && ip link set ${eth} up; doneSigned-off-by Vladimir Oltean <[email protected]>
Andrew
Vladimir Oltean
maintainerPATCH v3 20/24 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 v3:
None.
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)
@@ -1315,13 +1330,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
Re: [PATCH v3 net-next 20/24] net: dsa: sja1105: Error out if RGMII delays are requested in DT
Quoted 21 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.
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?
Quoted 6 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.
That is a good interpretation. I always recommend the PHY does the delay, because in general the PHY can, and often the MAC cannot.
Quoted 3 lines
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>
Andrew
Re: [PATCH v3 net-next 20/24] net: dsa: sja1105: Error out if RGMII delays are requested in DT
In reply to Vladimir OlteanQuoted 195 lines · Sat, Apr 13, 2019 at 03:28:18AM CEST, [email protected] wrote:
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.
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.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in v3:
None.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)@@ -1315,13 +1330,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 +5
-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",
drivers/net/dsa/sja1105/sja1105_spi.c struct sja1105_info sja1105s_info = { · line 553
Quoted 4 lines
drivers/net/dsa/sja1105/sja1105_spi.c +1
-0@@ -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,
You don't need to set this to NULL. Please avoid that.
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_spi.c +0
-0.reset_cmd = sja1105pqrs_reset_cmd, .name = "SJA1105S", };Signature · 1 line
2.17.1
Vladimir Oltean
maintainerRe: [PATCH v3 net-next 20/24] net: dsa: sja1105: Error out if RGMII delays are requested in DT
Quoted 195 lines · Jiri Pirko
Quoted 193 lines · Sat, Apr 13, 2019 at 03:28:18AM CEST, [email protected] wrote:
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.
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.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in v3:
None.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)@@ -1315,13 +1330,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 +5
-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,
Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_spi.c struct sja1105_info sja1105s_info = { · line 553
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_spi.c +1
-0.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,You don't need to set this to NULL. Please avoid that.
Hi Jiri, why not?
Thanks,
-Vladimir
Quoted 7 lines
Quoted 7 lines
drivers/net/dsa/sja1105/sja1105_spi.c +0
-1.reset_cmd = sja1105pqrs_reset_cmd, .name = "SJA1105S", }; --2.17.1
Re: [PATCH v3 net-next 20/24] net: dsa: sja1105: Error out if RGMII delays are requested in DT
Quoted 206 lines · Sat, Apr 13, 2019 at 11:31:01PM CEST, [email protected] wrote:
Quoted 195 lines · Jiri Pirko
Quoted 193 lines · Sat, Apr 13, 2019 at 03:28:18AM CEST, [email protected] wrote:
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.
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.
Signed-off-by Vladimir Oltean <[email protected]>Reviewed-by Florian Fainelli <[email protected]>---
Changes in v3:
None.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)@@ -1315,13 +1330,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 +5
-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,Quoted 9 lines
drivers/net/dsa/sja1105/sja1105_spi.c struct sja1105_info sja1105s_info = { · line 553
Quoted 6 lines
drivers/net/dsa/sja1105/sja1105_spi.c +1
-0.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,You don't need to set this to NULL. Please avoid that.
Quoted 1 line
Hi Jiri, why not?
If you don't assign, it is already NULL. so the assignment to NULL is pointless.
Quoted 11 lines
Thanks,
-VladimirQuoted 7 lines
Quoted 7 lines
drivers/net/dsa/sja1105/sja1105_spi.c +0
-1.reset_cmd = sja1105pqrs_reset_cmd, .name = "SJA1105S", }; --2.17.1
Vladimir Oltean
maintainerPATCH v3 21/24 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 v3:
None.
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105.h | 1 + drivers/net/dsa/sja1105/sja1105_spi.c | 37 +++++++++++++++++++++++++++ 2 files changed, 38 insertions(+)
drivers/net/dsa/sja1105/sja1105.h +1 -0
@@ -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 +*/ +usleep_range (500 ,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
Re: [PATCH v3 net-next 21/24] net: dsa: sja1105: Prevent PHY jabbering during switch reset
Quoted 14 lines · Vladimir Oltean
Resetting the switch at runtime is currently done while changing the
vlan_filteringsetting (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.
Quoted 6 lines
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.
Signed-off-by Vladimir Oltean <[email protected]>
Andrew
Vladimir Oltean
maintainerPATCH v3 22/24 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 v3:
None.
Changes in v2:
Patch is new.
drivers/net/dsa/sja1105/sja1105_main.c | 31 ++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
drivers/net/dsa/sja1105/sja1105_main.c +31 -0
@@ -11,6 +11,7 @@#include <linux/spi/spi.h> #include <linux/errno.h> #include <linux/gpio/consumer.h> +#include <linux/phylink.h> #include <linux/of.h> #include <linux/of_net.h> #include <linux/of_mdio.h>
@@ -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) \
@@ -1478,6 +1508,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 v3 23/24 Documentation: net: dsa: Add details about NXP SJA1105 driver
In reply to Vladimir Oltean---
Changes in v3:
Reworked as rst, added a table for traffic support, added chapter for switching features.
Changes in v2:
More verbiage at the end, regarding RGMII delays and potentially other hardware-related caveats.
Documentation/networking/dsa/index.rst | 1 + Documentation/networking/dsa/sja1105.rst | 216 +++++++++++++++++++++++ 2 files changed, 217 insertions(+) create mode 100644 Documentation/networking/dsa/sja1105.rst
Documentation/networking/dsa/index.rst +1 -0
@@ -8,3 +8,4 @@ Distributed Switch Architecture dsa bcm_sf2 lan9303 + sja1105
Documentation/networking/dsa/sja1105.rst new file +216 -0
216 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 net-next 23/24] Documentation: net: dsa: Add details about NXP SJA1105 driver
On 12/04/2019 18:28, Vladimir Oltean wrote:
[snip]
Documentation/networking/dsa/sja1105.rst line 125
Quoted 6 lines
Documentation/networking/dsa/sja1105.rst new file +6
-0+Segregating the switch ports in multiple bridges is supported (e.g. 2 + 2), but +all bridges should have the same level of VLAN awareness (either both have +``vlan_filtering`` 0, or both 1). Also an inevitable limitation of the fact +that VLAN awareness is global at the switch level is that once a bridge with +``vlan_filtering`` enslaves at least one switch port, the other un-bridged +ports are no longer available for standalone traffic termination.
That is quite a limitation that I don't think I had fully grasped until reading your different patches. Since enslaving ports into a bridge comes after the network device was already made available for use, maybe you should force the carrier down or something along those lines as soon as a port is enslaved into a bridge with vlan_filtering=1 to make this more predictable for the user?
Signature · 1 line
Florian
Vladimir Oltean
maintainerPATCH v3 24/24 dt-bindings: net: dsa: Add documentation for NXP SJA1105 driver
In reply to Vladimir Oltean---
Changes in v3:
None.
Changes in v2:
Renamed sja1105,phy-mode to sja1105,role-phy and similarly for mac. Clarified the switch situation with RGMII delays.
.../devicetree/bindings/net/dsa/sja1105.txt | 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