mtu update ops implementations.

Signed-off-by: Junlong Wang <wang.junlo...@zte.com.cn>
---
 doc/guides/nics/features/zxdh.ini  |  3 +-
 doc/guides/nics/zxdh.rst           |  2 +
 drivers/net/zxdh/zxdh_ethdev.c     |  1 +
 drivers/net/zxdh/zxdh_ethdev_ops.c | 79 ++++++++++++++++++++++++++++++
 drivers/net/zxdh/zxdh_ethdev_ops.h |  1 +
 drivers/net/zxdh/zxdh_tables.c     | 42 ++++++++++++++++
 drivers/net/zxdh/zxdh_tables.h     |  4 ++
 7 files changed, 131 insertions(+), 1 deletion(-)

diff --git a/doc/guides/nics/features/zxdh.ini 
b/doc/guides/nics/features/zxdh.ini
index 39c2473652..b9bdb73ddf 100644
--- a/doc/guides/nics/features/zxdh.ini
+++ b/doc/guides/nics/features/zxdh.ini
@@ -22,4 +22,5 @@ RSS hash             = Y
 RSS reta update      = Y
 Inner RSS            = Y
 Basic stats          = Y
-Stats per queue      = Y
\ No newline at end of file
+Stats per queue      = Y
+MTU update           = Y
\ No newline at end of file
diff --git a/doc/guides/nics/zxdh.rst b/doc/guides/nics/zxdh.rst
index c8a52b587c..58e0c49a2e 100644
--- a/doc/guides/nics/zxdh.rst
+++ b/doc/guides/nics/zxdh.rst
@@ -33,6 +33,8 @@ Features of the ZXDH PMD are:
 - QINQ stripping and inserting
 - Receive Side Scaling (RSS)
 - Port hardware statistics
+- MTU update
+- Jumbo frames
 
 
 Driver compilation and testing
diff --git a/drivers/net/zxdh/zxdh_ethdev.c b/drivers/net/zxdh/zxdh_ethdev.c
index 82f81d1ded..8f39f41c4e 100644
--- a/drivers/net/zxdh/zxdh_ethdev.c
+++ b/drivers/net/zxdh/zxdh_ethdev.c
@@ -1143,6 +1143,7 @@ static const struct eth_dev_ops zxdh_eth_dev_ops = {
        .rss_hash_conf_get               = zxdh_rss_hash_conf_get,
        .stats_get                               = zxdh_dev_stats_get,
        .stats_reset                     = zxdh_dev_stats_reset,
+       .mtu_set                                 = zxdh_dev_mtu_set,
 };
 
 static int32_t
diff --git a/drivers/net/zxdh/zxdh_ethdev_ops.c 
b/drivers/net/zxdh/zxdh_ethdev_ops.c
index 6156c94f2c..cca16001f7 100644
--- a/drivers/net/zxdh/zxdh_ethdev_ops.c
+++ b/drivers/net/zxdh/zxdh_ethdev_ops.c
@@ -12,6 +12,7 @@
 #include "zxdh_logs.h"
 #include "zxdh_rxtx.h"
 #include "zxdh_np.h"
+#include "zxdh_queue.h"
 
 #define ZXDH_VLAN_FILTER_GROUPS       64
 #define ZXDH_INVALID_LOGIC_QID        0xFFFFU
@@ -37,6 +38,7 @@
 #define ZXDH_HF_F3           2
 #define ZXDH_HF_MAC_VLAN     4
 #define ZXDH_HF_ALL          0
+#define ZXDH_ETHER_MIN_MTU     68
 
 struct zxdh_hw_mac_stats {
        uint64_t rx_total;
@@ -1419,3 +1421,80 @@ int zxdh_dev_stats_reset(struct rte_eth_dev *dev)
 
        return 0;
 }
