DPDK patches and discussions
 help / color / mirror / Atom feed
From: Xiaoyun wang <cloud.wangxiaoyun@huawei.com>
To: <ferruh.yigit@intel.com>
Cc: <dev@dpdk.org>, <xuanziyang2@huawei.com>,
	<shahar.belkar@huawei.com>, <luoxianjun@huawei.com>,
	<tanya.brokhman@huawei.com>, <zhouguoyang@huawei.com>,
	<wulike1@huawei.com>, Xiaoyun wang <cloud.wangxiaoyun@huawei.com>
Subject: [dpdk-dev] [PATCH v3 02/19] net/hinic/base: add HW interfaces for SR-IOV
Date: Mon, 30 Sep 2019 22:00:40 +0800	[thread overview]
Message-ID: <f0c5bbb8799acfbde0368c44043d1016c1470564.1569850827.git.cloud.wangxiaoyun@huawei.com> (raw)
In-Reply-To: <cover.1569850826.git.cloud.wangxiaoyun@huawei.com>

This patch introduces some HW interfaces required for SR-IOV function,
including: init hwdev, set port state, get default cos,
vf dma attribute table, vf txrx flush and so on.

Signed-off-by: Xiaoyun wang <cloud.wangxiaoyun@huawei.com>
---
 drivers/net/hinic/base/hinic_compat.h      |  32 ----
 drivers/net/hinic/base/hinic_pmd_api_cmd.c |  60 +++----
 drivers/net/hinic/base/hinic_pmd_cfg.c     |  35 ++++
 drivers/net/hinic/base/hinic_pmd_cmd.h     |  14 +-
 drivers/net/hinic/base/hinic_pmd_hwdev.c   | 198 ++++++++++++++++-----
 drivers/net/hinic/base/hinic_pmd_hwdev.h   |   4 +
 drivers/net/hinic/base/hinic_pmd_hwif.c    |  85 ++++++++-
 drivers/net/hinic/base/hinic_pmd_hwif.h    |  15 +-
 drivers/net/hinic/base/hinic_pmd_mgmt.c    |  83 +++++----
 drivers/net/hinic/base/hinic_pmd_mgmt.h    |   2 +-
 drivers/net/hinic/base/hinic_pmd_niccfg.c  | 268 +++++++++++++++++++++++------
 drivers/net/hinic/base/hinic_pmd_niccfg.h  |   4 +
 drivers/net/hinic/base/hinic_pmd_nicio.c   |  15 +-
 drivers/net/hinic/base/hinic_pmd_nicio.h   |   3 +-
 14 files changed, 606 insertions(+), 212 deletions(-)

diff --git a/drivers/net/hinic/base/hinic_compat.h b/drivers/net/hinic/base/hinic_compat.h
index db60a51..85cbb5b 100644
--- a/drivers/net/hinic/base/hinic_compat.h
+++ b/drivers/net/hinic/base/hinic_compat.h
@@ -223,38 +223,6 @@ static inline u16 ilog2(u32 n)
 	return res;
 }
 
