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: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>,
	Bjorn Helgaas <bhelgaas@google.com>,
	lpieralisi@kernel.org, kw@linux.com, robh@kernel.org,
	jingoohan1@gmail.com, thomas.richard@bootlin.com,
	linux-pci@vger.kernel.org, LKML <linux-kernel@vger.kernel.org>
Subject: Re: [v6 3/5] PCI: cadence: Use common PCI host bridge APIs for finding the capabilities
Date: Tue, 1 Apr 2025 21:20:34 +0800	[thread overview]
Message-ID: <418498a1-e2c0-4453-a69d-dabe0ee0e5f6@163.com> (raw)
In-Reply-To: <fc6bec19-fb1e-bff0-8676-ba2c1ca860df@linux.intel.com>



On 2025/4/1 00:39, Ilpo Järvinen wrote:
>>>> +			read_cfg((priv), (devfn), __pos, 2, (u32 *)&__ent); \
>>>> +     \
>>>> +			__id = __ent & 0xff;                                \
>>>> +			if (__id == 0xff)                                   \
>>>> +				break;                                      \
>>>> +			if (__id == (cap)) {                                \
>>>> +				__found_pos = __pos;                        \
>>>> +				break;                                      \
>>>> +			}                                                   \
>>>> +			__pos = (__ent >> 8);                               \
>>>
>>> I'd add these into uapi/linux/pci_regs.h:
>>
>> This means that you will submit, and I will submit after you?
>> Or should I submit this series of patches together?
> 
> I commented these cleanup opportunities so that you could add them to
> your series. If I'd immediately start working on area/lines you're working
> with, it would just trigger conflicts so it's better the original author
> does the improvements within the series he/she is working with. It's a lot
> less work for the maintainer that way :-).
> 

Hi Ilpo,

Thanks your for reply. Thank you so much for your comments.

>>> I started to wonder though if the controller drivers could simply create
>>> an "early" struct pci_dev & pci_bus just so they can use the normal
>>> accessors while the real structs are not yet created. It looks not
>>> much is needed from those structs to let the accessors to work.
>>>
>>
>> Here are a few questions:
>> 1. We need to initialize some variables for pci_dev. For example,
>> dev->cfg_size needs to be initialized to 4K for PCIe.
>>
>> u16 pci_find_next_ext_capability(struct pci_dev *dev, u16 start, int cap)
>> {
>> 	......
>> 	if (dev->cfg_size <= PCI_CFG_SPACE_SIZE)
>> 		return 0;
>> 	......
>>
> 
> Sure, it would require some initialization of the struct (but not
> full init like the probe path does that does lots of setup too).
> 
>> 2. Create an "early" struct pci_dev & pci_bus for each SOC vendor (Qcom,
>> Rockchip, etc). It leads to a lot of code that feels weird.
> 
> The early pci_dev+pci_bus would be created by a helper in PCI core that
> initializes what is necessary for the supported set of early core
> functionality to work. The controller drivers themselves would just call
> that function.
> 

Ok, got it.

>> I still prefer the approach we are discussing now.
> 
> I'm not saying we should immediately head toward this new idea within this
> series because it's going to be relatively big change. But it's certainly
> something that looks worth exploring so that the current chicken-egg
> problem with controller drivers could be solved.
> 

Ok, I hope to have the opportunity to participate in the discussion 
together in the future.

>> diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
>> index 2e9cf26a9ee9..68c111be521d 100644
>> --- a/drivers/pci/pci.h
>> +++ b/drivers/pci/pci.h
>> @@ -4,6 +4,65 @@
>>
>>   #include <linux/pci.h>
> 
> Make sure to add the necessary headers for the function/macros you're
> using so that things won't depend on the #include order in the .c file.
> 

Will do.

>>
>> +/* Ilpo: I'd add these into uapi/linux/pci_regs.h: */
>> +#define PCI_CAP_ID_MASK		0x00ff
>> +#define PCI_CAP_LIST_NEXT_MASK	0xff00
>> +
>> +/* Standard capability finder */
> 
> Capability
> 
> Always use the same capitalization as the specs do.
> 

Will change.

> You should probably write a kernel doc for this macro too.
> 

Will do.

> I'd put these macro around where pcie_cap_has_*() forward declarations
> are so that the initial define block is not split.
> 

Will change.

>> +#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);	\
>> +	}								\
>> +	__found_pos;							\
>> +})
>> +
>> +/* Extended capability finder */
>> +#define PCI_FIND_NEXT_EXT_CAPABILITY(read_cfg, start, cap, args...)	\
>> +({									\
>> +	u16 __pos = (start) ?: PCI_CFG_SPACE_SIZE;			\
>> +	u16 __found_pos = 0;						\
>> +	int __ttl, __ret;						\
>> +	u32 __header;							\
>> +									\
>> +	__ttl = (PCI_CFG_SPACE_EXP_SIZE - PCI_CFG_SPACE_SIZE) / 8;	\
>> +	while (__ttl-- > 0 && __pos >= PCI_CFG_SPACE_SIZE) {		\
>> +		__ret = read_cfg(args, __pos, 4, &__header);		\
>> +		if (__ret != PCIBIOS_SUCCESSFUL)			\
>> +			break;						\
>> +									\
>> +		if (__header == 0)					\
>> +			break;						\
>> +									\
>> +		if (PCI_EXT_CAP_ID(__header) == (cap) && __pos != start) {\
>> +			__found_pos = __pos;				\
>> +			break;						\
>> +		}							\
>> +									\
>> +		__pos = PCI_EXT_CAP_NEXT(__header);			\
>> +	}								\
>> +	__found_pos;							\
>> +})
>> +
>>   struct pcie_tlp_log;
>>
>>   /* Number of possible devfns: 0.0 to 1f.7 inclusive */
>>
>>
>> Looking forward to your latest suggestions.
> 
> This generally looked good, I didn't read with a very fine comb but just
> focused on the important bits. I'll take a more detailed look once you
> make the official submission.

