1. 23 6月, 2020 1 次提交
    • V
      net: mscc: ocelot: fix encoding destination ports into multicast IPv4 address · 0897ecf7
      Vladimir Oltean 提交于
      The ocelot hardware designers have made some hacks to support multicast
      IPv4 and IPv6 addresses. Normally, the MAC table matches on MAC
      addresses and the destination ports are selected through the DEST_IDX
      field of the respective MAC table entry. The DEST_IDX points to a Port
      Group ID (PGID) which contains the bit mask of ports that frames should
      be forwarded to. But there aren't a lot of PGIDs (only 80 or so) and
      there are clearly many more IP multicast addresses than that, so it
      doesn't scale to use this PGID mechanism, so something else was done.
      Since the first portion of the MAC address is known, the hack they did
      was to use a single PGID for _flooding_ unknown IPv4 multicast
      (PGID_MCIPV4 == 62), but for known IP multicast, embed the destination
      ports into the first 3 bytes of the MAC address recorded in the MAC
      table.
      
      The VSC7514 datasheet explains it like this:
      
          3.9.1.5 IPv4 Multicast Entries
      
          MAC table entries with the ENTRY_TYPE = 2 settings are interpreted
          as IPv4 multicast entries.
          IPv4 multicasts entries match IPv4 frames, which are classified to
          the specified VID, and which have DMAC = 0x01005Exxxxxx, where
          xxxxxx is the lower 24 bits of the MAC address in the entry.
          Instead of a lookup in the destination mask table (PGID), the
          destination set is programmed as part of the entry MAC address. This
          is shown in the following table.
      
          Table 78: IPv4 Multicast Destination Mask
      
              Destination Ports            Record Bit Field
              ---------------------------------------------
              Ports 10-0                   MAC[34-24]
      
          Example: All IPv4 multicast frames in VLAN 12 with MAC 01005E112233 are
          to be forwarded to ports 3, 8, and 9. This is done by inserting the
          following entry in the MAC table entry:
          VALID = 1
          VID = 12
          MAC = 0x000308112233
          ENTRY_TYPE = 2
          DEST_IDX = 0
      
      But this procedure is not at all what's going on in the driver. In fact,
      the code that embeds the ports into the MAC address looks like it hasn't
      actually been tested. This patch applies the procedure described in the
      datasheet.
      
      Since there are many other fixes to be made around multicast forwarding
      until it works properly, there is no real reason for this patch to be
      backported to stable trees, or considered a real fix of something that
      should have worked.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      0897ecf7
  2. 21 6月, 2020 11 次提交
  3. 20 6月, 2020 1 次提交
  4. 28 5月, 2020 2 次提交
  5. 23 5月, 2020 1 次提交
    • V
      net: mscc: ocelot: fix address ageing time (again) · bf655ba2
      Vladimir Oltean 提交于
      ocelot_set_ageing_time has 2 callers:
       - felix_set_ageing_time: from drivers/net/dsa/ocelot/felix.c
       - ocelot_port_attr_ageing_set: from drivers/net/ethernet/mscc/ocelot.c
      
      The issue described in the fixed commit below actually happened for the
      felix_set_ageing_time code path only, since ocelot_port_attr_ageing_set
      was already dividing by 1000. So to make both paths symmetrical (and to
      fix addresses getting aged way too fast on Ocelot), stop dividing by
      1000 at caller side altogether.
      
      Fixes: c0d7eccb ("net: mscc: ocelot: ANA_AUTOAGE_AGE_PERIOD holds a value in seconds, not ms")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      bf655ba2
  6. 08 5月, 2020 1 次提交
    • J
      net: remove newlines in NL_SET_ERR_MSG_MOD · c75a33c8
      Jacob Keller 提交于
      The NL_SET_ERR_MSG_MOD macro is used to report a string describing an
      error message to userspace via the netlink extended ACK structure. It
      should not have a trailing newline.
      
      Add a cocci script which catches cases where the newline marker is
      present. Using this script, fix the handful of cases which accidentally
      included a trailing new line.
      
      I couldn't figure out a way to get a patch mode working, so this script
      only implements context, report, and org.
      Signed-off-by: NJacob Keller <jacob.e.keller@intel.com>
      Cc: Jakub Kicinski <kuba@kernel.org>
      Cc: Andy Whitcroft <apw@canonical.com>
      Cc: Joe Perches <joe@perches.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      c75a33c8
  7. 07 5月, 2020 2 次提交
  8. 23 4月, 2020 3 次提交
    • V
      net: mscc: ocelot: lift protocol restriction for flow_match_eth_addrs keys · 4faa2e06
      Vladimir Oltean 提交于
      An attempt was made in commit fe3490e6 ("net: mscc: ocelot: Hardware
      ofload for tc flower filter") to avoid clashes between MAC_ETYPE rules
      and IP rules. Because the protocol blacklist should have included
      ETH_P_ALL too, it created some confusion, but now the situation should
      be dealt with a bit better by the patch immediately previous to this one
      ("net: mscc: ocelot: refine the ocelot_ace_is_problematic_mac_etype
      function").
      
      So now we can remove that check. MAC_ETYPE rules with a protocol of
      ETH_P_IP, ETH_P_IPV6, ETH_P_ARP and ETH_P_ALL _are_ supported, with some
      restrictions regarding per-port exclusivity which are enforced now.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      4faa2e06
    • V
      net: mscc: ocelot: refine the ocelot_ace_is_problematic_mac_etype function · 7dec902f
      Vladimir Oltean 提交于
      The commit mentioned below was a bit too harsh, and while it restricted
      the invalid key combinations which are known to not work, such as:
      
      tc filter add dev swp0 ingress proto ip \
            flower src_ip 192.0.2.1 action drop
      tc filter add dev swp0 ingress proto all \
            flower src_mac 00:11:22:33:44:55 action drop
      
      it also restricted some which still should work, such as:
      
      tc filter add dev swp0 ingress proto ip \
            flower src_ip 192.0.2.1 action drop
      tc filter add dev swp0 ingress proto 0x22f0 \
            flower src_mac 00:11:22:33:44:55 action drop
      
      What actually does not match "sanely" is a MAC_ETYPE rule on frames
      having an EtherType of ARP, IPv4, IPv6, in addition to SNAP and OAM
      frames (which the ocelot tc-flower implementation does not parse yet, so
      the function might need to be revisited again in the future).
      
      So just make the function recognize the problematic MAC_ETYPE rules by
      EtherType - thus the VCAP IS2 can be forced to match even on those
      packets.
      
      This patch makes it possible for IP rules to live on a port together
      with MAC_ETYPE rules that are non-all, non-arp, non-ip and non-ipv6.
      
      Fixes: d4d0cb741d7b ("net: mscc: ocelot: deal with problematic MAC_ETYPE VCAP IS2 rules")
      Reported-by: NAllan W. Nielsen <allan.nielsen@microchip.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      7dec902f
    • V
      net: mscc: ocelot: support matching on EtherType · 86b956de
      Vladimir Oltean 提交于
      Currently, the filter's protocol is ignored except for a few special
      cases (IPv4 and IPv6).
      
      The EtherType can be matched inside VCAP IS2 by using a MAC_ETYPE key.
      So there are 2 cases in which EtherType matches are supported:
      
        - As part of a larger MAC_ETYPE rule, such as:
      
          tc filter add dev swp0 ingress protocol ip \
                  flower skip_sw src_mac 42:be:24:9b:76:20 action drop
      
        - Standalone (matching on protocol only):
      
          tc filter add dev swp0 ingress protocol arp \
                  flower skip_sw action drop
      
      As before, if the protocol is not specified, is it implicitly "all" and
      the EtherType mask in the MAC_ETYPE half key is set to zero.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      86b956de
  9. 22 4月, 2020 5 次提交
  10. 19 4月, 2020 1 次提交
    • V
      net: mscc: ocelot: deal with problematic MAC_ETYPE VCAP IS2 rules · 89f9ffd3
      Vladimir Oltean 提交于
      By default, the VCAP IS2 will produce a single match for each frame, on
      the most specific classification.
      
      Example: a ping packet (ICMP over IPv4 over Ethernet) sent from an IP
      address of 10.0.0.1 and a MAC address of 96:18:82:00:04:01 will match
      this rule:
      
      tc filter add dev swp0 ingress protocol ipv4 \
      	flower skip_sw src_ip 10.0.0.1 action drop
      
      but not this one:
      
      tc filter add dev swp0 ingress \
      	flower skip_sw src_mac 96:18:82:00:04:01 action drop
      
      Currently the driver does not really warn the user in any way about
      this, and the behavior is rather strange anyway.
      
      The current patch is a workaround to force matches on MAC_ETYPE keys
      (DMAC and SMAC) for all packets irrespective of higher layer protocol.
      The setting is made at the port level.
      
      Of course this breaks all other non-src_mac and non-dst_mac matches, so
      rule exclusivity checks have been added to the driver, in order to never
      have rules of both types on any ingress port.
      
      The bits that discard higher-level protocol information are set only
      once a MAC_ETYPE rule is added to a filter block, and only for the ports
      that are bound to that filter block. Then all further non-MAC_ETYPE
      rules added to that filter block should be denied by the ports bound to
      it.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      89f9ffd3
  11. 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
  12. 31 3月, 2020 3 次提交
  13. 28 3月, 2020 1 次提交
  14. 18 3月, 2020 1 次提交
  15. 15 3月, 2020 1 次提交
  16. 10 3月, 2020 1 次提交
    • V
      net: mscc: ocelot: properly account for VLAN header length when setting MRU · a8015ded
      Vladimir Oltean 提交于
      What the driver writes into MAC_MAXLEN_CFG does not actually represent
      VLAN_ETH_FRAME_LEN but instead ETH_FRAME_LEN + ETH_FCS_LEN. Yes they are
      numerically equal, but the difference is important, as the switch treats
      VLAN-tagged traffic specially and knows to increase the maximum accepted
      frame size automatically. So it is always wrong to account for VLAN in
      the MAC_MAXLEN_CFG register.
      
      Unconditionally increase the maximum allowed frame size for
      double-tagged traffic. Accounting for the additional length does not
      mean that the other VLAN membership checks aren't performed, so there's
      no harm done.
      
      Also, stop abusing the MTU name for configuring the MRU. There is no
      support for configuring the MRU on an interface at the moment.
      
      Fixes: a556c76a ("net: mscc: Add initial Ocelot switch support")
      Fixes: fa914e9c ("net: mscc: ocelot: create a helper for changing the port MTU")
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a8015ded
  17. 09 3月, 2020 2 次提交
  18. 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