Skip to contentSkip to conversation

CTU CAN FD open-source IP core SocketCAN driver, PCI, platform integration and documentation

PATCH In review Pavel Pisa 4 participants 23 messages Mar 21, 2022 – Aug 12, 2022 1 message not in the archive

Subsystems (6)
lore
Share & tools
lore

Pavel Pisa

author maintainer
#0 lore raw

v8 cover CTU CAN FD open-source IP core SocketCAN driver, PCI, platform integration and documentation

This driver adds support for the CTU CAN FD open-source IP core. More documentation and core sources at project page
(https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core).
The core integration to Xilinx Zynq system as platform driver is available (https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top).
Implementation on Intel FPGA based PCI Express board is available from project (https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd).
The CTU CAN FD core emulation send for review for QEMU mainline. Development repository for QEMU emulation - ctu-canfd branch of
https://gitlab.fel.cvut.cz/canbus/qemu-canbus

More about CAN bus related projects used and developed at CTU FEE on the guidepost page http://canbus.pages.fel.cvut.cz/ .

Martin Jerabek (1):
can: ctucanfd: add support for CTU CAN FD open-source IP core - bus
independent part.

Pavel Pisa (6):
dt-bindings: vendor-prefix: add prefix for the Czech Technical
University in Prague.
dt-bindings: net: can: binding for CTU CAN FD open-source IP core.
can: ctucanfd: CTU CAN FD open-source IP core - PCI bus support.
can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.
docs: ctucanfd: CTU CAN FD open-source IP core documentation.
MAINTAINERS: Add maintainers for CTU CAN FD IP core driver

The version 8 changes:
- sent at 2022-03-22
- Ondrej Ille has extended ipxact to VHDL and header files generator to generate header files according to the last Pavel Machek's and Marc Kleine-Budde's review
- The code has been gradually updated and throughly tested with more 5.x kernels on QEMU and HW even with fully preemptive kernels. This series has been quickly tested with 5.17 kernel.

The version 7 changes:
- sent at 2020-10-31
- In response of Pavel Machek review, renamed files to match directly module names. The core specification updated to provide better description and match of the fields. Driver headers, routines adjusted etc.. To achieve this, registers HDL was regenerated and and its connection updated.
- CAN_STATE_* translation to text has been made robust to Linux kernel define value changes/updates and the function which uses table has moved after table for better readability.
- fsm_txt_buffer_user.svg redrawn from scratch to reduce file to 16 kB.
- documentation updated, unified references to recently renamed pcie-ctucanfd
- I have tried to fullfill request to cross-reference SocketCAN document by :doc: or :ref: constructs in Sphinx way, but without success. I reference geerated HTML on kernel.org site for now.

The version 6 changes:
- sent at 2020-10-22
- the driver has been tested with 5.9 bigendian MIPS kernel against QEMU CTU CAN FD model and correct behavior on PCIe virtual board for big-endian system passed
- documentation updated to reflect inclusion of SocketCAN FD and CTU CAN FD functional model support into QEMU mainline
- the integration for Cyclone V 5CSEMA4U23C6 based DE0-Nano-SoC Terasic board used for SkodaAuto research projects at our university has been clean up by its author (Jaroslav Beran) and published
https://gitlab.fel.cvut.cz/canbus/intel-soc-ctucanfd
- Xilinx Zynq Microzed MZ_APO based target for automatic test updated to Debian 10 base.

The version 5 changes:
- sent at 2020-08-15
- correct Kconfig formatting according to Randy Dunlap
- silence warnings reported by make W=1 C=1 flags. Changes suggested by Jakub Kicinski
- big thanks for core patch review by Pavel Machek resulting in more readability and formating updates
- fix power management errors found by Pavel Machek
- removed comments from d-t bindings as suggested by Rob Herring
- selected ctu,ctucanfd-2 as alternative name to ctu,ctucanfd which allows to bind to actual major HDL core sources version 2.x if for some reason driver adaptation would not work on version read from the core
- line length limit relaxed to 100 characters on some cases where it helps to readability

The version 4 changes:
- sent at 2020-08-04
- changes summary, 169 non-merge commits, 6 driver, 32 IP core sources enhancements and fixes, 58 tests in master and about additional 30 iso-testbench preparation branch.
- convert device-tree binding documentation to YAML
- QEMU model of CTU CAN FD IP core and generic extension of QEMU CAN bus emulation developed by Jan Charvat.
- driver tested on QEMU emulated Malta big-endian MIPS platform and big endian-support fixed.
- checkpatch from 5.4 kernel used to cleanup driver formatting
- header files generated from IP core IP-Xact description updated to include protocol exception (pex) field. Mechanism to set it from the driver is not provided yet.

The version 3 changes:
- sent at 2019-12-21
- adapts device tree bindings documentation according to
Rob Herring suggestions.
- the driver has been separated to individual modules for core support, PCI bus integration and platform, SoC integration.
- the FPGA design has been cleaned up and CAN protocol FSM redesigned by Ondrej Ille (the core redesign has been reason to pause attempts to driver submission)
- the work from February 2019 on core, test framework and driver 1601 commits in total, 436 commits in the core sources, 144 commits in the driver, 151 documentation, 502 in tests.
- not all continuous integration tests updated for latest design version yet
https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core/pipelines
- Zynq hardware in the loop test show no issues for after driver PCI and platform separation and latest VHDL sources updates.
- driver code has been periodically tested on 4.18.5-rt3 and 4.19 long term stable kernels.
- test of the patches before submission is run on 5.4 kernel
- the core has been integrated by Jaroslav Beran <[email protected]> into Intel FPGA based SoC used in the tester developed for Skoda auto at Department of Measurement, Faculty of Electrical Engineering, Czech Technical University https://meas.fel.cvut.cz/ . He has contributed feedback and fixes to the project.

The version 2 sent at 2019-02-27

The version 1 sent at 2019-02-22

Ondrej Ille has prepared the CTU CAN IP Core sources for new release. We are waiting with it for the driver review, our intention is to release IP when driver is reviewed and mainlined.

DKMS CTU CAN FD driver build by OpenBuildService to ease integration into Debian systems when driver is not provided by the distribution

https://build.opensuse.org/package/show/home:ppisa/ctu_can_fd

Jan Charvat <[email protected]> finished work to extend already mainlined QEMU SJA1000 and SocketCAN support to provide even CAN FD support and CTU CAN FD core support, work is mainlined already.

https://www.qemu.org/docs/master/system/devices/can.html

Thanks in advance to all who help us to deliver the project into public.

Thanks to all colleagues, reviewers and other providing feedback, infrastructure and enthusiasm and motivation for open-source work.

 .../bindings/net/can/ctu,ctucanfd.yaml        |   63 +
 .../devicetree/bindings/vendor-prefixes.yaml  |    2 +
 .../can/ctu/ctucanfd-driver.rst               |  638 +++++++
 .../can/ctu/fsm_txt_buffer_user.svg           |  151 ++
 MAINTAINERS                                   |    8 +
 drivers/net/can/Kconfig                       |    1 +
 drivers/net/can/Makefile                      |    1 +
 drivers/net/can/ctucanfd/Kconfig              |   34 +
 drivers/net/can/ctucanfd/Makefile             |   10 +
 drivers/net/can/ctucanfd/ctucanfd.h           |   82 +
 drivers/net/can/ctucanfd/ctucanfd_base.c      | 1490 +++++++++++++++++
 drivers/net/can/ctucanfd/ctucanfd_kframe.h    |   77 +
 drivers/net/can/ctucanfd/ctucanfd_kregs.h     |  325 ++++
 drivers/net/can/ctucanfd/ctucanfd_pci.c       |  304 ++++
 drivers/net/can/ctucanfd/ctucanfd_platform.c  |  132 ++
 15 files changed, 3318 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/ctu,ctucanfd.yaml
 create mode 100644 Documentation/networking/device_drivers/can/ctu/ctucanfd-driver.rst
 create mode 100644 Documentation/networking/device_drivers/can/ctu/fsm_txt_buffer_user.svg
 create mode 100644 drivers/net/can/ctucanfd/Kconfig
 create mode 100644 drivers/net/can/ctucanfd/Makefile
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd.h
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_base.c
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_kframe.h
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_kregs.h
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_pci.c
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_platform.c
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH v8 1/7 dt-bindings: vendor-prefix: add prefix for the Czech Technical University in Prague.

The Czech Technical University in Prague (CTU) is one of the biggest and oldest (founded 1707) technical universities in Europe. The abbreviation in Czech language is ČVUT according to official name in Czech language

České vysoké učení technické v Praze

The English translation

The Czech Technical University in Prague

The university pages in English

https://www.cvut.cz/en

---
 Documentation/devicetree/bindings/vendor-prefixes.yaml | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/vendor-prefixes.yaml +2 -0
index 294093d45a230..7fa538d5046a4 100644
@@ -277,6 +277,8 @@ patternProperties:
     description: Hangzhou C-SKY Microsystems Co., Ltd
   "^csq,.*":
     description: Shenzen Chuangsiqi Technology Co.,Ltd.
+  "^ctu,.*":
+    description: Czech Technical University in Prague
   "^cubietech,.*":
     description: Cubietech, Ltd.
   "^cui,.*":
Signature · 1 line
2.20.1
author maintainer
#2 lore raw

PATCH v8 2/7 dt-bindings: net: can: binding for CTU CAN FD open-source IP core.

In reply to Pavel Pisa

The device-tree bindings for open-source/open-hardware CAN FD IP core designed at the Czech Technical University in Prague.

CTU CAN FD IP core and other CTU CAN bus related projects listing and documentation page

http://canbus.pages.fel.cvut.cz/

---
 .../bindings/net/can/ctu,ctucanfd.yaml        | 63 +++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/can/ctu,ctucanfd.yaml
Documentation/devicetree/bindings/net/can/ctu,ctucanfd.yaml new file +63 -0
new file mode 100644
index 0000000000000..fb34d971dcb39
@@ -0,0 +1,63 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/can/ctu,ctucanfd.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: CTU CAN FD Open-source IP Core Device Tree Bindings
+
+description: |
+  Open-source CAN FD IP core developed at the Czech Technical University in Prague
+
+  The core sources and documentation on project page
+    [1] sources : https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core
+    [2] datasheet : https://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/doc/Datasheet.pdf
+
+  Integration in Xilinx Zynq SoC based system together with
+  OpenCores SJA1000 compatible controllers
+    [3] project : https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top
+  Martin Jerabek dimploma thesis with integration and testing
+  framework description
+    [4] PDF : https://dspace.cvut.cz/bitstream/handle/10467/80366/F3-DP-2019-Jerabek-Martin-Jerabek-thesis-2019-canfd.pdf
+
+maintainers:
+  - Pavel Pisa <[email protected]>
+  - Ondrej Ille <[email protected]>
+  - Martin Jerabek <[email protected]>
+
+properties:
+  compatible:
+    oneOf:
+      - items:
+          - const: ctu,ctucanfd-2
+          - const: ctu,ctucanfd
+      - const: ctu,ctucanfd
+
+  reg:
+    maxItems: 1
+
+  interrupts:
+    maxItems: 1
+
+  clocks:
+    description: |
+      phandle of reference clock (100 MHz is appropriate
+      for FPGA implementation on Zynq-7000 system).
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupts
+  - clocks
+
+additionalProperties: false
+
+examples:
+  - |
+    ctu_can_fd_0: can@43c30000 {
+      compatible = "ctu,ctucanfd";
+      interrupts = <0 30 4>;
+      clocks = <&clkc 15>;
+      reg = <0x43c30000 0x10000>;
+    };
Signature · 1 line
2.20.1
author maintainer
#3 lore raw

PATCH v8 3/7 can: ctucanfd: add support for CTU CAN FD open-source IP core - bus independent part.

In reply to Pavel Pisa

From: Martin Jerabek <[email protected]>

