]> git.droids-corp.org - dpdk.git/commitdiff
ethdev: move MTU set check to library
authorFerruh Yigit <ferruh.yigit@intel.com>
Mon, 18 Oct 2021 13:48:50 +0000 (14:48 +0100)
committerFerruh Yigit <ferruh.yigit@intel.com>
Mon, 18 Oct 2021 17:20:21 +0000 (19:20 +0200)
Move requested MTU value check to the API to prevent the duplicated
code.

Signed-off-by: Ferruh Yigit <ferruh.yigit@intel.com>
Reviewed-by: Andrew Rybchenko <andrew.rybchenko@oktetlabs.ru>
Reviewed-by: Rosen Xu <rosen.xu@intel.com>
Acked-by: Somnath Kotur <somnath.kotur@broadcom.com>
Acked-by: Konstantin Ananyev <konstantin.ananyev@intel.com>
22 files changed:
drivers/net/axgbe/axgbe_ethdev.c
drivers/net/bnxt/bnxt_ethdev.c
drivers/net/cxgbe/cxgbe_ethdev.c
drivers/net/dpaa/dpaa_ethdev.c
drivers/net/dpaa2/dpaa2_ethdev.c
drivers/net/e1000/em_ethdev.c
drivers/net/e1000/igb_ethdev.c
drivers/net/enetc/enetc_ethdev.c
drivers/net/hinic/hinic_pmd_ethdev.c
drivers/net/i40e/i40e_ethdev.c
drivers/net/iavf/iavf_ethdev.c
drivers/net/ice/ice_ethdev.c
drivers/net/igc/igc_ethdev.c
drivers/net/ipn3ke/ipn3ke_representor.c
drivers/net/liquidio/lio_ethdev.c
drivers/net/nfp/nfp_common.c
drivers/net/octeontx/octeontx_ethdev.c
drivers/net/octeontx2/otx2_ethdev_ops.c
drivers/net/qede/qede_ethdev.c
drivers/net/thunderx/nicvf_ethdev.c
drivers/net/txgbe/txgbe_ethdev.c
lib/ethdev/rte_ethdev.c

index 2dc5fa245bd85bcd510f0baee18aa087afc5bc5c..d302329525d0fe56557d5a5878f05f59a27135df 100644 (file)
@@ -1478,25 +1478,18 @@ axgbe_dev_supported_ptypes_get(struct rte_eth_dev *dev)
 
 static int axgb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
-       struct rte_eth_dev_info dev_info;
        struct axgbe_port *pdata = dev->data->dev_private;
-       uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
-       unsigned int val = 0;
-       axgbe_dev_info_get(dev, &dev_info);
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
-               return -EINVAL;
+       unsigned int val;
+
        /* mtu setting is forbidden if port is start */
        if (dev->data->dev_started) {
                PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
                                dev->data->port_id);
                return -EBUSY;
        }
-       if (mtu > RTE_ETHER_MTU)
-               val = 1;
-       else
-               val = 0;
+       val = mtu > RTE_ETHER_MTU ? 1 : 0;
        AXGMAC_IOWRITE_BITS(pdata, MAC_RCR, JE, val);
+
        return 0;
 }
 
index 6a66ed824a4787935bf5eea7e05ca0fd6c839e1b..f3cd756447cfe273c56374fab7b18415ddba1f3e 100644 (file)
@@ -3029,7 +3029,7 @@ int bnxt_mtu_set_op(struct rte_eth_dev *eth_dev, uint16_t new_mtu)
        uint32_t overhead = BNXT_MAX_PKT_LEN - BNXT_MAX_MTU;
        struct bnxt *bp = eth_dev->data->dev_private;
        uint32_t new_pkt_size;
-       uint32_t rc = 0;
+       uint32_t rc;
        uint32_t i;
 
        rc = is_bnxt_in_error(bp);
