Add support for CAN FD to broadcast manager (CAN_BCM)
Subsystems (4)
Oliver Hartkopp
maintainerv2 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).
Oliver Hartkopp (5):
can: bcm: fix indention style
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 | 22 +++ include/uapi/linux/can/bcm.h | 1 + net/can/bcm.c | 313 +++++++++++++++++++++++---------------- 3 files changed, 206 insertions(+), 130 deletions(-)
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v2 1/5 can: bcm: fix indention style
--- net/can/bcm.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
net/can/bcm.c +14 -14
@@ -184,42 +184,42 @@ 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 +282,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 v2 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
@@ -695,13 +695,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; }
@@ -744,12 +744,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
@@ -789,12 +790,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 */
@@ -810,7 +812,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 ;
@@ -847,8 +849,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 */
@@ -1012,7 +1013,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 */
@@ -1194,7 +1195,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;
@@ -1204,13 +1206,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;
@@ -1232,7 +1234,7 @@ static int bcm_tx_send(struct msghdr *msg, int ifindex, struct sock *sk)if (err)return err; -return CFSIZ +MHSIZ ; +return cfsiz +MHSIZ ; }/*
@@ -1250,7 +1252,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 */
@@ -1284,12 +1294,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) {
@@ -1303,14 +1307,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 ;
@@ -1333,7 +1337,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 v2 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 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;
@@ -307,13 +307,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
@@ -494,7 +494,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]))) {
@@ -503,7 +503,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],
@@ -556,7 +556,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 ); }
@@ -842,7 +842,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 ;
@@ -853,14 +853,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 );
@@ -885,7 +885,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 );
@@ -968,7 +968,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 ; }
@@ -1017,7 +1017,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. */
@@ -1025,7 +1025,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 )
@@ -1050,7 +1050,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) {
@@ -1058,7 +1058,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) {
@@ -1329,7 +1329,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 v2 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 | 229 ++++++++++++++++++++++++++----------------- 2 files changed, 140 insertions(+), 90 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 +139 -90
544 lines not on this page · raw message
Signature · 1 line
2.8.1
Oliver Hartkopp
maintainerPATCH v2 5/5 can: bcm: add documentation for CAN FD support
In reply to Oliver Hartkopp--- Documentation/networking/can.txt | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
Documentation/networking/can.txt +22 -0
@@ -852,6 +852,28 @@ solution for a couple of reasons: write(s, &msg, sizeof(msg)); + 4.2.6 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
Oliver Hartkopp
maintainerRequest for testing - Re: [PATCH v2 0/5] Add support for CAN FD to broadcast manager (CAN_BCM)
In reply to Oliver HartkoppHi all,
this patch set enables CAN FD for the BCM.
I did some basic tests but I would appreciate if anyone could give it some additional testing.
At least it should not affect the original function with classic CAN frames as it aims to preserve the former binary interface ;-)
Feedback is welcome!
Best regards,
Oliver
Quoted 20 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).Oliver Hartkopp (5):
can: bcm: fix indention style
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 supportDocumentation/networking/can.txt | 22 +++ include/uapi/linux/can/bcm.h | 1 + net/can/bcm.c | 313 +++++++++++++++++++++++---------------- 3 files changed, 206 insertions(+), 130 deletions(-)