diff mbox series

[2/4] ethdev: move jumbo frame offload check to library

Message ID 20210709172923.3369846-2-ferruh.yigit@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Andrew Rybchenko
Headers show
Series [1/4] ethdev: fix max Rx packet length | expand

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Ferruh Yigit July 9, 2021, 5:29 p.m. UTC
Setting MTU bigger than RTE_ETHER_MTU requires the jumbo frame support,
and application should enable the jumbo frame offload support for it.

When jumbo frame offload is not enabled by application, but MTU bigger
than RTE_ETHER_MTU is requested there are two options, either fail or
enable jumbo frame offload implicitly.

Enabling jumbo frame offload implicitly is selected by many drivers
since setting a big MTU value already implies it, and this increases
usability.

This patch moves this logic from drivers to the library, both to reduce
the duplicated code in the drivers and to make behaviour more visible.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
---
 drivers/net/axgbe/axgbe_ethdev.c        |  9 ++-------
 drivers/net/bnxt/bnxt_ethdev.c          |  9 ++-------
 drivers/net/cnxk/cnxk_ethdev_ops.c      |  5 -----
 drivers/net/cxgbe/cxgbe_ethdev.c        |  8 --------
 drivers/net/dpaa/dpaa_ethdev.c          |  7 -------
 drivers/net/dpaa2/dpaa2_ethdev.c        |  7 -------
 drivers/net/e1000/em_ethdev.c           |  9 ++-------
 drivers/net/e1000/igb_ethdev.c          |  9 ++-------
 drivers/net/enetc/enetc_ethdev.c        |  7 -------
 drivers/net/hinic/hinic_pmd_ethdev.c    |  7 -------
 drivers/net/hns3/hns3_ethdev.c          |  8 --------
 drivers/net/hns3/hns3_ethdev_vf.c       |  6 ------
 drivers/net/i40e/i40e_ethdev.c          |  5 -----
 drivers/net/i40e/i40e_ethdev_vf.c       |  5 -----
 drivers/net/iavf/iavf_ethdev.c          |  7 -------
 drivers/net/ice/ice_ethdev.c            |  5 -----
 drivers/net/igc/igc_ethdev.c            |  9 ++-------
 drivers/net/ipn3ke/ipn3ke_representor.c |  5 -----
 drivers/net/ixgbe/ixgbe_ethdev.c        |  7 ++-----
 drivers/net/liquidio/lio_ethdev.c       |  7 -------
 drivers/net/nfp/nfp_net.c               |  6 ------
 drivers/net/octeontx/octeontx_ethdev.c  |  5 -----
 drivers/net/octeontx2/otx2_ethdev_ops.c |  5 -----
 drivers/net/qede/qede_ethdev.c          |  4 ----
 drivers/net/sfc/sfc_ethdev.c            |  9 ---------
 drivers/net/thunderx/nicvf_ethdev.c     |  6 ------
 drivers/net/txgbe/txgbe_ethdev.c        |  6 ------
 lib/ethdev/rte_ethdev.c                 | 18 +++++++++++++++++-
 28 files changed, 29 insertions(+), 171 deletions(-)

Comments

Andrew Rybchenko July 13, 2021, 1:48 p.m. UTC | #1
On 7/9/21 8:29 PM, Ferruh Yigit wrote:
> Setting MTU bigger than RTE_ETHER_MTU requires the jumbo frame support,
> and application should enable the jumbo frame offload support for it.
> 
> When jumbo frame offload is not enabled by application, but MTU bigger
> than RTE_ETHER_MTU is requested there are two options, either fail or
> enable jumbo frame offload implicitly.
> 
> Enabling jumbo frame offload implicitly is selected by many drivers
> since setting a big MTU value already implies it, and this increases
> usability.
> 
> This patch moves this logic from drivers to the library, both to reduce
> the duplicated code in the drivers and to make behaviour more visible.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>

Very good cleanup, many thanks.

Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>

[snip]

> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
> index 3451125639f9..d649a5dd69a9 100644
> --- a/lib/ethdev/rte_ethdev.c
> +++ b/lib/ethdev/rte_ethdev.c
> @@ -3625,6 +3625,7 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
>  	int ret;
>  	struct rte_eth_dev_info dev_info;
>  	struct rte_eth_dev *dev;
> +	int is_jumbo_frame_capable = 0;
>  
>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>  	dev = &rte_eth_devices[port_id];
> @@ -3643,12 +3644,27 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
>  
>  		if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
>  			return -EINVAL;
> +
> +		if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)
> +			is_jumbo_frame_capable = 1;
>  	}
>  
> +	if (mtu > RTE_ETHER_MTU && is_jumbo_frame_capable == 0)
> +		return -EINVAL;
> +
>  	ret = (*dev->dev_ops->mtu_set)(dev, mtu);
> -	if (!ret)
> +	if (!ret) {

Since line it updated anyway, may I ask to use explicit
comparison vs 0 as coding style says.

>  		dev->data->mtu = mtu;
>  
> +		/* switch to jumbo mode if needed */
> +		if (mtu > RTE_ETHER_MTU)
> +			dev->data->dev_conf.rxmode.offloads |=
> +				DEV_RX_OFFLOAD_JUMBO_FRAME;
> +		else
> +			dev->data->dev_conf.rxmode.offloads &=
> +				~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	}
> +
>  	return eth_err(port_id, ret);
>  }
>  
>
Xu, Rosen July 18, 2021, 7:49 a.m. UTC | #2
Hi,

