src/dpdk/drivers/net/hns3/hns3_ethdev_vf.c
static int
hns3vf_find_pci_capability(const struct rte_pci_device *device, int cap)
{
#define MAX_PCIE_CAPABILITY 48
	uint16_t status;
	uint8_t pos;
	uint8_t id;
	int ttl;
	int ret;

	ret = rte_pci_read_config(device, &status, sizeof(status), PCI_STATUS);
	if (ret < 0) {
		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x", PCI_STATUS);
		return 0;
	}

	if (!(status & PCI_STATUS_CAP_LIST))
		return 0;

	ttl = MAX_PCIE_CAPABILITY;
	ret = rte_pci_read_config(device, &pos, sizeof(pos),
				  PCI_CAPABILITY_LIST);
	if (ret < 0) {
		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
			     PCI_CAPABILITY_LIST);
		return 0;
	}

	while (ttl-- && pos >= PCI_STD_HEADER_SIZEOF) {
		ret = rte_pci_read_config(device, &id, sizeof(id),
					  (pos + PCI_CAP_LIST_ID));
		if (ret < 0) {
			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
				     (pos + PCI_CAP_LIST_ID));
			break;
		}

		if (id == 0xFF)
			break;

		if (id == cap)
			return (int)pos;

		ret = rte_pci_read_config(device, &pos, sizeof(pos),
					  (pos + PCI_CAP_LIST_NEXT));
		if (ret < 0) {
			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
				     (pos + PCI_CAP_LIST_NEXT));
			break;
		}
	}
	return 0;
}
/**
 * hns3vf_find_pci_capability - lookup a capability in the PCI capability list
 * @cap: the capability
 *
 * Return the address of the given capability within the PCI capability list.
 */
lookup a capability in the PCI capability list
@cap: the capability

Return the address of the given capability within the PCI capability list.
lookup a capability in the PCI capability list @cap : the capability Return the address of the given capability within the PCI capability list .
static int
hns3vf_find_pci_capability(const struct rte_pci_device *device, int cap)
{
#define MAX_PCIE_CAPABILITY 48
	uint16_t status;
	uint8_t pos;
	uint8_t id;
	int ttl;
	int ret;
	ret = rte_pci_read_config(device, &status, sizeof(status), PCI_STATUS);
	if (ret < 0) {
		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x", PCI_STATUS);
		return 0;
	}
	if (!(status & PCI_STATUS_CAP_LIST))
		return 0;
	ttl = MAX_PCIE_CAPABILITY;
	ret = rte_pci_read_config(device, &pos, sizeof(pos),
				  PCI_CAPABILITY_LIST);
	if (ret < 0) {
		PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
			     PCI_CAPABILITY_LIST);
		return 0;
	}
	while (ttl-- && pos >= PCI_STD_HEADER_SIZEOF) {
		ret = rte_pci_read_config(device, &id, sizeof(id),
					  (pos + PCI_CAP_LIST_ID));
		if (ret < 0) {
			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
				     (pos + PCI_CAP_LIST_ID));
			break;
		}
		if (id == 0xFF)
			break;
		if (id == cap)
			return (int)pos;
		ret = rte_pci_read_config(device, &pos, sizeof(pos),
					  (pos + PCI_CAP_LIST_NEXT));
		if (ret < 0) {
			PMD_INIT_LOG(ERR, "Failed to read PCI offset 0x%x",
				     (pos + PCI_CAP_LIST_NEXT));
			break;
		}
	}
	return 0;
}
static int hns3vf_find_pci_capability ( const struct rte_pci_device * device , int cap ) { #define MAX_PCIE_CAPABILITY  48 uint16_t status ; uint8_t pos ; uint8_t id ; int ttl ; int ret ; ret = rte_pci_read_config ( device , & status , sizeof ( status ) , PCI_STATUS ) ; if ( ret < 0 ) { PMD_INIT_LOG ( ERR , " " , PCI_STATUS ) ; return 0 ; } if ( ! ( status & PCI_STATUS_CAP_LIST ) ) return 0 ; ttl = MAX_PCIE_CAPABILITY ; ret = rte_pci_read_config ( device , & pos , sizeof ( pos ) , PCI_CAPABILITY_LIST ) ; if ( ret < 0 ) { PMD_INIT_LOG ( ERR , " " , PCI_CAPABILITY_LIST ) ; return 0 ; } while ( ttl -- && pos >= PCI_STD_HEADER_SIZEOF ) { ret = rte_pci_read_config ( device , & id , sizeof ( id ) , ( pos + PCI_CAP_LIST_ID ) ) ; if ( ret < 0 ) { PMD_INIT_LOG ( ERR , " " , ( pos + PCI_CAP_LIST_ID ) ) ; break ; } if ( id == 0xFF ) break ; if ( id == cap ) return ( int ) pos ; ret = rte_pci_read_config ( device , & pos , sizeof ( pos ) , ( pos + PCI_CAP_LIST_NEXT ) ) ; if ( ret < 0 ) { PMD_INIT_LOG ( ERR , " " , ( pos + PCI_CAP_LIST_NEXT ) ) ; break ; } } return 0 ; }
hns3vf_find_pci_capability - lookup a capability in the PCI capability list
 @cap: the capability
hns3vf_find_pci_capability - lookup a capability in the PCI capability list @cap : the capability