diff mbox

[2/2] RDMA/qedr: Use pci_enable_atomic_ops_to_root

Message ID 1515113100-4718-2-git-send-email-Felix.Kuehling@amd.com (mailing list archive)
State New, archived
Delegated to: Bjorn Helgaas
Headers show

Commit Message

Felix Kuehling Jan. 5, 2018, 12:45 a.m. UTC
Use common helper function pci_enable_atomic_ops_to_root to enable
atomic capability.

CC: Bjorn Helgaas <helgaas@kernel.org>
CC: Ram Amrani <Ram.Amrani@cavium.com>
CC: Doug Ledford <dledford@redhat.com>
Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
---
 drivers/infiniband/hw/qedr/main.c | 59 ++++++---------------------------------
 1 file changed, 8 insertions(+), 51 deletions(-)

Comments

Kalderon, Michal Jan. 10, 2018, 5:55 p.m. UTC | #1
> From: Felix Kuehling [mailto:Felix.Kuehling@amd.com]
> Sent: Friday, January 05, 2018 2:45 AM
>
> Use common helper function pci_enable_atomic_ops_to_root to enable
> atomic capability.
>
> CC: Bjorn Helgaas <helgaas@kernel.org>
> CC: Ram Amrani <Ram.Amrani@cavium.com>
> CC: Doug Ledford <dledford@redhat.com>
> Signed-off-by: Felix Kuehling <Felix.Kuehling@amd.com>
> ---
>  drivers/infiniband/hw/qedr/main.c | 59
> ++++++---------------------------------
>  1 file changed, 8 insertions(+), 51 deletions(-)
>
> diff --git a/drivers/infiniband/hw/qedr/main.c
> b/drivers/infiniband/hw/qedr/main.c
> index 50812b3..b378647 100644
> --- a/drivers/infiniband/hw/qedr/main.c
> +++ b/drivers/infiniband/hw/qedr/main.c
> @@ -430,59 +430,16 @@ static void qedr_remove_sysfiles(struct qedr_dev
> *dev)
>
>  static void qedr_pci_set_atomic(struct qedr_dev *dev, struct pci_dev
> *pdev)  {
> -	struct pci_dev *bridge;
> -	u32 ctl2, cap2;
> -	u16 flags;
> -	int rc;
> -
> -	bridge = pdev->bus->self;
> -	if (!bridge)
> -		goto disable;
> -
> -	/* Check atomic routing support all the way to root complex */
> -	while (bridge->bus->parent) {
> -		rc = pcie_capability_read_word(bridge, PCI_EXP_FLAGS,
&flags);
> -		if (rc || ((flags & PCI_EXP_FLAGS_VERS) < 2))
> -			goto disable;
> -
> -		rc = pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2,
&cap2);
> -		if (rc)
> -			goto disable;
> +	int rc = pci_enable_atomic_ops_to_root(pdev,
> +
PCI_EXP_DEVCAP2_ATOMIC_COMP64);
>
> -		rc = pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2,
> &ctl2);
> -		if (rc)
> -			goto disable;
> -
> -		if (!(cap2 & PCI_EXP_DEVCAP2_ATOMIC_ROUTE) ||
> -		    (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK))
> -			goto disable;
> -		bridge = bridge->bus->parent->self;
> +	if (rc) {
> +		dev->atomic_cap = IB_ATOMIC_NONE;
> +		DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability
disabled\n");
> +	} else {
> +		dev->atomic_cap = IB_ATOMIC_GLOB;
> +		DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability
enabled\n");
>  	}
> -
> -	rc = pcie_capability_read_word(bridge, PCI_EXP_FLAGS, &flags);
> -	if (rc || ((flags & PCI_EXP_FLAGS_VERS) < 2))
> -		goto disable;
> -
> -	rc = pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap2);
> -	if (rc || !(cap2 & PCI_EXP_DEVCAP2_ATOMIC_COMP64))
> -		goto disable;
> -
> -	/* Set atomic operations */
> -	pcie_capability_set_word(pdev, PCI_EXP_DEVCTL2,
> -				 PCI_EXP_DEVCTL2_ATOMIC_REQ);
> -	dev->atomic_cap = IB_ATOMIC_GLOB;
> -
> -	DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability enabled\n");
> -
> -	return;
> -
> -disable:
> -	pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL2,
> -				   PCI_EXP_DEVCTL2_ATOMIC_REQ);
> -	dev->atomic_cap = IB_ATOMIC_NONE;
> -
> -	DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability disabled\n");
> -
>  }
>
>  static const struct qed_rdma_ops *qed_ops;
> --
> 2.7.4

