2 * Copyright (c) 2015, Mellanox Technologies. All rights reserved.
4 * This software is available to you under a choice of one of two
5 * licenses. You may choose to be licensed under the terms of the GNU
6 * General Public License (GPL) Version 2, available from the file
7 * COPYING in the main directory of this source tree, or the
8 * OpenIB.org BSD license below:
10 * Redistribution and use in source and binary forms, with or
11 * without modification, are permitted provided that the following
14 * - Redistributions of source code must retain the above
15 * copyright notice, this list of conditions and the following
18 * - Redistributions in binary form must reproduce the above
19 * copyright notice, this list of conditions and the following
20 * disclaimer in the documentation and/or other materials
21 * provided with the distribution.
23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33 #include <linux/etherdevice.h>
34 #include <linux/mlx5/driver.h>
35 #include <linux/mlx5/mlx5_ifc.h>
36 #include <linux/mlx5/vport.h>
37 #include <linux/mlx5/fs.h>
38 #include "mlx5_core.h"
41 #define UPLINK_VPORT 0xFFFF
49 /* E-Switch UC L2 table hash node */
51 struct l2addr_node node
;
56 /* E-Switch MC FDB table hash node */
57 struct esw_mc_addr
{ /* SRIOV only */
58 struct l2addr_node node
;
59 struct mlx5_flow_rule
*uplink_rule
; /* Forward to uplink rule */
63 /* Vport UC/MC hash node */
65 struct l2addr_node node
;
68 struct mlx5_flow_rule
*flow_rule
; /* SRIOV only */
69 /* A flag indicating that mac was added due to mc promiscuous vport */
74 UC_ADDR_CHANGE
= BIT(0),
75 MC_ADDR_CHANGE
= BIT(1),
76 PROMISC_CHANGE
= BIT(3),
79 /* Vport context events */
80 #define SRIOV_VPORT_EVENTS (UC_ADDR_CHANGE | \
84 int esw_create_offloads_fdb_table(struct mlx5_eswitch
*esw
, int nvports
);
85 void esw_destroy_offloads_fdb_table(struct mlx5_eswitch
*esw
);
87 static int arm_vport_context_events_cmd(struct mlx5_core_dev
*dev
, u16 vport
,
90 int in
[MLX5_ST_SZ_DW(modify_nic_vport_context_in
)];
91 int out
[MLX5_ST_SZ_DW(modify_nic_vport_context_out
)];
95 memset(out
, 0, sizeof(out
));
96 memset(in
, 0, sizeof(in
));
98 MLX5_SET(modify_nic_vport_context_in
, in
,
99 opcode
, MLX5_CMD_OP_MODIFY_NIC_VPORT_CONTEXT
);
100 MLX5_SET(modify_nic_vport_context_in
, in
, field_select
.change_event
, 1);
101 MLX5_SET(modify_nic_vport_context_in
, in
, vport_number
, vport
);
103 MLX5_SET(modify_nic_vport_context_in
, in
, other_vport
, 1);
104 nic_vport_ctx
= MLX5_ADDR_OF(modify_nic_vport_context_in
,
105 in
, nic_vport_context
);
107 MLX5_SET(nic_vport_context
, nic_vport_ctx
, arm_change_event
, 1);
109 if (events_mask
& UC_ADDR_CHANGE
)
110 MLX5_SET(nic_vport_context
, nic_vport_ctx
,
111 event_on_uc_address_change
, 1);
112 if (events_mask
& MC_ADDR_CHANGE
)
113 MLX5_SET(nic_vport_context
, nic_vport_ctx
,
114 event_on_mc_address_change
, 1);
115 if (events_mask
& PROMISC_CHANGE
)
116 MLX5_SET(nic_vport_context
, nic_vport_ctx
,
117 event_on_promisc_change
, 1);
119 err
= mlx5_cmd_exec(dev
, in
, sizeof(in
), out
, sizeof(out
));
122 err
= mlx5_cmd_status_to_err_v2(out
);
130 /* E-Switch vport context HW commands */
131 static int query_esw_vport_context_cmd(struct mlx5_core_dev
*mdev
, u32 vport
,
132 u32
*out
, int outlen
)
134 u32 in
[MLX5_ST_SZ_DW(query_esw_vport_context_in
)];
136 memset(in
, 0, sizeof(in
));
138 MLX5_SET(query_nic_vport_context_in
, in
, opcode
,
139 MLX5_CMD_OP_QUERY_ESW_VPORT_CONTEXT
);
141 MLX5_SET(query_esw_vport_context_in
, in
, vport_number
, vport
);
143 MLX5_SET(query_esw_vport_context_in
, in
, other_vport
, 1);
145 return mlx5_cmd_exec_check_status(mdev
, in
, sizeof(in
), out
, outlen
);
148 static int query_esw_vport_cvlan(struct mlx5_core_dev
*dev
, u32 vport
,
151 u32 out
[MLX5_ST_SZ_DW(query_esw_vport_context_out
)];
156 memset(out
, 0, sizeof(out
));
161 if (!MLX5_CAP_ESW(dev
, vport_cvlan_strip
) ||
162 !MLX5_CAP_ESW(dev
, vport_cvlan_insert_if_not_exist
))
165 err
= query_esw_vport_context_cmd(dev
, vport
, out
, sizeof(out
));
169 cvlan_strip
= MLX5_GET(query_esw_vport_context_out
, out
,
170 esw_vport_context
.vport_cvlan_strip
);
172 cvlan_insert
= MLX5_GET(query_esw_vport_context_out
, out
,
173 esw_vport_context
.vport_cvlan_insert
);
175 if (cvlan_strip
|| cvlan_insert
) {
176 *vlan
= MLX5_GET(query_esw_vport_context_out
, out
,
177 esw_vport_context
.cvlan_id
);
178 *qos
= MLX5_GET(query_esw_vport_context_out
, out
,
179 esw_vport_context
.cvlan_pcp
);
182 esw_debug(dev
, "Query Vport[%d] cvlan: VLAN %d qos=%d\n",
188 static int modify_esw_vport_context_cmd(struct mlx5_core_dev
*dev
, u16 vport
,
191 u32 out
[MLX5_ST_SZ_DW(modify_esw_vport_context_out
)];
193 memset(out
, 0, sizeof(out
));
195 MLX5_SET(modify_esw_vport_context_in
, in
, vport_number
, vport
);
197 MLX5_SET(modify_esw_vport_context_in
, in
, other_vport
, 1);
199 MLX5_SET(modify_esw_vport_context_in
, in
, opcode
,
200 MLX5_CMD_OP_MODIFY_ESW_VPORT_CONTEXT
);
202 return mlx5_cmd_exec_check_status(dev
, in
, inlen
,
206 static int modify_esw_vport_cvlan(struct mlx5_core_dev
*dev
, u32 vport
,
207 u16 vlan
, u8 qos
, bool set
)
209 u32 in
[MLX5_ST_SZ_DW(modify_esw_vport_context_in
)];
211 memset(in
, 0, sizeof(in
));
213 if (!MLX5_CAP_ESW(dev
, vport_cvlan_strip
) ||
214 !MLX5_CAP_ESW(dev
, vport_cvlan_insert_if_not_exist
))
217 esw_debug(dev
, "Set Vport[%d] VLAN %d qos %d set=%d\n",
218 vport
, vlan
, qos
, set
);
221 MLX5_SET(modify_esw_vport_context_in
, in
,
222 esw_vport_context
.vport_cvlan_strip
, 1);
223 /* insert only if no vlan in packet */
224 MLX5_SET(modify_esw_vport_context_in
, in
,
225 esw_vport_context
.vport_cvlan_insert
, 1);
226 MLX5_SET(modify_esw_vport_context_in
, in
,
227 esw_vport_context
.cvlan_pcp
, qos
);
228 MLX5_SET(modify_esw_vport_context_in
, in
,
229 esw_vport_context
.cvlan_id
, vlan
);
232 MLX5_SET(modify_esw_vport_context_in
, in
,
233 field_select
.vport_cvlan_strip
, 1);
234 MLX5_SET(modify_esw_vport_context_in
, in
,
235 field_select
.vport_cvlan_insert
, 1);
237 return modify_esw_vport_context_cmd(dev
, vport
, in
, sizeof(in
));
240 /* HW L2 Table (MPFS) management */
241 static int set_l2_table_entry_cmd(struct mlx5_core_dev
*dev
, u32 index
,
242 u8
*mac
, u8 vlan_valid
, u16 vlan
)
244 u32 in
[MLX5_ST_SZ_DW(set_l2_table_entry_in
)];
245 u32 out
[MLX5_ST_SZ_DW(set_l2_table_entry_out
)];
248 memset(in
, 0, sizeof(in
));
249 memset(out
, 0, sizeof(out
));
251 MLX5_SET(set_l2_table_entry_in
, in
, opcode
,
252 MLX5_CMD_OP_SET_L2_TABLE_ENTRY
);
253 MLX5_SET(set_l2_table_entry_in
, in
, table_index
, index
);
254 MLX5_SET(set_l2_table_entry_in
, in
, vlan_valid
, vlan_valid
);
255 MLX5_SET(set_l2_table_entry_in
, in
, vlan
, vlan
);
257 in_mac_addr
= MLX5_ADDR_OF(set_l2_table_entry_in
, in
, mac_address
);
258 ether_addr_copy(&in_mac_addr
[2], mac
);
260 return mlx5_cmd_exec_check_status(dev
, in
, sizeof(in
),
264 static int del_l2_table_entry_cmd(struct mlx5_core_dev
*dev
, u32 index
)
266 u32 in
[MLX5_ST_SZ_DW(delete_l2_table_entry_in
)];
267 u32 out
[MLX5_ST_SZ_DW(delete_l2_table_entry_out
)];
269 memset(in
, 0, sizeof(in
));
270 memset(out
, 0, sizeof(out
));
272 MLX5_SET(delete_l2_table_entry_in
, in
, opcode
,
273 MLX5_CMD_OP_DELETE_L2_TABLE_ENTRY
);
274 MLX5_SET(delete_l2_table_entry_in
, in
, table_index
, index
);
275 return mlx5_cmd_exec_check_status(dev
, in
, sizeof(in
),
279 static int alloc_l2_table_index(struct mlx5_l2_table
*l2_table
, u32
*ix
)
283 *ix
= find_first_zero_bit(l2_table
->bitmap
, l2_table
->size
);
284 if (*ix
>= l2_table
->size
)
287 __set_bit(*ix
, l2_table
->bitmap
);
292 static void free_l2_table_index(struct mlx5_l2_table
*l2_table
, u32 ix
)
294 __clear_bit(ix
, l2_table
->bitmap
);
297 static int set_l2_table_entry(struct mlx5_core_dev
*dev
, u8
*mac
,
298 u8 vlan_valid
, u16 vlan
,
301 struct mlx5_l2_table
*l2_table
= &dev
->priv
.eswitch
->l2_table
;
304 err
= alloc_l2_table_index(l2_table
, index
);
308 err
= set_l2_table_entry_cmd(dev
, *index
, mac
, vlan_valid
, vlan
);
310 free_l2_table_index(l2_table
, *index
);
315 static void del_l2_table_entry(struct mlx5_core_dev
*dev
, u32 index
)
317 struct mlx5_l2_table
*l2_table
= &dev
->priv
.eswitch
->l2_table
;
319 del_l2_table_entry_cmd(dev
, index
);
320 free_l2_table_index(l2_table
, index
);
324 static struct mlx5_flow_rule
*
325 __esw_fdb_set_vport_rule(struct mlx5_eswitch
*esw
, u32 vport
, bool rx_rule
,
326 u8 mac_c
[ETH_ALEN
], u8 mac_v
[ETH_ALEN
])
328 int match_header
= (is_zero_ether_addr(mac_c
) ? 0 :
329 MLX5_MATCH_OUTER_HEADERS
);
330 struct mlx5_flow_rule
*flow_rule
= NULL
;
331 struct mlx5_flow_destination dest
;
332 void *mv_misc
= NULL
;
333 void *mc_misc
= NULL
;
340 match_header
|= MLX5_MATCH_MISC_PARAMETERS
;
341 match_v
= kzalloc(MLX5_ST_SZ_BYTES(fte_match_param
), GFP_KERNEL
);
342 match_c
= kzalloc(MLX5_ST_SZ_BYTES(fte_match_param
), GFP_KERNEL
);
343 if (!match_v
|| !match_c
) {
344 pr_warn("FDB: Failed to alloc match parameters\n");
348 dmac_v
= MLX5_ADDR_OF(fte_match_param
, match_v
,
349 outer_headers
.dmac_47_16
);
350 dmac_c
= MLX5_ADDR_OF(fte_match_param
, match_c
,
351 outer_headers
.dmac_47_16
);
353 if (match_header
& MLX5_MATCH_OUTER_HEADERS
) {
354 ether_addr_copy(dmac_v
, mac_v
);
355 ether_addr_copy(dmac_c
, mac_c
);
358 if (match_header
& MLX5_MATCH_MISC_PARAMETERS
) {
359 mv_misc
= MLX5_ADDR_OF(fte_match_param
, match_v
, misc_parameters
);
360 mc_misc
= MLX5_ADDR_OF(fte_match_param
, match_c
, misc_parameters
);
361 MLX5_SET(fte_match_set_misc
, mv_misc
, source_port
, UPLINK_VPORT
);
362 MLX5_SET_TO_ONES(fte_match_set_misc
, mc_misc
, source_port
);
365 dest
.type
= MLX5_FLOW_DESTINATION_TYPE_VPORT
;
366 dest
.vport_num
= vport
;
369 "\tFDB add rule dmac_v(%pM) dmac_c(%pM) -> vport(%d)\n",
370 dmac_v
, dmac_c
, vport
);
372 mlx5_add_flow_rule(esw
->fdb_table
.fdb
,
376 MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
,
378 if (IS_ERR(flow_rule
)) {
380 "FDB: Failed to add flow rule: dmac_v(%pM) dmac_c(%pM) -> vport(%d), err(%ld)\n",
381 dmac_v
, dmac_c
, vport
, PTR_ERR(flow_rule
));
390 static struct mlx5_flow_rule
*
391 esw_fdb_set_vport_rule(struct mlx5_eswitch
*esw
, u8 mac
[ETH_ALEN
], u32 vport
)
395 eth_broadcast_addr(mac_c
);
396 return __esw_fdb_set_vport_rule(esw
, vport
, false, mac_c
, mac
);
399 static struct mlx5_flow_rule
*
400 esw_fdb_set_vport_allmulti_rule(struct mlx5_eswitch
*esw
, u32 vport
)
405 eth_zero_addr(mac_c
);
406 eth_zero_addr(mac_v
);
409 return __esw_fdb_set_vport_rule(esw
, vport
, false, mac_c
, mac_v
);
412 static struct mlx5_flow_rule
*
413 esw_fdb_set_vport_promisc_rule(struct mlx5_eswitch
*esw
, u32 vport
)
418 eth_zero_addr(mac_c
);
419 eth_zero_addr(mac_v
);
420 return __esw_fdb_set_vport_rule(esw
, vport
, true, mac_c
, mac_v
);
423 static int esw_create_legacy_fdb_table(struct mlx5_eswitch
*esw
, int nvports
)
425 int inlen
= MLX5_ST_SZ_BYTES(create_flow_group_in
);
426 struct mlx5_core_dev
*dev
= esw
->dev
;
427 struct mlx5_flow_namespace
*root_ns
;
428 struct mlx5_flow_table
*fdb
;
429 struct mlx5_flow_group
*g
;
430 void *match_criteria
;
436 esw_debug(dev
, "Create FDB log_max_size(%d)\n",
437 MLX5_CAP_ESW_FLOWTABLE_FDB(dev
, log_max_ft_size
));
439 root_ns
= mlx5_get_flow_namespace(dev
, MLX5_FLOW_NAMESPACE_FDB
);
441 esw_warn(dev
, "Failed to get FDB flow namespace\n");
445 flow_group_in
= mlx5_vzalloc(inlen
);
448 memset(flow_group_in
, 0, inlen
);
450 table_size
= BIT(MLX5_CAP_ESW_FLOWTABLE_FDB(dev
, log_max_ft_size
));
451 fdb
= mlx5_create_flow_table(root_ns
, 0, table_size
, 0);
454 esw_warn(dev
, "Failed to create FDB Table err %d\n", err
);
457 esw
->fdb_table
.fdb
= fdb
;
459 /* Addresses group : Full match unicast/multicast addresses */
460 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
,
461 MLX5_MATCH_OUTER_HEADERS
);
462 match_criteria
= MLX5_ADDR_OF(create_flow_group_in
, flow_group_in
, match_criteria
);
463 dmac
= MLX5_ADDR_OF(fte_match_param
, match_criteria
, outer_headers
.dmac_47_16
);
464 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 0);
465 /* Preserve 2 entries for allmulti and promisc rules*/
466 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, table_size
- 3);
467 eth_broadcast_addr(dmac
);
468 g
= mlx5_create_flow_group(fdb
, flow_group_in
);
471 esw_warn(dev
, "Failed to create flow group err(%d)\n", err
);
474 esw
->fdb_table
.legacy
.addr_grp
= g
;
476 /* Allmulti group : One rule that forwards any mcast traffic */
477 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
,
478 MLX5_MATCH_OUTER_HEADERS
);
479 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, table_size
- 2);
480 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, table_size
- 2);
483 g
= mlx5_create_flow_group(fdb
, flow_group_in
);
486 esw_warn(dev
, "Failed to create allmulti flow group err(%d)\n", err
);
489 esw
->fdb_table
.legacy
.allmulti_grp
= g
;
491 /* Promiscuous group :
492 * One rule that forward all unmatched traffic from previous groups
495 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
,
496 MLX5_MATCH_MISC_PARAMETERS
);
497 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, misc_parameters
.source_port
);
498 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, table_size
- 1);
499 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, table_size
- 1);
500 g
= mlx5_create_flow_group(fdb
, flow_group_in
);
503 esw_warn(dev
, "Failed to create promisc flow group err(%d)\n", err
);
506 esw
->fdb_table
.legacy
.promisc_grp
= g
;
510 if (!IS_ERR_OR_NULL(esw
->fdb_table
.legacy
.allmulti_grp
)) {
511 mlx5_destroy_flow_group(esw
->fdb_table
.legacy
.allmulti_grp
);
512 esw
->fdb_table
.legacy
.allmulti_grp
= NULL
;
514 if (!IS_ERR_OR_NULL(esw
->fdb_table
.legacy
.addr_grp
)) {
515 mlx5_destroy_flow_group(esw
->fdb_table
.legacy
.addr_grp
);
516 esw
->fdb_table
.legacy
.addr_grp
= NULL
;
518 if (!IS_ERR_OR_NULL(esw
->fdb_table
.fdb
)) {
519 mlx5_destroy_flow_table(esw
->fdb_table
.fdb
);
520 esw
->fdb_table
.fdb
= NULL
;
524 kvfree(flow_group_in
);
528 static void esw_destroy_legacy_fdb_table(struct mlx5_eswitch
*esw
)
530 if (!esw
->fdb_table
.fdb
)
533 esw_debug(esw
->dev
, "Destroy FDB Table\n");
534 mlx5_destroy_flow_group(esw
->fdb_table
.legacy
.promisc_grp
);
535 mlx5_destroy_flow_group(esw
->fdb_table
.legacy
.allmulti_grp
);
536 mlx5_destroy_flow_group(esw
->fdb_table
.legacy
.addr_grp
);
537 mlx5_destroy_flow_table(esw
->fdb_table
.fdb
);
538 esw
->fdb_table
.fdb
= NULL
;
539 esw
->fdb_table
.legacy
.addr_grp
= NULL
;
540 esw
->fdb_table
.legacy
.allmulti_grp
= NULL
;
541 esw
->fdb_table
.legacy
.promisc_grp
= NULL
;
544 /* E-Switch vport UC/MC lists management */
545 typedef int (*vport_addr_action
)(struct mlx5_eswitch
*esw
,
546 struct vport_addr
*vaddr
);
548 static int esw_add_uc_addr(struct mlx5_eswitch
*esw
, struct vport_addr
*vaddr
)
550 struct hlist_head
*hash
= esw
->l2_table
.l2_hash
;
551 struct esw_uc_addr
*esw_uc
;
552 u8
*mac
= vaddr
->node
.addr
;
553 u32 vport
= vaddr
->vport
;
556 esw_uc
= l2addr_hash_find(hash
, mac
, struct esw_uc_addr
);
559 "Failed to set L2 mac(%pM) for vport(%d), mac is already in use by vport(%d)\n",
560 mac
, vport
, esw_uc
->vport
);
564 esw_uc
= l2addr_hash_add(hash
, mac
, struct esw_uc_addr
, GFP_KERNEL
);
567 esw_uc
->vport
= vport
;
569 err
= set_l2_table_entry(esw
->dev
, mac
, 0, 0, &esw_uc
->table_index
);
573 /* SRIOV is enabled: Forward UC MAC to vport */
574 if (esw
->fdb_table
.fdb
&& esw
->mode
== SRIOV_LEGACY
)
575 vaddr
->flow_rule
= esw_fdb_set_vport_rule(esw
, mac
, vport
);
577 esw_debug(esw
->dev
, "\tADDED UC MAC: vport[%d] %pM index:%d fr(%p)\n",
578 vport
, mac
, esw_uc
->table_index
, vaddr
->flow_rule
);
581 l2addr_hash_del(esw_uc
);
585 static int esw_del_uc_addr(struct mlx5_eswitch
*esw
, struct vport_addr
*vaddr
)
587 struct hlist_head
*hash
= esw
->l2_table
.l2_hash
;
588 struct esw_uc_addr
*esw_uc
;
589 u8
*mac
= vaddr
->node
.addr
;
590 u32 vport
= vaddr
->vport
;
592 esw_uc
= l2addr_hash_find(hash
, mac
, struct esw_uc_addr
);
593 if (!esw_uc
|| esw_uc
->vport
!= vport
) {
595 "MAC(%pM) doesn't belong to vport (%d)\n",
599 esw_debug(esw
->dev
, "\tDELETE UC MAC: vport[%d] %pM index:%d fr(%p)\n",
600 vport
, mac
, esw_uc
->table_index
, vaddr
->flow_rule
);
602 del_l2_table_entry(esw
->dev
, esw_uc
->table_index
);
604 if (vaddr
->flow_rule
)
605 mlx5_del_flow_rule(vaddr
->flow_rule
);
606 vaddr
->flow_rule
= NULL
;
608 l2addr_hash_del(esw_uc
);
612 static void update_allmulti_vports(struct mlx5_eswitch
*esw
,
613 struct vport_addr
*vaddr
,
614 struct esw_mc_addr
*esw_mc
)
616 u8
*mac
= vaddr
->node
.addr
;
619 for (vport_idx
= 0; vport_idx
< esw
->total_vports
; vport_idx
++) {
620 struct mlx5_vport
*vport
= &esw
->vports
[vport_idx
];
621 struct hlist_head
*vport_hash
= vport
->mc_list
;
622 struct vport_addr
*iter_vaddr
=
623 l2addr_hash_find(vport_hash
,
626 if (IS_ERR_OR_NULL(vport
->allmulti_rule
) ||
627 vaddr
->vport
== vport_idx
)
629 switch (vaddr
->action
) {
630 case MLX5_ACTION_ADD
:
633 iter_vaddr
= l2addr_hash_add(vport_hash
, mac
,
638 "ALL-MULTI: Failed to add MAC(%pM) to vport[%d] DB\n",
642 iter_vaddr
->vport
= vport_idx
;
643 iter_vaddr
->flow_rule
=
644 esw_fdb_set_vport_rule(esw
,
647 iter_vaddr
->mc_promisc
= true;
649 case MLX5_ACTION_DEL
:
652 mlx5_del_flow_rule(iter_vaddr
->flow_rule
);
653 l2addr_hash_del(iter_vaddr
);
659 static int esw_add_mc_addr(struct mlx5_eswitch
*esw
, struct vport_addr
*vaddr
)
661 struct hlist_head
*hash
= esw
->mc_table
;
662 struct esw_mc_addr
*esw_mc
;
663 u8
*mac
= vaddr
->node
.addr
;
664 u32 vport
= vaddr
->vport
;
666 if (!esw
->fdb_table
.fdb
)
669 esw_mc
= l2addr_hash_find(hash
, mac
, struct esw_mc_addr
);
673 esw_mc
= l2addr_hash_add(hash
, mac
, struct esw_mc_addr
, GFP_KERNEL
);
677 esw_mc
->uplink_rule
= /* Forward MC MAC to Uplink */
678 esw_fdb_set_vport_rule(esw
, mac
, UPLINK_VPORT
);
680 /* Add this multicast mac to all the mc promiscuous vports */
681 update_allmulti_vports(esw
, vaddr
, esw_mc
);
684 /* If the multicast mac is added as a result of mc promiscuous vport,
685 * don't increment the multicast ref count
687 if (!vaddr
->mc_promisc
)
690 /* Forward MC MAC to vport */
691 vaddr
->flow_rule
= esw_fdb_set_vport_rule(esw
, mac
, vport
);
693 "\tADDED MC MAC: vport[%d] %pM fr(%p) refcnt(%d) uplinkfr(%p)\n",
694 vport
, mac
, vaddr
->flow_rule
,
695 esw_mc
->refcnt
, esw_mc
->uplink_rule
);
699 static int esw_del_mc_addr(struct mlx5_eswitch
*esw
, struct vport_addr
*vaddr
)
701 struct hlist_head
*hash
= esw
->mc_table
;
702 struct esw_mc_addr
*esw_mc
;
703 u8
*mac
= vaddr
->node
.addr
;
704 u32 vport
= vaddr
->vport
;
706 if (!esw
->fdb_table
.fdb
)
709 esw_mc
= l2addr_hash_find(hash
, mac
, struct esw_mc_addr
);
712 "Failed to find eswitch MC addr for MAC(%pM) vport(%d)",
717 "\tDELETE MC MAC: vport[%d] %pM fr(%p) refcnt(%d) uplinkfr(%p)\n",
718 vport
, mac
, vaddr
->flow_rule
, esw_mc
->refcnt
,
719 esw_mc
->uplink_rule
);
721 if (vaddr
->flow_rule
)
722 mlx5_del_flow_rule(vaddr
->flow_rule
);
723 vaddr
->flow_rule
= NULL
;
725 /* If the multicast mac is added as a result of mc promiscuous vport,
726 * don't decrement the multicast ref count.
728 if (vaddr
->mc_promisc
|| (--esw_mc
->refcnt
> 0))
731 /* Remove this multicast mac from all the mc promiscuous vports */
732 update_allmulti_vports(esw
, vaddr
, esw_mc
);
734 if (esw_mc
->uplink_rule
)
735 mlx5_del_flow_rule(esw_mc
->uplink_rule
);
737 l2addr_hash_del(esw_mc
);
741 /* Apply vport UC/MC list to HW l2 table and FDB table */
742 static void esw_apply_vport_addr_list(struct mlx5_eswitch
*esw
,
743 u32 vport_num
, int list_type
)
745 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
746 bool is_uc
= list_type
== MLX5_NVPRT_LIST_TYPE_UC
;
747 vport_addr_action vport_addr_add
;
748 vport_addr_action vport_addr_del
;
749 struct vport_addr
*addr
;
750 struct l2addr_node
*node
;
751 struct hlist_head
*hash
;
752 struct hlist_node
*tmp
;
755 vport_addr_add
= is_uc
? esw_add_uc_addr
:
757 vport_addr_del
= is_uc
? esw_del_uc_addr
:
760 hash
= is_uc
? vport
->uc_list
: vport
->mc_list
;
761 for_each_l2hash_node(node
, tmp
, hash
, hi
) {
762 addr
= container_of(node
, struct vport_addr
, node
);
763 switch (addr
->action
) {
764 case MLX5_ACTION_ADD
:
765 vport_addr_add(esw
, addr
);
766 addr
->action
= MLX5_ACTION_NONE
;
768 case MLX5_ACTION_DEL
:
769 vport_addr_del(esw
, addr
);
770 l2addr_hash_del(addr
);
776 /* Sync vport UC/MC list from vport context */
777 static void esw_update_vport_addr_list(struct mlx5_eswitch
*esw
,
778 u32 vport_num
, int list_type
)
780 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
781 bool is_uc
= list_type
== MLX5_NVPRT_LIST_TYPE_UC
;
782 u8 (*mac_list
)[ETH_ALEN
];
783 struct l2addr_node
*node
;
784 struct vport_addr
*addr
;
785 struct hlist_head
*hash
;
786 struct hlist_node
*tmp
;
792 size
= is_uc
? MLX5_MAX_UC_PER_VPORT(esw
->dev
) :
793 MLX5_MAX_MC_PER_VPORT(esw
->dev
);
795 mac_list
= kcalloc(size
, ETH_ALEN
, GFP_KERNEL
);
799 hash
= is_uc
? vport
->uc_list
: vport
->mc_list
;
801 for_each_l2hash_node(node
, tmp
, hash
, hi
) {
802 addr
= container_of(node
, struct vport_addr
, node
);
803 addr
->action
= MLX5_ACTION_DEL
;
809 err
= mlx5_query_nic_vport_mac_list(esw
->dev
, vport_num
, list_type
,
813 esw_debug(esw
->dev
, "vport[%d] context update %s list size (%d)\n",
814 vport_num
, is_uc
? "UC" : "MC", size
);
816 for (i
= 0; i
< size
; i
++) {
817 if (is_uc
&& !is_valid_ether_addr(mac_list
[i
]))
820 if (!is_uc
&& !is_multicast_ether_addr(mac_list
[i
]))
823 addr
= l2addr_hash_find(hash
, mac_list
[i
], struct vport_addr
);
825 addr
->action
= MLX5_ACTION_NONE
;
826 /* If this mac was previously added because of allmulti
827 * promiscuous rx mode, its now converted to be original
830 if (addr
->mc_promisc
) {
831 struct esw_mc_addr
*esw_mc
=
832 l2addr_hash_find(esw
->mc_table
,
837 "Failed to MAC(%pM) in mcast DB\n",
842 addr
->mc_promisc
= false;
847 addr
= l2addr_hash_add(hash
, mac_list
[i
], struct vport_addr
,
851 "Failed to add MAC(%pM) to vport[%d] DB\n",
852 mac_list
[i
], vport_num
);
855 addr
->vport
= vport_num
;
856 addr
->action
= MLX5_ACTION_ADD
;
862 /* Sync vport UC/MC list from vport context
863 * Must be called after esw_update_vport_addr_list
865 static void esw_update_vport_mc_promisc(struct mlx5_eswitch
*esw
, u32 vport_num
)
867 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
868 struct l2addr_node
*node
;
869 struct vport_addr
*addr
;
870 struct hlist_head
*hash
;
871 struct hlist_node
*tmp
;
874 hash
= vport
->mc_list
;
876 for_each_l2hash_node(node
, tmp
, esw
->mc_table
, hi
) {
877 u8
*mac
= node
->addr
;
879 addr
= l2addr_hash_find(hash
, mac
, struct vport_addr
);
881 if (addr
->action
== MLX5_ACTION_DEL
)
882 addr
->action
= MLX5_ACTION_NONE
;
885 addr
= l2addr_hash_add(hash
, mac
, struct vport_addr
,
889 "Failed to add allmulti MAC(%pM) to vport[%d] DB\n",
893 addr
->vport
= vport_num
;
894 addr
->action
= MLX5_ACTION_ADD
;
895 addr
->mc_promisc
= true;
899 /* Apply vport rx mode to HW FDB table */
900 static void esw_apply_vport_rx_mode(struct mlx5_eswitch
*esw
, u32 vport_num
,
901 bool promisc
, bool mc_promisc
)
903 struct esw_mc_addr
*allmulti_addr
= esw
->mc_promisc
;
904 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
906 if (IS_ERR_OR_NULL(vport
->allmulti_rule
) != mc_promisc
)
910 vport
->allmulti_rule
=
911 esw_fdb_set_vport_allmulti_rule(esw
, vport_num
);
912 if (!allmulti_addr
->uplink_rule
)
913 allmulti_addr
->uplink_rule
=
914 esw_fdb_set_vport_allmulti_rule(esw
,
916 allmulti_addr
->refcnt
++;
917 } else if (vport
->allmulti_rule
) {
918 mlx5_del_flow_rule(vport
->allmulti_rule
);
919 vport
->allmulti_rule
= NULL
;
921 if (--allmulti_addr
->refcnt
> 0)
924 if (allmulti_addr
->uplink_rule
)
925 mlx5_del_flow_rule(allmulti_addr
->uplink_rule
);
926 allmulti_addr
->uplink_rule
= NULL
;
930 if (IS_ERR_OR_NULL(vport
->promisc_rule
) != promisc
)
934 vport
->promisc_rule
= esw_fdb_set_vport_promisc_rule(esw
,
936 } else if (vport
->promisc_rule
) {
937 mlx5_del_flow_rule(vport
->promisc_rule
);
938 vport
->promisc_rule
= NULL
;
942 /* Sync vport rx mode from vport context */
943 static void esw_update_vport_rx_mode(struct mlx5_eswitch
*esw
, u32 vport_num
)
945 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
951 err
= mlx5_query_nic_vport_promisc(esw
->dev
,
958 esw_debug(esw
->dev
, "vport[%d] context update rx mode promisc_all=%d, all_multi=%d\n",
959 vport_num
, promisc_all
, promisc_mc
);
961 if (!vport
->trusted
|| !vport
->enabled
) {
967 esw_apply_vport_rx_mode(esw
, vport_num
, promisc_all
,
968 (promisc_all
|| promisc_mc
));
971 static void esw_vport_change_handle_locked(struct mlx5_vport
*vport
)
973 struct mlx5_core_dev
*dev
= vport
->dev
;
974 struct mlx5_eswitch
*esw
= dev
->priv
.eswitch
;
977 mlx5_query_nic_vport_mac_address(dev
, vport
->vport
, mac
);
978 esw_debug(dev
, "vport[%d] Context Changed: perm mac: %pM\n",
981 if (vport
->enabled_events
& UC_ADDR_CHANGE
) {
982 esw_update_vport_addr_list(esw
, vport
->vport
,
983 MLX5_NVPRT_LIST_TYPE_UC
);
984 esw_apply_vport_addr_list(esw
, vport
->vport
,
985 MLX5_NVPRT_LIST_TYPE_UC
);
988 if (vport
->enabled_events
& MC_ADDR_CHANGE
) {
989 esw_update_vport_addr_list(esw
, vport
->vport
,
990 MLX5_NVPRT_LIST_TYPE_MC
);
993 if (vport
->enabled_events
& PROMISC_CHANGE
) {
994 esw_update_vport_rx_mode(esw
, vport
->vport
);
995 if (!IS_ERR_OR_NULL(vport
->allmulti_rule
))
996 esw_update_vport_mc_promisc(esw
, vport
->vport
);
999 if (vport
->enabled_events
& (PROMISC_CHANGE
| MC_ADDR_CHANGE
)) {
1000 esw_apply_vport_addr_list(esw
, vport
->vport
,
1001 MLX5_NVPRT_LIST_TYPE_MC
);
1004 esw_debug(esw
->dev
, "vport[%d] Context Changed: Done\n", vport
->vport
);
1006 arm_vport_context_events_cmd(dev
, vport
->vport
,
1007 vport
->enabled_events
);
1010 static void esw_vport_change_handler(struct work_struct
*work
)
1012 struct mlx5_vport
*vport
=
1013 container_of(work
, struct mlx5_vport
, vport_change_handler
);
1014 struct mlx5_eswitch
*esw
= vport
->dev
->priv
.eswitch
;
1016 mutex_lock(&esw
->state_lock
);
1017 esw_vport_change_handle_locked(vport
);
1018 mutex_unlock(&esw
->state_lock
);
1021 static void esw_vport_enable_egress_acl(struct mlx5_eswitch
*esw
,
1022 struct mlx5_vport
*vport
)
1024 int inlen
= MLX5_ST_SZ_BYTES(create_flow_group_in
);
1025 struct mlx5_flow_group
*vlan_grp
= NULL
;
1026 struct mlx5_flow_group
*drop_grp
= NULL
;
1027 struct mlx5_core_dev
*dev
= esw
->dev
;
1028 struct mlx5_flow_namespace
*root_ns
;
1029 struct mlx5_flow_table
*acl
;
1030 void *match_criteria
;
1032 /* The egress acl table contains 2 rules:
1033 * 1)Allow traffic with vlan_tag=vst_vlan_id
1034 * 2)Drop all other traffic.
1039 if (!MLX5_CAP_ESW_EGRESS_ACL(dev
, ft_support
) ||
1040 !IS_ERR_OR_NULL(vport
->egress
.acl
))
1043 esw_debug(dev
, "Create vport[%d] egress ACL log_max_size(%d)\n",
1044 vport
->vport
, MLX5_CAP_ESW_EGRESS_ACL(dev
, log_max_ft_size
));
1046 root_ns
= mlx5_get_flow_namespace(dev
, MLX5_FLOW_NAMESPACE_ESW_EGRESS
);
1048 esw_warn(dev
, "Failed to get E-Switch egress flow namespace\n");
1052 flow_group_in
= mlx5_vzalloc(inlen
);
1056 acl
= mlx5_create_vport_flow_table(root_ns
, 0, table_size
, 0, vport
->vport
);
1059 esw_warn(dev
, "Failed to create E-Switch vport[%d] egress flow Table, err(%d)\n",
1064 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
, MLX5_MATCH_OUTER_HEADERS
);
1065 match_criteria
= MLX5_ADDR_OF(create_flow_group_in
, flow_group_in
, match_criteria
);
1066 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.vlan_tag
);
1067 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.first_vid
);
1068 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 0);
1069 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, 0);
1071 vlan_grp
= mlx5_create_flow_group(acl
, flow_group_in
);
1072 if (IS_ERR(vlan_grp
)) {
1073 err
= PTR_ERR(vlan_grp
);
1074 esw_warn(dev
, "Failed to create E-Switch vport[%d] egress allowed vlans flow group, err(%d)\n",
1079 memset(flow_group_in
, 0, inlen
);
1080 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 1);
1081 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, 1);
1082 drop_grp
= mlx5_create_flow_group(acl
, flow_group_in
);
1083 if (IS_ERR(drop_grp
)) {
1084 err
= PTR_ERR(drop_grp
);
1085 esw_warn(dev
, "Failed to create E-Switch vport[%d] egress drop flow group, err(%d)\n",
1090 vport
->egress
.acl
= acl
;
1091 vport
->egress
.drop_grp
= drop_grp
;
1092 vport
->egress
.allowed_vlans_grp
= vlan_grp
;
1094 kvfree(flow_group_in
);
1095 if (err
&& !IS_ERR_OR_NULL(vlan_grp
))
1096 mlx5_destroy_flow_group(vlan_grp
);
1097 if (err
&& !IS_ERR_OR_NULL(acl
))
1098 mlx5_destroy_flow_table(acl
);
1101 static void esw_vport_cleanup_egress_rules(struct mlx5_eswitch
*esw
,
1102 struct mlx5_vport
*vport
)
1104 if (!IS_ERR_OR_NULL(vport
->egress
.allowed_vlan
))
1105 mlx5_del_flow_rule(vport
->egress
.allowed_vlan
);
1107 if (!IS_ERR_OR_NULL(vport
->egress
.drop_rule
))
1108 mlx5_del_flow_rule(vport
->egress
.drop_rule
);
1110 vport
->egress
.allowed_vlan
= NULL
;
1111 vport
->egress
.drop_rule
= NULL
;
1114 static void esw_vport_disable_egress_acl(struct mlx5_eswitch
*esw
,
1115 struct mlx5_vport
*vport
)
1117 if (IS_ERR_OR_NULL(vport
->egress
.acl
))
1120 esw_debug(esw
->dev
, "Destroy vport[%d] E-Switch egress ACL\n", vport
->vport
);
1122 esw_vport_cleanup_egress_rules(esw
, vport
);
1123 mlx5_destroy_flow_group(vport
->egress
.allowed_vlans_grp
);
1124 mlx5_destroy_flow_group(vport
->egress
.drop_grp
);
1125 mlx5_destroy_flow_table(vport
->egress
.acl
);
1126 vport
->egress
.allowed_vlans_grp
= NULL
;
1127 vport
->egress
.drop_grp
= NULL
;
1128 vport
->egress
.acl
= NULL
;
1131 static void esw_vport_enable_ingress_acl(struct mlx5_eswitch
*esw
,
1132 struct mlx5_vport
*vport
)
1134 int inlen
= MLX5_ST_SZ_BYTES(create_flow_group_in
);
1135 struct mlx5_core_dev
*dev
= esw
->dev
;
1136 struct mlx5_flow_namespace
*root_ns
;
1137 struct mlx5_flow_table
*acl
;
1138 struct mlx5_flow_group
*g
;
1139 void *match_criteria
;
1141 /* The ingress acl table contains 4 groups
1142 * (2 active rules at the same time -
1143 * 1 allow rule from one of the first 3 groups.
1144 * 1 drop rule from the last group):
1145 * 1)Allow untagged traffic with smac=original mac.
1146 * 2)Allow untagged traffic.
1147 * 3)Allow traffic with smac=original mac.
1148 * 4)Drop all other traffic.
1153 if (!MLX5_CAP_ESW_INGRESS_ACL(dev
, ft_support
) ||
1154 !IS_ERR_OR_NULL(vport
->ingress
.acl
))
1157 esw_debug(dev
, "Create vport[%d] ingress ACL log_max_size(%d)\n",
1158 vport
->vport
, MLX5_CAP_ESW_INGRESS_ACL(dev
, log_max_ft_size
));
1160 root_ns
= mlx5_get_flow_namespace(dev
, MLX5_FLOW_NAMESPACE_ESW_INGRESS
);
1162 esw_warn(dev
, "Failed to get E-Switch ingress flow namespace\n");
1166 flow_group_in
= mlx5_vzalloc(inlen
);
1170 acl
= mlx5_create_vport_flow_table(root_ns
, 0, table_size
, 0, vport
->vport
);
1173 esw_warn(dev
, "Failed to create E-Switch vport[%d] ingress flow Table, err(%d)\n",
1177 vport
->ingress
.acl
= acl
;
1179 match_criteria
= MLX5_ADDR_OF(create_flow_group_in
, flow_group_in
, match_criteria
);
1181 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
, MLX5_MATCH_OUTER_HEADERS
);
1182 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.vlan_tag
);
1183 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.smac_47_16
);
1184 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.smac_15_0
);
1185 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 0);
1186 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, 0);
1188 g
= mlx5_create_flow_group(acl
, flow_group_in
);
1191 esw_warn(dev
, "Failed to create E-Switch vport[%d] ingress untagged spoofchk flow group, err(%d)\n",
1195 vport
->ingress
.allow_untagged_spoofchk_grp
= g
;
1197 memset(flow_group_in
, 0, inlen
);
1198 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
, MLX5_MATCH_OUTER_HEADERS
);
1199 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.vlan_tag
);
1200 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 1);
1201 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, 1);
1203 g
= mlx5_create_flow_group(acl
, flow_group_in
);
1206 esw_warn(dev
, "Failed to create E-Switch vport[%d] ingress untagged flow group, err(%d)\n",
1210 vport
->ingress
.allow_untagged_only_grp
= g
;
1212 memset(flow_group_in
, 0, inlen
);
1213 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
, MLX5_MATCH_OUTER_HEADERS
);
1214 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.smac_47_16
);
1215 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, outer_headers
.smac_15_0
);
1216 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 2);
1217 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, 2);
1219 g
= mlx5_create_flow_group(acl
, flow_group_in
);
1222 esw_warn(dev
, "Failed to create E-Switch vport[%d] ingress spoofchk flow group, err(%d)\n",
1226 vport
->ingress
.allow_spoofchk_only_grp
= g
;
1228 memset(flow_group_in
, 0, inlen
);
1229 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 3);
1230 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, 3);
1232 g
= mlx5_create_flow_group(acl
, flow_group_in
);
1235 esw_warn(dev
, "Failed to create E-Switch vport[%d] ingress drop flow group, err(%d)\n",
1239 vport
->ingress
.drop_grp
= g
;
1243 if (!IS_ERR_OR_NULL(vport
->ingress
.allow_spoofchk_only_grp
))
1244 mlx5_destroy_flow_group(
1245 vport
->ingress
.allow_spoofchk_only_grp
);
1246 if (!IS_ERR_OR_NULL(vport
->ingress
.allow_untagged_only_grp
))
1247 mlx5_destroy_flow_group(
1248 vport
->ingress
.allow_untagged_only_grp
);
1249 if (!IS_ERR_OR_NULL(vport
->ingress
.allow_untagged_spoofchk_grp
))
1250 mlx5_destroy_flow_group(
1251 vport
->ingress
.allow_untagged_spoofchk_grp
);
1252 if (!IS_ERR_OR_NULL(vport
->ingress
.acl
))
1253 mlx5_destroy_flow_table(vport
->ingress
.acl
);
1256 kvfree(flow_group_in
);
1259 static void esw_vport_cleanup_ingress_rules(struct mlx5_eswitch
*esw
,
1260 struct mlx5_vport
*vport
)
1262 if (!IS_ERR_OR_NULL(vport
->ingress
.drop_rule
))
1263 mlx5_del_flow_rule(vport
->ingress
.drop_rule
);
1265 if (!IS_ERR_OR_NULL(vport
->ingress
.allow_rule
))
1266 mlx5_del_flow_rule(vport
->ingress
.allow_rule
);
1268 vport
->ingress
.drop_rule
= NULL
;
1269 vport
->ingress
.allow_rule
= NULL
;
1272 static void esw_vport_disable_ingress_acl(struct mlx5_eswitch
*esw
,
1273 struct mlx5_vport
*vport
)
1275 if (IS_ERR_OR_NULL(vport
->ingress
.acl
))
1278 esw_debug(esw
->dev
, "Destroy vport[%d] E-Switch ingress ACL\n", vport
->vport
);
1280 esw_vport_cleanup_ingress_rules(esw
, vport
);
1281 mlx5_destroy_flow_group(vport
->ingress
.allow_spoofchk_only_grp
);
1282 mlx5_destroy_flow_group(vport
->ingress
.allow_untagged_only_grp
);
1283 mlx5_destroy_flow_group(vport
->ingress
.allow_untagged_spoofchk_grp
);
1284 mlx5_destroy_flow_group(vport
->ingress
.drop_grp
);
1285 mlx5_destroy_flow_table(vport
->ingress
.acl
);
1286 vport
->ingress
.acl
= NULL
;
1287 vport
->ingress
.drop_grp
= NULL
;
1288 vport
->ingress
.allow_spoofchk_only_grp
= NULL
;
1289 vport
->ingress
.allow_untagged_only_grp
= NULL
;
1290 vport
->ingress
.allow_untagged_spoofchk_grp
= NULL
;
1293 static int esw_vport_ingress_config(struct mlx5_eswitch
*esw
,
1294 struct mlx5_vport
*vport
)
1302 if (vport
->spoofchk
) {
1303 err
= mlx5_query_nic_vport_mac_address(esw
->dev
, vport
->vport
, smac
);
1306 "vport[%d] configure ingress rules failed, query smac failed, err(%d)\n",
1311 if (!is_valid_ether_addr(smac
)) {
1312 mlx5_core_warn(esw
->dev
,
1313 "vport[%d] configure ingress rules failed, illegal mac with spoofchk\n",
1319 esw_vport_cleanup_ingress_rules(esw
, vport
);
1321 if (!vport
->vlan
&& !vport
->qos
&& !vport
->spoofchk
) {
1322 esw_vport_disable_ingress_acl(esw
, vport
);
1326 esw_vport_enable_ingress_acl(esw
, vport
);
1329 "vport[%d] configure ingress rules, vlan(%d) qos(%d)\n",
1330 vport
->vport
, vport
->vlan
, vport
->qos
);
1332 match_v
= kzalloc(MLX5_ST_SZ_BYTES(fte_match_param
), GFP_KERNEL
);
1333 match_c
= kzalloc(MLX5_ST_SZ_BYTES(fte_match_param
), GFP_KERNEL
);
1334 if (!match_v
|| !match_c
) {
1336 esw_warn(esw
->dev
, "vport[%d] configure ingress rules failed, err(%d)\n",
1341 if (vport
->vlan
|| vport
->qos
)
1342 MLX5_SET_TO_ONES(fte_match_param
, match_c
, outer_headers
.vlan_tag
);
1344 if (vport
->spoofchk
) {
1345 MLX5_SET_TO_ONES(fte_match_param
, match_c
, outer_headers
.smac_47_16
);
1346 MLX5_SET_TO_ONES(fte_match_param
, match_c
, outer_headers
.smac_15_0
);
1347 smac_v
= MLX5_ADDR_OF(fte_match_param
,
1349 outer_headers
.smac_47_16
);
1350 ether_addr_copy(smac_v
, smac
);
1353 vport
->ingress
.allow_rule
=
1354 mlx5_add_flow_rule(vport
->ingress
.acl
,
1355 MLX5_MATCH_OUTER_HEADERS
,
1358 MLX5_FLOW_CONTEXT_ACTION_ALLOW
,
1360 if (IS_ERR(vport
->ingress
.allow_rule
)) {
1361 err
= PTR_ERR(vport
->ingress
.allow_rule
);
1362 pr_warn("vport[%d] configure ingress allow rule, err(%d)\n",
1364 vport
->ingress
.allow_rule
= NULL
;
1368 memset(match_c
, 0, MLX5_ST_SZ_BYTES(fte_match_param
));
1369 memset(match_v
, 0, MLX5_ST_SZ_BYTES(fte_match_param
));
1370 vport
->ingress
.drop_rule
=
1371 mlx5_add_flow_rule(vport
->ingress
.acl
,
1375 MLX5_FLOW_CONTEXT_ACTION_DROP
,
1377 if (IS_ERR(vport
->ingress
.drop_rule
)) {
1378 err
= PTR_ERR(vport
->ingress
.drop_rule
);
1379 pr_warn("vport[%d] configure ingress drop rule, err(%d)\n",
1381 vport
->ingress
.drop_rule
= NULL
;
1387 esw_vport_cleanup_ingress_rules(esw
, vport
);
1394 static int esw_vport_egress_config(struct mlx5_eswitch
*esw
,
1395 struct mlx5_vport
*vport
)
1401 esw_vport_cleanup_egress_rules(esw
, vport
);
1403 if (!vport
->vlan
&& !vport
->qos
) {
1404 esw_vport_disable_egress_acl(esw
, vport
);
1408 esw_vport_enable_egress_acl(esw
, vport
);
1411 "vport[%d] configure egress rules, vlan(%d) qos(%d)\n",
1412 vport
->vport
, vport
->vlan
, vport
->qos
);
1414 match_v
= kzalloc(MLX5_ST_SZ_BYTES(fte_match_param
), GFP_KERNEL
);
1415 match_c
= kzalloc(MLX5_ST_SZ_BYTES(fte_match_param
), GFP_KERNEL
);
1416 if (!match_v
|| !match_c
) {
1418 esw_warn(esw
->dev
, "vport[%d] configure egress rules failed, err(%d)\n",
1423 /* Allowed vlan rule */
1424 MLX5_SET_TO_ONES(fte_match_param
, match_c
, outer_headers
.vlan_tag
);
1425 MLX5_SET_TO_ONES(fte_match_param
, match_v
, outer_headers
.vlan_tag
);
1426 MLX5_SET_TO_ONES(fte_match_param
, match_c
, outer_headers
.first_vid
);
1427 MLX5_SET(fte_match_param
, match_v
, outer_headers
.first_vid
, vport
->vlan
);
1429 vport
->egress
.allowed_vlan
=
1430 mlx5_add_flow_rule(vport
->egress
.acl
,
1431 MLX5_MATCH_OUTER_HEADERS
,
1434 MLX5_FLOW_CONTEXT_ACTION_ALLOW
,
1436 if (IS_ERR(vport
->egress
.allowed_vlan
)) {
1437 err
= PTR_ERR(vport
->egress
.allowed_vlan
);
1438 pr_warn("vport[%d] configure egress allowed vlan rule failed, err(%d)\n",
1440 vport
->egress
.allowed_vlan
= NULL
;
1444 /* Drop others rule (star rule) */
1445 memset(match_c
, 0, MLX5_ST_SZ_BYTES(fte_match_param
));
1446 memset(match_v
, 0, MLX5_ST_SZ_BYTES(fte_match_param
));
1447 vport
->egress
.drop_rule
=
1448 mlx5_add_flow_rule(vport
->egress
.acl
,
1452 MLX5_FLOW_CONTEXT_ACTION_DROP
,
1454 if (IS_ERR(vport
->egress
.drop_rule
)) {
1455 err
= PTR_ERR(vport
->egress
.drop_rule
);
1456 pr_warn("vport[%d] configure egress drop rule failed, err(%d)\n",
1458 vport
->egress
.drop_rule
= NULL
;
1466 static void esw_enable_vport(struct mlx5_eswitch
*esw
, int vport_num
,
1469 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
1471 mutex_lock(&esw
->state_lock
);
1472 WARN_ON(vport
->enabled
);
1474 esw_debug(esw
->dev
, "Enabling VPORT(%d)\n", vport_num
);
1476 if (vport_num
) { /* Only VFs need ACLs for VST and spoofchk filtering */
1477 esw_vport_ingress_config(esw
, vport
);
1478 esw_vport_egress_config(esw
, vport
);
1481 mlx5_modify_vport_admin_state(esw
->dev
,
1482 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT
,
1484 MLX5_ESW_VPORT_ADMIN_STATE_AUTO
);
1486 /* Sync with current vport context */
1487 vport
->enabled_events
= enable_events
;
1488 vport
->enabled
= true;
1490 /* only PF is trusted by default */
1491 vport
->trusted
= (vport_num
) ? false : true;
1492 esw_vport_change_handle_locked(vport
);
1494 esw
->enabled_vports
++;
1495 esw_debug(esw
->dev
, "Enabled VPORT(%d)\n", vport_num
);
1496 mutex_unlock(&esw
->state_lock
);
1499 static void esw_disable_vport(struct mlx5_eswitch
*esw
, int vport_num
)
1501 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
1503 if (!vport
->enabled
)
1506 esw_debug(esw
->dev
, "Disabling vport(%d)\n", vport_num
);
1507 /* Mark this vport as disabled to discard new events */
1508 vport
->enabled
= false;
1510 synchronize_irq(mlx5_get_msix_vec(esw
->dev
, MLX5_EQ_VEC_ASYNC
));
1512 mlx5_modify_vport_admin_state(esw
->dev
,
1513 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT
,
1515 MLX5_ESW_VPORT_ADMIN_STATE_DOWN
);
1516 /* Wait for current already scheduled events to complete */
1517 flush_workqueue(esw
->work_queue
);
1518 /* Disable events from this vport */
1519 arm_vport_context_events_cmd(esw
->dev
, vport
->vport
, 0);
1520 mutex_lock(&esw
->state_lock
);
1521 /* We don't assume VFs will cleanup after themselves.
1522 * Calling vport change handler while vport is disabled will cleanup
1523 * the vport resources.
1525 esw_vport_change_handle_locked(vport
);
1526 vport
->enabled_events
= 0;
1528 esw_vport_disable_egress_acl(esw
, vport
);
1529 esw_vport_disable_ingress_acl(esw
, vport
);
1531 esw
->enabled_vports
--;
1532 mutex_unlock(&esw
->state_lock
);
1535 /* Public E-Switch API */
1536 int mlx5_eswitch_enable_sriov(struct mlx5_eswitch
*esw
, int nvfs
, int mode
)
1539 int i
, enabled_events
;
1541 if (!esw
|| !MLX5_CAP_GEN(esw
->dev
, vport_group_manager
) ||
1542 MLX5_CAP_GEN(esw
->dev
, port_type
) != MLX5_CAP_PORT_TYPE_ETH
)
1545 if (!MLX5_CAP_GEN(esw
->dev
, eswitch_flow_table
) ||
1546 !MLX5_CAP_ESW_FLOWTABLE_FDB(esw
->dev
, ft_support
)) {
1547 esw_warn(esw
->dev
, "E-Switch FDB is not supported, aborting ...\n");
1551 if (!MLX5_CAP_ESW_INGRESS_ACL(esw
->dev
, ft_support
))
1552 esw_warn(esw
->dev
, "E-Switch ingress ACL is not supported by FW\n");
1554 if (!MLX5_CAP_ESW_EGRESS_ACL(esw
->dev
, ft_support
))
1555 esw_warn(esw
->dev
, "E-Switch engress ACL is not supported by FW\n");
1557 esw_info(esw
->dev
, "E-Switch enable SRIOV: nvfs(%d) mode (%d)\n", nvfs
, mode
);
1559 esw_disable_vport(esw
, 0);
1561 if (mode
== SRIOV_LEGACY
)
1562 err
= esw_create_legacy_fdb_table(esw
, nvfs
+ 1);
1564 err
= esw_create_offloads_fdb_table(esw
, nvfs
+ 1);
1568 enabled_events
= (mode
== SRIOV_LEGACY
) ? SRIOV_VPORT_EVENTS
: UC_ADDR_CHANGE
;
1569 for (i
= 0; i
<= nvfs
; i
++)
1570 esw_enable_vport(esw
, i
, enabled_events
);
1572 esw_info(esw
->dev
, "SRIOV enabled: active vports(%d)\n",
1573 esw
->enabled_vports
);
1577 esw_enable_vport(esw
, 0, UC_ADDR_CHANGE
);
1581 void mlx5_eswitch_disable_sriov(struct mlx5_eswitch
*esw
)
1583 struct esw_mc_addr
*mc_promisc
;
1586 if (!esw
|| !MLX5_CAP_GEN(esw
->dev
, vport_group_manager
) ||
1587 MLX5_CAP_GEN(esw
->dev
, port_type
) != MLX5_CAP_PORT_TYPE_ETH
)
1590 esw_info(esw
->dev
, "disable SRIOV: active vports(%d) mode(%d)\n",
1591 esw
->enabled_vports
, esw
->mode
);
1593 mc_promisc
= esw
->mc_promisc
;
1595 for (i
= 0; i
< esw
->total_vports
; i
++)
1596 esw_disable_vport(esw
, i
);
1598 if (mc_promisc
&& mc_promisc
->uplink_rule
)
1599 mlx5_del_flow_rule(mc_promisc
->uplink_rule
);
1601 if (esw
->mode
== SRIOV_LEGACY
)
1602 esw_destroy_legacy_fdb_table(esw
);
1604 esw_destroy_offloads_fdb_table(esw
);
1606 esw
->mode
= SRIOV_NONE
;
1607 /* VPORT 0 (PF) must be enabled back with non-sriov configuration */
1608 esw_enable_vport(esw
, 0, UC_ADDR_CHANGE
);
1611 int mlx5_eswitch_init(struct mlx5_core_dev
*dev
)
1613 int l2_table_size
= 1 << MLX5_CAP_GEN(dev
, log_max_l2_table
);
1614 int total_vports
= MLX5_TOTAL_VPORTS(dev
);
1615 struct esw_mc_addr
*mc_promisc
;
1616 struct mlx5_eswitch
*esw
;
1620 if (!MLX5_CAP_GEN(dev
, vport_group_manager
) ||
1621 MLX5_CAP_GEN(dev
, port_type
) != MLX5_CAP_PORT_TYPE_ETH
)
1625 "Total vports %d, l2 table size(%d), per vport: max uc(%d) max mc(%d)\n",
1626 total_vports
, l2_table_size
,
1627 MLX5_MAX_UC_PER_VPORT(dev
),
1628 MLX5_MAX_MC_PER_VPORT(dev
));
1630 esw
= kzalloc(sizeof(*esw
), GFP_KERNEL
);
1636 esw
->l2_table
.bitmap
= kcalloc(BITS_TO_LONGS(l2_table_size
),
1637 sizeof(uintptr_t), GFP_KERNEL
);
1638 if (!esw
->l2_table
.bitmap
) {
1642 esw
->l2_table
.size
= l2_table_size
;
1644 mc_promisc
= kzalloc(sizeof(*mc_promisc
), GFP_KERNEL
);
1649 esw
->mc_promisc
= mc_promisc
;
1651 esw
->work_queue
= create_singlethread_workqueue("mlx5_esw_wq");
1652 if (!esw
->work_queue
) {
1657 esw
->vports
= kcalloc(total_vports
, sizeof(struct mlx5_vport
),
1664 mutex_init(&esw
->state_lock
);
1666 for (vport_num
= 0; vport_num
< total_vports
; vport_num
++) {
1667 struct mlx5_vport
*vport
= &esw
->vports
[vport_num
];
1669 vport
->vport
= vport_num
;
1671 INIT_WORK(&vport
->vport_change_handler
,
1672 esw_vport_change_handler
);
1675 esw
->total_vports
= total_vports
;
1676 esw
->enabled_vports
= 0;
1677 esw
->mode
= SRIOV_NONE
;
1679 dev
->priv
.eswitch
= esw
;
1680 esw_enable_vport(esw
, 0, UC_ADDR_CHANGE
);
1681 /* VF Vports will be enabled when SRIOV is enabled */
1684 if (esw
->work_queue
)
1685 destroy_workqueue(esw
->work_queue
);
1686 kfree(esw
->l2_table
.bitmap
);
1692 void mlx5_eswitch_cleanup(struct mlx5_eswitch
*esw
)
1694 if (!esw
|| !MLX5_CAP_GEN(esw
->dev
, vport_group_manager
) ||
1695 MLX5_CAP_GEN(esw
->dev
, port_type
) != MLX5_CAP_PORT_TYPE_ETH
)
1698 esw_info(esw
->dev
, "cleanup\n");
1699 esw_disable_vport(esw
, 0);
1701 esw
->dev
->priv
.eswitch
= NULL
;
1702 destroy_workqueue(esw
->work_queue
);
1703 kfree(esw
->l2_table
.bitmap
);
1704 kfree(esw
->mc_promisc
);
1709 void mlx5_eswitch_vport_event(struct mlx5_eswitch
*esw
, struct mlx5_eqe
*eqe
)
1711 struct mlx5_eqe_vport_change
*vc_eqe
= &eqe
->data
.vport_change
;
1712 u16 vport_num
= be16_to_cpu(vc_eqe
->vport_num
);
1713 struct mlx5_vport
*vport
;
1716 pr_warn("MLX5 E-Switch: vport %d got an event while eswitch is not initialized\n",
1721 vport
= &esw
->vports
[vport_num
];
1723 queue_work(esw
->work_queue
, &vport
->vport_change_handler
);
1726 /* Vport Administration */
1727 #define ESW_ALLOWED(esw) \
1728 (esw && MLX5_CAP_GEN(esw->dev, vport_group_manager) && mlx5_core_is_pf(esw->dev))
1729 #define LEGAL_VPORT(esw, vport) (vport >= 0 && vport < esw->total_vports)
1731 static void node_guid_gen_from_mac(u64
*node_guid
, u8 mac
[ETH_ALEN
])
1733 ((u8
*)node_guid
)[7] = mac
[0];
1734 ((u8
*)node_guid
)[6] = mac
[1];
1735 ((u8
*)node_guid
)[5] = mac
[2];
1736 ((u8
*)node_guid
)[4] = 0xff;
1737 ((u8
*)node_guid
)[3] = 0xfe;
1738 ((u8
*)node_guid
)[2] = mac
[3];
1739 ((u8
*)node_guid
)[1] = mac
[4];
1740 ((u8
*)node_guid
)[0] = mac
[5];
1743 int mlx5_eswitch_set_vport_mac(struct mlx5_eswitch
*esw
,
1744 int vport
, u8 mac
[ETH_ALEN
])
1746 struct mlx5_vport
*evport
;
1750 if (!ESW_ALLOWED(esw
))
1752 if (!LEGAL_VPORT(esw
, vport
))
1755 evport
= &esw
->vports
[vport
];
1757 if (evport
->spoofchk
&& !is_valid_ether_addr(mac
)) {
1758 mlx5_core_warn(esw
->dev
,
1759 "MAC invalidation is not allowed when spoofchk is on, vport(%d)\n",
1764 err
= mlx5_modify_nic_vport_mac_address(esw
->dev
, vport
, mac
);
1766 mlx5_core_warn(esw
->dev
,
1767 "Failed to mlx5_modify_nic_vport_mac vport(%d) err=(%d)\n",
1772 node_guid_gen_from_mac(&node_guid
, mac
);
1773 err
= mlx5_modify_nic_vport_node_guid(esw
->dev
, vport
, node_guid
);
1775 mlx5_core_warn(esw
->dev
,
1776 "Failed to set vport %d node guid, err = %d. RDMA_CM will not function properly for this VF.\n",
1779 mutex_lock(&esw
->state_lock
);
1780 if (evport
->enabled
)
1781 err
= esw_vport_ingress_config(esw
, evport
);
1782 mutex_unlock(&esw
->state_lock
);
1786 int mlx5_eswitch_set_vport_state(struct mlx5_eswitch
*esw
,
1787 int vport
, int link_state
)
1789 if (!ESW_ALLOWED(esw
))
1791 if (!LEGAL_VPORT(esw
, vport
))
1794 return mlx5_modify_vport_admin_state(esw
->dev
,
1795 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT
,
1799 int mlx5_eswitch_get_vport_config(struct mlx5_eswitch
*esw
,
1800 int vport
, struct ifla_vf_info
*ivi
)
1802 struct mlx5_vport
*evport
;
1806 if (!ESW_ALLOWED(esw
))
1808 if (!LEGAL_VPORT(esw
, vport
))
1811 evport
= &esw
->vports
[vport
];
1813 memset(ivi
, 0, sizeof(*ivi
));
1814 ivi
->vf
= vport
- 1;
1816 mlx5_query_nic_vport_mac_address(esw
->dev
, vport
, ivi
->mac
);
1817 ivi
->linkstate
= mlx5_query_vport_admin_state(esw
->dev
,
1818 MLX5_QUERY_VPORT_STATE_IN_OP_MOD_ESW_VPORT
,
1820 query_esw_vport_cvlan(esw
->dev
, vport
, &vlan
, &qos
);
1823 ivi
->spoofchk
= evport
->spoofchk
;
1828 int mlx5_eswitch_set_vport_vlan(struct mlx5_eswitch
*esw
,
1829 int vport
, u16 vlan
, u8 qos
)
1831 struct mlx5_vport
*evport
;
1835 if (!ESW_ALLOWED(esw
))
1837 if (!LEGAL_VPORT(esw
, vport
) || (vlan
> 4095) || (qos
> 7))
1843 evport
= &esw
->vports
[vport
];
1845 err
= modify_esw_vport_cvlan(esw
->dev
, vport
, vlan
, qos
, set
);
1849 mutex_lock(&esw
->state_lock
);
1850 evport
->vlan
= vlan
;
1852 if (evport
->enabled
) {
1853 err
= esw_vport_ingress_config(esw
, evport
);
1856 err
= esw_vport_egress_config(esw
, evport
);
1860 mutex_unlock(&esw
->state_lock
);
1864 int mlx5_eswitch_set_vport_spoofchk(struct mlx5_eswitch
*esw
,
1865 int vport
, bool spoofchk
)
1867 struct mlx5_vport
*evport
;
1871 if (!ESW_ALLOWED(esw
))
1873 if (!LEGAL_VPORT(esw
, vport
))
1876 evport
= &esw
->vports
[vport
];
1878 mutex_lock(&esw
->state_lock
);
1879 pschk
= evport
->spoofchk
;
1880 evport
->spoofchk
= spoofchk
;
1881 if (evport
->enabled
)
1882 err
= esw_vport_ingress_config(esw
, evport
);
1884 evport
->spoofchk
= pschk
;
1885 mutex_unlock(&esw
->state_lock
);
1890 int mlx5_eswitch_set_vport_trust(struct mlx5_eswitch
*esw
,
1891 int vport
, bool setting
)
1893 struct mlx5_vport
*evport
;
1895 if (!ESW_ALLOWED(esw
))
1897 if (!LEGAL_VPORT(esw
, vport
))
1900 evport
= &esw
->vports
[vport
];
1902 mutex_lock(&esw
->state_lock
);
1903 evport
->trusted
= setting
;
1904 if (evport
->enabled
)
1905 esw_vport_change_handle_locked(evport
);
1906 mutex_unlock(&esw
->state_lock
);
1911 int mlx5_eswitch_get_vport_stats(struct mlx5_eswitch
*esw
,
1913 struct ifla_vf_stats
*vf_stats
)
1915 int outlen
= MLX5_ST_SZ_BYTES(query_vport_counter_out
);
1916 u32 in
[MLX5_ST_SZ_DW(query_vport_counter_in
)];
1920 if (!ESW_ALLOWED(esw
))
1922 if (!LEGAL_VPORT(esw
, vport
))
1925 out
= mlx5_vzalloc(outlen
);
1929 memset(in
, 0, sizeof(in
));
1931 MLX5_SET(query_vport_counter_in
, in
, opcode
,
1932 MLX5_CMD_OP_QUERY_VPORT_COUNTER
);
1933 MLX5_SET(query_vport_counter_in
, in
, op_mod
, 0);
1934 MLX5_SET(query_vport_counter_in
, in
, vport_number
, vport
);
1936 MLX5_SET(query_vport_counter_in
, in
, other_vport
, 1);
1938 memset(out
, 0, outlen
);
1939 err
= mlx5_cmd_exec(esw
->dev
, in
, sizeof(in
), out
, outlen
);
1943 #define MLX5_GET_CTR(p, x) \
1944 MLX5_GET64(query_vport_counter_out, p, x)
1946 memset(vf_stats
, 0, sizeof(*vf_stats
));
1947 vf_stats
->rx_packets
=
1948 MLX5_GET_CTR(out
, received_eth_unicast
.packets
) +
1949 MLX5_GET_CTR(out
, received_eth_multicast
.packets
) +
1950 MLX5_GET_CTR(out
, received_eth_broadcast
.packets
);
1952 vf_stats
->rx_bytes
=
1953 MLX5_GET_CTR(out
, received_eth_unicast
.octets
) +
1954 MLX5_GET_CTR(out
, received_eth_multicast
.octets
) +
1955 MLX5_GET_CTR(out
, received_eth_broadcast
.octets
);
1957 vf_stats
->tx_packets
=
1958 MLX5_GET_CTR(out
, transmitted_eth_unicast
.packets
) +
1959 MLX5_GET_CTR(out
, transmitted_eth_multicast
.packets
) +
1960 MLX5_GET_CTR(out
, transmitted_eth_broadcast
.packets
);
1962 vf_stats
->tx_bytes
=
1963 MLX5_GET_CTR(out
, transmitted_eth_unicast
.octets
) +
1964 MLX5_GET_CTR(out
, transmitted_eth_multicast
.octets
) +
1965 MLX5_GET_CTR(out
, transmitted_eth_broadcast
.octets
);
1967 vf_stats
->multicast
=
1968 MLX5_GET_CTR(out
, received_eth_multicast
.packets
);
1970 vf_stats
->broadcast
=
1971 MLX5_GET_CTR(out
, received_eth_broadcast
.packets
);