Skip to contentSkip to conversation

Adding the Sparx5 Switch Driver

RFC PATCH In review Steen Hegelund 7 participants 38 messages Dec 17, 2020 – Dec 23, 2020

Subsystems (5)
lore
Share & tools
lore

Steen Hegelund

author maintainer
#0 lore raw

v2 cover Adding the Sparx5 Switch Driver

This series provides the Microchip Sparx5 Switch Driver

The Sparx5 Carrier Ethernet and Industrial switch family delivers 64 Ethernet ports and up to 200 Gbps of switching bandwidth.

It provides a rich set of Ethernet switching features such as hierarchical QoS, hardware-based OAM and service activation testing, protection switching, IEEE 1588, and Synchronous Ethernet.

Using provider bridging (Q-in-Q) and MPLS/MPLS-TP technology, it delivers MEF CE
2.0 Ethernet virtual connections (EVCs) and features advanced TCAM
classification in both ingress and egress.

Per-EVC features include advanced L3-aware classification, a rich set of statistics, OAM for end-to-end performance monitoring, and dual-rate policing and shaping.

Time sensitive networking (TSN) is supported through a comprehensive set of features including frame preemption, cut-through, frame replication and elimination for reliability, enhanced scheduling: credit-based shaping, time-aware shaping, cyclic queuing, and forwarding, and per-stream policing and filtering.

Together with IEEE 1588 and IEEE 802.1AS support, this guarantees low-latency deterministic networking for Fronthaul, Carrier, and Industrial Ethernet.

The Sparx5 switch family consists of following SKUs:

- VSC7546 Sparx5-64 up to 64 Gbps of bandwidth with the following primary port configurations:
- 6 *10G
- 16 * 2.5G + 2 * 10G
- 24 * 1G + 4 * 10G

- VSC7549 Sparx5-90 up to 90 Gbps of bandwidth with the following primary port configurations:
- 9 * 10G
- 16 * 2.5G + 4 * 10G
- 48 * 1G + 4 * 10G

- VSC7552 Sparx5-128 up to 128 Gbps of bandwidth with the following primary port configurations:
- 12 * 10G
- 16 * 2.5G + 8 * 10G
- 48 * 1G + 8 * 10G

- VSC7556 Sparx5-160 up to 160 Gbps of bandwidth with the following primary port configurations:
- 16 * 10G
- 10 * 10G + 2 * 25G
- 16 * 2.5G + 10 * 10G
- 48 * 1G + 10 * 10G

- VSC7558 Sparx5-200 up to 200 Gbps of bandwidth with the following primary port configurations:
- 20 * 10G
- 8 * 25G

In addition, the device supports one 10/100/1000/2500/5000 Mbps SGMII/SerDes node processor interface (NPI) Ethernet port.

The Sparx5 support is developed on the PCB134 and PCB135 evaluation boards.

- PCB134 main networking features:
- 12x SFP+ front 10G module slots (connected to Sparx5 through SFI).
- 8x SFP28 front 25G module slots (connected to Sparx5 through SFI high

    speed).

- Optional, one additional 10/100/1000BASE-T (RJ45) Ethernet port (on-board VSC8211 PHY connected to Sparx5 through SGMII).

- PCB135 main networking features:
- 48x1G (10/100/1000M) RJ45 front ports using 12xVSC8514 QuadPHY’s each connected to VSC7558 through QSGMII.
- 4x10G (1G/2.5G/5G/10G) RJ45 front ports using the AQR407 10G QuadPHY each port connects to VSC7558 through SFI.
- 4x SFP28 25G module slots on back connected to VSC7558 through SFI high speed.
- Optional, one additional 1G (10/100/1000M) RJ45 port using an on-board VSC8211 PHY, which can be connected to VSC7558 NPI port through SGMII using a loopback add-on PCB)

This series provides support for:
- SFPs and DAC cables via PHYLINK with a number of 5G, 10G and 25G devices and media types.
- Port module configuration for 10M to 25G speeds with SGMII, QSGMII, 1000BASEX, 2500BASEX and 10GBASER as appropriate for these modes.
- SerDes configuration via the Sparx5 SerDes driver (see below).
- Host mode providing register based injection and extraction.
- Switch mode providing MAC/VLAN table learning and Layer2 switching offloaded to the Sparx5 switch.
- STP state, VLAN support, host/bridge port mode, Forwarding DB, and configuration and statistics via ethtool.

More support will be added at a later stage.

The Sparx5 Switch chip register model can be browsed here:

The series depends on the following series currently on their way into the kernel:

- Sparx5 SerDes Driver

- Serial GPIO Controller

ChangeLog:
v2:
- The driver patch has been split into 6 patches by functionality like this:
- the basic sparx5 driver
- hostmode with phylink support
- port module support
- switching, vlan and mactable support
- calendar bandwidth allocation support
- ethtool configuration and statistics support
- IO ranges have been collapsed into just 2 (the SerDes driver uses the area inbetween) and the driver uses an offset table to get the target instances.
- register macros have been converted to functions
- register_netdev() moved to the end of the switch initialization.
- sparx5_update_port_stats: use reverse christmas tree
- sparx5_get_sset_strings: copy individual strings
- sparx5_port_open: updated to better use phylink: just call phylink_of_phy_connect directly
- sparx5_destroy_netdev: always take the NL lock
- sparx5_attr_stp_state_set: added learning state.
- sparx5_phylink_mac_config: use phylink to provide the status for the devices phylink controls.
- sparx5_get_1000basex_status: renamed to sparx5_get_dev2g5_status and corrected an error when combining the sync and link status information.
- let phylink provide link status for cuPHYs and SFPs
- corrected the pause mode status handling
- use ethtool's get_link function directly
- remove the use of the phy_validate function
- sparx5_update_counter function: no longer inline
- Removed the wrapper functions around the mactable mutex

Steen Hegelund (8):
dt-bindings: net: sparx5: Add sparx5-switch bindings
net: sparx5: add the basic sparx5 driver
net: sparx5: add hostmode with phylink support
net: sparx5: add port module support
net: sparx5: add switching, vlan and mactable support
net: sparx5: add calendar bandwidth allocation support
net: sparx5: add ethtool configuration and statistics support
arm64: dts: sparx5: Add the Sparx5 switch node

 .../bindings/net/microchip,sparx5-switch.yaml |  178 +
 arch/arm64/boot/dts/microchip/sparx5.dtsi     |   60 +
 .../dts/microchip/sparx5_pcb134_board.dtsi    |  424 +-
 .../dts/microchip/sparx5_pcb135_board.dtsi    |  602 ++-
 drivers/net/ethernet/microchip/Kconfig        |    2 +
 drivers/net/ethernet/microchip/Makefile       |    2 +
 drivers/net/ethernet/microchip/sparx5/Kconfig |    8 +
 .../net/ethernet/microchip/sparx5/Makefile    |   11 +
 .../microchip/sparx5/sparx5_calendar.c        |  595 +++
 .../microchip/sparx5/sparx5_ethtool.c         |  979 ++++
 .../microchip/sparx5/sparx5_mactable.c        |  502 +++
 .../ethernet/microchip/sparx5/sparx5_main.c   |  855 ++++
 .../ethernet/microchip/sparx5/sparx5_main.h   |  372 ++
 .../microchip/sparx5/sparx5_main_regs.h       | 3922 +++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_netdev.c |  246 ++
 .../ethernet/microchip/sparx5/sparx5_packet.c |  279 ++
 .../microchip/sparx5/sparx5_phylink.c         |  193 +
 .../ethernet/microchip/sparx5/sparx5_port.c   | 1140 +++++
 .../ethernet/microchip/sparx5/sparx5_port.h   |   98 +
 .../microchip/sparx5/sparx5_switchdev.c       |  516 +++
 .../ethernet/microchip/sparx5/sparx5_vlan.c   |  223 +
 21 files changed, 11147 insertions(+), 60 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml
 create mode 100644 drivers/net/ethernet/microchip/sparx5/Kconfig
 create mode 100644 drivers/net/ethernet/microchip/sparx5/Makefile
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_calendar.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_main.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_main.h
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_phylink.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_port.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_port.h
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c

--
2.29.2

author maintainer
#1 lore raw

RFC PATCH v2 1/8 dt-bindings: net: sparx5: Add sparx5-switch bindings

Document the Sparx5 switch device driver bindings

---
 .../bindings/net/microchip,sparx5-switch.yaml | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +178 -0
new file mode 100644
index 000000000000..6e3ef8285e9a
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/microchip,sparx5-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip Sparx5 Ethernet switch controller
+
+maintainers:
+  - Lars Povlsen <[email protected]>
+  - Steen Hegelund <[email protected]>
+
+description: |
+  The SparX-5 Enterprise Ethernet switch family provides a rich set of
+  Enterprise switching features such as advanced TCAM-based VLAN and
+  QoS processing enabling delivery of differentiated services, and
+  security through TCAM-based frame processing using versatile content
+  aware processor (VCAP).
+
+  IPv4/IPv6 Layer 3 (L3) unicast and multicast routing is supported
+  with up to 18K IPv4/9K IPv6 unicast LPM entries and up to 9K IPv4/3K
+  IPv6 (S,G) multicast groups.
+
+  L3 security features include source guard and reverse path
+  forwarding (uRPF) tasks. Additional L3 features include VRF-Lite and
+  IP tunnels (IP over GRE/IP).
+
+  The SparX-5 switch family targets managed Layer 2 and Layer 3
+  equipment in SMB, SME, and Enterprise where high port count
+  1G/2.5G/5G/10G switching with 10G/25G aggregation links is required.
+
+properties:
+  $nodename:
+    pattern: "^switch@[0-9a-f]+$"
+
+  compatible:
+    const: microchip,sparx5-switch
+
+  reg:
+    minItems: 2
+
+  reg-names:
+    minItems: 2
+    items:
+      - const: devices
+      - const: gcb
+
+  interrupts:
+    maxItems: 1
+    description: Interrupt used for reception of packets to the CPU
+
+  ethernet-ports:
+    type: object
+    properties:
+      '#address-cells':
+        const: 1
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Switch ports
+
+        allOf:
+          - $ref: ethernet-controller.yaml#
+
+        properties:
+          reg:
+            description: Switch port number
+
+          max-speed:
+            maxItems: 1
+            description: Bandwidth allocated to this port
+
+          phys:
+            description: phandle of a Ethernet Serdes PHY
+
+          phy-handle:
+            description: phandle of a Ethernet PHY
+
+          phy-mode:
+            description: Interface between the serdes and the phy
+
+          sfp:
+            description: phandle of an SFP
+
+          managed:
+            maxItems: 1
+            description: SFP management
+
+        required:
+          - reg
+          - max-speed
+          - phys
+
+        oneOf:
+          - required:
+              - phy-handle
+              - phy-mode
+          - required:
+              - sfp
+              - managed
+
+        additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - ethernet-ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    switch: switch@600000000 {
+      compatible = "microchip,sparx5-switch";
+      reg =  <0x10000000 0x800000>,
+             <0x11010000 0x1b00000>;
+      reg-names = "devices", "gcb";
+
+      interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
+      ethernet-ports {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        port0: port@0 {
+          reg = <0>;
+          max-speed = <1000>;
+          phys = <&serdes 13>;
+          phy-handle = <&phy0>;
+          phy-mode = "qsgmii";
+        };
+        /* ... */
+        /* Then the 25G interfaces */
+        port60: port@60 {
+          reg = <60>;
+          max-speed = <25000>;
+          phys = <&serdes 29>;
+          sfp = <&sfp_eth60>;
+          managed = "in-band-status";
+        };
+        port61: port@61 {
+          reg = <61>;
+          max-speed = <25000>;
+          phys = <&serdes 30>;
+          sfp = <&sfp_eth61>;
+          managed = "in-band-status";
+        };
+        port62: port@62 {
+          reg = <62>;
+          max-speed = <25000>;
+          phys = <&serdes 31>;
+          sfp = <&sfp_eth62>;
+          managed = "in-band-status";
+        };
+        port63: port@63 {
+          reg = <63>;
+          max-speed = <25000>;
+          phys = <&serdes 32>;
+          sfp = <&sfp_eth63>;
+          managed = "in-band-status";
+        };
+        /* Finally the Management interface */
+        port64: port@64 {
+          reg = <64>;
+          max-speed = <1000>;
+          phys = <&serdes 0>;
+          phy-handle = <&phy64>;
+          phy-mode = "sgmii";
+        };
+      };
+    };
+
+...
Signature · 7 lines
2.29.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#3 lore raw

Re: [RFC PATCH v2 1/8] dt-bindings: net: sparx5: Add sparx5-switch bindings

In reply to Steen Hegelund
Quoted 5 lines · Steen Hegelund

Document the Sparx5 switch device driver bindings

---

[snip]

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 83

Quoted 12 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +12 -0
+          max-speed:
+            maxItems: 1
+            description: Bandwidth allocated to this port
+
+          phys:
+            description: phandle of a Ethernet Serdes PHY
+
+          phy-handle:
+            description: phandle of a Ethernet PHY
+
+          phy-mode:
+            description: Interface between the serdes and the phy

Can you specify this pertains to the Serdes and Ethernet PHY?

Signature · 6 lines
Florian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#4 lore raw

Re: [RFC PATCH v2 1/8] dt-bindings: net: sparx5: Add sparx5-switch bindings

Quoted 12 lines · Florian Fainelli

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 5 lines · Steen Hegelund

Document the Sparx5 switch device driver bindings

---

[snip]

Quoted 14 lines

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 83

Quoted 12 lines

+          max-speed:
+            maxItems: 1
+            description: Bandwidth allocated to this port

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +9 -0
+
+          phys:
+            description: phandle of a Ethernet Serdes PHY
+
+          phy-handle:
+            description: phandle of a Ethernet PHY
+
+          phy-mode:
+            description: Interface between the serdes and the phy

Can you specify this pertains to the Serdes and Ethernet PHY?

Hi Florian,

Yes: I will clarify that phy-mode is for the optional Ethernet cuPHY.

Thanks for your comments
Steen

Quoted 2 lines

--
Florian

maintainer
#5 lore raw

Re: [RFC PATCH v2 1/8] dt-bindings: net: sparx5: Add sparx5-switch bindings

In reply to Steen Hegelund
Quoted 48 lines · Steen Hegelund

Document the Sparx5 switch device driver bindings

---
 .../bindings/net/microchip,sparx5-switch.yaml | 178 ++++++++++++++++++
 1 file changed, 178 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +33 -0
new file mode 100644
index 000000000000..6e3ef8285e9a
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/microchip,sparx5-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Microchip Sparx5 Ethernet switch controller
+
+maintainers:
+  - Lars Povlsen <[email protected]>
+  - Steen Hegelund <[email protected]>
+
+description: |
+  The SparX-5 Enterprise Ethernet switch family provides a rich set of
+  Enterprise switching features such as advanced TCAM-based VLAN and
+  QoS processing enabling delivery of differentiated services, and
+  security through TCAM-based frame processing using versatile content
+  aware processor (VCAP).
+
+  IPv4/IPv6 Layer 3 (L3) unicast and multicast routing is supported
+  with up to 18K IPv4/9K IPv6 unicast LPM entries and up to 9K IPv4/3K
+  IPv6 (S,G) multicast groups.
+
+  L3 security features include source guard and reverse path
+  forwarding (uRPF) tasks. Additional L3 features include VRF-Lite and
+  IP tunnels (IP over GRE/IP).
+
+  The SparX-5 switch family targets managed Layer 2 and Layer 3
+  equipment in SMB, SME, and Enterprise where high port count
+  1G/2.5G/5G/10G switching with 10G/25G aggregation links is required.
+
+properties:
+  $nodename:

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 43

Quoted 10 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +10 -0
+    pattern: "^switch@[0-9a-f]+$"
+
+  compatible:
+    const: microchip,sparx5-switch
+
+  reg:
+    minItems: 2
+
+  reg-names:
+    minItems: 2

This is the default based on 'items' length.

Quoted 20 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +20 -0
+    items:
+      - const: devices
+      - const: gcb
+
+  interrupts:
+    maxItems: 1
+    description: Interrupt used for reception of packets to the CPU
+
+  ethernet-ports:
+    type: object
+    properties:
+      '#address-cells':
+        const: 1
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Switch ports

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 73

Quoted 10 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +10 -0
+
+        allOf:
+          - $ref: ethernet-controller.yaml#
+
+        properties:
+          reg:
+            description: Switch port number
+
+          max-speed:
+            maxItems: 1

Is that an array?

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 76

Quoted 3 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +3 -0
+            description: Bandwidth allocated to this port
+
+          phys:

How many? (maxItems)

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 83

Quoted 7 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +7 -0
+            description: phandle of a Ethernet Serdes PHY
+
+          phy-handle:
+            description: phandle of a Ethernet PHY
+
+          phy-mode:
+            description: Interface between the serdes and the phy

The whole set of modes defined is supported?

Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml line 89

Quoted 6 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +6 -0
+
+          sfp:
+            description: phandle of an SFP
+
+          managed:
+            maxItems: 1

An array?

Quoted 92 lines
Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml new file +89 -0
+            description: SFP management
+
+        required:
+          - reg
+          - max-speed
+          - phys
+
+        oneOf:
+          - required:
+              - phy-handle
+              - phy-mode
+          - required:
+              - sfp
+              - managed
+
+        additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - ethernet-ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    switch: switch@600000000 {
+      compatible = "microchip,sparx5-switch";
+      reg =  <0x10000000 0x800000>,
+             <0x11010000 0x1b00000>;
+      reg-names = "devices", "gcb";
+
+      interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
+      ethernet-ports {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        port0: port@0 {
+          reg = <0>;
+          max-speed = <1000>;
+          phys = <&serdes 13>;
+          phy-handle = <&phy0>;
+          phy-mode = "qsgmii";
+        };
+        /* ... */
+        /* Then the 25G interfaces */
+        port60: port@60 {
+          reg = <60>;
+          max-speed = <25000>;
+          phys = <&serdes 29>;
+          sfp = <&sfp_eth60>;
+          managed = "in-band-status";
+        };
+        port61: port@61 {
+          reg = <61>;
+          max-speed = <25000>;
+          phys = <&serdes 30>;
+          sfp = <&sfp_eth61>;
+          managed = "in-band-status";
+        };
+        port62: port@62 {
+          reg = <62>;
+          max-speed = <25000>;
+          phys = <&serdes 31>;
+          sfp = <&sfp_eth62>;
+          managed = "in-band-status";
+        };
+        port63: port@63 {
+          reg = <63>;
+          max-speed = <25000>;
+          phys = <&serdes 32>;
+          sfp = <&sfp_eth63>;
+          managed = "in-band-status";
+        };
+        /* Finally the Management interface */
+        port64: port@64 {
+          reg = <64>;
+          max-speed = <1000>;
+          phys = <&serdes 0>;
+          phy-handle = <&phy64>;
+          phy-mode = "sgmii";
+        };
+      };
+    };
+
+...
Signature · 1 line
2.29.2
author maintainer
#6 lore raw

Re: [RFC PATCH v2 1/8] dt-bindings: net: sparx5: Add sparx5-switch bindings

Hi Rob,

Quoted 71 lines · Rob Herring

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 67 lines · Steen Hegelund

Document the Sparx5 switch device driver bindings

---
 .../bindings/net/microchip,sparx5-switch.yaml | 178
++++++++++++++++++

 1 file changed, 178 insertions(+)

 create mode 100644 Documentation/devicetree/bindings/net/microchip,sparx5-switch.yaml

diff --git a/Documentation/devicetree/bindings/net/microchip,sparx5- switch.yaml b/Documentation/devicetree/bindings/net/microchip,sparx5- switch.yaml
new file mode 100644
index 000000000000..6e3ef8285e9a

Documentation/devicetree/bindings/net/microchip,sparx5- new file +0 -0

switch.yaml

Documentation/devicetree/bindings/net/microchip,sparx5- new file +4 -0
@@ -0,0 +1,178 @@
+# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause
+%YAML 1.2
+---
+$id: 

http://devicetree.org/schemas/net/microchip,sparx5-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#

Documentation/devicetree/bindings/net/microchip,sparx5- new file +9 -0
+
+title: Microchip Sparx5 Ethernet switch controller
+
+maintainers:
+  - Lars Povlsen <[email protected]>
+  - Steen Hegelund <[email protected]>
+
+description: |
+  The SparX-5 Enterprise Ethernet switch family provides a rich

set of
+  Enterprise switching features such as advanced TCAM-based VLAN and
+  QoS processing enabling delivery of differentiated services, and +  security through TCAM-based frame processing using versatile content
+  aware processor (VCAP).
+
+  IPv4/IPv6 Layer 3 (L3) unicast and multicast routing is supported
+  with up to 18K IPv4/9K IPv6 unicast LPM entries and up to 9K IPv4/3K
+  IPv6 (S,G) multicast groups.
+
+  L3 security features include source guard and reverse path +  forwarding (uRPF) tasks. Additional L3 features include VRF-Lite and
+  IP tunnels (IP over GRE/IP).
+
+  The SparX-5 switch family targets managed Layer 2 and Layer 3 +  equipment in SMB, SME, and Enterprise where high port count +  1G/2.5G/5G/10G switching with 10G/25G aggregation links is required.

Documentation/devicetree/bindings/net/microchip,sparx5- new file +7 -0
+
+properties:
+  $nodename:
+    pattern: "^switch@[0-9a-f]+$"
+
+  compatible:
+    const: microchip,sparx5-switch
Quoted 8 lines

Documentation/devicetree/bindings/net/microchip,sparx5-

Quoted 6 lines
Documentation/devicetree/bindings/net/microchip,sparx5- new file +6 -0
+
+  reg:
+    minItems: 2
+
+  reg-names:
+    minItems: 2

This is the default based on 'items' length.

Does that mean that I should omit minItems here?

Quoted 26 lines
Quoted 26 lines

+    items:
+      - const: devices
+      - const: gcb
+
+  interrupts:
+    maxItems: 1
+    description: Interrupt used for reception of packets to the CPU

Documentation/devicetree/bindings/net/microchip,sparx5- new file +17 -0
+
+  ethernet-ports:
+    type: object
+    properties:
+      '#address-cells':
+        const: 1
+      '#size-cells':
+        const: 0
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Switch ports
+
+        allOf:
+          - $ref: ethernet-controller.yaml#
+
Quoted 8 lines
Quoted 6 lines

+        properties:
+          reg:
+            description: Switch port number
+
+          max-speed:
+            maxItems: 1

Is that an array?

No it is just a single value.

Quoted 6 lines
Quoted 4 lines

+            description: Bandwidth allocated to this port +
+          phys:

How many? (maxItems)

I will add "maxItems: 1"

Quoted 10 lines

Documentation/devicetree/bindings/net/microchip,sparx5-

Quoted 8 lines

+            description: phandle of a Ethernet Serdes PHY

Documentation/devicetree/bindings/net/microchip,sparx5- new file +6 -0
+
+          phy-handle:
+            description: phandle of a Ethernet PHY
+
+          phy-mode:
+            description: Interface between the serdes and the phy

The whole set of modes defined is supported?

This driver does not impose any limits on phy-mode. It is passed on to the phy, so all modes are supported as I see it.

Quoted 9 lines

Documentation/devicetree/bindings/net/microchip,sparx5-

Quoted 7 lines
Documentation/devicetree/bindings/net/microchip,sparx5- new file +6 -0
+
+          sfp:
+            description: phandle of an SFP
+
+          managed:
+            maxItems: 1

An array?

No just a single item.

Thanks for your comments.

BR
Steen

Quoted 93 lines
Quoted 93 lines

+            description: SFP management

Documentation/devicetree/bindings/net/microchip,sparx5- new file +88 -1
+
+        required:
+          - reg
+          - max-speed
+          - phys
+
+        oneOf:
+          - required:
+              - phy-handle
+              - phy-mode
+          - required:
+              - sfp
+              - managed
+
+        additionalProperties: false
+
+required:
+  - compatible
+  - reg
+  - reg-names
+  - interrupts
+  - ethernet-ports
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+    switch: switch@600000000 {
+      compatible = "microchip,sparx5-switch";
+      reg =  <0x10000000 0x800000>,
+             <0x11010000 0x1b00000>;
+      reg-names = "devices", "gcb";
+
+      interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
+      ethernet-ports {
+        #address-cells = <1>;
+        #size-cells = <0>;
+
+        port0: port@0 {
+          reg = <0>;
+          max-speed = <1000>;
+          phys = <&serdes 13>;
+          phy-handle = <&phy0>;
+          phy-mode = "qsgmii";
+        };
+        /* ... */
+        /* Then the 25G interfaces */
+        port60: port@60 {
+          reg = <60>;
+          max-speed = <25000>;
+          phys = <&serdes 29>;
+          sfp = <&sfp_eth60>;
+          managed = "in-band-status";
+        };
+        port61: port@61 {
+          reg = <61>;
+          max-speed = <25000>;
+          phys = <&serdes 30>;
+          sfp = <&sfp_eth61>;
+          managed = "in-band-status";
+        };
+        port62: port@62 {
+          reg = <62>;
+          max-speed = <25000>;
+          phys = <&serdes 31>;
+          sfp = <&sfp_eth62>;
+          managed = "in-band-status";
+        };
+        port63: port@63 {
+          reg = <63>;
+          max-speed = <25000>;
+          phys = <&serdes 32>;
+          sfp = <&sfp_eth63>;
+          managed = "in-band-status";
+        };
+        /* Finally the Management interface */
+        port64: port@64 {
+          reg = <64>;
+          max-speed = <1000>;
+          phys = <&serdes 0>;
+          phy-handle = <&phy64>;
+          phy-mode = "sgmii";
+        };
+      };
+    };
+
+...
--

