From patchwork Fri Jul 21 06:55:37 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 9856249 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 9A0DC60392 for ; Fri, 21 Jul 2017 06:57:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 783952876B for ; Fri, 21 Jul 2017 06:57:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CC3C2877C; Fri, 21 Jul 2017 06:57:18 +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 C92962876B for ; Fri, 21 Jul 2017 06:57:17 +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=u93PI+hNKLJB63Xbrtd1byDg9u F13GWAYqQZ1t4uyoQ7W/S2/npLgLDDci5FlBKjtOFDAH/2pmx45rDuTMpXAhFFMwPkqkhy9uKe3/8 txkBTQOHVWPTUpKKHdWOWeWQHShAOmJRymrVKbz1ru+iGlL2a9MRFFUOYxOU1SCBVZNzlRV8W1pb9 PjSziEZeWkZx+L3a+8bFYzBMudScIotqycR7IyvNwFGt6jHst+cuIKn0yyDGoRS+jdEy1OKVJqKM0 DN4YfK55Cc2gGYpMWYHFG/FIwAcJctOjYrjre24kNpIMxVlL76faDLPTZ+CJwpRKmrfYsW/KpQuVk 5CwyT8og==; 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 1dYRs8-0006LZ-TZ; Fri, 21 Jul 2017 06:57:12 +0000 Received: from mail-wm0-x235.google.com ([2a00:1450:400c:c09::235]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1dYRrZ-0005ig-7H for linux-arm-kernel@lists.infradead.org; Fri, 21 Jul 2017 06:56:43 +0000 Received: by mail-wm0-x235.google.com with SMTP id w191so832866wmw.1 for ; Thu, 20 Jul 2017 23:56:16 -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=f+Uct1vB1210YjsWmZIeK34xXto9m+iUdgvL3urrKpn9hs79Jj5Q3MKtbngJgwxL0t Iceu1fMSskDiCUfAr/yZ27Tg35lP75azt2ALG5ekcrP5YYx5Yx6y+45+C7TRZ0ocfe0j 0B/mI5uVahdhOBYhYJfpr/nae00Sh6Ni5Yg+g= 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=lmQHV8zGLRQCy3WI8APpVwDJWppzrrVZNkZ3yZKydQakRdEZku1/7nBJBCrkE5gotx /V68po7/jqAWguqx7S1ebuNvZbuSP0yWwUCgKnOpFOLxNcPP/hXjqj5yZ+/MrxZvneez e21ASeQTjTf3V+TpTxD0o7XgvOwF+bR7OSh640gun/NU785i0+5nR2p3z1sNIlAt7fWy qEoNtBCK3REk9H2E1hFDU6N868V/Ix9R+2i1375NsebQSpYbSbRSi4STVew7DRb0JDOG HBWdG3ItkpL3hvRdDHM5zVyMGfUsJIozW+S/Zu2Q8kg9ZEAWMb1OabHjbgtM848l26Fn eOgw== X-Gm-Message-State: AIVw110ocOKQay+VJiO4r7G8PLowTHzFryhJUwoNgfZZ3FXJSrUcoXZp 016I0baS/H/k+Sbe X-Received: by 10.28.236.19 with SMTP id k19mr4249137wmh.30.1500620174925; Thu, 20 Jul 2017 23:56:14 -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 77sm751684wmk.8.2017.07.20.23.56.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 20 Jul 2017 23:56:14 -0700 (PDT) From: Anup Patel To: Rob Herring , Mark Rutland , Catalin Marinas , Will Deacon , Jassi Brar Subject: [PATCH v2 2/7] mailbox: bcm-flexrm-mailbox: Add debugfs support Date: Fri, 21 Jul 2017 12:25:37 +0530 Message-Id: <1500620142-910-3-git-send-email-anup.patel@broadcom.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1500620142-910-1-git-send-email-anup.patel@broadcom.com> References: <1500620142-910-1-git-send-email-anup.patel@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170720_235637_957845_3540AF98 X-CRM114-Status: GOOD ( 17.63 ) 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);