1. 03 11月, 2020 3 次提交
    • V
      net: mscc: ocelot: transform the pvid and native vlan values into a structure · c3e58a75
      Vladimir Oltean 提交于
      This is a mechanical patch only.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      c3e58a75
    • V
      net: mscc: ocelot: don't reset the pvid to 0 when deleting it · 110e847c
      Vladimir Oltean 提交于
      I have no idea why this code is here, but I have 2 hypotheses:
      
      1.
      A desperate attempt to keep untagged traffic working when the bridge
      deletes the pvid on a port.
      
      There was a fairly okay discussion here:
      https://lore.kernel.org/netdev/CA+h21hrRMrLH-RjBGhEJSTZd6_QPRSd3RkVRQF-wNKkrgKcRSA@mail.gmail.com/#t
      which established that in vlan_filtering=1 mode, the absence of a pvid
      should denote that the ingress port should drop untagged and priority
      tagged traffic. While in vlan_filtering=0 mode, nothing should change.
      
      So in vlan_filtering=1 mode, we should simply let things happen, and not
      attempt to save the day. And in vlan_filtering=0 mode, the pvid is 0
      anyway, no need to do anything.
      
      2.
      The driver encodes the native VLAN (ocelot_port->vid) value of 0 as
      special, meaning "not valid". There are checks based on that. But there
      are no such checks for the ocelot_port->pvid value of 0. In fact, that's
      a perfectly valid value, which is used in standalone mode. Maybe there
      was some confusion and the author thought that 0 means "invalid" here as
      well.
      
      In conclusion, delete the code*.
      
      *in fact we'll add it back later, in a slightly different form, but for
      an entirely different reason than the one for which this exists now.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      110e847c
    • V
      net: mscc: ocelot: use the pvid of zero when bridged with vlan_filtering=0 · 75e5a554
      Vladimir Oltean 提交于
      Currently, mscc_ocelot ports configure pvid=0 in standalone mode, and
      inherit the pvid from the bridge when one is present.
      
      When the bridge has vlan_filtering=0, the software semantics are that
      packets should be received regardless of whether there's a pvid
      configured on the ingress port or not. However, ocelot does not observe
      those semantics today.
      
      Moreover, changing the PVID is also a problem with vlan_filtering=0.
      We are privately remapping the VID of FDB, MDB entries to the port's
      PVID when those are VLAN-unaware (i.e. when the VID of these entries
      comes to us as 0). But we have no logic of adjusting that remapping when
      the user changes the pvid and vlan_filtering is 0. So stale entries
      would be left behind, and untagged traffic will stop matching on them.
      
      And even if we were to solve that, there's an even bigger problem. If
      swp0 has pvid 1, and swp1 has pvid 2, and both are under a vlan_filtering=0
      bridge, they should be able to forward traffic between one another.
      However, with ocelot they wouldn't do that.
      
      The simplest way of fixing this is to never configure the pvid based on
      what the bridge is asking for, when vlan_filtering is 0. Only if there
      was a VLAN that the bridge couldn't mangle, that we could use as pvid....
      So, turns out, there's 0 just for that. And for a reason: IEEE
      802.1Q-2018, page 247, Table 9-2-Reserved VID values says:
      
      	The null VID. Indicates that the tag header contains only
      	priority information; no VID is present in the frame.
      	This VID value shall not be configured as a PVID or a member
      	~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
      	of a VID Set, or configured in any FDB entry, or used in any
      	Management operation.
      
      So, aren't we doing exactly what 802.1Q says not to? Well, in a way, but
      what we're doing here is just driver-level bookkeeping, all for the
      better. The fact that we're using a pvid of 0 is not observable behavior
      from the outside world: the network stack does not see the classified
      VLAN that the switch uses, in vlan_filtering=0 mode. And we're also more
      consistent with the standalone mode now.
      
      And now that we use the pvid of 0 in this mode, there's another advantage:
      we don't need to perform any VID remapping for FDB and MDB entries either,
      we can just use the VID of 0 that the bridge is passing to us.
      
      The only gotcha is that every time we change the vlan_filtering setting,
      we need to reapply the pvid (either to 0, or to the value from the bridge).
      A small side-effect visible in the patch is that ocelot_port_set_pvid
      needs to be moved above ocelot_port_vlan_filtering, so that it can be
      called from there without forward-declarations.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      75e5a554
  2. 31 10月, 2020 5 次提交
  3. 12 10月, 2020 1 次提交
    • V
      net: mscc: ocelot: offload VLAN mangle action to VCAP IS1 · 70edfae1
      Vladimir Oltean 提交于
      The VCAP_IS1_ACT_VID_REPLACE_ENA action, from the VCAP IS1 ingress TCAM,
      changes the classified VLAN.
      
      We are only exposing this ability for switch ports that are under VLAN
      aware bridges. This is because in standalone ports mode and under a
      bridge with vlan_filtering=0, the ocelot driver configures the switch to
      operate as VLAN-unaware, so the classified VLAN is not derived from the
      802.1Q header from the packet, but instead is always equal to the
      port-based VLAN ID of the ingress port. We _can_ still change the
      classified VLAN for packets when operating in this mode, but the end
      result will most likely be a drop, since both the ingress and the egress
      port need to be members of the modified VLAN. And even if we install the
      new classified VLAN into the VLAN table of the switch, the result would
      still not be as expected: we wouldn't see, on the output port, the
      modified VLAN tag, but the original one, even though the classified VLAN
      was indeed modified. This is because of how the hardware works: on
      egress, what is pushed to the frame is a "port tag", which gives us the
      following options:
      
      - Tag all frames with port tag (derived from the classified VLAN)
      - Tag all frames with port tag, except if the classified VLAN is 0 or
        equal to the native VLAN of the egress port
      - No port tag
      
      Needless to say, in VLAN-unaware mode we are disabling the port tag.
      Otherwise, the existing VLAN tag would be ignored, and a second VLAN
      tag (the port tag), holding the classified VLAN, would be pushed
      (instead of replacing the existing 802.1Q tag). This is definitely not
      what the user wanted when installing a "vlan modify" action.
      
      So it is simply not worth bothering with VLAN modify rules under other
      configurations except when the ports are fully VLAN-aware.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NJakub Kicinski <kuba@kernel.org>
      70edfae1
  4. 06 10月, 2020 1 次提交
  5. 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
  6. 03 10月, 2020 2 次提交
    • X
      net: mscc: ocelot: offload egress VLAN rewriting to VCAP ES0 · 2f17c050
      Xiaoliang Yang 提交于
      VCAP ES0 is an egress VCAP operating on all outgoing frames.
      This patch added ES0 driver to support vlan push action of tc filter.
      Usage:
      
      tc filter add dev swp1 egress protocol 802.1Q flower indev swp0 skip_sw \
              vlan_id 1 vlan_prio 1 action vlan push id 2 priority 2
      Signed-off-by: NXiaoliang Yang <xiaoliang.yang_1@nxp.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2f17c050
    • X
      net: mscc: ocelot: offload ingress skbedit and vlan actions to VCAP IS1 · 75944fda
      Xiaoliang Yang 提交于
      VCAP IS1 is a VCAP module which can filter on the most common L2/L3/L4
      Ethernet keys, and modify the results of the basic QoS classification
      and VLAN classification based on those flow keys.
      
      There are 3 VCAP IS1 lookups, mapped over chains 10000, 11000 and 12000.
      Currently the driver is hardcoded to use IS1_ACTION_TYPE_NORMAL half
      keys.
      
      Note that the VLAN_MANGLE has been omitted for now. In hardware, the
      VCAP_IS1_ACT_VID_REPLACE_ENA field replaces the classified VLAN
      (metadata associated with the frame) and not the VLAN from the header
      itself. There are currently some issues which need to be addressed when
      operating in standalone, or in bridge with vlan_filtering=0 modes,
      because in those cases the switch ports have VLAN awareness disabled,
      and changing the classified VLAN to anything other than the pvid causes
      the packets to be dropped. Another issue is that on egress, we expect
      port tagging to push the classified VLAN, but port tagging is disabled
      in the modes mentioned above, so although the classified VLAN is
      replaced, it is not visible in the packet transmitted by the switch.
      Signed-off-by: NXiaoliang Yang <xiaoliang.yang_1@nxp.com>
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      75944fda
  7. 30 9月, 2020 1 次提交
    • 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
  8. 27 9月, 2020 1 次提交
    • 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
  9. 25 9月, 2020 1 次提交
  10. 19 9月, 2020 2 次提交
  11. 24 8月, 2020 1 次提交
  12. 28 7月, 2020 1 次提交
  13. 14 7月, 2020 5 次提交
  14. 23 6月, 2020 5 次提交
    • V
      net: mscc: ocelot: support IPv4, IPv6 and plain Ethernet mdb entries · 9403c158
      Vladimir Oltean 提交于
      The current procedure for installing a multicast address is hardcoded
      for IPv4. But, in the ocelot hardware, there are 3 different procedures
      for IPv4, IPv6 and for regular L2 multicast.
      
      For IPv6 (33-33-xx-xx-xx-xx), it's the same as for IPv4
      (01-00-5e-xx-xx-xx), except that the destination port mask is stuffed
      into first 2 bytes of the MAC address except into first 3 bytes.
      
      For plain Ethernet multicast, there's no port-in-address stuffing going
      on, instead the DEST_IDX (pointer to PGID) is used there, just as for
      unicast. So we have to use one of the nonreserved multicast PGIDs that
      the hardware has allocated for this purpose.
      
      This patch classifies the type of multicast address based on its first
      bytes, then redirects to one of the 3 different hardware procedures.
      
      Note that this gives us a really better way of redirecting PTP frames
      sent at 01-1b-19-00-00-00 to the CPU. Previously, Yangbo Lu tried to add
      a trapping rule for PTP EtherType but got a lot of pushback:
      
      https://patchwork.ozlabs.org/project/netdev/patch/20190813025214.18601-5-yangbo.lu@nxp.com/
      
      But right now, that isn't needed at all. The application stack (ptp4l)
      does this for the PTP multicast addresses it's interested in (which are
      configurable, and include 01-1b-19-00-00-00):
      
      	memset(&mreq, 0, sizeof(mreq));
      	mreq.mr_ifindex = index;
      	mreq.mr_type = PACKET_MR_MULTICAST;
      	mreq.mr_alen = MAC_LEN;
      	memcpy(mreq.mr_address, addr1, MAC_LEN);
      
      	err1 = setsockopt(fd, SOL_PACKET, PACKET_ADD_MEMBERSHIP, &mreq,
      			  sizeof(mreq));
      
      Into the kernel, this translates into a dev_mc_add on the switch network
      interfaces, and our drivers know that it means they should translate it
      into a host MDB address (make the CPU port be the destination).
      Previously, this was broken because all mdb addresses were treated as
      IPv4 (which 01-1b-19-00-00-00 obviously is not).
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      9403c158
    • V
      net: mscc: ocelot: introduce macros for iterating over PGIDs · 96b029b0
      Vladimir Oltean 提交于
      The current iterators are impossible to understand at first glance
      without switching back and forth between the definitions and their
      actual use in the for loops.
      
      So introduce some convenience names to help readability.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      96b029b0
    • V
      net: dsa: felix: call port mdb operations from ocelot · 209edf95
      Vladimir Oltean 提交于
      This adds the mdb hooks in felix and exports the mdb functions from
      ocelot.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      209edf95
    • V
      net: mscc: ocelot: make the NPI port a proper target for FDB and MDB · 471beb11
      Vladimir Oltean 提交于
      When used in DSA mode (as seen in Felix), the DEST_IDX in the MAC table
      should point to the PGID for the CPU port (PGID_CPU) and not for the
      Ethernet port where the CPU queues are redirected to (also known as Node
      Processor Interface - NPI).
      
      Because for Felix this distinction shouldn't really matter (from DSA
      perspective, the NPI port _is_ the CPU port), make the ocelot library
      act upon the CPU port when NPI mode is enabled. This has no effect for
      the mscc_ocelot driver for VSC7514, because that does not use NPI (and
      ocelot->npi is -1).
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      471beb11
    • 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
  15. 21 6月, 2020 3 次提交
    • 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
    • V
      net: mscc: ocelot: rename ocelot_ace.{c, h} to ocelot_vcap.{c,h} · 3c83654f
      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 files that deal with generic operations on the VCAP
      TCAM, so that VCAP IS1 and ES0 can reuse the same code without
      confusion.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      3c83654f
    • V
      net: mscc: ocelot: move net_device related functions to ocelot_net.c · 9c90eea3
      Vladimir Oltean 提交于
      The ocelot hardware library shouldn't contain too much net_device
      specific code, since it is shared with DSA which abstracts that
      structure away. So much as much of this code as possible into the
      mscc_ocelot driver and outside of the common library.
      
      We're making an exception for MDB and LAG code. That is not yet exported
      to DSA, but when it will, most of the code that's already in ocelot.c
      will remain there. So, there's no point in moving code to ocelot_net.c
      just to move it back later.
      
      We could have moved all net_device code to ocelot_vsc7514.c directly,
      but let's operate under the assumption that if a new switchdev ocelot
      driver gets added, it'll define its SoC-specific stuff in a new
      ocelot_vsc*.c file and it'll reuse the rest of the code.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      9c90eea3
  16. 28 5月, 2020 2 次提交
  17. 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
  18. 07 5月, 2020 2 次提交
  19. 22 4月, 2020 2 次提交