Support updating port MTU.

Signed-off-by: Jiawen Wu <jiawe...@trustnetic.com>
---
 doc/guides/nics/features/ngbe.ini |  1 +
 drivers/net/ngbe/base/ngbe_type.h |  3 +++
 drivers/net/ngbe/ngbe_ethdev.c    | 41 +++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+)

diff --git a/doc/guides/nics/features/ngbe.ini 
b/doc/guides/nics/features/ngbe.ini
index 42101020dd..bdb06916e1 100644
--- a/doc/guides/nics/features/ngbe.ini
+++ b/doc/guides/nics/features/ngbe.ini
@@ -8,6 +8,7 @@ Speed capabilities   = Y
 Link status          = Y
 Link status event    = Y
 Queue start/stop     = Y
+MTU update           = Y
 Jumbo frame          = Y
 Scattered Rx         = Y
 TSO                  = Y
diff --git a/drivers/net/ngbe/base/ngbe_type.h 
b/drivers/net/ngbe/base/ngbe_type.h
index c13f0208fd..78fb0da7fa 100644
--- a/drivers/net/ngbe/base/ngbe_type.h
+++ b/drivers/net/ngbe/base/ngbe_type.h
@@ -8,6 +8,7 @@
 
 #define NGBE_LINK_UP_TIME      90 /* 9.0 Seconds */
 
+#define NGBE_FRAME_SIZE_MAX       (9728) /* Maximum frame size, +FCS */
 #define NGBE_FRAME_SIZE_DFT       (1522) /* Default frame size, +FCS */
 #define NGBE_MAX_QP               (8)
 
@@ -316,6 +317,8 @@ struct ngbe_hw {
        u16 nb_rx_queues;
        u16 nb_tx_queues;
 
+       u32 mode;
+
        u32 q_rx_regs[8 * 4];
        u32 q_tx_regs[8 * 4];
        bool offset_loaded;
diff --git a/drivers/net/ngbe/ngbe_ethdev.c b/drivers/net/ngbe/ngbe_ethdev.c
index 45d7c48011..29f35d9e8d 100644
--- a/drivers/net/ngbe/ngbe_ethdev.c
+++ b/drivers/net/ngbe/ngbe_ethdev.c
@@ -1970,6 +1970,46 @@ ngbe_dev_interrupt_handler(void *param)
        ngbe_dev_interrupt_action(dev);
 }
 
+static int
+ngbe_dev_mtu_set(struct rte_eth_dev *dev, uint16_t mtu)
+{
+       struct ngbe_hw *hw = ngbe_dev_hw(dev);
+       struct rte_eth_dev_info dev_info;
+       uint32_t frame_size = mtu + RTE_ETHER_HDR_LEN + RTE_ETHER_CRC_LEN + 4;
+       struct rte_eth_dev_data *dev_data = dev->data;
+       int ret;
+
+       ret = ngbe_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.
+        */
+       if (dev_data->dev_started && !dev_data->scattered_rx &&
+           (frame_size + 2 * NGBE_VLAN_TAG_SIZE >
+            dev->data->min_rx_buf_size - RTE_PKTMBUF_HEADROOM)) {
+               PMD_INIT_LOG(ERR, "Stop port first.");
+               return -EINVAL;
+       }
+
+       /* update max frame size */
+       dev->data->dev_conf.rxmode.max_rx_pkt_len = frame_size;
+
+       if (hw->mode)
+               wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
+                       NGBE_FRAME_SIZE_MAX);
+       else
+               wr32m(hw, NGBE_FRMSZ, NGBE_FRMSZ_MAX_MASK,
+                       NGBE_FRMSZ_MAX(frame_size));
+
+       return 0;
+}
+
 /**
  * Set the IVAR registers, mapping interrupt causes to vectors
  * @param hw
@@ -2078,6 +2118,7 @@ static const struct eth_dev_ops ngbe_eth_dev_ops = {
        .xstats_get_names           = ngbe_dev_xstats_get_names,
        .xstats_get_names_by_id     = ngbe_dev_xstats_get_names_by_id,
        .queue_stats_mapping_set    = ngbe_dev_queue_stats_mapping_set,
+       .mtu_set                    = ngbe_dev_mtu_set,
        .vlan_offload_set           = ngbe_vlan_offload_set,
        .rx_queue_start             = ngbe_dev_rx_queue_start,
        .rx_queue_stop              = ngbe_dev_rx_queue_stop,
-- 
2.21.0.windows.1



Reply via email to