From: "Jan Beulich" Subject: [PATCH 3/4] x86/MSI-X: reduce fiddling with control register during restore Date: Tue, 10 Mar 2015 16:29:04 +0000 Message-ID: <54FF29E0020000780006835D@mail.emea.novell.com> References: <54FF26F002000078000682F7@mail.emea.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__Part182DBEC0.1__=" Return-path: Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1YVN1p-0007SZ-6J for xen-devel@lists.xenproject.org; Tue, 10 Mar 2015 16:29:09 +0000 In-Reply-To: <54FF26F002000078000682F7@mail.emea.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: Andrew Cooper , Keir Fraser 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. --=__Part182DBEC0.1__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Rather than disabling and enabling MSI-X once per vector, do it just once per device. Signed-off-by: Jan Beulich --- a/xen/arch/x86/msi.c +++ b/xen/arch/x86/msi.c @@ -1218,6 +1218,9 @@ int pci_restore_msi_state(struct pci_dev struct msi_desc *entry, *tmp; struct irq_desc *desc; struct msi_msg msg; + u8 slot =3D PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn); + unsigned int type =3D 0, pos =3D 0; + u16 control =3D 0; =20 ASSERT(spin_is_locked(&pcidevs_lock)); =20 @@ -1234,8 +1237,6 @@ int pci_restore_msi_state(struct pci_dev list_for_each_entry_safe( entry, tmp, &pdev->msi_list, list ) { unsigned int i =3D 0, nr =3D 1; - u16 control =3D 0; - u8 slot =3D PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn);= =20 irq =3D entry->irq; desc =3D &irq_desc[irq]; @@ -1252,31 +1253,38 @@ int pci_restore_msi_state(struct pci_dev pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn), PCI_FUNC(pdev->devfn), i); spin_unlock_irqrestore(&desc->lock, flags); + if ( type =3D=3D PCI_CAP_ID_MSIX ) + pci_conf_write16(pdev->seg, pdev->bus, slot, func, + msix_control_reg(pos), + control & ~PCI_MSIX_FLAGS_ENABLE); return -EINVAL; } =20 + ASSERT(!type || type =3D=3D entry->msi_attrib.type); + pos =3D entry->msi_attrib.pos; if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSI ) { msi_set_enable(pdev, 0); nr =3D entry->msi.nvec; } - else if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSIX ) + else if ( !type && entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSIX = ) { control =3D pci_conf_read16(pdev->seg, pdev->bus, slot, func, - msix_control_reg(entry->msi_attrib.p= os)); + msix_control_reg(pos)); pci_conf_write16(pdev->seg, pdev->bus, slot, func, - msix_control_reg(entry->msi_attrib.pos), + msix_control_reg(pos), control | (PCI_MSIX_FLAGS_ENABLE | PCI_MSIX_FLAGS_MASKALL)); if ( unlikely(!memory_decoded(pdev)) ) { spin_unlock_irqrestore(&desc->lock, flags); pci_conf_write16(pdev->seg, pdev->bus, slot, func, - msix_control_reg(entry->msi_attrib.pos), + msix_control_reg(pos), control & ~PCI_MSIX_FLAGS_ENABLE); return -ENXIO; } } + type =3D entry->msi_attrib.type; =20 msg =3D entry->msg; write_msi_msg(entry, &msg); @@ -1299,9 +1307,9 @@ int pci_restore_msi_state(struct pci_dev =20 spin_unlock_irqrestore(&desc->lock, flags); =20 - if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSI ) + if ( type =3D=3D PCI_CAP_ID_MSI ) { - unsigned int cpos =3D msi_control_reg(entry->msi_attrib.pos); + unsigned int cpos =3D msi_control_reg(pos); =20 control =3D pci_conf_read16(pdev->seg, pdev->bus, slot, func, = cpos) & ~PCI_MSI_FLAGS_QSIZE; @@ -1311,12 +1319,13 @@ int pci_restore_msi_state(struct pci_dev =20 msi_set_enable(pdev, 1); } - else if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSIX ) - pci_conf_write16(pdev->seg, pdev->bus, slot, func, - msix_control_reg(entry->msi_attrib.pos), - control | PCI_MSIX_FLAGS_ENABLE); } =20 + if ( type =3D=3D PCI_CAP_ID_MSIX ) + pci_conf_write16(pdev->seg, pdev->bus, slot, func, + msix_control_reg(pos), + control | PCI_MSIX_FLAGS_ENABLE); + return 0; } =20 --=__Part182DBEC0.1__= Content-Type: text/plain; name="x86-MSI-X-restore-once.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-MSI-X-restore-once.patch" x86/MSI-X: reduce fiddling with control register during restore=0A=0ARather= than disabling and enabling MSI-X once per vector, do it just=0Aonce per = device.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- = a/xen/arch/x86/msi.c=0A+++ b/xen/arch/x86/msi.c=0A@@ -1218,6 +1218,9 @@ = int pci_restore_msi_state(struct pci_dev=0A struct msi_desc *entry, = *tmp;=0A struct irq_desc *desc;=0A struct msi_msg msg;=0A+ u8 = slot =3D PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn);=0A+ = unsigned int type =3D 0, pos =3D 0;=0A+ u16 control =3D 0;=0A =0A = ASSERT(spin_is_locked(&pcidevs_lock));=0A =0A@@ -1234,8 +1237,6 @@ int = pci_restore_msi_state(struct pci_dev=0A list_for_each_entry_safe( = entry, tmp, &pdev->msi_list, list )=0A {=0A unsigned int i =3D = 0, nr =3D 1;=0A- u16 control =3D 0;=0A- u8 slot =3D = PCI_SLOT(pdev->devfn), func =3D PCI_FUNC(pdev->devfn);=0A =0A irq = =3D entry->irq;=0A desc =3D &irq_desc[irq];=0A@@ -1252,31 +1253,38 = @@ int pci_restore_msi_state(struct pci_dev=0A = pdev->seg, pdev->bus, PCI_SLOT(pdev->devfn),=0A = PCI_FUNC(pdev->devfn), i);=0A spin_unlock_irqrestore(&desc->loc= k, flags);=0A+ if ( type =3D=3D PCI_CAP_ID_MSIX )=0A+ = pci_conf_write16(pdev->seg, pdev->bus, slot, func,=0A+ = msix_control_reg(pos),=0A+ = control & ~PCI_MSIX_FLAGS_ENABLE);=0A return -EINVAL;=0A = }=0A =0A+ ASSERT(!type || type =3D=3D entry->msi_attrib.type);=0A= + pos =3D entry->msi_attrib.pos;=0A if ( entry->msi_attrib.t= ype =3D=3D PCI_CAP_ID_MSI )=0A {=0A msi_set_enable(pdev= , 0);=0A nr =3D entry->msi.nvec;=0A }=0A- else = if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSIX )=0A+ else if ( = !type && entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSIX )=0A {=0A = control =3D pci_conf_read16(pdev->seg, pdev->bus, slot, = func,=0A- msix_control_reg(entry->msi_= attrib.pos));=0A+ msix_control_reg(pos= ));=0A pci_conf_write16(pdev->seg, pdev->bus, slot, func,=0A- = msix_control_reg(entry->msi_attrib.pos),=0A+ = msix_control_reg(pos),=0A = control | (PCI_MSIX_FLAGS_ENABLE |=0A = PCI_MSIX_FLAGS_MASKALL));=0A if ( unlikely(!memory_deco= ded(pdev)) )=0A {=0A spin_unlock_irqrestore(&de= sc->lock, flags);=0A pci_conf_write16(pdev->seg, pdev->bus,= slot, func,=0A- msix_control_reg(entry->ms= i_attrib.pos),=0A+ msix_control_reg(pos),= =0A control & ~PCI_MSIX_FLAGS_ENABLE);=0A = return -ENXIO;=0A }=0A }=0A+ = type =3D entry->msi_attrib.type;=0A =0A msg =3D entry->msg;=0A = write_msi_msg(entry, &msg);=0A@@ -1299,9 +1307,9 @@ int pci_restore_msi= _state(struct pci_dev=0A =0A spin_unlock_irqrestore(&desc->lock, = flags);=0A =0A- if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSI = )=0A+ if ( type =3D=3D PCI_CAP_ID_MSI )=0A {=0A- = unsigned int cpos =3D msi_control_reg(entry->msi_attrib.pos);=0A+ = unsigned int cpos =3D msi_control_reg(pos);=0A =0A control = =3D pci_conf_read16(pdev->seg, pdev->bus, slot, func, cpos) &=0A = ~PCI_MSI_FLAGS_QSIZE;=0A@@ -1311,12 +1319,13 @@ int pci_restore= _msi_state(struct pci_dev=0A =0A msi_set_enable(pdev, 1);=0A = }=0A- else if ( entry->msi_attrib.type =3D=3D PCI_CAP_ID_MSIX = )=0A- pci_conf_write16(pdev->seg, pdev->bus, slot, func,=0A- = msix_control_reg(entry->msi_attrib.pos),=0A- = control | PCI_MSIX_FLAGS_ENABLE);=0A }=0A =0A+ = if ( type =3D=3D PCI_CAP_ID_MSIX )=0A+ pci_conf_write16(pdev->seg,= pdev->bus, slot, func,=0A+ msix_control_reg(pos),= =0A+ control | PCI_MSIX_FLAGS_ENABLE);=0A+=0A = return 0;=0A }=0A =0A --=__Part182DBEC0.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 --=__Part182DBEC0.1__=--