can: add dummy_can driver
Vincent Mailhol
maintainerPATCH v2 1/1 can: add dummy_can driver
During the development of CAN XL, we found the need of creating a dummy CAN XL driver in order to test the new netlink interface. While this code was initially intended to be some throwaway, it received some positive feedback.
Add the dummy_can driver. This driver acts similarly to the vcan interface in the sense that it will echo back any packet it receives. The difference is that it exposes a set on bittiming parameters as a real device would and thus must be configured as if it was a real physical interface.
The driver comes with a debug mode. If debug message are enabled (for example by enabling CONFIG_CAN_DEBUG_DEVICES), it will print in the kernel log all the bittiming values, similar to what a:
ip --details link show can0
would do.
This driver is mostly intended for debugging and testing, but some developers also may want to look at it as a simple reference implementation.
---
Initially, I did not intend this to be merged. Oliver suggested that this may still be mainlined under a different name (e.g. can_nltest):
https://lore.kernel.org/linux-can/[email protected]/
Looking at what the net tree did, I saw the drivers/net/dummy.c driver and decided to mimic this as much as feasible.
Despite not being convinced by my own driver at the beginning, over time, I tend to find this more useful than initially anticipated. So after a bit of clean-up, I am resubmitting, this time to make it mainstream. I will let you guys decide if you want to merge this.
Meanwhile, please use this for your CAN XL testing!
---
Changes in v2:
- Move the debug message code out of dummy_can_netdev_open() into a new function: dummy_can_print_bittiming_info().
Link to v1: https://lore.kernel.org/r/[email protected]
Change in v1:
- This was initially part of the CAN XL RFC. Cherry-pick it and make it a stand-alone patch.
- Renamed from dummyxl to dummy_can.
- Add PMW.
- The driver is now silent by default. Enable debug mode to show all the bittimming information.
- Any frames it receives are now looped-back.
- Miscellaneous changes in the code (add PMW, refactor…)
- Add a proper Kconfig entry.
Link to RFC: https://lore.kernel.org/linux-can/[email protected]/
--- drivers/net/can/Kconfig | 17 +++ drivers/net/can/Makefile | 1 + drivers/net/can/dummy_can.c | 282 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 300 insertions(+)
drivers/net/can/Kconfig +17 -0
@@ -124,6 +124,23 @@ config CAN_CAN327 If this driver is built as a module, it will be called can327. +config CAN_DUMMY + tristate "Dummy CAN" + help + A dummy CAN module supporting Classical CAN, CAN FD and CAN XL. It + exposes bittiming values which can be configured through the netlink + interface. + + The module will simply echo any frame sent to it. If debug messages + are activated, it prints all the CAN bittiming information in the + kernel log. Aside from that it does nothing. + + This is convenient for testing the CAN netlink interface. Most of the + users will never need this. If unsure, say NO. + + To compile this driver as a module, choose M here: the module will be + called dummy-can. + config CAN_FLEXCAN tristate "Support for Freescale FLEXCAN based chips" depends on OF || COLDFIRE || COMPILE_TEST
drivers/net/can/Makefile +1 -0
@@ -21,6 +21,7 @@ obj-$(CONFIG_CAN_CAN327) += can327.o obj-$(CONFIG_CAN_CC770) += cc770/ obj-$(CONFIG_CAN_C_CAN) += c_can/ obj-$(CONFIG_CAN_CTUCANFD) += ctucanfd/ +obj-$(CONFIG_CAN_DUMMY) += dummy_can.o obj-$(CONFIG_CAN_FLEXCAN) += flexcan/ obj-$(CONFIG_CAN_GRCAN) += grcan.o obj-$(CONFIG_CAN_IFI_CANFD) += ifi_canfd/
drivers/net/can/dummy_can.c new file +282 -0
282 lines not on this page · raw message
---
base-commit: ffee675aceb9f44b0502a8bec912abb0c4f4af62
change-id: 20251013-dummy_can-29a900270aaf
prerequisite-change-id: 20251003-remove-can_change_mtu-e0ec4c0bfeeb:v1
prerequisite-patch-id: 6b3294205bd76b38257516c63b7001ab242c9b62
prerequisite-change-id: 20241229-canxl-netlink-bc640af10673:v2
prerequisite-patch-id: 6b3294205bd76b38257516c63b7001ab242c9b62
prerequisite-patch-id: 56431d12edcc0f325cf5204bb6868742c462c0ed
prerequisite-patch-id: 1547fd7ea8f1937f0491cfc0996b09890f850991
prerequisite-patch-id: 1dae270b0454352e46b927f71d1b47ff2bf7a49e
prerequisite-patch-id: e4d43de873dfdefc023a0b86e397b37ea2b9e9a3
prerequisite-patch-id: 4f3db477ff411effe70075c59ae6eac04fc65600
prerequisite-patch-id: 148dbfce9d3bb09537087ee93e60bb7819bdadee
prerequisite-patch-id: 7996539e26d449e8db260425c7287b4dce8cdf35
prerequisite-patch-id: 42215044df6a63fff07c7a7d771d7dc375cc8b0e
prerequisite-patch-id: 640ebf8ac8a1d114dcb91e6c05b9414bd09416fc
prerequisite-patch-id: 84ee5e4f937f8e4cd97833d601affea78fe55914
Best regards,
Signature · 1 line
Vincent Mailhol <[email protected]>