public inbox for linux-can@vger.kernel.org
 help / color / mirror / Atom feed
* [RFC] can: Introducing CANFD for af_can & can-raw
@ 2012-03-21  9:10 Kurt Van Dijck
       [not found] ` <E1SAIM4-0007a6-Sf@smtprelay03.ispgateway.de>
  0 siblings, 1 reply; 29+ messages in thread
From: Kurt Van Dijck @ 2012-03-21  9:10 UTC (permalink / raw)
  To: linux-can

Hi,

I thought a bit about the CANFD ideas from last ICC.

The patch below is a working prototype that extends
the frame format to 64 bytes. I explicitely did not
recompile userspace programs to see if current programs
still operate. candump & cansend do still work.
I did not try any other.

This is intended as a proof of concept that it is
possible to extend the ABI towards bigger CAN frames.

Next step could be to operate a vcan bus with bigger CAN frames.

Kurt
---
can: Introducing CANFD for af_can & can-raw

struct can_frame is expanded to contain 64byte.
This patch extends the ABI, while staying compatible
with the existing one.
This patch does not introduce CANFD for chip drivers.

Signed-off-by: Kurt Van Dijck <kurt.van.dijck@eia.be>

diff --git a/include/linux/can.h b/include/linux/can.h
index f4cd17c..ea73a89 100644
--- a/include/linux/can.h
+++ b/include/linux/can.h
@@ -55,7 +55,7 @@ typedef __u32 can_err_mask_t;
 struct can_frame {
 	canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
 	__u8    can_dlc; /* data length code: 0 .. 8 */
-	__u8    data[8] __attribute__((aligned(8)));
+	__u8    data[64] __attribute__((aligned(8)));
 };
 
 /* particular protocols of the protocol family PF_CAN */
diff --git a/include/linux/can/core.h b/include/linux/can/core.h
index 9716670..01f0923 100644
--- a/include/linux/can/core.h
+++ b/include/linux/can/core.h
@@ -89,4 +89,15 @@ extern void can_rx_unregister(struct net_device *dev, canid_t can_id,
 extern int can_send(struct sk_buff *skb, int loop);
 extern int can_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg);
 
+/**
+ * LEGACY CAN frame
+ * struct can20b_frame - basic CAN 2.0B frame structure
+ * differs only payload size from struct can_frame
+ */
+struct can20b_frame {
+	canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
+	__u8    can_dlc; /* data length code: 0 .. 8 */
+	__u8    data[8] __attribute__((aligned(8)));
+};
+
 #endif /* CAN_CORE_H */
diff --git a/net/can/af_can.c b/net/can/af_can.c
index 8cd9e2e..1ddc8bc 100644
--- a/net/can/af_can.c
+++ b/net/can/af_can.c
@@ -221,13 +221,22 @@ static int can_create(struct net *net, struct socket *sock, int protocol,
  *  -EPERM when trying to send on a non-CAN interface
  *  -EINVAL when the skb->data does not contain a valid CAN frame
  */
+#define CANFD_PADSIZE	(sizeof(struct can_frame) - sizeof(struct can20b_frame))
 int can_send(struct sk_buff *skb, int loop)
 {
 	struct sk_buff *newskb = NULL;
 	struct can_frame *cf = (struct can_frame *)skb->data;
 	int err;
 
-	if (skb->len != sizeof(struct can_frame) || cf->can_dlc > 8) {
+	if (skb->len == sizeof(struct can20b_frame))
+		/*
+		 * extend the skb to the new CAN frame format
+		 * fill with zero
+		 */
+		memset(skb_put(skb, CANFD_PADSIZE), 0, CANFD_PADSIZE);
+
+	if (skb->len != sizeof(struct can_frame) ||
+			(cf->can_dlc > sizeof(cf->data))) {
 		kfree_skb(skb);
 		return -EINVAL;
 	}
diff --git a/net/can/raw.c b/net/can/raw.c
index fbdd260..3471d22 100644
--- a/net/can/raw.c
+++ b/net/can/raw.c
@@ -662,7 +662,8 @@ static int raw_sendmsg(struct kiocb *iocb, struct socket *sock,
 	} else
 		ifindex = ro->ifindex;
 
-	if (size != sizeof(struct can_frame))
+	if ((size != sizeof(struct can_frame)) &&
+			(size != sizeof(struct can20b_frame)))
 		return -EINVAL;
 
 	dev = dev_get_by_index(&init_net, ifindex);

^ permalink raw reply related	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2012-03-23 11:01 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-21  9:10 [RFC] can: Introducing CANFD for af_can & can-raw Kurt Van Dijck
     [not found] ` <E1SAIM4-0007a6-Sf@smtprelay03.ispgateway.de>
2012-03-21 11:05   ` Kurt Van Dijck
2012-03-21 11:43     ` Marc Kleine-Budde
2012-03-21 12:08       ` Kurt Van Dijck
2012-03-21 12:32         ` Marc Kleine-Budde
2012-03-21 12:51           ` Kurt Van Dijck
2012-03-21 13:19             ` Marc Kleine-Budde
2012-03-21 13:21           ` Oliver Hartkopp
2012-03-21 13:53             ` Kurt Van Dijck
2012-03-21 14:49               ` Oliver Hartkopp
2012-03-21 15:26                 ` Oliver Hartkopp
2012-03-22  9:03                 ` Kurt Van Dijck
2012-03-21 14:56               ` Wolfgang Grandegger
2012-03-21 15:05                 ` Oliver Hartkopp
2012-03-22  9:24                   ` Kurt Van Dijck
2012-03-22  9:32                     ` Marc Kleine-Budde
2012-03-22  9:38                     ` Wolfgang Grandegger
2012-03-22 10:13                       ` Kurt Van Dijck
2012-03-23 11:01                         ` Wolfgang Grandegger
2012-03-22  9:57                   ` Kurt Van Dijck
2012-03-22 10:06                     ` Wolfgang Grandegger
2012-03-22 10:35                       ` Kurt Van Dijck
2012-03-22 11:00                         ` Wolfgang Grandegger
2012-03-22 12:25                           ` Oliver Hartkopp
2012-03-22 12:47                             ` Kurt Van Dijck
2012-03-21 13:29           ` Alexander Stein
2012-03-21 13:34             ` Kurt Van Dijck
2012-03-21 13:51             ` Marc Kleine-Budde
2012-03-21 15:47               ` Alexander Stein

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox