Commit b728ddde authored by Vitaly Lubart's avatar Vitaly Lubart Committed by Greg Kroah-Hartman

mei: Convert to use DEFINE_SHOW_ATTRIBUTE macro

Use DEFINE_SHOW_ATTRIBUTE macro to simplify the code.
Signed-off-by: default avatarVitaly Lubart <vitaly.lubart@intel.com>
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent a188339c
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <linux/kernel.h> #include <linux/kernel.h>
#include <linux/device.h> #include <linux/device.h>
#include <linux/debugfs.h> #include <linux/debugfs.h>
#include <linux/seq_file.h>
#include <linux/mei.h> #include <linux/mei.h>
...@@ -15,104 +16,56 @@ ...@@ -15,104 +16,56 @@
#include "client.h" #include "client.h"
#include "hw.h" #include "hw.h"
static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, static int mei_dbgfs_meclients_show(struct seq_file *m, void *unused)
size_t cnt, loff_t *ppos)
{ {
struct mei_device *dev = fp->private_data; struct mei_device *dev = m->private;
struct mei_me_client *me_cl; struct mei_me_client *me_cl;
size_t bufsz = 1;
char *buf;
int i = 0; int i = 0;
int pos = 0;
int ret;
#define HDR \ if (!dev)
" |id|fix| UUID |con|msg len|sb|refc|\n" return -ENODEV;
down_read(&dev->me_clients_rwsem); down_read(&dev->me_clients_rwsem);
list_for_each_entry(me_cl, &dev->me_clients, list)
bufsz++;
bufsz *= sizeof(HDR) + 1; seq_puts(m, " |id|fix| UUID |con|msg len|sb|refc|\n");
buf = kzalloc(bufsz, GFP_KERNEL);
if (!buf) {
up_read(&dev->me_clients_rwsem);
return -ENOMEM;
}
pos += scnprintf(buf + pos, bufsz - pos, HDR);
#undef HDR
/* if the driver is not enabled the list won't be consistent */ /* if the driver is not enabled the list won't be consistent */
if (dev->dev_state != MEI_DEV_ENABLED) if (dev->dev_state != MEI_DEV_ENABLED)
goto out; goto out;
list_for_each_entry(me_cl, &dev->me_clients, list) { list_for_each_entry(me_cl, &dev->me_clients, list) {
if (!mei_me_cl_get(me_cl))
if (mei_me_cl_get(me_cl)) { continue;
pos += scnprintf(buf + pos, bufsz - pos,
"%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n", seq_printf(m, "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
i++, me_cl->client_id, i++, me_cl->client_id,
me_cl->props.fixed_address, me_cl->props.fixed_address,
&me_cl->props.protocol_name, &me_cl->props.protocol_name,
me_cl->props.max_number_of_connections, me_cl->props.max_number_of_connections,
me_cl->props.max_msg_length, me_cl->props.max_msg_length,
me_cl->props.single_recv_buf, me_cl->props.single_recv_buf,
kref_read(&me_cl->refcnt)); kref_read(&me_cl->refcnt));
mei_me_cl_put(me_cl);
mei_me_cl_put(me_cl);
}
} }
out: out:
up_read(&dev->me_clients_rwsem); up_read(&dev->me_clients_rwsem);
ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); return 0;
kfree(buf);
return ret;
} }
DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_meclients);
static const struct file_operations mei_dbgfs_fops_meclients = { static int mei_dbgfs_active_show(struct seq_file *m, void *unused)
.open = simple_open,
.read = mei_dbgfs_read_meclients,
.llseek = generic_file_llseek,
};
static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf,
size_t cnt, loff_t *ppos)
{ {
struct mei_device *dev = fp->private_data; struct mei_device *dev = m->private;
struct mei_cl *cl; struct mei_cl *cl;
size_t bufsz = 1;
char *buf;
int i = 0; int i = 0;
int pos = 0;
int ret;
#define HDR " |me|host|state|rd|wr|wrq\n"
if (!dev) if (!dev)
return -ENODEV; return -ENODEV;
mutex_lock(&dev->device_lock); mutex_lock(&dev->device_lock);
/* seq_puts(m, " |me|host|state|rd|wr|wrq\n");
* if the driver is not enabled the list won't be consistent,
* we output empty table
*/
if (dev->dev_state == MEI_DEV_ENABLED)
list_for_each_entry(cl, &dev->file_list, link)
bufsz++;
bufsz *= sizeof(HDR) + 1;
buf = kzalloc(bufsz, GFP_KERNEL);
if (!buf) {
mutex_unlock(&dev->device_lock);
return -ENOMEM;
}
pos += scnprintf(buf + pos, bufsz - pos, HDR);
#undef HDR
/* if the driver is not enabled the list won't be consistent */ /* if the driver is not enabled the list won't be consistent */
if (dev->dev_state != MEI_DEV_ENABLED) if (dev->dev_state != MEI_DEV_ENABLED)
...@@ -120,76 +73,44 @@ static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf, ...@@ -120,76 +73,44 @@ static ssize_t mei_dbgfs_read_active(struct file *fp, char __user *ubuf,
list_for_each_entry(cl, &dev->file_list, link) { list_for_each_entry(cl, &dev->file_list, link) {
pos += scnprintf(buf + pos, bufsz - pos, seq_printf(m, "%3d|%2d|%4d|%5d|%2d|%2d|%3u\n",
"%3d|%2d|%4d|%5d|%2d|%2d|%3u\n", i, mei_cl_me_id(cl), cl->host_client_id, cl->state,
i, mei_cl_me_id(cl), cl->host_client_id, cl->state, !list_empty(&cl->rd_completed), cl->writing_state,
!list_empty(&cl->rd_completed), cl->writing_state, cl->tx_cb_queued);
cl->tx_cb_queued);
i++; i++;
} }
out: out:
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); return 0;
kfree(buf);
return ret;
} }
DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_active);
static const struct file_operations mei_dbgfs_fops_active = { static int mei_dbgfs_devstate_show(struct seq_file *m, void *unused)
.open = simple_open,
.read = mei_dbgfs_read_active,
.llseek = generic_file_llseek,
};
static ssize_t mei_dbgfs_read_devstate(struct file *fp, char __user *ubuf,
size_t cnt, loff_t *ppos)
{ {
struct mei_device *dev = fp->private_data; struct mei_device *dev = m->private;
const size_t bufsz = 1024;
char *buf = kzalloc(bufsz, GFP_KERNEL);
int pos = 0;
int ret;
if (!buf)
return -ENOMEM;
pos += scnprintf(buf + pos, bufsz - pos, "dev: %s\n", seq_printf(m, "dev: %s\n", mei_dev_state_str(dev->dev_state));
mei_dev_state_str(dev->dev_state)); seq_printf(m, "hbm: %s\n", mei_hbm_state_str(dev->hbm_state));
pos += scnprintf(buf + pos, bufsz - pos, "hbm: %s\n",
mei_hbm_state_str(dev->hbm_state));
if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS && if (dev->hbm_state >= MEI_HBM_ENUM_CLIENTS &&
dev->hbm_state <= MEI_HBM_STARTED) { dev->hbm_state <= MEI_HBM_STARTED) {
pos += scnprintf(buf + pos, bufsz - pos, "hbm features:\n"); seq_puts(m, "hbm features:\n");
pos += scnprintf(buf + pos, bufsz - pos, "\tPG: %01d\n", seq_printf(m, "\tPG: %01d\n", dev->hbm_f_pg_supported);
dev->hbm_f_pg_supported); seq_printf(m, "\tDC: %01d\n", dev->hbm_f_dc_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tDC: %01d\n", seq_printf(m, "\tIE: %01d\n", dev->hbm_f_ie_supported);
dev->hbm_f_dc_supported); seq_printf(m, "\tDOT: %01d\n", dev->hbm_f_dot_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tIE: %01d\n", seq_printf(m, "\tEV: %01d\n", dev->hbm_f_ev_supported);
dev->hbm_f_ie_supported); seq_printf(m, "\tFA: %01d\n", dev->hbm_f_fa_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tDOT: %01d\n", seq_printf(m, "\tOS: %01d\n", dev->hbm_f_os_supported);
dev->hbm_f_dot_supported); seq_printf(m, "\tDR: %01d\n", dev->hbm_f_dr_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tEV: %01d\n",
dev->hbm_f_ev_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tFA: %01d\n",
dev->hbm_f_fa_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tOS: %01d\n",
dev->hbm_f_os_supported);
pos += scnprintf(buf + pos, bufsz - pos, "\tDR: %01d\n",
dev->hbm_f_dr_supported);
} }
pos += scnprintf(buf + pos, bufsz - pos, "pg: %s, %s\n", seq_printf(m, "pg: %s, %s\n",
mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED", mei_pg_is_enabled(dev) ? "ENABLED" : "DISABLED",
mei_pg_state_str(mei_pg_state(dev))); mei_pg_state_str(mei_pg_state(dev)));
ret = simple_read_from_buffer(ubuf, cnt, ppos, buf, pos); return 0;
kfree(buf);
return ret;
} }
static const struct file_operations mei_dbgfs_fops_devstate = { DEFINE_SHOW_ATTRIBUTE(mei_dbgfs_devstate);
.open = simple_open,
.read = mei_dbgfs_read_devstate,
.llseek = generic_file_llseek,
};
static ssize_t mei_dbgfs_write_allow_fa(struct file *file, static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
const char __user *user_buf, const char __user *user_buf,
...@@ -208,7 +129,7 @@ static ssize_t mei_dbgfs_write_allow_fa(struct file *file, ...@@ -208,7 +129,7 @@ static ssize_t mei_dbgfs_write_allow_fa(struct file *file,
return ret; return ret;
} }
static const struct file_operations mei_dbgfs_fops_allow_fa = { static const struct file_operations mei_dbgfs_allow_fa_fops = {
.open = simple_open, .open = simple_open,
.read = debugfs_read_file_bool, .read = debugfs_read_file_bool,
.write = mei_dbgfs_write_allow_fa, .write = mei_dbgfs_write_allow_fa,
...@@ -247,26 +168,26 @@ int mei_dbgfs_register(struct mei_device *dev, const char *name) ...@@ -247,26 +168,26 @@ int mei_dbgfs_register(struct mei_device *dev, const char *name)
dev->dbgfs_dir = dir; dev->dbgfs_dir = dir;
f = debugfs_create_file("meclients", S_IRUSR, dir, f = debugfs_create_file("meclients", S_IRUSR, dir,
dev, &mei_dbgfs_fops_meclients); dev, &mei_dbgfs_meclients_fops);
if (!f) { if (!f) {
dev_err(dev->dev, "meclients: registration failed\n"); dev_err(dev->dev, "meclients: registration failed\n");
goto err; goto err;
} }
f = debugfs_create_file("active", S_IRUSR, dir, f = debugfs_create_file("active", S_IRUSR, dir,
dev, &mei_dbgfs_fops_active); dev, &mei_dbgfs_active_fops);
if (!f) { if (!f) {
dev_err(dev->dev, "active: registration failed\n"); dev_err(dev->dev, "active: registration failed\n");
goto err; goto err;
} }
f = debugfs_create_file("devstate", S_IRUSR, dir, f = debugfs_create_file("devstate", S_IRUSR, dir,
dev, &mei_dbgfs_fops_devstate); dev, &mei_dbgfs_devstate_fops);
if (!f) { if (!f) {
dev_err(dev->dev, "devstate: registration failed\n"); dev_err(dev->dev, "devstate: registration failed\n");
goto err; goto err;
} }
f = debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir, f = debugfs_create_file("allow_fixed_address", S_IRUSR | S_IWUSR, dir,
&dev->allow_fixed_address, &dev->allow_fixed_address,
&mei_dbgfs_fops_allow_fa); &mei_dbgfs_allow_fa_fops);
if (!f) { if (!f) {
dev_err(dev->dev, "allow_fixed_address: registration failed\n"); dev_err(dev->dev, "allow_fixed_address: registration failed\n");
goto err; goto err;
...@@ -276,4 +197,3 @@ int mei_dbgfs_register(struct mei_device *dev, const char *name) ...@@ -276,4 +197,3 @@ int mei_dbgfs_register(struct mei_device *dev, const char *name)
mei_dbgfs_deregister(dev); mei_dbgfs_deregister(dev);
return -ENODEV; return -ENODEV;
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment