Skip to content

Commit 0ef4479

Browse files
Michal Swiatkowskianguy11
authored andcommitted
ice: use src VSI instead of src MAC in slow-path
The use of a source MAC to direct packets from the VF to the corresponding port representor is only ok if there is only one MAC on a VF. To support this functionality when the number of MACs on a VF is greater, it is necessary to match a source VSI instead of a source MAC. Let's use the new switch API that allows matching on metadata. If MAC isn't used in match criteria there is no need to handle adding rule after virtchnl command. Instead add new rule while port representor is being configured. Remove rule_added field, checking for sp_rule can be used instead. Remove also checking for switchdev running in deleting rule as it can be called from unroll context when running flag isn't set. Checking for sp_rule covers both context (with and without running flag). Rules are added in eswitch configuration flow, so there is no need to have replay function. Signed-off-by: Michal Swiatkowski <[email protected]> Reviewed-by: Piotr Raczynski <[email protected]> Reviewed-by: Simon Horman <[email protected]> Reviewed-by: Leon Romanovsky <[email protected]> Tested-by: Sujai Buvaneswaran <[email protected]> Signed-off-by: Tony Nguyen <[email protected]>
1 parent 03592a1 commit 0ef4479

File tree

9 files changed

+40
-102
lines changed

9 files changed

+40
-102
lines changed

drivers/net/ethernet/intel/ice/ice_eswitch.c

Lines changed: 27 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,15 @@
1010
#include "ice_tc_lib.h"
1111

1212
/**
13-
* ice_eswitch_add_vf_mac_rule - add adv rule with VF's MAC
13+
* ice_eswitch_add_vf_sp_rule - add adv rule with VF's VSI index
1414
* @pf: pointer to PF struct
1515
* @vf: pointer to VF struct
16-
* @mac: VF's MAC address
1716
*
1817
* This function adds advanced rule that forwards packets with
19-
* VF's MAC address (src MAC) to the corresponding switchdev ctrl VSI queue.
18+
* VF's VSI index to the corresponding switchdev ctrl VSI queue.
2019
*/
21-
int
22-
ice_eswitch_add_vf_mac_rule(struct ice_pf *pf, struct ice_vf *vf, const u8 *mac)
20+
static int
21+
ice_eswitch_add_vf_sp_rule(struct ice_pf *pf, struct ice_vf *vf)
2322
{
2423
struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;
2524
struct ice_adv_rule_info rule_info = { 0 };
@@ -32,75 +31,41 @@ ice_eswitch_add_vf_mac_rule(struct ice_pf *pf, struct ice_vf *vf, const u8 *mac)
3231
if (!list)
3332
return -ENOMEM;
3433

35-
list[0].type = ICE_MAC_OFOS;
36-
ether_addr_copy(list[0].h_u.eth_hdr.src_addr, mac);
37-
eth_broadcast_addr(list[0].m_u.eth_hdr.src_addr);
34+
ice_rule_add_src_vsi_metadata(list);
3835

39-
rule_info.sw_act.flag |= ICE_FLTR_TX;
36+
rule_info.sw_act.flag = ICE_FLTR_TX;
4037
rule_info.sw_act.vsi_handle = ctrl_vsi->idx;
4138
rule_info.sw_act.fltr_act = ICE_FWD_TO_Q;
4239
rule_info.sw_act.fwd_id.q_id = hw->func_caps.common_cap.rxq_first_id +
4340
ctrl_vsi->rxq_map[vf->vf_id];
4441
rule_info.flags_info.act |= ICE_SINGLE_ACT_LB_ENABLE;
4542
rule_info.flags_info.act_valid = true;
4643
rule_info.tun_type = ICE_SW_TUN_AND_NON_TUN;
44+
rule_info.src_vsi = vf->lan_vsi_idx;
4745

4846
err = ice_add_adv_rule(hw, list, lkups_cnt, &rule_info,
49-
vf->repr->mac_rule);
47+
&vf->repr->sp_rule);
5048
if (err)
51-
dev_err(ice_pf_to_dev(pf), "Unable to add VF mac rule in switchdev mode for VF %d",
49+
dev_err(ice_pf_to_dev(pf), "Unable to add VF slow-path rule in switchdev mode for VF %d",
5250
vf->vf_id);
53-
else
54-
vf->repr->rule_added = true;
5551

5652
kfree(list);
5753
return err;
5854
}
5955

