1 #ifndef _OPA_VNIC_INTERNAL_H
2 #define _OPA_VNIC_INTERNAL_H
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54 #include <linux/bitops.h>
55 #include <linux/etherdevice.h>
56 #include <linux/hashtable.h>
57 #include <linux/sizes.h>
58 #include <rdma/opa_vnic.h>
59
60 #include "opa_vnic_encap.h"
61
62 #define OPA_VNIC_VLAN_PCP(vlan_tci) \
63 (((vlan_tci) & VLAN_PRIO_MASK) >> VLAN_PRIO_SHIFT)
64
65
66 #define OPA_VNIC_FLOW_TBL_SIZE 32
67
68
69 #define OPA_VNIC_INVALID_PORT 0xff
70
71 struct opa_vnic_adapter;
72
73
74
75
76
77
78 struct __opa_vesw_info {
79 u16 fabric_id;
80 u16 vesw_id;
81
82 u8 rsvd0[6];
83 u16 def_port_mask;
84
85 u8 rsvd1[2];
86 u16 pkey;
87
88 u8 rsvd2[4];
89 u32 u_mcast_dlid;
90 u32 u_ucast_dlid[OPA_VESW_MAX_NUM_DEF_PORT];
91
92 u32 rc;
93
94 u8 rsvd3[56];
95 u16 eth_mtu;
96 u8 rsvd4[2];
97 } __packed;
98
99
100
101
102
103
104 struct __opa_per_veswport_info {
105 u32 port_num;
106
107 u8 eth_link_status;
108 u8 rsvd0[3];
109
110 u8 base_mac_addr[ETH_ALEN];
111 u8 config_state;
112 u8 oper_state;
113
114 u16 max_mac_tbl_ent;
115 u16 max_smac_ent;
116 u32 mac_tbl_digest;
117 u8 rsvd1[4];
118
119 u32 encap_slid;
120
121 u8 pcp_to_sc_uc[OPA_VNIC_MAX_NUM_PCP];
122 u8 pcp_to_vl_uc[OPA_VNIC_MAX_NUM_PCP];
123 u8 pcp_to_sc_mc[OPA_VNIC_MAX_NUM_PCP];
124 u8 pcp_to_vl_mc[OPA_VNIC_MAX_NUM_PCP];
125
126 u8 non_vlan_sc_uc;
127 u8 non_vlan_vl_uc;
128 u8 non_vlan_sc_mc;
129 u8 non_vlan_vl_mc;
130
131 u8 rsvd2[48];
132
133 u16 uc_macs_gen_count;
134 u16 mc_macs_gen_count;
135
136 u8 rsvd3[8];
137 } __packed;
138
139
140
141
142
143
144 struct __opa_veswport_info {
145 struct __opa_vesw_info vesw;
146 struct __opa_per_veswport_info vport;
147 };
148
149
150
151
152
153
154 struct __opa_veswport_trap {
155 u16 fabric_id;
156 u16 veswid;
157 u32 veswportnum;
158 u16 opaportnum;
159 u8 veswportindex;
160 u8 opcode;
161 u32 reserved;
162 } __packed;
163
164
165
166
167
168
169
170 struct opa_vnic_ctrl_port {
171 struct ib_device *ibdev;
172 struct opa_vnic_ctrl_ops *ops;
173 u8 num_ports;
174 };
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196 struct opa_vnic_adapter {
197 struct net_device *netdev;
198 struct ib_device *ibdev;
199 struct opa_vnic_ctrl_port *cport;
200 const struct net_device_ops *rn_ops;
201
202 u8 port_num;
203 u8 vport_num;
204
205
206 struct mutex lock;
207
208 struct __opa_veswport_info info;
209 u8 vema_mac_addr[ETH_ALEN];
210 u32 umac_hash;
211 u32 mmac_hash;
212 struct hlist_head __rcu *mactbl;
213
214
215 struct mutex mactbl_lock;
216
217
218 spinlock_t stats_lock;
219
220 u8 flow_tbl[OPA_VNIC_FLOW_TBL_SIZE];
221
222 unsigned long trap_timeout;
223 u8 trap_count;
224 };
225
226
227 struct __opa_vnic_mactable_entry {
228 u8 mac_addr[ETH_ALEN];
229 u8 mac_addr_mask[ETH_ALEN];
230 u32 dlid_sd;
231 } __packed;
232
233
234
235
236
237
238
239 struct opa_vnic_mac_tbl_node {
240 struct hlist_node hlist;
241 u16 index;
242 struct __opa_vnic_mactable_entry entry;
243 };
244
245 #define v_dbg(format, arg...) \
246 netdev_dbg(adapter->netdev, format, ## arg)
247 #define v_err(format, arg...) \
248 netdev_err(adapter->netdev, format, ## arg)
249 #define v_info(format, arg...) \
250 netdev_info(adapter->netdev, format, ## arg)
251 #define v_warn(format, arg...) \
252 netdev_warn(adapter->netdev, format, ## arg)
253
254 #define c_err(format, arg...) \
255 dev_err(&cport->ibdev->dev, format, ## arg)
256 #define c_info(format, arg...) \
257 dev_info(&cport->ibdev->dev, format, ## arg)
258 #define c_dbg(format, arg...) \
259 dev_dbg(&cport->ibdev->dev, format, ## arg)
260
261
262 #define OPA_VNIC_MAC_TBL_MAX_ENTRIES 2048
263
264 #define OPA_VNIC_MAX_SMAC_LIMIT 256
265
266
267 #define OPA_VNIC_MAC_HASH_IDX 5
268
269
270 #define OPA_VNIC_MAC_TBL_HASH_BITS 8
271 #define OPA_VNIC_MAC_TBL_SIZE BIT(OPA_VNIC_MAC_TBL_HASH_BITS)
272
273
274 #define vnic_hash_init(hashtable) __hash_init(hashtable, OPA_VNIC_MAC_TBL_SIZE)
275
276 #define vnic_hash_add(hashtable, node, key) \
277 hlist_add_head(node, \
278 &hashtable[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))])
279
280 #define vnic_hash_for_each_safe(name, bkt, tmp, obj, member) \
281 for ((bkt) = 0, obj = NULL; \
282 !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++) \
283 hlist_for_each_entry_safe(obj, tmp, &name[bkt], member)
284
285 #define vnic_hash_for_each_possible(name, obj, member, key) \
286 hlist_for_each_entry(obj, \
287 &name[hash_min(key, ilog2(OPA_VNIC_MAC_TBL_SIZE))], member)
288
289 #define vnic_hash_for_each(name, bkt, obj, member) \
290 for ((bkt) = 0, obj = NULL; \
291 !obj && (bkt) < OPA_VNIC_MAC_TBL_SIZE; (bkt)++) \
292 hlist_for_each_entry(obj, &name[bkt], member)
293
294 extern char opa_vnic_driver_name[];
295 extern const char opa_vnic_driver_version[];
296
297 struct opa_vnic_adapter *opa_vnic_add_netdev(struct ib_device *ibdev,
298 u8 port_num, u8 vport_num);
299 void opa_vnic_rem_netdev(struct opa_vnic_adapter *adapter);
300 void opa_vnic_encap_skb(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
301 u8 opa_vnic_get_vl(struct opa_vnic_adapter *adapter, struct sk_buff *skb);
302 u8 opa_vnic_calc_entropy(struct sk_buff *skb);
303 void opa_vnic_process_vema_config(struct opa_vnic_adapter *adapter);
304 void opa_vnic_release_mac_tbl(struct opa_vnic_adapter *adapter);
305 void opa_vnic_query_mac_tbl(struct opa_vnic_adapter *adapter,
306 struct opa_veswport_mactable *tbl);
307 int opa_vnic_update_mac_tbl(struct opa_vnic_adapter *adapter,
308 struct opa_veswport_mactable *tbl);
309 void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,
310 struct opa_veswport_iface_macs *macs);
311 void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,
312 struct opa_veswport_iface_macs *macs);
313 void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,
314 struct opa_veswport_summary_counters *cntrs);
315 void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,
316 struct opa_veswport_error_counters *cntrs);
317 void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,
318 struct opa_vesw_info *info);
319 void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,
320 struct opa_vesw_info *info);
321 void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,
322 struct opa_per_veswport_info *info);
323 void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,
324 struct opa_per_veswport_info *info);
325 void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event);
326 void opa_vnic_set_ethtool_ops(struct net_device *netdev);
327 void opa_vnic_vema_send_trap(struct opa_vnic_adapter *adapter,
328 struct __opa_veswport_trap *data, u32 lid);
329
330 #endif