Commit 1b8f15b6 authored by Michal Swiatkowski's avatar Michal Swiatkowski Committed by Jeff Kirsher

ice: refactor filter functions

Move filter functions to separate file.

Add functions that prepare suitable ice_fltr_info struct
depending on the filter type and add this struct to earlier created
list:
- ice_fltr_add_mac_to_list
- ice_fltr_add_vlan_to_list
- ice_fltr_add_eth_to_list
This functions are used in adding and removing filters.

Create wrappers for functions mentioned above that alloc list,
add suitable ice_fltr_info to it and call add or remove function.
- ice_fltr_prepare_mac
- ice_fltr_prepare_mac_and_broadcast
- ice_fltr_prepare_vlan
- ice_fltr_prepare_eth
Signed-off-by: default avatarMichal Swiatkowski <michal.swiatkowski@intel.com>
Signed-off-by: default avatarTony Nguyen <anthony.l.nguyen@intel.com>
Tested-by: default avatarAndrew Bowers <andrewx.bowers@intel.com>
Signed-off-by: default avatarJeff Kirsher <jeffrey.t.kirsher@intel.com>
parent 857a4f0e
...@@ -17,6 +17,7 @@ ice-y := ice_main.o \ ...@@ -17,6 +17,7 @@ ice-y := ice_main.o \
ice_lib.o \ ice_lib.o \
ice_txrx_lib.o \ ice_txrx_lib.o \
ice_txrx.o \ ice_txrx.o \
ice_fltr.o \
ice_flex_pipe.o \ ice_flex_pipe.o \
ice_flow.o \ ice_flow.o \
ice_devlink.o \ ice_devlink.o \
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ice.h" #include "ice.h"
#include "ice_flow.h" #include "ice_flow.h"
#include "ice_fltr.h"
#include "ice_lib.h" #include "ice_lib.h"
#include "ice_dcb_lib.h" #include "ice_dcb_lib.h"
...@@ -676,7 +677,6 @@ static u64 ice_loopback_test(struct net_device *netdev) ...@@ -676,7 +677,6 @@ static u64 ice_loopback_test(struct net_device *netdev)
struct ice_ring *tx_ring, *rx_ring; struct ice_ring *tx_ring, *rx_ring;
u8 broadcast[ETH_ALEN], ret = 0; u8 broadcast[ETH_ALEN], ret = 0;
int num_frames, valid_frames; int num_frames, valid_frames;
LIST_HEAD(tmp_list);
struct device *dev; struct device *dev;
u8 *tx_frame; u8 *tx_frame;
int i; int i;
...@@ -712,16 +712,11 @@ static u64 ice_loopback_test(struct net_device *netdev) ...@@ -712,16 +712,11 @@ static u64 ice_loopback_test(struct net_device *netdev)
/* Test VSI needs to receive broadcast packets */ /* Test VSI needs to receive broadcast packets */
eth_broadcast_addr(broadcast); eth_broadcast_addr(broadcast);
if (ice_add_mac_to_list(test_vsi, &tmp_list, broadcast)) { if (ice_fltr_add_mac(test_vsi, broadcast, ICE_FWD_TO_VSI)) {
ret = 5; ret = 5;
goto lbtest_mac_dis; goto lbtest_mac_dis;
} }
if (ice_add_mac(&pf->hw, &tmp_list)) {
ret = 6;
goto free_mac_list;
}
if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) { if (ice_lbtest_create_frame(pf, &tx_frame, ICE_LB_FRAME_SIZE)) {
ret = 7; ret = 7;
goto remove_mac_filters; goto remove_mac_filters;
...@@ -744,10 +739,8 @@ static u64 ice_loopback_test(struct net_device *netdev) ...@@ -744,10 +739,8 @@ static u64 ice_loopback_test(struct net_device *netdev)
lbtest_free_frame: lbtest_free_frame:
devm_kfree(dev, tx_frame); devm_kfree(dev, tx_frame);
remove_mac_filters: remove_mac_filters:
if (ice_remove_mac(&pf->hw, &tmp_list)) if (ice_fltr_remove_mac(test_vsi, broadcast, ICE_FWD_TO_VSI))
netdev_err(netdev, "Could not remove MAC filter for the test VSI\n"); netdev_err(netdev, "Could not remove MAC filter for the test VSI\n");
free_mac_list:
ice_free_fltr_list(dev, &tmp_list);
lbtest_mac_dis: lbtest_mac_dis:
/* Disable MAC loopback after the test is completed. */ /* Disable MAC loopback after the test is completed. */
if (ice_aq_set_mac_loopback(&pf->hw, false, NULL)) if (ice_aq_set_mac_loopback(&pf->hw, false, NULL))
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0 */
/* Copyright (C) 2018-2020, Intel Corporation. */
#ifndef _ICE_FLTR_H_
#define _ICE_FLTR_H_
void ice_fltr_free_list(struct device *dev, struct list_head *h);
enum ice_status
ice_fltr_add_mac_to_list(struct ice_vsi *vsi, struct list_head *list,
const u8 *mac, enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_add_mac(struct ice_vsi *vsi, const u8 *mac,
enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_add_mac_and_broadcast(struct ice_vsi *vsi, const u8 *mac,
enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_add_mac_list(struct ice_vsi *vsi, struct list_head *list);
enum ice_status
ice_fltr_remove_mac(struct ice_vsi *vsi, const u8 *mac,
enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_remove_mac_list(struct ice_vsi *vsi, struct list_head *list);
enum ice_status
ice_fltr_add_vlan(struct ice_vsi *vsi, u16 vid,
enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_remove_vlan(struct ice_vsi *vsi, u16 vid,
enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_add_eth(struct ice_vsi *vsi, u16 ethertype, u16 flag,
enum ice_sw_fwd_act_type action);
enum ice_status
ice_fltr_remove_eth(struct ice_vsi *vsi, u16 ethertype, u16 flag,
enum ice_sw_fwd_act_type action);
void ice_fltr_remove_all(struct ice_vsi *vsi);
#endif
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include "ice_base.h" #include "ice_base.h"
#include "ice_flow.h" #include "ice_flow.h"
#include "ice_lib.h" #include "ice_lib.h"
#include "ice_fltr.h"
#include "ice_dcb_lib.h" #include "ice_dcb_lib.h"
/** /**
...@@ -1339,40 +1340,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi) ...@@ -1339,40 +1340,6 @@ static void ice_vsi_set_rss_flow_fld(struct ice_vsi *vsi)
vsi_num, ice_stat_str(status)); vsi_num, ice_stat_str(status));
} }
/**
* ice_add_mac_to_list - Add a MAC address filter entry to the list
* @vsi: the VSI to be forwarded to
* @add_list: pointer to the list which contains MAC filter entries
* @macaddr: the MAC address to be added.
*
* Adds MAC address filter entry to the temp list
*
* Returns 0 on success or ENOMEM on failure.
*/
int
ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
const u8 *macaddr)
{
struct ice_fltr_list_entry *tmp;
struct ice_pf *pf = vsi->back;
tmp = devm_kzalloc(ice_pf_to_dev(pf), sizeof(*tmp), GFP_ATOMIC);
if (!tmp)
return -ENOMEM;
tmp->fltr_info.flag = ICE_FLTR_TX;
tmp->fltr_info.src_id = ICE_SRC_ID_VSI;
tmp->fltr_info.lkup_type = ICE_SW_LKUP_MAC;
tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
tmp->fltr_info.vsi_handle = vsi->idx;
ether_addr_copy(tmp->fltr_info.l_data.mac.mac_addr, macaddr);
INIT_LIST_HEAD(&tmp->list_entry);
list_add(&tmp->list_entry, add_list);
return 0;
}
/** /**
* ice_update_eth_stats - Update VSI-specific ethernet statistics counters * ice_update_eth_stats - Update VSI-specific ethernet statistics counters
* @vsi: the VSI to be updated * @vsi: the VSI to be updated
...@@ -1419,55 +1386,22 @@ void ice_update_eth_stats(struct ice_vsi *vsi) ...@@ -1419,55 +1386,22 @@ void ice_update_eth_stats(struct ice_vsi *vsi)
vsi->stat_offsets_loaded = true; vsi->stat_offsets_loaded = true;
} }
/**
* ice_free_fltr_list - free filter lists helper
* @dev: pointer to the device struct
* @h: pointer to the list head to be freed
*
* Helper function to free filter lists previously created using
* ice_add_mac_to_list
*/
void ice_free_fltr_list(struct device *dev, struct list_head *h)
{
struct ice_fltr_list_entry *e, *tmp;
list_for_each_entry_safe(e, tmp, h, list_entry) {
list_del(&e->list_entry);
devm_kfree(dev, e);
}
}
/** /**
* ice_vsi_add_vlan - Add VSI membership for given VLAN * ice_vsi_add_vlan - Add VSI membership for given VLAN
* @vsi: the VSI being configured * @vsi: the VSI being configured
* @vid: VLAN ID to be added * @vid: VLAN ID to be added
* @action: filter action to be performed on match
*/ */
int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid) int
ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid, enum ice_sw_fwd_act_type action)
{ {
struct ice_fltr_list_entry *tmp;
struct ice_pf *pf = vsi->back; struct ice_pf *pf = vsi->back;
LIST_HEAD(tmp_add_list);
enum ice_status status;
struct device *dev; struct device *dev;
int err = 0; int err = 0;
dev = ice_pf_to_dev(pf); dev = ice_pf_to_dev(pf);
tmp = devm_kzalloc(dev, sizeof(*tmp), GFP_KERNEL);
if (!tmp)
return -ENOMEM;
tmp->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
tmp->fltr_info.fltr_act = ICE_FWD_TO_VSI;
tmp->fltr_info.flag = ICE_FLTR_TX;
tmp->fltr_info.src_id = ICE_SRC_ID_VSI;
tmp->fltr_info.vsi_handle = vsi->idx;
tmp->fltr_info.l_data.vlan.vlan_id = vid;
INIT_LIST_HEAD(&tmp->list_entry);
list_add(&tmp->list_entry, &tmp_add_list);
status = ice_add_vlan(&pf->hw, &tmp_add_list); if (!ice_fltr_add_vlan(vsi, vid, action)) {
if (!status) {
vsi->num_vlan++; vsi->num_vlan++;
} else { } else {
err = -ENODEV; err = -ENODEV;
...@@ -1475,7 +1409,6 @@ int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid) ...@@ -1475,7 +1409,6 @@ int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
vsi->vsi_num); vsi->vsi_num);
} }
ice_free_fltr_list(dev, &tmp_add_list);
return err; return err;
} }
...@@ -1488,29 +1421,14 @@ int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid) ...@@ -1488,29 +1421,14 @@ int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid)
*/ */
int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid) int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
{ {
struct ice_fltr_list_entry *list;
struct ice_pf *pf = vsi->back; struct ice_pf *pf = vsi->back;
LIST_HEAD(tmp_add_list);
enum ice_status status; enum ice_status status;
struct device *dev; struct device *dev;
int err = 0; int err = 0;
dev = ice_pf_to_dev(pf); dev = ice_pf_to_dev(pf);
list = devm_kzalloc(dev, sizeof(*list), GFP_KERNEL);
if (!list)
return -ENOMEM;
list->fltr_info.lkup_type = ICE_SW_LKUP_VLAN;
list->fltr_info.vsi_handle = vsi->idx;
list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
list->fltr_info.l_data.vlan.vlan_id = vid;
list->fltr_info.flag = ICE_FLTR_TX;
list->fltr_info.src_id = ICE_SRC_ID_VSI;
INIT_LIST_HEAD(&list->list_entry); status = ice_fltr_remove_vlan(vsi, vid, ICE_FWD_TO_VSI);
list_add(&list->list_entry, &tmp_add_list);
status = ice_remove_vlan(&pf->hw, &tmp_add_list);
if (!status) { if (!status) {
vsi->num_vlan--; vsi->num_vlan--;
} else if (status == ICE_ERR_DOES_NOT_EXIST) { } else if (status == ICE_ERR_DOES_NOT_EXIST) {
...@@ -1522,7 +1440,6 @@ int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid) ...@@ -1522,7 +1440,6 @@ int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid)
err = -EIO; err = -EIO;
} }
ice_free_fltr_list(dev, &tmp_add_list);
return err; return err;
} }
...@@ -1998,47 +1915,6 @@ ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi) ...@@ -1998,47 +1915,6 @@ ice_vsi_set_q_vectors_reg_idx(struct ice_vsi *vsi)
return -EINVAL; return -EINVAL;
} }
/**
* ice_vsi_add_rem_eth_mac - Program VSI ethertype based filter with rule
* @vsi: the VSI being configured
* @add_rule: boolean value to add or remove ethertype filter rule
*/
static void
ice_vsi_add_rem_eth_mac(struct ice_vsi *vsi, bool add_rule)
{
struct ice_fltr_list_entry *list;
struct ice_pf *pf = vsi->back;
LIST_HEAD(tmp_add_list);
enum ice_status status;
struct device *dev;
dev = ice_pf_to_dev(pf);
list = devm_kzalloc(dev, sizeof(*list), GFP_KERNEL);
if (!list)
return;
list->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
list->fltr_info.fltr_act = ICE_DROP_PACKET;
list->fltr_info.flag = ICE_FLTR_TX;
list->fltr_info.src_id = ICE_SRC_ID_VSI;
list->fltr_info.vsi_handle = vsi->idx;
list->fltr_info.l_data.ethertype_mac.ethertype = vsi->ethtype;
INIT_LIST_HEAD(&list->list_entry);
list_add(&list->list_entry, &tmp_add_list);
if (add_rule)
status = ice_add_eth_mac(&pf->hw, &tmp_add_list);
else
status = ice_remove_eth_mac(&pf->hw, &tmp_add_list);
if (status)
dev_err(dev, "Failure Adding or Removing Ethertype on VSI %i error: %s\n",
vsi->vsi_num, ice_stat_str(status));
ice_free_fltr_list(dev, &tmp_add_list);
}
/** /**
* ice_cfg_sw_lldp - Config switch rules for LLDP packet handling * ice_cfg_sw_lldp - Config switch rules for LLDP packet handling
* @vsi: the VSI being configured * @vsi: the VSI being configured
...@@ -2047,45 +1923,25 @@ ice_vsi_add_rem_eth_mac(struct ice_vsi *vsi, bool add_rule) ...@@ -2047,45 +1923,25 @@ ice_vsi_add_rem_eth_mac(struct ice_vsi *vsi, bool add_rule)
*/ */
void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create) void ice_cfg_sw_lldp(struct ice_vsi *vsi, bool tx, bool create)
{ {
struct ice_fltr_list_entry *list; enum ice_status (*eth_fltr)(struct ice_vsi *v, u16 type, u16 flag,
enum ice_sw_fwd_act_type act);
struct ice_pf *pf = vsi->back; struct ice_pf *pf = vsi->back;
LIST_HEAD(tmp_add_list);
enum ice_status status; enum ice_status status;
struct device *dev; struct device *dev;
dev = ice_pf_to_dev(pf); dev = ice_pf_to_dev(pf);
list = devm_kzalloc(dev, sizeof(*list), GFP_KERNEL); eth_fltr = create ? ice_fltr_add_eth : ice_fltr_remove_eth;
if (!list)
return;
list->fltr_info.lkup_type = ICE_SW_LKUP_ETHERTYPE;
list->fltr_info.vsi_handle = vsi->idx;
list->fltr_info.l_data.ethertype_mac.ethertype = ETH_P_LLDP;
if (tx) { if (tx)
list->fltr_info.fltr_act = ICE_DROP_PACKET; status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_TX,
list->fltr_info.flag = ICE_FLTR_TX; ICE_DROP_PACKET);
list->fltr_info.src_id = ICE_SRC_ID_VSI;
} else {
list->fltr_info.fltr_act = ICE_FWD_TO_VSI;
list->fltr_info.flag = ICE_FLTR_RX;
list->fltr_info.src_id = ICE_SRC_ID_LPORT;
}
INIT_LIST_HEAD(&list->list_entry);
list_add(&list->list_entry, &tmp_add_list);
if (create)
status = ice_add_eth_mac(&pf->hw, &tmp_add_list);
else else
status = ice_remove_eth_mac(&pf->hw, &tmp_add_list); status = eth_fltr(vsi, ETH_P_LLDP, ICE_FLTR_RX, ICE_FWD_TO_VSI);
if (status) if (status)
dev_err(dev, "Fail %s %s LLDP rule on VSI %i error: %s\n", dev_err(dev, "Fail %s %s LLDP rule on VSI %i error: %s\n",
create ? "adding" : "removing", tx ? "TX" : "RX", create ? "adding" : "removing", tx ? "TX" : "RX",
vsi->vsi_num, ice_stat_str(status)); vsi->vsi_num, ice_stat_str(status));
ice_free_fltr_list(dev, &tmp_add_list);
} }
/** /**
...@@ -2172,7 +2028,7 @@ ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi, ...@@ -2172,7 +2028,7 @@ ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
* so this handles those cases (i.e. adding the PF to a bridge * so this handles those cases (i.e. adding the PF to a bridge
* without the 8021q module loaded). * without the 8021q module loaded).
*/ */
ret = ice_vsi_add_vlan(vsi, 0); ret = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
if (ret) if (ret)
goto unroll_clear_rings; goto unroll_clear_rings;
...@@ -2247,9 +2103,8 @@ ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi, ...@@ -2247,9 +2103,8 @@ ice_vsi_setup(struct ice_pf *pf, struct ice_port_info *pi,
*/ */
if (!ice_is_safe_mode(pf)) if (!ice_is_safe_mode(pf))
if (vsi->type == ICE_VSI_PF) { if (vsi->type == ICE_VSI_PF) {
ice_vsi_add_rem_eth_mac(vsi, true); ice_fltr_add_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
ICE_DROP_PACKET);
/* Tx LLDP packets */
ice_cfg_sw_lldp(vsi, true, true); ice_cfg_sw_lldp(vsi, true, true);
} }
...@@ -2566,7 +2421,8 @@ int ice_vsi_release(struct ice_vsi *vsi) ...@@ -2566,7 +2421,8 @@ int ice_vsi_release(struct ice_vsi *vsi)
if (!ice_is_safe_mode(pf)) { if (!ice_is_safe_mode(pf)) {
if (vsi->type == ICE_VSI_PF) { if (vsi->type == ICE_VSI_PF) {
ice_vsi_add_rem_eth_mac(vsi, false); ice_fltr_remove_eth(vsi, ETH_P_PAUSE, ICE_FLTR_TX,
ICE_DROP_PACKET);
ice_cfg_sw_lldp(vsi, true, false); ice_cfg_sw_lldp(vsi, true, false);
/* The Rx rule will only exist to remove if the LLDP FW /* The Rx rule will only exist to remove if the LLDP FW
* engine is currently stopped * engine is currently stopped
...@@ -2576,7 +2432,7 @@ int ice_vsi_release(struct ice_vsi *vsi) ...@@ -2576,7 +2432,7 @@ int ice_vsi_release(struct ice_vsi *vsi)
} }
} }
ice_remove_vsi_fltr(&pf->hw, vsi->idx); ice_fltr_remove_all(vsi);
ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx); ice_rm_vsi_lan_cfg(vsi->port_info, vsi->idx);
ice_vsi_delete(vsi); ice_vsi_delete(vsi);
ice_vsi_free_q_vectors(vsi); ice_vsi_free_q_vectors(vsi);
...@@ -2992,36 +2848,6 @@ void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes) ...@@ -2992,36 +2848,6 @@ void ice_update_rx_ring_stats(struct ice_ring *rx_ring, u64 pkts, u64 bytes)
u64_stats_update_end(&rx_ring->syncp); u64_stats_update_end(&rx_ring->syncp);
} }
/**
* ice_vsi_cfg_mac_fltr - Add or remove a MAC address filter for a VSI
* @vsi: the VSI being configured MAC filter
* @macaddr: the MAC address to be added.
* @set: Add or delete a MAC filter
*
* Adds or removes MAC address filter entry for VF VSI
*/
enum ice_status
ice_vsi_cfg_mac_fltr(struct ice_vsi *vsi, const u8 *macaddr, bool set)
{
LIST_HEAD(tmp_add_list);
enum ice_status status;
/* Update MAC filter list to be added or removed for a VSI */
if (ice_add_mac_to_list(vsi, &tmp_add_list, macaddr)) {
status = ICE_ERR_NO_MEMORY;
goto cfg_mac_fltr_exit;
}
if (set)
status = ice_add_mac(&vsi->back->hw, &tmp_add_list);
else
status = ice_remove_mac(&vsi->back->hw, &tmp_add_list);
cfg_mac_fltr_exit:
ice_free_fltr_list(ice_pf_to_dev(vsi->back), &tmp_add_list);
return status;
}
/** /**
* ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used * ice_is_dflt_vsi_in_use - check if the default forwarding VSI is being used
* @sw: switch to check if its default forwarding VSI is free * @sw: switch to check if its default forwarding VSI is free
......
...@@ -8,12 +8,6 @@ ...@@ -8,12 +8,6 @@
const char *ice_vsi_type_str(enum ice_vsi_type vsi_type); const char *ice_vsi_type_str(enum ice_vsi_type vsi_type);
int
ice_add_mac_to_list(struct ice_vsi *vsi, struct list_head *add_list,
const u8 *macaddr);
void ice_free_fltr_list(struct device *dev, struct list_head *h);
void ice_update_eth_stats(struct ice_vsi *vsi); void ice_update_eth_stats(struct ice_vsi *vsi);
int ice_vsi_cfg_rxqs(struct ice_vsi *vsi); int ice_vsi_cfg_rxqs(struct ice_vsi *vsi);
...@@ -22,7 +16,8 @@ int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi); ...@@ -22,7 +16,8 @@ int ice_vsi_cfg_lan_txqs(struct ice_vsi *vsi);
void ice_vsi_cfg_msix(struct ice_vsi *vsi); void ice_vsi_cfg_msix(struct ice_vsi *vsi);
int ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid); int
ice_vsi_add_vlan(struct ice_vsi *vsi, u16 vid, enum ice_sw_fwd_act_type action);
int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid); int ice_vsi_kill_vlan(struct ice_vsi *vsi, u16 vid);
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include "ice.h" #include "ice.h"
#include "ice_base.h" #include "ice_base.h"
#include "ice_lib.h" #include "ice_lib.h"
#include "ice_fltr.h"
#include "ice_dcb_lib.h" #include "ice_dcb_lib.h"
#include "ice_dcb_nl.h" #include "ice_dcb_nl.h"
#include "ice_devlink.h" #include "ice_devlink.h"
...@@ -133,32 +134,18 @@ static void ice_check_for_hang_subtask(struct ice_pf *pf) ...@@ -133,32 +134,18 @@ static void ice_check_for_hang_subtask(struct ice_pf *pf)
static int ice_init_mac_fltr(struct ice_pf *pf) static int ice_init_mac_fltr(struct ice_pf *pf)
{ {
enum ice_status status; enum ice_status status;
u8 broadcast[ETH_ALEN];
struct ice_vsi *vsi; struct ice_vsi *vsi;
u8 *perm_addr;
vsi = ice_get_main_vsi(pf); vsi = ice_get_main_vsi(pf);
if (!vsi) if (!vsi)
return -EINVAL; return -EINVAL;
/* To add a MAC filter, first add the MAC to a list and then perm_addr = vsi->port_info->mac.perm_addr;
* pass the list to ice_add_mac. status = ice_fltr_add_mac_and_broadcast(vsi, perm_addr, ICE_FWD_TO_VSI);
*/ if (!status)
return 0;
/* Add a unicast MAC filter so the VSI can get its packets */
status = ice_vsi_cfg_mac_fltr(vsi, vsi->port_info->mac.perm_addr, true);
if (status)
goto unregister;
/* VSI needs to receive broadcast traffic, so add the broadcast
* MAC address to the list as well.
*/
eth_broadcast_addr(broadcast);
status = ice_vsi_cfg_mac_fltr(vsi, broadcast, true);
if (status)
goto unregister;
return 0;
unregister:
/* We aren't useful with no MAC filters, so unregister if we /* We aren't useful with no MAC filters, so unregister if we
* had an error * had an error
*/ */
...@@ -188,7 +175,8 @@ static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr) ...@@ -188,7 +175,8 @@ static int ice_add_mac_to_sync_list(struct net_device *netdev, const u8 *addr)
struct ice_netdev_priv *np = netdev_priv(netdev); struct ice_netdev_priv *np = netdev_priv(netdev);
struct ice_vsi *vsi = np->vsi; struct ice_vsi *vsi = np->vsi;
if (ice_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr)) if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_sync_list, addr,
ICE_FWD_TO_VSI))
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -209,7 +197,8 @@ static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr) ...@@ -209,7 +197,8 @@ static int ice_add_mac_to_unsync_list(struct net_device *netdev, const u8 *addr)
struct ice_netdev_priv *np = netdev_priv(netdev); struct ice_netdev_priv *np = netdev_priv(netdev);
struct ice_vsi *vsi = np->vsi; struct ice_vsi *vsi = np->vsi;
if (ice_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr)) if (ice_fltr_add_mac_to_list(vsi, &vsi->tmp_unsync_list, addr,
ICE_FWD_TO_VSI))
return -EINVAL; return -EINVAL;
return 0; return 0;
...@@ -307,8 +296,8 @@ static int ice_vsi_sync_fltr(struct ice_vsi *vsi) ...@@ -307,8 +296,8 @@ static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
} }
/* Remove MAC addresses in the unsync list */ /* Remove MAC addresses in the unsync list */
status = ice_remove_mac(hw, &vsi->tmp_unsync_list); status = ice_fltr_remove_mac_list(vsi, &vsi->tmp_unsync_list);
ice_free_fltr_list(dev, &vsi->tmp_unsync_list); ice_fltr_free_list(dev, &vsi->tmp_unsync_list);
if (status) { if (status) {
netdev_err(netdev, "Failed to delete MAC filters\n"); netdev_err(netdev, "Failed to delete MAC filters\n");
/* if we failed because of alloc failures, just bail */ /* if we failed because of alloc failures, just bail */
...@@ -319,8 +308,8 @@ static int ice_vsi_sync_fltr(struct ice_vsi *vsi) ...@@ -319,8 +308,8 @@ static int ice_vsi_sync_fltr(struct ice_vsi *vsi)
} }
/* Add MAC addresses in the sync list */ /* Add MAC addresses in the sync list */
status = ice_add_mac(hw, &vsi->tmp_sync_list); status = ice_fltr_add_mac_list(vsi, &vsi->tmp_sync_list);
ice_free_fltr_list(dev, &vsi->tmp_sync_list); ice_fltr_free_list(dev, &vsi->tmp_sync_list);
/* If filter is added successfully or already exists, do not go into /* If filter is added successfully or already exists, do not go into
* 'if' condition and report it as error. Instead continue processing * 'if' condition and report it as error. Instead continue processing
* rest of the function. * rest of the function.
...@@ -2521,7 +2510,7 @@ ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto, ...@@ -2521,7 +2510,7 @@ ice_vlan_rx_add_vid(struct net_device *netdev, __always_unused __be16 proto,
/* Add a switch rule for this VLAN ID so its corresponding VLAN tagged /* Add a switch rule for this VLAN ID so its corresponding VLAN tagged
* packets aren't pruned by the device's internal switch on Rx * packets aren't pruned by the device's internal switch on Rx
*/ */
ret = ice_vsi_add_vlan(vsi, vid); ret = ice_vsi_add_vlan(vsi, vid, ICE_FWD_TO_VSI);
if (!ret) { if (!ret) {
vsi->vlan_ena = true; vsi->vlan_ena = true;
set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags); set_bit(ICE_VSI_FLAG_VLAN_FLTR_CHANGED, vsi->flags);
...@@ -3718,20 +3707,14 @@ static int ice_set_mac_address(struct net_device *netdev, void *pi) ...@@ -3718,20 +3707,14 @@ static int ice_set_mac_address(struct net_device *netdev, void *pi)
return -EBUSY; return -EBUSY;
} }
/* When we change the MAC address we also have to change the MAC address /* Clean up old MAC filter before changing the MAC address */
* based filter rules that were created previously for the old MAC status = ice_fltr_remove_mac(vsi, netdev->dev_addr, ICE_FWD_TO_VSI);
* address. So first, we remove the old filter rule using ice_remove_mac
* and then create a new filter rule using ice_add_mac via
* ice_vsi_cfg_mac_fltr function call for both add and/or remove
* filters.
*/
status = ice_vsi_cfg_mac_fltr(vsi, netdev->dev_addr, false);
if (status) { if (status) {
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto err_update_filters; goto err_update_filters;
} }
status = ice_vsi_cfg_mac_fltr(vsi, mac, true); status = ice_fltr_add_mac(vsi, mac, ICE_FWD_TO_VSI);
if (status) { if (status) {
err = -EADDRNOTAVAIL; err = -EADDRNOTAVAIL;
goto err_update_filters; goto err_update_filters;
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
#include "ice.h" #include "ice.h"
#include "ice_base.h" #include "ice_base.h"
#include "ice_lib.h" #include "ice_lib.h"
#include "ice_fltr.h"
/** /**
* ice_validate_vf_id - helper to check if VF ID is valid * ice_validate_vf_id - helper to check if VF ID is valid
...@@ -548,7 +549,6 @@ static int ice_calc_vf_first_vector_idx(struct ice_pf *pf, struct ice_vf *vf) ...@@ -548,7 +549,6 @@ static int ice_calc_vf_first_vector_idx(struct ice_pf *pf, struct ice_vf *vf)
static int ice_alloc_vsi_res(struct ice_vf *vf) static int ice_alloc_vsi_res(struct ice_vf *vf)
{ {
struct ice_pf *pf = vf->pf; struct ice_pf *pf = vf->pf;
LIST_HEAD(tmp_add_list);
u8 broadcast[ETH_ALEN]; u8 broadcast[ETH_ALEN];
struct ice_vsi *vsi; struct ice_vsi *vsi;
struct device *dev; struct device *dev;
...@@ -570,7 +570,8 @@ static int ice_alloc_vsi_res(struct ice_vf *vf) ...@@ -570,7 +570,8 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
/* Check if port VLAN exist before, and restore it accordingly */ /* Check if port VLAN exist before, and restore it accordingly */
if (vf->port_vlan_info) { if (vf->port_vlan_info) {
ice_vsi_manage_pvid(vsi, vf->port_vlan_info, true); ice_vsi_manage_pvid(vsi, vf->port_vlan_info, true);
if (ice_vsi_add_vlan(vsi, vf->port_vlan_info & VLAN_VID_MASK)) if (ice_vsi_add_vlan(vsi, vf->port_vlan_info & VLAN_VID_MASK,
ICE_FWD_TO_VSI))
dev_warn(ice_pf_to_dev(pf), "Failed to add Port VLAN %d filter for VF %d\n", dev_warn(ice_pf_to_dev(pf), "Failed to add Port VLAN %d filter for VF %d\n",
vf->port_vlan_info & VLAN_VID_MASK, vf->vf_id); vf->port_vlan_info & VLAN_VID_MASK, vf->vf_id);
} else { } else {
...@@ -579,27 +580,23 @@ static int ice_alloc_vsi_res(struct ice_vf *vf) ...@@ -579,27 +580,23 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
* untagged broadcast/multicast traffic seen on the VF * untagged broadcast/multicast traffic seen on the VF
* interface. * interface.
*/ */
if (ice_vsi_add_vlan(vsi, 0)) if (ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI))
dev_warn(ice_pf_to_dev(pf), "Failed to add VLAN 0 filter for VF %d, MDD events will trigger. Reset the VF, disable spoofchk, or enable 8021q module on the guest\n", dev_warn(ice_pf_to_dev(pf), "Failed to add VLAN 0 filter for VF %d, MDD events will trigger. Reset the VF, disable spoofchk, or enable 8021q module on the guest\n",
vf->vf_id); vf->vf_id);
} }
eth_broadcast_addr(broadcast);
status = ice_add_mac_to_list(vsi, &tmp_add_list, broadcast);
if (status)
goto ice_alloc_vsi_res_exit;
if (is_valid_ether_addr(vf->dflt_lan_addr.addr)) { if (is_valid_ether_addr(vf->dflt_lan_addr.addr)) {
status = ice_add_mac_to_list(vsi, &tmp_add_list, status = ice_fltr_add_mac(vsi, vf->dflt_lan_addr.addr,
vf->dflt_lan_addr.addr); ICE_FWD_TO_VSI);
if (status) if (status)
goto ice_alloc_vsi_res_exit; goto ice_alloc_vsi_res_exit;
} }
status = ice_add_mac(&pf->hw, &tmp_add_list); eth_broadcast_addr(broadcast);
status = ice_fltr_add_mac(vsi, broadcast, ICE_FWD_TO_VSI);
if (status) if (status)
dev_err(dev, "could not add mac filters error %d\n", status); dev_err(dev, "could not add mac filters error %d\n",
status);
else else
vf->num_mac = 1; vf->num_mac = 1;
...@@ -610,7 +607,6 @@ static int ice_alloc_vsi_res(struct ice_vf *vf) ...@@ -610,7 +607,6 @@ static int ice_alloc_vsi_res(struct ice_vf *vf)
* more vectors. * more vectors.
*/ */
ice_alloc_vsi_res_exit: ice_alloc_vsi_res_exit:
ice_free_fltr_list(dev, &tmp_add_list);
return status; return status;
} }
...@@ -2807,7 +2803,7 @@ ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi, u8 *mac_addr) ...@@ -2807,7 +2803,7 @@ ice_vc_add_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi, u8 *mac_addr)
return -EPERM; return -EPERM;
} }
status = ice_vsi_cfg_mac_fltr(vsi, mac_addr, true); status = ice_fltr_add_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
if (status == ICE_ERR_ALREADY_EXISTS) { if (status == ICE_ERR_ALREADY_EXISTS) {
dev_err(dev, "MAC %pM already exists for VF %d\n", mac_addr, dev_err(dev, "MAC %pM already exists for VF %d\n", mac_addr,
vf->vf_id); vf->vf_id);
...@@ -2844,7 +2840,7 @@ ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi, u8 *mac_addr) ...@@ -2844,7 +2840,7 @@ ice_vc_del_mac_addr(struct ice_vf *vf, struct ice_vsi *vsi, u8 *mac_addr)
ether_addr_equal(mac_addr, vf->dflt_lan_addr.addr)) ether_addr_equal(mac_addr, vf->dflt_lan_addr.addr))
return 0; return 0;
status = ice_vsi_cfg_mac_fltr(vsi, mac_addr, false); status = ice_fltr_remove_mac(vsi, mac_addr, ICE_FWD_TO_VSI);
if (status == ICE_ERR_DOES_NOT_EXIST) { if (status == ICE_ERR_DOES_NOT_EXIST) {
dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr, dev_err(dev, "MAC %pM does not exist for VF %d\n", mac_addr,
vf->vf_id); vf->vf_id);
...@@ -3088,7 +3084,7 @@ ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos, ...@@ -3088,7 +3084,7 @@ ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
/* add VLAN 0 filter back when transitioning from port VLAN to /* add VLAN 0 filter back when transitioning from port VLAN to
* no port VLAN. No change to old port VLAN on failure. * no port VLAN. No change to old port VLAN on failure.
*/ */
ret = ice_vsi_add_vlan(vsi, 0); ret = ice_vsi_add_vlan(vsi, 0, ICE_FWD_TO_VSI);
if (ret) if (ret)
return ret; return ret;
ret = ice_vsi_manage_pvid(vsi, 0, false); ret = ice_vsi_manage_pvid(vsi, 0, false);
...@@ -3101,7 +3097,7 @@ ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos, ...@@ -3101,7 +3097,7 @@ ice_set_vf_port_vlan(struct net_device *netdev, int vf_id, u16 vlan_id, u8 qos,
vlan_id, qos, vf_id); vlan_id, qos, vf_id);
/* add VLAN filter for the port VLAN */ /* add VLAN filter for the port VLAN */
ret = ice_vsi_add_vlan(vsi, vlan_id); ret = ice_vsi_add_vlan(vsi, vlan_id, ICE_FWD_TO_VSI);
if (ret) if (ret)
return ret; return ret;
} }
...@@ -3222,7 +3218,7 @@ static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v) ...@@ -3222,7 +3218,7 @@ static int ice_vc_process_vlan_msg(struct ice_vf *vf, u8 *msg, bool add_v)
if (!vid) if (!vid)
continue; continue;
status = ice_vsi_add_vlan(vsi, vid); status = ice_vsi_add_vlan(vsi, vid, ICE_FWD_TO_VSI);
if (status) { if (status) {
v_ret = VIRTCHNL_STATUS_ERR_PARAM; v_ret = VIRTCHNL_STATUS_ERR_PARAM;
goto error_param; goto error_param;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment