From patchwork Wed Jun 20 23:41:44 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rajat Jain X-Patchwork-Id: 10478885 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 4CEC2601D7 for ; Wed, 20 Jun 2018 23:43:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3E8E628CD7 for ; Wed, 20 Jun 2018 23:43:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3291028CEB; Wed, 20 Jun 2018 23:43:16 +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 AFBC728CD7 for ; Wed, 20 Jun 2018 23:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933161AbeFTXmF (ORCPT ); Wed, 20 Jun 2018 19:42:05 -0400 Received: from mail-yw0-f202.google.com ([209.85.161.202]:38596 "EHLO mail-yw0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933149AbeFTXmB (ORCPT ); Wed, 20 Jun 2018 19:42:01 -0400 Received: by mail-yw0-f202.google.com with SMTP id f186-v6so842239ywb.5 for ; Wed, 20 Jun 2018 16:42:01 -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=aeGtqVA91iwtDMjXI2Tp7xDl955opSJ2XwDJ6yD6tUc=; b=ETa5Uphu690DkbWfHmCYYR4WjguyWGGoliqY/4DvkDKsFdvVLUezt4glzVknqRLCgn CMuudoq3dw7YC7P2SevsPHgkvn2/sJnuRNijMfr1HEN36TPi0IvXnNvQIq/vJkSh6qoz cdGiaA/Xy4CIk5GEHTTHjLex41TlrUdQ4F3/6V9oWMwbrI9S/123UofFAc8OdUuP2B6M YJ9NEy5bTFFoSxvcgaAUb8eO63S5HMjSfqKepGnWphiYSWCwtPZExKdWaeTjP9S16Q9z dJuyUZZtisiilYQvJnY/dZ2lzzqCcKYryG4ElDW1hBm29DWr1a6YWybGOZgUxZufXuT2 wq4Q== 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=aeGtqVA91iwtDMjXI2Tp7xDl955opSJ2XwDJ6yD6tUc=; b=ZBtRf5i4DbhxsMDfkIcjMtEKhkC2Topc8IESqfcPW5Gmvoy8tl8QTOXTup9Ks13JZY d6Ryrv2c2XI0kWXONjvNN83t0/BpKVj/s8u5gCLuIFX5jyH3XUaAU76NyfpDZDlqgutA w8462Oz/oRq1/aBKZDIGshq0VtSjTPjsqIgDWiwC9Sgl/8h2134wra3R4eQdxSngArMq xJg/mOn4oUwIeA5YODaaBuZ82Ceu/dKqCxlMzbT3M5DMQV/y9QX1OEEpcUTQdiJMuz/c SmJXbdhQM/Ex46ZHXb0N3Nz+BTHX6EkD8ofQQvsFAPKZ1TeTWX9u7J1GkjbCYaAoxA5F 6D1w== X-Gm-Message-State: APt69E2Zeb2xvmK7YkX8QNzZLbbbyh96H2A3icpMd4qmAqhPO5OyLugD 3okfZSDydVj8eZbxwIDH2qyGDfV9T8nH X-Google-Smtp-Source: ADUXVKLqHNODD22WIXP7Q4E0ZW9E4vvqB1ioWqZhQeKBshouIdg2vw0pecU+4vEvZbry2ZW1dJ5kaq3Wwh4R MIME-Version: 1.0 X-Received: by 2002:a0d:c787:: with SMTP id j129-v6mr6342954ywd.11.1529538121086; Wed, 20 Jun 2018 16:42:01 -0700 (PDT) Date: Wed, 20 Jun 2018 16:41:44 -0700 In-Reply-To: <20180620234147.48438-1-rajatja@google.com> Message-Id: <20180620234147.48438-2-rajatja@google.com> References: <20180522222805.80314-1-rajatja@google.com> <20180620234147.48438-1-rajatja@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog Subject: [PATCH v5 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 --- v5: same as v4 v4: Same as v3 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)