PCI: Return u8 from pci_find_capability() and similar

PCI Capabilities are linked in a list that must appear in the first 256
bytes of config space.  Each capabilities list pointer is 8 bits.

Change the return type of pci_find_capability() and supporting functions
from int to u8 to match the specification.

[bhelgaas: change other related interfaces, fix HyperTransport typos]
Link: https://lore.kernel.org/r/20201129164626.12887-1-puranjay12@gmail.com
Signed-off-by: Puranjay Mohan <puranjay12@gmail.com>
Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
This commit is contained in:
Puranjay Mohan 2020-11-29 22:16:26 +05:30 committed by Bjorn Helgaas
parent 3853f9123c
commit f646c2a0a6
2 changed files with 27 additions and 27 deletions

View File

@ -399,8 +399,8 @@ found:
return 1; return 1;
} }
static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn, static u8 __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
u8 pos, int cap, int *ttl) u8 pos, int cap, int *ttl)
{ {
u8 id; u8 id;
u16 ent; u16 ent;
@ -423,22 +423,22 @@ static int __pci_find_next_cap_ttl(struct pci_bus *bus, unsigned int devfn,
return 0; return 0;
} }
static int __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn, static u8 __pci_find_next_cap(struct pci_bus *bus, unsigned int devfn,
u8 pos, int cap) u8 pos, int cap)
{ {
int ttl = PCI_FIND_CAP_TTL; int ttl = PCI_FIND_CAP_TTL;
return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl); return __pci_find_next_cap_ttl(bus, devfn, pos, cap, &ttl);
} }
int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap) u8 pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap)
{ {
return __pci_find_next_cap(dev->bus, dev->devfn, return __pci_find_next_cap(dev->bus, dev->devfn,
pos + PCI_CAP_LIST_NEXT, cap); pos + PCI_CAP_LIST_NEXT, cap);
} }
EXPORT_SYMBOL_GPL(pci_find_next_capability); EXPORT_SYMBOL_GPL(pci_find_next_capability);
static int __pci_bus_find_cap_start(struct pci_bus *bus, static u8 __pci_bus_find_cap_start(struct pci_bus *bus,
unsigned int devfn, u8 hdr_type) unsigned int devfn, u8 hdr_type)
{ {
u16 status; u16 status;
@ -477,9 +477,9 @@ static int __pci_bus_find_cap_start(struct pci_bus *bus,
* %PCI_CAP_ID_PCIX PCI-X * %PCI_CAP_ID_PCIX PCI-X
* %PCI_CAP_ID_EXP PCI Express * %PCI_CAP_ID_EXP PCI Express
*/ */
int pci_find_capability(struct pci_dev *dev, int cap) u8 pci_find_capability(struct pci_dev *dev, int cap)
{ {
int pos; u8 pos;
pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type); pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
if (pos) if (pos)
@ -502,10 +502,9 @@ EXPORT_SYMBOL(pci_find_capability);
* device's PCI configuration space or 0 in case the device does not * device's PCI configuration space or 0 in case the device does not
* support it. * support it.
*/ */
int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap) u8 pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap)
{ {
int pos; u8 hdr_type, pos;
u8 hdr_type;
pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type); pci_bus_read_config_byte(bus, devfn, PCI_HEADER_TYPE, &hdr_type);
@ -623,7 +622,7 @@ u64 pci_get_dsn(struct pci_dev *dev)
} }
EXPORT_SYMBOL_GPL(pci_get_dsn); EXPORT_SYMBOL_GPL(pci_get_dsn);
static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap) static u8 __pci_find_next_ht_cap(struct pci_dev *dev, u8 pos, int ht_cap)
{ {
int rc, ttl = PCI_FIND_CAP_TTL; int rc, ttl = PCI_FIND_CAP_TTL;
u8 cap, mask; u8 cap, mask;
@ -650,11 +649,12 @@ static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
return 0; return 0;
} }
/** /**
* pci_find_next_ht_capability - query a device's Hypertransport capabilities * pci_find_next_ht_capability - query a device's HyperTransport capabilities
* @dev: PCI device to query * @dev: PCI device to query
* @pos: Position from which to continue searching * @pos: Position from which to continue searching
* @ht_cap: Hypertransport capability code * @ht_cap: HyperTransport capability code
* *
* To be used in conjunction with pci_find_ht_capability() to search for * To be used in conjunction with pci_find_ht_capability() to search for
* all capabilities matching @ht_cap. @pos should always be a value returned * all capabilities matching @ht_cap. @pos should always be a value returned
@ -663,26 +663,26 @@ static int __pci_find_next_ht_cap(struct pci_dev *dev, int pos, int ht_cap)
* NB. To be 100% safe against broken PCI devices, the caller should take * NB. To be 100% safe against broken PCI devices, the caller should take
* steps to avoid an infinite loop. * steps to avoid an infinite loop.
*/ */
int pci_find_next_ht_capability(struct pci_dev *dev, int pos, int ht_cap) u8 pci_find_next_ht_capability(struct pci_dev *dev, u8 pos, int ht_cap)
{ {
return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap); return __pci_find_next_ht_cap(dev, pos + PCI_CAP_LIST_NEXT, ht_cap);
} }
EXPORT_SYMBOL_GPL(pci_find_next_ht_capability); EXPORT_SYMBOL_GPL(pci_find_next_ht_capability);
/** /**
* pci_find_ht_capability - query a device's Hypertransport capabilities * pci_find_ht_capability - query a device's HyperTransport capabilities
* @dev: PCI device to query * @dev: PCI device to query
* @ht_cap: Hypertransport capability code * @ht_cap: HyperTransport capability code
* *
* Tell if a device supports a given Hypertransport capability. * Tell if a device supports a given HyperTransport capability.
* Returns an address within the device's PCI configuration space * Returns an address within the device's PCI configuration space
* or 0 in case the device does not support the request capability. * or 0 in case the device does not support the request capability.
* The address points to the PCI capability, of type PCI_CAP_ID_HT, * The address points to the PCI capability, of type PCI_CAP_ID_HT,
* which has a Hypertransport capability matching @ht_cap. * which has a HyperTransport capability matching @ht_cap.
*/ */
int pci_find_ht_capability(struct pci_dev *dev, int ht_cap) u8 pci_find_ht_capability(struct pci_dev *dev, int ht_cap)
{ {
int pos; u8 pos;
pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type); pos = __pci_bus_find_cap_start(dev->bus, dev->devfn, dev->hdr_type);
if (pos) if (pos)

View File

@ -1064,12 +1064,13 @@ void pci_sort_breadthfirst(void);
/* Generic PCI functions exported to card drivers */ /* Generic PCI functions exported to card drivers */
int pci_find_capability(struct pci_dev *dev, int cap); u8 pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
int pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap); u8 pci_find_capability(struct pci_dev *dev, int cap);
u8 pci_find_next_capability(struct pci_dev *dev, u8 pos, int cap);
u8 pci_find_ht_capability(struct pci_dev *dev, int ht_cap);
u8 pci_find_next_ht_capability(struct pci_dev *dev, u8 pos, int ht_cap);
int pci_find_ext_capability(struct pci_dev *dev, int cap); 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_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);
struct pci_bus *pci_find_next_bus(const struct pci_bus *from); struct pci_bus *pci_find_next_bus(const struct pci_bus *from);
u64 pci_get_dsn(struct pci_dev *dev); u64 pci_get_dsn(struct pci_dev *dev);
@ -1280,7 +1281,6 @@ void set_pcie_port_type(struct pci_dev *pdev);
void set_pcie_hotplug_bridge(struct pci_dev *pdev); void set_pcie_hotplug_bridge(struct pci_dev *pdev);
/* Functions for PCI Hotplug drivers to use */ /* Functions for PCI Hotplug drivers to use */
int pci_bus_find_capability(struct pci_bus *bus, unsigned int devfn, int cap);
unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge); unsigned int pci_rescan_bus_bridge_resize(struct pci_dev *bridge);
unsigned int pci_rescan_bus(struct pci_bus *bus); unsigned int pci_rescan_bus(struct pci_bus *bus);
void pci_lock_rescan_remove(void); void pci_lock_rescan_remove(void);
@ -1720,7 +1720,7 @@ static inline int __pci_register_driver(struct pci_driver *drv,
static inline int pci_register_driver(struct pci_driver *drv) static inline int pci_register_driver(struct pci_driver *drv)
{ return 0; } { return 0; }
static inline void pci_unregister_driver(struct pci_driver *drv) { } static inline void pci_unregister_driver(struct pci_driver *drv) { }
static inline int pci_find_capability(struct pci_dev *dev, int cap) static inline u8 pci_find_capability(struct pci_dev *dev, int cap)
{ return 0; } { return 0; }
static inline int pci_find_next_capability(struct pci_dev *dev, u8 post, static inline int pci_find_next_capability(struct pci_dev *dev, u8 post,
int cap) int cap)