On Thu, Jun 12, 2014 at 12:08:08PM +0200, Michal Privoznik wrote:
On 12.06.2014 10:56, Martin Kletzander wrote:
> On Fri, Jun 06, 2014 at 12:54:17PM +0200, Michal Privoznik wrote:
>> These functions will handle PCIe devices and their link capabilities
>> to query some info about it.
>>
>> Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
>> ---
>> src/libvirt_private.syms | 3 ++
>> src/util/virpci.c | 81
>> +++++++++++++++++++++++++++++++++++++++++++++++-
>> src/util/virpci.h | 8 +++++
>> 3 files changed, 91 insertions(+), 1 deletion(-)
>>
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index d73a9f5..f72a3ad 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -1690,6 +1690,8 @@ virPCIDeviceFree;
>> virPCIDeviceGetDriverPathAndName;
>> virPCIDeviceGetIOMMUGroupDev;
>> virPCIDeviceGetIOMMUGroupList;
>> +virPCIDeviceGetLinkCap;
>> +virPCIDeviceGetLinkSta;
>> virPCIDeviceGetManaged;
>> virPCIDeviceGetName;
>> virPCIDeviceGetRemoveSlot;
>> @@ -1698,6 +1700,7 @@ virPCIDeviceGetStubDriver;
>> virPCIDeviceGetUnbindFromStub;
>> virPCIDeviceGetUsedBy;
>> virPCIDeviceIsAssignable;
>> +virPCIDeviceIsPCIExpress;
>> virPCIDeviceListAdd;
>> virPCIDeviceListAddCopy;
>> virPCIDeviceListCount;
>> diff --git a/src/util/virpci.c b/src/util/virpci.c
>> index e0f2344..8ad28b8 100644
>> --- a/src/util/virpci.c
>> +++ b/src/util/virpci.c
>> @@ -130,7 +130,13 @@ struct _virPCIDeviceList {
>>
>> /* PCIe20 7.8.3 Device Capabilities Register (Offset 04h) */
>> #define PCI_EXP_DEVCAP 0x4 /* Device capabilities */
>> -#define PCI_EXP_DEVCAP_FLR (1<<28) /* Function Level Reset */
>> +#define PCI_EXP_LNKCAP 0xc /* Link Capabilities */
>> +#define PCI_EXP_LNKSTA 0x12 /* Link Status */
>> +#define PCI_EXP_DEVCAP_FLR (1<<28) /* Function Level Reset */
>> +#define PCI_EXP_LNKCAP_SPEED 0x0000f /* Maximum Link Speed */
>> +#define PCI_EXP_LNKCAP_WIDTH 0x003f0 /* Maximum Link Width */
>> +#define PCI_EXP_LNKSTA_SPEED 0x000f /* Negotiated Link Speed */
>> +#define PCI_EXP_LNKSTA_WIDTH 0x03f0 /* Negotiated Link Width */
>>
>
> These two sets are essentially the same, just keep it as e.g.
> PCI_EXP_LINK_(SPEED|WIDTH) with 0x(f|3f) respectively. And keep the
> order of the names alphabetical.
The values are copied from /usr/include/pci/header.h. One day we could
drop all of these copies and include the file directly. For that, I'd
rather keep it just as is in the foreign file. Until the time we do
that, I'm sorting these alphabetically, okay.
Well, the only ones I was concerned with were simple masks for 8 bits
and 13 bits, there's nothing special about those. We even use:
"(1 << x) - 1" for mask of x bits somewhere, I think. Including them
fromt he system is probably the best option (for applicable systems,
of course), so that would be preferred. Be sure we depend on
pciutils-devel or what's the package if we don't already.
Martin