This driver adds support for the CTU CAN FD open-source IP core. More documentation and core sources at project page
(https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core).
The core integration to Xilinx Zynq system as platform driver is available (https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top).
Implementation on Intel FPGA based PCI Express board is available from project (https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd).

More about CAN bus related projects used and developed at CTU FEE at
https://canbus.pages.fel.cvut.cz/ .

---
 drivers/net/can/Kconfig                    |    1 +
 drivers/net/can/Makefile                   |    1 +
 drivers/net/can/ctucanfd/Kconfig           |   12 +
 drivers/net/can/ctucanfd/Makefile          |    7 +
 drivers/net/can/ctucanfd/ctucanfd.h        |   82 ++
 drivers/net/can/ctucanfd/ctucanfd_base.c   | 1490 ++++++++++++++++++++
 drivers/net/can/ctucanfd/ctucanfd_kframe.h |   77 +
 drivers/net/can/ctucanfd/ctucanfd_kregs.h  |  325 +++++
 8 files changed, 1995 insertions(+)
 create mode 100644 drivers/net/can/ctucanfd/Kconfig
 create mode 100644 drivers/net/can/ctucanfd/Makefile
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd.h
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_base.c
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_kframe.h
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_kregs.h
drivers/net/can/Kconfig +1 -0
index fff259247d524..ac760fd39282f 100644
@@ -170,6 +170,7 @@ config PCH_CAN
 
 source "drivers/net/can/c_can/Kconfig"
 source "drivers/net/can/cc770/Kconfig"
+source "drivers/net/can/ctucanfd/Kconfig"
 source "drivers/net/can/ifi_canfd/Kconfig"
 source "drivers/net/can/m_can/Kconfig"
 source "drivers/net/can/mscan/Kconfig"
drivers/net/can/Makefile +1 -0
index 1e660afcb61bf..0af85983634cb 100644
@@ -16,6 +16,7 @@ obj-y				+= softing/
 obj-$(CONFIG_CAN_AT91)		+= at91_can.o
 obj-$(CONFIG_CAN_CC770)		+= cc770/
 obj-$(CONFIG_CAN_C_CAN)		+= c_can/
+obj-$(CONFIG_CAN_CTUCANFD)	+= ctucanfd/
 obj-$(CONFIG_CAN_FLEXCAN)	+= flexcan/
 obj-$(CONFIG_CAN_GRCAN)		+= grcan.o
 obj-$(CONFIG_CAN_IFI_CANFD)	+= ifi_canfd/
