0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033 #ifndef __MLX5_MPFS_H__
0034 #define __MLX5_MPFS_H__
0035
0036 #include <linux/if_ether.h>
0037 #include <linux/mlx5/device.h>
0038
0039
0040 #define MLX5_L2_ADDR_HASH_SIZE (BIT(BITS_PER_BYTE))
0041 #define MLX5_L2_ADDR_HASH(addr) (addr[5])
0042
0043 struct l2addr_node {
0044 struct hlist_node hlist;
0045 u8 addr[ETH_ALEN];
0046 };
0047
0048 #define for_each_l2hash_node(hn, tmp, hash, i) \
0049 for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \
0050 hlist_for_each_entry_safe(hn, tmp, &(hash)[i], hlist)
0051
0052 #define l2addr_hash_find(hash, mac, type) ({ \
0053 int ix = MLX5_L2_ADDR_HASH(mac); \
0054 bool found = false; \
0055 type *ptr = NULL; \
0056 \
0057 hlist_for_each_entry(ptr, &(hash)[ix], node.hlist) \
0058 if (ether_addr_equal(ptr->node.addr, mac)) {\
0059 found = true; \
0060 break; \
0061 } \
0062 if (!found) \
0063 ptr = NULL; \
0064 ptr; \
0065 })
0066
0067 #define l2addr_hash_add(hash, mac, type, gfp) ({ \
0068 int ix = MLX5_L2_ADDR_HASH(mac); \
0069 type *ptr = NULL; \
0070 \
0071 ptr = kzalloc(sizeof(type), gfp); \
0072 if (ptr) { \
0073 ether_addr_copy(ptr->node.addr, mac); \
0074 hlist_add_head(&ptr->node.hlist, &(hash)[ix]);\
0075 } \
0076 ptr; \
0077 })
0078
0079 #define l2addr_hash_del(ptr) ({ \
0080 hlist_del(&(ptr)->node.hlist); \
0081 kfree(ptr); \
0082 })
0083
0084 #ifdef CONFIG_MLX5_MPFS
0085 int mlx5_mpfs_init(struct mlx5_core_dev *dev);
0086 void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev);
0087 #else
0088 static inline int mlx5_mpfs_init(struct mlx5_core_dev *dev) { return 0; }
0089 static inline void mlx5_mpfs_cleanup(struct mlx5_core_dev *dev) {}
0090 #endif
0091
0092 #endif