mei: add mei_cl_write function
consolidate write code to a specific me client in mei_cl_write function the function is called from mei device write handler and from mei_cl bus send function Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Šī revīzija ir iekļauta:

revīziju iesūtīja
Greg Kroah-Hartman

vecāks
606f34ad12
revīzija
4234a6deb5
@@ -342,11 +342,10 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
|
||||
{
|
||||
struct mei_cl *cl = file->private_data;
|
||||
struct mei_cl_cb *write_cb = NULL;
|
||||
struct mei_msg_hdr mei_hdr;
|
||||
struct mei_device *dev;
|
||||
unsigned long timeout = 0;
|
||||
int rets;
|
||||
int i;
|
||||
int id;
|
||||
|
||||
if (WARN_ON(!cl || !cl->dev))
|
||||
return -ENODEV;
|
||||
@@ -357,24 +356,24 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
|
||||
|
||||
if (dev->dev_state != MEI_DEV_ENABLED) {
|
||||
rets = -ENODEV;
|
||||
goto err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
i = mei_me_cl_by_id(dev, cl->me_client_id);
|
||||
if (i < 0) {
|
||||
id = mei_me_cl_by_id(dev, cl->me_client_id);
|
||||
if (id < 0) {
|
||||
rets = -ENODEV;
|
||||
goto err;
|
||||
goto out;
|
||||
}
|
||||
if (length > dev->me_clients[i].props.max_msg_length || length <= 0) {
|
||||
if (length > dev->me_clients[id].props.max_msg_length || length <= 0) {
|
||||
rets = -EMSGSIZE;
|
||||
goto err;
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (cl->state != MEI_FILE_CONNECTED) {
|
||||
rets = -ENODEV;
|
||||
dev_err(&dev->pdev->dev, "host client = %d, is not connected to ME client = %d",
|
||||
cl->host_client_id, cl->me_client_id);
|
||||
goto err;
|
||||
rets = -ENODEV;
|
||||
goto out;
|
||||
}
|
||||
if (cl == &dev->iamthif_cl) {
|
||||
write_cb = mei_amthif_find_read_list_entry(dev, file);
|
||||
@@ -412,17 +411,15 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
|
||||
if (!write_cb) {
|
||||
dev_err(&dev->pdev->dev, "write cb allocation failed\n");
|
||||
rets = -ENOMEM;
|
||||
goto err;
|
||||
goto out;
|
||||
}
|
||||
rets = mei_io_cb_alloc_req_buf(write_cb, length);
|
||||
if (rets)
|
||||
goto err;
|
||||
|
||||
dev_dbg(&dev->pdev->dev, "cb request size = %zd\n", length);
|
||||
goto out;
|
||||
|
||||
rets = copy_from_user(write_cb->request_buffer.data, ubuf, length);
|
||||
if (rets)
|
||||
goto err;
|
||||
goto out;
|
||||
|
||||
cl->sm_state = 0;
|
||||
if (length == 4 &&
|
||||
@@ -440,65 +437,17 @@ static ssize_t mei_write(struct file *file, const char __user *ubuf,
|
||||
if (rets) {
|
||||
dev_err(&dev->pdev->dev,
|
||||
"amthif write failed with status = %d\n", rets);
|
||||
goto err;
|
||||
goto out;
|
||||
}
|
||||
mutex_unlock(&dev->device_lock);
|
||||
return length;
|
||||
}
|
||||
|
||||
write_cb->fop_type = MEI_FOP_WRITE;
|
||||
|
||||
dev_dbg(&dev->pdev->dev, "host client = %d, ME client = %d\n",
|
||||
cl->host_client_id, cl->me_client_id);
|
||||
rets = mei_cl_flow_ctrl_creds(cl);
|
||||
if (rets < 0)
|
||||
goto err;
|
||||
|
||||
if (rets == 0 || !dev->hbuf_is_ready) {
|
||||
write_cb->buf_idx = 0;
|
||||
mei_hdr.msg_complete = 0;
|
||||
cl->writing_state = MEI_WRITING;
|
||||
goto out;
|
||||
}
|
||||
|
||||
dev->hbuf_is_ready = false;
|
||||
if (length > mei_hbuf_max_len(dev)) {
|
||||
mei_hdr.length = mei_hbuf_max_len(dev);
|
||||
mei_hdr.msg_complete = 0;
|
||||
} else {
|
||||
mei_hdr.length = length;
|
||||
mei_hdr.msg_complete = 1;
|
||||
}
|
||||
mei_hdr.host_addr = cl->host_client_id;
|
||||
mei_hdr.me_addr = cl->me_client_id;
|
||||
mei_hdr.reserved = 0;
|
||||
|
||||
dev_dbg(&dev->pdev->dev, "write " MEI_HDR_FMT "\n",
|
||||
MEI_HDR_PRM(&mei_hdr));
|
||||
if (mei_write_message(dev, &mei_hdr, write_cb->request_buffer.data)) {
|
||||
rets = -ENODEV;
|
||||
goto err;
|
||||
}
|
||||
cl->writing_state = MEI_WRITING;
|
||||
write_cb->buf_idx = mei_hdr.length;
|
||||
|
||||
rets = mei_cl_write(cl, write_cb, false);
|
||||
out:
|
||||
if (mei_hdr.msg_complete) {
|
||||
if (mei_cl_flow_ctrl_reduce(cl)) {
|
||||
rets = -ENODEV;
|
||||
goto err;
|
||||
}
|
||||
list_add_tail(&write_cb->list, &dev->write_waiting_list.list);
|
||||
} else {
|
||||
list_add_tail(&write_cb->list, &dev->write_list.list);
|
||||
}
|
||||
|
||||
mutex_unlock(&dev->device_lock);
|
||||
return length;
|
||||
|
||||
err:
|
||||
mutex_unlock(&dev->device_lock);
|
||||
mei_io_cb_free(write_cb);
|
||||
if (rets < 0)
|
||||
mei_io_cb_free(write_cb);
|
||||
return rets;
|
||||
}
|
||||
|
||||
|
Atsaukties uz šo jaunā problēmā
Block a user