provided link info update, set link up /down,
and link intr.

Signed-off-by: Junlong Wang <wang.junlo...@zte.com.cn>
---
 doc/guides/nics/features/zxdh.ini  |   4 +-
 doc/guides/nics/zxdh.rst           |   3 +
 drivers/net/zxdh/meson.build       |   1 +
 drivers/net/zxdh/zxdh_ethdev.c     |  13 ++
 drivers/net/zxdh/zxdh_ethdev.h     |   2 +
 drivers/net/zxdh/zxdh_ethdev_ops.c | 166 ++++++++++++++++++++++++++
 drivers/net/zxdh/zxdh_ethdev_ops.h |  14 +++
 drivers/net/zxdh/zxdh_msg.c        |  58 ++++++++-
 drivers/net/zxdh/zxdh_msg.h        |  41 +++++++
 drivers/net/zxdh/zxdh_np.c         | 183 +++++++++++++++++++++++++++++
 drivers/net/zxdh/zxdh_np.h         |  20 ++++
 drivers/net/zxdh/zxdh_tables.c     |  14 +++
 drivers/net/zxdh/zxdh_tables.h     |   2 +
 13 files changed, 519 insertions(+), 2 deletions(-)
 create mode 100644 drivers/net/zxdh/zxdh_ethdev_ops.c
 create mode 100644 drivers/net/zxdh/zxdh_ethdev_ops.h

diff --git a/doc/guides/nics/features/zxdh.ini 
b/doc/guides/nics/features/zxdh.ini
index 85c5c8fd32..f052fde413 100644
--- a/doc/guides/nics/features/zxdh.ini
+++ b/doc/guides/nics/features/zxdh.ini
@@ -9,4 +9,6 @@ x86-64               = Y
 ARMv8                = Y
 SR-IOV               = Y
 Multiprocess         = Y
-Scattered Rx         = Y
\ No newline at end of file
+Scattered Rx         = Y
+Link status          = Y
+Link status event    = Y
diff --git a/doc/guides/nics/zxdh.rst b/doc/guides/nics/zxdh.rst
index f42db9c1f1..fdbc3b3923 100644
--- a/doc/guides/nics/zxdh.rst
+++ b/doc/guides/nics/zxdh.rst
@@ -21,6 +21,9 @@ Features of the ZXDH PMD are:
 - Multiple queues for TX and RX
 - SR-IOV VF
 - Scattered and gather for TX and RX
+- Link Auto-negotiation
+- Link state information
+- Set Link down or up
 
 
 Driver compilation and testing
diff --git a/drivers/net/zxdh/meson.build b/drivers/net/zxdh/meson.build
index 20b2cf484a..48f8f5e1ee 100644
--- a/drivers/net/zxdh/meson.build
+++ b/drivers/net/zxdh/meson.build
@@ -22,4 +22,5 @@ sources = files(
         'zxdh_np.c',
         'zxdh_tables.c',
         'zxdh_rxtx.c',
+        'zxdh_ethdev_ops.c',
 )
diff --git a/drivers/net/zxdh/zxdh_ethdev.c b/drivers/net/zxdh/zxdh_ethdev.c
index 226b9d6b67..57ee2f7c55 100644
--- a/drivers/net/zxdh/zxdh_ethdev.c
+++ b/drivers/net/zxdh/zxdh_ethdev.c
@@ -16,6 +16,7 @@
 #include "zxdh_np.h"
 #include "zxdh_tables.h"
 #include "zxdh_rxtx.h"
+#include "zxdh_ethdev_ops.h"
 
 struct zxdh_hw_internal zxdh_hw_internal[RTE_MAX_ETHPORTS];
 struct zxdh_shared_data *zxdh_shared_data;
@@ -105,9 +106,16 @@ static void
 zxdh_devconf_intr_handler(void *param)
 {
        struct rte_eth_dev *dev = param;
+       struct zxdh_hw *hw = dev->data->dev_private;
+
+       uint8_t isr = zxdh_pci_isr(hw);
 
        if (zxdh_intr_unmask(dev) < 0)
                PMD_DRV_LOG(ERR, "interrupt enable failed");
+       if (isr & ZXDH_PCI_ISR_CONFIG) {
+               if (zxdh_dev_link_update(dev, 0) == 0)
+                       rte_eth_dev_callback_process(dev, 
RTE_ETH_EVENT_INTR_LSC, NULL);
+       }
 }
 
 
