netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Marc Kleine-Budde <mkl@pengutronix.de>
To: netdev@vger.kernel.org
Cc: davem@davemloft.net, kuba@kernel.org, linux-can@vger.kernel.org,
	kernel@pengutronix.de, Oliver Hartkopp <socketcan@hartkopp.net>,
	Vincent Mailhol <mailhol.vincent@wanadoo.fr>,
	Marc Kleine-Budde <mkl@pengutronix.de>
Subject: [PATCH net-next 20/23] can: canxl: introduce CAN XL data structure
Date: Thu, 15 Sep 2022 10:20:10 +0200	[thread overview]
Message-ID: <20220915082013.369072-21-mkl@pengutronix.de> (raw)
In-Reply-To: <20220915082013.369072-1-mkl@pengutronix.de>

From: Oliver Hartkopp <socketcan@hartkopp.net>

This patch adds defines for data structures and length information for
CAN XL (CAN with eXtended data Length) which can transfer up to 2048
byte inside a single frame.

Notable changes from CAN FD:

- the 11 bit arbitration field is now named 'priority' instead of 'can_id'
  (there are no 29 bit identifiers nor RTR frames anymore)
- the data length needs a uint16 value to cover up to 2048 byte
  (the length element position is different to struct can[fd]_frame)
- new fields (SDT, AF) and a SEC bit have been introduced
- the virtual CAN interface identifier is not part if the CAN XL frame
  struct as this VCID value is stored in struct skbuff (analog to vlan id)

Acked-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Link: https://lore.kernel.org/all/20220912170725.120748-5-socketcan@hartkopp.net
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 include/uapi/linux/can.h | 51 ++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)

diff --git a/include/uapi/linux/can.h b/include/uapi/linux/can.h
index 7b23eeeb3273..dd645ea72306 100644
--- a/include/uapi/linux/can.h
+++ b/include/uapi/linux/can.h
@@ -48,6 +48,7 @@
 
 #include <linux/types.h>
 #include <linux/socket.h>
+#include <linux/stddef.h> /* for offsetof */
 
 /* controller area network (CAN) kernel definitions */
 
@@ -60,6 +61,7 @@
 #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
 #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
 #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
+#define CANXL_PRIO_MASK CAN_SFF_MASK /* 11 bit priority mask */
 
 /*
  * Controller Area Network Identifier structure
@@ -73,6 +75,7 @@ typedef __u32 canid_t;
 
 #define CAN_SFF_ID_BITS		11
 #define CAN_EFF_ID_BITS		29
+#define CANXL_PRIO_BITS		CAN_SFF_ID_BITS
 
 /*
  * Controller Area Network Error Message Frame Mask structure
@@ -91,6 +94,16 @@ typedef __u32 can_err_mask_t;
 #define CANFD_MAX_DLC 15
 #define CANFD_MAX_DLEN 64
 
+/*
+ * CAN XL payload length and DLC definitions according to ISO 11898-1
+ * CAN XL DLC ranges from 0 .. 2047 => data length from 1 .. 2048 byte
+ */
+#define CANXL_MIN_DLC 0
+#define CANXL_MAX_DLC 2047
+#define CANXL_MAX_DLC_MASK 0x07FF
+#define CANXL_MIN_DLEN 1
+#define CANXL_MAX_DLEN 2048
+
 /**
  * struct can_frame - Classical CAN frame structure (aka CAN 2.0B)
  * @can_id:   CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
@@ -166,8 +179,46 @@ struct canfd_frame {
 	__u8    data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
 };
 
+/*
+ * defined bits for canxl_frame.flags
+ *
+ * The canxl_frame.flags element contains two bits CANXL_XLF and CANXL_SEC
+ * and shares the relative position of the struct can[fd]_frame.len element.
+ * The CANXL_XLF bit ALWAYS needs to be set to indicate a valid CAN XL frame.
+ * As a side effect setting this bit intentionally breaks the length checks
+ * for Classical CAN and CAN FD frames.
+ *
+ * Undefined bits in canxl_frame.flags are reserved and shall be set to zero.
+ */
+#define CANXL_XLF 0x80 /* mandatory CAN XL frame flag (must always be set!) */
+#define CANXL_SEC 0x01 /* Simple Extended Content (security/segmentation) */
+
+/**
+ * struct canxl_frame - CAN with e'X'tended frame 'L'ength frame structure
+ * @prio:  11 bit arbitration priority with zero'ed CAN_*_FLAG flags
+ * @flags: additional flags for CAN XL
+ * @sdt:   SDU (service data unit) type
+ * @len:   frame payload length in byte (CANXL_MIN_DLEN .. CANXL_MAX_DLEN)
+ * @af:    acceptance field
+ * @data:  CAN XL frame payload (CANXL_MIN_DLEN .. CANXL_MAX_DLEN byte)
+ *
+ * @prio shares the same position as @can_id from struct can[fd]_frame.
+ */
+struct canxl_frame {
+	canid_t prio;  /* 11 bit priority for arbitration (canid_t) */
+	__u8    flags; /* additional flags for CAN XL */
+	__u8    sdt;   /* SDU (service data unit) type */
+	__u16   len;   /* frame payload length in byte */
+	__u32   af;    /* acceptance field */
+	__u8    data[CANXL_MAX_DLEN];
+};
+
 #define CAN_MTU		(sizeof(struct can_frame))
 #define CANFD_MTU	(sizeof(struct canfd_frame))
