[dpdk-dev,v2,05/32] net/i40e: set TX loopback from PF

Message ID 1481081535-37448-6-git-send-email-wenzhuo.lu@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers

Checks

Context Check Description
checkpatch/checkpatch success coding style OK

Commit Message

Wenzhuo Lu Dec. 7, 2016, 3:31 a.m. UTC
  Support enabling/disabling TX loopback from PF.
User can call the API on PF to enable/disable TX loopback
for all the PF and VFs.

Signed-off-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
---
 drivers/net/i40e/i40e_ethdev.c            | 219 ++++++++++++++++++++++++++++++
 drivers/net/i40e/rte_pmd_i40e.h           |  16 +++
 drivers/net/i40e/rte_pmd_i40e_version.map |   1 +
 3 files changed, 236 insertions(+)
  

Comments

Ferruh Yigit Dec. 7, 2016, 1:04 p.m. UTC | #1
On 12/7/2016 3:31 AM, Wenzhuo Lu wrote:
> Support enabling/disabling TX loopback from PF.
> User can call the API on PF to enable/disable TX loopback
> for all the PF and VFs.
> 
> Signed-off-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
> ---
>  drivers/net/i40e/i40e_ethdev.c            | 219 ++++++++++++++++++++++++++++++
>  drivers/net/i40e/rte_pmd_i40e.h           |  16 +++
>  drivers/net/i40e/rte_pmd_i40e_version.map |   1 +
>  3 files changed, 236 insertions(+)
> 
> diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
> index ec863b9..8bd0d70 100644
> --- a/drivers/net/i40e/i40e_ethdev.c
> +++ b/drivers/net/i40e/i40e_ethdev.c
> @@ -9938,3 +9938,222 @@ static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
>  
>  	return ret;
>  }
> +

<...>

> +
> +static int
> +i40e_vsi_set_tx_loopback(struct i40e_vsi *vsi, uint8_t on)
> +{
> +	struct i40e_vsi_context ctxt;
> +	struct i40e_hw *hw;
> +	int ret;
> +
> +	hw = I40E_VSI_TO_HW(vsi);
> +
> +	/* Use the FW API if FW >= v5.0 */
> +	if (hw->aq.fw_maj_ver < 5) {
> +		PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
> +		return -ENOTSUP;
> +	}
> +
> +	/* Check if it has been already on or off */
> +	if (vsi->info.valid_sections &
> +		rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID)) {
> +		if (on) {
> +			if ((vsi->info.switch_id &
> +			     I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) ==
> +			    I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB)
> +				return 0; /* already on */
> +		} else {
> +			if ((vsi->info.switch_id &
> +			     I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) == 0)
> +				return 0; /* already off */
> +		}
> +	}
> +
> +	/* remove all the MACs first */
> +	ret = i40e_vsi_rm_mac_filter(vsi);
> +	if (ret)
> +		return ret;
> +
> +	vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
> +	if (on)
> +		vsi->info.switch_id |= I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
> +	else
> +		vsi->info.switch_id &= ~I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
> +

---->

> +	memset(&ctxt, 0, sizeof(ctxt));
> +	(void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
> +	ctxt.seid = vsi->seid;
> +
> +	ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
> +	if (ret != I40E_SUCCESS) {
> +		PMD_DRV_LOG(ERR, "Failed to update VSI params");
> +		return ret;
> +	}

<----

This part is now duplicated in a few functions, does it make sense to
make it separate function, in the first patch it appeared 3/32 ?

> +
> +	/* add all the MACs back */
> +	ret = i40e_vsi_restore_mac_filter(vsi);
> +	if (ret)
> +		return ret;
> +
> +	return ret;
> +}
> +
> +int
> +rte_pmd_i40e_set_tx_loopback(uint8_t port, uint8_t on)
> +{
> +	struct rte_eth_dev *dev;
> +	struct i40e_pf *pf;
> +	struct i40e_pf_vf *vf;
> +	struct i40e_vsi *vsi;
> +	uint16_t vf_id;
> +	int ret;
> +
> +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
> +
> +	dev = &rte_eth_devices[port];
> +
> +	pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
> +
> +	/* setup PF TX loopback */
> +	vsi = pf->main_vsi;
> +	ret = i40e_vsi_set_tx_loopback(vsi, on);
> +	if (ret)
> +		return ret;
> +
> +	/* setup TX loopback for all the VFs */
> +	if (!pf->vfs) {
> +		PMD_DRV_LOG(ERR, "Invalid argument.");
> +		return -EINVAL;
> +	}
> +
> +	for (vf_id = 0; vf_id < pf->vf_num; vf_id++) {
> +		vf = &pf->vfs[vf_id];
> +		vsi = vf->vsi;
> +
> +		ret = i40e_vsi_set_tx_loopback(vsi, on);
> +		if (ret)
> +			return ret;
> +	}
> +
> +	return ret;
> +}
> diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
> index c8736c8..3c65be4 100644
> --- a/drivers/net/i40e/rte_pmd_i40e.h
> +++ b/drivers/net/i40e/rte_pmd_i40e.h
> @@ -114,4 +114,20 @@ int rte_pmd_i40e_set_vf_vlan_anti_spoof(uint8_t port,
>  					uint16_t vf_id,
>  					uint8_t on);
>  
> +/**
> + * Enable/Disable TX loopback on all the PF and VFs.
> + *
> + * @param port
> + *    The port identifier of the Ethernet device.
> + * @param on
> + *    1 - Enable TX loopback.
> + *    0 - Disable TX loopback.
> + * @return
> + *   - (0) if successful.
> + *   - (-ENODEV) if *port* invalid.
> + *   - (-EINVAL) if bad parameter.
> + */
> +int rte_pmd_i40e_set_tx_loopback(uint8_t port,
> +				 uint8_t on);
> +
>  #endif /* _PMD_I40E_H_ */
> diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map b/drivers/net/i40e/rte_pmd_i40e_version.map
> index fff6cf9..3da04d3 100644
> --- a/drivers/net/i40e/rte_pmd_i40e_version.map
> +++ b/drivers/net/i40e/rte_pmd_i40e_version.map
> @@ -9,4 +9,5 @@ DPDK_17.02 {
>  	rte_pmd_i40e_ping_vfs;
>  	rte_pmd_i40e_set_vf_mac_anti_spoof;
>  	rte_pmd_i40e_set_vf_vlan_anti_spoof;
> +	rte_pmd_i40e_set_tx_loopback;

We can add these alphabetically.
This may not worth to create a new version of the patch itself, but can
be fixed if a new version already required..

>  } DPDK_2.0;
>
  
Wenzhuo Lu Dec. 20, 2016, 8:16 a.m. UTC | #2
Hi Ferruh,


