Skip to contentSkip to conversation

MCB patches for v4.7

PATCH In review Johannes Thumshirn 3 participants 9 messages May 3, 2016

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

cover MCB patches for v4.7

Hi Greg,

The following patches are the MCB updates for v4.7. These are mainly cleanups and some bug fixes from Andreas and me. The only non cleanup/bugfix patch is 'mcb: export bus information via sysfs' which exports information about the carrier FPGA to sysfs, like the revision number and model name of the FPGA, so that a field technician can easily obtain these.

All patches have been tested by Andreas and have been on lkml for people to comment as well as in my git tree located at:

git://git.kernel.org/pub/scm/linux/kernel/git/jth/linux.git tags/for-v4.7

Thanks,
Johannes

Andreas Werner (3):
mcb: Fixed bar number assignment for the gdd
mcb: Replace ioremap and request_region with the devm version
mcb: Delete num_cells variable which is not required

Johannes Thumshirn (3):
mcb: Correctly initialize the bus's device
mcb: export bus information via sysfs
mcb: Implement bus->dev.release callback

 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++
 drivers/mcb/mcb-core.c                  | 99 ++++++++++++++++++++++++++++++---
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 17 ++----
 drivers/mcb/mcb-pci.c                   | 23 +++-----
 include/linux/mcb.h                     | 14 ++++-
 6 files changed, 144 insertions(+), 39 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
Signature · 1 line
2.8.1
#1 lore raw

PATCH 1/6 mcb: Correctly initialize the bus's device

The mcb bus' device member wasn't correctly initialized and thus wasn't placed correctly into the driver model.

---
 drivers/mcb/mcb-core.c | 19 ++++++++++++++++---
 include/linux/mcb.h    |  5 ++---
 2 files changed, 18 insertions(+), 6 deletions(-)
drivers/mcb/mcb-core.c +16 -3
index a4be451..1e336cc 100644
@@ -187,6 +187,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 {
 	struct mcb_bus *bus;
 	int bus_nr;
+	int rc;
 
 	bus = kzalloc(sizeof(struct mcb_bus), GFP_KERNEL);
 	if (!bus)
@@ -194,14 +195,26 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 
 	bus_nr = ida_simple_get(&mcb_ida, 0, 0, GFP_KERNEL);
 	if (bus_nr < 0) {
-		kfree(bus);
-		return ERR_PTR(bus_nr);
+		rc = bus_nr;
+		goto err_free;
 	}
 
-	INIT_LIST_HEAD(&bus->children);
 	bus->bus_nr = bus_nr;
 	bus->carrier = carrier;
+
+	device_initialize(&bus->dev);
+	bus->dev.parent = carrier;
+	bus->dev.bus = &mcb_bus_type;
+
+	dev_set_name(&bus->dev, "mcb:%d", bus_nr);
+	rc = device_add(&bus->dev);
+	if (rc)
+		goto err_free;
+
 	return bus;
+err_free:
+	kfree(bus);
+	return ERR_PTR(rc);
 }
 EXPORT_SYMBOL_GPL(mcb_alloc_bus);
 
