Skip to contentSkip to conversation

drm/amdgpu: improve MSI-X handling (v3)

PATCH In review Alex Deucher 3 participants 3 messages Oct 3, 2019 2 messages not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 drm/amdgpu: improve MSI-X handling (v3)

Check the number of supported vectors and fall back to MSI if we return or error or 0 MSI-X vectors.

v2: only allocate one vector. We can't currently use more than one anyway.

v3: install the irq on vector 0.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +13 -4
index 50771b2757dc..6f3b03f6224f 100644
@@ -245,11 +245,19 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
 	adev->irq.msi_enabled = false;
 
 	if (amdgpu_msi_ok(adev)) {
-		int nvec = pci_alloc_irq_vectors(adev->pdev, 1, pci_msix_vec_count(adev->pdev),
-					PCI_IRQ_MSI | PCI_IRQ_MSIX);
+		int nvec = pci_msix_vec_count(adev->pdev);
+		unsigned int flags;
+
+		if (nvec <= 0) {
+			flags = PCI_IRQ_MSI;
+		} else {
+			flags = PCI_IRQ_MSI | PCI_IRQ_MSIX;
+		}
+		/* we only need one vector */
+		nvec = pci_alloc_irq_vectors(adev->pdev, 1, 1, flags);
 		if (nvec > 0) {
 			adev->irq.msi_enabled = true;
-			dev_dbg(adev->dev, "amdgpu: using MSI.\n");
+			dev_dbg(adev->dev, "amdgpu: using MSI/MSI-X.\n");
 		}
 	}
 
@@ -272,7 +280,8 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
 	INIT_WORK(&adev->irq.ih2_work, amdgpu_irq_handle_ih2);
 
 	adev->irq.installed = true;
-	r = drm_irq_install(adev->ddev, adev->ddev->pdev->irq);
+	/* Use vector 0 for MSI-X */
+	r = drm_irq_install(adev->ddev, pci_irq_vector(adev->pdev, 0));
 	if (r) {
 		adev->irq.installed = false;
 		if (!amdgpu_device_has_dc_support(adev))
Signature · 6 lines
2.20.1

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): 20191003172951.15866-1-alexander.deucher-5C7GfCeVMHo@public.gmane.org

Tested-by
#2 lore raw

Cheers,
Tom

Quoted 55 lines · Alex Deucher

Check the number of supported vectors and fall back to MSI if we return or error or 0 MSI-X vectors.

v2: only allocate one vector. We can't currently use more than one anyway.

v3: install the irq on vector 0.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +13 -5
index 50771b2757dc..6f3b03f6224f 100644
@@ -245,11 +245,19 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
        adev->irq.msi_enabled = false;
 
        if (amdgpu_msi_ok(adev)) {
-               int nvec = pci_alloc_irq_vectors(adev->pdev, 1,
 pci_msix_vec_count(adev->pdev),
-                                       PCI_IRQ_MSI | PCI_IRQ_MSIX);
+               int nvec = pci_msix_vec_count(adev->pdev);
+               unsigned int flags;
+
+               if (nvec <= 0) {
+                       flags = PCI_IRQ_MSI;
+               } else {
+                       flags = PCI_IRQ_MSI | PCI_IRQ_MSIX;
+               }
+               /* we only need one vector */
+               nvec = pci_alloc_irq_vectors(adev->pdev, 1, 1, flags);
                if (nvec > 0) {
                        adev->irq.msi_enabled = true;
-                       dev_dbg(adev->dev, "amdgpu: using MSI.\n");
+                       dev_dbg(adev->dev, "amdgpu: using MSI/MSI-X.\n");
                }
        }
@@ -272,7 +280,8 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
        INIT_WORK(&adev->irq.ih2_work, amdgpu_irq_handle_ih2);
 
        adev->irq.installed = true;
-       r = drm_irq_install(adev->ddev, adev->ddev->pdev->irq);
+       /* Use vector 0 for MSI-X */
+       r = drm_irq_install(adev->ddev, pci_irq_vector(adev->pdev, 0));
        if (r) {
                adev->irq.installed = false;
                if (!amdgpu_device_has_dc_support(adev))
--

2.20.1

Quoted 4 lines

_______________________________________________
amd-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

A message that is not in the archive (sent off-list or not yet received): CAAzXoRKMd2gSrK5GE2Y6UDkbjLifZ5UuAvpTS06eeqB7zJP_Aw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org

Reviewed-by Shaoyun liu Tested-by Tom St Denis
#4 lore raw

Looks good to me .

On 2019-10-03 1:33 p.m., Tom St Denis wrote:

Cheers,
Tom

On Thu, Oct 3, 2019 at 1:30 PM Alex Deucher <[email protected]><mailto:[email protected]> wrote:

Check the number of supported vectors and fall back to MSI if we return or error or 0 MSI-X vectors.

v2: only allocate one vector. We can't currently use more than one anyway.

v3: install the irq on vector 0.

---
 drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)
(quoted diff) +0 -0

b/drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c
index 50771b2757dc..6f3b03f6224f 100644

drivers/gpu/drm/amd/amdgpu/amdgpu_irq.c +0 -1
@@ -245,11 +245,19 @@ int amdgpu_irq_init(struct amdgpu_device *adev)
        adev->irq.msi_enabled = false;
 
        if (amdgpu_msi_ok(adev)) {
-               int nvec = pci_alloc_irq_vectors(adev->pdev, 1,

pci_msix_vec_count(adev->pdev),
- PCI_IRQ_MSI | PCI_IRQ_MSIX);
+ int nvec = pci_msix_vec_count(adev->pdev);
+ unsigned int flags;
+
+ if (nvec <= 0) {
+ flags = PCI_IRQ_MSI;
+ } else {
+ flags = PCI_IRQ_MSI | PCI_IRQ_MSIX;

+               }
+               /* we only need one vector */
+               nvec = pci_alloc_irq_vectors(adev->pdev, 1, 1, flags);
                if (nvec > 0) {
                        adev->irq.msi_enabled = true;
-                       dev_dbg(adev->dev, "amdgpu: using MSI.\n");
+                       dev_dbg(adev->dev, "amdgpu: using MSI/MSI-X.\n");
                }
        }

@@ -272,7 +280,8 @@ int amdgpu_irq_init(struct amdgpu_device *adev)

        INIT_WORK(&adev->irq.ih2_work, amdgpu_irq_handle_ih2);

        adev->irq.installed = true;
-       r = drm_irq_install(adev->ddev, adev->ddev->pdev->irq);
+       /* Use vector 0 for MSI-X */
+       r = drm_irq_install(adev->ddev, pci_irq_vector(adev->pdev, 0));
        if (r) {
                adev->irq.installed = false;
                if (!amdgpu_device_has_dc_support(adev))

--
2.20.1

_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list [email protected]<mailto:[email protected]>
https://lists.freedesktop.org/mailman/listinfo/amd-gfx

_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx