[{"id":3683332,"web_url":"http://patchwork.ozlabs.org/comment/3683332/","msgid":"<bc3a5f58-676a-3634-6b8f-bffc91d25265@linux.intel.com>","list_archive_url":null,"date":"2026-04-28T09:27:49","subject":"Re: [PATCH v5 1/3] PCI/ASPM: Add helper to encode L1SS T_POWER_ON\n fields","submitter":{"id":83553,"url":"http://patchwork.ozlabs.org/api/people/83553/","name":"Ilpo Järvinen","email":"ilpo.jarvinen@linux.intel.com"},"content":"On Tue, 28 Apr 2026, Krishna Chaitanya Chundru wrote:\n\n> Add a shared helper to encode the PCIe L1 PM Substates T_POWER_ON\n> parameter into the T_POWER_ON Scale and T_POWER_ON Value fields.\n> \n> This helper can be used by the controller drivers to change the\n> default/wrong value of T_POWER_ON in L1ss capability register to\n> avoid incorrect calculation of LTR_L1.2_THRESHOLD value.\n> \n> The helper converts a T_POWER_ON time specified in microseconds into\n> the appropriate scale/value encoding defined by the PCIe spec r7.0,\n> sec 7.8.3.2. Values that exceed the maximum encodable range are clamped\n> to the largest representable encoding.\n> \n> Tested-by: Shawn Lin <shawn.lin@rock-chips.com>\n> Reviewed-by: Shawn Lin <shawn.lin@rock-chips.com>\n> Signed-off-by: Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>\n> ---\n>  drivers/pci/pci.h       |  6 ++++++\n>  drivers/pci/pcie/aspm.c | 40 ++++++++++++++++++++++++++++++++++++++++\n>  2 files changed, 46 insertions(+)\n> \n> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h\n> index 4a14f88e543a..c379befe1ebe 100644\n> --- a/drivers/pci/pci.h\n> +++ b/drivers/pci/pci.h\n> @@ -1110,6 +1110,7 @@ void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked);\n>  void pcie_aspm_powersave_config_link(struct pci_dev *pdev);\n>  void pci_configure_ltr(struct pci_dev *pdev);\n>  void pci_bridge_reconfigure_ltr(struct pci_dev *pdev);\n> +void pcie_encode_t_power_on(u16 t_power_on_us, u8 *scale, u8 *value);\n>  #else\n>  static inline void pcie_aspm_remove_cap(struct pci_dev *pdev, u32 lnkcap) { }\n>  static inline void pcie_aspm_init_link_state(struct pci_dev *pdev) { }\n> @@ -1118,6 +1119,11 @@ static inline void pcie_aspm_pm_state_change(struct pci_dev *pdev, bool locked)\n>  static inline void pcie_aspm_powersave_config_link(struct pci_dev *pdev) { }\n>  static inline void pci_configure_ltr(struct pci_dev *pdev) { }\n>  static inline void pci_bridge_reconfigure_ltr(struct pci_dev *pdev) { }\n> +static inline void pcie_encode_t_power_on(u16 t_power_on_us, u8 *scale, u8 *value)\n> +{\n> +\t*scale = 0;\n> +\t*value = 0;\n> +}\n>  #endif\n>  \n>  #ifdef CONFIG_PCIE_ECRC\n> diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c\n> index 925373b98dff..457d469b8d49 100644\n> --- a/drivers/pci/pcie/aspm.c\n> +++ b/drivers/pci/pcie/aspm.c\n> @@ -525,6 +525,46 @@ static u32 calc_l12_pwron(struct pci_dev *pdev, u32 scale, u32 val)\n>  \treturn 0;\n>  }\n>  \n> +/**\n> + * pcie_encode_t_power_on - Encode T_POWER_ON into scale and value fields\n> + * @t_power_on_us: T_POWER_ON time in microseconds\n> + * @scale: Encoded T_POWER_ON Scale (0..2)\n> + * @value: Encoded T_POWER_ON Value\n> + *\n> + * T_POWER_ON is encoded as:\n> + *   T_POWER_ON(us) = scale_unit(us) * value\n> + *\n> + * where scale_unit is selected by @scale:\n> + *   0: 2us\n> + *   1: 10us\n> + *   2: 100us\n> + *\n> + * If @t_power_on_us exceeds the maximum representable value, the result\n> + * is clamped to the largest encodable T_POWER_ON.\n> + *\n> + * See PCIe r7.0, sec 7.8.3.2.\n> + */\n> +void pcie_encode_t_power_on(u16 t_power_on_us, u8 *scale, u8 *value)\n\nHi,\n\nI don't know how the type for t_power_on_us was picked but if it was \narbitrary decision, I suggest you just go with 32-bit input.\n\nThat would also remove the u32 -> u16 truncate done in the other patches \nof your series which would potentially corrupt the number (I assume \nnumbers that big would be invalid but they could alias to small u16 \nnumbers).\n\nReviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>\n\n> +{\n> +\tu8 maxv = FIELD_MAX(PCI_L1SS_CAP_P_PWR_ON_VALUE);\n> +\n> +\t/* T_POWER_ON_Value (\"value\") is a 5-bit field with max value of 31. */\n> +\tif (t_power_on_us <= 2 * maxv) {\n> +\t\t*scale = 0; /* Value times 2us */\n> +\t\t*value = DIV_ROUND_UP(t_power_on_us, 2);\n> +\t} else if (t_power_on_us <= 10 * maxv) {\n> +\t\t*scale = 1; /* Value times 10us */\n> +\t\t*value = DIV_ROUND_UP(t_power_on_us, 10);\n> +\t} else if (t_power_on_us <= 100 * maxv) {\n> +\t\t*scale = 2; /* value times 100us */\n> +\t\t*value = DIV_ROUND_UP(t_power_on_us, 100);\n> +\t} else {\n> +\t\t*scale = 2;\n> +\t\t*value = maxv;\n> +\t}\n> +}\n> +EXPORT_SYMBOL(pcie_encode_t_power_on);\n> +\n>  /*\n>   * Encode an LTR_L1.2_THRESHOLD value for the L1 PM Substates Control 1\n>   * register.  Ports enter L1.2 when the most recent LTR value is greater\n> \n>","headers":{"Return-Path":"\n <linux-pci+bounces-53319-incoming=patchwork.ozlabs.org@vger.kernel.org>","X-Original-To":["incoming@patchwork.ozlabs.org","linux-pci@vger.kernel.org"],"Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n unprotected) header.d=intel.com header.i=@intel.com header.a=rsa-sha256\n header.s=Intel header.b=dH+hDT/3;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org\n (client-ip=2600:3c0a:e001:db::12fc:5321; helo=sea.lore.kernel.org;\n envelope-from=linux-pci+bounces-53319-incoming=patchwork.ozlabs.org@vger.kernel.org;\n receiver=patchwork.ozlabs.org)","smtp.subspace.kernel.org;\n\tdkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=\"dH+hDT/3\"","smtp.subspace.kernel.org;\n arc=none smtp.client-ip=198.175.65.21","smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com","smtp.subspace.kernel.org;\n spf=pass smtp.mailfrom=linux.intel.com"],"Received":["from sea.lore.kernel.org (sea.lore.kernel.org\n [IPv6:2600:3c0a:e001:db::12fc:5321])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4g4bYv3dTnz1yHX\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 20:01:39 +1000 (AEST)","from smtp.subspace.kernel.org (conduit.subspace.kernel.org\n [100.90.174.1])\n\tby sea.lore.kernel.org (Postfix) with ESMTP id 8EC26348CD07\n\tfor <incoming@patchwork.ozlabs.org>; Tue, 28 Apr 2026 09:28:25 +0000 (UTC)","from localhost.localdomain (localhost.localdomain [127.0.0.1])\n\tby smtp.subspace.kernel.org (Postfix) with ESMTP id 5A20838B7C4;\n\tTue, 28 Apr 2026 09:28:00 +0000 (UTC)","from mgamail.intel.com (mgamail.intel.com [198.175.65.21])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n\t(No client certificate requested)\n\tby smtp.subspace.kernel.org (Postfix) with ESMTPS id 3AF2438947C;\n\tTue, 28 Apr 2026 09:27:58 +0000 (UTC)","from orviesa005.jf.intel.com ([10.64.159.145])\n  by orvoesa113.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 28 Apr 2026 02:27:58 -0700","from ijarvine-mobl1.ger.corp.intel.com (HELO localhost)\n ([10.245.245.1])\n  by orviesa005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384;\n 28 Apr 2026 02:27:53 -0700"],"ARC-Seal":"i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116;\n\tt=1777368480; cv=none;\n b=coWnZZR+G3nOTz4Y9vBtUBS3wl3kSBNMGncYHMt9cfilzV+777rJ+KFKEC4sEVdct01x3Zsddc/rW6mjpjJkhU7mfhbFTO6VfN5ctdX6yeTruUfMTqXNY0m+uLgpfrQNlSLs/PP5Nw/DF2OKhfAfV9gjUxJIro/rzBzQI/31rSc=","ARC-Message-Signature":"i=1; a=rsa-sha256; d=subspace.kernel.org;\n\ts=arc-20240116; t=1777368480; c=relaxed/simple;\n\tbh=Mo4G/rDgf9z8gYFzvbSXsjnYyCAnDRzNDsLl0L9AnDM=;\n\th=From:Date:To:cc:Subject:In-Reply-To:Message-ID:References:\n\t MIME-Version:Content-Type;\n b=Dn+wDxk6kkmb9U/m1GbR9efO2s5pdrKofh9keaq9+f0118dsGP/2AXSpT09luHWSN7OSjTPAB2MgMvEnHokseWMAGlXmCSdFIj9qZqIP6Cffy5hcFJJDX3WGRU/30LU78Bditd47gmJugN1YyqncNON8KEqyjKYsDPiCn7NX1qg=","ARC-Authentication-Results":"i=1; smtp.subspace.kernel.org;\n dmarc=pass (p=none dis=none) header.from=linux.intel.com;\n spf=pass smtp.mailfrom=linux.intel.com;\n dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com\n header.b=dH+hDT/3; arc=none smtp.client-ip=198.175.65.21","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple;\n  d=intel.com; i=@intel.com; q=dns/txt; s=Intel;\n  t=1777368479; x=1808904479;\n  h=from:date:to:cc:subject:in-reply-to:message-id:\n   references:mime-version;\n  bh=Mo4G/rDgf9z8gYFzvbSXsjnYyCAnDRzNDsLl0L9AnDM=;\n  b=dH+hDT/3BDLK0O7KIrFaGhhV1WsqPOaPcW4pNCLurRrrGm0XnqQDOh++\n   dw0VEbl1NljiwZYPJsZZ8Pm5KbTOaW33SB5uEh6f15Dh/aByFoULVsq6f\n   zZ5cZnsg4OzoGRUygctu1BbbO1VvT57PwhrqLp6huvUegnZZHnJgeiW9n\n   Aq+5NHvDfLu70tHNmPpIMMZX5UYrI/H+/ik3Izvo0J1SMm4XOlXXZ5ywo\n   7Hk7kSNJDJH+Xh0IshEIwlp4ZR3lTCj35+bkD7iiS84oRXBsQj53vVuLG\n   Nl0fhsz68iqfh+QHRuCdFcHcNbK+CBfM34NSlb1VvVqE2FLktENpM50+G\n   A==;","X-CSE-ConnectionGUID":["MrIp7kANSV+4se2aIhtzxg==","K4NEpT2WQzyTicXVDSfP2Q=="],"X-CSE-MsgGUID":["qpQpBsarTISZGBkOj5Aabw==","2dnTrdfrRQ6g/LP+sNiiPg=="],"X-IronPort-AV":["E=McAfee;i=\"6800,10657,11769\"; a=\"78162000\"","E=Sophos;i=\"6.23,203,1770624000\";\n   d=\"scan'208\";a=\"78162000\"","E=Sophos;i=\"6.23,203,1770624000\";\n   d=\"scan'208\";a=\"238931536\""],"X-ExtLoop1":"1","From":"=?utf-8?q?Ilpo_J=C3=A4rvinen?= <ilpo.jarvinen@linux.intel.com>","Date":"Tue, 28 Apr 2026 12:27:49 +0300 (EEST)","To":"Krishna Chaitanya Chundru <krishna.chundru@oss.qualcomm.com>","cc":"Manivannan Sadhasivam <mani@kernel.org>,\n  Lorenzo Pieralisi <lpieralisi@kernel.org>, =?iso-8859-2?q?Krzysztof_Wilczy?=\n\t=?iso-8859-2?q?=F1ski?= <kwilczynski@kernel.org>,\n  Rob Herring <robh@kernel.org>, Bjorn Helgaas <bhelgaas@google.com>,\n  Jingoo Han <jingoohan1@gmail.com>, linux-pci@vger.kernel.org,\n  linux-arm-msm@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>,\n  mayank.rana@oss.qualcomm.com, quic_vbadigan@quicinc.com,\n  Shawn Lin <shawn.lin@rock-chips.com>","Subject":"Re: [PATCH v5 1/3] PCI/ASPM: Add helper to encode L1SS T_POWER_ON\n fields","In-Reply-To":"<20260428-t_power_on_fux-v5-1-f1ef926a91ff@oss.qualcomm.com>","Message-ID":"<bc3a5f58-676a-3634-6b8f-bffc91d25265@linux.intel.com>","References":"<20260428-t_power_on_fux-v5-0-f1ef926a91ff@oss.qualcomm.com>\n <20260428-t_power_on_fux-v5-1-f1ef926a91ff@oss.qualcomm.com>","Precedence":"bulk","X-Mailing-List":"linux-pci@vger.kernel.org","List-Id":"<linux-pci.vger.kernel.org>","List-Subscribe":"<mailto:linux-pci+subscribe@vger.kernel.org>","List-Unsubscribe":"<mailto:linux-pci+unsubscribe@vger.kernel.org>","MIME-Version":"1.0","Content-Type":"multipart/mixed; boundary=\"8323328-142568513-1777368469=:1128\""}}]