From: Alexander Duyck <alexander.h.duyck@intel.com>
To: bhelgaas@google.com, ddutile@redhat.com
Cc: linux-pci@vger.kernel.org, alex.williamson@redhat.com,
linux-kernel@vger.kernel.org
Subject: [PATCH 2/2] iov: Use pci_walk_vbus for tasks where we must search for VFs
Date: Wed, 28 May 2014 15:29:28 -0700 [thread overview]
Message-ID: <20140528222914.18898.42967.stgit@ahduyck-cp2.jf.intel.com> (raw)
In-Reply-To: <20140528222901.18898.48031.stgit@ahduyck-cp2.jf.intel.com>
This change makes it so that we use pci_walk_vbus to go though and search
for all devices that are contained within the local bus of our device.
Signed-off-by: Alexander Duyck <alexander.h.duyck@intel.com>
---
drivers/pci/iov.c | 50 +++++++++++++++++++++++++++-----------------------
1 files changed, 27 insertions(+), 23 deletions(-)
diff --git a/drivers/pci/iov.c b/drivers/pci/iov.c
index de7a747..717f202 100644
--- a/drivers/pci/iov.c
+++ b/drivers/pci/iov.c
@@ -602,6 +602,30 @@ int pci_num_vf(struct pci_dev *dev)
}
EXPORT_SYMBOL_GPL(pci_num_vf);
+struct vfs_assigned {
+ struct pci_dev *physfn;
+ unsigned int count;
+};
+
+/**
+ * pci_vfs_assigned_cb - callback used by pci_vfs_assigned
+ * @dev: the PCI device
+ * @data: Pointer to structure used by pci_vfs_assigned
+ *
+ * If the device is a virtual function and belongs to the provided PF
+ * and is assigned this will increment the count by 1.
+ */
+static int pci_vfs_assigned_cb(struct pci_dev *dev, void *data)
+{
+ struct vfs_assigned *vfa = data;
+
+ if (dev->is_virtfn && (dev->physfn == vfa->physfn) &&
+ (dev->dev_flags & PCI_DEV_FLAGS_ASSIGNED))
+ vfa->count++;
+
+ return 0;
+}
+
/**
* pci_vfs_assigned - returns number of VFs are assigned to a guest
* @dev: the PCI device
@@ -611,35 +635,15 @@ EXPORT_SYMBOL_GPL(pci_num_vf);
*/
int pci_vfs_assigned(struct pci_dev *dev)
{
- struct pci_dev *vfdev;
- unsigned int vfs_assigned = 0;
- unsigned short dev_id;
+ struct vfs_assigned vfa = { .physfn = dev, .count = 0 };
/* only search if we are a PF */
if (!dev->is_physfn)
return 0;
- /*
- * determine the device ID for the VFs, the vendor ID will be the
- * same as the PF so there is no need to check for that one
- */
- pci_read_config_word(dev, dev->sriov->pos + PCI_SRIOV_VF_DID, &dev_id);
-
- /* loop through all the VFs to see if we own any that are assigned */
- vfdev = pci_get_device(dev->vendor, dev_id, NULL);
- while (vfdev) {
- /*
- * It is considered assigned if it is a virtual function with
- * our dev as the physical function and the assigned bit is set
- */
- if (vfdev->is_virtfn && (vfdev->physfn == dev) &&
- (vfdev->dev_flags & PCI_DEV_FLAGS_ASSIGNED))
- vfs_assigned++;
-
- vfdev = pci_get_device(dev->vendor, dev_id, vfdev);
- }
+ pci_walk_vbus(dev->bus, pci_vfs_assigned_cb, &vfa);
- return vfs_assigned;
+ return vfa.count;
}
EXPORT_SYMBOL_GPL(pci_vfs_assigned);
next prev parent reply other threads:[~2014-05-28 22:30 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-05-28 22:29 [PATCH 1/2] pci: Add pci_walk_vbus for walking virtual busses associated with SR-IOV Alexander Duyck
2014-05-28 22:29 ` Alexander Duyck [this message]
2014-05-29 23:00 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140528222914.18898.42967.stgit@ahduyck-cp2.jf.intel.com \
--to=alexander.h.duyck@intel.com \
--cc=alex.williamson@redhat.com \
--cc=bhelgaas@google.com \
--cc=ddutile@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®