> -----Original Message-----
> From: Yigit, Ferruh <ferruh.yigit@intel.com>
> Sent: Saturday, July 10, 2021 1:29
> To: Somalapuram Amaranath <asomalap@amd.com>; Ajit Khaparde
> <ajit.khaparde@broadcom.com>; Somnath Kotur
> <somnath.kotur@broadcom.com>; Nithin Dabilpuram
> <ndabilpuram@marvell.com>; Kiran Kumar K <kirankumark@marvell.com>;
> Sunil Kumar Kori <skori@marvell.com>; Satha Rao
> <skoteshwar@marvell.com>; Rahul Lakkireddy
> <rahul.lakkireddy@chelsio.com>; Hemant Agrawal
> <hemant.agrawal@nxp.com>; Sachin Saxena <sachin.saxena@oss.nxp.com>;
> Wang, Haiyue <haiyue.wang@intel.com>; Gagandeep Singh
> <g.singh@nxp.com>; Ziyang Xuan <xuanziyang2@huawei.com>; Xiaoyun
> Wang <cloud.wangxiaoyun@huawei.com>; Guoyang Zhou
> <zhouguoyang@huawei.com>; Min Hu (Connor) <humin29@huawei.com>;
> Yisen Zhuang <yisen.zhuang@huawei.com>; Lijun Ou
> <oulijun@huawei.com>; Xing, Beilei <beilei.xing@intel.com>; Wu, Jingjing
> <jingjing.wu@intel.com>; Yang, Qiming <qiming.yang@intel.com>; Zhang, Qi
> Z <qi.z.zhang@intel.com>; Xu, Rosen <rosen.xu@intel.com>; Shijith Thotton
> <sthotton@marvell.com>; Srisivasubramanian Srinivasan
> <srinivasan@marvell.com>; Heinrich Kuhn
> <heinrich.kuhn@netronome.com>; Harman Kalra <hkalra@marvell.com>;
> Jerin Jacob <jerinj@marvell.com>; Rasesh Mody <rmody@marvell.com>;
> Devendra Singh Rawat <dsinghrawat@marvell.com>; Igor Russkikh
> <irusskikh@marvell.com>; Andrew Rybchenko
> <andrew.rybchenko@oktetlabs.ru>; Maciej Czekaj <mczekaj@marvell.com>;
> Jiawen Wu <jiawenwu@trustnetic.com>; Jian Wang
> <jianwang@trustnetic.com>; Thomas Monjalon <thomas@monjalon.net>
> Cc: Yigit, Ferruh <ferruh.yigit@intel.com>; dev@dpdk.org
> Subject: [PATCH 2/4] ethdev: move jumbo frame offload check to library
> 
> Setting MTU bigger than RTE_ETHER_MTU requires the jumbo frame support,
> and application should enable the jumbo frame offload support for it.
> 
> When jumbo frame offload is not enabled by application, but MTU bigger
> than RTE_ETHER_MTU is requested there are two options, either fail or
> enable jumbo frame offload implicitly.
> 
> Enabling jumbo frame offload implicitly is selected by many drivers since
> setting a big MTU value already implies it, and this increases usability.
> 
> This patch moves this logic from drivers to the library, both to reduce the
> duplicated code in the drivers and to make behaviour more visible.
> 
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  drivers/net/axgbe/axgbe_ethdev.c        |  9 ++-------
>  drivers/net/bnxt/bnxt_ethdev.c          |  9 ++-------
>  drivers/net/cnxk/cnxk_ethdev_ops.c      |  5 -----
>  drivers/net/cxgbe/cxgbe_ethdev.c        |  8 --------
>  drivers/net/dpaa/dpaa_ethdev.c          |  7 -------
>  drivers/net/dpaa2/dpaa2_ethdev.c        |  7 -------
>  drivers/net/e1000/em_ethdev.c           |  9 ++-------
>  drivers/net/e1000/igb_ethdev.c          |  9 ++-------
>  drivers/net/enetc/enetc_ethdev.c        |  7 -------
>  drivers/net/hinic/hinic_pmd_ethdev.c    |  7 -------
>  drivers/net/hns3/hns3_ethdev.c          |  8 --------
>  drivers/net/hns3/hns3_ethdev_vf.c       |  6 ------
>  drivers/net/i40e/i40e_ethdev.c          |  5 -----
>  drivers/net/i40e/i40e_ethdev_vf.c       |  5 -----
>  drivers/net/iavf/iavf_ethdev.c          |  7 -------
>  drivers/net/ice/ice_ethdev.c            |  5 -----
>  drivers/net/igc/igc_ethdev.c            |  9 ++-------
>  drivers/net/ipn3ke/ipn3ke_representor.c |  5 -----
>  drivers/net/ixgbe/ixgbe_ethdev.c        |  7 ++-----
>  drivers/net/liquidio/lio_ethdev.c       |  7 -------
>  drivers/net/nfp/nfp_net.c               |  6 ------
>  drivers/net/octeontx/octeontx_ethdev.c  |  5 -----
> drivers/net/octeontx2/otx2_ethdev_ops.c |  5 -----
>  drivers/net/qede/qede_ethdev.c          |  4 ----
>  drivers/net/sfc/sfc_ethdev.c            |  9 ---------
>  drivers/net/thunderx/nicvf_ethdev.c     |  6 ------
>  drivers/net/txgbe/txgbe_ethdev.c        |  6 ------
>  lib/ethdev/rte_ethdev.c                 | 18 +++++++++++++++++-
>  28 files changed, 29 insertions(+), 171 deletions(-)
> 
> diff --git a/drivers/net/axgbe/axgbe_ethdev.c
> b/drivers/net/axgbe/axgbe_ethdev.c
> index 76aeec077f2b..2960834b4539 100644
> --- a/drivers/net/axgbe/axgbe_ethdev.c
> +++ b/drivers/net/axgbe/axgbe_ethdev.c
> @@ -1492,15 +1492,10 @@ static int axgb_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  				dev->data->port_id);
>  		return -EBUSY;
>  	}
> -	if (mtu > RTE_ETHER_MTU) {
> -		dev->data->dev_conf.rxmode.offloads |=
> -			DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	if (mtu > RTE_ETHER_MTU)
>  		val = 1;
> -	} else {
> -		dev->data->dev_conf.rxmode.offloads &=
> -			~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	else
>  		val = 0;
> -	}
>  	AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
>  	return 0;
>  }
> diff --git a/drivers/net/bnxt/bnxt_ethdev.c
> b/drivers/net/bnxt/bnxt_ethdev.c index 335505a106d5..4344a012f06e
> 100644
> --- a/drivers/net/bnxt/bnxt_ethdev.c
> +++ b/drivers/net/bnxt/bnxt_ethdev.c
> @@ -3018,15 +3018,10 @@ int bnxt_mtu_set_op(struct rte_eth_dev
> *eth_dev, uint16_t new_mtu)
>  		return -EINVAL;
>  	}
> 
> -	if (new_mtu > RTE_ETHER_MTU) {
> +	if (new_mtu > RTE_ETHER_MTU)
>  		bp->flags |= BNXT_FLAG_JUMBO;
> -		bp->eth_dev->data->dev_conf.rxmode.offloads |=
> -			DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	} else {
> -		bp->eth_dev->data->dev_conf.rxmode.offloads &=
> -			~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	else
>  		bp->flags &= ~BNXT_FLAG_JUMBO;
> -	}
> 
>  	/* Is there a change in mtu setting? */
>  	if (eth_dev->data->mtu == new_mtu)
> diff --git a/drivers/net/cnxk/cnxk_ethdev_ops.c
> b/drivers/net/cnxk/cnxk_ethdev_ops.c
> index 695d0d6fd3e2..349896f6a1bf 100644
> --- a/drivers/net/cnxk/cnxk_ethdev_ops.c
> +++ b/drivers/net/cnxk/cnxk_ethdev_ops.c
> @@ -439,11 +439,6 @@ cnxk_nix_mtu_set(struct rte_eth_dev *eth_dev,
> uint16_t mtu)
>  		plt_err("Failed to max Rx frame length, rc=%d", rc);
>  		goto exit;
>  	}
> -
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
>  exit:
>  	return rc;
>  }
> diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c
> b/drivers/net/cxgbe/cxgbe_ethdev.c
> index 8cf61f12a8d6..0c9cc2f5bb3f 100644
> --- a/drivers/net/cxgbe/cxgbe_ethdev.c
> +++ b/drivers/net/cxgbe/cxgbe_ethdev.c
> @@ -313,14 +313,6 @@ int cxgbe_dev_mtu_set(struct rte_eth_dev
> *eth_dev, uint16_t mtu)
>  	if (mtu < RTE_ETHER_MIN_MTU || new_mtu >
> dev_info.max_rx_pktlen)
>  		return -EINVAL;
> 
> -	/* set to jumbo mode if needed */
> -	if (mtu > RTE_ETHER_MTU)
> -		eth_dev->data->dev_conf.rxmode.offloads |=
> -			DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		eth_dev->data->dev_conf.rxmode.offloads &=
> -			~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	err = t4_set_rxmode(adapter, adapter->mbox, pi->viid, new_mtu, -1,
> -1,
>  			    -1, -1, true);
>  	return err;
> diff --git a/drivers/net/dpaa/dpaa_ethdev.c
> b/drivers/net/dpaa/dpaa_ethdev.c index 56703e3a39e8..a444f749bb96
> 100644
> --- a/drivers/net/dpaa/dpaa_ethdev.c
> +++ b/drivers/net/dpaa/dpaa_ethdev.c
> @@ -187,13 +187,6 @@ dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t
> mtu)
>  		return -EINVAL;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->data->dev_conf.rxmode.offloads |=
> -
> 	DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -
> 	~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	fman_if_set_maxfrm(dev->process_private, frame_size);
> 
>  	return 0;
> diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c
> b/drivers/net/dpaa2/dpaa2_ethdev.c
> index 6213bcbf3a43..be2858b3adac 100644
> --- a/drivers/net/dpaa2/dpaa2_ethdev.c
> +++ b/drivers/net/dpaa2/dpaa2_ethdev.c
> @@ -1470,13 +1470,6 @@ dpaa2_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  	if (mtu < RTE_ETHER_MIN_MTU || frame_size >
> DPAA2_MAX_RX_PKT_LEN)
>  		return -EINVAL;
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->data->dev_conf.rxmode.offloads |=
> -
> 	DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -
> 	~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	/* Set the Max Rx frame length as 'mtu' +
>  	 * Maximum Ethernet header length
>  	 */
> diff --git a/drivers/net/e1000/em_ethdev.c
> b/drivers/net/e1000/em_ethdev.c index 6f418a36aa04..1b41dd04df5a
> 100644
> --- a/drivers/net/e1000/em_ethdev.c
> +++ b/drivers/net/e1000/em_ethdev.c
> @@ -1818,15 +1818,10 @@ eth_em_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  	rctl = E1000_READ_REG(hw, E1000_RCTL);
> 
>  	/* switch to jumbo mode if needed */
> -	if (mtu > RTE_ETHER_MTU) {
> -		dev->data->dev_conf.rxmode.offloads |=
> -			DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	if (mtu > RTE_ETHER_MTU)
>  		rctl |= E1000_RCTL_LPE;
> -	} else {
> -		dev->data->dev_conf.rxmode.offloads &=
> -			~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	else
>  		rctl &= ~E1000_RCTL_LPE;
> -	}
>  	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
> 
>  	return 0;
> diff --git a/drivers/net/e1000/igb_ethdev.c
> b/drivers/net/e1000/igb_ethdev.c index 35b517891d67..f15774eae20d
> 100644
> --- a/drivers/net/e1000/igb_ethdev.c
> +++ b/drivers/net/e1000/igb_ethdev.c
> @@ -4401,15 +4401,10 @@ eth_igb_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  	rctl = E1000_READ_REG(hw, E1000_RCTL);
> 
>  	/* switch to jumbo mode if needed */
> -	if (mtu > RTE_ETHER_MTU) {
> -		dev->data->dev_conf.rxmode.offloads |=
> -			DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	if (mtu > RTE_ETHER_MTU)
>  		rctl |= E1000_RCTL_LPE;
> -	} else {
> -		dev->data->dev_conf.rxmode.offloads &=
> -			~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	else
>  		rctl &= ~E1000_RCTL_LPE;
> -	}
>  	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
> 
>  	E1000_WRITE_REG(hw, E1000_RLPML, frame_size); diff --git
> a/drivers/net/enetc/enetc_ethdev.c b/drivers/net/enetc/enetc_ethdev.c
> index cdb9783b5372..fbcbbb6c0533 100644
> --- a/drivers/net/enetc/enetc_ethdev.c
> +++ b/drivers/net/enetc/enetc_ethdev.c
> @@ -677,13 +677,6 @@ enetc_mtu_set(struct rte_eth_dev *dev, uint16_t
> mtu)
>  		return -EINVAL;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->data->dev_conf.rxmode.offloads &=
> -
> 	DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -
> 	~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	enetc_port_wr(enetc_hw, ENETC_PTCMSDUR(0),
> ENETC_MAC_MAXFRM_SIZE);
>  	enetc_port_wr(enetc_hw, ENETC_PTXMBAR, 2 *
> ENETC_MAC_MAXFRM_SIZE);
> 
> diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c
> b/drivers/net/hinic/hinic_pmd_ethdev.c
> index c737ef8d06d8..c1cde811a252 100644
> --- a/drivers/net/hinic/hinic_pmd_ethdev.c
> +++ b/drivers/net/hinic/hinic_pmd_ethdev.c
> @@ -1556,13 +1556,6 @@ static int hinic_dev_set_mtu(struct rte_eth_dev
> *dev, uint16_t mtu)
>  		return ret;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->data->dev_conf.rxmode.offloads |=
> -			DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -			~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	nic_dev->mtu_size = mtu;
> 
>  	return ret;
> diff --git a/drivers/net/hns3/hns3_ethdev.c
> b/drivers/net/hns3/hns3_ethdev.c index 8bccdeddb2f7..868d381a4772
> 100644
> --- a/drivers/net/hns3/hns3_ethdev.c
> +++ b/drivers/net/hns3/hns3_ethdev.c
> @@ -2597,7 +2597,6 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  	struct hns3_adapter *hns = dev->data->dev_private;
>  	uint32_t frame_size = mtu + HNS3_ETH_OVERHEAD;
>  	struct hns3_hw *hw = &hns->hw;
> -	bool is_jumbo_frame;
>  	int ret;
> 
>  	if (dev->data->dev_started) {
> @@ -2607,7 +2606,6 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  	}
> 
>  	rte_spinlock_lock(&hw->lock);
> -	is_jumbo_frame = mtu > RTE_ETHER_MTU ? true : false;
>  	frame_size = RTE_MAX(frame_size, HNS3_DEFAULT_FRAME_LEN);
> 
>  	/*
> @@ -2622,12 +2620,6 @@ hns3_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  		return ret;
>  	}
> 
> -	if (is_jumbo_frame)
> -		dev->data->dev_conf.rxmode.offloads |=
> -
> 	DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -
> 	~DEV_RX_OFFLOAD_JUMBO_FRAME;
>  	rte_spinlock_unlock(&hw->lock);
> 
>  	return 0;
> diff --git a/drivers/net/hns3/hns3_ethdev_vf.c
> b/drivers/net/hns3/hns3_ethdev_vf.c
> index ca839fa55fa0..ff28cad53a03 100644
> --- a/drivers/net/hns3/hns3_ethdev_vf.c
> +++ b/drivers/net/hns3/hns3_ethdev_vf.c
> @@ -920,12 +920,6 @@ hns3vf_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  		rte_spinlock_unlock(&hw->lock);
>  		return ret;
>  	}
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->data->dev_conf.rxmode.offloads |=
> -
> 	DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -
> 	~DEV_RX_OFFLOAD_JUMBO_FRAME;
>  	rte_spinlock_unlock(&hw->lock);
> 
>  	return 0;
> diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
> index 1161f301b9ae..c5058f26dff2 100644
> --- a/drivers/net/i40e/i40e_ethdev.c
> +++ b/drivers/net/i40e/i40e_ethdev.c
> @@ -11772,11 +11772,6 @@ i40e_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  		return -EBUSY;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev_data->dev_conf.rxmode.offloads |=
> DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev_data->dev_conf.rxmode.offloads &=
> ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	return ret;
>  }
> 
> diff --git a/drivers/net/i40e/i40e_ethdev_vf.c
> b/drivers/net/i40e/i40e_ethdev_vf.c
> index 086a167ca672..2015a86ba5ca 100644
> --- a/drivers/net/i40e/i40e_ethdev_vf.c
> +++ b/drivers/net/i40e/i40e_ethdev_vf.c
> @@ -2884,11 +2884,6 @@ i40evf_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  		return -EBUSY;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev_data->dev_conf.rxmode.offloads |=
> DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev_data->dev_conf.rxmode.offloads &=
> ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	return ret;
>  }
> 
> diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
> index 13c2329d85a7..ba5be45e8c5e 100644
> --- a/drivers/net/iavf/iavf_ethdev.c
> +++ b/drivers/net/iavf/iavf_ethdev.c
> @@ -1446,13 +1446,6 @@ iavf_dev_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  		return -EBUSY;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev->data->dev_conf.rxmode.offloads |=
> -				DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev->data->dev_conf.rxmode.offloads &=
> -				~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	return ret;
>  }
> 
> diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
> index bdda6fee3f8e..502e410b5641 100644
> --- a/drivers/net/ice/ice_ethdev.c
> +++ b/drivers/net/ice/ice_ethdev.c
> @@ -3806,11 +3806,6 @@ ice_mtu_set(struct rte_eth_dev *dev, uint16_t
> mtu)
>  		return -EBUSY;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev_data->dev_conf.rxmode.offloads |=
> DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev_data->dev_conf.rxmode.offloads &=
> ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	return 0;
>  }
> 
> diff --git a/drivers/net/igc/igc_ethdev.c b/drivers/net/igc/igc_ethdev.c index
> b26723064b07..dcbc26b8186e 100644
> --- a/drivers/net/igc/igc_ethdev.c
> +++ b/drivers/net/igc/igc_ethdev.c
> @@ -1592,15 +1592,10 @@ eth_igc_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>  	}
> 
>  	rctl = IGC_READ_REG(hw, IGC_RCTL);
> -
> -	/* switch to jumbo mode if needed */
> -	if (mtu > RTE_ETHER_MTU) {
> -		dev->data->dev_conf.rxmode.offloads |=
> DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	if (mtu > RTE_ETHER_MTU)
>  		rctl |= IGC_RCTL_LPE;
> -	} else {
> -		dev->data->dev_conf.rxmode.offloads &=
> ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +	else
>  		rctl &= ~IGC_RCTL_LPE;
> -	}
>  	IGC_WRITE_REG(hw, IGC_RCTL, rctl);
> 
>  	IGC_WRITE_REG(hw, IGC_RLPML, frame_size); diff --git
> a/drivers/net/ipn3ke/ipn3ke_representor.c
> b/drivers/net/ipn3ke/ipn3ke_representor.c
> index 3634c0c8c5f0..e8a33f04bd69 100644
> --- a/drivers/net/ipn3ke/ipn3ke_representor.c
> +++ b/drivers/net/ipn3ke/ipn3ke_representor.c
> @@ -2801,11 +2801,6 @@ ipn3ke_rpst_mtu_set(struct rte_eth_dev
> *ethdev, uint16_t mtu)
>  		return -EBUSY;
>  	}
> 
> -	if (mtu > RTE_ETHER_MTU)
> -		dev_data->dev_conf.rxmode.offloads |=
> DEV_RX_OFFLOAD_JUMBO_FRAME;
> -	else
> -		dev_data->dev_conf.rxmode.offloads &=
> ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> -
>  	if (rpst->i40e_pf_eth) {
>  		ret = rpst->i40e_pf_eth->dev_ops->mtu_set(rpst-
> >i40e_pf_eth,
>  							mtu);

Reviewed-by: Rosen Xu <rosen.xu@intel.com>
Ajit Khaparde July 19, 2021, 2:38 p.m. UTC | #3
On Fri, Jul 9, 2021 at 10:30 AM Ferruh Yigit <ferruh.yigit@intel.com> wrote:

> Setting MTU bigger than RTE_ETHER_MTU requires the jumbo frame support,
> and application should enable the jumbo frame offload support for it.
>
> When jumbo frame offload is not enabled by application, but MTU bigger
> than RTE_ETHER_MTU is requested there are two options, either fail or
> enable jumbo frame offload implicitly.
>
> Enabling jumbo frame offload implicitly is selected by many drivers
> since setting a big MTU value already implies it, and this increases
> usability.
>
> This patch moves this logic from drivers to the library, both to reduce
> the duplicated code in the drivers and to make behaviour more visible.
>
> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> ---
>  drivers/net/axgbe/axgbe_ethdev.c        |  9 ++-------
>  drivers/net/bnxt/bnxt_ethdev.c          |  9 ++-------
>  drivers/net/cnxk/cnxk_ethdev_ops.c      |  5 -----
>  drivers/net/cxgbe/cxgbe_ethdev.c        |  8 --------
>  drivers/net/dpaa/dpaa_ethdev.c          |  7 -------
>  drivers/net/dpaa2/dpaa2_ethdev.c        |  7 -------
>  drivers/net/e1000/em_ethdev.c           |  9 ++-------
>  drivers/net/e1000/igb_ethdev.c          |  9 ++-------
>  drivers/net/enetc/enetc_ethdev.c        |  7 -------
>  drivers/net/hinic/hinic_pmd_ethdev.c    |  7 -------
>  drivers/net/hns3/hns3_ethdev.c          |  8 --------
>  drivers/net/hns3/hns3_ethdev_vf.c       |  6 ------
>  drivers/net/i40e/i40e_ethdev.c          |  5 -----
>  drivers/net/i40e/i40e_ethdev_vf.c       |  5 -----
>  drivers/net/iavf/iavf_ethdev.c          |  7 -------
>  drivers/net/ice/ice_ethdev.c            |  5 -----
>  drivers/net/igc/igc_ethdev.c            |  9 ++-------
>  drivers/net/ipn3ke/ipn3ke_representor.c |  5 -----
>  drivers/net/ixgbe/ixgbe_ethdev.c        |  7 ++-----
>  drivers/net/liquidio/lio_ethdev.c       |  7 -------
>  drivers/net/nfp/nfp_net.c               |  6 ------
>  drivers/net/octeontx/octeontx_ethdev.c  |  5 -----
>  drivers/net/octeontx2/otx2_ethdev_ops.c |  5 -----
>  drivers/net/qede/qede_ethdev.c          |  4 ----
>  drivers/net/sfc/sfc_ethdev.c            |  9 ---------
>  drivers/net/thunderx/nicvf_ethdev.c     |  6 ------
>  drivers/net/txgbe/txgbe_ethdev.c        |  6 ------
>  lib/ethdev/rte_ethdev.c                 | 18 +++++++++++++++++-
>  28 files changed, 29 insertions(+), 171 deletions(-)
>
> diff --git a/drivers/net/axgbe/axgbe_ethdev.c
> b/drivers/net/axgbe/axgbe_ethdev.c
> index 76aeec077f2b..2960834b4539 100644
> --- a/drivers/net/axgbe/axgbe_ethdev.c
> +++ b/drivers/net/axgbe/axgbe_ethdev.c
> @@ -1492,15 +1492,10 @@ static int axgb_mtu_set(struct rte_eth_dev *dev,
> uint16_t mtu)
>                                 dev->data->port_id);
>                 return -EBUSY;
>         }
> -       if (mtu > RTE_ETHER_MTU) {
> -               dev->data->dev_conf.rxmode.offloads |=
> -                       DEV_RX_OFFLOAD_JUMBO_FRAME;
> +       if (mtu > RTE_ETHER_MTU)
>                 val = 1;
> -       } else {
> -               dev->data->dev_conf.rxmode.offloads &=
> -                       ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +       else
>                 val = 0;
> -       }
>         AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
>         return 0;
>  }
> diff --git a/drivers/net/bnxt/bnxt_ethdev.c
> b/drivers/net/bnxt/bnxt_ethdev.c
> index 335505a106d5..4344a012f06e 100644
> --- a/drivers/net/bnxt/bnxt_ethdev.c
> +++ b/drivers/net/bnxt/bnxt_ethdev.c
> @@ -3018,15 +3018,10 @@ int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev,
> uint16_t new_mtu)
>                 return -EINVAL;
>         }
>
> -       if (new_mtu > RTE_ETHER_MTU) {
> +       if (new_mtu > RTE_ETHER_MTU)
>                 bp->flags |= BNXT_FLAG_JUMBO;
> -               bp->eth_dev->data->dev_conf.rxmode.offloads |=
> -                       DEV_RX_OFFLOAD_JUMBO_FRAME;
> -       } else {
> -               bp->eth_dev->data->dev_conf.rxmode.offloads &=
> -                       ~DEV_RX_OFFLOAD_JUMBO_FRAME;
> +       else
>                 bp->flags &= ~BNXT_FLAG_JUMBO;
> -       }
>
Acked-by: Ajit Khaparde <ajit.khaparde@broadcom.com>