+#define CANXL_MTU	(sizeof(struct canxl_frame))
+#define CANXL_HDR_SIZE	(offsetof(struct canxl_frame, data))
+#define CANXL_MIN_MTU	(CANXL_HDR_SIZE + 64)
+#define CANXL_MAX_MTU	CANXL_MTU
 
 /* particular protocols of the protocol family PF_CAN */
 #define CAN_RAW		1 /* RAW sockets */
-- 
2.35.1



  parent reply	other threads:[~2022-09-15  8:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-09-15  8:19 [PATCH net-next 0/23] pull-request: can-next 2022-09-15 Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 01/23] can: rx-offload: can_rx_offload_init_queue(): fix typo Marc Kleine-Budde
2022-09-17 19:20   ` patchwork-bot+netdevbpf
2022-09-15  8:19 ` [PATCH net-next 02/23] can: flexcan: fix typo: FLEXCAN_QUIRK_SUPPPORT_* -> FLEXCAN_QUIRK_SUPPORT_* Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 03/23] can: rcar_canfd: Use dev_err_probe() to simplify code and better handle -EPROBE_DEFER Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 04/23] can: kvaser_usb: kvaser_usb_hydra: Use kzalloc for allocating only one element Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 05/23] dt-bindings: can: nxp,sja1000: Document RZ/N1 power-domains support Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 06/23] can: sja1000: Add support for RZ/N1 SJA1000 CAN Controller Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 07/23] can: sja1000: remove redundant variable ret Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 08/23] can: kvaser_pciefd: " Marc Kleine-Budde
2022-09-15  8:19 ` [PATCH net-next 09/23] can: gs_usb: use common spelling of GS_USB in macros Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 10/23] can: gs_usb: add RX and TX hardware timestamp support Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 11/23] can: etas_es58x: Replace zero-length array with DECLARE_FLEX_ARRAY() helper Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 12/23] dt-bindings: net: can: nxp,sja1000: drop ref from reg-io-width Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 13/23] docs: networking: device drivers: flexcan: fix invalid email Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 14/23] can: raw: process optimization in raw_init() Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 15/23] can: raw: use guard clause to optimize nesting in raw_rcv() Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 16/23] can: flexcan: Switch to use dev_err_probe() helper Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 17/23] can: skb: unify skb CAN frame identification helpers Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 18/23] can: skb: add skb CAN frame data length helpers Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 19/23] can: set CANFD_FDF flag in all CAN FD frame structures Marc Kleine-Budde
2022-09-15  8:20 ` Marc Kleine-Budde [this message]
2022-09-15  8:20 ` [PATCH net-next 21/23] can: canxl: update CAN infrastructure for CAN XL frames Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 22/23] can: dev: add CAN XL support to virtual CAN Marc Kleine-Budde
2022-09-15  8:20 ` [PATCH net-next 23/23] can: raw: add CAN XL support Marc Kleine-Budde

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=20220915082013.369072-21-mkl@pengutronix.de \
    --to=mkl@pengutronix.de \
    --cc=davem@davemloft.net \
    --cc=kernel@pengutronix.de \
    --cc=kuba@kernel.org \
    --cc=linux-can@vger.kernel.org \
    --cc=mailhol.vincent@wanadoo.fr \
    --cc=netdev@vger.kernel.org \
    --cc=socketcan@hartkopp.net \
    /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;
as well as URLs for NNTP newsgroup(s).