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_ESWITCH_H__
34#define __MLX5_ESWITCH_H__
35
36#include <linux/if_ether.h>
37#include <linux/if_link.h>
38#include <linux/mlx5/device.h>
39
40#define MLX5_MAX_UC_PER_VPORT(dev) \
41 (1 << MLX5_CAP_GEN(dev, log_max_current_uc_list))
42
43#define MLX5_MAX_MC_PER_VPORT(dev) \
44 (1 << MLX5_CAP_GEN(dev, log_max_current_mc_list))
45
46#define MLX5_L2_ADDR_HASH_SIZE (BIT(BITS_PER_BYTE))
47#define MLX5_L2_ADDR_HASH(addr) (addr[5])
48
49
50struct l2addr_node {
51 struct hlist_node hlist;
52 u8 addr[ETH_ALEN];
53};
54
55#define for_each_l2hash_node(hn, tmp, hash, i) \
56 for (i = 0; i < MLX5_L2_ADDR_HASH_SIZE; i++) \
57 hlist_for_each_entry_safe(hn, tmp, &hash[i], hlist)
58
59#define l2addr_hash_find(hash, mac, type) ({ \
60 int ix = MLX5_L2_ADDR_HASH(mac); \
61 bool found = false; \
62 type *ptr = NULL; \
63 \
64 hlist_for_each_entry(ptr, &hash[ix], node.hlist) \
65 if (ether_addr_equal(ptr->node.addr, mac)) {\
66 found = true; \
67 break; \
68 } \
69 if (!found) \
70 ptr = NULL; \
71 ptr; \
72})
73
74#define l2addr_hash_add(hash, mac, type, gfp) ({ \
75 int ix = MLX5_L2_ADDR_HASH(mac); \
76 type *ptr = NULL; \
77 \
78 ptr = kzalloc(sizeof(type), gfp); \
79 if (ptr) { \
80 ether_addr_copy(ptr->node.addr, mac); \
81 hlist_add_head(&ptr->node.hlist, &hash[ix]);\
82 } \
83 ptr; \
84})
85
86#define l2addr_hash_del(ptr) ({ \
87 hlist_del(&ptr->node.hlist); \
88 kfree(ptr); \
89})
90
91struct mlx5_vport {
92 struct mlx5_core_dev *dev;
93 int vport;
94 struct hlist_head uc_list[MLX5_L2_ADDR_HASH_SIZE];
95 struct hlist_head mc_list[MLX5_L2_ADDR_HASH_SIZE];
96 struct work_struct vport_change_handler;
97
98
99
100
101
102 spinlock_t lock;
103 bool enabled;
104 u16 enabled_events;
105};
106
107struct mlx5_l2_table {
108 struct hlist_head l2_hash[MLX5_L2_ADDR_HASH_SIZE];
109 u32 size;
110 unsigned long *bitmap;
111};
112
113struct mlx5_eswitch_fdb {
114 void *fdb;
115 struct mlx5_flow_group *addr_grp;
116};
117
118struct mlx5_eswitch {
119 struct mlx5_core_dev *dev;
120 struct mlx5_l2_table l2_table;
121 struct mlx5_eswitch_fdb fdb_table;
122 struct hlist_head mc_table[MLX5_L2_ADDR_HASH_SIZE];
123 struct workqueue_struct *work_queue;
124 struct mlx5_vport *vports;
125 int total_vports;
126 int enabled_vports;
127};
128
129
130int mlx5_eswitch_init(struct mlx5_core_dev *dev);
131void mlx5_eswitch_cleanup(struct mlx5_eswitch *esw);
132void mlx5_eswitch_vport_event(struct mlx5_eswitch *esw, struct mlx5_eqe *eqe);
133int mlx5_eswitch_enable_sriov(struct mlx5_eswitch *esw, int nvfs);
134void mlx5_eswitch_disable_sriov(struct mlx5_eswitch *esw);
135int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch *esw,
136 int vport, u8 mac[ETH_ALEN]);
137int mlx5_eswitch_set_vport_state(struct mlx5_eswitch *esw,
138 int vport, int link_state);
139int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch *esw,
140 int vport, u16 vlan, u8 qos);
141int mlx5_eswitch_get_vport_config(struct mlx5_eswitch *esw,
142 int vport, struct ifla_vf_info *ivi);
143int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch *esw,
144 int vport,
145 struct ifla_vf_stats *vf_stats);
146
147#endif
148