Skip to contentSkip to conversation

PCI / DPC: Few improvements

PATCH Applied Mika Westerberg 3 participants 9 messages Jun 6, 2016 – Jun 22, 2016 PCI

lore
Share & tools
lore
#0 lore raw

cover PCI / DPC: Few improvements

Hi,

This series includes few improvements for the PCIe DPC driver. First we introduce module_pci_port_service() which allows reducing of boilerblate code used in the DPC driver. In addition we convert the driver to use managed resource functions (devm) to get rid of even more boilerblate.

I do not have hardware supporting DPC so these are only compile tested.

Mika Westerberg (4):
PCI / PCIe: Introduce module_pci_port_service() PCI / DPC: Convert to use module_pcie_port_service() PCI / DPC: Convert the driver to use devm_* functions PCI / DPC: Fix whitespace in struct dpc_dev

 drivers/pci/pcie/pcie-dpc.c | 30 +++++++-----------------------
 include/linux/pcieport_if.h | 13 +++++++++++++
 2 files changed, 20 insertions(+), 23 deletions(-)
Signature · 1 line
2.8.1
#1 lore raw

PATCH 1/4 PCI / PCIe: Introduce module_pci_port_service()

As used elsewhere in the kernel already. This will reduce amount of boilerblate code PCIe port service drivers otherwise need to open-code.

---
 include/linux/pcieport_if.h | 13 +++++++++++++
 1 file changed, 13 insertions(+)
include/linux/pcieport_if.h +13 -0
index afcd130ab3a9..9276a85bffde 100644
@@ -67,4 +67,17 @@ struct pcie_port_service_driver {
 int pcie_port_service_register(struct pcie_port_service_driver *new);
 void pcie_port_service_unregister(struct pcie_port_service_driver *new);
 
+/**
+ * module_pcie_port_service() - Helper macro for registering a PCI driver
+ * @__port_service: pcie_port_service struct
+ *
+ * Helper macro for PCIe port service drivers which do not do anything
+ * special in module init/exit. This eliminates a lot of boilerplate. Each
+ * module may only use this macro once, and calling it replaces
+ * module_init() and module_exit()
+ */
+#define module_pcie_port_service(__port_service) \
+	module_driver(__port_service, pcie_port_service_register, \
+		      pcie_port_service_unregister)
+
 #endif /* _PCIEPORT_IF_H_ */
Signature · 1 line
2.8.1
#2 lore raw

PATCH 2/4 PCI / DPC: Convert to use module_pcie_port_service()

In reply to Mika Westerberg

There is no need to open-code this in the driver. Use the helper we just introduced to remove the boilerblate code from the driver.

---
 drivers/pci/pcie/pcie-dpc.c | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/pci/pcie/pcie-dpc.c +1 -12
index ab552f1bc08f..533c548607d7 100644
@@ -144,20 +144,9 @@ static struct pcie_port_service_driver dpcdriver = {
 	.remove		= dpc_remove,
 };
 
-static int __init dpc_service_init(void)
-{
-	return pcie_port_service_register(&dpcdriver);
-}
-
-static void __exit dpc_service_exit(void)
-{
-	pcie_port_service_unregister(&dpcdriver);
-}
+module_pcie_port_service(dpcdriver);
 
 MODULE_DESCRIPTION("PCI Express Downstream Port Containment driver");
 MODULE_AUTHOR("Keith Busch <[email protected]>");
 MODULE_LICENSE("GPL");
 MODULE_VERSION("0.1");
-
-module_init(dpc_service_init);
-module_exit(dpc_service_exit);
Signature · 1 line
2.8.1
#3 lore raw

PATCH 3/4 PCI / DPC: Convert the driver to use devm_* functions

In reply to Mika Westerberg

These will automatically release the resources when the driver is removed so no need to do that explicitly in the driver.

---
 drivers/pci/pcie/pcie-dpc.c | 13 ++++---------
 1 file changed, 4 insertions(+), 9 deletions(-)
drivers/pci/pcie/pcie-dpc.c +4 -9
index 533c548607d7..8a061645f217 100644
@@ -89,7 +89,7 @@ static int dpc_probe(struct pcie_device *dev)
 	int status;
 	u16 ctl, cap;
 
-	dpc = kzalloc(sizeof(*dpc), GFP_KERNEL);
+	dpc = devm_kzalloc(&dev->device, sizeof(*dpc), GFP_KERNEL);
 	if (!dpc)
 		return -ENOMEM;
 
@@ -98,11 +98,12 @@ static int dpc_probe(struct pcie_device *dev)
 	INIT_WORK(&dpc->work, interrupt_event_handler);
 	set_service_data(dev, dpc);
 
-	status = request_irq(dev->irq, dpc_irq, IRQF_SHARED, "pcie-dpc", dpc);
+	status = devm_request_irq(&dev->device, dev->irq, dpc_irq, IRQF_SHARED,
+				  "pcie-dpc", dpc);
 	if (status) {
 		dev_warn(&dev->device, "request IRQ%d failed: %d\n", dev->irq,
 			 status);
-		goto out;
+		return status;
 	}
 
 	pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CAP, &cap);
@@ -117,9 +118,6 @@ static int dpc_probe(struct pcie_device *dev)
 		FLAG(cap, PCI_EXP_DPC_CAP_SW_TRIGGER), (cap >> 8) & 0xf,
 		FLAG(cap, PCI_EXP_DPC_CAP_DL_ACTIVE));
 	return status;
- out:
-	kfree(dpc);
-	return status;
 }
 
 static void dpc_remove(struct pcie_device *dev)
