From patchwork Wed Jun 20 01:12:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 10475747 X-Patchwork-Delegate: bhelgaas@google.com 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 7B29F601D7 for ; Wed, 20 Jun 2018 01:12:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6BC78287FA for ; Wed, 20 Jun 2018 01:12:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5FAE12882D; Wed, 20 Jun 2018 01:12:28 +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=-15.5 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI, USER_IN_DEF_DKIM_WL autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E7D4F287FA for ; Wed, 20 Jun 2018 01:12:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753906AbeFTBMX (ORCPT ); Tue, 19 Jun 2018 21:12:23 -0400 Received: from mail-qk0-f201.google.com ([209.85.220.201]:54764 "EHLO mail-qk0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752784AbeFTBMU (ORCPT ); Tue, 19 Jun 2018 21:12:20 -0400 Received: by mail-qk0-f201.google.com with SMTP id s133-v6so1394405qke.21 for ; Tue, 19 Jun 2018 18:12:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:date:in-reply-to:message-id:references:subject:from:to :cc; bh=RK6ATGESWnFl890Gleu1SQUKuxXTcyn7OVQIB2xUMTY=; b=Qp+6iAi1SwAnew1/Hy4n1LU5kdqlJHskjpz+7bBJSBXb+y6Q+8udPAikuyLKnnGyBQ NVgGZ3/zeSUY0rixV2CxKeLKszkAPQGNnUUbc4kYj9WVyQSEWzYJTyUnkz5spcWOyWCX X7anACled8Ym9xlmqbzS4odPq61a0M9R3vH9IYgjwes1KQK/TVpXEOnDWltqpVjmphVq 1aCdJGbjWekF0yOE9uI593Bri0YMnZiZlppfFBpsrJ2Pkh2MEaI80wBWNaCJRHS8kvWD VeA57Ajo3fPCtbCye56i4CksZY8MJZ01jjTUZg/+7kom6M28JBClUt2Kz7+Jny/oLcZs hH3w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:date:in-reply-to:message-id :references:subject:from:to:cc; bh=RK6ATGESWnFl890Gleu1SQUKuxXTcyn7OVQIB2xUMTY=; b=QZndLur/OsCxhclIB+6hby10U8Qw9/oLBjb/7xb3cZwc+f0qfCdCreWHVYxhxRPu/Y YhH8BUOWNsKhhXStrR2J8BapXvZFEqUNDOJeMva5kZq+YvU1pCel5SXzdh/g/cs7YwQV CgTYAcBl0n0BY9e9dQ2OgZbLLVBmhpCu5Chdey+GPTyrTQXFSv7j4X8XKS9R5EIWga8q oWRIMvWPi9RTZs6rs0LhF0Tlr8DhkpoXvvUY8lMw2YEveBfxZ9wor134tRE0HeumVdII IwPluapuUTCZFBX7HSDtPLk+1D0kLvw8KdhATrax2AZHLKe4MbB1sVw675tbDv6+yQy+ 28Ug== X-Gm-Message-State: APt69E0LdjXYA6tCUswhukjX4fRzyOfWTxmNttATCUXApiphkcV36rMV 6150sSsyh2PuwyLxLd9jnuIYgkSZiSuo X-Google-Smtp-Source: ADUXVKKO/83391Kxv7pZWXpULr38eQHVsSQ5TsLY2pAve8Zuli4d6Yxhj9J1lC4wNrb97p3gFx0vod2nB5Y7 MIME-Version: 1.0 X-Received: by 2002:a0c:d4cf:: with SMTP id y15-v6mr10231381qvh.16.1529457139450; Tue, 19 Jun 2018 18:12:19 -0700 (PDT) Date: Tue, 19 Jun 2018 18:12:07 -0700 In-Reply-To: <20180620011210.254601-1-rajatja@google.com> Message-Id: <20180620011210.254601-2-rajatja@google.com> References: <20180619221651.GH33049@bhelgaas-glaptop.roam.corp.google.com> <20180620011210.254601-1-rajatja@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog Subject: [PATCH v3 2/5] PCI/AER: Add sysfs stats for AER capable devices From: Rajat Jain To: Bjorn Helgaas , Jonathan Corbet , Philippe Ombredanne , Kate Stewart , Thomas Gleixner , Greg Kroah-Hartman , Frederick Lawler , Oza Pawandeep , Keith Busch , Alexandru Gagniuc , Thomas Tai , "Steven Rostedt (VMware)" , linux-pci@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Jes Sorensen , Kyle McMartin , rajatxjain@gmail.com, helgaas@kernel.org Cc: Rajat Jain Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the following AER sysfs stats to represent the counters for each kind of error as seen by the device: dev_total_cor_errs dev_total_fatal_errs dev_total_nonfatal_errs Signed-off-by: Rajat Jain --- v3: Merge everything in aer.c, use "%llu" in place of "%llx" drivers/pci/pci-sysfs.c | 3 ++ drivers/pci/pci.h | 4 ++- drivers/pci/pcie/aer.c | 74 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+), 1 deletion(-) diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c index 0c4653c1d2ce..9f1cb9051d7d 100644 --- a/drivers/pci/pci-sysfs.c +++ b/drivers/pci/pci-sysfs.c @@ -1746,6 +1746,9 @@ static const struct attribute_group *pci_dev_attr_groups[] = { #endif &pci_bridge_attr_group, &pcie_dev_attr_group, +#ifdef CONFIG_PCIEAER + &aer_stats_attr_group, +#endif NULL, }; diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h index c358e7a07f3f..9a28ec600225 100644 --- a/drivers/pci/pci.h +++ b/drivers/pci/pci.h @@ -181,7 +181,9 @@ extern const struct attribute_group *pci_dev_groups[]; extern const struct attribute_group *pcibus_groups[]; extern const struct device_type pci_dev_type; extern const struct attribute_group *pci_bus_groups[]; - +#ifdef CONFIG_PCIEAER +extern const struct attribute_group aer_stats_attr_group; +#endif /** * pci_match_one_device - Tell if a PCI device structure has a matching diff --git a/drivers/pci/pcie/aer.c b/drivers/pci/pcie/aer.c index f9fa994b6c33..ce0d675d7bd3 100644 --- a/drivers/pci/pcie/aer.c +++ b/drivers/pci/pcie/aer.c @@ -573,6 +573,79 @@ static const char *aer_agent_string[] = { "Transmitter ID" }; +#define aer_stats_aggregate_attr(field) \ + static ssize_t \ + field##_show(struct device *dev, struct device_attribute *attr, \ + char *buf) \ +{ \ + struct pci_dev *pdev = to_pci_dev(dev); \ + return sprintf(buf, "%llu\n", pdev->aer_stats->field); \ +} \ +static DEVICE_ATTR_RO(field) + +aer_stats_aggregate_attr(dev_total_cor_errs); +aer_stats_aggregate_attr(dev_total_fatal_errs); +aer_stats_aggregate_attr(dev_total_nonfatal_errs); + +static struct attribute *aer_stats_attrs[] __ro_after_init = { + &dev_attr_dev_total_cor_errs.attr, + &dev_attr_dev_total_fatal_errs.attr, + &dev_attr_dev_total_nonfatal_errs.attr, + NULL +}; + +static umode_t aer_stats_attrs_are_visible(struct kobject *kobj, + struct attribute *a, int n) +{ + struct device *dev = kobj_to_dev(kobj); + struct pci_dev *pdev = to_pci_dev(dev); + + if (!pdev->aer_stats) + return 0; + + return a->mode; +} + +const struct attribute_group aer_stats_attr_group = { + .name = "aer_stats", + .attrs = aer_stats_attrs, + .is_visible = aer_stats_attrs_are_visible, +}; + +static void pci_dev_aer_stats_incr(struct pci_dev *pdev, + struct aer_err_info *info) +{ + int status, i, max = -1; + u64 *counter = NULL; + struct aer_stats *aer_stats = pdev->aer_stats; + + if (!aer_stats) + return; + + switch (info->severity) { + case AER_CORRECTABLE: + aer_stats->dev_total_cor_errs++; + counter = &aer_stats->dev_cor_errs[0]; + max = AER_MAX_TYPEOF_CORRECTABLE_ERRS; + break; + case AER_NONFATAL: + aer_stats->dev_total_nonfatal_errs++; + counter = &aer_stats->dev_uncor_errs[0]; + max = AER_MAX_TYPEOF_UNCORRECTABLE_ERRS; + break; + case AER_FATAL: + aer_stats->dev_total_fatal_errs++; + counter = &aer_stats->dev_uncor_errs[0]; + max = AER_MAX_TYPEOF_UNCORRECTABLE_ERRS; + break; + } + + status = (info->status & ~info->mask); + for (i = 0; i < max; i++) + if (status & (1 << i)) + counter[i]++; +} + static void __print_tlp_header(struct pci_dev *dev, struct aer_header_log_regs *t) { @@ -605,6 +678,7 @@ static void __aer_print_error(struct pci_dev *dev, pci_err(dev, " [%2d] Unknown Error Bit%s\n", i, info->first_error == i ? " (First)" : ""); } + pci_dev_aer_stats_incr(dev, info); } static void aer_print_error(struct pci_dev *dev, struct aer_err_info *info)