drivers/net/can/ctucanfd/Kconfig new file +12 -0
new file mode 100644
index 0000000000000..b5f364068f86b
@@ -0,0 +1,12 @@
+config CAN_CTUCANFD
+	tristate "CTU CAN-FD IP core"
+	help
+	  This driver adds support for the CTU CAN FD open-source IP core.
+	  More documentation and core sources at project page
+	  (https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core).
+	  The core integration to Xilinx Zynq system as platform driver
+	  is available (https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top).
+	  Implementation on Intel FPGA-based PCI Express board is available
+	  from project (https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd) and
+	  on Intel SoC from project (https://gitlab.fel.cvut.cz/canbus/intel-soc-ctucanfd).
+	  Guidepost CTU FEE CAN bus projects page https://canbus.pages.fel.cvut.cz/ .
drivers/net/can/ctucanfd/Makefile new file +7 -0
new file mode 100644
index 0000000000000..259ecb0222c2b
@@ -0,0 +1,7 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+#
+# Makefile for the CTU CAN-FD IP module drivers
+#
+
+obj-$(CONFIG_CAN_CTUCANFD) := ctucanfd.o
+ctucanfd-y := ctucanfd_base.o
drivers/net/can/ctucanfd/ctucanfd.h new file +82 -0

82 lines not on this page · raw message

drivers/net/can/ctucanfd/ctucanfd_base.c new file +1490 -0

1,490 lines not on this page · raw message

drivers/net/can/ctucanfd/ctucanfd_kframe.h new file +77 -0

77 lines not on this page · raw message

drivers/net/can/ctucanfd/ctucanfd_kregs.h new file +325 -0

325 lines not on this page · raw message

Signature · 1 line
2.20.1
author maintainer
#7 lore raw

PATCH v8 5/7 can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.

In reply to Pavel Pisa

Platform bus adaptation for CTU CAN FD open-source IP core.

The core has been tested together with OpenCores SJA1000 modified to be CAN FD frames tolerant on MicroZed Zynq based MZ_APO education kits designed by Petr Porazil from PiKRON.com company. FPGA design

https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top.

The kit description at the Computer Architectures course pages

https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start .

Kit carrier board and mechanics design source files

https://gitlab.com/pikron/projects/mz_apo/microzed_apo

The work is documented in Martin Jeřábek's diploma theses Open-source and Open-hardware CAN FD Protocol Support

https://dspace.cvut.cz/handle/10467/80366
.

---
 drivers/net/can/ctucanfd/Kconfig             |  12 ++
 drivers/net/can/ctucanfd/Makefile            |   1 +
 drivers/net/can/ctucanfd/ctucanfd_platform.c | 132 +++++++++++++++++++
 3 files changed, 145 insertions(+)
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_platform.c
drivers/net/can/ctucanfd/Kconfig +12 -0
index d6e59522f4cf0..48963efc7f199 100644
@@ -20,3 +20,15 @@ config CAN_CTUCANFD_PCI
 	  The project providing FPGA design for Intel EP4CGX15 based DB4CGX15
 	  PCIe board with PiKRON.com designed transceiver riser shield is available
 	  at https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd .
+
+config CAN_CTUCANFD_PLATFORM
+	tristate "CTU CAN-FD IP core platform (FPGA, SoC) driver"
+	depends on CAN_CTUCANFD
+	depends on OF || COMPILE_TEST
+	help
+	  The core has been tested together with OpenCores SJA1000
+	  modified to be CAN FD frames tolerant on MicroZed Zynq based
+	  MZ_APO education kits designed by Petr Porazil from PiKRON.com
+	  company. FPGA design https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top.
+	  The kit description at the Computer Architectures course pages
+	  https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start .
drivers/net/can/ctucanfd/Makefile +1 -0
index 48555c3511e7c..8078f1f2c30fc 100644
@@ -7,3 +7,4 @@ obj-$(CONFIG_CAN_CTUCANFD) := ctucanfd.o
 ctucanfd-y := ctucanfd_base.o
 
 obj-$(CONFIG_CAN_CTUCANFD_PCI) += ctucanfd_pci.o
+obj-$(CONFIG_CAN_CTUCANFD_PLATFORM) += ctucanfd_platform.o
drivers/net/can/ctucanfd/ctucanfd_platform.c new file +132 -0

132 lines not on this page · raw message

Signature · 1 line
2.20.1
author maintainer
#12 lore raw

PATCH v8 7/7 MAINTAINERS: Add maintainers for CTU CAN FD IP core driver

In reply to Pavel Pisa
---
 MAINTAINERS | 8 ++++++++
 1 file changed, 8 insertions(+)
MAINTAINERS +8 -0
index cd0f68d4a34a6..82be168dbadd9 100644
@@ -5113,6 +5113,14 @@ T:	git git://linuxtv.org/media_tree.git
 F:	Documentation/devicetree/bindings/media/allwinner,sun6i-a31-csi.yaml
 F:	drivers/media/platform/sunxi/sun6i-csi/
 
+CTU CAN FD DRIVER
+M:	Pavel Pisa <[email protected]>
+M:	Ondrej Ille <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	Documentation/devicetree/bindings/net/can/ctu,ctucanfd.yaml
+F:	drivers/net/can/ctucanfd/
+
 CW1200 WLAN driver
 M:	Solomon Peachy <[email protected]>
 S:	Maintained
Signature · 1 line
2.20.1
author maintainer
#6 lore raw

PATCH v8 4/7 can: ctucanfd: CTU CAN FD open-source IP core - PCI bus support.

In reply to Pavel Pisa

PCI bus adaptation for CTU CAN FD open-source IP core.

The project providing FPGA design for Intel EP4CGX15 based DB4CGX15 PCIe board with PiKRON.com designed transceiver riser shield is available at https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd .

---
 drivers/net/can/ctucanfd/Kconfig        |  10 +
 drivers/net/can/ctucanfd/Makefile       |   2 +
 drivers/net/can/ctucanfd/ctucanfd_pci.c | 304 ++++++++++++++++++++++++
 3 files changed, 316 insertions(+)
 create mode 100644 drivers/net/can/ctucanfd/ctucanfd_pci.c
drivers/net/can/ctucanfd/Kconfig +10 -0
index b5f364068f86b..d6e59522f4cf0 100644
@@ -10,3 +10,13 @@ config CAN_CTUCANFD
 	  from project (https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd) and
 	  on Intel SoC from project (https://gitlab.fel.cvut.cz/canbus/intel-soc-ctucanfd).
 	  Guidepost CTU FEE CAN bus projects page https://canbus.pages.fel.cvut.cz/ .
+
+config CAN_CTUCANFD_PCI
+	tristate "CTU CAN-FD IP core PCI/PCIe driver"
+	depends on CAN_CTUCANFD
+	depends on PCI
+	help
+	  This driver adds PCI/PCIe support for CTU CAN-FD IP core.
+	  The project providing FPGA design for Intel EP4CGX15 based DB4CGX15
+	  PCIe board with PiKRON.com designed transceiver riser shield is available
+	  at https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd .
drivers/net/can/ctucanfd/Makefile +2 -0
index 259ecb0222c2b..48555c3511e7c 100644
@@ -5,3 +5,5 @@
 
 obj-$(CONFIG_CAN_CTUCANFD) := ctucanfd.o
 ctucanfd-y := ctucanfd_base.o
+
+obj-$(CONFIG_CAN_CTUCANFD_PCI) += ctucanfd_pci.o
drivers/net/can/ctucanfd/ctucanfd_pci.c new file +304 -0

304 lines not on this page · raw message

Signature · 1 line
2.20.1
author maintainer
#11 lore raw

PATCH v8 6/7 docs: ctucanfd: CTU CAN FD open-source IP core documentation.

In reply to Pavel Pisa

CTU CAN FD IP core documentation based on Martin Jeřábek's diploma theses Open-source and Open-hardware CAN FD Protocol Support
https://dspace.cvut.cz/handle/10467/80366
.

---
 .../can/ctu/ctucanfd-driver.rst               | 638 ++++++++++++++++++
 .../can/ctu/fsm_txt_buffer_user.svg           | 151 +++++
 2 files changed, 789 insertions(+)
 create mode 100644 Documentation/networking/device_drivers/can/ctu/ctucanfd-driver.rst
 create mode 100644 Documentation/networking/device_drivers/can/ctu/fsm_txt_buffer_user.svg
Documentation/networking/device_drivers/can/ctu/ctucanfd-driver.rst new file +638 -0
new file mode 100644
index 0000000000000..9faf1c975cf55
@@ -0,0 +1,638 @@
+.. SPDX-License-Identifier: GPL-2.0-or-later
+
+CTU CAN FD Driver
+=================
+
+Author: Martin Jerabek <[email protected]>
+
+
+About CTU CAN FD IP Core
+------------------------
+
+`CTU CAN FD <https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core>`_
+is an open source soft core written in VHDL.
+It originated in 2015 as Ondrej Ille's project
+at the `Department of Measurement <https://meas.fel.cvut.cz/>`_
+of `FEE <http://www.fel.cvut.cz/en/>`_ at `CTU <https://www.cvut.cz/en>`_.
+
+The SocketCAN driver for Xilinx Zynq SoC based MicroZed board
+`Vivado integration <https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top>`_
+and Intel Cyclone V 5CSEMA4U23C6 based DE0-Nano-SoC Terasic board
+`QSys integration <https://gitlab.fel.cvut.cz/canbus/intel-soc-ctucanfd>`_
+has been developed as well as support for
+`PCIe integration <https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd>`_ of the core.
+
+In the case of Zynq, the core is connected via the APB system bus, which does
+not have enumeration support, and the device must be specified in Device Tree.
+This kind of devices is called platform device in the kernel and is
+handled by a platform device driver.
+
+The basic functional model of the CTU CAN FD peripheral has been
+accepted into QEMU mainline. See QEMU `CAN emulation support <https://git.qemu.org/?p=qemu.git;a=blob;f=docs/can.txt>`_
+for CAN FD buses, host connection and CTU CAN FD core emulation. The development
+version of emulation support can be cloned from ctu-canfd branch of QEMU local
+development `repository <https://gitlab.fel.cvut.cz/canbus/qemu-canbus>`_.
+
+
+About SocketCAN
+---------------
+
+SocketCAN is a standard common interface for CAN devices in the Linux
+kernel. As the name suggests, the bus is accessed via sockets, similarly
+to common network devices. The reasoning behind this is in depth
+described in `Linux SocketCAN <https://www.kernel.org/doc/html/latest/networking/can.html>`_.
+In short, it offers a
+natural way to implement and work with higher layer protocols over CAN,
+in the same way as, e.g., UDP/IP over Ethernet.
+
+Device probe
+~~~~~~~~~~~~
+
+Before going into detail about the structure of a CAN bus device driver,
+let's reiterate how the kernel gets to know about the device at all.
+Some buses, like PCI or PCIe, support device enumeration. That is, when
+the system boots, it discovers all the devices on the bus and reads
+their configuration. The kernel identifies the device via its vendor ID
+and device ID, and if there is a driver registered for this identifier
+combination, its probe method is invoked to populate the driver's
+instance for the given hardware. A similar situation goes with USB, only
+it allows for device hot-plug.
+
+The situation is different for peripherals which are directly embedded
+in the SoC and connected to an internal system bus (AXI, APB, Avalon,
+and others). These buses do not support enumeration, and thus the kernel
+has to learn about the devices from elsewhere. This is exactly what the
+Device Tree was made for.
+
+Device tree
+~~~~~~~~~~~
+
+An entry in device tree states that a device exists in the system, how
+it is reachable (on which bus it resides) and its configuration –
+registers address, interrupts and so on. An example of such a device
+tree is given in .
+
+.. code:: raw
+
+           / {
+               /* ... */
+               amba: amba {
+                   #address-cells = <1>;
+                   #size-cells = <1>;
+                   compatible = "simple-bus";
+
+                   CTU_CAN_FD_0: CTU_CAN_FD@43c30000 {
+                       compatible = "ctu,ctucanfd";
+                       interrupt-parent = <&intc>;
+                       interrupts = <0 30 4>;
+                       clocks = <&clkc 15>;
+                       reg = <0x43c30000 0x10000>;
+                   };
+               };
+           };
+
+
+.. _sec:socketcan:drv:
+
+Driver structure
+~~~~~~~~~~~~~~~~
+
+The driver can be divided into two parts – platform-dependent device
+discovery and set up, and platform-independent CAN network device
+implementation.
+
+.. _sec:socketcan:platdev:
+
+Platform device driver
+^^^^^^^^^^^^^^^^^^^^^^
+
+In the case of Zynq, the core is connected via the AXI system bus, which
+does not have enumeration support, and the device must be specified in
+Device Tree. This kind of devices is called *platform device* in the
+kernel and is handled by a *platform device driver*\  [1]_.
+
+A platform device driver provides the following things:
+
+-  A *probe* function
+
+-  A *remove* function
+
+-  A table of *compatible* devices that the driver can handle
+
+The *probe* function is called exactly once when the device appears (or
+the driver is loaded, whichever happens later). If there are more
+devices handled by the same driver, the *probe* function is called for
+each one of them. Its role is to allocate and initialize resources
+required for handling the device, as well as set up low-level functions
+for the platform-independent layer, e.g., *read_reg* and *write_reg*.
+After that, the driver registers the device to a higher layer, in our
+case as a *network device*.
+
+The *remove* function is called when the device disappears, or the
+driver is about to be unloaded. It serves to free the resources
+allocated in *probe* and to unregister the device from higher layers.
+
+Finally, the table of *compatible* devices states which devices the
+driver can handle. The Device Tree entry ``compatible`` is matched
+against the tables of all *platform drivers*.
+
+.. code:: c
+
+           /* Match table for OF platform binding */
+           static const struct of_device_id ctucan_of_match[] = {
+               { .compatible = "ctu,canfd-2", },
+               { .compatible = "ctu,ctucanfd", },
+               { /* end of list */ },
+           };
+           MODULE_DEVICE_TABLE(of, ctucan_of_match);
+
+           static int ctucan_probe(struct platform_device *pdev);
+           static int ctucan_remove(struct platform_device *pdev);
+
+           static struct platform_driver ctucanfd_driver = {
+               .probe  = ctucan_probe,
+               .remove = ctucan_remove,
+               .driver = {
+                   .name = DRIVER_NAME,
+                   .of_match_table = ctucan_of_match,
+               },
+           };
+           module_platform_driver(ctucanfd_driver);
+
+
+.. _sec:socketcan:netdev:
+
+Network device driver
+^^^^^^^^^^^^^^^^^^^^^
+
+Each network device must support at least these operations:
+
+-  Bring the device up: ``ndo_open``
+
+-  Bring the device down: ``ndo_close``
+
+-  Submit TX frames to the device: ``ndo_start_xmit``
+
+-  Signal TX completion and errors to the network subsystem: ISR
+
+-  Submit RX frames to the network subsystem: ISR and NAPI
+
+There are two possible event sources: the device and the network
+subsystem. Device events are usually signaled via an interrupt, handled
+in an Interrupt Service Routine (ISR). Handlers for the events
+originating in the network subsystem are then specified in
+``struct net_device_ops``.
+
+When the device is brought up, e.g., by calling ``ip link set can0 up``,
+the driver’s function ``ndo_open`` is called. It should validate the
+interface configuration and configure and enable the device. The
+analogous opposite is ``ndo_close``, called when the device is being
+brought down, be it explicitly or implicitly.
+
+When the system should transmit a frame, it does so by calling
+``ndo_start_xmit``, which enqueues the frame into the device. If the
+device HW queue (FIFO, mailboxes or whatever the implementation is)
+becomes full, the ``ndo_start_xmit`` implementation informs the network
+subsystem that it should stop the TX queue (via ``netif_stop_queue``).
+It is then re-enabled later in ISR when the device has some space
+available again and is able to enqueue another frame.
+
+All the device events are handled in ISR, namely:
+
+#. **TX completion**. When the device successfully finishes transmitting
+   a frame, the frame is echoed locally. On error, an informative error
+   frame [2]_ is sent to the network subsystem instead. In both cases,
+   the software TX queue is resumed so that more frames may be sent.
+
+#. **Error condition**. If something goes wrong (e.g., the device goes
+   bus-off or RX overrun happens), error counters are updated, and
+   informative error frames are enqueued to SW RX queue.
+
+#. **RX buffer not empty**. In this case, read the RX frames and enqueue
+   them to SW RX queue. Usually NAPI is used as a middle layer (see ).
+
+.. _sec:socketcan:napi:
+
+NAPI
+~~~~
+
+The frequency of incoming frames can be high and the overhead to invoke
+the interrupt service routine for each frame can cause significant
+system load. There are multiple mechanisms in the Linux kernel to deal
+with this situation. They evolved over the years of Linux kernel
+development and enhancements. For network devices, the current standard
+is NAPI – *the New API*. It is similar to classical top-half/bottom-half
+interrupt handling in that it only acknowledges the interrupt in the ISR
+and signals that the rest of the processing should be done in softirq
+context. On top of that, it offers the possibility to *poll* for new
+frames for a while. This has a potential to avoid the costly round of
+enabling interrupts, handling an incoming IRQ in ISR, re-enabling the
+softirq and switching context back to softirq.
+
+More detailed documentation of NAPI may be found on the pages of Linux
+Foundation `<https://wiki.linuxfoundation.org/networking/napi>`_.
+
+Integrating the core to Xilinx Zynq
+-----------------------------------
+
+The core interfaces a simple subset of the Avalon
+`Avalon Interface Specifications <https://www.intel.com/content/dam/www/programmable/us/en/pdfs/literature/manual/mnl_avalon_spec.pdf>`_
+bus as it was originally used on
+Alterra FPGA chips, yet Xilinx natively interfaces with AXI
+`AMBA AXI and ACE Protocol Specification AXI3, AXI4, and AXI4-Lite, ACE and ACE-Lite <https://static.docs.arm.com/ihi0022/d/IHI0022D_amba_axi_protocol_spec.pdf>`_.
+The most obvious solution would be to use
+an Avalon/AXI bridge or implement some simple conversion entity.
+However, the core’s interface is half-duplex with no handshake
+signaling, whereas AXI is full duplex with two-way signaling. Moreover,
+even AXI-Lite slave interface is quite resource-intensive, and the
+flexibility and speed of AXI are not required for a CAN core.
+
+Thus a much simpler bus was chosen – APB (Advanced Peripheral Bus)
+`AMBA APB Protocol Specification v2.0 <https://static.docs.arm.com/ihi0024/c/IHI0024C_amba_apb_protocol_spec.pdf>`_.
+APB-AXI bridge is directly available in
+Xilinx Vivado, and the interface adaptor entity is just a few simple
+combinatorial assignments.
+
+Finally, to be able to include the core in a block diagram as a custom
+IP, the core, together with the APB interface, has been packaged as a
+Vivado component.
+
+CTU CAN FD Driver design
+------------------------
+
+The general structure of a CAN device driver has already been examined
+in . The next paragraphs provide a more detailed description of the CTU
+CAN FD core driver in particular.
+
+Low-level driver
+~~~~~~~~~~~~~~~~
+
+The core is not intended to be used solely with SocketCAN, and thus it
+is desirable to have an OS-independent low-level driver. This low-level
+driver can then be used in implementations of OS driver or directly
+either on bare metal or in a user-space application. Another advantage
+is that if the hardware slightly changes, only the low-level driver
+needs to be modified.
+
+The code [3]_ is in part automatically generated and in part written
+manually by the core author, with contributions of the thesis’ author.
+The low-level driver supports operations such as: set bit timing, set
+controller mode, enable/disable, read RX frame, write TX frame, and so
+on.
+
+Configuring bit timing
+~~~~~~~~~~~~~~~~~~~~~~
+
+On CAN, each bit is divided into four segments: SYNC, PROP, PHASE1, and
+PHASE2. Their duration is expressed in multiples of a Time Quantum
+(details in `CAN Specification, Version 2.0 <http://esd.cs.ucr.edu/webres/can20.pdf>`_, chapter 8).
+When configuring
+bitrate, the durations of all the segments (and time quantum) must be
+computed from the bitrate and Sample Point. This is performed
+independently for both the Nominal bitrate and Data bitrate for CAN FD.
+
+SocketCAN is fairly flexible and offers either highly customized
+configuration by setting all the segment durations manually, or a
+convenient configuration by setting just the bitrate and sample point
+(and even that is chosen automatically per Bosch recommendation if not
+specified). However, each CAN controller may have different base clock
+frequency and different width of segment duration registers. The
+algorithm thus needs the minimum and maximum values for the durations
+(and clock prescaler) and tries to optimize the numbers to fit both the
+constraints and the requested parameters.
+
+.. code:: c
+
+           struct can_bittiming_const {
+               char name[16];      /* Name of the CAN controller hardware */
+               __u32 tseg1_min;    /* Time segment 1 = prop_seg + phase_seg1 */
+               __u32 tseg1_max;
+               __u32 tseg2_min;    /* Time segment 2 = phase_seg2 */
+               __u32 tseg2_max;
+               __u32 sjw_max;      /* Synchronisation jump width */
+               __u32 brp_min;      /* Bit-rate prescaler */
+               __u32 brp_max;
+               __u32 brp_inc;
+           };
+
+
+[lst:can_bittiming_const]
+
+A curious reader will notice that the durations of the segments PROP_SEG
+and PHASE_SEG1 are not determined separately but rather combined and
+then, by default, the resulting TSEG1 is evenly divided between PROP_SEG
+and PHASE_SEG1. In practice, this has virtually no consequences as the
+sample point is between PHASE_SEG1 and PHASE_SEG2. In CTU CAN FD,
+however, the duration registers ``PROP`` and ``PH1`` have different
+widths (6 and 7 bits, respectively), so the auto-computed values might
+overflow the shorter register and must thus be redistributed among the
+two [4]_.
+
+Handling RX
+~~~~~~~~~~~
+
+Frame reception is handled in NAPI queue, which is enabled from ISR when
+the RXNE (RX FIFO Not Empty) bit is set. Frames are read one by one
+until either no frame is left in the RX FIFO or the maximum work quota
+has been reached for the NAPI poll run (see ). Each frame is then passed
+to the network interface RX queue.
+
+An incoming frame may be either a CAN 2.0 frame or a CAN FD frame. The
+way to distinguish between these two in the kernel is to allocate either
+``struct can_frame`` or ``struct canfd_frame``, the two having different
+sizes. In the controller, the information about the frame type is stored
+in the first word of RX FIFO.
+
+This brings us a chicken-egg problem: we want to allocate the ``skb``
+for the frame, and only if it succeeds, fetch the frame from FIFO;
+otherwise keep it there for later. But to be able to allocate the
+correct ``skb``, we have to fetch the first work of FIFO. There are
+several possible solutions:
+
+#. Read the word, then allocate. If it fails, discard the rest of the
+   frame. When the system is low on memory, the situation is bad anyway.
+
+#. Always allocate ``skb`` big enough for an FD frame beforehand. Then
+   tweak the ``skb`` internals to look like it has been allocated for
+   the smaller CAN 2.0 frame.
+
+#. Add option to peek into the FIFO instead of consuming the word.
+
+#. If the allocation fails, store the read word into driver’s data. On
+   the next try, use the stored word instead of reading it again.
+
+Option 1 is simple enough, but not very satisfying if we could do
+better. Option 2 is not acceptable, as it would require modifying the
+private state of an integral kernel structure. The slightly higher
+memory consumption is just a virtual cherry on top of the “cake”. Option
+3 requires non-trivial HW changes and is not ideal from the HW point of
+view.
+
+Option 4 seems like a good compromise, with its disadvantage being that
+a partial frame may stay in the FIFO for a prolonged time. Nonetheless,
+there may be just one owner of the RX FIFO, and thus no one else should
+see the partial frame (disregarding some exotic debugging scenarios).
+Basides, the driver resets the core on its initialization, so the
+partial frame cannot be “adopted” either. In the end, option 4 was
+selected [5]_.
+
+.. _subsec:ctucanfd:rxtimestamp:
+
+Timestamping RX frames
+^^^^^^^^^^^^^^^^^^^^^^
+
+The CTU CAN FD core reports the exact timestamp when the frame has been
+received. The timestamp is by default captured at the sample point of
+the last bit of EOF but is configurable to be captured at the SOF bit.
+The timestamp source is external to the core and may be up to 64 bits
+wide. At the time of writing, passing the timestamp from kernel to
+userspace is not yet implemented, but is planned in the future.
+
+Handling TX
+~~~~~~~~~~~
+
+The CTU CAN FD core has 4 independent TX buffers, each with its own
+state and priority. When the core wants to transmit, a TX buffer in
+Ready state with the highest priority is selected.
+
+The priorities are 3bit numbers in register TX_PRIORITY
+(nibble-aligned). This should be flexible enough for most use cases.
+SocketCAN, however, supports only one FIFO queue for outgoing
+frames [6]_. The buffer priorities may be used to simulate the FIFO
+behavior by assigning each buffer a distinct priority and *rotating* the
+priorities after a frame transmission is completed.
+
+In addition to priority rotation, the SW must maintain head and tail
+pointers into the FIFO formed by the TX buffers to be able to determine
+which buffer should be used for next frame (``txb_head``) and which
+should be the first completed one (``txb_tail``). The actual buffer
+indices are (obviously) modulo 4 (number of TX buffers), but the
+pointers must be at least one bit wider to be able to distinguish
+between FIFO full and FIFO empty – in this situation,
+:math:`txb\_head \equiv txb\_tail\ (\textrm{mod}\ 4)`. An example of how
+the FIFO is maintained, together with priority rotation, is depicted in
+
+|
+
++------+---+---+---+---+
+| TXB# | 0 | 1 | 2 | 3 |
++======+===+===+===+===+
+| Seq  | A | B | C |   |
++------+---+---+---+---+
+| Prio | 7 | 6 | 5 | 4 |
++------+---+---+---+---+
+|      |   | T |   | H |
++------+---+---+---+---+
+
+|
+
++------+---+---+---+---+
+| TXB# | 0 | 1 | 2 | 3 |
++======+===+===+===+===+
+| Seq  |   | B | C |   |
++------+---+---+---+---+
+| Prio | 4 | 7 | 6 | 5 |
++------+---+---+---+---+
+|      |   | T |   | H |
++------+---+---+---+---+
+
+|
+
++------+---+---+---+---+----+
+| TXB# | 0 | 1 | 2 | 3 | 0’ |
++======+===+===+===+===+====+
+| Seq  | E | B | C | D |    |
++------+---+---+---+---+----+
+| Prio | 4 | 7 | 6 | 5 |    |
++------+---+---+---+---+----+
+|      |   | T |   |   | H  |
++------+---+---+---+---+----+
+
+|
+
+.. figure:: fsm_txt_buffer_user.svg
+
+   TX Buffer states with possible transitions
+
+.. _subsec:ctucanfd:txtimestamp:
+
+Timestamping TX frames
+^^^^^^^^^^^^^^^^^^^^^^
+
+When submitting a frame to a TX buffer, one may specify the timestamp at
+which the frame should be transmitted. The frame transmission may start
+later, but not sooner. Note that the timestamp does not participate in
+buffer prioritization – that is decided solely by the mechanism
+described above.
+
+Support for time-based packet transmission was recently merged to Linux
+v4.19 `Time-based packet transmission <https://lwn.net/Articles/748879/>`_,
+but it remains yet to be researched
+whether this functionality will be practical for CAN.
+
+Also similarly to retrieving the timestamp of RX frames, the core
+supports retrieving the timestamp of TX frames – that is the time when
+the frame was successfully delivered. The particulars are very similar
+to timestamping RX frames and are described in .
+
+Handling RX buffer overrun
+~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+When a received frame does no more fit into the hardware RX FIFO in its
+entirety, RX FIFO overrun flag (STATUS[DOR]) is set and Data Overrun
+Interrupt (DOI) is triggered. When servicing the interrupt, care must be
+taken first to clear the DOR flag (via COMMAND[CDO]) and after that
+clear the DOI interrupt flag. Otherwise, the interrupt would be
+immediately [7]_ rearmed.
+
+**Note**: During development, it was discussed whether the internal HW
+pipelining cannot disrupt this clear sequence and whether an additional
+dummy cycle is necessary between clearing the flag and the interrupt. On
+the Avalon interface, it indeed proved to be the case, but APB being
+safe because it uses 2-cycle transactions. Essentially, the DOR flag
+would be cleared, but DOI register’s Preset input would still be high
+the cycle when the DOI clear request would also be applied (by setting
+the register’s Reset input high). As Set had higher priority than Reset,
+the DOI flag would not be reset. This has been already fixed by swapping
+the Set/Reset priority (see issue #187).
+
+Reporting Error Passive and Bus Off conditions
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+It may be desirable to report when the node reaches *Error Passive*,
+*Error Warning*, and *Bus Off* conditions. The driver is notified about
+error state change by an interrupt (EPI, EWLI), and then proceeds to
+determine the core’s error state by reading its error counters.
+
+There is, however, a slight race condition here – there is a delay
+between the time when the state transition occurs (and the interrupt is
+triggered) and when the error counters are read. When EPI is received,
+the node may be either *Error Passive* or *Bus Off*. If the node goes
+*Bus Off*, it obviously remains in the state until it is reset.
+Otherwise, the node is *or was* *Error Passive*. However, it may happen
+that the read state is *Error Warning* or even *Error Active*. It may be
+unclear whether and what exactly to report in that case, but I
+personally entertain the idea that the past error condition should still
+be reported. Similarly, when EWLI is received but the state is later
+detected to be *Error Passive*, *Error Passive* should be reported.
+
+
+CTU CAN FD Driver Sources Reference
+-----------------------------------
+
+.. kernel-doc:: drivers/net/can/ctucanfd/ctucanfd_hw.h
+   :internal:
+
+.. kernel-doc:: drivers/net/can/ctucanfd/ctucanfd_base.c
+   :internal:
+
+.. kernel-doc:: drivers/net/can/ctucanfd/ctucanfd_pci.c
+   :internal:
+
+.. kernel-doc:: drivers/net/can/ctucanfd/ctucanfd_platform.c
+   :internal:
+
+CTU CAN FD IP Core and Driver Development Acknowledgment
+---------------------------------------------------------
+
+* Odrej Ille <[email protected]>
+
+  * started the project as student at Department of Measurement, FEE, CTU
+  * invested great amount of personal time and enthusiasm to the project over years
+  * worked on more funded tasks
+
+* `Department of Measurement <https://meas.fel.cvut.cz/>`_,
+  `Faculty of Electrical Engineering <http://www.fel.cvut.cz/en/>`_,
+  `Czech Technical University <https://www.cvut.cz/en>`_
+
+  * is the main investor into the project over many years
+  * uses project in their CAN/CAN FD diagnostics framework for `Skoda Auto <https://www.skoda-auto.cz/>`_
+
+* `Digiteq Automotive <https://www.digiteqautomotive.com/en>`_
+
+  * funding of the project CAN FD Open Cores Support Linux Kernel Based Systems
+  * negotiated and paid CTU to allow public access to the project
+  * provided additional funding of the work
+
+* `Department of Control Engineering <https://dce.fel.cvut.cz/en>`_,
+  `Faculty of Electrical Engineering <http://www.fel.cvut.cz/en/>`_,
+  `Czech Technical University <https://www.cvut.cz/en>`_
+
+  * solving the project CAN FD Open Cores Support Linux Kernel Based Systems
+  * providing GitLab management
+  * virtual servers and computational power for continuous integration
+  * providing hardware for HIL continuous integration tests
+
+* `PiKRON Ltd. <http://pikron.com/>`_
+
+  * minor funding to initiate preparation of the project open-sourcing
+
+* Petr Porazil <[email protected]>
+
+  * design of PCIe transceiver addon board and assembly of boards
+  * design and assembly of MZ_APO baseboard for MicroZed/Zynq based system
+
+* Martin Jerabek <[email protected]>
+
+  * Linux driver development
+  * continuous integration platform architect and GHDL updates
+  * theses `Open-source and Open-hardware CAN FD Protocol Support <https://dspace.cvut.cz/bitstream/handle/10467/80366/F3-DP-2019-Jerabek-Martin-Jerabek-thesis-2019-canfd.pdf>`_
+
+* Jiri Novak <[email protected]>
+
+  * project initiation, management and use at Department of Measurement, FEE, CTU
+
+* Pavel Pisa <[email protected]>
+
+  * initiate open-sourcing, project coordination, management at Department of Control Engineering, FEE, CTU
+
+* Jaroslav Beran<[email protected]>
+
+ * system integration for Intel SoC, core and driver testing and updates
+
+* Carsten Emde (`OSADL <https://www.osadl.org/>`_)
+
+ * provided OSADL expertise to discuss IP core licensing
+ * pointed to possible deadlock for LGPL and CAN bus possible patent case which lead to relicense IP core design to BSD like license
+
+* Reiner Zitzmann and Holger Zeltwanger (`CAN in Automation <https://www.can-cia.org/>`_)
+
+ * provided suggestions and help to inform community about the project and invited us to events focused on CAN bus future development directions
+
+* Jan Charvat
+
+ * implemented CTU CAN FD functional model for QEMU which has been integrated into QEMU mainline (`docs/can.txt <https://git.qemu.org/?p=qemu.git;a=blob;f=docs/can.txt>`_)
+ * Bachelor theses Model of CAN FD Communication Controller for QEMU Emulator
+
+Notes
+-----
+
+
+.. [1]
+   Other buses have their own specific driver interface to set up the
+   device.
+
+.. [2]
+   Not to be mistaken with CAN Error Frame. This is a ``can_frame`` with
+   ``CAN_ERR_FLAG`` set and some error info in its ``data`` field.
+
+.. [3]
+   Available in CTU CAN FD repository
+   `<https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core>`_
+
+.. [4]
+   As is done in the low-level driver functions
+   ``ctucan_hw_set_nom_bittiming`` and
+   ``ctucan_hw_set_data_bittiming``.
+
+.. [5]
+   At the time of writing this thesis, option 1 is still being used and
+   the modification is queued in gitlab issue #222
+
+.. [6]
+   Strictly speaking, multiple CAN TX queues are supported since v4.19
+   `can: enable multi-queue for SocketCAN devices <https://lore.kernel.org/patchwork/patch/913526/>`_ but no mainline driver is using
+   them yet.
+
+.. [7]
+   Or rather in the next clock cycle
Documentation/networking/device_drivers/can/ctu/fsm_txt_buffer_user.svg new file +151 -0

151 lines not on this page · raw message

Signature · 1 line
2.20.1
#13 lore raw
In reply to Pavel Pisa
Quoted 11 lines · Pavel Pisa

This driver adds support for the CTU CAN FD open-source IP core. More documentation and core sources at project page
(https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core).
The core integration to Xilinx Zynq system as platform driver is available (https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top).
Implementation on Intel FPGA based PCI Express board is available from project (https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd).
The CTU CAN FD core emulation send for review for QEMU mainline. Development repository for QEMU emulation - ctu-canfd branch of
https://gitlab.fel.cvut.cz/canbus/qemu-canbus

Quoted 2 lines

More about CAN bus related projects used and developed at CTU FEE on the guidepost page http://canbus.pages.fel.cvut.cz/ .

The driver looks much better now. Good work. Please have a look at the TX path of the mcp251xfd driver, especially the tx_stop_queue and tx_wake_queue in mcp251xfd_start_xmit() and mcp251xfd_handle_tefif(). A lockless implementation should work in your hardware, too.

BTW: The PROP_SEG/PHASE_SEG1 issue is known:

Review

Quoted 4 lines
(quoted diff) +4 -0
+A curious reader will notice that the durations of the segments PROP_SEG
+and PHASE_SEG1 are not determined separately but rather combined and
+then, by default, the resulting TSEG1 is evenly divided between PROP_SEG
+and PHASE_SEG1.

and the flexcan IP core in CAN-FD mode has the same problem. When working on the bit timing parameter, I'll plan to have separate PROP_SEG/PHASE_SEG1 min/max in the kernel, so that the bit timing algorithm can take care of this.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
author maintainer
#14 lore raw

Hello Marc,

thanks for positive reply for our years effort.

Quoted 7 lines · On Tuesday 22 of March 2022 08:46:22 Marc Kleine-Budde wrote:
Quoted 1 line · Pavel Pisa

This driver adds support for the CTU CAN FD open-source IP core.

The driver looks much better now. Good work. Please have a look at the TX path of the mcp251xfd driver, especially the tx_stop_queue and tx_wake_queue in mcp251xfd_start_xmit() and mcp251xfd_handle_tefif(). A lockless implementation should work in your hardware, too.

Is this blocker for now? I would like to start with years tested base.

We have HW timestamping implemented for actual stable CTU CAN FD IP core version, support for variable number of TX buffers which count can be parameterized up to 8 in the prepared version and long term desire to configurable-SW defined multi-queue which our HW interface allows to dynamically server by á TX buffers. But plan is to keep combinations of the design and driver compatible from the actual revision.

I would be happy if we can agree on some base/minimal support and get it into mainline and use it as base for the followup patch series.

I understand that I have sent code late for actual merge window, but I am really loaded by teaching, related RISC-V simulator
https://github.com/cvut/qtrvsim , ESA and robotic projects at company. So I would prefer to go step by step and cooperate on updates and testing with my diploma students.

Quoted 10 lines

BTW: The PROP_SEG/PHASE_SEG1 issue is known:

Review

Quoted 4 lines
(quoted diff) +4 -0
+A curious reader will notice that the durations of the segments PROP_SEG
+and PHASE_SEG1 are not determined separately but rather combined and
+then, by default, the resulting TSEG1 is evenly divided between PROP_SEG
+and PHASE_SEG1.

and the flexcan IP core in CAN-FD mode has the same problem. When working on the bit timing parameter, I'll plan to have separate PROP_SEG/PHASE_SEG1 min/max in the kernel, so that the bit timing algorithm can take care of this.

Hmm, when I have thought about that years ago I have not noticed real difference when time quanta is move between PROP_SEG and PHASE_SEG1. So for me it had no influence on the algorithm computation and could be done on the chip level when minimal and maximal sum is respected. But may it be I have overlooked something and there is difference for CAN FD. May it be my colleagues Jiri Novak and Ondrej Ille are more knowable.

As for the optimal timequantas per bit value, I agree that it is not so simple. In the fact SJW and even tipple-sampling should be defined in percentage of bit time and then all should be optimized together and even combination with slight bitrate error should be preferred against other exact matching when there is significant difference in the other parameters values.

But I am not ready to dive into it till our ESA space NanoXplore FPGA project passes final stage...

By the way we have received report from Andrew Dennison about successful integration of CTU CAN FD into Litex based RISC-V system. Tested with the Linux our Linux kernel driver.

The first iteration there, but he reported that some corrections from his actual development needs to be added to the public repo still to be usable out of the box

https://github.com/AndrewD/litecan

Best wishes,

Pavel Pisa
phone: +420 603531357
e-mail: [email protected]
Department of Control Engineering FEE CVUT Karlovo namesti 13, 121 35, Prague 2
university: http://dce.fel.cvut.cz/
personal: http://cmp.felk.cvut.cz/~pisa
projects: https://www.openhub.net/accounts/ppisa
CAN related:http://canbus.pages.fel.cvut.cz/ Open Technologies Research Education and Exchange Services
https://gitlab.fel.cvut.cz/otrees/org/-/wikis/home

#15 lore raw
Quoted 22 lines · Pavel Pisa

Hello Marc,

thanks for positive reply for our years effort.

Quoted 7 lines · On Tuesday 22 of March 2022 08:46:22 Marc Kleine-Budde wrote:
Quoted 1 line · Pavel Pisa

This driver adds support for the CTU CAN FD open-source IP core.

The driver looks much better now. Good work. Please have a look at the TX path of the mcp251xfd driver, especially the tx_stop_queue and tx_wake_queue in mcp251xfd_start_xmit() and mcp251xfd_handle_tefif(). A lockless implementation should work in your hardware, too.

Is this blocker for now? I would like to start with years tested base.

We have HW timestamping implemented for actual stable CTU CAN FD IP core version, support for variable number of TX buffers which count can be parameterized up to 8 in the prepared version and long term desire to configurable-SW defined multi-queue which our HW interface allows to dynamically server by á TX buffers. But plan is to keep combinations of the design and driver compatible from the actual revision.

Quoted 2 lines

I would be happy if we can agree on some base/minimal support and get it into mainline and use it as base for the followup patch series.

IMHO I would vote for this approach too.

There are many users of that open source IP CAN core right now and the out-of-tree maintenance is no fun for all of them.

When the driver status is fine from the technical and programming style standpoint we should move the improvements for the lockless transmissions to a later date.

Best regards,
Oliver

Quoted 60 lines

I understand that I have sent code late for actual merge window, but I am really loaded by teaching, related RISC-V simulator
https://github.com/cvut/qtrvsim , ESA and robotic projects at company. So I would prefer to go step by step and cooperate on updates and testing with my diploma students.

Quoted 10 lines

BTW: The PROP_SEG/PHASE_SEG1 issue is known:

Review

Quoted 4 lines
(quoted diff) +4 -0
+A curious reader will notice that the durations of the segments PROP_SEG
+and PHASE_SEG1 are not determined separately but rather combined and
+then, by default, the resulting TSEG1 is evenly divided between PROP_SEG
+and PHASE_SEG1.

and the flexcan IP core in CAN-FD mode has the same problem. When working on the bit timing parameter, I'll plan to have separate PROP_SEG/PHASE_SEG1 min/max in the kernel, so that the bit timing algorithm can take care of this.

Hmm, when I have thought about that years ago I have not noticed real difference when time quanta is move between PROP_SEG and PHASE_SEG1. So for me it had no influence on the algorithm computation and could be done on the chip level when minimal and maximal sum is respected. But may it be I have overlooked something and there is difference for CAN FD. May it be my colleagues Jiri Novak and Ondrej Ille are more knowable.

As for the optimal timequantas per bit value, I agree that it is not so simple. In the fact SJW and even tipple-sampling should be defined in percentage of bit time and then all should be optimized together and even combination with slight bitrate error should be preferred against other exact matching when there is significant difference in the other parameters values.

But I am not ready to dive into it till our ESA space NanoXplore FPGA project passes final stage...

By the way we have received report from Andrew Dennison about successful integration of CTU CAN FD into Litex based RISC-V system. Tested with the Linux our Linux kernel driver.

The first iteration there, but he reported that some corrections from his actual development needs to be added to the public repo still to be usable out of the box

https://github.com/AndrewD/litecan

Best wishes,

Pavel Pisa
phone: +420 603531357
e-mail: [email protected]
Department of Control Engineering FEE CVUT Karlovo namesti 13, 121 35, Prague 2
university: http://dce.fel.cvut.cz/
personal: http://cmp.felk.cvut.cz/~pisa
projects: https://www.openhub.net/accounts/ppisa
CAN related:http://canbus.pages.fel.cvut.cz/ Open Technologies Research Education and Exchange Services
https://gitlab.fel.cvut.cz/otrees/org/-/wikis/home

#16 lore raw
In reply to Pavel Pisa
Quoted 6 lines · Pavel Pisa
Quoted 4 lines

The driver looks much better now. Good work. Please have a look at the TX path of the mcp251xfd driver, especially the tx_stop_queue and tx_wake_queue in mcp251xfd_start_xmit() and mcp251xfd_handle_tefif(). A lockless implementation should work in your hardware, too.

Is this blocker for now? I would like to start with years tested base.

Makes sense.

Quoted 6 lines

We have HW timestamping implemented for actual stable CTU CAN FD IP core version, support for variable number of TX buffers which count can be parameterized up to 8 in the prepared version and long term desire to configurable-SW defined multi-queue which our HW interface allows to dynamically server by á TX buffers. But plan is to keep combinations of the design and driver compatible from the actual revision.

Is the number of RX and TX buffers and TX queues auto detectable by software, or do we need DT bindings for this?

Quoted 8 lines

I would be happy if we can agree on some base/minimal support and get it into mainline and use it as base for the followup patch series.

I understand that I have sent code late for actual merge window, but I am really loaded by teaching, related RISC-V simulator
https://github.com/cvut/qtrvsim , ESA and robotic projects at company. So I would prefer to go step by step and cooperate on updates and testing with my diploma students.

The net-next merge window closed with Monday evening, so this driver will go into net-next for v5.19.

Quoted 11 lines
Quoted 10 lines

BTW: The PROP_SEG/PHASE_SEG1 issue is known:

Review

Quoted 4 lines
(quoted diff) +4 -0
+A curious reader will notice that the durations of the segments PROP_SEG
+and PHASE_SEG1 are not determined separately but rather combined and
+then, by default, the resulting TSEG1 is evenly divided between PROP_SEG
+and PHASE_SEG1.

and the flexcan IP core in CAN-FD mode has the same problem. When working on the bit timing parameter, I'll plan to have separate PROP_SEG/PHASE_SEG1 min/max in the kernel, so that the bit timing algorithm can take care of this.

Quoted 7 lines

Hmm, when I have thought about that years ago I have not noticed real difference when time quanta is move between PROP_SEG and PHASE_SEG1. So for me it had no influence on the algorithm computation and could be done on the chip level when minimal and maximal sum is respected. But may it be I have overlooked something and there is difference for CAN FD. May it be my colleagues Jiri Novak and Ondrej Ille are more knowable.

Jiri, Ondrej, I'm interested in details :)

Quoted 3 lines

As for the optimal timequantas per bit value, I agree that it is not so simple. In the fact SJW and even tipple-sampling should be defined in percentage of bit time

I thought of specifying SJW in a relative value, too.

Quoted 1 line

and then all should be optimized together

SJW has no influence on the bit rate and sample point. Although SJW is max phase seg 2, so it's maximum is influenced by the sample point.

Quoted 3 lines

and even combination with slight bitrate error should be preferred against other exact matching when there is significant difference in the other parameters values.

Since linux-4.8, i.e.

| 7da29f97d6c8 can: dev: can-calc-bit-timing(): better sample point calculation

the algorithm optimizes for best bit minimal absolute bit rate error first and then for minimal sample point error. The sample point must be <= the nominal sample point. I have some experiments where the algorithm optimizes the absolute sample point error.

For more complicated bit timing optimization you need to combine the bitrate error and the sample point error into a function that needs to be minimized.

Quoted 2 lines

But I am not ready to dive into it till our ESA space NanoXplore FPGA project passes final stage...

Ok

Quoted 3 lines

By the way we have received report from Andrew Dennison about successful integration of CTU CAN FD into Litex based RISC-V system. Tested with the Linux our Linux kernel driver.

That sounds interesting!

Quoted 5 lines

The first iteration there, but he reported that some corrections from his actual development needs to be added to the public repo still to be usable out of the box

https://github.com/AndrewD/litecan

Nice!

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
author maintainer
#17 lore raw

Hello Marc,

Quoted 9 lines · On Tuesday 22 of March 2022 10:22:12 Marc Kleine-Budde wrote:
Quoted 6 lines

We have HW timestamping implemented for actual stable CTU CAN FD IP core version, support for variable number of TX buffers which count can be parameterized up to 8 in the prepared version and long term desire to configurable-SW defined multi-queue which our HW interface allows to dynamically server by á TX buffers. But plan is to keep combinations of the design and driver compatible from the actual revision.

Is the number of RX and TX buffers and TX queues auto detectable by software, or do we need DT bindings for this?

we plan to count info available through field in the registers. See paragraph 3.1.39 TXTB_INFO

http://canbus.pages.fel.cvut.cz/ctucanfd_ip_core/doc/Datasheet.pdf

The bits are read as zeros on the older version so if the zero is found older default 4 will be chosen by the driver. So I prefer no side information channel DTC etc. Even on the actual PCI integration you can read number of channels from the support PCI BAR range and locate actual cores on the other BAR.

Quoted 2 lines

The net-next merge window closed with Monday evening, so this driver will go into net-next for v5.19.

My shame. I hoped to get driver into mainline till Embedded World Conference 2022 where we participate with our RISC-V education tools and materials so that I could report to others in the RISC-V camp and even CiA that we are finally easily to use.

On the other hand more time gives time for better review and possible cleanup. But I would wait with features addition till some base accepted to the next or mainline. I hope that interfaces will not change too much before inclusion that actual tested code can get in.

Quoted 38 lines
Quoted 11 lines
Quoted 10 lines

BTW: The PROP_SEG/PHASE_SEG1 issue is known:

Quoted 4 lines

+A curious reader will notice that the durations of the segments PROP_SEG +and PHASE_SEG1 are not determined separately but rather combined and +then, by default, the resulting TSEG1 is evenly divided between PROP_SEG +and PHASE_SEG1.

and the flexcan IP core in CAN-FD mode has the same problem. When working on the bit timing parameter, I'll plan to have separate PROP_SEG/PHASE_SEG1 min/max in the kernel, so that the bit timing algorithm can take care of this.

Quoted 7 lines

Hmm, when I have thought about that years ago I have not noticed real difference when time quanta is move between PROP_SEG and PHASE_SEG1. So for me it had no influence on the algorithm computation and could be done on the chip level when minimal and maximal sum is respected. But may it be I have overlooked something and there is difference for CAN FD. May it be my colleagues Jiri Novak and Ondrej Ille are more knowable.

Jiri, Ondrej, I'm interested in details :)

Quoted 3 lines

As for the optimal timequantas per bit value, I agree that it is not so simple. In the fact SJW and even tipple-sampling should be defined in percentage of bit time

I thought of specifying SJW in a relative value, too.

Quoted 1 line

and then all should be optimized together

SJW has no influence on the bit rate and sample point. Although SJW is max phase seg 2, so it's maximum is influenced by the sample point.

Quoted 3 lines

and even combination with slight bitrate error should be preferred against other exact matching when there is significant difference in the other parameters values.

Since linux-4.8, i.e.

Quoted 7 lines

| 7da29f97d6c8 can: dev: can-calc-bit-timing(): better sample point | calculation

the algorithm optimizes for best bit minimal absolute bit rate error first and then for minimal sample point error. The sample point must be <= the nominal sample point. I have some experiments where the algorithm optimizes the absolute sample point error.

Yes but you do not need exact bitrate even when it is available. I do no look into standards now, but I think 1% error should not be a problem. May it be even 3% error when whole jitter and clocks frequency errors fit below it should work (5 (bit stuff) x 3% = 15% is less than 100% - 80% (typical SP) and with well tuned SF even 25 or 50% of the last bit could be accepted that communication can at leas sometimes succeed). So allow error of 0.1% as better than too low or too high TQ per bit or strange SJW can be acceptable. On the other hand if CAN is used with time triggered stuff or keep/ synchronize whole plant global time then 0.1% is too much. So at the end in this case really tuning for concrete application comes into play. But in kernel algorithm is there to make most common usages easy...

Quoted 3 lines

For more complicated bit timing optimization you need to combine the bitrate error and the sample point error into a function that needs to be minimized.

Yes.

Quoted 5 lines
Quoted 3 lines

By the way we have received report from Andrew Dennison about successful integration of CTU CAN FD into Litex based RISC-V system. Tested with the Linux our Linux kernel driver.

That sounds interesting!

I hope that community joint forces can reach state where CAN FD will be solved on all FPGA and combinations easily and open source way. We need to find way for funding of certification and long term sustainability. But at least our previous release and actual public code is game level save point.

Best wishes,

Pavel
--
Pavel Pisa
phone: +420 603531357
e-mail: [email protected]
Department of Control Engineering FEE CVUT Karlovo namesti 13, 121 35, Prague 2
university: http://dce.fel.cvut.cz/
personal: http://cmp.felk.cvut.cz/~pisa
projects: https://www.openhub.net/accounts/ppisa
CAN related:http://canbus.pages.fel.cvut.cz/ Open Technologies Research Education and Exchange Services
https://gitlab.fel.cvut.cz/otrees/org/-/wikis/home

#19 lore raw
In reply to a message not in the archive
Quoted 1 line · Ondrej Ille

sorry for the late reply, my work duties are keeping me very busy.

Known problem :)

Quoted 10 lines

Let me just quickly comment on topics discussed in the emails above.

*1. Separation of PROP and TSEG1*

IMHO there is no real benefit. The reason why CTU CAN FD has this split is legacy. First implementation back in 2015 had this split since I wanted to follow the standard. In HW, the first thing done in bit timing logic (prescaler module), these two numbers are added, and all further resynchronization/hard-synchronization is done with TSEG1 value...

Thanks for the insight. It's not easy to get in touch with the developers of the proprietary IP cores :)

Never the less, there's another IP core which has different sizes for the prop and tseg1 register. So an update of the bit timing constant would help both.

Quoted 4 lines

*2. Number of TXT Buffers and RX Buffer size:*

Pavel already replied with TXTB_INFO. The same role has the RX_MEM_INFO register, when it comes to RX side.

Thanks for the clarification.

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
author maintainer
#20 lore raw
In reply to Marc Kleine-Budde

Hello Marc and others,

Quoted 9 lines · On Tuesday 22 of March 2022 10:22:12 Marc Kleine-Budde wrote:
Quoted 6 lines · Pavel Pisa
Quoted 4 lines

The driver looks much better now. Good work. Please have a look at the TX path of the mcp251xfd driver, especially the tx_stop_queue and tx_wake_queue in mcp251xfd_start_xmit() and mcp251xfd_handle_tefif(). A lockless implementation should work in your hardware, too.

Is this blocker for now? I would like to start with years tested base.

Makes sense.

I have missed timing for 5.18 but v5.18-rc1 is out so I would be happy if we do not miss 5.19 merge window at least with minimal version.

If we succeeds in review reasonably early we could fit with inclusion or at least the first review round of Mataj Vasilevski's

https://gitlab.fel.cvut.cz/canbus/ctucanfd_ip_core/-/tree/hw-timestamping

Please, help us to finish this subsequent goal of our portfolio development. I think that our work is valuable for the community, code can be tested even in QEMU CAN bus subsystem which we architected as well

https://www.qemu.org/docs/master/system/devices/can.html

I hope that it is usable for others. I have the last support call from Magdeburg University where they use CAN emulation for some Volkswagen projects. The Xilinx uses code for their CAN FD controllers emulation. Thei have whole stack including mainline driver for their CAN FD controller in mainline but on the other hand, their CAN FD is bound to Xilinx devices emulation. But CTU CAN FD provides generic PCI integration and can be used even on broad range of FPGAs so its emulation and matching driver provides valuable tool even if you do not consider use its actual design on hardware.

New version of the latency tester based on CTU CAN FD timestamping is in preparation as upgrade of original Martin Jerabek's work done on Oliver Hartkopp's and Volkswagen call

https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top/wikis/uploads/56b4d27d8f81ae390fc98bdce803398f/F3-BP-2016-Jerabek-Martin-Jerabek-thesis-2016.pdf

Best wishes,

Pavel
--
Pavel Pisa
phone: +420 603531357
e-mail: [email protected]
Department of Control Engineering FEE CVUT Karlovo namesti 13, 121 35, Prague 2
university: http://dce.fel.cvut.cz/
personal: http://cmp.felk.cvut.cz/~pisa
projects: https://www.openhub.net/accounts/ppisa
CAN related:http://canbus.pages.fel.cvut.cz/ Open Technologies Research Education and Exchange Services
https://gitlab.fel.cvut.cz/otrees/org/-/wikis/home

#21 lore raw
Quoted 9 lines · Pavel Pisa

Hello Marc and others,

Quoted 6 lines · On Tuesday 22 of March 2022 10:22:12 Marc Kleine-Budde wrote:
Quoted 5 lines · Pavel Pisa
Quoted 4 lines

The driver looks much better now. Good work. Please have a look at the TX path of the mcp251xfd driver, especially the tx_stop_queue and tx_wake_queue in mcp251xfd_start_xmit() and mcp251xfd_handle_tefif(). A lockless implementation should work in your hardware, too.

Quoted 6 lines
Quoted 3 lines
Quoted 1 line

Is this blocker for now? I would like to start with years tested base.

Makes sense.

I have missed timing for 5.18 but v5.18-rc1 is out so I would be happy if we do not miss 5.19 merge window at least with minimal version.

I've taken the patch (almost) as is, I marked both can_bittiming_const static, as sparse complained about that and I changed the order of two variable declarations to look nicer :)

Looking forward for more patches!

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#22 lore raw

Hello Pavel, Martin, Ondrej,

Quoted 10 lines · Marc Kleine-Budde
Quoted 2 lines · Pavel Pisa

I have missed timing for 5.18 but v5.18-rc1 is out so I would be happy if we do not miss 5.19 merge window at least with minimal version.

I've taken the patch (almost) as is, I marked both can_bittiming_const static, as sparse complained about that and I changed the order of two variable declarations to look nicer :)

Looking forward for more patches!

The patches now landed in net-next \o/

But while checking the automatic review results from Patchwork here ...

https://patchwork.kernel.org/project/netdevbpf/list/?series=&submitter=7454&state=*&q=CTU+CAN+FD&archive=&delegate=

... it looks like that at least the two red 'failed' markers should be addressed in follow up patches.

The 'inline' warnings are easy to fix:

https://patchwork.hopto.org/static/nipa/633430/12818712/source_inline/stderr

But the module_param()'s in

https://patchwork.hopto.org/static/nipa/633430/12818710/module_param/stderr

should probably be revisited, whether the parameters (PCI/MSI and 'second IP core') could be handled by some automatic detection.

Or did I miss something that makes these module parameters really necessary?

Best regards,
Oliver

author maintainer
#23 lore raw

Hello Oliver,

Quoted 5 lines · On Wednesday 20 of April 2022 18:40:18 Oliver Hartkopp wrote:
Quoted 4 lines · Marc Kleine-Budde
Quoted 2 lines · Pavel Pisa

I have missed timing for 5.18 but v5.18-rc1 is out so I would be happy if we do not miss 5.19 merge window at least with minimal version.

Quoted 7 lines
Quoted 5 lines

I've taken the patch (almost) as is, I marked both can_bittiming_const static, as sparse complained about that and I changed the order of two variable declarations to look nicer :)

Looking forward for more patches!

The patches now landed in net-next \o/

This is a big day...

Quoted 11 lines

But while checking the automatic review results from Patchwork here ...

https://patchwork.kernel.org/project/netdevbpf/list/?series=&submitter=7454
&state=*&q=CTU+CAN+FD&archive=&delegate=

... it looks like that at least the two red 'failed' markers should be addressed in follow up patches.

The 'inline' warnings are easy to fix:

https://patchwork.hopto.org/static/nipa/633430/12818712/source_inline/stder

If it means that no local function should be marked as inline if they are in C file then inline removal is fully OK and according to current compilers behavior probably comletely equivalent.

Quoted 6 lines

But the module_param()'s in

https://patchwork.hopto.org/static/nipa/633430/12818710/module_param/stderr

should probably be revisited, whether the parameters (PCI/MSI and 'second IP core') could be handled by some automatic detection.

The situation is handled automatically. The parameters are there only for situation when there is problem with PCIe design on the FPGA side to allow disable MSI interrupts and test if without that FPGA behaves correctly. It is great help to debug problems. In my case, if I remember well, problem was that some reference clocks has not been connected into core so it could sync for CPU initiated transfers and for MSI own initiated it failed horribly.

Quoted 2 lines

Or did I miss something that makes these module parameters really necessary?

They can go away for normal use. They are help for those who want to debug problems of CTU CAN FD core connection to PCIe FPGA design to test and identify one of possible sources problems sources in in the PCIe core setup and clocking. But that can be kept as separate patches for debugging purposes. Parameters can be connected directly to instances in sys or tuned some other way as well. But I think that they do no belong to netling or something networking related. It is strictly related to hardware and module load testing after magic sequence to get rid of broken test FPGA design and rescan for newly loaded Intel/Altera FPGA design

https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd/-/blob/master/scripts/db4cgx15-program
https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd/-/blob/master/scripts/test-ip-read

Device reapears after

echo 1 > /sys/bus/pci/rescan

then driver can be connected and tested.

But I prepare patch to get remove these debug options when it is preferred.

I expect that we test net-next soon and Mataj Vasilevski prepares patches for timestamping. Probably optional/controlled by some compile time option. Again it is good to have option to eliminate possible source of problems. The base has been tested really many times but addons are relatively new.

Best wises,

Pavel
--
Pavel Pisa
phone: +420 603531357
e-mail: [email protected]
Department of Control Engineering FEE CVUT Karlovo namesti 13, 121 35, Prague 2
university: http://control.fel.cvut.cz/
personal: http://cmp.felk.cvut.cz/~pisa
projects: https://www.openhub.net/accounts/ppisa
CAN related:http://canbus.pages.fel.cvut.cz/ Open Technologies Research Education and Exchange Services
https://gitlab.fel.cvut.cz/otrees/org/-/wikis/home

#8 lore raw

Re: [PATCH v8 5/7] can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.

In reply to Pavel Pisa

Hi Pavel,

Quoted 20 lines · Pavel Pisa

Platform bus adaptation for CTU CAN FD open-source IP core.

The core has been tested together with OpenCores SJA1000 modified to be CAN FD frames tolerant on MicroZed Zynq based MZ_APO education kits designed by Petr Porazil from PiKRON.com company. FPGA design

https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top.

The kit description at the Computer Architectures course pages

https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start .

Kit carrier board and mechanics design source files

https://gitlab.com/pikron/projects/mz_apo/microzed_apo

The work is documented in Martin Jeřábek's diploma theses Open-source and Open-hardware CAN FD Protocol Support

Quoted 6 lines

https://dspace.cvut.cz/handle/10467/80366
.

Thanks for your patch, which is now commit e8f0c23a2415fa8f ("can:
ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.") in linux-can-next/master.

drivers/net/can/ctucanfd/ctucanfd_platform.c line 112

Quoted 6 lines
drivers/net/can/ctucanfd/ctucanfd_platform.c new file +3 -0
 
+/* Match table for OF platform binding */
+static const struct of_device_id ctucan_of_match[] = {
+       { .compatible = "ctu,ctucanfd-2", },

Do you need to match on the above compatible value?
The driver seems to treat the hardware the same, and the DT bindings state the compatible value below should always be present.

drivers/net/can/ctucanfd/ctucanfd_platform.c line 116

Quoted 4 lines
drivers/net/can/ctucanfd/ctucanfd_platform.c new file +4 -0
+       { .compatible = "ctu,ctucanfd", },
+       { /* end of list */ },
+};
+MODULE_DEVICE_TABLE(of, ctucan_of_match);

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

author maintainer
#9 lore raw

Re: [PATCH v8 5/7] can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.

Hello Geert,

Quoted 11 lines · On Tuesday 03 of May 2022 13:37:46 Geert Uytterhoeven wrote:

Hi Pavel,

drivers/net/can/ctucanfd/ctucanfd_platform.c line 112

Quoted 6 lines
drivers/net/can/ctucanfd/ctucanfd_platform.c new file +3 -0
 
+/* Match table for OF platform binding */
+static const struct of_device_id ctucan_of_match[] = {
+       { .compatible = "ctu,ctucanfd-2", },

Do you need to match on the above compatible value?
The driver seems to treat the hardware the same, and the DT bindings state the compatible value below should always be present.

I would keep it because there will be newer revisions and releases of the core and I consider "ctu,ctucanfd" as the match to generic one with maximal attempt to adjust to the version from provided info registers but identification with the fixed version "ctu,ctucanfd-2" ensures that some old hardware which is in the wild is directly recognized even at /sys level and if we need to do some workarounds for autodetection etc. it can be recognized.

I understand that in ideal world that should never be required if we keep compatability right and if there is really new major completely incompatible revision we would need to use new identifier anyway. But we and the world is not perfect, so I would keep that safety option.

May it be there are designs with 5 years old IP core version in the wild and may it be even with this ID.... May be they need some version specific adjustment... Yes version should be readable from IP, hopefully, but that was experimental version and I am not sure how much register map changed from that days (can be analyzed from GIT if support request appears). You know how it works with feebacks when chain of subcontracted companies does integration for carmaker etc...

For example there appears questions and interest to update it to actual Debian for LinCAN after ten or 15 years of silence because that or origina CAN drivers solution works somewhere...

So I am personally more inclined to keep versionned ID.

Best wishes,

Pavel

#10 lore raw

Re: [PATCH v8 5/7] can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.

Quoted 15 lines · Pavel Pisa

Hello Geert,

Quoted 11 lines · On Tuesday 03 of May 2022 13:37:46 Geert Uytterhoeven wrote:

Hi Pavel,

drivers/net/can/ctucanfd/ctucanfd_platform.c line 112

Quoted 6 lines
drivers/net/can/ctucanfd/ctucanfd_platform.c new file +3 -0
 
+/* Match table for OF platform binding */
+static const struct of_device_id ctucan_of_match[] = {
+       { .compatible = "ctu,ctucanfd-2", },

Do you need to match on the above compatible value?
The driver seems to treat the hardware the same, and the DT bindings state the compatible value below should always be present.

Quoted 8 lines

I would keep it because there will be newer revisions and releases of the core and I consider "ctu,ctucanfd" as the match to generic one with maximal attempt to adjust to the version from provided info registers but identification with the fixed version "ctu,ctucanfd-2" ensures that some old hardware which is in the wild is directly recognized even at /sys level and if we need to do some workarounds for autodetection etc. it can be recognized.

As Geert said:
- There are 2 bindings in the driver which are (currently) treated the same.
- The binding documentation says devices must always have the ctu,ctucanfd compatible.

This means (currently) the ctu,ctucanfd-2 is not needed in the driver. We can add it back once we need it.

Or are there devices that have a compatible of ctu,ctucanfd-2 without stating to be compatible with ctu,ctucanfd?

regards,
Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
#4 lore raw

Re: [PATCH v8 3/7] can: ctucanfd: add support for CTU CAN FD open-source IP core - bus independent part.

In reply to Pavel Pisa

I was about to convert these macros into static inline bool functions and thinking the naming can be improved a bit:

drivers/net/can/ctucanfd/ctucanfd_base.c line 154

Quoted 2 lines · Pavel Pisa
drivers/net/can/ctucanfd/ctucanfd_base.c new file +2 -0
+#define CTU_CAN_FD_TXTNF(priv) (!!FIELD_GET(REG_STATUS_TXNF, ctucan_read32(priv, CTUCANFD_STATUS)))
+#define CTU_CAN_FD_ENABLED(priv) (!!FIELD_GET(REG_MODE_ENA, ctucan_read32(priv, CTUCANFD_MODE)))

[...]

The common prefix for functions seems to be "ctucan_", so if I convert CTU_CAN_FD_ENABLED -> ctucan_fd_enabled() the unfamiliar reader might think this functions tests if the controller is in FD mode.

As far as I understand the code, the test is if the controller is enabled at all. This is done via the ctucan_chip_start() function and undone via ctucan_chip_stop(). So a better function names might be:
- ctucan_chip_started()
- ctucan_chip_is_started()
- ctucan_chip_enabled()
- ctucan_chip_is_enabled()

Quoted 8 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +8 -0
+/**
+ * ctucan_set_btr() - Sets CAN bus bit timing in CTU CAN FD
+ * @ndev:	Pointer to net_device structure
+ * @bt:		Pointer to Bit timing structure
+ * @nominal:	True - Nominal bit timing, False - Data bit timing
+ *
+ * Return: 0 - OK, -%EPERM if controller is enabled
+ */

drivers/net/can/ctucanfd/ctucanfd_base.c line 218

Quoted 10 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +10 -0
+static int ctucan_set_btr(struct net_device *ndev, struct can_bittiming *bt, bool nominal)
+{
+	struct ctucan_priv *priv = netdev_priv(ndev);
+	int max_ph1_len = 31;
+	u32 btr = 0;
+	u32 prop_seg = bt->prop_seg;
+	u32 phase_seg1 = bt->phase_seg1;
+
+	if (CTU_CAN_FD_ENABLED(priv)) {
+		netdev_err(ndev, "BUG! Cannot set bittiming - CAN is enabled\n");

I would want to replace "CAN" with "Chip" or "Controller".

Quoted 38 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +38 -0
+		return -EPERM;
+	}
+
+	if (nominal)
+		max_ph1_len = 63;
+
+	/* The timing calculation functions have only constraints on tseg1, which is prop_seg +
+	 * phase1_seg combined. tseg1 is then split in half and stored into prog_seg and phase_seg1.
+	 * In CTU CAN FD, PROP is 6/7 bits wide but PH1 only 6/5, so we must re-distribute the
+	 * values here.
+	 */
+	if (phase_seg1 > max_ph1_len) {
+		prop_seg += phase_seg1 - max_ph1_len;
+		phase_seg1 = max_ph1_len;
+		bt->prop_seg = prop_seg;
+		bt->phase_seg1 = phase_seg1;
+	}
+
+	if (nominal) {
+		btr = FIELD_PREP(REG_BTR_PROP, prop_seg);
+		btr |= FIELD_PREP(REG_BTR_PH1, phase_seg1);
+		btr |= FIELD_PREP(REG_BTR_PH2, bt->phase_seg2);
+		btr |= FIELD_PREP(REG_BTR_BRP, bt->brp);
+		btr |= FIELD_PREP(REG_BTR_SJW, bt->sjw);
+
+		ctucan_write32(priv, CTUCANFD_BTR, btr);
+	} else {
+		btr = FIELD_PREP(REG_BTR_FD_PROP_FD, prop_seg);
+		btr |= FIELD_PREP(REG_BTR_FD_PH1_FD, phase_seg1);
+		btr |= FIELD_PREP(REG_BTR_FD_PH2_FD, bt->phase_seg2);
+		btr |= FIELD_PREP(REG_BTR_FD_BRP_FD, bt->brp);
+		btr |= FIELD_PREP(REG_BTR_FD_SJW_FD, bt->sjw);
+
+		ctucan_write32(priv, CTUCANFD_BTR_FD, btr);
+	}
+
+	return 0;
+}

[...]

Quoted 13 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +13 -0
+/**
+ * ctucan_start_xmit() - Starts the transmission
+ * @skb:	sk_buff pointer that contains data to be Txed
+ * @ndev:	Pointer to net_device structure
+ *
+ * Invoked from upper layers to initiate transmission. Uses the next available free TXT Buffer and
+ * populates its fields to start the transmission.
+ *
+ * Return: %NETDEV_TX_OK on success, %NETDEV_TX_BUSY when no free TXT buffer is available,
+ *         negative return values reserved for error cases
+ */
+static netdev_tx_t ctucan_start_xmit(struct sk_buff *skb, struct net_device *ndev)
+{

drivers/net/can/ctucanfd/ctucanfd_base.c line 620

Quoted 10 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +10 -0
+	struct ctucan_priv *priv = netdev_priv(ndev);
+	struct canfd_frame *cf = (struct canfd_frame *)skb->data;
+	u32 txtb_id;
+	bool ok;
+	unsigned long flags;
+
+	if (can_dropped_invalid_skb(ndev, skb))
+		return NETDEV_TX_OK;
+
+	if (unlikely(!CTU_CAN_FD_TXTNF(priv))) {

I'm also looking for nicer names for "CTU_CAN_FD_TXTNF". What about ctucan_txt_buffer_full() and reverse the logic?

drivers/net/can/ctucanfd/ctucanfd_base.c line 624

Quoted 4 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +4 -0
+		netif_stop_queue(ndev);
+		netdev_err(ndev, "BUG!, no TXB free when queue awake!\n");
+		return NETDEV_TX_BUSY;
+	}

Marc

Signature · 4 lines
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |
author maintainer
#5 lore raw

Re: [PATCH v8 3/7] can: ctucanfd: add support for CTU CAN FD open-source IP core - bus independent part.

Hello Marc,

thanks for interrest to clean the code.

Quoted 15 lines · On Wednesday 10 of August 2022 22:00:43 Marc Kleine-Budde wrote:

I was about to convert these macros into static inline bool functions and thinking the naming can be improved a bit:

Quoted 4 lines · Pavel Pisa

+#define CTU_CAN_FD_TXTNF(priv) (!!FIELD_GET(REG_STATUS_TXNF, ctucan_read32(priv, CTUCANFD_STATUS)))
+#define CTU_CAN_FD_ENABLED(priv) (!!FIELD_GET(REG_MODE_ENA, ctucan_read32(priv, CTUCANFD_MODE)))

[...]

The common prefix for functions seems to be "ctucan_", so if I convert CTU_CAN_FD_ENABLED -> ctucan_fd_enabled() the unfamiliar reader might think this functions tests if the controller is in FD mode.

Quoted 7 lines

As far as I understand the code, the test is if the controller is enabled at all. This is done via the ctucan_chip_start() function and undone via ctucan_chip_stop(). So a better function names might be:
- ctucan_chip_started()
- ctucan_chip_is_started()
- ctucan_chip_enabled()
- ctucan_chip_is_enabled()

All are understandable.

When I think about meaning then I have come to these two

ctucan_operation_is_enabled()

ctucan_communication_enabled()

As for TXNF, it meaning is TX buffers are not full or there is at least one buffer available to fill/prepare another Tx request. So some examples of descriptive names

ctucan_empty_txbuf_available()

or if negated then

ctucan_no_empty_txbuf()

If you want to clear that yourself then go on, you have my ACK in advance, I am not available on Internet for next week.

You can left it to the Matej Vasilevski prepared patches series. I hope he finds some time to prepare it to mainline his thesis work. But if he does not have time I takeover results of his work and attempt to form his path and add some mine followups (clock etc..) to include them in network next during September...

As for the basic driver functionality testing, it is possible with mainline QEMU easily

https://www.qemu.org/docs/master/system/devices/can.html

The setup to run commits against ARM kernel environment automatically on Zynq HW is available but requires access rights to our GitLab repositories and actual kernel version is

5.10.19-rt32-00004-gd19e6d98b097 #1 SMP PREEMPT_RT

I can add access to you to our GitLab but I do not expect that is is of much interrest. I plan to update base but it is used on more education and other systems, so we want to keep wider compatability.

Matej Vasilevski has HW for local testing and tests on mainline. Pavel Hronek will continue on his work with goal to have another setups with automatic testing, including latencies which would follow actual mainline. Ideally in cooperation with OSADL to be used on systems with other controllers on hardware available there. But that is longer goal and we look for OSADL members who have interrest for such continuous RT and CAN latencies QA farm testing.

Quoted 12 lines
Quoted 12 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +9 -0
+/**
+ * ctucan_set_btr() - Sets CAN bus bit timing in CTU CAN FD
+ * @ndev:	Pointer to net_device structure
+ * @bt:		Pointer to Bit timing structure
+ * @nominal:	True - Nominal bit timing, False - Data bit timing
+ *
+ * Return: 0 - OK, -%EPERM if controller is enabled
+ */
+static int ctucan_set_btr(struct net_device *ndev, struct can_bittiming

*bt, bool nominal) +{

(quoted diff) +2 -0
+	struct ctucan_priv *priv = netdev_priv(ndev);
+	int max_ph1_len = 31;
Quoted 8 lines

drivers/net/can/ctucanfd/ctucanfd_base.c line 218

Quoted 6 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +6 -0
+	u32 btr = 0;
+	u32 prop_seg = bt->prop_seg;
+	u32 phase_seg1 = bt->phase_seg1;
+
+	if (CTU_CAN_FD_ENABLED(priv)) {
+		netdev_err(ndev, "BUG! Cannot set bittiming - CAN is enabled\n");

I would want to replace "CAN" with "Chip" or "Controller".

May it be

BUG! Cannot set bittiming when operation is enabled

Quoted 62 lines
Quoted 39 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +7 -0
+		return -EPERM;
+	}
+
+	if (nominal)
+		max_ph1_len = 63;
+
+	/* The timing calculation functions have only constraints on tseg1,

which is prop_seg + + * phase1_seg combined. tseg1 is then split in half
and stored into prog_seg and phase_seg1. + * In CTU CAN FD, PROP is 6/7
bits wide but PH1 only 6/5, so we must re-distribute the + * values
here.

drivers/net/can/ctucanfd/ctucanfd_base.c new file +28 -0
+	 */
+	if (phase_seg1 > max_ph1_len) {
+		prop_seg += phase_seg1 - max_ph1_len;
+		phase_seg1 = max_ph1_len;
+		bt->prop_seg = prop_seg;
+		bt->phase_seg1 = phase_seg1;
+	}
+
+	if (nominal) {
+		btr = FIELD_PREP(REG_BTR_PROP, prop_seg);
+		btr |= FIELD_PREP(REG_BTR_PH1, phase_seg1);
+		btr |= FIELD_PREP(REG_BTR_PH2, bt->phase_seg2);
+		btr |= FIELD_PREP(REG_BTR_BRP, bt->brp);
+		btr |= FIELD_PREP(REG_BTR_SJW, bt->sjw);
+
+		ctucan_write32(priv, CTUCANFD_BTR, btr);
+	} else {
+		btr = FIELD_PREP(REG_BTR_FD_PROP_FD, prop_seg);
+		btr |= FIELD_PREP(REG_BTR_FD_PH1_FD, phase_seg1);
+		btr |= FIELD_PREP(REG_BTR_FD_PH2_FD, bt->phase_seg2);
+		btr |= FIELD_PREP(REG_BTR_FD_BRP_FD, bt->brp);
+		btr |= FIELD_PREP(REG_BTR_FD_SJW_FD, bt->sjw);
+
+		ctucan_write32(priv, CTUCANFD_BTR_FD, btr);
+	}
+
+	return 0;
+}

[...]

Quoted 20 lines

+/**
+ * ctucan_start_xmit() - Starts the transmission
+ * @skb: sk_buff pointer that contains data to be Txed
+ * @ndev: Pointer to net_device structure
+ *
+ * Invoked from upper layers to initiate transmission. Uses the next available free TXT Buffer and + * populates its fields to start the transmission.
+ *
+ * Return: %NETDEV_TX_OK on success, %NETDEV_TX_BUSY when no free TXT
buffer is available, + * negative return values reserved for
error cases
+ */
+static netdev_tx_t ctucan_start_xmit(struct sk_buff *skb, struct net_device *ndev) +{

drivers/net/can/ctucanfd/ctucanfd_base.c new file +5 -0
+	struct ctucan_priv *priv = netdev_priv(ndev);
+	struct canfd_frame *cf = (struct canfd_frame *)skb->data;
+	u32 txtb_id;
+	bool ok;
+	unsigned long flags;
Quoted 8 lines

drivers/net/can/ctucanfd/ctucanfd_base.c line 620

Quoted 5 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +5 -0
+
+	if (can_dropped_invalid_skb(ndev, skb))
+		return NETDEV_TX_OK;
+
+	if (unlikely(!CTU_CAN_FD_TXTNF(priv))) {

I'm also looking for nicer names for "CTU_CAN_FD_TXTNF". What about ctucan_txt_buffer_full() and reverse the logic?

possible as well

Quoted 6 lines

drivers/net/can/ctucanfd/ctucanfd_base.c line 624

Quoted 4 lines
drivers/net/can/ctucanfd/ctucanfd_base.c new file +4 -0
+		netif_stop_queue(ndev);
+		netdev_err(ndev, "BUG!, no TXB free when queue awake!\n");
+		return NETDEV_TX_BUSY;
+	}

Marc

Best wishes,

Pavel

Signature · 12 lines
                Pavel Pisa
    phone:      +420 603531357
    e-mail:     [email protected]
    Department of Control Engineering FEE CVUT
    Karlovo namesti 13, 121 35, Prague 2
    university: http://control.fel.cvut.cz/
    personal:   http://cmp.felk.cvut.cz/~pisa
    projects:   https://www.openhub.net/accounts/ppisa
    CAN related:http://canbus.pages.fel.cvut.cz/
    RISC-V education: https://comparch.edu.cvut.cz/
    Open Technologies Research Education and Exchange Services
    https://gitlab.fel.cvut.cz/otrees/org/-/wikis/home