aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/mei
diff options
context:
space:
mode:
authorTomas Winkler <tomas.winkler@intel.com>2012-12-25 12:06:09 -0500
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2013-01-07 13:31:29 -0500
commitcd51ed649fa4bd55c6a78db52b57260797ed56b4 (patch)
treedf36f6b385ed600ef714e4f813e61aedafcc2e1f /drivers/misc/mei
parent2efdf54603806cba681f7a09ec6c6205bddfd9a9 (diff)
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 @@
23#include "interface.h" 23#include "interface.h"
24 24
25/** 25/**
26 * mei_hbm_cl_hdr - construct client hbm header
27 * @cl: - client
28 * @hbm_cmd: host bus message command
29 * @buf: buffer for cl header
30 * @len: buffer length
31 */
32static inline
33void mei_hbm_cl_hdr(struct mei_cl *cl, u8 hbm_cmd, void *buf, size_t len)
34{
35 struct mei_hbm_cl_cmd *cmd = buf;
36
37 memset(cmd, 0, len);
38
39 cmd->hbm_cmd = hbm_cmd;
40 cmd->host_addr = cl->host_client_id;
41 cmd->me_addr = cl->me_client_id;
42}
43
44/**
45 * same_disconn_addr - tells if they have the same address
46 *
47 * @file: private data of the file object.
48 * @disconn: disconnection request.
49 *
50 * returns true if addres are same
51 */
52static inline
53bool mei_hbm_cl_addr_equal(struct mei_cl *cl, void *buf)
54{
55 struct mei_hbm_cl_cmd *cmd = buf;
56 return cl->host_client_id == cmd->host_addr &&
57 cl->me_client_id == cmd->me_addr;
58}
59
60
61/**
26 * host_start_message - mei host sends start message. 62 * host_start_message - mei host sends start message.
27 * 63 *
28 * @dev: the device structure 64 * @dev: the device structure
@@ -144,22 +180,16 @@ int mei_host_client_enumerate(struct mei_device *dev)
144int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl) 180int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
145{ 181{
146 struct mei_msg_hdr *mei_hdr; 182 struct mei_msg_hdr *mei_hdr;
147 struct hbm_flow_control *flow_ctrl; 183 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
148 const size_t len = sizeof(struct hbm_flow_control); 184 const size_t len = sizeof(struct hbm_flow_control);
149 185
150 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 186 mei_hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
187 mei_hbm_cl_hdr(cl, MEI_FLOW_CONTROL_CMD, buf, len);
151 188
152 flow_ctrl = (struct hbm_flow_control *)&dev->wr_msg_buf[1];
153 memset(flow_ctrl, 0, len);
154 flow_ctrl->hbm_cmd = MEI_FLOW_CONTROL_CMD;
155 flow_ctrl->host_addr = cl->host_client_id;
156 flow_ctrl->me_addr = cl->me_client_id;
157 /* FIXME: reserved !? */
158 memset(flow_ctrl->reserved, 0, sizeof(flow_ctrl->reserved));
159 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n", 189 dev_dbg(&dev->pdev->dev, "sending flow control host client = %d, ME client = %d\n",
160 cl->host_client_id, cl->me_client_id); 190 cl->host_client_id, cl->me_client_id);
161 191
162 return mei_write_message(dev, mei_hdr, (unsigned char *) flow_ctrl); 192 return mei_write_message(dev, mei_hdr, buf);
163} 193}
164 194
165/** 195/**
@@ -173,19 +203,13 @@ int mei_send_flow_control(struct mei_device *dev, struct mei_cl *cl)
173int mei_disconnect(struct mei_device *dev, struct mei_cl *cl) 203int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
174{ 204{
175 struct mei_msg_hdr *hdr; 205 struct mei_msg_hdr *hdr;
176 struct hbm_client_connect_request *req; 206 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
177 const size_t len = sizeof(struct hbm_client_connect_request); 207 const size_t len = sizeof(struct hbm_client_connect_request);
178 208
179 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 209 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
210 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_REQ_CMD, buf, len);
180 211
181 req = (struct hbm_client_connect_request *)&dev->wr_msg_buf[1]; 212 return mei_write_message(dev, hdr, buf);
182 memset(req, 0, len);
183 req->hbm_cmd = CLIENT_DISCONNECT_REQ_CMD;
184 req->host_addr = cl->host_client_id;
185 req->me_addr = cl->me_client_id;
186 req->reserved = 0;
187
188 return mei_write_message(dev, hdr, (unsigned char *)req);
189} 213}
190 214
191/** 215/**
@@ -199,33 +223,13 @@ int mei_disconnect(struct mei_device *dev, struct mei_cl *cl)
199int mei_connect(struct mei_device *dev, struct mei_cl *cl) 223int mei_connect(struct mei_device *dev, struct mei_cl *cl)
200{ 224{
201 struct mei_msg_hdr *hdr; 225 struct mei_msg_hdr *hdr;
202 struct hbm_client_connect_request *req; 226 unsigned char *buf = (unsigned char *)&dev->wr_msg_buf[1];
203 const size_t len = sizeof(struct hbm_client_connect_request); 227 const size_t len = sizeof(struct hbm_client_connect_request);
204 228
205 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len); 229 hdr = mei_hbm_hdr(&dev->wr_msg_buf[0], len);
230 mei_hbm_cl_hdr(cl, CLIENT_CONNECT_REQ_CMD, buf, len);
206 231
207 req = (struct hbm_client_connect_request *) &dev->wr_msg_buf[1]; 232 return mei_write_message(dev, hdr, buf);
208 req->hbm_cmd = CLIENT_CONNECT_REQ_CMD;
209 req->host_addr = cl->host_client_id;
210 req->me_addr = cl->me_client_id;
211 req->reserved = 0;
212
213 return mei_write_message(dev, hdr, (unsigned char *) req);
214}
215
216/**
217 * same_disconn_addr - tells if they have the same address
218 *
219 * @file: private data of the file object.
220 * @disconn: disconnection request.
221 *
222 * returns !=0, same; 0,not.
223 */
224static int same_disconn_addr(struct mei_cl *cl,
225 struct hbm_client_connect_request *req)
226{
227 return (cl->host_client_id == req->host_addr &&
228 cl->me_client_id == req->me_addr);
229} 233}
230 234
231/** 235/**
@@ -237,31 +241,25 @@ static int same_disconn_addr(struct mei_cl *cl,
237static void mei_client_disconnect_request(struct mei_device *dev, 241static void mei_client_disconnect_request(struct mei_device *dev,
238 struct hbm_client_connect_request *disconnect_req) 242 struct hbm_client_connect_request *disconnect_req)
239{ 243{
240 struct hbm_client_connect_response *disconnect_res; 244 struct mei_cl *cl, *next;
241 struct mei_cl *pos, *next;
242 const size_t len = sizeof(struct hbm_client_connect_response); 245 const size_t len = sizeof(struct hbm_client_connect_response);
243 246
244 list_for_each_entry_safe(pos, next, &dev->file_list, link) { 247 list_for_each_entry_safe(cl, next, &dev->file_list, link) {
245 if (same_disconn_addr(pos, disconnect_req)) { 248 if (mei_hbm_cl_addr_equal(cl, disconnect_req)) {
246 dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n", 249 dev_dbg(&dev->pdev->dev, "disconnect request host client %d ME client %d.\n",
247 disconnect_req->host_addr, 250 disconnect_req->host_addr,
248 disconnect_req->me_addr); 251 disconnect_req->me_addr);
249 pos->state = MEI_FILE_DISCONNECTED; 252 cl->state = MEI_FILE_DISCONNECTED;
250 pos->timer_count = 0; 253 cl->timer_count = 0;
251 if (pos == &dev->wd_cl) 254 if (cl == &dev->wd_cl)
252 dev->wd_pending = false; 255 dev->wd_pending = false;
253 else if (pos == &dev->iamthif_cl) 256 else if (cl == &dev->iamthif_cl)
254 dev->iamthif_timer = 0; 257 dev->iamthif_timer = 0;
255 258
256 /* prepare disconnect response */ 259 /* prepare disconnect response */
257 (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len); 260 (void)mei_hbm_hdr((u32 *)&dev->wr_ext_msg.hdr, len);
258 disconnect_res = 261 mei_hbm_cl_hdr(cl, CLIENT_DISCONNECT_RES_CMD,
259 (struct hbm_client_connect_response *) 262 &dev->wr_ext_msg.data, len);
260 &dev->wr_ext_msg.data;
261 disconnect_res->hbm_cmd = CLIENT_DISCONNECT_RES_CMD;
262 disconnect_res->host_addr = pos->host_client_id;
263 disconnect_res->me_addr = pos->me_client_id;
264 disconnect_res->status = 0;
265 break; 263 break;
266 } 264 }
267 } 265 }
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 {
121 u8 data[0]; 121 u8 data[0];
122} __packed; 122} __packed;
123 123
124/**
125 * struct hbm_cl_cmd - client specific host bus command
126 * CONNECT, DISCONNECT, and FlOW CONTROL
127 *
128 * @hbm_cmd - bus message command header
129 * @me_addr - address of the client in ME
130 * @host_addr - address of the client in the driver
131 * @data
132 */
133struct mei_hbm_cl_cmd {
134 u8 hbm_cmd;
135 u8 me_addr;
136 u8 host_addr;
137 u8 data;
138};
139
124struct hbm_version { 140struct hbm_version {
125 u8 minor_version; 141 u8 minor_version;
126 u8 major_version; 142 u8 major_version;