From a371c10ea4b38a5f120e86d906d404d50a0f4660 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Tue, 3 Oct 2017 10:51:48 +0530 Subject: mailbox: bcm-flexrm-mailbox: Fix FlexRM ring flush sequence As-per suggestion from FlexRM HW folks, we have to first set FlexRM ring flush state and then clear it for FlexRM ring flush to work properly. Currently, the FlexRM driver has incomplete FlexRM ring flush sequence which causes repeated insmod+rmmod of mailbox client drivers to fail. This patch fixes FlexRM ring flush sequence in flexrm_shutdown() as described above. Fixes: dbc049eee730 ("mailbox: Add driver for Broadcom FlexRM ring manager") Signed-off-by: Anup Patel Reviewed-by: Scott Branden Cc: stable@vger.kernel.org Signed-off-by: Jassi Brar --- drivers/mailbox/bcm-flexrm-mailbox.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c index ae6146311934..f052a3eb2098 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -1365,8 +1365,8 @@ static void flexrm_shutdown(struct mbox_chan *chan) /* Disable/inactivate ring */ writel_relaxed(0x0, ring->regs + RING_CONTROL); - /* Flush ring with timeout of 1s */ - timeout = 1000; + /* Set ring flush state */ + timeout = 1000; /* timeout of 1s */ writel_relaxed(BIT(CONTROL_FLUSH_SHIFT), ring->regs + RING_CONTROL); do { @@ -1374,7 +1374,23 @@ static void flexrm_shutdown(struct mbox_chan *chan) FLUSH_DONE_MASK) break; mdelay(1); - } while (timeout--); + } while (--timeout); + if (!timeout) + dev_err(ring->mbox->dev, + "setting ring%d flush state timedout\n", ring->num); + + /* Clear ring flush state */ + timeout = 1000; /* timeout of 1s */ + writel_relaxed(0x0, ring + RING_CONTROL); + do { + if (!(readl_relaxed(ring + RING_FLUSH_DONE) & + FLUSH_DONE_MASK)) + break; + mdelay(1); + } while (--timeout); + if (!timeout) + dev_err(ring->mbox->dev, + "clearing ring%d flush state timedout\n", ring->num); /* Abort all in-flight requests */ for (reqid = 0; reqid < RING_MAX_REQ_COUNT; reqid++) { -- cgit v1.2.3-59-g8ed1b From ca194c38305d6b554d5aa85ba44b9e68bf1d9692 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Tue, 3 Oct 2017 10:51:49 +0530 Subject: mailbox: bcm-flexrm-mailbox: Print ring number in errors and warnings This patch updates all dev_err() and dev_warn() to print ring number so that we have more info for debugging. Signed-off-by: Anup Patel Reviewed-by: Scott Branden Signed-off-by: Jassi Brar --- drivers/mailbox/bcm-flexrm-mailbox.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c index f052a3eb2098..e0443aee6256 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -1116,8 +1116,8 @@ static int flexrm_process_completions(struct flexrm_ring *ring) err = flexrm_cmpl_desc_to_error(desc); if (err < 0) { dev_warn(ring->mbox->dev, - "got completion desc=0x%lx with error %d", - (unsigned long)desc, err); + "ring%d got completion desc=0x%lx with error %d\n", + ring->num, (unsigned long)desc, err); } /* Determine request id from completion descriptor */ @@ -1127,8 +1127,8 @@ static int flexrm_process_completions(struct flexrm_ring *ring) msg = ring->requests[reqid]; if (!msg) { dev_warn(ring->mbox->dev, - "null msg pointer for completion desc=0x%lx", - (unsigned long)desc); + "ring%d null msg pointer for completion desc=0x%lx\n", + ring->num, (unsigned long)desc); continue; } @@ -1238,7 +1238,9 @@ static int flexrm_startup(struct mbox_chan *chan) ring->bd_base = dma_pool_alloc(ring->mbox->bd_pool, GFP_KERNEL, &ring->bd_dma_base); if (!ring->bd_base) { - dev_err(ring->mbox->dev, "can't allocate BD memory\n"); + dev_err(ring->mbox->dev, + "can't allocate BD memory for ring%d\n", + ring->num); ret = -ENOMEM; goto fail; } @@ -1261,7 +1263,9 @@ static int flexrm_startup(struct mbox_chan *chan) ring->cmpl_base = dma_pool_alloc(ring->mbox->cmpl_pool, GFP_KERNEL, &ring->cmpl_dma_base); if (!ring->cmpl_base) { - dev_err(ring->mbox->dev, "can't allocate completion memory\n"); + dev_err(ring->mbox->dev, + "can't allocate completion memory for ring%d\n", + ring->num); ret = -ENOMEM; goto fail_free_bd_memory; } @@ -1269,7 +1273,8 @@ static int flexrm_startup(struct mbox_chan *chan) /* Request IRQ */ if (ring->irq == UINT_MAX) { - dev_err(ring->mbox->dev, "ring IRQ not available\n"); + dev_err(ring->mbox->dev, + "ring%d IRQ not available\n", ring->num); ret = -ENODEV; goto fail_free_cmpl_memory; } @@ -1278,7 +1283,8 @@ static int flexrm_startup(struct mbox_chan *chan) flexrm_irq_thread, 0, dev_name(ring->mbox->dev), ring); if (ret) { - dev_err(ring->mbox->dev, "failed to request ring IRQ\n"); + dev_err(ring->mbox->dev, + "failed to request ring%d IRQ\n", ring->num); goto fail_free_cmpl_memory; } ring->irq_requested = true; @@ -1291,7 +1297,9 @@ static int flexrm_startup(struct mbox_chan *chan) &ring->irq_aff_hint); ret = irq_set_affinity_hint(ring->irq, &ring->irq_aff_hint); if (ret) { - dev_err(ring->mbox->dev, "failed to set IRQ affinity hint\n"); + dev_err(ring->mbox->dev, + "failed to set IRQ affinity hint for ring%d\n", + ring->num); goto fail_free_irq; } -- cgit v1.2.3-59-g8ed1b From 8f82121dcf32b168412c2a5eb33a493f81f436e8 Mon Sep 17 00:00:00 2001 From: Scott Branden Date: Tue, 3 Oct 2017 10:51:50 +0530 Subject: mailbox: bcm-flexrm-mailbox: add depends on ARCH_BCM_IPROC The Broadcom FlexRM Mailbox is only present in the Broadcom IPROC SoCs. Add depends on ARCH_BCM_IPROC to BCM_FLEXRX_MBOX. Signed-off-by: Scott Branden Reviewed-by: Ray Jui Signed-off-by: Jassi Brar --- drivers/mailbox/Kconfig | 1 + 1 file changed, 1 insertion(+) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index c5731e5e3c6c..3161f2322eb2 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -163,6 +163,7 @@ config BCM_PDC_MBOX config BCM_FLEXRM_MBOX tristate "Broadcom FlexRM Mailbox" depends on ARM64 + depends on ARCH_BCM_IPROC || COMPILE_TEST depends on HAS_DMA select GENERIC_MSI_IRQ_DOMAIN default ARCH_BCM_IPROC -- cgit v1.2.3-59-g8ed1b From bf7e18991f8fad39137abfa9098bf8d6a4b1e7e5 Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Tue, 3 Oct 2017 10:51:51 +0530 Subject: mailbox: bcm-flexrm-mailbox: Use common GPL comment header This patch makes the comment header of Broadcom FlexRM driver similar to the GPL comment header used across Broadcom driver sources. Signed-off-by: Anup Patel Signed-off-by: Jassi Brar --- drivers/mailbox/bcm-flexrm-mailbox.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c index e0443aee6256..a8cf4333a68f 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -1,10 +1,18 @@ -/* Broadcom FlexRM Mailbox Driver - * +/* * Copyright (C) 2017 Broadcom * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation version 2. + * + * This program is distributed "as is" WITHOUT ANY WARRANTY of any + * kind, whether express or implied; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +/* + * Broadcom FlexRM Mailbox Driver * * Each Broadcom FlexSparx4 offload engine is implemented as an * extension to Broadcom FlexRM ring manager. The FlexRM ring -- cgit v1.2.3-59-g8ed1b From 22d28b0ffcf42e8a98d3fef8d73d1aff26f5518b Mon Sep 17 00:00:00 2001 From: Anup Patel Date: Tue, 3 Oct 2017 10:51:52 +0530 Subject: mailbox: Build Broadcom FlexRM driver as loadable module for iProc SOCs By default, we build Broadcom FlexRM driver as loadable module for iProc SOCs so that kernel image is little smaller and we load FlexRM driver only when required. Signed-off-by: Anup Patel Reviewed-by: Scott Branden Signed-off-by: Jassi Brar --- drivers/mailbox/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/Kconfig b/drivers/mailbox/Kconfig index 3161f2322eb2..ba2f1525f4ee 100644 --- a/drivers/mailbox/Kconfig +++ b/drivers/mailbox/Kconfig @@ -166,7 +166,7 @@ config BCM_FLEXRM_MBOX depends on ARCH_BCM_IPROC || COMPILE_TEST depends on HAS_DMA select GENERIC_MSI_IRQ_DOMAIN - default ARCH_BCM_IPROC + default m if ARCH_BCM_IPROC help Mailbox implementation of the Broadcom FlexRM ring manager, which provides access to various offload engines on Broadcom -- cgit v1.2.3-59-g8ed1b From 33cd7123ac0ba5360656ae27db453de5b9aa711f Mon Sep 17 00:00:00 2001 From: Sudeep Holla Date: Thu, 28 Sep 2017 11:18:52 +0100 Subject: mailbox: reset txdone_method TXDONE_BY_POLL if client knows_txdone Currently the mailbox framework sets txdone_method to TXDONE_BY_POLL if the controller sets txdone_by_poll. However some clients can have a mechanism to do TXDONE_BY_ACK which they can specify by knows_txdone. However, we endup setting both TXDONE_BY_POLL and TXDONE_BY_ACK in that case. In such scenario, we may end up with below warnings as the tx ticker is run both by mailbox framework and the client. WARNING: CPU: 1 PID: 0 at kernel/time/hrtimer.c:805 hrtimer_forward+0x88/0xd8 CPU: 1 PID: 0 Comm: swapper/1 Not tainted 4.12.0-rc5 #242 Hardware name: ARM LTD ARM Juno Development Platform task: ffff8009768ca700 task.stack: ffff8009768f8000 PC is at hrtimer_forward+0x88/0xd8 LR is at txdone_hrtimer+0xd4/0xf8 Call trace: hrtimer_forward+0x88/0xd8 __hrtimer_run_queues+0xe4/0x158 hrtimer_interrupt+0xa4/0x220 arch_timer_handler_phys+0x30/0x40 handle_percpu_devid_irq+0x78/0x130 generic_handle_irq+0x24/0x38 __handle_domain_irq+0x5c/0xb8 gic_handle_irq+0x54/0xa8 This patch fixes the issue by resetting TXDONE_BY_POLL if client has set knows_txdone. Cc: Alexey Klimov Signed-off-by: Sudeep Holla Signed-off-by: Jassi Brar --- drivers/mailbox/mailbox.c | 4 ++-- drivers/mailbox/pcc.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 537f4f6d009b..674b35f402f5 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -351,7 +351,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_client *cl, int index) init_completion(&chan->tx_complete); if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) - chan->txdone_method |= TXDONE_BY_ACK; + chan->txdone_method = TXDONE_BY_ACK; spin_unlock_irqrestore(&chan->lock, flags); @@ -418,7 +418,7 @@ void mbox_free_channel(struct mbox_chan *chan) spin_lock_irqsave(&chan->lock, flags); chan->cl = NULL; chan->active_req = NULL; - if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) + if (chan->txdone_method == TXDONE_BY_ACK) chan->txdone_method = TXDONE_BY_POLL; module_put(chan->mbox->dev->driver->owner); diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 9b7005e1345e..27c2294be51a 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -266,7 +266,7 @@ struct mbox_chan *pcc_mbox_request_channel(struct mbox_client *cl, init_completion(&chan->tx_complete); if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone) - chan->txdone_method |= TXDONE_BY_ACK; + chan->txdone_method = TXDONE_BY_ACK; spin_unlock_irqrestore(&chan->lock, flags); @@ -312,7 +312,7 @@ void pcc_mbox_free_channel(struct mbox_chan *chan) spin_lock_irqsave(&chan->lock, flags); chan->cl = NULL; chan->active_req = NULL; - if (chan->txdone_method == (TXDONE_BY_POLL | TXDONE_BY_ACK)) + if (chan->txdone_method == TXDONE_BY_ACK) chan->txdone_method = TXDONE_BY_POLL; spin_unlock_irqrestore(&chan->lock, flags); -- cgit v1.2.3-59-g8ed1b From e339c80af95e14de3712d69ddea09a3868fa14cd Mon Sep 17 00:00:00 2001 From: Sudeep Holla Date: Thu, 28 Sep 2017 11:18:53 +0100 Subject: mailbox: mailbox-test: don't rely on rx_buffer content to signal data ready Currently we rely on the first byte of the Rx buffer to check if there's any data available to be read. If the first byte of the received buffer is zero (i.e. null character), then we fail to signal that data is available even when it's available. Instead introduce a boolean variable to track the data availability and update it in the channel receive callback as ready and clear it when the data is read. Signed-off-by: Sudeep Holla Signed-off-by: Jassi Brar --- drivers/mailbox/mailbox-test.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/mailbox-test.c b/drivers/mailbox/mailbox-test.c index 97fb956bb6e0..93f3d4d61fa7 100644 --- a/drivers/mailbox/mailbox-test.c +++ b/drivers/mailbox/mailbox-test.c @@ -30,6 +30,7 @@ #define MBOX_HEXDUMP_MAX_LEN (MBOX_HEXDUMP_LINE_LEN * \ (MBOX_MAX_MSG_LEN / MBOX_BYTES_PER_LINE)) +static bool mbox_data_ready; static struct dentry *root_debugfs_dir; struct mbox_test_device { @@ -152,16 +153,14 @@ out: static bool mbox_test_message_data_ready(struct mbox_test_device *tdev) { - unsigned char data; + bool data_ready; unsigned long flags; spin_lock_irqsave(&tdev->lock, flags); - data = tdev->rx_buffer[0]; + data_ready = mbox_data_ready; spin_unlock_irqrestore(&tdev->lock, flags); - if (data != '\0') - return true; - return false; + return data_ready; } static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf, @@ -223,6 +222,7 @@ static ssize_t mbox_test_message_read(struct file *filp, char __user *userbuf, *(touser + l) = '\0'; memset(tdev->rx_buffer, 0, MBOX_MAX_MSG_LEN); + mbox_data_ready = false; spin_unlock_irqrestore(&tdev->lock, flags); @@ -292,6 +292,7 @@ static void mbox_test_receive_message(struct mbox_client *client, void *message) message, MBOX_MAX_MSG_LEN); memcpy(tdev->rx_buffer, message, MBOX_MAX_MSG_LEN); } + mbox_data_ready = true; spin_unlock_irqrestore(&tdev->lock, flags); wake_up_interruptible(&tdev->waitq); -- cgit v1.2.3-59-g8ed1b From 1f90a2162fb3cdfd9c44380bf16209af00f7acbe Mon Sep 17 00:00:00 2001 From: Arvind Yadav Date: Sat, 11 Nov 2017 23:39:18 +0530 Subject: mailbox/omap: unregister mbox class platform_driver_register() can fail here and we must unregister mbox class. Signed-off-by: Arvind Yadav Acked-by: Suman Anna Signed-off-by: Jassi Brar --- drivers/mailbox/omap-mailbox.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/mailbox') diff --git a/drivers/mailbox/omap-mailbox.c b/drivers/mailbox/omap-mailbox.c index c5e8b9cb170d..2517038a8452 100644 --- a/drivers/mailbox/omap-mailbox.c +++ b/drivers/mailbox/omap-mailbox.c @@ -906,7 +906,11 @@ static int __init omap_mbox_init(void) mbox_kfifo_size = max_t(unsigned int, mbox_kfifo_size, sizeof(mbox_msg_t)); - return platform_driver_register(&omap_mbox_driver); + err = platform_driver_register(&omap_mbox_driver); + if (err) + class_unregister(&omap_mbox_class); + + return err; } subsys_initcall(omap_mbox_init); -- cgit v1.2.3-59-g8ed1b