1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * MCTP per-net structures
4 */
5
6#ifndef __NETNS_MCTP_H__
7#define __NETNS_MCTP_H__
8
9#include <linux/hash.h>
10#include <linux/hashtable.h>
11#include <linux/mutex.h>
12#include <linux/types.h>
13
14#define MCTP_BINDS_BITS 7
15
16struct netns_mctp {
17 /* Only updated under RTNL, entries freed via RCU */
18 struct list_head routes;
19
20 /* Bound sockets: hash table of sockets, keyed by
21 * (type, src_eid, dest_eid).
22 * Specific src_eid/dest_eid entries also have an entry for
23 * MCTP_ADDR_ANY. This list is updated from non-atomic contexts
24 * (under bind_lock), and read (under rcu) in packet rx.
25 */
26 struct mutex bind_lock;
27 DECLARE_HASHTABLE(binds, MCTP_BINDS_BITS);
28
29 /* tag allocations. This list is read and updated from atomic contexts,
30 * but elements are free()ed after a RCU grace-period
31 */
32 spinlock_t keys_lock;
33 struct hlist_head keys;
34
35 /* MCTP network */
36 unsigned int default_net;
37
38 /* neighbour table */
39 struct mutex neigh_lock;
40 struct list_head neighbours;
41};
42
43static inline u32 mctp_bind_hash(u8 type, u8 local_addr, u8 peer_addr)
44{
45 return hash_32(val: type | (u32)local_addr << 8 | (u32)peer_addr << 16,
46 MCTP_BINDS_BITS);
47}
48
49#endif /* __NETNS_MCTP_H__ */
50