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