On Tue, 15 Oct 2024 11:09:25 +0800
Howard Wang <howard_w...@realsil.com.cn> wrote:

> +static int
> +rtl_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
> +{
> +     struct rte_eth_dev_info dev_info;
> +     struct rtl_adapter *adapter = RTL_DEV_PRIVATE(dev);
> +     struct rtl_hw *hw = &adapter->hw;
> +     int ret;
> +     uint32_t frame_size = mtu + RTL_ETH_OVERHEAD;
> +
> +     ret = rtl_dev_infos_get(dev, &dev_info);
> +     if (ret != 0)
> +             return ret;
> +
> +     if (mtu < RTE_ETHER_MIN_MTU || frame_size > dev_info.max_rx_pktlen)
> +             return -EINVAL;
> +

This validation is already done in ethdev, not needed here.


int
rte_eth_dev_set_mtu(uint16_t port_id, uint16_t mtu)
{
...

                ret = rte_eth_dev_info_get(port_id, &dev_info);
                if (ret != 0)
                        return ret;

                ret = eth_dev_validate_mtu(port_id, &dev_info, mtu);
                if (ret != 0)
                        return ret;


static int
eth_dev_validate_mtu(uint16_t port_id, struct rte_eth_dev_info *dev_info,
                uint16_t mtu)
{
        uint32_t overhead_len;
        uint32_t frame_size;

        if (mtu < dev_info->min_mtu) {
                RTE_ETHDEV_LOG_LINE(ERR,
                        "MTU (%u) < device min MTU (%u) for port_id %u",
                        mtu, dev_info->min_mtu, port_id);
                return -EINVAL;
        }
        if (mtu > dev_info->max_mtu) {
                RTE_ETHDEV_LOG_LINE(ERR,
                        "MTU (%u) > device max MTU (%u) for port_id %u",
                        mtu, dev_info->max_mtu, port_id);
                return -EINVAL;
        }

Reply via email to