-/**
- * hinic_cpu_to_be32 - convert data to big endian 32 bit format
- * @data: the data to convert
- * @len: length of data to convert, must be Multiple of 4B
- */
-static inline void hinic_cpu_to_be32(void *data, u32 len)
-{
-	u32 i;
-	u32 *mem = (u32 *)data;
-
-	for (i = 0; i < (len >> 2); i++) {
-		*mem = cpu_to_be32(*mem);
-		mem++;
-	}
-}
-
-/**
- * hinic_be32_to_cpu - convert data from big endian 32 bit format
- * @data: the data to convert
- * @len: length of data to convert, must be Multiple of 4B
- */
-static inline void hinic_be32_to_cpu(void *data, u32 len)
-{
-	u32 i;
-	u32 *mem = (u32 *)data;
-
-	for (i = 0; i < (len >> 2); i++) {
-		*mem = be32_to_cpu(*mem);
-		mem++;
-	}
-}
-
 static inline int hinic_mutex_init(pthread_mutex_t *pthreadmutex,
 					const pthread_mutexattr_t *mattr)
 {
diff --git a/drivers/net/hinic/base/hinic_pmd_api_cmd.c b/drivers/net/hinic/base/hinic_pmd_api_cmd.c
index 1ea86fa..dbffc2e 100644
--- a/drivers/net/hinic/base/hinic_pmd_api_cmd.c
+++ b/drivers/net/hinic/base/hinic_pmd_api_cmd.c
@@ -120,7 +120,7 @@ static void dump_api_chain_reg(struct hinic_api_cmd_chain *chain)
 /**
  * chain_busy - check if the chain is still processing last requests
  * @chain: chain to check
- **/
+ */
 static int chain_busy(struct hinic_api_cmd_chain *chain)
 {
 	switch (chain->chain_type) {
@@ -146,7 +146,7 @@ static int chain_busy(struct hinic_api_cmd_chain *chain)
 /**
  * get_cell_data_size - get the data size of specific cell type
  * @type: chain type
- **/
+ */
 static u16 get_cell_data_size(enum hinic_api_cmd_chain_type type,
 				__rte_unused u16 cmd_size)
 {
@@ -170,7 +170,7 @@ static u16 get_cell_data_size(enum hinic_api_cmd_chain_type type,
  * prepare_cell_ctrl - prepare the ctrl of the cell for the command
  * @cell_ctrl: the control of the cell to set the control into it
  * @cell_len: the size of the cell
- **/
+ */
 static void prepare_cell_ctrl(u64 *cell_ctrl, u16 cell_len)
 {
 	u64 ctrl;
@@ -202,7 +202,7 @@ static void prepare_cell_ctrl(u64 *cell_ctrl, u16 cell_len)
  * @dest: destination node on the card that will receive the command
  * @cmd: command data
  * @cmd_size: the command size
- **/
+ */
 static void prepare_api_cmd(struct hinic_api_cmd_chain *chain,
 				struct hinic_api_cmd_cell *cell,
 				enum hinic_node_id dest,
@@ -254,7 +254,7 @@ static void prepare_api_cmd(struct hinic_api_cmd_chain *chain,
  * @dest: destination node on the card that will receive the command
  * @cmd: command data
  * @cmd_size: the command size
- **/
+ */
 static void prepare_cell(struct hinic_api_cmd_chain *chain,
 			 enum  hinic_node_id dest,
 			 void *cmd, u16 cmd_size)
@@ -283,7 +283,7 @@ static void issue_api_cmd(struct hinic_api_cmd_chain *chain)
 /**
  * api_cmd_status_update - update the status of the chain
  * @chain: chain to update
- **/
+ */
 static void api_cmd_status_update(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_api_cmd_status *wb_status;
@@ -314,7 +314,7 @@ static void api_cmd_status_update(struct hinic_api_cmd_chain *chain)
  * wait_for_status_poll - wait for write to mgmt command to complete
  * @chain: the chain of the command
  * Return: 0 - success, negative - failure
- **/
+ */
 static int wait_for_status_poll(struct hinic_api_cmd_chain *chain)
 {
 	unsigned long end;
@@ -340,7 +340,7 @@ static int wait_for_status_poll(struct hinic_api_cmd_chain *chain)
  * wait_for_api_cmd_completion - wait for command to complete
  * @chain: chain for the command
  * Return: 0 - success, negative - failure
- **/
+ */
 static int wait_for_api_cmd_completion(struct hinic_api_cmd_chain *chain,
 		       __rte_unused struct hinic_api_cmd_cell_ctxt *ctxt,
 		       __rte_unused void *ack, __rte_unused u16 ack_size)
@@ -384,7 +384,7 @@ static inline void update_api_cmd_ctxt(struct hinic_api_cmd_chain *chain,
  * @ack: pointer to messages to response
  * @ack_size: the size of ack message
  * Return: 0 - success, negative - failure
- **/
+ */
 static int api_cmd(struct hinic_api_cmd_chain *chain,
 		   enum hinic_node_id dest,
 		   void *cmd, u16 cmd_size, void *ack, u16 ack_size)
@@ -423,7 +423,7 @@ static int api_cmd(struct hinic_api_cmd_chain *chain,
  * @cmd: command data
  * @size: the command size
  * Return: 0 - success, negative - failure
- **/
+ */
 int hinic_api_cmd_write(struct hinic_api_cmd_chain *chain,
 			enum hinic_node_id dest, void *cmd, u16 size)
 {
@@ -434,7 +434,7 @@ int hinic_api_cmd_write(struct hinic_api_cmd_chain *chain,
 /**
  * api_cmd_hw_restart - restart the chain in the HW
  * @chain: the API CMD specific chain to restart
- **/
+ */
 static int api_cmd_hw_restart(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -470,7 +470,7 @@ static int api_cmd_hw_restart(struct hinic_api_cmd_chain *chain)
 /**
  * api_cmd_ctrl_init - set the control register of a chain
  * @chain: the API CMD specific chain to set control register for
- **/
+ */
 static void api_cmd_ctrl_init(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -497,7 +497,7 @@ static void api_cmd_ctrl_init(struct hinic_api_cmd_chain *chain)
 /**
  * api_cmd_set_status_addr - set the status address of a chain in the HW
  * @chain: the API CMD specific chain to set status address for
- **/
+ */
 static void api_cmd_set_status_addr(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -515,7 +515,7 @@ static void api_cmd_set_status_addr(struct hinic_api_cmd_chain *chain)
 /**
  * api_cmd_set_num_cells - set the number cells of a chain in the HW
  * @chain: the API CMD specific chain to set the number of cells for
- **/
+ */
 static void api_cmd_set_num_cells(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -529,7 +529,7 @@ static void api_cmd_set_num_cells(struct hinic_api_cmd_chain *chain)
 /**
  * api_cmd_head_init - set the head cell of a chain in the HW
  * @chain: the API CMD specific chain to set the head for
- **/
+ */
 static void api_cmd_head_init(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -548,7 +548,7 @@ static void api_cmd_head_init(struct hinic_api_cmd_chain *chain)
  * wait_for_ready_chain - wait for the chain to be ready
  * @chain: the API CMD specific chain to wait for
  * Return: 0 - success, negative - failure
- **/
+ */
 static int wait_for_ready_chain(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -580,7 +580,7 @@ static int wait_for_ready_chain(struct hinic_api_cmd_chain *chain)
 /**
  * api_cmd_chain_hw_clean - clean the HW
  * @chain: the API CMD specific chain
- **/
+ */
 static void api_cmd_chain_hw_clean(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_hwif *hwif = chain->hwdev->hwif;
@@ -603,7 +603,7 @@ static void api_cmd_chain_hw_clean(struct hinic_api_cmd_chain *chain)
  *(initialize API command csr)
  * @chain: the API CMD specific chain to initialize in HW
  * Return: 0 - success, negative - failure
- **/
+ */
 static int api_cmd_chain_hw_init(struct hinic_api_cmd_chain *chain)
 {
 	api_cmd_chain_hw_clean(chain);
@@ -626,7 +626,7 @@ static int api_cmd_chain_hw_init(struct hinic_api_cmd_chain *chain)
  * free_cmd_buf - free the dma buffer of API CMD command
  * @chain: the API CMD specific chain of the cmd
  * @cell_idx: the cell index of the cmd
- **/
+ */
 static void free_cmd_buf(struct hinic_api_cmd_chain *chain, u32 cell_idx)
 {
 	struct hinic_api_cmd_cell_ctxt *cell_ctxt;
@@ -645,7 +645,7 @@ static void free_cmd_buf(struct hinic_api_cmd_chain *chain, u32 cell_idx)
  * @cell: the cell in the HW for the cmd
  * @cell_idx: the index of the cell
  * Return: 0 - success, negative - failure
- **/
+ */
 static int alloc_cmd_buf(struct hinic_api_cmd_chain *chain,
 			 struct hinic_api_cmd_cell *cell, u32 cell_idx)
 {
@@ -697,7 +697,7 @@ static int alloc_cmd_buf(struct hinic_api_cmd_chain *chain,
  * @pre_node: previous cell
  * @node_vaddr: the virt addr of the cell
  * Return: 0 - success, negative - failure
- **/
+ */
 static int api_cmd_create_cell(struct hinic_api_cmd_chain *chain,
 			       u32 cell_idx,
 			       struct hinic_api_cmd_cell *pre_node,
@@ -774,7 +774,7 @@ static int api_cmd_create_cell(struct hinic_api_cmd_chain *chain,
  * api_cmd_destroy_cell - destroy API CMD cell of specific chain
  * @chain: the API CMD specific chain to destroy its cell
  * @cell_idx: the cell to destroy
- **/
+ */
 static void api_cmd_destroy_cell(struct hinic_api_cmd_chain *chain,
 				 u32 cell_idx)
 {
@@ -808,7 +808,7 @@ static void api_cmd_destroy_cell(struct hinic_api_cmd_chain *chain,
  * api_cmd_destroy_cells - destroy API CMD cells of specific chain
  * @chain: the API CMD specific chain to destroy its cells
  * @num_cells: number of cells to destroy
- **/
+ */
 static void api_cmd_destroy_cells(struct hinic_api_cmd_chain *chain,
 					 u32 num_cells)
 {
@@ -822,7 +822,7 @@ static void api_cmd_destroy_cells(struct hinic_api_cmd_chain *chain,
  * api_cmd_create_cells - create API CMD cells for specific chain
  * @chain: the API CMD specific chain
  * Return: 0 - success, negative - failure
- **/
+ */
 static int api_cmd_create_cells(struct hinic_api_cmd_chain *chain)
 {
 	struct hinic_api_cmd_cell *node = NULL, *pre_node = NULL;
@@ -861,7 +861,7 @@ static int api_cmd_create_cells(struct hinic_api_cmd_chain *chain)
  * @chain: the API CMD specific chain to initialize
  * @attr: attributes to set in the chain
  * Return: 0 - success, negative - failure
- **/
+ */
 static int api_chain_init(struct hinic_api_cmd_chain *chain,
 			  struct hinic_api_cmd_chain_attr *attr)
 {
@@ -910,7 +910,7 @@ static int api_chain_init(struct hinic_api_cmd_chain *chain,
 /**
  * api_chain_free - free API CMD specific chain
  * @chain: the API CMD specific chain to free
- **/
+ */
 static void api_chain_free(struct hinic_api_cmd_chain *chain)
 {
 	void *dev = chain->hwdev;
@@ -925,7 +925,7 @@ static void api_chain_free(struct hinic_api_cmd_chain *chain)
  * @cmd_chain: the API CMD specific chain to create
  * @attr: attributes to set in the chain
  * Return: 0 - success, negative - failure
- **/
+ */
 static int api_cmd_create_chain(struct hinic_api_cmd_chain **cmd_chain,
 				struct hinic_api_cmd_chain_attr *attr)
 {
@@ -981,7 +981,7 @@ static int api_cmd_create_chain(struct hinic_api_cmd_chain **cmd_chain,
 /**
  * api_cmd_destroy_chain - destroy API CMD specific chain
  * @chain: the API CMD specific chain to destroy
- **/
+ */
 static void api_cmd_destroy_chain(struct hinic_api_cmd_chain *chain)
 {
 	api_cmd_destroy_cells(chain, chain->num_cells);
@@ -994,7 +994,7 @@ static void api_cmd_destroy_chain(struct hinic_api_cmd_chain *chain)
  * @hwdev: the hardware interface of a pci function device
  * @chain: the API CMD chains that will be initialized
  * Return: 0 - success, negative - failure
- **/
+ */
 int hinic_api_cmd_init(struct hinic_hwdev *hwdev,
 		       struct hinic_api_cmd_chain **chain)
 {
@@ -1031,7 +1031,7 @@ int hinic_api_cmd_init(struct hinic_hwdev *hwdev,
 /**
  * hinic_api_cmd_free - free the API CMD chains
  * @chain: the API CMD chains that will be freed
- **/
+ */
 void hinic_api_cmd_free(struct hinic_api_cmd_chain **chain)
 {
 	enum hinic_api_cmd_chain_type chain_type;
diff --git a/drivers/net/hinic/base/hinic_pmd_cfg.c b/drivers/net/hinic/base/hinic_pmd_cfg.c
index 61537b1..aa883e0 100644
--- a/drivers/net/hinic/base/hinic_pmd_cfg.c
+++ b/drivers/net/hinic/base/hinic_pmd_cfg.c
@@ -8,6 +8,7 @@
 #include "hinic_pmd_mgmt.h"
 #include "hinic_pmd_eqs.h"
 #include "hinic_pmd_cfg.h"
+#include "hinic_pmd_mbox.h"
 
 bool hinic_support_nic(struct hinic_hwdev *hwdev, struct nic_service_cap *cap)
 {
@@ -122,6 +123,10 @@ static void hinic_parse_pub_res_cap(struct service_cap *cap,
 		cap->vf_id_start = dev_cap->vf_id_start;
 		cap->max_sqs = dev_cap->nic_max_sq + 1;
 		cap->max_rqs = dev_cap->nic_max_rq + 1;
+	} else {
+		cap->max_vf = 0;
+		cap->max_sqs = dev_cap->nic_max_sq;
+		cap->max_rqs = dev_cap->nic_max_rq;
 	}
 
 	cap->chip_svc_type = CFG_SVC_NIC_BIT0;
@@ -180,6 +185,28 @@ static int get_cap_from_fw(struct hinic_hwdev *dev, enum func_type type)
 	return 0;
 }
 
+static int get_cap_from_pf(struct hinic_hwdev *dev, enum func_type type)
+{
+	int err;
+	u16 in_len, out_len;
+	struct hinic_dev_cap dev_cap;
+
+	memset(&dev_cap, 0, sizeof(dev_cap));
+	in_len = sizeof(dev_cap);
+	out_len = in_len;
+	err = hinic_mbox_to_pf(dev, HINIC_MOD_CFGM, HINIC_CFG_MBOX_CAP,
+			       &dev_cap, in_len, &dev_cap, &out_len,
+			       CFG_MAX_CMD_TIMEOUT);
+	if (err || dev_cap.mgmt_msg_head.status || !out_len) {
+		PMD_DRV_LOG(ERR, "Get capability from PF failed, err: %d, status: %d, out_len: %d",
+				err, dev_cap.mgmt_msg_head.status, out_len);
+		return -EFAULT;
+	}
+
+	parse_dev_cap(dev, &dev_cap, type);
+	return 0;
+}
+
 static int get_dev_cap(struct hinic_hwdev *dev)
 {
 	int err;
@@ -194,6 +221,14 @@ static int get_dev_cap(struct hinic_hwdev *dev)
 			return err;
 		}
 		break;
+	case TYPE_VF:
+		err = get_cap_from_pf(dev, type);
+		if (err) {
+			PMD_DRV_LOG(ERR, "Get VF capability failed, err: %d",
+					err);
+			return err;
+		}
+		break;
 	default:
 		PMD_DRV_LOG(ERR, "Unsupported PCI function type");
 		return -EINVAL;
diff --git a/drivers/net/hinic/base/hinic_pmd_cmd.h b/drivers/net/hinic/base/hinic_pmd_cmd.h
index 7a9e9f6..c8750b8 100644
--- a/drivers/net/hinic/base/hinic_pmd_cmd.h
+++ b/drivers/net/hinic/base/hinic_pmd_cmd.h
@@ -25,6 +25,12 @@ enum hinic_mod_type {
 	HINIC_MOD_MAX	= 15
 };
 
+/* only used by VFD communicating with PFD to register or unregister,
+ * command mode type is HINIC_MOD_L2NIC
+ */
+#define HINIC_PORT_CMD_VF_REGISTER	0x0
+#define HINIC_PORT_CMD_VF_UNREGISTER	0x1
+
 /* cmd of mgmt CPU message for NIC module */
 enum hinic_port_cmd {
 	HINIC_PORT_CMD_MGMT_RESET		= 0x0,
@@ -416,12 +422,12 @@ enum hinic_pf_status {
 };
 
 /* total doorbell or direct wqe size is 512kB, db num: 128, dwqe: 128 */
-#define HINIC_DB_DWQE_SIZE       0x00080000
+#define HINIC_DB_DWQE_SIZE	0x00080000
 
-/* db/dwqe page size: 4K */
-#define HINIC_DB_PAGE_SIZE		0x00001000ULL
+/* db page size: 4K */
+#define HINIC_DB_PAGE_SIZE	0x00001000ULL
 
-#define HINIC_DB_MAX_AREAS         (HINIC_DB_DWQE_SIZE / HINIC_DB_PAGE_SIZE)
+#define HINIC_DB_MAX_AREAS	(HINIC_DB_DWQE_SIZE / HINIC_DB_PAGE_SIZE)
 
 #define HINIC_PCI_MSIX_ENTRY_SIZE			16
 #define HINIC_PCI_MSIX_ENTRY_VECTOR_CTRL		12
diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.c b/drivers/net/hinic/base/hinic_pmd_hwdev.c
index 4f70baf..6480d56 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwdev.c
+++ b/drivers/net/hinic/base/hinic_pmd_hwdev.c
@@ -15,6 +15,7 @@
 #include "hinic_pmd_cmdq.h"
 #include "hinic_pmd_mgmt.h"
 #include "hinic_pmd_niccfg.h"
+#include "hinic_pmd_mbox.h"
 
 #define HINIC_DEAULT_EQ_MSIX_PENDING_LIMIT		0
 #define HINIC_DEAULT_EQ_MSIX_COALESC_TIMER_CFG		0xFF
@@ -65,6 +66,52 @@
 	"Unrecognized module",
 };
 
+struct hinic_vf_dma_attr_table {
+	struct hinic_mgmt_msg_head mgmt_msg_head;
+
+	u16	func_idx;
+	u8	func_dma_entry_num;
+	u8	entry_idx;
+	u8	st;
+	u8	at;
+	u8	ph;
+	u8	no_snooping;
+	u8	tph_en;
+	u8	resv1[3];
+};
+
+/**
+ * hinic_cpu_to_be32 - convert data to big endian 32 bit format
+ * @data: the data to convert
+ * @len: length of data to convert, must be Multiple of 4B
+ */
+void hinic_cpu_to_be32(void *data, u32 len)
+{
+	u32 i;
+	u32 *mem = (u32 *)data;
+
+	for (i = 0; i < (len >> 2); i++) {
+		*mem = cpu_to_be32(*mem);
+		mem++;
+	}
+}
+
+/**
+ * hinic_be32_to_cpu - convert data from big endian 32 bit format
+ * @data: the data to convert
+ * @len: length of data to convert, must be Multiple of 4B
+ */
+void hinic_be32_to_cpu(void *data, u32 len)
+{
+	u32 i;
+	u32 *mem = (u32 *)data;
+
+	for (i = 0; i < (len >> 2); i++) {
+		*mem = be32_to_cpu(*mem);
+		mem++;
+	}
+}
+
 static void *
 hinic_dma_mem_zalloc(struct hinic_hwdev *hwdev, size_t size,
 		dma_addr_t *dma_handle, unsigned int flag, unsigned int align)
@@ -332,18 +379,6 @@ void hinic_osdep_deinit(struct hinic_hwdev *hwdev)
 	}
 }
 
-
-
-
-
-
-
-
-
-
-
-
-
 /**
  * hinic_set_ci_table - set ci attribute table
  * @hwdev: the hardware interface of a nic device
@@ -352,7 +387,7 @@ void hinic_osdep_deinit(struct hinic_hwdev *hwdev)
  * @return
  *   0 on success and ci attribute table is filled,
  *   negative error value otherwise.
- **/
+ */
 int hinic_set_ci_table(void *hwdev, u16 q_id, struct hinic_sq_attr *attr)
 {
 	struct hinic_cons_idx_attr cons_idx_attr;
@@ -385,7 +420,7 @@ int hinic_set_ci_table(void *hwdev, u16 q_id, struct hinic_sq_attr *attr)
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 int hinic_set_pagesize(void *hwdev, u8 page_size)
 {
 	struct hinic_page_size cmd;
@@ -417,7 +452,6 @@ static int wait_for_flr_finish(struct hinic_hwif *hwif)
 	do {
 		status = hinic_get_pf_status(hwif);
 		if (status == HINIC_PF_STATUS_FLR_FINISH_FLAG) {
-			hinic_set_pf_status(hwif, HINIC_PF_STATUS_ACTIVE_FLAG);
 			return 0;
 		}
 
@@ -463,13 +497,51 @@ static int wait_cmdq_stop(struct hinic_hwdev *hwdev)
 	return err;
 }
 
+static int hinic_vf_rx_tx_flush(struct hinic_hwdev *hwdev)
+{
+	struct hinic_clear_resource clr_res;
+	int err;
+
+	err = wait_cmdq_stop(hwdev);
+	if (err) {
+		PMD_DRV_LOG(WARNING, "Cmdq is still working");
+		return err;
+	}
+
+	memset(&clr_res, 0, sizeof(clr_res));
+	clr_res.func_idx = HINIC_HWIF_GLOBAL_IDX(hwdev->hwif);
+	clr_res.ppf_idx  = HINIC_HWIF_PPF_IDX(hwdev->hwif);
+	err = hinic_mbox_to_pf_no_ack(hwdev, HINIC_MOD_COMM,
+		HINIC_MGMT_CMD_START_FLR, &clr_res, sizeof(clr_res));
+	if (err)
+		PMD_DRV_LOG(WARNING, "Notice flush message failed");
+
+	/*
+	 * PF firstly set VF doorbell flush csr to be disabled. After PF finish
+	 * VF resources flush, PF will set VF doorbell flush csr to be enabled.
+	 */
+	err = wait_until_doorbell_flush_states(hwdev->hwif, DISABLE_DOORBELL);
+	if (err)
+		PMD_DRV_LOG(WARNING, "Wait doorbell flush disable timeout");
+
+	err = wait_until_doorbell_flush_states(hwdev->hwif, ENABLE_DOORBELL);
+	if (err)
+		PMD_DRV_LOG(WARNING, "Wait doorbell flush enable timeout");
+
+	err = hinic_reinit_cmdq_ctxts(hwdev);
+	if (err)
+		PMD_DRV_LOG(WARNING, "Reinit cmdq failed");
+
+	return err;
+}
+
 /**
  * hinic_pf_rx_tx_flush - clean up hardware resource
  * @hwdev: the hardware interface of a nic device
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 static int hinic_pf_rx_tx_flush(struct hinic_hwdev *hwdev)
 {
 	struct hinic_hwif *hwif = hwdev->hwif;
@@ -523,7 +595,10 @@ static int hinic_pf_rx_tx_flush(struct hinic_hwdev *hwdev)
 
 int hinic_func_rx_tx_flush(struct hinic_hwdev *hwdev)
 {
-	return hinic_pf_rx_tx_flush(hwdev);
+	if (HINIC_FUNC_TYPE(hwdev) == TYPE_VF)
+		return hinic_vf_rx_tx_flush(hwdev);
+	else
+		return hinic_pf_rx_tx_flush(hwdev);
 }
 
 /**
@@ -531,7 +606,7 @@ int hinic_func_rx_tx_flush(struct hinic_hwdev *hwdev)
  * @hwdev: the hardware interface of a nic device
  * @interrupt_info: Information of Interrupt aggregation
  * Return: 0 on success, negative error value otherwise.
- **/
+ */
 static int hinic_get_interrupt_cfg(struct hinic_hwdev *hwdev,
 				struct nic_interrupt_info *interrupt_info)
 {
@@ -567,7 +642,7 @@ static int hinic_get_interrupt_cfg(struct hinic_hwdev *hwdev,
  * @hwdev: the hardware interface of a nic device
  * @interrupt_info: Information of Interrupt aggregation
  * Return: 0 on success, negative error value otherwise.
- **/
+ */
 int hinic_set_interrupt_cfg(struct hinic_hwdev *hwdev,
 			    struct nic_interrupt_info interrupt_info)
 {
@@ -623,7 +698,7 @@ int hinic_set_interrupt_cfg(struct hinic_hwdev *hwdev,
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 int init_aeqs_msix_attr(void *hwdev)
 {
 	struct hinic_hwdev *nic_hwdev = hwdev;
@@ -662,7 +737,7 @@ int init_aeqs_msix_attr(void *hwdev)
  * @ph: PCIE TLP Processing Hint field
  * @no_snooping: PCIE TLP No snooping
  * @tph_en: PCIE TLP Processing Hint Enable
- **/
+ */
 static void set_pf_dma_attr_entry(struct hinic_hwdev *hwdev, u32 entry_idx,
 				  u8 st, u8 at, u8 ph,
 				  enum hinic_pcie_nosnoop no_snooping,
@@ -690,28 +765,74 @@ static void set_pf_dma_attr_entry(struct hinic_hwdev *hwdev, u32 entry_idx,
 	hinic_hwif_write_reg(hwdev->hwif, addr, val);
 }
 
+static int set_vf_dma_attr_entry(struct hinic_hwdev *hwdev, u8 entry_idx,
+				u8 st, u8 at, u8 ph,
+				enum hinic_pcie_nosnoop no_snooping,
+				enum hinic_pcie_tph tph_en)
+{
+	struct hinic_vf_dma_attr_table attr;
+
+	memset(&attr, 0, sizeof(attr));
+	attr.func_idx = hinic_global_func_id(hwdev);
+	attr.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
+	attr.func_dma_entry_num = hinic_dma_attr_entry_num(hwdev);
+	attr.entry_idx = entry_idx;
+	attr.st = st;
+	attr.at = at;
+	attr.ph = ph;
+	attr.no_snooping = no_snooping;
+	attr.tph_en = tph_en;
+
+	return hinic_msg_to_mgmt_sync(hwdev, HINIC_MOD_COMM,
+					HINIC_MGMT_CMD_DMA_ATTR_SET,
+					&attr, sizeof(attr), NULL, NULL, 0);
+}
+
 /**
  * dma_attr_table_init - initialize the the default dma attributes
  * @hwdev: the pointer to the private hardware device object
- **/
-static void dma_attr_table_init(struct hinic_hwdev *hwdev)
+ */
+static int dma_attr_table_init(struct hinic_hwdev *hwdev)
 {
+	int err = 0;
+
 	if (HINIC_IS_VF(hwdev))
-		return;
+		err = set_vf_dma_attr_entry(hwdev, PCIE_MSIX_ATTR_ENTRY,
+				HINIC_PCIE_ST_DISABLE, HINIC_PCIE_AT_DISABLE,
+				HINIC_PCIE_PH_DISABLE, HINIC_PCIE_SNOOP,
+				HINIC_PCIE_TPH_DISABLE);
+	else
+		set_pf_dma_attr_entry(hwdev, PCIE_MSIX_ATTR_ENTRY,
+				HINIC_PCIE_ST_DISABLE, HINIC_PCIE_AT_DISABLE,
+				HINIC_PCIE_PH_DISABLE, HINIC_PCIE_SNOOP,
+				HINIC_PCIE_TPH_DISABLE);
 
-	set_pf_dma_attr_entry(hwdev, PCIE_MSIX_ATTR_ENTRY,
-			      HINIC_PCIE_ST_DISABLE,
-			      HINIC_PCIE_AT_DISABLE,
-			      HINIC_PCIE_PH_DISABLE,
-			      HINIC_PCIE_SNOOP,
-			      HINIC_PCIE_TPH_DISABLE);
+	return err;
 }
 
+/**
+ * hinic_init_attr_table - init dma and aeq msix attribute table
+ * @hwdev: the pointer to the private hardware device object
+ */
 int hinic_init_attr_table(struct hinic_hwdev *hwdev)
 {
-	dma_attr_table_init(hwdev);
+	int err;
 
-	return init_aeqs_msix_attr(hwdev);
+	err = dma_attr_table_init(hwdev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Initialize dma attribute table failed, err: %d",
+				err);
+		return err;
+	}
+
+	err = init_aeqs_msix_attr(hwdev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Initialize aeqs msix attribute failed, err: %d",
+				err);
+		return err;
+	}
+
+	return 0;
 }
 
 #define FAULT_SHOW_STR_LEN 16
@@ -826,7 +947,7 @@ static int resources_state_set(struct hinic_hwdev *hwdev,
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 int hinic_activate_hwdev_state(struct hinic_hwdev *hwdev)
 {
 	int rc = HINIC_OK;
@@ -834,9 +955,7 @@ int hinic_activate_hwdev_state(struct hinic_hwdev *hwdev)
 	if (!hwdev)
 		return -EINVAL;
 
-	if (!HINIC_IS_VF(hwdev))
-		hinic_set_pf_status(hwdev->hwif,
-				    HINIC_PF_STATUS_ACTIVE_FLAG);
+	hinic_set_pf_status(hwdev->hwif, HINIC_PF_STATUS_ACTIVE_FLAG);
 
 	rc = resources_state_set(hwdev, HINIC_RES_ACTIVE);
 	if (rc) {
@@ -851,7 +970,7 @@ int hinic_activate_hwdev_state(struct hinic_hwdev *hwdev)
  * hinic_deactivate_hwdev_state - Deactivate host nic state and notify mgmt
  * channel that host nic is not ready.
  * @hwdev: the pointer to the private hardware device object
- **/
+ */
 void hinic_deactivate_hwdev_state(struct hinic_hwdev *hwdev)
 {
 	int rc = HINIC_OK;
@@ -863,8 +982,7 @@ void hinic_deactivate_hwdev_state(struct hinic_hwdev *hwdev)
 	if (rc)
 		PMD_DRV_LOG(ERR, "Deinit resources state failed");
 
-	if (!HINIC_IS_VF(hwdev))
-		hinic_set_pf_status(hwdev->hwif, HINIC_PF_STATUS_INIT);
+	hinic_set_pf_status(hwdev->hwif, HINIC_PF_STATUS_INIT);
 }
 
 int hinic_get_board_info(void *hwdev, struct hinic_board_info *info)
@@ -898,7 +1016,7 @@ int hinic_get_board_info(void *hwdev, struct hinic_board_info *info)
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 int hinic_l2nic_reset(struct hinic_hwdev *hwdev)
 {
 	struct hinic_hwif *hwif = hwdev->hwif;
diff --git a/drivers/net/hinic/base/hinic_pmd_hwdev.h b/drivers/net/hinic/base/hinic_pmd_hwdev.h
index fc5bdf9..c37771b 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwdev.h
+++ b/drivers/net/hinic/base/hinic_pmd_hwdev.h
@@ -485,4 +485,8 @@ void hinic_hilink_async_event_handle(struct hinic_hwdev *hwdev, u8 cmd,
 
 int hinic_set_pagesize(void *hwdev, u8 page_size);
 
+void hinic_cpu_to_be32(void *data, u32 len);
+
+void hinic_be32_to_cpu(void *data, u32 len);
+
 #endif /* _HINIC_PMD_HWDEV_H_ */
diff --git a/drivers/net/hinic/base/hinic_pmd_hwif.c b/drivers/net/hinic/base/hinic_pmd_hwif.c
index a5e223b..8a01fbc 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwif.c
+++ b/drivers/net/hinic/base/hinic_pmd_hwif.c
@@ -13,6 +13,9 @@
 #define HINIC_INTR_MSI_BAR	2
 #define HINIC_DB_MEM_BAR	4
 
+#define PAGE_SIZE_4K		0x1000
+#define PAGE_SIZE_64K		0x10000
+
 #define	HINIC_MSIX_CNT_RESEND_TIMER_SHIFT	29
 #define	HINIC_MSIX_CNT_RESEND_TIMER_MASK	0x7U
 
@@ -24,17 +27,22 @@
  * hwif_ready - test if the HW initialization passed
  * @hwdev: the pointer to the private hardware device object
  * Return: 0 - success, negative - failure
- **/
+ */
 static int hwif_ready(struct hinic_hwdev *hwdev)
 {
-	u32 addr, attr1;
+	u32 addr, attr0, attr1;
 
 	addr   = HINIC_CSR_FUNC_ATTR1_ADDR;
 	attr1  = hinic_hwif_read_reg(hwdev->hwif, addr);
-
 	if (!HINIC_AF1_GET(attr1, MGMT_INIT_STATUS))
 		return -EBUSY;
 
+	addr   = HINIC_CSR_FUNC_ATTR0_ADDR;
+	attr0  = hinic_hwif_read_reg(hwdev->hwif, addr);
+	if ((HINIC_AF0_GET(attr0, FUNC_TYPE) == TYPE_VF) &&
+	     !HINIC_AF1_GET(attr1, PF_INIT_STATUS))
+		return -EBUSY;
+
 	return 0;
 }
 
@@ -44,7 +52,7 @@ static int hwif_ready(struct hinic_hwdev *hwdev)
  * @attr0: the first attribute that was read from the hw
  * @attr1: the second attribute that was read from the hw
  * @attr2: the third attribute that was read from the hw
- **/
+ */
 static void set_hwif_attr(struct hinic_hwif *hwif, u32 attr0, u32 attr1,
 			  u32 attr2)
 {
@@ -68,7 +76,7 @@ static void set_hwif_attr(struct hinic_hwif *hwif, u32 attr0, u32 attr1,
 /**
  * get_hwif_attr - read and set the attributes as members in hwif
  * @hwif: the hardware interface of a pci function device
- **/
+ */
 static void get_hwif_attr(struct hinic_hwif *hwif)
 {
 	u32 addr, attr0, attr1, attr2;
@@ -90,6 +98,11 @@ void hinic_set_pf_status(struct hinic_hwif *hwif, enum hinic_pf_status status)
 	u32 attr5 = HINIC_AF5_SET(status, PF_STATUS);
 	u32 addr  = HINIC_CSR_FUNC_ATTR5_ADDR;
 
+	if (hwif->attr.func_type == TYPE_VF) {
+		PMD_DRV_LOG(ERR, "VF doesn't support set attr5");
+		return;
+	}
+
 	hinic_hwif_write_reg(hwif, addr, attr5);
 }
 
@@ -145,7 +158,7 @@ void hinic_disable_doorbell(struct hinic_hwif *hwif)
 /**
  * set_ppf - try to set hwif as ppf and set the type of hwif in this case
  * @hwif: the hardware interface of a pci function device
- **/
+ */
 static void set_ppf(struct hinic_hwif *hwif)
 {
 	struct hinic_func_attr *attr = &hwif->attr;
@@ -285,6 +298,30 @@ static void disable_all_msix(struct hinic_hwdev *hwdev)
 		hinic_set_msix_state(hwdev, i, HINIC_MSIX_DISABLE);
 }
 
+/**
+ * Wait for up enable or disable doorbell flush finished.
+ * @hwif: the hardware interface of a pci function device.
+ * @states: Disable or Enable.
+ */
+int wait_until_doorbell_flush_states(struct hinic_hwif *hwif,
+					enum hinic_doorbell_ctrl states)
+{
+	unsigned long end;
+	enum hinic_doorbell_ctrl db_ctrl;
+
+	end = jiffies +
+		msecs_to_jiffies(HINIC_WAIT_DOORBELL_AND_OUTBOUND_TIMEOUT);
+	do {
+		db_ctrl = hinic_get_doorbell_ctrl_status(hwif);
+		if (db_ctrl == states)
+			return 0;
+
+		rte_delay_ms(1);
+	} while (time_before(jiffies, end));
+
+	return -EFAULT;
+}
+
 static int wait_until_doorbell_and_outbound_enabled(struct hinic_hwif *hwif)
 {
 	unsigned long end;
@@ -329,6 +366,17 @@ u8 hinic_ppf_idx(void *hwdev)
 }
 
 /**
+ * hinic_dma_attr_entry_num - get number id of DMA attribute table.
+ * @hwdev: the pointer to the private hardware device object.
+ * Return: The number id of DMA attribute table.
+ */
+u8 hinic_dma_attr_entry_num(void *hwdev)
+{
+	struct hinic_hwif *hwif = ((struct hinic_hwdev *)hwdev)->hwif;
+	return hwif->attr.num_dma_attr;
+}
+
+/**
  * hinic_init_hwif - initialize the hw interface
  * @hwdev: the pointer to the private hardware device object
  * @cfg_reg_base: base physical address of configuration registers
@@ -337,7 +385,7 @@ u8 hinic_ppf_idx(void *hwdev)
  * @db_base: base virtual address of doorbell registers
  * @dwqe_mapping: direct wqe io mapping address
  * Return: 0 - success, negative - failure
- **/
+ */
 static int hinic_init_hwif(struct hinic_hwdev *hwdev, void *cfg_reg_base,
 		    void *intr_reg_base, u64 db_base_phy,
 		    void *db_base, __rte_unused void *dwqe_mapping)
@@ -371,6 +419,9 @@ static int hinic_init_hwif(struct hinic_hwdev *hwdev, void *cfg_reg_base,
 	if (!HINIC_IS_VF(hwdev))
 		set_ppf(hwif);
 
+	/* disable mgmt cpu report any event */
+	hinic_set_pf_status(hwdev->hwif, HINIC_PF_STATUS_INIT);
+
 	return 0;
 
 hwif_ready_err:
@@ -403,10 +454,28 @@ static void hinic_get_mmio(struct hinic_hwdev *hwdev, void **cfg_regs_base,
 			   void **intr_base, void **db_base)
 {
 	struct rte_pci_device *pci_dev = hwdev->pcidev_hdl;
+	uint64_t bar0_size;
+	uint64_t bar2_size;
+	uint64_t bar0_phy_addr;
+	uint64_t pagesize = sysconf(_SC_PAGESIZE);
 
 	*cfg_regs_base = pci_dev->mem_resource[HINIC_CFG_REGS_BAR].addr;
 	*intr_base = pci_dev->mem_resource[HINIC_INTR_MSI_BAR].addr;
 	*db_base = pci_dev->mem_resource[HINIC_DB_MEM_BAR].addr;
+
+	bar0_size = pci_dev->mem_resource[HINIC_CFG_REGS_BAR].len;
+	bar2_size = pci_dev->mem_resource[HINIC_INTR_MSI_BAR].len;
+
+	if (pagesize == PAGE_SIZE_64K && (bar0_size % pagesize != 0)) {
+		bar0_phy_addr =
+			pci_dev->mem_resource[HINIC_CFG_REGS_BAR].phys_addr;
+		if (bar0_phy_addr % pagesize != 0 &&
+		(bar0_size + bar2_size <= pagesize) &&
+		bar2_size >= bar0_size) {
+			*cfg_regs_base = (void *)((uint8_t *)(*intr_base)
+				+ bar2_size);
+		}
+	}
 }
 
 void hinic_hwif_res_free(struct hinic_hwdev *hwdev)
@@ -459,7 +528,7 @@ int hinic_hwif_res_init(struct hinic_hwdev *hwdev)
  * @hwdev: the hardware interface of a nic device
  * @msix_idx: Index of msix interrupt
  * @clear_resend_en: enable flag of clear resend configuration
- **/
+ */
 void hinic_misx_intr_clear_resend_bit(void *hwdev, u16 msix_idx,
 				      u8 clear_resend_en)
 {
diff --git a/drivers/net/hinic/base/hinic_pmd_hwif.h b/drivers/net/hinic/base/hinic_pmd_hwif.h
index c1289b5..6752587 100644
--- a/drivers/net/hinic/base/hinic_pmd_hwif.h
+++ b/drivers/net/hinic/base/hinic_pmd_hwif.h
@@ -31,7 +31,7 @@ enum hinic_msix_state {
 	HINIC_MSIX_DISABLE,
 };
 
-/* Defines the IRQ information structure*/
+/* Defines the IRQ information structure */
 struct irq_info {
 	u16 msix_entry_idx; /* IRQ corresponding index number */
 	u32 irq_id;         /* the IRQ number from OS */
@@ -59,11 +59,11 @@ struct hinic_func_attr {
 
 	u8			ppf_idx;
 
-	u16			num_irqs;		/* max: 2 ^ 15 */
-	u8			num_aeqs;		/* max: 2 ^ 3 */
-	u8			num_ceqs;		/* max: 2 ^ 7 */
+	u16			num_irqs;	/* max: 2 ^ 15 */
+	u8			num_aeqs;	/* max: 2 ^ 3 */
+	u8			num_ceqs;	/* max: 2 ^ 7 */
 
-	u8			num_dma_attr;		/* max: 2 ^ 6 */
+	u8			num_dma_attr;	/* max: 2 ^ 6 */
 
 	u16			global_vf_id_of_pf;
 };
@@ -104,6 +104,9 @@ static inline u32 hinic_hwif_read_reg(struct hinic_hwif *hwif, u32 reg)
 
 void hinic_free_db_addr(void *hwdev, void __iomem *db_base);
 
+int wait_until_doorbell_flush_states(struct hinic_hwif *hwif,
+					enum hinic_doorbell_ctrl states);
+
 void hinic_set_msix_state(void *hwdev, u16 msix_idx,
 			  enum hinic_msix_state flag);
 
@@ -116,4 +119,6 @@ void hinic_misx_intr_clear_resend_bit(void *hwdev, u16 msix_idx,
 
 void hinic_hwif_res_free(struct hinic_hwdev *hwdev);
 
+u8 hinic_dma_attr_entry_num(void *hwdev);
+
 #endif /* _HINIC_PMD_HWIF_H_ */
diff --git a/drivers/net/hinic/base/hinic_pmd_mgmt.c b/drivers/net/hinic/base/hinic_pmd_mgmt.c
index a18e567..eee50a8 100644
--- a/drivers/net/hinic/base/hinic_pmd_mgmt.c
+++ b/drivers/net/hinic/base/hinic_pmd_mgmt.c
@@ -7,6 +7,7 @@
 #include "hinic_pmd_hwdev.h"
 #include "hinic_pmd_hwif.h"
 #include "hinic_pmd_mgmt.h"
+#include "hinic_pmd_mbox.h"
 
 #define BUF_OUT_DEFAULT_SIZE		1
 
@@ -72,7 +73,7 @@
  * mgmt_msg_len - calculate the total message length
  * @msg_data_len: the length of the message data
  * Return: the total message length
- **/
+ */
 static u16 mgmt_msg_len(u16 msg_data_len)
 {
 	/* u64 - the size of the header */
@@ -99,7 +100,7 @@ static u16 mgmt_msg_len(u16 msg_data_len)
  * @direction: the direction of the original message
  * @cmd: the command to do
  * @msg_id: message id
- **/
+ */
 static void prepare_header(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 			   u64 *header, int msg_len, enum hinic_mod_type mod,
 			   enum hinic_msg_ack_type ack_type,
@@ -128,7 +129,7 @@ static void prepare_header(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
  * @header: pointer of the header to prepare
  * @msg: the data of the message
  * @msg_len: the length of the message
- **/
+ */
 static void prepare_mgmt_cmd(u8 *mgmt_cmd, u64 *header, void *msg,
 			     int msg_len)
 {
@@ -149,7 +150,7 @@ static void prepare_mgmt_cmd(u8 *mgmt_cmd, u64 *header, void *msg,
  * alloc_recv_msg - allocate received message memory
  * @recv_msg: pointer that will hold the allocated data
  * Return: 0 - success, negative - failure
- **/
+ */
 static int alloc_recv_msg(struct hinic_recv_msg *recv_msg)
 {
 	int err;
@@ -177,7 +178,7 @@ static int alloc_recv_msg(struct hinic_recv_msg *recv_msg)
 /**
  * free_recv_msg - free received message memory
  * @recv_msg: pointer that holds the allocated data
- **/
+ */
 static void free_recv_msg(struct hinic_recv_msg *recv_msg)
 {
 	kfree(recv_msg->buf_out);
@@ -188,7 +189,7 @@ static void free_recv_msg(struct hinic_recv_msg *recv_msg)
  * alloc_msg_buf - allocate all the message buffers of PF to MGMT channel
  * @pf_to_mgmt: PF to MGMT channel
  * Return: 0 - success, negative - failure
- **/
+ */
 static int alloc_msg_buf(struct hinic_msg_pf_to_mgmt *pf_to_mgmt)
 {
 	int err;
@@ -237,7 +238,7 @@ static int alloc_msg_buf(struct hinic_msg_pf_to_mgmt *pf_to_mgmt)
  * free_msg_buf - free all the message buffers of PF to MGMT channel
  * @pf_to_mgmt: PF to MGMT channel
  * Return: 0 - success, negative - failure
- **/
+ */
 static void free_msg_buf(struct hinic_msg_pf_to_mgmt *pf_to_mgmt)
 {
 	kfree(pf_to_mgmt->sync_msg_buf);
@@ -257,7 +258,7 @@ static void free_msg_buf(struct hinic_msg_pf_to_mgmt *pf_to_mgmt)
  * @direction: the direction of the original message
  * @resp_msg_id: message id of response
  * Return: 0 - success, negative - failure
- **/
+ */
 static int send_msg_to_mgmt_async(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 				  enum hinic_mod_type mod, u8 cmd,
 				  void *msg, u16 msg_len,
@@ -295,7 +296,7 @@ static int send_msg_to_mgmt_async(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
  * @direction: the direction of the original message
  * @resp_msg_id: msg id to response for
  * Return: 0 - success, negative - failure
- **/
+ */
 static int send_msg_to_mgmt_sync(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 				 enum hinic_mod_type mod, u8 cmd,
 				 void *msg, u16 msg_len,
@@ -327,7 +328,7 @@ static int send_msg_to_mgmt_sync(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
  * hinic_pf_to_mgmt_init - initialize PF to MGMT channel
  * @hwdev: the pointer to the private hardware device object
  * Return: 0 - success, negative - failure
- **/
+ */
 static int hinic_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
 {
 	struct hinic_msg_pf_to_mgmt *pf_to_mgmt;
@@ -342,7 +343,7 @@ static int hinic_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
 	hwdev->pf_to_mgmt = pf_to_mgmt;
 	pf_to_mgmt->hwdev = hwdev;
 
-	err = hinic_mutex_init(&pf_to_mgmt->sync_msg_lock, NULL);
+	err = hinic_mutex_init(&pf_to_mgmt->sync_msg_mutex, NULL);
 	if (err)
 		goto mutex_init_err;
 
@@ -364,7 +365,7 @@ static int hinic_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
 	free_msg_buf(pf_to_mgmt);
 
 alloc_msg_buf_err:
-	hinic_mutex_destroy(&pf_to_mgmt->sync_msg_lock);
+	hinic_mutex_destroy(&pf_to_mgmt->sync_msg_mutex);
 
 mutex_init_err:
 	kfree(pf_to_mgmt);
@@ -375,14 +376,14 @@ static int hinic_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
 /**
  * hinic_pf_to_mgmt_free - free PF to MGMT channel
  * @hwdev: the pointer to the private hardware device object
- **/
+ */
 static void hinic_pf_to_mgmt_free(struct hinic_hwdev *hwdev)
 {
 	struct hinic_msg_pf_to_mgmt *pf_to_mgmt = hwdev->pf_to_mgmt;
 
 	hinic_api_cmd_free(pf_to_mgmt->cmd_chain);
 	free_msg_buf(pf_to_mgmt);
-	hinic_mutex_destroy(&pf_to_mgmt->sync_msg_lock);
+	hinic_mutex_destroy(&pf_to_mgmt->sync_msg_mutex);
 	kfree(pf_to_mgmt);
 }
 
@@ -396,7 +397,9 @@ static void hinic_pf_to_mgmt_free(struct hinic_hwdev *hwdev)
 	u32 timeo;
 	int err, i;
 
-	pthread_mutex_lock(&pf_to_mgmt->sync_msg_lock);
+	err = hinic_mutex_lock(&pf_to_mgmt->sync_msg_mutex);
+	if (err)
+		return err;
 
 	SYNC_MSG_ID_INC(pf_to_mgmt);
 	recv_msg = &pf_to_mgmt->recv_resp_msg_from_mgmt;
@@ -455,7 +458,7 @@ static void hinic_pf_to_mgmt_free(struct hinic_hwdev *hwdev)
 unlock_sync_msg:
 	if (err && out_size)
 		*out_size = 0;
-	pthread_mutex_unlock(&pf_to_mgmt->sync_msg_lock);
+	(void)hinic_mutex_unlock(&pf_to_mgmt->sync_msg_mutex);
 	return err;
 }
 
@@ -464,6 +467,9 @@ static int hinic_get_mgmt_channel_status(void *hwdev)
 	struct hinic_hwif *hwif = ((struct hinic_hwdev *)hwdev)->hwif;
 	u32 val;
 
+	if (hinic_func_type((struct hinic_hwdev *)hwdev) == TYPE_VF)
+		return false;
+
 	val = hinic_hwif_read_reg(hwif, HINIC_ICPL_RESERVD_ADDR);
 
 	return HINIC_GET_MGMT_CHANNEL_STATUS(val, MGMT_CHANNEL_STATUS);
@@ -482,9 +488,13 @@ int hinic_msg_to_mgmt_sync(void *hwdev, enum hinic_mod_type mod, u8 cmd,
 	if (hinic_get_mgmt_channel_status(hwdev))
 		return -EPERM;
 
-	rc = hinic_pf_to_mgmt_sync(hwdev, mod, cmd, buf_in,
-				   in_size, buf_out, out_size,
-				   timeout);
+	if (hinic_func_type(hwdev) == TYPE_VF) {
+		rc = hinic_mbox_to_pf(hwdev, mod, cmd, buf_in, in_size,
+					buf_out, out_size, timeout);
+	} else {
+		rc = hinic_pf_to_mgmt_sync(hwdev, mod, cmd, buf_in, in_size,
+						buf_out, out_size, timeout);
+	}
 
 	return rc;
 }
@@ -502,13 +512,15 @@ int hinic_msg_to_mgmt_no_ack(void *hwdev, enum hinic_mod_type mod, u8 cmd,
 		return err;
 	}
 
-	pthread_mutex_lock(&pf_to_mgmt->sync_msg_lock);
+	err = hinic_mutex_lock(&pf_to_mgmt->sync_msg_mutex);
+	if (err)
+		return err;
 
 	err = send_msg_to_mgmt_sync(pf_to_mgmt, mod, cmd, buf_in, in_size,
 				    HINIC_MSG_NO_ACK, HINIC_MSG_DIRECT_SEND,
 				    MSG_NO_RESP);
 
-	pthread_mutex_unlock(&pf_to_mgmt->sync_msg_lock);
+	(void)hinic_mutex_unlock(&pf_to_mgmt->sync_msg_mutex);
 
 	return err;
 }
@@ -537,7 +549,7 @@ static bool check_mgmt_seq_id_and_seg_len(struct hinic_recv_msg *recv_msg,
  * @pf_to_mgmt: PF to MGMT channel
  * @recv_msg: received message details
  * @param: customized parameter
- **/
+ */
 static void hinic_mgmt_recv_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 					struct hinic_recv_msg *recv_msg,
 					void *param)
@@ -589,7 +601,7 @@ static void hinic_mgmt_recv_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
  * @param: customized parameter
  * Return: 0 when aeq is response message, -1 default result,
  * and when wrong message or not last message
- **/
+ */
 static int recv_mgmt_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 				 u8 *header, struct hinic_recv_msg *recv_msg,
 				 void *param)
@@ -609,7 +621,7 @@ static int recv_mgmt_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 			"func id: 0x%x, front id: 0x%x, current id: 0x%x, seg len: 0x%x",
 			hinic_global_func_id(pf_to_mgmt->hwdev),
 			recv_msg->sed_id, seq_id, seq_len);
-		return HINIC_RECV_NEXT_AEQE;
+		return HINIC_ERROR;
 	}
 
 	dest_msg = (u8 *)recv_msg->msg + seq_id * HINIC_MSG_SEG_LEN;
@@ -617,7 +629,7 @@ static int recv_mgmt_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 	memcpy(dest_msg, msg_body, seq_len);
 
 	if (!HINIC_MSG_HEADER_GET(msg_header, LAST))
-		return HINIC_RECV_NEXT_AEQE;
+		return HINIC_ERROR;
 
 	recv_msg->cmd = HINIC_MSG_HEADER_GET(msg_header, CMD);
 	recv_msg->mod = HINIC_MSG_HEADER_GET(msg_header, MODULE);
@@ -627,11 +639,11 @@ static int recv_mgmt_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
 	recv_msg->msg_id = HINIC_MSG_HEADER_GET(msg_header, MSG_ID);
 
 	if (HINIC_MSG_HEADER_GET(msg_header, DIRECTION) == HINIC_MSG_RESPONSE)
-		return HINIC_RECV_DONE;
+		return HINIC_OK;
 
 	hinic_mgmt_recv_msg_handler(pf_to_mgmt, recv_msg, param);
 
-	return HINIC_RECV_NEXT_AEQE;
+	return HINIC_ERROR;
 }
 
 /**
@@ -642,7 +654,7 @@ static int recv_mgmt_msg_handler(struct hinic_msg_pf_to_mgmt *pf_to_mgmt,
  * @param: customized parameter
  * Return: 0 when aeq is response message,
  *	   -1 default result, and when wrong message or not last message
- **/
+ */
 static int hinic_mgmt_msg_aeqe_handler(void *hwdev, u8 *header,
 			__rte_unused u8 size, void *param)
 {
@@ -667,10 +679,13 @@ static int hinic_handle_aeqe(void *handle, enum hinic_aeq_type event,
 	case HINIC_MSG_FROM_MGMT_CPU:
 		rc = hinic_mgmt_msg_aeqe_handler(handle, data, size, param);
 		break;
+	case HINIC_MBX_FROM_FUNC:
+		rc = hinic_mbox_func_aeqe_handler(handle, data, size, param);
+		break;
 	default:
 		PMD_DRV_LOG(ERR, "Unknown event type: 0x%x, size: %d",
 			    event, size);
-		rc = HINIC_RECV_NEXT_AEQE;
+		rc = HINIC_ERROR;
 		break;
 	}
 
@@ -685,7 +700,7 @@ static int hinic_handle_aeqe(void *handle, enum hinic_aeq_type event,
  *           used in polling mode.
  * @param: customized parameter
  * Return: 0 - Success, EIO - poll timeout, ENODEV - swe not support
- **/
+ */
 int hinic_aeq_poll_msg(struct hinic_eq *eq, u32 timeout, void *param)
 {
 	struct hinic_aeq_elem *aeqe_pos;
@@ -753,6 +768,10 @@ int hinic_comm_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
 {
 	int rc;
 
+	/* VF do not support send msg to mgmt directly */
+	if (hinic_func_type(hwdev) == TYPE_VF)
+		return 0;
+
 	rc = hinic_pf_to_mgmt_init(hwdev);
 	if (rc)
 		return rc;
@@ -764,6 +783,10 @@ int hinic_comm_pf_to_mgmt_init(struct hinic_hwdev *hwdev)
 
 void hinic_comm_pf_to_mgmt_free(struct hinic_hwdev *hwdev)
 {
+	/* VF do not support send msg to mgmt directly */
+	if (hinic_func_type(hwdev) == TYPE_VF)
+		return;
+
 	hinic_pf_to_mgmt_free(hwdev);
 }
 
diff --git a/drivers/net/hinic/base/hinic_pmd_mgmt.h b/drivers/net/hinic/base/hinic_pmd_mgmt.h
index 7804708..cc18843 100644
--- a/drivers/net/hinic/base/hinic_pmd_mgmt.h
+++ b/drivers/net/hinic/base/hinic_pmd_mgmt.h
@@ -82,7 +82,7 @@ struct hinic_msg_pf_to_mgmt {
 	struct hinic_hwdev		*hwdev;
 
 	/* mutex for sync message */
-	pthread_mutex_t			sync_msg_lock;
+	pthread_mutex_t			sync_msg_mutex;
 
 	void				*async_msg_buf;
 	void				*sync_msg_buf;
diff --git a/drivers/net/hinic/base/hinic_pmd_niccfg.c b/drivers/net/hinic/base/hinic_pmd_niccfg.c
index 78012b8..d3bbc3d 100644
--- a/drivers/net/hinic/base/hinic_pmd_niccfg.c
+++ b/drivers/net/hinic/base/hinic_pmd_niccfg.c
@@ -10,6 +10,7 @@
 #include "hinic_pmd_mgmt.h"
 #include "hinic_pmd_cmdq.h"
 #include "hinic_pmd_niccfg.h"
+#include "hinic_pmd_mbox.h"
 
 #define l2nic_msg_to_mgmt_sync(hwdev, cmd, buf_in,		\
 			       in_size, buf_out, out_size)	\
@@ -17,6 +18,18 @@
 			buf_in, in_size,			\
 			buf_out, out_size, 0)
 
+/**
+ * hinic_init_function_table - Initialize function table.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param rx_buf_sz
+ *   Receive buffer size.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_init_function_table(void *hwdev, u16 rx_buf_sz)
 {
 	struct hinic_function_table function_table;
@@ -40,8 +53,8 @@ int hinic_init_function_table(void *hwdev, u16 rx_buf_sz)
 				     &function_table, &out_size, 0);
 	if (err || function_table.mgmt_msg_head.status || !out_size) {
 		PMD_DRV_LOG(ERR,
-			"Failed to init func table, ret = %d",
-			function_table.mgmt_msg_head.status);
+			"Failed to init func table, err: %d, status: 0x%x, out size: 0x%x",
+			err, function_table.mgmt_msg_head.status, out_size);
 		return -EFAULT;
 	}
 
@@ -49,13 +62,17 @@ int hinic_init_function_table(void *hwdev, u16 rx_buf_sz)
 }
 
 /**
- * hinic_get_base_qpn - get global number of queue
- * @hwdev: the hardware interface of a nic device
- * @global_qpn: vat page size
+ * hinic_get_base_qpn - Get global queue number.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param global_qpn
+ *   Global queue number.
+ *
  * @return
- *   0 on success,
+ *   0 on success.
  *   negative error value otherwise.
- **/
+ */
 int hinic_get_base_qpn(void *hwdev, u16 *global_qpn)
 {
 	struct hinic_cmd_qpn cmd_qpn;
@@ -77,8 +94,8 @@ int hinic_get_base_qpn(void *hwdev, u16 *global_qpn)
 				     &out_size, 0);
 	if (err || !out_size || cmd_qpn.mgmt_msg_head.status) {
 		PMD_DRV_LOG(ERR,
-			"Failed to get base qpn, status(%d)",
-			cmd_qpn.mgmt_msg_head.status);
+			"Failed to get base qpn, err: %d, status: 0x%x, out size: 0x%x",
+			err, cmd_qpn.mgmt_msg_head.status, out_size);
 		return -EINVAL;
 	}
 
@@ -89,12 +106,18 @@ int hinic_get_base_qpn(void *hwdev, u16 *global_qpn)
 
 /**
  * hinic_set_mac - Init mac_vlan table in NIC.
- * @hwdev: the hardware interface of a nic device
- * @mac_addr: mac address
- * @vlan_id: set 0 for mac_vlan table initialization
- * @func_id: global function id of NIC
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param mac_addr
+ *   MAC address.
+ * @param vlan_id
+ *   Set 0 for mac_vlan table initialization.
+ * @param func_id
+ *   Global function id of NIC.
+ *
  * @return
- *   0 on success and stats is filled,
+ *   0 on success.
  *   negative error value otherwise.
  */
 int hinic_set_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
@@ -122,6 +145,7 @@ int hinic_set_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
 			err, mac_info.mgmt_msg_head.status, out_size);
 		return -EINVAL;
 	}
+
 	if (mac_info.mgmt_msg_head.status == HINIC_PF_SET_VF_ALREADY) {
 		PMD_DRV_LOG(WARNING, "PF has already set vf mac, Ignore set operation.");
 		return HINIC_PF_SET_VF_ALREADY;
@@ -132,16 +156,21 @@ int hinic_set_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
 
 /**
  * hinic_del_mac - Uninit mac_vlan table in NIC.
- * @hwdev: the hardware interface of a nic device
- * @mac_addr: mac address
- * @vlan_id: set 0 for mac_vlan table initialization
- * @func_id: global function id of NIC
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param mac_addr
+ *   MAC address.
+ * @param vlan_id
+ *   Set 0 for mac_vlan table initialization.
+ * @param func_id
+ *   Global function id of NIC.
+ *
  * @return
- *   0 on success and stats is filled,
+ *   0 on success.
  *   negative error value otherwise.
  */
-int hinic_del_mac(void *hwdev, u8 *mac_addr, u16 vlan_id,
-		  u16 func_id)
+int hinic_del_mac(void *hwdev, u8 *mac_addr, u16 vlan_id, u16 func_id)
 {
 	struct hinic_port_mac_set mac_info;
 	u16 out_size = sizeof(mac_info);
@@ -179,6 +208,18 @@ int hinic_del_mac(void *hwdev, u8 *mac_addr, u16 vlan_id,
 	return 0;
 }
 
+/**
+ * hinic_get_default_mac - Get default mac address from hardware.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param mac_addr
+ *   MAC address.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_get_default_mac(void *hwdev, u8 *mac_addr)
 {
 	struct hinic_port_mac_set mac_info;
@@ -208,6 +249,18 @@ int hinic_get_default_mac(void *hwdev, u8 *mac_addr)
 	return 0;
 }
 
+/**
+ * hinic_set_port_mtu -  Set MTU to port.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param new_mtu
+ *   MTU size.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_set_port_mtu(void *hwdev, u32 new_mtu)
 {
 	struct hinic_mtu mtu_info;
@@ -236,6 +289,18 @@ int hinic_set_port_mtu(void *hwdev, u32 new_mtu)
 	return 0;
 }
 
+/**
+ * hinic_get_link_status - Get link status from hardware.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param link_state
+ *   Link status.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_get_link_status(void *hwdev, u8 *link_state)
 {
 	struct hinic_get_link get_link;
@@ -267,10 +332,16 @@ int hinic_get_link_status(void *hwdev, u8 *link_state)
 
 /**
  * hinic_set_vport_enable - Notify firmware that driver is ready or not.
- * @hwdev: the hardware interface of a nic device
- * @enable: 1: driver is ready; 0: driver is not ok.
- * Return: 0 on success and state is filled, negative error value otherwise.
- **/
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param enable
+ *   1: driver is ready; 0: driver is not ok.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_set_vport_enable(void *hwdev, bool enable)
 {
 	struct hinic_vport_state en_state;
@@ -300,11 +371,15 @@ int hinic_set_vport_enable(void *hwdev, bool enable)
 }
 
 /**
- * hinic_set_port_enable - open MAG to receive packets.
- * @hwdev: the hardware interface of a nic device
- * @enable: 1: open MAG; 0: close MAG.
+ * hinic_set_port_enable - Open MAG to receive packets.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param enable
+ *   1: open MAG; 0: close MAG.
+ *
  * @return
- *   0 on success and stats is filled,
+ *   0 on success.
  *   negative error value otherwise.
  */
 int hinic_set_port_enable(void *hwdev, bool enable)
@@ -318,6 +393,9 @@ int hinic_set_port_enable(void *hwdev, bool enable)
 		return -EINVAL;
 	}
 
+	if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
+		return 0;
+
 	memset(&en_state, 0, sizeof(en_state));
 	en_state.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
 	en_state.state = (enable ? HINIC_PORT_ENABLE : HINIC_PORT_DISABLE);
@@ -432,7 +510,7 @@ int hinic_dcb_set_ets(void *hwdev, u8 *up_tc, u8 *pg_bw,
 
 	memset(&ets, 0, sizeof(ets));
 	ets.mgmt_msg_head.resp_aeq_num = HINIC_AEQ1;
-	ets.port_id = 0;    /* reserved */
+	ets.port_id = 0;	/* reserved */
 	memcpy(ets.up_tc, up_tc, HINIC_DCB_TC_MAX);
 	memcpy(ets.pg_bw, pg_bw, HINIC_DCB_UP_MAX);
 	memcpy(ets.pgid, pgid, HINIC_DCB_UP_MAX);
@@ -672,12 +750,17 @@ int hinic_rss_get_template_tbl(void *hwdev, u32 tmpl_idx, u8 *temp)
 }
 
 /**
- * hinic_rss_set_hash_engine - Init rss hash function .
- * @hwdev: the hardware interface of a nic device
- * @tmpl_idx: index of rss template from NIC.
- * @type: hash function, such as Toeplitz or XOR.
+ * hinic_rss_set_hash_engine - Init rss hash function.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param tmpl_idx
+ *   Index of rss template from NIC.
+ * @param type
+ *   Hash function, such as Toeplitz or XOR.
+ *
  * @return
- *   0 on success and stats is filled,
+ *   0 on success.
  *   negative error value otherwise.
  */
 int hinic_rss_set_hash_engine(void *hwdev, u8 tmpl_idx, u8 type)
@@ -845,12 +928,18 @@ int hinic_rss_cfg(void *hwdev, u8 rss_en, u8 tmpl_idx, u8 tc_num, u8 *prio_tc)
 }
 
 /**
- * hinic_rss_template_alloc - get rss template id from the chip,
- *			      all functions share 96 templates.
- * @hwdev: the pointer to the private hardware device object
- * @tmpl_idx: index of rss template from chip.
- * Return: 0 on success and stats is filled, negative error value otherwise.
- **/
+ * hinic_rss_template_alloc - Get rss template id from the chip,
+ * all functions share 96 templates.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param tmpl_idx
+ *   Index of rss template from chip.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_rss_template_alloc(void *hwdev, u8 *tmpl_idx)
 {
 	struct hinic_rss_template_mgmt template_mgmt;
@@ -882,11 +971,17 @@ int hinic_rss_template_alloc(void *hwdev, u8 *tmpl_idx)
 }
 
 /**
- * hinic_rss_template_alloc - free rss template id to the chip
- * @hwdev: the hardware interface of a nic device
- * @tmpl_idx: index of rss template from NIC.
- * Return: 0 on success and stats is filled, negative error value otherwise.
- **/
+ * hinic_rss_template_free - Free rss template id to the chip.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param tmpl_idx
+ *   Index of rss template from chip.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_rss_template_free(void *hwdev, u8 tmpl_idx)
 {
 	struct hinic_rss_template_mgmt template_mgmt;
@@ -917,12 +1012,17 @@ int hinic_rss_template_free(void *hwdev, u8 tmpl_idx)
 }
 
 /**
- * hinic_set_rx_vhd_mode - change rx buffer size after initialization,
- * @hwdev: the hardware interface of a nic device
- * @mode: not needed.
- * @rx_buf_sz: receive buffer size.
+ * hinic_set_rx_vhd_mode - Change rx buffer size after initialization.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ * @param vhd_mode
+ *   Not needed.
+ * @param rx_buf_sz
+ *   receive buffer size.
+ *
  * @return
- *   0 on success and stats is filled,
+ *   0 on success.
  *   negative error value otherwise.
  */
 int hinic_set_rx_vhd_mode(void *hwdev, u16 vhd_mode, u16 rx_buf_sz)
@@ -1100,6 +1200,54 @@ int hinic_reset_port_link_cfg(void *hwdev)
 	return 0;
 }
 
+/**
+ * hinic_vf_func_init - Register VF to PF.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
+int hinic_vf_func_init(struct hinic_hwdev *hwdev)
+{
+	int err, state = 0;
+
+	if (!HINIC_IS_VF(hwdev))
+		return 0;
+
+	err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
+			HINIC_PORT_CMD_VF_REGISTER, &state, sizeof(state),
+			NULL, NULL, 0);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Fail to register vf");
+		return err;
+	}
+
+	return 0;
+}
+
+/**
+ * hinic_vf_func_free - Unregister VF from PF.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ */
+void hinic_vf_func_free(struct hinic_hwdev *hwdev)
+{
+	int err;
+
+	if (hinic_func_type(hwdev) != TYPE_VF)
+		return;
+
+	err = hinic_mbox_to_pf(hwdev, HINIC_MOD_L2NIC,
+				HINIC_PORT_CMD_VF_UNREGISTER, &err, sizeof(err),
+				NULL, NULL, 0);
+	if (err)
+		PMD_DRV_LOG(ERR, "Fail to unregister VF, err: %d", err);
+}
+
 int hinic_set_fast_recycle_mode(void *hwdev, u8 mode)
 {
 	struct hinic_fast_recycled_mode fast_recycled_mode;
@@ -1199,6 +1347,9 @@ int hinic_set_link_status_follow(void *hwdev,
 	if (!hwdev)
 		return -EINVAL;
 
+	if (HINIC_IS_VF((struct hinic_hwdev *)hwdev))
+		return 0;
+
 	if (status >= HINIC_LINK_FOLLOW_STATUS_MAX) {
 		PMD_DRV_LOG(ERR,
 			"Invalid link follow status: %d", status);
@@ -1254,11 +1405,16 @@ int hinic_get_link_mode(void *hwdev, u32 *supported, u32 *advertised)
 }
 
 /**
- * hinic_flush_qp_res - Flush tx && rx chip resources in case of set vport fake
- * failed when device start.
- * @hwdev: the hardware interface of a nic device
- * Return: 0 on success, negative error value otherwise.
- **/
+ * hinic_flush_qp_res - Flush tx && rx chip resources in case of set vport
+ * fake failed when device start.
+ *
+ * @param hwdev
+ *   The hardware interface of a nic device.
+ *
+ * @return
+ *   0 on success.
+ *   negative error value otherwise.
+ */
 int hinic_flush_qp_res(void *hwdev)
 {
 	struct hinic_clear_qp_resource qp_res;
diff --git a/drivers/net/hinic/base/hinic_pmd_niccfg.h b/drivers/net/hinic/base/hinic_pmd_niccfg.h
index 174b40f..dcb9602 100644
--- a/drivers/net/hinic/base/hinic_pmd_niccfg.h
+++ b/drivers/net/hinic/base/hinic_pmd_niccfg.h
@@ -655,4 +655,8 @@ int hinic_set_link_status_follow(void *hwdev,
 
 int hinic_clear_phy_port_stats(struct hinic_hwdev *hwdev);
 
+int hinic_vf_func_init(struct hinic_hwdev *hwdev);
+
+void hinic_vf_func_free(struct hinic_hwdev *hwdev);
+
 #endif /* _HINIC_PMD_NICCFG_H_ */
diff --git a/drivers/net/hinic/base/hinic_pmd_nicio.c b/drivers/net/hinic/base/hinic_pmd_nicio.c
index 248211f..f6cc033 100644
--- a/drivers/net/hinic/base/hinic_pmd_nicio.c
+++ b/drivers/net/hinic/base/hinic_pmd_nicio.c
@@ -442,7 +442,7 @@ static int clean_qp_offload_ctxt(struct hinic_nic_io *nic_io)
  * @rx_buf_sz: receive buffer size
  * @return
  *   hw rx buffer size
- **/
+ */
 static u16 get_hw_rx_buf_size(u32 rx_buf_sz)
 {
 	u16 num_hw_types = sizeof(hinic_hw_rx_buf_size)
@@ -466,7 +466,7 @@ static u16 get_hw_rx_buf_size(u32 rx_buf_sz)
  * @sq_depth: the depth of transmit queue
  * @rx_buf_sz: receive buffer size from app
  * Return: 0 on success, negative error value otherwise.
- **/
+ */
 static int
 hinic_set_root_ctxt(void *hwdev, u16 rq_depth, u16 sq_depth, int rx_buf_sz)
 {
@@ -495,7 +495,7 @@ static u16 get_hw_rx_buf_size(u32 rx_buf_sz)
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 static int hinic_clean_root_ctxt(void *hwdev)
 {
 	struct hinic_root_ctxt root_ctxt;
@@ -618,6 +618,12 @@ static int hinic_init_nic_hwdev(struct hinic_hwdev *hwdev)
 		goto err_init_nic_hwdev;
 	}
 
+	err = hinic_vf_func_init(hwdev);
+	if (err) {
+		PMD_DRV_LOG(ERR, "Failed to init nic mbox");
+		goto err_init_nic_hwdev;
+	}
+
 	err = hinic_set_fast_recycle_mode(hwdev, RECYCLE_MODE_DPDK);
 	if (err) {
 		PMD_DRV_LOG(ERR, "Failed to set fast recycle mode");
@@ -632,6 +638,7 @@ static int hinic_init_nic_hwdev(struct hinic_hwdev *hwdev)
 
 static void hinic_free_nic_hwdev(struct hinic_hwdev *hwdev)
 {
+	hinic_vf_func_free(hwdev);
 	hwdev->nic_io = NULL;
 }
 
@@ -861,7 +868,7 @@ void hinic_deinit_nicio(struct hinic_hwdev *hwdev)
  * @return
  *   0 on success,
  *   negative error value otherwise.
- **/
+ */
 int hinic_convert_rx_buf_size(u32 rx_buf_sz, u32 *match_sz)
 {
 	u32 i, num_hw_types, best_match_sz;
diff --git a/drivers/net/hinic/base/hinic_pmd_nicio.h b/drivers/net/hinic/base/hinic_pmd_nicio.h
index 487e440..9a487d0 100644
--- a/drivers/net/hinic/base/hinic_pmd_nicio.h
+++ b/drivers/net/hinic/base/hinic_pmd_nicio.h
@@ -217,7 +217,7 @@ struct hinic_nic_io {
 	u16			vhd_mode;
 
 	struct hinic_qp		*qps;
-	/* sq ci mem base addr of the function*/
+	/* sq ci mem base addr of the function */
 	void			*ci_vaddr_base;
 	dma_addr_t		ci_dma_base;
 
@@ -229,7 +229,6 @@ struct hinic_sq_db {
 	u32	db_info;
 };
 
-
 int hinic_init_qp_ctxts(struct hinic_hwdev *hwdev);
 
 void hinic_free_qp_ctxts(struct hinic_hwdev *hwdev);
-- 
1.8.3.1


  parent reply	other threads:[~2019-09-30 13:46 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-30 14:00 [dpdk-dev] [PATCH v3 00/19] Add advanced features for Huawei hinic pmd Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 01/19] net/hinic/base: add mbox command channel for SRIOV Xiaoyun wang
2019-09-30 14:00 ` Xiaoyun wang [this message]
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 03/19] net/hinic: add VF PMD operation interfaces Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 04/19] net/hinic: add VLAN filter and offload Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 05/19] net/hinic: add allmulticast mode and MTU set Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 06/19] net/hinic: add unicast and multicast MAC set Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 07/19] net/hinic/base: add fdir config interface Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 08/19] net/hinic: add fdir validate flow operations Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 09/19] net/hinic: create and destroy ntuple filter Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 10/19] net/hinic: create and destroy fdir filter Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 11/19] net/hinic: flush " Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 12/19] net/hinic: set link down and up Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 13/19] net/hinic: get firmware version Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 14/19] net/hinic: support inner L3 checksum offload Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 15/19] net/hinic: support LRO offload Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 16/19] net/hinic: add hinic PMD doc files Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 17/19] net/hinic/base: optimize aeq interfaces Xiaoyun wang
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 18/19] net/hinic: optimize RX performance Xiaoyun wang
2019-09-30 15:10   ` Ferruh Yigit
2019-10-08 15:19     ` Wangxiaoyun (Cloud, Network Chip Application Development Dept)
2019-09-30 14:00 ` [dpdk-dev] [PATCH v3 19/19] net/hinic: add support for getting rxq or txq info Xiaoyun wang
2019-09-30 15:06 ` [dpdk-dev] [PATCH v3 00/19] Add advanced features for Huawei hinic pmd Ferruh Yigit
2019-10-08 15:14   ` Wangxiaoyun (Cloud, Network Chip Application Development Dept)
2019-10-08 15:33     ` Ferruh Yigit
2019-10-11  2:50       ` Wangxiaoyun (Cloud, Network Chip Application Development Dept)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=f0c5bbb8799acfbde0368c44043d1016c1470564.1569850827.git.cloud.wangxiaoyun@huawei.com \
    --to=cloud.wangxiaoyun@huawei.com \
    --cc=dev@dpdk.org \
    --cc=ferruh.yigit@intel.com \
    --cc=luoxianjun@huawei.com \
    --cc=shahar.belkar@huawei.com \
    --cc=tanya.brokhman@huawei.com \
    --cc=wulike1@huawei.com \
    --cc=xuanziyang2@huawei.com \
    --cc=zhouguoyang@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).