Re: [PATCH v5 03/16] CXL/PCI: Introduce PCIe helper functions pcie_is_cxl() and pcie_is_cxl_port()

Ira Weiny
2025-01-16T15:36:01Z

Bowman, Terry wrote:
>
>
>
> On 1/14/2025 5:33 PM, Ira Weiny wrote:
> > Bowman, Terry wrote:
> >>
> >>
> >> On 1/13/2025 5:49 PM, Ira Weiny wrote:
> >>> Terry Bowman wrote:

[snip]

> >>>> +bool pcie_is_cxl_port(struct pci_dev *dev)
> >>>> +{
> >>>> + 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);
> >>> Returning bool from a function which returns u16 is odd and I don't think
> >>> it should be coded this way. I don't think it is wrong right now but this
> >>> really ought to code the pcie_is_cxl() here and leave cxl_port_dvsec()
> >>> alone. Calling cxl_port_dvsec(), checking for if the dvsec exists, and
> >>> returning bool.
> >> Hi Ira,
> >>
> >> Thanks for reviewing. Is this what you are looking for here:
> >>
> >> +bool pcie_is_cxl_port(struct pci_dev *dev)
> >> +{
> >> + return (cxl_port_dvsec(dev) > 0);
> > With the type checks, yes that is more clear.
> >
> > Ira
> >
> > [snip]
> Since sending the above I made update to be:
>
> static u16 cxl_port_dvsec(struct pci_dev *dev)
> {
>         return pci_find_dvsec_capability(dev, PCI_VENDOR_ID_CXL,
>                                          PCI_DVSEC_CXL_PORT);
> }
>
> inline bool pcie_is_cxl(struct pci_dev *pci_dev)
> {
>         return pci_dev->is_cxl;
> }
>
> bool pcie_is_cxl_port(struct pci_dev *pci_dev)
> {
>         if (!pcie_is_cxl(pci_dev))
>                 return false;
>
>         return (cxl_port_dvsec(pci_dev) > 0);
> }
>
> I can change if you see anything is needed.

Looks good thanks!
Ira

[snip]