Skip to content

Commit

Permalink
net/hns3: fix MTU config complexity
Browse files Browse the repository at this point in the history
[ upstream commit d81d78e ]

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

Fixes: 1f5ca0b ("net/hns3: support some device operations")

Signed-off-by: Min Hu (Connor) <humin29@huawei.com>
  • Loading branch information
hushenggitcount authored and steevenlee committed May 8, 2021
1 parent 1324bea commit fdd1a58
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions drivers/net/hns3/hns3_ethdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -2302,6 +2302,41 @@ hns3_init_ring_with_vector(struct hns3_hw *hw)
return 0;
}

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)
{
Expand All @@ -2313,8 +2348,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;

Expand Down Expand Up @@ -2367,28 +2400,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)
Expand Down

0 comments on commit fdd1a58

Please sign in to comment.