index cdecf6b512ef0d4cc0df5f816c3daa4cd907fe3a..32a01009107dfed9d923d96ae864c76635b6a596 100644 (file)
@@ -301,21 +301,10 @@ int cxgbe_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 {
        struct port_info *pi = eth_dev->data->dev_private;
        struct adapter *adapter = pi->adapter;
-       struct rte_eth_dev_info dev_info;
-       int err;
        uint16_t new_mtu = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
 
-       err = cxgbe_dev_info_get(eth_dev, &dev_info);
-       if (err != 0)
-               return err;
-
-       /* Must accommodate at least RTE_ETHER_MIN_MTU */
-       if (mtu < RTE_ETHER_MIN_MTU || new_mtu > dev_info.max_rx_pktlen)
-               return -EINVAL;
-
-       err = t4_set_rxmode(adapter, adapter->mbox, pi->viid, new_mtu, -1, -1,
+       return t4_set_rxmode(adapter, adapter->mbox, pi->viid, new_mtu, -1, -1,
                            -1, -1, true);
-       return err;
 }
 
 /*
index f24ec55bee8bdd2c1c286db28f2c42d9278f15f4..c117115066b0ee3f398dc138233b31328d744398 100644 (file)
@@ -167,8 +167,6 @@ dpaa_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
        PMD_INIT_FUNC_TRACE();
 
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA_MAX_RX_PKT_LEN)
-               return -EINVAL;
        /*
         * Refuse mtu that requires the support of scattered packets
         * when this feature has not been enabled before.
index 02e1647d1f42816d94c5c0c2c6fb3a81cc9d9b77..3d1df34aa85223b3a43ed1bf3a6c44e04e3728c7 100644 (file)
@@ -1461,10 +1461,6 @@ dpaa2_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
                return -EINVAL;
        }
 
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > DPAA2_MAX_RX_PKT_LEN)
-               return -EINVAL;
-
        /* Set the Max Rx frame length as 'mtu' +
         * Maximum Ethernet header length
         */
index de4267bf599584a1c603c608f53f2cf5a9f59c02..e8d55ddf3349bb86e9a6ed62687601b333717efc 100644 (file)
@@ -1786,22 +1786,12 @@ eth_em_default_mac_addr_set(struct rte_eth_dev *dev,
 static int
 eth_em_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
-       struct rte_eth_dev_info dev_info;
        struct e1000_hw *hw;
        uint32_t frame_size;
        uint32_t rctl;
-       int ret;
-
-       ret = eth_em_infos_get(dev, &dev_info);
-       if (ret != 0)
-               return ret;
 
        frame_size = mtu + E1000_ETH_OVERHEAD;
 
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
-               return -EINVAL;
-
        /*
         * If device is started, refuse mtu that requires the support of
         * scattered packets when this feature has not been enabled before.
index 72bdd1087cdf32a62ca68e993ef31eec10483993..dbe811a1ad2f1113978724786ac63bae3a563257 100644 (file)
@@ -4359,9 +4359,7 @@ eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
        uint32_t rctl;
        struct e1000_hw *hw;
-       struct rte_eth_dev_info dev_info;
        uint32_t frame_size = mtu + E1000_ETH_OVERHEAD;
-       int ret;
 
        hw = E1000_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
@@ -4370,15 +4368,6 @@ eth_igb_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        if (hw->mac.type == e1000_82571)
                return -ENOTSUP;
 #endif
-       ret = eth_igb_infos_get(dev, &dev_info);
-       if (ret != 0)
-               return ret;
-
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU ||
-                       frame_size > dev_info.max_rx_pktlen)
-               return -EINVAL;
-
        /*
         * If device is started, refuse mtu that requires the support of
         * scattered packets when this feature has not been enabled before.
index 52c89aa038400fcd8764106cdc22b8ecb47b9362..ca83fbd0a3d8407179166c3e980dba769733eb57 100644 (file)
@@ -666,10 +666,6 @@ enetc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        struct enetc_hw *enetc_hw = &hw->hw;
        uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
 
-       /* check that mtu is within the allowed range */
-       if (mtu < ENETC_MAC_MINFRM_SIZE || frame_size > ENETC_MAC_MAXFRM_SIZE)
-               return -EINVAL;
-
        /*
         * Refuse mtu that requires the support of scattered packets
         * when this feature has not been enabled before.
index 5d6700c183035ef2e1c4f0846ac60e5420d64fb2..9a974dff580e1433e35ec2f9a491bcb5236e23c2 100644 (file)
@@ -1534,17 +1534,11 @@ static void hinic_deinit_mac_addr(struct rte_eth_dev *eth_dev)
 static int hinic_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 {
        struct hinic_nic_dev *nic_dev = HINIC_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
-       int ret = 0;
+       int ret;
 
        PMD_DRV_LOG(INFO, "Set port mtu, port_id: %d, mtu: %d, max_pkt_len: %d",
                        dev->data->port_id, mtu, HINIC_MTU_TO_PKTLEN(mtu));
 
-       if (mtu < HINIC_MIN_MTU_SIZE || mtu > HINIC_MAX_MTU_SIZE) {
-               PMD_DRV_LOG(ERR, "Invalid mtu: %d, must between %d and %d",
-                               mtu, HINIC_MIN_MTU_SIZE, HINIC_MAX_MTU_SIZE);
-               return -EINVAL;
-       }
-
        ret = hinic_set_port_mtu(nic_dev->hwdev, mtu);
        if (ret) {
                PMD_DRV_LOG(ERR, "Set port mtu failed, ret: %d", ret);
index 208e60ed8c62056900b4a2487a095512055eca1d..cf3f20e79f1a731fdac447badcb260b01252d4f1 100644 (file)
@@ -11419,25 +11419,16 @@ static int i40e_set_default_mac_addr(struct rte_eth_dev *dev,
 }
 
 static int
-i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+i40e_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
 {
-       struct i40e_pf *pf = I40E_DEV_PRIVATE_TO_PF(dev->data->dev_private);
-       struct rte_eth_dev_data *dev_data = pf->dev_data;
-       uint32_t frame_size = mtu + I40E_ETH_OVERHEAD;
-       int ret = 0;
-
-       /* check if mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > I40E_FRAME_SIZE_MAX)
-               return -EINVAL;
-
        /* mtu setting is forbidden if port is start */
-       if (dev_data->dev_started) {
+       if (dev->data->dev_started != 0) {
                PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
-                           dev_data->port_id);
+                           dev->data->port_id);
                return -EBUSY;
        }
 
-       return ret;
+       return 0;
 }
 
 /* Restore ethertype filter */
