All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/5] PCI: iproc: Cleanups
@ 2016-10-12 12:53 Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 1/5] PCI: iproc: Add local struct device pointers Bjorn Helgaas
                   ` (5 more replies)
  0 siblings, 6 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 12:53 UTC (permalink / raw)
  To: Jon Mason, Ray Jui, Scott Branden; +Cc: linux-pci, bcm-kernel-feedback-list

  - Add local "dev" pointers to reduce repetition of things like
    "&pdev->dev".

  - Tidy up drvdata usage.

  - Remove some null pointer checking after adding corresponding checking
    elsewhere.

  - Hard-code the PCIe capability offset instead of searching for it.  This
    removes a little bit of dependency on struct pci_bus, with an eye
    toward moving the link maintenance before enumeration.

Changes from v1:
  I dropped the following patches because they were a lot of churn for
  questionable benefit:
    PCI: iproc: Rename accessors
    PCI: iproc: Name private struct pointer "iproc" consistently

---

Bjorn Helgaas (5):
      PCI: iproc: Add local struct device pointers
      PCI: iproc: Set drvdata at end of probe function
      PCI: iproc: Validate CSR base in BCMA setup code
      PCI: iproc: Remove redundant null pointer checking
      PCI: iproc: Hard-code PCIe capability offset instead of searching


 drivers/pci/host/pcie-iproc-bcma.c     |   14 ++++++---
 drivers/pci/host/pcie-iproc-platform.c |   27 +++++++++--------
 drivers/pci/host/pcie-iproc.c          |   52 ++++++++++++++++----------------
 3 files changed, 50 insertions(+), 43 deletions(-)

^ permalink raw reply	[flat|nested] 10+ messages in thread

* [PATCH v2 1/5] PCI: iproc: Add local struct device pointers
  2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
@ 2016-10-12 12:53 ` Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 2/5] PCI: iproc: Set drvdata at end of probe function Bjorn Helgaas
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 12:53 UTC (permalink / raw)
  To: Jon Mason, Ray Jui, Scott Branden; +Cc: linux-pci, bcm-kernel-feedback-list

Use a local "struct device *dev" for brevity and consistency with other
drivers.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pcie-iproc-bcma.c     |    7 +++---
 drivers/pci/host/pcie-iproc-platform.c |   25 +++++++++++----------
 drivers/pci/host/pcie-iproc.c          |   38 ++++++++++++++++++--------------
 3 files changed, 38 insertions(+), 32 deletions(-)