>
>
Ferruh Yigit July 21, 2021, 12:26 p.m. UTC | #4
On 7/13/2021 2:48 PM, Andrew Rybchenko wrote:
> On 7/9/21 8:29 PM, Ferruh Yigit wrote:
>> Setting MTU bigger than RTE_ETHER_MTU requires the jumbo frame support,
>> and application should enable the jumbo frame offload support for it.
>>
>> When jumbo frame offload is not enabled by application, but MTU bigger
>> than RTE_ETHER_MTU is requested there are two options, either fail or
>> enable jumbo frame offload implicitly.
>>
>> Enabling jumbo frame offload implicitly is selected by many drivers
>> since setting a big MTU value already implies it, and this increases
>> usability.
>>
>> This patch moves this logic from drivers to the library, both to reduce
>> the duplicated code in the drivers and to make behaviour more visible.
>>
>> Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
> 
> Very good cleanup, many thanks.
> 
> Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
> 
> [snip]
> 
>> diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
>> index 3451125639f9..d649a5dd69a9 100644
>> --- a/lib/ethdev/rte_ethdev.c
>> +++ b/lib/ethdev/rte_ethdev.c
>> @@ -3625,6 +3625,7 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
>>  	int ret;
>>  	struct rte_eth_dev_info dev_info;
>>  	struct rte_eth_dev *dev;
>> +	int is_jumbo_frame_capable = 0;
>>  
>>  	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
>>  	dev = &rte_eth_devices[port_id];
>> @@ -3643,12 +3644,27 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
>>  
>>  		if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
>>  			return -EINVAL;
>> +
>> +		if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)
>> +			is_jumbo_frame_capable = 1;
>>  	}
>>  
>> +	if (mtu > RTE_ETHER_MTU && is_jumbo_frame_capable == 0)
>> +		return -EINVAL;
>> +
>>  	ret = (*dev->dev_ops->mtu_set)(dev, mtu);
>> -	if (!ret)
>> +	if (!ret) {
> 
> Since line it updated anyway, may I ask to use explicit
> comparison vs 0 as coding style says.
> 

ack, will fix all occurrences

>>  		dev->data->mtu = mtu;
>>  
>> +		/* switch to jumbo mode if needed */
>> +		if (mtu > RTE_ETHER_MTU)
>> +			dev->data->dev_conf.rxmode.offloads |=
>> +				DEV_RX_OFFLOAD_JUMBO_FRAME;
>> +		else
>> +			dev->data->dev_conf.rxmode.offloads &=
>> +				~DEV_RX_OFFLOAD_JUMBO_FRAME;
>> +	}
>> +
>>  	return eth_err(port_id, ret);
>>  }
>>  
>>
>
diff mbox series

