diff options
author | Tomas Winkler <tomas.winkler@intel.com> | 2013-04-05 15:10:34 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@linuxfoundation.org> | 2013-04-05 18:49:17 -0400 |
commit | 30e53bb8ffb1f3270ad89196d9799057008d9537 (patch) | |
tree | 94fe085a9e40cc0cc215053c4dedaa91acee73ac /drivers | |
parent | a864ec76db575b158427ec7fa624cd30ede5e038 (diff) |
mei: add debugfs hooks
debugfs exposes device state and list of me clients and their
properties
Signed-off-by: Tomas Winkler <tomas.winkler@intel.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/misc/mei/Makefile | 1 | ||||
-rw-r--r-- | drivers/misc/mei/debugfs.c | 149 | ||||
-rw-r--r-- | drivers/misc/mei/main.c | 18 | ||||
-rw-r--r-- | drivers/misc/mei/mei_dev.h | 20 | ||||
-rw-r--r-- | drivers/misc/mei/pci-me.c | 5 |
5 files changed, 185 insertions, 8 deletions
diff --git a/drivers/misc/mei/Makefile b/drivers/misc/mei/Makefile index 1b29f7ccac49..3612d576a677 100644 --- a/drivers/misc/mei/Makefile +++ b/drivers/misc/mei/Makefile | |||
@@ -11,6 +11,7 @@ mei-objs += main.o | |||
11 | mei-objs += amthif.o | 11 | mei-objs += amthif.o |
12 | mei-objs += wd.o | 12 | mei-objs += wd.o |
13 | mei-objs += bus.o | 13 | mei-objs += bus.o |
14 | mei-$(CONFIG_DEBUG_FS) += debugfs.o | ||
14 | 15 | ||
15 | obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o | 16 | obj-$(CONFIG_INTEL_MEI_ME) += mei-me.o |
16 | mei-me-objs := pci-me.o | 17 | mei-me-objs := pci-me.o |
diff --git a/drivers/misc/mei/debugfs.c b/drivers/misc/mei/debugfs.c new file mode 100644 index 000000000000..7135a7186940 --- /dev/null +++ b/drivers/misc/mei/debugfs.c | |||
@@ -0,0 +1,149 @@ | |||
1 | /* | ||
2 | * | ||
3 | * Intel Management Engine Interface (Intel MEI) Linux driver | ||
4 | * Copyright (c) 2012-2013, Intel Corporation. | ||
5 | * | ||
6 | * This program is free software; you can redistribute it and/or modify it | ||
7 | * under the terms and conditions of the GNU General Public License, | ||
8 | * version 2, as published by the Free Software Foundation. | ||
9 | * | ||
10 | * This program is distributed in the hope it will be useful, but WITHOUT | ||
11 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
12 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | ||
13 | * more details. | ||
14 | * | ||
15 | */ | ||
16 | #include <linux/slab.h> | ||
17 | #include <linux/kernel.h> | ||
18 | #include <linux/device.h> | ||
19 | #include <linux/debugfs.h> | ||
20 | #include <linux/pci.h> | ||
21 | |||
22 | #include <linux/mei.h> | ||
23 | |||
24 | #include "mei_dev.h" | ||
25 | #include "hw.h" | ||
26 | |||
27 | static int mei_dbgfs_open(struct inode *inode, struct file *file) | ||
28 | { | ||
29 | file->private_data = inode->i_private; | ||
30 | return 0; | ||
31 | } | ||
32 | |||
33 | static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, | ||
34 | size_t cnt, loff_t *ppos) | ||
35 | { | ||
36 | struct mei_device *dev = fp->private_data; | ||
37 | struct mei_me_client *cl; | ||
38 | const size_t bufsz = 1024; | ||
39 | char *buf = kzalloc(bufsz, GFP_KERNEL); | ||
40 | int i; | ||
41 | int pos = 0; | ||
42 | int ret; | ||
43 | |||
44 | if (!buf) | ||
45 | return -ENOMEM; | ||
46 | |||
47 | pos += scnprintf(buf + pos, bufsz - pos, | ||
48 | " |id|addr| UUID |con|msg len|\n"); | ||
49 | |||
50 | mutex_lock(&dev->device_lock); | ||
51 | |||
52 | /* if the driver is not enabled the list won't b consitent */ | ||
53 | if (dev->dev_state != MEI_DEV_ENABLED) | ||
54 | goto out; | ||
55 | |||
56 | for (i = 0; i < dev->me_clients_num; i++) { | ||
57 | cl = &dev->me_clients[i]; | ||
58 | |||
59 | /* skip me clients that cannot be connected */ | ||
60 | if (cl->props.max_number_of_connections == 0) | ||
61 | continue; | ||
62 | |||
63 | pos += scnprintf(buf + pos, bufsz - pos, | ||
64 | "%2d|%2d|%4d|%pUl|%3d|%7d|\n", | ||
65 | i, cl->client_id, | ||
66 | cl->props.fixed_address, | ||
67 | &cl->props.protocol_name, | ||
68 | cl->props.max_number_of_connections, | ||
69 | cl->props.max_msg_length); | ||
70 | } | ||
71 | out: | ||
72 | mutex_unlock(&dev->device_lock); | ||
73 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); | ||
74 | kfree(buf); | ||
75 | return ret; | ||
76 | } | ||
77 | |||
78 | static const struct file_operations mei_dbgfs_fops_meclients = { | ||
79 | .open = mei_dbgfs_open, | ||
80 | .read = mei_dbgfs_read_meclients, | ||
81 | .llseek = generic_file_llseek, | ||
82 | }; | ||
83 | |||
84 | static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf, | ||
85 | size_t cnt, loff_t *ppos) | ||
86 | { | ||
87 | struct mei_device *dev = fp->private_data; | ||
88 | const size_t bufsz = 1024; | ||
89 | char *buf = kzalloc(bufsz, GFP_KERNEL); | ||
90 | int pos = 0; | ||
91 | int ret; | ||
92 | |||
93 | if (!buf) | ||
94 | return -ENOMEM; | ||
95 | |||
96 | pos += scnprintf(buf + pos, bufsz - pos, "%s\n", | ||
97 | mei_dev_state_str(dev->dev_state)); | ||
98 | ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); | ||
99 | kfree(buf); | ||
100 | return ret; | ||
101 | } | ||
102 | static const struct file_operations mei_dbgfs_fops_devstate = { | ||
103 | .open = mei_dbgfs_open, | ||
104 | .read = mei_dbgfs_read_devstate, | ||
105 | .llseek = generic_file_llseek, | ||
106 | }; | ||
107 | |||
108 | /** | ||
109 | * mei_dbgfs_deregister - Remove the debugfs files and directories | ||
110 | * @mei - pointer to mei device private dat | ||
111 | */ | ||
112 | void mei_dbgfs_deregister(struct mei_device *dev) | ||
113 | { | ||
114 | if (!dev->dbgfs_dir) | ||
115 | return; | ||
116 | debugfs_remove_recursive(dev->dbgfs_dir); | ||
117 | dev->dbgfs_dir = NULL; | ||
118 | } | ||
119 | |||
120 | /** | ||
121 | * Add the debugfs files | ||
122 | * | ||
123 | */ | ||
124 | int mei_dbgfs_register(struct mei_device *dev, const char *name) | ||
125 | { | ||
126 | struct dentry *dir, *f; | ||
127 | dir = debugfs_create_dir(name, NULL); | ||
128 | if (!dir) | ||
129 | return -ENOMEM; | ||
130 | |||
131 | f = debugfs_create_file("meclients", S_IRUSR, dir, | ||
132 | dev, &mei_dbgfs_fops_meclients); | ||
133 | if (!f) { | ||
134 | dev_err(&dev->pdev->dev, "meclients: registration failed\n"); | ||
135 | goto err; | ||
136 | } | ||
137 | f = debugfs_create_file("devstate", S_IRUSR, dir, | ||
138 | dev, &mei_dbgfs_fops_devstate); | ||
139 | if (!f) { | ||
140 | dev_err(&dev->pdev->dev, "devstate: registration failed\n"); | ||
141 | goto err; | ||
142 | } | ||
143 | dev->dbgfs_dir = dir; | ||
144 | return 0; | ||
145 | err: | ||
146 | mei_dbgfs_deregister(dev); | ||
147 | return -ENODEV; | ||
148 | } | ||
149 | |||
diff --git a/drivers/misc/mei/main.c b/drivers/misc/mei/main.c index 872de9d1494b..329fb865cfd0 100644 --- a/drivers/misc/mei/main.c +++ b/drivers/misc/mei/main.c | |||
@@ -753,15 +753,25 @@ static struct miscdevice mei_misc_device = { | |||
753 | .minor = MISC_DYNAMIC_MINOR, | 753 | .minor = MISC_DYNAMIC_MINOR, |
754 | }; | 754 | }; |
755 | 755 | ||
756 | int mei_register(struct device *dev) | 756 | |
757 | int mei_register(struct mei_device *dev) | ||
757 | { | 758 | { |
758 | mei_misc_device.parent = dev; | 759 | int ret; |
759 | return misc_register(&mei_misc_device); | 760 | mei_misc_device.parent = &dev->pdev->dev; |
761 | ret = misc_register(&mei_misc_device); | ||
762 | if (ret) | ||
763 | return ret; | ||
764 | |||
765 | if (mei_dbgfs_register(dev, mei_misc_device.name)) | ||
766 | dev_err(&dev->pdev->dev, "cannot register debugfs\n"); | ||
767 | |||
768 | return 0; | ||
760 | } | 769 | } |
761 | EXPORT_SYMBOL_GPL(mei_register); | 770 | EXPORT_SYMBOL_GPL(mei_register); |
762 | 771 | ||
763 | void mei_deregister(void) | 772 | void mei_deregister(struct mei_device *dev) |
764 | { | 773 | { |
774 | mei_dbgfs_deregister(dev); | ||
765 | misc_deregister(&mei_misc_device); | 775 | misc_deregister(&mei_misc_device); |
766 | mei_misc_device.parent = NULL; | 776 | mei_misc_device.parent = NULL; |
767 | } | 777 | } |
diff --git a/drivers/misc/mei/mei_dev.h b/drivers/misc/mei/mei_dev.h index 325f71abeb7a..8806be420f6b 100644 --- a/drivers/misc/mei/mei_dev.h +++ b/drivers/misc/mei/mei_dev.h | |||
@@ -437,6 +437,11 @@ struct mei_device { | |||
437 | /* List of bus devices */ | 437 | /* List of bus devices */ |
438 | struct list_head device_list; | 438 | struct list_head device_list; |
439 | 439 | ||
440 | #if IS_ENABLED(CONFIG_DEBUG_FS) | ||
441 | struct dentry *dbgfs_dir; | ||
442 | #endif /* CONFIG_DEBUG_FS */ | ||
443 | |||
444 | |||
440 | const struct mei_hw_ops *ops; | 445 | const struct mei_hw_ops *ops; |
441 | char hw[0] __aligned(sizeof(void *)); | 446 | char hw[0] __aligned(sizeof(void *)); |
442 | }; | 447 | }; |
@@ -603,8 +608,19 @@ static inline int mei_count_full_read_slots(struct mei_device *dev) | |||
603 | return dev->ops->rdbuf_full_slots(dev); | 608 | return dev->ops->rdbuf_full_slots(dev); |
604 | } | 609 | } |
605 | 610 | ||
606 | int mei_register(struct device *dev); | 611 | #if IS_ENABLED(CONFIG_DEBUG_FS) |
607 | void mei_deregister(void); | 612 | int mei_dbgfs_register(struct mei_device *dev, const char *name); |
613 | void mei_dbgfs_deregister(struct mei_device *dev); | ||
614 | #else | ||
615 | static inline int mei_dbgfs_register(struct mei_device *dev, const char *name) | ||
616 | { | ||
617 | return 0; | ||
618 | } | ||
619 | static inline void mei_dbgfs_deregister(struct mei_device *dev) {} | ||
620 | #endif /* CONFIG_DEBUG_FS */ | ||
621 | |||
622 | int mei_register(struct mei_device *dev); | ||
623 | void mei_deregister(struct mei_device *dev); | ||
608 | 624 | ||
609 | #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d" | 625 | #define MEI_HDR_FMT "hdr:host=%02d me=%02d len=%d comp=%1d" |
610 | #define MEI_HDR_PRM(hdr) \ | 626 | #define MEI_HDR_PRM(hdr) \ |
diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c index a1a582b66f0d..88aec6a90ff4 100644 --- a/drivers/misc/mei/pci-me.c +++ b/drivers/misc/mei/pci-me.c | |||
@@ -190,7 +190,7 @@ static int mei_me_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | |||
190 | goto release_irq; | 190 | goto release_irq; |
191 | } | 191 | } |
192 | 192 | ||
193 | err = mei_register(&pdev->dev); | 193 | err = mei_register(dev); |
194 | if (err) | 194 | if (err) |
195 | goto release_irq; | 195 | goto release_irq; |
196 | 196 | ||
@@ -262,12 +262,13 @@ static void mei_me_remove(struct pci_dev *pdev) | |||
262 | if (hw->mem_addr) | 262 | if (hw->mem_addr) |
263 | pci_iounmap(pdev, hw->mem_addr); | 263 | pci_iounmap(pdev, hw->mem_addr); |
264 | 264 | ||
265 | mei_deregister(dev); | ||
266 | |||
265 | kfree(dev); | 267 | kfree(dev); |
266 | 268 | ||
267 | pci_release_regions(pdev); | 269 | pci_release_regions(pdev); |
268 | pci_disable_device(pdev); | 270 | pci_disable_device(pdev); |
269 | 271 | ||
270 | mei_deregister(); | ||
271 | 272 | ||
272 | } | 273 | } |
273 | #ifdef CONFIG_PM | 274 | #ifdef CONFIG_PM |