From patchwork Wed Nov 9 15:20:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tirthendu Sarkar X-Patchwork-Id: 13037646 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7B8AFC4332F for ; Wed, 9 Nov 2022 15:37:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230165AbiKIPhh (ORCPT ); Wed, 9 Nov 2022 10:37:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230153AbiKIPhf (ORCPT ); Wed, 9 Nov 2022 10:37:35 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 606D9BD1 for ; Wed, 9 Nov 2022 07:37:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1668008254; x=1699544254; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=j8ohFXTDf5LbUAkuSQef8+KA/jlhlC9ARroEqvsIzkc=; b=JKbva3I2AbTX/XUKyVzj9uau+YC8O4cU9sWHo1Q0KnMm6bDgyTvQPGoq FD7Q9KTHhGQHcVNfbCZjWsyUVs1vEok8fQkplNz4I+6wlBjhmWswgLeMX 2NkdHrk6atf0jkfkPnDXQsfc85TrjmD80IWdopCyi4VZCmNhtjHXKPFu9 o27YU9HVd1NiaBhEGYc4FeB7NfcOr8VTG1zX2zbjYpRKVMiDPi7QZ2ELx DWvKW5LjrtstD1JvdSP+9BMWV/TI+DnfWe7r25yefDm7fBx0/Cds1hZyC vQr3wni0cRy4sgRgP8H/BAlwk9GWem2M8/95SDAajw/L87x7Rc3D30uXS A==; X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="311003359" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="311003359" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 07:33:19 -0800 X-IronPort-AV: E=McAfee;i="6500,9779,10526"; a="668025673" X-IronPort-AV: E=Sophos;i="5.96,151,1665471600"; d="scan'208";a="668025673" Received: from unknown (HELO paamrpdk12-S2600BPB.aw.intel.com) ([10.228.151.145]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Nov 2022 07:33:18 -0800 From: Tirthendu Sarkar To: tirtha@gmail.com, magnus.karlsson@intel.com, intel-wired-lan@lists.osuosl.org, anthony.l.nguyen@intel.com, maciej.fijalkowski@intel.com Cc: netdev@vger.kernel.org Subject: [PATCH intel-next] i40e: allow toggling loopback mode via Date: Wed, 9 Nov 2022 20:50:16 +0530 Message-Id: <20221109152016.66326-1-tirthendu.sarkar@intel.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Add support for NETIF_F_LOOPBACK. This feature can be set via: $ ethtool -K eth0 loopback This sets the MAC Tx->Rx loopback. This feature is used for the xsk selftests, and might have other uses too. Signed-off-by: Tirthendu Sarkar --- drivers/net/ethernet/intel/i40e/i40e_common.c | 22 +++++++++++++++ drivers/net/ethernet/intel/i40e/i40e_main.c | 28 +++++++++++++++++++ .../net/ethernet/intel/i40e/i40e_prototype.h | 3 ++ 3 files changed, 53 insertions(+) diff --git a/drivers/net/ethernet/intel/i40e/i40e_common.c b/drivers/net/ethernet/intel/i40e/i40e_common.c index 4f01e2a6b6bb..73d2c700dc35 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_common.c +++ b/drivers/net/ethernet/intel/i40e/i40e_common.c @@ -1830,6 +1830,28 @@ i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw, return status; } +/** + * i40e_aq_set_mac_loopback + * @hw: pointer to the HW struct + * @ena_lpbk: Enable or Disable loopback + * @cmd_details: pointer to command details structure or NULL + * + * Enable/disable loopback on a given port + */ +i40e_status i40e_aq_set_mac_loopback(struct i40e_hw *hw, bool ena_lpbk, + struct i40e_asq_cmd_details *cmd_details) +{ + struct i40e_aq_desc desc; + struct i40e_aqc_set_lb_mode *cmd = + (struct i40e_aqc_set_lb_mode *)&desc.params.raw; + + i40e_fill_default_direct_cmd_desc(&desc, i40e_aqc_opc_set_lb_modes); + if (ena_lpbk) + cmd->lb_mode = cpu_to_le16(I40E_AQ_LB_MAC_LOCAL); + + return i40e_asq_send_command(hw, &desc, NULL, 0, cmd_details); +} + /** * i40e_aq_set_phy_debug * @hw: pointer to the hw struct diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 1a1fab94205d..04d2922f7646 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -12919,6 +12919,28 @@ static void i40e_clear_rss_lut(struct i40e_vsi *vsi) } } +/** + * i40e_set_loopback - turn on/off loopback mode on underlying PF + * @vsi: ptr to VSI + * @ena: flag to indicate the on/off setting + */ +static int i40e_set_loopback(struct i40e_vsi *vsi, bool ena) +{ + bool if_running = netif_running(vsi->netdev); + int ret; + + if (if_running && !test_and_set_bit(__I40E_VSI_DOWN, vsi->state)) + i40e_down(vsi); + + ret = i40e_aq_set_mac_loopback(&vsi->back->hw, ena, NULL); + if (ret) + netdev_err(vsi->netdev, "Failed to toggle loopback state\n"); + if (if_running) + i40e_up(vsi); + + return ret; +} + /** * i40e_set_features - set the netdev feature flags * @netdev: ptr to the netdev being adjusted @@ -12959,6 +12981,10 @@ static int i40e_set_features(struct net_device *netdev, if (need_reset) i40e_do_reset(pf, I40E_PF_RESET_FLAG, true); + if (features & NETIF_F_LOOPBACK) + if (i40e_set_loopback(vsi, !!(features & NETIF_F_LOOPBACK))) + return -EINVAL; + return 0; } @@ -13721,6 +13747,8 @@ static int i40e_config_netdev(struct i40e_vsi *vsi) if (!(pf->flags & I40E_FLAG_MFP_ENABLED)) hw_features |= NETIF_F_NTUPLE | NETIF_F_HW_TC; + hw_features |= NETIF_F_LOOPBACK; + netdev->hw_features |= hw_features; netdev->features |= hw_features | NETIF_F_HW_VLAN_CTAG_FILTER; diff --git a/drivers/net/ethernet/intel/i40e/i40e_prototype.h b/drivers/net/ethernet/intel/i40e/i40e_prototype.h index ebdcde6f1aeb..9a71121420c3 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_prototype.h +++ b/drivers/net/ethernet/intel/i40e/i40e_prototype.h @@ -105,6 +105,9 @@ enum i40e_status_code i40e_aq_set_phy_config(struct i40e_hw *hw, struct i40e_asq_cmd_details *cmd_details); enum i40e_status_code i40e_set_fc(struct i40e_hw *hw, u8 *aq_failures, bool atomic_reset); +i40e_status i40e_aq_set_mac_loopback(struct i40e_hw *hw, + bool ena_lpbk, + struct i40e_asq_cmd_details *cmd_details); i40e_status i40e_aq_set_phy_int_mask(struct i40e_hw *hw, u16 mask, struct i40e_asq_cmd_details *cmd_details); i40e_status i40e_aq_clear_pxe_mode(struct i40e_hw *hw,