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

mei: wd: simplify wd_send command

Add reduce credits to wd_send to remove code
repetition and simplify error handling
Signed-off-by: default avatarTomas Winkler <tomas.winkler@intel.com>
Signed-off-by: default avatarAlexander Usyskin <alexander.usyskin@intel.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 7ca96aa2
...@@ -480,10 +480,9 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list) ...@@ -480,10 +480,9 @@ int mei_irq_write_handler(struct mei_device *dev, struct mei_cl_cb *cmpl_list)
if (mei_cl_is_connected(&dev->wd_cl)) { if (mei_cl_is_connected(&dev->wd_cl)) {
if (dev->wd_pending && if (dev->wd_pending &&
mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) { mei_cl_flow_ctrl_creds(&dev->wd_cl) > 0) {
if (mei_wd_send(dev)) ret = mei_wd_send(dev);
dev_dbg(&dev->pdev->dev, "wd send failed.\n"); if (ret)
else if (mei_cl_flow_ctrl_reduce(&dev->wd_cl)) return ret;
return -EIO;
dev->wd_pending = false; dev->wd_pending = false;
} }
} }
......
...@@ -111,13 +111,16 @@ int mei_wd_host_init(struct mei_device *dev) ...@@ -111,13 +111,16 @@ int mei_wd_host_init(struct mei_device *dev)
* returns 0 if success, * returns 0 if success,
* -EIO when message send fails * -EIO when message send fails
* -EINVAL when invalid message is to be sent * -EINVAL when invalid message is to be sent
* -ENODEV on flow control failure
*/ */
int mei_wd_send(struct mei_device *dev) int mei_wd_send(struct mei_device *dev)
{ {
struct mei_cl *cl = &dev->wd_cl;
struct mei_msg_hdr hdr; struct mei_msg_hdr hdr;
int ret;
hdr.host_addr = dev->wd_cl.host_client_id; hdr.host_addr = cl->host_client_id;
hdr.me_addr = dev->wd_cl.me_client_id; hdr.me_addr = cl->me_client_id;
hdr.msg_complete = 1; hdr.msg_complete = 1;
hdr.reserved = 0; hdr.reserved = 0;
hdr.internal = 0; hdr.internal = 0;
...@@ -126,10 +129,24 @@ int mei_wd_send(struct mei_device *dev) ...@@ -126,10 +129,24 @@ int mei_wd_send(struct mei_device *dev)
hdr.length = MEI_WD_START_MSG_SIZE; hdr.length = MEI_WD_START_MSG_SIZE;
else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE)) else if (!memcmp(dev->wd_data, mei_stop_wd_params, MEI_WD_HDR_SIZE))
hdr.length = MEI_WD_STOP_MSG_SIZE; hdr.length = MEI_WD_STOP_MSG_SIZE;
else else {
dev_err(&dev->pdev->dev, "wd: invalid message is to be sent, aborting\n");
return -EINVAL; return -EINVAL;
}
ret = mei_write_message(dev, &hdr, dev->wd_data);
if (ret) {
dev_err(&dev->pdev->dev, "wd: write message failed\n");
return ret;
}
return mei_write_message(dev, &hdr, dev->wd_data); ret = mei_cl_flow_ctrl_reduce(cl);
if (ret) {
dev_err(&dev->pdev->dev, "wd: flow_ctrl_reduce failed.\n");
return ret;
}
return 0;
} }
/** /**
...@@ -159,16 +176,9 @@ int mei_wd_stop(struct mei_device *dev) ...@@ -159,16 +176,9 @@ int mei_wd_stop(struct mei_device *dev)
goto out; goto out;
if (ret && mei_hbuf_acquire(dev)) { if (ret && mei_hbuf_acquire(dev)) {
ret = 0; ret = mei_wd_send(dev);
if (ret)
if (!mei_wd_send(dev)) { goto out;
ret = mei_cl_flow_ctrl_reduce(&dev->wd_cl);
if (ret)
goto out;
} else {
dev_err(&dev->pdev->dev, "wd: send stop failed\n");
}
dev->wd_pending = false; dev->wd_pending = false;
} else { } else {
dev->wd_pending = true; dev->wd_pending = true;
...@@ -289,18 +299,10 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev) ...@@ -289,18 +299,10 @@ static int mei_wd_ops_ping(struct watchdog_device *wd_dev)
dev_dbg(&dev->pdev->dev, "wd: sending ping\n"); dev_dbg(&dev->pdev->dev, "wd: sending ping\n");
if (mei_wd_send(dev)) { ret = mei_wd_send(dev);
dev_err(&dev->pdev->dev, "wd: send failed.\n"); if (ret)
ret = -EIO;
goto end; goto end;
} dev->wd_pending = false;
if (mei_cl_flow_ctrl_reduce(&dev->wd_cl)) {
dev_err(&dev->pdev->dev, "wd: mei_cl_flow_ctrl_reduce() failed.\n");
ret = -EIO;
goto end;
}
} else { } else {
dev->wd_pending = true; dev->wd_pending = true;
} }
......
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