@@ -1007,6 +1015,8 @@ zxdh_dev_start(struct rte_eth_dev *dev)
                vq = hw->vqs[logic_qidx];
                zxdh_queue_notify(vq);
        }
+       zxdh_dev_set_link_up(dev);
+
        return 0;
 }
 
@@ -1021,6 +1031,9 @@ static const struct eth_dev_ops zxdh_eth_dev_ops = {
        .tx_queue_setup                  = zxdh_dev_tx_queue_setup,
        .rx_queue_intr_enable    = zxdh_dev_rx_queue_intr_enable,
        .rx_queue_intr_disable   = zxdh_dev_rx_queue_intr_disable,
+       .link_update                     = zxdh_dev_link_update,
+       .dev_set_link_up                 = zxdh_dev_set_link_up,
+       .dev_set_link_down               = zxdh_dev_set_link_down,
 };
 
 static int32_t
diff --git a/drivers/net/zxdh/zxdh_ethdev.h b/drivers/net/zxdh/zxdh_ethdev.h
index 6fdb5fb767..cf2bc207e9 100644
--- a/drivers/net/zxdh/zxdh_ethdev.h
+++ b/drivers/net/zxdh/zxdh_ethdev.h
@@ -70,6 +70,7 @@ struct zxdh_hw {
        uint64_t guest_features;
        uint32_t max_queue_pairs;
        uint32_t speed;
+       uint32_t speed_mode;
        uint32_t notify_off_multiplier;
        uint16_t *notify_base;
        uint16_t pcie_id;
@@ -91,6 +92,7 @@ struct zxdh_hw {
        uint8_t panel_id;
        uint8_t has_tx_offload;
        uint8_t has_rx_offload;
+       uint8_t admin_status;
 };
 
 struct zxdh_dtb_shared_data {
diff --git a/drivers/net/zxdh/zxdh_ethdev_ops.c 
b/drivers/net/zxdh/zxdh_ethdev_ops.c
new file mode 100644
index 0000000000..635868c4c0
--- /dev/null
+++ b/drivers/net/zxdh/zxdh_ethdev_ops.c
@@ -0,0 +1,166 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 ZTE Corporation
+ */
+
+#include "zxdh_ethdev.h"
+#include "zxdh_pci.h"
+#include "zxdh_msg.h"
+#include "zxdh_ethdev_ops.h"
+#include "zxdh_tables.h"
+#include "zxdh_logs.h"
+
+static int32_t zxdh_config_port_status(struct rte_eth_dev *dev, uint16_t 
link_status)
+{
+       struct zxdh_hw *hw = dev->data->dev_private;
+       struct zxdh_port_attr_table port_attr = {0};
+       struct zxdh_msg_info msg_info = {0};
+       int32_t ret = 0;
+
+       if (hw->is_pf) {
+               ret = zxdh_get_port_attr(hw->vfid, &port_attr);
+               if (ret) {
+                       PMD_DRV_LOG(ERR, "write port_attr failed");
+                       return -EAGAIN;
+               }
+               port_attr.is_up = link_status;
+
+               ret = zxdh_set_port_attr(hw->vfid, &port_attr);
+               if (ret) {
+                       PMD_DRV_LOG(ERR, "write port_attr failed");
+                       return -EAGAIN;
+               }
+       } else {
+               struct zxdh_port_attr_set_msg *port_attr_msg = 
&msg_info.data.port_attr_msg;
+
+               zxdh_msg_head_build(hw, ZXDH_PORT_ATTRS_SET, &msg_info);
+               port_attr_msg->mode = ZXDH_PORT_ATTR_IS_UP_FLAG;
+               port_attr_msg->value = link_status;
+               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_ATTR_IS_UP_FLAG);
+                       return ret;
+               }
+       }
+       return ret;
+}
+
+static int32_t
+zxdh_link_info_get(struct rte_eth_dev *dev, struct rte_eth_link *link)
+{
+       struct zxdh_hw *hw = dev->data->dev_private;
+       struct zxdh_msg_info msg_info = {0};
+       struct zxdh_msg_reply_info reply_info = {0};
+       uint16_t status = 0;
+       int32_t ret = 0;
+
+       if (zxdh_pci_with_feature(hw, ZXDH_NET_F_STATUS))
+               zxdh_pci_read_dev_config(hw, offsetof(struct zxdh_net_config, 
status),
+                                       &status, sizeof(status));
+
+       link->link_status = status;
+
+       if (status == RTE_ETH_LINK_DOWN) {
+               link->link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
+               link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
+       } else {
+               zxdh_agent_msg_build(hw, ZXDH_MAC_LINK_GET, &msg_info);
+
+               ret = zxdh_send_msg_to_riscv(dev, &msg_info, sizeof(struct 
zxdh_msg_info),
+                               &reply_info, sizeof(struct zxdh_msg_reply_info),
+                               ZXDH_BAR_MODULE_MAC);
+               if (ret) {
+                       PMD_DRV_LOG(ERR, "Failed to send msg: port 0x%x msg 
type %d",
+                                       hw->vport.vport, ZXDH_MAC_LINK_GET);
+                       return -EAGAIN;
+               }
+               link->link_speed = reply_info.reply_body.link_msg.speed;
+               hw->speed_mode = reply_info.reply_body.link_msg.speed_modes;
+               if ((reply_info.reply_body.link_msg.duplex & 
RTE_ETH_LINK_FULL_DUPLEX) ==
+                               RTE_ETH_LINK_FULL_DUPLEX)
+                       link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
+               else
+                       link->link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
+       }
+       hw->speed = link->link_speed;
+
+       return 0;
+}
+
+static int zxdh_set_link_status(struct rte_eth_dev *dev, uint8_t link_status)
+{
+       uint16_t curr_link_status = dev->data->dev_link.link_status;
+
+       struct rte_eth_link link;
+       struct zxdh_hw *hw = dev->data->dev_private;
+       int32_t ret = 0;
+
+       if (link_status == curr_link_status) {
+               PMD_DRV_LOG(INFO, "curr_link_status %u", curr_link_status);
+               return 0;
+       }
+
+       hw->admin_status = link_status;
+       ret = zxdh_link_info_get(dev, &link);
+       if (ret != 0) {
+               PMD_DRV_LOG(ERR, "Failed to get link status from hw");
+               return ret;
+       }
+       dev->data->dev_link.link_status = hw->admin_status & link.link_status;
+
+       if (dev->data->dev_link.link_status == RTE_ETH_LINK_UP) {
+               dev->data->dev_link.link_speed = link.link_speed;
+               dev->data->dev_link.link_duplex = link.link_duplex;
+       } else {
+               dev->data->dev_link.link_speed = RTE_ETH_SPEED_NUM_UNKNOWN;
+               dev->data->dev_link.link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
+       }
+       return zxdh_config_port_status(dev, dev->data->dev_link.link_status);
+}
+
+int zxdh_dev_set_link_up(struct rte_eth_dev *dev)
+{
+       int ret = zxdh_set_link_status(dev, RTE_ETH_LINK_UP);
+
+       if (ret)
+               PMD_DRV_LOG(ERR, "Set link up failed, code:%d", ret);
+
+       return ret;
+}
+
+int32_t zxdh_dev_link_update(struct rte_eth_dev *dev, int32_t wait_to_complete 
__rte_unused)
+{
+       struct rte_eth_link link;
+       struct zxdh_hw *hw = dev->data->dev_private;
+       int32_t ret = 0;
+
+       memset(&link, 0, sizeof(link));
+       link.link_duplex = hw->duplex;
+       link.link_speed  = hw->speed;
+       link.link_autoneg = RTE_ETH_LINK_AUTONEG;
+
+       ret = zxdh_link_info_get(dev, &link);
+       if (ret != 0) {
+               PMD_DRV_LOG(ERR, " Failed to get link status from hw");
+               return ret;
+       }
+       link.link_status &= hw->admin_status;
+       if (link.link_status == RTE_ETH_LINK_DOWN)
+               link.link_speed  = RTE_ETH_SPEED_NUM_UNKNOWN;
+
+       ret = zxdh_config_port_status(dev, link.link_status);
+       if (ret != 0) {
+               PMD_DRV_LOG(ERR, "set port attr %d failed.", link.link_status);
+               return ret;
+       }
+       return rte_eth_linkstatus_set(dev, &link);
+}
+
+int zxdh_dev_set_link_down(struct rte_eth_dev *dev)
+{
+       int ret = zxdh_set_link_status(dev, RTE_ETH_LINK_DOWN);
+
+       if (ret)
+               PMD_DRV_LOG(ERR, "Set link down failed");
+       return ret;
+}
diff --git a/drivers/net/zxdh/zxdh_ethdev_ops.h 
b/drivers/net/zxdh/zxdh_ethdev_ops.h
new file mode 100644
index 0000000000..c6d6ca56fd
--- /dev/null
+++ b/drivers/net/zxdh/zxdh_ethdev_ops.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2024 ZTE Corporation
+ */
+
+#ifndef ZXDH_ETHDEV_OPS_H
+#define ZXDH_ETHDEV_OPS_H
+
+#include "zxdh_ethdev.h"
+
+int zxdh_dev_set_link_up(struct rte_eth_dev *dev);
+int zxdh_dev_set_link_down(struct rte_eth_dev *dev);
+int32_t zxdh_dev_link_update(struct rte_eth_dev *dev, int32_t wait_to_complete 
__rte_unused);
+
+#endif /* ZXDH_ETHDEV_OPS_H */
diff --git a/drivers/net/zxdh/zxdh_msg.c b/drivers/net/zxdh/zxdh_msg.c
index 1aed979de3..be7bf46728 100644
--- a/drivers/net/zxdh/zxdh_msg.c
+++ b/drivers/net/zxdh/zxdh_msg.c
@@ -1083,7 +1083,7 @@ int zxdh_get_bar_offset(struct zxdh_bar_offset_params 
*paras,
        return ZXDH_BAR_MSG_OK;
 }
 
