162306a36Sopenharmony_ci/* SPDX-License-Identifier: (GPL-2.0 OR BSD-3-Clause) */
262306a36Sopenharmony_ci/* Copyright (c) 2002-2007 Volkswagen Group Electronic Research
362306a36Sopenharmony_ci * Copyright (c) 2017 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de>
462306a36Sopenharmony_ci *
562306a36Sopenharmony_ci * All rights reserved.
662306a36Sopenharmony_ci *
762306a36Sopenharmony_ci * Redistribution and use in source and binary forms, with or without
862306a36Sopenharmony_ci * modification, are permitted provided that the following conditions
962306a36Sopenharmony_ci * are met:
1062306a36Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright
1162306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer.
1262306a36Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright
1362306a36Sopenharmony_ci *    notice, this list of conditions and the following disclaimer in the
1462306a36Sopenharmony_ci *    documentation and/or other materials provided with the distribution.
1562306a36Sopenharmony_ci * 3. Neither the name of Volkswagen nor the names of its contributors
1662306a36Sopenharmony_ci *    may be used to endorse or promote products derived from this software
1762306a36Sopenharmony_ci *    without specific prior written permission.
1862306a36Sopenharmony_ci *
1962306a36Sopenharmony_ci * Alternatively, provided that this notice is retained in full, this
2062306a36Sopenharmony_ci * software may be distributed under the terms of the GNU General
2162306a36Sopenharmony_ci * Public License ("GPL") version 2, in which case the provisions of the
2262306a36Sopenharmony_ci * GPL apply INSTEAD OF those given above.
2362306a36Sopenharmony_ci *
2462306a36Sopenharmony_ci * The provided data structures and external interfaces from this code
2562306a36Sopenharmony_ci * are not restricted to be used by modules with a GPL compatible license.
2662306a36Sopenharmony_ci *
2762306a36Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2862306a36Sopenharmony_ci * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2962306a36Sopenharmony_ci * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
3062306a36Sopenharmony_ci * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3162306a36Sopenharmony_ci * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
3262306a36Sopenharmony_ci * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3362306a36Sopenharmony_ci * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
3462306a36Sopenharmony_ci * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
3562306a36Sopenharmony_ci * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
3662306a36Sopenharmony_ci * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3762306a36Sopenharmony_ci * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
3862306a36Sopenharmony_ci * DAMAGE.
3962306a36Sopenharmony_ci *
4062306a36Sopenharmony_ci */
4162306a36Sopenharmony_ci
4262306a36Sopenharmony_ci#ifndef CAN_ML_H
4362306a36Sopenharmony_ci#define CAN_ML_H
4462306a36Sopenharmony_ci
4562306a36Sopenharmony_ci#include <linux/can.h>
4662306a36Sopenharmony_ci#include <linux/list.h>
4762306a36Sopenharmony_ci#include <linux/netdevice.h>
4862306a36Sopenharmony_ci
4962306a36Sopenharmony_ci#define CAN_SFF_RCV_ARRAY_SZ (1 << CAN_SFF_ID_BITS)
5062306a36Sopenharmony_ci#define CAN_EFF_RCV_HASH_BITS 10
5162306a36Sopenharmony_ci#define CAN_EFF_RCV_ARRAY_SZ (1 << CAN_EFF_RCV_HASH_BITS)
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_cienum { RX_ERR, RX_ALL, RX_FIL, RX_INV, RX_MAX };
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cistruct can_dev_rcv_lists {
5662306a36Sopenharmony_ci	struct hlist_head rx[RX_MAX];
5762306a36Sopenharmony_ci	struct hlist_head rx_sff[CAN_SFF_RCV_ARRAY_SZ];
5862306a36Sopenharmony_ci	struct hlist_head rx_eff[CAN_EFF_RCV_ARRAY_SZ];
5962306a36Sopenharmony_ci	int entries;
6062306a36Sopenharmony_ci};
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_cistruct can_ml_priv {
6362306a36Sopenharmony_ci	struct can_dev_rcv_lists dev_rcv_lists;
6462306a36Sopenharmony_ci#ifdef CAN_J1939
6562306a36Sopenharmony_ci	struct j1939_priv *j1939_priv;
6662306a36Sopenharmony_ci#endif
6762306a36Sopenharmony_ci};
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_cistatic inline struct can_ml_priv *can_get_ml_priv(struct net_device *dev)
7062306a36Sopenharmony_ci{
7162306a36Sopenharmony_ci	return netdev_get_ml_priv(dev, ML_PRIV_CAN);
7262306a36Sopenharmony_ci}
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_cistatic inline void can_set_ml_priv(struct net_device *dev,
7562306a36Sopenharmony_ci				   struct can_ml_priv *ml_priv)
7662306a36Sopenharmony_ci{
7762306a36Sopenharmony_ci	netdev_set_ml_priv(dev, ml_priv, ML_PRIV_CAN);
7862306a36Sopenharmony_ci}
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci#endif /* CAN_ML_H */
81