Skip to contentSkip to conversation

Improve Synopsys DesignWare Root Complex driver code

PATCH Applied Gustavo Pimentel 2 participants 10 messages Jan 31, 2019 – Feb 1, 2019

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

v2 cover Improve Synopsys DesignWare Root Complex driver code

This patch series aims to improve Synopsys DesignWare Root Complex driver code by:
- removing unnecessary header files
- enforcing variable naming coherency among similar functions
- simplifing code readability of mask/unmask function operations
- replacing bit rotation operation (1 << bit) by BIT(bit)

No functional changes are intended.

All patches are independent so they can be easily analyzed and accepted or discarded.

This patches organization also allows to easily merge (squash) some patches, if desired.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

Gustavo Pimentel (8):
PCI: dwc: Remove unnecessary header include (of_gpio.h)
PCI: dwc: Remove unnecessary header include (signal.h)
PCI: dwc: Rename variable name from data to d on
dw_pci_bottom_mask/unmask()
PCI: dwc: Rename variable name from data to d on

    dw_pci_setup_msi_msg()

PCI: dwc: Rename variable name from data to d on
dw_pci_msi_set_affinity()
PCI: dwc: Rename variable name from data to d on
dw_pcie_irq_domain_free()
PCI: dwc: Improve code readability and simplifies mask/unmask
operations
PCI: dwc: Replace bit rotation operation (1 << bit) by BIT(bit)

 drivers/pci/controller/dwc/pcie-designware-host.c | 52 +++++++++++------------
 drivers/pci/controller/dwc/pcie-designware-plat.c |  2 -
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 3 files changed, 27 insertions(+), 29 deletions(-)
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/8 PCI: dwc: Remove unnecessary header include (of_gpio.h)

Remove unnecessary header include (of_gpio.h) since it doesn't provide any needed symbols.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-plat.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-plat.c +0 -1
index 99ad471..e889512 100644
@@ -13,7 +13,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/of_device.h>
-#include <linux/of_gpio.h>
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/resource.h>
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/8 PCI: dwc: Remove unnecessary header include (signal.h)

In reply to Gustavo Pimentel

Remove unnecessary header include (signal.h) since it doesn't provide any needed symbols.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>
---
 drivers/pci/controller/dwc/pcie-designware-plat.c | 1 -
 1 file changed, 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-plat.c +0 -1
index e889512..4272c4c 100644
@@ -16,7 +16,6 @@
 #include <linux/pci.h>
 #include <linux/platform_device.h>
 #include <linux/resource.h>
-#include <linux/signal.h>
 #include <linux/types.h>
 #include <linux/regmap.h>
 
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/8 PCI: dwc: Rename variable name from data to d on dw_pci_bottom_mask/unmask()

In reply to Gustavo Pimentel

Rename variable from data to d to maintain consistency between driver functions, such as dw_msi_mask_irq() and dw_msi_unmask_irq().

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

---
Changes v1 -> v2:
- Fix description terminology

 drivers/pci/controller/dwc/pcie-designware-host.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +10 -10
index 721d60a..36e284c 100644
@@ -149,20 +149,20 @@ static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
 	return -EINVAL;
 }
 
-static void dw_pci_bottom_mask(struct irq_data *data)
+static void dw_pci_bottom_mask(struct irq_data *d)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned int res, bit, ctrl;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	if (pp->ops->msi_clear_irq) {
-		pp->ops->msi_clear_irq(pp, data->hwirq);
+		pp->ops->msi_clear_irq(pp, d->hwirq);
 	} else {
-		ctrl = data->hwirq / MAX_MSI_IRQS_PER_CTRL;
+		ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
-		bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
+		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
 		pp->irq_status[ctrl] &= ~(1 << bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
@@ -172,20 +172,20 @@ static void dw_pci_bottom_mask(struct irq_data *data)
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
 }
 
-static void dw_pci_bottom_unmask(struct irq_data *data)
+static void dw_pci_bottom_unmask(struct irq_data *d)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned int res, bit, ctrl;
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
 	if (pp->ops->msi_set_irq) {
-		pp->ops->msi_set_irq(pp, data->hwirq);
+		pp->ops->msi_set_irq(pp, d->hwirq);
 	} else {
-		ctrl = data->hwirq / MAX_MSI_IRQS_PER_CTRL;
+		ctrl = d->hwirq / MAX_MSI_IRQS_PER_CTRL;
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
-		bit = data->hwirq % MAX_MSI_IRQS_PER_CTRL;
+		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
 		pp->irq_status[ctrl] |= 1 << bit;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 4/8 PCI: dwc: Rename variable name from data to d on dw_pci_setup_msi_msg()

In reply to Gustavo Pimentel

Rename variable from data to d to maintain consistency between driver functions, such as dw_pci_setup_msi_msg().

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

---
Changes v1 -> v2:
- Fix description terminology

drivers/pci/controller/dwc/pcie-designware-host.c | 10 +++++-----

 1 file changed, 5 insertions(+), 5 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +5 -5
index 36e284c..0c6e19a 100644
@@ -120,9 +120,9 @@ static void dw_chained_msi_isr(struct irq_desc *desc)
 	chained_irq_exit(chip, desc);
 }
 
-static void dw_pci_setup_msi_msg(struct irq_data *data, struct msi_msg *msg)
+static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg)
 {
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	struct dw_pcie *pci = to_dw_pcie_from_pp(pp);
 	u64 msi_target;
 
@@ -135,12 +135,12 @@ static void dw_pci_setup_msi_msg(struct irq_data *data, struct msi_msg *msg)
 	msg->address_hi = upper_32_bits(msi_target);
 
 	if (pp->ops->get_msi_data)
-		msg->data = pp->ops->get_msi_data(pp, data->hwirq);
+		msg->data = pp->ops->get_msi_data(pp, d->hwirq);
 	else
-		msg->data = data->hwirq;
+		msg->data = d->hwirq;
 
 	dev_dbg(pci->dev, "msi#%d address_hi %#x address_lo %#x\n",
-		(int)data->hwirq, msg->address_hi, msg->address_lo);
+		(int)d->hwirq, msg->address_hi, msg->address_lo);
 }
 
 static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
Signature · 1 line
2.7.4
#5 lore raw

PATCH v2 5/8 PCI: dwc: Rename variable name from data to d on dw_pci_msi_set_affinity()

In reply to Gustavo Pimentel

Rename variable from data to d to maintain consistency between driver functions.

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

---
Changes v1 -> v2:
- Fix description terminology

 drivers/pci/controller/dwc/pcie-designware-host.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/dwc/pcie-designware-host.c +1 -1
index 0c6e19a..a59fc17e 100644
@@ -143,7 +143,7 @@ static void dw_pci_setup_msi_msg(struct irq_data *d, struct msi_msg *msg)
 		(int)d->hwirq, msg->address_hi, msg->address_lo);
 }
 
-static int dw_pci_msi_set_affinity(struct irq_data *irq_data,
+static int dw_pci_msi_set_affinity(struct irq_data *d,
 				   const struct cpumask *mask, bool force)
 {
 	return -EINVAL;
Signature · 1 line
2.7.4
#6 lore raw

PATCH v2 6/8 PCI: dwc: Rename variable name from data to d on dw_pcie_irq_domain_free()

In reply to Gustavo Pimentel

Rename variable from data to d to maintain consistency between driver functions.

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

---
Changes v1 -> v2:
- Fix description terminology

 drivers/pci/controller/dwc/pcie-designware-host.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +3 -3
index a59fc17e..768e16a 100644
@@ -255,13 +255,13 @@ static int dw_pcie_irq_domain_alloc(struct irq_domain *domain,
 static void dw_pcie_irq_domain_free(struct irq_domain *domain,
 				    unsigned int virq, unsigned int nr_irqs)
 {
-	struct irq_data *data = irq_domain_get_irq_data(domain, virq);
-	struct pcie_port *pp = irq_data_get_irq_chip_data(data);
+	struct irq_data *d = irq_domain_get_irq_data(domain, virq);
+	struct pcie_port *pp = irq_data_get_irq_chip_data(d);
 	unsigned long flags;
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
-	bitmap_release_region(pp->msi_irq_in_use, data->hwirq,
+	bitmap_release_region(pp->msi_irq_in_use, d->hwirq,
 			      order_base_2(nr_irqs));
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
Signature · 1 line
2.7.4
#7 lore raw

PATCH v2 7/8 PCI: dwc: Improve code readability and simplifies mask/unmask operations

In reply to Gustavo Pimentel

Improve code readability and simplifies mask/unmask operations by inverting the applied logic (no functional change is intended).

Replace variable name from irq_status to irq_mask, since its goal is to keep track of which interruptions are mask or not.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

---
Changes v1 -> v2:
- Move 2 bit rotation operation replacement to patch 8

 drivers/pci/controller/dwc/pcie-designware-host.c | 12 ++++++------
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +6 -6
index 768e16a..c550c4a 100644
@@ -164,9 +164,9 @@ static void dw_pci_bottom_mask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] &= ~(1 << bit);
+		pp->irq_mask[ctrl] |= (1 << bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -187,9 +187,9 @@ static void dw_pci_bottom_unmask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_status[ctrl] |= 1 << bit;
+		pp->irq_mask[ctrl] &= ~(1 << bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
-				    ~pp->irq_status[ctrl]);
+				    pp->irq_mask[ctrl]);
 	}
 
 	raw_spin_unlock_irqrestore(&pp->lock, flags);
@@ -665,13 +665,13 @@ void dw_pcie_setup_rc(struct pcie_port *pp)
 
 	/* Initialize IRQ Status array */
 	for (ctrl = 0; ctrl < num_ctrls; ctrl++) {
+		pp->irq_mask[ctrl] = ~0;
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
-				    4, ~0);
+				    4, pp->irq_mask[ctrl]);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_ENABLE +
 					(ctrl * MSI_REG_CTRL_BLOCK_SIZE),
 				    4, ~0);
-		pp->irq_status[ctrl] = 0;
 	}
 
 	/* Setup RC BARs */
