Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

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