Linux PCI subsystem development
 help / color / mirror / Atom feed
From: Hans Zhang <18255117159@163.com>
To: "Ilpo Järvinen" <ilpo.jarvinen@linux.intel.com>
Cc: lpieralisi@kernel.org, bhelgaas@google.com, kw@linux.com,
	manivannan.sadhasivam@linaro.org, robh@kernel.org,
	jingoohan1@gmail.com, thomas.richard@bootlin.com,
	linux-pci@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [v7 1/5] PCI: Refactor capability search into common macros
Date: Thu, 3 Apr 2025 20:22:07 +0800	[thread overview]
Message-ID: <a0483c8d-3cd4-4da2-aca5-586379870e3a@163.com> (raw)
In-Reply-To: <9e9a68b1-8c3a-6132-d4fc-9f7b0b2d3e3a@linux.intel.com>



On 2025/4/3 17:10, Ilpo Järvinen wrote:
>>>> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
>>>> index 2e9cf26a9ee9..f705b8bd3084 100644
>>>> --- a/drivers/pci/pci.h
>>>> +++ b/drivers/pci/pci.h
>>>> @@ -89,6 +89,87 @@ bool pcie_cap_has_lnkctl(const struct pci_dev *dev);
>>>>    bool pcie_cap_has_lnkctl2(const struct pci_dev *dev);
>>>>    bool pcie_cap_has_rtctl(const struct pci_dev *dev);
>>>>    +/* Standard Capability finder */
>>>> +/**
>>>> + * PCI_FIND_NEXT_CAP_TTL - Find a PCI standard capability
>>>> + * @read_cfg: Function pointer for reading PCI config space
>>>> + * @start: Starting position to begin search
>>>> + * @cap: Capability ID to find
>>>> + * @args: Arguments to pass to read_cfg function
>>>> + *
>>>> + * Iterates through the capability list in PCI config space to find
>>>> + * the specified capability. Implements TTL (time-to-live) protection
>>>> + * against infinite loops.
>>>> + *
>>>> + * Returns: Position of the capability if found, 0 otherwise.
>>>> + */
>>>> +#define PCI_FIND_NEXT_CAP_TTL(read_cfg, start, cap, args...)
>>>> \
>>>> +({									\
>>>> +	u8 __pos = (start);						\
>>>> +	int __ttl = PCI_FIND_CAP_TTL;					\
>>>> +	u16 __ent;							\
>>>> +	u8 __found_pos = 0;						\
>>>> +	u8 __id;							\
>>>> +									\
>>>> +	read_cfg(args, __pos, 1, (u32 *)&__pos);			\
>>>> +									\
>>>> +	while (__ttl--) {						\
>>>> +		if (__pos < PCI_STD_HEADER_SIZEOF)			\
>>>> +			break;						\
>>>> +		__pos = ALIGN_DOWN(__pos, 4);				\
>>>> +		read_cfg(args, __pos, 2, (u32 *)&__ent);		\
>>>> +		__id = FIELD_GET(PCI_CAP_ID_MASK, __ent);		\
>>>> +		if (__id == 0xff)					\
>>>> +			break;						\
>>>> +		if (__id == (cap)) {					\
>>>> +			__found_pos = __pos;				\
>>>> +			break;						\
>>>> +		}							\
>>>> +		__pos = FIELD_GET(PCI_CAP_LIST_NEXT_MASK, __ent);	\
>>>
>>> Could you please separate the coding style cleanups into own patch that
>>> is before the actual move patch. IMO, all those cleanups can be in the
>>> same patch.
>>>
>>
>> Hi Ilpo,
>>
>> Thanks your for reply. I don't understand. Is it like this?
> 
> Add a patch before the first patch which does only the cleanups to
> __pci_find_next_cap_ttl(). The patch that creates PCI_FIND_NEXT_CAP_TTL()
> and converts its PCI core users (most of the patches 1&2) is to be based
> on top of that cleanup patch.
> 

Hi Ilpo,

Thank you so much for your patience in explaining it to me.

>> #define PCI_FIND_NEXT_CAP_TTL(read_cfg, start, cap, args...)		\
>> ({									\
>> 	int __ttl = PCI_FIND_CAP_TTL;					\
>> 	u8 __id, __found_pos = 0;					\
>> 	u8 __pos = (start);						\
>> 	u16 __ent;							\
>> 									\
>> 	read_cfg(args, __pos, 1, (u32 *)&__pos);			\
>> 									\
>> 	while (__ttl--) {						\
>> 		if (__pos < PCI_STD_HEADER_SIZEOF)			\
>> 			break;						\
>> 									\
>> 		__pos = ALIGN_DOWN(__pos, 4);				\
>> 		read_cfg(args, __pos, 2, (u32 *)&__ent);		\
>> 									\
>> 		__id = FIELD_GET(PCI_CAP_ID_MASK, __ent);		\
>> 		if (__id == 0xff)					\
>> 			break;						\
>> 									\
>> 		if (__id == (cap)) {					\
>> 			__found_pos = __pos;				\
>> 			break;						\
>> 		}							\
>> 									\
>> 		__pos = FIELD_GET(PCI_CAP_LIST_NEXT_MASK, __ent);	\
>> 	}								\
>> 	__found_pos;							\
>> })
>>
>>> You also need to add #includes for the defines you now started to use.
>>>
>>
>> Is that what you mean?
>>
>> +#include <linux/bitfield.h>
>> +#include <linux/align.h>
>> +#include <uapi/linux/pci_regs.h>
> 
> Almost, including pci_regs.h is not strictly necessary as linux/pci.h will
> always pull that one in (not that it would hurt).
> 
> Also, sort the includes alphabetically.
> 

OK,will change.

Best regards,
Hans


  reply	other threads:[~2025-04-03 12:23 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-04-02  4:20 [v7 0/5] Refactor capability search into common macros Hans Zhang
2025-04-02  4:20 ` [v7 1/5] PCI: " Hans Zhang
2025-04-02 12:42   ` Ilpo Järvinen
2025-04-02 15:31     ` Hans Zhang
2025-04-03  9:10       ` Ilpo Järvinen
2025-04-03 12:22         ` Hans Zhang [this message]
2025-04-03 16:31           ` Hans Zhang
2025-04-02  4:20 ` [v7 2/5] PCI: Refactor capability search functions to eliminate code duplication Hans Zhang
2025-04-02  9:19   ` kernel test robot
2025-04-02 10:42     ` Hans Zhang
2025-04-02 12:38   ` Ilpo Järvinen
2025-04-02 15:37     ` Hans Zhang
2025-04-03  9:15       ` Ilpo Järvinen
2025-04-03 12:24         ` Hans Zhang
2025-04-03 16:29           ` Hans Zhang
2025-04-03 16:35           ` Hans Zhang
2025-04-07 17:03             ` Ilpo Järvinen
2025-04-08 12:19               ` Hans Zhang
2025-04-08 16:18                 ` Ilpo Järvinen
2025-04-09  1:37                   ` Hans Zhang
2025-04-02  4:20 ` [v7 3/5] PCI: dwc: Use common PCI host bridge APIs for finding the capabilities Hans Zhang
2025-04-02 11:58   ` kernel test robot
2025-04-02 12:18     ` Hans Zhang
2025-04-02  4:20 ` [v7 4/5] PCI: cadence: " Hans Zhang
2025-04-02  4:20 ` [v7 5/5] PCI: cadence: Use cdns_pcie_find_*capability to avoid hardcode 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=a0483c8d-3cd4-4da2-aca5-586379870e3a@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=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lpieralisi@kernel.org \
    --cc=manivannan.sadhasivam@linaro.org \
    --cc=robh@kernel.org \
    --cc=thomas.richard@bootlin.com \
    /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