> -----Original Message-----
> From: Yigit, Ferruh
> Sent: Wednesday, December 7, 2016 9:05 PM
> To: Lu, Wenzhuo; dev@dpdk.org
> Subject: Re: [dpdk-dev] [PATCH v2 05/32] net/i40e: set TX loopback from PF
> 
> On 12/7/2016 3:31 AM, Wenzhuo Lu wrote:
> > Support enabling/disabling TX loopback from PF.
> > User can call the API on PF to enable/disable TX loopback for all the
> > PF and VFs.
> >
> > Signed-off-by: Wenzhuo Lu <wenzhuo.lu@intel.com>
> > ---
> >  drivers/net/i40e/i40e_ethdev.c            | 219
> ++++++++++++++++++++++++++++++
> >  drivers/net/i40e/rte_pmd_i40e.h           |  16 +++
> >  drivers/net/i40e/rte_pmd_i40e_version.map |   1 +
> >  3 files changed, 236 insertions(+)
> >
> > diff --git a/drivers/net/i40e/i40e_ethdev.c
> > b/drivers/net/i40e/i40e_ethdev.c index ec863b9..8bd0d70 100644
> > --- a/drivers/net/i40e/i40e_ethdev.c
> > +++ b/drivers/net/i40e/i40e_ethdev.c
> > @@ -9938,3 +9938,222 @@ static void i40e_set_default_mac_addr(struct
> > rte_eth_dev *dev,
> >
> >  	return ret;
> >  }
> > +
> 
> <...>
> 
> > +
> > +static int
> > +i40e_vsi_set_tx_loopback(struct i40e_vsi *vsi, uint8_t on) {
> > +	struct i40e_vsi_context ctxt;
> > +	struct i40e_hw *hw;
> > +	int ret;
> > +
> > +	hw = I40E_VSI_TO_HW(vsi);
> > +
> > +	/* Use the FW API if FW >= v5.0 */
> > +	if (hw->aq.fw_maj_ver < 5) {
> > +		PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
> > +		return -ENOTSUP;
> > +	}
> > +
> > +	/* Check if it has been already on or off */
> > +	if (vsi->info.valid_sections &
> > +		rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID)) {
> > +		if (on) {
> > +			if ((vsi->info.switch_id &
> > +			     I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) ==
> > +			    I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB)
> > +				return 0; /* already on */
> > +		} else {
> > +			if ((vsi->info.switch_id &
> > +			     I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) == 0)
> > +				return 0; /* already off */
> > +		}
> > +	}
> > +
> > +	/* remove all the MACs first */
> > +	ret = i40e_vsi_rm_mac_filter(vsi);
> > +	if (ret)
> > +		return ret;
> > +
> > +	vsi->info.valid_sections =
> cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
> > +	if (on)
> > +		vsi->info.switch_id |= I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
> > +	else
> > +		vsi->info.switch_id &= ~I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
> > +
> 
> ---->
> 
> > +	memset(&ctxt, 0, sizeof(ctxt));
> > +	(void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
> > +	ctxt.seid = vsi->seid;
> > +
> > +	ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
> > +	if (ret != I40E_SUCCESS) {
> > +		PMD_DRV_LOG(ERR, "Failed to update VSI params");
> > +		return ret;
> > +	}
> 
> <----
> 
> This part is now duplicated in a few functions, does it make sense to make it
> separate function, in the first patch it appeared 3/32 ?
There's already a function 'i40e_aq_update_vsi_params'. The duplicate code is for preparing the parameter for the functions. It looks bad to me if we add a function for that.

> 
> > +
> > +	/* add all the MACs back */
> > +	ret = i40e_vsi_restore_mac_filter(vsi);
> > +	if (ret)
> > +		return ret;
> > +
> > +	return ret;
> > +}
> > +
> > +int
> > +rte_pmd_i40e_set_tx_loopback(uint8_t port, uint8_t on) {
> > +	struct rte_eth_dev *dev;
> > +	struct i40e_pf *pf;
> > +	struct i40e_pf_vf *vf;
> > +	struct i40e_vsi *vsi;
> > +	uint16_t vf_id;
> > +	int ret;
> > +
> > +	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
> > +
> > +	dev = &rte_eth_devices[port];
> > +
> > +	pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
> > +
> > +	/* setup PF TX loopback */
> > +	vsi = pf->main_vsi;
> > +	ret = i40e_vsi_set_tx_loopback(vsi, on);
> > +	if (ret)
> > +		return ret;
> > +
> > +	/* setup TX loopback for all the VFs */
> > +	if (!pf->vfs) {
> > +		PMD_DRV_LOG(ERR, "Invalid argument.");
> > +		return -EINVAL;
> > +	}
> > +
> > +	for (vf_id = 0; vf_id < pf->vf_num; vf_id++) {
> > +		vf = &pf->vfs[vf_id];
> > +		vsi = vf->vsi;
> > +
> > +		ret = i40e_vsi_set_tx_loopback(vsi, on);
> > +		if (ret)
> > +			return ret;
> > +	}
> > +
> > +	return ret;
> > +}
> > diff --git a/drivers/net/i40e/rte_pmd_i40e.h
> > b/drivers/net/i40e/rte_pmd_i40e.h index c8736c8..3c65be4 100644
> > --- a/drivers/net/i40e/rte_pmd_i40e.h
> > +++ b/drivers/net/i40e/rte_pmd_i40e.h
> > @@ -114,4 +114,20 @@ int rte_pmd_i40e_set_vf_vlan_anti_spoof(uint8_t
> port,
> >  					uint16_t vf_id,
> >  					uint8_t on);
> >
> > +/**
> > + * Enable/Disable TX loopback on all the PF and VFs.
> > + *
> > + * @param port
> > + *    The port identifier of the Ethernet device.
> > + * @param on
> > + *    1 - Enable TX loopback.
> > + *    0 - Disable TX loopback.
> > + * @return
> > + *   - (0) if successful.
> > + *   - (-ENODEV) if *port* invalid.
> > + *   - (-EINVAL) if bad parameter.
> > + */
> > +int rte_pmd_i40e_set_tx_loopback(uint8_t port,
> > +				 uint8_t on);
> > +
> >  #endif /* _PMD_I40E_H_ */
> > diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map
> > b/drivers/net/i40e/rte_pmd_i40e_version.map
> > index fff6cf9..3da04d3 100644
> > --- a/drivers/net/i40e/rte_pmd_i40e_version.map
> > +++ b/drivers/net/i40e/rte_pmd_i40e_version.map
> > @@ -9,4 +9,5 @@ DPDK_17.02 {
> >  	rte_pmd_i40e_ping_vfs;
> >  	rte_pmd_i40e_set_vf_mac_anti_spoof;
> >  	rte_pmd_i40e_set_vf_vlan_anti_spoof;
> > +	rte_pmd_i40e_set_tx_loopback;
> 
> We can add these alphabetically.
> This may not worth to create a new version of the patch itself, but can be fixed
> if a new version already required..
Yes, will do it.

> 
> >  } DPDK_2.0;
> >
  

