mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Hans Zhang <18255117159@163.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: bhelgaas@google.com, lpieralisi@kernel.org, kw@linux.com,
	kwilczynski@kernel.org, mani@kernel.org, jingoohan1@gmail.com,
	robh@kernel.org, linux-pci@vger.kernel.org,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v5 2/3] PCI: Move pci_bus_speed2lnkctl2() to public header
Date: Tue, 7 Apr 2026 21:01:44 +0800	[thread overview]
Message-ID: <1a8583ad-0d27-4606-9a27-de3bc31d3e67@163.com> (raw)
In-Reply-To: <e79055d3-1353-b6be-7c83-f61697efeae9@linux.intel.com>



On 4/7/26 20:53, Ilpo Järvinen wrote:
> On Tue, 7 Apr 2026, Hans Zhang wrote:
>> On 4/7/26 20:29, Hans Zhang wrote:
>>> On 4/7/26 20:26, Ilpo Järvinen wrote:
>>>> On Tue, 7 Apr 2026, Hans Zhang wrote:
>>>>> On 4/7/26 16:11, Ilpo Järvinen wrote:
>>>>>> On Mon, 6 Apr 2026, Hans Zhang wrote:
>>>>>>
>>>>>>> Move the static array-based pci_bus_speed2lnkctl2() function from
>>>>>>> bwctrl.c to pci.h as a public inline function.
>>>>>>>
>>>>>>> This provides efficient O(1) speed-to-LNKCTL2 value conversion using
>>>>>>> static array lookup, maintaining optimal performance while enabling
>>>>>>> code reuse by other PCIe drivers.
>>>>>>>
>>>>>>> Signed-off-by: Hans Zhang <18255117159@163.com>
>>>>>>> ---
>>>>>>>     drivers/pci/pci.h         | 17 +++++++++++++++++
>>>>>>>     drivers/pci/pcie/bwctrl.c | 17 -----------------
>>>>>>>     2 files changed, 17 insertions(+), 17 deletions(-)
>>>>>>>
>>>>>>> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
>>>>>>> index f0a082bfd6f1..db91878a86ac 100644
>>>>>>> --- a/drivers/pci/pci.h
>>>>>>> +++ b/drivers/pci/pci.h
>>>>>>> @@ -611,6 +611,23 @@ static inline bool pcie_valid_speed(enum
>>>>>>> pci_bus_speed speed)
>>>>>>>         return (speed >= PCIE_SPEED_2_5GT) && (speed <=
>>>>>>> PCIE_SPEED_64_0GT);
>>>>>>>     }
>>>>>>>     +static inline u16 pci_bus_speed2lnkctl2(enum pci_bus_speed
>>>>>>> speed)
>>>>>>> +{
>>>>>>> +    static const u8 speed_conv[] = {
>>>>>>> +        [PCIE_SPEED_2_5GT] = PCI_EXP_LNKCTL2_TLS_2_5GT,
>>>>>>> +        [PCIE_SPEED_5_0GT] = PCI_EXP_LNKCTL2_TLS_5_0GT,
>>>>>>> +        [PCIE_SPEED_8_0GT] = PCI_EXP_LNKCTL2_TLS_8_0GT,
>>>>>>> +        [PCIE_SPEED_16_0GT] = PCI_EXP_LNKCTL2_TLS_16_0GT,
>>>>>>> +        [PCIE_SPEED_32_0GT] = PCI_EXP_LNKCTL2_TLS_32_0GT,
>>>>>>> +        [PCIE_SPEED_64_0GT] = PCI_EXP_LNKCTL2_TLS_64_0GT,
>>>>>>> +    };
>>>>>>> +
>>>>>>> +    if (WARN_ON_ONCE(!pcie_valid_speed(speed)))
>>>>>>
>>>>>> drivers/pci/pci.h doesn't seem to have include for WARN_ON_ONCE() so
>>>>>> you
>>>>>> should add it.
>>>>>
>>>>> Hi Ilpo,
>>>>>
>>>>> In the file "drivers/pci/pcie/bwctrl.c", there is no reference to the
>>>>> header
>>>>> file of WARN_ON_ONCE(). It seems that no error was reported. I think it
>>>>> might
>>>>> be that some other header files have indirectly referenced the header
>>>>> file of
>>>>> WARN_ON_ONCE(). However, when I compiled it locally, no errors were
>>>>> reported.
>>>>
>>>> Hi,
>>>>
>>>> Apparently it was missing from there as well.
>>>>
>>>> It might build now (I don't actually even doubt that), but that depends
>>>> on the includes in every file including drivers/pci/pci.h. We should not
>>>> depend on that as it is fragile but ensure a header is self-sufficient
>>>> when it comes to includes necessary for it.
>>>
>>> Hi Ilpo,
>>>
>>> OK, I see.
>>>
>>>
>>>>
>>>>> I think if we want to add a header file, it should be #include
>>>>> <asm-generic/bug.h> ?
>>>>
>>>> Yes
>>>>
>>>> #include <asm/bug.h>
>>
>> Hi Ilpo,
>>
>> Executing the following check script will trigger a warning. However, using
>> #include <asm-generic/bug.h> will not cause any issues. So, should we use
>> #include <asm-generic/bug.h> ?
>>
>> ./scripts/checkpatch.pl ...../*patch
>>
>> 0002-PCI-Move-pci_bus_speed2lnkctl2-to-public-header.patch
>> ---------------------------------------------------------------------
>> WARNING: Use #include <linux/bug.h> instead of <asm/bug.h>
>> #27: FILE: drivers/pci/pci.h:5:
>> +#include <asm/bug.h>
>>
>> total: 0 errors, 1 warnings, 53 lines checked
>>
>> NOTE: For some of the reported defects, checkpatch may be able to
>>        mechanically convert to the typical style using --fix or --fix-inplace.
> 
> This is a header, so using <asm/bug.h> minimizes what it pulls in so it
> is justified to use asm/ over linux/ in this case.
> 

Hi Ilpo,

Thank you. OK.

Best regards,
Hans

> 


  reply	other threads:[~2026-04-07 13:02 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-06 10:47 [PATCH v5 0/3] PCI: Refactor PCIe speed validation and conversion functions Hans Zhang
2026-04-06 10:47 ` [PATCH v5 1/3] PCI: Add public pcie_valid_speed() for shared validation Hans Zhang
2026-04-06 10:47 ` [PATCH v5 2/3] PCI: Move pci_bus_speed2lnkctl2() to public header Hans Zhang
2026-04-07  8:11   ` Ilpo Järvinen
2026-04-07 12:09     ` Hans Zhang
2026-04-07 12:26       ` Ilpo Järvinen
2026-04-07 12:29         ` Hans Zhang
2026-04-07 12:48           ` Hans Zhang
2026-04-07 12:53             ` Ilpo Järvinen
2026-04-07 13:01               ` Hans Zhang [this message]
2026-04-06 10:47 ` [PATCH v5 3/3] PCI: dwc: Use common speed conversion function Hans Zhang
2026-04-06 10:54   ` Hans Zhang

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=1a8583ad-0d27-4606-9a27-de3bc31d3e67@163.com \
    --to=18255117159@163.com \
    --cc=bhelgaas@google.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=jingoohan1@gmail.com \
    --cc=kw@linux.com \
    --cc=kwilczynski@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=mani@kernel.org \
    --cc=robh@kernel.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®