ice: switchdev bridge offload
Subsystems (3)
Wojciech Drewek says:
Linux bridge provides ability to learn MAC addresses and vlans detected on bridge's ports. As a result of this, FDB (forward data base) entries are created and they can be offloaded to the HW. By adding VF's port representors to the bridge together with the uplink netdev, we can learn VF's and link partner's MAC addresses. This is achieved by slow/exception-path, where packets that do not match any filters (FDB entries in this case) are send to the bridge ports.
Driver keeps track of the netdevs added to the bridge
by listening for NETDEV_CHANGEUPPER event. We distinguish two types of bridge ports: uplink port and VF's representor port. Linux bridge always learns src MAC of the packet on rx path. With the current slow-path implementation, it means that we will learn VF's MAC on port repr (when the VF transmits the packet) and link partner's MAC on uplink (when we receive it on uplink from LAN).
The driver is notified about learning of the MAC/VLAN by SWITCHDEV_FDB_{ADD|DEL}_TO_DEVICE events. This is followed by creation of the HW filter. The direction of the filter is based on port type (uplink or VF repr). In case of the uplink, rule forwards the packets to the LAN (matching on link partner's MAC). When the notification is received on VF repr then the rule forwards the packets to the associated VF (matching on VF's MAC).
This approach would not work on its own however. This is because if one of the directions is offloaded, then the bridge would not be able to learn the other one. If the egress rule is added (learned on uplink) then the response from the VF will be sent directly to the LAN. The packet will not got through slow-path, it would not be seen on VF's port repr. Because of that, the bridge would not learn VF's MAC.
This is solved by introducing guard rule. It prevents forward rule from working until the opposite direction is offloaded.
Aging is not fully supported yet, aging time is static for now. The follow up submissions will introduce counters that will allow us to keep track if the rule is actually being used or not.
A few fixes/changes are needed for this feature to work with ice driver. These are introduced in first 5 patches.
---
v2: delete FDB entries associated with deleted vlan
add missing vlan_ops calls when clearing pvid
v1: https://lore.kernel.org/netdev/[email protected]/
The following are changes since commit 5322a27c0d461ab3938dd513b1672b86ee722da7:
Merge branch 'ionic-FLR-support'
and are available in the git repository at:
git://git.kernel.org/pub/scm/linux/kernel/git/tnguy/next-queue 100GbE
Marcin Szycik (2):
ice: Add guard rule when creating FDB in switchdev
ice: Add VLAN FDB support in switchdev mode
Michal Swiatkowski (2):
ice: implement bridge port vlan
ice: implement static version of ageing
Pawel Chmielewski (1):
ice: add tracepoints for the switchdev bridge
Wojciech Drewek (7):
ice: Skip adv rules removal upon switchdev release
ice: Prohibit rx mode change in switchdev mode
ice: Don't tx before switchdev is fully configured
ice: Disable vlan pruning for uplink VSI
ice: Unset src prune on uplink VSI
ice: Implement basic eswitch bridge setup
ice: Switchdev FDB events support
drivers/net/ethernet/intel/ice/Makefile | 2 +- drivers/net/ethernet/intel/ice/ice.h | 5 +- drivers/net/ethernet/intel/ice/ice_eswitch.c | 46 +- .../net/ethernet/intel/ice/ice_eswitch_br.c | 1309 +++++++++++++++++ .../net/ethernet/intel/ice/ice_eswitch_br.h | 120 ++ drivers/net/ethernet/intel/ice/ice_lib.c | 25 + drivers/net/ethernet/intel/ice/ice_lib.h | 1 + drivers/net/ethernet/intel/ice/ice_main.c | 4 +- drivers/net/ethernet/intel/ice/ice_repr.c | 2 +- drivers/net/ethernet/intel/ice/ice_repr.h | 3 +- drivers/net/ethernet/intel/ice/ice_switch.c | 150 +- drivers/net/ethernet/intel/ice/ice_switch.h | 6 +- drivers/net/ethernet/intel/ice/ice_trace.h | 90 ++ drivers/net/ethernet/intel/ice/ice_type.h | 1 + .../ethernet/intel/ice/ice_vf_vsi_vlan_ops.c | 186 +-- .../ethernet/intel/ice/ice_vf_vsi_vlan_ops.h | 4 + .../net/ethernet/intel/ice/ice_vsi_vlan_lib.c | 84 +- .../net/ethernet/intel/ice/ice_vsi_vlan_lib.h | 8 + .../net/ethernet/intel/ice/ice_vsi_vlan_ops.h | 1 + 19 files changed, 1861 insertions(+), 186 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_eswitch_br.c create mode 100644 drivers/net/ethernet/intel/ice/ice_eswitch_br.h
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 1/12 ice: Skip adv rules removal upon switchdev release
From: Wojciech Drewek <[email protected]>
Advanced rules for ctrl VSI will be removed anyway when the VSI will cleaned up, no need to do it explicitly.
--- drivers/net/ethernet/intel/ice/ice_eswitch.c | 1 - drivers/net/ethernet/intel/ice/ice_switch.c | 53 -------------------- drivers/net/ethernet/intel/ice/ice_switch.h | 1 - 3 files changed, 55 deletions(-)
drivers/net/ethernet/intel/ice/ice_eswitch.c +0 -1
@@ -503,7 +503,6 @@ static void ice_eswitch_disable_switchdev(struct ice_pf *pf)ice_eswitch_napi_disable (pf);ice_eswitch_release_env (pf); -ice_rem_adv_rule_for_vsi (&pf->hw, ctrl_vsi->idx);ice_eswitch_release_reprs (pf, ctrl_vsi);ice_vsi_release (ctrl_vsi);ice_repr_rem_from_all_vfs (pf);
drivers/net/ethernet/intel/ice/ice_switch.c +0 -53
59 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_switch.h +0 -1
@@ -379,7 +379,6 @@ int ice_set_vlan_vsi_promisc(struct ice_hw *hw, u16 vsi_handle, u8 promisc_mask, bool rm_vlan_promisc); -int ice_rem_adv_rule_for_vsi (struct ice_hw *hw,u16 vsi_handle);int ice_rem_adv_rule_by_id (struct ice_hw *hw,struct ice_rule_query_data *remove_entry);
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 2/12 ice: Prohibit rx mode change in switchdev mode
In reply to Tony NguyenFrom: Wojciech Drewek <[email protected]>
Don't allow to change promisc mode in switchdev mode. When switchdev is configured, PF netdev is set to be a default VSI. This is needed for the slow-path to work correctly. All the unmatched packets will be directed to PF netdev.
It is possible that this setting might be overwritten by ndo_set_rx_mode. Prevent this by checking if switchdev is enabled in ice_set_rx_mode.
--- drivers/net/ethernet/intel/ice/ice_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
@@ -5704,7 +5704,7 @@ static void ice_set_rx_mode(struct net_device *netdev)struct ice_netdev_priv *np =netdev_priv (netdev);struct ice_vsi *vsi = np->vsi; -if (!vsi) +if (!vsi ||ice_is_switchdev_running (vsi->back))return ;/* Set the flags to synchronize filters
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 3/12 ice: Don't tx before switchdev is fully configured
In reply to Tony NguyenFrom: Wojciech Drewek <[email protected]>
There is possibility that ice_eswitch_port_start_xmit might be called while some resources are still not allocated which might cause NULL pointer dereference. Fix this by checking if switchdev configuration was finished.
--- drivers/net/ethernet/intel/ice/ice_eswitch.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/net/ethernet/intel/ice/ice_eswitch.c +3 -0
@@ -331,6 +331,9 @@ ice_eswitch_port_start_xmit(struct sk_buff *skb, struct net_device *netdev) np =netdev_priv (netdev); vsi = np->vsi; +if (!vsi || !ice_is_switchdev_running (vsi->back)) +return NETDEV_TX_BUSY ; +if (ice_is_reset_in_progress (vsi->back->state) ||test_bit (ICE_VF_DIS , vsi->back->state))return NETDEV_TX_BUSY ;
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 4/12 ice: Disable vlan pruning for uplink VSI
In reply to Tony NguyenFrom: Wojciech Drewek <[email protected]>
In switchdev mode, uplink VSI is configured to be default VSI which means it will receive all unmatched packets. In order to receive vlan packets we need to disable vlan pruning as well. This is done by dis_rx_filtering vlan op.
--- drivers/net/ethernet/intel/ice/ice_eswitch.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/net/ethernet/intel/ice/ice_eswitch.c +10 -0
@@ -103,6 +103,10 @@ static int ice_eswitch_setup_env(struct ice_pf *pf) rule_added = true; } + vlan_ops =ice_get_compat_vsi_vlan_ops (uplink_vsi); +if (vlan_ops->dis_rx_filtering (uplink_vsi)) + goto err_dis_rx; +if (ice_vsi_update_security (uplink_vsi, ice_vsi_ctx_set_allow_override)) goto err_override_uplink;
@@ -114,6 +118,8 @@ static int ice_eswitch_setup_env(struct ice_pf *pf) err_override_control:ice_vsi_update_security (uplink_vsi, ice_vsi_ctx_clear_allow_override); err_override_uplink: + vlan_ops->ena_rx_filtering (uplink_vsi); +err_dis_rx:if (rule_added)ice_clear_dflt_vsi (uplink_vsi); err_def_rx:
@@ -381,9 +387,13 @@ static void ice_eswitch_release_env(struct ice_pf *pf) {struct ice_vsi *uplink_vsi = pf->switchdev.uplink_vsi;struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi; +struct ice_vsi_vlan_ops *vlan_ops; + + vlan_ops =ice_get_compat_vsi_vlan_ops (uplink_vsi);ice_vsi_update_security (ctrl_vsi, ice_vsi_ctx_clear_allow_override);ice_vsi_update_security (uplink_vsi, ice_vsi_ctx_clear_allow_override); + vlan_ops->ena_rx_filtering (uplink_vsi);ice_clear_dflt_vsi (uplink_vsi); ice_fltr_add_mac_and_broadcast(uplink_vsi, uplink_vsi->port_info->mac.perm_addr,
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 5/12 ice: Unset src prune on uplink VSI
In reply to Tony NguyenFrom: Wojciech Drewek <[email protected]>
In switchdev mode uplink VSI is supposed to receive all packets that were not matched by existing filters. If ICE_AQ_VSI_SW_FLAG_LOCAL_LB bit is unset and we have a filter associated with uplink VSI which matches on dst mac equal to MAC1, then packets with src mac equal to MAC1 will be pruned from reaching uplink VSI.
Fix this by updating uplink VSI with ICE_AQ_VSI_SW_FLAG_LOCAL_LB bit set when configuring switchdev mode.
--- drivers/net/ethernet/intel/ice/ice_eswitch.c | 6 +++++ drivers/net/ethernet/intel/ice/ice_lib.c | 25 ++++++++++++++++++++ drivers/net/ethernet/intel/ice/ice_lib.h | 1 + 3 files changed, 32 insertions(+)
drivers/net/ethernet/intel/ice/ice_eswitch.c +6 -0
@@ -113,8 +113,13 @@ static int ice_eswitch_setup_env(struct ice_pf *pf)if (ice_vsi_update_security (ctrl_vsi, ice_vsi_ctx_set_allow_override)) goto err_override_control; +if (ice_vsi_update_local_lb (uplink_vsi, true)) + goto err_override_local_lb; +return 0 ; +err_override_local_lb: +ice_vsi_update_security (ctrl_vsi, ice_vsi_ctx_clear_allow_override); err_override_control:ice_vsi_update_security (uplink_vsi, ice_vsi_ctx_clear_allow_override); err_override_uplink:
@@ -391,6 +396,7 @@ static void ice_eswitch_release_env(struct ice_pf *pf) vlan_ops =ice_get_compat_vsi_vlan_ops (uplink_vsi); +ice_vsi_update_local_lb (uplink_vsi, false);ice_vsi_update_security (ctrl_vsi, ice_vsi_ctx_clear_allow_override);ice_vsi_update_security (uplink_vsi, ice_vsi_ctx_clear_allow_override); vlan_ops->ena_rx_filtering (uplink_vsi);
drivers/net/ethernet/intel/ice/ice_lib.c +25 -0
@@ -4076,3 +4076,28 @@ void ice_vsi_ctx_clear_allow_override(struct ice_vsi_ctx *ctx) { ctx->info.sec_flags &= ~ICE_AQ_VSI_SEC_FLAG_ALLOW_DEST_OVRD ; } + +/** +* ice_vsi_update_local_lb - update sw block in VSI with local loopback bit +* @vsi: pointer to VSI structure +* @set: set or unset the bit +*/ +int +ice_vsi_update_local_lb (struct ice_vsi *vsi,bool set) +{ +struct ice_vsi_ctx ctx = { + .info = vsi->info, + }; + + ctx.info.valid_sections =cpu_to_le16 (ICE_AQ_VSI_PROP_SW_VALID ); +if (set) + ctx.info.sw_flags |=ICE_AQ_VSI_SW_FLAG_LOCAL_LB ; +else + ctx.info.sw_flags &= ~ICE_AQ_VSI_SW_FLAG_LOCAL_LB ; + +if (ice_update_vsi (&vsi->back->hw, vsi->idx, &ctx,NULL )) +return -ENODEV ; + + vsi->info = ctx.info; +return 0 ; +}
drivers/net/ethernet/intel/ice/ice_lib.h +1 -0
@@ -157,6 +157,7 @@ void ice_vsi_ctx_clear_antispoof(struct ice_vsi_ctx *ctx);void ice_vsi_ctx_set_allow_override (struct ice_vsi_ctx *ctx);void ice_vsi_ctx_clear_allow_override (struct ice_vsi_ctx *ctx); +int ice_vsi_update_local_lb (struct ice_vsi *vsi,bool set);int ice_vsi_add_vlan_zero (struct ice_vsi *vsi);int ice_vsi_del_vlan_zero (struct ice_vsi *vsi);bool ice_vsi_has_non_zero_vlans (struct ice_vsi *vsi);
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 6/12 ice: Implement basic eswitch bridge setup
In reply to Tony NguyenFrom: Wojciech Drewek <[email protected]>
With this patch, ice driver is able to track if the port representors or uplink port were added to the linux bridge in switchdev mode. Listen for NETDEV_CHANGEUPPER events in order to detect this. ice_esw_br data structure reflects the linux bridge and stores all the ports of the bridge (ice_esw_br_port) in xarray, it's created when the first port is added to the bridge and freed once the last port is removed. Note that only one bridge is supported per eswitch.
Bridge port (ice_esw_br_port) can be either a VF port representor port or uplink port (ice_esw_br_port_type). In both cases bridge port holds a reference to the VSI, VF's VSI in case of the PR and uplink VSI in case of the uplink. VSI's index is used as an index to the xarray in which ports are stored.
Add a check which prevents configuring switchdev mode if uplink is already added to any bridge. This is needed because we need to listen for NETDEV_CHANGEUPPER events to record if the uplink was added to the bridge. Netdevice notifier is registered after eswitch mode is changed to switchdev.
--- drivers/net/ethernet/intel/ice/Makefile | 2 +- drivers/net/ethernet/intel/ice/ice.h | 4 +- drivers/net/ethernet/intel/ice/ice_eswitch.c | 26 +- .../net/ethernet/intel/ice/ice_eswitch_br.c | 384 ++++++++++++++++++ .../net/ethernet/intel/ice/ice_eswitch_br.h | 42 ++ drivers/net/ethernet/intel/ice/ice_main.c | 2 +- drivers/net/ethernet/intel/ice/ice_repr.c | 2 +- drivers/net/ethernet/intel/ice/ice_repr.h | 3 +- 8 files changed, 456 insertions(+), 9 deletions(-) create mode 100644 drivers/net/ethernet/intel/ice/ice_eswitch_br.c create mode 100644 drivers/net/ethernet/intel/ice/ice_eswitch_br.h
drivers/net/ethernet/intel/ice/Makefile +1 -1
@@ -47,5 +47,5 @@ ice-$(CONFIG_PTP_1588_CLOCK) += ice_ptp.o ice_ptp_hw.o ice-$(CONFIG_DCB) += ice_dcb.o ice_dcb_nl.o ice_dcb_lib.o ice-$(CONFIG_RFS_ACCEL) += ice_arfs.o ice-$(CONFIG_XDP_SOCKETS) += ice_xsk.o -ice-$(CONFIG_ICE_SWITCHDEV) += ice_eswitch.o +ice-$(CONFIG_ICE_SWITCHDEV) += ice_eswitch.o ice_eswitch_br.o ice-$(CONFIG_GNSS) += ice_gnss.o
drivers/net/ethernet/intel/ice/ice.h +3 -1
@@ -517,6 +517,7 @@ enum ice_misc_thread_tasks {struct ice_switchdev_info {struct ice_vsi *control_vsi;struct ice_vsi *uplink_vsi; +struct ice_esw_br_offloads *br_offloads;bool is_running; };
@@ -626,6 +627,7 @@ struct ice_pf {struct ice_lag *lag;/* Link Aggregation information */ struct ice_switchdev_info switchdev; +struct ice_esw_br_port *br_port;#define ICE_INVALID_AGG_NODE_ID 0#define ICE_PF_AGG_NODE_ID_START 1
@@ -853,7 +855,7 @@ static inline bool ice_is_adq_active(struct ice_pf *pf)return false; } -bool netif_is_ice (struct net_device *dev); +bool netif_is_ice (const struct net_device *dev);int ice_vsi_setup_tx_rings (struct ice_vsi *vsi);int ice_vsi_setup_rx_rings (struct ice_vsi *vsi);int ice_vsi_open_ctrl (struct ice_vsi *vsi);
drivers/net/ethernet/intel/ice/ice_eswitch.c +22 -4
@@ -4,6 +4,7 @@#include "ice.h" #include "ice_lib.h" #include "ice_eswitch.h" +#include "ice_eswitch_br.h" #include "ice_fltr.h" #include "ice_repr.h" #include "ice_devlink.h"
@@ -317,6 +318,9 @@ void ice_eswitch_update_repr(struct ice_vsi *vsi) repr->src_vsi = vsi; repr->dst->u.port_info.port_id = vsi->vsi_num; +if (repr->br_port) + repr->br_port->vsi = vsi; + ret =ice_vsi_update_security (vsi, ice_vsi_ctx_clear_antispoof);if (ret) {ice_fltr_add_mac_and_broadcast (vsi, vf->hw_lan_addr,ICE_FWD_TO_VSI );
@@ -474,16 +478,24 @@ static void ice_eswitch_napi_disable(struct ice_pf *pf)*/ static int ice_eswitch_enable_switchdev (struct ice_pf *pf) { -struct ice_vsi *ctrl_vsi; +struct ice_vsi *ctrl_vsi, *uplink_vsi; + + uplink_vsi =ice_get_main_vsi (pf); +if (!uplink_vsi) +return -ENODEV ; + +if (netif_is_any_bridge_port (uplink_vsi->netdev)) { +dev_err (ice_pf_to_dev (pf), +"Uplink port cannot be a bridge port\n" ); +return -EINVAL ; + } pf->switchdev.control_vsi =ice_eswitch_vsi_setup (pf, pf->hw.port_info);if (!pf->switchdev.control_vsi)return -ENODEV ; ctrl_vsi = pf->switchdev.control_vsi; - pf->switchdev.uplink_vsi =ice_get_main_vsi (pf); -if (!pf->switchdev.uplink_vsi) - goto err_vsi; + pf->switchdev.uplink_vsi = uplink_vsi;if (ice_eswitch_setup_env (pf)) goto err_vsi;
@@ -499,10 +511,15 @@ static int ice_eswitch_enable_switchdev(struct ice_pf *pf)if (ice_vsi_open (ctrl_vsi)) goto err_setup_reprs; +if (ice_eswitch_br_offloads_init (pf)) + goto err_br_offloads; +ice_eswitch_napi_enable (pf);return 0 ; +err_br_offloads: +ice_vsi_close (ctrl_vsi); err_setup_reprs:ice_repr_rem_from_all_vfs (pf); err_repr_add:
@@ -521,6 +538,7 @@ static void ice_eswitch_disable_switchdev(struct ice_pf *pf)struct ice_vsi *ctrl_vsi = pf->switchdev.control_vsi;ice_eswitch_napi_disable (pf); +ice_eswitch_br_offloads_deinit (pf);ice_eswitch_release_env (pf);ice_eswitch_release_reprs (pf, ctrl_vsi);ice_vsi_release (ctrl_vsi);
drivers/net/ethernet/intel/ice/ice_eswitch_br.c new file +384 -0
384 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_eswitch_br.h new file +42 -0
42 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_main.c +1 -1
@@ -80,7 +80,7 @@ ice_indr_setup_tc_cb(struct net_device *netdev, struct Qdisc *sch,void *data, void (*cleanup)(struct flow_block_cb *block_cb)); -bool netif_is_ice (struct net_device *dev) +bool netif_is_ice (const struct net_device *dev) {return dev && (dev->netdev_ops == &ice_netdev_ops); }
drivers/net/ethernet/intel/ice/ice_repr.c +1 -1
@@ -254,7 +254,7 @@ static const struct net_device_ops ice_repr_netdev_ops = {* ice_is_port_repr_netdev - Check if a given netdevice is a port representor netdev * @netdev: pointer to netdev */ -bool ice_is_port_repr_netdev (struct net_device *netdev) +bool ice_is_port_repr_netdev (const struct net_device *netdev) {return netdev && (netdev->netdev_ops == &ice_repr_netdev_ops); }
drivers/net/ethernet/intel/ice/ice_repr.h +2 -1
@@ -12,6 +12,7 @@ struct ice_repr {struct ice_q_vector *q_vector;struct net_device *netdev;struct metadata_dst *dst; +struct ice_esw_br_port *br_port;#ifdef CONFIG_ICE_SWITCHDEV /* info about slow path rule */ struct ice_rule_query_data sp_rule;
@@ -27,5 +28,5 @@ void ice_repr_stop_tx_queues(struct ice_repr *repr);void ice_repr_set_traffic_vsi (struct ice_repr *repr,struct ice_vsi *vsi);struct ice_repr *ice_netdev_to_repr (struct net_device *netdev); -bool ice_is_port_repr_netdev (struct net_device *netdev); +bool ice_is_port_repr_netdev (const struct net_device *netdev);#endif
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 7/12 ice: Switchdev FDB events support
In reply to Tony NguyenFrom: Wojciech Drewek <[email protected]>
Listen for SWITCHDEV_FDB_{ADD|DEL}_TO_DEVICE events while in switchdev mode. Accept these events on both uplink and VF PR ports. Add HW rules in newly created workqueue. FDB entries are stored in rhashtable for lookup when removing the entry and in the list for cleanup purpose. Direction of the HW rule depends on the type of the ports on which the FDB event was received:
ICE_ESWITCH_BR_UPLINK_PORT:
TX rule that forwards the packet to the LAN (egress).
ICE_ESWITCH_BR_VF_REPR_PORT:
RX rule that forwards the packet to the VF associated with the port representor.
In both cases the rule matches on the dst mac address.
All the FDB entries are stored in the bridge structure.
When the port is removed all the FDB entries associated with this port are removed as well. This is achieved thanks to the reference to the port that FDB entry holds.
In the fwd rule we use only one lookup type (MAC address) but lkups_cnt variable is already introduced because we will have more lookups in the subsequent patches.
--- .../net/ethernet/intel/ice/ice_eswitch_br.c | 433 ++++++++++++++++++ .../net/ethernet/intel/ice/ice_eswitch_br.h | 45 ++ 2 files changed, 478 insertions(+)
drivers/net/ethernet/intel/ice/ice_eswitch_br.c +433 -0
@@ -4,6 +4,14 @@#include "ice.h" #include "ice_eswitch_br.h" #include "ice_repr.h" +#include "ice_switch.h" + +static const struct rhashtable_params ice_fdb_ht_params = { + .key_offset = offsetof(struct ice_esw_br_fdb_entry , data), + .key_len =sizeof (struct ice_esw_br_fdb_data ), + .head_offset = offsetof(struct ice_esw_br_fdb_entry , ht_node), + .automatic_shrinking = true, +};static bool ice_eswitch_br_is_dev_valid (const struct net_device *dev) {
@@ -27,12 +35,405 @@ ice_eswitch_br_netdev_to_port(struct net_device *dev)return NULL ; } +static void +ice_eswitch_br_ingress_rule_setup (struct ice_adv_rule_info *rule_info, +u8 pf_id,u16 vf_vsi_idx) +{ + rule_info->sw_act.vsi_handle = vf_vsi_idx; + rule_info->sw_act.flag |=ICE_FLTR_RX ; + rule_info->sw_act.src = pf_id; + rule_info->priority =5 ; +} + +static void +ice_eswitch_br_egress_rule_setup (struct ice_adv_rule_info *rule_info, +u16 pf_vsi_idx) +{ + rule_info->sw_act.vsi_handle = pf_vsi_idx; + rule_info->sw_act.flag |=ICE_FLTR_TX ; + rule_info->flags_info.act =ICE_SINGLE_ACT_LAN_ENABLE ; + rule_info->flags_info.act_valid = true; + rule_info->priority =5 ; +} + +static int +ice_eswitch_br_rule_delete (struct ice_hw *hw,struct ice_rule_query_data *rule) +{ +int err; + +if (!rule) +return -EINVAL ; + + err =ice_rem_adv_rule_by_id (hw, rule); +kfree (rule); + +return err; +} + +static struct ice_rule_query_data * +ice_eswitch_br_fwd_rule_create (struct ice_hw *hw,int vsi_idx,int port_type, +const unsigned char *mac) +{ +struct ice_adv_rule_info rule_info = {0 }; +struct ice_rule_query_data *rule; +struct ice_adv_lkup_elem *list; +u16 lkups_cnt =1 ; +int err; + + rule =kzalloc (sizeof (*rule),GFP_KERNEL ); +if (!rule) +return ERR_PTR (-ENOMEM ); + + list =kcalloc (lkups_cnt,sizeof (*list),GFP_ATOMIC ); +if (!list) { + err = -ENOMEM ; + goto err_list_alloc; + } + +switch (port_type) { +case ICE_ESWITCH_BR_UPLINK_PORT : +ice_eswitch_br_egress_rule_setup (&rule_info, vsi_idx); +break ; +case ICE_ESWITCH_BR_VF_REPR_PORT : +ice_eswitch_br_ingress_rule_setup (&rule_info, hw->pf_id, + vsi_idx); +break ; +default : + err = -EINVAL ; + goto err_add_rule; + } + + list[0 ].type =ICE_MAC_OFOS ; +ether_addr_copy (list[0 ].h_u.eth_hdr.dst_addr, mac); +eth_broadcast_addr (list[0 ].m_u.eth_hdr.dst_addr); + + rule_info.sw_act.fltr_act =ICE_FWD_TO_VSI ; + + err =ice_add_adv_rule (hw, list, lkups_cnt, &rule_info, rule); +if (err) + goto err_add_rule; + +kfree (list); + +return rule; + +err_add_rule: +kfree (list); +err_list_alloc: +kfree (rule); + +return ERR_PTR (err); +} + +static struct ice_esw_br_flow * +ice_eswitch_br_flow_create (struct device *dev,struct ice_hw *hw,int vsi_idx, +int port_type,const unsigned char *mac) +{ +struct ice_rule_query_data *fwd_rule; +struct ice_esw_br_flow *flow; +int err; + + flow =kzalloc (sizeof (*flow),GFP_KERNEL ); +if (!flow) +return ERR_PTR (-ENOMEM ); + + fwd_rule =ice_eswitch_br_fwd_rule_create (hw, vsi_idx, port_type, mac); + err =PTR_ERR_OR_ZERO (fwd_rule); +if (err) { +dev_err (dev,"Failed to create eswitch bridge %sgress forward rule, err: %d\n" , + port_type ==ICE_ESWITCH_BR_UPLINK_PORT ?"e" :"in" , + err); + goto err_fwd_rule; + } + + flow->fwd_rule = fwd_rule; + +return flow; + +err_fwd_rule: +kfree (flow); + +return ERR_PTR (err); +} + +static struct ice_esw_br_fdb_entry * +ice_eswitch_br_fdb_find (struct ice_esw_br *bridge,const unsigned char *mac, +u16 vid) +{ +struct ice_esw_br_fdb_data data = { + .vid = vid, + }; + +ether_addr_copy (data.addr, mac); +return rhashtable_lookup_fast (&bridge->fdb_ht, &data, + ice_fdb_ht_params); +} + +static void +ice_eswitch_br_flow_delete (struct ice_pf *pf,struct ice_esw_br_flow *flow) +{ +struct device *dev =ice_pf_to_dev (pf); +int err; + + err =ice_eswitch_br_rule_delete (&pf->hw, flow->fwd_rule); +if (err) +dev_err (dev,"Failed to delete FDB forward rule, err: %d\n" , + err); + +kfree (flow); +} + +static void +ice_eswitch_br_fdb_entry_delete (struct ice_esw_br *bridge, +struct ice_esw_br_fdb_entry *fdb_entry) +{ +struct ice_pf *pf = bridge->br_offloads->pf; + +rhashtable_remove_fast (&bridge->fdb_ht, &fdb_entry->ht_node, + ice_fdb_ht_params); +list_del (&fdb_entry->list); + +ice_eswitch_br_flow_delete (pf, fdb_entry->flow); + +kfree (fdb_entry); +} + +static void +ice_eswitch_br_fdb_offload_notify (struct net_device *dev, +const unsigned char *mac,u16 vid, +unsigned long val) +{ +struct switchdev_notifier_fdb_info fdb_info = { + .addr = mac, + .vid = vid, + .offloaded = true, + }; + +call_switchdev_notifiers (val, dev, &fdb_info.info,NULL ); +} + +static void +ice_eswitch_br_fdb_entry_notify_and_cleanup (struct ice_esw_br *bridge, +struct ice_esw_br_fdb_entry *entry) +{ +if (!(entry->flags &ICE_ESWITCH_BR_FDB_ADDED_BY_USER )) +ice_eswitch_br_fdb_offload_notify (entry->dev, entry->data.addr, + entry->data.vid, +SWITCHDEV_FDB_DEL_TO_BRIDGE ); +ice_eswitch_br_fdb_entry_delete (bridge, entry); +} + +static void +ice_eswitch_br_fdb_entry_find_and_delete (struct ice_esw_br *bridge, +const unsigned char *mac,u16 vid) +{ +struct ice_pf *pf = bridge->br_offloads->pf; +struct ice_esw_br_fdb_entry *fdb_entry; +struct device *dev =ice_pf_to_dev (pf); + + fdb_entry =ice_eswitch_br_fdb_find (bridge, mac, vid); +if (!fdb_entry) { +dev_err (dev,"FDB entry with mac: %pM and vid: %u not found\n" , + mac, vid); +return ; + } + +ice_eswitch_br_fdb_entry_notify_and_cleanup (bridge, fdb_entry); +} + +static void +ice_eswitch_br_fdb_entry_create (struct net_device *netdev, +struct ice_esw_br_port *br_port, +bool added_by_user, +const unsigned char *mac,u16 vid) +{ +struct ice_esw_br *bridge = br_port->bridge; +struct ice_pf *pf = bridge->br_offloads->pf; +struct device *dev =ice_pf_to_dev (pf); +struct ice_esw_br_fdb_entry *fdb_entry; +struct ice_esw_br_flow *flow; +struct ice_hw *hw = &pf->hw; +unsigned long event; +int err; + + fdb_entry =ice_eswitch_br_fdb_find (bridge, mac, vid); +if (fdb_entry) +ice_eswitch_br_fdb_entry_notify_and_cleanup (bridge, fdb_entry); + + fdb_entry =kzalloc (sizeof (*fdb_entry),GFP_KERNEL ); +if (!fdb_entry) { + err = -ENOMEM ; + goto err_exit; + } + + flow =ice_eswitch_br_flow_create (dev, hw, br_port->vsi_idx, + br_port->type, mac); +if (IS_ERR (flow)) { + err =PTR_ERR (flow); + goto err_add_flow; + } + +ether_addr_copy (fdb_entry->data.addr, mac); + fdb_entry->data.vid = vid; + fdb_entry->br_port = br_port; + fdb_entry->flow = flow; + fdb_entry->dev = netdev; + event =SWITCHDEV_FDB_ADD_TO_BRIDGE ; + +if (added_by_user) { + fdb_entry->flags |=ICE_ESWITCH_BR_FDB_ADDED_BY_USER ; + event =SWITCHDEV_FDB_OFFLOADED ; + } + + err =rhashtable_insert_fast (&bridge->fdb_ht, &fdb_entry->ht_node, + ice_fdb_ht_params); +if (err) + goto err_fdb_insert; + +list_add (&fdb_entry->list, &bridge->fdb_list); + +ice_eswitch_br_fdb_offload_notify (netdev, mac, vid, event); + +return ; + +err_fdb_insert: +ice_eswitch_br_flow_delete (pf, flow); +err_add_flow: +kfree (fdb_entry); +err_exit: +dev_err (dev,"Failed to create fdb entry, err: %d\n" , err); +} + +static void +ice_eswitch_br_fdb_work_dealloc (struct ice_esw_br_fdb_work *fdb_work) +{ +kfree (fdb_work->fdb_info.addr); +kfree (fdb_work); +} + +static void +ice_eswitch_br_fdb_event_work (struct work_struct *work) +{ +struct ice_esw_br_fdb_work *fdb_work =ice_work_to_fdb_work (work); +bool added_by_user = fdb_work->fdb_info.added_by_user; +const unsigned char *mac = fdb_work->fdb_info.addr; +u16 vid = fdb_work->fdb_info.vid; +struct ice_esw_br_port *br_port; + +rtnl_lock (); + + br_port =ice_eswitch_br_netdev_to_port (fdb_work->dev); +if (!br_port) + goto err_exit; + +switch (fdb_work->event) { +case SWITCHDEV_FDB_ADD_TO_DEVICE : +ice_eswitch_br_fdb_entry_create (fdb_work->dev, br_port, + added_by_user, mac, vid); +break ; +case SWITCHDEV_FDB_DEL_TO_DEVICE : +ice_eswitch_br_fdb_entry_find_and_delete (br_port->bridge, + mac, vid); +break ; +default : + goto err_exit; + } + +err_exit: +rtnl_unlock (); +dev_put (fdb_work->dev); +ice_eswitch_br_fdb_work_dealloc (fdb_work); +} + +static struct ice_esw_br_fdb_work * +ice_eswitch_br_fdb_work_alloc (struct switchdev_notifier_fdb_info *fdb_info, +struct net_device *dev, +unsigned long event) +{ +struct ice_esw_br_fdb_work *work; +unsigned char *mac; + + work =kzalloc (sizeof (*work),GFP_ATOMIC ); +if (!work) +return ERR_PTR (-ENOMEM ); + +INIT_WORK (&work->work, ice_eswitch_br_fdb_event_work); +memcpy (&work->fdb_info, fdb_info,sizeof (work->fdb_info)); + + mac =kzalloc (ETH_ALEN ,GFP_ATOMIC ); +if (!mac) { +kfree (work); +return ERR_PTR (-ENOMEM ); + } + +ether_addr_copy (mac, fdb_info->addr); + work->fdb_info.addr = mac; + work->event = event; + work->dev = dev; + +return work; +} + +static int +ice_eswitch_br_switchdev_event (struct notifier_block *nb, +unsigned long event,void *ptr) +{ +struct net_device *dev =switchdev_notifier_info_to_dev (ptr); +struct switchdev_notifier_fdb_info *fdb_info; +struct switchdev_notifier_info *info = ptr; +struct ice_esw_br_offloads *br_offloads; +struct ice_esw_br_fdb_work *work; +struct netlink_ext_ack *extack; +struct net_device *upper; + + br_offloads =ice_nb_to_br_offloads (nb, switchdev_nb); + extack =switchdev_notifier_info_to_extack (ptr); + + upper =netdev_master_upper_dev_get_rcu (dev); +if (!upper) +return NOTIFY_DONE ; + +if (!netif_is_bridge_master (upper)) +return NOTIFY_DONE ; + +if (!ice_eswitch_br_is_dev_valid (dev)) +return NOTIFY_DONE ; + +if (!ice_eswitch_br_netdev_to_port (dev)) +return NOTIFY_DONE ; + +switch (event) { +case SWITCHDEV_FDB_ADD_TO_DEVICE : +case SWITCHDEV_FDB_DEL_TO_DEVICE : + fdb_info =container_of (info,typeof (*fdb_info), info); + + work =ice_eswitch_br_fdb_work_alloc (fdb_info, dev, event); +if (IS_ERR (work)) { +NL_SET_ERR_MSG_MOD (extack,"Failed to init switchdev fdb work" ); +return notifier_from_errno (PTR_ERR (work)); + } +dev_hold (dev); + +queue_work (br_offloads->wq, &work->work); +break ; +default : +break ; + } +return NOTIFY_DONE ; +} +static void ice_eswitch_br_port_deinit (struct ice_esw_br *bridge,struct ice_esw_br_port *br_port) { +struct ice_esw_br_fdb_entry *fdb_entry, *tmp;struct ice_vsi *vsi = br_port->vsi; +list_for_each_entry_safe (fdb_entry, tmp, &bridge->fdb_list, list) { +if (br_port == fdb_entry->br_port) +ice_eswitch_br_fdb_entry_delete (bridge, fdb_entry); + } +if (br_port->type ==ICE_ESWITCH_BR_UPLINK_PORT && vsi->back) vsi->back->br_port =NULL ;else if (vsi->vf && vsi->vf->repr)
@@ -129,6 +530,8 @@ ice_eswitch_br_deinit(struct ice_esw_br_offloads *br_offloads,ice_eswitch_br_ports_flush (bridge);WARN_ON (!xa_empty (&bridge->ports));xa_destroy (&bridge->ports); +rhashtable_destroy (&bridge->fdb_ht); + br_offloads->bridge =NULL ;kfree (bridge); }
@@ -137,11 +540,19 @@ static struct ice_esw_br * ice_eswitch_br_init(struct ice_esw_br_offloads *br_offloads, int ifindex) {struct ice_esw_br *bridge; +int err; bridge =kzalloc (sizeof (*bridge),GFP_KERNEL );if (!bridge)return ERR_PTR (-ENOMEM ); + err =rhashtable_init (&bridge->fdb_ht, &ice_fdb_ht_params); +if (err) { +kfree (bridge); +return ERR_PTR (err); + } + +INIT_LIST_HEAD (&bridge->fdb_list); bridge->br_offloads = br_offloads; bridge->ifindex = ifindex;xa_init (&bridge->ports);
@@ -340,6 +751,8 @@ ice_eswitch_br_offloads_deinit(struct ice_pf *pf)return ;unregister_netdevice_notifier (&br_offloads->netdev_nb); +unregister_switchdev_notifier (&br_offloads->switchdev_nb); +destroy_workqueue (br_offloads->wq);/* Although notifier block is unregistered just before, * so we don't get any new events, some events might be * already in progress. Hold the rtnl lock and wait for
@@ -365,6 +778,22 @@ ice_eswitch_br_offloads_init(struct ice_pf *pf)return PTR_ERR (br_offloads); } + br_offloads->wq =alloc_ordered_workqueue ("ice_bridge_wq" ,0 ); +if (!br_offloads->wq) { + err = -ENOMEM ; +dev_err (dev,"Failed to allocate bridge workqueue\n" ); + goto err_alloc_wq; + } + + br_offloads->switchdev_nb.notifier_call = + ice_eswitch_br_switchdev_event; + err =register_switchdev_notifier (&br_offloads->switchdev_nb); +if (err) { +dev_err (dev, +"Failed to register switchdev notifier\n" ); + goto err_reg_switchdev_nb; + } + br_offloads->netdev_nb.notifier_call = ice_eswitch_br_port_event; err =register_netdevice_notifier (&br_offloads->netdev_nb);if (err) {
@@ -376,6 +805,10 @@ ice_eswitch_br_offloads_init(struct ice_pf *pf)return 0 ; err_reg_netdev_nb: +unregister_switchdev_notifier (&br_offloads->switchdev_nb); +err_reg_switchdev_nb: +destroy_workqueue (br_offloads->wq); +err_alloc_wq:rtnl_lock ();ice_eswitch_br_offloads_dealloc (pf);rtnl_unlock ();
drivers/net/ethernet/intel/ice/ice_eswitch_br.h +45 -0
69 lines not on this page · raw message
Signature · 1 line
2.38.1
Re: [PATCH net-next v2 07/12] ice: Switchdev FDB events support
Quoted 22 lines · Tony Nguyen
From: Wojciech Drewek <[email protected]>
Listen for SWITCHDEV_FDB_{ADD|DEL}_TO_DEVICE events while in switchdev mode. Accept these events on both uplink and VF PR ports. Add HW rules in newly created workqueue. FDB entries are stored in rhashtable for lookup when removing the entry and in the list for cleanup purpose. Direction of the HW rule depends on the type of the ports on which the FDB event was received:
ICE_ESWITCH_BR_UPLINK_PORT:
TX rule that forwards the packet to the LAN (egress).
ICE_ESWITCH_BR_VF_REPR_PORT:
RX rule that forwards the packet to the VF associated with the port representor.In both cases the rule matches on the dst mac address.
All the FDB entries are stored in the bridge structure.
When the port is removed all the FDB entries associated with this port are removed as well. This is achieved thanks to the reference to the port that FDB entry holds.
Quoted 7 lines
In the fwd rule we use only one lookup type (MAC address) but
lkups_cntvariable is already introduced because we will have more lookups in the subsequent patches.Signed-off-by Wojciech Drewek <[email protected]>Tested-by Sujai Buvaneswaran <[email protected]>Signed-off-by Tony Nguyen <[email protected]>
Tony Nguyen
maintainerPATCH v2 8/12 ice: Add guard rule when creating FDB in switchdev
In reply to Tony NguyenFrom: Marcin Szycik <[email protected]>
Introduce new "guard" rule upon FDB entry creation.
It matches on src_mac, has valid bit unset, allow_pass_l2 set and has a nop action.
Previously introduced "forward" rule matches on dst_mac, has valid bit set, need_pass_l2 set and has a forward action.
With these rules, a packet will be offloaded only if FDB exists in both directions (RX and TX).
Let's assume link partner sends a packet to VF1: src_mac = LP_MAC, dst_mac = is VF1_MAC. Bridge adds FDB, two rules are created:
1. Guard rule matching on src_mac == LP_MAC
2. Forward rule matching on dst_mac == LP_MAC
Now VF1 responds with src_mac = VF1_MAC, dst_mac = LP_MAC. Before this change, only one rule with dst_mac == LP_MAC would have existed, and the packet would have been offloaded, meaning the bridge wouldn't add FDB in the opposite direction. Now, the forward rule matches (dst_mac == LP_MAC), but it has need_pass_l2 set an there is no guard rule with src_mac == VF1_MAC, so the packet goes through slow-path and the bridge adds FDB. Two rules are created:
1. Guard rule matching on src_mac == VF1_MAC
2. Forward rule matching on dst_mac == VF1_MAC
Further packets in both directions will be offloaded.
The same example is true in opposite direction (i.e. VF1 is the first to send a packet out).
--- .../net/ethernet/intel/ice/ice_eswitch_br.c | 64 +++++++++++- .../net/ethernet/intel/ice/ice_eswitch_br.h | 1 + drivers/net/ethernet/intel/ice/ice_switch.c | 97 ++++++++++++------- drivers/net/ethernet/intel/ice/ice_switch.h | 5 + drivers/net/ethernet/intel/ice/ice_type.h | 1 + 5 files changed, 132 insertions(+), 36 deletions(-)
drivers/net/ethernet/intel/ice/ice_eswitch_br.c +63 -1
@@ -107,6 +107,8 @@ ice_eswitch_br_fwd_rule_create(struct ice_hw *hw, int vsi_idx, int port_type,ether_addr_copy (list[0 ].h_u.eth_hdr.dst_addr, mac);eth_broadcast_addr (list[0 ].m_u.eth_hdr.dst_addr); + rule_info.need_pass_l2 = true; + rule_info.sw_act.fltr_act =ICE_FWD_TO_VSI ; err =ice_add_adv_rule (hw, list, lkups_cnt, &rule_info, rule);
@@ -125,11 +127,54 @@ ice_eswitch_br_fwd_rule_create(struct ice_hw *hw, int vsi_idx, int port_type,return ERR_PTR (err); } +static struct ice_rule_query_data * +ice_eswitch_br_guard_rule_create (struct ice_hw *hw,u16 vsi_idx, +const unsigned char *mac) +{ +struct ice_adv_rule_info rule_info = {0 }; +struct ice_rule_query_data *rule; +struct ice_adv_lkup_elem *list; +const u16 lkups_cnt =1 ; +int err = -ENOMEM ; + + rule =kzalloc (sizeof (*rule),GFP_KERNEL ); +if (!rule) + goto err_exit; + + list =kcalloc (lkups_cnt,sizeof (*list),GFP_ATOMIC ); +if (!list) + goto err_list_alloc; + + list[0 ].type =ICE_MAC_OFOS ; +ether_addr_copy (list[0 ].h_u.eth_hdr.src_addr, mac); +eth_broadcast_addr (list[0 ].m_u.eth_hdr.src_addr); + + rule_info.allow_pass_l2 = true; + rule_info.sw_act.vsi_handle = vsi_idx; + rule_info.sw_act.fltr_act =ICE_NOP ; + rule_info.priority =5 ; + + err =ice_add_adv_rule (hw, list, lkups_cnt, &rule_info, rule); +if (err) + goto err_add_rule; + +kfree (list); + +return rule; + +err_add_rule: +kfree (list); +err_list_alloc: +kfree (rule); +err_exit: +return ERR_PTR (err); +} +static struct ice_esw_br_flow *ice_eswitch_br_flow_create (struct device *dev,struct ice_hw *hw,int vsi_idx,int port_type,const unsigned char *mac) { -struct ice_rule_query_data *fwd_rule; +struct ice_rule_query_data *fwd_rule, *guard_rule;struct ice_esw_br_flow *flow;int err;
@@ -146,10 +191,22 @@ ice_eswitch_br_flow_create(struct device *dev, struct ice_hw *hw, int vsi_idx, goto err_fwd_rule; } + guard_rule =ice_eswitch_br_guard_rule_create (hw, vsi_idx, mac); + err =PTR_ERR_OR_ZERO (guard_rule); +if (err) { +dev_err (dev,"Failed to create eswitch bridge %sgress guard rule, err: %d\n" , + port_type ==ICE_ESWITCH_BR_UPLINK_PORT ?"e" :"in" , + err); + goto err_guard_rule; + } + flow->fwd_rule = fwd_rule; + flow->guard_rule = guard_rule;return flow; +err_guard_rule: +ice_eswitch_br_rule_delete (hw, fwd_rule); err_fwd_rule:kfree (flow);
@@ -180,6 +237,11 @@ ice_eswitch_br_flow_delete(struct ice_pf *pf, struct ice_esw_br_flow *flow)dev_err (dev,"Failed to delete FDB forward rule, err: %d\n" , err); + err =ice_eswitch_br_rule_delete (&pf->hw, flow->guard_rule); +if (err) +dev_err (dev,"Failed to delete FDB guard rule, err: %d\n" , + err); +kfree (flow); }
drivers/net/ethernet/intel/ice/ice_eswitch_br.h +1 -0
@@ -13,6 +13,7 @@ struct ice_esw_br_fdb_data {struct ice_esw_br_flow {struct ice_rule_query_data *fwd_rule; +struct ice_rule_query_data *guard_rule; };enum {
drivers/net/ethernet/intel/ice/ice_switch.c +62 -35
235 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_switch.h +5 -0
@@ -191,6 +191,8 @@ struct ice_adv_rule_info {u16 vlan_type;u16 fltr_rule_id;u32 priority; + u16 need_pass_l2:1; + u16 allow_pass_l2:1;u16 src_vsi;struct ice_sw_act_ctrl sw_act;struct ice_adv_rule_flags_info flags_info;
@@ -254,6 +256,9 @@ struct ice_sw_recipe {*/ u8 priority; + u8 need_pass_l2:1; + u8 allow_pass_l2:1; +struct list_head rg_list;/* AQ buffer associated with this recipe */
drivers/net/ethernet/intel/ice/ice_type.h +1 -0
@@ -1033,6 +1033,7 @@ enum ice_sw_fwd_act_type {ICE_FWD_TO_Q ,ICE_FWD_TO_QGRP ,ICE_DROP_PACKET , +ICE_NOP , ICE_INVAL_ACT };
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 9/12 ice: Add VLAN FDB support in switchdev mode
In reply to Tony NguyenFrom: Marcin Szycik <[email protected]>
Add support for matching on VLAN tag in bridge offloads. Currently only trunk mode is supported.
To enable VLAN filtering (existing FDB entries will be deleted):
ip link set $BR type bridge vlan_filtering 1
To add VLANs to bridge in trunk mode:
bridge vlan add dev $PF1 vid 110-111
bridge vlan add dev $VF1_PR vid 110-111
--- .../net/ethernet/intel/ice/ice_eswitch_br.c | 304 +++++++++++++++++- .../net/ethernet/intel/ice/ice_eswitch_br.h | 21 ++ 2 files changed, 317 insertions(+), 8 deletions(-)
drivers/net/ethernet/intel/ice/ice_eswitch_br.c +296 -8
@@ -70,16 +70,34 @@ ice_eswitch_br_rule_delete(struct ice_hw *hw, struct ice_rule_query_data *rule)return err; } +static u16 +ice_eswitch_br_get_lkups_cnt (u16 vid) +{ +return ice_eswitch_br_is_vid_valid (vid) ?2 :1 ; +} + +static void +ice_eswitch_br_add_vlan_lkup (struct ice_adv_lkup_elem *list,u16 vid) +{ +if (ice_eswitch_br_is_vid_valid (vid)) { + list[1 ].type =ICE_VLAN_OFOS ; + list[1 ].h_u.vlan_hdr.vlan =cpu_to_be16 (vid &VLAN_VID_MASK ); + list[1 ].m_u.vlan_hdr.vlan =cpu_to_be16 (0xFFFF ); + } +} +static struct ice_rule_query_data *ice_eswitch_br_fwd_rule_create (struct ice_hw *hw,int vsi_idx,int port_type, -const unsigned char *mac) +const unsigned char *mac,u16 vid) {struct ice_adv_rule_info rule_info = {0 };struct ice_rule_query_data *rule;struct ice_adv_lkup_elem *list; -u16 lkups_cnt =1 ; +u16 lkups_cnt;int err; + lkups_cnt =ice_eswitch_br_get_lkups_cnt (vid); + rule =kzalloc (sizeof (*rule),GFP_KERNEL );if (!rule)return ERR_PTR (-ENOMEM );
@@ -107,6 +125,8 @@ ice_eswitch_br_fwd_rule_create(struct ice_hw *hw, int vsi_idx, int port_type,ether_addr_copy (list[0 ].h_u.eth_hdr.dst_addr, mac);eth_broadcast_addr (list[0 ].m_u.eth_hdr.dst_addr); +ice_eswitch_br_add_vlan_lkup (list, vid); + rule_info.need_pass_l2 = true; rule_info.sw_act.fltr_act =ICE_FWD_TO_VSI ;
@@ -129,13 +149,15 @@ ice_eswitch_br_fwd_rule_create(struct ice_hw *hw, int vsi_idx, int port_type,static struct ice_rule_query_data *ice_eswitch_br_guard_rule_create (struct ice_hw *hw,u16 vsi_idx, -const unsigned char *mac) +const unsigned char *mac,u16 vid) {struct ice_adv_rule_info rule_info = {0 };struct ice_rule_query_data *rule;struct ice_adv_lkup_elem *list; -const u16 lkups_cnt =1 ;int err = -ENOMEM ; +u16 lkups_cnt; + + lkups_cnt =ice_eswitch_br_get_lkups_cnt (vid); rule =kzalloc (sizeof (*rule),GFP_KERNEL );if (!rule)
@@ -149,6 +171,8 @@ ice_eswitch_br_guard_rule_create(struct ice_hw *hw, u16 vsi_idx,ether_addr_copy (list[0 ].h_u.eth_hdr.src_addr, mac);eth_broadcast_addr (list[0 ].m_u.eth_hdr.src_addr); +ice_eswitch_br_add_vlan_lkup (list, vid); + rule_info.allow_pass_l2 = true; rule_info.sw_act.vsi_handle = vsi_idx; rule_info.sw_act.fltr_act =ICE_NOP ;
@@ -172,7 +196,7 @@ ice_eswitch_br_guard_rule_create(struct ice_hw *hw, u16 vsi_idx,static struct ice_esw_br_flow *ice_eswitch_br_flow_create (struct device *dev,struct ice_hw *hw,int vsi_idx, -int port_type,const unsigned char *mac) +int port_type,const unsigned char *mac,u16 vid) {struct ice_rule_query_data *fwd_rule, *guard_rule;struct ice_esw_br_flow *flow;
@@ -182,7 +206,8 @@ ice_eswitch_br_flow_create(struct device *dev, struct ice_hw *hw, int vsi_idx,if (!flow)return ERR_PTR (-ENOMEM ); - fwd_rule =ice_eswitch_br_fwd_rule_create (hw, vsi_idx, port_type, mac); + fwd_rule =ice_eswitch_br_fwd_rule_create (hw, vsi_idx, port_type, mac, + vid); err =PTR_ERR_OR_ZERO (fwd_rule);if (err) { dev_err(dev, "Failed to create eswitch bridge %sgress forward rule, err: %d\n",
@@ -191,7 +216,7 @@ ice_eswitch_br_flow_create(struct device *dev, struct ice_hw *hw, int vsi_idx, goto err_fwd_rule; } - guard_rule =ice_eswitch_br_guard_rule_create (hw, vsi_idx, mac); + guard_rule =ice_eswitch_br_guard_rule_create (hw, vsi_idx, mac, vid); err =PTR_ERR_OR_ZERO (guard_rule);if (err) { dev_err(dev, "Failed to create eswitch bridge %sgress guard rule, err: %d\n",
@@ -245,6 +270,30 @@ ice_eswitch_br_flow_delete(struct ice_pf *pf, struct ice_esw_br_flow *flow)kfree (flow); } +static struct ice_esw_br_vlan * +ice_esw_br_port_vlan_lookup (struct ice_esw_br *bridge,u16 vsi_idx,u16 vid) +{ +struct ice_pf *pf = bridge->br_offloads->pf; +struct device *dev =ice_pf_to_dev (pf); +struct ice_esw_br_port *port; +struct ice_esw_br_vlan *vlan; + + port =xa_load (&bridge->ports, vsi_idx); +if (!port) { +dev_info (dev,"Bridge port lookup failed (vsi=%u)\n" , vsi_idx); +return ERR_PTR (-EINVAL ); + } + + vlan =xa_load (&port->vlans, vid); +if (!vlan) { +dev_info (dev,"Bridge port vlan metadata lookup failed (vsi=%u)\n" , + vsi_idx); +return ERR_PTR (-EINVAL ); + } + +return vlan; +} +static void ice_eswitch_br_fdb_entry_delete (struct ice_esw_br *bridge,struct ice_esw_br_fdb_entry *fdb_entry)
@@ -314,10 +363,25 @@ ice_eswitch_br_fdb_entry_create(struct net_device *netdev,struct device *dev =ice_pf_to_dev (pf);struct ice_esw_br_fdb_entry *fdb_entry;struct ice_esw_br_flow *flow; +struct ice_esw_br_vlan *vlan;struct ice_hw *hw = &pf->hw;unsigned long event;int err; +/* untagged filtering is not yet supported */ +if (!(bridge->flags &ICE_ESWITCH_BR_VLAN_FILTERING ) && vid) +return ; + +if ((bridge->flags &ICE_ESWITCH_BR_VLAN_FILTERING )) { + vlan =ice_esw_br_port_vlan_lookup (bridge, br_port->vsi_idx, + vid); +if (IS_ERR (vlan)) { +dev_err (dev,"Failed to find vlan lookup, err: %ld\n" , +PTR_ERR (vlan)); +return ; + } + } + fdb_entry =ice_eswitch_br_fdb_find (bridge, mac, vid);if (fdb_entry)ice_eswitch_br_fdb_entry_notify_and_cleanup (bridge, fdb_entry);
@@ -329,7 +393,7 @@ ice_eswitch_br_fdb_entry_create(struct net_device *netdev, } flow =ice_eswitch_br_flow_create (dev, hw, br_port->vsi_idx, - br_port->type, mac); + br_port->type, mac, vid);if (IS_ERR (flow)) { err =PTR_ERR (flow); goto err_add_flow;
@@ -484,6 +548,215 @@ ice_eswitch_br_switchdev_event(struct notifier_block *nb,return NOTIFY_DONE ; } +static void ice_eswitch_br_fdb_flush (struct ice_esw_br *bridge) +{ +struct ice_esw_br_fdb_entry *entry, *tmp; + +list_for_each_entry_safe (entry, tmp, &bridge->fdb_list, list) +ice_eswitch_br_fdb_entry_notify_and_cleanup (bridge, entry); +} + +static void +ice_eswitch_br_vlan_filtering_set (struct ice_esw_br *bridge,bool enable) +{ +if (enable == !!(bridge->flags &ICE_ESWITCH_BR_VLAN_FILTERING )) +return ; + +ice_eswitch_br_fdb_flush (bridge); +if (enable) + bridge->flags |=ICE_ESWITCH_BR_VLAN_FILTERING ; +else + bridge->flags &= ~ICE_ESWITCH_BR_VLAN_FILTERING ; +} + +static void +ice_eswitch_br_vlan_cleanup (struct ice_esw_br_port *port, +struct ice_esw_br_vlan *vlan) +{ +struct ice_esw_br_fdb_entry *fdb_entry, *tmp; +struct ice_esw_br *bridge = port->bridge; + +list_for_each_entry_safe (fdb_entry, tmp, &bridge->fdb_list, list) { +if (vlan->vid == fdb_entry->data.vid) +ice_eswitch_br_fdb_entry_delete (bridge, fdb_entry); + } + +xa_erase (&port->vlans, vlan->vid); +kfree (vlan); +} + +static void ice_eswitch_br_port_vlans_flush (struct ice_esw_br_port *port) +{ +struct ice_esw_br_vlan *vlan; +unsigned long index; + +xa_for_each (&port->vlans, index, vlan) +ice_eswitch_br_vlan_cleanup (port, vlan); +} + +static struct ice_esw_br_vlan * +ice_eswitch_br_vlan_create (u16 vid,u16 flags,struct ice_esw_br_port *port) +{ +struct ice_esw_br_vlan *vlan; +int err; + + vlan =kzalloc (sizeof (*vlan),GFP_KERNEL ); +if (!vlan) +return ERR_PTR (-ENOMEM ); + + vlan->vid = vid; + vlan->flags = flags; + + err =xa_insert (&port->vlans, vlan->vid, vlan,GFP_KERNEL ); +if (err) { +kfree (vlan); +return ERR_PTR (err); + } + +return vlan; +} + +static int +ice_eswitch_br_port_vlan_add (struct ice_esw_br *bridge,u16 vsi_idx,u16 vid, +u16 flags,struct netlink_ext_ack *extack) +{ +struct ice_esw_br_port *port; +struct ice_esw_br_vlan *vlan; + + port =xa_load (&bridge->ports, vsi_idx); +if (!port) +return -EINVAL ; + + vlan =xa_load (&port->vlans, vid); +if (vlan) { +if (vlan->flags == flags) +return 0 ; + +ice_eswitch_br_vlan_cleanup (port, vlan); + } + + vlan =ice_eswitch_br_vlan_create (vid, flags, port); +if (IS_ERR (vlan)) { +NL_SET_ERR_MSG_FMT_MOD (extack,"Failed to create VLAN entry, vid: %u, vsi: %u" , + vid, vsi_idx); +return PTR_ERR (vlan); + } + +return 0 ; +} + +static void +ice_eswitch_br_port_vlan_del (struct ice_esw_br *bridge,u16 vsi_idx,u16 vid) +{ +struct ice_esw_br_port *port; +struct ice_esw_br_vlan *vlan; + + port =xa_load (&bridge->ports, vsi_idx); +if (!port) +return ; + + vlan =xa_load (&port->vlans, vid); +if (!vlan) +return ; + +ice_eswitch_br_vlan_cleanup (port, vlan); +} + +static int +ice_eswitch_br_port_obj_add (struct net_device *netdev,const void *ctx, +const struct switchdev_obj *obj, +struct netlink_ext_ack *extack) +{ +struct ice_esw_br_port *br_port =ice_eswitch_br_netdev_to_port (netdev); +struct switchdev_obj_port_vlan *vlan; +int err; + +if (!br_port) +return -EINVAL ; + +switch (obj->id) { +case SWITCHDEV_OBJ_ID_PORT_VLAN : + vlan =SWITCHDEV_OBJ_PORT_VLAN (obj); + err =ice_eswitch_br_port_vlan_add (br_port->bridge, + br_port->vsi_idx, vlan->vid, + vlan->flags, extack); +return err; +default : +return -EOPNOTSUPP ; + } +} + +static int +ice_eswitch_br_port_obj_del (struct net_device *netdev,const void *ctx, +const struct switchdev_obj *obj) +{ +struct ice_esw_br_port *br_port =ice_eswitch_br_netdev_to_port (netdev); +struct switchdev_obj_port_vlan *vlan; + +if (!br_port) +return -EINVAL ; + +switch (obj->id) { +case SWITCHDEV_OBJ_ID_PORT_VLAN : + vlan =SWITCHDEV_OBJ_PORT_VLAN (obj); +ice_eswitch_br_port_vlan_del (br_port->bridge, br_port->vsi_idx, + vlan->vid); +return 0 ; +default : +return -EOPNOTSUPP ; + } +} + +static int +ice_eswitch_br_port_obj_attr_set (struct net_device *netdev,const void *ctx, +const struct switchdev_attr *attr, +struct netlink_ext_ack *extack) +{ +struct ice_esw_br_port *br_port =ice_eswitch_br_netdev_to_port (netdev); + +if (!br_port) +return -EINVAL ; + +switch (attr->id) { +case SWITCHDEV_ATTR_ID_BRIDGE_VLAN_FILTERING : +ice_eswitch_br_vlan_filtering_set (br_port->bridge, + attr->u.vlan_filtering); +return 0 ; +default : +return -EOPNOTSUPP ; + } +} + +static int +ice_eswitch_br_event_blocking (struct notifier_block *nb,unsigned long event, +void *ptr) +{ +struct net_device *dev =switchdev_notifier_info_to_dev (ptr); +int err; + +switch (event) { +case SWITCHDEV_PORT_OBJ_ADD : + err =switchdev_handle_port_obj_add (dev, ptr, + ice_eswitch_br_is_dev_valid, + ice_eswitch_br_port_obj_add); +break ; +case SWITCHDEV_PORT_OBJ_DEL : + err =switchdev_handle_port_obj_del (dev, ptr, + ice_eswitch_br_is_dev_valid, + ice_eswitch_br_port_obj_del); +break ; +case SWITCHDEV_PORT_ATTR_SET : + err =switchdev_handle_port_attr_set (dev, ptr, + ice_eswitch_br_is_dev_valid, + ice_eswitch_br_port_obj_attr_set); +break ; +default : + err =0 ; + } + +return notifier_from_errno (err); +} +static void ice_eswitch_br_port_deinit (struct ice_esw_br *bridge,struct ice_esw_br_port *br_port)
@@ -502,6 +775,7 @@ ice_eswitch_br_port_deinit(struct ice_esw_br *bridge, vsi->vf->repr->br_port =NULL ;xa_erase (&bridge->ports, br_port->vsi_idx); +ice_eswitch_br_port_vlans_flush (br_port);kfree (br_port); }
@@ -514,6 +788,8 @@ ice_eswitch_br_port_init(struct ice_esw_br *bridge)if (!br_port)return ERR_PTR (-ENOMEM ); +xa_init (&br_port->vlans); + br_port->bridge = bridge;return br_port;
@@ -813,6 +1089,7 @@ ice_eswitch_br_offloads_deinit(struct ice_pf *pf)return ;unregister_netdevice_notifier (&br_offloads->netdev_nb); +unregister_switchdev_blocking_notifier (&br_offloads->switchdev_blk);unregister_switchdev_notifier (&br_offloads->switchdev_nb);destroy_workqueue (br_offloads->wq);/* Although notifier block is unregistered just before,
@@ -856,6 +1133,15 @@ ice_eswitch_br_offloads_init(struct ice_pf *pf) goto err_reg_switchdev_nb; } + br_offloads->switchdev_blk.notifier_call = + ice_eswitch_br_event_blocking; + err =register_switchdev_blocking_notifier (&br_offloads->switchdev_blk); +if (err) { +dev_err (dev, +"Failed to register bridge blocking switchdev notifier\n" ); + goto err_reg_switchdev_blk; + } + br_offloads->netdev_nb.notifier_call = ice_eswitch_br_port_event; err =register_netdevice_notifier (&br_offloads->netdev_nb);if (err) {
@@ -867,6 +1153,8 @@ ice_eswitch_br_offloads_init(struct ice_pf *pf)return 0 ; err_reg_netdev_nb: +unregister_switchdev_blocking_notifier (&br_offloads->switchdev_blk); +err_reg_switchdev_blk:unregister_switchdev_notifier (&br_offloads->switchdev_nb); err_reg_switchdev_nb:destroy_workqueue (br_offloads->wq);
drivers/net/ethernet/intel/ice/ice_eswitch_br.h +21 -0
@@ -42,6 +42,11 @@ struct ice_esw_br_port {struct ice_vsi *vsi;enum ice_esw_br_port_type type;u16 vsi_idx; +struct xarray vlans; +}; + +enum { +ICE_ESWITCH_BR_VLAN_FILTERING =BIT (0 ), };struct ice_esw_br {
@@ -52,12 +57,14 @@ struct ice_esw_br {struct list_head fdb_list;int ifindex; +u32 flags; };struct ice_esw_br_offloads {struct ice_pf *pf;struct ice_esw_br *bridge;struct notifier_block netdev_nb; +struct notifier_block switchdev_blk;struct notifier_block switchdev_nb;struct workqueue_struct *wq;
@@ -70,6 +77,11 @@ struct ice_esw_br_fdb_work {unsigned long event; }; +struct ice_esw_br_vlan { +u16 vid; +u16 flags; +}; +#define ice_nb_to_br_offloads (nb, nb_name) \ container_of(nb, \ struct ice_esw_br_offloads, \
@@ -80,6 +92,15 @@ struct ice_esw_br_fdb_work { struct ice_esw_br_fdb_work, \ work) +static inline bool ice_eswitch_br_is_vid_valid (u16 vid) +{ +/* In trunk VLAN mode, for untagged traffic the bridge sends requests +* to offload VLAN 1 with pvid and untagged flags set. Since these +* flags are not supported, add a MAC filter instead. +*/ +return vid >1 ; +} +void ice_eswitch_br_offloads_deinit (struct ice_pf *pf);int
Signature · 1 line
2.38.1
Re: [PATCH net-next v2 09/12] ice: Add VLAN FDB support in switchdev mode
Quoted 8 lines · Tony Nguyen
From: Marcin Szycik <[email protected]>
Add support for matching on VLAN tag in bridge offloads. Currently only trunk mode is supported.
To enable VLAN filtering (existing FDB entries will be deleted):
ip link set $BR type bridgevlan_filtering1
Quoted 8 lines
To add VLANs to bridge in trunk mode:
bridge vlan add dev $PF1 vid 110-111
bridge vlan add dev $VF1_PR vid 110-111Signed-off-by Marcin Szycik <[email protected]>Signed-off-by Wojciech Drewek <[email protected]>Tested-by Sujai Buvaneswaran <[email protected]>Signed-off-by Tony Nguyen <[email protected]>
Tony Nguyen
maintainerPATCH v2 10/12 ice: implement bridge port vlan
In reply to Tony NguyenFrom: Michal Swiatkowski <[email protected]>
Port VLAN in this case means push and pop VLAN action on specific vid. There are a few limitation in hardware:
- push and pop can't be used separately
- if port VLAN is used there can't be any trunk VLANs, because pop action is done on all traffic received by VSI in port VLAN mode
- port VLAN mode on uplink port isn't supported
Reflect these limitations in code using dev_info to inform the user about unsupported configuration.
In bridge mode there is a need to configure port vlan without resetting VFs. To do that implement ice_port_vlan_on/off() functions. They are only configuring correct vlan_ops to allow setting port vlan.
We also need to clear port vlan without resetting the VF which is not supported right now. Change it by implementing clear_port_vlan ops. As previous VLAN configuration isn't always the same, store current config while creating port vlan and restore it in clear function.
Configuration steps:
- configure switchdev with bridge
- #bridge vlan add dev eth0 vid 120 pvid untagged
- #bridge vlan add dev eth1 vid 120 pvid untagged
- ping from VF0 to VF1
--- drivers/net/ethernet/intel/ice/ice.h | 1 + .../net/ethernet/intel/ice/ice_eswitch_br.c | 92 ++++++++- .../net/ethernet/intel/ice/ice_eswitch_br.h | 1 + .../ethernet/intel/ice/ice_vf_vsi_vlan_ops.c | 186 ++++++++++-------- .../ethernet/intel/ice/ice_vf_vsi_vlan_ops.h | 4 + .../net/ethernet/intel/ice/ice_vsi_vlan_lib.c | 84 +++++++- .../net/ethernet/intel/ice/ice_vsi_vlan_lib.h | 8 + .../net/ethernet/intel/ice/ice_vsi_vlan_ops.h | 1 + 8 files changed, 287 insertions(+), 90 deletions(-)
drivers/net/ethernet/intel/ice/ice.h +1 -0
@@ -370,6 +370,7 @@ struct ice_vsi {u16 rx_buf_len;struct ice_aqc_vsi_props info;/* VSI properties */ +struct ice_vsi_vlan_info vlan_info;/* vlan config to be restored */ /* VSI stats */ struct rtnl_link_stats64 net_stats;
drivers/net/ethernet/intel/ice/ice_eswitch_br.c +88 -4
135 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_eswitch_br.h +1 -0
@@ -42,6 +42,7 @@ struct ice_esw_br_port {struct ice_vsi *vsi;enum ice_esw_br_port_type type;u16 vsi_idx; +u16 pvid;struct xarray vlans; };
drivers/net/ethernet/intel/ice/ice_vf_vsi_vlan_ops.c +103 -83
200 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_vf_vsi_vlan_ops.h +4 -0
@@ -13,7 +13,11 @@ void ice_vf_vsi_cfg_svm_legacy_vlan_mode(struct ice_vsi *vsi);#ifdef CONFIG_PCI_IOV void ice_vf_vsi_init_vlan_ops (struct ice_vsi *vsi); +void ice_vf_vsi_enable_port_vlan (struct ice_vsi *vsi); +void ice_vf_vsi_disable_port_vlan (struct ice_vsi *vsi);#else static inline void ice_vf_vsi_init_vlan_ops (struct ice_vsi *vsi) { } +static inline void ice_vf_vsi_enable_port_vlan (struct ice_vsi *vsi) { } +static inline void ice_vf_vsi_disable_port_vlan (struct ice_vsi *vsi) { }#endif /* CONFIG_PCI_IOV */ #endif /* _ICE_PF_VSI_VLAN_OPS_H_ */
drivers/net/ethernet/intel/ice/ice_vsi_vlan_lib.c +81 -3
117 lines not on this page · raw message
drivers/net/ethernet/intel/ice/ice_vsi_vlan_lib.h +8 -0
@@ -7,6 +7,12 @@#include <linux/types.h> #include "ice_vlan.h" +struct ice_vsi_vlan_info { +u8 sw_flags2; +u8 inner_vlan_flags; +u8 outer_vlan_flags; +}; +struct ice_vsi ;int ice_vsi_add_vlan (struct ice_vsi *vsi,struct ice_vlan *vlan);
@@ -17,6 +23,7 @@ int ice_vsi_dis_inner_stripping(struct ice_vsi *vsi);int ice_vsi_ena_inner_insertion (struct ice_vsi *vsi,u16 tpid);int ice_vsi_dis_inner_insertion (struct ice_vsi *vsi);int ice_vsi_set_inner_port_vlan (struct ice_vsi *vsi,struct ice_vlan *vlan); +int ice_vsi_clear_inner_port_vlan (struct ice_vsi *vsi);int ice_vsi_ena_rx_vlan_filtering (struct ice_vsi *vsi);int ice_vsi_dis_rx_vlan_filtering (struct ice_vsi *vsi);
@@ -28,5 +35,6 @@ int ice_vsi_dis_outer_stripping(struct ice_vsi *vsi);int ice_vsi_ena_outer_insertion (struct ice_vsi *vsi,u16 tpid);int ice_vsi_dis_outer_insertion (struct ice_vsi *vsi);int ice_vsi_set_outer_port_vlan (struct ice_vsi *vsi,struct ice_vlan *vlan); +int ice_vsi_clear_outer_port_vlan (struct ice_vsi *vsi);#endif /* _ICE_VSI_VLAN_LIB_H_ */
drivers/net/ethernet/intel/ice/ice_vsi_vlan_ops.h +1 -0
@@ -21,6 +21,7 @@ struct ice_vsi_vlan_ops {int (*ena_tx_filtering)(struct ice_vsi *vsi);int (*dis_tx_filtering)(struct ice_vsi *vsi);int (*set_port_vlan)(struct ice_vsi *vsi,struct ice_vlan *vlan); +int (*clear_port_vlan)(struct ice_vsi *vsi); };void ice_vsi_init_vlan_ops (struct ice_vsi *vsi);
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 11/12 ice: implement static version of ageing
In reply to Tony NguyenFrom: Michal Swiatkowski <[email protected]>
Remove fdb entries always when ageing time expired.
Allow user to set ageing time using port object attribute.
--- .../net/ethernet/intel/ice/ice_eswitch_br.c | 48 +++++++++++++++++++ .../net/ethernet/intel/ice/ice_eswitch_br.h | 10 ++++ 2 files changed, 58 insertions(+)
drivers/net/ethernet/intel/ice/ice_eswitch_br.c +48 -0
@@ -8,6 +8,8 @@#include "ice_vlan.h" #include "ice_vf_vsi_vlan_ops.h" +#define ICE_ESW_BRIDGE_UPDATE_INTERVAL msecs_to_jiffies(1000) +static const struct rhashtable_params ice_fdb_ht_params = { .key_offset = offsetof(struct ice_esw_br_fdb_entry , data), .key_len =sizeof (struct ice_esw_br_fdb_data ),
@@ -406,6 +408,7 @@ ice_eswitch_br_fdb_entry_create(struct net_device *netdev, fdb_entry->br_port = br_port; fdb_entry->flow = flow; fdb_entry->dev = netdev; + fdb_entry->last_use = jiffies; event =SWITCHDEV_FDB_ADD_TO_BRIDGE ;if (added_by_user) {
@@ -806,6 +809,10 @@ ice_eswitch_br_port_obj_attr_set(struct net_device *netdev, const void *ctx,ice_eswitch_br_vlan_filtering_set (br_port->bridge, attr->u.vlan_filtering);return 0 ; +case SWITCHDEV_ATTR_ID_BRIDGE_AGEING_TIME : + br_port->bridge->ageing_time = +clock_t_to_jiffies (attr->u.ageing_time); +return 0 ;default :return -EOPNOTSUPP ; }
@@ -977,6 +984,7 @@ ice_eswitch_br_init(struct ice_esw_br_offloads *br_offloads, int ifindex)INIT_LIST_HEAD (&bridge->fdb_list); bridge->br_offloads = br_offloads; bridge->ifindex = ifindex; + bridge->ageing_time =clock_t_to_jiffies (BR_DEFAULT_AGEING_TIME );xa_init (&bridge->ports); br_offloads->bridge = bridge;
@@ -1172,6 +1180,7 @@ ice_eswitch_br_offloads_deinit(struct ice_pf *pf)if (!br_offloads)return ; +cancel_delayed_work_sync (&br_offloads->update_work);unregister_netdevice_notifier (&br_offloads->netdev_nb);unregister_switchdev_blocking_notifier (&br_offloads->switchdev_blk);unregister_switchdev_notifier (&br_offloads->switchdev_nb);
@@ -1186,6 +1195,40 @@ ice_eswitch_br_offloads_deinit(struct ice_pf *pf)rtnl_unlock (); } +static void ice_eswitch_br_update (struct ice_esw_br_offloads *br_offloads) +{ +struct ice_esw_br *bridge = br_offloads->bridge; +struct ice_esw_br_fdb_entry *entry, *tmp; + +if (!bridge) +return ; + +rtnl_lock (); +list_for_each_entry_safe (entry, tmp, &bridge->fdb_list, list) { +if (entry->flags &ICE_ESWITCH_BR_FDB_ADDED_BY_USER ) +continue ; + +if (time_is_after_eq_jiffies (entry->last_use + + bridge->ageing_time)) +continue ; + +ice_eswitch_br_fdb_entry_notify_and_cleanup (bridge, entry); + } +rtnl_unlock (); +} + +static void ice_eswitch_br_update_work (struct work_struct *work) +{ +struct ice_esw_br_offloads *br_offloads; + + br_offloads =ice_work_to_br_offloads (work); + +ice_eswitch_br_update (br_offloads); + +queue_delayed_work (br_offloads->wq, &br_offloads->update_work, +ICE_ESW_BRIDGE_UPDATE_INTERVAL ); +} +int ice_eswitch_br_offloads_init (struct ice_pf *pf) {
@@ -1234,6 +1277,11 @@ ice_eswitch_br_offloads_init(struct ice_pf *pf) goto err_reg_netdev_nb; } +INIT_DELAYED_WORK (&br_offloads->update_work, + ice_eswitch_br_update_work); +queue_delayed_work (br_offloads->wq, &br_offloads->update_work, +ICE_ESW_BRIDGE_UPDATE_INTERVAL ); +return 0 ; err_reg_netdev_nb:
drivers/net/ethernet/intel/ice/ice_eswitch_br.h +10 -0
@@ -5,6 +5,7 @@#define _ICE_ESWITCH_BR_H_#include <linux/rhashtable.h> +#include <linux/workqueue.h> struct ice_esw_br_fdb_data {unsigned char addr[ETH_ALEN ];
@@ -30,6 +31,8 @@ struct ice_esw_br_fdb_entry {struct net_device *dev;struct ice_esw_br_port *br_port;struct ice_esw_br_flow *flow; + +unsigned long last_use; };enum ice_esw_br_port_type {
@@ -59,6 +62,7 @@ struct ice_esw_br {int ifindex;u32 flags; +unsigned long ageing_time; };struct ice_esw_br_offloads {
@@ -69,6 +73,7 @@ struct ice_esw_br_offloads {struct notifier_block switchdev_nb;struct workqueue_struct *wq; +struct delayed_work update_work; };struct ice_esw_br_fdb_work {
@@ -88,6 +93,11 @@ struct ice_esw_br_vlan { struct ice_esw_br_offloads, \ nb_name) +#define ice_work_to_br_offloads(w) \ + container_of(w, \ + struct ice_esw_br_offloads, \ + update_work.work) + #define ice_work_to_fdb_work(w) \ container_of(w, \ struct ice_esw_br_fdb_work, \
Signature · 1 line
2.38.1
Tony Nguyen
maintainerPATCH v2 12/12 ice: add tracepoints for the switchdev bridge
In reply to Tony NguyenFrom: Pawel Chmielewski <[email protected]>
Add tracepoints for the following events:
- Add FDB entry
- Delete FDB entry
- Create bridge VLAN
- Cleanup bridge VLAN
- Link port to the bridge
- Unlink port from the bridge
--- .../net/ethernet/intel/ice/ice_eswitch_br.c | 10 +++ drivers/net/ethernet/intel/ice/ice_trace.h | 90 +++++++++++++++++++ 2 files changed, 100 insertions(+)
drivers/net/ethernet/intel/ice/ice_eswitch_br.c +10 -0
@@ -7,6 +7,7 @@#include "ice_switch.h" #include "ice_vlan.h" #include "ice_vf_vsi_vlan_ops.h" +#include "ice_trace.h" #define ICE_ESW_BRIDGE_UPDATE_INTERVAL msecs_to_jiffies(1000)
@@ -353,6 +354,7 @@ ice_eswitch_br_fdb_entry_find_and_delete(struct ice_esw_br *bridge,return ; } +trace_ice_eswitch_br_fdb_entry_find_and_delete (fdb_entry);ice_eswitch_br_fdb_entry_notify_and_cleanup (bridge, fdb_entry); }
@@ -422,6 +424,7 @@ ice_eswitch_br_fdb_entry_create(struct net_device *netdev, goto err_fdb_insert;list_add (&fdb_entry->list, &bridge->fdb_list); +trace_ice_eswitch_br_fdb_entry_create (fdb_entry);ice_eswitch_br_fdb_offload_notify (netdev, mac, vid, event);
@@ -597,6 +600,8 @@ ice_eswitch_br_vlan_cleanup(struct ice_esw_br_port *port,struct ice_esw_br_fdb_entry *fdb_entry, *tmp;struct ice_esw_br *bridge = port->bridge; +trace_ice_eswitch_br_vlan_cleanup (vlan); +list_for_each_entry_safe (fdb_entry, tmp, &bridge->fdb_list, list) {if (vlan->vid == fdb_entry->data.vid)ice_eswitch_br_fdb_entry_delete (bridge, fdb_entry);
@@ -686,6 +691,8 @@ ice_eswitch_br_vlan_create(u16 vid, u16 flags, struct ice_esw_br_port *port)if (err) goto err_insert; +trace_ice_eswitch_br_vlan_create (vlan); +return vlan; err_insert:
@@ -1047,6 +1054,7 @@ ice_eswitch_br_port_unlink(struct ice_esw_br_offloads *br_offloads, bridge = br_port->bridge; +trace_ice_eswitch_br_port_unlink (br_port);ice_eswitch_br_port_deinit (br_port->bridge, br_port);ice_eswitch_br_verify_deinit (br_offloads, bridge);
@@ -1075,10 +1083,12 @@ ice_eswitch_br_port_link(struct ice_esw_br_offloads *br_offloads,struct ice_repr *repr =ice_netdev_to_repr (dev); err =ice_eswitch_br_vf_repr_port_init (bridge, repr); +trace_ice_eswitch_br_port_link (repr->br_port); }else {struct ice_pf *pf =ice_netdev_to_pf (dev); err =ice_eswitch_br_uplink_port_init (bridge, pf); +trace_ice_eswitch_br_port_link (pf->br_port); }if (err) {NL_SET_ERR_MSG_MOD (extack,"Failed to init bridge port" );
drivers/net/ethernet/intel/ice/ice_trace.h +90 -0
102 lines not on this page · raw message
Signature · 1 line
2.38.1
Re: [PATCH net-next v2 12/12] ice: add tracepoints for the switchdev bridge
Quoted 10 lines · Tony Nguyen
From: Pawel Chmielewski <[email protected]>
Add tracepoints for the following events:
- Add FDB entry
- Delete FDB entry
- Create bridge VLAN
- Cleanup bridge VLAN
- Link port to the bridge
- Unlink port from the bridge
Quoted 4 lines
Signed-off-by Pawel Chmielewski <[email protected]>Signed-off-by Wojciech Drewek <[email protected]>Tested-by Sujai Buvaneswaran <[email protected]>Signed-off-by Tony Nguyen <[email protected]>
Quoted 36 lines · Tony Nguyen
Wojciech Drewek says:
Linux bridge provides ability to learn MAC addresses and vlans detected on bridge's ports. As a result of this, FDB (forward data base) entries are created and they can be offloaded to the HW. By adding VF's port representors to the bridge together with the uplink netdev, we can learn VF's and link partner's MAC addresses. This is achieved by slow/exception-path, where packets that do not match any filters (FDB entries in this case) are send to the bridge ports.
Driver keeps track of the netdevs added to the bridge
by listening forNETDEV_CHANGEUPPERevent. We distinguish two types of bridge ports: uplink port and VF's representor port. Linux bridge always learns src MAC of the packet on rx path. With the current slow-path implementation, it means that we will learn VF's MAC on port repr (when the VF transmits the packet) and link partner's MAC on uplink (when we receive it on uplink from LAN).The driver is notified about learning of the MAC/VLAN by SWITCHDEV_FDB_{ADD|DEL}_TO_DEVICE events. This is followed by creation of the HW filter. The direction of the filter is based on port type (uplink or VF repr). In case of the uplink, rule forwards the packets to the LAN (matching on link partner's MAC). When the notification is received on VF repr then the rule forwards the packets to the associated VF (matching on VF's MAC).
This approach would not work on its own however. This is because if one of the directions is offloaded, then the bridge would not be able to learn the other one. If the egress rule is added (learned on uplink) then the response from the VF will be sent directly to the LAN. The packet will not got through slow-path, it would not be seen on VF's port repr. Because of that, the bridge would not learn VF's MAC.
This is solved by introducing guard rule. It prevents forward rule from working until the opposite direction is offloaded.
Quoted 8 lines
Aging is not fully supported yet, aging time is static for now. The follow up submissions will introduce counters that will allow us to keep track if the rule is actually being used or not.
A few fixes/changes are needed for this feature to work with ice driver. These are introduced in first 5 patches.
Reviewed-by Vlad Buslov <[email protected]>
In my previous reply I meant reviewed-by for the whole series, not for the cover letter specifically. Sorry for not being more clear!
Jakub Kicinski
maintainerQuoted 4 lines · On Tue, 25 Jul 2023 22:32:18 +0300 Vlad Buslov wrote:
Quoted 1 line
Reviewed-by Vlad Buslov <[email protected]>In my previous reply I meant reviewed-by for the whole series, not for the cover letter specifically. Sorry for not being more clear!
Oh well, since it's a PR I probably shouldn't try to fix that.. What's important is that you reviewed it! :)
Quoted 41 lines · Vlad Buslov
Quoted 40 lines · Tony Nguyen
Wojciech Drewek says:
Linux bridge provides ability to learn MAC addresses and vlans detected on bridge's ports. As a result of this, FDB (forward data base) entries are created and they can be offloaded to the HW. By adding VF's port representors to the bridge together with the uplink netdev, we can learn VF's and link partner's MAC addresses. This is achieved by slow/exception-path, where packets that do not match any filters (FDB entries in this case) are send to the bridge ports.
Driver keeps track of the netdevs added to the bridge
by listening forNETDEV_CHANGEUPPERevent. We distinguish two types of bridge ports: uplink port and VF's representor port. Linux bridge always learns src MAC of the packet on rx path. With the current slow-path implementation, it means that we will learn VF's MAC on port repr (when the VF transmits the packet) and link partner's MAC on uplink (when we receive it on uplink from LAN).The driver is notified about learning of the MAC/VLAN by SWITCHDEV_FDB_{ADD|DEL}_TO_DEVICE events. This is followed by creation of the HW filter. The direction of the filter is based on port type (uplink or VF repr). In case of the uplink, rule forwards the packets to the LAN (matching on link partner's MAC). When the notification is received on VF repr then the rule forwards the packets to the associated VF (matching on VF's MAC).
This approach would not work on its own however. This is because if one of the directions is offloaded, then the bridge would not be able to learn the other one. If the egress rule is added (learned on uplink) then the response from the VF will be sent directly to the LAN. The packet will not got through slow-path, it would not be seen on VF's port repr. Because of that, the bridge would not learn VF's MAC.
This is solved by introducing guard rule. It prevents forward rule from working until the opposite direction is offloaded.
Aging is not fully supported yet, aging time is static for now. The follow up submissions will introduce counters that will allow us to keep track if the rule is actually being used or not.
Quoted 8 lines
Quoted 4 lines
A few fixes/changes are needed for this feature to work with ice driver. These are introduced in first 5 patches.
Reviewed-by Vlad Buslov <[email protected]>In my previous reply I meant reviewed-by for the whole series, not for the cover letter specifically. Sorry for not being more clear!
For what its worth, it was my understanding that posting a "Reviewed-by" to the cover letter for the series implies that you reviewed and have no further comments to the whole series. I don't think you did anything wrong here :)
Thanks,
Jake
This series was applied to netdev/net-next.git (main) by Tony Nguyen <[email protected]>:
Hello:
This series was applied to netdev/net-next.git (main) by Tony Nguyen <[email protected]>:
Quoted 11 lines · On Mon, 24 Jul 2023 09:11:40 -0700 you wrote:
Wojciech Drewek says:
Linux bridge provides ability to learn MAC addresses and vlans detected on bridge's ports. As a result of this, FDB (forward data base) entries are created and they can be offloaded to the HW. By adding VF's port representors to the bridge together with the uplink netdev, we can learn VF's and link partner's MAC addresses. This is achieved by slow/exception-path, where packets that do not match any filters (FDB entries in this case) are send to the bridge ports.
[...]
Here is the summary with links:
- [net-next,v2,01/12] ice: Skip adv rules removal upon switchdev release
https://git.kernel.org/netdev/net-next/c/ee95d4420a2f - [net-next,v2,02/12] ice: Prohibit rx mode change in switchdev mode https://git.kernel.org/netdev/net-next/c/2571a3fa6251 - [net-next,v2,03/12] ice: Don't tx before switchdev is fully configured https://git.kernel.org/netdev/net-next/c/7aa529a69e92 - [net-next,v2,04/12] ice: Disable vlan pruning for uplink VSI https://git.kernel.org/netdev/net-next/c/6ab1155798c3 - [net-next,v2,05/12] ice: Unset src prune on uplink VSI https://git.kernel.org/netdev/net-next/c/6c0f4441d83b - [net-next,v2,06/12] ice: Implement basic eswitch bridge setup https://git.kernel.org/netdev/net-next/c/f6e8fb55e5af - [net-next,v2,07/12] ice: Switchdev FDB events support https://git.kernel.org/netdev/net-next/c/7c945a1a8e5f - [net-next,v2,08/12] ice: Add guard rule when creating FDB in switchdev https://git.kernel.org/netdev/net-next/c/bccd9bce29e0 - [net-next,v2,09/12] ice: Add VLAN FDB support in switchdev mode https://git.kernel.org/netdev/net-next/c/e9dda2cfab82 - [net-next,v2,10/12] ice: implement bridge port vlan https://git.kernel.org/netdev/net-next/c/2946204b3fa8 - [net-next,v2,11/12] ice: implement static version of ageing https://git.kernel.org/netdev/net-next/c/e42c6e0c902b - [net-next,v2,12/12] ice: add tracepoints for the switchdev bridge https://git.kernel.org/netdev/net-next/c/d129c2a245bf
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html