6056
/**
61-
* ice_eswitch_replay_vf_mac_rule - replay adv rule with VF's MAC
62-
* @vf: pointer to vF struct
63-
*
64-
* This function replays VF's MAC rule after reset.
65-
*/
66-
void ice_eswitch_replay_vf_mac_rule(struct ice_vf *vf)
67-
{
68-
int err;
69-
70-
if (!ice_is_switchdev_running(vf->pf))
71-
return;
72-
73-
if (is_valid_ether_addr(vf->hw_lan_addr)) {
74-
err = ice_eswitch_add_vf_mac_rule(vf->pf, vf,
75-
vf->hw_lan_addr);
76-
if (err) {
77-
dev_err(ice_pf_to_dev(vf->pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
78-
vf->hw_lan_addr, vf->vf_id, err);
79-
return;
80-
}
81-
vf->num_mac++;
82-
83-
ether_addr_copy(vf->dev_lan_addr, vf->hw_lan_addr);
84-
}
85-
}
86-
87-
/**
88-
* ice_eswitch_del_vf_mac_rule - delete adv rule with VF's MAC
57+
* ice_eswitch_del_vf_sp_rule - delete adv rule with VF's VSI index
8958
* @vf: pointer to the VF struct
9059
*
91-
* Delete the advanced rule that was used to forward packets with the VF's MAC
92-
* address (src MAC) to the corresponding switchdev ctrl VSI queue.
60+
* Delete the advanced rule that was used to forward packets with the VF's VSI
61+
* index to the corresponding switchdev ctrl VSI queue.
9362
*/
94-
void ice_eswitch_del_vf_mac_rule(struct ice_vf *vf)
63+
static void ice_eswitch_del_vf_sp_rule(struct ice_vf *vf)
9564
{
96-
if (!ice_is_switchdev_running(vf->pf))
97-
return;
98-
99-
if (!vf->repr->rule_added)
65+
if (!vf->repr)
10066
return;
10167

102-
ice_rem_adv_rule_by_id(&vf->pf->hw, vf->repr->mac_rule);
103-
vf->repr->rule_added = false;
68+
ice_rem_adv_rule_by_id(&vf->pf->hw, &vf->repr->sp_rule);
10469
}
10570

10671
/**
@@ -236,6 +201,7 @@ ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
236201
ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);
237202
metadata_dst_free(vf->repr->dst);
238203
vf->repr->dst = NULL;
204+
ice_eswitch_del_vf_sp_rule(vf);
239205
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
240206
ICE_FWD_TO_VSI);
241207

@@ -263,25 +229,30 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
263229
vf->repr->dst = metadata_dst_alloc(0, METADATA_HW_PORT_MUX,
264230
GFP_KERNEL);
265231
if (!vf->repr->dst) {
266-
ice_fltr_add_mac_and_broadcast(vsi,
267-
vf->hw_lan_addr,
232+
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
233+
ICE_FWD_TO_VSI);
234+
goto err;
235+
}
236+
237+
if (ice_eswitch_add_vf_sp_rule(pf, vf)) {
238+
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
268239
ICE_FWD_TO_VSI);
269240
goto err;
270241
}
271242

272243
if (ice_vsi_update_security(vsi, ice_vsi_ctx_clear_antispoof)) {
273-
ice_fltr_add_mac_and_broadcast(vsi,
274-
vf->hw_lan_addr,
244+
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
275245
ICE_FWD_TO_VSI);
246+
ice_eswitch_del_vf_sp_rule(vf);
276247
metadata_dst_free(vf->repr->dst);
277248
vf->repr->dst = NULL;
278249
goto err;
279250
}
280251

281252
if (ice_vsi_add_vlan_zero(vsi)) {
282-
ice_fltr_add_mac_and_broadcast(vsi,
283-
vf->hw_lan_addr,
253+
ice_fltr_add_mac_and_broadcast(vsi, vf->hw_lan_addr,
284254
ICE_FWD_TO_VSI);
255+
ice_eswitch_del_vf_sp_rule(vf);
285256
metadata_dst_free(vf->repr->dst);
286257
vf->repr->dst = NULL;
287258
ice_vsi_update_security(vsi, ice_vsi_ctx_set_antispoof);

drivers/net/ethernet/intel/ice/ice_eswitch.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@ bool ice_is_eswitch_mode_switchdev(struct ice_pf *pf);
2020
void ice_eswitch_update_repr(struct ice_vsi *vsi);
2121

2222
void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf);
23-
int
24-
ice_eswitch_add_vf_mac_rule(struct ice_pf *pf, struct ice_vf *vf,
25-
const u8 *mac);
26-
void ice_eswitch_replay_vf_mac_rule(struct ice_vf *vf);
27-
void ice_eswitch_del_vf_mac_rule(struct ice_vf *vf);
2823

2924
void ice_eswitch_set_target_vsi(struct sk_buff *skb,
3025
struct ice_tx_offload_params *off);
@@ -34,15 +29,6 @@ ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev);
3429
static inline void ice_eswitch_release(struct ice_pf *pf) { }
3530

3631
static inline void ice_eswitch_stop_all_tx_queues(struct ice_pf *pf) { }
37-
static inline void ice_eswitch_replay_vf_mac_rule(struct ice_vf *vf) { }
38-
static inline void ice_eswitch_del_vf_mac_rule(struct ice_vf *vf) { }
39-
40-
static inline int
41-
ice_eswitch_add_vf_mac_rule(struct ice_pf *pf, struct ice_vf *vf,
42-
const u8 *mac)
43-
{
44-
return -EOPNOTSUPP;
45-
}
4632

4733
static inline void
4834
ice_eswitch_set_target_vsi(struct sk_buff *skb,

drivers/net/ethernet/intel/ice/ice_protocol_type.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,10 @@ struct ice_nvgre_hdr {
256256
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
257257
*
258258
* Source VSI = Source VSI of packet loopbacked in switch (for egress) (10b).
259-
*
259+
*/
260+
#define ICE_MDID_SOURCE_VSI_MASK GENMASK(9, 0)
261+
262+
/*
260263
* MDID 20
261264
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
262265
* |A|B|C|D|E|F|R|R|G|H|I|J|K|L|M|N|

drivers/net/ethernet/intel/ice/ice_repr.c

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -298,14 +298,6 @@ static int ice_repr_add(struct ice_vf *vf)
298298
if (!repr)
299299
return -ENOMEM;
300300

301-
#ifdef CONFIG_ICE_SWITCHDEV
302-
repr->mac_rule = kzalloc(sizeof(*repr->mac_rule), GFP_KERNEL);
303-
if (!repr->mac_rule) {
304-
err = -ENOMEM;
305-
goto err_alloc_rule;
306-
}
307-
#endif
308-
309301
repr->netdev = alloc_etherdev(sizeof(struct ice_netdev_priv));
310302
if (!repr->netdev) {
311303
err = -ENOMEM;
@@ -351,11 +343,6 @@ static int ice_repr_add(struct ice_vf *vf)
351343
free_netdev(repr->netdev);
352344
repr->netdev = NULL;
353345
err_alloc:
354-
#ifdef CONFIG_ICE_SWITCHDEV
355-
kfree(repr->mac_rule);
356-
repr->mac_rule = NULL;
357-
err_alloc_rule:
358-
#endif
359346
kfree(repr);
360347
vf->repr = NULL;
361348
return err;
@@ -376,10 +363,6 @@ static void ice_repr_rem(struct ice_vf *vf)
376363
ice_devlink_destroy_vf_port(vf);
377364
free_netdev(vf->repr->netdev);
378365
vf->repr->netdev = NULL;
379-
#ifdef CONFIG_ICE_SWITCHDEV
380-
kfree(vf->repr->mac_rule);
381-
vf->repr->mac_rule = NULL;
382-
#endif
383366
kfree(vf->repr);
384367
vf->repr = NULL;
385368

drivers/net/ethernet/intel/ice/ice_repr.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ struct ice_repr {
1313
struct net_device *netdev;
1414
struct metadata_dst *dst;
1515
#ifdef CONFIG_ICE_SWITCHDEV
16-
/* info about slow path MAC rule */
17-
struct ice_rule_query_data *mac_rule;
18-
u8 rule_added;
16+
/* info about slow path rule */
17+
struct ice_rule_query_data sp_rule;
1918
#endif
2019
};
2120