+
+int zxdh_dev_mtu_set(struct rte_eth_dev *dev, uint16_t new_mtu)
+{
+       struct zxdh_hw *hw = dev->data->dev_private;
+       struct zxdh_panel_table panel = {0};
+       struct zxdh_port_attr_table vport_att = {0};
+       uint16_t vfid = zxdh_vport_to_vfid(hw->vport);
+       uint16_t max_mtu = 0;
+       int ret = 0;
+
+       max_mtu = ZXDH_MAX_RX_PKTLEN - RTE_ETHER_HDR_LEN - RTE_VLAN_HLEN - 
ZXDH_DL_NET_HDR_SIZE;
+       if (new_mtu < ZXDH_ETHER_MIN_MTU || new_mtu > max_mtu) {
+               PMD_DRV_LOG(ERR, "invalid mtu:%d, range[%d, %d]",
+                               new_mtu, ZXDH_ETHER_MIN_MTU, max_mtu);
+               return -EINVAL;
+       }
+
+       if (dev->data->mtu == new_mtu)
+               return 0;
+
+       if (hw->is_pf) {
+               memset(&panel, 0, sizeof(panel));
+               memset(&vport_att, 0, sizeof(vport_att));
+               ret = zxdh_get_panel_attr(dev, &panel);
+               if (ret != 0) {
+                       PMD_DRV_LOG(ERR, "get_panel_attr ret:%d", ret);
+                       return -1;
+               }
+
+               ret = zxdh_get_port_attr(vfid, &vport_att);
+               if (ret != 0) {
+                       PMD_DRV_LOG(ERR,
+                               "[vfid:%d] zxdh_dev_mtu, get vport dpp_ret:%d", 
vfid, ret);
+                       return -1;
+               }
+
+               panel.mtu = new_mtu;
+               panel.mtu_enable = 1;
+               ret = zxdh_set_panel_attr(dev, &panel);
+               if (ret != 0) {
+                       PMD_DRV_LOG(ERR, "set zxdh_dev_mtu failed, ret:%u", 
ret);
+                       return ret;
+               }
+
+               vport_att.mtu_enable = 1;
+               vport_att.mtu = new_mtu;
+               ret = zxdh_set_port_attr(vfid, &vport_att);
+               if (ret != 0) {
+                       PMD_DRV_LOG(ERR,
+                               "[vfid:%d] zxdh_dev_mtu, set vport dpp_ret:%d", 
vfid, ret);
+                       return ret;
+               }
+       } else {
+               struct zxdh_msg_info msg_info = {0};
+               struct zxdh_port_attr_set_msg *attr_msg = 
&msg_info.data.port_attr_msg;
+
+               zxdh_msg_head_build(hw, ZXDH_PORT_ATTRS_SET, &msg_info);
+               attr_msg->mode = ZXDH_PORT_MTU_EN_FLAG;
+               attr_msg->value = 1;
+               ret = zxdh_vf_send_msg_to_pf(dev, &msg_info, sizeof(msg_info), 
NULL, 0);
+               if (ret) {
+                       PMD_DRV_LOG(ERR, "Failed to send msg: port 0x%x msg 
type %d ",
+                               hw->vport.vport, ZXDH_PORT_MTU_EN_FLAG);
+                       return ret;
+               }
+               attr_msg->mode = ZXDH_PORT_MTU_FLAG;
+               attr_msg->value = new_mtu;
+               ret = zxdh_vf_send_msg_to_pf(dev, &msg_info, sizeof(msg_info), 
NULL, 0);
+               if (ret) {
+                       PMD_DRV_LOG(ERR, "Failed to send msg: port 0x%x msg 
type %d ",
+                               hw->vport.vport, ZXDH_PORT_MTU_FLAG);
+                       return ret;
+               }
+       }
+       dev->data->mtu = new_mtu;
+       return 0;
+}
diff --git a/drivers/net/zxdh/zxdh_ethdev_ops.h 
b/drivers/net/zxdh/zxdh_ethdev_ops.h
index dad84934fc..3f37c35178 100644
--- a/drivers/net/zxdh/zxdh_ethdev_ops.h
+++ b/drivers/net/zxdh/zxdh_ethdev_ops.h
@@ -55,5 +55,6 @@ int zxdh_rss_hash_update(struct rte_eth_dev *dev, struct 
rte_eth_rss_conf *rss_c
 int zxdh_rss_hash_conf_get(struct rte_eth_dev *dev, struct rte_eth_rss_conf 
*rss_conf);
 int zxdh_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats);
 int zxdh_dev_stats_reset(struct rte_eth_dev *dev);
+int zxdh_dev_mtu_set(struct rte_eth_dev *dev, uint16_t new_mtu);
 
 #endif /* ZXDH_ETHDEV_OPS_H */
