Skip to contentSkip to conversation

PRU-ICSSM Ethernet Driver

RFC PATCH In review Basharath Hussain Khaja 4 participants 31 messages Jan 24, 2025 – Feb 5, 2025

Subsystems (7)
lore
Share & tools
lore
#0 lore raw

v2 cover PRU-ICSSM Ethernet Driver

Hi,

The Programmable Real-Time Unit Industrial Communication Sub-system (PRU-ICSS) is available on the TI SOCs in two flavors: Gigabit ICSS (ICSSG) and the older Megabit ICSS (ICSSM).

Support for ICSSG Dual-EMAC mode has already been mainlined [1] and the fundamental components/drivers such as PRUSS driver, Remoteproc driver, PRU-ICSS INTC, and PRU-ICSS IEP drivers are already available in the mainline Linux kernel. The current RFC patch series builds on top of these components and introduces changes to support the Dual-EMAC mode on ICSSM, especially on the TI AM57xx devices.

TI AM57xx series of devices have two identical PRU-ICSS instances (PRU-ICSS1 and PRU-ICSS2), each with two 32-bit RISC PRU cores. Each PRU core has
(a) dedicated Ethernet interface (MII, MDIO), timers, capture modules, and serial communication interfaces, and (b) dedicated data and instruction RAM as well as shared RAM for inter PRU communication within the PRU-ICSS.

This set of patches is a follow-up to [2] yet to merged. These patches add support for the following features::
- RX and TX over PRU Ethernet ports in Dual-EMAC mode
- Full duplex with 100 Mbps link speed.
- VLAN Filtering
- Multicast Filtering
- Promiscuous mode
- Storm prevention
- Interrupt coalescing
- Linux PTP (ptp4l) Ordinary clock

Further, note that these are the first set of patches for PRU-ICSS2 Ethernet. Switch mode support, PRU-ICSS1 support, PRU Ethernet for AM437x and AM335x in Dual-EMAC and Switch mode support with full feature set changes will be posted subsequently.

These changes are validated on top of Linux next kernel by reverting a recent commit [3]. This commit is breaking the Ethernet functionality on TI AM57xx due to zero block size allocation in SRAM during initialization.

The patches presented in this series have gone through the patch verification tools and no warnings or errors are reported. Sample test logs verifying the functionality on Linux next kernel are available here:

[Interface up Testing](https://gist.github.com/basharath-cit/7fbdd48dec77e3eb3afee0eac4b5bc14)

[Ping Testing](https://gist.github.com/basharath-cit/edd75dedf0a69888ad8f1211540380b8)

[Iperf Testing](https://gist.github.com/basharath-cit/8e20dfdfbae5d14ccbbc5b76d8b90e73)

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/[email protected]/
[3] https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?h=v6.13-rc5&id=1a52a094c2f0821860d9ce15fffe01103a146f1f

This is the v2 of the patch series [v1]. This version of the patchset addresses the comments made on [v1] of the series.

Changes from v1 to v2 :

*) Addressed Andrew Lunn, Rob Herring comments on patch 1 of the series. *) Addressed Andrew Lunn comments on patch 2, 3, and 4 of the series. *) Addressed Richard Cochran, Jason Xing comments on patch 6 of the series. *) Rebased patchset on next-202401xx linux-next.

[v1] https://lore.kernel.org/all/[email protected]/

Thanks & Best Regards,
Basharath

Murali Karicheri (1):
net: ti: prueth: Adds support for RX interrupt coalescing/pacing

Parvathi Pudi (1):
dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for
AM57xx SOCs

Roger Quadros (8):
net: ti: prueth: Adds ICSSM Ethernet driver
net: ti: prueth: Adds PRUETH HW and SW configuration
net: ti: prueth: Adds link detection, RX and TX support.
net: ti: prueth: Adds ethtool support for ICSSM PRUETH Driver
net: ti: prueth: Adds HW timestamping support for PTP using PRU-ICSS
IEP module
net: ti: prueth: Adds support for network filters for traffic control
supported by PRU-ICSS
net: ti: prueth: Adds power management support for PRU-ICSS
arm: dts: ti: Adds device tree nodes for PRU Cores, IEP and eCAP
modules of PRU-ICSS2 Instance.

 .../devicetree/bindings/net/ti,icss-iep.yaml  |    5 +
 .../bindings/net/ti,icssm-prueth.yaml         |  147 +
 .../bindings/net/ti,pruss-ecap.yaml           |   32 +
 .../devicetree/bindings/soc/ti/ti,pruss.yaml  |    9 +
 arch/arm/boot/dts/ti/omap/am57-pruss.dtsi     |   11 +
 arch/arm/boot/dts/ti/omap/am571x-idk.dts      |    8 +-
 arch/arm/boot/dts/ti/omap/am572x-idk.dts      |   10 +-
 arch/arm/boot/dts/ti/omap/am574x-idk.dts      |   10 +-
 .../boot/dts/ti/omap/am57xx-idk-common.dtsi   |   61 +
 drivers/net/ethernet/ti/Kconfig               |   24 +
 drivers/net/ethernet/ti/Makefile              |    5 +
 drivers/net/ethernet/ti/icssg/icss_iep.c      |   42 +
 drivers/net/ethernet/ti/icssm/icssm_ethtool.c |  303 +++
 drivers/net/ethernet/ti/icssm/icssm_prueth.c  | 2396 +++++++++++++++++
 drivers/net/ethernet/ti/icssm/icssm_prueth.h  |  428 +++
 .../net/ethernet/ti/icssm/icssm_prueth_dos.c  |  225 ++
 .../net/ethernet/ti/icssm/icssm_prueth_ecap.c |  312 +++
 .../net/ethernet/ti/icssm/icssm_prueth_ecap.h |   47 +
 .../net/ethernet/ti/icssm/icssm_prueth_ptp.h  |   85 +
 drivers/net/ethernet/ti/icssm/icssm_switch.h  |  285 ++
 .../ti/icssm/icssm_vlan_mcast_filter_mmap.h   |  120 +
 21 files changed, 4556 insertions(+), 9 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml
 create mode 100644 Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_ethtool.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth.h
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_dos.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_ecap.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_ecap.h
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_ptp.h
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_switch.h
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_vlan_mcast_filter_mmap.h
Signature · 1 line
2.34.1
#1 lore raw

RFC PATCH v2 1/10 dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for AM57xx SOCs

From: Parvathi Pudi <[email protected]>

Documentation update for the newly added "pruss2_eth" device tree node and its dependencies along with compatibility for PRU-ICSS Industrial Ethernet Peripheral (IEP), PRU-ICSS Enhanced Capture (eCAP) peripheral and using YAML binding document for AM57xx SoCs.

---
 .../devicetree/bindings/net/ti,icss-iep.yaml  |   5 +
 .../bindings/net/ti,icssm-prueth.yaml         | 147 ++++++++++++++++++
 .../bindings/net/ti,pruss-ecap.yaml           |  32 ++++
 .../devicetree/bindings/soc/ti/ti,pruss.yaml  |   9 ++
 4 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml
 create mode 100644 Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +5 -0
index e36e3a622904..aad7d37fb47e 100644
@@ -8,6 +8,8 @@ title: Texas Instruments ICSS Industrial Ethernet Peripheral (IEP) module
 
 maintainers:
   - Md Danish Anwar <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
 
 properties:
   compatible:
@@ -20,6 +22,9 @@ properties:
 
       - const: ti,am654-icss-iep
 
+      - items:
+          - enum:
+              - ti,am5728-icss-iep
 
   reg:
     maxItems: 1
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +147 -0

147 lines not on this page · raw message

Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml new file +32 -0
new file mode 100644
index 000000000000..42f217099b2e
@@ -0,0 +1,32 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/ti,pruss-ecap.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments PRU-ICSS Enhanced Capture (eCAP) event module
+
+maintainers:
+  - Murali Karicheri <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
+
+properties:
+  compatible:
+    const: ti,pruss-ecap
+
+  reg:
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+additionalProperties: false
+
+examples:
+  - |
+    pruss2_ecap: ecap@30000 {
+        compatible = "ti,pruss-ecap";
+        reg = <0x30000 0x60>;
+    };
Documentation/devicetree/bindings/soc/ti/ti,pruss.yaml +9 -0
index 927b3200e29e..594f54264a8c 100644
@@ -251,6 +251,15 @@ patternProperties:
 
     type: object
 
+  ecap@[a-f0-9]+$:
+    description:
+      PRU-ICSS has a Enhanced Capture (eCAP) event module which can generate
+      and capture periodic timer based events which will be used for features
+      like RX Pacing to rise interrupt when the timer event has occurred.
+      Each PRU-ICSS instance has one eCAP modeule irrespective of SOCs.
+
+    type: object
+
   mii-rt@[a-f0-9]+$:
     description: |
       Real-Time Ethernet to support multiple industrial communication protocols.
Signature · 1 line
2.34.1
#2 lore raw

Re: [RFC v2 PATCH 01/10] dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for AM57xx SOCs

Quoted 7 lines · Basharath Hussain Khaja

From: Parvathi Pudi <[email protected]>

Documentation update for the newly added "pruss2_eth" device tree node and its dependencies along with compatibility for PRU-ICSS Industrial Ethernet Peripheral (IEP), PRU-ICSS Enhanced Capture (eCAP) peripheral and using YAML binding document for AM57xx SoCs.

Quoted 5 lines

I find this hard to believe. If all these people handled the patch, the signoff from Parvathi would be first, no? Should some of these people be co-developers?

Quoted 23 lines
---
 .../devicetree/bindings/net/ti,icss-iep.yaml  |   5 +
 .../bindings/net/ti,icssm-prueth.yaml         | 147 ++++++++++++++++++
 .../bindings/net/ti,pruss-ecap.yaml           |  32 ++++
 .../devicetree/bindings/soc/ti/ti,pruss.yaml  |   9 ++
 4 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml
 create mode 100644 Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +2 -0
index e36e3a622904..aad7d37fb47e 100644
@@ -8,6 +8,8 @@ title: Texas Instruments ICSS Industrial Ethernet Peripheral (IEP) module
 
 maintainers:
   - Md Danish Anwar <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
 
 properties:
   compatible:

Documentation/devicetree/bindings/net/ti,icss-iep.yaml properties: · line 27

Quoted 6 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +3 -0
@@ -20,6 +22,9 @@ properties:
 
       - const: ti,am654-icss-iep
 
+      - items:
+          - enum:
+              - ti,am5728-icss-iep

"items: - enum: <one item>" is the same as const.

Quoted 38 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
   reg:
     maxItems: 1
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +29 -0
new file mode 100644
index 000000000000..51e99beb5f5f
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/ti,icssm-prueth.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments ICSSM PRUSS Ethernet
+
+maintainers:
+  - Roger Quadros <[email protected]>
+  - Andrew F. Davis <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
+
+description:
+  Ethernet based on the Programmable Real-Time Unit and Industrial
+  Communication Subsystem.
+
+properties:
+  compatible:
+    enum:
+      - ti,am57-prueth     # for AM57x SoC family
+
+  sram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to OCMC SRAM node
+
+  ti,mii-rt:

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 39

Quoted 10 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +10 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to MII_RT module's syscon regmap
+
+  ti,iep:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to IEP (Industrial Ethernet Peripheral) for ICSS
+
+  ecap:

Why's this one not got a ti prefix?

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 42

Quoted 3 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to Enhanced Capture (eCAP) event for ICSS

Why do you need phandles for these things, can they not be looked up by compatible? (e.g. multiple devices on one SoC).

Quoted 5 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +5 -0
+
+  interrupts:
+    items:
+      - description: High priority Rx Interrupt specifier.
+      - description: Low priority Rx Interrupt specifier.
#3 lore raw

Re: [RFC v2 PATCH 01/10] dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for AM57xx SOCs

Quoted 14 lines · Basharath Hussain Khaja
Quoted 7 lines

From: Parvathi Pudi <[email protected]>

Documentation update for the newly added "pruss2_eth" device tree node and its dependencies along with compatibility for PRU-ICSS Industrial Ethernet Peripheral (IEP), PRU-ICSS Enhanced Capture (eCAP) peripheral and using YAML binding document for AM57xx SoCs.

Quoted 5 lines
Quoted 4 lines

I find this hard to believe. If all these people handled the patch, the signoff from Parvathi would be first, no? Should some of these people be co-developers?

Changes are about multiple modules. We have added our sign-off followed by original module authors.

Quoted 26 lines
Quoted 26 lines
---
 .../devicetree/bindings/net/ti,icss-iep.yaml  |   5 +
 .../bindings/net/ti,icssm-prueth.yaml         | 147 ++++++++++++++++++
 .../bindings/net/ti,pruss-ecap.yaml           |  32 ++++
 .../devicetree/bindings/soc/ti/ti,pruss.yaml  |   9 ++
 4 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml
 create mode 100644 Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
index e36e3a622904..aad7d37fb47e 100644
@@ -8,6 +8,8 @@ title: Texas Instruments ICSS Industrial Ethernet Peripheral

(IEP) module

maintainers:
- Md Danish Anwar <[email protected]>

Documentation/devicetree/bindings/net/ti,icss-iep.yaml +2 -0
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
 
 properties:
   compatible:
@@ -20,6 +22,9 @@ properties:
 
Quoted 8 lines

Documentation/devicetree/bindings/net/ti,icss-iep.yaml properties: · line 27

Quoted 5 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +3 -0
       - const: ti,am654-icss-iep
 
+      - items:
+          - enum:
+              - ti,am5728-icss-iep

"items: - enum: <one item>" is the same as const.

Sure, we will modify as below.

- const: ti,am5728-icss-iep

Quoted 43 lines
Quoted 43 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
   reg:
     maxItems: 1
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +33 -0
new file mode 100644
index 000000000000..51e99beb5f5f
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/ti,icssm-prueth.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments ICSSM PRUSS Ethernet
+
+maintainers:
+  - Roger Quadros <[email protected]>
+  - Andrew F. Davis <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
+
+description:
+  Ethernet based on the Programmable Real-Time Unit and Industrial
+  Communication Subsystem.
+
+properties:
+  compatible:
+    enum:
+      - ti,am57-prueth     # for AM57x SoC family
+
+  sram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to OCMC SRAM node
+
+  ti,mii-rt:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to MII_RT module's syscon regmap
+
Quoted 9 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 39

Quoted 6 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +6 -0
+  ti,iep:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to IEP (Industrial Ethernet Peripheral) for ICSS
+
+  ecap:

Why's this one not got a ti prefix?

We will add "ti" prefix to ecap as "ti,ecap" in the next version.

Quoted 7 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 42

Quoted 3 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to Enhanced Capture (eCAP) event for ICSS

Why do you need phandles for these things, can they not be looked up by compatible? (e.g. multiple devices on one SoC).

ecap is another peripheral similar to IEP in ICSSM/ICSSG. We have created a separate driver for possible reuse with ICSSG in future.

Quoted 5 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 47

Quoted 5 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +5 -0
+
+  interrupts:
+    items:
+      - description: High priority Rx Interrupt specifier.
+      - description: Low priority Rx Interrupt specifier.

Thanks & Best Regards,
Basharath

#4 lore raw

Re: [RFC v2 PATCH 01/10] dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for AM57xx SOCs

Quoted 14 lines · Basharath Hussain Khaja
Quoted 14 lines · Basharath Hussain Khaja
Quoted 12 lines

From: Parvathi Pudi <[email protected]>

Documentation update for the newly added "pruss2_eth" device tree node and its dependencies along with compatibility for PRU-ICSS Industrial Ethernet Peripheral (IEP), PRU-ICSS Enhanced Capture (eCAP) peripheral and using YAML binding document for AM57xx SoCs.

Quoted 6 lines
Quoted 4 lines

I find this hard to believe. If all these people handled the patch, the signoff from Parvathi would be first, no? Should some of these people be co-developers?

Changes are about multiple modules. We have added our sign-off followed by original module authors.

I think what you're trying to say is that these people are co-developers? Anyone that contributed to the content of this patch needs to get a co-developed-by. If they're not co-developers, and you just want to put them in the maintainers section, they don't get sign-offs.

Quoted 98 lines
Quoted 26 lines
Quoted 26 lines
---
 .../devicetree/bindings/net/ti,icss-iep.yaml  |   5 +
 .../bindings/net/ti,icssm-prueth.yaml         | 147 ++++++++++++++++++
 .../bindings/net/ti,pruss-ecap.yaml           |  32 ++++
 .../devicetree/bindings/soc/ti/ti,pruss.yaml  |   9 ++
 4 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml
 create mode 100644 Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
index e36e3a622904..aad7d37fb47e 100644
@@ -8,6 +8,8 @@ title: Texas Instruments ICSS Industrial Ethernet Peripheral

(IEP) module

maintainers:
- Md Danish Anwar <[email protected]>

Documentation/devicetree/bindings/net/ti,icss-iep.yaml +2 -0
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
 
 properties:
   compatible:
@@ -20,6 +22,9 @@ properties:
 
Quoted 8 lines

Documentation/devicetree/bindings/net/ti,icss-iep.yaml properties: · line 27

Quoted 5 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +3 -0
       - const: ti,am654-icss-iep
 
+      - items:
+          - enum:
+              - ti,am5728-icss-iep

"items: - enum: <one item>" is the same as const.

Sure, we will modify as below.

- const: ti,am5728-icss-iep

Quoted 43 lines
Quoted 43 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
   reg:
     maxItems: 1
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +33 -0
new file mode 100644
index 000000000000..51e99beb5f5f
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/ti,icssm-prueth.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments ICSSM PRUSS Ethernet
+
+maintainers:
+  - Roger Quadros <[email protected]>
+  - Andrew F. Davis <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
+
+description:
+  Ethernet based on the Programmable Real-Time Unit and Industrial
+  Communication Subsystem.
+
+properties:
+  compatible:
+    enum:
+      - ti,am57-prueth     # for AM57x SoC family
+
+  sram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to OCMC SRAM node
+
+  ti,mii-rt:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to MII_RT module's syscon regmap
+
Quoted 9 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 39

Quoted 6 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +6 -0
+  ti,iep:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to IEP (Industrial Ethernet Peripheral) for ICSS
+
+  ecap:

Why's this one not got a ti prefix?

We will add "ti" prefix to ecap as "ti,ecap" in the next version.

Quoted 4 lines
Quoted 3 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to Enhanced Capture (eCAP) event for ICSS
Quoted 5 lines
Quoted 3 lines

Why do you need phandles for these things, can they not be looked up by compatible? (e.g. multiple devices on one SoC).

ecap is another peripheral similar to IEP in ICSSM/ICSSG. We have created a separate driver for possible reuse with ICSSG in future.

That's not an answer to my question.

Quoted 10 lines
Quoted 6 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 47

Quoted 6 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +5 -0
+
+  interrupts:
+    items:
+      - description: High priority Rx Interrupt specifier.
+      - description: Low priority Rx Interrupt specifier.

Thanks & Best Regards,
Basharath

#5 lore raw

Re: [RFC v2 PATCH 01/10] dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for AM57xx SOCs

Quoted 20 lines · Basharath Hussain Khaja
Quoted 19 lines
Quoted 18 lines · Basharath Hussain Khaja
Quoted 7 lines

From: Parvathi Pudi <[email protected]>

Documentation update for the newly added "pruss2_eth" device tree node and its dependencies along with compatibility for PRU-ICSS Industrial Ethernet Peripheral (IEP), PRU-ICSS Enhanced Capture (eCAP) peripheral and using YAML binding document for AM57xx SoCs.

Quoted 5 lines

I find this hard to believe. If all these people handled the patch, the signoff from Parvathi would be first, no? Should some of these people be co-developers?

Quoted 9 lines
Quoted 2 lines

Changes are about multiple modules. We have added our sign-off followed by original module authors.

I think what you're trying to say is that these people are co-developers? Anyone that contributed to the content of this patch needs to get a co-developed-by. If they're not co-developers, and you just want to put them in the maintainers section, they don't get sign-offs.

Yes you may be right. We thought it would be good to include module owners in signed-off-by, though it is a documentation file which was not available earlier we have newly added. Due to that the ownership is with us.

As you suggested we will clean this in the next version as below.

Quoted 98 lines
Quoted 98 lines
Quoted 26 lines
Quoted 26 lines
---
 .../devicetree/bindings/net/ti,icss-iep.yaml  |   5 +
 .../bindings/net/ti,icssm-prueth.yaml         | 147 ++++++++++++++++++
 .../bindings/net/ti,pruss-ecap.yaml           |  32 ++++
 .../devicetree/bindings/soc/ti/ti,pruss.yaml  |   9 ++
 4 files changed, 193 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml
 create mode 100644 Documentation/devicetree/bindings/net/ti,pruss-ecap.yaml
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
index e36e3a622904..aad7d37fb47e 100644
@@ -8,6 +8,8 @@ title: Texas Instruments ICSS Industrial Ethernet Peripheral

(IEP) module

maintainers:
- Md Danish Anwar <[email protected]>

Documentation/devicetree/bindings/net/ti,icss-iep.yaml +2 -0
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
 
 properties:
   compatible:
@@ -20,6 +22,9 @@ properties:
 
Quoted 8 lines

Documentation/devicetree/bindings/net/ti,icss-iep.yaml properties: · line 27

Quoted 5 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +3 -0
       - const: ti,am654-icss-iep
 
+      - items:
+          - enum:
+              - ti,am5728-icss-iep

"items: - enum: <one item>" is the same as const.

Sure, we will modify as below.

- const: ti,am5728-icss-iep

Quoted 43 lines
Quoted 43 lines
Documentation/devicetree/bindings/net/ti,icss-iep.yaml +0 -0
   reg:
     maxItems: 1
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +33 -0
new file mode 100644
index 000000000000..51e99beb5f5f
@@ -0,0 +1,147 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/ti,icssm-prueth.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Texas Instruments ICSSM PRUSS Ethernet
+
+maintainers:
+  - Roger Quadros <[email protected]>
+  - Andrew F. Davis <[email protected]>
+  - Parvathi Pudi <[email protected]>
+  - Basharath Hussain Khaja <[email protected]>
+
+description:
+  Ethernet based on the Programmable Real-Time Unit and Industrial
+  Communication Subsystem.
+
+properties:
+  compatible:
+    enum:
+      - ti,am57-prueth     # for AM57x SoC family
+
+  sram:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to OCMC SRAM node
+
+  ti,mii-rt:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to MII_RT module's syscon regmap
+
Quoted 9 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 39

Quoted 6 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +6 -0
+  ti,iep:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to IEP (Industrial Ethernet Peripheral) for ICSS
+
+  ecap:

Why's this one not got a ti prefix?

We will add "ti" prefix to ecap as "ti,ecap" in the next version.

Quoted 4 lines
Quoted 3 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to Enhanced Capture (eCAP) event for ICSS
Quoted 9 lines
Quoted 6 lines
Quoted 3 lines

Why do you need phandles for these things, can they not be looked up by compatible? (e.g. multiple devices on one SoC).

ecap is another peripheral similar to IEP in ICSSM/ICSSG. We have created a separate driver for possible reuse with ICSSG in future.

That's not an answer to my question.

We can use compatible if we have only one instance of a peripheral in the SOC. On the AM57x SOC we have two identical ICSS instances(ICSS1 and ICSS2). So we use phandles to differentiate between the two instances. Currently this patch series adds support for ICSS2 instance on the AM57x SOC. Support for ICSS1 instance will be added in subsequent patches.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 47

Quoted 6 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +5 -0
+
+  interrupts:
+    items:
+      - description: High priority Rx Interrupt specifier.
+      - description: Low priority Rx Interrupt specifier.

Thanks & Best Regards,
Basharath

#6 lore raw

Re: [RFC v2 PATCH 01/10] dt-bindings: net: ti: Adds DUAL-EMAC mode support on PRU-ICSS2 for AM57xx SOCs

Quoted 11 lines · Basharath Hussain Khaja
Quoted 11 lines
Quoted 10 lines
Quoted 7 lines

Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml line 42

Quoted 3 lines
Documentation/devicetree/bindings/net/ti,icssm-prueth.yaml new file +3 -0
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to Enhanced Capture (eCAP) event for ICSS

Why do you need phandles for these things, can they not be looked up by compatible? (e.g. multiple devices on one SoC).

ecap is another peripheral similar to IEP in ICSSM/ICSSG. We have created a separate driver for possible reuse with ICSSG in future.

Quoted 8 lines
Quoted 2 lines

That's not an answer to my question.

We can use compatible if we have only one instance of a peripheral in the SOC. On the AM57x SOC we have two identical ICSS instances(ICSS1 and ICSS2). So we use phandles to differentiate between the two instances. Currently this patch series adds support for ICSS2 instance on the AM57x SOC. Support for ICSS1 instance will be added in subsequent patches.

Cool, that's an acceptance answer, thanks.

#7 lore raw

RFC PATCH v2 2/10 net: ti: prueth: Adds ICSSM Ethernet driver

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Updates Kernel configuration to enable PRUETH driver and its dependencies along with makefile changes to add the new PRUETH driver.

Changes includes init and deinit of ICSSM PRU Ethernet driver including net dev registration and firmware loading for DUAL-MAC mode running on PRU-ICSS2 instance.

Changes also includes link handling, PRU booting, default firmware loading and PRU stopping using existing remoteproc driver APIs.

---
 drivers/net/ethernet/ti/Kconfig              |  12 +
 drivers/net/ethernet/ti/Makefile             |   3 +
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 524 +++++++++++++++++++
 drivers/net/ethernet/ti/icssm/icssm_prueth.h | 100 ++++
 4 files changed, 639 insertions(+)
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth.h
drivers/net/ethernet/ti/Kconfig +12 -0
index 0d5a862cd78a..96ad084f1dce 100644
@@ -227,4 +227,16 @@ config TI_ICSS_IEP
 	  To compile this driver as a module, choose M here. The module
 	  will be called icss_iep.
 
+config TI_PRUETH
+	tristate "TI PRU Ethernet EMAC driver"
+	depends on PRU_REMOTEPROC
+	depends on NET_SWITCHDEV
+	select TI_ICSS_IEP
+	imply PTP_1588_CLOCK
+	help
+	  Some TI SoCs has Programmable Realtime Units (PRUs) cores which can
+	  support Single or Dual Ethernet ports with help of firmware code running
+	  on PRU cores. This driver supports remoteproc based communication to
+	  PRU firmware to expose ethernet interface to Linux.
+
 endif # NET_VENDOR_TI
