Skip to contentSkip to conversation

add hinic3 PMD driver

RFC In review Feifei Wang 4 participants 384 messages Apr 18, 2025 – Sep 26, 2025 Page 7 of 16

Subsystems (2)
lore
Share & tools
lore
#150 lore raw

PATCH v5 13/18 net/hinic3: add dev ops

In reply to Feifei Wang

From: Feifei Wang <[email protected]>

Add ops related function codes.

---
 drivers/net/hinic3/hinic3_ethdev.c | 2918 +++++++++++++++++++++++++++-
 drivers/net/hinic3/hinic3_nic_io.c |  828 ++++++++
 drivers/net/hinic3/hinic3_nic_io.h |  169 ++
 drivers/net/hinic3/hinic3_rx.c     |  814 ++++++++
 drivers/net/hinic3/hinic3_rx.h     |  356 ++++
 drivers/net/hinic3/hinic3_tx.c     |  274 +++
 drivers/net/hinic3/hinic3_tx.h     |  314 +++
 7 files changed, 5656 insertions(+), 17 deletions(-)
 create mode 100644 drivers/net/hinic3/hinic3_nic_io.c
 create mode 100644 drivers/net/hinic3/hinic3_nic_io.h
 create mode 100644 drivers/net/hinic3/hinic3_rx.c
 create mode 100644 drivers/net/hinic3/hinic3_rx.h
 create mode 100644 drivers/net/hinic3/hinic3_tx.c
 create mode 100644 drivers/net/hinic3/hinic3_tx.h
drivers/net/hinic3/hinic3_ethdev.c +2901 -17
index e6666a4d87..d9bca3aeb3 100644
@@ -21,42 +21,2917 @@
 #include "base/hinic3_hw_comm.h"
 #include "base/hinic3_nic_cfg.h"
 #include "base/hinic3_nic_event.h"
+#include "hinic3_pmd_nic_io.h"
+#include "hinic3_pmd_tx.h"
+#include "hinic3_pmd_rx.h"
 #include "hinic3_ethdev.h"
 
+#define HINIC3_MIN_RX_BUF_SIZE 1024
+
+#define HINIC3_DEFAULT_BURST_SIZE 32
+#define HINIC3_DEFAULT_NB_QUEUES  1
+#define HINIC3_DEFAULT_RING_SIZE  1024
+#define HINIC3_MAX_LRO_SIZE	  65536
+
+#define HINIC3_DEFAULT_RX_FREE_THRESH 32
+#define HINIC3_DEFAULT_TX_FREE_THRESH 32
+
+#define HINIC3_RX_WAIT_CYCLE_THRESH 500
+
+/**
+ * Get the 32-bit VFTA bit mask for the lower 5 bits of the VLAN ID.
+ *
+ * Vlan_id is a 12 bit number. The VFTA array is actually a 4096 bit array,
+ * 128 of 32bit elements. 2^5 = 32. The val of lower 5 bits specifies the bit
+ * in the 32bit element. The higher 7 bit val specifies VFTA array index.
+ */
+#define HINIC3_VFTA_BIT(vlan_id) (1 << ((vlan_id) & 0x1F))
+/**
+ * Get the VFTA index from the upper 7 bits of the VLAN ID.
+ */
+#define HINIC3_VFTA_IDX(vlan_id) ((vlan_id) >> 5)
+
+#define HINIC3_LRO_DEFAULT_TIME_LIMIT 16
+#define HINIC3_LRO_UNIT_WQE_SIZE      1024 /**< Bytes. */
+
+#define HINIC3_MAX_RX_PKT_LEN(rxmod) ((rxmod).mtu)
+int hinic3_logtype; /**< Driver-specific log messages type. */
+
+/**
+ * The different receive modes for the NIC.
+ *
+ * The receive modes are represented as bit flags that control how the
+ * NIC handles various types of network traffic.
+ */
+enum hinic3_rx_mod {
+	/* Enable unicast receive mode. */
+	HINIC3_RX_MODE_UC = 1 << 0,
+	/* Enable multicast receive mode. */
+	HINIC3_RX_MODE_MC = 1 << 1,
+	/* Enable broadcast receive mode. */
+	HINIC3_RX_MODE_BC = 1 << 2,
+	/* Enable receive mode for all multicast addresses. */
+	HINIC3_RX_MODE_MC_ALL = 1 << 3,
+	/* Enable promiscuous mode, receiving all packets. */
+	HINIC3_RX_MODE_PROMISC = 1 << 4,
+};
+
+#define HINIC3_DEFAULT_RX_MODE \
+	(HINIC3_RX_MODE_UC | HINIC3_RX_MODE_MC | HINIC3_RX_MODE_BC)
+
+struct hinic3_xstats_name_off {
+	char name[RTE_ETH_XSTATS_NAME_SIZE];
+	u32 offset;
+};
+
+#define HINIC3_FUNC_STAT(_stat_item)                                       \
+	{                                                                  \
+		.name = #_stat_item,                                       \
+		.offset = offsetof(struct hinic3_vport_stats, _stat_item), \
+	}
+
+static const struct hinic3_xstats_name_off hinic3_vport_stats_strings[] = {
+	HINIC3_FUNC_STAT(tx_unicast_pkts_vport),
+	HINIC3_FUNC_STAT(tx_unicast_bytes_vport),
+	HINIC3_FUNC_STAT(tx_multicast_pkts_vport),
+	HINIC3_FUNC_STAT(tx_multicast_bytes_vport),
+	HINIC3_FUNC_STAT(tx_broadcast_pkts_vport),
+	HINIC3_FUNC_STAT(tx_broadcast_bytes_vport),
+
+	HINIC3_FUNC_STAT(rx_unicast_pkts_vport),
+	HINIC3_FUNC_STAT(rx_unicast_bytes_vport),
+	HINIC3_FUNC_STAT(rx_multicast_pkts_vport),
+	HINIC3_FUNC_STAT(rx_multicast_bytes_vport),
+	HINIC3_FUNC_STAT(rx_broadcast_pkts_vport),
+	HINIC3_FUNC_STAT(rx_broadcast_bytes_vport),
+
+	HINIC3_FUNC_STAT(tx_discard_vport),
+	HINIC3_FUNC_STAT(rx_discard_vport),
+	HINIC3_FUNC_STAT(tx_err_vport),
+	HINIC3_FUNC_STAT(rx_err_vport),
+};
+
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
+
+#define HINIC3_VPORT_XSTATS_NUM ARRAY_SIZE(hinic3_vport_stats_strings)
+
+#define HINIC3_PORT_STAT(_stat_item)                                       \
+	{                                                                  \
+		.name = #_stat_item,                                       \
+		.offset = offsetof(struct mag_phy_port_stats, _stat_item), \
+	}
+
+static const struct hinic3_xstats_name_off hinic3_phyport_stats_strings[] = {
+	HINIC3_PORT_STAT(mac_tx_fragment_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_undersize_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_undermin_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_64_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_65_127_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_128_255_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_256_511_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_512_1023_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_1024_1518_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_1519_2047_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_2048_4095_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_4096_8191_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_8192_9216_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_9217_12287_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_12288_16383_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_1519_max_bad_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_1519_max_good_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_oversize_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_jabber_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_bad_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_bad_oct_num),
+	HINIC3_PORT_STAT(mac_tx_good_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_good_oct_num),
+	HINIC3_PORT_STAT(mac_tx_total_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_total_oct_num),
+	HINIC3_PORT_STAT(mac_tx_uni_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_multi_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_broad_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pause_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri0_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri1_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri2_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri3_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri4_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri5_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri6_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_pfc_pri7_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_control_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_err_all_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_from_app_good_pkt_num),
+	HINIC3_PORT_STAT(mac_tx_from_app_bad_pkt_num),
+
+	HINIC3_PORT_STAT(mac_rx_fragment_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_undersize_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_undermin_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_64_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_65_127_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_128_255_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_256_511_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_512_1023_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_1024_1518_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_1519_2047_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_2048_4095_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_4096_8191_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_8192_9216_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_9217_12287_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_12288_16383_oct_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_1519_max_bad_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_1519_max_good_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_oversize_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_jabber_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_bad_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_bad_oct_num),
+	HINIC3_PORT_STAT(mac_rx_good_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_good_oct_num),
+	HINIC3_PORT_STAT(mac_rx_total_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_total_oct_num),
+	HINIC3_PORT_STAT(mac_rx_uni_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_multi_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_broad_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pause_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri0_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri1_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri2_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri3_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri4_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri5_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri6_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_pfc_pri7_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_control_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_sym_err_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_fcs_err_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_send_app_good_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_send_app_bad_pkt_num),
+	HINIC3_PORT_STAT(mac_rx_unfilter_pkt_num),
+};
+
+#define HINIC3_PHYPORT_XSTATS_NUM ARRAY_SIZE(hinic3_phyport_stats_strings)
+
+#define HINIC3_RXQ_STAT(_stat_item)                                      \
+	{                                                                \
+		.name = #_stat_item,                                     \
+		.offset = offsetof(struct hinic3_rxq_stats, _stat_item), \
+	}
+
+/**
+ * The name and offset field of RXQ statistic items.
+ *
+ * The inclusion of additional statistics depends on the compilation flags:
+ * - `HINIC3_XSTAT_RXBUF_INFO` enables buffer-related stats.
+ * - `HINIC3_XSTAT_PROF_RX` enables performance timing stats.
+ * - `HINIC3_XSTAT_MBUF_USE` enables memory buffer usage stats.
+ */
+static const struct hinic3_xstats_name_off hinic3_rxq_stats_strings[] = {
+	HINIC3_RXQ_STAT(rx_nombuf),
+	HINIC3_RXQ_STAT(burst_pkts),
+	HINIC3_RXQ_STAT(errors),
+	HINIC3_RXQ_STAT(csum_errors),
+	HINIC3_RXQ_STAT(other_errors),
+	HINIC3_RXQ_STAT(empty),
+
+#ifdef HINIC3_XSTAT_RXBUF_INFO
+	HINIC3_RXQ_STAT(rx_mbuf),
+	HINIC3_RXQ_STAT(rx_avail),
+	HINIC3_RXQ_STAT(rx_hole),
+#endif
+
+#ifdef HINIC3_XSTAT_PROF_RX
+	HINIC3_RXQ_STAT(app_tsc),
+	HINIC3_RXQ_STAT(pmd_tsc),
+#endif
+
+#ifdef HINIC3_XSTAT_MBUF_USE
+	HINIC3_RXQ_STAT(rx_alloc_mbuf_bytes),
+	HINIC3_RXQ_STAT(rx_free_mbuf_bytes),
+	HINIC3_RXQ_STAT(rx_left_mbuf_bytes),
+#endif
+};
+
+#define HINIC3_RXQ_XSTATS_NUM ARRAY_SIZE(hinic3_rxq_stats_strings)
+
+#define HINIC3_TXQ_STAT(_stat_item)                                      \
+	{                                                                \
+		.name = #_stat_item,                                     \
+		.offset = offsetof(struct hinic3_txq_stats, _stat_item), \
+	}
+
+/**
+ * The name and offset field of TXQ statistic items.
+ *
+ * The inclusion of additional statistics depends on the compilation flags:
+ * - `HINIC3_XSTAT_PROF_TX` enables performance timing stats.
+ * - `HINIC3_XSTAT_MBUF_USE` enables memory buffer usage stats.
+ */
+static const struct hinic3_xstats_name_off hinic3_txq_stats_strings[] = {
+	HINIC3_TXQ_STAT(tx_busy),
+	HINIC3_TXQ_STAT(offload_errors),
+	HINIC3_TXQ_STAT(burst_pkts),
+	HINIC3_TXQ_STAT(sge_len0),
+	HINIC3_TXQ_STAT(mbuf_null),
+
+#ifdef HINIC3_XSTAT_PROF_TX
+	HINIC3_TXQ_STAT(app_tsc),
+	HINIC3_TXQ_STAT(pmd_tsc),
+#endif
+
+#ifdef HINIC3_XSTAT_MBUF_USE
+	HINIC3_TXQ_STAT(tx_left_mbuf_bytes),
+#endif
+};
+
+#define HINIC3_TXQ_XSTATS_NUM ARRAY_SIZE(hinic3_txq_stats_strings)
+
+static int
+hinic3_xstats_calc_num(struct hinic3_nic_dev *nic_dev)
+{
+	if (HINIC3_IS_VF(nic_dev->hwdev)) {
+		return (HINIC3_VPORT_XSTATS_NUM +
+			HINIC3_RXQ_XSTATS_NUM * nic_dev->num_rqs +
+			HINIC3_TXQ_XSTATS_NUM * nic_dev->num_sqs);
+	} else {
+		return (HINIC3_VPORT_XSTATS_NUM + HINIC3_PHYPORT_XSTATS_NUM +
+			HINIC3_RXQ_XSTATS_NUM * nic_dev->num_rqs +
+			HINIC3_TXQ_XSTATS_NUM * nic_dev->num_sqs);
+	}
+}
+
+#define HINIC3_MAX_QUEUE_DEPTH 16384
+#define HINIC3_MIN_QUEUE_DEPTH 128
+#define HINIC3_TXD_ALIGN       1
+#define HINIC3_RXD_ALIGN       1
+
+static const struct rte_eth_desc_lim hinic3_rx_desc_lim = {
+	.nb_max = HINIC3_MAX_QUEUE_DEPTH,
+	.nb_min = HINIC3_MIN_QUEUE_DEPTH,
+	.nb_align = HINIC3_RXD_ALIGN,
+};
+
+static const struct rte_eth_desc_lim hinic3_tx_desc_lim = {
+	.nb_max = HINIC3_MAX_QUEUE_DEPTH,
+	.nb_min = HINIC3_MIN_QUEUE_DEPTH,
+	.nb_align = HINIC3_TXD_ALIGN,
+};
+
+static void hinic3_deinit_mac_addr(struct rte_eth_dev *eth_dev);
+
+static int hinic3_copy_mempool_init(struct hinic3_nic_dev *nic_dev);
+
+static void hinic3_copy_mempool_uninit(struct hinic3_nic_dev *nic_dev);
+
+/**
+ * Interrupt handler triggered by NIC for handling specific event.
+ *
+ * @param[in] param
+ * The address of parameter (struct rte_eth_dev *) registered before.
+ */
+static void
+hinic3_dev_interrupt_handler(void *param)
+{
+	struct rte_eth_dev *dev = param;
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+	if (!hinic3_get_bit(HINIC3_DEV_INTR_EN, &nic_dev->dev_status)) {
+		PMD_DRV_LOG(WARNING,
+			    "Intr is disabled, ignore intr event, "
+			    "dev_name: %s, port_id: %d",
+			    nic_dev->dev_name, dev->data->port_id);
+		return;
+	}
+
+	/* Aeq0 msg handler. */
+	hinic3_dev_handle_aeq_event(nic_dev->hwdev, param);
+}
+
+/**
+ * Do the config for TX/Rx queues, include queue number, mtu size and RSS.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_configure(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+	nic_dev->num_sqs = dev->data->nb_tx_queues;
+	nic_dev->num_rqs = dev->data->nb_rx_queues;
+
+	if (nic_dev->num_sqs > nic_dev->max_sqs ||
+	    nic_dev->num_rqs > nic_dev->max_rqs) {
+		PMD_DRV_LOG(ERR,
+			    "num_sqs: %d or num_rqs: %d larger than "
+			    "max_sqs: %d or max_rqs: %d",
+			    nic_dev->num_sqs, nic_dev->num_rqs,
+			    nic_dev->max_sqs, nic_dev->max_rqs);
+		return -EINVAL;
+	}
+
+	/* The range of mtu is 384~9600. */
+
+	if (HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode) <
+		    HINIC3_MIN_FRAME_SIZE ||
+	    HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode) >
+		    HINIC3_MAX_JUMBO_FRAME_SIZE) {
+		PMD_DRV_LOG(ERR,
+			    "Max rx pkt len out of range, max_rx_pkt_len: %d, "
+			    "expect between %d and %d",
+			    HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode),
+			    HINIC3_MIN_FRAME_SIZE, HINIC3_MAX_JUMBO_FRAME_SIZE);
+		return -EINVAL;
+	}
+	nic_dev->mtu_size =
+		(u16)HINIC3_PKTLEN_TO_MTU(HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode));
+	if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
+		dev->data->dev_conf.rxmode.offloads |=
+			RTE_ETH_RX_OFFLOAD_RSS_HASH;
+
+	/* Clear fdir filter. */
+	hinic3_free_fdir_filter(dev);
+
+	return 0;
+}
+
+/**
+ * Get information about the device.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[out] info
+ * Info structure for ethernet device.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+	info->max_rx_queues = nic_dev->max_rqs;
+	info->max_tx_queues = nic_dev->max_sqs;
+	info->min_rx_bufsize = HINIC3_MIN_RX_BUF_SIZE;
+	info->max_rx_pktlen = HINIC3_MAX_JUMBO_FRAME_SIZE;
+	info->max_mac_addrs = HINIC3_MAX_UC_MAC_ADDRS;
+	info->min_mtu = HINIC3_MIN_MTU_SIZE;
+	info->max_mtu = HINIC3_MAX_MTU_SIZE;
+	info->max_lro_pkt_size = HINIC3_MAX_LRO_SIZE;
+
+	info->rx_queue_offload_capa = 0;
+	info->rx_offload_capa =
+		RTE_ETH_RX_OFFLOAD_VLAN_STRIP | RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
+		RTE_ETH_RX_OFFLOAD_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
+		RTE_ETH_RX_OFFLOAD_SCTP_CKSUM | RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
+		RTE_ETH_RX_OFFLOAD_SCATTER | RTE_ETH_RX_OFFLOAD_TCP_LRO |
+		RTE_ETH_RX_OFFLOAD_RSS_HASH;
+
+	info->tx_queue_offload_capa = 0;
+	info->tx_offload_capa =
+		RTE_ETH_TX_OFFLOAD_VLAN_INSERT | RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
+		RTE_ETH_TX_OFFLOAD_UDP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
+		RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
+		RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
+		RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
+
+	info->hash_key_size = HINIC3_RSS_KEY_SIZE;
+	info->reta_size = HINIC3_RSS_INDIR_SIZE;
+	info->flow_type_rss_offloads = HINIC3_RSS_OFFLOAD_ALL;
+
+	info->rx_desc_lim = hinic3_rx_desc_lim;
+	info->tx_desc_lim = hinic3_tx_desc_lim;
+
+	/* Driver-preferred rx/tx parameters. */
+	info->default_rxportconf.burst_size = HINIC3_DEFAULT_BURST_SIZE;
+	info->default_txportconf.burst_size = HINIC3_DEFAULT_BURST_SIZE;
+	info->default_rxportconf.nb_queues = HINIC3_DEFAULT_NB_QUEUES;
+	info->default_txportconf.nb_queues = HINIC3_DEFAULT_NB_QUEUES;
+	info->default_rxportconf.ring_size = HINIC3_DEFAULT_RING_SIZE;
+	info->default_txportconf.ring_size = HINIC3_DEFAULT_RING_SIZE;
+
+	return 0;
+}
+
+static int
+hinic3_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	char mgmt_ver[MGMT_VERSION_MAX_LEN] = {0};
+	int err;
+
+	err = hinic3_get_mgmt_version(nic_dev->hwdev, mgmt_ver,
+				      HINIC3_MGMT_VERSION_MAX_LEN);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Get fw version failed");
+		return -EIO;
+	}
+
+	if (fw_size < strlen((char *)mgmt_ver) + 1)
+		return (strlen((char *)mgmt_ver) + 1);
+
+	snprintf(fw_version, fw_size, "%s", mgmt_ver);
+
+	return 0;
+}
+
+/**
+ * Set ethernet device link state up.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_set_link_up(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int err;
+
+	/*
+	 * Vport enable will set function valid in mpu.
+	 * So dev start status need to be checked before vport enable.
+	 */
+	if (hinic3_get_bit(HINIC3_DEV_START, &nic_dev->dev_status)) {
+		err = hinic3_set_vport_enable(nic_dev->hwdev, true);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Enable vport failed, dev_name: %s",
+				    nic_dev->dev_name);
+			return err;
+		}
+	}
+
+	/* Link status follow phy port status, mpu will open pma. */
+	err = hinic3_set_port_enable(nic_dev->hwdev, true);
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			    "Set MAC link up failed, dev_name: %s, port_id: %d",
+			    nic_dev->dev_name, dev->data->port_id);
+		return err;
+	}
+
+	return 0;
+}
+
+/**
+ * Set ethernet device link state down.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_set_link_down(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int err;
+
+	err = hinic3_set_vport_enable(nic_dev->hwdev, false);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Disable vport failed, dev_name: %s",
+			    nic_dev->dev_name);
+		return err;
+	}
+
+	/* Link status follow phy port status, mpu will close pma. */
+	err = hinic3_set_port_enable(nic_dev->hwdev, false);
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			"Set MAC link down failed, dev_name: %s, port_id: %d",
+			nic_dev->dev_name, dev->data->port_id);
+		return err;
+	}
+
+	return 0;
+}
+
+/**
+ * Get device physical link information.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] wait_to_complete
+ * Wait for request completion.
+ *
+ * @return
+ * 0 : Link status changed
+ * -1 : Link status not changed.
+ */
+static int
+hinic3_link_update(struct rte_eth_dev *dev, int wait_to_complete)
+{
+#define CHECK_INTERVAL	10  /**< 10ms. */
+#define MAX_REPEAT_TIME 100 /**< 1s (100 * 10ms) in total. */
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct rte_eth_link link;
+	u8 link_state;
+	unsigned int rep_cnt = MAX_REPEAT_TIME;
+	int ret;
+
+	memset(&link, 0, sizeof(link));
+	do {
+		/* Get link status information from hardware. */
+		ret = hinic3_get_link_state(nic_dev->hwdev, &link_state);
+		if (ret) {
+			link.link_status = RTE_ETH_LINK_DOWN;
+			link.link_speed = RTE_ETH_SPEED_NUM_NONE;
+			link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
+			link.link_autoneg = RTE_ETH_LINK_FIXED;
+			goto out;
+		}
+
+		get_port_info(nic_dev->hwdev, link_state, &link);
+
+		if (!wait_to_complete || link.link_status)
+			break;
+
+		rte_delay_ms(CHECK_INTERVAL);
+	} while (rep_cnt--);
+
+out:
+	return rte_eth_linkstatus_set(dev, &link);
+}
+
+/**
+ * Reset all RX queues (RXQs).
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ */
+static void
+hinic3_reset_rx_queue(struct rte_eth_dev *dev)
+{
+	struct hinic3_rxq *rxq = NULL;
+	struct hinic3_nic_dev *nic_dev;
+	int q_id = 0;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+	for (q_id = 0; q_id < nic_dev->num_rqs; q_id++) {
+		rxq = nic_dev->rxqs[q_id];
+
+		rxq->cons_idx = 0;
+		rxq->prod_idx = 0;
+		rxq->delta = rxq->q_depth;
+		rxq->next_to_update = 0;
+	}
+}
+
+/**
+ * Reset all TX queues (TXQs).
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ */
+static void
+hinic3_reset_tx_queue(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev;
+	struct hinic3_txq *txq = NULL;
+	int q_id = 0;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+	for (q_id = 0; q_id < nic_dev->num_sqs; q_id++) {
+		txq = nic_dev->txqs[q_id];
+
+		txq->cons_idx = 0;
+		txq->prod_idx = 0;
+		txq->owner = 1;
+
+		/* Clear hardware ci. */
+		*txq->ci_vaddr_base = 0;
+	}
+}
+
+/**
+ * Create the receive queue.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] qid
+ * Receive queue index.
+ * @param[in] nb_desc
+ * Number of descriptors for receive queue.
+ * @param[in] socket_id
+ * Socket index on which memory must be allocated.
+ * @param[in] rx_conf
+ * Thresholds parameters (unused_).
+ * @param[in] mp
+ * Memory pool for buffer allocations.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qid, uint16_t nb_desc,
+		      unsigned int socket_id,
+		      __rte_unused const struct rte_eth_rxconf *rx_conf,
+		      struct rte_mempool *mp)
+{
+	struct hinic3_nic_dev *nic_dev;
+	struct hinic3_rxq *rxq = NULL;
+	const struct rte_memzone *rq_mz = NULL;
+	const struct rte_memzone *cqe_mz = NULL;
+	const struct rte_memzone *pi_mz = NULL;
+	u16 rq_depth, rx_free_thresh;
+	u32 queue_buf_size;
+	void *db_addr = NULL;
+	int wqe_count;
+	u32 buf_size;
+	int err;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+
+	/* Queue depth must be power of 2, otherwise will be aligned up. */
+	rq_depth = (nb_desc & (nb_desc - 1))
+			   ? ((u16)(1U << (ilog2(nb_desc) + 1)))
+			   : nb_desc;
+
+	/*
+	 * Validate number of receive descriptors.
+	 * It must not exceed hardware maximum and minimum.
+	 */
+	if (rq_depth > HINIC3_MAX_QUEUE_DEPTH ||
+	    rq_depth < HINIC3_MIN_QUEUE_DEPTH) {
+		PMD_DRV_LOG(ERR,
+			    "RX queue depth is out of range from %d to %d,"
+			    "(nb_desc: %d, q_depth: %d, port: %d queue: %d)",
+			    HINIC3_MIN_QUEUE_DEPTH, HINIC3_MAX_QUEUE_DEPTH,
+			    (int)nb_desc, (int)rq_depth,
+			    (int)dev->data->port_id, (int)qid);
+		return -EINVAL;
+	}
+
+	/*
+	 * The RX descriptor ring will be cleaned after rxq->rx_free_thresh
+	 * descriptors are used or if the number of descriptors required
+	 * to transmit a packet is greater than the number of free RX
+	 * descriptors.
+	 * The following constraints must be satisfied:
+	 * - rx_free_thresh must be greater than 0.
+	 * - rx_free_thresh must be less than the size of the ring minus 1.
+	 * When set to zero use default values.
+	 */
+	rx_free_thresh = (u16)((rx_conf->rx_free_thresh)
+				       ? rx_conf->rx_free_thresh
+				       : HINIC3_DEFAULT_RX_FREE_THRESH);
+	if (rx_free_thresh >= (rq_depth - 1)) {
+		PMD_DRV_LOG(ERR,
+			    "rx_free_thresh must be less than the number "
+			    "of RX descriptors minus 1, rx_free_thresh: %u "
+			    "port: %d queue: %d)",
+			    (unsigned int)rx_free_thresh,
+			    (int)dev->data->port_id, (int)qid);
+
+		return -EINVAL;
+	}
+
+	rxq = rte_zmalloc_socket("hinic3_rq", sizeof(struct hinic3_rxq),
+				 RTE_CACHE_LINE_SIZE, (int)socket_id);
+	if (!rxq) {
+		PMD_DRV_LOG(ERR, "Allocate rxq[%d] failed, dev_name: %s", qid,
+			    dev->data->name);
+
+		return -ENOMEM;
+	}
+
+	/* Init rq parameters. */
+	rxq->nic_dev = nic_dev;
+	nic_dev->rxqs[qid] = rxq;
+	rxq->mb_pool = mp;
+	rxq->q_id = qid;
+	rxq->next_to_update = 0;
+	rxq->q_depth = rq_depth;
+	rxq->q_mask = rq_depth - 1;
+	rxq->delta = rq_depth;
+	rxq->cons_idx = 0;
+	rxq->prod_idx = 0;
+	rxq->rx_free_thresh = rx_free_thresh;
+	rxq->rxinfo_align_end = rxq->q_depth - rxq->rx_free_thresh;
+	rxq->port_id = dev->data->port_id;
+	rxq->wait_time_cycle = HINIC3_RX_WAIT_CYCLE_THRESH;
+
+	/* If buf_len used for function table, need to translated. */
+	u16 rx_buf_size =
+		rte_pktmbuf_data_room_size(rxq->mb_pool) - RTE_PKTMBUF_HEADROOM;
+	err = hinic3_convert_rx_buf_size(rx_buf_size, &buf_size);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Adjust buf size failed, dev_name: %s",
+			    dev->data->name);
+		goto adjust_bufsize_fail;
+	}
+
+	if (buf_size >= HINIC3_RX_BUF_SIZE_4K &&
+	    buf_size < HINIC3_RX_BUF_SIZE_16K)
+		rxq->wqe_type = HINIC3_EXTEND_RQ_WQE;
+	else
+		rxq->wqe_type = HINIC3_NORMAL_RQ_WQE;
+
+	rxq->wqebb_shift = HINIC3_RQ_WQEBB_SHIFT + rxq->wqe_type;
+	rxq->wqebb_size = (u16)BIT(rxq->wqebb_shift);
+
+	rxq->buf_len = (u16)buf_size;
+	rxq->rx_buff_shift = ilog2(rxq->buf_len);
+
+	pi_mz = hinic3_dma_zone_reserve(dev, "hinic3_rq_pi", qid, RTE_PGSIZE_4K,
+					RTE_CACHE_LINE_SIZE, (int)socket_id);
+	if (!pi_mz) {
+		PMD_DRV_LOG(ERR, "Allocate rxq[%d] pi_mz failed, dev_name: %s",
+			    qid, dev->data->name);
+		err = -ENOMEM;
+		goto alloc_pi_mz_fail;
+	}
+	rxq->pi_mz = pi_mz;
+	rxq->pi_dma_addr = pi_mz->iova;
+	rxq->pi_virt_addr = pi_mz->addr;
+
+	err = hinic3_alloc_db_addr(nic_dev->hwdev, &db_addr, HINIC3_DB_TYPE_RQ);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Alloc rq doorbell addr failed");
+		goto alloc_db_err_fail;
+	}
+	rxq->db_addr = db_addr;
+
+	queue_buf_size = BIT(rxq->wqebb_shift) * rq_depth;
+	rq_mz = hinic3_dma_zone_reserve(dev, "hinic3_rq_mz", qid,
+					queue_buf_size, RTE_PGSIZE_256K,
+					(int)socket_id);
+	if (!rq_mz) {
+		PMD_DRV_LOG(ERR, "Allocate rxq[%d] rq_mz failed, dev_name: %s",
+			    qid, dev->data->name);
+		err = -ENOMEM;
+		goto alloc_rq_mz_fail;
+	}
+
+	memset(rq_mz->addr, 0, queue_buf_size);
+	rxq->rq_mz = rq_mz;
+	rxq->queue_buf_paddr = rq_mz->iova;
+	rxq->queue_buf_vaddr = rq_mz->addr;
+
+	rxq->rx_info = rte_zmalloc_socket("rx_info",
+					  rq_depth * sizeof(*rxq->rx_info),
+					  RTE_CACHE_LINE_SIZE, (int)socket_id);
+	if (!rxq->rx_info) {
+		PMD_DRV_LOG(ERR, "Allocate rx_info failed, dev_name: %s",
+			    dev->data->name);
+		err = -ENOMEM;
+		goto alloc_rx_info_fail;
+	}
+
+	cqe_mz = hinic3_dma_zone_reserve(dev, "hinic3_cqe_mz", qid,
+					 rq_depth * sizeof(*rxq->rx_cqe),
+					 RTE_CACHE_LINE_SIZE, (int)socket_id);
+	if (!cqe_mz) {
+		PMD_DRV_LOG(ERR, "Allocate cqe mem zone failed, dev_name: %s",
+			    dev->data->name);
+		err = -ENOMEM;
+		goto alloc_cqe_mz_fail;
+	}
+	memset(cqe_mz->addr, 0, rq_depth * sizeof(*rxq->rx_cqe));
+	rxq->cqe_mz = cqe_mz;
+	rxq->cqe_start_paddr = cqe_mz->iova;
+	rxq->cqe_start_vaddr = cqe_mz->addr;
+	rxq->rx_cqe = (struct hinic3_rq_cqe *)rxq->cqe_start_vaddr;
+
+	wqe_count = hinic3_rx_fill_wqe(rxq);
+	if (wqe_count != rq_depth) {
+		PMD_DRV_LOG(ERR,
+			    "Fill rx wqe failed, wqe_count: %d, dev_name: %s",
+			    wqe_count, dev->data->name);
+		err = -ENOMEM;
+		goto fill_rx_wqe_fail;
+	}
+	/* Record rxq pointer in rte_eth rx_queues. */
+	dev->data->rx_queues[qid] = rxq;
+
+	return 0;
+
+fill_rx_wqe_fail:
+	hinic3_memzone_free(rxq->cqe_mz);
+alloc_cqe_mz_fail:
+	rte_free(rxq->rx_info);
+
+alloc_rx_info_fail:
+	hinic3_memzone_free(rxq->rq_mz);
+
+alloc_rq_mz_fail:
+alloc_db_err_fail:
+	hinic3_memzone_free(rxq->pi_mz);
+
+alloc_pi_mz_fail:
+adjust_bufsize_fail:
+	rte_free(rxq);
+	nic_dev->rxqs[qid] = NULL;
+
+	return err;
+}
+
+/**
+ * Create the transmit queue.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] queue_idx
+ * Transmit queue index.
+ * @param[in] nb_desc
+ * Number of descriptors for transmit queue.
+ * @param[in] socket_id
+ * Socket index on which memory must be allocated.
+ * @param[in] tx_conf
+ * Tx queue configuration parameters (unused_).
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qid, uint16_t nb_desc,
+		      unsigned int socket_id,
+		      __rte_unused const struct rte_eth_txconf *tx_conf)
+{
+	struct hinic3_nic_dev *nic_dev;
+	struct hinic3_hwdev *hwdev;
+	struct hinic3_txq *txq = NULL;
+	const struct rte_memzone *sq_mz = NULL;
+	const struct rte_memzone *ci_mz = NULL;
+	void *db_addr = NULL;
+	u16 sq_depth, tx_free_thresh;
+	u32 queue_buf_size;
+	int err;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	hwdev = nic_dev->hwdev;
+
+	/* Queue depth must be power of 2, otherwise will be aligned up. */
+	sq_depth = (nb_desc & (nb_desc - 1))
+			   ? ((u16)(1U << (ilog2(nb_desc) + 1)))
+			   : nb_desc;
+
+	/*
+	 * Validate number of transmit descriptors.
+	 * It must not exceed hardware maximum and minimum.
+	 */
+	if (sq_depth > HINIC3_MAX_QUEUE_DEPTH ||
+	    sq_depth < HINIC3_MIN_QUEUE_DEPTH) {
+		PMD_DRV_LOG(ERR,
+			    "TX queue depth is out of range from %d to %d,"
+			    "(nb_desc: %d, q_depth: %d, port: %d queue: %d)",
+			    HINIC3_MIN_QUEUE_DEPTH, HINIC3_MAX_QUEUE_DEPTH,
+			    (int)nb_desc, (int)sq_depth,
+			    (int)dev->data->port_id, (int)qid);
+		return -EINVAL;
+	}
+
+	/*
+	 * The TX descriptor ring will be cleaned after txq->tx_free_thresh
+	 * descriptors are used or if the number of descriptors required
+	 * to transmit a packet is greater than the number of free TX
+	 * descriptors.
+	 * The following constraints must be satisfied:
+	 * - tx_free_thresh must be greater than 0.
+	 * - tx_free_thresh must be less than the size of the ring minus 1.
+	 * When set to zero use default values.
+	 */
+	tx_free_thresh = (u16)((tx_conf->tx_free_thresh)
+				       ? tx_conf->tx_free_thresh
+				       : HINIC3_DEFAULT_TX_FREE_THRESH);
+	if (tx_free_thresh >= (sq_depth - 1)) {
+		PMD_DRV_LOG(ERR,
+			    "tx_free_thresh must be less than the number of tx "
+			    "descriptors minus 1, tx_free_thresh: %u port: %d "
+			    "queue: %d",
+			    (unsigned int)tx_free_thresh,
+			    (int)dev->data->port_id, (int)qid);
+		return -EINVAL;
+	}
+
+	txq = rte_zmalloc_socket("hinic3_tx_queue", sizeof(struct hinic3_txq),
+				 RTE_CACHE_LINE_SIZE, (int)socket_id);
+	if (!txq) {
+		PMD_DRV_LOG(ERR, "Allocate txq[%d] failed, dev_name: %s", qid,
+			    dev->data->name);
+		return -ENOMEM;
+	}
+	nic_dev->txqs[qid] = txq;
+	txq->nic_dev = nic_dev;
+	txq->q_id = qid;
+	txq->q_depth = sq_depth;
+	txq->q_mask = sq_depth - 1;
+	txq->cons_idx = 0;
+	txq->prod_idx = 0;
+	txq->wqebb_shift = HINIC3_SQ_WQEBB_SHIFT;
+	txq->wqebb_size = (u16)BIT(txq->wqebb_shift);
+	txq->tx_free_thresh = tx_free_thresh;
+	txq->owner = 1;
+	txq->cos = nic_dev->default_cos;
+
+	ci_mz = hinic3_dma_zone_reserve(dev, "hinic3_sq_ci", qid,
+					HINIC3_CI_Q_ADDR_SIZE,
+					HINIC3_CI_Q_ADDR_SIZE, (int)socket_id);
+	if (!ci_mz) {
+		PMD_DRV_LOG(ERR, "Allocate txq[%d] ci_mz failed, dev_name: %s",
+			    qid, dev->data->name);
+		err = -ENOMEM;
+		goto alloc_ci_mz_fail;
+	}
+	txq->ci_mz = ci_mz;
+	txq->ci_dma_base = ci_mz->iova;
+	txq->ci_vaddr_base = (volatile u16 *)ci_mz->addr;
+
+	queue_buf_size = BIT(txq->wqebb_shift) * sq_depth;
+	sq_mz = hinic3_dma_zone_reserve(dev, "hinic3_sq_mz", qid,
+					queue_buf_size, RTE_PGSIZE_256K,
+					(int)socket_id);
+	if (!sq_mz) {
+		PMD_DRV_LOG(ERR, "Allocate txq[%d] sq_mz failed, dev_name: %s",
+			    qid, dev->data->name);
+		err = -ENOMEM;
+		goto alloc_sq_mz_fail;
+	}
+	memset(sq_mz->addr, 0, queue_buf_size);
+	txq->sq_mz = sq_mz;
+	txq->queue_buf_paddr = sq_mz->iova;
+	txq->queue_buf_vaddr = sq_mz->addr;
+	txq->sq_head_addr = (u64)txq->queue_buf_vaddr;
+	txq->sq_bot_sge_addr = txq->sq_head_addr + queue_buf_size;
+
+	err = hinic3_alloc_db_addr(hwdev, &db_addr, HINIC3_DB_TYPE_SQ);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Alloc sq doorbell addr failed");
+		goto alloc_db_err_fail;
+	}
+	txq->db_addr = db_addr;
+
+	txq->tx_info = rte_zmalloc_socket("tx_info",
+					  sq_depth * sizeof(*txq->tx_info),
+					  RTE_CACHE_LINE_SIZE, (int)socket_id);
+	if (!txq->tx_info) {
+		PMD_DRV_LOG(ERR, "Allocate tx_info failed, dev_name: %s",
+			    dev->data->name);
+		err = -ENOMEM;
+		goto alloc_tx_info_fail;
+	}
+
+	/* Record txq pointer in rte_eth tx_queues. */
+	dev->data->tx_queues[qid] = txq;
+
+	return 0;
+
+alloc_tx_info_fail:
+alloc_db_err_fail:
+	hinic3_memzone_free(txq->sq_mz);
+
+alloc_sq_mz_fail:
+	hinic3_memzone_free(txq->ci_mz);
+
+alloc_ci_mz_fail:
+	rte_free(txq);
+	return err;
+}
+
+static void
+hinic3_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
+{
+	if (dev == NULL || dev->data == NULL || dev->data->rx_queues == NULL) {
+		PMD_DRV_LOG(WARNING, "rx queue is null when release");
+		return;
+	}
+	if (queue_id >= dev->data->nb_rx_queues) {
+		PMD_DRV_LOG(WARNING, "eth_dev: %s, rx queue id: %u is illegal",
+			    dev->data->name, queue_id);
+		return;
+	}
+	struct hinic3_rxq *rxq = dev->data->rx_queues[queue_id];
+	struct hinic3_nic_dev *nic_dev = NULL;
+
+	if (!rxq) {
+		PMD_DRV_LOG(WARNING, "Rxq is null when release");
+		return;
+	}
+
+	nic_dev = rxq->nic_dev;
+
+	hinic3_free_rxq_mbufs(rxq);
+
+	hinic3_memzone_free(rxq->cqe_mz);
+
+	rte_free(rxq->rx_info);
+	rxq->rx_info = NULL;
+
+	hinic3_memzone_free(rxq->rq_mz);
+
+	hinic3_memzone_free(rxq->pi_mz);
+
+	nic_dev->rxqs[rxq->q_id] = NULL;
+	rte_free(rxq);
+	dev->data->rx_queues[queue_id] = NULL;
+}
+
+static void
+hinic3_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
+{
+	if (dev == NULL || dev->data == NULL || dev->data->tx_queues == NULL) {
+		PMD_DRV_LOG(WARNING, "tx queue is null when release");
+		return;
+	}
+	if (queue_id >= dev->data->nb_tx_queues) {
+		PMD_DRV_LOG(WARNING, "eth_dev: %s, tx queue id: %u is illegal",
+			    dev->data->name, queue_id);
+		return;
+	}
+	struct hinic3_txq *txq = dev->data->tx_queues[queue_id];
+	struct hinic3_nic_dev *nic_dev = NULL;
+
+	if (!txq) {
+		PMD_DRV_LOG(WARNING, "Txq is null when release");
+		return;
+	}
+	PMD_DRV_LOG(INFO, "%s txq_idx:%d queue release.",
+		    txq->nic_dev->dev_name, txq->q_id);
+	nic_dev = txq->nic_dev;
+
+	hinic3_free_txq_mbufs(txq);
+
+	rte_free(txq->tx_info);
+	txq->tx_info = NULL;
+
+	hinic3_memzone_free(txq->sq_mz);
+
+	hinic3_memzone_free(txq->ci_mz);
+
+	nic_dev->txqs[txq->q_id] = NULL;
+	rte_free(txq);
+	dev->data->tx_queues[queue_id] = NULL;
+}
+
+/**
+ * Start RXQ and enables flow director (fdir) filter for RXQ.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] rq_id
+ * RX queue ID to be started.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_rx_queue_start(__rte_unused struct rte_eth_dev *dev,
+			  __rte_unused uint16_t rq_id)
+{
+	struct hinic3_rxq *rxq = NULL;
+	int rc;
+
+	if (rq_id < dev->data->nb_rx_queues) {
+		rxq = dev->data->rx_queues[rq_id];
+
+		rc = hinic3_start_rq(dev, rxq);
+		if (rc) {
+			PMD_DRV_LOG(ERR,
+				    "Start rx queue failed, eth_dev:%s, "
+				    "queue_idx:%d",
+				    dev->data->name, rq_id);
+			return rc;
+		}
+
+		dev->data->rx_queue_state[rq_id] = RTE_ETH_QUEUE_STATE_STARTED;
+	}
+	rc = hinic3_enable_rxq_fdir_filter(dev, (u32)rq_id, (u32)true);
+	if (rc) {
+		PMD_DRV_LOG(ERR, "Failed to enable rq : %d fdir filter.",
+			    rq_id);
+		return rc;
+	}
+	return 0;
+}
+
+/**
+ * Stop RXQ and disable flow director (fdir) filter for RXQ.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] rq_id
+ * RX queue ID to be stopped.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_rx_queue_stop(__rte_unused struct rte_eth_dev *dev,
+			 __rte_unused uint16_t rq_id)
+{
+	struct hinic3_rxq *rxq = NULL;
+	int rc;
+
+	if (rq_id < dev->data->nb_rx_queues) {
+		rxq = dev->data->rx_queues[rq_id];
+
+		rc = hinic3_stop_rq(dev, rxq);
+		if (rc) {
+			PMD_DRV_LOG(ERR,
+				    "Stop rx queue failed, eth_dev:%s, "
+				    "queue_idx:%d",
+				    dev->data->name, rq_id);
+			return rc;
+		}
+
+		dev->data->rx_queue_state[rq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
+	}
+	rc = hinic3_enable_rxq_fdir_filter(dev, (u32)rq_id, (u32)false);
+	if (rc) {
+		PMD_DRV_LOG(ERR, "Failed to disable rq : %d fdir filter.",
+			    rq_id);
+		return rc;
+	}
+
+	return 0;
+}
+
+static int
+hinic3_dev_tx_queue_start(__rte_unused struct rte_eth_dev *dev,
+			  __rte_unused uint16_t sq_id)
+{
+	struct hinic3_txq *txq = NULL;
+
+	PMD_DRV_LOG(INFO, "Start tx queue, eth_dev:%s, queue_idx:%d",
+		    dev->data->name, sq_id);
+
+	txq = dev->data->tx_queues[sq_id];
+	HINIC3_SET_TXQ_STARTED(txq);
+	dev->data->tx_queue_state[sq_id] = RTE_ETH_QUEUE_STATE_STARTED;
+	return 0;
+}
+
+static int
+hinic3_dev_tx_queue_stop(__rte_unused struct rte_eth_dev *dev,
+			 __rte_unused uint16_t sq_id)
+{
+	struct hinic3_txq *txq = NULL;
+	int rc;
+
+	if (sq_id < dev->data->nb_tx_queues) {
+		txq = dev->data->tx_queues[sq_id];
+		rc = hinic3_stop_sq(txq);
+		if (rc) {
+			PMD_DRV_LOG(ERR,
+				    "Stop tx queue failed, eth_dev:%s, "
+				    "queue_idx:%d",
+				    dev->data->name, sq_id);
+			return rc;
+		}
+
+		HINIC3_SET_TXQ_STOPPED(txq);
+		dev->data->tx_queue_state[sq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
+	}
+
+	return 0;
+}
+
+int
+hinic3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
+{
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = PCI_DEV_TO_INTR_HANDLE(pci_dev);
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u16 msix_intr;
+
+	if (!rte_intr_dp_is_en(intr_handle) || !intr_handle->intr_vec)
+		return 0;
+
+	if (queue_id >= dev->data->nb_rx_queues)
+		return -EINVAL;
+
+	msix_intr = (u16)intr_handle->intr_vec[queue_id];
+	hinic3_set_msix_auto_mask_state(nic_dev->hwdev, msix_intr,
+					HINIC3_SET_MSIX_AUTO_MASK);
+	hinic3_set_msix_state(nic_dev->hwdev, msix_intr, HINIC3_MSIX_ENABLE);
+
+	return 0;
+}
+
+int
+hinic3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
+{
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+	struct rte_intr_handle *intr_handle = PCI_DEV_TO_INTR_HANDLE(pci_dev);
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u16 msix_intr;
+
+	if (!rte_intr_dp_is_en(intr_handle) || !intr_handle->intr_vec)
+		return 0;
+
+	if (queue_id >= dev->data->nb_rx_queues)
+		return -EINVAL;
+
+	msix_intr = (u16)intr_handle->intr_vec[queue_id];
+	hinic3_set_msix_auto_mask_state(nic_dev->hwdev, msix_intr,
+					HINIC3_CLR_MSIX_AUTO_MASK);
+	hinic3_set_msix_state(nic_dev->hwdev, msix_intr, HINIC3_MSIX_DISABLE);
+	hinic3_misx_intr_clear_resend_bit(nic_dev->hwdev, msix_intr,
+					  MSIX_RESEND_TIMER_CLEAR);
+
+	return 0;
+}
+
+static uint32_t
+hinic3_dev_rx_queue_count(__rte_unused void *rx_queue)
+{
+	return 0;
+}
+
+static int
+hinic3_dev_rx_descriptor_status(__rte_unused void *rx_queue,
+				__rte_unused uint16_t offset)
+{
+	return 0;
+}
+
+static int
+hinic3_dev_tx_descriptor_status(__rte_unused void *tx_queue,
+				__rte_unused uint16_t offset)
+{
+	return 0;
+}
+
+static int
+hinic3_set_lro(struct hinic3_nic_dev *nic_dev, struct rte_eth_conf *dev_conf)
+{
+	bool lro_en;
+	int max_lro_size, lro_max_pkt_len;
+	int err;
+
+	/* Config lro. */
+	lro_en = dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO ? true
+									: false;
+	max_lro_size = (int)(dev_conf->rxmode.max_lro_pkt_size);
+	/* `max_lro_size` is divisible by `HINIC3_LRO_UNIT_WQE_SIZE`. */
+	lro_max_pkt_len = max_lro_size / HINIC3_LRO_UNIT_WQE_SIZE
+				  ? max_lro_size / HINIC3_LRO_UNIT_WQE_SIZE
+				  : 1;
+
+	PMD_DRV_LOG(INFO,
+		    "max_lro_size: %d, rx_buff_len: %d, lro_max_pkt_len: %d",
+		    max_lro_size, nic_dev->rx_buff_len, lro_max_pkt_len);
+	PMD_DRV_LOG(INFO, "max_rx_pkt_len: %d",
+		    HINIC3_MAX_RX_PKT_LEN(dev_conf->rxmode));
+	err = hinic3_set_rx_lro_state(nic_dev->hwdev, lro_en,
+				      HINIC3_LRO_DEFAULT_TIME_LIMIT,
+				      lro_max_pkt_len);
+	if (err)
+		PMD_DRV_LOG(ERR, "Set lro state failed, err: %d", err);
+	return err;
+}
+
+static int
+hinic3_set_vlan(struct rte_eth_dev *dev, struct rte_eth_conf *dev_conf)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	bool vlan_filter, vlan_strip;
+	int err;
+
+	/* Config vlan filter. */
+	vlan_filter = dev_conf->rxmode.offloads &
+		      RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
+
+	err = hinic3_set_vlan_filter(nic_dev->hwdev, vlan_filter);
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			    "Config vlan filter failed, device: %s, port_id: "
+			    "%d, err: %d",
+			    nic_dev->dev_name, dev->data->port_id, err);
+		return err;
+	}
+
+	/* Config vlan stripping. */
+	vlan_strip = dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
+
+	err = hinic3_set_rx_vlan_offload(nic_dev->hwdev, vlan_strip);
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			    "Config vlan strip failed, device: %s, port_id: "
+			    "%d, err: %d",
+			    nic_dev->dev_name, dev->data->port_id, err);
+	}
+
+	return err;
+}
+
+/**
+ * Configure RX mode, checksum offload, LRO, RSS, VLAN and initialize the RXQ
+ * list.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_set_rxtx_configure(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
+	struct rte_eth_rss_conf *rss_conf = NULL;
+	int err;
+
+	/* Config rx mode. */
+	err = hinic3_set_rx_mode(nic_dev->hwdev, HINIC3_DEFAULT_RX_MODE);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set rx_mode: 0x%x failed",
+			    HINIC3_DEFAULT_RX_MODE);
+		return err;
+	}
+	nic_dev->rx_mode = HINIC3_DEFAULT_RX_MODE;
+
+	/* Config rx checksum offload. */
+	if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
+		nic_dev->rx_csum_en = HINIC3_DEFAULT_RX_CSUM_OFFLOAD;
+
+	err = hinic3_set_lro(nic_dev, dev_conf);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set lro failed");
+		return err;
+	}
+	/* Config RSS. */
+	if ((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) &&
+	    nic_dev->num_rqs > 1) {
+		rss_conf = &dev_conf->rx_adv_conf.rss_conf;
+		err = hinic3_update_rss_config(dev, rss_conf);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Set rss config failed, err: %d", err);
+			return err;
+		}
+	}
+
+	err = hinic3_set_vlan(dev, dev_conf);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set vlan failed, err: %d", err);
+		return err;
+	}
+
+	hinic3_init_rx_queue_list(nic_dev);
+
+	return 0;
+}
+
+/**
+ * Disable RX mode and RSS, and free associated resources.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ */
+static void
+hinic3_remove_rxtx_configure(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u8 prio_tc[HINIC3_DCB_UP_MAX] = {0};
+
+	hinic3_set_rx_mode(nic_dev->hwdev, 0);
+
+	if (nic_dev->rss_state == HINIC3_RSS_ENABLE) {
+		hinic3_rss_cfg(nic_dev->hwdev, HINIC3_RSS_DISABLE, 0, prio_tc);
+		hinic3_rss_template_free(nic_dev->hwdev);
+		nic_dev->rss_state = HINIC3_RSS_DISABLE;
+	}
+}
+
+static bool
+hinic3_find_vlan_filter(struct hinic3_nic_dev *nic_dev, uint16_t vlan_id)
+{
+	u32 vid_idx, vid_bit;
+
+	vid_idx = HINIC3_VFTA_IDX(vlan_id);
+	vid_bit = HINIC3_VFTA_BIT(vlan_id);
+
+	return (nic_dev->vfta[vid_idx] & vid_bit) ? true : false;
+}
+
+static void
+hinic3_store_vlan_filter(struct hinic3_nic_dev *nic_dev, u16 vlan_id, bool on)
+{
+	u32 vid_idx, vid_bit;
+
+	vid_idx = HINIC3_VFTA_IDX(vlan_id);
+	vid_bit = HINIC3_VFTA_BIT(vlan_id);
+
+	if (on)
+		nic_dev->vfta[vid_idx] |= vid_bit;
+	else
+		nic_dev->vfta[vid_idx] &= ~vid_bit;
+}
+
+static void
+hinic3_remove_all_vlanid(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int vlan_id;
+	u16 func_id;
+
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+
+	for (vlan_id = 1; vlan_id < RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
+		if (hinic3_find_vlan_filter(nic_dev, vlan_id)) {
+			hinic3_del_vlan(nic_dev->hwdev, vlan_id, func_id);
+			hinic3_store_vlan_filter(nic_dev, vlan_id, false);
+		}
+	}
+}
+
+static void
+hinic3_disable_interrupt(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+
+	if (!hinic3_get_bit(HINIC3_DEV_INIT, &nic_dev->dev_status))
+		return;
+
+	/* Disable rte interrupt. */
+	rte_intr_disable(PCI_DEV_TO_INTR_HANDLE(pci_dev));
+	rte_intr_callback_unregister(PCI_DEV_TO_INTR_HANDLE(pci_dev),
+				     hinic3_dev_interrupt_handler, (void *)dev);
+}
+
+static void
+hinic3_enable_interrupt(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
+
+	if (!hinic3_get_bit(HINIC3_DEV_INIT, &nic_dev->dev_status))
+		return;
+
+	/* Enable rte interrupt. */
+	rte_intr_enable(PCI_DEV_TO_INTR_HANDLE(pci_dev));
+	rte_intr_callback_register(PCI_DEV_TO_INTR_HANDLE(pci_dev),
+				   hinic3_dev_interrupt_handler, (void *)dev);
+}
+
+#define HINIC3_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
+
+/** Dp interrupt msix attribute. */
+#define HINIC3_TXRX_MSIX_PENDING_LIMIT	  2
+#define HINIC3_TXRX_MSIX_COALESC_TIMER	  2
+#define HINIC3_TXRX_MSIX_RESEND_TIMER_CFG 7
+
+static int
+hinic3_init_rxq_msix_attr(void *hwdev, u16 msix_index)
+{
+	struct interrupt_info info = {0};
+	int err;
+
+	info.lli_set = 0;
+	info.interrupt_coalesc_set = 1;
+	info.pending_limt = HINIC3_TXRX_MSIX_PENDING_LIMIT;
+	info.coalesc_timer_cfg = HINIC3_TXRX_MSIX_COALESC_TIMER;
+	info.resend_timer_cfg = HINIC3_TXRX_MSIX_RESEND_TIMER_CFG;
+
+	info.msix_index = msix_index;
+	err = hinic3_set_interrupt_cfg(hwdev, info);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set msix attr failed, msix_index %d",
+			    msix_index);
+		return -EFAULT;
+	}
+
+	return 0;
+}
+
+static void
+hinic3_deinit_rxq_intr(struct rte_eth_dev *dev)
+{
+	struct rte_intr_handle *intr_handle = dev->intr_handle;
+
+	rte_intr_efd_disable(intr_handle);
+	if (intr_handle->intr_vec) {
+		rte_free(intr_handle->intr_vec);
+		intr_handle->intr_vec = NULL;
+	}
+}
+
+/**
+ * Initialize RX queue interrupts by enabling MSI-X, allocate interrupt vectors,
+ * and configure interrupt attributes for each RX queue.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, negative error code on failure.
+ * - -ENOTSUP if MSI-X interrupts are not supported.
+ * - Error code if enabling event file descriptors fails.
+ * - -ENOMEM if allocating interrupt vectors fails.
+ */
+static int
+hinic3_init_rxq_intr(struct rte_eth_dev *dev)
+{
+	struct rte_intr_handle *intr_handle = NULL;
+	struct hinic3_nic_dev *nic_dev = NULL;
+	struct hinic3_rxq *rxq = NULL;
+	u32 nb_rx_queues, i;
+	int err;
+
+	intr_handle = dev->intr_handle;
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	if (!dev->data->dev_conf.intr_conf.rxq)
+		return 0;
+
+	if (!rte_intr_cap_multiple(intr_handle)) {
+		PMD_DRV_LOG(ERR, "Rx queue interrupts require MSI-X interrupts"
+				 " (vfio-pci driver)");
+		return -ENOTSUP;
+	}
+
+	nb_rx_queues = dev->data->nb_rx_queues;
+	err = rte_intr_efd_enable(intr_handle, nb_rx_queues);
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			"Failed to enable event fds for Rx queue interrupts");
+		return err;
+	}
+
+	intr_handle->intr_vec =
+		rte_zmalloc("hinic_intr_vec", nb_rx_queues * sizeof(int), 0);
+	if (intr_handle->intr_vec == NULL) {
+		PMD_DRV_LOG(ERR, "Failed to allocate intr_vec");
+		rte_intr_efd_disable(intr_handle);
+		return -ENOMEM;
+	}
+	intr_handle->vec_list_size = nb_rx_queues;
+	for (i = 0; i < nb_rx_queues; i++)
+		intr_handle->intr_vec[i] = (int)(i + HINIC3_RX_VEC_START);
+
+	for (i = 0; i < dev->data->nb_rx_queues; i++) {
+		rxq = dev->data->rx_queues[i];
+		rxq->dp_intr_en = 1;
+		rxq->msix_entry_idx = (u16)intr_handle->intr_vec[i];
+
+		err = hinic3_init_rxq_msix_attr(nic_dev->hwdev,
+						rxq->msix_entry_idx);
+		if (err) {
+			hinic3_deinit_rxq_intr(dev);
+			return err;
+		}
+	}
+
+	return 0;
+}
+
+static int
+hinic3_init_sw_rxtxqs(struct hinic3_nic_dev *nic_dev)
+{
+	u32 txq_size;
+	u32 rxq_size;
+
+	/* Allocate software txq array. */
+	txq_size = nic_dev->max_sqs * sizeof(*nic_dev->txqs);
+	nic_dev->txqs =
+		rte_zmalloc("hinic3_txqs", txq_size, RTE_CACHE_LINE_SIZE);
+	if (!nic_dev->txqs) {
+		PMD_DRV_LOG(ERR, "Allocate txqs failed");
+		return -ENOMEM;
+	}
+
+	/* Allocate software rxq array. */
+	rxq_size = nic_dev->max_rqs * sizeof(*nic_dev->rxqs);
+	nic_dev->rxqs =
+		rte_zmalloc("hinic3_rxqs", rxq_size, RTE_CACHE_LINE_SIZE);
+	if (!nic_dev->rxqs) {
+		/* Free txqs. */
+		rte_free(nic_dev->txqs);
+		nic_dev->txqs = NULL;
+
+		PMD_DRV_LOG(ERR, "Allocate rxqs failed");
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
+static void
+hinic3_deinit_sw_rxtxqs(struct hinic3_nic_dev *nic_dev)
+{
+	rte_free(nic_dev->txqs);
+	nic_dev->txqs = NULL;
+
+	rte_free(nic_dev->rxqs);
+	nic_dev->rxqs = NULL;
+}
+
+static void
+hinic3_disable_queue_intr(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct rte_intr_handle *intr_handle = dev->intr_handle;
+	int msix_intr;
+	int i;
+
+	if (intr_handle->intr_vec == NULL)
+		return;
+
+	for (i = 0; i < nic_dev->num_rqs; i++) {
+		msix_intr = intr_handle->intr_vec[i];
+		hinic3_set_msix_state(nic_dev->hwdev, (u16)msix_intr,
+				      HINIC3_MSIX_DISABLE);
+		hinic3_misx_intr_clear_resend_bit(nic_dev->hwdev,
+						  (u16)msix_intr,
+						  MSIX_RESEND_TIMER_CLEAR);
+	}
+}
+
+/**
+ * Start the device.
+ *
+ * Initialize function table, TXQ and TXQ context, configure RX offload, and
+ * enable vport and port to prepare receiving packets.
+ *
+ * @param[in] eth_dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_start(struct rte_eth_dev *eth_dev)
+{
+	struct hinic3_nic_dev *nic_dev = NULL;
+	u64 nic_features;
+	struct hinic3_rxq *rxq = NULL;
+	int i;
+	int err;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
+	err = hinic3_copy_mempool_init(nic_dev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Create copy mempool failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto init_mpool_fail;
+	}
+	hinic3_update_msix_info(nic_dev->hwdev->hwif);
+	hinic3_disable_interrupt(eth_dev);
+	err = hinic3_init_rxq_intr(eth_dev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Init rxq intr fail, eth_dev:%s",
+			    eth_dev->data->name);
+		goto init_rxq_intr_fail;
+	}
+
+	hinic3_get_func_rx_buf_size(nic_dev);
+	err = hinic3_init_function_table(nic_dev->hwdev, nic_dev->rx_buff_len);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Init function table failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto init_func_tbl_fail;
+	}
+
+	nic_features = hinic3_get_driver_feature(nic_dev);
+	/*
+	 * You can update the features supported by the driver according to the
+	 * scenario here.
+	 */
+	nic_features &= DEFAULT_DRV_FEATURE;
+	hinic3_update_driver_feature(nic_dev, nic_features);
+
+	err = hinic3_set_feature_to_hw(nic_dev->hwdev, &nic_dev->feature_cap,
+				       1);
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			    "Failed to set nic features to hardware, err %d",
+			    err);
+		goto get_feature_err;
+	}
+
+	/* Reset rx and tx queue. */
+	hinic3_reset_rx_queue(eth_dev);
+	hinic3_reset_tx_queue(eth_dev);
+
+	/* Init txq and rxq context. */
+	err = hinic3_init_qp_ctxts(nic_dev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Init qp context failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto init_qp_fail;
+	}
+
+	/* Set default mtu. */
+	err = hinic3_set_port_mtu(nic_dev->hwdev, nic_dev->mtu_size);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set mtu_size[%d] failed, dev_name: %s",
+			    nic_dev->mtu_size, eth_dev->data->name);
+		goto set_mtu_fail;
+	}
+	eth_dev->data->mtu = nic_dev->mtu_size;
+
+	/* Set rx configuration: rss/checksum/rxmode/lro. */
+	err = hinic3_set_rxtx_configure(eth_dev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set rx config failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto set_rxtx_config_fail;
+	}
+
+	/* Enable dev interrupt. */
+	hinic3_enable_interrupt(eth_dev);
+	err = hinic3_start_all_rqs(eth_dev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set rx config failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto start_rqs_fail;
+	}
+
+	hinic3_start_all_sqs(eth_dev);
+
+	/* Open virtual port and ready to start packet receiving. */
+	err = hinic3_set_vport_enable(nic_dev->hwdev, true);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Enable vport failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto en_vport_fail;
+	}
+
+	/* Open physical port and start packet receiving. */
+	err = hinic3_set_port_enable(nic_dev->hwdev, true);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Enable physical port failed, dev_name: %s",
+			    eth_dev->data->name);
+		goto en_port_fail;
+	}
+
+	/* Update eth_dev link status. */
+	if (eth_dev->data->dev_conf.intr_conf.lsc != 0)
+		hinic3_link_update(eth_dev, 0);
+
+	hinic3_set_bit(HINIC3_DEV_START, &nic_dev->dev_status);
+
+	return 0;
+
+en_port_fail:
+	hinic3_set_vport_enable(nic_dev->hwdev, false);
+
+en_vport_fail:
+	/* Flush tx && rx chip resources in case of setting vport fake fail. */
+	hinic3_flush_qps_res(nic_dev->hwdev);
+	rte_delay_ms(DEV_START_DELAY_MS);
+	for (i = 0; i < nic_dev->num_rqs; i++) {
+		rxq = nic_dev->rxqs[i];
+		hinic3_remove_rq_from_rx_queue_list(nic_dev, rxq->q_id);
+		hinic3_free_rxq_mbufs(rxq);
+		hinic3_dev_rx_queue_intr_disable(eth_dev, rxq->q_id);
+		eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
+		eth_dev->data->tx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
+	}
+start_rqs_fail:
+	hinic3_remove_rxtx_configure(eth_dev);
+
+set_rxtx_config_fail:
+set_mtu_fail:
+	hinic3_free_qp_ctxts(nic_dev->hwdev);
+
+init_qp_fail:
+get_feature_err:
+init_func_tbl_fail:
+	hinic3_deinit_rxq_intr(eth_dev);
+init_rxq_intr_fail:
+	hinic3_copy_mempool_uninit(nic_dev);
+init_mpool_fail:
+	return err;
+}
+
+/**
+ * Look up or creates a memory pool for storing packet buffers used in copy
+ * operations.
+ *
+ * @param[in] nic_dev
+ * Pointer to NIC device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ * `-ENOMEM`: Memory pool creation fails.
+ */
+static int
+hinic3_copy_mempool_init(struct hinic3_nic_dev *nic_dev)
+{
+	nic_dev->cpy_mpool = rte_mempool_lookup(HINCI3_CPY_MEMPOOL_NAME);
+	if (nic_dev->cpy_mpool == NULL) {
+		nic_dev->cpy_mpool = rte_pktmbuf_pool_create(HINCI3_CPY_MEMPOOL_NAME,
+			HINIC3_COPY_MEMPOOL_DEPTH, HINIC3_COPY_MEMPOOL_CACHE,
+			0, HINIC3_COPY_MBUF_SIZE, (int)rte_socket_id());
+		if (nic_dev->cpy_mpool == NULL) {
+			PMD_DRV_LOG(ERR,
+				    "Create copy mempool failed, errno: %d, "
+				    "dev_name: %s",
+				    rte_errno, HINCI3_CPY_MEMPOOL_NAME);
+			return -ENOMEM;
+		}
+	}
+
+	return 0;
+}
+
+/**
+ * Clear the reference to the copy memory pool without freeing it.
+ *
+ * @param[in] nic_dev
+ * Pointer to NIC device structure.
+ */
+static void
+hinic3_copy_mempool_uninit(struct hinic3_nic_dev *nic_dev)
+{
+	nic_dev->cpy_mpool = NULL;
+}
+
+/**
+ * Stop the device.
+ *
+ * Stop phy port and vport, flush pending io request, clean context configure
+ * and free io resourece.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ */
+static int
+hinic3_dev_stop(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev;
+	struct rte_eth_link link;
+	int err;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	if (!hinic3_test_and_clear_bit(HINIC3_DEV_START,
+				       &nic_dev->dev_status)) {
+		PMD_DRV_LOG(INFO, "Device %s already stopped",
+			    nic_dev->dev_name);
+		return 0;
+	}
+
+	/* Stop phy port and vport. */
+	err = hinic3_set_port_enable(nic_dev->hwdev, false);
+	if (err)
+		PMD_DRV_LOG(WARNING,
+			    "Disable phy port failed, error: %d, "
+			    "dev_name: %s, port_id: %d",
+			    err, dev->data->name, dev->data->port_id);
+
+	err = hinic3_set_vport_enable(nic_dev->hwdev, false);
+	if (err)
+		PMD_DRV_LOG(WARNING,
+			    "Disable vport failed, error: %d, "
+			    "dev_name: %s, port_id: %d",
+			    err, dev->data->name, dev->data->port_id);
+
+	/* Clear recorded link status. */
+	memset(&link, 0, sizeof(link));
+	rte_eth_linkstatus_set(dev, &link);
+
+	/* Disable dp interrupt. */
+	hinic3_disable_queue_intr(dev);
+	hinic3_deinit_rxq_intr(dev);
+
+	/* Flush pending io request. */
+	hinic3_flush_txqs(nic_dev);
+
+	/* After set vport disable 100ms, no packets will be send to host. */
+	rte_delay_ms(DEV_STOP_DELAY_MS);
+
+	hinic3_flush_qps_res(nic_dev->hwdev);
+
+	/* Clean RSS table and rx_mode. */
+	hinic3_remove_rxtx_configure(dev);
+
+	/* Clean root context. */
+	hinic3_free_qp_ctxts(nic_dev->hwdev);
+
+	/* Free all tx and rx mbufs. */
+	hinic3_free_all_txq_mbufs(nic_dev);
+	hinic3_free_all_rxq_mbufs(nic_dev);
+
+	/* Free mempool. */
+	hinic3_copy_mempool_uninit(nic_dev);
+	return 0;
+}
+
+static void
+hinic3_dev_release(struct rte_eth_dev *eth_dev)
+{
+	struct hinic3_nic_dev *nic_dev =
+		HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
+	int qid;
+
+	/* Release io resource. */
+	for (qid = 0; qid < nic_dev->num_sqs; qid++)
+		hinic3_tx_queue_release(eth_dev, qid);
+
+	for (qid = 0; qid < nic_dev->num_rqs; qid++)
+		hinic3_rx_queue_release(eth_dev, qid);
+
+	hinic3_deinit_sw_rxtxqs(nic_dev);
+
+	hinic3_deinit_mac_addr(eth_dev);
+	rte_free(nic_dev->mc_list);
+
+	hinic3_remove_all_vlanid(eth_dev);
+
+	hinic3_clear_bit(HINIC3_DEV_INTR_EN, &nic_dev->dev_status);
+	hinic3_set_msix_state(nic_dev->hwdev, 0, HINIC3_MSIX_DISABLE);
+	rte_intr_disable(PCI_DEV_TO_INTR_HANDLE(pci_dev));
+	rte_intr_callback_unregister(PCI_DEV_TO_INTR_HANDLE(pci_dev),
+					   hinic3_dev_interrupt_handler,
+					   (void *)eth_dev);
+
+	/* Destroy rx mode mutex. */
+	hinic3_mutex_destroy(&nic_dev->rx_mode_mutex);
+
+	hinic3_free_nic_hwdev(nic_dev->hwdev);
+	hinic3_free_hwdev(nic_dev->hwdev);
+
+	eth_dev->rx_pkt_burst = NULL;
+	eth_dev->tx_pkt_burst = NULL;
+	eth_dev->dev_ops = NULL;
+	eth_dev->rx_queue_count = NULL;
+	eth_dev->rx_descriptor_status = NULL;
+	eth_dev->tx_descriptor_status = NULL;
+
+	rte_free(nic_dev->hwdev);
+	nic_dev->hwdev = NULL;
+}
+
+/**
+ * Close the device.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_close(struct rte_eth_dev *eth_dev)
+{
+	struct hinic3_nic_dev *nic_dev =
+		HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
+	int ret;
+
+	if (hinic3_test_and_set_bit(HINIC3_DEV_CLOSE, &nic_dev->dev_status)) {
+		PMD_DRV_LOG(WARNING, "Device %s already closed",
+			    nic_dev->dev_name);
+		return 0;
+	}
+
+	ret = hinic3_dev_stop(eth_dev);
+
+	hinic3_dev_release(eth_dev);
+	return ret;
+}
+
+static int
+hinic3_dev_reset(__rte_unused struct rte_eth_dev *dev)
+{
+	return 0;
+}
+
+#define MIN_RX_BUFFER_SIZE	      256
+#define MIN_RX_BUFFER_SIZE_SMALL_MODE 1518
+
+static int
+hinic3_dev_set_mtu(struct rte_eth_dev *dev, uint16_t mtu)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int err = 0;
+
+	PMD_DRV_LOG(INFO, "Set port mtu, port_id: %d, mtu: %d, max_pkt_len: %d",
+		    dev->data->port_id, mtu, HINIC3_MTU_TO_PKTLEN(mtu));
+
+	if (mtu < HINIC3_MIN_MTU_SIZE || mtu > HINIC3_MAX_MTU_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid mtu: %d, must between %d and %d", mtu,
+			    HINIC3_MIN_MTU_SIZE, HINIC3_MAX_MTU_SIZE);
+		return -EINVAL;
+	}
+
+	err = hinic3_set_port_mtu(nic_dev->hwdev, mtu);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Set port mtu failed, err: %d", err);
+		return err;
+	}
+
+	/* Update max frame size. */
+	HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode) =
+		HINIC3_MTU_TO_PKTLEN(mtu);
+	nic_dev->mtu_size = mtu;
+	return err;
+}
+
+/**
+ * Add or delete vlan id.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] vlan_id
+ * Vlan id is used to filter vlan packets.
+ * @param[in] enable
+ * Disable or enable vlan filter function.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_vlan_filter_set(struct rte_eth_dev *dev, uint16_t vlan_id, int enable)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int err = 0;
+	u16 func_id;
+
+	if (vlan_id >= RTE_ETHER_MAX_VLAN_ID)
+		return -EINVAL;
+
+	if (vlan_id == 0)
+		return 0;
+
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+
+	if (enable) {
+		/* If vlanid is already set, just return. */
+		if (hinic3_find_vlan_filter(nic_dev, vlan_id)) {
+			PMD_DRV_LOG(INFO, "Vlan %u has been added, device: %s",
+				    vlan_id, nic_dev->dev_name);
+			return 0;
+		}
+
+		err = hinic3_add_vlan(nic_dev->hwdev, vlan_id, func_id);
+	} else {
+		/* If vlanid can't be found, just return. */
+		if (!hinic3_find_vlan_filter(nic_dev, vlan_id)) {
+			PMD_DRV_LOG(INFO,
+				    "Vlan %u is not in the vlan filter list, "
+				    "device: %s",
+				    vlan_id, nic_dev->dev_name);
+			return 0;
+		}
+
+		err = hinic3_del_vlan(nic_dev->hwdev, vlan_id, func_id);
+	}
+
+	if (err) {
+		PMD_DRV_LOG(ERR,
+			    "%s vlan failed, func_id: %d, vlan_id: %d, err: %d",
+			    enable ? "Add" : "Remove", func_id, vlan_id, err);
+		return err;
+	}
+
+	hinic3_store_vlan_filter(nic_dev, vlan_id, enable);
+
+	PMD_DRV_LOG(INFO, "%s vlan %u succeed, device: %s",
+		    enable ? "Add" : "Remove", vlan_id, nic_dev->dev_name);
+
+	return 0;
+}
+
+/**
+ * Enable or disable vlan offload.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] mask
+ * Definitions used for VLAN setting, vlan filter of vlan strip.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_vlan_offload_set(struct rte_eth_dev *dev, int mask)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct rte_eth_rxmode *rxmode = &dev->data->dev_conf.rxmode;
+	bool on;
+	int err;
+
+	/* Enable or disable VLAN filter. */
+	if (mask & RTE_ETH_VLAN_FILTER_MASK) {
+		on = (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_FILTER)
+			     ? true
+			     : false;
+		err = hinic3_set_vlan_filter(nic_dev->hwdev, on);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				    "%s vlan filter failed, device: %s, "
+				    "port_id: %d, err: %d",
+				    on ? "Enable" : "Disable",
+				    nic_dev->dev_name, dev->data->port_id, err);
+			return err;
+		}
+
+		PMD_DRV_LOG(INFO,
+			    "%s vlan filter succeed, device: %s, port_id: %d",
+			    on ? "Enable" : "Disable", nic_dev->dev_name,
+			    dev->data->port_id);
+	}
+
+	/* Enable or disable VLAN stripping. */
+	if (mask & RTE_ETH_VLAN_STRIP_MASK) {
+		on = (rxmode->offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP) ? true
+									: false;
+		err = hinic3_set_rx_vlan_offload(nic_dev->hwdev, on);
+		if (err) {
+			PMD_DRV_LOG(ERR,
+				    "%s vlan strip failed, device: %s, "
+				    "port_id: %d, err: %d",
+				    on ? "Enable" : "Disable",
+				    nic_dev->dev_name, dev->data->port_id, err);
+			return err;
+		}
+
+		PMD_DRV_LOG(INFO,
+			    "%s vlan strip succeed, device: %s, port_id: %d",
+			    on ? "Enable" : "Disable", nic_dev->dev_name,
+			    dev->data->port_id);
+	}
+	return 0;
+}
+
+/**
+ * Enable allmulticast mode.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_allmulticast_enable(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 rx_mode;
+	int err;
+
+	err = hinic3_mutex_lock(&nic_dev->rx_mode_mutex);
+	if (err)
+		return err;
+
+	rx_mode = nic_dev->rx_mode | HINIC3_RX_MODE_MC_ALL;
+
+	err = hinic3_set_rx_mode(nic_dev->hwdev, rx_mode);
+	if (err) {
+		hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+		PMD_DRV_LOG(ERR, "Enable allmulticast failed, error: %d", err);
+		return err;
+	}
+
+	nic_dev->rx_mode = rx_mode;
+
+	hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+
+	PMD_DRV_LOG(INFO,
+		    "Enable allmulticast succeed, nic_dev: %s, port_id: %d",
+		    nic_dev->dev_name, dev->data->port_id);
+	return 0;
+}
+
+/**
+ * Disable allmulticast mode.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 rx_mode;
+	int err;
+
+	err = hinic3_mutex_lock(&nic_dev->rx_mode_mutex);
+	if (err)
+		return err;
+
+	rx_mode = nic_dev->rx_mode & (~HINIC3_RX_MODE_MC_ALL);
+
+	err = hinic3_set_rx_mode(nic_dev->hwdev, rx_mode);
+	if (err) {
+		hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+		PMD_DRV_LOG(ERR, "Disable allmulticast failed, error: %d", err);
+		return err;
+	}
+
+	nic_dev->rx_mode = rx_mode;
+
+	hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+
+	PMD_DRV_LOG(INFO,
+		    "Disable allmulticast succeed, nic_dev: %s, port_id: %d",
+		    nic_dev->dev_name, dev->data->port_id);
+	return 0;
+}
+
+/**
+ * Get device generic statistics.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[out] stats
+ * Stats structure output buffer.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_stats_get(struct rte_eth_dev *dev, struct rte_eth_stats *stats)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct hinic3_vport_stats vport_stats;
+	struct hinic3_rxq *rxq = NULL;
+	struct hinic3_txq *txq = NULL;
+	int i, err, q_num;
+	u64 rx_discards_pmd = 0;
+
+	err = hinic3_get_vport_stats(nic_dev->hwdev, &vport_stats);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Get vport stats from fw failed, nic_dev: %s",
+			    nic_dev->dev_name);
+		return err;
+	}
+
+	dev->data->rx_mbuf_alloc_failed = 0;
+
+	/* Rx queue stats. */
+	q_num = (nic_dev->num_rqs < RTE_ETHDEV_QUEUE_STAT_CNTRS)
+			? nic_dev->num_rqs
+			: RTE_ETHDEV_QUEUE_STAT_CNTRS;
+	for (i = 0; i < q_num; i++) {
+		rxq = nic_dev->rxqs[i];
+#ifdef HINIC3_XSTAT_MBUF_USE
+		rxq->rxq_stats.rx_left_mbuf_bytes =
+			rxq->rxq_stats.rx_alloc_mbuf_bytes -
+			rxq->rxq_stats.rx_free_mbuf_bytes;
+#endif
+		rxq->rxq_stats.errors = rxq->rxq_stats.csum_errors +
+					rxq->rxq_stats.other_errors;
+
+		stats->q_ipackets[i] = rxq->rxq_stats.packets;
+		stats->q_ibytes[i] = rxq->rxq_stats.bytes;
+		stats->q_errors[i] = rxq->rxq_stats.errors;
+
+		stats->ierrors += rxq->rxq_stats.errors;
+		rx_discards_pmd += rxq->rxq_stats.dropped;
+		dev->data->rx_mbuf_alloc_failed += rxq->rxq_stats.rx_nombuf;
+	}
+
+	/* Tx queue stats. */
+	q_num = (nic_dev->num_sqs < RTE_ETHDEV_QUEUE_STAT_CNTRS)
+			? nic_dev->num_sqs
+			: RTE_ETHDEV_QUEUE_STAT_CNTRS;
+	for (i = 0; i < q_num; i++) {
+		txq = nic_dev->txqs[i];
+		stats->q_opackets[i] = txq->txq_stats.packets;
+		stats->q_obytes[i] = txq->txq_stats.bytes;
+		stats->oerrors += (txq->txq_stats.tx_busy +
+				   txq->txq_stats.offload_errors);
+	}
+
+	/* Vport stats. */
+	stats->oerrors += vport_stats.tx_discard_vport;
+
+	stats->imissed = vport_stats.rx_discard_vport + rx_discards_pmd;
+
+	stats->ipackets =
+		(vport_stats.rx_unicast_pkts_vport +
+		 vport_stats.rx_multicast_pkts_vport +
+		 vport_stats.rx_broadcast_pkts_vport - rx_discards_pmd);
+
+	stats->opackets = (vport_stats.tx_unicast_pkts_vport +
+			   vport_stats.tx_multicast_pkts_vport +
+			   vport_stats.tx_broadcast_pkts_vport);
+
+	stats->ibytes = (vport_stats.rx_unicast_bytes_vport +
+			 vport_stats.rx_multicast_bytes_vport +
+			 vport_stats.rx_broadcast_bytes_vport);
+
+	stats->obytes = (vport_stats.tx_unicast_bytes_vport +
+			 vport_stats.tx_multicast_bytes_vport +
+			 vport_stats.tx_broadcast_bytes_vport);
+	return 0;
+}
+
 /**
- * Interrupt handler triggered by NIC for handling specific event.
+ * Clear device generic statistics.
  *
- * @param[in] param
- * The address of parameter (struct rte_eth_dev *) registered before.
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_stats_reset(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct hinic3_rxq *rxq = NULL;
+	struct hinic3_txq *txq = NULL;
+	int qid;
+	int err;
+
+	err = hinic3_clear_vport_stats(nic_dev->hwdev);
+	if (err)
+		return err;
+
+	for (qid = 0; qid < nic_dev->num_rqs; qid++) {
+		rxq = nic_dev->rxqs[qid];
+		memset(&rxq->rxq_stats, 0, sizeof(struct hinic3_rxq_stats));
+	}
+
+	for (qid = 0; qid < nic_dev->num_sqs; qid++) {
+		txq = nic_dev->txqs[qid];
+		memset(&txq->txq_stats, 0, sizeof(struct hinic3_txq_stats));
+	}
+
+	return 0;
+}
+
+/**
+ * Get device extended statistics.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[out] xstats
+ * Pointer to rte extended stats table.
+ * @param[in] n
+ * The size of the stats table.
+ *
+ * @return
+ * positive: Number of extended stats on success and stats is filled.
+ * negative: Failure.
+ */
+static int
+hinic3_dev_xstats_get(struct rte_eth_dev *dev, struct rte_eth_xstat *xstats,
+		      unsigned int n)
+{
+	struct hinic3_nic_dev *nic_dev;
+	struct mag_phy_port_stats port_stats;
+	struct hinic3_vport_stats vport_stats;
+	struct hinic3_rxq *rxq = NULL;
+	struct hinic3_rxq_stats rxq_stats;
+	struct hinic3_txq *txq = NULL;
+	struct hinic3_txq_stats txq_stats;
+	u16 qid;
+	u32 i;
+	int err, count;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	count = hinic3_xstats_calc_num(nic_dev);
+	if ((int)n < count)
+		return count;
+
+	count = 0;
+
+	/* Get stats from rxq stats structure. */
+	for (qid = 0; qid < nic_dev->num_rqs; qid++) {
+		rxq = nic_dev->rxqs[qid];
+
+#ifdef HINIC3_XSTAT_RXBUF_INFO
+		hinic3_get_stats(rxq);
+#endif
+
+#ifdef HINIC3_XSTAT_MBUF_USE
+		rxq->rxq_stats.rx_left_mbuf_bytes =
+			rxq->rxq_stats.rx_alloc_mbuf_bytes -
+			rxq->rxq_stats.rx_free_mbuf_bytes;
+#endif
+		rxq->rxq_stats.errors = rxq->rxq_stats.csum_errors +
+					rxq->rxq_stats.other_errors;
+
+		memcpy((void *)&rxq_stats, (void *)&rxq->rxq_stats,
+		       sizeof(rxq->rxq_stats));
+
+		for (i = 0; i < HINIC3_RXQ_XSTATS_NUM; i++) {
+			xstats[count].value = *(uint64_t *)(((char *)&rxq_stats) +
+					    hinic3_rxq_stats_strings[i].offset);
+			xstats[count].id = count;
+			count++;
+		}
+	}
+
+	/* Get stats from txq stats structure. */
+	for (qid = 0; qid < nic_dev->num_sqs; qid++) {
+		txq = nic_dev->txqs[qid];
+		memcpy((void *)&txq_stats, (void *)&txq->txq_stats,
+		       sizeof(txq->txq_stats));
+
+		for (i = 0; i < HINIC3_TXQ_XSTATS_NUM; i++) {
+			xstats[count].value = *(uint64_t *)(((char *)&txq_stats) +
+					    hinic3_txq_stats_strings[i].offset);
+			xstats[count].id = count;
+			count++;
+		}
+	}
+
+	/* Get stats from vport stats structure. */
+	err = hinic3_get_vport_stats(nic_dev->hwdev, &vport_stats);
+	if (err)
+		return err;
+
+	for (i = 0; i < HINIC3_VPORT_XSTATS_NUM; i++) {
+		xstats[count].value =
+			*(uint64_t *)(((char *)&vport_stats) +
+				      hinic3_vport_stats_strings[i].offset);
+		xstats[count].id = count;
+		count++;
+	}
+
+	if (HINIC3_IS_VF(nic_dev->hwdev))
+		return count;
+
+	/* Get stats from phy port stats structure. */
+	err = hinic3_get_phy_port_stats(nic_dev->hwdev, &port_stats);
+	if (err)
+		return err;
+
+	for (i = 0; i < HINIC3_PHYPORT_XSTATS_NUM; i++) {
+		xstats[count].value =
+			*(uint64_t *)(((char *)&port_stats) +
+				      hinic3_phyport_stats_strings[i].offset);
+		xstats[count].id = count;
+		count++;
+	}
+
+	return count;
+}
+
+/**
+ * Clear device extended statistics.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_xstats_reset(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int err;
+
+	err = hinic3_dev_stats_reset(dev);
+	if (err)
+		return err;
+
+	if (hinic3_func_type(nic_dev->hwdev) != TYPE_VF) {
+		err = hinic3_clear_phy_port_stats(nic_dev->hwdev);
+		if (err)
+			return err;
+	}
+
+	return 0;
+}
+
+/**
+ * Retrieve names of extended device statistics.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[out] xstats_names
+ * Buffer to insert names into.
+ *
+ * @return
+ * Number of xstats names.
+ */
+static int
+hinic3_dev_xstats_get_names(struct rte_eth_dev *dev,
+			    struct rte_eth_xstat_name *xstats_names,
+			    __rte_unused unsigned int limit)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	int count = 0;
+	u16 i, q_num;
+
+	if (xstats_names == NULL)
+		return hinic3_xstats_calc_num(nic_dev);
+
+	/* Get pmd rxq stats name. */
+	for (q_num = 0; q_num < nic_dev->num_rqs; q_num++) {
+		for (i = 0; i < HINIC3_RXQ_XSTATS_NUM; i++) {
+			snprintf(xstats_names[count].name,
+				 sizeof(xstats_names[count].name),
+				 "rxq%d_%s_pmd", q_num,
+				 hinic3_rxq_stats_strings[i].name);
+			count++;
+		}
+	}
+
+	/* Get pmd txq stats name. */
+	for (q_num = 0; q_num < nic_dev->num_sqs; q_num++) {
+		for (i = 0; i < HINIC3_TXQ_XSTATS_NUM; i++) {
+			snprintf(xstats_names[count].name,
+				 sizeof(xstats_names[count].name),
+				 "txq%d_%s_pmd", q_num,
+				 hinic3_txq_stats_strings[i].name);
+			count++;
+		}
+	}
+
+	/* Get vport stats name. */
+	for (i = 0; i < HINIC3_VPORT_XSTATS_NUM; i++) {
+		snprintf(xstats_names[count].name,
+			 sizeof(xstats_names[count].name), "%s",
+			 hinic3_vport_stats_strings[i].name);
+		count++;
+	}
+
+	if (HINIC3_IS_VF(nic_dev->hwdev))
+		return count;
+
+	/* Get phy port stats name. */
+	for (i = 0; i < HINIC3_PHYPORT_XSTATS_NUM; i++) {
+		snprintf(xstats_names[count].name,
+			 sizeof(xstats_names[count].name), "%s",
+			 hinic3_phyport_stats_strings[i].name);
+		count++;
+	}
+
+	return count;
+}
+
+/**
+ * Function used to get supported ptypes of an Ethernet device.
+ *
+ * @param[in] dev
+ * ethdev handle of port.
+ * @param[out] no_of_elements
+ * number of ptypes elements. Must be initialized to 0.
+ *
+ * @return
+ * Success, array of ptypes elements and valid no_of_elements > 0.
+ * Failures, NULL.
  */
+static const uint32_t *
+hinic3_dev_supported_ptypes_get(__rte_unused struct rte_eth_dev *dev,
+				__rte_unused size_t *no_of_elements)
+{
+	return 0;
+}
+
 static void
-hinic3_dev_interrupt_handler(void *param)
+hinic3_rxq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
+		    struct rte_eth_rxq_info *rxq_info)
+{
+	struct hinic3_rxq *rxq = dev->data->rx_queues[queue_id];
+
+	rxq_info->mp = rxq->mb_pool;
+	rxq_info->nb_desc = rxq->q_depth;
+}
+
+static void
+hinic3_txq_info_get(struct rte_eth_dev *dev, uint16_t queue_id,
+		    struct rte_eth_txq_info *txq_qinfo)
+{
+	struct hinic3_txq *txq = dev->data->tx_queues[queue_id];
+
+	txq_qinfo->nb_desc = txq->q_depth;
+}
+
+/**
+ * Update MAC address.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] addr
+ * Pointer to MAC address.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_set_mac_addr(struct rte_eth_dev *dev, struct rte_ether_addr *addr)
 {
-	struct rte_eth_dev *dev = param;
 	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	char mac_addr[RTE_ETHER_ADDR_FMT_SIZE];
+	u16 func_id;
+	int err;
 
-	if (!hinic3_get_bit(HINIC3_DEV_INTR_EN, &nic_dev->dev_status)) {
-		PMD_DRV_LOG(WARNING,
-			    "Intr is disabled, ignore intr event, "
-			    "dev_name: %s, port_id: %d",
-			    nic_dev->dev_name, dev->data->port_id);
+	if (!rte_is_valid_assigned_ether_addr(addr)) {
+		rte_ether_format_addr(mac_addr, RTE_ETHER_ADDR_FMT_SIZE, addr);
+		PMD_DRV_LOG(ERR, "Set invalid MAC address %s", mac_addr);
+		return -EINVAL;
+	}
+
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+	err = hinic3_update_mac(nic_dev->hwdev,
+				nic_dev->default_addr.addr_bytes,
+				addr->addr_bytes, 0, func_id);
+	if (err)
+		return err;
+
+	rte_ether_addr_copy(addr, &nic_dev->default_addr);
+	rte_ether_format_addr(mac_addr, RTE_ETHER_ADDR_FMT_SIZE,
+			      &nic_dev->default_addr);
+
+	PMD_DRV_LOG(INFO, "Set new MAC address %s", mac_addr);
+	return 0;
+}
+
+/**
+ * Remove a MAC address.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] index
+ * MAC address index.
+ */
+static void
+hinic3_mac_addr_remove(struct rte_eth_dev *dev, uint32_t index)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u16 func_id;
+	int err;
+
+	if (index >= HINIC3_MAX_UC_MAC_ADDRS) {
+		PMD_DRV_LOG(INFO, "Remove MAC index(%u) is out of range",
+			    index);
 		return;
 	}
 
-	/* Aeq0 msg handler. */
-	hinic3_dev_handle_aeq_event(nic_dev->hwdev, param);
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+	err = hinic3_del_mac(nic_dev->hwdev,
+			     dev->data->mac_addrs[index].addr_bytes, 0,
+			     func_id);
+	if (err)
+		PMD_DRV_LOG(ERR, "Remove MAC index(%u) failed", index);
+}
+
+/**
+ * Add a MAC address.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] mac_addr
+ * MAC address to register.
+ * @param[in] index
+ * MAC address index.
+ * @param[in] vmdq
+ * VMDq pool index to associate address with (unused_).
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_mac_addr_add(struct rte_eth_dev *dev, struct rte_ether_addr *mac_addr,
+		    uint32_t index, __rte_unused uint32_t vmdq)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	unsigned int i;
+	u16 func_id;
+	int err;
+
+	if (!rte_is_valid_assigned_ether_addr(mac_addr)) {
+		PMD_DRV_LOG(ERR, "Add invalid MAC address");
+		return -EINVAL;
+	}
+
+	if (index >= HINIC3_MAX_UC_MAC_ADDRS) {
+		PMD_DRV_LOG(ERR, "Add MAC index(%u) is out of range", index);
+		return -EINVAL;
+	}
+
+	/* Make sure this address doesn't already be configured. */
+	for (i = 0; i < HINIC3_MAX_UC_MAC_ADDRS; i++) {
+		if (rte_is_same_ether_addr(mac_addr,
+					   &dev->data->mac_addrs[i])) {
+			PMD_DRV_LOG(ERR, "MAC address is already configured");
+			return -EADDRINUSE;
+		}
+	}
+
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+	err = hinic3_set_mac(nic_dev->hwdev, mac_addr->addr_bytes, 0, func_id);
+	if (err)
+		return err;
+
+	return 0;
 }
 
+/**
+ * Delete all multicast MAC addresses from the NIC device.
+ *
+ * This function iterates over the list of multicast MAC addresses and removes
+ * each address from the NIC device by calling `hinic3_del_mac`. After each
+ * deletion, the address is reset to zero.
+ *
+ * @param[in] nic_dev
+ * Pointer to NIC device structure.
+ */
 static void
-hinic3_deinit_sw_rxtxqs(struct hinic3_nic_dev *nic_dev)
+hinic3_delete_mc_addr_list(struct hinic3_nic_dev *nic_dev)
 {
-	rte_free(nic_dev->txqs);
-	nic_dev->txqs = NULL;
+	u16 func_id;
+	u32 i;
 
-	rte_free(nic_dev->rxqs);
-	nic_dev->rxqs = NULL;
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+
+	for (i = 0; i < HINIC3_MAX_MC_MAC_ADDRS; i++) {
+		if (rte_is_zero_ether_addr(&nic_dev->mc_list[i]))
+			break;
+
+		hinic3_del_mac(nic_dev->hwdev, nic_dev->mc_list[i].addr_bytes,
+			       0, func_id);
+		memset(&nic_dev->mc_list[i], 0, sizeof(struct rte_ether_addr));
+	}
+}
+
+/**
+ * Set multicast MAC address.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] mc_addr_set
+ * Pointer to multicast MAC address.
+ * @param[in] nb_mc_addr
+ * The number of multicast MAC address to set.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_set_mc_addr_list(struct rte_eth_dev *dev,
+			struct rte_ether_addr *mc_addr_set, uint32_t nb_mc_addr)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	char mac_addr[RTE_ETHER_ADDR_FMT_SIZE];
+	u16 func_id;
+	int err;
+	u32 i;
+
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
+
+	/* Delete old multi_cast addrs firstly. */
+	hinic3_delete_mc_addr_list(nic_dev);
+
+	if (nb_mc_addr > HINIC3_MAX_MC_MAC_ADDRS)
+		return -EINVAL;
+
+	for (i = 0; i < nb_mc_addr; i++) {
+		if (!rte_is_multicast_ether_addr(&mc_addr_set[i])) {
+			rte_ether_format_addr(mac_addr, RTE_ETHER_ADDR_FMT_SIZE,
+					      &mc_addr_set[i]);
+			PMD_DRV_LOG(ERR,
+				    "Set mc MAC addr failed, addr(%s) invalid",
+				    mac_addr);
+			return -EINVAL;
+		}
+	}
+
+	for (i = 0; i < nb_mc_addr; i++) {
+		err = hinic3_set_mac(nic_dev->hwdev, mc_addr_set[i].addr_bytes,
+				     0, func_id);
+		if (err) {
+			hinic3_delete_mc_addr_list(nic_dev);
+			return err;
+		}
+
+		rte_ether_addr_copy(&mc_addr_set[i], &nic_dev->mc_list[i]);
+	}
+
+	return 0;
+}
+
+static int
+hinic3_get_reg(__rte_unused struct rte_eth_dev *dev,
+	       __rte_unused struct rte_dev_reg_info *regs)
+{
+	return 0;
 }
 
+static const struct eth_dev_ops hinic3_pmd_ops = {
+	.dev_configure                 = hinic3_dev_configure,
+	.dev_infos_get                 = hinic3_dev_infos_get,
+	.fw_version_get                = hinic3_fw_version_get,
+	.dev_set_link_up               = hinic3_dev_set_link_up,
+	.dev_set_link_down             = hinic3_dev_set_link_down,
+	.link_update                   = hinic3_link_update,
+	.rx_queue_setup                = hinic3_rx_queue_setup,
+	.tx_queue_setup                = hinic3_tx_queue_setup,
+	.rx_queue_release              = hinic3_rx_queue_release,
+	.tx_queue_release              = hinic3_tx_queue_release,
+	.rx_queue_start                = hinic3_dev_rx_queue_start,
+	.rx_queue_stop                 = hinic3_dev_rx_queue_stop,
+	.tx_queue_start                = hinic3_dev_tx_queue_start,
+	.tx_queue_stop                 = hinic3_dev_tx_queue_stop,
+	.rx_queue_intr_enable          = hinic3_dev_rx_queue_intr_enable,
+	.rx_queue_intr_disable         = hinic3_dev_rx_queue_intr_disable,
+	.dev_start                     = hinic3_dev_start,
+	.dev_stop                      = hinic3_dev_stop,
+	.dev_close                     = hinic3_dev_close,
+	.dev_reset                     = hinic3_dev_reset,
+	.mtu_set                       = hinic3_dev_set_mtu,
+	.vlan_filter_set               = hinic3_vlan_filter_set,
+	.vlan_offload_set              = hinic3_vlan_offload_set,
+	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
+	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
+	.stats_get                     = hinic3_dev_stats_get,
+	.stats_reset                   = hinic3_dev_stats_reset,
+	.xstats_get                    = hinic3_dev_xstats_get,
+	.xstats_reset                  = hinic3_dev_xstats_reset,
+	.xstats_get_names              = hinic3_dev_xstats_get_names,
+	.dev_supported_ptypes_get      = hinic3_dev_supported_ptypes_get,
+	.rxq_info_get                  = hinic3_rxq_info_get,
+	.txq_info_get                  = hinic3_txq_info_get,
+	.mac_addr_set                  = hinic3_set_mac_addr,
+	.mac_addr_remove               = hinic3_mac_addr_remove,
+	.mac_addr_add                  = hinic3_mac_addr_add,
+	.set_mc_addr_list              = hinic3_set_mc_addr_list,
+	.get_reg                       = hinic3_get_reg,
+};
+
+static const struct eth_dev_ops hinic3_pmd_vf_ops = {
+	.dev_configure                 = hinic3_dev_configure,
+	.dev_infos_get                 = hinic3_dev_infos_get,
+	.fw_version_get                = hinic3_fw_version_get,
+	.rx_queue_setup                = hinic3_rx_queue_setup,
+	.tx_queue_setup                = hinic3_tx_queue_setup,
+	.rx_queue_intr_enable          = hinic3_dev_rx_queue_intr_enable,
+	.rx_queue_intr_disable         = hinic3_dev_rx_queue_intr_disable,
+
+	.rx_queue_start                = hinic3_dev_rx_queue_start,
+	.rx_queue_stop                 = hinic3_dev_rx_queue_stop,
+	.tx_queue_start                = hinic3_dev_tx_queue_start,
+	.tx_queue_stop                 = hinic3_dev_tx_queue_stop,
+
+	.dev_start                     = hinic3_dev_start,
+	.link_update                   = hinic3_link_update,
+	.rx_queue_release              = hinic3_rx_queue_release,
+	.tx_queue_release              = hinic3_tx_queue_release,
+	.dev_stop                      = hinic3_dev_stop,
+	.dev_close                     = hinic3_dev_close,
+	.mtu_set                       = hinic3_dev_set_mtu,
+	.vlan_filter_set               = hinic3_vlan_filter_set,
+	.vlan_offload_set              = hinic3_vlan_offload_set,
+	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
+	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
+	.stats_get                     = hinic3_dev_stats_get,
+	.stats_reset                   = hinic3_dev_stats_reset,
+	.xstats_get                    = hinic3_dev_xstats_get,
+	.xstats_reset                  = hinic3_dev_xstats_reset,
+	.xstats_get_names              = hinic3_dev_xstats_get_names,
+	.rxq_info_get                  = hinic3_rxq_info_get,
+	.txq_info_get                  = hinic3_txq_info_get,
+	.mac_addr_set                  = hinic3_set_mac_addr,
+	.mac_addr_remove               = hinic3_mac_addr_remove,
+	.mac_addr_add                  = hinic3_mac_addr_add,
+	.set_mc_addr_list              = hinic3_set_mc_addr_list,
+};
+
 /**
  * Init mac_vlan table in hardwares.
  *
@@ -319,6 +3194,15 @@ hinic3_func_init(struct rte_eth_dev *eth_dev)
 	nic_dev->max_sqs = hinic3_func_max_sqs(nic_dev->hwdev);
 	nic_dev->max_rqs = hinic3_func_max_rqs(nic_dev->hwdev);
 
+	if (HINIC3_FUNC_TYPE(nic_dev->hwdev) == TYPE_VF)
+		eth_dev->dev_ops = &hinic3_pmd_vf_ops;
+	else
+		eth_dev->dev_ops = &hinic3_pmd_ops;
+
+	eth_dev->rx_queue_count = hinic3_dev_rx_queue_count;
+	eth_dev->rx_descriptor_status = hinic3_dev_rx_descriptor_status;
+	eth_dev->tx_descriptor_status = hinic3_dev_tx_descriptor_status;
+
 	err = hinic3_init_nic_hwdev(nic_dev->hwdev);
 	if (err) {
 		PMD_DRV_LOG(ERR, "Init nic hwdev failed, dev_name: %s",
drivers/net/hinic3/hinic3_nic_io.c new file +828 -0

51 lines not on this page · raw message

drivers/net/hinic3/hinic3_nic_io.h new file +169 -0

169 lines not on this page · raw message

drivers/net/hinic3/hinic3_rx.c new file +814 -0

814 lines not on this page · raw message

drivers/net/hinic3/hinic3_rx.h new file +356 -0

356 lines not on this page · raw message

drivers/net/hinic3/hinic3_tx.c new file +274 -0

274 lines not on this page · raw message

drivers/net/hinic3/hinic3_tx.h new file +314 -0

314 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.45.1.windows.1

Part of the diff is not shown here. View the raw message.

#151 lore raw

Re: [V5 13/18] net/hinic3: add dev ops

Quoted 8 lines · On Wed, 2 Jul 2025 10:09:36 +0800 Feifei Wang <[email protected]> wrote:

From: Feifei Wang <[email protected]>

Add ops related function codes.

---

Some spelling errors in this patch that should be fixed.

### [PATCH] net/hinic3: add dev ops

WARNING:TYPO_SPELLING: 'resourece' may be misspelled - perhaps 'resource'? #1893: FILE: drivers/net/hinic3/hinic3_ethdev.c:1897:
+ * and free io resourece.

                ^^^^^^^^^

WARNING:TYPO_SPELLING: 'coverting' may be misspelled - perhaps 'converting'? #3906: FILE: drivers/net/hinic3/hinic3_nic_io.h:100:
+ /* Hardware will do endianness coverting. */
^^^^^^^^^

WARNING:TYPO_SPELLING: 'indrect' may be misspelled - perhaps 'indirect'? #4431: FILE: drivers/net/hinic3/hinic3_rx.c:450:
+ "Set indrect table failed, eth_dev:%s, queue_idx:%d",
^^^^^^^

WARNING:TYPO_SPELLING: 'Does't' may be misspelled - perhaps 'Doesn't'? #4474: FILE: drivers/net/hinic3/hinic3_rx.c:493:
+ PMD_DRV_LOG(ERR, "Does't support rss hash type: %" PRIu64,
^^^^^^

WARNING:TYPO_SPELLING: 'possition' may be misspelled - perhaps 'position'? #4522: FILE: drivers/net/hinic3/hinic3_rx.c:541:
+ * Search given queue array to find possition of given id.

                                     ^^^^^^^^^

WARNING:TYPO_SPELLING: 'pakcet' may be misspelled - perhaps 'packet'? #4708: FILE: drivers/net/hinic3/hinic3_rx.c:727:
+ * If RSS is disable, no mbuf in rq, pakcet will be dropped.
^^^^^^

WARNING:TYPO_SPELLING: 'indrect' may be misspelled - perhaps 'indirect'? #4775: FILE: drivers/net/hinic3/hinic3_rx.c:794:
+ "Refill rq to indrect table failed, "
^^^^^^^

#152 lore raw

Re: [V5 13/18] net/hinic3: add dev ops

In reply to Feifei Wang
Quoted 23 lines · Feifei Wang

From: Feifei Wang <[email protected]>

Add ops related function codes.

---

 drivers/net/hinic3/hinic3_ethdev.c | 2918 +++++++++++++++++++++++++++-
 drivers/net/hinic3/hinic3_nic_io.c |  828 ++++++++
 drivers/net/hinic3/hinic3_nic_io.h |  169 ++
 drivers/net/hinic3/hinic3_rx.c     |  814 ++++++++
Quoted 7 lines
 drivers/net/hinic3/hinic3_rx.h     |  356 ++++
 drivers/net/hinic3/hinic3_tx.c     |  274 +++
 drivers/net/hinic3/hinic3_tx.h     |  314 +++
 7 files changed, 5656 insertions(+), 17 deletions(-)

this patch contain too much code and hard to review, suggest split it to several patches..

Quoted 1,676 lines
 create mode 100644 drivers/net/hinic3/hinic3_nic_io.c
 create mode 100644 drivers/net/hinic3/hinic3_nic_io.h
 create mode 100644 drivers/net/hinic3/hinic3_rx.c
 create mode 100644 drivers/net/hinic3/hinic3_rx.h
 create mode 100644 drivers/net/hinic3/hinic3_tx.c
 create mode 100644 drivers/net/hinic3/hinic3_tx.h
drivers/net/hinic3/hinic3_ethdev.c +0 -0

index e6666a4d87..d9bca3aeb3 100644

--- a/drivers/net/hinic3/hinic3_ethdev.c

+++ b/drivers/net/hinic3/hinic3_ethdev.c

drivers/net/hinic3/hinic3_ethdev.c +821 -0
@@ -21,42 +21,2917 @@
 
 #include "base/hinic3_hw_comm.h"
 
 #include "base/hinic3_nic_cfg.h"
 
 #include "base/hinic3_nic_event.h"
 
+#include "hinic3_pmd_nic_io.h"
 
+#include "hinic3_pmd_tx.h"
 
+#include "hinic3_pmd_rx.h"
 
 #include "hinic3_ethdev.h"
 
 
 
+#define HINIC3_MIN_RX_BUF_SIZE 1024
 
+
 
+#define HINIC3_DEFAULT_BURST_SIZE 32
 
+#define HINIC3_DEFAULT_NB_QUEUES  1
 
+#define HINIC3_DEFAULT_RING_SIZE  1024
 
+#define HINIC3_MAX_LRO_SIZE	  65536
 
+
 
+#define HINIC3_DEFAULT_RX_FREE_THRESH 32
 
+#define HINIC3_DEFAULT_TX_FREE_THRESH 32
 
+
 
+#define HINIC3_RX_WAIT_CYCLE_THRESH 500
 
+
 
+/**
 
+ * Get the 32-bit VFTA bit mask for the lower 5 bits of the VLAN ID.
 
+ *
 
+ * Vlan_id is a 12 bit number. The VFTA array is actually a 4096 bit array,
 
+ * 128 of 32bit elements. 2^5 = 32. The val of lower 5 bits specifies the bit
 
+ * in the 32bit element. The higher 7 bit val specifies VFTA array index.
 
+ */
 
+#define HINIC3_VFTA_BIT(vlan_id) (1 << ((vlan_id) & 0x1F))
 
+/**
 
+ * Get the VFTA index from the upper 7 bits of the VLAN ID.
 
+ */
 
+#define HINIC3_VFTA_IDX(vlan_id) ((vlan_id) >> 5)
 
+
 
+#define HINIC3_LRO_DEFAULT_TIME_LIMIT 16
 
+#define HINIC3_LRO_UNIT_WQE_SIZE      1024 /**< Bytes. */
 
+
 
+#define HINIC3_MAX_RX_PKT_LEN(rxmod) ((rxmod).mtu)
 
+int hinic3_logtype; /**< Driver-specific log messages type. */
 
+
 
+/**
 
+ * The different receive modes for the NIC.
 
+ *
 
+ * The receive modes are represented as bit flags that control how the
 
+ * NIC handles various types of network traffic.
 
+ */
 
+enum hinic3_rx_mod {
 
+	/* Enable unicast receive mode. */
 
+	HINIC3_RX_MODE_UC = 1 << 0,
 
+	/* Enable multicast receive mode. */
 
+	HINIC3_RX_MODE_MC = 1 << 1,
 
+	/* Enable broadcast receive mode. */
 
+	HINIC3_RX_MODE_BC = 1 << 2,
 
+	/* Enable receive mode for all multicast addresses. */
 
+	HINIC3_RX_MODE_MC_ALL = 1 << 3,
 
+	/* Enable promiscuous mode, receiving all packets. */
 
+	HINIC3_RX_MODE_PROMISC = 1 << 4,
 
+};
 
+
 
+#define HINIC3_DEFAULT_RX_MODE \
 
+	(HINIC3_RX_MODE_UC | HINIC3_RX_MODE_MC | HINIC3_RX_MODE_BC)
 
+
 
+struct hinic3_xstats_name_off {
 
+	char name[RTE_ETH_XSTATS_NAME_SIZE];
 
+	u32 offset;
 
+};
 
+
 
+#define HINIC3_FUNC_STAT(_stat_item)                                       \
 
+	{                                                                  \
 
+		.name = #_stat_item,                                       \
 
+		.offset = offsetof(struct hinic3_vport_stats, _stat_item), \
 
+	}
 
+
 
+static const struct hinic3_xstats_name_off hinic3_vport_stats_strings[] = {
 
+	HINIC3_FUNC_STAT(tx_unicast_pkts_vport),
 
+	HINIC3_FUNC_STAT(tx_unicast_bytes_vport),
 
+	HINIC3_FUNC_STAT(tx_multicast_pkts_vport),
 
+	HINIC3_FUNC_STAT(tx_multicast_bytes_vport),
 
+	HINIC3_FUNC_STAT(tx_broadcast_pkts_vport),
 
+	HINIC3_FUNC_STAT(tx_broadcast_bytes_vport),
 
+
 
+	HINIC3_FUNC_STAT(rx_unicast_pkts_vport),
 
+	HINIC3_FUNC_STAT(rx_unicast_bytes_vport),
 
+	HINIC3_FUNC_STAT(rx_multicast_pkts_vport),
 
+	HINIC3_FUNC_STAT(rx_multicast_bytes_vport),
 
+	HINIC3_FUNC_STAT(rx_broadcast_pkts_vport),
 
+	HINIC3_FUNC_STAT(rx_broadcast_bytes_vport),
 
+
 
+	HINIC3_FUNC_STAT(tx_discard_vport),
 
+	HINIC3_FUNC_STAT(rx_discard_vport),
 
+	HINIC3_FUNC_STAT(tx_err_vport),
 
+	HINIC3_FUNC_STAT(rx_err_vport),
 
+};
 
+
 
+#define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0]))
 
+
 
+#define HINIC3_VPORT_XSTATS_NUM ARRAY_SIZE(hinic3_vport_stats_strings)
 
+
 
+#define HINIC3_PORT_STAT(_stat_item)                                       \
 
+	{                                                                  \
 
+		.name = #_stat_item,                                       \
 
+		.offset = offsetof(struct mag_phy_port_stats, _stat_item), \
 
+	}
 
+
 
+static const struct hinic3_xstats_name_off hinic3_phyport_stats_strings[] = {
 
+	HINIC3_PORT_STAT(mac_tx_fragment_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_undersize_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_undermin_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_64_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_65_127_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_128_255_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_256_511_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_512_1023_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_1024_1518_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_1519_2047_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_2048_4095_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_4096_8191_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_8192_9216_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_9217_12287_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_12288_16383_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_1519_max_bad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_1519_max_good_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_oversize_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_jabber_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_bad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_bad_oct_num),
 
+	HINIC3_PORT_STAT(mac_tx_good_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_good_oct_num),
 
+	HINIC3_PORT_STAT(mac_tx_total_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_total_oct_num),
 
+	HINIC3_PORT_STAT(mac_tx_uni_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_multi_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_broad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pause_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri0_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri1_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri2_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri3_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri4_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri5_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri6_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_pfc_pri7_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_control_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_err_all_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_from_app_good_pkt_num),
 
+	HINIC3_PORT_STAT(mac_tx_from_app_bad_pkt_num),
 
+
 
+	HINIC3_PORT_STAT(mac_rx_fragment_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_undersize_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_undermin_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_64_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_65_127_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_128_255_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_256_511_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_512_1023_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_1024_1518_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_1519_2047_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_2048_4095_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_4096_8191_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_8192_9216_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_9217_12287_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_12288_16383_oct_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_1519_max_bad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_1519_max_good_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_oversize_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_jabber_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_bad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_bad_oct_num),
 
+	HINIC3_PORT_STAT(mac_rx_good_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_good_oct_num),
 
+	HINIC3_PORT_STAT(mac_rx_total_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_total_oct_num),
 
+	HINIC3_PORT_STAT(mac_rx_uni_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_multi_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_broad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pause_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri0_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri1_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri2_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri3_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri4_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri5_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri6_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_pfc_pri7_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_control_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_sym_err_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_fcs_err_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_send_app_good_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_send_app_bad_pkt_num),
 
+	HINIC3_PORT_STAT(mac_rx_unfilter_pkt_num),
 
+};
 
+
 
+#define HINIC3_PHYPORT_XSTATS_NUM ARRAY_SIZE(hinic3_phyport_stats_strings)
 
+
 
+#define HINIC3_RXQ_STAT(_stat_item)                                      \
 
+	{                                                                \
 
+		.name = #_stat_item,                                     \
 
+		.offset = offsetof(struct hinic3_rxq_stats, _stat_item), \
 
+	}
 
+
 
+/**
 
+ * The name and offset field of RXQ statistic items.
 
+ *
 
+ * The inclusion of additional statistics depends on the compilation flags:
 
+ * - `HINIC3_XSTAT_RXBUF_INFO` enables buffer-related stats.
 
+ * - `HINIC3_XSTAT_PROF_RX` enables performance timing stats.
 
+ * - `HINIC3_XSTAT_MBUF_USE` enables memory buffer usage stats.
 
+ */
 
+static const struct hinic3_xstats_name_off hinic3_rxq_stats_strings[] = {
 
+	HINIC3_RXQ_STAT(rx_nombuf),
 
+	HINIC3_RXQ_STAT(burst_pkts),
 
+	HINIC3_RXQ_STAT(errors),
 
+	HINIC3_RXQ_STAT(csum_errors),
 
+	HINIC3_RXQ_STAT(other_errors),
 
+	HINIC3_RXQ_STAT(empty),
 
+
 
+#ifdef HINIC3_XSTAT_RXBUF_INFO
 
+	HINIC3_RXQ_STAT(rx_mbuf),
 
+	HINIC3_RXQ_STAT(rx_avail),
 
+	HINIC3_RXQ_STAT(rx_hole),
 
+#endif
 
+
 
+#ifdef HINIC3_XSTAT_PROF_RX
 
+	HINIC3_RXQ_STAT(app_tsc),
 
+	HINIC3_RXQ_STAT(pmd_tsc),
 
+#endif
 
+
 
+#ifdef HINIC3_XSTAT_MBUF_USE
 
+	HINIC3_RXQ_STAT(rx_alloc_mbuf_bytes),
 
+	HINIC3_RXQ_STAT(rx_free_mbuf_bytes),
 
+	HINIC3_RXQ_STAT(rx_left_mbuf_bytes),
 
+#endif
 
+};
 
+
 
+#define HINIC3_RXQ_XSTATS_NUM ARRAY_SIZE(hinic3_rxq_stats_strings)
 
+
 
+#define HINIC3_TXQ_STAT(_stat_item)                                      \
 
+	{                                                                \
 
+		.name = #_stat_item,                                     \
 
+		.offset = offsetof(struct hinic3_txq_stats, _stat_item), \
 
+	}
 
+
 
+/**
 
+ * The name and offset field of TXQ statistic items.
 
+ *
 
+ * The inclusion of additional statistics depends on the compilation flags:
 
+ * - `HINIC3_XSTAT_PROF_TX` enables performance timing stats.
 
+ * - `HINIC3_XSTAT_MBUF_USE` enables memory buffer usage stats.
 
+ */
 
+static const struct hinic3_xstats_name_off hinic3_txq_stats_strings[] = {
 
+	HINIC3_TXQ_STAT(tx_busy),
 
+	HINIC3_TXQ_STAT(offload_errors),
 
+	HINIC3_TXQ_STAT(burst_pkts),
 
+	HINIC3_TXQ_STAT(sge_len0),
 
+	HINIC3_TXQ_STAT(mbuf_null),
 
+
 
+#ifdef HINIC3_XSTAT_PROF_TX
 
+	HINIC3_TXQ_STAT(app_tsc),
 
+	HINIC3_TXQ_STAT(pmd_tsc),
 
+#endif
 
+
 
+#ifdef HINIC3_XSTAT_MBUF_USE
 
+	HINIC3_TXQ_STAT(tx_left_mbuf_bytes),
 
+#endif
 
+};
 
+
 
+#define HINIC3_TXQ_XSTATS_NUM ARRAY_SIZE(hinic3_txq_stats_strings)
 
+
 
+static int
 
+hinic3_xstats_calc_num(struct hinic3_nic_dev *nic_dev)
 
+{
 
+	if (HINIC3_IS_VF(nic_dev->hwdev)) {
 
+		return (HINIC3_VPORT_XSTATS_NUM +
 
+			HINIC3_RXQ_XSTATS_NUM * nic_dev->num_rqs +
 
+			HINIC3_TXQ_XSTATS_NUM * nic_dev->num_sqs);
 
+	} else {
 
+		return (HINIC3_VPORT_XSTATS_NUM + HINIC3_PHYPORT_XSTATS_NUM +
 
+			HINIC3_RXQ_XSTATS_NUM * nic_dev->num_rqs +
 
+			HINIC3_TXQ_XSTATS_NUM * nic_dev->num_sqs);
 
+	}
 
+}
 
+
 
+#define HINIC3_MAX_QUEUE_DEPTH 16384
 
+#define HINIC3_MIN_QUEUE_DEPTH 128
 
+#define HINIC3_TXD_ALIGN       1
 
+#define HINIC3_RXD_ALIGN       1
 
+
 
+static const struct rte_eth_desc_lim hinic3_rx_desc_lim = {
 
+	.nb_max = HINIC3_MAX_QUEUE_DEPTH,
 
+	.nb_min = HINIC3_MIN_QUEUE_DEPTH,
 
+	.nb_align = HINIC3_RXD_ALIGN,
 
+};
 
+
 
+static const struct rte_eth_desc_lim hinic3_tx_desc_lim = {
 
+	.nb_max = HINIC3_MAX_QUEUE_DEPTH,
 
+	.nb_min = HINIC3_MIN_QUEUE_DEPTH,
 
+	.nb_align = HINIC3_TXD_ALIGN,
 
+};
 
+
 
+static void hinic3_deinit_mac_addr(struct rte_eth_dev *eth_dev);
 
+
 
+static int hinic3_copy_mempool_init(struct hinic3_nic_dev *nic_dev);
 
+
 
+static void hinic3_copy_mempool_uninit(struct hinic3_nic_dev *nic_dev);
 
+
 
+/**
 
+ * Interrupt handler triggered by NIC for handling specific event.
 
+ *
 
+ * @param[in] param
 
+ * The address of parameter (struct rte_eth_dev *) registered before.
 
+ */
 
+static void
 
+hinic3_dev_interrupt_handler(void *param)
 
+{
 
+	struct rte_eth_dev *dev = param;
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	if (!hinic3_get_bit(HINIC3_DEV_INTR_EN, &nic_dev->dev_status)) {
 
+		PMD_DRV_LOG(WARNING,
 
+			    "Intr is disabled, ignore intr event, "
 
+			    "dev_name: %s, port_id: %d",
 
+			    nic_dev->dev_name, dev->data->port_id);
 
+		return;
 
+	}
 
+
 
+	/* Aeq0 msg handler. */
 
+	hinic3_dev_handle_aeq_event(nic_dev->hwdev, param);
 
+}
 
+
 
+/**
 
+ * Do the config for TX/Rx queues, include queue number, mtu size and RSS.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_configure(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	nic_dev->num_sqs = dev->data->nb_tx_queues;
 
+	nic_dev->num_rqs = dev->data->nb_rx_queues;
 
+
 
+	if (nic_dev->num_sqs > nic_dev->max_sqs ||
 
+	    nic_dev->num_rqs > nic_dev->max_rqs) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "num_sqs: %d or num_rqs: %d larger than "
 
+			    "max_sqs: %d or max_rqs: %d",
 
+			    nic_dev->num_sqs, nic_dev->num_rqs,
 
+			    nic_dev->max_sqs, nic_dev->max_rqs);
 
+		return -EINVAL;
 
+	}
 
+
 
+	/* The range of mtu is 384~9600. */
 
+
 
+	if (HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode) <
 
+		    HINIC3_MIN_FRAME_SIZE ||
 
+	    HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode) >
 
+		    HINIC3_MAX_JUMBO_FRAME_SIZE) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Max rx pkt len out of range, max_rx_pkt_len: %d, "
 
+			    "expect between %d and %d",
 
+			    HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode),
 
+			    HINIC3_MIN_FRAME_SIZE, HINIC3_MAX_JUMBO_FRAME_SIZE);
 
+		return -EINVAL;
 
+	}
 
+	nic_dev->mtu_size =
 
+		(u16)HINIC3_PKTLEN_TO_MTU(HINIC3_MAX_RX_PKT_LEN(dev->data->dev_conf.rxmode));
 
+	if (dev->data->dev_conf.rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG)
 
+		dev->data->dev_conf.rxmode.offloads |=
 
+			RTE_ETH_RX_OFFLOAD_RSS_HASH;
 
+
 
+	/* Clear fdir filter. */
 
+	hinic3_free_fdir_filter(dev);
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Get information about the device.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[out] info
 
+ * Info structure for ethernet device.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_infos_get(struct rte_eth_dev *dev, struct rte_eth_dev_info *info)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	info->max_rx_queues = nic_dev->max_rqs;
 
+	info->max_tx_queues = nic_dev->max_sqs;
 
+	info->min_rx_bufsize = HINIC3_MIN_RX_BUF_SIZE;
 
+	info->max_rx_pktlen = HINIC3_MAX_JUMBO_FRAME_SIZE;
 
+	info->max_mac_addrs = HINIC3_MAX_UC_MAC_ADDRS;
 
+	info->min_mtu = HINIC3_MIN_MTU_SIZE;
 
+	info->max_mtu = HINIC3_MAX_MTU_SIZE;
 
+	info->max_lro_pkt_size = HINIC3_MAX_LRO_SIZE;
 
+
 
+	info->rx_queue_offload_capa = 0;
 
+	info->rx_offload_capa =
 
+		RTE_ETH_RX_OFFLOAD_VLAN_STRIP | RTE_ETH_RX_OFFLOAD_IPV4_CKSUM |
 
+		RTE_ETH_RX_OFFLOAD_UDP_CKSUM | RTE_ETH_RX_OFFLOAD_TCP_CKSUM |
 
+		RTE_ETH_RX_OFFLOAD_SCTP_CKSUM | RTE_ETH_RX_OFFLOAD_VLAN_FILTER |
 
+		RTE_ETH_RX_OFFLOAD_SCATTER | RTE_ETH_RX_OFFLOAD_TCP_LRO |
 
+		RTE_ETH_RX_OFFLOAD_RSS_HASH;
 
+
 
+	info->tx_queue_offload_capa = 0;
 
+	info->tx_offload_capa =
 
+		RTE_ETH_TX_OFFLOAD_VLAN_INSERT | RTE_ETH_TX_OFFLOAD_IPV4_CKSUM |
 
+		RTE_ETH_TX_OFFLOAD_UDP_CKSUM | RTE_ETH_TX_OFFLOAD_TCP_CKSUM |
 
+		RTE_ETH_TX_OFFLOAD_SCTP_CKSUM |
 
+		RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM |
 
+		RTE_ETH_TX_OFFLOAD_TCP_TSO | RTE_ETH_TX_OFFLOAD_MULTI_SEGS;
 
+
 
+	info->hash_key_size = HINIC3_RSS_KEY_SIZE;
 
+	info->reta_size = HINIC3_RSS_INDIR_SIZE;
 
+	info->flow_type_rss_offloads = HINIC3_RSS_OFFLOAD_ALL;
 
+
 
+	info->rx_desc_lim = hinic3_rx_desc_lim;
 
+	info->tx_desc_lim = hinic3_tx_desc_lim;
 
+
 
+	/* Driver-preferred rx/tx parameters. */
 
+	info->default_rxportconf.burst_size = HINIC3_DEFAULT_BURST_SIZE;
 
+	info->default_txportconf.burst_size = HINIC3_DEFAULT_BURST_SIZE;
 
+	info->default_rxportconf.nb_queues = HINIC3_DEFAULT_NB_QUEUES;
 
+	info->default_txportconf.nb_queues = HINIC3_DEFAULT_NB_QUEUES;
 
+	info->default_rxportconf.ring_size = HINIC3_DEFAULT_RING_SIZE;
 
+	info->default_txportconf.ring_size = HINIC3_DEFAULT_RING_SIZE;
 
+
 
+	return 0;
 
+}
 
+
 
+static int
 
+hinic3_fw_version_get(struct rte_eth_dev *dev, char *fw_version, size_t fw_size)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	char mgmt_ver[MGMT_VERSION_MAX_LEN] = {0};
 
+	int err;
 
+
 
+	err = hinic3_get_mgmt_version(nic_dev->hwdev, mgmt_ver,
 
+				      HINIC3_MGMT_VERSION_MAX_LEN);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Get fw version failed");
 
+		return -EIO;
 
+	}
 
+
 
+	if (fw_size < strlen((char *)mgmt_ver) + 1)
 
+		return (strlen((char *)mgmt_ver) + 1);
 
+
 
+	snprintf(fw_version, fw_size, "%s", mgmt_ver);
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Set ethernet device link state up.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_set_link_up(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	int err;
 
+
 
+	/*
 
+	 * Vport enable will set function valid in mpu.
 
+	 * So dev start status need to be checked before vport enable.
 
+	 */
 
+	if (hinic3_get_bit(HINIC3_DEV_START, &nic_dev->dev_status)) {
 
+		err = hinic3_set_vport_enable(nic_dev->hwdev, true);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR, "Enable vport failed, dev_name: %s",
 
+				    nic_dev->dev_name);
 
+			return err;
 
+		}
 
+	}
 
+
 
+	/* Link status follow phy port status, mpu will open pma. */
 
+	err = hinic3_set_port_enable(nic_dev->hwdev, true);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Set MAC link up failed, dev_name: %s, port_id: %d",
 
+			    nic_dev->dev_name, dev->data->port_id);
 
+		return err;
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Set ethernet device link state down.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_set_link_down(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	int err;
 
+
 
+	err = hinic3_set_vport_enable(nic_dev->hwdev, false);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Disable vport failed, dev_name: %s",
 
+			    nic_dev->dev_name);
 
+		return err;
 
+	}
 
+
 
+	/* Link status follow phy port status, mpu will close pma. */
 
+	err = hinic3_set_port_enable(nic_dev->hwdev, false);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR,
 
+			"Set MAC link down failed, dev_name: %s, port_id: %d",
 
+			nic_dev->dev_name, dev->data->port_id);
 
+		return err;
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Get device physical link information.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] wait_to_complete
 
+ * Wait for request completion.
 
+ *
 
+ * @return
 
+ * 0 : Link status changed
 
+ * -1 : Link status not changed.
 
+ */
 
+static int
 
+hinic3_link_update(struct rte_eth_dev *dev, int wait_to_complete)
 
+{
 
+#define CHECK_INTERVAL	10  /**< 10ms. */
 
+#define MAX_REPEAT_TIME 100 /**< 1s (100 * 10ms) in total. */
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	struct rte_eth_link link;
 
+	u8 link_state;
 
+	unsigned int rep_cnt = MAX_REPEAT_TIME;
 
+	int ret;
 
+
 
+	memset(&link, 0, sizeof(link));
 
+	do {
 
+		/* Get link status information from hardware. */
 
+		ret = hinic3_get_link_state(nic_dev->hwdev, &link_state);
 
+		if (ret) {
 
+			link.link_status = RTE_ETH_LINK_DOWN;
 
+			link.link_speed = RTE_ETH_SPEED_NUM_NONE;
 
+			link.link_duplex = RTE_ETH_LINK_HALF_DUPLEX;
 
+			link.link_autoneg = RTE_ETH_LINK_FIXED;
 
+			goto out;
 
+		}
 
+
 
+		get_port_info(nic_dev->hwdev, link_state, &link);
 
+
 
+		if (!wait_to_complete || link.link_status)
 
+			break;
 
+
 
+		rte_delay_ms(CHECK_INTERVAL);
 
+	} while (rep_cnt--);
 
+
 
+out:
 
+	return rte_eth_linkstatus_set(dev, &link);
 
+}
 
+
 
+/**
 
+ * Reset all RX queues (RXQs).
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ */
 
+static void
 
+hinic3_reset_rx_queue(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_rxq *rxq = NULL;
 
+	struct hinic3_nic_dev *nic_dev;
 
+	int q_id = 0;
 
+
 
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	for (q_id = 0; q_id < nic_dev->num_rqs; q_id++) {
 
+		rxq = nic_dev->rxqs[q_id];
 
+
 
+		rxq->cons_idx = 0;
 
+		rxq->prod_idx = 0;
 
+		rxq->delta = rxq->q_depth;
 
+		rxq->next_to_update = 0;
 
+	}
 
+}
 
+
 
+/**
 
+ * Reset all TX queues (TXQs).
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ */
 
+static void
 
+hinic3_reset_tx_queue(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev;
 
+	struct hinic3_txq *txq = NULL;
 
+	int q_id = 0;
 
+
 
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	for (q_id = 0; q_id < nic_dev->num_sqs; q_id++) {
 
+		txq = nic_dev->txqs[q_id];
 
+
 
+		txq->cons_idx = 0;
 
+		txq->prod_idx = 0;
 
+		txq->owner = 1;
 
+
 
+		/* Clear hardware ci. */
 
+		*txq->ci_vaddr_base = 0;
 
+	}
 
+}
 
+
 
+/**
 
+ * Create the receive queue.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] qid
 
+ * Receive queue index.
 
+ * @param[in] nb_desc
 
+ * Number of descriptors for receive queue.
 
+ * @param[in] socket_id
 
+ * Socket index on which memory must be allocated.
 
+ * @param[in] rx_conf
 
+ * Thresholds parameters (unused_).
 
+ * @param[in] mp
 
+ * Memory pool for buffer allocations.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_rx_queue_setup(struct rte_eth_dev *dev, uint16_t qid, uint16_t nb_desc,
 
+		      unsigned int socket_id,
 
+		      __rte_unused const struct rte_eth_rxconf *rx_conf,
 
+		      struct rte_mempool *mp)
 
+{
 
+	struct hinic3_nic_dev *nic_dev;
 
+	struct hinic3_rxq *rxq = NULL;
 
+	const struct rte_memzone *rq_mz = NULL;
 
+	const struct rte_memzone *cqe_mz = NULL;
 
+	const struct rte_memzone *pi_mz = NULL;
 
+	u16 rq_depth, rx_free_thresh;
 
+	u32 queue_buf_size;
 
+	void *db_addr = NULL;
 
+	int wqe_count;
 
+	u32 buf_size;
 
+	int err;
 
+
 
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	/* Queue depth must be power of 2, otherwise will be aligned up. */
 
+	rq_depth = (nb_desc & (nb_desc - 1))
 
+			   ? ((u16)(1U << (ilog2(nb_desc) + 1)))
 
+			   : nb_desc;
 
+
 
+	/*
 
+	 * Validate number of receive descriptors.
 
+	 * It must not exceed hardware maximum and minimum.
 
+	 */
 
+	if (rq_depth > HINIC3_MAX_QUEUE_DEPTH ||
 
+	    rq_depth < HINIC3_MIN_QUEUE_DEPTH) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "RX queue depth is out of range from %d to %d,"
 
+			    "(nb_desc: %d, q_depth: %d, port: %d queue: %d)",
 
+			    HINIC3_MIN_QUEUE_DEPTH, HINIC3_MAX_QUEUE_DEPTH,
 
+			    (int)nb_desc, (int)rq_depth,
 
+			    (int)dev->data->port_id, (int)qid);
 
+		return -EINVAL;
 
+	}
 
+
 
+	/*
 
+	 * The RX descriptor ring will be cleaned after rxq->rx_free_thresh
 
+	 * descriptors are used or if the number of descriptors required
 
+	 * to transmit a packet is greater than the number of free RX
 
+	 * descriptors.
 
+	 * The following constraints must be satisfied:
 
+	 * - rx_free_thresh must be greater than 0.
 
+	 * - rx_free_thresh must be less than the size of the ring minus 1.
 
+	 * When set to zero use default values.
 
+	 */
 
+	rx_free_thresh = (u16)((rx_conf->rx_free_thresh)
 
+				       ? rx_conf->rx_free_thresh
 
+				       : HINIC3_DEFAULT_RX_FREE_THRESH);
 
+	if (rx_free_thresh >= (rq_depth - 1)) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "rx_free_thresh must be less than the number "
 
+			    "of RX descriptors minus 1, rx_free_thresh: %u "
 
+			    "port: %d queue: %d)",
 
+			    (unsigned int)rx_free_thresh,
 
+			    (int)dev->data->port_id, (int)qid);
 
+
 
+		return -EINVAL;
 
+	}
 
+
 
+	rxq = rte_zmalloc_socket("hinic3_rq", sizeof(struct hinic3_rxq),
 
+				 RTE_CACHE_LINE_SIZE, (int)socket_id);
 
+	if (!rxq) {
 
+		PMD_DRV_LOG(ERR, "Allocate rxq[%d] failed, dev_name: %s", qid,
 
+			    dev->data->name);
 
+
 
+		return -ENOMEM;
 
+	}
 
+
 
+	/* Init rq parameters. */
 
+	rxq->nic_dev = nic_dev;
 
+	nic_dev->rxqs[qid] = rxq;
 
+	rxq->mb_pool = mp;
 
+	rxq->q_id = qid;
 
+	rxq->next_to_update = 0;
 
+	rxq->q_depth = rq_depth;
 
+	rxq->q_mask = rq_depth - 1;
 
+	rxq->delta = rq_depth;
 
+	rxq->cons_idx = 0;
 
+	rxq->prod_idx = 0;
 
+	rxq->rx_free_thresh = rx_free_thresh;
 
+	rxq->rxinfo_align_end = rxq->q_depth - rxq->rx_free_thresh;
 
+	rxq->port_id = dev->data->port_id;
 
+	rxq->wait_time_cycle = HINIC3_RX_WAIT_CYCLE_THRESH;
 
+
 
+	/* If buf_len used for function table, need to translated. */
 
+	u16 rx_buf_size =
 
+		rte_pktmbuf_data_room_size(rxq->mb_pool) - RTE_PKTMBUF_HEADROOM;
 
+	err = hinic3_convert_rx_buf_size(rx_buf_size, &buf_size);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Adjust buf size failed, dev_name: %s",
 
+			    dev->data->name);
 
+		goto adjust_bufsize_fail;
 
+	}
 
+
 
+	if (buf_size >= HINIC3_RX_BUF_SIZE_4K &&
 
+	    buf_size < HINIC3_RX_BUF_SIZE_16K)
 
+		rxq->wqe_type = HINIC3_EXTEND_RQ_WQE;
 
+	else
 
+		rxq->wqe_type = HINIC3_NORMAL_RQ_WQE;
 
+
 
+	rxq->wqebb_shift = HINIC3_RQ_WQEBB_SHIFT + rxq->wqe_type;
 
+	rxq->wqebb_size = (u16)BIT(rxq->wqebb_shift);
 
+
 
+	rxq->buf_len = (u16)buf_size;
 
+	rxq->rx_buff_shift = ilog2(rxq->buf_len);
 
+
 
+	pi_mz = hinic3_dma_zone_reserve(dev, "hinic3_rq_pi", qid, RTE_PGSIZE_4K,
 
+					RTE_CACHE_LINE_SIZE, (int)socket_id);
 
+	if (!pi_mz) {
 
+		PMD_DRV_LOG(ERR, "Allocate rxq[%d] pi_mz failed, dev_name: %s",
 
+			    qid, dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_pi_mz_fail;
 
+	}
 
+	rxq->pi_mz = pi_mz;
 
+	rxq->pi_dma_addr = pi_mz->iova;
 
+	rxq->pi_virt_addr = pi_mz->addr;
 
+
 
+	err = hinic3_alloc_db_addr(nic_dev->hwdev, &db_addr, HINIC3_DB_TYPE_RQ);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Alloc rq doorbell addr failed");
 
+		goto alloc_db_err_fail;
 
+	}
 
+	rxq->db_addr = db_addr;
 
+
 
+	queue_buf_size = BIT(rxq->wqebb_shift) * rq_depth;
 
+	rq_mz = hinic3_dma_zone_reserve(dev, "hinic3_rq_mz", qid,
 
+					queue_buf_size, RTE_PGSIZE_256K,
 
+					(int)socket_id);
 
+	if (!rq_mz) {
 
+		PMD_DRV_LOG(ERR, "Allocate rxq[%d] rq_mz failed, dev_name: %s",
 
+			    qid, dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_rq_mz_fail;
 
+	}
 
+
 
+	memset(rq_mz->addr, 0, queue_buf_size);
 
+	rxq->rq_mz = rq_mz;
 
+	rxq->queue_buf_paddr = rq_mz->iova;
 
+	rxq->queue_buf_vaddr = rq_mz->addr;
 
+
 
+	rxq->rx_info = rte_zmalloc_socket("rx_info",
 
+					  rq_depth * sizeof(*rxq->rx_info),
 
+					  RTE_CACHE_LINE_SIZE, (int)socket_id);
 
+	if (!rxq->rx_info) {
 
+		PMD_DRV_LOG(ERR, "Allocate rx_info failed, dev_name: %s",
 
+			    dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_rx_info_fail;
 
+	}
 
+
 
+	cqe_mz = hinic3_dma_zone_reserve(dev, "hinic3_cqe_mz", qid,
 
+					 rq_depth * sizeof(*rxq->rx_cqe),
 
+					 RTE_CACHE_LINE_SIZE, (int)socket_id);
 
+	if (!cqe_mz) {
 
+		PMD_DRV_LOG(ERR, "Allocate cqe mem zone failed, dev_name: %s",
 
+			    dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_cqe_mz_fail;
 
+	}
 
+	memset(cqe_mz->addr, 0, rq_depth * sizeof(*rxq->rx_cqe));
 
+	rxq->cqe_mz = cqe_mz;
 
+	rxq->cqe_start_paddr = cqe_mz->iova;
 
+	rxq->cqe_start_vaddr = cqe_mz->addr;
 
+	rxq->rx_cqe = (struct hinic3_rq_cqe *)rxq->cqe_start_vaddr;
 
+

drivers/net/hinic3/hinic3_ethdev.c line 851

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+	wqe_count = hinic3_rx_fill_wqe(rxq);
 
+	if (wqe_count != rq_depth) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Fill rx wqe failed, wqe_count: %d, dev_name: %s",
 
+			    wqe_count, dev->data->name);

As said before, please wrap an macro e.g. hinic3_err(hwdev, ...), it could output device name default.

Quoted 88 lines
drivers/net/hinic3/hinic3_ethdev.c +44 -0
+		err = -ENOMEM;
 
+		goto fill_rx_wqe_fail;
 
+	}
 
+	/* Record rxq pointer in rte_eth rx_queues. */
 
+	dev->data->rx_queues[qid] = rxq;
 
+
 
+	return 0;
 
+
 
+fill_rx_wqe_fail:
 
+	hinic3_memzone_free(rxq->cqe_mz);
 
+alloc_cqe_mz_fail:
 
+	rte_free(rxq->rx_info);
 
+
 
+alloc_rx_info_fail:
 
+	hinic3_memzone_free(rxq->rq_mz);
 
+
 
+alloc_rq_mz_fail:
 
+alloc_db_err_fail:
 
+	hinic3_memzone_free(rxq->pi_mz);
 
+
 
+alloc_pi_mz_fail:
 
+adjust_bufsize_fail:
 
+	rte_free(rxq);
 
+	nic_dev->rxqs[qid] = NULL;
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Create the transmit queue.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] queue_idx
 
+ * Transmit queue index.
 
+ * @param[in] nb_desc
 
+ * Number of descriptors for transmit queue.
 
+ * @param[in] socket_id
 
+ * Socket index on which memory must be allocated.
 
+ * @param[in] tx_conf
 
+ * Tx queue configuration parameters (unused_).
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.

drivers/net/hinic3/hinic3_ethdev.c line 900

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+ */
 
+static int
 
+hinic3_tx_queue_setup(struct rte_eth_dev *dev, uint16_t qid, uint16_t nb_desc,
 
+		      unsigned int socket_id,
 
+		      __rte_unused const struct rte_eth_txconf *tx_conf)

tx_conf should not add unused prefix.

Quoted 128 lines
drivers/net/hinic3/hinic3_ethdev.c +64 -0
+{
 
+	struct hinic3_nic_dev *nic_dev;
 
+	struct hinic3_hwdev *hwdev;
 
+	struct hinic3_txq *txq = NULL;
 
+	const struct rte_memzone *sq_mz = NULL;
 
+	const struct rte_memzone *ci_mz = NULL;
 
+	void *db_addr = NULL;
 
+	u16 sq_depth, tx_free_thresh;
 
+	u32 queue_buf_size;
 
+	int err;
 
+
 
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	hwdev = nic_dev->hwdev;
 
+
 
+	/* Queue depth must be power of 2, otherwise will be aligned up. */
 
+	sq_depth = (nb_desc & (nb_desc - 1))
 
+			   ? ((u16)(1U << (ilog2(nb_desc) + 1)))
 
+			   : nb_desc;
 
+
 
+	/*
 
+	 * Validate number of transmit descriptors.
 
+	 * It must not exceed hardware maximum and minimum.
 
+	 */
 
+	if (sq_depth > HINIC3_MAX_QUEUE_DEPTH ||
 
+	    sq_depth < HINIC3_MIN_QUEUE_DEPTH) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "TX queue depth is out of range from %d to %d,"
 
+			    "(nb_desc: %d, q_depth: %d, port: %d queue: %d)",
 
+			    HINIC3_MIN_QUEUE_DEPTH, HINIC3_MAX_QUEUE_DEPTH,
 
+			    (int)nb_desc, (int)sq_depth,
 
+			    (int)dev->data->port_id, (int)qid);
 
+		return -EINVAL;
 
+	}
 
+
 
+	/*
 
+	 * The TX descriptor ring will be cleaned after txq->tx_free_thresh
 
+	 * descriptors are used or if the number of descriptors required
 
+	 * to transmit a packet is greater than the number of free TX
 
+	 * descriptors.
 
+	 * The following constraints must be satisfied:
 
+	 * - tx_free_thresh must be greater than 0.
 
+	 * - tx_free_thresh must be less than the size of the ring minus 1.
 
+	 * When set to zero use default values.
 
+	 */
 
+	tx_free_thresh = (u16)((tx_conf->tx_free_thresh)
 
+				       ? tx_conf->tx_free_thresh
 
+				       : HINIC3_DEFAULT_TX_FREE_THRESH);
 
+	if (tx_free_thresh >= (sq_depth - 1)) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "tx_free_thresh must be less than the number of tx "
 
+			    "descriptors minus 1, tx_free_thresh: %u port: %d "
 
+			    "queue: %d",
 
+			    (unsigned int)tx_free_thresh,
 
+			    (int)dev->data->port_id, (int)qid);
 
+		return -EINVAL;
 
+	}
 
+
 
+	txq = rte_zmalloc_socket("hinic3_tx_queue", sizeof(struct hinic3_txq),
 
+				 RTE_CACHE_LINE_SIZE, (int)socket_id);
 
+	if (!txq) {
 
+		PMD_DRV_LOG(ERR, "Allocate txq[%d] failed, dev_name: %s", qid,
 
+			    dev->data->name);
 
+		return -ENOMEM;
 
+	}

drivers/net/hinic3/hinic3_ethdev.c line 969

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+	nic_dev->txqs[qid] = txq;
 
+	txq->nic_dev = nic_dev;
 
+	txq->q_id = qid;
 
+	txq->q_depth = sq_depth;
 
+	txq->q_mask = sq_depth - 1;

the sq_depth maynot 2's power, so the q_mask maybe not valid.

Quoted 162 lines
drivers/net/hinic3/hinic3_ethdev.c +81 -0
+	txq->cons_idx = 0;
 
+	txq->prod_idx = 0;
 
+	txq->wqebb_shift = HINIC3_SQ_WQEBB_SHIFT;
 
+	txq->wqebb_size = (u16)BIT(txq->wqebb_shift);
 
+	txq->tx_free_thresh = tx_free_thresh;
 
+	txq->owner = 1;
 
+	txq->cos = nic_dev->default_cos;
 
+
 
+	ci_mz = hinic3_dma_zone_reserve(dev, "hinic3_sq_ci", qid,
 
+					HINIC3_CI_Q_ADDR_SIZE,
 
+					HINIC3_CI_Q_ADDR_SIZE, (int)socket_id);
 
+	if (!ci_mz) {
 
+		PMD_DRV_LOG(ERR, "Allocate txq[%d] ci_mz failed, dev_name: %s",
 
+			    qid, dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_ci_mz_fail;
 
+	}
 
+	txq->ci_mz = ci_mz;
 
+	txq->ci_dma_base = ci_mz->iova;
 
+	txq->ci_vaddr_base = (volatile u16 *)ci_mz->addr;
 
+
 
+	queue_buf_size = BIT(txq->wqebb_shift) * sq_depth;
 
+	sq_mz = hinic3_dma_zone_reserve(dev, "hinic3_sq_mz", qid,
 
+					queue_buf_size, RTE_PGSIZE_256K,
 
+					(int)socket_id);
 
+	if (!sq_mz) {
 
+		PMD_DRV_LOG(ERR, "Allocate txq[%d] sq_mz failed, dev_name: %s",
 
+			    qid, dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_sq_mz_fail;
 
+	}
 
+	memset(sq_mz->addr, 0, queue_buf_size);
 
+	txq->sq_mz = sq_mz;
 
+	txq->queue_buf_paddr = sq_mz->iova;
 
+	txq->queue_buf_vaddr = sq_mz->addr;
 
+	txq->sq_head_addr = (u64)txq->queue_buf_vaddr;
 
+	txq->sq_bot_sge_addr = txq->sq_head_addr + queue_buf_size;
 
+
 
+	err = hinic3_alloc_db_addr(hwdev, &db_addr, HINIC3_DB_TYPE_SQ);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Alloc sq doorbell addr failed");
 
+		goto alloc_db_err_fail;
 
+	}
 
+	txq->db_addr = db_addr;
 
+
 
+	txq->tx_info = rte_zmalloc_socket("tx_info",
 
+					  sq_depth * sizeof(*txq->tx_info),
 
+					  RTE_CACHE_LINE_SIZE, (int)socket_id);
 
+	if (!txq->tx_info) {
 
+		PMD_DRV_LOG(ERR, "Allocate tx_info failed, dev_name: %s",
 
+			    dev->data->name);
 
+		err = -ENOMEM;
 
+		goto alloc_tx_info_fail;
 
+	}
 
+
 
+	/* Record txq pointer in rte_eth tx_queues. */
 
+	dev->data->tx_queues[qid] = txq;
 
+
 
+	return 0;
 
+
 
+alloc_tx_info_fail:
 
+alloc_db_err_fail:
 
+	hinic3_memzone_free(txq->sq_mz);
 
+
 
+alloc_sq_mz_fail:
 
+	hinic3_memzone_free(txq->ci_mz);
 
+
 
+alloc_ci_mz_fail:
 
+	rte_free(txq);
 
+	return err;
 
+}
 
+
 
+static void
 
+hinic3_rx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
 
+{
 
+	if (dev == NULL || dev->data == NULL || dev->data->rx_queues == NULL) {
 
+		PMD_DRV_LOG(WARNING, "rx queue is null when release");
 
+		return;
 
+	}
 
+	if (queue_id >= dev->data->nb_rx_queues) {
 
+		PMD_DRV_LOG(WARNING, "eth_dev: %s, rx queue id: %u is illegal",

drivers/net/hinic3/hinic3_ethdev.c line 1055

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+			    dev->data->name, queue_id);
 
+		return;
 
+	}
 
+	struct hinic3_rxq *rxq = dev->data->rx_queues[queue_id];
 
+	struct hinic3_nic_dev *nic_dev = NULL;

please define the local variables in the beginning of function.

Quoted 166 lines
drivers/net/hinic3/hinic3_ethdev.c +83 -0
+
 
+	if (!rxq) {
 
+		PMD_DRV_LOG(WARNING, "Rxq is null when release");
 
+		return;
 
+	}
 
+
 
+	nic_dev = rxq->nic_dev;
 
+
 
+	hinic3_free_rxq_mbufs(rxq);
 
+
 
+	hinic3_memzone_free(rxq->cqe_mz);
 
+
 
+	rte_free(rxq->rx_info);
 
+	rxq->rx_info = NULL;
 
+
 
+	hinic3_memzone_free(rxq->rq_mz);
 
+
 
+	hinic3_memzone_free(rxq->pi_mz);
 
+
 
+	nic_dev->rxqs[rxq->q_id] = NULL;
 
+	rte_free(rxq);
 
+	dev->data->rx_queues[queue_id] = NULL;
 
+}
 
+
 
+static void
 
+hinic3_tx_queue_release(struct rte_eth_dev *dev, uint16_t queue_id)
 
+{
 
+	if (dev == NULL || dev->data == NULL || dev->data->tx_queues == NULL) {
 
+		PMD_DRV_LOG(WARNING, "tx queue is null when release");
 
+		return;
 
+	}
 
+	if (queue_id >= dev->data->nb_tx_queues) {
 
+		PMD_DRV_LOG(WARNING, "eth_dev: %s, tx queue id: %u is illegal",
 
+			    dev->data->name, queue_id);
 
+		return;
 
+	}
 
+	struct hinic3_txq *txq = dev->data->tx_queues[queue_id];
 
+	struct hinic3_nic_dev *nic_dev = NULL;
 
+
 
+	if (!txq) {
 
+		PMD_DRV_LOG(WARNING, "Txq is null when release");
 
+		return;
 
+	}
 
+	PMD_DRV_LOG(INFO, "%s txq_idx:%d queue release.",
 
+		    txq->nic_dev->dev_name, txq->q_id);
 
+	nic_dev = txq->nic_dev;
 
+
 
+	hinic3_free_txq_mbufs(txq);
 
+
 
+	rte_free(txq->tx_info);
 
+	txq->tx_info = NULL;
 
+
 
+	hinic3_memzone_free(txq->sq_mz);
 
+
 
+	hinic3_memzone_free(txq->ci_mz);
 
+
 
+	nic_dev->txqs[txq->q_id] = NULL;
 
+	rte_free(txq);
 
+	dev->data->tx_queues[queue_id] = NULL;
 
+}
 
+
 
+/**
 
+ * Start RXQ and enables flow director (fdir) filter for RXQ.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] rq_id
 
+ * RX queue ID to be started.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_rx_queue_start(__rte_unused struct rte_eth_dev *dev,
 
+			  __rte_unused uint16_t rq_id)
 
+{
 
+	struct hinic3_rxq *rxq = NULL;
 
+	int rc;
 
+
 
+	if (rq_id < dev->data->nb_rx_queues) {
 
+		rxq = dev->data->rx_queues[rq_id];
 
+
 
+		rc = hinic3_start_rq(dev, rxq);

drivers/net/hinic3/hinic3_ethdev.c line 1143

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+		if (rc) {
 
+			PMD_DRV_LOG(ERR,
 
+				    "Start rx queue failed, eth_dev:%s, "
 
+				    "queue_idx:%d",
 
+				    dev->data->name, rq_id);

need to disable the rq other than immediately return.

Quoted 92 lines
drivers/net/hinic3/hinic3_ethdev.c +46 -0
+			return rc;
 
+		}
 
+
 
+		dev->data->rx_queue_state[rq_id] = RTE_ETH_QUEUE_STATE_STARTED;
 
+	}
 
+	rc = hinic3_enable_rxq_fdir_filter(dev, (u32)rq_id, (u32)true);
 
+	if (rc) {
 
+		PMD_DRV_LOG(ERR, "Failed to enable rq : %d fdir filter.",
 
+			    rq_id);
 
+		return rc;
 
+	}
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Stop RXQ and disable flow director (fdir) filter for RXQ.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] rq_id
 
+ * RX queue ID to be stopped.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_rx_queue_stop(__rte_unused struct rte_eth_dev *dev,
 
+			 __rte_unused uint16_t rq_id)
 
+{
 
+	struct hinic3_rxq *rxq = NULL;
 
+	int rc;
 
+
 
+	if (rq_id < dev->data->nb_rx_queues) {
 
+		rxq = dev->data->rx_queues[rq_id];
 
+
 
+		rc = hinic3_stop_rq(dev, rxq);
 
+		if (rc) {
 
+			PMD_DRV_LOG(ERR,
 
+				    "Stop rx queue failed, eth_dev:%s, "
 
+				    "queue_idx:%d",
 
+				    dev->data->name, rq_id);
 
+			return rc;
 
+		}
 
+
 
+		dev->data->rx_queue_state[rq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
 
+	}

drivers/net/hinic3/hinic3_ethdev.c line 1194

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+	rc = hinic3_enable_rxq_fdir_filter(dev, (u32)rq_id, (u32)false);
 
+	if (rc) {
 
+		PMD_DRV_LOG(ERR, "Failed to disable rq : %d fdir filter.",
 
+			    rq_id);
 
+		return rc;

should invoke this subcode before disable rq.

Quoted 210 lines
drivers/net/hinic3/hinic3_ethdev.c +105 -0
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+static int
 
+hinic3_dev_tx_queue_start(__rte_unused struct rte_eth_dev *dev,
 
+			  __rte_unused uint16_t sq_id)
 
+{
 
+	struct hinic3_txq *txq = NULL;
 
+
 
+	PMD_DRV_LOG(INFO, "Start tx queue, eth_dev:%s, queue_idx:%d",
 
+		    dev->data->name, sq_id);
 
+
 
+	txq = dev->data->tx_queues[sq_id];
 
+	HINIC3_SET_TXQ_STARTED(txq);
 
+	dev->data->tx_queue_state[sq_id] = RTE_ETH_QUEUE_STATE_STARTED;
 
+	return 0;
 
+}
 
+
 
+static int
 
+hinic3_dev_tx_queue_stop(__rte_unused struct rte_eth_dev *dev,
 
+			 __rte_unused uint16_t sq_id)
 
+{
 
+	struct hinic3_txq *txq = NULL;
 
+	int rc;
 
+
 
+	if (sq_id < dev->data->nb_tx_queues) {
 
+		txq = dev->data->tx_queues[sq_id];
 
+		rc = hinic3_stop_sq(txq);
 
+		if (rc) {
 
+			PMD_DRV_LOG(ERR,
 
+				    "Stop tx queue failed, eth_dev:%s, "
 
+				    "queue_idx:%d",
 
+				    dev->data->name, sq_id);
 
+			return rc;
 
+		}
 
+
 
+		HINIC3_SET_TXQ_STOPPED(txq);
 
+		dev->data->tx_queue_state[sq_id] = RTE_ETH_QUEUE_STATE_STOPPED;
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id)
 
+{
 
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
+	struct rte_intr_handle *intr_handle = PCI_DEV_TO_INTR_HANDLE(pci_dev);
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u16 msix_intr;
 
+
 
+	if (!rte_intr_dp_is_en(intr_handle) || !intr_handle->intr_vec)
 
+		return 0;
 
+
 
+	if (queue_id >= dev->data->nb_rx_queues)
 
+		return -EINVAL;
 
+
 
+	msix_intr = (u16)intr_handle->intr_vec[queue_id];
 
+	hinic3_set_msix_auto_mask_state(nic_dev->hwdev, msix_intr,
 
+					HINIC3_SET_MSIX_AUTO_MASK);
 
+	hinic3_set_msix_state(nic_dev->hwdev, msix_intr, HINIC3_MSIX_ENABLE);
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev, uint16_t queue_id)
 
+{
 
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
+	struct rte_intr_handle *intr_handle = PCI_DEV_TO_INTR_HANDLE(pci_dev);
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u16 msix_intr;
 
+
 
+	if (!rte_intr_dp_is_en(intr_handle) || !intr_handle->intr_vec)
 
+		return 0;
 
+
 
+	if (queue_id >= dev->data->nb_rx_queues)
 
+		return -EINVAL;
 
+
 
+	msix_intr = (u16)intr_handle->intr_vec[queue_id];
 
+	hinic3_set_msix_auto_mask_state(nic_dev->hwdev, msix_intr,
 
+					HINIC3_CLR_MSIX_AUTO_MASK);
 
+	hinic3_set_msix_state(nic_dev->hwdev, msix_intr, HINIC3_MSIX_DISABLE);
 
+	hinic3_misx_intr_clear_resend_bit(nic_dev->hwdev, msix_intr,
 
+					  MSIX_RESEND_TIMER_CLEAR);
 
+
 
+	return 0;
 
+}
 
+
 
+static uint32_t
 
+hinic3_dev_rx_queue_count(__rte_unused void *rx_queue)
 
+{
 
+	return 0;
 
+}
 
+
 
+static int
 
+hinic3_dev_rx_descriptor_status(__rte_unused void *rx_queue,
 
+				__rte_unused uint16_t offset)
 
+{
 
+	return 0;
 
+}
 
+
 
+static int

drivers/net/hinic3/hinic3_ethdev.c line 1304

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
 
+hinic3_dev_tx_descriptor_status(__rte_unused void *tx_queue,
 
+				__rte_unused uint16_t offset)
 
+{
 
+	return 0;
 
+}

the above thress ops was not necessary to impl, you could impl later or don't impl it.

Quoted 1,046 lines
drivers/net/hinic3/hinic3_ethdev.c +523 -0
+
 
+static int
 
+hinic3_set_lro(struct hinic3_nic_dev *nic_dev, struct rte_eth_conf *dev_conf)
 
+{
 
+	bool lro_en;
 
+	int max_lro_size, lro_max_pkt_len;
 
+	int err;
 
+
 
+	/* Config lro. */
 
+	lro_en = dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_TCP_LRO ? true
 
+									: false;
 
+	max_lro_size = (int)(dev_conf->rxmode.max_lro_pkt_size);
 
+	/* `max_lro_size` is divisible by `HINIC3_LRO_UNIT_WQE_SIZE`. */
 
+	lro_max_pkt_len = max_lro_size / HINIC3_LRO_UNIT_WQE_SIZE
 
+				  ? max_lro_size / HINIC3_LRO_UNIT_WQE_SIZE
 
+				  : 1;
 
+
 
+	PMD_DRV_LOG(INFO,
 
+		    "max_lro_size: %d, rx_buff_len: %d, lro_max_pkt_len: %d",
 
+		    max_lro_size, nic_dev->rx_buff_len, lro_max_pkt_len);
 
+	PMD_DRV_LOG(INFO, "max_rx_pkt_len: %d",
 
+		    HINIC3_MAX_RX_PKT_LEN(dev_conf->rxmode));
 
+	err = hinic3_set_rx_lro_state(nic_dev->hwdev, lro_en,
 
+				      HINIC3_LRO_DEFAULT_TIME_LIMIT,
 
+				      lro_max_pkt_len);
 
+	if (err)
 
+		PMD_DRV_LOG(ERR, "Set lro state failed, err: %d", err);
 
+	return err;
 
+}
 
+
 
+static int
 
+hinic3_set_vlan(struct rte_eth_dev *dev, struct rte_eth_conf *dev_conf)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	bool vlan_filter, vlan_strip;
 
+	int err;
 
+
 
+	/* Config vlan filter. */
 
+	vlan_filter = dev_conf->rxmode.offloads &
 
+		      RTE_ETH_RX_OFFLOAD_VLAN_FILTER;
 
+
 
+	err = hinic3_set_vlan_filter(nic_dev->hwdev, vlan_filter);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Config vlan filter failed, device: %s, port_id: "
 
+			    "%d, err: %d",
 
+			    nic_dev->dev_name, dev->data->port_id, err);
 
+		return err;
 
+	}
 
+
 
+	/* Config vlan stripping. */
 
+	vlan_strip = dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_VLAN_STRIP;
 
+
 
+	err = hinic3_set_rx_vlan_offload(nic_dev->hwdev, vlan_strip);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Config vlan strip failed, device: %s, port_id: "
 
+			    "%d, err: %d",
 
+			    nic_dev->dev_name, dev->data->port_id, err);
 
+	}
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Configure RX mode, checksum offload, LRO, RSS, VLAN and initialize the RXQ
 
+ * list.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_set_rxtx_configure(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	struct rte_eth_conf *dev_conf = &dev->data->dev_conf;
 
+	struct rte_eth_rss_conf *rss_conf = NULL;
 
+	int err;
 
+
 
+	/* Config rx mode. */
 
+	err = hinic3_set_rx_mode(nic_dev->hwdev, HINIC3_DEFAULT_RX_MODE);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Set rx_mode: 0x%x failed",
 
+			    HINIC3_DEFAULT_RX_MODE);
 
+		return err;
 
+	}
 
+	nic_dev->rx_mode = HINIC3_DEFAULT_RX_MODE;
 
+
 
+	/* Config rx checksum offload. */
 
+	if (dev_conf->rxmode.offloads & RTE_ETH_RX_OFFLOAD_CHECKSUM)
 
+		nic_dev->rx_csum_en = HINIC3_DEFAULT_RX_CSUM_OFFLOAD;
 
+
 
+	err = hinic3_set_lro(nic_dev, dev_conf);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Set lro failed");
 
+		return err;
 
+	}
 
+	/* Config RSS. */
 
+	if ((dev_conf->rxmode.mq_mode & RTE_ETH_MQ_RX_RSS_FLAG) &&
 
+	    nic_dev->num_rqs > 1) {
 
+		rss_conf = &dev_conf->rx_adv_conf.rss_conf;
 
+		err = hinic3_update_rss_config(dev, rss_conf);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR, "Set rss config failed, err: %d", err);
 
+			return err;
 
+		}
 
+	}
 
+
 
+	err = hinic3_set_vlan(dev, dev_conf);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Set vlan failed, err: %d", err);
 
+		return err;
 
+	}
 
+
 
+	hinic3_init_rx_queue_list(nic_dev);
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Disable RX mode and RSS, and free associated resources.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ */
 
+static void
 
+hinic3_remove_rxtx_configure(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u8 prio_tc[HINIC3_DCB_UP_MAX] = {0};
 
+
 
+	hinic3_set_rx_mode(nic_dev->hwdev, 0);
 
+
 
+	if (nic_dev->rss_state == HINIC3_RSS_ENABLE) {
 
+		hinic3_rss_cfg(nic_dev->hwdev, HINIC3_RSS_DISABLE, 0, prio_tc);
 
+		hinic3_rss_template_free(nic_dev->hwdev);
 
+		nic_dev->rss_state = HINIC3_RSS_DISABLE;
 
+	}
 
+}
 
+
 
+static bool
 
+hinic3_find_vlan_filter(struct hinic3_nic_dev *nic_dev, uint16_t vlan_id)
 
+{
 
+	u32 vid_idx, vid_bit;
 
+
 
+	vid_idx = HINIC3_VFTA_IDX(vlan_id);
 
+	vid_bit = HINIC3_VFTA_BIT(vlan_id);
 
+
 
+	return (nic_dev->vfta[vid_idx] & vid_bit) ? true : false;
 
+}
 
+
 
+static void
 
+hinic3_store_vlan_filter(struct hinic3_nic_dev *nic_dev, u16 vlan_id, bool on)
 
+{
 
+	u32 vid_idx, vid_bit;
 
+
 
+	vid_idx = HINIC3_VFTA_IDX(vlan_id);
 
+	vid_bit = HINIC3_VFTA_BIT(vlan_id);
 
+
 
+	if (on)
 
+		nic_dev->vfta[vid_idx] |= vid_bit;
 
+	else
 
+		nic_dev->vfta[vid_idx] &= ~vid_bit;
 
+}
 
+
 
+static void
 
+hinic3_remove_all_vlanid(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	int vlan_id;
 
+	u16 func_id;
 
+
 
+	func_id = hinic3_global_func_id(nic_dev->hwdev);
 
+
 
+	for (vlan_id = 1; vlan_id < RTE_ETHER_MAX_VLAN_ID; vlan_id++) {
 
+		if (hinic3_find_vlan_filter(nic_dev, vlan_id)) {
 
+			hinic3_del_vlan(nic_dev->hwdev, vlan_id, func_id);
 
+			hinic3_store_vlan_filter(nic_dev, vlan_id, false);
 
+		}
 
+	}
 
+}
 
+
 
+static void
 
+hinic3_disable_interrupt(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
+
 
+	if (!hinic3_get_bit(HINIC3_DEV_INIT, &nic_dev->dev_status))
 
+		return;
 
+
 
+	/* Disable rte interrupt. */
 
+	rte_intr_disable(PCI_DEV_TO_INTR_HANDLE(pci_dev));
 
+	rte_intr_callback_unregister(PCI_DEV_TO_INTR_HANDLE(pci_dev),
 
+				     hinic3_dev_interrupt_handler, (void *)dev);
 
+}
 
+
 
+static void
 
+hinic3_enable_interrupt(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	struct rte_pci_device *pci_dev = RTE_ETH_DEV_TO_PCI(dev);
 
+
 
+	if (!hinic3_get_bit(HINIC3_DEV_INIT, &nic_dev->dev_status))
 
+		return;
 
+
 
+	/* Enable rte interrupt. */
 
+	rte_intr_enable(PCI_DEV_TO_INTR_HANDLE(pci_dev));
 
+	rte_intr_callback_register(PCI_DEV_TO_INTR_HANDLE(pci_dev),
 
+				   hinic3_dev_interrupt_handler, (void *)dev);
 
+}
 
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

drivers/net/hinic3/hinic3_ethdev.c

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +5 -0
+
 
+#define HINIC3_RX_VEC_START RTE_INTR_VEC_RXTX_OFFSET
 
+
 
+/** Dp interrupt msix attribute. */
 
+#define HINIC3_TXRX_MSIX_PENDING_LIMIT	  2
 
[… more lines in the raw message]

please wrap these lines as one independ function:

drivers/net/hinic3/hinic3_ethdev.c

Quoted 116 lines
drivers/net/hinic3/hinic3_ethdev.c +58 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

It may lead to memroy leakage when remove driver.

Quoted 7,743 lines
drivers/net/hinic3/hinic3_ethdev.c +1036 -17

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/hinic3_nic_io.c +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..2d5a60efe5

--- /dev/null

+++ b/drivers/net/hinic3/hinic3_nic_io.c

drivers/net/hinic3/hinic3_nic_io.c +828 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/hinic3_nic_io.h +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..774247dc56

--- /dev/null

+++ b/drivers/net/hinic3/hinic3_nic_io.h

drivers/net/hinic3/hinic3_nic_io.h +169 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/hinic3_rx.c +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..6fe565984b

--- /dev/null

+++ b/drivers/net/hinic3/hinic3_rx.c

drivers/net/hinic3/hinic3_rx.c +814 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/hinic3_rx.h +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..02e5cc61f1

--- /dev/null

+++ b/drivers/net/hinic3/hinic3_rx.h

drivers/net/hinic3/hinic3_rx.h +356 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/hinic3_tx.c +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..6f8c42e0c3

--- /dev/null

+++ b/drivers/net/hinic3/hinic3_tx.c

drivers/net/hinic3/hinic3_tx.c +274 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/hinic3_tx.h +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..f4c61ea1b1

--- /dev/null

+++ b/drivers/net/hinic3/hinic3_tx.h

drivers/net/hinic3/hinic3_tx.h +314 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#153 lore raw

PATCH v5 14/18 net/hinic3: add Rx/Tx functions

In reply to Feifei Wang

From: Feifei Wang <[email protected]>

This patch add package sending and receiving function codes.

---
 drivers/net/hinic3/hinic3_ethdev.c |  15 +-
 drivers/net/hinic3/hinic3_rx.c     | 305 +++++++++++-
 drivers/net/hinic3/hinic3_tx.c     | 754 +++++++++++++++++++++++++++++
 drivers/net/hinic3/hinic3_tx.h     |   1 +
 4 files changed, 1059 insertions(+), 16 deletions(-)
drivers/net/hinic3/hinic3_ethdev.c +9 -6
index d9bca3aeb3..47b47b7412 100644
@@ -21,9 +21,9 @@
 #include "base/hinic3_hw_comm.h"
 #include "base/hinic3_nic_cfg.h"
 #include "base/hinic3_nic_event.h"
-#include "hinic3_pmd_nic_io.h"
-#include "hinic3_pmd_tx.h"
-#include "hinic3_pmd_rx.h"
+#include "hinic3_nic_io.h"
+#include "hinic3_tx.h"
+#include "hinic3_rx.h"
 #include "hinic3_ethdev.h"
 
 #define HINIC3_MIN_RX_BUF_SIZE 1024
@@ -1521,7 +1521,7 @@ hinic3_enable_interrupt(struct rte_eth_dev *dev)
 
 /** Dp interrupt msix attribute. */
 #define HINIC3_TXRX_MSIX_PENDING_LIMIT	  2
-#define HINIC3_TXRX_MSIX_COALESC_TIMER	  2
+#define HINIC3_TXRX_MSIX_COALESCE_TIMER	  2
 #define HINIC3_TXRX_MSIX_RESEND_TIMER_CFG 7
 
 static int
@@ -1531,9 +1531,9 @@ hinic3_init_rxq_msix_attr(void *hwdev, u16 msix_index)
 	int err;
 
 	info.lli_set = 0;
-	info.interrupt_coalesc_set = 1;
+	info.interrupt_coalesce_set = 1;
 	info.pending_limt = HINIC3_TXRX_MSIX_PENDING_LIMIT;
-	info.coalesc_timer_cfg = HINIC3_TXRX_MSIX_COALESC_TIMER;
+	info.coalesce_timer_cfg = HINIC3_TXRX_MSIX_COALESCE_TIMER;
 	info.resend_timer_cfg = HINIC3_TXRX_MSIX_RESEND_TIMER_CFG;
 
 	info.msix_index = msix_index;
@@ -3337,6 +3337,9 @@ hinic3_dev_init(struct rte_eth_dev *eth_dev)
 	PMD_DRV_LOG(INFO, "Network Interface pmd driver version: %s",
 		    HINIC3_PMD_DRV_VERSION);
 
+	eth_dev->rx_pkt_burst = hinic3_recv_pkts;
+	eth_dev->tx_pkt_burst = hinic3_xmit_pkts;
+
 	return hinic3_func_init(eth_dev);
 }
 
drivers/net/hinic3/hinic3_rx.c +295 -10

326 lines not on this page · raw message

drivers/net/hinic3/hinic3_tx.c +754 -0

766 lines not on this page · raw message

drivers/net/hinic3/hinic3_tx.h +1 -0
index f4c61ea1b1..6026b3fabc 100644
@@ -308,6 +308,7 @@ struct __rte_cache_aligned hinic3_txq {
 void hinic3_flush_txqs(struct hinic3_nic_dev *nic_dev);
 void hinic3_free_txq_mbufs(struct hinic3_txq *txq);
 void hinic3_free_all_txq_mbufs(struct hinic3_nic_dev *nic_dev);
+u16 hinic3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, u16 nb_pkts);
 int hinic3_stop_sq(struct hinic3_txq *txq);
 int hinic3_start_all_sqs(struct rte_eth_dev *eth_dev);
 int hinic3_tx_done_cleanup(void *txq, uint32_t free_cnt);
Signature · 1 line
2.45.1.windows.1
#154 lore raw

Re: [V5 14/18] net/hinic3: add Rx/Tx functions

Quoted 62 lines · Feifei Wang

From: Feifei Wang <[email protected]>

This patch add package sending and receiving function codes.

---

 drivers/net/hinic3/hinic3_ethdev.c |  15 +-
 drivers/net/hinic3/hinic3_rx.c     | 305 +++++++++++-
 drivers/net/hinic3/hinic3_tx.c     | 754 +++++++++++++++++++++++++++++
 drivers/net/hinic3/hinic3_tx.h     |   1 +
 4 files changed, 1059 insertions(+), 16 deletions(-)
drivers/net/hinic3/hinic3_ethdev.c +0 -0

index d9bca3aeb3..47b47b7412 100644

--- a/drivers/net/hinic3/hinic3_ethdev.c

+++ b/drivers/net/hinic3/hinic3_ethdev.c

drivers/net/hinic3/hinic3_ethdev.c +3 -3
@@ -21,9 +21,9 @@
 
 #include "base/hinic3_hw_comm.h"
 
 #include "base/hinic3_nic_cfg.h"
 
 #include "base/hinic3_nic_event.h"
 
-#include "hinic3_pmd_nic_io.h"
 
-#include "hinic3_pmd_tx.h"
 
-#include "hinic3_pmd_rx.h"
 
+#include "hinic3_nic_io.h"
 
+#include "hinic3_tx.h"
 
+#include "hinic3_rx.h"
 
 #include "hinic3_ethdev.h"
 
 
 
 #define HINIC3_MIN_RX_BUF_SIZE 1024

drivers/net/hinic3/hinic3_ethdev.c hinic3_enable_interrupt(struct rte_eth_dev *dev)

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.c +1 -1
@@ -1521,7 +1521,7 @@ hinic3_enable_interrupt(struct rte_eth_dev *dev)
 
 
 
 /** Dp interrupt msix attribute. */
 
 #define HINIC3_TXRX_MSIX_PENDING_LIMIT	  2
 
-#define HINIC3_TXRX_MSIX_COALESC_TIMER	  2
 
+#define HINIC3_TXRX_MSIX_COALESCE_TIMER	  2

it should modify the patch where the COALESC introduced.

Quoted 106 lines

#define HINIC3_TXRX_MSIX_RESEND_TIMER_CFG 7

static int

drivers/net/hinic3/hinic3_ethdev.c +1 -1
@@ -1531,9 +1531,9 @@ hinic3_init_rxq_msix_attr(void *hwdev, u16 msix_index)
 
 	int err;
 
 
 
 	info.lli_set = 0;
 
-	info.interrupt_coalesc_set = 1;
 
+	info.interrupt_coalesce_set = 1;
drivers/net/hinic3/hinic3_ethdev.c +4 -1
 	info.pending_limt = HINIC3_TXRX_MSIX_PENDING_LIMIT;
 
-	info.coalesc_timer_cfg = HINIC3_TXRX_MSIX_COALESC_TIMER;
 
+	info.coalesce_timer_cfg = HINIC3_TXRX_MSIX_COALESCE_TIMER;
 
 	info.resend_timer_cfg = HINIC3_TXRX_MSIX_RESEND_TIMER_CFG;
 
 
 
 	info.msix_index = msix_index;
@@ -3337,6 +3337,9 @@ hinic3_dev_init(struct rte_eth_dev *eth_dev)
 
 	PMD_DRV_LOG(INFO, "Network Interface pmd driver version: %s",
 
 		    HINIC3_PMD_DRV_VERSION);
 
 
 
+	eth_dev->rx_pkt_burst = hinic3_recv_pkts;
 
+	eth_dev->tx_pkt_burst = hinic3_xmit_pkts;
 
+
 
 	return hinic3_func_init(eth_dev);
 
 }
drivers/net/hinic3/hinic3_rx.c +0 -0

index 6fe565984b..36890e48e6 100644

--- a/drivers/net/hinic3/hinic3_rx.c

+++ b/drivers/net/hinic3/hinic3_rx.c

drivers/net/hinic3/hinic3_rx.c +8 -8
@@ -7,14 +7,14 @@
 
 #include <rte_mbuf.h>
 
 
 
 #include "base/hinic3_compat.h"
 
-#include "base/hinic3_pmd_hwif.h"
 
-#include "base/hinic3_pmd_hwdev.h"
 
-#include "base/hinic3_pmd_wq.h"
 
-#include "base/hinic3_pmd_nic_cfg.h"
 
-#include "hinic3_pmd_nic_io.h"
 
-#include "hinic3_pmd_ethdev.h"
 
-#include "hinic3_pmd_tx.h"
 
-#include "hinic3_pmd_rx.h"
 
+#include "base/hinic3_hwif.h"
 
+#include "base/hinic3_hwdev.h"
 
+#include "base/hinic3_wq.h"
 
+#include "base/hinic3_nic_cfg.h"
 
+#include "hinic3_nic_io.h"
 
+#include "hinic3_ethdev.h"
 
+#include "hinic3_tx.h"
 
+#include "hinic3_rx.h"
 
 
 
 /**
 
  * Get wqe from receive queue.

drivers/net/hinic3/hinic3_rx.c hinic3_refill_indir_rqid(struct hinic3_rxq *rxq) · line 450

Quoted 10 lines
drivers/net/hinic3/hinic3_rx.c +1 -1
@@ -447,7 +447,7 @@ hinic3_refill_indir_rqid(struct hinic3_rxq *rxq)
 
 				       HINIC3_RSS_INDIR_SIZE);
 
 	if (err) {
 
 		PMD_DRV_LOG(ERR,
 
-			"Set indrect table failed, eth_dev:%s, queue_idx:%d",
 
+			"Set indirect table failed, eth_dev:%s, queue_idx:%d",

it should modify the patch where the COALESC introduced.

Quoted 2,171 lines
drivers/net/hinic3/hinic3_rx.c +286 -1
 			nic_dev->dev_name, rxq->q_id);
 
 		goto out;
 
 	}
@@ -791,7 +791,7 @@ hinic3_start_rq(struct rte_eth_dev *eth_dev, struct hinic3_rxq *rxq)
 
 		err = hinic3_refill_indir_rqid(rxq);
 
 		if (err) {
 
 			PMD_DRV_LOG(ERR,
 
-				    "Refill rq to indrect table failed, "
 
+				    "Refill rq to indirect table failed, "
 
 				    "eth_dev:%s, queue_idx:%d err:%d",
 
 				    nic_dev->dev_name, rxq->q_id, err);
 
 			hinic3_remove_rq_from_rx_queue_list(nic_dev, rxq->q_id);
@@ -812,3 +812,288 @@ hinic3_start_rq(struct rte_eth_dev *eth_dev, struct hinic3_rxq *rxq)
 
 
 
 	return err;
 
 }
 
+
 
+
 
+static inline u64
 
+hinic3_rx_vlan(u32 offload_type, u32 vlan_len, u16 *vlan_tci)
 
+{
 
+	uint16_t vlan_tag;
 
+
 
+	vlan_tag = HINIC3_GET_RX_VLAN_TAG(vlan_len);
 
+	if (!HINIC3_GET_RX_VLAN_OFFLOAD_EN(offload_type) || vlan_tag == 0) {
 
+		*vlan_tci = 0;
 
+		return 0;
 
+	}
 
+
 
+	*vlan_tci = vlan_tag;
 
+
 
+	return HINIC3_PKT_RX_VLAN | HINIC3_PKT_RX_VLAN_STRIPPED;
 
+}
 
+
 
+static inline u64
 
+hinic3_rx_csum(uint32_t status, struct hinic3_rxq *rxq)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = rxq->nic_dev;
 
+	u32 csum_err;
 
+	u64 flags;
 
+
 
+	if (unlikely(!(nic_dev->rx_csum_en & HINIC3_DEFAULT_RX_CSUM_OFFLOAD)))
 
+		return HINIC3_PKT_RX_IP_CKSUM_UNKNOWN;
 
+
 
+	csum_err = HINIC3_GET_RX_CSUM_ERR(status);
 
+	if (likely(csum_err == 0))
 
+		return (HINIC3_PKT_RX_IP_CKSUM_GOOD |
 
+			HINIC3_PKT_RX_L4_CKSUM_GOOD);
 
+
 
+	/*
 
+	 * If bypass bit is set, all other err status indications should be
 
+	 * ignored.
 
+	 */
 
+	if (unlikely(csum_err & HINIC3_RX_CSUM_HW_CHECK_NONE))
 
+		return HINIC3_PKT_RX_IP_CKSUM_UNKNOWN;
 
+
 
+	flags = 0;
 
+
 
+	/* IP checksum error. */
 
+	if (csum_err & HINIC3_RX_CSUM_IP_CSUM_ERR) {
 
+		flags |= HINIC3_PKT_RX_IP_CKSUM_BAD;
 
+		rxq->rxq_stats.csum_errors++;
 
+	}
 
+
 
+	/* L4 checksum error. */
 
+	if ((csum_err & HINIC3_RX_CSUM_TCP_CSUM_ERR) ||
 
+	    (csum_err & HINIC3_RX_CSUM_UDP_CSUM_ERR) ||
 
+	    (csum_err & HINIC3_RX_CSUM_SCTP_CRC_ERR)) {
 
+		flags |= HINIC3_PKT_RX_L4_CKSUM_BAD;
 
+		rxq->rxq_stats.csum_errors++;
 
+	}
 
+
 
+	if (unlikely(csum_err == HINIC3_RX_CSUM_IPSU_OTHER_ERR))
 
+		rxq->rxq_stats.other_errors++;
 
+
 
+	return flags;
 
+}
 
+
 
+static inline u64
 
+hinic3_rx_rss_hash(u32 offload_type, u32 rss_hash_value, u32 *rss_hash)
 
+{
 
+	u32 rss_type;
 
+
 
+	rss_type = HINIC3_GET_RSS_TYPES(offload_type);
 
+	if (likely(rss_type != 0)) {
 
+		*rss_hash = rss_hash_value;
 
+		return HINIC3_PKT_RX_RSS_HASH;
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+static void
 
+hinic3_recv_jumbo_pkt(struct hinic3_rxq *rxq, struct rte_mbuf *head_mbuf,
 
+		      u32 remain_pkt_len)
 
+{
 
+	struct rte_mbuf *cur_mbuf = NULL;
 
+	struct rte_mbuf *rxm = NULL;
 
+	struct hinic3_rx_info *rx_info = NULL;
 
+	u16 sw_ci, rx_buf_len = rxq->buf_len;
 
+	u32 pkt_len;
 
+
 
+	while (remain_pkt_len > 0) {
 
+		sw_ci = hinic3_get_rq_local_ci(rxq);
 
+		rx_info = &rxq->rx_info[sw_ci];
 
+
 
+		hinic3_update_rq_local_ci(rxq, 1);
 
+
 
+		pkt_len = remain_pkt_len > rx_buf_len ? rx_buf_len
 
+						      : remain_pkt_len;
 
+		remain_pkt_len -= pkt_len;
 
+
 
+		cur_mbuf = rx_info->mbuf;
 
+		cur_mbuf->data_len = (u16)pkt_len;
 
+		cur_mbuf->next = NULL;
 
+
 
+		head_mbuf->pkt_len += cur_mbuf->data_len;
 
+		head_mbuf->nb_segs++;
 
+#ifdef HINIC3_XSTAT_MBUF_USE
 
+		rxq->rxq_stats.rx_free_mbuf_bytes++;
 
+#endif
 
+		if (!rxm)
 
+			head_mbuf->next = cur_mbuf;
 
+		else
 
+			rxm->next = cur_mbuf;
 
+
 
+		rxm = cur_mbuf;
 
+	}
 
+}
 
+
 
+int
 
+hinic3_start_all_rqs(struct rte_eth_dev *eth_dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = NULL;
 
+	struct hinic3_rxq *rxq = NULL;
 
+	int err = 0;
 
+	int i;
 
+
 
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(eth_dev);
 
+
 
+	for (i = 0; i < nic_dev->num_rqs; i++) {
 
+		rxq = eth_dev->data->rx_queues[i];
 
+		hinic3_add_rq_to_rx_queue_list(nic_dev, rxq->q_id);
 
+		err = hinic3_rearm_rxq_mbuf(rxq);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR,
 
+				    "Fail to alloc mbuf for Rx queue %d, "
 
+				    "qid = %u, need_mbuf: %d",
 
+				    i, rxq->q_id, rxq->q_depth);
 
+			goto out;
 
+		}
 
+		hinic3_dev_rx_queue_intr_enable(eth_dev, rxq->q_id);
 
+		eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STARTED;
 
+	}
 
+
 
+	if (nic_dev->rss_state == HINIC3_RSS_ENABLE) {
 
+		err = hinic3_refill_indir_rqid(rxq);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR,
 
+				    "Refill rq to indirect table failed, "
 
+				    "eth_dev:%s, queue_idx:%d, err:%d",
 
+				    rxq->nic_dev->dev_name, rxq->q_id, err);
 
+			goto out;
 
+		}
 
+	}
 
+
 
+	return 0;
 
+out:
 
+	for (i = 0; i < nic_dev->num_rqs; i++) {
 
+		rxq = eth_dev->data->rx_queues[i];
 
+		hinic3_remove_rq_from_rx_queue_list(nic_dev, rxq->q_id);
 
+		hinic3_free_rxq_mbufs(rxq);
 
+		hinic3_dev_rx_queue_intr_disable(eth_dev, rxq->q_id);
 
+		eth_dev->data->rx_queue_state[i] = RTE_ETH_QUEUE_STATE_STOPPED;
 
+	}
 
+	return err;
 
+}
 
+
 
+#define HINIC3_RX_EMPTY_THRESHOLD 3
 
+u16
 
+hinic3_recv_pkts(void *rx_queue, struct rte_mbuf **rx_pkts, u16 nb_pkts)
 
+{
 
+	struct hinic3_rxq *rxq = rx_queue;
 
+	struct hinic3_rx_info *rx_info = NULL;
 
+	volatile struct hinic3_rq_cqe *rx_cqe = NULL;
 
+	struct rte_mbuf *rxm = NULL;
 
+	u16 sw_ci, rx_buf_len, wqebb_cnt = 0, pkts = 0;
 
+	u32 status, pkt_len, vlan_len, offload_type, lro_num;
 
+	u64 rx_bytes = 0;
 
+	u32 hash_value;
 
+
 
+#ifdef HINIC3_XSTAT_PROF_RX
 
+	uint64_t t1 = rte_get_tsc_cycles();
 
+	uint64_t t2;
 
+#endif
 
+	if (((rte_get_timer_cycles() - rxq->rxq_stats.tsc) < rxq->wait_time_cycle) &&
 
+	    rxq->rxq_stats.empty >= HINIC3_RX_EMPTY_THRESHOLD)
 
+		goto out;
 
+
 
+	sw_ci = hinic3_get_rq_local_ci(rxq);
 
+	rx_buf_len = rxq->buf_len;
 
+
 
+	while (pkts < nb_pkts) {
 
+		rx_cqe = &rxq->rx_cqe[sw_ci];
 
+		status = hinic3_hw_cpu32((u32)(rte_atomic_load_explicit(&rx_cqe->status,
 
+			rte_memory_order_acquire)));
 
+		if (!HINIC3_GET_RX_DONE(status)) {
 
+			rxq->rxq_stats.empty++;
 
+			break;
 
+		}
 
+
 
+		vlan_len = hinic3_hw_cpu32(rx_cqe->vlan_len);
 
+
 
+		pkt_len = HINIC3_GET_RX_PKT_LEN(vlan_len);
 
+
 
+		rx_info = &rxq->rx_info[sw_ci];
 
+		rxm = rx_info->mbuf;
 
+
 
+		/* 1. Next ci point and prefetch. */
 
+		sw_ci++;
 
+		sw_ci &= rxq->q_mask;
 
+
 
+		/* 2. Prefetch next mbuf first 64B. */
 
+		rte_prefetch0(rxq->rx_info[sw_ci].mbuf);
 
+
 
+		/* 3. Jumbo frame process. */
 
+		if (likely(pkt_len <= (u32)rx_buf_len)) {
 
+			rxm->data_len = (u16)pkt_len;
 
+			rxm->pkt_len = pkt_len;
 
+			wqebb_cnt++;
 
+		} else {
 
+			rxm->data_len = rx_buf_len;
 
+			rxm->pkt_len = rx_buf_len;
 
+
 
+			/*
 
+			 * If receive jumbo, updating ci will be done by
 
+			 * hinic3_recv_jumbo_pkt function.
 
+			 */
 
+			hinic3_update_rq_local_ci(rxq, wqebb_cnt + 1);
 
+			wqebb_cnt = 0;
 
+			hinic3_recv_jumbo_pkt(rxq, rxm, pkt_len - rx_buf_len);
 
+			sw_ci = hinic3_get_rq_local_ci(rxq);
 
+		}
 
+
 
+		rxm->data_off = RTE_PKTMBUF_HEADROOM;
 
+		rxm->port = rxq->port_id;
 
+
 
+		/* 4. Rx checksum offload. */
 
+		rxm->ol_flags |= hinic3_rx_csum(status, rxq);
 
+
 
+		/* 5. Vlan offload. */
 
+		offload_type = hinic3_hw_cpu32(rx_cqe->offload_type);
 
+
 
+		rxm->ol_flags |=
 
+			hinic3_rx_vlan(offload_type, vlan_len, &rxm->vlan_tci);
 
+
 
+		/* 6. RSS. */
 
+		hash_value = hinic3_hw_cpu32(rx_cqe->hash_val);
 
+		rxm->ol_flags |= hinic3_rx_rss_hash(offload_type, hash_value,
 
+						    &rxm->hash.rss);
 
+		/* 8. LRO. */
 
+		lro_num = HINIC3_GET_RX_NUM_LRO(status);
 
+		if (unlikely(lro_num != 0)) {
 
+			rxm->ol_flags |= HINIC3_PKT_RX_LRO;
 
+			rxm->tso_segsz = pkt_len / lro_num;
 
+		}
 
+
 
+		rx_cqe->status = 0;
 
+
 
+		rx_bytes += pkt_len;
 
+		rx_pkts[pkts++] = rxm;
 
+	}
 
+
 
+	if (pkts) {
 
+		/* 9. Update local ci. */
 
+		hinic3_update_rq_local_ci(rxq, wqebb_cnt);
 
+
 
+		/* Update packet stats. */
 
+		rxq->rxq_stats.packets += pkts;
 
+		rxq->rxq_stats.bytes += rx_bytes;
 
+		rxq->rxq_stats.empty = 0;
 
+#ifdef HINIC3_XSTAT_MBUF_USE
 
+		rxq->rxq_stats.rx_free_mbuf_bytes += pkts;
 
+#endif
 
+	}
 
+	rxq->rxq_stats.burst_pkts = pkts;
 
+	rxq->rxq_stats.tsc = rte_get_timer_cycles();
 
+out:
 
+	/* 10. Rearm mbuf to rxq. */
 
+	hinic3_rearm_rxq_mbuf(rxq);
 
+
 
+#ifdef HINIC3_XSTAT_PROF_RX
 
+	/* Do profiling stats. */
 
+	t2 = rte_get_tsc_cycles();
 
+	rxq->rxq_stats.app_tsc = t1 - rxq->prof_rx_end_tsc;
 
+	rxq->prof_rx_end_tsc = t2;
 
+	rxq->rxq_stats.pmd_tsc = t2 - t1;
 
+#endif
 
+
 
+	return pkts;
 
+}
drivers/net/hinic3/hinic3_tx.c +0 -0

index 6f8c42e0c3..04d5551bba 100644

--- a/drivers/net/hinic3/hinic3_tx.c

+++ b/drivers/net/hinic3/hinic3_tx.c

drivers/net/hinic3/hinic3_tx.c +754 -0
@@ -60,6 +60,98 @@ hinic3_get_sq_hw_ci(struct hinic3_txq *sq)
 
 	return MASKED_QUEUE_IDX(sq, hinic3_hw_cpu16(*sq->ci_vaddr_base));
 
 }
 
 
 
+static void *
 
+hinic3_get_sq_wqe(struct hinic3_txq *sq, struct hinic3_wqe_info *wqe_info)
 
+{
 
+	u16 cur_pi = MASKED_QUEUE_IDX(sq, sq->prod_idx);
 
+	u32 end_pi;
 
+
 
+	end_pi = cur_pi + wqe_info->wqebb_cnt;
 
+	sq->prod_idx += wqe_info->wqebb_cnt;
 
+
 
+	wqe_info->owner = (u8)(sq->owner);
 
+	wqe_info->pi = cur_pi;
 
+	wqe_info->wrapped = 0;
 
+
 
+	if (unlikely(end_pi >= sq->q_depth)) {
 
+		sq->owner = !sq->owner;
 
+
 
+		if (likely(end_pi > sq->q_depth))
 
+			wqe_info->wrapped = (u8)(sq->q_depth - cur_pi);
 
+	}
 
+
 
+	return NIC_WQE_ADDR(sq, cur_pi);
 
+}
 
+
 
+static inline void
 
+hinic3_put_sq_wqe(struct hinic3_txq *sq, struct hinic3_wqe_info *wqe_info)
 
+{
 
+	if (wqe_info->owner != sq->owner)
 
+		sq->owner = wqe_info->owner;
 
+
 
+	sq->prod_idx -= wqe_info->wqebb_cnt;
 
+}
 
+
 
+/**
 
+ * Sets the WQE combination information in the transmit queue (SQ).
 
+ *
 
+ * @param[in] txq
 
+ * Point to send queue.
 
+ * @param[out] wqe_combo
 
+ * Point to wqe_combo of send queue(SQ).
 
+ * @param[in] wqe
 
+ * Point to wqe of send queue(SQ).
 
+ * @param[in] wqe_info
 
+ * Point to wqe_info of send queue(SQ).
 
+ */
 
+static void
 
+hinic3_set_wqe_combo(struct hinic3_txq *txq,
 
+		     struct hinic3_sq_wqe_combo *wqe_combo,
 
+		     struct hinic3_sq_wqe *wqe,
 
+		     struct hinic3_wqe_info *wqe_info)
 
+{
 
+	wqe_combo->hdr = &wqe->compact_wqe.wqe_desc;
 
+
 
+	if (wqe_info->offload) {
 
+		if (wqe_info->wrapped == HINIC3_TX_TASK_WRAPPED) {
 
+			wqe_combo->task = (struct hinic3_sq_task *)
 
+				(void *)txq->sq_head_addr;
 
+			wqe_combo->bds_head = (struct hinic3_sq_bufdesc *)
 
+				(void *)(txq->sq_head_addr + txq->wqebb_size);
 
+		} else if (wqe_info->wrapped == HINIC3_TX_BD_DESC_WRAPPED) {
 
+			wqe_combo->task = &wqe->extend_wqe.task;
 
+			wqe_combo->bds_head = (struct hinic3_sq_bufdesc *)
 
+				(void *)(txq->sq_head_addr);
 
+		} else {
 
+			wqe_combo->task = &wqe->extend_wqe.task;
 
+			wqe_combo->bds_head = wqe->extend_wqe.buf_desc;
 
+		}
 
+
 
+		wqe_combo->wqe_type = SQ_WQE_EXTENDED_TYPE;
 
+		wqe_combo->task_type = SQ_WQE_TASKSECT_16BYTES;
 
+
 
+		return;
 
+	}
 
+
 
+	if (wqe_info->wrapped == HINIC3_TX_TASK_WRAPPED) {
 
+		wqe_combo->bds_head = (struct hinic3_sq_bufdesc *)
 
+			(void *)(txq->sq_head_addr);
 
+	} else {
 
+		wqe_combo->bds_head =
 
+			(struct hinic3_sq_bufdesc *)(&wqe->extend_wqe.task);
 
+	}
 
+
 
+	if (wqe_info->wqebb_cnt > 1) {
 
+		wqe_combo->wqe_type = SQ_WQE_EXTENDED_TYPE;
 
+		wqe_combo->task_type = SQ_WQE_TASKSECT_46BITS;
 
+
 
+		/* This section used as vlan insert, needs to clear. */
 
+		wqe_combo->bds_head->rsvd = 0;
 
+	} else {
 
+		wqe_combo->wqe_type = SQ_WQE_COMPACT_TYPE;
 
+	}
 
+}
 
+
 
 int
 
 hinic3_start_all_sqs(struct rte_eth_dev *eth_dev)
 
 {
@@ -220,6 +312,668 @@ hinic3_tx_done_cleanup(void *txq, u32 free_cnt)
 
 	return hinic3_xmit_mbuf_cleanup(tx_queue, try_free_cnt);
 
 }
 
 
 
+/**
 
+ * Prepare the data packet to be sent and calculate the internal L3 offset.
 
+ *
 
+ * @param[in] mbuf
 
+ * Point to the mbuf to be processed.
 
+ * @param[out] inner_l3_offset
 
+ * Inner(IP Layer) L3 layer offset.
 
+ * @return
 
+ * 0 as success, -EINVAL as failure.
 
+ */
 
+static int
 
+hinic3_tx_offload_pkt_prepare(struct rte_mbuf *mbuf, u16 *inner_l3_offset)
 
+{
 
+	uint64_t ol_flags = mbuf->ol_flags;
 
+
 
+	/* Only support vxlan offload. */
 
+	if ((ol_flags & HINIC3_PKT_TX_TUNNEL_MASK) &&
 
+	    (!(ol_flags & HINIC3_PKT_TX_TUNNEL_VXLAN)))
 
+		return -EINVAL;
 
+
 
+#ifdef RTE_LIBRTE_ETHDEV_DEBUG
 
+	if (rte_validate_tx_offload(mbuf) != 0)
 
+		return -EINVAL;
 
+#endif
 
+	/* Support tunnel. */
 
+	if ((ol_flags & HINIC3_PKT_TX_TUNNEL_MASK)) {
 
+		if ((ol_flags & HINIC3_PKT_TX_OUTER_IP_CKSUM) ||
 
+		    (ol_flags & HINIC3_PKT_TX_OUTER_IPV6) ||
 
+		    (ol_flags & HINIC3_PKT_TX_TCP_SEG)) {
 
+			/*
 
+			 * For this senmatic, l2_len of mbuf means
 
+			 * len(out_udp + vxlan + in_eth).
 
+			 */
 
+			*inner_l3_offset = mbuf->l2_len + mbuf->outer_l2_len +
 
+					   mbuf->outer_l3_len;
 
+		} else {
 
+			/*
 
+			 * For this senmatic, l2_len of mbuf means
 
+			 * len(out_eth + out_ip + out_udp + vxlan + in_eth).
 
+			 */
 
+			*inner_l3_offset = mbuf->l2_len;
 
+		}
 
+	} else {
 
+		/* For non-tunnel type pkts. */
 
+		*inner_l3_offset = mbuf->l2_len;
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+static inline void
 
+hinic3_set_vlan_tx_offload(struct hinic3_sq_task *task, u16 vlan_tag,
 
+			   u8 vlan_type)
 
+{
 
+	task->vlan_offload = SQ_TASK_INFO3_SET(vlan_tag, VLAN_TAG) |
 
+			     SQ_TASK_INFO3_SET(vlan_type, VLAN_TYPE) |
 
+			     SQ_TASK_INFO3_SET(1U, VLAN_TAG_VALID);
 
+}
 
+
 
+/**
 
+ * Set the corresponding offload information based on ol_flags of the mbuf.
 
+ *
 
+ * @param[in] mbuf
 
+ * Point to the mbuf for which offload needs to be set in the sending queue.
 
+ * @param[out] task
 
+ * Point to task of send queue(SQ).
 
+ * @param[out] wqe_info
 
+ * Point to wqe_info of send queue(SQ).
 
+ * @return
 
+ * 0 as success, -EINVAL as failure.
 
+ */
 
+static int
 
+hinic3_set_tx_offload(struct rte_mbuf *mbuf, struct hinic3_sq_task *task,
 
+		      struct hinic3_wqe_info *wqe_info)
 
+{
 
+	uint64_t ol_flags = mbuf->ol_flags;
 
+	u16 pld_offset = 0;
 
+	u32 queue_info = 0;
 
+	u16 vlan_tag;
 
+
 
+	task->pkt_info0 = 0;
 
+	task->ip_identify = 0;
 
+	task->pkt_info2 = 0;
 
+	task->vlan_offload = 0;
 
+
 
+	/* Vlan offload. */
 
+	if (unlikely(ol_flags & HINIC3_PKT_TX_VLAN_PKT)) {
 
+		vlan_tag = mbuf->vlan_tci;
 
+		hinic3_set_vlan_tx_offload(task, vlan_tag, HINIC3_TX_TPID0);
 
+		task->vlan_offload = hinic3_hw_be32(task->vlan_offload);
 
+	}
 
+	/* Cksum offload. */
 
+	if (!(ol_flags & HINIC3_TX_CKSUM_OFFLOAD_MASK))
 
+		return 0;
 
+
 
+	/* Tso offload. */
 
+	if (ol_flags & HINIC3_PKT_TX_TCP_SEG) {
 
+		pld_offset = wqe_info->payload_offset;
 
+		if ((pld_offset >> 1) > MAX_PAYLOAD_OFFSET)
 
+			return -EINVAL;
 
+
 
+		task->pkt_info0 |= SQ_TASK_INFO0_SET(1U, INNER_L4_EN);
 
+		task->pkt_info0 |= SQ_TASK_INFO0_SET(1U, INNER_L3_EN);
 
+
 
+		queue_info |= SQ_CTRL_QUEUE_INFO_SET(1U, TSO);
 
+		queue_info |= SQ_CTRL_QUEUE_INFO_SET(pld_offset >> 1, PLDOFF);
 
+
 
+		/* Set MSS value. */
 
+		queue_info = SQ_CTRL_QUEUE_INFO_CLEAR(queue_info, MSS);
 
+		queue_info |= SQ_CTRL_QUEUE_INFO_SET(mbuf->tso_segsz, MSS);
 
+	} else {
 
+		if (ol_flags & HINIC3_PKT_TX_IP_CKSUM)
 
+			task->pkt_info0 |= SQ_TASK_INFO0_SET(1U, INNER_L3_EN);
 
+
 
+		switch (ol_flags & HINIC3_PKT_TX_L4_MASK) {
 
+		case HINIC3_PKT_TX_TCP_CKSUM:
 
+		case HINIC3_PKT_TX_UDP_CKSUM:
 
+		case HINIC3_PKT_TX_SCTP_CKSUM:
 
+			task->pkt_info0 |= SQ_TASK_INFO0_SET(1U, INNER_L4_EN);
 
+			break;
 
+
 
+		case HINIC3_PKT_TX_L4_NO_CKSUM:
 
+			break;
 
+
 
+		default:
 
+			PMD_DRV_LOG(INFO, "not support pkt type");
 
+			return -EINVAL;
 
+		}
 
+	}
 
+
 
+	/* For vxlan, also can support PKT_TX_TUNNEL_GRE, etc. */
 
+	switch (ol_flags & HINIC3_PKT_TX_TUNNEL_MASK) {
 
+	case HINIC3_PKT_TX_TUNNEL_VXLAN:
 
+		task->pkt_info0 |= SQ_TASK_INFO0_SET(1U, TUNNEL_FLAG);
 
+		break;
 
+
 
+	case 0:
 
+		break;
 
+
 
+	default:
 
+		/* For non UDP/GRE tunneling, drop the tunnel packet. */
 
+		PMD_DRV_LOG(INFO, "not support tunnel pkt type");
 
+		return -EINVAL;
 
+	}
 
+
 
+	if (ol_flags & HINIC3_PKT_TX_OUTER_IP_CKSUM)
 
+		task->pkt_info0 |= SQ_TASK_INFO0_SET(1U, OUT_L3_EN);
 
+
 
+	task->pkt_info0 = hinic3_hw_be32(task->pkt_info0);
 
+	task->pkt_info2 = hinic3_hw_be32(task->pkt_info2);
 
+	wqe_info->queue_info = queue_info;
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Check whether the number of segments in the mbuf is valid.
 
+ *
 
+ * @param[in] mbuf
 
+ * Point to the mbuf to be verified.
 
+ * @param[in] wqe_info
 
+ * Point to wqe_info of send queue(SQ).
 
+ * @return
 
+ * true as valid, false as invalid.
 
+ */
 
+static bool
 
+hinic3_is_tso_sge_valid(struct rte_mbuf *mbuf, struct hinic3_wqe_info *wqe_info)
 
+{
 
+	u32 total_len, limit_len, checked_len, left_len, adjust_mss;
 
+	u32 i, max_sges, left_sges, first_len;
 
+	struct rte_mbuf *mbuf_head, *mbuf_first;
 
+	struct rte_mbuf *mbuf_pre = mbuf;
 
+
 
+	left_sges = mbuf->nb_segs;
 
+	mbuf_head = mbuf;
 
+	mbuf_first = mbuf;
 
+
 
+	/* Tso sge number validation. */
 
+	if (unlikely(left_sges >= HINIC3_NONTSO_PKT_MAX_SGE)) {
 
+		checked_len = 0;
 
+		total_len = 0;
 
+		first_len = 0;
 
+		adjust_mss = mbuf->tso_segsz >= TX_MSS_MIN ? mbuf->tso_segsz
 
+							   : TX_MSS_MIN;
 
+		max_sges = HINIC3_NONTSO_PKT_MAX_SGE - 1;
 
+		limit_len = adjust_mss + wqe_info->payload_offset;
 
+
 
+		for (i = 0; (i < max_sges) && (total_len < limit_len); i++) {
 
+			total_len += mbuf->data_len;
 
+			mbuf_pre = mbuf;
 
+			mbuf = mbuf->next;
 
+		}
 
+
 
+		/* Each continues 38 mbufs segmust do one check. */
 
+		while (left_sges >= HINIC3_NONTSO_PKT_MAX_SGE) {
 
+			if (total_len >= limit_len) {
 
+				/* Update the limit len. */
 
+				limit_len = adjust_mss;
 
+				/* Update checked len. */
 
+				checked_len += first_len;
 
+				/* Record the first len. */
 
+				first_len = mbuf_first->data_len;
 
+				/* First mbuf move to the next. */
 
+				mbuf_first = mbuf_first->next;
 
+				/* Update total len. */
 
+				total_len -= first_len;
 
+				left_sges--;
 
+				i--;
 
+				for (;
 
+				     (i < max_sges) && (total_len < limit_len);
 
+				     i++) {
 
+					total_len += mbuf->data_len;
 
+					mbuf_pre = mbuf;
 
+					mbuf = mbuf->next;
 
+				}
 
+			} else {
 
+				/* Try to copy if not valid. */
 
+				checked_len += (total_len - mbuf_pre->data_len);
 
+
 
+				left_len = mbuf_head->pkt_len - checked_len;
 
+				if (left_len > HINIC3_COPY_MBUF_SIZE)
 
+					return false;
 
+				wqe_info->sge_cnt = (u16)(mbuf_head->nb_segs +
 
+							  i - left_sges);
 
+				wqe_info->cpy_mbuf_cnt = 1;
 
+
 
+				return true;
 
+			}
 
+		} /**< End of while. */
 
+	}
 
+
 
+	wqe_info->sge_cnt = mbuf_head->nb_segs;
 
+
 
+	return true;
 
+}
 
+
 
+/**
 
+ * Checks and processes transport offload information for data packets.
 
+ *
 
+ * @param[in] mbuf
 
+ * Point to the mbuf to send.
 
+ * @param[in] wqe_info
 
+ * Point to wqe_info of send queue(SQ).
 
+ * @return
 
+ * 0 as success, -EINVAL as failure.
 
+ */
 
+static int
 
+hinic3_get_tx_offload(struct rte_mbuf *mbuf, struct hinic3_wqe_info *wqe_info)
 
+{
 
+	uint64_t ol_flags = mbuf->ol_flags;
 
+	u16 i, total_len, inner_l3_offset = 0;
 
+	int err;
 
+	struct rte_mbuf *mbuf_pkt = NULL;
 
+
 
+	wqe_info->sge_cnt = mbuf->nb_segs;
 
+	/* Check if the packet set available offload flags. */
 
+	if (!(ol_flags & HINIC3_TX_OFFLOAD_MASK)) {
 
+		wqe_info->offload = 0;
 
+		return 0;
 
+	}
 
+
 
+	wqe_info->offload = 1;
 
+	err = hinic3_tx_offload_pkt_prepare(mbuf, &inner_l3_offset);
 
+	if (err)
 
+		return err;
 
+
 
+	/* Non tso mbuf only check sge num. */
 
+	if (likely(!(mbuf->ol_flags & HINIC3_PKT_TX_TCP_SEG))) {
 
+		if (unlikely(mbuf->pkt_len > MAX_SINGLE_SGE_SIZE))
 
+			/* Non tso packet len must less than 64KB. */
 
+			return -EINVAL;
 
+
 
+		if (likely(HINIC3_NONTSO_SEG_NUM_VALID(mbuf->nb_segs)))
 
+			/* Valid non-tso mbuf. */
 
+			return 0;
 
+
 
+		/*
 
+		 * The number of non-tso packet fragments must be less than 38,
 
+		 * and mbuf segs greater than 38 must be copied to other
 
+		 * buffers.
 
+		 */
 
+		total_len = 0;
 
+		mbuf_pkt = mbuf;
 
+		for (i = 0; i < (HINIC3_NONTSO_PKT_MAX_SGE - 1); i++) {
 
+			total_len += mbuf_pkt->data_len;
 
+			mbuf_pkt = mbuf_pkt->next;
 
+		}
 
+
 
+		/* Default support copy total 4k mbuf segs. */
 
+		if ((u32)(total_len + (u16)HINIC3_COPY_MBUF_SIZE) <
 
+		    mbuf->pkt_len)
 
+			return -EINVAL;
 
+
 
+		wqe_info->sge_cnt = HINIC3_NONTSO_PKT_MAX_SGE;
 
+		wqe_info->cpy_mbuf_cnt = 1;
 
+
 
+		return 0;
 
+	}
 
+
 
+	/* Tso mbuf. */
 
+	wqe_info->payload_offset =
 
+		inner_l3_offset + mbuf->l3_len + mbuf->l4_len;
 
+
 
+	/* Too many mbuf segs. */
 
+	if (unlikely(HINIC3_TSO_SEG_NUM_INVALID(mbuf->nb_segs)))
 
+		return -EINVAL;
 
+
 
+	/* Check whether can cover all tso mbuf segs or not. */
 
+	if (unlikely(!hinic3_is_tso_sge_valid(mbuf, wqe_info)))
 
+		return -EINVAL;
 
+
 
+	return 0;
 
+}
 
+
 
+static inline void
 
+hinic3_set_buf_desc(struct hinic3_sq_bufdesc *buf_descs, rte_iova_t addr,
 
+		    u32 len)
 
+{
 
+	buf_descs->hi_addr = hinic3_hw_be32(upper_32_bits(addr));
 
+	buf_descs->lo_addr = hinic3_hw_be32(lower_32_bits(addr));
 
+	buf_descs->len = hinic3_hw_be32(len);
 
+}
 
+
 
+static inline struct rte_mbuf *
 
+hinic3_alloc_cpy_mbuf(struct hinic3_nic_dev *nic_dev)
 
+{
 
+	return rte_pktmbuf_alloc(nic_dev->cpy_mpool);
 
+}
 
+
 
+/**
 
+ * Copy packets in the send queue(SQ).
 
+ *
 
+ * @param[in] nic_dev
 
+ * Point to nic device.
 
+ * @param[in] mbuf
 
+ * Point to the source mbuf.
 
+ * @param[in] seg_cnt
 
+ * Number of mbuf segments to be copied.
 
+ * @result
 
+ * The address of the copied mbuf.
 
+ */
 
+static void *
 
+hinic3_copy_tx_mbuf(struct hinic3_nic_dev *nic_dev, struct rte_mbuf *mbuf,
 
+		    u16 sge_cnt)
 
+{
 
+	struct rte_mbuf *dst_mbuf;
 
+	u32 offset = 0;
 
+	u16 i;
 
+
 
+	if (unlikely(!nic_dev->cpy_mpool))
 
+		return NULL;
 
+
 
+	dst_mbuf = hinic3_alloc_cpy_mbuf(nic_dev);
 
+	if (unlikely(!dst_mbuf))
 
+		return NULL;
 
+
 
+	dst_mbuf->data_off = 0;
 
+	dst_mbuf->data_len = 0;
 
+	for (i = 0; i < sge_cnt; i++) {
 
+		rte_memcpy((u8 *)dst_mbuf->buf_addr + offset,
 
+			   (u8 *)mbuf->buf_addr + mbuf->data_off,
 
+			   mbuf->data_len);
 
+		dst_mbuf->data_len += mbuf->data_len;
 
+		offset += mbuf->data_len;
 
+		mbuf = mbuf->next;
 
+	}
 
+	dst_mbuf->pkt_len = dst_mbuf->data_len;
 
+
 
+	return dst_mbuf;
 
+}
 
+
 
+/**
 
+ * Map the TX mbuf to the DMA address space and set related information for
 
+ * subsequent DMA transmission.
 
+ *
 
+ * @param[in] txq
 
+ * Point to send queue.
 
+ * @param[in] mbuf
 
+ * Point to the tx mbuf.
 
+ * @param[out] wqe_combo
 
+ * Point to send queue wqe_combo.
 
+ * @param[in] wqe_info
 
+ * Point to wqe_info of send queue(SQ).
 
+ * @result
 
+ * 0 as success, -EINVAL as failure.
 
+ */
 
+static int
 
+hinic3_mbuf_dma_map_sge(struct hinic3_txq *txq, struct rte_mbuf *mbuf,
 
+			struct hinic3_sq_wqe_combo *wqe_combo,
 
+			struct hinic3_wqe_info *wqe_info)
 
+{
 
+	struct hinic3_sq_wqe_desc *wqe_desc = wqe_combo->hdr;
 
+	struct hinic3_sq_bufdesc *buf_desc = wqe_combo->bds_head;
 
+
 
+	uint16_t nb_segs = wqe_info->sge_cnt - wqe_info->cpy_mbuf_cnt;
 
+	uint16_t real_segs = mbuf->nb_segs;
 
+	rte_iova_t dma_addr;
 
+	u32 i;
 
+
 
+	for (i = 0; i < nb_segs; i++) {
 
+		if (unlikely(mbuf == NULL)) {
 
+			txq->txq_stats.mbuf_null++;
 
+			return -EINVAL;
 
+		}
 
+
 
+		if (unlikely(mbuf->data_len == 0)) {
 
+			txq->txq_stats.sge_len0++;
 
+			return -EINVAL;
 
+		}
 
+
 
+		dma_addr = rte_mbuf_data_iova(mbuf);
 
+		if (i == 0) {
 
+			if (wqe_combo->wqe_type == SQ_WQE_COMPACT_TYPE &&
 
+			    mbuf->data_len > COMPACT_WQE_MAX_CTRL_LEN) {
 
+				txq->txq_stats.sge_len_too_large++;
 
+				return -EINVAL;
 
+			}
 
+
 
+			wqe_desc->hi_addr =
 
+				hinic3_hw_be32(upper_32_bits(dma_addr));
 
+			wqe_desc->lo_addr =
 
+				hinic3_hw_be32(lower_32_bits(dma_addr));
 
+			wqe_desc->ctrl_len = mbuf->data_len;
 
+		} else {
 
+			/*
 
+			 * Parts of wqe is in sq bottom while parts
 
+			 * of wqe is in sq head.
 
+			 */
 
+			if (unlikely(wqe_info->wrapped &&
 
+				     (u64)buf_desc == txq->sq_bot_sge_addr))
 
+				buf_desc = (struct hinic3_sq_bufdesc *)
 
+					   (void *)txq->sq_head_addr;
 
+
 
+			hinic3_set_buf_desc(buf_desc, dma_addr, mbuf->data_len);
 
+			buf_desc++;
 
+		}
 
+		mbuf = mbuf->next;
 
+	}
 
+
 
+	/* For now: support over 38 sge, copy the last 2 mbuf. */
 
+	if (unlikely(wqe_info->cpy_mbuf_cnt != 0)) {
 
+		/*
 
+		 * Copy invalid mbuf segs to a valid buffer, lost performance.
 
+		 */
 
+		txq->txq_stats.cpy_pkts += 1;
 
+		mbuf = hinic3_copy_tx_mbuf(txq->nic_dev, mbuf,
 
+					   real_segs - nb_segs);
 
+		if (unlikely(!mbuf))
 
+			return -EINVAL;
 
+
 
+		txq->tx_info[wqe_info->pi].cpy_mbuf = mbuf;
 
+
 
+		/* Deal with the last mbuf. */
 
+		dma_addr = rte_mbuf_data_iova(mbuf);
 
+		if (unlikely(mbuf->data_len == 0)) {
 
+			txq->txq_stats.sge_len0++;
 
+			return -EINVAL;
 
+		}
 
+		/*
 
+		 * Parts of wqe is in sq bottom while parts
 
+		 * of wqe is in sq head.
 
+		 */
 
+		if (i == 0) {
 
+			wqe_desc->hi_addr =
 
+				hinic3_hw_be32(upper_32_bits(dma_addr));
 
+			wqe_desc->lo_addr =
 
+				hinic3_hw_be32(lower_32_bits(dma_addr));
 
+			wqe_desc->ctrl_len = mbuf->data_len;
 
+		} else {
 
+			if (unlikely(wqe_info->wrapped &&
 
+				     ((u64)buf_desc == txq->sq_bot_sge_addr)))
 
+				buf_desc = (struct hinic3_sq_bufdesc *)
 
+						   txq->sq_head_addr;
 
+
 
+			hinic3_set_buf_desc(buf_desc, dma_addr, mbuf->data_len);
 
+		}
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Sets and configures fields in the transmit queue control descriptor based on
 
+ * the WQE type.
 
+ *
 
+ * @param[out] wqe_combo
 
+ * Point to wqe_combo of send queue.
 
+ * @param[in] wqe_info
 
+ * Point to wqe_info of send queue.
 
+ */
 
+static void
 
+hinic3_prepare_sq_ctrl(struct hinic3_sq_wqe_combo *wqe_combo,
 
+		       struct hinic3_wqe_info *wqe_info)
 
+{
 
+	struct hinic3_sq_wqe_desc *wqe_desc = wqe_combo->hdr;
 
+
 
+	if (wqe_combo->wqe_type == SQ_WQE_COMPACT_TYPE) {
 
+		wqe_desc->ctrl_len |=
 
+			SQ_CTRL_SET(SQ_NORMAL_WQE, DATA_FORMAT) |
 
+			SQ_CTRL_SET(wqe_combo->wqe_type, EXTENDED) |
 
+			SQ_CTRL_SET(wqe_info->owner, OWNER);
 
+		wqe_desc->ctrl_len = hinic3_hw_be32(wqe_desc->ctrl_len);
 
+
 
+		/* Compact wqe queue_info will transfer to ucode. */
 
+		wqe_desc->queue_info = 0;
 
+
 
+		return;
 
+	}
 
+
 
+	wqe_desc->ctrl_len |= SQ_CTRL_SET(wqe_info->sge_cnt, BUFDESC_NUM) |
 
+			      SQ_CTRL_SET(wqe_combo->task_type, TASKSECT_LEN) |
 
+			      SQ_CTRL_SET(SQ_NORMAL_WQE, DATA_FORMAT) |
 
+			      SQ_CTRL_SET(wqe_combo->wqe_type, EXTENDED) |
 
+			      SQ_CTRL_SET(wqe_info->owner, OWNER);
 
+
 
+	wqe_desc->ctrl_len = hinic3_hw_be32(wqe_desc->ctrl_len);
 
+
 
+	wqe_desc->queue_info = wqe_info->queue_info;
 
+	wqe_desc->queue_info |= SQ_CTRL_QUEUE_INFO_SET(1U, UC);
 
+
 
+	if (!SQ_CTRL_QUEUE_INFO_GET(wqe_desc->queue_info, MSS)) {
 
+		wqe_desc->queue_info |=
 
+			SQ_CTRL_QUEUE_INFO_SET(TX_MSS_DEFAULT, MSS);
 
+	} else if (SQ_CTRL_QUEUE_INFO_GET(wqe_desc->queue_info, MSS) <
 
+		   TX_MSS_MIN) {
 
+		/* Mss should not less than 80. */
 
+		wqe_desc->queue_info =
 
+			SQ_CTRL_QUEUE_INFO_CLEAR(wqe_desc->queue_info, MSS);
 
+		wqe_desc->queue_info |= SQ_CTRL_QUEUE_INFO_SET(TX_MSS_MIN, MSS);
 
+	}
 
+
 
+	wqe_desc->queue_info = hinic3_hw_be32(wqe_desc->queue_info);
 
+}
 
+
 
+/**
 
+ * It is responsible for sending data packets.
 
+ *
 
+ * @param[in] tx_queue
 
+ * Point to send queue.
 
+ * @param[in] tx_pkts
 
+ * Pointer to the array of data packets to be sent.
 
+ * @param[in] nb_pkts
 
+ * Number of sent packets.
 
+ * @return
 
+ * Number of actually sent packets.
 
+ */
 
+u16
 
+hinic3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, u16 nb_pkts)
 
+{
 
+	struct hinic3_txq *txq = tx_queue;
 
+	struct hinic3_tx_info *tx_info = NULL;
 
+	struct rte_mbuf *mbuf_pkt = NULL;
 
+	struct hinic3_sq_wqe_combo wqe_combo = {0};
 
+	struct hinic3_sq_wqe *sq_wqe = NULL;
 
+	struct hinic3_wqe_info wqe_info = {0};
 
+
 
+	u32 offload_err, free_cnt;
 
+	u64 tx_bytes = 0;
 
+	u16 free_wqebb_cnt, nb_tx;
 
+	int err;
 
+
 
+#ifdef HINIC3_XSTAT_PROF_TX
 
+	uint64_t t1, t2;
 
+	t1 = rte_get_tsc_cycles();
 
+#endif
 
+
 
+	if (unlikely(!HINIC3_TXQ_IS_STARTED(txq)))
 
+		return 0;
 
+
 
+	free_cnt = txq->tx_free_thresh;
 
+	/* Reclaim tx mbuf before xmit new packets. */
 
+	if (hinic3_get_sq_free_wqebbs(txq) < txq->tx_free_thresh)
 
+		hinic3_xmit_mbuf_cleanup(txq, free_cnt);
 
+
 
+	/* Tx loop routine. */
 
+	for (nb_tx = 0; nb_tx < nb_pkts; nb_tx++) {
 
+		mbuf_pkt = *tx_pkts++;
 
+		if (unlikely(hinic3_get_tx_offload(mbuf_pkt, &wqe_info))) {
 
+			txq->txq_stats.offload_errors++;
 
+			break;
 
+		}
 
+
 
+		if (!wqe_info.offload)
 
+			wqe_info.wqebb_cnt = wqe_info.sge_cnt;
 
+		else
 
+			/* Use extended sq wqe with normal TS. */
 
+			wqe_info.wqebb_cnt = wqe_info.sge_cnt + 1;
 
+
 
+		free_wqebb_cnt = hinic3_get_sq_free_wqebbs(txq);
 
+		if (unlikely(wqe_info.wqebb_cnt > free_wqebb_cnt)) {
 
+			/* Reclaim again. */
 
+			hinic3_xmit_mbuf_cleanup(txq, free_cnt);
 
+			free_wqebb_cnt = hinic3_get_sq_free_wqebbs(txq);
 
+			if (unlikely(wqe_info.wqebb_cnt > free_wqebb_cnt)) {
 
+				txq->txq_stats.tx_busy += (nb_pkts - nb_tx);
 
+				break;
 
+			}
 
+		}
 
+
 
+		/* Get sq wqe address from wqe_page. */
 
+		sq_wqe = hinic3_get_sq_wqe(txq, &wqe_info);
 
+		if (unlikely(!sq_wqe)) {
 
+			txq->txq_stats.tx_busy++;
 
+			break;
 
+		}
 
+
 
+		/* Task or bd section maybe wrapped for one wqe. */
 
+		hinic3_set_wqe_combo(txq, &wqe_combo, sq_wqe, &wqe_info);
 
+
 
+		wqe_info.queue_info = 0;
 
+		/* Fill tx packet offload into qsf and task field. */
 
+		if (wqe_info.offload) {
 
+			offload_err = hinic3_set_tx_offload(mbuf_pkt,
 
+							    wqe_combo.task,
 
+							    &wqe_info);
 
+			if (unlikely(offload_err)) {
 
+				hinic3_put_sq_wqe(txq, &wqe_info);
 
+				txq->txq_stats.offload_errors++;
 
+				break;
 
+			}
 
+		}
 
+
 
+		/* Fill sq_wqe buf_desc and bd_desc. */
 
+		err = hinic3_mbuf_dma_map_sge(txq, mbuf_pkt, &wqe_combo,
 
+					      &wqe_info);
 
+		if (err) {
 
+			hinic3_put_sq_wqe(txq, &wqe_info);
 
+			txq->txq_stats.offload_errors++;
 
+			break;
 
+		}
 
+
 
+		/* Record tx info. */
 
+		tx_info = &txq->tx_info[wqe_info.pi];
 
+		tx_info->mbuf = mbuf_pkt;
 
+		tx_info->wqebb_cnt = wqe_info.wqebb_cnt;
 
+
 
+		hinic3_prepare_sq_ctrl(&wqe_combo, &wqe_info);
 
+
 
+		tx_bytes += mbuf_pkt->pkt_len;
 
+	}
 
+
 
+	/* Update txq stats. */
 
+	if (nb_tx) {
 
+		hinic3_write_db(txq->db_addr, txq->q_id, (int)(txq->cos),
 
+				SQ_CFLAG_DP,
 
+				MASKED_QUEUE_IDX(txq, txq->prod_idx));
 
+		txq->txq_stats.packets += nb_tx;
 
+		txq->txq_stats.bytes += tx_bytes;
 
+	}
 
+	txq->txq_stats.burst_pkts = nb_tx;
 
+
 
+#ifdef HINIC3_XSTAT_PROF_TX
 
+	t2 = rte_get_tsc_cycles();
 
+	txq->txq_stats.app_tsc = t1 - txq->prof_tx_end_tsc;
 
+	txq->prof_tx_end_tsc = t2;
 
+	txq->txq_stats.pmd_tsc = t2 - t1;
 
+	txq->txq_stats.burst_pkts = nb_tx;
 
+#endif
 
+
 
+	return nb_tx;
 
+}
 
+
 
 int
 
 hinic3_stop_sq(struct hinic3_txq *txq)
 
 {
drivers/net/hinic3/hinic3_tx.h +0 -0

index f4c61ea1b1..6026b3fabc 100644

--- a/drivers/net/hinic3/hinic3_tx.h

+++ b/drivers/net/hinic3/hinic3_tx.h

drivers/net/hinic3/hinic3_tx.h +1 -0
@@ -308,6 +308,7 @@ struct __rte_cache_aligned hinic3_txq {
 
 void hinic3_flush_txqs(struct hinic3_nic_dev *nic_dev);
 
 void hinic3_free_txq_mbufs(struct hinic3_txq *txq);
 
 void hinic3_free_all_txq_mbufs(struct hinic3_nic_dev *nic_dev);
 
+u16 hinic3_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts, u16 nb_pkts);
 
 int hinic3_stop_sq(struct hinic3_txq *txq);
 
 int hinic3_start_all_sqs(struct rte_eth_dev *eth_dev);
 
 int hinic3_tx_done_cleanup(void *txq, uint32_t free_cnt);
#155 lore raw

PATCH v5 15/18 net/hinic3: add MML and EEPROM access feature

In reply to Feifei Wang

From: Xin Wang <[email protected]>

Add man-machine language support and implements the get eeprom method.

---
 drivers/net/hinic3/hinic3_ethdev.c        |  13 +
 drivers/net/hinic3/mml/hinic3_dbg.c       | 171 +++++
 drivers/net/hinic3/mml/hinic3_dbg.h       | 160 +++++
 drivers/net/hinic3/mml/hinic3_mml_cmd.c   | 375 +++++++++++
 drivers/net/hinic3/mml/hinic3_mml_cmd.h   | 131 ++++
 drivers/net/hinic3/mml/hinic3_mml_ioctl.c | 215 +++++++
 drivers/net/hinic3/mml/hinic3_mml_lib.c   | 136 ++++
 drivers/net/hinic3/mml/hinic3_mml_lib.h   | 276 ++++++++
 drivers/net/hinic3/mml/hinic3_mml_main.c  | 167 +++++
 drivers/net/hinic3/mml/hinic3_mml_queue.c | 745 ++++++++++++++++++++++
 drivers/net/hinic3/mml/hinic3_mml_queue.h | 256 ++++++++
 drivers/net/hinic3/mml/meson.build        |  62 ++
 12 files changed, 2707 insertions(+)
 create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.h
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.h
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_ioctl.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.h
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_main.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.h
 create mode 100644 drivers/net/hinic3/mml/meson.build
drivers/net/hinic3/hinic3_ethdev.c +13 -0
index 47b47b7412..ac36c49afc 100644
@@ -21,6 +21,7 @@
 #include "base/hinic3_hw_comm.h"
 #include "base/hinic3_nic_cfg.h"
 #include "base/hinic3_nic_event.h"
+#include "mml/hinic3_mml_lib.h"
 #include "hinic3_nic_io.h"
 #include "hinic3_tx.h"
 #include "hinic3_rx.h"
@@ -2276,6 +2277,16 @@ hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	return 0;
 }
 
+static int
+hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,
+		  struct rte_dev_eeprom_info *info)
+{
+#define MAX_BUF_OUT_LEN 2048
+
+	return hinic3_pmd_mml_lib(info->data, info->offset, info->data,
+				  &info->length, MAX_BUF_OUT_LEN);
+}
+
 /**
  * Get device generic statistics.
  *
@@ -2879,6 +2890,7 @@ static const struct eth_dev_ops hinic3_pmd_ops = {
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
+	.get_eeprom                    = hinic3_get_eeprom,
 	.stats_get                     = hinic3_dev_stats_get,
 	.stats_reset                   = hinic3_dev_stats_reset,
 	.xstats_get                    = hinic3_dev_xstats_get,
@@ -2919,6 +2931,7 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = {
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
+	.get_eeprom                    = hinic3_get_eeprom,
 	.stats_get                     = hinic3_dev_stats_get,
 	.stats_reset                   = hinic3_dev_stats_reset,
 	.xstats_get                    = hinic3_dev_xstats_get,
drivers/net/hinic3/mml/hinic3_dbg.c new file +171 -0

171 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_dbg.h new file +160 -0

160 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_cmd.c new file +375 -0

375 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_cmd.h new file +131 -0

131 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_ioctl.c new file +215 -0

215 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_lib.c new file +136 -0

136 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_lib.h new file +276 -0

276 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_main.c new file +167 -0

167 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_queue.c new file +745 -0

745 lines not on this page · raw message

drivers/net/hinic3/mml/hinic3_mml_queue.h new file +256 -0

256 lines not on this page · raw message

drivers/net/hinic3/mml/meson.build new file +62 -0

62 lines not on this page · raw message

Signature · 1 line
2.45.1.windows.1
#156 lore raw

Re: [V5 15/18] net/hinic3: add MML and EEPROM access feature

Quoted 4 lines · Feifei Wang

From: Xin Wang <[email protected]>

Add man-machine language support and implements the get eeprom method.

how about split this commit to two commits?

could you explain the mml?

and I see the ioctl was not really ioctl, it seem a wrapper.

Quoted 5,671 lines

---

 drivers/net/hinic3/hinic3_ethdev.c        |  13 +
 drivers/net/hinic3/mml/hinic3_dbg.c       | 171 +++++
 drivers/net/hinic3/mml/hinic3_dbg.h       | 160 +++++
 drivers/net/hinic3/mml/hinic3_mml_cmd.c   | 375 +++++++++++
 drivers/net/hinic3/mml/hinic3_mml_cmd.h   | 131 ++++
 drivers/net/hinic3/mml/hinic3_mml_ioctl.c | 215 +++++++
 drivers/net/hinic3/mml/hinic3_mml_lib.c   | 136 ++++
 drivers/net/hinic3/mml/hinic3_mml_lib.h   | 276 ++++++++
 drivers/net/hinic3/mml/hinic3_mml_main.c  | 167 +++++
 drivers/net/hinic3/mml/hinic3_mml_queue.c | 745 ++++++++++++++++++++++
 drivers/net/hinic3/mml/hinic3_mml_queue.h | 256 ++++++++
 drivers/net/hinic3/mml/meson.build        |  62 ++
 12 files changed, 2707 insertions(+)
 create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_dbg.h
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_cmd.h
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_ioctl.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_lib.h
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_main.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.c
 create mode 100644 drivers/net/hinic3/mml/hinic3_mml_queue.h
 create mode 100644 drivers/net/hinic3/mml/meson.build
drivers/net/hinic3/hinic3_ethdev.c +0 -0

index 47b47b7412..ac36c49afc 100644

--- a/drivers/net/hinic3/hinic3_ethdev.c

+++ b/drivers/net/hinic3/hinic3_ethdev.c

drivers/net/hinic3/hinic3_ethdev.c +13 -0
@@ -21,6 +21,7 @@
 
 #include "base/hinic3_hw_comm.h"
 
 #include "base/hinic3_nic_cfg.h"
 
 #include "base/hinic3_nic_event.h"
 
+#include "mml/hinic3_mml_lib.h"
 
 #include "hinic3_nic_io.h"
 
 #include "hinic3_tx.h"
 
 #include "hinic3_rx.h"
@@ -2276,6 +2277,16 @@ hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)
 
 	return 0;
 
 }
 
 
 
+static int
 
+hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,
 
+		  struct rte_dev_eeprom_info *info)
 
+{
 
+#define MAX_BUF_OUT_LEN 2048
 
+
 
+	return hinic3_pmd_mml_lib(info->data, info->offset, info->data,
 
+				  &info->length, MAX_BUF_OUT_LEN);
 
+}
 
+
 
 /**
 
  * Get device generic statistics.
 
  *
@@ -2879,6 +2890,7 @@ static const struct eth_dev_ops hinic3_pmd_ops = {
 
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
 
+	.get_eeprom                    = hinic3_get_eeprom,
 
 	.stats_get                     = hinic3_dev_stats_get,
 
 	.stats_reset                   = hinic3_dev_stats_reset,
 
 	.xstats_get                    = hinic3_dev_xstats_get,
@@ -2919,6 +2931,7 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = {
 
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
 
+	.get_eeprom                    = hinic3_get_eeprom,
 
 	.stats_get                     = hinic3_dev_stats_get,
 
 	.stats_reset                   = hinic3_dev_stats_reset,
 
 	.xstats_get                    = hinic3_dev_xstats_get,
drivers/net/hinic3/mml/hinic3_dbg.c +0 -0

new file mode 100644

index 0000000000..30051c8e6b

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_dbg.c

drivers/net/hinic3/mml/hinic3_dbg.c +171 -0
@@ -0,0 +1,171 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+
 
+#include "hinic3_compat.h"
 
+#include "hinic3_hwif.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_wq.h"
 
+#include "hinic3_nic_cfg.h"
 
+#include "hinic3_ethdev.h"
 
+#include "hinic3_rx.h"
 
+#include "hinic3_tx.h"
 
+#include "hinic3_nic_io.h"
 
+#include "hinic3_dbg.h"
 
+
 
+#define DB_IDX(db, db_base) \
 
+	((u32)(((ulong)(db) - (ulong)(db_base)) / HINIC3_DB_PAGE_SIZE))
 
+
 
+int
 
+hinic3_dbg_get_rq_info(void *hwdev, uint16_t q_id,
 
+		       struct hinic3_dbg_rq_info *rq_info, u16 *msg_size)
 
+{
 
+	struct hinic3_hwdev *dev = (struct hinic3_hwdev *)hwdev;
 
+	struct hinic3_nic_dev *nic_dev =
 
+		(struct hinic3_nic_dev *)dev->dev_handle;
 
+	struct hinic3_rxq *rxq = NULL;
 
+
 
+	if (q_id >= nic_dev->num_rqs) {
 
+		PMD_DRV_LOG(ERR, "Invalid rx queue id, q_id: %d, num_rqs: %d",
 
+			    q_id, nic_dev->num_rqs);
 
+		return -EINVAL;
 
+	}
 
+
 
+	rq_info->q_id = q_id;
 
+	rxq = nic_dev->rxqs[q_id];
 
+
 
+	rq_info->hw_pi = (u16)cpu_to_be16(*rxq->pi_virt_addr);
 
+	rq_info->ci = rxq->cons_idx & rxq->q_mask;
 
+	rq_info->sw_pi = rxq->prod_idx & rxq->q_mask;
 
+	rq_info->wqebb_size = HINIC3_SQ_WQEBB_SIZE;
 
+	rq_info->q_depth = rxq->q_depth;
 
+	rq_info->buf_len = rxq->buf_len;
 
+	rq_info->ci_wqe_page_addr = rxq->queue_buf_vaddr;
 
+	rq_info->ci_cla_tbl_addr = NULL;
 
+	rq_info->msix_idx = 0;
 
+	rq_info->msix_vector = 0;
 
+
 
+	*msg_size = sizeof(*rq_info);
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_dbg_get_rx_cqe_info(void *hwdev, uint16_t q_id, uint16_t idx,
 
+			   void *buf_out, uint16_t *out_size)
 
+{
 
+	struct hinic3_hwdev *dev = (struct hinic3_hwdev *)hwdev;
 
+	struct hinic3_nic_dev *nic_dev =
 
+		(struct hinic3_nic_dev *)dev->dev_handle;
 
+
 
+	if (q_id >= nic_dev->num_rqs || idx >= nic_dev->rxqs[q_id]->q_depth)
 
+		return -EFAULT;
 
+
 
+	memcpy(buf_out, (void *)&nic_dev->rxqs[q_id]->rx_cqe[idx],
 
+		     sizeof(struct hinic3_rq_cqe));
 
+	*out_size = sizeof(struct hinic3_rq_cqe);
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_dbg_get_sq_info(void *dev, u16 q_id, struct hinic3_dbg_sq_info *sq_info,
 
+		       u16 *msg_size)
 
+{
 
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
 
+	struct hinic3_nic_dev *nic_dev =
 
+		(struct hinic3_nic_dev *)hwdev->dev_handle;
 
+	struct hinic3_txq *txq = NULL;
 
+
 
+	if (q_id >= nic_dev->num_sqs) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Inputting tx queue id is larger than actual tx "
 
+			    "queue number, qid: %d, num_sqs: %d",
 
+			    q_id, nic_dev->num_sqs);
 
+		return -EINVAL;
 
+	}
 
+
 
+	sq_info->q_id = q_id;
 
+	txq = nic_dev->txqs[q_id];
 
+
 
+	sq_info->pi = txq->prod_idx & txq->q_mask;
 
+	sq_info->ci = txq->cons_idx & txq->q_mask;
 
+	sq_info->fi = (*(volatile u16 *)txq->ci_vaddr_base) & txq->q_mask;
 
+	sq_info->q_depth = txq->q_depth;
 
+	sq_info->weqbb_size = HINIC3_SQ_WQEBB_SIZE;
 
+	sq_info->ci_addr =
 
+		(volatile u16 *)HINIC3_CI_VADDR(txq->ci_vaddr_base, q_id);
 
+	sq_info->cla_addr = txq->queue_buf_paddr;
 
+	sq_info->db_addr.phy_addr = (u64 *)txq->db_addr;
 
+	sq_info->pg_idx = DB_IDX(txq->db_addr, hwdev->hwif->db_base);
 
+
 
+	*msg_size = sizeof(*sq_info);
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_dbg_get_sq_wqe_info(void *dev, u16 q_id, u16 idx, u16 wqebb_cnt, u8 *wqe,
 
+			   u16 *wqe_size)
 
+{
 
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
 
+	struct hinic3_nic_dev *nic_dev =
 
+		(struct hinic3_nic_dev *)hwdev->dev_handle;
 
+	struct hinic3_txq *txq = NULL;
 
+	void *src_wqe = NULL;
 
+	u32 offset;
 
+
 
+	if (q_id >= nic_dev->num_sqs) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Inputting tx queue id is larger than actual tx "
 
+			    "queue number, qid: %d, num_sqs: %d",
 
+			    q_id, nic_dev->num_sqs);
 
+		return -EINVAL;
 
+	}
 
+
 
+	txq = nic_dev->txqs[q_id];
 
+	if (idx + wqebb_cnt > txq->q_depth)
 
+		return -EFAULT;
 
+
 
+	src_wqe = (void *)txq->queue_buf_vaddr;
 
+	offset = (u32)idx << txq->wqebb_shift;
 
+
 
+	memcpy((void *)wqe, (void *)((u8 *)src_wqe + offset),
 
+		     (size_t)((u32)wqebb_cnt << txq->wqebb_shift));
 
+
 
+	*wqe_size = (u16)((u32)wqebb_cnt << txq->wqebb_shift);
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_dbg_get_rq_wqe_info(void *dev, u16 q_id, u16 idx, u16 wqebb_cnt, u8 *wqe,
 
+			   u16 *wqe_size)
 
+{
 
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
 
+	struct hinic3_nic_dev *nic_dev =
 
+		(struct hinic3_nic_dev *)hwdev->dev_handle;
 
+	struct hinic3_rxq *rxq = NULL;
 
+	void *src_wqe = NULL;
 
+	u32 offset;
 
+
 
+	if (q_id >= nic_dev->num_rqs) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Inputting rx queue id is larger than actual rx "
 
+			    "queue number, qid: %d, num_rqs: %d",
 
+			    q_id, nic_dev->num_rqs);
 
+		return -EINVAL;
 
+	}
 
+
 
+	rxq = nic_dev->rxqs[q_id];
 
+	if (idx + wqebb_cnt > rxq->q_depth)
 
+		return -EFAULT;
 
+
 
+	src_wqe = (void *)rxq->queue_buf_vaddr;
 
+	offset = (u32)idx << rxq->wqebb_shift;
 
+
 
+	memcpy((void *)wqe, (void *)((u8 *)src_wqe + offset),
 
+		     (size_t)((u32)wqebb_cnt << rxq->wqebb_shift));
 
+
 
+	*wqe_size = (u16)((u32)wqebb_cnt << rxq->wqebb_shift);
 
+	return 0;
 
+}
drivers/net/hinic3/mml/hinic3_dbg.h +0 -0

new file mode 100644

index 0000000000..bac96c84a0

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_dbg.h

drivers/net/hinic3/mml/hinic3_dbg.h +160 -0
@@ -0,0 +1,160 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+
 
+#ifndef _HINIC3_MML_DBG_H
 
+#define _HINIC3_MML_DBG_H
 
+
 
+/* nic_tool */
 
+struct hinic3_tx_hw_page {
 
+	u64 *phy_addr;
 
+	u64 *map_addr;
 
+};
 
+
 
+/* nic_tool */
 
+struct hinic3_dbg_sq_info {
 
+	u16 q_id;
 
+	u16 pi;
 
+	u16 ci; /**< sw_ci */
 
+	u16 fi; /**< hw_ci */
 
+
 
+	u32 q_depth;
 
+	u16 weqbb_size;
 
+
 
+	volatile u16 *ci_addr;
 
+	u64 cla_addr;
 
+
 
+	struct hinic3_tx_hw_page db_addr;
 
+	u32 pg_idx;
 
+};
 
+
 
+/* nic_tool */
 
+struct hinic3_dbg_rq_info {
 
+	u16 q_id;
 
+	u16 hw_pi;
 
+	u16 ci; /**< sw_ci */
 
+	u16 sw_pi;
 
+	u16 wqebb_size;
 
+	u16 q_depth;
 
+	u16 buf_len;
 
+
 
+	void *ci_wqe_page_addr;
 
+	void *ci_cla_tbl_addr;
 
+	u16 msix_idx;
 
+	u32 msix_vector;
 
+};
 
+
 
+void *hinic3_dbg_get_sq_wq_handle(void *hwdev, u16 q_id);
 
+
 
+void *hinic3_dbg_get_rq_wq_handle(void *hwdev, u16 q_id);
 
+
 
+void *hinic3_dbg_get_sq_ci_addr(void *hwdev, u16 q_id);
 
+
 
+u16 hinic3_dbg_get_global_qpn(void *hwdev);
 
+
 
+/**
 
+ * Get details of specified RX queue and store in `rq_info`.
 
+ *
 
+ * @param[in] hwdev
 
+ * Pointer to the hardware device.
 
+ * @param[in] q_id
 
+ * RX queue ID.
 
+ * @param[out] rq_info
 
+ * Structure to store RX queue information.
 
+ * @param[out] msg_size
 
+ * Size of the message.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+int hinic3_dbg_get_rq_info(void *hwdev, uint16_t q_id,
 
+			   struct hinic3_dbg_rq_info *rq_info, u16 *msg_size);
 
+
 
+/**
 
+ * Get the RX CQE at the specified index from the given RX queue.
 
+ *
 
+ * @param[in] hwdev
 
+ * Pointer to hardware device structure.
 
+ * @param[in] q_id
 
+ * RX queue ID.
 
+ * @param[in] idx
 
+ * Index of the CQE.
 
+ * @param[out] buf_out
 
+ * Buffer to store the CQE.
 
+ * @param[out] out_size
 
+ * Size of the CQE.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+int hinic3_dbg_get_rx_cqe_info(void *hwdev, uint16_t q_id, uint16_t idx,
 
+			       void *buf_out, uint16_t *out_size);
 
+
 
+/**
 
+ * Get SQ information for debugging.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] q_id
 
+ * ID of SQ to retrieve information for.
 
+ * @param[out] sq_info
 
+ * Pointer to the structure where the SQ information will be stored.
 
+ * @param[out] msg_size
 
+ * The size (in bytes) of the `sq_info` structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ * - -EINVAL if the queue ID is invalid.
 
+ */
 
+int hinic3_dbg_get_sq_info(void *hwdev, u16 q_id,
 
+			   struct hinic3_dbg_sq_info *sq_info, u16 *msg_size);
 
+
 
+/**
 
+ * Get WQE information from a send queue.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] q_id
 
+ * The ID of the send queue from which to retrieve WQE information.
 
+ * @param[in] idx
 
+ * The index of the first WQE to retrieve.
 
+ * @param[in] wqebb_cnt
 
+ * The number of WQEBBs to retrieve.
 
+ * @param[out] wqe
 
+ * Pointer to the buffer where the WQE data will be stored.
 
+ * @param[out] wqe_size
 
+ * The size (in bytes) of the retrieved WQE data.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ * - -EINVAL if queue ID invalid.
 
+ * - -EFAULT if index invalid.
 
+ */
 
+int hinic3_dbg_get_sq_wqe_info(void *hwdev, u16 q_id, u16 idx, u16 wqebb_cnt,
 
+			       u8 *wqe, u16 *wqe_size);
 
+
 
+/**
 
+ * Get WQE information from a receive queue.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to the device structure.
 
+ * @param[in] q_id
 
+ * The ID of the receive queue from which to retrieve WQE information.
 
+ * @param[in] idx
 
+ * The index of the first WQE to retrieve.
 
+ * @param[in] wqebb_cnt
 
+ * The number of WQEBBs to retrieve.
 
+ * @param[out] wqe
 
+ * Pointer to the buffer where the WQE data will be stored.
 
+ * @param[out] wqe_size
 
+ * The size (in bytes) of the retrieved WQE data.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ * - -EINVAL if queue ID invalid.
 
+ * - -EFAULT if index invalid.
 
+ */
 
+int hinic3_dbg_get_rq_wqe_info(void *hwdev, u16 q_id, u16 idx, u16 wqebb_cnt,
 
+			       u8 *wqe, u16 *wqe_size);
 
+
 
+#endif /* _HINIC3_MML_DBG_H */
drivers/net/hinic3/mml/hinic3_mml_cmd.c +0 -0

new file mode 100644

index 0000000000..797952b8c0

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_cmd.c

drivers/net/hinic3/mml/hinic3_mml_cmd.c +375 -0
@@ -0,0 +1,375 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+
 
+#include "hinic3_mml_lib.h"
 
+#include "hinic3_compat.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_nic_cfg.h"
 
+#include "hinic3_ethdev.h"
 
+#include "hinic3_mml_cmd.h"
 
+
 
+/**
 
+ * Compares two strings for equality.
 
+ *
 
+ * @param[in] command
 
+ * The first string to compare.
 
+ * @param[in] argument
 
+ * The second string to compare.
 
+ *
 
+ * @return
 
+ * UDA_TRUE if the strings are equal, otherwise UDA_FALSE.
 
+ */
 
+static int
 
+string_cmp(const char *command, const char *argument)
 
+{
 
+	const char *cmd = command;
 
+	const char *arg = argument;
 
+
 
+	if (!cmd || !arg)
 
+		return UDA_FALSE;
 
+
 
+	if (strlen(cmd) != strlen(arg))
 
+		return UDA_FALSE;
 
+
 
+	do {
 
+		if (*cmd != *arg)
 
+			return UDA_FALSE;
 
+		cmd++;
 
+		arg++;
 
+	} while (*cmd != '\0');
 
+
 
+	return UDA_TRUE;
 
+}
 
+
 
+static void
 
+show_tool_version(cmd_adapter_t *adapter)
 
+{
 
+	hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+			   "hinic3 pmd version %s", HINIC3_PMD_DRV_VERSION);
 
+}
 
+
 
+static void
 
+show_tool_help(cmd_adapter_t *adapter)
 
+{
 
+	int i;
 
+	major_cmd_t *major_cmd = NULL;
 
+
 
+	if (!adapter)
 
+		return;
 
+
 
+	hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+			   "\n Usage:evsadm exec dump-hinic-status <major_cmd> "
 
+			   "[option]\n");
 
+	hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+			   "	-h, --help show help information");
 
+	hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+			   "	-v, --version show version information");
 
+	hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+			   "\n Major Commands:\n");
 
+
 
+	for (i = 0; i < adapter->major_cmds; i++) {
 
+		major_cmd = adapter->p_major_cmd[i];
 
+		hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+				   "	%-23s %s", major_cmd->name,
 
+				   major_cmd->description);
 
+	}
 
+	hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len, "\n");
 
+}
 
+
 
+void
 
+major_command_option(major_cmd_t *major_cmd, const char *little,
 
+		     const char *large, uint32_t have_param,
 
+		     command_record_t record)
 
+{
 
+	cmd_option_t *option = NULL;
 
+
 
+	if (major_cmd == NULL || (little == NULL && large == NULL) || !record) {
 
+		PMD_DRV_LOG(ERR, "Invalid input parameter.");
 
+		return;
 
+	}
 
+
 
+	if (major_cmd->option_count >= COMMAND_MAX_OPTIONS) {
 
+		PMD_DRV_LOG(ERR, "Do not support more than %d options",
 
+			    COMMAND_MAX_OPTIONS);
 
+		return;
 
+	}
 
+
 
+	option = &major_cmd->options[major_cmd->option_count];
 
+	major_cmd->options_repeat_flag[major_cmd->option_count] = 0;
 
+	major_cmd->option_count++;
 
+
 
+	option->record = record;
 
+	option->little = little;
 
+	option->large = large;
 
+	option->have_param = have_param;
 
+}
 
+
 
+void
 
+major_command_register(cmd_adapter_t *adapter, major_cmd_t *major_cmd)
 
+{
 
+	int i = 0;
 
+
 
+	if (adapter == NULL || major_cmd == NULL) {
 
+		PMD_DRV_LOG(ERR, "Invalid input parameter.");
 
+		return;
 
+	}
 
+
 
+	if (adapter->major_cmds >= COMMAND_MAX_MAJORS) {
 
+		PMD_DRV_LOG(ERR, "Major Commands is full");
 
+		return;
 
+	}
 
+	while (adapter->p_major_cmd[i] != NULL)
 
+		i++;
 
+	adapter->p_major_cmd[i] = major_cmd;
 
+	adapter->major_cmds++;
 
+	major_cmd->adapter = adapter;
 
+	major_cmd->err_no = UDA_SUCCESS;
 
+	memset(major_cmd->err_str, 0, sizeof(major_cmd->err_str));
 
+}
 
+
 
+static int
 
+is_help_version(cmd_adapter_t *adapter, int argc, char *arg)
 
+{
 
+	if (COMMAND_HELP_POSITION(argc) &&
 
+	    (string_cmp("-h", arg) || string_cmp("--help", arg))) {
 
+		show_tool_help(adapter);
 
+		return UDA_TRUE;
 
+	}
 
+
 
+	if (COMMAND_VERSION_POSITION(argc) &&
 
+	    (string_cmp("-v", arg) || string_cmp("--version", arg))) {
 
+		show_tool_version(adapter);
 
+		return UDA_TRUE;
 
+	}
 
+
 
+	return UDA_FALSE;
 
+}
 
+
 
+static int
 
+check_command_length(int argc, char **argv)
 
+{
 
+	int i;
 
+	unsigned long long str_len = 0;
 
+
 
+	for (i = 1; i < argc; i++)
 
+		str_len += strlen(argv[i]);
 
+
 
+	if (str_len > COMMAND_MAX_STRING)
 
+		return -UDA_EINVAL;
 
+
 
+	return UDA_SUCCESS;
 
+}
 
+
 
+static inline int
 
+char_check(const char cmd)
 
+{
 
+	if (cmd >= 'a' && cmd <= 'z')
 
+		return UDA_SUCCESS;
 
+
 
+	if (cmd >= 'A' && cmd <= 'Z')
 
+		return UDA_SUCCESS;
 
+	return UDA_FAIL;
 
+}
 
+
 
+static int
 
+major_command_check_param(cmd_option_t *option, char *arg)
 
+{
 
+	if (!option)
 
+		return -UDA_EINVAL;
 
+	if (option->have_param != 0) {
 
+		if (!arg || ((arg[0] == '-') && char_check(arg[1])))
 
+			return -UDA_EINVAL;
 
+		return UDA_SUCCESS;
 
+	}
 
+
 
+	return -UDA_ENOOBJ;
 
+}
 
+
 
+static int
 
+major_cmd_repeat_option_set(major_cmd_t *major_cmd, const cmd_option_t *option,
 
+			    u32 *options_repeat_flag)
 
+{
 
+	int err;
 
+
 
+	if (*options_repeat_flag != 0) {
 
+		major_cmd->err_no = -UDA_EINVAL;
 
+		err = snprintf(major_cmd->err_str, COMMANDER_ERR_MAX_STRING - 1,
 
+			       "Repeated option %s|%s.", option->little,
 
+			       option->large);
 
+		if (err <= 0) {
 
+			PMD_DRV_LOG(ERR,
 
+				"snprintf cmd repeat option failed, err: %d.",
 
+				err);
 
+		}
 
+		return -UDA_EINVAL;
 
+	}
 
+	*options_repeat_flag = 1;
 
+	return UDA_SUCCESS;
 
+}
 
+
 
+static int
 
+major_cmd_option_check(major_cmd_t *major_cmd, char **argv, int *index)
 
+{
 
+	int j, ret, err, option_ok, intermediate_var;
 
+	cmd_option_t *option = NULL;
 
+	char *arg = argv[*index];
 
+
 
+	/* Find command. */
 
+	for (j = 0; j < major_cmd->option_count; j++) {
 
+		option = &major_cmd->options[j];
 
+		option_ok = (((option->little != NULL) &&
 
+			      string_cmp(option->little, arg)) ||
 
+			     ((option->large != NULL) &&
 
+			      string_cmp(option->large, arg)));
 
+		if (!option_ok)
 
+			continue;
 
+		/* Find same option. */
 
+		ret = major_cmd_repeat_option_set(major_cmd,
 
+			option, &major_cmd->options_repeat_flag[j]);
 
+		if (ret != UDA_SUCCESS)
 
+			return ret;
 
+
 
+		arg = NULL;
 
+		/* If this option need parameters. */
 
+		intermediate_var = (*index) + 1;
 
+		ret = major_command_check_param(option, argv[intermediate_var]);
 
+		if (ret == UDA_SUCCESS) {
 
+			(*index)++;
 
+			arg = argv[*index];
 
+		} else if (ret == -UDA_EINVAL) {
 
+			major_cmd->err_no = -UDA_EINVAL;
 
+			err = snprintf(major_cmd->err_str,
 
+				       COMMANDER_ERR_MAX_STRING - 1,
 
+				       "%s|%s option need parameter.",
 
+				       option->little, option->large);
 
+			if (err <= 0) {
 
+				PMD_DRV_LOG(ERR,
 
+					    "snprintf cmd option need para "
 
+					    "failed, err: %d.",
 
+					    err);
 
+			}
 
+			return -UDA_EINVAL;
 
+		}
 
+
 
+		/* Record messages. */
 
+		ret = option->record(major_cmd, arg);
 
+		if (ret != UDA_SUCCESS)
 
+			return ret;
 
+		break;
 
+	}
 
+
 
+	/* Illegal option. */
 
+	if (j == major_cmd->option_count) {
 
+		major_cmd->err_no = -UDA_EINVAL;
 
+		err = snprintf(major_cmd->err_str, COMMANDER_ERR_MAX_STRING - 1,
 
+			       "%s is not option needed.", arg);
 
+		if (err <= 0) {
 
+			PMD_DRV_LOG(ERR,
 
+				"snprintf cmd option invalid failed, err: %d.",
 
+				err);
 
+		}
 
+		return -UDA_EINVAL;
 
+	}
 
+	return UDA_SUCCESS;
 
+}
 
+
 
+static int
 
+major_command_parse(major_cmd_t *major_cmd, int argc, char **argv)
 
+{
 
+	int i, err;
 
+
 
+	for (i = 0; i < argc; i++) {
 
+		err = major_cmd_option_check(major_cmd, argv, &i);
 
+		if (err != UDA_SUCCESS)
 
+			return err;
 
+	}
 
+
 
+	return UDA_SUCCESS;
 
+}
 
+
 
+static int
 
+copy_result_to_buffer(void *buf_out, char *result, int len)
 
+{
 
+	int ret;
 
+
 
+	ret = snprintf(buf_out, len - 1, "%s", result);
 
+	if (ret <= 0)
 
+		return 0;
 
+
 
+	return ret + 1;
 
+}
 
+
 
+void
 
+command_parse(cmd_adapter_t *adapter, int argc, char **argv, void *buf_out,
 
+	      uint32_t *out_len)
 
+{
 
+	int i;
 
+	major_cmd_t *major_cmd = NULL;
 
+	char *arg = argv[1];
 
+
 
+	if (is_help_version(adapter, argc, arg) == UDA_TRUE) {
 
+		*out_len = (u32)copy_result_to_buffer(buf_out,
 
+			adapter->show_str, MAX_SHOW_STR_LEN);
 
+		return;
 
+	}
 
+
 
+	for (i = 0; i < adapter->major_cmds; i++) {
 
+		major_cmd = adapter->p_major_cmd[i];
 
+
 
+		/* Find major command. */
 
+		if (!string_cmp(major_cmd->name, arg))
 
+			continue;
 
+		if (check_command_length(argc, argv) != UDA_SUCCESS) {
 
+			major_cmd->err_no = -UDA_EINVAL;
 
+			snprintf(major_cmd->err_str,
 
+				       COMMANDER_ERR_MAX_STRING - 1,
 
+				       "Command input too long.");
 
+			break;
 
+		}
 
+
 
+		/* Deal sub command. */
 
+		if (argc > SUB_COMMAND_OFFSET) {
 
+			if (major_command_parse(major_cmd,
 
+				    argc - SUB_COMMAND_OFFSET,
 
+				    argv + SUB_COMMAND_OFFSET) != UDA_SUCCESS) {
 
+				goto PARSE_OUT;
 
+			}
 
+		}
 
+
 
+		/* Command exec. */
 
+		major_cmd->execute(major_cmd);
 
+		break;
 
+	}
 
+
 
+	/* Not find command. */
 
+	if (i == adapter->major_cmds) {
 
+		hinic3_pmd_mml_log(adapter->show_str, &adapter->show_len,
 
+				   "Unknown major command, assign 'evsadm exec "
 
+				   "dump-hinic-status -h' for help.");
 
+		*out_len = (u32)copy_result_to_buffer(buf_out,
 
+			adapter->show_str, MAX_SHOW_STR_LEN);
 
+		return;
 
+	}
 
+
 
+PARSE_OUT:
 
+	if (major_cmd->err_no != UDA_SUCCESS &&
 
+	    major_cmd->err_no != -UDA_CANCEL) {
 
+		PMD_DRV_LOG(ERR, "%s command error(%d): %s", major_cmd->name,
 
+			    major_cmd->err_no, major_cmd->err_str);
 
+
 
+		hinic3_pmd_mml_log(major_cmd->show_str, &major_cmd->show_len,
 
+				   "%s command error(%d): %s",
 
+				   major_cmd->name, major_cmd->err_no,
 
+				   major_cmd->err_str);
 
+	}
 
+	*out_len = (u32)copy_result_to_buffer(buf_out, major_cmd->show_str,
 
+					      MAX_SHOW_STR_LEN);
 
+}
 
+
 
+void
 
+tool_target_init(int *bus_num, char *dev_name, int len)
 
+{
 
+	*bus_num = TRGET_UNKNOWN_BUS_NUM;
 
+	memset(dev_name, 0, len);
 
+}
drivers/net/hinic3/mml/hinic3_mml_cmd.h +0 -0

new file mode 100644

index 0000000000..b9c32441b5

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_cmd.h

drivers/net/hinic3/mml/hinic3_mml_cmd.h +131 -0
@@ -0,0 +1,131 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+
 
+#ifndef _HINIC3_MML_CMD
 
+#define _HINIC3_MML_CMD
 
+
 
+#include <stdint.h>
 
+
 
+#define COMMAND_HELP_POSITION(argc)            \
 
+	({                                    \
 
+		typeof(argc) __argc = (argc); \
 
+		(__argc == 1 || __argc == 2); \
 
+	})
 
+#define COMMAND_VERSION_POSITION(argc) ((argc) == 2)
 
+#define SUB_COMMAND_OFFSET	      2
 
+
 
+#define COMMAND_MAX_MAJORS	 128
 
+#define COMMAND_MAX_OPTIONS	 64
 
+#define PARAM_MAX_STRING	 128
 
+#define COMMAND_MAX_STRING	 512
 
+#define COMMANDER_ERR_MAX_STRING 128
 
+
 
+#define MAX_NAME_LEN	 32
 
+#define MAX_DES_LEN	 128
 
+#define MAX_SHOW_STR_LEN 2048
 
+
 
+struct tag_major_cmd_t;
 
+struct tag_cmd_adapter_t;
 
+
 
+typedef int (*command_record_t)(struct tag_major_cmd_t *major, char *param);
 
+typedef void (*command_executeute_t)(struct tag_major_cmd_t *major);
 
+
 
+typedef struct {
 
+	const char *little;
 
+	const char *large;
 
+	unsigned int have_param;
 
+	command_record_t record;
 
+} cmd_option_t;
 
+
 
+/* Major command structure for save command details and options. */
 
+typedef struct tag_major_cmd_t {
 
+	struct tag_cmd_adapter_t *adapter;
 
+	char name[MAX_NAME_LEN];
 
+	int option_count;
 
+	cmd_option_t options[COMMAND_MAX_OPTIONS];
 
+	uint32_t options_repeat_flag[COMMAND_MAX_OPTIONS];
 
+	command_executeute_t execute;
 
+	int err_no;
 
+	char err_str[COMMANDER_ERR_MAX_STRING];
 
+	char show_str[MAX_SHOW_STR_LEN];
 
+	int show_len;
 
+	char description[MAX_DES_LEN];
 
+	void *cmd_st; /**< Command show queue state structure. */
 
+} major_cmd_t;
 
+
 
+typedef struct tag_cmd_adapter_t {
 
+	const char *name;
 
+	const char *version;
 
+	major_cmd_t *p_major_cmd[COMMAND_MAX_MAJORS];
 
+	int major_cmds;
 
+	char show_str[MAX_SHOW_STR_LEN];
 
+	int show_len;
 
+	char *cmd_buf;
 
+} cmd_adapter_t;
 
+
 
+/**
 
+ * Add an option to a major command.
 
+ *
 
+ * This function adds a command option with its short and long forms, whether it
 
+ * requires a parameter, and the function to handle it.
 
+ *
 
+ * @param[in] major_cmd
 
+ * Pointer to the major command structure.
 
+ * @param[in] little
 
+ * Short form of the option.
 
+ * @param[in] large
 
+ * Long form of the option.
 
+ * @param[in] have_param
 
+ * Flag indicating whether the option requires a parameter.
 
+ * @param[in] record
 
+ * Function to handle the option's action.
 
+ */
 
+void major_command_option(major_cmd_t *major_cmd, const char *little,
 
+			  const char *large, uint32_t have_param,
 
+			  command_record_t record);
 
+
 
+/**
 
+ * Register a major command with adapter.
 
+ *
 
+ * @param[in] adapter
 
+ * Pointer to command adapter.
 
+ * @param[in] major_cmd
 
+ * The major command to be registered with the adapter.
 
+ */
 
+void major_command_register(cmd_adapter_t *adapter, major_cmd_t *major_cmd);
 
+
 
+/**
 
+ * Parse and execute commands.
 
+ *
 
+ * @param[in] adapter
 
+ * Pointer to command adapter.
 
+ * @param[in] argc
 
+ * The number of command arguments.
 
+ * @param[in] argv
 
+ * The array of command arguments.
 
+ * @param[out] buf_out
 
+ * The buffer used to store the output result.
 
+ * @param[out] out_len
 
+ * The length (in bytes) of the output result.
 
+ */
 
+void command_parse(cmd_adapter_t *adapter, int argc, char **argv, void *buf_out,
 
+		   uint32_t *out_len);
 
+
 
+/**
 
+ * Initialize the target bus number and device name.
 
+ *
 
+ * @param[out] bus_num
 
+ * Pointer to the bus number, which will be set to a default unknown value.
 
+ * @param[out] dev_name
 
+ * Pointer to the device name buffer, which will be cleared (set to zeros).
 
+ * @param[in] len
 
+ * The length of the device name buffer.
 
+ */
 
+void tool_target_init(int *bus_num, char *dev_name, int len);
 
+
 
+int cmd_show_q_init(cmd_adapter_t *adapter);
 
+int cmd_show_xstats_init(cmd_adapter_t *adapter);
 
+int cmd_show_dump_init(cmd_adapter_t *adapter);
 
+
 
+#endif /* _HINIC3_MML_CMD */
drivers/net/hinic3/mml/hinic3_mml_ioctl.c +0 -0

new file mode 100644

index 0000000000..e0ae558f05

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_ioctl.c

drivers/net/hinic3/mml/hinic3_mml_ioctl.c +215 -0
@@ -0,0 +1,215 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+#include <rte_ethdev.h>
 
+#include <rte_pci.h>
 
+#include <rte_bus_pci.h>
 
+#include <rte_common.h>
 
+#include <rte_ether.h>
 
+#include <rte_ethdev_core.h>
 
+#include "hinic3_mml_lib.h"
 
+#include "hinic3_dbg.h"
 
+#include "hinic3_compat.h"
 
+#include "hinic3_csr.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_nic_cfg.h"
 
+#include "hinic3_ethdev.h"
 
+
 
+static int
 
+get_tx_info(struct rte_eth_dev *dev, void *buf_in, uint16_t in_size,
 
+	    void *buf_out, uint16_t *out_size)
 
+{
 
+	uint16_t q_id = *((uint16_t *)buf_in);
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	if (in_size != sizeof(int))
 
+		return -UDA_EINVAL;
 
+
 
+	return hinic3_dbg_get_sq_info(nic_dev->hwdev, q_id, buf_out, out_size);
 
+}
 
+
 
+static int
 
+get_tx_wqe_info(struct rte_eth_dev *dev, void *buf_in, uint16_t in_size,
 
+		void *buf_out, uint16_t *out_size)
 
+{
 
+	struct hinic_wqe_info *wqe_info = (struct hinic_wqe_info *)buf_in;
 
+	uint16_t q_id = (uint16_t)wqe_info->q_id;
 
+	uint16_t idx = (uint16_t)wqe_info->wqe_id;
 
+	uint16_t wqebb_cnt = (uint16_t)wqe_info->wqebb_cnt;
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	if (in_size != sizeof(struct hinic_wqe_info))
 
+		return -UDA_EINVAL;
 
+
 
+	return hinic3_dbg_get_sq_wqe_info(nic_dev->hwdev, q_id, idx, wqebb_cnt,
 
+					  buf_out, out_size);
 
+}
 
+
 
+static int
 
+get_rx_info(struct rte_eth_dev *dev, void *buf_in, uint16_t in_size,
 
+	    void *buf_out, uint16_t *out_size)
 
+{
 
+	uint16_t q_id = *((uint16_t *)buf_in);
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	if (in_size != sizeof(int))
 
+		return -UDA_EINVAL;
 
+
 
+	return hinic3_dbg_get_rq_info(nic_dev->hwdev, q_id, buf_out, out_size);
 
+}
 
+
 
+static int
 
+get_rx_wqe_info(struct rte_eth_dev *dev, void *buf_in, uint16_t in_size,
 
+		void *buf_out, uint16_t *out_size)
 
+{
 
+	struct hinic_wqe_info *wqe_info = (struct hinic_wqe_info *)buf_in;
 
+	uint16_t q_id = (uint16_t)wqe_info->q_id;
 
+	uint16_t idx = (uint16_t)wqe_info->wqe_id;
 
+	uint16_t wqebb_cnt = (uint16_t)wqe_info->wqebb_cnt;
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	if (in_size != sizeof(struct hinic_wqe_info))
 
+		return -UDA_EINVAL;
 
+
 
+	return hinic3_dbg_get_rq_wqe_info(nic_dev->hwdev, q_id, idx, wqebb_cnt,
 
+					  buf_out, out_size);
 
+}
 
+
 
+static int
 
+get_rx_cqe_info(struct rte_eth_dev *dev, void *buf_in, uint16_t in_size,
 
+		void *buf_out, uint16_t *out_size)
 
+{
 
+	struct hinic_wqe_info *wqe_info = (struct hinic_wqe_info *)buf_in;
 
+	uint16_t q_id = (uint16_t)wqe_info->q_id;
 
+	uint16_t idx = (uint16_t)wqe_info->wqe_id;
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+
 
+	if (in_size != sizeof(struct hinic_wqe_info))
 
+		return -UDA_EINVAL;
 
+
 
+	return hinic3_dbg_get_rx_cqe_info(nic_dev->hwdev, q_id, idx, buf_out,
 
+					  out_size);
 
+}
 
+
 
+typedef int (*nic_drv_module)(struct rte_eth_dev *dev, void *buf_in,
 
+			      uint16_t in_size, void *buf_out,
 
+			      uint16_t *out_size);
 
+
 
+struct nic_drv_module_handle {
 
+	enum driver_cmd_type drv_cmd_name;
 
+	nic_drv_module drv_func;
 
+};
 
+
 
+const struct nic_drv_module_handle g_nic_drv_module_cmd_handle[] = {
 
+	{TX_INFO, get_tx_info},		{TX_WQE_INFO, get_tx_wqe_info},
 
+	{RX_INFO, get_rx_info},		{RX_WQE_INFO, get_rx_wqe_info},
 
+	{RX_CQE_INFO, get_rx_cqe_info},
 
+};
 
+
 
+static int
 
+send_to_nic_driver(struct rte_eth_dev *dev, struct msg_module *nt_msg)
 
+{
 
+	int index;
 
+	int err = 0;
 
+	enum driver_cmd_type cmd_type =
 
+		(enum driver_cmd_type)nt_msg->msg_format;
 
+	int num_cmds = sizeof(g_nic_drv_module_cmd_handle) /
 
+		       sizeof(g_nic_drv_module_cmd_handle[0]);
 
+
 
+	for (index = 0; index < num_cmds; index++) {
 
+		if (cmd_type ==
 
+		    g_nic_drv_module_cmd_handle[index].drv_cmd_name) {
 
+			err = g_nic_drv_module_cmd_handle[index].drv_func(dev,
 
+				nt_msg->in_buf,
 
+				(uint16_t)nt_msg->buf_in_size, nt_msg->out_buf,
 
+				(uint16_t *)&nt_msg->buf_out_size);
 
+			break;
 
+		}
 
+	}
 
+
 
+	if (index == num_cmds) {
 
+		PMD_DRV_LOG(ERR, "Unknown nic driver cmd: %d", cmd_type);
 
+		err = -UDA_EINVAL;
 
+	}
 
+
 
+	return err;
 
+}
 
+
 
+static int
 
+hinic3_msg_handle(struct rte_eth_dev *dev, struct msg_module *nt_msg)
 
+{
 
+	int err;
 
+
 
+	switch (nt_msg->module) {
 
+	case SEND_TO_NIC_DRIVER:
 
+		err = send_to_nic_driver(dev, nt_msg);
 
+		if (err != 0)
 
+			PMD_DRV_LOG(ERR, "Send message to driver failed");
 
+		break;
 
+	default:
 
+		PMD_DRV_LOG(ERR, "Unknown message module: %d", nt_msg->module);
 
+		err = -UDA_EINVAL;
 
+		break;
 
+	}
 
+
 
+	return err;
 
+}
 
+
 
+static struct rte_eth_dev *
 
+get_eth_dev_by_pci_addr(char *pci_addr, __rte_unused int len)
 
+{
 
+	uint32_t i;
 
+	struct rte_eth_dev *eth_dev = NULL;
 
+	struct rte_pci_device *pci_dev = NULL;
 
+	int ret;
 
+	uint32_t bus, devid, function;
 
+
 
+	ret = sscanf(pci_addr, "%02x:%02x.%x", &bus, &devid, &function);
 
+	if (ret <= 0) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Get pci bus devid and function id fail, err: %d",
 
+			    ret);
 
+		return NULL;
 
+	}
 
+
 
+	for (i = 0; i < RTE_MAX_ETHPORTS; i++) {
 
+		eth_dev = &rte_eth_devices[i];
 
+		if (eth_dev->state != RTE_ETH_DEV_ATTACHED)
 
+			continue;
 
+
 
+		pci_dev = RTE_ETH_DEV_TO_PCI(eth_dev);
 
+
 
+#ifdef CONFIG_SP_VID_DID
 
+		if (pci_dev->id.vendor_id == PCI_VENDOR_ID_SPNIC &&
 
+		    (pci_dev->id.device_id == HINIC3_DEV_ID_STANDARD ||
 
+		     pci_dev->id.device_id == HINIC3_DEV_ID_VF) &&
 
+#else
 
+		if (pci_dev->id.vendor_id == PCI_VENDOR_ID_HUAWEI &&
 
+		    (pci_dev->id.device_id == HINIC3_DEV_ID_STANDARD ||
 
+		     pci_dev->id.device_id == HINIC3_DEV_ID_VF) &&
 
+#endif
 
+		    pci_dev->addr.bus == bus && pci_dev->addr.devid == devid &&
 
+		    pci_dev->addr.function == function) {
 
+			return eth_dev;
 
+		}
 
+	}
 
+
 
+	return NULL;
 
+}
 
+
 
+int
 
+hinic3_pmd_mml_ioctl(void *msg)
 
+{
 
+	struct msg_module *nt_msg = msg;
 
+	struct rte_eth_dev *dev;
 
+
 
+	dev = get_eth_dev_by_pci_addr(nt_msg->device_name,
 
+				      sizeof(nt_msg->device_name));
 
+	if (!dev) {
 
+		PMD_DRV_LOG(ERR, "Can not get the device %s correctly",
 
+			    nt_msg->device_name);
 
+		return UDA_FAIL;
 
+	}
 
+
 
+	return hinic3_msg_handle(dev, nt_msg);
 
+}
drivers/net/hinic3/mml/hinic3_mml_lib.c +0 -0

new file mode 100644

index 0000000000..c74777f50b

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_lib.c

drivers/net/hinic3/mml/hinic3_mml_lib.c +136 -0
@@ -0,0 +1,136 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+#include "hinic3_compat.h"
 
+#include "hinic3_mml_lib.h"
 
+
 
+int
 
+tool_get_valid_target(char *name, struct tool_target *target)
 
+{
 
+	int ret = UDA_SUCCESS;
 
+
 
+	if (strlen(name) >= MAX_DEV_LEN) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Input parameter of device name is too long.");
 
+		ret = -UDA_ELEN;
 
+	} else {
 
+		memcpy(target->dev_name, name, strlen(name));
 
+		target->bus_num = 0;
 
+	}
 
+
 
+	return ret;
 
+}
 
+
 
+static void
 
+fill_ioctl_msg_hd(struct msg_module *msg, unsigned int module,
 
+		  unsigned int msg_format, unsigned int in_buff_len,
 
+		  unsigned int out_buff_len, char *dev_name, int bus_num)
 
+{
 
+	memcpy(msg->device_name, dev_name, strlen(dev_name) + 1);
 
+
 
+	msg->module = module;
 
+	msg->msg_format = msg_format;
 
+	msg->buf_in_size = in_buff_len;
 
+	msg->buf_out_size = out_buff_len;
 
+	msg->bus_num = bus_num;
 
+}
 
+
 
+static int
 
+lib_ioctl(struct msg_module *in_buf, void *out_buf)
 
+{
 
+	in_buf->out_buf = out_buf;
 
+
 
+	return hinic3_pmd_mml_ioctl(in_buf);
 
+}
 
+
 
+int
 
+lib_tx_sq_info_get(struct tool_target target, struct nic_sq_info *sq_info,
 
+		   int sq_id)
 
+{
 
+	struct msg_module msg_to_kernel;
 
+
 
+	memset(&msg_to_kernel, 0, sizeof(msg_to_kernel));
 
+	fill_ioctl_msg_hd(&msg_to_kernel, SEND_TO_NIC_DRIVER, TX_INFO,
 
+			  (unsigned int)sizeof(int),
 
+			  (unsigned int)sizeof(struct nic_sq_info),
 
+			  target.dev_name, target.bus_num);
 
+	msg_to_kernel.in_buf = (void *)&sq_id;
 
+
 
+	return lib_ioctl(&msg_to_kernel, sq_info);
 
+}
 
+
 
+int
 
+lib_tx_wqe_info_get(struct tool_target target, struct nic_sq_info *sq_info,
 
+		    int sq_id, int wqe_id, void *nwqe, int nwqe_size)
 
+{
 
+	struct msg_module msg_to_kernel;
 
+	struct hinic_wqe_info wqe = {0};
 
+
 
+	wqe.wqe_id = wqe_id;
 
+	wqe.q_id = sq_id;
 
+	wqe.wqebb_cnt = nwqe_size / sq_info->sq_wqebb_size;
 
+
 
+	memset(&msg_to_kernel, 0, sizeof(msg_to_kernel));
 
+	fill_ioctl_msg_hd(&msg_to_kernel, SEND_TO_NIC_DRIVER, TX_WQE_INFO,
 
+			  (unsigned int)(sizeof(struct hinic_wqe_info)),
 
+			  nwqe_size, target.dev_name, target.bus_num);
 
+	msg_to_kernel.in_buf = (void *)&wqe;
 
+
 
+	return lib_ioctl(&msg_to_kernel, nwqe);
 
+}
 
+
 
+int
 
+lib_rx_rq_info_get(struct tool_target target, struct nic_rq_info *rq_info,
 
+		   int rq_id)
 
+{
 
+	struct msg_module msg_to_kernel;
 
+
 
+	memset(&msg_to_kernel, 0, sizeof(msg_to_kernel));
 
+	fill_ioctl_msg_hd(&msg_to_kernel, SEND_TO_NIC_DRIVER, RX_INFO,
 
+			  (unsigned int)(sizeof(int)),
 
+			  (unsigned int)sizeof(struct nic_rq_info),
 
+			  target.dev_name, target.bus_num);
 
+	msg_to_kernel.in_buf = &rq_id;
 
+
 
+	return lib_ioctl(&msg_to_kernel, rq_info);
 
+}
 
+
 
+int
 
+lib_rx_wqe_info_get(struct tool_target target, struct nic_rq_info *rq_info,
 
+		    int rq_id, int wqe_id, void *nwqe, int nwqe_size)
 
+{
 
+	struct msg_module msg_to_kernel;
 
+	struct hinic_wqe_info wqe = {0};
 
+
 
+	wqe.wqe_id = wqe_id;
 
+	wqe.q_id = rq_id;
 
+	wqe.wqebb_cnt = nwqe_size / rq_info->rq_wqebb_size;
 
+
 
+	memset(&msg_to_kernel, 0, sizeof(msg_to_kernel));
 
+	fill_ioctl_msg_hd(&msg_to_kernel, SEND_TO_NIC_DRIVER, RX_WQE_INFO,
 
+			  (unsigned int)(sizeof(struct hinic_wqe_info)),
 
+			  nwqe_size, target.dev_name, target.bus_num);
 
+	msg_to_kernel.in_buf = (void *)&wqe;
 
+
 
+	return lib_ioctl(&msg_to_kernel, nwqe);
 
+}
 
+
 
+int
 
+lib_rx_cqe_info_get(struct tool_target target,
 
+		    __rte_unused struct nic_rq_info *rq_info, int rq_id,
 
+		    int wqe_id, void *nwqe, int nwqe_size)
 
+{
 
+	struct msg_module msg_to_kernel;
 
+	struct hinic_wqe_info wqe = {0};
 
+
 
+	wqe.wqe_id = wqe_id;
 
+	wqe.q_id = rq_id;
 
+
 
+	memset(&msg_to_kernel, 0, sizeof(msg_to_kernel));
 
+	fill_ioctl_msg_hd(&msg_to_kernel, SEND_TO_NIC_DRIVER, RX_CQE_INFO,
 
+			  (unsigned int)(sizeof(struct hinic_wqe_info)),
 
+			  nwqe_size, target.dev_name, target.bus_num);
 
+	msg_to_kernel.in_buf = (void *)&wqe;
 
+
 
+	return lib_ioctl(&msg_to_kernel, nwqe);
 
+}
drivers/net/hinic3/mml/hinic3_mml_lib.h +0 -0

new file mode 100644

index 0000000000..ab045525f3

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_lib.h

drivers/net/hinic3/mml/hinic3_mml_lib.h +276 -0
@@ -0,0 +1,276 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright (c) Huawei Technologies Co., Ltd. 2025. All rights reserved.
 
+ */
 
+
 
+#ifndef _HINIC3_MML_LIB
 
+#define _HINIC3_MML_LIB
 
+
 
+#include <string.h>
 
+#include <stdint.h>
 
+
 
+#include "hinic3_mml_cmd.h"
 
+#include "hinic3_compat.h"
 
+#include "hinic3_mgmt.h"
 
+
 
+#define MAX_DEV_LEN	      16
 
+#define TRGET_UNKNOWN_BUS_NUM (-1)
 
+
 
+#ifndef DEV_NAME_LEN
 
+#define DEV_NAME_LEN 64
 
+#endif
 
+
 
+enum {
 
+	UDA_SUCCESS = 0x0,
 
+	UDA_FAIL,
 
+	UDA_ENXIO,
 
+	UDA_ENONMEM,
 
+	UDA_EBUSY,
 
+	UDA_ECRC,
 
+	UDA_EINVAL,
 
+	UDA_EFAULT,
 
+	UDA_ELEN,
 
+	UDA_ECMD,
 
+	UDA_ENODRIVER,
 
+	UDA_EXIST,
 
+	UDA_EOVERSTEP,
 
+	UDA_ENOOBJ,
 
+	UDA_EOBJ,
 
+	UDA_ENOMATCH,
 
+	UDA_ETIMEOUT,
 
+
 
+	UDA_CONTOP,
 
+
 
+	UDA_REBOOT = 0xFD,
 
+	UDA_CANCEL = 0xFE,
 
+	UDA_KILLED = 0xFF,
 
+};
 
+
 
+#define PARAM_NEED     1
 
+#define PARAM_NOT_NEED 0
 
+
 
+#define BASE_ALL 0
 
+#define BASE_8	 8
 
+#define BASE_10	 10
 
+#define BASE_16	 16
 
+
 
+enum module_name {
 
+	SEND_TO_NPU = 1,
 
+	SEND_TO_MPU,
 
+	SEND_TO_SM,
 
+
 
+	SEND_TO_HW_DRIVER,
 
+	SEND_TO_NIC_DRIVER,
 
+	SEND_TO_OVS_DRIVER,
 
+	SEND_TO_ROCE_DRIVER,
 
+	SEND_TO_TOE_DRIVER,
 
+	SEND_TO_IWAP_DRIVER,
 
+	SEND_TO_FC_DRIVER,
 
+	SEND_FCOE_DRIVER,
 
+};
 
+
 
+enum driver_cmd_type {
 
+	TX_INFO = 1,
 
+	Q_NUM,
 
+	TX_WQE_INFO,
 
+	TX_MAPPING,
 
+	RX_INFO,
 
+	RX_WQE_INFO,
 
+	RX_CQE_INFO
 
+};
 
+
 
+struct tool_target {
 
+	int bus_num;
 
+	char dev_name[MAX_DEV_LEN];
 
+	void *pri;
 
+};
 
+
 
+struct nic_tx_hw_page {
 
+	long long phy_addr;
 
+	long long *map_addr;
 
+};
 
+
 
+struct nic_sq_info {
 
+	unsigned short q_id;
 
+	unsigned short pi; /**< Ring buffer queue producer point. */
 
+	unsigned short ci; /**< Ring buffer queue consumer point. */
 
+	unsigned short fi; /**< Ring buffer queue complete point. */
 
+	unsigned int sq_depth;
 
+	unsigned short sq_wqebb_size;
 
+	unsigned short *ci_addr;
 
+	uint64_t cla_addr;
 
+
 
+	struct nic_tx_hw_page doorbell;
 
+	unsigned int page_idx;
 
+};
 
+
 
+struct comm_info_l2nic_sq_ci_attr {
 
+	struct mgmt_msg_head msg_head;
 
+
 
+	uint16_t func_idx;
 
+	uint8_t dma_attr_off;
 
+	uint8_t pending_limit;
 
+
 
+	uint8_t coalescing_time;
 
+	uint8_t int_en;
 
+	uint16_t int_offset;
 
+
 
+	uint32_t l2nic_sqn;
 
+	uint32_t rsv;
 
+	uint64_t ci_addr;
 
+};
 
+
 
+struct nic_rq_info {
 
+	unsigned short q_id; /**< Queue id in current function, 0, 1, 2... */
 
+
 
+	unsigned short hw_pi; /**< Where pkt buf allocated. */
 
+	unsigned short ci;    /**< Where hw pkt received, owned by hw. */
 
+	unsigned short sw_pi; /**< Where driver begin receive pkt. */
 
+	unsigned short rq_wqebb_size; /**< wqebb size, default to 32 bytes. */
 
+
 
+	unsigned short rq_depth;
 
+	unsigned short buf_len; /**< 2K. */
 
+	void *ci_wqe_page_addr; /**< For queue context init. */
 
+	void *ci_cla_tbl_addr;
 
+	unsigned short int_num;	  /**< RSS support should consider int_num. */
 
+	unsigned int msix_vector; /**< For debug. */
 
+};
 
+
 
+struct hinic_wqe_info {
 
+	int q_id;
 
+	void *slq_handle;
 
+	uint32_t wqe_id;
 
+	uint32_t wqebb_cnt;
 
+};
 
+
 
+struct npu_cmd_st {
 
+	uint32_t mod : 8;
 
+	uint32_t cmd : 8;
 
+	uint32_t ack_type : 3;
 
+	uint32_t direct_resp : 1;
 
+	uint32_t len : 12;
 
+};
 
+
 
+struct mpu_cmd_st {
 
+	uint32_t api_type : 8;
 
+	uint32_t mod : 8;
 
+	uint32_t cmd : 16;
 
+};
 
+
 
+struct msg_module {
 
+	char device_name[DEV_NAME_LEN];
 
+	uint32_t module;
 
+	union {
 
+		uint32_t msg_format; /**< For driver. */
 
+		struct npu_cmd_st npu_cmd;
 
+		struct mpu_cmd_st mpu_cmd;
 
+	};
 
+	uint32_t timeout; /**< For mpu/npu cmd. */
 
+	uint32_t func_idx;
 
+	uint32_t buf_in_size;
 
+	uint32_t buf_out_size;
 
+	void *in_buf;
 
+	void *out_buf;
 
+	int bus_num;
 
+	uint32_t rsvd2[5];
 
+};
 
+
 
+/**
 
+ * Convert the provided string into `uint32_t` according to the specified base.
 
+ *
 
+ * @param[in] nptr
 
+ * The string to be converted.
 
+ * @param[in] base
 
+ * The base to use for conversion (e.g., 10 for decimal, 16 for hexadecimal).
 
+ * @param[out] value
 
+ * The output variable where the converted `uint32_t` value will be stored.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ * - -UDA_EINVAL if the string is invalid or the value is out of range.
 
+ */
 
+static inline int
 
+string_toui(const char *nptr, int base, uint32_t *value)
 
+{
 
+	char *endptr = NULL;
 
+	long tmp_value;
 
+
 
+	tmp_value = strtol(nptr, &endptr, base);
 
+	if ((*endptr != 0) || tmp_value >= 0x7FFFFFFF || tmp_value < 0)
 
+		return -UDA_EINVAL;
 
+	*value = (uint32_t)tmp_value;
 
+	return UDA_SUCCESS;
 
+}
 
+
 
+#define UDA_TRUE  1
 
+#define UDA_FALSE 0
 
+
 
+/**
 
+ * Format and append a log message to a string buffer.
 
+ *
 
+ * @param[out] show_str
 
+ * The string buffer where the formatted message will be appended.
 
+ * @param[out] show_len
 
+ * The current length of the string in the buffer. It is updated after
 
+ * appending.
 
+ * @param[in] fmt
 
+ * The format string that specifies how to format the log message.
 
+ * @param[in] args
 
+ * The variable arguments to be formatted according to the format string.
 
+ */
 
+static inline void
 
+__rte_format_printf(3, 4)
 
+hinic3_pmd_mml_log(char *show_str, int *show_len, const char *fmt, ...)
 
+{
 
+	va_list args;
 
+	int ret = 0;
 
+
 
+	va_start(args, fmt);
 
+	ret = vsprintf(show_str + *show_len, fmt, args);
 
+	va_end(args);
 
+
 
+	if (ret > 0) {
 
+		*show_len += ret;
 
+	} else {
 
+		PMD_DRV_LOG(ERR, "MML show string snprintf failed, err: %d",
 
+			    ret);
 
+	}
 
+}
 
+
 
+/**
 
+ * Get a valid target device based on the given name.
 
+ *
 
+ * This function checks if the device name is valid (within the length limit)
 
+ * and then stores it in the target structure. The bus number is initialized to
 
+ * 0.
 
+ *
 
+ * @param[in] name
 
+ * The device name to be validated and stored.
 
+ * @param[out] target
 
+ * The structure where the device name and bus number will be stored.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+int tool_get_valid_target(char *name, struct tool_target *target);
 
+
 
+int hinic3_pmd_mml_ioctl(void *msg);
 
+
 
+int lib_tx_sq_info_get(struct tool_target target, struct nic_sq_info *sq_info,
 
+		       int sq_id);
 
+
 
+int lib_tx_wqe_info_get(struct tool_target target, struct nic_sq_info *sq_info,
 
+			int sq_id, int wqe_id, void *nwqe, int nwqe_size);
 
+
 
+int lib_rx_rq_info_get(struct tool_target target, struct nic_rq_info *rq_info,
 
+		       int rq_id);
 
+
 
+int lib_rx_wqe_info_get(struct tool_target target, struct nic_rq_info *rq_info,
 
+			int rq_id, int wqe_id, void *nwqe, int nwqe_size);
 
+
 
+int lib_rx_cqe_info_get(struct tool_target target, struct nic_rq_info *rq_info,
 
+			int rq_id, int wqe_id, void *nwqe, int nwqe_size);
 
+
 
+int hinic3_pmd_mml_lib(const char *buf_in, uint32_t in_size, char *buf_out,
 
+		       uint32_t *out_len, uint32_t max_buf_out_len);
 
+
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/mml/hinic3_mml_main.c +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..0b508bc1c3

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_main.c

drivers/net/hinic3/mml/hinic3_mml_main.c +167 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/mml/hinic3_mml_queue.c +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..2e0c4a284b

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_queue.c

drivers/net/hinic3/mml/hinic3_mml_queue.c +745 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/mml/hinic3_mml_queue.h +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..61b91fb115

--- /dev/null

+++ b/drivers/net/hinic3/mml/hinic3_mml_queue.h

drivers/net/hinic3/mml/hinic3_mml_queue.h +256 -0

Lines of this file are not shown. View the raw message.

drivers/net/hinic3/mml/meson.build +0 -0

The rest of this diff is not shown. View the raw message.

new file mode 100644

index 0000000000..f8d2650d8d

--- /dev/null

+++ b/drivers/net/hinic3/mml/meson.build

drivers/net/hinic3/mml/meson.build +62 -0

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Part of the diff is not shown here. View the raw message.

#157 lore raw

PATCH v5 16/18 net/hinic3: add RSS promiscuous ops

In reply to Feifei Wang

From: Xin Wang <[email protected]>

Add RSS and promiscuous ops related function codes.

---
 drivers/net/hinic3/hinic3_ethdev.c | 370 +++++++++++++++++++++++++++++
 drivers/net/hinic3/hinic3_ethdev.h |  31 +++
 2 files changed, 401 insertions(+)
drivers/net/hinic3/hinic3_ethdev.c +370 -0
index ac36c49afc..0807e017c2 100644
@@ -2277,6 +2277,281 @@ hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)
 	return 0;
 }
 
+/**
+ * Enable promiscuous mode.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_promiscuous_enable(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 rx_mode;
+	int err;
+
+	err = hinic3_mutex_lock(&nic_dev->rx_mode_mutex);
+	if (err)
+		return err;
+
+	rx_mode = nic_dev->rx_mode | HINIC3_RX_MODE_PROMISC;
+
+	err = hinic3_set_rx_mode(nic_dev->hwdev, rx_mode);
+	if (err) {
+		hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+		PMD_DRV_LOG(ERR, "Enable promiscuous failed");
+		return err;
+	}
+
+	nic_dev->rx_mode = rx_mode;
+
+	hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+
+	PMD_DRV_LOG(INFO,
+		    "Enable promiscuous, nic_dev: %s, port_id: %d, promisc: %d",
+		    nic_dev->dev_name, dev->data->port_id,
+		    dev->data->promiscuous);
+	return 0;
+}
+
+/**
+ * Disable promiscuous mode.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_promiscuous_disable(struct rte_eth_dev *dev)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 rx_mode;
+	int err;
+
+	err = hinic3_mutex_lock(&nic_dev->rx_mode_mutex);
+	if (err)
+		return err;
+
+	rx_mode = nic_dev->rx_mode & (~HINIC3_RX_MODE_PROMISC);
+
+	err = hinic3_set_rx_mode(nic_dev->hwdev, rx_mode);
+	if (err) {
+		hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+		PMD_DRV_LOG(ERR, "Disable promiscuous failed");
+		return err;
+	}
+
+	nic_dev->rx_mode = rx_mode;
+
+	hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
+
+	PMD_DRV_LOG(INFO,
+		"Disable promiscuous, nic_dev: %s, port_id: %d, promisc: %d",
+		nic_dev->dev_name, dev->data->port_id, dev->data->promiscuous);
+	return 0;
+}
+
+/**
+ * Get flow control configuration, including auto-negotiation and RX/TX pause
+ * settings.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ *
+ * @param[out] fc_conf
+ * The flow control configuration to be filled.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+
+/**
+ * Update the RSS hash key and RSS hash type.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] rss_conf
+ * RSS configuration data.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_rss_hash_update(struct rte_eth_dev *dev,
+		       struct rte_eth_rss_conf *rss_conf)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct hinic3_rss_type rss_type = {0};
+	u64 rss_hf = rss_conf->rss_hf;
+	int err = 0;
+
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE) {
+		if (rss_hf != 0)
+			return -EINVAL;
+
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
+		return 0;
+	}
+
+	if (rss_conf->rss_key_len > HINIC3_RSS_KEY_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid RSS key, rss_key_len: %d",
+			    rss_conf->rss_key_len);
+		return -EINVAL;
+	}
+
+	if (rss_conf->rss_key) {
+		err = hinic3_rss_set_hash_key(nic_dev->hwdev, nic_dev->rss_key,
+					      HINIC3_RSS_KEY_SIZE);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Set RSS hash key failed");
+			return err;
+		}
+		memcpy((void *)nic_dev->rss_key, (void *)rss_conf->rss_key,
+		       (size_t)rss_conf->rss_key_len);
+	}
+
+	rss_type.ipv4 = (rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
+				   RTE_ETH_RSS_NONFRAG_IPV4_OTHER))
+				? 1
+				: 0;
+	rss_type.tcp_ipv4 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ? 1 : 0;
+	rss_type.ipv6 = (rss_hf & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
+				   RTE_ETH_RSS_NONFRAG_IPV6_OTHER))
+				? 1
+				: 0;
+	rss_type.ipv6_ext = (rss_hf & RTE_ETH_RSS_IPV6_EX) ? 1 : 0;
+	rss_type.tcp_ipv6 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ? 1 : 0;
+	rss_type.tcp_ipv6_ext = (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX) ? 1 : 0;
+	rss_type.udp_ipv4 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ? 1 : 0;
+	rss_type.udp_ipv6 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ? 1 : 0;
+
+	err = hinic3_set_rss_type(nic_dev->hwdev, rss_type);
+	if (err)
+		PMD_DRV_LOG(ERR, "Set RSS type failed");
+
+	return err;
+}
+
+/**
+ * Get the RSS hash configuration.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[out] rss_conf
+ * RSS configuration data.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_rss_conf_get(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct hinic3_rss_type rss_type = {0};
+	int err;
+
+	if (!rss_conf)
+		return -EINVAL;
+
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE) {
+		rss_conf->rss_hf = 0;
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
+		return 0;
+	}
+
+	if (rss_conf->rss_key && rss_conf->rss_key_len >= HINIC3_RSS_KEY_SIZE) {
+		/*
+		 * Get RSS key from driver to reduce the frequency of the MPU
+		 * accessing the RSS memory.
+		 */
+		rss_conf->rss_key_len = sizeof(nic_dev->rss_key);
+		memcpy((void *)rss_conf->rss_key, (void *)nic_dev->rss_key,
+		       (size_t)rss_conf->rss_key_len);
+	}
+
+	err = hinic3_get_rss_type(nic_dev->hwdev, &rss_type);
+	if (err)
+		return err;
+
+	rss_conf->rss_hf = 0;
+	rss_conf->rss_hf |=
+		rss_type.ipv4 ? (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
+				 RTE_ETH_RSS_NONFRAG_IPV4_OTHER)
+			      : 0;
+	rss_conf->rss_hf |= rss_type.tcp_ipv4 ? RTE_ETH_RSS_NONFRAG_IPV4_TCP
+					      : 0;
+	rss_conf->rss_hf |=
+		rss_type.ipv6 ? (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
+				 RTE_ETH_RSS_NONFRAG_IPV6_OTHER)
+			      : 0;
+	rss_conf->rss_hf |= rss_type.ipv6_ext ? RTE_ETH_RSS_IPV6_EX : 0;
+	rss_conf->rss_hf |= rss_type.tcp_ipv6 ? RTE_ETH_RSS_NONFRAG_IPV6_TCP
+					      : 0;
+	rss_conf->rss_hf |= rss_type.tcp_ipv6_ext ? RTE_ETH_RSS_IPV6_TCP_EX : 0;
+	rss_conf->rss_hf |= rss_type.udp_ipv4 ? RTE_ETH_RSS_NONFRAG_IPV4_UDP
+					      : 0;
+	rss_conf->rss_hf |= rss_type.udp_ipv6 ? RTE_ETH_RSS_NONFRAG_IPV6_UDP
+					      : 0;
+
+	return 0;
+}
+
+/**
+ * Get the RETA indirection table.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[out] reta_conf
+ * Pointer to RETA configuration structure array.
+ * @param[in] reta_size
+ * Size of the RETA table.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_rss_reta_query(struct rte_eth_dev *dev,
+		      struct rte_eth_rss_reta_entry64 *reta_conf,
+		      uint16_t reta_size)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 indirtbl[HINIC3_RSS_INDIR_SIZE] = {0};
+	u16 idx, shift;
+	u16 i;
+	int err;
+
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE) {
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
+		return 0;
+	}
+
+	if (reta_size != HINIC3_RSS_INDIR_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
+		return -EINVAL;
+	}
+
+	err = hinic3_rss_get_indir_tbl(nic_dev->hwdev, indirtbl,
+				       HINIC3_RSS_INDIR_SIZE);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Get RSS retas table failed, error: %d", err);
+		return err;
+	}
+
+	for (i = 0; i < reta_size; i++) {
+		idx = i / RTE_ETH_RETA_GROUP_SIZE;
+		shift = i % RTE_ETH_RETA_GROUP_SIZE;
+		if (reta_conf[idx].mask & (1ULL << shift))
+			reta_conf[idx].reta[shift] = (uint16_t)indirtbl[i];
+	}
+
+	return 0;
+}
+
 static int
 hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,
 		  struct rte_dev_eeprom_info *info)
@@ -2287,6 +2562,68 @@ hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,
 				  &info->length, MAX_BUF_OUT_LEN);
 }
 
+/**
+ * Update the RETA indirection table.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] reta_conf
+ * Pointer to RETA configuration structure array.
+ * @param[in] reta_size
+ * Size of the RETA table.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_rss_reta_update(struct rte_eth_dev *dev,
+		       struct rte_eth_rss_reta_entry64 *reta_conf,
+		       uint16_t reta_size)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	u32 indirtbl[HINIC3_RSS_INDIR_SIZE] = {0};
+	u16 idx, shift;
+	u16 i;
+	int err;
+
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE)
+		return 0;
+
+	if (reta_size != HINIC3_RSS_INDIR_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
+		return -EINVAL;
+	}
+
+	err = hinic3_rss_get_indir_tbl(nic_dev->hwdev, indirtbl,
+				       HINIC3_RSS_INDIR_SIZE);
+	if (err)
+		return err;
+
+	/* Update RSS reta table. */
+	for (i = 0; i < reta_size; i++) {
+		idx = i / RTE_ETH_RETA_GROUP_SIZE;
+		shift = i % RTE_ETH_RETA_GROUP_SIZE;
+		if (reta_conf[idx].mask & (1ULL << shift))
+			indirtbl[i] = reta_conf[idx].reta[shift];
+	}
+
+	for (i = 0; i < reta_size; i++) {
+		if (indirtbl[i] >= nic_dev->num_rqs) {
+			PMD_DRV_LOG(ERR,
+				"Invalid reta entry, index: %d, num_rqs: %d",
+				indirtbl[i], nic_dev->num_rqs);
+			return -EFAULT;
+		}
+	}
+
+	err = hinic3_rss_set_indir_tbl(nic_dev->hwdev, indirtbl,
+				       HINIC3_RSS_INDIR_SIZE);
+	if (err)
+		PMD_DRV_LOG(ERR, "Set RSS reta table failed");
+
+	return err;
+}
+
 /**
  * Get device generic statistics.
  *
@@ -2857,6 +3194,29 @@ hinic3_set_mc_addr_list(struct rte_eth_dev *dev,
 	return 0;
 }
 
+/**
+ * Manage flow director filter operations.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] filter_type
+ * Filter type.
+ * @param[in] filter_op
+ * Operation to perform.
+ * @param[in] arg
+ * Pointer to operation-specific structure.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hinic3_dev_filter_ctrl(struct rte_eth_dev *dev, const struct rte_flow_ops **arg)
+{
+	RTE_SET_USED(dev);
+	*arg = &hinic3_flow_ops;
+	return 0;
+}
+
 static int
 hinic3_get_reg(__rte_unused struct rte_eth_dev *dev,
 	       __rte_unused struct rte_dev_reg_info *regs)
@@ -2890,6 +3250,12 @@ static const struct eth_dev_ops hinic3_pmd_ops = {
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
+	.promiscuous_enable            = hinic3_dev_promiscuous_enable,
+	.promiscuous_disable           = hinic3_dev_promiscuous_disable,
+	.rss_hash_update               = hinic3_rss_hash_update,
+	.rss_hash_conf_get             = hinic3_rss_conf_get,
+	.reta_update                   = hinic3_rss_reta_update,
+	.reta_query                    = hinic3_rss_reta_query,
 	.get_eeprom                    = hinic3_get_eeprom,
 	.stats_get                     = hinic3_dev_stats_get,
 	.stats_reset                   = hinic3_dev_stats_reset,
@@ -2931,6 +3297,10 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = {
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
+	.rss_hash_update               = hinic3_rss_hash_update,
+	.rss_hash_conf_get             = hinic3_rss_conf_get,
+	.reta_update                   = hinic3_rss_reta_update,
+	.reta_query                    = hinic3_rss_reta_query,
 	.get_eeprom                    = hinic3_get_eeprom,
 	.stats_get                     = hinic3_dev_stats_get,
 	.stats_reset                   = hinic3_dev_stats_reset,
drivers/net/hinic3/hinic3_ethdev.h +31 -0
index e0d5b4602c..90ca21491f 100644
@@ -97,6 +97,10 @@ struct hinic3_nic_dev {
 	u16 rx_buff_len;
 	u16 mtu_size;
 
+	u16 rss_state;
+	u8 num_rss; /**< Number of RSS queues. */
+	u8 rsvd0;   /**< Reserved field 0. */
+
 	u32 rx_mode;
 	u8 rx_queue_list[HINIC3_MAX_QUEUE_NUM];
 	rte_spinlock_t queue_list_lock;
@@ -106,6 +110,8 @@ struct hinic3_nic_dev {
 	u32 default_cos;
 	u32 rx_csum_en;
 
+	u8 rss_key[HINIC3_RSS_KEY_SIZE];
+
 	RTE_ATOMIC(u64) dev_status;
 
 	struct rte_ether_addr default_addr;
@@ -116,4 +122,29 @@ struct hinic3_nic_dev {
 	u32 vfta[HINIC3_VFTA_SIZE]; /**< VLAN bitmap. */
 };
 
+/**
+ * Enable interrupt for the specified RX queue.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] queue_id
+ * The ID of the receive queue for which the interrupt is being enabled.
+ * @return
+ * 0 on success, a negative error code on failure.
+ */
+int hinic3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
+
+/**
+ * Disable interrupt for the specified RX queue.
+ *
+ * @param[in] dev
+ * Pointer to ethernet device structure.
+ * @param[in] queue_id
+ * The ID of the receive queue for which the interrupt is being disabled.
+ * @return
+ * 0 on success, a negative error code on failure.
+ */
+int hinic3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
+				     uint16_t queue_id);
+
 #endif /* _HINIC3_ETHDEV_H_ */
Signature · 1 line
2.45.1.windows.1
#158 lore raw

Re: [V5 16/18] net/hinic3: add RSS promiscuous ops

Quoted 934 lines · Feifei Wang

From: Xin Wang <[email protected]>

Add RSS and promiscuous ops related function codes.

---

 drivers/net/hinic3/hinic3_ethdev.c | 370 +++++++++++++++++++++++++++++
 drivers/net/hinic3/hinic3_ethdev.h |  31 +++
 2 files changed, 401 insertions(+)
drivers/net/hinic3/hinic3_ethdev.c +0 -0

index ac36c49afc..0807e017c2 100644

--- a/drivers/net/hinic3/hinic3_ethdev.c

+++ b/drivers/net/hinic3/hinic3_ethdev.c

drivers/net/hinic3/hinic3_ethdev.c +370 -0
@@ -2277,6 +2277,281 @@ hinic3_dev_allmulticast_disable(struct rte_eth_dev *dev)
 
 	return 0;
 
 }
 
 
 
+/**
 
+ * Enable promiscuous mode.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_promiscuous_enable(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u32 rx_mode;
 
+	int err;
 
+
 
+	err = hinic3_mutex_lock(&nic_dev->rx_mode_mutex);
 
+	if (err)
 
+		return err;
 
+
 
+	rx_mode = nic_dev->rx_mode | HINIC3_RX_MODE_PROMISC;
 
+
 
+	err = hinic3_set_rx_mode(nic_dev->hwdev, rx_mode);
 
+	if (err) {
 
+		hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
 
+		PMD_DRV_LOG(ERR, "Enable promiscuous failed");
 
+		return err;
 
+	}
 
+
 
+	nic_dev->rx_mode = rx_mode;
 
+
 
+	hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
 
+
 
+	PMD_DRV_LOG(INFO,
 
+		    "Enable promiscuous, nic_dev: %s, port_id: %d, promisc: %d",
 
+		    nic_dev->dev_name, dev->data->port_id,
 
+		    dev->data->promiscuous);
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Disable promiscuous mode.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_promiscuous_disable(struct rte_eth_dev *dev)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u32 rx_mode;
 
+	int err;
 
+
 
+	err = hinic3_mutex_lock(&nic_dev->rx_mode_mutex);
 
+	if (err)
 
+		return err;
 
+
 
+	rx_mode = nic_dev->rx_mode & (~HINIC3_RX_MODE_PROMISC);
 
+
 
+	err = hinic3_set_rx_mode(nic_dev->hwdev, rx_mode);
 
+	if (err) {
 
+		hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
 
+		PMD_DRV_LOG(ERR, "Disable promiscuous failed");
 
+		return err;
 
+	}
 
+
 
+	nic_dev->rx_mode = rx_mode;
 
+
 
+	hinic3_mutex_unlock(&nic_dev->rx_mode_mutex);
 
+
 
+	PMD_DRV_LOG(INFO,
 
+		"Disable promiscuous, nic_dev: %s, port_id: %d, promisc: %d",
 
+		nic_dev->dev_name, dev->data->port_id, dev->data->promiscuous);
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Get flow control configuration, including auto-negotiation and RX/TX pause
 
+ * settings.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ *
 
+ * @param[out] fc_conf
 
+ * The flow control configuration to be filled.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+
 
+/**
 
+ * Update the RSS hash key and RSS hash type.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] rss_conf
 
+ * RSS configuration data.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_rss_hash_update(struct rte_eth_dev *dev,
 
+		       struct rte_eth_rss_conf *rss_conf)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	struct hinic3_rss_type rss_type = {0};
 
+	u64 rss_hf = rss_conf->rss_hf;
 
+	int err = 0;
 
+
 
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE) {
 
+		if (rss_hf != 0)
 
+			return -EINVAL;
 
+
 
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
 
+		return 0;
 
+	}
 
+
 
+	if (rss_conf->rss_key_len > HINIC3_RSS_KEY_SIZE) {
 
+		PMD_DRV_LOG(ERR, "Invalid RSS key, rss_key_len: %d",
 
+			    rss_conf->rss_key_len);
 
+		return -EINVAL;
 
+	}
 
+
 
+	if (rss_conf->rss_key) {
 
+		err = hinic3_rss_set_hash_key(nic_dev->hwdev, nic_dev->rss_key,
 
+					      HINIC3_RSS_KEY_SIZE);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR, "Set RSS hash key failed");
 
+			return err;
 
+		}
 
+		memcpy((void *)nic_dev->rss_key, (void *)rss_conf->rss_key,
 
+		       (size_t)rss_conf->rss_key_len);
 
+	}
 
+
 
+	rss_type.ipv4 = (rss_hf & (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
 
+				   RTE_ETH_RSS_NONFRAG_IPV4_OTHER))
 
+				? 1
 
+				: 0;
 
+	rss_type.tcp_ipv4 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_TCP) ? 1 : 0;
 
+	rss_type.ipv6 = (rss_hf & (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
 
+				   RTE_ETH_RSS_NONFRAG_IPV6_OTHER))
 
+				? 1
 
+				: 0;
 
+	rss_type.ipv6_ext = (rss_hf & RTE_ETH_RSS_IPV6_EX) ? 1 : 0;
 
+	rss_type.tcp_ipv6 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_TCP) ? 1 : 0;
 
+	rss_type.tcp_ipv6_ext = (rss_hf & RTE_ETH_RSS_IPV6_TCP_EX) ? 1 : 0;
 
+	rss_type.udp_ipv4 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV4_UDP) ? 1 : 0;
 
+	rss_type.udp_ipv6 = (rss_hf & RTE_ETH_RSS_NONFRAG_IPV6_UDP) ? 1 : 0;
 
+
 
+	err = hinic3_set_rss_type(nic_dev->hwdev, rss_type);
 
+	if (err)
 
+		PMD_DRV_LOG(ERR, "Set RSS type failed");
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Get the RSS hash configuration.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[out] rss_conf
 
+ * RSS configuration data.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_rss_conf_get(struct rte_eth_dev *dev, struct rte_eth_rss_conf *rss_conf)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	struct hinic3_rss_type rss_type = {0};
 
+	int err;
 
+
 
+	if (!rss_conf)
 
+		return -EINVAL;
 
+
 
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE) {
 
+		rss_conf->rss_hf = 0;
 
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
 
+		return 0;
 
+	}
 
+
 
+	if (rss_conf->rss_key && rss_conf->rss_key_len >= HINIC3_RSS_KEY_SIZE) {
 
+		/*
 
+		 * Get RSS key from driver to reduce the frequency of the MPU
 
+		 * accessing the RSS memory.
 
+		 */
 
+		rss_conf->rss_key_len = sizeof(nic_dev->rss_key);
 
+		memcpy((void *)rss_conf->rss_key, (void *)nic_dev->rss_key,
 
+		       (size_t)rss_conf->rss_key_len);
 
+	}
 
+
 
+	err = hinic3_get_rss_type(nic_dev->hwdev, &rss_type);
 
+	if (err)
 
+		return err;
 
+
 
+	rss_conf->rss_hf = 0;
 
+	rss_conf->rss_hf |=
 
+		rss_type.ipv4 ? (RTE_ETH_RSS_IPV4 | RTE_ETH_RSS_FRAG_IPV4 |
 
+				 RTE_ETH_RSS_NONFRAG_IPV4_OTHER)
 
+			      : 0;
 
+	rss_conf->rss_hf |= rss_type.tcp_ipv4 ? RTE_ETH_RSS_NONFRAG_IPV4_TCP
 
+					      : 0;
 
+	rss_conf->rss_hf |=
 
+		rss_type.ipv6 ? (RTE_ETH_RSS_IPV6 | RTE_ETH_RSS_FRAG_IPV6 |
 
+				 RTE_ETH_RSS_NONFRAG_IPV6_OTHER)
 
+			      : 0;
 
+	rss_conf->rss_hf |= rss_type.ipv6_ext ? RTE_ETH_RSS_IPV6_EX : 0;
 
+	rss_conf->rss_hf |= rss_type.tcp_ipv6 ? RTE_ETH_RSS_NONFRAG_IPV6_TCP
 
+					      : 0;
 
+	rss_conf->rss_hf |= rss_type.tcp_ipv6_ext ? RTE_ETH_RSS_IPV6_TCP_EX : 0;
 
+	rss_conf->rss_hf |= rss_type.udp_ipv4 ? RTE_ETH_RSS_NONFRAG_IPV4_UDP
 
+					      : 0;
 
+	rss_conf->rss_hf |= rss_type.udp_ipv6 ? RTE_ETH_RSS_NONFRAG_IPV6_UDP
 
+					      : 0;
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Get the RETA indirection table.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[out] reta_conf
 
+ * Pointer to RETA configuration structure array.
 
+ * @param[in] reta_size
 
+ * Size of the RETA table.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_rss_reta_query(struct rte_eth_dev *dev,
 
+		      struct rte_eth_rss_reta_entry64 *reta_conf,
 
+		      uint16_t reta_size)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u32 indirtbl[HINIC3_RSS_INDIR_SIZE] = {0};
 
+	u16 idx, shift;
 
+	u16 i;
 
+	int err;
 
+
 
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE) {
 
+		PMD_DRV_LOG(INFO, "RSS is not enabled");
 
+		return 0;
 
+	}
 
+
 
+	if (reta_size != HINIC3_RSS_INDIR_SIZE) {
 
+		PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
 
+		return -EINVAL;
 
+	}
 
+
 
+	err = hinic3_rss_get_indir_tbl(nic_dev->hwdev, indirtbl,
 
+				       HINIC3_RSS_INDIR_SIZE);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Get RSS retas table failed, error: %d", err);
 
+		return err;
 
+	}
 
+
 
+	for (i = 0; i < reta_size; i++) {
 
+		idx = i / RTE_ETH_RETA_GROUP_SIZE;
 
+		shift = i % RTE_ETH_RETA_GROUP_SIZE;
 
+		if (reta_conf[idx].mask & (1ULL << shift))
 
+			reta_conf[idx].reta[shift] = (uint16_t)indirtbl[i];
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
 static int
 
 hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,
 
 		  struct rte_dev_eeprom_info *info)
@@ -2287,6 +2562,68 @@ hinic3_get_eeprom(__rte_unused struct rte_eth_dev *dev,
 
 				  &info->length, MAX_BUF_OUT_LEN);
 
 }
 
 
 
+/**
 
+ * Update the RETA indirection table.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] reta_conf
 
+ * Pointer to RETA configuration structure array.
 
+ * @param[in] reta_size
 
+ * Size of the RETA table.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_rss_reta_update(struct rte_eth_dev *dev,
 
+		       struct rte_eth_rss_reta_entry64 *reta_conf,
 
+		       uint16_t reta_size)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
 
+	u32 indirtbl[HINIC3_RSS_INDIR_SIZE] = {0};
 
+	u16 idx, shift;
 
+	u16 i;
 
+	int err;
 
+
 
+	if (nic_dev->rss_state == HINIC3_RSS_DISABLE)
 
+		return 0;
 
+
 
+	if (reta_size != HINIC3_RSS_INDIR_SIZE) {
 
+		PMD_DRV_LOG(ERR, "Invalid reta size, reta_size: %d", reta_size);
 
+		return -EINVAL;
 
+	}
 
+
 
+	err = hinic3_rss_get_indir_tbl(nic_dev->hwdev, indirtbl,
 
+				       HINIC3_RSS_INDIR_SIZE);
 
+	if (err)
 
+		return err;
 
+
 
+	/* Update RSS reta table. */
 
+	for (i = 0; i < reta_size; i++) {
 
+		idx = i / RTE_ETH_RETA_GROUP_SIZE;
 
+		shift = i % RTE_ETH_RETA_GROUP_SIZE;
 
+		if (reta_conf[idx].mask & (1ULL << shift))
 
+			indirtbl[i] = reta_conf[idx].reta[shift];
 
+	}
 
+
 
+	for (i = 0; i < reta_size; i++) {
 
+		if (indirtbl[i] >= nic_dev->num_rqs) {
 
+			PMD_DRV_LOG(ERR,
 
+				"Invalid reta entry, index: %d, num_rqs: %d",
 
+				indirtbl[i], nic_dev->num_rqs);
 
+			return -EFAULT;
 
+		}
 
+	}
 
+
 
+	err = hinic3_rss_set_indir_tbl(nic_dev->hwdev, indirtbl,
 
+				       HINIC3_RSS_INDIR_SIZE);
 
+	if (err)
 
+		PMD_DRV_LOG(ERR, "Set RSS reta table failed");
 
+
 
+	return err;
 
+}
 
+
 
 /**
 
  * Get device generic statistics.
 
  *
@@ -2857,6 +3194,29 @@ hinic3_set_mc_addr_list(struct rte_eth_dev *dev,
 
 	return 0;
 
 }
 
 
 
+/**
 
+ * Manage flow director filter operations.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] filter_type
 
+ * Filter type.
 
+ * @param[in] filter_op
 
+ * Operation to perform.
 
+ * @param[in] arg
 
+ * Pointer to operation-specific structure.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hinic3_dev_filter_ctrl(struct rte_eth_dev *dev, const struct rte_flow_ops **arg)
 
+{
 
+	RTE_SET_USED(dev);
 
+	*arg = &hinic3_flow_ops;
 
+	return 0;
 
+}
 
+
 
 static int
 
 hinic3_get_reg(__rte_unused struct rte_eth_dev *dev,
 
 	       __rte_unused struct rte_dev_reg_info *regs)
@@ -2890,6 +3250,12 @@ static const struct eth_dev_ops hinic3_pmd_ops = {
 
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
 
+	.promiscuous_enable            = hinic3_dev_promiscuous_enable,
 
+	.promiscuous_disable           = hinic3_dev_promiscuous_disable,
 
+	.rss_hash_update               = hinic3_rss_hash_update,
 
+	.rss_hash_conf_get             = hinic3_rss_conf_get,
 
+	.reta_update                   = hinic3_rss_reta_update,
 
+	.reta_query                    = hinic3_rss_reta_query,
 
 	.get_eeprom                    = hinic3_get_eeprom,
 
 	.stats_get                     = hinic3_dev_stats_get,
 
 	.stats_reset                   = hinic3_dev_stats_reset,
@@ -2931,6 +3297,10 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = {
 
 	.vlan_offload_set              = hinic3_vlan_offload_set,
 
 	.allmulticast_enable           = hinic3_dev_allmulticast_enable,
 
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
 
+	.rss_hash_update               = hinic3_rss_hash_update,
 
+	.rss_hash_conf_get             = hinic3_rss_conf_get,
 
+	.reta_update                   = hinic3_rss_reta_update,
 
+	.reta_query                    = hinic3_rss_reta_query,
 
 	.get_eeprom                    = hinic3_get_eeprom,
 
 	.stats_get                     = hinic3_dev_stats_get,
 
 	.stats_reset                   = hinic3_dev_stats_reset,
drivers/net/hinic3/hinic3_ethdev.h +0 -0

index e0d5b4602c..90ca21491f 100644

--- a/drivers/net/hinic3/hinic3_ethdev.h

+++ b/drivers/net/hinic3/hinic3_ethdev.h

drivers/net/hinic3/hinic3_ethdev.h +25 -0
@@ -97,6 +97,10 @@ struct hinic3_nic_dev {
 
 	u16 rx_buff_len;
 
 	u16 mtu_size;
 
 
 
+	u16 rss_state;
 
+	u8 num_rss; /**< Number of RSS queues. */
 
+	u8 rsvd0;   /**< Reserved field 0. */
 
+
 
 	u32 rx_mode;
 
 	u8 rx_queue_list[HINIC3_MAX_QUEUE_NUM];
 
 	rte_spinlock_t queue_list_lock;
@@ -106,6 +110,8 @@ struct hinic3_nic_dev {
 
 	u32 default_cos;
 
 	u32 rx_csum_en;
 
 
 
+	u8 rss_key[HINIC3_RSS_KEY_SIZE];
 
+
 
 	RTE_ATOMIC(u64) dev_status;
 
 
 
 	struct rte_ether_addr default_addr;
@@ -116,4 +122,29 @@ struct hinic3_nic_dev {
 
 	u32 vfta[HINIC3_VFTA_SIZE]; /**< VLAN bitmap. */
 
 };
 
 
 
+/**
 
+ * Enable interrupt for the specified RX queue.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] queue_id
 
+ * The ID of the receive queue for which the interrupt is being enabled.
 
+ * @return
 
+ * 0 on success, a negative error code on failure.
 
+ */
 
+int hinic3_dev_rx_queue_intr_enable(struct rte_eth_dev *dev, uint16_t queue_id);
 
+
 
+/**
 
+ * Disable interrupt for the specified RX queue.
 
+ *
 
+ * @param[in] dev
 
+ * Pointer to ethernet device structure.
 
+ * @param[in] queue_id
 
+ * The ID of the receive queue for which the interrupt is being disabled.

drivers/net/hinic3/hinic3_ethdev.h struct hinic3_nic_dev {

Quoted 10 lines
drivers/net/hinic3/hinic3_ethdev.h +5 -0
 
+ * @return
 
+ * 0 on success, a negative error code on failure.
 
+ */
 
+int hinic3_dev_rx_queue_intr_disable(struct rte_eth_dev *dev,
 
+				     uint16_t queue_id);

the above two function declation were not related to the subject, please remove them.

Quoted 5 lines

+

#endif /* _HINIC3_ETHDEV_H_ */

#159 lore raw

PATCH v5 17/18 net/hinic3: add FDIR flow control module

In reply to Feifei Wang

From: Yi Chen <[email protected]>

Added support for rte_flow, including ethertype, IPv4, IPv6, and tunnel VXLAN. In addition, user can add or delete filters.

---
 drivers/net/hinic3/hinic3_ethdev.c |   82 ++
 drivers/net/hinic3/hinic3_ethdev.h |   17 +
 drivers/net/hinic3/hinic3_fdir.c   | 1394 +++++++++++++++++++++++
 drivers/net/hinic3/hinic3_fdir.h   |  398 +++++++
 drivers/net/hinic3/hinic3_flow.c   | 1700 ++++++++++++++++++++++++++++
 drivers/net/hinic3/hinic3_flow.h   |   42 +
 6 files changed, 3633 insertions(+)
 create mode 100644 drivers/net/hinic3/hinic3_fdir.c
 create mode 100644 drivers/net/hinic3/hinic3_fdir.h
 create mode 100644 drivers/net/hinic3/hinic3_flow.c
 create mode 100644 drivers/net/hinic3/hinic3_flow.h
drivers/net/hinic3/hinic3_ethdev.c +82 -0
index 0807e017c2..a10ca3c7cb 100644
@@ -2369,6 +2369,84 @@ hinic3_dev_promiscuous_disable(struct rte_eth_dev *dev)
  * @return
  * 0 on success, non-zero on failure.
  */
+static int
+hinic3_dev_flow_ctrl_get(struct rte_eth_dev *dev,
+			 struct rte_eth_fc_conf *fc_conf)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct nic_pause_config nic_pause;
+	int err;
+
+	err = hinic3_mutex_lock(&nic_dev->pause_mutex);
+	if (err)
+		return err;
+
+	memset(&nic_pause, 0, sizeof(nic_pause));
+	err = hinic3_get_pause_info(nic_dev->hwdev, &nic_pause);
+	if (err) {
+		hinic3_mutex_unlock(&nic_dev->pause_mutex);
+		return err;
+	}
+
+	if (nic_dev->pause_set || !nic_pause.auto_neg) {
+		nic_pause.rx_pause = nic_dev->nic_pause.rx_pause;
+		nic_pause.tx_pause = nic_dev->nic_pause.tx_pause;
+	}
+
+	fc_conf->autoneg = nic_pause.auto_neg;
+
+	if (nic_pause.tx_pause && nic_pause.rx_pause)
+		fc_conf->mode = RTE_ETH_FC_FULL;
+	else if (nic_pause.tx_pause)
+		fc_conf->mode = RTE_ETH_FC_TX_PAUSE;
+	else if (nic_pause.rx_pause)
+		fc_conf->mode = RTE_ETH_FC_RX_PAUSE;
+	else
+		fc_conf->mode = RTE_ETH_FC_NONE;
+
+	hinic3_mutex_unlock(&nic_dev->pause_mutex);
+	return 0;
+}
+
+static int
+hinic3_dev_flow_ctrl_set(struct rte_eth_dev *dev,
+			 struct rte_eth_fc_conf *fc_conf)
+{
+	struct hinic3_nic_dev *nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV(dev);
+	struct nic_pause_config nic_pause;
+	int err;
+
+	err = hinic3_mutex_lock(&nic_dev->pause_mutex);
+	if (err)
+		return err;
+
+	memset(&nic_pause, 0, sizeof(nic_pause));
+	if ((fc_conf->mode & RTE_ETH_FC_FULL) == RTE_ETH_FC_FULL ||
+	    (fc_conf->mode & RTE_ETH_FC_TX_PAUSE))
+		nic_pause.tx_pause = true;
+
+	if ((fc_conf->mode & RTE_ETH_FC_FULL) == RTE_ETH_FC_FULL ||
+	    (fc_conf->mode & RTE_ETH_FC_RX_PAUSE))
+		nic_pause.rx_pause = true;
+
+	err = hinic3_set_pause_info(nic_dev->hwdev, nic_pause);
+	if (err) {
+		hinic3_mutex_unlock(&nic_dev->pause_mutex);
+		return err;
+	}
+
+	nic_dev->pause_set = true;
+	nic_dev->nic_pause.rx_pause = nic_pause.rx_pause;
+	nic_dev->nic_pause.tx_pause = nic_pause.tx_pause;
+
+	PMD_DRV_LOG(INFO,
+		    "Just support set tx or rx pause info, tx: %s, rx: %s",
+		    nic_pause.tx_pause ? "on" : "off",
+		    nic_pause.rx_pause ? "on" : "off");
+
+	hinic3_mutex_unlock(&nic_dev->pause_mutex);
+	return 0;
+}
 
 /**
  * Update the RSS hash key and RSS hash type.
@@ -3252,6 +3330,8 @@ static const struct eth_dev_ops hinic3_pmd_ops = {
 	.allmulticast_disable          = hinic3_dev_allmulticast_disable,
 	.promiscuous_enable            = hinic3_dev_promiscuous_enable,
 	.promiscuous_disable           = hinic3_dev_promiscuous_disable,
+	.flow_ctrl_get                 = hinic3_dev_flow_ctrl_get,
+	.flow_ctrl_set                 = hinic3_dev_flow_ctrl_set,
 	.rss_hash_update               = hinic3_rss_hash_update,
 	.rss_hash_conf_get             = hinic3_rss_conf_get,
 	.reta_update                   = hinic3_rss_reta_update,
@@ -3269,6 +3349,7 @@ static const struct eth_dev_ops hinic3_pmd_ops = {
 	.mac_addr_remove               = hinic3_mac_addr_remove,
 	.mac_addr_add                  = hinic3_mac_addr_add,
 	.set_mc_addr_list              = hinic3_set_mc_addr_list,
+	.flow_ops_get                  = hinic3_dev_filter_ctrl,
 	.get_reg                       = hinic3_get_reg,
 };
 
@@ -3313,6 +3394,7 @@ static const struct eth_dev_ops hinic3_pmd_vf_ops = {
 	.mac_addr_remove               = hinic3_mac_addr_remove,
 	.mac_addr_add                  = hinic3_mac_addr_add,
 	.set_mc_addr_list              = hinic3_set_mc_addr_list,
+	.flow_ops_get                  = hinic3_dev_filter_ctrl,
 };
 
 /**
drivers/net/hinic3/hinic3_ethdev.h +17 -0
index 90ca21491f..f71183d722 100644
@@ -8,6 +8,8 @@
 #include <rte_ethdev.h>
 #include <rte_ethdev_core.h>
 
+#include "hinic3_fdir.h"
+
 #define HINIC3_PMD_DRV_VERSION "B106"
 
 #define PCI_DEV_TO_INTR_HANDLE(pci_dev) ((pci_dev)->intr_handle)
@@ -83,6 +85,9 @@ enum nic_feature_cap {
 
 #define DEFAULT_DRV_FEATURE 0x3FFF
 
+TAILQ_HEAD(hinic3_ethertype_filter_list, rte_flow);
+TAILQ_HEAD(hinic3_fdir_rule_filter_list, rte_flow);
+
 struct hinic3_nic_dev {
 	struct hinic3_hwdev *hwdev; /**< Hardware device. */
 	struct hinic3_txq **txqs;
@@ -114,14 +119,26 @@ struct hinic3_nic_dev {
 
 	RTE_ATOMIC(u64) dev_status;
 
+	u8 pause_set; /**< Flag of PAUSE frame setting. */
+	pthread_mutex_t pause_mutex;
+	struct nic_pause_config nic_pause;
+
 	struct rte_ether_addr default_addr;
 	struct rte_ether_addr *mc_list;
 
 	char dev_name[HINIC3_DEV_NAME_LEN];
 	u64 feature_cap;
 	u32 vfta[HINIC3_VFTA_SIZE]; /**< VLAN bitmap. */
+
+	u16 tcam_rule_nums;
+	u16 ethertype_rule_nums;
+	struct hinic3_tcam_info tcam;
+	struct hinic3_ethertype_filter_list filter_ethertype_list;
+	struct hinic3_fdir_rule_filter_list filter_fdir_rule_list;
 };
 
+extern const struct rte_flow_ops hinic3_flow_ops;
+
 /**
  * Enable interrupt for the specified RX queue.
  *
drivers/net/hinic3/hinic3_fdir.c new file +1394 -0

1,394 lines not on this page · raw message

drivers/net/hinic3/hinic3_fdir.h new file +398 -0

398 lines not on this page · raw message

drivers/net/hinic3/hinic3_flow.c new file +1700 -0

1,059 lines not on this page · raw message

drivers/net/hinic3/hinic3_flow.h new file +42 -0

42 lines not on this page · raw message

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.45.1.windows.1

Part of the diff is not shown here. View the raw message.