net/nfp: add the restrict of setting the mtu

Message ID 20220317125230.498284-1-peng.zhang@corigine.com (mailing list archive)
State Superseded, archived
Delegated to: Ferruh Yigit
Headers
Series net/nfp: add the restrict of setting the mtu |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS
ci/iol-intel-Performance success Performance Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-broadcom-Functional fail Functional Testing issues
ci/Intel-compilation success Compilation OK
ci/intel-Testing success Testing PASS

Commit Message

Nole Zhang March 17, 2022, 12:52 p.m. UTC
  1.When the setting mtu is higher than flbufsz, the mtu doesn't work.
But it doesn't have any notice about this restrict.
2.when the setting mtu isn't in the range, it doesn't have any notice.

This patch will add the notice about these restrict.

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>
---
 drivers/net/nfp/nfp_common.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
  

Patch

diff --git a/drivers/net/nfp/nfp_common.c b/drivers/net/nfp/nfp_common.c
index f8978e803a..2ea9853548 100644
--- a/drivers/net/nfp/nfp_common.c
+++ b/drivers/net/nfp/nfp_common.c
@@ -956,6 +956,20 @@  nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 		return -EBUSY;
 	}
 
+	/* the setting mtu is in the range */
+	if (mtu < 68 || mtu > hw->max_mtu) {
+		PMD_DRV_LOG(ERR, "the setting mtu cannot be less than 68 or more than %d",
+			    hw->max_mtu);
+		return -ERANGE;
+	}
+
+	/* the setting mtu is lower than flbufsz */
+	if (mtu > hw->flbufsz) {
+		PMD_DRV_LOG(ERR, "the setting mtu must be lower than current mbufsize of %d",
+			    hw->flbufsz);
+		return -ERANGE;
+	}
+
 	/* writing to configuration space */
 	nn_cfg_writel(hw, NFP_NET_CFG_MTU, mtu);