Patch

diff --git a/drivers/net/axgbe/axgbe_ethdev.c b/drivers/net/axgbe/axgbe_ethdev.c
index 76aeec077f2b..2960834b4539 100644
--- a/drivers/net/axgbe/axgbe_ethdev.c
+++ b/drivers/net/axgbe/axgbe_ethdev.c
@@ -1492,15 +1492,10 @@  static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 				dev->data->port_id);
 		return -EBUSY;
 	}
-	if (mtu > RTE_ETHER_MTU) {
-		dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (mtu > RTE_ETHER_MTU)
 		val = 1;
-	} else {
-		dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	else
 		val = 0;
-	}
 	AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
 	return 0;
 }
diff --git a/drivers/net/bnxt/bnxt_ethdev.c b/drivers/net/bnxt/bnxt_ethdev.c
index 335505a106d5..4344a012f06e 100644
--- a/drivers/net/bnxt/bnxt_ethdev.c
+++ b/drivers/net/bnxt/bnxt_ethdev.c
@@ -3018,15 +3018,10 @@  int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
 		return -EINVAL;
 	}
 
-	if (new_mtu > RTE_ETHER_MTU) {
+	if (new_mtu > RTE_ETHER_MTU)
 		bp->flags |= BNXT_FLAG_JUMBO;
-		bp->eth_dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
-	} else {
-		bp->eth_dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	else
 		bp->flags &= ~BNXT_FLAG_JUMBO;
-	}
 
 	/* Is there a change in mtu setting? */
 	if (eth_dev->data->mtu == new_mtu)
