blob: 2399b3181e6c431409040bd2293cfde2bfc13438 [file] [log] [blame]
Tomas Winkler30e53bb2013-04-05 22:10:34 +03001/*
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
Tomas Winkler30e53bb2013-04-05 22:10:34 +030027static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
28 size_t cnt, loff_t *ppos)
29{
30 struct mei_device *dev = fp->private_data;
Tomas Winkler5ca2d382014-08-21 14:29:13 +030031 struct mei_me_client *me_cl;
Tomas Winkler30e53bb2013-04-05 22:10:34 +030032 const size_t bufsz = 1024;
33 char *buf = kzalloc(bufsz, GFP_KERNEL);
Tomas Winkler5ca2d382014-08-21 14:29:13 +030034 int i = 0;
Tomas Winkler30e53bb2013-04-05 22:10:34 +030035 int pos = 0;
36 int ret;
37
38 if (!buf)
39 return -ENOMEM;
40
41 pos += scnprintf(buf + pos, bufsz - pos,
42 " |id|addr| UUID |con|msg len|\n");
43
44 mutex_lock(&dev->device_lock);
45
Alexander Usyskin83ce0742014-01-08 22:31:46 +020046 /* if the driver is not enabled the list won't be consistent */
Tomas Winkler30e53bb2013-04-05 22:10:34 +030047 if (dev->dev_state != MEI_DEV_ENABLED)
48 goto out;
49
Tomas Winkler5ca2d382014-08-21 14:29:13 +030050 list_for_each_entry(me_cl, &dev->me_clients, list) {
Tomas Winkler30e53bb2013-04-05 22:10:34 +030051
52 /* skip me clients that cannot be connected */
Tomas Winkler5ca2d382014-08-21 14:29:13 +030053 if (me_cl->props.max_number_of_connections == 0)
Tomas Winkler30e53bb2013-04-05 22:10:34 +030054 continue;
55
56 pos += scnprintf(buf + pos, bufsz - pos,
57 "%2d|%2d|%4d|%pUl|%3d|%7d|\n",
Tomas Winkler5ca2d382014-08-21 14:29:13 +030058 i++, me_cl->client_id,
59 me_cl->props.fixed_address,
60 &me_cl->props.protocol_name,
61 me_cl->props.max_number_of_connections,
62 me_cl->props.max_msg_length);
Tomas Winkler30e53bb2013-04-05 22:10:34 +030063 }
64out:
65 mutex_unlock(&dev->device_lock);
66 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
67 kfree(buf);
68 return ret;
69}
70
71static const struct file_operations mei_dbgfs_fops_meclients = {
Wei Yongjuna42f82f2013-04-09 14:30:19 +080072 .open = simple_open,
Tomas Winkler30e53bb2013-04-05 22:10:34 +030073 .read = mei_dbgfs_read_meclients,
74 .llseek = generic_file_llseek,
75};
76
Tomas Winkler5baaf712014-01-14 23:21:41 +020077static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf,
78 size_t cnt, loff_t *ppos)
79{
80 struct mei_device *dev = fp->private_data;
81 struct mei_cl *cl;
82 const size_t bufsz = 1024;
83 char *buf;
84 int i = 0;
85 int pos = 0;
86 int ret;
87
88 if (!dev)
89 return -ENODEV;
90
91 buf = kzalloc(bufsz, GFP_KERNEL);
92 if (!buf)
93 return -ENOMEM;
94
95 pos += scnprintf(buf + pos, bufsz - pos,
96 " |me|host|state|rd|wr|\n");
97
98 mutex_lock(&dev->device_lock);
99
100 /* if the driver is not enabled the list won't b consitent */
101 if (dev->dev_state != MEI_DEV_ENABLED)
102 goto out;
103
104 list_for_each_entry(cl, &dev->file_list, link) {
105
106 pos += scnprintf(buf + pos, bufsz - pos,
107 "%2d|%2d|%4d|%5d|%2d|%2d|\n",
108 i, cl->me_client_id, cl->host_client_id, cl->state,
109 cl->reading_state, cl->writing_state);
110 i++;
111 }
112out:
113 mutex_unlock(&dev->device_lock);
114 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
115 kfree(buf);
116 return ret;
117}
118
119static const struct file_operations mei_dbgfs_fops_active = {
120 .open = simple_open,
121 .read = mei_dbgfs_read_active,
122 .llseek = generic_file_llseek,
123};
124
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300125static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
126 size_t cnt, loff_t *ppos)
127{
128 struct mei_device *dev = fp->private_data;
129 const size_t bufsz = 1024;
130 char *buf = kzalloc(bufsz, GFP_KERNEL);
131 int pos = 0;
132 int ret;
133
134 if (!buf)
135 return -ENOMEM;
136
Alexander Usyskin1beeb4b2014-09-29 16:31:33 +0300137 pos += scnprintf(buf + pos, bufsz - pos, "dev: %s\n",
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300138 mei_dev_state_str(dev->dev_state));
Alexander Usyskin1beeb4b2014-09-29 16:31:33 +0300139 pos += scnprintf(buf + pos, bufsz - pos, "hbm: %s\n",
140 mei_hbm_state_str(dev->hbm_state));
141 pos += scnprintf(buf + pos, bufsz - pos, "pg: %s, %s\n",
142 mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
143 mei_pg_state_str(mei_pg_state(dev)));
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300144 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
145 kfree(buf);
146 return ret;
147}
148static const struct file_operations mei_dbgfs_fops_devstate = {
Wei Yongjuna42f82f2013-04-09 14:30:19 +0800149 .open = simple_open,
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300150 .read = mei_dbgfs_read_devstate,
151 .llseek = generic_file_llseek,
152};
153
154/**
155 * mei_dbgfs_deregister - Remove the debugfs files and directories
Alexander Usyskin83ce0742014-01-08 22:31:46 +0200156 * @mei - pointer to mei device private data
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300157 */
158void mei_dbgfs_deregister(struct mei_device *dev)
159{
160 if (!dev->dbgfs_dir)
161 return;
162 debugfs_remove_recursive(dev->dbgfs_dir);
163 dev->dbgfs_dir = NULL;
164}
165
166/**
167 * Add the debugfs files
168 *
169 */
170int mei_dbgfs_register(struct mei_device *dev, const char *name)
171{
172 struct dentry *dir, *f;
173 dir = debugfs_create_dir(name, NULL);
174 if (!dir)
175 return -ENOMEM;
176
177 f = debugfs_create_file("meclients", S_IRUSR, dir,
178 dev, &mei_dbgfs_fops_meclients);
179 if (!f) {
180 dev_err(&dev->pdev->dev, "meclients: registration failed\n");
181 goto err;
182 }
Tomas Winkler5baaf712014-01-14 23:21:41 +0200183 f = debugfs_create_file("active", S_IRUSR, dir,
184 dev, &mei_dbgfs_fops_active);
185 if (!f) {
186 dev_err(&dev->pdev->dev, "meclients: registration failed\n");
187 goto err;
188 }
Tomas Winkler30e53bb2013-04-05 22:10:34 +0300189 f = debugfs_create_file("devstate", S_IRUSR, dir,
190 dev, &mei_dbgfs_fops_devstate);
191 if (!f) {
192 dev_err(&dev->pdev->dev, "devstate: registration failed\n");
193 goto err;
194 }
195 dev->dbgfs_dir = dir;
196 return 0;
197err:
198 mei_dbgfs_deregister(dev);
199 return -ENODEV;
200}
201