From: "Jan Beulich" Subject: [PATCH 3/3] passthrough: allow to suppress SERR and PERR signaling altogether Date: Thu, 03 Apr 2014 10:41:09 +0100 Message-ID: <533D48D50200007800005128@nat28.tlf.novell.com> References: <533D471D0200007800005104@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part8FBDECA5.1__=" Return-path: Received: from mail6.bemta4.messagelabs.com ([85.158.143.247]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1WVe93-0001PT-En for xen-devel@lists.xenproject.org; Thu, 03 Apr 2014 09:41:15 +0000 In-Reply-To: <533D471D0200007800005104@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel Cc: Asit K Mallick , xiantao.zhang@intel.com, Keir Fraser , Jun Nakajima , Donald D Dugger List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__Part8FBDECA5.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline This is just to have a workaround at hand in case other chipsets (not covered by the previous two patches) also have similar issues. Signed-off-by: Jan Beulich --- a/xen/drivers/passthrough/pci.c +++ b/xen/drivers/passthrough/pci.c @@ -154,6 +154,112 @@ static void __init parse_phantom_dev(cha } custom_param("pci-phantom", parse_phantom_dev); =20 +static u16 __read_mostly command_mask; +static u16 __read_mostly bridge_ctl_mask; + +/* + * The 'pci' parameter controls certain PCI device aspects. + * Optional comma separated value may contain: + * + * serr don't suppress system errors (default) + * no-serr suppress system errors + * perr don't suppress parity errors (default) + * no-perr suppress parity errors + */ +static void __init parse_pci_param(char *s) +{ + char *ss; + + do { + bool_t on =3D !!strncmp(s, "no-", 3); + u16 cmd_mask =3D 0, brctl_mask =3D 0; + + if ( !on ) + s +=3D 3; + + ss =3D strchr(s, ','); + if ( ss ) + *ss =3D '\0'; + + if ( !strcmp(s, "serr") ) + { + cmd_mask =3D PCI_COMMAND_SERR; + brctl_mask =3D PCI_BRIDGE_CTL_SERR | PCI_BRIDGE_CTL_DTMR_SERR;= + } + else if ( !strcmp(s, "perr") ) + { + cmd_mask =3D PCI_COMMAND_PARITY; + brctl_mask =3D PCI_BRIDGE_CTL_PARITY; + } + + if ( on ) + { + command_mask &=3D ~cmd_mask; + bridge_ctl_mask &=3D ~brctl_mask; + } + else + { + command_mask |=3D cmd_mask; + bridge_ctl_mask |=3D brctl_mask; + } + + s =3D ss + 1; + } while ( ss ); +} +custom_param("pci", parse_pci_param); + +static void check_pdev(const struct pci_dev *pdev) +{ +#define PCI_STATUS_CHECK \ + (PCI_STATUS_PARITY | PCI_STATUS_SIG_TARGET_ABORT | \ + PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_REC_MASTER_ABORT | \ + PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_DETECTED_PARITY) + u16 seg =3D pdev->seg; + u8 bus =3D pdev->bus; + u8 dev =3D PCI_SLOT(pdev->devfn); + u8 func =3D PCI_FUNC(pdev->devfn); + u16 val; + + if ( command_mask ) + { + val =3D pci_conf_read16(seg, bus, dev, func, PCI_COMMAND); + if ( val & command_mask ) + pci_conf_write16(seg, bus, dev, func, PCI_COMMAND, + val & ~command_mask); + val =3D pci_conf_read16(seg, bus, dev, func, PCI_STATUS); + if ( val & PCI_STATUS_CHECK ) + { + printk(XENLOG_INFO "%04x:%02x:%02x.%u status %04x\n", + seg, bus, dev, func, val); + pci_conf_write16(seg, bus, dev, func, PCI_STATUS, val); + } + } + + switch ( pci_conf_read8(seg, bus, dev, func, PCI_HEADER_TYPE) & 0x7f = ) + { + case PCI_HEADER_TYPE_BRIDGE: + if ( !bridge_ctl_mask ) + break; + val =3D pci_conf_read16(seg, bus, dev, func, PCI_BRIDGE_CONTROL); + if ( val & bridge_ctl_mask ) + pci_conf_write16(seg, bus, dev, func, PCI_BRIDGE_CONTROL, + val & ~bridge_ctl_mask); + val =3D pci_conf_read16(seg, bus, dev, func, PCI_SEC_STATUS); + if ( val & PCI_STATUS_CHECK ) + { + printk(XENLOG_INFO "%04x:%02x:%02x.%u secondary status = %04x\n", + seg, bus, dev, func, val); + pci_conf_write16(seg, bus, dev, func, PCI_SEC_STATUS, val); + } + break; + + case PCI_HEADER_TYPE_CARDBUS: + /* TODO */ + break; + } +#undef PCI_STATUS_CHECK +} + static struct pci_dev *alloc_pdev(struct pci_seg *pseg, u8 bus, u8 devfn) { struct pci_dev *pdev; @@ -252,6 +358,8 @@ static struct pci_dev *alloc_pdev(struct break; } =20 + check_pdev(pdev); + return pdev; } =20 @@ -566,6 +674,8 @@ int pci_add_device(u16 seg, u8 bus, u8 d seg, bus, slot, func, ctrl); } =20 + check_pdev(pdev); + ret =3D 0; if ( !pdev->domain ) { --- a/xen/include/xen/pci_regs.h +++ b/xen/include/xen/pci_regs.h @@ -125,7 +125,7 @@ #define PCI_IO_RANGE_TYPE_16 0x00 #define PCI_IO_RANGE_TYPE_32 0x01 #define PCI_IO_RANGE_MASK (~0x0fUL) -#define PCI_SEC_STATUS 0x1e /* Secondary status register, only = bit 14 used */ +#define PCI_SEC_STATUS 0x1e /* Secondary status register */ #define PCI_MEMORY_BASE 0x20 /* Memory range behind */ #define PCI_MEMORY_LIMIT 0x22 #define PCI_MEMORY_RANGE_TYPE_MASK 0x0fUL @@ -152,6 +152,7 @@ #define PCI_BRIDGE_CTL_MASTER_ABORT 0x20 /* Report master aborts */ #define PCI_BRIDGE_CTL_BUS_RESET 0x40 /* Secondary bus reset */ #define PCI_BRIDGE_CTL_FAST_BACK 0x80 /* Fast Back2Back enabled = on secondary interface */ +#define PCI_BRIDGE_CTL_DTMR_SERR 0x800 /* SERR upon discard timer = expiry */ =20 /* Header type 2 (CardBus bridges) */ #define PCI_CB_CAPABILITY_LIST 0x14 --=__Part8FBDECA5.1__= Content-Type: text/plain; name="pt-suppress-SERR.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="pt-suppress-SERR.patch" passthrough: allow to suppress SERR and PERR signaling altogether=0A=0AThis= is just to have a workaround at hand in case other chipsets (not=0Acovered= by the previous two patches) also have similar issues.=0A=0ASigned-off-by:= Jan Beulich =0A=0A--- a/xen/drivers/passthrough/pci.c= =0A+++ b/xen/drivers/passthrough/pci.c=0A@@ -154,6 +154,112 @@ static void = __init parse_phantom_dev(cha=0A }=0A custom_param("pci-phantom", parse_phan= tom_dev);=0A =0A+static u16 __read_mostly command_mask;=0A+static u16 = __read_mostly bridge_ctl_mask;=0A+=0A+/*=0A+ * The 'pci' parameter = controls certain PCI device aspects.=0A+ * Optional comma separated value = may contain:=0A+ *=0A+ * serr don't suppress = system errors (default)=0A+ * no-serr suppress system = errors=0A+ * perr don't suppress parity errors = (default)=0A+ * no-perr suppress parity errors=0A+ = */=0A+static void __init parse_pci_param(char *s)=0A+{=0A+ char = *ss;=0A+=0A+ do {=0A+ bool_t on =3D !!strncmp(s, "no-", 3);=0A+ = u16 cmd_mask =3D 0, brctl_mask =3D 0;=0A+=0A+ if ( !on )=0A+ = s +=3D 3;=0A+=0A+ ss =3D strchr(s, ',');=0A+ if ( = ss )=0A+ *ss =3D '\0';=0A+=0A+ if ( !strcmp(s, "serr") = )=0A+ {=0A+ cmd_mask =3D PCI_COMMAND_SERR;=0A+ = brctl_mask =3D PCI_BRIDGE_CTL_SERR | PCI_BRIDGE_CTL_DTMR_SERR;=0A+ = }=0A+ else if ( !strcmp(s, "perr") )=0A+ {=0A+ = cmd_mask =3D PCI_COMMAND_PARITY;=0A+ brctl_mask =3D PCI_BRIDGE_C= TL_PARITY;=0A+ }=0A+=0A+ if ( on )=0A+ {=0A+ = command_mask &=3D ~cmd_mask;=0A+ bridge_ctl_mask &=3D = ~brctl_mask;=0A+ }=0A+ else=0A+ {=0A+ = command_mask |=3D cmd_mask;=0A+ bridge_ctl_mask |=3D brctl_mask;= =0A+ }=0A+=0A+ s =3D ss + 1;=0A+ } while ( ss );=0A+}=0A+c= ustom_param("pci", parse_pci_param);=0A+=0A+static void check_pdev(const = struct pci_dev *pdev)=0A+{=0A+#define PCI_STATUS_CHECK \=0A+ (PCI_STATUS= _PARITY | PCI_STATUS_SIG_TARGET_ABORT | \=0A+ PCI_STATUS_REC_TARGET_ABO= RT | PCI_STATUS_REC_MASTER_ABORT | \=0A+ PCI_STATUS_SIG_SYSTEM_ERROR | = PCI_STATUS_DETECTED_PARITY)=0A+ u16 seg =3D pdev->seg;=0A+ u8 bus = =3D pdev->bus;=0A+ u8 dev =3D PCI_SLOT(pdev->devfn);=0A+ u8 func =3D = PCI_FUNC(pdev->devfn);=0A+ u16 val;=0A+=0A+ if ( command_mask )=0A+ = {=0A+ val =3D pci_conf_read16(seg, bus, dev, func, PCI_COMMAND);= =0A+ if ( val & command_mask )=0A+ pci_conf_write16(seg, = bus, dev, func, PCI_COMMAND,=0A+ val & = ~command_mask);=0A+ val =3D pci_conf_read16(seg, bus, dev, func, = PCI_STATUS);=0A+ if ( val & PCI_STATUS_CHECK )=0A+ {=0A+ = printk(XENLOG_INFO "%04x:%02x:%02x.%u status %04x\n",=0A+ = seg, bus, dev, func, val);=0A+ pci_conf_write16(seg, = bus, dev, func, PCI_STATUS, val);=0A+ }=0A+ }=0A+=0A+ switch = ( pci_conf_read8(seg, bus, dev, func, PCI_HEADER_TYPE) & 0x7f )=0A+ = {=0A+ case PCI_HEADER_TYPE_BRIDGE:=0A+ if ( !bridge_ctl_mask = )=0A+ break;=0A+ val =3D pci_conf_read16(seg, bus, dev, = func, PCI_BRIDGE_CONTROL);=0A+ if ( val & bridge_ctl_mask )=0A+ = pci_conf_write16(seg, bus, dev, func, PCI_BRIDGE_CONTROL,=0A+ = val & ~bridge_ctl_mask);=0A+ val =3D = pci_conf_read16(seg, bus, dev, func, PCI_SEC_STATUS);=0A+ if ( val = & PCI_STATUS_CHECK )=0A+ {=0A+ printk(XENLOG_INFO = "%04x:%02x:%02x.%u secondary status %04x\n",=0A+ seg, = bus, dev, func, val);=0A+ pci_conf_write16(seg, bus, dev, func, = PCI_SEC_STATUS, val);=0A+ }=0A+ break;=0A+=0A+ case = PCI_HEADER_TYPE_CARDBUS:=0A+ /* TODO */=0A+ break;=0A+ = }=0A+#undef PCI_STATUS_CHECK=0A+}=0A+=0A static struct pci_dev *alloc_pdev(= struct pci_seg *pseg, u8 bus, u8 devfn)=0A {=0A struct pci_dev = *pdev;=0A@@ -252,6 +358,8 @@ static struct pci_dev *alloc_pdev(struct=0A = break;=0A }=0A =0A+ check_pdev(pdev);=0A+=0A return = pdev;=0A }=0A =0A@@ -566,6 +674,8 @@ int pci_add_device(u16 seg, u8 bus, = u8 d=0A seg, bus, slot, func, ctrl);=0A }=0A =0A+ = check_pdev(pdev);=0A+=0A ret =3D 0;=0A if ( !pdev->domain )=0A = {=0A--- a/xen/include/xen/pci_regs.h=0A+++ b/xen/include/xen/pci_regs.h=0A= @@ -125,7 +125,7 @@=0A #define PCI_IO_RANGE_TYPE_16 0x00=0A #define = PCI_IO_RANGE_TYPE_32 0x01=0A #define PCI_IO_RANGE_MASK = (~0x0fUL)=0A-#define PCI_SEC_STATUS 0x1e /* Secondary = status register, only bit 14 used */=0A+#define PCI_SEC_STATUS = 0x1e /* Secondary status register */=0A #define PCI_MEMORY_BASE = 0x20 /* Memory range behind */=0A #define PCI_MEMORY_LIMIT 0x22=0A = #define PCI_MEMORY_RANGE_TYPE_MASK 0x0fUL=0A@@ -152,6 +152,7 @@=0A = #define PCI_BRIDGE_CTL_MASTER_ABORT 0x20 /* Report master aborts = */=0A #define PCI_BRIDGE_CTL_BUS_RESET 0x40 /* Secondary bus reset = */=0A #define PCI_BRIDGE_CTL_FAST_BACK 0x80 /* Fast Back2Back enabled = on secondary interface */=0A+#define PCI_BRIDGE_CTL_DTMR_SERR 0x800 /* = SERR upon discard timer expiry */=0A =0A /* Header type 2 (CardBus = bridges) */=0A #define PCI_CB_CAPABILITY_LIST 0x14=0A --=__Part8FBDECA5.1__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__Part8FBDECA5.1__=--