blob: ef21f7c6bc80ef817ab825fd893a9f8299e46df8 [file] [log] [blame]
Oliver Hartkoppfba76a52019-07-23 15:17:55 +02001/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
Oliver Hartkopp0d665482007-11-16 15:52:17 -08002/*
3 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. Neither the name of Volkswagen nor the names of its contributors
15 * may be used to endorse or promote products derived from this software
16 * without specific prior written permission.
17 *
18 * Alternatively, provided that this notice is retained in full, this
19 * software may be distributed under the terms of the GNU General
20 * Public License ("GPL") version 2, in which case the provisions of the
21 * GPL apply INSTEAD OF those given above.
22 *
23 * The provided data structures and external interfaces from this code
24 * are not restricted to be used by modules with a GPL compatible license.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
29 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
30 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
31 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
32 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
33 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
34 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
37 * DAMAGE.
38 *
Oliver Hartkopp0d665482007-11-16 15:52:17 -080039 */
40
41#ifndef AF_CAN_H
42#define AF_CAN_H
43
44#include <linux/skbuff.h>
45#include <linux/netdevice.h>
46#include <linux/list.h>
47#include <linux/rcupdate.h>
48#include <linux/can.h>
49
50/* af_can rx dispatcher structures */
51
52struct receiver {
53 struct hlist_node list;
Oliver Hartkopp0d665482007-11-16 15:52:17 -080054 canid_t can_id;
55 canid_t mask;
56 unsigned long matches;
57 void (*func)(struct sk_buff *, void *);
58 void *data;
59 char *ident;
Eric Dumazetf1712c72017-01-27 08:11:44 -080060 struct sock *sk;
61 struct rcu_head rcu;
Oliver Hartkopp0d665482007-11-16 15:52:17 -080062};
63
Oliver Hartkoppe3d39172014-04-02 20:25:25 +020064#define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS)
Oliver Hartkopp45c70022014-04-02 20:25:26 +020065#define CAN_EFF_RCV_HASH_BITS 10
66#define CAN_EFF_RCV_ARRAY_SZ (1 << CAN_EFF_RCV_HASH_BITS)
Oliver Hartkoppe3d39172014-04-02 20:25:25 +020067
Oliver Hartkopp45c70022014-04-02 20:25:26 +020068enum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_MAX };
Oliver Hartkopp0d665482007-11-16 15:52:17 -080069
Oliver Hartkopp20dd3852009-12-25 06:47:47 +000070/* per device receive filters linked at dev->ml_priv */
Marc Kleine-Buddeff847ee2017-06-03 20:10:03 +020071struct can_dev_rcv_lists {
Oliver Hartkopp0d665482007-11-16 15:52:17 -080072 struct hlist_head rx[RX_MAX];
Oliver Hartkoppe3d39172014-04-02 20:25:25 +020073 struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ];
Oliver Hartkopp45c70022014-04-02 20:25:26 +020074 struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ];
Oliver Hartkopp0d665482007-11-16 15:52:17 -080075 int remove_on_zero_entries;
76 int entries;
77};
78
79/* statistic structures */
80
81/* can be reset e.g. by can_init_stats() */
82struct s_stats {
83 unsigned long jiffies_init;
84
85 unsigned long rx_frames;
86 unsigned long tx_frames;
87 unsigned long matches;
88
89 unsigned long total_rx_rate;
90 unsigned long total_tx_rate;
91 unsigned long total_rx_match_ratio;
92
93 unsigned long current_rx_rate;
94 unsigned long current_tx_rate;
95 unsigned long current_rx_match_ratio;
96
97 unsigned long max_rx_rate;
98 unsigned long max_tx_rate;
99 unsigned long max_rx_match_ratio;
100
101 unsigned long rx_frames_delta;
102 unsigned long tx_frames_delta;
103 unsigned long matches_delta;
104};
105
106/* persistent statistics */
107struct s_pstats {
108 unsigned long stats_reset;
109 unsigned long user_reset;
110 unsigned long rcv_entries;
111 unsigned long rcv_entries_max;
112};
113
Oliver Hartkopp0d665482007-11-16 15:52:17 -0800114/* function prototypes for the CAN networklayer procfs (proc.c) */
Mario Kicherer8e8cda62017-02-21 12:19:47 +0100115void can_init_proc(struct net *net);
116void can_remove_proc(struct net *net);
Kees Cook1fccb562017-10-16 17:29:06 -0700117void can_stat_update(struct timer_list *t);
Oliver Hartkopp0d665482007-11-16 15:52:17 -0800118
Oliver Hartkopp0d665482007-11-16 15:52:17 -0800119#endif /* AF_CAN_H */