Commit 79563db9 authored by Tomas Winkler's avatar Tomas Winkler Committed by Greg Kroah-Hartman

mei: add reference counting for me clients

To support dynamic addition and removal of
me clients we add reference counter.

Update kdoc with locking requirements.
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 3542f6b1
...@@ -97,23 +97,25 @@ int mei_amthif_host_init(struct mei_device *dev) ...@@ -97,23 +97,25 @@ int mei_amthif_host_init(struct mei_device *dev)
/* allocate storage for ME message buffer */ /* allocate storage for ME message buffer */
msg_buf = kcalloc(dev->iamthif_mtu, msg_buf = kcalloc(dev->iamthif_mtu,
sizeof(unsigned char), GFP_KERNEL); sizeof(unsigned char), GFP_KERNEL);
if (!msg_buf) if (!msg_buf) {
return -ENOMEM; ret = -ENOMEM;
goto out;
}
dev->iamthif_msg_buf = msg_buf; dev->iamthif_msg_buf = msg_buf;
ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID); ret = mei_cl_link(cl, MEI_IAMTHIF_HOST_CLIENT_ID);
if (ret < 0) { if (ret < 0) {
dev_err(dev->dev, dev_err(dev->dev, "amthif: failed cl_link %d\n", ret);
"amthif: failed link client %d\n", ret); goto out;
return ret;
} }
ret = mei_cl_connect(cl, NULL); ret = mei_cl_connect(cl, NULL);
dev->iamthif_state = MEI_IAMTHIF_IDLE; dev->iamthif_state = MEI_IAMTHIF_IDLE;
out:
mei_me_cl_put(me_cl);
return ret; return ret;
} }
......
...@@ -228,8 +228,8 @@ static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, ...@@ -228,8 +228,8 @@ static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
bool blocking) bool blocking)
{ {
struct mei_device *dev; struct mei_device *dev;
struct mei_me_client *me_cl; struct mei_me_client *me_cl = NULL;
struct mei_cl_cb *cb; struct mei_cl_cb *cb = NULL;
ssize_t rets; ssize_t rets;
if (WARN_ON(!cl || !cl->dev)) if (WARN_ON(!cl || !cl->dev))
...@@ -237,33 +237,40 @@ static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length, ...@@ -237,33 +237,40 @@ static ssize_t ___mei_cl_send(struct mei_cl *cl, u8 *buf, size_t length,
dev = cl->dev; dev = cl->dev;
if (cl->state != MEI_FILE_CONNECTED) mutex_lock(&dev->device_lock);
return -ENODEV; if (cl->state != MEI_FILE_CONNECTED) {
rets = -ENODEV;
goto out;
}
/* Check if we have an ME client device */ /* Check if we have an ME client device */
me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id); me_cl = mei_me_cl_by_uuid_id(dev, &cl->cl_uuid, cl->me_client_id);
if (!me_cl) if (!me_cl) {
return -ENOTTY; rets = -ENOTTY;
goto out;
}
if (length > me_cl->props.max_msg_length) if (length > me_cl->props.max_msg_length) {
return -EFBIG; rets = -EFBIG;
goto out;
}
cb = mei_io_cb_init(cl, NULL); cb = mei_io_cb_init(cl, NULL);
if (!cb) if (!cb) {
return -ENOMEM; rets = -ENOMEM;
goto out;
}
rets = mei_io_cb_alloc_req_buf(cb, length); rets = mei_io_cb_alloc_req_buf(cb, length);
if (rets < 0) { if (rets < 0)
mei_io_cb_free(cb); goto out;
return rets;
}
memcpy(cb->request_buffer.data, buf, length); memcpy(cb->request_buffer.data, buf, length);
mutex_lock(&dev->device_lock);
rets = mei_cl_write(cl, cb, blocking); rets = mei_cl_write(cl, cb, blocking);
out:
mei_me_cl_put(me_cl);
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
if (rets < 0) if (rets < 0)
mei_io_cb_free(cb); mei_io_cb_free(cb);
......
...@@ -26,8 +26,64 @@ ...@@ -26,8 +26,64 @@
#include "hbm.h" #include "hbm.h"
#include "client.h" #include "client.h"
/**
* mei_me_cl_init - initialize me client
*
* @me_cl: me client
*/
void mei_me_cl_init(struct mei_me_client *me_cl)
{
INIT_LIST_HEAD(&me_cl->list);
kref_init(&me_cl->refcnt);
}
/**
* mei_me_cl_get - increases me client refcount
*
* @me_cl: me client
*
* Locking: called under "dev->device_lock" lock
*
* Return: me client or NULL
*/
struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl)
{
if (me_cl)
kref_get(&me_cl->refcnt);
return me_cl;
}
/**
* mei_me_cl_release - unlink and free me client
*
* Locking: called under "dev->device_lock" lock
*
* @ref: me_client refcount
*/
static void mei_me_cl_release(struct kref *ref)
{
struct mei_me_client *me_cl =
container_of(ref, struct mei_me_client, refcnt);
list_del(&me_cl->list);
kfree(me_cl);
}
/**
* mei_me_cl_put - decrease me client refcount and free client if necessary
*
* Locking: called under "dev->device_lock" lock
*
* @me_cl: me client
*/
void mei_me_cl_put(struct mei_me_client *me_cl)
{
if (me_cl)
kref_put(&me_cl->refcnt, mei_me_cl_release);
}
/** /**
* mei_me_cl_by_uuid - locate me client by uuid * mei_me_cl_by_uuid - locate me client by uuid
* increases ref count
* *
* @dev: mei device * @dev: mei device
* @uuid: me client uuid * @uuid: me client uuid
...@@ -43,13 +99,14 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, ...@@ -43,13 +99,14 @@ struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
list_for_each_entry(me_cl, &dev->me_clients, list) list_for_each_entry(me_cl, &dev->me_clients, list)
if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0) if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
return me_cl; return mei_me_cl_get(me_cl);
return NULL; return NULL;
} }
/** /**
* mei_me_cl_by_id - locate me client by client id * mei_me_cl_by_id - locate me client by client id
* increases ref count
* *
* @dev: the device structure * @dev: the device structure
* @client_id: me client id * @client_id: me client id
...@@ -65,12 +122,14 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id) ...@@ -65,12 +122,14 @@ struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
list_for_each_entry(me_cl, &dev->me_clients, list) list_for_each_entry(me_cl, &dev->me_clients, list)
if (me_cl->client_id == client_id) if (me_cl->client_id == client_id)
return me_cl; return mei_me_cl_get(me_cl);
return NULL; return NULL;
} }
/** /**
* mei_me_cl_by_uuid_id - locate me client by client id and uuid * mei_me_cl_by_uuid_id - locate me client by client id and uuid
* increases ref count
* *
* @dev: the device structure * @dev: the device structure
* @uuid: me client uuid * @uuid: me client uuid
...@@ -88,31 +147,67 @@ struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, ...@@ -88,31 +147,67 @@ struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
list_for_each_entry(me_cl, &dev->me_clients, list) list_for_each_entry(me_cl, &dev->me_clients, list)
if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 &&
me_cl->client_id == client_id) me_cl->client_id == client_id)
return me_cl; return mei_me_cl_get(me_cl);
return NULL; return NULL;
} }
/** /**
* mei_me_cl_remove - remove me client matching uuid and client_id * mei_me_cl_rm_by_uuid - remove all me clients matching uuid
* *
* @dev: the device structure * @dev: the device structure
* @uuid: me client uuid * @uuid: me client uuid
* @client_id: me client address *
* Locking: called under "dev->device_lock" lock
*/ */
void mei_me_cl_remove(struct mei_device *dev, const uuid_le *uuid, u8 client_id) void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid)
{ {
struct mei_me_client *me_cl, *next; struct mei_me_client *me_cl, *next;
dev_dbg(dev->dev, "remove %pUl\n", uuid);
list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0)
mei_me_cl_put(me_cl);
}
/**
* mei_me_cl_rm_by_uuid_id - remove all me clients matching client id
*
* @dev: the device structure
* @uuid: me client uuid
* @id: me client id
*
* Locking: called under "dev->device_lock" lock
*/
void mei_me_cl_rm_by_uuid_id(struct mei_device *dev, const uuid_le *uuid, u8 id)
{
struct mei_me_client *me_cl, *next;
const uuid_le *pn;
dev_dbg(dev->dev, "remove %pUl %d\n", uuid, id);
list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) { list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
if (uuid_le_cmp(*uuid, me_cl->props.protocol_name) == 0 && pn = &me_cl->props.protocol_name;
me_cl->client_id == client_id) { if (me_cl->client_id == id && uuid_le_cmp(*uuid, *pn) == 0)
list_del(&me_cl->list); mei_me_cl_put(me_cl);
kfree(me_cl);
break;
}
} }
} }
/**
* mei_me_cl_rm_all - remove all me clients
*
* @dev: the device structure
*
* Locking: called under "dev->device_lock" lock
*/
void mei_me_cl_rm_all(struct mei_device *dev)
{
struct mei_me_client *me_cl, *next;
list_for_each_entry_safe(me_cl, next, &dev->me_clients, list)
mei_me_cl_put(me_cl);
}
/** /**
* mei_cl_cmp_id - tells if the clients are the same * mei_cl_cmp_id - tells if the clients are the same
...@@ -695,6 +790,7 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl) ...@@ -695,6 +790,7 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
{ {
struct mei_device *dev; struct mei_device *dev;
struct mei_me_client *me_cl; struct mei_me_client *me_cl;
int rets = 0;
if (WARN_ON(!cl || !cl->dev)) if (WARN_ON(!cl || !cl->dev))
return -EINVAL; return -EINVAL;
...@@ -710,12 +806,13 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl) ...@@ -710,12 +806,13 @@ int mei_cl_flow_ctrl_creds(struct mei_cl *cl)
return -ENOENT; return -ENOENT;
} }
if (me_cl->mei_flow_ctrl_creds) { if (me_cl->mei_flow_ctrl_creds > 0) {
rets = 1;
if (WARN_ON(me_cl->props.single_recv_buf == 0)) if (WARN_ON(me_cl->props.single_recv_buf == 0))
return -EINVAL; rets = -EINVAL;
return 1;
} }
return 0; mei_me_cl_put(me_cl);
return rets;
} }
/** /**
...@@ -732,6 +829,7 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl) ...@@ -732,6 +829,7 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
{ {
struct mei_device *dev; struct mei_device *dev;
struct mei_me_client *me_cl; struct mei_me_client *me_cl;
int rets;
if (WARN_ON(!cl || !cl->dev)) if (WARN_ON(!cl || !cl->dev))
return -EINVAL; return -EINVAL;
...@@ -745,15 +843,22 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl) ...@@ -745,15 +843,22 @@ int mei_cl_flow_ctrl_reduce(struct mei_cl *cl)
} }
if (me_cl->props.single_recv_buf) { if (me_cl->props.single_recv_buf) {
if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) if (WARN_ON(me_cl->mei_flow_ctrl_creds <= 0)) {
return -EINVAL; rets = -EINVAL;
goto out;
}
me_cl->mei_flow_ctrl_creds--; me_cl->mei_flow_ctrl_creds--;
} else { } else {
if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) if (WARN_ON(cl->mei_flow_ctrl_creds <= 0)) {
return -EINVAL; rets = -EINVAL;
goto out;
}
cl->mei_flow_ctrl_creds--; cl->mei_flow_ctrl_creds--;
} }
return 0; rets = 0;
out:
mei_me_cl_put(me_cl);
return rets;
} }
/** /**
...@@ -788,6 +893,9 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length) ...@@ -788,6 +893,9 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
cl_err(dev, cl, "no such me client %d\n", cl->me_client_id); cl_err(dev, cl, "no such me client %d\n", cl->me_client_id);
return -ENOTTY; return -ENOTTY;
} }
/* always allocate at least client max message */
length = max_t(size_t, length, me_cl->props.max_msg_length);
mei_me_cl_put(me_cl);
rets = pm_runtime_get(dev->dev); rets = pm_runtime_get(dev->dev);
if (rets < 0 && rets != -EINPROGRESS) { if (rets < 0 && rets != -EINPROGRESS) {
...@@ -802,8 +910,6 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length) ...@@ -802,8 +910,6 @@ int mei_cl_read_start(struct mei_cl *cl, size_t length)
goto out; goto out;
} }
/* always allocate at least client max message */
length = max_t(size_t, length, me_cl->props.max_msg_length);
rets = mei_io_cb_alloc_resp_buf(cb, length); rets = mei_io_cb_alloc_resp_buf(cb, length);
if (rets) if (rets)
goto out; goto out;
......
...@@ -24,15 +24,22 @@ ...@@ -24,15 +24,22 @@
#include "mei_dev.h" #include "mei_dev.h"
/*
* reference counting base function
*/
void mei_me_cl_init(struct mei_me_client *me_cl);
void mei_me_cl_put(struct mei_me_client *me_cl);
struct mei_me_client *mei_me_cl_get(struct mei_me_client *me_cl);
struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev, struct mei_me_client *mei_me_cl_by_uuid(const struct mei_device *dev,
const uuid_le *cuuid); const uuid_le *uuid);
struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id); struct mei_me_client *mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev, struct mei_me_client *mei_me_cl_by_uuid_id(struct mei_device *dev,
const uuid_le *uuid, u8 client_id); const uuid_le *uuid, u8 client_id);
void mei_me_cl_rm_by_uuid(struct mei_device *dev, const uuid_le *uuid);
void mei_me_cl_remove(struct mei_device *dev, void mei_me_cl_rm_by_uuid_id(struct mei_device *dev,
const uuid_le *uuid, u8 client_id); const uuid_le *uuid, u8 id);
void mei_me_cl_rm_all(struct mei_device *dev);
/* /*
* MEI IO Functions * MEI IO Functions
......
...@@ -21,20 +21,22 @@ ...@@ -21,20 +21,22 @@
#include <linux/mei.h> #include <linux/mei.h>
#include "mei_dev.h" #include "mei_dev.h"
#include "client.h"
#include "hw.h" #include "hw.h"
static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
size_t cnt, loff_t *ppos) size_t cnt, loff_t *ppos)
{ {
struct mei_device *dev = fp->private_data; struct mei_device *dev = fp->private_data;
struct mei_me_client *me_cl; struct mei_me_client *me_cl, *n;
size_t bufsz = 1; size_t bufsz = 1;
char *buf; char *buf;
int i = 0; int i = 0;
int pos = 0; int pos = 0;
int ret; int ret;
#define HDR " |id|fix| UUID |con|msg len|sb|\n" #define HDR \
" |id|fix| UUID |con|msg len|sb|refc|\n"
mutex_lock(&dev->device_lock); mutex_lock(&dev->device_lock);
...@@ -54,16 +56,22 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf, ...@@ -54,16 +56,22 @@ static ssize_t mei_dbgfs_read_meclients(struct file *fp, char __user *ubuf,
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_safe(me_cl, n, &dev->me_clients, list) {
pos += scnprintf(buf + pos, bufsz - pos, me_cl = mei_me_cl_get(me_cl);
"%2d|%2d|%3d|%pUl|%3d|%7d|%2d|\n", if (me_cl) {
i++, me_cl->client_id, pos += scnprintf(buf + pos, bufsz - pos,
me_cl->props.fixed_address, "%2d|%2d|%3d|%pUl|%3d|%7d|%2d|%4d|\n",
&me_cl->props.protocol_name, i++, me_cl->client_id,
me_cl->props.max_number_of_connections, me_cl->props.fixed_address,
me_cl->props.max_msg_length, &me_cl->props.protocol_name,
me_cl->props.single_recv_buf); me_cl->props.max_number_of_connections,
me_cl->props.max_msg_length,
me_cl->props.single_recv_buf,
atomic_read(&me_cl->refcnt.refcount));
}
mei_me_cl_put(me_cl);
} }
out: out:
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
......
...@@ -104,21 +104,6 @@ void mei_hbm_idle(struct mei_device *dev) ...@@ -104,21 +104,6 @@ void mei_hbm_idle(struct mei_device *dev)
dev->hbm_state = MEI_HBM_IDLE; dev->hbm_state = MEI_HBM_IDLE;
} }
/**
* mei_me_cl_remove_all - remove all me clients
*
* @dev: the device structure
*/
static void mei_me_cl_remove_all(struct mei_device *dev)
{
struct mei_me_client *me_cl, *next;
list_for_each_entry_safe(me_cl, next, &dev->me_clients, list) {
list_del(&me_cl->list);
kfree(me_cl);
}
}
/** /**
* mei_hbm_reset - reset hbm counters and book keeping data structurs * mei_hbm_reset - reset hbm counters and book keeping data structurs
* *
...@@ -128,7 +113,7 @@ void mei_hbm_reset(struct mei_device *dev) ...@@ -128,7 +113,7 @@ void mei_hbm_reset(struct mei_device *dev)
{ {
dev->me_client_index = 0; dev->me_client_index = 0;
mei_me_cl_remove_all(dev); mei_me_cl_rm_all(dev);
mei_hbm_idle(dev); mei_hbm_idle(dev);
} }
...@@ -339,11 +324,16 @@ static int mei_hbm_me_cl_add(struct mei_device *dev, ...@@ -339,11 +324,16 @@ static int mei_hbm_me_cl_add(struct mei_device *dev,
struct hbm_props_response *res) struct hbm_props_response *res)
{ {
struct mei_me_client *me_cl; struct mei_me_client *me_cl;
const uuid_le *uuid = &res->client_properties.protocol_name;
mei_me_cl_rm_by_uuid(dev, uuid);
me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL); me_cl = kzalloc(sizeof(struct mei_me_client), GFP_KERNEL);
if (!me_cl) if (!me_cl)
return -ENOMEM; return -ENOMEM;
mei_me_cl_init(me_cl);
me_cl->props = res->client_properties; me_cl->props = res->client_properties;
me_cl->client_id = res->me_addr; me_cl->client_id = res->me_addr;
me_cl->mei_flow_ctrl_creds = 0; me_cl->mei_flow_ctrl_creds = 0;
...@@ -484,6 +474,7 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev, ...@@ -484,6 +474,7 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
struct hbm_flow_control *flow) struct hbm_flow_control *flow)
{ {
struct mei_me_client *me_cl; struct mei_me_client *me_cl;
int rets;
me_cl = mei_me_cl_by_id(dev, flow->me_addr); me_cl = mei_me_cl_by_id(dev, flow->me_addr);
if (!me_cl) { if (!me_cl) {
...@@ -492,14 +483,19 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev, ...@@ -492,14 +483,19 @@ static int mei_hbm_add_single_flow_creds(struct mei_device *dev,
return -ENOENT; return -ENOENT;
} }
if (WARN_ON(me_cl->props.single_recv_buf == 0)) if (WARN_ON(me_cl->props.single_recv_buf == 0)) {
return -EINVAL; rets = -EINVAL;
goto out;
}
me_cl->mei_flow_ctrl_creds++; me_cl->mei_flow_ctrl_creds++;
dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n", dev_dbg(dev->dev, "recv flow ctrl msg ME %d (single) creds = %d.\n",
flow->me_addr, me_cl->mei_flow_ctrl_creds); flow->me_addr, me_cl->mei_flow_ctrl_creds);
return 0; rets = 0;
out:
mei_me_cl_put(me_cl);
return rets;
} }
/** /**
......
...@@ -303,7 +303,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -303,7 +303,7 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
size_t length, loff_t *offset) size_t length, loff_t *offset)
{ {
struct mei_cl *cl = file->private_data; struct mei_cl *cl = file->private_data;
struct mei_me_client *me_cl; struct mei_me_client *me_cl = NULL;
struct mei_cl_cb *write_cb = NULL; struct mei_cl_cb *write_cb = NULL;
struct mei_device *dev; struct mei_device *dev;
unsigned long timeout = 0; unsigned long timeout = 0;
...@@ -399,12 +399,14 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf, ...@@ -399,12 +399,14 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
"amthif write failed with status = %d\n", rets); "amthif write failed with status = %d\n", rets);
goto out; goto out;
} }
mei_me_cl_put(me_cl);
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
return length; return length;
} }
rets = mei_cl_write(cl, write_cb, false); rets = mei_cl_write(cl, write_cb, false);
out: out:
mei_me_cl_put(me_cl);
mutex_unlock(&dev->device_lock); mutex_unlock(&dev->device_lock);
if (rets < 0) if (rets < 0)
mei_io_cb_free(write_cb); mei_io_cb_free(write_cb);
...@@ -433,24 +435,19 @@ static int mei_ioctl_connect_client(struct file *file, ...@@ -433,24 +435,19 @@ static int mei_ioctl_connect_client(struct file *file,
cl = file->private_data; cl = file->private_data;
dev = cl->dev; dev = cl->dev;
if (dev->dev_state != MEI_DEV_ENABLED) { if (dev->dev_state != MEI_DEV_ENABLED)
rets = -ENODEV; return -ENODEV;
goto end;
}
if (cl->state != MEI_FILE_INITIALIZING && if (cl->state != MEI_FILE_INITIALIZING &&
cl->state != MEI_FILE_DISCONNECTED) { cl->state != MEI_FILE_DISCONNECTED)
rets = -EBUSY; return -EBUSY;
goto end;
}
/* find ME client we're trying to connect to */ /* find ME client we're trying to connect to */
me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid); me_cl = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
if (!me_cl || me_cl->props.fixed_address) { if (!me_cl || me_cl->props.fixed_address) {
dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n", dev_dbg(dev->dev, "Cannot connect to FW Client UUID = %pUl\n",
&data->in_client_uuid); &data->in_client_uuid);
rets = -ENOTTY; return -ENOTTY;
goto end;
} }
cl->me_client_id = me_cl->client_id; cl->me_client_id = me_cl->client_id;
...@@ -487,17 +484,16 @@ static int mei_ioctl_connect_client(struct file *file, ...@@ -487,17 +484,16 @@ static int mei_ioctl_connect_client(struct file *file,
goto end; goto end;
} }
/* prepare the output buffer */ /* prepare the output buffer */
client = &data->out_client_properties; client = &data->out_client_properties;
client->max_msg_length = me_cl->props.max_msg_length; client->max_msg_length = me_cl->props.max_msg_length;
client->protocol_version = me_cl->props.protocol_version; client->protocol_version = me_cl->props.protocol_version;
dev_dbg(dev->dev, "Can connect?\n"); dev_dbg(dev->dev, "Can connect?\n");
rets = mei_cl_connect(cl, file); rets = mei_cl_connect(cl, file);
end: end:
mei_me_cl_put(me_cl);
return rets; return rets;
} }
......
...@@ -172,12 +172,14 @@ struct mei_fw_status { ...@@ -172,12 +172,14 @@ struct mei_fw_status {
* struct mei_me_client - representation of me (fw) client * struct mei_me_client - representation of me (fw) client
* *
* @list: link in me client list * @list: link in me client list
* @refcnt: struct reference count
* @props: client properties * @props: client properties
* @client_id: me client id * @client_id: me client id
* @mei_flow_ctrl_creds: flow control credits * @mei_flow_ctrl_creds: flow control credits
*/ */
struct mei_me_client { struct mei_me_client {
struct list_head list; struct list_head list;
struct kref refcnt;
struct mei_client_properties props; struct mei_client_properties props;
u8 client_id; u8 client_id;
u8 mei_flow_ctrl_creds; u8 mei_flow_ctrl_creds;
......
...@@ -521,6 +521,7 @@ int mei_nfc_host_init(struct mei_device *dev) ...@@ -521,6 +521,7 @@ int mei_nfc_host_init(struct mei_device *dev)
cl_info->me_client_id = me_cl->client_id; cl_info->me_client_id = me_cl->client_id;
cl_info->cl_uuid = me_cl->props.protocol_name; cl_info->cl_uuid = me_cl->props.protocol_name;
mei_me_cl_put(me_cl);
ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY); ret = mei_cl_link(cl_info, MEI_HOST_CLIENT_ID_ANY);
if (ret) if (ret)
...@@ -539,6 +540,7 @@ int mei_nfc_host_init(struct mei_device *dev) ...@@ -539,6 +540,7 @@ int mei_nfc_host_init(struct mei_device *dev)
cl->me_client_id = me_cl->client_id; cl->me_client_id = me_cl->client_id;
cl->cl_uuid = me_cl->props.protocol_name; cl->cl_uuid = me_cl->props.protocol_name;
mei_me_cl_put(me_cl);
ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY); ret = mei_cl_link(cl, MEI_HOST_CLIENT_ID_ANY);
if (ret) if (ret)
......
...@@ -76,6 +76,7 @@ int mei_wd_host_init(struct mei_device *dev) ...@@ -76,6 +76,7 @@ int mei_wd_host_init(struct mei_device *dev)
cl->me_client_id = me_cl->client_id; cl->me_client_id = me_cl->client_id;
cl->cl_uuid = me_cl->props.protocol_name; cl->cl_uuid = me_cl->props.protocol_name;
mei_me_cl_put(me_cl);
ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID); ret = mei_cl_link(cl, MEI_WD_HOST_CLIENT_ID);
......
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