drivers/pci/controller/dwc/pcie-designware.h +1 -1
index 9943d8c..2790002 100644
@@ -177,7 +177,7 @@ struct pcie_port {
 	struct irq_domain	*msi_domain;
 	dma_addr_t		msi_data;
 	u32			num_vectors;
-	u32			irq_status[MAX_MSI_CTRLS];
+	u32			irq_mask[MAX_MSI_CTRLS];
 	raw_spinlock_t		lock;
 	DECLARE_BITMAP(msi_irq_in_use, MAX_MSI_IRQS);
 };
Signature · 1 line
2.7.4
#8 lore raw

PATCH v2 8/8 PCI: dwc: Replace bit rotation operation (1 << bit) by BIT(bit)

In reply to Gustavo Pimentel

Replace bit rotation operation (1 << bit) by BIT(bit), which simplifies code reading.

No functional change is intended.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

---
Changes v1 -> v2:
- No changes

 drivers/pci/controller/dwc/pcie-designware-host.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/pci/controller/dwc/pcie-designware-host.c +3 -3
index c550c4a..45ff5e4 100644
@@ -164,7 +164,7 @@ static void dw_pci_bottom_mask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_mask[ctrl] |= (1 << bit);
+		pp->irq_mask[ctrl] |= BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
 				    pp->irq_mask[ctrl]);
 	}
@@ -187,7 +187,7 @@ static void dw_pci_bottom_unmask(struct irq_data *d)
 		res = ctrl * MSI_REG_CTRL_BLOCK_SIZE;
 		bit = d->hwirq % MAX_MSI_IRQS_PER_CTRL;
 
-		pp->irq_mask[ctrl] &= ~(1 << bit);
+		pp->irq_mask[ctrl] &= ~BIT(bit);
 		dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_MASK + res, 4,
 				    pp->irq_mask[ctrl]);
 	}
@@ -207,7 +207,7 @@ static void dw_pci_bottom_ack(struct irq_data *d)
 
 	raw_spin_lock_irqsave(&pp->lock, flags);
 
-	dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS + res, 4, 1 << bit);
+	dw_pcie_wr_own_conf(pp, PCIE_MSI_INTR0_STATUS + res, 4, BIT(bit));
 
 	if (pp->ops->msi_irq_ack)
 		pp->ops->msi_irq_ack(d->hwirq, pp);
Signature · 1 line
2.7.4
#9 lore raw
In reply to Gustavo Pimentel
Quoted 35 lines · Gustavo Pimentel

This patch series aims to improve Synopsys DesignWare Root Complex driver code by:
- removing unnecessary header files
- enforcing variable naming coherency among similar functions
- simplifing code readability of mask/unmask function operations
- replacing bit rotation operation (1 << bit) by BIT(bit)

No functional changes are intended.

All patches are independent so they can be easily analyzed and accepted or discarded.

This patches organization also allows to easily merge (squash) some patches, if desired.

Cc Lorenzo Pieralisi <[email protected]>
Cc Joao Pinto <[email protected]>
Cc Jingoo Han <[email protected]>

Gustavo Pimentel (8):
PCI: dwc: Remove unnecessary header include (of_gpio.h)
PCI: dwc: Remove unnecessary header include (signal.h)
PCI: dwc: Rename variable name from data to d on
dw_pci_bottom_mask/unmask()
PCI: dwc: Rename variable name from data to d on

    dw_pci_setup_msi_msg()

PCI: dwc: Rename variable name from data to d on
dw_pci_msi_set_affinity()
PCI: dwc: Rename variable name from data to d on
dw_pcie_irq_domain_free()
PCI: dwc: Improve code readability and simplifies mask/unmask
operations
PCI: dwc: Replace bit rotation operation (1 << bit) by BIT(bit)

Quoted 5 lines
 drivers/pci/controller/dwc/pcie-designware-host.c | 52 +++++++++++------------
 drivers/pci/controller/dwc/pcie-designware-plat.c |  2 -
 drivers/pci/controller/dwc/pcie-designware.h      |  2 +-
 3 files changed, 27 insertions(+), 29 deletions(-)

Applied to pci/dwc for v5.1, thanks.

Lorenzo