mctp.h 1.2 KB

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