diff --git a/drivers/net/cnxk/cnxk_ethdev_ops.c b/drivers/net/cnxk/cnxk_ethdev_ops.c
index 695d0d6fd3e2..349896f6a1bf 100644
--- a/drivers/net/cnxk/cnxk_ethdev_ops.c
+++ b/drivers/net/cnxk/cnxk_ethdev_ops.c
@@ -439,11 +439,6 @@  cnxk_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 		plt_err("Failed to max Rx frame length, rc=%d", rc);
 		goto exit;
 	}
-
-	if (mtu > RTE_ETHER_MTU)
-		dev->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
 exit:
 	return rc;
 }
diff --git a/drivers/net/cxgbe/cxgbe_ethdev.c b/drivers/net/cxgbe/cxgbe_ethdev.c
index 8cf61f12a8d6..0c9cc2f5bb3f 100644
--- a/drivers/net/cxgbe/cxgbe_ethdev.c
+++ b/drivers/net/cxgbe/cxgbe_ethdev.c
@@ -313,14 +313,6 @@  int cxgbe_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 	if (mtu < RTE_ETHER_MIN_MTU || new_mtu > dev_info.max_rx_pktlen)
 		return -EINVAL;
 
-	/* set to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU)
-		eth_dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		eth_dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	err = t4_set_rxmode(adapter, adapter->mbox, pi->viid, new_mtu, -1, -1,
 			    -1, -1, true);
 	return err;
diff --git a/drivers/net/dpaa/dpaa_ethdev.c b/drivers/net/dpaa/dpaa_ethdev.c
index 56703e3a39e8..a444f749bb96 100644
--- a/drivers/net/dpaa/dpaa_ethdev.c
+++ b/drivers/net/dpaa/dpaa_ethdev.c
@@ -187,13 +187,6 @@  dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EINVAL;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |=
-						DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-						~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	fman_if_set_maxfrm(dev->process_private, frame_size);
 
 	return 0;
diff --git a/drivers/net/dpaa2/dpaa2_ethdev.c b/drivers/net/dpaa2/dpaa2_ethdev.c
index 6213bcbf3a43..be2858b3adac 100644
--- a/drivers/net/dpaa2/dpaa2_ethdev.c
+++ b/drivers/net/dpaa2/dpaa2_ethdev.c
@@ -1470,13 +1470,6 @@  dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA2_MAX_RX_PKT_LEN)
 		return -EINVAL;
 
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |=
-						DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-						~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	/* Set the Max Rx frame length as 'mtu' +
 	 * Maximum Ethernet header length
 	 */
