From patchwork Fri Dec 8 06:55:08 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jie Hai X-Patchwork-Id: 134951 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 7DE20436A6; Fri, 8 Dec 2023 08:09:26 +0100 (CET) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 55A6E42FE3; Fri, 8 Dec 2023 08:09:05 +0100 (CET) Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mails.dpdk.org (Postfix) with ESMTP id 9A1EA42FBF for ; Fri, 8 Dec 2023 08:09:01 +0100 (CET) Received: from kwepemd100004.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4Smhwk3kcHz1Q6RX; Fri, 8 Dec 2023 15:05:10 +0800 (CST) Received: from localhost.localdomain (10.67.165.2) by kwepemd100004.china.huawei.com (7.221.188.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.2.1258.28; Fri, 8 Dec 2023 15:08:59 +0800 From: Jie Hai To: , Yisen Zhuang , "Min Hu (Connor)" , Chunsong Feng , "Wei Hu (Xavier)" , Huisong Li , Hao Chen , Hongbo Zheng CC: , , Subject: [PATCH v4 4/4] net/hns3: refactor handle mailbox function Date: Fri, 8 Dec 2023 14:55:08 +0800 Message-ID: <20231208065508.1663412-5-haijie1@huawei.com> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20231208065508.1663412-1-haijie1@huawei.com> References: <20231108034434.559030-1-haijie1@huawei.com> <20231208065508.1663412-1-haijie1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To kwepemd100004.china.huawei.com (7.221.188.31) X-CFilter-Loop: Reflected X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org From: Dengdui Huang The mailbox messages of the PF and VF are processed in the same function. The PF and VF call the same function to process the messages. This code is excessive coupling and isn't good for maintenance. Therefore, this patch separates the interfaces that handle PF mailbox message and handle VF mailbox message. Fixes: 463e748964f5 ("net/hns3: support mailbox") Fixes: 109e4dd1bd7a ("net/hns3: get link state change through mailbox") Cc: stable@dpdk.org Signed-off-by: Dengdui Huang Signed-off-by: Jie Hai --- drivers/net/hns3/hns3_ethdev.c | 2 +- drivers/net/hns3/hns3_ethdev_vf.c | 4 +- drivers/net/hns3/hns3_mbx.c | 69 ++++++++++++++++++++++++------- drivers/net/hns3/hns3_mbx.h | 3 +- 4 files changed, 58 insertions(+), 20 deletions(-) diff --git a/drivers/net/hns3/hns3_ethdev.c b/drivers/net/hns3/hns3_ethdev.c index ae81368f68ae..bccd9db0dd4d 100644 --- a/drivers/net/hns3/hns3_ethdev.c +++ b/drivers/net/hns3/hns3_ethdev.c @@ -380,7 +380,7 @@ hns3_interrupt_handler(void *param) hns3_warn(hw, "received reset interrupt"); hns3_schedule_reset(hns); } else if (event_cause == HNS3_VECTOR0_EVENT_MBX) { - hns3_dev_handle_mbx_msg(hw); + hns3pf_handle_mbx_msg(hw); } else if (event_cause != HNS3_VECTOR0_EVENT_PTP) { hns3_warn(hw, "received unknown event: vector0_int_stat:0x%x " "ras_int_stat:0x%x cmdq_int_stat:0x%x", diff --git a/drivers/net/hns3/hns3_ethdev_vf.c b/drivers/net/hns3/hns3_ethdev_vf.c index b0d0c29df191..f5a7a2b1f46c 100644 --- a/drivers/net/hns3/hns3_ethdev_vf.c +++ b/drivers/net/hns3/hns3_ethdev_vf.c @@ -618,7 +618,7 @@ hns3vf_interrupt_handler(void *param) hns3_schedule_reset(hns); break; case HNS3VF_VECTOR0_EVENT_MBX: - hns3_dev_handle_mbx_msg(hw); + hns3vf_handle_mbx_msg(hw); break; default: break; @@ -670,7 +670,7 @@ hns3vf_get_push_lsc_cap(struct hns3_hw *hw) * driver has to actively handle the HNS3_MBX_LINK_STAT_CHANGE * mailbox from PF driver to get this capability. */ - hns3_dev_handle_mbx_msg(hw); + hns3vf_handle_mbx_msg(hw); if (__atomic_load_n(&vf->pf_push_lsc_cap, __ATOMIC_ACQUIRE) != HNS3_PF_PUSH_LSC_CAP_UNKNOWN) break; diff --git a/drivers/net/hns3/hns3_mbx.c b/drivers/net/hns3/hns3_mbx.c index 43195ff184b1..9cdbc1668a17 100644 --- a/drivers/net/hns3/hns3_mbx.c +++ b/drivers/net/hns3/hns3_mbx.c @@ -78,7 +78,7 @@ hns3_get_mbx_resp(struct hns3_hw *hw, uint16_t code, uint16_t subcode, return -EIO; } - hns3_dev_handle_mbx_msg(hw); + hns3vf_handle_mbx_msg(hw); rte_delay_us(HNS3_WAIT_RESP_US); if (hw->mbx_resp.received_match_resp) @@ -372,9 +372,57 @@ hns3_handle_mbx_msg_out_intr(struct hns3_hw *hw) } void -hns3_dev_handle_mbx_msg(struct hns3_hw *hw) +hns3pf_handle_mbx_msg(struct hns3_hw *hw) +{ + struct hns3_cmq_ring *crq = &hw->cmq.crq; + struct hns3_mbx_vf_to_pf_cmd *req; + struct hns3_cmd_desc *desc; + uint16_t flag; + + rte_spinlock_lock(&hw->cmq.crq.lock); + + while (!hns3_cmd_crq_empty(hw)) { + if (__atomic_load_n(&hw->reset.disable_cmd, __ATOMIC_RELAXED)) { + rte_spinlock_unlock(&hw->cmq.crq.lock); + return; + } + desc = &crq->desc[crq->next_to_use]; + req = (struct hns3_mbx_vf_to_pf_cmd *)desc->data; + + flag = rte_le_to_cpu_16(crq->desc[crq->next_to_use].flag); + if (unlikely(!hns3_get_bit(flag, HNS3_CMDQ_RX_OUTVLD_B))) { + hns3_warn(hw, + "dropped invalid mailbox message, code = %u", + req->msg.code); + + /* dropping/not processing this invalid message */ + crq->desc[crq->next_to_use].flag = 0; + hns3_mbx_ring_ptr_move_crq(crq); + continue; + } + + switch (req->msg.code) { + case HNS3_MBX_PUSH_LINK_STATUS: + hns3pf_handle_link_change_event(hw, req); + break; + default: + hns3_err(hw, "received unsupported(%u) mbx msg", + req->msg.code); + break; + } + crq->desc[crq->next_to_use].flag = 0; + hns3_mbx_ring_ptr_move_crq(crq); + } + + /* Write back CMDQ_RQ header pointer, IMP need this pointer */ + hns3_write_dev(hw, HNS3_CMDQ_RX_HEAD_REG, crq->next_to_use); + + rte_spinlock_unlock(&hw->cmq.crq.lock); +} + +void +hns3vf_handle_mbx_msg(struct hns3_hw *hw) { - struct hns3_adapter *hns = HNS3_DEV_HW_TO_ADAPTER(hw); struct hns3_cmq_ring *crq = &hw->cmq.crq; struct hns3_mbx_pf_to_vf_cmd *req; struct hns3_cmd_desc *desc; @@ -385,7 +433,7 @@ hns3_dev_handle_mbx_msg(struct hns3_hw *hw) rte_spinlock_lock(&hw->cmq.crq.lock); handle_out = (rte_eal_process_type() != RTE_PROC_PRIMARY || - !rte_thread_is_intr()) && hns->is_vf; + !rte_thread_is_intr()); if (handle_out) { /* * Currently, any threads in the primary and secondary processes @@ -430,8 +478,7 @@ hns3_dev_handle_mbx_msg(struct hns3_hw *hw) continue; } - handle_out = hns->is_vf && desc->opcode == 0; - if (handle_out) { + if (desc->opcode == 0) { /* Message already processed by other thread */ crq->desc[crq->next_to_use].flag = 0; hns3_mbx_ring_ptr_move_crq(crq); @@ -448,16 +495,6 @@ hns3_dev_handle_mbx_msg(struct hns3_hw *hw) case HNS3_MBX_ASSERTING_RESET: hns3_handle_asserting_reset(hw, req); break; - case HNS3_MBX_PUSH_LINK_STATUS: - /* - * This message is reported by the firmware and is - * reported in 'struct hns3_mbx_vf_to_pf_cmd' format. - * Therefore, we should cast the req variable to - * 'struct hns3_mbx_vf_to_pf_cmd' and then process it. - */ - hns3pf_handle_link_change_event(hw, - (struct hns3_mbx_vf_to_pf_cmd *)req); - break; case HNS3_MBX_PUSH_VLAN_INFO: /* * When the PVID configuration status of VF device is diff --git a/drivers/net/hns3/hns3_mbx.h b/drivers/net/hns3/hns3_mbx.h index 2952b96ab6b3..2b6cb8f513d0 100644 --- a/drivers/net/hns3/hns3_mbx.h +++ b/drivers/net/hns3/hns3_mbx.h @@ -207,7 +207,8 @@ struct hns3_pf_rst_done_cmd { ((crq)->next_to_use = ((crq)->next_to_use + 1) % (crq)->desc_num) struct hns3_hw; -void hns3_dev_handle_mbx_msg(struct hns3_hw *hw); +void hns3pf_handle_mbx_msg(struct hns3_hw *hw); +void hns3vf_handle_mbx_msg(struct hns3_hw *hw); void hns3vf_mbx_setup(struct hns3_vf_to_pf_msg *req, uint8_t code, uint8_t subcode); int hns3vf_mbx_send(struct hns3_hw *hw,