summaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-12-25 18:06:09 +0100
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-07 19:31:29 +0100
commitcd51ed649fa4bd55c6a78db52b57260797ed56b4 (patch)
treedf36f6b385ed600ef714e4f813e61aedafcc2e1f /drivers/misc/mei
parentmei: drop nonexistent function prototype (diff)
downloadlinux-cd51ed649fa4bd55c6a78db52b57260797ed56b4.tar.xz
linux-cd51ed649fa4bd55c6a78db52b57260797ed56b4.zip
mei: simplify preparing client host bus messages
Define a new parent type mei_hbm_cl_cmd for hbm commands that are sent on behalf of specific ME client. This allows us compacting boilerplate code via mei_hbm_cl_hdr function Signed-off-by: Tomas Winkler <tomas.winkler@intel.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc/mei')
-rw-r--r--drivers/misc/mei/hbm.c110
-rw-r--r--drivers/misc/mei/hw.h16
2 files changed, 70 insertions, 56 deletions
diff --git a/drivers/misc/mei/hbm.c b/drivers/misc/mei/hbm.c
index 2c4c1bb6d36a..bc36c23cd2db 100644
--- a/drivers/misc/mei/hbm.c
+++ b/drivers/misc/mei/hbm.c
@@ -23,6 +23,42 @@
#include "interface.h"
/**
+ * mei_hbm_cl_hdr - construct client hbm header
+ * @cl: - client
+ * @hbm_cmd: host bus message command
+ * @buf: buffer for cl header
+ * @len: buffer length
+ */
+static inline
+void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len)
+{
+ struct mei_hbm_cl_cmd *cmd = buf;
+
+ memset(cmd, 0, len);
+
+ cmd->hbm_cmd = hbm_cmd;
+ cmd->host_addr = cl->host_client_id;
+ cmd->me_addr = cl->me_client_id;
+}
+
+/**
+ * same_disconn_addr - tells if they have the same address
+ *
+ * @file: private data of the file object.
+ * @disconn: disconnection request.
+ *
+ * returns true if addres are same
+ */
+static inline
+bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
+{
+ struct mei_hbm_cl_cmd *cmd = buf;
+ return cl->host_client_id == cmd->host_addr &&
+ cl->me_client_id == cmd->me_addr;
+}
+
+
+/**
* host_start_message - mei host sends start message.
*
* @dev: the device structure
@@ -144,22 +180,16 @@ int mei_host_client_enumerate(struct mei_device *dev)
int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
{
struct mei_msg_hdr *mei_hdr;
- struct hbm_flow_control *flow_ctrl;
+ unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
const size_t len = sizeof(struct hbm_flow_control);
mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
+ mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, buf, len);
- flow_ctrl = (struct hbm_flow_control *)&dev->wr_msg_buf[1];
- memset(flow_ctrl, 0, len);
- flow_ctrl->hbm_cmd = MEI_FLOW_CONTROL_CMD;
- flow_ctrl->host_addr = cl->host_client_id;
- flow_ctrl->me_addr = cl->me_client_id;
- /* FIXME: reserved !? */
- memset(flow_ctrl->reserved, 0, sizeof(flow_ctrl->reserved));
dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
cl->host_client_id, cl->me_client_id);
- return mei_write_message(dev, mei_hdr, (unsigned char *) flow_ctrl);
+ return mei_write_message(dev, mei_hdr, buf);
}
/**
@@ -173,19 +203,13 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
{
struct mei_msg_hdr *hdr;
- struct hbm_client_connect_request *req;
+ unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
const size_t len = sizeof(struct hbm_client_connect_request);
hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
+ mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, buf, len);
- req = (struct hbm_client_connect_request *)&dev->wr_msg_buf[1];
- memset(req, 0, len);
- req->hbm_cmd = CLIENT_DISCONNECT_REQ_CMD;
- req->host_addr = cl->host_client_id;
- req->me_addr = cl->me_client_id;
- req->reserved = 0;
-
- return mei_write_message(dev, hdr, (unsigned char *)req);
+ return mei_write_message(dev, hdr, buf);
}
/**
@@ -199,33 +223,13 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
int mei_connect(struct mei_device *dev, struct mei_cl *cl)
{
struct mei_msg_hdr *hdr;
- struct hbm_client_connect_request *req;
+ unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
const size_t len = sizeof(struct hbm_client_connect_request);
hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
+ mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, buf, len);
- req = (struct hbm_client_connect_request *) &dev->wr_msg_buf[1];
- req->hbm_cmd = CLIENT_CONNECT_REQ_CMD;
- req->host_addr = cl->host_client_id;
- req->me_addr = cl->me_client_id;
- req->reserved = 0;
-
- return mei_write_message(dev, hdr, (unsigned char *) req);
-}
-
-/**
- * same_disconn_addr - tells if they have the same address
- *
- * @file: private data of the file object.
- * @disconn: disconnection request.
- *
- * returns !=0, same; 0,not.
- */
-static int same_disconn_addr(struct mei_cl *cl,
- struct hbm_client_connect_request *req)
-{
- return (cl->host_client_id == req->host_addr &&
- cl->me_client_id == req->me_addr);
+ return mei_write_message(dev, hdr, buf);
}
/**
@@ -237,31 +241,25 @@ static int same_disconn_addr(struct mei_cl *cl,
static void mei_client_disconnect_request(struct mei_device *dev,
struct hbm_client_connect_request *disconnect_req)
{
- struct hbm_client_connect_response *disconnect_res;
- struct mei_cl *pos, *next;
+ struct mei_cl *cl, *next;
const size_t len = sizeof(struct hbm_client_connect_response);
- list_for_each_entry_safe(pos, next, &dev->file_list, link) {
- if (same_disconn_addr(pos, disconnect_req)) {
+ list_for_each_entry_safe(cl, next, &dev->file_list, link) {
+ if (mei_hbm_cl_addr_equal(cl, disconnect_req)) {
dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
disconnect_req->host_addr,
disconnect_req->me_addr);
- pos->state = MEI_FILE_DISCONNECTED;
- pos->timer_count = 0;
- if (pos == &dev->wd_cl)
+ cl->state = MEI_FILE_DISCONNECTED;
+ cl->timer_count = 0;
+ if (cl == &dev->wd_cl)
dev->wd_pending = false;
- else if (pos == &dev->iamthif_cl)
+ else if (cl == &dev->iamthif_cl)
dev->iamthif_timer = 0;
/* prepare disconnect response */
(void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
- disconnect_res =
- (struct hbm_client_connect_response *)
- &dev->wr_ext_msg.data;
- disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD;
- disconnect_res->host_addr = pos->host_client_id;
- disconnect_res->me_addr = pos->me_client_id;
- disconnect_res->status = 0;
+ mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
+ &dev->wr_ext_msg.data, len);
break;
}
}
diff --git a/drivers/misc/mei/hw.h b/drivers/misc/mei/hw.h
index 6ebb369af668..cb2f556b4252 100644
--- a/drivers/misc/mei/hw.h
+++ b/drivers/misc/mei/hw.h
@@ -121,6 +121,22 @@ struct mei_bus_message {
u8 data[0];
} __packed;
+/**
+ * struct hbm_cl_cmd - client specific host bus command
+ * CONNECT, DISCONNECT, and FlOW CONTROL
+ *
+ * @hbm_cmd - bus message command header
+ * @me_addr - address of the client in ME
+ * @host_addr - address of the client in the driver
+ * @data
+ */
+struct mei_hbm_cl_cmd {
+ u8 hbm_cmd;
+ u8 me_addr;
+ u8 host_addr;
+ u8 data;
+};
+
struct hbm_version {
u8 minor_version;
u8 major_version;