include/linux/mcb.h +2 -3
index ed06e15..3efafbc 100644
@@ -21,13 +21,12 @@ struct mcb_device;
 /**
  * struct mcb_bus - MEN Chameleon Bus
  *
- * @dev: pointer to carrier device
- * @children: the child busses
+ * @dev: bus device
+ * @carrier: pointer to carrier device
  * @bus_nr: mcb bus number
  * @get_irq: callback to get IRQ number
  */
 struct mcb_bus {
-	struct list_head children;
 	struct device dev;
 	struct device *carrier;
 	int bus_nr;
Signature · 1 line
2.8.1
#2 lore raw

PATCH 2/6 mcb: export bus information via sysfs

In reply to Johannes Thumshirn

Export information about the bus stored in the FPGA's header to userspace via sysfs, instead of hiding it in pr_debug()s from everyone.

---
 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++++++++
 drivers/mcb/mcb-core.c                  | 60 +++++++++++++++++++++++++++++++++
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 15 +++------
 include/linux/mcb.h                     |  9 +++++
 5 files changed, 103 insertions(+), 11 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
Documentation/ABI/testing/sysfs-bus-mcb new file +29 -0
new file mode 100644
index 0000000..77947c5
@@ -0,0 +1,29 @@
+What:		/sys/bus/mcb/devices/mcb:X
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <[email protected]>
+Description:	Hardware chip or device hosting the MEN chameleon bus
+
+What:		/sys/bus/mcb/devices/mcb:X/revision
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <[email protected]>
+Description:	The FPGA's revision number
+
+What:		/sys/bus/mcb/devices/mcb:X/minor
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <[email protected]>
+Description:	The FPGA's minor number
+
+What:		/sys/bus/mcb/devices/mcb:X/model
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <[email protected]>
+Description:	The FPGA's model number
+
+What:		/sys/bus/mcb/devices/mcb:X/name
+Date:		March 2016
+KernelVersion:	4.7
+Contact:	Johannes Thumshirn <[email protected]>
+Description:	The FPGA's name
drivers/mcb/mcb-core.c +60 -0

78 lines not on this page · raw message

drivers/mcb/mcb-internal.h +0 -1
index fb7493d..5254e02 100644
@@ -5,7 +5,6 @@
 
 #define PCI_VENDOR_ID_MEN		0x1a88
 #define PCI_DEVICE_ID_MEN_CHAMELEON	0x4d45
-#define CHAMELEON_FILENAME_LEN		12
 #define CHAMELEONV2_MAGIC		0xabce
 #define CHAM_HEADER_SIZE		0x200
 
drivers/mcb/mcb-parse.c +5 -10
index 0049269..35f385b 100644
@@ -113,16 +113,11 @@ int chameleon_parse_cells(struct mcb_bus *bus, phys_addr_t mapbase,
 	}
 	p += hsize;
 
-	pr_debug("header->revision = %d\n", header->revision);
-	pr_debug("header->model = 0x%x ('%c')\n", header->model,
-		header->model);
-	pr_debug("header->minor = %d\n", header->minor);
-	pr_debug("header->bus_type = 0x%x\n", header->bus_type);
-
-
-	pr_debug("header->magic = 0x%x\n", header->magic);
-	pr_debug("header->filename = \"%.*s\"\n", CHAMELEON_FILENAME_LEN,
-		header->filename);
+	bus->revision = header->revision;
+	bus->model = header->model;
+	bus->minor = header->minor;
+	snprintf(bus->name, CHAMELEON_FILENAME_LEN + 1, "%s",
+		 header->filename);
 
 	for_each_chameleon_cell(dtype, p) {
 		switch (dtype) {
include/linux/mcb.h +9 -0
index 3efafbc..ead13d2 100644
@@ -15,6 +15,8 @@
 #include <linux/device.h>
 #include <linux/irqreturn.h>
 
+#define CHAMELEON_FILENAME_LEN 12
+
 struct mcb_driver;
 struct mcb_device;
 
@@ -25,11 +27,18 @@ struct mcb_device;
  * @carrier: pointer to carrier device
  * @bus_nr: mcb bus number
  * @get_irq: callback to get IRQ number
+ * @revision: the FPGA's revision number
+ * @model: the FPGA's model number
+ * @filename: the FPGA's name
  */
 struct mcb_bus {
 	struct device dev;
 	struct device *carrier;
 	int bus_nr;
+	u8 revision;
+	char model;
+	u8 minor;
+	char name[CHAMELEON_FILENAME_LEN + 1];
 	int (*get_irq)(struct mcb_device *dev);
 };
 #define to_mcb_bus(b) container_of((b), struct mcb_bus, dev)
Signature · 1 line
2.8.1
#3 lore raw
In reply to Johannes Thumshirn
Quoted 26 lines · Johannes Thumshirn

Hi Greg,

The following patches are the MCB updates for v4.7. These are mainly cleanups and some bug fixes from Andreas and me. The only non cleanup/bugfix patch is 'mcb: export bus information via sysfs' which exports information about the carrier FPGA to sysfs, like the revision number and model name of the FPGA, so that a field technician can easily obtain these.

All patches have been tested by Andreas and have been on lkml for people to comment as well as in my git tree located at:

git://git.kernel.org/pub/scm/linux/kernel/git/jth/linux.git tags/for-v4.7

Thanks,
Johannes

Andreas Werner (3):
mcb: Fixed bar number assignment for the gdd
mcb: Replace ioremap and request_region with the devm version
mcb: Delete num_cells variable which is not required

Johannes Thumshirn (3):
mcb: Correctly initialize the bus's device
mcb: export bus information via sysfs
mcb: Implement bus->dev.release callback

Quoted 12 lines
 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++
 drivers/mcb/mcb-core.c                  | 99 ++++++++++++++++++++++++++++++---
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 17 ++----
 drivers/mcb/mcb-pci.c                   | 23 +++-----
 include/linux/mcb.h                     | 14 ++++-
 6 files changed, 144 insertions(+), 39 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
Signature · 1 line
2.8.1

Somehow only two patches did make it through the mailserver, my apologies.

I'll re-send once I figured out what went wrong.

Signature · 6 lines
Johannes Thumshirn                                          Storage
[email protected]                                +49 911 74053 689
SUSE LINUX GmbH, Maxfeldstr. 5, 90409 Nürnberg
GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)
Key fingerprint = EC38 9CAB C2C4 F25D 8600 D0D0 0393 969D 2D76 0850
maintainer
#4 lore raw
Quoted 36 lines · Johannes Thumshirn
Quoted 35 lines · Johannes Thumshirn

Hi Greg,

The following patches are the MCB updates for v4.7. These are mainly cleanups and some bug fixes from Andreas and me. The only non cleanup/bugfix patch is 'mcb: export bus information via sysfs' which exports information about the carrier FPGA to sysfs, like the revision number and model name of the FPGA, so that a field technician can easily obtain these.

All patches have been tested by Andreas and have been on lkml for people to comment as well as in my git tree located at:

git://git.kernel.org/pub/scm/linux/kernel/git/jth/linux.git tags/for-v4.7

Thanks,
Johannes

Andreas Werner (3):
mcb: Fixed bar number assignment for the gdd
mcb: Replace ioremap and request_region with the devm version
mcb: Delete num_cells variable which is not required

Johannes Thumshirn (3):
mcb: Correctly initialize the bus's device
mcb: export bus information via sysfs
mcb: Implement bus->dev.release callback

 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++
 drivers/mcb/mcb-core.c                  | 99 ++++++++++++++++++++++++++++++---
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 17 ++----
 drivers/mcb/mcb-pci.c                   | 23 +++-----
 include/linux/mcb.h                     | 14 ++++-
 6 files changed, 144 insertions(+), 39 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
Quoted 7 lines
Quoted 3 lines
Signature · 1 line
2.8.1

Somehow only two patches did make it through the mailserver, my apologies.

I'll re-send once I figured out what went wrong.

Odd, I got them all here, unless you resent them...

#5 lore raw

PATCH 3/6 mcb: Fixed bar number assignment for the gdd

In reply to Johannes Thumshirn

From: Andreas Werner <[email protected]>

The bar number is found in reg2 within the gdd. Therefore we need to change the assigment from reg1 to reg2 which is the correct location.

Fixes '3764e82e5' drivers: Introduce MEN Chameleon Bus
Cc [email protected] # v3.15+
---
 drivers/mcb/mcb-parse.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/mcb/mcb-parse.c +1 -1
index 35f385b..dbecbed 100644
@@ -57,7 +57,7 @@ static int chameleon_parse_gdd(struct mcb_bus *bus,
 	mdev->id = GDD_DEV(reg1);
 	mdev->rev = GDD_REV(reg1);
 	mdev->var = GDD_VAR(reg1);
-	mdev->bar = GDD_BAR(reg1);
+	mdev->bar = GDD_BAR(reg2);
 	mdev->group = GDD_GRP(reg2);
 	mdev->inst = GDD_INS(reg2);
 
Signature · 1 line
2.8.1
#6 lore raw

PATCH 4/6 mcb: Replace ioremap and request_region with the devm version

In reply to Johannes Thumshirn

From: Andreas Werner <[email protected]>

Replaced ioremap with devm_ioremap and request_mem_region with devm_request_mem_region. This makes the code much more cleaner.

---
 drivers/mcb/mcb-pci.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/mcb/mcb-pci.c +7 -12
index 67d5e7d..99dd9db 100644
@@ -55,19 +55,20 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		goto out_disable;
 	}
 
-	res = request_mem_region(priv->mapbase, CHAM_HEADER_SIZE,
-				 KBUILD_MODNAME);
+	res = devm_request_mem_region(&pdev->dev, priv->mapbase,
+				      CHAM_HEADER_SIZE,
+				      KBUILD_MODNAME);
 	if (!res) {
 		dev_err(&pdev->dev, "Failed to request PCI memory\n");
 		ret = -EBUSY;
 		goto out_disable;
 	}
 
-	priv->base = ioremap(priv->mapbase, CHAM_HEADER_SIZE);
+	priv->base = devm_ioremap(&pdev->dev, priv->mapbase, CHAM_HEADER_SIZE);
 	if (!priv->base) {
 		dev_err(&pdev->dev, "Cannot ioremap\n");
 		ret = -ENOMEM;
-		goto out_release;
+		goto out_disable;
 	}
 
 	flags = pci_resource_flags(pdev, 0);
@@ -75,7 +76,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 		ret = -ENOTSUPP;
 		dev_err(&pdev->dev,
 			"IO mapped PCI devices are not supported\n");
-		goto out_iounmap;
+		goto out_disable;
 	}
 
 	pci_set_drvdata(pdev, priv);
@@ -83,7 +84,7 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	priv->bus = mcb_alloc_bus(&pdev->dev);
 	if (IS_ERR(priv->bus)) {
 		ret = PTR_ERR(priv->bus);
-		goto out_iounmap;
+		goto out_disable;
 	}
 
 	priv->bus->get_irq = mcb_pci_get_irq;
@@ -101,10 +102,6 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 
 out_mcb_bus:
 	mcb_release_bus(priv->bus);
-out_iounmap:
-	iounmap(priv->base);
-out_release:
-	pci_release_region(pdev, 0);
 out_disable:
 	pci_disable_device(pdev);
 	return ret;
@@ -116,8 +113,6 @@ static void mcb_pci_remove(struct pci_dev *pdev)
 
 	mcb_release_bus(priv->bus);
 
-	iounmap(priv->base);
-	release_region(priv->mapbase, CHAM_HEADER_SIZE);
 	pci_disable_device(pdev);
 }
 
