Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1289913imm; Fri, 5 Oct 2018 23:54:33 -0700 (PDT) X-Google-Smtp-Source: ACcGV62ySOVGpJQMSQrutxDPi3hRuaC0GD7M6eo/aTwxoIYP7jwZ5ZMPbtOcKO7Opzx3QDc6irgl X-Received: by 2002:a63:9712:: with SMTP id n18-v6mr12993919pge.69.1538808873547; Fri, 05 Oct 2018 23:54:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538808873; cv=none; d=google.com; s=arc-20160816; b=ztfOOUBU6vSq8fXOYx/tG8PT+cUjLqgc8sAY5oNThiB1vdXZAygTuQMEOkK2IMgoyG uDaL4m7CiIgFrpHWFbBwlulSfmmOXgwHAv9OjWRSLHoUzYL9iIhQ1vW32iDGm4du8FaK fpWOlfXGoSbGPSjPkb/twhzCa+HFGqxWOIpI6uR+Llxk1UYJPF2zh90kBmVuw8exopu7 ViXuAyTp6CkPHm7nWD+JeBGQrRk2u03zcC3AUi9hKNAcx3sAuoj/P/S7/hqFJRPoV1Me CxgcLAr8BfRYV4miWEUdru+KDdYO9KjwLqN7PcmMf0bOeKauPrvlj1hmQV68ur9IUYZj 45pw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=qQqN/65hXEY8kbE9QFL+Cchl0VqDvmPqMsVQ+lkSyEg=; b=ULO6s0h/Fo/K4i3yEH2wd6AQVhp0ZAKeY/DllSO/0/9UkWoeLL4oHpgtKcOBE+a2Rb O7v1x+mCIjh+iFcQk+D85BaHB2hJK+H/eU7F6LsOWiNwyX9hArwL3rI1VCf5Q+k2300f s6oxaKp634ebkrD2JCj8qAwuwHglIXbqA//JhLABBQ9+5tVYBimNGroN2903YCS9ezNc Le8g2WRbAwprOymcrzxNRZ8/N4iTc242rLyFBM9mYpLmf3cC4dXln6sJx7QE7eLt6McZ 0NcPnfBlq8m0BsjZ8IqVoAqN2RcH5RvuvdJnIw2SqwiJQpykSju2SlNSjhvzKxCNOaK5 VSow== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e7-v6si11055982pgn.82.2018.10.05.23.54.18; Fri, 05 Oct 2018 23:54:33 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727848AbeJFN4Q (ORCPT + 99 others); Sat, 6 Oct 2018 09:56:16 -0400 Received: from mga03.intel.com ([134.134.136.65]:23260 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726913AbeJFN4K (ORCPT ); Sat, 6 Oct 2018 09:56:10 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 05 Oct 2018 23:53:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,347,1534834800"; d="scan'208";a="79200387" Received: from rajneesh-desk.iind.intel.com ([10.223.86.34]) by orsmga008.jf.intel.com with ESMTP; 05 Oct 2018 23:52:46 -0700 From: Rajneesh Bhardwaj To: platform-driver-x86@vger.kernel.org Cc: dvhart@infradead.org, andy@infradead.org, linux-kernel@vger.kernel.org, rajneesh.bhardwaj@intel.com, Rajneesh Bhardwaj Subject: [PATCH v2 3/4] platform/x86: intel_pmc_core: Decode Snoop / Non Snoop LTR Date: Sat, 6 Oct 2018 12:21:12 +0530 Message-Id: <20181006065113.669-3-rajneesh.bhardwaj@linux.intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181006065113.669-1-rajneesh.bhardwaj@linux.intel.com> References: <20181006065113.669-1-rajneesh.bhardwaj@linux.intel.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The LTR values follow PCIE LTR encoding format and can be decoded as per https://pcisig.com/sites/default/files/specification_documents/ECN_LatencyTolnReporting_14Aug08.pdf This adds support to translate the raw LTR values as read from the PMC to meaningful values in nanosecond units of time. Signed-off-by: Rajneesh Bhardwaj --- Changes in v2: * Get rid of union and bitfields to decode LTR and use FIELD_GET macro * Change get_ltr_scale to convert_ltr_scale. * Other style fixes and misc. improvements suggested by Andy for v1. drivers/platform/x86/intel_pmc_core.c | 64 +++++++++++++++++++++++++-- drivers/platform/x86/intel_pmc_core.h | 5 +++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/drivers/platform/x86/intel_pmc_core.c b/drivers/platform/x86/intel_pmc_core.c index c616cfedf2be..fbcab53456f3 100644 --- a/drivers/platform/x86/intel_pmc_core.c +++ b/drivers/platform/x86/intel_pmc_core.c @@ -21,6 +21,7 @@ #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt #include +#include #include #include #include @@ -650,16 +651,73 @@ static int pmc_core_slps0_dbg_show(struct seq_file *s, void *unused) } DEFINE_SHOW_ATTRIBUTE(pmc_core_slps0_dbg); +static u32 convert_ltr_scale(u32 val) +{ + u32 scale = 0; + /* + * As per PCIE specification supporting document + * ECN_LatencyTolnReporting_14Aug08.pdf the Latency + * Tolerance Reporting data payload is encoded in a + * 3 bit scale and 10 bit value fields. Values are + * multiplied by the indicated scale to yield an absolute time + * value, expressible in a range from 1 nanosecond to + * 2^25*(2^10-1) = 34,326,183,936 nanoseconds. + * + * scale encoding is as follows: + * + * ---------------------------------------------- + * |scale factor | Multiplier (ns) | + * ---------------------------------------------- + * | 0 | 1 | + * | 1 | 32 | + * | 2 | 1024 | + * | 3 | 32768 | + * | 4 | 1048576 | + * | 5 | 33554432 | + * | 6 | Invalid | + * | 7 | Invalid | + * ---------------------------------------------- + */ + if (val > 5) + pr_warn("Invalid LTR scale factor.\n"); + else + scale = 1U << (5 * (val)); + + return scale; +} + static int pmc_core_ltr_show(struct seq_file *s, void *unused) { struct pmc_dev *pmcdev = s->private; const struct pmc_bit_map *map = pmcdev->map->ltr_show_sts; + u64 decoded_snoop_ltr, decoded_non_snoop_ltr; + u32 ltr_raw_data, scale, val; + u16 snoop_ltr, nonsnoop_ltr; int index; for (index = 0; map[index].name ; index++) { - seq_printf(s, "IP %-2d :%-32s\tRAW LTR: 0x%x\n", index, - map[index].name, - pmc_core_reg_read(pmcdev, map[index].bit_mask)); + decoded_snoop_ltr = decoded_non_snoop_ltr = 0; + ltr_raw_data = pmc_core_reg_read(pmcdev, + map[index].bit_mask); + snoop_ltr = ltr_raw_data & ~MTPMC_MASK; + nonsnoop_ltr = (ltr_raw_data >> 0x10) & ~MTPMC_MASK; + + if (FIELD_GET(LTR_REQ_NONSNOOP, ltr_raw_data)) { + scale = FIELD_GET(LTR_DECODED_SCALE, nonsnoop_ltr); + val = FIELD_GET(LTR_DECODED_VAL, nonsnoop_ltr); + decoded_non_snoop_ltr = val * convert_ltr_scale(scale); + } + + if (FIELD_GET(LTR_REQ_SNOOP, ltr_raw_data)) { + scale = FIELD_GET(LTR_DECODED_SCALE, snoop_ltr); + val = FIELD_GET(LTR_DECODED_VAL, snoop_ltr); + decoded_snoop_ltr = val * convert_ltr_scale(scale); + } + + seq_printf(s, "IP %-2d :%-24s\tRaw LTR: 0x%-16x\t Non-Snoop LTR (ns): %-16llu\t Snoop LTR (ns): %-16llu\n", + index, map[index].name, ltr_raw_data, + decoded_non_snoop_ltr, + decoded_snoop_ltr); } return 0; } diff --git a/drivers/platform/x86/intel_pmc_core.h b/drivers/platform/x86/intel_pmc_core.h index 7f8181057ec8..cc49cd4c86e9 100644 --- a/drivers/platform/x86/intel_pmc_core.h +++ b/drivers/platform/x86/intel_pmc_core.h @@ -177,6 +177,11 @@ enum ppfear_regs { #define CNP_PMC_LTR_EMMC 0x1BF4 #define CNP_PMC_LTR_UFSX2 0x1BF8 +#define LTR_REQ_NONSNOOP BIT(31) +#define LTR_REQ_SNOOP BIT(15) +#define LTR_DECODED_VAL GENMASK(9, 0) +#define LTR_DECODED_SCALE GENMASK(12, 10) + struct pmc_bit_map { const char *name; u32 bit_mask; -- 2.17.1