1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2012-2016, Intel Corporation. All rights reserved
4 * Intel Management Engine Interface (Intel MEI) Linux driver
7 #include <linux/slab.h>
8 #include <linux/kernel.h>
9 #include <linux/device.h>
10 #include <linux/debugfs.h>
12 #include <linux/mei.h>
18 static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
19 size_t cnt, loff_t *ppos)
21 struct mei_device *dev = fp->private_data;
22 struct mei_me_client *me_cl;
30 " |id|fix| UUID |con|msg len|sb|refc|\n"
32 down_read(&dev->me_clients_rwsem);
33 list_for_each_entry(me_cl, &dev->me_clients, list)
36 bufsz *= sizeof(HDR) + 1;
37 buf = kzalloc(bufsz, GFP_KERNEL);
39 up_read(&dev->me_clients_rwsem);
43 pos += scnprintf(buf + pos, bufsz - pos, HDR);
46 /* if the driver is not enabled the list won't be consistent */
47 if (dev->dev_state != MEI_DEV_ENABLED)
50 list_for_each_entry(me_cl, &dev->me_clients, list) {
52 if (mei_me_cl_get(me_cl)) {
53 pos += scnprintf(buf + pos, bufsz - pos,
54 "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
55 i++, me_cl->client_id,
56 me_cl->props.fixed_address,
57 &me_cl->props.protocol_name,
58 me_cl->props.max_number_of_connections,
59 me_cl->props.max_msg_length,
60 me_cl->props.single_recv_buf,
61 kref_read(&me_cl->refcnt));
68 up_read(&dev->me_clients_rwsem);
69 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
74 static const struct file_operations mei_dbgfs_fops_meclients = {
76 .read = mei_dbgfs_read_meclients,
77 .llseek = generic_file_llseek,
80 static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf,
81 size_t cnt, loff_t *ppos)
83 struct mei_device *dev = fp->private_data;
91 #define HDR " |me|host|state|rd|wr|wrq\n"
96 mutex_lock(&dev->device_lock);
99 * if the driver is not enabled the list won't be consistent,
100 * we output empty table
102 if (dev->dev_state == MEI_DEV_ENABLED)
103 list_for_each_entry(cl, &dev->file_list, link)
106 bufsz *= sizeof(HDR) + 1;
108 buf = kzalloc(bufsz, GFP_KERNEL);
110 mutex_unlock(&dev->device_lock);
114 pos += scnprintf(buf + pos, bufsz - pos, HDR);
117 /* if the driver is not enabled the list won't be consistent */
118 if (dev->dev_state != MEI_DEV_ENABLED)
121 list_for_each_entry(cl, &dev->file_list, link) {
123 pos += scnprintf(buf + pos, bufsz - pos,
124 "%3d|%2d|%4d|%5d|%2d|%2d|%3u\n",
125 i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
126 !list_empty(&cl->rd_completed), cl->writing_state,
131 mutex_unlock(&dev->device_lock);
132 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
137 static const struct file_operations mei_dbgfs_fops_active = {
139 .read = mei_dbgfs_read_active,
140 .llseek = generic_file_llseek,
143 static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
144 size_t cnt, loff_t *ppos)
146 struct mei_device *dev = fp->private_data;
147 const size_t bufsz = 1024;
148 char *buf = kzalloc(bufsz, GFP_KERNEL);
155 pos += scnprintf(buf + pos, bufsz - pos, "dev: %s\n",
156 mei_dev_state_str(dev->dev_state));
157 pos += scnprintf(buf + pos, bufsz - pos, "hbm: %s\n",
158 mei_hbm_state_str(dev->hbm_state));
160 if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS &&
161 dev->hbm_state <= MEI_HBM_STARTED) {
162 pos += scnprintf(buf + pos, bufsz - pos, "hbm features:\n");
163 pos += scnprintf(buf + pos, bufsz - pos, "\tPG: %01d\n",
164 dev->hbm_f_pg_supported);
165 pos += scnprintf(buf + pos, bufsz - pos, "\tDC: %01d\n",
166 dev->hbm_f_dc_supported);
167 pos += scnprintf(buf + pos, bufsz - pos, "\tIE: %01d\n",
168 dev->hbm_f_ie_supported);
169 pos += scnprintf(buf + pos, bufsz - pos, "\tDOT: %01d\n",
170 dev->hbm_f_dot_supported);
171 pos += scnprintf(buf + pos, bufsz - pos, "\tEV: %01d\n",
172 dev->hbm_f_ev_supported);
173 pos += scnprintf(buf + pos, bufsz - pos, "\tFA: %01d\n",
174 dev->hbm_f_fa_supported);
175 pos += scnprintf(buf + pos, bufsz - pos, "\tOS: %01d\n",
176 dev->hbm_f_os_supported);
177 pos += scnprintf(buf + pos, bufsz - pos, "\tDR: %01d\n",
178 dev->hbm_f_dr_supported);
181 pos += scnprintf(buf + pos, bufsz - pos, "pg: %s, %s\n",
182 mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
183 mei_pg_state_str(mei_pg_state(dev)));
184 ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos);
188 static const struct file_operations mei_dbgfs_fops_devstate = {
190 .read = mei_dbgfs_read_devstate,
191 .llseek = generic_file_llseek,
194 static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
195 const char __user *user_buf,
196 size_t count, loff_t *ppos)
198 struct mei_device *dev;
201 dev = container_of(file->private_data,
202 struct mei_device, allow_fixed_address);
204 ret = debugfs_write_file_bool(file, user_buf, count, ppos);
207 dev->override_fixed_address = true;
211 static const struct file_operations mei_dbgfs_fops_allow_fa = {
213 .read = debugfs_read_file_bool,
214 .write = mei_dbgfs_write_allow_fa,
215 .llseek = generic_file_llseek,
219 * mei_dbgfs_deregister - Remove the debugfs files and directories
221 * @dev: the mei device structure
223 void mei_dbgfs_deregister(struct mei_device *dev)
227 debugfs_remove_recursive(dev->dbgfs_dir);
228 dev->dbgfs_dir = NULL;
232 * mei_dbgfs_register - Add the debugfs files
234 * @dev: the mei device structure
235 * @name: the mei device name
237 void mei_dbgfs_register(struct mei_device *dev, const char *name)
241 dir = debugfs_create_dir(name, NULL);
242 dev->dbgfs_dir = dir;
244 debugfs_create_file("meclients", S_IRUSR, dir, dev,
245 &mei_dbgfs_fops_meclients);
246 debugfs_create_file("active", S_IRUSR, dir, dev,
247 &mei_dbgfs_fops_active);
248 debugfs_create_file("devstate", S_IRUSR, dir, dev,
249 &mei_dbgfs_fops_devstate);
250 debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
251 &dev->allow_fixed_address,
252 &mei_dbgfs_fops_allow_fa);