From patchwork Wed Jul 19 09:55:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9851067 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 8FF6160392 for ; Wed, 19 Jul 2017 09:57:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 74BD828632 for ; Wed, 19 Jul 2017 09:57:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 696E42863C; Wed, 19 Jul 2017 09:57:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0FED828632 for ; Wed, 19 Jul 2017 09:57:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=e1yTyPY5Xg9zl6Sw/ORKOfLayC5qNotN70K0BfNiwDc=; b=WNCwmO3HtO1O1iyGm+utw7dbBA aI3E5mRLVO4U3H7c2PLmzzpFtqqceoEpBQFP+LGA//7WRDyLisIzXbar3NGP4yaV2ic/36zSf268F 4x8vkB2u6iK0HexGW6Aq0gLsERS9S8H/sq7eUGqsA56WPax8EdUqCfCw/vRtmsZK8iISPJBiVzzLw jV2zPan0Zi0UZReqU+ZRxuP/Cpp1mGZ4oLwId8dnek2sSCQz0KJ/NjDYrC0/PM9psBiFUckYIEHMt N17rnXakioYB2NyHtBMrhnJ2hC5W3KRd9dUdNUZdIjjef7kVSzFdfny8Ub+B2p50DW8xyVH2iAIzv 8mcOSnKg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1dXljv-00066o-5E; Wed, 19 Jul 2017 09:57:55 +0000 Received: from mail-wm0-x231.google.com ([2a00:1450:400c:c09::231]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dXlj6-000540-JK for linux-arm-kernel@lists.infradead.org; Wed, 19 Jul 2017 09:57:11 +0000 Received: by mail-wm0-x231.google.com with SMTP id t70so4417525wmt.1 for ; Wed, 19 Jul 2017 02:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=msEojV3iuJBh4Fp7p9gY8JWsHez2yNd/ld8K3pA0uVA=; b=WahYXbEYUhTeGCvxPwg1HnkpScgqdwPbypqhr8Q/weyJjiMb4jd1xZ5xI96OMhn3b9 PWebZyRvYy8TjIYfO+eTamTz3iP9u1840cWwdMPjzUcIUovOkDIEJR7NKd7XcFYoVrmX X7mBz3TNFmkAElV5wrZvZwzsW5kiZIJfDTrek= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=msEojV3iuJBh4Fp7p9gY8JWsHez2yNd/ld8K3pA0uVA=; b=nWECRwOiAxifxqTnrzpuWPnHOyYjrzVUPgfhAaTyi39XkmnrK7pb/+NWkSZ5HeGikc CQWE3oDcZBRCVgRypGHINU5OOr1pwNVeIVRWPuI1qAvubLjPgeTD4V84LAzlkRdK38eK i0yAnqDgOsfwslZOOTJYYaar96IwAC9uTX/P2XFm46wfCnMCVm0/3mzUXv7S8bAswb1g VCzxyhGjPvmdQ5sgOlDtUD9ytWEdgEG8NYj5Ab1yMshPC24RUky8kRZ++3BQifXfiAsG 1gbQ0vT7VtOjCrQMtqd7E4c4GK89y8zhIj31X+DLDqNPzMdropyx0KH4NADRWsd3r1FT oUKg== X-Gm-Message-State: AIVw1120YFq1VKElKQIV5rvsCawuzspN53dQmIei9YIU3MEnlxjia/UF y68vqZvDsh4ghvbQ X-Received: by 10.28.238.85 with SMTP id m82mr5000826wmh.101.1500458202470; Wed, 19 Jul 2017 02:56:42 -0700 (PDT) Received: from anup-HP-Compaq-8100-Elite-CMT-PC.dhcp.avagotech.net ([192.19.237.250]) by smtp.gmail.com with ESMTPSA id 16sm20181480wmk.13.2017.07.19.02.56.36 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 19 Jul 2017 02:56:41 -0700 (PDT) From: Anup Patel To: Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Jassi Brar Subject: [PATCH 4/6] mailbox: Make message send queue size dynamic in Linux mailbox Date: Wed, 19 Jul 2017 15:25:40 +0530 Message-Id: <1500458142-19243-5-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500458142-19243-1-git-send-email-anup.patel@broadcom.com> References: <1500458142-19243-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170719_025707_712236_07D6EBD4 X-CRM114-Status: GOOD ( 17.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Florian Fainelli , Anup Patel , Scott Branden , Ray Jui , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Currently, the message send queue size in Linux mailbox framework is hard-coded to MBOX_TX_QUEUE_LEN which is defined as 20. This message send queue can easily overflow if mbox_send_message() is called for same mailbox channel several times. The size of message send queue should not be hard-coded in Linux mailbox framework and instead mailbox controller driver should have a mechanism to specify message send queue size for each mailbox channel. This patch makes message send queue size dynamic in Linux mailbox framework and provides a mechanism to set message send queue size for each mailbox channel. If mailbox controller driver does not set message send queue size then we assume the hard-coded value of 20. Signed-off-by: Anup Patel Reviewed-by: Jonathan Richardson Reviewed-by: Scott Branden --- drivers/mailbox/mailbox.c | 15 ++++++++++++--- include/linux/mailbox_controller.h | 5 +++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 537f4f6..ccc2aea 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -34,7 +34,7 @@ static int add_to_rbuf(struct mbox_chan *chan, void *mssg) spin_lock_irqsave(&chan->lock, flags); /* See if there is any space left */ - if (chan->msg_count == MBOX_TX_QUEUE_LEN) { + if (chan->msg_count == chan->msg_queue_len) { spin_unlock_irqrestore(&chan->lock, flags); return -ENOBUFS; } @@ -43,7 +43,7 @@ static int add_to_rbuf(struct mbox_chan *chan, void *mssg) chan->msg_data[idx] = mssg; chan->msg_count++; - if (idx == MBOX_TX_QUEUE_LEN - 1) + if (idx == chan->msg_queue_len - 1) chan->msg_free = 0; else chan->msg_free++; @@ -70,7 +70,7 @@ static void msg_submit(struct mbox_chan *chan) if (idx >= count) idx -= count; else - idx += MBOX_TX_QUEUE_LEN - count; + idx += chan->msg_queue_len - count; data = chan->msg_data[idx]; @@ -346,6 +346,12 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) spin_lock_irqsave(&chan->lock, flags); chan->msg_free = 0; chan->msg_count = 0; + chan->msg_data = kcalloc(chan->msg_queue_len, + sizeof(void *), GFP_ATOMIC); + if (!chan->msg_data) { + spin_unlock_irqrestore(&chan->lock, flags); + return ERR_PTR(-ENOMEM); + } chan->active_req = NULL; chan->cl = cl; init_completion(&chan->tx_complete); @@ -420,6 +426,7 @@ void mbox_free_channel(struct mbox_chan *chan) chan->active_req = NULL; if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) chan->txdone_method = TXDONE_BY_POLL; + kfree(chan->msg_data); module_put(chan->mbox->dev->driver->owner); spin_unlock_irqrestore(&chan->lock, flags); @@ -477,6 +484,8 @@ int mbox_controller_register(struct mbox_controller *mbox) chan->cl = NULL; chan->mbox = mbox; chan->txdone_method = txdone; + if (chan->msg_queue_len < MBOX_TX_QUEUE_LEN) + chan->msg_queue_len = MBOX_TX_QUEUE_LEN; spin_lock_init(&chan->lock); } diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_controller.h index 74deadb..eba3fed 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -110,6 +110,7 @@ struct mbox_controller { * @active_req: Currently active request hook * @msg_count: No. of mssg currently queued * @msg_free: Index of next available mssg slot + * @msg_queue_len: Max number of mssg which can be queued * @msg_data: Hook for data packet * @lock: Serialise access to the channel * @con_priv: Hook for controller driver to attach private data @@ -120,8 +121,8 @@ struct mbox_chan { struct mbox_client *cl; struct completion tx_complete; void *active_req; - unsigned msg_count, msg_free; - void *msg_data[MBOX_TX_QUEUE_LEN]; + unsigned int msg_count, msg_free, msg_queue_len; + void **msg_data; spinlock_t lock; /* Serialise access to the channel */ void *con_priv; };