1 /* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */ 2 /* 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 * 39 */ 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 52 struct receiver { 53 struct hlist_node list; 54 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; 60 struct sock *sk; 61 struct rcu_head rcu; 62 }; 63 64 #define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS) 65 #define CAN_EFF_RCV_HASH_BITS 10 66 #define CAN_EFF_RCV_ARRAY_SZ (1 << CAN_EFF_RCV_HASH_BITS) 67 68 enum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_MAX }; 69 70 /* per device receive filters linked at dev->ml_priv */ 71 struct can_dev_rcv_lists { 72 struct hlist_head rx[RX_MAX]; 73 struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ]; 74 struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ]; 75 int remove_on_zero_entries; 76 int entries; 77 }; 78 79 /* statistic structures */ 80 81 /* can be reset e.g. by can_init_stats() */ 82 struct 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 */ 107 struct 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 114 /* function prototypes for the CAN networklayer procfs (proc.c) */ 115 void can_init_proc(struct net *net); 116 void can_remove_proc(struct net *net); 117 void can_stat_update(struct timer_list *t); 118 119 #endif /* AF_CAN_H */ 120