Skip to contentSkip to conversation

mcb: export FPGA information via sysfs

PATCH New Johannes Thumshirn 2 participants 7 messages Mar 18, 2016 – Apr 8, 2016 Men chameleon bus (mcb)

lore
Share & tools
lore
#0 lore raw

cover mcb: export FPGA information via sysfs

The following series adds a way to obtain information about a MCB FPGA via sysfs. This is viable i.e. for a field technician to check if the latest FPGA bitstream version is applied to the hardware.

The first patch layes the foundation in order to get sysfs correctly working with MCB and the second patch exports the bus information into sysfs.

Changes from v1:
* Address kbuild robots warning about broken bisectability

Johannes Thumshirn (2):
mcb: Correctly initialize the bus's device
mcb: export bus information via sysfs

 Documentation/ABI/testing/sysfs-bus-mcb | 29 ++++++++++++
 drivers/mcb/mcb-core.c                  | 79 +++++++++++++++++++++++++++++++--
 drivers/mcb/mcb-internal.h              |  1 -
 drivers/mcb/mcb-parse.c                 | 15 +++----
 include/linux/mcb.h                     | 14 ++++--
 5 files changed, 121 insertions(+), 17 deletions(-)
 create mode 100644 Documentation/ABI/testing/sysfs-bus-mcb
Signature · 1 line
2.7.2
#1 lore raw

PATCH v2 1/2 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.7.2
Reviewed-by Tested-by on v2 1/2
#2 lore raw

Re: [PATCH v2 1/2] mcb: Correctly initialize the bus's device

Quoted 5 lines · Johannes Thumshirn

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

---

Looks good to me. I have tested this on the MEN SC24 AMD Board with a MCB FPGA.

#3 lore raw

Re: [PATCH v2 1/2] mcb: Correctly initialize the bus's device

Quoted 4 lines · On Freitag, 8. April 2016 09:06:03 CEST Andreas Werner wrote:
Quoted 3 lines · Johannes Thumshirn

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

Quoted 8 lines
Quoted 2 lines

---

Looks good to me. I have tested this on the MEN SC24 AMD Board with a MCB FPGA.

Thanks

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
#4 lore raw

PATCH v2 2/2 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.7.2
Reviewed-by Tested-by on v2 2/2
#5 lore raw

Re: [PATCH v2 2/2] mcb: export bus information via sysfs

Quoted 5 lines · 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.

---

Looks good to me. I have tested this on the MEN SC24 with a MCB FPGA.

#6 lore raw

Re: [PATCH v2 2/2] mcb: export bus information via sysfs

Quoted 4 lines · On Freitag, 8. April 2016 09:07:15 CEST Andreas Werner wrote:
Quoted 3 lines · 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.

Quoted 8 lines
Quoted 2 lines

---

Looks good to me. I have tested this on the MEN SC24 with a MCB FPGA.

Yay, thanks

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