drivers/net/ethernet/ti/Makefile +3 -0
index cbcf44806924..93c0a4d0e33a 100644
@@ -3,6 +3,9 @@
 # Makefile for the TI network device drivers.
 #
 
+obj-$(CONFIG_TI_PRUETH) += icssm-prueth.o
+icssm-prueth-y := icssm/icssm_prueth.o
+
 obj-$(CONFIG_TI_CPSW) += cpsw-common.o
 obj-$(CONFIG_TI_DAVINCI_EMAC) += cpsw-common.o
 obj-$(CONFIG_TI_CPSW_SWITCHDEV) += cpsw-common.o
drivers/net/ethernet/ti/icssm/icssm_prueth.c new file +524 -0

524 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_prueth.h new file +100 -0

100 lines not on this page · raw message

Signature · 1 line
2.34.1
reviewer
#8 lore raw

Re: [RFC v2 PATCH 02/10] net: ti: prueth: Adds ICSSM Ethernet driver

Quoted 16 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Updates Kernel configuration to enable PRUETH driver and its dependencies along with makefile changes to add the new PRUETH driver.

Changes includes init and deinit of ICSSM PRU Ethernet driver including net dev registration and firmware loading for DUAL-MAC mode running on PRU-ICSS2 instance.

Changes also includes link handling, PRU booting, default firmware loading and PRU stopping using existing remoteproc driver APIs.

...

Quoted 1 line
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

Quoted 38 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +38 -0
+static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
+				   struct net_device *ndev)
+{
+	const struct prueth_firmware *pru_firmwares;
+	struct prueth *prueth = emac->prueth;
+	const char *fw_name;
+	int ret;
+
+	pru_firmwares = &prueth->fw_data->fw_pru[emac->port_id - 1];
+	fw_name = pru_firmwares->fw_name[prueth->eth_type];
+	if (!fw_name) {
+		netdev_err(ndev, "eth_type %d not supported\n",
+			   prueth->eth_type);
+		return -ENODEV;
+	}
+
+	ret = rproc_set_firmware(emac->pru, fw_name);
+	if (ret) {
+		netdev_err(ndev, "failed to set PRU0 firmware %s: %d\n",
+			   fw_name, ret);
+		return ret;
+	}
+
+	ret = rproc_boot(emac->pru);
+	if (ret) {
+		netdev_err(ndev, "failed to boot PRU0: %d\n", ret);
+		return ret;
+	}
+
+	return ret;
+}
+
+/**
+ * icssm_emac_ndo_open - EMAC device open
+ * @ndev: network adapter device
+ *
+ * Called when system wants to start the interface.
+ *

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 124

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+ * Return: 0 for a successful open, or appropriate error code
+ */
+static int icssm_emac_ndo_open(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int ret;
+
+	ret = icssm_emac_set_boot_pru(emac, ndev);
+	if (ret)
+		netdev_err(ndev, "failed to boot PRU: %d\n", ret);

Hi Roger, Basharath, all,

icssm_emac_set_boot_pru() already logs errors, including the one above. So this log seems unnecessary to me.

Also, should an error be returned here? If so, it looks like icssm_emac_set_boot_pru() should release resources allocated by rproc_set_firmware() if rproc_boot() fails.

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +6 -0
+
+	/* start PHY */
+	phy_start(emac->phydev);
+
+	return 0;
+}

...

Quoted 44 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +44 -0
+static int icssm_prueth_netdev_init(struct prueth *prueth,
+				    struct device_node *eth_node)
+{
+	struct prueth_emac *emac;
+	struct net_device *ndev;
+	enum prueth_port port;
+	enum prueth_mac mac;
+	int ret;
+
+	port = icssm_prueth_node_port(eth_node);
+	if (port == PRUETH_PORT_INVALID)
+		return -EINVAL;
+
+	mac = icssm_prueth_node_mac(eth_node);
+	if (mac == PRUETH_MAC_INVALID)
+		return -EINVAL;
+
+	ndev = devm_alloc_etherdev(prueth->dev, sizeof(*emac));
+	if (!ndev)
+		return -ENOMEM;
+
+	SET_NETDEV_DEV(ndev, prueth->dev);
+	emac = netdev_priv(ndev);
+	prueth->emac[mac] = emac;
+	emac->prueth = prueth;
+	emac->ndev = ndev;
+	emac->port_id = port;
+
+	/* by default eth_type is EMAC */
+	switch (port) {
+	case PRUETH_PORT_MII0:
+		emac->pru = prueth->pru0;
+		break;
+	case PRUETH_PORT_MII1:
+		emac->pru = prueth->pru1;
+		break;
+	default:
+		return -EINVAL;
+	}
+	/* get mac address from DT and set private and netdev addr */
+	ret = of_get_ethdev_address(eth_node, ndev);
+	if (!is_valid_ether_addr(ndev->dev_addr)) {
+		eth_hw_addr_random(ndev);
+		dev_warn(prueth->dev, "port %d: using random MAC addr: %pM\n",

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 246

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+			 port, ndev->dev_addr);
+	}
+	ether_addr_copy(emac->mac_addr, ndev->dev_addr);
+
+	/* connect PHY */
+	emac->phydev = of_phy_get_and_connect(ndev, eth_node,
+					      icssm_emac_adjust_link);
+	if (!emac->phydev) {
+		dev_dbg(prueth->dev, "PHY connection failed\n");
+		ret = -EPROBE_DEFER;

Perhaps I misunderstand things, but if this occurs then presumably icssm_prueth_netdev_init() will be called again. And for each time this occirs another ndev will be allocated by devm_alloc_etherdev(), each of which will only be freed once the device is eventually torn-down.

I wonder if it would be better to free ndev here.
Which I think would imply using a non-mdev allocation for symmetry.

Similarly for resources allocated in the caller icssm_prueth_probe().

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +6 -0
+		goto free;
+	}
+
+	/* remove unsupported modes */
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_10baseT_Full_BIT);
+

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 262

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
+
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_Pause_BIT);
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_Asym_Pause_BIT);
+
+	ndev->netdev_ops = &emac_netdev_ops;
+
+	return 0;
+free:

nit: This doesn't free anything.

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+	prueth->emac[mac] = NULL;
+
+	return ret;
+}

...

#9 lore raw

Re: [RFC v2 PATCH 02/10] net: ti: prueth: Adds ICSSM Ethernet driver

Quoted 77 lines · Basharath Hussain Khaja
Quoted 16 lines

From: Roger Quadros <[email protected]>

Updates Kernel configuration to enable PRUETH driver and its dependencies along with makefile changes to add the new PRUETH driver.

Changes includes init and deinit of ICSSM PRU Ethernet driver including net dev registration and firmware loading for DUAL-MAC mode running on PRU-ICSS2 instance.

Changes also includes link handling, PRU booting, default firmware loading and PRU stopping using existing remoteproc driver APIs.

...

Quoted 2 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

Quoted 38 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +38 -0
+static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
+				   struct net_device *ndev)
+{
+	const struct prueth_firmware *pru_firmwares;
+	struct prueth *prueth = emac->prueth;
+	const char *fw_name;
+	int ret;
+
+	pru_firmwares = &prueth->fw_data->fw_pru[emac->port_id - 1];
+	fw_name = pru_firmwares->fw_name[prueth->eth_type];
+	if (!fw_name) {
+		netdev_err(ndev, "eth_type %d not supported\n",
+			   prueth->eth_type);
+		return -ENODEV;
+	}
+
+	ret = rproc_set_firmware(emac->pru, fw_name);
+	if (ret) {
+		netdev_err(ndev, "failed to set PRU0 firmware %s: %d\n",
+			   fw_name, ret);
+		return ret;
+	}
+
+	ret = rproc_boot(emac->pru);
+	if (ret) {
+		netdev_err(ndev, "failed to boot PRU0: %d\n", ret);
+		return ret;
+	}
+
+	return ret;
+}
+
+/**
+ * icssm_emac_ndo_open - EMAC device open
+ * @ndev: network adapter device
+ *
+ * Called when system wants to start the interface.
+ *

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 124

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+ * Return: 0 for a successful open, or appropriate error code
+ */
+static int icssm_emac_ndo_open(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int ret;
+
+	ret = icssm_emac_set_boot_pru(emac, ndev);
+	if (ret)
+		netdev_err(ndev, "failed to boot PRU: %d\n", ret);

Hi Roger, Basharath, all,

Quoted 7 lines

icssm_emac_set_boot_pru() already logs errors, including the one above. So this log seems unnecessary to me.

Also, should an error be returned here? If so, it looks like icssm_emac_set_boot_pru() should release resources allocated by rproc_set_firmware() if rproc_boot() fails.

Agreed. We will remove the extra print and make sure allocated resources are released appropriately in the next version.

Quoted 70 lines
Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +6 -0
+
+	/* start PHY */
+	phy_start(emac->phydev);
+
+	return 0;
+}

...

Quoted 44 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +44 -0
+static int icssm_prueth_netdev_init(struct prueth *prueth,
+				    struct device_node *eth_node)
+{
+	struct prueth_emac *emac;
+	struct net_device *ndev;
+	enum prueth_port port;
+	enum prueth_mac mac;
+	int ret;
+
+	port = icssm_prueth_node_port(eth_node);
+	if (port == PRUETH_PORT_INVALID)
+		return -EINVAL;
+
+	mac = icssm_prueth_node_mac(eth_node);
+	if (mac == PRUETH_MAC_INVALID)
+		return -EINVAL;
+
+	ndev = devm_alloc_etherdev(prueth->dev, sizeof(*emac));
+	if (!ndev)
+		return -ENOMEM;
+
+	SET_NETDEV_DEV(ndev, prueth->dev);
+	emac = netdev_priv(ndev);
+	prueth->emac[mac] = emac;
+	emac->prueth = prueth;
+	emac->ndev = ndev;
+	emac->port_id = port;
+
+	/* by default eth_type is EMAC */
+	switch (port) {
+	case PRUETH_PORT_MII0:
+		emac->pru = prueth->pru0;
+		break;
+	case PRUETH_PORT_MII1:
+		emac->pru = prueth->pru1;
+		break;
+	default:
+		return -EINVAL;
+	}
+	/* get mac address from DT and set private and netdev addr */
+	ret = of_get_ethdev_address(eth_node, ndev);
+	if (!is_valid_ether_addr(ndev->dev_addr)) {
+		eth_hw_addr_random(ndev);
+		dev_warn(prueth->dev, "port %d: using random MAC addr: %pM\n",

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 246

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+			 port, ndev->dev_addr);
+	}
+	ether_addr_copy(emac->mac_addr, ndev->dev_addr);
+
+	/* connect PHY */
+	emac->phydev = of_phy_get_and_connect(ndev, eth_node,
+					      icssm_emac_adjust_link);
+	if (!emac->phydev) {
+		dev_dbg(prueth->dev, "PHY connection failed\n");
+		ret = -EPROBE_DEFER;

Perhaps I misunderstand things, but if this occurs then presumably icssm_prueth_netdev_init() will be called again. And for each time this occirs another ndev will be allocated by devm_alloc_etherdev(), each of which will only be freed once the device is eventually torn-down.

Quoted 5 lines

I wonder if it would be better to free ndev here.
Which I think would imply using a non-mdev allocation for symmetry.

Similarly for resources allocated in the caller icssm_prueth_probe().

Agreed, we will address this error case and free the resources appropriately.

Quoted 10 lines
Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		goto free;
+	}
+
+	/* remove unsupported modes */
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_10baseT_Full_BIT);
+
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_10baseT_Half_BIT);
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_100baseT_Half_BIT);
+
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_Pause_BIT);
Quoted 9 lines

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 262

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +6 -0
+	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_Asym_Pause_BIT);
+
+	ndev->netdev_ops = &emac_netdev_ops;
+
+	return 0;
+free:

nit: This doesn't free anything.

Sure. We will address in the next version.

Quoted 6 lines
Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+	prueth->emac[mac] = NULL;
+
+	return ret;
+}

...

Thanks & Best Regards,
Basharath

#10 lore raw

RFC PATCH v2 3/10 net: ti: prueth: Adds PRUETH HW and SW configuration

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Updates for MII_RT hardware peripheral configuration such as RX and TX configuration for PRU0 and PRU1, frame sizes, and MUX config.

Updates for PRU-ICSS firmware register configuration and DRAM, SRAM and OCMC memory initialization, which will be used in the runtime for packet reception and transmission.

DUAL-EMAC memory allocation for software queues and its supporting components such as the buffer descriptors and queue discriptors. These software queues are placed in OCMC memory and are shared with CPU by PRU-ICSS for packet receive and transmit.

All declarations and macros are being used from common header file for various protocols.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 424 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  94 ++++
 drivers/net/ethernet/ti/icssm/icssm_switch.h | 257 +++++++++++
 3 files changed, 773 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_switch.h
drivers/net/ethernet/ti/icssm/icssm_prueth.c +422 -2
index aec81962c6c2..82ed0e3a0d88 100644
@@ -29,6 +29,316 @@
 #include <net/pkt_cls.h>
 
 #include "icssm_prueth.h"