@@ -131,9 +129,6 @@ static void dpc_remove(struct pcie_device *dev)
 	pci_read_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, &ctl);
 	ctl &= ~(PCI_EXP_DPC_CTL_EN_NONFATAL | PCI_EXP_DPC_CTL_INT_EN);
 	pci_write_config_word(pdev, dpc->cap_pos + PCI_EXP_DPC_CTL, ctl);
-
-	free_irq(dev->irq, dpc);
-	kfree(dpc);
 }
 
 static struct pcie_port_service_driver dpcdriver = {
Signature · 1 line
2.8.1
#4 lore raw

PATCH 4/4 PCI / DPC: Fix whitespace in struct dpc_dev

In reply to Mika Westerberg

There is unnecesary space before tab in the two lines. Remove these.

---
 drivers/pci/pcie/pcie-dpc.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/pci/pcie/pcie-dpc.c +2 -2
index 8a061645f217..197d9ec18713 100644
@@ -15,8 +15,8 @@
 
 struct dpc_dev {
 	struct pcie_device	*dev;
-	struct work_struct 	work;
-	int 			cap_pos;
+	struct work_struct	work;
+	int			cap_pos;
 };
 
 static void dpc_wait_link_inactive(struct pci_dev *pdev)
Signature · 1 line
2.8.1
Acked-by on the v1 series
#5 lore raw
In reply to Mika Westerberg
Quoted 15 lines · Mika Westerberg

Hi,

This series includes few improvements for the PCIe DPC driver. First we introduce module_pci_port_service() which allows reducing of boilerblate code used in the DPC driver. In addition we convert the driver to use managed resource functions (devm) to get rid of even more boilerblate.

I do not have hardware supporting DPC so these are only compile tested.

Mika Westerberg (4):
PCI / PCIe: Introduce module_pci_port_service() PCI / DPC: Convert to use module_pcie_port_service() PCI / DPC: Convert the driver to use devm_* functions PCI / DPC: Fix whitespace in struct dpc_dev

Quoted 3 lines
 drivers/pci/pcie/pcie-dpc.c | 30 +++++++-----------------------
 include/linux/pcieport_if.h | 13 +++++++++++++
 2 files changed, 20 insertions(+), 23 deletions(-)

Thanks, these look good to me.

#6 lore raw
In reply to Mika Westerberg

Gentle ping on this.

Quoted 21 lines · Mika Westerberg

Hi,

This series includes few improvements for the PCIe DPC driver. First we introduce module_pci_port_service() which allows reducing of boilerblate code used in the DPC driver. In addition we convert the driver to use managed resource functions (devm) to get rid of even more boilerblate.

I do not have hardware supporting DPC so these are only compile tested.

Mika Westerberg (4):
PCI / PCIe: Introduce module_pci_port_service() PCI / DPC: Convert to use module_pcie_port_service() PCI / DPC: Convert the driver to use devm_* functions PCI / DPC: Fix whitespace in struct dpc_dev

 drivers/pci/pcie/pcie-dpc.c | 30 +++++++-----------------------
 include/linux/pcieport_if.h | 13 +++++++++++++
 2 files changed, 20 insertions(+), 23 deletions(-)
Signature · 1 line
2.8.1
#7 lore raw
In reply to Mika Westerberg
Quoted 15 lines · Mika Westerberg

Hi,

This series includes few improvements for the PCIe DPC driver. First we introduce module_pci_port_service() which allows reducing of boilerblate code used in the DPC driver. In addition we convert the driver to use managed resource functions (devm) to get rid of even more boilerblate.

I do not have hardware supporting DPC so these are only compile tested.

Mika Westerberg (4):
PCI / PCIe: Introduce module_pci_port_service() PCI / DPC: Convert to use module_pcie_port_service() PCI / DPC: Convert the driver to use devm_* functions PCI / DPC: Fix whitespace in struct dpc_dev

Quoted 3 lines
 drivers/pci/pcie/pcie-dpc.c | 30 +++++++-----------------------
 include/linux/pcieport_if.h | 13 +++++++++++++
 2 files changed, 20 insertions(+), 23 deletions(-)

I applied the last two, with Keith's acks, to pci/dpc for v4.8.

I didn't apply the first two because I don't think these port drivers should be modules. I think DPC and thunderbolt are the only candidates right now, and I think it's a stretch to think about either one as a module.

Bjorn

#8 lore raw
Quoted 20 lines · Bjorn Helgaas
Quoted 15 lines · Mika Westerberg

Hi,

This series includes few improvements for the PCIe DPC driver. First we introduce module_pci_port_service() which allows reducing of boilerblate code used in the DPC driver. In addition we convert the driver to use managed resource functions (devm) to get rid of even more boilerblate.

I do not have hardware supporting DPC so these are only compile tested.

Mika Westerberg (4):
PCI / PCIe: Introduce module_pci_port_service() PCI / DPC: Convert to use module_pcie_port_service() PCI / DPC: Convert the driver to use devm_* functions PCI / DPC: Fix whitespace in struct dpc_dev

Quoted 3 lines
 drivers/pci/pcie/pcie-dpc.c | 30 +++++++-----------------------
 include/linux/pcieport_if.h | 13 +++++++++++++
 2 files changed, 20 insertions(+), 23 deletions(-)
Quoted 6 lines

I applied the last two, with Keith's acks, to pci/dpc for v4.8.

I didn't apply the first two because I don't think these port drivers should be modules. I think DPC and thunderbolt are the only candidates right now, and I think it's a stretch to think about either one as a module.

Understood. Thanks.