[v4] net/nfp: make sure MTU is never larger than mbufsize

Message ID 20220511011553.2905582-1-peng.zhang@corigine.com (mailing list archive)
State Accepted, archived
Delegated to: Andrew Rybchenko
Headers
Series [v4] net/nfp: make sure MTU is never larger than mbufsize |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-testing warning apply patch failure
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS

Commit Message

Nole Zhang May 11, 2022, 1:15 a.m. UTC
  Setting a MTU larger than mbufsize is not supported by the device but
not prohibited by the driver. This change adds a restriction to the
driver to prevent setting an MTU that is too large.

While at it define the minimum MTU in the device information to describe
the complete supported MTU range.

Fixes: d4a27a3 ("nfp: add basic features")
Cc: stable@dpdk.org

Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
Signed-off-by: Louis Peens <louis.peens@corigine.com>
Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
Reviewed-by: Walter Heymans <walter.heymans@corigine.com>
------
Depends-on: patch-109914 ("net/nfp: update how MAX MTU is read")
---
 drivers/net/nfp/nfp_common.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
  

Comments

Andrew Rybchenko May 19, 2022, 7:08 a.m. UTC | #1
On 5/11/22 04:15, Peng Zhang wrote:
> Setting a MTU larger than mbufsize is not supported by the device but
> not prohibited by the driver. This change adds a restriction to the
> driver to prevent setting an MTU that is too large.
> 
> While at it define the minimum MTU in the device information to describe
> the complete supported MTU range.
> 
> Fixes: d4a27a3 ("nfp: add basic features")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Peng Zhang <peng.zhang@corigine.com>
> Signed-off-by: Chaoyong He <chaoyong.he@corigine.com>
> Signed-off-by: Louis Peens <louis.peens@corigine.com>
> Signed-off-by: Niklas Söderlund <niklas.soderlund@corigine.com>
> Reviewed-by: Walter Heymans <walter.heymans@corigine.com>

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

Applied, thanks.
  

Patch

diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index 52fbda1a79..be68c25fb8 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -176,6 +176,13 @@  nfp_net_configure(struct rte_eth_dev *dev)
 		return -EINVAL;
 	}
 
+	/* Checking MTU set */
+	if (rxmode->mtu > hw->flbufsz) {
+		PMD_INIT_LOG(INFO, "MTU (%u) larger then current mbufsize (%u) not supported",
+				    rxmode->mtu, hw->flbufsz);
+		return -ERANGE;
+	}
+
 	return 0;
 }
 
@@ -702,6 +709,7 @@  nfp_net_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	 */
 	dev_info->max_rx_pktlen = NFP_FRAME_SIZE_MAX;
 	dev_info->max_mtu = hw->max_mtu;
+	dev_info->min_mtu = RTE_ETHER_MIN_MTU;
 	/* Next should change when PF support is implemented */
 	dev_info->max_mac_addrs = 1;
 
@@ -961,6 +969,13 @@  nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
+	/* MTU larger then current mbufsize not supported */
+	if (mtu > hw->flbufsz) {
+		PMD_DRV_LOG(ERR, "MTU (%u) larger then current mbufsize (%u) not supported",
+			    mtu, hw->flbufsz);
+		return -ERANGE;
+	}
+
 	/* writing to configuration space */
 	nn_cfg_writel(hw, NFP_NET_CFG_MTU, mtu);