Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (c) 2012-2016, Intel Corporation. All rights reserved
0004  * Intel Management Engine Interface (Intel MEI) Linux driver
0005  */
0006 
0007 #include <linux/slab.h>
0008 #include <linux/kernel.h>
0009 #include <linux/device.h>
0010 #include <linux/debugfs.h>
0011 #include <linux/seq_file.h>
0012 
0013 #include <linux/mei.h>
0014 
0015 #include "mei_dev.h"
0016 #include "client.h"
0017 #include "hw.h"
0018 
0019 static int mei_dbgfs_meclients_show(struct seq_file *m, void *unused)
0020 {
0021     struct mei_device *dev = m->private;
0022     struct mei_me_client *me_cl;
0023     int i = 0;
0024 
0025     if (!dev)
0026         return -ENODEV;
0027 
0028     down_read(&dev->me_clients_rwsem);
0029 
0030     seq_puts(m, "  |id|fix|         UUID                       |con|msg len|sb|refc|vt|\n");
0031 
0032     /*  if the driver is not enabled the list won't be consistent */
0033     if (dev->dev_state != MEI_DEV_ENABLED)
0034         goto out;
0035 
0036     list_for_each_entry(me_cl, &dev->me_clients, list) {
0037         if (!mei_me_cl_get(me_cl))
0038             continue;
0039 
0040         seq_printf(m, "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|%2d|\n",
0041                i++, me_cl->client_id,
0042                me_cl->props.fixed_address,
0043                &me_cl->props.protocol_name,
0044                me_cl->props.max_number_of_connections,
0045                me_cl->props.max_msg_length,
0046                me_cl->props.single_recv_buf,
0047                kref_read(&me_cl->refcnt),
0048                me_cl->props.vt_supported);
0049         mei_me_cl_put(me_cl);
0050     }
0051 
0052 out:
0053     up_read(&dev->me_clients_rwsem);
0054     return 0;
0055 }
0056 DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_meclients);
0057 
0058 static int mei_dbgfs_active_show(struct seq_file *m, void *unused)
0059 {
0060     struct mei_device *dev = m->private;
0061     struct mei_cl *cl;
0062     int i = 0;
0063 
0064     if (!dev)
0065         return -ENODEV;
0066 
0067     mutex_lock(&dev->device_lock);
0068 
0069     seq_puts(m, "   |me|host|state|rd|wr|wrq\n");
0070 
0071     /*  if the driver is not enabled the list won't be consistent */
0072     if (dev->dev_state != MEI_DEV_ENABLED)
0073         goto out;
0074 
0075     list_for_each_entry(cl, &dev->file_list, link) {
0076 
0077         seq_printf(m, "%3d|%2d|%4d|%5d|%2d|%2d|%3u\n",
0078                i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
0079                !list_empty(&cl->rd_completed), cl->writing_state,
0080                cl->tx_cb_queued);
0081         i++;
0082     }
0083 out:
0084     mutex_unlock(&dev->device_lock);
0085     return 0;
0086 }
0087 DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_active);
0088 
0089 static int mei_dbgfs_devstate_show(struct seq_file *m, void *unused)
0090 {
0091     struct mei_device *dev = m->private;
0092 
0093     seq_printf(m, "dev: %s\n", mei_dev_state_str(dev->dev_state));
0094     seq_printf(m, "hbm: %s\n", mei_hbm_state_str(dev->hbm_state));
0095 
0096     if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS &&
0097         dev->hbm_state <= MEI_HBM_STARTED) {
0098         seq_puts(m, "hbm features:\n");
0099         seq_printf(m, "\tPG: %01d\n", dev->hbm_f_pg_supported);
0100         seq_printf(m, "\tDC: %01d\n", dev->hbm_f_dc_supported);
0101         seq_printf(m, "\tIE: %01d\n", dev->hbm_f_ie_supported);
0102         seq_printf(m, "\tDOT: %01d\n", dev->hbm_f_dot_supported);
0103         seq_printf(m, "\tEV: %01d\n", dev->hbm_f_ev_supported);
0104         seq_printf(m, "\tFA: %01d\n", dev->hbm_f_fa_supported);
0105         seq_printf(m, "\tOS: %01d\n", dev->hbm_f_os_supported);
0106         seq_printf(m, "\tDR: %01d\n", dev->hbm_f_dr_supported);
0107         seq_printf(m, "\tVT: %01d\n", dev->hbm_f_vt_supported);
0108         seq_printf(m, "\tCAP: %01d\n", dev->hbm_f_cap_supported);
0109         seq_printf(m, "\tCD: %01d\n", dev->hbm_f_cd_supported);
0110     }
0111 
0112     seq_printf(m, "pg:  %s, %s\n",
0113            mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
0114            mei_pg_state_str(mei_pg_state(dev)));
0115     return 0;
0116 }
0117 DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_devstate);
0118 
0119 static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
0120                     const char __user *user_buf,
0121                     size_t count, loff_t *ppos)
0122 {
0123     struct mei_device *dev;
0124     int ret;
0125 
0126     dev = container_of(file->private_data,
0127                struct mei_device, allow_fixed_address);
0128 
0129     ret = debugfs_write_file_bool(file, user_buf, count, ppos);
0130     if (ret < 0)
0131         return ret;
0132     dev->override_fixed_address = true;
0133     return ret;
0134 }
0135 
0136 static const struct file_operations mei_dbgfs_allow_fa_fops = {
0137     .open = simple_open,
0138     .read = debugfs_read_file_bool,
0139     .write = mei_dbgfs_write_allow_fa,
0140     .llseek = generic_file_llseek,
0141 };
0142 
0143 /**
0144  * mei_dbgfs_deregister - Remove the debugfs files and directories
0145  *
0146  * @dev: the mei device structure
0147  */
0148 void mei_dbgfs_deregister(struct mei_device *dev)
0149 {
0150     if (!dev->dbgfs_dir)
0151         return;
0152     debugfs_remove_recursive(dev->dbgfs_dir);
0153     dev->dbgfs_dir = NULL;
0154 }
0155 
0156 /**
0157  * mei_dbgfs_register - Add the debugfs files
0158  *
0159  * @dev: the mei device structure
0160  * @name: the mei device name
0161  */
0162 void mei_dbgfs_register(struct mei_device *dev, const char *name)
0163 {
0164     struct dentry *dir;
0165 
0166     dir = debugfs_create_dir(name, NULL);
0167     dev->dbgfs_dir = dir;
0168 
0169     debugfs_create_file("meclients", S_IRUSR, dir, dev,
0170                 &mei_dbgfs_meclients_fops);
0171     debugfs_create_file("active", S_IRUSR, dir, dev,
0172                 &mei_dbgfs_active_fops);
0173     debugfs_create_file("devstate", S_IRUSR, dir, dev,
0174                 &mei_dbgfs_devstate_fops);
0175     debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
0176                 &dev->allow_fixed_address,
0177                 &mei_dbgfs_allow_fa_fops);
0178 }