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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52#include "opa_vnic_internal.h"
53
54
55
56
57
58
59
60
61void opa_vnic_vema_report_event(struct opa_vnic_adapter *adapter, u8 event)
62{
63 struct __opa_veswport_info *info = &adapter->info;
64 struct __opa_veswport_trap trap_data;
65
66 trap_data.fabric_id = info->vesw.fabric_id;
67 trap_data.veswid = info->vesw.vesw_id;
68 trap_data.veswportnum = info->vport.port_num;
69 trap_data.opaportnum = adapter->port_num;
70 trap_data.veswportindex = adapter->vport_num;
71 trap_data.opcode = event;
72
73 opa_vnic_vema_send_trap(adapter, &trap_data, info->vport.encap_slid);
74}
75
76
77
78
79
80
81
82
83
84void opa_vnic_get_summary_counters(struct opa_vnic_adapter *adapter,
85 struct opa_veswport_summary_counters *cntrs)
86{
87 struct opa_vnic_stats vstats;
88 __be64 *dst;
89 u64 *src;
90
91 memset(&vstats, 0, sizeof(vstats));
92 spin_lock(&adapter->stats_lock);
93 adapter->rn_ops->ndo_get_stats64(adapter->netdev, &vstats.netstats);
94 spin_unlock(&adapter->stats_lock);
95
96 cntrs->vp_instance = cpu_to_be16(adapter->vport_num);
97 cntrs->vesw_id = cpu_to_be16(adapter->info.vesw.vesw_id);
98 cntrs->veswport_num = cpu_to_be32(adapter->port_num);
99
100 cntrs->tx_errors = cpu_to_be64(vstats.netstats.tx_errors);
101 cntrs->rx_errors = cpu_to_be64(vstats.netstats.rx_errors);
102 cntrs->tx_packets = cpu_to_be64(vstats.netstats.tx_packets);
103 cntrs->rx_packets = cpu_to_be64(vstats.netstats.rx_packets);
104 cntrs->tx_bytes = cpu_to_be64(vstats.netstats.tx_bytes);
105 cntrs->rx_bytes = cpu_to_be64(vstats.netstats.rx_bytes);
106
107
108
109
110
111 for (dst = &cntrs->tx_unicast, src = &vstats.tx_grp.unicast;
112 dst < &cntrs->reserved[0]; dst++, src++) {
113 *dst = cpu_to_be64(*src);
114 }
115}
116
117
118
119
120
121
122
123
124
125void opa_vnic_get_error_counters(struct opa_vnic_adapter *adapter,
126 struct opa_veswport_error_counters *cntrs)
127{
128 struct opa_vnic_stats vstats;
129
130 memset(&vstats, 0, sizeof(vstats));
131 spin_lock(&adapter->stats_lock);
132 adapter->rn_ops->ndo_get_stats64(adapter->netdev, &vstats.netstats);
133 spin_unlock(&adapter->stats_lock);
134
135 cntrs->vp_instance = cpu_to_be16(adapter->vport_num);
136 cntrs->vesw_id = cpu_to_be16(adapter->info.vesw.vesw_id);
137 cntrs->veswport_num = cpu_to_be32(adapter->port_num);
138
139 cntrs->tx_errors = cpu_to_be64(vstats.netstats.tx_errors);
140 cntrs->rx_errors = cpu_to_be64(vstats.netstats.rx_errors);
141 cntrs->tx_dlid_zero = cpu_to_be64(vstats.tx_dlid_zero);
142 cntrs->tx_drop_state = cpu_to_be64(vstats.tx_drop_state);
143 cntrs->tx_logic = cpu_to_be64(vstats.netstats.tx_fifo_errors +
144 vstats.netstats.tx_carrier_errors);
145
146 cntrs->rx_bad_veswid = cpu_to_be64(vstats.netstats.rx_nohandler);
147 cntrs->rx_runt = cpu_to_be64(vstats.rx_runt);
148 cntrs->rx_oversize = cpu_to_be64(vstats.rx_oversize);
149 cntrs->rx_drop_state = cpu_to_be64(vstats.rx_drop_state);
150 cntrs->rx_logic = cpu_to_be64(vstats.netstats.rx_fifo_errors);
151}
152
153
154
155
156
157
158
159
160
161void opa_vnic_get_vesw_info(struct opa_vnic_adapter *adapter,
162 struct opa_vesw_info *info)
163{
164 struct __opa_vesw_info *src = &adapter->info.vesw;
165 int i;
166
167 info->fabric_id = cpu_to_be16(src->fabric_id);
168 info->vesw_id = cpu_to_be16(src->vesw_id);
169 memcpy(info->rsvd0, src->rsvd0, ARRAY_SIZE(src->rsvd0));
170 info->def_port_mask = cpu_to_be16(src->def_port_mask);
171 memcpy(info->rsvd1, src->rsvd1, ARRAY_SIZE(src->rsvd1));
172 info->pkey = cpu_to_be16(src->pkey);
173
174 memcpy(info->rsvd2, src->rsvd2, ARRAY_SIZE(src->rsvd2));
175 info->u_mcast_dlid = cpu_to_be32(src->u_mcast_dlid);
176 for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++)
177 info->u_ucast_dlid[i] = cpu_to_be32(src->u_ucast_dlid[i]);
178
179 info->rc = cpu_to_be32(src->rc);
180
181 memcpy(info->rsvd3, src->rsvd3, ARRAY_SIZE(src->rsvd3));
182 info->eth_mtu = cpu_to_be16(src->eth_mtu);
183 memcpy(info->rsvd4, src->rsvd4, ARRAY_SIZE(src->rsvd4));
184}
185
186
187
188
189
190
191
192
193
194
195void opa_vnic_set_vesw_info(struct opa_vnic_adapter *adapter,
196 struct opa_vesw_info *info)
197{
198 struct __opa_vesw_info *dst = &adapter->info.vesw;
199 int i;
200
201 dst->fabric_id = be16_to_cpu(info->fabric_id);
202 dst->vesw_id = be16_to_cpu(info->vesw_id);
203 memcpy(dst->rsvd0, info->rsvd0, ARRAY_SIZE(info->rsvd0));
204 dst->def_port_mask = be16_to_cpu(info->def_port_mask);
205 memcpy(dst->rsvd1, info->rsvd1, ARRAY_SIZE(info->rsvd1));
206 dst->pkey = be16_to_cpu(info->pkey);
207
208 memcpy(dst->rsvd2, info->rsvd2, ARRAY_SIZE(info->rsvd2));
209 dst->u_mcast_dlid = be32_to_cpu(info->u_mcast_dlid);
210 for (i = 0; i < OPA_VESW_MAX_NUM_DEF_PORT; i++)
211 dst->u_ucast_dlid[i] = be32_to_cpu(info->u_ucast_dlid[i]);
212
213 dst->rc = be32_to_cpu(info->rc);
214
215 memcpy(dst->rsvd3, info->rsvd3, ARRAY_SIZE(info->rsvd3));
216 dst->eth_mtu = be16_to_cpu(info->eth_mtu);
217 memcpy(dst->rsvd4, info->rsvd4, ARRAY_SIZE(info->rsvd4));
218}
219
220
221
222
223
224
225
226
227
228
229void opa_vnic_get_per_veswport_info(struct opa_vnic_adapter *adapter,
230 struct opa_per_veswport_info *info)
231{
232 struct __opa_per_veswport_info *src = &adapter->info.vport;
233
234 info->port_num = cpu_to_be32(src->port_num);
235 info->eth_link_status = src->eth_link_status;
236 memcpy(info->rsvd0, src->rsvd0, ARRAY_SIZE(src->rsvd0));
237
238 memcpy(info->base_mac_addr, src->base_mac_addr,
239 ARRAY_SIZE(info->base_mac_addr));
240 info->config_state = src->config_state;
241 info->oper_state = src->oper_state;
242 info->max_mac_tbl_ent = cpu_to_be16(src->max_mac_tbl_ent);
243 info->max_smac_ent = cpu_to_be16(src->max_smac_ent);
244 info->mac_tbl_digest = cpu_to_be32(src->mac_tbl_digest);
245 memcpy(info->rsvd1, src->rsvd1, ARRAY_SIZE(src->rsvd1));
246
247 info->encap_slid = cpu_to_be32(src->encap_slid);
248 memcpy(info->pcp_to_sc_uc, src->pcp_to_sc_uc,
249 ARRAY_SIZE(info->pcp_to_sc_uc));
250 memcpy(info->pcp_to_vl_uc, src->pcp_to_vl_uc,
251 ARRAY_SIZE(info->pcp_to_vl_uc));
252 memcpy(info->pcp_to_sc_mc, src->pcp_to_sc_mc,
253 ARRAY_SIZE(info->pcp_to_sc_mc));
254 memcpy(info->pcp_to_vl_mc, src->pcp_to_vl_mc,
255 ARRAY_SIZE(info->pcp_to_vl_mc));
256 info->non_vlan_sc_uc = src->non_vlan_sc_uc;
257 info->non_vlan_vl_uc = src->non_vlan_vl_uc;
258 info->non_vlan_sc_mc = src->non_vlan_sc_mc;
259 info->non_vlan_vl_mc = src->non_vlan_vl_mc;
260 memcpy(info->rsvd2, src->rsvd2, ARRAY_SIZE(src->rsvd2));
261
262 info->uc_macs_gen_count = cpu_to_be16(src->uc_macs_gen_count);
263 info->mc_macs_gen_count = cpu_to_be16(src->mc_macs_gen_count);
264 memcpy(info->rsvd3, src->rsvd3, ARRAY_SIZE(src->rsvd3));
265}
266
267
268
269
270
271
272
273
274
275
276void opa_vnic_set_per_veswport_info(struct opa_vnic_adapter *adapter,
277 struct opa_per_veswport_info *info)
278{
279 struct __opa_per_veswport_info *dst = &adapter->info.vport;
280
281 dst->port_num = be32_to_cpu(info->port_num);
282 memcpy(dst->rsvd0, info->rsvd0, ARRAY_SIZE(info->rsvd0));
283
284 memcpy(dst->base_mac_addr, info->base_mac_addr,
285 ARRAY_SIZE(dst->base_mac_addr));
286 dst->config_state = info->config_state;
287 memcpy(dst->rsvd1, info->rsvd1, ARRAY_SIZE(info->rsvd1));
288
289 dst->encap_slid = be32_to_cpu(info->encap_slid);
290 memcpy(dst->pcp_to_sc_uc, info->pcp_to_sc_uc,
291 ARRAY_SIZE(dst->pcp_to_sc_uc));
292 memcpy(dst->pcp_to_vl_uc, info->pcp_to_vl_uc,
293 ARRAY_SIZE(dst->pcp_to_vl_uc));
294 memcpy(dst->pcp_to_sc_mc, info->pcp_to_sc_mc,
295 ARRAY_SIZE(dst->pcp_to_sc_mc));
296 memcpy(dst->pcp_to_vl_mc, info->pcp_to_vl_mc,
297 ARRAY_SIZE(dst->pcp_to_vl_mc));
298 dst->non_vlan_sc_uc = info->non_vlan_sc_uc;
299 dst->non_vlan_vl_uc = info->non_vlan_vl_uc;
300 dst->non_vlan_sc_mc = info->non_vlan_sc_mc;
301 dst->non_vlan_vl_mc = info->non_vlan_vl_mc;
302 memcpy(dst->rsvd2, info->rsvd2, ARRAY_SIZE(info->rsvd2));
303 memcpy(dst->rsvd3, info->rsvd3, ARRAY_SIZE(info->rsvd3));
304}
305
306
307
308
309
310
311
312
313
314void opa_vnic_query_mcast_macs(struct opa_vnic_adapter *adapter,
315 struct opa_veswport_iface_macs *macs)
316{
317 u16 start_idx, num_macs, idx = 0, count = 0;
318 struct netdev_hw_addr *ha;
319
320 start_idx = be16_to_cpu(macs->start_idx);
321 num_macs = be16_to_cpu(macs->num_macs_in_msg);
322 netdev_for_each_mc_addr(ha, adapter->netdev) {
323 struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
324
325 if (start_idx > idx++)
326 continue;
327 else if (num_macs == count)
328 break;
329 memcpy(entry, ha->addr, sizeof(*entry));
330 count++;
331 }
332
333 macs->tot_macs_in_lst = cpu_to_be16(netdev_mc_count(adapter->netdev));
334 macs->num_macs_in_msg = cpu_to_be16(count);
335 macs->gen_count = cpu_to_be16(adapter->info.vport.mc_macs_gen_count);
336}
337
338
339
340
341
342
343
344
345
346void opa_vnic_query_ucast_macs(struct opa_vnic_adapter *adapter,
347 struct opa_veswport_iface_macs *macs)
348{
349 u16 start_idx, tot_macs, num_macs, idx = 0, count = 0, em_macs = 0;
350 struct netdev_hw_addr *ha;
351
352 start_idx = be16_to_cpu(macs->start_idx);
353 num_macs = be16_to_cpu(macs->num_macs_in_msg);
354
355 for_each_dev_addr(adapter->netdev, ha) {
356 struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
357
358
359 if (!memcmp(adapter->info.vport.base_mac_addr, ha->addr,
360 ARRAY_SIZE(adapter->info.vport.base_mac_addr))) {
361 em_macs++;
362 continue;
363 }
364
365 if (start_idx > idx++)
366 continue;
367 else if (num_macs == count)
368 break;
369 memcpy(entry, ha->addr, sizeof(*entry));
370 count++;
371 }
372
373
374 netdev_for_each_uc_addr(ha, adapter->netdev) {
375 struct opa_vnic_iface_mac_entry *entry = &macs->entry[count];
376
377 if (start_idx > idx++)
378 continue;
379 else if (num_macs == count)
380 break;
381 memcpy(entry, ha->addr, sizeof(*entry));
382 count++;
383 }
384
385 tot_macs = netdev_hw_addr_list_count(&adapter->netdev->dev_addrs) +
386 netdev_uc_count(adapter->netdev) - em_macs;
387 macs->tot_macs_in_lst = cpu_to_be16(tot_macs);
388 macs->num_macs_in_msg = cpu_to_be16(count);
389 macs->gen_count = cpu_to_be16(adapter->info.vport.uc_macs_gen_count);
390}
391