-int zxdh_vf_send_msg_to_pf(struct rte_eth_dev *dev,  void *msg_req,
+int zxdh_vf_send_msg_to_pf(struct rte_eth_dev *dev, void *msg_req,
                        uint16_t msg_req_len, void *reply, uint16_t reply_len)
 {
        struct zxdh_hw *hw  = dev->data->dev_private;
@@ -1133,6 +1133,50 @@ int zxdh_vf_send_msg_to_pf(struct rte_eth_dev *dev,  
void *msg_req,
        return 0;
 }
 
+int32_t zxdh_send_msg_to_riscv(struct rte_eth_dev *dev, void *msg_req,
+                       uint16_t msg_req_len, void *reply, uint16_t reply_len,
+                       enum ZXDH_BAR_MODULE_ID module_id)
+{
+       struct zxdh_hw *hw = dev->data->dev_private;
+       struct zxdh_pci_bar_msg in = {0};
+       struct zxdh_msg_recviver_mem result = {0};
+       struct zxdh_msg_reply_info reply_info = {0};
+
+       if (reply) {
+               RTE_ASSERT(reply_len < sizeof(zxdh_msg_reply_info));
+               result.recv_buffer  = reply;
+               result.buffer_len = reply_len;
+       } else {
+               result.recv_buffer = &reply_info;
+               result.buffer_len = sizeof(reply_info);
+       }
+       struct zxdh_msg_reply_head *reply_head =
+                               &(((struct zxdh_msg_reply_info 
*)result.recv_buffer)->reply_head);
+       struct zxdh_msg_reply_body *reply_body =
+                               &(((struct zxdh_msg_reply_info 
*)result.recv_buffer)->reply_body);
+       in.payload_addr = &msg_req;
+       in.payload_len = msg_req_len;
+       in.virt_addr = (uint64_t)(hw->bar_addr[ZXDH_BAR0_INDEX] + 
ZXDH_CTRLCH_OFFSET);
+       in.src = hw->is_pf ? ZXDH_MSG_CHAN_END_PF : ZXDH_MSG_CHAN_END_VF;
+       in.dst = ZXDH_MSG_CHAN_END_RISC;
+       in.module_id = module_id;
+       in.src_pcieid = hw->pcie_id;
+       if (zxdh_bar_chan_sync_msg_send(&in, &result) != ZXDH_BAR_MSG_OK) {
+               PMD_MSG_LOG(ERR, "Failed to send sync messages or receive 
response");
+               return -EAGAIN;
+       }
+       if (reply_head->flag != ZXDH_MSG_REPS_OK) {
+               PMD_MSG_LOG(ERR, "vf[%d] get pf reply failed: reply_head flag : 
0x%x(0xff is OK).replylen %d",
+                               hw->vport.vfid, reply_head->flag, 
reply_head->reps_len);
+               return -EAGAIN;
+       }
+       if (reply_body->flag != ZXDH_REPS_SUCC) {
+               PMD_MSG_LOG(ERR, "vf[%d] msg processing failed", hw->vfid);
+               return -EAGAIN;
+       }
+       return 0;
+}
+
 void zxdh_msg_head_build(struct zxdh_hw *hw, enum zxdh_msg_type type,
                struct zxdh_msg_info *msg_info)
 {
@@ -1143,3 +1187,15 @@ void zxdh_msg_head_build(struct zxdh_hw *hw, enum 
zxdh_msg_type type,
        msghead->vf_id    = hw->vport.vfid;
        msghead->pcieid   = hw->pcie_id;
 }
+
+void zxdh_agent_msg_build(struct zxdh_hw *hw, enum zxdh_agent_msg_type type,
+               struct zxdh_msg_info *msg_info)
+{
+       struct zxdh_agent_msg_head *agent_head = &msg_info->agent_msg_head;
+
+       agent_head->msg_type = type;
+       agent_head->panel_id = hw->panel_id;
+       agent_head->phyport = hw->phyport;
+       agent_head->vf_id = hw->vfid;
+       agent_head->pcie_id = hw->pcie_id;
+}
diff --git a/drivers/net/zxdh/zxdh_msg.h b/drivers/net/zxdh/zxdh_msg.h
index 9997417f28..66c337443b 100644
--- a/drivers/net/zxdh/zxdh_msg.h
+++ b/drivers/net/zxdh/zxdh_msg.h
@@ -164,11 +164,18 @@ enum pciebar_layout_type {
        ZXDH_URI_MAX,
 };
 
+/* riscv msg opcodes */
+enum zxdh_agent_msg_type {
+       ZXDH_MAC_LINK_GET = 14,
+} __rte_packed;
+
 enum zxdh_msg_type {
        ZXDH_NULL = 0,
        ZXDH_VF_PORT_INIT = 1,
        ZXDH_VF_PORT_UNINIT = 2,
 
+       ZXDH_PORT_ATTRS_SET = 25,
+
        ZXDH_MSG_TYPE_END,
 } __rte_packed;
 
@@ -261,6 +268,16 @@ struct zxdh_offset_get_msg {
        uint16_t type;
 };
 
+struct zxdh_link_info_msg {
+       uint8_t autoneg;
+       uint8_t link_state;
+       uint8_t blink_enable;
+       uint8_t duplex;
+       uint32_t speed_modes;
+       uint32_t speed;
+} __rte_packed;
+
+
 struct zxdh_msg_reply_head {
        uint8_t flag;
        uint16_t reps_len;
@@ -276,6 +293,7 @@ struct zxdh_msg_reply_body {
        enum zxdh_reps_flag flag;
        union {
                uint8_t reply_data[ZXDH_MSG_REPLY_BODY_MAX_LEN - sizeof(enum 
zxdh_reps_flag)];
+               struct zxdh_link_info_msg link_msg;
        } __rte_packed;
 } __rte_packed;
 
@@ -291,6 +309,21 @@ struct zxdh_vf_init_msg {
        uint8_t rss_enable;
 } __rte_packed;
 
+struct zxdh_port_attr_set_msg {
+       uint32_t mode;
+       uint32_t value;
+       uint8_t allmulti_follow;
+} __rte_packed;
+
+struct zxdh_agent_msg_head {
+       enum zxdh_agent_msg_type msg_type;
+       uint8_t panel_id;
+       uint8_t phyport;
+       uint8_t rsv;
+       uint16_t vf_id;
+       uint16_t pcie_id;
+} __rte_packed;
+
 struct zxdh_msg_head {
        enum zxdh_msg_type msg_type;
        uint16_t  vport;
@@ -302,10 +335,13 @@ struct zxdh_msg_info {
        union {
                uint8_t head_len[ZXDH_MSG_HEAD_LEN];
                struct zxdh_msg_head msg_head;
+               struct zxdh_agent_msg_head agent_msg_head;
        };
        union {
                uint8_t datainfo[ZXDH_MSG_REQ_BODY_MAX_LEN];
                struct zxdh_vf_init_msg vf_init_msg;
+               struct zxdh_port_attr_set_msg port_attr_msg;
+               struct zxdh_link_info_msg link_msg;
        } __rte_packed data;
 } __rte_packed;
 
@@ -326,5 +362,10 @@ void zxdh_msg_head_build(struct zxdh_hw *hw, enum 
zxdh_msg_type type,
                struct zxdh_msg_info *msg_info);
 int zxdh_vf_send_msg_to_pf(struct rte_eth_dev *dev,  void *msg_req,
                        uint16_t msg_req_len, void *reply, uint16_t reply_len);
+void zxdh_agent_msg_build(struct zxdh_hw *hw, enum zxdh_agent_msg_type type,
+               struct zxdh_msg_info *msg_info);
+int32_t zxdh_send_msg_to_riscv(struct rte_eth_dev *dev, void *msg_req,
+                       uint16_t msg_req_len, void *reply, uint16_t reply_len,
+                       enum ZXDH_BAR_MODULE_ID module_id);
 
 #endif /* ZXDH_MSG_H */
diff --git a/drivers/net/zxdh/zxdh_np.c b/drivers/net/zxdh/zxdh_np.c
index 242a6901ed..2a4d38b846 100644
--- a/drivers/net/zxdh/zxdh_np.c
+++ b/drivers/net/zxdh/zxdh_np.c
@@ -36,6 +36,16 @@ ZXDH_DTB_TABLE_T g_dpp_dtb_table_info[4] = {0};
 #define ZXDH_COMM_GET_BIT_MASK(_inttype_, _bitqnt_)\
        ((_inttype_)(((_bitqnt_) < 32)))
 
+#define ZXDH_COMM_UINT32_GET_BITS(_uidst_, _uisrc_, _uistartpos_, _uilen_)\
+       ((_uidst_) = (((_uisrc_) >> (_uistartpos_)) & \
+                               (ZXDH_COMM_GET_BIT_MASK(uint32_t, (_uilen_)))))
+
+#define ZXDH_COMM_UINT32_WRITE_BITS(_uidst_, _uisrc_, _uistartpos_, _uilen_)\
+       (((_uidst_) & ~(ZXDH_COMM_GET_BIT_MASK(uint32_t, (_uilen_)) << 
(_uistartpos_))))
+
+#define ZXDH_COMM_CONVERT32(dw_data) \
+                                       (((dw_data) & 0xff) << 24)
+
 #define ZXDH_REG_DATA_MAX      (128)
 
 #define ZXDH_COMM_CHECK_DEV_POINT(dev_id, point)\
@@ -1610,3 +1620,176 @@ zxdh_np_dtb_table_entry_delete(uint32_t dev_id,
        rte_free(p_data_buff_ex);
        return 0;
 }
+
+static uint32_t
+zxdh_np_sdt_tbl_data_parser(uint32_t sdt_hig32, uint32_t sdt_low32, void 
*p_sdt_info)
+{
+       uint32_t tbl_type = 0;
+       uint32_t clutch_en = 0;
+
+       ZXDH_SDTTBL_ERAM_T *p_sdt_eram = NULL;
+       ZXDH_SDTTBL_PORTTBL_T *p_sdt_porttbl = NULL;
+
+
+       ZXDH_COMM_UINT32_GET_BITS(tbl_type,  sdt_hig32,
+               ZXDH_SDT_H_TBL_TYPE_BT_POS,     ZXDH_SDT_H_TBL_TYPE_BT_LEN);
+       ZXDH_COMM_UINT32_GET_BITS(clutch_en, sdt_low32, 0, 1);
+
+       switch (tbl_type) {
+       case ZXDH_SDT_TBLT_ERAM:
+       {
+               p_sdt_eram = (ZXDH_SDTTBL_ERAM_T *)p_sdt_info;
+               p_sdt_eram->table_type = tbl_type;
+               p_sdt_eram->eram_clutch_en = clutch_en;
+               break;
+       }
+
+       case ZXDH_SDT_TBLT_PORTTBL:
+       {
+               p_sdt_porttbl = (ZXDH_SDTTBL_PORTTBL_T *)p_sdt_info;
+               p_sdt_porttbl->table_type = tbl_type;
+               p_sdt_porttbl->porttbl_clutch_en = clutch_en;
+               break;
+       }
+       default:
+       {
+               PMD_DRV_LOG(ERR, "SDT table_type[ %d ] is invalid!", tbl_type);
+               return 1;
+       }
+       }
+
+       return 0;
+}
+
+static uint32_t
+zxdh_np_soft_sdt_tbl_get(uint32_t dev_id, uint32_t sdt_no, void *p_sdt_info)
+{
+       uint32_t  rc       = 0;
+       ZXDH_SDT_TBL_DATA_T sdt_tbl = {0};
+
+       rc = zxdh_np_sdt_tbl_data_get(dev_id, sdt_no, &sdt_tbl);
+       ZXDH_COMM_CHECK_RC_NO_ASSERT(rc, "zxdh_sdt_tbl_data_get");
+
+       rc = zxdh_np_sdt_tbl_data_parser(sdt_tbl.data_high32, 
sdt_tbl.data_low32, p_sdt_info);
+
+       if (rc != 0)
+               PMD_DRV_LOG(ERR, "dpp sdt [%d] tbl_data_parser error.", sdt_no);
+
+       ZXDH_COMM_CHECK_RC_NO_ASSERT(rc, "zxdh_sdt_tbl_data_parser");
+
+       return rc;
+}
+
+static uint32_t
+zxdh_np_eram_index_cal(uint32_t eram_mode, uint32_t index,
+               uint32_t *p_row_index, uint32_t *p_col_index)
+{
+       uint32_t  rc = 0;
+       uint32_t row_index = 0;
+       uint32_t col_index = 0;
+
+       switch (eram_mode) {
+       case ZXDH_ERAM128_TBL_128b:
+       {
+               row_index = index;
+               break;
+       }
+       case ZXDH_ERAM128_TBL_64b:
+       {
+               row_index = (index >> 1);
+               col_index = index & 0x1;
+               break;
+       }
+       case ZXDH_ERAM128_TBL_1b:
+       {
+               row_index = (index >> 7);
+               col_index = index & 0x7F;
+               break;
+       }
+       }
+       *p_row_index = row_index;
+       *p_col_index = col_index;
+
+       return rc;
+}
+
+static uint32_t
+zxdh_np_dtb_eram_data_get(uint32_t dev_id, uint32_t queue_id, uint32_t sdt_no,
+               ZXDH_DTB_ERAM_ENTRY_INFO_T *p_dump_eram_entry)
+{
+       uint32_t  rc = 0;
+       uint32_t rd_mode = 0;
+       uint32_t row_index = 0;
+       uint32_t col_index = 0;
+       uint32_t temp_data[4] = {0};
+       uint32_t index = p_dump_eram_entry->index;
+       uint32_t *p_data = p_dump_eram_entry->p_data;
+
+       ZXDH_SDTTBL_ERAM_T sdt_eram_info = {0};
+
+       rc = zxdh_np_soft_sdt_tbl_get(queue_id, sdt_no, &sdt_eram_info);
+       ZXDH_COMM_CHECK_DEV_RC(dev_id, rc, "dpp_soft_sdt_tbl_get");
+       rd_mode = sdt_eram_info.eram_mode;
+
+       rc = zxdh_np_eram_index_cal(rd_mode, index, &row_index, &col_index);
+       ZXDH_COMM_CHECK_RC_NO_ASSERT(rc, "dtb_eram_index_cal");
+
+       switch (rd_mode) {
+       case ZXDH_ERAM128_TBL_128b:
+       {
+               memcpy(p_data, temp_data, (128 / 8));
+               break;
+       }
+
+       case ZXDH_ERAM128_TBL_64b:
+       {
+               memcpy(p_data, temp_data + ((1 - col_index) << 1), (64 / 8));
+               break;
+       }
+
+       case ZXDH_ERAM128_TBL_1b:
+       {
+               ZXDH_COMM_UINT32_GET_BITS(p_data[0], *(temp_data +
+                       (3 - col_index / 32)), (col_index % 32), 1);
+               break;
+       }
+       }
+       return rc;
+}
+
+int
+zxdh_np_dtb_table_entry_get(uint32_t dev_id,
+                uint32_t queue_id,
+                ZXDH_DTB_USER_ENTRY_T *get_entry,
+                uint32_t srh_mode)
+{
+       uint32_t rc = 0;
+       uint32_t sdt_no = 0;
+       uint32_t tbl_type = 0;
+       ZXDH_SDT_TBL_DATA_T sdt_tbl = {0};
+
+       memset(&sdt_tbl, 0x0, sizeof(ZXDH_SDT_TBL_DATA_T));
+       sdt_no = get_entry->sdt_no;
+       rc = zxdh_np_sdt_tbl_data_get(srh_mode, sdt_no, &sdt_tbl);
+       ZXDH_COMM_CHECK_RC_NO_ASSERT(rc, "dpp_sdt_tbl_data_get");
+       ZXDH_COMM_UINT32_GET_BITS(tbl_type, sdt_tbl.data_high32,
+                       ZXDH_SDT_H_TBL_TYPE_BT_POS, ZXDH_SDT_H_TBL_TYPE_BT_LEN);
+       switch (tbl_type) {
+       case ZXDH_SDT_TBLT_ERAM:
+       {
+               rc = zxdh_np_dtb_eram_data_get(dev_id,
+                               queue_id,
+                               sdt_no,
+                               (ZXDH_DTB_ERAM_ENTRY_INFO_T 
*)get_entry->p_entry_data);
+               ZXDH_COMM_CHECK_RC_NO_ASSERT(rc, "dpp_dtb_eram_data_get");
+               break;
+       }
+       default:
+       {
+               PMD_DRV_LOG(ERR, "SDT table_type[ %d ] is invalid!", tbl_type);
+               return 1;
+       }
+       }
+
+       return 0;
+}
diff --git a/drivers/net/zxdh/zxdh_np.h b/drivers/net/zxdh/zxdh_np.h
index 3cb9580254..3a7a830d7d 100644
--- a/drivers/net/zxdh/zxdh_np.h
+++ b/drivers/net/zxdh/zxdh_np.h
@@ -514,11 +514,31 @@ typedef struct zxdh_sdt_tbl_data_t {
        uint32_t data_low32;
 } ZXDH_SDT_TBL_DATA_T;
 
+typedef struct zxdh_sdt_tbl_etcam_t {
+       uint32_t table_type;
+       uint32_t etcam_id;
+       uint32_t etcam_key_mode;
+       uint32_t etcam_table_id;
+       uint32_t no_as_rsp_mode;
+       uint32_t as_en;
+       uint32_t as_eram_baddr;
+       uint32_t as_rsp_mode;
+       uint32_t etcam_table_depth;
+       uint32_t etcam_clutch_en;
+} ZXDH_SDTTBL_ETCAM_T;
+
+typedef struct zxdh_sdt_tbl_porttbl_t {
+       uint32_t table_type;
+       uint32_t porttbl_clutch_en;
+} ZXDH_SDTTBL_PORTTBL_T;
+
 int zxdh_np_host_init(uint32_t dev_id, ZXDH_DEV_INIT_CTRL_T *p_dev_init_ctrl);
 int zxdh_np_online_uninit(uint32_t dev_id, char *port_name, uint32_t queue_id);
 int zxdh_np_dtb_table_entry_write(uint32_t dev_id, uint32_t queue_id,
                        uint32_t entrynum, ZXDH_DTB_USER_ENTRY_T *down_entries);
 int zxdh_np_dtb_table_entry_delete(uint32_t dev_id, uint32_t queue_id,
                         uint32_t entrynum, ZXDH_DTB_USER_ENTRY_T 
*delete_entries);
+int zxdh_np_dtb_table_entry_get(uint32_t dev_id, uint32_t queue_id,
+                       ZXDH_DTB_USER_ENTRY_T *get_entry, uint32_t srh_mode);
 
 #endif /* ZXDH_NP_H */
diff --git a/drivers/net/zxdh/zxdh_tables.c b/drivers/net/zxdh/zxdh_tables.c
index e28823c657..15098e723d 100644
--- a/drivers/net/zxdh/zxdh_tables.c
+++ b/drivers/net/zxdh/zxdh_tables.c
@@ -26,6 +26,20 @@ int zxdh_set_port_attr(uint16_t vfid, struct 
zxdh_port_attr_table *port_attr)
        return ret;
 }
 
+int zxdh_get_port_attr(uint16_t vfid, struct zxdh_port_attr_table *port_attr)
+{
+       int ret = 0;
+
+       ZXDH_DTB_ERAM_ENTRY_INFO_T entry = {vfid, (uint32_t *)port_attr};
+       ZXDH_DTB_USER_ENTRY_T user_entry_get = {ZXDH_SDT_VPORT_ATT_TABLE, 
&entry};
+
+       ret = zxdh_np_dtb_table_entry_get(ZXDH_DEVICE_NO, g_dtb_data.queueid, 
&user_entry_get, 1);
+       if (ret != 0)
+               PMD_DRV_LOG(ERR, "get port_attr vfid:%d failed, ret:%d ", vfid, 
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 5e9b36faee..7f592beb3c 100644
--- a/drivers/net/zxdh/zxdh_tables.h
+++ b/drivers/net/zxdh/zxdh_tables.h
@@ -10,6 +10,7 @@
 extern struct zxdh_dtb_shared_data g_dtb_data;
 
 #define ZXDH_DEVICE_NO                    0
+#define ZXDH_PORT_ATTR_IS_UP_FLAG         35
 
 struct zxdh_port_attr_table {
 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
@@ -144,6 +145,7 @@ struct zxdh_panel_table {
 int zxdh_port_attr_init(struct rte_eth_dev *dev);
 int zxdh_panel_table_init(struct rte_eth_dev *dev);
 int zxdh_set_port_attr(uint16_t vfid, struct zxdh_port_attr_table *port_attr);
+int zxdh_get_port_attr(uint16_t vfid, struct zxdh_port_attr_table *port_attr);
 int zxdh_port_attr_uninit(struct rte_eth_dev *dev);
 
 #endif /* ZXDH_TABLES_H */
-- 
2.27.0

Reply via email to