Re: [PATCH v3 03/15] cxl/pci: Introduce PCIe helper functions pcie_is_cxl() and pcie_is_cxl_port()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On 11/14/2024 10:52 AM, Lukas Wunner wrote:
> On Thu, Nov 14, 2024 at 10:45:39AM -0600, Bowman, Terry wrote:
>> On 11/14/2024 9:45 AM, Lukas Wunner wrote:
>>> On Wed, Nov 13, 2024 at 03:54:17PM -0600, Terry Bowman wrote:
>>>> --- a/drivers/pci/pci.c
>>>> +++ b/drivers/pci/pci.c
>>>> @@ -5038,6 +5038,20 @@ static u16 cxl_port_dvsec(struct pci_dev *dev)
>>>>  					 PCI_DVSEC_CXL_PORT);
>>>>  }
>>>>  
>>>> +bool pcie_is_cxl_port(struct pci_dev *dev)
>>>> +{
>>>> +	if (!pcie_is_cxl(dev))
>>>> +		return false;
>>>> +
>>>> +	if ((pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT) &&
>>>> +	    (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM) &&
>>>> +	    (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM))
>>>> +		return false;
>>>> +
>>>> +	return cxl_port_dvsec(dev);
>>>> +}
>>>> +EXPORT_SYMBOL_GPL(pcie_is_cxl_port);
>>> The "!pcie_is_cxl(dev)" check at the top of the function is identical
>>> to the return value "cxl_port_dvsec(dev)".  This looks redundant.
>>> However one cannot call pci_pcie_type() without first checking
>>> pci_is_pcie().  So I'm wondering if the "!pcie_is_cxl(dev)" check
>>> is actually erroneous and supposed to be "!pci_is_pcie(dev)"?
>>> That would make more sense to me.
>> I see pcie_is_cxl(dev) is different than cxl_port_dvsec(dev).
>> They check different DVSECs.
> Ah, sorry, I missed that.
>
>> CXL flexbus DVSEC presence is cached in pci_dev::is_cxl and returned by
>> pcie_is_cxl(). This is used for indicating CXL device.
>>
>> cxl_port_dvsec(dev) returns boolean based on presence of CXL port DVSEC to 
>> indicate a CXL port device.
>>
>> I don't believe they are redundant if you consider you can have a CXL
>> device that 
>> is not a CXL port device.
> Can you have a CXL port that is not a CXL device?
>
> If not, it would seem to me that checking for Flexbus DVSEC presence
> *is* redundant.  Or do you anticipate broken devices which lack the
> Flexbus DVSEC and that you explicitly want to exclude?
>
> Thanks,
>
> Lukas
No, the CXL port device is always a CXL device per spec.

This was added to short-circuit the function by returning immediately if the device
is _not_ a CXL device. Otherwise for PCIe Port devices, the CXL Port DVSEC will be searched.
I was trying to avoid the unnecessary CXL port DVSEC search unless the other criteria
are met. And I expect most cases will not be a CXL device.

I will remove the "if (!pcie_is_cxl(dev))" block as you suggested.

Regards,
Terry






[Index of Archives]     [DMA Engine]     [Linux Coverity]     [Linux USB]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Greybus]

  Powered by Linux