1 // SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause)
3 * bcm.c - Broadcast Manager to filter/send (cyclic) CAN content
5 * Copyright (c) 2002-2017 Volkswagen Group Electronic Research
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of Volkswagen nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * Alternatively, provided that this notice is retained in full, this
21 * software may be distributed under the terms of the GNU General
22 * Public License ("GPL") version 2, in which case the provisions of the
23 * GPL apply INSTEAD OF those given above.
25 * The provided data structures and external interfaces from this code
26 * are not restricted to be used by modules with a GPL compatible license.
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
31 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
32 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
35 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
36 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
37 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
38 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
43 #include <linux/module.h>
44 #include <linux/init.h>
45 #include <linux/interrupt.h>
46 #include <linux/hrtimer.h>
47 #include <linux/list.h>
48 #include <linux/proc_fs.h>
49 #include <linux/seq_file.h>
50 #include <linux/uio.h>
51 #include <linux/net.h>
52 #include <linux/netdevice.h>
53 #include <linux/socket.h>
54 #include <linux/if_arp.h>
55 #include <linux/skbuff.h>
56 #include <linux/can.h>
57 #include <linux/can/core.h>
58 #include <linux/can/skb.h>
59 #include <linux/can/bcm.h>
60 #include <linux/slab.h>
62 #include <net/net_namespace.h>
65 * To send multiple CAN frame content within TX_SETUP or to filter
66 * CAN messages with multiplex index within RX_SETUP, the number of
67 * different filters is limited to 256 due to the one byte index value.
69 #define MAX_NFRAMES 256
71 /* limit timers to 400 days for sending/timeouts */
72 #define BCM_TIMER_SEC_MAX (400 * 24 * 60 * 60)
74 /* use of last_frames[index].flags */
75 #define RX_RECV 0x40 /* received data for this element */
76 #define RX_THR 0x80 /* element not been sent due to throttle feature */
77 #define BCM_CAN_FLAGS_MASK 0x3F /* to clean private flags after usage */
79 /* get best masking value for can_rx_register() for a given single can_id */
80 #define REGMASK(id) ((id & CAN_EFF_FLAG) ? \
81 (CAN_EFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG) : \
82 (CAN_SFF_MASK | CAN_EFF_FLAG | CAN_RTR_FLAG))
84 MODULE_DESCRIPTION("PF_CAN broadcast manager protocol");
85 MODULE_LICENSE("Dual BSD/GPL");
86 MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
87 MODULE_ALIAS("can-proto-2");
90 * easy access to the first 64 bit of can(fd)_frame payload. cp->data is
91 * 64 bit aligned so the offset has to be multiples of 8 which is ensured
92 * by the only callers in bcm_rx_cmp_to_index() bcm_rx_handler().
94 static inline u64
get_u64(const struct canfd_frame
*cp
, int offset
)
96 return *(u64
*)(cp
->data
+ offset
);
100 struct list_head list
;
104 unsigned long frames_abs
, frames_filtered
;
105 struct bcm_timeval ival1
, ival2
;
106 struct hrtimer timer
, thrtimer
;
107 ktime_t rx_stamp
, kt_ival1
, kt_ival2
, kt_lastmsg
;
113 /* void pointers to arrays of struct can[fd]_frame */
116 struct canfd_frame sframe
;
117 struct canfd_frame last_sframe
;
119 struct net_device
*rx_reg_dev
;
126 struct notifier_block notifier
;
127 struct list_head rx_ops
;
128 struct list_head tx_ops
;
129 unsigned long dropped_usr_msgs
;
130 struct proc_dir_entry
*bcm_proc_read
;
131 char procname
[32]; /* inode number in decimal with \0 */
134 static inline struct bcm_sock
*bcm_sk(const struct sock
*sk
)
136 return (struct bcm_sock
*)sk
;
139 static inline ktime_t
bcm_timeval_to_ktime(struct bcm_timeval tv
)
141 return ktime_set(tv
.tv_sec
, tv
.tv_usec
* NSEC_PER_USEC
);
144 /* check limitations for timeval provided by user */
145 static bool bcm_is_invalid_tv(struct bcm_msg_head
*msg_head
)
147 if ((msg_head
->ival1
.tv_sec
< 0) ||
148 (msg_head
->ival1
.tv_sec
> BCM_TIMER_SEC_MAX
) ||
149 (msg_head
->ival1
.tv_usec
< 0) ||
150 (msg_head
->ival1
.tv_usec
>= USEC_PER_SEC
) ||
151 (msg_head
->ival2
.tv_sec
< 0) ||
152 (msg_head
->ival2
.tv_sec
> BCM_TIMER_SEC_MAX
) ||
153 (msg_head
->ival2
.tv_usec
< 0) ||
154 (msg_head
->ival2
.tv_usec
>= USEC_PER_SEC
))
160 #define CFSIZ(flags) ((flags & CAN_FD_FRAME) ? CANFD_MTU : CAN_MTU)
161 #define OPSIZ sizeof(struct bcm_op)
162 #define MHSIZ sizeof(struct bcm_msg_head)
167 #if IS_ENABLED(CONFIG_PROC_FS)
168 static char *bcm_proc_getifname(struct net
*net
, char *result
, int ifindex
)
170 struct net_device
*dev
;
176 dev
= dev_get_by_index_rcu(net
, ifindex
);
178 strcpy(result
, dev
->name
);
180 strcpy(result
, "???");
186 static int bcm_proc_show(struct seq_file
*m
, void *v
)
188 char ifname
[IFNAMSIZ
];
189 struct net
*net
= m
->private;
190 struct sock
*sk
= (struct sock
*)PDE_DATA(m
->file
->f_inode
);
191 struct bcm_sock
*bo
= bcm_sk(sk
);
194 seq_printf(m
, ">>> socket %pK", sk
->sk_socket
);
195 seq_printf(m
, " / sk %pK", sk
);
196 seq_printf(m
, " / bo %pK", bo
);
197 seq_printf(m
, " / dropped %lu", bo
->dropped_usr_msgs
);
198 seq_printf(m
, " / bound %s", bcm_proc_getifname(net
, ifname
, bo
->ifindex
));
199 seq_printf(m
, " <<<\n");
201 list_for_each_entry(op
, &bo
->rx_ops
, list
) {
203 unsigned long reduction
;
205 /* print only active entries & prevent division by zero */
209 seq_printf(m
, "rx_op: %03X %-5s ", op
->can_id
,
210 bcm_proc_getifname(net
, ifname
, op
->ifindex
));
212 if (op
->flags
& CAN_FD_FRAME
)
213 seq_printf(m
, "(%u)", op
->nframes
);
215 seq_printf(m
, "[%u]", op
->nframes
);
217 seq_printf(m
, "%c ", (op
->flags
& RX_CHECK_DLC
) ? 'd' : ' ');
220 seq_printf(m
, "timeo=%lld ",
221 (long long)ktime_to_us(op
->kt_ival1
));
224 seq_printf(m
, "thr=%lld ",
225 (long long)ktime_to_us(op
->kt_ival2
));
227 seq_printf(m
, "# recv %ld (%ld) => reduction: ",
228 op
->frames_filtered
, op
->frames_abs
);
230 reduction
= 100 - (op
->frames_filtered
* 100) / op
->frames_abs
;
232 seq_printf(m
, "%s%ld%%\n",
233 (reduction
== 100) ? "near " : "", reduction
);
236 list_for_each_entry(op
, &bo
->tx_ops
, list
) {
238 seq_printf(m
, "tx_op: %03X %s ", op
->can_id
,
239 bcm_proc_getifname(net
, ifname
, op
->ifindex
));
241 if (op
->flags
& CAN_FD_FRAME
)
242 seq_printf(m
, "(%u) ", op
->nframes
);
244 seq_printf(m
, "[%u] ", op
->nframes
);
247 seq_printf(m
, "t1=%lld ",
248 (long long)ktime_to_us(op
->kt_ival1
));
251 seq_printf(m
, "t2=%lld ",
252 (long long)ktime_to_us(op
->kt_ival2
));
254 seq_printf(m
, "# sent %ld\n", op
->frames_abs
);
259 #endif /* CONFIG_PROC_FS */
262 * bcm_can_tx - send the (next) CAN frame to the appropriate CAN interface
263 * of the given bcm tx op
265 static void bcm_can_tx(struct bcm_op
*op
)
268 struct net_device
*dev
;
269 struct canfd_frame
*cf
= op
->frames
+ op
->cfsiz
* op
->currframe
;
271 /* no target device? => exit */
275 dev
= dev_get_by_index(sock_net(op
->sk
), op
->ifindex
);
277 /* RFC: should this bcm_op remove itself here? */
281 skb
= alloc_skb(op
->cfsiz
+ sizeof(struct can_skb_priv
), gfp_any());
285 can_skb_reserve(skb
);
286 can_skb_prv(skb
)->ifindex
= dev
->ifindex
;
287 can_skb_prv(skb
)->skbcnt
= 0;
289 skb_put_data(skb
, cf
, op
->cfsiz
);
291 /* send with loopback */
293 can_skb_set_owner(skb
, op
->sk
);
296 /* update statistics */
300 /* reached last frame? */
301 if (op
->currframe
>= op
->nframes
)
308 * bcm_send_to_user - send a BCM message to the userspace
309 * (consisting of bcm_msg_head + x CAN frames)
311 static void bcm_send_to_user(struct bcm_op
*op
, struct bcm_msg_head
*head
,
312 struct canfd_frame
*frames
, int has_timestamp
)
315 struct canfd_frame
*firstframe
;
316 struct sockaddr_can
*addr
;
317 struct sock
*sk
= op
->sk
;
318 unsigned int datalen
= head
->nframes
* op
->cfsiz
;
321 skb
= alloc_skb(sizeof(*head
) + datalen
, gfp_any());
325 skb_put_data(skb
, head
, sizeof(*head
));
328 /* CAN frames starting here */
329 firstframe
= (struct canfd_frame
*)skb_tail_pointer(skb
);
331 skb_put_data(skb
, frames
, datalen
);
334 * the BCM uses the flags-element of the canfd_frame
335 * structure for internal purposes. This is only
336 * relevant for updates that are generated by the
337 * BCM, where nframes is 1
339 if (head
->nframes
== 1)
340 firstframe
->flags
&= BCM_CAN_FLAGS_MASK
;
344 /* restore rx timestamp */
345 skb
->tstamp
= op
->rx_stamp
;
349 * Put the datagram to the queue so that bcm_recvmsg() can
350 * get it from there. We need to pass the interface index to
351 * bcm_recvmsg(). We pass a whole struct sockaddr_can in skb->cb
352 * containing the interface index.
355 sock_skb_cb_check_size(sizeof(struct sockaddr_can
));
356 addr
= (struct sockaddr_can
*)skb
->cb
;
357 memset(addr
, 0, sizeof(*addr
));
358 addr
->can_family
= AF_CAN
;
359 addr
->can_ifindex
= op
->rx_ifindex
;
361 err
= sock_queue_rcv_skb(sk
, skb
);
363 struct bcm_sock
*bo
= bcm_sk(sk
);
366 /* don't care about overflows in this statistic */
367 bo
->dropped_usr_msgs
++;
371 static bool bcm_tx_set_expiry(struct bcm_op
*op
, struct hrtimer
*hrt
)
375 if (op
->kt_ival1
&& op
->count
)
377 else if (op
->kt_ival2
)
382 hrtimer_set_expires(hrt
, ktime_add(ktime_get(), ival
));
386 static void bcm_tx_start_timer(struct bcm_op
*op
)
388 if (bcm_tx_set_expiry(op
, &op
->timer
))
389 hrtimer_start_expires(&op
->timer
, HRTIMER_MODE_ABS_SOFT
);
392 /* bcm_tx_timeout_handler - performs cyclic CAN frame transmissions */
393 static enum hrtimer_restart
bcm_tx_timeout_handler(struct hrtimer
*hrtimer
)
395 struct bcm_op
*op
= container_of(hrtimer
, struct bcm_op
, timer
);
396 struct bcm_msg_head msg_head
;
398 if (op
->kt_ival1
&& (op
->count
> 0)) {
400 if (!op
->count
&& (op
->flags
& TX_COUNTEVT
)) {
402 /* create notification to user */
403 msg_head
.opcode
= TX_EXPIRED
;
404 msg_head
.flags
= op
->flags
;
405 msg_head
.count
= op
->count
;
406 msg_head
.ival1
= op
->ival1
;
407 msg_head
.ival2
= op
->ival2
;
408 msg_head
.can_id
= op
->can_id
;
409 msg_head
.nframes
= 0;
411 bcm_send_to_user(op
, &msg_head
, NULL
, 0);
415 } else if (op
->kt_ival2
) {
419 return bcm_tx_set_expiry(op
, &op
->timer
) ?
420 HRTIMER_RESTART
: HRTIMER_NORESTART
;
424 * bcm_rx_changed - create a RX_CHANGED notification due to changed content
426 static void bcm_rx_changed(struct bcm_op
*op
, struct canfd_frame
*data
)
428 struct bcm_msg_head head
;
430 /* update statistics */
431 op
->frames_filtered
++;
433 /* prevent statistics overflow */
434 if (op
->frames_filtered
> ULONG_MAX
/100)
435 op
->frames_filtered
= op
->frames_abs
= 0;
437 /* this element is not throttled anymore */
438 data
->flags
&= (BCM_CAN_FLAGS_MASK
|RX_RECV
);
440 head
.opcode
= RX_CHANGED
;
441 head
.flags
= op
->flags
;
442 head
.count
= op
->count
;
443 head
.ival1
= op
->ival1
;
444 head
.ival2
= op
->ival2
;
445 head
.can_id
= op
->can_id
;
448 bcm_send_to_user(op
, &head
, data
, 1);
452 * bcm_rx_update_and_send - process a detected relevant receive content change
453 * 1. update the last received data
454 * 2. send a notification to the user (if possible)
456 static void bcm_rx_update_and_send(struct bcm_op
*op
,
457 struct canfd_frame
*lastdata
,
458 const struct canfd_frame
*rxdata
)
460 memcpy(lastdata
, rxdata
, op
->cfsiz
);
462 /* mark as used and throttled by default */
463 lastdata
->flags
|= (RX_RECV
|RX_THR
);
465 /* throttling mode inactive ? */
467 /* send RX_CHANGED to the user immediately */
468 bcm_rx_changed(op
, lastdata
);
472 /* with active throttling timer we are just done here */
473 if (hrtimer_active(&op
->thrtimer
))
476 /* first reception with enabled throttling mode */
478 goto rx_changed_settime
;
480 /* got a second frame inside a potential throttle period? */
481 if (ktime_us_delta(ktime_get(), op
->kt_lastmsg
) <
482 ktime_to_us(op
->kt_ival2
)) {
483 /* do not send the saved data - only start throttle timer */
484 hrtimer_start(&op
->thrtimer
,
485 ktime_add(op
->kt_lastmsg
, op
->kt_ival2
),
486 HRTIMER_MODE_ABS_SOFT
);
490 /* the gap was that big, that throttling was not needed here */
492 bcm_rx_changed(op
, lastdata
);
493 op
->kt_lastmsg
= ktime_get();
497 * bcm_rx_cmp_to_index - (bit)compares the currently received data to formerly
498 * received data stored in op->last_frames[]
500 static void bcm_rx_cmp_to_index(struct bcm_op
*op
, unsigned int index
,
501 const struct canfd_frame
*rxdata
)
503 struct canfd_frame
*cf
= op
->frames
+ op
->cfsiz
* index
;
504 struct canfd_frame
*lcf
= op
->last_frames
+ op
->cfsiz
* index
;
508 * no one uses the MSBs of flags for comparison,
509 * so we use it here to detect the first time of reception
512 if (!(lcf
->flags
& RX_RECV
)) {
513 /* received data for the first time => send update to user */
514 bcm_rx_update_and_send(op
, lcf
, rxdata
);
518 /* do a real check in CAN frame data section */
519 for (i
= 0; i
< rxdata
->len
; i
+= 8) {
520 if ((get_u64(cf
, i
) & get_u64(rxdata
, i
)) !=
521 (get_u64(cf
, i
) & get_u64(lcf
, i
))) {
522 bcm_rx_update_and_send(op
, lcf
, rxdata
);
527 if (op
->flags
& RX_CHECK_DLC
) {
528 /* do a real check in CAN frame length */
529 if (rxdata
->len
!= lcf
->len
) {
530 bcm_rx_update_and_send(op
, lcf
, rxdata
);
537 * bcm_rx_starttimer - enable timeout monitoring for CAN frame reception
539 static void bcm_rx_starttimer(struct bcm_op
*op
)
541 if (op
->flags
& RX_NO_AUTOTIMER
)
545 hrtimer_start(&op
->timer
, op
->kt_ival1
, HRTIMER_MODE_REL_SOFT
);
548 /* bcm_rx_timeout_handler - when the (cyclic) CAN frame reception timed out */
549 static enum hrtimer_restart
bcm_rx_timeout_handler(struct hrtimer
*hrtimer
)
551 struct bcm_op
*op
= container_of(hrtimer
, struct bcm_op
, timer
);
552 struct bcm_msg_head msg_head
;
554 /* if user wants to be informed, when cyclic CAN-Messages come back */
555 if ((op
->flags
& RX_ANNOUNCE_RESUME
) && op
->last_frames
) {
556 /* clear received CAN frames to indicate 'nothing received' */
557 memset(op
->last_frames
, 0, op
->nframes
* op
->cfsiz
);
560 /* create notification to user */
561 msg_head
.opcode
= RX_TIMEOUT
;
562 msg_head
.flags
= op
->flags
;
563 msg_head
.count
= op
->count
;
564 msg_head
.ival1
= op
->ival1
;
565 msg_head
.ival2
= op
->ival2
;
566 msg_head
.can_id
= op
->can_id
;
567 msg_head
.nframes
= 0;
569 bcm_send_to_user(op
, &msg_head
, NULL
, 0);
571 return HRTIMER_NORESTART
;
575 * bcm_rx_do_flush - helper for bcm_rx_thr_flush
577 static inline int bcm_rx_do_flush(struct bcm_op
*op
, unsigned int index
)
579 struct canfd_frame
*lcf
= op
->last_frames
+ op
->cfsiz
* index
;
581 if ((op
->last_frames
) && (lcf
->flags
& RX_THR
)) {
582 bcm_rx_changed(op
, lcf
);
589 * bcm_rx_thr_flush - Check for throttled data and send it to the userspace
591 static int bcm_rx_thr_flush(struct bcm_op
*op
)
595 if (op
->nframes
> 1) {
598 /* for MUX filter we start at index 1 */
599 for (i
= 1; i
< op
->nframes
; i
++)
600 updated
+= bcm_rx_do_flush(op
, i
);
603 /* for RX_FILTER_ID and simple filter */
604 updated
+= bcm_rx_do_flush(op
, 0);
611 * bcm_rx_thr_handler - the time for blocked content updates is over now:
612 * Check for throttled data and send it to the userspace
614 static enum hrtimer_restart
bcm_rx_thr_handler(struct hrtimer
*hrtimer
)
616 struct bcm_op
*op
= container_of(hrtimer
, struct bcm_op
, thrtimer
);
618 if (bcm_rx_thr_flush(op
)) {
619 hrtimer_forward(hrtimer
, ktime_get(), op
->kt_ival2
);
620 return HRTIMER_RESTART
;
622 /* rearm throttle handling */
624 return HRTIMER_NORESTART
;
629 * bcm_rx_handler - handle a CAN frame reception
631 static void bcm_rx_handler(struct sk_buff
*skb
, void *data
)
633 struct bcm_op
*op
= (struct bcm_op
*)data
;
634 const struct canfd_frame
*rxframe
= (struct canfd_frame
*)skb
->data
;
637 if (op
->can_id
!= rxframe
->can_id
)
640 /* make sure to handle the correct frame type (CAN / CAN FD) */
641 if (skb
->len
!= op
->cfsiz
)
644 /* disable timeout */
645 hrtimer_cancel(&op
->timer
);
647 /* save rx timestamp */
648 op
->rx_stamp
= skb
->tstamp
;
649 /* save originator for recvfrom() */
650 op
->rx_ifindex
= skb
->dev
->ifindex
;
651 /* update statistics */
654 if (op
->flags
& RX_RTR_FRAME
) {
655 /* send reply for RTR-request (placed in op->frames[0]) */
660 if (op
->flags
& RX_FILTER_ID
) {
661 /* the easiest case */
662 bcm_rx_update_and_send(op
, op
->last_frames
, rxframe
);
666 if (op
->nframes
== 1) {
667 /* simple compare with index 0 */
668 bcm_rx_cmp_to_index(op
, 0, rxframe
);
672 if (op
->nframes
> 1) {
676 * find the first multiplex mask that fits.
677 * Remark: The MUX-mask is stored in index 0 - but only the
678 * first 64 bits of the frame data[] are relevant (CAN FD)
681 for (i
= 1; i
< op
->nframes
; i
++) {
682 if ((get_u64(op
->frames
, 0) & get_u64(rxframe
, 0)) ==
683 (get_u64(op
->frames
, 0) &
684 get_u64(op
->frames
+ op
->cfsiz
* i
, 0))) {
685 bcm_rx_cmp_to_index(op
, i
, rxframe
);
692 bcm_rx_starttimer(op
);
696 * helpers for bcm_op handling: find & delete bcm [rx|tx] op elements
698 static struct bcm_op
*bcm_find_op(struct list_head
*ops
,
699 struct bcm_msg_head
*mh
, int ifindex
)
703 list_for_each_entry(op
, ops
, list
) {
704 if ((op
->can_id
== mh
->can_id
) && (op
->ifindex
== ifindex
) &&
705 (op
->flags
& CAN_FD_FRAME
) == (mh
->flags
& CAN_FD_FRAME
))
712 static void bcm_remove_op(struct bcm_op
*op
)
714 hrtimer_cancel(&op
->timer
);
715 hrtimer_cancel(&op
->thrtimer
);
717 if ((op
->frames
) && (op
->frames
!= &op
->sframe
))
720 if ((op
->last_frames
) && (op
->last_frames
!= &op
->last_sframe
))
721 kfree(op
->last_frames
);
726 static void bcm_rx_unreg(struct net_device
*dev
, struct bcm_op
*op
)
728 if (op
->rx_reg_dev
== dev
) {
729 can_rx_unregister(dev_net(dev
), dev
, op
->can_id
,
730 REGMASK(op
->can_id
), bcm_rx_handler
, op
);
732 /* mark as removed subscription */
733 op
->rx_reg_dev
= NULL
;
735 printk(KERN_ERR
"can-bcm: bcm_rx_unreg: registered device "
736 "mismatch %p %p\n", op
->rx_reg_dev
, dev
);
740 * bcm_delete_rx_op - find and remove a rx op (returns number of removed ops)
742 static int bcm_delete_rx_op(struct list_head
*ops
, struct bcm_msg_head
*mh
,
745 struct bcm_op
*op
, *n
;
747 list_for_each_entry_safe(op
, n
, ops
, list
) {
748 if ((op
->can_id
== mh
->can_id
) && (op
->ifindex
== ifindex
) &&
749 (op
->flags
& CAN_FD_FRAME
) == (mh
->flags
& CAN_FD_FRAME
)) {
752 * Don't care if we're bound or not (due to netdev
753 * problems) can_rx_unregister() is always a save
758 * Only remove subscriptions that had not
759 * been removed due to NETDEV_UNREGISTER
762 if (op
->rx_reg_dev
) {
763 struct net_device
*dev
;
765 dev
= dev_get_by_index(sock_net(op
->sk
),
768 bcm_rx_unreg(dev
, op
);
773 can_rx_unregister(sock_net(op
->sk
), NULL
,
784 return 0; /* not found */
788 * bcm_delete_tx_op - find and remove a tx op (returns number of removed ops)
790 static int bcm_delete_tx_op(struct list_head
*ops
, struct bcm_msg_head
*mh
,
793 struct bcm_op
*op
, *n
;
795 list_for_each_entry_safe(op
, n
, ops
, list
) {
796 if ((op
->can_id
== mh
->can_id
) && (op
->ifindex
== ifindex
) &&
797 (op
->flags
& CAN_FD_FRAME
) == (mh
->flags
& CAN_FD_FRAME
)) {
804 return 0; /* not found */
808 * bcm_read_op - read out a bcm_op and send it to the user (for bcm_sendmsg)
810 static int bcm_read_op(struct list_head
*ops
, struct bcm_msg_head
*msg_head
,
813 struct bcm_op
*op
= bcm_find_op(ops
, msg_head
, ifindex
);
818 /* put current values into msg_head */
819 msg_head
->flags
= op
->flags
;
820 msg_head
->count
= op
->count
;
821 msg_head
->ival1
= op
->ival1
;
822 msg_head
->ival2
= op
->ival2
;
823 msg_head
->nframes
= op
->nframes
;
825 bcm_send_to_user(op
, msg_head
, op
->frames
, 0);
831 * bcm_tx_setup - create or update a bcm tx op (for bcm_sendmsg)
833 static int bcm_tx_setup(struct bcm_msg_head
*msg_head
, struct msghdr
*msg
,
834 int ifindex
, struct sock
*sk
)
836 struct bcm_sock
*bo
= bcm_sk(sk
);
838 struct canfd_frame
*cf
;
842 /* we need a real device to send frames */
846 /* check nframes boundaries - we need at least one CAN frame */
847 if (msg_head
->nframes
< 1 || msg_head
->nframes
> MAX_NFRAMES
)
850 /* check timeval limitations */
851 if ((msg_head
->flags
& SETTIMER
) && bcm_is_invalid_tv(msg_head
))
854 /* check the given can_id */
855 op
= bcm_find_op(&bo
->tx_ops
, msg_head
, ifindex
);
857 /* update existing BCM operation */
860 * Do we need more space for the CAN frames than currently
861 * allocated? -> This is a _really_ unusual use-case and
862 * therefore (complexity / locking) it is not supported.
864 if (msg_head
->nframes
> op
->nframes
)
867 /* update CAN frames content */
868 for (i
= 0; i
< msg_head
->nframes
; i
++) {
870 cf
= op
->frames
+ op
->cfsiz
* i
;
871 err
= memcpy_from_msg((u8
*)cf
, msg
, op
->cfsiz
);
873 if (op
->flags
& CAN_FD_FRAME
) {
884 if (msg_head
->flags
& TX_CP_CAN_ID
) {
885 /* copy can_id into frame */
886 cf
->can_id
= msg_head
->can_id
;
889 op
->flags
= msg_head
->flags
;
892 /* insert new BCM operation for the given can_id */
894 op
= kzalloc(OPSIZ
, GFP_KERNEL
);
898 op
->can_id
= msg_head
->can_id
;
899 op
->cfsiz
= CFSIZ(msg_head
->flags
);
900 op
->flags
= msg_head
->flags
;
902 /* create array for CAN frames and copy the data */
903 if (msg_head
->nframes
> 1) {
904 op
->frames
= kmalloc_array(msg_head
->nframes
,
912 op
->frames
= &op
->sframe
;
914 for (i
= 0; i
< msg_head
->nframes
; i
++) {
916 cf
= op
->frames
+ op
->cfsiz
* i
;
917 err
= memcpy_from_msg((u8
*)cf
, msg
, op
->cfsiz
);
919 if (op
->flags
& CAN_FD_FRAME
) {
928 if (op
->frames
!= &op
->sframe
)
934 if (msg_head
->flags
& TX_CP_CAN_ID
) {
935 /* copy can_id into frame */
936 cf
->can_id
= msg_head
->can_id
;
940 /* tx_ops never compare with previous received messages */
941 op
->last_frames
= NULL
;
943 /* bcm_can_tx / bcm_tx_timeout_handler needs this */
945 op
->ifindex
= ifindex
;
947 /* initialize uninitialized (kzalloc) structure */
948 hrtimer_init(&op
->timer
, CLOCK_MONOTONIC
,
949 HRTIMER_MODE_REL_SOFT
);
950 op
->timer
.function
= bcm_tx_timeout_handler
;
952 /* currently unused in tx_ops */
953 hrtimer_init(&op
->thrtimer
, CLOCK_MONOTONIC
,
954 HRTIMER_MODE_REL_SOFT
);
956 /* add this bcm_op to the list of the tx_ops */
957 list_add(&op
->list
, &bo
->tx_ops
);
959 } /* if ((op = bcm_find_op(&bo->tx_ops, msg_head->can_id, ifindex))) */
961 if (op
->nframes
!= msg_head
->nframes
) {
962 op
->nframes
= msg_head
->nframes
;
963 /* start multiple frame transmission with index 0 */
969 if (op
->flags
& TX_RESET_MULTI_IDX
) {
970 /* start multiple frame transmission with index 0 */
974 if (op
->flags
& SETTIMER
) {
975 /* set timer values */
976 op
->count
= msg_head
->count
;
977 op
->ival1
= msg_head
->ival1
;
978 op
->ival2
= msg_head
->ival2
;
979 op
->kt_ival1
= bcm_timeval_to_ktime(msg_head
->ival1
);
980 op
->kt_ival2
= bcm_timeval_to_ktime(msg_head
->ival2
);
982 /* disable an active timer due to zero values? */
983 if (!op
->kt_ival1
&& !op
->kt_ival2
)
984 hrtimer_cancel(&op
->timer
);
987 if (op
->flags
& STARTTIMER
) {
988 hrtimer_cancel(&op
->timer
);
989 /* spec: send CAN frame when starting timer */
990 op
->flags
|= TX_ANNOUNCE
;
993 if (op
->flags
& TX_ANNOUNCE
) {
999 if (op
->flags
& STARTTIMER
)
1000 bcm_tx_start_timer(op
);
1002 return msg_head
->nframes
* op
->cfsiz
+ MHSIZ
;
1006 * bcm_rx_setup - create or update a bcm rx op (for bcm_sendmsg)
1008 static int bcm_rx_setup(struct bcm_msg_head
*msg_head
, struct msghdr
*msg
,
1009 int ifindex
, struct sock
*sk
)
1011 struct bcm_sock
*bo
= bcm_sk(sk
);
1016 if ((msg_head
->flags
& RX_FILTER_ID
) || (!(msg_head
->nframes
))) {
1017 /* be robust against wrong usage ... */
1018 msg_head
->flags
|= RX_FILTER_ID
;
1019 /* ignore trailing garbage */
1020 msg_head
->nframes
= 0;
1023 /* the first element contains the mux-mask => MAX_NFRAMES + 1 */
1024 if (msg_head
->nframes
> MAX_NFRAMES
+ 1)
1027 if ((msg_head
->flags
& RX_RTR_FRAME
) &&
1028 ((msg_head
->nframes
!= 1) ||
1029 (!(msg_head
->can_id
& CAN_RTR_FLAG
))))
1032 /* check timeval limitations */
1033 if ((msg_head
->flags
& SETTIMER
) && bcm_is_invalid_tv(msg_head
))
1036 /* check the given can_id */
1037 op
= bcm_find_op(&bo
->rx_ops
, msg_head
, ifindex
);
1039 /* update existing BCM operation */
1042 * Do we need more space for the CAN frames than currently
1043 * allocated? -> This is a _really_ unusual use-case and
1044 * therefore (complexity / locking) it is not supported.
1046 if (msg_head
->nframes
> op
->nframes
)
1049 if (msg_head
->nframes
) {
1050 /* update CAN frames content */
1051 err
= memcpy_from_msg(op
->frames
, msg
,
1052 msg_head
->nframes
* op
->cfsiz
);
1056 /* clear last_frames to indicate 'nothing received' */
1057 memset(op
->last_frames
, 0, msg_head
->nframes
* op
->cfsiz
);
1060 op
->nframes
= msg_head
->nframes
;
1061 op
->flags
= msg_head
->flags
;
1063 /* Only an update -> do not call can_rx_register() */
1067 /* insert new BCM operation for the given can_id */
1068 op
= kzalloc(OPSIZ
, GFP_KERNEL
);
1072 op
->can_id
= msg_head
->can_id
;
1073 op
->nframes
= msg_head
->nframes
;
1074 op
->cfsiz
= CFSIZ(msg_head
->flags
);
1075 op
->flags
= msg_head
->flags
;
1077 if (msg_head
->nframes
> 1) {
1078 /* create array for CAN frames and copy the data */
1079 op
->frames
= kmalloc_array(msg_head
->nframes
,
1087 /* create and init array for received CAN frames */
1088 op
->last_frames
= kcalloc(msg_head
->nframes
,
1091 if (!op
->last_frames
) {
1098 op
->frames
= &op
->sframe
;
1099 op
->last_frames
= &op
->last_sframe
;
1102 if (msg_head
->nframes
) {
1103 err
= memcpy_from_msg(op
->frames
, msg
,
1104 msg_head
->nframes
* op
->cfsiz
);
1106 if (op
->frames
!= &op
->sframe
)
1108 if (op
->last_frames
!= &op
->last_sframe
)
1109 kfree(op
->last_frames
);
1115 /* bcm_can_tx / bcm_tx_timeout_handler needs this */
1117 op
->ifindex
= ifindex
;
1119 /* ifindex for timeout events w/o previous frame reception */
1120 op
->rx_ifindex
= ifindex
;
1122 /* initialize uninitialized (kzalloc) structure */
1123 hrtimer_init(&op
->timer
, CLOCK_MONOTONIC
,
1124 HRTIMER_MODE_REL_SOFT
);
1125 op
->timer
.function
= bcm_rx_timeout_handler
;
1127 hrtimer_init(&op
->thrtimer
, CLOCK_MONOTONIC
,
1128 HRTIMER_MODE_REL_SOFT
);
1129 op
->thrtimer
.function
= bcm_rx_thr_handler
;
1131 /* add this bcm_op to the list of the rx_ops */
1132 list_add(&op
->list
, &bo
->rx_ops
);
1134 /* call can_rx_register() */
1137 } /* if ((op = bcm_find_op(&bo->rx_ops, msg_head->can_id, ifindex))) */
1141 if (op
->flags
& RX_RTR_FRAME
) {
1142 struct canfd_frame
*frame0
= op
->frames
;
1144 /* no timers in RTR-mode */
1145 hrtimer_cancel(&op
->thrtimer
);
1146 hrtimer_cancel(&op
->timer
);
1149 * funny feature in RX(!)_SETUP only for RTR-mode:
1150 * copy can_id into frame BUT without RTR-flag to
1151 * prevent a full-load-loopback-test ... ;-]
1153 if ((op
->flags
& TX_CP_CAN_ID
) ||
1154 (frame0
->can_id
== op
->can_id
))
1155 frame0
->can_id
= op
->can_id
& ~CAN_RTR_FLAG
;
1158 if (op
->flags
& SETTIMER
) {
1160 /* set timer value */
1161 op
->ival1
= msg_head
->ival1
;
1162 op
->ival2
= msg_head
->ival2
;
1163 op
->kt_ival1
= bcm_timeval_to_ktime(msg_head
->ival1
);
1164 op
->kt_ival2
= bcm_timeval_to_ktime(msg_head
->ival2
);
1166 /* disable an active timer due to zero value? */
1168 hrtimer_cancel(&op
->timer
);
1171 * In any case cancel the throttle timer, flush
1172 * potentially blocked msgs and reset throttle handling
1175 hrtimer_cancel(&op
->thrtimer
);
1176 bcm_rx_thr_flush(op
);
1179 if ((op
->flags
& STARTTIMER
) && op
->kt_ival1
)
1180 hrtimer_start(&op
->timer
, op
->kt_ival1
,
1181 HRTIMER_MODE_REL_SOFT
);
1184 /* now we can register for can_ids, if we added a new bcm_op */
1185 if (do_rx_register
) {
1187 struct net_device
*dev
;
1189 dev
= dev_get_by_index(sock_net(sk
), ifindex
);
1191 err
= can_rx_register(sock_net(sk
), dev
,
1193 REGMASK(op
->can_id
),
1197 op
->rx_reg_dev
= dev
;
1202 err
= can_rx_register(sock_net(sk
), NULL
, op
->can_id
,
1203 REGMASK(op
->can_id
),
1204 bcm_rx_handler
, op
, "bcm", sk
);
1206 /* this bcm rx op is broken -> remove it */
1207 list_del(&op
->list
);
1213 return msg_head
->nframes
* op
->cfsiz
+ MHSIZ
;
1217 * bcm_tx_send - send a single CAN frame to the CAN interface (for bcm_sendmsg)
1219 static int bcm_tx_send(struct msghdr
*msg
, int ifindex
, struct sock
*sk
,
1222 struct sk_buff
*skb
;
1223 struct net_device
*dev
;
1226 /* we need a real device to send frames */
1230 skb
= alloc_skb(cfsiz
+ sizeof(struct can_skb_priv
), GFP_KERNEL
);
1234 can_skb_reserve(skb
);
1236 err
= memcpy_from_msg(skb_put(skb
, cfsiz
), msg
, cfsiz
);
1242 dev
= dev_get_by_index(sock_net(sk
), ifindex
);
1248 can_skb_prv(skb
)->ifindex
= dev
->ifindex
;
1249 can_skb_prv(skb
)->skbcnt
= 0;
1251 can_skb_set_owner(skb
, sk
);
1252 err
= can_send(skb
, 1); /* send with loopback */
1258 return cfsiz
+ MHSIZ
;
1262 * bcm_sendmsg - process BCM commands (opcodes) from the userspace
1264 static int bcm_sendmsg(struct socket
*sock
, struct msghdr
*msg
, size_t size
)
1266 struct sock
*sk
= sock
->sk
;
1267 struct bcm_sock
*bo
= bcm_sk(sk
);
1268 int ifindex
= bo
->ifindex
; /* default ifindex for this bcm_op */
1269 struct bcm_msg_head msg_head
;
1271 int ret
; /* read bytes or error codes as return value */
1276 /* check for valid message length from userspace */
1280 /* read message head information */
1281 ret
= memcpy_from_msg((u8
*)&msg_head
, msg
, MHSIZ
);
1285 cfsiz
= CFSIZ(msg_head
.flags
);
1286 if ((size
- MHSIZ
) % cfsiz
)
1289 /* check for alternative ifindex for this bcm_op */
1291 if (!ifindex
&& msg
->msg_name
) {
1292 /* no bound device as default => check msg_name */
1293 DECLARE_SOCKADDR(struct sockaddr_can
*, addr
, msg
->msg_name
);
1295 if (msg
->msg_namelen
< CAN_REQUIRED_SIZE(*addr
, can_ifindex
))
1298 if (addr
->can_family
!= AF_CAN
)
1301 /* ifindex from sendto() */
1302 ifindex
= addr
->can_ifindex
;
1305 struct net_device
*dev
;
1307 dev
= dev_get_by_index(sock_net(sk
), ifindex
);
1311 if (dev
->type
!= ARPHRD_CAN
) {
1322 switch (msg_head
.opcode
) {
1325 ret
= bcm_tx_setup(&msg_head
, msg
, ifindex
, sk
);
1329 ret
= bcm_rx_setup(&msg_head
, msg
, ifindex
, sk
);
1333 if (bcm_delete_tx_op(&bo
->tx_ops
, &msg_head
, ifindex
))
1340 if (bcm_delete_rx_op(&bo
->rx_ops
, &msg_head
, ifindex
))
1347 /* reuse msg_head for the reply to TX_READ */
1348 msg_head
.opcode
= TX_STATUS
;
1349 ret
= bcm_read_op(&bo
->tx_ops
, &msg_head
, ifindex
);
1353 /* reuse msg_head for the reply to RX_READ */
1354 msg_head
.opcode
= RX_STATUS
;
1355 ret
= bcm_read_op(&bo
->rx_ops
, &msg_head
, ifindex
);
1359 /* we need exactly one CAN frame behind the msg head */
1360 if ((msg_head
.nframes
!= 1) || (size
!= cfsiz
+ MHSIZ
))
1363 ret
= bcm_tx_send(msg
, ifindex
, sk
, cfsiz
);
1377 * notification handler for netdevice status changes
1379 static int bcm_notifier(struct notifier_block
*nb
, unsigned long msg
,
1382 struct net_device
*dev
= netdev_notifier_info_to_dev(ptr
);
1383 struct bcm_sock
*bo
= container_of(nb
, struct bcm_sock
, notifier
);
1384 struct sock
*sk
= &bo
->sk
;
1386 int notify_enodev
= 0;
1388 if (!net_eq(dev_net(dev
), sock_net(sk
)))
1391 if (dev
->type
!= ARPHRD_CAN
)
1396 case NETDEV_UNREGISTER
:
1399 /* remove device specific receive entries */
1400 list_for_each_entry(op
, &bo
->rx_ops
, list
)
1401 if (op
->rx_reg_dev
== dev
)
1402 bcm_rx_unreg(dev
, op
);
1404 /* remove device reference, if this is our bound device */
1405 if (bo
->bound
&& bo
->ifindex
== dev
->ifindex
) {
1413 if (notify_enodev
) {
1414 sk
->sk_err
= ENODEV
;
1415 if (!sock_flag(sk
, SOCK_DEAD
))
1416 sk
->sk_error_report(sk
);
1421 if (bo
->bound
&& bo
->ifindex
== dev
->ifindex
) {
1422 sk
->sk_err
= ENETDOWN
;
1423 if (!sock_flag(sk
, SOCK_DEAD
))
1424 sk
->sk_error_report(sk
);
1432 * initial settings for all BCM sockets to be set at socket creation time
1434 static int bcm_init(struct sock
*sk
)
1436 struct bcm_sock
*bo
= bcm_sk(sk
);
1440 bo
->dropped_usr_msgs
= 0;
1441 bo
->bcm_proc_read
= NULL
;
1443 INIT_LIST_HEAD(&bo
->tx_ops
);
1444 INIT_LIST_HEAD(&bo
->rx_ops
);
1447 bo
->notifier
.notifier_call
= bcm_notifier
;
1449 register_netdevice_notifier(&bo
->notifier
);
1455 * standard socket functions
1457 static int bcm_release(struct socket
*sock
)
1459 struct sock
*sk
= sock
->sk
;
1461 struct bcm_sock
*bo
;
1462 struct bcm_op
*op
, *next
;
1470 /* remove bcm_ops, timer, rx_unregister(), etc. */
1472 unregister_netdevice_notifier(&bo
->notifier
);
1476 list_for_each_entry_safe(op
, next
, &bo
->tx_ops
, list
)
1479 list_for_each_entry_safe(op
, next
, &bo
->rx_ops
, list
) {
1481 * Don't care if we're bound or not (due to netdev problems)
1482 * can_rx_unregister() is always a save thing to do here.
1486 * Only remove subscriptions that had not
1487 * been removed due to NETDEV_UNREGISTER
1490 if (op
->rx_reg_dev
) {
1491 struct net_device
*dev
;
1493 dev
= dev_get_by_index(net
, op
->ifindex
);
1495 bcm_rx_unreg(dev
, op
);
1500 can_rx_unregister(net
, NULL
, op
->can_id
,
1501 REGMASK(op
->can_id
),
1502 bcm_rx_handler
, op
);
1507 #if IS_ENABLED(CONFIG_PROC_FS)
1508 /* remove procfs entry */
1509 if (net
->can
.bcmproc_dir
&& bo
->bcm_proc_read
)
1510 remove_proc_entry(bo
->procname
, net
->can
.bcmproc_dir
);
1511 #endif /* CONFIG_PROC_FS */
1513 /* remove device reference */
1528 static int bcm_connect(struct socket
*sock
, struct sockaddr
*uaddr
, int len
,
1531 struct sockaddr_can
*addr
= (struct sockaddr_can
*)uaddr
;
1532 struct sock
*sk
= sock
->sk
;
1533 struct bcm_sock
*bo
= bcm_sk(sk
);
1534 struct net
*net
= sock_net(sk
);
1537 if (len
< CAN_REQUIRED_SIZE(*addr
, can_ifindex
))
1547 /* bind a device to this socket */
1548 if (addr
->can_ifindex
) {
1549 struct net_device
*dev
;
1551 dev
= dev_get_by_index(net
, addr
->can_ifindex
);
1556 if (dev
->type
!= ARPHRD_CAN
) {
1562 bo
->ifindex
= dev
->ifindex
;
1566 /* no interface reference for ifindex = 0 ('any' CAN device) */
1570 #if IS_ENABLED(CONFIG_PROC_FS)
1571 if (net
->can
.bcmproc_dir
) {
1572 /* unique socket address as filename */
1573 sprintf(bo
->procname
, "%lu", sock_i_ino(sk
));
1574 bo
->bcm_proc_read
= proc_create_net_single(bo
->procname
, 0644,
1575 net
->can
.bcmproc_dir
,
1577 if (!bo
->bcm_proc_read
) {
1582 #endif /* CONFIG_PROC_FS */
1592 static int bcm_recvmsg(struct socket
*sock
, struct msghdr
*msg
, size_t size
,
1595 struct sock
*sk
= sock
->sk
;
1596 struct sk_buff
*skb
;
1601 noblock
= flags
& MSG_DONTWAIT
;
1602 flags
&= ~MSG_DONTWAIT
;
1603 skb
= skb_recv_datagram(sk
, flags
, noblock
, &error
);
1607 if (skb
->len
< size
)
1610 err
= memcpy_to_msg(msg
, skb
->data
, size
);
1612 skb_free_datagram(sk
, skb
);
1616 sock_recv_ts_and_drops(msg
, sk
, skb
);
1618 if (msg
->msg_name
) {
1619 __sockaddr_check_size(sizeof(struct sockaddr_can
));
1620 msg
->msg_namelen
= sizeof(struct sockaddr_can
);
1621 memcpy(msg
->msg_name
, skb
->cb
, msg
->msg_namelen
);
1624 skb_free_datagram(sk
, skb
);
1629 static int bcm_sock_no_ioctlcmd(struct socket
*sock
, unsigned int cmd
,
1632 /* no ioctls for socket layer -> hand it down to NIC layer */
1633 return -ENOIOCTLCMD
;
1636 static const struct proto_ops bcm_ops
= {
1638 .release
= bcm_release
,
1639 .bind
= sock_no_bind
,
1640 .connect
= bcm_connect
,
1641 .socketpair
= sock_no_socketpair
,
1642 .accept
= sock_no_accept
,
1643 .getname
= sock_no_getname
,
1644 .poll
= datagram_poll
,
1645 .ioctl
= bcm_sock_no_ioctlcmd
,
1646 .gettstamp
= sock_gettstamp
,
1647 .listen
= sock_no_listen
,
1648 .shutdown
= sock_no_shutdown
,
1649 .sendmsg
= bcm_sendmsg
,
1650 .recvmsg
= bcm_recvmsg
,
1651 .mmap
= sock_no_mmap
,
1652 .sendpage
= sock_no_sendpage
,
1655 static struct proto bcm_proto __read_mostly
= {
1657 .owner
= THIS_MODULE
,
1658 .obj_size
= sizeof(struct bcm_sock
),
1662 static const struct can_proto bcm_can_proto
= {
1664 .protocol
= CAN_BCM
,
1669 static int canbcm_pernet_init(struct net
*net
)
1671 #if IS_ENABLED(CONFIG_PROC_FS)
1672 /* create /proc/net/can-bcm directory */
1673 net
->can
.bcmproc_dir
= proc_net_mkdir(net
, "can-bcm", net
->proc_net
);
1674 #endif /* CONFIG_PROC_FS */
1679 static void canbcm_pernet_exit(struct net
*net
)
1681 #if IS_ENABLED(CONFIG_PROC_FS)
1682 /* remove /proc/net/can-bcm directory */
1683 if (net
->can
.bcmproc_dir
)
1684 remove_proc_entry("can-bcm", net
->proc_net
);
1685 #endif /* CONFIG_PROC_FS */
1688 static struct pernet_operations canbcm_pernet_ops __read_mostly
= {
1689 .init
= canbcm_pernet_init
,
1690 .exit
= canbcm_pernet_exit
,
1693 static int __init
bcm_module_init(void)
1697 pr_info("can: broadcast manager protocol\n");
1699 err
= can_proto_register(&bcm_can_proto
);
1701 printk(KERN_ERR
"can: registration of bcm protocol failed\n");
1705 register_pernet_subsys(&canbcm_pernet_ops
);
1709 static void __exit
bcm_module_exit(void)
1711 can_proto_unregister(&bcm_can_proto
);
1712 unregister_pernet_subsys(&canbcm_pernet_ops
);
1715 module_init(bcm_module_init
);
1716 module_exit(bcm_module_exit
);