[v2,5/5] net/idpf: refine MTU setting

Message ID 20230106090501.9106-6-beilei.xing@intel.com (mailing list archive)
State Accepted, archived
Delegated to: Qi Zhang
Headers
Series net/idpf: code refine |

Checks

Context Check Description
ci/checkpatch success coding style OK
ci/loongarch-compilation success Compilation OK
ci/loongarch-unit-testing success Unit Testing PASS
ci/iol-broadcom-Performance success Performance Testing PASS
ci/Intel-compilation success Compilation OK
ci/iol-mellanox-Performance success Performance Testing PASS
ci/iol-intel-Functional success Functional Testing PASS
ci/github-robot: build success github build: passed
ci/iol-intel-Performance success Performance Testing PASS
ci/intel-Testing success Testing PASS
ci/iol-abi-testing success Testing PASS
ci/iol-x86_64-compile-testing success Testing PASS
ci/iol-aarch64-compile-testing success Testing PASS
ci/iol-aarch64-unit-testing success Testing PASS
ci/iol-testing success Testing PASS
ci/iol-x86_64-unit-testing success Testing PASS

Commit Message

Xing, Beilei Jan. 6, 2023, 9:05 a.m. UTC
  From: Jingjing Wu <jingjing.wu@intel.com>

This patch refines MTU configuration.

Signed-off-by: Jingjing Wu <jingjing.wu@intel.com>
Signed-off-by: Beilei Xing <beilei.xing@intel.com>
---
 drivers/net/idpf/idpf_ethdev.c | 37 +++++++++++++++++++---------------
 drivers/net/idpf/idpf_ethdev.h |  1 +
 2 files changed, 22 insertions(+), 16 deletions(-)
  

Patch

diff --git a/drivers/net/idpf/idpf_ethdev.c b/drivers/net/idpf/idpf_ethdev.c
index 89af27ca34..3f1b77144c 100644
--- a/drivers/net/idpf/idpf_ethdev.c
+++ b/drivers/net/idpf/idpf_ethdev.c
@@ -56,9 +56,9 @@  idpf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 	dev_info->max_rx_queues = adapter->caps->max_rx_q;
 	dev_info->max_tx_queues = adapter->caps->max_tx_q;
 	dev_info->min_rx_bufsize = IDPF_MIN_BUF_SIZE;
-	dev_info->max_rx_pktlen = IDPF_MAX_FRAME_SIZE;
+	dev_info->max_rx_pktlen = vport->max_mtu + IDPF_ETH_OVERHEAD;
 
-	dev_info->max_mtu = dev_info->max_rx_pktlen - IDPF_ETH_OVERHEAD;
+	dev_info->max_mtu = vport->max_mtu;
 	dev_info->min_mtu = RTE_ETHER_MIN_MTU;
 
 	dev_info->flow_type_rss_offloads = IDPF_RSS_OFFLOAD_ALL;
@@ -104,14 +104,23 @@  idpf_dev_info_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *dev_info)
 }
 
 static int
-idpf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
+idpf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
+	struct idpf_vport *vport = dev->data->dev_private;
+
 	/* mtu setting is forbidden if port is start */
 	if (dev->data->dev_started) {
 		PMD_DRV_LOG(ERR, "port must be stopped before configuration");
 		return -EBUSY;
 	}
 
+	if (mtu > vport->max_mtu) {
+		PMD_DRV_LOG(ERR, "MTU should be less than %d", vport->max_mtu);
+		return -EINVAL;
+	}
+
+	vport->max_pkt_len = mtu + IDPF_ETH_OVERHEAD;
+
 	return 0;
 }
 
@@ -381,6 +390,10 @@  idpf_dev_configure(struct rte_eth_dev *dev)
 		return -1;
 	}
 
+	vport->max_pkt_len =
+		(dev->data->mtu == 0) ? IDPF_DEFAULT_MTU : dev->data->mtu +
+		IDPF_ETH_OVERHEAD;
+
 	return 0;
 }
 
@@ -513,39 +526,31 @@  idpf_dev_start(struct rte_eth_dev *dev)
 
 	vport->stopped = 0;
 
-	if (dev->data->mtu > vport->max_mtu) {
-		PMD_DRV_LOG(ERR, "MTU should be less than %d", vport->max_mtu);
-		ret = -EINVAL;
-		goto err_mtu;
-	}
-
-	vport->max_pkt_len = dev->data->mtu + IDPF_ETH_OVERHEAD;
-
 	req_vecs_num = IDPF_DFLT_Q_VEC_NUM;
 	if (req_vecs_num + adapter->used_vecs_num > num_allocated_vectors) {
 		PMD_DRV_LOG(ERR, "The accumulated request vectors' number should be less than %d",
 			    num_allocated_vectors);
 		ret = -EINVAL;
-		goto err_mtu;
+		goto err_vec;
 	}
 
 	ret = idpf_vc_alloc_vectors(vport, req_vecs_num);
 	if (ret != 0) {
 		PMD_DRV_LOG(ERR, "Failed to allocate interrupt vectors");
-		goto err_mtu;
+		goto err_vec;
 	}
 	adapter->used_vecs_num += req_vecs_num;
 
 	ret = idpf_config_rx_queues_irqs(dev);
 	if (ret != 0) {
 		PMD_DRV_LOG(ERR, "Failed to configure irqs");
-		goto err_mtu;
+		goto err_vec;
 	}
 
 	ret = idpf_start_queues(dev);
 	if (ret != 0) {
 		PMD_DRV_LOG(ERR, "Failed to start queues");
-		goto err_mtu;
+		goto err_vec;
 	}
 
 	idpf_set_rx_function(dev);
@@ -561,7 +566,7 @@  idpf_dev_start(struct rte_eth_dev *dev)
 
 err_vport:
 	idpf_stop_queues(dev);
-err_mtu:
+err_vec:
 	return ret;
 }
 
diff --git a/drivers/net/idpf/idpf_ethdev.h b/drivers/net/idpf/idpf_ethdev.h
index bf37d5184c..b0746e5041 100644
--- a/drivers/net/idpf/idpf_ethdev.h
+++ b/drivers/net/idpf/idpf_ethdev.h
@@ -39,6 +39,7 @@ 
 #define IDPF_MIN_BUF_SIZE	1024
 #define IDPF_MAX_FRAME_SIZE	9728
 #define IDPF_MIN_FRAME_SIZE	14
+#define IDPF_DEFAULT_MTU	RTE_ETHER_MTU
 
 #define IDPF_NUM_MACADDR_MAX	64