From patchwork Tue Aug 1 10:35:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9874101 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 5A31460365 for ; Tue, 1 Aug 2017 10:37:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 091C728173 for ; Tue, 1 Aug 2017 10:37:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F1D4828676; Tue, 1 Aug 2017 10:37:15 +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,RCVD_IN_DNSWL_NONE 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 D296A28173 for ; Tue, 1 Aug 2017 10:37:14 +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=AgoMvMv5ugeUtYW2x03TDvwBkqmbjVmAhsOHS4b3sns=; b=Inp0tUqZyvcBlOkHN3bDVhSpxe je55hHin0KOmfkUQovnE006PVn3P26szIVAVIXJgWaqgcOb0D1MkJ4BrUa/FOq46P/2sDvWc95YOB M+H7AlHouhUb3OflKLzk4CVag2xpkaRpSxvEIhKqboP02ecr9uuSzbJtqYHIRH7uis+l5jQcNXT+I EjwJcScE39J0RgLPYu/gszccQWbn9ChjxU4o7z9SaFg4fftzNRBdyBBaH8N9UK48IzH4mTXe6il9p WndiT/vemWGvkVDz/P/MS+R+aPvpnB2Ioh98m2HnfYAbC8B1WElpu99ALVWdu5w9Rh0FR3qo4L+Yy jT+NS4DQ==; 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 1dcUY2-0002El-Qa; Tue, 01 Aug 2017 10:37:10 +0000 Received: from mail-qk0-x233.google.com ([2607:f8b0:400d:c09::233]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dcUXf-0001h8-SR for linux-arm-kernel@lists.infradead.org; Tue, 01 Aug 2017 10:36:57 +0000 Received: by mail-qk0-x233.google.com with SMTP id d145so6487496qkc.2 for ; Tue, 01 Aug 2017 03:36:27 -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=KcYLuOTLtLriEITNhzvZNIHL7YW1TkrR1FK8JE2Enfo=; b=JXxWkBDdq5MJkAGfDuUt3/ELGtwh2e0TQASMbXK0FsUu+p9vXapujoOYujipDJ2Nco hC4SYfwueEtQmMjKVAK474IYyMSEwpQDdYmCtC9Zp4DrxweMCvxd5443ERTdYuIfNmD3 RDVcX+AyQQ0r/UYUueBX8Fh/ViSqsEiCIiHHw= 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=KcYLuOTLtLriEITNhzvZNIHL7YW1TkrR1FK8JE2Enfo=; b=a2W+UM8e18w/hRjnNvlCMj1faFUEDwfMU3pCfzcVcTN85YzpC2q8ekH3pLsogtOX3X 03oywo1/ZOSdtdpBRuUm+ZGKmj3awRp+FC0FXZF3pUuRyO0BYP6+OHCyDh+XF+sybUY8 9eiUgM213mO9lmpjl3PRmRYN7Lusb+UskAVB1/fJgaURJ4YEo2WT0xUghz7qc/Yzj1y6 JDmEWx0DI2YCEkjAh+9G28TYM4YdoNQneaw5edqy7p3pAnkK8lZsDnnGGaBgakFHEwRO pyehH5oPFoGQMjk6dGzDDr3nnCC91J6cFwwHv5jXRceY81S1Yd6Qt2ySN8vEJlAGDpN3 Xo/g== X-Gm-Message-State: AIVw110ZiWJaUIzO1Mxmo4cK79ltak9/alD98uZV1BpFFbUx8ZVVXn2i B+IxXjQbp4Q46+X3 X-Received: by 10.55.168.140 with SMTP id r134mr26428477qke.204.1501583784062; Tue, 01 Aug 2017 03:36:24 -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 d14sm23961629qtd.21.2017.08.01.03.36.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 01 Aug 2017 03:36:23 -0700 (PDT) From: Anup Patel To: Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Jassi Brar Subject: [PATCH v3 2/5] mailbox: bcm-flexrm-mailbox: Add debugfs support Date: Tue, 1 Aug 2017 16:05:51 +0530 Message-Id: <1501583754-31969-3-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501583754-31969-1-git-send-email-anup.patel@broadcom.com> References: <1501583754-31969-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170801_033648_679628_39B8A514 X-CRM114-Status: GOOD ( 18.07 ) 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 This patch adds debugfs support to Broadcom FlexRM driver so that we can see FlexRM ring state when any issue happens. Signed-off-by: Anup Patel Reviewed-by: Vikram Prakash Reviewed-by: Scott Branden --- drivers/mailbox/bcm-flexrm-mailbox.c | 136 ++++++++++++++++++++++++++++++++++- 1 file changed, 134 insertions(+), 2 deletions(-) diff --git a/drivers/mailbox/bcm-flexrm-mailbox.c b/drivers/mailbox/bcm-flexrm-mailbox.c index e8c3666..a0be2ea 100644 --- a/drivers/mailbox/bcm-flexrm-mailbox.c +++ b/drivers/mailbox/bcm-flexrm-mailbox.c @@ -17,6 +17,8 @@ #include #include +#include +#include #include #include #include @@ -270,6 +272,9 @@ struct flexrm_ring { u32 bd_write_offset; void *cmpl_base; dma_addr_t cmpl_dma_base; + /* Atomic stats */ + atomic_t msg_send_count; + atomic_t msg_cmpl_count; /* Protected members */ spinlock_t lock; struct brcm_message *last_pending_msg; @@ -283,6 +288,9 @@ struct flexrm_mbox { struct flexrm_ring *rings; struct dma_pool *bd_pool; struct dma_pool *cmpl_pool; + struct dentry *root; + struct dentry *config; + struct dentry *stats; struct mbox_controller controller; }; @@ -913,6 +921,62 @@ static void *flexrm_write_descs(struct brcm_message *msg, u32 nhcnt, /* ====== FlexRM driver helper routines ===== */ +static void flexrm_write_config_in_seqfile(struct flexrm_mbox *mbox, + struct seq_file *file) +{ + int i; + const char *state; + struct flexrm_ring *ring; + + seq_printf(file, "%-5s %-9s %-18s %-10s %-18s %-10s\n", + "Ring#", "State", "BD_Addr", "BD_Size", + "Cmpl_Addr", "Cmpl_Size"); + + for (i = 0; i < mbox->num_rings; i++) { + ring = &mbox->rings[i]; + if (readl(ring->regs + RING_CONTROL) & + BIT(CONTROL_ACTIVE_SHIFT)) + state = "active"; + else + state = "inactive"; + seq_printf(file, + "%-5d %-9s 0x%016llx 0x%08x 0x%016llx 0x%08x\n", + ring->num, state, + (unsigned long long)ring->bd_dma_base, + (u32)RING_BD_SIZE, + (unsigned long long)ring->cmpl_dma_base, + (u32)RING_CMPL_SIZE); + } +} + +static void flexrm_write_stats_in_seqfile(struct flexrm_mbox *mbox, + struct seq_file *file) +{ + int i; + u32 val, bd_read_offset; + struct flexrm_ring *ring; + + seq_printf(file, "%-5s %-10s %-10s %-10s %-11s %-11s\n", + "Ring#", "BD_Read", "BD_Write", + "Cmpl_Read", "Submitted", "Completed"); + + for (i = 0; i < mbox->num_rings; i++) { + ring = &mbox->rings[i]; + bd_read_offset = readl_relaxed(ring->regs + RING_BD_READ_PTR); + val = readl_relaxed(ring->regs + RING_BD_START_ADDR); + bd_read_offset *= RING_DESC_SIZE; + bd_read_offset += (u32)(BD_START_ADDR_DECODE(val) - + ring->bd_dma_base); + seq_printf(file, "%-5d 0x%08x 0x%08x 0x%08x %-11d %-11d\n", + ring->num, + (u32)bd_read_offset, + (u32)ring->bd_write_offset, + (u32)ring->cmpl_read_offset, + (u32)atomic_read(&ring->msg_send_count), + (u32)atomic_read(&ring->msg_cmpl_count)); + } +} + static int flexrm_new_request(struct flexrm_ring *ring, struct brcm_message *batch_msg, struct brcm_message *msg) @@ -1013,6 +1077,9 @@ static int flexrm_new_request(struct flexrm_ring *ring, /* Save ring BD write offset */ ring->bd_write_offset = (unsigned long)(next - ring->bd_base); + /* Increment number of messages sent */ + atomic_inc_return(&ring->msg_send_count); + exit: /* Update error status in message */ msg->error = ret; @@ -1106,12 +1173,37 @@ static int flexrm_process_completions(struct flexrm_ring *ring) mbox_chan_received_data(chan, msg); /* Increment number of completions processed */ + atomic_inc_return(&ring->msg_cmpl_count); count++; } return count; } +/* ====== FlexRM Debugfs callbacks ====== */ + +static int flexrm_debugfs_conf_show(struct seq_file *file, void *offset) +{ + struct platform_device *pdev = to_platform_device(file->private); + struct flexrm_mbox *mbox = platform_get_drvdata(pdev); + + /* Write config in file */ + flexrm_write_config_in_seqfile(mbox, file); + + return 0; +} + +static int flexrm_debugfs_stats_show(struct seq_file *file, void *offset) +{ + struct platform_device *pdev = to_platform_device(file->private); + struct flexrm_mbox *mbox = platform_get_drvdata(pdev); + + /* Write stats in file */ + flexrm_write_stats_in_seqfile(mbox, file); + + return 0; +} + /* ====== FlexRM interrupt handler ===== */ static irqreturn_t flexrm_irq_event(int irq, void *dev_id) @@ -1272,6 +1364,10 @@ static int flexrm_startup(struct mbox_chan *chan) val = BIT(CONTROL_ACTIVE_SHIFT); writel_relaxed(val, ring->regs + RING_CONTROL); + /* Reset stats to zero */ + atomic_set(&ring->msg_send_count, 0); + atomic_set(&ring->msg_cmpl_count, 0); + return 0; fail_free_irq: @@ -1491,6 +1587,8 @@ static int flexrm_mbox_probe(struct platform_device *pdev) ring->bd_dma_base = 0; ring->cmpl_base = NULL; ring->cmpl_dma_base = 0; + atomic_set(&ring->msg_send_count, 0); + atomic_set(&ring->msg_cmpl_count, 0); spin_lock_init(&ring->lock); ring->last_pending_msg = NULL; ring->cmpl_read_offset = 0; @@ -1532,6 +1630,36 @@ static int flexrm_mbox_probe(struct platform_device *pdev) ring->irq = desc->irq; } + /* Check availability of debugfs */ + if (!debugfs_initialized()) + goto skip_debugfs; + + /* Create debugfs root entry */ + mbox->root = debugfs_create_dir(dev_name(mbox->dev), NULL); + if (IS_ERR_OR_NULL(mbox->root)) { + ret = PTR_ERR_OR_ZERO(mbox->root); + goto fail_free_msis; + } + + /* Create debugfs config entry */ + mbox->config = debugfs_create_devm_seqfile(mbox->dev, + "config", mbox->root, + flexrm_debugfs_conf_show); + if (IS_ERR_OR_NULL(mbox->config)) { + ret = PTR_ERR_OR_ZERO(mbox->config); + goto fail_free_debugfs_root; + } + + /* Create debugfs stats entry */ + mbox->stats = debugfs_create_devm_seqfile(mbox->dev, + "stats", mbox->root, + flexrm_debugfs_stats_show); + if (IS_ERR_OR_NULL(mbox->stats)) { + ret = PTR_ERR_OR_ZERO(mbox->stats); + goto fail_free_debugfs_root; + } +skip_debugfs: + /* Initialize mailbox controller */ mbox->controller.txdone_irq = false; mbox->controller.txdone_poll = true; @@ -1544,7 +1672,7 @@ static int flexrm_mbox_probe(struct platform_device *pdev) sizeof(*mbox->controller.chans), GFP_KERNEL); if (!mbox->controller.chans) { ret = -ENOMEM; - goto fail_free_msis; + goto fail_free_debugfs_root; } for (index = 0; index < mbox->num_rings; index++) mbox->controller.chans[index].con_priv = &mbox->rings[index]; @@ -1552,13 +1680,15 @@ static int flexrm_mbox_probe(struct platform_device *pdev) /* Register mailbox controller */ ret = mbox_controller_register(&mbox->controller); if (ret) - goto fail_free_msis; + goto fail_free_debugfs_root; dev_info(dev, "registered flexrm mailbox with %d channels\n", mbox->controller.num_chans); return 0; +fail_free_debugfs_root: + debugfs_remove_recursive(mbox->root); fail_free_msis: platform_msi_domain_free_irqs(dev); fail_destroy_cmpl_pool: @@ -1578,6 +1708,8 @@ static int flexrm_mbox_remove(struct platform_device *pdev) mbox_controller_unregister(&mbox->controller); + debugfs_remove_recursive(mbox->root); + platform_msi_domain_free_irqs(dev); dma_pool_destroy(mbox->cmpl_pool);