1. 09 6月, 2021 2 次提交
    • V
      net: dsa: sja1105: make sure the retagging port is enabled for SJA1110 · ceec8bc0
      Vladimir Oltean 提交于
      The SJA1110 has an extra configuration in the General Parameters Table
      through which the user can select the buffer reservation config.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ceec8bc0
    • V
      net: dsa: sja1105: add support for the SJA1110 switch family · 3e77e59b
      Vladimir Oltean 提交于
      The SJA1110 is basically an SJA1105 with more ports, some integrated
      PHYs (100base-T1 and 100base-TX) and an embedded microcontroller which
      can be disabled, and the switch core can be controlled by a host running
      Linux, over SPI.
      
      This patch contains:
      - the static and dynamic config packing functions, for the tables that
        are common with SJA1105
      - one more static config tables which is "unique" to the SJA1110
        (actually it is a rehash of stuff that was placed somewhere else in
        SJA1105): the PCP Remapping Table
      - a reset and clock configuration procedure for the SJA1110 switch.
        This resets just the switch subsystem, and gates off the clock which
        powers on the embedded microcontroller.
      - an RGMII delay configuration procedure for SJA1110, which is very
        similar to SJA1105, but different enough for us to be unable to reuse
        it (this is a pattern that repeats itself)
      - some adaptations to dynamic config table entries which are no longer
        programmed in the same way. For example, to delete a VLAN, you used to
        write an entry through the dynamic reconfiguration interface with the
        desired VLAN ID, and with the VALIDENT bit set to false. Now, the VLAN
        table entries contain a TYPE_ENTRY field, which must be set to zero
        (in a backwards-incompatible way) in order for the entry to be deleted,
        or to some other entry for the VLAN to match "inner tagged" or "outer
        tagged" packets.
      - a similar thing for the static config: the xMII Mode Parameters Table
        encoding for SGMII and MII (the latter just when attached to a
        100base-TX PHY) just isn't what it used to be in SJA1105. They are
        identical, except there is an extra "special" bit which needs to be
        set. Set it.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3e77e59b
  2. 08 6月, 2021 2 次提交
  3. 01 6月, 2021 8 次提交
    • V
      net: dsa: sja1105: some table entries are always present when read dynamically · 96c85f51
      Vladimir Oltean 提交于
      The SJA1105 has a static configuration comprised of a number of tables
      with entries. Some of these can be read and modified at runtime as well,
      through the dynamic configuration interface.
      
      As a careful reader can notice from the comments in this file, the
      software interface for accessing a table entry through the dynamic
      reconfiguration is a bit of a no man's land, and varies wildly across
      switch generations and even from one kind of table to another.
      
      I have tried my best to come up with a software representation of a
      'common denominator' SPI command to access a table entry through the
      dynamic configuration interface:
      
      struct sja1105_dyn_cmd {
      	bool search;
      	u64 valid; /* must be set to 1 */
      	u64 rdwrset; /* 0 to read, 1 to write */
      	u64 errors;
      	u64 valident; /* 0 if entry is invalid, 1 if valid */
      	u64 index;
      };
      
      Relevant to this patch is the VALIDENT bit, which for READ commands is
      populated by the switch and lets us know if we're looking at junk or at
      a real table entry.
      
      In SJA1105, the dynamic reconfiguration interface for management routes
      has notably not implemented the VALIDENT bit, leading to a workaround to
      ignore this field in sja1105_dynamic_config_read(), as it will be set to
      zero, but the data is valid nonetheless.
      
      In SJA1110, this pattern has sadly been abused to death, and while there
      are many more tables which can be read back over the dynamic config
      interface compared to SJA1105, their handling isn't in any way more
      uniform. Generally speaking, if there is a single possible entry in a
      given table, and loading that table in the static config is mandatory as
      per the documentation, then the VALIDENT bit is deemed as redundant and
      more than likely not implemented.
      
      So it is time to make the workaround more official, and add a bit to the
      flags implemented by dynamic config tables. It will be used by more
      tables when SJA1110 support arrives.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      96c85f51
    • V
      net: dsa: sja1105: always keep RGMII ports in the MAC role · f41fad3c
      Vladimir Oltean 提交于
      In SJA1105, the xMII Mode Parameters Table field called PHY_MAC denotes
      the 'role' of the port, be it a PHY or a MAC. This makes a difference in
      the MII and RMII protocols, but RGMII is symmetric, so either PHY or MAC
      settings result in the same hardware behavior.
      
      The SJA1110 is different, and the RGMII ports only work when configured
      in MAC mode, so keep the port roles in MAC mode unconditionally.
      
      Why we had an RGMII port in the PHY role in the first place was because
      we wanted to have a way in the driver to denote whether RGMII delays
      should be applied based on the phy-mode property or not. This is already
      done in sja1105_parse_rgmii_delays() based on an intermediary
      struct sja1105_dt_port (which contains the port role). So it is a
      logical fallacy to use the hardware configuration as a scratchpad for
      driver data, it isn't necessary.
      
      We can also remove the gating condition for applying RGMII delays only
      for ports in the PHY role. The .setup_rgmii_delay() method looks at
      the priv->rgmii_rx_delay[port] and priv->rgmii_tx_delay[port] properties
      which are already populated properly (in the case of a port in the MAC
      role they are false). Removing this condition generates a few more SPI
      writes for these ports (clearing the RGMII delays) which are perhaps
      useless for SJA1105P/Q/R/S, where we know that the delays are disabled
      by default. But for SJA1110, the firmware on the embedded microcontroller
      might have done something funny, so it's always a good idea to clear the
      RGMII delays if that's what Linux expects.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      f41fad3c
    • V
      net: dsa: sja1105: add a translation table for port speeds · 41fed17f
      Vladimir Oltean 提交于
      In order to support the new speed of 2500Mbps, the SJA1110 has achieved
      the great performance of changing the encoding in the MAC Configuration
      Table for the port speeds of 10, 100, 1000 compared to SJA1105.
      
      Because this is a common driver, we need a layer of indirection in order
      to program the hardware with the right values irrespective of switch
      generation.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      41fed17f
    • V
      net: dsa: sja1105: add a PHY interface type compatibility matrix · 91a05078
      Vladimir Oltean 提交于
      On the SJA1105, all ports support the parallel "xMII" protocols (MII,
      RMII, RGMII) except for port 4 on SJA1105R/S which supports only SGMII.
      This was relatively easy to model, by special-casing the SGMII port.
      
      On the SJA1110, certain ports can be pinmuxed between SGMII and xMII, or
      between SGMII and an internal 100base-TX PHY. This creates problems,
      because the driver's assumption so far was that if a port supports
      SGMII, it uses SGMII.
      
      We allow the device tree to tell us how the port pinmuxing is done, and
      check that against a PHY interface type compatibility matrix for
      plausibility.
      
      The other big change is that instead of doing SGMII configuration based
      on what the port supports, we do it based on what is the configured
      phy_mode of the port.
      
      The 2500base-x support added in this patch is not complete.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      91a05078
    • V
      net: dsa: sja1105: cache the phy-mode port property · bf4edf4a
      Vladimir Oltean 提交于
      So far we've succeeded in operating without keeping a copy of the
      phy-mode in the driver, since we already have the static config and we
      can look at the xMII Mode Parameters Table which already holds that
      information.
      
      But with the SJA1110, we cannot make the distinction between sgmii and
      2500base-x, because to the hardware's static config, it's all SGMII.
      So add a phy_mode property per port inside struct sja1105_private.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      bf4edf4a
    • V
      net: dsa: sja1105: the 0x1F0000 SGMII "base address" is actually MDIO_MMD_VEND2 · 4c7ee010
      Vladimir Oltean 提交于
      Looking at the SGMII PCS from SJA1110, which is accessed indirectly
      through a different base address as can be seen in the next patch, it
      appears odd that the address accessed through indirection still
      references the base address from the SJA1105S register map (first MDIO
      register is at 0x1f0000), when it could index the SGMII registers
      starting from zero.
      
      Except that the 0x1f0000 is not a base address at all, it seems. It is
      0x1f << 16 | 0x0000, and 0x1f is coding for the vendor-specific MMD2.
      So, it turns out, the Synopsys PCS implements all its registers inside
      the vendor-specific MMDs 1 and 2 (0x1e and 0x1f). This explains why the
      PCS has no overlaps (for the other MMDs) with other register regions of
      the switch (because no other MMDs are implemented).
      
      Change the code to remove the SGMII "base address" and explicitly encode
      the MMD for reads/writes. This will become necessary for SJA1110 support.
      
      Cc: Russell King <linux@armlinux.org.uk>
      Cc: Heiner Kallweit <hkallweit1@gmail.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      4c7ee010
    • V
      net: dsa: sja1105: allow SGMII PCS configuration to be per port · 84db00f2
      Vladimir Oltean 提交于
      The SJA1105 R and S switches have 1 SGMII port (port 4). Because there
      is only one such port, there is no "port" parameter in the configuration
      code for the SGMII PCS.
      
      However, the SJA1110 can have up to 4 SGMII ports, each with its own
      SGMII register map. So we need to generalize the logic.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      84db00f2
    • V
      net: dsa: sja1105: be compatible with "ethernet-ports" OF node name · 15074a36
      Vladimir Oltean 提交于
      Since commit f2f3e09396be ("net: dsa: sja1105: be compatible with
      "ethernet-ports" OF node name"), DSA supports the "ethernet-ports" name
      for the container node of the ports, but the sja1105 driver doesn't,
      because it handles some device tree parsing of its own.
      
      Add the second node name as a fallback.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      15074a36
  4. 25 5月, 2021 15 次提交
    • V
      net: dsa: sja1105: allow the frame buffer size to be customized · 1bf658ee
      Vladimir Oltean 提交于
      The shared frame buffer of the SJA1110 is larger than that of SJA1105,
      which is natural due to the fact that there are more ports.
      
      Introduce yet another property in struct sja1105_info which encodes the
      maximum number of 128 byte blocks that can be used for frame buffers.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1bf658ee
    • V
      net: dsa: sja1105: configure the multicast policers, if present · 38fbe91f
      Vladimir Oltean 提交于
      The SJA1110 policer array is similar in layout with SJA1105, except it
      contains one multicast policer per port at the end.
      
      Detect the presence of multicast policers based on the maximum number of
      supported L2 Policing Table entries, and make those policers have a
      shared index equal to the port's default policer. Letting the user
      configure these policers is not supported at the moment.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      38fbe91f
    • V
      net: dsa: sja1105: use sja1105_xfer_u32 for the reset procedure · f78a2517
      Vladimir Oltean 提交于
      Using sja1105_xfer_buf results in a higher overhead and is harder to
      read.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f78a2517
    • V
      net: dsa: sja1105: dynamically choose the number of static config table entries · fd6f2c25
      Vladimir Oltean 提交于
      Due to the fact that the port count is different, some static config
      tables have a different number of elements in SJA1105 compared to
      SJA1110. Such an example is the L2 Policing table, which has 45 entries
      in SJA1105 (one per port x traffic class, and one broadcast policer per
      port) and 110 entries in SJA1110 (one per port x traffic class, one
      broadcast and one multicast policer per port).
      
      Similarly, the MAC Configuration Table, the L2 Forwarding table, all
      have a different number of elements simply because the port count is
      different, and although this can be accounted for by looking at
      ds->ports, the policing table can't because of the presence of the extra
      multicast policers.
      
      The common denominator for the static config initializers for these
      tables is that they must set up all the entries within that table.
      So the simplest way to account for these differences in a uniform manner
      is to look at struct sja1105_table_ops::max_entry_count. For the sake of
      uniformity, this patch makes that change also for tables whose number of
      elements did not change in SJA1110, like the xMII Mode Parameters, the
      L2 Lookup Parameters, General Parameters, AVB Parameters (all of these
      are singleton tables with a single entry).
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      fd6f2c25
    • V
      net: dsa: sja1105: skip CGU configuration if it's unnecessary · c5037678
      Vladimir Oltean 提交于
      There are two distinct code paths which enter sja1105_clocking.c, one
      through sja1105_clocking_setup() and the other through
      sja1105_clocking_setup_port():
      
      sja1105_static_config_reload      sja1105_setup
                    |                         |
                    |      +------------------+
                    |      |
                    v      v
         sja1105_clocking_setup               sja1105_adjust_port_config
                       |                                   |
                       v                                   |
            sja1105_clocking_setup_port <------------------+
      
      As opposed to SJA1105, the SJA1110 does not need any configuration of
      the Clock Generation Unit in order for xMII ports to work. Just RGMII
      internal delays need to be configured, and that is done inside
      sja1105_clocking_setup_port for the RGMII ports.
      
      So this patch introduces the concept of a "reserved address", which the
      CGU configuration functions from sja1105_clocking.c must check before
      proceeding to do anything. The SJA1110 will have reserved addresses for
      the CGU PLLs for MII/RMII/RGMII.
      
      Additionally, make sja1105_clocking_setup() a function pointer so it can
      be overridden by the SJA1110. Even though nothing port-related needs to
      be done in the CGU, there are some operations such as disabling the
      watchdog clock which are unique to the SJA1110.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c5037678
    • V
      net: dsa: sja1105: don't assign the host port using dsa_upstream_port() · df2a81a3
      Vladimir Oltean 提交于
      If @port is unused, then dsa_upstream_port(ds, port) returns @port,
      which means we cannot assume the CPU port can be retrieved this way.
      
      The sja1105 switches support a single CPU port, so just iterate over the
      switch ports and stop at the first CPU port we see.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      df2a81a3
    • V
      net: dsa: sja1105: dimension the data structures for a larger port count · 82760d7f
      Vladimir Oltean 提交于
      Introduce a SJA1105_MAX_NUM_PORTS macro which at the moment is equal to
      SJA1105_NUM_PORTS (5). With the introduction of SJA1110, these
      structures will need to hold information for up to 11 ports.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      82760d7f
    • V
      net: dsa: sja1105: avoid some work for unused ports · f238fef1
      Vladimir Oltean 提交于
      Do not put unused ports in the forwarding domain, and do not allocate
      FDB entries for dynamic address learning for them.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      f238fef1
    • V
      net: dsa: sja1105: parameterize the number of ports · 542043e9
      Vladimir Oltean 提交于
      The sja1105 driver will gain support for the next-gen SJA1110 switch,
      which is very similar except for the fact it has more than 5 ports.
      
      So we need to replace the hardcoded SJA1105_NUM_PORTS in this driver
      with ds->num_ports. This patch is as mechanical as possible (save for
      the fact that ds->num_ports is not an integer constant expression).
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      542043e9
    • V
      net: dsa: sja1105: update existing VLANs from the bridge VLAN list · b38e659d
      Vladimir Oltean 提交于
      When running this sequence of operations:
      
      ip link add br0 type bridge vlan_filtering 1
      ip link set swp4 master br0
      bridge vlan add dev swp4 vid 1
      
      We observe the traffic sent on swp4 is still untagged, even though the
      bridge has overwritten the existing VLAN entry:
      
      port    vlan ids
      swp4     1 PVID
      
      br0      1 PVID Egress Untagged
      
      This happens because we didn't consider that the 'bridge vlan add'
      command just overwrites VLANs like it's nothing. We treat the 'vid 1
      pvid untagged' and the 'vid 1' as two separate VLANs, and the first
      still has precedence when calling sja1105_build_vlan_table. Obviously
      there is a disagreement regarding semantics, and we end up doing
      something unexpected from the PoV of the bridge.
      
      Let's actually consider an "existing VLAN" to be one which is on the
      same port, and has the same VLAN ID, as one we already have, and update
      it if it has different flags than we do.
      
      The first blamed commit is the one introducing the bug, the second one
      is the latest on top of which the bugfix still applies.
      
      Fixes: ec5ae610 ("net: dsa: sja1105: save/restore VLANs using a delta commit method")
      Fixes: 5899ee36 ("net: dsa: tag_8021q: add a context structure")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      b38e659d
    • V
      net: dsa: sja1105: use 4095 as the private VLAN for untagged traffic · ed040abc
      Vladimir Oltean 提交于
      One thing became visible when writing the blamed commit, and that was
      that STP and PTP frames injected by net/dsa/tag_sja1105.c using the
      deferred xmit mechanism are always classified to the pvid of the CPU
      port, regardless of whatever VLAN there might be in these packets.
      
      So a decision needed to be taken regarding the mechanism through which
      we should ensure that delivery of STP and PTP traffic is possible when
      we are in a VLAN awareness mode that involves tag_8021q. This is because
      tag_8021q is not concerned with managing the pvid of the CPU port, since
      as far as tag_8021q is concerned, no traffic should be sent as untagged
      from the CPU port. So we end up not actually having a pvid on the CPU
      port if we only listen to tag_8021q, and unless we do something about it.
      
      The decision taken at the time was to keep VLAN 1 in the list of
      priv->dsa_8021q_vlans, and make it a pvid of the CPU port. This ensures
      that STP and PTP frames can always be sent to the outside world.
      
      However there is a problem. If we do the following while we are in
      the best_effort_vlan_filtering=true mode:
      
      ip link add br0 type bridge vlan_filtering 1
      ip link set swp2 master br0
      bridge vlan del dev swp2 vid 1
      
      Then untagged and pvid-tagged frames should be dropped. But we observe
      that they aren't, and this is because of the precaution we took that VID
      1 is always installed on all ports.
      
      So clearly VLAN 1 is not good for this purpose. What about VLAN 0?
      Well, VLAN 0 is managed by the 8021q module, and that module wants to
      ensure that 802.1p tagged frames are always received by a port, and are
      always transmitted as VLAN-tagged (with VLAN ID 0). Whereas we want our
      STP and PTP frames to be untagged if the stack sent them as untagged -
      we don't want the driver to just decide out of the blue that it adds
      VID 0 to some packets.
      
      So what to do?
      
      Well, there is one other VLAN that is reserved, and that is 4095:
      $ ip link add link swp2 name swp2.4095 type vlan id 4095
      Error: 8021q: Invalid VLAN id.
      $ bridge vlan add dev swp2 vid 4095
      Error: bridge: Vlan id is invalid.
      
      After we made this change, VLAN 1 is indeed forwarded and/or dropped
      according to the bridge VLAN table, there are no further alterations
      done by the sja1105 driver.
      
      Fixes: ec5ae610 ("net: dsa: sja1105: save/restore VLANs using a delta commit method")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ed040abc
    • V
      net: dsa: sja1105: error out on unsupported PHY mode · 6729188d
      Vladimir Oltean 提交于
      The driver continues probing when a port is configured for an
      unsupported PHY interface type, instead it should stop.
      
      Fixes: 8aa9ebcc ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      6729188d
    • V
      net: dsa: sja1105: add error handling in sja1105_setup() · cec279a8
      Vladimir Oltean 提交于
      If any of sja1105_static_config_load(), sja1105_clocking_setup() or
      sja1105_devlink_setup() fails, we can't just return in the middle of
      sja1105_setup() or memory will leak. Add a cleanup path.
      
      Fixes: 0a7bdbc2 ("net: dsa: sja1105: move devlink param code to sja1105_devlink.c")
      Fixes: 8aa9ebcc ("net: dsa: Introduce driver for NXP SJA1105 5-port L2 switch")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      cec279a8
    • V
      net: dsa: sja1105: call dsa_unregister_switch when allocating memory fails · dc596e3f
      Vladimir Oltean 提交于
      Unlike other drivers which pretty much end their .probe() execution with
      dsa_register_switch(), the sja1105 does some extra stuff. When that
      fails with -ENOMEM, the driver is quick to return that, forgetting to
      call dsa_unregister_switch(). Not critical, but a bug nonetheless.
      
      Fixes: 4d752508 ("net: dsa: sja1105: offload the Credit-Based Shaper qdisc")
      Fixes: a68578c2 ("net: dsa: Make deferred_xmit private to sja1105")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      dc596e3f
    • V
      net: dsa: sja1105: fix VL lookup command packing for P/Q/R/S · ba61cf16
      Vladimir Oltean 提交于
      At the beginning of the sja1105_dynamic_config.c file there is a diagram
      of the dynamic config interface layout:
      
       packed_buf
      
       |
       V
       +-----------------------------------------+------------------+
       |              ENTRY BUFFER               |  COMMAND BUFFER  |
       +-----------------------------------------+------------------+
      
       <----------------------- packed_size ------------------------>
      
      So in order to pack/unpack the command bits into the buffer,
      sja1105_vl_lookup_cmd_packing must first advance the buffer pointer by
      the length of the entry. This is similar to what the other *cmd_packing
      functions do.
      
      This bug exists because the command packing function for P/Q/R/S was
      copied from the E/T generation, and on E/T, the command was actually
      embedded within the entry buffer itself.
      
      Fixes: 94f94d4a ("net: dsa: sja1105: add static tables for virtual links")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ba61cf16
  5. 22 5月, 2021 4 次提交
    • V
      net: dsa: sja1105: don't use burst SPI reads for port statistics · 039b167d
      Vladimir Oltean 提交于
      The current internal sja1105 driver API is optimized for retrieving many
      statistics counters at once. But the switch does not do atomic snapshotting
      for them anyway.
      
      In case we start reporting the hardware port counters through
      ndo_get_stats64 as well, not just ethtool, it would be good to be able
      to read individual port counters and not all of them.
      
      Additionally, since Arnd Bergmann's commit ae1804de ("dsa: sja1105:
      dynamically allocate stats structure"), sja1105_get_ethtool_stats
      allocates memory dynamically, since struct sja1105_port_status was
      deemed to consume too much stack memory. That is not ideal.
      The large structure is only needed because of the burst read.
      If we read statistics one by one, we can consume less memory, and
      we can avoid dynamic allocation.
      
      Additionally, latency-sensitive interfaces such as PTP operations (for
      phc2sys) might suffer if the SPI mutex is being held for too long, which
      happens in the case of SPI burst reads. By reading counters one by one,
      we give a chance for higher priority processes to preempt and take the
      SPI bus mutex for accessing the PTP clock.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      039b167d
    • V
      net: dsa: sja1105: stop reporting the queue levels in ethtool port counters · 30a2e9c0
      Vladimir Oltean 提交于
      The queue levels are not counters, but instead they represent the
      occupancy of the MAC TX queues. Having these in ethtool port counters is
      not helpful, so remove them.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      30a2e9c0
    • V
      net: dsa: sja1105: adapt to a SPI controller with a limited max transfer size · 718bad0e
      Vladimir Oltean 提交于
      The static config of the sja1105 switch is a long stream of bytes which
      is programmed to the hardware in chunks (portions with the chip select
      continuously asserted) of max 256 bytes each. Each chunk is a
      spi_message composed of 2 spi_transfers: the buffer with the data and a
      preceding buffer with the SPI access header.
      
      Only that certain SPI controllers, such as the spi-sc18is602 I2C-to-SPI
      bridge, cannot keep the chip select asserted for that long.
      The spi_max_transfer_size() and spi_max_message_size() functions are how
      the controller can impose its hardware limitations upon the SPI
      peripheral driver.
      
      For the sja1105 driver to work with these controllers, both buffers must
      be smaller than the transfer limit, and their sum must be smaller than
      the message limit.
      
      Regression-tested on a switch connected to a controller with no
      limitations (spi-fsl-dspi) as well as with one with caps for both
      max_transfer_size and max_message_size (spi-sc18is602).
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      718bad0e
    • V
      net: dsa: sja1105: send multiple spi_messages instead of using cs_change · ca021f0d
      Vladimir Oltean 提交于
      The sja1105 driver has been described by Mark Brown as "not using the
      [ SPI ] API at all idiomatically" due to the use of cs_change:
      https://patchwork.kernel.org/project/netdevbpf/patch/20210520135031.2969183-1-olteanv@gmail.com/
      
      According to include/linux/spi/spi.h, the chip select is supposed to be
      asserted for the entire length of a SPI message, as long as cs_change is
      false for all member transfers. The cs_change flag changes the following:
      
      (i) When a non-final SPI transfer has cs_change = true, the chip select
          should temporarily deassert and then reassert starting with the next
          transfer.
      (ii) When a final SPI transfer has cs_change = true, the chip select
           should remain asserted until the following SPI message.
      
      The sja1105 driver only uses cs_change for its first property, to form a
      single SPI message whose layout can be seen below:
      
                                                   this is an entire, single spi_message
                 _______________________________________________________________________________________________
                /                                                                                               \
                +-------------+---------------+-------------+---------------+ ... +-------------+---------------+
                | hdr_xfer[0] | chunk_xfer[0] | hdr_xfer[1] | chunk_xfer[1] |     | hdr_xfer[n] | chunk_xfer[n] |
                +-------------+---------------+-------------+---------------+ ... +-------------+---------------+
      cs_change      false          true           false           true                false          false
      
                 ____________________________  _____________________________       _____________________________
      CS line __/                            \/                             \ ... /                             \__
      
      The fact of the matter is that spi_max_message_size() has an ambiguous
      meaning if any non-final transfer has cs_change = true.
      
      If the SPI master has a limitation in that it cannot keep the chip
      select asserted for more than, say, 200 bytes (like the spi-sc18is602),
      the normal thing for it to do is to implement .max_transfer_size and
      .max_message_size, and limit both to 200: in the "worst case" where
      cs_change is always false, then the controller can, indeed, not send
      messages larger than 200 bytes.
      
      But the fact that the SPI controller's max_message_size does not
      necessarily mean that we cannot send messages larger than that.
      Notably, if the SPI master special-cases the transfers with cs_change
      and treats every chip select toggling as an entirely new transaction,
      then a SPI message can easily exceed that limit. So there is a
      temptation to ignore the controller's reported max_message_size when
      using cs_change = true in non-final transfers.
      
      But that can lead to false conclusions. As Mark points out, the SPI
      controller might have a different kind of limitation with the max
      message size, that has nothing at all to do with how long it can keep
      the chip select asserted.
      For example, that might be the case if the device is able to offload the
      chip select changes to the hardware as part of the data stream, and it
      packs the entire stream of commands+data (corresponding to a SPI
      message) into a single DMA transfer that is itself limited in size.
      
      So the only thing we can do is avoid ambiguity by not using cs_change at
      all. Instead of sending a single spi_message, we now send multiple SPI
      messages as follows:
      
                        spi_message 0                 spi_message 1                       spi_message n
                 ____________________________   ___________________________        _____________________________
                /                            \ /                           \      /                             \
                +-------------+---------------+-------------+---------------+ ... +-------------+---------------+
                | hdr_xfer[0] | chunk_xfer[0] | hdr_xfer[1] | chunk_xfer[1] |     | hdr_xfer[n] | chunk_xfer[n] |
                +-------------+---------------+-------------+---------------+ ... +-------------+---------------+
      cs_change      false          true           false           true                false          false
      
                 ____________________________  _____________________________       _____________________________
      CS line __/                            \/                             \ ... /                             \__
      
      which is clearer because the max_message_size limit is now easier to
      enforce. What is transmitted on the wire stays, of course, the same.
      
      Additionally, because we send no more than 2 transfers at a time, we now
      avoid dynamic memory allocation too, which might be seen as an
      improvement by some.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      ca021f0d
  6. 28 4月, 2021 3 次提交
  7. 21 3月, 2021 1 次提交
    • V
      Revert "net: dsa: sja1105: Clear VLAN filtering offload netdev feature" · a1e6f641
      Vladimir Oltean 提交于
      This reverts commit e9bf9694.
      
      The topic of the reverted patch is the support for switches with global
      VLAN filtering, added by commit 061f6a50 ("net: dsa: Add
      ndo_vlan_rx_{add, kill}_vid implementation"). Be there a switch with 4
      ports swp0 -> swp3, and the following setup:
      
      ip link add br0 type bridge vlan_filtering 1
      ip link set swp0 master br0
      ip link set swp1 master br0
      
      What would happen with VLAN-tagged traffic received on standalone ports
      swp2 and swp3? Well, it would get dropped, were it not for the
      .ndo_vlan_rx_add_vid and .ndo_vlan_rx_kill_vid implementations (called
      from vlan_vid_add and vlan_vid_del respectively). Basically, for DSA
      switches where VLAN filtering is a global attribute, we enforce the
      standalone ports to have 'rx-vlan-filter: off [fixed]' in their ethtool
      features, which lets the user know that all VLAN-tagged packets that are
      not explicitly added in the RX filtering list are dropped.
      
      As for the sja1105 driver, at the time of the reverted patch, it was
      operating in a pretty handicapped mode when it had ports under a bridge
      with vlan_filtering=1. Specifically, it was unable to terminate traffic
      through the CPU port (for further explanation see "Traffic support" in
      Documentation/networking/dsa/sja1105.rst).
      
      However, since then, the sja1105 driver has made considerable progress,
      and that limitation is no longer as severe now. Specifically, since
      commit 2cafa72e ("net: dsa: sja1105: add a new
      best_effort_vlan_filtering devlink parameter"), the driver is able to
      perform CPU termination even when some ports are under bridges with
      vlan_filtering=1. Then, since commit 8841f6e6 ("net: dsa: sja1105:
      make devlink property best_effort_vlan_filtering true by default"), this
      even became the default operating mode.
      
      So we can now take advantage of the logic in the DSA core.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a1e6f641
  8. 17 3月, 2021 1 次提交
  9. 14 3月, 2021 1 次提交
  10. 05 3月, 2021 2 次提交
  11. 26 2月, 2021 1 次提交