Re: [PATCH v2] PCI: add helper function to find DVSEC

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

 



On Tue, Nov 03, 2020 at 08:12:28AM -0700, Dave Jiang wrote:
> Add function that searches for DVSEC and returns the offset in PCI
> configuration space for the interested DVSEC capability.
> 
> Signed-off-by: Dave Jiang <dave.jiang@xxxxxxxxx>
> Reviewed-by: Ashok Raj <ashok.raj@xxxxxxxxx>

I'm sorry, I screwed this up.  I should have merged the
PCI_EXT_CAP_ID_DVSEC definitions and pci_find_dvsec() for v5.11 to
resolve the mess of dependencies, but I didn't.  Lee applied the
#defines already [1], but I think we're going to have a similar
problem with multiple features that want to add pci_find_dvsec() but
be merged via different trees.

I'm a simple-minded git user, and I don't want to mess with merging
Lee's branch into my tree, so I think the easiest thing would be for
each of these features to implement their own static version of
pci_find_dvsec() (and the DVSEC #defines, if necessary) in the series
that needs it.  That way all the series can be merged independently,
and we can deduplicate them in a future cycle.

So I'm going to drop this for now and assume you'll move it to the
file that uses it and include it in that series.

The patch itself looks good.  Thanks for changing the "not found"
return value to 0.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/lee/mfd.git/commit/?h=ib-mfd-x86-5.11&id=1dc2da5cd51f648de6d1df87e2bc6ea13f72f19c

> ---
> 
> v2:
> - Comment fixups (Randy)
> - Function return 0 on fail to be consistent with other find cap functions.  (Randy)
> 
>  drivers/pci/pci.c   |   30 ++++++++++++++++++++++++++++++
>  include/linux/pci.h |    3 +++
>  2 files changed, 33 insertions(+)
> 
> diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
> index 6d4d5a2f923d..09208a31114a 100644
> --- a/drivers/pci/pci.c
> +++ b/drivers/pci/pci.c
> @@ -589,6 +589,36 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap)
>  }
>  EXPORT_SYMBOL_GPL(pci_find_ext_capability);
>  
> +/**
> + * pci_find_dvsec - return position of DVSEC with provided vendor and DVSEC ID
> + * @dev: the PCI device
> + * @vendor: vendor for the DVSEC
> + * @id: the DVSEC capability ID
> + *
> + * Return: the offset of DVSEC on success or 0 if not found
> + */
> +int pci_find_dvsec(struct pci_dev *dev, u16 vendor, u16 id)
> +{
> +	u16 dev_vendor, dev_id;
> +	int pos;
> +
> +	pos = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DVSEC);
> +	if (!pos)
> +		return 0;
> +
> +	while (pos) {
> +		pci_read_config_word(dev, pos + PCI_DVSEC_HEADER1, &dev_vendor);
> +		pci_read_config_word(dev, pos + PCI_DVSEC_HEADER2, &dev_id);
> +		if (dev_vendor == vendor && dev_id == id)
> +			return pos;
> +
> +		pos = pci_find_next_ext_capability(dev, pos, PCI_EXT_CAP_ID_DVSEC);
> +	}
> +
> +	return 0;
> +}
> +EXPORT_SYMBOL_GPL(pci_find_dvsec);
> +
>  /**
>   * pci_get_dsn - Read and return the 8-byte Device Serial Number
>   * @dev: PCI device to query
> diff --git a/include/linux/pci.h b/include/linux/pci.h
> index 22207a79762c..6c692d32c82a 100644
> --- a/include/linux/pci.h
> +++ b/include/linux/pci.h
> @@ -1069,6 +1069,7 @@ int pci_find_ext_capability(struct pci_dev *dev, int cap);
>  int pci_find_next_ext_capability(struct pci_dev *dev, int pos, int cap);
>  int pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
>  int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap);
> +int pci_find_dvsec(struct pci_dev *dev, u16 vendor, u16 id);
>  struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
>  
>  u64 pci_get_dsn(struct pci_dev *dev);
> @@ -1726,6 +1727,8 @@ static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
>  { return 0; }
>  static inline int pci_find_ext_capability(struct pci_dev *dev, int cap)
>  { return 0; }
> +static inline int pci_find_dvsec(struct pci_dev *dev, u16 vendor, u16 id)
> +{ return 0; }
>  
>  static inline u64 pci_get_dsn(struct pci_dev *dev)
>  { return 0; }
> 
> 



[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