xen-devel.lists.xenproject.org archive mirror
 help / color / mirror / Atom feed
From: Keir Fraser <keir.fraser@eu.citrix.com>
To: "xen-devel@lists.xensource.com" <xen-devel@lists.xensource.com>,
	Ian Campbell <Ian.Campbell@eu.citrix.com>,
	Jeremy Fitzhardinge <jeremy@goop.org>,
	Jan Beulich <JBeulich@novell.com>
Cc: Ian Pratt <Ian.Pratt@eu.citrix.com>
Subject: [DOM0 KERNELS] pciback: Fix SR-IOV VF passthrough
Date: Fri, 26 Feb 2010 17:25:45 +0000	[thread overview]
Message-ID: <C7ADB49A.B801%keir.fraser@eu.citrix.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 571 bytes --]

Vendor/device and BAR fields in a VF's host-level PCI config space are dummy
and must always be virtualised/emulated. Implement this in pciback by always
extracting the values installed in dom0 kernel's own PCI structures, rather
than interrogating the underlying PCI config space directly.

AFAIK, this patch should apply to any kernel that implements pciback: That
includes pv_ops, SLES, and the XS/XCP kernels. It should be applied to all
of them. It is already applied to linux-2.6.18-xen.hg as 998:693c40564c8d.

Signed-off-by: Keir Fraser <keir.fraser@citrix.com>


[-- Attachment #2: 00-pciback --]
[-- Type: application/octet-stream, Size: 3000 bytes --]

diff --git a/drivers/xen/pciback/conf_space_header.c b/drivers/xen/pciback/conf_space_header.c
index 3ae7da1..66a46dd 100644
--- a/drivers/xen/pciback/conf_space_header.c
+++ b/drivers/xen/pciback/conf_space_header.c
@@ -74,17 +74,7 @@ static int rom_write(struct pci_dev *dev, int offset, u32 value, void *data)
 	/* A write to obtain the length must happen as a 32-bit write.
 	 * This does not (yet) support writing individual bytes
 	 */
-	if (value == ~PCI_ROM_ADDRESS_ENABLE)
-		bar->which = 1;
-	else {
-		u32 tmpval;
-		pci_read_config_dword(dev, offset, &tmpval);
-		if (tmpval != bar->val && value == bar->val) {
-			/* Allow restoration of bar value. */
-			pci_write_config_dword(dev, offset, bar->val);
-		}
-		bar->which = 0;
-	}
+	bar->which = (value == ~PCI_ROM_ADDRESS_ENABLE);
 
 	/* Do we need to support enabling/disabling the rom address here? */
 
@@ -108,17 +98,7 @@ static int bar_write(struct pci_dev *dev, int offset, u32 value, void *data)
 	/* A write to obtain the length must happen as a 32-bit write.
 	 * This does not (yet) support writing individual bytes
 	 */
-	if (value == ~0)
-		bar->which = 1;
-	else {
-		u32 tmpval;
-		pci_read_config_dword(dev, offset, &tmpval);
-		if (tmpval != bar->val && value == bar->val) {
-			/* Allow restoration of bar value. */
-			pci_write_config_dword(dev, offset, bar->val);
-		}
-		bar->which = 0;
-	}
+	bar->which = (value == ~0);
 
 	return 0;
 }
@@ -126,6 +106,10 @@ static int bar_write(struct pci_dev *dev, int offset, u32 value, void *data)
 static int bar_read(struct pci_dev *dev, int offset, u32 * value, void *data)
 {
 	struct pci_bar_info *bar = data;
+	int idx = (offset - 0x10) >> 2;
+
+	if (idx > PCI_STD_RESOURCE_END )
+		idx = PCI_ROM_RESOURCE;
 
 	if (unlikely(!bar)) {
 		printk(KERN_WARNING "pciback: driver data not found for %s\n",
@@ -133,7 +117,8 @@ static int bar_read(struct pci_dev *dev, int offset, u32 * value, void *data)
 		return XEN_PCI_ERR_op_failed;
 	}
 
-	*value = bar->which ? bar->len_val : bar->val;
+	*value = bar->which ? ~(pci_resource_len(dev, idx)-1) : pci_resource_start(dev, idx);
+	*value |= pci_resource_flags(dev, idx) & 0xf;
 
 	return 0;
 }
@@ -194,6 +179,22 @@ static int interrupt_read(struct pci_dev *dev, int offset, u8 * value,
 	return 0;
 }
 
+static int vendor_read(struct pci_dev *dev, int offset, u16 * value,
+		       void *data)
+{
+	*value = dev->vendor;
+
+	return 0;
+}
+
+static int device_read(struct pci_dev *dev, int offset, u16 * value,
+		       void *data)
+{
+	*value = dev->device;
+
+	return 0;
+}
+
 static int bist_write(struct pci_dev *dev, int offset, u8 value, void *data)
 {
 	u8 cur_value;
@@ -213,6 +214,16 @@ out:
 
 static const struct config_field header_common[] = {
 	{
+	 .offset    = PCI_VENDOR_ID,
+	 .size      = 2,
+	 .u.w.read  = vendor_read
+	},
+	{
+	 .offset    = PCI_DEVICE_ID,
+	 .size      = 2,
+	 .u.w.read  = device_read
+	},
+	{
 	 .offset    = PCI_COMMAND,
 	 .size      = 2,
 	 .u.w.read  = pciback_read_config_word,

[-- Attachment #3: Type: text/plain, Size: 138 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xensource.com
http://lists.xensource.com/xen-devel

             reply	other threads:[~2010-02-26 17:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-02-26 17:25 Keir Fraser [this message]
2010-02-26 20:51 ` [DOM0 KERNELS] pciback: Fix SR-IOV VF passthrough Konrad Rzeszutek Wilk
2010-03-01  9:06 ` Jan Beulich
2010-03-01  9:45   ` Keir Fraser
2010-03-01 16:20   ` Konrad Rzeszutek Wilk
2010-03-01 16:49     ` Keir Fraser
2010-03-01 19:12       ` Konrad Rzeszutek Wilk
2010-03-01 22:21         ` Keir Fraser
2010-03-02  9:33     ` Jan Beulich

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=C7ADB49A.B801%keir.fraser@eu.citrix.com \
    --to=keir.fraser@eu.citrix.com \
    --cc=Ian.Campbell@eu.citrix.com \
    --cc=Ian.Pratt@eu.citrix.com \
    --cc=JBeulich@novell.com \
    --cc=jeremy@goop.org \
    --cc=xen-devel@lists.xensource.com \
    /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;
as well as URLs for NNTP newsgroup(s).