Signature · 1 line
2.8.1
#7 lore raw

PATCH 5/6 mcb: Delete num_cells variable which is not required

In reply to Johannes Thumshirn

From: Andreas Werner <[email protected]>

The num_cells variable is only used in the dev_dbg print, but we can directly use the ret variable which also includes the same value.

---
 drivers/mcb/mcb-pci.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
drivers/mcb/mcb-pci.c +1 -3
index 99dd9db..b15a034 100644
@@ -35,7 +35,6 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	struct resource *res;
 	struct priv *priv;
 	int ret;
-	int num_cells;
 	unsigned long flags;
 
 	priv = devm_kzalloc(&pdev->dev, sizeof(struct priv), GFP_KERNEL);
@@ -92,9 +91,8 @@ static int mcb_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
 	ret = chameleon_parse_cells(priv->bus, priv->mapbase, priv->base);
 	if (ret < 0)
 		goto out_mcb_bus;
-	num_cells = ret;
 
-	dev_dbg(&pdev->dev, "Found %d cells\n", num_cells);
+	dev_dbg(&pdev->dev, "Found %d cells\n", ret);
 
 	mcb_bus_add_devices(priv->bus);
 
Signature · 1 line
2.8.1
#8 lore raw

PATCH 6/6 mcb: Implement bus->dev.release callback

In reply to Johannes Thumshirn

The mcb_bus structure previously was released in mcb_release_bus. This lead to the following warning on module unload:

------------[ cut here ]------------
WARNING: CPU: 1 PID: 2032 at drivers/base/core.c:251 device_release+0x73/0x90
Device 'mcb:0' does not have a release() function, it is broken and must be fixed.
Modules linked in: men_z135_uart mcb_pci(-) mcb
CPU: 1 PID: 2032 Comm: rmmod Not tainted 4.6.0-rc4+ #3
Hardware name: N/A N/A/COMe-mBTi10, BIOS MVV1R921 X64 10/14/2015
 00000286 00000286 c0117de4 c12d6f16 c0117e2c c18be0d3 c0117dfc c104f6e1
 000000fb f5ccbe08 f5ccbe00 f5c64600 c0117e18 c104f728 00000009 00000000
 c0117e10 c18db674 c0117e2c c0117e3c c13ce5c3 c18be0d3 000000fb c18db674
Call Trace:
 [<c12d6f16>] dump_stack+0x47/0x61
 [<c104f6e1>] __warn+0xc1/0xe0
 [<c104f728>] warn_slowpath_fmt+0x28/0x30
 [<c13ce5c3>] device_release+0x73/0x90
 [<c12d92e4>] kobject_release+0x34/0x80
 [<c12d929d>] ? kobject_del+0x2d/0x40
 [<c12d9205>] kobject_put+0x25/0x50
 [<c13ce77f>] put_device+0xf/0x20
 [<c13d114b>] klist_devices_put+0xb/0x10
 [<c1752673>] klist_next+0x73/0xf0
 [<c13d1140>] ? unbind_store+0x100/0x100
 [<f8a23370>] ? mcb_bus_add_devices+0x30/0x30 [mcb]
 [<c13d0a81>] bus_for_each_dev+0x51/0x80
 [<f8a23319>] mcb_release_bus+0x19/0x40 [mcb]
 [<f8a23370>] ? mcb_bus_add_devices+0x30/0x30 [mcb]
 [<f8a2b033>] mcb_pci_remove+0x13/0x20 [mcb_pci]
 [<c130d358>] pci_device_remove+0x28/0xb0
 [<c13d201b>] __device_release_driver+0x7b/0x110
 [<c13d2847>] driver_detach+0x87/0x90
 [<c13d1b9b>] bus_remove_driver+0x3b/0x80
 [<c13d2ed0>] driver_unregister+0x20/0x50
 [<c130be53>] pci_unregister_driver+0x13/0x60
 [<f8a2b1f4>] mcb_pci_driver_exit+0xd/0xf [mcb_pci]
 [<c10be588>] SyS_delete_module+0x138/0x200
 [<c1159208>] ? ____fput+0x8/0x10
 [<c1068054>] ? task_work_run+0x74/0x90
 [<c1001879>] do_fast_syscall_32+0x69/0x120
 [<c1757597>] sysenter_past_esp+0x40/0x6a