diff --git a/drivers/net/zxdh/zxdh_tables.c b/drivers/net/zxdh/zxdh_tables.c
index e8e483a02a..6587c868c7 100644
--- a/drivers/net/zxdh/zxdh_tables.c
+++ b/drivers/net/zxdh/zxdh_tables.c
@@ -55,6 +55,48 @@ int zxdh_get_port_attr(uint16_t vfid, struct 
zxdh_port_attr_table *port_attr)
        return ret;
 }
 
+int zxdh_get_panel_attr(struct rte_eth_dev *dev, struct zxdh_panel_table 
*panel_att)
+{
+       struct zxdh_hw *hw = dev->data->dev_private;
+       uint8_t index_phy_port = hw->phyport;
+
+       ZXDH_DTB_ERAM_ENTRY_INFO_T panel_entry = {
+               .index = index_phy_port,
+               .p_data = (uint32_t *)panel_att
+       };
+       ZXDH_DTB_USER_ENTRY_T entry = {
+               .sdt_no = ZXDH_SDT_PANEL_ATT_TABLE,
+               .p_entry_data = (void *)&panel_entry
+       };
+       int ret = zxdh_np_dtb_table_entry_get(ZXDH_DEVICE_NO, 
g_dtb_data.queueid, &entry, 1);
+
+       if (ret != 0)
+               PMD_DRV_LOG(ERR, "get eram-panel  failed, ret:%d ", ret);
+
+       return ret;
+}
+
+int zxdh_set_panel_attr(struct rte_eth_dev *dev, struct zxdh_panel_table 
*panel_att)
+{
+       struct zxdh_hw *hw = dev->data->dev_private;
+       uint8_t index_phy_port = hw->phyport;
+
+       ZXDH_DTB_ERAM_ENTRY_INFO_T panel_entry = {
+               .index = index_phy_port,
+               .p_data = (uint32_t *)panel_att
+       };
+       ZXDH_DTB_USER_ENTRY_T entry = {
+               .sdt_no = ZXDH_SDT_PANEL_ATT_TABLE,
+               .p_entry_data = (void *)&panel_entry
+       };
+       int ret = zxdh_np_dtb_table_entry_write(ZXDH_DEVICE_NO, 
g_dtb_data.queueid, 1, &entry);
+
+       if (ret)
+               PMD_DRV_LOG(ERR, "Insert eram-panel failed, code:%u", ret);
+
+       return ret;
+}
+
 int
 zxdh_port_attr_init(struct rte_eth_dev *dev)
 {
diff --git a/drivers/net/zxdh/zxdh_tables.h b/drivers/net/zxdh/zxdh_tables.h
index 675c7871ae..d176ec2ed3 100644
--- a/drivers/net/zxdh/zxdh_tables.h
+++ b/drivers/net/zxdh/zxdh_tables.h
@@ -10,8 +10,10 @@
 extern struct zxdh_dtb_shared_data g_dtb_data;
 
 #define ZXDH_DEVICE_NO                    0
+#define ZXDH_PORT_MTU_FLAG                9
 #define ZXDH_PORT_BASE_QID_FLAG           10
 #define ZXDH_PORT_ATTR_IS_UP_FLAG         35
+#define ZXDH_PORT_MTU_EN_FLAG             42
 
 #define ZXDH_MTU_STATS_EGRESS_BASE        0x8481
 #define ZXDH_MTU_STATS_INGRESS_BASE       0x8981
@@ -223,5 +225,7 @@ int zxdh_vlan_filter_table_init(struct rte_eth_dev *dev);
 int zxdh_vlan_filter_table_set(uint16_t vport, uint16_t vlan_id, uint8_t 
enable);
 int zxdh_rss_table_set(uint16_t vport, struct zxdh_rss_reta *rss_reta);
 int zxdh_rss_table_get(uint16_t vport, struct zxdh_rss_reta *rss_reta);
+int zxdh_get_panel_attr(struct rte_eth_dev *dev, struct zxdh_panel_table 
*panel_att);
+int zxdh_set_panel_attr(struct rte_eth_dev *dev, struct zxdh_panel_table 
*panel_att);
 
 #endif /* ZXDH_TABLES_H */
-- 
2.27.0

Reply via email to