Add support for CAN FD to broadcast manager (CAN_BCM)
Subsystems (4)
Oliver Hartkopp
maintainerv5 cover Add support for CAN FD to broadcast manager (CAN_BCM)
This series adds the capability for the CAN broadcast manager to handle CAN FD frames analogue to the CAN frames. It allows sending as well as all known data filtering functions (including multiplex filtering).
Changes in v2:
Introduce a helper variable cfsiz to prevent multiple CFSIZ(op) operations in bcm_rx_handler() (patch 4/5).
Changes in v3:
Introduce a helper variable cfsiz into struct bcm_op to minimize CFSIZ(op) operations (patch 4/5).
Fix documentation table of contents and code example (patch 5/5)
Changes in v4:
fixed more style issues remarked by checkpatch.pl (patch 1/5) Use CFSIZ macro in bcm_sendmsg() for TX_SEND too (patch 4/5)
Changes in v5:
Rename function GET_U64() to get_u64() and update version date (patch 4/5)
Oliver Hartkopp (5):
can: bcm: fix indention and other minor style issues
can: bcm: use CAN frame instead of can_frame in comments
can: bcm: unify bcm_msg_head handling and prepare function parameters
can: bcm: add support for CAN FD frames
can: bcm: add documentation for CAN FD support
Documentation/networking/can.txt | 25 +++- include/uapi/linux/can/bcm.h | 1 + net/can/bcm.c | 309 +++++++++++++++++++++++---------------- 3 files changed, 204 insertions(+), 131 deletions(-)
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v5 1/5 can: bcm: fix indention and other minor style issues
--- net/can/bcm.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-)
net/can/bcm.c +12 -14
@@ -184,42 +184,40 @@ static int bcm_proc_show(struct seq_file *m, void *v)continue ;seq_printf (m,"rx_op: %03X %-5s " , - op->can_id,bcm_proc_getifname (ifname, op->ifindex)); + op->can_id,bcm_proc_getifname (ifname, op->ifindex));seq_printf (m,"[%u]%c " , op->nframes, - (op->flags &RX_CHECK_DLC )?'d' :' ' ); + (op->flags &RX_CHECK_DLC ) ?'d' :' ' );if (op->kt_ival1.tv64)seq_printf (m,"timeo=%lld " , - (long long ) -ktime_to_us (op->kt_ival1)); + (long long )ktime_to_us (op->kt_ival1));if (op->kt_ival2.tv64)seq_printf (m,"thr=%lld " , - (long long ) -ktime_to_us (op->kt_ival2)); + (long long )ktime_to_us (op->kt_ival2));seq_printf (m,"# recv %ld (%ld) => reduction: " , - op->frames_filtered, op->frames_abs); + op->frames_filtered, op->frames_abs); reduction =100 - (op->frames_filtered *100 ) / op->frames_abs;seq_printf (m,"%s%ld%%\n" , - (reduction ==100 )?"near " :"" , reduction); + (reduction ==100 ) ?"near " :"" , reduction); }list_for_each_entry (op, &bo->tx_ops, list) {seq_printf (m,"tx_op: %03X %s [%u] " , - op->can_id, -bcm_proc_getifname (ifname, op->ifindex), - op->nframes); + op->can_id, +bcm_proc_getifname (ifname, op->ifindex), + op->nframes);if (op->kt_ival1.tv64)seq_printf (m,"t1=%lld " , - (long long )ktime_to_us (op->kt_ival1)); + (long long )ktime_to_us (op->kt_ival1));if (op->kt_ival2.tv64)seq_printf (m,"t2=%lld " , - (long long )ktime_to_us (op->kt_ival2)); + (long long )ktime_to_us (op->kt_ival2));seq_printf (m,"# sent %ld\n" , op->frames_abs); }
@@ -282,7 +280,7 @@ static void bcm_can_tx(struct bcm_op *op)/* reached last frame? */ if (op->currframe >= op->nframes) op->currframe =0 ; - out: +out:dev_put (dev); }
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v5 2/5 can: bcm: use CAN frame instead of can_frame in comments
In reply to Oliver Hartkoppcan_frame is the name of the struct can_frame which is not meant in the corrected comments.
--- net/can/bcm.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-)
net/can/bcm.c +16 -16
@@ -84,7 +84,7 @@ MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR ("Oliver Hartkopp <[email protected]>" );MODULE_ALIAS ("can-proto-2" ); -/* easy access to can_frame payload */ +/* easy access to CAN frame payload */ static inline u64 GET_U64 (const struct can_frame *cp) {return *(u64 *)cp->data;
@@ -305,13 +305,13 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head,memcpy (skb_put (skb,sizeof (*head)), head,sizeof (*head));if (head->nframes) { -/* can_frames starting here */ +/* CAN frames starting here */ firstframe = (struct can_frame *)skb_tail_pointer (skb);memcpy (skb_put (skb, datalen), frames, datalen);/* -* the BCM uses the can_dlc-element of the can_frame +* the BCM uses the can_dlc-element of the CAN frame * structure for internal purposes. This is only * relevant for updates that are generated by the * BCM, where nframes is 1
@@ -492,7 +492,7 @@ static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index,return ; } -/* do a real check in can_frame data section */ +/* do a real check in CAN frame data section */ if ((GET_U64 (&op->frames[index]) &GET_U64 (rxdata)) != (GET_U64 (&op->frames[index]) &GET_U64 (&op->last_frames[index]))) {
@@ -501,7 +501,7 @@ static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index, }if (op->flags &RX_CHECK_DLC ) { -/* do a real check in can_frame dlc */ +/* do a real check in CAN frame dlc */ if (rxdata->can_dlc != (op->last_frames[index].can_dlc &BCM_CAN_DLC_MASK )) { bcm_rx_update_and_send(op, &op->last_frames[index],
@@ -554,7 +554,7 @@ static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer)/* if user wants to be informed, when cyclic CAN-Messages come back */ if ((op->flags &RX_ANNOUNCE_RESUME ) && op->last_frames) { -/* clear received can_frames to indicate 'nothing received' */ +/* clear received CAN frames to indicate 'nothing received' */ memset (op->last_frames,0 , op->nframes *CFSIZ ); }
@@ -840,7 +840,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,if (!ifindex)return -ENODEV ; -/* check nframes boundaries - we need at least one can_frame */ +/* check nframes boundaries - we need at least one CAN frame */ if (msg_head->nframes <1 || msg_head->nframes >MAX_NFRAMES )return -EINVAL ;
@@ -851,14 +851,14 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,/* update existing BCM operation */ /* -* Do we need more space for the can_frames than currently +* Do we need more space for the CAN frames than currently * allocated? -> This is a _really_ unusual use-case and * therefore (complexity / locking) it is not supported. */ if (msg_head->nframes > op->nframes)return -E2BIG ; -/* update can_frames content */ +/* update CAN frames content */ for (i =0 ; i < msg_head->nframes; i++) { err =memcpy_from_msg ((u8 *)&op->frames[i], msg,CFSIZ );
@@ -883,7 +883,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, op->can_id = msg_head->can_id; -/* create array for can_frames and copy the data */ +/* create array for CAN frames and copy the data */ if (msg_head->nframes >1 ) { op->frames =kmalloc (msg_head->nframes *CFSIZ ,GFP_KERNEL );
@@ -966,7 +966,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,if (op->flags &STARTTIMER ) {hrtimer_cancel (&op->timer); -/* spec: send can_frame when starting timer */ +/* spec: send CAN frame when starting timer */ op->flags |=TX_ANNOUNCE ; }
@@ -1015,7 +1015,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,/* update existing BCM operation */ /* -* Do we need more space for the can_frames than currently +* Do we need more space for the CAN frames than currently * allocated? -> This is a _really_ unusual use-case and * therefore (complexity / locking) it is not supported. */
@@ -1023,7 +1023,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,return -E2BIG ;if (msg_head->nframes) { -/* update can_frames content */ +/* update CAN frames content */ err =memcpy_from_msg ((u8 *)op->frames, msg, msg_head->nframes *CFSIZ );if (err <0 )
@@ -1048,7 +1048,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, op->nframes = msg_head->nframes;if (msg_head->nframes >1 ) { -/* create array for can_frames and copy the data */ +/* create array for CAN frames and copy the data */ op->frames =kmalloc (msg_head->nframes *CFSIZ ,GFP_KERNEL );if (!op->frames) {
@@ -1056,7 +1056,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,return -ENOMEM ; } -/* create and init array for received can_frames */ +/* create and init array for received CAN frames */ op->last_frames =kzalloc (msg_head->nframes *CFSIZ ,GFP_KERNEL );if (!op->last_frames) {
@@ -1327,7 +1327,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)break ;case TX_SEND : -/* we need exactly one can_frame behind the msg head */ +/* we need exactly one CAN frame behind the msg head */ if ((msg_head.nframes !=1 ) || (size !=CFSIZ +MHSIZ )) ret = -EINVAL ;else
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v5 3/5 can: bcm: unify bcm_msg_head handling and prepare function parameters
In reply to Oliver Hartkopp--- net/can/bcm.c | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-)
net/can/bcm.c +29 -25
@@ -693,13 +693,13 @@ rx_starttimer:/* * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements */ -static struct bcm_op *bcm_find_op (struct list_head *ops,canid_t can_id, -int ifindex) +static struct bcm_op *bcm_find_op (struct list_head *ops, +struct bcm_msg_head *mh,int ifindex) {struct bcm_op *op;list_for_each_entry (op, ops, list) { -if ((op->can_id == can_id) && (op->ifindex == ifindex)) +if ((op->can_id == mh->can_id) && (op->ifindex == ifindex))return op; }
@@ -742,12 +742,13 @@ static void bcm_rx_unreg(struct net_device *dev, struct bcm_op *op)/* * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops) */ -static int bcm_delete_rx_op (struct list_head *ops,canid_t can_id,int ifindex) +static int bcm_delete_rx_op (struct list_head *ops,struct bcm_msg_head *mh, +int ifindex) {struct bcm_op *op, *n;list_for_each_entry_safe (op, n, ops, list) { -if ((op->can_id == can_id) && (op->ifindex == ifindex)) { +if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) {/* * Don't care if we're bound or not (due to netdev
@@ -787,12 +788,13 @@ static int bcm_delete_rx_op(struct list_head *ops, canid_t can_id, int ifindex)/* * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops) */ -static int bcm_delete_tx_op (struct list_head *ops,canid_t can_id,int ifindex) +static int bcm_delete_tx_op (struct list_head *ops,struct bcm_msg_head *mh, +int ifindex) {struct bcm_op *op, *n;list_for_each_entry_safe (op, n, ops, list) { -if ((op->can_id == can_id) && (op->ifindex == ifindex)) { +if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) {list_del (&op->list);bcm_remove_op (op);return 1 ;/* done */
@@ -808,7 +810,7 @@ static int bcm_delete_tx_op(struct list_head *ops, canid_t can_id, int ifindex)static int bcm_read_op (struct list_head *ops,struct bcm_msg_head *msg_head,int ifindex) { -struct bcm_op *op =bcm_find_op (ops, msg_head->can_id, ifindex); +struct bcm_op *op =bcm_find_op (ops, msg_head, ifindex);if (!op)return -EINVAL ;
@@ -845,8 +847,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,return -EINVAL ;/* check the given can_id */ - op =bcm_find_op (&bo->tx_ops, msg_head->can_id, ifindex); - + op =bcm_find_op (&bo->tx_ops, msg_head, ifindex);if (op) {/* update existing BCM operation */
@@ -1010,7 +1011,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,return -EINVAL ;/* check the given can_id */ - op =bcm_find_op (&bo->rx_ops, msg_head->can_id, ifindex); + op =bcm_find_op (&bo->rx_ops, msg_head, ifindex);if (op) {/* update existing BCM operation */
@@ -1192,7 +1193,8 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg,/* * bcm_tx_send - send a single CAN frame to the CAN interface (for bcm_sendmsg) */ -static int bcm_tx_send (struct msghdr *msg,int ifindex,struct sock *sk) +static int bcm_tx_send (struct msghdr *msg,int ifindex,struct sock *sk, +int cfsiz) {struct sk_buff *skb;struct net_device *dev;
@@ -1202,13 +1204,13 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)if (!ifindex)return -ENODEV ; - skb =alloc_skb (CFSIZ +sizeof (struct can_skb_priv ),GFP_KERNEL ); + skb =alloc_skb (cfsiz +sizeof (struct can_skb_priv ),GFP_KERNEL );if (!skb)return -ENOMEM ;can_skb_reserve (skb); - err =memcpy_from_msg (skb_put (skb,CFSIZ ), msg,CFSIZ ); + err =memcpy_from_msg (skb_put (skb, cfsiz), msg, cfsiz);if (err <0 ) {kfree_skb (skb);return err;
@@ -1230,7 +1232,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)if (err)return err; -return CFSIZ +MHSIZ ; +return cfsiz +MHSIZ ; }/*
@@ -1248,7 +1250,15 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)return -ENOTCONN ;/* check for valid message length from userspace */ -if (size <MHSIZ || (size -MHSIZ ) %CFSIZ ) +if (size <MHSIZ ) +return -EINVAL ; + +/* read message head information */ + ret =memcpy_from_msg ((u8 *)&msg_head, msg,MHSIZ ); +if (ret <0 ) +return ret; + +if ((size -MHSIZ ) %CFSIZ )return -EINVAL ;/* check for alternative ifindex for this bcm_op */
@@ -1282,12 +1292,6 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) } } -/* read message head information */ - - ret =memcpy_from_msg ((u8 *)&msg_head, msg,MHSIZ ); -if (ret <0 ) -return ret; -lock_sock (sk);switch (msg_head.opcode) {
@@ -1301,14 +1305,14 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)break ;case TX_DELETE : -if (bcm_delete_tx_op (&bo->tx_ops, msg_head.can_id, ifindex)) +if (bcm_delete_tx_op (&bo->tx_ops, &msg_head, ifindex)) ret =MHSIZ ;else ret = -EINVAL ;break ;case RX_DELETE : -if (bcm_delete_rx_op (&bo->rx_ops, msg_head.can_id, ifindex)) +if (bcm_delete_rx_op (&bo->rx_ops, &msg_head, ifindex)) ret =MHSIZ ;else ret = -EINVAL ;
@@ -1331,7 +1335,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)if ((msg_head.nframes !=1 ) || (size !=CFSIZ +MHSIZ )) ret = -EINVAL ;else - ret =bcm_tx_send (msg, ifindex, sk); + ret =bcm_tx_send (msg, ifindex, sk,CFSIZ );break ;default :
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v5 4/5 can: bcm: add support for CAN FD frames
In reply to Oliver HartkoppThe programming API of the CAN_BCM depends on struct can_frame which is given as array directly behind the bcm_msg_head structure. To follow this schema for the CAN FD frames a new flag 'CAN_FD_FRAME' in the bcm_msg_head flags indicates that the concatenated CAN frame structures behind the bcm_msg_head are defined as struct canfd_frame.
This patch adds the support to handle CAN and CAN FD frames on a per BCM-op base. Main changes:
- generally use struct canfd_frames instead if struct can_frames
- use canfd_frame.flags instead of can_frame.can_dlc for private BCM flags
- make all CAN frame sizes depending on the new CAN_FD_FRAME flags
- separate between CAN and CAN FD when sending/receiving frames
Due to the dependence of the CAN_FD_FRAME flag the former binary interface for classic CAN frames remains stable.
--- include/uapi/linux/can/bcm.h | 1 + net/can/bcm.c | 223 ++++++++++++++++++++++++++----------------- 2 files changed, 136 insertions(+), 88 deletions(-)
include/uapi/linux/can/bcm.h +1 -0
@@ -99,5 +99,6 @@ enum {#define RX_ANNOUNCE_RESUME 0x0100#define TX_RESET_MULTI_IDX 0x0200#define RX_RTR_FRAME 0x0400 +#define CAN_FD_FRAME 0x0800#endif /* !_UAPI_CAN_BCM_H */
net/can/bcm.c +135 -88
532 lines not on this page · raw message
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v5 5/5 can: bcm: add documentation for CAN FD support
In reply to Oliver Hartkopp--- Documentation/networking/can.txt | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
Documentation/networking/can.txt +24 -1
@@ -31,6 +31,7 @@ This file contains 4.2.4 Broadcast Manager message sequence transmission 4.2.5 Broadcast Manager receive filter timers 4.2.6 Broadcast Manager multiplex message receive filter + 4.2.7 Broadcast Manager CAN FD support 4.3 connected transport protocols (SOCK_SEQPACKET) 4.4 unconnected transport protocols (SOCK_DGRAM)
@@ -799,7 +800,7 @@ solution for a couple of reasons: } mytxmsg; (..) - mytxmsg.nframes = 4; + mytxmsg.msg_head.nframes = 4; (..) write(s, &mytxmsg, sizeof(mytxmsg));
@@ -852,6 +853,28 @@ solution for a couple of reasons: write(s, &msg, sizeof(msg)); + 4.2.7 Broadcast Manager CAN FD support + + The programming API of the CAN_BCM depends on struct can_frame which is + given as array directly behind the bcm_msg_head structure. To follow this + schema for the CAN FD frames a new flag 'CAN_FD_FRAME' in the bcm_msg_head + flags indicates that the concatenated CAN frame structures behind the + bcm_msg_head are defined as struct canfd_frame. + + struct { + struct bcm_msg_head msg_head; + struct canfd_frame frame[5]; + } msg; + + msg.msg_head.opcode = RX_SETUP; + msg.msg_head.can_id = 0x42; + msg.msg_head.flags = CAN_FD_FRAME; + msg.msg_head.nframes = 5; + (..) + + When using CAN FD frames for multiplex filtering the MUX mask is still + expected in the first 64 bit of the struct canfd_frame data section. + 4.3 connected transport protocols (SOCK_SEQPACKET) 4.4 unconnected transport protocols (SOCK_DGRAM)
Signature · 1 line
2.8.1
Quoted 27 lines · Oliver Hartkopp
This series adds the capability for the CAN broadcast manager to handle CAN FD frames analogue to the CAN frames. It allows sending as well as all known data filtering functions (including multiplex filtering).
Changes in v2:
Introduce a helper variable cfsiz to prevent multiple CFSIZ(op) operations inbcm_rx_handler()(patch 4/5).Changes in v3:
Introduce a helper variable cfsiz into structbcm_opto minimize CFSIZ(op) operations (patch 4/5).
Fix documentation table of contents and code example (patch 5/5)Changes in v4:
fixed more style issues remarked by checkpatch.pl (patch 1/5) Use CFSIZ macro inbcm_sendmsg()forTX_SENDtoo (patch 4/5)Changes in v5:
Rename functionGET_U64()toget_u64()and update version date (patch 4/5)Oliver Hartkopp (5):
can: bcm: fix indention and other minor style issues
can: bcm: use CAN frame instead ofcan_framein comments
can: bcm: unifybcm_msg_headhandling and prepare function parameters
can: bcm: add support for CAN FD frames
can: bcm: add documentation for CAN FD support
Quoted 4 lines
Documentation/networking/can.txt | 25 +++- include/uapi/linux/can/bcm.h | 1 + net/can/bcm.c | 309 +++++++++++++++++++++++---------------- 3 files changed, 204 insertions(+), 131 deletions(-)
applied to can-next.
tnx,
Marc
Signature · 4 lines
Pengutronix e.K. | Marc Kleine-Budde | Industrial Linux Solutions | Phone: +49-231-2826-924 | Vertretung West/Dortmund | Fax: +49-5121-206917-5555 | Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |