Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp158122imm; Tue, 19 Jun 2018 18:13:55 -0700 (PDT) X-Google-Smtp-Source: ADUXVKKN93pYEWC3PMMg4t+lozUF7bu+lSoxhZHdATU1KsmxiGIW5rTyjukLIA8AHB1GYQzeZ5+8 X-Received: by 2002:a65:5185:: with SMTP id h5-v6mr17151740pgq.0.1529457235452; Tue, 19 Jun 2018 18:13:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529457235; cv=none; d=google.com; s=arc-20160816; b=oIs+yqTc6Eu/ojMUIRIvnZRhdkq/neuNpmnNzIYD/TAMbRUoWV+Q7rvJ6JycUmAQXJ Q1li3eB0O2bq6vFTVFYjb2w1J49XluI/gDwfLDBWQvDL3CmyjwE9Ind8kggmbCkCBKlt fcARbiByN8i3guvBwmsaYvImK+yHCWrwD3oiLMP0YSgjCOXrEj/AVdm561b19HWKceNl PHrsk6Ki/mkwDvUbfXNx1ooGfouLMhZhbtyNXddFqJukLpAAs0PGXQZ3h0SIDGe54jfp 4IAevO9UMtKodWMZ+bsrlmofVSui8usNzEbxV4JPFgw3ylPbMwV3Y7nBV7YVPHjHBMkF sBww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references:message-id :in-reply-to:date:mime-version:dkim-signature :arc-authentication-results; bh=RK6ATGESWnFl890Gleu1SQUKuxXTcyn7OVQIB2xUMTY=; b=SnPyO42IkkZiSbxG9kk3s8nZ+arXHfrxZSdKq/M9CVoK/BSMN5SBCXoWcz4CMQGlCD 5puhj77T+7LQSXIndmtzlgnuvFxYP7o6y1IGRUGaiIpcvipoHr/o+OXnScT9DvaYGIpj 1It4g6ZzgUxrra2SUH/xaeBJYBUoi2XhyZT50zHdas34Tt64+L2Tmoes1mrmPR6BZ9uh IuS99ftWCRW/Id22WhRdUtwY+yg/d5A669MNcScSLVAW46QkiQNm8hpC6Hlu0wyAehnE zhDZlbBpUe60S+vYjfjVSfn0mTWHFzKJhtxiC2oTPxrESwoiYQ5HMWRwxZcuqqugrdTm 9Saw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Qp+6iAi1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e4-v6si973486pfn.322.2018.06.19.18.13.29; Tue, 19 Jun 2018 18:13:55 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=Qp+6iAi1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753995AbeFTBM0 (ORCPT + 99 others); Tue, 19 Jun 2018 21:12:26 -0400 Received: from mail-qt0-f201.google.com ([209.85.216.201]:36096 "EHLO mail-qt0-f201.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753741AbeFTBMU (ORCPT ); Tue, 19 Jun 2018 21:12:20 -0400 Received: by mail-qt0-f201.google.com with SMTP id d14-v6so1396621qtn.3 for ; Tue, 19 Jun 2018 18:12:19 -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=AQZQqRRapzooZUo8jDLyT94EPB5KjtyTQmSNvu1yzJnKDK50C5HwPDjZ78/60nqQ6m dEakLTWnp/P3LGsoS0QnsQxKKhnBweCWx1qsc522czNaoi0sFaLeyWZEsZltP/coGNIZ Yv1iS2dgR2GWkb0bk0QjBbRxqQATrVYa7/xyfzXCil5wkU78mav5oCCUdV3gyOiBZ5dG UZYlcGaZsi/QB8GcHBnYvyrKjA8Xx7vDnpXyC1Pntle5mF4b2OgRO5BmbyMBDgPjIIuO l3LiIpfHN+MVNqGMmBy5anpIa0TEBezcBegMAykt8Vd6AbrnVVc7oZPpYf21ak0pd4vz vU6w== X-Gm-Message-State: APt69E3bwYfvO29NZPsrs1obVgxWgRZQtTq5SNwClMCTT552ggouw7Lj CmpskRFjmX37Xh2OS6rIvPOMh4X7pSZ1 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 Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.18.0.rc1.244.gcf134e6275-goog