Patch

diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index ec863b9..8bd0d70 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -9938,3 +9938,222 @@  static void i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 
 	return ret;
 }
+
+static int
+i40e_vsi_rm_mac_filter(struct i40e_vsi *vsi)
+{
+	struct i40e_mac_filter *f;
+	struct i40e_macvlan_filter *mv_f;
+	int i, vlan_num;
+	enum rte_mac_filter_type filter_type;
+	int ret = I40E_SUCCESS;
+
+	/* remove all the MACs */
+	TAILQ_FOREACH(f, &vsi->mac_list, next) {
+		vlan_num = vsi->vlan_num;
+		filter_type = f->mac_info.filter_type;
+		if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
+		    filter_type == RTE_MACVLAN_HASH_MATCH) {
+			if (vlan_num == 0) {
+				PMD_DRV_LOG(ERR,
+					    "VLAN number shouldn't be 0\n");
+				return I40E_ERR_PARAM;
+			}
+		} else if (filter_type == RTE_MAC_PERFECT_MATCH ||
+			   filter_type == RTE_MAC_HASH_MATCH)
+			vlan_num = 1;
+
+		mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
+		if (!mv_f) {
+			PMD_DRV_LOG(ERR, "failed to allocate memory");
+			return I40E_ERR_NO_MEMORY;
+		}
+
+		for (i = 0; i < vlan_num; i++) {
+			mv_f[i].filter_type = filter_type;
+			(void)rte_memcpy(&mv_f[i].macaddr,
+					 &f->mac_info.mac_addr,
+					 ETH_ADDR_LEN);
+		}
+		if (filter_type == RTE_MACVLAN_PERFECT_MATCH ||
+		    filter_type == RTE_MACVLAN_HASH_MATCH) {
+			ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
+							 &f->mac_info.mac_addr);
+			if (ret != I40E_SUCCESS) {
+				rte_free(mv_f);
+				return ret;
+			}
+		}
+
+		ret = i40e_remove_macvlan_filters(vsi, mv_f, vlan_num);
+		if (ret != I40E_SUCCESS) {
+			rte_free(mv_f);
+			return ret;
+		}
+
+		rte_free(mv_f);
+		ret = I40E_SUCCESS;
+	}
+
+	return ret;
+}
+
+static int
+i40e_vsi_restore_mac_filter(struct i40e_vsi *vsi)
+{
+	struct i40e_mac_filter *f;
+	struct i40e_macvlan_filter *mv_f;
+	int i, vlan_num = 0;
+	int ret = I40E_SUCCESS;
+
+	/* restore all the MACs */
+	TAILQ_FOREACH(f, &vsi->mac_list, next) {
+		if ((f->mac_info.filter_type == RTE_MACVLAN_PERFECT_MATCH) ||
+		    (f->mac_info.filter_type == RTE_MACVLAN_HASH_MATCH)) {
+			/**
+			 * If vlan_num is 0, that's the first time to add mac,
+			 * set mask for vlan_id 0.
+			 */
+			if (vsi->vlan_num == 0) {
+				i40e_set_vlan_filter(vsi, 0, 1);
+				vsi->vlan_num = 1;
+			}
+			vlan_num = vsi->vlan_num;
+		} else if ((f->mac_info.filter_type == RTE_MAC_PERFECT_MATCH) ||
+			   (f->mac_info.filter_type == RTE_MAC_HASH_MATCH))
+			vlan_num = 1;
+
+		mv_f = rte_zmalloc("macvlan_data", vlan_num * sizeof(*mv_f), 0);
+		if (!mv_f) {
+			PMD_DRV_LOG(ERR, "failed to allocate memory");
+			return I40E_ERR_NO_MEMORY;
+		}
+
+		for (i = 0; i < vlan_num; i++) {
+			mv_f[i].filter_type = f->mac_info.filter_type;
+			(void)rte_memcpy(&mv_f[i].macaddr,
+					 &f->mac_info.mac_addr,
+					 ETH_ADDR_LEN);
+		}
+
+		if (f->mac_info.filter_type == RTE_MACVLAN_PERFECT_MATCH ||
+		    f->mac_info.filter_type == RTE_MACVLAN_HASH_MATCH) {
+			ret = i40e_find_all_vlan_for_mac(vsi, mv_f, vlan_num,
+							 &f->mac_info.mac_addr);
+			if (ret != I40E_SUCCESS) {
+				rte_free(mv_f);
+				return ret;
+			}
+		}
+
+		ret = i40e_add_macvlan_filters(vsi, mv_f, vlan_num);
+		if (ret != I40E_SUCCESS) {
+			rte_free(mv_f);
+			return ret;
+		}
+
+		rte_free(mv_f);
+		ret = I40E_SUCCESS;
+	}
+
+	return ret;
+}
+
+static int
+i40e_vsi_set_tx_loopback(struct i40e_vsi *vsi, uint8_t on)
+{
+	struct i40e_vsi_context ctxt;
+	struct i40e_hw *hw;
+	int ret;
+
+	hw = I40E_VSI_TO_HW(vsi);
+
+	/* Use the FW API if FW >= v5.0 */
+	if (hw->aq.fw_maj_ver < 5) {
+		PMD_INIT_LOG(ERR, "FW < v5.0, cannot enable loopback");
+		return -ENOTSUP;
+	}
+
+	/* Check if it has been already on or off */
+	if (vsi->info.valid_sections &
+		rte_cpu_to_le_16(I40E_AQ_VSI_PROP_SWITCH_VALID)) {
+		if (on) {
+			if ((vsi->info.switch_id &
+			     I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) ==
+			    I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB)
+				return 0; /* already on */
+		} else {
+			if ((vsi->info.switch_id &
+			     I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB) == 0)
+				return 0; /* already off */
+		}
+	}
+
+	/* remove all the MACs first */
+	ret = i40e_vsi_rm_mac_filter(vsi);
+	if (ret)
+		return ret;
+
+	vsi->info.valid_sections = cpu_to_le16(I40E_AQ_VSI_PROP_SWITCH_VALID);
+	if (on)
+		vsi->info.switch_id |= I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
+	else
+		vsi->info.switch_id &= ~I40E_AQ_VSI_SW_ID_FLAG_ALLOW_LB;
+
+	memset(&ctxt, 0, sizeof(ctxt));
+	(void)rte_memcpy(&ctxt.info, &vsi->info, sizeof(vsi->info));
+	ctxt.seid = vsi->seid;
+
+	ret = i40e_aq_update_vsi_params(hw, &ctxt, NULL);
+	if (ret != I40E_SUCCESS) {
+		PMD_DRV_LOG(ERR, "Failed to update VSI params");
+		return ret;
+	}
+
+	/* add all the MACs back */
+	ret = i40e_vsi_restore_mac_filter(vsi);
+	if (ret)
+		return ret;
+
+	return ret;
+}
+
+int
+rte_pmd_i40e_set_tx_loopback(uint8_t port, uint8_t on)
+{
+	struct rte_eth_dev *dev;
+	struct i40e_pf *pf;
+	struct i40e_pf_vf *vf;
+	struct i40e_vsi *vsi;
+	uint16_t vf_id;
+	int ret;
+
+	RTE_ETH_VALID_PORTID_OR_ERR_RET(port, -ENODEV);
+
+	dev = &rte_eth_devices[port];
+
+	pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
+
+	/* setup PF TX loopback */
+	vsi = pf->main_vsi;
+	ret = i40e_vsi_set_tx_loopback(vsi, on);
+	if (ret)
+		return ret;
+
+	/* setup TX loopback for all the VFs */
+	if (!pf->vfs) {
+		PMD_DRV_LOG(ERR, "Invalid argument.");
+		return -EINVAL;
+	}
+
+	for (vf_id = 0; vf_id < pf->vf_num; vf_id++) {
+		vf = &pf->vfs[vf_id];
+		vsi = vf->vsi;
+
+		ret = i40e_vsi_set_tx_loopback(vsi, on);
+		if (ret)
+			return ret;
+	}
+
+	return ret;
+}
diff --git a/drivers/net/i40e/rte_pmd_i40e.h b/drivers/net/i40e/rte_pmd_i40e.h
index c8736c8..3c65be4 100644
--- a/drivers/net/i40e/rte_pmd_i40e.h
+++ b/drivers/net/i40e/rte_pmd_i40e.h
@@ -114,4 +114,20 @@  int rte_pmd_i40e_set_vf_vlan_anti_spoof(uint8_t port,
 					uint16_t vf_id,
 					uint8_t on);
 
+/**
+ * Enable/Disable TX loopback on all the PF and VFs.
+ *
+ * @param port
+ *    The port identifier of the Ethernet device.
+ * @param on
+ *    1 - Enable TX loopback.
+ *    0 - Disable TX loopback.
+ * @return
+ *   - (0) if successful.
+ *   - (-ENODEV) if *port* invalid.
+ *   - (-EINVAL) if bad parameter.
+ */
+int rte_pmd_i40e_set_tx_loopback(uint8_t port,
+				 uint8_t on);
+
 #endif /* _PMD_I40E_H_ */
diff --git a/drivers/net/i40e/rte_pmd_i40e_version.map b/drivers/net/i40e/rte_pmd_i40e_version.map
index fff6cf9..3da04d3 100644
--- a/drivers/net/i40e/rte_pmd_i40e_version.map
+++ b/drivers/net/i40e/rte_pmd_i40e_version.map
@@ -9,4 +9,5 @@  DPDK_17.02 {
 	rte_pmd_i40e_ping_vfs;
 	rte_pmd_i40e_set_vf_mac_anti_spoof;
 	rte_pmd_i40e_set_vf_vlan_anti_spoof;
+	rte_pmd_i40e_set_tx_loopback;
 } DPDK_2.0;