diff mbox series

[v3,bpf-next,02/11] ice: allow toggling loopback mode via ndo_set_features callback

Message ID 20220615161041.902916-3-maciej.fijalkowski@intel.com (mailing list archive)
State Superseded
Delegated to: BPF
Headers show
Series AF_XDP ZC selftests | expand

Checks

Context Check Description
bpf/vmtest-bpf-next-PR success PR summary
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Series has a cover letter
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers warning 13 maintainers not CCed: kafai@fb.com intel-wired-lan@lists.osuosl.org songliubraving@fb.com anthony.l.nguyen@intel.com jesse.brandeburg@intel.com pabeni@redhat.com kuba@kernel.org edumazet@google.com davem@davemloft.net yhs@fb.com john.fastabend@gmail.com andrii@kernel.org kpsingh@kernel.org
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 42 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-1 success Logs for Kernel LATEST on ubuntu-latest with gcc
bpf/vmtest-bpf-next-VM_Test-2 success Logs for Kernel LATEST on ubuntu-latest with llvm-15
bpf/vmtest-bpf-next-VM_Test-3 success Logs for Kernel LATEST on z15 with gcc

Commit Message

Fijalkowski, Maciej June 15, 2022, 4:10 p.m. UTC
Add support for NETIF_F_LOOPBACK. This feature can be set via:
$ ethtool -K eth0 loopback <on|off>

Feature can be useful for local data path tests.

CC: Alexandr Lobakin <alexandr.lobakin@intel.com>
Signed-off-by: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
---
 drivers/net/ethernet/intel/ice/ice_main.c | 24 +++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Jakub Kicinski June 15, 2022, 11:50 p.m. UTC | #1
On Wed, 15 Jun 2022 18:10:32 +0200 Maciej Fijalkowski wrote:
> +	if (if_running)
> +		ice_stop(netdev);
> +	if (ice_aq_set_mac_loopback(hw, ena, NULL))
> +		netdev_err(netdev, "Failed to toggle loopback state\n");
> +	if (if_running)
> +		ice_open(netdev);

Ay. Looks like I commented on previous version, same complaint.
diff mbox series

Patch

diff --git a/drivers/net/ethernet/intel/ice/ice_main.c b/drivers/net/ethernet/intel/ice/ice_main.c
index 23d1b1fc39fb..85d956517b2e 100644
--- a/drivers/net/ethernet/intel/ice/ice_main.c
+++ b/drivers/net/ethernet/intel/ice/ice_main.c
@@ -3358,6 +3358,7 @@  static void ice_set_netdev_features(struct net_device *netdev)
 	netdev->features |= netdev->hw_features;
 
 	netdev->hw_features |= NETIF_F_HW_TC;
+	netdev->hw_features |= NETIF_F_LOOPBACK;
 
 	/* encap and VLAN devices inherit default, csumo and tso features */
 	netdev->hw_enc_features |= dflt_features | csumo_features |
@@ -5902,6 +5903,25 @@  ice_set_vlan_features(struct net_device *netdev, netdev_features_t features)
 	return 0;
 }
 
+/**
+ * ice_set_loopback - turn on/off loopback mode on underlying PF
+ * @hw: ptr to ice_hw struct needed for AQ command
+ * @netdev: ptr to the netdev being adjusted
+ * @ena: flag to indicate the on/off setting
+ */
+static void
+ice_set_loopback(struct ice_hw *hw, struct net_device *netdev, bool ena)
+{
+	bool if_running = netif_running(netdev);
+
+	if (if_running)
+		ice_stop(netdev);
+	if (ice_aq_set_mac_loopback(hw, ena, NULL))
+		netdev_err(netdev, "Failed to toggle loopback state\n");
+	if (if_running)
+		ice_open(netdev);
+}
+
 /**
  * ice_set_features - set the netdev feature flags
  * @netdev: ptr to the netdev being adjusted
@@ -5960,6 +5980,10 @@  ice_set_features(struct net_device *netdev, netdev_features_t features)
 		      clear_bit(ICE_FLAG_CLS_FLOWER, pf->flags);
 	}
 
+	if (changed & NETIF_F_LOOPBACK)
+		ice_set_loopback(&pf->hw, netdev,
+				 !!(features & NETIF_F_LOOPBACK));
+
 	return 0;
 }