1. 05 10月, 2020 1 次提交
    • V
      net: dsa: propagate switchdev vlan_filtering prepare phase to drivers · 2e554a7a
      Vladimir Oltean 提交于
      A driver may refuse to enable VLAN filtering for any reason beyond what
      the DSA framework cares about, such as:
      - having tc-flower rules that rely on the switch being VLAN-aware
      - the particular switch does not support VLAN, even if the driver does
        (the DSA framework just checks for the presence of the .port_vlan_add
        and .port_vlan_del pointers)
      - simply not supporting this configuration to be toggled at runtime
      
      Currently, when a driver rejects a configuration it cannot support, it
      does this from the commit phase, which triggers various warnings in
      switchdev.
      
      So propagate the prepare phase to drivers, to give them the ability to
      refuse invalid configurations cleanly and avoid the warnings.
      
      Since we need to modify all function prototypes and check for the
      prepare phase from within the drivers, take that opportunity and move
      the existing driver restrictions within the prepare phase where that is
      possible and easy.
      
      Cc: Florian Fainelli <f.fainelli@gmail.com>
      Cc: Martin Blumenstingl <martin.blumenstingl@googlemail.com>
      Cc: Hauke Mehrtens <hauke@hauke-m.de>
      Cc: Woojung Huh <woojung.huh@microchip.com>
      Cc: Microchip Linux Driver Support <UNGLinuxDriver@microchip.com>
      Cc: Sean Wang <sean.wang@mediatek.com>
      Cc: Landen Chao <Landen.Chao@mediatek.com>
      Cc: Andrew Lunn <andrew@lunn.ch>
      Cc: Vivien Didelot <vivien.didelot@gmail.com>
      Cc: Jonathan McDowell <noodles@earth.li>
      Cc: Linus Walleij <linus.walleij@linaro.org>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Cc: Claudiu Manoil <claudiu.manoil@nxp.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2e554a7a
  2. 03 10月, 2020 2 次提交
  3. 30 9月, 2020 5 次提交
    • V
      net: mscc: ocelot: automatically detect VCAP constants · 20968054
      Vladimir Oltean 提交于
      The numbers in struct vcap_props are not intuitive to derive, because
      they are not a straightforward copy-and-paste from the reference manual
      but instead rely on a fairly detailed level of understanding of the
      layout of an entry in the TCAM and in the action RAM. For this reason,
      bugs are very easy to introduce here.
      
      Ease the work of hardware porters and read from hardware the constants
      that were exported for this particular purpose. Note that this implies
      that struct vcap_props can no longer be const.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      20968054
    • V
      net: mscc: ocelot: add definitions for VCAP ES0 keys, actions and target · e3aea296
      Vladimir Oltean 提交于
      As a preparation step for the offloading to ES0, let's create the
      infrastructure for talking with this hardware block.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      e3aea296
    • V
      net: mscc: ocelot: add definitions for VCAP IS1 keys, actions and target · a61e365d
      Vladimir Oltean 提交于
      As a preparation step for the offloading to IS1, let's create the
      infrastructure for talking with this hardware block.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a61e365d
    • V
      net: mscc: ocelot: generalize existing code for VCAP · c1c3993e
      Vladimir Oltean 提交于
      In the Ocelot switches there are 3 TCAMs: VCAP ES0, IS1 and IS2, which
      have the same configuration interface, but different sets of keys and
      actions. The driver currently only supports VCAP IS2.
      
      In preparation of VCAP IS1 and ES0 support, the existing code must be
      generalized to work with any VCAP.
      
      In that direction, we should move the structures that depend upon VCAP
      instantiation, like vcap_is2_keys and vcap_is2_actions, out of struct
      ocelot and into struct vcap_props .keys and .actions, a structure that
      is replicated 3 times, once per VCAP. We'll pass that structure as an
      argument to each function that does the key and action packing - only
      the control logic needs to distinguish between ocelot->vcap[VCAP_IS2]
      or IS1 or ES0.
      
      Another change is to make use of the newly introduced ocelot_target_read
      and ocelot_target_write API, since the 3 VCAPs have the same registers
      but put at different addresses.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c1c3993e
    • V
      net: mscc: ocelot: introduce a new ocelot_target_{read,write} API · 3c0e37a9
      Vladimir Oltean 提交于
      There are some targets (register blocks) in the Ocelot switch that are
      instantiated more than once. For example, the VCAP IS1, IS2 and ES0
      blocks all share the same register layout for interacting with the cache
      for the TCAM and the action RAM.
      
      For the VCAPs, the procedure for servicing them is actually common. We
      just need an API specifying which VCAP we are talking to, and we do that
      via these raw ocelot_target_read and ocelot_target_write accessors.
      
      In plain ocelot_read, the target is encoded into the register enum
      itself:
      
      	u16 target = reg >> TARGET_OFFSET;
      
      For the VCAPs, the registers are currently defined like this:
      
      	enum ocelot_reg {
      	[...]
      		S2_CORE_UPDATE_CTRL = S2 << TARGET_OFFSET,
      		S2_CORE_MV_CFG,
      		S2_CACHE_ENTRY_DAT,
      		S2_CACHE_MASK_DAT,
      		S2_CACHE_ACTION_DAT,
      		S2_CACHE_CNT_DAT,
      		S2_CACHE_TG_DAT,
      	[...]
      	};
      
      which is precisely what we want to avoid, because we'd have to duplicate
      the same register map for S1 and for S0, and then figure out how to pass
      VCAP instance-specific registers to the ocelot_read calls (basically
      another lookup table that undoes the effect of shifting with
      TARGET_OFFSET).
      
      So for some targets, propose a more raw API, similar to what is
      currently done with ocelot_port_readl and ocelot_port_writel. Those
      targets can only be accessed with ocelot_target_{read,write} and not
      with ocelot_{read,write} after the conversion, which is fine.
      
      The VCAP registers are not actually modified to use this new API as of
      this patch. They will be modified in the next one.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Acked-by: NAlexandre Belloni <alexandre.belloni@bootlin.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3c0e37a9
  4. 27 9月, 2020 2 次提交
    • V
      net: dsa: tag_ocelot: use a short prefix on both ingress and egress · 5124197c
      Vladimir Oltean 提交于
      There are 2 goals that we follow:
      
      - Reduce the header size
      - Make the header size equal between RX and TX
      
      The issue that required long prefix on RX was the fact that the ocelot
      DSA tag, being put before Ethernet as it is, would overlap with the area
      that a DSA master uses for RX filtering (destination MAC address
      mainly).
      
      Now that we can ask DSA to put the master in promiscuous mode, in theory
      we could remove the prefix altogether and call it a day, but it looks
      like we can't. Using no prefix on ingress, some packets (such as ICMP)
      would be received, while others (such as PTP) would not be received.
      This is because the DSA master we use (enetc) triggers parse errors
      ("MAC rx frame errors") presumably because it sees Ethernet frames with
      a bad length. And indeed, when using no prefix, the EtherType (bytes
      12-13 of the frame, bits 96-111) falls over the REW_VAL field from the
      extraction header, aka the PTP timestamp.
      
      When turning the short (32-bit) prefix on, the EtherType overlaps with
      bits 64-79 of the extraction header, which are a reserved area
      transmitted as zero by the switch. The packets are not dropped by the
      DSA master with a short prefix. Actually, the frames look like this in
      tcpdump (below is a PTP frame, with an extra dsa_8021q tag - dadb 0482 -
      added by a downstream sja1105).
      
      89:0c:a9:f2:01:00 > 88:80:00:0a:00:1d, 802.3, length 0: LLC, \
      	dsap Unknown (0x10) Individual, ssap ProWay NM (0x0e) Response, \
      	ctrl 0x0004: Information, send seq 2, rcv seq 0, \
      	Flags [Response], length 78
      
      0x0000:  8880 000a 001d 890c a9f2 0100 0000 100f  ................
      0x0010:  0400 0000 0180 c200 000e 001f 7b63 0248  ............{c.H
      0x0020:  dadb 0482 88f7 1202 0036 0000 0000 0000  .........6......
      0x0030:  0000 0000 0000 0000 0000 001f 7bff fe63  ............{..c
      0x0040:  0248 0001 1f81 0500 0000 0000 0000 0000  .H..............
      0x0050:  0000 0000 0000 0000 0000 0000            ............
      
      So the short prefix is our new default: we've shortened our RX frames by
      12 octets, increased TX by 4, and headers are now equal between RX and
      TX. Note that we still need promiscuous mode for the DSA master to not
      drop it.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      5124197c
    • V
      net: mscc: ocelot: move NPI port configuration to DSA · 2d44b097
      Vladimir Oltean 提交于
      Remove the ocelot_configure_cpu() function, which was in fact bringing
      up 2 ports: the CPU port module, which both switchdev and DSA have, and
      the NPI port, which only DSA has.
      
      The (non-Ethernet) CPU port module is at a fixed index in the analyzer,
      whereas the NPI port is selected through the "ethernet" property in the
      device tree.
      
      Therefore, the function to set up an NPI port is DSA-specific, so we
      move it there, simplifying the ocelot switch library a little bit.
      
      Cc: Horatiu Vultur <horatiu.vultur@microchip.com>
      Cc: Alexandre Belloni <alexandre.belloni@bootlin.com>
      Cc: UNGLinuxDriver <UNGLinuxDriver@microchip.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2d44b097
  5. 25 9月, 2020 1 次提交
  6. 19 9月, 2020 2 次提交
  7. 14 7月, 2020 6 次提交
  8. 23 6月, 2020 2 次提交
  9. 21 6月, 2020 1 次提交
    • V
      net: mscc: ocelot: generalize the "ACE/ACL" names · aae4e500
      Vladimir Oltean 提交于
      Access Control Lists (and their respective Access Control Entries) are
      specifically entries in the VCAP IS2, the security enforcement block,
      according to the documentation.
      Let's rename the structures and functions to something more generic, so
      that VCAP IS1 structures (which would otherwise have to be called
      Ingress Classification Entries) can reuse the same code without
      confusion.
      
      Some renaming that was done:
      
      struct ocelot_ace_rule -> struct ocelot_vcap_filter
      struct ocelot_acl_block -> struct ocelot_vcap_block
      enum ocelot_ace_type -> enum ocelot_vcap_key_type
      struct ocelot_ace_vlan -> struct ocelot_vcap_key_vlan
      enum ocelot_ace_action -> enum ocelot_vcap_action
      struct ocelot_ace_stats -> struct ocelot_vcap_stats
      enum ocelot_ace_type -> enum ocelot_vcap_key_type
      struct ocelot_ace_frame_* -> struct ocelot_vcap_key_*
      
      No functional change is intended.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      aae4e500
  10. 07 5月, 2020 1 次提交
  11. 22 4月, 2020 4 次提交
  12. 16 4月, 2020 1 次提交
    • V
      net: mscc: ocelot: fix untagged packet drops when enslaving to vlan aware bridge · 87b0f983
      Vladimir Oltean 提交于
      To rehash a previous explanation given in commit 1c44ce56 ("net:
      mscc: ocelot: fix vlan_filtering when enslaving to bridge before link is
      up"), the switch driver operates the in a mode where a single VLAN can
      be transmitted as untagged on a particular egress port. That is the
      "native VLAN on trunk port" use case.
      
      The configuration for this native VLAN is driven in 2 ways:
       - Set the egress port rewriter to strip the VLAN tag for the native
         VID (as it is egress-untagged, after all).
       - Configure the ingress port to drop untagged and priority-tagged
         traffic, if there is no native VLAN. The intention of this setting is
         that a trunk port with no native VLAN should not accept untagged
         traffic.
      
      Since both of the above configurations for the native VLAN should only
      be done if VLAN awareness is requested, they are actually done from the
      ocelot_port_vlan_filtering function, after the basic procedure of
      toggling the VLAN awareness flag of the port.
      
      But there's a problem with that simplistic approach: we are trying to
      juggle with 2 independent variables from a single function:
       - Native VLAN of the port - its value is held in port->vid.
       - VLAN awareness state of the port - currently there are some issues
         here, more on that later*.
      The actual problem can be seen when enslaving the switch ports to a VLAN
      filtering bridge:
       0. The driver configures a pvid of zero for each port, when in
          standalone mode. While the bridge configures a default_pvid of 1 for
          each port that gets added as a slave to it.
       1. The bridge calls ocelot_port_vlan_filtering with vlan_aware=true.
          The VLAN-filtering-dependent portion of the native VLAN
          configuration is done, considering that the native VLAN is 0.
       2. The bridge calls ocelot_vlan_add with vid=1, pvid=true,
          untagged=true. The native VLAN changes to 1 (change which gets
          propagated to hardware).
       3. ??? - nobody calls ocelot_port_vlan_filtering again, to reapply the
          VLAN-filtering-dependent portion of the native VLAN configuration,
          for the new native VLAN of 1. One can notice that after toggling "ip
          link set dev br0 type bridge vlan_filtering 0 && ip link set dev br0
          type bridge vlan_filtering 1", the new native VLAN finally makes it
          through and untagged traffic finally starts flowing again. But
          obviously that shouldn't be needed.
      
      So it is clear that 2 independent variables need to both re-trigger the
      native VLAN configuration. So we introduce the second variable as
      ocelot_port->vlan_aware.
      
      *Actually both the DSA Felix driver and the Ocelot driver already had
      each its own variable:
       - Ocelot: ocelot_port_private->vlan_aware
       - Felix: dsa_port->vlan_filtering
      but the common Ocelot library needs to work with a single, common,
      variable, so there is some refactoring done to move the vlan_aware
      property from the private structure into the common ocelot_port
      structure.
      
      Fixes: 97bb69e1 ("net: mscc: ocelot: break apart ocelot_vlan_port_apply")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NHoratiu Vultur <horatiu.vultur@microchip.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      87b0f983
  13. 31 3月, 2020 2 次提交
  14. 28 3月, 2020 1 次提交
  15. 05 3月, 2020 2 次提交
    • V
      net: dsa: felix: Allow unknown unicast traffic towards the CPU port module · 1cf3299b
      Vladimir Oltean 提交于
      Compared to other DSA switches, in the Ocelot cores, the RX filtering is
      a much more important concern.
      
      Firstly, the primary use case for Ocelot is non-DSA, so there isn't any
      secondary Ethernet MAC [the DSA master's one] to implicitly drop frames
      having a DMAC we are not interested in.  So the switch driver itself
      needs to install FDB entries towards the CPU port module (PGID_CPU) for
      the MAC address of each switch port, in each VLAN installed on the port.
      Every address that is not whitelisted is implicitly dropped. This is in
      order to achieve a behavior similar to N standalone net devices.
      
      Secondly, even in the secondary use case of DSA, such as illustrated by
      Felix with the NPI port mode, that secondary Ethernet MAC is present,
      but its RX filter is bypassed. This is because the DSA tags themselves
      are placed before Ethernet, so the DMAC that the switch ports see is
      not seen by the DSA master too (since it's shifter to the right).
      
      So RX filtering is pretty important. A good RX filter won't bother the
      CPU in case the switch port receives a frame that it's not interested
      in, and there exists no other line of defense.
      
      Ocelot is pretty strict when it comes to RX filtering: non-IP multicast
      and broadcast traffic is allowed to go to the CPU port module, but
      unknown unicast isn't. This means that traffic reception for any other
      MAC addresses than the ones configured on each switch port net device
      won't work. This includes use cases such as macvlan or bridging with a
      non-Ocelot (so-called "foreign") interface. But this seems to be fine
      for the scenarios that the Linux system embedded inside an Ocelot switch
      is intended for - it is simply not interested in unknown unicast
      traffic, as explained in Allan Nielsen's presentation [0].
      
      On the other hand, the Felix DSA switch is integrated in more
      general-purpose Linux systems, so it can't afford to drop that sort of
      traffic in hardware, even if it will end up doing so later, in software.
      
      Actually, unknown unicast means more for Felix than it does for Ocelot.
      Felix doesn't attempt to perform the whitelisting of switch port MAC
      addresses towards PGID_CPU at all, mainly because it is too complicated
      to be feasible: while the MAC addresses are unique in Ocelot, by default
      in DSA all ports are equal and inherited from the DSA master. This adds
      into account the question of reference counting MAC addresses (delayed
      ocelot_mact_forget), not to mention reference counting for the VLAN IDs
      that those MAC addresses are installed in. This reference counting
      should be done in the DSA core, and the fact that it wasn't needed so
      far is due to the fact that the other DSA switches don't have the DSA
      tag placed before Ethernet, so the DSA master is able to whitelist the
      MAC addresses in hardware.
      
      So this means that even regular traffic termination on a Felix switch
      port happens through flooding (because neither Felix nor Ocelot learn
      source MAC addresses from CPU-injected frames).
      
      So far we've explained that whitelisting towards PGID_CPU:
      - helps to reduce the likelihood of spamming the CPU with frames it
        won't process very far anyway
      - is implemented in the ocelot driver
      - is sufficient for the ocelot use cases
      - is not feasible in DSA
      - breaks use cases in DSA, in the current status (whitelisting enabled
        but no MAC address whitelisted)
      
      So the proposed patch allows unknown unicast frames to be sent to the
      CPU port module. This is done for the Felix DSA driver only, as Ocelot
      seems to be happy without it.
      
      [0]: https://www.youtube.com/watch?v=B1HhxEcU7JgSuggested-by: NAllan W. Nielsen <allan.nielsen@microchip.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NAllan W. Nielsen <allan.nielsen@microchip.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      1cf3299b
    • V
      net: mscc: ocelot: eliminate confusion between CPU and NPI port · 69df578c
      Vladimir Oltean 提交于
      Ocelot has the concept of a CPU port. The CPU port is represented in the
      forwarding and the queueing system, but it is not a physical device. The
      CPU port can either be accessed via register-based injection/extraction
      (which is the case of Ocelot), via Frame-DMA (similar to the first one),
      or "connected" to a physical Ethernet port (called NPI in the datasheet)
      which is the case of the Felix DSA switch.
      
      In Ocelot the CPU port is at index 11.
      In Felix the CPU port is at index 6.
      
      The CPU bit is treated special in the forwarding, as it is never cleared
      from the forwarding port mask (once added to it). Other than that, it is
      treated the same as a normal front port.
      
      Both Felix and Ocelot should use the CPU port in the same way. This
      means that Felix should not use the NPI port directly when forwarding to
      the CPU, but instead use the CPU port.
      
      This patch is fixing this such that Felix will use port 6 as its CPU
      port, and just use the NPI port to carry the traffic.
      
      Therefore, eliminate the "ocelot->cpu" variable which was holding the
      index of the NPI port for Felix, and the index of the CPU port module
      for Ocelot, so the variable was actually configuring different things
      for different drivers and causing at least part of the confusion.
      
      Also remove the "ocelot->num_cpu_ports" variable, which is the result of
      another confusion. The 2 CPU ports mentioned in the datasheet are
      because there are two frame extraction channels (register based or DMA
      based). This is of no relevance to the driver at the moment, and
      invisible to the analyzer module.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Suggested-by: NAllan W. Nielsen <allan.nielsen@microchip.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      69df578c
  16. 04 3月, 2020 5 次提交
  17. 06 1月, 2020 1 次提交
  18. 28 11月, 2019 1 次提交