drivers/net/ethernet/intel/ice/ice_switch.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6012,6 +6012,12 @@ void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup)
60126012
cpu_to_be16(ICE_PKT_VLAN_MASK);
60136013
}
60146014

6015+
void ice_rule_add_src_vsi_metadata(struct ice_adv_lkup_elem *lkup)
6016+
{
6017+
lkup->type = ICE_HW_METADATA;
6018+
lkup->m_u.metadata.source_vsi = cpu_to_be16(ICE_MDID_SOURCE_VSI_MASK);
6019+
}
6020+
60156021
/**
60166022
* ice_add_adv_rule - helper function to create an advanced switch rule
60176023
* @hw: pointer to the hardware structure

drivers/net/ethernet/intel/ice/ice_switch.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@ ice_free_res_cntr(struct ice_hw *hw, u8 type, u8 alloc_shared, u16 num_items,
344344
/* Switch/bridge related commands */
345345
void ice_rule_add_tunnel_metadata(struct ice_adv_lkup_elem *lkup);
346346
void ice_rule_add_vlan_metadata(struct ice_adv_lkup_elem *lkup);
347+
void ice_rule_add_src_vsi_metadata(struct ice_adv_lkup_elem *lkup);
347348
int
348349
ice_add_adv_rule(struct ice_hw *hw, struct ice_adv_lkup_elem *lkups,
349350
u16 lkups_cnt, struct ice_adv_rule_info *rinfo,

drivers/net/ethernet/intel/ice/ice_vf_lib.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -689,8 +689,6 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags)
689689
*/
690690
ice_vf_clear_all_promisc_modes(vf, vsi);
691691

