net/ixgbe: check jumbo frame enable parameter

Message ID 1541058926-3576-1-git-send-email-wei.zhao1@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Qi Zhang
Headers
Series net/ixgbe: check jumbo frame enable parameter |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/Intel-compilation fail Compilation issues

Commit Message

Zhao1, Wei Nov. 1, 2018, 7:55 a.m. UTC
  There is necessary to do some check of max packet size boundary
for code safe when enable jumbo frame.

Signed-off-by: Wei Zhao <wei.zhao1@intel.com>
---
 drivers/net/ixgbe/ixgbe_rxtx.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)
  

Comments

Stephen Hemminger Nov. 1, 2018, 5:46 p.m. UTC | #1
On Thu,  1 Nov 2018 15:55:26 +0800
wei zhao <wei.zhao1@intel.com> wrote:

> +	/* check that max packet size is within the allowed range */
> +	if (max_rx_pkt_len < ETHER_MIN_MTU) {
> +		PMD_INIT_LOG(ERR, "max packet size is too small.");
> +		return -EINVAL;
> +	}
> +
> +	if (max_rx_pkt_len > dev_info.max_rx_pktlen) {
> +		PMD_INIT_LOG(ERR, "max packet size is too big.");
> +		return -EINVAL;
> +	}
> +
> +	/* check jumbo mode if needed */
> +	if (max_rx_pkt_len < ETHER_MAX_LEN) {
> +		PMD_INIT_LOG(ERR, "No need to enable jumbo.");
> +		return -EINVAL;
> +	}
> +

Yes, these checks are needed and for other devices as well.
Why not add them into rte_ethdev instead?
  
Zhao1, Wei Nov. 5, 2018, 9:13 a.m. UTC | #2
> -----Original Message-----
> From: Stephen Hemminger [mailto:stephen@networkplumber.org]
> Sent: Friday, November 2, 2018 1:46 AM
> To: Zhao1, Wei <wei.zhao1@intel.com>
> Cc: dev@dpdk.org; stable@dpdk.org; Zhang, Qi Z <qi.z.zhang@intel.com>
> Subject: Re: [dpdk-dev] [PATCH] net/ixgbe: check jumbo frame enable
> parameter
> 
> On Thu,  1 Nov 2018 15:55:26 +0800
> wei zhao <wei.zhao1@intel.com> wrote:
> 
> > +	/* check that max packet size is within the allowed range */
> > +	if (max_rx_pkt_len < ETHER_MIN_MTU) {
> > +		PMD_INIT_LOG(ERR, "max packet size is too small.");
> > +		return -EINVAL;
> > +	}
> > +
> > +	if (max_rx_pkt_len > dev_info.max_rx_pktlen) {
> > +		PMD_INIT_LOG(ERR, "max packet size is too big.");
> > +		return -EINVAL;
> > +	}
> > +
> > +	/* check jumbo mode if needed */
> > +	if (max_rx_pkt_len < ETHER_MAX_LEN) {
> > +		PMD_INIT_LOG(ERR, "No need to enable jumbo.");
> > +		return -EINVAL;
> > +	}
> > +
> 
> Yes, these checks are needed and for other devices as well.
> Why not add them into rte_ethdev instead?

I am not familiar with NIC except ixgbe and i40e, I am not sure property of other NIC and rationality of these check....
  

Patch

diff --git a/drivers/net/ixgbe/ixgbe_rxtx.c b/drivers/net/ixgbe/ixgbe_rxtx.c
index 2f0262a..d304dee 100644
--- a/drivers/net/ixgbe/ixgbe_rxtx.c
+++ b/drivers/net/ixgbe/ixgbe_rxtx.c
@@ -4814,6 +4814,34 @@  void __attribute__((cold))
 	return 0;
 }
 
+int __attribute__((cold))
+ixgbe_dev_jumboenable_check(struct rte_eth_dev *dev,
+				uint16_t max_rx_pkt_len)
+{
+	struct rte_eth_dev_info dev_info;
+
+	ixgbe_dev_info_get(dev, &dev_info);
+
+	/* check that max packet size is within the allowed range */
+	if (max_rx_pkt_len < ETHER_MIN_MTU) {
+		PMD_INIT_LOG(ERR, "max packet size is too small.");
+		return -EINVAL;
+	}
+
+	if (max_rx_pkt_len > dev_info.max_rx_pktlen) {
+		PMD_INIT_LOG(ERR, "max packet size is too big.");
+		return -EINVAL;
+	}
+
+	/* check jumbo mode if needed */
+	if (max_rx_pkt_len < ETHER_MAX_LEN) {
+		PMD_INIT_LOG(ERR, "No need to enable jumbo.");
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 /*
  * Initializes Receive Unit.
  */
@@ -4865,6 +4893,9 @@  int __attribute__((cold))
 	 * Configure jumbo frame support, if any.
 	 */
 	if (rx_conf->offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
+		if (ixgbe_dev_jumboenable_check(dev, rx_conf->max_rx_pkt_len))
+			return -EINVAL;
+
 		hlreg0 |= IXGBE_HLREG0_JUMBOEN;
 		maxfrs = IXGBE_READ_REG(hw, IXGBE_MAXFRS);
 		maxfrs &= 0x0000FFFF;