diff --git a/drivers/net/e1000/em_ethdev.c b/drivers/net/e1000/em_ethdev.c
index 6f418a36aa04..1b41dd04df5a 100644
--- a/drivers/net/e1000/em_ethdev.c
+++ b/drivers/net/e1000/em_ethdev.c
@@ -1818,15 +1818,10 @@  eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	rctl = E1000_READ_REG(hw, E1000_RCTL);
 
 	/* switch to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU) {
-		dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (mtu > RTE_ETHER_MTU)
 		rctl |= E1000_RCTL_LPE;
-	} else {
-		dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	else
 		rctl &= ~E1000_RCTL_LPE;
-	}
 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
 
 	return 0;
diff --git a/drivers/net/e1000/igb_ethdev.c b/drivers/net/e1000/igb_ethdev.c
index 35b517891d67..f15774eae20d 100644
--- a/drivers/net/e1000/igb_ethdev.c
+++ b/drivers/net/e1000/igb_ethdev.c
@@ -4401,15 +4401,10 @@  eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	rctl = E1000_READ_REG(hw, E1000_RCTL);
 
 	/* switch to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU) {
-		dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (mtu > RTE_ETHER_MTU)
 		rctl |= E1000_RCTL_LPE;
-	} else {
-		dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	else
 		rctl &= ~E1000_RCTL_LPE;
-	}
 	E1000_WRITE_REG(hw, E1000_RCTL, rctl);
 
 	E1000_WRITE_REG(hw, E1000_RLPML, frame_size);
diff --git a/drivers/net/enetc/enetc_ethdev.c b/drivers/net/enetc/enetc_ethdev.c
index cdb9783b5372..fbcbbb6c0533 100644
--- a/drivers/net/enetc/enetc_ethdev.c
+++ b/drivers/net/enetc/enetc_ethdev.c
@@ -677,13 +677,6 @@  enetc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EINVAL;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads &=
-						DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-						~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	enetc_port_wr(enetc_hw, ENETC_PTCMSDUR(0), ENETC_MAC_MAXFRM_SIZE);
 	enetc_port_wr(enetc_hw, ENETC_PTXMBAR, 2 * ENETC_MAC_MAXFRM_SIZE);
 
diff --git a/drivers/net/hinic/hinic_pmd_ethdev.c b/drivers/net/hinic/hinic_pmd_ethdev.c
index c737ef8d06d8..c1cde811a252 100644
--- a/drivers/net/hinic/hinic_pmd_ethdev.c
+++ b/drivers/net/hinic/hinic_pmd_ethdev.c
@@ -1556,13 +1556,6 @@  static int hinic_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 		return ret;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	nic_dev->mtu_size = mtu;
 
 	return ret;
diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 8bccdeddb2f7..868d381a4772 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2597,7 +2597,6 @@  hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	struct hns3_adapter *hns = dev->data->dev_private;
 	uint32_t frame_size = mtu + HNS3_ETH_OVERHEAD;
 	struct hns3_hw *hw = &hns->hw;
-	bool is_jumbo_frame;
 	int ret;
 
 	if (dev->data->dev_started) {
@@ -2607,7 +2606,6 @@  hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	}
 
 	rte_spinlock_lock(&hw->lock);
-	is_jumbo_frame = mtu > RTE_ETHER_MTU ? true : false;
 	frame_size = RTE_MAX(frame_size, HNS3_DEFAULT_FRAME_LEN);
 
 	/*
@@ -2622,12 +2620,6 @@  hns3_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return ret;
 	}
 
-	if (is_jumbo_frame)
-		dev->data->dev_conf.rxmode.offloads |=
-						DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-						~DEV_RX_OFFLOAD_JUMBO_FRAME;
 	rte_spinlock_unlock(&hw->lock);
 
 	return 0;
diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c
index ca839fa55fa0..ff28cad53a03 100644
--- a/drivers/net/hns3/hns3_ethdev_vf.c
+++ b/drivers/net/hns3/hns3_ethdev_vf.c
@@ -920,12 +920,6 @@  hns3vf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		rte_spinlock_unlock(&hw->lock);
 		return ret;
 	}
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |=
-						DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-						~DEV_RX_OFFLOAD_JUMBO_FRAME;
 	rte_spinlock_unlock(&hw->lock);
 
 	return 0;
diff --git a/drivers/net/i40e/i40e_ethdev.c b/drivers/net/i40e/i40e_ethdev.c
index 1161f301b9ae..c5058f26dff2 100644
--- a/drivers/net/i40e/i40e_ethdev.c
+++ b/drivers/net/i40e/i40e_ethdev.c
@@ -11772,11 +11772,6 @@  i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev_data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev_data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	return ret;
 }
 
diff --git a/drivers/net/i40e/i40e_ethdev_vf.c b/drivers/net/i40e/i40e_ethdev_vf.c
index 086a167ca672..2015a86ba5ca 100644
--- a/drivers/net/i40e/i40e_ethdev_vf.c
+++ b/drivers/net/i40e/i40e_ethdev_vf.c
@@ -2884,11 +2884,6 @@  i40evf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev_data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev_data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	return ret;
 }
 
diff --git a/drivers/net/iavf/iavf_ethdev.c b/drivers/net/iavf/iavf_ethdev.c
index 13c2329d85a7..ba5be45e8c5e 100644
--- a/drivers/net/iavf/iavf_ethdev.c
+++ b/drivers/net/iavf/iavf_ethdev.c
@@ -1446,13 +1446,6 @@  iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |=
-				DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &=
-				~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	return ret;
 }
 
diff --git a/drivers/net/ice/ice_ethdev.c b/drivers/net/ice/ice_ethdev.c
index bdda6fee3f8e..502e410b5641 100644
--- a/drivers/net/ice/ice_ethdev.c
+++ b/drivers/net/ice/ice_ethdev.c
@@ -3806,11 +3806,6 @@  ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev_data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev_data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	return 0;
 }
 
diff --git a/drivers/net/igc/igc_ethdev.c b/drivers/net/igc/igc_ethdev.c
index b26723064b07..dcbc26b8186e 100644
--- a/drivers/net/igc/igc_ethdev.c
+++ b/drivers/net/igc/igc_ethdev.c
@@ -1592,15 +1592,10 @@  eth_igc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	}
 
 	rctl = IGC_READ_REG(hw, IGC_RCTL);
-
-	/* switch to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU) {
-		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (mtu > RTE_ETHER_MTU)
 		rctl |= IGC_RCTL_LPE;
-	} else {
-		dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	else
 		rctl &= ~IGC_RCTL_LPE;
-	}
 	IGC_WRITE_REG(hw, IGC_RCTL, rctl);
 
 	IGC_WRITE_REG(hw, IGC_RLPML, frame_size);
diff --git a/drivers/net/ipn3ke/ipn3ke_representor.c b/drivers/net/ipn3ke/ipn3ke_representor.c
index 3634c0c8c5f0..e8a33f04bd69 100644
--- a/drivers/net/ipn3ke/ipn3ke_representor.c
+++ b/drivers/net/ipn3ke/ipn3ke_representor.c
@@ -2801,11 +2801,6 @@  ipn3ke_rpst_mtu_set(struct rte_eth_dev *ethdev, uint16_t mtu)
 		return -EBUSY;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		dev_data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev_data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	if (rpst->i40e_pf_eth) {
 		ret = rpst->i40e_pf_eth->dev_ops->mtu_set(rpst->i40e_pf_eth,
 							mtu);
diff --git a/drivers/net/ixgbe/ixgbe_ethdev.c b/drivers/net/ixgbe/ixgbe_ethdev.c
index b9048ade3c35..c4696f34a7a1 100644
--- a/drivers/net/ixgbe/ixgbe_ethdev.c
+++ b/drivers/net/ixgbe/ixgbe_ethdev.c
@@ -5196,13 +5196,10 @@  ixgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 	hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0);
 
 	/* switch to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU) {
-		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
+	if (mtu > RTE_ETHER_MTU)
 		hlreg0 |= IXGBE_HLREG0_JUMBOEN;
-	} else {
-		dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	else
 		hlreg0 &= ~IXGBE_HLREG0_JUMBOEN;
-	}
 	IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0);
 
 	maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
diff --git a/drivers/net/liquidio/lio_ethdev.c b/drivers/net/liquidio/lio_ethdev.c
index f0c165c89ba7..5c40f16bfa24 100644
--- a/drivers/net/liquidio/lio_ethdev.c
+++ b/drivers/net/liquidio/lio_ethdev.c
@@ -480,13 +480,6 @@  lio_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 		return -1;
 	}
 
-	if (mtu > RTE_ETHER_MTU)
-		eth_dev->data->dev_conf.rxmode.offloads |=
-			DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		eth_dev->data->dev_conf.rxmode.offloads &=
-			~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	return 0;
 }
 
diff --git a/drivers/net/nfp/nfp_net.c b/drivers/net/nfp/nfp_net.c
index ff531fdb2354..5cea035e1465 100644
--- a/drivers/net/nfp/nfp_net.c
+++ b/drivers/net/nfp/nfp_net.c
@@ -1550,12 +1550,6 @@  nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
-	/* switch to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	/* writing to configuration space */
 	nn_cfg_writel(hw, NFP_NET_CFG_MTU, mtu);
 
