From patchwork Tue Dec 21 17:43:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Chen X-Patchwork-Id: 526729 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00778C433EF for ; Tue, 21 Dec 2021 17:44:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240487AbhLURo2 (ORCPT ); Tue, 21 Dec 2021 12:44:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35372 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240488AbhLURo1 (ORCPT ); Tue, 21 Dec 2021 12:44:27 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA2E0C06173F for ; Tue, 21 Dec 2021 09:44:26 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id d27-20020a25addb000000b005c2355d9052so26830600ybe.3 for ; Tue, 21 Dec 2021 09:44:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=tstkmqRThhOrJgyx+bXU0cB1kakh9VwqC35Xj4Y7sHs=; b=H1TXf7VRnhvGMYIuNGRoKHGhiNZhPjvZuVRFBftoQAFzYF+HVtPZBGPR9MbsjuT0r3 VTVuSMjgf6AK1I6QRjatJmo1afgs0KKpqGMcyaaOvLBOe6wtQtZ8EgX85/5i0qULNMF+ nFWOc9ocKD5OWCKF1uzkF2YeaPOUiB/B+vqDx/+RVKBO2neOm9xTZtDDH4QAye0OaidL ttBbW+cS0C0CUpU4YHp217FkYRGUEs85cvv5LW1jUnih3WJmySo+2vEAunexnqC4shT/ DeVrXUJLrEjzDkTZgmbc9lyKm50XoahUitaBVZ+uBmBUZeX14NepKhKoNSDN1HYpebi/ VvXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=tstkmqRThhOrJgyx+bXU0cB1kakh9VwqC35Xj4Y7sHs=; b=Y2vfQ86QeyvI0elCoIRQ1uERRL4u9PjVyOTbEMia0p3gtDE+YMcktpXr+cJJRfSteC 8Y+MTOAXO/OPQ2G1OlT9svrQWS18O+0jbhMGfM1Mnd/WP3yJGv5e8fAdg70aVxCzMg/9 XH2trdzCFillCNhINJaXiMUPRFhQt+ovl/EZviPGlk1unQSg4Sg/1ORKJkBPMXyitOoZ 9EVs1KEwAPyOfTT/KspfQh48wbW5F6T2zT4/uualsUlfH3eA9JcBDQoIXzyIxNnd85g8 bU2DTvX5Skup54sOcJ04/95YXi8f5RQz/wtvEn61CFvWqhRdN+xT04vwAQiEb9g1gI/g r7ng== X-Gm-Message-State: AOAM5300RNYWJOcUvBZIb0T6a9PMc1GUAUZtQaWqZn0GFOoHdUuM/L0f 9EgOFSWzWKiXARZYdiphRQ1Ro/xsSL7v X-Google-Smtp-Source: ABdhPJxMMnb+SjpJddfxXapAUglYaX2Jb8fWQY/cObc9QUb+NeD49lwCuuDh+pO4gSgiAs1MAH7d+BqvFTtN X-Received: from suichen.svl.corp.google.com ([2620:15c:2c5:13:19fd:5987:f46f:7488]) (user=suichen job=sendgmr) by 2002:a25:7802:: with SMTP id t2mr5915521ybc.158.1640108665998; Tue, 21 Dec 2021 09:44:25 -0800 (PST) Date: Tue, 21 Dec 2021 09:43:42 -0800 In-Reply-To: <20211221174344.1249202-1-suichen@google.com> Message-Id: <20211221174344.1249202-2-suichen@google.com> Mime-Version: 1.0 References: <20211221174344.1249202-1-suichen@google.com> X-Mailer: git-send-email 2.34.1.307.g9b7440fafd-goog Subject: [RFC Patch v3 1/3] i2c debug counters as sysfs attributes From: Sui Chen To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, joel@jms.id.au, andrew@aj.id.au, tali.perry1@gmail.com, benjaminfair@google.com, krellan@google.com, Sui Chen , kernel test robot Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This change adds a few example I2C debug counters as sysfs attributes: - ber_cnt (bus error count) - nack_cnt (NACK count) - rec_fail_cnt, rec_succ_cnt (recovery failure/success count) - timeout_cnt (timeout count) - i2c_speed (bus frequency) - tx_complete_cnt (transaction completed, including both as an initiator and as a target) The function i2c_adapter_create_stats_folder creates a stats directory in the device's sysfs directory to hold the debug counters. The platform drivers are responsible for instantiating the counters in the stats directory if applicable. i2c_adapter_create_stats_folder is placed in i2c-core-base.c for fixing a build error on arc700. Signed-off-by: Sui Chen Reported-by: kernel test robot --- drivers/i2c/i2c-core-base.c | 23 +++++++ drivers/i2c/i2c-dev.c | 124 ++++++++++++++++++++++++++++++++++++ include/linux/i2c.h | 28 ++++++++ 3 files changed, 175 insertions(+) diff --git a/drivers/i2c/i2c-core-base.c b/drivers/i2c/i2c-core-base.c index 84f12bf90644a..64dd79d32a0c3 100644 --- a/drivers/i2c/i2c-core-base.c +++ b/drivers/i2c/i2c-core-base.c @@ -1610,6 +1610,8 @@ static int i2c_register_adapter(struct i2c_adapter *adap) bus_for_each_drv(&i2c_bus_type, NULL, adap, __process_new_adapter); mutex_unlock(&core_lock); + i2c_adapter_create_stats_directory(adap); + return 0; out_reg: @@ -2617,6 +2619,27 @@ void i2c_put_dma_safe_msg_buf(u8 *buf, struct i2c_msg *msg, bool xferred) kfree(buf); } + +/** + * i2c_adapter_create_stats_directory - creates folder for I2C statistics. + * @adapter: the i2c_adapter to create the stats directory for. + * + * Return: 0 if successful, 1 if failed. + */ +int i2c_adapter_create_stats_directory(struct i2c_adapter *adapter) +{ + struct i2c_adapter_stats *stats; + + stats = kzalloc(sizeof(*stats), GFP_KERNEL); + if (!stats) { + adapter->stats = NULL; + return 1; + } + adapter->stats = stats; + adapter->stats->kobj = kobject_create_and_add("stats", &adapter->dev.kobj); + return 0; +} + EXPORT_SYMBOL_GPL(i2c_put_dma_safe_msg_buf); MODULE_AUTHOR("Simon G. Vogl "); diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c index 77f576e516522..902a964d47b10 100644 --- a/drivers/i2c/i2c-dev.c +++ b/drivers/i2c/i2c-dev.c @@ -767,6 +767,130 @@ static void __exit i2c_dev_exit(void) unregister_chrdev_region(MKDEV(I2C_MAJOR, 0), I2C_MINORS); } +static struct i2c_adapter *kobj_to_adapter(struct device *pdev) +{ + struct kobject *dev_kobj; + struct device *dev; + + dev_kobj = ((struct kobject *)pdev)->parent; + dev = container_of(dev_kobj, struct device, kobj); + return to_i2c_adapter(dev); +} + +static ssize_t ber_cnt_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *ber_cnt = kobj_to_adapter(pdev)->stats->ber_cnt; + + if (!ber_cnt) + return 0; + return sysfs_emit(buf, "%llu\n", *ber_cnt); +} +DEVICE_ATTR_RO(ber_cnt); + +ssize_t nack_cnt_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *nack_cnt = kobj_to_adapter(pdev)->stats->nack_cnt; + + if (!nack_cnt) + return 0; + return sysfs_emit(buf, "%llu\n", *nack_cnt); +} +DEVICE_ATTR_RO(nack_cnt); + +ssize_t rec_succ_cnt_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *rec_succ_cnt = kobj_to_adapter(pdev)->stats->rec_succ_cnt; + + if (!rec_succ_cnt) + return 0; + return sysfs_emit(buf, "%llu\n", *rec_succ_cnt); +} +DEVICE_ATTR_RO(rec_succ_cnt); + +ssize_t rec_fail_cnt_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *rec_fail_cnt = kobj_to_adapter(pdev)->stats->rec_fail_cnt; + + if (!rec_fail_cnt) + return 0; + return sysfs_emit(buf, "%llu\n", *rec_fail_cnt); +} +DEVICE_ATTR_RO(rec_fail_cnt); + +ssize_t timeout_cnt_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *timeout_cnt = kobj_to_adapter(pdev)->stats->timeout_cnt; + + if (!timeout_cnt) + return 0; + return sysfs_emit(buf, "%llu\n", *timeout_cnt); +} +DEVICE_ATTR_RO(timeout_cnt); + +ssize_t i2c_speed_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *i2c_speed = kobj_to_adapter(pdev)->stats->i2c_speed; + + if (!i2c_speed) + return 0; + return sysfs_emit(buf, "%llu\n", *i2c_speed); +} +DEVICE_ATTR_RO(i2c_speed); + +ssize_t tx_complete_cnt_show(struct device *pdev, + struct device_attribute *attr, char *buf) +{ + u64 *tx_complete_cnt = kobj_to_adapter(pdev)->stats->tx_complete_cnt; + + if (!tx_complete_cnt) + return 0; + return sysfs_emit(buf, "%llu\n", *tx_complete_cnt); +} +DEVICE_ATTR_RO(tx_complete_cnt); + +void i2c_adapter_stats_register_counter(struct i2c_adapter *adapter, + const char *counter_name, void *data_source) +{ + int ret = 1; + + if (!adapter->stats) { + if (i2c_adapter_create_stats_directory(adapter)) + return; + } + + if (!strcmp(counter_name, "ber_cnt")) { + adapter->stats->ber_cnt = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_ber_cnt.attr); + } else if (!strcmp(counter_name, "nack_cnt")) { + adapter->stats->nack_cnt = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_nack_cnt.attr); + } else if (!strcmp(counter_name, "rec_succ_cnt")) { + adapter->stats->rec_succ_cnt = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_rec_succ_cnt.attr); + } else if (!strcmp(counter_name, "rec_fail_cnt")) { + adapter->stats->rec_fail_cnt = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_rec_fail_cnt.attr); + } else if (!strcmp(counter_name, "timeout_cnt")) { + adapter->stats->timeout_cnt = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_timeout_cnt.attr); + } else if (!strcmp(counter_name, "i2c_speed")) { + adapter->stats->i2c_speed = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_i2c_speed.attr); + } else if (!strcmp(counter_name, "tx_complete_cnt")) { + adapter->stats->tx_complete_cnt = data_source; + ret = sysfs_create_file(adapter->stats->kobj, &dev_attr_tx_complete_cnt.attr); + } + + if (ret) + dev_warn(&adapter->dev, "Failed to create sysfs file for %s\n", counter_name); +} + MODULE_AUTHOR("Frodo Looijaard "); MODULE_AUTHOR("Simon G. Vogl "); MODULE_DESCRIPTION("I2C /dev entries driver"); diff --git a/include/linux/i2c.h b/include/linux/i2c.h index 3eb60a2e9e618..23914600af586 100644 --- a/include/linux/i2c.h +++ b/include/linux/i2c.h @@ -21,6 +21,7 @@ #include /* for struct device_node */ #include /* for swab16 */ #include +#include /* for kzalloc */ extern struct bus_type i2c_bus_type; extern struct device_type i2c_adapter_type; @@ -684,6 +685,27 @@ struct i2c_adapter_quirks { u16 max_comb_2nd_msg_len; }; +/** + * I2C statistics + * The list of statistics are currently copied from npcm7xx. + * Perhaps a more universal set of statistics can be used. + * + * The stats are currently modeled as pointers to members in the bus drivers. + * A null pointer indicates the counter is not supported by the bus driver. + */ +struct i2c_adapter_stats { + struct kobject *kobj; + + /* a NULL value means the counter is not available */ + u64 *tx_complete_cnt; + u64 *ber_cnt; + u64 *nack_cnt; + u64 *rec_succ_cnt; + u64 *rec_fail_cnt; + u64 *timeout_cnt; + u64 *i2c_speed; +}; + /* enforce max_num_msgs = 2 and use max_comb_*_len for length checks */ #define I2C_AQ_COMB BIT(0) /* first combined message must be write */ @@ -735,12 +757,18 @@ struct i2c_adapter { struct i2c_bus_recovery_info *bus_recovery_info; const struct i2c_adapter_quirks *quirks; + struct i2c_adapter_stats *stats; struct irq_domain *host_notify_domain; struct regulator *bus_regulator; }; #define to_i2c_adapter(d) container_of(d, struct i2c_adapter, dev) +int i2c_adapter_create_stats_directory(struct i2c_adapter *adapter); + +void i2c_adapter_stats_register_counter(struct i2c_adapter *adapter, + const char *counter_name, void *data_source); + static inline void *i2c_get_adapdata(const struct i2c_adapter *adap) { return dev_get_drvdata(&adap->dev); From patchwork Tue Dec 21 17:43:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Chen X-Patchwork-Id: 527287 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4176C433F5 for ; Tue, 21 Dec 2021 17:44:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240489AbhLURoa (ORCPT ); Tue, 21 Dec 2021 12:44:30 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35384 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240504AbhLURoa (ORCPT ); Tue, 21 Dec 2021 12:44:30 -0500 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB4E4C061574 for ; Tue, 21 Dec 2021 09:44:29 -0800 (PST) Received: by mail-yb1-xb4a.google.com with SMTP id b15-20020a25ae8f000000b005c20f367790so27005820ybj.2 for ; Tue, 21 Dec 2021 09:44:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=HkXdeoDDS4XC9WW1t3ovXGQdnbI8L5ktylsEwvM1dMc=; b=ETNvHd8111/hLG/3/ROxw3sC6AqMoWNtx1W2oVtJKNsM5tdBbnLwCpLxyxBEpJxoOK pcCq+L1AMUhQf10lvFRHOysRre6GXkZ6InOGARh3EmPwaQJHqa1oPFo6aUyC+am5vibq DC25E2eGr5Ts4/9M5el+gPDxxPgakEGZOE5zNfGkkC/R6jZsnAaLha0n90XkOPmEr4gA DnulDSw9hJApvOFHNlTlCC19SxtmbHfC0x0vTSoVY9dgY98mJKoXTW48nk8dxV1zwI31 pI0Y3fJGBcjBJ4uunsi9ZWaoixmMab4ug8sqWtWCK5UFCoNI51jcBqR8tIYXceRTMa8N XMaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=HkXdeoDDS4XC9WW1t3ovXGQdnbI8L5ktylsEwvM1dMc=; b=DdqMbzG5sKXpqBNMZxtSZSPPkouBP1QbAz1IVKyrX2arTVIlXPXcm1I7P9QzosFYZy KVuJ5wQjgIvhJBsy6BR1mKmbFG/i9b590b2RlmoHdjJpYyMRUrfFYembicOJWG8ZHOcT L4nez+SLlhK5zZtkhIX9QQ1TNzWrQgM+OiGMIQBZJRq+muWece2vB/q8VoKVP/nLR4IX iKg6cbQBs/nvT2LTqKaoTRZ1+tM4I961/AGlf04f/LBYyzgVHBuZUcJmW2Be7DMHJhys WyVviTCR772aqDbTR25YaCZIeFAHE8/IoJC4a+2q9UoC2x8AwQbRL29Sywq3rajy8U54 /DWw== X-Gm-Message-State: AOAM533CcH23uJOf4KKyFl/CWRYes591T1ynwlgqur80DRlU5b3lKQyH NTP18x/dtooWhk8lSs0lVX33xwLuQWU1 X-Google-Smtp-Source: ABdhPJwCJM4EkwOClyVAfTDeoeRC4+/Y03u13sQX/1lpfnuJre5DLbkFg1YukGstywgAkyz6SQT6mUZi0gzY X-Received: from suichen.svl.corp.google.com ([2620:15c:2c5:13:19fd:5987:f46f:7488]) (user=suichen job=sendgmr) by 2002:a25:bfd2:: with SMTP id q18mr6304044ybm.542.1640108669011; Tue, 21 Dec 2021 09:44:29 -0800 (PST) Date: Tue, 21 Dec 2021 09:43:43 -0800 In-Reply-To: <20211221174344.1249202-1-suichen@google.com> Message-Id: <20211221174344.1249202-3-suichen@google.com> Mime-Version: 1.0 References: <20211221174344.1249202-1-suichen@google.com> X-Mailer: git-send-email 2.34.1.307.g9b7440fafd-goog Subject: [RFC Patch v3 2/3] i2c: npcm7xx: add tx_complete counter From: Sui Chen To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, joel@jms.id.au, andrew@aj.id.au, tali.perry1@gmail.com, benjaminfair@google.com, krellan@google.com Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Tali Perry Add tx_copmplete counter which increments when a valid transaction completes. Signed-off-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index 2ad166355ec9b..cc7abd0b870be 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -314,6 +314,7 @@ struct npcm_i2c { u64 rec_fail_cnt; u64 nack_cnt; u64 timeout_cnt; + u64 tx_complete_cnt; }; static inline void npcm_i2c_select_bank(struct npcm_i2c *bus, @@ -684,6 +685,8 @@ static void npcm_i2c_callback(struct npcm_i2c *bus, switch (op_status) { case I2C_MASTER_DONE_IND: bus->cmd_err = bus->msgs_num; + if (bus->tx_complete_cnt < ULLONG_MAX) + bus->tx_complete_cnt++; fallthrough; case I2C_BLOCK_BYTES_ERR_IND: /* Master tx finished and all transmit bytes were sent */ @@ -2223,6 +2226,7 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev, debugfs_create_u64("rec_succ_cnt", 0444, d, &bus->rec_succ_cnt); debugfs_create_u64("rec_fail_cnt", 0444, d, &bus->rec_fail_cnt); debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt); + debugfs_create_u64("tx_complete_cnt", 0444, d, &bus->tx_complete_cnt); bus->debugfs = d; } From patchwork Tue Dec 21 17:43:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sui Chen X-Patchwork-Id: 526728 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0FA45C433F5 for ; Tue, 21 Dec 2021 17:44:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240529AbhLURoe (ORCPT ); Tue, 21 Dec 2021 12:44:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35400 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240504AbhLURod (ORCPT ); Tue, 21 Dec 2021 12:44:33 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A74B9C061574 for ; Tue, 21 Dec 2021 09:44:32 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id u13-20020a17090a450d00b001b1e6726fccso1974564pjg.0 for ; Tue, 21 Dec 2021 09:44:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=yQVcC55OoadpUPJm5lgEHKled6Uu3AS/23JgHN3JweM=; b=GiDwlFY4PevNZXTZxjYnA+LOJzLzost4vNTVzsrNvamLrnwxkYJYAaMz4PD5VxO/tq fXiy+gfDB17AzOm9ExFT9g4+nJMacXzvQmHqhjP1i2CrisMeEvfX7zcFqxRtGF/i38x5 DbDdCZEdrp8ldNKoPo/hCA3DepLd8fQ882lLlCSRVrU4P44PKojnydVKH/7l/jMOAeJ4 /2BuLQt3Nh8bFYth2C+kGhwX8fh897taYbjW+WT/jfhohd4okyf4OLXhpWc8GwGcQOZo LJqY5OqXrioPP7FVVEor+qksnpyMr36QEDSYU0bhHD6oi1DjTcg8ZYLGjhAc+6HxEhSc 8AyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=yQVcC55OoadpUPJm5lgEHKled6Uu3AS/23JgHN3JweM=; b=vjzhOXN51a41adQpbEY/k5bSU/WzkzcHEysU93KL3HZFRmbFfDKMRnmhYCUdD2uMWE TPLDKdB0eCSh5qOOeibb6ED6iqOSwOMtgkNfZJsTJXIQ5I9qN9Y5lwpLL3sXVww5+APd Nbe525GrWdU+etAMerELX+uQ6gEfrDDa5j7iTqqMg5fnT0KL2aLBW1gf30iR8kQ/Zvh7 dfhW442BXn/PDN7ZGF4ALo1i7DccQXfbHAS4/CSZBYyzAeCkMWbrS59ucxbAgkPj/vr8 I5icigIhcWugsK0q/v/SiE4JqgpKtZqYlkpPfs9UR77KqQ3bdXHNQiFDcAiY5Ker76se GUkg== X-Gm-Message-State: AOAM531+RPz48S2ZhhzJROOpI+1ZLPA5v2DHWHX9m/K3A5Lf0zmjH1LR 35BGF0LyFF7oPfINQKzlr3AhNRDgHBaH X-Google-Smtp-Source: ABdhPJy1QkR7/Vg/h/zj3GiBFEnfoUAbZdCXSJyAJqx7x75BiMeFHNxASCd5GeldXB+EfbmjW5UqUdXWfz5k X-Received: from suichen.svl.corp.google.com ([2620:15c:2c5:13:19fd:5987:f46f:7488]) (user=suichen job=sendgmr) by 2002:a17:90b:798:: with SMTP id l24mr5338989pjz.122.1640108672149; Tue, 21 Dec 2021 09:44:32 -0800 (PST) Date: Tue, 21 Dec 2021 09:43:44 -0800 In-Reply-To: <20211221174344.1249202-1-suichen@google.com> Message-Id: <20211221174344.1249202-4-suichen@google.com> Mime-Version: 1.0 References: <20211221174344.1249202-1-suichen@google.com> X-Mailer: git-send-email 2.34.1.307.g9b7440fafd-goog Subject: [RFC Patch v3 3/3] add npcm7xx debug counters as sysfs attributes From: Sui Chen To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, openbmc@lists.ozlabs.org, joel@jms.id.au, andrew@aj.id.au, tali.perry1@gmail.com, benjaminfair@google.com, krellan@google.com, Sui Chen Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org This change adds npcm7xx debug counters as sysfs attributes using the i2c_adapter_stats_register_counter function. Signed-off-by: Sui Chen Reviewed-by: Tali Perry --- drivers/i2c/busses/i2c-npcm7xx.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/i2c/busses/i2c-npcm7xx.c b/drivers/i2c/busses/i2c-npcm7xx.c index cc7abd0b870be..c3ba5f3d33af1 100644 --- a/drivers/i2c/busses/i2c-npcm7xx.c +++ b/drivers/i2c/busses/i2c-npcm7xx.c @@ -2228,6 +2228,15 @@ static void npcm_i2c_init_debugfs(struct platform_device *pdev, debugfs_create_u64("timeout_cnt", 0444, d, &bus->timeout_cnt); debugfs_create_u64("tx_complete_cnt", 0444, d, &bus->tx_complete_cnt); + /* register debug counters in sysfs */ + i2c_adapter_stats_register_counter(&bus->adap, "ber_cnt", &bus->ber_cnt); + i2c_adapter_stats_register_counter(&bus->adap, "nack_cnt", &bus->nack_cnt); + i2c_adapter_stats_register_counter(&bus->adap, "rec_succ_cnt", &bus->rec_succ_cnt); + i2c_adapter_stats_register_counter(&bus->adap, "rec_fail_cnt", &bus->rec_fail_cnt); + i2c_adapter_stats_register_counter(&bus->adap, "timeout_cnt", &bus->timeout_cnt); + i2c_adapter_stats_register_counter(&bus->adap, "i2c_speed", &bus->bus_freq); + i2c_adapter_stats_register_counter(&bus->adap, "tx_complete_cnt", &bus->tx_complete_cnt); + bus->debugfs = d; }