net/txgbe: support MTU set
authorJiawen Wu <jiawenwu@trustnetic.com>
Mon, 19 Oct 2020 08:54:05 +0000 (16:54 +0800)
committerFerruh Yigit <ferruh.yigit@intel.com>
Tue, 3 Nov 2020 22:24:27 +0000 (23:24 +0100)
Add MTU set operation.

Signed-off-by: Jiawen Wu <jiawenwu@trustnetic.com>
Reviewed-by: Ferruh Yigit <ferruh.yigit@intel.com>
doc/guides/nics/features/txgbe.ini
drivers/net/txgbe/base/txgbe_type.h
drivers/net/txgbe/txgbe_ethdev.c

index 34f8985..13ee26a 100644 (file)
@@ -9,6 +9,7 @@ Link status          = Y
 Link status event    = Y
 Rx interrupt         = Y
 Queue start/stop     = Y
+MTU update           = Y
 Jumbo frame          = Y
 Scattered Rx         = Y
 LRO                  = Y
index d851648..ac36cb2 100644 (file)
@@ -673,6 +673,8 @@ struct txgbe_hw {
        void IOMEM *isb_mem;
        u16 nb_rx_queues;
        u16 nb_tx_queues;
+
+       u32 mode;
        enum txgbe_link_status {
                TXGBE_LINK_STATUS_NONE = 0,
                TXGBE_LINK_STATUS_KX,
index f5c8f36..70f0246 100644 (file)
@@ -3026,6 +3026,46 @@ txgbe_set_default_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
        return 0;
 }
 
+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.
+        */
+       if (dev_data->dev_started && !dev_data->scattered_rx &&
+           (frame_size + 2 * TXGBE_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, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
+                       TXGBE_FRAME_SIZE_MAX);
+       else
+               wr32m(hw, TXGBE_FRMSZ, TXGBE_FRMSZ_MAX_MASK,
+                       TXGBE_FRMSZ_MAX(frame_size));
+
+       return 0;
+}
+
 static uint32_t
 txgbe_uta_vector(struct txgbe_hw *hw, struct rte_ether_addr *uc_addr)
 {
@@ -3386,6 +3426,7 @@ static const struct eth_dev_ops txgbe_eth_dev_ops = {
        .xstats_get_names_by_id     = txgbe_dev_xstats_get_names_by_id,
        .queue_stats_mapping_set    = txgbe_dev_queue_stats_mapping_set,
        .dev_supported_ptypes_get   = txgbe_dev_supported_ptypes_get,
+       .mtu_set                    = txgbe_dev_mtu_set,
        .vlan_filter_set            = txgbe_vlan_filter_set,
        .vlan_tpid_set              = txgbe_vlan_tpid_set,
        .vlan_offload_set           = txgbe_vlan_offload_set,