xref: /OK3568_Linux_fs/kernel/drivers/misc/mei/debugfs.c (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Copyright (c) 2012-2016, Intel Corporation. All rights reserved
4*4882a593Smuzhiyun  * Intel Management Engine Interface (Intel MEI) Linux driver
5*4882a593Smuzhiyun  */
6*4882a593Smuzhiyun 
7*4882a593Smuzhiyun #include <linux/slab.h>
8*4882a593Smuzhiyun #include <linux/kernel.h>
9*4882a593Smuzhiyun #include <linux/device.h>
10*4882a593Smuzhiyun #include <linux/debugfs.h>
11*4882a593Smuzhiyun #include <linux/seq_file.h>
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #include <linux/mei.h>
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun #include "mei_dev.h"
16*4882a593Smuzhiyun #include "client.h"
17*4882a593Smuzhiyun #include "hw.h"
18*4882a593Smuzhiyun 
mei_dbgfs_meclients_show(struct seq_file * m,void * unused)19*4882a593Smuzhiyun static int mei_dbgfs_meclients_show(struct seq_file *m, void *unused)
20*4882a593Smuzhiyun {
21*4882a593Smuzhiyun 	struct mei_device *dev = m->private;
22*4882a593Smuzhiyun 	struct mei_me_client *me_cl;
23*4882a593Smuzhiyun 	int i = 0;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun 	if (!dev)
26*4882a593Smuzhiyun 		return -ENODEV;
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun 	down_read(&dev->me_clients_rwsem);
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun 	seq_puts(m, "  |id|fix|         UUID                       |con|msg len|sb|refc|vt|\n");
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun 	/*  if the driver is not enabled the list won't be consistent */
33*4882a593Smuzhiyun 	if (dev->dev_state != MEI_DEV_ENABLED)
34*4882a593Smuzhiyun 		goto out;
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	list_for_each_entry(me_cl, &dev->me_clients, list) {
37*4882a593Smuzhiyun 		if (!mei_me_cl_get(me_cl))
38*4882a593Smuzhiyun 			continue;
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 		seq_printf(m, "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|%2d|\n",
41*4882a593Smuzhiyun 			   i++, me_cl->client_id,
42*4882a593Smuzhiyun 			   me_cl->props.fixed_address,
43*4882a593Smuzhiyun 			   &me_cl->props.protocol_name,
44*4882a593Smuzhiyun 			   me_cl->props.max_number_of_connections,
45*4882a593Smuzhiyun 			   me_cl->props.max_msg_length,
46*4882a593Smuzhiyun 			   me_cl->props.single_recv_buf,
47*4882a593Smuzhiyun 			   kref_read(&me_cl->refcnt),
48*4882a593Smuzhiyun 			   me_cl->props.vt_supported);
49*4882a593Smuzhiyun 		mei_me_cl_put(me_cl);
50*4882a593Smuzhiyun 	}
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun out:
53*4882a593Smuzhiyun 	up_read(&dev->me_clients_rwsem);
54*4882a593Smuzhiyun 	return 0;
55*4882a593Smuzhiyun }
56*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_meclients);
57*4882a593Smuzhiyun 
mei_dbgfs_active_show(struct seq_file * m,void * unused)58*4882a593Smuzhiyun static int mei_dbgfs_active_show(struct seq_file *m, void *unused)
59*4882a593Smuzhiyun {
60*4882a593Smuzhiyun 	struct mei_device *dev = m->private;
61*4882a593Smuzhiyun 	struct mei_cl *cl;
62*4882a593Smuzhiyun 	int i = 0;
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun 	if (!dev)
65*4882a593Smuzhiyun 		return -ENODEV;
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun 	mutex_lock(&dev->device_lock);
68*4882a593Smuzhiyun 
69*4882a593Smuzhiyun 	seq_puts(m, "   |me|host|state|rd|wr|wrq\n");
70*4882a593Smuzhiyun 
71*4882a593Smuzhiyun 	/*  if the driver is not enabled the list won't be consistent */
72*4882a593Smuzhiyun 	if (dev->dev_state != MEI_DEV_ENABLED)
73*4882a593Smuzhiyun 		goto out;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	list_for_each_entry(cl, &dev->file_list, link) {
76*4882a593Smuzhiyun 
77*4882a593Smuzhiyun 		seq_printf(m, "%3d|%2d|%4d|%5d|%2d|%2d|%3u\n",
78*4882a593Smuzhiyun 			   i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
79*4882a593Smuzhiyun 			   !list_empty(&cl->rd_completed), cl->writing_state,
80*4882a593Smuzhiyun 			   cl->tx_cb_queued);
81*4882a593Smuzhiyun 		i++;
82*4882a593Smuzhiyun 	}
83*4882a593Smuzhiyun out:
84*4882a593Smuzhiyun 	mutex_unlock(&dev->device_lock);
85*4882a593Smuzhiyun 	return 0;
86*4882a593Smuzhiyun }
87*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_active);
88*4882a593Smuzhiyun 
mei_dbgfs_devstate_show(struct seq_file * m,void * unused)89*4882a593Smuzhiyun static int mei_dbgfs_devstate_show(struct seq_file *m, void *unused)
90*4882a593Smuzhiyun {
91*4882a593Smuzhiyun 	struct mei_device *dev = m->private;
92*4882a593Smuzhiyun 
93*4882a593Smuzhiyun 	seq_printf(m, "dev: %s\n", mei_dev_state_str(dev->dev_state));
94*4882a593Smuzhiyun 	seq_printf(m, "hbm: %s\n", mei_hbm_state_str(dev->hbm_state));
95*4882a593Smuzhiyun 
96*4882a593Smuzhiyun 	if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS &&
97*4882a593Smuzhiyun 	    dev->hbm_state <= MEI_HBM_STARTED) {
98*4882a593Smuzhiyun 		seq_puts(m, "hbm features:\n");
99*4882a593Smuzhiyun 		seq_printf(m, "\tPG: %01d\n", dev->hbm_f_pg_supported);
100*4882a593Smuzhiyun 		seq_printf(m, "\tDC: %01d\n", dev->hbm_f_dc_supported);
101*4882a593Smuzhiyun 		seq_printf(m, "\tIE: %01d\n", dev->hbm_f_ie_supported);
102*4882a593Smuzhiyun 		seq_printf(m, "\tDOT: %01d\n", dev->hbm_f_dot_supported);
103*4882a593Smuzhiyun 		seq_printf(m, "\tEV: %01d\n", dev->hbm_f_ev_supported);
104*4882a593Smuzhiyun 		seq_printf(m, "\tFA: %01d\n", dev->hbm_f_fa_supported);
105*4882a593Smuzhiyun 		seq_printf(m, "\tOS: %01d\n", dev->hbm_f_os_supported);
106*4882a593Smuzhiyun 		seq_printf(m, "\tDR: %01d\n", dev->hbm_f_dr_supported);
107*4882a593Smuzhiyun 		seq_printf(m, "\tVT: %01d\n", dev->hbm_f_vt_supported);
108*4882a593Smuzhiyun 		seq_printf(m, "\tCAP: %01d\n", dev->hbm_f_cap_supported);
109*4882a593Smuzhiyun 	}
110*4882a593Smuzhiyun 
111*4882a593Smuzhiyun 	seq_printf(m, "pg:  %s, %s\n",
112*4882a593Smuzhiyun 		   mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
113*4882a593Smuzhiyun 		   mei_pg_state_str(mei_pg_state(dev)));
114*4882a593Smuzhiyun 	return 0;
115*4882a593Smuzhiyun }
116*4882a593Smuzhiyun DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_devstate);
117*4882a593Smuzhiyun 
mei_dbgfs_write_allow_fa(struct file * file,const char __user * user_buf,size_t count,loff_t * ppos)118*4882a593Smuzhiyun static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
119*4882a593Smuzhiyun 					const char __user *user_buf,
120*4882a593Smuzhiyun 					size_t count, loff_t *ppos)
121*4882a593Smuzhiyun {
122*4882a593Smuzhiyun 	struct mei_device *dev;
123*4882a593Smuzhiyun 	int ret;
124*4882a593Smuzhiyun 
125*4882a593Smuzhiyun 	dev = container_of(file->private_data,
126*4882a593Smuzhiyun 			   struct mei_device, allow_fixed_address);
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	ret = debugfs_write_file_bool(file, user_buf, count, ppos);
129*4882a593Smuzhiyun 	if (ret < 0)
130*4882a593Smuzhiyun 		return ret;
131*4882a593Smuzhiyun 	dev->override_fixed_address = true;
132*4882a593Smuzhiyun 	return ret;
133*4882a593Smuzhiyun }
134*4882a593Smuzhiyun 
135*4882a593Smuzhiyun static const struct file_operations mei_dbgfs_allow_fa_fops = {
136*4882a593Smuzhiyun 	.open = simple_open,
137*4882a593Smuzhiyun 	.read = debugfs_read_file_bool,
138*4882a593Smuzhiyun 	.write = mei_dbgfs_write_allow_fa,
139*4882a593Smuzhiyun 	.llseek = generic_file_llseek,
140*4882a593Smuzhiyun };
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun /**
143*4882a593Smuzhiyun  * mei_dbgfs_deregister - Remove the debugfs files and directories
144*4882a593Smuzhiyun  *
145*4882a593Smuzhiyun  * @dev: the mei device structure
146*4882a593Smuzhiyun  */
mei_dbgfs_deregister(struct mei_device * dev)147*4882a593Smuzhiyun void mei_dbgfs_deregister(struct mei_device *dev)
148*4882a593Smuzhiyun {
149*4882a593Smuzhiyun 	if (!dev->dbgfs_dir)
150*4882a593Smuzhiyun 		return;
151*4882a593Smuzhiyun 	debugfs_remove_recursive(dev->dbgfs_dir);
152*4882a593Smuzhiyun 	dev->dbgfs_dir = NULL;
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun /**
156*4882a593Smuzhiyun  * mei_dbgfs_register - Add the debugfs files
157*4882a593Smuzhiyun  *
158*4882a593Smuzhiyun  * @dev: the mei device structure
159*4882a593Smuzhiyun  * @name: the mei device name
160*4882a593Smuzhiyun  */
mei_dbgfs_register(struct mei_device * dev,const char * name)161*4882a593Smuzhiyun void mei_dbgfs_register(struct mei_device *dev, const char *name)
162*4882a593Smuzhiyun {
163*4882a593Smuzhiyun 	struct dentry *dir;
164*4882a593Smuzhiyun 
165*4882a593Smuzhiyun 	dir = debugfs_create_dir(name, NULL);
166*4882a593Smuzhiyun 	dev->dbgfs_dir = dir;
167*4882a593Smuzhiyun 
168*4882a593Smuzhiyun 	debugfs_create_file("meclients", S_IRUSR, dir, dev,
169*4882a593Smuzhiyun 			    &mei_dbgfs_meclients_fops);
170*4882a593Smuzhiyun 	debugfs_create_file("active", S_IRUSR, dir, dev,
171*4882a593Smuzhiyun 			    &mei_dbgfs_active_fops);
172*4882a593Smuzhiyun 	debugfs_create_file("devstate", S_IRUSR, dir, dev,
173*4882a593Smuzhiyun 			    &mei_dbgfs_devstate_fops);
174*4882a593Smuzhiyun 	debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
175*4882a593Smuzhiyun 			    &dev->allow_fixed_address,
176*4882a593Smuzhiyun 			    &mei_dbgfs_allow_fa_fops);
177*4882a593Smuzhiyun }
178