From: Sumit Gupta <sumitg@nvidia.com>
To: Bjorn Helgaas <helgaas@kernel.org>
Cc: <treding@nvidia.com>, <krzysztof.kozlowski@linaro.org>,
<dmitry.osipenko@collabora.com>, <viresh.kumar@linaro.org>,
<rafael@kernel.org>, <jonathanh@nvidia.com>, <robh+dt@kernel.org>,
<lpieralisi@kernel.org>, <linux-kernel@vger.kernel.org>,
<linux-tegra@vger.kernel.org>, <linux-pm@vger.kernel.org>,
<devicetree@vger.kernel.org>, <linux-pci@vger.kernel.org>,
<mmaddireddy@nvidia.com>, <kw@linux.com>, <bhelgaas@google.com>,
<vidyas@nvidia.com>, <sanjayc@nvidia.com>,
<ksitaraman@nvidia.com>, <ishah@nvidia.com>, <bbasu@nvidia.com>,
Sumit Gupta <sumitg@nvidia.com>
Subject: Re: [Patch v4 10/10] PCI: tegra194: add interconnect support in Tegra234
Date: Thu, 30 Mar 2023 13:30:16 +0530 [thread overview]
Message-ID: <72b9168b-d4d6-4312-32ea-69358df2f2d0@nvidia.com> (raw)
In-Reply-To: <20230329191703.GA3076491@bhelgaas>
On 30/03/23 00:47, Bjorn Helgaas wrote:
> External email: Use caution opening links or attachments
>
>
> On Wed, Mar 29, 2023 at 11:28:40PM +0530, Sumit Gupta wrote:
>> On 29/03/23 22:29, Bjorn Helgaas wrote:
>>> On Wed, Mar 29, 2023 at 02:44:34PM +0530, Sumit Gupta wrote:
>>>> On 28/03/23 23:23, Bjorn Helgaas wrote:
>>>>>> +static void tegra_pcie_icc_set(struct tegra_pcie_dw *pcie)
>>>>>> +{
>>>>>> + struct dw_pcie *pci = &pcie->pci;
>>>>>> + u32 val, speed, width;
>>>>>> +
>>>>>> + val = dw_pcie_readw_dbi(pci, pcie->pcie_cap_base + PCI_EXP_LNKSTA);
>>>>>> +
>>>>>> + speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
>>>>>> + width = FIELD_GET(PCI_EXP_LNKSTA_NLW, val);
>>>>>> +
>>>>>> + val = width * (PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]) / BITS_PER_BYTE);
>>>>>> +
>>>>>> + if (icc_set_bw(pcie->icc_path, MBps_to_icc(val), 0))
>>>>>> + dev_err(pcie->dev, "can't set bw[%u]\n", val);
>>>>>> +
>>>>>> + clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
>>>>>
>>>>> Array bounds violation; PCI_EXP_LNKSTA_CLS is 0x000f, so possible
>>>>> speed (CLS) values are 0..0xf and "speed - 1" values are -1..0xe.
>>>>>
>>>>> pcie_gen_freq[] is of size 4 (valid indices 0..3).
>>>>>
>>>>> I see that you're just *moving* this code, but might as well fix it.
>>>>>
>>>> Thank you for the review.
>>>> Will include the below change in the same patch. Please let me know if any
>>>> issue.
>>>>
>>>> - clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
>>>> + if (speed && (speed <= ARRAY_SIZE(pcie_gen_freq)))
>>>> + clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
>>>> + else
>>>> + clk_set_rate(pcie->core_clk, pcie_gen_freq[0]);
>>>
>>> I didn't notice that speed is a u32, so -1 is not a possible value.
>>> Also, it's used earlier for PCIE_SPEED2MBS_ENC(), so you could do
>>> something like this:
>>>
>>> speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val) - 1;
>>> if (speed >= ARRAY_SIZE(pcie_gen_freq))
>>> speed = 0;
>>>
>>> val = width * (PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]) /
>>> BITS_PER_BYTE);
>>> ...
>>> clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);
>>
>> I tried this change but PCIE_SPEED2MBS_ENC gives zero when speed value is
>> one. The speed value ranges from "1 to 4" and for value "1",
>> pcie_link_speed[speed] gives '0xff'.
>
> Oh, my fault, sorry! I thought both places indexed the same array,
> but the first is pcie_link_speed[] (where all the possible values
> (0..0xf) are valid indices) and the second is pcie_gen_freq[] (where
> only 0..3 are valid).
>
>> The below change works fine. Please share if its OK to add it in patch.
>>
>> speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
>> if (!speed || speed >= ARRAY_SIZE(pcie_gen_freq))
>> speed = 1;
>>
>> val = width * (PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]) /
>> BITS_PER_BYTE);
>
> So I don't think you need to clamp "speed" for indexing
> pcie_link_speed[] at all.
>
>> if (icc_set_bw(pcie->icc_path, MBps_to_icc(val), 0))
>> dev_err(pcie->dev, "can't set bw[%u]\n", val);
>>
>> clk_set_rate(pcie->core_clk, pcie_gen_freq[speed - 1]);
>
> What if you added a 0th entry to pcie_gen_freq[] so you can index it
> directly with the PCI_EXP_LNKSTA_CLS value the same way as
> pcie_link_speed[]? Then you wouldn't need the "- 1" and only have to
> worry about going off the end:
>
> static const unsigned int pcie_gen_freq[] = {
> GEN1_CORE_CLK_FREQ, /* PCI_EXP_LNKSTA_CLS == 0; undefined */
> GEN1_CORE_CLK_FREQ,
> GEN2_CORE_CLK_FREQ,
> GEN3_CORE_CLK_FREQ,
> GEN4_CORE_CLK_FREQ,
> };
>
> speed = FIELD_GET(PCI_EXP_LNKSTA_CLS, val);
>
> val = width * (PCIE_SPEED2MBS_ENC(pcie_link_speed[speed]) /
> BITS_PER_BYTE);
>
> if (speed >= ARRAY_SIZE(pcie_gen_freq))
> speed = 0;
> clk_set_rate(pcie->core_clk, pcie_gen_freq[speed]);
>
> Bjorn
Yes, this is working fine. Will add it in the patch.
Thank you,
Sumit Gupta
prev parent reply other threads:[~2023-03-30 8:01 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-27 16:14 [Patch v4 00/10] Tegra234 Memory interconnect support Sumit Gupta
2023-03-27 16:14 ` [Patch v4 01/10] dt-bindings: memory: tegra: add bpmp ref in tegra234-mc node Sumit Gupta
2023-03-28 7:23 ` Krzysztof Kozlowski
2023-03-28 10:48 ` Thierry Reding
2023-03-28 11:22 ` Krzysztof Kozlowski
2023-03-28 12:48 ` Thierry Reding
2023-03-29 17:12 ` Sumit Gupta
2023-04-02 10:47 ` Krzysztof Kozlowski
2023-04-04 11:44 ` Thierry Reding
2023-03-28 10:42 ` Thierry Reding
2023-03-27 16:14 ` [Patch v4 02/10] arm64: " Sumit Gupta
2023-03-28 7:21 ` Krzysztof Kozlowski
2023-03-28 12:41 ` Sumit Gupta
2023-03-27 16:14 ` [Patch v4 03/10] memory: tegra: add interconnect support for DRAM scaling in Tegra234 Sumit Gupta
2023-03-28 7:31 ` Krzysztof Kozlowski
2023-03-28 11:05 ` Thierry Reding
2023-03-28 12:30 ` Sumit Gupta
2023-03-28 12:34 ` Sumit Gupta
2023-03-27 16:14 ` [Patch v4 04/10] memory: tegra: add mc clients for Tegra234 Sumit Gupta
2023-03-27 16:14 ` [Patch v4 05/10] memory: tegra: add software mc clients in Tegra234 Sumit Gupta
2023-03-27 16:14 ` [Patch v4 06/10] dt-bindings: tegra: add icc ids for dummy MC clients Sumit Gupta
2023-03-27 16:14 ` [Patch v4 07/10] arm64: tegra: Add cpu OPP tables and interconnects property Sumit Gupta
2023-03-27 16:14 ` [Patch v4 08/10] cpufreq: tegra194: add OPP support and set bandwidth Sumit Gupta
2023-03-27 16:14 ` [Patch v4 09/10] memory: tegra: make cpu cluster bw request a multiple of mc channels Sumit Gupta
2023-03-27 16:14 ` [Patch v4 10/10] PCI: tegra194: add interconnect support in Tegra234 Sumit Gupta
2023-03-28 17:53 ` Bjorn Helgaas
2023-03-29 9:14 ` Sumit Gupta
2023-03-29 16:59 ` Bjorn Helgaas
2023-03-29 17:58 ` Sumit Gupta
2023-03-29 19:17 ` Bjorn Helgaas
2023-03-30 8:00 ` Sumit Gupta [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=72b9168b-d4d6-4312-32ea-69358df2f2d0@nvidia.com \
--to=sumitg@nvidia.com \
--cc=bbasu@nvidia.com \
--cc=bhelgaas@google.com \
--cc=devicetree@vger.kernel.org \
--cc=dmitry.osipenko@collabora.com \
--cc=helgaas@kernel.org \
--cc=ishah@nvidia.com \
--cc=jonathanh@nvidia.com \
--cc=krzysztof.kozlowski@linaro.org \
--cc=ksitaraman@nvidia.com \
--cc=kw@linux.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=lpieralisi@kernel.org \
--cc=mmaddireddy@nvidia.com \
--cc=rafael@kernel.org \
--cc=robh+dt@kernel.org \
--cc=sanjayc@nvidia.com \
--cc=treding@nvidia.com \
--cc=vidyas@nvidia.com \
--cc=viresh.kumar@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®