2 * Copyright (c) 2016, 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"
46 struct mlx5_flow_handle
*
47 mlx5_eswitch_add_offloaded_rule(struct mlx5_eswitch
*esw
,
48 struct mlx5_flow_spec
*spec
,
49 struct mlx5_esw_flow_attr
*attr
)
51 struct mlx5_flow_destination dest
[2] = {};
52 struct mlx5_flow_act flow_act
= {0};
53 struct mlx5_fc
*counter
= NULL
;
54 struct mlx5_flow_handle
*rule
;
58 if (esw
->mode
!= SRIOV_OFFLOADS
)
59 return ERR_PTR(-EOPNOTSUPP
);
61 flow_act
.action
= attr
->action
;
63 if (flow_act
.action
& MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
) {
64 dest
[i
].type
= MLX5_FLOW_DESTINATION_TYPE_VPORT
;
65 dest
[i
].vport_num
= attr
->out_rep
->vport
;
68 if (flow_act
.action
& MLX5_FLOW_CONTEXT_ACTION_COUNT
) {
69 counter
= mlx5_fc_create(esw
->dev
, true);
71 return ERR_CAST(counter
);
72 dest
[i
].type
= MLX5_FLOW_DESTINATION_TYPE_COUNTER
;
73 dest
[i
].counter
= counter
;
77 misc
= MLX5_ADDR_OF(fte_match_param
, spec
->match_value
, misc_parameters
);
78 MLX5_SET(fte_match_set_misc
, misc
, source_port
, attr
->in_rep
->vport
);
80 misc
= MLX5_ADDR_OF(fte_match_param
, spec
->match_criteria
, misc_parameters
);
81 MLX5_SET_TO_ONES(fte_match_set_misc
, misc
, source_port
);
83 spec
->match_criteria_enable
= MLX5_MATCH_OUTER_HEADERS
|
84 MLX5_MATCH_MISC_PARAMETERS
;
85 if (flow_act
.action
& MLX5_FLOW_CONTEXT_ACTION_DECAP
)
86 spec
->match_criteria_enable
|= MLX5_MATCH_INNER_HEADERS
;
89 flow_act
.encap_id
= attr
->encap
->encap_id
;
91 rule
= mlx5_add_flow_rules((struct mlx5_flow_table
*)esw
->fdb_table
.fdb
,
92 spec
, &flow_act
, dest
, i
);
94 mlx5_fc_destroy(esw
->dev
, counter
);
99 static int esw_set_global_vlan_pop(struct mlx5_eswitch
*esw
, u8 val
)
101 struct mlx5_eswitch_rep
*rep
;
102 int vf_vport
, err
= 0;
104 esw_debug(esw
->dev
, "%s applying global %s policy\n", __func__
, val
? "pop" : "none");
105 for (vf_vport
= 1; vf_vport
< esw
->enabled_vports
; vf_vport
++) {
106 rep
= &esw
->offloads
.vport_reps
[vf_vport
];
110 err
= __mlx5_eswitch_set_vport_vlan(esw
, rep
->vport
, 0, 0, val
);
119 static struct mlx5_eswitch_rep
*
120 esw_vlan_action_get_vport(struct mlx5_esw_flow_attr
*attr
, bool push
, bool pop
)
122 struct mlx5_eswitch_rep
*in_rep
, *out_rep
, *vport
= NULL
;
124 in_rep
= attr
->in_rep
;
125 out_rep
= attr
->out_rep
;
137 static int esw_add_vlan_action_check(struct mlx5_esw_flow_attr
*attr
,
138 bool push
, bool pop
, bool fwd
)
140 struct mlx5_eswitch_rep
*in_rep
, *out_rep
;
142 if ((push
|| pop
) && !fwd
)
145 in_rep
= attr
->in_rep
;
146 out_rep
= attr
->out_rep
;
148 if (push
&& in_rep
->vport
== FDB_UPLINK_VPORT
)
151 if (pop
&& out_rep
->vport
== FDB_UPLINK_VPORT
)
154 /* vport has vlan push configured, can't offload VF --> wire rules w.o it */
155 if (!push
&& !pop
&& fwd
)
156 if (in_rep
->vlan
&& out_rep
->vport
== FDB_UPLINK_VPORT
)
159 /* protects against (1) setting rules with different vlans to push and
160 * (2) setting rules w.o vlans (attr->vlan = 0) && w. vlans to push (!= 0)
162 if (push
&& in_rep
->vlan_refcount
&& (in_rep
->vlan
!= attr
->vlan
))
171 int mlx5_eswitch_add_vlan_action(struct mlx5_eswitch
*esw
,
172 struct mlx5_esw_flow_attr
*attr
)
174 struct offloads_fdb
*offloads
= &esw
->fdb_table
.offloads
;
175 struct mlx5_eswitch_rep
*vport
= NULL
;
179 push
= !!(attr
->action
& MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH
);
180 pop
= !!(attr
->action
& MLX5_FLOW_CONTEXT_ACTION_VLAN_POP
);
181 fwd
= !!(attr
->action
& MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
);
183 err
= esw_add_vlan_action_check(attr
, push
, pop
, fwd
);
187 attr
->vlan_handled
= false;
189 vport
= esw_vlan_action_get_vport(attr
, push
, pop
);
191 if (!push
&& !pop
&& fwd
) {
192 /* tracks VF --> wire rules without vlan push action */
193 if (attr
->out_rep
->vport
== FDB_UPLINK_VPORT
) {
194 vport
->vlan_refcount
++;
195 attr
->vlan_handled
= true;
204 if (!(offloads
->vlan_push_pop_refcount
)) {
205 /* it's the 1st vlan rule, apply global vlan pop policy */
206 err
= esw_set_global_vlan_pop(esw
, SET_VLAN_STRIP
);
210 offloads
->vlan_push_pop_refcount
++;
213 if (vport
->vlan_refcount
)
216 err
= __mlx5_eswitch_set_vport_vlan(esw
, vport
->vport
, attr
->vlan
, 0,
217 SET_VLAN_INSERT
| SET_VLAN_STRIP
);
220 vport
->vlan
= attr
->vlan
;
222 vport
->vlan_refcount
++;
226 attr
->vlan_handled
= true;
230 int mlx5_eswitch_del_vlan_action(struct mlx5_eswitch
*esw
,
231 struct mlx5_esw_flow_attr
*attr
)
233 struct offloads_fdb
*offloads
= &esw
->fdb_table
.offloads
;
234 struct mlx5_eswitch_rep
*vport
= NULL
;
238 if (!attr
->vlan_handled
)
241 push
= !!(attr
->action
& MLX5_FLOW_CONTEXT_ACTION_VLAN_PUSH
);
242 pop
= !!(attr
->action
& MLX5_FLOW_CONTEXT_ACTION_VLAN_POP
);
243 fwd
= !!(attr
->action
& MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
);
245 vport
= esw_vlan_action_get_vport(attr
, push
, pop
);
247 if (!push
&& !pop
&& fwd
) {
248 /* tracks VF --> wire rules without vlan push action */
249 if (attr
->out_rep
->vport
== FDB_UPLINK_VPORT
)
250 vport
->vlan_refcount
--;
256 vport
->vlan_refcount
--;
257 if (vport
->vlan_refcount
)
258 goto skip_unset_push
;
261 err
= __mlx5_eswitch_set_vport_vlan(esw
, vport
->vport
,
262 0, 0, SET_VLAN_STRIP
);
268 offloads
->vlan_push_pop_refcount
--;
269 if (offloads
->vlan_push_pop_refcount
)
272 /* no more vlan rules, stop global vlan pop policy */
273 err
= esw_set_global_vlan_pop(esw
, 0);
279 static struct mlx5_flow_handle
*
280 mlx5_eswitch_add_send_to_vport_rule(struct mlx5_eswitch
*esw
, int vport
, u32 sqn
)
282 struct mlx5_flow_act flow_act
= {0};
283 struct mlx5_flow_destination dest
;
284 struct mlx5_flow_handle
*flow_rule
;
285 struct mlx5_flow_spec
*spec
;
288 spec
= mlx5_vzalloc(sizeof(*spec
));
290 esw_warn(esw
->dev
, "FDB: Failed to alloc match parameters\n");
291 flow_rule
= ERR_PTR(-ENOMEM
);
295 misc
= MLX5_ADDR_OF(fte_match_param
, spec
->match_value
, misc_parameters
);
296 MLX5_SET(fte_match_set_misc
, misc
, source_sqn
, sqn
);
297 MLX5_SET(fte_match_set_misc
, misc
, source_port
, 0x0); /* source vport is 0 */
299 misc
= MLX5_ADDR_OF(fte_match_param
, spec
->match_criteria
, misc_parameters
);
300 MLX5_SET_TO_ONES(fte_match_set_misc
, misc
, source_sqn
);
301 MLX5_SET_TO_ONES(fte_match_set_misc
, misc
, source_port
);
303 spec
->match_criteria_enable
= MLX5_MATCH_MISC_PARAMETERS
;
304 dest
.type
= MLX5_FLOW_DESTINATION_TYPE_VPORT
;
305 dest
.vport_num
= vport
;
306 flow_act
.action
= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
;
308 flow_rule
= mlx5_add_flow_rules(esw
->fdb_table
.offloads
.fdb
, spec
,
309 &flow_act
, &dest
, 1);
310 if (IS_ERR(flow_rule
))
311 esw_warn(esw
->dev
, "FDB: Failed to add send to vport rule err %ld\n", PTR_ERR(flow_rule
));
317 void mlx5_eswitch_sqs2vport_stop(struct mlx5_eswitch
*esw
,
318 struct mlx5_eswitch_rep
*rep
)
320 struct mlx5_esw_sq
*esw_sq
, *tmp
;
322 if (esw
->mode
!= SRIOV_OFFLOADS
)
325 list_for_each_entry_safe(esw_sq
, tmp
, &rep
->vport_sqs_list
, list
) {
326 mlx5_del_flow_rules(esw_sq
->send_to_vport_rule
);
327 list_del(&esw_sq
->list
);
332 int mlx5_eswitch_sqs2vport_start(struct mlx5_eswitch
*esw
,
333 struct mlx5_eswitch_rep
*rep
,
334 u16
*sqns_array
, int sqns_num
)
336 struct mlx5_flow_handle
*flow_rule
;
337 struct mlx5_esw_sq
*esw_sq
;
341 if (esw
->mode
!= SRIOV_OFFLOADS
)
344 for (i
= 0; i
< sqns_num
; i
++) {
345 esw_sq
= kzalloc(sizeof(*esw_sq
), GFP_KERNEL
);
351 /* Add re-inject rule to the PF/representor sqs */
352 flow_rule
= mlx5_eswitch_add_send_to_vport_rule(esw
,
355 if (IS_ERR(flow_rule
)) {
356 err
= PTR_ERR(flow_rule
);
360 esw_sq
->send_to_vport_rule
= flow_rule
;
361 list_add(&esw_sq
->list
, &rep
->vport_sqs_list
);
366 mlx5_eswitch_sqs2vport_stop(esw
, rep
);
370 static int esw_add_fdb_miss_rule(struct mlx5_eswitch
*esw
)
372 struct mlx5_flow_act flow_act
= {0};
373 struct mlx5_flow_destination dest
;
374 struct mlx5_flow_handle
*flow_rule
= NULL
;
375 struct mlx5_flow_spec
*spec
;
378 spec
= mlx5_vzalloc(sizeof(*spec
));
380 esw_warn(esw
->dev
, "FDB: Failed to alloc match parameters\n");
385 dest
.type
= MLX5_FLOW_DESTINATION_TYPE_VPORT
;
387 flow_act
.action
= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
;
389 flow_rule
= mlx5_add_flow_rules(esw
->fdb_table
.offloads
.fdb
, spec
,
390 &flow_act
, &dest
, 1);
391 if (IS_ERR(flow_rule
)) {
392 err
= PTR_ERR(flow_rule
);
393 esw_warn(esw
->dev
, "FDB: Failed to add miss flow rule err %d\n", err
);
397 esw
->fdb_table
.offloads
.miss_rule
= flow_rule
;
403 #define MAX_PF_SQ 256
404 #define ESW_OFFLOADS_NUM_ENTRIES (1 << 13) /* 8K */
405 #define ESW_OFFLOADS_NUM_GROUPS 4
407 static int esw_create_offloads_fdb_table(struct mlx5_eswitch
*esw
, int nvports
)
409 int inlen
= MLX5_ST_SZ_BYTES(create_flow_group_in
);
410 struct mlx5_core_dev
*dev
= esw
->dev
;
411 struct mlx5_flow_namespace
*root_ns
;
412 struct mlx5_flow_table
*fdb
= NULL
;
413 struct mlx5_flow_group
*g
;
415 void *match_criteria
;
416 int table_size
, ix
, err
= 0;
419 flow_group_in
= mlx5_vzalloc(inlen
);
423 root_ns
= mlx5_get_flow_namespace(dev
, MLX5_FLOW_NAMESPACE_FDB
);
425 esw_warn(dev
, "Failed to get FDB flow namespace\n");
429 esw_debug(dev
, "Create offloads FDB table, log_max_size(%d)\n",
430 MLX5_CAP_ESW_FLOWTABLE_FDB(dev
, log_max_ft_size
));
432 if (MLX5_CAP_ESW_FLOWTABLE_FDB(dev
, encap
) &&
433 MLX5_CAP_ESW_FLOWTABLE_FDB(dev
, decap
))
434 flags
|= MLX5_FLOW_TABLE_TUNNEL_EN
;
436 fdb
= mlx5_create_auto_grouped_flow_table(root_ns
, FDB_FAST_PATH
,
437 ESW_OFFLOADS_NUM_ENTRIES
,
438 ESW_OFFLOADS_NUM_GROUPS
, 0,
442 esw_warn(dev
, "Failed to create Fast path FDB Table err %d\n", err
);
445 esw
->fdb_table
.fdb
= fdb
;
447 table_size
= nvports
+ MAX_PF_SQ
+ 1;
448 fdb
= mlx5_create_flow_table(root_ns
, FDB_SLOW_PATH
, table_size
, 0, 0);
451 esw_warn(dev
, "Failed to create slow path FDB Table err %d\n", err
);
454 esw
->fdb_table
.offloads
.fdb
= fdb
;
456 /* create send-to-vport group */
457 memset(flow_group_in
, 0, inlen
);
458 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
,
459 MLX5_MATCH_MISC_PARAMETERS
);
461 match_criteria
= MLX5_ADDR_OF(create_flow_group_in
, flow_group_in
, match_criteria
);
463 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, misc_parameters
.source_sqn
);
464 MLX5_SET_TO_ONES(fte_match_param
, match_criteria
, misc_parameters
.source_port
);
466 ix
= nvports
+ MAX_PF_SQ
;
467 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 0);
468 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, ix
- 1);
470 g
= mlx5_create_flow_group(fdb
, flow_group_in
);
473 esw_warn(dev
, "Failed to create send-to-vport flow group err(%d)\n", err
);
476 esw
->fdb_table
.offloads
.send_to_vport_grp
= g
;
478 /* create miss group */
479 memset(flow_group_in
, 0, inlen
);
480 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
, 0);
482 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, ix
);
483 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, ix
+ 1);
485 g
= mlx5_create_flow_group(fdb
, flow_group_in
);
488 esw_warn(dev
, "Failed to create miss flow group err(%d)\n", err
);
491 esw
->fdb_table
.offloads
.miss_grp
= g
;
493 err
= esw_add_fdb_miss_rule(esw
);
500 mlx5_destroy_flow_group(esw
->fdb_table
.offloads
.miss_grp
);
502 mlx5_destroy_flow_group(esw
->fdb_table
.offloads
.send_to_vport_grp
);
504 mlx5_destroy_flow_table(esw
->fdb_table
.offloads
.fdb
);
506 mlx5_destroy_flow_table(esw
->fdb_table
.fdb
);
509 kvfree(flow_group_in
);
513 static void esw_destroy_offloads_fdb_table(struct mlx5_eswitch
*esw
)
515 if (!esw
->fdb_table
.fdb
)
518 esw_debug(esw
->dev
, "Destroy offloads FDB Table\n");
519 mlx5_del_flow_rules(esw
->fdb_table
.offloads
.miss_rule
);
520 mlx5_destroy_flow_group(esw
->fdb_table
.offloads
.send_to_vport_grp
);
521 mlx5_destroy_flow_group(esw
->fdb_table
.offloads
.miss_grp
);
523 mlx5_destroy_flow_table(esw
->fdb_table
.offloads
.fdb
);
524 mlx5_destroy_flow_table(esw
->fdb_table
.fdb
);
527 static int esw_create_offloads_table(struct mlx5_eswitch
*esw
)
529 struct mlx5_flow_namespace
*ns
;
530 struct mlx5_flow_table
*ft_offloads
;
531 struct mlx5_core_dev
*dev
= esw
->dev
;
534 ns
= mlx5_get_flow_namespace(dev
, MLX5_FLOW_NAMESPACE_OFFLOADS
);
536 esw_warn(esw
->dev
, "Failed to get offloads flow namespace\n");
540 ft_offloads
= mlx5_create_flow_table(ns
, 0, dev
->priv
.sriov
.num_vfs
+ 2, 0, 0);
541 if (IS_ERR(ft_offloads
)) {
542 err
= PTR_ERR(ft_offloads
);
543 esw_warn(esw
->dev
, "Failed to create offloads table, err %d\n", err
);
547 esw
->offloads
.ft_offloads
= ft_offloads
;
551 static void esw_destroy_offloads_table(struct mlx5_eswitch
*esw
)
553 struct mlx5_esw_offload
*offloads
= &esw
->offloads
;
555 mlx5_destroy_flow_table(offloads
->ft_offloads
);
558 static int esw_create_vport_rx_group(struct mlx5_eswitch
*esw
)
560 int inlen
= MLX5_ST_SZ_BYTES(create_flow_group_in
);
561 struct mlx5_flow_group
*g
;
562 struct mlx5_priv
*priv
= &esw
->dev
->priv
;
564 void *match_criteria
, *misc
;
566 int nvports
= priv
->sriov
.num_vfs
+ 2;
568 flow_group_in
= mlx5_vzalloc(inlen
);
572 /* create vport rx group */
573 memset(flow_group_in
, 0, inlen
);
574 MLX5_SET(create_flow_group_in
, flow_group_in
, match_criteria_enable
,
575 MLX5_MATCH_MISC_PARAMETERS
);
577 match_criteria
= MLX5_ADDR_OF(create_flow_group_in
, flow_group_in
, match_criteria
);
578 misc
= MLX5_ADDR_OF(fte_match_param
, match_criteria
, misc_parameters
);
579 MLX5_SET_TO_ONES(fte_match_set_misc
, misc
, source_port
);
581 MLX5_SET(create_flow_group_in
, flow_group_in
, start_flow_index
, 0);
582 MLX5_SET(create_flow_group_in
, flow_group_in
, end_flow_index
, nvports
- 1);
584 g
= mlx5_create_flow_group(esw
->offloads
.ft_offloads
, flow_group_in
);
588 mlx5_core_warn(esw
->dev
, "Failed to create vport rx group err %d\n", err
);
592 esw
->offloads
.vport_rx_group
= g
;
594 kfree(flow_group_in
);
598 static void esw_destroy_vport_rx_group(struct mlx5_eswitch
*esw
)
600 mlx5_destroy_flow_group(esw
->offloads
.vport_rx_group
);
603 struct mlx5_flow_handle
*
604 mlx5_eswitch_create_vport_rx_rule(struct mlx5_eswitch
*esw
, int vport
, u32 tirn
)
606 struct mlx5_flow_act flow_act
= {0};
607 struct mlx5_flow_destination dest
;
608 struct mlx5_flow_handle
*flow_rule
;
609 struct mlx5_flow_spec
*spec
;
612 spec
= mlx5_vzalloc(sizeof(*spec
));
614 esw_warn(esw
->dev
, "Failed to alloc match parameters\n");
615 flow_rule
= ERR_PTR(-ENOMEM
);
619 misc
= MLX5_ADDR_OF(fte_match_param
, spec
->match_value
, misc_parameters
);
620 MLX5_SET(fte_match_set_misc
, misc
, source_port
, vport
);
622 misc
= MLX5_ADDR_OF(fte_match_param
, spec
->match_criteria
, misc_parameters
);
623 MLX5_SET_TO_ONES(fte_match_set_misc
, misc
, source_port
);
625 spec
->match_criteria_enable
= MLX5_MATCH_MISC_PARAMETERS
;
626 dest
.type
= MLX5_FLOW_DESTINATION_TYPE_TIR
;
629 flow_act
.action
= MLX5_FLOW_CONTEXT_ACTION_FWD_DEST
;
630 flow_rule
= mlx5_add_flow_rules(esw
->offloads
.ft_offloads
, spec
,
631 &flow_act
, &dest
, 1);
632 if (IS_ERR(flow_rule
)) {
633 esw_warn(esw
->dev
, "fs offloads: Failed to add vport rx rule err %ld\n", PTR_ERR(flow_rule
));
642 static int esw_offloads_start(struct mlx5_eswitch
*esw
)
644 int err
, err1
, num_vfs
= esw
->dev
->priv
.sriov
.num_vfs
;
646 if (esw
->mode
!= SRIOV_LEGACY
) {
647 esw_warn(esw
->dev
, "Can't set offloads mode, SRIOV legacy not enabled\n");
651 mlx5_eswitch_disable_sriov(esw
);
652 err
= mlx5_eswitch_enable_sriov(esw
, num_vfs
, SRIOV_OFFLOADS
);
654 esw_warn(esw
->dev
, "Failed setting eswitch to offloads, err %d\n", err
);
655 err1
= mlx5_eswitch_enable_sriov(esw
, num_vfs
, SRIOV_LEGACY
);
657 esw_warn(esw
->dev
, "Failed setting eswitch back to legacy, err %d\n", err
);
662 int esw_offloads_init(struct mlx5_eswitch
*esw
, int nvports
)
664 struct mlx5_eswitch_rep
*rep
;
668 err
= esw_create_offloads_fdb_table(esw
, nvports
);
672 err
= esw_create_offloads_table(esw
);
676 err
= esw_create_vport_rx_group(esw
);
680 for (vport
= 0; vport
< nvports
; vport
++) {
681 rep
= &esw
->offloads
.vport_reps
[vport
];
685 err
= rep
->load(esw
, rep
);
692 for (vport
--; vport
>= 0; vport
--) {
693 rep
= &esw
->offloads
.vport_reps
[vport
];
696 rep
->unload(esw
, rep
);
698 esw_destroy_vport_rx_group(esw
);
701 esw_destroy_offloads_table(esw
);
704 esw_destroy_offloads_fdb_table(esw
);
708 static int esw_offloads_stop(struct mlx5_eswitch
*esw
)
710 int err
, err1
, num_vfs
= esw
->dev
->priv
.sriov
.num_vfs
;
712 mlx5_eswitch_disable_sriov(esw
);
713 err
= mlx5_eswitch_enable_sriov(esw
, num_vfs
, SRIOV_LEGACY
);
715 esw_warn(esw
->dev
, "Failed setting eswitch to legacy, err %d\n", err
);
716 err1
= mlx5_eswitch_enable_sriov(esw
, num_vfs
, SRIOV_OFFLOADS
);
718 esw_warn(esw
->dev
, "Failed setting eswitch back to offloads, err %d\n", err
);
724 void esw_offloads_cleanup(struct mlx5_eswitch
*esw
, int nvports
)
726 struct mlx5_eswitch_rep
*rep
;
729 for (vport
= 0; vport
< nvports
; vport
++) {
730 rep
= &esw
->offloads
.vport_reps
[vport
];
733 rep
->unload(esw
, rep
);
736 esw_destroy_vport_rx_group(esw
);
737 esw_destroy_offloads_table(esw
);
738 esw_destroy_offloads_fdb_table(esw
);
741 static int esw_mode_from_devlink(u16 mode
, u16
*mlx5_mode
)
744 case DEVLINK_ESWITCH_MODE_LEGACY
:
745 *mlx5_mode
= SRIOV_LEGACY
;
747 case DEVLINK_ESWITCH_MODE_SWITCHDEV
:
748 *mlx5_mode
= SRIOV_OFFLOADS
;
757 static int esw_mode_to_devlink(u16 mlx5_mode
, u16
*mode
)
761 *mode
= DEVLINK_ESWITCH_MODE_LEGACY
;
764 *mode
= DEVLINK_ESWITCH_MODE_SWITCHDEV
;
773 int mlx5_devlink_eswitch_mode_set(struct devlink
*devlink
, u16 mode
)
775 struct mlx5_core_dev
*dev
;
776 u16 cur_mlx5_mode
, mlx5_mode
= 0;
778 dev
= devlink_priv(devlink
);
780 if (!MLX5_CAP_GEN(dev
, vport_group_manager
))
783 cur_mlx5_mode
= dev
->priv
.eswitch
->mode
;
785 if (cur_mlx5_mode
== SRIOV_NONE
)
788 if (esw_mode_from_devlink(mode
, &mlx5_mode
))
791 if (cur_mlx5_mode
== mlx5_mode
)
794 if (mode
== DEVLINK_ESWITCH_MODE_SWITCHDEV
)
795 return esw_offloads_start(dev
->priv
.eswitch
);
796 else if (mode
== DEVLINK_ESWITCH_MODE_LEGACY
)
797 return esw_offloads_stop(dev
->priv
.eswitch
);
802 int mlx5_devlink_eswitch_mode_get(struct devlink
*devlink
, u16
*mode
)
804 struct mlx5_core_dev
*dev
;
806 dev
= devlink_priv(devlink
);
808 if (!MLX5_CAP_GEN(dev
, vport_group_manager
))
811 if (dev
->priv
.eswitch
->mode
== SRIOV_NONE
)
814 return esw_mode_to_devlink(dev
->priv
.eswitch
->mode
, mode
);
817 void mlx5_eswitch_register_vport_rep(struct mlx5_eswitch
*esw
,
819 struct mlx5_eswitch_rep
*__rep
)
821 struct mlx5_esw_offload
*offloads
= &esw
->offloads
;
822 struct mlx5_eswitch_rep
*rep
;
824 rep
= &offloads
->vport_reps
[vport_index
];
826 memset(rep
, 0, sizeof(*rep
));
828 rep
->load
= __rep
->load
;
829 rep
->unload
= __rep
->unload
;
830 rep
->vport
= __rep
->vport
;
831 rep
->priv_data
= __rep
->priv_data
;
832 ether_addr_copy(rep
->hw_id
, __rep
->hw_id
);
834 INIT_LIST_HEAD(&rep
->vport_sqs_list
);
838 void mlx5_eswitch_unregister_vport_rep(struct mlx5_eswitch
*esw
,
841 struct mlx5_esw_offload
*offloads
= &esw
->offloads
;
842 struct mlx5_eswitch_rep
*rep
;
844 rep
= &offloads
->vport_reps
[vport_index
];
846 if (esw
->mode
== SRIOV_OFFLOADS
&& esw
->vports
[vport_index
].enabled
)
847 rep
->unload(esw
, rep
);