This patch fixed cyclomatic complexity about MTU
in device configure process.

Fixes: 1f5ca0b460cd ("net/hns3: support some device operations")
Cc: sta...@dpdk.org

Signed-off-by: Min Hu (Connor) <humi...@huawei.com>
---
 drivers/net/hns3/hns3_ethdev.c | 61 +++++++++++++++++++++++++-----------------
 1 file changed, 37 insertions(+), 24 deletions(-)

diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c
index 9c71808..bb71808 100644
--- a/drivers/net/hns3/hns3_ethdev.c
+++ b/drivers/net/hns3/hns3_ethdev.c
@@ -2373,6 +2373,40 @@ hns3_init_ring_with_vector(struct hns3_hw *hw)
 }
 
 static int
+hns3_refresh_mtu(struct rte_eth_dev *dev, struct rte_eth_conf *conf)
+{
+       struct hns3_adapter *hns = dev->data->dev_private;
+       struct hns3_hw *hw = &hns->hw;
+       uint32_t max_rx_pkt_len;
+       uint16_t mtu;
+       int ret;
+
+       if (!(conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME))
+               return 0;
+
+       /*
+        * If jumbo frames are enabled, MTU needs to be refreshed
+        * according to the maximum RX packet length.
+        */
+       max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
+       if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
+           max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
+               hns3_err(hw, "maximum Rx packet length must be greater than %u "
+                        "and no more than %u when jumbo frame enabled.",
+                        (uint16_t)HNS3_DEFAULT_FRAME_LEN,
+                        (uint16_t)HNS3_MAX_FRAME_LEN);
+               return -EINVAL;
+       }
+
+       mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
+       ret = hns3_dev_mtu_set(dev, mtu);
+       if (ret)
+               return ret;
+       dev->data->mtu = mtu;
+
+       return 0;
+}
+static int
 hns3_dev_configure(struct rte_eth_dev *dev)
 {
        struct hns3_adapter *hns = dev->data->dev_private;
@@ -2382,8 +2416,6 @@ hns3_dev_configure(struct rte_eth_dev *dev)
        uint16_t nb_rx_q = dev->data->nb_rx_queues;
        uint16_t nb_tx_q = dev->data->nb_tx_queues;
        struct rte_eth_rss_conf rss_conf;
-       uint32_t max_rx_pkt_len;
-       uint16_t mtu;
        bool gro_en;
        int ret;
 
@@ -2431,28 +2463,9 @@ hns3_dev_configure(struct rte_eth_dev *dev)
                        goto cfg_err;
        }
 
-       /*
-        * If jumbo frames are enabled, MTU needs to be refreshed
-        * according to the maximum RX packet length.
-        */
-       if (conf->rxmode.offloads & DEV_RX_OFFLOAD_JUMBO_FRAME) {
-               max_rx_pkt_len = conf->rxmode.max_rx_pkt_len;
-               if (max_rx_pkt_len > HNS3_MAX_FRAME_LEN ||
-                   max_rx_pkt_len <= HNS3_DEFAULT_FRAME_LEN) {
-                       hns3_err(hw, "maximum Rx packet length must be greater "
-                                "than %u and less than %u when jumbo frame 
enabled.",
-                                (uint16_t)HNS3_DEFAULT_FRAME_LEN,
-                                (uint16_t)HNS3_MAX_FRAME_LEN);
-                       ret = -EINVAL;
-                       goto cfg_err;
-               }
-
-               mtu = (uint16_t)HNS3_PKTLEN_TO_MTU(max_rx_pkt_len);
-               ret = hns3_dev_mtu_set(dev, mtu);
-               if (ret)
-                       goto cfg_err;
-               dev->data->mtu = mtu;
-       }
+       ret = hns3_refresh_mtu(dev, conf);
+       if (ret)
+               goto cfg_err;
 
        ret = hns3_dev_configure_vlan(dev);
        if (ret)
-- 
2.7.4

Reply via email to