1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33#ifndef __MLX5_MPFS_H__
34#define __MLX5_MPFS_H__
35
36#include <linux/if_ether.h>
37#include <linux/mlx5/device.h>
38
39
40#define MLX5_L2_ADDR_HASH_SIZE (BIT(BITS_PER_BYTE))
41#define MLX5_L2_ADDR_HASH(addr) (addr[5])
42
43struct l2addr_node {
44 struct hlist_node hlist;
45 u8 addr[ETH_ALEN];
46};
47
48#define for_each_l2hash_node(hn, tmp, hash, i) \
49 for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \
50 hlist_for_each_entry_safe(hn, tmp, &(hash)[i], hlist)
51
52#define l2addr_hash_find(hash, mac, type) ({ \
53 int ix = MLX5_L2_ADDR_HASH(mac); \
54 bool found = false; \
55 type *ptr = NULL; \
56 \
57 hlist_for_each_entry(ptr, &(hash)[ix], node.hlist) \
58 if (ether_addr_equal(ptr->node.addr, mac)) {\
59 found = true; \
60 break; \
61 } \
62 if (!found) \
63 ptr = NULL; \
64 ptr; \
65})
66
67#define l2addr_hash_add(hash, mac, type, gfp) ({ \
68 int ix = MLX5_L2_ADDR_HASH(mac); \
69 type *ptr = NULL; \
70 \
71 ptr = kzalloc(sizeof(type), gfp); \
72 if (ptr) { \
73 ether_addr_copy(ptr->node.addr, mac); \
74 hlist_add_head(&ptr->node.hlist, &(hash)[ix]);\
75 } \
76 ptr; \
77})
78
79#define l2addr_hash_del(ptr) ({ \
80 hlist_del(&(ptr)->node.hlist); \
81 kfree(ptr); \
82})
83
84#ifdef CONFIG_MLX5_MPFS
85int mlx5_mpfs_init(struct mlx5_core_dev *dev);
86void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev);
87int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac);
88int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac);
89#else
90static inline int mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; }
91static inline void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev) {}
92static inline int mlx5_mpfs_add_mac(struct mlx5_core_dev *dev, u8 *mac) { return 0; }
93static inline int mlx5_mpfs_del_mac(struct mlx5_core_dev *dev, u8 *mac) { return 0; }
94#endif
95#endif
96