All of lore.kernel.org
 help / color / mirror / Atom feed
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Hao Ma <maxwillma0713@gmail.com>
Cc: Hao Ma <hao.ma@intel.com>,
	netdev@vger.kernel.org, jesse.brandeburg@intel.com,
	anthony.l.nguyen@intel.com, intel-wired-lan@lists.osuosl.org,
	magnus.karlsson@intel.com
Subject: Re: [Intel-wired-lan] [PATCH intel-net] ixgbe: allow toggling loopback mode via ndo_set_features callback
Date: Tue, 4 Apr 2023 11:35:57 +0200	[thread overview]
Message-ID: <ZCvvfQTYtH2S3P6k@boxer> (raw)
In-Reply-To: <20230321003524.700353-1-maxwillma0713@gmail.com>

On Tue, Mar 21, 2023 at 08:35:24AM +0800, Hao Ma wrote:
> From: Hao Ma <hao.ma@intel.com>
> 
> Add support for NETIF_F_LOOPBACK. This feature can be set via:
> $ ethtool -K eth0 loopback <on|off>
> 
> This sets the MAC Tx->Rx loopback used by selftests/bpf/xskxceiver

Can you resend this patch please? It seems it didn't arrive to iwl nor
netdev.

> 
> Signed-off-by: Hao Ma <hao.ma@intel.com>
> ---
>  .../net/ethernet/intel/ixgbe/ixgbe_common.c   |  4 +-
>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 73 +++++++++++++++++++
>  drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  1 +
>  3 files changed, 76 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
> index 38c4609bd429..a39dd2d11bc8 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
> @@ -3336,7 +3336,7 @@ s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
>  
>  	if (link_up_wait_to_complete) {
>  		for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
> -			if (links_reg & IXGBE_LINKS_UP) {
> +			if (links_reg & IXGBE_LINKS_UP || hw->loopback_on) {
>  				*link_up = true;
>  				break;
>  			} else {
> @@ -3346,7 +3346,7 @@ s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
>  			links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
>  		}
>  	} else {
> -		if (links_reg & IXGBE_LINKS_UP)
> +		if (links_reg & IXGBE_LINKS_UP || hw->loopback_on)
>  			*link_up = true;
>  		else
>  			*link_up = false;
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> index ab8370c413f3..e5624d1fc6c3 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> @@ -8874,6 +8874,57 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
>  	return NETDEV_TX_OK;
>  }
>  
> +static int ixgbe_force_loopback(struct ixgbe_adapter *adapter, bool on)
> +{	struct ixgbe_hw *hw = &adapter->hw;
> +	u32 reg_data;
> +
> +	hw->loopback_on = on;
> +	/* Setup MAC loopback */
> +	reg_data = IXGBE_READ_REG(hw, IXGBE_HLREG0);
> +	if (on)
> +		reg_data |= IXGBE_HLREG0_LPBK;
> +	else
> +		reg_data &= ~IXGBE_HLREG0_LPBK;
> +	IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_data);
> +
> +	reg_data = IXGBE_READ_REG(hw, IXGBE_FCTRL);
> +	if (on)
> +		reg_data |= IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE;
> +	else
> +		reg_data &= ~(IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE);
> +	reg_data &= ~(IXGBE_FCTRL_BAM);
> +	IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_data);
> +
> +	/* X540 and X550 needs to set the MACC.FLU bit to force link up */
> +	switch (adapter->hw.mac.type) {
> +	case ixgbe_mac_X540:
> +	case ixgbe_mac_X550:
> +	case ixgbe_mac_X550EM_x:
> +	case ixgbe_mac_x550em_a:
> +		reg_data = IXGBE_READ_REG(hw, IXGBE_MACC);
> +		if (on)
> +			reg_data |= IXGBE_MACC_FLU;
> +		else
> +			reg_data &= ~IXGBE_MACC_FLU;
> +		IXGBE_WRITE_REG(hw, IXGBE_MACC, reg_data);
> +		break;
> +	default:
> +		if (hw->mac.orig_autoc) {
> +			if (on)
> +				reg_data = hw->mac.orig_autoc | IXGBE_AUTOC_FLU;
> +			else
> +				reg_data = hw->mac.orig_autoc & ~IXGBE_AUTOC_FLU;
> +			IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_data);
> +		} else {
> +			return 10;
> +		}
> +	}
> +
> +	IXGBE_WRITE_FLUSH(hw);
> +
> +	return 0;
> +}
> +
>  static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
>  				      struct net_device *netdev,
>  				      struct ixgbe_ring *ring)
> @@ -9923,6 +9974,15 @@ static int ixgbe_set_features(struct net_device *netdev,
>  	if (changed & NETIF_F_RXALL)
>  		need_reset = true;
>  
> +	if (changed & NETIF_F_LOOPBACK) {
> +		if (features & NETIF_F_LOOPBACK) {
> +			ixgbe_force_loopback(adapter, true);
> +		} else {
> +			ixgbe_force_loopback(adapter, false);
> +			need_reset = true;
> +			}
> +	}
> +
>  	netdev->features = features;
>  
>  	if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
> @@ -10296,6 +10356,17 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
>  			/* Wait until ndo_xsk_wakeup completes. */
>  			synchronize_rcu();
>  		err = ixgbe_setup_tc(dev, adapter->hw_tcs);
> +		if (adapter->hw.loopback_on) {
> +			u32 reg_data;
> +
> +			reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0);
> +			reg_data |= IXGBE_HLREG0_LPBK;
> +			IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data);
> +
> +			reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_MACC);
> +			reg_data |= IXGBE_MACC_FLU;
> +			IXGBE_WRITE_REG(&adapter->hw, IXGBE_MACC, reg_data);
> +		}
>  
>  		if (err) {
>  			rcu_assign_pointer(adapter->xdp_prog, old_prog);
> @@ -10979,6 +11050,8 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	if (hw->mac.type >= ixgbe_mac_82599EB)
>  		netdev->features |= NETIF_F_SCTP_CRC | NETIF_F_GSO_UDP_L4;
>  
> +	netdev->features |= NETIF_F_LOOPBACK;
> +
>  #ifdef CONFIG_IXGBE_IPSEC
>  #define IXGBE_ESP_FEATURES	(NETIF_F_HW_ESP | \
>  				 NETIF_F_HW_ESP_TX_CSUM | \
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
> index 2b00db92b08f..ca50ccd59b50 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
> @@ -3652,6 +3652,7 @@ struct ixgbe_hw {
>  	bool				allow_unsupported_sfp;
>  	bool				wol_enabled;
>  	bool				need_crosstalk_fix;
> +	bool				loopback_on;
>  };
>  
>  struct ixgbe_info {
> -- 
> 2.34.1
> 
_______________________________________________
Intel-wired-lan mailing list
Intel-wired-lan@osuosl.org
https://lists.osuosl.org/mailman/listinfo/intel-wired-lan

WARNING: multiple messages have this Message-ID (diff)
From: Maciej Fijalkowski <maciej.fijalkowski@intel.com>
To: Hao Ma <maxwillma0713@gmail.com>
Cc: <intel-wired-lan@lists.osuosl.org>, <anthony.l.nguyen@intel.com>,
	<jesse.brandeburg@intel.com>, <netdev@vger.kernel.org>,
	<magnus.karlsson@intel.com>, Hao Ma <hao.ma@intel.com>
Subject: Re: [PATCH intel-net] ixgbe: allow toggling loopback mode via ndo_set_features callback
Date: Tue, 4 Apr 2023 11:35:57 +0200	[thread overview]
Message-ID: <ZCvvfQTYtH2S3P6k@boxer> (raw)
In-Reply-To: <20230321003524.700353-1-maxwillma0713@gmail.com>

On Tue, Mar 21, 2023 at 08:35:24AM +0800, Hao Ma wrote:
> From: Hao Ma <hao.ma@intel.com>
> 
> Add support for NETIF_F_LOOPBACK. This feature can be set via:
> $ ethtool -K eth0 loopback <on|off>
> 
> This sets the MAC Tx->Rx loopback used by selftests/bpf/xskxceiver

Can you resend this patch please? It seems it didn't arrive to iwl nor
netdev.

> 
> Signed-off-by: Hao Ma <hao.ma@intel.com>
> ---
>  .../net/ethernet/intel/ixgbe/ixgbe_common.c   |  4 +-
>  drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 73 +++++++++++++++++++
>  drivers/net/ethernet/intel/ixgbe/ixgbe_type.h |  1 +
>  3 files changed, 76 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
> index 38c4609bd429..a39dd2d11bc8 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_common.c
> @@ -3336,7 +3336,7 @@ s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
>  
>  	if (link_up_wait_to_complete) {
>  		for (i = 0; i < IXGBE_LINK_UP_TIME; i++) {
> -			if (links_reg & IXGBE_LINKS_UP) {
> +			if (links_reg & IXGBE_LINKS_UP || hw->loopback_on) {
>  				*link_up = true;
>  				break;
>  			} else {
> @@ -3346,7 +3346,7 @@ s32 ixgbe_check_mac_link_generic(struct ixgbe_hw *hw, ixgbe_link_speed *speed,
>  			links_reg = IXGBE_READ_REG(hw, IXGBE_LINKS);
>  		}
>  	} else {
> -		if (links_reg & IXGBE_LINKS_UP)
> +		if (links_reg & IXGBE_LINKS_UP || hw->loopback_on)
>  			*link_up = true;
>  		else
>  			*link_up = false;
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> index ab8370c413f3..e5624d1fc6c3 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c
> @@ -8874,6 +8874,57 @@ netdev_tx_t ixgbe_xmit_frame_ring(struct sk_buff *skb,
>  	return NETDEV_TX_OK;
>  }
>  
> +static int ixgbe_force_loopback(struct ixgbe_adapter *adapter, bool on)
> +{	struct ixgbe_hw *hw = &adapter->hw;
> +	u32 reg_data;
> +
> +	hw->loopback_on = on;
> +	/* Setup MAC loopback */
> +	reg_data = IXGBE_READ_REG(hw, IXGBE_HLREG0);
> +	if (on)
> +		reg_data |= IXGBE_HLREG0_LPBK;
> +	else
> +		reg_data &= ~IXGBE_HLREG0_LPBK;
> +	IXGBE_WRITE_REG(hw, IXGBE_HLREG0, reg_data);
> +
> +	reg_data = IXGBE_READ_REG(hw, IXGBE_FCTRL);
> +	if (on)
> +		reg_data |= IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE;
> +	else
> +		reg_data &= ~(IXGBE_FCTRL_SBP | IXGBE_FCTRL_MPE);
> +	reg_data &= ~(IXGBE_FCTRL_BAM);
> +	IXGBE_WRITE_REG(hw, IXGBE_FCTRL, reg_data);
> +
> +	/* X540 and X550 needs to set the MACC.FLU bit to force link up */
> +	switch (adapter->hw.mac.type) {
> +	case ixgbe_mac_X540:
> +	case ixgbe_mac_X550:
> +	case ixgbe_mac_X550EM_x:
> +	case ixgbe_mac_x550em_a:
> +		reg_data = IXGBE_READ_REG(hw, IXGBE_MACC);
> +		if (on)
> +			reg_data |= IXGBE_MACC_FLU;
> +		else
> +			reg_data &= ~IXGBE_MACC_FLU;
> +		IXGBE_WRITE_REG(hw, IXGBE_MACC, reg_data);
> +		break;
> +	default:
> +		if (hw->mac.orig_autoc) {
> +			if (on)
> +				reg_data = hw->mac.orig_autoc | IXGBE_AUTOC_FLU;
> +			else
> +				reg_data = hw->mac.orig_autoc & ~IXGBE_AUTOC_FLU;
> +			IXGBE_WRITE_REG(hw, IXGBE_AUTOC, reg_data);
> +		} else {
> +			return 10;
> +		}
> +	}
> +
> +	IXGBE_WRITE_FLUSH(hw);
> +
> +	return 0;
> +}
> +
>  static netdev_tx_t __ixgbe_xmit_frame(struct sk_buff *skb,
>  				      struct net_device *netdev,
>  				      struct ixgbe_ring *ring)
> @@ -9923,6 +9974,15 @@ static int ixgbe_set_features(struct net_device *netdev,
>  	if (changed & NETIF_F_RXALL)
>  		need_reset = true;
>  
> +	if (changed & NETIF_F_LOOPBACK) {
> +		if (features & NETIF_F_LOOPBACK) {
> +			ixgbe_force_loopback(adapter, true);
> +		} else {
> +			ixgbe_force_loopback(adapter, false);
> +			need_reset = true;
> +			}
> +	}
> +
>  	netdev->features = features;
>  
>  	if ((changed & NETIF_F_HW_L2FW_DOFFLOAD) && adapter->num_rx_pools > 1)
> @@ -10296,6 +10356,17 @@ static int ixgbe_xdp_setup(struct net_device *dev, struct bpf_prog *prog)
>  			/* Wait until ndo_xsk_wakeup completes. */
>  			synchronize_rcu();
>  		err = ixgbe_setup_tc(dev, adapter->hw_tcs);
> +		if (adapter->hw.loopback_on) {
> +			u32 reg_data;
> +
> +			reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_HLREG0);
> +			reg_data |= IXGBE_HLREG0_LPBK;
> +			IXGBE_WRITE_REG(&adapter->hw, IXGBE_HLREG0, reg_data);
> +
> +			reg_data = IXGBE_READ_REG(&adapter->hw, IXGBE_MACC);
> +			reg_data |= IXGBE_MACC_FLU;
> +			IXGBE_WRITE_REG(&adapter->hw, IXGBE_MACC, reg_data);
> +		}
>  
>  		if (err) {
>  			rcu_assign_pointer(adapter->xdp_prog, old_prog);
> @@ -10979,6 +11050,8 @@ static int ixgbe_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
>  	if (hw->mac.type >= ixgbe_mac_82599EB)
>  		netdev->features |= NETIF_F_SCTP_CRC | NETIF_F_GSO_UDP_L4;
>  
> +	netdev->features |= NETIF_F_LOOPBACK;
> +
>  #ifdef CONFIG_IXGBE_IPSEC
>  #define IXGBE_ESP_FEATURES	(NETIF_F_HW_ESP | \
>  				 NETIF_F_HW_ESP_TX_CSUM | \
> diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
> index 2b00db92b08f..ca50ccd59b50 100644
> --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
> +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
> @@ -3652,6 +3652,7 @@ struct ixgbe_hw {
>  	bool				allow_unsupported_sfp;
>  	bool				wol_enabled;
>  	bool				need_crosstalk_fix;
> +	bool				loopback_on;
>  };
>  
>  struct ixgbe_info {
> -- 
> 2.34.1
> 

       reply	other threads:[~2023-04-04  9:36 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230321003524.700353-1-maxwillma0713@gmail.com>
2023-04-04  9:35 ` Maciej Fijalkowski [this message]
2023-04-04  9:35   ` [PATCH intel-net] ixgbe: allow toggling loopback mode via ndo_set_features callback Maciej Fijalkowski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZCvvfQTYtH2S3P6k@boxer \
    --to=maciej.fijalkowski@intel.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=hao.ma@intel.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jesse.brandeburg@intel.com \
    --cc=magnus.karlsson@intel.com \
    --cc=maxwillma0713@gmail.com \
    --cc=netdev@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.