Ok, I'm going to prepare the next version of patch. I hope you can 
review it again. Thank you very much


Best regards,
Hans


  reply	other threads:[~2025-04-01 13:21 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-23 16:48 [v6 0/5] Introduce generic capability search functions Hans Zhang
2025-03-23 16:48 ` [v6 1/5] PCI: " Hans Zhang
2025-03-24 13:28   ` Ilpo Järvinen
2025-03-24 14:39     ` Hans Zhang
2025-03-24 14:52       ` Ilpo Järvinen
2025-03-25  2:58         ` Hans Zhang
2025-03-27 16:57   ` Manivannan Sadhasivam
2025-03-28  9:41     ` Hans Zhang
2025-03-27 16:58   ` Manivannan Sadhasivam
2025-03-28  9:42     ` Hans Zhang
2025-03-23 16:48 ` [v6 2/5] PCI: dwc: Use common PCI host bridge APIs for finding the capabilities Hans Zhang
2025-03-23 16:48 ` [v6 3/5] PCI: cadence: " Hans Zhang
2025-03-23 18:33   ` kernel test robot
2025-03-24  1:07     ` Hans Zhang
2025-03-23 19:26   ` kernel test robot
2025-03-24  1:08     ` Hans Zhang
2025-03-24 13:44   ` Ilpo Järvinen
2025-03-24 14:29     ` Hans Zhang
2025-03-24 15:02       ` Ilpo Järvinen
2025-03-25  2:59         ` Hans Zhang
2025-03-25 11:15           ` Ilpo Järvinen
2025-03-25 12:16             ` Hans Zhang
2025-03-25 14:47               ` Hans Zhang
2025-03-25 15:18                 ` Ilpo Järvinen
2025-03-25 15:37                   ` Hans Zhang
2025-03-28 10:33                     ` Hans Zhang
2025-03-28 11:42                       ` Ilpo Järvinen
2025-03-29 16:03                         ` Hans Zhang
2025-03-31 16:39                           ` Ilpo Järvinen
2025-04-01 13:20                             ` Hans Zhang [this message]
2025-03-23 16:48 ` [v6 4/5] PCI: cadence: Use cdns_pcie_find_*capability to avoid hardcode Hans Zhang
2025-03-23 16:48 ` [v6 5/5] MAINTAINERS: Add entry for PCI host controller helpers Hans Zhang
2025-03-27 17:01   ` Manivannan Sadhasivam
2025-03-28 10:36     ` 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=418498a1-e2c0-4453-a69d-dabe0ee0e5f6@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