diff --git a/drivers/net/octeontx/octeontx_ethdev.c b/drivers/net/octeontx/octeontx_ethdev.c
index 69c3bda12df8..fb65be2c2dc3 100644
--- a/drivers/net/octeontx/octeontx_ethdev.c
+++ b/drivers/net/octeontx/octeontx_ethdev.c
@@ -552,11 +552,6 @@  octeontx_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 	if (rc)
 		return rc;
 
-	if (mtu > RTE_ETHER_MTU)
-		nic->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		nic->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	octeontx_log_info("Received pkt beyond  maxlen %d will be dropped",
 			  frame_size);
 
diff --git a/drivers/net/octeontx2/otx2_ethdev_ops.c b/drivers/net/octeontx2/otx2_ethdev_ops.c
index ba282762b749..0c97ef7584a0 100644
--- a/drivers/net/octeontx2/otx2_ethdev_ops.c
+++ b/drivers/net/octeontx2/otx2_ethdev_ops.c
@@ -58,11 +58,6 @@  otx2_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 	if (rc)
 		return rc;
 
-	if (mtu > RTE_ETHER_MTU)
-		dev->rx_offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->rx_offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	return rc;
 }
 
diff --git a/drivers/net/qede/qede_ethdev.c b/drivers/net/qede/qede_ethdev.c
index 53b2c0ca10e3..71065f8072ac 100644
--- a/drivers/net/qede/qede_ethdev.c
+++ b/drivers/net/qede/qede_ethdev.c
@@ -2361,10 +2361,6 @@  static int qede_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 			fp->rxq->rx_buf_size = rc;
 		}
 	}
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
 
 	if (!dev->data->dev_started && restart) {
 		qede_dev_start(dev);
diff --git a/drivers/net/sfc/sfc_ethdev.c b/drivers/net/sfc/sfc_ethdev.c
index 2afb13b77892..85209b5befbd 100644
--- a/drivers/net/sfc/sfc_ethdev.c
+++ b/drivers/net/sfc/sfc_ethdev.c
@@ -1014,15 +1014,6 @@  sfc_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 		}
 	}
 