Thanks,

Acked-by: Michal Kalderon <michal.kalderon@cavium.com>
diff mbox

Patch

diff --git a/drivers/infiniband/hw/qedr/main.c b/drivers/infiniband/hw/qedr/main.c
index 50812b3..b378647 100644
--- a/drivers/infiniband/hw/qedr/main.c
+++ b/drivers/infiniband/hw/qedr/main.c
@@ -430,59 +430,16 @@  static void qedr_remove_sysfiles(struct qedr_dev *dev)
 
 static void qedr_pci_set_atomic(struct qedr_dev *dev, struct pci_dev *pdev)
 {
-	struct pci_dev *bridge;
-	u32 ctl2, cap2;
-	u16 flags;
-	int rc;
-
-	bridge = pdev->bus->self;
-	if (!bridge)
-		goto disable;
-
-	/* Check atomic routing support all the way to root complex */
-	while (bridge->bus->parent) {
-		rc = pcie_capability_read_word(bridge, PCI_EXP_FLAGS, &flags);
-		if (rc || ((flags & PCI_EXP_FLAGS_VERS) < 2))
-			goto disable;
-
-		rc = pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap2);
-		if (rc)
-			goto disable;
+	int rc = pci_enable_atomic_ops_to_root(pdev,
+					       PCI_EXP_DEVCAP2_ATOMIC_COMP64);
 
-		rc = pcie_capability_read_dword(bridge, PCI_EXP_DEVCTL2, &ctl2);
-		if (rc)
-			goto disable;
-
-		if (!(cap2 & PCI_EXP_DEVCAP2_ATOMIC_ROUTE) ||
-		    (ctl2 & PCI_EXP_DEVCTL2_ATOMIC_EGRESS_BLOCK))
-			goto disable;
-		bridge = bridge->bus->parent->self;
+	if (rc) {
+		dev->atomic_cap = IB_ATOMIC_NONE;
+		DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability disabled\n");
+	} else {
+		dev->atomic_cap = IB_ATOMIC_GLOB;
+		DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability enabled\n");
 	}
-
-	rc = pcie_capability_read_word(bridge, PCI_EXP_FLAGS, &flags);
-	if (rc || ((flags & PCI_EXP_FLAGS_VERS) < 2))
-		goto disable;
-
-	rc = pcie_capability_read_dword(bridge, PCI_EXP_DEVCAP2, &cap2);
-	if (rc || !(cap2 & PCI_EXP_DEVCAP2_ATOMIC_COMP64))
-		goto disable;
-
-	/* Set atomic operations */
-	pcie_capability_set_word(pdev, PCI_EXP_DEVCTL2,
-				 PCI_EXP_DEVCTL2_ATOMIC_REQ);
-	dev->atomic_cap = IB_ATOMIC_GLOB;
-
-	DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability enabled\n");
-
-	return;
-
-disable:
-	pcie_capability_clear_word(pdev, PCI_EXP_DEVCTL2,
-				   PCI_EXP_DEVCTL2_ATOMIC_REQ);
-	dev->atomic_cap = IB_ATOMIC_NONE;
-
-	DP_DEBUG(dev, QEDR_MSG_INIT, "Atomic capability disabled\n");
-
 }
 
 static const struct qed_rdma_ops *qed_ops;