+#include "../icssg/icssg_mii_rt.h"
+
+#define OCMC_RAM_SIZE		(SZ_64K)
+
+#define TX_START_DELAY		0x40
+#define TX_CLK_DELAY_100M	0x6
+
+/* Below macro is for 1528 Byte Frame support, to Allow even with
+ * Redundancy tag
+ */
+#define PRUSS_MII_RT_RX_FRMS_MAX_SUPPORT_EMAC  (VLAN_ETH_FRAME_LEN + \
+						ETH_FCS_LEN + \
+						ICSSM_LRE_TAG_SIZE)
+
+/* ensure that order of PRUSS mem regions is same as enum prueth_mem */
+static enum pruss_mem pruss_mem_ids[] = { PRUSS_MEM_DRAM0, PRUSS_MEM_DRAM1,
+					  PRUSS_MEM_SHRD_RAM2 };
+
+static const struct prueth_queue_info queue_infos[][NUM_QUEUES] = {
+	[PRUETH_PORT_QUEUE_HOST] = {
+		[PRUETH_QUEUE1] = {
+			P0_Q1_BUFFER_OFFSET,
+			HOST_QUEUE_DESC_OFFSET,
+			P0_Q1_BD_OFFSET,
+			P0_Q1_BD_OFFSET + ((HOST_QUEUE_1_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE2] = {
+			P0_Q2_BUFFER_OFFSET,
+			HOST_QUEUE_DESC_OFFSET + 8,
+			P0_Q2_BD_OFFSET,
+			P0_Q2_BD_OFFSET + ((HOST_QUEUE_2_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE3] = {
+			P0_Q3_BUFFER_OFFSET,
+			HOST_QUEUE_DESC_OFFSET + 16,
+			P0_Q3_BD_OFFSET,
+			P0_Q3_BD_OFFSET + ((HOST_QUEUE_3_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE4] = {
+			P0_Q4_BUFFER_OFFSET,
+			HOST_QUEUE_DESC_OFFSET + 24,
+			P0_Q4_BD_OFFSET,
+			P0_Q4_BD_OFFSET + ((HOST_QUEUE_4_SIZE - 1) * BD_SIZE),
+		},
+	},
+	[PRUETH_PORT_QUEUE_MII0] = {
+		[PRUETH_QUEUE1] = {
+			P1_Q1_BUFFER_OFFSET,
+			P1_Q1_BUFFER_OFFSET + ((QUEUE_1_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P1_Q1_BD_OFFSET,
+			P1_Q1_BD_OFFSET + ((QUEUE_1_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE2] = {
+			P1_Q2_BUFFER_OFFSET,
+			P1_Q2_BUFFER_OFFSET + ((QUEUE_2_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P1_Q2_BD_OFFSET,
+			P1_Q2_BD_OFFSET + ((QUEUE_2_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE3] = {
+			P1_Q3_BUFFER_OFFSET,
+			P1_Q3_BUFFER_OFFSET + ((QUEUE_3_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P1_Q3_BD_OFFSET,
+			P1_Q3_BD_OFFSET + ((QUEUE_3_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE4] = {
+			P1_Q4_BUFFER_OFFSET,
+			P1_Q4_BUFFER_OFFSET + ((QUEUE_4_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P1_Q4_BD_OFFSET,
+			P1_Q4_BD_OFFSET + ((QUEUE_4_SIZE - 1) * BD_SIZE),
+		},
+	},
+	[PRUETH_PORT_QUEUE_MII1] = {
+		[PRUETH_QUEUE1] = {
+			P2_Q1_BUFFER_OFFSET,
+			P2_Q1_BUFFER_OFFSET + ((QUEUE_1_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P2_Q1_BD_OFFSET,
+			P2_Q1_BD_OFFSET + ((QUEUE_1_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE2] = {
+			P2_Q2_BUFFER_OFFSET,
+			P2_Q2_BUFFER_OFFSET + ((QUEUE_2_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P2_Q2_BD_OFFSET,
+			P2_Q2_BD_OFFSET + ((QUEUE_2_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE3] = {
+			P2_Q3_BUFFER_OFFSET,
+			P2_Q3_BUFFER_OFFSET + ((QUEUE_3_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P2_Q3_BD_OFFSET,
+			P2_Q3_BD_OFFSET + ((QUEUE_3_SIZE - 1) * BD_SIZE),
+		},
+		[PRUETH_QUEUE4] = {
+			P2_Q4_BUFFER_OFFSET,
+			P2_Q4_BUFFER_OFFSET + ((QUEUE_4_SIZE - 1) *
+					ICSS_BLOCK_SIZE),
+			P2_Q4_BD_OFFSET,
+			P2_Q4_BD_OFFSET + ((QUEUE_4_SIZE - 1) * BD_SIZE),
+		},
+	},
+};
+
+static const struct prueth_queue_desc queue_descs[][NUM_QUEUES] = {
+	[PRUETH_PORT_QUEUE_HOST] = {
+		{ .rd_ptr = P0_Q1_BD_OFFSET, .wr_ptr = P0_Q1_BD_OFFSET, },
+		{ .rd_ptr = P0_Q2_BD_OFFSET, .wr_ptr = P0_Q2_BD_OFFSET, },
+		{ .rd_ptr = P0_Q3_BD_OFFSET, .wr_ptr = P0_Q3_BD_OFFSET, },
+		{ .rd_ptr = P0_Q4_BD_OFFSET, .wr_ptr = P0_Q4_BD_OFFSET, },
+	},
+	[PRUETH_PORT_QUEUE_MII0] = {
+		{ .rd_ptr = P1_Q1_BD_OFFSET, .wr_ptr = P1_Q1_BD_OFFSET, },
+		{ .rd_ptr = P1_Q2_BD_OFFSET, .wr_ptr = P1_Q2_BD_OFFSET, },
+		{ .rd_ptr = P1_Q3_BD_OFFSET, .wr_ptr = P1_Q3_BD_OFFSET, },
+		{ .rd_ptr = P1_Q4_BD_OFFSET, .wr_ptr = P1_Q4_BD_OFFSET, },
+	},
+	[PRUETH_PORT_QUEUE_MII1] = {
+		{ .rd_ptr = P2_Q1_BD_OFFSET, .wr_ptr = P2_Q1_BD_OFFSET, },
+		{ .rd_ptr = P2_Q2_BD_OFFSET, .wr_ptr = P2_Q2_BD_OFFSET, },
+		{ .rd_ptr = P2_Q3_BD_OFFSET, .wr_ptr = P2_Q3_BD_OFFSET, },
+		{ .rd_ptr = P2_Q4_BD_OFFSET, .wr_ptr = P2_Q4_BD_OFFSET, },
+	}
+};
+
+static void icssm_prueth_hostconfig(struct prueth *prueth)
+{
+	void __iomem *sram_base = prueth->mem[PRUETH_MEM_SHARED_RAM].va;
+	void __iomem *sram;
+
+	/* queue size lookup table */
+	sram = sram_base + HOST_QUEUE_SIZE_ADDR;
+	writew(HOST_QUEUE_1_SIZE, sram);
+	writew(HOST_QUEUE_2_SIZE, sram + 2);
+	writew(HOST_QUEUE_3_SIZE, sram + 4);
+	writew(HOST_QUEUE_4_SIZE, sram + 6);
+
+	/* queue information table */
+	sram = sram_base + HOST_Q1_RX_CONTEXT_OFFSET;
+	memcpy_toio(sram, queue_infos[PRUETH_PORT_QUEUE_HOST],
+		    sizeof(queue_infos[PRUETH_PORT_QUEUE_HOST]));
+
+	/* buffer offset table */
+	sram = sram_base + HOST_QUEUE_OFFSET_ADDR;
+	writew(P0_Q1_BUFFER_OFFSET, sram);
+	writew(P0_Q2_BUFFER_OFFSET, sram + 2);
+	writew(P0_Q3_BUFFER_OFFSET, sram + 4);
+	writew(P0_Q4_BUFFER_OFFSET, sram + 6);
+
+	/* buffer descriptor offset table*/
+	sram = sram_base + HOST_QUEUE_DESCRIPTOR_OFFSET_ADDR;
+	writew(P0_Q1_BD_OFFSET, sram);
+	writew(P0_Q2_BD_OFFSET, sram + 2);
+	writew(P0_Q3_BD_OFFSET, sram + 4);
+	writew(P0_Q4_BD_OFFSET, sram + 6);
+
+	/* queue table */
+	sram = sram_base + HOST_QUEUE_DESC_OFFSET;
+	memcpy_toio(sram, queue_descs[PRUETH_PORT_QUEUE_HOST],
+		    sizeof(queue_descs[PRUETH_PORT_QUEUE_HOST]));
+}
+
+static void icssm_prueth_mii_init(struct prueth *prueth)
+{
+	struct regmap *mii_rt;
+	u32 rxcfg_reg, rxcfg;
+	u32 txcfg_reg, txcfg;
+
+	mii_rt = prueth->mii_rt;
+
+	rxcfg = PRUSS_MII_RT_RXCFG_RX_ENABLE |
+		PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DIS |
+		PRUSS_MII_RT_RXCFG_RX_L2_EN |
+		PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE |
+		PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS;
+
+	/* Configuration of Port 0 Rx */
+	rxcfg_reg = PRUSS_MII_RT_RXCFG0;
+
+	regmap_write(mii_rt, rxcfg_reg, rxcfg);
+
+	/* Configuration of Port 1 Rx */
+	rxcfg_reg = PRUSS_MII_RT_RXCFG1;
+
+	rxcfg |= PRUSS_MII_RT_RXCFG_RX_MUX_SEL;
+
+	regmap_write(mii_rt, rxcfg_reg, rxcfg);
+
+	txcfg = PRUSS_MII_RT_TXCFG_TX_ENABLE |
+		PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLE |
+		PRUSS_MII_RT_TXCFG_TX_32_MODE_EN |
+		(TX_START_DELAY << PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT) |
+		(TX_CLK_DELAY_100M << PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT);
+
+	/* Configuration of Port 0 Tx */
+	txcfg_reg = PRUSS_MII_RT_TXCFG0;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg	|= PRUSS_MII_RT_TXCFG_TX_MUX_SEL;
+
+	/* Configuration of Port 1 Tx */
+	txcfg_reg = PRUSS_MII_RT_TXCFG1;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg_reg = PRUSS_MII_RT_RX_FRMS0;
+
+	/* Min frame length should be set to 64 to allow receive of standard
+	 * Ethernet frames such as PTP, LLDP that will not have the tag/rct.
+	 * Actual size written to register is size - 1 per TRM. This also
+	 * includes CRC/FCS.
+	 */
+	txcfg = (((PRUSS_MII_RT_RX_FRMS_MIN_FRM - 1) <<
+			PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT) &
+			PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK);
+
+	/* For EMAC, set Max frame size to 1528 i.e size with VLAN.
+	 * Actual size written to register is size - 1 as per TRM.
+	 * Since driver support run time change of protocol, driver
+	 * must overwrite the values based on Ethernet type.
+	 */
+	txcfg |= (((PRUSS_MII_RT_RX_FRMS_MAX_SUPPORT_EMAC - 1) <<
+			   PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT)	&
+			   PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK);
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg_reg = PRUSS_MII_RT_RX_FRMS1;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+}
+
+static void icssm_prueth_clearmem(struct prueth *prueth, enum prueth_mem region)
+{
+	memset_io(prueth->mem[region].va, 0, prueth->mem[region].size);
+}
+
+static void icssm_prueth_hostinit(struct prueth *prueth)
+{
+	/* Clear shared RAM */
+	icssm_prueth_clearmem(prueth, PRUETH_MEM_SHARED_RAM);
+
+	/* Clear OCMC RAM */
+	icssm_prueth_clearmem(prueth, PRUETH_MEM_OCMC);
+
+	/* Clear data RAMs */
+	if (prueth->eth_node[PRUETH_MAC0])
+		icssm_prueth_clearmem(prueth, PRUETH_MEM_DRAM0);
+	if (prueth->eth_node[PRUETH_MAC1])
+		icssm_prueth_clearmem(prueth, PRUETH_MEM_DRAM1);
+
+	/* Initialize host queues in shared RAM */
+	icssm_prueth_hostconfig(prueth);
+
+	/* Configure MII_RT */
+	icssm_prueth_mii_init(prueth);
+}
+
+/* This function initialize the driver in EMAC or HSR or PRP mode
+ * based on eth_type
+ */
+static void icssm_prueth_init_ethernet_mode(struct prueth *prueth)
+{
+	icssm_prueth_hostinit(prueth);
+}
+
+static int icssm_prueth_emac_config(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+
+	/* PRU needs local shared RAM address for C28 */
+	u32 sharedramaddr = ICSS_LOCAL_SHARED_RAM;
+
+	/* PRU needs real global OCMC address for C30*/
+	u32 ocmcaddr = (u32)prueth->mem[PRUETH_MEM_OCMC].pa;
+	void __iomem *dram_base;
+	void __iomem *mac_addr;
+	void __iomem *dram;
+
+	/* Clear data RAM */
+	icssm_prueth_clearmem(prueth, emac->dram);
+
+	dram_base = prueth->mem[emac->dram].va;
+
+	/* setup mac address */
+	mac_addr = dram_base + PORT_MAC_ADDR;
+	memcpy_toio(mac_addr, emac->mac_addr, 6);
+
+	/* queue information table */
+	dram = dram_base + TX_CONTEXT_Q1_OFFSET_ADDR;
+	memcpy_toio(dram, queue_infos[emac->port_id],
+		    sizeof(queue_infos[emac->port_id]));
+
+	/* queue table */
+	dram = dram_base + PORT_QUEUE_DESC_OFFSET;
+	memcpy_toio(dram, queue_descs[emac->port_id],
+		    sizeof(queue_descs[emac->port_id]));
+
+	/* Set in constant table C28 of PRU0 to ICSS Shared memory */
+	pru_rproc_set_ctable(emac->pru, PRU_C28, sharedramaddr);
+
+	/* Set in constant table C30 of PRU0 to OCMC memory */
+	pru_rproc_set_ctable(emac->pru, PRU_C30, ocmcaddr);
+
+	return 0;
+}
 
 /* called back by PHY layer if there is change in link state of hw port*/
 static void icssm_emac_adjust_link(struct net_device *ndev)
@@ -117,15 +427,24 @@ static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
 static int icssm_emac_ndo_open(struct net_device *ndev)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth *prueth = emac->prueth;
 	int ret;
 
+	/* set h/w MAC as user might have re-configured */
+	ether_addr_copy(emac->mac_addr, ndev->dev_addr);
+
+	if (!prueth->emac_configured)
+		icssm_prueth_init_ethernet_mode(prueth);
+
+	icssm_prueth_emac_config(emac);
+
 	ret = icssm_emac_set_boot_pru(emac, ndev);
 	if (ret)
 		netdev_err(ndev, "failed to boot PRU: %d\n", ret);
 
 	/* start PHY */
 	phy_start(emac->phydev);
-
+	prueth->emac_configured |= BIT(emac->port_id);
 	return 0;
 }
 
@@ -221,9 +540,11 @@ static int icssm_prueth_netdev_init(struct prueth *prueth,
 	/* by default eth_type is EMAC */
 	switch (port) {
 	case PRUETH_PORT_MII0:
+		emac->dram = PRUETH_MEM_DRAM0;
 		emac->pru = prueth->pru0;
 		break;
 	case PRUETH_PORT_MII1:
+		emac->dram = PRUETH_MEM_DRAM1;
 		emac->pru = prueth->pru1;
 		break;
 	default:
@@ -292,6 +613,7 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct device_node *np;
 	struct prueth *prueth;
+	struct pruss *pruss;
 	int i, ret;
 
 	np = dev->of_node;
@@ -357,6 +679,12 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 	prueth->eth_node[PRUETH_MAC0] = eth0_node;
 	prueth->eth_node[PRUETH_MAC1] = eth1_node;
 
+	prueth->mii_rt = syscon_regmap_lookup_by_phandle(np, "ti,mii-rt");
+	if (IS_ERR(prueth->mii_rt)) {
+		dev_err(dev, "couldn't get mii-rt syscon regmap\n");
+		return -ENODEV;
+	}
+
 	if (eth0_node) {
 		prueth->pru0 = pru_rproc_get(np, 0, &pruss_id0);
 		if (IS_ERR(prueth->pru0)) {
@@ -377,6 +705,70 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 		}
 	}
 
+	pruss = pruss_get(prueth->pru0 ? prueth->pru0 : prueth->pru1);
+	if (IS_ERR(pruss)) {
+		ret = PTR_ERR(pruss);
+		dev_err(dev, "unable to get pruss handle\n");
+		goto put_pru;
+	}
+	prueth->pruss = pruss;
+
+	ret = pruss_cfg_ocp_master_ports(prueth->pruss, 1);
+	if (ret) {
+		dev_err(dev, "couldn't enabled ocp master port: %d\n", ret);
+		goto put_pruss;
+	}
+
+	/* Configure PRUSS */
+	if (eth0_node)
+		pruss_cfg_gpimode(pruss, pruss_id0, PRUSS_GPI_MODE_MII);
+	if (eth1_node)
+		pruss_cfg_gpimode(pruss, pruss_id1, PRUSS_GPI_MODE_MII);
+	pruss_cfg_miirt_enable(pruss, true);
+	pruss_cfg_xfr_enable(pruss, PRU_TYPE_PRU, true);
+
+	/* Get PRUSS mem resources */
+	/* OCMC is system resource which we get separately */
+	for (i = 0; i < ARRAY_SIZE(pruss_mem_ids); i++) {
+		/* skip appropriate DRAM if not required */
+		if (!eth0_node && i == PRUETH_MEM_DRAM0)
+			continue;
+
+		if (!eth1_node && i == PRUETH_MEM_DRAM1)
+			continue;
+
+		ret = pruss_request_mem_region(pruss, pruss_mem_ids[i],
+					       &prueth->mem[i]);
+		if (ret) {
+			dev_err(dev, "unable to get PRUSS resource %d: %d\n",
+				i, ret);
+			goto put_mem;
+		}
+	}
+
+	prueth->sram_pool = of_gen_pool_get(np, "sram", 0);
+	if (!prueth->sram_pool) {
+		dev_err(dev, "unable to get SRAM pool\n");
+		ret = -ENODEV;
+		goto put_mem;
+	}
+	prueth->mem[PRUETH_MEM_OCMC].va =
+			(void __iomem *)gen_pool_alloc(prueth->sram_pool,
+						       OCMC_RAM_SIZE);
+	if (!prueth->mem[PRUETH_MEM_OCMC].va) {
+		dev_err(dev, "unable to allocate OCMC resource\n");
+		ret = -ENOMEM;
+		goto put_mem;
+	}
+	prueth->mem[PRUETH_MEM_OCMC].pa = gen_pool_virt_to_phys
+		(prueth->sram_pool, (unsigned long)
+		 prueth->mem[PRUETH_MEM_OCMC].va);
+	prueth->mem[PRUETH_MEM_OCMC].size = OCMC_RAM_SIZE;
+	dev_dbg(dev, "ocmc: pa %pa va %p size %#zx\n",
+		&prueth->mem[PRUETH_MEM_OCMC].pa,
+		prueth->mem[PRUETH_MEM_OCMC].va,
+		prueth->mem[PRUETH_MEM_OCMC].size);
+
 	/* setup netdev interfaces */
 	if (eth0_node) {
 		ret = icssm_prueth_netdev_init(prueth, eth0_node);
@@ -385,7 +777,7 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 				dev_err(dev, "netdev init %s failed: %d\n",
 					eth0_node->name, ret);
 			}
-			goto put_pru;
+			goto free_pool;
 		}
 	}
 
@@ -423,6 +815,9 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 			prueth->emac[PRUETH_MAC1]->ndev;
 	}
 
+	dev_info(dev, "TI PRU ethernet driver initialized: %s EMAC mode\n",
+		 (!eth0_node || !eth1_node) ? "single" : "dual");
+
 	if (eth1_node)
 		of_node_put(eth1_node);
 	if (eth0_node)
@@ -445,6 +840,21 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 		icssm_prueth_netdev_exit(prueth, eth_node);
 	}
 
+free_pool:
+	gen_pool_free(prueth->sram_pool,
+		      (unsigned long)prueth->mem[PRUETH_MEM_OCMC].va,
+		      OCMC_RAM_SIZE);
+
+put_mem:
+	pruss_cfg_ocp_master_ports(prueth->pruss, 0);
+	for (i = PRUETH_MEM_DRAM0; i < PRUETH_MEM_OCMC; i++) {
+		if (prueth->mem[i].va)
+			pruss_release_mem_region(pruss, &prueth->mem[i]);
+	}
+
+put_pruss:
+	pruss_put(prueth->pruss);
+
 put_pru:
 	if (eth1_node) {
 		if (prueth->pru1)
@@ -482,6 +892,16 @@ static void icssm_prueth_remove(struct platform_device *pdev)
 		of_node_put(eth_node);
 	}
 
+	gen_pool_free(prueth->sram_pool,
+		      (unsigned long)prueth->mem[PRUETH_MEM_OCMC].va,
+		      OCMC_RAM_SIZE);
+
+	for (i = PRUETH_MEM_DRAM0; i < PRUETH_MEM_OCMC; i++) {
+		if (prueth->mem[i].va)
+			pruss_release_mem_region(prueth->pruss,
+						 &prueth->mem[i]);
+	}
+
 	pruss_put(prueth->pruss);
 
 	if (prueth->eth_node[PRUETH_MAC0])
drivers/net/ethernet/ti/icssm/icssm_prueth.h +94 -0

135 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_switch.h new file +257 -0

257 lines not on this page · raw message

Signature · 1 line
2.34.1
reviewer
#11 lore raw

Re: [RFC v2 PATCH 03/10] net: ti: prueth: Adds PRUETH HW and SW configuration

Quoted 11 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Updates for MII_RT hardware peripheral configuration such as RX and TX configuration for PRU0 and PRU1, frame sizes, and MUX config.

Updates for PRU-ICSS firmware register configuration and DRAM, SRAM and OCMC memory initialization, which will be used in the runtime for packet reception and transmission.

DUAL-EMAC memory allocation for software queues and its supporting components such as the buffer descriptors and queue discriptors. These

nit: descriptors

Quoted 10 lines

software queues are placed in OCMC memory and are shared with CPU by PRU-ICSS for packet receive and transmit.

All declarations and macros are being used from common header file for various protocols.

...

Quoted 1 line
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

Quoted 28 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +28 -0
+static void icssm_prueth_mii_init(struct prueth *prueth)
+{
+	struct regmap *mii_rt;
+	u32 rxcfg_reg, rxcfg;
+	u32 txcfg_reg, txcfg;
+
+	mii_rt = prueth->mii_rt;
+
+	rxcfg = PRUSS_MII_RT_RXCFG_RX_ENABLE |
+		PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DIS |
+		PRUSS_MII_RT_RXCFG_RX_L2_EN |
+		PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE |
+		PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS;
+
+	/* Configuration of Port 0 Rx */
+	rxcfg_reg = PRUSS_MII_RT_RXCFG0;
+
+	regmap_write(mii_rt, rxcfg_reg, rxcfg);
+
+	/* Configuration of Port 1 Rx */
+	rxcfg_reg = PRUSS_MII_RT_RXCFG1;
+
+	rxcfg |= PRUSS_MII_RT_RXCFG_RX_MUX_SEL;
+
+	regmap_write(mii_rt, rxcfg_reg, rxcfg);
+
+	txcfg = PRUSS_MII_RT_TXCFG_TX_ENABLE |
+		PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLE |

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 234

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		PRUSS_MII_RT_TXCFG_TX_32_MODE_EN |
+		(TX_START_DELAY << PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT) |
+		(TX_CLK_DELAY_100M << PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT);
+
+	/* Configuration of Port 0 Tx */
+	txcfg_reg = PRUSS_MII_RT_TXCFG0;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg	|= PRUSS_MII_RT_TXCFG_TX_MUX_SEL;

nit: a space seems more appropriate than a tab before '|='

Quoted 32 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +32 -0
+
+	/* Configuration of Port 1 Tx */
+	txcfg_reg = PRUSS_MII_RT_TXCFG1;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg_reg = PRUSS_MII_RT_RX_FRMS0;
+
+	/* Min frame length should be set to 64 to allow receive of standard
+	 * Ethernet frames such as PTP, LLDP that will not have the tag/rct.
+	 * Actual size written to register is size - 1 per TRM. This also
+	 * includes CRC/FCS.
+	 */
+	txcfg = (((PRUSS_MII_RT_RX_FRMS_MIN_FRM - 1) <<
+			PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT) &
+			PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK);
+
+	/* For EMAC, set Max frame size to 1528 i.e size with VLAN.
+	 * Actual size written to register is size - 1 as per TRM.
+	 * Since driver support run time change of protocol, driver
+	 * must overwrite the values based on Ethernet type.
+	 */
+	txcfg |= (((PRUSS_MII_RT_RX_FRMS_MAX_SUPPORT_EMAC - 1) <<
+			   PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT)	&
+			   PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK);
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg_reg = PRUSS_MII_RT_RX_FRMS1;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+}

...

Quoted 7 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +3 -0
@@ -377,6 +705,70 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 		}
 	}
 
+	pruss = pruss_get(prueth->pru0 ? prueth->pru0 : prueth->pru1);
+	if (IS_ERR(pruss)) {
+		ret = PTR_ERR(pruss);

drivers/net/ethernet/ti/icssm/icssm_prueth.c static int icssm_prueth_probe(struct platform_device *pdev) · line 720

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		dev_err(dev, "unable to get pruss handle\n");
+		goto put_pru;
+	}
+	prueth->pruss = pruss;
+
+	ret = pruss_cfg_ocp_master_ports(prueth->pruss, 1);
+	if (ret) {
+		dev_err(dev, "couldn't enabled ocp master port: %d\n", ret);
+		goto put_pruss;
+	}

FTR, I applied this patch set on top of the patch at the link below so that pruss_cfg_ocp_master_ports() is present.

- [PATCH v2 1/1] soc: ti: PRUSS OCP configuration
https://lore.kernel.org/all/[email protected]/

...

Quoted 1 line
drivers/net/ethernet/ti/icssm/icssm_prueth.h +0 -0

...

Quoted 2 lines

+/**
+ * struct prueth_queue - Information about a queue in memory

struct prueth_queue_info

Quoted 11 lines

+ * @buffer_offset: buffer offset in OCMC RAM
+ * @queue_desc_offset: queue descriptor offset in Shared RAM
+ * @buffer_desc_offset: buffer descriptors offset in Shared RAM
+ * @buffer_desc_end: end address of buffer descriptors in Shared RAM
+ */

drivers/net/ethernet/ti/icssm/icssm_prueth.h +6 -0
+struct prueth_queue_info {
+	u16 buffer_offset;
+	u16 queue_desc_offset;
+	u16 buffer_desc_offset;
+	u16 buffer_desc_end;
+} __packed;

...

#12 lore raw

Re: [RFC v2 PATCH 03/10] net: ti: prueth: Adds PRUETH HW and SW configuration

Quoted 6 lines · Basharath Hussain Khaja
Quoted 5 lines

From: Roger Quadros <[email protected]>

Updates for MII_RT hardware peripheral configuration such as RX and TX configuration for PRU0 and PRU1, frame sizes, and MUX config.

Quoted 9 lines
Quoted 6 lines

Updates for PRU-ICSS firmware register configuration and DRAM, SRAM and OCMC memory initialization, which will be used in the runtime for packet reception and transmission.

DUAL-EMAC memory allocation for software queues and its supporting components such as the buffer descriptors and queue discriptors. These

nit: descriptors

Sure. We will change in the next version.

Quoted 50 lines
Quoted 10 lines

software queues are placed in OCMC memory and are shared with CPU by PRU-ICSS for packet receive and transmit.

All declarations and macros are being used from common header file for various protocols.

...

Quoted 2 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

Quoted 32 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +32 -0
+static void icssm_prueth_mii_init(struct prueth *prueth)
+{
+	struct regmap *mii_rt;
+	u32 rxcfg_reg, rxcfg;
+	u32 txcfg_reg, txcfg;
+
+	mii_rt = prueth->mii_rt;
+
+	rxcfg = PRUSS_MII_RT_RXCFG_RX_ENABLE |
+		PRUSS_MII_RT_RXCFG_RX_DATA_RDY_MODE_DIS |
+		PRUSS_MII_RT_RXCFG_RX_L2_EN |
+		PRUSS_MII_RT_RXCFG_RX_CUT_PREAMBLE |
+		PRUSS_MII_RT_RXCFG_RX_L2_EOF_SCLR_DIS;
+
+	/* Configuration of Port 0 Rx */
+	rxcfg_reg = PRUSS_MII_RT_RXCFG0;
+
+	regmap_write(mii_rt, rxcfg_reg, rxcfg);
+
+	/* Configuration of Port 1 Rx */
+	rxcfg_reg = PRUSS_MII_RT_RXCFG1;
+
+	rxcfg |= PRUSS_MII_RT_RXCFG_RX_MUX_SEL;
+
+	regmap_write(mii_rt, rxcfg_reg, rxcfg);
+
+	txcfg = PRUSS_MII_RT_TXCFG_TX_ENABLE |
+		PRUSS_MII_RT_TXCFG_TX_AUTO_PREAMBLE |
+		PRUSS_MII_RT_TXCFG_TX_32_MODE_EN |
+		(TX_START_DELAY << PRUSS_MII_RT_TXCFG_TX_START_DELAY_SHIFT) |
+		(TX_CLK_DELAY_100M << PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT);
+
Quoted 9 lines

drivers/net/ethernet/ti/icssm/icssm_prueth.c line 234

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +6 -0
+	/* Configuration of Port 0 Tx */
+	txcfg_reg = PRUSS_MII_RT_TXCFG0;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg	|= PRUSS_MII_RT_TXCFG_TX_MUX_SEL;

nit: a space seems more appropriate than a tab before '|='

Sure. We will remove extra spaces in the next version.

Quoted 66 lines
Quoted 32 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +32 -0
+
+	/* Configuration of Port 1 Tx */
+	txcfg_reg = PRUSS_MII_RT_TXCFG1;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg_reg = PRUSS_MII_RT_RX_FRMS0;
+
+	/* Min frame length should be set to 64 to allow receive of standard
+	 * Ethernet frames such as PTP, LLDP that will not have the tag/rct.
+	 * Actual size written to register is size - 1 per TRM. This also
+	 * includes CRC/FCS.
+	 */
+	txcfg = (((PRUSS_MII_RT_RX_FRMS_MIN_FRM - 1) <<
+			PRUSS_MII_RT_RX_FRMS_MIN_FRM_SHIFT) &
+			PRUSS_MII_RT_RX_FRMS_MIN_FRM_MASK);
+
+	/* For EMAC, set Max frame size to 1528 i.e size with VLAN.
+	 * Actual size written to register is size - 1 as per TRM.
+	 * Since driver support run time change of protocol, driver
+	 * must overwrite the values based on Ethernet type.
+	 */
+	txcfg |= (((PRUSS_MII_RT_RX_FRMS_MAX_SUPPORT_EMAC - 1) <<
+			   PRUSS_MII_RT_RX_FRMS_MAX_FRM_SHIFT)	&
+			   PRUSS_MII_RT_RX_FRMS_MAX_FRM_MASK);
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+
+	txcfg_reg = PRUSS_MII_RT_RX_FRMS1;
+
+	regmap_write(mii_rt, txcfg_reg, txcfg);
+}

...

Quoted 7 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +3 -0
@@ -377,6 +705,70 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 		}
 	}
 
+	pruss = pruss_get(prueth->pru0 ? prueth->pru0 : prueth->pru1);
+	if (IS_ERR(pruss)) {
+		ret = PTR_ERR(pruss);

drivers/net/ethernet/ti/icssm/icssm_prueth.c static int icssm_prueth_probe(struct platform_device *pdev) · line 720

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		dev_err(dev, "unable to get pruss handle\n");
+		goto put_pru;
+	}
+	prueth->pruss = pruss;
+
+	ret = pruss_cfg_ocp_master_ports(prueth->pruss, 1);
+	if (ret) {
+		dev_err(dev, "couldn't enabled ocp master port: %d\n", ret);
+		goto put_pruss;
+	}

FTR, I applied this patch set on top of the patch at the link below so that pruss_cfg_ocp_master_ports() is present.

- [PATCH v2 1/1] soc: ti: PRUSS OCP configuration
https://lore.kernel.org/all/[email protected]/

...

Quoted 2 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +0 -0

...

Quoted 5 lines
Quoted 2 lines

+/**
+ * struct prueth_queue - Information about a queue in memory

struct prueth_queue_info

We will address this in the next version.

Quoted 5 lines
Quoted 5 lines

+ * @buffer_offset: buffer offset in OCMC RAM
+ * @queue_desc_offset: queue descriptor offset in Shared RAM
+ * @buffer_desc_offset: buffer descriptors offset in Shared RAM
+ * @buffer_desc_end: end address of buffer descriptors in Shared RAM
+ */

Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +6 -0
+struct prueth_queue_info {
+	u16 buffer_offset;
+	u16 queue_desc_offset;
+	u16 buffer_desc_offset;
+	u16 buffer_desc_end;
+} __packed;

...

Thanks & Best Regards,
Basharath

#13 lore raw

RFC PATCH v2 4/10 net: ti: prueth: Adds link detection, RX and TX support.

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +594 -5
index 82ed0e3a0d88..0ba1d16a7a15 100644
@@ -36,6 +36,13 @@
 #define TX_START_DELAY		0x40
 #define TX_CLK_DELAY_100M	0x6
 
+static inline void icssm_prueth_write_reg(struct prueth *prueth,
+					  enum prueth_mem region,
+					  unsigned int reg, u32 val)
+{
+	writel_relaxed(val, prueth->mem[region].va + reg);
+}
+
 /* Below macro is for 1528 Byte Frame support, to Allow even with
  * Redundancy tag
  */
@@ -299,18 +306,31 @@ static void icssm_prueth_init_ethernet_mode(struct prueth *prueth)
 	icssm_prueth_hostinit(prueth);
 }
 
-static int icssm_prueth_emac_config(struct prueth_emac *emac)
+static void icssm_prueth_port_enable(struct prueth_emac *emac, bool enable)
 {
 	struct prueth *prueth = emac->prueth;
+	void __iomem *port_ctrl;
+	void __iomem *ram;
 
-	/* PRU needs local shared RAM address for C28 */
-	u32 sharedramaddr = ICSS_LOCAL_SHARED_RAM;
+	ram = prueth->mem[emac->dram].va;
+	port_ctrl = ram + PORT_CONTROL_ADDR;
+	writeb(!!enable, port_ctrl);
+}
 
-	/* PRU needs real global OCMC address for C30*/
-	u32 ocmcaddr = (u32)prueth->mem[PRUETH_MEM_OCMC].pa;
+static int icssm_prueth_emac_config(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	u32 sharedramaddr, ocmcaddr;
 	void __iomem *dram_base;
 	void __iomem *mac_addr;
 	void __iomem *dram;
+	void __iomem *sram;
+
+	/* PRU needs local shared RAM address for C28 */
+	sharedramaddr = ICSS_LOCAL_SHARED_RAM;
+	/* PRU needs real global OCMC address for C30*/
+	ocmcaddr = (u32)prueth->mem[PRUETH_MEM_OCMC].pa;
+	sram = prueth->mem[PRUETH_MEM_SHARED_RAM].va;
 
 	/* Clear data RAM */
 	icssm_prueth_clearmem(prueth, emac->dram);
@@ -331,6 +351,9 @@ static int icssm_prueth_emac_config(struct prueth_emac *emac)
 	memcpy_toio(dram, queue_descs[emac->port_id],
 		    sizeof(queue_descs[emac->port_id]));
 
+	emac->rx_queue_descs = sram + HOST_QUEUE_DESC_OFFSET;
+	emac->tx_queue_descs = dram;
+
 	/* Set in constant table C28 of PRU0 to ICSS Shared memory */
 	pru_rproc_set_ctable(emac->pru, PRU_C28, sharedramaddr);
 
@@ -340,6 +363,40 @@ static int icssm_prueth_emac_config(struct prueth_emac *emac)
 	return 0;
 }
 
+/* update phy/port status information for firmware */
+static void icssm_emac_update_phystatus(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	u32 phy_speed, port_status = 0;
+	enum prueth_mem region;
+	u32 delay;
+
+	region = emac->dram;
+	phy_speed = emac->speed;
+	icssm_prueth_write_reg(prueth, region, PHY_SPEED_OFFSET, phy_speed);
+
+	delay = TX_CLK_DELAY_100M;
+
+	delay = delay << PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT;
+
+	if (emac->port_id) {
+		regmap_update_bits(prueth->mii_rt,
+				   PRUSS_MII_RT_TXCFG1,
+				   PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK,
+				   delay);
+	} else {
+		regmap_update_bits(prueth->mii_rt,
+				   PRUSS_MII_RT_TXCFG0,
+				   PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK,
+				   delay);
+	}
+
+	if (emac->link)
+		port_status |= PORT_LINK_MASK;
+
+	writeb(port_status, prueth->mem[region].va + PORT_STATUS_OFFSET);
+}
+
 /* called back by PHY layer if there is change in link state of hw port*/
 static void icssm_emac_adjust_link(struct net_device *ndev)
 {
@@ -369,6 +426,8 @@ static void icssm_emac_adjust_link(struct net_device *ndev)
 		emac->link = 0;
 	}
 
+	icssm_emac_update_phystatus(emac);
+
 	if (new_state)
 		phy_print_status(phydev);
 
@@ -384,6 +443,374 @@ static void icssm_emac_adjust_link(struct net_device *ndev)
 	spin_unlock_irqrestore(&emac->lock, flags);
 }
 
+/**
+ * icssm_prueth_tx_enqueue - queue a packet to firmware for transmission
+ *
+ * @emac: EMAC data structure
+ * @skb: packet data buffer
+ * @queue_id: priority queue id
+ *
+ * Return: 0 (Success)
+ */
+static int icssm_prueth_tx_enqueue(struct prueth_emac *emac,
+				   struct sk_buff *skb,
+				   enum prueth_queue_id queue_id)
+{
+	struct prueth_queue_desc __iomem *queue_desc;
+	const struct prueth_queue_info *txqueue;
+	u16 bd_rd_ptr, bd_wr_ptr, update_wr_ptr;
+	struct net_device *ndev = emac->ndev;
+	unsigned int buffer_desc_count;
+	int free_blocks, update_block;
+	bool buffer_wrapped = false;
+	int write_block, read_block;
+	void *src_addr, *dst_addr;
+	int pkt_block_size;
+	void __iomem *dram;
+	int txport, pktlen;
+	u32 wr_buf_desc;
+	void *ocmc_ram;
+
+	dram = emac->prueth->mem[emac->dram].va;
+	if (eth_skb_pad(skb)) {
+		if (netif_msg_tx_err(emac) && net_ratelimit())
+			netdev_err(ndev, "packet pad failed\n");
+		return -ENOMEM;
+	}
+
+	/* which port to tx: MII0 or MII1 */
+	txport = emac->tx_port_queue;
+	src_addr = skb->data;
+	pktlen = skb->len;
+	/* Get the tx queue */
+	queue_desc = emac->tx_queue_descs + queue_id;
+	txqueue = &queue_infos[txport][queue_id];
+
+	buffer_desc_count = txqueue->buffer_desc_end -
+			    txqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+
+	bd_rd_ptr = readw(&queue_desc->rd_ptr);
+	bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	write_block = (bd_wr_ptr - txqueue->buffer_desc_offset) / BD_SIZE;
+	read_block = (bd_rd_ptr - txqueue->buffer_desc_offset) / BD_SIZE;
+	if (write_block > read_block) {
+		free_blocks = buffer_desc_count - write_block;
+		free_blocks += read_block;
+	} else if (write_block < read_block) {
+		free_blocks = read_block - write_block;
+	} else { /* they are all free */
+		free_blocks = buffer_desc_count;
+	}
+
+	pkt_block_size = DIV_ROUND_UP(pktlen, ICSS_BLOCK_SIZE);
+	if (pkt_block_size > free_blocks) /* out of queue space */
+		return -ENOBUFS;
+
+	/* calculate end BD address post write */
+	update_block = write_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		buffer_wrapped = true;
+	}
+
+	/* OCMC RAM is not cached and write order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+	dst_addr = ocmc_ram + txqueue->buffer_offset +
+		   (write_block * ICSS_BLOCK_SIZE);
+
+	/* Copy the data from socket buffer(DRAM) to PRU buffers(OCMC) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - write_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pktlen < bytes)
+			bytes = pktlen;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		src_addr += bytes;
+		remaining = pktlen - bytes;
+		dst_addr = ocmc_ram + txqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+	} else {
+		memcpy(dst_addr, src_addr, pktlen);
+	}
+
+       /* update first buffer descriptor */
+	wr_buf_desc = (pktlen << PRUETH_BD_LENGTH_SHIFT) &
+		       PRUETH_BD_LENGTH_MASK;
+	writel(wr_buf_desc, dram + bd_wr_ptr);
+
+	/* update the write pointer in this queue descriptor, the firmware
+	 * polls for this change so this will signal the start of transmission
+	 */
+	update_wr_ptr = txqueue->buffer_desc_offset + (update_block * BD_SIZE);
+	writew(update_wr_ptr, &queue_desc->wr_ptr);
+
+	return 0;
+}
+
+void icssm_parse_packet_info(struct prueth *prueth, u32 buffer_descriptor,
+			     struct prueth_packet_info *pkt_info)
+{
+	pkt_info->start_offset = false;
+
+	pkt_info->shadow = !!(buffer_descriptor & PRUETH_BD_SHADOW_MASK);
+	pkt_info->port = (buffer_descriptor & PRUETH_BD_PORT_MASK) >>
+			 PRUETH_BD_PORT_SHIFT;
+	pkt_info->length = (buffer_descriptor & PRUETH_BD_LENGTH_MASK) >>
+			   PRUETH_BD_LENGTH_SHIFT;
+	pkt_info->broadcast = !!(buffer_descriptor & PRUETH_BD_BROADCAST_MASK);
+	pkt_info->error = !!(buffer_descriptor & PRUETH_BD_ERROR_MASK);
+	pkt_info->sv_frame = false;
+	pkt_info->lookup_success = !!(buffer_descriptor &
+				      PRUETH_BD_LOOKUP_SUCCESS_MASK);
+	pkt_info->flood = !!(buffer_descriptor & PRUETH_BD_SW_FLOOD_MASK);
+	pkt_info->timestamp = !!(buffer_descriptor & PRUETH_BD_TIMESTAMP_MASK);
+}
+
+/* get packet from queue
+ * negative for error
+ */
+int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr,
+			 struct prueth_packet_info *pkt_info,
+			 const struct prueth_queue_info *rxqueue)
+{
+	struct net_device *ndev = emac->ndev;
+	unsigned int buffer_desc_count;
+	int read_block, update_block;
+	unsigned int actual_pkt_len;
+	bool buffer_wrapped = false;
+	void *src_addr, *dst_addr;
+	u16 start_offset = 0;
+	struct sk_buff *skb;
+	int pkt_block_size;
+	void *ocmc_ram;
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	buffer_desc_count = rxqueue->buffer_desc_end -
+			    rxqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+	read_block = (*bd_rd_ptr - rxqueue->buffer_desc_offset) / BD_SIZE;
+	pkt_block_size = DIV_ROUND_UP(pkt_info->length, ICSS_BLOCK_SIZE);
+
+	/* calculate end BD address post read */
+	update_block = read_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		if (update_block)
+			buffer_wrapped = true;
+	}
+
+	/* calculate new pointer in ram */
+	*bd_rd_ptr = rxqueue->buffer_desc_offset + (update_block * BD_SIZE);
+
+	/* Pkt len w/ HSR tag removed, If applicable */
+	actual_pkt_len = pkt_info->length - start_offset;
+
+	/* Allocate a socket buffer for this packet */
+	skb = netdev_alloc_skb_ip_align(ndev, actual_pkt_len);
+	if (!skb) {
+		if (netif_msg_rx_err(emac) && net_ratelimit())
+			netdev_err(ndev, "failed rx buffer alloc\n");
+		return -ENOMEM;
+	}
+
+	dst_addr = skb->data;
+
+	/* OCMC RAM is not cached and read order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+
+	/* Get the start address of the first buffer from
+	 * the read buffer description
+	 */
+	src_addr = ocmc_ram + rxqueue->buffer_offset +
+		   (read_block * ICSS_BLOCK_SIZE);
+	src_addr += start_offset;
+
+	/* Copy the data from PRU buffers(OCMC) to socket buffer(DRAM) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - read_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pkt_info->length < bytes)
+			bytes = pkt_info->length;
+
+		/* If applicable, account for the HSR tag removed */
+		bytes -= start_offset;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		dst_addr += bytes;
+		remaining = actual_pkt_len - bytes;
+
+		src_addr = ocmc_ram + rxqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+		src_addr += remaining;
+	} else {
+		memcpy(dst_addr, src_addr, actual_pkt_len);
+		src_addr += actual_pkt_len;
+	}
+
+	if (!pkt_info->sv_frame) {
+		skb_put(skb, actual_pkt_len);
+
+		/* send packet up the stack */
+		skb->protocol = eth_type_trans(skb, ndev);
+		local_bh_disable();
+		netif_receive_skb(skb);
+		local_bh_enable();
+	} else {
+		dev_kfree_skb_any(skb);
+	}
+
+	/* update stats */
+	ndev->stats.rx_bytes += actual_pkt_len;
+	ndev->stats.rx_packets++;
+
+	return 0;
+}
+
+/**
+ * icssm_emac_rx_thread - EMAC Rx interrupt thread handler
+ * @irq: interrupt number
+ * @dev_id: pointer to net_device
+ *
+ * EMAC Rx Interrupt thread handler - function to process the rx frames in a
+ * irq thread function. There is only limited buffer at the ingress to
+ * queue the frames. As the frames are to be emptied as quickly as
+ * possible to avoid overflow, irq thread is necessary. Current implementation
+ * based on NAPI poll results in packet loss due to overflow at
+ * the ingress queues. Industrial use case requires loss free packet
+ * processing. Tests shows that with threaded irq based processing,
+ * no overflow happens when receiving at ~92Mbps for MTU sized frames and thus
+ * meet the requirement for industrial use case.
+ *
+ * Return: interrupt handled condition
+ */
+static irqreturn_t icssm_emac_rx_thread(int irq, void *dev_id)
+{
+	struct net_device *ndev = (struct net_device *)dev_id;
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_queue_desc __iomem *queue_desc;
+	const struct prueth_queue_info *rxqueue;
+	struct prueth *prueth = emac->prueth;
+	struct net_device_stats *ndevstats;
+	struct prueth_packet_info pkt_info;
+	int start_queue, end_queue;
+	void __iomem *shared_ram;
+	u16 bd_rd_ptr, bd_wr_ptr;
+	u16 update_rd_ptr;
+	u8 overflow_cnt;
+	u32 rd_buf_desc;
+	int used = 0;
+	int i, ret;
+
+	ndevstats = &emac->ndev->stats;
+	shared_ram = emac->prueth->mem[PRUETH_MEM_SHARED_RAM].va;
+
+	start_queue = emac->rx_queue_start;
+	end_queue = emac->rx_queue_end;
+retry:
+	/* search host queues for packets */
+	for (i = start_queue; i <= end_queue; i++) {
+		queue_desc = emac->rx_queue_descs + i;
+		rxqueue = &queue_infos[PRUETH_PORT_HOST][i];
+
+		overflow_cnt = readb(&queue_desc->overflow_cnt);
+		if (overflow_cnt > 0) {
+			emac->ndev->stats.rx_over_errors += overflow_cnt;
+			/* reset to zero */
+			writeb(0, &queue_desc->overflow_cnt);
+		}
+
+		bd_rd_ptr = readw(&queue_desc->rd_ptr);
+		bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+		/* while packets are available in this queue */
+		while (bd_rd_ptr != bd_wr_ptr) {
+			/* get packet info from the read buffer descriptor */
+			rd_buf_desc = readl(shared_ram + bd_rd_ptr);
+			icssm_parse_packet_info(prueth, rd_buf_desc, &pkt_info);
+
+			if (pkt_info.length <= 0) {
+				/* a packet length of zero will cause us to
+				 * never move the read pointer ahead, locking
+				 * the driver, so we manually have to move it
+				 * to the write pointer, discarding all
+				 * remaining packets in this queue. This should
+				 * never happen.
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;
+			} else if (pkt_info.length > EMAC_MAX_FRM_SUPPORT) {
+				/* if the packet is too large we skip it but we
+				 * still need to move the read pointer ahead
+				 * and assume something is wrong with the read
+				 * pointer as the firmware should be filtering
+				 * these packets
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;
+			} else {
+				update_rd_ptr = bd_rd_ptr;
+				ret = icssm_emac_rx_packet(emac, &update_rd_ptr,
+							   &pkt_info, rxqueue);
+				if (ret)
+					return IRQ_HANDLED;
+				used++;
+			}
+
+			/* after reading the buffer descriptor we clear it
+			 * to prevent improperly moved read pointer errors
+			 * from simply looking like old packets.
+			 */
+			writel(0, shared_ram + bd_rd_ptr);
+
+			/* update read pointer in queue descriptor */
+			writew(update_rd_ptr, &queue_desc->rd_ptr);
+			bd_rd_ptr = update_rd_ptr;
+		}
+	}
+
+	if (used) {
+		used = 0;
+		goto retry;
+	}
+
+	return IRQ_HANDLED;
+}
+
 static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
 				   struct net_device *ndev)
 {
@@ -412,6 +839,21 @@ static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
 		netdev_err(ndev, "failed to boot PRU0: %d\n", ret);
 		return ret;
 	}
+	return ret;
+}
+
+static int icssm_emac_request_irqs(struct prueth_emac *emac)
+{
+	struct net_device *ndev = emac->ndev;
+	int ret;
+
+	ret = request_threaded_irq(emac->rx_irq, NULL, icssm_emac_rx_thread,
+				   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+				   ndev->name, ndev);
+	if (ret) {
+		netdev_err(ndev, "unable to request RX IRQ\n");
+		return ret;
+	}
 
 	return ret;
 }
@@ -442,10 +884,27 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 	if (ret)
 		netdev_err(ndev, "failed to boot PRU: %d\n", ret);
 
+	ret = icssm_emac_request_irqs(emac);
+	if (ret)
+		goto rproc_shutdown;
+
 	/* start PHY */
 	phy_start(emac->phydev);
+
+	/* enable the port and vlan */
+	icssm_prueth_port_enable(emac, true);
+
 	prueth->emac_configured |= BIT(emac->port_id);
+
+	if (netif_msg_drv(emac))
+		dev_notice(&ndev->dev, "started\n");
+
 	return 0;
+
+rproc_shutdown:
+	rproc_shutdown(emac->pru);
+
+	return ret;
 }
 
 /**
@@ -459,18 +918,122 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 static int icssm_emac_ndo_stop(struct net_device *ndev)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth *prueth = emac->prueth;
+
+	prueth->emac_configured &= ~BIT(emac->port_id);
+
+	/* disable the mac port */
+	icssm_prueth_port_enable(emac, false);
 
 	/* stop PHY */
 	phy_stop(emac->phydev);
 
+	/* stop the PRU */
 	rproc_shutdown(emac->pru);
 
+	/* free rx and tx interrupts */
+	if (emac->tx_irq > 0)
+		free_irq(emac->tx_irq, ndev);
+
+	free_irq(emac->rx_irq, ndev);
+
+	if (netif_msg_drv(emac))
+		dev_notice(&ndev->dev, "stopped\n");
+
 	return 0;
 }
 
+/* VLAN-tag PCP to priority queue map for EMAC/Switch/HSR/PRP used by driver
+ * Index is PCP val / 2.
+ *   low  - pcp 0..3 maps to Q4 for Host
+ *   high - pcp 4..7 maps to Q3 for Host
+ *   low  - pcp 0..3 maps to Q2 (FWD Queue) for PRU-x
+ *   where x = 1 for PRUETH_PORT_MII0
+ *             0 for PRUETH_PORT_MII1
+ *   high - pcp 4..7 maps to Q1 (FWD Queue) for PRU-x
+ */
+static const unsigned short emac_pcp_tx_priority_queue_map[] = {
+	PRUETH_QUEUE4, PRUETH_QUEUE4,
+	PRUETH_QUEUE3, PRUETH_QUEUE3,
+	PRUETH_QUEUE2, PRUETH_QUEUE2,
+	PRUETH_QUEUE1, PRUETH_QUEUE1,
+};
+
+static u16 icssm_prueth_get_tx_queue_id(struct prueth *prueth,
+					struct sk_buff *skb)
+{
+	u16 vlan_tci, pcp;
+	int err;
+
+	err = vlan_get_tag(skb, &vlan_tci);
+	if (likely(err))
+		pcp = 0;
+	else
+		pcp = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
+
+	/* Below code (pcp >>= 1) is made common for all
+	 * protocols (i.e., EMAC, RSTP, HSR and PRP)*
+	 * pcp value 0,1 will be updated to 0 mapped to QUEUE4
+	 * pcp value 2,3 will be updated to 1 mapped to QUEUE4
+	 * pcp value 4,5 will be updated to 2 mapped to QUEUE3
+	 * pcp value 6,7 will be updated to 3 mapped to QUEUE3
+	 */
+	pcp >>= 1;
+
+	return emac_pcp_tx_priority_queue_map[pcp];
+}
+
+/**
+ * icssm_emac_ndo_start_xmit - EMAC Transmit function
+ * @skb: SKB pointer
+ * @ndev: EMAC network adapter
+ *
+ * Called by the system to transmit a packet  - we queue the packet in
+ * EMAC hardware transmit queue
+ *
+ * Return: success(NETDEV_TX_OK) or error code (typically out of desc's)
+ */
+static int icssm_emac_ndo_start_xmit(struct sk_buff *skb,
+				     struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int ret;
+	u16 qid;
+
+	qid = icssm_prueth_get_tx_queue_id(emac->prueth, skb);
+	ret = icssm_prueth_tx_enqueue(emac, skb, qid);
+	if (ret) {
+		if (ret != -ENOBUFS && netif_msg_tx_err(emac) &&
+		    net_ratelimit())
+			netdev_err(ndev, "packet queue failed: %d\n", ret);
+		goto fail_tx;
+	}
+
+	ndev->stats.tx_packets++;
+	ndev->stats.tx_bytes += skb->len;
+	dev_kfree_skb_any(skb);
+
+	return NETDEV_TX_OK;
+
+fail_tx:
+	if (ret == -ENOBUFS) {
+		/* no free TX queue */
+		if (emac->tx_irq > 0)
+			netif_stop_queue(ndev);
+		ret = NETDEV_TX_BUSY;
+	} else {
+		/* error */
+		ndev->stats.tx_dropped++;
+		ret = NET_XMIT_DROP;
+	}
+
+	return ret;
+}
+
 static const struct net_device_ops emac_netdev_ops = {
 	.ndo_open = icssm_emac_ndo_open,
 	.ndo_stop = icssm_emac_ndo_stop,
+	.ndo_start_xmit = icssm_emac_ndo_start_xmit,
 };
 
 /* get emac_port corresponding to eth_node name */
@@ -540,16 +1103,42 @@ static int icssm_prueth_netdev_init(struct prueth *prueth,
 	/* by default eth_type is EMAC */
 	switch (port) {
 	case PRUETH_PORT_MII0:
+		emac->tx_port_queue = PRUETH_PORT_QUEUE_MII0;
+
+		/* packets from MII0 are on queues 1 through 2 */
+		emac->rx_queue_start = PRUETH_QUEUE1;
+		emac->rx_queue_end = PRUETH_QUEUE2;
+
 		emac->dram = PRUETH_MEM_DRAM0;
 		emac->pru = prueth->pru0;
 		break;
 	case PRUETH_PORT_MII1:
+		emac->tx_port_queue = PRUETH_PORT_QUEUE_MII1;
+
+		/* packets from MII1 are on queues 3 through 4 */
+		emac->rx_queue_start = PRUETH_QUEUE3;
+		emac->rx_queue_end = PRUETH_QUEUE4;
+
 		emac->dram = PRUETH_MEM_DRAM1;
 		emac->pru = prueth->pru1;
 		break;
 	default:
 		return -EINVAL;
 	}
+
+	emac->rx_irq = of_irq_get_byname(eth_node, "rx");
+	if (emac->rx_irq < 0) {
+		ret = emac->rx_irq;
+		if (ret != -EPROBE_DEFER)
+			dev_err(prueth->dev, "could not get rx irq\n");
+		goto free;
+	}
+	emac->tx_irq = of_irq_get_byname(eth_node, "tx");
+	if (emac->tx_irq < 0) {
+		if (emac->tx_irq != -EPROBE_DEFER)
+			dev_dbg(prueth->dev, "tx irq not configured\n");
+	}
+
 	/* get mac address from DT and set private and netdev addr */
 	ret = of_get_ethdev_address(eth_node, ndev);
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
drivers/net/ethernet/ti/icssm/icssm_prueth.h +46 -0

76 lines not on this page · raw message

Signature · 1 line
2.34.1
#14 lore raw

Re: [RFC v2 PATCH 04/10] net: ti: prueth: Adds link detection, RX and TX support.

Quoted 27 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0
index 82ed0e3a0d88..0ba1d16a7a15 100644

[...]

Quoted 13 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +13 -0
+/**
+ * icssm_prueth_tx_enqueue - queue a packet to firmware for transmission
+ *
+ * @emac: EMAC data structure
+ * @skb: packet data buffer
+ * @queue_id: priority queue id
+ *
+ * Return: 0 (Success)
+ */
+static int icssm_prueth_tx_enqueue(struct prueth_emac *emac,
+				   struct sk_buff *skb,
+				   enum prueth_queue_id queue_id)
+{

[...]

Quoted 14 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +14 -0
+
+	/* which port to tx: MII0 or MII1 */
+	txport = emac->tx_port_queue;
+	src_addr = skb->data;
+	pktlen = skb->len;
+	/* Get the tx queue */
+	queue_desc = emac->tx_queue_descs + queue_id;
+	txqueue = &queue_infos[txport][queue_id];
+
+	buffer_desc_count = txqueue->buffer_desc_end -
+			    txqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 503

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	bd_rd_ptr = readw(&queue_desc->rd_ptr);
+	bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	write_block = (bd_wr_ptr - txqueue->buffer_desc_offset) / BD_SIZE;
+	read_block = (bd_rd_ptr - txqueue->buffer_desc_offset) / BD_SIZE;

Seems like there's a lot of similar code repeated in the rx code path.

Maybe there's a way to simplify it all with a helper of some sort?

Quoted 65 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +65 -0
+	if (write_block > read_block) {
+		free_blocks = buffer_desc_count - write_block;
+		free_blocks += read_block;
+	} else if (write_block < read_block) {
+		free_blocks = read_block - write_block;
+	} else { /* they are all free */
+		free_blocks = buffer_desc_count;
+	}
+
+	pkt_block_size = DIV_ROUND_UP(pktlen, ICSS_BLOCK_SIZE);
+	if (pkt_block_size > free_blocks) /* out of queue space */
+		return -ENOBUFS;
+
+	/* calculate end BD address post write */
+	update_block = write_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		buffer_wrapped = true;
+	}
+
+	/* OCMC RAM is not cached and write order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+	dst_addr = ocmc_ram + txqueue->buffer_offset +
+		   (write_block * ICSS_BLOCK_SIZE);
+
+	/* Copy the data from socket buffer(DRAM) to PRU buffers(OCMC) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - write_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pktlen < bytes)
+			bytes = pktlen;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		src_addr += bytes;
+		remaining = pktlen - bytes;
+		dst_addr = ocmc_ram + txqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+	} else {
+		memcpy(dst_addr, src_addr, pktlen);
+	}
+
+       /* update first buffer descriptor */
+	wr_buf_desc = (pktlen << PRUETH_BD_LENGTH_SHIFT) &
+		       PRUETH_BD_LENGTH_MASK;
+	writel(wr_buf_desc, dram + bd_wr_ptr);
+
+	/* update the write pointer in this queue descriptor, the firmware
+	 * polls for this change so this will signal the start of transmission
+	 */
+	update_wr_ptr = txqueue->buffer_desc_offset + (update_block * BD_SIZE);
+	writew(update_wr_ptr, &queue_desc->wr_ptr);
+
+	return 0;
+}

[...]

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 591

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+
+/* get packet from queue
+ * negative for error
+ */

The comment above seems superfluous and does not seem to follow the format of the tx comment which appears to use kdoc style

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr,
+			 struct prueth_packet_info *pkt_info,
+			 const struct prueth_queue_info *rxqueue)
+{

[...]

Quoted 15 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +15 -0
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	buffer_desc_count = rxqueue->buffer_desc_end -
+			    rxqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+	read_block = (*bd_rd_ptr - rxqueue->buffer_desc_offset) / BD_SIZE;
+	pkt_block_size = DIV_ROUND_UP(pkt_info->length, ICSS_BLOCK_SIZE);
+
+	/* calculate end BD address post read */
+	update_block = read_block + pkt_block_size;

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 630

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		if (update_block)
+			buffer_wrapped = true;
+	}
+
+	/* calculate new pointer in ram */
+	*bd_rd_ptr = rxqueue->buffer_desc_offset + (update_block * BD_SIZE);

Seems like there's a lot of repeated math here and in the above function. Maybe this can be simplified with a helper function to avoid repeating the math in multiple places?

Quoted 59 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +59 -0
+
+	/* Pkt len w/ HSR tag removed, If applicable */
+	actual_pkt_len = pkt_info->length - start_offset;
+
+	/* Allocate a socket buffer for this packet */
+	skb = netdev_alloc_skb_ip_align(ndev, actual_pkt_len);
+	if (!skb) {
+		if (netif_msg_rx_err(emac) && net_ratelimit())
+			netdev_err(ndev, "failed rx buffer alloc\n");
+		return -ENOMEM;
+	}
+
+	dst_addr = skb->data;
+
+	/* OCMC RAM is not cached and read order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+
+	/* Get the start address of the first buffer from
+	 * the read buffer description
+	 */
+	src_addr = ocmc_ram + rxqueue->buffer_offset +
+		   (read_block * ICSS_BLOCK_SIZE);
+	src_addr += start_offset;
+
+	/* Copy the data from PRU buffers(OCMC) to socket buffer(DRAM) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - read_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pkt_info->length < bytes)
+			bytes = pkt_info->length;
+
+		/* If applicable, account for the HSR tag removed */
+		bytes -= start_offset;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		dst_addr += bytes;
+		remaining = actual_pkt_len - bytes;
+
+		src_addr = ocmc_ram + rxqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+		src_addr += remaining;
+	} else {
+		memcpy(dst_addr, src_addr, actual_pkt_len);
+		src_addr += actual_pkt_len;
+	}
+
+	if (!pkt_info->sv_frame) {
+		skb_put(skb, actual_pkt_len);
+
+		/* send packet up the stack */
+		skb->protocol = eth_type_trans(skb, ndev);

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 699

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		local_bh_disable();
+		netif_receive_skb(skb);
+		local_bh_enable();
+	} else {
+		dev_kfree_skb_any(skb);
+	}
+
+	/* update stats */
+	ndev->stats.rx_bytes += actual_pkt_len;
+	ndev->stats.rx_packets++;

See comment below about atomicity.

Quoted 7 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +7 -0
+	return 0;
+}
+
+/**
+ * icssm_emac_rx_thread - EMAC Rx interrupt thread handler
+ * @irq: interrupt number
+ * @dev_id: pointer to net_device

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 717

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+ *
+ * EMAC Rx Interrupt thread handler - function to process the rx frames in a
+ * irq thread function. There is only limited buffer at the ingress to
+ * queue the frames. As the frames are to be emptied as quickly as
+ * possible to avoid overflow, irq thread is necessary. Current implementation
+ * based on NAPI poll results in packet loss due to overflow at
+ * the ingress queues. Industrial use case requires loss free packet
+ * processing. Tests shows that with threaded irq based processing,
+ * no overflow happens when receiving at ~92Mbps for MTU sized frames and thus
+ * meet the requirement for industrial use case.

That's interesting. Any idea why this is the case? Is there not enough CPU for softirq/NAPI processing to run or something? I suppose I'd imagine that NAPI would run and if data is arriving fast enough, the NAPI would be added to the repoll list and processed later.

So I guess either there isn't enough CPU or the ingress queues don't have many descriptors or something like that ?

Quoted 12 lines

+ *
+ * Return: interrupt handled condition
+ */

drivers/net/ethernet/ti/icssm/icssm_prueth.c +9 -0
+static irqreturn_t icssm_emac_rx_thread(int irq, void *dev_id)
+{
+	struct net_device *ndev = (struct net_device *)dev_id;
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_queue_desc __iomem *queue_desc;
+	const struct prueth_queue_info *rxqueue;
+	struct prueth *prueth = emac->prueth;
+	struct net_device_stats *ndevstats;
+	struct prueth_packet_info pkt_info;

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 739

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	int start_queue, end_queue;
+	void __iomem *shared_ram;
+	u16 bd_rd_ptr, bd_wr_ptr;
+	u16 update_rd_ptr;
+	u8 overflow_cnt;
+	u32 rd_buf_desc;
+	int used = 0;
+	int i, ret;
+
+	ndevstats = &emac->ndev->stats;

FWIW the docs in include/linux/netdevice.h say:

/**
...
* @stats: Statistics struct, which was left as a legacy, use
* rtnl_link_stats64 instead
...
*/
struct net_device {
...
struct net_device_stats stats; /* not used by modern drivers */
...
};

perhaps consider using rtnl_link_stats64 as suggested instead?

Quoted 26 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +26 -0
+	shared_ram = emac->prueth->mem[PRUETH_MEM_SHARED_RAM].va;
+
+	start_queue = emac->rx_queue_start;
+	end_queue = emac->rx_queue_end;
+retry:
+	/* search host queues for packets */
+	for (i = start_queue; i <= end_queue; i++) {
+		queue_desc = emac->rx_queue_descs + i;
+		rxqueue = &queue_infos[PRUETH_PORT_HOST][i];
+
+		overflow_cnt = readb(&queue_desc->overflow_cnt);
+		if (overflow_cnt > 0) {
+			emac->ndev->stats.rx_over_errors += overflow_cnt;
+			/* reset to zero */
+			writeb(0, &queue_desc->overflow_cnt);
+		}
+
+		bd_rd_ptr = readw(&queue_desc->rd_ptr);
+		bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+		/* while packets are available in this queue */
+		while (bd_rd_ptr != bd_wr_ptr) {
+			/* get packet info from the read buffer descriptor */
+			rd_buf_desc = readl(shared_ram + bd_rd_ptr);
+			icssm_parse_packet_info(prueth, rd_buf_desc, &pkt_info);
+

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 775

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+			if (pkt_info.length <= 0) {
+				/* a packet length of zero will cause us to
+				 * never move the read pointer ahead, locking
+				 * the driver, so we manually have to move it
+				 * to the write pointer, discarding all
+				 * remaining packets in this queue. This should
+				 * never happen.
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;

See question below.

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 784

Quoted 9 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +9 -0
+			} else if (pkt_info.length > EMAC_MAX_FRM_SUPPORT) {
+				/* if the packet is too large we skip it but we
+				 * still need to move the read pointer ahead
+				 * and assume something is wrong with the read
+				 * pointer as the firmware should be filtering
+				 * these packets
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;

in netdevice.h it says:

* struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);

*      Called when a user wants to get the network device usage
*      statistics. Drivers must do one of the following:
*      1. Define @ndo_get_stats64 to fill in a zero-initialised
*         rtnl_link_stats64 structure passed by the caller.
*      2. Define @ndo_get_stats to update a net_device_stats structure
*         (which should normally be dev->stats) and return a pointer to
*         it. The structure may be changed asynchronously only if each
*         field is written atomically.

* 3. Update dev->stats asynchronously and atomically, and define
* neither operation.

I didn't look in the other patches to see if ndo_get_stats is defined or not, but are these increments atomic?

#15 lore raw

Re: [RFC v2 PATCH 04/10] net: ti: prueth: Adds link detection, RX and TX support.

Quoted 76 lines · Basharath Hussain Khaja
Quoted 28 lines

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0
index 82ed0e3a0d88..0ba1d16a7a15 100644

[...]

Quoted 13 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +13 -0
+/**
+ * icssm_prueth_tx_enqueue - queue a packet to firmware for transmission
+ *
+ * @emac: EMAC data structure
+ * @skb: packet data buffer
+ * @queue_id: priority queue id
+ *
+ * Return: 0 (Success)
+ */
+static int icssm_prueth_tx_enqueue(struct prueth_emac *emac,
+				   struct sk_buff *skb,
+				   enum prueth_queue_id queue_id)
+{

[...]

Quoted 14 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +14 -0
+
+	/* which port to tx: MII0 or MII1 */
+	txport = emac->tx_port_queue;
+	src_addr = skb->data;
+	pktlen = skb->len;
+	/* Get the tx queue */
+	queue_desc = emac->tx_queue_descs + queue_id;
+	txqueue = &queue_infos[txport][queue_id];
+
+	buffer_desc_count = txqueue->buffer_desc_end -
+			    txqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 503

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	bd_rd_ptr = readw(&queue_desc->rd_ptr);
+	bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	write_block = (bd_wr_ptr - txqueue->buffer_desc_offset) / BD_SIZE;
+	read_block = (bd_rd_ptr - txqueue->buffer_desc_offset) / BD_SIZE;

Seems like there's a lot of similar code repeated in the rx code path.

Quoted 2 lines

Maybe there's a way to simplify it all with a helper of some sort?

We will plan to re-look into common code (more than twice) and create a helper function and use it.

Quoted 68 lines
Quoted 65 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +65 -0
+	if (write_block > read_block) {
+		free_blocks = buffer_desc_count - write_block;
+		free_blocks += read_block;
+	} else if (write_block < read_block) {
+		free_blocks = read_block - write_block;
+	} else { /* they are all free */
+		free_blocks = buffer_desc_count;
+	}
+
+	pkt_block_size = DIV_ROUND_UP(pktlen, ICSS_BLOCK_SIZE);
+	if (pkt_block_size > free_blocks) /* out of queue space */
+		return -ENOBUFS;
+
+	/* calculate end BD address post write */
+	update_block = write_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		buffer_wrapped = true;
+	}
+
+	/* OCMC RAM is not cached and write order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+	dst_addr = ocmc_ram + txqueue->buffer_offset +
+		   (write_block * ICSS_BLOCK_SIZE);
+
+	/* Copy the data from socket buffer(DRAM) to PRU buffers(OCMC) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - write_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pktlen < bytes)
+			bytes = pktlen;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		src_addr += bytes;
+		remaining = pktlen - bytes;
+		dst_addr = ocmc_ram + txqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+	} else {
+		memcpy(dst_addr, src_addr, pktlen);
+	}
+
+       /* update first buffer descriptor */
+	wr_buf_desc = (pktlen << PRUETH_BD_LENGTH_SHIFT) &
+		       PRUETH_BD_LENGTH_MASK;
+	writel(wr_buf_desc, dram + bd_wr_ptr);
+
+	/* update the write pointer in this queue descriptor, the firmware
+	 * polls for this change so this will signal the start of transmission
+	 */
+	update_wr_ptr = txqueue->buffer_desc_offset + (update_block * BD_SIZE);
+	writew(update_wr_ptr, &queue_desc->wr_ptr);
+
+	return 0;
+}

[...]

Quoted 8 lines

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 591

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+
+/* get packet from queue
+ * negative for error
+ */

The comment above seems superfluous and does not seem to follow the format of the tx comment which appears to use kdoc style

We will address in the next version.

Quoted 28 lines
Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr,
+			 struct prueth_packet_info *pkt_info,
+			 const struct prueth_queue_info *rxqueue)
+{

[...]

Quoted 21 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +21 -0
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	buffer_desc_count = rxqueue->buffer_desc_end -
+			    rxqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+	read_block = (*bd_rd_ptr - rxqueue->buffer_desc_offset) / BD_SIZE;
+	pkt_block_size = DIV_ROUND_UP(pkt_info->length, ICSS_BLOCK_SIZE);
+
+	/* calculate end BD address post read */
+	update_block = read_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		if (update_block)
+			buffer_wrapped = true;
Quoted 9 lines

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 630

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+	}
+
+	/* calculate new pointer in ram */
+	*bd_rd_ptr = rxqueue->buffer_desc_offset + (update_block * BD_SIZE);

Seems like there's a lot of repeated math here and in the above function. Maybe this can be simplified with a helper function to avoid repeating the math in multiple places?

We will plan to re-look into common code (more than twice) and create a helper function and use it.

Quoted 96 lines
Quoted 59 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +59 -0
+
+	/* Pkt len w/ HSR tag removed, If applicable */
+	actual_pkt_len = pkt_info->length - start_offset;
+
+	/* Allocate a socket buffer for this packet */
+	skb = netdev_alloc_skb_ip_align(ndev, actual_pkt_len);
+	if (!skb) {
+		if (netif_msg_rx_err(emac) && net_ratelimit())
+			netdev_err(ndev, "failed rx buffer alloc\n");
+		return -ENOMEM;
+	}
+
+	dst_addr = skb->data;
+
+	/* OCMC RAM is not cached and read order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+
+	/* Get the start address of the first buffer from
+	 * the read buffer description
+	 */
+	src_addr = ocmc_ram + rxqueue->buffer_offset +
+		   (read_block * ICSS_BLOCK_SIZE);
+	src_addr += start_offset;
+
+	/* Copy the data from PRU buffers(OCMC) to socket buffer(DRAM) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - read_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pkt_info->length < bytes)
+			bytes = pkt_info->length;
+
+		/* If applicable, account for the HSR tag removed */
+		bytes -= start_offset;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		dst_addr += bytes;
+		remaining = actual_pkt_len - bytes;
+
+		src_addr = ocmc_ram + rxqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+		src_addr += remaining;
+	} else {
+		memcpy(dst_addr, src_addr, actual_pkt_len);
+		src_addr += actual_pkt_len;
+	}
+
+	if (!pkt_info->sv_frame) {
+		skb_put(skb, actual_pkt_len);
+
+		/* send packet up the stack */
+		skb->protocol = eth_type_trans(skb, ndev);

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 699

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		local_bh_disable();
+		netif_receive_skb(skb);
+		local_bh_enable();
+	} else {
+		dev_kfree_skb_any(skb);
+	}
+
+	/* update stats */
+	ndev->stats.rx_bytes += actual_pkt_len;
+	ndev->stats.rx_packets++;

See comment below about atomicity.

Quoted 7 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +7 -0
+	return 0;
+}
+
+/**
+ * icssm_emac_rx_thread - EMAC Rx interrupt thread handler
+ * @irq: interrupt number
+ * @dev_id: pointer to net_device

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 717

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+ *
+ * EMAC Rx Interrupt thread handler - function to process the rx frames in a
+ * irq thread function. There is only limited buffer at the ingress to
+ * queue the frames. As the frames are to be emptied as quickly as
+ * possible to avoid overflow, irq thread is necessary. Current implementation
+ * based on NAPI poll results in packet loss due to overflow at
+ * the ingress queues. Industrial use case requires loss free packet
+ * processing. Tests shows that with threaded irq based processing,
+ * no overflow happens when receiving at ~92Mbps for MTU sized frames and thus
+ * meet the requirement for industrial use case.

That's interesting. Any idea why this is the case? Is there not enough CPU for softirq/NAPI processing to run or something? I suppose I'd imagine that NAPI would run and if data is arriving fast enough, the NAPI would be added to the repoll list and processed later.

Quoted 3 lines

So I guess either there isn't enough CPU or the ingress queues don't have many descriptors or something like that ?

This is due to combination of both limited number of buffer descriptors (memory constraints) and also not having enough CPU.

Quoted 99 lines
Quoted 12 lines

+ *
+ * Return: interrupt handled condition
+ */

drivers/net/ethernet/ti/icssm/icssm_prueth.c +9 -0
+static irqreturn_t icssm_emac_rx_thread(int irq, void *dev_id)
+{
+	struct net_device *ndev = (struct net_device *)dev_id;
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_queue_desc __iomem *queue_desc;
+	const struct prueth_queue_info *rxqueue;
+	struct prueth *prueth = emac->prueth;
+	struct net_device_stats *ndevstats;
+	struct prueth_packet_info pkt_info;

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 739

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	int start_queue, end_queue;
+	void __iomem *shared_ram;
+	u16 bd_rd_ptr, bd_wr_ptr;
+	u16 update_rd_ptr;
+	u8 overflow_cnt;
+	u32 rd_buf_desc;
+	int used = 0;
+	int i, ret;
+
+	ndevstats = &emac->ndev->stats;

FWIW the docs in include/linux/netdevice.h say:

/**
...
* @stats: Statistics struct, which was left as a legacy, use
* rtnl_link_stats64 instead
...
*/
struct net_device {
...
struct net_device_stats stats; /* not used by modern drivers */
...
};

perhaps consider using rtnl_link_stats64 as suggested instead?

Quoted 26 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +26 -0
+	shared_ram = emac->prueth->mem[PRUETH_MEM_SHARED_RAM].va;
+
+	start_queue = emac->rx_queue_start;
+	end_queue = emac->rx_queue_end;
+retry:
+	/* search host queues for packets */
+	for (i = start_queue; i <= end_queue; i++) {
+		queue_desc = emac->rx_queue_descs + i;
+		rxqueue = &queue_infos[PRUETH_PORT_HOST][i];
+
+		overflow_cnt = readb(&queue_desc->overflow_cnt);
+		if (overflow_cnt > 0) {
+			emac->ndev->stats.rx_over_errors += overflow_cnt;
+			/* reset to zero */
+			writeb(0, &queue_desc->overflow_cnt);
+		}
+
+		bd_rd_ptr = readw(&queue_desc->rd_ptr);
+		bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+		/* while packets are available in this queue */
+		while (bd_rd_ptr != bd_wr_ptr) {
+			/* get packet info from the read buffer descriptor */
+			rd_buf_desc = readl(shared_ram + bd_rd_ptr);
+			icssm_parse_packet_info(prueth, rd_buf_desc, &pkt_info);
+

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 775

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+			if (pkt_info.length <= 0) {
+				/* a packet length of zero will cause us to
+				 * never move the read pointer ahead, locking
+				 * the driver, so we manually have to move it
+				 * to the write pointer, discarding all
+				 * remaining packets in this queue. This should
+				 * never happen.
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;

See question below.

drivers/net/ethernet/ti/icssm/icssm_prueth.c static void icssm_emac_adjust_link(struct net_device *ndev) · line 784

Quoted 9 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +9 -0
+			} else if (pkt_info.length > EMAC_MAX_FRM_SUPPORT) {
+				/* if the packet is too large we skip it but we
+				 * still need to move the read pointer ahead
+				 * and assume something is wrong with the read
+				 * pointer as the firmware should be filtering
+				 * these packets
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;

in netdevice.h it says:

* struct net_device_stats* (*ndo_get_stats)(struct net_device *dev);

*      Called when a user wants to get the network device usage
*      statistics. Drivers must do one of the following:
*      1. Define @ndo_get_stats64 to fill in a zero-initialised
*         rtnl_link_stats64 structure passed by the caller.
*      2. Define @ndo_get_stats to update a net_device_stats structure
*         (which should normally be dev->stats) and return a pointer to
*         it. The structure may be changed asynchronously only if each
*         field is written atomically.
Quoted 5 lines

* 3. Update dev->stats asynchronously and atomically, and define
* neither operation.

I didn't look in the other patches to see if ndo_get_stats is defined or not, but are these increments atomic?

This module maintain 32 bit statistics inside PRU firmware. we will check the feasibility of using rtnl_link_stats64 and make appropriate changes as per your suggestion in next version.

Thanks & Best Regards,
Basharath

reviewer
#16 lore raw

Re: [RFC v2 PATCH 04/10] net: ti: prueth: Adds link detection, RX and TX support.

In reply to Basharath Hussain Khaja
Quoted 24 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

drivers/net/ethernet/ti/icssm/icssm_prueth.c static int icssm_emac_ndo_open(struct net_device *ndev) · line 997

Quoted 12 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +12 -0
+/**
+ * icssm_emac_ndo_start_xmit - EMAC Transmit function
+ * @skb: SKB pointer
+ * @ndev: EMAC network adapter
+ *
+ * Called by the system to transmit a packet  - we queue the packet in
+ * EMAC hardware transmit queue
+ *
+ * Return: success(NETDEV_TX_OK) or error code (typically out of desc's)
+ */
+static int icssm_emac_ndo_start_xmit(struct sk_buff *skb,
+				     struct net_device *ndev)

I think the return type of this function should be netdev_tx_t rather than int to match the signature of ndo_start_xmit in struct net_device_ops.

Flagged by W=1 build with clang-19
(-Wincompatible-function-pointer-types-strict).

...

Quoted 7 lines

static const struct net_device_ops emac_netdev_ops = {

drivers/net/ethernet/ti/icssm/icssm_prueth.c +1 -0
 	.ndo_open = icssm_emac_ndo_open,
 	.ndo_stop = icssm_emac_ndo_stop,
+	.ndo_start_xmit = icssm_emac_ndo_start_xmit,
 };
 
 /* get emac_port corresponding to eth_node name */

...

Quoted 1 line
drivers/net/ethernet/ti/icssm/icssm_prueth.h +0 -0

...

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +2 -0
@@ -76,6 +82,32 @@ struct prueth_queue_info {
 	u16 buffer_desc_end;
 } __packed;
 
+/**
+ * struct prueth_packet_info - Info about a packet in buffer

drivers/net/ethernet/ti/icssm/icssm_prueth.h struct prueth_queue_info { · line 96

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +10 -0
+ * @start_offset: start offset of the frame in the buffer for HSR/PRP
+ * @shadow: this packet is stored in the collision queue
+ * @port: port packet is on
+ * @length: length of packet
+ * @broadcast: this packet is a broadcast packet
+ * @error: this packet has an error
+ * @sv_frame: indicate if the frame is a SV frame for HSR/PRP
+ * @lookup_success: src mac found in FDB
+ * @flood: packet is to be flooded
+ * @timstamp: Specifies if timestamp is appended to the packet

nit: @timestamp

Quoted 13 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +13 -0
+ */
+struct prueth_packet_info {
+	bool start_offset;
+	bool shadow;
+	unsigned int port;
+	unsigned int length;
+	bool broadcast;
+	bool error;
+	bool sv_frame;
+	bool lookup_success;
+	bool flood;
+	bool timestamp;
+};

...

#17 lore raw

Re: [RFC v2 PATCH 04/10] net: ti: prueth: Adds link detection, RX and TX support.

Quoted 47 lines · Basharath Hussain Khaja
Quoted 25 lines

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

drivers/net/ethernet/ti/icssm/icssm_prueth.c static int icssm_emac_ndo_open(struct net_device *ndev) · line 997

Quoted 12 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +12 -0
+/**
+ * icssm_emac_ndo_start_xmit - EMAC Transmit function
+ * @skb: SKB pointer
+ * @ndev: EMAC network adapter
+ *
+ * Called by the system to transmit a packet  - we queue the packet in
+ * EMAC hardware transmit queue
+ *
+ * Return: success(NETDEV_TX_OK) or error code (typically out of desc's)
+ */
+static int icssm_emac_ndo_start_xmit(struct sk_buff *skb,
+				     struct net_device *ndev)

I think the return type of this function should be netdev_tx_t rather than int to match the signature of ndo_start_xmit in struct net_device_ops.

Quoted 3 lines

Flagged by W=1 build with clang-19
(-Wincompatible-function-pointer-types-strict).

We will change the return type in the next version.

Quoted 21 lines

...

Quoted 7 lines

static const struct net_device_ops emac_netdev_ops = {

drivers/net/ethernet/ti/icssm/icssm_prueth.c +1 -0
 	.ndo_open = icssm_emac_ndo_open,
 	.ndo_stop = icssm_emac_ndo_stop,
+	.ndo_start_xmit = icssm_emac_ndo_start_xmit,
 };
 
 /* get emac_port corresponding to eth_node name */

...

Quoted 2 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +0 -0

...

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +0 -0
@@ -76,6 +82,32 @@ struct prueth_queue_info {
 	u16 buffer_desc_end;
 } __packed;
 
Quoted 15 lines

drivers/net/ethernet/ti/icssm/icssm_prueth.h struct prueth_queue_info { · line 96

Quoted 12 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +12 -0
+/**
+ * struct prueth_packet_info - Info about a packet in buffer
+ * @start_offset: start offset of the frame in the buffer for HSR/PRP
+ * @shadow: this packet is stored in the collision queue
+ * @port: port packet is on
+ * @length: length of packet
+ * @broadcast: this packet is a broadcast packet
+ * @error: this packet has an error
+ * @sv_frame: indicate if the frame is a SV frame for HSR/PRP
+ * @lookup_success: src mac found in FDB
+ * @flood: packet is to be flooded
+ * @timstamp: Specifies if timestamp is appended to the packet

nit: @timestamp

We will address this in the next version.

Quoted 7 lines
Quoted 7 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +7 -0
+ */
+struct prueth_packet_info {
+	bool start_offset;
+	bool shadow;
+	unsigned int port;
+	unsigned int length;
+	bool broadcast;
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.h +6 -0
+	bool error;
+	bool sv_frame;
+	bool lookup_success;
+	bool flood;
+	bool timestamp;
+};

...

Thanks & Best Regards,
Basharath

#18 lore raw

RFC PATCH v2 4/10 net: ti: prueth: Adds link detection, RX and TX support.

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +594 -5
index 82ed0e3a0d88..0ba1d16a7a15 100644
@@ -36,6 +36,13 @@
 #define TX_START_DELAY		0x40
 #define TX_CLK_DELAY_100M	0x6
 
+static inline void icssm_prueth_write_reg(struct prueth *prueth,
+					  enum prueth_mem region,
+					  unsigned int reg, u32 val)
+{
+	writel_relaxed(val, prueth->mem[region].va + reg);
+}
+
 /* Below macro is for 1528 Byte Frame support, to Allow even with
  * Redundancy tag
  */
@@ -299,18 +306,31 @@ static void icssm_prueth_init_ethernet_mode(struct prueth *prueth)
 	icssm_prueth_hostinit(prueth);
 }
 
-static int icssm_prueth_emac_config(struct prueth_emac *emac)
+static void icssm_prueth_port_enable(struct prueth_emac *emac, bool enable)
 {
 	struct prueth *prueth = emac->prueth;
+	void __iomem *port_ctrl;
+	void __iomem *ram;
 
-	/* PRU needs local shared RAM address for C28 */
-	u32 sharedramaddr = ICSS_LOCAL_SHARED_RAM;
+	ram = prueth->mem[emac->dram].va;
+	port_ctrl = ram + PORT_CONTROL_ADDR;
+	writeb(!!enable, port_ctrl);
+}
 
-	/* PRU needs real global OCMC address for C30*/
-	u32 ocmcaddr = (u32)prueth->mem[PRUETH_MEM_OCMC].pa;
+static int icssm_prueth_emac_config(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	u32 sharedramaddr, ocmcaddr;
 	void __iomem *dram_base;
 	void __iomem *mac_addr;
 	void __iomem *dram;
+	void __iomem *sram;
+
+	/* PRU needs local shared RAM address for C28 */
+	sharedramaddr = ICSS_LOCAL_SHARED_RAM;
+	/* PRU needs real global OCMC address for C30*/
+	ocmcaddr = (u32)prueth->mem[PRUETH_MEM_OCMC].pa;
+	sram = prueth->mem[PRUETH_MEM_SHARED_RAM].va;
 
 	/* Clear data RAM */
 	icssm_prueth_clearmem(prueth, emac->dram);
@@ -331,6 +351,9 @@ static int icssm_prueth_emac_config(struct prueth_emac *emac)
 	memcpy_toio(dram, queue_descs[emac->port_id],
 		    sizeof(queue_descs[emac->port_id]));
 
+	emac->rx_queue_descs = sram + HOST_QUEUE_DESC_OFFSET;
+	emac->tx_queue_descs = dram;
+
 	/* Set in constant table C28 of PRU0 to ICSS Shared memory */
 	pru_rproc_set_ctable(emac->pru, PRU_C28, sharedramaddr);
 
@@ -340,6 +363,40 @@ static int icssm_prueth_emac_config(struct prueth_emac *emac)
 	return 0;
 }
 
+/* update phy/port status information for firmware */
+static void icssm_emac_update_phystatus(struct prueth_emac *emac)
+{
+	struct prueth *prueth = emac->prueth;
+	u32 phy_speed, port_status = 0;
+	enum prueth_mem region;
+	u32 delay;
+
+	region = emac->dram;
+	phy_speed = emac->speed;
+	icssm_prueth_write_reg(prueth, region, PHY_SPEED_OFFSET, phy_speed);
+
+	delay = TX_CLK_DELAY_100M;
+
+	delay = delay << PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_SHIFT;
+
+	if (emac->port_id) {
+		regmap_update_bits(prueth->mii_rt,
+				   PRUSS_MII_RT_TXCFG1,
+				   PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK,
+				   delay);
+	} else {
+		regmap_update_bits(prueth->mii_rt,
+				   PRUSS_MII_RT_TXCFG0,
+				   PRUSS_MII_RT_TXCFG_TX_CLK_DELAY_MASK,
+				   delay);
+	}
+
+	if (emac->link)
+		port_status |= PORT_LINK_MASK;
+
+	writeb(port_status, prueth->mem[region].va + PORT_STATUS_OFFSET);
+}
+
 /* called back by PHY layer if there is change in link state of hw port*/
 static void icssm_emac_adjust_link(struct net_device *ndev)
 {
@@ -369,6 +426,8 @@ static void icssm_emac_adjust_link(struct net_device *ndev)
 		emac->link = 0;
 	}
 
+	icssm_emac_update_phystatus(emac);
+
 	if (new_state)
 		phy_print_status(phydev);
 
@@ -384,6 +443,374 @@ static void icssm_emac_adjust_link(struct net_device *ndev)
 	spin_unlock_irqrestore(&emac->lock, flags);
 }
 
+/**
+ * icssm_prueth_tx_enqueue - queue a packet to firmware for transmission
+ *
+ * @emac: EMAC data structure
+ * @skb: packet data buffer
+ * @queue_id: priority queue id
+ *
+ * Return: 0 (Success)
+ */
+static int icssm_prueth_tx_enqueue(struct prueth_emac *emac,
+				   struct sk_buff *skb,
+				   enum prueth_queue_id queue_id)
+{
+	struct prueth_queue_desc __iomem *queue_desc;
+	const struct prueth_queue_info *txqueue;
+	u16 bd_rd_ptr, bd_wr_ptr, update_wr_ptr;
+	struct net_device *ndev = emac->ndev;
+	unsigned int buffer_desc_count;
+	int free_blocks, update_block;
+	bool buffer_wrapped = false;
+	int write_block, read_block;
+	void *src_addr, *dst_addr;
+	int pkt_block_size;
+	void __iomem *dram;
+	int txport, pktlen;
+	u32 wr_buf_desc;
+	void *ocmc_ram;
+
+	dram = emac->prueth->mem[emac->dram].va;
+	if (eth_skb_pad(skb)) {
+		if (netif_msg_tx_err(emac) && net_ratelimit())
+			netdev_err(ndev, "packet pad failed\n");
+		return -ENOMEM;
+	}
+
+	/* which port to tx: MII0 or MII1 */
+	txport = emac->tx_port_queue;
+	src_addr = skb->data;
+	pktlen = skb->len;
+	/* Get the tx queue */
+	queue_desc = emac->tx_queue_descs + queue_id;
+	txqueue = &queue_infos[txport][queue_id];
+
+	buffer_desc_count = txqueue->buffer_desc_end -
+			    txqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+
+	bd_rd_ptr = readw(&queue_desc->rd_ptr);
+	bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	write_block = (bd_wr_ptr - txqueue->buffer_desc_offset) / BD_SIZE;
+	read_block = (bd_rd_ptr - txqueue->buffer_desc_offset) / BD_SIZE;
+	if (write_block > read_block) {
+		free_blocks = buffer_desc_count - write_block;
+		free_blocks += read_block;
+	} else if (write_block < read_block) {
+		free_blocks = read_block - write_block;
+	} else { /* they are all free */
+		free_blocks = buffer_desc_count;
+	}
+
+	pkt_block_size = DIV_ROUND_UP(pktlen, ICSS_BLOCK_SIZE);
+	if (pkt_block_size > free_blocks) /* out of queue space */
+		return -ENOBUFS;
+
+	/* calculate end BD address post write */
+	update_block = write_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		buffer_wrapped = true;
+	}
+
+	/* OCMC RAM is not cached and write order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+	dst_addr = ocmc_ram + txqueue->buffer_offset +
+		   (write_block * ICSS_BLOCK_SIZE);
+
+	/* Copy the data from socket buffer(DRAM) to PRU buffers(OCMC) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - write_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pktlen < bytes)
+			bytes = pktlen;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		src_addr += bytes;
+		remaining = pktlen - bytes;
+		dst_addr = ocmc_ram + txqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+	} else {
+		memcpy(dst_addr, src_addr, pktlen);
+	}
+
+       /* update first buffer descriptor */
+	wr_buf_desc = (pktlen << PRUETH_BD_LENGTH_SHIFT) &
+		       PRUETH_BD_LENGTH_MASK;
+	writel(wr_buf_desc, dram + bd_wr_ptr);
+
+	/* update the write pointer in this queue descriptor, the firmware
+	 * polls for this change so this will signal the start of transmission
+	 */
+	update_wr_ptr = txqueue->buffer_desc_offset + (update_block * BD_SIZE);
+	writew(update_wr_ptr, &queue_desc->wr_ptr);
+
+	return 0;
+}
+
+void icssm_parse_packet_info(struct prueth *prueth, u32 buffer_descriptor,
+			     struct prueth_packet_info *pkt_info)
+{
+	pkt_info->start_offset = false;
+
+	pkt_info->shadow = !!(buffer_descriptor & PRUETH_BD_SHADOW_MASK);
+	pkt_info->port = (buffer_descriptor & PRUETH_BD_PORT_MASK) >>
+			 PRUETH_BD_PORT_SHIFT;
+	pkt_info->length = (buffer_descriptor & PRUETH_BD_LENGTH_MASK) >>
+			   PRUETH_BD_LENGTH_SHIFT;
+	pkt_info->broadcast = !!(buffer_descriptor & PRUETH_BD_BROADCAST_MASK);
+	pkt_info->error = !!(buffer_descriptor & PRUETH_BD_ERROR_MASK);
+	pkt_info->sv_frame = false;
+	pkt_info->lookup_success = !!(buffer_descriptor &
+				      PRUETH_BD_LOOKUP_SUCCESS_MASK);
+	pkt_info->flood = !!(buffer_descriptor & PRUETH_BD_SW_FLOOD_MASK);
+	pkt_info->timestamp = !!(buffer_descriptor & PRUETH_BD_TIMESTAMP_MASK);
+}
+
+/* get packet from queue
+ * negative for error
+ */
+int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr,
+			 struct prueth_packet_info *pkt_info,
+			 const struct prueth_queue_info *rxqueue)
+{
+	struct net_device *ndev = emac->ndev;
+	unsigned int buffer_desc_count;
+	int read_block, update_block;
+	unsigned int actual_pkt_len;
+	bool buffer_wrapped = false;
+	void *src_addr, *dst_addr;
+	u16 start_offset = 0;
+	struct sk_buff *skb;
+	int pkt_block_size;
+	void *ocmc_ram;
+
+	/* the PRU firmware deals mostly in pointers already
+	 * offset into ram, we would like to deal in indexes
+	 * within the queue we are working with for code
+	 * simplicity, calculate this here
+	 */
+	buffer_desc_count = rxqueue->buffer_desc_end -
+			    rxqueue->buffer_desc_offset;
+	buffer_desc_count /= BD_SIZE;
+	buffer_desc_count++;
+	read_block = (*bd_rd_ptr - rxqueue->buffer_desc_offset) / BD_SIZE;
+	pkt_block_size = DIV_ROUND_UP(pkt_info->length, ICSS_BLOCK_SIZE);
+
+	/* calculate end BD address post read */
+	update_block = read_block + pkt_block_size;
+
+	/* Check for wrap around */
+	if (update_block >= buffer_desc_count) {
+		update_block %= buffer_desc_count;
+		if (update_block)
+			buffer_wrapped = true;
+	}
+
+	/* calculate new pointer in ram */
+	*bd_rd_ptr = rxqueue->buffer_desc_offset + (update_block * BD_SIZE);
+
+	/* Pkt len w/ HSR tag removed, If applicable */
+	actual_pkt_len = pkt_info->length - start_offset;
+
+	/* Allocate a socket buffer for this packet */
+	skb = netdev_alloc_skb_ip_align(ndev, actual_pkt_len);
+	if (!skb) {
+		if (netif_msg_rx_err(emac) && net_ratelimit())
+			netdev_err(ndev, "failed rx buffer alloc\n");
+		return -ENOMEM;
+	}
+
+	dst_addr = skb->data;
+
+	/* OCMC RAM is not cached and read order is not important */
+	ocmc_ram = (__force void *)emac->prueth->mem[PRUETH_MEM_OCMC].va;
+
+	/* Get the start address of the first buffer from
+	 * the read buffer description
+	 */
+	src_addr = ocmc_ram + rxqueue->buffer_offset +
+		   (read_block * ICSS_BLOCK_SIZE);
+	src_addr += start_offset;
+
+	/* Copy the data from PRU buffers(OCMC) to socket buffer(DRAM) */
+	if (buffer_wrapped) { /* wrapped around buffer */
+		int bytes = (buffer_desc_count - read_block) * ICSS_BLOCK_SIZE;
+		int remaining;
+		/* bytes is integral multiple of ICSS_BLOCK_SIZE but
+		 * entire packet may have fit within the last BD
+		 * if pkt_info.length is not integral multiple of
+		 * ICSS_BLOCK_SIZE
+		 */
+		if (pkt_info->length < bytes)
+			bytes = pkt_info->length;
+
+		/* If applicable, account for the HSR tag removed */
+		bytes -= start_offset;
+
+		/* copy non-wrapped part */
+		memcpy(dst_addr, src_addr, bytes);
+
+		/* copy wrapped part */
+		dst_addr += bytes;
+		remaining = actual_pkt_len - bytes;
+
+		src_addr = ocmc_ram + rxqueue->buffer_offset;
+		memcpy(dst_addr, src_addr, remaining);
+		src_addr += remaining;
+	} else {
+		memcpy(dst_addr, src_addr, actual_pkt_len);
+		src_addr += actual_pkt_len;
+	}
+
+	if (!pkt_info->sv_frame) {
+		skb_put(skb, actual_pkt_len);
+
+		/* send packet up the stack */
+		skb->protocol = eth_type_trans(skb, ndev);
+		local_bh_disable();
+		netif_receive_skb(skb);
+		local_bh_enable();
+	} else {
+		dev_kfree_skb_any(skb);
+	}
+
+	/* update stats */
+	ndev->stats.rx_bytes += actual_pkt_len;
+	ndev->stats.rx_packets++;
+
+	return 0;
+}
+
+/**
+ * icssm_emac_rx_thread - EMAC Rx interrupt thread handler
+ * @irq: interrupt number
+ * @dev_id: pointer to net_device
+ *
+ * EMAC Rx Interrupt thread handler - function to process the rx frames in a
+ * irq thread function. There is only limited buffer at the ingress to
+ * queue the frames. As the frames are to be emptied as quickly as
+ * possible to avoid overflow, irq thread is necessary. Current implementation
+ * based on NAPI poll results in packet loss due to overflow at
+ * the ingress queues. Industrial use case requires loss free packet
+ * processing. Tests shows that with threaded irq based processing,
+ * no overflow happens when receiving at ~92Mbps for MTU sized frames and thus
+ * meet the requirement for industrial use case.
+ *
+ * Return: interrupt handled condition
+ */
+static irqreturn_t icssm_emac_rx_thread(int irq, void *dev_id)
+{
+	struct net_device *ndev = (struct net_device *)dev_id;
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth_queue_desc __iomem *queue_desc;
+	const struct prueth_queue_info *rxqueue;
+	struct prueth *prueth = emac->prueth;
+	struct net_device_stats *ndevstats;
+	struct prueth_packet_info pkt_info;
+	int start_queue, end_queue;
+	void __iomem *shared_ram;
+	u16 bd_rd_ptr, bd_wr_ptr;
+	u16 update_rd_ptr;
+	u8 overflow_cnt;
+	u32 rd_buf_desc;
+	int used = 0;
+	int i, ret;
+
+	ndevstats = &emac->ndev->stats;
+	shared_ram = emac->prueth->mem[PRUETH_MEM_SHARED_RAM].va;
+
+	start_queue = emac->rx_queue_start;
+	end_queue = emac->rx_queue_end;
+retry:
+	/* search host queues for packets */
+	for (i = start_queue; i <= end_queue; i++) {
+		queue_desc = emac->rx_queue_descs + i;
+		rxqueue = &queue_infos[PRUETH_PORT_HOST][i];
+
+		overflow_cnt = readb(&queue_desc->overflow_cnt);
+		if (overflow_cnt > 0) {
+			emac->ndev->stats.rx_over_errors += overflow_cnt;
+			/* reset to zero */
+			writeb(0, &queue_desc->overflow_cnt);
+		}
+
+		bd_rd_ptr = readw(&queue_desc->rd_ptr);
+		bd_wr_ptr = readw(&queue_desc->wr_ptr);
+
+		/* while packets are available in this queue */
+		while (bd_rd_ptr != bd_wr_ptr) {
+			/* get packet info from the read buffer descriptor */
+			rd_buf_desc = readl(shared_ram + bd_rd_ptr);
+			icssm_parse_packet_info(prueth, rd_buf_desc, &pkt_info);
+
+			if (pkt_info.length <= 0) {
+				/* a packet length of zero will cause us to
+				 * never move the read pointer ahead, locking
+				 * the driver, so we manually have to move it
+				 * to the write pointer, discarding all
+				 * remaining packets in this queue. This should
+				 * never happen.
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;
+			} else if (pkt_info.length > EMAC_MAX_FRM_SUPPORT) {
+				/* if the packet is too large we skip it but we
+				 * still need to move the read pointer ahead
+				 * and assume something is wrong with the read
+				 * pointer as the firmware should be filtering
+				 * these packets
+				 */
+				update_rd_ptr = bd_wr_ptr;
+				ndevstats->rx_length_errors++;
+			} else {
+				update_rd_ptr = bd_rd_ptr;
+				ret = icssm_emac_rx_packet(emac, &update_rd_ptr,
+							   &pkt_info, rxqueue);
+				if (ret)
+					return IRQ_HANDLED;
+				used++;
+			}
+
+			/* after reading the buffer descriptor we clear it
+			 * to prevent improperly moved read pointer errors
+			 * from simply looking like old packets.
+			 */
+			writel(0, shared_ram + bd_rd_ptr);
+
+			/* update read pointer in queue descriptor */
+			writew(update_rd_ptr, &queue_desc->rd_ptr);
+			bd_rd_ptr = update_rd_ptr;
+		}
+	}
+
+	if (used) {
+		used = 0;
+		goto retry;
+	}
+
+	return IRQ_HANDLED;
+}
+
 static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
 				   struct net_device *ndev)
 {
@@ -412,6 +839,21 @@ static int icssm_emac_set_boot_pru(struct prueth_emac *emac,
 		netdev_err(ndev, "failed to boot PRU0: %d\n", ret);
 		return ret;
 	}
+	return ret;
+}
+
+static int icssm_emac_request_irqs(struct prueth_emac *emac)
+{
+	struct net_device *ndev = emac->ndev;
+	int ret;
+
+	ret = request_threaded_irq(emac->rx_irq, NULL, icssm_emac_rx_thread,
+				   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+				   ndev->name, ndev);
+	if (ret) {
+		netdev_err(ndev, "unable to request RX IRQ\n");
+		return ret;
+	}
 
 	return ret;
 }
@@ -442,10 +884,27 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 	if (ret)
 		netdev_err(ndev, "failed to boot PRU: %d\n", ret);
 
+	ret = icssm_emac_request_irqs(emac);
+	if (ret)
+		goto rproc_shutdown;
+
 	/* start PHY */
 	phy_start(emac->phydev);
+
+	/* enable the port and vlan */
+	icssm_prueth_port_enable(emac, true);
+
 	prueth->emac_configured |= BIT(emac->port_id);
+
+	if (netif_msg_drv(emac))
+		dev_notice(&ndev->dev, "started\n");
+
 	return 0;
+
+rproc_shutdown:
+	rproc_shutdown(emac->pru);
+
+	return ret;
 }
 
 /**
@@ -459,18 +918,122 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 static int icssm_emac_ndo_stop(struct net_device *ndev)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth *prueth = emac->prueth;
+
+	prueth->emac_configured &= ~BIT(emac->port_id);
+
+	/* disable the mac port */
+	icssm_prueth_port_enable(emac, false);
 
 	/* stop PHY */
 	phy_stop(emac->phydev);
 
+	/* stop the PRU */
 	rproc_shutdown(emac->pru);
 
+	/* free rx and tx interrupts */
+	if (emac->tx_irq > 0)
+		free_irq(emac->tx_irq, ndev);
+
+	free_irq(emac->rx_irq, ndev);
+
+	if (netif_msg_drv(emac))
+		dev_notice(&ndev->dev, "stopped\n");
+
 	return 0;
 }
 
+/* VLAN-tag PCP to priority queue map for EMAC/Switch/HSR/PRP used by driver
+ * Index is PCP val / 2.
+ *   low  - pcp 0..3 maps to Q4 for Host
+ *   high - pcp 4..7 maps to Q3 for Host
+ *   low  - pcp 0..3 maps to Q2 (FWD Queue) for PRU-x
+ *   where x = 1 for PRUETH_PORT_MII0
+ *             0 for PRUETH_PORT_MII1
+ *   high - pcp 4..7 maps to Q1 (FWD Queue) for PRU-x
+ */
+static const unsigned short emac_pcp_tx_priority_queue_map[] = {
+	PRUETH_QUEUE4, PRUETH_QUEUE4,
+	PRUETH_QUEUE3, PRUETH_QUEUE3,
+	PRUETH_QUEUE2, PRUETH_QUEUE2,
+	PRUETH_QUEUE1, PRUETH_QUEUE1,
+};
+
+static u16 icssm_prueth_get_tx_queue_id(struct prueth *prueth,
+					struct sk_buff *skb)
+{
+	u16 vlan_tci, pcp;
+	int err;
+
+	err = vlan_get_tag(skb, &vlan_tci);
+	if (likely(err))
+		pcp = 0;
+	else
+		pcp = (vlan_tci & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT;
+
+	/* Below code (pcp >>= 1) is made common for all
+	 * protocols (i.e., EMAC, RSTP, HSR and PRP)*
+	 * pcp value 0,1 will be updated to 0 mapped to QUEUE4
+	 * pcp value 2,3 will be updated to 1 mapped to QUEUE4
+	 * pcp value 4,5 will be updated to 2 mapped to QUEUE3
+	 * pcp value 6,7 will be updated to 3 mapped to QUEUE3
+	 */
+	pcp >>= 1;
+
+	return emac_pcp_tx_priority_queue_map[pcp];
+}
+
+/**
+ * icssm_emac_ndo_start_xmit - EMAC Transmit function
+ * @skb: SKB pointer
+ * @ndev: EMAC network adapter
+ *
+ * Called by the system to transmit a packet  - we queue the packet in
+ * EMAC hardware transmit queue
+ *
+ * Return: success(NETDEV_TX_OK) or error code (typically out of desc's)
+ */
+static int icssm_emac_ndo_start_xmit(struct sk_buff *skb,
+				     struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	int ret;
+	u16 qid;
+
+	qid = icssm_prueth_get_tx_queue_id(emac->prueth, skb);
+	ret = icssm_prueth_tx_enqueue(emac, skb, qid);
+	if (ret) {
+		if (ret != -ENOBUFS && netif_msg_tx_err(emac) &&
+		    net_ratelimit())
+			netdev_err(ndev, "packet queue failed: %d\n", ret);
+		goto fail_tx;
+	}
+
+	ndev->stats.tx_packets++;
+	ndev->stats.tx_bytes += skb->len;
+	dev_kfree_skb_any(skb);
+
+	return NETDEV_TX_OK;
+
+fail_tx:
+	if (ret == -ENOBUFS) {
+		/* no free TX queue */
+		if (emac->tx_irq > 0)
+			netif_stop_queue(ndev);
+		ret = NETDEV_TX_BUSY;
+	} else {
+		/* error */
+		ndev->stats.tx_dropped++;
+		ret = NET_XMIT_DROP;
+	}
+
+	return ret;
+}
+
 static const struct net_device_ops emac_netdev_ops = {
 	.ndo_open = icssm_emac_ndo_open,
 	.ndo_stop = icssm_emac_ndo_stop,
+	.ndo_start_xmit = icssm_emac_ndo_start_xmit,
 };
 
 /* get emac_port corresponding to eth_node name */
@@ -540,16 +1103,42 @@ static int icssm_prueth_netdev_init(struct prueth *prueth,
 	/* by default eth_type is EMAC */
 	switch (port) {
 	case PRUETH_PORT_MII0:
+		emac->tx_port_queue = PRUETH_PORT_QUEUE_MII0;
+
+		/* packets from MII0 are on queues 1 through 2 */
+		emac->rx_queue_start = PRUETH_QUEUE1;
+		emac->rx_queue_end = PRUETH_QUEUE2;
+
 		emac->dram = PRUETH_MEM_DRAM0;
 		emac->pru = prueth->pru0;
 		break;
 	case PRUETH_PORT_MII1:
+		emac->tx_port_queue = PRUETH_PORT_QUEUE_MII1;
+
+		/* packets from MII1 are on queues 3 through 4 */
+		emac->rx_queue_start = PRUETH_QUEUE3;
+		emac->rx_queue_end = PRUETH_QUEUE4;
+
 		emac->dram = PRUETH_MEM_DRAM1;
 		emac->pru = prueth->pru1;
 		break;
 	default:
 		return -EINVAL;
 	}
+
+	emac->rx_irq = of_irq_get_byname(eth_node, "rx");
+	if (emac->rx_irq < 0) {
+		ret = emac->rx_irq;
+		if (ret != -EPROBE_DEFER)
+			dev_err(prueth->dev, "could not get rx irq\n");
+		goto free;
+	}
+	emac->tx_irq = of_irq_get_byname(eth_node, "tx");
+	if (emac->tx_irq < 0) {
+		if (emac->tx_irq != -EPROBE_DEFER)
+			dev_dbg(prueth->dev, "tx irq not configured\n");
+	}
+
 	/* get mac address from DT and set private and netdev addr */
 	ret = of_get_ethdev_address(eth_node, ndev);
 	if (!is_valid_ether_addr(ndev->dev_addr)) {
drivers/net/ethernet/ti/icssm/icssm_prueth.h +46 -0

76 lines not on this page · raw message

Signature · 1 line
2.34.1
#19 lore raw

Re: [RFC v2 PATCH 04/10] net: ti: prueth: Adds link detection, RX and TX support.

Quoted 14 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

Quoted 8 lines
---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)

Looks like this patch was duplicated and posted twice ?

#20 lore raw

Re: [RFC v2 PATCH 04/10] net: ti: prueth: Adds link detection, RX and TX support.

Quoted 24 lines · Basharath Hussain Khaja
Quoted 14 lines

From: Roger Quadros <[email protected]>

Changes corresponding to link configuration such as speed and duplexity. IRQ and handler initializations are performed for packet reception.Firmware receives the packet from the wire and stores it into OCMC queue. Next, it notifies the CPU via interrupt. Upon receiving the interrupt CPU will service the IRQ and packet will be processed by pushing the newly allocated SKB to upper layers.

When the user application want to transmit a packet, it will invoke sys_send() which will inturn invoke the PRUETH driver, then it will write the packet into OCMC queues. PRU firmware will pick up the packet and transmit it on to the wire.

Quoted 8 lines
---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 599 ++++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h |  46 ++
 2 files changed, 640 insertions(+), 5 deletions(-)
Quoted 1 line

Looks like this patch was duplicated and posted twice ?

When I posted the patch first time I received a bounce back error. So I was not sure if the patch got posted successfully or not so I have to re-sent. Sorry for the confusion.

Thanks & Best Regards,
Basharath.

#21 lore raw

RFC PATCH v2 5/10 net: ti: prueth: Adds ethtool support for ICSSM PRUETH Driver

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes for enabling ethtool support for the newly added PRU Ethernet interfaces. Extends the support for statistics collection from PRU internal memory and displays it in the user space. Along with statistics, enable/disable of features, configuring link speed etc.are now supported.

The firmware running on PRU maintains statistics in internal data memory. When requested ethtool collects all the statistics for the specified interface and displays it in the user space.

Makefile is updated to include ethtool support into PRUETH driver.

---
 drivers/net/ethernet/ti/Makefile              |   2 +-
 drivers/net/ethernet/ti/icssm/icssm_ethtool.c | 203 ++++++++++++++++++
 drivers/net/ethernet/ti/icssm/icssm_prueth.c  |  31 +++
 drivers/net/ethernet/ti/icssm/icssm_prueth.h  | 127 +++++++++++
 4 files changed, 362 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_ethtool.c
drivers/net/ethernet/ti/Makefile +1 -1
index 93c0a4d0e33a..f21dd11118ab 100644
@@ -4,7 +4,7 @@
 #
 
 obj-$(CONFIG_TI_PRUETH) += icssm-prueth.o
-icssm-prueth-y := icssm/icssm_prueth.o
+icssm-prueth-y := icssm/icssm_prueth.o icssm/icssm_ethtool.o
 
 obj-$(CONFIG_TI_CPSW) += cpsw-common.o
 obj-$(CONFIG_TI_DAVINCI_EMAC) += cpsw-common.o
drivers/net/ethernet/ti/icssm/icssm_ethtool.c new file +203 -0

203 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_prueth.c +31 -0
index 0ba1d16a7a15..35dd91c71caa 100644
@@ -880,6 +880,8 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 
 	icssm_prueth_emac_config(emac);
 
+	icssm_emac_set_stats(emac, &emac->stats);
+
 	ret = icssm_emac_set_boot_pru(emac, ndev);
 	if (ret)
 		netdev_err(ndev, "failed to boot PRU: %d\n", ret);
@@ -931,6 +933,8 @@ static int icssm_emac_ndo_stop(struct net_device *ndev)
 	/* stop the PRU */
 	rproc_shutdown(emac->pru);
 
+	icssm_emac_get_stats(emac, &emac->stats);
+
 	/* free rx and tx interrupts */
 	if (emac->tx_irq > 0)
 		free_irq(emac->tx_irq, ndev);
@@ -1030,10 +1034,36 @@ static int icssm_emac_ndo_start_xmit(struct sk_buff *skb,
 	return ret;
 }
 
+/**
+ * icssm_emac_ndo_get_stats - EMAC get statistics function
+ * @ndev: The EMAC network adapter
+ *
+ * Called when system wants to get statistics from the device.
+ *
+ * We return the statistics in net_device_stats structure pulled from emac
+ *
+ * Return: stats
+ */
+static struct net_device_stats
+*icssm_emac_ndo_get_stats(struct net_device *ndev)
+{
+	struct net_device_stats *stats = &ndev->stats;
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct port_statistics pstats;
+
+	icssm_emac_get_stats(emac, &pstats);
+	stats->collisions = pstats.late_coll + pstats.single_coll +
+			    pstats.multi_coll + pstats.excess_coll;
+	stats->multicast = pstats.rx_mcast;
+
+	return stats;
+}
+
 static const struct net_device_ops emac_netdev_ops = {
 	.ndo_open = icssm_emac_ndo_open,
 	.ndo_stop = icssm_emac_ndo_stop,
 	.ndo_start_xmit = icssm_emac_ndo_start_xmit,
+	.ndo_get_stats = icssm_emac_ndo_get_stats,
 };
 
 /* get emac_port corresponding to eth_node name */
@@ -1167,6 +1197,7 @@ static int icssm_prueth_netdev_init(struct prueth *prueth,
 	phy_remove_link_mode(emac->phydev, ETHTOOL_LINK_MODE_Asym_Pause_BIT);
 
 	ndev->netdev_ops = &emac_netdev_ops;
+	ndev->ethtool_ops = &emac_ethtool_ops;
 
 	return 0;
 free:
drivers/net/ethernet/ti/icssm/icssm_prueth.h +127 -0

154 lines not on this page · raw message

Signature · 1 line
2.34.1
reviewer
#22 lore raw

Re: [RFC v2 PATCH 05/10] net: ti: prueth: Adds ethtool support for ICSSM PRUETH Driver

Quoted 17 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes for enabling ethtool support for the newly added PRU Ethernet interfaces. Extends the support for statistics collection from PRU internal memory and displays it in the user space. Along with statistics, enable/disable of features, configuring link speed etc.are now supported.

The firmware running on PRU maintains statistics in internal data memory. When requested ethtool collects all the statistics for the specified interface and displays it in the user space.

Makefile is updated to include ethtool support into PRUETH driver.

...

Quoted 1 line
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +0 -0

...

drivers/net/ethernet/ti/icssm/icssm_ethtool.c line 92

Quoted 12 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +12 -0
+static const struct {
+	char string[ETH_GSTRING_LEN];
+	u32 offset;
+} prueth_ethtool_stats[] = {
+	{"txBcast", PRUETH_STAT_OFFSET(tx_bcast)},
+	{"txMcast", PRUETH_STAT_OFFSET(tx_mcast)},
+	{"txUcast", PRUETH_STAT_OFFSET(tx_ucast)},
+	{"txOctets", PRUETH_STAT_OFFSET(tx_octets)},
+	{"rxBcast", PRUETH_STAT_OFFSET(rx_bcast)},
+	{"rxMcast", PRUETH_STAT_OFFSET(rx_mcast)},
+	{"rxUcast", PRUETH_STAT_OFFSET(rx_ucast)},
+	{"rxOctets", PRUETH_STAT_OFFSET(rx_octets)},

Hi Roger, Basharath, all,

There seems to be some overlap between the above and struct rtnl_link_stats64.

Please implement those stats which are present in struct rtnl_link_stats64 using ndo_get_stats64 and omit them from your implementation of get_ethtool_stats.

IOW, get_ethtool_stats() is for extended stats, whereas is for standard stats ndo_get_stats64(). And standard stats should not be presented to the user as extended stats.

drivers/net/ethernet/ti/icssm/icssm_ethtool.c line 105

Quoted 12 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +12 -0
+	{"tx64byte", PRUETH_STAT_OFFSET(tx64byte)},
+	{"tx65_127byte", PRUETH_STAT_OFFSET(tx65_127byte)},
+	{"tx128_255byte", PRUETH_STAT_OFFSET(tx128_255byte)},
+	{"tx256_511byte", PRUETH_STAT_OFFSET(tx256_511byte)},
+	{"tx512_1023byte", PRUETH_STAT_OFFSET(tx512_1023byte)},
+	{"tx1024byte", PRUETH_STAT_OFFSET(tx1024byte)},
+	{"rx64byte", PRUETH_STAT_OFFSET(rx64byte)},
+	{"rx65_127byte", PRUETH_STAT_OFFSET(rx65_127byte)},
+	{"rx128_255byte", PRUETH_STAT_OFFSET(rx128_255byte)},
+	{"rx256_511byte", PRUETH_STAT_OFFSET(rx256_511byte)},
+	{"rx512_1023byte", PRUETH_STAT_OFFSET(rx512_1023byte)},
+	{"rx1024byte", PRUETH_STAT_OFFSET(rx1024byte)},

Similarly, the above, along with rxOverSizedFrames and rxUnderSizedFrames below seem to be RMON (RFC 2819) statistics. So I think they should be handled by implementing get_rmon_stats().

drivers/net/ethernet/ti/icssm/icssm_ethtool.c line 110

Quoted 5 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +5 -0
+
+	{"lateColl", PRUETH_STAT_OFFSET(late_coll)},
+	{"singleColl", PRUETH_STAT_OFFSET(single_coll)},
+	{"multiColl", PRUETH_STAT_OFFSET(multi_coll)},
+	{"excessColl", PRUETH_STAT_OFFSET(excess_coll)},

And likewise, the section above and below seem to overlap with Basic IEEE 802.3 MAC statistics which I believe should be handled by implementing get_eth_mac_stats()

Quoted 19 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +19 -0
+
+	{"rxMisAlignmentFrames", PRUETH_STAT_OFFSET(rx_misalignment_frames)},
+	{"stormPrevCounterBC", PRUETH_STAT_OFFSET(stormprev_counter_bc)},
+	{"stormPrevCounterMC", PRUETH_STAT_OFFSET(stormprev_counter_mc)},
+	{"stormPrevCounterUC", PRUETH_STAT_OFFSET(stormprev_counter_uc)},
+	{"macRxError", PRUETH_STAT_OFFSET(mac_rxerror)},
+	{"SFDError", PRUETH_STAT_OFFSET(sfd_error)},
+	{"defTx", PRUETH_STAT_OFFSET(def_tx)},
+	{"macTxError", PRUETH_STAT_OFFSET(mac_txerror)},
+	{"rxOverSizedFrames", PRUETH_STAT_OFFSET(rx_oversized_frames)},
+	{"rxUnderSizedFrames", PRUETH_STAT_OFFSET(rx_undersized_frames)},
+	{"rxCRCFrames", PRUETH_STAT_OFFSET(rx_crc_frames)},
+	{"droppedPackets", PRUETH_STAT_OFFSET(dropped_packets)},
+
+	{"txHWQOverFlow", PRUETH_STAT_OFFSET(tx_hwq_overflow)},
+	{"txHWQUnderFlow", PRUETH_STAT_OFFSET(tx_hwq_underflow)},
+	{"vlanDropped", PRUETH_STAT_OFFSET(vlan_dropped)},
+	{"multicastDropped", PRUETH_STAT_OFFSET(multicast_dropped)},
+};

...

#23 lore raw

Re: [RFC v2 PATCH 05/10] net: ti: prueth: Adds ethtool support for ICSSM PRUETH Driver

Quoted 48 lines · Basharath Hussain Khaja
Quoted 17 lines

From: Roger Quadros <[email protected]>

Changes for enabling ethtool support for the newly added PRU Ethernet interfaces. Extends the support for statistics collection from PRU internal memory and displays it in the user space. Along with statistics, enable/disable of features, configuring link speed etc.are now supported.

The firmware running on PRU maintains statistics in internal data memory. When requested ethtool collects all the statistics for the specified interface and displays it in the user space.

Makefile is updated to include ethtool support into PRUETH driver.

...

Quoted 2 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +0 -0

...

drivers/net/ethernet/ti/icssm/icssm_ethtool.c line 92

Quoted 12 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +12 -0
+static const struct {
+	char string[ETH_GSTRING_LEN];
+	u32 offset;
+} prueth_ethtool_stats[] = {
+	{"txBcast", PRUETH_STAT_OFFSET(tx_bcast)},
+	{"txMcast", PRUETH_STAT_OFFSET(tx_mcast)},
+	{"txUcast", PRUETH_STAT_OFFSET(tx_ucast)},
+	{"txOctets", PRUETH_STAT_OFFSET(tx_octets)},
+	{"rxBcast", PRUETH_STAT_OFFSET(rx_bcast)},
+	{"rxMcast", PRUETH_STAT_OFFSET(rx_mcast)},
+	{"rxUcast", PRUETH_STAT_OFFSET(rx_ucast)},
+	{"rxOctets", PRUETH_STAT_OFFSET(rx_octets)},

Hi Roger, Basharath, all,

There seems to be some overlap between the above and struct rtnl_link_stats64.

Please implement those stats which are present in struct rtnl_link_stats64 using ndo_get_stats64 and omit them from your implementation of get_ethtool_stats.

Quoted 7 lines

IOW, get_ethtool_stats() is for extended stats, whereas is for standard stats ndo_get_stats64(). And standard stats should not be presented to the user as extended stats.

Link:
https://docs.kernel.org/networking/statistics.html#notes-for-driver-authors

We will address this along with the changes that will be done by using rtnl_link_stats64 instead of legacy net_device_stats.

Quoted 8 lines
Quoted 8 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +8 -0
+	{"tx64byte", PRUETH_STAT_OFFSET(tx64byte)},
+	{"tx65_127byte", PRUETH_STAT_OFFSET(tx65_127byte)},
+	{"tx128_255byte", PRUETH_STAT_OFFSET(tx128_255byte)},
+	{"tx256_511byte", PRUETH_STAT_OFFSET(tx256_511byte)},
+	{"tx512_1023byte", PRUETH_STAT_OFFSET(tx512_1023byte)},
+	{"tx1024byte", PRUETH_STAT_OFFSET(tx1024byte)},
+	{"rx64byte", PRUETH_STAT_OFFSET(rx64byte)},
+	{"rx65_127byte", PRUETH_STAT_OFFSET(rx65_127byte)},
Quoted 9 lines

drivers/net/ethernet/ti/icssm/icssm_ethtool.c line 105

Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +4 -0
+	{"rx128_255byte", PRUETH_STAT_OFFSET(rx128_255byte)},
+	{"rx256_511byte", PRUETH_STAT_OFFSET(rx256_511byte)},
+	{"rx512_1023byte", PRUETH_STAT_OFFSET(rx512_1023byte)},
+	{"rx1024byte", PRUETH_STAT_OFFSET(rx1024byte)},

Similarly, the above, along with rxOverSizedFrames and rxUnderSizedFrames below seem to be RMON (RFC 2819) statistics. So I think they should be handled by implementing get_rmon_stats().

Sure. We will add get_rmon_stats() function and update necessary statistics in that function.

Quoted 10 lines

drivers/net/ethernet/ti/icssm/icssm_ethtool.c line 110

Quoted 5 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +5 -0
+
+	{"lateColl", PRUETH_STAT_OFFSET(late_coll)},
+	{"singleColl", PRUETH_STAT_OFFSET(single_coll)},
+	{"multiColl", PRUETH_STAT_OFFSET(multi_coll)},
+	{"excessColl", PRUETH_STAT_OFFSET(excess_coll)},

And likewise, the section above and below seem to overlap with Basic IEEE 802.3 MAC statistics which I believe should be handled by implementing get_eth_mac_stats()

For now we will remove these stats in the next version and address this in the next series of patches.

Quoted 13 lines
Quoted 13 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +13 -0
+
+	{"rxMisAlignmentFrames", PRUETH_STAT_OFFSET(rx_misalignment_frames)},
+	{"stormPrevCounterBC", PRUETH_STAT_OFFSET(stormprev_counter_bc)},
+	{"stormPrevCounterMC", PRUETH_STAT_OFFSET(stormprev_counter_mc)},
+	{"stormPrevCounterUC", PRUETH_STAT_OFFSET(stormprev_counter_uc)},
+	{"macRxError", PRUETH_STAT_OFFSET(mac_rxerror)},
+	{"SFDError", PRUETH_STAT_OFFSET(sfd_error)},
+	{"defTx", PRUETH_STAT_OFFSET(def_tx)},
+	{"macTxError", PRUETH_STAT_OFFSET(mac_txerror)},
+	{"rxOverSizedFrames", PRUETH_STAT_OFFSET(rx_oversized_frames)},
+	{"rxUnderSizedFrames", PRUETH_STAT_OFFSET(rx_undersized_frames)},
+	{"rxCRCFrames", PRUETH_STAT_OFFSET(rx_crc_frames)},
+	{"droppedPackets", PRUETH_STAT_OFFSET(dropped_packets)},
Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +6 -0
+
+	{"txHWQOverFlow", PRUETH_STAT_OFFSET(tx_hwq_overflow)},
+	{"txHWQUnderFlow", PRUETH_STAT_OFFSET(tx_hwq_underflow)},
+	{"vlanDropped", PRUETH_STAT_OFFSET(vlan_dropped)},
+	{"multicastDropped", PRUETH_STAT_OFFSET(multicast_dropped)},
+};

...

Thanks & Best Regards,
Basharath

#24 lore raw

RFC PATCH v2 6/10 net: ti: prueth: Adds HW timestamping support for PTP using PRU-ICSS IEP module

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

PRU-ICSS IEP module, which is capable of timestamping RX and TX packets at HW level, is used for time synchronization by PTP4L.

This change includes interaction between firmware and user space application (ptp4l) with required packet timestamps. The driver initializes the PRU firmware with appropriate mode and configuration flags. Firmware updates local registers with the flags set by driver and uses for further operation. RX SOF timestamp comes along with packet and firmware will rise interrupt with TX SOF timestamp after pushing the packet on to the wire.

IEP driver is available in upstream and we are reusing for hardware configuration for ICSSM as well. On top of that we have extended it with the changes for AM57xx SoC.

Extended ethtool for reading HW timestamping capability of the PRU interfaces.

Currently ordinary clock (OC) configuration has been validated with Linux ptp4l.

---
 drivers/net/ethernet/ti/icssg/icss_iep.c      |  42 ++
 drivers/net/ethernet/ti/icssm/icssm_ethtool.c |  23 +
 drivers/net/ethernet/ti/icssm/icssm_prueth.c  | 443 +++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h  |  11 +
 .../net/ethernet/ti/icssm/icssm_prueth_ptp.h  |  85 ++++
 5 files changed, 602 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_ptp.h
drivers/net/ethernet/ti/icssg/icss_iep.c +42 -0
index 768578c0d958..9a2ea13703d8 100644
@@ -937,11 +937,53 @@ static const struct icss_iep_plat_data am654_icss_iep_plat_data = {
 	.config = &am654_icss_iep_regmap_config,
 };
 
+static const struct icss_iep_plat_data am57xx_icss_iep_plat_data = {
+	.flags = ICSS_IEP_64BIT_COUNTER_SUPPORT |
+		 ICSS_IEP_SLOW_COMPEN_REG_SUPPORT,
+	.reg_offs = {
+		[ICSS_IEP_GLOBAL_CFG_REG] = 0x00,
+		[ICSS_IEP_COMPEN_REG] = 0x08,
+		[ICSS_IEP_SLOW_COMPEN_REG] = 0x0C,
+		[ICSS_IEP_COUNT_REG0] = 0x10,
+		[ICSS_IEP_COUNT_REG1] = 0x14,
+		[ICSS_IEP_CAPTURE_CFG_REG] = 0x18,
+		[ICSS_IEP_CAPTURE_STAT_REG] = 0x1c,
+
+		[ICSS_IEP_CAP6_RISE_REG0] = 0x50,
+		[ICSS_IEP_CAP6_RISE_REG1] = 0x54,
+
+		[ICSS_IEP_CAP7_RISE_REG0] = 0x60,
+		[ICSS_IEP_CAP7_RISE_REG1] = 0x64,
+
+		[ICSS_IEP_CMP_CFG_REG] = 0x70,
+		[ICSS_IEP_CMP_STAT_REG] = 0x74,
+		[ICSS_IEP_CMP0_REG0] = 0x78,
+		[ICSS_IEP_CMP0_REG1] = 0x7c,
+		[ICSS_IEP_CMP1_REG0] = 0x80,
+		[ICSS_IEP_CMP1_REG1] = 0x84,
+
+		[ICSS_IEP_CMP8_REG0] = 0xc0,
+		[ICSS_IEP_CMP8_REG1] = 0xc4,
+		[ICSS_IEP_SYNC_CTRL_REG] = 0x180,
+		[ICSS_IEP_SYNC0_STAT_REG] = 0x188,
+		[ICSS_IEP_SYNC1_STAT_REG] = 0x18c,
+		[ICSS_IEP_SYNC_PWIDTH_REG] = 0x190,
+		[ICSS_IEP_SYNC0_PERIOD_REG] = 0x194,
+		[ICSS_IEP_SYNC1_DELAY_REG] = 0x198,
+		[ICSS_IEP_SYNC_START_REG] = 0x19c,
+	},
+	.config = &am654_icss_iep_regmap_config,
+};
+
 static const struct of_device_id icss_iep_of_match[] = {
 	{
 		.compatible = "ti,am654-icss-iep",
 		.data = &am654_icss_iep_plat_data,
 	},
+	{
+		.compatible = "ti,am5728-icss-iep",
+		.data = &am57xx_icss_iep_plat_data,
+	},
 	{},
 };
 MODULE_DEVICE_TABLE(of, icss_iep_of_match);
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +23 -0
index cce3276d5565..ff9faaef9f9e 100644
@@ -7,6 +7,7 @@
 
 #include <linux/if_bridge.h>
 #include "icssm_prueth.h"
+#include "../icssg/icss_iep.h"
 
 #define PRUETH_MODULE_VERSION "0.2"
 #define PRUETH_MODULE_DESCRIPTION "PRUSS Ethernet driver"
@@ -189,12 +190,34 @@ static void icssm_emac_get_regs(struct net_device *ndev,
 	regs->version = PRUETH_REG_DUMP_GET_VER(prueth);
 }
 
+static int icssm_emac_get_ts_info(struct net_device *ndev,
+				  struct kernel_ethtool_ts_info *info)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+
+	if ((PRUETH_IS_EMAC(emac->prueth) && !emac->emac_ptp_tx_irq))
+		return ethtool_op_get_ts_info(ndev, info);
+
+	info->so_timestamping =
+		SOF_TIMESTAMPING_TX_HARDWARE |
+		SOF_TIMESTAMPING_RX_HARDWARE |
+		SOF_TIMESTAMPING_RAW_HARDWARE;
+
+	info->phc_index = icss_iep_get_ptp_clock_idx(emac->prueth->iep);
+	info->tx_types = BIT(HWTSTAMP_TX_OFF) | BIT(HWTSTAMP_TX_ON);
+	info->rx_filters = BIT(HWTSTAMP_FILTER_NONE) |
+				BIT(HWTSTAMP_FILTER_PTP_V2_EVENT);
+
+	return 0;
+}
+
 /* Ethtool support for EMAC adapter */
 const struct ethtool_ops emac_ethtool_ops = {
 	.get_drvinfo = icssm_emac_get_drvinfo,
 	.get_link_ksettings = icssm_emac_get_link_ksettings,
 	.set_link_ksettings = icssm_emac_set_link_ksettings,
 	.get_link = ethtool_op_get_link,
+	.get_ts_info = icssm_emac_get_ts_info,
 	.get_sset_count = icssm_emac_get_sset_count,
 	.get_strings = icssm_emac_get_strings,
 	.get_ethtool_stats = icssm_emac_get_ethtool_stats,
drivers/net/ethernet/ti/icssm/icssm_prueth.c +441 -2

585 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_prueth.h +11 -0
index d663a842fc38..bd7ad8318544 100644
@@ -14,6 +14,7 @@
 #include <linux/remoteproc/pruss.h>
 
 #include "icssm_switch.h"
+#include "icssm_prueth_ptp.h"
 
 /* ICSSM size of redundancy tag */
 #define ICSSM_LRE_TAG_SIZE	6
@@ -331,6 +332,12 @@ struct prueth_emac {
 	u8 mac_addr[6];
 	phy_interface_t phy_if;
 	spinlock_t lock;	/* serialize access */
+
+	struct sk_buff *ptp_skb[PRUETH_PTP_TS_EVENTS];
+	spinlock_t ptp_skb_lock;	/* serialize access */
+	int emac_ptp_tx_irq;
+	bool ptp_tx_enable;
+	bool ptp_rx_enable;
 };
 
 struct prueth {
@@ -340,6 +347,7 @@ struct prueth {
 	struct pruss_mem_region mem[PRUETH_MEM_MAX];
 	struct gen_pool *sram_pool;
 	struct regmap *mii_rt;
+	struct icss_iep *iep;
 
 	const struct prueth_private_data *fw_data;
 	struct prueth_fw_offsets *fw_offsets;
@@ -360,6 +368,9 @@ int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr,
 			 struct prueth_packet_info *pkt_info,
 			 const struct prueth_queue_info *rxqueue);
 
+irqreturn_t icssm_prueth_ptp_tx_irq_handle(int irq, void *dev);
+irqreturn_t icssm_prueth_ptp_tx_irq_work(int irq, void *dev);
+
 void icssm_emac_set_stats(struct prueth_emac *emac,
 			  struct port_statistics *pstats);
 void icssm_emac_get_stats(struct prueth_emac *emac,
drivers/net/ethernet/ti/icssm/icssm_prueth_ptp.h new file +85 -0

85 lines not on this page · raw message

Signature · 1 line
2.34.1
reviewer
#25 lore raw

Re: [RFC v2 PATCH 06/10] net: ti: prueth: Adds HW timestamping support for PTP using PRU-ICSS IEP module

Quoted 27 lines · Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

PRU-ICSS IEP module, which is capable of timestamping RX and TX packets at HW level, is used for time synchronization by PTP4L.

This change includes interaction between firmware and user space application (ptp4l) with required packet timestamps. The driver initializes the PRU firmware with appropriate mode and configuration flags. Firmware updates local registers with the flags set by driver and uses for further operation. RX SOF timestamp comes along with packet and firmware will rise interrupt with TX SOF timestamp after pushing the packet on to the wire.

IEP driver is available in upstream and we are reusing for hardware configuration for ICSSM as well. On top of that we have extended it with the changes for AM57xx SoC.

Extended ethtool for reading HW timestamping capability of the PRU interfaces.

Currently ordinary clock (OC) configuration has been validated with Linux ptp4l.

...

Quoted 1 line
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

drivers/net/ethernet/ti/icssm/icssm_prueth.c int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr, · line 904

Quoted 7 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +3 -0
@@ -682,9 +899,22 @@ int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr,
 		src_addr += actual_pkt_len;
 	}
 
+	if (pkt_info->timestamp) {
+		src_addr = (void *)roundup((uintptr_t)src_addr,
+					   ICSS_BLOCK_SIZE);

Can PTR_ALIGN() be used here?

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +4 -0
+		dst_addr = &ts;
+		memcpy(dst_addr, src_addr, sizeof(ts));
+	}
+
 	if (!pkt_info->sv_frame) {
 		skb_put(skb, actual_pkt_len);

drivers/net/ethernet/ti/icssm/icssm_prueth.c int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr, · line 920

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +6 -0
 
+		if (icssm_prueth_ptp_rx_ts_is_enabled(emac) &&
+		    pkt_info->timestamp) {
+			ssh = skb_hwtstamps(skb);
+			memset(ssh, 0, sizeof(*ssh));
+			ssh->hwtstamp = ns_to_ktime(ts);
+		}
 		/* send packet up the stack */
 		skb->protocol = eth_type_trans(skb, ndev);
 		local_bh_disable();

The code preceding the hunk below is:

static int icssm_emac_request_irqs(struct prueth_emac *emac)

{
	struct net_device *ndev = emac->ndev;
	int ret;

	ret = request_threaded_irq(emac->rx_irq, NULL, icssm_emac_rx_thread,
				   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
				   ndev->name, ndev);
	if (ret) {
		netdev_err(ndev, "unable to request RX IRQ\n");
		return ret;
	}
Quoted 4 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0
@@ -855,9 +1085,64 @@ static int icssm_emac_request_irqs(struct prueth_emac *emac)
 		return ret;
 	}
 

drivers/net/ethernet/ti/icssm/icssm_prueth.c static int icssm_emac_request_irqs(struct prueth_emac *emac) · line 1097

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	if (emac->emac_ptp_tx_irq) {
+		ret = request_threaded_irq(emac->emac_ptp_tx_irq,
+					   icssm_prueth_ptp_tx_irq_handle,
+					   icssm_prueth_ptp_tx_irq_work,
+					   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+					   ndev->name, ndev);
+		if (ret) {
+			netdev_err(ndev, "unable to request PTP TX IRQ\n");
+			free_irq(emac->rx_irq, ndev);
+			free_irq(emac->tx_irq, ndev);

This seems somewhat asymmetric. This function does request emac->rx_irq but not emac->tx_irq. So I don't think it is appropriate to free emac->tx_irq here.

Also, I would suggest using a goto label for unwind here.

Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +3 -0
+		}
+	}
+
 	return ret;
 }
 

...

#26 lore raw

Re: [RFC v2 PATCH 06/10] net: ti: prueth: Adds HW timestamping support for PTP using PRU-ICSS IEP module

Quoted 42 lines · Basharath Hussain Khaja
Quoted 27 lines

From: Roger Quadros <[email protected]>

PRU-ICSS IEP module, which is capable of timestamping RX and TX packets at HW level, is used for time synchronization by PTP4L.

This change includes interaction between firmware and user space application (ptp4l) with required packet timestamps. The driver initializes the PRU firmware with appropriate mode and configuration flags. Firmware updates local registers with the flags set by driver and uses for further operation. RX SOF timestamp comes along with packet and firmware will rise interrupt with TX SOF timestamp after pushing the packet on to the wire.

IEP driver is available in upstream and we are reusing for hardware configuration for ICSSM as well. On top of that we have extended it with the changes for AM57xx SoC.

Extended ethtool for reading HW timestamping capability of the PRU interfaces.

Currently ordinary clock (OC) configuration has been validated with Linux ptp4l.

...

Quoted 2 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0

...

Quoted 5 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0
@@ -682,9 +899,22 @@ int icssm_emac_rx_packet(struct prueth_emac *emac, u16
 *bd_rd_ptr,
 		src_addr += actual_pkt_len;
 	}
 
Quoted 6 lines

drivers/net/ethernet/ti/icssm/icssm_prueth.c int icssm_emac_rx_packet(struct prueth_emac *emac, u16 *bd_rd_ptr, · line 904

Quoted 3 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +3 -0
+	if (pkt_info->timestamp) {
+		src_addr = (void *)roundup((uintptr_t)src_addr,
+					   ICSS_BLOCK_SIZE);

Can PTR_ALIGN() be used here?

We are making sure Both roundup() and PTR_ALIGN() will point to the same address location. We will change this in the next version.

Quoted 52 lines
Quoted 15 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+		dst_addr = &ts;
+		memcpy(dst_addr, src_addr, sizeof(ts));
+	}
+
 	if (!pkt_info->sv_frame) {
 		skb_put(skb, actual_pkt_len);
 
+		if (icssm_prueth_ptp_rx_ts_is_enabled(emac) &&
+		    pkt_info->timestamp) {
+			ssh = skb_hwtstamps(skb);
+			memset(ssh, 0, sizeof(*ssh));
+			ssh->hwtstamp = ns_to_ktime(ts);
+		}
 		/* send packet up the stack */
 		skb->protocol = eth_type_trans(skb, ndev);
Quoted 1 line

local_bh_disable();

The code preceding the hunk below is:

static int icssm_emac_request_irqs(struct prueth_emac *emac)

{
	struct net_device *ndev = emac->ndev;
	int ret;

	ret = request_threaded_irq(emac->rx_irq, NULL, icssm_emac_rx_thread,
				   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
				   ndev->name, ndev);
	if (ret) {
		netdev_err(ndev, "unable to request RX IRQ\n");
		return ret;
	}
Quoted 5 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +0 -0
@@ -855,9 +1085,64 @@ static int icssm_emac_request_irqs(struct prueth_emac
 *emac)
 		return ret;
 	}
 

drivers/net/ethernet/ti/icssm/icssm_prueth.c static int icssm_emac_request_irqs(struct prueth_emac · line 1098

Quoted 10 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +10 -0
+	if (emac->emac_ptp_tx_irq) {
+		ret = request_threaded_irq(emac->emac_ptp_tx_irq,
+					   icssm_prueth_ptp_tx_irq_handle,
+					   icssm_prueth_ptp_tx_irq_work,
+					   IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
+					   ndev->name, ndev);
+		if (ret) {
+			netdev_err(ndev, "unable to request PTP TX IRQ\n");
+			free_irq(emac->rx_irq, ndev);
+			free_irq(emac->tx_irq, ndev);

This seems somewhat asymmetric. This function does request emac->rx_irq but not emac->tx_irq. So I don't think it is appropriate to free emac->tx_irq here.

Quoted 2 lines

Also, I would suggest using a goto label for unwind here.

Sure. We will clean this in the next version.

Quoted 8 lines
Quoted 6 lines
drivers/net/ethernet/ti/icssm/icssm_prueth.c +3 -0
+		}
+	}
+
 	return ret;
 }
 

...

Thanks & Best Regards,
Basharath

#27 lore raw

RFC PATCH v2 7/10 net: ti: prueth: Adds support for network filters for traffic control supported by PRU-ICSS

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Driver updates to enable/disable network filters and traffic control features supported by the firmware running on PRU-ICSS.

Control of the following features are now supported:
1. Promiscuous mode
2. Network Storm prevention
3. Multicast filtering and
4. VLAN filtering

Firmware running on PRU-ICSS will go through all these filter checks prior to sending the rx packets to the host.

Ethtool or dev ioctl can be used to enable/disable these features from the user space.

---
 drivers/net/ethernet/ti/Makefile              |   2 +-
 drivers/net/ethernet/ti/icssm/icssm_ethtool.c |  39 +++
 drivers/net/ethernet/ti/icssm/icssm_prueth.c  | 310 +++++++++++++++++-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h  |  49 ++-
 .../net/ethernet/ti/icssm/icssm_prueth_dos.c  | 225 +++++++++++++
 drivers/net/ethernet/ti/icssm/icssm_switch.h  |   5 +
 .../ti/icssm/icssm_vlan_mcast_filter_mmap.h   | 120 +++++++
 7 files changed, 747 insertions(+), 3 deletions(-)
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_dos.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_vlan_mcast_filter_mmap.h
drivers/net/ethernet/ti/Makefile +1 -1
index f21dd11118ab..852640ce2b15 100644
@@ -4,7 +4,7 @@
 #
 
 obj-$(CONFIG_TI_PRUETH) += icssm-prueth.o
-icssm-prueth-y := icssm/icssm_prueth.o icssm/icssm_ethtool.o
+icssm-prueth-y := icssm/icssm_prueth.o icssm/icssm_ethtool.o icssm/icssm_prueth_dos.o
 
 obj-$(CONFIG_TI_CPSW) += cpsw-common.o
 obj-$(CONFIG_TI_DAVINCI_EMAC) += cpsw-common.o
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +39 -0
index ff9faaef9f9e..bf7d508aecaf 100644
@@ -7,6 +7,7 @@
 
 #include <linux/if_bridge.h>
 #include "icssm_prueth.h"
+#include "icssm_vlan_mcast_filter_mmap.h"
 #include "../icssg/icss_iep.h"
 
 #define PRUETH_MODULE_VERSION "0.2"
@@ -20,6 +21,11 @@ void icssm_emac_set_stats(struct prueth_emac *emac,
 
 	dram = emac->prueth->mem[emac->dram].va;
 	memcpy_toio(dram + STATISTICS_OFFSET, pstats, STAT_SIZE);
+
+	writel(pstats->vlan_dropped, dram +
+			ICSS_EMAC_FW_VLAN_FILTER_DROP_CNT_OFFSET);
+	writel(pstats->multicast_dropped, dram +
+			ICSS_EMAC_FW_MULTICAST_FILTER_DROP_CNT_OFFSET);
 }
 
 /* get statistics maintained by the PRU firmware into @pstats */
@@ -30,6 +36,11 @@ void icssm_emac_get_stats(struct prueth_emac *emac,
 
 	dram = emac->prueth->mem[emac->dram].va;
 	memcpy_fromio(pstats, dram + STATISTICS_OFFSET, STAT_SIZE);
+
+	pstats->vlan_dropped =
+		readl(dram + ICSS_EMAC_FW_VLAN_FILTER_DROP_CNT_OFFSET);
+	pstats->multicast_dropped =
+		readl(dram + ICSS_EMAC_FW_MULTICAST_FILTER_DROP_CNT_OFFSET);
 }
 
 /**
@@ -181,13 +192,40 @@ static void icssm_emac_get_ethtool_stats(struct net_device *ndev,
 	}
 }
 
+static int icssm_emac_get_regs_len(struct net_device *ndev)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth *prueth = emac->prueth;
+
+	/* VLAN Table at the end of the memory map, after MultiCast
+	 * filter region. So VLAN table base +
+	 * size will give the entire size of reg dump in case of
+	 * Dual-EMAC firmware.
+	 */
+	if (PRUETH_IS_EMAC(prueth)) {
+		return ICSS_EMAC_FW_VLAN_FLTR_TBL_BASE_ADDR +
+		       ICSS_EMAC_FW_VLAN_FILTER_TABLE_SIZE_BYTES;
+	}
+
+	return 0;
+}
+
 static void icssm_emac_get_regs(struct net_device *ndev,
 				struct ethtool_regs *regs, void *p)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
 	struct prueth *prueth = emac->prueth;
+	void __iomem *ram;
+	u8 *reg = p;
 
 	regs->version = PRUETH_REG_DUMP_GET_VER(prueth);
+
+	/* Dump firmware's VLAN and MC tables */
+	if (PRUETH_IS_EMAC(prueth)) {
+		ram = prueth->mem[emac->dram].va;
+		memcpy_fromio(reg, ram, icssm_emac_get_regs_len(ndev));
+		return;
+	}
 }
 
 static int icssm_emac_get_ts_info(struct net_device *ndev,
@@ -222,5 +260,6 @@ const struct ethtool_ops emac_ethtool_ops = {
 	.get_strings = icssm_emac_get_strings,
 	.get_ethtool_stats = icssm_emac_get_ethtool_stats,
 	.get_regs = icssm_emac_get_regs,
+	.get_regs_len = icssm_emac_get_regs_len,
 };
 EXPORT_SYMBOL_GPL(emac_ethtool_ops);
drivers/net/ethernet/ti/icssm/icssm_prueth.c +309 -1

389 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_prueth.h +48 -1

93 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_prueth_dos.c new file +225 -0

225 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_switch.h +5 -0
index b13e0706ccec..0053191380b7 100644
@@ -146,6 +146,11 @@
 /* 4 bytes ? */
 #define STP_INVALID_STATE_OFFSET	(STATISTICS_OFFSET + STAT_SIZE + 33)
 
+/* Shared RAM Offsets for Switch */
+/* NSP (Network Storm Prevention) timer re-uses NT timer */
+#define PRUETH_NSP_CREDIT_SHIFT       8
+#define PRUETH_NSP_ENABLE            BIT(0)
+
 /* DRAM Offsets for EMAC
  * Present on Both DRAM0 and DRAM1
  */
drivers/net/ethernet/ti/icssm/icssm_vlan_mcast_filter_mmap.h new file +120 -0

120 lines not on this page · raw message

Signature · 1 line
2.34.1
#28 lore raw

RFC PATCH v2 8/10 net: ti: prueth: Adds support for RX interrupt coalescing/pacing

In reply to Basharath Hussain Khaja

From: Murali Karicheri <[email protected]>

Changes for supporting RX interrupt pacing feature using eCAP peripheral available in PRU-ICSS.

Instead of interrupting the CPU for every packet received, the firmware running on the PRU-ICSS will interrupt the CPU based on the configured time period, if interrupt pacing is enabled.

The time period can be configured using ethtool.

RX pacing/coalescing is implemented Using eCAP timer events to give CPU breathing space from ISR to perform other critical tasks.

The changes include new eCAP driver module which will initialization and configures the ICSS eCAP HW.

Makefile and Kernel config has been updated to compile the eCAP driver and to insert the module.

---
 drivers/net/ethernet/ti/Kconfig               |  12 +
 drivers/net/ethernet/ti/Makefile              |   2 +
 drivers/net/ethernet/ti/icssm/icssm_ethtool.c |  38 +++
 drivers/net/ethernet/ti/icssm/icssm_prueth.c  |  25 +-
 drivers/net/ethernet/ti/icssm/icssm_prueth.h  |   3 +
 .../net/ethernet/ti/icssm/icssm_prueth_ecap.c | 312 ++++++++++++++++++
 .../net/ethernet/ti/icssm/icssm_prueth_ecap.h |  47 +++
 drivers/net/ethernet/ti/icssm/icssm_switch.h  |  23 ++
 8 files changed, 461 insertions(+), 1 deletion(-)
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_ecap.c
 create mode 100644 drivers/net/ethernet/ti/icssm/icssm_prueth_ecap.h
drivers/net/ethernet/ti/Kconfig +12 -0
index 96ad084f1dce..b0fc6d348151 100644
@@ -227,6 +227,18 @@ config TI_ICSS_IEP
 	  To compile this driver as a module, choose M here. The module
 	  will be called icss_iep.
 
+config TI_PRUETH_ECAP
+	tristate "TI PRUETH ECAP driver"
+	depends on TI_PRUSS
+	default TI_PRUSS
+	help
+	  This enables support for the PRU-ICSS Enhanced Capture (eCAP) driver
+	  used for rx interrupt pacing support in PRU Driver/firmwares
+	  (Dual EMAC, HSR, PRP).
+
+	  To compile this driver as a module, choose M here. The module
+	  will be called prueth_ecap.
+
 config TI_PRUETH
 	tristate "TI PRU Ethernet EMAC driver"
 	depends on PRU_REMOTEPROC
drivers/net/ethernet/ti/Makefile +2 -0
index 852640ce2b15..dce14a30d4ac 100644
@@ -49,3 +49,5 @@ icssg-y := icssg/icssg_common.o \
 	   icssg/icssg_ethtool.o
 
 obj-$(CONFIG_TI_ICSS_IEP) += icssg/icss_iep.o
+
+obj-$(CONFIG_TI_PRUETH_ECAP) += icssm/icssm_prueth_ecap.o
drivers/net/ethernet/ti/icssm/icssm_ethtool.c +38 -0
index bf7d508aecaf..b8df41014d4d 100644
@@ -7,6 +7,7 @@
 
 #include <linux/if_bridge.h>
 #include "icssm_prueth.h"
+#include "icssm_prueth_ecap.h"
 #include "icssm_vlan_mcast_filter_mmap.h"
 #include "../icssg/icss_iep.h"
 
@@ -249,6 +250,40 @@ static int icssm_emac_get_ts_info(struct net_device *ndev,
 	return 0;
 }
 
+static int icssm_emac_get_coalesce(struct net_device *ndev,
+				   struct ethtool_coalesce *coal,
+				   struct kernel_ethtool_coalesce *kernel_coal,
+				   struct netlink_ext_ack *extack)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth *prueth = emac->prueth;
+	struct prueth_ecap *ecap;
+
+	ecap = prueth->ecap;
+	if (IS_ERR(ecap))
+		return -EOPNOTSUPP;
+
+	return ecap->get_coalesce(emac, &coal->use_adaptive_rx_coalesce,
+				  &coal->rx_coalesce_usecs);
+}
+
+static int icssm_emac_set_coalesce(struct net_device *ndev,
+				   struct ethtool_coalesce *coal,
+				   struct kernel_ethtool_coalesce *kernel_coal,
+				   struct netlink_ext_ack *extack)
+{
+	struct prueth_emac *emac = netdev_priv(ndev);
+	struct prueth *prueth = emac->prueth;
+	struct prueth_ecap *ecap;
+
+	ecap = prueth->ecap;
+	if (IS_ERR(ecap))
+		return -EOPNOTSUPP;
+
+	return ecap->set_coalesce(emac, coal->use_adaptive_rx_coalesce,
+				  coal->rx_coalesce_usecs);
+}
+
 /* Ethtool support for EMAC adapter */
 const struct ethtool_ops emac_ethtool_ops = {
 	.get_drvinfo = icssm_emac_get_drvinfo,
@@ -261,5 +296,8 @@ const struct ethtool_ops emac_ethtool_ops = {
 	.get_ethtool_stats = icssm_emac_get_ethtool_stats,
 	.get_regs = icssm_emac_get_regs,
 	.get_regs_len = icssm_emac_get_regs_len,
+	.supported_coalesce_params = ETHTOOL_COALESCE_RX_USECS,
+	.get_coalesce = icssm_emac_get_coalesce,
+	.set_coalesce = icssm_emac_set_coalesce,
 };
 EXPORT_SYMBOL_GPL(emac_ethtool_ops);
drivers/net/ethernet/ti/icssm/icssm_prueth.c +24 -1
index 1b2571773d53..fdc97ed9c1fb 100644
@@ -30,6 +30,7 @@
 
 #include "icssm_prueth.h"
 #include "icssm_vlan_mcast_filter_mmap.h"
+#include "icssm_prueth_ecap.h"
 #include "../icssg/icssg_mii_rt.h"
 #include "../icssg/icss_iep.h"
 
@@ -1183,8 +1184,10 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 {
 	struct prueth_emac *emac = netdev_priv(ndev);
 	struct prueth *prueth = emac->prueth;
+	struct prueth_ecap *ecap;
 	int ret;
 
+	ecap = prueth->ecap;
 	/* set h/w MAC as user might have re-configured */
 	ether_addr_copy(emac->mac_addr, ndev->dev_addr);
 
@@ -1194,6 +1197,9 @@ static int icssm_emac_ndo_open(struct net_device *ndev)
 	icssm_prueth_emac_config(emac);
 
 	icssm_emac_set_stats(emac, &emac->stats);
+	/* initialize ecap for interrupt pacing */
+	if (!IS_ERR(ecap))
+		ecap->init(emac);
 
 	if (!prueth->emac_configured) {
 		icssm_iptp_dram_init(emac);
@@ -2152,12 +2158,25 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 		goto netdev_exit;
 	}
 
+	/* Make rx interrupt pacing optional so that users can use ECAP for
+	 * other use cases if needed
+	 */
+	prueth->ecap = icssm_prueth_ecap_get(np);
+	if (IS_ERR(prueth->ecap)) {
+		ret = PTR_ERR(prueth->ecap);
+		if (ret != -EPROBE_DEFER)
+			dev_info(dev,
+				 "No ECAP. Rx interrupt pacing disabled\n");
+		else
+			goto iep_put;
+	}
+
 	/* register the network devices */
 	if (eth0_node) {
 		ret = register_netdev(prueth->emac[PRUETH_MAC0]->ndev);
 		if (ret) {
 			dev_err(dev, "can't register netdev for port MII0");
-			goto iep_put;
+			goto ecap_put;
 		}
 
 		prueth->registered_netdevs[PRUETH_MAC0] =
@@ -2193,6 +2212,10 @@ static int icssm_prueth_probe(struct platform_device *pdev)
 		unregister_netdev(prueth->registered_netdevs[i]);
 	}
 
+ecap_put:
+	if (!IS_ERR(prueth->ecap))
+		icssm_prueth_ecap_put(prueth->ecap);
+
 iep_put:
 	icss_iep_put(prueth->iep);
 
drivers/net/ethernet/ti/icssm/icssm_prueth.h +3 -0
index 4eac7f9f8496..43fc382cd0e6 100644
@@ -12,6 +12,7 @@
 #include <linux/types.h>
 #include <linux/pruss_driver.h>
 #include <linux/remoteproc/pruss.h>
+#include <linux/netdevice.h>
 
 #include "icssm_switch.h"
 #include "icssm_prueth_ptp.h"
@@ -388,6 +389,7 @@ struct prueth {
 	struct regmap *mii_rt;
 	struct icss_iep *iep;
 
+	struct prueth_ecap *ecap;
 	const struct prueth_private_data *fw_data;
 	struct prueth_fw_offsets *fw_offsets;
 
@@ -396,6 +398,7 @@ struct prueth {
 	struct net_device *registered_netdevs[PRUETH_NUM_MACS];
 
 	unsigned int eth_type;
+	struct mutex mlock; /* serialize access */
 	u8 emac_configured;
 	u8 base_mac[ETH_ALEN];
 };
drivers/net/ethernet/ti/icssm/icssm_prueth_ecap.c new file +312 -0

312 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_prueth_ecap.h new file +47 -0

47 lines not on this page · raw message

drivers/net/ethernet/ti/icssm/icssm_switch.h +23 -0
index 0053191380b7..cb5ddd536747 100644
@@ -259,4 +259,27 @@
 #define P0_COL_BUFFER_OFFSET	0xEE00
 #define P0_Q1_BUFFER_OFFSET	0x0000
 
+/* Below Rx Interrupt pacing defines. */
+/* shared RAM */
+/* 1 byte for pace control */
+#define INTR_PAC_STATUS_OFFSET                       0x1FAF
+#define INTR_PAC_STATUS_OFFSET_PRU1                  0x1FAE
+#define INTR_PAC_STATUS_OFFSET_PRU0                  0x1FAF
+/* Interrupt Pacing disabled, Adaptive logic disabled */
+#define INTR_PAC_DIS_ADP_LGC_DIS                     0x0
+/* Interrupt Pacing enabled, Adaptive logic disabled */
+#define INTR_PAC_ENA_ADP_LGC_DIS                     0x1
+/* Interrupt Pacing enabled, Adaptive logic enabled */
+#define INTR_PAC_ENA_ADP_LGC_ENA                     0x2
+
+/* 4 bytes | previous TS from eCAP TSCNT for PRU 0 */
+#define INTR_PAC_PREV_TS_OFFSET_PRU0                 0x1FB0
+/* 4 bytes | timer expiration value for PRU 0 */
+#define INTR_PAC_TMR_EXP_OFFSET_PRU0                 0x1FB4
+/* 4 bytes | previous TS from eCAP TSCNT for PRU 1 */
+#define INTR_PAC_PREV_TS_OFFSET_PRU1                 0x1FB8
+/* 4 bytes | timer expiration value for PRU 1 */
+#define INTR_PAC_TMR_EXP_OFFSET_PRU1                 0x1FBC
+#define INTR_PAC_PREV_TS_RESET_VAL                   0x0
+
 #endif /* __ICSS_SWITCH_H */
Signature · 1 line
2.34.1
#29 lore raw

RFC PATCH v2 9/10 net: ti: prueth: Adds power management support for PRU-ICSS

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

Changes for supporting the sleep/resume feature for PRU-ICSS.

PRU-ICSS will be kept in IDLE mode for optimal power consumption by Linux power management subsystem and will be resumed when it is required.

---
 drivers/net/ethernet/ti/icssm/icssm_prueth.c | 62 ++++++++++++++++++++
 1 file changed, 62 insertions(+)
drivers/net/ethernet/ti/icssm/icssm_prueth.c +62 -0
index fdc97ed9c1fb..a3c8c746ebf8 100644
@@ -2300,6 +2300,67 @@ static void icssm_prueth_remove(struct platform_device *pdev)
 		pru_rproc_put(prueth->pru0);
 }
 
+#ifdef CONFIG_PM_SLEEP
+static int icssm_prueth_suspend(struct device *dev)
+{
+	struct prueth *prueth = dev_get_drvdata(dev);
+	struct net_device *ndev;
+	int i, ret;
+
+	for (i = 0; i < PRUETH_NUM_MACS; i++) {
+		ndev = prueth->registered_netdevs[i];
+
+		if (!ndev)
+			continue;
+
+		if (netif_running(ndev)) {
+			netif_device_detach(ndev);
+			ret = icssm_emac_ndo_stop(ndev);
+			if (ret < 0) {
+				netdev_err(ndev, "failed to stop: %d", ret);
+				return ret;
+			}
+		}
+	}
+
+	pruss_cfg_ocp_master_ports(prueth->pruss, 0);
+
+	return 0;
+}
+
+static int icssm_prueth_resume(struct device *dev)
+{
+	struct prueth *prueth = dev_get_drvdata(dev);
+	struct net_device *ndev;
+	int i, ret;
+
+	pruss_cfg_ocp_master_ports(prueth->pruss, 1);
+
+	for (i = 0; i < PRUETH_NUM_MACS; i++) {
+		ndev = prueth->registered_netdevs[i];
+
+		if (!ndev)
+			continue;
+
+		if (netif_running(ndev)) {
+			ret = icssm_emac_ndo_open(ndev);
+			if (ret < 0) {
+				netdev_err(ndev, "failed to start: %d", ret);
+				return ret;
+			}
+			netif_device_attach(ndev);
+		}
+	}
+
+	return 0;
+}
+
+#endif /* CONFIG_PM_SLEEP */
+
+static const struct dev_pm_ops prueth_dev_pm_ops = {
+	SET_SYSTEM_SLEEP_PM_OPS(icssm_prueth_suspend, icssm_prueth_resume)
+};
+
 /* AM57xx SoC-specific firmware data */
 static struct prueth_private_data am57xx_prueth_pdata = {
 	.fw_pru[PRUSS_PRU0] = {
@@ -2324,6 +2385,7 @@ static struct platform_driver prueth_driver = {
 	.driver = {
 		.name = "prueth",
 		.of_match_table = prueth_dt_match,
+		.pm = &prueth_dev_pm_ops,
 	},
 };
 module_platform_driver(prueth_driver);
Signature · 1 line
2.34.1
#30 lore raw

RFC PATCH v2 10/10 arm: dts: ti: Adds device tree nodes for PRU Cores, IEP and eCAP modules of PRU-ICSS2 Instance.

In reply to Basharath Hussain Khaja

From: Roger Quadros <[email protected]>

The TI Sitara AM57xx series of devices consists of 2 PRU-ICSS instances (PRU-ICSS1 and PRU-ICSS2). This patch adds the device tree nodes for the PRU-ICSS2 instance to support DUAL-MAC mode of operation.

Each PRU-ICSS instance consists of two PRU cores along with various peripherals such as the Interrupt Controller (PRU_INTC), the Industrial Ethernet Peripheral(IEP), the Real Time Media Independent Interface controller (MII_RT), and the Enhanced Capture (eCAP) event module.

am57-pruss.dtsi - Adds IEP and eCAP peripheral as child nodes of the PRUSS subsystem node.

am57xx-idk-common.dtsi - Adds PRU-ICSS2 instance node along with PRU eth port information and corresponding port configuration. It includes interrupt mapping for packet reception, HW timestamp collection, and PRU Ethernet ports in MII mode.

am571x-idk.dts, am572x-idk.dts and am574x-idk.dts - GPIO configuration along with delay configuration for individual PRU Ethernet port.

---
 arch/arm/boot/dts/ti/omap/am57-pruss.dtsi     | 11 ++++
 arch/arm/boot/dts/ti/omap/am571x-idk.dts      |  8 ++-
 arch/arm/boot/dts/ti/omap/am572x-idk.dts      | 10 +--
 arch/arm/boot/dts/ti/omap/am574x-idk.dts      | 10 +--
 .../boot/dts/ti/omap/am57xx-idk-common.dtsi   | 61 +++++++++++++++++++
 5 files changed, 91 insertions(+), 9 deletions(-)
arch/arm/boot/dts/ti/omap/am57-pruss.dtsi +11 -0
index 46c5383f0eee..f73316625608 100644
@@ -170,6 +170,17 @@ pruss2_iepclk_mux: iepclk-mux@30 {
 				};
 			};
 
+			pruss2_iep: iep@2e000 {
+				compatible = "ti,am5728-icss-iep";
+				reg = <0x2e000 0x31c>;
+				clocks = <&pruss2_iepclk_mux>;
+			};
+
+			pruss2_ecap: ecap@30000 {
+				compatible = "ti,pruss-ecap";
+				reg = <0x30000 0x60>;
+			};
+
 			pruss2_mii_rt: mii-rt@32000 {
 				compatible = "ti,pruss-mii", "syscon";
 				reg = <0x32000 0x58>;
arch/arm/boot/dts/ti/omap/am571x-idk.dts +7 -1
index 322cf79d22e9..02653b440585 100644
@@ -214,5 +214,11 @@ &pruss1_mdio {
 };
 
 &pruss2_mdio {
-	status = "disabled";
+	reset-gpios = <&gpio5 9 GPIO_ACTIVE_LOW>;
+	reset-delay-us = <2>;   /* PHY datasheet states 1uS min */
+};
+
+&pruss2_eth {
+	ti,pruss-gp-mux-sel = <4>,      /* MII2, needed for PRUSS1_MII0 */
+			      <4>;      /* MII2, needed for PRUSS1_MII1 */
 };
arch/arm/boot/dts/ti/omap/am572x-idk.dts +6 -4
index 94a738cb0a4d..54a8ccb9ca14 100644
@@ -28,10 +28,12 @@ &mmc2 {
 	pinctrl-2 = <&mmc2_pins_ddr_rev20>;
 };
 
-&pruss1_mdio {
-	status = "disabled";
+&pruss2_eth0_phy {
+	reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
+	reset-assert-us = <2>;   /* PHY datasheet states 1uS min */
 };
 
-&pruss2_mdio {
-	status = "disabled";
+&pruss2_eth1_phy {
+	reset-gpios = <&gpio5 9 GPIO_ACTIVE_LOW>;
+	reset-assert-us = <2>;   /* PHY datasheet states 1uS min */
 };
arch/arm/boot/dts/ti/omap/am574x-idk.dts +6 -4
index 47b9174d2353..47b6c6cb210c 100644
@@ -40,10 +40,12 @@ &emif1 {
 	status = "okay";
 };
 
-&pruss1_mdio {
-	status = "disabled";
+&pruss2_eth0_phy {
+	reset-gpios = <&gpio5 8 GPIO_ACTIVE_LOW>;
+	reset-assert-us = <2>;   /* PHY datasheet states 1uS min */
 };
 
-&pruss2_mdio {
-	status = "disabled";
+&pruss2_eth1_phy {
+	reset-gpios = <&gpio5 9 GPIO_ACTIVE_LOW>;
+	reset-assert-us = <2>;   /* PHY datasheet states 1uS min */
 };
arch/arm/boot/dts/ti/omap/am57xx-idk-common.dtsi +61 -0

70 lines not on this page · raw message

Signature · 1 line
2.34.1