index 1df4cf17ab9220944d599e6130da708e860fbdc3..654337187842cae8b3046f35521adf9ab1e6eb4f 100644 (file)
@@ -1459,21 +1459,15 @@ iavf_dev_rss_hash_conf_get(struct rte_eth_dev *dev,
 }
 
 static int
-iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+iavf_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
 {
-       uint32_t frame_size = mtu + IAVF_ETH_OVERHEAD;
-       int ret = 0;
-
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > IAVF_FRAME_SIZE_MAX)
-               return -EINVAL;
-
        /* 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;
        }
 
-       return ret;
+       return 0;
 }
 
 static int
index 4929fc7d3a1c531e0e7a19b587c49fab4fec44ae..3a1bcc4e3eb7abc6ac5e59295a61d6651463bfd3 100644 (file)
@@ -3974,21 +3974,13 @@ ice_dev_set_link_down(struct rte_eth_dev *dev)
 }
 
 static int
-ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+ice_mtu_set(struct rte_eth_dev *dev, uint16_t mtu __rte_unused)
 {
-       struct ice_pf *pf = ICE_DEV_PRIVATE_TO_PF(dev->data->dev_private);
-       struct rte_eth_dev_data *dev_data = pf->dev_data;
-       uint32_t frame_size = mtu + ICE_ETH_OVERHEAD;
-
-       /* check if mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > ICE_FRAME_SIZE_MAX)
-               return -EINVAL;
-
        /* mtu setting is forbidden if port is start */
-       if (dev_data->dev_started) {
+       if (dev->data->dev_started != 0) {
                PMD_DRV_LOG(ERR,
                            "port %d must be stopped before configuration",
-                           dev_data->port_id);
+                           dev->data->port_id);
                return -EBUSY;
        }
 
