blob: a26c716c61a121fcd299fb858ff62f8b1982fe64 [file] [log] [blame]
David Brazdil0f672f62019-12-10 10:32:29 +00001// SPDX-License-Identifier: GPL-2.0
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00002/*
David Brazdil0f672f62019-12-10 10:32:29 +00003 * Copyright (c) 2012-2016, Intel Corporation. All rights reserved
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00004 * Intel Management Engine Interface (Intel MEI) Linux driver
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00005 */
David Brazdil0f672f62019-12-10 10:32:29 +00006
Andrew Scullb4b6d4a2019-01-02 15:54:55 +00007#include <linux/slab.h>
8#include <linux/kernel.h>
9#include <linux/device.h>
10#include <linux/debugfs.h>
David Brazdil0f672f62019-12-10 10:32:29 +000011#include <linux/seq_file.h>
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000012
13#include <linux/mei.h>
14
15#include "mei_dev.h"
16#include "client.h"
17#include "hw.h"
18
David Brazdil0f672f62019-12-10 10:32:29 +000019static int mei_dbgfs_meclients_show(struct seq_file *m, void *unused)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000020{
David Brazdil0f672f62019-12-10 10:32:29 +000021 struct mei_device *dev = m->private;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000022 struct mei_me_client *me_cl;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000023 int i = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000024
David Brazdil0f672f62019-12-10 10:32:29 +000025 if (!dev)
26 return -ENODEV;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000027
28 down_read(&dev->me_clients_rwsem);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000029
David Brazdil0f672f62019-12-10 10:32:29 +000030 seq_puts(m, " |id|fix| UUID |con|msg len|sb|refc|\n");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000031
32 /* if the driver is not enabled the list won't be consistent */
33 if (dev->dev_state != MEI_DEV_ENABLED)
34 goto out;
35
36 list_for_each_entry(me_cl, &dev->me_clients, list) {
David Brazdil0f672f62019-12-10 10:32:29 +000037 if (!mei_me_cl_get(me_cl))
38 continue;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000039
David Brazdil0f672f62019-12-10 10:32:29 +000040 seq_printf(m, "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
41 i++, me_cl->client_id,
42 me_cl->props.fixed_address,
43 &me_cl->props.protocol_name,
44 me_cl->props.max_number_of_connections,
45 me_cl->props.max_msg_length,
46 me_cl->props.single_recv_buf,
47 kref_read(&me_cl->refcnt));
48 mei_me_cl_put(me_cl);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000049 }
50
51out:
52 up_read(&dev->me_clients_rwsem);
David Brazdil0f672f62019-12-10 10:32:29 +000053 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000054}
David Brazdil0f672f62019-12-10 10:32:29 +000055DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_meclients);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000056
David Brazdil0f672f62019-12-10 10:32:29 +000057static int mei_dbgfs_active_show(struct seq_file *m, void *unused)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000058{
David Brazdil0f672f62019-12-10 10:32:29 +000059 struct mei_device *dev = m->private;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000060 struct mei_cl *cl;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000061 int i = 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000062
63 if (!dev)
64 return -ENODEV;
65
66 mutex_lock(&dev->device_lock);
67
David Brazdil0f672f62019-12-10 10:32:29 +000068 seq_puts(m, " |me|host|state|rd|wr|wrq\n");
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000069
70 /* if the driver is not enabled the list won't be consistent */
71 if (dev->dev_state != MEI_DEV_ENABLED)
72 goto out;
73
74 list_for_each_entry(cl, &dev->file_list, link) {
75
David Brazdil0f672f62019-12-10 10:32:29 +000076 seq_printf(m, "%3d|%2d|%4d|%5d|%2d|%2d|%3u\n",
77 i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
78 !list_empty(&cl->rd_completed), cl->writing_state,
79 cl->tx_cb_queued);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000080 i++;
81 }
82out:
83 mutex_unlock(&dev->device_lock);
David Brazdil0f672f62019-12-10 10:32:29 +000084 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000085}
David Brazdil0f672f62019-12-10 10:32:29 +000086DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_active);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000087
David Brazdil0f672f62019-12-10 10:32:29 +000088static int mei_dbgfs_devstate_show(struct seq_file *m, void *unused)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000089{
David Brazdil0f672f62019-12-10 10:32:29 +000090 struct mei_device *dev = m->private;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000091
David Brazdil0f672f62019-12-10 10:32:29 +000092 seq_printf(m, "dev: %s\n", mei_dev_state_str(dev->dev_state));
93 seq_printf(m, "hbm: %s\n", mei_hbm_state_str(dev->hbm_state));
Andrew Scullb4b6d4a2019-01-02 15:54:55 +000094
95 if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS &&
96 dev->hbm_state <= MEI_HBM_STARTED) {
David Brazdil0f672f62019-12-10 10:32:29 +000097 seq_puts(m, "hbm features:\n");
98 seq_printf(m, "\tPG: %01d\n", dev->hbm_f_pg_supported);
99 seq_printf(m, "\tDC: %01d\n", dev->hbm_f_dc_supported);
100 seq_printf(m, "\tIE: %01d\n", dev->hbm_f_ie_supported);
101 seq_printf(m, "\tDOT: %01d\n", dev->hbm_f_dot_supported);
102 seq_printf(m, "\tEV: %01d\n", dev->hbm_f_ev_supported);
103 seq_printf(m, "\tFA: %01d\n", dev->hbm_f_fa_supported);
104 seq_printf(m, "\tOS: %01d\n", dev->hbm_f_os_supported);
105 seq_printf(m, "\tDR: %01d\n", dev->hbm_f_dr_supported);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000106 }
107
David Brazdil0f672f62019-12-10 10:32:29 +0000108 seq_printf(m, "pg: %s, %s\n",
109 mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
110 mei_pg_state_str(mei_pg_state(dev)));
111 return 0;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000112}
David Brazdil0f672f62019-12-10 10:32:29 +0000113DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_devstate);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000114
115static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
116 const char __user *user_buf,
117 size_t count, loff_t *ppos)
118{
119 struct mei_device *dev;
120 int ret;
121
122 dev = container_of(file->private_data,
123 struct mei_device, allow_fixed_address);
124
125 ret = debugfs_write_file_bool(file, user_buf, count, ppos);
126 if (ret < 0)
127 return ret;
128 dev->override_fixed_address = true;
129 return ret;
130}
131
David Brazdil0f672f62019-12-10 10:32:29 +0000132static const struct file_operations mei_dbgfs_allow_fa_fops = {
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000133 .open = simple_open,
134 .read = debugfs_read_file_bool,
135 .write = mei_dbgfs_write_allow_fa,
136 .llseek = generic_file_llseek,
137};
138
139/**
140 * mei_dbgfs_deregister - Remove the debugfs files and directories
141 *
142 * @dev: the mei device structure
143 */
144void mei_dbgfs_deregister(struct mei_device *dev)
145{
146 if (!dev->dbgfs_dir)
147 return;
148 debugfs_remove_recursive(dev->dbgfs_dir);
149 dev->dbgfs_dir = NULL;
150}
151
152/**
153 * mei_dbgfs_register - Add the debugfs files
154 *
155 * @dev: the mei device structure
156 * @name: the mei device name
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000157 */
David Brazdil0f672f62019-12-10 10:32:29 +0000158void mei_dbgfs_register(struct mei_device *dev, const char *name)
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000159{
David Brazdil0f672f62019-12-10 10:32:29 +0000160 struct dentry *dir;
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000161
162 dir = debugfs_create_dir(name, NULL);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000163 dev->dbgfs_dir = dir;
164
David Brazdil0f672f62019-12-10 10:32:29 +0000165 debugfs_create_file("meclients", S_IRUSR, dir, dev,
166 &mei_dbgfs_meclients_fops);
167 debugfs_create_file("active", S_IRUSR, dir, dev,
168 &mei_dbgfs_active_fops);
169 debugfs_create_file("devstate", S_IRUSR, dir, dev,
170 &mei_dbgfs_devstate_fops);
171 debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
172 &dev->allow_fixed_address,
173 &mei_dbgfs_allow_fa_fops);
Andrew Scullb4b6d4a2019-01-02 15:54:55 +0000174}