DPDK patches and discussions
 help / color / mirror / Atom feed
From: Jie Hai <haijie1@huawei.com>
To: <dev@dpdk.org>, Yisen Zhuang <yisen.zhuang@huawei.com>,
	"Min Hu (Connor)" <humin29@huawei.com>,
	"Wei Hu (Xavier)" <xavier.huwei@huawei.com>,
	Chunsong Feng <fengchunsong@huawei.com>,
	Huisong Li <lihuisong@huawei.com>, Hao Chen <chenh@yusur.tech>
Subject: [PATCH 3/5] net/hns3: refactor PF mailbox message struct
Date: Wed, 8 Nov 2023 11:44:32 +0800	[thread overview]
Message-ID: <20231108034434.559030-4-haijie1@huawei.com> (raw)
In-Reply-To: <20231108034434.559030-1-haijie1@huawei.com>

From: Dengdui Huang <huangdengdui@huawei.com>

The data region in PF to VF mbx memssage command is used
to communicate with VF driver. And this data region exists
as an array. As a result, some complicated feature commands,
like mailbox response, link change event, close promisc mode,
reset request and update pvid state, have to use magic number
to set them. This isn't good for maintenance of driver. So
this patch refactors these messages by extracting an
hns3_pf_to_vf_msg structure.

Fixes: 463e748964f5 ("net/hns3: support mailbox")
Cc: stable@dpdk.org

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Signed-off-by: Jie Hai <haijie1@huawei.com>
---
 drivers/net/hns3/hns3_mbx.c | 38 ++++++++++++++++++-------------------
 drivers/net/hns3/hns3_mbx.h | 25 +++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 20 deletions(-)

diff --git a/drivers/net/hns3/hns3_mbx.c b/drivers/net/hns3/hns3_mbx.c
index ad5ec555b39e..c90f5d59ba21 100644
--- a/drivers/net/hns3/hns3_mbx.c
+++ b/drivers/net/hns3/hns3_mbx.c
@@ -192,17 +192,17 @@ static void
 hns3vf_handle_link_change_event(struct hns3_hw *hw,
 				struct hns3_mbx_pf_to_vf_cmd *req)
 {
+	struct hns3_mbx_link_status *link_info =
+		(struct hns3_mbx_link_status *)req->msg.msg_data;
 	uint8_t link_status, link_duplex;
-	uint16_t *msg_q = req->msg;
 	uint8_t support_push_lsc;
 	uint32_t link_speed;
 
-	memcpy(&link_speed, &msg_q[2], sizeof(link_speed));
-	link_status = rte_le_to_cpu_16(msg_q[1]);
-	link_duplex = (uint8_t)rte_le_to_cpu_16(msg_q[4]);
-	hns3vf_update_link_status(hw, link_status, link_speed,
-				  link_duplex);
-	support_push_lsc = (*(uint8_t *)&msg_q[5]) & 1u;
+	link_status = (uint8_t)rte_le_to_cpu_16(link_info->link_status);
+	link_speed = rte_le_to_cpu_32(link_info->speed);
+	link_duplex = (uint8_t)rte_le_to_cpu_16(link_info->duplex);
+	hns3vf_update_link_status(hw, link_status, link_speed, link_duplex);
+	support_push_lsc = (link_info->flag) & 1u;
 	hns3vf_update_push_lsc_cap(hw, support_push_lsc);
 }
 
@@ -211,7 +211,6 @@ hns3_handle_asserting_reset(struct hns3_hw *hw,
 			    struct hns3_mbx_pf_to_vf_cmd *req)
 {
 	enum hns3_reset_level reset_level;
-	uint16_t *msg_q = req->msg;
 
 	/*
 	 * PF has asserted reset hence VF should go in pending
@@ -219,7 +218,7 @@ hns3_handle_asserting_reset(struct hns3_hw *hw,
 	 * has been completely reset. After this stack should
 	 * eventually be re-initialized.
 	 */
-	reset_level = rte_le_to_cpu_16(msg_q[1]);
+	reset_level = rte_le_to_cpu_16(req->msg.reset_level);
 	hns3_atomic_set_bit(reset_level, &hw->reset.pending);
 
 	hns3_warn(hw, "PF inform reset level %d", reset_level);
@@ -241,8 +240,9 @@ hns3_handle_mbx_response(struct hns3_hw *hw, struct hns3_mbx_pf_to_vf_cmd *req)
 		 * to match the request.
 		 */
 		if (req->match_id == resp->match_id) {
-			resp->resp_status = hns3_resp_to_errno(req->msg[3]);
-			memcpy(resp->additional_info, &req->msg[4],
+			resp->resp_status =
+				hns3_resp_to_errno(req->msg.resp_status);
+			memcpy(resp->additional_info, &req->msg.resp_data,
 			       HNS3_MBX_MAX_RESP_DATA_SIZE);
 			rte_io_wmb();
 			resp->received_match_resp = true;
@@ -255,7 +255,8 @@ hns3_handle_mbx_response(struct hns3_hw *hw, struct hns3_mbx_pf_to_vf_cmd *req)
 	 * support copy request's match_id to its response. So VF follows the
 	 * original scheme to process.
 	 */
-	msg_data = (uint32_t)req->msg[1] << HNS3_MBX_RESP_CODE_OFFSET | req->msg[2];
+	msg_data = (uint32_t)req->msg.vf_mbx_msg_code <<
+			HNS3_MBX_RESP_CODE_OFFSET | req->msg.vf_mbx_msg_subcode;
 	if (resp->req_msg_data != msg_data) {
 		hns3_warn(hw,
 			"received response tag (%u) is mismatched with requested tag (%u)",
@@ -263,8 +264,8 @@ hns3_handle_mbx_response(struct hns3_hw *hw, struct hns3_mbx_pf_to_vf_cmd *req)
 		return;
 	}
 
-	resp->resp_status = hns3_resp_to_errno(req->msg[3]);
-	memcpy(resp->additional_info, &req->msg[4],
+	resp->resp_status = hns3_resp_to_errno(req->msg.resp_status);
+	memcpy(resp->additional_info, &req->msg.resp_data,
 	       HNS3_MBX_MAX_RESP_DATA_SIZE);
 	rte_io_wmb();
 	resp->received_match_resp = true;
@@ -305,8 +306,7 @@ static void
 hns3_update_port_base_vlan_info(struct hns3_hw *hw,
 				struct hns3_mbx_pf_to_vf_cmd *req)
 {
-#define PVID_STATE_OFFSET	1
-	uint16_t new_pvid_state = req->msg[PVID_STATE_OFFSET] ?
+	uint16_t new_pvid_state = req->msg.pvid_state ?
 		HNS3_PORT_BASE_VLAN_ENABLE : HNS3_PORT_BASE_VLAN_DISABLE;
 	/*
 	 * Currently, hardware doesn't support more than two layers VLAN offload
@@ -355,7 +355,7 @@ hns3_handle_mbx_msg_out_intr(struct hns3_hw *hw)
 	while (next_to_use != tail) {
 		desc = &crq->desc[next_to_use];
 		req = (struct hns3_mbx_pf_to_vf_cmd *)desc->data;
-		opcode = req->msg[0] & 0xff;
+		opcode = req->msg.code & 0xff;
 
 		flag = rte_le_to_cpu_16(crq->desc[next_to_use].flag);
 		if (!hns3_get_bit(flag, HNS3_CMDQ_RX_OUTVLD_B))
@@ -428,7 +428,7 @@ hns3_dev_handle_mbx_msg(struct hns3_hw *hw)
 
 		desc = &crq->desc[crq->next_to_use];
 		req = (struct hns3_mbx_pf_to_vf_cmd *)desc->data;
-		opcode = req->msg[0] & 0xff;
+		opcode = req->msg.code & 0xff;
 
 		flag = rte_le_to_cpu_16(crq->desc[crq->next_to_use].flag);
 		if (unlikely(!hns3_get_bit(flag, HNS3_CMDQ_RX_OUTVLD_B))) {
@@ -484,7 +484,7 @@ hns3_dev_handle_mbx_msg(struct hns3_hw *hw)
 			 * hns3 PF kernel driver, VF driver will receive this
 			 * mailbox message from PF driver.
 			 */
-			hns3_handle_promisc_info(hw, req->msg[1]);
+			hns3_handle_promisc_info(hw, req->msg.promisc_en);
 			break;
 		default:
 			hns3_err(hw, "received unsupported(%u) mbx msg",
diff --git a/drivers/net/hns3/hns3_mbx.h b/drivers/net/hns3/hns3_mbx.h
index 3f623ba64ca4..64f30d2923ea 100644
--- a/drivers/net/hns3/hns3_mbx.h
+++ b/drivers/net/hns3/hns3_mbx.h
@@ -118,6 +118,13 @@ struct hns3_mbx_vlan_filter {
 	uint16_t vlan_id;
 	uint16_t proto;
 };
+
+struct hns3_mbx_link_status {
+	uint16_t link_status;
+	uint32_t speed;
+	uint16_t duplex;
+	uint8_t flag;
+};
 #pragma pack()
 
 #define HNS3_MBX_MSG_MAX_DATA_SIZE	14
@@ -148,6 +155,22 @@ struct hns3_vf_to_pf_msg {
 	};
 };
 
+struct hns3_pf_to_vf_msg {
+	uint16_t code;
+	union {
+		struct {
+			uint16_t vf_mbx_msg_code;
+			uint16_t vf_mbx_msg_subcode;
+			uint16_t resp_status;
+			uint8_t resp_data[HNS3_MBX_MAX_RESP_DATA_SIZE];
+		};
+		uint16_t promisc_en;
+		uint16_t reset_level;
+		uint16_t pvid_state;
+		uint8_t msg_data[HNS3_MBX_MSG_MAX_DATA_SIZE];
+	};
+};
+
 struct errno_respcode_map {
 	uint16_t resp_code;
 	int err_no;
@@ -172,7 +195,7 @@ struct hns3_mbx_pf_to_vf_cmd {
 	uint8_t msg_len;
 	uint8_t rsv1;
 	uint16_t match_id;
-	uint16_t msg[8];
+	struct hns3_pf_to_vf_msg msg;
 };
 
 struct hns3_pf_rst_done_cmd {
-- 
2.30.0


  parent reply	other threads:[~2023-11-08  3:49 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-08  3:44 [PATCH 0/5] net/hns3: fix and refactor mailbox code Jie Hai
2023-11-08  3:44 ` [PATCH 1/5] net/hns3: fix sync mailbox failure forever Jie Hai
2023-11-08  3:44 ` [PATCH 2/5] net/hns3: refactor VF mailbox message struct Jie Hai
2023-11-09 18:51   ` Ferruh Yigit
2023-11-08  3:44 ` Jie Hai [this message]
2023-11-08  3:44 ` [PATCH 4/5] net/hns3: refactor send mailbox function Jie Hai
2023-11-08  3:44 ` [PATCH 5/5] net/hns3: refactor handle " Jie Hai
2023-11-09 18:50 ` [PATCH 0/5] net/hns3: fix and refactor mailbox code Ferruh Yigit
2023-11-10  6:21   ` Jie Hai
2023-11-10 12:35     ` Ferruh Yigit
2023-11-10  6:13 ` [PATCH v2 0/6] net/hns3: fix and refactor some codes Jie Hai
2023-11-10  6:13   ` [PATCH v2 1/6] net/hns3: fix sync mailbox failure forever Jie Hai
2023-11-10  6:13   ` [PATCH v2 2/6] net/hns3: use stdatomic API Jie Hai
2023-11-10  6:13   ` [PATCH v2 3/6] net/hns3: refactor VF mailbox message struct Jie Hai
2023-11-10  6:13   ` [PATCH v2 4/6] net/hns3: refactor PF " Jie Hai
2023-11-10  6:13   ` [PATCH v2 5/6] net/hns3: refactor send mailbox function Jie Hai
2023-11-10 16:23     ` Ferruh Yigit
2023-11-10  6:13   ` [PATCH v2 6/6] net/hns3: refactor handle " Jie Hai
2023-11-10 16:12   ` [PATCH v2 0/6] net/hns3: fix and refactor some codes Ferruh Yigit
2023-12-07  1:37 ` [PATCH v3 0/4] net/hns3: refactor mailbox Jie Hai
2023-12-07  1:37   ` [PATCH v3 1/4] net/hns3: refactor VF mailbox message struct Jie Hai
2023-12-07 12:47     ` Ferruh Yigit
2023-12-07  1:37   ` [PATCH v3 2/4] net/hns3: refactor PF " Jie Hai
2023-12-07  1:37   ` [PATCH v3 3/4] net/hns3: refactor send mailbox function Jie Hai
2023-12-07  1:37   ` [PATCH v3 4/4] net/hns3: refactor handle " Jie Hai
2023-12-07 12:31   ` [PATCH v3 0/4] net/hns3: refactor mailbox Ferruh Yigit
2023-12-08  1:06     ` Jie Hai
2023-12-08  6:55 ` [PATCH v4 " Jie Hai
2023-12-08  6:55   ` [PATCH v4 1/4] net/hns3: refactor VF mailbox message struct Jie Hai
2023-12-08  6:55   ` [PATCH v4 2/4] net/hns3: refactor PF " Jie Hai
2023-12-08  6:55   ` [PATCH v4 3/4] net/hns3: refactor send mailbox function Jie Hai
2023-12-08  6:55   ` [PATCH v4 4/4] net/hns3: refactor handle " Jie Hai
2023-12-08 10:48   ` [PATCH v4 0/4] net/hns3: refactor mailbox Ferruh Yigit

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=20231108034434.559030-4-haijie1@huawei.com \
    --to=haijie1@huawei.com \
    --cc=chenh@yusur.tech \
    --cc=dev@dpdk.org \
    --cc=fengchunsong@huawei.com \
    --cc=humin29@huawei.com \
    --cc=lihuisong@huawei.com \
    --cc=xavier.huwei@huawei.com \
    --cc=yisen.zhuang@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).