index c36f0c879ef9a88171fbffbdd7a49e4e906e4a61..2a1ed90b641be289667935f043e6bbff4ba37a79 100644 (file)
@@ -1575,11 +1575,6 @@ eth_igc_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
        if (IGC_READ_REG(hw, IGC_CTRL_EXT) & IGC_CTRL_EXT_EXT_VLAN)
                frame_size += VLAN_TAG_SIZE;
 
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU ||
-               frame_size > MAX_RX_JUMBO_FRAME_SIZE)
-               return -EINVAL;
-
        /*
         * If device is started, refuse mtu that requires the support of
         * scattered packets when this feature has not been enabled before.
index 6bf139c85dea7479990868c2238bd3172facd66b..0438c3f08c24410cfa18802608b4b4ee2d630ecb 100644 (file)
@@ -2768,12 +2768,6 @@ ipn3ke_rpst_mtu_set(struct rte_eth_dev *ethdev, uint16_t mtu)
        int ret = 0;
        struct ipn3ke_rpst *rpst = IPN3KE_DEV_PRIVATE_TO_RPST(ethdev);
        struct rte_eth_dev_data *dev_data = ethdev->data;
-       uint32_t frame_size = mtu  + IPN3KE_ETH_OVERHEAD;
-
-       /* check if mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU ||
-               frame_size > IPN3KE_MAC_FRAME_SIZE_MAX)
-               return -EINVAL;
 
        /* mtu setting is forbidden if port is start */
        /* make sure NIC port is stopped */
index 5e3b2aa7a3168aeb7e94d675d8f236771e1afda6..0fc3f0ab66a9808f5496ae05429f0ed79658e839 100644 (file)
@@ -434,7 +434,6 @@ static int
 lio_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
 {
        struct lio_device *lio_dev = LIO_DEV(eth_dev);
-       uint16_t pf_mtu = lio_dev->linfo.link.s.mtu;
        struct lio_dev_ctrl_cmd ctrl_cmd;
        struct lio_ctrl_pkt ctrl_pkt;
 
@@ -446,15 +445,6 @@ lio_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
                return -EINVAL;
        }
 
-       /* check if VF MTU is within allowed range.
-        * New value should not exceed PF MTU.
-        */
-       if (mtu < RTE_ETHER_MIN_MTU || mtu > pf_mtu) {
-               lio_dev_err(lio_dev, "VF MTU should be >= %d and <= %d\n",
-                           RTE_ETHER_MIN_MTU, pf_mtu);
-               return -EINVAL;
-       }
-
        /* flush added to prevent cmd failure
         * incase the queue is full
         */
