1. 16 1月, 2021 2 次提交
    • V
      net: mscc: ocelot: register devlink ports · 6c30384e
      Vladimir Oltean 提交于
      Add devlink integration into the mscc_ocelot switchdev driver. All
      physical ports (i.e. the unused ones as well) except the CPU port module
      at ocelot->num_phys_ports are registered with devlink, and that requires
      keeping the devlink_port structure outside struct ocelot_port_private,
      since the latter has a 1:1 mapping with a struct net_device (which does
      not exist for unused ports).
      
      Since we use devlink_port_type_eth_set to link the devlink port to the
      net_device, we can as well remove the .ndo_get_phys_port_name and
      .ndo_get_port_parent_id implementations, since devlink takes care of
      retrieving the port name and number automatically, once
      .ndo_get_devlink_port is implemented.
      
      Note that the felix DSA driver is already integrated with devlink by
      default, since that is a thing that the DSA core takes care of. This is
      the reason why these devlink stubs were put in ocelot_net.c and not in
      the common library. It is also the reason why ocelot::devlink is a
      pointer and not a full structure embedded inside struct ocelot: because
      the mscc_ocelot driver allocates that by itself (as the container of
      struct ocelot, in fact), but in the case of felix, it is DSA who
      allocates the devlink, and felix just propagates the pointer towards
      struct ocelot.
      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>
      6c30384e
    • V
      net: mscc: ocelot: delete unused ocelot_set_cpu_port prototype · c6c65d47
      Vladimir Oltean 提交于
      This is a leftover of commit 69df578c ("net: mscc: ocelot: eliminate
      confusion between CPU and NPI port") which renamed that function.
      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>
      c6c65d47
  2. 31 10月, 2020 2 次提交
    • V
      net: mscc: ocelot: support L2 multicast entries · e5d1f896
      Vladimir Oltean 提交于
      There is one main difference in mscc_ocelot between IP multicast and L2
      multicast. With IP multicast, destination ports are encoded into the
      upper bytes of the multicast MAC address. Example: to deliver the
      address 01:00:5E:11:22:33 to ports 3, 8, and 9, one would need to
      program the address of 00:03:08:11:22:33 into hardware. Whereas for L2
      multicast, the MAC table entry points to a Port Group ID (PGID), and
      that PGID contains the port mask that the packet will be forwarded to.
      As to why it is this way, no clue. My guess is that not all port
      combinations can be supported simultaneously with the limited number of
      PGIDs, and this was somehow an issue for IP multicast but not for L2
      multicast. Anyway.
      
      Prior to this change, the raw L2 multicast code was bogus, due to the
      fact that there wasn't really any way to test it using the bridge code.
      There were 2 issues:
      - A multicast PGID was allocated for each MDB entry, but it wasn't in
        fact programmed to hardware. It was dummy.
      - In fact we don't want to reserve a multicast PGID for every single MDB
        entry. That would be odd because we can only have ~60 PGIDs, but
        thousands of MDB entries. So instead, we want to reserve a multicast
        PGID for every single port combination for multicast traffic. And
        since we can have 2 (or more) MDB entries delivered to the same port
        group (and therefore PGID), we need to reference-count the PGIDs.
      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>
      e5d1f896
    • V
      net: mscc: ocelot: make entry_type a member of struct ocelot_multicast · bb8d53fd
      Vladimir Oltean 提交于
      This saves a re-classification of the MDB address on deletion.
      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>
      bb8d53fd
  3. 03 10月, 2020 1 次提交
  4. 14 7月, 2020 2 次提交
    • V
      net: mscc: ocelot: convert QSYS_SWITCH_PORT_MODE and SYS_PORT_MODE to regfields · 886e1387
      Vladimir Oltean 提交于
      Currently Felix and Ocelot share the same bit layout in these per-port
      registers, but Seville does not. So we need reg_fields for that.
      
      Actually since these are per-port registers, we need to also specify the
      number of ports, and register size per port, and use the regmap API for
      multiple ports.
      
      There's a more subtle point to be made about the other 2 register
      fields:
      - QSYS_SWITCH_PORT_MODE_SCH_NEXT_CFG
      - QSYS_SWITCH_PORT_MODE_INGRESS_DROP_MODE
      which we are not writing any longer, for 2 reasons:
      - Using the previous API (ocelot_write_rix), we were only writing 1 for
        Felix and Ocelot, which was their hardware-default value, and which
        there wasn't any intention in changing.
      - In the case of SCH_NEXT_CFG, in fact Seville does not have this
        register field at all, and therefore, if we want to have common code
        we would be required to not write to it.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      886e1387
    • V
      net: mscc: ocelot: convert port registers to regmap · 91c724cf
      Vladimir Oltean 提交于
      At the moment, there are some minimal register differences between
      VSC7514 Ocelot and VSC9959 Felix. To be precise, the PCS1G registers are
      missing from Felix because it was integrated with an NXP PCS.
      
      But with VSC9953 Seville (not yet introduced), the register differences
      are more pronounced.  The MAC registers are located at different offsets
      within the DEV_GMII target. So we need to refactor the driver to keep a
      regmap even for per-port registers. The callers of the ocelot_port_readl
      and ocelot_port_writel were kept unchanged, only the implementation is
      now more generic.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Reviewed-by: NFlorian Fainelli <f.fainelli@gmail.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      91c724cf
  5. 23 6月, 2020 2 次提交
    • 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: 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
  6. 21 6月, 2020 2 次提交
    • 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
    • V
      net: mscc: ocelot: move ocelot_regs.c into ocelot_vsc7514.c · d9feb904
      Vladimir Oltean 提交于
      ocelot_regs.c actually shouldn't be part of the common library. It
      describes the register map of the VSC7514 switch. The way ocelot
      switches work, they'll have highly optimized register maps, so another
      SoC will likely have the same registers but laid out completely
      different in memory (so there's little room for reusing this structure).
      So move it to ocelot_vsc7514.c instead.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      d9feb904
  7. 22 4月, 2020 1 次提交
    • Y
      net: mscc: ocelot: move ocelot ptp clock code out of ocelot.c · 2b49d128
      Yangbo Lu 提交于
      The Ocelot PTP clock driver had been embedded into ocelot.c driver.
      It had supported basic gettime64/settime64/adjtime/adjfine functions
      by now which were used by both Ocelot switch and Felix switch.
      
      This patch is to move current ptp clock code out of ocelot.c driver
      maintaining as a single ocelot_ptp.c.
      For futher new features implementation, the common code could be put
      in ocelot_ptp.c and the switch specific code should be in specific
      switch driver. The interrupt implementation in SoC is different
      between Ocelot and Felix.
      Signed-off-by: NYangbo Lu <yangbo.lu@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      2b49d128
  8. 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
  9. 05 3月, 2020 1 次提交
    • 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
  10. 06 1月, 2020 2 次提交
  11. 22 11月, 2019 1 次提交
  12. 16 11月, 2019 7 次提交
  13. 12 11月, 2019 2 次提交
    • V
      net: mscc: ocelot: split assignment of the cpu port into a separate function · 21468199
      Vladimir Oltean 提交于
      Now that the places that configure routing destinations for the CPU port
      have been marked as such, allow callers to specify their own CPU port
      that is different than ocelot->num_phys_ports. A user will be the Felix
      DSA driver, where the CPU port is one of the physical ports (NPI mode).
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      21468199
    • V
      net: mscc: ocelot: separate net_device related items out of ocelot_port · 004d44f6
      Vladimir Oltean 提交于
      The ocelot and ocelot_port structures will be used by a new DSA driver,
      so the ocelot_board.c file will have to allocate and work with a private
      structure (ocelot_port_private), which embeds the generic struct
      ocelot_port. This is because in DSA, at least one interface does not
      have a net_device, and the DSA driver API does not interact with that
      anyway.
      
      The ocelot_port structure is equivalent to dsa_port, and ocelot to
      dsa_switch. The members of ocelot_port which have an equivalent in
      dsa_port (such as dp->vlan_filtering) have been moved to
      ocelot_port_private.
      
      We want to enforce the coding convention that "ocelot_port" refers to
      the structure, and "port" refers to the integer index. One can retrieve
      the structure at any time from ocelot->ports[port].
      
      The patch is large but only contains variable renaming and mechanical
      movement of fields from one structure to another.
      Signed-off-by: NVladimir Oltean <vladimir.oltean@nxp.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      004d44f6
  14. 07 11月, 2019 1 次提交
  15. 16 8月, 2019 3 次提交
  16. 03 6月, 2019 1 次提交
  17. 30 5月, 2019 1 次提交
  18. 23 5月, 2019 1 次提交
  19. 28 2月, 2019 1 次提交
  20. 24 11月, 2018 1 次提交
    • P
      ocelot: Handle SWITCHDEV_PORT_OBJ_ADD/_DEL · 0e332c85
      Petr Machata 提交于
      Following patches will change the way of distributing port object
      changes from a switchdev operation to a switchdev notifier. The
      switchdev code currently recursively descends through layers of lower
      devices, eventually calling the op on a front-panel port device. The
      notifier will instead be sent referencing the bridge port device, which
      may be a stacking device that's one of front-panel ports uppers, or a
      completely unrelated device.
      
      Dispatch the new events to ocelot_port_obj_add() resp. _del() to
      maintain the same behavior that the switchdev operation based code
      currently has. Pass through switchdev_handle_port_obj_add() / _del() to
      handle the recursive descend, because Ocelot supports LAG uppers.
      
      Register to the new switchdev blocking notifier chain to get the new
      events when they start getting distributed.
      Signed-off-by: NPetr Machata <petrm@mellanox.com>
      Acked-by: NJiri Pirko <jiri@mellanox.com>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      0e332c85
  21. 06 10月, 2018 3 次提交
  22. 28 6月, 2018 1 次提交
  23. 16 5月, 2018 1 次提交
    • A
      net: mscc: Add initial Ocelot switch support · a556c76a
      Alexandre Belloni 提交于
      Add a driver for Microsemi Ocelot Ethernet switch support.
      
      This makes two modules:
      mscc_ocelot_common handles all the common features that doesn't depend on
      how the switch is integrated in the SoC. Currently, it handles offloading
      bridging to the hardware. ocelot_io.c handles register accesses. This is
      unfortunately needed because the register layout is packed and then depends
      on the number of ports available on the switch. The register definition
      files are automatically generated.
      
      ocelot_board handles the switch integration on the SoC and on the board.
      
      Frame injection and extraction to/from the CPU port is currently done using
      register accesses which is quite slow. DMA is possible but the port is not
      able to absorb the whole switch bandwidth.
      Signed-off-by: NAlexandre Belloni <alexandre.belloni@bootlin.com>
      Reviewed-by: NAndrew Lunn <andrew@lunn.ch>
      Signed-off-by: NDavid S. Miller <davem@davemloft.net>
      a556c76a