Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4618412pxj; Wed, 12 May 2021 09:21:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxOvEo7Cac1GFvMduBsLU+htoBaH1XUk5hJte6wzsApyopT9ReMuCGAeiRDTp1mJR4exXVC X-Received: by 2002:a17:906:2854:: with SMTP id s20mr11583765ejc.335.1620836466442; Wed, 12 May 2021 09:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620836466; cv=none; d=google.com; s=arc-20160816; b=qNZTAlMzS9hhrKMNWbzCOE1Bt1pBairVI51bjgyORQGgMz9EAYxxavgNqgFfnPh0r4 0fz1Gaft8zzMEVhw1/7j//FVWb9GI0Q5X36bAoyYHj8/U5/lQDB3J+l5jKXKPkImFuEq mXbZKcHbn8VSsN4t0pjMrSuDV2P57HHxTRC6tqgLo7OC60I8MPUwsKyQiAvi/YhO5YlH oZvKteoksENYoR5aUK9160JSF/cumlTzeycyt5rNLMDkykSyqVdIuwbJA8/P26Y/451l KcMdzbeOWhJUdLMSVAUE2lBzbQPwHq6ZWnqXuRR3VDs+uXnQaWPiCtR2bviz2gMDvoqc fmYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fwk+ur9ffyshuWPlsN4yyavKvDUlT0hLpRMrpqe4e/o=; b=zxYPcx+ZrmyFkBvXYw8mGQg73YoGGJLGB0aVbyZQ050Mk/FSggyEZXBVH9nCADhLXw T1Djha69c5oHD5uNkAqRDyzhbhnTAvBbA1lG7o+euIeRKo9+qj+maihtOauxQNq1LVRs Em7W0zM2fkSpSANUvb0FJCWF+x1SV/6p4NMGp2bdEyYEf38p/e5CW6o1Ab/Rb52GV/tD 9ahMAad95FUaUZcY4AIN6FAP+eE21BpO4UceJKqT3c2j+B/1HROJIB/nlXTrCWhY6eRU kJ4uErS1cB44Purm3p3o8Mo2EpYcDeoFBQiglsUvPb27uNFp5/ObWVSPppRKULKIH0Me Hnww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g8U0g7nJ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ss21si372333ejb.390.2021.05.12.09.20.41; Wed, 12 May 2021 09:21:06 -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; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=g8U0g7nJ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240473AbhELQSI (ORCPT + 99 others); Wed, 12 May 2021 12:18:08 -0400 Received: from mail.kernel.org ([198.145.29.99]:48856 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235020AbhELPfI (ORCPT ); Wed, 12 May 2021 11:35:08 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id CA1F761C37; Wed, 12 May 2021 15:17:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1620832661; bh=8TVqaRWtXkycjf8XmVkiEBiZDcz3aCqEO5QImUkOQGc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g8U0g7nJcVGzSRcymIPX+pQMc5WEMkOa+XFeXDOZOJbBks46ONkS3nKHyzKb7dzvV XyxXEXco6cibTWYynQK7MTn89rN4hRiKbvlFGhSqgBb0GdFT0MjR8Kk+6IZS8Dxp2m l7sEPmunm0/+7L54GgXi+4a7LyWrHLdOn1ddUjHI= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Orson Zhai , Baolin Wang , Jassi Brar , Sasha Levin Subject: [PATCH 5.10 336/530] mailbox: sprd: Introduce refcnt when clients requests/free channels Date: Wed, 12 May 2021 16:47:26 +0200 Message-Id: <20210512144830.845105746@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210512144819.664462530@linuxfoundation.org> References: <20210512144819.664462530@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Orson Zhai [ Upstream commit 9468ab84032f96496e998cfa173cd1d0ac316bcd ] Unisoc mailbox has no way to be enabled/disabled for any single channel. They can only be set to startup or shutdown as a whole device at same time. Add a variable to count references to avoid mailbox FIFO being reset unexpectedly when clients are requesting or freeing channels. Also add a lock to dismiss possible conflicts from register r/w in different startup or shutdown threads. And fix the crash problem when early interrupts come from channel which has not been requested by client yet. Fixes: ca27fc26cd22 ("mailbox: sprd: Add Spreadtrum mailbox driver") Signed-off-by: Orson Zhai Reviewed-by: Baolin Wang Signed-off-by: Jassi Brar Signed-off-by: Sasha Levin --- drivers/mailbox/sprd-mailbox.c | 43 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/drivers/mailbox/sprd-mailbox.c b/drivers/mailbox/sprd-mailbox.c index 4c325301a2fe..94d9067dc8d0 100644 --- a/drivers/mailbox/sprd-mailbox.c +++ b/drivers/mailbox/sprd-mailbox.c @@ -60,6 +60,8 @@ struct sprd_mbox_priv { struct clk *clk; u32 outbox_fifo_depth; + struct mutex lock; + u32 refcnt; struct mbox_chan chan[SPRD_MBOX_CHAN_MAX]; }; @@ -115,7 +117,11 @@ static irqreturn_t sprd_mbox_outbox_isr(int irq, void *data) id = readl(priv->outbox_base + SPRD_MBOX_ID); chan = &priv->chan[id]; - mbox_chan_received_data(chan, (void *)msg); + if (chan->cl) + mbox_chan_received_data(chan, (void *)msg); + else + dev_warn_ratelimited(priv->dev, + "message's been dropped at ch[%d]\n", id); /* Trigger to update outbox FIFO pointer */ writel(0x1, priv->outbox_base + SPRD_MBOX_TRIGGER); @@ -215,18 +221,22 @@ static int sprd_mbox_startup(struct mbox_chan *chan) struct sprd_mbox_priv *priv = to_sprd_mbox_priv(chan->mbox); u32 val; - /* Select outbox FIFO mode and reset the outbox FIFO status */ - writel(0x0, priv->outbox_base + SPRD_MBOX_FIFO_RST); + mutex_lock(&priv->lock); + if (priv->refcnt++ == 0) { + /* Select outbox FIFO mode and reset the outbox FIFO status */ + writel(0x0, priv->outbox_base + SPRD_MBOX_FIFO_RST); - /* Enable inbox FIFO overflow and delivery interrupt */ - val = readl(priv->inbox_base + SPRD_MBOX_IRQ_MSK); - val &= ~(SPRD_INBOX_FIFO_OVERFLOW_IRQ | SPRD_INBOX_FIFO_DELIVER_IRQ); - writel(val, priv->inbox_base + SPRD_MBOX_IRQ_MSK); + /* Enable inbox FIFO overflow and delivery interrupt */ + val = readl(priv->inbox_base + SPRD_MBOX_IRQ_MSK); + val &= ~(SPRD_INBOX_FIFO_OVERFLOW_IRQ | SPRD_INBOX_FIFO_DELIVER_IRQ); + writel(val, priv->inbox_base + SPRD_MBOX_IRQ_MSK); - /* Enable outbox FIFO not empty interrupt */ - val = readl(priv->outbox_base + SPRD_MBOX_IRQ_MSK); - val &= ~SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ; - writel(val, priv->outbox_base + SPRD_MBOX_IRQ_MSK); + /* Enable outbox FIFO not empty interrupt */ + val = readl(priv->outbox_base + SPRD_MBOX_IRQ_MSK); + val &= ~SPRD_OUTBOX_FIFO_NOT_EMPTY_IRQ; + writel(val, priv->outbox_base + SPRD_MBOX_IRQ_MSK); + } + mutex_unlock(&priv->lock); return 0; } @@ -235,9 +245,13 @@ static void sprd_mbox_shutdown(struct mbox_chan *chan) { struct sprd_mbox_priv *priv = to_sprd_mbox_priv(chan->mbox); - /* Disable inbox & outbox interrupt */ - writel(SPRD_INBOX_FIFO_IRQ_MASK, priv->inbox_base + SPRD_MBOX_IRQ_MSK); - writel(SPRD_OUTBOX_FIFO_IRQ_MASK, priv->outbox_base + SPRD_MBOX_IRQ_MSK); + mutex_lock(&priv->lock); + if (--priv->refcnt == 0) { + /* Disable inbox & outbox interrupt */ + writel(SPRD_INBOX_FIFO_IRQ_MASK, priv->inbox_base + SPRD_MBOX_IRQ_MSK); + writel(SPRD_OUTBOX_FIFO_IRQ_MASK, priv->outbox_base + SPRD_MBOX_IRQ_MSK); + } + mutex_unlock(&priv->lock); } static const struct mbox_chan_ops sprd_mbox_ops = { @@ -266,6 +280,7 @@ static int sprd_mbox_probe(struct platform_device *pdev) return -ENOMEM; priv->dev = dev; + mutex_init(&priv->lock); /* * The Spreadtrum mailbox uses an inbox to send messages to the target -- 2.30.2