Received: by 2002:ac0:a581:0:0:0:0:0 with SMTP id m1-v6csp1345691imm; Wed, 20 Jun 2018 16:29:56 -0700 (PDT) X-Google-Smtp-Source: ADUXVKLwER4RtQdCu/KWDyydb5scUHU7BHGT6qXES4wi2llmTsYzg+rLQy8kZbWtx2iYWBBu/veE X-Received: by 2002:a62:9652:: with SMTP id c79-v6mr25085104pfe.114.1529537396936; Wed, 20 Jun 2018 16:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1529537396; cv=none; d=google.com; s=arc-20160816; b=ePM8mcs0MgvpUONbcMhCxkahYEhOJxNz5WbFxjAs9Rv0mAjWVroX0wHgEara8EfFnb 3vSCMreBYvQOUtaQi6J+dWLiN5Iynv3CvUr+KrzV/o5TtqoTcr2Tfif80tMZrW6iogMx 9vlQ8FGtOhvyQjxngHg9d/ITpFsdDfaRFAmhhS2vHzvSh05FKLv1A0VTAFhoXStLfHQ5 TnsEJ/qGoGUuup3+AasHaBdUVlGsd6FizjFfL4R+sc4BiOaxqrND8jJ/10jvzcb8dexS iOtP6jEKLdU2gQdMtqP8V+MI5zoS2jUPPpqjye62ddE9YOFBpKSgTHaanJllWna4/cyE eWTw== 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=XVWBiQoW73MDz+ss3et58XuC+WEmn3lVaP0MbEEILLI=; b=SRbDoTg235zu0XH4I6doTbt6bgyLJPXK9HVlcJ+1h10H1KwPRiN5UhaOhH0kmF/D7e FTS9Q2A8EWy9RiFEKQQ4Me7g0DVDB9MRGy7W2k7TLhqDSmGyyIO+VMcaPH9wdhbOTsR0 v0aykNB6OdmOHccp7GIrY+KB2cW6hjH8hOMx3dwiPYIED6rJwL1A8dOUNGp/VOS1zKCW PfDP+VAKs7zyPEKznBvkNrowD/KrdY5isVc3wstC7qVPYDdx+8tIgDemr6pkkzNnC4tI pGXJB85PTVZHJ+Y8prW37LAiKuYugwHDxh9ksEJuQRLN42IgJ2W6dxeJjr2QyUpG4jet 6F/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=pFC0dKmq; 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 b60-v6si3262911plc.270.2018.06.20.16.29.42; Wed, 20 Jun 2018 16:29:56 -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=pFC0dKmq; 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 S932845AbeFTX2z (ORCPT + 99 others); Wed, 20 Jun 2018 19:28:55 -0400 Received: from mail-qt0-f202.google.com ([209.85.216.202]:42493 "EHLO mail-qt0-f202.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932789AbeFTX2v (ORCPT ); Wed, 20 Jun 2018 19:28:51 -0400 Received: by mail-qt0-f202.google.com with SMTP id f8-v6so1025630qth.9 for ; Wed, 20 Jun 2018 16:28:50 -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=XVWBiQoW73MDz+ss3et58XuC+WEmn3lVaP0MbEEILLI=; b=pFC0dKmqt58m89T35/999ozJSb8PiopkaThWvGSoyIUVzCHlcnzkZxHNxnsgesYCtL 7j6Ku36lRZKdB6yW1/IpPkFv0XBeGnNypv7bYtp6NN0iGh4FQJW7XmZ4tGlBCXwmxk4I smkfxvrmemRDvUHUg5FW7DoUe5boFn7au6V3ByH9Z5+F6p/Wzq6lzhSWxo5uCcHND6Y8 k67Ka9uMDWhHiPO3uw/x4y4qxBUL2L3HTu4nYjhUUtOTqx7cnObv5YZSX0tIUR45mI/G 1/nDkHQQnR3QMDgExBfVcaKsiz3KUC6Eg31mp0Nxdg4pslqJeIy7c5wZgIkWd8SKWSQC ADHA== 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=XVWBiQoW73MDz+ss3et58XuC+WEmn3lVaP0MbEEILLI=; b=eNeMWtwF8hIcNaizh9Km/J4jcM2CUN6zqQRuAgp1WyIUAXom5UgLNpw8hUeGEkFbJL rb05SpB76iWzIGdHiiH6KPWetwEmx0BXEjYiAGg0ZjSrxhza0+Yt4rN/+lrLcl5KdXBL 1W30FMRfOGZ/4TaABk1cibK25jsZaMhICa+bcyvR7O92jCFeGZuvXzuaRqqUMrEKn8Rv xcuhYtkJhh9+L3NNGj+Sp3tOeHkYXY5Eu0pw74v+eYtdpFJ/5ryoLgYLR8zENrE9ezyD sFwqiAxZpOxYCUFwuDO6qM4kh0eVDqyXH3jC7pqsKM60oeXaqb7vEygkSGl1BxInWOnk wOAg== X-Gm-Message-State: APt69E00DfY1ynrTBpRvjunqDf55TWPliWeItqjk9mr3zWMKnyFYj0mm YHX1fYqtkFRlyb129H1fsuE3n3ZsT93M MIME-Version: 1.0 X-Received: by 2002:ac8:2cf2:: with SMTP id 47-v6mr12275854qtx.44.1529537330067; Wed, 20 Jun 2018 16:28:50 -0700 (PDT) Date: Wed, 20 Jun 2018 16:28:38 -0700 In-Reply-To: <20180620232841.43922-1-rajatja@google.com> Message-Id: <20180620232841.43922-2-rajatja@google.com> References: <20180522222805.80314-1-rajatja@google.com> <20180620232841.43922-1-rajatja@google.com> X-Mailer: git-send-email 2.18.0.rc1.244.gcf134e6275-goog Subject: [PATCH v4 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 --- 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) -- 2.18.0.rc1.244.gcf134e6275-goog