diff --git a/drivers/pci/host/pcie-iproc-bcma.c b/drivers/pci/host/pcie-iproc-bcma.c
index 0d7bee4..94d1101 100644
--- a/drivers/pci/host/pcie-iproc-bcma.c
+++ b/drivers/pci/host/pcie-iproc-bcma.c
@@ -42,16 +42,17 @@ static int iproc_pcie_bcma_map_irq(const struct pci_dev *dev, u8 slot, u8 pin)
 
 static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 {
+	struct device *dev = &bdev->dev;
 	struct iproc_pcie *pcie;
 	LIST_HEAD(res);
 	struct resource res_mem;
 	int ret;
 
-	pcie = devm_kzalloc(&bdev->dev, sizeof(*pcie), GFP_KERNEL);
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
 	if (!pcie)
 		return -ENOMEM;
 
-	pcie->dev = &bdev->dev;
+	pcie->dev = dev;
 	bcma_set_drvdata(bdev, pcie);
 
 	pcie->base = bdev->io_addr;
@@ -67,7 +68,7 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 
 	ret = iproc_pcie_setup(pcie, &res);
 	if (ret)
-		dev_err(pcie->dev, "PCIe controller setup failed\n");
+		dev_err(dev, "PCIe controller setup failed\n");
 
 	pci_free_resource_list(&res);
 
diff --git a/drivers/pci/host/pcie-iproc-platform.c b/drivers/pci/host/pcie-iproc-platform.c
index 1738c52..6030dc1 100644
--- a/drivers/pci/host/pcie-iproc-platform.c
+++ b/drivers/pci/host/pcie-iproc-platform.c
@@ -40,35 +40,36 @@ MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);
 
 static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 {
+	struct device *dev = &pdev->dev;
 	const struct of_device_id *of_id;
 	struct iproc_pcie *pcie;
-	struct device_node *np = pdev->dev.of_node;
+	struct device_node *np = dev->of_node;
 	struct resource reg;
 	resource_size_t iobase = 0;
 	LIST_HEAD(res);
 	int ret;
 
-	of_id = of_match_device(iproc_pcie_of_match_table, &pdev->dev);
+	of_id = of_match_device(iproc_pcie_of_match_table, dev);
 	if (!of_id)
 		return -EINVAL;
 
-	pcie = devm_kzalloc(&pdev->dev, sizeof(struct iproc_pcie), GFP_KERNEL);
+	pcie = devm_kzalloc(dev, sizeof(*pcie), GFP_KERNEL);
 	if (!pcie)
 		return -ENOMEM;
 
-	pcie->dev = &pdev->dev;
+	pcie->dev = dev;
 	pcie->type = (enum iproc_pcie_type)of_id->data;
 	platform_set_drvdata(pdev, pcie);
 
 	ret = of_address_to_resource(np, 0, &reg);
 	if (ret < 0) {
-		dev_err(pcie->dev, "unable to obtain controller resources\n");
+		dev_err(dev, "unable to obtain controller resources\n");
 		return ret;
 	}
 
-	pcie->base = devm_ioremap(pcie->dev, reg.start, resource_size(&reg));
+	pcie->base = devm_ioremap(dev, reg.start, resource_size(&reg));
 	if (!pcie->base) {
-		dev_err(pcie->dev, "unable to map controller registers\n");
+		dev_err(dev, "unable to map controller registers\n");
 		return -ENOMEM;
 	}
 	pcie->base_addr = reg.start;
@@ -79,7 +80,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 		ret = of_property_read_u32(np, "brcm,pcie-ob-axi-offset",
 					   &val);
 		if (ret) {
-			dev_err(pcie->dev,
+			dev_err(dev,
 				"missing brcm,pcie-ob-axi-offset property\n");
 			return ret;
 		}
@@ -88,7 +89,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 		ret = of_property_read_u32(np, "brcm,pcie-ob-window-size",
 					   &val);
 		if (ret) {
-			dev_err(pcie->dev,
+			dev_err(dev,
 				"missing brcm,pcie-ob-window-size property\n");
 			return ret;
 		}
@@ -101,7 +102,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 	}
 
 	/* PHY use is optional */
-	pcie->phy = devm_phy_get(&pdev->dev, "pcie-phy");
+	pcie->phy = devm_phy_get(dev, "pcie-phy");
 	if (IS_ERR(pcie->phy)) {
 		if (PTR_ERR(pcie->phy) == -EPROBE_DEFER)
 			return -EPROBE_DEFER;
@@ -110,7 +111,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 
 	ret = of_pci_get_host_bridge_resources(np, 0, 0xff, &res, &iobase);
 	if (ret) {
-		dev_err(pcie->dev,
+		dev_err(dev,
 			"unable to get PCI host bridge resources\n");
 		return ret;
 	}
@@ -119,7 +120,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 
 	ret = iproc_pcie_setup(pcie, &res);
 	if (ret)
-		dev_err(pcie->dev, "PCIe controller setup failed\n");
+		dev_err(dev, "PCIe controller setup failed\n");
 
 	pci_free_resource_list(&res);
 
diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index e167b2f..c41d6bd 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -258,6 +258,7 @@ static void iproc_pcie_reset(struct iproc_pcie *pcie)
 
 static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
 {
+	struct device *dev = pcie->dev;
 	u8 hdr_type;
 	u32 link_ctrl, class, val;
 	u16 pos, link_status;
@@ -272,14 +273,14 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
 
 	val = iproc_pcie_read_reg(pcie, IPROC_PCIE_LINK_STATUS);
 	if (!(val & PCIE_PHYLINKUP) || !(val & PCIE_DL_ACTIVE)) {
-		dev_err(pcie->dev, "PHY or data link is INACTIVE!\n");
+		dev_err(dev, "PHY or data link is INACTIVE!\n");
 		return -ENODEV;
 	}
 
 	/* make sure we are not in EP mode */
 	pci_bus_read_config_byte(bus, 0, PCI_HEADER_TYPE, &hdr_type);
 	if ((hdr_type & 0x7f) != PCI_HEADER_TYPE_BRIDGE) {
-		dev_err(pcie->dev, "in EP mode, hdr=%#02x\n", hdr_type);
+		dev_err(dev, "in EP mode, hdr=%#02x\n", hdr_type);
 		return -EFAULT;
 	}
 
@@ -324,7 +325,7 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
 		}
 	}
 
-	dev_info(pcie->dev, "link: %s\n", link_is_active ? "UP" : "DOWN");
+	dev_info(dev, "link: %s\n", link_is_active ? "UP" : "DOWN");
 
 	return link_is_active ? 0 : -ENODEV;
 }
@@ -349,12 +350,13 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
 			       u64 pci_addr, resource_size_t size)
 {
 	struct iproc_pcie_ob *ob = &pcie->ob;
+	struct device *dev = pcie->dev;
 	unsigned i;
 	u64 max_size = (u64)ob->window_size * MAX_NUM_OB_WINDOWS;
 	u64 remainder;
 
 	if (size > max_size) {
-		dev_err(pcie->dev,
+		dev_err(dev,
 			"res size %pap exceeds max supported size 0x%llx\n",
 			&size, max_size);
 		return -EINVAL;
@@ -362,15 +364,14 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
 
 	div64_u64_rem(size, ob->window_size, &remainder);
 	if (remainder) {
-		dev_err(pcie->dev,
+		dev_err(dev,
 			"res size %pap needs to be multiple of window size %pap\n",
 			&size, &ob->window_size);
 		return -EINVAL;
 	}
 
 	if (axi_addr < ob->axi_offset) {
-		dev_err(pcie->dev,
-			"axi address %pap less than offset %pap\n",
+		dev_err(dev, "axi address %pap less than offset %pap\n",
 			&axi_addr, &ob->axi_offset);
 		return -EINVAL;
 	}
@@ -406,6 +407,7 @@ static int iproc_pcie_setup_ob(struct iproc_pcie *pcie, u64 axi_addr,
 static int iproc_pcie_map_ranges(struct iproc_pcie *pcie,
 				 struct list_head *resources)
 {
+	struct device *dev = pcie->dev;
 	struct resource_entry *window;
 	int ret;
 
@@ -425,7 +427,7 @@ static int iproc_pcie_map_ranges(struct iproc_pcie *pcie,
 				return ret;
 			break;
 		default:
-			dev_err(pcie->dev, "invalid resource %pR\n", res);
+			dev_err(dev, "invalid resource %pR\n", res);
 			return -EINVAL;
 		}
 	}
@@ -455,6 +457,7 @@ static void iproc_pcie_msi_disable(struct iproc_pcie *pcie)
 
 int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 {
+	struct device *dev;
 	int ret;
 	void *sysdata;
 	struct pci_bus *bus;
@@ -462,19 +465,20 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 	if (!pcie || !pcie->dev || !pcie->base)
 		return -EINVAL;
 
-	ret = devm_request_pci_bus_resources(pcie->dev, res);
+	dev = pcie->dev;
+	ret = devm_request_pci_bus_resources(dev, res);
 	if (ret)
 		return ret;
 
 	ret = phy_init(pcie->phy);
 	if (ret) {
-		dev_err(pcie->dev, "unable to initialize PCIe PHY\n");
+		dev_err(dev, "unable to initialize PCIe PHY\n");
 		return ret;
 	}
 
 	ret = phy_power_on(pcie->phy);
 	if (ret) {
-		dev_err(pcie->dev, "unable to power on PCIe PHY\n");
+		dev_err(dev, "unable to power on PCIe PHY\n");
 		goto err_exit_phy;
 	}
 
@@ -486,7 +490,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 		pcie->reg_offsets = iproc_pcie_reg_paxc;
 		break;
 	default:
-		dev_err(pcie->dev, "incompatible iProc PCIe interface\n");
+		dev_err(dev, "incompatible iProc PCIe interface\n");
 		ret = -EINVAL;
 		goto err_power_off_phy;
 	}
@@ -496,7 +500,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 	if (pcie->need_ob_cfg) {
 		ret = iproc_pcie_map_ranges(pcie, res);
 		if (ret) {
-			dev_err(pcie->dev, "map failed\n");
+			dev_err(dev, "map failed\n");
 			goto err_power_off_phy;
 		}
 	}
@@ -508,9 +512,9 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 	sysdata = pcie;
 #endif
 
-	bus = pci_create_root_bus(pcie->dev, 0, &iproc_pcie_ops, sysdata, res);
+	bus = pci_create_root_bus(dev, 0, &iproc_pcie_ops, sysdata, res);
 	if (!bus) {
-		dev_err(pcie->dev, "unable to create PCI root bus\n");
+		dev_err(dev, "unable to create PCI root bus\n");
 		ret = -ENOMEM;
 		goto err_power_off_phy;
 	}
@@ -518,7 +522,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 
 	ret = iproc_pcie_check_link(pcie, bus);
 	if (ret) {
-		dev_err(pcie->dev, "no PCIe EP device detected\n");
+		dev_err(dev, "no PCIe EP device detected\n");
 		goto err_rm_root_bus;
 	}
 
@@ -526,7 +530,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 
 	if (IS_ENABLED(CONFIG_PCI_MSI))
 		if (iproc_pcie_msi_enable(pcie))
-			dev_info(pcie->dev, "not using iProc MSI\n");
+			dev_info(dev, "not using iProc MSI\n");
 
 	pci_scan_child_bus(bus);
 	pci_assign_unassigned_bus_resources(bus);


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 2/5] PCI: iproc: Set drvdata at end of probe function
  2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 1/5] PCI: iproc: Add local struct device pointers Bjorn Helgaas
@ 2016-10-12 12:53 ` Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 3/5] PCI: iproc: Validate CSR base in BCMA setup code Bjorn Helgaas
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 12:53 UTC (permalink / raw)
  To: Jon Mason, Ray Jui, Scott Branden; +Cc: linux-pci, bcm-kernel-feedback-list

Set the drvdata pointer at the end of probe function for consistency with
other drivers.  We don't need the drvdata until after the probe completes,
and we don't need it at all if the probe fails.  No functional change
intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pcie-iproc-bcma.c     |    2 +-
 drivers/pci/host/pcie-iproc-platform.c |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/pci/host/pcie-iproc-bcma.c b/drivers/pci/host/pcie-iproc-bcma.c
index 94d1101..ec6edaf 100644
--- a/drivers/pci/host/pcie-iproc-bcma.c
+++ b/drivers/pci/host/pcie-iproc-bcma.c
@@ -53,7 +53,6 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 		return -ENOMEM;
 
 	pcie->dev = dev;
-	bcma_set_drvdata(bdev, pcie);
 
 	pcie->base = bdev->io_addr;
 	pcie->base_addr = bdev->addr;
@@ -72,6 +71,7 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 
 	pci_free_resource_list(&res);
 
+	bcma_set_drvdata(bdev, pcie);
 	return ret;
 }
 
diff --git a/drivers/pci/host/pcie-iproc-platform.c b/drivers/pci/host/pcie-iproc-platform.c
index 6030dc1..a3de087 100644
--- a/drivers/pci/host/pcie-iproc-platform.c
+++ b/drivers/pci/host/pcie-iproc-platform.c
@@ -59,7 +59,6 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 
 	pcie->dev = dev;
 	pcie->type = (enum iproc_pcie_type)of_id->data;
-	platform_set_drvdata(pdev, pcie);
 
 	ret = of_address_to_resource(np, 0, &reg);
 	if (ret < 0) {
@@ -124,6 +123,7 @@ static int iproc_pcie_pltfm_probe(struct platform_device *pdev)
 
 	pci_free_resource_list(&res);
 
+	platform_set_drvdata(pdev, pcie);
 	return ret;
 }
 


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 3/5] PCI: iproc: Validate CSR base in BCMA setup code
  2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 1/5] PCI: iproc: Add local struct device pointers Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 2/5] PCI: iproc: Set drvdata at end of probe function Bjorn Helgaas
@ 2016-10-12 12:53 ` Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 4/5] PCI: iproc: Remove redundant null pointer checking Bjorn Helgaas
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 12:53 UTC (permalink / raw)
  To: Jon Mason, Ray Jui, Scott Branden; +Cc: linux-pci, bcm-kernel-feedback-list

Validate iproc_pcie->base for BCMA devices just like we already do for
platform devices in iproc_pcie_pltfm_probe().  No functional change
intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pcie-iproc-bcma.c |    5 +++++
 drivers/pci/host/pcie-iproc.c      |    2 +-
 2 files changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/pci/host/pcie-iproc-bcma.c b/drivers/pci/host/pcie-iproc-bcma.c
index ec6edaf..8ce0890 100644
--- a/drivers/pci/host/pcie-iproc-bcma.c
+++ b/drivers/pci/host/pcie-iproc-bcma.c
@@ -55,6 +55,11 @@ static int iproc_pcie_bcma_probe(struct bcma_device *bdev)
 	pcie->dev = dev;
 
 	pcie->base = bdev->io_addr;
+	if (!pcie->base) {
+		dev_err(dev, "no controller registers\n");
+		return -ENOMEM;
+	}
+
 	pcie->base_addr = bdev->addr;
 
 	res_mem.start = bdev->addr_s[0];
diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index c41d6bd..12a5156 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -462,7 +462,7 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 	void *sysdata;
 	struct pci_bus *bus;
 
-	if (!pcie || !pcie->dev || !pcie->base)
+	if (!pcie || !pcie->dev)
 		return -EINVAL;
 
 	dev = pcie->dev;


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 4/5] PCI: iproc: Remove redundant null pointer checking
  2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
                   ` (2 preceding siblings ...)
  2016-10-12 12:53 ` [PATCH v2 3/5] PCI: iproc: Validate CSR base in BCMA setup code Bjorn Helgaas
@ 2016-10-12 12:53 ` Bjorn Helgaas
  2016-10-12 12:53 ` [PATCH v2 5/5] PCI: iproc: Hard-code PCIe capability offset instead of searching Bjorn Helgaas
  2016-10-12 16:01 ` [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
  5 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 12:53 UTC (permalink / raw)
  To: Jon Mason, Ray Jui, Scott Branden; +Cc: linux-pci, bcm-kernel-feedback-list

The callers never pass a null "pcie" pointer (they check for kzalloc
failure), so we don't need to check here.  The bus driver should never call
the probe function with a null ->dev pointer, so we don't need to check
that either.  No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pcie-iproc.c |    3 ---
 1 file changed, 3 deletions(-)

diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index 12a5156..e9210f6 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -462,9 +462,6 @@ int iproc_pcie_setup(struct iproc_pcie *pcie, struct list_head *res)
 	void *sysdata;
 	struct pci_bus *bus;
 
-	if (!pcie || !pcie->dev)
-		return -EINVAL;
-
 	dev = pcie->dev;
 	ret = devm_request_pci_bus_resources(dev, res);
 	if (ret)


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* [PATCH v2 5/5] PCI: iproc: Hard-code PCIe capability offset instead of searching
  2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
                   ` (3 preceding siblings ...)
  2016-10-12 12:53 ` [PATCH v2 4/5] PCI: iproc: Remove redundant null pointer checking Bjorn Helgaas
@ 2016-10-12 12:53 ` Bjorn Helgaas
  2016-10-12 16:01 ` [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
  5 siblings, 0 replies; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 12:53 UTC (permalink / raw)
  To: Jon Mason, Ray Jui, Scott Branden; +Cc: linux-pci, bcm-kernel-feedback-list

We know where the PCIe capability lives in the host bridge's config space;
in fact, we already hard-coded the offset of the Link Control 2 register.

The hard-coded Link Control 2 offset was 0xdc.  Link Control 2 is at offset
0x30 into the PCIe capability, so the capability itself must be at
0xdc - 0x30 = 0xac.

Hard-code the PCIe capability offset, which means we don't have to search
for it and we can use the standard definitions for registers within the
capability.

No functional change intended.

Signed-off-by: Bjorn Helgaas <bhelgaas@google.com>
---
 drivers/pci/host/pcie-iproc.c |   11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/host/pcie-iproc.c b/drivers/pci/host/pcie-iproc.c
index e9210f6..0b999a9 100644
--- a/drivers/pci/host/pcie-iproc.c
+++ b/drivers/pci/host/pcie-iproc.c
@@ -63,6 +63,8 @@
 #define OARR_SIZE_CFG_SHIFT          1
 #define OARR_SIZE_CFG                BIT(OARR_SIZE_CFG_SHIFT)
 
+#define PCI_EXP_CAP			0xac
+
 #define MAX_NUM_OB_WINDOWS           2
 
 #define IPROC_PCIE_REG_INVALID 0xffff
@@ -261,7 +263,7 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
 	struct device *dev = pcie->dev;
 	u8 hdr_type;
 	u32 link_ctrl, class, val;
-	u16 pos, link_status;
+	u16 pos = PCI_EXP_CAP, link_status;
 	bool link_is_active = false;
 
 	/*
@@ -294,30 +296,27 @@ static int iproc_pcie_check_link(struct iproc_pcie *pcie, struct pci_bus *bus)
 	pci_bus_write_config_dword(bus, 0, PCI_BRIDGE_CTRL_REG_OFFSET, class);
 
 	/* check link status to see if link is active */
-	pos = pci_bus_find_capability(bus, 0, PCI_CAP_ID_EXP);
 	pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA, &link_status);
 	if (link_status & PCI_EXP_LNKSTA_NLW)
 		link_is_active = true;
 
 	if (!link_is_active) {
 		/* try GEN 1 link speed */
-#define PCI_LINK_STATUS_CTRL_2_OFFSET 0x0dc
 #define PCI_TARGET_LINK_SPEED_MASK    0xf
 #define PCI_TARGET_LINK_SPEED_GEN2    0x2
 #define PCI_TARGET_LINK_SPEED_GEN1    0x1
 		pci_bus_read_config_dword(bus, 0,
-					  PCI_LINK_STATUS_CTRL_2_OFFSET,
+					  pos + PCI_EXP_LNKCTL2,
 					  &link_ctrl);
 		if ((link_ctrl & PCI_TARGET_LINK_SPEED_MASK) ==
 		    PCI_TARGET_LINK_SPEED_GEN2) {
 			link_ctrl &= ~PCI_TARGET_LINK_SPEED_MASK;
 			link_ctrl |= PCI_TARGET_LINK_SPEED_GEN1;
 			pci_bus_write_config_dword(bus, 0,
-					   PCI_LINK_STATUS_CTRL_2_OFFSET,
+					   pos + PCI_EXP_LNKCTL2,
 					   link_ctrl);
 			msleep(100);
 
-			pos = pci_bus_find_capability(bus, 0, PCI_CAP_ID_EXP);
 			pci_bus_read_config_word(bus, 0, pos + PCI_EXP_LNKSTA,
 						 &link_status);
 			if (link_status & PCI_EXP_LNKSTA_NLW)


^ permalink raw reply related	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/5] PCI: iproc: Cleanups
  2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
                   ` (4 preceding siblings ...)
  2016-10-12 12:53 ` [PATCH v2 5/5] PCI: iproc: Hard-code PCIe capability offset instead of searching Bjorn Helgaas
@ 2016-10-12 16:01 ` Bjorn Helgaas
  2016-10-12 16:04   ` Ray Jui
  5 siblings, 1 reply; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 16:01 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Jon Mason, Ray Jui, Scott Branden, linux-pci, bcm-kernel-feedback-list

On Wed, Oct 12, 2016 at 07:53:03AM -0500, Bjorn Helgaas wrote:
>   - Add local "dev" pointers to reduce repetition of things like
>     "&pdev->dev".
> 
>   - Tidy up drvdata usage.
> 
>   - Remove some null pointer checking after adding corresponding checking
>     elsewhere.
> 
>   - Hard-code the PCIe capability offset instead of searching for it.  This
>     removes a little bit of dependency on struct pci_bus, with an eye
>     toward moving the link maintenance before enumeration.
> 
> Changes from v1:
>   I dropped the following patches because they were a lot of churn for
>   questionable benefit:
>     PCI: iproc: Rename accessors
>     PCI: iproc: Name private struct pointer "iproc" consistently
> 
> ---
> 
> Bjorn Helgaas (5):
>       PCI: iproc: Add local struct device pointers
>       PCI: iproc: Set drvdata at end of probe function
>       PCI: iproc: Validate CSR base in BCMA setup code
>       PCI: iproc: Remove redundant null pointer checking
>       PCI: iproc: Hard-code PCIe capability offset instead of searching

I applied these to pci/host-iproc for v4.9.  I hope to ask Linus to
pull them tomorrow, so if you see any issues, let me know soon.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/5] PCI: iproc: Cleanups
  2016-10-12 16:01 ` [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
@ 2016-10-12 16:04   ` Ray Jui
  2016-10-12 16:18     ` Bjorn Helgaas
  0 siblings, 1 reply; 10+ messages in thread
From: Ray Jui @ 2016-10-12 16:04 UTC (permalink / raw)
  To: Bjorn Helgaas, Bjorn Helgaas
  Cc: Jon Mason, Ray Jui, Scott Branden, linux-pci, bcm-kernel-feedback-list

Hi Bjorn,

On 10/12/2016 9:01 AM, Bjorn Helgaas wrote:
> On Wed, Oct 12, 2016 at 07:53:03AM -0500, Bjorn Helgaas wrote:
>>   - Add local "dev" pointers to reduce repetition of things like
>>     "&pdev->dev".
>>
>>   - Tidy up drvdata usage.
>>
>>   - Remove some null pointer checking after adding corresponding checking
>>     elsewhere.
>>
>>   - Hard-code the PCIe capability offset instead of searching for it.  This
>>     removes a little bit of dependency on struct pci_bus, with an eye
>>     toward moving the link maintenance before enumeration.
>>
>> Changes from v1:
>>   I dropped the following patches because they were a lot of churn for
>>   questionable benefit:
>>     PCI: iproc: Rename accessors
>>     PCI: iproc: Name private struct pointer "iproc" consistently
>>
>> ---
>>
>> Bjorn Helgaas (5):
>>       PCI: iproc: Add local struct device pointers
>>       PCI: iproc: Set drvdata at end of probe function
>>       PCI: iproc: Validate CSR base in BCMA setup code
>>       PCI: iproc: Remove redundant null pointer checking
>>       PCI: iproc: Hard-code PCIe capability offset instead of searching
>
> I applied these to pci/host-iproc for v4.9.  I hope to ask Linus to
> pull them tomorrow, so if you see any issues, let me know soon.
>

That sounds good. Are these patches in the git repo: 
git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git at branch 
pci/host-iproc?

I plan to sanity test them on various iProc based SoCs.

Thanks,

Ray

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/5] PCI: iproc: Cleanups
  2016-10-12 16:04   ` Ray Jui
@ 2016-10-12 16:18     ` Bjorn Helgaas
  2016-10-17 22:02       ` Ray Jui
  0 siblings, 1 reply; 10+ messages in thread
From: Bjorn Helgaas @ 2016-10-12 16:18 UTC (permalink / raw)
  To: Ray Jui
  Cc: Bjorn Helgaas, Jon Mason, Ray Jui, Scott Branden, linux-pci,
	bcm-kernel-feedback-list

On Wed, Oct 12, 2016 at 09:04:26AM -0700, Ray Jui wrote:
> Hi Bjorn,
> 
> On 10/12/2016 9:01 AM, Bjorn Helgaas wrote:
> >On Wed, Oct 12, 2016 at 07:53:03AM -0500, Bjorn Helgaas wrote:
> >>  - Add local "dev" pointers to reduce repetition of things like
> >>    "&pdev->dev".
> >>
> >>  - Tidy up drvdata usage.
> >>
> >>  - Remove some null pointer checking after adding corresponding checking
> >>    elsewhere.
> >>
> >>  - Hard-code the PCIe capability offset instead of searching for it.  This
> >>    removes a little bit of dependency on struct pci_bus, with an eye
> >>    toward moving the link maintenance before enumeration.
> >>
> >>Changes from v1:
> >>  I dropped the following patches because they were a lot of churn for
> >>  questionable benefit:
> >>    PCI: iproc: Rename accessors
> >>    PCI: iproc: Name private struct pointer "iproc" consistently
> >>
> >>---
> >>
> >>Bjorn Helgaas (5):
> >>      PCI: iproc: Add local struct device pointers
> >>      PCI: iproc: Set drvdata at end of probe function
> >>      PCI: iproc: Validate CSR base in BCMA setup code
> >>      PCI: iproc: Remove redundant null pointer checking
> >>      PCI: iproc: Hard-code PCIe capability offset instead of searching
> >
> >I applied these to pci/host-iproc for v4.9.  I hope to ask Linus to
> >pull them tomorrow, so if you see any issues, let me know soon.
> >
> 
> That sounds good. Are these patches in the git repo:
> git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git at
> branch pci/host-iproc?

They should be there.  I also just merged everything into my "next"
branch.

> I plan to sanity test them on various iProc based SoCs.

Great, thanks!

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: [PATCH v2 0/5] PCI: iproc: Cleanups
  2016-10-12 16:18     ` Bjorn Helgaas
@ 2016-10-17 22:02       ` Ray Jui
  0 siblings, 0 replies; 10+ messages in thread
From: Ray Jui @ 2016-10-17 22:02 UTC (permalink / raw)
  To: Bjorn Helgaas
  Cc: Bjorn Helgaas, Jon Mason, Ray Jui, Scott Branden, linux-pci,
	bcm-kernel-feedback-list

Hi Bjorn,

On 10/12/2016 9:18 AM, Bjorn Helgaas wrote:
> On Wed, Oct 12, 2016 at 09:04:26AM -0700, Ray Jui wrote:
>> Hi Bjorn,
>>
>> On 10/12/2016 9:01 AM, Bjorn Helgaas wrote:
>>> On Wed, Oct 12, 2016 at 07:53:03AM -0500, Bjorn Helgaas wrote:
>>>>  - Add local "dev" pointers to reduce repetition of things like
>>>>    "&pdev->dev".
>>>>
>>>>  - Tidy up drvdata usage.
>>>>
>>>>  - Remove some null pointer checking after adding corresponding checking
>>>>    elsewhere.
>>>>
>>>>  - Hard-code the PCIe capability offset instead of searching for it.  This
>>>>    removes a little bit of dependency on struct pci_bus, with an eye
>>>>    toward moving the link maintenance before enumeration.
>>>>
>>>> Changes from v1:
>>>>  I dropped the following patches because they were a lot of churn for
>>>>  questionable benefit:
>>>>    PCI: iproc: Rename accessors
>>>>    PCI: iproc: Name private struct pointer "iproc" consistently
>>>>
>>>> ---
>>>>
>>>> Bjorn Helgaas (5):
>>>>      PCI: iproc: Add local struct device pointers
>>>>      PCI: iproc: Set drvdata at end of probe function
>>>>      PCI: iproc: Validate CSR base in BCMA setup code
>>>>      PCI: iproc: Remove redundant null pointer checking
>>>>      PCI: iproc: Hard-code PCIe capability offset instead of searching
>>>
>>> I applied these to pci/host-iproc for v4.9.  I hope to ask Linus to
>>> pull them tomorrow, so if you see any issues, let me know soon.
>>>
>>
>> That sounds good. Are these patches in the git repo:
>> git://git.kernel.org/pub/scm/linux/kernel/git/helgaas/pci.git at
>> branch pci/host-iproc?
>
> They should be there.  I also just merged everything into my "next"
> branch.
>
>> I plan to sanity test them on various iProc based SoCs.
>
> Great, thanks!
>

I sanity tested the following patches through v4.9-rc1 on both ARM32 and 
ARM64, iProc based platforms (i.e., Cygnus and NS2):

PCI: iproc: Hard-code PCIe capability offset instead of searching
PCI: iproc: Remove redundant null pointer checking
PCI: iproc: Validate CSR base in BCMA setup code
PCI: iproc: Set drvdata at end of probe function
PCI: iproc: Add local struct device pointers

I plan to refresh my patches on top of v4.9-rc1 and will send them out 
once they are done.

Thanks,

Ray

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2016-10-17 22:02 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-12 12:53 [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
2016-10-12 12:53 ` [PATCH v2 1/5] PCI: iproc: Add local struct device pointers Bjorn Helgaas
2016-10-12 12:53 ` [PATCH v2 2/5] PCI: iproc: Set drvdata at end of probe function Bjorn Helgaas
2016-10-12 12:53 ` [PATCH v2 3/5] PCI: iproc: Validate CSR base in BCMA setup code Bjorn Helgaas
2016-10-12 12:53 ` [PATCH v2 4/5] PCI: iproc: Remove redundant null pointer checking Bjorn Helgaas
2016-10-12 12:53 ` [PATCH v2 5/5] PCI: iproc: Hard-code PCIe capability offset instead of searching Bjorn Helgaas
2016-10-12 16:01 ` [PATCH v2 0/5] PCI: iproc: Cleanups Bjorn Helgaas
2016-10-12 16:04   ` Ray Jui
2016-10-12 16:18     ` Bjorn Helgaas
2016-10-17 22:02       ` Ray Jui

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.