-	/*
-	 * The driver does not use it, but other PMDs update jumbo frame
-	 * flag when MTU is set.
-	 */
-	if (mtu > RTE_ETHER_MTU) {
-		struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
-		rxmode->offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	}
-
 	sfc_adapter_unlock(sa);
 
 	sfc_log_init(sa, "done");
diff --git a/drivers/net/thunderx/nicvf_ethdev.c b/drivers/net/thunderx/nicvf_ethdev.c
index 1d1360faff66..0639889b2144 100644
--- a/drivers/net/thunderx/nicvf_ethdev.c
+++ b/drivers/net/thunderx/nicvf_ethdev.c
@@ -151,7 +151,6 @@  nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 	struct nicvf *nic = nicvf_pmd_priv(dev);
 	uint32_t buffsz, frame_size = mtu + NIC_HW_L2_OVERHEAD;
 	size_t i;
-	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
 
 	PMD_INIT_FUNC_TRACE();
 
@@ -176,11 +175,6 @@  nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 		(frame_size + 2 * VLAN_TAG_SIZE > buffsz * NIC_HW_MAX_SEGS))
 		return -EINVAL;
 
-	if (mtu > RTE_ETHER_MTU)
-		rxmode->offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		rxmode->offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	if (nicvf_mbox_update_hw_max_frs(nic, mtu))
 		return -EINVAL;
 
diff --git a/drivers/net/txgbe/txgbe_ethdev.c b/drivers/net/txgbe/txgbe_ethdev.c
index d773a81665d7..b1a3f9fbb84d 100644
--- a/drivers/net/txgbe/txgbe_ethdev.c
+++ b/drivers/net/txgbe/txgbe_ethdev.c
@@ -3482,12 +3482,6 @@  txgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EINVAL;
 	}
 
-	/* switch to jumbo mode if needed */
-	if (mtu > RTE_ETHER_MTU)
-		dev->data->dev_conf.rxmode.offloads |= DEV_RX_OFFLOAD_JUMBO_FRAME;
-	else
-		dev->data->dev_conf.rxmode.offloads &= ~DEV_RX_OFFLOAD_JUMBO_FRAME;
-
 	if (hw->mode)
 		wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
 			TXGBE_FRAME_SIZE_MAX);
diff --git a/lib/ethdev/rte_ethdev.c b/lib/ethdev/rte_ethdev.c
index 3451125639f9..d649a5dd69a9 100644
--- a/lib/ethdev/rte_ethdev.c
+++ b/lib/ethdev/rte_ethdev.c
@@ -3625,6 +3625,7 @@  rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
 	int ret;
 	struct rte_eth_dev_info dev_info;
 	struct rte_eth_dev *dev;
+	int is_jumbo_frame_capable = 0;
 
 	RTE_ETH_VALID_PORTID_OR_ERR_RET(port_id, -ENODEV);
 	dev = &rte_eth_devices[port_id];
@@ -3643,12 +3644,27 @@  rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
 
 		if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
 			return -EINVAL;
+
+		if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME)
+			is_jumbo_frame_capable = 1;
 	}
 
+	if (mtu > RTE_ETHER_MTU && is_jumbo_frame_capable == 0)
+		return -EINVAL;
+
 	ret = (*dev->dev_ops->mtu_set)(dev, mtu);
-	if (!ret)
+	if (!ret) {
 		dev->data->mtu = mtu;
 
+		/* switch to jumbo mode if needed */
+		if (mtu > RTE_ETHER_MTU)
+			dev->data->dev_conf.rxmode.offloads |=
+				DEV_RX_OFFLOAD_JUMBO_FRAME;
+		else
+			dev->data->dev_conf.rxmode.offloads &=
+				~DEV_RX_OFFLOAD_JUMBO_FRAME;
+	}
+
 	return eth_err(port_id, ret);
 }