Skip to contentSkip to conversation

mei: add debugfs hooks

char-misc-next Tomas Winkler 2 participants 3 messages Apr 4, 2013 – Apr 5, 2013

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

debugfs exposes device state and list of me clients and their properties

---
 drivers/misc/mei/Makefile  |   1 +
 drivers/misc/mei/debugfs.c | 150 +++++++++++++++++++++++++++++++++++++++++++++
 drivers/misc/mei/main.c    |  18 ++++--
 drivers/misc/mei/mei_dev.h |  20 +++++-
 drivers/misc/mei/pci-me.c  |   5 +-
 5 files changed, 186 insertions(+), 8 deletions(-)
 create mode 100644 drivers/misc/mei/debugfs.c
drivers/misc/mei/Makefile +1 -0
index 1b29f7c..ee85456 100644
@@ -11,6 +11,7 @@ mei-objs += main.o
 mei-objs += amthif.o
 mei-objs += wd.o
 mei-objs += bus.o
+mei-objs += debugfs.o
 
 obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o
 mei-me-objs := pci-me.o
drivers/misc/mei/debugfs.c new file +150 -0

150 lines not on this page · raw message

drivers/misc/mei/main.c +14 -4
index 872de9d..329fb86 100644
@@ -753,15 +753,25 @@ static struct miscdevice  mei_misc_device = {
 		.minor = MISC_DYNAMIC_MINOR,
 };
 
-int mei_register(struct device *dev)
+
+int mei_register(struct mei_device *dev)
 {
-	mei_misc_device.parent = dev;
-	return misc_register(&mei_misc_device);
+	int ret;
+	mei_misc_device.parent = &dev->pdev->dev;
+	ret = misc_register(&mei_misc_device);
+	if (ret)
+		return ret;
+
+	if (mei_dbgfs_register(dev, mei_misc_device.name))
+		dev_err(&dev->pdev->dev, "cannot register debugfs\n");
+
+	return 0;
 }
 EXPORT_SYMBOL_GPL(mei_register);
 
-void mei_deregister(void)
+void mei_deregister(struct mei_device *dev)
 {
+	mei_dbgfs_deregister(dev);
 	misc_deregister(&mei_misc_device);
 	mei_misc_device.parent = NULL;
 }
drivers/misc/mei/mei_dev.h +18 -2
index 325f71a..8806be4 100644
@@ -437,6 +437,11 @@ struct mei_device {
 	/* List of bus devices */
 	struct list_head device_list;
 
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+	struct dentry *dbgfs_dir;
+#endif /* CONFIG_DEBUG_FS */
+
+
 	const struct mei_hw_ops *ops;
 	char hw[0] __aligned(sizeof(void *));
 };
@@ -603,8 +608,19 @@ static inline int mei_count_full_read_slots(struct mei_device *dev)
 	return dev->ops->rdbuf_full_slots(dev);
 }
 
-int mei_register(struct device *dev);
-void mei_deregister(void);
+#if IS_ENABLED(CONFIG_DEBUG_FS)
+int mei_dbgfs_register(struct mei_device *dev, const char *name);
+void mei_dbgfs_deregister(struct mei_device *dev);
+#else
+static inline int mei_dbgfs_register(struct mei_device *dev, const char *name)
+{
+	return 0;
+}
+static inline void mei_dbgfs_deregister(struct mei_device *dev) {}
+#endif /* CONFIG_DEBUG_FS */
+
+int mei_register(struct mei_device *dev);
+void mei_deregister(struct mei_device *dev);
 
 #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d"
 #define MEI_HDR_PRM(hdr)                  \
drivers/misc/mei/pci-me.c +3 -2
index a1a582b..88aec6a 100644
@@ -190,7 +190,7 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
 		goto release_irq;
 	}
 
-	err = mei_register(&pdev->dev);
+	err = mei_register(dev);
 	if (err)
 		goto release_irq;
 
@@ -262,12 +262,13 @@ static void mei_me_remove(struct pci_dev *pdev)
 	if (hw->mem_addr)
 		pci_iounmap(pdev, hw->mem_addr);
 
+	mei_deregister(dev);
+
 	kfree(dev);
 
 	pci_release_regions(pdev);
 	pci_disable_device(pdev);
 
-	mei_deregister();
 
 }
 #ifdef CONFIG_PM
Signature · 1 line
1.7.11.7
maintainer
#1 lore raw
Quoted 4 lines · Tomas Winkler

debugfs exposes device state and list of me clients and their properties

Just one small comment:

drivers/misc/mei/debugfs.c line 31

Quoted 3 lines
drivers/misc/mei/debugfs.c new file +3 -0
+#define DEBUGFS_ADD_FILE(_mei, name, parent, mode)	\
+	debugfs_create_file(#name, mode, parent,	\
+			_mei, &mei_dbgfs_fops_##name)

This macro seems to obfuscate more than it helps. In general, string concatenation in macros is problematic because it means you can no longer grep for where a symbols is being used.

Arnd

#2 lore raw
Quoted 9 lines · Tomas Winkler
Quoted 4 lines

debugfs exposes device state and list of me clients and their properties

Just one small comment:

Quoted 9 lines

drivers/misc/mei/debugfs.c line 31

Quoted 3 lines
drivers/misc/mei/debugfs.c new file +3 -0
+#define DEBUGFS_ADD_FILE(_mei, name, parent, mode)	\
+	debugfs_create_file(#name, mode, parent,	\
+			_mei, &mei_dbgfs_fops_##name)

This macro seems to obfuscate more than it helps. In general, string concatenation in macros is problematic because it means you can no longer grep for where a symbols is being used.

This is very common shortcut mostly used in wireless drivers,
vut I don't mind to open code this, I will resubmit version two, this patch also needs a fix in the Makefile

Thanks
Tomas