mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2025-01-24 14:54:49 +08:00
mei: revamp me client search function
me client search functions returns index into me_client array according me client id or me client uuid. 1. Add common prefix for the functions mei_me_cl_<> 2. create new function mei_me_cl_by_id that wraps open coded loops scattered over the code 3. rename mei_find_me_client_index to mei_me_cl_by_uuid 4. rename mei_find_me_client_update_filext to mei_me_cl_update_filext and updates its parameter names Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
0d7614f09c
commit
07b509b794
@ -522,12 +522,12 @@ void mei_cl_init(struct mei_cl *priv, struct mei_device *dev)
|
|||||||
priv->dev = dev;
|
priv->dev = dev;
|
||||||
}
|
}
|
||||||
|
|
||||||
int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid)
|
int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid)
|
||||||
{
|
{
|
||||||
int i, res = -1;
|
int i, res = -ENOENT;
|
||||||
|
|
||||||
for (i = 0; i < dev->me_clients_num; ++i)
|
for (i = 0; i < dev->me_clients_num; ++i)
|
||||||
if (uuid_le_cmp(cuuid,
|
if (uuid_le_cmp(*cuuid,
|
||||||
dev->me_clients[i].props.protocol_name) == 0) {
|
dev->me_clients[i].props.protocol_name) == 0) {
|
||||||
res = i;
|
res = i;
|
||||||
break;
|
break;
|
||||||
@ -538,35 +538,35 @@ int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid)
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mei_find_me_client_update_filext - searches for ME client guid
|
* mei_me_cl_update_filext - searches for ME client guid
|
||||||
* sets client_id in mei_file_private if found
|
* sets client_id in mei_file_private if found
|
||||||
* @dev: the device structure
|
* @dev: the device structure
|
||||||
* @priv: private file structure to set client_id in
|
* @cl: private file structure to set client_id in
|
||||||
* @cguid: searched guid of ME client
|
* @cuuid: searched uuid of ME client
|
||||||
* @client_id: id of host client to be set in file private structure
|
* @client_id: id of host client to be set in file private structure
|
||||||
*
|
*
|
||||||
* returns ME client index
|
* returns ME client index
|
||||||
*/
|
*/
|
||||||
u8 mei_find_me_client_update_filext(struct mei_device *dev, struct mei_cl *priv,
|
int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
|
||||||
const uuid_le *cguid, u8 client_id)
|
const uuid_le *cuuid, u8 host_cl_id)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!dev || !priv || !cguid)
|
if (!dev || !cl || !cuuid)
|
||||||
return 0;
|
return -EINVAL;
|
||||||
|
|
||||||
/* check for valid client id */
|
/* check for valid client id */
|
||||||
i = mei_find_me_client_index(dev, *cguid);
|
i = mei_me_cl_by_uuid(dev, cuuid);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
priv->me_client_id = dev->me_clients[i].client_id;
|
cl->me_client_id = dev->me_clients[i].client_id;
|
||||||
priv->state = MEI_FILE_CONNECTING;
|
cl->state = MEI_FILE_CONNECTING;
|
||||||
priv->host_client_id = client_id;
|
cl->host_client_id = host_cl_id;
|
||||||
|
|
||||||
list_add_tail(&priv->link, &dev->file_list);
|
list_add_tail(&cl->link, &dev->file_list);
|
||||||
return (u8)i;
|
return (u8)i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -577,16 +577,16 @@ u8 mei_find_me_client_update_filext(struct mei_device *dev, struct mei_cl *priv,
|
|||||||
*/
|
*/
|
||||||
void mei_host_init_iamthif(struct mei_device *dev)
|
void mei_host_init_iamthif(struct mei_device *dev)
|
||||||
{
|
{
|
||||||
u8 i;
|
int i;
|
||||||
unsigned char *msg_buf;
|
unsigned char *msg_buf;
|
||||||
|
|
||||||
mei_cl_init(&dev->iamthif_cl, dev);
|
mei_cl_init(&dev->iamthif_cl, dev);
|
||||||
dev->iamthif_cl.state = MEI_FILE_DISCONNECTED;
|
dev->iamthif_cl.state = MEI_FILE_DISCONNECTED;
|
||||||
|
|
||||||
/* find ME amthi client */
|
/* find ME amthi client */
|
||||||
i = mei_find_me_client_update_filext(dev, &dev->iamthif_cl,
|
i = mei_me_cl_update_filext(dev, &dev->iamthif_cl,
|
||||||
&mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID);
|
&mei_amthi_guid, MEI_IAMTHIF_HOST_CLIENT_ID);
|
||||||
if (dev->iamthif_cl.state != MEI_FILE_CONNECTING) {
|
if (i < 0) {
|
||||||
dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n");
|
dev_dbg(&dev->pdev->dev, "failed to find iamthif client.\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,31 @@
|
|||||||
#include <linux/mei.h>
|
#include <linux/mei.h>
|
||||||
#include "interface.h"
|
#include "interface.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* mei_me_cl_by_id return index to me_clients for client_id
|
||||||
|
*
|
||||||
|
* @dev: the device structure
|
||||||
|
* @client_id: me client id
|
||||||
|
*
|
||||||
|
* Locking: called under "dev->device_lock" lock
|
||||||
|
*
|
||||||
|
* returns index on success, -ENOENT on failure.
|
||||||
|
*/
|
||||||
|
|
||||||
|
int mei_me_cl_by_id(struct mei_device *dev, u8 client_id)
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
for (i = 0; i < dev->me_clients_num; i++)
|
||||||
|
if (dev->me_clients[i].client_id == client_id)
|
||||||
|
break;
|
||||||
|
if (WARN_ON(dev->me_clients[i].client_id != client_id))
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
if (i == dev->me_clients_num)
|
||||||
|
return -ENOENT;
|
||||||
|
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* mei_ioctl_connect_client - the connect to fw client IOCTL function
|
* mei_ioctl_connect_client - the connect to fw client IOCTL function
|
||||||
@ -95,7 +119,7 @@ int mei_ioctl_connect_client(struct file *file,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* find ME client we're trying to connect to */
|
/* find ME client we're trying to connect to */
|
||||||
i = mei_find_me_client_index(dev, data->in_client_uuid);
|
i = mei_me_cl_by_uuid(dev, &data->in_client_uuid);
|
||||||
if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
|
if (i >= 0 && !dev->me_clients[i].props.fixed_address) {
|
||||||
cl->me_client_id = dev->me_clients[i].client_id;
|
cl->me_client_id = dev->me_clients[i].client_id;
|
||||||
cl->state = MEI_FILE_CONNECTING;
|
cl->state = MEI_FILE_CONNECTING;
|
||||||
@ -273,19 +297,12 @@ int amthi_read(struct mei_device *dev, struct file *file,
|
|||||||
return -ETIMEDOUT;
|
return -ETIMEDOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < dev->me_clients_num; i++) {
|
i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
|
||||||
if (dev->me_clients[i].client_id ==
|
|
||||||
dev->iamthif_cl.me_client_id)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == dev->me_clients_num) {
|
if (i < 0) {
|
||||||
dev_dbg(&dev->pdev->dev, "amthi client not found.\n");
|
dev_dbg(&dev->pdev->dev, "amthi client not found.\n");
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id))
|
|
||||||
return -ENODEV;
|
|
||||||
|
|
||||||
dev_dbg(&dev->pdev->dev, "checking amthi data\n");
|
dev_dbg(&dev->pdev->dev, "checking amthi data\n");
|
||||||
cb = find_amthi_read_list_entry(dev, file);
|
cb = find_amthi_read_list_entry(dev, file);
|
||||||
|
|
||||||
@ -316,8 +333,7 @@ int amthi_read(struct mei_device *dev, struct file *file,
|
|||||||
dev->iamthif_timer = 0;
|
dev->iamthif_timer = 0;
|
||||||
|
|
||||||
if (cb) {
|
if (cb) {
|
||||||
timeout = cb->read_time +
|
timeout = cb->read_time + msecs_to_jiffies(IAMTHIF_READ_TIMER);
|
||||||
msecs_to_jiffies(IAMTHIF_READ_TIMER);
|
|
||||||
dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n",
|
dev_dbg(&dev->pdev->dev, "amthi timeout = %lud\n",
|
||||||
timeout);
|
timeout);
|
||||||
|
|
||||||
@ -401,19 +417,8 @@ int mei_start_read(struct mei_device *dev, struct mei_cl *cl)
|
|||||||
|
|
||||||
dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n",
|
dev_dbg(&dev->pdev->dev, "allocation call back successful. host client = %d, ME client = %d\n",
|
||||||
cl->host_client_id, cl->me_client_id);
|
cl->host_client_id, cl->me_client_id);
|
||||||
|
i = mei_me_cl_by_id(dev, cl->me_client_id);
|
||||||
for (i = 0; i < dev->me_clients_num; i++) {
|
if (i < 0) {
|
||||||
if (dev->me_clients[i].client_id == cl->me_client_id)
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
|
|
||||||
rets = -ENODEV;
|
|
||||||
goto unlock;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i == dev->me_clients_num) {
|
|
||||||
rets = -ENODEV;
|
rets = -ENODEV;
|
||||||
goto unlock;
|
goto unlock;
|
||||||
}
|
}
|
||||||
|
@ -393,10 +393,9 @@ static ssize_t mei_read(struct file *file, char __user *ubuf,
|
|||||||
|
|
||||||
if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) {
|
if ((cl->sm_state & MEI_WD_STATE_INDEPENDENCE_MSG_SENT) == 0) {
|
||||||
/* Do not allow to read watchdog client */
|
/* Do not allow to read watchdog client */
|
||||||
i = mei_find_me_client_index(dev, mei_wd_guid);
|
i = mei_me_cl_by_uuid(dev, &mei_wd_guid);
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
struct mei_me_client *me_client = &dev->me_clients[i];
|
struct mei_me_client *me_client = &dev->me_clients[i];
|
||||||
|
|
||||||
if (cl->me_client_id == me_client->client_id) {
|
if (cl->me_client_id == me_client->client_id) {
|
||||||
rets = -EBADF;
|
rets = -EBADF;
|
||||||
goto out;
|
goto out;
|
||||||
@ -620,22 +619,12 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
|
|||||||
rets = -ENODEV;
|
rets = -ENODEV;
|
||||||
goto unlock_dev;
|
goto unlock_dev;
|
||||||
}
|
}
|
||||||
for (i = 0; i < dev->me_clients_num; i++) {
|
i = mei_me_cl_by_id(dev, dev->iamthif_cl.me_client_id);
|
||||||
if (dev->me_clients[i].client_id ==
|
if (i < 0) {
|
||||||
dev->iamthif_cl.me_client_id)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
|
|
||||||
rets = -ENODEV;
|
rets = -ENODEV;
|
||||||
goto unlock_dev;
|
goto unlock_dev;
|
||||||
}
|
}
|
||||||
if (i == dev->me_clients_num ||
|
if (length > dev->me_clients[i].props.max_msg_length ||
|
||||||
(dev->me_clients[i].client_id !=
|
|
||||||
dev->iamthif_cl.me_client_id)) {
|
|
||||||
rets = -ENODEV;
|
|
||||||
goto unlock_dev;
|
|
||||||
} else if (length > dev->me_clients[i].props.max_msg_length ||
|
|
||||||
length <= 0) {
|
length <= 0) {
|
||||||
rets = -EMSGSIZE;
|
rets = -EMSGSIZE;
|
||||||
goto unlock_dev;
|
goto unlock_dev;
|
||||||
@ -688,16 +677,8 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
|
|||||||
cl->me_client_id);
|
cl->me_client_id);
|
||||||
goto unlock_dev;
|
goto unlock_dev;
|
||||||
}
|
}
|
||||||
for (i = 0; i < dev->me_clients_num; i++) {
|
i = mei_me_cl_by_id(dev, cl->me_client_id);
|
||||||
if (dev->me_clients[i].client_id ==
|
if (i < 0) {
|
||||||
cl->me_client_id)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (WARN_ON(dev->me_clients[i].client_id != cl->me_client_id)) {
|
|
||||||
rets = -ENODEV;
|
|
||||||
goto unlock_dev;
|
|
||||||
}
|
|
||||||
if (i == dev->me_clients_num) {
|
|
||||||
rets = -ENODEV;
|
rets = -ENODEV;
|
||||||
goto unlock_dev;
|
goto unlock_dev;
|
||||||
}
|
}
|
||||||
|
@ -279,9 +279,10 @@ void mei_host_init_iamthif(struct mei_device *dev);
|
|||||||
void mei_allocate_me_clients_storage(struct mei_device *dev);
|
void mei_allocate_me_clients_storage(struct mei_device *dev);
|
||||||
|
|
||||||
|
|
||||||
u8 mei_find_me_client_update_filext(struct mei_device *dev,
|
int mei_me_cl_update_filext(struct mei_device *dev, struct mei_cl *cl,
|
||||||
struct mei_cl *priv,
|
const uuid_le *cguid, u8 host_client_id);
|
||||||
const uuid_le *cguid, u8 client_id);
|
int mei_me_cl_by_uuid(const struct mei_device *dev, const uuid_le *cuuid);
|
||||||
|
int mei_me_cl_by_id(struct mei_device *dev, u8 client_id);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* MEI IO List Functions
|
* MEI IO List Functions
|
||||||
@ -348,7 +349,6 @@ void mei_run_next_iamthif_cmd(struct mei_device *dev);
|
|||||||
|
|
||||||
void mei_free_cb_private(struct mei_cl_cb *priv_cb);
|
void mei_free_cb_private(struct mei_cl_cb *priv_cb);
|
||||||
|
|
||||||
int mei_find_me_client_index(const struct mei_device *dev, uuid_le cuuid);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Register Access Function
|
* Register Access Function
|
||||||
|
@ -69,7 +69,7 @@ int mei_wd_host_init(struct mei_device *dev)
|
|||||||
dev->wd_timeout = AMT_WD_DEFAULT_TIMEOUT;
|
dev->wd_timeout = AMT_WD_DEFAULT_TIMEOUT;
|
||||||
|
|
||||||
/* find ME WD client */
|
/* find ME WD client */
|
||||||
mei_find_me_client_update_filext(dev, &dev->wd_cl,
|
mei_me_cl_update_filext(dev, &dev->wd_cl,
|
||||||
&mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
|
&mei_wd_guid, MEI_WD_HOST_CLIENT_ID);
|
||||||
|
|
||||||
dev_dbg(&dev->pdev->dev, "wd: check client\n");
|
dev_dbg(&dev->pdev->dev, "wd: check client\n");
|
||||||
|
Loading…
Reference in New Issue
Block a user