Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp6507815imu; Sun, 2 Dec 2018 20:16:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/VWBq+DmNN/rItE4j8UUxLJ74bBWAZBQz8a8wVBezBxKA1tYPp2AgHXCvDgnuWH741+7GTu X-Received: by 2002:a63:eb0e:: with SMTP id t14mr12205163pgh.445.1543810571938; Sun, 02 Dec 2018 20:16:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543810571; cv=none; d=google.com; s=arc-20160816; b=fAUs4kmAOwuR/hqp70VrTGnEDNNpMd/lDxCx7VZr5AdL8K/jilqAXmpkHM1BsWnSPU QCbbQI/eRsEtkoce99njl7j1asbJcOH3uOS7bCkMD8QVIutuXlgBsym0RW0Ord+TTmbI O9svzkbHrAXPFzL5Jn1waX0lqBLhWq/yoTeoXB24FbdzJfBaY6hye5de2r37hGz8UlPi WYfwuk8mNeX/0A4TbQL3nc+Aq1kZYfgDctU/W3IT/Vr+sVRqtLhXYAN8vQTfJ4fjSgtK 8fCnvSgoKYWdD3HNas42f+MdvjYmCNmuQmz/EOirVITTP4CS4tveejEnAAhPnnl+raix 20ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=ClLDUqmYEWpY65vHJLdZxxpvOvIbBiCyR4kGnc58M9Y=; b=VV5SdAtBja9tz1x6nxqJGsShVyYM4PCjJVNQZwT7tSk2l5z+FVenm69InSUy0qQPOh wUGbCCBdkOOptONy9fo/ZZqEPzFt47IxkSJ7BomD6yLjhKpAz3ao0GNsE5O7qwTihwYy 4lUVh+t+S951YouJYntMfl77/+U8yh3rOkqcOf1cpgZgivJTCgLzw3SovQKxqpwPYrkc RltLhJ+ZcAYNg5ribTVYMhsWGzAerMjZ7BbdlY1TC/KSFe9pPToInx3xObXBf8EYbuT5 GGxzpOb/ziEB54CdFGc00yAjiOLAB/+oqBAejcNkhJtw/+uv2xG9oG+fawIaM2xqkCXa mr/w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p22si11253518pgl.340.2018.12.02.20.15.56; Sun, 02 Dec 2018 20:16:11 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725833AbeLCEPZ (ORCPT + 99 others); Sun, 2 Dec 2018 23:15:25 -0500 Received: from szxga04-in.huawei.com ([45.249.212.190]:16069 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1725807AbeLCEPZ (ORCPT ); Sun, 2 Dec 2018 23:15:25 -0500 Received: from DGGEMS403-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3F2039898AC0F; Mon, 3 Dec 2018 12:15:19 +0800 (CST) Received: from HSH1000038028.huawei.com (10.177.161.152) by DGGEMS403-HUB.china.huawei.com (10.3.19.203) with Microsoft SMTP Server id 14.3.408.0; Mon, 3 Dec 2018 12:15:12 +0800 From: Kevin Wangtao To: CC: , , , , Kevin Wangtao Subject: [PATCH] mailbox: Hi3660: Fixup mailbox state machine malfunction issue Date: Mon, 3 Dec 2018 11:55:09 +0800 Message-ID: <1543809309-61169-1-git-send-email-kevin.wangtao@hisilicon.com> X-Mailer: git-send-email 2.8.1 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.177.161.152] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Current mailbox driver of Hi3660 release the mailbox directly before sending a new message which may cause last message lost and next message sending doesn't take effect actually. This patch fixs this issue by following the right progress below, each time before sending a message, mailbox driver will check whether the mailbox is in ready state, if last message has been acknowledged, the mailbox driver will clear the ack state to turn the mailbox to ready state again. Signed-off-by: Kevin Wangtao --- drivers/mailbox/hi3660-mailbox.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/mailbox/hi3660-mailbox.c b/drivers/mailbox/hi3660-mailbox.c index 3eea6b6..035b71a 100644 --- a/drivers/mailbox/hi3660-mailbox.c +++ b/drivers/mailbox/hi3660-mailbox.c @@ -38,6 +38,7 @@ #define MBOX_AUTOMATIC_ACK 1 #define MBOX_STATE_IDLE BIT(4) +#define MBOX_STATE_READY BIT(5) #define MBOX_STATE_ACK BIT(7) #define MBOX_MSG_LEN 8 @@ -91,8 +92,8 @@ static int hi3660_mbox_check_state(struct mbox_chan *chan) unsigned long val; unsigned int ret; - /* Mailbox is idle so directly bail out */ - if (readl(base + MBOX_MODE_REG) & MBOX_STATE_IDLE) + /* Mailbox is ready to use */ + if (readl(base + MBOX_MODE_REG) & MBOX_STATE_READY) return 0; /* Wait for acknowledge from remote */ @@ -103,9 +104,9 @@ static int hi3660_mbox_check_state(struct mbox_chan *chan) return ret; } - /* Ensure channel is released */ - writel(0xffffffff, base + MBOX_IMASK_REG); - writel(BIT(mchan->ack_irq), base + MBOX_SRC_REG); + /* clear ack state, mailbox will get back to ready state */ + writel(BIT(mchan->ack_irq), base + MBOX_ICLR_REG); + return 0; } @@ -160,10 +161,6 @@ static int hi3660_mbox_startup(struct mbox_chan *chan) { int ret; - ret = hi3660_mbox_check_state(chan); - if (ret) - return ret; - ret = hi3660_mbox_unlock(chan); if (ret) return ret; @@ -183,10 +180,11 @@ static int hi3660_mbox_send_data(struct mbox_chan *chan, void *msg) void __iomem *base = MBOX_BASE(mbox, ch); u32 *buf = msg; unsigned int i; + int ret; - /* Ensure channel is released */ - writel_relaxed(0xffffffff, base + MBOX_IMASK_REG); - writel_relaxed(BIT(mchan->ack_irq), base + MBOX_SRC_REG); + ret = hi3660_mbox_check_state(chan); + if (ret) + return ret; /* Clear mask for destination interrupt */ writel_relaxed(~BIT(mchan->dst_irq), base + MBOX_IMASK_REG); -- 2.8.1