---[ end trace 1ed34c2aa3019875 ]---

Release a mcb_bus' memory on the device's release callback, to avoid above warning.

---
 drivers/mcb/mcb-core.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
drivers/mcb/mcb-core.c +14 -6
index 9ae4d15..b73c6e7 100644
@@ -83,8 +83,8 @@ static int mcb_remove(struct device *dev)
 
 static void mcb_shutdown(struct device *dev)
 {
+	struct mcb_driver *mdrv = to_mcb_driver(dev->driver);
 	struct mcb_device *mdev = to_mcb_device(dev);
-	struct mcb_driver *mdrv = mdev->driver;
 
 	if (mdrv && mdrv->shutdown)
 		mdrv->shutdown(mdev);
@@ -214,6 +214,7 @@ int mcb_device_register(struct mcb_bus *bus, struct mcb_device *dev)
 	int device_id;
 
 	device_initialize(&dev->dev);
+	mcb_bus_get(bus);
 	dev->dev.bus = &mcb_bus_type;
 	dev->dev.parent = bus->dev.parent;
 	dev->dev.release = mcb_release_dev;
@@ -237,6 +238,15 @@ out:
 }
 EXPORT_SYMBOL_GPL(mcb_device_register);
 
+static void mcb_free_bus(struct device *dev)
+{
+	struct mcb_bus *bus = to_mcb_bus(dev);
+
+	put_device(bus->carrier);
+	ida_simple_remove(&mcb_ida, bus->bus_nr);
+	kfree(bus);
+}
+
 /**
  * mcb_alloc_bus() - Allocate a new @mcb_bus
  *
@@ -259,12 +269,13 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 	}
 
 	bus->bus_nr = bus_nr;
-	bus->carrier = carrier;
+	bus->carrier = get_device(carrier);
 
 	device_initialize(&bus->dev);
 	bus->dev.parent = carrier;
 	bus->dev.bus = &mcb_bus_type;
 	bus->dev.type = &mcb_carrier_device_type;
+	bus->dev.release = &mcb_free_bus;
 
 	dev_set_name(&bus->dev, "mcb:%d", bus_nr);
 	rc = device_add(&bus->dev);
@@ -273,6 +284,7 @@ struct mcb_bus *mcb_alloc_bus(struct device *carrier)
 
 	return bus;
 err_free:
+	put_device(carrier);
 	kfree(bus);
 	return ERR_PTR(rc);
 }
@@ -297,10 +309,6 @@ static void mcb_devices_unregister(struct mcb_bus *bus)
 void mcb_release_bus(struct mcb_bus *bus)
 {
 	mcb_devices_unregister(bus);
-
-	ida_simple_remove(&mcb_ida, bus->bus_nr);
-
-	kfree(bus);
 }
 EXPORT_SYMBOL_GPL(mcb_release_bus);
 
Signature · 1 line
2.8.1