2.29.2

author maintainer
#7 lore raw

RFC PATCH v2 2/8 net: sparx5: add the basic sparx5 driver

In reply to Steen Hegelund

This adds the SwitchDev driver basic framework with switch device detection and core clock configuration.

---
 drivers/net/ethernet/microchip/Kconfig        |    2 +
 drivers/net/ethernet/microchip/Makefile       |    2 +
 drivers/net/ethernet/microchip/sparx5/Kconfig |    8 +
 .../net/ethernet/microchip/sparx5/Makefile    |    8 +
 .../ethernet/microchip/sparx5/sparx5_main.c   |  733 +++
 .../ethernet/microchip/sparx5/sparx5_main.h   |  282 ++
 .../microchip/sparx5/sparx5_main_regs.h       | 3922 +++++++++++++++++
 7 files changed, 4957 insertions(+)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/Kconfig
 create mode 100644 drivers/net/ethernet/microchip/sparx5/Makefile
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_main.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_main.h
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h
drivers/net/ethernet/microchip/Kconfig +2 -0
index d0f6dfe0dcf3..d54aa164c4e9 100644
@@ -54,4 +54,6 @@ config LAN743X
 	  To compile this driver as a module, choose M here. The module will be
 	  called lan743x.
 
+source "drivers/net/ethernet/microchip/sparx5/Kconfig"
+
 endif # NET_VENDOR_MICROCHIP
drivers/net/ethernet/microchip/Makefile +2 -0
index da603540ca57..c77dc0379bfd 100644
@@ -8,3 +8,5 @@ obj-$(CONFIG_ENCX24J600) += encx24j600.o encx24j600-regmap.o
 obj-$(CONFIG_LAN743X) += lan743x.o
 
 lan743x-objs := lan743x_main.o lan743x_ethtool.o lan743x_ptp.o
+
+obj-$(CONFIG_SPARX5_SWITCH) += sparx5/
drivers/net/ethernet/microchip/sparx5/Kconfig new file +8 -0
new file mode 100644
index 000000000000..d2cb84372071
@@ -0,0 +1,8 @@
+config SPARX5_SWITCH
+	tristate "Sparx5 switch driver"
+	depends on NET_SWITCHDEV
+	depends on HAS_IOMEM
+	select PHYLINK
+	select PHY_SPARX5_SERDES
+	help
+	  This driver supports the Sparx5 network switch device.
drivers/net/ethernet/microchip/sparx5/Makefile new file +8 -0
new file mode 100644
index 000000000000..41a31843d86f
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Makefile for the Microchip Sparx5 network device drivers.
+#
+
+obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o
+
+sparx5-switch-objs  := sparx5_main.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +733 -0

733 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_main.h new file +282 -0

282 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h new file +3922 -0

1,958 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.29.2

Part of the diff is not shown here. View the raw message.

#8 lore raw

Re: [RFC PATCH v2 2/8] net: sparx5: add the basic sparx5 driver

Quoted 1 line · Steen Hegelund

+static struct sparx5_io_resource sparx5_iomap[] = {

This could be made const i think,.

Review

Quoted 12 lines
(quoted diff) +11 -0
+	{ TARGET_DEV2G5,         0,         0 }, /* 0x610004000: dev2g5_0 */
+	{ TARGET_DEV5G,          0x4000,    0 }, /* 0x610008000: dev5g_0 */
+	{ TARGET_PCS5G_BR,       0x8000,    0 }, /* 0x61000c000: pcs5g_br_0 */
+	{ TARGET_DEV2G5 + 1,     0xc000,    0 }, /* 0x610010000: dev2g5_1 */
 
+static int sparx5_create_targets(struct sparx5 *sparx5)
+{
+	int idx, jdx;
+	struct resource *iores[IO_RANGES];
+	void __iomem *iomem[IO_RANGES];
+	void __iomem *begin[IO_RANGES];
+	int range_id[IO_RANGES];

Reverse Christmas tree. idx, jdx need to come last.

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 207

Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +4 -0
+
+	/* Check if done previously (deferred by serdes load) */
+	if (sparx5->regs[sparx5_iomap[0].id])
+		return 0;

Could you explain this a bit more. Do you mean -EPROBE_DEFER?

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 249

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +13 -0
+static int sparx5_probe_port(struct sparx5 *sparx5,
+			     struct device_node *portnp,
+			     struct phy *serdes,
+			     u32 portno,
+			     struct sparx5_port_config *conf)
+{
+	struct sparx5_port *spx5_port;
+	struct net_device *ndev;
+	int err;
+
+	err = sparx5_create_targets(sparx5);
+	if (err)
+		return err;

This sees odd here. Don't sparx5_create_targets() create all the targets, where as this creates one specific port? Seems like sparx5_create_targets() should be in the devices as a whole probe, not the port probe.

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +6 -0
+	spx5_port = netdev_priv(ndev);
+	spx5_port->of_node = portnp;
+	spx5_port->serdes = serdes;
+	spx5_port->pvid = NULL_VID;
+	spx5_port->signd_internal = true;
+	spx5_port->signd_active_high = true;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 265

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+	spx5_port->signd_enable = true;
+	spx5_port->flow_control = false;
+	spx5_port->max_vlan_tags = SPX5_PORT_MAX_TAGS_NONE;
+	spx5_port->vlan_type = SPX5_VLAN_PORT_TYPE_UNAWARE;
+	spx5_port->custom_etype = 0x8880; /* Vitesse */
+	conf->portmode = conf->phy_mode;
+	spx5_port->conf.speed = SPEED_UNKNOWN;
+	spx5_port->conf.power_down = true;
+	sparx5->ports[portno] = spx5_port;
+	return 0;

I'm also not sure this has the correct name. This does not look like a typical probe function.

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +13 -0
+}
+
+static int sparx5_init_switchcore(struct sparx5 *sparx5)
+{
+	u32 value, pending, jdx, idx;
+	struct {
+		bool gazwrap;
+		void __iomem *init_reg;
+		u32  init_val;
+	} ram, ram_init_list[] = {
+		{false, spx5_reg_get(sparx5, ANA_AC_STAT_RESET),
+		 ANA_AC_STAT_RESET_RESET},
+		{false, spx5_reg_get(sparx5, ASM_STAT_CFG),

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 288

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+		 ASM_STAT_CFG_STAT_CNT_CLR_SHOT},
+		{true,  spx5_reg_get(sparx5, QSYS_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, REW_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, VOP_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, ANA_AC_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, ASM_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, EACL_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, VCAP_SUPER_RAM_INIT), 0},
+		{true,  spx5_reg_get(sparx5, DSM_RAM_INIT), 0}
+	};

Looks like this could be const as well. And this does not really fit reverse christmas tree.

Quoted 26 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +26 -0
+
+	spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(1),
+		 EACL_POL_EACL_CFG_EACL_FORCE_INIT,
+		 sparx5,
+		 EACL_POL_EACL_CFG);
+
+	spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(0),
+		 EACL_POL_EACL_CFG_EACL_FORCE_INIT,
+		 sparx5,
+		 EACL_POL_EACL_CFG);
+
+	/* Initialize memories, if not done already */
+	value = spx5_rd(sparx5, HSCH_RESET_CFG);
+
+	if (!(value & HSCH_RESET_CFG_CORE_ENA)) {
+		for (idx = 0; idx < 10; idx++) {
+			pending = ARRAY_SIZE(ram_init_list);
+			for (jdx = 0; jdx < ARRAY_SIZE(ram_init_list); jdx++) {
+				ram = ram_init_list[jdx];
+				if (ram.gazwrap)
+					ram.init_val = QSYS_RAM_INIT_RAM_INIT;
+
+				if (idx == 0) {
+					writel(ram.init_val, ram.init_reg);
+				} else {
+					value = readl(ram.init_reg);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 324

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+					if ((value & ram.init_val) !=
+					    ram.init_val) {
+						pending--;
+					}
+				}
+			}
+			if (!pending)
+				break;
+			usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
+		}

You are getting pretty deeply nested here. Might be better to pull this out into a helpers.

Quoted 14 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +14 -0
+
+		if (pending > 0) {
+			/* Still initializing, should be complete in
+			 * less than 1ms
+			 */
+			dev_err(sparx5->dev, "Memory initialization error\n");
+			return -EINVAL;
+		}
+	}
+
+	/* Reset counters */
+	spx5_wr(ANA_AC_STAT_RESET_RESET_SET(1), sparx5, ANA_AC_STAT_RESET);
+	spx5_wr(ASM_STAT_CFG_STAT_CNT_CLR_SHOT_SET(1), sparx5, ASM_STAT_CFG);
+

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 348

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+	/* Enable switch-core and queue system */
+	spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5, HSCH_RESET_CFG);
+
+	return 0;
+}
+
+static int sparx5_init_coreclock(struct sparx5 *sparx5)
+{
+	u32 clk_div, clk_period, pol_upd_int, idx;
+	enum sparx5_core_clockfreq freq = sparx5->coreclock;

More reverse christmas tree. Please review the whole driver.

Quoted 31 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +31 -0
+
+	/* Verify if core clock frequency is supported on target.
+	 * If 'VTSS_CORE_CLOCK_DEFAULT' then the highest supported
+	 * freq. is used
+	 */
+	switch (sparx5->target_ct) {
+	case SPX5_TARGET_CT_7546:
+		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
+			freq = SPX5_CORE_CLOCK_250MHZ;
+		else if (sparx5->coreclock != SPX5_CORE_CLOCK_250MHZ)
+			freq = 0; /* Not supported */
+		break;
+	case SPX5_TARGET_CT_7549:
+	case SPX5_TARGET_CT_7552:
+	case SPX5_TARGET_CT_7556:
+		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
+			freq = SPX5_CORE_CLOCK_500MHZ;
+		else if (sparx5->coreclock != SPX5_CORE_CLOCK_500MHZ)
+			freq = 0; /* Not supported */
+		break;
+	case SPX5_TARGET_CT_7558:
+	case SPX5_TARGET_CT_7558TSN:
+		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
+			freq = SPX5_CORE_CLOCK_625MHZ;
+		else if (sparx5->coreclock != SPX5_CORE_CLOCK_625MHZ)
+			freq = 0; /* Not supported */
+		break;
+	case SPX5_TARGET_CT_7546TSN:
+		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
+			freq = SPX5_CORE_CLOCK_625MHZ;
+		break;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 389

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+	case SPX5_TARGET_CT_7549TSN:
+	case SPX5_TARGET_CT_7552TSN:
+	case SPX5_TARGET_CT_7556TSN:
+		if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT)
+			freq = SPX5_CORE_CLOCK_625MHZ;
+		else if (sparx5->coreclock == SPX5_CORE_CLOCK_250MHZ)
+			freq = 0; /* Not supported */
+		break;
+	default:
+		dev_err(sparx5->dev, "Target (%#04x) not supported\n", sparx5->target_ct);

netdev is staying with 80 character lines. Please fold this, here and every where else, where possible. The exception is, you should not split a string.

Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +11 -0
+		return -ENODEV;
+	}
+
+	switch (freq) {
+	case SPX5_CORE_CLOCK_250MHZ:
+		clk_div = 10;
+		pol_upd_int = 312;
+		break;
+	case SPX5_CORE_CLOCK_500MHZ:
+		clk_div = 5;
+		pol_upd_int = 624;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 410

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+		break;
+	case SPX5_CORE_CLOCK_625MHZ:
+		clk_div = 4;
+		pol_upd_int = 780;
+		break;
+	default:
+		dev_err(sparx5->dev, "%s: Frequency (%d) not supported on target (%#04x)\n",
+			__func__,
+			sparx5->coreclock, sparx5->target_ct);
+		return 0;

-EINVAL? Or is it not fatal to use an unsupported frequency?

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 501

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +6 -0
+static int sparx5_init(struct sparx5 *sparx5)
+{
+	u32 idx;
+
+	if (sparx5_create_targets(sparx5))
+		return -ENODEV;

Hum, sparx5_create_targets() again?

Quoted 24 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +24 -0
+
+	/* Read chip ID to check CPU interface */
+	sparx5->chip_id = spx5_rd(sparx5, GCB_CHIP_ID);
+
+	sparx5->target_ct = (enum spx5_target_chiptype)
+		GCB_CHIP_ID_PART_ID_GET(sparx5->chip_id);
+
+	/* Initialize Switchcore and internal RAMs */
+	if (sparx5_init_switchcore(sparx5)) {
+		dev_err(sparx5->dev, "Switchcore initialization error\n");
+		return -EINVAL;
+	}
+
+	/* Initialize the LC-PLL (core clock) and set affected registers */
+	if (sparx5_init_coreclock(sparx5)) {
+		dev_err(sparx5->dev, "LC-PLL initialization error\n");
+		return -EINVAL;
+	}
+
+	/* Setup own UPSIDs */
+	for (idx = 0; idx < 3; idx++) {
+		spx5_wr(idx, sparx5, ANA_AC_OWN_UPSID(idx));
+		spx5_wr(idx, sparx5, ANA_CL_OWN_UPSID(idx));
+		spx5_wr(idx, sparx5, ANA_L2_OWN_UPSID(idx));

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 535

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+		spx5_wr(idx, sparx5, REW_OWN_UPSID(idx));
+	}
+
+	/* Enable switch ports */
+	for (idx = SPX5_PORTS; idx < SPX5_PORTS_ALL; idx++) {
+		spx5_rmw(QFWD_SWITCH_PORT_MODE_PORT_ENA_SET(1),
+			 QFWD_SWITCH_PORT_MODE_PORT_ENA,
+			 sparx5,
+			 QFWD_SWITCH_PORT_MODE(idx));
+	}

What happens when you enable the ports? Why is this here, and not in the port specific open call?

Quoted 17 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +17 -0
+/* Some boards needs to map the SGPIO for signal detect explicitly to the
+ * port module
+ */
+static void sparx5_board_init(struct sparx5 *sparx5)
+{
+	int idx;
+
+	if (!sparx5->sd_sgpio_remapping)
+		return;
+
+	/* Enable SGPIO Signal Detect remapping */
+	spx5_rmw(GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+		 GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+		 sparx5,
+		 GCB_HW_SGPIO_SD_CFG);
+
+	/* Refer to LOS SGPIO */

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 581

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+	for (idx = 0; idx < SPX5_PORTS; idx++) {
+		if (sparx5->ports[idx]) {
+			if (sparx5->ports[idx]->conf.sd_sgpio != ~0) {
+				spx5_wr(sparx5->ports[idx]->conf.sd_sgpio,
+					sparx5,
+					GCB_HW_SGPIO_TO_SD_MAP_CFG(idx));
+			}
+		}
+	}
+}

I've not looked at how you do SFP integration yet. Is this the LOS from the SFP socket? Is there a Linux GPIO controller exported by this driver, so the SFP driver can use the GPIOs?

Quoted 21 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +21 -0
+
+static int mchp_sparx5_probe(struct platform_device *pdev)
+{
+	struct device_node *np = pdev->dev.of_node;
+	struct sparx5 *sparx5;
+	struct device_node *ports, *portnp;
+	const u8 *mac_addr;
+	int err = 0;
+
+	if (!np && !pdev->dev.platform_data)
+		return -ENODEV;
+
+	sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5), GFP_KERNEL);
+	if (!sparx5)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, sparx5);
+	sparx5->pdev = pdev;
+	sparx5->dev = &pdev->dev;
+
+	/* Default values, some from DT */

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 612

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+	sparx5->coreclock = SPX5_CORE_CLOCK_DEFAULT;
+
+	mac_addr = of_get_mac_address(np);
+	if (IS_ERR_OR_NULL(mac_addr)) {
+		dev_info(sparx5->dev, "MAC addr was not set, use random MAC\n");
+		eth_random_addr(sparx5->base_mac);
+		sparx5->base_mac[5] = 0;
+	} else {
+		ether_addr_copy(sparx5->base_mac, mac_addr);
+	}

The binding document does not say anything about a MAC address at the top level. What is this used for?

+

Quoted 19 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +19 -0
+	if (sparx5_init(sparx5)) {
+		dev_err(sparx5->dev, "Init failed\n");
+		return -ENODEV;
+	}
+	ports = of_get_child_by_name(np, "ethernet-ports");
+	if (!ports) {
+		dev_err(sparx5->dev, "no ethernet-ports child node found\n");
+		return -ENODEV;
+	}
+	sparx5->port_count = of_get_child_count(ports);
+
+	for_each_available_child_of_node(ports, portnp) {
+		struct sparx5_port_config config = {};
+		u32 portno;
+		struct phy *serdes;
+
+		err = of_property_read_u32(portnp, "reg", &portno);
+		if (err) {
+			dev_err(sparx5->dev, "port reg property error\n");

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 642

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+			continue;
+		}
+		err = of_property_read_u32(portnp, "max-speed",
+					   &config.max_speed);
+		if (err) {
+			dev_err(sparx5->dev, "port max-speed property error\n");
+			continue;
+		}
+		config.speed = SPEED_UNKNOWN;
+		err = of_property_read_u32(portnp, "sd_sgpio", &config.sd_sgpio);

Not in the binding documentation. I think i need to withdraw my Reviewed-by :-(

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +7 -0
+		if (err)
+			config.sd_sgpio = ~0;
+		else
+			sparx5->sd_sgpio_remapping = true;
+		serdes = devm_of_phy_get(sparx5->dev, portnp, NULL);
+		if (IS_ERR(serdes)) {
+			err = PTR_ERR(serdes);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 659

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+			if (err != -EPROBE_DEFER)
+				dev_err(sparx5->dev,
+					"missing SerDes phys for port%d\n",
+					portno);
+			return err;
+		}
+
+		err = of_get_phy_mode(portnp, &config.phy_mode);
+		if (err)
+			config.power_down = true;

You should indicate in the binding it is optional. And what happens when it is missing.

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 672

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +13 -0
+		config.media_type = ETH_MEDIA_DAC;
+		config.serdes_reset = true;
+		config.portmode = config.phy_mode;
+		err = sparx5_probe_port(sparx5, portnp, serdes, portno, &config);
+		if (err) {
+			dev_err(sparx5->dev, "port probe error\n");
+			goto cleanup_ports;
+		}
+	}
+	sparx5_board_init(sparx5);
+
+cleanup_ports:
+	return err;

Seems missed named, no cleanup.

Quoted 21 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +21 -0
+static int __init sparx5_switch_reset(void)
+{
+	const char *syscon_cpu = "microchip,sparx5-cpu-syscon",
+		*syscon_gcb = "microchip,sparx5-gcb-syscon";
+	struct regmap *cpu_ctrl, *gcb_ctrl;
+	u32 val;
+
+	cpu_ctrl = syscon_regmap_lookup_by_compatible(syscon_cpu);
+	if (IS_ERR(cpu_ctrl)) {
+		pr_err("No '%s' syscon map\n", syscon_cpu);
+		return PTR_ERR(cpu_ctrl);
+	}
+
+	gcb_ctrl = syscon_regmap_lookup_by_compatible(syscon_gcb);
+	if (IS_ERR(gcb_ctrl)) {
+		pr_err("No '%s' syscon map\n", syscon_gcb);
+		return PTR_ERR(gcb_ctrl);
+	}
+
+	/* Make sure the core is PROTECTED from reset */
+	regmap_update_bits(cpu_ctrl, RESET_PROT_STAT,

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 729

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+			   SYS_RST_PROT_VCORE, SYS_RST_PROT_VCORE);
+
+	regmap_write(gcb_ctrl, spx5_offset(GCB_SOFT_RST),
+		     GCB_SOFT_RST_SOFT_SWC_RST_SET(1));
+
+	return readx_poll_timeout(sparx5_read_gcb_soft_rst, gcb_ctrl, val,
+				  GCB_SOFT_RST_SOFT_SWC_RST_GET(val) == 0,
+				  1, 100);
+}
+postcore_initcall(sparx5_switch_reset);

That is pretty unusual. Why cannot this be done at probe time?

drivers/net/ethernet/microchip/sparx5/sparx5_main.h line 147

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h new file +13 -0
+/* Clock period in picoseconds */
+static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
+{
+	switch (cclock) {
+	case SPX5_CORE_CLOCK_250MHZ:
+		return 4000;
+	case SPX5_CORE_CLOCK_500MHZ:
+		return 2000;
+	case SPX5_CORE_CLOCK_625MHZ:
+	default:
+		return 1600;
+	}
+}

Is this something which is used in the hot path?

drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h line 9

Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h new file +9 -0
@@ -0,0 +1,3922 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ * Microchip Sparx5 Switch driver
+ *
+ * Copyright (c) 2020 Microchip Technology Inc.
+ */
+
+/* This file is autogenerated by cml-utils 2020-11-19 10:41:34 +0100.
+ * Commit ID: f34790e69dc252103e2cc3e85b1a5e4d9e3aa190
+ */

How reproducible this is generation process? If you have to run it again, will it keep the same order of lines?

Andrew

author maintainer
#9 lore raw

Re: [RFC PATCH v2 2/8] net: sparx5: add the basic sparx5 driver

Hi Andrew,

Quoted 8 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 1 line · Steen Hegelund

+static struct sparx5_io_resource sparx5_iomap[] =  {

This could be made const i think,.

Yes

Quoted 10 lines
Quoted 9 lines

+     { TARGET_DEV2G5,         0,         0 }, /* 0x610004000:
dev2g5_0 */
+     { TARGET_DEV5G,          0x4000,    0 }, /* 0x610008000:
dev5g_0 */
+     { TARGET_PCS5G_BR,       0x8000,    0 }, /* 0x61000c000:
pcs5g_br_0 */
+     { TARGET_DEV2G5 + 1,     0xc000,    0 }, /* 0x610010000:
dev2g5_1 */

Quoted 9 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 203

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +7 -0
+static int sparx5_create_targets(struct sparx5 *sparx5)
+{
+     int idx, jdx;
+     struct resource *iores[IO_RANGES];
+     void __iomem *iomem[IO_RANGES];
+     void __iomem *begin[IO_RANGES];
+     int range_id[IO_RANGES];

Reverse Christmas tree. idx, jdx need to come last.

Yes - I will check the entire file for RCT...

Quoted 7 lines
Quoted 5 lines

+
+     /* Check if done previously (deferred by serdes load) */ +     if (sparx5->regs[sparx5_iomap[0].id])
+             return 0;

Could you explain this a bit more. Do you mean -EPROBE_DEFER?

Yes that was the intended usage. I will change the startup flow to try to avoid checking this-

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +11 -0
+static int sparx5_probe_port(struct sparx5 *sparx5,
+                          struct device_node *portnp,
+                          struct phy *serdes,
+                          u32 portno,
+                          struct sparx5_port_config *conf)
+{
+     struct sparx5_port *spx5_port;
+     struct net_device *ndev;
+     int err;
+
+     err = sparx5_create_targets(sparx5);
Quoted 8 lines
Quoted 2 lines

+     if (err)
+             return err;

This sees odd here. Don't sparx5_create_targets() create all the targets, where as this creates one specific port? Seems like sparx5_create_targets() should be in the devices as a whole probe, not
the port probe.

You are right - the name does not really fit (anymore). I will rework this.

Quoted 18 lines
Quoted 17 lines

+     spx5_port = netdev_priv(ndev);
+     spx5_port->of_node = portnp;
+     spx5_port->serdes = serdes;
+     spx5_port->pvid = NULL_VID;
+     spx5_port->signd_internal = true;
+     spx5_port->signd_active_high = true;
+     spx5_port->signd_enable = true;
+     spx5_port->flow_control = false;
+     spx5_port->max_vlan_tags = SPX5_PORT_MAX_TAGS_NONE; +     spx5_port->vlan_type = SPX5_VLAN_PORT_TYPE_UNAWARE; +     spx5_port->custom_etype = 0x8880; /* Vitesse */ +     conf->portmode = conf->phy_mode;
+     spx5_port->conf.speed = SPEED_UNKNOWN;
+     spx5_port->conf.power_down = true;
+     sparx5->ports[portno] = spx5_port;
+     return 0;

Quoted 3 lines

I'm also not sure this has the correct name. This does not look like a
typical probe function.

Agree.

Quoted 21 lines
Quoted 21 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +19 -0
+}
+
+static int sparx5_init_switchcore(struct sparx5 *sparx5)
+{
+     u32 value, pending, jdx, idx;
+     struct {
+             bool gazwrap;
+             void __iomem *init_reg;
+             u32  init_val;
+     } ram, ram_init_list[] = {
+             {false, spx5_reg_get(sparx5, ANA_AC_STAT_RESET),
+              ANA_AC_STAT_RESET_RESET},
+             {false, spx5_reg_get(sparx5, ASM_STAT_CFG),
+              ASM_STAT_CFG_STAT_CNT_CLR_SHOT},
+             {true,  spx5_reg_get(sparx5, QSYS_RAM_INIT), 0},
+             {true,  spx5_reg_get(sparx5, REW_RAM_INIT), 0},
+             {true,  spx5_reg_get(sparx5, VOP_RAM_INIT), 0},
+             {true,  spx5_reg_get(sparx5, ANA_AC_RAM_INIT), 0},
+             {true,  spx5_reg_get(sparx5, ASM_RAM_INIT), 0},
Quoted 8 lines
Quoted 5 lines

+             {true,  spx5_reg_get(sparx5, EACL_RAM_INIT), 0}, +             {true,  spx5_reg_get(sparx5, VCAP_SUPER_RAM_INIT), 0},
+             {true,  spx5_reg_get(sparx5, DSM_RAM_INIT), 0} +     };

Looks like this could be const as well. And this does not really fit reverse christmas tree.

I will update this.

Quoted 36 lines
Quoted 36 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +18 -0
+
+     spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(1),
+              EACL_POL_EACL_CFG_EACL_FORCE_INIT,
+              sparx5,
+              EACL_POL_EACL_CFG);
+
+     spx5_rmw(EACL_POL_EACL_CFG_EACL_FORCE_INIT_SET(0),
+              EACL_POL_EACL_CFG_EACL_FORCE_INIT,
+              sparx5,
+              EACL_POL_EACL_CFG);
+
+     /* Initialize memories, if not done already */
+     value = spx5_rd(sparx5, HSCH_RESET_CFG);
+
+     if (!(value & HSCH_RESET_CFG_CORE_ENA)) {
+             for (idx = 0; idx < 10; idx++) {
+                     pending = ARRAY_SIZE(ram_init_list);
+                     for (jdx = 0; jdx <

ARRAY_SIZE(ram_init_list); jdx++) {
+                             ram = ram_init_list[jdx]; +                             if (ram.gazwrap)
+                                     ram.init_val = QSYS_RAM_INIT_RAM_INIT;
+
+                             if (idx == 0) {
+                                     writel(ram.init_val, ram.init_reg);
+                             } else {
+                                     value = readl(ram.init_reg); +                                     if ((value & ram.init_val) != +                                         ram.init_val) { +                                             pending--; +                                     }
+                             }
+                     }

Quoted 8 lines
Quoted 5 lines

+                     if (!pending)
+                             break;
+                     usleep_range(USEC_PER_MSEC, 2 * USEC_PER_MSEC);
+             }

You are getting pretty deeply nested here. Might be better to pull this out into a helpers.

Yes.

Quoted 23 lines
Quoted 23 lines

+
+             if (pending > 0) {
+                     /* Still initializing, should be complete in +                      * less than 1ms
+                      */
+                     dev_err(sparx5->dev, "Memory initialization error\n");
+                     return -EINVAL;
+             }
+     }
+
+     /* Reset counters */
+     spx5_wr(ANA_AC_STAT_RESET_RESET_SET(1), sparx5, ANA_AC_STAT_RESET);
+     spx5_wr(ASM_STAT_CFG_STAT_CNT_CLR_SHOT_SET(1), sparx5, ASM_STAT_CFG);
+
+     /* Enable switch-core and queue system */
+     spx5_wr(HSCH_RESET_CFG_CORE_ENA_SET(1), sparx5, HSCH_RESET_CFG);
+
+     return 0;

Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 348

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +6 -0
+}
+
+static int sparx5_init_coreclock(struct sparx5 *sparx5)
+{
+     u32 clk_div, clk_period, pol_upd_int, idx;
+     enum sparx5_core_clockfreq freq = sparx5->coreclock;

More reverse christmas tree. Please review the whole driver.

I will do that.

Quoted 44 lines
Quoted 35 lines

+
+     /* Verify if core clock frequency is supported on target. +      * If 'VTSS_CORE_CLOCK_DEFAULT' then the highest supported +      * freq. is used
+      */
+     switch (sparx5->target_ct) {
+     case SPX5_TARGET_CT_7546:
+             if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) +                     freq = SPX5_CORE_CLOCK_250MHZ;
+             else if (sparx5->coreclock != SPX5_CORE_CLOCK_250MHZ) +                     freq = 0; /* Not supported */
+             break;
+     case SPX5_TARGET_CT_7549:
+     case SPX5_TARGET_CT_7552:
+     case SPX5_TARGET_CT_7556:
+             if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) +                     freq = SPX5_CORE_CLOCK_500MHZ;
+             else if (sparx5->coreclock != SPX5_CORE_CLOCK_500MHZ) +                     freq = 0; /* Not supported */
+             break;
+     case SPX5_TARGET_CT_7558:
+     case SPX5_TARGET_CT_7558TSN:
+             if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) +                     freq = SPX5_CORE_CLOCK_625MHZ;
+             else if (sparx5->coreclock != SPX5_CORE_CLOCK_625MHZ) +                     freq = 0; /* Not supported */
+             break;
+     case SPX5_TARGET_CT_7546TSN:
+             if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) +                     freq = SPX5_CORE_CLOCK_625MHZ;
+             break;
+     case SPX5_TARGET_CT_7549TSN:
+     case SPX5_TARGET_CT_7552TSN:
+     case SPX5_TARGET_CT_7556TSN:

Quoted 8 lines

+             if (sparx5->coreclock == SPX5_CORE_CLOCK_DEFAULT) +                     freq = SPX5_CORE_CLOCK_625MHZ;
+             else if (sparx5->coreclock == SPX5_CORE_CLOCK_250MHZ) +                     freq = 0; /* Not supported */
+             break;
+     default:
+             dev_err(sparx5->dev, "Target (%#04x) not supported\n", sparx5->target_ct);

Quoted 3 lines

netdev is staying with 80 character lines. Please fold this, here and every where else, where possible. The exception is, you should not split a string.

Will do.

Quoted 24 lines
Quoted 15 lines

+             return -ENODEV;
+     }
+
+     switch (freq) {
+     case SPX5_CORE_CLOCK_250MHZ:
+             clk_div = 10;
+             pol_upd_int = 312;
+             break;
+     case SPX5_CORE_CLOCK_500MHZ:
+             clk_div = 5;
+             pol_upd_int = 624;
+             break;
+     case SPX5_CORE_CLOCK_625MHZ:
+             clk_div = 4;

Quoted 8 lines

+             pol_upd_int = 780;
+             break;
+     default:
+             dev_err(sparx5->dev, "%s: Frequency (%d) not supported on target (%#04x)\n",
+                     __func__,
+                     sparx5->coreclock, sparx5->target_ct); +             return 0;

Quoted 1 line

-EINVAL? Or is it not fatal to use an unsupported frequency?

Yes - it should be fatal.

Quoted 9 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 501

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +6 -0
+static int sparx5_init(struct sparx5 *sparx5)
+{
+     u32 idx;
+
+     if (sparx5_create_targets(sparx5))
+             return -ENODEV;

Hum, sparx5_create_targets() again?

Yes that was due to the PROBE_DEFER - but I will go over this again.

Quoted 33 lines
Quoted 33 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +10 -0
+
+     /* Read chip ID to check CPU interface */
+     sparx5->chip_id = spx5_rd(sparx5, GCB_CHIP_ID);
+
+     sparx5->target_ct = (enum spx5_target_chiptype)
+             GCB_CHIP_ID_PART_ID_GET(sparx5->chip_id);
+
+     /* Initialize Switchcore and internal RAMs */
+     if (sparx5_init_switchcore(sparx5)) {
+             dev_err(sparx5->dev, "Switchcore initialization

error\n");
+             return -EINVAL;
+     }
+
+     /* Initialize the LC-PLL (core clock) and set affected registers */
+     if (sparx5_init_coreclock(sparx5)) {
+             dev_err(sparx5->dev, "LC-PLL initialization error\n");
+             return -EINVAL;
+     }

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +11 -0
+
+     /* Setup own UPSIDs */
+     for (idx = 0; idx < 3; idx++) {
+             spx5_wr(idx, sparx5, ANA_AC_OWN_UPSID(idx));
+             spx5_wr(idx, sparx5, ANA_CL_OWN_UPSID(idx));
+             spx5_wr(idx, sparx5, ANA_L2_OWN_UPSID(idx));
+             spx5_wr(idx, sparx5, REW_OWN_UPSID(idx));
+     }
+
+     /* Enable switch ports */
+     for (idx = SPX5_PORTS; idx < SPX5_PORTS_ALL; idx++) {
Quoted 8 lines
Quoted 5 lines

+             spx5_rmw(QFWD_SWITCH_PORT_MODE_PORT_ENA_SET(1), +                      QFWD_SWITCH_PORT_MODE_PORT_ENA, +                      sparx5,
+                      QFWD_SWITCH_PORT_MODE(idx)); +     }

What happens when you enable the ports? Why is this here, and not in the port specific open call?

The comment is not correct. This is just enabling the CPU ports, so it belongs with the other switch core initialization. I will update the comment.

Quoted 33 lines
Quoted 24 lines

+/* Some boards needs to map the SGPIO for signal detect explicitly to the
+ * port module
+ */

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +17 -0
+static void sparx5_board_init(struct sparx5 *sparx5)
+{
+     int idx;
+
+     if (!sparx5->sd_sgpio_remapping)
+             return;
+
+     /* Enable SGPIO Signal Detect remapping */
+     spx5_rmw(GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+              GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+              sparx5,
+              GCB_HW_SGPIO_SD_CFG);
+
+     /* Refer to LOS SGPIO */
+     for (idx = 0; idx < SPX5_PORTS; idx++) {
+             if (sparx5->ports[idx]) {
+                     if (sparx5->ports[idx]->conf.sd_sgpio != ~0)

{
+                             spx5_wr(sparx5->ports[idx]-

Quoted 8 lines
Quoted 1 line

conf.sd_sgpio,

+                                     sparx5,
+
GCB_HW_SGPIO_TO_SD_MAP_CFG(idx));
+                     }
+             }
+     }
+}

Quoted 4 lines

I've not looked at how you do SFP integration yet. Is this the LOS from the SFP socket? Is there a Linux GPIO controller exported by this
driver, so the SFP driver can use the GPIOs?

Yes the SFP driver (used by the Sparx5 SerDes driver) will use the SGPIO LOS, Module Detect etc, and the Port Modules are aware of the location of the LOS, and use this by default without any driver configuration.
But on the PCB134 the SGPIOs are shifted one bit by a mistake, and they are not located in the expected position, so we have this board remapping function to handle that aspect.

Quoted 29 lines
Quoted 29 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +13 -0
+
+static int mchp_sparx5_probe(struct platform_device *pdev)
+{
+     struct device_node *np = pdev->dev.of_node;
+     struct sparx5 *sparx5;
+     struct device_node *ports, *portnp;
+     const u8 *mac_addr;
+     int err = 0;
+
+     if (!np && !pdev->dev.platform_data)
+             return -ENODEV;
+
+     sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5),

GFP_KERNEL);
+     if (!sparx5)
+             return -ENOMEM;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +11 -0
+
+     platform_set_drvdata(pdev, sparx5);
+     sparx5->pdev = pdev;
+     sparx5->dev = &pdev->dev;
+
+     /* Default values, some from DT */
+     sparx5->coreclock = SPX5_CORE_CLOCK_DEFAULT;
+
+     mac_addr = of_get_mac_address(np);
+     if (IS_ERR_OR_NULL(mac_addr)) {
+             dev_info(sparx5->dev, "MAC addr was not set, use

random MAC\n");

Quoted 8 lines
Quoted 5 lines

+             eth_random_addr(sparx5->base_mac); +             sparx5->base_mac[5] = 0;
+     } else {
+             ether_addr_copy(sparx5->base_mac, mac_addr); +     }

The binding document does not say anything about a MAC address at the top level. What is this used for?

This the base MAC address used for generating the the switch NI's MAC addresses.

Quoted 30 lines

+

Quoted 28 lines

+     if (sparx5_init(sparx5)) {
+             dev_err(sparx5->dev, "Init failed\n");
+             return -ENODEV;
+     }
+     ports = of_get_child_by_name(np, "ethernet-ports"); +     if (!ports) {
+             dev_err(sparx5->dev, "no ethernet-ports child node found\n");
+             return -ENODEV;
+     }
+     sparx5->port_count = of_get_child_count(ports);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +9 -0
+
+     for_each_available_child_of_node(ports, portnp) {
+             struct sparx5_port_config config = {};
+             u32 portno;
+             struct phy *serdes;
+
+             err = of_property_read_u32(portnp, "reg", &portno);
+             if (err) {
+                     dev_err(sparx5->dev, "port reg property

error\n");
+                     continue;
+             }
+             err = of_property_read_u32(portnp, "max-speed", +                                        &config.max_speed); +             if (err) {
+                     dev_err(sparx5->dev, "port max-speed property error\n");

Quoted 8 lines
Quoted 5 lines

+                     continue;
+             }
+             config.speed = SPEED_UNKNOWN;
+             err = of_property_read_u32(portnp, "sd_sgpio", &config.sd_sgpio);

Not in the binding documentation. I think i need to withdraw my Reviewed-by :-(

Ooops - yes that is a mistake that these 2 items were not included.

Quoted 20 lines
Quoted 11 lines

+             if (err)
+                     config.sd_sgpio = ~0;
+             else
+                     sparx5->sd_sgpio_remapping = true; +             serdes = devm_of_phy_get(sparx5->dev, portnp, NULL); +             if (IS_ERR(serdes)) {
+                     err = PTR_ERR(serdes);
+                     if (err != -EPROBE_DEFER)
+                             dev_err(sparx5->dev,
+                                     "missing SerDes phys for

Quoted 8 lines

port%d\n",
+                                     portno);
+                     return err;
+             }
+
+             err = of_get_phy_mode(portnp, &config.phy_mode); +             if (err)
+                     config.power_down = true;

Quoted 2 lines

You should indicate in the binding it is optional. And what happens when it is missing.

Will update the description.

Quoted 17 lines
Quoted 12 lines

+             config.media_type = ETH_MEDIA_DAC;
+             config.serdes_reset = true;
+             config.portmode = config.phy_mode;
+             err = sparx5_probe_port(sparx5, portnp, serdes, portno, &config);
+             if (err) {
+                     dev_err(sparx5->dev, "port probe error\n"); +                     goto cleanup_ports;
+             }
+     }
+     sparx5_board_init(sparx5);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 672

Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +3 -0
+
+cleanup_ports:
+     return err;

Seems missed named, no cleanup.

Ah - this comes later (as the driver was split in functional groups for reviewing). I hope this is OK, as it is only temporary - I could add a comment to that effect.

Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +27 -0
+static int __init sparx5_switch_reset(void)
+{
+     const char *syscon_cpu = "microchip,sparx5-cpu-syscon",
+             *syscon_gcb = "microchip,sparx5-gcb-syscon";
+     struct regmap *cpu_ctrl, *gcb_ctrl;
+     u32 val;
+
+     cpu_ctrl = syscon_regmap_lookup_by_compatible(syscon_cpu);
+     if (IS_ERR(cpu_ctrl)) {
+             pr_err("No '%s' syscon map\n", syscon_cpu);
+             return PTR_ERR(cpu_ctrl);
+     }
+
+     gcb_ctrl = syscon_regmap_lookup_by_compatible(syscon_gcb);
+     if (IS_ERR(gcb_ctrl)) {
+             pr_err("No '%s' syscon map\n", syscon_gcb);
+             return PTR_ERR(gcb_ctrl);
+     }
+
+     /* Make sure the core is PROTECTED from reset */
+     regmap_update_bits(cpu_ctrl, RESET_PROT_STAT,
+                        SYS_RST_PROT_VCORE, SYS_RST_PROT_VCORE);
+
+     regmap_write(gcb_ctrl, spx5_offset(GCB_SOFT_RST),
+                  GCB_SOFT_RST_SOFT_SWC_RST_SET(1));
+
+     return readx_poll_timeout(sparx5_read_gcb_soft_rst, gcb_ctrl,
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 729

Quoted 6 lines

val,
+                               GCB_SOFT_RST_SOFT_SWC_RST_GET(val) == 0,
+                               1, 100);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +2 -0
+}
+postcore_initcall(sparx5_switch_reset);

That is pretty unusual. Why cannot this be done at probe time?

The problem is that the switch core reset also affects (reset) the SGPIO controller.

We tried to put this in the reset driver, but it was rejected. If the reset is done at probe time, the SGPIO driver may already have initialized state.

The switch core reset will then reset all SGPIO registers.

Quoted 17 lines
Quoted 5 lines
(quoted diff) +2 -0
+/* Clock period in picoseconds */
+static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq

cclock)

drivers/net/ethernet/microchip/sparx5/sparx5_main.h new file +1 -0
+{

drivers/net/ethernet/microchip/sparx5/sparx5_main.h line 147

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h new file +10 -0
+     switch (cclock) {
+     case SPX5_CORE_CLOCK_250MHZ:
+             return 4000;
+     case SPX5_CORE_CLOCK_500MHZ:
+             return 2000;
+     case SPX5_CORE_CLOCK_625MHZ:
+     default:
+             return 1600;
+     }
+}

Is this something which is used in the hot path?

No - so maybe this should just be a regular function?

Quoted 17 lines
Quoted 4 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h line 10

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main_regs.h new file +10 -0
@@ -0,0 +1,3922 @@
+/* SPDX-License-Identifier: GPL-2.0+
+ * Microchip Sparx5 Switch driver
+ *
+ * Copyright (c) 2020 Microchip Technology Inc.
+ */
+
+/* This file is autogenerated by cml-utils 2020-11-19 10:41:34
+0100.
+ * Commit ID: f34790e69dc252103e2cc3e85b1a5e4d9e3aa190
+ */

How reproducible this is generation process? If you have to run it again, will it keep the same order of lines?

As long as the CML (Chip Markup Language) file has not changed (documentation fields not considered), this is reproducible. The tool parses the XML nodes in a deterministic order.

Quoted 2 lines

       Andrew

Thanks for your comments
/Steen

#10 lore raw

Re: [RFC PATCH v2 2/8] net: sparx5: add the basic sparx5 driver

Quoted 33 lines
Quoted 28 lines
Quoted 19 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +17 -0
+static void sparx5_board_init(struct sparx5 *sparx5)
+{
+     int idx;
+
+     if (!sparx5->sd_sgpio_remapping)
+             return;
+
+     /* Enable SGPIO Signal Detect remapping */
+     spx5_rmw(GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+              GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+              sparx5,
+              GCB_HW_SGPIO_SD_CFG);
+
+     /* Refer to LOS SGPIO */
+     for (idx = 0; idx < SPX5_PORTS; idx++) {
+             if (sparx5->ports[idx]) {
+                     if (sparx5->ports[idx]->conf.sd_sgpio != ~0)

{
+                             spx5_wr(sparx5->ports[idx]-

Quoted 8 lines
Quoted 1 line

conf.sd_sgpio,

+                                     sparx5,
+
GCB_HW_SGPIO_TO_SD_MAP_CFG(idx));
+                     }
+             }
+     }
+}

Quoted 4 lines

I've not looked at how you do SFP integration yet. Is this the LOS from the SFP socket? Is there a Linux GPIO controller exported by this
driver, so the SFP driver can use the GPIOs?

Quoted 7 lines

Yes the SFP driver (used by the Sparx5 SerDes driver) will use the SGPIO LOS, Module Detect etc, and the Port Modules are aware of the location of the LOS, and use this by default without any driver configuration.
But on the PCB134 the SGPIOs are shifted one bit by a mistake, and they are not located in the expected position, so we have this board remapping function to handle that aspect.

Is it possible to turn this off in the hardware? It might be less confusing if LOS it determined by phylink, not phylink and the switch itself. Especially when we get into race conditions between PHYLINK polling the GPIO and the hardware taking the short cut?

Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +12 -0
+static int mchp_sparx5_probe(struct platform_device *pdev)
+{
+     struct device_node *np = pdev->dev.of_node;
+     struct sparx5 *sparx5;
+     struct device_node *ports, *portnp;
+     const u8 *mac_addr;
+     int err = 0;
+
+     if (!np && !pdev->dev.platform_data)
+             return -ENODEV;
+
+     sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5),

GFP_KERNEL);
+     if (!sparx5)
+             return -ENOMEM;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +11 -0
+
+     platform_set_drvdata(pdev, sparx5);
+     sparx5->pdev = pdev;
+     sparx5->dev = &pdev->dev;
+
+     /* Default values, some from DT */
+     sparx5->coreclock = SPX5_CORE_CLOCK_DEFAULT;
+
+     mac_addr = of_get_mac_address(np);
+     if (IS_ERR_OR_NULL(mac_addr)) {
+             dev_info(sparx5->dev, "MAC addr was not set, use

random MAC\n");

Quoted 8 lines
Quoted 5 lines

+             eth_random_addr(sparx5->base_mac); +             sparx5->base_mac[5] = 0;
+     } else {
+             ether_addr_copy(sparx5->base_mac, mac_addr); +     }

The binding document does not say anything about a MAC address at the top level. What is this used for?

Quoted 2 lines

This the base MAC address used for generating the the switch NI's MAC addresses.

Yes, that is obvious from the code. But all DT properties must be in the binding Documentation. The DT verifier is going to complain when it finds a mac-address property which is not described in the yaml file.

Quoted 17 lines
Quoted 8 lines
Quoted 8 lines

+             config.media_type = ETH_MEDIA_DAC;
+             config.serdes_reset = true;
+             config.portmode = config.phy_mode;
+             err = sparx5_probe_port(sparx5, portnp, serdes, portno, &config);
+             if (err) {
+                     dev_err(sparx5->dev, "port probe error\n"); +                     goto cleanup_ports;

Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 672

Quoted 6 lines

+             }
+     }
+     sparx5_board_init(sparx5);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +3 -0
+
+cleanup_ports:
+     return err;

Seems missed named, no cleanup.

Quoted 3 lines

Ah - this comes later (as the driver was split in functional groups for reviewing). I hope this is OK, as it is only temporary - I could add a comment to that effect.

Yes, this is fine. Here, and in other places, a comment like:

/* More code to be added in later patches */

would of been nice, just as a heads up. That is the problem with linear patch review.

Quoted 36 lines
Quoted 27 lines
Quoted 27 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +27 -0
+static int __init sparx5_switch_reset(void)
+{
+     const char *syscon_cpu = "microchip,sparx5-cpu-syscon",
+             *syscon_gcb = "microchip,sparx5-gcb-syscon";
+     struct regmap *cpu_ctrl, *gcb_ctrl;
+     u32 val;
+
+     cpu_ctrl = syscon_regmap_lookup_by_compatible(syscon_cpu);
+     if (IS_ERR(cpu_ctrl)) {
+             pr_err("No '%s' syscon map\n", syscon_cpu);
+             return PTR_ERR(cpu_ctrl);
+     }
+
+     gcb_ctrl = syscon_regmap_lookup_by_compatible(syscon_gcb);
+     if (IS_ERR(gcb_ctrl)) {
+             pr_err("No '%s' syscon map\n", syscon_gcb);
+             return PTR_ERR(gcb_ctrl);
+     }
+
+     /* Make sure the core is PROTECTED from reset */
+     regmap_update_bits(cpu_ctrl, RESET_PROT_STAT,
+                        SYS_RST_PROT_VCORE, SYS_RST_PROT_VCORE);
+
+     regmap_write(gcb_ctrl, spx5_offset(GCB_SOFT_RST),
+                  GCB_SOFT_RST_SOFT_SWC_RST_SET(1));
+
+     return readx_poll_timeout(sparx5_read_gcb_soft_rst, gcb_ctrl,
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 729

Quoted 6 lines

val,
+                               GCB_SOFT_RST_SOFT_SWC_RST_GET(val) == 0,
+                               1, 100);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +2 -0
+}
+postcore_initcall(sparx5_switch_reset);

That is pretty unusual. Why cannot this be done at probe time?

Quoted 8 lines

The problem is that the switch core reset also affects (reset) the SGPIO controller.

We tried to put this in the reset driver, but it was rejected. If the reset is done at probe time, the SGPIO driver may already have initialized state.

The switch core reset will then reset all SGPIO registers.

Ah, O.K. Dumb question. Why is the SGPIO driver a separate driver? It sounds like it should be embedded inside this driver if it is sharing hardware.

Another option would be to look at the reset subsystem, and have this driver export a reset controller, which the SGPIO driver can bind to. Given that the GPIO driver has been merged, if this will work, it is probably a better solution.

Andrew

#11 lore raw

Re: [RFC PATCH v2 2/8] net: sparx5: add the basic sparx5 driver

Quoted 9 lines · Andrew Lunn
Quoted 8 lines

The problem is that the switch core reset also affects (reset) the SGPIO controller.

We tried to put this in the reset driver, but it was rejected. If the reset is done at probe time, the SGPIO driver may already have initialized state.

The switch core reset will then reset all SGPIO registers.

Quoted 9 lines

Ah, O.K. Dumb question. Why is the SGPIO driver a separate driver? It sounds like it should be embedded inside this driver if it is sharing hardware.

Another option would be to look at the reset subsystem, and have this driver export a reset controller, which the SGPIO driver can bind to. Given that the GPIO driver has been merged, if this will work, it is probably a better solution.

That was my suggestion. Then you can ensure from the reset controller driver that this is done exactly once, either from the sgpio driver or from the switchdev driver. IIRC, the sgpio from the other SoCs are not affected by the reset.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#12 lore raw

Re: [RFC PATCH v2 2/8] net: sparx5: add the basic sparx5 driver

Quoted 20 lines · Alexandre Belloni
Quoted 9 lines · Andrew Lunn
Quoted 8 lines

The problem is that the switch core reset also affects (reset) the SGPIO controller.

We tried to put this in the reset driver, but it was rejected. If the reset is done at probe time, the SGPIO driver may already have initialized state.

The switch core reset will then reset all SGPIO registers.

Quoted 9 lines

Ah, O.K. Dumb question. Why is the SGPIO driver a separate driver? It sounds like it should be embedded inside this driver if it is sharing hardware.

Another option would be to look at the reset subsystem, and have this driver export a reset controller, which the SGPIO driver can bind to. Given that the GPIO driver has been merged, if this will work, it is probably a better solution.

Quoted 4 lines

That was my suggestion. Then you can ensure from the reset controller driver that this is done exactly once, either from the sgpio driver or from the switchdev driver. IIRC, the sgpio from the other SoCs are not affected by the reset.

I will take a look to see if we can change the implementation to use a reset controller.

---Lars

--
Lars Povlsen,
Microchip

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#13 lore raw

Re: [RFC PATCH v2 2/8] net: sparx5: add the basic sparx5 driver

In reply to Andrew Lunn
Quoted 43 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 33 lines
Quoted 20 lines
Quoted 20 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +17 -0
+static void sparx5_board_init(struct sparx5 *sparx5)
+{
+     int idx;
+
+     if (!sparx5->sd_sgpio_remapping)
+             return;
+
+     /* Enable SGPIO Signal Detect remapping */
+     spx5_rmw(GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+              GCB_HW_SGPIO_SD_CFG_SD_MAP_SEL,
+              sparx5,
+              GCB_HW_SGPIO_SD_CFG);
+
+     /* Refer to LOS SGPIO */
+     for (idx = 0; idx < SPX5_PORTS; idx++) {
+             if (sparx5->ports[idx]) {
+                     if (sparx5->ports[idx]->conf.sd_sgpio != ~0)

{
+ spx5_wr(sparx5->ports[idx]-

Quoted 1 line

conf.sd_sgpio,

Quoted 12 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 228

Quoted 7 lines
(quoted diff) +2 -0
+                                     sparx5,
+

GCB_HW_SGPIO_TO_SD_MAP_CFG(idx));

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +4 -0
+                     }
+             }
+     }
+}

I've not looked at how you do SFP integration yet. Is this the LOS from the SFP socket? Is there a Linux GPIO controller exported by this
driver, so the SFP driver can use the GPIOs?

Quoted 7 lines

Yes the SFP driver (used by the Sparx5 SerDes driver) will use the SGPIO LOS, Module Detect etc, and the Port Modules are aware of the location of the LOS, and use this by default without any driver configuration.
But on the PCB134 the SGPIOs are shifted one bit by a mistake, and they are not located in the expected position, so we have this board remapping function to handle that aspect.

Quoted 5 lines

Is it possible to turn this off in the hardware? It might be less confusing if LOS it determined by phylink, not phylink and the switch itself. Especially when we get into race conditions between PHYLINK polling the GPIO and the hardware taking the short cut?

OK - I get you point, but I think the message I got when investigating this, was that it was not possible to turn it off. I will check that again.
On the other hand this is also used by our bare-metal API (MESA) so in that context it simpifies the setup, since the port modules are aware of the SFP state.

Quoted 37 lines
Quoted 37 lines
Quoted 36 lines
Quoted 28 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +12 -0
+static int mchp_sparx5_probe(struct platform_device *pdev)
+{
+     struct device_node *np = pdev->dev.of_node;
+     struct sparx5 *sparx5;
+     struct device_node *ports, *portnp;
+     const u8 *mac_addr;
+     int err = 0;
+
+     if (!np && !pdev->dev.platform_data)
+             return -ENODEV;
+
+     sparx5 = devm_kzalloc(&pdev->dev, sizeof(*sparx5),

GFP_KERNEL);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +13 -0
+     if (!sparx5)
+             return -ENOMEM;
+
+     platform_set_drvdata(pdev, sparx5);
+     sparx5->pdev = pdev;
+     sparx5->dev = &pdev->dev;
+
+     /* Default values, some from DT */
+     sparx5->coreclock = SPX5_CORE_CLOCK_DEFAULT;
+
+     mac_addr = of_get_mac_address(np);
+     if (IS_ERR_OR_NULL(mac_addr)) {
+             dev_info(sparx5->dev, "MAC addr was not set, use

random MAC\n");

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 612

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +5 -0
+             eth_random_addr(sparx5->base_mac);
+             sparx5->base_mac[5] = 0;
+     } else {
+             ether_addr_copy(sparx5->base_mac, mac_addr);
+     }

The binding document does not say anything about a MAC address at the top level. What is this used for?

Quoted 7 lines
Quoted 2 lines

This the base MAC address used for generating the the switch NI's MAC addresses.

Yes, that is obvious from the code. But all DT properties must be in the binding Documentation. The DT verifier is going to complain when it finds a mac-address property which is not described in the yaml file.

I will add a description for the MAC address to the bindings.

Quoted 22 lines
Quoted 18 lines
Quoted 17 lines
Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +4 -0
+             config.media_type = ETH_MEDIA_DAC;
+             config.serdes_reset = true;
+             config.portmode = config.phy_mode;
+             err = sparx5_probe_port(sparx5, portnp, serdes,

portno, &config);

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 672

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +9 -0
+             if (err) {
+                     dev_err(sparx5->dev, "port probe error\n");
+                     goto cleanup_ports;
+             }
+     }
+     sparx5_board_init(sparx5);
+
+cleanup_ports:
+     return err;

Seems missed named, no cleanup.

Quoted 3 lines

Ah - this comes later (as the driver was split in functional groups for reviewing). I hope this is OK, as it is only temporary - I could add a comment to that effect.

Quoted 6 lines

Yes, this is fine. Here, and in other places, a comment like:

/* More code to be added in later patches */

would of been nice, just as a heads up. That is the problem with linear patch review.

Will do

Quoted 44 lines
Quoted 44 lines
Quoted 28 lines
Quoted 28 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +27 -0
+static int __init sparx5_switch_reset(void)
+{
+     const char *syscon_cpu = "microchip,sparx5-cpu-syscon",
+             *syscon_gcb = "microchip,sparx5-gcb-syscon";
+     struct regmap *cpu_ctrl, *gcb_ctrl;
+     u32 val;
+
+     cpu_ctrl = syscon_regmap_lookup_by_compatible(syscon_cpu);
+     if (IS_ERR(cpu_ctrl)) {
+             pr_err("No '%s' syscon map\n", syscon_cpu);
+             return PTR_ERR(cpu_ctrl);
+     }
+
+     gcb_ctrl = syscon_regmap_lookup_by_compatible(syscon_gcb);
+     if (IS_ERR(gcb_ctrl)) {
+             pr_err("No '%s' syscon map\n", syscon_gcb);
+             return PTR_ERR(gcb_ctrl);
+     }
+
+     /* Make sure the core is PROTECTED from reset */
+     regmap_update_bits(cpu_ctrl, RESET_PROT_STAT,
+                        SYS_RST_PROT_VCORE, SYS_RST_PROT_VCORE);
+
+     regmap_write(gcb_ctrl, spx5_offset(GCB_SOFT_RST),
+                  GCB_SOFT_RST_SOFT_SWC_RST_SET(1));
+
+     return readx_poll_timeout(sparx5_read_gcb_soft_rst, gcb_ctrl,
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.c line 729

Quoted 6 lines

val,
+ GCB_SOFT_RST_SOFT_SWC_RST_GET(val)
== 0,

drivers/net/ethernet/microchip/sparx5/sparx5_main.c new file +3 -0
+                               1, 100);
+}
+postcore_initcall(sparx5_switch_reset);

That is pretty unusual. Why cannot this be done at probe time?

The problem is that the switch core reset also affects (reset) the SGPIO controller.

We tried to put this in the reset driver, but it was rejected. If the reset is done at probe time, the SGPIO driver may already have initialized state.

Quoted 5 lines
Quoted 1 line

The switch core reset will then reset all SGPIO registers.

Ah, O.K. Dumb question. Why is the SGPIO driver a separate driver? It sounds like it should be embedded inside this driver if it is sharing hardware.

The same SGPIO block is present (with suitable scaling of the number of SGPIOS) in all our switches, so this driver will be reused on all the platforms when we get them upstreamed (or at least that is the plan).

Quoted 5 lines

Another option would be to look at the reset subsystem, and have this driver export a reset controller, which the SGPIO driver can bind to. Given that the GPIO driver has been merged, if this will work, it is probably a better solution.

Alex has already commented on this, but this is probably the goal as I understand.

Quoted 2 lines

Andrew

BR
Steen

---------------------------------------
Steen Hegelund
[email protected]

author maintainer
#14 lore raw

RFC PATCH v2 3/8 net: sparx5: add hostmode with phylink support

In reply to Steen Hegelund

This adds phylink support for ports and register base injection and extraction.

---
 .../net/ethernet/microchip/sparx5/Makefile    |   2 +-
 .../ethernet/microchip/sparx5/sparx5_main.c   |  68 +++++
 .../ethernet/microchip/sparx5/sparx5_main.h   |  26 ++
 .../ethernet/microchip/sparx5/sparx5_netdev.c | 203 +++++++++++++
 .../ethernet/microchip/sparx5/sparx5_packet.c | 273 ++++++++++++++++++
 .../microchip/sparx5/sparx5_phylink.c         | 168 +++++++++++
 6 files changed, 739 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_packet.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_phylink.c
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
index 41a31843d86f..19a593d17f4a 100644
@@ -5,4 +5,4 @@
 
 obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o
 
-sparx5-switch-objs  := sparx5_main.o
+sparx5-switch-objs  := sparx5_main.o sparx5_packet.o sparx5_netdev.o sparx5_phylink.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +68 -0

128 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_main.h +26 -0
index 887b4f80b2db..a92ebf339fe1 100644
@@ -93,6 +93,9 @@ struct sparx5_port {
 	struct device_node         *of_node;
 	struct phy                 *serdes;
 	struct sparx5_port_config  conf;
+	struct phylink_config      phylink_config;
+	struct phylink             *phylink;
+	struct phylink_pcs         phylink_pcs;
 	u16                        portno;
 	/* Ingress default VLAN (pvid) */
 	u16                        pvid;
@@ -132,6 +135,27 @@ struct sparx5 {
 	bool                                  sd_sgpio_remapping;
 };
 
+/* sparx5_main.c */
+void sparx5_update_cpuport_stats(struct sparx5 *sparx5, int portno);
+bool sparx5_is_cpuport_stat(struct sparx5 *sparx5, int idx);
+
+/* sparx5_packet.c */
+irqreturn_t sparx5_xtr_handler(int irq, void *_priv);
+int sparx5_port_xmit_impl(struct sk_buff *skb, struct net_device *dev);
+void sparx5_manual_injection_mode(struct sparx5 *sparx5);
+
+/* sparx5_netdev.c */
+bool sparx5_netdevice_check(const struct net_device *dev);
+struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno);
+int sparx5_register_netdevs(struct sparx5 *sparx5);
+void sparx5_destroy_netdev(struct sparx5 *sparx5, struct sparx5_port *port);
+
+/* Configuration */
+static inline bool sparx5_use_cu_phy(struct sparx5_port *port)
+{
+	return port->conf.phy_mode != PHY_INTERFACE_MODE_NA;
+}
+
 /* Clock period in picoseconds */
 static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 {
@@ -146,6 +170,8 @@ static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 	}
 }
 
+extern const struct phylink_mac_ops sparx5_phylink_mac_ops;
+
 /* Calculate raw offset */
 static inline __pure int spx5_offset(int id, int tinst, int tcnt,
 				     int gbase, int ginst,
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +203 -0

203 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +273 -0

273 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_phylink.c new file +168 -0

168 lines not on this page · raw message

Signature · 7 lines
2.29.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#15 lore raw

Re: [RFC PATCH v2 3/8] net: sparx5: add hostmode with phylink support

drivers/net/ethernet/microchip/sparx5/sparx5_main.c static int sparx5_probe_port(struct sparx5 *sparx5, · line 279

Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +8 -0
+	/* Create a phylink for PHY management.  Also handles SFPs */
+	spx5_port->phylink_config.dev = &spx5_port->ndev->dev;
+	spx5_port->phylink_config.type = PHYLINK_NETDEV;
+	spx5_port->phylink_config.pcs_poll = true;
+
+	/* phylink needs a valid interface mode to parse dt node */
+	if (phy_mode == PHY_INTERFACE_MODE_NA)
+		phy_mode = PHY_INTERFACE_MODE_10GBASER;

Maybe just enforce a valid value in DT?

drivers/net/ethernet/microchip/sparx5/sparx5_main.h struct sparx5 { · line 157

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +5 -0
+/* Configuration */
+static inline bool sparx5_use_cu_phy(struct sparx5_port *port)
+{
+	return port->conf.phy_mode != PHY_INTERFACE_MODE_NA;
+}

That is a rather odd definition of copper.

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 7

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +7 -0
new file mode 100644
index 000000000000..6f9282e9d3f4
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Microchip Sparx5 Switch driver
+ *
+ * Copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
+ */
+
+#include "sparx5_main.h"

I don't actually know what is preferred here, but very few drivers i've reviewed put all the required headers into another header file. They normally list them in each .c file.

Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +4 -0
+static int sparx5_port_open(struct net_device *ndev)
+{
+	struct sparx5_port *port = netdev_priv(ndev);
+	int err = 0;

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 81

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+
+	err = phylink_of_phy_connect(port->phylink, port->of_node, 0);
+	if (err) {
+		netdev_err(ndev, "Could not attach to PHY\n");
+		return err;
+	}
+
+	phylink_start(port->phylink);
+
+	if (!ndev->phydev) {

Humm. When is ndev->phydev set? I don't think phylink ever sets it.

Quoted 18 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +17 -0
+		/* power up serdes */
+		port->conf.power_down = false;
+		err = phy_power_on(port->serdes);
+		if (err)
+			netdev_err(ndev, "%s failed\n", __func__);
+	}
+
+	return err;
+}
 
+struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno)
+{
+	struct net_device *ndev;
+	struct sparx5_port *spx5_port;
+
+	ndev = devm_alloc_etherdev(sparx5->dev, sizeof(struct sparx5_port));
+	if (!ndev)
+		return ERR_PTR(-ENOMEM);

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 163

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+
+	SET_NETDEV_DEV(ndev, sparx5->dev);
+	spx5_port = netdev_priv(ndev);
+	spx5_port->ndev = ndev;
+	spx5_port->sparx5 = sparx5;
+	spx5_port->portno = portno;
+	sparx5_set_port_ifh(spx5_port->ifh, portno);
+	snprintf(ndev->name, IFNAMSIZ, "eth%d", portno);
+
+	ether_setup(ndev);

devm_alloc_etherdev() should of already called ether_setup().

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 168

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +5 -0
+	ndev->netdev_ops = &sparx5_port_netdev_ops;
+	ndev->features |= NETIF_F_LLTX; /* software tx */
+
+	ether_addr_copy(ndev->dev_addr, sparx5->base_mac);
+	ndev->dev_addr[ETH_ALEN - 1] += portno + 1;

That will cause some surprises with wrap around. Use eth_addr_inc()

Quoted 82 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +82 -0
+static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap)
+{
+	int i, byte_cnt = 0;
+	bool eof_flag = false, pruned_flag = false, abort_flag = false;
+	u32 ifh[IFH_LEN];
+	struct sk_buff *skb;
+	struct frame_info fi;
+	struct sparx5_port *port;
+	struct net_device *netdev;
+	u32 *rxbuf;
+
+	/* Get IFH */
+	for (i = 0; i < IFH_LEN; i++)
+		ifh[i] = spx5_rd(sparx5, QS_XTR_RD(grp));
+
+	/* Decode IFH (whats needed) */
+	sparx5_ifh_parse(ifh, &fi);
+
+	/* Map to port netdev */
+	port = fi.src_port < SPX5_PORTS ?
+		sparx5->ports[fi.src_port] : NULL;
+	if (!port || !port->ndev) {
+		dev_err(sparx5->dev, "Data on inactive port %d\n", fi.src_port);
+		sparx5_xtr_flush(sparx5, grp);
+		return;
+	}
+
+	/* Have netdev, get skb */
+	netdev = port->ndev;
+	skb = netdev_alloc_skb(netdev, netdev->mtu + ETH_HLEN);
+	if (!skb) {
+		sparx5_xtr_flush(sparx5, grp);
+		dev_err(sparx5->dev, "No skb allocated\n");
+		return;
+	}
+	rxbuf = (u32 *)skb->data;
+
+	/* Now, pull frame data */
+	while (!eof_flag) {
+		u32 val = spx5_rd(sparx5, QS_XTR_RD(grp));
+		u32 cmp = val;
+
+		if (byte_swap)
+			cmp = ntohl((__force __be32)val);
+
+		switch (cmp) {
+		case XTR_NOT_READY:
+			break;
+		case XTR_ABORT:
+			/* No accompanying data */
+			abort_flag = true;
+			eof_flag = true;
+			break;
+		case XTR_EOF_0:
+		case XTR_EOF_1:
+		case XTR_EOF_2:
+		case XTR_EOF_3:
+			/* This assumes STATUS_WORD_POS == 1, Status
+			 * just after last data
+			 */
+			byte_cnt -= (4 - XTR_VALID_BYTES(val));
+			eof_flag = true;
+			break;
+		case XTR_PRUNED:
+			/* But get the last 4 bytes as well */
+			eof_flag = true;
+			pruned_flag = true;
+			fallthrough;
+		case XTR_ESCAPE:
+			*rxbuf = spx5_rd(sparx5, QS_XTR_RD(grp));
+			byte_cnt += 4;
+			rxbuf++;
+			break;
+		default:
+			*rxbuf = val;
+			byte_cnt += 4;
+			rxbuf++;
+		}
+	}
+
+	if (abort_flag || pruned_flag || !eof_flag) {
+		netdev_err(netdev, "Discarded frame: abort:%d pruned:%d eof:%d\n",

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+			   abort_flag, pruned_flag, eof_flag);
+		kfree_skb(skb);
+		return;
+	}
+
+	if (!netif_oper_up(netdev)) {
+		netdev_err(netdev, "Discarded frame: Interface not up\n");
+		kfree_skb(skb);
+		return;
+	}

Why is it sending frames when it is not up?

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +13 -0
+static int sparx5_inject(struct sparx5 *sparx5,
+			 u32 *ifh,
+			 struct sk_buff *skb)
+{
+	u32 val, w, count;
+	int grp = INJ_QUEUE;
+	u8 *buf;
+
+	val = spx5_rd(sparx5, QS_INJ_STATUS);
+	if (!(QS_INJ_STATUS_FIFO_RDY_GET(val) & BIT(grp))) {
+		pr_err("Injection: Queue not ready: 0x%lx\n",
+		       QS_INJ_STATUS_FIFO_RDY_GET(val));
+		return -1;

Always use -ESOMETHING.

Quoted 14 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +14 -0
+	}
+
+	if (QS_INJ_STATUS_WMARK_REACHED_GET(val) & BIT(grp)) {
+		pr_err("Injection: Watermark reached: 0x%lx\n",
+		       QS_INJ_STATUS_WMARK_REACHED_GET(val));
+		return -1;
+	}
+
+	/* Indicate SOF */
+	spx5_wr(QS_INJ_CTRL_SOF_SET(1) |
+		QS_INJ_CTRL_GAP_SIZE_SET(1),
+		sparx5, QS_INJ_CTRL(grp));
+
+	// Write the IFH to the chip.

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+	for (w = 0; w < IFH_LEN; w++)
+		spx5_wr(ifh[w], sparx5, QS_INJ_WR(grp));
+
+	/* Write words, round up */
+	count = ((skb->len + 3) / 4);
+	buf = skb->data;
+	for (w = 0; w < count; w++, buf += 4) {
+		val = get_unaligned((const u32 *)buf);
+		spx5_wr(val, sparx5, QS_INJ_WR(grp));
+	}

No DMA? What sort of performance do you get? Enough for the odd BPDU, IGMP frame etc, but i guess you don't want any real bulk data to be sent this way?

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+irqreturn_t sparx5_xtr_handler(int irq, void *_sparx5)
+{
+	struct sparx5 *sparx5 = _sparx5;
+
+	/* Check data in queue */
+	while (spx5_rd(sparx5, QS_XTR_DATA_PRESENT) & BIT(XTR_QUEUE))
+		sparx5_xtr_grp(sparx5, XTR_QUEUE, false);
+
+	return IRQ_HANDLED;
+}

Is there any sort of limit how many times this will loop? If somebody is blasting 10Gbps at the CPU, will it ever get out of this loop?

Andrew

author maintainer
#16 lore raw

Re: [RFC PATCH v2 3/8] net: sparx5: add hostmode with phylink support

Hi Andrew,

Quoted 13 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines

+     /* Create a phylink for PHY management.  Also handles SFPs */ +     spx5_port->phylink_config.dev = &spx5_port->ndev->dev; +     spx5_port->phylink_co
nfig.type = PHYLINK_NETDEV;
+     spx5_port->phylink_config.pcs_poll = true;
+
+     /* phylink needs a valid interface mode to parse dt node */ +     if (phy_mode == PHY_INTERFACE_MODE_NA)
+             phy_mode = PHY_INTERFACE_MODE_10GBASER;

Quoted 1 line

Maybe just enforce a valid value in DT?

Maybe I need to clarify that you must choose between an Ethernet cuPHY or an SFP, so it is optional.

Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.h struct sparx5 { · line 157

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +5 -0
+/* Configuration */
+static inline bool sparx5_use_cu_phy(struct sparx5_port *port)
+{
+     return port->conf.phy_mode != PHY_INTERFACE_MODE_NA;
+}

That is a rather odd definition of copper.

Should I rather use a bool property to select between the two options (cuPHY or SFP)?

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +4 -0
new file mode 100644
index 000000000000..6f9282e9d3f4
@@ -0,0 +1,203 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Microchip Sparx5 Switch driver
+ *
+ * Copyright (c) 2020 Microchip Technology Inc. and its
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 4 lines

subsidiaries.
+ */

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +2 -0
+
+#include "sparx5_main.h"

I don't actually know what is preferred here, but very few drivers i've reviewed put all the required headers into another header file. They normally list them in each .c file.

I will look at reworking this.

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +6 -0
+static int sparx5_port_open(struct net_device *ndev)
+{
+     struct sparx5_port *port = netdev_priv(ndev);
+     int err = 0;
+
+     err = phylink_of_phy_connect(port->phylink, port->of_node,

0);
+     if (err) {
+             netdev_err(ndev, "Could not attach to PHY\n");

Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 81

Quoted 6 lines

+             return err;
+     }

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +4 -0
+
+     phylink_start(port->phylink);
+
+     if (!ndev->phydev) {

Humm. When is ndev->phydev set? I don't think phylink ever sets it.

Indirectly: phylink_of_phy_connect uses phy_attach_direct and that sets the phydev.

Quoted 25 lines
Quoted 25 lines

+             /* power up serdes */
+             port->conf.power_down = false;
+             err = phy_power_on(port->serdes);
+             if (err)
+                     netdev_err(ndev, "%s failed\n", __func__); +     }

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +4 -0
+
+     return err;
+}
 
+struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32

portno)

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +5 -0
+{
+     struct net_device *ndev;
+     struct sparx5_port *spx5_port;
+
+     ndev = devm_alloc_etherdev(sparx5->dev, sizeof(struct

sparx5_port));
+     if (!ndev)
+             return ERR_PTR(-ENOMEM);
+
+     SET_NETDEV_DEV(ndev, sparx5->dev);
+     spx5_port = netdev_priv(ndev);
+     spx5_port->ndev = ndev;

Quoted 8 lines
Quoted 6 lines

+     spx5_port->sparx5 = sparx5;
+     spx5_port->portno = portno;
+     sparx5_set_port_ifh(spx5_port->ifh, portno); +     snprintf(ndev->name, IFNAMSIZ, "eth%d", portno); +
+     ether_setup(ndev);

devm_alloc_etherdev() should of already called ether_setup().

Ah - yes it is the setup(dev) call in alloc_netdev_mqs. I will remove that then.

Quoted 8 lines
Quoted 6 lines

+     ndev->netdev_ops = &sparx5_port_netdev_ops; +     ndev->features |= NETIF_F_LLTX; /* software tx */ +
+     ether_addr_copy(ndev->dev_addr, sparx5->base_mac); +     ndev->dev_addr[ETH_ALEN - 1] += portno + 1;

That will cause some surprises with wrap around. Use eth_addr_inc()

OK - will do.

Quoted 92 lines
Quoted 92 lines

+static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap)
+{
+     int i, byte_cnt = 0;
+     bool eof_flag = false, pruned_flag = false, abort_flag = false;
+     u32 ifh[IFH_LEN];
+     struct sk_buff *skb;
+     struct frame_info fi;
+     struct sparx5_port *port;
+     struct net_device *netdev;
+     u32 *rxbuf;

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +13 -0
+
+     /* Get IFH */
+     for (i = 0; i < IFH_LEN; i++)
+             ifh[i] = spx5_rd(sparx5, QS_XTR_RD(grp));
+
+     /* Decode IFH (whats needed) */
+     sparx5_ifh_parse(ifh, &fi);
+
+     /* Map to port netdev */
+     port = fi.src_port < SPX5_PORTS ?
+             sparx5->ports[fi.src_port] : NULL;
+     if (!port || !port->ndev) {
+             dev_err(sparx5->dev, "Data on inactive port %d\n",

fi.src_port);
+             sparx5_xtr_flush(sparx5, grp);
+             return;
+     }

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +56 -0
+
+     /* Have netdev, get skb */
+     netdev = port->ndev;
+     skb = netdev_alloc_skb(netdev, netdev->mtu + ETH_HLEN);
+     if (!skb) {
+             sparx5_xtr_flush(sparx5, grp);
+             dev_err(sparx5->dev, "No skb allocated\n");
+             return;
+     }
+     rxbuf = (u32 *)skb->data;
+
+     /* Now, pull frame data */
+     while (!eof_flag) {
+             u32 val = spx5_rd(sparx5, QS_XTR_RD(grp));
+             u32 cmp = val;
+
+             if (byte_swap)
+                     cmp = ntohl((__force __be32)val);
+
+             switch (cmp) {
+             case XTR_NOT_READY:
+                     break;
+             case XTR_ABORT:
+                     /* No accompanying data */
+                     abort_flag = true;
+                     eof_flag = true;
+                     break;
+             case XTR_EOF_0:
+             case XTR_EOF_1:
+             case XTR_EOF_2:
+             case XTR_EOF_3:
+                     /* This assumes STATUS_WORD_POS == 1, Status
+                      * just after last data
+                      */
+                     byte_cnt -= (4 - XTR_VALID_BYTES(val));
+                     eof_flag = true;
+                     break;
+             case XTR_PRUNED:
+                     /* But get the last 4 bytes as well */
+                     eof_flag = true;
+                     pruned_flag = true;
+                     fallthrough;
+             case XTR_ESCAPE:
+                     *rxbuf = spx5_rd(sparx5, QS_XTR_RD(grp));
+                     byte_cnt += 4;
+                     rxbuf++;
+                     break;
+             default:
+                     *rxbuf = val;
+                     byte_cnt += 4;
+                     rxbuf++;
+             }
+     }
+
+     if (abort_flag || pruned_flag || !eof_flag) {
+             netdev_err(netdev, "Discarded frame: abort:%d

pruned:%d eof:%d\n",
+                        abort_flag, pruned_flag, eof_flag); +             kfree_skb(skb);
+             return;
+     }
+

Quoted 8 lines
Quoted 6 lines

+     if (!netif_oper_up(netdev)) {
+             netdev_err(netdev, "Discarded frame: Interface not up\n");
+             kfree_skb(skb);
+             return;
+     }

Why is it sending frames when it is not up?

This is intended for received frames. A situation where the lower layers have been enabled correctly but not the port.

Quoted 16 lines
Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +3 -0
+static int sparx5_inject(struct sparx5 *sparx5,
+                      u32 *ifh,
+                      struct sk_buff *skb)

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+{
+     u32 val, w, count;
+     int grp = INJ_QUEUE;
+     u8 *buf;
+
+     val = spx5_rd(sparx5, QS_INJ_STATUS);
+     if (!(QS_INJ_STATUS_FIFO_RDY_GET(val) & BIT(grp))) {
+             pr_err("Injection: Queue not ready: 0x%lx\n",
+                    QS_INJ_STATUS_FIFO_RDY_GET(val));
+             return -1;

Always use -ESOMETHING.

Yes.

Quoted 21 lines
Quoted 21 lines

+     }

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +19 -0
+
+     if (QS_INJ_STATUS_WMARK_REACHED_GET(val) & BIT(grp)) {
+             pr_err("Injection: Watermark reached: 0x%lx\n",
+                    QS_INJ_STATUS_WMARK_REACHED_GET(val));
+             return -1;
+     }
+
+     /* Indicate SOF */
+     spx5_wr(QS_INJ_CTRL_SOF_SET(1) |
+             QS_INJ_CTRL_GAP_SIZE_SET(1),
+             sparx5, QS_INJ_CTRL(grp));
+
+     // Write the IFH to the chip.
+     for (w = 0; w < IFH_LEN; w++)
+             spx5_wr(ifh[w], sparx5, QS_INJ_WR(grp));
+
+     /* Write words, round up */
+     count = ((skb->len + 3) / 4);
+     buf = skb->data;
Quoted 8 lines
Quoted 4 lines

+     for (w = 0; w < count; w++, buf += 4) { +             val = get_unaligned((const u32 *)buf); +             spx5_wr(val, sparx5, QS_INJ_WR(grp)); +     }

No DMA? What sort of performance do you get? Enough for the odd BPDU, IGMP frame etc, but i guess you don't want any real bulk data to be sent this way?

Yes the register based injection/extration is not going to be fast, but the FDMA and its driver is being sent later as separate series to keep the size of this review down.

Quoted 14 lines

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c

Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +10 -0
+irqreturn_t sparx5_xtr_handler(int irq, void *_sparx5)
+{
+     struct sparx5 *sparx5 = _sparx5;
+
+     /* Check data in queue */
+     while (spx5_rd(sparx5, QS_XTR_DATA_PRESENT) & BIT(XTR_QUEUE))
+             sparx5_xtr_grp(sparx5, XTR_QUEUE, false);
+
+     return IRQ_HANDLED;
+}

Is there any sort of limit how many times this will loop? If somebody is blasting 10Gbps at the CPU, will it ever get out of this loop?

Hmmm, not at the moment but this is because the FDMA driver is intended to be used in these scenarios.

Quoted 2 lines

   Andrew

Thanks for your comments

BR
Steen

#17 lore raw

Re: [RFC PATCH v2 3/8] net: sparx5: add hostmode with phylink support

Quoted 16 lines · Steen Hegelund

Hi Andrew,

Quoted 13 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines

+     /* Create a phylink for PHY management.  Also handles SFPs */ +     spx5_port->phylink_config.dev = &spx5_port->ndev->dev; +     spx5_port->phylink_co
nfig.type = PHYLINK_NETDEV;
+     spx5_port->phylink_config.pcs_poll = true;
+
+     /* phylink needs a valid interface mode to parse dt node */ +     if (phy_mode == PHY_INTERFACE_MODE_NA)
+             phy_mode = PHY_INTERFACE_MODE_10GBASER;

Quoted 4 lines
Quoted 1 line

Maybe just enforce a valid value in DT?

Maybe I need to clarify that you must choose between an Ethernet cuPHY or an SFP, so it is optional.

But you also need to watch out for somebody putting a copper modules in an SFP port. phylink will then set the mode to SGMII for a 1G copper module, etc.

Quoted 10 lines
Quoted 7 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.h struct sparx5 { · line 157

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +5 -0
+/* Configuration */
+static inline bool sparx5_use_cu_phy(struct sparx5_port *port)
+{
+     return port->conf.phy_mode != PHY_INTERFACE_MODE_NA;
+}

That is a rather odd definition of copper.

Should I rather use a bool property to select between the two options (cuPHY or SFP)?

I guess what you are trying to indicate is between a hard wired Copper PHY and an SFP cage? You have some sort of MII switch which allows the MAC to be connected to either the QSGMII PHY, or an SFP cage? But since the SFP cage could be populated with a copper PHY, and PHYLINK will then instantiate a phylib copper PHY driver for it, looking at phy_mode is not reliable. You need a property which selects the port, not the technology.

Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +6 -0
+static int sparx5_port_open(struct net_device *ndev)
+{
+     struct sparx5_port *port = netdev_priv(ndev);
+     int err = 0;
+
+     err = phylink_of_phy_connect(port->phylink, port->of_node,

0);
+     if (err) {
+             netdev_err(ndev, "Could not attach to PHY\n");

Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 81

Quoted 6 lines

+             return err;
+     }

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +4 -0
+
+     phylink_start(port->phylink);
+
+     if (!ndev->phydev) {

Humm. When is ndev->phydev set? I don't think phylink ever sets it.

Quoted 2 lines

Indirectly: phylink_of_phy_connect uses phy_attach_direct and that sets the phydev.

Ah, O.K. But watch out for a copper SFP module!

Quoted 100 lines
Quoted 91 lines
Quoted 91 lines

+static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap)
+{
+     int i, byte_cnt = 0;
+     bool eof_flag = false, pruned_flag = false, abort_flag = false;
+     u32 ifh[IFH_LEN];
+     struct sk_buff *skb;
+     struct frame_info fi;
+     struct sparx5_port *port;
+     struct net_device *netdev;
+     u32 *rxbuf;

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +13 -0
+
+     /* Get IFH */
+     for (i = 0; i < IFH_LEN; i++)
+             ifh[i] = spx5_rd(sparx5, QS_XTR_RD(grp));
+
+     /* Decode IFH (whats needed) */
+     sparx5_ifh_parse(ifh, &fi);
+
+     /* Map to port netdev */
+     port = fi.src_port < SPX5_PORTS ?
+             sparx5->ports[fi.src_port] : NULL;
+     if (!port || !port->ndev) {
+             dev_err(sparx5->dev, "Data on inactive port %d\n",

fi.src_port);
+             sparx5_xtr_flush(sparx5, grp);
+             return;
+     }

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +56 -0
+
+     /* Have netdev, get skb */
+     netdev = port->ndev;
+     skb = netdev_alloc_skb(netdev, netdev->mtu + ETH_HLEN);
+     if (!skb) {
+             sparx5_xtr_flush(sparx5, grp);
+             dev_err(sparx5->dev, "No skb allocated\n");
+             return;
+     }
+     rxbuf = (u32 *)skb->data;
+
+     /* Now, pull frame data */
+     while (!eof_flag) {
+             u32 val = spx5_rd(sparx5, QS_XTR_RD(grp));
+             u32 cmp = val;
+
+             if (byte_swap)
+                     cmp = ntohl((__force __be32)val);
+
+             switch (cmp) {
+             case XTR_NOT_READY:
+                     break;
+             case XTR_ABORT:
+                     /* No accompanying data */
+                     abort_flag = true;
+                     eof_flag = true;
+                     break;
+             case XTR_EOF_0:
+             case XTR_EOF_1:
+             case XTR_EOF_2:
+             case XTR_EOF_3:
+                     /* This assumes STATUS_WORD_POS == 1, Status
+                      * just after last data
+                      */
+                     byte_cnt -= (4 - XTR_VALID_BYTES(val));
+                     eof_flag = true;
+                     break;
+             case XTR_PRUNED:
+                     /* But get the last 4 bytes as well */
+                     eof_flag = true;
+                     pruned_flag = true;
+                     fallthrough;
+             case XTR_ESCAPE:
+                     *rxbuf = spx5_rd(sparx5, QS_XTR_RD(grp));
+                     byte_cnt += 4;
+                     rxbuf++;
+                     break;
+             default:
+                     *rxbuf = val;
+                     byte_cnt += 4;
+                     rxbuf++;
+             }
+     }
+
+     if (abort_flag || pruned_flag || !eof_flag) {
+             netdev_err(netdev, "Discarded frame: abort:%d

pruned:%d eof:%d\n",
+                        abort_flag, pruned_flag, eof_flag); +             kfree_skb(skb);
+             return;
+     }
+

Quoted 8 lines
Quoted 6 lines

+     if (!netif_oper_up(netdev)) {
+             netdev_err(netdev, "Discarded frame: Interface not up\n");
+             kfree_skb(skb);
+             return;
+     }

Why is it sending frames when it is not up?

Quoted 2 lines

This is intended for received frames. A situation where the lower layers have been enabled correctly but not the port.

But why should that happen? It suggests you have the order wrong. The lower level should only be enabled once the port is opened.

Quoted 7 lines
Quoted 3 lines

No DMA? What sort of performance do you get? Enough for the odd BPDU, IGMP frame etc, but i guess you don't want any real bulk data to be sent this way?

Yes the register based injection/extration is not going to be fast, but the FDMA and its driver is being sent later as separate series to keep the size of this review down.

FDMA?

I need a bit more background here, just to make use this should be a pure switchdev driver and not a DSA driver.

Quoted 16 lines
Quoted 15 lines

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c line 273

Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +10 -0
+irqreturn_t sparx5_xtr_handler(int irq, void *_sparx5)
+{
+     struct sparx5 *sparx5 = _sparx5;
+
+     /* Check data in queue */
+     while (spx5_rd(sparx5, QS_XTR_DATA_PRESENT) & BIT(XTR_QUEUE))
+             sparx5_xtr_grp(sparx5, XTR_QUEUE, false);
+
+     return IRQ_HANDLED;
+}

Is there any sort of limit how many times this will loop? If somebody is blasting 10Gbps at the CPU, will it ever get out of this loop?

Quoted 2 lines

Hmmm, not at the moment but this is because the FDMA driver is intended to be used in these scenarios.

So throwing out an idea, which might be terrible. How about limiting it to 64 loops, the same as the NAPI poll? That might allow the machine to get some work done before the next interrupt? Does the hardware do interrupt coalescing? But is this is going to be quickly thrown away and replaced with FDMA, don't spend too much time on it.

Andrew

author maintainer
#18 lore raw

Re: [RFC PATCH v2 3/8] net: sparx5: add hostmode with phylink support

Hi Andrew,

Quoted 19 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 16 lines · Steen Hegelund

Hi Andrew,

Quoted 13 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +3 -0
+     /* Create a phylink for PHY management.  Also handles SFPs */
+     spx5_port->phylink_config.dev = &spx5_port->ndev->dev;
+     spx5_port->phylink_co

nfig.type = PHYLINK_NETDEV;

drivers/net/ethernet/microchip/sparx5/sparx5_main.c +5 -0
+     spx5_port->phylink_config.pcs_poll = true;
+
+     /* phylink needs a valid interface mode to parse dt node */
+     if (phy_mode == PHY_INTERFACE_MODE_NA)
+             phy_mode = PHY_INTERFACE_MODE_10GBASER;
Quoted 9 lines
Quoted 4 lines
Quoted 1 line

Maybe just enforce a valid value in DT?

Maybe I need to clarify that you must choose between an Ethernet cuPHY or an SFP, so it is optional.

But you also need to watch out for somebody putting a copper modules in an SFP port. phylink will then set the mode to SGMII for a 1G copper module, etc.

The cuPHY SFPs are handled by phylink out-of-the-box if the kernel has added support for the particular cuPHY driver, and that is done just by specifying the SFP phandle.
So here we just need to know if the user has attached a cuPHY directly or an SFP.

The phylink_of_phy_connect function provides a way to add a cuPHY direcly to the PHYLINK instance, but I have not found a way that you can specify a specific cuPHY embedded in an SFP, so here PHYLINK determines what is the appropriate PHY (driver) to use.

Could this be done in a simpler way?

Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

drivers/net/ethernet/microchip/sparx5/sparx5_main.h struct sparx5 { · line 157

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +5 -0
+/* Configuration */
+static inline bool sparx5_use_cu_phy(struct sparx5_port *port)
+{
+     return port->conf.phy_mode != PHY_INTERFACE_MODE_NA;
+}

That is a rather odd definition of copper.

Should I rather use a bool property to select between the two options (cuPHY or SFP)?

Quoted 7 lines

I guess what you are trying to indicate is between a hard wired Copper PHY and an SFP cage? You have some sort of MII switch which allows the MAC to be connected to either the QSGMII PHY, or an SFP cage? But since the SFP cage could be populated with a copper PHY, and PHYLINK will then instantiate a phylib copper PHY driver for it, looking at phy_mode is not reliable. You need a property which selects the port, not the technology.

Yes the intention was to be able to distinguish between the hardwired cuPHY case and the SFP case.

I am OK with adding a property to distinguish between the two cases, but if the SFP handle is present, PHYLINK has been able to handle an embedded cuPHY (if the driver is available) and use that in the tests that I have done so far. So my thinking was that if a phy handle is present, then the user wants a directly attached cuPHY, not an SFP.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +6 -0
+static int sparx5_port_open(struct net_device *ndev)
+{
+     struct sparx5_port *port = netdev_priv(ndev);
+     int err = 0;
+
+     err = phylink_of_phy_connect(port->phylink, port->of_node,

0);

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c line 81

Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c new file +8 -0
+     if (err) {
+             netdev_err(ndev, "Could not attach to PHY\n");
+             return err;
+     }
+
+     phylink_start(port->phylink);
+
+     if (!ndev->phydev) {

Humm. When is ndev->phydev set? I don't think phylink ever sets it.

Quoted 4 lines
Quoted 2 lines

Indirectly: phylink_of_phy_connect uses phy_attach_direct and that sets the phydev.

Ah, O.K. But watch out for a copper SFP module!

Hmm, my expectation is that we have this covered by now.

Quoted 101 lines
Quoted 101 lines
Quoted 100 lines
Quoted 95 lines

+static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap)

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +3 -0
+{
+     int i, byte_cnt = 0;
+     bool eof_flag = false, pruned_flag = false, abort_flag =

false;

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +19 -0
+     u32 ifh[IFH_LEN];
+     struct sk_buff *skb;
+     struct frame_info fi;
+     struct sparx5_port *port;
+     struct net_device *netdev;
+     u32 *rxbuf;
+
+     /* Get IFH */
+     for (i = 0; i < IFH_LEN; i++)
+             ifh[i] = spx5_rd(sparx5, QS_XTR_RD(grp));
+
+     /* Decode IFH (whats needed) */
+     sparx5_ifh_parse(ifh, &fi);
+
+     /* Map to port netdev */
+     port = fi.src_port < SPX5_PORTS ?
+             sparx5->ports[fi.src_port] : NULL;
+     if (!port || !port->ndev) {
+             dev_err(sparx5->dev, "Data on inactive port %d\n",

fi.src_port);

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +59 -0
+             sparx5_xtr_flush(sparx5, grp);
+             return;
+     }
+
+     /* Have netdev, get skb */
+     netdev = port->ndev;
+     skb = netdev_alloc_skb(netdev, netdev->mtu + ETH_HLEN);
+     if (!skb) {
+             sparx5_xtr_flush(sparx5, grp);
+             dev_err(sparx5->dev, "No skb allocated\n");
+             return;
+     }
+     rxbuf = (u32 *)skb->data;
+
+     /* Now, pull frame data */
+     while (!eof_flag) {
+             u32 val = spx5_rd(sparx5, QS_XTR_RD(grp));
+             u32 cmp = val;
+
+             if (byte_swap)
+                     cmp = ntohl((__force __be32)val);
+
+             switch (cmp) {
+             case XTR_NOT_READY:
+                     break;
+             case XTR_ABORT:
+                     /* No accompanying data */
+                     abort_flag = true;
+                     eof_flag = true;
+                     break;
+             case XTR_EOF_0:
+             case XTR_EOF_1:
+             case XTR_EOF_2:
+             case XTR_EOF_3:
+                     /* This assumes STATUS_WORD_POS == 1, Status
+                      * just after last data
+                      */
+                     byte_cnt -= (4 - XTR_VALID_BYTES(val));
+                     eof_flag = true;
+                     break;
+             case XTR_PRUNED:
+                     /* But get the last 4 bytes as well */
+                     eof_flag = true;
+                     pruned_flag = true;
+                     fallthrough;
+             case XTR_ESCAPE:
+                     *rxbuf = spx5_rd(sparx5, QS_XTR_RD(grp));
+                     byte_cnt += 4;
+                     rxbuf++;
+                     break;
+             default:
+                     *rxbuf = val;
+                     byte_cnt += 4;
+                     rxbuf++;
+             }
+     }
+
+     if (abort_flag || pruned_flag || !eof_flag) {
+             netdev_err(netdev, "Discarded frame: abort:%d

pruned:%d eof:%d\n",

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +7 -0
+                        abort_flag, pruned_flag, eof_flag);
+             kfree_skb(skb);
+             return;
+     }
+
+     if (!netif_oper_up(netdev)) {
+             netdev_err(netdev, "Discarded frame: Interface not

up\n");

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c line 138

Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +3 -0
+             kfree_skb(skb);
+             return;
+     }

Why is it sending frames when it is not up?

Quoted 5 lines
Quoted 2 lines

This is intended for received frames. A situation where the lower layers have been enabled correctly but not the port.

But why should that happen? It suggests you have the order wrong. The lower level should only be enabled once the port is opened.

Yes, on second thought I think this was added to capture an error situation with a particular cuPHY that we were testing. It should be removed now.

Quoted 10 lines
Quoted 8 lines
Quoted 4 lines

No DMA? What sort of performance do you get? Enough for the odd BPDU, IGMP frame etc, but i guess you don't want any real bulk data to be sent this way?

Yes the register based injection/extration is not going to be fast, but the FDMA and its driver is being sent later as separate series to keep the size of this review down.

FDMA?

Ah, I should qualify this a bit more: A "Frame DMA" to transfer rx/tx frames via CPU ports instead of the register based injection/extraction that is in the driver at the moment.

Quoted 4 lines

I need a bit more background here, just to make use this should be a pure switchdev driver and not a DSA driver.

It is not a DSA driver (if I have understood the principle correctly).

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines

drivers/net/ethernet/microchip/sparx5/sparx5_packet.c line 273

Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c new file +10 -0
+irqreturn_t sparx5_xtr_handler(int irq, void *_sparx5)
+{
+     struct sparx5 *sparx5 = _sparx5;
+
+     /* Check data in queue */
+     while (spx5_rd(sparx5, QS_XTR_DATA_PRESENT) & BIT(XTR_QUEUE))
+             sparx5_xtr_grp(sparx5, XTR_QUEUE, false);
+
+     return IRQ_HANDLED;
+}

Is there any sort of limit how many times this will loop? If somebody is blasting 10Gbps at the CPU, will it ever get out of this loop?

Quoted 8 lines
Quoted 2 lines

Hmmm, not at the moment but this is because the FDMA driver is intended to be used in these scenarios.

So throwing out an idea, which might be terrible. How about limiting it to 64 loops, the same as the NAPI poll? That might allow the machine to get some work done before the next interrupt? Does the hardware do interrupt coalescing? But is this is going to be quickly thrown away and replaced with FDMA, don't spend too much time on it.

I agree with you. I will put a cap on the number of loops.

Quoted 2 lines

Andrew

BR
Steen

---------------------------------------
Steen Hegelund
[email protected]

#19 lore raw

Re: [RFC PATCH v2 3/8] net: sparx5: add hostmode with phylink support

In reply to Andrew Lunn
Quoted 9 lines · Andrew Lunn
Quoted 3 lines

Yes the register based injection/extration is not going to be fast, but the FDMA and its driver is being sent later as separate series to keep the size of this review down.

FDMA?

I need a bit more background here, just to make use this should be a pure switchdev driver and not a DSA driver.

I don't think this should be a DSA driver. As for Ocelot, the CPU port is not a MAC and in that use case, this would be like a top of the rack switch with traffic going to the CPU port being mostly used for managmement (dhcp, stp, etc...) as opposed to being used to forward traffic to another interface, like WAN or wifi.

However, I would think there will be cases where the internal CPU is not use and instead use ths switch in a DSA setting, very much like what is done for Felix with regards to Ocelot.

Signature · 3 lines
Alexandre Belloni, Bootlin
Embedded Linux and Kernel engineering
https://bootlin.com
#20 lore raw

Re: [RFC PATCH v2 3/8] net: sparx5: add hostmode with phylink support

Quoted 17 lines · Alexandre Belloni
Quoted 9 lines · Andrew Lunn
Quoted 3 lines

Yes the register based injection/extration is not going to be fast, but the FDMA and its driver is being sent later as separate series to keep the size of this review down.

FDMA?

I need a bit more background here, just to make use this should be a pure switchdev driver and not a DSA driver.

I don't think this should be a DSA driver. As for Ocelot, the CPU port is not a MAC and in that use case, this would be like a top of the rack switch with traffic going to the CPU port being mostly used for managmement (dhcp, stp, etc...) as opposed to being used to forward traffic to another interface, like WAN or wifi.

Quoted 3 lines

However, I would think there will be cases where the internal CPU is not use and instead use ths switch in a DSA setting, very much like what is done for Felix with regards to Ocelot.

From what i have heard so far, it does seem like a pure switchdev driver is correct. So long as FDMA is not a standalone Ethernet driver, but just a DMA engine incorporated into this driver, the architecture looks correct.

I was asking because from the information that was available, it was impossible to say what the correct architecture should be.

Andrew

author maintainer
#21 lore raw

RFC PATCH v2 4/8 net: sparx5: add port module support

In reply to Steen Hegelund

This add configuration of the Sparx5 port module instances.

---
 .../net/ethernet/microchip/sparx5/Makefile    |    3 +-
 .../ethernet/microchip/sparx5/sparx5_main.c   |    9 +
 .../ethernet/microchip/sparx5/sparx5_netdev.c |   14 +-
 .../microchip/sparx5/sparx5_phylink.c         |   37 +-
 .../ethernet/microchip/sparx5/sparx5_port.c   | 1140 +++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_port.h   |   98 ++
 6 files changed, 1292 insertions(+), 9 deletions(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_port.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_port.h
drivers/net/ethernet/microchip/sparx5/Makefile +2 -1
index 19a593d17f4a..9c14eec33fd7 100644
@@ -5,4 +5,5 @@
 
 obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o
 
-sparx5-switch-objs  := sparx5_main.o sparx5_packet.o sparx5_netdev.o sparx5_phylink.o
+sparx5-switch-objs  := sparx5_main.o sparx5_packet.o \
+ sparx5_netdev.o sparx5_port.o sparx5_phylink.o
drivers/net/ethernet/microchip/sparx5/sparx5_main.c +9 -0
index baa108cd99b2..ea75f993f80e 100644
@@ -24,6 +24,7 @@
 #include <linux/types.h>
 
 #include "sparx5_main.h"
+#include "sparx5_port.h"
 
 /* Switch core reset/protect */
 #define RESET_PROT_STAT		0x84
@@ -269,6 +270,14 @@ static int sparx5_probe_port(struct sparx5 *sparx5,
 	spx5_port->conf.speed = SPEED_UNKNOWN;
 	spx5_port->conf.power_down = true;
 	sparx5->ports[portno] = spx5_port;
+
+	err = sparx5_port_init(sparx5, spx5_port, conf);
+	if (err) {
+		dev_err(sparx5->dev, "port init failed\n");
+		return err;
+	}
+	spx5_port->conf = *conf;
+
 	/* Create a phylink for PHY management.  Also handles SFPs */
 	spx5_port->phylink_config.dev = &spx5_port->ndev->dev;
 	spx5_port->phylink_config.type = PHYLINK_NETDEV;
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +12 -2
index 6f9282e9d3f4..98decd1d6f57 100644
@@ -5,6 +5,7 @@
  */
 
 #include "sparx5_main.h"
+#include "sparx5_port.h"
 
 /* The IFH bit position of the first VSTAX bit. This is because the
  * VSTAX bit positions in Data sheet is starting from zero.
@@ -70,6 +71,7 @@ static int sparx5_port_open(struct net_device *ndev)
 	struct sparx5_port *port = netdev_priv(ndev);
 	int err = 0;
 
+	sparx5_port_enable(port, true);
 	err = phylink_of_phy_connect(port->phylink, port->of_node, 0);
 	if (err) {
 		netdev_err(ndev, "Could not attach to PHY\n");
@@ -81,7 +83,10 @@ static int sparx5_port_open(struct net_device *ndev)
 	if (!ndev->phydev) {
 		/* power up serdes */
 		port->conf.power_down = false;
-		err = phy_power_on(port->serdes);
+		if (port->conf.serdes_reset)
+			err = sparx5_serdes_set(port->sparx5, port, &port->conf);
+		else
+			err = phy_power_on(port->serdes);
 		if (err)
 			netdev_err(ndev, "%s failed\n", __func__);
 	}
@@ -94,12 +99,17 @@ static int sparx5_port_stop(struct net_device *ndev)
 	struct sparx5_port *port = netdev_priv(ndev);
 	int err = 0;
 
+	sparx5_port_enable(port, false);
 	phylink_stop(port->phylink);
 	phylink_disconnect_phy(port->phylink);
 
 	if (!ndev->phydev) {
+		/* power down serdes */
 		port->conf.power_down = true;
-		err = phy_power_off(port->serdes);
+		if (port->conf.serdes_reset)
+			err = sparx5_serdes_set(port->sparx5, port, &port->conf);
+		else
+			err = phy_power_off(port->serdes);
 		if (err)
 			netdev_err(ndev, "%s failed\n", __func__);
 	}
drivers/net/ethernet/microchip/sparx5/sparx5_phylink.c +31 -6
index 8166bdedaea1..b474fc29e8df 100644
@@ -11,6 +11,7 @@
 #include <linux/sfp.h>
 
 #include "sparx5_main.h"
+#include "sparx5_port.h"
 
 static void sparx5_phylink_validate(struct phylink_config *config,
 				    unsigned long *supported,
@@ -91,6 +92,7 @@ static void sparx5_phylink_mac_config(struct phylink_config *config,
 {
 	struct sparx5_port *port = netdev_priv(to_net_dev(config->dev));
 	struct sparx5_port_config conf;
+	int err = 0;
 
 	conf = port->conf;
 	conf.power_down = false;
@@ -124,6 +126,11 @@ static void sparx5_phylink_mac_config(struct phylink_config *config,
 
 	if (!port_conf_has_changed(&port->conf, &conf))
 		return;
+
+	/* Enable the PCS matching this interface type */
+	err = sparx5_port_pcs_set(port->sparx5, port, &conf);
+	if (err)
+		netdev_err(port->ndev, "port config failed: %d\n", err);
 }
 
 static void sparx5_phylink_mac_link_up(struct phylink_config *config,
@@ -133,17 +140,35 @@ static void sparx5_phylink_mac_link_up(struct phylink_config *config,
 				       int speed, int duplex,
 				       bool tx_pause, bool rx_pause)
 {
-	/* Currently not used */
+	struct sparx5_port *port = netdev_priv(to_net_dev(config->dev));
+	struct sparx5_port_config conf;
+	int err = 0;
+
+	conf = port->conf;
+	conf.duplex = duplex;
+	conf.pause = 0;
+	conf.pause |= tx_pause ? MLO_PAUSE_TX : 0;
+	conf.pause |= rx_pause ? MLO_PAUSE_RX : 0;
+	conf.speed = speed;
+
+	/* Configure the port to speed/duplex/pause */
+	err = sparx5_port_config(port->sparx5, port, &conf);
+	if (err)
+		netdev_err(port->ndev, "port config failed: %d\n", err);
 }
 
 static void sparx5_phylink_mac_link_state(struct phylink_config *config,
 					  struct phylink_link_state *state)
 {
-	state->link = true;
-	state->an_complete = true;
-	state->speed = SPEED_1000;
-	state->duplex = true;
-	state->pause = MLO_PAUSE_AN;
+	struct sparx5_port *port = netdev_priv(to_net_dev(config->dev));
+	struct sparx5_port_status status;
+
+	sparx5_get_port_status(port->sparx5, port, &status);
+	state->link = status.link && !status.link_down;
+	state->an_complete = status.an_complete;
+	state->speed = status.speed;
+	state->duplex = status.duplex;
+	state->pause = status.pause;
 }
 
 static void sparx5_phylink_mac_aneg_restart(struct phylink_config *config)
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +1140 -0

1,140 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_port.h new file +98 -0

98 lines not on this page · raw message

Signature · 7 lines
2.29.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#22 lore raw

Re: [RFC PATCH v2 4/8] net: sparx5: add port module support

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 58

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +5 -0
+	/* Aneg complete provides more information  */
+	if (DEV2G5_PCS1G_ANEG_STATUS_ANEG_COMPLETE_GET(value)) {
+		if (port->conf.portmode == PHY_INTERFACE_MODE_SGMII) {
+			/* SGMII cisco aneg */
+			u32 spdvalue = ((lp_abil >> 10) & 3);
			u32 spdvalue = lp_abil & LPA_SGMII_SPD_MASK;

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+			status->link = !!((lp_abil >> 15) == 1) && status->link;

Maybe

			status->link = !!((lp_abil & LPA_SGMII_LINK) && status->link;

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 62

Quoted 2 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +2 -0
+			status->an_complete = true;
+			status->duplex = (lp_abil >> 12) & 0x1 ?  DUPLEX_FULL : DUPLEX_HALF;
			status->duplex = (lp_abil & LPA_SGMII_FULL_DUPLEX) ?  DUPLEX_FULL : DUPLEX_HALF;

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 68

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +6 -0
+			if (spdvalue == LPA_SGMII_10)
+				status->speed = SPEED_10;
+			else if (spdvalue == LPA_SGMII_100)
+				status->speed = SPEED_100;
+			else
+				status->speed = SPEED_1000;

I wonder if there is a helper for this?

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 78

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+		} else {
+			/* Clause 37 Aneg */
+			status->link = !((lp_abil >> 12) & 3) && status->link;
+			status->an_complete = true;
+			status->duplex = ((lp_abil >> 5) & 1) ? DUPLEX_FULL : DUPLEX_UNKNOWN;
+			if ((lp_abil >> 8) & 1) /* symmetric pause */
+				status->pause = MLO_PAUSE_RX | MLO_PAUSE_TX;
+			if (lp_abil & (1 << 7)) /* asymmetric pause */
+				status->pause |= MLO_PAUSE_RX;
+		}

Please check if there are any standard #defines you can use for this. Russell King has done some work for clause 37. Maybe there is some code in phy_driver.c you can use? phylink_decode_sgmii_word()

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 241

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+static int sparx5_port_verify_speed(struct sparx5 *sparx5,
+				    struct sparx5_port *port,
+				    struct sparx5_port_config *conf)
+{
+	case PHY_INTERFACE_MODE_SGMII:
+		if (conf->speed != SPEED_1000 &&
+		    conf->speed != SPEED_100 &&
+		    conf->speed != SPEED_10 &&
+		    conf->speed != SPEED_2500)
+			return sparx5_port_error(port, conf, SPX5_PERR_SPEED);

Is it really SGMII over clocked at 2500? Or 2500BaseX?

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 462

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +9 -0
+static int sparx5_port_fifo_sz(struct sparx5 *sparx5,
+			       u32 portno, u32 speed)
+{
+	u32 sys_clk    = sparx5_clk_period(sparx5->coreclock);
+	u32 mac_width  = 8;
+	u32 fifo_width = 16;
+	u32 addition   = 0;
+	u32 mac_per    = 6400, tmp1, tmp2, tmp3;
+	u32 taxi_dist[SPX5_PORTS_ALL] = {

const. As it is at the moment, it gets copied onto the stack, so it can be modified. Const i guess prevents that copy?

drivers/net/ethernet/microchip/sparx5/sparx5_port.c

Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+		6, 8, 10, 6, 8, 10, 6, 8, 10, 6, 8, 10,
+		4, 4, 4, 4,
+		11, 12, 13, 14, 15, 16, 17, 18,
+		11, 12, 13, 14, 15, 16, 17, 18,
+		11, 12, 13, 14, 15, 16, 17, 18,
+		11, 12, 13, 14, 15, 16, 17, 18,
+		4, 6, 8, 4, 6, 8, 6, 8,
+		2, 2, 2, 2, 2, 2, 2, 4, 2
+	};
 
+static int sparx5_port_fwd_urg(struct sparx5 *sparx5, u32 speed)

What is urg?

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 678

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +7 -0
+static u16 sparx5_get_aneg_word(struct sparx5_port_config *conf)
+{
+	if (conf->portmode == PHY_INTERFACE_MODE_1000BASEX) /* cl-37 aneg */
+		return ((1 << 14) | /* ack */
+		((conf->pause ? 1 : 0) << 8) | /* asymmetric pause */
+		((conf->pause ? 1 : 0) << 7) | /* symmetric pause */
+		(1 << 5)); /* FDX only */

ADVERTISE_LPACK, ADVERTISE_PAUSE_ASYM, ADVERTISE_PAUSE_CAP, ADVERTISE_1000XFULL?

Quoted 25 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +25 -0
+int sparx5_port_config(struct sparx5 *sparx5,
+		       struct sparx5_port *port,
+		       struct sparx5_port_config *conf)
+{
+	bool high_speed_dev = sparx5_is_high_speed_device(conf);
+	int err, urgency, stop_wm;
+
+	err = sparx5_port_verify_speed(sparx5, port, conf);
+	if (err)
+		return err;
+
+	/* high speed device is already configured */
+	if (!high_speed_dev)
+		sparx5_port_config_low_set(sparx5, port, conf);
+
+	/* Configure flow control */
+	err = sparx5_port_fc_setup(sparx5, port, conf);
+	if (err)
+		return err;
+
+	/* Set the DSM stop watermark */
+	stop_wm = sparx5_port_fifo_sz(sparx5, port->portno, conf->speed);
+	spx5_rmw(DSM_DEV_TX_STOP_WM_CFG_DEV_TX_STOP_WM_SET(stop_wm),
+		 DSM_DEV_TX_STOP_WM_CFG_DEV_TX_STOP_WM,
+		 sparx5,

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 989

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+		 DSM_DEV_TX_STOP_WM_CFG(port->portno));
+
+	/* Enable port forwarding */
+	urgency = sparx5_port_fwd_urg(sparx5, conf->speed);
+	spx5_rmw(QFWD_SWITCH_PORT_MODE_PORT_ENA_SET(1) |
+		 QFWD_SWITCH_PORT_MODE_FWD_URGENCY_SET(urgency),
+		 QFWD_SWITCH_PORT_MODE_PORT_ENA |
+		 QFWD_SWITCH_PORT_MODE_FWD_URGENCY,
+		 sparx5,
+		 QFWD_SWITCH_PORT_MODE(port->portno));

What does it mean by port forwarding? By default, packets should only go to the CPU, until the port is added to a bridge. I've not thought much about L3, since DSA so far only has L2 switches, but i guess you don't need to enable L3 forwarding until a route out the port has been added?

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 1065

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +7 -0
+/* Initialize port config to default */
+int sparx5_port_init(struct sparx5 *sparx5,
+		     struct sparx5_port *port,
+		     struct sparx5_port_config *conf)
+{
+	/* Discard pause frame 01-80-C2-00-00-01 */
+	spx5_wr(0xC, sparx5, ANA_CL_CAPTURE_BPDU_CFG(port->portno));

The comment is about pause frames, but the macro contain BPDU?

Andrew

#23 lore raw

Re: [RFC PATCH v2 4/8] net: sparx5: add port module support

Quoted 19 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 58

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +3 -0
+     /* Aneg complete provides more information  */
+     if (DEV2G5_PCS1G_ANEG_STATUS_ANEG_COMPLETE_GET(value)) {
+             if (port->conf.portmode == PHY_INTERFACE_MODE_SGMII)

{

drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +2 -0
+                     /* SGMII cisco aneg */
+                     u32 spdvalue = ((lp_abil >> 10) & 3);
                        u32 spdvalue = lp_abil & LPA_SGMII_SPD_MASK;
Quoted 3 lines
(quoted diff) +2 -0
+
+                     status->link = !!((lp_abil >> 15) == 1) &&

status->link;

Maybe

                        status->link = !!((lp_abil & LPA_SGMII_LINK)
Quoted 8 lines

&& status->link;

Quoted 3 lines
(quoted diff) +2 -0
+                     status->an_complete = true;
+                     status->duplex = (lp_abil >> 12) & 0x1

? DUPLEX_FULL : DUPLEX_HALF;

                        status->duplex = (lp_abil &

LPA_SGMII_FULL_DUPLEX) ? DUPLEX_FULL : DUPLEX_HALF;

Yes, changed to use the SGMII macroes.

Quoted 27 lines

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 68

Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +6 -0
+                     if (spdvalue == LPA_SGMII_10)
+                             status->speed = SPEED_10;
+                     else if (spdvalue == LPA_SGMII_100)
+                             status->speed = SPEED_100;
+                     else
+                             status->speed = SPEED_1000;

I wonder if there is a helper for this?

Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +3 -0
+             } else {
+                     /* Clause 37 Aneg */
+                     status->link = !((lp_abil >> 12) & 3) &&

status->link;

(quoted diff) +2 -0
+                     status->an_complete = true;
+                     status->duplex = ((lp_abil >> 5) & 1) ?

DUPLEX_FULL : DUPLEX_UNKNOWN;

(quoted diff) +2 -0
+                     if ((lp_abil >> 8) & 1) /* symmetric pause */
+                             status->pause = MLO_PAUSE_RX |

MLO_PAUSE_TX;
+ if (lp_abil & (1 << 7)) /* asymmetric pause
*/

Review

Quoted 2 lines
(quoted diff) +2 -0
+                             status->pause |= MLO_PAUSE_RX;
+             }
Quoted 3 lines

Please check if there are any standard #defines you can use for this. Russell King has done some work for clause 37. Maybe there is some code in phy_driver.c you can use? phylink_decode_sgmii_word()

There are the ADVERTISE_* macroes in mii.h.
I've changed the code to use them.

Quoted 14 lines
Quoted 11 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+static int sparx5_port_verify_speed(struct sparx5 *sparx5,
+                                 struct sparx5_port *port,
+                                 struct sparx5_port_config *conf)
+{
+     case PHY_INTERFACE_MODE_SGMII:
+             if (conf->speed != SPEED_1000 &&
+                 conf->speed != SPEED_100 &&
+                 conf->speed != SPEED_10 &&
+                 conf->speed != SPEED_2500)
+                     return sparx5_port_error(port, conf,
Quoted 1 line

SPX5_PERR_SPEED);

Is it really SGMII over clocked at 2500? Or 2500BaseX?

Yes the SGMII mode in the serdes driver is overclocked. Nothing in the switch driver needs changing when changing between speeds 1G/2G5.

Quoted 24 lines

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 462

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +9 -0
+static int sparx5_port_fifo_sz(struct sparx5 *sparx5,
+                            u32 portno, u32 speed)
+{
+     u32 sys_clk    = sparx5_clk_period(sparx5->coreclock);
+     u32 mac_width  = 8;
+     u32 fifo_width = 16;
+     u32 addition   = 0;
+     u32 mac_per    = 6400, tmp1, tmp2, tmp3;
+     u32 taxi_dist[SPX5_PORTS_ALL] = {

const. As it is at the moment, it gets copied onto the stack, so it can be modified. Const i guess prevents that copy?

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+             6, 8, 10, 6, 8, 10, 6, 8, 10, 6, 8, 10,
+             4, 4, 4, 4,
+             11, 12, 13, 14, 15, 16, 17, 18,
+             11, 12, 13, 14, 15, 16, 17, 18,
+             11, 12, 13, 14, 15, 16, 17, 18,
+             11, 12, 13, 14, 15, 16, 17, 18,
+             4, 6, 8, 4, 6, 8, 6, 8,
+             2, 2, 2, 2, 2, 2, 2, 4, 2
+     };
+static int sparx5_port_fwd_urg(struct sparx5 *sparx5, u32 speed)

Changed to const.

Quoted 2 lines

What is urg?

urg=urgency (taken directly from the name in the asic). Another name for speed, or actually how many clockcycles can go by before the port instance must be served.

Quoted 12 lines

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 678

Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +3 -0
+static u16 sparx5_get_aneg_word(struct sparx5_port_config *conf)
+{
+     if (conf->portmode == PHY_INTERFACE_MODE_1000BASEX) /* cl-37

aneg */

drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +4 -0
+             return ((1 << 14) | /* ack */
+             ((conf->pause ? 1 : 0) << 8) | /* asymmetric pause */
+             ((conf->pause ? 1 : 0) << 7) | /* symmetric pause */
+             (1 << 5)); /* FDX only */

ADVERTISE_LPACK, ADVERTISE_PAUSE_ASYM, ADVERTISE_PAUSE_CAP, ADVERTISE_1000XFULL?

Yes, applied.

Quoted 38 lines
Quoted 27 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +22 -0
+int sparx5_port_config(struct sparx5 *sparx5,
+                    struct sparx5_port *port,
+                    struct sparx5_port_config *conf)
+{
+     bool high_speed_dev = sparx5_is_high_speed_device(conf);
+     int err, urgency, stop_wm;
+
+     err = sparx5_port_verify_speed(sparx5, port, conf);
+     if (err)
+             return err;
+
+     /* high speed device is already configured */
+     if (!high_speed_dev)
+             sparx5_port_config_low_set(sparx5, port, conf);
+
+     /* Configure flow control */
+     err = sparx5_port_fc_setup(sparx5, port, conf);
+     if (err)
+             return err;
+
+     /* Set the DSM stop watermark */
+     stop_wm = sparx5_port_fifo_sz(sparx5, port->portno, conf-
Quoted 1 line

speed);

drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +3 -0
+     spx5_rmw(DSM_DEV_TX_STOP_WM_CFG_DEV_TX_STOP_WM_SET(stop_wm),
+              DSM_DEV_TX_STOP_WM_CFG_DEV_TX_STOP_WM,
+              sparx5,

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 989

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +10 -0
+              DSM_DEV_TX_STOP_WM_CFG(port->portno));
+
+     /* Enable port forwarding */
+     urgency = sparx5_port_fwd_urg(sparx5, conf->speed);
+     spx5_rmw(QFWD_SWITCH_PORT_MODE_PORT_ENA_SET(1) |
+              QFWD_SWITCH_PORT_MODE_FWD_URGENCY_SET(urgency),
+              QFWD_SWITCH_PORT_MODE_PORT_ENA |
+              QFWD_SWITCH_PORT_MODE_FWD_URGENCY,
+              sparx5,
+              QFWD_SWITCH_PORT_MODE(port->portno));
Quoted 6 lines

What does it mean by port forwarding? By default, packets should only go to the CPU, until the port is added to a bridge. I've not thought much about L3, since DSA so far only has L2 switches, but i guess you don't need to enable L3 forwarding until a route out the port has been
added?

This mean that the port is enabled in the queue system - not that it can participate in switching. When the port joins the bridge, then forwarding masks will enable swithcing.
I've changed the comment to "Enable port in queue system"

Quoted 10 lines

drivers/net/ethernet/microchip/sparx5/sparx5_port.c line 1065

Quoted 8 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +7 -0
+/* Initialize port config to default */
+int sparx5_port_init(struct sparx5 *sparx5,
+                  struct sparx5_port *port,
+                  struct sparx5_port_config *conf)
+{
+     /* Discard pause frame 01-80-C2-00-00-01 */
+     spx5_wr(0xC, sparx5, ANA_CL_CAPTURE_BPDU_CFG(port->portno));

The comment is about pause frames, but the macro contain BPDU?

The "0xC" is a 2 bit field that chooses what to do with the second BPDU with the address 01-80-C2-00-00-01 (0x3 chooses the first 01-80-C2-00- 00-00, and 0x300 chooses the third 01-80-C2-00-00-02, etc..). Both bits high means discard.
I've change the 0xC to a macro called "PAUSE_DISCARD"

Quoted 2 lines

Andrew

Thanks
Bjarni Jonasson
Microchip

#24 lore raw

Re: [RFC PATCH v2 4/8] net: sparx5: add port module support

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +5 -0
+static int sparx5_port_verify_speed(struct sparx5 *sparx5,
+                                 struct sparx5_port *port,
+                                 struct sparx5_port_config *conf)
+{
+     case PHY_INTERFACE_MODE_SGMII:
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_port.c new file +5 -0
+             if (conf->speed != SPEED_1000 &&
+                 conf->speed != SPEED_100 &&
+                 conf->speed != SPEED_10 &&
+                 conf->speed != SPEED_2500)
+                     return sparx5_port_error(port, conf,

SPX5_PERR_SPEED);

Is it really SGMII over clocked at 2500? Or 2500BaseX?

Quoted 3 lines

Yes the SGMII mode in the serdes driver is overclocked. Nothing in the switch driver needs changing when changing between speeds 1G/2G5.

So it continues to use the SGMII inband signalling?

There is a lot of confusion in this area, but SGMII inband signalling overclocked does not make much sense. So it is more likely to be using 2500BaseX.

Andrew

author maintainer
#25 lore raw

RFC PATCH v2 5/8 net: sparx5: add switching, vlan and mactable support

In reply to Steen Hegelund

This adds SwitchDev support by hardware offloading the SW bridge and setting up the Sparx5 MAC/VLAN tables, and listening for MAC table updates.

---
 .../net/ethernet/microchip/sparx5/Makefile    |   3 +-
 .../microchip/sparx5/sparx5_mactable.c        | 502 +++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_main.c   |  32 ++
 .../ethernet/microchip/sparx5/sparx5_main.h   |  51 ++
 .../ethernet/microchip/sparx5/sparx5_netdev.c |  31 ++
 .../ethernet/microchip/sparx5/sparx5_packet.c |   6 +
 .../microchip/sparx5/sparx5_switchdev.c       | 516 ++++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_vlan.c   | 223 ++++++++
 8 files changed, 1363 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c
drivers/net/ethernet/microchip/sparx5/Makefile +2 -1
index 9c14eec33fd7..32e0691e328a 100644
@@ -5,5 +5,6 @@
 
 obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o
 
-sparx5-switch-objs  := sparx5_main.o sparx5_packet.o \
+sparx5-switch-objs  := sparx5_main.o sparx5_switchdev.o \
+ sparx5_vlan.o sparx5_mactable.o sparx5_packet.o \
  sparx5_netdev.o sparx5_port.o sparx5_phylink.o
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +502 -0

502 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_main.c +32 -0
index ea75f993f80e..30940d9ee916 100644
@@ -278,6 +278,9 @@ static int sparx5_probe_port(struct sparx5 *sparx5,
 	}
 	spx5_port->conf = *conf;
 
+	/* Setup VLAN */
+	sparx5_vlan_port_setup(sparx5, spx5_port->portno);
+
 	/* Create a phylink for PHY management.  Also handles SFPs */
 	spx5_port->phylink_config.dev = &spx5_port->ndev->dev;
 	spx5_port->phylink_config.type = PHYLINK_NETDEV;
@@ -532,6 +535,7 @@ static int sparx5_qlim_set(struct sparx5 *sparx5)
 
 static int sparx5_init(struct sparx5 *sparx5)
 {
+	u8 broadcast[ETH_ALEN] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
 	int irq, ret;
 	u32 idx;
 
@@ -582,6 +586,9 @@ static int sparx5_init(struct sparx5 *sparx5)
 			 QFWD_SWITCH_PORT_MODE(idx));
 	}
 
+	/* Init masks */
+	sparx5_update_fwd(sparx5);
+
 	/* CPU copy CPU pgids */
 	spx5_wr(ANA_AC_PGID_MISC_CFG_PGID_CPU_COPY_ENA_SET(1),
 		sparx5, ANA_AC_PGID_MISC_CFG(PGID_CPU));
@@ -594,6 +601,15 @@ static int sparx5_init(struct sparx5 *sparx5)
 			 ANA_CL_FILTER_CTRL_FORCE_FCS_UPDATE_ENA,
 			 sparx5, ANA_CL_FILTER_CTRL(idx));
 
+	/* Init MAC table, ageing */
+	sparx5_mact_init(sparx5);
+
+	/* Setup VLANs */
+	sparx5_vlan_init(sparx5);
+
+	/* Add host mode BC address (points only to CPU) */
+	sparx5_mact_learn(sparx5, PGID_CPU, broadcast, NULL_VID);
+
 	/* Enable queue limitation watermarks */
 	sparx5_qlim_set(sparx5);
 
@@ -647,6 +663,7 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 	struct device_node *ports, *portnp;
 	const u8 *mac_addr;
 	int err = 0;
+	char queue_name[32];
 
 	if (!np && !pdev->dev.platform_data)
 		return -ENODEV;
@@ -726,11 +743,24 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 			goto cleanup_ports;
 		}
 	}
+	/* Init mact_sw struct */
+	mutex_init(&sparx5->mact_lock);
+	INIT_LIST_HEAD(&sparx5->mact_entries);
+	snprintf(queue_name, sizeof(queue_name), "%s-mact",
+		 dev_name(sparx5->dev));
+	sparx5->mact_queue = create_singlethread_workqueue(queue_name);
+	INIT_DELAYED_WORK(&sparx5->mact_work, sparx5_mact_pull_work);
+	queue_delayed_work(sparx5->mact_queue, &sparx5->mact_work,
+			   SPX5_MACT_PULL_DELAY);
+
 	err = sparx5_register_netdevs(sparx5);
 	if (err)
 		goto cleanup_ports;
 
 	sparx5_board_init(sparx5);
+	err = sparx5_register_notifier_blocks(sparx5);
+	if (err)
+		goto cleanup_ports;
 
 	return err;
 
@@ -744,6 +774,8 @@ static int mchp_sparx5_remove(struct platform_device *pdev)
 	struct sparx5 *sparx5 = platform_get_drvdata(pdev);
 
 	sparx5_cleanup_ports(sparx5);
+	/* Unregister netdevs */
+	sparx5_unregister_notifier_blocks(sparx5);
 
 	return 0;
 }
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +51 -0

69 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +31 -0
index 98decd1d6f57..a0992443ab9f 100644
@@ -116,6 +116,15 @@ static int sparx5_port_stop(struct net_device *ndev)
 	return 0;
 }
 
+static void sparx5_set_rx_mode(struct net_device *dev)
+{
+	struct sparx5_port *port = netdev_priv(dev);
+	struct sparx5 *sparx5 = port->sparx5;
+
+	if (!test_bit(port->portno, sparx5->bridge_mask))
+		__dev_mc_sync(dev, sparx5_mc_sync, sparx5_mc_unsync);
+}
+
 static int sparx5_port_get_phys_port_name(struct net_device *dev,
 					  char *buf, size_t len)
 {
@@ -131,21 +140,43 @@ static int sparx5_port_get_phys_port_name(struct net_device *dev,
 
 static int sparx5_set_mac_address(struct net_device *dev, void *p)
 {
+	struct sparx5_port *port = netdev_priv(dev);
+	struct sparx5 *sparx5 = port->sparx5;
 	const struct sockaddr *addr = p;
 
+	/* Remove current */
+	sparx5_mact_forget(sparx5, dev->dev_addr,  port->pvid);
+
+	/* Add new */
+	sparx5_mact_learn(sparx5, PGID_CPU, addr->sa_data, port->pvid);
+
 	/* Record the address */
 	ether_addr_copy(dev->dev_addr, addr->sa_data);
 
 	return 0;
 }
 
+static int sparx5_get_port_parent_id(struct net_device *dev,
+				     struct netdev_phys_item_id *ppid)
+{
+	struct sparx5_port *sparx5_port = netdev_priv(dev);
+	struct sparx5 *sparx5 = sparx5_port->sparx5;
+
+	ppid->id_len = sizeof(sparx5->base_mac);
+	memcpy(&ppid->id, &sparx5->base_mac, ppid->id_len);
+
+	return 0;
+}
+
 static const struct net_device_ops sparx5_port_netdev_ops = {
 	.ndo_open               = sparx5_port_open,
 	.ndo_stop               = sparx5_port_stop,
 	.ndo_start_xmit         = sparx5_port_xmit_impl,
+	.ndo_set_rx_mode        = sparx5_set_rx_mode,
 	.ndo_get_phys_port_name = sparx5_port_get_phys_port_name,
 	.ndo_set_mac_address    = sparx5_set_mac_address,
 	.ndo_validate_addr      = eth_validate_addr,
+	.ndo_get_port_parent_id = sparx5_get_port_parent_id,
 };
 
 bool sparx5_netdevice_check(const struct net_device *dev)
drivers/net/ethernet/microchip/sparx5/sparx5_packet.c +6 -0
index 209eef5c6385..c4b1d89d2204 100644
@@ -143,6 +143,12 @@ static void sparx5_xtr_grp(struct sparx5 *sparx5, u8 grp, bool byte_swap)
 		return;
 	}
 
+	/* Everything we see on an interface that is in the HW bridge
+	 * has already been forwarded
+	 */
+	if (test_bit(port->portno, sparx5->bridge_mask))
+		skb->offload_fwd_mark = 1;
+
 	/* Finish up skb */
 	skb_put(skb, byte_cnt - ETH_FCS_LEN);
 	eth_skb_pad(skb);
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +516 -0

516 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +223 -0

223 lines not on this page · raw message

Signature · 7 lines
2.29.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#26 lore raw

Re: [RFC PATCH v2 5/8] net: sparx5: add switching, vlan and mactable support

Quoted 6 lines

+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +5 -0
+
+static inline int sparx5_mact_get_status(struct sparx5 *sparx5)
+{
+	return spx5_rd(sparx5, LRN_COMMON_ACCESS_CTRL);
+}

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c line 55

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +10 -0
+
+static inline int sparx5_mact_wait_for_completion(struct sparx5 *sparx5)
+{
+	u32 val;
+
+	return readx_poll_timeout(sparx5_mact_get_status,
+		sparx5, val,
+		LRN_COMMON_ACCESS_CTRL_MAC_TABLE_ACCESS_SHOT_GET(val) == 0,
+		TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
+}

No inline functions in C files please.

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +5 -0
+void sparx5_mact_init(struct sparx5 *sparx5)
+{
+	mutex_init(&sparx5->lock);
+
+	mutex_lock(&sparx5->lock);

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c line 499

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +10 -0
+
+	/*  Flush MAC table */
+	spx5_wr(LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_CMD_SET(MAC_CMD_CLEAR_ALL) |
+		LRN_COMMON_ACCESS_CTRL_MAC_TABLE_ACCESS_SHOT_SET(1),
+		sparx5, LRN_COMMON_ACCESS_CTRL);
+
+	if (sparx5_mact_wait_for_completion(sparx5) != 0)
+		dev_warn(sparx5->dev, "MAC flush error\n");
+
+	mutex_unlock(&sparx5->lock);

It always seems odd to me, when you initialise a mutex, and then immediately take it. Who are you locking against? I'm not saying it is wrong though, especially if you have code in spx5_wr() and spx5_rd() which check the lock is actually taken. I've found a number of locking bugs in mv88e6xxx by having such checks.

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c line 501

Quoted 2 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +2 -0
+
+	sparx5_set_ageing(sparx5, 10 * MSEC_PER_SEC); /* 10 sec */

BR_DEFAULT_AGEING_TIME is 300 seconds. Is this the same thing?

Quoted 4 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +4 -0
+static int sparx5_port_bridge_join(struct sparx5_port *port,
+				   struct net_device *bridge)
+{
+	struct sparx5 *sparx5 = port->sparx5;

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c line 110

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +10 -0
+
+	if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS))
+		/* First bridged port */
+		sparx5->hw_bridge_dev = bridge;
+	else
+		if (sparx5->hw_bridge_dev != bridge)
+			/* This is adding the port to a second bridge, this is
+			 * unsupported
+			 */
+			return -ENODEV;

Just checking my understanding. You have a 64 port switch, which only supports a single bridge?

-EOPNOTSUPP seems like a better return code.

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c line 117

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +7 -0
+
+	set_bit(port->portno, sparx5->bridge_mask);
+
+	/* Port enters in bridge mode therefor don't need to copy to CPU
+	 * frames for multicast in case the bridge is not requesting them
+	 */
+	__dev_mc_unsync(port->ndev, sparx5_mc_unsync);

Did you copy that from the mellanox driver? I think in DSA we take the opposite approach. Multicast/broadcast goes to the CPU until the CPU says it does not want it.

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +5 -0
+static void sparx5_port_bridge_leave(struct sparx5_port *port,
+				     struct net_device *bridge)
+{
+	struct sparx5 *sparx5 = port->sparx5;
+

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c line 136

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +10 -0
+	clear_bit(port->portno, sparx5->bridge_mask);
+	if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS))
+		sparx5->hw_bridge_dev = NULL;
+
+	/* Clear bridge vlan settings before updating the port settings */
+	port->vlan_aware = 0;
+	port->pvid = NULL_VID;
+	port->vid = NULL_VID;
+
+	/* Port enters in host more therefore restore mc list */

s/more/mode

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c line 9

Quoted 11 lines

+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +9 -0
@@ -0,0 +1,223 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Microchip Sparx5 Switch driver
+ *
+ * Copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
+ */
+
+#include "sparx5_main.h"
+
+static int sparx5_vlant_set_mask(struct sparx5 *sparx5, u16 vid)

Is the t in vlant typ0?

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +7 -0
+int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,
+			bool untagged)
+{
+	struct sparx5 *sparx5 = port->sparx5;
+	int ret;
+
+	/* Make the port a member of the VLAN */

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c line 70

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +10 -0
+	set_bit(port->portno, sparx5->vlan_mask[vid]);
+	ret = sparx5_vlant_set_mask(sparx5, vid);
+	if (ret)
+		return ret;
+
+	/* Default ingress vlan classification */
+	if (pvid)
+		port->pvid = vid;
+
+	/* Untagged egress vlan clasification */

classification

Quoted 37 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +35 -0
+	if (untagged && port->vid != vid) {
+		if (port->vid) {
+			netdev_err(port->ndev,
+				   "Port already has a native VLAN: %d\n",
+				   port->vid);
+			return -EBUSY;
+		}
+		port->vid = vid;
+	}
+
+	sparx5_vlan_port_apply(sparx5, port);
+
+	return 0;
+}
 
 
+void sparx5_update_fwd(struct sparx5 *sparx5)
+{
+	u32 mask[3];
+	DECLARE_BITMAP(workmask, SPX5_PORTS);
+	int port;
+
+	/* Divide up fwd mask in 32 bit words */
+	bitmap_to_arr32(mask, sparx5->bridge_fwd_mask, SPX5_PORTS);
+
+	/* Update flood masks */
+	for (port = PGID_UC_FLOOD; port <= PGID_BCAST; port++) {
+		spx5_wr(mask[0], sparx5, ANA_AC_PGID_CFG(port));
+		spx5_wr(mask[1], sparx5, ANA_AC_PGID_CFG1(port));
+		spx5_wr(mask[2], sparx5, ANA_AC_PGID_CFG2(port));
+	}
+
+	/* Update SRC masks */
+	for (port = 0; port < SPX5_PORTS; port++) {
+		if (test_bit(port, sparx5->bridge_fwd_mask)) {
+			/* Allow to send to all bridged but self */
+			bitmap_copy(workmask, sparx5->bridge_fwd_mask, SPX5_PORTS);

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c line 170

Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +10 -0
+			clear_bit(port, workmask);
+			bitmap_to_arr32(mask, workmask, SPX5_PORTS);
+			spx5_wr(mask[0], sparx5, ANA_AC_SRC_CFG(port));
+			spx5_wr(mask[1], sparx5, ANA_AC_SRC_CFG1(port));
+			spx5_wr(mask[2], sparx5, ANA_AC_SRC_CFG2(port));
+		} else {
+			spx5_wr(0, sparx5, ANA_AC_SRC_CFG(port));
+			spx5_wr(0, sparx5, ANA_AC_SRC_CFG1(port));
+			spx5_wr(0, sparx5, ANA_AC_SRC_CFG2(port));
+		}

Humm, interesting. This seems to control what other ports a port can send to. That is one of the basic features you need for supporting multiple bridges. So i assume your problems is you cannot partition the MAC table?

Andrew

author maintainer
#27 lore raw

Re: [RFC PATCH v2 5/8] net: sparx5: add switching, vlan and mactable support

Hi Andrew,

Quoted 12 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

Quoted 10 lines

+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +9 -0
+
+static inline int sparx5_mact_get_status(struct sparx5 *sparx5)
+{
+     return spx5_rd(sparx5, LRN_COMMON_ACCESS_CTRL);
+}
+
+static inline int sparx5_mact_wait_for_completion(struct sparx5 *sparx5)
+{
+     u32 val;
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c line 55

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +6 -0
+
+     return readx_poll_timeout(sparx5_mact_get_status,
+             sparx5, val,
+             LRN_COMMON_ACCESS_CTRL_MAC_TABLE_ACCESS_SHOT_GET(val) == 0,
+             TABLE_UPDATE_SLEEP_US, TABLE_UPDATE_TIMEOUT_US);
+}

No inline functions in C files please.

OK.

Quoted 14 lines
Quoted 14 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +13 -0
+void sparx5_mact_init(struct sparx5 *sparx5)
+{
+     mutex_init(&sparx5->lock);
+
+     mutex_lock(&sparx5->lock);
+
+     /*  Flush MAC table */
+     spx5_wr(LRN_COMMON_ACCESS_CTRL_CPU_ACCESS_CMD_SET(MAC_CMD_CLEAR_ALL) |
+             LRN_COMMON_ACCESS_CTRL_MAC_TABLE_ACCESS_SHOT_SET(1),
+             sparx5, LRN_COMMON_ACCESS_CTRL);
+
+     if (sparx5_mact_wait_for_completion(sparx5) != 0)
+             dev_warn(sparx5->dev, "MAC flush error\n");
Quoted 8 lines

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+     mutex_unlock(&sparx5->lock);

It always seems odd to me, when you initialise a mutex, and then immediately take it. Who are you locking against? I'm not saying it is wrong though, especially if you have code in spx5_wr() and spx5_rd() which check the lock is actually taken. I've found a number of locking bugs in mv88e6xxx by having such checks.

The driver has a workqueue and a notifier callback that may want to access the table, and will have to wait in line to be served, but since they have not yet been activated at this point, you are probably correct in saying that locking is not needed at init time.
I will investigate this..

Quoted 5 lines

drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c line 501

Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_mactable.c new file +2 -0
+
+     sparx5_set_ageing(sparx5, 10 * MSEC_PER_SEC); /* 10 sec */

BR_DEFAULT_AGEING_TIME is 300 seconds. Is this the same thing?

Same thing but different value. I think this should change to same default, but I will test it out.

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +9 -0
+static int sparx5_port_bridge_join(struct sparx5_port *port,
+                                struct net_device *bridge)
+{
+     struct sparx5 *sparx5 = port->sparx5;
+
+     if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS))
+             /* First bridged port */
+             sparx5->hw_bridge_dev = bridge;
+     else
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c line 110

Quoted 5 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +5 -0
+             if (sparx5->hw_bridge_dev != bridge)
+                     /* This is adding the port to a second bridge, this is
+                      * unsupported
+                      */
+                     return -ENODEV;

Just checking my understanding. You have a 64 port switch, which only supports a single bridge?

Yes, at least for the initial version. The switch has some virtualization features, but were not using that just yet.

Quoted 16 lines

-EOPNOTSUPP seems like a better return code.

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c line 117

Quoted 7 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +7 -0
+
+     set_bit(port->portno, sparx5->bridge_mask);
+
+     /* Port enters in bridge mode therefor don't need to copy to CPU
+      * frames for multicast in case the bridge is not requesting them
+      */
+     __dev_mc_unsync(port->ndev, sparx5_mc_unsync);

Did you copy that from the mellanox driver? I think in DSA we take the opposite approach. Multicast/broadcast goes to the CPU until the CPU says it does not want it.

It is "inspired" by the Ocelot driver. MC is explicitly opted in.

Quoted 9 lines
Quoted 9 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +9 -0
+static void sparx5_port_bridge_leave(struct sparx5_port *port,
+                                  struct net_device *bridge)
+{
+     struct sparx5 *sparx5 = port->sparx5;
+
+     clear_bit(port->portno, sparx5->bridge_mask);
+     if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS))
+             sparx5->hw_bridge_dev = NULL;
+
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c line 136

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c new file +6 -0
+     /* Clear bridge vlan settings before updating the port settings */
+     port->vlan_aware = 0;
+     port->pvid = NULL_VID;
+     port->vid = NULL_VID;
+
+     /* Port enters in host more therefore restore mc list */

s/more/mode

OK.

Quoted 14 lines

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c line 9

Quoted 12 lines

+++ b/drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +9 -0
@@ -0,0 +1,223 @@
+// SPDX-License-Identifier: GPL-2.0+
+/* Microchip Sparx5 Switch driver
+ *
+ * Copyright (c) 2020 Microchip Technology Inc. and its subsidiaries.
+ */
+
+#include "sparx5_main.h"
+
+static int sparx5_vlant_set_mask(struct sparx5 *sparx5, u16 vid)

Is the t in vlant typ0?

No, it is probably short for "vlan table". Again the inspiration comes from the Ocelot implementation.

Quoted 12 lines
Quoted 12 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +11 -0
+int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,
+                     bool untagged)
+{
+     struct sparx5 *sparx5 = port->sparx5;
+     int ret;
+
+     /* Make the port a member of the VLAN */
+     set_bit(port->portno, sparx5->vlan_mask[vid]);
+     ret = sparx5_vlant_set_mask(sparx5, vid);
+     if (ret)
+             return ret;
Quoted 8 lines

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c line 70

Quoted 6 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +6 -0
+
+     /* Default ingress vlan classification */
+     if (pvid)
+             port->pvid = vid;
+
+     /* Untagged egress vlan clasification */

classification

OK.

Quoted 45 lines
Quoted 45 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +42 -0
+     if (untagged && port->vid != vid) {
+             if (port->vid) {
+                     netdev_err(port->ndev,
+                                "Port already has a native VLAN: %d\n",
+                                port->vid);
+                     return -EBUSY;
+             }
+             port->vid = vid;
+     }
+
+     sparx5_vlan_port_apply(sparx5, port);
+
+     return 0;
+}
 
 
+void sparx5_update_fwd(struct sparx5 *sparx5)
+{
+     u32 mask[3];
+     DECLARE_BITMAP(workmask, SPX5_PORTS);
+     int port;
+
+     /* Divide up fwd mask in 32 bit words */
+     bitmap_to_arr32(mask, sparx5->bridge_fwd_mask, SPX5_PORTS);
+
+     /* Update flood masks */
+     for (port = PGID_UC_FLOOD; port <= PGID_BCAST; port++) {
+             spx5_wr(mask[0], sparx5, ANA_AC_PGID_CFG(port));
+             spx5_wr(mask[1], sparx5, ANA_AC_PGID_CFG1(port));
+             spx5_wr(mask[2], sparx5, ANA_AC_PGID_CFG2(port));
+     }
+
+     /* Update SRC masks */
+     for (port = 0; port < SPX5_PORTS; port++) {
+             if (test_bit(port, sparx5->bridge_fwd_mask)) {
+                     /* Allow to send to all bridged but self */
+                     bitmap_copy(workmask, sparx5->bridge_fwd_mask, SPX5_PORTS);
+                     clear_bit(port, workmask);
+                     bitmap_to_arr32(mask, workmask, SPX5_PORTS);
+                     spx5_wr(mask[0], sparx5, ANA_AC_SRC_CFG(port));
+                     spx5_wr(mask[1], sparx5, ANA_AC_SRC_CFG1(port));
+                     spx5_wr(mask[2], sparx5, ANA_AC_SRC_CFG2(port));
+             } else {
+                     spx5_wr(0, sparx5, ANA_AC_SRC_CFG(port));
Quoted 9 lines

drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c line 170

Quoted 3 lines
drivers/net/ethernet/microchip/sparx5/sparx5_vlan.c new file +3 -0
+                     spx5_wr(0, sparx5, ANA_AC_SRC_CFG1(port));
+                     spx5_wr(0, sparx5, ANA_AC_SRC_CFG2(port));
+             }

Humm, interesting. This seems to control what other ports a port can send to. That is one of the basic features you need for supporting multiple bridges. So i assume your problems is you cannot partition the MAC table?

No, the MAC table is VLAN aware.

Quoted 2 lines

Andrew

BR
Steen

---------------------------------------
Steen Hegelund
[email protected]

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

author maintainer
#28 lore raw

RFC PATCH v2 6/8 net: sparx5: add calendar bandwidth allocation support

In reply to Steen Hegelund

This configures the Sparx5 calendars according to the bandwidth requested in the Device Tree nodes.
It also checks if the total requested bandwidth is within the specs of the detected Sparx5 models limits.

---
 .../net/ethernet/microchip/sparx5/Makefile    |   2 +-
 .../microchip/sparx5/sparx5_calendar.c        | 595 ++++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_main.c   |   8 +
 .../ethernet/microchip/sparx5/sparx5_main.h   |   4 +
 4 files changed, 608 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_calendar.c
drivers/net/ethernet/microchip/sparx5/Makefile +1 -1
index 32e0691e328a..17654ab90ce1 100644
@@ -7,4 +7,4 @@ obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o
 
 sparx5-switch-objs  := sparx5_main.o sparx5_switchdev.o \
  sparx5_vlan.o sparx5_mactable.o sparx5_packet.o \
- sparx5_netdev.o sparx5_port.o sparx5_phylink.o
+ sparx5_netdev.o sparx5_port.o sparx5_phylink.o sparx5_calendar.o
drivers/net/ethernet/microchip/sparx5/sparx5_calendar.c new file +595 -0

595 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_main.c +8 -0
index 30940d9ee916..2b42c72dac72 100644
@@ -743,6 +743,14 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 			goto cleanup_ports;
 		}
 	}
+	err = sparx5_config_auto_calendar(sparx5);
+	if (err)
+		goto cleanup_ports;
+
+	err = sparx5_config_dsm_calendar(sparx5);
+	if (err)
+		goto cleanup_ports;
+
 	/* Init mact_sw struct */
 	mutex_init(&sparx5->mact_lock);
 	INIT_LIST_HEAD(&sparx5->mact_entries);
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +4 -0
index 49657f9edbf3..e59e1962f7d4 100644
@@ -195,6 +195,10 @@ int sparx5_vlan_vid_add(struct sparx5_port *port, u16 vid, bool pvid,
 int sparx5_vlan_vid_del(struct sparx5_port *port, u16 vid);
 void sparx5_vlan_port_apply(struct sparx5 *sparx5, struct sparx5_port *port);
 
+/* sparx5_calendar.c */
+int sparx5_config_auto_calendar(struct sparx5 *sparx5);
+int sparx5_config_dsm_calendar(struct sparx5 *sparx5);
+
 /* sparx5_netdev.c */
 bool sparx5_netdevice_check(const struct net_device *dev);
 struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno);
Signature · 1 line
2.29.2
author maintainer
#29 lore raw

RFC PATCH v2 7/8 net: sparx5: add ethtool configuration and statistics support

In reply to Steen Hegelund

This adds statistic counters for the network interfaces provided by the driver. It also adds CPU port counters (which are not exposed by ethtool).
This also adds support for configuring the network interface parameters via ethtool: speed, duplex, aneg etc.

---
 .../net/ethernet/microchip/sparx5/Makefile    |   3 +-
 .../microchip/sparx5/sparx5_ethtool.c         | 979 ++++++++++++++++++
 .../ethernet/microchip/sparx5/sparx5_main.c   |   5 +
 .../ethernet/microchip/sparx5/sparx5_main.h   |  17 +-
 .../ethernet/microchip/sparx5/sparx5_netdev.c |   2 +
 5 files changed, 1001 insertions(+), 5 deletions(-)
 create mode 100644 drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c
drivers/net/ethernet/microchip/sparx5/Makefile +2 -1
index 17654ab90ce1..de3155cd582c 100644
@@ -7,4 +7,5 @@ obj-$(CONFIG_SPARX5_SWITCH) += sparx5-switch.o
 
 sparx5-switch-objs  := sparx5_main.o sparx5_switchdev.o \
  sparx5_vlan.o sparx5_mactable.o sparx5_packet.o \
- sparx5_netdev.o sparx5_port.o sparx5_phylink.o sparx5_calendar.o
+ sparx5_ethtool.o sparx5_netdev.o sparx5_port.o \
+ sparx5_phylink.o sparx5_calendar.o
drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c new file +979 -0

979 lines not on this page · raw message

drivers/net/ethernet/microchip/sparx5/sparx5_main.c +5 -0
index 2b42c72dac72..e1e2384512bc 100644
@@ -751,6 +751,11 @@ static int mchp_sparx5_probe(struct platform_device *pdev)
 	if (err)
 		goto cleanup_ports;
 
+	/* Init stats */
+	err = sparx_stats_init(sparx5);
+	if (err)
+		goto cleanup_ports;
+
 	/* Init mact_sw struct */
 	mutex_init(&sparx5->mact_lock);
 	INIT_LIST_HEAD(&sparx5->mact_entries);
drivers/net/ethernet/microchip/sparx5/sparx5_main.h +13 -4
index e59e1962f7d4..1d1b3b516244 100644
@@ -130,6 +130,14 @@ struct sparx5 {
 	/* port structures are in net device */
 	struct sparx5_port                    *ports[SPX5_PORTS];
 	enum sparx5_core_clockfreq            coreclock;
+	/* Statistics */
+	u32                                   num_stats;
+	const char * const                    *stats_layout;
+	u64                                   *stats;
+	/* Workqueue for reading stats */
+	struct mutex                          stats_lock;
+	struct delayed_work                   stats_work;
+	struct workqueue_struct               *stats_queue;
 	/* Notifiers */
 	struct notifier_block                 netdevice_nb;
 	struct notifier_block                 switchdev_nb;
@@ -153,10 +161,6 @@ struct sparx5 {
 	bool                                  sd_sgpio_remapping;
 };
 
-/* sparx5_main.c */
-void sparx5_update_cpuport_stats(struct sparx5 *sparx5, int portno);
-bool sparx5_is_cpuport_stat(struct sparx5 *sparx5, int idx);
-
 /* sparx5_switchdev.c */
 int sparx5_register_notifier_blocks(struct sparx5 *sparx5);
 void sparx5_unregister_notifier_blocks(struct sparx5 *sparx5);
@@ -199,6 +203,10 @@ void sparx5_vlan_port_apply(struct sparx5 *sparx5, struct sparx5_port *port);
 int sparx5_config_auto_calendar(struct sparx5 *sparx5);
 int sparx5_config_dsm_calendar(struct sparx5 *sparx5);
 
+/* sparx5_ethtool.c */
+void sparx5_get_stats64(struct net_device *ndev, struct rtnl_link_stats64 *stats);
+int sparx_stats_init(struct sparx5 *sparx5);
+
 /* sparx5_netdev.c */
 bool sparx5_netdevice_check(const struct net_device *dev);
 struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno);
@@ -226,6 +234,7 @@ static inline u32 sparx5_clk_period(enum sparx5_core_clockfreq cclock)
 }
 
 extern const struct phylink_mac_ops sparx5_phylink_mac_ops;
+extern const struct ethtool_ops sparx5_ethtool_ops;
 
 /* Calculate raw offset */
 static inline __pure int spx5_offset(int id, int tinst, int tcnt,
drivers/net/ethernet/microchip/sparx5/sparx5_netdev.c +2 -0
index a0992443ab9f..3b7cfbb14f2e 100644
@@ -176,6 +176,7 @@ static const struct net_device_ops sparx5_port_netdev_ops = {
 	.ndo_get_phys_port_name = sparx5_port_get_phys_port_name,
 	.ndo_set_mac_address    = sparx5_set_mac_address,
 	.ndo_validate_addr      = eth_validate_addr,
+	.ndo_get_stats64        = sparx5_get_stats64,
 	.ndo_get_port_parent_id = sparx5_get_port_parent_id,
 };
 
@@ -203,6 +204,7 @@ struct net_device *sparx5_create_netdev(struct sparx5 *sparx5, u32 portno)
 
 	ether_setup(ndev);
 	ndev->netdev_ops = &sparx5_port_netdev_ops;
+	ndev->ethtool_ops = &sparx5_ethtool_ops;
 	ndev->features |= NETIF_F_LLTX; /* software tx */
 
 	ether_addr_copy(ndev->dev_addr, sparx5->base_mac);
Signature · 7 lines
2.29.2


_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
#30 lore raw

Re: [RFC PATCH v2 7/8] net: sparx5: add ethtool configuration and statistics support

drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c line 889

Quoted 13 lines
drivers/net/ethernet/microchip/sparx5/sparx5_ethtool.c new file +13 -0
+void sparx5_get_stats64(struct net_device *ndev,
+			struct rtnl_link_stats64 *stats)
+{
+	struct sparx5_port *port = netdev_priv(ndev);
+	struct sparx5 *sparx5 = port->sparx5;
+	u64 *portstats;
+
+	if (!sparx5->stats)
+		return;		/* Not initialized yet */
+
+	portstats = &sparx5->stats[port->portno * sparx5->num_stats];
+
+	mutex_lock(&sparx5->stats_lock);

There was a big discussion about stats64 not being able to take a lock a few weeks ago. You probably want to go read the thread. The aim was to allow sleeping, but i don't know if that as been achieved yet.

Andrew

author maintainer
#31 lore raw

RFC PATCH v2 8/8 arm64: dts: sparx5: Add the Sparx5 switch node

In reply to Steen Hegelund

This provides switchdev support for the Microship Sparx5 PCB134 and PCB135 reference boards.

This commit depends on the following series currently on their way into the kernel:

- Sparx5 SerDes Driver

- Serial GPIO Controller

---
 arch/arm64/boot/dts/microchip/sparx5.dtsi     |  60 ++
 .../dts/microchip/sparx5_pcb134_board.dtsi    | 424 ++++++++++--
 .../dts/microchip/sparx5_pcb135_board.dtsi    | 602 +++++++++++++++++-
 3 files changed, 1026 insertions(+), 60 deletions(-)
arch/arm64/boot/dts/microchip/sparx5.dtsi +60 -0
index e480238489fa..085ab5a4fa50 100644
@@ -267,6 +267,21 @@ emmc_pins: emmc-pins {
 					"GPIO_46", "GPIO_47";
 				function = "emmc";
 			};
+
+			miim1_pins: miim1-pins {
+				pins = "GPIO_56", "GPIO_57";
+				function = "miim";
+			};
+
+			miim2_pins: miim2-pins {
+				pins = "GPIO_58", "GPIO_59";
+				function = "miim";
+			};
+
+			miim3_pins: miim3-pins {
+				pins = "GPIO_52", "GPIO_53";
+				function = "miim";
+			};
 		};
 
 		sgpio0: gpio@61101036c {
@@ -379,6 +394,44 @@ tmon0: tmon@610508110 {
 			clocks = <&ahb_clk>;
 		};
 
+		mdio0: mdio@6110102b0 {
+			compatible = "mscc,ocelot-miim";
+			status = "disabled";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <0x6 0x110102b0 0x24>;
+		};
+
+		mdio1: mdio@6110102d4 {
+			compatible = "mscc,ocelot-miim";
+			status = "disabled";
+			pinctrl-0 = <&miim1_pins>;
+			pinctrl-names = "default";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <0x6 0x110102d4 0x24>;
+		};
+
+		mdio2: mdio@6110102f8 {
+			compatible = "mscc,ocelot-miim";
+			status = "disabled";
+			pinctrl-0 = <&miim2_pins>;
+			pinctrl-names = "default";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <0x6 0x110102d4 0x24>;
+		};
+
+		mdio3: mdio@61101031c {
+			compatible = "mscc,ocelot-miim";
+			status = "disabled";
+			pinctrl-0 = <&miim3_pins>;
+			pinctrl-names = "default";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <0x6 0x1101031c 0x24>;
+		};
+
 		serdes: serdes@10808000 {
 			compatible = "microchip,sparx5-serdes";
 			#phy-cells = <1>;
@@ -386,5 +439,12 @@ serdes: serdes@10808000 {
 			reg = <0x6 0x10808000 0x5d0000>;
 		};
 
+		switch: switch@610004000 {
+			compatible = "microchip,sparx5-switch";
+			reg =	<0x6 0x10004000 0x800000>,
+				<0x6 0x11010000 0x1b00000>;
+			reg-names = "devices", "gcb";
+			interrupts = <GIC_SPI 30 IRQ_TYPE_LEVEL_HIGH>;
+		};
 	};
 };
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +377 -47

528 lines not on this page · raw message

arch/arm64/boot/dts/microchip/sparx5_pcb135_board.dtsi +589 -13

640 lines not on this page · raw message

Signature · 1 line
2.29.2
#32 lore raw

Re: [RFC PATCH v2 8/8] arm64: dts: sparx5: Add the Sparx5 switch node

arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi &gpio 60 GPIO_ACTIVE_HIGH · line 712

Quoted 4 lines
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +4 -0
+		port13: port@13 {
+			reg = <13>;
+			/* Example: CU SFP, 1G speed */
+			max-speed = <10000>;

One too many 0's for 1G.

arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi &gpio 60 GPIO_ACTIVE_HIGH · line 801

Quoted 4 lines
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +4 -0
+		/* 25G SFPs */
+		port56: port@56 {
+			reg = <56>;
+			max-speed = <10000>;

Why limit a 25G SFP to 10G?

Andrew

author maintainer
#33 lore raw

Re: [RFC PATCH v2 8/8] arm64: dts: sparx5: Add the Sparx5 switch node

Quoted 8 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi &gpio 60 GPIO_ACTIVE_HIGH · line 712

Quoted 4 lines
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +4 -0
+             port13: port@13 {
+                     reg = <13>;
+                     /* Example: CU SFP, 1G speed */
+                     max-speed = <10000>;

One too many 0's for 1G.

Ah, but this is allocation for the port, not the speed. This just used by the calendar module to allocate slots on the taxis as requested. So I would say it is OK to overallocate in this case (but you could argue it does not make much sense).

Quoted 7 lines

arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi &gpio 60 GPIO_ACTIVE_HIGH · line 801

Quoted 5 lines
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +4 -0
+             /* 25G SFPs */
+             port56: port@56 {
+                     reg = <56>;
+                     max-speed = <10000>;

Why limit a 25G SFP to 10G?

In the PCB134 case it is to keep the total allocation below 200Gbits ((12+8)*10G). There is a port mux mode that provides 8*25G on the 25G SerDes'es, but that would be a different DT.

The Datasheet shows which port mux combinations are possible, and not all combinations of SerDes, Speed and interface are allowed.

The PCB134 was designed to showcase this "many 10G ports" mode, so that is why we have the current DT.

Quoted 2 lines

Andrew

BR
Steen

---------------------------------------
Steen Hegelund
[email protected]

#34 lore raw

Re: [RFC PATCH v2 8/8] arm64: dts: sparx5: Add the Sparx5 switch node

Quoted 11 lines · Steen Hegelund
Quoted 8 lines · Andrew Lunn

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi &gpio 60 GPIO_ACTIVE_HIGH · line 712

Quoted 4 lines
arch/arm64/boot/dts/microchip/sparx5_pcb134_board.dtsi +4 -0
+             port13: port@13 {
+                     reg = <13>;
+                     /* Example: CU SFP, 1G speed */
+                     max-speed = <10000>;

One too many 0's for 1G.

Ah, but this is allocation for the port, not the speed.

phylib will look for this property and change what the PHY advertises based on this. There are some devices with Fast Ethernet but with a 1G PHY, because they are cheaper. By setting max-speed=<100>; phylib will stop the PHY advertising 1000Base-T/Full and 1000Base-T/Half. I can imaging the same is used when the MAC can do 2.5G, but the PHY is 5G capable, etc.

Quoted 3 lines

This just used by the calendar module to allocate slots on the taxis as requested. So I would say it is OK to overallocate in this case (but you could argue it does not make much sense).

Rather than misusing the max-speed property, it would be better to add a property with your specific meaning.

Andrew

#35 lore raw
In reply to Steen Hegelund
Quoted 95 lines · Steen Hegelund

This series provides the Microchip Sparx5 Switch Driver

The Sparx5 Carrier Ethernet and Industrial switch family delivers 64 Ethernet ports and up to 200 Gbps of switching bandwidth.

It provides a rich set of Ethernet switching features such as hierarchical QoS, hardware-based OAM and service activation testing, protection switching, IEEE 1588, and Synchronous Ethernet.

Using provider bridging (Q-in-Q) and MPLS/MPLS-TP technology, it delivers MEF CE
2.0 Ethernet virtual connections (EVCs) and features advanced TCAM
classification in both ingress and egress.

Per-EVC features include advanced L3-aware classification, a rich set of statistics, OAM for end-to-end performance monitoring, and dual-rate policing and shaping.

Time sensitive networking (TSN) is supported through a comprehensive set of features including frame preemption, cut-through, frame replication and elimination for reliability, enhanced scheduling: credit-based shaping, time-aware shaping, cyclic queuing, and forwarding, and per-stream policing and filtering.

Together with IEEE 1588 and IEEE 802.1AS support, this guarantees low-latency deterministic networking for Fronthaul, Carrier, and Industrial Ethernet.

The Sparx5 switch family consists of following SKUs:

- VSC7546 Sparx5-64 up to 64 Gbps of bandwidth with the following primary port configurations:
- 6 *10G
- 16 * 2.5G + 2 * 10G
- 24 * 1G + 4 * 10G

- VSC7549 Sparx5-90 up to 90 Gbps of bandwidth with the following primary port configurations:
- 9 * 10G
- 16 * 2.5G + 4 * 10G
- 48 * 1G + 4 * 10G

- VSC7552 Sparx5-128 up to 128 Gbps of bandwidth with the following primary port configurations:
- 12 * 10G
- 16 * 2.5G + 8 * 10G
- 48 * 1G + 8 * 10G

- VSC7556 Sparx5-160 up to 160 Gbps of bandwidth with the following primary port configurations:
- 16 * 10G
- 10 * 10G + 2 * 25G
- 16 * 2.5G + 10 * 10G
- 48 * 1G + 10 * 10G

- VSC7558 Sparx5-200 up to 200 Gbps of bandwidth with the following primary port configurations:
- 20 * 10G
- 8 * 25G

In addition, the device supports one 10/100/1000/2500/5000 Mbps SGMII/SerDes node processor interface (NPI) Ethernet port.

The Sparx5 support is developed on the PCB134 and PCB135 evaluation boards.

- PCB134 main networking features:
- 12x SFP+ front 10G module slots (connected to Sparx5 through SFI).
- 8x SFP28 front 25G module slots (connected to Sparx5 through SFI high

    speed).

- Optional, one additional 10/100/1000BASE-T (RJ45) Ethernet port (on-board VSC8211 PHY connected to Sparx5 through SGMII).

- PCB135 main networking features:
- 48x1G (10/100/1000M) RJ45 front ports using 12xVSC8514 QuadPHY’s each connected to VSC7558 through QSGMII.
- 4x10G (1G/2.5G/5G/10G) RJ45 front ports using the AQR407 10G QuadPHY each port connects to VSC7558 through SFI.
- 4x SFP28 25G module slots on back connected to VSC7558 through SFI high speed.
- Optional, one additional 1G (10/100/1000M) RJ45 port using an on-board VSC8211 PHY, which can be connected to VSC7558 NPI port through SGMII using a loopback add-on PCB)

This series provides support for:
- SFPs and DAC cables via PHYLINK with a number of 5G, 10G and 25G devices and media types.
- Port module configuration for 10M to 25G speeds with SGMII, QSGMII, 1000BASEX, 2500BASEX and 10GBASER as appropriate for these modes.
- SerDes configuration via the Sparx5 SerDes driver (see below).
- Host mode providing register based injection and extraction.
- Switch mode providing MAC/VLAN table learning and Layer2 switching offloaded to the Sparx5 switch.
- STP state, VLAN support, host/bridge port mode, Forwarding DB, and configuration and statistics via ethtool.

Quoted 4 lines

More support will be added at a later stage.

The Sparx5 Switch chip register model can be browsed here:

Out of curiosity, what tool was used to generate the register information page? It looks really neat and well organized.

Signature · 6 lines
Florian

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
author maintainer
#36 lore raw

Hi Florian,

Quoted 7 lines · Florian Fainelli
Quoted 4 lines

The Sparx5 Switch chip register model can be browsed here:
Link:
https://microchip-ung.github.io/sparx-5_reginfo/reginfo_sparx-5.html

Out of curiosity, what tool was used to generate the register information page? It looks really neat and well organized.

It is an in-house tool that is used in our so-called VML-flow (Versatile Markup Language), so it is not out in the open yet.

The same model file is used internally in many ways - but exposing it to the public is something we have not tried before, and having this view is so much nicer that the usual datasheet, I find...

And thanks for the kind words - I passed them on to the author.

BR
Steen

Quoted 2 lines

--
Florian

#37 lore raw
In reply to Florian Fainelli
Quoted 96 lines · Florian Fainelli
Quoted 95 lines · Steen Hegelund

This series provides the Microchip Sparx5 Switch Driver

The Sparx5 Carrier Ethernet and Industrial switch family delivers 64 Ethernet ports and up to 200 Gbps of switching bandwidth.

It provides a rich set of Ethernet switching features such as hierarchical QoS, hardware-based OAM and service activation testing, protection switching, IEEE 1588, and Synchronous Ethernet.

Using provider bridging (Q-in-Q) and MPLS/MPLS-TP technology, it delivers MEF CE
2.0 Ethernet virtual connections (EVCs) and features advanced TCAM
classification in both ingress and egress.

Per-EVC features include advanced L3-aware classification, a rich set of statistics, OAM for end-to-end performance monitoring, and dual-rate policing and shaping.

Time sensitive networking (TSN) is supported through a comprehensive set of features including frame preemption, cut-through, frame replication and elimination for reliability, enhanced scheduling: credit-based shaping, time-aware shaping, cyclic queuing, and forwarding, and per-stream policing and filtering.

Together with IEEE 1588 and IEEE 802.1AS support, this guarantees low-latency deterministic networking for Fronthaul, Carrier, and Industrial Ethernet.

The Sparx5 switch family consists of following SKUs:

- VSC7546 Sparx5-64 up to 64 Gbps of bandwidth with the following primary port configurations:
- 6 *10G
- 16 * 2.5G + 2 * 10G
- 24 * 1G + 4 * 10G

- VSC7549 Sparx5-90 up to 90 Gbps of bandwidth with the following primary port configurations:
- 9 * 10G
- 16 * 2.5G + 4 * 10G
- 48 * 1G + 4 * 10G

- VSC7552 Sparx5-128 up to 128 Gbps of bandwidth with the following primary port configurations:
- 12 * 10G
- 16 * 2.5G + 8 * 10G
- 48 * 1G + 8 * 10G

- VSC7556 Sparx5-160 up to 160 Gbps of bandwidth with the following primary port configurations:
- 16 * 10G
- 10 * 10G + 2 * 25G
- 16 * 2.5G + 10 * 10G
- 48 * 1G + 10 * 10G

- VSC7558 Sparx5-200 up to 200 Gbps of bandwidth with the following primary port configurations:
- 20 * 10G
- 8 * 25G

In addition, the device supports one 10/100/1000/2500/5000 Mbps SGMII/SerDes node processor interface (NPI) Ethernet port.

The Sparx5 support is developed on the PCB134 and PCB135 evaluation boards.

- PCB134 main networking features:
- 12x SFP+ front 10G module slots (connected to Sparx5 through SFI).
- 8x SFP28 front 25G module slots (connected to Sparx5 through SFI high

    speed).

- Optional, one additional 10/100/1000BASE-T (RJ45) Ethernet port (on-board VSC8211 PHY connected to Sparx5 through SGMII).

- PCB135 main networking features:
- 48x1G (10/100/1000M) RJ45 front ports using 12xVSC8514 QuadPHY’s each connected to VSC7558 through QSGMII.
- 4x10G (1G/2.5G/5G/10G) RJ45 front ports using the AQR407 10G QuadPHY each port connects to VSC7558 through SFI.
- 4x SFP28 25G module slots on back connected to VSC7558 through SFI high speed.
- Optional, one additional 1G (10/100/1000M) RJ45 port using an on-board VSC8211 PHY, which can be connected to VSC7558 NPI port through SGMII using a loopback add-on PCB)

This series provides support for:
- SFPs and DAC cables via PHYLINK with a number of 5G, 10G and 25G devices and media types.
- Port module configuration for 10M to 25G speeds with SGMII, QSGMII, 1000BASEX, 2500BASEX and 10GBASER as appropriate for these modes.
- SerDes configuration via the Sparx5 SerDes driver (see below).
- Host mode providing register based injection and extraction.
- Switch mode providing MAC/VLAN table learning and Layer2 switching offloaded to the Sparx5 switch.
- STP state, VLAN support, host/bridge port mode, Forwarding DB, and configuration and statistics via ethtool.

Quoted 7 lines
Quoted 4 lines

More support will be added at a later stage.

The Sparx5 Switch chip register model can be browsed here:

Out of curiosity, what tool was used to generate the register information page? It looks really neat and well organized.

Florian,

It is an in-house tool. The input data is in a proprietary XML-like format.

We're pleased that you like it, we do too. We are also pleased that being a Microchip entity, we can actually make this kind of information public.

I'll pass your praise on.

---Lars

--
Lars Povlsen,
Microchip