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 5 of 16

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

PATCH v4 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.

#119 lore raw

PATCH v4 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
#120 lore raw

PATCH v4 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
#121 lore raw

PATCH v4 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
#122 lore raw

PATCH v4 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.

#123 lore raw

PATCH v4 18/18 drivers/net: add hinic3 PMD build and doc files

In reply to Feifei Wang

From: Yi Chen <[email protected]>

The meson.build file is added to this patch to enable the hinic3 compilation function.

---
 doc/guides/nics/features/hinic3.ini | 62 +++++++++++++++++++++++++++++
 drivers/net/hinic3/base/meson.build | 50 +++++++++++++++++++++++
 drivers/net/hinic3/meson.build      | 33 +++++++++++++++
 drivers/net/hinic3/mml/meson.build  | 33 ++++-----------
 drivers/net/meson.build             |  1 +
 5 files changed, 154 insertions(+), 25 deletions(-)
 create mode 100644 doc/guides/nics/features/hinic3.ini
 create mode 100644 drivers/net/hinic3/base/meson.build
 create mode 100644 drivers/net/hinic3/meson.build
doc/guides/nics/features/hinic3.ini new file +62 -0
new file mode 100644
index 0000000000..a30236fe09
@@ -0,0 +1,62 @@
+;
+; Supported features of the 'hinic3' network poll mode driver.
+;
+; Refer to default.ini for the full list of available PMD features.
+;
+[Features]
+Speed capabilities   = Y
+Link speed configuration = Y
+Link status          = Y
+Link status event    = Y ?
+Rx interrupt         = Y
+Queue start/stop     = Y
+Runtime Rx queue setup = Y
+Runtime Tx queue setup = Y
+Burst mode info      = Y
+Fast mbuf free       = Y
+Free Tx mbuf on demand = Y
+MTU update           = Y
+Scattered Rx         = Y
+TSO                  = Y
+LRO                  = Y
+Promiscuous mode     = Y
+Allmulticast mode    = Y
+Unicast MAC filter   = Y
+Multicast MAC filter = Y
+RSS hash             = Y
+RSS key update       = Y
+RSS reta update      = Y
+RSS reta query       = Y
+VLAN filter          = Y
+Flow control         = Y
+Traffic manager      = Y
+CRC offload          = Y
+FEC                  = Y
+L3 checksum offload  = Y
+L4 checksum offload  = Y
+Inner L3 checksum    = Y
+Inner L4 checksum    = Y
+Packet type parsing  = Y
+Basic stats          = Y
+Extended stats       = Y
+Stats per queue      = Y
+FW version           = Y
+Registers dump       = Y
+Module EEPROM dump   = Y
+Timesync             = Y
+Multiprocess aware   = Y
+Linux                = Y
+x86-64               = Y
+ARMv8                = Y
+
+[rte_flow items]
+any                  = Y
+eth                  = Y
+icmp                 = Y
+ipv4                 = Y
+ipv6                 = Y
+tcp                  = Y
+udp                  = Y
+vxlan                = Y
+[rte_flow actions]
+queue                = Y
drivers/net/hinic3/base/meson.build new file +50 -0

50 lines not on this page · raw message

drivers/net/hinic3/meson.build new file +33 -0
new file mode 100644
index 0000000000..42fb5bc194
@@ -0,0 +1,33 @@
+# SPDX-License-Identifier: BSD-3-Clause
+# Copyright(c) 2025 Huawei Technologies Co., Ltd
+
+if not is_linux
+    build = false
+    reason = 'only supported on Linux'
+    subdir_done()
+endif
+
+if (arch_subdir != 'x86' and arch_subdir != 'arm'
+        or not dpdk_conf.get('RTE_ARCH_64'))
+    build = false
+    reason = 'only supported on x86_64 and aarch64'
+    subdir_done()
+endif
+
+cflags += ['-DHW_CONVERT_ENDIAN']
+
+subdir('base')
+subdir('mml')
+objs = [base_objs] + [mml_objs]
+
+sources = files(
+        'hinic3_ethdev.c',
+        'hinic3_fdir.c',
+        'hinic3_flow.c',
+        'hinic3_nic_io.c',
+        'hinic3_rx.c',
+        'hinic3_tx.c',
+)
+
+includes += include_directories('base')
+includes += include_directories('mml')
drivers/net/hinic3/mml/meson.build +8 -25
index f8d2650d8d..67bba4f067 100644
@@ -2,36 +2,19 @@
 # Copyright(c) 2025 Huawei Technologies Co., Ltd
 
 sources = files(
-    'hinic3_dbg.c',
-    'hinic3_mml_cmd.c',
-    'hinic3_mml_ioctl.c',
-    'hinic3_mml_lib.c',
-    'hinic3_mml_main.c',
-    'hinic3_mml_queue.c',
+        'hinic3_dbg.c',
+        'hinic3_mml_cmd.c',
+        'hinic3_mml_ioctl.c',
+        'hinic3_mml_lib.c',
+        'hinic3_mml_main.c',
+        'hinic3_mml_queue.c',
 )
 
-extra_flags = [
-    '-Wno-cast-qual',
-    '-Wno-format',
-    '-Wno-format-nonliteral',
-    '-Wno-format-security',
-    '-Wno-missing-braces',
-    '-Wno-missing-field-initializers',
-    '-Wno-missing-prototypes',
-    '-Wno-pointer-sign',
-    '-Wno-pointer-to-int-cast',
-    '-Wno-sign-compare',
-    '-Wno-strict-aliasing',
-    '-Wno-unused-parameter',
-    '-Wno-unused-value',
-    '-Wno-unused-variable',
-]
-
 # The driver runs only on arch64 machine, remove 32bit warnings
 if not dpdk_conf.get('RTE_ARCH_64')
     extra_flags += [
-        '-Wno-int-to-pointer-cast',
-        '-Wno-pointer-to-int-cast',
+            '-Wno-int-to-pointer-cast',
+            '-Wno-pointer-to-int-cast',
     ]
 endif
 
drivers/net/meson.build +1 -0
index 61f8cddb30..2d32068ed2 100644
@@ -23,6 +23,7 @@ drivers = [
         'failsafe',
         'gve',
         'hinic',
+        'hinic3',
         'hns3',
         'intel/e1000',
         'intel/fm10k',
Signature · 1 line
2.45.1.windows.1
#124 lore raw

Re: [V4 00/18] add hinic3 pmd driver

In reply to Feifei Wang
Quoted 149 lines · On Tue, 1 Jul 2025 09:41:51 +0800 Feifei Wang <[email protected]> wrote:

From: Yi Chen <[email protected]>

The hinic3 PMD (**librte_net_hinic3**) provides poll mode driver support for 25Gbps/100Gbps/200Gbps Huawei SPx series Network Adapters.

V4:
- solve patch application conflict issue

V3:
- Fix checkpatchs error issue

v2:
- modify CI compile errors

V1:
- modify community comments and compile issues
- remove the compilation flags in the meson build
- remove (void) cast
- remove "BLURE HERE ***" in cover letter

RFC:
- add hinic3 pmd driver code, modify the driver code to adapt to Huawei SPx series network cards.

Feifei Wang (2):
net/hinic3: add dev ops
net/hinic3: add Rx/Tx functions

Xin Wang (7):
net/hinic3: add basic header files
net/hinic3: add support for cmdq mechanism
net/hinic3: add NIC event module
net/hinic3: add context and work queue support
net/hinic3: add device initialization
net/hinic3: add MML and EEPROM access feature
net/hinic3: add RSS promiscuous ops

Yi Chen (9):
add some basic files to describe the hinic3 driver. net/hinic3: add hardware interfaces of BAR operation net/hinic3: add eq mechanism function code net/hinic3: add mgmt module function code net/hinic3: add module about hardware operation net/hinic3: add a NIC business configuration module net/hinic3: add a mailbox communication module net/hinic3: add FDIR flow control module drivers/net: add hinic3 PMD build and doc files

 .mailmap                                   |    4 +-
 MAINTAINERS                                |    6 +
 doc/guides/nics/features/hinic3.ini        |   62 +
 doc/guides/nics/hinic3.rst                 |   51 +
 doc/guides/nics/index.rst                  |    1 +
 doc/guides/rel_notes/release_25_07.rst     |    4 +
 drivers/net/hinic3/base/hinic3_cmd.h       |  231 ++
 drivers/net/hinic3/base/hinic3_cmdq.c      |  978 +++++
 drivers/net/hinic3/base/hinic3_cmdq.h      |  230 ++
 drivers/net/hinic3/base/hinic3_compat.h    |  266 ++
 drivers/net/hinic3/base/hinic3_csr.h       |  108 +
 drivers/net/hinic3/base/hinic3_eqs.c       |  721 ++++
 drivers/net/hinic3/base/hinic3_eqs.h       |   98 +
 drivers/net/hinic3/base/hinic3_hw_cfg.c    |  240 ++
 drivers/net/hinic3/base/hinic3_hw_cfg.h    |  121 +
 drivers/net/hinic3/base/hinic3_hw_comm.c   |  452 +++
 drivers/net/hinic3/base/hinic3_hw_comm.h   |  366 ++
 drivers/net/hinic3/base/hinic3_hwdev.c     |  573 +++
 drivers/net/hinic3/base/hinic3_hwdev.h     |  177 +
 drivers/net/hinic3/base/hinic3_hwif.c      |  779 ++++
 drivers/net/hinic3/base/hinic3_hwif.h      |  142 +
 drivers/net/hinic3/base/hinic3_mbox.c      | 1399 +++++++
 drivers/net/hinic3/base/hinic3_mbox.h      |  199 +
 drivers/net/hinic3/base/hinic3_mgmt.c      |  392 ++
 drivers/net/hinic3/base/hinic3_mgmt.h      |  121 +
 drivers/net/hinic3/base/hinic3_nic_cfg.c   | 1828 +++++++++
 drivers/net/hinic3/base/hinic3_nic_cfg.h   | 1527 ++++++++
 drivers/net/hinic3/base/hinic3_nic_event.c |  433 +++
 drivers/net/hinic3/base/hinic3_nic_event.h |   39 +
 drivers/net/hinic3/base/hinic3_wq.c        |  148 +
 drivers/net/hinic3/base/hinic3_wq.h        |  109 +
 drivers/net/hinic3/base/meson.build        |   50 +
 drivers/net/hinic3/hinic3_ethdev.c         | 3866 ++++++++++++++++++++
 drivers/net/hinic3/hinic3_ethdev.h         |  167 +
 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 +
 drivers/net/hinic3/hinic3_nic_io.c         |  828 +++++
 drivers/net/hinic3/hinic3_nic_io.h         |  169 +
 drivers/net/hinic3/hinic3_rx.c             | 1099 ++++++
 drivers/net/hinic3/hinic3_rx.h             |  356 ++
 drivers/net/hinic3/hinic3_tx.c             | 1028 ++++++
 drivers/net/hinic3/hinic3_tx.h             |  315 ++
 drivers/net/hinic3/meson.build             |   33 +
 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         |   45 +
 drivers/net/meson.build                    |    1 +
 57 files changed, 25927 insertions(+), 1 deletion(-)
 create mode 100644 doc/guides/nics/features/hinic3.ini
 create mode 100644 doc/guides/nics/hinic3.rst
 create mode 100644 drivers/net/hinic3/base/hinic3_cmd.h
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.c
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.h
 create mode 100644 drivers/net/hinic3/base/hinic3_compat.h
 create mode 100644 drivers/net/hinic3/base/hinic3_csr.h
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.c
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.h
 create mode 100644 drivers/net/hinic3/base/hinic3_mbox.c
 create mode 100644 drivers/net/hinic3/base/hinic3_mbox.h
 create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.c
 create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.h
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.c
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.h
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.c
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.h
 create mode 100644 drivers/net/hinic3/base/hinic3_wq.c
 create mode 100644 drivers/net/hinic3/base/hinic3_wq.h
 create mode 100644 drivers/net/hinic3/base/meson.build
 create mode 100644 drivers/net/hinic3/hinic3_ethdev.c
 create mode 100644 drivers/net/hinic3/hinic3_ethdev.h
 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
 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
 create mode 100644 drivers/net/hinic3/meson.build
 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
Quoted 9 lines
 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

Looks good, but too close to 25.07 release date for this release. Review deferred to the start of 25.11 cycle.

#125 lore raw

v5 cover add hinic3 pmd driver

In reply to Feifei Wang

From: Yi Chen <[email protected]>

The hinic3 PMD (**librte_net_hinic3**) provides poll mode driver support for 25Gbps/100Gbps/200Gbps Huawei SPx series Network Adapters.

v5:
- solve hinic3.ini unknown feature issue

V4:
- solve patch application conflict issue

V3:
- Fix checkpatchs error issue

v2:
- modify CI compile errors

V1:
- modify community comments and compile issues
- remove the compilation flags in the meson build
- remove (void) cast
- remove "BLURE HERE ***" in cover letter

RFC:
- add hinic3 pmd driver code, modify the driver code to adapt to Huawei SPx series network cards.

Feifei Wang (2):
net/hinic3: add dev ops
net/hinic3: add Rx/Tx functions

Xin Wang (7):
net/hinic3: add basic header files
net/hinic3: add support for cmdq mechanism
net/hinic3: add NIC event module
net/hinic3: add context and work queue support
net/hinic3: add device initialization
net/hinic3: add MML and EEPROM access feature
net/hinic3: add RSS promiscuous ops

Yi Chen (9):
add some basic files to describe the hinic3 driver. net/hinic3: add hardware interfaces of BAR operation net/hinic3: add eq mechanism function code net/hinic3: add mgmt module function code net/hinic3: add module about hardware operation net/hinic3: add a NIC business configuration module net/hinic3: add a mailbox communication module net/hinic3: add FDIR flow control module drivers/net: add hinic3 PMD build and doc files

 .mailmap                                   |    4 +-
 MAINTAINERS                                |    6 +
 doc/guides/nics/features/hinic3.ini        |   61 +
 doc/guides/nics/hinic3.rst                 |   51 +
 doc/guides/nics/index.rst                  |    1 +
 doc/guides/rel_notes/release_25_07.rst     |    4 +
 drivers/net/hinic3/base/hinic3_cmd.h       |  231 ++
 drivers/net/hinic3/base/hinic3_cmdq.c      |  978 +++++
 drivers/net/hinic3/base/hinic3_cmdq.h      |  230 ++
 drivers/net/hinic3/base/hinic3_compat.h    |  266 ++
 drivers/net/hinic3/base/hinic3_csr.h       |  108 +
 drivers/net/hinic3/base/hinic3_eqs.c       |  721 ++++
 drivers/net/hinic3/base/hinic3_eqs.h       |   98 +
 drivers/net/hinic3/base/hinic3_hw_cfg.c    |  240 ++
 drivers/net/hinic3/base/hinic3_hw_cfg.h    |  121 +
 drivers/net/hinic3/base/hinic3_hw_comm.c   |  452 +++
 drivers/net/hinic3/base/hinic3_hw_comm.h   |  366 ++
 drivers/net/hinic3/base/hinic3_hwdev.c     |  573 +++
 drivers/net/hinic3/base/hinic3_hwdev.h     |  177 +
 drivers/net/hinic3/base/hinic3_hwif.c      |  779 ++++
 drivers/net/hinic3/base/hinic3_hwif.h      |  142 +
 drivers/net/hinic3/base/hinic3_mbox.c      | 1399 +++++++
 drivers/net/hinic3/base/hinic3_mbox.h      |  199 +
 drivers/net/hinic3/base/hinic3_mgmt.c      |  392 ++
 drivers/net/hinic3/base/hinic3_mgmt.h      |  121 +
 drivers/net/hinic3/base/hinic3_nic_cfg.c   | 1828 +++++++++
 drivers/net/hinic3/base/hinic3_nic_cfg.h   | 1527 ++++++++
 drivers/net/hinic3/base/hinic3_nic_event.c |  433 +++
 drivers/net/hinic3/base/hinic3_nic_event.h |   39 +
 drivers/net/hinic3/base/hinic3_wq.c        |  148 +
 drivers/net/hinic3/base/hinic3_wq.h        |  109 +
 drivers/net/hinic3/base/meson.build        |   50 +
 drivers/net/hinic3/hinic3_ethdev.c         | 3866 ++++++++++++++++++++
 drivers/net/hinic3/hinic3_ethdev.h         |  167 +
 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 +
 drivers/net/hinic3/hinic3_nic_io.c         |  828 +++++
 drivers/net/hinic3/hinic3_nic_io.h         |  169 +
 drivers/net/hinic3/hinic3_rx.c             | 1099 ++++++
 drivers/net/hinic3/hinic3_rx.h             |  356 ++
 drivers/net/hinic3/hinic3_tx.c             | 1028 ++++++
 drivers/net/hinic3/hinic3_tx.h             |  315 ++
 drivers/net/hinic3/meson.build             |   33 +
 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         |   45 +
 drivers/net/meson.build                    |    1 +
 57 files changed, 25926 insertions(+), 1 deletion(-)
 create mode 100644 doc/guides/nics/features/hinic3.ini
 create mode 100644 doc/guides/nics/hinic3.rst
 create mode 100644 drivers/net/hinic3/base/hinic3_cmd.h
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.c
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.h
 create mode 100644 drivers/net/hinic3/base/hinic3_compat.h
 create mode 100644 drivers/net/hinic3/base/hinic3_csr.h
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.c
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.h
 create mode 100644 drivers/net/hinic3/base/hinic3_mbox.c
 create mode 100644 drivers/net/hinic3/base/hinic3_mbox.h
 create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.c
 create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.h
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.c
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_cfg.h
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.c
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.h
 create mode 100644 drivers/net/hinic3/base/hinic3_wq.c
 create mode 100644 drivers/net/hinic3/base/hinic3_wq.h
 create mode 100644 drivers/net/hinic3/base/meson.build
 create mode 100644 drivers/net/hinic3/hinic3_ethdev.c
 create mode 100644 drivers/net/hinic3/hinic3_ethdev.h
 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
 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
 create mode 100644 drivers/net/hinic3/meson.build
 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
Signature · 1 line
2.45.1.windows.1
#126 lore raw

PATCH v5 1/18 doc: add some basic files to describe the hinic3 driver.

From: Yi Chen <[email protected]>

This patch adds some basic files to describe the hinic3 driver.

---
 .mailmap                               |  4 +-
 MAINTAINERS                            |  6 +++
 doc/guides/nics/hinic3.rst             | 51 ++++++++++++++++++++++++++
 doc/guides/nics/index.rst              |  1 +
 doc/guides/rel_notes/release_25_07.rst |  4 ++
 5 files changed, 65 insertions(+), 1 deletion(-)
 create mode 100644 doc/guides/nics/hinic3.rst
.mailmap +3 -1
index 8e898e303e..ecd7fe5805 100644
@@ -434,7 +434,7 @@ Fang TongHao <[email protected]>
 Fan Zhang <[email protected]> <[email protected]>
 Farah Smith <[email protected]>
 Fei Chen <[email protected]>
-Feifei Wang <[email protected]> <[email protected]>
+Feifei Wang <[email protected]> <[email protected]> <[email protected]> <[email protected]> <[email protected]>
 Fei Qin <[email protected]>
 Fengjiang Liu <[email protected]>
 Fengnan Chang <[email protected]>
@@ -1735,6 +1735,7 @@ Xingguang He <[email protected]>
 Xingyou Chen <[email protected]>
 Xing Wang <[email protected]>
 Xinying Yu <[email protected]>
+Xin Wang <[email protected]>
 Xin Long <[email protected]>
 Xi Zhang <[email protected]>
 Xuan Ding <[email protected]>
@@ -1769,6 +1770,7 @@ Yelena Krivosheev <[email protected]>
 Yerden Zhumabekov <[email protected]> <[email protected]>
 Yevgeny Kliteynik <[email protected]>
 Yicai Lu <[email protected]>
+Yi Chen <[email protected]>
 Yiding Zhou <[email protected]>
 Yi Li <[email protected]>
 Yi Liu <[email protected]>
MAINTAINERS +6 -0
index 0e9357f3a3..eeb735679e 100644
@@ -780,6 +780,12 @@ F: drivers/net/hinic/
 F: doc/guides/nics/hinic.rst
 F: doc/guides/nics/features/hinic.ini
 
+Huawei hinic3
+M: Feifei Wang <[email protected]>
+F: drivers/net/hinic3/
+F: doc/guides/nics/hinic3.rst
+F: doc/guides/nics/features/hinic3.ini
+
 Intel Network Common Code
 M: Bruce Richardson <[email protected]>
 T: git://dpdk.org/next/dpdk-next-net-intel
doc/guides/nics/hinic3.rst new file +51 -0

51 lines not on this page · raw message

doc/guides/nics/index.rst +1 -0
index 57d161c526..1a1e3a6825 100644
@@ -33,6 +33,7 @@ Network Interface Controller Drivers
     fm10k
     gve
     hinic
+    hinic3
     hns3
     i40e
     ice
doc/guides/rel_notes/release_25_07.rst +4 -0
index b75405edf6..0821ca8b63 100644
@@ -160,6 +160,10 @@ New Features
   (including out-of-tree nodes).
   This minimizes footprint of node specific mbuf dynamic field.
 
+* **Added Huawei hinic3 net driver.**
+
+  * Added network driver for the Huawei SPx series Network Adapters.
+
 
 Removed Items
 -------------
Signature · 1 line
2.45.1.windows.1
#127 lore raw

Re: [V5 01/18] doc: add some basic files to describe the hinic3 driver.

Quoted 4 lines · Feifei Wang

From: Yi Chen <[email protected]>

This patch adds some basic files to describe the hinic3 driver.

The subject suggest: doc: add hinic3 driver

Commit log: This patch adds document for hinic3 driver.

Quoted 10 lines

---

...

MAINTAINERS F: drivers/net/hinic/ · line 785

Quoted 7 lines
MAINTAINERS +3 -0
+Huawei hinic3
 
+M: Feifei Wang <[email protected]>
 
+F: drivers/net/hinic3/

There are no drivers/hinic3/ files included in this commit.

MAINTAINERS F: drivers/net/hinic/ · line 787

Quoted 4 lines
MAINTAINERS +2 -0
+F: doc/guides/nics/hinic3.rst
 
+F: doc/guides/nics/features/hinic3.ini

The hinic3.ini was also not included in this commit.

Quoted 20 lines
MAINTAINERS +1 -0
+
 
 Intel Network Common Code
 
 M: Bruce Richardson <[email protected]>
 
 T: git://dpdk.org/next/dpdk-next-net-intel
doc/guides/nics/hinic3.rst +0 -0

new file mode 100644

index 0000000000..c9e49a2be2

--- /dev/null

+++ b/doc/guides/nics/hinic3.rst

doc/guides/nics/hinic3.rst line 4

Quoted 8 lines
doc/guides/nics/hinic3.rst +4 -0
@@ -0,0 +1,51 @@
 
+..  SPDX-License-Identifier: BSD-3-Clause
 
+    Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+
 
+HINIC Poll Mode Driver

HINIC -> HINIC3

#128 lore raw

PATCH v5 2/18 net/hinic3: add basic header files

In reply to Feifei Wang

From: Xin Wang <[email protected]>

Add HW registers definition header file for SP series NIC. Add some headers that define commands and basic defines for use in the code.

---
 drivers/net/hinic3/base/hinic3_cmd.h    | 231 ++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_compat.h | 266 ++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_csr.h    | 108 ++++++++++
 3 files changed, 605 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_cmd.h
 create mode 100644 drivers/net/hinic3/base/hinic3_compat.h
 create mode 100644 drivers/net/hinic3/base/hinic3_csr.h
drivers/net/hinic3/base/hinic3_cmd.h new file +231 -0
new file mode 100644
index 0000000000..f0e200a944
@@ -0,0 +1,231 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#ifndef _HINIC3_CMD_H_
+#define _HINIC3_CMD_H_
+
+#define NIC_RSS_TEMP_ID_TO_CTX_LT_IDX(tmp_id)	tmp_id
+/* Begin of one temp tbl. */
+#define NIC_RSS_TEMP_ID_TO_INDIR_LT_IDX(tmp_id)	((tmp_id) << 4)
+/* 4 ctx in one entry. */
+#define NIC_RSS_CTX_TBL_ENTRY_SIZE		0x10
+/* Entry size = 16B, 16 entry/template. */
+#define NIC_RSS_INDIR_TBL_ENTRY_SIZE		0x10
+/* Entry size = 16B, so entry_num = 256B/16B. */
+#define NIC_RSS_INDIR_TBL_ENTRY_NUM		0x10
+
+#define NIC_UP_RSS_INVALID_TEMP_ID		0xFF
+#define NIC_UP_RSS_INVALID_FUNC_ID		0xFFFF
+#define NIC_UP_RSS_INVALID			0x00
+#define NIC_UP_RSS_EN				0x01
+#define NIC_UP_RSS_INVALID_GROUP_ID		0x7F
+
+#define NIC_RSS_CMD_TEMP_ALLOC			0x01
+#define NIC_RSS_CMD_TEMP_FREE			0x02
+
+#define HINIC3_RSS_TYPE_VALID_SHIFT		23
+#define HINIC3_RSS_TYPE_TCP_IPV6_EXT_SHIFT	24
+#define HINIC3_RSS_TYPE_IPV6_EXT_SHIFT		25
+#define HINIC3_RSS_TYPE_TCP_IPV6_SHIFT		26
+#define HINIC3_RSS_TYPE_IPV6_SHIFT		27
+#define HINIC3_RSS_TYPE_TCP_IPV4_SHIFT		28
+#define HINIC3_RSS_TYPE_IPV4_SHIFT		29
+#define HINIC3_RSS_TYPE_UDP_IPV6_SHIFT		30
+#define HINIC3_RSS_TYPE_UDP_IPV4_SHIFT		31
+#define HINIC3_RSS_TYPE_SET(val, member)	\
+	(((u32)(val) & 0x1) << HINIC3_RSS_TYPE_##member##_SHIFT)
+
+#define HINIC3_RSS_TYPE_GET(val, member)	\
+	(((u32)(val) >> HINIC3_RSS_TYPE_##member##_SHIFT) & 0x1)
+
+/* NIC CMDQ MODE. */
+typedef enum hinic3_ucode_cmd {
+	HINIC3_UCODE_CMD_MODIFY_QUEUE_CTX = 0,
+	HINIC3_UCODE_CMD_CLEAN_QUEUE_CONTEXT,
+	HINIC3_UCODE_CMD_ARM_SQ,
+	HINIC3_UCODE_CMD_ARM_RQ,
+	HINIC3_UCODE_CMD_SET_RSS_INDIR_TABLE,
+	HINIC3_UCODE_CMD_SET_RSS_CONTEXT_TABLE,
+	HINIC3_UCODE_CMD_GET_RSS_INDIR_TABLE,
+	HINIC3_UCODE_CMD_GET_RSS_CONTEXT_TABLE,
+	HINIC3_UCODE_CMD_SET_IQ_ENABLE,
+	HINIC3_UCODE_CMD_SET_RQ_FLUSH = 10,
+	HINIC3_UCODE_CMD_MODIFY_VLAN_CTX,
+} cmdq_nic_subtype_e;
+
+/* Commands between NIC to MPU. */
+enum hinic3_nic_cmd {
+	/* Only for PFD and VFD. */
+	HINIC3_NIC_CMD_VF_REGISTER = 0,
+
+	/* FUNC CFG */
+	HINIC3_NIC_CMD_SET_FUNC_TBL = 5,
+	HINIC3_NIC_CMD_SET_VPORT_ENABLE,
+	HINIC3_NIC_CMD_SET_RX_MODE,
+	HINIC3_NIC_CMD_SQ_CI_ATTR_SET,
+	HINIC3_NIC_CMD_GET_VPORT_STAT,
+	HINIC3_NIC_CMD_CLEAN_VPORT_STAT,
+	HINIC3_NIC_CMD_CLEAR_QP_RESOURCE,
+	HINIC3_NIC_CMD_CFG_FLEX_QUEUE,
+	/* LRO CFG */
+	HINIC3_NIC_CMD_CFG_RX_LRO,
+	HINIC3_NIC_CMD_CFG_LRO_TIMER,
+	HINIC3_NIC_CMD_FEATURE_NEGO,
+
+	/* MAC & VLAN CFG */
+	HINIC3_NIC_CMD_GET_MAC = 20,
+	HINIC3_NIC_CMD_SET_MAC,
+	HINIC3_NIC_CMD_DEL_MAC,
+	HINIC3_NIC_CMD_UPDATE_MAC,
+	HINIC3_NIC_CMD_GET_ALL_DEFAULT_MAC,
+
+	HINIC3_NIC_CMD_CFG_FUNC_VLAN,
+	HINIC3_NIC_CMD_SET_VLAN_FILTER_EN,
+	HINIC3_NIC_CMD_SET_RX_VLAN_OFFLOAD,
+
+	/* SR-IOV */
+	HINIC3_NIC_CMD_CFG_VF_VLAN = 40,
+	HINIC3_NIC_CMD_SET_SPOOPCHK_STATE,
+	/* RATE LIMIT */
+	HINIC3_NIC_CMD_SET_MAX_MIN_RATE,
+
+	/* RSS CFG */
+	HINIC3_NIC_CMD_RSS_CFG = 60,
+	HINIC3_NIC_CMD_RSS_TEMP_MGR,
+	HINIC3_NIC_CMD_GET_RSS_CTX_TBL,
+	HINIC3_NIC_CMD_CFG_RSS_HASH_KEY,
+	HINIC3_NIC_CMD_CFG_RSS_HASH_ENGINE,
+	HINIC3_NIC_CMD_SET_RSS_CTX_TBL_INTO_FUNC,
+
+	/* FDIR */
+	HINIC3_NIC_CMD_ADD_TC_FLOW = 80,
+	HINIC3_NIC_CMD_DEL_TC_FLOW,
+	HINIC3_NIC_CMD_GET_TC_FLOW,
+	HINIC3_NIC_CMD_FLUSH_TCAM,
+	HINIC3_NIC_CMD_CFG_TCAM_BLOCK,
+	HINIC3_NIC_CMD_ENABLE_TCAM,
+	HINIC3_NIC_CMD_GET_TCAM_BLOCK,
+
+	HINIC3_NIC_CMD_SET_FDIR_STATUS = 91,
+
+	/* PORT CFG */
+	HINIC3_NIC_CMD_SET_PORT_ENABLE = 100,
+	HINIC3_NIC_CMD_CFG_PAUSE_INFO,
+
+	HINIC3_NIC_CMD_SET_PORT_CAR,
+	HINIC3_NIC_CMD_SET_ER_DROP_PKT,
+
+	HINIC3_NIC_CMD_VF_COS,
+	HINIC3_NIC_CMD_SETUP_COS_MAPPING,
+	HINIC3_NIC_CMD_SET_ETS,
+	HINIC3_NIC_CMD_SET_PFC,
+
+	/* MISC */
+	HINIC3_NIC_CMD_BIOS_CFG = 120,
+	HINIC3_NIC_CMD_SET_FIRMWARE_CUSTOM_PACKETS_MSG,
+
+	/* DFX */
+	HINIC3_NIC_CMD_GET_SM_TABLE = 140,
+	HINIC3_NIC_CMD_RD_LINE_TBL,
+
+	HINIC3_NIC_CMD_SET_VHD_CFG = 161,
+
+	HINIC3_NIC_CMD_GET_PORT_STAT = 200,
+	HINIC3_NIC_CMD_CLEAN_PORT_STAT,
+
+	HINIC3_NIC_CMD_MAX = 256
+};
+
+/* COMM commands between driver to MPU. */
+enum hinic3_mgmt_cmd {
+	HINIC3_MGMT_CMD_FUNC_RESET = 0,
+	HINIC3_MGMT_CMD_FEATURE_NEGO,
+	HINIC3_MGMT_CMD_FLUSH_DOORBELL,
+	HINIC3_MGMT_CMD_START_FLUSH,
+	HINIC3_MGMT_CMD_SET_FUNC_FLR,
+	HINIC3_MGMT_CMD_SET_FUNC_SVC_USED_STATE = 7,
+
+	HINIC3_MGMT_CMD_CFG_MSIX_NUM = 10,
+
+	HINIC3_MGMT_CMD_SET_CMDQ_CTXT = 20,
+	HINIC3_MGMT_CMD_SET_VAT,
+	HINIC3_MGMT_CMD_CFG_PAGESIZE,
+	HINIC3_MGMT_CMD_CFG_MSIX_CTRL_REG,
+	HINIC3_MGMT_CMD_SET_CEQ_CTRL_REG,
+	HINIC3_MGMT_CMD_SET_DMA_ATTR,
+
+	HINIC3_MGMT_CMD_GET_MQM_FIX_INFO = 40,
+	HINIC3_MGMT_CMD_SET_MQM_CFG_INFO,
+	HINIC3_MGMT_CMD_SET_MQM_SRCH_GPA,
+	HINIC3_MGMT_CMD_SET_PPF_TMR,
+	HINIC3_MGMT_CMD_SET_PPF_HT_GPA,
+	HINIC3_MGMT_CMD_SET_FUNC_TMR_BITMAT,
+
+	HINIC3_MGMT_CMD_GET_FW_VERSION = 60,
+	HINIC3_MGMT_CMD_GET_BOARD_INFO,
+	HINIC3_MGMT_CMD_SYNC_TIME,
+	HINIC3_MGMT_CMD_GET_HW_PF_INFOS,
+	HINIC3_MGMT_CMD_SEND_BDF_INFO,
+
+	HINIC3_MGMT_CMD_UPDATE_FW = 80,
+	HINIC3_MGMT_CMD_ACTIVE_FW,
+	HINIC3_MGMT_CMD_HOT_ACTIVE_FW,
+	HINIC3_MGMT_CMD_HOT_ACTIVE_DONE_NOTICE,
+	HINIC3_MGMT_CMD_SWITCH_CFG,
+	HINIC3_MGMT_CMD_CHECK_FLASH,
+	HINIC3_MGMT_CMD_CHECK_FLASH_RW,
+	HINIC3_MGMT_CMD_RESOURCE_CFG,
+	HINIC3_MGMT_CMD_UPDATE_BIOS,
+
+	HINIC3_MGMT_CMD_FAULT_REPORT = 100,
+	HINIC3_MGMT_CMD_WATCHDOG_INFO,
+	HINIC3_MGMT_CMD_MGMT_RESET,
+	HINIC3_MGMT_CMD_FFM_SET,
+
+	HINIC3_MGMT_CMD_GET_LOG = 120,
+	HINIC3_MGMT_CMD_TEMP_OP,
+	HINIC3_MGMT_CMD_EN_AUTO_RST_CHIP,
+	HINIC3_MGMT_CMD_CFG_REG,
+	HINIC3_MGMT_CMD_GET_CHIP_ID,
+	HINIC3_MGMT_CMD_SYSINFO_DFX,
+	HINIC3_MGMT_CMD_PCIE_DFX_NTC,
+};
+
+enum mag_cmd {
+	SERDES_CMD_PROCESS = 0,
+
+	MAG_CMD_SET_PORT_CFG      = 1,
+	MAG_CMD_SET_PORT_ADAPT    = 2,
+	MAG_CMD_CFG_LOOPBACK_MODE = 3,
+
+	MAG_CMD_GET_PORT_ENABLE   = 5,
+	MAG_CMD_SET_PORT_ENABLE   = 6,
+	MAG_CMD_GET_LINK_STATUS   = 7,
+	MAG_CMD_SET_LINK_FOLLOW   = 8,
+	MAG_CMD_SET_PMA_ENABLE    = 9,
+	MAG_CMD_CFG_FEC_MODE      = 10,
+
+	/* PHY */
+	MAG_CMD_GET_XSFP_INFO        = 60,
+	MAG_CMD_SET_XSFP_ENABLE      = 61,
+	MAG_CMD_GET_XSFP_PRESENT     = 62,
+	/* sfp/qsfp single byte read/write, for equipment test. */
+	MAG_CMD_SET_XSFP_RW          = 63,
+	MAG_CMD_CFG_XSFP_TEMPERATURE = 64,
+
+	MAG_CMD_WIRE_EVENT        = 100,
+	MAG_CMD_LINK_ERR_EVENT    = 101,
+
+	MAG_CMD_EVENT_PORT_INFO   = 150,
+	MAG_CMD_GET_PORT_STAT     = 151,
+	MAG_CMD_CLR_PORT_STAT     = 152,
+	MAG_CMD_GET_PORT_INFO     = 153,
+	MAG_CMD_GET_PCS_ERR_CNT   = 154,
+	MAG_CMD_GET_MAG_CNT       = 155,
+	MAG_CMD_DUMP_ANTRAIN_INFO = 156,
+
+	MAG_CMD_MAX = 0xFF
+};
+
+#endif /* _HINIC3_CMD_H_ */
drivers/net/hinic3/base/hinic3_compat.h new file +266 -0

266 lines not on this page · raw message

drivers/net/hinic3/base/hinic3_csr.h new file +108 -0

108 lines not on this page · raw message

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

Re: [V5 02/18] net/hinic3: add basic header files

Quoted 5 lines · On Wed, 2 Jul 2025 10:09:25 +0800 Feifei Wang <[email protected]> wrote:
drivers/net/hinic3/base/hinic3_compat.h new file +5 -0
+static inline unsigned long
+clock_gettime_ms(void)
+{
+	struct timespec tv;
+

drivers/net/hinic3/base/hinic3_compat.h line 159

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h new file +10 -0
+	clock_gettime(CLOCK_TYPE, &tv);
+
+	return (unsigned long)tv.tv_sec * HINIC3_S_TO_MS_UNIT +
+	       (unsigned long)tv.tv_nsec / HINIC3_S_TO_NS_UNIT;
+}
+
+#define jiffies		      clock_gettime_ms()
+#define msecs_to_jiffies(ms)  (ms)
+#define time_before(now, end) ((now) < (end))
+

Use of clock_gettime() is discouraged. Instead, drivers should use TSC directly like the rest of the DPDK.

Also, that version of time_before() macro is incorrect for the case of jiffie wraparound. Better off to use uint64_t.

Quoted 4 lines
drivers/net/hinic3/base/hinic3_compat.h new file +4 -0
+
+static inline u16
+ilog2(u32 n)
+{

drivers/net/hinic3/base/hinic3_compat.h line 222

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h new file +10 -0
+	u16 res = 0;
+
+	while (n > 1) {
+		n >>= 1;
+		res++;
+	}
+
+	return res;
+}
+

If it matters, there are faster ways to do this function.

Quoted 7 lines
drivers/net/hinic3/base/hinic3_compat.h new file +7 -0
+static inline int
+hinic3_mutex_lock(pthread_mutex_t *pthreadmutex)
+{
+	int err;
+
+	err = pthread_mutex_lock(pthreadmutex);
+	if (err)

drivers/net/hinic3/base/hinic3_compat.h line 264

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h new file +10 -0
+		PMD_DRV_LOG(ERR, "Mutex lock failed, err: %d", err);
+
+	return err;
+}
+
+static inline void
+hinic3_mutex_unlock(pthread_mutex_t *pthreadmutex)
+{
+	pthread_mutex_unlock(pthreadmutex);
+}

Why are you using pthread_mutex? DPDK drivers in general do not do locking in the control path, it is assumed the application is coded correctly to only do control operations from single context.

The driver needs to be more like other drivers. "Snowflake" drivers mean applications have to deal with different semantics for each device.

#130 lore raw

Re: [V5 02/18] net/hinic3: add basic header files

In reply to Feifei Wang
Quoted 52 lines · Feifei Wang

From: Xin Wang <[email protected]>

Add HW registers definition header file for SP series NIC.

Add some headers that define commands and basic defines for

use in the code.

---

 drivers/net/hinic3/base/hinic3_cmd.h    | 231 ++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_compat.h | 266 ++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_csr.h    | 108 ++++++++++
 3 files changed, 605 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_cmd.h
 create mode 100644 drivers/net/hinic3/base/hinic3_compat.h
 create mode 100644 drivers/net/hinic3/base/hinic3_csr.h
drivers/net/hinic3/base/hinic3_cmd.h +0 -0

new file mode 100644

index 0000000000..f0e200a944

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_cmd.h

drivers/net/hinic3/base/hinic3_cmd.h +3 -0
@@ -0,0 +1,231 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */

drivers/net/hinic3/base/hinic3_cmd.h line 8

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmd.h +5 -0
 
+
 
+#ifndef _HINIC3_CMD_H_
 
+#define _HINIC3_CMD_H_
 
+
 
+#define NIC_RSS_TEMP_ID_TO_CTX_LT_IDX(tmp_id)	tmp_id

Suggest: #define NIC_RSS_TEMP_ID_TO_CTX_LT_IDX(tmp_id) (tmp_id)

Quoted 84 lines
drivers/net/hinic3/base/hinic3_cmd.h +42 -0
+/* Begin of one temp tbl. */
 
+#define NIC_RSS_TEMP_ID_TO_INDIR_LT_IDX(tmp_id)	((tmp_id) << 4)
 
+/* 4 ctx in one entry. */
 
+#define NIC_RSS_CTX_TBL_ENTRY_SIZE		0x10
 
+/* Entry size = 16B, 16 entry/template. */
 
+#define NIC_RSS_INDIR_TBL_ENTRY_SIZE		0x10
 
+/* Entry size = 16B, so entry_num = 256B/16B. */
 
+#define NIC_RSS_INDIR_TBL_ENTRY_NUM		0x10
 
+
 
+#define NIC_UP_RSS_INVALID_TEMP_ID		0xFF
 
+#define NIC_UP_RSS_INVALID_FUNC_ID		0xFFFF
 
+#define NIC_UP_RSS_INVALID			0x00
 
+#define NIC_UP_RSS_EN				0x01
 
+#define NIC_UP_RSS_INVALID_GROUP_ID		0x7F
 
+
 
+#define NIC_RSS_CMD_TEMP_ALLOC			0x01
 
+#define NIC_RSS_CMD_TEMP_FREE			0x02
 
+
 
+#define HINIC3_RSS_TYPE_VALID_SHIFT		23
 
+#define HINIC3_RSS_TYPE_TCP_IPV6_EXT_SHIFT	24
 
+#define HINIC3_RSS_TYPE_IPV6_EXT_SHIFT		25
 
+#define HINIC3_RSS_TYPE_TCP_IPV6_SHIFT		26
 
+#define HINIC3_RSS_TYPE_IPV6_SHIFT		27
 
+#define HINIC3_RSS_TYPE_TCP_IPV4_SHIFT		28
 
+#define HINIC3_RSS_TYPE_IPV4_SHIFT		29
 
+#define HINIC3_RSS_TYPE_UDP_IPV6_SHIFT		30
 
+#define HINIC3_RSS_TYPE_UDP_IPV4_SHIFT		31
 
+#define HINIC3_RSS_TYPE_SET(val, member)	\
 
+	(((u32)(val) & 0x1) << HINIC3_RSS_TYPE_##member##_SHIFT)
 
+
 
+#define HINIC3_RSS_TYPE_GET(val, member)	\
 
+	(((u32)(val) >> HINIC3_RSS_TYPE_##member##_SHIFT) & 0x1)
 
+
 
+/* NIC CMDQ MODE. */
 
+typedef enum hinic3_ucode_cmd {
 
+	HINIC3_UCODE_CMD_MODIFY_QUEUE_CTX = 0,
 
+	HINIC3_UCODE_CMD_CLEAN_QUEUE_CONTEXT,
 
+	HINIC3_UCODE_CMD_ARM_SQ,
 
+	HINIC3_UCODE_CMD_ARM_RQ,
 
+	HINIC3_UCODE_CMD_SET_RSS_INDIR_TABLE,
 
+	HINIC3_UCODE_CMD_SET_RSS_CONTEXT_TABLE,
 
+	HINIC3_UCODE_CMD_GET_RSS_INDIR_TABLE,

drivers/net/hinic3/base/hinic3_cmd.h line 55

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmd.h +5 -0
 
+	HINIC3_UCODE_CMD_GET_RSS_CONTEXT_TABLE,
 
+	HINIC3_UCODE_CMD_SET_IQ_ENABLE,
 
+	HINIC3_UCODE_CMD_SET_RQ_FLUSH = 10,
 
+	HINIC3_UCODE_CMD_MODIFY_VLAN_CTX,
 
+} cmdq_nic_subtype_e;

Some enum (below) don't have typedef. Suggest keep the same.

drivers/net/hinic3/base/hinic3_cmd.h line 57

Quoted 4 lines
drivers/net/hinic3/base/hinic3_cmd.h +2 -0
+
 
+/* Commands between NIC to MPU. */

There are no place to describe MPU I think.
Is this firmware? If is, suggest descript it as: Commands definend between NIC and firmware.

Quoted 132 lines
drivers/net/hinic3/base/hinic3_cmd.h +66 -0
+enum hinic3_nic_cmd {
 
+	/* Only for PFD and VFD. */
 
+	HINIC3_NIC_CMD_VF_REGISTER = 0,
 
+
 
+	/* FUNC CFG */
 
+	HINIC3_NIC_CMD_SET_FUNC_TBL = 5,
 
+	HINIC3_NIC_CMD_SET_VPORT_ENABLE,
 
+	HINIC3_NIC_CMD_SET_RX_MODE,
 
+	HINIC3_NIC_CMD_SQ_CI_ATTR_SET,
 
+	HINIC3_NIC_CMD_GET_VPORT_STAT,
 
+	HINIC3_NIC_CMD_CLEAN_VPORT_STAT,
 
+	HINIC3_NIC_CMD_CLEAR_QP_RESOURCE,
 
+	HINIC3_NIC_CMD_CFG_FLEX_QUEUE,
 
+	/* LRO CFG */
 
+	HINIC3_NIC_CMD_CFG_RX_LRO,
 
+	HINIC3_NIC_CMD_CFG_LRO_TIMER,
 
+	HINIC3_NIC_CMD_FEATURE_NEGO,
 
+
 
+	/* MAC & VLAN CFG */
 
+	HINIC3_NIC_CMD_GET_MAC = 20,
 
+	HINIC3_NIC_CMD_SET_MAC,
 
+	HINIC3_NIC_CMD_DEL_MAC,
 
+	HINIC3_NIC_CMD_UPDATE_MAC,
 
+	HINIC3_NIC_CMD_GET_ALL_DEFAULT_MAC,
 
+
 
+	HINIC3_NIC_CMD_CFG_FUNC_VLAN,
 
+	HINIC3_NIC_CMD_SET_VLAN_FILTER_EN,
 
+	HINIC3_NIC_CMD_SET_RX_VLAN_OFFLOAD,
 
+
 
+	/* SR-IOV */
 
+	HINIC3_NIC_CMD_CFG_VF_VLAN = 40,
 
+	HINIC3_NIC_CMD_SET_SPOOPCHK_STATE,
 
+	/* RATE LIMIT */
 
+	HINIC3_NIC_CMD_SET_MAX_MIN_RATE,
 
+
 
+	/* RSS CFG */
 
+	HINIC3_NIC_CMD_RSS_CFG = 60,
 
+	HINIC3_NIC_CMD_RSS_TEMP_MGR,
 
+	HINIC3_NIC_CMD_GET_RSS_CTX_TBL,
 
+	HINIC3_NIC_CMD_CFG_RSS_HASH_KEY,
 
+	HINIC3_NIC_CMD_CFG_RSS_HASH_ENGINE,
 
+	HINIC3_NIC_CMD_SET_RSS_CTX_TBL_INTO_FUNC,
 
+
 
+	/* FDIR */
 
+	HINIC3_NIC_CMD_ADD_TC_FLOW = 80,
 
+	HINIC3_NIC_CMD_DEL_TC_FLOW,
 
+	HINIC3_NIC_CMD_GET_TC_FLOW,
 
+	HINIC3_NIC_CMD_FLUSH_TCAM,
 
+	HINIC3_NIC_CMD_CFG_TCAM_BLOCK,
 
+	HINIC3_NIC_CMD_ENABLE_TCAM,
 
+	HINIC3_NIC_CMD_GET_TCAM_BLOCK,
 
+
 
+	HINIC3_NIC_CMD_SET_FDIR_STATUS = 91,
 
+
 
+	/* PORT CFG */
 
+	HINIC3_NIC_CMD_SET_PORT_ENABLE = 100,
 
+	HINIC3_NIC_CMD_CFG_PAUSE_INFO,
 
+
 
+	HINIC3_NIC_CMD_SET_PORT_CAR,
 
+	HINIC3_NIC_CMD_SET_ER_DROP_PKT,
 
+
 
+	HINIC3_NIC_CMD_VF_COS,
 
+	HINIC3_NIC_CMD_SETUP_COS_MAPPING,
 
+	HINIC3_NIC_CMD_SET_ETS,
 
+	HINIC3_NIC_CMD_SET_PFC,
 
+

drivers/net/hinic3/base/hinic3_cmd.h line 128

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmd.h +5 -0
 
+	/* MISC */
 
+	HINIC3_NIC_CMD_BIOS_CFG = 120,
 
+	HINIC3_NIC_CMD_SET_FIRMWARE_CUSTOM_PACKETS_MSG,
 
+
 
+	/* DFX */

DFX is most used in Huawei, Maybe we should use another descriptor.

Quoted 14 lines
drivers/net/hinic3/base/hinic3_cmd.h +7 -0
+	HINIC3_NIC_CMD_GET_SM_TABLE = 140,
 
+	HINIC3_NIC_CMD_RD_LINE_TBL,
 
+
 
+	HINIC3_NIC_CMD_SET_VHD_CFG = 161,
 
+
 
+	HINIC3_NIC_CMD_GET_PORT_STAT = 200,
 
+	HINIC3_NIC_CMD_CLEAN_PORT_STAT,

drivers/net/hinic3/base/hinic3_cmd.h line 140

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmd.h +5 -0
 
+
 
+	HINIC3_NIC_CMD_MAX = 256
 
+};
 
+
 
+/* COMM commands between driver to MPU. */

Common commands between driver and firmware.

Quoted 98 lines
drivers/net/hinic3/base/hinic3_cmd.h +49 -0
+enum hinic3_mgmt_cmd {
 
+	HINIC3_MGMT_CMD_FUNC_RESET = 0,
 
+	HINIC3_MGMT_CMD_FEATURE_NEGO,
 
+	HINIC3_MGMT_CMD_FLUSH_DOORBELL,
 
+	HINIC3_MGMT_CMD_START_FLUSH,
 
+	HINIC3_MGMT_CMD_SET_FUNC_FLR,
 
+	HINIC3_MGMT_CMD_SET_FUNC_SVC_USED_STATE = 7,
 
+
 
+	HINIC3_MGMT_CMD_CFG_MSIX_NUM = 10,
 
+
 
+	HINIC3_MGMT_CMD_SET_CMDQ_CTXT = 20,
 
+	HINIC3_MGMT_CMD_SET_VAT,
 
+	HINIC3_MGMT_CMD_CFG_PAGESIZE,
 
+	HINIC3_MGMT_CMD_CFG_MSIX_CTRL_REG,
 
+	HINIC3_MGMT_CMD_SET_CEQ_CTRL_REG,
 
+	HINIC3_MGMT_CMD_SET_DMA_ATTR,
 
+
 
+	HINIC3_MGMT_CMD_GET_MQM_FIX_INFO = 40,
 
+	HINIC3_MGMT_CMD_SET_MQM_CFG_INFO,
 
+	HINIC3_MGMT_CMD_SET_MQM_SRCH_GPA,
 
+	HINIC3_MGMT_CMD_SET_PPF_TMR,
 
+	HINIC3_MGMT_CMD_SET_PPF_HT_GPA,
 
+	HINIC3_MGMT_CMD_SET_FUNC_TMR_BITMAT,
 
+
 
+	HINIC3_MGMT_CMD_GET_FW_VERSION = 60,
 
+	HINIC3_MGMT_CMD_GET_BOARD_INFO,
 
+	HINIC3_MGMT_CMD_SYNC_TIME,
 
+	HINIC3_MGMT_CMD_GET_HW_PF_INFOS,
 
+	HINIC3_MGMT_CMD_SEND_BDF_INFO,
 
+
 
+	HINIC3_MGMT_CMD_UPDATE_FW = 80,
 
+	HINIC3_MGMT_CMD_ACTIVE_FW,
 
+	HINIC3_MGMT_CMD_HOT_ACTIVE_FW,
 
+	HINIC3_MGMT_CMD_HOT_ACTIVE_DONE_NOTICE,
 
+	HINIC3_MGMT_CMD_SWITCH_CFG,
 
+	HINIC3_MGMT_CMD_CHECK_FLASH,
 
+	HINIC3_MGMT_CMD_CHECK_FLASH_RW,
 
+	HINIC3_MGMT_CMD_RESOURCE_CFG,
 
+	HINIC3_MGMT_CMD_UPDATE_BIOS,
 
+
 
+	HINIC3_MGMT_CMD_FAULT_REPORT = 100,
 
+	HINIC3_MGMT_CMD_WATCHDOG_INFO,
 
+	HINIC3_MGMT_CMD_MGMT_RESET,
 
+	HINIC3_MGMT_CMD_FFM_SET,
 
+
 
+	HINIC3_MGMT_CMD_GET_LOG = 120,
 
+	HINIC3_MGMT_CMD_TEMP_OP,
 
+	HINIC3_MGMT_CMD_EN_AUTO_RST_CHIP,
 
+	HINIC3_MGMT_CMD_CFG_REG,

drivers/net/hinic3/base/hinic3_cmd.h line 194

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmd.h +5 -0
 
+	HINIC3_MGMT_CMD_GET_CHIP_ID,
 
+	HINIC3_MGMT_CMD_SYSINFO_DFX,
 
+	HINIC3_MGMT_CMD_PCIE_DFX_NTC,
 
+};
 
+

suggest add small comment to descriptor what the following command means.

Quoted 127 lines
drivers/net/hinic3/base/hinic3_cmd.h +37 -0
+enum mag_cmd {
 
+	SERDES_CMD_PROCESS = 0,
 
+
 
+	MAG_CMD_SET_PORT_CFG      = 1,
 
+	MAG_CMD_SET_PORT_ADAPT    = 2,
 
+	MAG_CMD_CFG_LOOPBACK_MODE = 3,
 
+
 
+	MAG_CMD_GET_PORT_ENABLE   = 5,
 
+	MAG_CMD_SET_PORT_ENABLE   = 6,
 
+	MAG_CMD_GET_LINK_STATUS   = 7,
 
+	MAG_CMD_SET_LINK_FOLLOW   = 8,
 
+	MAG_CMD_SET_PMA_ENABLE    = 9,
 
+	MAG_CMD_CFG_FEC_MODE      = 10,
 
+
 
+	/* PHY */
 
+	MAG_CMD_GET_XSFP_INFO        = 60,
 
+	MAG_CMD_SET_XSFP_ENABLE      = 61,
 
+	MAG_CMD_GET_XSFP_PRESENT     = 62,
 
+	/* sfp/qsfp single byte read/write, for equipment test. */
 
+	MAG_CMD_SET_XSFP_RW          = 63,
 
+	MAG_CMD_CFG_XSFP_TEMPERATURE = 64,
 
+
 
+	MAG_CMD_WIRE_EVENT        = 100,
 
+	MAG_CMD_LINK_ERR_EVENT    = 101,
 
+
 
+	MAG_CMD_EVENT_PORT_INFO   = 150,
 
+	MAG_CMD_GET_PORT_STAT     = 151,
 
+	MAG_CMD_CLR_PORT_STAT     = 152,
 
+	MAG_CMD_GET_PORT_INFO     = 153,
 
+	MAG_CMD_GET_PCS_ERR_CNT   = 154,
 
+	MAG_CMD_GET_MAG_CNT       = 155,
 
+	MAG_CMD_DUMP_ANTRAIN_INFO = 156,
 
+
 
+	MAG_CMD_MAX = 0xFF
 
+};
 
+
 
+#endif /* _HINIC3_CMD_H_ */
drivers/net/hinic3/base/hinic3_compat.h +0 -0

new file mode 100644

index 0000000000..76ce5b83c6

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_compat.h

drivers/net/hinic3/base/hinic3_compat.h +21 -0
@@ -0,0 +1,266 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#ifndef _HINIC3_COMPAT_H_
 
+#define _HINIC3_COMPAT_H_
 
+
 
+#include <stdint.h>
 
+#include <stdbool.h>
 
+#include <sys/time.h>
 
+#include <unistd.h>
 
+#include <sys/syscall.h>
 
+#include <pthread.h>
 
+#include <ethdev_pci.h>
 
+#include <eal_interrupts.h>
 
+#include <rte_io.h>
 
+#include <rte_atomic.h>
 
+#include <rte_byteorder.h>
 
+#include <rte_common.h>
 
+#include <rte_config.h>
 
+#include <rte_cycles.h>

drivers/net/hinic3/base/hinic3_compat.h line 26

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h +5 -0
 
+#include <rte_log.h>
 
+#include <rte_malloc.h>
 
+#include <rte_memcpy.h>
 
+#include <rte_memzone.h>
 
+#include <rte_spinlock.h>

Only included what need in this file.

Quoted 4 lines
drivers/net/hinic3/base/hinic3_compat.h +2 -0
+
 
+typedef uint8_t  u8;

drivers/net/hinic3/base/hinic3_compat.h line 33

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h +5 -0
 
+typedef int8_t   s8;
 
+typedef uint16_t u16;
 
+typedef uint32_t u32;
 
+typedef int32_t  s32;
 
+typedef uint64_t u64;

Suggest don't redefine it, just use the stdint.h types.

Quoted 44 lines
drivers/net/hinic3/base/hinic3_compat.h +22 -0
+
 
+#ifndef BIT
 
+#define BIT(n) (1U << (n))
 
+#endif
 
+
 
+#define upper_32_bits(n) ((u32)(((n) >> 16) >> 16))
 
+#define lower_32_bits(n) ((u32)(n))
 
+
 
+#define HINIC3_MEM_ALLOC_ALIGN_MIN 1
 
+
 
+extern int hinic3_logtype;
 
+#define RTE_LOGTYPE_NET_HINIC3 hinic3_logtype
 
+
 
+#define PMD_DRV_LOG(level, ...) RTE_LOG_LINE(level, NET_HINIC3, __VA_ARGS__)
 
+
 
+/* Bit order interface. */
 
+#define cpu_to_be16(o) rte_cpu_to_be_16(o)
 
+#define cpu_to_be32(o) rte_cpu_to_be_32(o)
 
+#define cpu_to_be64(o) rte_cpu_to_be_64(o)
 
+#define cpu_to_le32(o) rte_cpu_to_le_32(o)
 
+#define be16_to_cpu(o) rte_be_to_cpu_16(o)
 
+#define be32_to_cpu(o) rte_be_to_cpu_32(o)

drivers/net/hinic3/base/hinic3_compat.h line 60

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h +5 -0
 
+#define be64_to_cpu(o) rte_be_to_cpu_64(o)
 
+#define le32_to_cpu(o) rte_le_to_cpu_32(o)
 
+
 
+#ifdef HW_CONVERT_ENDIAN
 
+/* If csrs to enable endianness converting are configured, hw will do the

If csrs to enable xxx ---can't get the meaning.
hw -> the hardware

Quoted 16 lines

+ * endianness converting for stateless SQ ci, the fields less than 4B for

+ * doorbell, the fields less than 4B in the CQE data.

+ */

drivers/net/hinic3/base/hinic3_compat.h +5 -0
+#define hinic3_hw_be32(val)  (val)
 
+#define hinic3_hw_cpu32(val) (val)
 
+#define hinic3_hw_cpu16(val) (val)
 
+#else
 
+#define hinic3_hw_be32(val)  cpu_to_be32(val)

drivers/net/hinic3/base/hinic3_compat.h line 73

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h +5 -0
 
+#define hinic3_hw_cpu32(val) be32_to_cpu(val)
 
+#define hinic3_hw_cpu16(val) be16_to_cpu(val)
 
+#endif
 
+
 
+#define ARRAY_LEN(arr) ((int)(sizeof(arr) / sizeof((arr)[0])))

There are RTE_DIM.

drivers/net/hinic3/base/hinic3_compat.h line 76

Quoted 6 lines
drivers/net/hinic3/base/hinic3_compat.h +3 -0
+
 
+static inline void
 
+hinic3_hw_be32_len(void *data, int len)

This function name was not very good.

drivers/net/hinic3/base/hinic3_compat.h line 82

Quoted 12 lines
drivers/net/hinic3/base/hinic3_compat.h +6 -0
+{
 
+	int i, chunk_sz = sizeof(u32);
 
+	u32 *mem = data;
 
+
 
+	if (!data)
 
+		return;

this is inned help function, if the data is always non NULL, no need to add this judgement.

Quoted 4 lines
drivers/net/hinic3/base/hinic3_compat.h +2 -0
+
 
+	len = len / chunk_sz;

drivers/net/hinic3/base/hinic3_compat.h line 89

Quoted 10 lines
drivers/net/hinic3/base/hinic3_compat.h +5 -0
 
+
 
+	for (i = 0; i < len; i++) {
 
+		*mem = hinic3_hw_be32(*mem);
 
+		mem++;
 
+	}

if there are rem of len % chun_sz?

Quoted 372 lines
drivers/net/hinic3/base/hinic3_compat.h +177 -0
+}
 
+
 
+static inline int
 
+hinic3_get_bit(int nr, volatile RTE_ATOMIC(u64) *addr)
 
+{
 
+	RTE_ASSERT(nr < 0x20);
 
+
 
+	uint32_t mask = UINT32_C(1) << nr;
 
+	return (*addr) & mask;
 
+}
 
+
 
+static inline void
 
+hinic3_set_bit(unsigned int nr, volatile RTE_ATOMIC(u64) *addr)
 
+{
 
+	rte_atomic_fetch_or_explicit(addr, (1UL << nr),
 
+				     rte_memory_order_seq_cst);
 
+}
 
+
 
+static inline void
 
+hinic3_clear_bit(int nr, volatile RTE_ATOMIC(u64) *addr)
 
+{
 
+	rte_atomic_fetch_and_explicit(addr, ~(1UL << nr),
 
+				      rte_memory_order_seq_cst);
 
+}
 
+
 
+static inline int
 
+hinic3_test_and_clear_bit(int nr, volatile RTE_ATOMIC(u64) *addr)
 
+{
 
+	unsigned long mask = (1UL << nr);
 
+
 
+	return (int)(rte_atomic_fetch_and_explicit(addr, ~mask,
 
+						   rte_memory_order_seq_cst) &
 
+		     mask);
 
+}
 
+
 
+static inline int
 
+hinic3_test_and_set_bit(int nr, volatile RTE_ATOMIC(u64) *addr)
 
+{
 
+	unsigned long mask = (1UL << nr);
 
+
 
+	return (int)(rte_atomic_fetch_or_explicit(addr, mask,
 
+						  rte_memory_order_seq_cst) &
 
+		     mask);
 
+}
 
+
 
+#ifdef CLOCK_MONOTONIC_RAW /**< Defined in glibc bits/time.h . */
 
+#define CLOCK_TYPE CLOCK_MONOTONIC_RAW
 
+#else
 
+#define CLOCK_TYPE CLOCK_MONOTONIC
 
+#endif
 
+
 
+#define HINIC3_MUTEX_TIMEOUT 10
 
+#define HINIC3_S_TO_MS_UNIT  1000
 
+#define HINIC3_S_TO_NS_UNIT  1000000
 
+
 
+static inline unsigned long
 
+clock_gettime_ms(void)
 
+{
 
+	struct timespec tv;
 
+
 
+	clock_gettime(CLOCK_TYPE, &tv);
 
+
 
+	return (unsigned long)tv.tv_sec * HINIC3_S_TO_MS_UNIT +
 
+	       (unsigned long)tv.tv_nsec / HINIC3_S_TO_NS_UNIT;
 
+}
 
+
 
+#define jiffies		      clock_gettime_ms()
 
+#define msecs_to_jiffies(ms)  (ms)
 
+#define time_before(now, end) ((now) < (end))
 
+
 
+/**
 
+ * Convert data to big endian 32 bit format.
 
+ *
 
+ * @param data
 
+ * The data to convert.
 
+ * @param len
 
+ * Length of data to convert, must be Multiple of 4B.
 
+ */
 
+static inline void
 
+hinic3_cpu_to_be32(void *data, int len)
 
+{
 
+	int i, chunk_sz = sizeof(u32);
 
+	u32 *mem = data;
 
+
 
+	if (!data)
 
+		return;
 
+
 
+	len = len / chunk_sz;
 
+
 
+	for (i = 0; i < len; i++) {
 
+		*mem = cpu_to_be32(*mem);
 
+		mem++;
 
+	}
 
+}
 
+
 
+/**
 
+ * Convert data from big endian 32 bit format.
 
+ *
 
+ * @param data
 
+ * The data to convert.
 
+ * @param len
 
+ * Length of data to convert, must be Multiple of 4B.
 
+ */
 
+static inline void
 
+hinic3_be32_to_cpu(void *data, int len)
 
+{
 
+	int i, chunk_sz = sizeof(u32);
 
+	u32 *mem = data;
 
+
 
+	if (!data)
 
+		return;
 
+
 
+	len = len / chunk_sz;
 
+
 
+	for (i = 0; i < len; i++) {
 
+		*mem = be32_to_cpu(*mem);
 
+		mem++;
 
+	}
 
+}
 
+
 
+static inline u16
 
+ilog2(u32 n)
 
+{
 
+	u16 res = 0;
 
+
 
+	while (n > 1) {
 
+		n >>= 1;
 
+		res++;
 
+	}
 
+
 
+	return res;
 
+}
 
+
 
+static inline int
 
+hinic3_mutex_init(pthread_mutex_t *pthreadmutex,
 
+		  const pthread_mutexattr_t *mattr)
 
+{
 
+	int err;
 
+
 
+	err = pthread_mutex_init(pthreadmutex, mattr);
 
+	if (unlikely(err))
 
+		PMD_DRV_LOG(ERR, "Initialize mutex failed, error: %d", err);
 
+
 
+	return err;
 
+}
 
+
 
+static inline int
 
+hinic3_mutex_destroy(pthread_mutex_t *pthreadmutex)
 
+{
 
+	int err;
 
+
 
+	err = pthread_mutex_destroy(pthreadmutex);
 
+	if (unlikely(err))
 
+		PMD_DRV_LOG(ERR, "Destroy mutex failed, error: %d", err);
 
+
 
+	return err;
 
+}
 
+
 
+static inline int
 
+hinic3_mutex_lock(pthread_mutex_t *pthreadmutex)
 
+{
 
+	int err;
 
+
 
+	err = pthread_mutex_lock(pthreadmutex);
 
+	if (err)
 
+		PMD_DRV_LOG(ERR, "Mutex lock failed, err: %d", err);
 
+
 
+	return err;
 
+}
 
+
 
+static inline void
 
+hinic3_mutex_unlock(pthread_mutex_t *pthreadmutex)
 
+{
 
+	pthread_mutex_unlock(pthreadmutex);
 
+}
 
+
 
+#endif /* _HINIC3_COMPAT_H_ */
drivers/net/hinic3/base/hinic3_csr.h +0 -0

new file mode 100644

index 0000000000..f0dd690bf8

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_csr.h

drivers/net/hinic3/base/hinic3_csr.h +3 -0
@@ -0,0 +1,108 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */

drivers/net/hinic3/base/hinic3_csr.h line 8

Quoted 10 lines
drivers/net/hinic3/base/hinic3_csr.h +5 -0
 
+
 
+#ifndef _HINIC3_CSR_H_
 
+#define _HINIC3_CSR_H_
 
+
 
+#ifdef CONFIG_SP_VID_DID

This define should be document is drivers's rst.

Quoted 201 lines
drivers/net/hinic3/base/hinic3_csr.h +100 -0
+#define PCI_VENDOR_ID_SPNIC    0x1F3F
 
+#define HINIC3_DEV_ID_STANDARD 0x9020
 
+#define HINIC3_DEV_ID_VF       0x9001
 
+#else
 
+#define PCI_VENDOR_ID_HUAWEI   0x19e5
 
+#define HINIC3_DEV_ID_STANDARD 0x0222
 
+#define HINIC3_DEV_ID_VF       0x375F
 
+#endif
 
+
 
+/*
 
+ * Bit30/bit31 for bar index flag.
 
+ * 00: bar0
 
+ * 01: bar1
 
+ * 10: bar2
 
+ * 11: bar3
 
+ */
 
+#define HINIC3_CFG_REGS_FLAG 0x40000000
 
+
 
+#define HINIC3_MGMT_REGS_FLAG 0xC0000000
 
+
 
+#define HINIC3_REGS_FLAG_MASK 0x3FFFFFFF
 
+
 
+#define HINIC3_VF_CFG_REG_OFFSET 0x2000
 
+
 
+#define HINIC3_HOST_CSR_BASE_ADDR   (HINIC3_MGMT_REGS_FLAG + 0x6000)
 
+#define HINIC3_CSR_GLOBAL_BASE_ADDR (HINIC3_MGMT_REGS_FLAG + 0x6400)
 
+
 
+/* HW interface registers. */
 
+#define HINIC3_CSR_FUNC_ATTR0_ADDR (HINIC3_CFG_REGS_FLAG + 0x0)
 
+#define HINIC3_CSR_FUNC_ATTR1_ADDR (HINIC3_CFG_REGS_FLAG + 0x4)
 
+#define HINIC3_CSR_FUNC_ATTR2_ADDR (HINIC3_CFG_REGS_FLAG + 0x8)
 
+#define HINIC3_CSR_FUNC_ATTR3_ADDR (HINIC3_CFG_REGS_FLAG + 0xC)
 
+#define HINIC3_CSR_FUNC_ATTR4_ADDR (HINIC3_CFG_REGS_FLAG + 0x10)
 
+#define HINIC3_CSR_FUNC_ATTR5_ADDR (HINIC3_CFG_REGS_FLAG + 0x14)
 
+#define HINIC3_CSR_FUNC_ATTR6_ADDR (HINIC3_CFG_REGS_FLAG + 0x18)
 
+
 
+#define HINIC3_FUNC_CSR_MAILBOX_DATA_OFF       0x80
 
+#define HINIC3_FUNC_CSR_MAILBOX_CONTROL_OFF    (HINIC3_CFG_REGS_FLAG + 0x0100)
 
+#define HINIC3_FUNC_CSR_MAILBOX_INT_OFFSET_OFF (HINIC3_CFG_REGS_FLAG + 0x0104)
 
+#define HINIC3_FUNC_CSR_MAILBOX_RESULT_H_OFF   (HINIC3_CFG_REGS_FLAG + 0x0108)
 
+#define HINIC3_FUNC_CSR_MAILBOX_RESULT_L_OFF   (HINIC3_CFG_REGS_FLAG + 0x010C)
 
+
 
+#define HINIC3_PPF_ELECTION_OFFSET 0x0
 
+#define HINIC3_MPF_ELECTION_OFFSET 0x20
 
+
 
+#define HINIC3_CSR_PPF_ELECTION_ADDR \
 
+	(HINIC3_HOST_CSR_BASE_ADDR + HINIC3_PPF_ELECTION_OFFSET)
 
+
 
+#define HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR \
 
+	(HINIC3_HOST_CSR_BASE_ADDR + HINIC3_MPF_ELECTION_OFFSET)
 
+
 
+#define HINIC3_CSR_DMA_ATTR_TBL_ADDR	   (HINIC3_CFG_REGS_FLAG + 0x380)
 
+#define HINIC3_CSR_DMA_ATTR_INDIR_IDX_ADDR (HINIC3_CFG_REGS_FLAG + 0x390)
 
+
 
+/* MSI-X registers. */
 
+#define HINIC3_CSR_MSIX_INDIR_IDX_ADDR	(HINIC3_CFG_REGS_FLAG + 0x310)
 
+#define HINIC3_CSR_MSIX_CTRL_ADDR	(HINIC3_CFG_REGS_FLAG + 0x300)
 
+#define HINIC3_CSR_MSIX_CNT_ADDR	(HINIC3_CFG_REGS_FLAG + 0x304)
 
+#define HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR (HINIC3_CFG_REGS_FLAG + 0x58)
 
+
 
+#define HINIC3_MSI_CLR_INDIR_RESEND_TIMER_CLR_SHIFT 0
 
+#define HINIC3_MSI_CLR_INDIR_INT_MSK_SET_SHIFT	    1
 
+#define HINIC3_MSI_CLR_INDIR_INT_MSK_CLR_SHIFT	    2
 
+#define HINIC3_MSI_CLR_INDIR_AUTO_MSK_SET_SHIFT	    3
 
+#define HINIC3_MSI_CLR_INDIR_AUTO_MSK_CLR_SHIFT	    4
 
+#define HINIC3_MSI_CLR_INDIR_SIMPLE_INDIR_IDX_SHIFT 22
 
+
 
+#define HINIC3_MSI_CLR_INDIR_RESEND_TIMER_CLR_MASK 0x1U
 
+#define HINIC3_MSI_CLR_INDIR_INT_MSK_SET_MASK	   0x1U
 
+#define HINIC3_MSI_CLR_INDIR_INT_MSK_CLR_MASK	   0x1U
 
+#define HINIC3_MSI_CLR_INDIR_AUTO_MSK_SET_MASK	   0x1U
 
+#define HINIC3_MSI_CLR_INDIR_AUTO_MSK_CLR_MASK	   0x1U
 
+#define HINIC3_MSI_CLR_INDIR_SIMPLE_INDIR_IDX_MASK 0x3FFU
 
+
 
+#define HINIC3_MSI_CLR_INDIR_SET(val, member)           \
 
+	(((val) & HINIC3_MSI_CLR_INDIR_##member##_MASK) \
 
+	 << HINIC3_MSI_CLR_INDIR_##member##_SHIFT)
 
+
 
+/* EQ registers. */
 
+#define HINIC3_AEQ_INDIR_IDX_ADDR (HINIC3_CFG_REGS_FLAG + 0x210)
 
+
 
+#define HINIC3_AEQ_MTT_OFF_BASE_ADDR (HINIC3_CFG_REGS_FLAG + 0x240)
 
+
 
+#define HINIC3_CSR_EQ_PAGE_OFF_STRIDE 8
 
+
 
+#define HINIC3_AEQ_HI_PHYS_ADDR_REG(pg_num) \
 
+	(HINIC3_AEQ_MTT_OFF_BASE_ADDR +     \
 
+	 (pg_num) * HINIC3_CSR_EQ_PAGE_OFF_STRIDE)
 
+
 
+#define HINIC3_AEQ_LO_PHYS_ADDR_REG(pg_num) \
 
+	(HINIC3_AEQ_MTT_OFF_BASE_ADDR +     \
 
+	 (pg_num) * HINIC3_CSR_EQ_PAGE_OFF_STRIDE + 4)
 
+
 
+#define HINIC3_CSR_AEQ_CTRL_0_ADDR	    (HINIC3_CFG_REGS_FLAG + 0x200)
 
+#define HINIC3_CSR_AEQ_CTRL_1_ADDR	    (HINIC3_CFG_REGS_FLAG + 0x204)
 
+#define HINIC3_CSR_AEQ_CONS_IDX_ADDR	    (HINIC3_CFG_REGS_FLAG + 0x208)
 
+#define HINIC3_CSR_AEQ_PROD_IDX_ADDR	    (HINIC3_CFG_REGS_FLAG + 0x20C)
 
+#define HINIC3_CSR_AEQ_CI_SIMPLE_INDIR_ADDR (HINIC3_CFG_REGS_FLAG + 0x50)
 
+
 
+#endif /* _HINIC3_CSR_H_ */
#131 lore raw

PATCH v5 3/18 net/hinic3: add hardware interfaces of BAR operation

In reply to Feifei Wang

From: Yi Chen <[email protected]>

This patch adds some HW interfaces for bar operatioin interfaces,
including: mapped bar address geeting, HW attributes getting, msi-x reg operation, function type getting and so on.

---
 drivers/net/hinic3/base/hinic3_hwif.c | 779 ++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_hwif.h | 142 +++++
 2 files changed, 921 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.h
drivers/net/hinic3/base/hinic3_hwif.c new file +779 -0
new file mode 100644
index 0000000000..ede4aa311f
@@ -0,0 +1,779 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#include <rte_bus_pci.h>
+#include "hinic3_compat.h"
+#include "hinic3_csr.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_hwif.h"
+
+#define WAIT_HWIF_READY_TIMEOUT 10000
+
+#define DB_IDX(db, db_base) \
+	((u32)(((ulong)(db) - (ulong)(db_base)) / HINIC3_DB_PAGE_SIZE))
+
+#define HINIC3_AF0_FUNC_GLOBAL_IDX_SHIFT 0
+#define HINIC3_AF0_P2P_IDX_SHIFT	 12
+#define HINIC3_AF0_PCI_INTF_IDX_SHIFT	 17
+#define HINIC3_AF0_VF_IN_PF_SHIFT	 20
+#define HINIC3_AF0_FUNC_TYPE_SHIFT	 28
+
+#define HINIC3_AF0_FUNC_GLOBAL_IDX_MASK 0xFFF
+#define HINIC3_AF0_P2P_IDX_MASK		0x1F
+#define HINIC3_AF0_PCI_INTF_IDX_MASK	0x7
+#define HINIC3_AF0_VF_IN_PF_MASK	0xFF
+#define HINIC3_AF0_FUNC_TYPE_MASK	0x1
+
+#define HINIC3_AF0_GET(val, member) \
+	(((val) >> HINIC3_AF0_##member##_SHIFT) & HINIC3_AF0_##member##_MASK)
+
+#define HINIC3_AF1_PPF_IDX_SHIFT	  0
+#define HINIC3_AF1_AEQS_PER_FUNC_SHIFT	  8
+#define HINIC3_AF1_MGMT_INIT_STATUS_SHIFT 30
+#define HINIC3_AF1_PF_INIT_STATUS_SHIFT	  31
+
+#define HINIC3_AF1_PPF_IDX_MASK		 0x3F
+#define HINIC3_AF1_AEQS_PER_FUNC_MASK	 0x3
+#define HINIC3_AF1_MGMT_INIT_STATUS_MASK 0x1
+#define HINIC3_AF1_PF_INIT_STATUS_MASK	 0x1
+
+#define HINIC3_AF1_GET(val, member) \
+	(((val) >> HINIC3_AF1_##member##_SHIFT) & HINIC3_AF1_##member##_MASK)
+
+#define HINIC3_AF2_CEQS_PER_FUNC_SHIFT	   0
+#define HINIC3_AF2_DMA_ATTR_PER_FUNC_SHIFT 9
+#define HINIC3_AF2_IRQS_PER_FUNC_SHIFT	   16
+
+#define HINIC3_AF2_CEQS_PER_FUNC_MASK	  0x1FF
+#define HINIC3_AF2_DMA_ATTR_PER_FUNC_MASK 0x7
+#define HINIC3_AF2_IRQS_PER_FUNC_MASK	  0x7FF
+
+#define HINIC3_AF2_GET(val, member) \
+	(((val) >> HINIC3_AF2_##member##_SHIFT) & HINIC3_AF2_##member##_MASK)
+
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_NXT_PF_SHIFT 0
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_PF_SHIFT	16
+
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_NXT_PF_MASK 0xFFF
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_PF_MASK     0xFFF
+
+#define HINIC3_AF3_GET(val, member) \
+	(((val) >> HINIC3_AF3_##member##_SHIFT) & HINIC3_AF3_##member##_MASK)
+
+#define HINIC3_AF4_DOORBELL_CTRL_SHIFT 0
+#define HINIC3_AF4_DOORBELL_CTRL_MASK  0x1
+
+#define HINIC3_AF4_GET(val, member) \
+	(((val) >> HINIC3_AF4_##member##_SHIFT) & HINIC3_AF4_##member##_MASK)
+
+#define HINIC3_AF4_SET(val, member) \
+	(((val) & HINIC3_AF4_##member##_MASK) << HINIC3_AF4_##member##_SHIFT)
+
+#define HINIC3_AF4_CLEAR(val, member) \
+	((val) & (~(HINIC3_AF4_##member##_MASK << HINIC3_AF4_##member##_SHIFT)))
+
+#define HINIC3_AF5_OUTBOUND_CTRL_SHIFT 0
+#define HINIC3_AF5_OUTBOUND_CTRL_MASK  0x1
+
+#define HINIC3_AF5_GET(val, member) \
+	(((val) >> HINIC3_AF5_##member##_SHIFT) & HINIC3_AF5_##member##_MASK)
+
+#define HINIC3_AF5_SET(val, member) \
+	(((val) & HINIC3_AF5_##member##_MASK) << HINIC3_AF5_##member##_SHIFT)
+
+#define HINIC3_AF5_CLEAR(val, member) \
+	((val) & (~(HINIC3_AF5_##member##_MASK << HINIC3_AF5_##member##_SHIFT)))
+
+#define HINIC3_AF6_PF_STATUS_SHIFT 0
+#define HINIC3_AF6_PF_STATUS_MASK  0xFFFF
+
+#define HINIC3_AF6_FUNC_MAX_QUEUE_SHIFT 23
+#define HINIC3_AF6_FUNC_MAX_QUEUE_MASK	0x1FF
+
+#define HINIC3_AF6_MSIX_FLEX_EN_SHIFT 22
+#define HINIC3_AF6_MSIX_FLEX_EN_MASK  0x1
+
+#define HINIC3_AF6_SET(val, member)                  \
+	((((u32)(val)) & HINIC3_AF6_##member##_MASK) \
+	 << HINIC3_AF6_##member##_SHIFT)
+
+#define HINIC3_AF6_GET(val, member) \
+	(((val) >> HINIC3_AF6_##member##_SHIFT) & HINIC3_AF6_##member##_MASK)
+
+#define HINIC3_AF6_CLEAR(val, member) \
+	((val) & (~(HINIC3_AF6_##member##_MASK << HINIC3_AF6_##member##_SHIFT)))
+
+#define HINIC3_PPF_ELECTION_IDX_SHIFT 0
+
+#define HINIC3_PPF_ELECTION_IDX_MASK 0x3F
+
+#define HINIC3_PPF_ELECTION_SET(val, member)           \
+	(((val) & HINIC3_PPF_ELECTION_##member##_MASK) \
+	 << HINIC3_PPF_ELECTION_##member##_SHIFT)
+
+#define HINIC3_PPF_ELECTION_GET(val, member)               \
+	(((val) >> HINIC3_PPF_ELECTION_##member##_SHIFT) & \
+	 HINIC3_PPF_ELECTION_##member##_MASK)
+
+#define HINIC3_PPF_ELECTION_CLEAR(val, member)          \
+	((val) & (~(HINIC3_PPF_ELECTION_##member##_MASK \
+		    << HINIC3_PPF_ELECTION_##member##_SHIFT)))
+
+#define HINIC3_MPF_ELECTION_IDX_SHIFT 0
+
+#define HINIC3_MPF_ELECTION_IDX_MASK 0x1F
+
+#define HINIC3_MPF_ELECTION_SET(val, member)           \
+	(((val) & HINIC3_MPF_ELECTION_##member##_MASK) \
+	 << HINIC3_MPF_ELECTION_##member##_SHIFT)
+
+#define HINIC3_MPF_ELECTION_GET(val, member)               \
+	(((val) >> HINIC3_MPF_ELECTION_##member##_SHIFT) & \
+	 HINIC3_MPF_ELECTION_##member##_MASK)
+
+#define HINIC3_MPF_ELECTION_CLEAR(val, member)          \
+	((val) & (~(HINIC3_MPF_ELECTION_##member##_MASK \
+		    << HINIC3_MPF_ELECTION_##member##_SHIFT)))
+
+#define HINIC3_GET_REG_FLAG(reg) ((reg) & (~(HINIC3_REGS_FLAG_MASK)))
+
+#define HINIC3_GET_REG_ADDR(reg) ((reg) & (HINIC3_REGS_FLAG_MASK))
+
+#define HINIC3_IS_VF_DEV(pdev) ((pdev)->id.device_id == HINIC3_DEV_ID_VF)
+
+u32
+hinic3_hwif_read_reg(struct hinic3_hwif *hwif, u32 reg)
+{
+	if (HINIC3_GET_REG_FLAG(reg) == HINIC3_MGMT_REGS_FLAG)
+		return be32_to_cpu(rte_read32(hwif->mgmt_regs_base +
+					      HINIC3_GET_REG_ADDR(reg)));
+	else
+		return be32_to_cpu(rte_read32(hwif->cfg_regs_base +
+					      HINIC3_GET_REG_ADDR(reg)));
+}
+
+void
+hinic3_hwif_write_reg(struct hinic3_hwif *hwif, u32 reg, u32 val)
+{
+	if (HINIC3_GET_REG_FLAG(reg) == HINIC3_MGMT_REGS_FLAG)
+		rte_write32(cpu_to_be32(val),
+			    hwif->mgmt_regs_base + HINIC3_GET_REG_ADDR(reg));
+	else
+		rte_write32(cpu_to_be32(val),
+			    hwif->cfg_regs_base + HINIC3_GET_REG_ADDR(reg));
+}
+
+/**
+ * Judge whether HW initialization ok.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+hwif_ready(struct hinic3_hwdev *hwdev)
+{
+	u32 addr, attr1;
+
+	addr = HINIC3_CSR_FUNC_ATTR1_ADDR;
+	attr1 = hinic3_hwif_read_reg(hwdev->hwif, addr);
+	if (attr1 == HINIC3_PCIE_LINK_DOWN)
+		return -EBUSY;
+
+	if (!HINIC3_AF1_GET(attr1, MGMT_INIT_STATUS))
+		return -EBUSY;
+
+	return 0;
+}
+
+static int
+wait_hwif_ready(struct hinic3_hwdev *hwdev)
+{
+	ulong timeout = 0;
+
+	do {
+		if (!hwif_ready(hwdev))
+			return 0;
+
+		rte_delay_ms(1);
+		timeout++;
+	} while (timeout <= WAIT_HWIF_READY_TIMEOUT);
+
+	PMD_DRV_LOG(ERR, "Hwif is not ready");
+	return -EBUSY;
+}
+
+/**
+ * Set the attributes as members in hwif.
+ *
+ * @param[in] hwif
+ * The hardware interface of a pci function device.
+ * @param[in] attr0
+ * The first attribute that was read from the hw.
+ * @param[in] attr1
+ * The second attribute that was read from the hw.
+ * @param[in] attr2
+ * The third attribute that was read from the hw.
+ * @param[in] attr3
+ * The fourth attribute that was read from the hw.
+ */
+static void
+set_hwif_attr(struct hinic3_hwif *hwif, u32 attr0, u32 attr1, u32 attr2,
+	      u32 attr3)
+{
+	hwif->attr.func_global_idx = HINIC3_AF0_GET(attr0, FUNC_GLOBAL_IDX);
+	hwif->attr.port_to_port_idx = HINIC3_AF0_GET(attr0, P2P_IDX);
+	hwif->attr.pci_intf_idx = HINIC3_AF0_GET(attr0, PCI_INTF_IDX);
+	hwif->attr.vf_in_pf = HINIC3_AF0_GET(attr0, VF_IN_PF);
+	hwif->attr.func_type = HINIC3_AF0_GET(attr0, FUNC_TYPE);
+
+	hwif->attr.ppf_idx = HINIC3_AF1_GET(attr1, PPF_IDX);
+	hwif->attr.num_aeqs = BIT(HINIC3_AF1_GET(attr1, AEQS_PER_FUNC));
+
+	hwif->attr.num_ceqs = (u8)HINIC3_AF2_GET(attr2, CEQS_PER_FUNC);
+	hwif->attr.num_irqs = HINIC3_AF2_GET(attr2, IRQS_PER_FUNC);
+	hwif->attr.num_dma_attr = BIT(HINIC3_AF2_GET(attr2, DMA_ATTR_PER_FUNC));
+
+	hwif->attr.global_vf_id_of_pf =
+		HINIC3_AF3_GET(attr3, GLOBAL_VF_ID_OF_PF);
+}
+
+/**
+ * Read and set the attributes as members in hwif.
+ *
+ * @param[in] hwif
+ * The hardware interface of a pci function device.
+ */
+static void
+get_hwif_attr(struct hinic3_hwif *hwif)
+{
+	u32 addr, attr0, attr1, attr2, attr3;
+
+	addr = HINIC3_CSR_FUNC_ATTR0_ADDR;
+	attr0 = hinic3_hwif_read_reg(hwif, addr);
+
+	addr = HINIC3_CSR_FUNC_ATTR1_ADDR;
+	attr1 = hinic3_hwif_read_reg(hwif, addr);
+
+	addr = HINIC3_CSR_FUNC_ATTR2_ADDR;
+	attr2 = hinic3_hwif_read_reg(hwif, addr);
+
+	addr = HINIC3_CSR_FUNC_ATTR3_ADDR;
+	attr3 = hinic3_hwif_read_reg(hwif, addr);
+
+	set_hwif_attr(hwif, attr0, attr1, attr2, attr3);
+}
+
+/**
+ * Update message signaled interrupt information.
+ *
+ * @param[in] hwif
+ * The hardware interface of a pci function device.
+ */
+void
+hinic3_update_msix_info(struct hinic3_hwif *hwif)
+{
+	u32 attr6 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR);
+	hwif->attr.num_queue = HINIC3_AF6_GET(attr6, FUNC_MAX_QUEUE);
+	hwif->attr.msix_flex_en = HINIC3_AF6_GET(attr6, MSIX_FLEX_EN);
+	PMD_DRV_LOG(INFO, "msix_flex_en: %u, queue msix: %u",
+		    hwif->attr.msix_flex_en, hwif->attr.num_queue);
+}
+
+void
+hinic3_set_pf_status(struct hinic3_hwif *hwif, enum hinic3_pf_status status)
+{
+	u32 attr6 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR);
+
+	attr6 = HINIC3_AF6_CLEAR(attr6, PF_STATUS);
+	attr6 |= HINIC3_AF6_SET(status, PF_STATUS);
+
+	if (hwif->attr.func_type == TYPE_VF)
+		return;
+
+	hinic3_hwif_write_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR, attr6);
+}
+
+enum hinic3_pf_status
+hinic3_get_pf_status(struct hinic3_hwif *hwif)
+{
+	u32 attr6 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR);
+
+	return HINIC3_AF6_GET(attr6, PF_STATUS);
+}
+
+static enum hinic3_doorbell_ctrl
+hinic3_get_doorbell_ctrl_status(struct hinic3_hwif *hwif)
+{
+	u32 attr4 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR4_ADDR);
+
+	return HINIC3_AF4_GET(attr4, DOORBELL_CTRL);
+}
+
+static enum hinic3_outbound_ctrl
+hinic3_get_outbound_ctrl_status(struct hinic3_hwif *hwif)
+{
+	u32 attr5 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR5_ADDR);
+
+	return HINIC3_AF5_GET(attr5, OUTBOUND_CTRL);
+}
+
+void
+hinic3_enable_doorbell(struct hinic3_hwif *hwif)
+{
+	u32 addr, attr4;
+
+	addr = HINIC3_CSR_FUNC_ATTR4_ADDR;
+	attr4 = hinic3_hwif_read_reg(hwif, addr);
+
+	attr4 = HINIC3_AF4_CLEAR(attr4, DOORBELL_CTRL);
+	attr4 |= HINIC3_AF4_SET(ENABLE_DOORBELL, DOORBELL_CTRL);
+
+	hinic3_hwif_write_reg(hwif, addr, attr4);
+}
+
+void
+hinic3_disable_doorbell(struct hinic3_hwif *hwif)
+{
+	u32 addr, attr4;
+
+	addr = HINIC3_CSR_FUNC_ATTR4_ADDR;
+	attr4 = hinic3_hwif_read_reg(hwif, addr);
+
+	attr4 = HINIC3_AF4_CLEAR(attr4, DOORBELL_CTRL);
+	attr4 |= HINIC3_AF4_SET(DISABLE_DOORBELL, DOORBELL_CTRL);
+
+	hinic3_hwif_write_reg(hwif, addr, attr4);
+}
+
+/**
+ * Try to set hwif as ppf and set the type of hwif in this case.
+ *
+ * @param[in] hwif
+ * The hardware interface of a pci function device
+ */
+static void
+set_ppf(struct hinic3_hwif *hwif)
+{
+	struct hinic3_func_attr *attr = &hwif->attr;
+	u32 addr, val, ppf_election;
+
+	addr = HINIC3_CSR_PPF_ELECTION_ADDR;
+
+	val = hinic3_hwif_read_reg(hwif, addr);
+	val = HINIC3_PPF_ELECTION_CLEAR(val, IDX);
+
+	ppf_election = HINIC3_PPF_ELECTION_SET(attr->func_global_idx, IDX);
+	val |= ppf_election;
+
+	hinic3_hwif_write_reg(hwif, addr, val);
+
+	/* Check PPF. */
+	val = hinic3_hwif_read_reg(hwif, addr);
+
+	attr->ppf_idx = HINIC3_PPF_ELECTION_GET(val, IDX);
+	if (attr->ppf_idx == attr->func_global_idx)
+		attr->func_type = TYPE_PPF;
+}
+
+/**
+ * Get the mpf index from the hwif.
+ *
+ * @param[in] hwif
+ * The hardware interface of a pci function device.
+ */
+static void
+get_mpf(struct hinic3_hwif *hwif)
+{
+	struct hinic3_func_attr *attr = &hwif->attr;
+	u32 mpf_election, addr;
+
+	addr = HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR;
+
+	mpf_election = hinic3_hwif_read_reg(hwif, addr);
+	attr->mpf_idx = HINIC3_MPF_ELECTION_GET(mpf_election, IDX);
+}
+
+/**
+ * Try to set hwif as mpf and set the mpf idx in hwif.
+ *
+ * @param[in] hwif
+ * The hardware interface of a pci function device.
+ */
+static void
+set_mpf(struct hinic3_hwif *hwif)
+{
+	struct hinic3_func_attr *attr = &hwif->attr;
+	u32 addr, val, mpf_election;
+
+	addr = HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR;
+
+	val = hinic3_hwif_read_reg(hwif, addr);
+
+	val = HINIC3_MPF_ELECTION_CLEAR(val, IDX);
+	mpf_election = HINIC3_MPF_ELECTION_SET(attr->func_global_idx, IDX);
+
+	val |= mpf_election;
+	hinic3_hwif_write_reg(hwif, addr, val);
+}
+
+int
+hinic3_alloc_db_addr(void *hwdev, void **db_base,
+		     enum hinic3_db_type queue_type)
+{
+	struct hinic3_hwif *hwif = NULL;
+
+	if (!hwdev || !db_base)
+		return -EINVAL;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+	*db_base = hwif->db_base + queue_type * HINIC3_DB_PAGE_SIZE;
+
+	return 0;
+}
+
+void
+hinic3_set_msix_auto_mask_state(void *hwdev, u16 msix_idx,
+				enum hinic3_msix_auto_mask flag)
+{
+	struct hinic3_hwif *hwif = NULL;
+	u32 mask_bits;
+	u32 addr;
+
+	if (!hwdev)
+		return;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	if (flag)
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(1, AUTO_MSK_SET);
+	else
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(1, AUTO_MSK_CLR);
+
+	mask_bits = mask_bits |
+		    HINIC3_MSI_CLR_INDIR_SET(msix_idx, SIMPLE_INDIR_IDX);
+
+	addr = HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR;
+	hinic3_hwif_write_reg(hwif, addr, mask_bits);
+}
+
+/**
+ * Set msix state.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device object.
+ * @param[in] msix_idx
+ * MSIX(Message Signaled Interrupts) index.
+ * @param[in] flag
+ * MSIX state flag, 0-enable, 1-disable.
+ */
+void
+hinic3_set_msix_state(void *hwdev, u16 msix_idx, enum hinic3_msix_state flag)
+{
+	struct hinic3_hwif *hwif = NULL;
+	u32 mask_bits;
+	u32 addr;
+	u8 int_msk = 1;
+
+	if (!hwdev)
+		return;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	if (flag)
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(int_msk, INT_MSK_SET);
+	else
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(int_msk, INT_MSK_CLR);
+	mask_bits = mask_bits |
+		    HINIC3_MSI_CLR_INDIR_SET(msix_idx, SIMPLE_INDIR_IDX);
+
+	addr = HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR;
+	hinic3_hwif_write_reg(hwif, addr, mask_bits);
+}
+
+static void
+disable_all_msix(struct hinic3_hwdev *hwdev)
+{
+	u16 num_irqs = hwdev->hwif->attr.num_irqs;
+	u16 i;
+
+	for (i = 0; i < num_irqs; i++)
+		hinic3_set_msix_state(hwdev, i, HINIC3_MSIX_DISABLE);
+}
+
+/**
+ * Clear msix resend bit.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device object.
+ * @param[in] msix_idx
+ * MSIX(Message Signaled Interrupts) index
+ * @param[in] clear_resend_en
+ * Clear resend en flag, 1-clear.
+ */
+void
+hinic3_misx_intr_clear_resend_bit(void *hwdev, u16 msix_idx, u8 clear_resend_en)
+{
+	struct hinic3_hwif *hwif = NULL;
+	u32 msix_ctrl = 0, addr;
+
+	if (!hwdev)
+		return;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	msix_ctrl = HINIC3_MSI_CLR_INDIR_SET(msix_idx, SIMPLE_INDIR_IDX) |
+		    HINIC3_MSI_CLR_INDIR_SET(clear_resend_en, RESEND_TIMER_CLR);
+
+	addr = HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR;
+	hinic3_hwif_write_reg(hwif, addr, msix_ctrl);
+}
+
+#ifdef HINIC3_RELEASE
+static int
+wait_until_doorbell_flush_states(struct hinic3_hwif *hwif,
+				 enum hinic3_doorbell_ctrl states)
+{
+	enum hinic3_doorbell_ctrl db_ctrl;
+	u32 cnt = 0;
+
+	if (!hwif)
+		return -EINVAL;
+
+	while (cnt < HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT) {
+		db_ctrl = hinic3_get_doorbell_ctrl_status(hwif);
+		if (db_ctrl == states)
+			return 0;
+
+		rte_delay_ms(1);
+		cnt++;
+	}
+
+	return -EFAULT;
+}
+#endif
+
+static int
+wait_until_doorbell_and_outbound_enabled(struct hinic3_hwif *hwif)
+{
+	enum hinic3_doorbell_ctrl db_ctrl;
+	enum hinic3_outbound_ctrl outbound_ctrl;
+	u32 cnt = 0;
+
+	while (cnt < HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT) {
+		db_ctrl = hinic3_get_doorbell_ctrl_status(hwif);
+		outbound_ctrl = hinic3_get_outbound_ctrl_status(hwif);
+		if (outbound_ctrl == ENABLE_OUTBOUND &&
+		    db_ctrl == ENABLE_DOORBELL)
+			return 0;
+
+		rte_delay_ms(1);
+		cnt++;
+	}
+
+	return -EFAULT;
+}
+
+static int
+hinic3_get_bar_addr(struct hinic3_hwdev *hwdev)
+{
+	struct rte_pci_device *pci_dev = hwdev->pci_dev;
+	struct hinic3_hwif *hwif = hwdev->hwif;
+	void *cfg_regs_base = NULL;
+	void *mgmt_reg_base = NULL;
+	void *db_base = NULL;
+	int cfg_bar;
+
+	cfg_bar = HINIC3_IS_VF_DEV(pci_dev) ? HINIC3_VF_PCI_CFG_REG_BAR
+					    : HINIC3_PF_PCI_CFG_REG_BAR;
+
+	cfg_regs_base = pci_dev->mem_resource[cfg_bar].addr;
+	if (!HINIC3_IS_VF_DEV(pci_dev)) {
+		mgmt_reg_base =
+			pci_dev->mem_resource[HINIC3_PCI_MGMT_REG_BAR].addr;
+		if (mgmt_reg_base == NULL) {
+			PMD_DRV_LOG(ERR, "mgmt_reg_base addr is null");
+			return -EFAULT;
+		}
+	}
+	db_base = pci_dev->mem_resource[HINIC3_PCI_DB_BAR].addr;
+	if (cfg_regs_base == NULL) {
+		PMD_DRV_LOG(ERR,
+			    "mem_resource addr is null, cfg_regs_base is NULL");
+		return -EFAULT;
+	} else if (db_base == NULL) {
+		PMD_DRV_LOG(ERR, "mem_resource addr is null, db_base is NULL");
+		return -EFAULT;
+	}
+
+	/* If function is VF, mgmt_regs_base will be NULL. */
+	if (!mgmt_reg_base)
+		hwif->cfg_regs_base =
+			(u8 *)cfg_regs_base + HINIC3_VF_CFG_REG_OFFSET;
+	else
+		hwif->cfg_regs_base = cfg_regs_base;
+	hwif->mgmt_regs_base = mgmt_reg_base;
+	hwif->db_base = db_base;
+	hwif->db_dwqe_len = pci_dev->mem_resource[HINIC3_PCI_DB_BAR].len;
+
+	return 0;
+}
+
+/**
+ * Initialize the hw interface.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device object.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+int
+hinic3_init_hwif(void *dev)
+{
+	struct hinic3_hwdev *hwdev = NULL;
+	struct hinic3_hwif *hwif;
+	int err;
+	u32 attr4, attr5;
+
+	hwif = rte_zmalloc("hinic_hwif", sizeof(struct hinic3_hwif),
+			   RTE_CACHE_LINE_SIZE);
+	if (!hwif)
+		return -ENOMEM;
+
+	hwdev = (struct hinic3_hwdev *)dev;
+	hwdev->hwif = hwif;
+
+	err = hinic3_get_bar_addr(hwdev);
+	if (err != 0) {
+		PMD_DRV_LOG(ERR, "get bar addr fail");
+		goto hwif_ready_err;
+	}
+
+	err = wait_hwif_ready(hwdev);
+	if (err != 0) {
+		PMD_DRV_LOG(ERR, "Chip status is not ready");
+		goto hwif_ready_err;
+	}
+
+	get_hwif_attr(hwif);
+
+	err = wait_until_doorbell_and_outbound_enabled(hwif);
+	if (err != 0) {
+		attr4 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR4_ADDR);
+		attr5 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR5_ADDR);
+		PMD_DRV_LOG(ERR,
+			    "Hw doorbell/outbound is disabled, attr4 0x%x "
+			    "attr5 0x%x",
+			    attr4, attr5);
+		goto hwif_ready_err;
+	}
+
+	if (!HINIC3_IS_VF(hwdev)) {
+		set_ppf(hwif);
+
+		if (HINIC3_IS_PPF(hwdev))
+			set_mpf(hwif);
+
+		get_mpf(hwif);
+	}
+
+	disable_all_msix(hwdev);
+	/* Disable mgmt cpu reporting any event. */
+	hinic3_set_pf_status(hwdev->hwif, HINIC3_PF_STATUS_INIT);
+
+	PMD_DRV_LOG(INFO,
+		    "global_func_idx: %d, func_type: %d, host_id: %d, ppf: %d, "
+		    "mpf: %d",
+		    hwif->attr.func_global_idx, hwif->attr.func_type,
+		    hwif->attr.pci_intf_idx, hwif->attr.ppf_idx,
+		    hwif->attr.mpf_idx);
+
+	return 0;
+
+hwif_ready_err:
+	rte_free(hwdev->hwif);
+	hwdev->hwif = NULL;
+
+	return err;
+}
+
+/**
+ * Free the hw interface.
+ *
+ * @param[in] dev
+ * The pointer to the private hardware device.
+ */
+void
+hinic3_free_hwif(void *dev)
+{
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
+
+	rte_free(hwdev->hwif);
+}
+
+u16
+hinic3_global_func_id(void *hwdev)
+{
+	struct hinic3_hwif *hwif = NULL;
+
+	if (!hwdev)
+		return 0;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	return hwif->attr.func_global_idx;
+}
+
+u8
+hinic3_pf_id_of_vf(void *hwdev)
+{
+	struct hinic3_hwif *hwif = NULL;
+
+	if (!hwdev)
+		return 0;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	return hwif->attr.port_to_port_idx;
+}
+
+u8
+hinic3_pcie_itf_id(void *hwdev)
+{
+	struct hinic3_hwif *hwif = NULL;
+
+	if (!hwdev)
+		return 0;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	return hwif->attr.pci_intf_idx;
+}
+
+enum func_type
+hinic3_func_type(void *hwdev)
+{
+	struct hinic3_hwif *hwif = NULL;
+
+	if (!hwdev)
+		return 0;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	return hwif->attr.func_type;
+}
+
+u16
+hinic3_glb_pf_vf_offset(void *hwdev)
+{
+	struct hinic3_hwif *hwif = NULL;
+
+	if (!hwdev)
+		return 0;
+
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
+
+	return hwif->attr.global_vf_id_of_pf;
+}
drivers/net/hinic3/base/hinic3_hwif.h new file +142 -0

142 lines not on this page · raw message

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

Re: [V5 03/18] net/hinic3: add hardware interfaces of BAR operation

Quoted 15 lines · Feifei Wang

From: Yi Chen <[email protected]>

This patch adds some HW interfaces for bar operatioin interfaces,

including: mapped bar address geeting, HW attributes getting,

msi-x reg operation, function type getting and so on.

Quoted 7 lines

---

 drivers/net/hinic3/base/hinic3_hwif.c | 779 ++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_hwif.h | 142 +++++

Since have c source file, suggest add meson.build, then could compile this drivers. And also update the MAINTAINER files (this should do in 02/18 commit).

Quoted 418 lines
 2 files changed, 921 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwif.h
drivers/net/hinic3/base/hinic3_hwif.c +0 -0

new file mode 100644

index 0000000000..ede4aa311f

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_hwif.c

drivers/net/hinic3/base/hinic3_hwif.c +199 -0
@@ -0,0 +1,779 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#include <rte_bus_pci.h>
 
+#include "hinic3_compat.h"
 
+#include "hinic3_csr.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_hwif.h"
 
+
 
+#define WAIT_HWIF_READY_TIMEOUT 10000
 
+
 
+#define DB_IDX(db, db_base) \
 
+	((u32)(((ulong)(db) - (ulong)(db_base)) / HINIC3_DB_PAGE_SIZE))
 
+
 
+#define HINIC3_AF0_FUNC_GLOBAL_IDX_SHIFT 0
 
+#define HINIC3_AF0_P2P_IDX_SHIFT	 12
 
+#define HINIC3_AF0_PCI_INTF_IDX_SHIFT	 17
 
+#define HINIC3_AF0_VF_IN_PF_SHIFT	 20
 
+#define HINIC3_AF0_FUNC_TYPE_SHIFT	 28
 
+
 
+#define HINIC3_AF0_FUNC_GLOBAL_IDX_MASK 0xFFF
 
+#define HINIC3_AF0_P2P_IDX_MASK		0x1F
 
+#define HINIC3_AF0_PCI_INTF_IDX_MASK	0x7
 
+#define HINIC3_AF0_VF_IN_PF_MASK	0xFF
 
+#define HINIC3_AF0_FUNC_TYPE_MASK	0x1
 
+
 
+#define HINIC3_AF0_GET(val, member) \
 
+	(((val) >> HINIC3_AF0_##member##_SHIFT) & HINIC3_AF0_##member##_MASK)
 
+
 
+#define HINIC3_AF1_PPF_IDX_SHIFT	  0
 
+#define HINIC3_AF1_AEQS_PER_FUNC_SHIFT	  8
 
+#define HINIC3_AF1_MGMT_INIT_STATUS_SHIFT 30
 
+#define HINIC3_AF1_PF_INIT_STATUS_SHIFT	  31
 
+
 
+#define HINIC3_AF1_PPF_IDX_MASK		 0x3F
 
+#define HINIC3_AF1_AEQS_PER_FUNC_MASK	 0x3
 
+#define HINIC3_AF1_MGMT_INIT_STATUS_MASK 0x1
 
+#define HINIC3_AF1_PF_INIT_STATUS_MASK	 0x1
 
+
 
+#define HINIC3_AF1_GET(val, member) \
 
+	(((val) >> HINIC3_AF1_##member##_SHIFT) & HINIC3_AF1_##member##_MASK)
 
+
 
+#define HINIC3_AF2_CEQS_PER_FUNC_SHIFT	   0
 
+#define HINIC3_AF2_DMA_ATTR_PER_FUNC_SHIFT 9
 
+#define HINIC3_AF2_IRQS_PER_FUNC_SHIFT	   16
 
+
 
+#define HINIC3_AF2_CEQS_PER_FUNC_MASK	  0x1FF
 
+#define HINIC3_AF2_DMA_ATTR_PER_FUNC_MASK 0x7
 
+#define HINIC3_AF2_IRQS_PER_FUNC_MASK	  0x7FF
 
+
 
+#define HINIC3_AF2_GET(val, member) \
 
+	(((val) >> HINIC3_AF2_##member##_SHIFT) & HINIC3_AF2_##member##_MASK)
 
+
 
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_NXT_PF_SHIFT 0
 
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_PF_SHIFT	16
 
+
 
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_NXT_PF_MASK 0xFFF
 
+#define HINIC3_AF3_GLOBAL_VF_ID_OF_PF_MASK     0xFFF
 
+
 
+#define HINIC3_AF3_GET(val, member) \
 
+	(((val) >> HINIC3_AF3_##member##_SHIFT) & HINIC3_AF3_##member##_MASK)
 
+
 
+#define HINIC3_AF4_DOORBELL_CTRL_SHIFT 0
 
+#define HINIC3_AF4_DOORBELL_CTRL_MASK  0x1
 
+
 
+#define HINIC3_AF4_GET(val, member) \
 
+	(((val) >> HINIC3_AF4_##member##_SHIFT) & HINIC3_AF4_##member##_MASK)
 
+
 
+#define HINIC3_AF4_SET(val, member) \
 
+	(((val) & HINIC3_AF4_##member##_MASK) << HINIC3_AF4_##member##_SHIFT)
 
+
 
+#define HINIC3_AF4_CLEAR(val, member) \
 
+	((val) & (~(HINIC3_AF4_##member##_MASK << HINIC3_AF4_##member##_SHIFT)))
 
+
 
+#define HINIC3_AF5_OUTBOUND_CTRL_SHIFT 0
 
+#define HINIC3_AF5_OUTBOUND_CTRL_MASK  0x1
 
+
 
+#define HINIC3_AF5_GET(val, member) \
 
+	(((val) >> HINIC3_AF5_##member##_SHIFT) & HINIC3_AF5_##member##_MASK)
 
+
 
+#define HINIC3_AF5_SET(val, member) \
 
+	(((val) & HINIC3_AF5_##member##_MASK) << HINIC3_AF5_##member##_SHIFT)
 
+
 
+#define HINIC3_AF5_CLEAR(val, member) \
 
+	((val) & (~(HINIC3_AF5_##member##_MASK << HINIC3_AF5_##member##_SHIFT)))
 
+
 
+#define HINIC3_AF6_PF_STATUS_SHIFT 0
 
+#define HINIC3_AF6_PF_STATUS_MASK  0xFFFF
 
+
 
+#define HINIC3_AF6_FUNC_MAX_QUEUE_SHIFT 23
 
+#define HINIC3_AF6_FUNC_MAX_QUEUE_MASK	0x1FF
 
+
 
+#define HINIC3_AF6_MSIX_FLEX_EN_SHIFT 22
 
+#define HINIC3_AF6_MSIX_FLEX_EN_MASK  0x1
 
+
 
+#define HINIC3_AF6_SET(val, member)                  \
 
+	((((u32)(val)) & HINIC3_AF6_##member##_MASK) \
 
+	 << HINIC3_AF6_##member##_SHIFT)
 
+
 
+#define HINIC3_AF6_GET(val, member) \
 
+	(((val) >> HINIC3_AF6_##member##_SHIFT) & HINIC3_AF6_##member##_MASK)
 
+
 
+#define HINIC3_AF6_CLEAR(val, member) \
 
+	((val) & (~(HINIC3_AF6_##member##_MASK << HINIC3_AF6_##member##_SHIFT)))
 
+
 
+#define HINIC3_PPF_ELECTION_IDX_SHIFT 0
 
+
 
+#define HINIC3_PPF_ELECTION_IDX_MASK 0x3F
 
+
 
+#define HINIC3_PPF_ELECTION_SET(val, member)           \
 
+	(((val) & HINIC3_PPF_ELECTION_##member##_MASK) \
 
+	 << HINIC3_PPF_ELECTION_##member##_SHIFT)
 
+
 
+#define HINIC3_PPF_ELECTION_GET(val, member)               \
 
+	(((val) >> HINIC3_PPF_ELECTION_##member##_SHIFT) & \
 
+	 HINIC3_PPF_ELECTION_##member##_MASK)
 
+
 
+#define HINIC3_PPF_ELECTION_CLEAR(val, member)          \
 
+	((val) & (~(HINIC3_PPF_ELECTION_##member##_MASK \
 
+		    << HINIC3_PPF_ELECTION_##member##_SHIFT)))
 
+
 
+#define HINIC3_MPF_ELECTION_IDX_SHIFT 0
 
+
 
+#define HINIC3_MPF_ELECTION_IDX_MASK 0x1F
 
+
 
+#define HINIC3_MPF_ELECTION_SET(val, member)           \
 
+	(((val) & HINIC3_MPF_ELECTION_##member##_MASK) \
 
+	 << HINIC3_MPF_ELECTION_##member##_SHIFT)
 
+
 
+#define HINIC3_MPF_ELECTION_GET(val, member)               \
 
+	(((val) >> HINIC3_MPF_ELECTION_##member##_SHIFT) & \
 
+	 HINIC3_MPF_ELECTION_##member##_MASK)
 
+
 
+#define HINIC3_MPF_ELECTION_CLEAR(val, member)          \
 
+	((val) & (~(HINIC3_MPF_ELECTION_##member##_MASK \
 
+		    << HINIC3_MPF_ELECTION_##member##_SHIFT)))
 
+
 
+#define HINIC3_GET_REG_FLAG(reg) ((reg) & (~(HINIC3_REGS_FLAG_MASK)))
 
+
 
+#define HINIC3_GET_REG_ADDR(reg) ((reg) & (HINIC3_REGS_FLAG_MASK))
 
+
 
+#define HINIC3_IS_VF_DEV(pdev) ((pdev)->id.device_id == HINIC3_DEV_ID_VF)
 
+
 
+u32
 
+hinic3_hwif_read_reg(struct hinic3_hwif *hwif, u32 reg)
 
+{
 
+	if (HINIC3_GET_REG_FLAG(reg) == HINIC3_MGMT_REGS_FLAG)
 
+		return be32_to_cpu(rte_read32(hwif->mgmt_regs_base +
 
+					      HINIC3_GET_REG_ADDR(reg)));
 
+	else
 
+		return be32_to_cpu(rte_read32(hwif->cfg_regs_base +
 
+					      HINIC3_GET_REG_ADDR(reg)));
 
+}
 
+
 
+void
 
+hinic3_hwif_write_reg(struct hinic3_hwif *hwif, u32 reg, u32 val)
 
+{
 
+	if (HINIC3_GET_REG_FLAG(reg) == HINIC3_MGMT_REGS_FLAG)
 
+		rte_write32(cpu_to_be32(val),
 
+			    hwif->mgmt_regs_base + HINIC3_GET_REG_ADDR(reg));
 
+	else
 
+		rte_write32(cpu_to_be32(val),
 
+			    hwif->cfg_regs_base + HINIC3_GET_REG_ADDR(reg));
 
+}
 
+
 
+/**
 
+ * Judge whether HW initialization ok.
 
+ *
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device.
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+hwif_ready(struct hinic3_hwdev *hwdev)
 
+{
 
+	u32 addr, attr1;
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR1_ADDR;
 
+	attr1 = hinic3_hwif_read_reg(hwdev->hwif, addr);
 
+	if (attr1 == HINIC3_PCIE_LINK_DOWN)
 
+		return -EBUSY;
 
+
 
+	if (!HINIC3_AF1_GET(attr1, MGMT_INIT_STATUS))
 
+		return -EBUSY;
 
+
 
+	return 0;
 
+}
 
+
 
+static int
 
+wait_hwif_ready(struct hinic3_hwdev *hwdev)
 
+{
 
+	ulong timeout = 0;
 
+
 
+	do {
 
+		if (!hwif_ready(hwdev))
 
+			return 0;
 
+

drivers/net/hinic3/base/hinic3_hwif.c line 204

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+		rte_delay_ms(1);
 
+		timeout++;
 
+	} while (timeout <= WAIT_HWIF_READY_TIMEOUT);
 
+
 
+	PMD_DRV_LOG(ERR, "Hwif is not ready");

The PMD_DRV_LOG will don't show which device, suggest wrap the PMD_DRV_LOG and pass hwdev as a paramenter.

Quoted 24 lines
drivers/net/hinic3/base/hinic3_hwif.c +12 -0
+	return -EBUSY;
 
+}
 
+
 
+/**
 
+ * Set the attributes as members in hwif.
 
+ *
 
+ * @param[in] hwif
 
+ * The hardware interface of a pci function device.
 
+ * @param[in] attr0
 
+ * The first attribute that was read from the hw.
 
+ * @param[in] attr1
 
+ * The second attribute that was read from the hw.

drivers/net/hinic3/base/hinic3_hwif.c line 221

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+ * @param[in] attr2
 
+ * The third attribute that was read from the hw.
 
+ * @param[in] attr3
 
+ * The fourth attribute that was read from the hw.
 
+ */

It seem the above comment don't provide any usage information.

Quoted 48 lines
drivers/net/hinic3/base/hinic3_hwif.c +24 -0
+static void
 
+set_hwif_attr(struct hinic3_hwif *hwif, u32 attr0, u32 attr1, u32 attr2,
 
+	      u32 attr3)
 
+{
 
+	hwif->attr.func_global_idx = HINIC3_AF0_GET(attr0, FUNC_GLOBAL_IDX);
 
+	hwif->attr.port_to_port_idx = HINIC3_AF0_GET(attr0, P2P_IDX);
 
+	hwif->attr.pci_intf_idx = HINIC3_AF0_GET(attr0, PCI_INTF_IDX);
 
+	hwif->attr.vf_in_pf = HINIC3_AF0_GET(attr0, VF_IN_PF);
 
+	hwif->attr.func_type = HINIC3_AF0_GET(attr0, FUNC_TYPE);
 
+
 
+	hwif->attr.ppf_idx = HINIC3_AF1_GET(attr1, PPF_IDX);
 
+	hwif->attr.num_aeqs = BIT(HINIC3_AF1_GET(attr1, AEQS_PER_FUNC));
 
+
 
+	hwif->attr.num_ceqs = (u8)HINIC3_AF2_GET(attr2, CEQS_PER_FUNC);
 
+	hwif->attr.num_irqs = HINIC3_AF2_GET(attr2, IRQS_PER_FUNC);
 
+	hwif->attr.num_dma_attr = BIT(HINIC3_AF2_GET(attr2, DMA_ATTR_PER_FUNC));
 
+
 
+	hwif->attr.global_vf_id_of_pf =
 
+		HINIC3_AF3_GET(attr3, GLOBAL_VF_ID_OF_PF);
 
+}
 
+
 
+/**
 
+ * Read and set the attributes as members in hwif.
 
+ *

drivers/net/hinic3/base/hinic3_hwif.c line 250

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+ * @param[in] hwif
 
+ * The hardware interface of a pci function device.
 
+ */
 
+static void
 
+get_hwif_attr(struct hinic3_hwif *hwif)

this function do get and set, but the function name don't reflect this.

Quoted 700 lines
drivers/net/hinic3/base/hinic3_hwif.c +350 -0
+{
 
+	u32 addr, attr0, attr1, attr2, attr3;
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR0_ADDR;
 
+	attr0 = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR1_ADDR;
 
+	attr1 = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR2_ADDR;
 
+	attr2 = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR3_ADDR;
 
+	attr3 = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	set_hwif_attr(hwif, attr0, attr1, attr2, attr3);
 
+}
 
+
 
+/**
 
+ * Update message signaled interrupt information.
 
+ *
 
+ * @param[in] hwif
 
+ * The hardware interface of a pci function device.
 
+ */
 
+void
 
+hinic3_update_msix_info(struct hinic3_hwif *hwif)
 
+{
 
+	u32 attr6 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR);
 
+	hwif->attr.num_queue = HINIC3_AF6_GET(attr6, FUNC_MAX_QUEUE);
 
+	hwif->attr.msix_flex_en = HINIC3_AF6_GET(attr6, MSIX_FLEX_EN);
 
+	PMD_DRV_LOG(INFO, "msix_flex_en: %u, queue msix: %u",
 
+		    hwif->attr.msix_flex_en, hwif->attr.num_queue);
 
+}
 
+
 
+void
 
+hinic3_set_pf_status(struct hinic3_hwif *hwif, enum hinic3_pf_status status)
 
+{
 
+	u32 attr6 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR);
 
+
 
+	attr6 = HINIC3_AF6_CLEAR(attr6, PF_STATUS);
 
+	attr6 |= HINIC3_AF6_SET(status, PF_STATUS);
 
+
 
+	if (hwif->attr.func_type == TYPE_VF)
 
+		return;
 
+
 
+	hinic3_hwif_write_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR, attr6);
 
+}
 
+
 
+enum hinic3_pf_status
 
+hinic3_get_pf_status(struct hinic3_hwif *hwif)
 
+{
 
+	u32 attr6 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR6_ADDR);
 
+
 
+	return HINIC3_AF6_GET(attr6, PF_STATUS);
 
+}
 
+
 
+static enum hinic3_doorbell_ctrl
 
+hinic3_get_doorbell_ctrl_status(struct hinic3_hwif *hwif)
 
+{
 
+	u32 attr4 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR4_ADDR);
 
+
 
+	return HINIC3_AF4_GET(attr4, DOORBELL_CTRL);
 
+}
 
+
 
+static enum hinic3_outbound_ctrl
 
+hinic3_get_outbound_ctrl_status(struct hinic3_hwif *hwif)
 
+{
 
+	u32 attr5 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR5_ADDR);
 
+
 
+	return HINIC3_AF5_GET(attr5, OUTBOUND_CTRL);
 
+}
 
+
 
+void
 
+hinic3_enable_doorbell(struct hinic3_hwif *hwif)
 
+{
 
+	u32 addr, attr4;
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR4_ADDR;
 
+	attr4 = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	attr4 = HINIC3_AF4_CLEAR(attr4, DOORBELL_CTRL);
 
+	attr4 |= HINIC3_AF4_SET(ENABLE_DOORBELL, DOORBELL_CTRL);
 
+
 
+	hinic3_hwif_write_reg(hwif, addr, attr4);
 
+}
 
+
 
+void
 
+hinic3_disable_doorbell(struct hinic3_hwif *hwif)
 
+{
 
+	u32 addr, attr4;
 
+
 
+	addr = HINIC3_CSR_FUNC_ATTR4_ADDR;
 
+	attr4 = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	attr4 = HINIC3_AF4_CLEAR(attr4, DOORBELL_CTRL);
 
+	attr4 |= HINIC3_AF4_SET(DISABLE_DOORBELL, DOORBELL_CTRL);
 
+
 
+	hinic3_hwif_write_reg(hwif, addr, attr4);
 
+}
 
+
 
+/**
 
+ * Try to set hwif as ppf and set the type of hwif in this case.
 
+ *
 
+ * @param[in] hwif
 
+ * The hardware interface of a pci function device
 
+ */
 
+static void
 
+set_ppf(struct hinic3_hwif *hwif)
 
+{
 
+	struct hinic3_func_attr *attr = &hwif->attr;
 
+	u32 addr, val, ppf_election;
 
+
 
+	addr = HINIC3_CSR_PPF_ELECTION_ADDR;
 
+
 
+	val = hinic3_hwif_read_reg(hwif, addr);
 
+	val = HINIC3_PPF_ELECTION_CLEAR(val, IDX);
 
+
 
+	ppf_election = HINIC3_PPF_ELECTION_SET(attr->func_global_idx, IDX);
 
+	val |= ppf_election;
 
+
 
+	hinic3_hwif_write_reg(hwif, addr, val);
 
+
 
+	/* Check PPF. */
 
+	val = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	attr->ppf_idx = HINIC3_PPF_ELECTION_GET(val, IDX);
 
+	if (attr->ppf_idx == attr->func_global_idx)
 
+		attr->func_type = TYPE_PPF;
 
+}
 
+
 
+/**
 
+ * Get the mpf index from the hwif.
 
+ *
 
+ * @param[in] hwif
 
+ * The hardware interface of a pci function device.
 
+ */
 
+static void
 
+get_mpf(struct hinic3_hwif *hwif)
 
+{
 
+	struct hinic3_func_attr *attr = &hwif->attr;
 
+	u32 mpf_election, addr;
 
+
 
+	addr = HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR;
 
+
 
+	mpf_election = hinic3_hwif_read_reg(hwif, addr);
 
+	attr->mpf_idx = HINIC3_MPF_ELECTION_GET(mpf_election, IDX);
 
+}
 
+
 
+/**
 
+ * Try to set hwif as mpf and set the mpf idx in hwif.
 
+ *
 
+ * @param[in] hwif
 
+ * The hardware interface of a pci function device.
 
+ */
 
+static void
 
+set_mpf(struct hinic3_hwif *hwif)
 
+{
 
+	struct hinic3_func_attr *attr = &hwif->attr;
 
+	u32 addr, val, mpf_election;
 
+
 
+	addr = HINIC3_CSR_GLOBAL_MPF_ELECTION_ADDR;
 
+
 
+	val = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	val = HINIC3_MPF_ELECTION_CLEAR(val, IDX);
 
+	mpf_election = HINIC3_MPF_ELECTION_SET(attr->func_global_idx, IDX);
 
+
 
+	val |= mpf_election;
 
+	hinic3_hwif_write_reg(hwif, addr, val);
 
+}
 
+
 
+int
 
+hinic3_alloc_db_addr(void *hwdev, void **db_base,
 
+		     enum hinic3_db_type queue_type)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+
 
+	if (!hwdev || !db_base)
 
+		return -EINVAL;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+	*db_base = hwif->db_base + queue_type * HINIC3_DB_PAGE_SIZE;
 
+
 
+	return 0;
 
+}
 
+
 
+void
 
+hinic3_set_msix_auto_mask_state(void *hwdev, u16 msix_idx,
 
+				enum hinic3_msix_auto_mask flag)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+	u32 mask_bits;
 
+	u32 addr;
 
+
 
+	if (!hwdev)
 
+		return;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	if (flag)
 
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(1, AUTO_MSK_SET);
 
+	else
 
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(1, AUTO_MSK_CLR);
 
+
 
+	mask_bits = mask_bits |
 
+		    HINIC3_MSI_CLR_INDIR_SET(msix_idx, SIMPLE_INDIR_IDX);
 
+
 
+	addr = HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR;
 
+	hinic3_hwif_write_reg(hwif, addr, mask_bits);
 
+}
 
+
 
+/**
 
+ * Set msix state.
 
+ *
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device object.
 
+ * @param[in] msix_idx
 
+ * MSIX(Message Signaled Interrupts) index.
 
+ * @param[in] flag
 
+ * MSIX state flag, 0-enable, 1-disable.
 
+ */
 
+void
 
+hinic3_set_msix_state(void *hwdev, u16 msix_idx, enum hinic3_msix_state flag)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+	u32 mask_bits;
 
+	u32 addr;
 
+	u8 int_msk = 1;
 
+
 
+	if (!hwdev)
 
+		return;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	if (flag)
 
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(int_msk, INT_MSK_SET);
 
+	else
 
+		mask_bits = HINIC3_MSI_CLR_INDIR_SET(int_msk, INT_MSK_CLR);
 
+	mask_bits = mask_bits |
 
+		    HINIC3_MSI_CLR_INDIR_SET(msix_idx, SIMPLE_INDIR_IDX);
 
+
 
+	addr = HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR;
 
+	hinic3_hwif_write_reg(hwif, addr, mask_bits);
 
+}
 
+
 
+static void
 
+disable_all_msix(struct hinic3_hwdev *hwdev)
 
+{
 
+	u16 num_irqs = hwdev->hwif->attr.num_irqs;
 
+	u16 i;
 
+
 
+	for (i = 0; i < num_irqs; i++)
 
+		hinic3_set_msix_state(hwdev, i, HINIC3_MSIX_DISABLE);
 
+}
 
+
 
+/**
 
+ * Clear msix resend bit.
 
+ *
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device object.
 
+ * @param[in] msix_idx
 
+ * MSIX(Message Signaled Interrupts) index
 
+ * @param[in] clear_resend_en
 
+ * Clear resend en flag, 1-clear.
 
+ */
 
+void
 
+hinic3_misx_intr_clear_resend_bit(void *hwdev, u16 msix_idx, u8 clear_resend_en)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+	u32 msix_ctrl = 0, addr;
 
+
 
+	if (!hwdev)
 
+		return;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	msix_ctrl = HINIC3_MSI_CLR_INDIR_SET(msix_idx, SIMPLE_INDIR_IDX) |
 
+		    HINIC3_MSI_CLR_INDIR_SET(clear_resend_en, RESEND_TIMER_CLR);
 
+
 
+	addr = HINIC3_CSR_FUNC_MSI_CLR_WR_ADDR;
 
+	hinic3_hwif_write_reg(hwif, addr, msix_ctrl);
 
+}
 
+
 
+#ifdef HINIC3_RELEASE
 
+static int
 
+wait_until_doorbell_flush_states(struct hinic3_hwif *hwif,
 
+				 enum hinic3_doorbell_ctrl states)
 
+{
 
+	enum hinic3_doorbell_ctrl db_ctrl;
 
+	u32 cnt = 0;
 
+
 
+	if (!hwif)
 
+		return -EINVAL;
 
+
 
+	while (cnt < HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT) {
 
+		db_ctrl = hinic3_get_doorbell_ctrl_status(hwif);
 
+		if (db_ctrl == states)
 
+			return 0;
 
+
 
+		rte_delay_ms(1);
 
+		cnt++;
 
+	}
 
+
 
+	return -EFAULT;
 
+}
 
+#endif
 
+
 
+static int
 
+wait_until_doorbell_and_outbound_enabled(struct hinic3_hwif *hwif)
 
+{
 
+	enum hinic3_doorbell_ctrl db_ctrl;
 
+	enum hinic3_outbound_ctrl outbound_ctrl;
 
+	u32 cnt = 0;
 
+
 
+	while (cnt < HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT) {
 
+		db_ctrl = hinic3_get_doorbell_ctrl_status(hwif);
 
+		outbound_ctrl = hinic3_get_outbound_ctrl_status(hwif);
 
+		if (outbound_ctrl == ENABLE_OUTBOUND &&
 
+		    db_ctrl == ENABLE_DOORBELL)
 
+			return 0;
 
+
 
+		rte_delay_ms(1);
 
+		cnt++;
 
+	}
 
+
 
+	return -EFAULT;
 
+}
 
+
 
+static int
 
+hinic3_get_bar_addr(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct rte_pci_device *pci_dev = hwdev->pci_dev;
 
+	struct hinic3_hwif *hwif = hwdev->hwif;
 
+	void *cfg_regs_base = NULL;
 
+	void *mgmt_reg_base = NULL;
 
+	void *db_base = NULL;
 
+	int cfg_bar;
 
+
 
+	cfg_bar = HINIC3_IS_VF_DEV(pci_dev) ? HINIC3_VF_PCI_CFG_REG_BAR
 
+					    : HINIC3_PF_PCI_CFG_REG_BAR;
 
+
 
+	cfg_regs_base = pci_dev->mem_resource[cfg_bar].addr;
 
+	if (!HINIC3_IS_VF_DEV(pci_dev)) {
 
+		mgmt_reg_base =
 
+			pci_dev->mem_resource[HINIC3_PCI_MGMT_REG_BAR].addr;
 
+		if (mgmt_reg_base == NULL) {
 
+			PMD_DRV_LOG(ERR, "mgmt_reg_base addr is null");
 
+			return -EFAULT;
 
+		}
 
+	}

drivers/net/hinic3/base/hinic3_hwif.c line 605

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+	db_base = pci_dev->mem_resource[HINIC3_PCI_DB_BAR].addr;
 
+	if (cfg_regs_base == NULL) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "mem_resource addr is null, cfg_regs_base is NULL");
 
+		return -EFAULT;

This judge should near the assigment of cfg_regs_base

Quoted 52 lines
drivers/net/hinic3/base/hinic3_hwif.c +26 -0
+	} else if (db_base == NULL) {
 
+		PMD_DRV_LOG(ERR, "mem_resource addr is null, db_base is NULL");
 
+		return -EFAULT;
 
+	}
 
+
 
+	/* If function is VF, mgmt_regs_base will be NULL. */
 
+	if (!mgmt_reg_base)
 
+		hwif->cfg_regs_base =
 
+			(u8 *)cfg_regs_base + HINIC3_VF_CFG_REG_OFFSET;
 
+	else
 
+		hwif->cfg_regs_base = cfg_regs_base;
 
+	hwif->mgmt_regs_base = mgmt_reg_base;
 
+	hwif->db_base = db_base;
 
+	hwif->db_dwqe_len = pci_dev->mem_resource[HINIC3_PCI_DB_BAR].len;
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Initialize the hw interface.
 
+ *
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device object.
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */

drivers/net/hinic3/base/hinic3_hwif.c line 636

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+int
 
+hinic3_init_hwif(void *dev)
 
+{
 
+	struct hinic3_hwdev *hwdev = NULL;
 
+	struct hinic3_hwif *hwif;

Such pointer define has inited to NULL, some don't, suggest keep the same style.

drivers/net/hinic3/base/hinic3_hwif.c line 642

Quoted 12 lines
drivers/net/hinic3/base/hinic3_hwif.c +6 -0
+	int err;
 
+	u32 attr4, attr5;
 
+
 
+	hwif = rte_zmalloc("hinic_hwif", sizeof(struct hinic3_hwif),
 
+			   RTE_CACHE_LINE_SIZE);
 
+	if (!hwif)

Suggest if (hwif == NULL)>

Quoted 41 lines
drivers/net/hinic3/base/hinic3_hwif.c +21 -0
+		return -ENOMEM;
 
+
 
+	hwdev = (struct hinic3_hwdev *)dev;
 
+	hwdev->hwif = hwif;
 
+
 
+	err = hinic3_get_bar_addr(hwdev);
 
+	if (err != 0) {
 
+		PMD_DRV_LOG(ERR, "get bar addr fail");
 
+		goto hwif_ready_err;
 
+	}
 
+
 
+	err = wait_hwif_ready(hwdev);
 
+	if (err != 0) {
 
+		PMD_DRV_LOG(ERR, "Chip status is not ready");
 
+		goto hwif_ready_err;
 
+	}
 
+
 
+	get_hwif_attr(hwif);
 
+
 
+	err = wait_until_doorbell_and_outbound_enabled(hwif);
 
+	if (err != 0) {

drivers/net/hinic3/base/hinic3_hwif.c line 668

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+		attr4 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR4_ADDR);
 
+		attr5 = hinic3_hwif_read_reg(hwif, HINIC3_CSR_FUNC_ATTR5_ADDR);
 
+		PMD_DRV_LOG(ERR,
 
+			    "Hw doorbell/outbound is disabled, attr4 0x%x "
 
+			    "attr5 0x%x",

Please keep one line, BTW: current the DPDK support most 100 character one line. and for string it chould more.

Quoted 30 lines
drivers/net/hinic3/base/hinic3_hwif.c +15 -0
+			    attr4, attr5);
 
+		goto hwif_ready_err;
 
+	}
 
+
 
+	if (!HINIC3_IS_VF(hwdev)) {
 
+		set_ppf(hwif);
 
+
 
+		if (HINIC3_IS_PPF(hwdev))
 
+			set_mpf(hwif);
 
+
 
+		get_mpf(hwif);
 
+	}
 
+
 
+	disable_all_msix(hwdev);
 
+	/* Disable mgmt cpu reporting any event. */

drivers/net/hinic3/base/hinic3_hwif.c line 688

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+	hinic3_set_pf_status(hwdev->hwif, HINIC3_PF_STATUS_INIT);
 
+
 
+	PMD_DRV_LOG(INFO,
 
+		    "global_func_idx: %d, func_type: %d, host_id: %d, ppf: %d, "
 
+		    "mpf: %d",

how about append init success.

Quoted 32 lines
drivers/net/hinic3/base/hinic3_hwif.c +16 -0
+		    hwif->attr.func_global_idx, hwif->attr.func_type,
 
+		    hwif->attr.pci_intf_idx, hwif->attr.ppf_idx,
 
+		    hwif->attr.mpf_idx);
 
+
 
+	return 0;
 
+
 
+hwif_ready_err:
 
+	rte_free(hwdev->hwif);
 
+	hwdev->hwif = NULL;
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Free the hw interface.
 
+ *

drivers/net/hinic3/base/hinic3_hwif.c line 709

Quoted 10 lines
drivers/net/hinic3/base/hinic3_hwif.c +5 -0
 
+ * @param[in] dev
 
+ * The pointer to the private hardware device.
 
+ */
 
+void
 
+hinic3_free_hwif(void *dev)

suggest rename as hinic3_deinit_hwif

drivers/net/hinic3/base/hinic3_hwif.c line 712

Quoted 6 lines
drivers/net/hinic3/base/hinic3_hwif.c +3 -0
+{
 
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
 
+

maybe should do some configuration to reset hardware?

Quoted 431 lines
drivers/net/hinic3/base/hinic3_hwif.c +67 -0
+	rte_free(hwdev->hwif);
 
+}
 
+
 
+u16
 
+hinic3_global_func_id(void *hwdev)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+
 
+	if (!hwdev)
 
+		return 0;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	return hwif->attr.func_global_idx;
 
+}
 
+
 
+u8
 
+hinic3_pf_id_of_vf(void *hwdev)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+
 
+	if (!hwdev)
 
+		return 0;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	return hwif->attr.port_to_port_idx;
 
+}
 
+
 
+u8
 
+hinic3_pcie_itf_id(void *hwdev)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+
 
+	if (!hwdev)
 
+		return 0;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	return hwif->attr.pci_intf_idx;
 
+}
 
+
 
+enum func_type
 
+hinic3_func_type(void *hwdev)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+
 
+	if (!hwdev)
 
+		return 0;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	return hwif->attr.func_type;
 
+}
 
+
 
+u16
 
+hinic3_glb_pf_vf_offset(void *hwdev)
 
+{
 
+	struct hinic3_hwif *hwif = NULL;
 
+
 
+	if (!hwdev)
 
+		return 0;
 
+
 
+	hwif = ((struct hinic3_hwdev *)hwdev)->hwif;
 
+
 
+	return hwif->attr.global_vf_id_of_pf;
 
+}
drivers/net/hinic3/base/hinic3_hwif.h +0 -0

new file mode 100644

index 0000000000..97d2ed99df

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_hwif.h

drivers/net/hinic3/base/hinic3_hwif.h +142 -0
@@ -0,0 +1,142 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#ifndef _HINIC3_HWIF_H_
 
+#define _HINIC3_HWIF_H_
 
+
 
+#define HINIC3_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT 60000
 
+#define HINIC3_PCIE_LINK_DOWN			  0xFFFFFFFF
 
+
 
+/* PCIe bar space. */
 
+#define HINIC3_VF_PCI_CFG_REG_BAR 0
 
+#define HINIC3_PF_PCI_CFG_REG_BAR 1
 
+
 
+#define HINIC3_PCI_INTR_REG_BAR 2
 
+#define HINIC3_PCI_MGMT_REG_BAR 3 /**< Only PF has mgmt bar. */
 
+#define HINIC3_PCI_DB_BAR	4
 
+
 
+/* Doorbell or direct wqe page size is 4K. */
 
+#define HINIC3_DB_PAGE_SIZE 0x00001000ULL
 
+#define HINIC3_DWQE_OFFSET  0x00000800ULL
 
+
 
+enum func_type { TYPE_PF, TYPE_VF, TYPE_PPF, TYPE_UNKNOWN };
 
+#define MSIX_RESEND_TIMER_CLEAR 1
 
+
 
+/* Message signaled interrupt status. */
 
+enum hinic3_msix_state { HINIC3_MSIX_ENABLE, HINIC3_MSIX_DISABLE };
 
+
 
+enum hinic3_msix_auto_mask {
 
+	HINIC3_CLR_MSIX_AUTO_MASK,
 
+	HINIC3_SET_MSIX_AUTO_MASK,
 
+};
 
+
 
+struct hinic3_func_attr {
 
+	u16 func_global_idx;
 
+	u8 port_to_port_idx;
 
+	u8 pci_intf_idx;
 
+	u8 vf_in_pf;
 
+	enum func_type func_type;
 
+
 
+	u8 mpf_idx;
 
+
 
+	u8 ppf_idx;
 
+
 
+	u16 num_irqs; /**< Max: 2 ^ 15. */
 
+	u8 num_aeqs;  /**< Max: 2 ^ 3. */
 
+	u8 num_ceqs;  /**< Max: 2 ^ 7. */
 
+
 
+	u16 num_queue;	 /**< Max: 2 ^ 8. */
 
+	u8 num_dma_attr; /**< Max: 2 ^ 6. */
 
+	u8 msix_flex_en;
 
+
 
+	u16 global_vf_id_of_pf;
 
+};
 
+
 
+/* Structure for hardware interface. */
 
+struct hinic3_hwif {
 
+	/* Configure virtual address, PF is bar1, VF is bar0/1. */
 
+	u8 *cfg_regs_base;
 
+	/* For PF bar3 virtual address, if function is VF should set NULL. */
 
+	u8 *mgmt_regs_base;
 
+	u8 *db_base;
 
+	u64 db_dwqe_len;
 
+
 
+	struct hinic3_func_attr attr;
 
+
 
+	void *pdev;
 
+};
 
+
 
+enum hinic3_outbound_ctrl { ENABLE_OUTBOUND = 0x0, DISABLE_OUTBOUND = 0x1 };
 
+
 
+enum hinic3_doorbell_ctrl { ENABLE_DOORBELL = 0x0, DISABLE_DOORBELL = 0x1 };
 
+
 
+enum hinic3_pf_status {
 
+	HINIC3_PF_STATUS_INIT = 0x0,
 
+	HINIC3_PF_STATUS_ACTIVE_FLAG = 0x11,
 
+	HINIC3_PF_STATUS_FLR_START_FLAG = 0x12,
 
+	HINIC3_PF_STATUS_FLR_FINISH_FLAG = 0x13
 
+};
 
+
 
+/* Type of doorbell. */
 
+enum hinic3_db_type {
 
+	HINIC3_DB_TYPE_CMDQ = 0x0,
 
+	HINIC3_DB_TYPE_SQ = 0x1,
 
+	HINIC3_DB_TYPE_RQ = 0x2,
 
+	HINIC3_DB_TYPE_MAX = 0x3
 
+};
 
+
 
+/* Get the attributes of the hardware interface. */
 
+#define HINIC3_HWIF_NUM_AEQS(hwif)	   ((hwif)->attr.num_aeqs)
 
+#define HINIC3_HWIF_NUM_IRQS(hwif)	   ((hwif)->attr.num_irqs)
 
+#define HINIC3_HWIF_GLOBAL_IDX(hwif)	   ((hwif)->attr.func_global_idx)
 
+#define HINIC3_HWIF_GLOBAL_VF_OFFSET(hwif) ((hwif)->attr.global_vf_id_of_pf)
 
+#define HINIC3_HWIF_PPF_IDX(hwif)	   ((hwif)->attr.ppf_idx)
 
+#define HINIC3_PCI_INTF_IDX(hwif)	   ((hwif)->attr.pci_intf_idx)
 
+
 
+/* Func type judgment. */
 
+#define HINIC3_FUNC_TYPE(dev) ((dev)->hwif->attr.func_type)
 
+#define HINIC3_IS_PF(dev)     (HINIC3_FUNC_TYPE(dev) == TYPE_PF)
 
+#define HINIC3_IS_VF(dev)     (HINIC3_FUNC_TYPE(dev) == TYPE_VF)
 
+#define HINIC3_IS_PPF(dev)    (HINIC3_FUNC_TYPE(dev) == TYPE_PPF)
 
+
 
+u32 hinic3_hwif_read_reg(struct hinic3_hwif *hwif, u32 reg);
 
+
 
+void hinic3_hwif_write_reg(struct hinic3_hwif *hwif, u32 reg, u32 val);
 
+
 
+void hinic3_set_msix_auto_mask_state(void *hwdev, u16 msix_idx,
 
+				     enum hinic3_msix_auto_mask flag);
 
+
 
+void hinic3_set_msix_state(void *hwdev, u16 msix_idx,
 
+			   enum hinic3_msix_state flag);
 
+
 
+void hinic3_misx_intr_clear_resend_bit(void *hwdev, u16 msix_idx,
 
+				       u8 clear_resend_en);
 
+
 
+u16 hinic3_global_func_id(void *hwdev);
 
+
 
+u8 hinic3_pf_id_of_vf(void *hwdev);
 
+
 
+u8 hinic3_pcie_itf_id(void *hwdev);
 
+
 
+enum func_type hinic3_func_type(void *hwdev);
 
+
 
+u16 hinic3_glb_pf_vf_offset(void *hwdev);
 
+void hinic3_update_msix_info(struct hinic3_hwif *hwif);
 
+void hinic3_set_pf_status(struct hinic3_hwif *hwif,
 
+			  enum hinic3_pf_status status);
 
+
 
+enum hinic3_pf_status hinic3_get_pf_status(struct hinic3_hwif *hwif);
 
+
 
+int hinic3_alloc_db_addr(void *hwdev, void **db_base,
 
+			 enum hinic3_db_type queue_type);
 
+
 
+void hinic3_disable_doorbell(struct hinic3_hwif *hwif);
 
+
 
+void hinic3_enable_doorbell(struct hinic3_hwif *hwif);
 
+
 
+int hinic3_init_hwif(void *dev);
 
+
 
+void hinic3_free_hwif(void *dev);
 
+
 
+#endif /**< _HINIC3_HWIF_H_ */
#133 lore raw

PATCH v5 4/18 net/hinic3: add support for cmdq mechanism

In reply to Feifei Wang

From: Xin Wang <[email protected]>

Micocode is named ucode in SP series NIC. Its main responsibility is data transmission and reception. But it can also handle some administration works. It uses cmdq mechanism. This patch introduces data structures, initialization, interfaces, and commands sending functions of cmdq.

---
 drivers/net/hinic3/base/hinic3_cmdq.c | 978 ++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_cmdq.h | 230 ++++++
 2 files changed, 1208 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.c
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.h
drivers/net/hinic3/base/hinic3_cmdq.c new file +978 -0
new file mode 100644
index 0000000000..5b5c1da999
@@ -0,0 +1,978 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#include <rte_atomic.h>
+#include <rte_mbuf.h>
+
+#include "hinic3_compat.h"
+#include "hinic3_cmd.h"
+#include "hinic3_cmdq.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_hwif.h"
+#include "hinic3_mgmt.h"
+#include "hinic3_wq.h"
+
+#define CMDQ_CMD_TIMEOUT 5000 /**< Millisecond. */
+
+#define UPPER_8_BITS(data) (((data) >> 8) & 0xFF)
+#define LOWER_8_BITS(data) ((data) & 0xFF)
+
+#define CMDQ_DB_INFO_HI_PROD_IDX_SHIFT 0
+#define CMDQ_DB_INFO_HI_PROD_IDX_MASK  0xFFU
+
+#define CMDQ_DB_INFO_SET(val, member)                  \
+	((((u32)(val)) & CMDQ_DB_INFO_##member##_MASK) \
+	 << CMDQ_DB_INFO_##member##_SHIFT)
+#define CMDQ_DB_INFO_UPPER_32(val) ((u64)(val) << 32)
+
+#define CMDQ_DB_HEAD_QUEUE_TYPE_SHIFT 23
+#define CMDQ_DB_HEAD_CMDQ_TYPE_SHIFT  24
+#define CMDQ_DB_HEAD_SRC_TYPE_SHIFT   27
+#define CMDQ_DB_HEAD_QUEUE_TYPE_MASK  0x1U
+#define CMDQ_DB_HEAD_CMDQ_TYPE_MASK   0x7U
+#define CMDQ_DB_HEAD_SRC_TYPE_MASK    0x1FU
+#define CMDQ_DB_HEAD_SET(val, member)                  \
+	((((u32)(val)) & CMDQ_DB_HEAD_##member##_MASK) \
+	 << CMDQ_DB_HEAD_##member##_SHIFT)
+
+#define CMDQ_CTRL_PI_SHIFT	    0
+#define CMDQ_CTRL_CMD_SHIFT	    16
+#define CMDQ_CTRL_MOD_SHIFT	    24
+#define CMDQ_CTRL_ACK_TYPE_SHIFT    29
+#define CMDQ_CTRL_HW_BUSY_BIT_SHIFT 31
+
+#define CMDQ_CTRL_PI_MASK	   0xFFFFU
+#define CMDQ_CTRL_CMD_MASK	   0xFFU
+#define CMDQ_CTRL_MOD_MASK	   0x1FU
+#define CMDQ_CTRL_ACK_TYPE_MASK	   0x3U
+#define CMDQ_CTRL_HW_BUSY_BIT_MASK 0x1U
+
+#define CMDQ_CTRL_SET(val, member) \
+	(((u32)(val) & CMDQ_CTRL_##member##_MASK) << CMDQ_CTRL_##member##_SHIFT)
+
+#define CMDQ_CTRL_GET(val, member) \
+	(((val) >> CMDQ_CTRL_##member##_SHIFT) & CMDQ_CTRL_##member##_MASK)
+
+#define CMDQ_WQE_HEADER_BUFDESC_LEN_SHIFT	0
+#define CMDQ_WQE_HEADER_COMPLETE_FMT_SHIFT	15
+#define CMDQ_WQE_HEADER_DATA_FMT_SHIFT		22
+#define CMDQ_WQE_HEADER_COMPLETE_REQ_SHIFT	23
+#define CMDQ_WQE_HEADER_COMPLETE_SECT_LEN_SHIFT 27
+#define CMDQ_WQE_HEADER_CTRL_LEN_SHIFT		29
+#define CMDQ_WQE_HEADER_HW_BUSY_BIT_SHIFT	31
+
+#define CMDQ_WQE_HEADER_BUFDESC_LEN_MASK       0xFFU
+#define CMDQ_WQE_HEADER_COMPLETE_FMT_MASK      0x1U
+#define CMDQ_WQE_HEADER_DATA_FMT_MASK	       0x1U
+#define CMDQ_WQE_HEADER_COMPLETE_REQ_MASK      0x1U
+#define CMDQ_WQE_HEADER_COMPLETE_SECT_LEN_MASK 0x3U
+#define CMDQ_WQE_HEADER_CTRL_LEN_MASK	       0x3U
+#define CMDQ_WQE_HEADER_HW_BUSY_BIT_MASK       0x1U
+
+#define CMDQ_WQE_HEADER_SET(val, member)                \
+	(((u32)(val) & CMDQ_WQE_HEADER_##member##_MASK) \
+	 << CMDQ_WQE_HEADER_##member##_SHIFT)
+
+#define CMDQ_WQE_HEADER_GET(val, member)               \
+	(((val) >> CMDQ_WQE_HEADER_##member##_SHIFT) & \
+	 CMDQ_WQE_HEADER_##member##_MASK)
+
+#define CMDQ_CTXT_CURR_WQE_PAGE_PFN_SHIFT 0
+#define CMDQ_CTXT_EQ_ID_SHIFT		  53
+#define CMDQ_CTXT_CEQ_ARM_SHIFT		  61
+#define CMDQ_CTXT_CEQ_EN_SHIFT		  62
+#define CMDQ_CTXT_HW_BUSY_BIT_SHIFT	  63
+
+#define CMDQ_CTXT_CURR_WQE_PAGE_PFN_MASK 0xFFFFFFFFFFFFF
+#define CMDQ_CTXT_EQ_ID_MASK		 0xFF
+#define CMDQ_CTXT_CEQ_ARM_MASK		 0x1
+#define CMDQ_CTXT_CEQ_EN_MASK		 0x1
+#define CMDQ_CTXT_HW_BUSY_BIT_MASK	 0x1
+
+#define CMDQ_CTXT_PAGE_INFO_SET(val, member) \
+	(((u64)(val) & CMDQ_CTXT_##member##_MASK) << CMDQ_CTXT_##member##_SHIFT)
+
+#define CMDQ_CTXT_WQ_BLOCK_PFN_SHIFT 0
+#define CMDQ_CTXT_CI_SHIFT	     52
+
+#define CMDQ_CTXT_WQ_BLOCK_PFN_MASK 0xFFFFFFFFFFFFF
+#define CMDQ_CTXT_CI_MASK	    0xFFF
+
+#define CMDQ_CTXT_BLOCK_INFO_SET(val, member) \
+	(((u64)(val) & CMDQ_CTXT_##member##_MASK) << CMDQ_CTXT_##member##_SHIFT)
+
+#define SAVED_DATA_ARM_SHIFT 31
+
+#define SAVED_DATA_ARM_MASK 0x1U
+
+#define SAVED_DATA_SET(val, member) \
+	(((val) & SAVED_DATA_##member##_MASK) << SAVED_DATA_##member##_SHIFT)
+
+#define SAVED_DATA_CLEAR(val, member) \
+	((val) & (~(SAVED_DATA_##member##_MASK << SAVED_DATA_##member##_SHIFT)))
+
+#define WQE_ERRCODE_VAL_SHIFT 0
+
+#define WQE_ERRCODE_VAL_MASK 0x7FFFFFFF
+
+#define WQE_ERRCODE_GET(val, member) \
+	(((val) >> WQE_ERRCODE_##member##_SHIFT) & WQE_ERRCODE_##member##_MASK)
+
+#define WQE_COMPLETED(ctrl_info) CMDQ_CTRL_GET(ctrl_info, HW_BUSY_BIT)
+
+#define WQE_HEADER(wqe) ((struct hinic3_cmdq_header *)(wqe))
+
+#define CMDQ_DB_PI_OFF(pi) (((u16)LOWER_8_BITS(pi)) << 3)
+
+#define CMDQ_DB_ADDR(db_base, pi) (((u8 *)(db_base)) + CMDQ_DB_PI_OFF(pi))
+
+#define CMDQ_PFN(addr, page_size) ((addr) >> (ilog2(page_size)))
+
+#define FIRST_DATA_TO_WRITE_LAST sizeof(u64)
+
+#define WQE_LCMD_SIZE 64
+#define WQE_SCMD_SIZE 64
+
+#define COMPLETE_LEN 3
+
+#define CMDQ_WQEBB_SIZE	 64
+#define CMDQ_WQEBB_SHIFT 6
+
+#define CMDQ_WQE_SIZE 64
+
+#define HINIC3_CMDQ_WQ_BUF_SIZE 4096
+
+#define WQE_NUM_WQEBBS(wqe_size, wq)                                 \
+	({                                                           \
+		typeof(wq) __wq = (wq);                              \
+		(u16)(RTE_ALIGN((u32)(wqe_size), __wq->wqebb_size) / \
+		      __wq->wqebb_size);                             \
+	})
+
+#define cmdq_to_cmdqs(cmdq)                                                   \
+	({                                                                    \
+		typeof(cmdq) __cmdq = (cmdq);                                 \
+		container_of(__cmdq - __cmdq->cmdq_type, struct hinic3_cmdqs, \
+			     __cmdq[0]);                                      \
+	})
+
+#define WAIT_CMDQ_ENABLE_TIMEOUT 300
+
+static int hinic3_cmdq_poll_msg(struct hinic3_cmdq *cmdq, u32 timeout);
+
+bool
+hinic3_cmdq_idle(struct hinic3_cmdq *cmdq)
+{
+	struct hinic3_wq *wq = cmdq->wq;
+
+	return rte_atomic_load_explicit(&wq->delta, rte_memory_order_seq_cst) ==
+	       wq->q_depth;
+}
+
+struct hinic3_cmd_buf *
+hinic3_alloc_cmd_buf(void *hwdev)
+{
+	struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs;
+	struct hinic3_cmd_buf *cmd_buf;
+
+	cmd_buf = rte_zmalloc(NULL, sizeof(*cmd_buf), 0);
+	if (!cmd_buf) {
+		PMD_DRV_LOG(ERR, "Allocate cmd buffer failed");
+		return NULL;
+	}
+
+	cmd_buf->mbuf = rte_pktmbuf_alloc(cmdqs->cmd_buf_pool);
+	if (!cmd_buf->mbuf) {
+		PMD_DRV_LOG(ERR, "Allocate cmd from the pool failed");
+		goto alloc_pci_buf_err;
+	}
+
+	cmd_buf->dma_addr = rte_mbuf_data_iova(cmd_buf->mbuf);
+	cmd_buf->buf = rte_pktmbuf_mtod(cmd_buf->mbuf, void *);
+
+	return cmd_buf;
+
+alloc_pci_buf_err:
+	rte_free(cmd_buf);
+	return NULL;
+}
+
+void
+hinic3_free_cmd_buf(struct hinic3_cmd_buf *cmd_buf)
+{
+	rte_pktmbuf_free(cmd_buf->mbuf);
+
+	rte_free(cmd_buf);
+}
+
+static u32
+cmdq_wqe_size(enum cmdq_wqe_type wqe_type)
+{
+	u32 wqe_size = 0;
+
+	switch (wqe_type) {
+	case WQE_LCMD_TYPE:
+		wqe_size = WQE_LCMD_SIZE;
+		break;
+	case WQE_SCMD_TYPE:
+		wqe_size = WQE_SCMD_SIZE;
+		break;
+	default:
+		break;
+	}
+
+	return wqe_size;
+}
+
+static int
+cmdq_get_wqe_size(enum bufdesc_len len)
+{
+	int wqe_size = 0;
+
+	switch (len) {
+	case BUFDESC_LCMD_LEN:
+		wqe_size = WQE_LCMD_SIZE;
+		break;
+	case BUFDESC_SCMD_LEN:
+		wqe_size = WQE_SCMD_SIZE;
+		break;
+	default:
+		break;
+	}
+
+	return wqe_size;
+}
+
+static void
+cmdq_set_completion(struct hinic3_cmdq_completion *complete,
+		    struct hinic3_cmd_buf *buf_out)
+{
+	struct hinic3_sge_resp *sge_resp = &complete->sge_resp;
+
+	hinic3_set_sge(&sge_resp->sge, buf_out->dma_addr, HINIC3_CMDQ_BUF_SIZE);
+}
+
+static void
+cmdq_set_lcmd_bufdesc(struct hinic3_cmdq_wqe_lcmd *wqe,
+		      struct hinic3_cmd_buf *buf_in)
+{
+	hinic3_set_sge(&wqe->buf_desc.sge, buf_in->dma_addr, buf_in->size);
+}
+
+static void
+cmdq_set_db(struct hinic3_cmdq *cmdq, enum hinic3_cmdq_type cmdq_type,
+	    u16 prod_idx)
+{
+	u64 db = 0;
+
+	/* Hardware will do endianness converting. */
+	db = CMDQ_DB_INFO_SET(UPPER_8_BITS(prod_idx), HI_PROD_IDX);
+	db = CMDQ_DB_INFO_UPPER_32(db) |
+	     CMDQ_DB_HEAD_SET(HINIC3_DB_CMDQ_TYPE, QUEUE_TYPE) |
+	     CMDQ_DB_HEAD_SET(cmdq_type, CMDQ_TYPE) |
+	     CMDQ_DB_HEAD_SET(HINIC3_DB_SRC_CMDQ_TYPE, SRC_TYPE);
+
+	/**< Write all before the doorbell. */
+	rte_atomic_thread_fence(rte_memory_order_release);
+
+	rte_write64(db, CMDQ_DB_ADDR(cmdq->db_base, prod_idx));
+}
+
+static void
+cmdq_wqe_fill(void *dst, void *src)
+{
+	memcpy((void *)((u8 *)dst + FIRST_DATA_TO_WRITE_LAST),
+	       (void *)((u8 *)src + FIRST_DATA_TO_WRITE_LAST),
+	       CMDQ_WQE_SIZE - FIRST_DATA_TO_WRITE_LAST);
+
+	/* The first 8 bytes should be written last. */
+	rte_atomic_thread_fence(rte_memory_order_release);
+
+	*(u64 *)dst = *(u64 *)src;
+}
+
+static void
+cmdq_prepare_wqe_ctrl(struct hinic3_cmdq_wqe *wqe, int wrapped,
+		      enum hinic3_mod_type mod, u8 cmd, u16 prod_idx,
+		      enum completion_format complete_format,
+		      enum data_format local_data_format,
+		      enum bufdesc_len buf_len)
+{
+	struct hinic3_ctrl *ctrl = NULL;
+	enum ctrl_sect_len ctrl_len;
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = NULL;
+	struct hinic3_cmdq_wqe_scmd *wqe_scmd = NULL;
+	u32 saved_data = WQE_HEADER(wqe)->saved_data;
+
+	if (local_data_format == DATA_SGE) {
+		wqe_lcmd = &wqe->wqe_lcmd;
+
+		wqe_lcmd->status.status_info = 0;
+		ctrl = &wqe_lcmd->ctrl;
+		ctrl_len = CTRL_SECT_LEN;
+	} else {
+		wqe_scmd = &wqe->inline_wqe.wqe_scmd;
+
+		wqe_scmd->status.status_info = 0;
+		ctrl = &wqe_scmd->ctrl;
+		ctrl_len = CTRL_DIRECT_SECT_LEN;
+	}
+
+	ctrl->ctrl_info = CMDQ_CTRL_SET(prod_idx, PI) |
+			  CMDQ_CTRL_SET(cmd, CMD) | CMDQ_CTRL_SET(mod, MOD) |
+			  CMDQ_CTRL_SET(HINIC3_ACK_TYPE_CMDQ, ACK_TYPE);
+
+	WQE_HEADER(wqe)->header_info =
+		CMDQ_WQE_HEADER_SET(buf_len, BUFDESC_LEN) |
+		CMDQ_WQE_HEADER_SET(complete_format, COMPLETE_FMT) |
+		CMDQ_WQE_HEADER_SET(local_data_format, DATA_FMT) |
+		CMDQ_WQE_HEADER_SET(CEQ_SET, COMPLETE_REQ) |
+		CMDQ_WQE_HEADER_SET(COMPLETE_LEN, COMPLETE_SECT_LEN) |
+		CMDQ_WQE_HEADER_SET(ctrl_len, CTRL_LEN) |
+		CMDQ_WQE_HEADER_SET((u32)wrapped, HW_BUSY_BIT);
+
+	saved_data &= SAVED_DATA_CLEAR(saved_data, ARM);
+	if (cmd == CMDQ_SET_ARM_CMD && mod == HINIC3_MOD_COMM)
+		WQE_HEADER(wqe)->saved_data = saved_data |
+					      SAVED_DATA_SET(1, ARM);
+	else
+		WQE_HEADER(wqe)->saved_data = saved_data;
+}
+
+static void
+cmdq_set_lcmd_wqe(struct hinic3_cmdq_wqe *wqe, enum cmdq_cmd_type cmd_type,
+		  struct hinic3_cmd_buf *buf_in, struct hinic3_cmd_buf *buf_out,
+		  int wrapped, enum hinic3_mod_type mod, u8 cmd, u16 prod_idx)
+{
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = &wqe->wqe_lcmd;
+	enum completion_format complete_format = COMPLETE_DIRECT;
+
+	switch (cmd_type) {
+	case SYNC_CMD_DIRECT_RESP:
+		complete_format = COMPLETE_DIRECT;
+		wqe_lcmd->completion.direct_resp = 0;
+		break;
+	case SYNC_CMD_SGE_RESP:
+		if (buf_out) {
+			complete_format = COMPLETE_SGE;
+			cmdq_set_completion(&wqe_lcmd->completion, buf_out);
+		}
+		break;
+	case ASYNC_CMD:
+		complete_format = COMPLETE_DIRECT;
+		wqe_lcmd->completion.direct_resp = 0;
+		wqe_lcmd->buf_desc.saved_async_buf = (u64)(buf_in);
+		break;
+	default:
+		break;
+	}
+
+	cmdq_prepare_wqe_ctrl(wqe, wrapped, mod, cmd, prod_idx, complete_format,
+			      DATA_SGE, BUFDESC_LCMD_LEN);
+
+	cmdq_set_lcmd_bufdesc(wqe_lcmd, buf_in);
+}
+
+/**
+ * Prepare necessary context for command queue, send a synchronous command with
+ * a direct response to hardware. It waits for completion of command by polling
+ * command queue for a response.
+ *
+ * @param[in] cmdq
+ * The command queue object that represents the queue to send the command to.
+ * @param[in] mod
+ * The module type that the command belongs to.
+ * @param[in] cmd
+ * The command to be executed.
+ * @param[in] buf_in
+ * The input buffer containing the command parameters.
+ * @param[out] out_param
+ * A pointer to the location where the response data will be stored, if
+ * available.
+ * @param[in] timeout
+ * The timeout value (ms) to wait for the command completion. If zero, a default
+ * timeout will be used.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ * - -EBUSY: The command queue is busy.
+ * - -ETIMEDOUT: The command did not complete within the specified timeout.
+ */
+static int
+cmdq_sync_cmd_direct_resp(struct hinic3_cmdq *cmdq, enum hinic3_mod_type mod,
+			  u8 cmd, struct hinic3_cmd_buf *buf_in, u64 *out_param,
+			  u32 timeout)
+{
+	struct hinic3_wq *wq = cmdq->wq;
+	struct hinic3_cmdq_wqe wqe;
+	struct hinic3_cmdq_wqe *curr_wqe = NULL;
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = NULL;
+	u16 curr_prod_idx, next_prod_idx, num_wqebbs;
+	int wrapped;
+	u32 timeo, wqe_size;
+	int err;
+
+	wqe_size = cmdq_wqe_size(WQE_LCMD_TYPE);
+	num_wqebbs = WQE_NUM_WQEBBS(wqe_size, wq);
+
+	/* Keep wrapped and doorbell index correct. */
+	rte_spinlock_lock(&cmdq->cmdq_lock);
+
+	curr_wqe = hinic3_get_wqe(cmdq->wq, num_wqebbs, &curr_prod_idx);
+	if (!curr_wqe) {
+		err = -EBUSY;
+		goto cmdq_unlock;
+	}
+
+	memset(&wqe, 0, sizeof(wqe));
+	wrapped = cmdq->wrapped;
+
+	next_prod_idx = curr_prod_idx + num_wqebbs;
+	if (next_prod_idx >= wq->q_depth) {
+		cmdq->wrapped = !cmdq->wrapped;
+		next_prod_idx -= wq->q_depth;
+	}
+
+	cmdq_set_lcmd_wqe(&wqe, SYNC_CMD_DIRECT_RESP, buf_in, NULL, wrapped,
+			  mod, cmd, curr_prod_idx);
+
+	/* The data that is written to HW should be in Big Endian Format. */
+	hinic3_hw_be32_len(&wqe, (int)wqe_size);
+
+	/* Cmdq wqe is not shadow, therefore wqe will be written to wq. */
+	cmdq_wqe_fill(curr_wqe, &wqe);
+
+	cmdq->cmd_infos[curr_prod_idx].cmd_type = HINIC3_CMD_TYPE_DIRECT_RESP;
+
+	cmdq_set_db(cmdq, HINIC3_CMDQ_SYNC, next_prod_idx);
+
+	timeo = msecs_to_jiffies(timeout ? timeout : CMDQ_CMD_TIMEOUT);
+	err = hinic3_cmdq_poll_msg(cmdq, timeo);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Cmdq poll msg ack failed, prod idx: 0x%x",
+			    curr_prod_idx);
+		err = -ETIMEDOUT;
+		goto cmdq_unlock;
+	}
+
+	rte_smp_rmb(); /**< Read error code after completion. */
+
+	if (out_param) {
+		wqe_lcmd = &curr_wqe->wqe_lcmd;
+		*out_param = cpu_to_be64(wqe_lcmd->completion.direct_resp);
+	}
+
+	if (cmdq->errcode[curr_prod_idx])
+		err = cmdq->errcode[curr_prod_idx];
+
+cmdq_unlock:
+	rte_spinlock_unlock(&cmdq->cmdq_lock);
+
+	return err;
+}
+
+/**
+ * Send a synchronous command with detailed response and wait for the
+ * completion.
+ *
+ * @param[in] cmdq
+ * The command queue object representing the queue to send the command to.
+ * @param[in] mod
+ * The module type that the command belongs to.
+ * @param[in] cmd
+ * The command to be executed.
+ * @param[in] buf_in
+ * The input buffer containing the parameters for the command.
+ * @param[out] buf_out
+ * The output buffer where the detailed response from the hardware will be
+ * stored.
+ * @param[in] timeout
+ * The timeout value (ms) to wait for the command completion. If zero, a default
+ * timeout will be used.
+ *
+ * @return
+ * 0 on success, non-zero on failure.
+ * - -EBUSY: The command queue is busy.
+ * - -ETIMEDOUT: The command did not complete within the specified timeout.
+ */
+static int
+cmdq_sync_cmd_detail_resp(struct hinic3_cmdq *cmdq, enum hinic3_mod_type mod,
+			  u8 cmd, struct hinic3_cmd_buf *buf_in,
+			  struct hinic3_cmd_buf *buf_out, u32 timeout)
+{
+	struct hinic3_wq *wq = cmdq->wq;
+	struct hinic3_cmdq_wqe wqe;
+	struct hinic3_cmdq_wqe *curr_wqe = NULL;
+	u16 curr_prod_idx, next_prod_idx, num_wqebbs;
+	int wrapped;
+	u32 timeo, wqe_size;
+	int err;
+
+	wqe_size = cmdq_wqe_size(WQE_LCMD_TYPE);
+	num_wqebbs = WQE_NUM_WQEBBS(wqe_size, wq);
+
+	/* Keep wrapped and doorbell index correct. */
+	rte_spinlock_lock(&cmdq->cmdq_lock);
+
+	curr_wqe = hinic3_get_wqe(cmdq->wq, num_wqebbs, &curr_prod_idx);
+	if (!curr_wqe) {
+		err = -EBUSY;
+		goto cmdq_unlock;
+	}
+
+	memset(&wqe, 0, sizeof(wqe));
+	wrapped = cmdq->wrapped;
+
+	next_prod_idx = curr_prod_idx + num_wqebbs;
+	if (next_prod_idx >= wq->q_depth) {
+		cmdq->wrapped = !cmdq->wrapped;
+		next_prod_idx -= wq->q_depth;
+	}
+
+	cmdq_set_lcmd_wqe(&wqe, SYNC_CMD_SGE_RESP, buf_in, buf_out, wrapped,
+			  mod, cmd, curr_prod_idx);
+
+	/* The data that is written to HW should be in Big Endian Format. */
+	hinic3_hw_be32_len(&wqe, (int)wqe_size);
+
+	/* Cmdq wqe is not shadow, therefore wqe will be written to wq. */
+	cmdq_wqe_fill(curr_wqe, &wqe);
+
+	cmdq->cmd_infos[curr_prod_idx].cmd_type = HINIC3_CMD_TYPE_SGE_RESP;
+
+	cmdq_set_db(cmdq, cmdq->cmdq_type, next_prod_idx);
+
+	timeo = msecs_to_jiffies(timeout ? timeout : CMDQ_CMD_TIMEOUT);
+	err = hinic3_cmdq_poll_msg(cmdq, timeo);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Cmdq poll msg ack failed, prod idx: 0x%x",
+			    curr_prod_idx);
+		err = -ETIMEDOUT;
+		goto cmdq_unlock;
+	}
+
+	rte_smp_rmb(); /**< Read error code after completion. */
+
+	if (cmdq->errcode[curr_prod_idx])
+		err = cmdq->errcode[curr_prod_idx];
+
+cmdq_unlock:
+	rte_spinlock_unlock(&cmdq->cmdq_lock);
+
+	return err;
+}
+
+static int
+cmdq_params_valid(void *hwdev, struct hinic3_cmd_buf *buf_in)
+{
+	if (!buf_in || !hwdev) {
+		PMD_DRV_LOG(ERR, "Invalid CMDQ buffer or hwdev is NULL");
+		return -EINVAL;
+	}
+
+	if (buf_in->size == 0 || buf_in->size > HINIC3_CMDQ_BUF_SIZE) {
+		PMD_DRV_LOG(ERR, "Invalid CMDQ buffer size: 0x%x",
+			    buf_in->size);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+static int
+wait_cmdqs_enable(struct hinic3_cmdqs *cmdqs)
+{
+	unsigned long end;
+
+	end = jiffies + msecs_to_jiffies(WAIT_CMDQ_ENABLE_TIMEOUT);
+	do {
+		if (cmdqs->status & HINIC3_CMDQ_ENABLE)
+			return 0;
+	} while (time_before(jiffies, end));
+
+	return -EBUSY;
+}
+
+int
+hinic3_cmdq_direct_resp(void *hwdev, enum hinic3_mod_type mod, u8 cmd,
+			struct hinic3_cmd_buf *buf_in, u64 *out_param,
+			u32 timeout)
+{
+	struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs;
+	int err;
+
+	err = cmdq_params_valid(hwdev, buf_in);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Invalid cmdq parameters");
+		return err;
+	}
+
+	err = wait_cmdqs_enable(cmdqs);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Cmdq is disabled");
+		return err;
+	}
+
+	return cmdq_sync_cmd_direct_resp(&cmdqs->cmdq[HINIC3_CMDQ_SYNC], mod,
+					 cmd, buf_in, out_param, timeout);
+}
+
+int
+hinic3_cmdq_detail_resp(void *hwdev, enum hinic3_mod_type mod, u8 cmd,
+			struct hinic3_cmd_buf *buf_in,
+			struct hinic3_cmd_buf *buf_out, u32 timeout)
+{
+	struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs;
+	int err;
+
+	err = cmdq_params_valid(hwdev, buf_in);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Invalid cmdq parameters");
+		return err;
+	}
+
+	err = wait_cmdqs_enable(cmdqs);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Cmdq is disabled");
+		return err;
+	}
+
+	return cmdq_sync_cmd_detail_resp(&cmdqs->cmdq[HINIC3_CMDQ_SYNC], mod,
+					 cmd, buf_in, buf_out, timeout);
+}
+
+static void
+cmdq_update_errcode(struct hinic3_cmdq *cmdq, u16 prod_idx, int errcode)
+{
+	cmdq->errcode[prod_idx] = errcode;
+}
+
+static void
+clear_wqe_complete_bit(struct hinic3_cmdq *cmdq, struct hinic3_cmdq_wqe *wqe)
+{
+	struct hinic3_ctrl *ctrl = NULL;
+	u32 header_info = hinic3_hw_cpu32(WQE_HEADER(wqe)->header_info);
+	int buf_len = CMDQ_WQE_HEADER_GET(header_info, BUFDESC_LEN);
+	int wqe_size = cmdq_get_wqe_size(buf_len);
+	u16 num_wqebbs;
+
+	if (wqe_size == WQE_LCMD_SIZE)
+		ctrl = &wqe->wqe_lcmd.ctrl;
+	else
+		ctrl = &wqe->inline_wqe.wqe_scmd.ctrl;
+
+	/* Clear HW busy bit. */
+	ctrl->ctrl_info = 0;
+
+	rte_atomic_thread_fence(rte_memory_order_release); /**< Verify wqe is cleared. */
+
+	num_wqebbs = WQE_NUM_WQEBBS(wqe_size, cmdq->wq);
+	hinic3_put_wqe(cmdq->wq, num_wqebbs);
+}
+
+static void
+cmdq_init_queue_ctxt(struct hinic3_cmdq *cmdq,
+		     struct hinic3_cmdq_ctxt_info *ctxt_info)
+{
+	struct hinic3_wq *wq = cmdq->wq;
+	u64 wq_first_page_paddr, pfn;
+
+	u16 start_ci = (u16)(wq->cons_idx);
+
+	/* The data in the HW is in Big Endian Format. */
+	wq_first_page_paddr = wq->queue_buf_paddr;
+
+	pfn = CMDQ_PFN(wq_first_page_paddr, RTE_PGSIZE_4K);
+	ctxt_info->curr_wqe_page_pfn =
+		CMDQ_CTXT_PAGE_INFO_SET(1, HW_BUSY_BIT) |
+		CMDQ_CTXT_PAGE_INFO_SET(0, CEQ_EN) |
+		CMDQ_CTXT_PAGE_INFO_SET(0, CEQ_ARM) |
+		CMDQ_CTXT_PAGE_INFO_SET(HINIC3_CEQ_ID_CMDQ, EQ_ID) |
+		CMDQ_CTXT_PAGE_INFO_SET(pfn, CURR_WQE_PAGE_PFN);
+
+	ctxt_info->wq_block_pfn = CMDQ_CTXT_BLOCK_INFO_SET(start_ci, CI) |
+				  CMDQ_CTXT_BLOCK_INFO_SET(pfn, WQ_BLOCK_PFN);
+}
+
+static int
+init_cmdq(struct hinic3_cmdq *cmdq, struct hinic3_hwdev *hwdev,
+	  struct hinic3_wq *wq, enum hinic3_cmdq_type q_type)
+{
+	int err = 0;
+	size_t errcode_size;
+	size_t cmd_infos_size;
+
+	cmdq->wq = wq;
+	cmdq->cmdq_type = q_type;
+	cmdq->wrapped = 1;
+
+	rte_spinlock_init(&cmdq->cmdq_lock);
+
+	errcode_size = wq->q_depth * sizeof(*cmdq->errcode);
+	cmdq->errcode = rte_zmalloc(NULL, errcode_size, 0);
+	if (!cmdq->errcode) {
+		PMD_DRV_LOG(ERR, "Allocate errcode for cmdq failed");
+		return -ENOMEM;
+	}
+
+	cmd_infos_size = wq->q_depth * sizeof(*cmdq->cmd_infos);
+	cmdq->cmd_infos = rte_zmalloc(NULL, cmd_infos_size, 0);
+	if (!cmdq->cmd_infos) {
+		PMD_DRV_LOG(ERR, "Allocate cmd info for cmdq failed");
+		err = -ENOMEM;
+		goto cmd_infos_err;
+	}
+
+	cmdq->db_base = hwdev->cmdqs->cmdqs_db_base;
+
+	return 0;
+
+cmd_infos_err:
+	rte_free(cmdq->errcode);
+
+	return err;
+}
+
+static void
+free_cmdq(struct hinic3_cmdq *cmdq)
+{
+	rte_free(cmdq->cmd_infos);
+	rte_free(cmdq->errcode);
+}
+
+static int
+hinic3_set_cmdq_ctxts(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_cmdqs *cmdqs = hwdev->cmdqs;
+	struct hinic3_cmd_cmdq_ctxt cmdq_ctxt;
+	enum hinic3_cmdq_type cmdq_type;
+	u16 out_size = sizeof(cmdq_ctxt);
+	int err;
+
+	cmdq_type = HINIC3_CMDQ_SYNC;
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++) {
+		memset(&cmdq_ctxt, 0, sizeof(cmdq_ctxt));
+		memcpy((void *)&cmdq_ctxt.ctxt_info,
+		       (void *)&cmdqs->cmdq[cmdq_type].cmdq_ctxt,
+		       sizeof(cmdq_ctxt.ctxt_info));
+		cmdq_ctxt.func_idx = hinic3_global_func_id(hwdev);
+		cmdq_ctxt.cmdq_id = cmdq_type;
+
+		err = hinic3_msg_to_mgmt_sync(hwdev, HINIC3_MOD_COMM,
+					      HINIC3_MGMT_CMD_SET_CMDQ_CTXT,
+					      &cmdq_ctxt, sizeof(cmdq_ctxt),
+					      &cmdq_ctxt, &out_size, 0);
+		if (err || !out_size || cmdq_ctxt.status) {
+			PMD_DRV_LOG(ERR,
+				    "Set cmdq ctxt failed, err: %d, status: "
+				    "0x%x, out_size: 0x%x",
+				    err, cmdq_ctxt.status, out_size);
+			return -EFAULT;
+		}
+	}
+
+	cmdqs->status |= HINIC3_CMDQ_ENABLE;
+
+	return 0;
+}
+
+int
+hinic3_reinit_cmdq_ctxts(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_cmdqs *cmdqs = hwdev->cmdqs;
+	enum hinic3_cmdq_type cmdq_type = HINIC3_CMDQ_SYNC;
+
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++) {
+		cmdqs->cmdq[cmdq_type].wrapped = 1;
+		hinic3_wq_wqe_pg_clear(cmdqs->cmdq[cmdq_type].wq);
+	}
+
+	return hinic3_set_cmdq_ctxts(hwdev);
+}
+
+static int
+hinic3_set_cmdqs(struct hinic3_hwdev *hwdev, struct hinic3_cmdqs *cmdqs)
+{
+	void *db_base = NULL;
+	enum hinic3_cmdq_type type, cmdq_type;
+	int err;
+
+	err = hinic3_alloc_db_addr(hwdev, &db_base, HINIC3_DB_TYPE_CMDQ);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Failed to allocate doorbell address");
+		goto alloc_db_err;
+	}
+	cmdqs->cmdqs_db_base = (u8 *)db_base;
+
+	cmdq_type = HINIC3_CMDQ_SYNC;
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++) {
+		err = init_cmdq(&cmdqs->cmdq[cmdq_type], hwdev,
+				&cmdqs->saved_wqs[cmdq_type], cmdq_type);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Initialize cmdq failed");
+			goto init_cmdq_err;
+		}
+
+		cmdq_init_queue_ctxt(&cmdqs->cmdq[cmdq_type],
+				     &cmdqs->cmdq[cmdq_type].cmdq_ctxt);
+	}
+
+	err = hinic3_set_cmdq_ctxts(hwdev);
+	if (err)
+		goto init_cmdq_err;
+
+	return 0;
+
+init_cmdq_err:
+	type = HINIC3_CMDQ_SYNC;
+	for (; type < cmdq_type; type++)
+		free_cmdq(&cmdqs->cmdq[type]);
+
+alloc_db_err:
+	hinic3_cmdq_free(cmdqs->saved_wqs, HINIC3_MAX_CMDQ_TYPES);
+	return -ENOMEM;
+}
+
+int
+hinic3_cmdqs_init(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_cmdqs *cmdqs = NULL;
+	size_t saved_wqs_size;
+	char cmdq_pool_name[RTE_MEMPOOL_NAMESIZE];
+	int err;
+
+	cmdqs = rte_zmalloc(NULL, sizeof(*cmdqs), 0);
+	if (!cmdqs)
+		return -ENOMEM;
+
+	hwdev->cmdqs = cmdqs;
+	cmdqs->hwdev = hwdev;
+
+	saved_wqs_size = HINIC3_MAX_CMDQ_TYPES * sizeof(struct hinic3_wq);
+	cmdqs->saved_wqs = rte_zmalloc(NULL, saved_wqs_size, 0);
+	if (!cmdqs->saved_wqs) {
+		PMD_DRV_LOG(ERR, "Allocate saved wqs failed");
+		err = -ENOMEM;
+		goto alloc_wqs_err;
+	}
+
+	memset(cmdq_pool_name, 0, RTE_MEMPOOL_NAMESIZE);
+	snprintf(cmdq_pool_name, sizeof(cmdq_pool_name), "hinic3_cmdq_%u",
+		       hwdev->port_id);
+
+	cmdqs->cmd_buf_pool = rte_pktmbuf_pool_create(cmdq_pool_name,
+		HINIC3_CMDQ_DEPTH * HINIC3_MAX_CMDQ_TYPES, 0, 0,
+		HINIC3_CMDQ_BUF_SIZE, (int)rte_socket_id());
+	if (!cmdqs->cmd_buf_pool) {
+		PMD_DRV_LOG(ERR, "Create cmdq buffer pool failed");
+		err = -ENOMEM;
+		goto pool_create_err;
+	}
+
+	err = hinic3_cmdq_alloc(cmdqs->saved_wqs, hwdev, HINIC3_MAX_CMDQ_TYPES,
+				HINIC3_CMDQ_WQ_BUF_SIZE, CMDQ_WQEBB_SHIFT,
+				HINIC3_CMDQ_DEPTH);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Allocate cmdq failed");
+		goto cmdq_alloc_err;
+	}
+
+	err = hinic3_set_cmdqs(hwdev, cmdqs);
+	if (err) {
+		PMD_DRV_LOG(ERR, "set_cmdqs failed");
+		goto cmdq_alloc_err;
+	}
+	return 0;
+
+cmdq_alloc_err:
+	rte_mempool_free(cmdqs->cmd_buf_pool);
+
+pool_create_err:
+	rte_free(cmdqs->saved_wqs);
+
+alloc_wqs_err:
+	rte_free(cmdqs);
+
+	return err;
+}
+
+void
+hinic3_cmdqs_free(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_cmdqs *cmdqs = hwdev->cmdqs;
+	enum hinic3_cmdq_type cmdq_type = HINIC3_CMDQ_SYNC;
+
+	cmdqs->status &= ~HINIC3_CMDQ_ENABLE;
+
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++)
+		free_cmdq(&cmdqs->cmdq[cmdq_type]);
+
+	hinic3_cmdq_free(cmdqs->saved_wqs, HINIC3_MAX_CMDQ_TYPES);
+
+	rte_mempool_free(cmdqs->cmd_buf_pool);
+
+	rte_free(cmdqs->saved_wqs);
+
+	rte_free(cmdqs);
+}
+
+static int
+hinic3_cmdq_poll_msg(struct hinic3_cmdq *cmdq, u32 timeout)
+{
+	struct hinic3_cmdq_wqe *wqe = NULL;
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = NULL;
+	struct hinic3_ctrl *ctrl = NULL;
+	struct hinic3_cmdq_cmd_info *cmd_info = NULL;
+	u32 status_info, ctrl_info;
+	u16 ci;
+	int errcode;
+	unsigned long end;
+	int done = 0;
+	int err = 0;
+
+	wqe = hinic3_read_wqe(cmdq->wq, 1, &ci);
+	if (!wqe) {
+		PMD_DRV_LOG(ERR, "No outstanding cmdq msg");
+		return -EINVAL;
+	}
+
+	cmd_info = &cmdq->cmd_infos[ci];
+	if (cmd_info->cmd_type == HINIC3_CMD_TYPE_NONE) {
+		PMD_DRV_LOG(ERR,
+			    "Cmdq msg has not been filled and send to hw, "
+			    "or get TMO msg ack. cmdq ci: %u",
+			    ci);
+		return -EINVAL;
+	}
+
+	/* Only arm bit is using scmd wqe, the wqe is lcmd. */
+	wqe_lcmd = &wqe->wqe_lcmd;
+	ctrl = &wqe_lcmd->ctrl;
+	end = jiffies + msecs_to_jiffies(timeout);
+	do {
+		ctrl_info = hinic3_hw_cpu32((ctrl)->ctrl_info);
+		if (WQE_COMPLETED(ctrl_info)) {
+			done = 1;
+			break;
+		}
+
+		rte_delay_us(1);
+	} while (time_before(jiffies, end));
+
+	if (done) {
+		status_info = hinic3_hw_cpu32(wqe_lcmd->status.status_info);
+		errcode = WQE_ERRCODE_GET(status_info, VAL);
+		cmdq_update_errcode(cmdq, ci, errcode);
+		clear_wqe_complete_bit(cmdq, wqe);
+		err = 0;
+	} else {
+		PMD_DRV_LOG(ERR, "Poll cmdq msg time out, ci: %u", ci);
+		err = -ETIMEDOUT;
+	}
+
+	/* Set this cmd invalid. */
+	cmd_info->cmd_type = HINIC3_CMD_TYPE_NONE;
+
+	return err;
+}
drivers/net/hinic3/base/hinic3_cmdq.h new file +230 -0

230 lines not on this page · raw message

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

Re: [V5 04/18] net/hinic3: add support for cmdq mechanism

Quoted 2 lines · Feifei Wang

From: Xin Wang <[email protected]>

The title suggest: net/hns3: add cmdq mechanism

Quoted 2 lines

Micocode is named ucode in SP series NIC. Its main responsibility is data

Micocode -> Microcode ?

Quoted 440 lines

transmission and reception. But it can also handle some administration

works. It uses cmdq mechanism. This patch introduces data structures,

initialization, interfaces, and commands sending functions of cmdq.

---

 drivers/net/hinic3/base/hinic3_cmdq.c | 978 ++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_cmdq.h | 230 ++++++
 2 files changed, 1208 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.c
 create mode 100644 drivers/net/hinic3/base/hinic3_cmdq.h
drivers/net/hinic3/base/hinic3_cmdq.c +0 -0

new file mode 100644

index 0000000000..5b5c1da999

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_cmdq.c

drivers/net/hinic3/base/hinic3_cmdq.c +200 -0
@@ -0,0 +1,978 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#include <rte_atomic.h>
 
+#include <rte_mbuf.h>
 
+
 
+#include "hinic3_compat.h"
 
+#include "hinic3_cmd.h"
 
+#include "hinic3_cmdq.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_hwif.h"
 
+#include "hinic3_mgmt.h"
 
+#include "hinic3_wq.h"
 
+
 
+#define CMDQ_CMD_TIMEOUT 5000 /**< Millisecond. */
 
+
 
+#define UPPER_8_BITS(data) (((data) >> 8) & 0xFF)
 
+#define LOWER_8_BITS(data) ((data) & 0xFF)
 
+
 
+#define CMDQ_DB_INFO_HI_PROD_IDX_SHIFT 0
 
+#define CMDQ_DB_INFO_HI_PROD_IDX_MASK  0xFFU
 
+
 
+#define CMDQ_DB_INFO_SET(val, member)                  \
 
+	((((u32)(val)) & CMDQ_DB_INFO_##member##_MASK) \
 
+	 << CMDQ_DB_INFO_##member##_SHIFT)
 
+#define CMDQ_DB_INFO_UPPER_32(val) ((u64)(val) << 32)
 
+
 
+#define CMDQ_DB_HEAD_QUEUE_TYPE_SHIFT 23
 
+#define CMDQ_DB_HEAD_CMDQ_TYPE_SHIFT  24
 
+#define CMDQ_DB_HEAD_SRC_TYPE_SHIFT   27
 
+#define CMDQ_DB_HEAD_QUEUE_TYPE_MASK  0x1U
 
+#define CMDQ_DB_HEAD_CMDQ_TYPE_MASK   0x7U
 
+#define CMDQ_DB_HEAD_SRC_TYPE_MASK    0x1FU
 
+#define CMDQ_DB_HEAD_SET(val, member)                  \
 
+	((((u32)(val)) & CMDQ_DB_HEAD_##member##_MASK) \
 
+	 << CMDQ_DB_HEAD_##member##_SHIFT)
 
+
 
+#define CMDQ_CTRL_PI_SHIFT	    0
 
+#define CMDQ_CTRL_CMD_SHIFT	    16
 
+#define CMDQ_CTRL_MOD_SHIFT	    24
 
+#define CMDQ_CTRL_ACK_TYPE_SHIFT    29
 
+#define CMDQ_CTRL_HW_BUSY_BIT_SHIFT 31
 
+
 
+#define CMDQ_CTRL_PI_MASK	   0xFFFFU
 
+#define CMDQ_CTRL_CMD_MASK	   0xFFU
 
+#define CMDQ_CTRL_MOD_MASK	   0x1FU
 
+#define CMDQ_CTRL_ACK_TYPE_MASK	   0x3U
 
+#define CMDQ_CTRL_HW_BUSY_BIT_MASK 0x1U
 
+
 
+#define CMDQ_CTRL_SET(val, member) \
 
+	(((u32)(val) & CMDQ_CTRL_##member##_MASK) << CMDQ_CTRL_##member##_SHIFT)
 
+
 
+#define CMDQ_CTRL_GET(val, member) \
 
+	(((val) >> CMDQ_CTRL_##member##_SHIFT) & CMDQ_CTRL_##member##_MASK)
 
+
 
+#define CMDQ_WQE_HEADER_BUFDESC_LEN_SHIFT	0
 
+#define CMDQ_WQE_HEADER_COMPLETE_FMT_SHIFT	15
 
+#define CMDQ_WQE_HEADER_DATA_FMT_SHIFT		22
 
+#define CMDQ_WQE_HEADER_COMPLETE_REQ_SHIFT	23
 
+#define CMDQ_WQE_HEADER_COMPLETE_SECT_LEN_SHIFT 27
 
+#define CMDQ_WQE_HEADER_CTRL_LEN_SHIFT		29
 
+#define CMDQ_WQE_HEADER_HW_BUSY_BIT_SHIFT	31
 
+
 
+#define CMDQ_WQE_HEADER_BUFDESC_LEN_MASK       0xFFU
 
+#define CMDQ_WQE_HEADER_COMPLETE_FMT_MASK      0x1U
 
+#define CMDQ_WQE_HEADER_DATA_FMT_MASK	       0x1U
 
+#define CMDQ_WQE_HEADER_COMPLETE_REQ_MASK      0x1U
 
+#define CMDQ_WQE_HEADER_COMPLETE_SECT_LEN_MASK 0x3U
 
+#define CMDQ_WQE_HEADER_CTRL_LEN_MASK	       0x3U
 
+#define CMDQ_WQE_HEADER_HW_BUSY_BIT_MASK       0x1U
 
+
 
+#define CMDQ_WQE_HEADER_SET(val, member)                \
 
+	(((u32)(val) & CMDQ_WQE_HEADER_##member##_MASK) \
 
+	 << CMDQ_WQE_HEADER_##member##_SHIFT)
 
+
 
+#define CMDQ_WQE_HEADER_GET(val, member)               \
 
+	(((val) >> CMDQ_WQE_HEADER_##member##_SHIFT) & \
 
+	 CMDQ_WQE_HEADER_##member##_MASK)
 
+
 
+#define CMDQ_CTXT_CURR_WQE_PAGE_PFN_SHIFT 0
 
+#define CMDQ_CTXT_EQ_ID_SHIFT		  53
 
+#define CMDQ_CTXT_CEQ_ARM_SHIFT		  61
 
+#define CMDQ_CTXT_CEQ_EN_SHIFT		  62
 
+#define CMDQ_CTXT_HW_BUSY_BIT_SHIFT	  63
 
+
 
+#define CMDQ_CTXT_CURR_WQE_PAGE_PFN_MASK 0xFFFFFFFFFFFFF
 
+#define CMDQ_CTXT_EQ_ID_MASK		 0xFF
 
+#define CMDQ_CTXT_CEQ_ARM_MASK		 0x1
 
+#define CMDQ_CTXT_CEQ_EN_MASK		 0x1
 
+#define CMDQ_CTXT_HW_BUSY_BIT_MASK	 0x1
 
+
 
+#define CMDQ_CTXT_PAGE_INFO_SET(val, member) \
 
+	(((u64)(val) & CMDQ_CTXT_##member##_MASK) << CMDQ_CTXT_##member##_SHIFT)
 
+
 
+#define CMDQ_CTXT_WQ_BLOCK_PFN_SHIFT 0
 
+#define CMDQ_CTXT_CI_SHIFT	     52
 
+
 
+#define CMDQ_CTXT_WQ_BLOCK_PFN_MASK 0xFFFFFFFFFFFFF
 
+#define CMDQ_CTXT_CI_MASK	    0xFFF
 
+
 
+#define CMDQ_CTXT_BLOCK_INFO_SET(val, member) \
 
+	(((u64)(val) & CMDQ_CTXT_##member##_MASK) << CMDQ_CTXT_##member##_SHIFT)
 
+
 
+#define SAVED_DATA_ARM_SHIFT 31
 
+
 
+#define SAVED_DATA_ARM_MASK 0x1U
 
+
 
+#define SAVED_DATA_SET(val, member) \
 
+	(((val) & SAVED_DATA_##member##_MASK) << SAVED_DATA_##member##_SHIFT)
 
+
 
+#define SAVED_DATA_CLEAR(val, member) \
 
+	((val) & (~(SAVED_DATA_##member##_MASK << SAVED_DATA_##member##_SHIFT)))
 
+
 
+#define WQE_ERRCODE_VAL_SHIFT 0
 
+
 
+#define WQE_ERRCODE_VAL_MASK 0x7FFFFFFF
 
+
 
+#define WQE_ERRCODE_GET(val, member) \
 
+	(((val) >> WQE_ERRCODE_##member##_SHIFT) & WQE_ERRCODE_##member##_MASK)
 
+
 
+#define WQE_COMPLETED(ctrl_info) CMDQ_CTRL_GET(ctrl_info, HW_BUSY_BIT)
 
+
 
+#define WQE_HEADER(wqe) ((struct hinic3_cmdq_header *)(wqe))
 
+
 
+#define CMDQ_DB_PI_OFF(pi) (((u16)LOWER_8_BITS(pi)) << 3)
 
+
 
+#define CMDQ_DB_ADDR(db_base, pi) (((u8 *)(db_base)) + CMDQ_DB_PI_OFF(pi))
 
+
 
+#define CMDQ_PFN(addr, page_size) ((addr) >> (ilog2(page_size)))
 
+
 
+#define FIRST_DATA_TO_WRITE_LAST sizeof(u64)
 
+
 
+#define WQE_LCMD_SIZE 64
 
+#define WQE_SCMD_SIZE 64
 
+
 
+#define COMPLETE_LEN 3
 
+
 
+#define CMDQ_WQEBB_SIZE	 64
 
+#define CMDQ_WQEBB_SHIFT 6
 
+
 
+#define CMDQ_WQE_SIZE 64
 
+
 
+#define HINIC3_CMDQ_WQ_BUF_SIZE 4096
 
+
 
+#define WQE_NUM_WQEBBS(wqe_size, wq)                                 \
 
+	({                                                           \
 
+		typeof(wq) __wq = (wq);                              \
 
+		(u16)(RTE_ALIGN((u32)(wqe_size), __wq->wqebb_size) / \
 
+		      __wq->wqebb_size);                             \
 
+	})
 
+
 
+#define cmdq_to_cmdqs(cmdq)                                                   \
 
+	({                                                                    \
 
+		typeof(cmdq) __cmdq = (cmdq);                                 \
 
+		container_of(__cmdq - __cmdq->cmdq_type, struct hinic3_cmdqs, \
 
+			     __cmdq[0]);                                      \
 
+	})
 
+
 
+#define WAIT_CMDQ_ENABLE_TIMEOUT 300
 
+
 
+static int hinic3_cmdq_poll_msg(struct hinic3_cmdq *cmdq, u32 timeout);
 
+
 
+bool
 
+hinic3_cmdq_idle(struct hinic3_cmdq *cmdq)
 
+{
 
+	struct hinic3_wq *wq = cmdq->wq;
 
+
 
+	return rte_atomic_load_explicit(&wq->delta, rte_memory_order_seq_cst) ==
 
+	       wq->q_depth;
 
+}
 
+
 
+struct hinic3_cmd_buf *
 
+hinic3_alloc_cmd_buf(void *hwdev)
 
+{
 
+	struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs;
 
+	struct hinic3_cmd_buf *cmd_buf;
 
+
 
+	cmd_buf = rte_zmalloc(NULL, sizeof(*cmd_buf), 0);
 
+	if (!cmd_buf) {
 
+		PMD_DRV_LOG(ERR, "Allocate cmd buffer failed");
 
+		return NULL;
 
+	}
 
+
 
+	cmd_buf->mbuf = rte_pktmbuf_alloc(cmdqs->cmd_buf_pool);
 
+	if (!cmd_buf->mbuf) {
 
+		PMD_DRV_LOG(ERR, "Allocate cmd from the pool failed");
 
+		goto alloc_pci_buf_err;
 
+	}
 
+
 
+	cmd_buf->dma_addr = rte_mbuf_data_iova(cmd_buf->mbuf);
 
+	cmd_buf->buf = rte_pktmbuf_mtod(cmd_buf->mbuf, void *);
 
+
 
+	return cmd_buf;
 
+
 
+alloc_pci_buf_err:
 
+	rte_free(cmd_buf);
 
+	return NULL;
 
+}
 
+

drivers/net/hinic3/base/hinic3_cmdq.c line 205

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+void
 
+hinic3_free_cmd_buf(struct hinic3_cmd_buf *cmd_buf)
 
+{
 
+	rte_pktmbuf_free(cmd_buf->mbuf);
 
+

no need this line

Quoted 314 lines
drivers/net/hinic3/base/hinic3_cmdq.c +157 -0
+	rte_free(cmd_buf);
 
+}
 
+
 
+static u32
 
+cmdq_wqe_size(enum cmdq_wqe_type wqe_type)
 
+{
 
+	u32 wqe_size = 0;
 
+
 
+	switch (wqe_type) {
 
+	case WQE_LCMD_TYPE:
 
+		wqe_size = WQE_LCMD_SIZE;
 
+		break;
 
+	case WQE_SCMD_TYPE:
 
+		wqe_size = WQE_SCMD_SIZE;
 
+		break;
 
+	default:
 
+		break;
 
+	}
 
+
 
+	return wqe_size;
 
+}
 
+
 
+static int
 
+cmdq_get_wqe_size(enum bufdesc_len len)
 
+{
 
+	int wqe_size = 0;
 
+
 
+	switch (len) {
 
+	case BUFDESC_LCMD_LEN:
 
+		wqe_size = WQE_LCMD_SIZE;
 
+		break;
 
+	case BUFDESC_SCMD_LEN:
 
+		wqe_size = WQE_SCMD_SIZE;
 
+		break;
 
+	default:
 
+		break;
 
+	}
 
+
 
+	return wqe_size;
 
+}
 
+
 
+static void
 
+cmdq_set_completion(struct hinic3_cmdq_completion *complete,
 
+		    struct hinic3_cmd_buf *buf_out)
 
+{
 
+	struct hinic3_sge_resp *sge_resp = &complete->sge_resp;
 
+
 
+	hinic3_set_sge(&sge_resp->sge, buf_out->dma_addr, HINIC3_CMDQ_BUF_SIZE);
 
+}
 
+
 
+static void
 
+cmdq_set_lcmd_bufdesc(struct hinic3_cmdq_wqe_lcmd *wqe,
 
+		      struct hinic3_cmd_buf *buf_in)
 
+{
 
+	hinic3_set_sge(&wqe->buf_desc.sge, buf_in->dma_addr, buf_in->size);
 
+}
 
+
 
+static void
 
+cmdq_set_db(struct hinic3_cmdq *cmdq, enum hinic3_cmdq_type cmdq_type,
 
+	    u16 prod_idx)
 
+{
 
+	u64 db = 0;
 
+
 
+	/* Hardware will do endianness converting. */
 
+	db = CMDQ_DB_INFO_SET(UPPER_8_BITS(prod_idx), HI_PROD_IDX);
 
+	db = CMDQ_DB_INFO_UPPER_32(db) |
 
+	     CMDQ_DB_HEAD_SET(HINIC3_DB_CMDQ_TYPE, QUEUE_TYPE) |
 
+	     CMDQ_DB_HEAD_SET(cmdq_type, CMDQ_TYPE) |
 
+	     CMDQ_DB_HEAD_SET(HINIC3_DB_SRC_CMDQ_TYPE, SRC_TYPE);
 
+
 
+	/**< Write all before the doorbell. */
 
+	rte_atomic_thread_fence(rte_memory_order_release);
 
+
 
+	rte_write64(db, CMDQ_DB_ADDR(cmdq->db_base, prod_idx));
 
+}
 
+
 
+static void
 
+cmdq_wqe_fill(void *dst, void *src)
 
+{
 
+	memcpy((void *)((u8 *)dst + FIRST_DATA_TO_WRITE_LAST),
 
+	       (void *)((u8 *)src + FIRST_DATA_TO_WRITE_LAST),
 
+	       CMDQ_WQE_SIZE - FIRST_DATA_TO_WRITE_LAST);
 
+
 
+	/* The first 8 bytes should be written last. */
 
+	rte_atomic_thread_fence(rte_memory_order_release);
 
+
 
+	*(u64 *)dst = *(u64 *)src;
 
+}
 
+
 
+static void
 
+cmdq_prepare_wqe_ctrl(struct hinic3_cmdq_wqe *wqe, int wrapped,
 
+		      enum hinic3_mod_type mod, u8 cmd, u16 prod_idx,
 
+		      enum completion_format complete_format,
 
+		      enum data_format local_data_format,
 
+		      enum bufdesc_len buf_len)
 
+{
 
+	struct hinic3_ctrl *ctrl = NULL;
 
+	enum ctrl_sect_len ctrl_len;
 
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = NULL;
 
+	struct hinic3_cmdq_wqe_scmd *wqe_scmd = NULL;
 
+	u32 saved_data = WQE_HEADER(wqe)->saved_data;
 
+
 
+	if (local_data_format == DATA_SGE) {
 
+		wqe_lcmd = &wqe->wqe_lcmd;
 
+
 
+		wqe_lcmd->status.status_info = 0;
 
+		ctrl = &wqe_lcmd->ctrl;
 
+		ctrl_len = CTRL_SECT_LEN;
 
+	} else {
 
+		wqe_scmd = &wqe->inline_wqe.wqe_scmd;
 
+
 
+		wqe_scmd->status.status_info = 0;
 
+		ctrl = &wqe_scmd->ctrl;
 
+		ctrl_len = CTRL_DIRECT_SECT_LEN;
 
+	}
 
+
 
+	ctrl->ctrl_info = CMDQ_CTRL_SET(prod_idx, PI) |
 
+			  CMDQ_CTRL_SET(cmd, CMD) | CMDQ_CTRL_SET(mod, MOD) |
 
+			  CMDQ_CTRL_SET(HINIC3_ACK_TYPE_CMDQ, ACK_TYPE);
 
+
 
+	WQE_HEADER(wqe)->header_info =
 
+		CMDQ_WQE_HEADER_SET(buf_len, BUFDESC_LEN) |
 
+		CMDQ_WQE_HEADER_SET(complete_format, COMPLETE_FMT) |
 
+		CMDQ_WQE_HEADER_SET(local_data_format, DATA_FMT) |
 
+		CMDQ_WQE_HEADER_SET(CEQ_SET, COMPLETE_REQ) |
 
+		CMDQ_WQE_HEADER_SET(COMPLETE_LEN, COMPLETE_SECT_LEN) |
 
+		CMDQ_WQE_HEADER_SET(ctrl_len, CTRL_LEN) |
 
+		CMDQ_WQE_HEADER_SET((u32)wrapped, HW_BUSY_BIT);
 
+
 
+	saved_data &= SAVED_DATA_CLEAR(saved_data, ARM);
 
+	if (cmd == CMDQ_SET_ARM_CMD && mod == HINIC3_MOD_COMM)
 
+		WQE_HEADER(wqe)->saved_data = saved_data |
 
+					      SAVED_DATA_SET(1, ARM);
 
+	else
 
+		WQE_HEADER(wqe)->saved_data = saved_data;
 
+}
 
+
 
+static void
 
+cmdq_set_lcmd_wqe(struct hinic3_cmdq_wqe *wqe, enum cmdq_cmd_type cmd_type,
 
+		  struct hinic3_cmd_buf *buf_in, struct hinic3_cmd_buf *buf_out,
 
+		  int wrapped, enum hinic3_mod_type mod, u8 cmd, u16 prod_idx)
 
+{
 
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = &wqe->wqe_lcmd;
 
+	enum completion_format complete_format = COMPLETE_DIRECT;
 
+
 
+	switch (cmd_type) {
 
+	case SYNC_CMD_DIRECT_RESP:
 
+		complete_format = COMPLETE_DIRECT;
 
+		wqe_lcmd->completion.direct_resp = 0;
 
+		break;
 
+	case SYNC_CMD_SGE_RESP:
 
+		if (buf_out) {
 
+			complete_format = COMPLETE_SGE;
 
+			cmdq_set_completion(&wqe_lcmd->completion, buf_out);
 
+		}
 
+		break;
 
+	case ASYNC_CMD:

drivers/net/hinic3/base/hinic3_cmdq.c line 367

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+		complete_format = COMPLETE_DIRECT;
 
+		wqe_lcmd->completion.direct_resp = 0;
 
+		wqe_lcmd->buf_desc.saved_async_buf = (u64)(buf_in);
 
+		break;
 
+	default:

If never get this, how about add RTE_ASSERT or emit one error message.

Quoted 160 lines
drivers/net/hinic3/base/hinic3_cmdq.c +80 -0
+		break;
 
+	}
 
+
 
+	cmdq_prepare_wqe_ctrl(wqe, wrapped, mod, cmd, prod_idx, complete_format,
 
+			      DATA_SGE, BUFDESC_LCMD_LEN);
 
+
 
+	cmdq_set_lcmd_bufdesc(wqe_lcmd, buf_in);
 
+}
 
+
 
+/**
 
+ * Prepare necessary context for command queue, send a synchronous command with
 
+ * a direct response to hardware. It waits for completion of command by polling
 
+ * command queue for a response.
 
+ *
 
+ * @param[in] cmdq
 
+ * The command queue object that represents the queue to send the command to.
 
+ * @param[in] mod
 
+ * The module type that the command belongs to.
 
+ * @param[in] cmd
 
+ * The command to be executed.
 
+ * @param[in] buf_in
 
+ * The input buffer containing the command parameters.
 
+ * @param[out] out_param
 
+ * A pointer to the location where the response data will be stored, if
 
+ * available.
 
+ * @param[in] timeout
 
+ * The timeout value (ms) to wait for the command completion. If zero, a default
 
+ * timeout will be used.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ * - -EBUSY: The command queue is busy.
 
+ * - -ETIMEDOUT: The command did not complete within the specified timeout.
 
+ */
 
+static int
 
+cmdq_sync_cmd_direct_resp(struct hinic3_cmdq *cmdq, enum hinic3_mod_type mod,
 
+			  u8 cmd, struct hinic3_cmd_buf *buf_in, u64 *out_param,
 
+			  u32 timeout)
 
+{
 
+	struct hinic3_wq *wq = cmdq->wq;
 
+	struct hinic3_cmdq_wqe wqe;
 
+	struct hinic3_cmdq_wqe *curr_wqe = NULL;
 
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = NULL;
 
+	u16 curr_prod_idx, next_prod_idx, num_wqebbs;
 
+	int wrapped;
 
+	u32 timeo, wqe_size;
 
+	int err;
 
+
 
+	wqe_size = cmdq_wqe_size(WQE_LCMD_TYPE);
 
+	num_wqebbs = WQE_NUM_WQEBBS(wqe_size, wq);
 
+
 
+	/* Keep wrapped and doorbell index correct. */
 
+	rte_spinlock_lock(&cmdq->cmdq_lock);
 
+
 
+	curr_wqe = hinic3_get_wqe(cmdq->wq, num_wqebbs, &curr_prod_idx);
 
+	if (!curr_wqe) {
 
+		err = -EBUSY;
 
+		goto cmdq_unlock;
 
+	}
 
+
 
+	memset(&wqe, 0, sizeof(wqe));
 
+	wrapped = cmdq->wrapped;
 
+
 
+	next_prod_idx = curr_prod_idx + num_wqebbs;
 
+	if (next_prod_idx >= wq->q_depth) {
 
+		cmdq->wrapped = !cmdq->wrapped;
 
+		next_prod_idx -= wq->q_depth;
 
+	}
 
+
 
+	cmdq_set_lcmd_wqe(&wqe, SYNC_CMD_DIRECT_RESP, buf_in, NULL, wrapped,
 
+			  mod, cmd, curr_prod_idx);
 
+
 
+	/* The data that is written to HW should be in Big Endian Format. */
 
+	hinic3_hw_be32_len(&wqe, (int)wqe_size);
 
+
 
+	/* Cmdq wqe is not shadow, therefore wqe will be written to wq. */
 
+	cmdq_wqe_fill(curr_wqe, &wqe);
 
+
 
+	cmdq->cmd_infos[curr_prod_idx].cmd_type = HINIC3_CMD_TYPE_DIRECT_RESP;
 
+

drivers/net/hinic3/base/hinic3_cmdq.c line 452

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+	cmdq_set_db(cmdq, HINIC3_CMDQ_SYNC, next_prod_idx);
 
+
 
+	timeo = msecs_to_jiffies(timeout ? timeout : CMDQ_CMD_TIMEOUT);
 
+	err = hinic3_cmdq_poll_msg(cmdq, timeo);
 
+	if (err) {

please keep explicit compare, e.g. if (err != 0) just like previous commits.

Quoted 107 lines
drivers/net/hinic3/base/hinic3_cmdq.c +53 -0
+		PMD_DRV_LOG(ERR, "Cmdq poll msg ack failed, prod idx: 0x%x",
 
+			    curr_prod_idx);
 
+		err = -ETIMEDOUT;
 
+		goto cmdq_unlock;
 
+	}
 
+
 
+	rte_smp_rmb(); /**< Read error code after completion. */
 
+
 
+	if (out_param) {
 
+		wqe_lcmd = &curr_wqe->wqe_lcmd;
 
+		*out_param = cpu_to_be64(wqe_lcmd->completion.direct_resp);
 
+	}
 
+
 
+	if (cmdq->errcode[curr_prod_idx])
 
+		err = cmdq->errcode[curr_prod_idx];
 
+
 
+cmdq_unlock:
 
+	rte_spinlock_unlock(&cmdq->cmdq_lock);
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Send a synchronous command with detailed response and wait for the
 
+ * completion.
 
+ *
 
+ * @param[in] cmdq
 
+ * The command queue object representing the queue to send the command to.
 
+ * @param[in] mod
 
+ * The module type that the command belongs to.
 
+ * @param[in] cmd
 
+ * The command to be executed.
 
+ * @param[in] buf_in
 
+ * The input buffer containing the parameters for the command.
 
+ * @param[out] buf_out
 
+ * The output buffer where the detailed response from the hardware will be
 
+ * stored.
 
+ * @param[in] timeout
 
+ * The timeout value (ms) to wait for the command completion. If zero, a default
 
+ * timeout will be used.
 
+ *
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ * - -EBUSY: The command queue is busy.
 
+ * - -ETIMEDOUT: The command did not complete within the specified timeout.
 
+ */
 
+static int
 
+cmdq_sync_cmd_detail_resp(struct hinic3_cmdq *cmdq, enum hinic3_mod_type mod,
 
+			  u8 cmd, struct hinic3_cmd_buf *buf_in,
 
+			  struct hinic3_cmd_buf *buf_out, u32 timeout)
 
+{
 
+	struct hinic3_wq *wq = cmdq->wq;
 
+	struct hinic3_cmdq_wqe wqe;

drivers/net/hinic3/base/hinic3_cmdq.c line 510

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+	struct hinic3_cmdq_wqe *curr_wqe = NULL;
 
+	u16 curr_prod_idx, next_prod_idx, num_wqebbs;
 
+	int wrapped;
 
+	u32 timeo, wqe_size;
 
+	int err;

Prefer define it in inverted triangle.

drivers/net/hinic3/base/hinic3_cmdq.c line 419

Quoted 9 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
+
 
+	wqe_size = cmdq_wqe_size(WQE_LCMD_TYPE);
 
+	num_wqebbs = WQE_NUM_WQEBBS(wqe_size, wq);
 
+
 
+	/* Keep wrapped and doorbell index correct. */

this comment has no meaning.

drivers/net/hinic3/base/hinic3_cmdq.c line 423

Quoted 8 lines
drivers/net/hinic3/base/hinic3_cmdq.c +4 -0
+	rte_spinlock_lock(&cmdq->cmdq_lock);
 
+
 
+	curr_wqe = hinic3_get_wqe(cmdq->wq, num_wqebbs, &curr_prod_idx);
 
+	if (!curr_wqe) {

if (cur_wqe == NULL)

Quoted 136 lines
drivers/net/hinic3/base/hinic3_cmdq.c +68 -0
+		err = -EBUSY;
 
+		goto cmdq_unlock;
 
+	}
 
+
 
+	memset(&wqe, 0, sizeof(wqe));
 
+	wrapped = cmdq->wrapped;
 
+
 
+	next_prod_idx = curr_prod_idx + num_wqebbs;
 
+	if (next_prod_idx >= wq->q_depth) {
 
+		cmdq->wrapped = !cmdq->wrapped;
 
+		next_prod_idx -= wq->q_depth;
 
+	}
 
+
 
+	cmdq_set_lcmd_wqe(&wqe, SYNC_CMD_SGE_RESP, buf_in, buf_out, wrapped,
 
+			  mod, cmd, curr_prod_idx);
 
+
 
+	/* The data that is written to HW should be in Big Endian Format. */
 
+	hinic3_hw_be32_len(&wqe, (int)wqe_size);
 
+
 
+	/* Cmdq wqe is not shadow, therefore wqe will be written to wq. */
 
+	cmdq_wqe_fill(curr_wqe, &wqe);
 
+
 
+	cmdq->cmd_infos[curr_prod_idx].cmd_type = HINIC3_CMD_TYPE_SGE_RESP;
 
+
 
+	cmdq_set_db(cmdq, cmdq->cmdq_type, next_prod_idx);
 
+
 
+	timeo = msecs_to_jiffies(timeout ? timeout : CMDQ_CMD_TIMEOUT);
 
+	err = hinic3_cmdq_poll_msg(cmdq, timeo);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Cmdq poll msg ack failed, prod idx: 0x%x",
 
+			    curr_prod_idx);
 
+		err = -ETIMEDOUT;
 
+		goto cmdq_unlock;
 
+	}
 
+
 
+	rte_smp_rmb(); /**< Read error code after completion. */
 
+
 
+	if (cmdq->errcode[curr_prod_idx])
 
+		err = cmdq->errcode[curr_prod_idx];
 
+
 
+cmdq_unlock:
 
+	rte_spinlock_unlock(&cmdq->cmdq_lock);
 
+
 
+	return err;
 
+}
 
+
 
+static int
 
+cmdq_params_valid(void *hwdev, struct hinic3_cmd_buf *buf_in)
 
+{
 
+	if (!buf_in || !hwdev) {
 
+		PMD_DRV_LOG(ERR, "Invalid CMDQ buffer or hwdev is NULL");
 
+		return -EINVAL;
 
+	}
 
+
 
+	if (buf_in->size == 0 || buf_in->size > HINIC3_CMDQ_BUF_SIZE) {
 
+		PMD_DRV_LOG(ERR, "Invalid CMDQ buffer size: 0x%x",
 
+			    buf_in->size);
 
+		return -EINVAL;
 
+	}
 
+
 
+	return 0;
 
+}
 
+
 
+static int
 
+wait_cmdqs_enable(struct hinic3_cmdqs *cmdqs)
 
+{
 
+	unsigned long end;
 
+

drivers/net/hinic3/base/hinic3_cmdq.c line 592

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+	end = jiffies + msecs_to_jiffies(WAIT_CMDQ_ENABLE_TIMEOUT);
 
+	do {
 
+		if (cmdqs->status & HINIC3_CMDQ_ENABLE)
 
+			return 0;
 
+	} while (time_before(jiffies, end));

Prefer use rte_delay_ms other than global jiffies.

you need to keep jiffies updated in each process whether in main-process or secondary-process.

drivers/net/hinic3/base/hinic3_cmdq.c line 598

Quoted 12 lines
drivers/net/hinic3/base/hinic3_cmdq.c +6 -0
+
 
+	return -EBUSY;
 
+}
 
+
 
+int
 
+hinic3_cmdq_direct_resp(void *hwdev, enum hinic3_mod_type mod, u8 cmd,

why define the hwdev as void * type? Let's use the compiler as much as possible.

Quoted 302 lines
drivers/net/hinic3/base/hinic3_cmdq.c +151 -0
+			struct hinic3_cmd_buf *buf_in, u64 *out_param,
 
+			u32 timeout)
 
+{
 
+	struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs;
 
+	int err;
 
+
 
+	err = cmdq_params_valid(hwdev, buf_in);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Invalid cmdq parameters");
 
+		return err;
 
+	}
 
+
 
+	err = wait_cmdqs_enable(cmdqs);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Cmdq is disabled");
 
+		return err;
 
+	}
 
+
 
+	return cmdq_sync_cmd_direct_resp(&cmdqs->cmdq[HINIC3_CMDQ_SYNC], mod,
 
+					 cmd, buf_in, out_param, timeout);
 
+}
 
+
 
+int
 
+hinic3_cmdq_detail_resp(void *hwdev, enum hinic3_mod_type mod, u8 cmd,
 
+			struct hinic3_cmd_buf *buf_in,
 
+			struct hinic3_cmd_buf *buf_out, u32 timeout)
 
+{
 
+	struct hinic3_cmdqs *cmdqs = ((struct hinic3_hwdev *)hwdev)->cmdqs;
 
+	int err;
 
+
 
+	err = cmdq_params_valid(hwdev, buf_in);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Invalid cmdq parameters");
 
+		return err;
 
+	}
 
+
 
+	err = wait_cmdqs_enable(cmdqs);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Cmdq is disabled");
 
+		return err;
 
+	}
 
+
 
+	return cmdq_sync_cmd_detail_resp(&cmdqs->cmdq[HINIC3_CMDQ_SYNC], mod,
 
+					 cmd, buf_in, buf_out, timeout);
 
+}
 
+
 
+static void
 
+cmdq_update_errcode(struct hinic3_cmdq *cmdq, u16 prod_idx, int errcode)
 
+{
 
+	cmdq->errcode[prod_idx] = errcode;
 
+}
 
+
 
+static void
 
+clear_wqe_complete_bit(struct hinic3_cmdq *cmdq, struct hinic3_cmdq_wqe *wqe)
 
+{
 
+	struct hinic3_ctrl *ctrl = NULL;
 
+	u32 header_info = hinic3_hw_cpu32(WQE_HEADER(wqe)->header_info);
 
+	int buf_len = CMDQ_WQE_HEADER_GET(header_info, BUFDESC_LEN);
 
+	int wqe_size = cmdq_get_wqe_size(buf_len);
 
+	u16 num_wqebbs;
 
+
 
+	if (wqe_size == WQE_LCMD_SIZE)
 
+		ctrl = &wqe->wqe_lcmd.ctrl;
 
+	else
 
+		ctrl = &wqe->inline_wqe.wqe_scmd.ctrl;
 
+
 
+	/* Clear HW busy bit. */
 
+	ctrl->ctrl_info = 0;
 
+
 
+	rte_atomic_thread_fence(rte_memory_order_release); /**< Verify wqe is cleared. */
 
+
 
+	num_wqebbs = WQE_NUM_WQEBBS(wqe_size, cmdq->wq);
 
+	hinic3_put_wqe(cmdq->wq, num_wqebbs);
 
+}
 
+
 
+static void
 
+cmdq_init_queue_ctxt(struct hinic3_cmdq *cmdq,
 
+		     struct hinic3_cmdq_ctxt_info *ctxt_info)
 
+{
 
+	struct hinic3_wq *wq = cmdq->wq;
 
+	u64 wq_first_page_paddr, pfn;
 
+
 
+	u16 start_ci = (u16)(wq->cons_idx);
 
+
 
+	/* The data in the HW is in Big Endian Format. */
 
+	wq_first_page_paddr = wq->queue_buf_paddr;
 
+
 
+	pfn = CMDQ_PFN(wq_first_page_paddr, RTE_PGSIZE_4K);
 
+	ctxt_info->curr_wqe_page_pfn =
 
+		CMDQ_CTXT_PAGE_INFO_SET(1, HW_BUSY_BIT) |
 
+		CMDQ_CTXT_PAGE_INFO_SET(0, CEQ_EN) |
 
+		CMDQ_CTXT_PAGE_INFO_SET(0, CEQ_ARM) |
 
+		CMDQ_CTXT_PAGE_INFO_SET(HINIC3_CEQ_ID_CMDQ, EQ_ID) |
 
+		CMDQ_CTXT_PAGE_INFO_SET(pfn, CURR_WQE_PAGE_PFN);
 
+
 
+	ctxt_info->wq_block_pfn = CMDQ_CTXT_BLOCK_INFO_SET(start_ci, CI) |
 
+				  CMDQ_CTXT_BLOCK_INFO_SET(pfn, WQ_BLOCK_PFN);
 
+}
 
+
 
+static int
 
+init_cmdq(struct hinic3_cmdq *cmdq, struct hinic3_hwdev *hwdev,
 
+	  struct hinic3_wq *wq, enum hinic3_cmdq_type q_type)
 
+{
 
+	int err = 0;
 
+	size_t errcode_size;
 
+	size_t cmd_infos_size;
 
+
 
+	cmdq->wq = wq;
 
+	cmdq->cmdq_type = q_type;
 
+	cmdq->wrapped = 1;
 
+
 
+	rte_spinlock_init(&cmdq->cmdq_lock);
 
+
 
+	errcode_size = wq->q_depth * sizeof(*cmdq->errcode);
 
+	cmdq->errcode = rte_zmalloc(NULL, errcode_size, 0);
 
+	if (!cmdq->errcode) {
 
+		PMD_DRV_LOG(ERR, "Allocate errcode for cmdq failed");
 
+		return -ENOMEM;
 
+	}
 
+
 
+	cmd_infos_size = wq->q_depth * sizeof(*cmdq->cmd_infos);
 
+	cmdq->cmd_infos = rte_zmalloc(NULL, cmd_infos_size, 0);
 
+	if (!cmdq->cmd_infos) {
 
+		PMD_DRV_LOG(ERR, "Allocate cmd info for cmdq failed");
 
+		err = -ENOMEM;
 
+		goto cmd_infos_err;
 
+	}
 
+
 
+	cmdq->db_base = hwdev->cmdqs->cmdqs_db_base;
 
+
 
+	return 0;
 
+
 
+cmd_infos_err:
 
+	rte_free(cmdq->errcode);
 
+
 
+	return err;
 
+}
 
+
 
+static void
 
+free_cmdq(struct hinic3_cmdq *cmdq)
 
+{
 
+	rte_free(cmdq->cmd_infos);
 
+	rte_free(cmdq->errcode);
 
+}
 
+
 
+static int
 
+hinic3_set_cmdq_ctxts(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct hinic3_cmdqs *cmdqs = hwdev->cmdqs;
 
+	struct hinic3_cmd_cmdq_ctxt cmdq_ctxt;
 
+	enum hinic3_cmdq_type cmdq_type;

drivers/net/hinic3/base/hinic3_cmdq.c line 754

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+	u16 out_size = sizeof(cmdq_ctxt);
 
+	int err;
 
+
 
+	cmdq_type = HINIC3_CMDQ_SYNC;
 
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++) {

why not for (cmdq_type = HINIC3_CMDQ_SYNC; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++)?

Quoted 22 lines
drivers/net/hinic3/base/hinic3_cmdq.c +11 -0
+		memset(&cmdq_ctxt, 0, sizeof(cmdq_ctxt));
 
+		memcpy((void *)&cmdq_ctxt.ctxt_info,
 
+		       (void *)&cmdqs->cmdq[cmdq_type].cmdq_ctxt,
 
+		       sizeof(cmdq_ctxt.ctxt_info));
 
+		cmdq_ctxt.func_idx = hinic3_global_func_id(hwdev);
 
+		cmdq_ctxt.cmdq_id = cmdq_type;
 
+
 
+		err = hinic3_msg_to_mgmt_sync(hwdev, HINIC3_MOD_COMM,
 
+					      HINIC3_MGMT_CMD_SET_CMDQ_CTXT,
 
+					      &cmdq_ctxt, sizeof(cmdq_ctxt),
 
+					      &cmdq_ctxt, &out_size, 0);

drivers/net/hinic3/base/hinic3_cmdq.c line 770

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+		if (err || !out_size || cmdq_ctxt.status) {
 
+			PMD_DRV_LOG(ERR,
 
+				    "Set cmdq ctxt failed, err: %d, status: "
 
+				    "0x%x, out_size: 0x%x",
 
+				    err, cmdq_ctxt.status, out_size);

Maybe we need to rollback the previous success case.

Quoted 58 lines
drivers/net/hinic3/base/hinic3_cmdq.c +29 -0
+			return -EFAULT;
 
+		}
 
+	}
 
+
 
+	cmdqs->status |= HINIC3_CMDQ_ENABLE;
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_reinit_cmdq_ctxts(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct hinic3_cmdqs *cmdqs = hwdev->cmdqs;
 
+	enum hinic3_cmdq_type cmdq_type = HINIC3_CMDQ_SYNC;
 
+
 
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++) {
 
+		cmdqs->cmdq[cmdq_type].wrapped = 1;
 
+		hinic3_wq_wqe_pg_clear(cmdqs->cmdq[cmdq_type].wq);
 
+	}
 
+
 
+	return hinic3_set_cmdq_ctxts(hwdev);
 
+}
 
+
 
+static int
 
+hinic3_set_cmdqs(struct hinic3_hwdev *hwdev, struct hinic3_cmdqs *cmdqs)
 
+{
 
+	void *db_base = NULL;
 
+	enum hinic3_cmdq_type type, cmdq_type;
 
+	int err;

drivers/net/hinic3/base/hinic3_cmdq.c line 804

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+
 
+	err = hinic3_alloc_db_addr(hwdev, &db_base, HINIC3_DB_TYPE_CMDQ);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Failed to allocate doorbell address");
 
+		goto alloc_db_err;

In this case, the hinic3_alloc_db_addr should do the cleanup of res. so no need to goto alloc_db_err.

Quoted 108 lines
drivers/net/hinic3/base/hinic3_cmdq.c +54 -0
+	}
 
+	cmdqs->cmdqs_db_base = (u8 *)db_base;
 
+
 
+	cmdq_type = HINIC3_CMDQ_SYNC;
 
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++) {
 
+		err = init_cmdq(&cmdqs->cmdq[cmdq_type], hwdev,
 
+				&cmdqs->saved_wqs[cmdq_type], cmdq_type);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR, "Initialize cmdq failed");
 
+			goto init_cmdq_err;
 
+		}
 
+
 
+		cmdq_init_queue_ctxt(&cmdqs->cmdq[cmdq_type],
 
+				     &cmdqs->cmdq[cmdq_type].cmdq_ctxt);
 
+	}
 
+
 
+	err = hinic3_set_cmdq_ctxts(hwdev);
 
+	if (err)
 
+		goto init_cmdq_err;
 
+
 
+	return 0;
 
+
 
+init_cmdq_err:
 
+	type = HINIC3_CMDQ_SYNC;
 
+	for (; type < cmdq_type; type++)
 
+		free_cmdq(&cmdqs->cmdq[type]);
 
+
 
+alloc_db_err:
 
+	hinic3_cmdq_free(cmdqs->saved_wqs, HINIC3_MAX_CMDQ_TYPES);
 
+	return -ENOMEM;
 
+}
 
+
 
+int
 
+hinic3_cmdqs_init(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct hinic3_cmdqs *cmdqs = NULL;
 
+	size_t saved_wqs_size;
 
+	char cmdq_pool_name[RTE_MEMPOOL_NAMESIZE];
 
+	int err;
 
+
 
+	cmdqs = rte_zmalloc(NULL, sizeof(*cmdqs), 0);
 
+	if (!cmdqs)
 
+		return -ENOMEM;
 
+
 
+	hwdev->cmdqs = cmdqs;
 
+	cmdqs->hwdev = hwdev;
 
+
 
+	saved_wqs_size = HINIC3_MAX_CMDQ_TYPES * sizeof(struct hinic3_wq);
 
+	cmdqs->saved_wqs = rte_zmalloc(NULL, saved_wqs_size, 0);
 
+	if (!cmdqs->saved_wqs) {
 
+		PMD_DRV_LOG(ERR, "Allocate saved wqs failed");
 
+		err = -ENOMEM;
 
+		goto alloc_wqs_err;
 
+	}

drivers/net/hinic3/base/hinic3_cmdq.c line 863

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+
 
+	memset(cmdq_pool_name, 0, RTE_MEMPOOL_NAMESIZE);
 
+	snprintf(cmdq_pool_name, sizeof(cmdq_pool_name), "hinic3_cmdq_%u",
 
+		       hwdev->port_id);
 
+

two many no need blank line, such as this.

Quoted 66 lines
drivers/net/hinic3/base/hinic3_cmdq.c +33 -0
+	cmdqs->cmd_buf_pool = rte_pktmbuf_pool_create(cmdq_pool_name,
 
+		HINIC3_CMDQ_DEPTH * HINIC3_MAX_CMDQ_TYPES, 0, 0,
 
+		HINIC3_CMDQ_BUF_SIZE, (int)rte_socket_id());
 
+	if (!cmdqs->cmd_buf_pool) {
 
+		PMD_DRV_LOG(ERR, "Create cmdq buffer pool failed");
 
+		err = -ENOMEM;
 
+		goto pool_create_err;
 
+	}
 
+
 
+	err = hinic3_cmdq_alloc(cmdqs->saved_wqs, hwdev, HINIC3_MAX_CMDQ_TYPES,
 
+				HINIC3_CMDQ_WQ_BUF_SIZE, CMDQ_WQEBB_SHIFT,
 
+				HINIC3_CMDQ_DEPTH);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Allocate cmdq failed");
 
+		goto cmdq_alloc_err;
 
+	}
 
+
 
+	err = hinic3_set_cmdqs(hwdev, cmdqs);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "set_cmdqs failed");
 
+		goto cmdq_alloc_err;
 
+	}
 
+	return 0;
 
+
 
+cmdq_alloc_err:
 
+	rte_mempool_free(cmdqs->cmd_buf_pool);
 
+
 
+pool_create_err:
 
+	rte_free(cmdqs->saved_wqs);
 
+
 
+alloc_wqs_err:
 
+	rte_free(cmdqs);
 
+

drivers/net/hinic3/base/hinic3_cmdq.c line 901

Quoted 10 lines
drivers/net/hinic3/base/hinic3_cmdq.c +5 -0
 
+	return err;
 
+}
 
+
 
+void
 
+hinic3_cmdqs_free(struct hinic3_hwdev *hwdev)

In the previous commit, the function names is like: hinic3 + verb + noun, here is hinic3 + noun + verb Suggest keep the same style.

Quoted 627 lines
drivers/net/hinic3/base/hinic3_cmdq.c +77 -0
+{
 
+	struct hinic3_cmdqs *cmdqs = hwdev->cmdqs;
 
+	enum hinic3_cmdq_type cmdq_type = HINIC3_CMDQ_SYNC;
 
+
 
+	cmdqs->status &= ~HINIC3_CMDQ_ENABLE;
 
+
 
+	for (; cmdq_type < HINIC3_MAX_CMDQ_TYPES; cmdq_type++)
 
+		free_cmdq(&cmdqs->cmdq[cmdq_type]);
 
+
 
+	hinic3_cmdq_free(cmdqs->saved_wqs, HINIC3_MAX_CMDQ_TYPES);
 
+
 
+	rte_mempool_free(cmdqs->cmd_buf_pool);
 
+
 
+	rte_free(cmdqs->saved_wqs);
 
+
 
+	rte_free(cmdqs);
 
+}
 
+
 
+static int
 
+hinic3_cmdq_poll_msg(struct hinic3_cmdq *cmdq, u32 timeout)
 
+{
 
+	struct hinic3_cmdq_wqe *wqe = NULL;
 
+	struct hinic3_cmdq_wqe_lcmd *wqe_lcmd = NULL;
 
+	struct hinic3_ctrl *ctrl = NULL;
 
+	struct hinic3_cmdq_cmd_info *cmd_info = NULL;
 
+	u32 status_info, ctrl_info;
 
+	u16 ci;
 
+	int errcode;
 
+	unsigned long end;
 
+	int done = 0;
 
+	int err = 0;
 
+
 
+	wqe = hinic3_read_wqe(cmdq->wq, 1, &ci);
 
+	if (!wqe) {
 
+		PMD_DRV_LOG(ERR, "No outstanding cmdq msg");
 
+		return -EINVAL;
 
+	}
 
+
 
+	cmd_info = &cmdq->cmd_infos[ci];
 
+	if (cmd_info->cmd_type == HINIC3_CMD_TYPE_NONE) {
 
+		PMD_DRV_LOG(ERR,
 
+			    "Cmdq msg has not been filled and send to hw, "
 
+			    "or get TMO msg ack. cmdq ci: %u",
 
+			    ci);
 
+		return -EINVAL;
 
+	}
 
+
 
+	/* Only arm bit is using scmd wqe, the wqe is lcmd. */
 
+	wqe_lcmd = &wqe->wqe_lcmd;
 
+	ctrl = &wqe_lcmd->ctrl;
 
+	end = jiffies + msecs_to_jiffies(timeout);
 
+	do {
 
+		ctrl_info = hinic3_hw_cpu32((ctrl)->ctrl_info);
 
+		if (WQE_COMPLETED(ctrl_info)) {
 
+			done = 1;
 
+			break;
 
+		}
 
+
 
+		rte_delay_us(1);
 
+	} while (time_before(jiffies, end));
 
+
 
+	if (done) {
 
+		status_info = hinic3_hw_cpu32(wqe_lcmd->status.status_info);
 
+		errcode = WQE_ERRCODE_GET(status_info, VAL);
 
+		cmdq_update_errcode(cmdq, ci, errcode);
 
+		clear_wqe_complete_bit(cmdq, wqe);
 
+		err = 0;
 
+	} else {
 
+		PMD_DRV_LOG(ERR, "Poll cmdq msg time out, ci: %u", ci);
 
+		err = -ETIMEDOUT;
 
+	}
 
+
 
+	/* Set this cmd invalid. */
 
+	cmd_info->cmd_type = HINIC3_CMD_TYPE_NONE;
 
+
 
+	return err;
 
+}
drivers/net/hinic3/base/hinic3_cmdq.h +0 -0

new file mode 100644

index 0000000000..fdff69fd51

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_cmdq.h

drivers/net/hinic3/base/hinic3_cmdq.h +230 -0
@@ -0,0 +1,230 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#ifndef _HINIC3_CMDQ_H_
 
+#define _HINIC3_CMDQ_H_
 
+
 
+#include "hinic3_mgmt.h"
 
+#include "hinic3_wq.h"
 
+
 
+#define HINIC3_SCMD_DATA_LEN 16
 
+
 
+/* Pmd driver uses 64, kernel l2nic uses 4096. */
 
+#define HINIC3_CMDQ_DEPTH 64
 
+
 
+#define HINIC3_CMDQ_BUF_SIZE 2048U
 
+
 
+#define HINIC3_CEQ_ID_CMDQ 0
 
+
 
+enum cmdq_scmd_type {
 
+	CMDQ_SET_ARM_CMD = 2,
 
+};
 
+
 
+enum cmdq_wqe_type { WQE_LCMD_TYPE, WQE_SCMD_TYPE };
 
+
 
+enum ctrl_sect_len { CTRL_SECT_LEN = 1, CTRL_DIRECT_SECT_LEN = 2 };
 
+
 
+enum bufdesc_len { BUFDESC_LCMD_LEN = 2, BUFDESC_SCMD_LEN = 3 };
 
+
 
+enum data_format {
 
+	DATA_SGE,
 
+};
 
+
 
+enum completion_format { COMPLETE_DIRECT, COMPLETE_SGE };
 
+
 
+enum completion_request {
 
+	CEQ_SET = 1,
 
+};
 
+
 
+enum cmdq_cmd_type { SYNC_CMD_DIRECT_RESP, SYNC_CMD_SGE_RESP, ASYNC_CMD };
 
+
 
+enum hinic3_cmdq_type {
 
+	HINIC3_CMDQ_SYNC,
 
+	HINIC3_CMDQ_ASYNC,
 
+	HINIC3_MAX_CMDQ_TYPES
 
+};
 
+
 
+enum hinic3_db_src_type {
 
+	HINIC3_DB_SRC_CMDQ_TYPE,
 
+	HINIC3_DB_SRC_L2NIC_SQ_TYPE
 
+};
 
+
 
+enum hinic3_cmdq_db_type { HINIC3_DB_SQ_RQ_TYPE, HINIC3_DB_CMDQ_TYPE };
 
+
 
+/* Cmdq ack type. */
 
+enum hinic3_ack_type {
 
+	HINIC3_ACK_TYPE_CMDQ,
 
+	HINIC3_ACK_TYPE_SHARE_CQN,
 
+	HINIC3_ACK_TYPE_APP_CQN,
 
+
 
+	HINIC3_MOD_ACK_MAX = 15
 
+};
 
+
 
+/* Cmdq wqe ctrls. */
 
+struct hinic3_cmdq_header {
 
+	u32 header_info;
 
+	u32 saved_data;
 
+};
 
+
 
+struct hinic3_scmd_bufdesc {
 
+	u32 buf_len;
 
+	u32 rsvd;
 
+	u8 data[HINIC3_SCMD_DATA_LEN];
 
+};
 
+
 
+struct hinic3_lcmd_bufdesc {
 
+	struct hinic3_sge sge;
 
+	u32 rsvd1;
 
+	u64 saved_async_buf;
 
+	u64 rsvd3;
 
+};
 
+
 
+struct hinic3_cmdq_db {
 
+	u32 db_head;
 
+	u32 db_info;
 
+};
 
+
 
+struct hinic3_status {
 
+	u32 status_info;
 
+};
 
+
 
+struct hinic3_ctrl {
 
+	u32 ctrl_info;
 
+};
 
+
 
+struct hinic3_sge_resp {
 
+	struct hinic3_sge sge;
 
+	u32 rsvd;
 
+};
 
+
 
+struct hinic3_cmdq_completion {
 
+	/* HW format. */
 
+	union {
 
+		struct hinic3_sge_resp sge_resp;
 
+		u64 direct_resp;
 
+	};
 
+};
 
+
 
+struct hinic3_cmdq_wqe_scmd {
 
+	struct hinic3_cmdq_header header;
 
+	u64 rsvd;
 
+	struct hinic3_status status;
 
+	struct hinic3_ctrl ctrl;
 
+	struct hinic3_cmdq_completion completion;
 
+	struct hinic3_scmd_bufdesc buf_desc;
 
+};
 
+
 
+struct hinic3_cmdq_wqe_lcmd {
 
+	struct hinic3_cmdq_header header;
 
+	struct hinic3_status status;
 
+	struct hinic3_ctrl ctrl;
 
+	struct hinic3_cmdq_completion completion;
 
+	struct hinic3_lcmd_bufdesc buf_desc;
 
+};
 
+
 
+struct hinic3_cmdq_inline_wqe {
 
+	struct hinic3_cmdq_wqe_scmd wqe_scmd;
 
+};
 
+
 
+struct hinic3_cmdq_wqe {
 
+	/* HW format. */
 
+	union {
 
+		struct hinic3_cmdq_inline_wqe inline_wqe;
 
+		struct hinic3_cmdq_wqe_lcmd wqe_lcmd;
 
+	};
 
+};
 
+
 
+struct hinic3_cmdq_ctxt_info {
 
+	u64 curr_wqe_page_pfn;
 
+	u64 wq_block_pfn;
 
+};
 
+
 
+struct hinic3_cmd_cmdq_ctxt {
 
+	u8 status;
 
+	u8 version;
 
+	u8 rsvd0[6];
 
+
 
+	u16 func_idx;
 
+	u8 cmdq_id;
 
+	u8 rsvd1[5];
 
+
 
+	struct hinic3_cmdq_ctxt_info ctxt_info;
 
+};
 
+
 
+enum hinic3_cmdq_status {
 
+	HINIC3_CMDQ_ENABLE = BIT(0),
 
+};
 
+
 
+enum hinic3_cmdq_cmd_type {
 
+	HINIC3_CMD_TYPE_NONE,
 
+	HINIC3_CMD_TYPE_SET_ARM,
 
+	HINIC3_CMD_TYPE_DIRECT_RESP,
 
+	HINIC3_CMD_TYPE_SGE_RESP
 
+};
 
+
 
+struct hinic3_cmdq_cmd_info {
 
+	enum hinic3_cmdq_cmd_type cmd_type;
 
+};
 
+
 
+struct hinic3_cmdq {
 
+	struct hinic3_wq *wq;
 
+
 
+	enum hinic3_cmdq_type cmdq_type;
 
+	int wrapped;
 
+
 
+	int *errcode;
 
+	u8 *db_base;
 
+
 
+	rte_spinlock_t cmdq_lock;
 
+
 
+	struct hinic3_cmdq_ctxt_info cmdq_ctxt;
 
+
 
+	struct hinic3_cmdq_cmd_info *cmd_infos;
 
+};
 
+
 
+struct hinic3_cmdqs {
 
+	struct hinic3_hwdev *hwdev;
 
+	u8 *cmdqs_db_base;
 
+
 
+	struct rte_mempool *cmd_buf_pool;
 
+
 
+	struct hinic3_wq *saved_wqs;
 
+
 
+	struct hinic3_cmdq cmdq[HINIC3_MAX_CMDQ_TYPES];
 
+
 
+	u32 status;
 
+};
 
+
 
+struct hinic3_cmd_buf {
 
+	void *buf;
 
+	uint64_t dma_addr;
 
+	struct rte_mbuf *mbuf;
 
+	u16 size;
 
+};
 
+
 
+int hinic3_reinit_cmdq_ctxts(struct hinic3_hwdev *hwdev);
 
+
 
+bool hinic3_cmdq_idle(struct hinic3_cmdq *cmdq);
 
+
 
+struct hinic3_cmd_buf *hinic3_alloc_cmd_buf(void *hwdev);
 
+
 
+void hinic3_free_cmd_buf(struct hinic3_cmd_buf *cmd_buf);
 
+
 
+/*
 
+ * PF/VF sends cmd to ucode by cmdq, and return 0 if success.
 
+ * timeout=0, use default timeout.
 
+ */
 
+int hinic3_cmdq_direct_resp(void *hwdev, enum hinic3_mod_type mod, u8 cmd,
 
+			    struct hinic3_cmd_buf *buf_in, u64 *out_param,
 
+			    u32 timeout);
 
+
 
+int hinic3_cmdq_detail_resp(void *hwdev, enum hinic3_mod_type mod, u8 cmd,
 
+			    struct hinic3_cmd_buf *buf_in,
 
+			    struct hinic3_cmd_buf *buf_out, u32 timeout);
 
+
 
+int hinic3_cmdqs_init(struct hinic3_hwdev *hwdev);
 
+
 
+void hinic3_cmdqs_free(struct hinic3_hwdev *hwdev);
 
+
 
+#endif /* _HINIC3_CMDQ_H_ */
#135 lore raw

PATCH v5 5/18 net/hinic3: add NIC event module

In reply to Feifei Wang

From: Xin Wang <[email protected]>

Currently, there are two types of events: pf/vf connection status and port information printing. This patch contains related data structures and function codes.

---
 drivers/net/hinic3/base/hinic3_nic_event.c | 433 +++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_nic_event.h |  39 ++
 2 files changed, 472 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.c
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.h
drivers/net/hinic3/base/hinic3_nic_event.c new file +433 -0
new file mode 100644
index 0000000000..fb779fcf25
@@ -0,0 +1,433 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#include "hinic3_compat.h"
+#include "hinic3_cmd.h"
+#include "hinic3_hwif.h"
+#include "hinic3_nic_cfg.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_nic_event.h"
+#include "hinic3_ethdev.h"
+
+static const char *g_hw_to_char_fec[HILINK_FEC_MAX_TYPE] = {
+	"not set", "rsfec", "basefec", "nofec", "llrsfec",
+};
+static const char *g_hw_to_speed_info[PORT_SPEED_UNKNOWN] = {
+	"not set", "10MB", "100MB", "1GB",   "10GB",
+	"25GB",	   "40GB", "50GB",  "100GB", "200GB",
+};
+static const char *g_hw_to_an_state_info[PORT_CFG_AN_OFF + 1] = {
+	"not set",
+	"on",
+	"off",
+};
+
+struct port_type_table {
+	u32 port_type;
+	const char *port_type_name;
+};
+
+void
+get_port_info(struct hinic3_hwdev *hwdev, u8 link_state,
+	      struct rte_eth_link *link)
+{
+	uint32_t port_speed[LINK_SPEED_LEVELS] = {
+		RTE_ETH_SPEED_NUM_NONE, RTE_ETH_SPEED_NUM_10M,
+		RTE_ETH_SPEED_NUM_100M, RTE_ETH_SPEED_NUM_1G,
+		RTE_ETH_SPEED_NUM_10G,	RTE_ETH_SPEED_NUM_25G,
+		RTE_ETH_SPEED_NUM_40G,	RTE_ETH_SPEED_NUM_50G,
+		RTE_ETH_SPEED_NUM_100G, RTE_ETH_SPEED_NUM_200G,
+	};
+	struct nic_port_info port_info = {0};
+	int err;
+
+	if (!link_state) {
+		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;
+	} else {
+		link->link_status = RTE_ETH_LINK_UP;
+
+		err = hinic3_get_port_info(hwdev, &port_info);
+		if (err) {
+			link->link_speed = RTE_ETH_SPEED_NUM_NONE;
+			link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
+			link->link_autoneg = RTE_ETH_LINK_FIXED;
+		} else {
+			link->link_speed =
+				port_speed[port_info.speed % LINK_SPEED_LEVELS];
+			link->link_duplex = port_info.duplex;
+			link->link_autoneg = port_info.autoneg_state;
+		}
+	}
+}
+
+static void
+hinic3_link_event_stats(void *dev, u8 link)
+{
+	struct hinic3_hwdev *hwdev = dev;
+
+	if (link)
+		rte_atomic_fetch_add_explicit(&hwdev->hw_stats.link_event_stats.link_up_stats,
+			1, rte_memory_order_seq_cst);
+	else
+		rte_atomic_fetch_add_explicit(&hwdev->hw_stats.link_event_stats.link_down_stats,
+			1, rte_memory_order_seq_cst);
+}
+
+static void
+hinic3_set_vport_state(struct hinic3_hwdev *hwdev,
+		       struct hinic3_cmd_link_state *link_state)
+{
+	struct hinic3_nic_dev *nic_dev = NULL;
+	int err = 0;
+
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV((struct rte_eth_dev *)(hwdev->eth_dev));
+
+	if (link_state->state) {
+		if (hinic3_get_bit(HINIC3_DEV_START, &nic_dev->dev_status))
+			err = hinic3_set_vport_enable(hwdev, true);
+	} else {
+		err = hinic3_set_vport_enable(hwdev, false);
+	}
+
+	if (err)
+		PMD_DRV_LOG(ERR, "Set vport status failed");
+}
+
+static void
+link_status_event_handler(void *hwdev, void *buf_in, __rte_unused u16 in_size,
+			  __rte_unused void *buf_out,
+			  __rte_unused u16 *out_size)
+{
+	struct hinic3_cmd_link_state *link_status = NULL;
+	struct rte_eth_link link;
+	struct hinic3_hwdev *dev = hwdev;
+	int err;
+
+	link_status = buf_in;
+	PMD_DRV_LOG(INFO,
+		    "Link status report received, func_id: %d, status: %d(%s)",
+		    hinic3_global_func_id(hwdev), link_status->state,
+		    link_status->state ? "UP" : "DOWN");
+
+	hinic3_link_event_stats(hwdev, link_status->state);
+
+	hinic3_set_vport_state(dev, link_status);
+
+	/* Link event reported only after set vport enable. */
+	get_port_info(dev, link_status->state, &link);
+	err = rte_eth_linkstatus_set((struct rte_eth_dev *)(dev->eth_dev),
+				     &link);
+	if (!err)
+		rte_eth_dev_callback_process(dev->eth_dev,
+					     RTE_ETH_EVENT_INTR_LSC, NULL);
+}
+
+static const char *
+get_port_type_name(u32 type)
+{
+	int i;
+	const struct port_type_table port_optical_type_table_s[] = {
+		{LINK_PORT_UNKNOWN, "UNKNOWN"},
+		{LINK_PORT_OPTICAL_MM, "optical_sr"},
+		{LINK_PORT_OPTICAL_SM, "optical_lr"},
+		{LINK_PORT_PAS_COPPER, "copper"},
+		{LINK_PORT_ACC, "ACC"},
+		{LINK_PORT_BASET, "baset"},
+		{LINK_PORT_AOC, "AOC"},
+		{LINK_PORT_ELECTRIC, "electric"},
+		{LINK_PORT_BACKBOARD_INTERFACE, "interface"},
+	};
+
+	for (i = 0; i < ARRAY_LEN(port_optical_type_table_s); i++) {
+		if (type == port_optical_type_table_s[i].port_type)
+			return port_optical_type_table_s[i].port_type_name;
+	}
+	return "UNKNOWN TYPE";
+}
+
+static void
+get_port_type(struct mag_cmd_event_port_info *port_info, const char **port_type)
+{
+	if (port_info->port_type <= LINK_PORT_BACKBOARD_INTERFACE)
+		*port_type = get_port_type_name(port_info->port_type);
+	else
+		PMD_DRV_LOG(INFO, "Unknown port type: %u",
+			    port_info->port_type);
+}
+
+static int
+get_port_temperature_power(struct mag_cmd_event_port_info *info, char *str)
+{
+	char arr[CAP_INFO_MAX_LEN];
+
+	snprintf(arr, CAP_INFO_MAX_LEN - 1, "%s, %s, Temperature: %u", str,
+		 info->sfp_type ? "QSFP" : "SFP", info->cable_temp);
+	if (info->sfp_type)
+		snprintf(str, CAP_INFO_MAX_LEN - 1,
+			 "%s, rx power: %uuw %uuW %uuW %uuW", arr,
+			 info->power[0x0], info->power[0x1], info->power[0x2],
+			 info->power[0x3]);
+	else
+		snprintf(str, CAP_INFO_MAX_LEN - 1,
+			 "%s, rx power: %uuW, tx power: %uuW", arr,
+			 info->power[0x0], info->power[0x1]);
+
+	return 0;
+}
+
+static void
+print_cable_info(struct mag_cmd_event_port_info *port_info)
+{
+	char tmp_str[CAP_INFO_MAX_LEN] = {0};
+	char tmp_vendor[VENDOR_MAX_LEN] = {0};
+	const char *port_type = "Unknown port type";
+	int i;
+	int err = 0;
+	if (port_info->gpio_insert) {
+		PMD_DRV_LOG(INFO, "Cable unpresent");
+		return;
+	}
+
+	get_port_type(port_info, &port_type);
+
+	for (i = (int)sizeof(port_info->vendor_name) - 1; i >= 0; i--) {
+		if (port_info->vendor_name[i] == ' ')
+			port_info->vendor_name[i] = '\0';
+		else
+			break;
+	}
+
+	memcpy(tmp_vendor, port_info->vendor_name,
+	       sizeof(port_info->vendor_name));
+	snprintf(tmp_str, CAP_INFO_MAX_LEN - 1,
+		     "Vendor: %s, %s, length: %um, max_speed: %uGbps",
+		     tmp_vendor, port_type, port_info->cable_length,
+		     port_info->max_speed);
+
+	if (port_info->port_type == LINK_PORT_OPTICAL_MM ||
+	    port_info->port_type == LINK_PORT_AOC) {
+		err = get_port_temperature_power(port_info, tmp_str);
+		if (err)
+			return;
+	}
+
+	PMD_DRV_LOG(INFO, "Cable information: %s", tmp_str);
+}
+
+static void
+print_link_info(struct mag_cmd_event_port_info *port_info)
+{
+	const char *fec = "None";
+	const char *speed = "None";
+	const char *an_state = "None";
+
+	if (port_info->fec < HILINK_FEC_MAX_TYPE)
+		fec = g_hw_to_char_fec[port_info->fec];
+	else
+		PMD_DRV_LOG(INFO, "Unknown fec type: %u", port_info->fec);
+
+	if (port_info->an_state > PORT_CFG_AN_OFF) {
+		PMD_DRV_LOG(INFO, "an_state %u is invalid",
+			    port_info->an_state);
+		return;
+	}
+
+	an_state = g_hw_to_an_state_info[port_info->an_state];
+
+	if (port_info->speed >= PORT_SPEED_UNKNOWN) {
+		PMD_DRV_LOG(INFO, "speed %u is invalid", port_info->speed);
+		return;
+	}
+
+	speed = g_hw_to_speed_info[port_info->speed];
+	PMD_DRV_LOG(INFO, "Link information: speed %s, %s, autoneg %s", speed,
+		    fec, an_state);
+}
+
+static void
+print_port_info(void *hwdev, struct mag_cmd_event_port_info *port_info, u8 type)
+{
+	print_cable_info(port_info);
+
+	print_link_info(port_info);
+
+	if (type == RTE_ETH_LINK_UP)
+		return;
+
+	PMD_DRV_LOG(INFO, "Function %d link down msg:",
+		    hinic3_global_func_id(hwdev));
+
+	PMD_DRV_LOG(INFO,
+		    "PMA ctrl: %s, tx %s, rx %s, PMA fifo reg: 0x%x, "
+		    "PMA signal ok reg: 0x%x, RF/LF status reg: 0x%x",
+		    port_info->pma_ctrl == 1 ? "off" : "on",
+		    port_info->tx_enable ? "enable" : "disable",
+		    port_info->rx_enable ? "enable" : "disable",
+		    port_info->pma_fifo_reg, port_info->pma_signal_ok_reg,
+		    port_info->rf_lf);
+	PMD_DRV_LOG(INFO,
+		    "alos: %u, rx_los: %u, PCS 64 66b reg: 0x%x, "
+		    "PCS link: 0x%x, MAC link: 0x%x, PCS_err_cnt: 0x%x",
+		    port_info->alos, port_info->rx_los,
+		    port_info->pcs_64_66b_reg, port_info->pcs_link,
+		    port_info->pcs_mac_link, port_info->pcs_err_cnt);
+	PMD_DRV_LOG(INFO,
+		    "his_link_machine_state = 0x%08x, "
+		    "cur_link_machine_state = 0x%08x",
+		    port_info->his_link_machine_state,
+		    port_info->cur_link_machine_state);
+}
+
+static void
+port_info_event_printf(void *hwdev, void *buf_in, __rte_unused u16 in_size,
+		       __rte_unused void *buf_out, __rte_unused u16 *out_size)
+{
+	struct mag_cmd_event_port_info *port_info = buf_in;
+	((struct mag_cmd_event_port_info *)buf_out)->head.status = 0;
+	enum hinic3_nic_event_type type = port_info->event_type;
+	if (type < RTE_ETH_LINK_DOWN || type > RTE_ETH_LINK_UP) {
+		PMD_DRV_LOG(ERR, "Invalid hilink info report, type: %d",
+			    type);
+		return;
+	}
+
+	print_port_info(hwdev, port_info, type);
+}
+
+struct nic_event_handler {
+	u16 cmd;
+	void (*handler)(void *hwdev, void *buf_in, u16 in_size, void *buf_out,
+			u16 *out_size);
+};
+
+static const struct nic_event_handler nic_cmd_handler[] = {};
+
+/**
+ * Handle NIC event based on the provided command.
+ *
+ * @param[in] hwdev
+ * Pointer to hardware device structure.
+ * @param[in] cmd
+ * The command associated with the NIC event to be handled.
+ * @param[in] buf_in
+ * The input buffer containing the event data.
+ * @param[in] in_size
+ * The size of the input buffer.
+ * @param[out] buf_out
+ * The output buffer to store the event response.
+ * @param[out] out_size
+ * The size of the output data stored in the output buffer.
+ */
+static void
+nic_event_handler(void *hwdev, u16 cmd, void *buf_in, u16 in_size,
+		  void *buf_out, u16 *out_size)
+{
+	u32 i, size = ARRAY_LEN(nic_cmd_handler);
+
+	if (!hwdev)
+		return;
+
+	*out_size = 0;
+
+	for (i = 0; i < size; i++) {
+		if (cmd == nic_cmd_handler[i].cmd) {
+			nic_cmd_handler[i].handler(hwdev, buf_in, in_size,
+						   buf_out, out_size);
+			break;
+		}
+	}
+
+	if (i == size)
+		PMD_DRV_LOG(WARNING, "Unsupported nic event cmd(%d) to process",
+			    cmd);
+}
+
+/*
+ * VF handler mbox msg from ppf/pf.
+ * VF link change event.
+ */
+int
+hinic3_vf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
+			void *buf_in, u16 in_size, void *buf_out, u16 *out_size)
+{
+	nic_event_handler(hwdev, cmd, buf_in, in_size, buf_out, out_size);
+	return 0;
+}
+
+/* NIC event of PF/PPF handler reported by mgmt cpu. */
+void
+hinic3_pf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
+			void *buf_in, u16 in_size, void *buf_out, u16 *out_size)
+{
+	nic_event_handler(hwdev, cmd, buf_in, in_size, buf_out, out_size);
+}
+
+static const struct nic_event_handler mag_cmd_handler[] = {
+	{
+		.cmd = MAG_CMD_GET_LINK_STATUS,
+		.handler = link_status_event_handler,
+	},
+	{
+		.cmd = MAG_CMD_EVENT_PORT_INFO,
+		.handler = port_info_event_printf,
+	},
+};
+
+static int
+hinic3_mag_event_handler(void *hwdev, u16 cmd, void *buf_in, u16 in_size,
+			 void *buf_out, u16 *out_size)
+{
+	u32 size = ARRAY_LEN(mag_cmd_handler);
+	u32 i;
+
+	if (!hwdev)
+		return -EINVAL;
+
+	*out_size = 0;
+	for (i = 0; i < size; i++) {
+		if (cmd == mag_cmd_handler[i].cmd) {
+			mag_cmd_handler[i].handler(hwdev, buf_in, in_size,
+						   buf_out, out_size);
+			break;
+		}
+	}
+
+	/* Can't find this event cmd. */
+	if (i == size)
+		PMD_DRV_LOG(ERR, "Unsupported mag event, cmd: %u", cmd);
+
+	return 0;
+}
+
+int
+hinic3_vf_mag_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
+			    void *buf_in, u16 in_size, void *buf_out,
+			    u16 *out_size)
+{
+	return hinic3_mag_event_handler(hwdev, cmd, buf_in, in_size, buf_out,
+					out_size);
+}
+
+/* pf/ppf handler mgmt cpu report hilink event. */
+void
+hinic3_pf_mag_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
+			    void *buf_in, u16 in_size, void *buf_out,
+			    u16 *out_size)
+{
+	hinic3_mag_event_handler(hwdev, cmd, buf_in, in_size, buf_out,
+				 out_size);
+}
+
+u8
+hinic3_nic_sw_aeqe_handler(__rte_unused void *hwdev, u8 event, u8 *data)
+{
+	PMD_DRV_LOG(ERR,
+		    "Received nic ucode aeq event type: 0x%x, data: %" PRIu64,
+		    event, *((u64 *)data));
+
+	return 0;
+}
drivers/net/hinic3/base/hinic3_nic_event.h new file +39 -0
new file mode 100644
index 0000000000..6a792e6af5
@@ -0,0 +1,39 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#ifndef _HINIC3_NIC_EVENT_H_
+#define _HINIC3_NIC_EVENT_H_
+
+/**
+ * Get the Ethernet port link information based on the link state.
+ *
+ * @param[in] hwdev
+ * The hardware device context.
+ * @param[in] link_state
+ * The current link state (0 = down, non-zero = up).
+ * @param[out] link
+ * Pointer to the `rte_eth_link` structure.
+ */
+void get_port_info(struct hinic3_hwdev *hwdev, u8 link_state,
+		   struct rte_eth_link *link);
+
+int hinic3_vf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
+			    void *buf_in, u16 in_size, void *buf_out,
+			    u16 *out_size);
+
+void hinic3_pf_event_handler(void *hwdev, __rte_unused void *pri_handle,
+			     u16 cmd, void *buf_in, u16 in_size, void *buf_out,
+			     u16 *out_size);
+
+int hinic3_vf_mag_event_handler(void *hwdev, void *pri_handle, u16 cmd,
+				void *buf_in, u16 in_size, void *buf_out,
+				u16 *out_size);
+
+void hinic3_pf_mag_event_handler(void *hwdev, void *pri_handle, u16 cmd,
+				 void *buf_in, u16 in_size, void *buf_out,
+				 u16 *out_size);
+
+u8 hinic3_nic_sw_aeqe_handler(__rte_unused void *hwdev, u8 event, u8 *data);
+
+#endif /* _HINIC3_NIC_EVENT_H_ */
Signature · 1 line
2.45.1.windows.1
#136 lore raw

Re: [V5 05/18] net/hinic3: add NIC event module

Quoted 284 lines · Feifei Wang

From: Xin Wang <[email protected]>

Currently, there are two types of events: pf/vf connection status

and port information printing. This patch contains related data

structures and function codes.

---

 drivers/net/hinic3/base/hinic3_nic_event.c | 433 +++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_nic_event.h |  39 ++
 2 files changed, 472 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.c
 create mode 100644 drivers/net/hinic3/base/hinic3_nic_event.h
drivers/net/hinic3/base/hinic3_nic_event.c +0 -0

new file mode 100644

index 0000000000..fb779fcf25

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_nic_event.c

drivers/net/hinic3/base/hinic3_nic_event.c +121 -0
@@ -0,0 +1,433 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#include "hinic3_compat.h"
 
+#include "hinic3_cmd.h"
 
+#include "hinic3_hwif.h"
 
+#include "hinic3_nic_cfg.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_nic_event.h"
 
+#include "hinic3_ethdev.h"
 
+
 
+static const char *g_hw_to_char_fec[HILINK_FEC_MAX_TYPE] = {
 
+	"not set", "rsfec", "basefec", "nofec", "llrsfec",
 
+};
 
+static const char *g_hw_to_speed_info[PORT_SPEED_UNKNOWN] = {
 
+	"not set", "10MB", "100MB", "1GB",   "10GB",
 
+	"25GB",	   "40GB", "50GB",  "100GB", "200GB",
 
+};
 
+static const char *g_hw_to_an_state_info[PORT_CFG_AN_OFF + 1] = {
 
+	"not set",
 
+	"on",
 
+	"off",
 
+};
 
+
 
+struct port_type_table {
 
+	u32 port_type;
 
+	const char *port_type_name;
 
+};
 
+
 
+void
 
+get_port_info(struct hinic3_hwdev *hwdev, u8 link_state,
 
+	      struct rte_eth_link *link)
 
+{
 
+	uint32_t port_speed[LINK_SPEED_LEVELS] = {
 
+		RTE_ETH_SPEED_NUM_NONE, RTE_ETH_SPEED_NUM_10M,
 
+		RTE_ETH_SPEED_NUM_100M, RTE_ETH_SPEED_NUM_1G,
 
+		RTE_ETH_SPEED_NUM_10G,	RTE_ETH_SPEED_NUM_25G,
 
+		RTE_ETH_SPEED_NUM_40G,	RTE_ETH_SPEED_NUM_50G,
 
+		RTE_ETH_SPEED_NUM_100G, RTE_ETH_SPEED_NUM_200G,
 
+	};
 
+	struct nic_port_info port_info = {0};
 
+	int err;
 
+
 
+	if (!link_state) {
 
+		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;
 
+	} else {
 
+		link->link_status = RTE_ETH_LINK_UP;
 
+
 
+		err = hinic3_get_port_info(hwdev, &port_info);
 
+		if (err) {
 
+			link->link_speed = RTE_ETH_SPEED_NUM_NONE;
 
+			link->link_duplex = RTE_ETH_LINK_FULL_DUPLEX;
 
+			link->link_autoneg = RTE_ETH_LINK_FIXED;
 
+		} else {
 
+			link->link_speed =
 
+				port_speed[port_info.speed % LINK_SPEED_LEVELS];
 
+			link->link_duplex = port_info.duplex;
 
+			link->link_autoneg = port_info.autoneg_state;
 
+		}
 
+	}
 
+}
 
+
 
+static void
 
+hinic3_link_event_stats(void *dev, u8 link)
 
+{
 
+	struct hinic3_hwdev *hwdev = dev;
 
+
 
+	if (link)
 
+		rte_atomic_fetch_add_explicit(&hwdev->hw_stats.link_event_stats.link_up_stats,
 
+			1, rte_memory_order_seq_cst);
 
+	else
 
+		rte_atomic_fetch_add_explicit(&hwdev->hw_stats.link_event_stats.link_down_stats,
 
+			1, rte_memory_order_seq_cst);
 
+}
 
+
 
+static void
 
+hinic3_set_vport_state(struct hinic3_hwdev *hwdev,
 
+		       struct hinic3_cmd_link_state *link_state)
 
+{
 
+	struct hinic3_nic_dev *nic_dev = NULL;
 
+	int err = 0;
 
+
 
+	nic_dev = HINIC3_ETH_DEV_TO_PRIVATE_NIC_DEV((struct rte_eth_dev *)(hwdev->eth_dev));
 
+
 
+	if (link_state->state) {
 
+		if (hinic3_get_bit(HINIC3_DEV_START, &nic_dev->dev_status))
 
+			err = hinic3_set_vport_enable(hwdev, true);
 
+	} else {
 
+		err = hinic3_set_vport_enable(hwdev, false);
 
+	}
 
+
 
+	if (err)
 
+		PMD_DRV_LOG(ERR, "Set vport status failed");
 
+}
 
+
 
+static void
 
+link_status_event_handler(void *hwdev, void *buf_in, __rte_unused u16 in_size,
 
+			  __rte_unused void *buf_out,
 
+			  __rte_unused u16 *out_size)
 
+{
 
+	struct hinic3_cmd_link_state *link_status = NULL;
 
+	struct rte_eth_link link;
 
+	struct hinic3_hwdev *dev = hwdev;
 
+	int err;
 
+
 
+	link_status = buf_in;
 
+	PMD_DRV_LOG(INFO,
 
+		    "Link status report received, func_id: %d, status: %d(%s)",
 
+		    hinic3_global_func_id(hwdev), link_status->state,
 
+		    link_status->state ? "UP" : "DOWN");
 
+
 
+	hinic3_link_event_stats(hwdev, link_status->state);
 
+
 
+	hinic3_set_vport_state(dev, link_status);
 
+
 
+	/* Link event reported only after set vport enable. */
 
+	get_port_info(dev, link_status->state, &link);

drivers/net/hinic3/base/hinic3_nic_event.c line 126

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+	err = rte_eth_linkstatus_set((struct rte_eth_dev *)(dev->eth_dev),
 
+				     &link);
 
+	if (!err)
 
+		rte_eth_dev_callback_process(dev->eth_dev,
 
+					     RTE_ETH_EVENT_INTR_LSC, NULL);

Please report lsc event when dev->data->dev_conf.intr_conf.lsc = 1

Quoted 56 lines
drivers/net/hinic3/base/hinic3_nic_event.c +28 -0
+}
 
+
 
+static const char *
 
+get_port_type_name(u32 type)
 
+{
 
+	int i;
 
+	const struct port_type_table port_optical_type_table_s[] = {
 
+		{LINK_PORT_UNKNOWN, "UNKNOWN"},
 
+		{LINK_PORT_OPTICAL_MM, "optical_sr"},
 
+		{LINK_PORT_OPTICAL_SM, "optical_lr"},
 
+		{LINK_PORT_PAS_COPPER, "copper"},
 
+		{LINK_PORT_ACC, "ACC"},
 
+		{LINK_PORT_BASET, "baset"},
 
+		{LINK_PORT_AOC, "AOC"},
 
+		{LINK_PORT_ELECTRIC, "electric"},
 
+		{LINK_PORT_BACKBOARD_INTERFACE, "interface"},
 
+	};
 
+
 
+	for (i = 0; i < ARRAY_LEN(port_optical_type_table_s); i++) {
 
+		if (type == port_optical_type_table_s[i].port_type)
 
+			return port_optical_type_table_s[i].port_type_name;
 
+	}
 
+	return "UNKNOWN TYPE";
 
+}
 
+
 
+static void
 
+get_port_type(struct mag_cmd_event_port_info *port_info, const char **port_type)
 
+{

drivers/net/hinic3/base/hinic3_nic_event.c line 159

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+	if (port_info->port_type <= LINK_PORT_BACKBOARD_INTERFACE)
 
+		*port_type = get_port_type_name(port_info->port_type);
 
+	else
 
+		PMD_DRV_LOG(INFO, "Unknown port type: %u",
 
+			    port_info->port_type);

No need to break the lines. suggest cleanup because too much such case. And how about set an default return value for port_type

Quoted 44 lines
drivers/net/hinic3/base/hinic3_nic_event.c +22 -0
+}
 
+
 
+static int
 
+get_port_temperature_power(struct mag_cmd_event_port_info *info, char *str)
 
+{
 
+	char arr[CAP_INFO_MAX_LEN];
 
+
 
+	snprintf(arr, CAP_INFO_MAX_LEN - 1, "%s, %s, Temperature: %u", str,
 
+		 info->sfp_type ? "QSFP" : "SFP", info->cable_temp);
 
+	if (info->sfp_type)
 
+		snprintf(str, CAP_INFO_MAX_LEN - 1,
 
+			 "%s, rx power: %uuw %uuW %uuW %uuW", arr,
 
+			 info->power[0x0], info->power[0x1], info->power[0x2],
 
+			 info->power[0x3]);
 
+	else
 
+		snprintf(str, CAP_INFO_MAX_LEN - 1,
 
+			 "%s, rx power: %uuW, tx power: %uuW", arr,
 
+			 info->power[0x0], info->power[0x1]);
 
+
 
+	return 0;
 
+}
 
+

drivers/net/hinic3/base/hinic3_nic_event.c line 186

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+static void
 
+print_cable_info(struct mag_cmd_event_port_info *port_info)
 
+{
 
+	char tmp_str[CAP_INFO_MAX_LEN] = {0};
 
+	char tmp_vendor[VENDOR_MAX_LEN] = {0};

how about just char str[] and vendor[]

Quoted 22 lines
drivers/net/hinic3/base/hinic3_nic_event.c +11 -0
+	const char *port_type = "Unknown port type";
 
+	int i;
 
+	int err = 0;
 
+	if (port_info->gpio_insert) {
 
+		PMD_DRV_LOG(INFO, "Cable unpresent");
 
+		return;
 
+	}
 
+
 
+	get_port_type(port_info, &port_type);
 
+
 
+	for (i = (int)sizeof(port_info->vendor_name) - 1; i >= 0; i--) {

drivers/net/hinic3/base/hinic3_nic_event.c line 202

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+		if (port_info->vendor_name[i] == ' ')
 
+			port_info->vendor_name[i] = '\0';
 
+		else
 
+			break;
 
+	}

what the above means? how about set the terminal character when setting port_info->vendor_name?

Quoted 82 lines
drivers/net/hinic3/base/hinic3_nic_event.c +41 -0
+
 
+	memcpy(tmp_vendor, port_info->vendor_name,
 
+	       sizeof(port_info->vendor_name));
 
+	snprintf(tmp_str, CAP_INFO_MAX_LEN - 1,
 
+		     "Vendor: %s, %s, length: %um, max_speed: %uGbps",
 
+		     tmp_vendor, port_type, port_info->cable_length,
 
+		     port_info->max_speed);
 
+
 
+	if (port_info->port_type == LINK_PORT_OPTICAL_MM ||
 
+	    port_info->port_type == LINK_PORT_AOC) {
 
+		err = get_port_temperature_power(port_info, tmp_str);
 
+		if (err)
 
+			return;
 
+	}
 
+
 
+	PMD_DRV_LOG(INFO, "Cable information: %s", tmp_str);
 
+}
 
+
 
+static void
 
+print_link_info(struct mag_cmd_event_port_info *port_info)
 
+{
 
+	const char *fec = "None";
 
+	const char *speed = "None";
 
+	const char *an_state = "None";
 
+
 
+	if (port_info->fec < HILINK_FEC_MAX_TYPE)
 
+		fec = g_hw_to_char_fec[port_info->fec];
 
+	else
 
+		PMD_DRV_LOG(INFO, "Unknown fec type: %u", port_info->fec);
 
+
 
+	if (port_info->an_state > PORT_CFG_AN_OFF) {
 
+		PMD_DRV_LOG(INFO, "an_state %u is invalid",
 
+			    port_info->an_state);
 
+		return;
 
+	}
 
+
 
+	an_state = g_hw_to_an_state_info[port_info->an_state];
 
+
 
+	if (port_info->speed >= PORT_SPEED_UNKNOWN) {
 
+		PMD_DRV_LOG(INFO, "speed %u is invalid", port_info->speed);
 
+		return;

drivers/net/hinic3/base/hinic3_nic_event.c line 248

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+	}
 
+
 
+	speed = g_hw_to_speed_info[port_info->speed];
 
+	PMD_DRV_LOG(INFO, "Link information: speed %s, %s, autoneg %s", speed,
 
+		    fec, an_state);

there is eth_dump callback, maybe it should in dump API.

Quoted 68 lines
drivers/net/hinic3/base/hinic3_nic_event.c +34 -0
+}
 
+
 
+static void
 
+print_port_info(void *hwdev, struct mag_cmd_event_port_info *port_info, u8 type)
 
+{
 
+	print_cable_info(port_info);
 
+
 
+	print_link_info(port_info);
 
+
 
+	if (type == RTE_ETH_LINK_UP)
 
+		return;
 
+
 
+	PMD_DRV_LOG(INFO, "Function %d link down msg:",
 
+		    hinic3_global_func_id(hwdev));
 
+
 
+	PMD_DRV_LOG(INFO,
 
+		    "PMA ctrl: %s, tx %s, rx %s, PMA fifo reg: 0x%x, "
 
+		    "PMA signal ok reg: 0x%x, RF/LF status reg: 0x%x",
 
+		    port_info->pma_ctrl == 1 ? "off" : "on",
 
+		    port_info->tx_enable ? "enable" : "disable",
 
+		    port_info->rx_enable ? "enable" : "disable",
 
+		    port_info->pma_fifo_reg, port_info->pma_signal_ok_reg,
 
+		    port_info->rf_lf);
 
+	PMD_DRV_LOG(INFO,
 
+		    "alos: %u, rx_los: %u, PCS 64 66b reg: 0x%x, "
 
+		    "PCS link: 0x%x, MAC link: 0x%x, PCS_err_cnt: 0x%x",
 
+		    port_info->alos, port_info->rx_los,
 
+		    port_info->pcs_64_66b_reg, port_info->pcs_link,
 
+		    port_info->pcs_mac_link, port_info->pcs_err_cnt);
 
+	PMD_DRV_LOG(INFO,
 
+		    "his_link_machine_state = 0x%08x, "
 
+		    "cur_link_machine_state = 0x%08x",
 
+		    port_info->his_link_machine_state,
 
+		    port_info->cur_link_machine_state);

drivers/net/hinic3/base/hinic3_nic_event.c line 287

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+}
 
+
 
+static void
 
+port_info_event_printf(void *hwdev, void *buf_in, __rte_unused u16 in_size,
 
+		       __rte_unused void *buf_out, __rte_unused u16 *out_size)

buf_out was used, so no need add unused prefix.

Quoted 108 lines
drivers/net/hinic3/base/hinic3_nic_event.c +54 -0
+{
 
+	struct mag_cmd_event_port_info *port_info = buf_in;
 
+	((struct mag_cmd_event_port_info *)buf_out)->head.status = 0;
 
+	enum hinic3_nic_event_type type = port_info->event_type;
 
+	if (type < RTE_ETH_LINK_DOWN || type > RTE_ETH_LINK_UP) {
 
+		PMD_DRV_LOG(ERR, "Invalid hilink info report, type: %d",
 
+			    type);
 
+		return;
 
+	}
 
+
 
+	print_port_info(hwdev, port_info, type);
 
+}
 
+
 
+struct nic_event_handler {
 
+	u16 cmd;
 
+	void (*handler)(void *hwdev, void *buf_in, u16 in_size, void *buf_out,
 
+			u16 *out_size);
 
+};
 
+
 
+static const struct nic_event_handler nic_cmd_handler[] = {};
 
+
 
+/**
 
+ * Handle NIC event based on the provided command.
 
+ *
 
+ * @param[in] hwdev
 
+ * Pointer to hardware device structure.
 
+ * @param[in] cmd
 
+ * The command associated with the NIC event to be handled.
 
+ * @param[in] buf_in
 
+ * The input buffer containing the event data.
 
+ * @param[in] in_size
 
+ * The size of the input buffer.
 
+ * @param[out] buf_out
 
+ * The output buffer to store the event response.
 
+ * @param[out] out_size
 
+ * The size of the output data stored in the output buffer.
 
+ */
 
+static void
 
+nic_event_handler(void *hwdev, u16 cmd, void *buf_in, u16 in_size,
 
+		  void *buf_out, u16 *out_size)
 
+{
 
+	u32 i, size = ARRAY_LEN(nic_cmd_handler);
 
+
 
+	if (!hwdev)
 
+		return;
 
+
 
+	*out_size = 0;
 
+
 
+	for (i = 0; i < size; i++) {
 
+		if (cmd == nic_cmd_handler[i].cmd) {
 
+			nic_cmd_handler[i].handler(hwdev, buf_in, in_size,
 
+						   buf_out, out_size);
 
+			break;
 
+		}

drivers/net/hinic3/base/hinic3_nic_event.c line 346

Quoted 10 lines
drivers/net/hinic3/base/hinic3_nic_event.c +5 -0
 
+	}
 
+
 
+	if (i == size)
 
+		PMD_DRV_LOG(WARNING, "Unsupported nic event cmd(%d) to process",
 
+			    cmd);

why not ERROR?

Quoted 265 lines
drivers/net/hinic3/base/hinic3_nic_event.c +87 -0
+}
 
+
 
+/*
 
+ * VF handler mbox msg from ppf/pf.
 
+ * VF link change event.
 
+ */
 
+int
 
+hinic3_vf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
 
+			void *buf_in, u16 in_size, void *buf_out, u16 *out_size)
 
+{
 
+	nic_event_handler(hwdev, cmd, buf_in, in_size, buf_out, out_size);
 
+	return 0;
 
+}
 
+
 
+/* NIC event of PF/PPF handler reported by mgmt cpu. */
 
+void
 
+hinic3_pf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
 
+			void *buf_in, u16 in_size, void *buf_out, u16 *out_size)
 
+{
 
+	nic_event_handler(hwdev, cmd, buf_in, in_size, buf_out, out_size);
 
+}
 
+
 
+static const struct nic_event_handler mag_cmd_handler[] = {
 
+	{
 
+		.cmd = MAG_CMD_GET_LINK_STATUS,
 
+		.handler = link_status_event_handler,
 
+	},
 
+	{
 
+		.cmd = MAG_CMD_EVENT_PORT_INFO,
 
+		.handler = port_info_event_printf,
 
+	},
 
+};
 
+
 
+static int
 
+hinic3_mag_event_handler(void *hwdev, u16 cmd, void *buf_in, u16 in_size,
 
+			 void *buf_out, u16 *out_size)
 
+{
 
+	u32 size = ARRAY_LEN(mag_cmd_handler);
 
+	u32 i;
 
+
 
+	if (!hwdev)
 
+		return -EINVAL;
 
+
 
+	*out_size = 0;
 
+	for (i = 0; i < size; i++) {
 
+		if (cmd == mag_cmd_handler[i].cmd) {
 
+			mag_cmd_handler[i].handler(hwdev, buf_in, in_size,
 
+						   buf_out, out_size);
 
+			break;
 
+		}
 
+	}
 
+
 
+	/* Can't find this event cmd. */
 
+	if (i == size)
 
+		PMD_DRV_LOG(ERR, "Unsupported mag event, cmd: %u", cmd);
 
+
 
+	return 0;
 
+}
 
+
 
+int
 
+hinic3_vf_mag_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
 
+			    void *buf_in, u16 in_size, void *buf_out,
 
+			    u16 *out_size)
 
+{
 
+	return hinic3_mag_event_handler(hwdev, cmd, buf_in, in_size, buf_out,
 
+					out_size);
 
+}
 
+
 
+/* pf/ppf handler mgmt cpu report hilink event. */
 
+void
 
+hinic3_pf_mag_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
 
+			    void *buf_in, u16 in_size, void *buf_out,
 
+			    u16 *out_size)
 
+{
 
+	hinic3_mag_event_handler(hwdev, cmd, buf_in, in_size, buf_out,
 
+				 out_size);
 
+}
 
+
 
+u8
 
+hinic3_nic_sw_aeqe_handler(__rte_unused void *hwdev, u8 event, u8 *data)
 
+{
 
+	PMD_DRV_LOG(ERR,
 
+		    "Received nic ucode aeq event type: 0x%x, data: %" PRIu64,
 
+		    event, *((u64 *)data));
 
+
 
+	return 0;
 
+}
drivers/net/hinic3/base/hinic3_nic_event.h +0 -0

new file mode 100644

index 0000000000..6a792e6af5

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_nic_event.h

drivers/net/hinic3/base/hinic3_nic_event.h +39 -0
@@ -0,0 +1,39 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#ifndef _HINIC3_NIC_EVENT_H_
 
+#define _HINIC3_NIC_EVENT_H_
 
+
 
+/**
 
+ * Get the Ethernet port link information based on the link state.
 
+ *
 
+ * @param[in] hwdev
 
+ * The hardware device context.
 
+ * @param[in] link_state
 
+ * The current link state (0 = down, non-zero = up).
 
+ * @param[out] link
 
+ * Pointer to the `rte_eth_link` structure.
 
+ */
 
+void get_port_info(struct hinic3_hwdev *hwdev, u8 link_state,
 
+		   struct rte_eth_link *link);
 
+
 
+int hinic3_vf_event_handler(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
 
+			    void *buf_in, u16 in_size, void *buf_out,
 
+			    u16 *out_size);
 
+
 
+void hinic3_pf_event_handler(void *hwdev, __rte_unused void *pri_handle,
 
+			     u16 cmd, void *buf_in, u16 in_size, void *buf_out,
 
+			     u16 *out_size);
 
+
 
+int hinic3_vf_mag_event_handler(void *hwdev, void *pri_handle, u16 cmd,
 
+				void *buf_in, u16 in_size, void *buf_out,
 
+				u16 *out_size);
 
+
 
+void hinic3_pf_mag_event_handler(void *hwdev, void *pri_handle, u16 cmd,
 
+				 void *buf_in, u16 in_size, void *buf_out,
 
+				 u16 *out_size);
 
+
 
+u8 hinic3_nic_sw_aeqe_handler(__rte_unused void *hwdev, u8 event, u8 *data);
 
+
 
+#endif /* _HINIC3_NIC_EVENT_H_ */
#137 lore raw

PATCH v5 6/18 net/hinic3: add eq mechanism function code

In reply to Feifei Wang

From: Yi Chen <[email protected]>

Eqs include aeq and ceq. Aeq is a kind of queue for mgmt asynchronous message and mgmt command response message. This patch introduces data structures, initialization, and related interfaces about aeq.

---
 drivers/net/hinic3/base/hinic3_eqs.c | 721 +++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_eqs.h |  98 ++++
 2 files changed, 819 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.c
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.h
drivers/net/hinic3/base/hinic3_eqs.c new file +721 -0
new file mode 100644
index 0000000000..745b1fbad5
@@ -0,0 +1,721 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#include <rte_atomic.h>
+#include <rte_memory.h>
+#include <rte_memzone.h>
+#include "hinic3_compat.h"
+#include "hinic3_csr.h"
+#include "hinic3_eqs.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_hwif.h"
+#include "hinic3_mbox.h"
+#include "hinic3_mgmt.h"
+#include "hinic3_nic_event.h"
+
+/* Indicate AEQ_CTRL_0 shift. */
+#define AEQ_CTRL_0_INTR_IDX_SHIFT     0
+#define AEQ_CTRL_0_DMA_ATTR_SHIFT     12
+#define AEQ_CTRL_0_PCI_INTF_IDX_SHIFT 20
+#define AEQ_CTRL_0_INTR_MODE_SHIFT    31
+
+/* Indicate AEQ_CTRL_0 mask. */
+#define AEQ_CTRL_0_INTR_IDX_MASK     0x3FFU
+#define AEQ_CTRL_0_DMA_ATTR_MASK     0x3FU
+#define AEQ_CTRL_0_PCI_INTF_IDX_MASK 0x7U
+#define AEQ_CTRL_0_INTR_MODE_MASK    0x1U
+
+/* Set and clear the AEQ_CTRL_0 bit fields. */
+#define AEQ_CTRL_0_SET(val, member) \
+	(((val) & AEQ_CTRL_0_##member##_MASK) << AEQ_CTRL_0_##member##_SHIFT)
+#define AEQ_CTRL_0_CLEAR(val, member) \
+	((val) & (~(AEQ_CTRL_0_##member##_MASK << AEQ_CTRL_0_##member##_SHIFT)))
+
+/* Indicate AEQ_CTRL_1 shift. */
+#define AEQ_CTRL_1_LEN_SHIFT	   0
+#define AEQ_CTRL_1_ELEM_SIZE_SHIFT 24
+#define AEQ_CTRL_1_PAGE_SIZE_SHIFT 28
+
+/* Indicate AEQ_CTRL_1 mask. */
+#define AEQ_CTRL_1_LEN_MASK	  0x1FFFFFU
+#define AEQ_CTRL_1_ELEM_SIZE_MASK 0x3U
+#define AEQ_CTRL_1_PAGE_SIZE_MASK 0xFU
+
+/* Set and clear the AEQ_CTRL_1 bit fields. */
+#define AEQ_CTRL_1_SET(val, member) \
+	(((val) & AEQ_CTRL_1_##member##_MASK) << AEQ_CTRL_1_##member##_SHIFT)
+#define AEQ_CTRL_1_CLEAR(val, member) \
+	((val) & (~(AEQ_CTRL_1_##member##_MASK << AEQ_CTRL_1_##member##_SHIFT)))
+
+#define HINIC3_EQ_PROD_IDX_MASK	      0xFFFFF
+#define HINIC3_TASK_PROCESS_EQE_LIMIT 1024
+#define HINIC3_EQ_UPDATE_CI_STEP      64
+
+/* Indicate EQ_ELEM_DESC shift. */
+#define EQ_ELEM_DESC_TYPE_SHIFT	   0
+#define EQ_ELEM_DESC_SRC_SHIFT	   7
+#define EQ_ELEM_DESC_SIZE_SHIFT	   8
+#define EQ_ELEM_DESC_WRAPPED_SHIFT 31
+
+/* Indicate EQ_ELEM_DESC mask. */
+#define EQ_ELEM_DESC_TYPE_MASK	  0x7FU
+#define EQ_ELEM_DESC_SRC_MASK	  0x1U
+#define EQ_ELEM_DESC_SIZE_MASK	  0xFFU
+#define EQ_ELEM_DESC_WRAPPED_MASK 0x1U
+
+/* Get the AEQ_CTRL_1 bit fields. */
+#define EQ_ELEM_DESC_GET(val, member)               \
+	(((val) >> EQ_ELEM_DESC_##member##_SHIFT) & \
+	 EQ_ELEM_DESC_##member##_MASK)
+
+/* Indicate EQ_CI_SIMPLE_INDIR shift. */
+#define EQ_CI_SIMPLE_INDIR_CI_SHIFT	 0
+#define EQ_CI_SIMPLE_INDIR_ARMED_SHIFT	 21
+#define EQ_CI_SIMPLE_INDIR_AEQ_IDX_SHIFT 30
+
+/* Indicate EQ_CI_SIMPLE_INDIR mask. */
+#define EQ_CI_SIMPLE_INDIR_CI_MASK	0x1FFFFFU
+#define EQ_CI_SIMPLE_INDIR_ARMED_MASK	0x1U
+#define EQ_CI_SIMPLE_INDIR_AEQ_IDX_MASK 0x3U
+
+/* Set and clear the EQ_CI_SIMPLE_INDIR bit fields. */
+#define EQ_CI_SIMPLE_INDIR_SET(val, member)           \
+	(((val) & EQ_CI_SIMPLE_INDIR_##member##_MASK) \
+	 << EQ_CI_SIMPLE_INDIR_##member##_SHIFT)
+#define EQ_CI_SIMPLE_INDIR_CLEAR(val, member)          \
+	((val) & (~(EQ_CI_SIMPLE_INDIR_##member##_MASK \
+		    << EQ_CI_SIMPLE_INDIR_##member##_SHIFT)))
+
+#define EQ_WRAPPED(eq) ((u32)(eq)->wrapped << EQ_VALID_SHIFT)
+
+#define EQ_CONS_IDX(eq)                                                    \
+	({                                                                 \
+		typeof(eq) __eq = (eq);                                    \
+		__eq->cons_idx | ((u32)__eq->wrapped << EQ_WRAPPED_SHIFT); \
+	})
+#define GET_EQ_NUM_PAGES(eq, size)                                     \
+	({                                                             \
+		typeof(eq) __eq = (eq);                                \
+		typeof(size) __size = (size);                          \
+		(u16)(RTE_ALIGN((u32)(__eq->eq_len * __eq->elem_size), \
+				__size) /                              \
+		      __size);                                         \
+	})
+
+#define GET_EQ_NUM_ELEMS(eq, pg_size) ((pg_size) / (u32)(eq)->elem_size)
+
+#define GET_EQ_ELEMENT(eq, idx)                                         \
+	({                                                              \
+		typeof(eq) __eq = (eq);                                 \
+		typeof(idx) __idx = (idx);                              \
+		((u8 *)__eq->virt_addr[__idx / __eq->num_elem_in_pg]) + \
+			(u32)((__idx & (__eq->num_elem_in_pg - 1)) *    \
+			      __eq->elem_size);                         \
+	})
+
+#define GET_AEQ_ELEM(eq, idx) \
+	((struct hinic3_aeq_elem *)GET_EQ_ELEMENT((eq), (idx)))
+
+#define PAGE_IN_4K(page_size)	    ((page_size) >> 12)
+#define EQ_SET_HW_PAGE_SIZE_VAL(eq) ((u32)ilog2(PAGE_IN_4K((eq)->page_size)))
+
+#define ELEMENT_SIZE_IN_32B(eq)	    (((eq)->elem_size) >> 5)
+#define EQ_SET_HW_ELEM_SIZE_VAL(eq) ((u32)ilog2(ELEMENT_SIZE_IN_32B(eq)))
+
+#define AEQ_DMA_ATTR_DEFAULT 0
+
+#define EQ_WRAPPED_SHIFT 20
+
+#define EQ_VALID_SHIFT 31
+
+#define aeq_to_aeqs(eq)                                                      \
+	({                                                                   \
+		typeof(eq) __eq = (eq);                                      \
+		container_of(__eq - __eq->q_id, struct hinic3_aeqs, aeq[0]); \
+	})
+
+#define AEQ_MSIX_ENTRY_IDX_0 0
+
+/**
+ * Write the consumer idx to hw.
+ *
+ * @param[in] eq
+ * The event queue to update the cons idx.
+ * @param[in] arm_state
+ * Indicate whether report interrupts when generate eq element.
+ */
+static void
+set_eq_cons_idx(struct hinic3_eq *eq, u32 arm_state)
+{
+	u32 eq_wrap_ci = 0;
+	u32 val = 0;
+	u32 addr = HINIC3_CSR_AEQ_CI_SIMPLE_INDIR_ADDR;
+
+	eq_wrap_ci = EQ_CONS_IDX(eq);
+
+	/* Dpdk pmd driver only aeq0 use int_arm mode. */
+	if (eq->q_id != 0)
+		val = EQ_CI_SIMPLE_INDIR_SET(HINIC3_EQ_NOT_ARMED, ARMED);
+	else
+		val = EQ_CI_SIMPLE_INDIR_SET(arm_state, ARMED);
+
+	val = val | EQ_CI_SIMPLE_INDIR_SET(eq_wrap_ci, CI) |
+	      EQ_CI_SIMPLE_INDIR_SET(eq->q_id, AEQ_IDX);
+
+	hinic3_hwif_write_reg(eq->hwdev->hwif, addr, val);
+}
+
+/**
+ * Set aeq's ctrls registers.
+ *
+ * @param[in] eq
+ * The event queue for setting.
+ */
+static void
+set_aeq_ctrls(struct hinic3_eq *eq)
+{
+	struct hinic3_hwif *hwif = eq->hwdev->hwif;
+	struct irq_info *eq_irq = &eq->eq_irq;
+	u32 addr, val, ctrl0, ctrl1, page_size_val, elem_size;
+	u32 pci_intf_idx = HINIC3_PCI_INTF_IDX(hwif);
+
+	/* Set AEQ ctrl0. */
+	addr = HINIC3_CSR_AEQ_CTRL_0_ADDR;
+
+	val = hinic3_hwif_read_reg(hwif, addr);
+
+	val = AEQ_CTRL_0_CLEAR(val, INTR_IDX) &
+	      AEQ_CTRL_0_CLEAR(val, DMA_ATTR) &
+	      AEQ_CTRL_0_CLEAR(val, PCI_INTF_IDX) &
+	      AEQ_CTRL_0_CLEAR(val, INTR_MODE);
+
+	ctrl0 = AEQ_CTRL_0_SET(eq_irq->msix_entry_idx, INTR_IDX) |
+		AEQ_CTRL_0_SET(AEQ_DMA_ATTR_DEFAULT, DMA_ATTR) |
+		AEQ_CTRL_0_SET(pci_intf_idx, PCI_INTF_IDX) |
+		AEQ_CTRL_0_SET(HINIC3_INTR_MODE_ARMED, INTR_MODE);
+
+	val |= ctrl0;
+
+	hinic3_hwif_write_reg(hwif, addr, val);
+
+	/* Set AEQ ctrl1. */
+	addr = HINIC3_CSR_AEQ_CTRL_1_ADDR;
+
+	page_size_val = EQ_SET_HW_PAGE_SIZE_VAL(eq);
+	elem_size = EQ_SET_HW_ELEM_SIZE_VAL(eq);
+
+	ctrl1 = AEQ_CTRL_1_SET(eq->eq_len, LEN) |
+		AEQ_CTRL_1_SET(elem_size, ELEM_SIZE) |
+		AEQ_CTRL_1_SET(page_size_val, PAGE_SIZE);
+
+	hinic3_hwif_write_reg(hwif, addr, ctrl1);
+}
+
+/**
+ * Initialize all the elements in the aeq.
+ *
+ * @param[in] eq
+ * The event queue.
+ * @param[in] init_val
+ * Value to init.
+ */
+static void
+aeq_elements_init(struct hinic3_eq *eq, u32 init_val)
+{
+	struct hinic3_aeq_elem *aeqe = NULL;
+	u32 i;
+
+	for (i = 0; i < eq->eq_len; i++) {
+		aeqe = GET_AEQ_ELEM(eq, i);
+		aeqe->desc = cpu_to_be32(init_val);
+	}
+
+	rte_atomic_thread_fence(rte_memory_order_release); /**< Write the init values. */
+}
+
+/**
+ * Set the pages for the event queue.
+ *
+ * @param[in] eq
+ * The event queue.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+set_eq_pages(struct hinic3_eq *eq)
+{
+	struct hinic3_hwif *hwif = eq->hwdev->hwif;
+	u32 reg, init_val;
+	u16 pg_num, i;
+	int err;
+
+	for (pg_num = 0; pg_num < eq->num_pages; pg_num++) {
+		/* Allocate memory for each page. */
+		eq->eq_mz[pg_num] = hinic3_dma_zone_reserve(eq->hwdev->eth_dev,
+			"eq_mz", eq->q_id, eq->page_size,
+			eq->page_size, SOCKET_ID_ANY);
+		if (!eq->eq_mz[pg_num]) {
+			err = -ENOMEM;
+			goto dma_alloc_err;
+		}
+
+		/* Write physical memory address and virtual memory address. */
+		eq->dma_addr[pg_num] = eq->eq_mz[pg_num]->iova;
+		eq->virt_addr[pg_num] = eq->eq_mz[pg_num]->addr;
+
+		reg = HINIC3_AEQ_HI_PHYS_ADDR_REG(pg_num);
+		hinic3_hwif_write_reg(hwif, reg,
+				      upper_32_bits(eq->dma_addr[pg_num]));
+
+		reg = HINIC3_AEQ_LO_PHYS_ADDR_REG(pg_num);
+		hinic3_hwif_write_reg(hwif, reg,
+				      lower_32_bits(eq->dma_addr[pg_num]));
+	}
+	/* Calculate the number of elements that can be accommodated. */
+	eq->num_elem_in_pg = GET_EQ_NUM_ELEMS(eq, eq->page_size);
+	if (eq->num_elem_in_pg & (eq->num_elem_in_pg - 1)) {
+		PMD_DRV_LOG(ERR, "Number element in eq page != power of 2");
+		err = -EINVAL;
+		goto dma_alloc_err;
+	}
+	init_val = EQ_WRAPPED(eq);
+
+	/* Initialize elements in the queue. */
+	aeq_elements_init(eq, init_val);
+
+	return 0;
+
+dma_alloc_err:
+	for (i = 0; i < pg_num; i++)
+		hinic3_memzone_free(eq->eq_mz[i]);
+
+	return err;
+}
+
+/**
+ * Allocate the pages for the event queue.
+ *
+ * @param[in] eq
+ * The event queue.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+alloc_eq_pages(struct hinic3_eq *eq)
+{
+	u64 dma_addr_size, virt_addr_size, eq_mz_size;
+	int err;
+
+	/* Calculate the size of the memory to be allocated. */
+	dma_addr_size = eq->num_pages * sizeof(*eq->dma_addr);
+	virt_addr_size = eq->num_pages * sizeof(*eq->virt_addr);
+	eq_mz_size = eq->num_pages * sizeof(*eq->eq_mz);
+
+	eq->dma_addr = rte_zmalloc("eq_dma", dma_addr_size,
+				   HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!eq->dma_addr)
+		return -ENOMEM;
+
+	eq->virt_addr = rte_zmalloc("eq_va", virt_addr_size,
+				    HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!eq->virt_addr) {
+		err = -ENOMEM;
+		goto virt_addr_alloc_err;
+	}
+
+	eq->eq_mz =
+		rte_zmalloc("eq_mz", eq_mz_size, HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!eq->eq_mz) {
+		err = -ENOMEM;
+		goto eq_mz_alloc_err;
+	}
+	err = set_eq_pages(eq);
+	if (err != 0)
+		goto eq_pages_err;
+
+	return 0;
+
+eq_pages_err:
+	rte_free(eq->eq_mz);
+
+eq_mz_alloc_err:
+	rte_free(eq->virt_addr);
+
+virt_addr_alloc_err:
+	rte_free(eq->dma_addr);
+
+	return err;
+}
+
+/**
+ * Free the pages of the event queue.
+ *
+ * @param[in] eq
+ * The event queue.
+ */
+static void
+free_eq_pages(struct hinic3_eq *eq)
+{
+	u16 pg_num;
+
+	for (pg_num = 0; pg_num < eq->num_pages; pg_num++)
+		hinic3_memzone_free(eq->eq_mz[pg_num]);
+
+	rte_free(eq->eq_mz);
+	rte_free(eq->virt_addr);
+	rte_free(eq->dma_addr);
+}
+
+static u32
+get_page_size(struct hinic3_eq *eq)
+{
+	u32 total_size;
+	u16 count, n = 0;
+
+	/* Total memory size. */
+	total_size = RTE_ALIGN((eq->eq_len * eq->elem_size),
+			       HINIC3_MIN_EQ_PAGE_SIZE);
+	if (total_size <= (HINIC3_EQ_MAX_PAGES * HINIC3_MIN_EQ_PAGE_SIZE))
+		return HINIC3_MIN_EQ_PAGE_SIZE;
+	/* Total number of pages. */
+	count = (u16)(RTE_ALIGN((total_size / HINIC3_EQ_MAX_PAGES),
+				HINIC3_MIN_EQ_PAGE_SIZE) /
+		      HINIC3_MIN_EQ_PAGE_SIZE);
+
+	/* Whether count is a power of 2. */
+	if (!(count & (count - 1)))
+		return HINIC3_MIN_EQ_PAGE_SIZE * count;
+
+	while (count) {
+		count >>= 1;
+		n++;
+	}
+
+	return ((u32)HINIC3_MIN_EQ_PAGE_SIZE) << n;
+}
+
+/**
+ * Initialize AEQ.
+ *
+ * @param[in] eq
+ * The event queue.
+ * @param[in] hwdev
+ * The pointer to the private hardware device.
+ * @param[in] q_id
+ * Queue id number.
+ * @param[in] q_len
+ * The number of EQ elements.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+init_aeq(struct hinic3_eq *eq, struct hinic3_hwdev *hwdev, u16 q_id, u32 q_len)
+{
+	int err = 0;
+
+	eq->hwdev = hwdev;
+	eq->q_id = q_id;
+	eq->eq_len = q_len;
+
+	/* Indirect access should set q_id first. */
+	hinic3_hwif_write_reg(hwdev->hwif, HINIC3_AEQ_INDIR_IDX_ADDR, eq->q_id);
+	rte_atomic_thread_fence(rte_memory_order_release); /**< write index before config. */
+
+	/* Clear eq_len to force eqe drop in hardware. */
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_CSR_AEQ_CTRL_1_ADDR, 0);
+	rte_atomic_thread_fence(rte_memory_order_release);
+	/* Init aeq pi to 0 before allocating aeq pages. */
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_CSR_AEQ_PROD_IDX_ADDR, 0);
+
+	eq->cons_idx = 0;
+	eq->wrapped = 0;
+
+	eq->elem_size = HINIC3_AEQE_SIZE;
+	eq->page_size = get_page_size(eq);
+	eq->orig_page_size = eq->page_size;
+	eq->num_pages = GET_EQ_NUM_PAGES(eq, eq->page_size);
+	if (eq->num_pages > HINIC3_EQ_MAX_PAGES) {
+		PMD_DRV_LOG(ERR, "Too many pages: %d for aeq", eq->num_pages);
+		return -EINVAL;
+	}
+
+	err = alloc_eq_pages(eq);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Allocate pages for eq failed");
+		return err;
+	}
+
+	/* Pmd driver uses AEQ_MSIX_ENTRY_IDX_0. */
+	eq->eq_irq.msix_entry_idx = AEQ_MSIX_ENTRY_IDX_0;
+	set_aeq_ctrls(eq);
+
+	set_eq_cons_idx(eq, HINIC3_EQ_ARMED);
+
+	if (eq->q_id == 0)
+		hinic3_set_msix_state(hwdev, 0, HINIC3_MSIX_ENABLE);
+
+	eq->poll_retry_nr = HINIC3_RETRY_NUM;
+
+	return 0;
+}
+
+/**
+ * Remove AEQ.
+ *
+ * @param[in] eq
+ * The event queue.
+ */
+static void
+remove_aeq(struct hinic3_eq *eq)
+{
+	struct irq_info *entry = &eq->eq_irq;
+
+	if (eq->q_id == 0)
+		hinic3_set_msix_state(eq->hwdev, entry->msix_entry_idx,
+				      HINIC3_MSIX_DISABLE);
+
+	/* Indirect access should set q_id first. */
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_AEQ_INDIR_IDX_ADDR,
+			      eq->q_id);
+
+	rte_atomic_thread_fence(rte_memory_order_release); /**< Write index before config. */
+
+	/* Clear eq_len to avoid hw access host memory. */
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_CSR_AEQ_CTRL_1_ADDR, 0);
+
+	/* Update cons_idx to avoid invalid interrupt. */
+	eq->cons_idx = hinic3_hwif_read_reg(eq->hwdev->hwif,
+					    HINIC3_CSR_AEQ_PROD_IDX_ADDR);
+	set_eq_cons_idx(eq, HINIC3_EQ_NOT_ARMED);
+
+	free_eq_pages(eq);
+}
+
+/**
+ * Init all AEQs.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device object
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+int
+hinic3_aeqs_init(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_aeqs *aeqs = NULL;
+	u16 num_aeqs;
+	int err;
+	u16 i, q_id;
+
+	if (!hwdev)
+		return -EINVAL;
+
+	num_aeqs = HINIC3_HWIF_NUM_AEQS(hwdev->hwif);
+	if (num_aeqs > HINIC3_MAX_AEQS) {
+		PMD_DRV_LOG(INFO, "Adjust aeq num to %d", HINIC3_MAX_AEQS);
+		num_aeqs = HINIC3_MAX_AEQS;
+	} else if (num_aeqs < HINIC3_MIN_AEQS) {
+		PMD_DRV_LOG(ERR, "PMD needs %d AEQs, Chip has %d",
+			    HINIC3_MIN_AEQS, num_aeqs);
+		return -EINVAL;
+	}
+
+	aeqs = rte_zmalloc("hinic3_aeqs", sizeof(*aeqs),
+			   HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!aeqs)
+		return -ENOMEM;
+
+	hwdev->aeqs = aeqs;
+	aeqs->hwdev = hwdev;
+	aeqs->num_aeqs = num_aeqs;
+
+	for (q_id = 0; q_id < num_aeqs; q_id++) {
+		err = init_aeq(&aeqs->aeq[q_id], hwdev, q_id,
+			       HINIC3_DEFAULT_AEQ_LEN);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Init aeq %d failed", q_id);
+			goto init_aeq_err;
+		}
+	}
+
+	return 0;
+
+init_aeq_err:
+	for (i = 0; i < q_id; i++)
+		remove_aeq(&aeqs->aeq[i]);
+
+	rte_free(aeqs);
+	return err;
+}
+
+/**
+ * Free all AEQs.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device.
+ */
+void
+hinic3_aeqs_free(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_aeqs *aeqs = hwdev->aeqs;
+	u16 q_id;
+
+	for (q_id = 0; q_id < aeqs->num_aeqs; q_id++)
+		remove_aeq(&aeqs->aeq[q_id]);
+
+	rte_free(aeqs);
+}
+
+void
+hinic3_dump_aeq_info(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_aeq_elem *aeqe_pos = NULL;
+	struct hinic3_eq *eq = NULL;
+	u32 addr, ci, pi, ctrl0, idx;
+	int q_id;
+
+	for (q_id = 0; q_id < hwdev->aeqs->num_aeqs; q_id++) {
+		eq = &hwdev->aeqs->aeq[q_id];
+		/* Indirect access should set q_id first. */
+		hinic3_hwif_write_reg(eq->hwdev->hwif,
+				      HINIC3_AEQ_INDIR_IDX_ADDR, eq->q_id);
+		/* Write index before config. */
+		rte_atomic_thread_fence(rte_memory_order_release);
+
+		addr = HINIC3_CSR_AEQ_CTRL_0_ADDR;
+
+		ctrl0 = hinic3_hwif_read_reg(hwdev->hwif, addr);
+
+		idx = hinic3_hwif_read_reg(hwdev->hwif,
+					   HINIC3_AEQ_INDIR_IDX_ADDR);
+
+		addr = HINIC3_CSR_AEQ_CONS_IDX_ADDR;
+		ci = hinic3_hwif_read_reg(hwdev->hwif, addr);
+		addr = HINIC3_CSR_AEQ_PROD_IDX_ADDR;
+		pi = hinic3_hwif_read_reg(hwdev->hwif, addr);
+		aeqe_pos = GET_AEQ_ELEM(eq, eq->cons_idx);
+		PMD_DRV_LOG(ERR,
+			    "Aeq id: %d, idx: %u, ctrl0: 0x%08x, wrap: %d,"
+			    " pi: 0x%x, ci: 0x%08x,  desc: 0x%x",
+			    q_id, idx, ctrl0, eq->wrapped, pi, ci,
+			    be32_to_cpu(aeqe_pos->desc));
+	}
+}
+
+static int
+aeq_elem_handler(struct hinic3_eq *eq, u32 aeqe_desc,
+		 struct hinic3_aeq_elem *aeqe_pos, void *param)
+{
+	enum hinic3_aeq_type event;
+	u8 data[HINIC3_AEQE_DATA_SIZE];
+	u8 size;
+
+	event = EQ_ELEM_DESC_GET(aeqe_desc, TYPE);
+	if (EQ_ELEM_DESC_GET(aeqe_desc, SRC)) {
+		/* SW event uses only the first 8B. */
+		memcpy(data, aeqe_pos->aeqe_data, HINIC3_AEQE_DATA_SIZE);
+		hinic3_be32_to_cpu(data, HINIC3_AEQE_DATA_SIZE);
+		/* Just support HINIC3_STATELESS_EVENT. */
+		return hinic3_nic_sw_aeqe_handler(eq->hwdev, event, data);
+	}
+
+	memcpy(data, aeqe_pos->aeqe_data, HINIC3_AEQE_DATA_SIZE);
+	hinic3_be32_to_cpu(data, HINIC3_AEQE_DATA_SIZE);
+	size = EQ_ELEM_DESC_GET(aeqe_desc, SIZE);
+
+	if (event == HINIC3_MSG_FROM_MGMT_CPU) {
+		return hinic3_mgmt_msg_aeqe_handler(eq->hwdev, data, size,
+						    param);
+	} else if (event == HINIC3_MBX_FROM_FUNC) {
+		return hinic3_mbox_func_aeqe_handler(eq->hwdev, data, size,
+						     param);
+	} else {
+		PMD_DRV_LOG(ERR, "AEQ hw event not support %d", event);
+		return -EINVAL;
+	}
+}
+
+/**
+ * Poll one or continue aeqe, and call dedicated process.
+ *
+ * @param[in] eq
+ * Pointer to the event queue.
+ * @param[in] timeout
+ * equal to 0 - Poll all aeqe in eq, used in interrupt mode.
+ * Greater than 0 - Poll aeq until get aeqe with 'last' field set to 1, used in
+ * polling mode.
+ * @param[in] param
+ * Customized parameter.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+int
+hinic3_aeq_poll_msg(struct hinic3_eq *eq, u32 timeout, void *param)
+{
+	struct hinic3_aeq_elem *aeqe_pos = NULL;
+	u32 aeqe_desc = 0;
+	u32 eqe_cnt = 0;
+	int err = -EFAULT;
+	int done = HINIC3_MSG_HANDLER_RES;
+	unsigned long end;
+	u16 i;
+
+	for (i = 0; ((timeout == 0) && (i < eq->eq_len)) ||
+		    ((timeout > 0) && (done != 0) && (i < eq->eq_len));
+	     i++) {
+		err = -EIO;
+		end = jiffies + msecs_to_jiffies(timeout);
+		do {
+			aeqe_pos = GET_AEQ_ELEM(eq, eq->cons_idx);
+
+			/* Data in HW is in Big endian format. */
+			aeqe_desc = be32_to_cpu(aeqe_pos->desc);
+
+			/*
+			 * HW updates wrapped bit, when it adds eq element
+			 * event.
+			 */
+			if (EQ_ELEM_DESC_GET(aeqe_desc, WRAPPED) !=
+			    eq->wrapped) {
+				err = 0;
+				rte_atomic_thread_fence(rte_memory_order_acquire);
+				break;
+			}
+
+			if (timeout != 0)
+				usleep(HINIC3_AEQE_DESC_SIZE);
+		} while (time_before(jiffies, end));
+
+		if (err != 0) /**< Poll time out. */
+			break;
+		/* Handle the middle element of the event queue. */
+		done = aeq_elem_handler(eq, aeqe_desc, aeqe_pos, param);
+
+		eq->cons_idx++;
+		if (eq->cons_idx == eq->eq_len) {
+			eq->cons_idx = 0;
+			eq->wrapped = !eq->wrapped;
+		}
+
+		if (++eqe_cnt >= HINIC3_EQ_UPDATE_CI_STEP) {
+			eqe_cnt = 0;
+			set_eq_cons_idx(eq, HINIC3_EQ_NOT_ARMED);
+		}
+	}
+	/* Set the consumer index of the event queue. */
+	set_eq_cons_idx(eq, HINIC3_EQ_ARMED);
+
+	return err;
+}
+
+void
+hinic3_dev_handle_aeq_event(struct hinic3_hwdev *hwdev, void *param)
+{
+	struct hinic3_eq *aeq = &hwdev->aeqs->aeq[0];
+
+	/* Clear resend timer cnt register. */
+	hinic3_misx_intr_clear_resend_bit(hwdev, aeq->eq_irq.msix_entry_idx,
+					  MSIX_RESEND_TIMER_CLEAR);
+	hinic3_aeq_poll_msg(aeq, 0, param);
+}
drivers/net/hinic3/base/hinic3_eqs.h new file +98 -0

98 lines not on this page · raw message

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

Re: [V5 06/18] net/hinic3: add eq mechanism function code

Quoted 2 lines · Feifei Wang

From: Yi Chen <[email protected]>

the commit header should simply and don't include meaningless descriptor
suggest: net/hinic3: add eq mechanism

Quoted 346 lines

Eqs include aeq and ceq. Aeq is a kind of queue for mgmt

asynchronous message and mgmt command response message.

This patch introduces data structures, initialization,

and related interfaces about aeq.

---

 drivers/net/hinic3/base/hinic3_eqs.c | 721 +++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_eqs.h |  98 ++++
 2 files changed, 819 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.c
 create mode 100644 drivers/net/hinic3/base/hinic3_eqs.h
drivers/net/hinic3/base/hinic3_eqs.c +0 -0

new file mode 100644

index 0000000000..745b1fbad5

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_eqs.c

drivers/net/hinic3/base/hinic3_eqs.c +152 -0
@@ -0,0 +1,721 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#include <rte_atomic.h>
 
+#include <rte_memory.h>
 
+#include <rte_memzone.h>
 
+#include "hinic3_compat.h"
 
+#include "hinic3_csr.h"
 
+#include "hinic3_eqs.h"
 
+#include "hinic3_hwdev.h"
 
+#include "hinic3_hwif.h"
 
+#include "hinic3_mbox.h"
 
+#include "hinic3_mgmt.h"
 
+#include "hinic3_nic_event.h"
 
+
 
+/* Indicate AEQ_CTRL_0 shift. */
 
+#define AEQ_CTRL_0_INTR_IDX_SHIFT     0
 
+#define AEQ_CTRL_0_DMA_ATTR_SHIFT     12
 
+#define AEQ_CTRL_0_PCI_INTF_IDX_SHIFT 20
 
+#define AEQ_CTRL_0_INTR_MODE_SHIFT    31
 
+
 
+/* Indicate AEQ_CTRL_0 mask. */
 
+#define AEQ_CTRL_0_INTR_IDX_MASK     0x3FFU
 
+#define AEQ_CTRL_0_DMA_ATTR_MASK     0x3FU
 
+#define AEQ_CTRL_0_PCI_INTF_IDX_MASK 0x7U
 
+#define AEQ_CTRL_0_INTR_MODE_MASK    0x1U
 
+
 
+/* Set and clear the AEQ_CTRL_0 bit fields. */
 
+#define AEQ_CTRL_0_SET(val, member) \
 
+	(((val) & AEQ_CTRL_0_##member##_MASK) << AEQ_CTRL_0_##member##_SHIFT)
 
+#define AEQ_CTRL_0_CLEAR(val, member) \
 
+	((val) & (~(AEQ_CTRL_0_##member##_MASK << AEQ_CTRL_0_##member##_SHIFT)))
 
+
 
+/* Indicate AEQ_CTRL_1 shift. */
 
+#define AEQ_CTRL_1_LEN_SHIFT	   0
 
+#define AEQ_CTRL_1_ELEM_SIZE_SHIFT 24
 
+#define AEQ_CTRL_1_PAGE_SIZE_SHIFT 28
 
+
 
+/* Indicate AEQ_CTRL_1 mask. */
 
+#define AEQ_CTRL_1_LEN_MASK	  0x1FFFFFU
 
+#define AEQ_CTRL_1_ELEM_SIZE_MASK 0x3U
 
+#define AEQ_CTRL_1_PAGE_SIZE_MASK 0xFU
 
+
 
+/* Set and clear the AEQ_CTRL_1 bit fields. */
 
+#define AEQ_CTRL_1_SET(val, member) \
 
+	(((val) & AEQ_CTRL_1_##member##_MASK) << AEQ_CTRL_1_##member##_SHIFT)
 
+#define AEQ_CTRL_1_CLEAR(val, member) \
 
+	((val) & (~(AEQ_CTRL_1_##member##_MASK << AEQ_CTRL_1_##member##_SHIFT)))
 
+
 
+#define HINIC3_EQ_PROD_IDX_MASK	      0xFFFFF
 
+#define HINIC3_TASK_PROCESS_EQE_LIMIT 1024
 
+#define HINIC3_EQ_UPDATE_CI_STEP      64
 
+
 
+/* Indicate EQ_ELEM_DESC shift. */
 
+#define EQ_ELEM_DESC_TYPE_SHIFT	   0
 
+#define EQ_ELEM_DESC_SRC_SHIFT	   7
 
+#define EQ_ELEM_DESC_SIZE_SHIFT	   8
 
+#define EQ_ELEM_DESC_WRAPPED_SHIFT 31
 
+
 
+/* Indicate EQ_ELEM_DESC mask. */
 
+#define EQ_ELEM_DESC_TYPE_MASK	  0x7FU
 
+#define EQ_ELEM_DESC_SRC_MASK	  0x1U
 
+#define EQ_ELEM_DESC_SIZE_MASK	  0xFFU
 
+#define EQ_ELEM_DESC_WRAPPED_MASK 0x1U
 
+
 
+/* Get the AEQ_CTRL_1 bit fields. */
 
+#define EQ_ELEM_DESC_GET(val, member)               \
 
+	(((val) >> EQ_ELEM_DESC_##member##_SHIFT) & \
 
+	 EQ_ELEM_DESC_##member##_MASK)
 
+
 
+/* Indicate EQ_CI_SIMPLE_INDIR shift. */
 
+#define EQ_CI_SIMPLE_INDIR_CI_SHIFT	 0
 
+#define EQ_CI_SIMPLE_INDIR_ARMED_SHIFT	 21
 
+#define EQ_CI_SIMPLE_INDIR_AEQ_IDX_SHIFT 30
 
+
 
+/* Indicate EQ_CI_SIMPLE_INDIR mask. */
 
+#define EQ_CI_SIMPLE_INDIR_CI_MASK	0x1FFFFFU
 
+#define EQ_CI_SIMPLE_INDIR_ARMED_MASK	0x1U
 
+#define EQ_CI_SIMPLE_INDIR_AEQ_IDX_MASK 0x3U
 
+
 
+/* Set and clear the EQ_CI_SIMPLE_INDIR bit fields. */
 
+#define EQ_CI_SIMPLE_INDIR_SET(val, member)           \
 
+	(((val) & EQ_CI_SIMPLE_INDIR_##member##_MASK) \
 
+	 << EQ_CI_SIMPLE_INDIR_##member##_SHIFT)
 
+#define EQ_CI_SIMPLE_INDIR_CLEAR(val, member)          \
 
+	((val) & (~(EQ_CI_SIMPLE_INDIR_##member##_MASK \
 
+		    << EQ_CI_SIMPLE_INDIR_##member##_SHIFT)))
 
+
 
+#define EQ_WRAPPED(eq) ((u32)(eq)->wrapped << EQ_VALID_SHIFT)
 
+
 
+#define EQ_CONS_IDX(eq)                                                    \
 
+	({                                                                 \
 
+		typeof(eq) __eq = (eq);                                    \
 
+		__eq->cons_idx | ((u32)__eq->wrapped << EQ_WRAPPED_SHIFT); \
 
+	})
 
+#define GET_EQ_NUM_PAGES(eq, size)                                     \
 
+	({                                                             \
 
+		typeof(eq) __eq = (eq);                                \
 
+		typeof(size) __size = (size);                          \
 
+		(u16)(RTE_ALIGN((u32)(__eq->eq_len * __eq->elem_size), \
 
+				__size) /                              \
 
+		      __size);                                         \
 
+	})
 
+
 
+#define GET_EQ_NUM_ELEMS(eq, pg_size) ((pg_size) / (u32)(eq)->elem_size)
 
+
 
+#define GET_EQ_ELEMENT(eq, idx)                                         \
 
+	({                                                              \
 
+		typeof(eq) __eq = (eq);                                 \
 
+		typeof(idx) __idx = (idx);                              \
 
+		((u8 *)__eq->virt_addr[__idx / __eq->num_elem_in_pg]) + \
 
+			(u32)((__idx & (__eq->num_elem_in_pg - 1)) *    \
 
+			      __eq->elem_size);                         \
 
+	})
 
+
 
+#define GET_AEQ_ELEM(eq, idx) \
 
+	((struct hinic3_aeq_elem *)GET_EQ_ELEMENT((eq), (idx)))
 
+
 
+#define PAGE_IN_4K(page_size)	    ((page_size) >> 12)
 
+#define EQ_SET_HW_PAGE_SIZE_VAL(eq) ((u32)ilog2(PAGE_IN_4K((eq)->page_size)))
 
+
 
+#define ELEMENT_SIZE_IN_32B(eq)	    (((eq)->elem_size) >> 5)
 
+#define EQ_SET_HW_ELEM_SIZE_VAL(eq) ((u32)ilog2(ELEMENT_SIZE_IN_32B(eq)))
 
+
 
+#define AEQ_DMA_ATTR_DEFAULT 0
 
+
 
+#define EQ_WRAPPED_SHIFT 20
 
+
 
+#define EQ_VALID_SHIFT 31
 
+
 
+#define aeq_to_aeqs(eq)                                                      \
 
+	({                                                                   \
 
+		typeof(eq) __eq = (eq);                                      \
 
+		container_of(__eq - __eq->q_id, struct hinic3_aeqs, aeq[0]); \
 
+	})
 
+
 
+#define AEQ_MSIX_ENTRY_IDX_0 0
 
+
 
+/**
 
+ * Write the consumer idx to hw.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue to update the cons idx.
 
+ * @param[in] arm_state
 
+ * Indicate whether report interrupts when generate eq element.
 
+ */
 
+static void
 
+set_eq_cons_idx(struct hinic3_eq *eq, u32 arm_state)
 
+{
 
+	u32 eq_wrap_ci = 0;
 
+	u32 val = 0;

drivers/net/hinic3/base/hinic3_eqs.c line 157

Quoted 10 lines
drivers/net/hinic3/base/hinic3_eqs.c +5 -0
 
+	u32 addr = HINIC3_CSR_AEQ_CI_SIMPLE_INDIR_ADDR;
 
+
 
+	eq_wrap_ci = EQ_CONS_IDX(eq);
 
+
 
+	/* Dpdk pmd driver only aeq0 use int_arm mode. */

Only aeq0 use int_arm mode.?

Quoted 246 lines
drivers/net/hinic3/base/hinic3_eqs.c +123 -0
+	if (eq->q_id != 0)
 
+		val = EQ_CI_SIMPLE_INDIR_SET(HINIC3_EQ_NOT_ARMED, ARMED);
 
+	else
 
+		val = EQ_CI_SIMPLE_INDIR_SET(arm_state, ARMED);
 
+
 
+	val = val | EQ_CI_SIMPLE_INDIR_SET(eq_wrap_ci, CI) |
 
+	      EQ_CI_SIMPLE_INDIR_SET(eq->q_id, AEQ_IDX);
 
+
 
+	hinic3_hwif_write_reg(eq->hwdev->hwif, addr, val);
 
+}
 
+
 
+/**
 
+ * Set aeq's ctrls registers.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue for setting.
 
+ */
 
+static void
 
+set_aeq_ctrls(struct hinic3_eq *eq)
 
+{
 
+	struct hinic3_hwif *hwif = eq->hwdev->hwif;
 
+	struct irq_info *eq_irq = &eq->eq_irq;
 
+	u32 addr, val, ctrl0, ctrl1, page_size_val, elem_size;
 
+	u32 pci_intf_idx = HINIC3_PCI_INTF_IDX(hwif);
 
+
 
+	/* Set AEQ ctrl0. */
 
+	addr = HINIC3_CSR_AEQ_CTRL_0_ADDR;
 
+
 
+	val = hinic3_hwif_read_reg(hwif, addr);
 
+
 
+	val = AEQ_CTRL_0_CLEAR(val, INTR_IDX) &
 
+	      AEQ_CTRL_0_CLEAR(val, DMA_ATTR) &
 
+	      AEQ_CTRL_0_CLEAR(val, PCI_INTF_IDX) &
 
+	      AEQ_CTRL_0_CLEAR(val, INTR_MODE);
 
+
 
+	ctrl0 = AEQ_CTRL_0_SET(eq_irq->msix_entry_idx, INTR_IDX) |
 
+		AEQ_CTRL_0_SET(AEQ_DMA_ATTR_DEFAULT, DMA_ATTR) |
 
+		AEQ_CTRL_0_SET(pci_intf_idx, PCI_INTF_IDX) |
 
+		AEQ_CTRL_0_SET(HINIC3_INTR_MODE_ARMED, INTR_MODE);
 
+
 
+	val |= ctrl0;
 
+
 
+	hinic3_hwif_write_reg(hwif, addr, val);
 
+
 
+	/* Set AEQ ctrl1. */
 
+	addr = HINIC3_CSR_AEQ_CTRL_1_ADDR;
 
+
 
+	page_size_val = EQ_SET_HW_PAGE_SIZE_VAL(eq);
 
+	elem_size = EQ_SET_HW_ELEM_SIZE_VAL(eq);
 
+
 
+	ctrl1 = AEQ_CTRL_1_SET(eq->eq_len, LEN) |
 
+		AEQ_CTRL_1_SET(elem_size, ELEM_SIZE) |
 
+		AEQ_CTRL_1_SET(page_size_val, PAGE_SIZE);
 
+
 
+	hinic3_hwif_write_reg(hwif, addr, ctrl1);
 
+}
 
+
 
+/**
 
+ * Initialize all the elements in the aeq.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue.
 
+ * @param[in] init_val
 
+ * Value to init.
 
+ */
 
+static void
 
+aeq_elements_init(struct hinic3_eq *eq, u32 init_val)
 
+{
 
+	struct hinic3_aeq_elem *aeqe = NULL;
 
+	u32 i;
 
+
 
+	for (i = 0; i < eq->eq_len; i++) {
 
+		aeqe = GET_AEQ_ELEM(eq, i);
 
+		aeqe->desc = cpu_to_be32(init_val);
 
+	}
 
+
 
+	rte_atomic_thread_fence(rte_memory_order_release); /**< Write the init values. */
 
+}
 
+
 
+/**
 
+ * Set the pages for the event queue.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue.
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+set_eq_pages(struct hinic3_eq *eq)
 
+{
 
+	struct hinic3_hwif *hwif = eq->hwdev->hwif;
 
+	u32 reg, init_val;
 
+	u16 pg_num, i;
 
+	int err;
 
+
 
+	for (pg_num = 0; pg_num < eq->num_pages; pg_num++) {
 
+		/* Allocate memory for each page. */
 
+		eq->eq_mz[pg_num] = hinic3_dma_zone_reserve(eq->hwdev->eth_dev,
 
+			"eq_mz", eq->q_id, eq->page_size,
 
+			eq->page_size, SOCKET_ID_ANY);
 
+		if (!eq->eq_mz[pg_num]) {
 
+			err = -ENOMEM;
 
+			goto dma_alloc_err;
 
+		}
 
+
 
+		/* Write physical memory address and virtual memory address. */
 
+		eq->dma_addr[pg_num] = eq->eq_mz[pg_num]->iova;
 
+		eq->virt_addr[pg_num] = eq->eq_mz[pg_num]->addr;
 
+
 
+		reg = HINIC3_AEQ_HI_PHYS_ADDR_REG(pg_num);
 
+		hinic3_hwif_write_reg(hwif, reg,
 
+				      upper_32_bits(eq->dma_addr[pg_num]));
 
+
 
+		reg = HINIC3_AEQ_LO_PHYS_ADDR_REG(pg_num);
 
+		hinic3_hwif_write_reg(hwif, reg,
 
+				      lower_32_bits(eq->dma_addr[pg_num]));
 
+	}
 
+	/* Calculate the number of elements that can be accommodated. */
 
+	eq->num_elem_in_pg = GET_EQ_NUM_ELEMS(eq, eq->page_size);
 
+	if (eq->num_elem_in_pg & (eq->num_elem_in_pg - 1)) {
 
+		PMD_DRV_LOG(ERR, "Number element in eq page != power of 2");
 
+		err = -EINVAL;
 
+		goto dma_alloc_err;

drivers/net/hinic3/base/hinic3_eqs.c line 285

Quoted 10 lines
drivers/net/hinic3/base/hinic3_eqs.c +5 -0
 
+	}
 
+	init_val = EQ_WRAPPED(eq);
 
+
 
+	/* Initialize elements in the queue. */
 
+	aeq_elements_init(eq, init_val);

Suggest no blank line between define and usage.
And the init_val could obtain from eq, why we need to pass another paramter.

Quoted 206 lines
drivers/net/hinic3/base/hinic3_eqs.c +103 -0
+
 
+	return 0;
 
+
 
+dma_alloc_err:
 
+	for (i = 0; i < pg_num; i++)
 
+		hinic3_memzone_free(eq->eq_mz[i]);
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Allocate the pages for the event queue.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue.
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+alloc_eq_pages(struct hinic3_eq *eq)
 
+{
 
+	u64 dma_addr_size, virt_addr_size, eq_mz_size;
 
+	int err;
 
+
 
+	/* Calculate the size of the memory to be allocated. */
 
+	dma_addr_size = eq->num_pages * sizeof(*eq->dma_addr);
 
+	virt_addr_size = eq->num_pages * sizeof(*eq->virt_addr);
 
+	eq_mz_size = eq->num_pages * sizeof(*eq->eq_mz);
 
+
 
+	eq->dma_addr = rte_zmalloc("eq_dma", dma_addr_size,
 
+				   HINIC3_MEM_ALLOC_ALIGN_MIN);
 
+	if (!eq->dma_addr)
 
+		return -ENOMEM;
 
+
 
+	eq->virt_addr = rte_zmalloc("eq_va", virt_addr_size,
 
+				    HINIC3_MEM_ALLOC_ALIGN_MIN);
 
+	if (!eq->virt_addr) {
 
+		err = -ENOMEM;
 
+		goto virt_addr_alloc_err;
 
+	}
 
+
 
+	eq->eq_mz =
 
+		rte_zmalloc("eq_mz", eq_mz_size, HINIC3_MEM_ALLOC_ALIGN_MIN);
 
+	if (!eq->eq_mz) {
 
+		err = -ENOMEM;
 
+		goto eq_mz_alloc_err;
 
+	}
 
+	err = set_eq_pages(eq);
 
+	if (err != 0)
 
+		goto eq_pages_err;
 
+
 
+	return 0;
 
+
 
+eq_pages_err:
 
+	rte_free(eq->eq_mz);
 
+
 
+eq_mz_alloc_err:
 
+	rte_free(eq->virt_addr);
 
+
 
+virt_addr_alloc_err:
 
+	rte_free(eq->dma_addr);
 
+
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Free the pages of the event queue.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue.
 
+ */
 
+static void
 
+free_eq_pages(struct hinic3_eq *eq)
 
+{
 
+	u16 pg_num;
 
+
 
+	for (pg_num = 0; pg_num < eq->num_pages; pg_num++)
 
+		hinic3_memzone_free(eq->eq_mz[pg_num]);
 
+
 
+	rte_free(eq->eq_mz);
 
+	rte_free(eq->virt_addr);
 
+	rte_free(eq->dma_addr);
 
+}
 
+
 
+static u32
 
+get_page_size(struct hinic3_eq *eq)
 
+{
 
+	u32 total_size;
 
+	u16 count, n = 0;
 
+
 
+	/* Total memory size. */
 
+	total_size = RTE_ALIGN((eq->eq_len * eq->elem_size),
 
+			       HINIC3_MIN_EQ_PAGE_SIZE);
 
+	if (total_size <= (HINIC3_EQ_MAX_PAGES * HINIC3_MIN_EQ_PAGE_SIZE))
 
+		return HINIC3_MIN_EQ_PAGE_SIZE;
 
+	/* Total number of pages. */
 
+	count = (u16)(RTE_ALIGN((total_size / HINIC3_EQ_MAX_PAGES),
 
+				HINIC3_MIN_EQ_PAGE_SIZE) /
 
+		      HINIC3_MIN_EQ_PAGE_SIZE);
 
+
 
+	/* Whether count is a power of 2. */
 
+	if (!(count & (count - 1)))
 
+		return HINIC3_MIN_EQ_PAGE_SIZE * count;

drivers/net/hinic3/base/hinic3_eqs.c line 393

Quoted 10 lines
drivers/net/hinic3/base/hinic3_eqs.c +5 -0
 
+
 
+	while (count) {
 
+		count >>= 1;
 
+		n++;
 
+	}

could use rte_ctz32() API

Quoted 865 lines
drivers/net/hinic3/base/hinic3_eqs.c +328 -0
+
 
+	return ((u32)HINIC3_MIN_EQ_PAGE_SIZE) << n;
 
+}
 
+
 
+/**
 
+ * Initialize AEQ.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue.
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device.
 
+ * @param[in] q_id
 
+ * Queue id number.
 
+ * @param[in] q_len
 
+ * The number of EQ elements.
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+static int
 
+init_aeq(struct hinic3_eq *eq, struct hinic3_hwdev *hwdev, u16 q_id, u32 q_len)
 
+{
 
+	int err = 0;
 
+
 
+	eq->hwdev = hwdev;
 
+	eq->q_id = q_id;
 
+	eq->eq_len = q_len;
 
+
 
+	/* Indirect access should set q_id first. */
 
+	hinic3_hwif_write_reg(hwdev->hwif, HINIC3_AEQ_INDIR_IDX_ADDR, eq->q_id);
 
+	rte_atomic_thread_fence(rte_memory_order_release); /**< write index before config. */
 
+
 
+	/* Clear eq_len to force eqe drop in hardware. */
 
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_CSR_AEQ_CTRL_1_ADDR, 0);
 
+	rte_atomic_thread_fence(rte_memory_order_release);
 
+	/* Init aeq pi to 0 before allocating aeq pages. */
 
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_CSR_AEQ_PROD_IDX_ADDR, 0);
 
+
 
+	eq->cons_idx = 0;
 
+	eq->wrapped = 0;
 
+
 
+	eq->elem_size = HINIC3_AEQE_SIZE;
 
+	eq->page_size = get_page_size(eq);
 
+	eq->orig_page_size = eq->page_size;
 
+	eq->num_pages = GET_EQ_NUM_PAGES(eq, eq->page_size);
 
+	if (eq->num_pages > HINIC3_EQ_MAX_PAGES) {
 
+		PMD_DRV_LOG(ERR, "Too many pages: %d for aeq", eq->num_pages);
 
+		return -EINVAL;
 
+	}
 
+
 
+	err = alloc_eq_pages(eq);
 
+	if (err) {
 
+		PMD_DRV_LOG(ERR, "Allocate pages for eq failed");
 
+		return err;
 
+	}
 
+
 
+	/* Pmd driver uses AEQ_MSIX_ENTRY_IDX_0. */
 
+	eq->eq_irq.msix_entry_idx = AEQ_MSIX_ENTRY_IDX_0;
 
+	set_aeq_ctrls(eq);
 
+
 
+	set_eq_cons_idx(eq, HINIC3_EQ_ARMED);
 
+
 
+	if (eq->q_id == 0)
 
+		hinic3_set_msix_state(hwdev, 0, HINIC3_MSIX_ENABLE);
 
+
 
+	eq->poll_retry_nr = HINIC3_RETRY_NUM;
 
+
 
+	return 0;
 
+}
 
+
 
+/**
 
+ * Remove AEQ.
 
+ *
 
+ * @param[in] eq
 
+ * The event queue.
 
+ */
 
+static void
 
+remove_aeq(struct hinic3_eq *eq)
 
+{
 
+	struct irq_info *entry = &eq->eq_irq;
 
+
 
+	if (eq->q_id == 0)
 
+		hinic3_set_msix_state(eq->hwdev, entry->msix_entry_idx,
 
+				      HINIC3_MSIX_DISABLE);
 
+
 
+	/* Indirect access should set q_id first. */
 
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_AEQ_INDIR_IDX_ADDR,
 
+			      eq->q_id);
 
+
 
+	rte_atomic_thread_fence(rte_memory_order_release); /**< Write index before config. */
 
+
 
+	/* Clear eq_len to avoid hw access host memory. */
 
+	hinic3_hwif_write_reg(eq->hwdev->hwif, HINIC3_CSR_AEQ_CTRL_1_ADDR, 0);
 
+
 
+	/* Update cons_idx to avoid invalid interrupt. */
 
+	eq->cons_idx = hinic3_hwif_read_reg(eq->hwdev->hwif,
 
+					    HINIC3_CSR_AEQ_PROD_IDX_ADDR);
 
+	set_eq_cons_idx(eq, HINIC3_EQ_NOT_ARMED);
 
+
 
+	free_eq_pages(eq);
 
+}
 
+
 
+/**
 
+ * Init all AEQs.
 
+ *
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device object
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+int
 
+hinic3_aeqs_init(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct hinic3_aeqs *aeqs = NULL;
 
+	u16 num_aeqs;
 
+	int err;
 
+	u16 i, q_id;
 
+
 
+	if (!hwdev)
 
+		return -EINVAL;
 
+
 
+	num_aeqs = HINIC3_HWIF_NUM_AEQS(hwdev->hwif);
 
+	if (num_aeqs > HINIC3_MAX_AEQS) {
 
+		PMD_DRV_LOG(INFO, "Adjust aeq num to %d", HINIC3_MAX_AEQS);
 
+		num_aeqs = HINIC3_MAX_AEQS;
 
+	} else if (num_aeqs < HINIC3_MIN_AEQS) {
 
+		PMD_DRV_LOG(ERR, "PMD needs %d AEQs, Chip has %d",
 
+			    HINIC3_MIN_AEQS, num_aeqs);
 
+		return -EINVAL;
 
+	}
 
+
 
+	aeqs = rte_zmalloc("hinic3_aeqs", sizeof(*aeqs),
 
+			   HINIC3_MEM_ALLOC_ALIGN_MIN);
 
+	if (!aeqs)
 
+		return -ENOMEM;
 
+
 
+	hwdev->aeqs = aeqs;
 
+	aeqs->hwdev = hwdev;
 
+	aeqs->num_aeqs = num_aeqs;
 
+
 
+	for (q_id = 0; q_id < num_aeqs; q_id++) {
 
+		err = init_aeq(&aeqs->aeq[q_id], hwdev, q_id,
 
+			       HINIC3_DEFAULT_AEQ_LEN);
 
+		if (err) {
 
+			PMD_DRV_LOG(ERR, "Init aeq %d failed", q_id);
 
+			goto init_aeq_err;
 
+		}
 
+	}
 
+
 
+	return 0;
 
+
 
+init_aeq_err:
 
+	for (i = 0; i < q_id; i++)
 
+		remove_aeq(&aeqs->aeq[i]);
 
+
 
+	rte_free(aeqs);
 
+	return err;
 
+}
 
+
 
+/**
 
+ * Free all AEQs.
 
+ *
 
+ * @param[in] hwdev
 
+ * The pointer to the private hardware device.
 
+ */
 
+void
 
+hinic3_aeqs_free(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct hinic3_aeqs *aeqs = hwdev->aeqs;
 
+	u16 q_id;
 
+
 
+	for (q_id = 0; q_id < aeqs->num_aeqs; q_id++)
 
+		remove_aeq(&aeqs->aeq[q_id]);
 
+
 
+	rte_free(aeqs);
 
+}
 
+
 
+void
 
+hinic3_dump_aeq_info(struct hinic3_hwdev *hwdev)
 
+{
 
+	struct hinic3_aeq_elem *aeqe_pos = NULL;
 
+	struct hinic3_eq *eq = NULL;
 
+	u32 addr, ci, pi, ctrl0, idx;
 
+	int q_id;
 
+
 
+	for (q_id = 0; q_id < hwdev->aeqs->num_aeqs; q_id++) {
 
+		eq = &hwdev->aeqs->aeq[q_id];
 
+		/* Indirect access should set q_id first. */
 
+		hinic3_hwif_write_reg(eq->hwdev->hwif,
 
+				      HINIC3_AEQ_INDIR_IDX_ADDR, eq->q_id);
 
+		/* Write index before config. */
 
+		rte_atomic_thread_fence(rte_memory_order_release);
 
+
 
+		addr = HINIC3_CSR_AEQ_CTRL_0_ADDR;
 
+
 
+		ctrl0 = hinic3_hwif_read_reg(hwdev->hwif, addr);
 
+
 
+		idx = hinic3_hwif_read_reg(hwdev->hwif,
 
+					   HINIC3_AEQ_INDIR_IDX_ADDR);
 
+
 
+		addr = HINIC3_CSR_AEQ_CONS_IDX_ADDR;
 
+		ci = hinic3_hwif_read_reg(hwdev->hwif, addr);
 
+		addr = HINIC3_CSR_AEQ_PROD_IDX_ADDR;
 
+		pi = hinic3_hwif_read_reg(hwdev->hwif, addr);
 
+		aeqe_pos = GET_AEQ_ELEM(eq, eq->cons_idx);
 
+		PMD_DRV_LOG(ERR,
 
+			    "Aeq id: %d, idx: %u, ctrl0: 0x%08x, wrap: %d,"
 
+			    " pi: 0x%x, ci: 0x%08x,  desc: 0x%x",
 
+			    q_id, idx, ctrl0, eq->wrapped, pi, ci,
 
+			    be32_to_cpu(aeqe_pos->desc));
 
+	}
 
+}
 
+
 
+static int
 
+aeq_elem_handler(struct hinic3_eq *eq, u32 aeqe_desc,
 
+		 struct hinic3_aeq_elem *aeqe_pos, void *param)
 
+{
 
+	enum hinic3_aeq_type event;
 
+	u8 data[HINIC3_AEQE_DATA_SIZE];
 
+	u8 size;
 
+
 
+	event = EQ_ELEM_DESC_GET(aeqe_desc, TYPE);
 
+	if (EQ_ELEM_DESC_GET(aeqe_desc, SRC)) {
 
+		/* SW event uses only the first 8B. */
 
+		memcpy(data, aeqe_pos->aeqe_data, HINIC3_AEQE_DATA_SIZE);
 
+		hinic3_be32_to_cpu(data, HINIC3_AEQE_DATA_SIZE);
 
+		/* Just support HINIC3_STATELESS_EVENT. */
 
+		return hinic3_nic_sw_aeqe_handler(eq->hwdev, event, data);
 
+	}
 
+
 
+	memcpy(data, aeqe_pos->aeqe_data, HINIC3_AEQE_DATA_SIZE);
 
+	hinic3_be32_to_cpu(data, HINIC3_AEQE_DATA_SIZE);
 
+	size = EQ_ELEM_DESC_GET(aeqe_desc, SIZE);
 
+
 
+	if (event == HINIC3_MSG_FROM_MGMT_CPU) {
 
+		return hinic3_mgmt_msg_aeqe_handler(eq->hwdev, data, size,
 
+						    param);
 
+	} else if (event == HINIC3_MBX_FROM_FUNC) {
 
+		return hinic3_mbox_func_aeqe_handler(eq->hwdev, data, size,
 
+						     param);
 
+	} else {
 
+		PMD_DRV_LOG(ERR, "AEQ hw event not support %d", event);
 
+		return -EINVAL;
 
+	}
 
+}
 
+
 
+/**
 
+ * Poll one or continue aeqe, and call dedicated process.
 
+ *
 
+ * @param[in] eq
 
+ * Pointer to the event queue.
 
+ * @param[in] timeout
 
+ * equal to 0 - Poll all aeqe in eq, used in interrupt mode.
 
+ * Greater than 0 - Poll aeq until get aeqe with 'last' field set to 1, used in
 
+ * polling mode.
 
+ * @param[in] param
 
+ * Customized parameter.
 
+ * @return
 
+ * 0 on success, non-zero on failure.
 
+ */
 
+int
 
+hinic3_aeq_poll_msg(struct hinic3_eq *eq, u32 timeout, void *param)
 
+{
 
+	struct hinic3_aeq_elem *aeqe_pos = NULL;
 
+	u32 aeqe_desc = 0;
 
+	u32 eqe_cnt = 0;
 
+	int err = -EFAULT;
 
+	int done = HINIC3_MSG_HANDLER_RES;
 
+	unsigned long end;
 
+	u16 i;
 
+
 
+	for (i = 0; ((timeout == 0) && (i < eq->eq_len)) ||
 
+		    ((timeout > 0) && (done != 0) && (i < eq->eq_len));
 
+	     i++) {
 
+		err = -EIO;
 
+		end = jiffies + msecs_to_jiffies(timeout);
 
+		do {
 
+			aeqe_pos = GET_AEQ_ELEM(eq, eq->cons_idx);
 
+
 
+			/* Data in HW is in Big endian format. */
 
+			aeqe_desc = be32_to_cpu(aeqe_pos->desc);
 
+
 
+			/*
 
+			 * HW updates wrapped bit, when it adds eq element
 
+			 * event.
 
+			 */
 
+			if (EQ_ELEM_DESC_GET(aeqe_desc, WRAPPED) !=
 
+			    eq->wrapped) {
 
+				err = 0;
 
+				rte_atomic_thread_fence(rte_memory_order_acquire);
 
+				break;
 
+			}
 
+
 
+			if (timeout != 0)
 
+				usleep(HINIC3_AEQE_DESC_SIZE);
 
+		} while (time_before(jiffies, end));
 
+
 
+		if (err != 0) /**< Poll time out. */
 
+			break;
 
+		/* Handle the middle element of the event queue. */
 
+		done = aeq_elem_handler(eq, aeqe_desc, aeqe_pos, param);
 
+
 
+		eq->cons_idx++;
 
+		if (eq->cons_idx == eq->eq_len) {
 
+			eq->cons_idx = 0;
 
+			eq->wrapped = !eq->wrapped;
 
+		}
 
+
 
+		if (++eqe_cnt >= HINIC3_EQ_UPDATE_CI_STEP) {
 
+			eqe_cnt = 0;
 
+			set_eq_cons_idx(eq, HINIC3_EQ_NOT_ARMED);
 
+		}
 
+	}
 
+	/* Set the consumer index of the event queue. */
 
+	set_eq_cons_idx(eq, HINIC3_EQ_ARMED);
 
+
 
+	return err;
 
+}
 
+
 
+void
 
+hinic3_dev_handle_aeq_event(struct hinic3_hwdev *hwdev, void *param)
 
+{
 
+	struct hinic3_eq *aeq = &hwdev->aeqs->aeq[0];
 
+
 
+	/* Clear resend timer cnt register. */
 
+	hinic3_misx_intr_clear_resend_bit(hwdev, aeq->eq_irq.msix_entry_idx,
 
+					  MSIX_RESEND_TIMER_CLEAR);
 
+	hinic3_aeq_poll_msg(aeq, 0, param);
 
+}
drivers/net/hinic3/base/hinic3_eqs.h +0 -0

new file mode 100644

index 0000000000..7617ed9589

--- /dev/null

+++ b/drivers/net/hinic3/base/hinic3_eqs.h

drivers/net/hinic3/base/hinic3_eqs.h +98 -0
@@ -0,0 +1,98 @@
 
+/* SPDX-License-Identifier: BSD-3-Clause
 
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
 
+ */
 
+
 
+#ifndef _HINIC3_EQS_H_
 
+#define _HINIC3_EQS_H_
 
+
 
+#define HINIC3_MAX_AEQS	    4
 
+#define HINIC3_MIN_AEQS	    2
 
+#define HINIC3_EQ_MAX_PAGES 4
 
+
 
+#define HINIC3_AEQE_SIZE 64
 
+
 
+#define HINIC3_AEQE_DESC_SIZE 4
 
+#define HINIC3_AEQE_DATA_SIZE (HINIC3_AEQE_SIZE - HINIC3_AEQE_DESC_SIZE)
 
+
 
+/* Linux is 1K, dpdk is 64. */
 
+#define HINIC3_DEFAULT_AEQ_LEN 64
 
+
 
+#define HINIC3_MIN_EQ_PAGE_SIZE 0x1000	 /**< Min eq page size 1K Bytes. */
 
+#define HINIC3_MAX_EQ_PAGE_SIZE 0x400000 /**< Max eq page size 4M Bytes */
 
+
 
+#define HINIC3_MIN_AEQ_LEN 64
 
+#define HINIC3_MAX_AEQ_LEN \
 
+	((HINIC3_MAX_EQ_PAGE_SIZE / HINIC3_AEQE_SIZE) * HINIC3_EQ_MAX_PAGES)
 
+
 
+#define EQ_IRQ_NAME_LEN 64
 
+
 
+enum hinic3_eq_intr_mode { HINIC3_INTR_MODE_ARMED, HINIC3_INTR_MODE_ALWAYS };
 
+
 
+enum hinic3_eq_ci_arm_state { HINIC3_EQ_NOT_ARMED, HINIC3_EQ_ARMED };
 
+
 
+/* Structure for interrupt request information. */
 
+struct irq_info {
 
+	u16 msix_entry_idx; /**< IRQ corresponding index number. */
 
+	u32 irq_id;	    /**< The IRQ number from OS. */
 
+};
 
+
 
+#define HINIC3_RETRY_NUM 10
 
+
 
+enum hinic3_aeq_type {
 
+	HINIC3_HW_INTER_INT = 0,
 
+	HINIC3_MBX_FROM_FUNC = 1,
 
+	HINIC3_MSG_FROM_MGMT_CPU = 2,
 
+	HINIC3_API_RSP = 3,
 
+	HINIC3_API_CHAIN_STS = 4,
 
+	HINIC3_MBX_SEND_RSLT = 5,
 
+	HINIC3_MAX_AEQ_EVENTS
 
+};
 
+
 
+/* Structure for EQ(Event Queue) information. */
 
+struct hinic3_eq {
 
+	struct hinic3_hwdev *hwdev;
 
+	u16 q_id;
 
+	u32 page_size;
 
+	u32 orig_page_size;
 
+	u32 eq_len;
 
+
 
+	u32 cons_idx;
 
+	u16 wrapped;
 
+
 
+	u16 elem_size;
 
+	u16 num_pages;
 
+	u32 num_elem_in_pg;
 
+
 
+	struct irq_info eq_irq;
 
+
 
+	const struct rte_memzone **eq_mz;
 
+	rte_iova_t *dma_addr;
 
+	u8 **virt_addr;
 
+
 
+	u16 poll_retry_nr;
 
+};
 
+
 
+struct hinic3_aeq_elem {
 
+	u8 aeqe_data[HINIC3_AEQE_DATA_SIZE];
 
+	u32 desc;
 
+};
 
+
 
+/* Structure for AEQs(Asynchronous Event Queues) information. */
 
+struct hinic3_aeqs {
 
+	struct hinic3_hwdev *hwdev;
 
+
 
+	struct hinic3_eq aeq[HINIC3_MAX_AEQS];
 
+	u16 num_aeqs;
 
+};
 
+
 
+int hinic3_aeqs_init(struct hinic3_hwdev *hwdev);
 
+
 
+void hinic3_aeqs_free(struct hinic3_hwdev *hwdev);
 
+
 
+void hinic3_dump_aeq_info(struct hinic3_hwdev *hwdev);
 
+
 
+int hinic3_aeq_poll_msg(struct hinic3_eq *eq, u32 timeout, void *param);
 
+
 
+void hinic3_dev_handle_aeq_event(struct hinic3_hwdev *hwdev, void *param);
 
+
 
+#endif /**< _HINIC3_EQS_H_ */
#139 lore raw

PATCH v5 7/18 net/hinic3: add mgmt module function code

In reply to Feifei Wang

From: Yi Chen <[email protected]>

Mgmt module is a kind of administration module for the chip. It is responsible for handling administration command from host. It mainly uses aeq to implement. This patch adds related data structures, packaged interfaces and function codes.

---
 drivers/net/hinic3/base/hinic3_mgmt.c | 392 ++++++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_mgmt.h | 121 ++++++++
 2 files changed, 513 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.c
 create mode 100644 drivers/net/hinic3/base/hinic3_mgmt.h
drivers/net/hinic3/base/hinic3_mgmt.c new file +392 -0
new file mode 100644
index 0000000000..dfed1229e4
@@ -0,0 +1,392 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+#include <rte_ethdev.h>
+
+#include "hinic3_compat.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_mbox.h"
+#include "hinic3_mgmt.h"
+#include "hinic3_nic_event.h"
+
+#define HINIC3_MSG_TO_MGMT_MAX_LEN 2016
+
+#define MAX_PF_MGMT_BUF_SIZE 2048UL
+#define SEGMENT_LEN	     48
+#define ASYNC_MSG_FLAG	     0x20
+#define MGMT_MSG_MAX_SEQ_ID \
+	(RTE_ALIGN(HINIC3_MSG_TO_MGMT_MAX_LEN, SEGMENT_LEN) / SEGMENT_LEN)
+
+#define BUF_OUT_DEFAULT_SIZE 1
+
+#define MGMT_MSG_SIZE_MIN     20
+#define MGMT_MSG_SIZE_STEP    16
+#define MGMT_MSG_RSVD_FOR_DEV 8
+
+#define SYNC_MSG_ID_MASK  0x1F
+#define ASYNC_MSG_ID_MASK 0x1F
+
+#define SYNC_FLAG  0
+#define ASYNC_FLAG 1
+
+#define MSG_NO_RESP 0xFFFF
+
+#define MGMT_MSG_TIMEOUT 5000 /**< Millisecond. */
+
+int
+hinic3_msg_to_mgmt_sync(void *hwdev, enum hinic3_mod_type mod, u16 cmd,
+			void *buf_in, u16 in_size, void *buf_out, u16 *out_size,
+			u32 timeout)
+{
+	int err;
+
+	if (!hwdev)
+		return -EINVAL;
+
+	/* Send a mailbox message to the management. */
+	err = hinic3_send_mbox_to_mgmt(hwdev, mod, cmd, buf_in, in_size,
+				       buf_out, out_size, timeout);
+	return err;
+}
+
+int
+hinic3_msg_to_mgmt_no_ack(void *hwdev, enum hinic3_mod_type mod, u16 cmd,
+			  void *buf_in, u16 in_size)
+{
+	if (!hwdev)
+		return -EINVAL;
+
+	return hinic3_send_mbox_to_mgmt_no_ack(hwdev, mod, cmd, buf_in,
+					       in_size);
+}
+
+static void
+send_mgmt_ack(struct hinic3_msg_pf_to_mgmt *pf_to_mgmt,
+	      enum hinic3_mod_type mod, u16 cmd, void *buf_in, u16 in_size,
+	      u16 msg_id)
+{
+	u16 buf_size;
+
+	if (!in_size)
+		buf_size = BUF_OUT_DEFAULT_SIZE;
+	else
+		buf_size = in_size;
+
+	hinic3_response_mbox_to_mgmt(pf_to_mgmt->hwdev, mod, cmd, buf_in,
+				     buf_size, msg_id);
+}
+
+static bool
+check_mgmt_seq_id_and_seg_len(struct hinic3_recv_msg *recv_msg, u8 seq_id,
+			      u8 seg_len, u16 msg_id)
+{
+	if (seq_id > MGMT_MSG_MAX_SEQ_ID || seg_len > SEGMENT_LEN)
+		return false;
+
+	if (seq_id == 0) {
+		recv_msg->seq_id = seq_id;
+		recv_msg->msg_id = msg_id;
+	} else {
+		if ((seq_id != recv_msg->seq_id + 1) ||
+		    msg_id != recv_msg->msg_id) {
+			recv_msg->seq_id = 0;
+			return false;
+		}
+
+		recv_msg->seq_id = seq_id;
+	}
+
+	return true;
+}
+
+static void
+hinic3_mgmt_recv_msg_handler(struct hinic3_msg_pf_to_mgmt *pf_to_mgmt,
+			     struct hinic3_recv_msg *recv_msg,
+			     __rte_unused void *param)
+{
+	void *buf_out = pf_to_mgmt->mgmt_ack_buf;
+	bool ack_first = false;
+	u16 out_size = 0;
+
+	memset(buf_out, 0, MAX_PF_MGMT_BUF_SIZE);
+
+	/* Select the corresponding processing function according to the mod. */
+	switch (recv_msg->mod) {
+	case HINIC3_MOD_COMM:
+		pf_handle_mgmt_comm_event(pf_to_mgmt->hwdev,
+			pf_to_mgmt, recv_msg->cmd,
+			recv_msg->msg, recv_msg->msg_len, buf_out, &out_size);
+		break;
+	case HINIC3_MOD_L2NIC:
+		hinic3_pf_event_handler(pf_to_mgmt->hwdev, pf_to_mgmt,
+					recv_msg->cmd, recv_msg->msg,
+					recv_msg->msg_len, buf_out, &out_size);
+		break;
+	case HINIC3_MOD_HILINK:
+		hinic3_pf_mag_event_handler(pf_to_mgmt->hwdev,
+			pf_to_mgmt, recv_msg->cmd,
+			recv_msg->msg, recv_msg->msg_len, buf_out, &out_size);
+		break;
+
+	default:
+		PMD_DRV_LOG(ERR,
+			    "Not support mod, maybe need to response, mod: %d",
+			    recv_msg->mod);
+		break;
+	}
+
+	if (!ack_first && !recv_msg->async_mgmt_to_pf)
+		/* Mgmt sends async msg, sends the response. */
+		send_mgmt_ack(pf_to_mgmt, recv_msg->mod, recv_msg->cmd, buf_out,
+			      out_size, recv_msg->msg_id);
+}
+
+/**
+ * Handler a recv message from mgmt channel.
+ *
+ * @param[in] pf_to_mgmt
+ * PF to mgmt channel.
+ * @param[in] recv_msg
+ * Received message details.
+ * @param[in] param
+ * Customized parameter.
+ * @return
+ * 0 : When aeqe is response message.
+ * -1 : Default result, when wrong message or not last message.
+ */
+static int
+recv_mgmt_msg_handler(struct hinic3_msg_pf_to_mgmt *pf_to_mgmt, u8 *header,
+		      struct hinic3_recv_msg *recv_msg, void *param)
+{
+	u64 mbox_header = *((u64 *)header);
+	void *msg_body = header + sizeof(mbox_header);
+	u8 seq_id, seq_len;
+	u32 offset;
+	u8 front_id;
+	u16 msg_id;
+
+	/* Don't need to get anything from hw when cmd is async. */
+	if (HINIC3_MSG_HEADER_GET(mbox_header, DIRECTION) ==
+	    HINIC3_MSG_RESPONSE)
+		return 0;
+
+	seq_len = HINIC3_MSG_HEADER_GET(mbox_header, SEG_LEN);
+	seq_id = HINIC3_MSG_HEADER_GET(mbox_header, SEQID);
+	msg_id = HINIC3_MSG_HEADER_GET(mbox_header, MSG_ID);
+	front_id = recv_msg->seq_id;
+
+	/* Check the consistency between seq_id and seg_len. */
+	if (!check_mgmt_seq_id_and_seg_len(recv_msg, seq_id, seq_len, msg_id)) {
+		PMD_DRV_LOG(ERR,
+			    "Mgmt msg sequence id and segment length check "
+			    "failed, front seq_id: 0x%x, current seq_id: 0x%x,"
+			    " seg len: 0x%x front msg_id: %d, cur msg_id: %d",
+			    front_id, seq_id, seq_len, recv_msg->msg_id,
+			    msg_id);
+		/* Set seq_id to invalid seq_id. */
+		recv_msg->seq_id = MGMT_MSG_MAX_SEQ_ID;
+		return HINIC3_MSG_HANDLER_RES;
+	}
+
+	offset = seq_id * SEGMENT_LEN;
+	memcpy((u8 *)recv_msg->msg + offset, msg_body, seq_len);
+
+	if (!HINIC3_MSG_HEADER_GET(mbox_header, LAST))
+		return HINIC3_MSG_HANDLER_RES;
+	/* Setting the message receiving information. */
+	recv_msg->cmd = HINIC3_MSG_HEADER_GET(mbox_header, CMD);
+	recv_msg->mod = HINIC3_MSG_HEADER_GET(mbox_header, MODULE);
+	recv_msg->async_mgmt_to_pf = HINIC3_MSG_HEADER_GET(mbox_header, NO_ACK);
+	recv_msg->msg_len = HINIC3_MSG_HEADER_GET(mbox_header, MSG_LEN);
+	recv_msg->msg_id = HINIC3_MSG_HEADER_GET(mbox_header, MSG_ID);
+	recv_msg->seq_id = MGMT_MSG_MAX_SEQ_ID;
+
+	hinic3_mgmt_recv_msg_handler(pf_to_mgmt, recv_msg, param);
+
+	return HINIC3_MSG_HANDLER_RES;
+}
+
+/**
+ * Handler for a aeqe from mgmt channel.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device.
+ * @param[in] header
+ * The header of the message.
+ * @param[in] size
+ * Indicate size.
+ * @param[in] param
+ * Customized parameter.
+ * @return
+ * zero: When aeqe is response message
+ * negative: When wrong message or not last message.
+ */
+int
+hinic3_mgmt_msg_aeqe_handler(void *hwdev, u8 *header, u8 size, void *param)
+{
+	struct hinic3_hwdev *dev = (struct hinic3_hwdev *)hwdev;
+	struct hinic3_msg_pf_to_mgmt *pf_to_mgmt = NULL;
+	struct hinic3_recv_msg *recv_msg = NULL;
+	bool is_send_dir = false;
+
+	/* For mbox message, invoke the mailbox processing function. */
+	if ((HINIC3_MSG_HEADER_GET(*(u64 *)header, SOURCE) ==
+	     HINIC3_MSG_FROM_MBOX)) {
+		return hinic3_mbox_func_aeqe_handler(hwdev, header, size,
+						     param);
+	}
+
+	pf_to_mgmt = dev->pf_to_mgmt;
+
+	is_send_dir = (HINIC3_MSG_HEADER_GET(*(u64 *)header, DIRECTION) ==
+		       HINIC3_MSG_DIRECT_SEND) ? true : false;
+
+	/* Determine whether a message is received or responded. */
+	recv_msg = is_send_dir ? &pf_to_mgmt->recv_msg_from_mgmt
+			       : &pf_to_mgmt->recv_resp_msg_from_mgmt;
+
+	return recv_mgmt_msg_handler(pf_to_mgmt, header, recv_msg, param);
+}
+
+/**
+ * Allocate received message memory.
+ *
+ * @param[in] recv_msg
+ * Pointer that will hold the allocated data.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+alloc_recv_msg(struct hinic3_recv_msg *recv_msg)
+{
+	recv_msg->seq_id = MGMT_MSG_MAX_SEQ_ID;
+
+	recv_msg->msg = rte_zmalloc("recv_msg", MAX_PF_MGMT_BUF_SIZE,
+				    HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!recv_msg->msg)
+		return -ENOMEM;
+
+	return 0;
+}
+
+static void
+free_recv_msg(struct hinic3_recv_msg *recv_msg)
+{
+	rte_free(recv_msg->msg);
+}
+
+/**
+ * Allocate all the message buffers of PF to mgmt channel.
+ *
+ * @param[in] pf_to_mgmt
+ * PF to mgmt channel.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+static int
+alloc_msg_buf(struct hinic3_msg_pf_to_mgmt *pf_to_mgmt)
+{
+	int err;
+
+	err = alloc_recv_msg(&pf_to_mgmt->recv_msg_from_mgmt);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Allocate recv msg failed");
+		return err;
+	}
+
+	err = alloc_recv_msg(&pf_to_mgmt->recv_resp_msg_from_mgmt);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Allocate resp recv msg failed");
+		goto alloc_msg_for_resp_err;
+	}
+
+	pf_to_mgmt->mgmt_ack_buf = rte_zmalloc("mgmt_ack_buf",
+					       MAX_PF_MGMT_BUF_SIZE,
+					       HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!pf_to_mgmt->mgmt_ack_buf) {
+		err = -ENOMEM;
+		goto ack_msg_buf_err;
+	}
+
+	return 0;
+
+ack_msg_buf_err:
+	free_recv_msg(&pf_to_mgmt->recv_resp_msg_from_mgmt);
+
+alloc_msg_for_resp_err:
+	free_recv_msg(&pf_to_mgmt->recv_msg_from_mgmt);
+	return err;
+}
+
+/**
+ * Free all the message buffers of PF to mgmt channel.
+ *
+ * @param[in] pf_to_mgmt
+ * PF to mgmt channel.
+ */
+static void
+free_msg_buf(struct hinic3_msg_pf_to_mgmt *pf_to_mgmt)
+{
+	rte_free(pf_to_mgmt->mgmt_ack_buf);
+	free_recv_msg(&pf_to_mgmt->recv_resp_msg_from_mgmt);
+	free_recv_msg(&pf_to_mgmt->recv_msg_from_mgmt);
+}
+
+/**
+ * Initialize PF to mgmt channel.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device.
+ * @return
+ * 0 on success, non-zero on failure.
+ */
+int
+hinic3_pf_to_mgmt_init(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_msg_pf_to_mgmt *pf_to_mgmt;
+	int err;
+
+	pf_to_mgmt = rte_zmalloc("pf_to_mgmt", sizeof(*pf_to_mgmt),
+				 HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!pf_to_mgmt)
+		return -ENOMEM;
+
+	hwdev->pf_to_mgmt = pf_to_mgmt;
+	pf_to_mgmt->hwdev = hwdev;
+
+	err = hinic3_mutex_init(&pf_to_mgmt->sync_msg_mutex, NULL);
+	if (err)
+		goto mutex_init_err;
+
+	err = alloc_msg_buf(pf_to_mgmt);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Allocate msg buffers failed");
+		goto alloc_msg_buf_err;
+	}
+
+	return 0;
+
+alloc_msg_buf_err:
+	hinic3_mutex_destroy(&pf_to_mgmt->sync_msg_mutex);
+
+mutex_init_err:
+	rte_free(pf_to_mgmt);
+
+	return err;
+}
+
+/**
+ * Free PF to mgmt channel.
+ *
+ * @param[in] hwdev
+ * The pointer to the private hardware device.
+ */
+void
+hinic3_pf_to_mgmt_free(struct hinic3_hwdev *hwdev)
+{
+	struct hinic3_msg_pf_to_mgmt *pf_to_mgmt = hwdev->pf_to_mgmt;
+
+	free_msg_buf(pf_to_mgmt);
+	hinic3_mutex_destroy(&pf_to_mgmt->sync_msg_mutex);
+	rte_free(pf_to_mgmt);
+}
drivers/net/hinic3/base/hinic3_mgmt.h new file +121 -0

121 lines not on this page · raw message

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

PATCH v5 8/18 net/hinic3: add module about hardware operation

In reply to Feifei Wang

From: Yi Chen <[email protected]>

Add code and data structure for hardware operation, including configuration, query, initialization and release.

---
 drivers/net/hinic3/base/hinic3_hw_cfg.c  | 240 ++++++++++
 drivers/net/hinic3/base/hinic3_hw_cfg.h  | 121 +++++
 drivers/net/hinic3/base/hinic3_hw_comm.c | 452 ++++++++++++++++++
 drivers/net/hinic3/base/hinic3_hw_comm.h | 366 +++++++++++++++
 drivers/net/hinic3/base/hinic3_hwdev.c   | 573 +++++++++++++++++++++++
 drivers/net/hinic3/base/hinic3_hwdev.h   | 177 +++++++
 6 files changed, 1929 insertions(+)
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_cfg.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hw_comm.h
 create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.c
 create mode 100644 drivers/net/hinic3/base/hinic3_hwdev.h
drivers/net/hinic3/base/hinic3_hw_cfg.c new file +240 -0
new file mode 100644
index 0000000000..ebe746a9ae
@@ -0,0 +1,240 @@
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2025 Huawei Technologies Co., Ltd
+ */
+
+#include "hinic3_compat.h"
+#include "hinic3_mbox.h"
+#include "hinic3_mgmt.h"
+#include "hinic3_hw_cfg.h"
+#include "hinic3_hwdev.h"
+#include "hinic3_hwif.h"
+
+static void
+parse_pub_res_cap(struct service_cap *cap,
+		  struct hinic3_cfg_cmd_dev_cap *dev_cap, enum func_type type)
+{
+	cap->host_id = dev_cap->host_id;
+	cap->ep_id = dev_cap->ep_id;
+	cap->er_id = dev_cap->er_id;
+	cap->port_id = dev_cap->port_id;
+
+	cap->svc_type = dev_cap->svc_cap_en;
+	cap->chip_svc_type = cap->svc_type;
+
+	cap->cos_valid_bitmap = dev_cap->valid_cos_bitmap;
+	cap->flexq_en = dev_cap->flexq_en;
+
+	cap->host_total_function = dev_cap->host_total_func;
+	cap->max_vf = 0;
+	if (type == TYPE_PF || type == TYPE_PPF) {
+		cap->max_vf = dev_cap->max_vf;
+		cap->pf_num = dev_cap->host_pf_num;
+		cap->pf_id_start = dev_cap->pf_id_start;
+		cap->vf_num = dev_cap->host_vf_num;
+		cap->vf_id_start = dev_cap->vf_id_start;
+	}
+
+	PMD_DRV_LOG(INFO, "Get public resource capability: ");
+	PMD_DRV_LOG(INFO,
+		    "host_id: 0x%x, ep_id: 0x%x, er_id: 0x%x, port_id: 0x%x",
+		    cap->host_id, cap->ep_id, cap->er_id, cap->port_id);
+	PMD_DRV_LOG(INFO, "host_total_function: 0x%x, max_vf: 0x%x",
+		    cap->host_total_function, cap->max_vf);
+	PMD_DRV_LOG(INFO,
+		    "host_pf_num: 0x%x, pf_id_start: 0x%x, host_vf_num: 0x%x, "
+		    "vf_id_start: 0x%x",
+		    cap->pf_num, cap->pf_id_start, cap->vf_num,
+		    cap->vf_id_start);
+}
+
+static void
+parse_l2nic_res_cap(struct service_cap *cap,
+		    struct hinic3_cfg_cmd_dev_cap *dev_cap)
+{
+	struct nic_service_cap *nic_cap = &cap->nic_cap;
+
+	nic_cap->max_sqs = dev_cap->nic_max_sq_id + 1;
+	nic_cap->max_rqs = dev_cap->nic_max_rq_id + 1;
+
+	PMD_DRV_LOG(INFO,
+		    "L2nic resource capbility, "
+		    "max_sqs: 0x%x, max_rqs: 0x%x",
+		    nic_cap->max_sqs, nic_cap->max_rqs);
+}
+
+static void
+parse_dev_cap(struct hinic3_hwdev *dev, struct hinic3_cfg_cmd_dev_cap *dev_cap,
+	      enum func_type type)
+{
+	struct service_cap *cap = &dev->cfg_mgmt->svc_cap;
+
+	parse_pub_res_cap(cap, dev_cap, type);
+
+	if (IS_NIC_TYPE(dev))
+		parse_l2nic_res_cap(cap, dev_cap);
+}
+
+static int
+get_cap_from_fw(struct hinic3_hwdev *hwdev, enum func_type type)
+{
+	struct hinic3_cfg_cmd_dev_cap dev_cap;
+	u16 out_len = sizeof(dev_cap);
+	int err;
+
+	memset(&dev_cap, 0, sizeof(dev_cap));
+	dev_cap.func_id = hinic3_global_func_id(hwdev);
+	err = hinic3_msg_to_mgmt_sync(hwdev, HINIC3_MOD_CFGM,
+				      HINIC3_CFG_CMD_GET_DEV_CAP, &dev_cap,
+				      sizeof(dev_cap), &dev_cap, &out_len, 0);
+	if (err || dev_cap.status || !out_len) {
+		PMD_DRV_LOG(ERR,
+			    "Get capability from FW failed, "
+			    "err: %d, status: 0x%x, out size: 0x%x",
+			    err, dev_cap.status, out_len);
+		return -EFAULT;
+	}
+
+	parse_dev_cap(hwdev, &dev_cap, type);
+	return 0;
+}
+
+static int
+get_dev_cap(struct hinic3_hwdev *hwdev)
+{
+	enum func_type type = HINIC3_FUNC_TYPE(hwdev);
+
+	switch (type) {
+	case TYPE_PF:
+	case TYPE_PPF:
+	case TYPE_VF:
+		if (get_cap_from_fw(hwdev, type) != 0)
+			return -EFAULT;
+		break;
+	default:
+		PMD_DRV_LOG(ERR, "Unsupported PCIe function type: %d", type);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
+int
+cfg_mbx_vf_proc_msg(void *hwdev, __rte_unused void *pri_handle, u16 cmd,
+		    __rte_unused void *buf_in, __rte_unused u16 in_size,
+		    __rte_unused void *buf_out, __rte_unused u16 *out_size)
+{
+	struct hinic3_hwdev *dev = hwdev;
+
+	if (!dev)
+		return -EINVAL;
+
+	PMD_DRV_LOG(WARNING, "Unsupported cfg mbox vf event %d to process",
+		    cmd);
+
+	return 0;
+}
+
+int
+hinic3_init_cfg_mgmt(void *dev)
+{
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
+	struct cfg_mgmt_info *cfg_mgmt = NULL;
+
+	cfg_mgmt = rte_zmalloc("cfg_mgmt", sizeof(*cfg_mgmt),
+			       HINIC3_MEM_ALLOC_ALIGN_MIN);
+	if (!cfg_mgmt)
+		return -ENOMEM;
+
+	memset(cfg_mgmt, 0, sizeof(struct cfg_mgmt_info));
+	hwdev->cfg_mgmt = cfg_mgmt;
+	cfg_mgmt->hwdev = hwdev;
+
+	return 0;
+}
+
+int
+hinic3_init_capability(void *dev)
+{
+	struct hinic3_hwdev *hwdev = (struct hinic3_hwdev *)dev;
+
+	return get_dev_cap(hwdev);
+}
+
+void
+hinic3_deinit_cfg_mgmt(void *dev)
+{
+	rte_free(((struct hinic3_hwdev *)dev)->cfg_mgmt);
+	((struct hinic3_hwdev *)dev)->cfg_mgmt = NULL;
+}
+
+#ifdef HINIC3_RELEASE
+static bool
+hinic3_support_nic(void *hwdev, struct nic_service_cap *cap)
+{
+	struct hinic3_hwdev *dev = (struct hinic3_hwdev *)hwdev;
+
+	if (!hwdev)
+		return false;
+
+	if (!IS_NIC_TYPE(dev))
+		return false;
+
+	if (cap)
+		memcpy(cap, &dev->cfg_mgmt->svc_cap.nic_cap, sizeof(*cap));
+
+	return true;
+}
+
+static bool
+hinic3_func_for_mgmt(void *hwdev)
+{
+	struct hinic3_hwdev *dev = hwdev;
+
+	if (!hwdev)
+		return false;
+
+	if (dev->cfg_mgmt->svc_cap.chip_svc_type >= CFG_SVC_NIC_BIT0)
+		return false;
+	else
+		return true;
+}
+#endif
+
+u16
+hinic3_func_max_sqs(void *hwdev)
+{
+	struct hinic3_hwdev *dev = hwdev;
+
+	if (!dev) {
+		PMD_DRV_LOG(INFO, "Hwdev is NULL for getting max_sqs");
+		return 0;
+	}
+
+	return dev->cfg_mgmt->svc_cap.nic_cap.max_sqs;
+}
+
+u16
+hinic3_func_max_rqs(void *hwdev)
+{
+	struct hinic3_hwdev *dev = hwdev;
+
+	if (!dev) {
+		PMD_DRV_LOG(INFO, "Hwdev is NULL for getting max_rqs");
+		return 0;
+	}
+
+	return dev->cfg_mgmt->svc_cap.nic_cap.max_rqs;
+}
+
+u8
+hinic3_physical_port_id(void *hwdev)
+{
+	struct hinic3_hwdev *dev = hwdev;
+
+	if (!dev) {
+		PMD_DRV_LOG(INFO, "Hwdev is NULL for getting physical port id");
+		return 0;
+	}
+
+	return dev->cfg_mgmt->svc_cap.port_id;
+}
drivers/net/hinic3/base/hinic3_hw_cfg.h new file +121 -0

121 lines not on this page · raw message

drivers/net/hinic3/base/hinic3_hw_comm.c new file +452 -0

452 lines not on this page · raw message

drivers/net/hinic3/base/hinic3_hw_comm.h new file +366 -0

366 lines not on this page · raw message

drivers/net/hinic3/base/hinic3_hwdev.c new file +573 -0

573 lines not on this page · raw message

drivers/net/hinic3/base/hinic3_hwdev.h new file +177 -0

177 lines not on this page · raw message

Signature · 1 line
2.45.1.windows.1