692-
ice_eswitch_del_vf_mac_rule(vf);
693-
694692
ice_vf_fdir_exit(vf);
695693
ice_vf_fdir_init(vf);
696694
/* clean VF control VSI when resetting VF since it should be setup
@@ -716,7 +714,6 @@ int ice_reset_vf(struct ice_vf *vf, u32 flags)
716714
}
717715

718716
ice_eswitch_update_repr(vsi);
719-
ice_eswitch_replay_vf_mac_rule(vf);
720717

721718
/* if the VF has been reset allow it to come up again */
722719
ice_mbx_clear_malvf(&vf->mbx_info);

drivers/net/ethernet/intel/ice/ice_virtchnl.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3730,7 +3730,6 @@ static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
37303730

37313731
for (i = 0; i < al->num_elements; i++) {
37323732
u8 *mac_addr = al->list[i].addr;
3733-
int result;
37343733

37353734
if (!is_unicast_ether_addr(mac_addr) ||
37363735
ether_addr_equal(mac_addr, vf->hw_lan_addr))
@@ -3742,13 +3741,6 @@ static int ice_vc_repr_add_mac(struct ice_vf *vf, u8 *msg)
37423741
goto handle_mac_exit;
37433742
}
37443743

3745-
result = ice_eswitch_add_vf_mac_rule(pf, vf, mac_addr);
3746-
if (result) {
3747-
dev_err(ice_pf_to_dev(pf), "Failed to add MAC %pM for VF %d\n, error %d\n",
3748-
mac_addr, vf->vf_id, result);
3749-
goto handle_mac_exit;
3750-
}
3751-
37523744
ice_vfhw_mac_add(vf, &al->list[i]);
37533745
vf->num_mac++;
37543746
break;

0 commit comments

Comments
 (0)