diff options
author | Oliver Hartkopp <socketcan@hartkopp.net> | 2016-06-17 09:35:27 -0400 |
---|---|---|
committer | Marc Kleine-Budde <mkl@pengutronix.de> | 2016-06-17 09:39:46 -0400 |
commit | 6f3b911d5f29b98752e5da86a295210c0c4f4e14 (patch) | |
tree | 385a3c2b38bbee79bbec91ed6d5969eb49021820 | |
parent | 2b5f5f5dc114219dcd848fb0ff344acb413c11ef (diff) |
can: bcm: add support for CAN FD frames
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.
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.
Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
-rw-r--r-- | include/uapi/linux/can/bcm.h | 1 | ||||
-rw-r--r-- | net/can/bcm.c | 223 |
2 files changed, 136 insertions, 88 deletions
diff --git a/include/uapi/linux/can/bcm.h b/include/uapi/linux/can/bcm.h index 7a291dc1ff15..cefb304414ba 100644 --- a/include/uapi/linux/can/bcm.h +++ b/include/uapi/linux/can/bcm.h | |||
@@ -99,5 +99,6 @@ enum { | |||
99 | #define RX_ANNOUNCE_RESUME 0x0100 | 99 | #define RX_ANNOUNCE_RESUME 0x0100 |
100 | #define TX_RESET_MULTI_IDX 0x0200 | 100 | #define TX_RESET_MULTI_IDX 0x0200 |
101 | #define RX_RTR_FRAME 0x0400 | 101 | #define RX_RTR_FRAME 0x0400 |
102 | #define CAN_FD_FRAME 0x0800 | ||
102 | 103 | ||
103 | #endif /* !_UAPI_CAN_BCM_H */ | 104 | #endif /* !_UAPI_CAN_BCM_H */ |
diff --git a/net/can/bcm.c b/net/can/bcm.c index f3bf3875313a..8e999ffdf28b 100644 --- a/net/can/bcm.c +++ b/net/can/bcm.c | |||
@@ -1,7 +1,7 @@ | |||
1 | /* | 1 | /* |
2 | * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content | 2 | * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content |
3 | * | 3 | * |
4 | * Copyright (c) 2002-2007 Volkswagen Group Electronic Research | 4 | * Copyright (c) 2002-2016 Volkswagen Group Electronic Research |
5 | * All rights reserved. | 5 | * All rights reserved. |
6 | * | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | 7 | * Redistribution and use in source and binary forms, with or without |
@@ -67,27 +67,31 @@ | |||
67 | */ | 67 | */ |
68 | #define MAX_NFRAMES 256 | 68 | #define MAX_NFRAMES 256 |
69 | 69 | ||
70 | /* use of last_frames[index].can_dlc */ | 70 | /* use of last_frames[index].flags */ |
71 | #define RX_RECV 0x40 /* received data for this element */ | 71 | #define RX_RECV 0x40 /* received data for this element */ |
72 | #define RX_THR 0x80 /* element not been sent due to throttle feature */ | 72 | #define RX_THR 0x80 /* element not been sent due to throttle feature */ |
73 | #define BCM_CAN_DLC_MASK 0x0F /* clean private flags in can_dlc by masking */ | 73 | #define BCM_CAN_FLAGS_MASK 0x3F /* to clean private flags after usage */ |
74 | 74 | ||
75 | /* get best masking value for can_rx_register() for a given single can_id */ | 75 | /* get best masking value for can_rx_register() for a given single can_id */ |
76 | #define REGMASK(id) ((id & CAN_EFF_FLAG) ? \ | 76 | #define REGMASK(id) ((id & CAN_EFF_FLAG) ? \ |
77 | (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \ | 77 | (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \ |
78 | (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)) | 78 | (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG)) |
79 | 79 | ||
80 | #define CAN_BCM_VERSION CAN_VERSION | 80 | #define CAN_BCM_VERSION "20160617" |
81 | 81 | ||
82 | MODULE_DESCRIPTION("PF_CAN broadcast manager protocol"); | 82 | MODULE_DESCRIPTION("PF_CAN broadcast manager protocol"); |
83 | MODULE_LICENSE("Dual BSD/GPL"); | 83 | MODULE_LICENSE("Dual BSD/GPL"); |
84 | MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>"); | 84 | MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>"); |
85 | MODULE_ALIAS("can-proto-2"); | 85 | MODULE_ALIAS("can-proto-2"); |
86 | 86 | ||
87 | /* easy access to CAN frame payload */ | 87 | /* |
88 | static inline u64 GET_U64(const struct can_frame *cp) | 88 | * easy access to the first 64 bit of can(fd)_frame payload. cp->data is |
89 | * 64 bit aligned so the offset has to be multiples of 8 which is ensured | ||
90 | * by the only callers in bcm_rx_cmp_to_index() bcm_rx_handler(). | ||
91 | */ | ||
92 | static inline u64 get_u64(const struct canfd_frame *cp, int offset) | ||
89 | { | 93 | { |
90 | return *(u64 *)cp->data; | 94 | return *(u64 *)(cp->data + offset); |
91 | } | 95 | } |
92 | 96 | ||
93 | struct bcm_op { | 97 | struct bcm_op { |
@@ -101,13 +105,14 @@ struct bcm_op { | |||
101 | struct tasklet_struct tsklet, thrtsklet; | 105 | struct tasklet_struct tsklet, thrtsklet; |
102 | ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg; | 106 | ktime_t rx_stamp, kt_ival1, kt_ival2, kt_lastmsg; |
103 | int rx_ifindex; | 107 | int rx_ifindex; |
108 | int cfsiz; | ||
104 | u32 count; | 109 | u32 count; |
105 | u32 nframes; | 110 | u32 nframes; |
106 | u32 currframe; | 111 | u32 currframe; |
107 | struct can_frame *frames; | 112 | struct canfd_frame *frames; |
108 | struct can_frame *last_frames; | 113 | struct canfd_frame *last_frames; |
109 | struct can_frame sframe; | 114 | struct canfd_frame sframe; |
110 | struct can_frame last_sframe; | 115 | struct canfd_frame last_sframe; |
111 | struct sock *sk; | 116 | struct sock *sk; |
112 | struct net_device *rx_reg_dev; | 117 | struct net_device *rx_reg_dev; |
113 | }; | 118 | }; |
@@ -136,7 +141,7 @@ static inline ktime_t bcm_timeval_to_ktime(struct bcm_timeval tv) | |||
136 | return ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC); | 141 | return ktime_set(tv.tv_sec, tv.tv_usec * NSEC_PER_USEC); |
137 | } | 142 | } |
138 | 143 | ||
139 | #define CFSIZ sizeof(struct can_frame) | 144 | #define CFSIZ(flags) ((flags & CAN_FD_FRAME) ? CANFD_MTU : CAN_MTU) |
140 | #define OPSIZ sizeof(struct bcm_op) | 145 | #define OPSIZ sizeof(struct bcm_op) |
141 | #define MHSIZ sizeof(struct bcm_msg_head) | 146 | #define MHSIZ sizeof(struct bcm_msg_head) |
142 | 147 | ||
@@ -183,10 +188,16 @@ static int bcm_proc_show(struct seq_file *m, void *v) | |||
183 | if (!op->frames_abs) | 188 | if (!op->frames_abs) |
184 | continue; | 189 | continue; |
185 | 190 | ||
186 | seq_printf(m, "rx_op: %03X %-5s ", | 191 | seq_printf(m, "rx_op: %03X %-5s ", op->can_id, |
187 | op->can_id, bcm_proc_getifname(ifname, op->ifindex)); | 192 | bcm_proc_getifname(ifname, op->ifindex)); |
188 | seq_printf(m, "[%u]%c ", op->nframes, | 193 | |
189 | (op->flags & RX_CHECK_DLC) ? 'd' : ' '); | 194 | if (op->flags & CAN_FD_FRAME) |
195 | seq_printf(m, "(%u)", op->nframes); | ||
196 | else | ||
197 | seq_printf(m, "[%u]", op->nframes); | ||
198 | |||
199 | seq_printf(m, "%c ", (op->flags & RX_CHECK_DLC) ? 'd' : ' '); | ||
200 | |||
190 | if (op->kt_ival1.tv64) | 201 | if (op->kt_ival1.tv64) |
191 | seq_printf(m, "timeo=%lld ", | 202 | seq_printf(m, "timeo=%lld ", |
192 | (long long)ktime_to_us(op->kt_ival1)); | 203 | (long long)ktime_to_us(op->kt_ival1)); |
@@ -206,10 +217,13 @@ static int bcm_proc_show(struct seq_file *m, void *v) | |||
206 | 217 | ||
207 | list_for_each_entry(op, &bo->tx_ops, list) { | 218 | list_for_each_entry(op, &bo->tx_ops, list) { |
208 | 219 | ||
209 | seq_printf(m, "tx_op: %03X %s [%u] ", | 220 | seq_printf(m, "tx_op: %03X %s ", op->can_id, |
210 | op->can_id, | 221 | bcm_proc_getifname(ifname, op->ifindex)); |
211 | bcm_proc_getifname(ifname, op->ifindex), | 222 | |
212 | op->nframes); | 223 | if (op->flags & CAN_FD_FRAME) |
224 | seq_printf(m, "(%u) ", op->nframes); | ||
225 | else | ||
226 | seq_printf(m, "[%u] ", op->nframes); | ||
213 | 227 | ||
214 | if (op->kt_ival1.tv64) | 228 | if (op->kt_ival1.tv64) |
215 | seq_printf(m, "t1=%lld ", | 229 | seq_printf(m, "t1=%lld ", |
@@ -246,7 +260,7 @@ static void bcm_can_tx(struct bcm_op *op) | |||
246 | { | 260 | { |
247 | struct sk_buff *skb; | 261 | struct sk_buff *skb; |
248 | struct net_device *dev; | 262 | struct net_device *dev; |
249 | struct can_frame *cf = &op->frames[op->currframe]; | 263 | struct canfd_frame *cf = op->frames + op->cfsiz * op->currframe; |
250 | 264 | ||
251 | /* no target device? => exit */ | 265 | /* no target device? => exit */ |
252 | if (!op->ifindex) | 266 | if (!op->ifindex) |
@@ -258,7 +272,7 @@ static void bcm_can_tx(struct bcm_op *op) | |||
258 | return; | 272 | return; |
259 | } | 273 | } |
260 | 274 | ||
261 | skb = alloc_skb(CFSIZ + sizeof(struct can_skb_priv), gfp_any()); | 275 | skb = alloc_skb(op->cfsiz + sizeof(struct can_skb_priv), gfp_any()); |
262 | if (!skb) | 276 | if (!skb) |
263 | goto out; | 277 | goto out; |
264 | 278 | ||
@@ -266,7 +280,7 @@ static void bcm_can_tx(struct bcm_op *op) | |||
266 | can_skb_prv(skb)->ifindex = dev->ifindex; | 280 | can_skb_prv(skb)->ifindex = dev->ifindex; |
267 | can_skb_prv(skb)->skbcnt = 0; | 281 | can_skb_prv(skb)->skbcnt = 0; |
268 | 282 | ||
269 | memcpy(skb_put(skb, CFSIZ), cf, CFSIZ); | 283 | memcpy(skb_put(skb, op->cfsiz), cf, op->cfsiz); |
270 | 284 | ||
271 | /* send with loopback */ | 285 | /* send with loopback */ |
272 | skb->dev = dev; | 286 | skb->dev = dev; |
@@ -289,13 +303,13 @@ out: | |||
289 | * (consisting of bcm_msg_head + x CAN frames) | 303 | * (consisting of bcm_msg_head + x CAN frames) |
290 | */ | 304 | */ |
291 | static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head, | 305 | static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head, |
292 | struct can_frame *frames, int has_timestamp) | 306 | struct canfd_frame *frames, int has_timestamp) |
293 | { | 307 | { |
294 | struct sk_buff *skb; | 308 | struct sk_buff *skb; |
295 | struct can_frame *firstframe; | 309 | struct canfd_frame *firstframe; |
296 | struct sockaddr_can *addr; | 310 | struct sockaddr_can *addr; |
297 | struct sock *sk = op->sk; | 311 | struct sock *sk = op->sk; |
298 | unsigned int datalen = head->nframes * CFSIZ; | 312 | unsigned int datalen = head->nframes * op->cfsiz; |
299 | int err; | 313 | int err; |
300 | 314 | ||
301 | skb = alloc_skb(sizeof(*head) + datalen, gfp_any()); | 315 | skb = alloc_skb(sizeof(*head) + datalen, gfp_any()); |
@@ -306,18 +320,18 @@ static void bcm_send_to_user(struct bcm_op *op, struct bcm_msg_head *head, | |||
306 | 320 | ||
307 | if (head->nframes) { | 321 | if (head->nframes) { |
308 | /* CAN frames starting here */ | 322 | /* CAN frames starting here */ |
309 | firstframe = (struct can_frame *)skb_tail_pointer(skb); | 323 | firstframe = (struct canfd_frame *)skb_tail_pointer(skb); |
310 | 324 | ||
311 | memcpy(skb_put(skb, datalen), frames, datalen); | 325 | memcpy(skb_put(skb, datalen), frames, datalen); |
312 | 326 | ||
313 | /* | 327 | /* |
314 | * the BCM uses the can_dlc-element of the CAN frame | 328 | * the BCM uses the flags-element of the canfd_frame |
315 | * structure for internal purposes. This is only | 329 | * structure for internal purposes. This is only |
316 | * relevant for updates that are generated by the | 330 | * relevant for updates that are generated by the |
317 | * BCM, where nframes is 1 | 331 | * BCM, where nframes is 1 |
318 | */ | 332 | */ |
319 | if (head->nframes == 1) | 333 | if (head->nframes == 1) |
320 | firstframe->can_dlc &= BCM_CAN_DLC_MASK; | 334 | firstframe->flags &= BCM_CAN_FLAGS_MASK; |
321 | } | 335 | } |
322 | 336 | ||
323 | if (has_timestamp) { | 337 | if (has_timestamp) { |
@@ -404,7 +418,7 @@ static enum hrtimer_restart bcm_tx_timeout_handler(struct hrtimer *hrtimer) | |||
404 | /* | 418 | /* |
405 | * bcm_rx_changed - create a RX_CHANGED notification due to changed content | 419 | * bcm_rx_changed - create a RX_CHANGED notification due to changed content |
406 | */ | 420 | */ |
407 | static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data) | 421 | static void bcm_rx_changed(struct bcm_op *op, struct canfd_frame *data) |
408 | { | 422 | { |
409 | struct bcm_msg_head head; | 423 | struct bcm_msg_head head; |
410 | 424 | ||
@@ -416,7 +430,7 @@ static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data) | |||
416 | op->frames_filtered = op->frames_abs = 0; | 430 | op->frames_filtered = op->frames_abs = 0; |
417 | 431 | ||
418 | /* this element is not throttled anymore */ | 432 | /* this element is not throttled anymore */ |
419 | data->can_dlc &= (BCM_CAN_DLC_MASK|RX_RECV); | 433 | data->flags &= (BCM_CAN_FLAGS_MASK|RX_RECV); |
420 | 434 | ||
421 | head.opcode = RX_CHANGED; | 435 | head.opcode = RX_CHANGED; |
422 | head.flags = op->flags; | 436 | head.flags = op->flags; |
@@ -435,13 +449,13 @@ static void bcm_rx_changed(struct bcm_op *op, struct can_frame *data) | |||
435 | * 2. send a notification to the user (if possible) | 449 | * 2. send a notification to the user (if possible) |
436 | */ | 450 | */ |
437 | static void bcm_rx_update_and_send(struct bcm_op *op, | 451 | static void bcm_rx_update_and_send(struct bcm_op *op, |
438 | struct can_frame *lastdata, | 452 | struct canfd_frame *lastdata, |
439 | const struct can_frame *rxdata) | 453 | const struct canfd_frame *rxdata) |
440 | { | 454 | { |
441 | memcpy(lastdata, rxdata, CFSIZ); | 455 | memcpy(lastdata, rxdata, op->cfsiz); |
442 | 456 | ||
443 | /* mark as used and throttled by default */ | 457 | /* mark as used and throttled by default */ |
444 | lastdata->can_dlc |= (RX_RECV|RX_THR); | 458 | lastdata->flags |= (RX_RECV|RX_THR); |
445 | 459 | ||
446 | /* throttling mode inactive ? */ | 460 | /* throttling mode inactive ? */ |
447 | if (!op->kt_ival2.tv64) { | 461 | if (!op->kt_ival2.tv64) { |
@@ -479,33 +493,36 @@ rx_changed_settime: | |||
479 | * received data stored in op->last_frames[] | 493 | * received data stored in op->last_frames[] |
480 | */ | 494 | */ |
481 | static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index, | 495 | static void bcm_rx_cmp_to_index(struct bcm_op *op, unsigned int index, |
482 | const struct can_frame *rxdata) | 496 | const struct canfd_frame *rxdata) |
483 | { | 497 | { |
498 | struct canfd_frame *cf = op->frames + op->cfsiz * index; | ||
499 | struct canfd_frame *lcf = op->last_frames + op->cfsiz * index; | ||
500 | int i; | ||
501 | |||
484 | /* | 502 | /* |
485 | * no one uses the MSBs of can_dlc for comparison, | 503 | * no one uses the MSBs of flags for comparison, |
486 | * so we use it here to detect the first time of reception | 504 | * so we use it here to detect the first time of reception |
487 | */ | 505 | */ |
488 | 506 | ||
489 | if (!(op->last_frames[index].can_dlc & RX_RECV)) { | 507 | if (!(lcf->flags & RX_RECV)) { |
490 | /* received data for the first time => send update to user */ | 508 | /* received data for the first time => send update to user */ |
491 | bcm_rx_update_and_send(op, &op->last_frames[index], rxdata); | 509 | bcm_rx_update_and_send(op, lcf, rxdata); |
492 | return; | 510 | return; |
493 | } | 511 | } |
494 | 512 | ||
495 | /* do a real check in CAN frame data section */ | 513 | /* do a real check in CAN frame data section */ |
496 | 514 | for (i = 0; i < rxdata->len; i += 8) { | |
497 | if ((GET_U64(&op->frames[index]) & GET_U64(rxdata)) != | 515 | if ((get_u64(cf, i) & get_u64(rxdata, i)) != |
498 | (GET_U64(&op->frames[index]) & GET_U64(&op->last_frames[index]))) { | 516 | (get_u64(cf, i) & get_u64(lcf, i))) { |
499 | bcm_rx_update_and_send(op, &op->last_frames[index], rxdata); | 517 | bcm_rx_update_and_send(op, lcf, rxdata); |
500 | return; | 518 | return; |
519 | } | ||
501 | } | 520 | } |
502 | 521 | ||
503 | if (op->flags & RX_CHECK_DLC) { | 522 | if (op->flags & RX_CHECK_DLC) { |
504 | /* do a real check in CAN frame dlc */ | 523 | /* do a real check in CAN frame length */ |
505 | if (rxdata->can_dlc != (op->last_frames[index].can_dlc & | 524 | if (rxdata->len != lcf->len) { |
506 | BCM_CAN_DLC_MASK)) { | 525 | bcm_rx_update_and_send(op, lcf, rxdata); |
507 | bcm_rx_update_and_send(op, &op->last_frames[index], | ||
508 | rxdata); | ||
509 | return; | 526 | return; |
510 | } | 527 | } |
511 | } | 528 | } |
@@ -555,7 +572,7 @@ static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer) | |||
555 | /* if user wants to be informed, when cyclic CAN-Messages come back */ | 572 | /* if user wants to be informed, when cyclic CAN-Messages come back */ |
556 | if ((op->flags & RX_ANNOUNCE_RESUME) && op->last_frames) { | 573 | if ((op->flags & RX_ANNOUNCE_RESUME) && op->last_frames) { |
557 | /* clear received CAN frames to indicate 'nothing received' */ | 574 | /* clear received CAN frames to indicate 'nothing received' */ |
558 | memset(op->last_frames, 0, op->nframes * CFSIZ); | 575 | memset(op->last_frames, 0, op->nframes * op->cfsiz); |
559 | } | 576 | } |
560 | 577 | ||
561 | return HRTIMER_NORESTART; | 578 | return HRTIMER_NORESTART; |
@@ -567,9 +584,11 @@ static enum hrtimer_restart bcm_rx_timeout_handler(struct hrtimer *hrtimer) | |||
567 | static inline int bcm_rx_do_flush(struct bcm_op *op, int update, | 584 | static inline int bcm_rx_do_flush(struct bcm_op *op, int update, |
568 | unsigned int index) | 585 | unsigned int index) |
569 | { | 586 | { |
570 | if ((op->last_frames) && (op->last_frames[index].can_dlc & RX_THR)) { | 587 | struct canfd_frame *lcf = op->last_frames + op->cfsiz * index; |
588 | |||
589 | if ((op->last_frames) && (lcf->flags & RX_THR)) { | ||
571 | if (update) | 590 | if (update) |
572 | bcm_rx_changed(op, &op->last_frames[index]); | 591 | bcm_rx_changed(op, lcf); |
573 | return 1; | 592 | return 1; |
574 | } | 593 | } |
575 | return 0; | 594 | return 0; |
@@ -634,15 +653,19 @@ static enum hrtimer_restart bcm_rx_thr_handler(struct hrtimer *hrtimer) | |||
634 | static void bcm_rx_handler(struct sk_buff *skb, void *data) | 653 | static void bcm_rx_handler(struct sk_buff *skb, void *data) |
635 | { | 654 | { |
636 | struct bcm_op *op = (struct bcm_op *)data; | 655 | struct bcm_op *op = (struct bcm_op *)data; |
637 | const struct can_frame *rxframe = (struct can_frame *)skb->data; | 656 | const struct canfd_frame *rxframe = (struct canfd_frame *)skb->data; |
638 | unsigned int i; | 657 | unsigned int i; |
639 | 658 | ||
640 | /* disable timeout */ | ||
641 | hrtimer_cancel(&op->timer); | ||
642 | |||
643 | if (op->can_id != rxframe->can_id) | 659 | if (op->can_id != rxframe->can_id) |
644 | return; | 660 | return; |
645 | 661 | ||
662 | /* make sure to handle the correct frame type (CAN / CAN FD) */ | ||
663 | if (skb->len != op->cfsiz) | ||
664 | return; | ||
665 | |||
666 | /* disable timeout */ | ||
667 | hrtimer_cancel(&op->timer); | ||
668 | |||
646 | /* save rx timestamp */ | 669 | /* save rx timestamp */ |
647 | op->rx_stamp = skb->tstamp; | 670 | op->rx_stamp = skb->tstamp; |
648 | /* save originator for recvfrom() */ | 671 | /* save originator for recvfrom() */ |
@@ -673,13 +696,14 @@ static void bcm_rx_handler(struct sk_buff *skb, void *data) | |||
673 | * multiplex compare | 696 | * multiplex compare |
674 | * | 697 | * |
675 | * find the first multiplex mask that fits. | 698 | * find the first multiplex mask that fits. |
676 | * Remark: The MUX-mask is stored in index 0 | 699 | * Remark: The MUX-mask is stored in index 0 - but only the |
700 | * first 64 bits of the frame data[] are relevant (CAN FD) | ||
677 | */ | 701 | */ |
678 | 702 | ||
679 | for (i = 1; i < op->nframes; i++) { | 703 | for (i = 1; i < op->nframes; i++) { |
680 | if ((GET_U64(&op->frames[0]) & GET_U64(rxframe)) == | 704 | if ((get_u64(op->frames, 0) & get_u64(rxframe, 0)) == |
681 | (GET_U64(&op->frames[0]) & | 705 | (get_u64(op->frames, 0) & |
682 | GET_U64(&op->frames[i]))) { | 706 | get_u64(op->frames + op->cfsiz * i, 0))) { |
683 | bcm_rx_cmp_to_index(op, i, rxframe); | 707 | bcm_rx_cmp_to_index(op, i, rxframe); |
684 | break; | 708 | break; |
685 | } | 709 | } |
@@ -699,7 +723,8 @@ static struct bcm_op *bcm_find_op(struct list_head *ops, | |||
699 | struct bcm_op *op; | 723 | struct bcm_op *op; |
700 | 724 | ||
701 | list_for_each_entry(op, ops, list) { | 725 | list_for_each_entry(op, ops, list) { |
702 | if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) | 726 | if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) && |
727 | (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) | ||
703 | return op; | 728 | return op; |
704 | } | 729 | } |
705 | 730 | ||
@@ -748,7 +773,8 @@ static int bcm_delete_rx_op(struct list_head *ops, struct bcm_msg_head *mh, | |||
748 | struct bcm_op *op, *n; | 773 | struct bcm_op *op, *n; |
749 | 774 | ||
750 | list_for_each_entry_safe(op, n, ops, list) { | 775 | list_for_each_entry_safe(op, n, ops, list) { |
751 | if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) { | 776 | if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) && |
777 | (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) { | ||
752 | 778 | ||
753 | /* | 779 | /* |
754 | * Don't care if we're bound or not (due to netdev | 780 | * Don't care if we're bound or not (due to netdev |
@@ -794,7 +820,8 @@ static int bcm_delete_tx_op(struct list_head *ops, struct bcm_msg_head *mh, | |||
794 | struct bcm_op *op, *n; | 820 | struct bcm_op *op, *n; |
795 | 821 | ||
796 | list_for_each_entry_safe(op, n, ops, list) { | 822 | list_for_each_entry_safe(op, n, ops, list) { |
797 | if ((op->can_id == mh->can_id) && (op->ifindex == ifindex)) { | 823 | if ((op->can_id == mh->can_id) && (op->ifindex == ifindex) && |
824 | (op->flags & CAN_FD_FRAME) == (mh->flags & CAN_FD_FRAME)) { | ||
798 | list_del(&op->list); | 825 | list_del(&op->list); |
799 | bcm_remove_op(op); | 826 | bcm_remove_op(op); |
800 | return 1; /* done */ | 827 | return 1; /* done */ |
@@ -835,6 +862,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
835 | { | 862 | { |
836 | struct bcm_sock *bo = bcm_sk(sk); | 863 | struct bcm_sock *bo = bcm_sk(sk); |
837 | struct bcm_op *op; | 864 | struct bcm_op *op; |
865 | struct canfd_frame *cf; | ||
838 | unsigned int i; | 866 | unsigned int i; |
839 | int err; | 867 | int err; |
840 | 868 | ||
@@ -861,19 +889,27 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
861 | 889 | ||
862 | /* update CAN frames content */ | 890 | /* update CAN frames content */ |
863 | for (i = 0; i < msg_head->nframes; i++) { | 891 | for (i = 0; i < msg_head->nframes; i++) { |
864 | err = memcpy_from_msg((u8 *)&op->frames[i], msg, CFSIZ); | ||
865 | 892 | ||
866 | if (op->frames[i].can_dlc > 8) | 893 | cf = op->frames + op->cfsiz * i; |
867 | err = -EINVAL; | 894 | err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz); |
895 | |||
896 | if (op->flags & CAN_FD_FRAME) { | ||
897 | if (cf->len > 64) | ||
898 | err = -EINVAL; | ||
899 | } else { | ||
900 | if (cf->len > 8) | ||
901 | err = -EINVAL; | ||
902 | } | ||
868 | 903 | ||
869 | if (err < 0) | 904 | if (err < 0) |
870 | return err; | 905 | return err; |
871 | 906 | ||
872 | if (msg_head->flags & TX_CP_CAN_ID) { | 907 | if (msg_head->flags & TX_CP_CAN_ID) { |
873 | /* copy can_id into frame */ | 908 | /* copy can_id into frame */ |
874 | op->frames[i].can_id = msg_head->can_id; | 909 | cf->can_id = msg_head->can_id; |
875 | } | 910 | } |
876 | } | 911 | } |
912 | op->flags = msg_head->flags; | ||
877 | 913 | ||
878 | } else { | 914 | } else { |
879 | /* insert new BCM operation for the given can_id */ | 915 | /* insert new BCM operation for the given can_id */ |
@@ -882,11 +918,13 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
882 | if (!op) | 918 | if (!op) |
883 | return -ENOMEM; | 919 | return -ENOMEM; |
884 | 920 | ||
885 | op->can_id = msg_head->can_id; | 921 | op->can_id = msg_head->can_id; |
922 | op->cfsiz = CFSIZ(msg_head->flags); | ||
923 | op->flags = msg_head->flags; | ||
886 | 924 | ||
887 | /* create array for CAN frames and copy the data */ | 925 | /* create array for CAN frames and copy the data */ |
888 | if (msg_head->nframes > 1) { | 926 | if (msg_head->nframes > 1) { |
889 | op->frames = kmalloc(msg_head->nframes * CFSIZ, | 927 | op->frames = kmalloc(msg_head->nframes * op->cfsiz, |
890 | GFP_KERNEL); | 928 | GFP_KERNEL); |
891 | if (!op->frames) { | 929 | if (!op->frames) { |
892 | kfree(op); | 930 | kfree(op); |
@@ -896,10 +934,17 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
896 | op->frames = &op->sframe; | 934 | op->frames = &op->sframe; |
897 | 935 | ||
898 | for (i = 0; i < msg_head->nframes; i++) { | 936 | for (i = 0; i < msg_head->nframes; i++) { |
899 | err = memcpy_from_msg((u8 *)&op->frames[i], msg, CFSIZ); | ||
900 | 937 | ||
901 | if (op->frames[i].can_dlc > 8) | 938 | cf = op->frames + op->cfsiz * i; |
902 | err = -EINVAL; | 939 | err = memcpy_from_msg((u8 *)cf, msg, op->cfsiz); |
940 | |||
941 | if (op->flags & CAN_FD_FRAME) { | ||
942 | if (cf->len > 64) | ||
943 | err = -EINVAL; | ||
944 | } else { | ||
945 | if (cf->len > 8) | ||
946 | err = -EINVAL; | ||
947 | } | ||
903 | 948 | ||
904 | if (err < 0) { | 949 | if (err < 0) { |
905 | if (op->frames != &op->sframe) | 950 | if (op->frames != &op->sframe) |
@@ -910,7 +955,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
910 | 955 | ||
911 | if (msg_head->flags & TX_CP_CAN_ID) { | 956 | if (msg_head->flags & TX_CP_CAN_ID) { |
912 | /* copy can_id into frame */ | 957 | /* copy can_id into frame */ |
913 | op->frames[i].can_id = msg_head->can_id; | 958 | cf->can_id = msg_head->can_id; |
914 | } | 959 | } |
915 | } | 960 | } |
916 | 961 | ||
@@ -945,8 +990,6 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
945 | 990 | ||
946 | /* check flags */ | 991 | /* check flags */ |
947 | 992 | ||
948 | op->flags = msg_head->flags; | ||
949 | |||
950 | if (op->flags & TX_RESET_MULTI_IDX) { | 993 | if (op->flags & TX_RESET_MULTI_IDX) { |
951 | /* start multiple frame transmission with index 0 */ | 994 | /* start multiple frame transmission with index 0 */ |
952 | op->currframe = 0; | 995 | op->currframe = 0; |
@@ -980,7 +1023,7 @@ static int bcm_tx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
980 | if (op->flags & STARTTIMER) | 1023 | if (op->flags & STARTTIMER) |
981 | bcm_tx_start_timer(op); | 1024 | bcm_tx_start_timer(op); |
982 | 1025 | ||
983 | return msg_head->nframes * CFSIZ + MHSIZ; | 1026 | return msg_head->nframes * op->cfsiz + MHSIZ; |
984 | } | 1027 | } |
985 | 1028 | ||
986 | /* | 1029 | /* |
@@ -1026,15 +1069,16 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1026 | if (msg_head->nframes) { | 1069 | if (msg_head->nframes) { |
1027 | /* update CAN frames content */ | 1070 | /* update CAN frames content */ |
1028 | err = memcpy_from_msg((u8 *)op->frames, msg, | 1071 | err = memcpy_from_msg((u8 *)op->frames, msg, |
1029 | msg_head->nframes * CFSIZ); | 1072 | msg_head->nframes * op->cfsiz); |
1030 | if (err < 0) | 1073 | if (err < 0) |
1031 | return err; | 1074 | return err; |
1032 | 1075 | ||
1033 | /* clear last_frames to indicate 'nothing received' */ | 1076 | /* clear last_frames to indicate 'nothing received' */ |
1034 | memset(op->last_frames, 0, msg_head->nframes * CFSIZ); | 1077 | memset(op->last_frames, 0, msg_head->nframes * op->cfsiz); |
1035 | } | 1078 | } |
1036 | 1079 | ||
1037 | op->nframes = msg_head->nframes; | 1080 | op->nframes = msg_head->nframes; |
1081 | op->flags = msg_head->flags; | ||
1038 | 1082 | ||
1039 | /* Only an update -> do not call can_rx_register() */ | 1083 | /* Only an update -> do not call can_rx_register() */ |
1040 | do_rx_register = 0; | 1084 | do_rx_register = 0; |
@@ -1045,12 +1089,14 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1045 | if (!op) | 1089 | if (!op) |
1046 | return -ENOMEM; | 1090 | return -ENOMEM; |
1047 | 1091 | ||
1048 | op->can_id = msg_head->can_id; | 1092 | op->can_id = msg_head->can_id; |
1049 | op->nframes = msg_head->nframes; | 1093 | op->nframes = msg_head->nframes; |
1094 | op->cfsiz = CFSIZ(msg_head->flags); | ||
1095 | op->flags = msg_head->flags; | ||
1050 | 1096 | ||
1051 | if (msg_head->nframes > 1) { | 1097 | if (msg_head->nframes > 1) { |
1052 | /* create array for CAN frames and copy the data */ | 1098 | /* create array for CAN frames and copy the data */ |
1053 | op->frames = kmalloc(msg_head->nframes * CFSIZ, | 1099 | op->frames = kmalloc(msg_head->nframes * op->cfsiz, |
1054 | GFP_KERNEL); | 1100 | GFP_KERNEL); |
1055 | if (!op->frames) { | 1101 | if (!op->frames) { |
1056 | kfree(op); | 1102 | kfree(op); |
@@ -1058,7 +1104,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1058 | } | 1104 | } |
1059 | 1105 | ||
1060 | /* create and init array for received CAN frames */ | 1106 | /* create and init array for received CAN frames */ |
1061 | op->last_frames = kzalloc(msg_head->nframes * CFSIZ, | 1107 | op->last_frames = kzalloc(msg_head->nframes * op->cfsiz, |
1062 | GFP_KERNEL); | 1108 | GFP_KERNEL); |
1063 | if (!op->last_frames) { | 1109 | if (!op->last_frames) { |
1064 | kfree(op->frames); | 1110 | kfree(op->frames); |
@@ -1073,7 +1119,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1073 | 1119 | ||
1074 | if (msg_head->nframes) { | 1120 | if (msg_head->nframes) { |
1075 | err = memcpy_from_msg((u8 *)op->frames, msg, | 1121 | err = memcpy_from_msg((u8 *)op->frames, msg, |
1076 | msg_head->nframes * CFSIZ); | 1122 | msg_head->nframes * op->cfsiz); |
1077 | if (err < 0) { | 1123 | if (err < 0) { |
1078 | if (op->frames != &op->sframe) | 1124 | if (op->frames != &op->sframe) |
1079 | kfree(op->frames); | 1125 | kfree(op->frames); |
@@ -1115,7 +1161,6 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1115 | } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */ | 1161 | } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */ |
1116 | 1162 | ||
1117 | /* check flags */ | 1163 | /* check flags */ |
1118 | op->flags = msg_head->flags; | ||
1119 | 1164 | ||
1120 | if (op->flags & RX_RTR_FRAME) { | 1165 | if (op->flags & RX_RTR_FRAME) { |
1121 | 1166 | ||
@@ -1187,7 +1232,7 @@ static int bcm_rx_setup(struct bcm_msg_head *msg_head, struct msghdr *msg, | |||
1187 | } | 1232 | } |
1188 | } | 1233 | } |
1189 | 1234 | ||
1190 | return msg_head->nframes * CFSIZ + MHSIZ; | 1235 | return msg_head->nframes * op->cfsiz + MHSIZ; |
1191 | } | 1236 | } |
1192 | 1237 | ||
1193 | /* | 1238 | /* |
@@ -1244,6 +1289,7 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
1244 | struct bcm_sock *bo = bcm_sk(sk); | 1289 | struct bcm_sock *bo = bcm_sk(sk); |
1245 | int ifindex = bo->ifindex; /* default ifindex for this bcm_op */ | 1290 | int ifindex = bo->ifindex; /* default ifindex for this bcm_op */ |
1246 | struct bcm_msg_head msg_head; | 1291 | struct bcm_msg_head msg_head; |
1292 | int cfsiz; | ||
1247 | int ret; /* read bytes or error codes as return value */ | 1293 | int ret; /* read bytes or error codes as return value */ |
1248 | 1294 | ||
1249 | if (!bo->bound) | 1295 | if (!bo->bound) |
@@ -1258,7 +1304,8 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
1258 | if (ret < 0) | 1304 | if (ret < 0) |
1259 | return ret; | 1305 | return ret; |
1260 | 1306 | ||
1261 | if ((size - MHSIZ) % CFSIZ) | 1307 | cfsiz = CFSIZ(msg_head.flags); |
1308 | if ((size - MHSIZ) % cfsiz) | ||
1262 | return -EINVAL; | 1309 | return -EINVAL; |
1263 | 1310 | ||
1264 | /* check for alternative ifindex for this bcm_op */ | 1311 | /* check for alternative ifindex for this bcm_op */ |
@@ -1332,10 +1379,10 @@ static int bcm_sendmsg(struct socket *sock, struct msghdr *msg, size_t size) | |||
1332 | 1379 | ||
1333 | case TX_SEND: | 1380 | case TX_SEND: |
1334 | /* we need exactly one CAN frame behind the msg head */ | 1381 | /* we need exactly one CAN frame behind the msg head */ |
1335 | if ((msg_head.nframes != 1) || (size != CFSIZ + MHSIZ)) | 1382 | if ((msg_head.nframes != 1) || (size != cfsiz + MHSIZ)) |
1336 | ret = -EINVAL; | 1383 | ret = -EINVAL; |
1337 | else | 1384 | else |
1338 | ret = bcm_tx_send(msg, ifindex, sk, CFSIZ); | 1385 | ret = bcm_tx_send(msg, ifindex, sk, cfsiz); |
1339 | break; | 1386 | break; |
1340 | 1387 | ||
1341 | default: | 1388 | default: |