From: Oliver Hartkopp <socketcan@hartkopp.net>
To: linux-can@vger.kernel.org
Cc: Oliver Hartkopp <socketcan@hartkopp.net>
Subject: [RFC PATCH 5/5] can: raw: add CAN XL support
Date: Mon, 11 Jul 2022 20:34:26 +0200 [thread overview]
Message-ID: <20220711183426.96446-6-socketcan@hartkopp.net> (raw)
In-Reply-To: <20220711183426.96446-1-socketcan@hartkopp.net>
Enable CAN_RAW sockets to read and write CAN XL frames analogue to the
CAN FD extension (new CAN_RAW_XL_FRAMES sockopt).
A CAN XL network interface is capable to handle Classical CAN, CAN FD and
CAN XL frames. When CAN_RAW_XL_FRAMES is enabled, the CAN_RAW socket checks
whether the addressed CAN network interface is capable to handle the
provided CAN frame.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
---
include/uapi/linux/can/raw.h | 1 +
net/can/raw.c | 26 +++++++++++++++++++++++++-
2 files changed, 26 insertions(+), 1 deletion(-)
diff --git a/include/uapi/linux/can/raw.h b/include/uapi/linux/can/raw.h
index 3386aa81fdf2..ff12f525c37c 100644
--- a/include/uapi/linux/can/raw.h
+++ b/include/uapi/linux/can/raw.h
@@ -60,8 +60,9 @@ enum {
CAN_RAW_ERR_FILTER, /* set filter for error frames */
CAN_RAW_LOOPBACK, /* local loopback (default:on) */
CAN_RAW_RECV_OWN_MSGS, /* receive my own msgs (default:off) */
CAN_RAW_FD_FRAMES, /* allow CAN FD frames (default:off) */
CAN_RAW_JOIN_FILTERS, /* all filters must match to trigger */
+ CAN_RAW_XL_FRAMES, /* allow CAN XL frames (default:off) */
};
#endif /* !_UAPI_CAN_RAW_H */
diff --git a/net/can/raw.c b/net/can/raw.c
index d1bd9cc51ebe..c036de63fcfa 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -85,10 +85,11 @@ struct raw_sock {
int ifindex;
struct list_head notifier;
int loopback;
int recv_own_msgs;
int fd_frames;
+ int xl_frames;
int join_filters;
int count; /* number of active filters */
struct can_filter dfilter; /* default/single filter */
struct can_filter *filter; /* pointer to filter(s) */
can_err_mask_t err_mask;
@@ -344,10 +345,11 @@ static int raw_init(struct sock *sk)
/* set default loopback behaviour */
ro->loopback = 1;
ro->recv_own_msgs = 0;
ro->fd_frames = 0;
+ ro->xl_frames = 0;
ro->join_filters = 0;
/* alloc_percpu provides zero'ed memory */
ro->uniq = alloc_percpu(struct uniqframe);
if (unlikely(!ro->uniq))
@@ -667,10 +669,19 @@ static int raw_setsockopt(struct socket *sock, int level, int optname,
if (copy_from_sockptr(&ro->fd_frames, optval, optlen))
return -EFAULT;
break;
+ case CAN_RAW_XL_FRAMES:
+ if (optlen != sizeof(ro->xl_frames))
+ return -EINVAL;
+
+ if (copy_from_sockptr(&ro->xl_frames, optval, optlen))
+ return -EFAULT;
+
+ break;
+
case CAN_RAW_JOIN_FILTERS:
if (optlen != sizeof(ro->join_filters))
return -EINVAL;
if (copy_from_sockptr(&ro->join_filters, optval, optlen))
@@ -749,10 +760,16 @@ static int raw_getsockopt(struct socket *sock, int level, int optname,
if (len > sizeof(int))
len = sizeof(int);
val = &ro->fd_frames;
break;
+ case CAN_RAW_XL_FRAMES:
+ if (len > sizeof(int))
+ len = sizeof(int);
+ val = &ro->xl_frames;
+ break;
+
case CAN_RAW_JOIN_FILTERS:
if (len > sizeof(int))
len = sizeof(int);
val = &ro->join_filters;
break;
@@ -795,14 +812,21 @@ static int raw_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
dev = dev_get_by_index(sock_net(sk), ifindex);
if (!dev)
return -ENXIO;
err = -EINVAL;
- if (ro->fd_frames && dev->mtu == CANFD_MTU) {
+ if (ro->xl_frames && dev->mtu == CANXL_MTU) {
+ /* CAN XL, CAN FD and Classical CAN */
+ if (unlikely(size != CANXL_MTU && size != CANFD_MTU &&
+ size != CAN_MTU))
+ goto put_dev;
+ } else if (ro->fd_frames && dev->mtu == CANFD_MTU) {
+ /* CAN FD and Classical CAN */
if (unlikely(size != CANFD_MTU && size != CAN_MTU))
goto put_dev;
} else {
+ /* Classical CAN */
if (unlikely(size != CAN_MTU))
goto put_dev;
}
skb = sock_alloc_send_skb(sk, size + sizeof(struct can_skb_priv),
--
2.30.2
prev parent reply other threads:[~2022-07-11 18:34 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-11 18:34 [RFC PATCH 0/5] can: support CAN XL Oliver Hartkopp
2022-07-11 18:34 ` [RFC PATCH 1/5] can: canxl: introduce CAN XL data structure Oliver Hartkopp
2022-07-12 0:36 ` Vincent Mailhol
2022-07-12 7:55 ` Oliver Hartkopp
2022-07-12 8:40 ` Vincent Mailhol
2022-07-12 9:31 ` Oliver Hartkopp
2022-07-12 10:19 ` Vincent Mailhol
2022-07-12 12:30 ` Oliver Hartkopp
2022-07-12 14:31 ` Vincent Mailhol
2022-07-12 19:24 ` Oliver Hartkopp
2022-07-13 1:07 ` Vincent Mailhol
2022-07-13 20:02 ` Oliver Hartkopp
2022-07-14 1:23 ` Vincent Mailhol
2022-07-14 6:11 ` Oliver Hartkopp
2022-07-14 9:12 ` Vincent Mailhol
2022-07-14 10:10 ` Oliver Hartkopp
2022-07-11 18:34 ` [RFC PATCH 2/5] can: canxl: introduce ETH_P_CANXL ethernet protocol handling Oliver Hartkopp
2022-07-11 19:34 ` Marc Kleine-Budde
2022-07-11 19:41 ` Marc Kleine-Budde
2022-07-12 7:12 ` Oliver Hartkopp
2022-07-12 7:17 ` Marc Kleine-Budde
2022-07-12 8:02 ` Oliver Hartkopp
2022-07-12 8:10 ` Marc Kleine-Budde
2022-07-12 1:23 ` Vincent Mailhol
2022-07-12 20:20 ` Oliver Hartkopp
2022-07-12 23:58 ` Vincent Mailhol
2022-07-13 7:02 ` Marc Kleine-Budde
2022-07-13 7:15 ` Vincent Mailhol
2022-07-13 20:27 ` Oliver Hartkopp
2022-07-14 1:32 ` Vincent Mailhol
2022-07-11 18:34 ` [RFC PATCH 3/5] can: dev: add CAN XL support Oliver Hartkopp
2022-07-11 19:46 ` Marc Kleine-Budde
2022-07-12 7:08 ` Oliver Hartkopp
2022-07-11 18:34 ` [RFC PATCH 4/5] can: vcan: " Oliver Hartkopp
2022-07-11 18:34 ` Oliver Hartkopp [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220711183426.96446-6-socketcan@hartkopp.net \
--to=socketcan@hartkopp.net \
--cc=linux-can@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox