Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp3524871pxv; Mon, 19 Jul 2021 02:17:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5nkpqq1q4yCrOXdtoXjpLjcOJLhXv38mtg/vpl+g75EWTy33jnXKCoaYafOAYAG6XAXNN X-Received: by 2002:a02:908a:: with SMTP id x10mr20506327jaf.30.1626686279271; Mon, 19 Jul 2021 02:17:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626686279; cv=none; d=google.com; s=arc-20160816; b=bk0Cka3fD8LnElW+zT1ybQAg44HD7lrBsh/KsK/iNkvQu0HEKZx9hq7KQ3nf0m7oPu uedC9VRpcTrtGzmItHjeL1vUXVAzK6Ca3qTO8FUKJKZN/OG0o404O1CYAuLW6GGjQvOZ 0GC705BPV/R80WpE83WIsD2veIJ1Sh2+ggG/B3Pn9su7IVxWhqSbluB8cSO1pVvQjntK C193pHytmFWioC83hnfi2g8fy0ugPoyvwCraxhy1GcwWdqITAvYRm3CgPgqsBxUEk4kZ KSCr7ie+Lxpw8ZuLjHCBzGriYMcLk/7QKP4w/ZC5OWhbQv6fXM83IWxlaBuYZBq5+v7w fSBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=WI0phY1zqpBQHovL71Sjcz7sP2NJf/avTsp94envU9c=; b=gRnM+b7wyqkYAabidpn3Jg71Fgd7BM/HXb9KXc/OAr6jcdRX5KAd1rmsTrWnlqhjPA z0uhrFxLCNCD60TuAfSS5XDxBIY3kz4TB4rkk8dhD33HFTgBXL8qX/1FEgHShA7TmMJ1 aeXA5T0TCZT8uopzn0mY6ew1tO1rrA+oWYC2aX1HaDYOg3vIPMb85SX2MTXgv+fECdER aMLlbEOLPWnRKMzzw9Vbuv23JDQQSv/pxdQXJiXAnYlL/YmBjYe3ox9cyPvc9lQi7kqv 84xR6lQFm5icEfbn8jW+UwTlpwyNNyogKl4sDO4ydJb5K0tgcJhkWm6GH/+3N1hbthcd qtDA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w9si20866506jad.35.2021.07.19.02.17.47; Mon, 19 Jul 2021 02:17:59 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236009AbhGSIgI (ORCPT + 99 others); Mon, 19 Jul 2021 04:36:08 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:7390 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235518AbhGSIgB (ORCPT ); Mon, 19 Jul 2021 04:36:01 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4GSx2j2nlPz7wGB; Mon, 19 Jul 2021 17:13:01 +0800 (CST) Received: from dggemi759-chm.china.huawei.com (10.1.198.145) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Mon, 19 Jul 2021 17:16:38 +0800 Received: from localhost.localdomain (10.67.165.24) by dggemi759-chm.china.huawei.com (10.1.198.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Mon, 19 Jul 2021 17:16:38 +0800 From: Guangbin Huang To: , , CC: , , , , Subject: [PATCH net 2/4] net: hns3: add match_id to check mailbox response from PF to VF Date: Mon, 19 Jul 2021 17:13:06 +0800 Message-ID: <1626685988-25869-3-git-send-email-huangguangbin2@huawei.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1626685988-25869-1-git-send-email-huangguangbin2@huawei.com> References: <1626685988-25869-1-git-send-email-huangguangbin2@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.67.165.24] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggemi759-chm.china.huawei.com (10.1.198.145) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Peng Li When VF need response from PF, VF will wait (1us - 1s) to receive the response, or it will wait timeout and the VF action fails. If VF do not receive response in 1st action because timeout, the 2nd action may receive response for the 1st action, and get incorrect response data.VF must reciveve the right response from PF,or it will cause unexpected error. This patch adds match_id to check mailbox response from PF to VF, to make sure VF get the right response: 1. The message sent from VF was labelled with match_id which was a unique 16-bit non-zero value. 2. The response sent from PF will label with match_id which got from the request. 3. The VF uses the match_id to match request and response message. This scheme depends on PF driver supports match_id, if PF driver doesn't support then VF will uses the original scheme. Signed-off-by: Peng Li Signed-off-by: Guangbin Huang --- drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h | 1 + .../net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h index 56b573e47072..aa86a81c8f4a 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h +++ b/drivers/net/ethernet/hisilicon/hns3/hclge_mbx.h @@ -98,6 +98,7 @@ struct hclgevf_mbx_resp_status { u32 origin_mbx_msg; bool received_resp; int resp_status; + u16 match_id; u8 additional_info[HCLGE_MBX_MAX_RESP_DATA_SIZE]; }; diff --git a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c index 9b17735b9f4c..772b2f8acd2e 100644 --- a/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c +++ b/drivers/net/ethernet/hisilicon/hns3/hns3vf/hclgevf_mbx.c @@ -13,6 +13,7 @@ static int hclgevf_resp_to_errno(u16 resp_code) return resp_code ? -resp_code : 0; } +#define HCLGEVF_MBX_MATCH_ID_START 1 static void hclgevf_reset_mbx_resp_status(struct hclgevf_dev *hdev) { /* this function should be called with mbx_resp.mbx_mutex held @@ -21,6 +22,10 @@ static void hclgevf_reset_mbx_resp_status(struct hclgevf_dev *hdev) hdev->mbx_resp.received_resp = false; hdev->mbx_resp.origin_mbx_msg = 0; hdev->mbx_resp.resp_status = 0; + hdev->mbx_resp.match_id++; + /* Update match_id and ensure the value of match_id is not zero */ + if (hdev->mbx_resp.match_id == 0) + hdev->mbx_resp.match_id = HCLGEVF_MBX_MATCH_ID_START; memset(hdev->mbx_resp.additional_info, 0, HCLGE_MBX_MAX_RESP_DATA_SIZE); } @@ -115,6 +120,7 @@ int hclgevf_send_mbx_msg(struct hclgevf_dev *hdev, if (need_resp) { mutex_lock(&hdev->mbx_resp.mbx_mutex); hclgevf_reset_mbx_resp_status(hdev); + req->match_id = hdev->mbx_resp.match_id; status = hclgevf_cmd_send(&hdev->hw, &desc, 1); if (status) { dev_err(&hdev->pdev->dev, @@ -211,6 +217,19 @@ void hclgevf_mbx_handler(struct hclgevf_dev *hdev) resp->additional_info[i] = *temp; temp++; } + + /* If match_id is not zero, it means PF support + * match_id. If the match_id is right, VF get the + * right response, otherwise ignore the response. + * Driver will clear hdev->mbx_resp when send + * next message which need response. + */ + if (req->match_id) { + if (req->match_id == resp->match_id) + resp->received_resp = true; + } else { + resp->received_resp = true; + } break; case HCLGE_MBX_LINK_STAT_CHANGE: case HCLGE_MBX_ASSERTING_RESET: -- 2.8.1