99#include "ice_devlink.h"
1010#include "ice_tc_lib.h"
1111
12+ /**
13+ * ice_eswitch_add_vf_mac_rule - add adv rule with VF's MAC
14+ * @pf: pointer to PF struct
15+ * @vf: pointer to VF struct
16+ * @mac: VF's MAC address
17+ *
18+ * This function adds advanced rule that forwards packets with
19+ * VF's MAC address (src MAC) to the corresponding switchdev ctrl VSI queue.
20+ */
21+ int
22+ ice_eswitch_add_vf_mac_rule (struct ice_pf * pf , struct ice_vf * vf , const u8 * mac )
23+ {
24+ struct ice_vsi * ctrl_vsi = pf -> switchdev .control_vsi ;
25+ struct ice_adv_rule_info rule_info = { 0 };
26+ struct ice_adv_lkup_elem * list ;
27+ struct ice_hw * hw = & pf -> hw ;
28+ const u16 lkups_cnt = 1 ;
29+ int err ;
30+
31+ list = kcalloc (lkups_cnt , sizeof (* list ), GFP_ATOMIC );
32+ if (!list )
33+ return - ENOMEM ;
34+
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 );
38+
39+ rule_info .sw_act .flag |= ICE_FLTR_TX ;
40+ rule_info .sw_act .vsi_handle = ctrl_vsi -> idx ;
41+ rule_info .sw_act .fltr_act = ICE_FWD_TO_Q ;
42+ rule_info .rx = false;
43+ rule_info .sw_act .fwd_id .q_id = hw -> func_caps .common_cap .rxq_first_id +
44+ ctrl_vsi -> rxq_map [vf -> vf_id ];
45+ rule_info .flags_info .act |= ICE_SINGLE_ACT_LB_ENABLE ;
46+ rule_info .flags_info .act_valid = true;
47+
48+ err = ice_add_adv_rule (hw , list , lkups_cnt , & rule_info ,
49+ vf -> repr -> mac_rule );
50+ if (err )
51+ dev_err (ice_pf_to_dev (pf ), "Unable to add VF mac rule in switchdev mode for VF %d" ,
52+ vf -> vf_id );
53+ else
54+ vf -> repr -> rule_added = true;
55+
56+ kfree (list );
57+ return err ;
58+ }
59+
60+ /**
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 .addr )) {
74+ err = ice_eswitch_add_vf_mac_rule (vf -> pf , vf ,
75+ vf -> hw_lan_addr .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 .addr , vf -> vf_id , err );
79+ return ;
80+ }
81+ vf -> num_mac ++ ;
82+
83+ ether_addr_copy (vf -> dev_lan_addr .addr , vf -> hw_lan_addr .addr );
84+ }
85+ }
86+
87+ /**
88+ * ice_eswitch_del_vf_mac_rule - delete adv rule with VF's MAC
89+ * @vf: pointer to the VF struct
90+ *
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.
93+ */
94+ void ice_eswitch_del_vf_mac_rule (struct ice_vf * vf )
95+ {
96+ if (!ice_is_switchdev_running (vf -> pf ))
97+ return ;
98+
99+ if (!vf -> repr -> rule_added )
100+ return ;
101+
102+ ice_rem_adv_rule_by_id (& vf -> pf -> hw , vf -> repr -> mac_rule );
103+ vf -> repr -> rule_added = false;
104+ }
105+
12106/**
13107 * ice_eswitch_setup_env - configure switchdev HW filters
14108 * @pf: pointer to PF struct
@@ -21,7 +115,6 @@ static int ice_eswitch_setup_env(struct ice_pf *pf)
21115 struct ice_vsi * uplink_vsi = pf -> switchdev .uplink_vsi ;
22116 struct net_device * uplink_netdev = uplink_vsi -> netdev ;
23117 struct ice_vsi * ctrl_vsi = pf -> switchdev .control_vsi ;
24- struct ice_port_info * pi = pf -> hw .port_info ;
25118 bool rule_added = false;
26119
27120 ice_vsi_manage_vlan_stripping (ctrl_vsi , false);
@@ -42,29 +135,17 @@ static int ice_eswitch_setup_env(struct ice_pf *pf)
42135 rule_added = true;
43136 }
44137
45- if (ice_cfg_dflt_vsi (pi -> hw , ctrl_vsi -> idx , true, ICE_FLTR_TX ))
46- goto err_def_tx ;
47-
48138 if (ice_vsi_update_security (uplink_vsi , ice_vsi_ctx_set_allow_override ))
49139 goto err_override_uplink ;
50140
51141 if (ice_vsi_update_security (ctrl_vsi , ice_vsi_ctx_set_allow_override ))
52142 goto err_override_control ;
53143
54- if (ice_fltr_update_flags_dflt_rule (ctrl_vsi , pi -> dflt_tx_vsi_rule_id ,
55- ICE_FLTR_TX ,
56- ICE_SINGLE_ACT_LB_ENABLE ))
57- goto err_update_action ;
58-
59144 return 0 ;
60145
61- err_update_action :
62- ice_vsi_update_security (ctrl_vsi , ice_vsi_ctx_clear_allow_override );
63146err_override_control :
64147 ice_vsi_update_security (uplink_vsi , ice_vsi_ctx_clear_allow_override );
65148err_override_uplink :
66- ice_cfg_dflt_vsi (pi -> hw , ctrl_vsi -> idx , false, ICE_FLTR_TX );
67- err_def_tx :
68149 if (rule_added )
69150 ice_clear_dflt_vsi (uplink_vsi -> vsw );
70151err_def_rx :
@@ -167,21 +248,11 @@ static int ice_eswitch_setup_reprs(struct ice_pf *pf)
167248 netif_keep_dst (vf -> repr -> netdev );
168249 }
169250
170- kfree (ctrl_vsi -> target_netdevs );
171-
172- ctrl_vsi -> target_netdevs = kcalloc (max_vsi_num + 1 ,
173- sizeof (* ctrl_vsi -> target_netdevs ),
174- GFP_KERNEL );
175- if (!ctrl_vsi -> target_netdevs )
176- goto err ;
177-
178251 ice_for_each_vf (pf , i ) {
179252 struct ice_repr * repr = pf -> vf [i ].repr ;
180253 struct ice_vsi * vsi = repr -> src_vsi ;
181254 struct metadata_dst * dst ;
182255
183- ctrl_vsi -> target_netdevs [vsi -> vsi_num ] = repr -> netdev ;
184-
185256 dst = repr -> dst ;
186257 dst -> u .port_info .port_id = vsi -> vsi_num ;
187258 dst -> u .port_info .lower_dev = repr -> netdev ;
@@ -214,7 +285,6 @@ ice_eswitch_release_reprs(struct ice_pf *pf, struct ice_vsi *ctrl_vsi)
214285{
215286 int i ;
216287
217- kfree (ctrl_vsi -> target_netdevs );
218288 ice_for_each_vf (pf , i ) {
219289 struct ice_vsi * vsi = pf -> vf [i ].repr -> src_vsi ;
220290 struct ice_vf * vf = & pf -> vf [i ];
@@ -320,7 +390,6 @@ static void ice_eswitch_release_env(struct ice_pf *pf)
320390
321391 ice_vsi_update_security (ctrl_vsi , ice_vsi_ctx_clear_allow_override );
322392 ice_vsi_update_security (uplink_vsi , ice_vsi_ctx_clear_allow_override );
323- ice_cfg_dflt_vsi (& pf -> hw , ctrl_vsi -> idx , false, ICE_FLTR_TX );
324393 ice_clear_dflt_vsi (uplink_vsi -> vsw );
325394 ice_fltr_add_mac_and_broadcast (uplink_vsi ,
326395 uplink_vsi -> port_info -> mac .perm_addr ,
@@ -374,24 +443,6 @@ static void ice_eswitch_napi_disable(struct ice_pf *pf)
374443 napi_disable (& pf -> vf [i ].repr -> q_vector -> napi );
375444}
376445
377- /**
378- * ice_eswitch_set_rxdid - configure rxdid on all Rx queues from VSI
379- * @vsi: VSI to setup rxdid on
380- * @rxdid: flex descriptor id
381- */
382- static void ice_eswitch_set_rxdid (struct ice_vsi * vsi , u32 rxdid )
383- {
384- struct ice_hw * hw = & vsi -> back -> hw ;
385- int i ;
386-
387- ice_for_each_rxq (vsi , i ) {
388- struct ice_rx_ring * ring = vsi -> rx_rings [i ];
389- u16 pf_q = vsi -> rxq_map [ring -> q_index ];
390-
391- ice_write_qrxflxp_cntxt (hw , pf_q , rxdid , 0x3 , true);
392- }
393- }
394-
395446/**
396447 * ice_eswitch_enable_switchdev - configure eswitch in switchdev mode
397448 * @pf: pointer to PF structure
@@ -425,8 +476,6 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)
425476
426477 ice_eswitch_napi_enable (pf );
427478
428- ice_eswitch_set_rxdid (ctrl_vsi , ICE_RXDID_FLEX_NIC_2 );
429-
430479 return 0 ;
431480
432481err_setup_reprs :
@@ -448,6 +497,7 @@ static void ice_eswitch_disable_switchdev(struct ice_pf *pf)
448497
449498 ice_eswitch_napi_disable (pf );
450499 ice_eswitch_release_env (pf );
500+ ice_rem_adv_rule_for_vsi (& pf -> hw , ctrl_vsi -> idx );
451501 ice_eswitch_release_reprs (pf , ctrl_vsi );
452502 ice_vsi_release (ctrl_vsi );
453503 ice_repr_rem_from_all_vfs (pf );
@@ -496,34 +546,6 @@ ice_eswitch_mode_set(struct devlink *devlink, u16 mode,
496546 return 0 ;
497547}
498548
499- /**
500- * ice_eswitch_get_target_netdev - return port representor netdev
501- * @rx_ring: pointer to Rx ring
502- * @rx_desc: pointer to Rx descriptor
503- *
504- * When working in switchdev mode context (when control VSI is used), this
505- * function returns netdev of appropriate port representor. For non-switchdev
506- * context, regular netdev associated with Rx ring is returned.
507- */
508- struct net_device *
509- ice_eswitch_get_target_netdev (struct ice_rx_ring * rx_ring ,
510- union ice_32b_rx_flex_desc * rx_desc )
511- {
512- struct ice_32b_rx_flex_desc_nic_2 * desc ;
513- struct ice_vsi * vsi = rx_ring -> vsi ;
514- struct ice_vsi * control_vsi ;
515- u16 target_vsi_id ;
516-
517- control_vsi = vsi -> back -> switchdev .control_vsi ;
518- if (vsi != control_vsi )
519- return rx_ring -> netdev ;
520-
521- desc = (struct ice_32b_rx_flex_desc_nic_2 * )rx_desc ;
522- target_vsi_id = le16_to_cpu (desc -> src_vsi );
523-
524- return vsi -> target_netdevs [target_vsi_id ];
525- }
526-
527549/**
528550 * ice_eswitch_mode_get - get current eswitch mode
529551 * @devlink: pointer to devlink structure
@@ -648,7 +670,6 @@ int ice_eswitch_rebuild(struct ice_pf *pf)
648670 return status ;
649671
650672 ice_eswitch_napi_enable (pf );
651- ice_eswitch_set_rxdid (ctrl_vsi , ICE_RXDID_FLEX_NIC_2 );
652673 ice_eswitch_start_all_tx_queues (pf );
653674
654675 return 0 ;
0 commit comments