drivers/can: add support for Bosch C_CAN controller
v3 cover drivers/can: add support for Bosch C_CAN controller
The series was created to optimize the use of the C_CAN controller (maximum number of message objects, use of FIFO, ...) to get the best possible RX/TX throughput from hardware.
To emphasize the purpose of the series I also added the patch which adds multi-message support to `sendmsg ', rather than' submitting it separately. In fact, it too has contributed to increasing transmission throughput.
The patches prior to the one adding the BOSCH C_CAN controller driver, are a backporting of commits from the linux kernel that also impacted on the driver itself and I found it necessary to add to the series.
The latest patch, as described in its commit, modified Stephen Battazzo's patch [1] with bug fixes, backporting of commits from the linux kernel, extension of message objects to 64 and improvements in FIFO handling. This series was in fact preceded by the creation of patches which I sent to the Linux kernel and which were then accepted:
387da6bc7a82 ("can: c_can: cache frames to operate as a true FIFO") 28e86e9ab522 ("can: c_can: support tx ring algorithm")a54cdbba9dee ("can: c_can: exit c_can_do_tx() early if no frames have been sent") 5064e40596f4 ("can: c_can: remove struct c_can_priv::priv field") 06fc143b2ede dt-bindings: net: can: c_can: convert to json-schema 132f2d45fb23 ("can: c_can: add support to 64 message objects") 13831ce69c77 ("can: c_can: prepare to up the message objects number") fcbded019855 ("can: c_can: use 32-bit write to set arbitration register") eddf67115040 ("can: c_can: add a comment about IF_RX interface's use") c8a6b44388cb ("can: c_can: fix indentation")f65735c203d5 ("can: c_can: remove unused code")
The patch was tested on a custom board mounting an AM335x SOC.
PCI support has not been developed.
[1] http://xenomai.org/pipermail/xenomai/2015-July/034690.html
Changes in v3:
- Add virtual CAN testsuite
Changes in v2:
- Expand the commit message to better describe the added API.
- Drop 'default n' Kconfig
- Enable the driver for Xenomai CI builds
- Drop commented code
- Drop power managemet (pm) code
Dario Binacchi (7):
testsuite/smokey: add virtual CAN testsuite drivers/can: add multi message support to sendmsg drivers/can: add CAN_ERR_CRTL_ACTIVE info status drivers/can: add len field to can frame structures drivers/can: add a minimal support to ethtool API drivers/can: fix updating of tx_count statistics drivers/can: add support for Bosch C_CAN controller
.gitlab-ci.yml | 2 + configure.ac | 1 + include/rtdm/uapi/can.h | 6 +- kernel/drivers/can/Kconfig | 1 + kernel/drivers/can/Makefile | 4 +- kernel/drivers/can/README | 1 + kernel/drivers/can/c_can/Kconfig | 15 + kernel/drivers/can/c_can/Makefile | 8 + kernel/drivers/can/c_can/rtcan_c_can.c | 1298 +++++++++++++++++ kernel/drivers/can/c_can/rtcan_c_can.h | 255 ++++ .../drivers/can/c_can/rtcan_c_can_ethtool.c | 47 + .../drivers/can/c_can/rtcan_c_can_platform.c | 461 ++++++ kernel/drivers/can/mscan/rtcan_mscan.c | 1 + kernel/drivers/can/rtcan_dev.h | 4 +- kernel/drivers/can/rtcan_ethtool.c | 75 + kernel/drivers/can/rtcan_ethtool.h | 24 + kernel/drivers/can/rtcan_flexcan.c | 1 + kernel/drivers/can/rtcan_raw.c | 240 +-- kernel/drivers/can/rtcan_raw_dev.c | 20 + kernel/drivers/can/rtcan_socket.h | 5 +- kernel/drivers/can/rtcan_virt.c | 1 + kernel/drivers/can/sja1000/rtcan_sja1000.c | 1 + testsuite/smokey/Makefile.am | 2 + testsuite/smokey/can-virt/Makefile.am | 8 + testsuite/smokey/can-virt/virt.c | 295 ++++ 25 files changed, 2659 insertions(+), 117 deletions(-) create mode 100644 kernel/drivers/can/c_can/Kconfig create mode 100644 kernel/drivers/can/c_can/Makefile create mode 100644 kernel/drivers/can/c_can/rtcan_c_can.c create mode 100644 kernel/drivers/can/c_can/rtcan_c_can.h create mode 100644 kernel/drivers/can/c_can/rtcan_c_can_ethtool.c create mode 100644 kernel/drivers/can/c_can/rtcan_c_can_platform.c create mode 100644 kernel/drivers/can/rtcan_ethtool.c create mode 100644 kernel/drivers/can/rtcan_ethtool.h create mode 100644 testsuite/smokey/can-virt/Makefile.am create mode 100644 testsuite/smokey/can-virt/virt.c
Signature · 1 line
2.17.1
PATCH v3 1/7 testsuite/smokey: add virtual CAN testsuite
Add a minimal test for the virtual CAN driver, checking that sent messages are received correctly.
The timeout on read operations has been wired to 1 s in order not to fail the test in case the verbose option is enabled.
---
(no changes since v1)
configure.ac | 1 + testsuite/smokey/Makefile.am | 2 + testsuite/smokey/can-virt/Makefile.am | 8 + testsuite/smokey/can-virt/virt.c | 295 ++++++++++++++++++++++++++ 4 files changed, 306 insertions(+) create mode 100644 testsuite/smokey/can-virt/Makefile.am create mode 100644 testsuite/smokey/can-virt/virt.c
configure.ac +1 -0
@@ -1005,6 +1005,7 @@ AC_CONFIG_FILES([ \ testsuite/smokey/cpu-affinity/Makefile \ testsuite/smokey/gdb/Makefile \ testsuite/smokey/y2038/Makefile \ + testsuite/smokey/can-virt/Makefile testsuite/clocktest/Makefile \ testsuite/xeno-test/Makefile \ utils/Makefile \
testsuite/smokey/Makefile.am +2 -0
@@ -12,6 +12,7 @@ smokey_SOURCES = main.c COBALT_SUBDIRS = \ arith \ bufp \ + can-virt \ cpu-affinity \ fpu-stress \ gdb \
@@ -49,6 +50,7 @@ MERCURY_SUBDIRS = \ DIST_SUBDIRS = \ arith \ bufp \ + can-virt \ cpu-affinity \ dlopen \ fpu-stress \
testsuite/smokey/can-virt/Makefile.am new file +8 -0
@@ -0,0 +1,8 @@ +noinst_LIBRARIES = libcan-virt.a + +libcan_virt_a_SOURCES = \ + virt.c + +libcan_virt_a_CPPFLAGS = \ + @XENO_USER_CFLAGS@ \ + -I$(top_srcdir)/include
testsuite/smokey/can-virt/virt.c new file +295 -0
295 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH v3 1/7] testsuite/smokey: add virtual CAN testsuite
Quoted 10 lines · Dario Binacchi
Add a minimal test for the virtual CAN driver, checking that sent messages are received correctly.
The timeout on read operations has been wired to 1 s in order not to fail the test in case the verbose option is enabled.
Signed-off-by Dario Binacchi <[email protected]>---
(no changes since v1)
Well... you added it after v1 ;)
Thanks for picking up this task! It immediately showed value:
[ 277.753790] RT-Socket-CAN 0.90.2 - (C) 2006 RT-Socket-CAN Development Team [ 284.000869] BUG: spinlock bad magic on CPU#0, smokey/1552 [ 284.000870] lock: rtcan_recv_list_lock+0x0/0xffffffffffffd5c0 [xeno_can], .magic: 00000000, .owner: <none>/-1, .owner_cpu: 0 [ 284.000871] CPU: 0 PID: 1552 Comm: smokey Not tainted 5.10.76+ #232 [ 284.000871] Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS rel-1.14.0-0-g155821a1990b-prebuilt.qemu.org 04/01/2014 [ 284.000872] IRQ stage: Linux [ 284.000872] Call Trace: [ 284.000872] dump_stack+0x84/0x9c [ 284.000872] do_raw_spin_lock+0x71/0xc0 [ 284.000873] rtcan_socket_init+0xa8/0x110 [xeno_can] [ 284.000873] rtcan_raw_socket+0x14/0x20 [xeno_can] [ 284.000873] __rtdm_dev_socket+0xbe/0x220 [ 284.000874] ? CoBaLt_open+0x40/0x40 [ 284.000874] CoBaLt_socket+0xa/0x10 [ 284.000874] handle_root_syscall+0xf1/0x400 [ 284.000875] __pipeline_syscall+0xd3/0x2f0 [ 284.000875] pipeline_syscall+0x6f/0x100 [ 284.000875] syscall_enter_from_user_mode+0x30/0x90 [ 284.000876] do_syscall_64+0xf/0x50 [ 284.000876] entry_SYSCALL_64_after_hwframe+0x44/0xa9 [ 284.000876] RIP: 0033:0x7fdc04b2c08d [ 284.000877] Code: 98 48 89 45 f0 8b 45 c8 48 98 48 89 45 e8 8b 45 cc 48 98 48 89 45 e0 48 8b 55 f0 48 8b 75 e8 48 8b 7d e0 b8 4e 00 00 10 0f 05 <48> 89 45 d8 48 8b 45 d8 89 45 fc 83 7d fc 00 79 33 83 7d fc 9f 74 [ 284.000877] RSP: 002b:00007ffc40b58400 EFLAGS: 00000206 ORIG_RAX: 000000001000004e [ 284.000878] RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00007fdc04b2c08d [ 284.000879] RDX: 0000000000000001 RSI: 0000000000000003 RDI: 000000000000001d [ 284.000879] RBP: 00007ffc40b58440 R08: 00007ffc40b5846c R09: 00007ffc40b581ab [ 284.000879] R10: 00007fdc04b189f0 R11: 0000000000000206 R12: 0000000000000000 [ 284.000880] R13: 00007ffc40b58690 R14: 0000000000000000 R15: 0000000000000000 [ 284.048863] IRQ pipeline: out-of-band stage stalled on IRQ entry
That was wit xeno_can loaded, but without xeno_can_virt.
This should be fixed (I'll also have a look), but your test should also try to load the required modules, see testsuite/smokey/net_common/ setup.c (maybe you can even reuse smokey_net_modprobe).
Jan
Signature · 2 lines
Siemens AG, T RDA IOT Corporate Competence Center Embedded Linux
PATCH v3 2/7 drivers/can: add multi message support to sendmsg
In reply to Dario BinacchiThe `user_msghdr' structure is designed to send multiple messages as well, so rtcan_raw_sendmsg() can also send multiple messages. This avoids having to add the sendmmsg system call which requires more extensive Xenomai changes.
---
(no changes since v1)
kernel/drivers/can/rtcan_raw.c | 239 ++++++++++++++++++--------------- 1 file changed, 128 insertions(+), 111 deletions(-)
kernel/drivers/can/rtcan_raw.c +128 -111
@@ -762,113 +762,13 @@ ssize_t rtcan_raw_recvmsg(struct rtdm_fd *fd, } -ssize_t rtcan_raw_sendmsg (struct rtdm_fd *fd, -const struct user_msghdr *msg,int flags) +static ssize_t __rtcan_raw_sendmsg (struct rtcan_device *dev,struct rtcan_socket *sock, +can_frame_t *frame,nanosecs_rel_t timeout) { -struct rtcan_socket *sock =rtdm_fd_to_private (fd); -struct sockaddr_can *scan = (struct sockaddr_can *)msg->msg_name; -struct sockaddr_can scan_buf; -struct iovec *iov = (struct iovec *)msg->msg_iov; -struct iovec iov_buf; -can_frame_t *frame; -can_frame_t frame_buf; -rtdm_lockctx_t lock_ctx; -nanosecs_rel_t timeout =0 ;struct tx_wait_queue tx_wait; -struct rtcan_device *dev; -int ifindex =0 ; -int ret =0 ; +rtdm_lockctx_t lock_ctx;spl_t s; - - -if (flags &MSG_OOB )/* Mirror BSD error message compatibility */ -return -EOPNOTSUPP ; - -/* Only MSG_DONTWAIT is a valid flag. */ -if (flags & ~MSG_DONTWAIT ) -return -EINVAL ; - -/* Check msg_iovlen, only one buffer allowed */ -if (msg->msg_iovlen !=1 ) -return -EMSGSIZE ; - -if (scan ==NULL ) { -/* No socket address. Will use bound interface for sending */ - -if (msg->msg_namelen !=0 ) -return -EINVAL ; - - -/* We only want a consistent value here, a spin lock would be -* overkill. Nevertheless, the binding could change till we have -* the chance to send. Blame the user, though. */ - ifindex =atomic_read (&sock->ifindex); - -if (!ifindex) -/* Socket isn't bound or bound to all interfaces. Go out. */ -return -ENXIO ; - }else { -/* Socket address given */ -if (msg->msg_namelen <sizeof (struct sockaddr_can )) -return -EINVAL ; - -if (rtdm_fd_is_user (fd)) { -/* Copy socket address from userspace */ -if (!rtdm_read_user_ok (fd, msg->msg_name, -sizeof (struct sockaddr_can )) || -rtdm_copy_from_user (fd, &scan_buf, msg->msg_name, -sizeof (struct sockaddr_can ))) -return -EFAULT ; - - scan = &scan_buf; - } - -/* Check address family */ -if (scan->can_family !=AF_CAN ) -return -EINVAL ; - - ifindex = scan->can_ifindex; - } - -if (rtdm_fd_is_user (fd)) { -/* Copy IO vector from userspace */ -if (!rtdm_rw_user_ok (fd, msg->msg_iov, -sizeof (struct iovec )) || -rtdm_copy_from_user (fd, &iov_buf, msg->msg_iov, -sizeof (struct iovec ))) -return -EFAULT ; - - iov = &iov_buf; - } - -/* Check size of buffer */ -if (iov->iov_len !=sizeof (can_frame_t)) -return -EMSGSIZE ; - - frame = (can_frame_t *)iov->iov_base; - -if (rtdm_fd_is_user (fd)) { -/* Copy CAN frame from userspace */ -if (!rtdm_read_user_ok (fd, iov->iov_base, -sizeof (can_frame_t)) || -rtdm_copy_from_user (fd, &frame_buf, iov->iov_base, -sizeof (can_frame_t))) -return -EFAULT ; - - frame = &frame_buf; - } - -/* Adjust iovec in the common way */ - iov->iov_base +=sizeof (can_frame_t); - iov->iov_len -=sizeof (can_frame_t); -/* ... and copy it back to userspace if necessary */ -if (rtdm_fd_is_user (fd)) { -if (rtdm_copy_to_user (fd, msg->msg_iov, iov, -sizeof (struct iovec ))) -return -EFAULT ; - } - -/* At last, we've got the frame ... */ +int ret =0 ;/* Check if DLC between 0 and 15 */ if (frame->can_dlc >15 )
@@ -881,11 +781,6 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_fd *fd,return -EINVAL ; } -if ((dev =rtcan_dev_get_by_index (ifindex)) ==NULL ) -return -ENXIO ; - - timeout = (flags &MSG_DONTWAIT ) ?RTDM_TIMEOUT_NONE : sock->tx_timeout; - tx_wait.rt_task =rtdm_task_current ();/* Register the task at the socket's TX wait queue and decrement
@@ -931,7 +826,6 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_fd *fd,/* We got access */ -/* Push message onto stack for loopback when TX done */ if (rtcan_loopback_enabled (sock))rtcan_tx_push (dev, sock, frame);
@@ -960,10 +854,133 @@ ssize_t rtcan_raw_sendmsg(struct rtdm_fd *fd, send_out2:rtdm_lock_put_irqrestore (&dev->device_lock, lock_ctx); send_out1: -rtcan_dev_dereference (dev);return ret; } +ssize_t rtcan_raw_sendmsg (struct rtdm_fd *fd, +const struct user_msghdr *msg,int flags) +{ +struct rtcan_socket *sock =rtdm_fd_to_private (fd); +struct sockaddr_can *scan = (struct sockaddr_can *)msg->msg_name; +struct sockaddr_can scan_buf; +struct iovec *iov = (struct iovec *)msg->msg_iov; +struct iovec iov_buf; +can_frame_t *frame; +can_frame_t frame_buf; +nanosecs_rel_t timeout; +struct rtcan_device *dev; +int ret =0 , ifindex =0 , i =0 , n, sent =0 ; + +if (flags &MSG_OOB )/* Mirror BSD error message compatibility */ +return -EOPNOTSUPP ; + +/* Only MSG_DONTWAIT is a valid flag. */ +if (flags & ~MSG_DONTWAIT ) +return -EINVAL ; + + timeout = (flags &MSG_DONTWAIT ) ?RTDM_TIMEOUT_NONE : sock->tx_timeout; + +if (scan ==NULL ) { +/* No socket address. Will use bound interface for sending */ +if (msg->msg_namelen !=0 ) +return -EINVAL ; + + +/* We only want a consistent value here, a spin lock would be +* overkill. Nevertheless, the binding could change till we have +* the chance to send. Blame the user, though. */ + ifindex =atomic_read (&sock->ifindex); +if (!ifindex) +/* Socket isn't bound or bound to all interfaces. Go out. */ +return -ENXIO ; + }else { +/* Socket address given */ +if (msg->msg_namelen <sizeof (struct sockaddr_can )) +return -EINVAL ; + +if (rtdm_fd_is_user (fd)) { +/* Copy socket address from userspace */ +if (!rtdm_read_user_ok (fd, msg->msg_name, +sizeof (struct sockaddr_can )) || +rtdm_copy_from_user (fd, &scan_buf, msg->msg_name, +sizeof (struct sockaddr_can ))) +return -EFAULT ; + + scan = &scan_buf; + } + +/* Check address family */ +if (scan->can_family !=AF_CAN ) +return -EINVAL ; + + ifindex = scan->can_ifindex; + } + + dev =rtcan_dev_get_by_index (ifindex); +if (!dev) +return -ENXIO ; + +if (rtdm_fd_is_user (fd)) { + +/* Copy IO vector from userspace */ +if (!rtdm_rw_user_ok (fd, msg->msg_iov, +sizeof (struct iovec )) || +rtdm_copy_from_user (fd, &iov_buf, msg->msg_iov, +sizeof (struct iovec ))) { + ret = -EFAULT ; + goto finally; + } + + iov = &iov_buf; + } + + n = msg->msg_iovlen; +while (i < n) { +if (iov->iov_len <sizeof (can_frame_t)) { + ret = -EMSGSIZE ; + goto finally; + } + + frame = (can_frame_t *)iov->iov_base; + +if (rtdm_fd_is_user (fd)) { +/* Copy CAN frame from userspace */ +if (!rtdm_read_user_ok (fd, iov->iov_base,sizeof (can_frame_t)) || +rtdm_copy_from_user (fd, &frame_buf, iov->iov_base, +sizeof (can_frame_t))) { + ret = -EFAULT ; + goto finally; + } + + frame = &frame_buf; + } + + iov->iov_base +=sizeof (can_frame_t); + iov->iov_len -=sizeof (can_frame_t); + + ret =__rtcan_raw_sendmsg (dev, sock, frame, timeout); +if (ret <0 ) + goto finally; + + sent += ret; + } + +/* copy it back to userspace if necessary */ +if (rtdm_fd_is_user (fd)) { +if (rtdm_copy_to_user (fd, msg->msg_iov, iov,sizeof (struct iovec ))) { + ret = -EFAULT ; + goto finally; + } + } + +finally: +rtcan_dev_dereference (dev); + +if (sent >0 ) +return sent; + +return ret; +}static struct rtdm_driver rtcan_driver = { .profile_info = RTDM_PROFILE_INFO(rtcan,
Signature · 1 line
2.17.1
PATCH v3 3/7 drivers/can: add CAN_ERR_CRTL_ACTIVE info status
In reply to Dario BinacchiTo be used in case of recovered to error active state.
---
(no changes since v1)
include/rtdm/uapi/can.h | 1 + 1 file changed, 1 insertion(+)
include/rtdm/uapi/can.h +1 -0
@@ -837,6 +837,7 @@ struct can_ifreq {#define CAN_ERR_CRTL_TX_WARNING 0x08/**< reached warning level for TX errors */ #define CAN_ERR_CRTL_RX_PASSIVE 0x10/**< reached passive level for RX errors */ #define CAN_ERR_CRTL_TX_PASSIVE 0x20/**< reached passive level for TX errors */ +#define CAN_ERR_CRTL_ACTIVE 0x40/**< recovered to error active state */ /** @} */ /*!
Signature · 1 line
2.17.1
PATCH v3 4/7 drivers/can: add len field to can frame structures
In reply to Dario BinacchiAs mentioned in Linux, can_dlc is a misleading name that suggests a code instead of a length. Adding the len field can_dlc becomes deprecated too.
---
(no changes since v1)
include/rtdm/uapi/can.h | 5 ++++- kernel/drivers/can/rtcan_socket.h | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-)
include/rtdm/uapi/can.h +4 -1
@@ -318,7 +318,10 @@ typedef struct can_frame {can_id_t can_id;/** Size of the payload in bytes */ -uint8_t can_dlc; +union { +uint8_t can_dlc; +uint8_t len; + };/** Payload data bytes */ uint8_t data[8] __attribute__ ((aligned(8)));
kernel/drivers/can/rtcan_socket.h +4 -1
@@ -76,7 +76,10 @@ struct rtcan_rb_frame {/* DLC (between 0 and 15) and mark if frame has got a timestamp. The * existence of a timestamp is indicated by the RTCAN_HAS_TIMESTAMP * bit. */ -unsigned char can_dlc; +union { +unsigned char can_dlc; +unsigned char len; + };/* Data bytes */ uint8_t data[8 ];
Signature · 1 line
2.17.1
PATCH v3 5/7 drivers/can: add a minimal support to ethtool API
In reply to Dario BinacchiLike in the Linux kernel, the API allows to get/set device controller parameters.
For now it only supports:
- ETHTOOL_GDRVINFO: get general driver and device information
- ETHTOOL_GRINGPARAM: get RX/TX ring parameters
It allows the userspace to know the number of messages managed by the controller and how many of them are used for reception/transmission. This information allows you to know the maximum number of messages that sendmsg() can transmit without returning a full FIFO error.
Application programs are expected to use the new API directly via IOCTL, since, unlike the Linux Kernel, there is currently no userspace application like ethtool in Xenomai.
---
(no changes since v2)
Changes in v2:
- Expand the commit message to better describe the added API.
kernel/drivers/can/Makefile | 2 +- kernel/drivers/can/rtcan_dev.h | 4 +- kernel/drivers/can/rtcan_ethtool.c | 75 ++++++++++++++++++++++++++++++ kernel/drivers/can/rtcan_ethtool.h | 24 ++++++++++ kernel/drivers/can/rtcan_raw_dev.c | 20 ++++++++ 5 files changed, 123 insertions(+), 2 deletions(-) create mode 100644 kernel/drivers/can/rtcan_ethtool.c create mode 100644 kernel/drivers/can/rtcan_ethtool.h
kernel/drivers/can/Makefile +1 -1
@@ -5,6 +5,6 @@ obj-$(CONFIG_XENO_DRIVERS_CAN) += xeno_can.o mscan/ sja1000/ peak_canfd/ obj-$(CONFIG_XENO_DRIVERS_CAN_FLEXCAN) += xeno_can_flexcan.o obj-$(CONFIG_XENO_DRIVERS_CAN_VIRT) += xeno_can_virt.o -xeno_can-y := rtcan_dev.o rtcan_socket.o rtcan_module.o rtcan_raw.o rtcan_raw_dev.o rtcan_raw_filter.o +xeno_can-y := rtcan_dev.o rtcan_socket.o rtcan_module.o rtcan_raw.o rtcan_raw_dev.o rtcan_raw_filter.o rtcan_ethtool.o xeno_can_virt-y := rtcan_virt.o xeno_can_flexcan-y := rtcan_flexcan.o
kernel/drivers/can/rtcan_dev.h +3 -1
@@ -34,7 +34,7 @@#include <linux/semaphore.h> #include "rtcan_list.h" - +#include "rtcan_ethtool.h" /* Number of MSCAN devices the driver can handle */ #define RTCAN_MAX_DEVICES CONFIG_XENO_DRIVERS_CAN_MAX_DEVICES
@@ -137,6 +137,8 @@ struct rtcan_device {void (*do_enable_bus_err)(struct rtcan_device *dev);#endif +const struct rtcan_ethtool_ops *ethtool_ops; +/* Reception list head. This list contains all filters which have been * registered via a bind call. */ struct rtcan_recv *recv_list;
kernel/drivers/can/rtcan_ethtool.c new file +75 -0
75 lines not on this page · raw message
kernel/drivers/can/rtcan_ethtool.h new file +24 -0
@@ -0,0 +1,24 @@ +#ifndef __RTCAN_ETHTOOL_H_ +#define __RTCAN_ETHTOOL_H_ + +#ifdef __KERNEL__ + +#include <linux/ethtool.h> + +struct rtcan_device ; + +struct rtcan_ethtool_ops { +int (*begin)(struct rtcan_device *dev); +int (*complete)(struct rtcan_device *dev); +void (*get_drvinfo)(struct rtcan_device *dev, +struct ethtool_drvinfo *info); +void (*get_ringparam)(struct rtcan_device *dev, +struct ethtool_ringparam *ring); +}; + +int rtcan_ethtool (struct rtdm_fd *fd,struct rtcan_device *dev, +struct ifreq *ifr); + +#endif /* __KERNEL__ */ + +#endif /* __RTCAN_ETHTOOL_H_ */
kernel/drivers/can/rtcan_raw_dev.c +20 -0
@@ -354,6 +354,7 @@ static inline int rtcan_raw_ioctl_dev_set(struct rtcan_device *dev,int rtcan_raw_ioctl_dev (struct rtdm_fd *fd,int request,void *arg) {struct can_ifreq *ifr; +struct ifreq *ifreq;int ret =0 , get =0 ;union {/*
@@ -414,7 +415,26 @@ int rtcan_raw_ioctl_dev(struct rtdm_fd *fd, int request, void *arg)rtcan_dev_dereference (dev); }break ; +case SIOCETHTOOL : +if (rtdm_fd_is_user (fd)) { +/* Copy struct can_ifreq from userspace */ +if (!rtdm_read_user_ok (fd, arg,sizeof (*ifreq)) || +rtdm_copy_from_user (fd, &ifr_buf, arg,sizeof (*ifreq))) +return -EFAULT ; + + ifreq = &ifr_buf.ifr_legacy; + }else { + ifreq = (struct ifreq *)arg; + } +/* Get interface index and data */ + dev =rtcan_dev_get_by_name (ifreq->ifr_name); +if (dev ==NULL ) +return -ENODEV ; + + ret =rtcan_ethtool (fd, dev, ifreq); +rtcan_dev_dereference (dev); +break ;default : ret = -EOPNOTSUPP ;break ;
Signature · 1 line
2.17.1
PATCH v3 6/7 drivers/can: fix updating of tx_count statistics
In reply to Dario BinacchiAs in the Linux kernel, the counter is updated only after the message has been really transmitted.
---
(no changes since v1)
kernel/drivers/can/mscan/rtcan_mscan.c | 1 + kernel/drivers/can/rtcan_flexcan.c | 1 + kernel/drivers/can/rtcan_raw.c | 1 - kernel/drivers/can/rtcan_virt.c | 1 + kernel/drivers/can/sja1000/rtcan_sja1000.c | 1 + 5 files changed, 4 insertions(+), 1 deletion(-)
kernel/drivers/can/mscan/rtcan_mscan.c +1 -0
@@ -217,6 +217,7 @@ static int rtcan_mscan_interrupt(rtdm_irq_t *irq_handle)out_8 (®s->cantier,0 );/* Wake up a sender */ rtdm_sem_up (&dev->tx_sem); + dev->tx_count++;if (rtcan_loopback_pending (dev)) {
kernel/drivers/can/rtcan_flexcan.c +1 -0
@@ -897,6 +897,7 @@ static int flexcan_irq(rtdm_irq_t *irq_handle) &priv->tx_mb->can_ctrl);flexcan_write (FLEXCAN_IFLAG_MB (priv->tx_mb_idx), ®s->iflag1);rtdm_sem_up (&dev->tx_sem); + dev->tx_count++;if (rtcan_loopback_pending (dev))rtcan_loopback (dev); handled =RTDM_IRQ_HANDLED ;
kernel/drivers/can/rtcan_raw.c +0 -1
@@ -844,7 +844,6 @@ static ssize_t __rtcan_raw_sendmsg(struct rtcan_device *dev, struct rtcan_socket goto send_out2; } - dev->tx_count++; ret = dev->hard_start_xmit (dev, frame);/* Return number of bytes sent upon successful completion */
kernel/drivers/can/rtcan_virt.c +1 -0
@@ -56,6 +56,7 @@ static int rtcan_virt_start_xmit(struct rtcan_device *tx_dev,/* we can transmit immediately again */ rtdm_sem_up (&tx_dev->tx_sem); + tx_dev->tx_count++; skb.rb_frame_size =EMPTY_RB_FRAME_SIZE ;
kernel/drivers/can/sja1000/rtcan_sja1000.c +1 -0
@@ -326,6 +326,7 @@ static int rtcan_sja_interrupt(rtdm_irq_t *irq_handle)if (irq_source &SJA_IR_TI ) {/* Wake up a sender */ rtdm_sem_up (&dev->tx_sem); + dev->tx_count++;if (rtcan_loopback_pending (dev)) {
Signature · 1 line
2.17.1
PATCH v3 7/7 drivers/can: add support for Bosch C_CAN controller
In reply to Dario BinacchiBosch C_CAN controller is a full-CAN implementation which is compliant to CAN protocol version 2.0 part A and B.
Starting from the RTDM porting [1] by Stephen Battazzo, Michael applied some fixes for proper driver operation. Then I ported the commits from Linux kernel version 5.12 and finally I added support for 64 message objects [2] and improved the FIFO management [2] to get the best possible RX/TX throughput. Features [2] and [3] led to the creation of patches applied to the Linux kernel too.
The patch was tested on a custom board mounting an AM335x SOC.
PCI support has not been developed.
[1] http://xenomai.org/pipermail/xenomai/2015-July/034690.html
[2] 132f2d45fb23 ("can: c_can: add support to 64 message objects")
[3] 387da6bc7a82 ("can: c_can: cache frames to operate as a true FIFO")
---
Changes in v3:
- Add virtual CAN testsuite
Changes in v2:
- Drop 'default n' Kconfig
- Enable the driver for Xenomai CI builds
- Drop commented code
- Drop power managemet (pm) code
.gitlab-ci.yml | 2 + kernel/drivers/can/Kconfig | 1 + kernel/drivers/can/Makefile | 2 +- kernel/drivers/can/README | 1 + kernel/drivers/can/c_can/Kconfig | 15 + kernel/drivers/can/c_can/Makefile | 8 + kernel/drivers/can/c_can/rtcan_c_can.c | 1298 +++++++++++++++++ kernel/drivers/can/c_can/rtcan_c_can.h | 255 ++++ .../drivers/can/c_can/rtcan_c_can_ethtool.c | 47 + .../drivers/can/c_can/rtcan_c_can_platform.c | 461 ++++++ 10 files changed, 2089 insertions(+), 1 deletion(-) create mode 100644 kernel/drivers/can/c_can/Kconfig create mode 100644 kernel/drivers/can/c_can/Makefile create mode 100644 kernel/drivers/can/c_can/rtcan_c_can.c create mode 100644 kernel/drivers/can/c_can/rtcan_c_can.h create mode 100644 kernel/drivers/can/c_can/rtcan_c_can_ethtool.c create mode 100644 kernel/drivers/can/c_can/rtcan_c_can_platform.c
.gitlab-ci.yml +2 -0
@@ -118,6 +118,8 @@ variables: - ./scripts/config -e XENO_DRIVERS_CAN_SJA1000_ESD_PCI - ./scripts/config -e XENO_DRIVERS_CAN_SJA1000_PEAK_DNG - ./scripts/config -e XENO_DRIVERS_CAN_PEAK_CANFD + - ./scripts/config -e XENO_DRIVERS_CAN_C_CAN + - ./scripts/config -e XENO_DRIVERS_CAN_C_CAN_PLATFORM - ./scripts/config -m XENO_DRIVERS_NET - ./scripts/config -e XENO_DRIVERS_RTNET_CHECKED - ./scripts/config -e XENO_DRIVERS_NET_ETH_P_ALL
kernel/drivers/can/Kconfig +1 -0
@@ -85,6 +85,7 @@ config XENO_DRIVERS_CAN_FLEXCAN Say Y here if you want to support for Freescale FlexCAN. +source "drivers/xenomai/can/c_can/Kconfig" source "drivers/xenomai/can/mscan/Kconfig" source "drivers/xenomai/can/peak_canfd/Kconfig" source "drivers/xenomai/can/sja1000/Kconfig"
kernel/drivers/can/Makefile +1 -1
@@ -1,7 +1,7 @@ ccflags-y += -I$(srctree)/drivers/xenomai/can -obj-$(CONFIG_XENO_DRIVERS_CAN) += xeno_can.o mscan/ sja1000/ peak_canfd/ +obj-$(CONFIG_XENO_DRIVERS_CAN) += xeno_can.o mscan/ sja1000/ peak_canfd/ c_can/ obj-$(CONFIG_XENO_DRIVERS_CAN_FLEXCAN) += xeno_can_flexcan.o obj-$(CONFIG_XENO_DRIVERS_CAN_VIRT) += xeno_can_virt.o
kernel/drivers/can/README +1 -0
@@ -20,6 +20,7 @@ devices: SJA1000 PEAK parallel port Dongle SJA1000 IXXAT PCI card MSCAN for MPC5200 boards + C_CAN/D_CAN for AM335x/AM437x Sitara processors and DRA7 SOC Utilities for RT-Socket-CAN are available in "src/utils/can".
kernel/drivers/can/c_can/Kconfig new file +15 -0
@@ -0,0 +1,15 @@ +config XENO_DRIVERS_CAN_C_CAN + depends on XENO_DRIVERS_CAN && OF + tristate "Bosch C-CAN based chips" + +config XENO_DRIVERS_CAN_C_CAN_PLATFORM + depends on XENO_DRIVERS_CAN_C_CAN + tristate "Generic Platform Bus based controller" + help + + This driver adds support for the C_CAN/D_CAN chips connected + to the "platform bus" (Linux abstraction for directly to the + processor attached devices) which can be found on various + boards from ST Microelectronics (http://www.st.com) like the + SPEAr1310 and SPEAr320 evaluation boards & TI (www.ti.com) + boards like am335x, dm814x, dm813x and dm811x.
kernel/drivers/can/c_can/Makefile new file +8 -0
@@ -0,0 +1,8 @@ + +ccflags-y += -Idrivers/xenomai/can -Idrivers/xenomai/can/c_can + +obj-$(CONFIG_XENO_DRIVERS_CAN_C_CAN) += xeno_can_c_can.o +obj-$(CONFIG_XENO_DRIVERS_CAN_C_CAN_PLATFORM) += xeno_can_c_can_platform.o + +xeno_can_c_can-y := rtcan_c_can.o rtcan_c_can_ethtool.o +xeno_can_c_can_platform-y := rtcan_c_can_platform.o
kernel/drivers/can/c_can/rtcan_c_can.c new file +1298 -0
1,298 lines not on this page · raw message
kernel/drivers/can/c_can/rtcan_c_can.h new file +255 -0
255 lines not on this page · raw message
kernel/drivers/can/c_can/rtcan_c_can_ethtool.c new file +47 -0
47 lines not on this page · raw message
kernel/drivers/can/c_can/rtcan_c_can_platform.c new file +461 -0
461 lines not on this page · raw message
Signature · 1 line
2.17.1