2009-03-02 16:18:11 +00:00
|
|
|
/*
|
2012-12-13 14:52:25 +00:00
|
|
|
* virpci.h: helper APIs for managing host PCI devices
|
|
|
|
*
|
nodedev: report maxCount for virtual_functions capability
A PCI device may have the capability to setup virtual functions (VFs)
but have them currently all disabled. Prior to this patch, if that was
the case the the node device XML for the device wouldn't report any
virtual_functions capability.
With this patch, if a file called "sriov_totalvfs" is found in the
device's sysfs directory, its contents will be interpreted as a
decimal number, and that value will be reported as "maxCount" in a
capability element of the device's XML, e.g.:
<capability type='virtual_functions' maxCount='7'/>
This will be reported regardless of whether or not any VFs are
currently enabled for the device.
NB: sriov_numvfs (the number of VFs currently active) is also
available in sysfs, but that value is implied by the number of items
in the list that is inside the capability element, so there is no
reason to explicitly provide it as an attribute.
sriov_totalvfs and sriov_numvfs are available in kernels at least as far
back as the 2.6.32 that is in RHEL6.7, but in the case that they
simply aren't there, libvirt will behave as it did prior to this patch
- no maxCount will be displayed, and the virtual_functions capability
will be absent from the device's XML when 0 VFs are enabled.
2015-11-23 19:19:13 +00:00
|
|
|
* Copyright (C) 2009, 2011-2015 Red Hat, Inc.
|
2009-03-02 16:18:11 +00:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-09-20 22:30:55 +00:00
|
|
|
* License along with this library. If not, see
|
2012-07-21 10:06:23 +00:00
|
|
|
* <http://www.gnu.org/licenses/>.
|
2009-03-02 16:18:11 +00:00
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Mark McLoughlin <markmc@redhat.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __VIR_PCI_H__
|
2010-03-09 18:22:22 +00:00
|
|
|
# define __VIR_PCI_H__
|
2009-03-02 16:18:11 +00:00
|
|
|
|
2010-03-09 18:22:22 +00:00
|
|
|
# include "internal.h"
|
2013-01-16 11:49:54 +00:00
|
|
|
# include "virobject.h"
|
2014-07-24 01:52:22 +00:00
|
|
|
# include "virutil.h"
|
2009-03-02 16:18:11 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
typedef struct _virPCIDevice virPCIDevice;
|
|
|
|
typedef virPCIDevice *virPCIDevicePtr;
|
|
|
|
typedef struct _virPCIDeviceAddress virPCIDeviceAddress;
|
|
|
|
typedef virPCIDeviceAddress *virPCIDeviceAddressPtr;
|
|
|
|
typedef struct _virPCIDeviceList virPCIDeviceList;
|
|
|
|
typedef virPCIDeviceList *virPCIDeviceListPtr;
|
|
|
|
|
|
|
|
struct _virPCIDeviceAddress {
|
2011-08-16 04:28:43 +00:00
|
|
|
unsigned int domain;
|
|
|
|
unsigned int bus;
|
|
|
|
unsigned int slot;
|
|
|
|
unsigned int function;
|
2016-04-03 18:16:51 +00:00
|
|
|
int multi; /* virTristateSwitch */
|
2011-08-16 04:28:43 +00:00
|
|
|
};
|
|
|
|
|
2015-10-23 09:54:07 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_PCI_STUB_DRIVER_NONE = 0,
|
|
|
|
VIR_PCI_STUB_DRIVER_XEN,
|
|
|
|
VIR_PCI_STUB_DRIVER_KVM,
|
|
|
|
VIR_PCI_STUB_DRIVER_VFIO,
|
|
|
|
VIR_PCI_STUB_DRIVER_LAST
|
|
|
|
} virPCIStubDriver;
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virPCIStubDriver);
|
|
|
|
|
2014-07-24 01:52:22 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_PCIE_LINK_SPEED_NA = 0,
|
|
|
|
VIR_PCIE_LINK_SPEED_25,
|
|
|
|
VIR_PCIE_LINK_SPEED_5,
|
|
|
|
VIR_PCIE_LINK_SPEED_8,
|
2017-03-01 09:55:58 +00:00
|
|
|
VIR_PCIE_LINK_SPEED_16,
|
2014-07-24 01:52:22 +00:00
|
|
|
VIR_PCIE_LINK_SPEED_LAST
|
|
|
|
} virPCIELinkSpeed;
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virPCIELinkSpeed)
|
|
|
|
|
2016-03-15 11:22:03 +00:00
|
|
|
typedef enum {
|
|
|
|
VIR_PCI_HEADER_ENDPOINT = 0,
|
|
|
|
VIR_PCI_HEADER_PCI_BRIDGE,
|
|
|
|
VIR_PCI_HEADER_CARDBUS_BRIDGE,
|
|
|
|
|
|
|
|
VIR_PCI_HEADER_LAST
|
|
|
|
} virPCIHeaderType;
|
|
|
|
|
|
|
|
VIR_ENUM_DECL(virPCIHeader)
|
|
|
|
|
2014-07-24 01:52:22 +00:00
|
|
|
typedef struct _virPCIELink virPCIELink;
|
|
|
|
typedef virPCIELink *virPCIELinkPtr;
|
|
|
|
struct _virPCIELink {
|
|
|
|
int port;
|
|
|
|
virPCIELinkSpeed speed;
|
|
|
|
unsigned int width;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct _virPCIEDeviceInfo virPCIEDeviceInfo;
|
|
|
|
typedef virPCIEDeviceInfo *virPCIEDeviceInfoPtr;
|
|
|
|
struct _virPCIEDeviceInfo {
|
|
|
|
/* Not all PCI Express devices have link. For example this 'Root Complex
|
|
|
|
* Integrated Endpoint' and 'Root Complex Event Collector' don't have it. */
|
|
|
|
virPCIELink *link_cap; /* PCIe device link capabilities */
|
|
|
|
virPCIELink *link_sta; /* Actually negotiated capabilities */
|
|
|
|
};
|
|
|
|
|
2013-04-15 10:29:23 +00:00
|
|
|
virPCIDevicePtr virPCIDeviceNew(unsigned int domain,
|
|
|
|
unsigned int bus,
|
|
|
|
unsigned int slot,
|
|
|
|
unsigned int function);
|
2013-05-31 15:06:32 +00:00
|
|
|
virPCIDevicePtr virPCIDeviceCopy(virPCIDevicePtr dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
void virPCIDeviceFree(virPCIDevicePtr dev);
|
|
|
|
const char *virPCIDeviceGetName(virPCIDevicePtr dev);
|
2016-11-19 19:30:03 +00:00
|
|
|
const char *virPCIDeviceGetConfigPath(virPCIDevicePtr dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
|
|
|
|
int virPCIDeviceDetach(virPCIDevicePtr dev,
|
|
|
|
virPCIDeviceListPtr activeDevs,
|
2013-05-30 18:14:46 +00:00
|
|
|
virPCIDeviceListPtr inactiveDevs);
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIDeviceReattach(virPCIDevicePtr dev,
|
|
|
|
virPCIDeviceListPtr activeDevs,
|
pci: autolearn name of stub driver, remove from arglist
virPCIDeviceReattach and virPCIDeviceUnbindFromStub (called by
virPCIDeviceReattach) had previously required the name of the stub
driver as input. This is unnecessary, because the name of the driver
the device is currently bound to can be found by looking at the link:
/sys/bus/pci/dddd:bb:ss.ff/driver
Instead of requiring that the name of the expected stub driver name
and only unbinding if that one name is matched, we no longer take a
driver name in the arglist for either of these
functions. virPCIDeviceUnbindFromStub just compares the name of the
currently bound driver to a list of "well known" stubs (right now
contains "pci-stub" and "vfio-pci" for qemu, and "pciback" for xen),
and only performs the unbind if it's one of those devices.
This allows virsh nodedevice-reattach to work properly across a
libvirtd restart, and fixes a couple of cases where we were
erroneously still hard-coding "pci-stub" as the drive name.
For some unknown reason, virPCIDeviceReattach had been calling
modprobe on the stub driver prior to unbinding the device. This was
problematic because we no longer know the name of the stub driver in
that function. However, it is pointless to probe for the stub driver
at that time anyway - because the device is bound to the stub driver,
we are guaranteed that it is already loaded, and so that call to
modprobe has been removed.
2013-05-01 18:44:10 +00:00
|
|
|
virPCIDeviceListPtr inactiveDevs);
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIDeviceReset(virPCIDevicePtr dev,
|
|
|
|
virPCIDeviceListPtr activeDevs,
|
|
|
|
virPCIDeviceListPtr inactiveDevs);
|
|
|
|
|
|
|
|
void virPCIDeviceSetManaged(virPCIDevice *dev,
|
2013-04-10 10:09:23 +00:00
|
|
|
bool managed);
|
2016-01-28 08:21:43 +00:00
|
|
|
bool virPCIDeviceGetManaged(virPCIDevice *dev);
|
2015-10-23 09:54:07 +00:00
|
|
|
void virPCIDeviceSetStubDriver(virPCIDevicePtr dev,
|
|
|
|
virPCIStubDriver driver);
|
|
|
|
virPCIStubDriver virPCIDeviceGetStubDriver(virPCIDevicePtr dev);
|
2015-01-14 11:02:40 +00:00
|
|
|
virPCIDeviceAddressPtr virPCIDeviceGetAddress(virPCIDevicePtr dev);
|
2014-03-01 06:28:56 +00:00
|
|
|
int virPCIDeviceSetUsedBy(virPCIDevice *dev,
|
|
|
|
const char *drv_name,
|
|
|
|
const char *dom_name);
|
|
|
|
void virPCIDeviceGetUsedBy(virPCIDevice *dev,
|
|
|
|
const char **drv_name,
|
|
|
|
const char **dom_name);
|
2016-01-28 08:21:43 +00:00
|
|
|
bool virPCIDeviceGetUnbindFromStub(virPCIDevicePtr dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
void virPCIDeviceSetUnbindFromStub(virPCIDevice *dev,
|
2013-04-10 10:44:41 +00:00
|
|
|
bool unbind);
|
2016-01-28 08:21:43 +00:00
|
|
|
bool virPCIDeviceGetRemoveSlot(virPCIDevicePtr dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
void virPCIDeviceSetRemoveSlot(virPCIDevice *dev,
|
2013-04-10 10:44:41 +00:00
|
|
|
bool remove_slot);
|
2016-01-28 08:21:43 +00:00
|
|
|
bool virPCIDeviceGetReprobe(virPCIDevicePtr dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
void virPCIDeviceSetReprobe(virPCIDevice *dev,
|
2013-04-10 10:44:41 +00:00
|
|
|
bool reprobe);
|
2013-01-14 22:11:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
virPCIDeviceListPtr virPCIDeviceListNew(void);
|
|
|
|
int virPCIDeviceListAdd(virPCIDeviceListPtr list,
|
|
|
|
virPCIDevicePtr dev);
|
2013-06-25 01:27:52 +00:00
|
|
|
int virPCIDeviceListAddCopy(virPCIDeviceListPtr list, virPCIDevicePtr dev);
|
2013-01-14 22:11:44 +00:00
|
|
|
virPCIDevicePtr virPCIDeviceListGet(virPCIDeviceListPtr list,
|
|
|
|
int idx);
|
2014-01-07 14:44:27 +00:00
|
|
|
size_t virPCIDeviceListCount(virPCIDeviceListPtr list);
|
2013-01-14 22:11:44 +00:00
|
|
|
virPCIDevicePtr virPCIDeviceListSteal(virPCIDeviceListPtr list,
|
|
|
|
virPCIDevicePtr dev);
|
|
|
|
virPCIDevicePtr virPCIDeviceListStealIndex(virPCIDeviceListPtr list,
|
|
|
|
int idx);
|
|
|
|
void virPCIDeviceListDel(virPCIDeviceListPtr list,
|
|
|
|
virPCIDevicePtr dev);
|
|
|
|
virPCIDevicePtr virPCIDeviceListFind(virPCIDeviceListPtr list,
|
|
|
|
virPCIDevicePtr dev);
|
2013-05-31 15:06:32 +00:00
|
|
|
virPCIDevicePtr
|
|
|
|
virPCIDeviceListFindByIDs(virPCIDeviceListPtr list,
|
|
|
|
unsigned int domain,
|
|
|
|
unsigned int bus,
|
|
|
|
unsigned int slot,
|
|
|
|
unsigned int function);
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIDeviceListFindIndex(virPCIDeviceListPtr list,
|
|
|
|
virPCIDevicePtr dev);
|
2009-08-14 07:31:11 +00:00
|
|
|
|
2009-08-14 13:20:40 +00:00
|
|
|
/*
|
|
|
|
* Callback that will be invoked once for each file
|
|
|
|
* associated with / used for PCI host device access.
|
|
|
|
*
|
|
|
|
* Should return 0 if successfully processed, or
|
|
|
|
* -1 to indicate error and abort iteration
|
|
|
|
*/
|
2013-01-14 22:11:44 +00:00
|
|
|
typedef int (*virPCIDeviceFileActor)(virPCIDevicePtr dev,
|
|
|
|
const char *path, void *opaque);
|
|
|
|
int virPCIDeviceFileIterate(virPCIDevicePtr dev,
|
|
|
|
virPCIDeviceFileActor actor,
|
|
|
|
void *opaque);
|
2013-06-23 18:47:57 +00:00
|
|
|
|
2016-04-03 18:16:51 +00:00
|
|
|
typedef int (*virPCIDeviceAddressActor)(virPCIDeviceAddressPtr addr,
|
2013-06-23 18:47:57 +00:00
|
|
|
void *opaque);
|
|
|
|
int virPCIDeviceAddressIOMMUGroupIterate(virPCIDeviceAddressPtr orig,
|
|
|
|
virPCIDeviceAddressActor actor,
|
|
|
|
void *opaque);
|
|
|
|
virPCIDeviceListPtr virPCIDeviceGetIOMMUGroupList(virPCIDevicePtr dev);
|
|
|
|
int virPCIDeviceAddressGetIOMMUGroupAddresses(virPCIDeviceAddressPtr devAddr,
|
|
|
|
virPCIDeviceAddressPtr **iommuGroupDevices,
|
|
|
|
size_t *nIommuGroupDevices);
|
2015-12-15 08:53:31 +00:00
|
|
|
int virPCIDeviceAddressGetIOMMUGroupNum(virPCIDeviceAddressPtr addr);
|
2013-06-23 18:47:57 +00:00
|
|
|
char *virPCIDeviceGetIOMMUGroupDev(virPCIDevicePtr dev);
|
2009-08-14 13:20:40 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIDeviceIsAssignable(virPCIDevicePtr dev,
|
|
|
|
int strict_acs_check);
|
|
|
|
int virPCIDeviceWaitForCleanup(virPCIDevicePtr dev, const char *matcher);
|
2009-12-22 17:21:15 +00:00
|
|
|
|
2017-03-07 19:23:01 +00:00
|
|
|
virPCIDeviceAddressPtr
|
|
|
|
virPCIGetDeviceAddressFromSysfsLink(const char *device_link);
|
|
|
|
|
2015-12-20 22:58:58 +00:00
|
|
|
int virPCIGetPhysicalFunction(const char *vf_sysfs_path,
|
|
|
|
virPCIDeviceAddressPtr *pf);
|
2011-08-16 04:28:43 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIGetVirtualFunctions(const char *sysfs_path,
|
|
|
|
virPCIDeviceAddressPtr **virtual_functions,
|
nodedev: report maxCount for virtual_functions capability
A PCI device may have the capability to setup virtual functions (VFs)
but have them currently all disabled. Prior to this patch, if that was
the case the the node device XML for the device wouldn't report any
virtual_functions capability.
With this patch, if a file called "sriov_totalvfs" is found in the
device's sysfs directory, its contents will be interpreted as a
decimal number, and that value will be reported as "maxCount" in a
capability element of the device's XML, e.g.:
<capability type='virtual_functions' maxCount='7'/>
This will be reported regardless of whether or not any VFs are
currently enabled for the device.
NB: sriov_numvfs (the number of VFs currently active) is also
available in sysfs, but that value is implied by the number of items
in the list that is inside the capability element, so there is no
reason to explicitly provide it as an attribute.
sriov_totalvfs and sriov_numvfs are available in kernels at least as far
back as the 2.6.32 that is in RHEL6.7, but in the case that they
simply aren't there, libvirt will behave as it did prior to this patch
- no maxCount will be displayed, and the virtual_functions capability
will be absent from the device's XML when 0 VFs are enabled.
2015-11-23 19:19:13 +00:00
|
|
|
size_t *num_virtual_functions,
|
|
|
|
unsigned int *max_virtual_functions);
|
2011-08-16 04:28:43 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIIsVirtualFunction(const char *vf_sysfs_device_link);
|
2011-08-16 04:28:48 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link,
|
|
|
|
const char *vf_sysfs_device_link,
|
|
|
|
int *vf_index);
|
2011-08-16 04:28:48 +00:00
|
|
|
|
2015-12-15 08:53:31 +00:00
|
|
|
int virPCIDeviceAddressGetSysfsFile(virPCIDeviceAddressPtr addr,
|
2013-01-14 22:11:44 +00:00
|
|
|
char **pci_sysfs_device_link);
|
2012-03-06 01:12:23 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIGetNetName(char *device_link_sysfs_path, char **netname);
|
2011-08-16 04:28:48 +00:00
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIGetSysfsFile(char *virPCIDeviceName,
|
|
|
|
char **pci_sysfs_device_link)
|
2011-12-14 10:50:01 +00:00
|
|
|
ATTRIBUTE_RETURN_CHECK;
|
|
|
|
|
2013-04-15 10:29:23 +00:00
|
|
|
int virPCIGetAddrString(unsigned int domain,
|
|
|
|
unsigned int bus,
|
|
|
|
unsigned int slot,
|
|
|
|
unsigned int function,
|
2013-01-14 22:11:44 +00:00
|
|
|
char **pciConfigAddr)
|
2011-12-14 10:50:14 +00:00
|
|
|
ATTRIBUTE_NONNULL(5) ATTRIBUTE_RETURN_CHECK;
|
2012-03-06 01:12:23 +00:00
|
|
|
|
2013-06-17 15:57:19 +00:00
|
|
|
int virPCIDeviceAddressParse(char *address, virPCIDeviceAddressPtr bdf);
|
|
|
|
|
2013-01-14 22:11:44 +00:00
|
|
|
int virPCIGetVirtualFunctionInfo(const char *vf_sysfs_device_path,
|
|
|
|
char **pfname, int *vf_index);
|
2012-03-06 01:12:23 +00:00
|
|
|
|
2015-10-29 15:09:54 +00:00
|
|
|
int virPCIDeviceUnbind(virPCIDevicePtr dev);
|
2017-03-07 17:58:15 +00:00
|
|
|
int virPCIDeviceRebind(virPCIDevicePtr dev);
|
2014-01-16 11:27:23 +00:00
|
|
|
int virPCIDeviceGetDriverPathAndName(virPCIDevicePtr dev,
|
|
|
|
char **path,
|
|
|
|
char **name);
|
|
|
|
|
2014-05-15 08:04:28 +00:00
|
|
|
int virPCIDeviceIsPCIExpress(virPCIDevicePtr dev);
|
|
|
|
int virPCIDeviceHasPCIExpressLink(virPCIDevicePtr dev);
|
|
|
|
int virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev,
|
|
|
|
int *ca_port,
|
|
|
|
unsigned int *cap_speed,
|
|
|
|
unsigned int *cap_width,
|
|
|
|
unsigned int *sta_speed,
|
|
|
|
unsigned int *sta_width);
|
2014-07-23 04:38:30 +00:00
|
|
|
|
2016-03-15 11:22:03 +00:00
|
|
|
int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType);
|
|
|
|
|
2014-07-23 04:38:30 +00:00
|
|
|
void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev);
|
|
|
|
|
2009-03-02 16:18:11 +00:00
|
|
|
#endif /* __VIR_PCI_H__ */
|