1 // SPDX-License-Identifier: GPL-2.0
2 /* Copyright (C) 2018-2020, Intel Corporation. */
8 * ice_fltr_free_list - free filter lists helper
9 * @dev: pointer to the device struct
10 * @h: pointer to the list head to be freed
12 * Helper function to free filter lists previously created using
13 * ice_fltr_add_mac_to_list
15 void ice_fltr_free_list(struct device *dev, struct list_head *h)
17 struct ice_fltr_list_entry *e, *tmp;
19 list_for_each_entry_safe(e, tmp, h, list_entry) {
20 list_del(&e->list_entry);
26 * ice_fltr_add_entry_to_list - allocate and add filter entry to list
27 * @dev: pointer to device needed by alloc function
28 * @info: filter info struct that gets added to the passed in list
29 * @list: pointer to the list which contains MAC filters entry
32 ice_fltr_add_entry_to_list(struct device *dev, struct ice_fltr_info *info,
33 struct list_head *list)
35 struct ice_fltr_list_entry *entry;
37 entry = devm_kzalloc(dev, sizeof(*entry), GFP_ATOMIC);
41 entry->fltr_info = *info;
43 INIT_LIST_HEAD(&entry->list_entry);
44 list_add(&entry->list_entry, list);
50 * ice_fltr_set_vlan_vsi_promisc
51 * @hw: pointer to the hardware structure
52 * @vsi: the VSI being configured
53 * @promisc_mask: mask of promiscuous config bits
55 * Set VSI with all associated VLANs to given promiscuous mode(s)
58 ice_fltr_set_vlan_vsi_promisc(struct ice_hw *hw, struct ice_vsi *vsi,
61 return ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_mask, false);
65 * ice_fltr_clear_vlan_vsi_promisc
66 * @hw: pointer to the hardware structure
67 * @vsi: the VSI being configured
68 * @promisc_mask: mask of promiscuous config bits
70 * Clear VSI with all associated VLANs to given promiscuous mode(s)
73 ice_fltr_clear_vlan_vsi_promisc(struct ice_hw *hw, struct ice_vsi *vsi,
76 return ice_set_vlan_vsi_promisc(hw, vsi->idx, promisc_mask, true);
80 * ice_fltr_clear_vsi_promisc - clear specified promiscuous mode(s)
81 * @hw: pointer to the hardware structure
82 * @vsi_handle: VSI handle to clear mode
83 * @promisc_mask: mask of promiscuous config bits to clear
84 * @vid: VLAN ID to clear VLAN promiscuous
87 ice_fltr_clear_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
90 return ice_clear_vsi_promisc(hw, vsi_handle, promisc_mask, vid);
94 * ice_fltr_set_vsi_promisc - set given VSI to given promiscuous mode(s)
95 * @hw: pointer to the hardware structure
96 * @vsi_handle: VSI handle to configure
97 * @promisc_mask: mask of promiscuous config bits
98 * @vid: VLAN ID to set VLAN promiscuous
101 ice_fltr_set_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask,
104 return ice_set_vsi_promisc(hw, vsi_handle, promisc_mask, vid);
108 * ice_fltr_add_mac_list - add list of MAC filters
109 * @vsi: pointer to VSI struct
110 * @list: list of filters
112 int ice_fltr_add_mac_list(struct ice_vsi *vsi, struct list_head *list)
114 return ice_add_mac(&vsi->back->hw, list);
118 * ice_fltr_remove_mac_list - remove list of MAC filters
119 * @vsi: pointer to VSI struct
120 * @list: list of filters
122 int ice_fltr_remove_mac_list(struct ice_vsi *vsi, struct list_head *list)
124 return ice_remove_mac(&vsi->back->hw, list);
128 * ice_fltr_add_vlan_list - add list of VLAN filters
129 * @vsi: pointer to VSI struct
130 * @list: list of filters
132 static int ice_fltr_add_vlan_list(struct ice_vsi *vsi, struct list_head *list)
134 return ice_add_vlan(&vsi->back->hw, list);
138 * ice_fltr_remove_vlan_list - remove list of VLAN filters
139 * @vsi: pointer to VSI struct
140 * @list: list of filters
143 ice_fltr_remove_vlan_list(struct ice_vsi *vsi, struct list_head *list)
145 return ice_remove_vlan(&vsi->back->hw, list);
149 * ice_fltr_add_eth_list - add list of ethertype filters
150 * @vsi: pointer to VSI struct
151 * @list: list of filters
153 static int ice_fltr_add_eth_list(struct ice_vsi *vsi, struct list_head *list)
155 return ice_add_eth_mac(&vsi->back->hw, list);
159 * ice_fltr_remove_eth_list - remove list of ethertype filters
160 * @vsi: pointer to VSI struct
161 * @list: list of filters
163 static int ice_fltr_remove_eth_list(struct ice_vsi *vsi, struct list_head *list)
165 return ice_remove_eth_mac(&vsi->back->hw, list);
169 * ice_fltr_remove_all - remove all filters associated with VSI
170 * @vsi: pointer to VSI struct
172 void ice_fltr_remove_all(struct ice_vsi *vsi)
174 ice_remove_vsi_fltr(&vsi->back->hw, vsi->idx);
178 * ice_fltr_add_mac_to_list - add MAC filter info to exsisting list
179 * @vsi: pointer to VSI struct
180 * @list: list to add filter info to
181 * @mac: MAC address to add
182 * @action: filter action
185 ice_fltr_add_mac_to_list(struct ice_vsi *vsi, struct list_head *list,
186 const u8 *mac, enum ice_sw_fwd_act_type action)
188 struct ice_fltr_info info = { 0 };
190 info.flag = ICE_FLTR_TX;
191 info.src_id = ICE_SRC_ID_VSI;
192 info.lkup_type = ICE_SW_LKUP_MAC;
193 info.fltr_act = action;
194 info.vsi_handle = vsi->idx;
196 ether_addr_copy(info.l_data.mac.mac_addr, mac);
198 return ice_fltr_add_entry_to_list(ice_pf_to_dev(vsi->back), &info,
203 * ice_fltr_add_vlan_to_list - add VLAN filter info to exsisting list
204 * @vsi: pointer to VSI struct
205 * @list: list to add filter info to
206 * @vlan: VLAN filter details
209 ice_fltr_add_vlan_to_list(struct ice_vsi *vsi, struct list_head *list,
210 struct ice_vlan *vlan)
212 struct ice_fltr_info info = { 0 };
214 info.flag = ICE_FLTR_TX;
215 info.src_id = ICE_SRC_ID_VSI;
216 info.lkup_type = ICE_SW_LKUP_VLAN;
217 info.fltr_act = ICE_FWD_TO_VSI;
218 info.vsi_handle = vsi->idx;
219 info.l_data.vlan.vlan_id = vlan->vid;
220 info.l_data.vlan.tpid = vlan->tpid;
221 info.l_data.vlan.tpid_valid = true;
223 return ice_fltr_add_entry_to_list(ice_pf_to_dev(vsi->back), &info,
228 * ice_fltr_add_eth_to_list - add ethertype filter info to exsisting list
229 * @vsi: pointer to VSI struct
230 * @list: list to add filter info to
231 * @ethertype: ethertype of packet that matches filter
232 * @flag: filter direction, Tx or Rx
233 * @action: filter action
236 ice_fltr_add_eth_to_list(struct ice_vsi *vsi, struct list_head *list,
237 u16 ethertype, u16 flag,
238 enum ice_sw_fwd_act_type action)
240 struct ice_fltr_info info = { 0 };
243 info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
244 info.fltr_act = action;
245 info.vsi_handle = vsi->idx;
246 info.l_data.ethertype_mac.ethertype = ethertype;
248 if (flag == ICE_FLTR_TX)
249 info.src_id = ICE_SRC_ID_VSI;
251 info.src_id = ICE_SRC_ID_LPORT;
253 return ice_fltr_add_entry_to_list(ice_pf_to_dev(vsi->back), &info,
258 * ice_fltr_prepare_mac - add or remove MAC rule
259 * @vsi: pointer to VSI struct
260 * @mac: MAC address to add
261 * @action: action to be performed on filter match
262 * @mac_action: pointer to add or remove MAC function
265 ice_fltr_prepare_mac(struct ice_vsi *vsi, const u8 *mac,
266 enum ice_sw_fwd_act_type action,
267 int (*mac_action)(struct ice_vsi *, struct list_head *))
272 if (ice_fltr_add_mac_to_list(vsi, &tmp_list, mac, action)) {
273 ice_fltr_free_list(ice_pf_to_dev(vsi->back), &tmp_list);
277 result = mac_action(vsi, &tmp_list);
278 ice_fltr_free_list(ice_pf_to_dev(vsi->back), &tmp_list);
283 * ice_fltr_prepare_mac_and_broadcast - add or remove MAC and broadcast filter
284 * @vsi: pointer to VSI struct
285 * @mac: MAC address to add
286 * @action: action to be performed on filter match
287 * @mac_action: pointer to add or remove MAC function
290 ice_fltr_prepare_mac_and_broadcast(struct ice_vsi *vsi, const u8 *mac,
291 enum ice_sw_fwd_act_type action,
293 (struct ice_vsi *, struct list_head *))
295 u8 broadcast[ETH_ALEN];
299 eth_broadcast_addr(broadcast);
300 if (ice_fltr_add_mac_to_list(vsi, &tmp_list, mac, action) ||
301 ice_fltr_add_mac_to_list(vsi, &tmp_list, broadcast, action)) {
302 ice_fltr_free_list(ice_pf_to_dev(vsi->back), &tmp_list);
306 result = mac_action(vsi, &tmp_list);
307 ice_fltr_free_list(ice_pf_to_dev(vsi->back), &tmp_list);
312 * ice_fltr_prepare_vlan - add or remove VLAN filter
313 * @vsi: pointer to VSI struct
314 * @vlan: VLAN filter details
315 * @vlan_action: pointer to add or remove VLAN function
318 ice_fltr_prepare_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan,
319 int (*vlan_action)(struct ice_vsi *, struct list_head *))
324 if (ice_fltr_add_vlan_to_list(vsi, &tmp_list, vlan))
327 result = vlan_action(vsi, &tmp_list);
328 ice_fltr_free_list(ice_pf_to_dev(vsi->back), &tmp_list);
333 * ice_fltr_prepare_eth - add or remove ethertype filter
334 * @vsi: pointer to VSI struct
335 * @ethertype: ethertype of packet to be filtered
336 * @flag: direction of packet, Tx or Rx
337 * @action: action to be performed on filter match
338 * @eth_action: pointer to add or remove ethertype function
341 ice_fltr_prepare_eth(struct ice_vsi *vsi, u16 ethertype, u16 flag,
342 enum ice_sw_fwd_act_type action,
343 int (*eth_action)(struct ice_vsi *, struct list_head *))
348 if (ice_fltr_add_eth_to_list(vsi, &tmp_list, ethertype, flag, action))
351 result = eth_action(vsi, &tmp_list);
352 ice_fltr_free_list(ice_pf_to_dev(vsi->back), &tmp_list);
357 * ice_fltr_add_mac - add single MAC filter
358 * @vsi: pointer to VSI struct
360 * @action: action to be performed on filter match
362 int ice_fltr_add_mac(struct ice_vsi *vsi, const u8 *mac,
363 enum ice_sw_fwd_act_type action)
365 return ice_fltr_prepare_mac(vsi, mac, action, ice_fltr_add_mac_list);
369 * ice_fltr_add_mac_and_broadcast - add single MAC and broadcast
370 * @vsi: pointer to VSI struct
372 * @action: action to be performed on filter match
375 ice_fltr_add_mac_and_broadcast(struct ice_vsi *vsi, const u8 *mac,
376 enum ice_sw_fwd_act_type action)
378 return ice_fltr_prepare_mac_and_broadcast(vsi, mac, action,
379 ice_fltr_add_mac_list);
383 * ice_fltr_remove_mac - remove MAC filter
384 * @vsi: pointer to VSI struct
385 * @mac: filter MAC to remove
386 * @action: action to remove
388 int ice_fltr_remove_mac(struct ice_vsi *vsi, const u8 *mac,
389 enum ice_sw_fwd_act_type action)
391 return ice_fltr_prepare_mac(vsi, mac, action, ice_fltr_remove_mac_list);
395 * ice_fltr_add_vlan - add single VLAN filter
396 * @vsi: pointer to VSI struct
397 * @vlan: VLAN filter details
399 int ice_fltr_add_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
401 return ice_fltr_prepare_vlan(vsi, vlan, ice_fltr_add_vlan_list);
405 * ice_fltr_remove_vlan - remove VLAN filter
406 * @vsi: pointer to VSI struct
407 * @vlan: VLAN filter details
409 int ice_fltr_remove_vlan(struct ice_vsi *vsi, struct ice_vlan *vlan)
411 return ice_fltr_prepare_vlan(vsi, vlan, ice_fltr_remove_vlan_list);
415 * ice_fltr_add_eth - add specyfic ethertype filter
416 * @vsi: pointer to VSI struct
417 * @ethertype: ethertype of filter
418 * @flag: direction of packet to be filtered, Tx or Rx
419 * @action: action to be performed on filter match
421 int ice_fltr_add_eth(struct ice_vsi *vsi, u16 ethertype, u16 flag,
422 enum ice_sw_fwd_act_type action)
424 return ice_fltr_prepare_eth(vsi, ethertype, flag, action,
425 ice_fltr_add_eth_list);
429 * ice_fltr_remove_eth - remove ethertype filter
430 * @vsi: pointer to VSI struct
431 * @ethertype: ethertype of filter
432 * @flag: direction of filter
433 * @action: action to remove
435 int ice_fltr_remove_eth(struct ice_vsi *vsi, u16 ethertype, u16 flag,
436 enum ice_sw_fwd_act_type action)
438 return ice_fltr_prepare_eth(vsi, ethertype, flag, action,
439 ice_fltr_remove_eth_list);