index d7bd5883b107ca4001e1ecfbc6aa12718ca52737..dc906872192fa06b30e8a3674ca68c393e056e02 100644 (file)
@@ -951,10 +951,6 @@ nfp_net_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 
        hw = NFP_NET_DEV_PRIVATE_TO_HW(dev->data->dev_private);
 
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || (uint32_t)mtu > hw->max_mtu)
-               return -EINVAL;
-
        /* mtu setting is forbidden if port is started */
        if (dev->data->dev_started) {
                PMD_DRV_LOG(ERR, "port %d must be stopped before configuration",
index c5dbcc45d86b0a431e38d0c013fb4ac47d1056bd..f578123ed00b2d91f39f10ebc5c1258d20a8545e 100644 (file)
@@ -524,10 +524,6 @@ octeontx_dev_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
        struct rte_eth_dev_data *data = eth_dev->data;
        int rc = 0;
 
-       /* Check if MTU is within the allowed range */
-       if (frame_size < OCCTX_MIN_FRS || frame_size > OCCTX_MAX_FRS)
-               return -EINVAL;
-
        buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
 
        /* Refuse MTU that requires the support of scattered packets
index fa6d4030b827ce4afd6e5d88515653f1aac84684..22a8af5cba45dd954d395dca48653139f8337320 100644 (file)
@@ -20,10 +20,6 @@ otx2_nix_mtu_set(struct rte_eth_dev *eth_dev, uint16_t mtu)
        if (dev->configured && otx2_ethdev_is_ptp_en(dev))
                frame_size += NIX_TIMESYNC_RX_OFFSET;
 
-       /* Check if MTU is within the allowed range */
-       if (frame_size < NIX_MIN_FRS || frame_size > NIX_MAX_FRS)
-               return -EINVAL;
-
        buffsz = data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
 
        /* Refuse MTU that requires the support of scattered packets
index 7b12794405a16a772eb9813e5f1026ba8cd4cf96..663cb1460f4ffffeab32fe338dd6e16f4c529373 100644 (file)
@@ -2307,7 +2307,6 @@ static int qede_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 {
        struct qede_dev *qdev = QEDE_INIT_QDEV(dev);
        struct ecore_dev *edev = QEDE_INIT_EDEV(qdev);
-       struct rte_eth_dev_info dev_info = {0};
        struct qede_fastpath *fp;
        uint32_t frame_size;
        uint16_t bufsz;
@@ -2315,19 +2314,8 @@ static int qede_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
        int i, rc;
 
        PMD_INIT_FUNC_TRACE(edev);
-       rc = qede_dev_info_get(dev, &dev_info);
-       if (rc != 0) {
-               DP_ERR(edev, "Error during getting ethernet device info\n");
-               return rc;
-       }
 
        frame_size = mtu + QEDE_MAX_ETHER_HDR_LEN;
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen) {
-               DP_ERR(edev, "MTU %u out of range, %u is maximum allowable\n",
-                      mtu, dev_info.max_rx_pktlen - RTE_ETHER_HDR_LEN -
-                      QEDE_ETH_OVERHEAD);
-               return -EINVAL;
-       }
        if (!dev->data->scattered_rx &&
            frame_size > dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM) {
                DP_INFO(edev, "MTU greater than minimum RX buffer size of %u\n",
index 0624efcbb8663be9d208045a3037de6b9fc0704b..8ce9a99dc074cb243cf1c6a24c8af780e7c75b99 100644 (file)
@@ -154,12 +154,6 @@ nicvf_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
 
        PMD_INIT_FUNC_TRACE();
 
-       if (frame_size > NIC_HW_MAX_FRS)
-               return -EINVAL;
-
-       if (frame_size < NIC_HW_MIN_FRS)
-               return -EINVAL;
-
        buffsz = dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM;
 
        /*
index cc1d4a623818133a81e69624d9f035f894e6a163..7b46ffb68635014f7a2ab10f7ffc4679f1e68b64 100644 (file)
@@ -3459,18 +3459,8 @@ static int
 txgbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
 {
        struct txgbe_hw *hw = TXGBE_DEV_HW(dev);
-       struct rte_eth_dev_info dev_info;
        uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN;
        struct rte_eth_dev_data *dev_data = dev->data;
-       int ret;
-
-       ret = txgbe_dev_info_get(dev, &dev_info);
-       if (ret != 0)
-               return ret;
-
-       /* check that mtu is within the allowed range */
-       if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
-               return -EINVAL;
 
        /* If device is started, refuse mtu that requires the support of
         * scattered packets when this feature has not been enabled before.
index 850208b640dda931bf8edf6d0042929e36708a76..4e32b6d964f628ec41b48ac40a55edccd573955d 100644 (file)
@@ -3660,6 +3660,9 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
         * which relies on dev->dev_ops->dev_infos_get.
         */
        if (*dev->dev_ops->dev_infos_get != NULL) {
+               uint16_t overhead_len;
+               uint32_t frame_size;
+
                ret = rte_eth_dev_info_get(port_id, &dev_info);
                if (ret != 0)
                        return ret;
@@ -3667,6 +3670,12 @@ rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
                if (mtu < dev_info.min_mtu || mtu > dev_info.max_mtu)
                        return -EINVAL;
 
+               overhead_len = eth_dev_get_overhead_len(dev_info.max_rx_pktlen,
+                               dev_info.max_mtu);
+               frame_size = mtu + overhead_len;
+               if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
+                       return -EINVAL;
+
                if ((dev_info.rx_offload_capa & DEV_RX_OFFLOAD_JUMBO_FRAME) != 0)
                        is_jumbo_frame_capable = 1;
        }