From nobody Thu Nov 28 16:51:56 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=libvir-list-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1521099112517612.1159726878664; Thu, 15 Mar 2018 00:31:52 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D3C487F7AF; Thu, 15 Mar 2018 07:31:50 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 9A86518945; Thu, 15 Mar 2018 07:31:50 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 5DF66181B9FD; Thu, 15 Mar 2018 07:31:50 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2EHISYk024552 for ; Wed, 14 Mar 2018 13:18:40 -0400 Received: by smtp.corp.redhat.com (Postfix) id 58F9754580; Wed, 14 Mar 2018 17:18:28 +0000 (UTC) Received: from mx1.redhat.com (ext-mx04.extmail.prod.ext.phx2.redhat.com [10.5.110.28]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 4C265608F7 for ; Wed, 14 Mar 2018 17:18:25 +0000 (UTC) Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3C9088049B for ; Wed, 14 Mar 2018 17:18:24 +0000 (UTC) Received: from pps.filterd (m0098399.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.22/8.16.0.22) with SMTP id w2EHGOTu065395 for ; Wed, 14 Mar 2018 13:18:23 -0400 Received: from e06smtp12.uk.ibm.com (e06smtp12.uk.ibm.com [195.75.94.108]) by mx0a-001b2d01.pphosted.com with ESMTP id 2gq5bd05wg-1 (version=TLSv1.2 cipher=AES256-SHA256 bits=256 verify=NOT) for ; Wed, 14 Mar 2018 13:18:22 -0400 Received: from localhost by e06smtp12.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Wed, 14 Mar 2018 17:18:20 -0000 Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198) by e06smtp12.uk.ibm.com (192.168.101.142) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Wed, 14 Mar 2018 17:18:19 -0000 Received: from d06av22.portsmouth.uk.ibm.com (d06av22.portsmouth.uk.ibm.com [9.149.105.58]) by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id w2EHIJei56623138 for ; Wed, 14 Mar 2018 17:18:19 GMT Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8FEAD4C040 for ; Wed, 14 Mar 2018 17:11:33 +0000 (GMT) Received: from d06av22.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 0DCDF4C044 for ; Wed, 14 Mar 2018 17:11:33 +0000 (GMT) Received: from localhost.localdomain (unknown [9.79.182.166]) by d06av22.portsmouth.uk.ibm.com (Postfix) with ESMTP for ; Wed, 14 Mar 2018 17:11:32 +0000 (GMT) From: Shivaprasad G Bhat To: libvir-list@redhat.com Date: Wed, 14 Mar 2018 22:48:17 +0530 In-Reply-To: <152104711186.10112.1077788328340024644.stgit@localhost.localdomain> References: <152104711186.10112.1077788328340024644.stgit@localhost.localdomain> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 18031417-0008-0000-0000-000004DD7906 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 18031417-0009-0000-0000-00001E707EC2 Message-Id: <152104786997.10112.1455235497465118846.stgit@localhost.localdomain> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2018-03-14_09:, , signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1803140192 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 207 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 14 Mar 2018 17:18:24 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Wed, 14 Mar 2018 17:18:24 +0000 (UTC) for IP:'148.163.156.1' DOMAIN:'mx0a-001b2d01.pphosted.com' HELO:'mx0a-001b2d01.pphosted.com' FROM:'sbhat@linux.vnet.ibm.com' RCPT:'' X-RedHat-Spam-Score: -0.701 (RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2) 148.163.156.1 mx0a-001b2d01.pphosted.com 148.163.156.1 mx0a-001b2d01.pphosted.com X-Scanned-By: MIMEDefang 2.78 on 10.5.110.28 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-loop: libvir-list@redhat.com Subject: [libvirt] [RFC PATCH 08/28] util: virpci: detect if the device is a multifunction device from sysfs X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Transfer-Encoding: quoted-printable Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 15 Mar 2018 07:31:51 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Shivaprasad G Bhat --- src/libvirt_private.syms | 1 + src/node_device/node_device_udev.c | 2 +- src/util/virhostdev.c | 2 +- src/util/virpci.c | 20 ++++++++++++++++++-- src/util/virpci.h | 3 ++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index e1bdaa127e..53e174a223 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -2462,6 +2462,7 @@ virPCIDeviceGetUnbindFromStub; virPCIDeviceGetUsedBy; virPCIDeviceHasPCIExpressLink; virPCIDeviceIsAssignable; +virPCIDeviceIsMultifunction; virPCIDeviceIsPCIExpress; virPCIDeviceListAdd; virPCIDeviceListAddCopy; diff --git a/src/node_device/node_device_udev.c b/src/node_device/node_devi= ce_udev.c index e87eb32a85..99b936bb5c 100644 --- a/src/node_device/node_device_udev.c +++ b/src/node_device/node_device_udev.c @@ -455,7 +455,7 @@ udevProcessPCI(struct udev_device *device, =20 /* We need to be root to read PCI device configs */ if (privileged) { - if (virPCIGetHeaderType(pciDev, &pci_dev->hdrType) < 0) + if (virPCIGetHeaderType(pciDev, &pci_dev->hdrType, NULL) < 0) goto cleanup; =20 if (virPCIDeviceIsPCIExpress(pciDev) > 0) { diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c index e0133cdeec..807caf567a 100644 --- a/src/util/virhostdev.c +++ b/src/util/virhostdev.c @@ -693,7 +693,7 @@ virHostdevPreparePCIDevices(virHostdevManagerPtr mgr, struct virHostdevIsPCINodeDeviceUsedData data =3D { mgr, dom_name,= usesVFIO }; int hdrType =3D -1; =20 - if (virPCIGetHeaderType(pci, &hdrType) < 0) + if (virPCIGetHeaderType(pci, &hdrType, NULL) < 0) goto cleanup; =20 if (hdrType !=3D VIR_PCI_HEADER_ENDPOINT) { diff --git a/src/util/virpci.c b/src/util/virpci.c index 55e4c3e492..a827b3bc0f 100644 --- a/src/util/virpci.c +++ b/src/util/virpci.c @@ -936,7 +936,7 @@ virPCIDeviceReset(virPCIDevicePtr dev, int fd =3D -1; int hdrType =3D -1; =20 - if (virPCIGetHeaderType(dev, &hdrType) < 0) + if (virPCIGetHeaderType(dev, &hdrType, NULL) < 0) return -1; =20 if (hdrType !=3D VIR_PCI_HEADER_ENDPOINT) { @@ -3169,6 +3169,18 @@ virPCIGetMdevTypes(const char *sysfspath ATTRIBUTE_U= NUSED, } #endif /* __linux__ */ =20 +bool +virPCIDeviceIsMultifunction(virPCIDevicePtr dev) +{ + bool multifunction =3D false; + int hdrType =3D -1; + + if (virPCIGetHeaderType(dev, &hdrType, &multifunction) < 0) + return false; + + return multifunction; +} + int virPCIDeviceIsPCIExpress(virPCIDevicePtr dev) { @@ -3254,10 +3266,11 @@ virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev, } =20 =20 -int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType) +int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType, bool *multiFunc) { int fd; uint8_t type; + bool multi =3D false; =20 *hdrType =3D -1; =20 @@ -3268,6 +3281,7 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdr= Type) =20 virPCIDeviceConfigClose(dev, fd); =20 + multi =3D type & PCI_HEADER_TYPE_MULTI; type &=3D PCI_HEADER_TYPE_MASK; if (type >=3D VIR_PCI_HEADER_LAST) { virReportError(VIR_ERR_INTERNAL_ERROR, @@ -3276,6 +3290,8 @@ int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdr= Type) } =20 *hdrType =3D type; + if (multiFunc) + *multiFunc =3D multi; =20 return 0; } diff --git a/src/util/virpci.h b/src/util/virpci.h index 794b7e59db..179249677a 100644 --- a/src/util/virpci.h +++ b/src/util/virpci.h @@ -199,6 +199,7 @@ int virPCIGetVirtualFunctions(const char *sysfs_path, size_t *num_virtual_functions, unsigned int *max_virtual_functions); =20 +bool virPCIDeviceIsMultifunction(virPCIDevicePtr dev); int virPCIIsVirtualFunction(const char *vf_sysfs_device_link); =20 int virPCIGetVirtualFunctionIndex(const char *pf_sysfs_device_link, @@ -246,7 +247,7 @@ int virPCIDeviceGetLinkCapSta(virPCIDevicePtr dev, unsigned int *sta_speed, unsigned int *sta_width); =20 -int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType); +int virPCIGetHeaderType(virPCIDevicePtr dev, int *hdrType, bool *multiFunc= ); =20 void virPCIEDeviceInfoFree(virPCIEDeviceInfoPtr dev); =20 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list